Changeset 3730:5c45a5df9a59 for inc/core/class.dc.store.parser.php
- Timestamp:
- 03/08/18 17:58:39 (8 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.store.parser.php
r2566 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 /** … … 18 18 19 19 Provides an object to parse XML feed of modules from a repository. 20 */20 */ 21 21 class dcStoreParser 22 22 { 23 /** @var objectXML object of feed contents */24 25 /** @var arrayArray of feed contents */26 27 /** @var stringXML bloc tag */28 23 /** @var object XML object of feed contents */ 24 protected $xml; 25 /** @var array Array of feed contents */ 26 protected $items; 27 /** @var string XML bloc tag */ 28 protected static $bloc = 'http://dotaddict.org/da/'; 29 29 30 31 32 33 * @param string $dataFeed content34 35 36 37 38 39 30 /** 31 * Constructor. 32 * 33 * @param string $data Feed content 34 */ 35 public function __construct($data) 36 { 37 if (!is_string($data)) { 38 throw new Exception(__('Failed to read data feed')); 39 } 40 40 41 $this->xml= simplexml_load_string($data);42 41 $this->xml = simplexml_load_string($data); 42 $this->items = array(); 43 43 44 45 46 44 if ($this->xml === false) { 45 throw new Exception(__('Wrong data feed')); 46 } 47 47 48 48 $this->_parse(); 49 49 50 51 52 50 unset($data); 51 unset($this->xml); 52 } 53 53 54 55 56 57 58 59 60 61 54 /** 55 * Parse XML into array 56 */ 57 protected function _parse() 58 { 59 if (empty($this->xml->module)) { 60 return; 61 } 62 62 63 64 63 foreach ($this->xml->module as $i) { 64 $attrs = $i->attributes(); 65 65 66 66 $item = array(); 67 67 68 69 $item['id']= (string) $attrs['id'];70 $item['file']= (string) $i->file;71 $item['label']= (string) $i->name; // deprecated72 $item['name']= (string) $i->name;73 $item['version']= (string) $i->version;74 $item['author']= (string) $i->author;75 $item['desc']= (string) $i->desc;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 76 77 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;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; 83 83 84 85 foreach($i->children(self::$bloc)->tags as $t) {86 87 88 $item['tags'] = implode(', ',$tags);84 $tags = array(); 85 foreach ($i->children(self::$bloc)->tags as $t) { 86 $tags[] = (string) $t->tag; 87 } 88 $item['tags'] = implode(', ', $tags); 89 89 90 91 92 93 94 95 90 # First filter right now. If DC_DEV is set all modules are parse 91 if (defined('DC_DEV') && DC_DEV === true || dcUtils::versionsCompare(DC_VERSION, $item['dc_min'], '>=', false)) { 92 $this->items[$item['id']] = $item; 93 } 94 } 95 } 96 96 97 98 99 100 * @return arrayModules list101 102 103 104 105 97 /** 98 * Get modules. 99 * 100 * @return array Modules list 101 */ 102 public function getModules() 103 { 104 return $this->items; 105 } 106 106 }
Note: See TracChangeset
for help on using the changeset viewer.