[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 |
---|
| 16 | @brief Rpeository modules feed parser |
---|
| 17 | |
---|
| 18 | Provides an object to parse feed of modules from repository. |
---|
| 19 | */ |
---|
| 20 | class dcRepositoryParser |
---|
| 21 | { |
---|
| 22 | protected $xml; |
---|
| 23 | protected $items; |
---|
| 24 | protected static $bloc = 'http://dotaddict.org/da/'; |
---|
| 25 | |
---|
| 26 | public function __construct($data) |
---|
| 27 | { |
---|
| 28 | if (!is_string($data)) { |
---|
| 29 | throw new Exception(__('Failed to read data feed')); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | $this->xml = simplexml_load_string($data); |
---|
| 33 | $this->items = array(); |
---|
| 34 | |
---|
| 35 | if ($this->xml === false) { |
---|
| 36 | throw new Exception(__('Wrong data feed')); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | $this->_parse(); |
---|
| 40 | |
---|
| 41 | unset($data); |
---|
| 42 | unset($this->xml); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | protected function _parse() |
---|
| 46 | { |
---|
| 47 | if (empty($this->xml->module)) { |
---|
| 48 | return; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | foreach ($this->xml->module as $i) |
---|
| 52 | { |
---|
| 53 | $attrs = $i->attributes(); |
---|
| 54 | |
---|
| 55 | $item = array(); |
---|
| 56 | |
---|
| 57 | # DC/DA shared markers |
---|
| 58 | $item['id'] = (string) $attrs['id']; |
---|
| 59 | $item['file'] = (string) $i->file; |
---|
| 60 | $item['label'] = (string) $i->name; // deprecated |
---|
| 61 | $item['name'] = (string) $i->name; |
---|
| 62 | $item['version'] = (string) $i->version; |
---|
| 63 | $item['author'] = (string) $i->author; |
---|
| 64 | $item['desc'] = (string) $i->desc; |
---|
| 65 | |
---|
| 66 | # DA specific markers |
---|
| 67 | $item['dc_min'] = (string) $i->children(self::$bloc)->dcmin; |
---|
| 68 | $item['details'] = (string) $i->children(self::$bloc)->details; |
---|
| 69 | $item['section'] = (string) $i->children(self::$bloc)->section; |
---|
| 70 | $item['support'] = (string) $i->children(self::$bloc)->support; |
---|
| 71 | $item['sshot'] = (string) $i->children(self::$bloc)->sshot; |
---|
| 72 | |
---|
| 73 | $tags = array(); |
---|
| 74 | foreach($i->children(self::$bloc)->tags as $t) |
---|
| 75 | { |
---|
| 76 | $tags[] = (string) $t->tag; |
---|
| 77 | } |
---|
| 78 | $item['tags'] = implode(', ',$tags); |
---|
| 79 | |
---|
| 80 | # First filter right now |
---|
| 81 | if (defined('DC_DEV') && DC_DEV === true || version_compare(DC_VERSION,$item['dc_min'],'>=')) { |
---|
| 82 | $this->items[$item['id']] = $item; |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | public function getModules() |
---|
| 88 | { |
---|
| 89 | return $this->items; |
---|
| 90 | } |
---|
| 91 | } |
---|