/usr/share/php/arc/parsers/ARC2_RSSParser.php is in libarc-php 2.2.5-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | <?php
/*
homepage: http://arc.semsol.org/
license: http://arc.semsol.org/license
class: ARC2 RSS Parser
author: Benjamin Nowack
version: 2010-11-16
*/
ARC2::inc('LegacyXMLParser');
class ARC2_RSSParser extends ARC2_LegacyXMLParser {
function __construct($a, &$caller) {
parent::__construct($a, $caller);
}
function __init() {/* reader */
parent::__init();
$this->triples = array();
$this->target_encoding = '';
$this->t_count = 0;
$this->added_triples = array();
$this->skip_dupes = false;
$this->bnode_prefix = $this->v('bnode_prefix', 'arc'.substr(md5(uniqid(rand())), 0, 4).'b', $this->a);
$this->bnode_id = 0;
$this->cache = array();
$this->allowCDataNodes = 0;
}
/* */
function done() {
$this->extractRDF();
}
/* */
function setReader(&$reader) {
$this->reader = $reader;
}
function createBnodeID(){
$this->bnode_id++;
return '_:' . $this->bnode_prefix . $this->bnode_id;
}
function addT($t) {
//if (!isset($t['o_datatype']))
if ($this->skip_dupes) {
$h = md5(serialize($t));
if (!isset($this->added_triples[$h])) {
$this->triples[$this->t_count] = $t;
$this->t_count++;
$this->added_triples[$h] = true;
}
}
else {
$this->triples[$this->t_count] = $t;
$this->t_count++;
}
}
function getTriples() {
return $this->v('triples', array());
}
function countTriples() {
return $this->t_count;
}
function getSimpleIndex($flatten_objects = 1, $vals = '') {
return ARC2::getSimpleIndex($this->getTriples(), $flatten_objects, $vals);
}
/* */
function extractRDF() {
$index = $this->getNodeIndex();
$this->rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
$this->rss = 'http://purl.org/rss/1.0/';
$this->dc = 'http://purl.org/dc/elements/1.1/';
$this->dct = 'http://purl.org/dc/terms/';
$this->content = 'http://purl.org/rss/1.0/modules/content/';
$this->enc = 'http://purl.oclc.org/net/rss_2.0/enc#';
$this->mappings = array(
'channel' => $this->rss . 'channel',
'item' => $this->rss . 'item',
'title' => $this->rss . 'title',
'link' => $this->rss . 'link',
'description' => $this->rss . 'description',
'guid' => $this->dc . 'identifier',
'author' => $this->dc . 'creator',
'category' => $this->dc . 'subject',
'pubDate' => $this->dc . 'date',
'pubdate' => $this->dc . 'date',
'source' => $this->dc . 'source',
'enclosure' => $this->enc . 'enclosure',
);
$this->dt_props = array(
$this->dc . 'identifier',
$this->rss . 'link'
);
foreach ($index as $p_id => $nodes) {
foreach ($nodes as $pos => $node) {
$tag = $this->v('tag', '', $node);
if ($tag == 'channel') {
$struct = $this->extractChannel($index[$node['id']]);
$triples = ARC2::getTriplesFromIndex($struct);
foreach ($triples as $t) {
$this->addT($t);
}
}
elseif ($tag == 'item') {
$struct = $this->extractItem($index[$node['id']]);
$triples = ARC2::getTriplesFromIndex($struct);
foreach ($triples as $t) {
$this->addT($t);
}
}
}
}
}
function extractChannel($els) {
$res = array($this->rdf . 'type' => array(array('value' => $this->rss . 'channel', 'type' => 'uri')));
$res = array_merge($res, $this->extractProps($els, 'channel'));
return array($res[$this->rss . 'link'][0]['value'] => $res);
}
function extractItem($els) {
$res = array($this->rdf . 'type' => array(array('value' => $this->rss . 'item', 'type' => 'uri')));
$res = array_merge($res, $this->extractProps($els, 'item'));
if (isset($res[$this->rss . 'link'])) return array($res[$this->rss . 'link'][0]['value'] => $res);
if (isset($res[$this->dc . 'identifier'])) return array($res[$this->dc . 'identifier'][0]['value'] => $res);
}
function extractProps($els, $container) {
$res = array();
foreach ($els as $info) {
/* key */
$tag = $info['tag'];
if (!preg_match('/^[a-z0-9]+\:/i', $tag)) {
$k = isset($this->mappings[$tag]) ? $this->mappings[$tag] : '';
}
else {
$k = $tag;
}
if (($container == 'channel') && ($k == $this->rss . 'item')) continue;
/* val */
$v = $info['cdata'];
if (!$v) $v = $this->v('url', '', $info['a']);
if (!$v) $v = $this->v('href', '', $info['a']);
/* prop */
if ($k) {
/* enclosure handling */
if ($k == $this->enc . 'enclosure') {
$sub_res = array();
foreach (array('length', 'type') as $attr) {
if ($attr_v = $this->v($attr, 0, $info['a'])) {
$sub_res[$this->enc . $attr] = array(array('value' => $attr_v, 'type' => 'literal'));
}
}
$struct[$v] = $sub_res;
}
/* date handling */
if (in_array($k, array($this->dc . 'date', $this->dct . 'modified'))) {
if (!preg_match('/^[0-9]{4}/', $v) && ($sub_v = strtotime($v)) && ($sub_v != -1)) {
$tz = date('Z', $sub_v); /* timezone offset */
$sub_v -= $tz; /* utc */
$v = date('Y-m-d\TH:i:s\Z', $sub_v);
}
}
if (!isset($res[$k])) $res[$k] = array();
$res[$k][] = array('value' => $v, 'type' => in_array($k, $this->dt_props) || !preg_match('/^[a-z0-9]+\:[^\s]+$/is', $v) ? 'literal' : 'uri');
}
}
return $res;
}
/* */
}
|