ElggPluginManifestParser17.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Plugin manifest.xml parser for Elgg 1.7 and lower.
  4. *
  5. * @package Elgg.Core
  6. * @subpackage Plugins
  7. * @since 1.8
  8. */
  9. class ElggPluginManifestParser17 extends \ElggPluginManifestParser {
  10. /**
  11. * The valid top level attributes and defaults for a 1.7 manifest
  12. */
  13. protected $validAttributes = array(
  14. 'author', 'version', 'description', 'website',
  15. 'copyright', 'license', 'licence', 'elgg_version',
  16. // were never really used and not enforced in code.
  17. 'requires', 'recommends', 'conflicts',
  18. // not a 1.7 field, but we need it
  19. 'name',
  20. );
  21. /**
  22. * Parse a manifest object from 1.7 or earlier.
  23. *
  24. * @return void
  25. */
  26. public function parse() {
  27. if (!isset($this->manifestObject->children)) {
  28. return false;
  29. }
  30. $elements = array();
  31. foreach ($this->manifestObject->children as $element) {
  32. $key = $element->attributes['key'];
  33. $value = $element->attributes['value'];
  34. // create arrays if multiple fields are set
  35. if (array_key_exists($key, $elements)) {
  36. if (!is_array($elements[$key])) {
  37. $orig = $elements[$key];
  38. $elements[$key] = array($orig);
  39. }
  40. $elements[$key][] = $value;
  41. } else {
  42. $elements[$key] = $value;
  43. }
  44. }
  45. if ($elements && !array_key_exists('name', $elements)) {
  46. $elements['name'] = $this->caller->getName();
  47. }
  48. $this->manifest = $elements;
  49. if (!$this->manifest) {
  50. return false;
  51. }
  52. return true;
  53. }
  54. /**
  55. * Return an attribute in the manifest.
  56. *
  57. * Overrides \ElggPluginManifestParser::getAttribute() because before 1.8
  58. * there were no rules...weeeeeeeee!
  59. *
  60. * @param string $name Attribute name
  61. * @return mixed
  62. */
  63. public function getAttribute($name) {
  64. if (isset($this->manifest[$name])) {
  65. return $this->manifest[$name];
  66. }
  67. return false;
  68. }
  69. }