📄 rssfilter.php
字号:
$theFirst = 1; $z = 0; $filterProgram = ""; for ($x = 0; $x < $_POST["arrayCount"]+5; $x++) { if ($_POST["filterName$x"] != "") { if ($theFirst) { $theFirst = 0; } else { $scriptString .= ",\n\n"; if ($_POST["matchType"] == "AND") { $filterProgram .= " &&\n "; } else { $filterProgram .= " ||\n "; } } $scriptString .= "// Entry #".($z+1)."\n"; $scriptString .= "Array(\"Field\" => \"".$_POST["fieldName$x"]."\",\n"; $scriptString .= " \"Filter\" => \"".$_POST["filterName$x"]."\",\n"; $scriptString .= " \"Value\" => \"".htmlspecialchars($_POST["fieldValue$x"])."\",\n"; $scriptString .= " \"MatchCase\" => \"".$_POST["matchCase$x"]."\"\n"; $scriptString .= " )\n"; $filterProgram .= "\$currentItem->".$_POST["filterName$x"]."(\"".$_POST["fieldName$x"]."\", \"".addslashes(htmlspecialchars($_POST["fieldValue$x"]))."\", ".$_POST["matchCase$x"].")"; $z++; } } $scriptString .= ");\n"; $scriptString .= "\n"; // Plug the filter back in $scriptString = str_replace("<><><>filterProgram<><>", $filterProgram, $scriptString); echo "<pre style=\"font-size: smaller;\">\n"; echo "<?PHP\n\n"; echo htmlentities($scriptString); echo "\n?>\n"; echo "</pre>\n"; echo "================== End of file ==================<br><br>\n"; echo "<form method=\"POST\" action=\"$_SERVER[PHP_SELF]\" target=\"test_rssFilter\">\n"; echo "<input type=\"hidden\" name=\"testScript\">\n"; echo "<input type=\"hidden\" name=\"scriptValue\" value=\"".htmlentities($scriptString)."\">\n"; echo "<input type=\"SUBMIT\" name=\"submit\" value=\"Test Script\">\n"; echo "</form>\n"; } echo "<form method=\"POST\">\n"; echo "<table border=\"0\">\n"; echo "<tr><th valign=\"top\">XMLFilename</td><td><input type=\"text\" name=\"XMLfilename\" value=\"$_POST[XMLfilename]\" size=\"64\" maxlen=\"250\"></td></tr>\n"; echo "<tr><th valign=\"top\">useOutputCaching</th><td>"; echo "<select name=\"useOutputCaching\" size=\"1\">\n"; echo "<OPTION VALUE=\"0\""; if ($_POST["useOutputCaching"] == 0) echo " SELECTED"; echo ">No\n"; echo "<OPTION VALUE=\"1\""; if ($_POST["useOutputCaching"] == 1) echo " SELECTED"; echo ">Yes\n"; echo "</SELECT>\n"; echo "Enable the caching for the created RSS feed. Since it may take time to process multiple RSS feeds and may be noticed by visitors to your website this is highly recommended. <u>During development and testing set this to "No" so you can see the results of your changes.</u>"; echo "</td></tr>\n"; echo "<tr><th valign=\"top\">outputCacheTTL</th><td><input type=\"text\" name=\"outputCacheTTL\" value=\"$_POST[outputCacheTTL]\" size=\"8\"> The variable <b>outputCacheTTL</b> controls how many seconds a cached copy of resulting RSS feed can be used before it must be recreated.</td></tr>\n"; echo "</table>\n"; echo "Use item if "; echo "<select name=\"matchType\" size=\"1\">\n"; echo "<option value=\"AND\""; if ($_POST["matchType"] == "AND") echo " SELECTED"; echo ">ALL</option>\n"; echo "<option value=\"OR\""; if ($_POST["matchType"] == "OR") echo " SELECTED"; echo ">Any</option>\n"; echo "</select> of the following conditions are met<br>\n"; echo "<table border=\"1\" cellpading=\"2\" cellspacing=\"2\">\n"; echo "<tr><th>Field</th><th>Filter</th><th>Value</th></tr>\n"; $z = 0; for ($x = 0; $x < $arrayCount+5; $x++) { if ((isset($_POST["filterName$x"])) && ($_POST["filterName$x"] != "")) { echo "<tr><td valign=\"top\">".createFieldSelect($arrayOfFields, "fieldName$z", $_POST["fieldName$x"])."</td>\n"; echo "<td valign=\"top\">".createFilterSelect($arrayOfFilters, "filterName$z", $_POST["filterName$x"])."</td>\n"; echo "<td><input type=\"text\" name=\"fieldValue$z\" value=\"".$_POST["fieldValue$x"]."\" size=\"48\" maxlen=\"250\"><br>"; echo "<input type=\"checkbox\" name=\"matchCase$z\" value=\"1\""; if ($_POST["matchCase$x"]) echo " CHECKED"; echo "> Match Case</td></tr>\n"; $z++; } } $newArrayCount = $z; // Add more blank ones for ($y = $x; $y < $x+5; $y++) { echo "<tr><td valign=\"top\">".createFieldSelect($arrayOfFields, "fieldName$z")."</td>\n"; echo "<td valign=\"top\">".createFilterSelect($arrayOfFilters, "filterName$z")."</td>\n"; echo "<td><input type=\"text\" name=\"fieldValue$z\" value=\"\" size=\"48\" maxlen=\"250\"><br>"; echo "<input type=\"checkbox\" name=\"matchCase$z\" value=\"1\"> Match Case</td></tr>\n"; $z++; } echo "</table>\n"; echo "<input type=\"hidden\" name=\"buildScript\">\n"; echo "<input type=\"hidden\" name=\"arrayCount\" value=\"$newArrayCount\">\n"; echo "<input type=\"SUBMIT\" name=\"submit\" value=\"Generate script file\">\n"; echo "</form>\n";} else { // // Add the path to $cacheFolder, incase it is called from a different directoy $localCacheFolder = dirname(__FILE__)."/$outputCacheFolder"; // // Make the directory if it doesn't exist if (file_exists($localCacheFolder) === FALSE) { if (@mkdir($localCacheFolder, 0777) === FALSE) { $useOutputCaching = 0; } } $gotDataFromCache = 0; if (isset($_REQUEST["testScript"])) { $useOutputCaching = 0; } elseif ($FilterScriptFilename != "DO_NOT_INCLUDE_SCRIPT") { $outputCacheName = "$localCacheFolder/$FilterScriptFilename.cache.xml"; } else { $outputCacheName = "$localCacheFolder/".basename($_SERVER["PHP_SELF"]).".cache.xml"; } if ($useOutputCaching && !isset($_REQUEST["FORCECACHEREFRESH"])) { if (file_exists($outputCacheName) === TRUE) { // File exists, so lets check the age if ((time() - filemtime($outputCacheName)) <= $outputCacheTTL) { if (($fd = @fopen($outputCacheName, "rb")) !== FALSE) { if (flock($fd, LOCK_EX)) { $finalResult = fread($fd, filesize($outputCacheName)); flock($fd, LOCK_UN); if (strlen($finalResult) == filesize($outputCacheName)) { $gotDataFromCache = 1; } } fclose($fd); } } } } if ($gotDataFromCache == 0) { if (($XML = FeedForAll_scripts_readFile($XMLfilename, $useFopenURL, $allowCachingXMLFiles)) === FALSE) { if ($GLOBALS["ERRORSTRING"] == "") { echo "Unable to open RSS Feed $XMLfilename, exiting\n"; } else { echo "Unable to open RSS Feed $XMLfilename with error <b>$GLOBALS[ERRORSTRING]</b>, exiting\n"; } exit -1; } if (strstr(trim($XML), "<?xml") === FALSE) { $XML = "<?xml version=\"1.0\"?>\n$XML"; } $XML = strstr(trim($XML), "<?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("rssFilter"); $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) { $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); if ($rss_parser->feedTYPE == "FEE") { $channelTop = substr($convertedXML, 0, strpos($convertedXML, "<entry>")); $channelBottom = substr($convertedXML, strrpos($convertedXML, "</entry>")); } elseif ($rss_parser->feedTYPE == "RDF") { if (($start1 = strpos($convertedXML, "<item>")) === FALSE) $start1 = strlen($convertedXML); if (($start2 = strpos($convertedXML, "<item ")) === FALSE) $start2 = strlen($convertedXML); $channelTop = substr($convertedXML, 0, min($start1, $start2)); $channelBottom = substr($convertedXML, strrpos($convertedXML, "</item>")); } else { $channelTop = substr($convertedXML, 0, strpos($convertedXML, "<item>")); $channelBottom = substr($convertedXML, strpos($convertedXML, "</channel>")); } $items = ""; for ($x = 0; $x < count($rss_parser->Items); $x++) { $items .= $rss_parser->Items[$x]->itemFullText."\n"; } // // If requested, update the channel pubDate and latBuildDate to the newest date if (isset($updateChannelDates) && $updateChannelDates && ($rss_parser->feedTYPE == "RDF")) { $pubDate = $rss_parser->FeedAtomUpdated; $pubDate_t = $rss_parser->FeedPubDate_t; for ($x = 0; $x < count($rss_parser->Items); $x++) { if ($pubDate_t < $rss_parser->Items[$x]->pubDate_t) { $pubDate_t = $rss_parser->Items[$x]->pubDate_t; $pubDate = $rss_parser->Items[$x]->pubAtomUpdated; } } $channelTop = preg_replace("/<updated.*updated>/", "<updated>$pubDate</updated>", $channelTop); } elseif (isset($updateChannelDates) && $updateChannelDates && ($rss_parser->feedTYPE == "RDF")) { $pubDate = $rss_parser->FeedPubDateDC; $pubDate_t = $rss_parser->FeedPubDate_t; for ($x = 0; $x < count($rss_parser->Items); $x++) { if ($pubDate_t < $rss_parser->Items[$x]->pubDate_t) { $pubDate_t = $rss_parser->Items[$x]->pubDate_t; $pubDate = $rss_parser->Items[$x]->pubDateDC; } } $channelTop = preg_replace("/<dc:date.*dc:date>/", "<dc:date>$pubDate</dc:date>", $channelTop); } elseif (isset($updateChannelDates) && $updateChannelDates && ($rss_parser->feedTYPE == "RSS")) { $pubDate = $rss_parser->FeedPubDate; $pubDate_t = $rss_parser->FeedPubDate_t; for ($x = 0; $x < count($rss_parser->Items); $x++) { if ($pubDate_t < $rss_parser->Items[$x]->pubDate_t) { $pubDate_t = $rss_parser->Items[$x]->pubDate_t; $pubDate = $rss_parser->Items[$x]->pubDate; } } $channelTop = preg_replace("/<lastBuildDate.*lastBuildDate>/", "<lastBuildDate>$pubDate</lastBuildDate>", $channelTop); $channelTop = preg_replace("/<pubDate.*pubDate>/", "<pubDate>$pubDate</pubDate>", $channelTop); } $finalResult = "$channelTop\n$items$channelBottom\n"; // // Write to cache if ($useOutputCaching) { if (($fd = @fopen($outputCacheName, "wb")) !== FALSE) { if (@flock($fd, LOCK_EX)) { fwrite($fd, $finalResult); flock($fd, LOCK_UN); } fclose($fd); } } } } if ((isset($debugLevel) && ($debugLevel >= 1)) || isset($_REQUEST["testScript"])) { echo "<br>Below is the XML for the produced RSS feed<hr>\n"; $finalResult = str_replace("&", "&", $finalResult); $finalResult = str_replace("<", "<", $finalResult); $finalResult = str_replace(">", ">", $finalResult); if (!headers_sent()) { // Send the Content-Type to force UTF-8 header("Content-Type: text/html; charset=UTF-8"); } echo "<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\"><title>Debug Output</title></head><body><pre>$finalResult</pre>\n"; } else { if (!headers_sent()) { // Send the Content-Type to force UTF-8 header("Content-Type: application/xml; charset=UTF-8"); } echo $finalResult."\n"; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -