From 5a551760b09ad40f83f624c0fc22c5e677d0910e Mon Sep 17 00:00:00 2001 From: brettp Date: Tue, 14 Dec 2010 03:01:24 +0000 Subject: Cleaned up constructor logic for ElggPluginPackage. Better detection of invalid paths. git-svn-id: http://code.elgg.org/elgg/trunk@7614 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggPluginPackage.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/engine/classes/ElggPluginPackage.php b/engine/classes/ElggPluginPackage.php index 4a10da43d..8bbacce22 100644 --- a/engine/classes/ElggPluginPackage.php +++ b/engine/classes/ElggPluginPackage.php @@ -95,28 +95,29 @@ class ElggPluginPackage { public function __construct($plugin, $validate = true) { if (substr($plugin, 0, 1) == '/') { // this is a path - $plugin = sanitise_filepath($plugin); - - if (!is_dir($plugin)) { - throw new PluginException(elgg_echo('PluginException:InvalidPath', array($plugin))); - } + $path = sanitise_filepath($plugin); // the id is the last element of the array - $path_array = explode('/', trim($plugin, '/')); - $this->id = array_pop($path_array); - $this->path = $plugin; + $path_array = explode('/', trim($path, '/')); + $id = array_pop($path_array); } else { - // this is a plugin name - + // this is a plugin id // strict plugin names if (preg_match('/[^a-z0-9\.\-_]/i', $id)) { throw new PluginException(elgg_echo('PluginException:InvalidID', array($plugin))); } - $this->id = $plugin; - $this->path = get_config('pluginspath') . "$plugin/"; + $path = get_config('pluginspath') . "$plugin/"; + $id = $plugin; } + if (!is_dir($path)) { + throw new PluginException(elgg_echo('PluginException:InvalidPath', array($path))); + } + + $this->path = $path; + $this->id = $id; + if ($validate && !$this->isValid()) { if ($this->invalidPluginError) { throw new PluginException(elgg_echo('PluginException:InvalidPlugin:Details', -- cgit v1.2.3