Zend_Feed-Importing.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.feed.importing">
  4. <title>Importing Feeds</title>
  5. <para>
  6. <classname>Zend_Feed</classname> enables developers to retrieve feeds very easily. If you know the URI of a feed, simply
  7. use the <classname>Zend_Feed::import()</classname> method:
  8. </para>
  9. <programlisting role="php"><![CDATA[
  10. $feed = Zend_Feed::import('http://feeds.example.com/feedName');
  11. ]]></programlisting>
  12. <para>
  13. You can also use <classname>Zend_Feed</classname> to fetch the contents of a feed from a file or the contents of a PHP
  14. string variable:
  15. </para>
  16. <programlisting role="php"><![CDATA[
  17. // importing a feed from a text file
  18. $feedFromFile = Zend_Feed::importFile('feed.xml');
  19. // importing a feed from a PHP string variable
  20. $feedFromPHP = Zend_Feed::importString($feedString);
  21. ]]></programlisting>
  22. <para>
  23. In each of the examples above, an object of a class that extends <classname>Zend_Feed_Abstract</classname> is returned
  24. upon success, depending on the type of the feed. If an RSS feed were retrieved via one of the import methods
  25. above, then a <classname>Zend_Feed_Rss</classname> object would be returned. On the other hand, if an Atom feed were
  26. imported, then a <classname>Zend_Feed_Atom</classname> object is returned. The import methods will also throw a
  27. <classname>Zend_Feed_Exception</classname> object upon failure, such as an unreadable or malformed feed.
  28. </para>
  29. <sect2 id="zend.feed.importing.custom">
  30. <title>Custom feeds</title>
  31. <para>
  32. <classname>Zend_Feed</classname> enables developers to create custom feeds very easily. You just have to create an
  33. array and to import it with <classname>Zend_Feed</classname>. This array can be imported with <classname>Zend_Feed::importArray()</classname>
  34. or with <classname>Zend_Feed::importBuilder()</classname>. In this last case the array will be computed on the fly by
  35. a custom data source implementing <classname>Zend_Feed_Builder_Interface</classname>.
  36. </para>
  37. <sect3 id="zend.feed.importing.custom.importarray">
  38. <title>Importing a custom array</title>
  39. <programlisting role="php"><![CDATA[
  40. // importing a feed from an array
  41. $atomFeedFromArray = Zend_Feed::importArray($array);
  42. // the following line is equivalent to the above;
  43. // by default a Zend_Feed_Atom instance is returned
  44. $atomFeedFromArray = Zend_Feed::importArray($array, 'atom');
  45. // importing a rss feed from an array
  46. $rssFeedFromArray = Zend_Feed::importArray($array, 'rss');
  47. ]]></programlisting>
  48. <para>
  49. The format of the array must conform to this structure:
  50. </para>
  51. <programlisting role="php"><![CDATA[
  52. array(
  53. //required
  54. 'title' => 'title of the feed',
  55. 'link' => 'canonical url to the feed',
  56. // optional
  57. 'lastUpdate' => 'timestamp of the update date',
  58. 'published' => 'timestamp of the publication date',
  59. // required
  60. 'charset' => 'charset of the textual data',
  61. // optional
  62. 'description' => 'short description of the feed',
  63. 'author' => 'author/publisher of the feed',
  64. 'email' => 'email of the author',
  65. // optional, ignored if atom is used
  66. 'webmaster' => 'email address for person responsible '
  67. . 'for technical issues',
  68. // optional
  69. 'copyright' => 'copyright notice',
  70. 'image' => 'url to image',
  71. 'generator' => 'generator',
  72. 'language' => 'language the feed is written in',
  73. // optional, ignored if atom is used
  74. 'ttl' => 'how long in minutes a feed can be cached '
  75. . 'before refreshing',
  76. 'rating' => 'The PICS rating for the channel.',
  77. // optional, ignored if atom is used
  78. // a cloud to be notified of updates
  79. 'cloud' => array(
  80. // required
  81. 'domain' => 'domain of the cloud, e.g. rpc.sys.com',
  82. // optional, defaults to 80
  83. 'port' => 'port to connect to',
  84. // required
  85. 'path' => 'path of the cloud, e.g. /RPC2',
  86. 'registerProcedure' => 'procedure to call, e.g. myCloud.rssPlsNotify',
  87. 'protocol' => 'protocol to use, e.g. soap or xml-rpc'
  88. ),
  89. // optional, ignored if atom is used
  90. // a text input box that can be displayed with the feed
  91. 'textInput' => array(
  92. // required
  93. 'title' => 'label of the Submit button in the text input area',
  94. 'description' => 'explains the text input area',
  95. 'name' => 'the name of the text object in the text input area',
  96. 'link' => 'URL of the CGI script processing text input requests'
  97. ),
  98. // optional, ignored if atom is used
  99. // Hint telling aggregators which hours they can skip
  100. 'skipHours' => array(
  101. // up to 24 rows whose value is a number between 0 and 23
  102. // e.g 13 (1pm)
  103. 'hour in 24 format'
  104. ),
  105. // optional, ignored if atom is used
  106. // Hint telling aggregators which days they can skip
  107. 'skipDays ' => array(
  108. // up to 7 rows whose value is
  109. // Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday
  110. // e.g Monday
  111. 'a day to skip'
  112. ),
  113. // optional, ignored if atom is used
  114. // Itunes extension data
  115. 'itunes' => array(
  116. // optional, default to the main author value
  117. 'author' => 'Artist column',
  118. // optional, default to the main author value
  119. // Owner of the podcast
  120. 'owner' => array(
  121. 'name' => 'name of the owner',
  122. 'email' => 'email of the owner'
  123. ),
  124. // optional, default to the main image value
  125. 'image' => 'album/podcast art',
  126. // optional, default to the main description value
  127. 'subtitle' => 'short description',
  128. 'summary' => 'longer description',
  129. // optional
  130. 'block' => 'Prevent an episode from appearing (yes|no)',
  131. // required, Category column and in iTunes Music Store Browse
  132. 'category' => array(
  133. // up to 3 rows
  134. array(
  135. // required
  136. 'main' => 'main category',
  137. // optional
  138. 'sub' => 'sub category'
  139. )
  140. ),
  141. // optional
  142. 'explicit' => 'parental advisory graphic (yes|no|clean)',
  143. 'keywords' => 'a comma separated list of 12 keywords maximum',
  144. 'new-feed-url' => 'used to inform iTunes of new feed URL location'
  145. ),
  146. 'entries' => array(
  147. array(
  148. //required
  149. 'title' => 'title of the feed entry',
  150. 'link' => 'url to a feed entry',
  151. // required, only text, no html
  152. 'description' => 'short version of a feed entry',
  153. // optional
  154. 'guid' => 'id of the article, '
  155. . 'if not given link value will used',
  156. // optional, can contain html
  157. 'content' => 'long version',
  158. // optional
  159. 'lastUpdate' => 'timestamp of the publication date',
  160. 'comments' => 'comments page of the feed entry',
  161. 'commentRss' => 'the feed url of the associated comments',
  162. // optional, original source of the feed entry
  163. 'source' => array(
  164. // required
  165. 'title' => 'title of the original source',
  166. 'url' => 'url of the original source'
  167. ),
  168. // optional, list of the attached categories
  169. 'category' => array(
  170. array(
  171. // required
  172. 'term' => 'first category label',
  173. // optional
  174. 'scheme' => 'url that identifies a categorization scheme'
  175. ),
  176. array(
  177. // data for the second category and so on
  178. )
  179. ),
  180. // optional, list of the enclosures of the feed entry
  181. 'enclosure' => array(
  182. array(
  183. // required
  184. 'url' => 'url of the linked enclosure',
  185. // optional
  186. 'type' => 'mime type of the enclosure',
  187. 'length' => 'length of the linked content in octets'
  188. ),
  189. array(
  190. //data for the second enclosure and so on
  191. )
  192. )
  193. ),
  194. array(
  195. //data for the second entry and so on
  196. )
  197. )
  198. );
  199. ]]></programlisting>
  200. <para>
  201. References:
  202. <itemizedlist>
  203. <listitem>
  204. <para>
  205. RSS 2.0 specification: <ulink url="http://blogs.law.harvard.edu/tech/rss">RSS 2.0</ulink>
  206. </para>
  207. </listitem>
  208. <listitem>
  209. <para>
  210. Atom specification: <ulink url="http://tools.ietf.org/html/rfc4287">RFC 4287</ulink>
  211. </para>
  212. </listitem>
  213. <listitem>
  214. <para>
  215. WFW specification: <ulink url="http://wellformedweb.org/news/wfw_namespace_elements">Well
  216. Formed Web</ulink>
  217. </para>
  218. </listitem>
  219. <listitem>
  220. <para>
  221. iTunes specification:
  222. <ulink url="http://www.apple.com/itunes/store/podcaststechspecs.html">iTunes Technical
  223. Specifications</ulink>
  224. </para>
  225. </listitem>
  226. </itemizedlist>
  227. </para>
  228. </sect3>
  229. <sect3 id="zend.feed.importing.custom.importbuilder">
  230. <title>Importing a custom data source</title>
  231. <para>
  232. You can create a Zeed_Feed instance from any data source implementing
  233. <classname>Zend_Feed_Builder_Interface</classname>. You just have to implement the <code>getHeader()</code> and
  234. <code>getEntries()</code> methods to be able to use your object with
  235. <classname>Zend_Feed::importBuilder()</classname>. As a simple reference implementation, you can use
  236. <classname>Zend_Feed_Builder</classname>, which takes an array in its constructor, performs some minor validation,
  237. and then can be used in the <code>importBuilder()</code> method. The <code>getHeader()</code> method
  238. must return an instance of <classname>Zend_Feed_Builder_Header</classname>, and <code>getEntries()</code> must
  239. return an array of <classname>Zend_Feed_Builder_Entry</classname> instances.
  240. </para>
  241. <note>
  242. <para>
  243. <classname>Zend_Feed_Builder</classname> serves as a concrete implementation to demonstrate the usage. Users
  244. are encouraged to make their own classes to implement <classname>Zend_Feed_Builder_Interface</classname>.
  245. </para>
  246. </note>
  247. <para>
  248. Here is an example of <classname>Zend_Feed::importBuilder()</classname> usage:
  249. </para>
  250. <programlisting role="php"><![CDATA[
  251. // importing a feed from a custom builder source
  252. $atomFeedFromArray =
  253. Zend_Feed::importBuilder(new Zend_Feed_Builder($array));
  254. // the following line is equivalent to the above;
  255. // by default a Zend_Feed_Atom instance is returned
  256. $atomFeedFromArray =
  257. Zend_Feed::importArray(new Zend_Feed_Builder($array), 'atom');
  258. // importing a rss feed from a custom builder array
  259. $rssFeedFromArray =
  260. Zend_Feed::importArray(new Zend_Feed_Builder($array), 'rss');
  261. ]]></programlisting>
  262. </sect3>
  263. <sect3 id="zend.feed.importing.custom.dump">
  264. <title>Dumping the contents of a feed</title>
  265. <para>
  266. To dump the contents of a <classname>Zend_Feed_Abstract</classname> instance, you may use <code>send()</code> or
  267. <code>saveXml()</code> methods.
  268. </para>
  269. <programlisting role="php"><![CDATA[
  270. assert($feed instanceof Zend_Feed_Abstract);
  271. // dump the feed to standard output
  272. print $feed->saveXML();
  273. // send http headers and dump the feed
  274. $feed->send();
  275. ]]></programlisting>
  276. </sect3>
  277. </sect2>
  278. </sect1>
  279. <!--
  280. vim:se ts=4 sw=4 et:
  281. -->