View file index.php

File size: 18.88Kb
<?php
//
//  index.php
//  rev0019
//

if($modo=='phpinfo') {
	phpinfo();
	exit();
}

include('config.php');
include('lang/'.$idioma.'.php');
include('funciones.php');
$time_used=getmicrotime();

if($installed==0) $HTML='<script>window.location.href = "admin.php?pass='.$adminPass.'&login='.$adminLogin.'";</script>';

function generarTOP($para) {
    global $enableComment, $enableRate, $ordenCriterio, $tiempoCaduca, $tiempoReset, $tiempoResetLast, $bloque1, $bloque2;
    global $_Rank_, $_Webs_, $_INOUT_;
    global $_Average_, $_Comments_, $_IN_, $_OUT_, $_Ratio_, $_day_, $_votes_, $_DaysInTop_, $_RateIt_, $_Info_;
    $_Average_=strtoupper($_Average_);
    $_Comments_=strtoupper($_Comments_);

	$plantilla=TOPoTags("read",$para,0);
	$maxBannerAncho=$plantilla[7];
	$maxBannerAlto=$plantilla[8];
	
    if(file_exists("data/orden.dat")) {
        $ordenOLD=orden("read",0);
        $ordenOLD=array_flip($ordenOLD);
        $orden=orden("update",$ordenCriterio);
    } else {
        $orden=orden("update",$ordenCriterio);
        $ordenOLD=orden("read",0);
        $ordenOLD=array_flip($ordenOLD);
    }

    if( $tiempoResetLast<abs(time()-$tiempoReset) ) {
        $reset=1;
        config("parcial","\$tiempoResetLast=".$tiempoResetLast,"\$tiempoResetLast=".time());
    }
	
	$anchoWebs=500;
	if($anchoWebs<$maxBannerAncho+10) $anchoWebs=$maxBannerAncho+10;

    $top[1]='<table align="center" border="0" bgcolor="Black" cellspacing="1" cellpadding="2">';
    $top[1].='<tr align="center" class="2"><td class="texto1">'.$_Rank_.'</td>';
    $top[1].='<td class="texto1" width="'.$anchoWebs.'">'.$_Webs_.'</td>';
    $top[1].='<td class="texto1">'.$_INOUT_.'</td></tr>';
    for($i=1;$i<=$bloque1;$i++) {   //Cуdigo HTML para top1.htm
		if(!isset($orden[$i])) break;
        $datos=datos("read",$orden[$i],0);
        $totalsites++;
        $parcialIN+=$datos[0];
        $parcialOUT+=$datos[1];
        $globalIN+=$datos[2];
        $globalOUT+=$datos[3];
        if( $datos[7]<abs(time()-$tiempoCaduca) ) { //Sitio muerto
            index("delete",$orden[$i],0,0);
            continue;
        }
        include("data/".$orden[$i]."info.php");
        //Cбlculos previos
        if($datos[5]) {
            $nota=number_format($datos[4]/$datos[5],1,'.','');
        } else {
            $nota=0;
        }
        $dif=$ordenOLD[$orden[$i]]-$i;
        if($dif>0) $flecha='<img src="gif/arrow_green.gif" border="0" width="15" height="20"><font color="green">+'.$dif.'</font>';
        if($dif<0) $flecha='<img src="gif/arrow_red.gif" border="0" width="15" height="20"><font color="red">'.$dif.'</font>';
        if($dif==0) $flecha='<span style="{font-size:15pt; color:blue; font-weight:bold;}">=</span>';
		if(strlen($bannerURL)>10) {
			$bannerAncho=string("int",$bannerAncho,$maxBannerAncho);
			$bannerAlto=string("int",$bannerAlto,$maxBannerAlto);
			$bannerAUX='<A href="out.php?ID='.$orden[$i].'" target="_blank" onMouseover="window.status=\''.$webURL.'\'; return true;" onMouseout="window.status=\'\'; return true;"><img src="'.$bannerURL.'" border="0" width="'.$bannerAncho.'" height="'.$bannerAlto.'"></A>';
		} else {
			$bannerAUX="";
		}
		//TOPoTags
		$old[0]='%%RANK%%';			$new[0]=$i;
		$old[1]='%%RANKARROW%%';	$new[1]=$flecha;
		$old[2]='%%BGCOLOR%%';		$new[2]='class="'.($i%2).'"';
		$old[3]='%%BANNER%%';		$new[3]=$bannerAUX;
		$old[4]='%%WEB%%';			$new[4]='<A href="out.php?ID='.$orden[$i].'" target="_blank" onMouseover="window.status=\''.$webURL.'\'; return true;" onMouseout="window.status=\'\'; return true;">'.str_replace(array('\"',"\'"),array('&Prime;','&prime;'),$web).'</A>';
		$old[5]='%%DESCRIPTION%%';	$new[5]=str_replace(array('\"',"\'"),array('&Prime;','&prime;'),$descripcion);
		if($enableComment) {
			$old[6]='%%STARS%%';		$new[6]='<img src="gif/star'.number_format($nota,0,'.','').'.gif" border="0">';
			$old[7]='%%AVERAGE1%%';		$new[7]=$nota;		
			$old[8]='%%AVERAGE2%%';		$new[8]=$nota.' <i>('.$datos[5].' '.$_votes_.')</i>';		
			$old[9]='%%AVERAGE3%%';		$new[9]='<b>'.$_Average_.':</b> '.$new[8];
		} else {
			$old[6]='%%STARS%%';		$new[6]='';
			$old[7]='%%AVERAGE1%%';		$new[7]='';		
			$old[8]='%%AVERAGE2%%';		$new[8]='';		
			$old[9]='%%AVERAGE3%%';		$new[9]='';
		}
		if($enableComment) {
			$old[10]='%%COMMENTS%%';	$new[10]='<b>'.$_Comments_.':</b> '.$datos[6];
		} else {
			$old[10]='%%COMMENTS%%';	$new[10]='';
		}
		if($enableRate) {
			$old[11]='%%RATEIT%%';		$new[11]='<INPUT TYPE="BUTTON" class="miniboton" value="'.$_RateIt_.'" onClick="ventana(\'info.php?ID='.$orden[$i].'&modo=puntuar&paso=1\',\'_blank\',300,150)">';
		} else {
			$old[11]='%%RATEIT%%';		$new[11]='';		
		}
		$old[12]='%%INFO%%';		$new[12]='<INPUT TYPE="BUTTON" class="miniboton" value="'.$_Info_.'" onClick="ventana(\'info.php?ID='.$orden[$i].'\',\'_blank\','.(200*$enableComment+360).','.(200*$enableRate+225).')">';
		$old[13]='%%IN%%';			$new[13]=$_IN_;		
		$old[14]='%%IN1%%';			$new[14]='<span class="in">'.$datos[0].'</span>';
		$old[15]='%%IN2%%';			$new[15]='<span class="in">'.$datos[2].'</span>';				
		$old[16]='%%IN3%%';			$new[16]='<span class="in">'.media("pordia",$orden[$i],time(),$datos[2]).'/'.$_day_.'</span>';
		$old[17]='%%OUT%%';			$new[17]=$_OUT_;		
		$old[18]='%%OUT1%%';		$new[18]='<span class="out">'.$datos[1].'</span>';
		$old[19]='%%OUT2%%';		$new[19]='<span class="out">'.$datos[3].'</span>';				
		$old[20]='%%OUT3%%';		$new[20]='<span class="out">'.media("pordia",$orden[$i],time(),$datos[3]).'/'.$_day_.'</span>';
		$old[21]='%%DAYS%%';		$new[21]='<i>'.media("dias",time(),$orden[$i],0).$_DaysInTop_.'</i>';
		$old[22]='%%RATIO1%%';		$new[22]=barra("ratio",100,$datos[0],$datos[1]);		
		$old[23]='%%RATIO2%%';		$new[23]='<b>'.$_Ratio_.':</b> '.barra("ratio",100,$datos[0],$datos[1]);
		//Plantilla
		$RANK=str_replace($old,$new,$plantilla[1]);
		$WEBS=str_replace($old,$new,$plantilla[2]);
		$INOUT=str_replace($old,$new,$plantilla[3]);				
		//Tablas estructurales
        $top[1].='<TR class="'.($i%2).'">';
        $top[1].='<TD class="texto0" valign="middle">'.$RANK.'</TD>';
        $top[1].='<TD valign="middle" width="'.$anchoWebs.'">'.$WEBS.'</TD>';
        $top[1].='<TD class="minitexto0" valign="middle">'.$INOUT.'</TD>';
		$top[1].='</TR>';

        if($reset) datos("reset",$orden[$i],0);
    }
    $top[1].='</table>';

    $top[2]='<table align="center" border="0" bgcolor="Black" cellspacing="1" cellpadding="2">';
    $top[2].='<tr align="center" class="2"><td class="texto1">'.$_Rank_.'</td>';
    $top[2].='<td class="texto1" width="'.$anchoWebs.'">'.$_Webs_.'</td>';
    $top[2].='<td class="texto1">'.$_INOUT_.'</td></tr>';
    for($i=$bloque1+1;$i<=$bloque1+$bloque2;$i++) {   //Cуdigo HTML para top2.htm	
        //if(!array_key_exists($i,$orden)) break;
		if(!isset($orden[$i])) break;
        $datos=datos("read",$orden[$i],0);
        $totalsites++;
        $parcialIN+=$datos[0];
        $parcialOUT+=$datos[1];
        $globalIN+=$datos[2];
        $globalOUT+=$datos[3];
        if( $datos[7]<abs(time()-$tiempoCaduca) ) { //Sitio muerto
            index("delete",$orden[$i],0,0);
            continue;
        }
        include("data/".$orden[$i]."info.php");
        //Cбlculos previos
        if($datos[5]) {
            $nota=number_format($datos[4]/$datos[5],1,'.','');
        } else {
            $nota=0;
        }
        $dif=$ordenOLD[$orden[$i]]-$i;
        if($dif>0) $flecha='<img src="gif/arrow_green.gif" border="0" width="15" height="20"><font color="green">+'.$dif.'</font>';
        if($dif<0) $flecha='<img src="gif/arrow_red.gif" border="0" width="15" height="20"><font color="red">'.$dif.'</font>';
        if($dif==0) $flecha='<span style="{font-size:15pt; color:blue; font-weight:bold;}">=</span>';
		//TOPoTags
		$old[0]='%%RANK%%';			$new[0]=$i;
		$old[1]='%%RANKARROW%%';	$new[1]=$flecha;
		$old[2]='%%BGCOLOR%%';		$new[2]='class="'.($i%2).'"';
		//$old[3]='%%BANNER%%';		$new[3]=$bannerAUX;
		$old[4]='%%WEB%%';			$new[4]='<A href="out.php?ID='.$orden[$i].'" target="_blank" onMouseover="window.status=\''.$webURL.'\'; return true;" onMouseout="window.status=\'\'; return true;">'.str_replace(array('\"',"\'"),array('&Prime;','&prime;'),$web).'</A>';
		$old[5]='%%DESCRIPTION%%';	$new[5]=str_replace(array('\"',"\'"),array('&Prime;','&prime;'),$descripcion);
		if($enableComment) {
			$old[6]='%%STARS%%';		$new[6]='<img src="gif/star'.number_format($nota,0,'.','').'.gif" border="0">';
			$old[7]='%%AVERAGE1%%';		$new[7]=$nota;		
			$old[8]='%%AVERAGE2%%';		$new[8]=$nota.' <i>('.$datos[5].' '.$_votes_.')</i>';		
			$old[9]='%%AVERAGE3%%';		$new[9]='<b>'.$_Average_.':</b> '.$new[8];
		} else {
			$old[6]='%%STARS%%';		$new[6]='';
			$old[7]='%%AVERAGE1%%';		$new[7]='';		
			$old[8]='%%AVERAGE2%%';		$new[8]='';		
			$old[9]='%%AVERAGE3%%';		$new[9]='';
		}
		if($enableComment) {
			$old[10]='%%COMMENTS%%';	$new[10]='<b>'.$_Comments_.':</b> '.$datos[6];
		} else {
			$old[10]='%%COMMENTS%%';	$new[10]='';
		}
		if($enableRate) {
			$old[11]='%%RATEIT%%';		$new[11]='<INPUT TYPE="BUTTON" class="miniboton" value="'.$_RateIt_.'" onClick="ventana(\'info.php?ID='.$orden[$i].'&modo=puntuar&paso=1\',\'_blank\',300,150)">';
		} else {
			$old[11]='%%RATEIT%%';		$new[11]='';		
		}
		$old[12]='%%INFO%%';		$new[12]='<INPUT TYPE="BUTTON" class="miniboton" value="'.$_Info_.'" onClick="ventana(\'info.php?ID='.$orden[$i].'\',\'_blank\','.(200*$enableComment+360).','.(200*$enableRate+225).')">';
		$old[13]='%%IN%%';			$new[13]=$_IN_;		
		$old[14]='%%IN1%%';			$new[14]='<span class="in">'.$datos[0].'</span>';
		$old[15]='%%IN2%%';			$new[15]='<span class="in">'.$datos[2].'</span>';				
		$old[16]='%%IN3%%';			$new[16]='<span class="in">'.media("pordia",$orden[$i],time(),$datos[2]).'/'.$_day_.'</span>';
		$old[17]='%%OUT%%';			$new[17]=$_OUT_;		
		$old[18]='%%OUT1%%';		$new[18]='<span class="out">'.$datos[1].'</span>';
		$old[19]='%%OUT2%%';		$new[19]='<span class="out">'.$datos[3].'</span>';				
		$old[20]='%%OUT3%%';		$new[20]='<span class="out">'.media("pordia",$orden[$i],time(),$datos[3]).'/'.$_day_.'</span>';
		$old[21]='%%DAYS%%';		$new[21]='<i>'.media("dias",time(),$orden[$i],0).$_DaysInTop_.'</i>';
		$old[22]='%%RATIO1%%';		$new[22]=barra("ratio",100,$datos[0],$datos[1]);		
		$old[23]='%%RATIO2%%';		$new[23]='<b>'.$_Ratio_.':</b> '.barra("ratio",100,$datos[0],$datos[1]);
		//Plantilla
		$RANK=str_replace($old,$new,$plantilla[4]);
		$WEBS=str_replace($old,$new,$plantilla[5]);
		$INOUT=str_replace($old,$new,$plantilla[6]);				
		//Tablas estructurales
        $top[2].='<TR class="'.($i%2).'">';
        $top[2].='<TD class="texto0" valign="middle">'.$RANK.'</TD>';
        $top[2].='<TD valign="middle" width="'.$anchoWebs.'">'.$WEBS.'</TD>';
        $top[2].='<TD class="minitexto0" valign="middle">'.$INOUT.'</TD>';
		$top[2].='</TR>';

        if($reset) datos("reset",$orden[$i],0);
    }
    $top[2].='</table>';


    $top[3]='<table align="center" border="0" bgcolor="Black" cellspacing="1" cellpadding="2">';
    $top[3].='<tr align="center" class="2"><td class="texto1">'.$_Rank_.'</td>';
    $top[3].='<td class="texto1" width="'.$anchoWebs.'">'.$_Webs_.'</td>';
    $top[3].='<td class="texto1">'.$_INOUT_.'</td></tr>';
    for($i=$bloque1+$bloque2+1;;$i++) {   //Cуdigo HTML para top3.htm	
        //if(!array_key_exists($i,$orden)) break;
		if(!isset($orden[$i])) break;
        $datos=datos("read",$orden[$i],0);
        $totalsites++;
        $parcialIN+=$datos[0];
        $parcialOUT+=$datos[1];
        $globalIN+=$datos[2];
        $globalOUT+=$datos[3];
        if( $datos[7]<abs(time()-$tiempoCaduca) ) { //Sitio muerto
            index("delete",$orden[$i],0,0);
            continue;
        }
        include("data/".$orden[$i]."info.php");
        //Cбlculos previos
        if($datos[5]) {
            $nota=number_format($datos[4]/$datos[5],1,'.','');
        } else {
            $nota=0;
        }
        $dif=$ordenOLD[$orden[$i]]-$i;
        if($dif>0) $flecha='<img src="gif/arrow_green.gif" border="0" width="15" height="20"><font color="green">+'.$dif.'</font>';
        if($dif<0) $flecha='<img src="gif/arrow_red.gif" border="0" width="15" height="20"><font color="red">'.$dif.'</font>';
        if($dif==0) $flecha='<span style="{font-size:15pt; color:blue; font-weight:bold;}">=</span>';
        //Cуdigo HTML
        $top[3].='<TR class="'.($i%2).'">';
        $top[3].='<TD class="texto0" align="center" valign="middle">'.$i.'<br>'.$flecha.'</TD>';
        $top[3].='<TD align="left" valign="middle" width="'.$anchoWebs.'">';
        $top[3].='<CENTER><A href="out.php?ID='.$orden[$i].'" target="_blank" onMouseover="window.status=\''.$webURL.'\'; return true;" onMouseout="window.status=\'\'; return true;">'.$web.'</A>';
		if($enableRate) $top[3].='&nbsp;<img src="gif/star'.number_format($nota,0,'.','').'.gif" border="0">';
        $top[3].='</CENTER><span>'.$descripcion.'</span>';
        $top[3].='</TD>';
        $top[3].='<TD class="minitexto0" align="center" valign="middle">';
        $top[3].='<b>'.$_IN_.':</b>&nbsp;<span class="in"><span style="{font-size:15pt; font-weight:bold;}">'.$datos[0].'</span><b>/ '.$datos[2].'</b></span>';
        $top[3].='<br><b>'.$_OUT_.':</b>&nbsp;<span class="out"><span style="{font-size:15pt; font-weight:bold;}">'.$datos[1].'</span><b>/ '.$datos[3].'</b></span>';
        $top[3].='</TD>';
        $top[3].='</TR>';

        if($reset) datos("reset",$orden[$i],0);
    }
    $top[3].='</table>';
	

    for($i=1;$i<4;$i++) {
        $fp=fopen("html/top".$i.".htm","w");
        flock($fp,2);
        fwrite($fp,$top[$i]);
        fclose($fp);
    }

    //stats
    $stats="<?php\n";
    $stats.="echo '<form name=\"clock\">';\n";
    $stats.="echo '<table align=\"center\" border=\"0\" bgcolor=\"Black\" cellspacing=\"0\" cellpadding=\"5\">';\n";
    $stats.="echo '<caption><span class=\"minititulo\">'.\$_Stats_.'</span></caption>';\n";
    $stats.="echo '<tr class=\"texto0\">';\n";
    $stats.="echo '<td align=\"right\" valign=\"middle\" class=\"1\">';\n";
    $stats.="echo \$_TotalSites_.':';";
    $stats.="echo '<br>'.\$_ParcialINOUT_.':';\n";
    $stats.="echo '<br>'.\$_TotalINOUT_.':';\n";
    $stats.="echo '</td>';\n";
    $stats.="echo '<td align=\"left\" valign=\"middle\" class=\"1\">';\n";
    $stats.="echo '".$totalsites."';\n";
    $stats.="echo '<br>".$parcialIN." / ".$parcialOUT."';\n";
    $stats.="echo '<br>".$globalIN." / ".$globalOUT."';\n";
    $stats.="echo '</td>';\n";
    $stats.="echo '<td align=\"center\" valign=\"middle\" class=\"0\">';\n";
    $stats.="echo \$_TimeResetUpdate_;\n";
    $stats.="echo '<br>'.\$_NextUpdate_.'<INPUT TYPE=\"TEXT\" name=\"CuentaAtras\" class=\"reloj\" size=\"6\">';\n";
    $stats.="echo '<br>'.\$_NextReset_.date(\$_DateFormat_.\" (H:i)\",\$tiempoResetLast+\$tiempoReset);\n";
    $stats.="echo '<br>'.\$_SortBy_.' '.\$_SortCriterio_[\$ordenCriterio];\n";	
    $stats.="echo '</td>';\n";
    $stats.="echo '</tr>';\n";
    $stats.="echo '</table></form>';\n";
    $stats.="clearstatcache();\n";
    $stats.="\$stat=stat(\"html/top1.htm\");\n";
    $stats.="\$tiempo=\$stat[9];\n";
    $stats.="echo '<script>CuentaAtras('.abs(\$tiempo+\$tiempoUpdate-time()).',0)</script>';\n";
    $stats.="?>\n";
    $fp=fopen("html/stats.php","w");
    flock($fp,2);
    fwrite($fp,$stats);
    fclose($fp);
}

if($modo=="rest") {
	if($compress) {
		ob_start(); 
		ob_implicit_flush(0); 
	}
    include('html/header.php');
    if($showBannerTop) readfile("html/bannertop.htm");
    echo '<BR>';
    include('html/top3.htm');
    echo '<BR>';
    if($showBannerBotton) readfile("html/bannerbotton.htm");
    include('html/footer.php');
	if($compress) GzDocOut($compress,$debug);
	exit();
}

if(file_exists("html/top1.htm")) {
    $tiempo=stat("html/top1.htm");
    if( $tiempo[9]<abs(time()-$tiempoUpdate) ) {
        //Actualiza Top
        if(filesize("data/index.dat")>10) {
			generarTOP($template);
		} else {
			$NoTop=1;
		}
    }
} else {
    if(file_exists("data/index.dat")) {
        //Actualiza el Top (generado por primera vez)
        generarTOP($template);
    } else {
        $NoTop=1;
    }
}

if($NoTop) {
    $HTML.='<table align="center" border="0" bgcolor="Black" cellspacing="1" cellpadding="10">';
    $HTML.='<caption><span class="titulo">'.$topNombre.'</span></caption>';
    $HTML.='<tr class="1">';
    $HTML.='<td align="center" valign="middle" class="texto0"><a href="members.php?modo=join&paso=1" target="_blank">'.$_Join_.'</a></td>';
    $HTML.='<td align="center" valign="middle" class="texto0"><a href="members.php?modo=modify&paso=0" target="_blank">'.$_EditSite_.'</a></td>';
    $HTML.='<td align="center" valign="middle" class="texto0"><a href="admin.php" target="_blank">'.$_Webmaster_.'</a></td>';
    $HTML.='</tr>';
    $HTML.='</table>';
    $HTML.='<br><center><span class="titulo">'.$_EmptyIndex_.'</span></center>';
    include('html/header.php');
    echo $HTML;
    include('html/footer.php');
    exit();
}

$HTML.='<table align="center" border="0" bgcolor="Black" cellspacing="1" cellpadding="10">';
$HTML.='<caption><span class="titulo">'.$topNombre.'</span></caption>';
$HTML.='<tr class="1">';
$HTML.='<td align="center" valign="middle" class="texto0"><a href="members.php?modo=join&paso=1" target="_blank">'.$_Join_.'</a></td>';
$HTML.='<td align="center" valign="middle" class="texto0"><a href="members.php?modo=modify&paso=0" target="_blank">'.$_EditSite_.'</a></td>';
$HTML.='<td align="center" valign="middle" class="texto0"><a href="admin.php" target="_blank">'.$_Webmaster_.'</a></td>';
$HTML.='</tr>';
$HTML.='</table>';

$_TimeResetUpdate_=str_replace("%%min%%",media("minutos",$tiempoUpdate,0,0),$_TimeResetUpdate_);
$_TimeResetUpdate_=str_replace("%%dias%%",media("dias",$tiempoReset,0,0),$_TimeResetUpdate_);


if($compress) {
	ob_start(); 
	ob_implicit_flush(0); 
}
include('html/header.php');
if($showBannerTop==2 OR $showBannerMiddle==2 OR $showBannerBotton==2) $autoBanner=AutoBanner(3);
if($showBannerTop==1) readfile("html/bannertop.htm");
if($showBannerTop==2) echo '<CENTER>'.$autoBanner[0].'</CENTER>';
echo '<BR>';
echo $HTML;
if($showStats) include('html/stats.php');
echo '<BR>';
include('html/top1.htm');
if(filesize('html/top2.htm')>501) {
    echo '<BR>';
   	if($showBannerMiddle==1) readfile("html/bannermiddle.htm");
   	if($showBannerMiddle==2) echo '<CENTER>'.$autoBanner[1].'</CENTER>';
    echo '<BR>';
    include('html/top2.htm');
}
if(filesize('html/top3.htm')>501) {
	echo '<br><table align="center" border="0" bgcolor="Black" cellspacing="1" cellpadding="5" width="60%"><tr class="1"><td align="center" class="texto0"><a href="index.php?modo=rest" target="_blank">'.$_Rest_.'</a></td></tr></table>';
}
echo '<BR>';
if($showBannerBotton==1) readfile("html/bannerbotton.htm");
if($showBannerBotton==2) echo '<CENTER>'.$autoBanner[2].'</CENTER>';
include('html/footer.php');
if($compress) {
	GzDocOut($compress,$performance);
}
?>