|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Rss/Atom Bundle for Symfony. |
|
5
|
|
|
* |
|
6
|
|
|
* |
|
7
|
|
|
* @license http://opensource.org/licenses/lgpl-3.0.html LGPL |
|
8
|
|
|
* @copyright (c) 2013, Alexandre Debril |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace Debril\RssAtomBundle\Protocol\Parser; |
|
11
|
|
|
|
|
12
|
|
|
use Debril\RssAtomBundle\Protocol\FeedInInterface; |
|
13
|
|
|
use Debril\RssAtomBundle\Protocol\FeedInterface; |
|
14
|
|
|
use Debril\RssAtomBundle\Protocol\ItemInInterface; |
|
15
|
|
|
use Debril\RssAtomBundle\Protocol\Parser; |
|
16
|
|
|
use SimpleXMLElement; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class RdfParser. |
|
20
|
|
|
*/ |
|
21
|
|
|
class RdfParser extends Parser |
|
22
|
|
|
{ |
|
23
|
|
|
protected $mandatoryFields = array( |
|
24
|
|
|
'channel', |
|
25
|
|
|
); |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* |
|
29
|
|
|
*/ |
|
30
|
1 |
|
public function __construct() |
|
31
|
|
|
{ |
|
32
|
1 |
|
$this->setdateFormats(array(\DateTime::W3C, 'Y-m-d')); |
|
33
|
1 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param SimpleXMLElement $xmlBody |
|
37
|
|
|
* |
|
38
|
|
|
* @return bool |
|
39
|
|
|
*/ |
|
40
|
2 |
|
public function canHandle(SimpleXMLElement $xmlBody) |
|
41
|
|
|
{ |
|
42
|
2 |
|
return 'rdf' === strtolower($xmlBody->getName()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param SimpleXMLElement $xmlBody |
|
47
|
|
|
* @param FeedInterface $feed |
|
48
|
|
|
* @param array $filters |
|
49
|
|
|
* |
|
50
|
|
|
* @return FeedInInterface |
|
51
|
|
|
*/ |
|
52
|
1 |
|
protected function parseBody(SimpleXMLElement $xmlBody, FeedInterface $feed, array $filters) |
|
53
|
|
|
{ |
|
54
|
1 |
|
$feed->setPublicId($xmlBody->channel->link); |
|
55
|
1 |
|
$feed->setLink($xmlBody->channel->link); |
|
56
|
1 |
|
$feed->setTitle($xmlBody->channel->title); |
|
57
|
1 |
|
$feed->setDescription($xmlBody->channel->description); |
|
58
|
|
|
|
|
59
|
1 |
|
if (isset($xmlBody->channel->date)) { |
|
60
|
1 |
|
$date = $xmlBody->channel->children('dc', true); |
|
61
|
1 |
|
$updated = static::convertToDateTime($date[0], $this->guessDateFormat($date[0])); |
|
62
|
1 |
|
$feed->setLastModified($updated); |
|
63
|
1 |
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
$format = null; |
|
66
|
1 |
|
foreach ($xmlBody->item as $xmlElement) { |
|
67
|
1 |
|
$item = $this->newItem(); |
|
68
|
1 |
|
$date = $xmlElement->children('dc', true); |
|
69
|
1 |
|
$format = !is_null($format) ? $format : $this->guessDateFormat($date[0]); |
|
70
|
|
|
|
|
71
|
1 |
|
$item->setTitle($xmlElement->title) |
|
72
|
1 |
|
->setDescription($xmlElement->description) |
|
73
|
1 |
|
->setUpdated(static::convertToDateTime($date[0], $format)) |
|
74
|
1 |
|
->setLink($xmlElement->link); |
|
75
|
|
|
|
|
76
|
1 |
|
$this->addValidItem($feed, $item, $filters); |
|
77
|
1 |
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
return $feed; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* RDF format doesn't support enclosures. |
|
84
|
|
|
* |
|
85
|
|
|
* @param SimpleXMLElement $element |
|
86
|
|
|
* @param ItemInInterface $item |
|
87
|
|
|
* |
|
88
|
|
|
* @return $this |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function handleEnclosure(SimpleXMLElement $element, ItemInInterface $item) |
|
91
|
|
|
{ |
|
92
|
|
|
return $this; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|