level++; $this->tag = $tagName; if ($this->gotROOT == 0) { $this->gotROOT = 1; if (strstr($tagName, "RSS")) { $this->feedTYPE = "RSS"; } elseif (strstr($tagName, "RDF")) { $this->feedTYPE = "RDF"; } elseif (strstr($tagName, "FEE")) { $this->feedTYPE = "FEE"; $insidechannel = TRUE; $level_channel = 1; } } elseif ((($tagName == "ITEM") && ($this->feedTYPE != "FEE")) || (($tagName == "ENTRY") && ($this->feedTYPE == "FEE"))) { $insideitem = TRUE; $level_item = $this->level; } elseif (($insideitem) && ($tagName == "ENCLOSURE")) { $this->enclosureURL = $attrs["URL"]; } elseif (($tagName == "LINK") && ($this->feedTYPE == "FEE")) { $this->link = $attrs["HREF"]; } elseif ($tagName == "CHANNEL") { $insidechannel = TRUE; $level_channel = $this->level; } elseif (($tagName == "IMAGE") && ($insidechannel = TRUE)) { $insidechannelimage = TRUE; $level_channelimage = $this->level; } } function endElement($parser, $tagName) { GLOBAL $insidechannel; GLOBAL $level_channel; GLOBAL $insidechannelimage; GLOBAL $level_channelimage; GLOBAL $insideitem; GLOBAL $level_item; $this->level--; if ((($tagName == "ITEM") && ($this->feedTYPE != "FEE")) || (($tagName == "ENTRY") && ($this->feedTYPE == "FEE"))) { $this->ItemTitle[] = trim($this->title); $this->ItemDescription[] = trim($this->description); $this->ItemLink[] = trim($this->link); $this->ItemPubDate[] = trim($this->pubdate); if ($this->feedTYPE == "RSS") { $this->ItemPubDate_t[] = strtotime($this->pubdate); } else { $this->ItemPubDate_t[] = getRFDdate($this->pubdate); } $this->ItemGuid[] = trim($this->guid); $this->ItemEnclosureURL[] = trim($this->enclosureURL); $this->title = ""; $this->description = ""; $this->link = ""; $this->pubdate = ""; $this->guid = ""; $this->enclosureURL = ""; $insideitem = FALSE; $level_item = 0; } elseif (($tagName == "IMAGE") && ($insidechannelimage)) { $this->FeedImageURL = trim($this->fimageURL); $this->FeedImageTitle = trim($this->fimageTitle); $this->FeedImageLink = trim($this->fimageLink); $this->fimageURL = ""; $this->fimageTitle = ""; $this->fimageLink = ""; $insidechannelimage = FALSE; $level_channelimage = 0; } elseif ($tagName == "CHANNEL") { if ($this->feedTYPE == "RSS") { $this->FeedPubDate_t = strtotime($this->FeedPubDate); } else { $this->FeedPubDate_t = getRFDdate($this->FeedPubDate); } $insidechannel = FALSE; $level_channel = 0; } elseif ($this->level == $level_channel) { if ($tagName == "TITLE") { $this->FeedTitle = trim($this->title); $this->title = ""; } elseif (($tagName == "DESCRIPTION") || ($tagName == "TAGLINE")) { $this->FeedDescription = trim($this->description); $this->description = ""; } elseif ($tagName == "LINK") { $this->FeedLink = trim($this->link); $this->link = ""; } } } function characterData($parser, $data) { GLOBAL $insidechannel; GLOBAL $level_channel; GLOBAL $insidechannelimage; GLOBAL $level_channelimage; GLOBAL $insideitem; GLOBAL $level_item; if (($data == "") || ($data == NULL)) { } else { if (($insideitem) && ($this->level == $level_item+1)) { switch ($this->tag) { case "TITLE": $this->title .= $data; break; case "DESCRIPTION": $this->description .= $data; break; case "SUMMARY": $this->description .= $data; break; case "LINK": $this->link .= $data; break; case "PUBDATE": $this->pubdate .= $data; break; case "DC:DATE": $this->pubdate .= $data; break; case "MODIFIED": $this->pubdate .= $data; break; case "GUID": $this->guid .= $data; break; } } elseif ($insidechannelimage) { switch ($this->tag) { case "TITLE": $this->fimageTitle .= $data; break; case "URL": $this->fimageURL .= $data; break; case "LINK": $this->fimageLink .= $data; break; } } elseif (($insidechannel) && ($this->level == $level_channel+1)) { switch ($this->tag) { case "TITLE": $this->title .= $data; break; case "DESCRIPTION": $this->description .= $data; break; case "TAGLINE": $this->description .= $data; break; case "LINK": $this->link .= $data; break; case "PUBDATE": $this->FeedPubDate .= $data; break; case "DC:DATE": $this->FeedPubDate .= $data; break; case "MODIFIED": $this->FeedPubDate .= $data; break; } } } } } $fd = fopen($TEMPLATEfilename, "rb"); $template = NULL; while (($data = fread($fd, 4096)) != "") { $template .= $data; } fclose($fd); $xml_parser = xml_parser_create(''); $rss_parser = new RSSParser(); xml_set_object($xml_parser, $rss_parser); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1); $fd = fopen($XMLfilename, "rb"); // Read the whole file 4k at a time so remote files can be read while (($XML = fread($fd, 4096)) != "") { xml_parse($xml_parser,$XML); } fclose($fd); xml_parser_free($xml_parser); $template = str_replace("~~~FeedTitle~~~", $rss_parser->FeedTitle, $template); $template = str_replace("~~~FeedDescription~~~", $rss_parser->FeedDescription, $template); $template = str_replace("~~~FeedLink~~~", $rss_parser->FeedLink, $template); $template = str_replace("~~~FeedPubDate~~~", $rss_parser->FeedPubDate, $template); $template = str_replace("~~~FeedPubLongDate~~~", date($LongDateFormat, $rss_parser->FeedPubDate_t), $template); $template = str_replace("~~~FeedPubShortDate~~~", date($ShortDateFormat, $rss_parser->FeedPubDate_t), $template); $template = str_replace("~~~FeedPubLongTime~~~", date($LongTimeFormat, $rss_parser->FeedPubDate_t), $template); $template = str_replace("~~~FeedPubShortTime~~~", date($ShortTimeFormat, $rss_parser->FeedPubDate_t), $template); $template = str_replace("~~~FeedImageUrl~~~", $rss_parser->FeedImageURL, $template); $template = str_replace("~~~FeedImageTitle~~~", $rss_parser->FeedImageTitle, $template); $template = str_replace("~~~FeedImageLink~~~", $rss_parser->FeedImageLink, $template); if (strstr($template, "~~~FeedMaxItems=")) { // Limit the maximum number of items displayed if (preg_match("/~~~FeedMaxItems=([0-9]*)~~~/", $template, $match) !== FALSE) { if ($match[0] == "") break; if ($match[1] == "") break; $FeedMaxItems = $match[1]; $template = str_replace("~~~FeedMaxItems=$match[1]~~~", "", $template); } } // // Find the string, if it exists, between the ~~~EndItemsRecord~~~ and ~~~BeginItemsRecord~~~ // while ((strstr($template, "~~~BeginItemsRecord~~~")) !== FALSE) { $match = NULL; $allitems = NULL; $loop_limit = min($FeedMaxItems, count($rss_parser->ItemTitle)); if (($parts = split("~~~BeginItemsRecord~~~", $template)) !== FALSE) { if (($parts = split("~~~EndItemsRecord~~~", $parts[1])) !== FALSE) { $WholeBlock = $parts[0]; // // Check for ~~~BeginAlternateItemsRecord~~~ // if (strstr($WholeBlock, "~~~BeginAlternateItemsRecord~~~")) { $parts = split("~~~BeginAlternateItemsRecord~~~", $WholeBlock); $block1 = $parts[0]; $block2 = $parts[1]; } else { $block1 = $WholeBlock; $block2 = $WholeBlock; } for ($x = 0; $x < $loop_limit; $x++) { $item = str_replace("~~~ItemTitle~~~", $rss_parser->ItemTitle[$x], $block1); $item = str_replace("~~~ItemDescription~~~", $rss_parser->ItemDescription[$x], $item); $item = str_replace("~~~ItemLink~~~", $rss_parser->ItemLink[$x], $item); $item = str_replace("~~~ItemPubDate~~~", $rss_parser->ItemPubDate[$x], $item); $item = str_replace("~~~ItemGuid~~~", urlencode($rss_parser->ItemGuid[$x]), $item); $item = str_replace("~~~ItemPubLongDate~~~", date($LongDateFormat, $rss_parser->ItemPubDate_t[$x]), $item); $item = str_replace("~~~ItemPubShortDate~~~", date($ShortDateFormat, $rss_parser->ItemPubDate_t[$x]), $item); $item = str_replace("~~~ItemPubLongTime~~~", date($LongTimeFormat, $rss_parser->ItemPubDate_t[$x]), $item); $item = str_replace("~~~ItemPubShortTime~~~", date($ShortTimeFormat, $rss_parser->ItemPubDate_t[$x]), $item); $item = str_replace("~~~ItemEnclosureUrl~~~", $rss_parser->ItemEnclosureURL[$x], $item); $allitems .= $item; $x++; if ($x < $loop_limit) { // // This is at least one more item so use the Alternate definition // $item = str_replace("~~~ItemTitle~~~", $rss_parser->ItemTitle[$x], $block2); $item = str_replace("~~~ItemDescription~~~", $rss_parser->ItemDescription[$x], $item); $item = str_replace("~~~ItemLink~~~", $rss_parser->ItemLink[$x], $item); $item = str_replace("~~~ItemPubDate~~~", $rss_parser->ItemPubDate[$x], $item); $item = str_replace("~~~ItemGuid~~~", urlencode($rss_parser->ItemGuid[$x]), $item); $item = str_replace("~~~ItemPubLongDate~~~", date($LongDateFormat, $rss_parser->ItemPubDate_t[$x]), $item); $item = str_replace("~~~ItemPubShortDate~~~", date($ShortDateFormat, $rss_parser->ItemPubDate_t[$x]), $item); $item = str_replace("~~~ItemPubLongTime~~~", date($LongTimeFormat, $rss_parser->ItemPubDate_t[$x]), $item); $item = str_replace("~~~ItemPubShortTime~~~", date($ShortTimeFormat, $rss_parser->ItemPubDate_t[$x]), $item); $item = str_replace("~~~ItemEnclosureUrl~~~", $rss_parser->ItemEnclosureURL[$x], $item); $allitems .= $item; } } $allitems = str_replace("