File size: 3.59Kb
<?
include("mysql.inc.php");
/*
* Animated Collapsible DIV- © Dynamic Drive DHTML code library (www.pokazuha.tv)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.pokazuha.tv/ for this script and 100s more
* Last Update : Tuesday, November 13 2005
*/
if (get_magic_quotes_gpc())
{
foreach ($_POST as $name => $value)
$_POST[$name] = stripslashes($value);
foreach ($_GET as $name => $value)
$_GET[$name] = stripslashes($value);
foreach ($_REQUEST as $name => $value)
$_REQUEST[$name] = stripslashes($value);
}
function clear_cache($live_time)
{
$query = "select file_name,itemID from cache_feed where (timeCreated + interval $live_time second) < now() limit 2";
$data = db_getrows(db_query($query));
if (count($data))
{
foreach($data as $index=>$value)
{
@unlink("cache/".$value['file_name']);
$query = "delete from cache_feed where itemID={$value['itemID']}";
db_query($query);
}
}
}
function if_cache_full($max_size)
{
$query = "select sum(size) as s from cache_feed";
$data = db_getrows(db_query($query));
$max_bytes = $max_size * 1024 * 1024;
if ($data[0]['s'] >= $max_bytes)
return TRUE;
else
return FALSE;
}
function check_chache($keywords,$live_time)
{
clear_cache($live_time);
$terms = mysql_escape_string($keywords);
$query = "select * from cache_feed where keywords='$terms' and (timeCreated + interval $live_time second) > now() order by timeCreated desc";
$data = db_getrows(db_query($query));
if (count($data[0]) && is_file("cache/".$data[0]['file_name']))//query cached
{
return "<font color=\"red\">Cached results</font>".file_get_contents("cache/".$data[0]['file_name']);
}
return FALSE;
}
function add_data_to_cache($keywords,$content,$live_time,$max_size)
{
if (if_cache_full($max_size))
return FALSE;
$terms = mysql_escape_string($keywords);
$file_name = md5($keywords.time()).".cch";
$fp = @fopen("cache/".$file_name,"w");
if ($fp == FALSE)
return FALSE;
$content = str_replace("\r\n",'',$content);
$content = str_replace("\t",'',$content);
$content = chop($content);
$content = preg_replace('|\s\s|','',$content);
$file_size = strlen($content);
@fwrite($fp,$content,$file_size);
@fclose($fp);
$query = "insert into cache_feed set file_name='$file_name',timeCreated=now(),exipredAfter='$live_time',keywords='$terms',size='$file_size'";
db_query($query);
return TRUE;
}
function add_stat_to_db($keywords, $type)
{
$keywords = mysql_escape_string($keywords);
$query = "select count from terms where keyword='$keywords' and type='$type'";
$ret = db_getrows(db_query($query));
if (count($ret) != 0)
{
$count = $ret[0]['count'] + 1;
$query = "update terms set count='$count' where keyword='$keywords' and type='$type'";
}
else
{
$query = "insert into terms set keyword='$keywords', date=now(), type='$type', count='1'";
}
db_query($query);
}
function check_if_bad_request($keywords)
{
$bad_words_array = explode('+',$keywords);
$q = '';
$i = 0;
for (; $i < (count($bad_words_array) - 1); $i ++)
{
if (strlen(chop($bad_words_array[$i])) != 0)
$q .= " word like '{$bad_words_array[$i]}' or ";
}
$q .= " word like '{$bad_words_array[$i]}'";
$query = "select count(*) as c from bad_words where $q";
$rows = db_getrows(db_query($query));
return ($rows[0]['c'] != 0);
}
?>