Skip to content

Instantly share code, notes, and snippets.

View netProphET's full-sized avatar

Mike Schell netProphET

  • MODX, LLC
  • Bancroft, Ontario, Canada
View GitHub Profile
<?php
class xPDOSimpleTemplatingObject extends xPDOSimpleObject {
function __construct(& $xpdo) {
parent :: __construct($xpdo);
}
/**
* Load a collection of xPDOObject instances.
*
* @static
* @param xPDO &$xpdo A valid xPDO instance.
<?php
require_once dirname(dirname(__FILE__)) . '/inc/sys.inc';
require_once XPDO_PATH . '/xpdo.class.php';
session_start();
$xpdo= new xPDO(XPDO_DSN,XPDO_DBUSER,XPDO_DBPW, array(
xPDO::OPT_CACHE_DB=> true,
xPDO::OPT_CACHE_DB_COLLECTIONS=> true,
xPDO::OPT_CACHE_PATH=> CACHE_PATH,
regexp = /(\[\[[^\]]*)&amp;([^\[]*\]\])/g;
tests = [
"",
"no modx tags",
"[[something?&amp;foo=`bar`]]",
"[[something? &amp;foo=`[[$bar &amp;baz=`fuz`]]`]]",
"[[something? &amp;replace=`yes`]] &amp; don't replace",
"[[something? &amp;replace=`yes`]] &amp; don't replace [[something? &amp;replace=`yes`]]",
"[[line1? &amp;foo=`bar`]] &amp; don't replace\n[[line2? &amp;bar=`baz`]]"
];
@netProphET
netProphET / mgrChunk.php
Created November 26, 2010 18:01
mgrChunk snippet idea
<?php
$return = '';
if(isset ($_SESSION['mgrValidated'])){
$return = $modx->getChunk($chunk);
}
return $return;
?>
@netProphET
netProphET / subdomain-context.php
Created December 13, 2010 14:43
MODx Revolution plugin bound to OnHandleRequest event
<?php
/**
* plugin to map subdomain requests to contexts
* @setting event OnHandleRequest
* @todo currently, subdomains and context names are bound together.. remove this constraint through some mapping/lookup
* @todo currently, assumes first name in host (name before first dot) is what maps to the context
*/
$context = 'web';
@netProphET
netProphET / context_directory_binding.php
Created May 16, 2011 17:17
emulate @Directory binding, but from base_path of Resource's context #MODX
<?php
/**
* emulate @DIRECTORY binding, from base_path of Resource's context
*
* usage:
* a) create context settings named 'base_path' for each context (not neccessary for web context)
* (note: you may also want assets_path and/or other settings in your contexts as well)
* b) call with @EVAL in TV's Input Options field, e.g.
* @EVAL $dir='assets/images/'; return(include '/path/to/this/file/context_directory_binding.php');
*/
<?php
if ($modx->event->name == 'OnManagerPageInit') {
$script = <<<SCRIPT
<script type="text/javascript">
Ext.ComponentMgr.onAvailable('modx-panel-resource', function(){
Ext.getCmp('modx-panel-resource').on('ready', function(){
window.setTimeout(function(){Ext.getCmp('modx-panel-resource').markDirty()}, 250);
})
})
</script>
@netProphET
netProphET / migx_modx-2.2.diff
Created October 6, 2011 04:22
MIGX diff for MODX2.2
--------------- core/components/migx/elements/tv/input/migx.php ---------------
index 11a9c2d..53370a5 100644
@@ -133,6 +133,7 @@ $lang = $this->xpdo->lexicon->fetch();
$lang['mig_add'] = !empty($properties['btntext'])?$properties['btntext']:$lang['mig_add'];
$modx->smarty->assign('i18n', $lang);
$this->xpdo->smarty->assign('properties', $properties);
+$this->xpdo->smarty->assign('resource', is_object($this->xpdo->resource) ? $this->xpdo->resource->toArray() : array());
$this->xpdo->smarty->assign('pathconfigs', $this->xpdo->toJSON($pathconfigs));
$this->xpdo->smarty->assign('columns', $this->xpdo->toJSON($cols));
$this->xpdo->smarty->assign('fields', $this->xpdo->toJSON($fields));
@netProphET
netProphET / autoResourceSelect.html
Created November 25, 2011 21:04
select element of resources, will take user to resource selected
<select name="mySelect" id="mySelectId" onchange="el=document.getElementById('mySelectId');u=el.options[el.selectedIndex].value;if(u!=''){window.location.href=u;}">
[[getResources? &parents=`0` &tpl=`selectOption.tpl`]]
</select>
@netProphET
netProphET / manager_leftpanel_width.plugin.php
Created June 22, 2012 15:05
plugin fragment for setting width of MODX Manager left panel
<?php
/**
* plugin fragment for setting width of MODX Manager left panel
*/
if($modx->event->name == 'OnBeforeManagerPageInit') {
// update layout manager state
$state = $modx->controller->getDefaultState();
$state['modx-leftbar-tabs']['width'] = 525;
$response = $modx->runProcessor('system/registry/register/send',array(
'register' => 'state',