Skip to content

Instantly share code, notes, and snippets.

View sepiariver's full-sized avatar

YJ Tso sepiariver

View GitHub Profile
@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 / cloneResource.php
Last active January 8, 2019 20:58
A Snippet to clone a Resource into multiple, user-defined parent containers in arbitrary contexts
<?php
// get user-defined source document and target parents
$source = intval($modx->getOption('sourceId', $scriptProperties, ''));
$targets = array_map('trim', explode(',', $modx->getOption('targetIds', $scriptProperties, '')));
// to prevent accidents...
$_allowedUsers = explode(',', 'username1,username2');
// check stuff, and if passed then get the source document object
if ( !in_array($modx->user->get('username'), $_allowedUsers) || empty($source) || $source == 0 || !is_array($targets) || empty($targets) ) return;
$sourceDoc = $modx->getObject('modResource', $source);
<?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 / 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>';
}
}
@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 / rootResource.php
Last active December 19, 2023 12:48
Get the ID of the "Root Resource", aka "Ultimate Parent", with slightly different feature set.
<?php
/*
* @author @sepiariver
*
* GPL license, no warranties, no liability, etc.
*
* USAGE EXAMPLE:
* [[rootResource? &toPlaceholder=`root_resource`]]
* //followed by something like
@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 / 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
@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 / twog-modx.html
Last active February 26, 2020 15:01
Twitter/OG Meta Tags for MODX
<!-- Open Graph Tags -->
<meta property="og:site_name" content="[[++site_name]]" />
<meta property="og:type" content="article" />
<meta property="og:title" content="[[*longtitle:default=`[[*pagetitle]]`]]" />
<meta property="og:description" content="[[*description:default=`[[++site_description]]`]]" />
<meta property="og:url" content="[[~[[*id]]? &scheme=`full`]]" />
<meta property="og:image" content="[[*image:default=`[[++site_image]]`]]" />
<meta property="fb:app_id" content="[[++fb_app_id]]" />
<meta property="article:publisher" content="[[++fb_url]]" />
<!-- Twitter Tags -->