Back on track, RSS Feed parser; RSS to HTML gateway

Still in it’s infancy, my RSS Feed Reader has grown from a buggy concept into a fully-realized utility. Previously modeled upon Keith Devens XML-RPC, it’s been rewritten with a customized version of Onyx RSS.

Rarely is it required to “throw the baby out with the bathwater”, but my former implementation has been rewritten from a 200k+ monolith to roughly 40k.

It will read, parse, cache, then spew out a brief synopsis of articles available. I will be expanding it as I usurp it into my Rollator CMS system; but feel free to test it out. I will reimplement “Titles Only”, as well as other various tweaks in the near future.

Update: Heck, I don’t really care about Onyx; it’s a bit bloated for my needs. I’ve got all I need right here:

function startElement($parser, $tagName, $attrs) { global $insideitem, $tag; if ($insideitem) { $tag = $tagName; } elseif (($tagName "ITEM") || ($tagName “IMAGE”)) { $insideitem = true; } } function endElement($parser, $tagName) { global $insideitem, $tag, $title, $description, $link, $iurl, $i, $n; if ($i >= $n) { return; } if ($tagName == “ITEM”) { printf(“� %s – %s
\n”, trim($link), htmlspecialchars(trim($title)), htmlspecialchars(trim($description))); $title = “”; $description = “”; $link = “”; $iurl = “”; $insideitem = false; $i += 1; } } function characterData($parser, $data) { global $insideitem, $tag, $title, $description, $link, $iurl; if ($insideitem) { switch ($tag) { case “TITLE”: $title .= $data; break; case “DESCRIPTION”: $description .= $data; break; case “LINK”: $link .= $data; break; case “URL”: $iurl .= $data; break; } } } function parse_feed ($url, $num) { global $insideitem, $tag, $title, $description, $link, $iurl, $i, $n; $insideitem = false; $tag = “”; $title = “”; $description = “”; $link = “”; $iurl = “”; $i = 0; $n = $num; // Create an XML parser $xml_parser = xml_parser_create(); // Set the functions to handle opening and closing tags xml_set_element_handler($xml_parser, “startElement”, “endElement”); // Set the function to handle blocks of character data xml_set_character_data_handler($xml_parser, “characterData”); // Open the XML file for reading $fp = fopen($url, “r”) or die(“Error reading RSS data.”); // Read the XML file 4KB at a time while ($data = fread($fp, 4096)) { // Parse each 4KB chunk with the XML parser created above xml_parse($xml_parser, $data, feof($fp)) // Handle errors in parsing 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))); } // Close the XML file fclose($fp); // Free up memory used by the XML parser xml_parser_free($xml_parser); $i = 0; }