Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
atom.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Feed
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * ATOM Feed Parser class.
14  *
15  * @package Joomla.Platform
16  * @subpackage Feed
17  * @link http://www.atomenabled.org/developers/syndication/
18  * @since 12.3
19  */
21 {
22  /**
23  * @var string The feed format version.
24  * @since 12.3
25  */
26  protected $version;
27 
28  /**
29  * Method to handle the <author> element for the feed.
30  *
31  * @param JFeed $feed The JFeed object being built from the parsed feed.
32  * @param SimpleXMLElement $el The current XML element object to handle.
33  *
34  * @return void
35  *
36  * @since 12.3
37  */
38  protected function handleAuthor(JFeed $feed, SimpleXMLElement $el)
39  {
40  // Set the author information from the XML element.
41  $feed->setAuthor((string) $el->name, (string) $el->email, (string) $el->uri);
42  }
43 
44  /**
45  * Method to handle the <contributor> element for the feed.
46  *
47  * @param JFeed $feed The JFeed object being built from the parsed feed.
48  * @param SimpleXMLElement $el The current XML element object to handle.
49  *
50  * @return void
51  *
52  * @since 12.3
53  */
54  protected function handleContributor(JFeed $feed, SimpleXMLElement $el)
55  {
56  $feed->addContributor((string) $el->name, (string) $el->email, (string) $el->uri);
57  }
58 
59  /**
60  * Method to handle the <generator> element for the feed.
61  *
62  * @param JFeed $feed The JFeed object being built from the parsed feed.
63  * @param SimpleXMLElement $el The current XML element object to handle.
64  *
65  * @return void
66  *
67  * @since 12.3
68  */
69  protected function handleGenerator(JFeed $feed, SimpleXMLElement $el)
70  {
71  $feed->generator = (string) $el;
72  }
73 
74  /**
75  * Method to handle the <id> element for the feed.
76  *
77  * @param JFeed $feed The JFeed object being built from the parsed feed.
78  * @param SimpleXMLElement $el The current XML element object to handle.
79  *
80  * @return void
81  *
82  * @since 12.3
83  */
84  protected function handleId(JFeed $feed, SimpleXMLElement $el)
85  {
86  $feed->uri = (string) $el;
87  }
88 
89  /**
90  * Method to handle the <link> element for the feed.
91  *
92  * @param JFeed $feed The JFeed object being built from the parsed feed.
93  * @param SimpleXMLElement $el The current XML element object to handle.
94  *
95  * @return void
96  *
97  * @since 12.3
98  */
99  protected function handleLink(JFeed $feed, SimpleXMLElement $el)
100  {
101  $link = new JFeedLink;
102  $link->uri = (string) $el['href'];
103  $link->language = (string) $el['hreflang'];
104  $link->length = (int) $el['length'];
105  $link->relation = (string) $el['rel'];
106  $link->title = (string) $el['title'];
107  $link->type = (string) $el['type'];
108 
109  $feed->link = $link;
110  }
111 
112  /**
113  * Method to handle the <rights> element for the feed.
114  *
115  * @param JFeed $feed The JFeed object being built from the parsed feed.
116  * @param SimpleXMLElement $el The current XML element object to handle.
117  *
118  * @return void
119  *
120  * @since 12.3
121  */
122  protected function handleRights(JFeed $feed, SimpleXMLElement $el)
123  {
124  $feed->copyright = (string) $el;
125  }
126 
127  /**
128  * Method to handle the <subtitle> element for the feed.
129  *
130  * @param JFeed $feed The JFeed object being built from the parsed feed.
131  * @param SimpleXMLElement $el The current XML element object to handle.
132  *
133  * @return void
134  *
135  * @since 12.3
136  */
137  protected function handleSubtitle(JFeed $feed, SimpleXMLElement $el)
138  {
139  $feed->description = (string) $el;
140  }
141 
142  /**
143  * Method to handle the <title> element for the feed.
144  *
145  * @param JFeed $feed The JFeed object being built from the parsed feed.
146  * @param SimpleXMLElement $el The current XML element object to handle.
147  *
148  * @return void
149  *
150  * @since 12.3
151  */
152  protected function handleTitle(JFeed $feed, SimpleXMLElement $el)
153  {
154  $feed->title = (string) $el;
155  }
156 
157  /**
158  * Method to handle the <updated> element for the feed.
159  *
160  * @param JFeed $feed The JFeed object being built from the parsed feed.
161  * @param SimpleXMLElement $el The current XML element object to handle.
162  *
163  * @return void
164  *
165  * @since 12.3
166  */
167  protected function handleUpdated(JFeed $feed, SimpleXMLElement $el)
168  {
169  $feed->updatedDate = (string) $el;
170  }
171 
172  /**
173  * Method to initialise the feed for parsing. Here we detect the version and advance the stream
174  * reader so that it is ready to parse feed elements.
175  *
176  * @return void
177  *
178  * @since 12.3
179  */
180  protected function initialise()
181  {
182  // Read the version attribute.
183  $this->version = ($this->stream->getAttribute('version') == '0.3') ? '0.3' : '1.0';
184 
185  // We want to move forward to the first element after the root element.
186  $this->moveToNextElement();
187  }
188 
189  /**
190  * Method to handle the feed entry element for the feed: <entry>.
191  *
192  * @param JFeedEntry $entry The JFeedEntry object being built from the parsed feed entry.
193  * @param SimpleXMLElement $el The current XML element object to handle.
194  *
195  * @return void
196  *
197  * @since 12.3
198  */
199  protected function processFeedEntry(JFeedEntry $entry, SimpleXMLElement $el)
200  {
201  $entry->uri = (string) $el->id;
202  $entry->title = (string) $el->title;
203  $entry->updatedDate = (string) $el->updated;
204  $entry->content = (string) $el->summary;
205  }
206 }