Zend_Feed-Importing.xml 13 KB

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