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