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