aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggPluginManifestParser17.php
blob: f439b5af0cbdfd412a9a3977cd8d3aa53c3b0d9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
 * Plugin manifest.xml parser for Elgg 1.7 and lower.
 *
 * @package    Elgg.Core
 * @subpackage Plugins
 * @since      1.8
 */
class ElggPluginManifestParser17 extends ElggPluginManifestParser {
	/**
	 * The valid top level attributes and defaults for a 1.7 manifest
	 */
	protected $validAttributes = array(
		'author', 'version', 'description', 'website',
		'copyright', 'license', 'elgg_version',

		// were never really used and not enforced in code.
		'requires', 'recommends', 'conflicts'
	);

	/**
	 * Parse a manifest object from 1.7 or earlier.
	 *
	 * @return void
	 */
	public function parse() {
		if (!isset($this->manifestObject->children)) {
			return false;
		}

		foreach ($this->manifestObject->children as $element) {
			$key = $element->attributes['key'];
			$value = $element->attributes['value'];

			// create arrays if multiple fields are set
			if (array_key_exists($key, $elements)) {
				if (!is_array($elements[$key])) {
					$orig = $elements[$key];
					$elements[$key] = array($orig);
				}

				$elements[$key][] = $value;
			} else {
				$elements[$key] = $value;
			}
		}

		if (!$this->manifest = $elements) {
			return false;
		}

		return true;
	}

	/**
	 * Return an attribute in the manifest.
	 *
	 * Overrides ElggPluginManifestParser::getAttribute() because before 1.8
	 * there were no rules...weeeeeeeee!
	 *
	 * @param string $name Attribute name
	 * @return mixed
	 */
	public function getAttribute($name) {
		if (isset($this->manifest[$name])) {
			return $this->manifest[$name];
		}

		return false;
	}
}