Skip to content

Instantly share code, notes, and snippets.

@rsanchez
rsanchez / gist:1953785
Created March 1, 2012 22:48
safecracker bp
{if logged_in_group_id != 1}{redirect='404'}{/if}
<html>
<head>
<link href="{path=css/_ee_saef_css}" type="text/css" rel="stylesheet" media="screen" />
<style type="text/css">
.error { color: red; }
</style>
</head>
<body>
{exp:safecracker channel="{segment_3}" return="site/safecracker/{segment_3}/ENTRY_ID" entry_id="{segment_4}"}
@rsanchez
rsanchez / gist:2001555
Created March 8, 2012 15:39
CartThrob forms JSON response
//successful form submission
{
"success": 1,
"errors": {},
"return": "http://yoursite.com/path/to",
"XID": "0394wjg0w9rj0e65gmaode509gj095e", //only if secure forms is turned on
"cart_total": 100,
"cart_subtotal": 80,
"cart_discount": 0,
"cart_tax": 10,
@rsanchez
rsanchez / gist:2287611
Created April 2, 2012 22:22 — forked from atnan/git-opendiff
use FileMerge for git diffs on directories
[alias]
opendiff=difftool --tool=opendiff --dir-diff --no-prompt
Usage:
git opendiff <branch, tag, sha>
@rsanchez
rsanchez / gist:2407622
Created April 17, 2012 17:25
Cartthrob config to set curl proxy if Charles is open, for debugging payment gateway request/response
<?php
if (trim(shell_exec('osascript -e \'tell app "System Events" to count processes whose name is "Charles"\'')))
{
$config['cartthrob:curl_proxy'] = '127.0.0.1';
$config['cartthrob:curl_proxy_port'] = 8888;
}
@rsanchez
rsanchez / ext.cartthrob_entry_author_email_notifications.php
Created April 17, 2012 21:34
CartThrob Entry Author Email Notifications Extension
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CartThrob CartThrob Entry Author Email Notifications Extension
*
* @package ExpressionEngine
* @subpackage CartThrob
* @category Extension
* @author Rob Sanchez
* @link http://cartthrob.com
@rsanchez
rsanchez / ee-boostrap-php.md
Created April 28, 2012 16:37
PHP CLI (or CodeRunner) bootstrap into EE

#Bootstrap EE in PHP CLI

Use the bootstrapper and php auto-prepend your bootstrap file:

In my .profile I have this alias.

alias ee='php -a -d auto_prepend_file="/path/to/your/bootstrap.php"'

Now in the terminal I enter the command ee and I have an interactive PHP cli with access to my local EE environment. If you are using virtual hosts and have many local EE environments, use multiple aliases/bootstrap files.

@rsanchez
rsanchez / Nest.php
Created June 21, 2012 20:21
Using stash to move safecracker JS to footer
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$plugin_info = array(
'pi_name' => 'Nest',
'pi_version' => '1.0.0',
'pi_author' => 'Rob Sanchez',
'pi_author_url' => 'http://github.com/rsanchez',
'pi_description' => 'Useful when you need to delay the parsing of the inner, nested tag.',
'pi_usage' => '{exp:nest parse="inward"}
{exp:other:tag}
@rsanchez
rsanchez / gist:3207641
Created July 30, 2012 15:07
add new form validation rules in safecracker_submit_entry_start
<?php
public function safecracker_submit_entry_start()
{
$my_custom_rules = array(
'my_field_1' => 'max_length[5]',
'my_field_2' => 'required|max_length[10]',
);
foreach ($my_custom_rules as $field_name => $field_rules)
//for PHP 5.2
$dateTime = new DateTime();
$dateTime->setTimezone(new DateTimeZone('America/New_york'));
$date = getdate();
$dateTime->setDate($date['year'], $date['mon'], $date['mday']);
$dateTime->setTime($date['hours'], $date['minutes'], $date['seconds']);
$conf['daylight_savings'] = (bool) $dateTime->format('I') ? 'y' : 'n';
@rsanchez
rsanchez / gist:4494530
Created January 9, 2013 16:27
diff two urls using FileMerge
curldiff( ) {
template="/tmp/curldiff-XXXXXXXX"
file1=$(mktemp $template)
file2=$(mktemp $template)
echo "Loading $1"
curl -# -L -o $file1 $1
echo "Loading $2"
curl -# -L -o $file2 $2
opendiff $file1 $file2
rm $file1 $file2