diff options
Diffstat (limited to 'engine/classes/ElggPluginManifest.php')
| -rw-r--r-- | engine/classes/ElggPluginManifest.php | 334 |
1 files changed, 258 insertions, 76 deletions
diff --git a/engine/classes/ElggPluginManifest.php b/engine/classes/ElggPluginManifest.php index ccd0d984a..6912c2b08 100644 --- a/engine/classes/ElggPluginManifest.php +++ b/engine/classes/ElggPluginManifest.php @@ -8,8 +8,8 @@ * as $this->parser. * * To add new parser versions, name them ElggPluginManifestParserXX - * where XX is the version specified in the top-level <plugin-manifest> - * tag. + * where XX is the version specified in the top-level <plugin_manifest> + * tag's XML namespace. * * @package Elgg.Core * @subpackage Plugins @@ -23,19 +23,34 @@ class ElggPluginManifest { protected $parser; /** - * The expected structure of a requires element + * The root for plugin manifest namespaces. + * This is in the format http://www.elgg.org/plugin_manifest/<version> */ - private $_depsRequiresStructPlugin = array( + protected $namespace_root = 'http://www.elgg.org/plugin_manifest/'; + + /** + * The expected structure of a plugins requires element + */ + private $depsStructPlugin = array( 'type' => '', 'name' => '', 'version' => '', 'comparison' => 'ge' ); + /** + * The expected structure of a priority element + */ + private $depsStructPriority = array( + 'type' => '', + 'priority' => '', + 'plugin' => '' + ); + /* - * The expected structure of elgg and elgg_release requires element + * The expected structure of elgg_version and elgg_release requires element */ - private $_depsRequiresStructElgg = array( + private $depsStructElgg = array( 'type' => '', 'version' => '', 'comparison' => 'ge' @@ -44,7 +59,7 @@ class ElggPluginManifest { /** * The expected structure of a requires php_ini dependency element */ - private $_depsRequiresStructPhpIni = array( + private $depsStructPhpIni = array( 'type' => '', 'name' => '', 'value' => '', @@ -54,7 +69,7 @@ class ElggPluginManifest { /** * The expected structure of a requires php_extension dependency element */ - private $_depsRequiresStructPhpExtension = array( + private $depsStructPhpExtension = array( 'type' => '', 'name' => '', 'version' => '', @@ -64,7 +79,7 @@ class ElggPluginManifest { /** * The expected structure of a conflicts depedency element */ - private $_depsConflictsStruct = array( + private $depsConflictsStruct = array( 'type' => '', 'name' => '', 'version' => '', @@ -74,7 +89,7 @@ class ElggPluginManifest { /** * The expected structure of a provides dependency element. */ - private $_depsProvidesStruct = array( + private $depsProvidesStruct = array( 'type' => '', 'name' => '', 'version' => '' @@ -83,7 +98,7 @@ class ElggPluginManifest { /** * The expected structure of a screenshot element */ - private $_screenshotStruct = array( + private $screenshotStruct = array( 'description' => '', 'path' => '' ); @@ -115,7 +130,7 @@ class ElggPluginManifest { } // see if we need to construct the xml object. - if ($manifest instanceof XmlElement) { + if ($manifest instanceof ElggXMLElement) { $manifest_obj = $manifest; } else { if (substr(trim($manifest), 0, 1) == '<') { @@ -135,12 +150,15 @@ class ElggPluginManifest { } // set manifest api version - if (isset($manifest_obj->attributes['version'])) { - $this->apiVersion = (float)$manifest_obj->attributes['version']; + if (isset($manifest_obj->attributes['xmlns'])) { + $namespace = $manifest_obj->attributes['xmlns']; + $version = str_replace($this->namespace_root, '', $namespace); } else { - $this->apiVersion = 1.7; + $version = 1.7; } + $this->apiVersion = $version; + $parser_class_name = 'ElggPluginManifestParser' . str_replace('.', '', $this->apiVersion); // @todo currently the autoloader freaks out if a class doesn't exist. @@ -225,7 +243,7 @@ class ElggPluginManifest { * @return string */ public function getDescription() { - return elgg_echo($this->parser->getAttribute('description')); + return $this->parser->getAttribute('description'); } /** @@ -234,7 +252,9 @@ class ElggPluginManifest { * @return string */ public function getBlurb() { - if (!$blurb = elgg_echo($this->parser->getAttribute('blurb'))) { + $blurb = $this->parser->getAttribute('blurb'); + + if (!$blurb) { $blurb = elgg_get_excerpt($this->getDescription()); } @@ -244,12 +264,44 @@ class ElggPluginManifest { /** * Returns the license * - * @return sting + * @return string */ 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'); + } + } + + /** + * Returns the repository url + * + * @return string + */ + public function getRepositoryURL() { + return $this->parser->getAttribute('repository'); + } + + /** + * Returns the bug tracker page + * + * @return string + */ + public function getBugTrackerURL() { + return $this->parser->getAttribute('bugtracker'); } + /** + * Returns the donations page + * + * @return string + */ + public function getDonationsPageURL() { + return $this->parser->getAttribute('donations'); + } /** * Returns the version of the plugin. @@ -293,10 +345,26 @@ class ElggPluginManifest { * @return array */ public function getCategories() { - if (!$cats = $this->parser->getAttribute('category')) { + $bundled_plugins = array('blog', 'bookmarks', 'categories', + 'custom_index', 'dashboard', 'developers', 'diagnostics', + 'embed', 'externalpages', 'file', 'garbagecollector', + 'groups', 'htmlawed', 'invitefriends', 'likes', + 'logbrowser', 'logrotate', 'members', 'messageboard', + 'messages', 'notifications', 'oauth_api', 'pages', 'profile', + 'reportedcontent', 'search', 'tagcloud', 'thewire', 'tinymce', + 'twitter', 'twitter_api', 'uservalidationbyemail', 'zaudio', + ); + + $cats = $this->parser->getAttribute('category'); + + if (!$cats) { $cats = array(); } + if (in_array('bundled', $cats) && !in_array($this->getPluginID(), $bundled_plugins)) { + unset($cats[array_search('bundled', $cats)]); + } + return $cats; } @@ -306,13 +374,15 @@ class ElggPluginManifest { * @return array */ public function getScreenshots() { - if (!$ss = $this->parser->getAttribute('screenshot')) { + $ss = $this->parser->getAttribute('screenshot'); + + if (!$ss) { $ss = array(); } $normalized = array(); foreach ($ss as $s) { - $normalized[] = $this->buildStruct($this->_screenshotStruct, $s); + $normalized[] = $this->buildStruct($this->screenshotStruct, $s); } return $normalized; @@ -324,7 +394,14 @@ class ElggPluginManifest { * @return array */ public function getProvides() { - if (!$provides = $this->parser->getAttribute('provides')) { + // normalize for 1.7 + if ($this->getApiVersion() < 1.8) { + $provides = array(); + } else { + $provides = $this->parser->getAttribute('provides'); + } + + if (!$provides) { $provides = array(); } @@ -339,7 +416,7 @@ class ElggPluginManifest { $normalized = array(); foreach ($provides as $provide) { - $normalized[] = $this->buildStruct($this->_depsProvidesStruct, $provide); + $normalized[] = $this->buildStruct($this->depsProvidesStruct, $provide); } return $normalized; @@ -351,88 +428,144 @@ class ElggPluginManifest { * @return array */ public function getRequires() { - if (!$reqs = $this->parser->getAttribute('requires')) { + // rewrite the 1.7 style elgg_version as a real requires. + if ($this->apiVersion < 1.8) { + $elgg_version = $this->parser->getAttribute('elgg_version'); + if ($elgg_version) { + $reqs = array( + array( + 'type' => 'elgg_version', + 'version' => $elgg_version, + 'comparison' => 'ge' + ) + ); + } else { + $reqs = array(); + } + } else { + $reqs = $this->parser->getAttribute('requires'); + } + + if (!$reqs) { $reqs = array(); } $normalized = array(); foreach ($reqs as $req) { + $normalized[] = $this->normalizeDep($req); + } - switch ($req['type']) { - case 'elgg': - case 'elgg_release': - $struct = $this->_depsRequiresStructElgg; - break; + return $normalized; + } - case 'plugin': - $struct = $this->_depsRequiresStructPlugin; - break; + /** + * Returns the suggests elements. + * + * @return array + */ + public function getSuggests() { + $suggests = $this->parser->getAttribute('suggests'); - case 'php_extension': - $struct = $this->_depsRequiresStructPhpExtension; - break; + if (!$suggests) { + $suggests = array(); + } - case 'php_ini': - $struct = $this->_depsRequiresStructPhpIni; - - // also normalize boolean values - if (isset($req['value'])) { - switch (strtolower($normalized_req['value'])) { - case 'yes': - case 'true': - case 'on': - case 1: - $normalized_req['value'] = 1; - break; - - case 'no': - case 'false': - case 'off': - case 0: - case '': - $normalized_req['value'] = 0; - break; - } - } + $normalized = array(); + foreach ($suggests as $suggest) { + $normalized[] = $this->normalizeDep($suggest); + } - break; - } + return $normalized; + } - $normalized_req = $this->buildStruct($struct, $req); + /** + * Normalizes a dependency array using the defined structs. + * Can be used with either requires or suggests. + * + * @param array $dep A dependency array. + * @return array The normalized deps array. + */ + private function normalizeDep($dep) { + switch ($dep['type']) { + case 'elgg_version': + case 'elgg_release': + $struct = $this->depsStructElgg; + break; + + case 'plugin': + $struct = $this->depsStructPlugin; + break; + + case 'priority': + $struct = $this->depsStructPriority; + break; + + case 'php_extension': + $struct = $this->depsStructPhpExtension; + break; + + case 'php_ini': + $struct = $this->depsStructPhpIni; + + // also normalize boolean values + if (isset($dep['value'])) { + switch (strtolower($dep['value'])) { + case 'yes': + case 'true': + case 'on': + case 1: + $dep['value'] = 1; + break; + + case 'no': + case 'false': + case 'off': + case 0: + case '': + $dep['value'] = 0; + break; + } + } + break; + default: + // unrecognized so we just return the raw dependency + return $dep; + } + + $normalized_dep = $this->buildStruct($struct, $dep); - // normalize comparison operators - switch ($normalized_req['comparison']) { + // normalize comparison operators + if (isset($normalized_dep['comparison'])) { + switch ($normalized_dep['comparison']) { case '<': - $normalized_req['comparison'] = 'lt'; + $normalized_dep['comparison'] = 'lt'; break; case '<=': - $normalized_req['comparison'] = 'le'; + $normalized_dep['comparison'] = 'le'; break; case '>': - $normalized_req['comparison'] = 'gt'; + $normalized_dep['comparison'] = 'gt'; break; case '>=': - $normalized_req['comparison'] = 'ge'; + $normalized_dep['comparison'] = 'ge'; break; case '==': case 'eq': - $normalized_req['comparison'] = '='; + $normalized_dep['comparison'] = '='; break; case '<>': case 'ne': - $normalized_req['comparison'] = '!='; + $normalized_dep['comparison'] = '!='; break; } - - $normalized[] = $normalized_req; } - return $normalized; + return $normalized_dep; } /** @@ -441,20 +574,50 @@ class ElggPluginManifest { * @return array */ public function getConflicts() { - if (!$conflicts = $this->parser->getAttribute('conflicts')) { + // normalize for 1.7 + if ($this->getApiVersion() < 1.8) { + $conflicts = array(); + } else { + $conflicts = $this->parser->getAttribute('conflicts'); + } + + if (!$conflicts) { $conflicts = array(); } $normalized = array(); foreach ($conflicts as $conflict) { - $normalized[] = $this->buildStruct($this->_depsConflictsStruct, $conflict); + $normalized[] = $this->buildStruct($this->depsConflictsStruct, $conflict); } return $normalized; } /** + * Should this plugin be activated when Elgg is installed + * + * @return bool + */ + public function getActivateOnInstall() { + $activate = $this->parser->getAttribute('activate_on_install'); + switch (strtolower($activate)) { + case 'yes': + case 'true': + case 'on': + case 1: + return true; + + case 'no': + case 'false': + case 'off': + case 0: + case '': + return false; + } + } + + /** * Normalizes an array into the structure specified * * @param array $struct The struct to normalize $element to. @@ -466,9 +629,28 @@ class ElggPluginManifest { $return = array(); foreach ($struct as $index => $default) { - $return[$index] = elgg_get_array_value($index, $array, $default); + $return[$index] = elgg_extract($index, $array, $default); } return $return; } -}
\ No newline at end of file + + /** + * Returns a category's friendly name. This can be localized by + * defining the string 'admin:plugins:category:<category>'. If no + * localization is found, returns the category with _ and - converted to ' ' + * and then ucwords()'d. + * + * @param str $category The category as defined in the manifest. + * @return str A human-readable category + */ + static public function getFriendlyCategory($category) { + $cat_raw_string = "admin:plugins:category:$category"; + $cat_display_string = elgg_echo($cat_raw_string); + if ($cat_display_string == $cat_raw_string) { + $category = str_replace(array('-', '_'), ' ', $category); + $cat_display_string = ucwords($category); + } + return $cat_display_string; + } +} |
