Code:
<?php
/**
*
* INDEXU
* Copyright(C), Nicecoder, 2000-2006, All Rights Reserved.
*
* INDEXU(tm) is protected by Indonesia and International copyright laws.
* Unauthorized use or distribution of INDEXU(tm) is strictly prohibited,
* violators will be prosecuted. To obtain a license for using INDEXU(tm),
* please register at Nicecoder home page at http://www.nicecoder.com
*
* Author:
* Dody Rachmat Wicaksono (dody@nicecoder.com)
* M. Zuber (zubby@nicecoder.com)
*
*/
// robot script - Copyright (C) 2006 Yuriy Hatala (yuriy@myth.org.ua)
function block_spiders($params) {
global $theme_path, $active_theme;
if (!$params['template']) {
$params['template'] = 'block.spiders.html';
}
$flExists = FALSE;
$RobotDB = "robot.db";
$RobotArray = array("googlebot", "msnbot", "yahoo");
$CurrentPage = md5($_SERVER['REQUEST_URI']);
$CurrentBot = strtolower($_SERVER['HTTP_USER_AGENT']);
if (preg_match(sprintf("/%s/", join("|", $RobotArray)), $CurrentBot))
{
foreach ($RobotArray as $key => $value)
{ if (preg_match(sprintf("/%s/", $value), $CurrentBot)) { break; } }
if (file_exists($RobotDB) && (is_readable($RobotDB) && is_writable($RobotDB)))
{
$DBHandle = fopen($RobotDB, "r+");
if (is_resource($DBHandle) && flock($DBHandle, LOCK_EX))
{
$Line = fgets($DBHandle, 61);
while (!feof($DBHandle))
{
$PageInfo = unpack("A32Page/Vgooglebot/Vmsnbot/Vyahoo", base64_decode($Line));
if (preg_match(sprintf("/%s/", $CurrentPage), $PageInfo['Page']))
{
$flExists = TRUE;
$CurrentPos = ftell($DBHandle);
fseek($DBHandle, 0, SEEK_END);
}
$Line = fgets($DBHandle, 61);
}
if (!$flExists)
{
fseek($DBHandle, 0, SEEK_END);
$PageInfo = array_merge($CurrentPage, array('googlebot' => 0, 'msnbot' => 0, 'yahoo' => 0));
}
else { fseek($DBHandle, ($CurrentPos - 60), SEEK_SET); }
$PageInfo[ $RobotArray[$key] ] = $PageInfo[ $RobotArray[$key] ] + 1;
// print_r($PageInfo);
fwrite($DBHandle, base64_encode(pack("A*VVV", $CurrentPage, $PageInfo['googlebot'], $PageInfo['msnbot'], $PageInfo['yahoo'])));
flock($DBHandle, LOCK_UN);
}
fclose($DBHandle);
}
}
else
{
if (file_exists($RobotDB) && is_readable($RobotDB))
{
$DBHandle = fopen($RobotDB, "r");
if (is_resource($DBHandle))
{
$Line = fgets($DBHandle, 61);
while (!feof($DBHandle))
{
$PageInfo = unpack("A32Page/Vgooglebot/Vmsnbot/Vyahoo", base64_decode($Line));
if (preg_match(sprintf("/%s/", $CurrentPage), $PageInfo['Page']))
{
$flExists = TRUE;
$CurrentPos = ftell($DBHandle);
fseek($DBHandle, 0, SEEK_END);
}
$Line = fgets($DBHandle, 61);
}
}
fclose($DBHandle);
if (!$flExists) { $PageInfo = array('googlebot' => 0, 'msnbot' => 0, 'yahoo' => 0); }
}
}
$tpl = new Template;
$google_spider = $PageInfo['googlebot'];
$yahoo_spider = $PageInfo['yahoo'];
$msn_spider = $PageInfo['msnbot'];
$tpl->assign("Gspider", $google_spider);
$tpl->assign("Yspider", $yahoo_spider);
$tpl->assign("Mspider", $msn_spider);
$tpl->display("blocks/" . $params['template']);
}
?>
3.