Skip to content

Instantly share code, notes, and snippets.

@jonleverrier
jonleverrier / getImgSizeFromUrl.snippet.php
Last active December 12, 2018 17:19
getImgSizeFromUrl snippet for MODX. Retrieves the height and width of an image from a remote url.
<?php
/**
* getImgSizeFromUrl snippet for MODX
* Retrieves the height and width of an image from a remote url
*
* example usage: [[!getImgSizeFromUrl? &url='https://path/to/myimg.jpg' &tpl=`myTpl`]]
* placeholders to use in the myTpl chunk are [[+height]]] and [[+width]]
*
* @author Jon Leverrier (jon@youandmedigital.com)
* @version 1.0
@jonleverrier
jonleverrier / pdfcrowd.plugin.php
Last active December 12, 2018 17:19
PDF Crowd MODX Plugin. Using the API from PDF Crowd, this plugin will convert a MODX resource in to PDF format and then save it to your web server in a specified location.
<?php
/**
* PDF Crowd MODX Plugin
*
* Using the API from PDF Crowd, this plugin will convert a MODX resource in to
* PDF format and then save it to your web server in a specified location.
*
* The plugin is setup to trigger witin a certain MODX context.
* For example, a "pdf" context.
*
@jonleverrier
jonleverrier / getFormSteps.snippet.php
Last active December 12, 2018 17:18
getFormSteps for the MODX Formalicious form builder by Sterc. This utility snippet displays all the step titles for a given form ID.
<?php
/**
* getFromSteps v.1.0
* An unoffical utility snippet for Formalicious by Sterc
*
* This utility snippet outputs all the steps for a multistep form
* based on a given form ID
*
* Usage:
* Put the snippet in your &stepTpl and call the snippet like this:
@jonleverrier
jonleverrier / welcomeMessage.plugin.php
Last active December 12, 2018 17:17 — forked from rtripault/plugin.php
Sample plugin to display the welcome screen to any new member login for the first time in MODX Revolution manager
<?php
/**
* A sample plugin to display the "welcome message" to all users, login for the first time in Revo manager
*
* @var modX $modx
* @var array $scriptProperties
* @var modPlugin $this
*
* @see modPlugin::process()
*
@jonleverrier
jonleverrier / logOutput.snippet.php
Last active December 12, 2018 17:16
Log the output of a placeholder or snippet to the MODX error log. Useful for checking what a placeholder actually outputs...
<?php
/*
logOutput snippet for MODX
Use like this:
[[!logOutput? &input=`[[+placeholder]]`]] or
*/
if (empty($input)) {
@jonleverrier
jonleverrier / minifyHTML.php
Last active April 20, 2018 08:13
minifyHTML Plugin for MODX. Based on the PHPWee PHP Minifier class. This plugin will minify and compress the html output of your resources which have a content type of text/html.
<?php
/**
* minifyHTML Plugin for MODX
* Based on the PHPWee PHP Minifier class
*
* This plugin uses a forked version of PHPWee PHP Minifier
* which has been patched and updated
*
* For more info see;
* https://github.com/ashucg/phpwee-php-minifier
@jonleverrier
jonleverrier / getFolderIDs.php
Last active December 8, 2017 13:31
Used as a folder selector for Content Blocks. Intended to be used inside a field setting, with the field type set to "select". If the manager user is an Admin, display a set of folders. If the manager user is a Content Editor, display a restricted set of folders
// folder selector for content blocks
// put this snippet inside a field setting with the field type of "select"
// get current resource id
$id = (!empty($id) ? $id : $modx->resource->get('id'));
// get current context key
// if $resourceid isn't a resource object, it will fallback to web
if ($resourceid = $modx->getObject('modResource', $id)) {
@jonleverrier
jonleverrier / getAllContexts.php
Last active June 2, 2016 13:50
MODX: List all context keys but exclude the manager
<?php
$contexts = $modx->getCollection('modContext', array('key:!=' => 'mgr'));
foreach($contexts as $context)
{
$context_keys[] = $context->get('key');
}
return implode(',', $context_keys);