[2146] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @brief Repository modules XML feed parser |
---|
| 4 | * |
---|
| 5 | * Provides an object to parse XML feed of modules from a repository. |
---|
| 6 | * |
---|
| 7 | * @package Dotclear |
---|
| 8 | * @subpackage Core |
---|
| 9 | * |
---|
| 10 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 11 | * @copyright GPL-2.0-only |
---|
| 12 | * |
---|
| 13 | * @since 2.6 |
---|
| 14 | */ |
---|
| 15 | |
---|
[3730] | 16 | if (!defined('DC_RC_PATH')) {return;} |
---|
[2146] | 17 | |
---|
[2216] | 18 | class dcStoreParser |
---|
[2146] | 19 | { |
---|
[3730] | 20 | /** @var object XML object of feed contents */ |
---|
| 21 | protected $xml; |
---|
| 22 | /** @var array Array of feed contents */ |
---|
| 23 | protected $items; |
---|
| 24 | /** @var string XML bloc tag */ |
---|
| 25 | protected static $bloc = 'http://dotaddict.org/da/'; |
---|
[2146] | 26 | |
---|
[3730] | 27 | /** |
---|
| 28 | * Constructor. |
---|
| 29 | * |
---|
| 30 | * @param string $data Feed content |
---|
| 31 | */ |
---|
| 32 | public function __construct($data) |
---|
| 33 | { |
---|
| 34 | if (!is_string($data)) { |
---|
| 35 | throw new Exception(__('Failed to read data feed')); |
---|
| 36 | } |
---|
[2146] | 37 | |
---|
[3730] | 38 | $this->xml = simplexml_load_string($data); |
---|
| 39 | $this->items = array(); |
---|
[2146] | 40 | |
---|
[3730] | 41 | if ($this->xml === false) { |
---|
| 42 | throw new Exception(__('Wrong data feed')); |
---|
| 43 | } |
---|
[2146] | 44 | |
---|
[3730] | 45 | $this->_parse(); |
---|
[2146] | 46 | |
---|
[3730] | 47 | unset($data); |
---|
| 48 | unset($this->xml); |
---|
| 49 | } |
---|
[2146] | 50 | |
---|
[3730] | 51 | /** |
---|
| 52 | * Parse XML into array |
---|
| 53 | */ |
---|
| 54 | protected function _parse() |
---|
| 55 | { |
---|
| 56 | if (empty($this->xml->module)) { |
---|
| 57 | return; |
---|
| 58 | } |
---|
[2146] | 59 | |
---|
[3730] | 60 | foreach ($this->xml->module as $i) { |
---|
| 61 | $attrs = $i->attributes(); |
---|
[2146] | 62 | |
---|
[3730] | 63 | $item = array(); |
---|
[2146] | 64 | |
---|
[3730] | 65 | # DC/DA shared markers |
---|
| 66 | $item['id'] = (string) $attrs['id']; |
---|
| 67 | $item['file'] = (string) $i->file; |
---|
| 68 | $item['label'] = (string) $i->name; // deprecated |
---|
| 69 | $item['name'] = (string) $i->name; |
---|
| 70 | $item['version'] = (string) $i->version; |
---|
| 71 | $item['author'] = (string) $i->author; |
---|
| 72 | $item['desc'] = (string) $i->desc; |
---|
[2146] | 73 | |
---|
[3730] | 74 | # DA specific markers |
---|
| 75 | $item['dc_min'] = (string) $i->children(self::$bloc)->dcmin; |
---|
| 76 | $item['details'] = (string) $i->children(self::$bloc)->details; |
---|
| 77 | $item['section'] = (string) $i->children(self::$bloc)->section; |
---|
| 78 | $item['support'] = (string) $i->children(self::$bloc)->support; |
---|
| 79 | $item['sshot'] = (string) $i->children(self::$bloc)->sshot; |
---|
[2214] | 80 | |
---|
[3730] | 81 | $tags = array(); |
---|
| 82 | foreach ($i->children(self::$bloc)->tags as $t) { |
---|
| 83 | $tags[] = (string) $t->tag; |
---|
| 84 | } |
---|
| 85 | $item['tags'] = implode(', ', $tags); |
---|
[2566] | 86 | |
---|
[3730] | 87 | # First filter right now. If DC_DEV is set all modules are parse |
---|
| 88 | if (defined('DC_DEV') && DC_DEV === true || dcUtils::versionsCompare(DC_VERSION, $item['dc_min'], '>=', false)) { |
---|
| 89 | $this->items[$item['id']] = $item; |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | } |
---|
[2146] | 93 | |
---|
[3730] | 94 | /** |
---|
| 95 | * Get modules. |
---|
| 96 | * |
---|
| 97 | * @return array Modules list |
---|
| 98 | */ |
---|
| 99 | public function getModules() |
---|
| 100 | { |
---|
| 101 | return $this->items; |
---|
| 102 | } |
---|
[2146] | 103 | } |
---|