PageRenderTime 47ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/MantisBT/library/rssbuilder/class.RSS_V_200.inc.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 220 lines | 178 code | 32 blank | 10 comment | 42 complexity | f6e969239d11959699a5fe0ec11fa059 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. require_once 'class.RSSBase.inc.php';
  3. /**
  4. * Class for creating an RSS-feed
  5. * @author Michael Wimmer <flaimo@gmail.com>
  6. * @category flaimo-php
  7. * @copyright Copyright Š 2002-2008, Michael Wimmer
  8. * @license GNU General Public License v3
  9. * @link http://code.google.com/p/flaimo-php/
  10. * @package RSS
  11. * @version 2.2.1
  12. */
  13. class RSS_V_200 extends RSS_V_abstract {
  14. function __construct(RSSBuilder &$rssdata) {
  15. parent::__construct($rssdata);
  16. } // end constructor
  17. protected function generateXML() {
  18. parent::generateXML();
  19. $root = $this->xml->createElement('rss');
  20. $root->setAttribute('version', '2.0');
  21. $root->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
  22. $root->setAttribute('xmlns:sy', 'http://purl.org/rss/1.0/modules/syndication/');
  23. $this->xml->appendChild($root);
  24. $channel = $this->xml->createElement('channel');
  25. $root->appendChild($channel);
  26. if ($this->rssdata->getDCRights() != FALSE) {
  27. $copyright = $this->xml->createElement('copyright');
  28. $copyright->appendChild($this->xml->createTextNode($this->rssdata->getDCRights()));
  29. $channel->appendChild($copyright);
  30. } // end if
  31. if ($this->rssdata->getDCDate() != FALSE) {
  32. $date = $this->xml->createTextNode(date('Y-m-d\TH:i:sO', $this->rssdata->getDCDate()));
  33. $pub_date = $this->xml->createElement('pubDate');
  34. $last_build = $this->xml->createElement('lastBuildDate');
  35. $pub_date->appendChild($date);
  36. $last_build->appendChild($date->cloneNode());
  37. $channel->appendChild($pub_date);
  38. $channel->appendChild($last_build);
  39. } // end if
  40. if ($this->rssdata->getAbout() != FALSE) {
  41. $about = $this->xml->createTextNode($this->rssdata->getAbout());
  42. $link = $this->xml->createElement('link');
  43. $docs = $this->xml->createElement('docs');
  44. $docs->appendChild($about);
  45. $link->appendChild($about->cloneNode());
  46. $channel->appendChild($docs);
  47. $channel->appendChild($link);
  48. } // end if
  49. if ($this->rssdata->getDescription() != FALSE) {
  50. $description = $this->xml->createElement('description');
  51. $description->appendChild($this->xml->createCDATASection($this->rssdata->getDescription()));
  52. $channel->appendChild($description);
  53. } // end if
  54. if ($this->rssdata->getTitle() != FALSE) {
  55. $title = $this->xml->createElement('title');
  56. $title->appendChild($this->xml->createTextNode($this->rssdata->getTitle()));
  57. $channel->appendChild($title);
  58. } // end if
  59. if ($this->rssdata->getImageLink() != FALSE) {
  60. $image = $this->xml->createElement('image');
  61. $channel->appendChild($image);
  62. $image->appendChild($title->cloneNode(TRUE));
  63. $url = $this->xml->createElement('url');
  64. $url->appendChild($this->xml->createTextNode($this->rssdata->getImageLink()));
  65. $image->appendChild($url);
  66. $image->appendChild($link->cloneNode(TRUE));
  67. $image->appendChild($description->cloneNode(TRUE));
  68. } // end if
  69. if ($this->rssdata->getDCPublisher() != FALSE) {
  70. $managingEditor = $this->xml->createElement('managingEditor');
  71. $managingEditor->appendChild($this->xml->createTextNode($this->rssdata->getDCPublisher()));
  72. $channel->appendChild($managingEditor);
  73. } // end if
  74. if ($this->rssdata->getDCCreator() != FALSE) {
  75. $webmaster_string = $this->xml->createTextNode($this->rssdata->getDCCreator());
  76. $webMaster = $this->xml->createElement('webMaster');
  77. $generator = $this->xml->createElement('generator');
  78. $webMaster->appendChild($webmaster_string);
  79. $generator->appendChild($webmaster_string->cloneNode());
  80. $channel->appendChild($webMaster);
  81. $channel->appendChild($generator);
  82. } // end if
  83. if ($this->rssdata->getDCLanguage() != FALSE) {
  84. $language = $this->xml->createElement('language');
  85. $language->appendChild($this->xml->createTextNode($this->rssdata->getDCLanguage()));
  86. $channel->appendChild($language);
  87. } // end if
  88. if ($this->rssdata->getCategory() != FALSE) {
  89. $category = $this->xml->createElement('category');
  90. $category->appendChild($this->xml->createTextNode($this->rssdata->getCategory()));
  91. $channel->appendChild($category);
  92. } // end if
  93. if ($this->rssdata->getCache() != FALSE) {
  94. $cache = $this->xml->createElement('ttl');
  95. $cache->appendChild($this->xml->createTextNode($this->rssdata->getCache()));
  96. $channel->appendChild($cache);
  97. } // end if
  98. if ($this->rssdata->getDCPublisher() != FALSE) {
  99. $publisher = $this->xml->createElement('dc:publisher');
  100. $publisher->appendChild($this->xml->createTextNode($this->rssdata->getDCPublisher()));
  101. $channel->appendChild($publisher);
  102. } // end if
  103. if ($this->rssdata->getDCCreator() != FALSE) {
  104. $creator = $this->xml->createElement('dc:creator');
  105. $creator->appendChild($this->xml->createTextNode($this->rssdata->getDCCreator()));
  106. $channel->appendChild($creator);
  107. } // end if
  108. if ($this->rssdata->getDCDate() != FALSE) {
  109. $date = $this->xml->createTextNode(date('Y-m-d\TH:i:sO', $this->rssdata->getDCDate()));
  110. $pub_date = $this->xml->createElement('dc:date');
  111. $pub_date->appendChild($date);
  112. $channel->appendChild($pub_date);
  113. } // end if
  114. if ($this->rssdata->getDCLanguage() != FALSE) {
  115. $language_dc = $this->xml->createElement('dc:language');
  116. $language_dc->appendChild($this->xml->createTextNode($this->rssdata->getDCLanguage()));
  117. $channel->appendChild($language_dc);
  118. } // end if
  119. if ($this->rssdata->getDCRights() != FALSE) {
  120. $copyright = $this->xml->createElement('dc:rights');
  121. $copyright->appendChild($this->xml->createTextNode($this->rssdata->getDCRights()));
  122. $channel->appendChild($copyright);
  123. } // end if
  124. if ($this->rssdata->getDCContributor() != FALSE) {
  125. $contributor = $this->xml->createElement('dc:contributor');
  126. $contributor->appendChild($this->xml->createTextNode($this->rssdata->getDCContributor()));
  127. $channel->appendChild($contributor);
  128. } // end if
  129. if ($this->rssdata->getSYPeriod() != FALSE) {
  130. $period = $this->xml->createElement('sy:updatePeriod');
  131. $period->appendChild($this->xml->createTextNode($this->rssdata->getSYPeriod()));
  132. $channel->appendChild($period);
  133. } // end if
  134. if ($this->rssdata->getSYFrequency() != FALSE) {
  135. $frequency = $this->xml->createElement('sy:updateFrequency');
  136. $frequency->appendChild($this->xml->createTextNode($this->rssdata->getSYFrequency()));
  137. $channel->appendChild($frequency);
  138. } // end if
  139. if ($this->rssdata->getSYBase() != FALSE) {
  140. $basedate = $this->xml->createTextNode(date('r', $this->rssdata->getSYBase()));
  141. $base = $this->xml->createElement('sy:updateBase');
  142. $base->appendChild($basedate);
  143. $channel->appendChild($base);
  144. } // end if
  145. foreach ($this->rssdata->getRSSItemList() as $id => $rss_item) {
  146. $item = '$item_' . $id;
  147. $$item = $this->xml->createElement('item');
  148. $channel->appendChild($$item);
  149. $item_title = '$item_title_' . $id;
  150. $$item_title = $this->xml->createElement('title');
  151. $$item_title->appendChild($this->xml->createTextNode($rss_item->getTitle()));
  152. $$item->appendChild($$item_title);
  153. $item_author = '$item_author_' . $id;
  154. $$item_author = $this->xml->createElement('author');
  155. $$item_author->appendChild($this->xml->createTextNode($rss_item->getAuthor()));
  156. $$item->appendChild($$item_author);
  157. $item_link = '$item_link_' . $id;
  158. $$item_link = $this->xml->createElement('link');
  159. $$item_link->appendChild($this->xml->createTextNode($rss_item->getLink()));
  160. $$item->appendChild($$item_link);
  161. $item_desc = '$item_desc_' . $id;
  162. $$item_desc = $this->xml->createElement('description');
  163. $$item_desc->appendChild($this->xml->createCDATASection($rss_item->getDescription()));
  164. $$item->appendChild($$item_desc);
  165. $item_sub = '$item_sub_' . $id;
  166. $$item_sub = $this->xml->createElement('category');
  167. $$item_sub->appendChild($this->xml->createTextNode($rss_item->getSubject()));
  168. $$item->appendChild($$item_sub);
  169. $item_date = '$item_date_' . $id;
  170. $item_date_string = '$item_date_string_' . $id;
  171. $$item_date_string = $this->xml->createTextNode(date('r', $rss_item->getItemDate()));
  172. $$item_date = $this->xml->createElement('pubDate');
  173. $$item_date->appendChild($$item_date_string);
  174. $$item->appendChild($$item_date);
  175. $item_guid = '$item_guid_' . $id;
  176. $$item_guid = $this->xml->createElement('guid');
  177. $$item_guid->appendChild($this->xml->createTextNode($rss_item->getLink()));
  178. $$item->appendChild($$item_guid);
  179. if ( $rss_item->getComments() != FALSE ) {
  180. $item_comments = '$item_comments_' . $id;
  181. $$item_comments = $this->xml->createElement('comments');
  182. $$item_comments->appendChild($this->xml->createTextNode($rss_item->getComments()));
  183. $$item->appendChild($$item_comments);
  184. } // end if
  185. } // end foreach
  186. } // function
  187. } // end class
  188. ?>