Skip to content

Commit

Permalink
The import function has to track paths per dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker committed May 21, 2017
1 parent 5d4683e commit 341db17
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions libraries/cms/plugin/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,6 @@ public static function importPlugin($type, $plugin = null, $autocreate = true, J
{
static $loaded = array();

// Check for the default args, if so we can optimise cheaply
$defaults = false;

if (is_null($plugin) && $autocreate == true && is_null($dispatcher))
{
$defaults = true;
}

// Ensure we have a dispatcher now so we can correctly track the loaded plugins
$dispatcher = $dispatcher ?: JEventDispatcher::getInstance();

Expand All @@ -166,7 +158,7 @@ public static function importPlugin($type, $plugin = null, $autocreate = true, J
$loaded[$dispatcherHash] = array();
}

if (!isset($loaded[$dispatcherHash][$type]) || !$defaults)
if (!isset($loaded[$dispatcherHash][$type]))
{
$results = null;

Expand All @@ -183,12 +175,6 @@ public static function importPlugin($type, $plugin = null, $autocreate = true, J
}
}

// Bail out early if we're not using default args
if (!$defaults)
{
return $results;
}

$loaded[$dispatcherHash][$type] = $results;
}

Expand Down Expand Up @@ -227,30 +213,35 @@ protected static function import($plugin, $autocreate = true, JEventDispatcher $
{
static $paths = array();

// Ensure we have a dispatcher now so we can correctly track the loaded paths
$dispatcher = $dispatcher ?: JEventDispatcher::getInstance();

// Get the dispatcher's hash to allow paths to be tracked against unique dispatchers
$dispatcherHash = spl_object_hash($dispatcher);

if (!isset($paths[$dispatcherHash]))
{
$paths[$dispatcherHash] = array();
}

$plugin->type = preg_replace('/[^A-Z0-9_\.-]/i', '', $plugin->type);
$plugin->name = preg_replace('/[^A-Z0-9_\.-]/i', '', $plugin->name);

$path = JPATH_PLUGINS . '/' . $plugin->type . '/' . $plugin->name . '/' . $plugin->name . '.php';

if (!isset($paths[$path]))
if (!isset($paths[$dispatcherHash][$path]))
{
if (file_exists($path))
{
if (!isset($paths[$path]))
if (!isset($paths[$dispatcherHash][$path]))
{
require_once $path;
}

$paths[$path] = true;
$paths[$dispatcherHash][$path] = true;

if ($autocreate)
{
// Makes sure we have an event dispatcher
if (!is_object($dispatcher))
{
$dispatcher = JEventDispatcher::getInstance();
}

$className = 'Plg' . $plugin->type . $plugin->name;

if (class_exists($className))
Expand All @@ -269,7 +260,7 @@ protected static function import($plugin, $autocreate = true, JEventDispatcher $
}
else
{
$paths[$path] = false;
$paths[$dispatcherHash][$path] = false;
}
}
}
Expand Down

0 comments on commit 341db17

Please sign in to comment.