Skip to content

Instantly share code, notes, and snippets.

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

Burick Burick

🏠
Работаю из дома
View GitHub Profile
@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;
@Burick
Burick / SaveProcessedContent.plugin.php
Created December 21, 2017 12:13 — forked from sepiariver/SaveProcessedContent.plugin.php
OnDocFormSave, process MODX Resource content and save to a TV for search indexing.
<?php
/*
* SaveProcessedContent
* @author @theboxer
* @comments @sepiariver
*
* GPL, no warranties, etc.
*
* USAGE:
* Enable 'OnDocFormSave' event in Plugin properties, and supply a valid "tvName" value.
@Burick
Burick / rootResource.php
Created December 21, 2017 12:11 — forked from sepiariver/rootResource.php
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
@Burick
Burick / iContactPost.php
Created December 21, 2017 12:10 — forked from sepiariver/iContactPost.php
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
@Burick
Burick / SandboxUserGroupToContainer.php
Created December 21, 2017 12:10 — forked from sepiariver/SandboxUserGroupToContainer.php
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',