Skip to content

Instantly share code, notes, and snippets.

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

Burick Burick

🏠
Работаю из дома
View GitHub Profile
@Burick
Burick / sample_json_export_config.json
Created December 21, 2017 12:27 — forked from sepiariver/sample_json_export_config.json
Example of JSON config file consumed by sample_json_export.php script.
[
{
"class": "modSnippet",
"where": [
{
"name:=": "SomeCustomSnippet"
}
],
"toWhere": "create"
},
<?php
/**
* getResourcesColumns
* @author @sepiariver
*
* &parent optional ID of Resource from which to fetch children. Defaults to current resource.
* &fields optional Resource field(s) from which to fetch values. Defaults to 'pagetitle,longtitle,introtext,parent,hidemenu'.
* &columns optional Number of columns to sort Resources into and wrap with colWrapper_n;
* &columnDirection optionalVertical or horizontal column sorting. Defaults to horizontal
* &depth optional Depth to seek children via getChildIds(). Defaults to 1
@Burick
Burick / quicklist.snippet.php
Created December 21, 2017 12:25 — forked from sepiariver/quicklist.snippet.php
Fast snippet for listing MODX Resources. Outputs generic HTML list with link to each Resource. Not template-able except wrapper.
<?php
/**
* quickList
*
* Lists Resourcs super fast. Uses code by Garry Nutting of the MODX Core Team.
*
* @author YJ Tso <[email protected]>, Garry Nutting <[email protected]>
*
*
* quickList is free software; you can redistribute it and/or modify it
@Burick
Burick / filterpathsegment.snippet.php
Created December 21, 2017 12:25 — forked from sepiariver/filterpathsegment.snippet.php
Use the MODX filterPathSegment method to filter a string value into valid URL syntax. Useful for HTML attribute values as well.
<?php
$options = $modx->getOption('options', $scriptProperties, $modx->getOption('friendly_alias_restrict_chars_pattern'), true);
return $modx->filterPathSegment($input, array('friendly_alias_restrict_chars_pattern' => $options));
@Burick
Burick / client_preview.plugin.php
Created December 21, 2017 12:25 — forked from sepiariver/client_preview.plugin.php
MODX Client Preview Plugin
<?php
if ($modx->context->get('key') === 'mgr') return;
$key = $modx->getOption('key', $scriptProperties, 'my-secret-key');
$val = $modx->getOption('val', $scriptProperties, 'my-secret-value');
switch ($modx->event->name) {
case 'OnHandleRequest':
if (!$modx->getOption('site_status')) {
if ($_GET[$key] === $val) {
$modx->config['site_status'] = 1;
@Burick
Burick / readtime.snippet.php
Created December 21, 2017 12:24 — forked from sepiariver/readtime.snippet.php
Reading time MODX output filter.
<?php
$options = (int) $modx->getOption('options', $scriptProperties, 200, true); // 200 words per minute
$wordCount = (int) str_word_count(strip_tags($input)); // To display word count set options to 0
if ($options === 0) return $wordCount;
return ceil($wordCount / abs($options));
@Burick
Burick / inSection.snippet.php
Created December 21, 2017 12:24 — forked from sepiariver/inSection.snippet.php
Detects if the current MODX Resource is in a predefined list of "sections", and if so returns a string (e.g. a CSS classname).
<?php
// The Resource ID to test
$id = (int) $modx->getOption('id', $scriptProperties, $modx->resource->get('id'), true);
// Option to return early if Current Resource matches $id
$matchCurrent = $modx->getOption('matchCurrent', $scriptProperties, true);
// IDs of Resources deemed as "sections", against which to test
$sectionIds = array_filter(array_map('trim', explode(',', $modx->getOption('sectionIds', $scriptProperties, ''))));
// IDs of parent Resources, the direct children of which will be added to $sectionIds
$sectionParentIds = array_filter(array_map('trim', explode(',', $modx->getOption('sectionParentIds', $scriptProperties, ''))));
// If the test passes, meaning the Resource has a $sectionId as an ancestor, output this
@Burick
Burick / SaveResourceImageThumbnails.plugin.php
Created December 21, 2017 12:19 — forked from sepiariver/SaveResourceImageThumbnails.plugin.php
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;
}
@Burick
Burick / DateToTimestamp.plugin.php
Created December 21, 2017 12:19 — forked from sepiariver/DateToTimestamp.plugin.php
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.
@Burick
Burick / caching.htaccess
Created December 21, 2017 12:19 — forked from sepiariver/caching.htaccess
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