|
//date ip name e-mail web comments
$gfile = "comments.txt";
$step = 5;
$prev=1; //link to previous
$next=1; //link to next
$ilast=0; //last item
if ($offset == "") {$offset=0;}
if ($offset < 0) {$offset=0;}
//печать комментариев
if ($addcmnt == "") {
if ($name != "" and $urlcom != "")
{
//добавить комментарии в файл
$email = ereg_replace("\n", "", $email);
$email = htmlspecialchars($email);
$name = ereg_replace("\n", "", $name);
$name = htmlspecialchars($name);
$urlcom = chop($urlcom);
$urlcom = htmlspecialchars($urlcom);
$urlcom = ereg_replace("\x0d", "", $urlcom);
$urlcom = ereg_replace("\n", " ", $urlcom);
$xwb11 = ereg_replace("\n", "", $xwb11);
$xwb11 = htmlspecialchars($xwb11);
//Чтение из файла старых записей, если нету файла, то создаём файл
if (file_exists($gfile)) {
$read_old = fopen($gfile, "r");
$old = fread($read_old, filesize($gfile));
fclose($read_old);
}
else {
$read_old = fopen($gfile, "w");
$old = "";
fclose($read_old);
}
// Настройка даты
$date = date("j.m.Y H:i");
// Вычисление есть ли ip проходимый через cache, если нет, то просто ip
if ($HTTP_X_FORWARDED_FOR=="") {
$ip = $REMOTE_ADDR;
} else {
$ip = $HTTP_X_FORWARDED_FOR;
}
//Макс. длина строки - 1000
$urlcom=substr($urlcom,0,1000);
// Устанавливаем вид записи в базу данных
$text = "$date\t$ip\t$name\t$email\t$xwb11\t$urlcom\n";
$text .= "$old";
$fal=1;
$lcom=strtolower($urlcom);
$lweb=strtolower($xwb11);
if (strpos($lcom,"sharedance")!==false) {$fal=0;}
if (strpos($lweb,"sharedance")!==false) {$fal=0;}
if (strpos($lcom,"href=http")!==false) {$fal=0;}
if (strpos($lcom,"[url")!==false) {$fal=0;}
if (strpos($lcom,"http")!==false) {$fal=0;}
if (strpos($xwb11,"http")!==false) {$fal=0;}
//сохранить текст
if ($fal==1)
{
$fp = fopen($gfile, "w");
flock($fp, 2);
fputs($fp, $text);
flock($fp, 3);
fclose($fp);
}
$offset=0;
}
//вывод комментариев
if ($offset==0) $prev=0;
$file = @file($gfile);
if ($offset>count($file)-1) {$offset=count($file)-1;}
echo "Ballroom music guestbook\n";
echo "\n";
for ($i=0; $i$offset+$step-1) {break;}
$ilast=$i;
// Разделяем строку на столбцы
$row = explode("\t",$file[$i]);
list($cdate, $cip, $cname, $cemail, $cweb, $ccomments) = $row;
// Если в строке email нету @, то не выводим емайл
if (eregi("@", $cemail)) {
$cemail = "$cname";
} else {
$cemail = $cname;
}
if (substr(trim(strtolower($cweb)), 0, 7) != "http://" and $cweb != "") {
$cweb = "http://$cweb";
}
else if (substr(trim(strtolower($cweb)), 0, 7) == "http://") {
$xwb11a = "$cweb";
}
echo "| $cdate | Comment by: $cemail | Web: $cweb | | $ccomments | ";
}
if ($ilast==count($file)-1) {$next=0;}
echo " ";
}
else
{
echo "Next >> | |