Skip to content

Instantly share code, notes, and snippets.

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

Burick Burick

🏠
Работаю из дома
View GitHub Profile
@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
@Burick
Burick / getProps.snippet.php
Created December 21, 2017 12:18 — forked from sepiariver/getProps.snippet.php
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.
*
**/
@Burick
Burick / cbGetFieldContent.snippet.php
Created December 21, 2017 12:18 — forked from sepiariver/cbGetFieldContent.snippet.php
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?
<?php
$success = false;
if (!empty($value)) {
$re = "/^((((\+[\d\-.]{1,5})?[ \-.]?\d{3})|(\+[\d\-.]{1,5})?[ \-.]?\((\d{3}\)))?[ \-.]?\d{3}[ \-.]?\d{4}\s?(e?x?t?\.?\s?\d{1,7})?)?$/i";
if (preg_match($re, $value) === 1) $success = true;
}
if (!$success) {
$validator->addError($key, 'Please enter a valid phone number.');
return false;
} else {
@Burick
Burick / NormalizeUriSuffix.plugin.php
Created December 21, 2017 12:17 — forked from sepiariver/NormalizeUriSuffix.plugin.php
Plugin to fix trailing slash inconsistencies in MODX Resource URIs
<?php
/**
* Steps to implement
* 1. Set HTML content-type default suffix to '/'
* 2. Ensure Resources have isFolder = 1 as default
* 3. If you still have issues with Resources being routed to the URI without a trailing slash,
* create this Plugin and enable it 'OnWebPageInit'.
**/
if ($modx->event->name !== 'OnWebPageInit') return;
if (substr($_SERVER['REQUEST_URI'], -1) !== '/') $modx->sendRedirect($_SERVER['REQUEST_URI'] . '/', array(
@Burick
Burick / getResourceProps.snippet.php
Created December 21, 2017 12:13 — forked from sepiariver/getResourceProps.snippet.php
Gets Resource Properties and sets placeholders
<?php
/**
* getter function for resource properties. sets placeholders with all values.
* optionally allows direct return of one element within the namespaced properties sub-array
* @author @sepiariver
*
**/
// OPTIONS
$id = (int) $modx->getOption('id', $scriptProperties, 0);
@Burick
Burick / setResourceProps.plugin.php
Created December 21, 2017 12:13 — forked from sepiariver/setResourceProps.plugin.php
Sets Resource properties OnDocFormSave. To be used with getResourceProps.snippet.php
<?php
/**
*
* @author @sepiariver
*
**/
if ($modx->context->get('key') !== 'mgr' || $modx->event->name !== 'OnDocFormSave') return;
if (!($resource instanceof modResource)) {
$modx->log(modX::LOG_LEVEL_ERROR, 'setResourceProps Plugin did not have access to a valid resource object on line: ' . __LINE__);
return;