Skip to content

Instantly share code, notes, and snippets.

View opengeek's full-sized avatar

Jason Coward opengeek

View GitHub Profile
<?php
/**
* An extension to modUser that allows Atlassian Crowd integration via SOAP.
*
* @todo Complete this class to handle all external user management tasks
* allowed with Crowd.
*
* @package modx
* @subpackage user.crowd
*/
<?php
$output = $input;
$limit = intval($options) ? intval($options) : 100;
if (function_exists('mb_strlen')) {
if (mb_strlen($output, $encoding) > $limit) {
$output = mb_substr($output, 0, $limit, $encoding) . '&hellip;';
}
} else if (strlen($output) > $limit) {
$output = substr($output, 0, $limit) . '&hellip;';
}
<?php
$output = array();
$total = 0;
$limit = isset($limit) ? (integer) $limit : 0;
$offset = isset($offset) ? (integer) $offset : 0;
$totalVar = !empty($totalVar) ? $totalVar : 'total';
// determine the total number of records for your criteria
$totalStmt = $modx->query("SELECT COUNT(*) FROM `myTable` WHERE `food` = 'beer'");
<?php
$output = '';
$tElementClass = !empty($tElementClass) ? $tElementClass : 'modSnippet';
$tStart = $modx->getMicroTime();
if (!empty($tElement)) {
switch ($tElementClass) {
case 'modChunk':
$output = $modx->getChunk($tElement, $scriptProperties);
break;
[[!getPage?
&element=`getResourcesTag`
&elementClass=`modSnippet`
&tpl=`pitem_home`
&hideContainers=`1`
&pageVarKey=`page`
&parents=`[[*id]]`
&includeTVs=`1`
&includeContent=`1`
&pageFirstTpl=`&nbsp;`
@opengeek
opengeek / getCache.sample.html
Created October 16, 2010 05:00
Snippet to flexibly cache any modElement instance
<div>
<ul>
[[!getCache? &element=`getResources` &elementClass=`modSnippet` &cache_expires=`1200` &parents=`0` &depth=`0` &limit=`2` &tpl=`ulTpl` &sortby=`RAND()`]]
</ul>
</div>
@opengeek
opengeek / recalculateURIs.php
Created April 13, 2011 14:47
Script to recalculate all unfrozen URI values for MODX Resources in 2.1.x+
<?php
include 'config.core.php';
include MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = new modX();
$modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
$modx->initialize('mgr');
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
@opengeek
opengeek / plugin.RemoteCommands.php
Created October 4, 2011 14:48
RemoteCommands and SendClearCache plugins for MODX Revolution 2.2+
<?php
/* RemoteCommands plugin -- register with OnHandleRequest OR OnWebPageComplete event */
/* define the IP of the master instance which does not need to execute remote commands */
$master_instance = $modx->getOption('master_instance', $scriptProperties, '127.0.0.1');
/* get the instance IP */
$instance = $_SERVER['SERVER_ADDR'];
/* the number of seconds the remote command is valid for */
@opengeek
opengeek / test-speed.php
Created March 1, 2012 18:36
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();
@opengeek
opengeek / .htaccess
Created March 26, 2012 22:43
Example of how to cache static HTML copies of MODX Resources using plugin + mod_rewrite
# Add this before your MODX Friendly URLs RewriteCond's and RewriteRule...
RewriteCond /abs/path/to/docroot/statcache%{REQUEST_URI} -f
RewriteRule ^(.*)$ /statcache/$1 [L,QSA]