Skip to content

Instantly share code, notes, and snippets.

@ashitvora-zz
ashitvora-zz / alerts.njk
Created July 19, 2016 13:36
Nunjucks Alerts Macros
{% macro alerts() %}
{% set types = ['success', 'error', 'info', 'warning'] %}
{% for type in types %}
{% if( old(type) ) %}
<p class="alert alert-{% if type == 'error' %}danger{% else %}{{type}}{% endif %}">{{ old(type) }}</p>
{% endif %}
{% endfor %}
{% endmacro %}
@ashitvora-zz
ashitvora-zz / Facebook.php
Created November 4, 2015 12:14
Ask Facebook to scrape information of a link again
public function requestRescrape($url)
{
$graphUrl = 'https://graph.facebook.com/';
$post = 'id=' . urlencode($url) . '&scrape=true';
\Httpful\Request::post($graphUrl)->body($post)->send();
}
@ashitvora-zz
ashitvora-zz / JVZoo.php
Last active August 23, 2016 09:26
Verify JVZoo Request
<?php namespace Alfanso\Services\Jvzoo;
class Jvzoo {
public function isValidRequest($data) {
$jvzooSecretKey = config('jvzoo.secret_key');
$receivedVerificationCode = $data['cverify'];
// remove cverify from the array since we don't use that
unset($data['cverify']);
@ashitvora-zz
ashitvora-zz / html_macro.php
Created December 9, 2012 07:30
Back button link macro for Laravel PHP Framework
/**
* Link to Back page
*/
HTML::macro("link_to_back", function($text = "Back"){
return "<a href='javascript:history.back();'>$text</a>";
});
@ashitvora-zz
ashitvora-zz / html.macros.php
Created November 28, 2012 13:00
Laravel macro to display flash alert messages
/**
* Display Error / Success / Warn / Info messages
*
* These messages are set using Session::flash(<message_type>, <message>);
*/
HTML::macro("alert", function(){
$alerts = array();
$alert_types = array("error", "success", "warn", "info");
foreach ($alert_types as $type) {
if( Session::has($type) ){
@ashitvora-zz
ashitvora-zz / form_macros.php
Created November 21, 2012 11:53
Open form by routes in Laravel
/**
* Open form for a Route
*/
Form::macro('open_by_route', function($route, $params = array(), $attributes = array(), $type = "POST"){
return Form::open( URL::to_route( $route, $params ), $type, $attributes );
});
/**
@ashitvora-zz
ashitvora-zz / Laravel first field error Macro
Created November 21, 2012 11:48
Laravel macro to display first validation error for the field
/**
* Returns first error message for a field, if any, in html
*/
Form::macro('first_field_error', function($field_name){
$html = array();
$errors = Session::get('errors');
if( $errors->has( $field_name ) ){
array_push( $html, '<div class="form-error">' );
array_push( $html, $errors->first( $field_name ) );