Dotclear

source: inc/core/class.dc.repository.parser.php @ 2214:6d7d4c3f60d9

Revision 2214:6d7d4c3f60d9, 2.5 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Document and clean up dcRepository classes

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

Sites map