From 8766b89f9399ef680251e7f2893db253a0694e9f Mon Sep 17 00:00:00 2001 From: dhawes Date: Thu, 30 Dec 2004 18:27:40 +0000 Subject: [PATCH] a little cleanup --- rss/class.Atom.php | 417 +++++++++++++++++++++++---------------------- rss/class.RSS.php | 57 ++++--- 2 files changed, 238 insertions(+), 236 deletions(-) diff --git a/rss/class.Atom.php b/rss/class.Atom.php index fa7f483f1e..8e9f256f8a 100644 --- a/rss/class.Atom.php +++ b/rss/class.Atom.php @@ -1,11 +1,12 @@ - - * Version: 0.1 - * License: GPL + * Version: 0.1 + * License: GPL * * The lastest version of phAnTOM can be obtained from: * http://www.simplog.org @@ -19,7 +20,7 @@ */ -/* +/** * The lastest Atom feed spec is at http://diveintomark.org/public/2003/08/atom02spec.txt * * @@ -29,158 +30,158 @@ */ class Atom { - /* - * Useage Example: - * - * $xml = "feed['title']; - * - * // print the title of each entry - * foreach ($atom->entries as $entry ) { - * print $entry[title]; - * } - * - */ - - var $parser; - - var $current_item = array(); // item currently being parsed - var $entries = array(); // collection of parsed items - var $feed = array(); // hash of channel fields - - var $parent_field = array('RDF'); - var $author = array(); - var $contributor = array(); - var $current_field = ''; - var $current_namespace = false; - - var $ERROR = ''; - + /* + * Useage Example: + * + * $xml = "feed['title']; + * + * // print the title of each entry + * foreach ($atom->entries as $entry ) { + * print $entry[title]; + * } + * + */ + + var $parser; + + var $current_item = array(); // item currently being parsed + var $entries = array(); // collection of parsed items + var $feed = array(); // hash of channel fields + + var $parent_field = array('RDF'); + var $author = array(); + var $contributor = array(); + var $current_field = ''; + var $current_namespace = false; + + var $ERROR = ''; + /*======================================================================*\ Function: MagpieRSS Purpose: Constructor, sets up XML parser,parses source, - and populates object.. - Input: String containing the RSS to be parsed + and populates object.. + Input: String containing the RSS to be parsed \*======================================================================*/ - function Atom ($source) { - - # if PHP xml isn't compiled in, die - # - if (!function_exists('xml_parser_create')) { - $this->error( 'Failed to load PHP\'s XML Extension. ' . - 'http://www.php.net/manual/en/ref.xml.php', - E_USER_ERROR ); - } - - $parser = @xml_parser_create(); - - if (!is_resource($parser)) - { - $this->error( 'Failed to create an instance of PHP\'s XML parser. ' . - 'http://www.php.net/manual/en/ref.xml.php', - E_USER_ERROR ); - } + function Atom ($source) { + + # if PHP xml isn't compiled in, die + # + if (!function_exists('xml_parser_create')) { + $this->error( 'Failed to load PHP\'s XML Extension. ' . + 'http://www.php.net/manual/en/ref.xml.php', + E_USER_ERROR ); + } + + $parser = @xml_parser_create(); + + if (!is_resource($parser)) + { + $this->error( 'Failed to create an instance of PHP\'s XML parser. ' . + 'http://www.php.net/manual/en/ref.xml.php', + E_USER_ERROR ); + } - - $this->parser = $parser; - - # pass in parser, and a reference to this object - # setup handlers - # - xml_set_object( $this->parser, $this ); - xml_set_element_handler($this->parser, 'start_element', 'end_element'); - xml_set_character_data_handler( $this->parser, 'cdata' ); - - - $status = xml_parse( $this->parser, $source ); - - if (! $status ) { - $errorcode = xml_get_error_code( $this->parser ); - if ( $errorcode != XML_ERROR_NONE ) { - $xml_error = xml_error_string( $errorcode ); - $error_line = xml_get_current_line_number($this->parser); - $error_col = xml_get_current_column_number($this->parser); - $errormsg = $xml_error .' at line '. $error_line .', column '. $error_col; + + $this->parser = $parser; + + # pass in parser, and a reference to this object + # setup handlers + # + xml_set_object( $this->parser, $this ); + xml_set_element_handler($this->parser, 'start_element', 'end_element'); + xml_set_character_data_handler( $this->parser, 'cdata' ); + + + $status = xml_parse( $this->parser, $source ); + + if (! $status ) { + $errorcode = xml_get_error_code( $this->parser ); + if ( $errorcode != XML_ERROR_NONE ) { + $xml_error = xml_error_string( $errorcode ); + $error_line = xml_get_current_line_number($this->parser); + $error_col = xml_get_current_column_number($this->parser); + $errormsg = $xml_error .' at line '. $error_line .', column '. $error_col; - $this->error( $errormsg ); - } - } - - xml_parser_free( $this->parser ); - } - - function start_element ($p, $element, &$attrs) { - $element = strtolower( $element ); - # check for a namespace, and split if found - # - $namespace = false; - if ( strpos( $element, ':' ) ) { - list($namespace, $element) = split( ':', $element, 2); - } - $this->current_field = $element; - if ( $namespace ) { - $this->current_namespace = $namespace; - } - - if ( $element == 'feed' ) { - array_unshift( $this->parent_field, 'feed' ); - } else if ( $element == 'items' ) { - array_unshift( $this->parent_field, 'items' ); - } else if ( $element == 'entry' ) { - array_unshift( $this->parent_field, 'entry' ); - } else if ( $element == 'author' ) { + $this->error( $errormsg ); + } + } + + xml_parser_free( $this->parser ); + } + + function start_element ($p, $element, &$attrs) { + $element = strtolower( $element ); + # check for a namespace, and split if found + # + $namespace = false; + if ( strpos( $element, ':' ) ) { + list($namespace, $element) = split( ':', $element, 2); + } + $this->current_field = $element; + if ( $namespace ) { + $this->current_namespace = $namespace; + } + + if ( $element == 'feed' ) { + array_unshift( $this->parent_field, 'feed' ); + } else if ( $element == 'items' ) { + array_unshift( $this->parent_field, 'items' ); + } else if ( $element == 'entry' ) { + array_unshift( $this->parent_field, 'entry' ); + } else if ( $element == 'author' ) { array_unshift( $this->parent_field, 'author' ); - } else if ( $element == 'contributor' ) { + } else if ( $element == 'contributor' ) { array_unshift( $this->parent_field, 'contributor' ); } - } - - function end_element ($p, $element) { - $element = strtolower($element); - - if ( $element == 'entry' ) { - $this->entries[] = $this->current_item; - $this->current_item = array(); - array_shift( $this->parent_field ); - } else if ( $element == 'feed' or $element == 'items' or - $element == 'author' or $element == 'contributor') { - array_shift( $this->parent_field ); - } - - $this->current_field = ''; - $this->current_namespace = false; - } - - function cdata ($p, $text) { - # skip item, channel, items first time we see them - # - if ( $this->parent_field[0] == $this->current_field or - ! $this->current_field ) { - return; - } else if ( $this->parent_field[0] == 'feed') { - if ( $this->current_namespace ) { - $this->append( - $this->feed[ $this->current_namespace ][ $this->current_field ], - $text); - } else { - $this->append($this->feed[ $this->current_field ], $text); - } - - } else if ( $this->parent_field[0] == 'entry' ) { - if ( $this->current_namespace ) { - $this->append( - $this->current_item[ $this->current_namespace ][$this->current_field ], - $text); - } else { - $this->append( - $this->current_item[ $this->current_field ], - $text ); - } - } else if ( $this->parent_field[0] == 'author' ) { + } + + function end_element ($p, $element) { + $element = strtolower($element); + + if ( $element == 'entry' ) { + $this->entries[] = $this->current_item; + $this->current_item = array(); + array_shift( $this->parent_field ); + } else if ( $element == 'feed' or $element == 'items' or + $element == 'author' or $element == 'contributor') { + array_shift( $this->parent_field ); + } + + $this->current_field = ''; + $this->current_namespace = false; + } + + function cdata ($p, $text) { + # skip item, channel, items first time we see them + # + if ( $this->parent_field[0] == $this->current_field or + ! $this->current_field ) { + return; + } else if ( $this->parent_field[0] == 'feed') { + if ( $this->current_namespace ) { + $this->append( + $this->feed[ $this->current_namespace ][ $this->current_field ], + $text); + } else { + $this->append($this->feed[ $this->current_field ], $text); + } + + } else if ( $this->parent_field[0] == 'entry' ) { + if ( $this->current_namespace ) { + $this->append( + $this->current_item[ $this->current_namespace ][$this->current_field ], + $text); + } else { + $this->append( + $this->current_item[ $this->current_field ], + $text ); + } + } else if ( $this->parent_field[0] == 'author' ) { if ( $this->current_namespace ) { $this->append( $this->author[ $this->current_namespace ][ $this->current_field ], @@ -201,70 +202,70 @@ class Atom { $text ); } } - } - - function append (&$str1, $str2='') { - if (!isset($str1) ) { - $str1=''; - } - $str1 .= $str2; - } - - function error ($errormsg, $lvl=E_USER_WARNING) { - // append PHP's error message if track_errors enabled - if ( $php_errormsg ) { - $errormsg .= ' ('. $php_errormsg .')'; - } - $this->ERROR = $errormsg; - if ( ATOM_DEBUG ) { - trigger_error( $errormsg, $lvl); - } else { - error_log( $errormsg, 0); - } - } - + } + + function append (&$str1, $str2='') { + if (!isset($str1) ) { + $str1=''; + } + $str1 .= $str2; + } + + function error ($errormsg, $lvl=E_USER_WARNING) { + // append PHP's error message if track_errors enabled + if ( $php_errormsg ) { + $errormsg .= ' ('. $php_errormsg .')'; + } + $this->ERROR = $errormsg; + if ( ATOM_DEBUG ) { + trigger_error( $errormsg, $lvl); + } else { + error_log( $errormsg, 0); + } + } + /*======================================================================*\ - EVERYTHING BELOW HERE IS FOR DEBUGGING PURPOSES + EVERYTHING BELOW HERE IS FOR DEBUGGING PURPOSES \*======================================================================*/ - function show_list () { - print '
    '."\n"; - foreach ($this->entries as $item) { - print '
  1. '. $this->show_entry( $item ); - } - print '
'; - } - - function show_feed () { - print 'feed:
'; - print ''; - } - - function show_entry ($item) { - print 'entry: '. $item[title]; - print ''; - } + function show_list () { + print '
    '."\n"; + foreach ($this->entries as $item) { + print '
  1. '. $this->show_entry( $item ); + } + print '
'; + } + + function show_feed () { + print 'feed:
'; + print ''; + } + + function show_entry ($item) { + print 'entry: '. $item[title]; + print ''; + } /*======================================================================*\ - END DEBUGGING FUNCTIONS + END DEBUGGING FUNCTIONS \*======================================================================*/ - + } # end class Atom ?> \ No newline at end of file diff --git a/rss/class.RSS.php b/rss/class.RSS.php index e5319f60c9..89ba32e59c 100644 --- a/rss/class.RSS.php +++ b/rss/class.RSS.php @@ -1,11 +1,12 @@ - - * Version: 0.51 - * License: GPL + * Version: 0.51 + * License: GPL * * The lastest version of MagpieRSS can be obtained from: * http://magpierss.sourceforge.net @@ -17,7 +18,7 @@ */ -/* +/** * NOTES ON RSS PARSING PHILOSOPHY (moderately important): * MagpieRSS parse all versions of RSS with a few limitation (mod_content, and * mod_taxonomy support is shaky) into a simple object, with 2 fields, @@ -57,19 +58,19 @@ * onto the array $rss-items * * array( - * title => 'Weekly Peace Vigil', - * link => - * 'http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257', - * description => 'Wear a white ribbon', - * dc => array ( - * subject => 'Peace' - * ), - * ev => array ( - * startdate => '2002-06-01T11:00:00', - * enddate => '2002-06-01T12:00:00', - * type => 'Protest', - * location => 'Northampton, MA' - * ) + * title => 'Weekly Peace Vigil', + * link => + * 'http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257', + * description => 'Wear a white ribbon', + * dc => array ( + * subject => 'Peace' + * ), + * ev => array ( + * startdate => '2002-06-01T11:00:00', + * enddate => '2002-06-01T12:00:00', + * type => 'Protest', + * location => 'Northampton, MA' + * ) * ) * */ @@ -97,15 +98,15 @@ class MagpieRSS { var $parser; - var $current_item = array(); // item currently being parsed - var $items = array(); // collection of parsed items - var $channel = array(); // hash of channel fields - var $textinput = array(); - var $image = array(); + var $current_item = array(); // item currently being parsed + var $items = array(); // collection of parsed items + var $channel = array(); // hash of channel fields + var $textinput = array(); + var $image = array(); - var $parent_field = array('RDF'); - var $current_field = ''; - var $current_namespace = false; + var $parent_field = array('RDF'); + var $current_field = ''; + var $current_namespace = false; var $ERROR = ""; @@ -163,7 +164,7 @@ class MagpieRSS { } function start_element ($p, $element, &$attrs) { - $element = strtolower( $element ); + $element = strtolower( $element ); # check for a namespace, and split if found # $namespace = false; -- 2.39.5