diff options
Diffstat (limited to 'engine/classes/ElggPluginPackage.php')
| -rw-r--r-- | engine/classes/ElggPluginPackage.php | 143 |
1 files changed, 101 insertions, 42 deletions
diff --git a/engine/classes/ElggPluginPackage.php b/engine/classes/ElggPluginPackage.php index 48a5fc4a8..37eb4bf4d 100644 --- a/engine/classes/ElggPluginPackage.php +++ b/engine/classes/ElggPluginPackage.php @@ -28,6 +28,17 @@ class ElggPluginPackage { ); /** + * The optional files that can be read and served through the markdown page handler + * @var array + */ + private $textFiles = array( + 'README.txt', 'CHANGES.txt', + 'INSTALL.txt', 'COPYRIGHT.txt', 'LICENSE.txt', + + 'README', 'README.md', 'README.markdown' + ); + + /** * Valid types for provides. * * @var array @@ -48,7 +59,7 @@ class ElggPluginPackage { /** * An invalid plugin error. */ - private $invalidPluginError = ''; + private $errorMsg = ''; /** * Any dependencies messages @@ -89,7 +100,6 @@ class ElggPluginPackage { * @param string $plugin The ID (directory name) or full path of the plugin. * @param bool $validate Automatically run isValid()? * - * @return true * @throws PluginException */ public function __construct($plugin, $validate = true) { @@ -106,7 +116,7 @@ class ElggPluginPackage { } else { // this is a plugin id // strict plugin names - if (preg_match('/[^a-z0-9\.\-_]/i', $id)) { + if (preg_match('/[^a-z0-9\.\-_]/i', $plugin)) { throw new PluginException(elgg_echo('PluginException:InvalidID', array($plugin))); } @@ -122,9 +132,9 @@ class ElggPluginPackage { $this->id = $id; if ($validate && !$this->isValid()) { - if ($this->invalidPluginError) { + if ($this->errorMsg) { throw new PluginException(elgg_echo('PluginException:InvalidPlugin:Details', - array($plugin, $this->invalidPluginError))); + array($plugin, $this->errorMsg))); } else { throw new PluginException(elgg_echo('PluginException:InvalidPlugin', array($plugin))); } @@ -155,14 +165,12 @@ class ElggPluginPackage { return $this->valid; } - $valid = true; - // check required files. $have_req_files = true; foreach ($this->requiredFiles as $file) { if (!is_readable($this->path . $file)) { $have_req_files = false; - $this->invalidPluginError = + $this->errorMsg = elgg_echo('ElggPluginPackage:InvalidPlugin:MissingFile', array($file)); break; } @@ -170,23 +178,21 @@ class ElggPluginPackage { // check required files if (!$have_req_files) { - $valid = false; + return $this->valid = false; } // check for valid manifest. if (!$this->loadManifest()) { - $valid = false; + return $this->valid = false; } // can't require or conflict with yourself or something you provide. // make sure provides are all valid. if (!$this->isSaneDeps()) { - $valid = false; + return $this->valid = false; } - $this->valid = $valid; - - return $valid; + return $this->valid = true; } /** @@ -206,6 +212,7 @@ class ElggPluginPackage { return false; } + // Note: $conflicts and $requires are not unused. They're called dynamically $conflicts = $this->getManifest()->getConflicts(); $requires = $this->getManifest()->getRequires(); $provides = $this->getManifest()->getProvides(); @@ -213,7 +220,7 @@ class ElggPluginPackage { foreach ($provides as $provide) { // only valid provide types if (!in_array($provide['type'], $this->providesSupportedTypes)) { - $this->invalidPluginError = + $this->errorMsg = elgg_echo('ElggPluginPackage:InvalidPlugin:InvalidProvides', array($provide['type'])); return false; } @@ -223,7 +230,7 @@ class ElggPluginPackage { foreach (array('conflicts', 'requires') as $dep_type) { foreach (${$dep_type} as $dep) { if (!in_array($dep['type'], $this->depsSupportedTypes)) { - $this->invalidPluginError = + $this->errorMsg = elgg_echo('ElggPluginPackage:InvalidPlugin:InvalidDependency', array($dep['type'])); return false; } @@ -233,7 +240,7 @@ class ElggPluginPackage { $version_compare = version_compare($provide['version'], $dep['version'], $dep['comparison']); if ($version_compare) { - $this->invalidPluginError = + $this->errorMsg = elgg_echo('ElggPluginPackage:InvalidPlugin:CircularDep', array($dep['type'], $dep['name'], $this->id)); @@ -279,6 +286,7 @@ class ElggPluginPackage { try { $this->manifest = new ElggPluginManifest($file, $this->id); } catch (Exception $e) { + $this->errorMsg = $e->getMessage(); return false; } @@ -286,9 +294,22 @@ class ElggPluginPackage { return true; } + $this->errorMsg = elgg_echo('unknown_error'); return false; } + /**************** + * Readme Files * + ***************/ + + /** + * Returns an array of present and readable text files + * + * @return array + */ + public function getTextFilenames() { + return $this->textFiles; + } /*********************** * Dependencies system * @@ -310,23 +331,30 @@ class ElggPluginPackage { * @return bool|array */ public function checkDependencies($full_report = false) { + // Note: $conflicts and $requires are not unused. They're called dynamically $requires = $this->getManifest()->getRequires(); $conflicts = $this->getManifest()->getConflicts(); + $enabled_plugins = elgg_get_plugins('active'); $this_id = $this->getID(); $report = array(); // first, check if any active plugin conflicts with us. foreach ($enabled_plugins as $plugin) { - $temp_conflicts = $plugin->manifest->getConflicts(); + $temp_conflicts = array(); + $temp_manifest = $plugin->getManifest(); + if ($temp_manifest instanceof ElggPluginManifest) { + $temp_conflicts = $plugin->getManifest()->getConflicts(); + } foreach ($temp_conflicts as $conflict) { if ($conflict['type'] == 'plugin' && $conflict['name'] == $this_id) { $result = $this->checkDepPlugin($conflict, $enabled_plugins, false); // rewrite the conflict to show the originating plugin - $conflict['name'] = $plugin->manifest->getName(); + $conflict['name'] = $plugin->getManifest()->getName(); if (!$full_report && !$result['status']) { + $this->errorMsg = "Conflicts with plugin \"{$plugin->getManifest()->getName()}\"."; return $result['status']; } else { $report[] = array( @@ -340,17 +368,25 @@ class ElggPluginPackage { } } - foreach (array('requires', 'conflicts') as $dep_type) { + $check_types = array('requires', 'conflicts'); + + if ($full_report) { + // Note: $suggests is not unused. It's called dynamically + $suggests = $this->getManifest()->getSuggests(); + $check_types[] = 'suggests'; + } + + foreach ($check_types as $dep_type) { $inverse = ($dep_type == 'conflicts') ? true : false; foreach (${$dep_type} as $dep) { switch ($dep['type']) { case 'elgg_version': - $result = $this->checkDepElgg($dep, get_version()); + $result = $this->checkDepElgg($dep, get_version(), $inverse); break; case 'elgg_release': - $result = $this->checkDepElgg($dep, get_version(true)); + $result = $this->checkDepElgg($dep, get_version(true), $inverse); break; case 'plugin': @@ -362,16 +398,17 @@ class ElggPluginPackage { break; case 'php_extension': - $result = $this->checkDepPhpExtension($dep); + $result = $this->checkDepPhpExtension($dep, $inverse); break; case 'php_ini': - $result = $this->checkDepPhpIni($dep); + $result = $this->checkDepPhpIni($dep, $inverse); break; } // unless we're doing a full report, break as soon as we fail. if (!$full_report && !$result['status']) { + $this->errorMsg = "Missing dependencies."; return $result['status']; } else { // build report element and comment @@ -408,7 +445,7 @@ class ElggPluginPackage { * Checks if $plugins meets the requirement by $dep. * * @param array $dep An Elgg manifest.xml deps array - * @param array $plugins A list of plugins as returned by get_installed_plugins(); + * @param array $plugins A list of plugins as returned by elgg_get_plugins(); * @param bool $inverse Inverse the results to use as a conflicts. * @return bool */ @@ -426,30 +463,34 @@ class ElggPluginPackage { * Checks if $plugins meets the requirement by $dep. * * @param array $dep An Elgg manifest.xml deps array - * @param array $plugins A list of plugins as returned by get_installed_plugins(); + * @param array $plugins A list of plugins as returned by elgg_get_plugins(); * @param bool $inverse Inverse the results to use as a conflicts. * @return bool */ private function checkDepPriority(array $dep, array $plugins, $inverse = false) { - // see if we exist as an ElggPlugin - $this_plugin = elgg_get_plugin_from_id($this->getID()); - $this_priority = $this_plugin->getPriority(); - - foreach ($plugins as $test_plugin) { - if ($test_plugin->getID() == $dep['plugin']) { - break; - } + // grab the ElggPlugin using this package. + $plugin_package = elgg_get_plugin_from_id($this->getID()); + $plugin_priority = $plugin_package->getPriority(); + $test_plugin = elgg_get_plugin_from_id($dep['plugin']); + + // If this isn't a plugin or the plugin isn't installed or active + // priority doesn't matter. Use requires to check if a plugin is active. + if (!$plugin_package || !$test_plugin || !$test_plugin->isActive()) { + return array( + 'status' => true, + 'value' => 'uninstalled' + ); } $test_plugin_priority = $test_plugin->getPriority(); switch ($dep['priority']) { case 'before': - $status = $this_priority < $test_plugin_priority; + $status = $plugin_priority < $test_plugin_priority; break; case 'after': - $status = $this_priority > $test_plugin_priority; + $status = $plugin_priority > $test_plugin_priority; break; default; @@ -457,7 +498,7 @@ class ElggPluginPackage { } // get the current value - if ($this_priority < $test_plugin_priority) { + if ($plugin_priority < $test_plugin_priority) { $value = 'before'; } else { $value = 'after'; @@ -499,13 +540,14 @@ class ElggPluginPackage { * * @todo Can this be merged with the plugin checker? * - * @param array $dep An Elgg manifest.xml deps array + * @param array $dep An Elgg manifest.xml deps array + * @param bool $inverse Inverse the result to use as a conflicts. * @return array An array in the form array( * 'status' => bool * 'value' => string The version provided * ) */ - private function checkDepPhpExtension(array $dep) { + private function checkDepPhpExtension(array $dep, $inverse = false) { $name = $dep['name']; $version = $dep['version']; $comparison = $dep['comparison']; @@ -535,6 +577,10 @@ class ElggPluginPackage { $ext_version = $provides['value']; } + if ($inverse) { + $status = !$status; + } + return array( 'status' => $status, 'value' => $ext_version @@ -544,10 +590,11 @@ class ElggPluginPackage { /** * Check if the PHP ini setting satisfies $dep. * - * @param array $dep An Elgg manifest.xml deps array + * @param array $dep An Elgg manifest.xml deps array + * @param bool $inverse Inverse the result to use as a conflicts. * @return bool */ - private function checkDepPhpIni($dep) { + private function checkDepPhpIni($dep, $inverse = false) { $name = $dep['name']; $value = $dep['value']; $comparison = $dep['comparison']; @@ -563,6 +610,10 @@ class ElggPluginPackage { $status = version_compare($setting, $value, $comparison); + if ($inverse) { + $status = !$status; + } + return array( 'status' => $status, 'value' => $setting @@ -578,4 +629,12 @@ class ElggPluginPackage { return $this->id; } -}
\ No newline at end of file + /** + * Returns the last error message. + * + * @return string + */ + public function getError() { + return $this->errorMsg; + } +} |
