PHP Kod: Kodu kopyalamak için üzerine çift tıklayın!
cacher.class.php
<?php
class Cacher
{
var $cachedir = CACHE_DIR;
var $suffix;
/**
* Constructor. Requires CACHE_DIR directive to be set
* prior to use. CACHE_DIR will contain cache files
* which hold the contents of requested URLs.
*/
function Cacher($suffix='')
{
if(!(CACHE_DIR))
{
die('CACHE_DIR not configured.');
}
$this->suffix = $suffix;
}
/**
* Fetch a URL. If it has already
* been cached within the specified cacheTime,
* the cached copy is returned. Otherwise a
* fresh copy is retrieved and cached.
*
* If it can't write to the cache for some reason, the original URL
* is returned.
*
* [MENTION=81769]para[/MENTION]m $url The URL to retrieve
* [MENTION=81769]para[/MENTION]m $cacheTime The length of time to cache the requested URL.
*/
function fetch($url, $cacheTime=86600)
{
// Determine cache file name
$cacheFile = $this->cachedir . md5($url) . $this->suffix . '.cache' ;
$refresh = true;
if([MENTION=37436]file[/MENTION]_exists($cacheFile))
{
$refresh = (time() - $cacheTime > [MENTION=37436]file[/MENTION]mtime($cacheFile)) ;
}
[MENTION=15783]cLear[/MENTION]statcache();
/**
* Fetch a URL and return contents as a string. If it has already
* been cached within the specified cacheTime,
* the cached copy is returned. Otherwise a
* fresh copy is retrieved and cached.
*
* [MENTION=81769]para[/MENTION]m $url The URL to retrieve
* [MENTION=81769]para[/MENTION]m $cacheTime The length of time to cache the requested URL.
*/
function fetchContents($url, $cacheTime=86600)
{
$file = $this->fetch($url, $cacheTime);
if(!$file) return false;
return file_get_contents($file);
}
/**
* Clear cache files for a url.
*/
function clear($url)
{
// Determine cache file name
$cacheFile = $this->cachedir . md5($url) . $this->suffix . '.cache' ;
if([MENTION=37436]file[/MENTION]_exists($cacheFile))
{
[MENTION=55533]UnL[/MENTION]ink($cacheFile);
}
}
}
?>
cacher.class.php
<?php
require_once('cacher.class.php');
class GooglePageRank
{
var $site;
var $pagerank;
/**
* Constructor.
*
* [MENTION=81769]para[/MENTION]m url The site URL to check for PageRank
* [MENTION=81769]para[/MENTION]m cacheTime (Optional) Length of time in seconds to cache results.
*/
function GooglePageRank($site, $cacheTime=86400)
{
$this->site = $site;
if(count($site)==0) die('Google needs a site URL to check pagerank.');
// Calculated variables
$info = 'info:' . urldecode($site);
$checksum = $this->checksum($this->strord($info));
$url = " Bu forumdaki linkleri ve resimleri görebilmek için en az 25 mesajınız olması gerekir. style="color: #007700">{$checksum}&features=Rank&q={$info}";
// Pull pagerank through cache
$cacher = new Cacher('_google');
$result = $cacher->fetchContents($url, $cacheTime);
$rankObject = new GooglePageRank(" Bu forumdaki linkleri ve resimleri görebilmek için en az 25 mesajınız olması gerekir. type="text/javascript" src="https://code.jquery.com/jquery-1.12.0.min.js">