Zend_Feed_Writer.xml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 19730 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.feed.writer">
  5. <title>Zend_Feed_Writer</title>
  6. <sect2 id="zend.feed.writer.introduction">
  7. <title>Einführung</title>
  8. <para>
  9. <classname>Zend_Feed_Writer</classname> ist die Bruderkomponente zu
  10. <classname>Zend_Feed_Reader</classname> und verantwortlich für die Erzeugung von
  11. Feeds für die Ausgabe. Sie unterstützt die Atom 1.0 Spezifikation (RFC 4287) und
  12. RSS 2.0 wie vom RSS Advisory Board (RSS 2.0.11) spezifiziert. Es ist kein Nachkomme
  13. dieser Standard. Trotzdem bietet es ein einfaches System der Erweiterung welches es
  14. erlaube jede Erweiterung/Modul für jede der zwei Spezifikationen zu implementieren
  15. wenn diese nicht von Haus aus angeboten werden.
  16. </para>
  17. <para>
  18. Auf vielen Wegen ist <classname>Zend_Feed_Writer</classname> das Gegenteil von
  19. <classname>Zend_Feed_Reader</classname>. Wobei <classname>Zend_Feed_Reader</classname>
  20. darauf fokusiert ist ein einfach zu verwendendes Architektur Frontend durch Getter
  21. Methoden anzubieten, und <classname>Zend_Feed_Writer</classname> durch ähnlich
  22. benannte Setter oder Mutatoren. Das stellt sicher das die API keine weitere Lernkurve
  23. erfordert wenn jemand bereits mit <classname>Zend_Feed_Reader</classname> bekannt ist.
  24. </para>
  25. <para>
  26. Als Ergebnis dieses Designs, ist der Rest sogar einleuchtend. Dahinter, wird jedes
  27. Datenset eines <classname>Zend_Feed_Reader</classname> Objekts wärend der
  28. Darstellungszeit in ein <classname>DOMDocument</classname> Objekt übersetzt indem die
  29. notwendigen Feed Elemente verwendet werden. Für jeden unterstützten Feed Typen gibt es
  30. beide, sowohl einen Atom 1.0 als auch einen RSS 2.0 Renderer. Die Verwendung von
  31. <classname>DOMDocument</classname> statt einer Template Lösung hat viele Vorteile.
  32. Der offensichtlichste ist die Möglichkeit das <classname>DOMDocument</classname> zu
  33. exportieren um es weiter zu bearbeiten und auf PHP DOM für die Korrakturen und
  34. richtige Darstellung zu setzen.
  35. </para>
  36. <para>
  37. Wie bei <classname>Zend_Feed_Reader</classname> ist
  38. <classname>Zend_Feed_Writer</classname> ein alleinstehender Ersatz für
  39. <classname>Zend_Feed</classname>'s Builder Architektur und nicht kompatibel mit diesen
  40. Klassen.
  41. </para>
  42. </sect2>
  43. <sect2 id="zend.feed.writer.architecture">
  44. <title>Architektur</title>
  45. <para>
  46. Die Architektur von <classname>Zend_Feed_Writer</classname> ist sehr einfach. Es hat
  47. zwei Kernsets von Klassen: Container und Renderer.
  48. </para>
  49. <para>
  50. The containers include the <classname>Zend_Feed_Writer_Feed</classname> and
  51. <classname>Zend_Feed_Writer_Entry</classname> classes. The Entry classes can be attached
  52. to any Feed class. The sole purpose of these containers is to collect data about the
  53. feed to generate using a simple interface of setter methods. These methods perform some
  54. data validity testing. For example, it will validate any passed URIs, dates, etc. These
  55. checks are not tied to any of the feed standards. The container objects also contain
  56. methods to allow for fast rendering and export of the final feed, and these can be
  57. reused at will.
  58. </para>
  59. <para>
  60. While there are two data containers, there are four renderers - two matching container
  61. renderers per support feed type. The renderer accept a container, and based on its
  62. content attempt to generate a valid feed. If the renderer is unable to generate a valid
  63. feed, perhaps due to the container missing an obligatory data point, it will report this
  64. by throwing an <classname>Exception</classname>. While it is possible to ignore
  65. <classname>Exception</classname>s, this removes the default safeguard of ensuring you
  66. have sufficient data set to render a wholly valid feed.
  67. </para>
  68. <para>
  69. Due to the system being divided between data containers and renderers, it can make
  70. Extensions somewhat interesting. A typical Extension offering namespaced feed and entry
  71. level elements, must itself reflect the exact same architecture, i.e. offer feed and
  72. entry level data containers, and matching renderers. There is, fortunately, no complex
  73. integration work required since all Extension classes are simply registered and
  74. automatically used by the core classes. We'll meet Extensions in more detail at the end
  75. of this section.
  76. </para>
  77. </sect2>
  78. <sect2 id="zend.feed.writer.getting.started">
  79. <title>Getting Started</title>
  80. <para>
  81. Using <classname>Zend_Feed_Reader</classname> is as simple as setting data and
  82. triggering the renderer. Here is an example to generate a minimal Atom 1.0 feed.
  83. </para>
  84. <programlisting language="php"><![CDATA[
  85. /**
  86. * Create the parent feed
  87. */
  88. $feed = new Zend_Feed_Writer_Feed;
  89. $feed->setTitle('Paddy\'s Blog');
  90. $feed->setLink('http://www.example.com');
  91. $feed->setFeedLink('http://www.example.com/atom', 'atom');
  92. $feed->addAuthor(array(
  93. 'name' => 'Paddy',
  94. 'email' => 'paddy@example.com',
  95. 'uri' => 'http://www.example.com',
  96. ));
  97. $feed->setDateModified(time());
  98. $feed->addHub('http://pubsubhubbub.appspot.com/');
  99. /**
  100. * Add one or more entries. Note that entries must
  101. * be manually added once created.
  102. */
  103. $entry = $feed->createEntry();
  104. $entry->setTitle('All Your Base Are Belong To Us');
  105. $entry->setLink('http://www.example.com/all-your-base-are-belong-to-us');
  106. $entry->addAuthor(array(
  107. 'name' => 'Paddy',
  108. 'email' => 'paddy@example.com',
  109. 'uri' => 'http://www.example.com',
  110. ));
  111. $entry->setDateModified(time());
  112. $entry->setDateCreated(time());
  113. $entry->setDescription('Exposing the difficultly of porting games to English.');
  114. $entry->setContent('I am not writing the article. The example is long enough as is ;).');
  115. $feed->addEntry($entry);
  116. /**
  117. * Render the resulting feed to Atom 1.0 and assign to $out.
  118. * You can substitute "atom" with "rss" to generate an RSS 2.0 feed.
  119. */
  120. $out = $feed->export('atom');
  121. ]]></programlisting>
  122. <para>
  123. The output rendered should be as follows:
  124. </para>
  125. <programlisting language="xml">
  126. &#60;?xml version="1.0" encoding="utf-8"?&#62;
  127. &#60;feed xmlns="http://www.w3.org/2005/Atom"&#62;
  128. &#60;title type="text"&#62;Paddy's Blog&#60;/title&#62;
  129. &#60;subtitle type="text"&#62;Writing about PC Games since 176 BC.&#60;/subtitle&#62;
  130. &#60;updated&#62;2009-12-14T20:28:18+00:00&#60;/updated&#62;
  131. &#60;generator uri="http://framework.zend.com" version="1.10.0alpha"&#62;
  132. Zend_Feed_Writer
  133. &#60;/generator&#62;
  134. &#60;link rel="alternate" type="text/html" href="http://www.example.com"/&#62;
  135. &#60;link rel="self" type="application/atom+xml" href="http://www.example.com/atom"/&#62;
  136. &#60;id&#62;http://www.example.com&#60;/id&#62;
  137. &#60;author&#62;
  138. &#60;name&#62;Paddy&#60;/name&#62;
  139. &#60;email&#62;paddy@example.com&#60;/email&#62;
  140. &#60;uri&#62;http://www.example.com&#60;/uri&#62;
  141. &#60;/author&#62;
  142. &#60;link rel="hub" href="http://pubsubhubbub.appspot.com/"/&#62;
  143. &#60;entry&#62;
  144. &#60;title type="html"&#62;&#60;![CDATA[All Your Base Are Belong To Us]]&#62;&#60;/title&#62;
  145. &#60;summary type="html"&#62;
  146. &#60;![CDATA[Exposing the difficultly of porting games to English.]]&#62;
  147. &#60;/summary&#62;
  148. &#60;published&#62;2009-12-14T20:28:18+00:00&#60;/published&#62;
  149. &#60;updated&#62;2009-12-14T20:28:18+00:00&#60;/updated&#62;
  150. &#60;link rel="alternate" type="text/html" href="http://www.example.com/all-your-base-are-belong-to-us"/&#62;
  151. &#60;id&#62;http://www.example.com/all-your-base-are-belong-to-us&#60;/id&#62;
  152. &#60;author&#62;
  153. &#60;name&#62;Paddy&#60;/name&#62;
  154. &#60;email&#62;paddy@example.com&#60;/email&#62;
  155. &#60;uri&#62;http://www.example.com&#60;/uri&#62;
  156. &#60;/author&#62;
  157. &#60;content type="html"&#62;
  158. &#60;![CDATA[I am not writing the article. The example is long enough as is ;).]]&#62;
  159. &#60;/content&#62;
  160. &#60;/entry&#62;
  161. &#60;/feed&#62;
  162. </programlisting>
  163. <para>
  164. This is a perfectly valid Atom 1.0 example. It should be noted that omitting an obligatory point
  165. of data, such as a title, will trigger an <classname>Exception</classname> when
  166. rendering as Atom 1.0. This will differ for RSS 2.0 since a title may be omitted so long
  167. as a description is present. This gives rise to Exceptions that differ between the two
  168. standards depending on the renderer in use. By design,
  169. <classname>Zend_Feed_Writer</classname> will not render an invalid feed for either
  170. standard unless the end-user deliberately elects to ignore all Exceptions.
  171. </para>
  172. </sect2>
  173. <sect2 id="zend.feed.writer.setting.feed.data.points">
  174. <title>Setting Feed Data Points</title>
  175. <para>
  176. Before you can render a feed, you must first setup the data necessary for
  177. the feed being rendered. This utilises a simple setter style API which doubles
  178. as an initial method for validating the data being set. By design, the API
  179. closely matches that for <classname>Zend_Feed_Reader</classname> to avoid
  180. undue confusion and uncertainty.
  181. </para>
  182. <para>
  183. <classname>Zend_Feed_Writer</classname> offers this API via its data container
  184. classes <classname>Zend_Feed_Writer_Feed</classname> and
  185. <classname>Zend_Feed_Writer_Entry</classname>. These classes merely store
  186. all feed data in type-agnostic manner, meaning you may reuse any data
  187. container with any renderer without requiring additional work. Both classes
  188. are also amenable to Extensions, meaning that an Extension may define its own
  189. container classes which are registered to the base container classes as extensions, and
  190. are checked when any method call triggers the base container's
  191. <methodname>__call()</methodname> method.
  192. </para>
  193. <para>
  194. Here's a summary of the Core <acronym>API</acronym> for Feeds. You should note it
  195. comprises not only the basic <acronym>RSS</acronym> and Atom standards, but also
  196. accounts for a number of included Extensions bundled with
  197. <classname>Zend_Feed_Writer</classname>. The naming of these
  198. Extension sourced methods remain fairly generic - all Extension
  199. methods operate at the same level as the Core <acronym>API</acronym> though we do allow
  200. you to retrieve any specific Extension object separately if required.
  201. </para>
  202. <table>
  203. <title>Feed Level API Methods</title>
  204. <tgroup cols="2">
  205. <tbody>
  206. <row>
  207. <entry><methodname>setId()</methodname></entry>
  208. <entry>Set a unique ID associated with this feed. For Atom 1.0
  209. this is an atom:id element, whereas for RSS 2.0 it is added
  210. as a guid element. These are optional so long as a link is
  211. added, i.e. the link is set as the ID.</entry>
  212. </row>
  213. <row>
  214. <entry><methodname>setTitle()</methodname></entry>
  215. <entry>Set the title of the feed.</entry>
  216. </row>
  217. <row>
  218. <entry><methodname>setDescription()</methodname></entry>
  219. <entry>Set the text description of the feed.</entry>
  220. </row>
  221. <row>
  222. <entry><methodname>setLink()</methodname></entry>
  223. <entry>
  224. Set a <acronym>URI</acronym> to the <acronym>HTML</acronym> website
  225. containing the same or
  226. similar information as this feed (i.e. if the feed is from a blog,
  227. it should provide the blog's <acronym>URI</acronym> where the
  228. <acronym>HTML</acronym> version of the entries can be read).
  229. </entry>
  230. </row>
  231. <row>
  232. <entry><methodname>setFeedLinks()</methodname></entry>
  233. <entry>
  234. Add a link to an XML feed, whether the feed being generated or
  235. an alternate URI pointing to the same feed but in a different
  236. format. At a minimum, it is recommended to include a link to
  237. the feed being generated so it has an identifiable final
  238. URI allowing a client to track its location changes without
  239. necessitating constant redirects. The parameter is an array of
  240. arrays, where each sub-array contains the keys "type" and "uri".
  241. The type should be one of "atom", "rss", or "rdf". If a type is
  242. omitted, it defaults to the type used when rendering the feed.
  243. </entry>
  244. </row>
  245. <row>
  246. <entry><methodname>setAuthors()</methodname></entry>
  247. <entry>
  248. Sets the data for authors. The parameter is an array of arrays
  249. where each sub-array may contain the keys "name", "email" and
  250. "uri". The "uri" value is only applicable for Atom feeds since
  251. RSS contains no facility to show it. For RSS 2.0, rendering will
  252. create two elements - an author element containing the email
  253. reference with the name in brackets, and a Dublin Core creator
  254. element only containing the name.
  255. </entry>
  256. </row>
  257. <row>
  258. <entry><methodname>setAuthor()</methodname></entry>
  259. <entry>
  260. Sets the data for a single author following the same
  261. format as described above for a single sub-array.
  262. </entry>
  263. </row>
  264. <row>
  265. <entry><methodname>setDateCreated()</methodname></entry>
  266. <entry>
  267. Sets the date on which this feed was created. Generally
  268. only applicable to Atom where it represents the date the resource
  269. described by an Atom 1.0 document was created. The expected parameter
  270. may be a UNIX timestamp or a <classname>Zend_Date</classname> object.
  271. </entry>
  272. </row>
  273. <row>
  274. <entry><methodname>getDateModified()</methodname></entry>
  275. <entry>
  276. Sets the date on which this feed was last modified. The expected parameter
  277. may be a UNIX timestamp or a <classname>Zend_Date</classname> object.
  278. </entry>
  279. </row>
  280. <row>
  281. <entry><methodname>setLanguage()</methodname></entry>
  282. <entry>
  283. Sets the language of the feed. This will be omitted unless set.
  284. </entry>
  285. </row>
  286. <row>
  287. <entry><methodname>getGenerator()</methodname></entry>
  288. <entry>
  289. Allows the setting of a generator. The parameter should be an
  290. array containing the keys "name", "version" and "uri". If omitted
  291. a default generator will be added referencing
  292. <classname>Zend_Feed_Writer</classname>, the current Zend Framework
  293. version and the Framework's URI.
  294. </entry>
  295. </row>
  296. <row>
  297. <entry><methodname>setCopyright()</methodname></entry>
  298. <entry>
  299. Sets a copyright notice associated with the feed.
  300. </entry>
  301. </row>
  302. <row>
  303. <entry><methodname>setHubs()</methodname></entry>
  304. <entry>
  305. Accepts an array of Pubsubhubbub Hub Endpoints to be rendered in
  306. the feed as Atom links so that PuSH Subscribers may subscribe to
  307. your feed. Note that you must implement a Pubsubhubbub Publisher in
  308. order for real-time updates to be enabled. A Publisher may be implemented
  309. using <classname>Zend_Feed_Pubsubhubbub_Publisher</classname>.
  310. </entry>
  311. </row>
  312. <row>
  313. <entry><methodname>setCategories()</methodname></entry>
  314. <entry>
  315. Accepts an array of categories for rendering, where each element is itself
  316. an array whose possible keys include "term", "label" and "scheme". The "term"
  317. is a typically a category name suitable for inclusion in a URI. The "label"
  318. may be a human readable category name supporting special characters (it is encoded
  319. during rendering) and is a required key. The "scheme" (called the domain in RSS)
  320. is optional but must be a valid URI.
  321. </entry>
  322. </row>
  323. </tbody>
  324. </tgroup>
  325. </table>
  326. </sect2>
  327. <sect2 id="zend.feed.writer.setting.entry.data.points">
  328. <title>Setting Entry Data Points</title>
  329. <para>
  330. Here's a summary of the Core <acronym>API</acronym> for Entries/Items. You should note it
  331. comprises not only the basic <acronym>RSS</acronym> and Atom standards, but also
  332. accounts for a number of included Extensions bundled with
  333. <classname>Zend_Feed_Writer</classname>. The naming of these
  334. Extension sourced methods remain fairly generic - all Extension
  335. methods operate at the same level as the Core <acronym>API</acronym> though we do allow
  336. you to retrieve any specific Extension object separately if required.
  337. </para>
  338. <table>
  339. <title>Entry Level API Methods</title>
  340. <tgroup cols="2">
  341. <tbody>
  342. <row>
  343. <entry><methodname>setId()</methodname></entry>
  344. <entry>Set a unique ID associated with this feed. For Atom 1.0
  345. this is an atom:id element, whereas for RSS 2.0 it is added
  346. as a guid element. These are optional so long as a link is
  347. added, i.e. the link is set as the ID.</entry>
  348. </row>
  349. <row>
  350. <entry><methodname>setTitle()</methodname></entry>
  351. <entry>Set the title of the feed.</entry>
  352. </row>
  353. <row>
  354. <entry><methodname>setDescription()</methodname></entry>
  355. <entry>Set the text description of the feed.</entry>
  356. </row>
  357. <row>
  358. <entry><methodname>setLink()</methodname></entry>
  359. <entry>
  360. Set a <acronym>URI</acronym> to the <acronym>HTML</acronym> website
  361. containing the same or
  362. similar information as this feed (i.e. if the feed is from a blog,
  363. it should provide the blog's <acronym>URI</acronym> where the
  364. <acronym>HTML</acronym> version of the entries can be read).
  365. </entry>
  366. </row>
  367. <row>
  368. <entry><methodname>setFeedLinks()</methodname></entry>
  369. <entry>
  370. Add a link to an XML feed, whether the feed being generated or
  371. an alternate URI pointing to the same feed but in a different
  372. format. At a minimum, it is recommended to include a link to
  373. the feed being generated so it has an identifiable final
  374. URI allowing a client to track its location changes without
  375. necessitating constant redirects. The parameter is an array of
  376. arrays, where each sub-array contains the keys "type" and "uri".
  377. The type should be one of "atom", "rss", or "rdf". If a type is
  378. omitted, it defaults to the type used when rendering the feed.
  379. </entry>
  380. </row>
  381. <row>
  382. <entry><methodname>setAuthors()</methodname></entry>
  383. <entry>
  384. Sets the data for authors. The parameter is an array of arrays
  385. where each sub-array may contain the keys "name", "email" and
  386. "uri". The "uri" value is only applicable for Atom feeds since
  387. RSS contains no facility to show it. For RSS 2.0, rendering will
  388. create two elements - an author element containing the email
  389. reference with the name in brackets, and a Dublin Core creator
  390. element only containing the name.
  391. </entry>
  392. </row>
  393. <row>
  394. <entry><methodname>setAuthor()</methodname></entry>
  395. <entry>
  396. Sets the data for a single author following the same
  397. format as described above for a single sub-array.
  398. </entry>
  399. </row>
  400. <row>
  401. <entry><methodname>setDateCreated()</methodname></entry>
  402. <entry>
  403. Sets the date on which this feed was created. Generally
  404. only applicable to Atom where it represents the date the resource
  405. described by an Atom 1.0 document was created. The expected parameter
  406. may be a UNIX timestamp or a <classname>Zend_Date</classname> object.
  407. </entry>
  408. </row>
  409. <row>
  410. <entry><methodname>getDateModified()</methodname></entry>
  411. <entry>
  412. Sets the date on which this feed was last modified. The expected parameter
  413. may be a UNIX timestamp or a <classname>Zend_Date</classname> object.
  414. </entry>
  415. </row>
  416. <row>
  417. <entry><methodname>setLanguage()</methodname></entry>
  418. <entry>
  419. Sets the language of the feed. This will be omitted unless set.
  420. </entry>
  421. </row>
  422. <row>
  423. <entry><methodname>getGenerator()</methodname></entry>
  424. <entry>
  425. Allows the setting of a generator. The parameter should be an
  426. array containing the keys "name", "version" and "uri". If omitted
  427. a default generator will be added referencing
  428. <classname>Zend_Feed_Writer</classname>, the current Zend Framework
  429. version and the Framework's URI.
  430. </entry>
  431. </row>
  432. <row>
  433. <entry><methodname>setCopyright()</methodname></entry>
  434. <entry>
  435. Sets a copyright notice associated with the feed.
  436. </entry>
  437. </row>
  438. <row>
  439. <entry><methodname>setHubs()</methodname></entry>
  440. <entry>
  441. Accepts an array of Pubsubhubbub Hub Endpoints to be rendered in
  442. the feed as Atom links so that PuSH Subscribers may subscribe to
  443. your feed. Note that you must implement a Pubsubhubbub Publisher in
  444. order for real-time updates to be enabled. A Publisher may be implemented
  445. using <classname>Zend_Feed_Pubsubhubbub_Publisher</classname>.
  446. </entry>
  447. </row>
  448. <row>
  449. <entry><methodname>setCategories()</methodname></entry>
  450. <entry>
  451. Accepts an array of categories for rendering, where each element is itself
  452. an array whose possible keys include "term", "label" and "scheme". The "term"
  453. is a typically a category name suitable for inclusion in a URI. The "label"
  454. may be a human readable category name supporting special characters (it is encoded
  455. during rendering) and is a required key. The "scheme" (called the domain in RSS)
  456. is optional but must be a valid URI.
  457. </entry>
  458. </row>
  459. </tbody>
  460. </tgroup>
  461. </table>
  462. </sect2>
  463. </sect1>