📄 feedforall_scripts_cachingextension.php
字号:
if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_contentOfCache(): return false<br>\n"; } return FALSE; } Function FeedForAll_scripts_readFile($filename, $useFopenURL, $useCaching = 0, $actualCacheTTL = -1) { GLOBAL $cacheFolder; GLOBAL $useExpiredOnError; GLOBAL $debugLevel; GLOBAL $connectTimeoutLimit; if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_readFile($filename, $useFopenURL, $useCaching, $actualCacheTTL)<br>\n"; } // // Add the path to $cacheFolder, incase it is called from a different directoy $localCacheFolder = dirname(__FILE__)."/$cacheFolder"; $GLOBALS["ERRORSTRING"] = ""; $result = ""; if (stristr($filename, "://")) { if ($useFopenURL) { if (($result = FeedForAll_scripts_contentOfCache($filename, $useCaching, $actualCacheTTL)) === FALSE) { if (($fd = @fopen($filename, "rb")) === FALSE) { return FeedForAll_scripts_contentOfCache($filename, $useCaching, $actualCacheTTL, $useExpiredOnError); } if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_readFile(): fopen() succeeded<br>\n"; } while (($data = fread($fd, 4096)) != "") { $result .= $data; } fclose($fd); if ($useCaching) { if (($fd = @fopen($localCacheFolder."/".md5($filename), "wb")) !== FALSE) { if (@flock($fd, LOCK_EX)) { if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_readFile(): flock() successeded<br>\n"; } fwrite($fd, $result); flock($fd, LOCK_UN); chmod($localCacheFolder."/".md5($filename), 0664); } fclose($fd); if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_readFile(): fclose()<br>\n"; } } else { if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_readFile(): fopen(): failed<br>\n"; } } } } } else { if (($result = FeedForAll_scripts_contentOfCache($filename, $useCaching, $actualCacheTTL)) === FALSE) { // This is a URL so use CURL $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $filename); curl_setopt($curlHandle, CURLOPT_HEADER, 0); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlHandle, CURLOPT_USERAGENT, "FeedForAll rss2html.php v2"); // curl_setopt($curlHandle, CURLOPT_AUTOREFERER, 1); curl_setopt($curlHandle, CURLOPT_REFERER, $filename); if (ini_get("safe_mode") || ini_get("open_basedir")) { ; } else { curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, 1); } if (isset($connectTimeoutLimit) && $connectTimeoutLimit != 0) { curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, $connectTimeoutLimit); } curl_setopt($curlHandle, CURLOPT_MAXREDIRS, 10); $result = curl_exec($curlHandle); if (curl_errno($curlHandle)) { $GLOBALS["ERRORSTRING"] = curl_error($curlHandle); curl_close($curlHandle); return FeedForAll_scripts_contentOfCache($filename, $useCaching, $actualCacheTTL, $useExpiredOnError); } curl_close($curlHandle); if ($useCaching) { if (($fd = fopen($localCacheFolder."/".md5($filename), "wb")) !== FALSE) { if (flock($fd, LOCK_EX)) { if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_readFile(): flock() successeded<br>\n"; } fwrite($fd, $result); flock($fd, LOCK_UN); chmod($localCacheFolder."/".md5($filename), 0664); } fclose($fd); if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_readFile(): fclose()<br>\n"; } } else { if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_readFile(): fopen(): failed<br>\n"; } } } } } } else { // This is a local file, so use fopen if (($result = FeedForAll_scripts_contentOfCache($filename, $useCaching, $actualCacheTTL)) === FALSE) { if (($fd = @fopen($filename, "rb")) === FALSE) { return FeedForAll_scripts_contentOfCache($filename, $useCaching, $actualCacheTTL, $useExpiredOnError); } while (($data = fread($fd, 4096)) != "") { $result .= $data; } fclose($fd); if ($useCaching) { if (($fd = fopen($localCacheFolder."/".md5($filename), "wb")) !== FALSE) { if (flock($fd, LOCK_EX)) { if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_readFile(): flock() successeded<br>\n"; } fwrite($fd, $result); flock($fd, LOCK_UN); chmod($localCacheFolder."/".md5($filename), 0664); } fclose($fd); if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_readFile(): fclose()<br>\n"; } } else { if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_readFile(): fopen(): failed<br>\n"; } } } } } if (isset($debugLevel) && ($debugLevel >= 1)) { echo "DIAG: FeedForAll_scripts_readFile(): return SUCCESSFUL<br>\n"; } return $result; } Function FeedForAll_scripts_readOutputCacheFile($xmlFile, $tempalteFile) { GLOBAL $cacheFolder; GLOBAL $outputCacheTTL; // // If we are in here, it is assumed we what caching $useOutputCaching = 1; // // Add the path to $cacheFolder, incase it is called from a different directoy $localCacheFolder = dirname(__FILE__)."/$cacheFolder"; // // Make the directory if it doesn't exist if (file_exists($localCacheFolder) === FALSE) { if (@mkdir($localCacheFolder, 0777) === FALSE) { $useOutputCaching = 0; } } $gotDataFromCache = 0; if ($useOutputCaching && !isset($_REQUEST["FORCECACHEREFRESH"])) { $outputCacheName = "$localCacheFolder/".md5("$xmlFile - $tempalteFile").".cache.html"; 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)) { return $finalResult; } } fclose($fd); } } } } return FALSE; } Function FeedForAll_scripts_writeOutputCacheFile($xmlFile, $tempalteFile, $outputString) { GLOBAL $cacheFolder; // // If we are in here, it is assumed we what caching $useOutputCaching = 1; // // Add the path to $cacheFolder, incase it is called from a different directoy $localCacheFolder = dirname(__FILE__)."/$cacheFolder"; // // Make the directory if it doesn't exist if (file_exists($localCacheFolder) === FALSE) { if (@mkdir($localCacheFolder, 0777) === FALSE) { $useOutputCaching = 0; } } if ($useOutputCaching && !isset($_REQUEST["FORCECACHEREFRESH"])) { $outputCacheName = "$localCacheFolder/".md5("$xmlFile - $tempalteFile").".cache.html"; // // Write to cache if (($fd = @fopen($outputCacheName, "wb")) !== FALSE) { if (@flock($fd, LOCK_EX)) { fwrite($fd, $outputString); flock($fd, LOCK_UN); } fclose($fd); } } }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -