Esempio n. 1
0
 $template = FeedForAll_rss2html_str_replace("~~~FeedTitle~~~", FeedForAll_rss2html_limitLength($rss_parser->FeedTitle, $limitFeedTitleLength), $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedDescription~~~", FeedForAll_rss2html_limitLength($rss_parser->FeedDescription, $limitFeedDescriptionLength), $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedContentEncoded~~~", $rss_parser->FeedContentEncoded, $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedLink~~~", FeedForAll_rss2html_EscapeLink($rss_parser->FeedLink), $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedPubDate~~~", $rss_parser->FeedPubDate, $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedPubLongDate~~~", date($LongDateFormat, $rss_parser->FeedPubDate_t), $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedPubShortDate~~~", date($ShortDateFormat, $rss_parser->FeedPubDate_t), $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedPubLongTime~~~", date($LongTimeFormat, $rss_parser->FeedPubDate_t), $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedPubShortTime~~~", date($ShortTimeFormat, $rss_parser->FeedPubDate_t), $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedImageUrl~~~", FeedForAll_rss2html_EscapeLink($rss_parser->FeedImageURL), $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedImageTitle~~~", $rss_parser->FeedImageTitle, $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedImageLink~~~", FeedForAll_rss2html_EscapeLink($rss_parser->FeedImageLink), $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedImageDescription~~~", $rss_parser->FeedImageDescription, $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedImageHeight~~~", $rss_parser->FeedImageWidth, $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedImageWidth~~~", $rss_parser->FeedImageWidth, $template);
 $template = FeedForAll_rss2html_str_replace("~~~FeedCreativeCommons~~~", FeedForAll_rss2html_EscapeLink($rss_parser->FeedCreativeCommons), $template);
 if (FeedForAll_parseExtensions() === TRUE) {
     $template = FeedForAll_parseExtensions_replaceInChannel($rss_parser, $template);
 }
 $match = NULL;
 $template = str_replace("~~~NoFutureItems~~~", "", $template);
 //
 // Sort by PubDate if requested
 if (strstr($template, "~~~SortByPubDate~~~")) {
     $template = str_replace("~~~SortByPubDate~~~", "", $template);
     for ($x = 0; $x < count($rss_parser->Items) - 1; $x++) {
         for ($y = $x + 1; $y < count($rss_parser->Items); $y++) {
             if ($rss_parser->Items[$x]->pubDate_t < $rss_parser->Items[$y]->pubDate_t) {
                 // Swap them
                 $swapTemp = $rss_parser->Items[$x];
                 $rss_parser->Items[$x] = $rss_parser->Items[$y];
 function endElement($parser, $tagName)
 {
     global $debugLevel;
     $this->tag = "";
     $this->level--;
     if ($this->insideItem && $tagName == "CATEGORY") {
         $this->currentItem->categoryArray[] = array("Category" => $this->currentItem->category, "Domain" => $this->currentItem->categoryDomain);
         $this->currentItem->category = "";
         $this->currentItem->categoryDomain = "";
     } elseif ($tagName == "ITEM" && $this->feedTYPE != "FEE" || $tagName == "ENTRY" && $this->feedTYPE == "FEE") {
         if (isset($debugLevel) && $debugLevel >= 2) {
             echo "DIAG: endElement(\$parser, {$tagName})<br>\n";
         }
         $this->UseItem = TRUE;
         //
         // Do any special processing to convert ATOM to RSS 2.0
         if ($this->feedTYPE == "FEE") {
             if ($this->currentItem->guid == "") {
                 // There was no GUID, use ID
                 $this->currentItem->guid = $this->currentItem->atomID;
                 $this->currentItem->guidIsPermaLink = "false";
             }
         }
         //
         // The the whole item string
         $pos = xml_get_current_byte_index($parser);
         //
         // Find the element that opened this all up.
         $endingString = '</' . substr($this->wholeString, $this->currentItem->ItemStartPos + 1, 4);
         if ($endingString == substr($this->wholeString, $pos, 6)) {
             // We are good just where we are
         } else {
             for (; $pos > 0; $pos--) {
                 /* Look for a closing angle */
                 if ($endingString == substr($this->wholeString, $pos, 6)) {
                     break;
                 }
             }
         }
         $pos++;
         $hereToEnd = substr($this->wholeString, $pos);
         $closePos = strpos($hereToEnd, '>');
         $this->currentItem->itemFullText = substr($this->wholeString, $this->currentItem->ItemStartPos, $pos + $closePos - $this->currentItem->ItemStartPos + 1);
         //
         // Get the pubDate from pubDate first and then dc:date
         if (trim($this->currentItem->pubDate) != "") {
             $this->currentItem->pubDate = trim($this->currentItem->pubDate);
             $this->currentItem->pubDate_t = strtotime($this->currentItem->pubDate);
         } elseif ($this->feedTYPE == "FEE" && trim($this->currentItem->atomUpdated) != "") {
             $this->currentItem->atomUpdated = trim($this->currentItem->atomUpdated);
             $this->currentItem->pubDate_t = FeedForAll_scripts_getRFDdate($this->currentItem->atomUpdated);
             $this->currentItem->pubDate = date("D, d M Y H:i:s O", $this->currentItem->pubDate_t);
         } elseif (trim($this->currentItem->pubDateDC) != "") {
             $this->currentItem->pubDate_t = FeedForAll_scripts_getRFDdate($this->currentItem->pubDateDC);
             $this->currentItem->pubDate = date("D, d M Y H:i:s O", $this->currentItem->pubDate_t);
         } else {
             $this->currentItem->pubDate_t = time();
             $this->currentItem->pubDate = date("D, d M Y H:i:s O", $this->currentItem->pubDate_t);
         }
         if ($this->operateAs == "rssFilter" && function_exists("rssFilter_useItem")) {
             global $_REQUEST;
             $this->UseItem = rssFilter_useItem($this->currentItem);
             if (isset($_REQUEST["testScript"])) {
                 if ($this->UseItem) {
                     echo "USING Item: " . htmlentities($this->currentItem->title) . "<br>\n";
                 } else {
                     echo "NOT Using: " . htmlentities($this->currentItem->title) . "<br>\n";
                 }
             }
         }
         if ($this->operateAs == "rssMesh") {
             if ($this->itemLimit >= 0 && count($this->Items) >= $this->itemLimit) {
                 $this->UseItem = FALSE;
             }
         } elseif ($this->operateAs == "rss2html") {
             if (($useUniq = FeedForAll_rss2html_UseUniqueLink($this->currentItem->title, $this->currentItem->description, $this->currentItem->link, $this->currentItem->guid)) != -1) {
                 if ($useUniq == 0) {
                     if (isset($debugLevel) && $debugLevel >= 2) {
                         echo "DIAG: FeedForAll_rss2html_UseUniqueLink() => 0, Not using<br>\n";
                     }
                     $this->UseItem = FALSE;
                 }
             }
             if ($this->noFutureItems) {
                 if ($this->currentItem->pubDate_t - $this->noon_t > 43200) {
                     if (isset($debugLevel) && $debugLevel >= 2) {
                         echo "DIAG: future pubdate, Not using<br>\n";
                     }
                     $this->UseItem = FALSE;
                 }
             }
         }
         if ($this->UseItem) {
             if (isset($debugLevel) && $debugLevel >= 2) {
                 echo "DIAG: Using item \"" . $this->currentItem->title . "\"<br>\n";
             }
             //
             // Clean up some of the values
             $this->currentItem->title = trim($this->currentItem->title);
             $this->currentItem->description = trim($this->currentItem->description);
             if ($this->feedTYPE == "FEE") {
                 $this->currentItem->atomContent = trim($this->currentItem->atomContent);
                 if ($this->currentItem->atomContent != "") {
                     $this->currentItem->description = $this->currentItem->atomContent;
                 } else {
                     $this->currentItem->description = trim($this->currentItem->description);
                 }
             } else {
                 $this->currentItem->description = $this->currentItem->description;
             }
             if (trim($this->currentItem->contentEncoded) == "") {
                 if ($this->operateAs != "rssMesh") {
                     $this->currentItem->contentEncoded = $this->currentItem->description;
                 }
             } else {
                 $this->currentItem->contentEncoded = trim($this->currentItem->contentEncoded);
             }
             if (trim($this->currentItem->description) == "") {
                 $this->currentItem->description = trim($this->currentItem->contentEncoded);
             }
             $this->currentItem->link = trim($this->currentItem->link);
             $this->currentItem->guid = trim($this->currentItem->guid);
             $this->currentItem->guidIsPermaLink = trim($this->currentItem->guidIsPermaLink);
             if ($this->feedTYPE == "FEE") {
                 $this->currentItem->atomAuthorEmail = trim($this->currentItem->atomAuthorEmail);
                 $this->currentItem->author = trim($this->currentItem->atomAuthorEmail);
             }
             $this->currentItem->author = trim($this->currentItem->author);
             if ($this->currentItem->creativeCommons == "") {
                 $this->currentItem->creativeCommons = trim($this->FeedCreativeCommons);
             } else {
                 $this->currentItem->creativeCommons = trim($this->currentItem->creativeCommons);
             }
             if ($this->operateAs == "rss2sql") {
                 if ($this->currentItem->source == "" && $this->sourceFeedURL != "") {
                     $this->currentItem->source = $this->FeedTitle;
                     $this->currentItem->sourceURL = $this->sourceFeedURL;
                 }
             }
             $this->currentItem->source = trim($this->currentItem->source);
             $this->currentItem->sourceURL = trim($this->currentItem->sourceURL);
             $this->currentItem->enclosureURL = trim($this->currentItem->enclosureURL);
             $this->currentItem->enclosureLength = trim($this->currentItem->enclosureLength);
             $this->currentItem->enclosureType = trim($this->currentItem->enclosureType);
             $this->currentItem->comments = trim($this->currentItem->comments);
             $this->currentItem->rssMeshExtra = trim($this->currentItem->rssMeshExtra);
             $this->currentItem->rssMeshExtra1 = trim($this->currentItem->rssMeshExtra1);
             $this->currentItem->rssMeshExtra2 = trim($this->currentItem->rssMeshExtra2);
             $this->currentItem->rssMeshExtra3 = trim($this->currentItem->rssMeshExtra3);
             $this->currentItem->rssMeshFeedImageTitle = trim($this->currentItem->rssMeshFeedImageTitle);
             $this->currentItem->rssMeshFeedImageUrl = trim($this->currentItem->rssMeshFeedImageUrl);
             $this->currentItem->rssMeshFeedImageLink = trim($this->currentItem->rssMeshFeedImageLink);
             $this->currentItem->rssMeshFeedImageDescription = trim($this->currentItem->rssMeshFeedImageDescription);
             $this->currentItem->rssMeshFeedImageHeight = trim($this->currentItem->rssMeshFeedImageHeight);
             $this->currentItem->rssMeshFeedImageWidth = trim($this->currentItem->rssMeshFeedImageWidth);
             if ($this->operateAs == "rss2html") {
                 //
                 // Escape any links
                 $this->currentItem->link = FeedForAll_rss2html_EscapeLink($this->currentItem->link);
                 $this->currentItem->guid = FeedForAll_rss2html_EscapeLink($this->currentItem->guid);
                 $this->currentItem->creativeCommons = FeedForAll_rss2html_EscapeLink($this->currentItem->creativeCommons);
                 $this->currentItem->sourceURL = FeedForAll_rss2html_EscapeLink($this->currentItem->sourceURL);
                 $this->currentItem->enclosureURL = FeedForAll_rss2html_EscapeLink($this->currentItem->enclosureURL);
                 $this->currentItem->comments = FeedForAll_rss2html_EscapeLink($this->currentItem->comments);
                 $this->currentItem->rssMeshFeedImageUrl = FeedForAll_rss2html_EscapeLink($this->currentItem->rssMeshFeedImageUrl);
                 $this->currentItem->rssMeshFeedImageLink = FeedForAll_rss2html_EscapeLink($this->currentItem->rssMeshFeedImageLink);
             }
             //
             if ($this->currentItem->contentEncodedUsed) {
                 $this->contentEncodedUsed = 1;
             }
             if (FeedForAll_parseExtensions() === TRUE) {
                 FeedForAll_parseExtensions_endElemend($parser, $this, $tagName);
             }
             if ($this->UseItem) {
                 $this->Items[] = $this->currentItem;
                 if (isset($debugLevel) && $debugLevel >= 3) {
                     echo "DIAG: adding to items, count=" . count($this->Items) . "<br>\n";
                 }
             }
         } else {
             unset($this->currentItem);
         }
         $this->insideItem = FALSE;
         $this->level_item = 0;
         return;
     } elseif ($this->insideAtomAuthor && $tagName == "AUTHOR") {
         $this->insideAtomAuthor = FALSE;
     } elseif ($tagName == "IMAGE" && $this->insideChannelImage) {
         $this->FeedImageTitle = trim($this->FeedImageTitle);
         $this->FeedImageURL = trim($this->FeedImageURL);
         $this->FeedImageLink = trim($this->FeedImageLink);
         $this->FeedImageDescription = trim($this->FeedImageDescription);
         $this->FeedImageHeight = trim($this->FeedImageHeight);
         $this->FeedImageWidth = trim($this->FeedImageWidth);
         if ($this->operateAs == "rss2html") {
             //
             // Escape any links
             $this->FeedImageURL = FeedForAll_rss2html_EscapeLink($this->FeedImageURL);
             $this->FeedImageLink = FeedForAll_rss2html_EscapeLink($this->FeedImageLink);
         }
         if (FeedForAll_parseExtensions() === TRUE) {
             FeedForAll_parseExtensions_endElemend($parser, $this, $tagName);
         }
         $this->insideChannelImage = FALSE;
         $this->level_channelImage = 0;
         return;
     } elseif ($tagName == "CHANNEL" && $this->feedTYPE != "FEE" || $tagName == "FEED" && $this->feedTYPE == "FEE") {
         $this->FeedPubDate = trim($this->FeedPubDate);
         $this->FeedPubDateDC = trim($this->FeedPubDateDC);
         $this->FeedAtomUpdated = trim($this->FeedAtomUpdated);
         //
         // Get the pubDate from pubDate first and then dc:date
         if (trim($this->FeedPubDate) != "") {
             $this->FeedPubDate_t = strtotime($this->FeedPubDate);
         } elseif ($this->feedTYPE == "FEE" && $this->FeedAtomUpdated != "") {
             $this->FeedAtomUpdated = trim($this->FeedAtomUpdated);
             $this->FeedPubDate_t = FeedForAll_scripts_getRFDdate($this->FeedAtomUpdated);
             $this->FeedPubDate = date("D, d M Y H:i:s O", $this->FeedPubDate_t);
         } elseif (trim($this->FeedPubDateDC) != "") {
             $this->FeedPubDate_t = FeedForAll_scripts_getRFDdate($this->FeedPubDateDC);
             $this->FeedPubDate = date("D, d M Y H:i:s O", $this->FeedPubDate_t);
         } elseif (trim($this->FeedLastBuildDate) != "") {
             $this->FeedPubDate_t = strtotime($this->FeedLastBuildDate);
             $this->FeedPubDate = date("D, d M Y H:i:s O", $this->FeedPubDate_t);
         } else {
             $this->FeedPubDate_t = time();
             $this->FeedPubDate = date("D, d M Y H:i:s O", $this->FeedPubDate_t);
         }
         $this->FeedTitle = trim($this->FeedTitle);
         if ($this->feedTYPE == "FEE") {
             $this->FeedAtomContent = trim($this->FeedAtomContent);
             $this->FeedDescription = $this->FeedAtomContent;
         } else {
             $this->FeedDescription = $this->FeedDescription;
         }
         if (trim($this->FeedContentEncoded) == "") {
             $this->FeedContentEncoded = $this->FeedDescription;
         }
         $this->FeedLink = trim($this->FeedLink);
         if ($this->operateAs == "rss2html") {
             //
             // Escape any links
             $this->FeedLink = FeedForAll_rss2html_EscapeLink($this->FeedLink);
             $this->FeedCreativeCommons = FeedForAll_rss2html_EscapeLink($this->FeedCreativeCommons);
         }
         if (FeedForAll_parseExtensions() === TRUE) {
             FeedForAll_parseExtensions_endElemend($parser, $this, $tagName);
         }
         $this->insideChannel = FALSE;
         $this->level_channel = 0;
         return;
     } elseif ($this->level == $this->level_channel) {
         if ($tagName == "TITLE") {
             $this->FeedTitle = trim($this->FeedTitle);
         } elseif ($tagName == "DESCRIPTION" || $tagName == "TAGLINE") {
             $this->FeedDescription = trim($this->FeedDescription);
         } elseif ($tagName == "CONTENT:ENCODED") {
             $this->FeedContentEncoded = trim($this->FeedContentEncoded);
         } elseif ($tagName == "LINK") {
             $this->FeedLink = trim($this->FeedLink);
         }
     } elseif ($tagName == "CONTENT") {
         if ($this->insideItem == TRUE) {
             // Lets look to see if the content is
             if ($this->currentItem->atomContentStartPos) {
                 //
                 // The the whole <content ... > string
                 $pos = xml_get_current_byte_index($parser);
                 for (; $pos > 0; $pos--) {
                     /* Look for a closing angle */
                     if ($this->wholeString[$pos] == ">") {
                         break;
                     }
                 }
                 $pos++;
                 $hereToEnd = substr($this->wholeString, $pos);
                 $closePos = strpos($hereToEnd, ">");
                 $fullContentText = substr($this->wholeString, $this->currentItem->atomContentStartPos, $pos + $closePos - $this->currentItem->atomContentStartPos + 1);
                 // Find the end of <content
                 $start = strpos($fullContentText, ">");
                 $fullContentText = substr($fullContentText, $start + 1);
                 // Find the end of <div
                 $start = strpos($fullContentText, ">");
                 $fullContentText = substr($fullContentText, $start + 1);
                 // Find the start of </content
                 $start = strrpos($fullContentText, "<");
                 $fullContentText = substr($fullContentText, 0, $start - 1);
                 // Find the start of </div
                 $start = strrpos($fullContentText, "<");
                 $this->currentItem->atomContent = substr($fullContentText, 0, $start - 1);
                 $this->currentItem->atomContentStartPos = 0;
             }
         } else {
             // Lets look to see if the content is
             if ($this->FeedAtomContentStartPos) {
                 //
                 // The the whole <content ... > string
                 $pos = xml_get_current_byte_index($parser);
                 for (; $pos > 0; $pos--) {
                     /* Look for a closing angle */
                     if ($this->wholeString[$pos] == ">") {
                         break;
                     }
                 }
                 $pos++;
                 $hereToEnd = substr($this->wholeString, $pos);
                 $closePos = strpos($hereToEnd, ">");
                 $fullContentText = substr($this->wholeString, $this->FeedAtomContentStartPos, $pos + $closePos - $this->FeedAtomContentStartPos + 1);
                 // Find the end of <content
                 $start = strpos($fullContentText, ">");
                 $fullContentText = substr($fullContentText, $start + 1);
                 // Find the end of <div
                 $start = strpos($fullContentText, ">");
                 $fullContentText = substr($fullContentText, $start + 1);
                 // Find the start of </content
                 $start = strrpos($fullContentText, "<");
                 $fullContentText = substr($fullContentText, 0, $start - 1);
                 // Find the start of </div
                 $start = strrpos($fullContentText, "<");
                 $this->FeedAtomContent = substr($fullContentText, 0, $start - 1);
                 $this->FeedAtomContentStartPos = 0;
             }
         }
     }
     if (FeedForAll_parseExtensions() === TRUE) {
         FeedForAll_parseExtensions_endElemend($parser, $this, $tagName);
     }
 }