Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
Refactor - $modx->invokeEvent()
Browse files Browse the repository at this point in the history
  • Loading branch information
yama committed Mar 6, 2017
1 parent 0e6cef8 commit 0a244df
Showing 1 changed file with 39 additions and 48 deletions.
87 changes: 39 additions & 48 deletions manager/includes/document.parser.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4503,56 +4503,47 @@ function removeAllEventListener() {
* @return boolean|array
*/
function invokeEvent($evtName, $extParams= array ()) {
if (!$evtName)
return false;
if (!isset ($this->pluginEvent[$evtName]))
return false;
if (!$evtName) return false;
if (!isset ($this->pluginEvent[$evtName])) return false;


$el= $this->pluginEvent[$evtName];
$results= array ();
$numEvents= count($el);
if ($numEvents > 0)
for ($i= 0; $i < $numEvents; $i++) { // start for loop
if ($this->dumpPlugins) $eventtime = $this->getMicroTime();
$pluginName= $el[$i];
$pluginName = $this->stripslashes($pluginName);
// reset event object
$e= & $this->Event;
$e->_resetEventObject();
$e->name= $evtName;
$e->activePlugin= $pluginName;

// get plugin code
$plugin = $this->getPluginCode($pluginName);
$pluginCode= $plugin['code'];
$pluginProperties= $plugin['props'];

// load default params/properties
$parameter= $this->parseProperties($pluginProperties, $pluginName, 'plugin');
if(!is_array($parameter)){
$parameter = array();
}
if (!empty ($extParams))
$parameter= array_merge($parameter, $extParams);

// eval plugin
$this->evalPlugin($pluginCode, $parameter);

if(class_exists('PHxParser')) $this->config['enable_filter'] = 0;

if ($this->dumpPlugins) {
$eventtime = $this->getMicroTime() - $eventtime;
$this->pluginsCode .= '<fieldset><legend><b>' . $evtName . ' / ' . $pluginName . '</b> ('.sprintf('%2.2f ms', $eventtime*1000).')</legend>';
foreach ($parameter as $k=>$v) $this->pluginsCode .= $k . ' => ' . print_r($v, true) . '<br>';
$this->pluginsCode .= '</fieldset><br />';
$this->pluginsTime["$evtName / $pluginName"] += $eventtime;
}
if ($e->_output != "")
$results[]= $e->_output;
if ($e->_propagate != true)
break;
}
$e->activePlugin= "";
foreach($this->pluginEvent[$evtName] as $pluginName) { // start for loop
if ($this->dumpPlugins) $eventtime = $this->getMicroTime();
$pluginName = $this->stripslashes($pluginName);
// reset event object
$e= & $this->event;
$e->_resetEventObject();
$e->name = $evtName;
$e->activePlugin = $pluginName;

// get plugin code
$plugin = $this->getPluginCode($pluginName);
$pluginCode= $plugin['code'];
$pluginProperties= $plugin['props'];

// load default params/properties
$parameter= $this->parseProperties($pluginProperties, $pluginName, 'plugin');
if(!is_array($parameter)) $parameter = array();
if(!empty($extParams)) $parameter = array_merge($parameter, $extParams);

// eval plugin
$this->evalPlugin($pluginCode, $parameter);

if(class_exists('PHxParser')) $this->config['enable_filter'] = 0;

if ($this->dumpPlugins) {
$eventtime = $this->getMicroTime() - $eventtime;
$this->pluginsCode .= '<fieldset><legend><b>' . $evtName . ' / ' . $pluginName . '</b> ('.sprintf('%2.2f ms', $eventtime*1000).')</legend>';
foreach ($parameter as $k=>$v) $this->pluginsCode .= $k . ' => ' . print_r($v, true) . '<br>';
$this->pluginsCode .= '</fieldset><br />';
$this->pluginsTime["$evtName / $pluginName"] += $eventtime;
}
if ($e->_output != '') $results[]= $e->_output;
if ($e->_propagate != true) break;
}

$e->activePlugin= '';
return $results;
}

Expand Down

0 comments on commit 0a244df

Please sign in to comment.