All pastes #161864 Raw Edit

LoBo_JeDi

public php v1 · immutable
·published 2006-09-05 21:42 UTC
rendered paste body
<?php/*rss.inc.phpCopyright (C)2006  Angel Alberto Briceño Obregón ( angel (at) peruviansoft (dot) com )This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.*/class image {	var $title;	var $url;	var $link;}class channel {	var $title;	var $link;	var $description;	var $language;	var $copyright;	var $managingEditor;	var $webMaster;	function channel() {		$this->image = new image;		$this->items = new items;	}	}class item {	var $title;	var $link;	var $description;	var $author;	var $category;	var $comments;	var $enclosure;	var $guid;	var $source;	function set_object ($attrib, $value) {		$this->$attrib = $value;	}}class items {	var $litems;	var $num_items;	function items() {		$this->num_items = 0;	}	function add_item() {		$this->litems[$this->num_items+1] = new item;		$this->num_items += 1;	}}class rss {var $version;var $url = '';var $ubicacion = '';var $in_item;var $in_channel;var $in_image;	function rss ($url) {		$this->url = $url;				$this->channel = new channel;		$this->parse();	}	function parse() {		$this->fpurl = fopen($this->url,'r');				while(!feof($this->fpurl)) {			$again_end=false;			$line = trim(fgets($this->fpurl,100000));			$label = "";			$type_label = "";			$is_label = false;			$content = "";			$within_channel=false;			$len_line = strlen($line)-1;			for ($i = 0; $i <= $len_line; $i++) {				$character = substr($line,$i,1);				switch ($character) {					case "<": // Empieza una etiqueta						$again_end=false;						$is_label = true;						$label .= $character;						break;					case ">": // Termina una etiqueta						if ($again_end) {							$content.=">";							$again_end=true;						} else {							$again_end=true;							$label .= $character;							$is_label = true;						}						break;					default:						if ($is_label) {							if ($again_end) {								$content.=$character;								$again_end=true;							} else {								$type_label .= $character;								$label.=$character;								$again_end=false;							}												} else {							$content .= $character;							$again_end=false;						}				}			 				}			$content=str_replace('&lt;','<',$content);			switch ($type_label) {				case "channel":					$this->in_channel=true;					break;				case "image":					$this->in_image=true;					break;				case "item":					$this->in_item=true;					$this->channel->items->add_item();					break;				case "/item":					$this->in_item=false;					break;				case "/image":					$this->in_image=false;					break;				case "/channel";					$this->in_channel=false;					break;				case "title/title":					if ($this->in_channel) {						if ($this->in_item) {							$l_i = $this->channel->items->num_items;							$this->channel->items->litems[$l_i]->title=$content;						} else {							if ($this->in_image) {								$this->channel->image->title=$content;							} else {								$this->channel->title=$content;							}						}					}					break;				case "link/link":					if ($this->in_channel) {						if ($this->in_item) {							$l_i = $this->channel->items->num_items;							$this->channel->items->litems[$l_i]->link=$content;						} else {							if ($this->in_image) {								$this->channel->image->link=$content;							} else {								$this->channel->link=$content;							}						}					}					break;				case "description/description":					if ($this->in_channel) {						if ($this->in_item) {							$l_i = $this->channel->items->num_items;							$this->channel->items->litems[$l_i]->description=$content;						} else {							$this->channel->description=$content;						}					}					break;				case "language/language":					if ($this->in_channel) {						if ($this->in_item) {												} else {							$this->channel->language=$content;						}					}					break;				case "copyright/copyright":					if ($this->in_channel) {						if ($this->in_item) {												} else {							$this->channel->copyright=$content;						}					}					break;				case "managingEditor/managingEditor":					if ($this->in_channel) {						if ($this->in_item) {												} else {							$this->channel->managingEditor=$content;						}					}					break;				case "webMaster/webMaster":					if ($this->in_channel) {						if ($this->in_item) {												} else {							$this->channel->webMaster=$content;						}					}					break;					case "guid isPermaLink=\"true\"/guid":					if ($this->in_channel) {						if ($this->in_item) {							$l_i = $this->channel->items->num_items;							$this->channel->items->litems[$l_i]->guid=$content;						} else {													}					}					break;					case "guid/guid":					if ($this->in_channel) {						if ($this->in_item) {							$l_i = $this->channel->items->num_items;							$this->channel->items->litems[$l_i]->guid=$content;						} else {													}					}					break;					case "category/category":					if ($this->in_channel) {						if ($this->in_item) {							$l_i = $this->channel->items->num_items;							$this->channel->items->litems[$l_i]->category=$content;						} else {												}					}					break;				case "url/url":					if ($this->in_channel) {						if ($this->in_item) {												} else {							if ($this->in_image) {								$this->channel->image->url=$content;							} else {															}						}					}					break;			}		}	}	function display() {		include("template.html.php");	}}//$oRss = new rss("http://www.securiteam.com/securiteam.rss");?>