Dotclear

source: inc/core/class.dc.store.parser.php @ 3730:5c45a5df9a59

Revision 3730:5c45a5df9a59, 3.0 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Code formatting (PSR-2)

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@since 2.6
18
19Provides an object to parse XML feed of modules from a repository.
20 */
21class dcStoreParser
22{
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
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
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
54    /**
55     * Parse XML into array
56     */
57    protected function _parse()
58    {
59        if (empty($this->xml->module)) {
60            return;
61        }
62
63        foreach ($this->xml->module as $i) {
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;
83
84            $tags = array();
85            foreach ($i->children(self::$bloc)->tags as $t) {
86                $tags[] = (string) $t->tag;
87            }
88            $item['tags'] = implode(', ', $tags);
89
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
97    /**
98     * Get modules.
99     *
100     * @return    array        Modules list
101     */
102    public function getModules()
103    {
104        return $this->items;
105    }
106}
Note: See TracBrowser for help on using the repository browser.

Sites map