Skip to content

Instantly share code, notes, and snippets.

View opengeek's full-sized avatar

Jason Coward opengeek

View GitHub Profile
<?php
$path = MODX_CORE_PATH . 'components/getCourses/';
$result = $modx->addPackage('getCourses',$path . 'model/');
if ($result) {
$c = $modx->newQuery('Courses201213Combined');
$whereArray = array();
// Get query string parameters
<?php
$m = mt_rand(1, 100);
$list = range(1, 100);
unset($list[array_search($m, $list)]);
function missing(array $list) {
$n = count($list);
$allSum = ($n+1)*($n+2)/2;
return $allSum - array_sum($list);
}
@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]
@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 / 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 / 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 / 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>
[[!getPage?
&element=`getResourcesTag`
&elementClass=`modSnippet`
&tpl=`pitem_home`
&hideContainers=`1`
&pageVarKey=`page`
&parents=`[[*id]]`
&includeTVs=`1`
&includeContent=`1`
&pageFirstTpl=`&nbsp;`
<?php
$output = '';
$tElementClass = !empty($tElementClass) ? $tElementClass : 'modSnippet';
$tStart = $modx->getMicroTime();
if (!empty($tElement)) {
switch ($tElementClass) {
case 'modChunk':
$output = $modx->getChunk($tElement, $scriptProperties);
break;
<?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'");