aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggPluginManifestParser18.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-30 03:56:34 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-30 03:56:34 +0000
commit8173f672f06ad2783d3d0112e7b285d2240f488b (patch)
tree283496b227e083fb18ee628f9a6b8b40a0b24edb /engine/classes/ElggPluginManifestParser18.php
parentcaef932790b72de1efa5b8ef2065dd3ca3b9eb5a (diff)
downloadelgg-8173f672f06ad2783d3d0112e7b285d2240f488b.tar.gz
elgg-8173f672f06ad2783d3d0112e7b285d2240f488b.tar.bz2
Refs #1986 #2170 #2225 Added ElggPluginManifest, ElggPluginManifestParser, and its parser classes for 1.7 and 1.8 style manifests. Changed load_plugin_manifest() to use new parser. Added initial unit tests.
git-svn-id: http://code.elgg.org/elgg/trunk@7481 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/classes/ElggPluginManifestParser18.php')
-rw-r--r--engine/classes/ElggPluginManifestParser18.php119
1 files changed, 119 insertions, 0 deletions
diff --git a/engine/classes/ElggPluginManifestParser18.php b/engine/classes/ElggPluginManifestParser18.php
new file mode 100644
index 000000000..1d4e9daed
--- /dev/null
+++ b/engine/classes/ElggPluginManifestParser18.php
@@ -0,0 +1,119 @@
+<?php
+/**
+ * Plugin manifest.xml parser for Elgg 1.8 and above.
+ *
+ * @package Elgg.Core
+ * @subpackage Plugins
+ */
+class ElggPluginManifestParser18 extends ElggPluginManifestParser {
+ /**
+ * The valid top level attributes and defaults for a 1.8 manifest array.
+ *
+ * @var array
+ */
+ protected $validAttributes = array(
+ 'name' => null,
+ 'author' => null,
+ 'version' => null,
+ 'blurb' => null,
+ 'description' => null,
+ 'website' => null,
+ 'copyright' => null,
+ 'license' => 'GNU Public License version 2',
+ 'depends' => array(),
+ 'screenshots' => array(),
+ 'conflicts' => array(),
+ 'provides' => array(),
+ 'admin' => array(
+ 'on_enable' => null,
+ 'on_disable' => null,
+ 'interface_type' => 'advanced'
+ )
+ );
+
+ /**
+ * Required attributes for a valid 1.8 manifest
+ *
+ * @var array
+ */
+ protected $requiredAttributes = array(
+ 'name', 'author', 'version', 'description', 'depends'
+ );
+
+ /**
+ * Parse a manifest object from 1.8 and later
+ *
+ * @return void
+ */
+ public function parse() {
+ $parsed = array();
+ foreach ($this->manifestObject->children as $element) {
+ switch ($element->name) {
+ // single elements
+ // translatable
+ case 'blurb':
+ case 'description':
+ $element->content = elgg_echo($element->content);
+
+ case 'name':
+ case 'author':
+ case 'version':
+ case 'website':
+ case 'copyright':
+ case 'license':
+ $parsed[$element->name] = $element->content;
+ break;
+
+ // arrays
+ case 'screenshot':
+ if (isset($element->attributes['description'])) {
+ $description = elgg_echo($element->attributes['description']);
+ }
+ $parsed['screenshots'][] = array(
+ 'description' => $description,
+ 'path' => $element->content
+ );
+ break;
+
+ case 'admin':
+ $parsed['admin'] = array();
+ if (!isset($element->children)) {
+ return false;
+ }
+
+ foreach ($element->children as $child_element) {
+ $parsed['admin'][$child_element->name] = $child_element->content;
+ }
+
+ break;
+
+ case 'provides':
+ case 'conflicts':
+ case 'depends':
+ if (!isset($element->children)) {
+ return false;
+ }
+
+ $info = array();
+ foreach ($element->children as $child_element) {
+ $info[$child_element->name] = $child_element->content;
+ }
+
+ $parsed[$element->name][] = $info;
+ break;
+ }
+ }
+
+ // check we have all the required fields
+ foreach ($this->requiredAttributes as $attr) {
+ if (!array_key_exists($attr, $parsed)) {
+ throw new PluginException(elgg_echo('PluginException:ParserErrorMissingRequiredAttribute',
+ array($attr, $this->caller->getPluginID())));
+ }
+ }
+
+ $this->manifest = $parsed;
+
+ return true;
+ }
+} \ No newline at end of file