Skip to content

Instantly share code, notes, and snippets.

View Burick's full-sized avatar
🏠
Работаю из дома

Burick Burick

🏠
Работаю из дома
View GitHub Profile
@Burick
Burick / LangRouter.php
Created December 22, 2017 19:53 — forked from fomigo/LangRouter.php
Language context router for use with Babel extra for MODX Revolution
<?php
/* LangRouter
* ==========
*
* This plugin is meant to be used with Babel extra for MODX Revolution. It
* takes care of switching contexts, which hold translations, depending on URL
* requested by client. LangRouter works with so called subfolder based setup,
* in which many languages are served under a single domain but are
* differentiated by a virtual subfolder indicating the language, eg.
* mydomain.com/pl/.
@Burick
Burick / gist:2f69845bfd26b172fd5230f21fcbbb91
Created December 21, 2017 18:07 — forked from Mark-H/gist:3104835
Adding transparent watermark to a PhpThumb thumbnail.
{"fltr":{"":"wmi|assets/images/logo-watermark.png|385x220|20|350|58"}}
@Burick
Burick / getTVInputsFromJson.snippet.php
Created December 21, 2017 12:35 — forked from sepiariver/getTVInputsFromJson.snippet.php
Turns JSON into TV input options in MODX.
<?php
/*
* getTVInputsFromJson
* @author @sepiariver <[email protected]>
*
* Example usage:
* 1. Create a Chunk with this Snippet call: [[getTVInputsFromJson? &jsonFile=`http://schema.org/docs/tree.jsonld`]]
* 2. Create a Single-Select TV with @CHUNK binding for "Input Options": @CHUNK my_schema_tv_chunk
* 3. Resources with the TV enabled will get a list of schema.org itemtype property values, like this screenshot: http://sepiariver.co/1KUr4LJ
*
<?php
/**
* Based on @garryn Garry Nutting's amazingly fast sitemap generator:
* http://www.modx360.com/blog/2013/09/03/google-sitemap-thousands-of-resources/
*
* Modified by @sepiariver for multi-context support
* GPL, no warranties, etc.
*
*/
@Burick
Burick / cbGetLayoutSetting.snippet.php
Created December 21, 2017 12:32 — forked from sepiariver/cbGetLayoutSetting.snippet.php
Gets a ContentBlocks Layout setting.
<?php
/**
* Use the cbGetLayoutSetting snippet to get a setting from a particular layout.
* @author YJ Tso @sepiariver <[email protected]>
* @param (id) &resource allows checking for fields on other resources.
* @param (bool) &showDebug return debugging info as JSON.
* @param (string) &toPlaceholder set a placeholder with this string as key, instead of returning.
* @param required (int) &layout - ID of ContentBlocks layout from which to fetch the setting.
* @param required (string) &setting - key of layout setting to return.
*
@Burick
Burick / getJsonProperty.snippet.php
Created December 21, 2017 12:32 — forked from sepiariver/getJsonProperty.snippet.php
Useful in conjunction with ContentBlocks for example to get nested field content (from a repeater)
<?php
/**
* getJsonProperty
*
* Example usage:
* [[getJsonProperty?
* &tpl=`myChunkTpl`
* &key=`0.rows.0.repeater.rows`
* &json=`[[cbGetFieldContent? &field=`28` &returnAsJSON=`1`]]`
* ]]
@Burick
Burick / numberformat.snippet.php
Created December 21, 2017 12:32 — forked from sepiariver/numberformat.snippet.php
MODX output modifier to format number using php number_format
<?php
if (empty($input) || !is_numeric($input)) return $input;
$opts = array_filter(array_map('trim', explode(',', $options)));
$args = array();
$args['decimals'] = (isset($opts[0])) ? intval($opts[0]) : 2;
$args['dec_point'] = (isset($opts[1])) ? (string) $opts[1] : '.';
$args['thousands_sep'] = (isset($opts[2])) ? (string) $opts[2] : ',';
return number_format(floatval($input), $args['decimals'], $args['dec_point'], $args['thousands_sep']);
@Burick
Burick / imageplusvalue.snippet.php
Created December 21, 2017 12:31 — forked from sepiariver/imageplusvalue.snippet.php
ImagePlusValue output modifier.
<?php
/**
* imageplusvalue is a Snippet/Output Modifier to parse
* the ImagePlus stored JSON and return values or thumbs.
*
* @author YJ Tso <[email protected]>
*
* Example usage:
* <img src="[[*image:imageplusvalue=`croppedImg:w=840&zc=1`]]" alt="[[*image:imageplusvalue=`altTag`]]">
*
// Array.diff()
if (typeof Array.prototype.diff === 'undefined') {
Array.prototype.diff = function() {
var result = arguments[0];
delete arguments[0];
if (!(result instanceof Array)) {
throw new TypeError('1st argument passed to Array.diff was not an array');
@Burick
Burick / web_rules.conf
Created December 21, 2017 12:30 — forked from sepiariver/web_rules.conf
Web Rules (nginx conf) in MODX Cloud for CDN, proxy caching assets, and statcache
# statcache bits
set $cache_prefix 'statcache';
if ($http_user_agent = 'MODX RegenCache') {
set $cache_prefix 'no cache';
}
# CORS for CDN pull zone and expires directives
location ~* \.(?:ico|css|js|jpe?g|png|gif|svg|pdf|mov|mp4|mp3|woff|woff2|ttf|ttc|otf|eot|font.css)$ {
expires 7d;
add_header Access-Control-Allow-Origin "*";
add_header Pragma public;