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)

RevLine 
[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 -----------------------------------------
[3730]12if (!defined('DC_RC_PATH')) {return;}
[2146]13
14/**
15@ingroup DC_CORE
[2214]16@brief Repository modules XML feed parser
[2222]17@since 2.6
[2146]18
[2214]19Provides an object to parse XML feed of modules from a repository.
[3730]20 */
[2216]21class dcStoreParser
[2146]22{
[3730]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/';
[2146]29
[3730]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        }
[2146]40
[3730]41        $this->xml   = simplexml_load_string($data);
42        $this->items = array();
[2146]43
[3730]44        if ($this->xml === false) {
45            throw new Exception(__('Wrong data feed'));
46        }
[2146]47
[3730]48        $this->_parse();
[2146]49
[3730]50        unset($data);
51        unset($this->xml);
52    }
[2146]53
[3730]54    /**
55     * Parse XML into array
56     */
57    protected function _parse()
58    {
59        if (empty($this->xml->module)) {
60            return;
61        }
[2146]62
[3730]63        foreach ($this->xml->module as $i) {
64            $attrs = $i->attributes();
[2146]65
[3730]66            $item = array();
[2146]67
[3730]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;
[2146]76
[3730]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;
[2214]83
[3730]84            $tags = array();
85            foreach ($i->children(self::$bloc)->tags as $t) {
86                $tags[] = (string) $t->tag;
87            }
88            $item['tags'] = implode(', ', $tags);
[2566]89
[3730]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    }
[2146]96
[3730]97    /**
98     * Get modules.
99     *
100     * @return    array        Modules list
101     */
102    public function getModules()
103    {
104        return $this->items;
105    }
[2146]106}
Note: See TracBrowser for help on using the repository browser.

Sites map