Skip to content

Instantly share code, notes, and snippets.

@pepebe
pepebe / image.tpl
Created March 3, 2017 16:28 — forked from JensWolff/image.tpl
Quick'n'Dirty MODX 2.3.x image-TV-clearbutton (/manager/templates/default/element/tv/renders/input/image.tpl)
<style>
.clearImageTV + .x-panel.modx-panel.x-panel-noborder{
margin-left: 30px;
margin-top: -34px;
}
</style>
<div id="tvbrowser{$tv->id}"></div>
<div id="tv-image-{$tv->id}"><a class="clearImageTV" href="#" onclick="javascript:Ext.getCmp('tvbrowser{$tv->id}').setValue('');document.getElementById('tv{$tv->id}').value='';document.getElementById('tv-image-preview-{$tv->id}').getElementsByTagName('img')[0].remove();"><i class="icon icon-2x icon-trash-o"></i></i></a></div>
<?php
if(!function_exists(autoRotateImage)) {
function autoRotateImage($image) {
$orientation = $image->getImageOrientation();
switch($orientation) {
case imagick::ORIENTATION_BOTTOMRIGHT:
$image->rotateimage("#000", 180); // rotate 180 degrees
break;
@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 / 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 / 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?
/**
* A* (A-Star) Pathfinding Algorithm in JavaScript
* @author Matthew Trost
* @license Creative Commons Attribution-ShareAlike 3.0 Unported License
* @datepublished December 2010
*/
function astar (map, heuristic, cutCorners) {
var listOpen = [];
var listClosed = [];
<?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>');