diff options
Diffstat (limited to 'engine')
-rw-r--r-- | engine/classes/ElggPlugin.php | 35 | ||||
-rw-r--r-- | engine/classes/ElggPluginManifest.php | 8 | ||||
-rw-r--r-- | engine/classes/ElggPluginPackage.php | 74 | ||||
-rw-r--r-- | engine/lib/plugins.php | 127 |
4 files changed, 196 insertions, 48 deletions
diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php index 2fe29d175..3352105f8 100644 --- a/engine/classes/ElggPlugin.php +++ b/engine/classes/ElggPlugin.php @@ -131,7 +131,7 @@ class ElggPlugin extends ElggObject { * @return string */ public function getPath() { - return $this->path; + return sanitise_filepath($this->path); } @@ -179,20 +179,6 @@ class ElggPlugin extends ElggObject { $old_priority = (int) $this->getPriority(); $max_priority = elgg_get_max_plugin_priority(); - if ($priority == $old_priority) { - return false; - } - - // there's nothing above the max. - if ($priority > $max_priority) { - $priority = $max_priority; - } - - // there's nothing below 1. - if ($priority < 1) { - $priority = 1; - } - // (int) 0 matches (string) first, so cast to string. $priority = (string) $priority; @@ -220,6 +206,20 @@ class ElggPlugin extends ElggObject { return false; } + if ($priority == $old_priority) { + return false; + } + + // there's nothing above the max. + if ($priority > $max_priority) { + $priority = $max_priority; + } + + // there's nothing below 1. + if ($priority < 1) { + $priority = 1; + } + if ($priority > $old_priority) { $op = '-'; $where = "CAST(value as unsigned) BETWEEN $old_priority AND $priority"; @@ -489,6 +489,11 @@ class ElggPlugin extends ElggObject { if ($this->isActive($site_guid)) { return false; } + + if (!$this->canActivate()) { + return false; + } + // set in the db, now perform tasks and emit events if ($this->setStatus(true, $site_guid)) { // emit an event. returning false will make this not be activated. diff --git a/engine/classes/ElggPluginManifest.php b/engine/classes/ElggPluginManifest.php index 290a59a0c..9ddf60396 100644 --- a/engine/classes/ElggPluginManifest.php +++ b/engine/classes/ElggPluginManifest.php @@ -249,7 +249,13 @@ class ElggPluginManifest { * @return sting */ public function getLicense() { - return $this->parser->getAttribute('license'); + // license vs licence. Use license. + $en_us = $this->parser->getAttribute('license'); + if ($en_us) { + return $en_us; + } else { + return $this->parser->getAttribute('licence'); + } } diff --git a/engine/classes/ElggPluginPackage.php b/engine/classes/ElggPluginPackage.php index dcc6918d0..fd54ff731 100644 --- a/engine/classes/ElggPluginPackage.php +++ b/engine/classes/ElggPluginPackage.php @@ -334,27 +334,33 @@ class ElggPluginPackage { } // unless we're doing a full report, break as soon as we fail. - if (!$full_report && !$result) { - return $result; + if (!$full_report && !$result['status']) { + return $result['status']; } else { // build report element and comment - if ($dep_type == 'requires') { - $comment = ''; - } elseif ($dep_type == 'conflicts') { - $comment = ''; - } - $report[] = array( 'type' => $dep_type, 'dep' => $dep, - 'status' => $result, - 'comment' => $comment + 'status' => $result['status'], + 'value' => $result['value'] ); } } } if ($full_report) { + // add provides to full report + $provides = $this->getManifest()->getProvides(); + + foreach ($provides as $provide) { + $report[] = array( + 'type' => 'provides', + 'dep' => $provide, + 'status' => true, + 'value' => '' + ); + } + return $report; } @@ -373,7 +379,7 @@ class ElggPluginPackage { $r = elgg_check_plugins_provides('plugin', $dep['name'], $dep['version'], $dep['comparison']); if ($inverse) { - $r = !$r; + $r['status'] = !$r['status']; } return $r; @@ -388,13 +394,16 @@ class ElggPluginPackage { * @return bool */ private function checkDepElgg(array $dep, $elgg_version, $inverse = false) { - $r = version_compare($elgg_version, $dep['version'], $dep['comparison']); + $status = version_compare($elgg_version, $dep['version'], $dep['comparison']); if ($inverse) { - $r = !$r; + $status = !$status; } - return $r; + return array( + 'status' => $status, + 'value' => $elgg_version + ); } /** @@ -403,7 +412,10 @@ class ElggPluginPackage { * @todo Can this be merged with the plugin checker? * * @param array $dep An Elgg manifest.xml deps array - * @return bool + * @return array An array in the form array( + * 'status' => bool + * 'value' => string The version provided + * ) */ private function checkDepPhpExtension(array $dep) { $name = $dep['name']; @@ -411,21 +423,34 @@ class ElggPluginPackage { $comparison = $dep['comparison']; // not enabled. - $r = extension_loaded($name); + $status = extension_loaded($name); // enabled. check version. $ext_version = phpversion($name); - if ($version && !version_compare($ext_version, $version, $comparison)) { - $r = false; + if ($status) { + // some extensions (like gd) don't provide versions. neat. + // don't check version info and return a lie. + if ($ext_version && $version) { + $status = version_compare($ext_version, $version, $comparison); + } + + if (!$ext_version) { + $ext_version = '???'; + } } // some php extensions can be emulated, so check provides. - if ($r == false) { - $r = elgg_check_plugins_provides('php_extension', $name, $version, $comparison); + if ($status == false) { + $provides = elgg_check_plugins_provides('php_extension', $name, $version, $comparison); + $status = $provides['status']; + $ext_version = $provides['value']; } - return $r; + return array( + 'status' => $status, + 'value' => $ext_version + ); } /** @@ -448,9 +473,12 @@ class ElggPluginPackage { $setting = 0; } - $r = version_compare($setting, $value, $comparison); + $status = version_compare($setting, $value, $comparison); - return $r; + return array( + 'status' => $status, + 'value' => $setting + ); } /** diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index cfb27cd8c..9a3dd630a 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -727,23 +727,132 @@ function elgg_get_plugins_provides($type = null, $name = null) { * @param string $version A version to check against * @param string $comparison The comparison operator to use in version_compare() * - * @return bool + * @return array An array in the form array( + * 'status' => bool Does the provide exist?, + * 'value' => string The version provided + * ) * @since 1.8 */ function elgg_check_plugins_provides($type, $name, $version = null, $comparison = 'ge') { if (!$provided = elgg_get_plugins_provides($type, $name)) { - return false; + return array( + 'status' => false, + 'version' => '' + ); } if ($provided) { + $version = $provided['version']; if ($version) { - return version_compare($provided['version'], $version, $comparison); + $status = version_compare($provided['version'], $version, $comparison); } else { - return true; + $status = true; } } + + return array( + 'status' => $r, + 'value' => $version + ); +} + +/** + * Returns an array of parsed strings for a dependency in the + * format: array( + * 'type' => requires, conflicts, or provides. + * 'name' => The name of the requirement / conflict + * 'value' => A string representing the expected value: <1, >=3, !=enabled + * 'local_value' => The current value, ("Not installed") + * 'comment' => Free form text to help resovle the problem ("Enable / Search for plugin <link>") + * ) + * + * @param array $dep An ElggPluginPackage dependency array + * @return array + */ +function elgg_get_plugin_dependency_strings($dep) { + $dep_system = elgg_get_array_value('type', $dep); + $info = elgg_get_array_value('dep', $dep); + $type = elgg_get_array_value('type', $info); + + if (!$dep_system || !$info || !$type) { + return false; + } + + // rewrite some of these to be more readable + switch($info['comparison']) { + case 'lt': + $comparison = '<'; + break; + case 'gt': + $comparison = '>'; + break; + case 'ge': + $comparison = '>='; + break; + case 'le': + $comparison = '<='; + break; + default; + $comparison = $info['comparison']; + break; + } + + /* + 'requires' 'plugin oauth_lib' <1.3 1.3 'downgrade' + 'requires' 'php setting bob' >3 3 'change it' + 'conflicts' 'php setting' >3 4 'change it' + 'provides' 'plugin oauth_lib' 1.3 -- -- + */ + $strings = array(); + $strings['type'] = elgg_echo('ElggPlugin:Dependencies:' . ucwords($dep_system)); + + switch ($type) { + case 'elgg_version': + case 'elgg_release': + // 'Elgg Version' + $strings['name'] = elgg_echo('ElggPlugin:Dependencies:Elgg'); + $strings['value'] = "$comparison {$info['version']}"; + $strings['local_value'] = $dep['value']; + $strings['comment'] = ''; + break; + + case 'php_extension': + // PHP Extension %s [version] + $strings['name'] = elgg_echo('ElggPlugin:Dependencies:PhpExtension', array($info['name'])); + if ($info['version']) { + $strings['value'] = "$comparison {$info['version']}"; + $strings['local_value'] = $dep['value']; + } else { + $strings['value'] = ''; + $strings['local_value'] = ''; + } + $strings['comment'] = ''; + break; + + case 'php_ini': + $strings['name'] = elgg_echo('ElggPlugin:Dependencies:PhpIni', array($info['name'])); + $strings['value'] = "$comparison {$info['value']}"; + $strings['local_value'] = $dep['value']; + $strings['comment'] = ''; + break; + + case 'plugin': + $strings['name'] = elgg_echo('ElggPlugin:Dependencies:Plugin', array($info['name'])); + $strings['value'] = "$comparison {$info['version']}"; + $strings['local_value'] = $dep['version']; + $strings['comment'] = ''; + break; + } + + if ($dep['status']) { + $strings['comment'] = elgg_echo('ok'); + } + + return $strings; } + + /** * Shorthand function for finding the plugin settings. * @@ -1208,12 +1317,12 @@ function plugin_init() { elgg_register_action("plugins/settings/save", '', 'admin'); elgg_register_action("plugins/usersettings/save"); - elgg_register_action('admin/plugins/enable', '', 'admin'); - elgg_register_action('admin/plugins/disable', '', 'admin'); - elgg_register_action('admin/plugins/enableall', '', 'admin'); - elgg_register_action('admin/plugins/disableall', '', 'admin'); + elgg_register_action('admin/plugins/activate', '', 'admin'); + elgg_register_action('admin/plugins/deactivate', '', 'admin'); + elgg_register_action('admin/plugins/activate_all', '', 'admin'); + elgg_register_action('admin/plugins/deactivate_all', '', 'admin'); - elgg_register_action('admin/plugins/reorder', '', 'admin'); + elgg_register_action('admin/plugins/set_priority', '', 'admin'); } elgg_register_event_handler('init', 'system', 'plugin_init');
\ No newline at end of file |