View file index.php

File size: 15.11Kb
<?php
header("Content-type:text/html; charset=utf-8");
session_start();


error_reporting(0);
include ("config.inc.php");
if (!isset($messref)) $messref=0;
function replace ($string,$id)
{
        global $exech;
        $string = " ".$string;
        if ($id=="answ")
		{
		$string = eregi_replace ("[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*","<a href=\"mailto:\\0\" class=answ>\\0</a>", $string);
        $string = eregi_replace ('([[:space:]]|\n|<br>)(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2" target="_blank" class=answ>\\2</a>', $string);
        $string = eregi_replace ('([[:space:]]|\n|<br>)(http://.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="\\2" target="_blank" class=answ>\\2</a>', $string);
		}
        else if ($id=="dark")
		{
		$string = eregi_replace ("[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*","<a href=\"mailto:\\0\" class=dark>\\0</a>", $string);
        $string = eregi_replace ('([[:space:]]|\n|<br>)(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2" target="_blank" class=dark>\\2</a>', $string);
        $string = eregi_replace ('([[:space:]]|\n|<br>)(http://.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="\\2" target="_blank" class=dark>\\2</a>', $string);
		}
		else
		{
		$string = eregi_replace ("[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*","<a href=\"mailto:\\0\">\\0</a>", $string);
        $string = eregi_replace ('([[:space:]]|\n|<br>)(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2" target="_blank">\\2</a>', $string);
        $string = eregi_replace ('([[:space:]]|\n|<br>)(http://.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="\\2" target="_blank">\\2</a>', $string);
		}
        $string = eregi_replace ('(\[img\])(http://.[-a-zA-Z0-9@:%_\+.~#?&//=]+)(\[/img\])', '<img src="\\2">', $string);
        $autochange = file ($exech);
        $lines = count ($autochange);
        for($i=0;$i<$lines;$i++)
                {
                list($change1,$change2)=explode("|", $autochange[$i]);
                $string = eregi_replace("$change1","$change2",$string);
                }
        return trim($string);
}

function replace_short ($string)
        {
        global $exech;
        $string = " ".$string;
        $autochange = file ($exech);
        $lines = count ($autochange);
        for($i=0;$i<$lines;$i++)
                {
                list($change1,$change2)=explode("|", $autochange[$i]);
                $string = eregi_replace("$change1","$change2",$string);
                }
        return trim($string);
        }

function cutty ($string)
        {
        $string = trim($string);
        $string = stripslashes($string);
		$string = str_replace ("<", "&lt;", $string);
        $string = str_replace (">", "&gt;", $string);
        $string = ereg_replace ('\\\"', "&quot;", $string);
        $string = ereg_replace ("\\\'", "&quot;", $string);
		$string = ereg_replace ("\&quot;", "&quot;", $string);
		$string = ereg_replace ("\'", "'", $string);
		$string = ereg_replace ("'", "`", $string);
        $string = str_replace ("\r", "", $string);
        $string = str_replace ("\n", "<br>", $string);
        $string = str_replace ("%", "&#37;", $string);
        $string = str_replace ("!", "&#33;", $string);
        $string = str_replace ("^ +", "", $string);
        $string = str_replace (" +$", "", $string);
        $string = str_replace ("|", "l", $string);
        return ($string);
        }

function getHTMLtags($text)
	{
	$text = str_replace("[b]","<strong>",$text);
	$text = str_replace("[/b]","</strong>",$text);
	$text = str_replace("[i]","<i>",$text);
	$text = str_replace("[/i]","</i>",$text);
	$text = str_replace("[font=red]","<font color=ff0000>",$text);
	$text = str_replace("[font=blue]","<font color=003399>",$text);
	$text = str_replace("[/font]","</font>",$text);
	return $text;
	}

function cutHTMLtags($text)
	{
	$text = str_replace("[b]","",$text);
	$text = str_replace("[/b]","",$text);
	$text = str_replace("[i]","",$text);
	$text = str_replace("[/i]","",$text);
	$text = str_replace("[font=red]","",$text);
	$text = str_replace("[font=blue]","",$text);
	$text = str_replace("[/font]","",$text);
	return $text;
	}
function mydate($date)
        {
        $min = date ($date);
        $date = getdate ($date);
        $mymon = array ("","января","февраля","марта","апреля","мая","июня","июля","августа","сентября","октября","ноября","декабря");
        $m = $date[mon];
        $myday = array( "Воскресенье","Понедельник","Вторник","Среда","Четверг","Пятница","Суббота");
        $d = $date[wday];
        $real_month = $mymon[$m];
        if ($real_month=="") $real_month="декабря";
        $date = "".$myday[$d].", $date[mday] ".$real_month.", в $date[hours]:".date("i",$min);
        return $date;
        }



function mess($name,$mess,$mail,$url,$city,$date,$answer)
        {
        global $BORDER, $DARK, $LIGHT, $ANSW, $anti_email, $PICHEIGHT, $PICWIDTH;
		if (($mail!="")&&($anti_email<>"yes"))
		{
			$mess_mail = replace($mail,"dark");
		}
		else if (($mail!="")&&($anti_email=="yes"))
		{
			list($mm2,$mm1) = explode("@", $mail);
			$mess_mail = "<img src=\"mail.php?mm1=$mm1&mm2=$mm2\" align=\"absmiddle\" border=0 /></a>";
		}
        echo "\n<table border=0 align=center cellpadding=2 cellspacing=1 width=100% bgcolor=$BORDER>\n";
        echo "<tr><td bgcolor=$DARK class=pdark colspan=2>\n";
		if($city=="") { echo "<b>$name</b></td></tr>"; }
        else { echo "<b>$name</b> ($city)</td></tr>\n"; }
        if($mail!=""&&$url!="") { echo "</tr><td bgcolor=$DARK class=pdark>Почта: $mail<br/>Сайт: $url</td></tr>\n"; }
        if($url!=""&&$mail=="") { echo "</tr><td bgcolor=$DARK class=pdark>Почта: нет<br/>Сайт: $url</td></tr>\n"; }
        if($url==""&&$mail!="") { echo "</tr><td bgcolor=$DARK class=pdark>Почта: $mail<br/>Сайт: нет</td></tr>\n"; }
        echo "</td></tr>\n";
        echo "<tr><td bgcolor=$LIGHT class=p colspan=2><div id=\"m$date\" align=justify>$mess</div></td></tr>\n";
        echo "<tr><td bgcolor=$LIGHT class=p>".mydate($date)."</td></tr>\n";
        if(!($answer=="")) {
                echo "<tr><td align=left bgcolor=$ANSW class=pansw colspan=2>";
                echo "<b>Ответ :</b> $answer";
                echo "</td></tr>\n"; }
        echo "</table>\n";
        echo "<table border=0 cellpadding=0 cellspacing=0 width=100% height=4><tr><td height=4></td></tr></table>\n";
        }


        if (getenv('HTTP_X_FORWARDED_FOR')) { $ip=getenv('HTTP_X_FORWARDED_FOR'); }
        else { $ip=getenv('REMOTE_ADDR');}

if (isset($add)):
        if ((isset($name) && $name == "") || (isset($mess) && cutHTMLtags($mess) == "")) { $error[] = "Вы заполнили не все обязательные поля."; }
        if (isset($name) && strlen($name) > $maxword) { $error[] = "Имя должно быть не длиннее $maxmail символов."; }
        if (isset($mail) && strlen($mail) > $maxmail) { $error[] = "Адрес e-mail не должен превышать $maxmail символов."; }
        if (isset($mail) && $mail != "" && !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$",$mail)) { $error[] = "Таких адресов e-mail не бывает."; }
        if (isset($url) && strlen($url) > $maxurl) { $error[] = "Адрес URL не должен превышать $maxurl символов."; }
        if (isset($city) && strlen($city) > $maxcity) { $error[] = "Название города не должно превышать $maxcity символов."; }
        if (isset($mess) && strlen($mess) > $maxlenght) { $error[] = "Сообщение не должно превышать $maxlenght символов."; }
        if (isset($mess) && eregi("[^ ]{".$maxword.",}",$mess)) { $error[] = "Слова в сообщении не должны превышать $maxword символов."; }
        $data_array = file("$data");
        $cnt = count($data_array) - 1;
        $ch_name = cutty($name);
        $ch_mess = cutty($mess);
        for ($i = $cnt; $i >= 0; $i--)
                {
                list($cname,$cmess,$cmail,$curl,$ccity,$cdate,$canswer) = explode("|", $data_array[$i]);
                $check = "$ch_name|$ch_mess";
                if($check == "$cname|$cmess") { $error[] = "Такое сообщение уже есть в базе данных."; }
                }
        $temp_string = $mess;
	while ($temp_string=strstr($temp_string,'[img]'))
	{
		eregi('(\[img\])(http://.[-a-zA-Z0-9@:%_\+.~#?&//=]+)(\[/img\])',$temp_string,$pic_array);
		$imgurl = $pic_array[2];
		$picfile = @fopen("$imgurl","r");
		if (!$picfile) { $error[] = "Не найден файл вставляемого в сообщение рисунка."; }
		else
		{
			$imagesize = GetImageSize("$imgurl");
			if (!isset($imagesize[2])) { $error[] = "Вы пытаетесь вставить рисунок недопустимого формата."; }
			else
			{
				if ($imagesize[0]>$PICWIDTH) { $error[] = "Ширина вставляемого рисунка больше максимально возможной (".$PICWIDTH." пикс.)"; }
				if ($imagesize[1]>$PICHEIGHT) { $error[] = "Высота вставляемого рисунка больше максимально возможной (".$PICHEIGHT." пикс.)"; }
			}
		}
		$cutlength = strlen($pic_array[0]);
		$temp_string = substr($temp_string,$cutlength);
	}
endif;

$banip=file("$banlist");
$banlines=count($banip);
for($i=0;$i<$banlines;$i++)
        {
        list($badip,$why,$who)=explode("|", $banip[$i]);
        if(strstr($ip,$badip))
        {
                include("$header");
                echo "<table width=100% border=0 cellspacing=0 cellpadding=0 class=p><tr><td align=center>";
                echo "<table width=100% bgcolor=$BORDER border=0 cellspacing=1 cellpadding=3 class=p><tr><td bgcolor=#FF0000 align=center style=\"color:#FFFFFF\"><b>Доступ запрещен!</b></td></tr>";
                echo "<tr><td bgcolor=$LIGHT align=center>Для Вас гостевая книга закрыта.<br>Причина: $why</td></tr></table>";
                include("$footer");
                exit;
        }
        if ((cutty($name)==cutty($who))&&(cutty($name)<>"")) { $error[] = "Вам запрещено добавлять сообщения. Причина: $why"; }
        }
//Транслит

if ($tr==5) {
$trans1= array("E","F","CH","SH","IU","IA","A","B","V","G","D","ZH","Z","I","K","L","M","N","O","R","S","T","U","H","C","Y","ch","sh","iu","ia","a","b","v","g","d","e","zh","z","i","k","l","m","n","o","p","r","s","t","u","f","h","c","'","y","J","j","P"    
                );
        
        
$trans2= array("&#x0415;","&#x0424;","&#x0427;","&#x0428;","&#x042E;","&#x042F;","&#x0410;","&#x0411;","&#x0412;","&#x0413;","&#x0414;","&#x0416;","&#x0417;","&#x0418;","&#x041A;","&#x041B;","M","&#x041D;","&#x041E;","&#x0420;","&#x0421;","&#x0422;","&#x0423;","&#x0425;","&#x0426;","&#x042B;","&#x0447;","&#x0448;","&#x044E;","&#x044F;","&#x0430;","&#x0431;","&#x0432;","&#x0433;","&#x0434;","&#x0435;","&#x0436;","&#x0437;","&#x0438;","&#x043A;","&#x043B;","&#x043C;","&#x043D;","&#x043E;","&#x043F;","&#x0440;","&#x0441;","&#x0442;","&#x0443;","&#x0444;","&#x0445;","&#x0446;","&#x044C;","&#x044B;","&#x0419;","&#x0439;","&#x041F;"
                );
$mess=str_replace($trans1,$trans2,$mess);                  
};
///////////////////////////////

if ($name != "" && $mess != "" && isset($add) && $error == "")
{
	include("write.php");
	exit;
}

include("$header");
echo "<table width=100% border=0 cellspacing=0 cellpadding=0 class=p><tr><td align=center>";

if ($name != "" && $mess != "" && isset($add) && $error == ""):
elseif (isset($error) &&  $error != ""):
        echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\" bgcolor=\"$BORDER\">";
        echo "<tr><td align=\"center\" class=\"error\" bgcolor=\"#FF0000\"><b>Ошибка!</b></td></tr>";
        echo "<tr><td align=\"left\" class=\"p\" bgcolor=\"$LIGHT\">";
        foreach ($error as $value)
                {
                echo "<li>$value<br>";
                }
        echo "</td></tr>";
        echo "</table>";
        echo "<table border=0 cellpadding=0 cellspacing=0 width=100% height=4><tr><td height=4></td></tr></table>";
endif;

if (!eregi("\%", $TABWIDTH)) $SENDWIDTH = $TABWIDTH-300;
else $SENDWIDTH = 300;

$file_array = file("$data");
$lines = count($file_array);

if (!isset($page)) { $page = 1; }

function getPages($total, $page, $link, $perpage)
        {
        $mpp = $perpage;
        $prev_page = $page - 1;
        $next_page = $page + 1;
        if ($total <= $mpp) $pages = 1;
        elseif($total % $mpp == 0) $pages = $total / $mpp;
        else $pages = $total / $mpp + 1;
        $pages = (int) $pages;
        $s_pages    = $page<7 ? 1 : floor($page / 7) * 7;
        $e_pages    = $page + 6;
        if ($e_pages > $pages) { $e_pages = $pages; }
        $s = "";
        if ($pages > 6){
        if($prev_page != 0) { $s = "<a href=\"".$link."page=1\" class=\"mid\"> &lt;&lt; </a>| \n"; }
        if($prev_page) { $s .= "<a href=\"".$link."page=$prev_page\" class=\"mid\"> &lt; </a>| \n"; }}
        for($i=$s_pages;$i<=$e_pages;$i++)
                {
                if ($i != $page) { $s .= "<a href=\"".$link."page=$i\" class=\"mid\"> $i </a>| \n"; }
                elseif ($i != 1) { $s .= " <b> $i |</b> "; }
                elseif ($page != $pages) { $s .= " <b> 1 |</b> "; }
                }
        if($page != $pages && $pages > 6)
                {
                $s .= "<a href=\"".$link."page=$next_page\" class=\"mid\"> &gt; </a>| \n";
                $s .= "<a href=\"".$link."page=$pages\" class=\"mid\"> &gt;&gt; </a>| \n";
                }
        if (!isset($s) || $s == "") { $s = " <b> 1 |</b> "; }
        return $s;
        }
$print_pages = getPages($lines, $page, "$PHP_SELF?", $maxmess);


$from = $lines - ($page * $maxmess - 1);
$to = $lines - (($page - 1) * $maxmess);
if($from < 0) { $from = 1; }

for($i = $to - 1; $i >= $from - 1; $i--)
        {
        list($name,$mess,$mail,$url,$city,$date,$answer) = explode("|", $file_array[$i]);
        if(!($name==""&&$mess=="")):
                $name = replace_short($name);
                $mess = replace($mess,"light");
				$mess = getHTMLtags($mess);
                $url = replace($url,"dark");
                $city = replace_short($city);
                $answer = replace($answer,"answ");
                mess($name,$mess,$mail,$url,$city,$date,$answer);
        endif;
        }
echo "<table bgcolor=$BORDER border=0 cellpadding=2 cellspacing=1 width=100%><tr><td bgcolor=$LIGHT class=pmid><b>Всего сообщений : $lines</b></td></tr><tr><td bgcolor=$LIGHT class=pmid><b>Страницы : |$print_pages</b></td></tr></table>";
echo "<table border=0 cellpadding=0 cellspacing=0 width=100% height=4><tr><td height=4></td></tr></table>";

include("$footer");
?>