|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the feed-io package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Alexandre Debril <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace FeedIo\Standard; |
|
12
|
|
|
|
|
13
|
|
|
use DOMDocument; |
|
14
|
|
|
use FeedIo\Rule\Atom\LinkNode; |
|
15
|
|
|
use FeedIo\Rule\Description; |
|
16
|
|
|
use FeedIo\Rule\PublicId; |
|
17
|
|
|
use FeedIo\Rule\Atom\Category; |
|
18
|
|
|
use FeedIo\StandardAbstract; |
|
19
|
|
|
|
|
20
|
|
|
class Atom extends StandardAbstract |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Atom document must have a <feed> root node |
|
24
|
|
|
*/ |
|
25
|
|
|
const ROOT_NODE_TAGNAME = 'feed'; |
|
26
|
|
|
|
|
27
|
|
|
const ITEM_NODE = 'entry'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Formats the document according to the standard's specification |
|
31
|
|
|
* @param \DOMDocument $document |
|
32
|
|
|
* @return \DOMDocument |
|
33
|
|
|
*/ |
|
34
|
2 |
|
public function format(\DOMDocument $document) |
|
35
|
|
|
{ |
|
36
|
2 |
|
$element = $document->createElement('feed'); |
|
37
|
2 |
|
$element->setAttribute('xmlns', 'http://www.w3.org/2005/Atom'); |
|
38
|
2 |
|
$document->appendChild($element); |
|
39
|
|
|
|
|
40
|
2 |
|
return $document; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Tells if the parser can handle the feed or not |
|
45
|
|
|
* @param \DOMDocument $document |
|
46
|
|
|
* @return mixed |
|
47
|
|
|
*/ |
|
48
|
3 |
|
public function canHandle(\DOMDocument $document) |
|
49
|
|
|
{ |
|
50
|
3 |
|
return self::ROOT_NODE_TAGNAME === $document->documentElement->tagName; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param DOMDocument $document |
|
55
|
|
|
* @return \DomElement |
|
56
|
|
|
*/ |
|
57
|
4 |
|
public function getMainElement(\DOMDocument $document) |
|
58
|
|
|
{ |
|
59
|
4 |
|
return $document->documentElement; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Builds and returns a rule set to parse the root node |
|
64
|
|
|
* @return \FeedIo\RuleSet |
|
65
|
|
|
*/ |
|
66
|
5 |
|
public function buildFeedRuleSet() |
|
67
|
|
|
{ |
|
68
|
5 |
|
$ruleSet = $this->buildBaseRuleSet(); |
|
69
|
|
|
$ruleSet |
|
70
|
5 |
|
->add(new LinkNode()) |
|
71
|
5 |
|
->add(new PublicId('id')) |
|
72
|
5 |
|
->add($this->getModifiedSinceRule('updated')) |
|
73
|
|
|
; |
|
74
|
|
|
|
|
75
|
5 |
|
return $ruleSet; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Builds and returns a rule set to parse an item |
|
80
|
|
|
* @return \FeedIo\RuleSet |
|
81
|
|
|
*/ |
|
82
|
4 |
|
public function buildItemRuleSet() |
|
83
|
|
|
{ |
|
84
|
4 |
|
$ruleSet = $this->buildFeedRuleSet(); |
|
85
|
4 |
|
$ruleSet->add(new Description('content'), ['summary']); |
|
86
|
|
|
|
|
87
|
4 |
|
return $ruleSet; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return RuleSet |
|
92
|
|
|
*/ |
|
93
|
5 |
|
protected function buildBaseRuleSet() |
|
94
|
|
|
{ |
|
95
|
5 |
|
$ruleSet = parent::buildBaseRuleSet(); |
|
96
|
5 |
|
$ruleSet->add(new Category()); |
|
97
|
|
|
|
|
98
|
5 |
|
return $ruleSet; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|