Skip to content

Instantly share code, notes, and snippets.

@brandonkelly
brandonkelly / gist:5643159
Created May 24, 2013 12:27
Upcoming BaseOptionsFieldType templating options
{% if entry.drinkAttributes.contains('alcoholic') %}
Alcoholic!
{% else %}
Not alcoholic
{% endif %}
<h2>Selected Attributes</h2>
<table>
{% for attr in entry.drinkAttributes %}
<tr>
@brandonkelly
brandonkelly / assets2-simple-file-input.html
Created January 15, 2013 21:10
Here's how to create a simple file upload input for an Assets 2 field in SafeCracker
<input type="file" name="fieldname">
<input type="hidden" name="fieldname_filedir" value="1">
@brandonkelly
brandonkelly / gist:3217046
Created July 31, 2012 13:30
Wygwam extension for adding custom toolbar buttons
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
require_once PATH_THIRD.'matrix/config.php';
/**
* Wygwam Custom Toolbar Button
*
* This is a sample extension that would add a plugin to Wygwam’s extraPlugins setting,
@brandonkelly
brandonkelly / wygwam-trim
Created June 22, 2012 19:26
Trim out whitespace when saving a Wygwam field
In system/expressionengine/third_party/wygwam/ft.wygwam.php, find this in the beginning of the save() function:
// Clear out if just whitespace
if (! $data || preg_match('/^\s*(<\w+>\s*(&nbsp;)*\s*<\/\w+>|<br \/>)?\s*$/s', $data))
{
return '';
}
And replace it with this:
@brandonkelly
brandonkelly / gist:2723569
Created May 18, 2012 06:31
Remove <script> tags from HTML
// Remove any <script> tags
// Go backwards to factor in nested script tags, e.g. <script>document.write('<script></script>')</script>
$offset = strlen($html) - 9; // Minimum match length is 9 chars (<script/>)
for ($offset; $offset >= 0; $offset--)
{
$substr = substr($html, $offset);
if (preg_match('/^<script[^>]+?\/>|^<script(?:.|\s)*?\/script>/im', $substr, $match))
{
$html = substr($html, 0, $offset).substr($html, $offset+strlen($match[0]));
}
@brandonkelly
brandonkelly / gist:1671737
Created January 24, 2012 18:27
Cross-compatible get_upload_preferences() for EE 2.0 thru 2.4
<?php
/**
* Get Upload Preferences (Cross-compatible between ExpressionEngine 2.0 and 2.4)
* @param int $group_id Member group ID specified when returning allowed upload directories only for that member group
* @param int $id Specific ID of upload destination to return
* @return array Result array of DB object, possibly merged with custom file upload settings (if on EE 2.4+)
*/
function get_upload_preferences($group_id = NULL, $id = NULL)
{
@brandonkelly
brandonkelly / gist:1051722
Created June 28, 2011 17:56
Assets.Sheet usage
// -------------------------------------------
// Include the Sheet resources in PHP
// -------------------------------------------
if (! class_exists('Assets_helper'))
{
require PATH_THIRD.'assets/helper.php';
}
$assets_helper = new Assets_helper;
@brandonkelly
brandonkelly / Make 'git difftool' use Changes.app
Created October 30, 2010 13:41
Make 'git difftool' use Changes.app
After clicking Changes > Install Terminal Utility…, add this to ~/.gitconfig:
[diff]
tool = changes-app
[difftool "changes-app"]
cmd = /usr/bin/chdiff $LOCAL $REMOTE
[difftool]
/**
* tabfocus event plugin for jQuery
*
* Mimics the focus() event, except it's only
* called when focus wasn't assigned via a click
*
* -------------------------------------------
* Usage
* -------------------------------------------
*
A Guide to Fieldtype Settings in EE2
display_global_settings()
- $this->settings
- fieldtype's global settings
display_settings($data)
- $this->settings
- fieldtype's global settings