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