Skip to content

Instantly share code, notes, and snippets.

View sepiariver's full-sized avatar

YJ Tso sepiariver

View GitHub Profile
@sepiariver
sepiariver / schema-head.tpl
Created April 30, 2015 02:06
Schema.org head tags
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" itemscope itemtype="http://schema.org/{put something here}"> <!--<![endif]-->
<head>
<meta charset="[[++modx_charset]]">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>[[*pagetitle]] | [[++site_name]]</title>
<meta itemprop="name" content="[[++site_name]]">
@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 / fontAwesomeInputOptions.php
Last active January 5, 2019 17:43
Font Awesome Input Options for MODX CMS
<?php
/*
* fontAwesomeInputOptions
* MODX Snippet
* @author YJ Tso @sepiariver
* GPL, no warranties, etc.
*
* Usage: execute in TV input options, preferably with @CHUNK binding
* alternatively install as Content Blocks input (link to repo coming soon)
*/
@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 / 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 / SaveResourceImageThumbnails.plugin.php
Last active December 21, 2017 12:19
Process MODX Resource Image OnDocFormSave with pthumb
<?php
// In case the wrong event is enabled
if ($modx->context->key !== 'mgr' || $modx->event->name !== 'OnDocFormSave') return;
// We really need a resource object and the pthumb snippet
if (!is_object($resource) || $modx->getCount('modSnippet', array('name' => 'phpthumbof')) !== 1) {
$modx->log(modX::LOG_LEVEL_ERROR, 'ResourceImageThumbnails plugin requires phpthumbof and a valid resource object.');
return;
}
@sepiariver
sepiariver / DateToTimestamp.plugin.php
Created September 8, 2015 00:43
MODX Plugin to convert TV date inputs to unix timestamp. By @theboxer
<?php
/*
* DateToTimestamp Plugin for MODX Revolution
* @code @theboxer
* @comments @sepiariver
*
* DateToTimestamp is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
@sepiariver
sepiariver / caching.htaccess
Last active December 21, 2017 12:19
Add GZIP and caching to .htaccess
# Add content types for fonts
AddType application/x-font-ttf .ttf
AddType application/x-font-opentype .otf
AddType application/x-font-woff .woff
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
ExpiresByType image/x-icon A2592000
@sepiariver
sepiariver / getProps.snippet.php
Last active December 21, 2017 12:18
Accessor snippet for MODX Resource properties field.
<?php
/**
* getProps
* Snippet to access MODX Resource properties.
* @author @sepiariver
*
* @package ResourceProperties
* GPL+, no warranties express nor implied.
*
**/
@sepiariver
sepiariver / cbGetFieldContent.snippet.php
Last active December 21, 2017 12:18
Modified Content Blocks snippet tries a comma separated list of fields, in order of priority, until a value is found or nothing is returned.
<?php
/**
* Use the cbGetFieldContent snippet to get the content of a particular field.
*
* For example, this can be useful if you need to get a bit of content
* in a getResources call
*
* Example usage:
*
* [[cbGetFieldContent?