View file new/komments/add.php

File size: 2.56Kb
<?
error_reporting(0);
include'../../style/head.php';
$id=$_GET['id'];
$kom=$_GET['kom'];
function countfiles($dir){$d=opendir($dir);
$c=0;
while($str=readdir($d)){
if($str{0}!='.'){
if(is_dir($dir.$str)) $c+=countfiles($dir.$str.'/'); else $c++;
} } return (int)$c;
}
$f=countfiles('../zap');
$save=$f-1 ;

if ($kom<$save){echo'<div class="f1">Вы не можете добавлять комментарии к старым новостям!</div>';}
if ($kom==$save){
if($id=='add')
{

$novost=$_POST['new'];
$name=$_POST['name'];
{
$kom=$_GET['kom'];
$novost=$_POST['new'];
$name=$_POST['name'];
$novost = substr($novost, 0 , 300);
$name = substr($name, 0, 20);

$name = str_replace("/","",$name);
$name = str_replace(".","",$name);
$name = str_replace("`","",$name);
$name = str_replace("<","",$name);
$name = str_replace(">","",$name);

$name = str_replace("=","",$name);
$name = str_replace(":","",$name);
$name = str_replace("http://","",$name);
$novost = str_replace("/","",$novost);
$novost = str_replace("http://","",$novost);
$novost = str_replace("img","",$novost);
$novost = str_replace("script","",$novost);
$novost = str_replace("`","",$novost);
$novost = str_replace("<","",$novost);
$novost = str_replace(">","",$novost);

$novost = str_replace("=","",$novost);
$novost = str_replace("
","<br>",$novost);
$countfiles=count(glob("data/$kom/*.dat"));
$f_name=$countfiles++;
$date=date("H:i d.m.y",time());
if (trim($name) == "")
{echo '<div class=news>Не все формы заполнены! Повторите.<br><a href="add.php?kom='.$kom.'">Повторить</a></div>';
exit();}
if (trim($novost) == "")
{echo '<div class=news>Не все формы заполнены! Повторите.<br><a href="add.php?kom='.$kom.'">Повторить</a></div>';
exit();}
$open=fopen("data/$kom/$f_name.dat", "w");
fwrite($open,"$date:::::$name:::::$novost");
fclose($open);
echo'<div class="f1">Комментарий добавлен.</div>';
}}
else
{
echo'Добавление комментария<br>
Введите имя: <form action="?id=add&kom='.$kom.'" method="post"><textarea cols=20 rows=1 name="name"></textarea><br>Введите комментарий: <form action="?id=add&kom='.$kom.'" method="post"><textarea cols=20 rows=3 name="new"></textarea><br><input type="submit" value="Добавить"></form>';
}
}
echo'
<br><a href="index.php?kom='.$kom.'">Назад</a><br/>
<a href="../index.php">К новостям</a><br/>
<a href="../../">На главную</a><br/>
'; include"../../style/foot.php"; ?>