PageRenderTime 81ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/domit/xml_domit_rss.php

https://gitlab.com/endomorphosis/greenrenaissancejoomla
PHP | 1121 lines | 546 code | 117 blank | 458 comment | 41 complexity | c877f8461536ce796e953facd754141d MD5 | raw file
  1. <?php
  2. /**
  3. * DOMIT! RSS is a DOM based RSS parser
  4. * @package domit-rss
  5. * @subpackage domit-rss-main
  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 */
  17. define ('DOMIT_RSS_VERSION', '0.51');
  18. /** language constant */
  19. define('DOMIT_RSS_ELEMENT_LANGUAGE', 'language');
  20. /** copyright constant */
  21. define('DOMIT_RSS_ELEMENT_COPYRIGHT', 'copyright');
  22. /** managing editor constant */
  23. define('DOMIT_RSS_ELEMENT_MANAGINGEDITOR', 'managingeditor');
  24. /** webmaster constant */
  25. define('DOMIT_RSS_ELEMENT_WEBMASTER', 'webmaster');
  26. /** pubdate constant */
  27. define('DOMIT_RSS_ELEMENT_PUBDATE', 'pubdate');
  28. /** last build date constant */
  29. define('DOMIT_RSS_ELEMENT_LASTBUILDDATE', 'lastbuilddate');
  30. /** category constant */
  31. define('DOMIT_RSS_ELEMENT_CATEGORY', 'category');
  32. /** generator constant */
  33. define('DOMIT_RSS_ELEMENT_GENERATOR', 'generator');
  34. /** docs constant */
  35. define('DOMIT_RSS_ELEMENT_DOCS', 'docs');
  36. /** cloud constant */
  37. define('DOMIT_RSS_ELEMENT_CLOUD', 'cloud');
  38. /** ttl constant */
  39. define('DOMIT_RSS_ELEMENT_TTL', 'ttl');
  40. /** image constant */
  41. define('DOMIT_RSS_ELEMENT_IMAGE', 'image');
  42. /** rating constant */
  43. define('DOMIT_RSS_ELEMENT_RATING', 'rating');
  44. /** textinput constant */
  45. define('DOMIT_RSS_ELEMENT_TEXTINPUT', 'textinput');
  46. /** skiphours constant */
  47. define('DOMIT_RSS_ELEMENT_SKIPHOURS', 'skiphours');
  48. /** skipdays constant */
  49. define('DOMIT_RSS_ELEMENT_SKIPDAYS', 'skipdays');
  50. /** url constant */
  51. define('DOMIT_RSS_ELEMENT_URL', 'url');
  52. /** width constant */
  53. define('DOMIT_RSS_ELEMENT_WIDTH', 'width');
  54. /** height constant */
  55. define('DOMIT_RSS_ELEMENT_HEIGHT', 'height');
  56. /** guid constant */
  57. define('DOMIT_RSS_ELEMENT_GUID', 'guid');
  58. /** enclosure constant */
  59. define('DOMIT_RSS_ELEMENT_ENCLOSURE', 'enclosure');
  60. /** comments constant */
  61. define('DOMIT_RSS_ELEMENT_COMMENTS', 'comments');
  62. /** source constant */
  63. define('DOMIT_RSS_ELEMENT_SOURCE', 'source');
  64. /** name constant */
  65. define('DOMIT_RSS_ELEMENT_NAME', 'name');
  66. /** author constant */
  67. define('DOMIT_RSS_ELEMENT_AUTHOR', 'author');
  68. /** domain constant */
  69. define('DOMIT_RSS_ATTR_DOMAIN', 'domain');
  70. /** port constant */
  71. define('DOMIT_RSS_ATTR_PORT', 'port');
  72. /** path constant */
  73. define('DOMIT_RSS_ATTR_PATH', 'path');
  74. /** registerProcedure constant */
  75. define('DOMIT_RSS_ATTR_REGISTERPROCEDURE', 'registerProcedure');
  76. /** protocol constant */
  77. define('DOMIT_RSS_ATTR_PROTOCOL', 'protocol');
  78. /** url constant */
  79. define('DOMIT_RSS_ATTR_URL', 'url');
  80. /** length constant */
  81. define('DOMIT_RSS_ATTR_LENGTH', 'length');
  82. /** type constant */
  83. define('DOMIT_RSS_ATTR_TYPE', 'type');
  84. /** isPermaLink constant */
  85. define('DOMIT_RSS_ATTR_ISPERMALINK', 'isPermaLink');
  86. require_once(DOMIT_RSS_INCLUDE_PATH . 'xml_domit_rss_shared.php');
  87. /**
  88. * The base DOMIT! RSS document class
  89. *
  90. * @package domit-rss
  91. * @subpackage domit-rss-main
  92. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  93. */
  94. class xml_domit_rss_document extends xml_domit_rss_base_document {
  95. /**
  96. * Constructor
  97. * @param string Path to the rss file
  98. * @param string Directory in which cache files are to be stored
  99. * @param string Expiration time (in seconds) for the cache file
  100. * @return Object A new instance of xml_domit_rss_document
  101. */
  102. function xml_domit_rss_document($url = '', $cacheDir = './', $cacheTime = '3600') {
  103. $this->parser = 'DOMIT_RSS';
  104. $this->xml_domit_rss_base_document($url, $cacheDir, $cacheTime);
  105. } //xml_domit_rss_document
  106. /**
  107. * Performs initialization of the RSS document
  108. */
  109. function _init() {
  110. $total = $this->node->documentElement->childCount;
  111. $itemCounter = 0;
  112. $channelCounter = 0;
  113. $categoryCounter = 0;
  114. for ($i = 0; $i < $total; $i++) {
  115. $currNode =& $this->node->documentElement->childNodes[$i];
  116. $tagName = strtolower($currNode->nodeName);
  117. switch ($tagName) {
  118. case DOMIT_RSS_ELEMENT_ITEM:
  119. $this->domit_rss_items[$itemCounter] = new xml_domit_rss_item($currNode);
  120. $itemCounter++;
  121. break;
  122. case DOMIT_RSS_ELEMENT_CHANNEL:
  123. $this->domit_rss_channels[$channelCounter] = new xml_domit_rss_channel($currNode);
  124. $channelCounter++;
  125. break;
  126. case DOMIT_RSS_ELEMENT_CATEGORY:
  127. $this->domit_rss_categories[$categoryCounter] = new xml_domit_rss_category($currNode);
  128. $categoryCounter++;
  129. break;
  130. case DOMIT_RSS_ELEMENT_IMAGE:
  131. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_image($currNode);
  132. break;
  133. case DOMIT_RSS_ELEMENT_CLOUD:
  134. $this->indexer[$tagName] = new xml_domit_rss_cloud($currNode);
  135. break;
  136. case DOMIT_RSS_ELEMENT_TEXTINPUT:
  137. $this->indexer[$tagName] = new xml_domit_rss_textinput($currNode);
  138. break;
  139. case DOMIT_RSS_ELEMENT_TITLE:
  140. case DOMIT_RSS_ELEMENT_LINK:
  141. case DOMIT_RSS_ELEMENT_DESCRIPTION:
  142. case DOMIT_RSS_ELEMENT_LANGUAGE:
  143. case DOMIT_RSS_ELEMENT_COPYRIGHT:
  144. case DOMIT_RSS_ELEMENT_MANAGINGEDITOR:
  145. case DOMIT_RSS_ELEMENT_WEBMASTER:
  146. case DOMIT_RSS_ELEMENT_PUBDATE:
  147. case DOMIT_RSS_ELEMENT_LASTBUILDDATE:
  148. case DOMIT_RSS_ELEMENT_GENERATOR:
  149. case DOMIT_RSS_ELEMENT_DOCS:
  150. case DOMIT_RSS_ELEMENT_TTL:
  151. case DOMIT_RSS_ELEMENT_RATING:
  152. case DOMIT_RSS_ELEMENT_SKIPHOURS:
  153. case DOMIT_RSS_ELEMENT_SKIPDAYS:
  154. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_simpleelement($currNode);
  155. break;
  156. default:
  157. $this->addIndexedElement($currNode);
  158. //$this->indexer[$tagName] =& $currNode;
  159. }
  160. }
  161. if ($itemCounter != 0) {
  162. $this->DOMIT_RSS_indexer[DOMIT_RSS_ARRAY_ITEMS] =& $this->domit_rss_items;
  163. }
  164. if ($channelCounter != 0) {
  165. $this->DOMIT_RSS_indexer[DOMIT_RSS_ARRAY_CHANNELS] =& $this->domit_rss_channels;
  166. }
  167. if ($categoryCounter != 0) {
  168. $this->DOMIT_RSS_indexer[DOMIT_RSS_ARRAY_CATEGORIES] =& $this->domit_rss_categories;
  169. }
  170. $this->handleChannelElementsEmbedded();
  171. } //_init
  172. /**
  173. * Returns the current version of DOMIT! RSS
  174. * @return int The current version of DOMIT! RSS
  175. */
  176. function getVersion() {
  177. return DOMIT_RSS_VERSION;
  178. } //getVersion
  179. } //xml_domit_rss_document
  180. /**
  181. * Represents an RSS channel
  182. *
  183. * @package domit-rss
  184. * @subpackage domit-rss-main
  185. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  186. */
  187. class xml_domit_rss_channel extends xml_domit_rss_elementindexer {
  188. /** @var array A list of references to channel items */
  189. var $domit_rss_items = array();
  190. /** @var array A list of references to category items */
  191. var $domit_rss_categories = array();
  192. /**
  193. * Constructor
  194. * @param Object A DOM node containing channel data
  195. * @param boolean True if channel elements are siblings of the channel rather than children
  196. */
  197. function xml_domit_rss_channel(&$channel, $externalElements = false) {
  198. $this->node =& $channel;
  199. $this->rssDefinedElements = array('title','link','description','language','copyright',
  200. 'managingEditor','webmaster','pubDate','lastBuildDate',
  201. 'generator','docs','cloud','ttl','image', 'rating',
  202. 'textInput','skipHours','skipDays','domit_rss_channels',
  203. 'domit_rss_items','domit_rss_categories');
  204. $this->_init();
  205. } //xml_domit_rss_channel
  206. /**
  207. * Performs initialization of the RSS channel element
  208. */
  209. function _init() {
  210. $total = $this->node->childCount;
  211. $itemCounter = 0;
  212. $categoryCounter = 0;
  213. for ($i = 0; $i < $total; $i++) {
  214. $currNode =& $this->node->childNodes[$i];
  215. $tagName = strtolower($currNode->nodeName);
  216. switch($tagName) {
  217. case DOMIT_RSS_ELEMENT_ITEM:
  218. $this->domit_rss_items[$itemCounter] = new xml_domit_rss_item($currNode);
  219. $itemCounter++;
  220. break;
  221. case DOMIT_RSS_ELEMENT_CATEGORY:
  222. $this->domit_rss_categories[$categoryCounter] = new xml_domit_rss_category($currNode);
  223. $categoryCounter++;
  224. break;
  225. case DOMIT_RSS_ELEMENT_IMAGE:
  226. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_image($currNode);
  227. break;
  228. case DOMIT_RSS_ELEMENT_CLOUD:
  229. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_cloud($currNode);
  230. break;
  231. case DOMIT_RSS_ELEMENT_TEXTINPUT:
  232. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_textinput($currNode);
  233. break;
  234. case DOMIT_RSS_ELEMENT_SKIPHOURS:
  235. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_skiphours($currNode);
  236. break;
  237. case DOMIT_RSS_ELEMENT_SKIPDAYS:
  238. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_skipdays($currNode);
  239. break;
  240. case DOMIT_RSS_ELEMENT_TITLE:
  241. case DOMIT_RSS_ELEMENT_LINK:
  242. case DOMIT_RSS_ELEMENT_DESCRIPTION:
  243. case DOMIT_RSS_ELEMENT_LANGUAGE:
  244. case DOMIT_RSS_ELEMENT_COPYRIGHT:
  245. case DOMIT_RSS_ELEMENT_MANAGINGEDITOR:
  246. case DOMIT_RSS_ELEMENT_WEBMASTER:
  247. case DOMIT_RSS_ELEMENT_PUBDATE:
  248. case DOMIT_RSS_ELEMENT_LASTBUILDDATE:
  249. case DOMIT_RSS_ELEMENT_GENERATOR:
  250. case DOMIT_RSS_ELEMENT_DOCS:
  251. case DOMIT_RSS_ELEMENT_TTL:
  252. case DOMIT_RSS_ELEMENT_RATING:
  253. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_simpleelement($currNode);
  254. break;
  255. default:
  256. $this->addIndexedElement($currNode);
  257. //$this->DOMIT_RSS_indexer[$tagName] =& $currNode;
  258. }
  259. }
  260. if ($itemCounter != 0) {
  261. $this->DOMIT_RSS_indexer[DOMIT_RSS_ARRAY_ITEMS] =& $this->domit_rss_items;
  262. }
  263. if ($categoryCounter != 0) {
  264. $this->DOMIT_RSS_indexer[DOMIT_RSS_ARRAY_CATEGORIES] =& $this->domit_rss_categories;
  265. }
  266. } //_init
  267. /**
  268. * Returns the title of the channel
  269. * @return string The title of the channel, or an empty string
  270. */
  271. function getTitle() {
  272. return $this->getElementText(DOMIT_RSS_ELEMENT_TITLE);
  273. } //getTitle
  274. /**
  275. * Returns the url of the channel
  276. * @return string The url of the channel, or an empty string
  277. */
  278. function getLink() {
  279. return $this->getElementText(DOMIT_RSS_ELEMENT_LINK);
  280. } //getLink
  281. /**
  282. * Returns a description of the channel
  283. * @return string A description of the channel, or an empty string
  284. */
  285. function getDescription() {
  286. return $this->getElementText(DOMIT_RSS_ELEMENT_DESCRIPTION);
  287. } //getDescription
  288. /**
  289. * Returns the language of the channel
  290. * @return string The language of the channel, or an empty string
  291. */
  292. function getLanguage() {
  293. return $this->getElementText(DOMIT_RSS_ELEMENT_LANGUAGE);
  294. } //getLanguage
  295. /**
  296. * Returns the copyright of the channel
  297. * @return string The copyright of the channel, or an empty string
  298. */
  299. function getCopyright() {
  300. return $this->getElementText(DOMIT_RSS_ELEMENT_COPYRIGHT);
  301. } //getCopyright
  302. /**
  303. * Returns the managing editor of the channel
  304. * @return string The managing editor of the channel, or an empty string
  305. */
  306. function getManagingEditor() {
  307. return $this->getElementText(DOMIT_RSS_ELEMENT_MANAGINGEDITOR);
  308. } //getManagingEditor
  309. /**
  310. * Returns the webmaster of the channel
  311. * @return string The webmaster of the channel, or an empty string
  312. */
  313. function getWebMaster() {
  314. return $this->getElementText(DOMIT_RSS_ELEMENT_WEBMASTER);
  315. } //getWebMaster
  316. /**
  317. * Returns the publication date of the channel
  318. * @return string The publication date of the channel, or an empty string
  319. */
  320. function getPubDate() {
  321. return $this->getElementText(DOMIT_RSS_ELEMENT_PUBDATE);
  322. } //getPubDate
  323. /**
  324. * Returns the last build date of the channel
  325. * @return string The last build date of the channel, or an empty string
  326. */
  327. function getLastBuildDate() {
  328. return $this->getElementText(DOMIT_RSS_ELEMENT_LASTBUILDDATE);
  329. } //getLastBuildDate
  330. /**
  331. * Returns the generator of the channel
  332. * @return string The generator of the channel, or an empty string
  333. */
  334. function getGenerator() {
  335. return $this->getElementText(DOMIT_RSS_ELEMENT_GENERATOR);
  336. } //getGenerator
  337. /**
  338. * Returns the docs of the channel
  339. * @return string The docs of the channel, or an empty string
  340. */
  341. function getDocs() {
  342. return $this->getElementText(DOMIT_RSS_ELEMENT_DOCS);
  343. } //getDocs
  344. /**
  345. * Returns the cloud of the channel
  346. * @return object A reference to the cloud object for the channel, or null
  347. */
  348. function getCloud() {
  349. if ($this->hasElement(DOMIT_RSS_ELEMENT_CLOUD)) {
  350. return $this->getElement(DOMIT_RSS_ELEMENT_CLOUD);
  351. }
  352. return null;
  353. } //getCloud
  354. /**
  355. * Returns the ttl of the channel
  356. * @return string The ttl of the channel, or an empty string
  357. */
  358. function getTTL() {
  359. return $this->getElementText(DOMIT_RSS_ELEMENT_TTL);
  360. } //getTTL
  361. /**
  362. * Returns the image of the channel
  363. * @return object A reference to an image object for the channel, or null
  364. */
  365. function getImage() {
  366. if ($this->hasElement(DOMIT_RSS_ELEMENT_IMAGE)) {
  367. return $this->getElement(DOMIT_RSS_ELEMENT_IMAGE);
  368. }
  369. return null;
  370. } //getImage
  371. /**
  372. * Returns the rating of the channel
  373. * @return string The rating of the channel, or an empty string
  374. */
  375. function getRating() {
  376. return $this->getElementText(DOMIT_RSS_ELEMENT_RATING);
  377. } //getRating
  378. /**
  379. * Returns the text input box of the channel
  380. * @return object A reference to a text input box object for the channel, or null
  381. */
  382. function getTextInput() {
  383. if ($this->hasElement(DOMIT_RSS_ELEMENT_TEXTINPUT)) {
  384. return $this->getElement(DOMIT_RSS_ELEMENT_TEXTINPUT);
  385. }
  386. return null;
  387. } //getTextInput
  388. /**
  389. * Returns the skip days of the channel
  390. * @return object A reference to the skip days object for the channel, or null
  391. */
  392. function getSkipDays() {
  393. if ($this->hasElement(DOMIT_RSS_ELEMENT_SKIPDAYS)) {
  394. return $this->getElement(DOMIT_RSS_ELEMENT_SKIPDAYS);
  395. }
  396. return null;
  397. } //getSkipDays
  398. /**
  399. * Returns the skip hours of the channel
  400. * @return object A reference to the skip hours object for the channel, or null
  401. */
  402. function getSkipHours() {
  403. if ($this->hasElement(DOMIT_RSS_ELEMENT_SKIPHOURS)) {
  404. return $this->getElement(DOMIT_RSS_ELEMENT_SKIPHOURS);
  405. }
  406. return null;
  407. } //getSkipHours
  408. /**
  409. * Returns the number of items in the channel
  410. * @return int The number of items in the channel
  411. */
  412. function getItemCount() {
  413. return count($this->domit_rss_items);
  414. } //getItemCount
  415. /**
  416. * Returns a reference to the item at the specified index
  417. * @param int The index of the requested item
  418. * @return Object A reference to the item at the specified index
  419. */
  420. function &getItem($index) {
  421. return $this->domit_rss_items[$index];
  422. } //getItem
  423. /**
  424. * Returns the number of categories in the channel
  425. * @return int The number of categories in the channel
  426. */
  427. function getCategoryCount() {
  428. return count($this->domit_rss_categories);
  429. } //getCategoryCount
  430. /**
  431. * Returns a reference to the category at the specified index
  432. * @param int The index of the requested category
  433. * @return Object A reference to the category at the specified index
  434. */
  435. function &getCategory($index) {
  436. return $this->domit_rss_categories[$index];
  437. } //getCategory
  438. } //xml_domit_rss_channel
  439. /**
  440. * Represents an RSS item
  441. *
  442. * @package domit-rss
  443. * @subpackage domit-rss-main
  444. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  445. */
  446. class xml_domit_rss_item extends xml_domit_rss_elementindexer {
  447. /** @var array A list of references to category items */
  448. var $domit_rss_categories = array();
  449. /**
  450. * Constructor
  451. * @param Object A DOM node containing item data
  452. */
  453. function xml_domit_rss_item(&$item) {
  454. $this->node =& $item;
  455. $this->rssDefinedElements = array('title','link','description','author','comments',
  456. 'enclosure','guid','pubDate','source','domit_rss_categories');
  457. $this->_init();
  458. } //xml_domit_rss_item
  459. /**
  460. * Performs initialization of the item element
  461. */
  462. function _init(){
  463. $total = $this->node->childCount;
  464. $categoryCounter = 0;
  465. for($i = 0; $i < $total; $i++) {
  466. $currNode =& $this->node->childNodes[$i];
  467. $tagName = strtolower($currNode->nodeName);
  468. switch ($tagName) {
  469. case DOMIT_RSS_ELEMENT_CATEGORY:
  470. $this->categories[$categoryCounter] = new xml_domit_rss_category($currNode);
  471. $categoryCounter++;
  472. break;
  473. case DOMIT_RSS_ELEMENT_ENCLOSURE:
  474. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_enclosure($currNode);
  475. break;
  476. case DOMIT_RSS_ELEMENT_SOURCE:
  477. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_source($currNode);
  478. break;
  479. case DOMIT_RSS_ELEMENT_GUID:
  480. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_guid($currNode);
  481. break;
  482. case DOMIT_RSS_ELEMENT_TITLE:
  483. case DOMIT_RSS_ELEMENT_LINK:
  484. case DOMIT_RSS_ELEMENT_DESCRIPTION:
  485. case DOMIT_RSS_ELEMENT_AUTHOR:
  486. case DOMIT_RSS_ELEMENT_COMMENTS:
  487. case DOMIT_RSS_ELEMENT_PUBDATE:
  488. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_simpleelement($currNode);
  489. break;
  490. default:
  491. $this->addIndexedElement($currNode);
  492. //$this->DOMIT_RSS_indexer[$tagName] =& $currNode;
  493. }
  494. }
  495. if ($categoryCounter != 0) {
  496. $this->DOMIT_RSS_indexer[DOMIT_RSS_ARRAY_CATEGORIES] =& $this->domit_rss_categories;
  497. }
  498. } //init
  499. /**
  500. * Returns the title of the item
  501. * @return string The title of the item, or an empty string
  502. */
  503. function getTitle() {
  504. return $this->getElementText(DOMIT_RSS_ELEMENT_TITLE);
  505. } //getTitle
  506. /**
  507. * Returns the url of the item
  508. * @return string The url of the item, or an empty string
  509. */
  510. function getLink() {
  511. return $this->getElementText(DOMIT_RSS_ELEMENT_LINK);
  512. } //getLink
  513. /**
  514. * Returns a description of the item
  515. * @return string A description of the item, or an empty string
  516. */
  517. function getDescription() {
  518. return $this->getElementText(DOMIT_RSS_ELEMENT_DESCRIPTION);
  519. } //getDescription
  520. /**
  521. * Returns the author of the item
  522. * @return string The author of the item, or an empty string
  523. */
  524. function getAuthor() {
  525. return $this->getElementText(DOMIT_RSS_ELEMENT_AUTHOR);
  526. } //getAuthor
  527. /**
  528. * Returns the comments of the item
  529. * @return string The comments of the item, or an empty string
  530. */
  531. function getComments() {
  532. return $this->getElementText(DOMIT_RSS_ELEMENT_COMMENTS);
  533. } //getComments
  534. /**
  535. * Returns the enclosure of the item
  536. * @return object A reference to the enclosure object for the item, or null
  537. */
  538. function getEnclosure() {
  539. if ($this->hasElement(DOMIT_RSS_ELEMENT_ENCLOSURE)) {
  540. return $this->getElement(DOMIT_RSS_ELEMENT_ENCLOSURE);
  541. }
  542. return null;
  543. } //getEnclosure
  544. /**
  545. * Returns the guid of the item
  546. * @return object A reference to the guid object for the item, or null
  547. */
  548. function getGUID() {
  549. if ($this->hasElement(DOMIT_RSS_ELEMENT_GUID)) {
  550. return $this->getElement(DOMIT_RSS_ELEMENT_GUID);
  551. }
  552. return null;
  553. } //getGUID
  554. /**
  555. * Returns the publication date of the item
  556. * @return string The publication date of the item, or an empty string
  557. */
  558. function getPubDate() {
  559. return $this->getElementText(DOMIT_RSS_ELEMENT_PUBDATE);
  560. } //getPubDate
  561. /**
  562. * Returns the source of the item
  563. * @return object A reference to the source object for the item, or null
  564. */
  565. function getSource() {
  566. if ($this->hasElement(DOMIT_RSS_ELEMENT_SOURCE)) {
  567. return $this->getElement(DOMIT_RSS_ELEMENT_SOURCE);
  568. }
  569. return null;
  570. } //getSource
  571. /**
  572. * Returns the number of categories in the item
  573. * @return int The number of categories in the item
  574. */
  575. function getCategoryCount() {
  576. return count($this->domit_rss_categories);
  577. } //getCategoryCount
  578. /**
  579. * Returns a reference to the category at the specified index
  580. * @param int The index of the requested category
  581. * @return Object A reference to the category at the specified index
  582. */
  583. function &getCategory($index) {
  584. return $this->domit_rss_categories[$index];
  585. } //getCategory
  586. } //xml_domit_rss_item
  587. /**
  588. * Represents an RSS category
  589. *
  590. * @package domit-rss
  591. * @subpackage domit-rss-main
  592. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  593. */
  594. class xml_domit_rss_category extends xml_domit_rss_elementindexer {
  595. /**
  596. * Constructor
  597. * @param Object A DOM node containing category data
  598. */
  599. function xml_domit_rss_category(&$category) {
  600. $this->node =& $category;
  601. $this->_init();
  602. } //xml_domit_rss_category
  603. /**
  604. * Returns the category
  605. * @return string The category text
  606. */
  607. function getCategory() {
  608. return $this->node->firstChild->toString();
  609. } //getCategory
  610. /**
  611. * Returns the category domain
  612. * @return string The category domain
  613. */
  614. function getDomain() {
  615. return $this->getAttribute(DOMIT_RSS_ATTR_DOMAIN);
  616. } //getDomain
  617. } //xml_domit_rss_category
  618. /**
  619. * Represents an RSS image
  620. *
  621. * @package domit-rss
  622. * @subpackage domit-rss-main
  623. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  624. */
  625. class xml_domit_rss_image extends xml_domit_rss_elementindexer {
  626. /**
  627. * Constructor
  628. * @param Object A DOM node containing image data
  629. */
  630. function xml_domit_rss_image(&$image) {
  631. $this->node =& $image;
  632. $this->rssDefinedElements = array('title','link','description','url',
  633. 'width', 'height');
  634. $this->_init();
  635. } //xml_domit_rss_image
  636. /**
  637. * Performs initialization of image element
  638. */
  639. function _init(){
  640. $total = $this->node->childCount;
  641. for($i = 0; $i < $total; $i++) {
  642. $currNode =& $this->node->childNodes[$i];
  643. $tagName = strtolower($currNode->nodeName);
  644. switch ($tagName) {
  645. case DOMIT_RSS_ELEMENT_TITLE:
  646. case DOMIT_RSS_ELEMENT_LINK:
  647. case DOMIT_RSS_ELEMENT_DESCRIPTION:
  648. case DOMIT_RSS_ELEMENT_URL:
  649. case DOMIT_RSS_ELEMENT_WIDTH:
  650. case DOMIT_RSS_ELEMENT_HEIGHT:
  651. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_simpleelement($currNode);
  652. break;
  653. default:
  654. $this->addIndexedElement($currNode);
  655. //$this->DOMIT_RSS_indexer[$tagName] =& $currNode;
  656. }
  657. }
  658. } //_init
  659. /**
  660. * Returns the image title
  661. * @return string The image title
  662. */
  663. function getTitle() {
  664. return $this->getElementText(DOMIT_RSS_ELEMENT_TITLE);
  665. } //getTitle
  666. /**
  667. * Returns the image link
  668. * @return string The image link
  669. */
  670. function getLink() {
  671. return $this->getElementText(DOMIT_RSS_ELEMENT_LINK);
  672. } //getLink
  673. /**
  674. * Returns the image url
  675. * @return string The image url
  676. */
  677. function getUrl() {
  678. return $this->getElementText(DOMIT_RSS_ELEMENT_URL);
  679. } //getUrl
  680. /**
  681. * Returns the image width in pixels
  682. * @return string The image width (maximum 144, default 88)
  683. */
  684. function getWidth() {
  685. $myWidth = $this->getElementText(DOMIT_RSS_ELEMENT_WIDTH);
  686. if ($myWidth == '') {
  687. $myWidth = '88';
  688. }
  689. else if (intval($myWidth) > 144) {
  690. $myWidth = '144';
  691. }
  692. return $myWidth;
  693. } //getWidth
  694. /**
  695. * Returns the image height in pixels
  696. * @return string The image height (maximum 400, default 31)
  697. */
  698. function getHeight() {
  699. $myHeight = $this->getElementText(DOMIT_RSS_ELEMENT_HEIGHT);
  700. if ($myHeight == '') {
  701. $myHeight = '31';
  702. }
  703. else if (intval($myHeight) > 400) {
  704. $myHeight = '400';
  705. }
  706. return $myHeight;
  707. } //getHeight
  708. /**
  709. * Returns the image description
  710. * @return string The image description
  711. */
  712. function getDescription() {
  713. return $this->getElementText(DOMIT_RSS_ELEMENT_DESCRIPTION);
  714. } //getDescription
  715. } //xml_domit_rss_image
  716. /**
  717. * Represents an RSS text input form
  718. *
  719. * @package domit-rss
  720. * @subpackage domit-rss-main
  721. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  722. */
  723. class xml_domit_rss_textinput extends xml_domit_rss_elementindexer {
  724. /**
  725. * Constructor
  726. * @param Object A DOM node containing text input data
  727. */
  728. function xml_domit_rss_textinput(&$textinput) {
  729. $this->node =& $textinput;
  730. $this->rssDefinedElements = array('title','link','description','name');
  731. $this->_init();
  732. } //xml_domit_rss_textinput
  733. /**
  734. * Performs initialization of textInput element
  735. */
  736. function _init(){
  737. $total = $this->node->childCount;
  738. for($i = 0; $i < $total; $i++) {
  739. $currNode =& $this->node->childNodes[$i];
  740. $tagName = strtolower($currNode->nodeName);
  741. switch ($tagName) {
  742. case DOMIT_RSS_ELEMENT_TITLE:
  743. case DOMIT_RSS_ELEMENT_LINK:
  744. case DOMIT_RSS_ELEMENT_DESCRIPTION:
  745. case DOMIT_RSS_ELEMENT_NAME:
  746. $this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_simpleelement($currNode);
  747. break;
  748. default:
  749. $this->addIndexedElement($currNode);
  750. //$this->DOMIT_RSS_indexer[$tagName] =& $currNode;
  751. }
  752. }
  753. } //_init
  754. /**
  755. * Returns the title of the text input
  756. * @return string The title of the text input, or an empty string
  757. */
  758. function getTitle() {
  759. return $this->getElementText(DOMIT_RSS_ELEMENT_TITLE);
  760. } //getTitle
  761. /**
  762. * Returns a description of the text input
  763. * @return string A description of the text input, or an empty string
  764. */
  765. function getDescription() {
  766. return $this->getElementText(DOMIT_RSS_ELEMENT_DESCRIPTION);
  767. } //getDescription
  768. /**
  769. * Returns the name of the text input
  770. * @return string The name of the text input, or an empty string
  771. */
  772. function getName() {
  773. return $this->getElementText(DOMIT_RSS_ELEMENT_NAME);
  774. } //getName
  775. /**
  776. * Returns the url of the text input
  777. * @return string The url of the text input, or an empty string
  778. */
  779. function getLink() {
  780. return $this->getElementText(DOMIT_RSS_ELEMENT_LINK);
  781. } //getLink
  782. } //xml_domit_rss_textinput
  783. /**
  784. * Represents an RSS cloud
  785. *
  786. * @package domit-rss
  787. * @subpackage domit-rss-main
  788. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  789. */
  790. class xml_domit_rss_cloud extends xml_domit_rss_elementindexer {
  791. /**
  792. * Constructor
  793. * @param Object A DOM node containing cloud data
  794. */
  795. function xml_domit_rss_cloud(&$cloud) {
  796. $this->node =& $cloud;
  797. $this->_init();
  798. } //xml_domit_rss_cloud
  799. /**
  800. * Returns the domain of the cloud
  801. * @return string The domain of the cloud
  802. */
  803. function getDomain() {
  804. return $this->getAttribute(DOMIT_RSS_ATTR_DOMAIN);
  805. } //getDomain
  806. /**
  807. * Returns the port of the cloud
  808. * @return string The port of the cloud
  809. */
  810. function getPort() {
  811. return $this->getAttribute(DOMIT_RSS_ATTR_PORT);
  812. } //getPort
  813. /**
  814. * Returns the path of the cloud
  815. * @return string The path of the cloud
  816. */
  817. function getPath() {
  818. return $this->getAttribute(DOMIT_RSS_ATTR_PATH);
  819. } //getPath
  820. /**
  821. * Returns the register procedure value of the cloud
  822. * @return string The register procedure value of the cloud
  823. */
  824. function getRegisterProcedure() {
  825. return $this->getAttribute(DOMIT_RSS_ATTR_REGISTERPROCEDURE);
  826. } //getRegisterProcedure
  827. /**
  828. * Returns the protocol used by the cloud
  829. * @return string The protocol used by the cloud
  830. */
  831. function getProtocol() {
  832. return $this->getAttribute(DOMIT_RSS_ATTR_PROTOCOL);
  833. } //getProtocol
  834. } //xml_domit_rss_cloud
  835. /**
  836. * Represents an RSS enclosure
  837. *
  838. * @package domit-rss
  839. * @subpackage domit-rss-main
  840. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  841. */
  842. class xml_domit_rss_enclosure extends xml_domit_rss_elementindexer {
  843. /**
  844. * Constructor
  845. * @param Object A DOM node containing enclosure data
  846. */
  847. function xml_domit_rss_enclosure(&$enclosure) {
  848. $this->node =& $enclosure;
  849. $this->_init();
  850. } //xml_domit_rss_enclosure
  851. /**
  852. * Returns the url of the enclosure
  853. * @return string The url of the enclosure
  854. */
  855. function getUrl() {
  856. return $this->getAttribute(DOMIT_RSS_ATTR_URL);
  857. } //getUrl
  858. /**
  859. * Returns the length of the enclosure
  860. * @return string The length of the enclosure
  861. */
  862. function getLength() {
  863. return $this->getAttribute(DOMIT_RSS_ATTR_LENGTH);
  864. } //getLength
  865. /**
  866. * Returns the type of the enclosure
  867. * @return string The type of the enclosure
  868. */
  869. function getType() {
  870. return $this->getAttribute(DOMIT_RSS_ATTR_TYPE);
  871. } //getType
  872. } //xml_domit_rss_enclosure
  873. /**
  874. * Represents an RSS guid
  875. *
  876. * @package domit-rss
  877. * @subpackage domit-rss-main
  878. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  879. */
  880. class xml_domit_rss_guid extends xml_domit_rss_elementindexer {
  881. /**
  882. * Constructor
  883. * @param Object A DOM node containing guid data
  884. */
  885. function xml_domit_rss_guid(&$guid) {
  886. $this->node =& $guid;
  887. $this->_init();
  888. } //xml_domit_rss_guid
  889. /**
  890. * Returns the guid text
  891. * @return string The guid text
  892. */
  893. function getGuid() {
  894. return $this->node->getText();
  895. } //getGuid
  896. /**
  897. * Determines whether the guid is a permalink
  898. * @return boolean True if the guid is a permalink (default true)
  899. */
  900. function isPermaLink() {
  901. if (!$this->node->hasAttribute(DOMIT_RSS_ATTR_ISPERMALINK)) {
  902. return true;
  903. }
  904. else {
  905. return (strtolower($this->node->getAttribute(DOMIT_RSS_ATTR_ISPERMALINK)) == "true");
  906. }
  907. } //isPermaLink
  908. } //xml_domit_rss_guid
  909. /**
  910. * Represents an RSS source
  911. *
  912. * @package domit-rss
  913. * @subpackage domit-rss-main
  914. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  915. */
  916. class xml_domit_rss_source extends xml_domit_rss_elementindexer {
  917. /**
  918. * Constructor
  919. * @param Object A DOM node containing source data
  920. */
  921. function xml_domit_rss_source(&$source) {
  922. $this->node =& $source;
  923. $this->_init();
  924. } //xml_domit_rss_source
  925. /**
  926. * Returns the source text
  927. * @return string The source text
  928. */
  929. function getSource() {
  930. return $this->node->getText();
  931. } //getSource
  932. /**
  933. * Returns the url of the source
  934. * @return string The url of the source
  935. */
  936. function getUrl() {
  937. return $this->getAttribute(DOMIT_RSS_ATTR_URL);
  938. } //getUrl
  939. } //xml_domit_rss_source
  940. /**
  941. * Represents an RSS skipDays element
  942. *
  943. * @package domit-rss
  944. * @subpackage domit-rss-main
  945. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  946. */
  947. class xml_domit_rss_skipdays extends xml_domit_rss_elementindexer {
  948. /**
  949. * Constructor
  950. * @param Object A DOM node containing source data
  951. */
  952. function xml_domit_rss_skipdays(&$skipdays) {
  953. $this->node =& $skipdays;
  954. $this->_init();
  955. } //xml_domit_rss_skipdays
  956. /**
  957. * Returns the number of skip day items
  958. * @return int The number of skip day items
  959. */
  960. function getSkipDayCount() {
  961. return $this->node->childCount;
  962. } //getSkipDayCount
  963. /**
  964. * Returns the day of the specified index (Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday)
  965. * @param int The index of the requested day
  966. * @return string The day of the specified index (Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday)
  967. */
  968. function getSkipDay($index) {
  969. return $this->node->childNodes[$index]->getText();
  970. } //getSkipDay
  971. } //xml_domit_rss_skipdays
  972. /**
  973. * Represents an RSS skipHours element
  974. *
  975. * @package domit-rss
  976. * @subpackage domit-rss-main
  977. * @author John Heinstein <johnkarl@nbnet.nb.ca>
  978. */
  979. class xml_domit_rss_skiphours extends xml_domit_rss_elementindexer {
  980. /**
  981. * Constructor
  982. * @param Object A DOM node containing source data
  983. */
  984. function xml_domit_rss_skiphours(&$skiphours) {
  985. $this->node =& $skiphours;
  986. $this->_init();
  987. } //xml_domit_rss_skiphours
  988. /**
  989. * Returns the number of skip hour items
  990. * @return int The number of skip hour items
  991. */
  992. function getSkipHourCount() {
  993. return $this->node->childCount;
  994. } //getSkipHourCount
  995. /**
  996. * Returns the hour of the specified index (0-23)
  997. * @param int The index of the requested hour
  998. * @return string The hour of the specified index (0-23)
  999. */
  1000. function getSkipHour($index) {
  1001. return $this->node->childNodes[$index]->getText();
  1002. } //getSkipHour
  1003. } //xml_domit_rss_skiphours
  1004. ?>