Просмотр файла forum/top.php

Размер файла: 3.68Kb
<?php
// mod by Golem http://veplog.ru

require_once"../template/start.php";
require_once"../template/regglobals.php";
require_once"../template/config.php";
require_once"../template/functions.php";
require_once"../template/antidos.php";
require_once"../template/cookies.php";
require_once"../template/gzip.php";
require_once"../template/header.php";
require_once"../template/referer.php";
include_once"../themes/$config_themes/index.php";
include_once"../template/isset.php";

echo '<div class=tp><b>Топ популярных тем</b></div>';

//------------------------------ НОВАЯ ФУНКЦИЯ КЕШИРОВАНИЯ ------------------------------//
$filtime=filemtime(BASEDIR."local/datatmp/topthemes.dat");
$themfile=file(BASEDIR."local/datatmp/topthemes.dat");
$them_count=count($themfile);

$filtime=$filtime+(3600*$config_themesforumcache);

if($sitetime>$filtime || $them_count<50){



$dir = opendir (BASEDIR."local/dataforum");
while ($file = readdir ($dir)) {
if (ereg ("\.dat$", $file) && !ereg("^top", $file)&& !ereg("^main", $file)) {
$alltopthem[]=$file;
}}
closedir ($dir);
$total = count($alltopthem);


$alltopthem=str_replace(".dat","",$alltopthem);
for ($i = 0; $i < $total; $i++){
$tex = file(BASEDIR."local/dataforum/$alltopthem[$i].dat");
$summa=count($tex);
$dat_total[]=$summa;
$dat_count[]=$alltopthem[$i];
}

arsort($dat_total);

foreach($dat_total as $k=>$v){ $gg++;

$tex = file(BASEDIR."local/dataforum/$dat_count[$k].dat");
$tex = array_reverse($tex);
$data = explode("|",$tex[0]);
if($dat_count[$k]!="" && $data[8]!=""){
$dat_top[]='|'.$gg.'|'.$data[8].'|'.$dat_count[$k].'|'.$data[3].'|'.$v.'|'.$data[0].'||'.$data[9].'|';
}}

$dat_top=implode("\r\n",$dat_top);

if($dat_top!=""){
$fp = fopen(BASEDIR."local/datatmp/topthemes.dat","a+");
flock ($fp,LOCK_EX);
ftruncate ($fp,0);
fputs($fp,"$dat_top\r\n");
fflush ($fp);
flock ($fp,LOCK_UN);
fclose($fp);
chmod ($fp, 0666);
chmod (BASEDIR."local/datatmp/topthemes.dat", 0666);
}
}


//------------------------------ ВЫВОД ИЗ КЕША ------------------------------//
$file = file(BASEDIR."local/datatmp/topthemes.dat");
$total = count($file);

$start = (int)$_GET['start'];
if($start < 0 || $start > $total){$start = 0;}
if ($total < $start + $config_forumtem){ $end = $total; }
else {$end = $start + $config_forumtem; }
for ($i = $start; $i < $end; $i++){

$data = explode("|",$file[$i]);

echo '<div class="forum"><div class="r0">'.$data[1].'.
<a href="index.php?fid='.$data[2].'&amp;id='.$data[3].'&amp;'.SID.'">'.$data[4].'</a>
['.$data[5].'] '.$data[6].'</div></div>';
}

if ($start != 0) {echo '<a href="top.php?start='.($start - $config_forumtem).'&amp;'.SID.'">&lt;пред.</a> ';}else{echo'&lt;пред.';}
echo ' | ';
if ($total > $start + $config_forumtem) {echo ' <a href="top.php?start='.($start + $config_forumtem).'&amp;'.SID.'">след.&gt;</a>';}else{echo'след.&gt;';}


if($total>0){

$ba=ceil($total/$config_forumtem);
$ba2=$ba*$config_forumtem-$config_forumtem;

echo '<br>Стр.:';
$asd=$start-($config_forumtem*4);
$asd2=$start+($config_forumtem*5);
if($asd<$total && $asd>0){echo ' <a href="top.php?start=0&amp;'.SID.'">1</a> ... ';}

for($i=$asd; $i<$asd2;)
{
if($i<$total && $i>=0){
$ii=floor(1+$i/$config_forumtem);

if ($start==$i) {
echo ' ('.$ii.')';
}
else {
echo ' <a href="top.php?start='.$i.'&amp;'.SID.'">'.$ii.'</a>';
}}


$i=$i+$config_forumtem;}
if($asd2<$total){echo ' ... <a href="top.php?start='.$ba2.'&amp;'.SID.'">'.$ba.'</a></div></div>';}
}


echo'<div class="btm">[<a href="../forum/index.php">В форум</a>]</div>';
include_once"../themes/$config_themes/foot.php";
echo'</div>';
?>