topical media & game development
server-php-xml-class-rss-parser-class-rss-parser.php / php
<?php
// # # # # # # # # # # # # # # # # # # # ###
// Title : Class RSS_parser
// Version : 1.0
// Author : Luis Argerich (lrargerich@yahoo.com)
// Last modification date : 06-19-2002
// Description : A class to parse RSS 1.0 documents.
// Can parse documents from files or URIs.
// Based in a true RDF parser
// so it will respet any valid RDF syntax describing RSS
// files.
// # # # # # # # # # # # # # # # # # # # ###
// History:
// 07-17-2002 : BugFixes (Leandro Mariano Lopez)
// 06-19-2002 : First version of this class.
// # # # # # # # # # # # # # # # # # # # ###
// To-Dos:
//
// # # # # # # # # # # # # # # # # # # # ###
// How to use it:
// Read the documentation in rss_parser.html
// # # # # # # # # # # # # # # # # # # # ###
if(defined("_class_rss_parser_is_included")) {
// do nothing since the class is already included
} else {
define("_class_rss_parser_is_included",1);
include_once("class_rdf_parser.php");
class RSS_parser {
var item_handler_name;
var channel_subject='';
var unreported_item=false;
var item_properties=Array();
var channel_textinput=Array();
var this->channel_properties;
}
function get_channel_image_data() {
// Return channel_image
return this->channel_textinput;
}
function get_items_data() {
// Return item properties
return rss) {
rss;
base,"r");
if(!rdf=new Rdf_parser();
rdf->rdf_set_user_data( rdf->rdf_set_user_data(rdf->rdf_set_statement_handler( "my_statement_handler" );
rdf->rdf_set_base(done=false;
while(!buf = fread( done = feof(rdf->rdf_parse( buf), feof(rdf->rdf_get_xml_parser() ) ),
print( xml_get_current_line_number(input );
user_data,
subject,
ordinal,
object,
statements = predicate=="http://www.w3.org/1999/02/22-rdf-syntax-ns#type") && (subject_type != RDF_SUBJECT_TYPE_ANONYMOUS)) {
subject;
}
// If we found an RSS property of the channel then add it to the array of channel info
if ( user_data->channel_subject && strstr(props=explode("/",prop=array_pop(user_data->channel_properties[object;
}
// If we found a member of the Seq resource add it to the items array
if(isset(subject == subject_type == RDF_SUBJECT_TYPE_ANONYMOUS) {
ordinal]=user_data->item_properties[predicate=="http://www.w3.org/1999/02/22-rdf-syntax-ns#type") && (user_data->items_subject=subject,predicate,"http://purl.org/rss/1.0/")) {
predicate);
props);
subject][object;
}
// If we found the textinput element of the channel
if(isset(subject == predicate, "http://purl.org/rss/1.0/")) {
predicate);
props);
prop]=user_data->channel_properties["textinput"]) && user_data->channel_properties["textinput"] && strstr(props=explode("/",prop=array_pop(user_data->channel_textinput[object;
}
}
function my_warning_handler(warning );
}
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.