PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/domit/xml_domit_rss_lite.php

https://gitlab.com/endomorphosis/greenrenaissancejoomla
PHP | 244 lines | 120 code | 30 blank | 94 comment | 13 complexity | 677031c85a11fb79aac3019b02f2bb13 MD5 | raw file
  1. <?php
  2. /**
  3. * DOMIT! RSS Lite is a lightweight version of the DOMIT! Lite RSS parser
  4. * @package domit-rss
  5. * @subpackage domit-rss-lite
  6. * @version 0.51
  7. * @copyright (C) 2004 John Heinstein. All rights reserved
  8. * @license http://www.gnu.org/copyleft/lesser.html LGPL License
  9. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  10. * @link http://www.engageinteractive.com/domitrss/ DOMIT! RSS Home Page
  11. * DOMIT! RSS is Free Software
  12. **/
  13. if (!defined('DOMIT_RSS_INCLUDE_PATH')) {
  14. define('DOMIT_RSS_INCLUDE_PATH', (dirname(__FILE__) . DIRECTORY_SEPARATOR));
  15. }
  16. /** current version of DOMIT! RSS Lite */
  17. define ('DOMIT_RSS_LITE_VERSION', '0.51');
  18. require_once(DOMIT_RSS_INCLUDE_PATH . 'xml_domit_rss_shared.php');
  19. /**
  20. * The base DOMIT! RSS Lite document class
  21. *
  22. * @package domit-rss
  23. * @subpackage domit-rss-lite
  24. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  25. */
  26. class xml_domit_rss_document_lite extends xml_domit_rss_base_document {
  27. /**
  28. * Constructor
  29. * @param string Path to the rss file
  30. * @param string Directory for cache files
  31. * @param int Expiration time for a cache file
  32. */
  33. function xml_domit_rss_document_lite($url = '', $cacheDir = './', $cacheTime = 3600) {
  34. $this->parser = 'DOMIT_RSS_LITE';
  35. $this->xml_domit_rss_base_document($url, $cacheDir, $cacheTime);
  36. } //xml_domit_rss_document_lite
  37. /**
  38. * Performs initialization of the RSS document
  39. */
  40. function _init() {
  41. $total = $this->node->documentElement->childCount;
  42. $itemCounter = 0;
  43. $channelCounter = 0;
  44. for ($i = 0; $i < $total; $i++) {
  45. $currNode =& $this->node->documentElement->childNodes[$i];
  46. $tagName = strtolower($currNode->nodeName);
  47. switch ($tagName) {
  48. case DOMIT_RSS_ELEMENT_ITEM:
  49. $this->domit_rss_items[$itemCounter] = new xml_domit_rss_item_lite($currNode);
  50. $itemCounter++;
  51. break;
  52. case DOMIT_RSS_ELEMENT_CHANNEL:
  53. $this->domit_rss_channels[$channelCounter] = new xml_domit_rss_channel_lite($currNode);
  54. $channelCounter++;
  55. break;
  56. case DOMIT_RSS_ELEMENT_TITLE:
  57. case DOMIT_RSS_ELEMENT_LINK:
  58. case DOMIT_RSS_ELEMENT_DESCRIPTION:
  59. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_simpleelement($currNode);
  60. break;
  61. }
  62. }
  63. if ($itemCounter != 0) {
  64. $this->DOMIT_RSS_indexer[DOMIT_RSS_ARRAY_ITEMS] =& $this->domit_rss_items;
  65. }
  66. if ($channelCounter != 0) {
  67. $this->DOMIT_RSS_indexer[DOMIT_RSS_ARRAY_CHANNELS] =& $this->domit_rss_channels;
  68. }
  69. $this->handleChannelElementsEmbedded();
  70. } //_init
  71. /**
  72. * Returns the current version of DOMIT! RSS
  73. * @return Object The current version of DOMIT! RSS
  74. */
  75. function getVersion() {
  76. return DOMIT_RSS_LITE_VERSION;
  77. } //getVersion
  78. } //xml_domit_rss_document_lite
  79. /**
  80. * Represents an RSS channel
  81. *
  82. * @package domit-rss
  83. * @subpackage domit-rss-lite
  84. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  85. */
  86. class xml_domit_rss_channel_lite extends xml_domit_rss_elementindexer {
  87. /** @var array A list of references to channel items */
  88. var $domit_rss_items = array();
  89. /**
  90. * Constructor
  91. * @param Object A DOM node containing channel data
  92. */
  93. function xml_domit_rss_channel_lite(&$channel) {
  94. $this->node =& $channel;
  95. $this->_init();
  96. } //xml_domit_rss_channel_lite
  97. /**
  98. * Performs initialization of the RSS channel element
  99. */
  100. function _init() {
  101. $total = $this->node->childCount;
  102. $itemCounter = 0;
  103. for ($i = 0; $i < $total; $i++) {
  104. $currNode =& $this->node->childNodes[$i];
  105. $tagName = strtolower($currNode->nodeName);
  106. switch ($tagName) {
  107. case DOMIT_RSS_ELEMENT_ITEM:
  108. $this->domit_rss_items[$itemCounter] = new xml_domit_rss_item_lite($currNode);
  109. $itemCounter++;
  110. break;
  111. case DOMIT_RSS_ELEMENT_TITLE:
  112. case DOMIT_RSS_ELEMENT_LINK:
  113. case DOMIT_RSS_ELEMENT_DESCRIPTION:
  114. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_simpleelement($currNode);
  115. break;
  116. }
  117. }
  118. if ($itemCounter != 0) {
  119. $this->DOMIT_RSS_indexer[DOMIT_RSS_ARRAY_ITEMS] =& $this->domit_rss_items;
  120. }
  121. } //_init
  122. /**
  123. * Returns the title of the channel
  124. * @return string The title of the channel, or an empty string
  125. */
  126. function getTitle() {
  127. return $this->getElementText(DOMIT_RSS_ELEMENT_TITLE);
  128. } //getTitle
  129. /**
  130. * Returns the url of the channel
  131. * @return string The url of the channel, or an empty string
  132. */
  133. function getLink() {
  134. return $this->getElementText(DOMIT_RSS_ELEMENT_LINK);
  135. } //getLink
  136. /**
  137. * Returns a description of the channel
  138. * @return string A description of the channel, or an empty string
  139. */
  140. function getDescription() {
  141. return $this->getElementText(DOMIT_RSS_ELEMENT_DESCRIPTION);
  142. } //getDescription
  143. /**
  144. * Returns the number of items in the channel
  145. * @return int The number of items in the channel
  146. */
  147. function getItemCount() {
  148. return count($this->domit_rss_items);
  149. } //getItemCount
  150. /**
  151. * Returns a reference to the item at the specified index
  152. * @param int The index of the requested item
  153. * @return Object A reference to the item at the specified index
  154. */
  155. function &getItem($index) {
  156. return $this->domit_rss_items[$index];
  157. } //getItem
  158. } //xml_domit_rss_channel_lite
  159. /**
  160. * Represents an RSS item
  161. *
  162. * @package domit-rss
  163. * @subpackage domit-rss-lite
  164. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  165. */
  166. class xml_domit_rss_item_lite extends xml_domit_rss_elementindexer {
  167. /**
  168. * Constructor
  169. * @param Object A DOM node containing item data
  170. */
  171. function xml_domit_rss_item_lite(&$item) {
  172. $this->node =& $item;
  173. $this->_init();
  174. } //xml_domit_rss_item_lite
  175. /**
  176. * Performs initialization of the item element
  177. */
  178. function _init(){
  179. $total = $this->node->childCount;
  180. for($i = 0; $i < $total; $i++) {
  181. $currNode =& $this->node->childNodes[$i];
  182. $tagName = strtolower($currNode->nodeName);
  183. switch ($tagName) {
  184. case DOMIT_RSS_ELEMENT_TITLE:
  185. case DOMIT_RSS_ELEMENT_LINK:
  186. case DOMIT_RSS_ELEMENT_DESCRIPTION:
  187. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_simpleelement($currNode);
  188. break;
  189. }
  190. }
  191. } //init
  192. /**
  193. * Returns the title of the item
  194. * @return string The title of the item, or an empty string
  195. */
  196. function getTitle() {
  197. return $this->getElementText(DOMIT_RSS_ELEMENT_TITLE);
  198. } //getTitle
  199. /**
  200. * Returns the url of the item
  201. * @return string The url of the item, or an empty string
  202. */
  203. function getLink() {
  204. return $this->getElementText(DOMIT_RSS_ELEMENT_LINK);
  205. } //getLink
  206. /**
  207. * Returns a description of the item
  208. * @return string A description of the item, or an empty string
  209. */
  210. function getDescription() {
  211. return $this->getElementText(DOMIT_RSS_ELEMENT_DESCRIPTION);
  212. } //getDescription
  213. } //xml_domit_rss_item_lite
  214. ?>