Skip to content

Instantly share code, notes, and snippets.

View sepiariver's full-sized avatar

YJ Tso sepiariver

View GitHub Profile
@sepiariver
sepiariver / getCtx.php
Last active December 21, 2017 12:03
Get MODX Context Settings and optionally output to placeholders.
<?php
/*
* @author @sepiariver
*
* GPL license, no warranties, no liability, etc.
*
* USAGE EXAMPLE:
* [[getCtx? &context=`othercontext` &key=`site_url`]]
* // outputs the "site_url" context setting from "othercontext"
@sepiariver
sepiariver / timestamprenderer.js
Created September 30, 2014 23:10
Custom Collections Timestamp Renderer
var timestampToDatetime = function(value, metaData, record, rowIndex, colIndex, store) {
if (value == 0 || value == null) return '';
return Ext.util.Format.date(new Date(parseInt(value) * 1000),MODx.config['collections.mgr_datetime_format']);
};
@sepiariver
sepiariver / customimgrenderer.js
Created September 30, 2014 22:59
Custom Collections Image Renderer
var myimagerenderer = function(value, metaData, record, rowIndex, colIndex, store) {
if (value != '' && value != null) {
var baseUrl = MODx.config.collections_renderer_basepath_img;
if (value.indexOf('http://') === 0) {
baseUrl = '';
}
return '<div class="myimagerenderer"><img src="' + baseUrl + value + '" width="100"></div>';
}
}
<?php
/*
* Copyright (c) YJ Tso <info@sepiariver.com>
*
* GPL2, do what you want at your own risk. No warranties whatsoever.
*
*/
// Get &resources property from snippet call
$ids = array_map('trim', explode(',', $modx->getOption('resources', $scriptProperties, '')));
@sepiariver
sepiariver / TwitterX-modified
Last active December 21, 2017 12:07
Slight mods to TwitterX » http://www.qodo.co.uk/blog/twitterx-a-new-modx-extra-for-pulling-in-twitter-feeds-using-api-1.1/ Added cache_id property to use more than one snippet call on a page. Added toPlaceholder property to display output with custom placeholder. Added support for Twitter favorites timeline. Needs more testing.
/**
* TwitterX
*
* This package loads Twitter feeds using the new (and very annoying) Twitter
* 1.1 API. You will need to create a Twitter app and get the keys and tokens
* by creating a new app here: https://dev.twitter.com/apps/new
*
* This uses twitteroauth: https://github.com/abraham/twitteroauth
*
* TwitterX is free software; you can redistribute it and/or modify it
@sepiariver
sepiariver / getResourceImage.snippet.php
Created July 12, 2015 22:58
Retrieves thumbnail paths from a json source in MODX.
<?php
// Options
$input = $modx->getOption('input', $scriptProperties, '');
if (empty($input)) return;
$size = $modx->getOption('size', $scriptProperties, 'original');
$toPlaceholder = $modx->getOption('toPlaceholder', $scriptProperties, '');
// Get stuff
$image = $modx->fromJSON($input);
if (!is_array($image)) return;
@sepiariver
sepiariver / prototype.snippet.php
Last active December 21, 2017 12:09
Utility snippet for rapid prototyping in MODX CMS.
<?php
// Options
$limit = (int) $modx->getOption('limit', $scriptProperties, 3, true);
// $limit must be > 0
$limit = ($limit === 0) ? 1 : abs($limit);
$tpl = $modx->getOption('tpl', $scriptProperties, '');
if (empty($tpl)) return; // if empty what's the point?
$outputSeparator = $modx->getOption('outputSeparator', $scriptProperties, '');
$delim = $modx->getOption('delimiter', $scriptProperties, ',', true);
@sepiariver
sepiariver / ContentBlocksTemplates.php
Last active December 21, 2017 12:09
Scope ContentBlocks (modmore's premium plugin for MODX) to specific templates
<?php
$eventName = $modx->event->name;
switch($eventName) {
case 'OnDocFormPrerender':
if (!is_object($resource)) { // prevents bad error when user doesn't have perms to resource
$modx->log(modX::LOG_LEVEL_ERROR, '[ContentBlocks Templates] No Resource Object on line: ' . __LINE__);
return;
}
// a system setting must be created with the key 'contentblocks.enabled_template_ids'
$enabledTemplates = array_map('trim', explode(',', $modx->getOption('contentblocks.enabled_template_ids')));
@sepiariver
sepiariver / SandboxUserGroupToContainer.php
Last active December 21, 2017 12:10
Sandboxes MODX Manager Users to edit child Resources of a specific Container only. Works best with a CollectionContainer.
<?php
/*
* MODX Plugin to sandbox Users by User Group, to a specific Resource container.
*
* @author @sepiariver
* GPL, no warranties, no liability, etc.
*
* Create a Plugin with the code from this gist. Enable the 'OnDocFormPrerender' event
* in the 'System Events' tab of the Plugin. Create a namespace, e.g. 'sandbox', and
* the following system settings with that namespace: 'sandbox.allow_create',
@sepiariver
sepiariver / iContactPost.php
Last active December 21, 2017 12:10
POST newsletter signup submissions to iContact via custom FormIt hook
<?php
/*
* @author @sepiariver
*
* GPL, no warranties, no liability, etc.
*
* USAGE EXAMPLE:
* [[!FormIt? &hooks=`iContactPost`]]
*
* NOTE: using iContact's API would be a more robust approach