Rss Feed Plugin /Code Php Lib Rss
La classe RSSParser, basée sur celle écrite par Duncan Gough. Cette classe est la base constituant le Rss Feed Plugin. Voir RssFeedPlugin /CodePhp pour plus de détails.
Bien entendu, les améliorations sont les bienvenues !
<?php
/*
* Class RSSParser
* Based on Duncan Gough RSSParser class
* Copyleft Arnaud Fontaine
* Licence : GPL
*
*/
class RSSParser {
var $title = "";
var $link = "";
var $description = "";
var $inside_item = false;
var $items = array();
var $channel = array();
var $divers = "";
var $date = "";
function startElement( $parser, $name, $attrs='' ){
global $current_tag;
$current_tag = $name;
if( $current_tag == "ITEM" )
$this->inside_item = true;
} // startElement
function endElement( $parser, $tagName, $attrs='' ){
global $current_tag;
if ( $tagName == "ITEM" ) {
$this->items[] = array( "title" => $this->title,
"description" => $this->description,
"link" => $this->link );
$this->title = "";
$this->description = "";
$this->link = "";
$this->inside_item = false;
} elseif( $tagName == "CHANNEL") {
$this->channel = array( "title" => $this->title,
"description" => $this->description,
"link" => $this->link,
"date" => $this->date,
"divers" => $this->divers );
$this->title = "";
$this->description = "";
$this->link = "";
$this->divers = "";
$this->date = "";
}
} // endElement
function characterData( $parser, $data ){
global $current_tag;
if( $this->inside_item ){
switch($current_tag){
case "TITLE":
$this->title .= trim( $data );
break;
case "DESCRIPTION":
$this->description .= trim( $data );
break;
case "LINK":
$this->link .= trim( $data );
break;
default:
break;
}
} else {
switch($current_tag){
case "TITLE":
$this->title .= trim($data);
break;
case "DESCRIPTION":
$this->description .= trim($data);
break;
case "LINK":
$this->link .= trim($data);
break;
case "DC:DATE":
$this->date .= trim($data);
default:
$this->divers .= $current_tag."/".$data;
break;
}
}
} // characterData
function parse_results( $xml_parser, $rss_parser, $file ) {
xml_set_object( $xml_parser, &$rss_parser );
xml_set_element_handler( $xml_parser, "startElement", "endElement" );
xml_set_character_data_handler( $xml_parser, "characterData" );
$fp = fopen("$file","r") or die( "Error reading XML file, $file" );
while ($data = fread($fp, 4096)) {
// parse the data
xml_parse( $xml_parser, $data, feof($fp) ) or die( sprintf( "XML error: %s at line %d", xml_error_string( xml_get_error_code($xml_parser) ), xml_get_current_line_number( $xml_parser ) ) );
}
fclose($fp);
xml_parser_free( $xml_parser );
} // parse_results
}
?>
Dernière modification le jeudi 2 octobre 2003 17:33:32



