diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-12-14 03:01:24 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-12-14 03:01:24 +0000 |
commit | 5a551760b09ad40f83f624c0fc22c5e677d0910e (patch) | |
tree | e1288943bd38cb4f6255e11dffa350f67eada9f4 /engine/classes/ElggPluginPackage.php | |
parent | 4cc94c22cf097a0234e7cdf808224cab7f3caf44 (diff) | |
download | elgg-5a551760b09ad40f83f624c0fc22c5e677d0910e.tar.gz elgg-5a551760b09ad40f83f624c0fc22c5e677d0910e.tar.bz2 |
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
Diffstat (limited to 'engine/classes/ElggPluginPackage.php')
-rw-r--r-- | engine/classes/ElggPluginPackage.php | 25 |
1 files 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', |