2013-04-05 05:34:07 +02:00
|
|
|
<?php
|
|
|
|
|
2013-06-29 03:50:15 +02:00
|
|
|
namespace PicoFeed\Parsers;
|
2013-04-05 05:34:07 +02:00
|
|
|
|
2013-06-29 03:50:15 +02:00
|
|
|
class Rss10 extends \PicoFeed\Parser
|
2013-04-05 05:34:07 +02:00
|
|
|
{
|
|
|
|
public function execute()
|
|
|
|
{
|
2013-08-30 01:34:11 +02:00
|
|
|
\PicoFeed\Logging::log(\get_called_class().': begin parsing');
|
|
|
|
|
2013-04-05 05:34:07 +02:00
|
|
|
\libxml_use_internal_errors(true);
|
|
|
|
$xml = \simplexml_load_string($this->content);
|
|
|
|
|
|
|
|
if ($xml === false) {
|
2013-08-30 01:34:11 +02:00
|
|
|
\PicoFeed\Logging::log(\get_called_class().': XML parsing error');
|
2013-07-06 20:29:45 +02:00
|
|
|
\PicoFeed\Logging::log($this->getXmlErrors());
|
2013-04-05 05:34:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-07 16:58:46 +02:00
|
|
|
$namespaces = $xml->getNamespaces(true);
|
2013-04-05 05:34:07 +02:00
|
|
|
|
2013-06-29 19:41:36 +02:00
|
|
|
$this->title = $this->stripWhiteSpace((string) $xml->channel->title);
|
2013-04-05 05:34:07 +02:00
|
|
|
$this->url = (string) $xml->channel->link;
|
|
|
|
$this->id = $this->url;
|
|
|
|
|
2013-04-07 16:58:46 +02:00
|
|
|
if (isset($namespaces['dc'])) {
|
2013-04-05 05:34:07 +02:00
|
|
|
|
2013-04-07 16:58:46 +02:00
|
|
|
$ns_dc = $xml->channel->children($namespaces['dc']);
|
2013-04-05 05:34:07 +02:00
|
|
|
$this->updated = isset($ns_dc->date) ? strtotime($ns_dc->date) : time();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
$this->updated = time();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($xml->item as $entry) {
|
|
|
|
|
2013-04-07 16:58:46 +02:00
|
|
|
$item = new \StdClass;
|
2013-06-29 19:41:36 +02:00
|
|
|
$item->title = $this->stripWhiteSpace((string) $entry->title);
|
2013-04-07 16:58:46 +02:00
|
|
|
$item->url = '';
|
|
|
|
$item->author= '';
|
|
|
|
$item->updated = '';
|
|
|
|
$item->content = '';
|
2013-04-05 05:34:07 +02:00
|
|
|
|
2013-04-07 16:58:46 +02:00
|
|
|
foreach ($namespaces as $name => $url) {
|
2013-04-05 05:34:07 +02:00
|
|
|
|
2013-04-07 16:58:46 +02:00
|
|
|
$namespace = $entry->children($namespaces[$name]);
|
|
|
|
|
|
|
|
if (! $item->url && ! empty($namespace->origLink)) $item->url = (string) $namespace->origLink;
|
|
|
|
if (! $item->author && ! empty($namespace->creator)) $item->author = (string) $namespace->creator;
|
|
|
|
if (! $item->updated && ! empty($namespace->date)) $item->updated = strtotime((string) $namespace->date);
|
|
|
|
if (! $item->updated && ! empty($namespace->updated)) $item->updated = strtotime((string) $namespace->updated);
|
|
|
|
if (! $item->content && ! empty($namespace->encoded)) $item->content = (string) $namespace->encoded;
|
2013-04-05 05:34:07 +02:00
|
|
|
}
|
|
|
|
|
2013-04-07 16:58:46 +02:00
|
|
|
if (empty($item->url)) $item->url = (string) $entry->link;
|
|
|
|
if (empty($item->updated)) $item->updated = $this->updated;
|
|
|
|
|
|
|
|
if (empty($item->content)) {
|
2013-04-05 05:34:07 +02:00
|
|
|
|
2013-04-07 16:58:46 +02:00
|
|
|
$item->content = isset($entry->description) ? (string) $entry->description : '';
|
2013-04-05 05:34:07 +02:00
|
|
|
}
|
|
|
|
|
2013-04-07 16:58:46 +02:00
|
|
|
if (empty($item->author)) {
|
2013-04-05 05:34:07 +02:00
|
|
|
|
2013-04-07 16:58:46 +02:00
|
|
|
if (isset($entry->author)) {
|
2013-04-05 05:34:07 +02:00
|
|
|
|
2013-04-07 16:58:46 +02:00
|
|
|
$item->author = (string) $entry->author;
|
|
|
|
}
|
|
|
|
else if (isset($xml->channel->webMaster)) {
|
2013-04-05 05:34:07 +02:00
|
|
|
|
2013-04-07 16:58:46 +02:00
|
|
|
$item->author = (string) $xml->channel->webMaster;
|
|
|
|
}
|
2013-04-05 05:34:07 +02:00
|
|
|
}
|
|
|
|
|
2013-05-06 03:44:03 +02:00
|
|
|
if (empty($item->title)) $item->title = $item->url;
|
|
|
|
|
2013-07-27 03:00:39 +02:00
|
|
|
$item->id = $this->generateId($item->url, $this->url);
|
2013-04-07 16:58:46 +02:00
|
|
|
$item->content = $this->filterHtml($item->content, $item->url);
|
2013-04-05 05:34:07 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
|
2013-08-30 01:34:11 +02:00
|
|
|
\PicoFeed\Logging::log(\get_called_class().': parsing finished ('.count($this->items).' items)');
|
|
|
|
|
2013-04-05 05:34:07 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|