Skip to content

Instantly share code, notes, and snippets.

@pepebe
pepebe / plugin.php
Created January 26, 2017 16:09 — forked from rtripault/plugin.php
Plugin to add a "created by" field on a MODX Revolution resource form, listening on the "OnDocFormPrerender" event
<?php
/**
* Sample plugin to add a "created by" field on a resource form
*
* @var modX $modx
* @var array $scriptProperties
*
* @event OnDocFormPrerender
*/
@pepebe
pepebe / getParent.snippet.php
Created January 24, 2017 13:47
Get all parents of a resource, return the id at a specific level.
<?php
/*Usage [[getParentIds? &level=`1`]]
*/
$level = !empty($level) ? $level : 1;
$arr = array_reverse($modx->getParentIds($modx->resource->get('id'), 10, array('context' => 'web')));
@pepebe
pepebe / mqDebug.js
Created December 9, 2016 15:22
Add a breakpoint class to the html element. Useful for targeting stuff in Bootstrap projects.
/*
mqDebug by pepebe
Purpose: Add a class to the html element that fits to the current media Query
To be used with with bootstrap
*/
function mqDebug(){
if(document.getElementById("mq") === null){
console.log('Appending mq debugger to dom');
@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';
@pepebe
pepebe / GetImages.php
Created December 4, 2016 08:14
Dirty hack for moregallery v1.5.6 adding [[+first.view_url]] and [[+last.view_url]] file_urls to simgleImage layouts
<?php
use modmore\Alpacka\Snippet;
use modmore\Alpacka\Properties\SimpleProperty;
use modmore\Alpacka\Properties\BooleanProperty;
use modmore\Alpacka\Properties\EnumProperty;
/**
* Class GetImagesSnippet
*
* Gets a collection of images and videos.
@pepebe
pepebe / Collections.renderers.markdown
Last active September 15, 2018 19:53
Collections - Setup

###Renderers:

  • this.rendYesNo - Yes/No (1/0) boolean values, coloured in green and red, respectively
  • Collections.renderer.qtip - On hover will show a qtip with value (useful for longer values)
  • Collections.renderer.pagetitleWithButtons - Pagetitle (in h2 element) with link to edit and *buttons for update, view, delete, publish (ala Articles grid view)
  • Collections.renderer.pagetitle - Pagetitle (in h2 element) with link to edit
  • Collections.renderer.pagetitleLink - Pagetitle with link to edit (smaller text than h2)
  • Collections.renderer.datetimeTwoLines - Date on first line and time on second line; date and time formats are configurable via system settings
  • Collections.renderer.datetime - Date and time on one line
@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();
@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 / 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 / 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?