1 | <?php |
---|
2 | # ***** BEGIN LICENSE BLOCK ***** |
---|
3 | # This file is part of daInstaller, a plugin for DotClear2. |
---|
4 | # Copyright (c) 2008-2010 Tomtom, Pep and contributors, for DotAddict.org. |
---|
5 | # All rights reserved. |
---|
6 | # |
---|
7 | # ***** END LICENSE BLOCK ***** |
---|
8 | |
---|
9 | /** |
---|
10 | * Class daModuleParserException |
---|
11 | */ |
---|
12 | class daModuleParserException extends Exception {} |
---|
13 | |
---|
14 | /** |
---|
15 | * Class daModulesParser |
---|
16 | */ |
---|
17 | class daModulesParser |
---|
18 | { |
---|
19 | protected $xml; |
---|
20 | protected $items; |
---|
21 | |
---|
22 | public function __construct($data) |
---|
23 | { |
---|
24 | if (!is_string($data)) { |
---|
25 | throw new daModuleParserException(__('Impossible to read data feed')); |
---|
26 | } |
---|
27 | |
---|
28 | $this->xml = simplexml_load_string($data); |
---|
29 | $this->items = array(); |
---|
30 | |
---|
31 | if ($this->xml === false) { |
---|
32 | throw new daModuleParserException(__('Wrong data feed')); |
---|
33 | } |
---|
34 | |
---|
35 | $this->_parse(); |
---|
36 | |
---|
37 | unset($data); |
---|
38 | unset($this->xml); |
---|
39 | } |
---|
40 | |
---|
41 | protected function _parse() |
---|
42 | { |
---|
43 | if (empty($this->xml->module)) { |
---|
44 | return; |
---|
45 | } |
---|
46 | |
---|
47 | foreach ($this->xml->module as $i) |
---|
48 | { |
---|
49 | $attrs = $i->attributes(); |
---|
50 | |
---|
51 | $item = array(); |
---|
52 | |
---|
53 | # DC/DA shared markers |
---|
54 | $item['id'] = (string) $attrs['id']; |
---|
55 | $item['file'] = (string) $i->file; |
---|
56 | $item['label'] = (string) $i->name; |
---|
57 | $item['version'] = (string) $i->version; |
---|
58 | $item['author'] = (string) $i->author; |
---|
59 | $item['desc'] = (string) $i->desc; |
---|
60 | |
---|
61 | # DA specific markers |
---|
62 | $item['dc_min'] = (string) $i->children('http://dotaddict.org/da/')->dcmin; |
---|
63 | $item['details'] = (string) $i->children('http://dotaddict.org/da/')->details; |
---|
64 | /*$item['section'] = (string) $i->children('http://dotaddict.org/da/')->section;*/ |
---|
65 | $item['support'] = (string) $i->children('http://dotaddict.org/da/')->support; |
---|
66 | $item['sshot'] = (string) $i->children('http://dotaddict.org/da/')->sshot; |
---|
67 | |
---|
68 | # First filter right now |
---|
69 | if (version_compare(DC_VERSION,$item['dc_min'],'>=')) { |
---|
70 | $this->items[$item['id']] = $item; |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | public function getModules() |
---|
76 | { |
---|
77 | return $this->items; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | ?> |
---|