📄 rss2html.php
字号:
// Check variables that could be used if URL wrapper are disable or not working if (isset($GLOBALS["XMLFILE"])) { $XMLfilename = $GLOBALS["XMLFILE"]; } if (isset($GLOBALS["TEMPLATE"])) { $TEMPLATEfilename = $GLOBALS["TEMPLATE"]; } if (isset($GLOBALS["FeedTitleLength"])) { $limitFeedTitleLength = abs($GLOBALS["FeedTitleLength"]); } if (isset($GLOBALS["FeedDescriptionLength"])) { $limitFeedDescriptionLength = abs($GLOBALS["FeedDescriptionLength"]); } if (isset($GLOBALS["ItemTitleLength"])) { $limitItemTitleLength = abs($GLOBALS["ItemTitleLength"]); } if (isset($GLOBALS["ItemDescriptionLength"])) { $limitItemDescriptionLength = abs($GLOBALS["ItemDescriptionLength"]); } if (isset($GLOBALS["MAXITEMS"])) { $FeedMaxItems = $GLOBALS["MAXITEMS"]; } if (isset($GLOBALS["NOFUTUREITEMS"])) { $NoFutureItems = TRUE; } if (isset($_REQUEST["XMLFILE"])) { if (stristr($_REQUEST["XMLFILE"], "file"."://")) { // Not allowed ; } elseif (stristr($_REQUEST["XMLFILE"], "://")) { if ($fileAccessLevel == -1) { echo "Configuration setting prohibit using remote files, exiting\n"; return; } else { // URL files are allowed $XMLfilename = $_REQUEST["XMLFILE"]; } } else { if (($fileAccessLevel == 1) || ($fileAccessLevel == -1)) { if (FeedForAll_rss2html_validExtension(basename($_REQUEST["XMLFILE"]), $allowedFeedExtensions) === FALSE) { echo "Configuration setting prohibit using the specified feed file, exiting\n"; return; } $XMLfilename = basename($_REQUEST["XMLFILE"]); } elseif ($fileAccessLevel == 2) { echo "Configuration setting prohibit using local files, exiting\n"; return; } else { // It is local and must be in the same directory $XMLfilename = basename($_REQUEST["XMLFILE"]); } } } if (isset($_REQUEST["TEMPLATE"])) { if (stristr($_REQUEST["TEMPLATE"], "file"."://")) { // Not allowed ; } elseif (stristr($_REQUEST["TEMPLATE"], "://")) { if ($fileAccessLevel == -1) { echo "Configuration setting prohibit using remote files, exiting\n"; return; } else { // URL files are allowed $TEMPLATEfilename = $_REQUEST["TEMPLATE"]; } } else { if (($fileAccessLevel == 1) || ($fileAccessLevel == -1)) { if (FeedForAll_rss2html_validExtension(basename($_REQUEST["TEMPLATE"]), $allowedTemplateExtensions) === FALSE) { echo "Configuration setting prohibit using the specified template file, exiting\n"; return; } $TEMPLATEfilename = basename($_REQUEST["TEMPLATE"]); } elseif ($fileAccessLevel == 2) { echo "Configuration setting prohibit using local files, exiting\n"; return; } else { // It is local and must be in the same directory $TEMPLATEfilename = basename($_REQUEST["TEMPLATE"]); } } } if (isset($_REQUEST["FeedTitleLength"])) { $limitFeedTitleLength = abs($_REQUEST["FeedTitleLength"]); } if (isset($_REQUEST["FeedDescriptionLength"])) { $limitFeedDescriptionLength = abs($_REQUEST["FeedDescriptionLength"]); } if (isset($_REQUEST["ItemTitleLength"])) { $limitItemTitleLength = abs($_REQUEST["ItemTitleLength"]); } if (isset($_REQUEST["ItemDescriptionLength"])) { $limitItemDescriptionLength = abs($_REQUEST["ItemDescriptionLength"]); } // // Maximum number of items to be displayed // if (isset($_REQUEST["MAXITEMS"])) { $FeedMaxItems = $_REQUEST["MAXITEMS"]; } if (isset($_REQUEST["NOFUTUREITEMS"])) { $NoFutureItems = TRUE; } if (isset($outputCacheTTL) && function_exists("FeedForAll_scripts_readOutputCacheFile") && (($cacheContents = FeedForAll_scripts_readOutputCacheFile($XMLfilename, $TEMPLATEfilename)) !== FALSE)) { if (!headers_sent()) { // Send the Content-Type to force $destinationEncoding header("Content-Type: text/html; charset=$destinationEncoding"); } echo $cacheContents; } else { if (($template = FeedForAll_scripts_readFile($TEMPLATEfilename, $useFopenURL)) === FALSE) { if (!isset($hideErrors)) { if ($ReadErrorString == "") { echo "Unable to open template $TEMPLATEfilename, exiting\n"; } else { echo "Unable to open template $TEMPLATEfilename with error <b>$ReadErrorString</b>, exiting\n"; } } return; } if (FeedForAll_rss2html_isTemplate($template) === FALSE) { if (!isset($hideErrors)) { echo "$TEMPLATEfilename is not a valid rss2html.php template file, exiting\n"; } return; } if (strstr($template, "~~~NoFutureItems~~~")) { $NoFutureItems = TRUE; } if (($XML = FeedForAll_scripts_readFile($XMLfilename, $useFopenURL, $allowCachingXMLFiles)) === FALSE) { if (!isset($hideErrors)) { if ($ReadErrorString == "") { echo "Unable to open RSS Feed $XMLfilename, exiting\n"; } else { echo "Unable to open RSS Feed $XMLfilename with error <b>$ReadErrorString</b>, exiting\n"; } } return; } if (strstr(trim($XML), "<?xml") === FALSE) { $XML = "<?xml version=\"1.0\"?>\n$XML"; } $XML = strstr(trim($XML), "<?xml"); $XML = FeedForAll_preProcessXML($XML); if (($convertedXML = FeedForAll_scripts_convertEncoding($XML, $missingEncodingDefault, $destinationEncoding)) === FALSE) { // Conversions failed, probably becasue it was wrong or the routines were missing $convertedXML = $XML; $xml_parser = xml_parser_create(); } else { $xml_parser = xml_parser_create($destinationEncoding); } $rss_parser = new baseParserClass("rss2html"); $rss_parser->noFutureItems = $NoFutureItems; $rss_parser->wholeString = $convertedXML; 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); $parseResult = xml_parse($xml_parser, $convertedXML, TRUE); if ($parseResult == 0) { if (!isset($hideErrors)) { $errorCode = xml_get_error_code($xml_parser); echo "\$errorCode = $errorCode<br>\n"; echo "xml_error_string() = ".xml_error_string($errorCode)."<br>\n"; echo "xml_get_current_line_number() = ".xml_get_current_line_number($xml_parser)."<br>\n"; echo "xml_get_current_column_number() = ".xml_get_current_column_number($xml_parser)."<br>\n"; echo "xml_get_current_byte_index() = ".xml_get_current_byte_index($xml_parser)."<br>\n"; } } else { xml_parser_free($xml_parser); // make sure the channel contentEncoded is not blank if ($rss_parser->FeedContentEncoded == "") { $rss_parser->FeedContentEncoded = $rss_parser->FeedDescription; } $template = FeedForAll_rss2html_str_replace("~~~FeedXMLFilename~~~", FeedForAll_rss2html_EscapeLink($XMLfilename), $template); $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]; $rss_parser->Items[$y] = $swapTemp; } } } } if (isset($debugLevel) && ($debugLevel >= 3)) { echo "DIAG: adding to items, count=".count($rss_parser->Items)."<br>\n"; } // The the maximum items requested if (strstr($template, "~~~FeedMaxItems=")) { // Limit the maximun number of items displayed if (preg_match("/~~~FeedMaxItems=([0-9-]*)~~~/", $template, $match) !== FALSE) { if (($match[0] != "") && ($match[1] != "")) { $FeedMaxItems = $match[1]; $template = str_replace("~~~FeedMaxItems=$match[1]~~~", "", $template); if (abs($FeedMaxItems) > count($rss_parser->Items)) { if ($FeedMaxItems > 0) { $FeedMaxItems = count($rss_parser->Items); } else { $FeedMaxItems = -count($rss_parser->Items); } } } } } if (!function_exists("FeedForALL_rss2html_replaceInItem")) { Function FeedForALL_rss2html_replaceInItem($source, $currentItem) { GLOBAL $limitFeedTitleLength; GLOBAL $limitFeedDescriptionLength; GLOBAL $limitItemTitleLength; GLOBAL $limitItemDescriptionLength; GLOBAL $LongDateFormat; GLOBAL $ShortDateFormat; GLOBAL $LongTimeFormat; GLOBAL $ShortTimeFormat; GLOBAL $XMLfilename; $item = FeedForAll_rss2html_str_replace("~~~ItemTitle~~~", FeedForAll_rss2html_limitLength($currentItem->title, $limitItemTitleLength), $source); $item = FeedForAll_rss2html_str_replace("~~~ItemDescription~~~", FeedForAll_rss2html_limitLength($currentItem->description, $limitItemDescriptionLength), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemEnclosureLengthFormatted~~~", FeedForAll_rss2html_sizeToString($currentItem->enclosureLength), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemPubLongDate~~~", date($LongDateFormat, $currentItem->pubDate_t), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemPubShortDate~~~", date($ShortDateFormat, $currentItem->pubDate_t), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemPubLongTime~~~", date($LongTimeFormat, $currentItem->pubDate_t), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemPubShortTime~~~", date($ShortTimeFormat, $currentItem->pubDate_t), $item); $knownFields = $currentItem->getArrayOfFields(); foreach ($knownFields as $field) { $item = FeedForAll_rss2html_str_replace($field, $currentItem->getValueOf($field), $item); } $item = FeedForAll_rss2html_CreateUniqueLink($currentItem->title, $currentItem->description, $currentItem->link, $currentItem->guid, $XMLfilename, $item); if (FeedForAll_parseExtensions() === TRUE) { $item = FeedForAll_parseExtensions_replaceInItem($currentItem, $item); } return FeedForAll_rss2html_AddIdentity($item); } } // // Allow access to the number of times that will be processed in the feed $template = FeedForAll_rss2html_str_replace("~~~NumberOfFeedItems~~~", min(abs($FeedMaxItems), count($rss_parser->Items)), $template); // // Find the string, if it exists, between the ~~~EndItemsRecord~~~ and ~~~BeginItemsRecord~~~ // while ((strstr($template, "~~~BeginItemsRecord~~~")) !== FALSE) { $match = NULL; $allitems = NULL; $loop_limit = min(abs($FeedMaxItems), count($rss_parser->Items)); 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; } if ($FeedMaxItems < 0) { for ($x = count($rss_parser->Items)-1; $x >= count($rss_parser->Items) + $FeedMaxItems; $x--) { $allitems .= FeedForALL_rss2html_replaceInItem($block1, $rss_parser->Items[$x]); $x--; if ($x >= count($rss_parser->Items) + $FeedMaxItems) { //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -