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 / getResourceThumbnails.snippet.php
Last active December 12, 2018 17:20
getResourceThumbnails snippet for MODX. Searches inside the tv_posttype field and pulls out the images for use in open graph tags. If the resource is a "default" resource, it will display the default Open Graph image from ClientConfig.
<?php
/**
* getResourceThumbnails snippet
* Searches inside the tv_posttype field, and pulls out images
* for use in Open Graph tags.
* If the resource is a default resource, it displays the default
* Open Graph image from ClientConfig
*
*
* @author Jon Leverrier (jon@youandmedigital.com)
@jonleverrier
jonleverrier / isAnon.snippet.php
Last active December 12, 2018 17:21
isAnon snippet for MODx. Returns the value 1 if the user is anonymous (not logged into the manager)
<?php
/**
* isAnon snippet
* returns the value 1 if the user is anonymous (not logged into the manager)
*
* example usage: [[!isAnon:is=`1`:then=``:else=`i'm not logged in`]]
*
* @author Jon Leverrier (jon@youandmedigital.com)
* @version 1.0
* @since 10th December 2017
@jonleverrier
jonleverrier / isAdmin.snippet.php
Last active December 12, 2018 17:21
isAdmin snippet for MODX. returns the value 1 if the user is an administrator
<?php
/**
* isAdmin snippet
* returns the value 1 if the user is an administrator
*
* example usage: [[!isAdmin:is=`1`:then=`i'm an admin`:else=`i'm just a content editor`]]
*
* @author Jon Leverrier (jon@youandmedigital.com)
* @version 1.0
* @since 10th December 2017
@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 / cbContentEditor.php
Last active December 30, 2021 22:49
This MODX plugin hides certain Content Blocks buttons from a specific MODX user group. It also disables the drag and drop functionality, so that you can provide some users with a more locked down version of Content Blocks.
<?php
/**
* Content Blocks cbContentEditor Plugin
*
* This plugin hides certain CB buttons from certain MODX user groups
* and disables the drag and drop functionality, so that you can provide
* some clients with a more locked down version of CB.
*
* I would suggest setting up CB templates and defaults in the CB component manager,
* so that predefined layouts are loaded automatically when a new resource is created.
@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);