Skip to content

Instantly share code, notes, and snippets.

@pepebe
Forked from opengeek/Executioner.snippet.php
Created February 24, 2012 19:37
Show Gist options
  • Save pepebe/1903200 to your computer and use it in GitHub Desktop.
Save pepebe/1903200 to your computer and use it in GitHub Desktop.
MODX REVO : Executioner snippet
<?php
/*
Fork of the original executioner snippet by opengeek
Usage:
[[!Executioner?
&tElementClass=`modSnippet`
&tEcho=`comment`
&tElement=`getResourceField`
&id=`27`
&field=`nav248`
&processTV=`1`
&default=`Sorry, no data available`
&docid=`27`
]]
&tElementClass= may be `modSnippet` or `modChunk`
&tEcho= may be `log` or `comment`
&msg= Use this one to put a message at the begionning or end of a group of exectioner snippets.
&msg=`Start`
[2012-02-24 17:42:15] (ERROR @ /index.php) ### Start: Homepage (2) 17:42:15 ###
&msg=`End`
[2012-02-24 17:42:15] (ERROR @ /index.php) ### End: Homepage (2) 17:42:55 ###
*/
$id = $modx->resource->get('id');
$pagetitle = $modx->resource->get('pagetitle');
if ( !empty($msg) ) {
$modx->log(modX::LOG_LEVEL_ERROR, "### ".$msg.": ".$pagetitle."(".$id.") ".date('H:i:s')." ###");
return;
}
$output = '';
$tElementClass = !empty($tElementClass) ? $tElementClass : 'modSnippet';
$tElementId = !empty($tElementId) ? $tElementId : $tElementClass;
$tStart = $modx->getMicroTime();
if (!empty($tElement)) {
switch ($tElementClass) {
case 'modChunk':
$output = $modx->getChunk($tElement, $scriptProperties);
break;
case 'modSnippet':
$output = $modx->runSnippet($tElement, $scriptProperties);
break;
default:
$tElementObj = $modx->getObject($tElementClass, array('name' => $tElement));
if ($tElementObj && $tElementObj instanceof modElement) {
$tElementObj->setCacheable(false);
$output = $tElementObj->process($scriptProperties);
} else {
$modx->log(modX::LOG_LEVEL_ERROR, "{$tElementClass}: {$tElement} is not a valid MODx Element");
}
break;
}
}
$tEnd = $modx->getMicroTime();
$exec = sprintf("%2.4f s", $tEnd - $tStart);
switch($tEcho) {
case('comment'):
$output .= "\n"."<!-- ";
$output .= "\n"."Executioner Snippet";
$output .= "\n"."Document: ".$pagetitle." (ID:".$id.")";
$output .= "\n"."{$tElementClass}: {$tElement}";
$output .= "\n"."Execution time:".$exec;
$output .= "\n"."-->";
break;
case('log'):
$modx->log(modX::LOG_LEVEL_ERROR, "{$tElementClass}: {$tElement} executed in " . $exec );
break;
default:
$modx->log(modX::LOG_LEVEL_ERROR, "{$tElementClass}: {$tElement} executed in " . $exec );
break;
}
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment