Zend_Feed-Importing.xml 13 KB

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