Skip to content

Instantly share code, notes, and snippets.

@pepebe
pepebe / Executioner.snippet.php
Created February 24, 2012 19:37 — forked from opengeek/Executioner.snippet.php
MODX REVO : Executioner snippet
<?php
/*
Fork of the original executioner snippet by opengeek
Usage:
[[!Executioner?
&tElementClass=`modSnippet`
&tEcho=`comment`
&tElement=`getResourceField`
&id=`27`
@pepebe
pepebe / transpose_table.js
Created July 31, 2012 08:45 — forked from pgaertig/transpose_table.js
JS: Transpose HTML table using jQuery
$(function() {
var t = $('#thetable tbody').eq(0);
var r = t.find('tr');
var cols= r.length;
var rows= r.eq(0).find('td').length;
var cell, next, tem, i = 0;
var tb= $('<tbody></tbody>');
while(i<rows){
cell= 0;
@pepebe
pepebe / optimized.html
Last active October 11, 2015 05:57 — forked from opengeek/optimized.html
Example of optimizing conditional filters using a Chunk wrapper
[[[[*page-image:notempty=`$wrapImgThumb?
&src=`*page-image`
&alt=`[[*pagetitle]]`
&thumbOpts=`w=480&h=320`
`]]]]
@pepebe
pepebe / chunk.html
Created October 23, 2012 14:09 — forked from Mark-H/chunk.html
Plugin to send email notifications to all members of a user group
<p>Hi there!</p>
<p>The resource [[+pagetitle]] (ID: [[+id]]) has been [[+mode]].</p>
<p>You can login to the manager at www.mysite.com/manager/ to review and if needed publish the resource.</p>
<p>Thank you!</p>
@pepebe
pepebe / cbGetFieldContent.snippet.php
Created October 13, 2015 05:00 — 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?
@pepebe
pepebe / extract-teaser-layouts.php
Created February 9, 2016 17:44 — forked from christianseel/extract-teaser-layouts.php
MODX Plugin (OnDocFormSave): Extract Teaser Layouts – saves a specific ContentBlocks layout into a TV to make it available elsewhere. To prevent the layout from rendering in the content area you need to wrap your CB layout template into [[+render_teaser:is=`1`:then=`<template here>`:else``]]
<?php
// load service
$corePath = $modx->getOption('contentblocks.core_path', null, $modx->getOption('core_path').'components/contentblocks/');
$ContentBlocks = $modx->getService('contentblocks','ContentBlocks', $corePath.'model/contentblocks/');
// get cb json
if ($modx->event->name == 'OnDocFormSave') {
$cbJson = $resource->get('contentblocks');
} else {
$cbJson = $resource->getProperty('content','contentblocks','');
@pepebe
pepebe / cloneResource.php
Created February 23, 2016 09:16 — forked from sepiariver/cloneResource.php
A Snippet to clone a Resource into multiple, user-defined parent containers in arbitrary contexts
<?php
// get user-defined source document and target parents
$source = intval($modx->getOption('sourceId', $scriptProperties, ''));
$targets = array_map('trim', explode(',', $modx->getOption('targetIds', $scriptProperties, '')));
// to prevent accidents...
$_allowedUsers = explode(',', 'username1,username2');
// check stuff, and if passed then get the source document object
if ( !in_array($modx->user->get('username'), $_allowedUsers) || empty($source) || $source == 0 || !is_array($targets) || empty($targets) ) return;
$sourceDoc = $modx->getObject('modResource', $source);
@pepebe
pepebe / test-speed.php
Created July 7, 2016 12:23 — forked from lossendae/test-speed.php
Simple benchmark for iterative MODX Chunk parsing
<?php
include 'config.core.php';
include MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('web');
$modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
$modx->setLogLevel(xPDO::LOG_LEVEL_INFO);
$tstart = $modx->getMicroTime();
<?php
// Add RTE for introtext if richtext option is enabled for the resource
// check "OnDocFormRender" event
$modx->regClientStartupHTMLBlock('<script>Ext.onReady(function() {
if(MODx.loadRTE) MODx.loadRTE("modx-resource-introtext");
});</script>');
@pepebe
pepebe / collections.imageplus.js
Created December 7, 2016 09:52 — forked from vidhav/collections.imageplus.js
Custom MODX Collections renderer for Image+
Collections.renderer.imageplus = function(value, metaData, record, rowIndex, colIndex, store) {
if (value != '' && value != null) {
var data = Ext.decode(value);
var url = MODx.config.connectors_url + 'system/phpthumb.php?imageplus=1';
var params = {};
params.src = MODx.config['collections.renderer_image_path'] + data.sourceImg.src;
params.w = 100;
if (data.sourceImg.src.indexOf('.png') !== -1) {
params.f = 'png';