You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.0 KiB

  1. <?php
  2. /*
  3. This file is part of ActiveLink PHP XML Package (www.active-link.com).
  4. Copyright (c) 2002-2004 by Zurab Davitiani
  5. You can contact the author of this software via E-mail at
  6. hattrick@mailcan.com
  7. ActiveLink PHP XML Package is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU Lesser General Public License as published by
  9. the Free Software Foundation; either version 2.1 of the License, or
  10. (at your option) any later version.
  11. ActiveLink PHP XML Package is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public License
  16. along with ActiveLink PHP XML Package; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. import("org.active-link.xml.XML");
  20. /**
  21. * Simple RSS class based on XML
  22. * @class RSS
  23. * @package org.active-link.xml
  24. * @author Zurab Davitiani
  25. * @version 0.4.0
  26. * @requires XML
  27. * @see XML
  28. */
  29. class RSS {
  30. var $xml;
  31. var $rootTags;
  32. var $itemBranches;
  33. /**
  34. * Constructor, parses the supplied RSS string into the object
  35. * @method RSS
  36. * @param string parseString
  37. * @returns none
  38. */
  39. function RSS($parseString) {
  40. $this->xml = new XML($parseString);
  41. $this->rootTags = array("rss", "rdf:RDF");
  42. $this->itemBranches = array();
  43. $this->parseItemBranches();
  44. }
  45. /**
  46. * Returns array of references to item branches of the RSS
  47. * @method getItemBranches
  48. * @returns array of references to objects of type XMLBranch (item branches of RSS)
  49. */
  50. function getItemBranches() {
  51. return $this->itemBranches;
  52. }
  53. /**
  54. * Returns HTML-formatted RSS items
  55. * @method getHTMLTitlesFormatted
  56. * @returns string HTML-formatted RSS items
  57. */
  58. function getHTMLTitlesFormatted() {
  59. $itemBranchesXML = new XML("ul");
  60. reset($this->itemBranches);
  61. foreach($this->itemBranches as $newsItem) {
  62. $itemXML = new XMLBranch("li");
  63. $itemLinkXML = new XMLBranch("a");
  64. $itemLinkXML->setTagContent($newsItem->getTagContent("item/title"));
  65. $itemLinkXML->setTagAttribute("href", $newsItem->getTagContent("item/link"));
  66. $itemXML->addXMLBranch($itemLinkXML);
  67. $itemBranchesXML->addXMLBranch($itemXML);
  68. }
  69. return $itemBranchesXML->getXMLString();
  70. }
  71. /**
  72. * Parses RSS item branches, called from constructor
  73. * @method parseItemBranches
  74. * @returns true if successful, false otherwise
  75. */
  76. function parseItemBranches() {
  77. $success = false;
  78. $rootTagName = $this->xml->getTagName();
  79. if(in_array($rootTagName, $this->rootTags)) {
  80. $tempBranches = array();
  81. if($rootTagName == "rss")
  82. $tempBranches = $this->xml->getBranches($rootTagName . "/channel", "item");
  83. elseif($rootTagName == "rdf:RDF")
  84. $tempBranches = $this->xml->getBranches($rootTagName, "item");
  85. if($tempBranches !== false) {
  86. $this->itemBranches = $tempBranches;
  87. $success = true;
  88. }
  89. }
  90. return $success;
  91. }
  92. }
  93. ?>