<?php
##############################################################################
## ##
## P C M S ##
## Движок на файлах ##
## Скрипт распространяется бесплатно! ##
## Запрещается продавать его и вносить изменения в код! ##
## ##
## Автор скрипта: Proton (http://wap-svoboda.com ##
## Создан в ноябре 2009 года. ##
## ##
##############################################################################
$path=$_SERVER['DOCUMENT_ROOT'];
include $path.'/config.php';
include $path.'/functions.php';
$act=@$_GET['act']?htmlspecialchars($_GET['act']):'';
if (empty($act)) {
################################################################################
///////////////////////////////////Мини форум///////////////////////////////////
################################################################################
echo head_tags('Мини форум').'
<div class="t1">
<div class="t2">
<div class="t3">
';
$page=@$_GET['page']?htmlspecialchars($_GET['page']):1;
$count=0;
if ($file=@file($path.'/data/mini_forum/base.dat')) {
$count=count($file);
$file=array_reverse($file);
$obsum=$page*7;
$nasum=$obsum-7;
for($i=$nasum;$i<$obsum;$i++) {
if (!empty($file[$i])) {
// начало строк
echo '<div class="bg2">
<div class="cs">
';
$str=trim($file[$i]);
$array=explode('||',$str);
$id_user=$array[0];
$user=search_user($id_user);
$topic_id=$array[1];
$time_topic=$array[1];
$time=date("H:i d/m/y",$array[1]);
$id_mess=$i+1;
$topic=trim(stripslashes($array[2]));
$topic=htmlspecialchars($topic);
$file_topic=@file($path.'/data/mini_forum/'.$topic_id.'.dat');
$count_mess=count($file_topic);
$page_nav=ceil($count_mess/7);
echo '<a href="/user.php?user='.$id_user.'"><b>'.$user.'</b></a> '.online_tag($id_user).'';
if ($status=='Admin') {
echo ' (<a href="mini_forum.php?act=topic_set&topic_id='.$id_mess.'">?</a>)';
}
echo '<br />
<b>'.$time.'</b><br />
'.$topic.'<br />
» <a href="mini_forum.php?act=viewtopic&topic_id='.$time_topic.'">Сообщения</a> <a href="mini_forum.php?act=viewtopic&topic_id='.$time_topic.'&page='.$page_nav.'">('.$count_mess.')</a><br />
';
// Конец строк
echo '<div class="line"></div>
</div></div>
';
}}
echo '</div>
</div>
</div>
<div class="t1">
<div class="t2">
<div class="t3">
<div class="t4">
<div class="tcs">
<div class="bg3">
';
$page_nav=ceil($count/7);
if ($page<=$page_nav and $page_nav>1) {
echo 'Страницы: ';
$pages=3;
$link=0;
$link2=0;
if ($page>($page_nav-$pages)) {
$link2=$page_nav-$page;
$link2=$pages-$link2;
}
if ($page>($pages+1) and $page_nav>7) {
echo '<a href="mini_forum.php?page=1">1</a> ';
}
if (($page-$pages)>2 and $page_nav>8) {
echo ' ... ';
}
for ($i=(($page-$pages)-$link2); $i<$page; $i++) {
if ($i>0) {
echo '<a href="mini_forum.php?page='.$i.'">'.$i.'</a> ';
$link++;
}}
$link=$pages-$link;
echo '<b>'.$page.'</b> ';
for ($i=($page+1); $i<((($page+$pages)+1)+$link); $i++) {
if ($i<=$page_nav) {
echo '<a href="mini_forum.php?page='.$i.'">'.$i.'</a> ';
}}
if (($page+$pages)<($page_nav-1) and $page_nav>8) {
echo ' ... ';
}
if ($page<($page_nav-$pages) and $page_nav>7) {
echo '<a href="mini_forum.php?page='.$page_nav.'">'.$page_nav.'</a>';
}
echo '<br />
';
}} else {
echo '<div class="bg2">
<div class="cs">
Тем нет!<br />
</div>
</div>
</div>
</div>
</div>
<div class="t1">
<div class="t2">
<div class="t3">
<div class="t4">
<div class="tcs">
<div class="bg3">
';
}
if (!empty($status)) {
echo '<a href="mini_forum.php?act=new_topic">Создать тему</a><br />
';
}
echo '<a href="/">Главная</a><br />
</div>
</div>
</div>
</div>
</div>
</div>
'.foot_tags($timestart);
} else if ($act=="new_topic") {
################################################################################
//////////////////////////////////Создаем тему//////////////////////////////////
################################################################################
if (!empty($status)) {
if (empty($_POST['submit'])) {
echo head_tags('Форма ввода').'
<div class="t1">
<div class="t2">
<div class="t3">
<div class="tcs">
<div class="t2">
<div class="bg1">
<form action="mini_forum.php?act=new_topic" method="post">
Тема:<br />
<input type="text" name="topic" /><br />
Текст сообщения:<br />
<textarea cols="25" rows="3" name="mess"></textarea><br />
<input type="submit" value="Создать" name="submit" />
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="t1">
<div class="t2">
<div class="t3">
<div class="t4">
<div class="tcs">
<div class="bg3">
<a href="mini_forum.php?">Темы</a><br />
<a href="/">Главная</a><br />
</div>
</div>
</div>
</div>
</div>
</div>
'.foot_tags($timestart);
} else {
if (!empty($_POST['mess']) and !empty($_POST['topic'])) {
$topic=stripslashes(trim($_POST['topic']));
$topic=substr($topic,0,200);
$topic=str_replace(array("\r\n","\n","
","\r"),"[br/]",$topic);
$topic=str_replace('||','II',$topic);
$mess=stripslashes(trim($_POST['mess']));
$mess=substr($mess,0,1500);
$mess=str_replace(array("\r\n","\n","
","\r"),"[br/]",$mess);
$mess=str_replace('||','II',$mess);
if ($file=@file($path.'/data/mini_forum/base.dat')) {
$count=count($file);
/*
if ($count>250) {
unset($file[0]);
@file_put_contents($path.'/data/mini_forum/base.dat',$file);
}
*/
$file=array_reverse($file);
for($i=0;$i<3;$i++) {
if (!empty($file[$i])) {
$str=trim($file[$i]);
$array=explode('||',$str);
$check_mess=$array[2];
if ($topic==$check_mess) {
echo head_tags('Ошибка записи').'
<div class="t1">
<div class="t2">
<div class="t3">
<div class="bg2">
<div class="cs">
Вы пишете предыдущее сообщение!<br />
</div>
</div>
</div>
</div>
</div>
<div class="t1">
<div class="t2">
<div class="t3">
<div class="t4">
<div class="tcs">
<div class="bg3">
<a href="mini_forum.php?">Темы</a><br />
<a href="/">Главная</a><br />
</div>
</div>
</div>
</div>
</div>
</div>
'.foot_tags($timestart); exit;
}}}}
if ($fopen=fopen($path.'/data/mini_forum/base.dat','a')) {
fputs($fopen,"$id||$time||$topic\r\n");
fclose($fopen);
$_SESSION['text']='Тема успешно создана!<br />';
$messages=@file_get_contents($path.'/data/mini_forum/base_count.dat')+1;
@file_put_contents($path.'/data/mini_forum/base_count.dat',$messages);
$fopen=fopen($path.'/data/mini_forum/'.$time.'.dat','a');
fputs($fopen,"$id||$time||$mess||$topic\r\n");
fclose($fopen);
$messages=@file_get_contents($path.'/data/mini_forum/topic_count.dat')+1;
@file_put_contents($path.'/data/mini_forum/topic_count.dat',$messages);
}}
header("location: mini_forum.php?act=&rand=".rand(1111,9999)."&".SID); exit;
}}} else if ($act=="topic_set") {
################################################################################
////////////////////////////////Редактор темы///////////////////////////////////
################################################################################
if ($status=='Admin') {
$topic_id=htmlspecialchars($_GET['topic_id']);
if (empty($_POST['topic'])) {
$file=@file($path.'/data/mini_forum/base.dat');
$file=array_reverse($file);
$str=trim($file[$topic_id-1]);
$array=explode('||',$str);
$topic=htmlspecialchars($array[2]);
$topic=str_replace('[br/]',"\r\n",$topic);
echo head_tags('Редактор').'
<div class="t1">
<div class="t2">
<div class="t3">
<div class="tcs">
<div class="t2">
<div class="bg1">
<form action="mini_forum.php?act=topic_set&topic_id='.$topic_id.'" method="post">
Тема:<br />
<input type="text" name="topic" value="'.$topic.'" /><br />
<input type="submit" value="Изменить" />
<input type="submit" name="del" value="Удалить" />
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="t1">
<div class="t2">
<div class="t3">
<div class="t4">
<div class="tcs">
<div class="bg3">
<a href="mini_forum.php?">Темы</a><br />
<a href="/">Главная</a><br />
</div>
</div>
</div>
</div>
</div>
</div>
'.foot_tags($timestart);
} elseif (empty($_POST['del'])) {
$file=@file($path.'/data/mini_forum/base.dat');
$file=array_reverse($file);
$str=trim($file[$topic_id-1]);
$array=explode('||',$str);
$id_user=$array[0];
$time=$array[1];
$topic=stripslashes(trim($_POST['topic']));
$topic=substr($topic,0,1500);
$topic=str_replace(array("\r\n","\n","
","\r"),"[br/]",$topic);
$topic=str_replace('||','II',$topic);
$file[$topic_id-1]="$id_user||$time||$topic\r\n";
$file=array_reverse($file);
if (@file_put_contents($path.'/data/mini_forum/base.dat',$file)) {
$file=@file($path.'/data/mini_forum/'.$time.'.dat');
$count=count($file);
$id_mess=0;
$str=trim($file[$id_mess]);
$array=explode('||',$str);
$id_user=$array[0];
$time=$array[1];
$mess=$array[2];
$file[$id_mess]="$id_user||$time||$mess||$topic\r\n";
@file_put_contents($path.'/data/mini_forum/'.$time.'.dat',$file);
$_SESSION['text']='Тема изменена!<br />';
}
header("location: mini_forum.php?act=&rand=".rand(1111,9999)."&".SID); exit;
} else {
$file=@file($path.'/data/mini_forum/base.dat');
$file=array_reverse($file);
$str=trim($file[$topic_id-1]);
$array=explode('||',$str);
$time_topic=$array[1];
$count=count(file($path.'/data/mini_forum/'.$time_topic.'.dat'));
unset($file[$topic_id-1]);
@unlink($path.'/data/mini_forum/'.$time_topic.'.dat');
$file=array_reverse($file);
@file_put_contents($path.'/data/mini_forum/base.dat',$file);
$messages=@file_get_contents($path.'/data/mini_forum/base_count.dat')-1;
@file_put_contents($path.'/data/mini_forum/base_count.dat',$messages);
$messages=@file_get_contents($path.'/data/mini_forum/topic_count.dat')-$count;
@file_put_contents($path.'/data/mini_forum/topic_count.dat',$messages);
$_SESSION['text']='Тема удалена!<br />';
header("location: mini_forum.php?act=&rand=".rand(1111,9999)."&".SID); exit;
}}} else if ($act=='viewtopic') {
################################################################################
/////////////////////////////////////Темы///////////////////////////////////////
################################################################################
$topic_id=htmlspecialchars($_GET['topic_id']);
$file=@file($path.'/data/mini_forum/'.$topic_id.'.dat');
$str=trim($file[0]);
$array=explode('||',$str);
$topic_name=@$array[3];
$topic_name=iconv('utf-8','windows-1251',$topic_name);
if (strlen($topic_name)>=30){
$topic_name=substr($topic_name,0,30).'...';
}
$topic_name=iconv('windows-1251','utf-8',$topic_name);
//echo $time_topic;
if (!file_exists($path.'/data/mini_forum/'.$topic_id.'.dat')) { exit; }
echo head_tags($topic_name).'
<div class="t1">
<div class="t2">
<div class="t3">
';
if (!empty($status)) {
echo '<div class="tcs">
<div class="t2">
<div class="bg1">
<form action="mini_forum.php?act=new_mess&topic_id='.$topic_id.'" method="post">
Сообщение:<br />
<textarea name="mess" nums="47" rows="3"></textarea><br />
<input type="submit" value="Добавить / Обновить" name="submit" /></form>
</div></div></div>
';
}
$page=@$_GET['page']?htmlspecialchars($_GET['page']):1;
$count_mess=0;
if ($file=@file($path.'/data/mini_forum/'.$topic_id.'.dat')) {
$count_mess=$count=count($file);
$obsum=$page*7;
$nasum=$obsum-7;
for($i=$nasum;$i<$obsum;$i++) {
if (!empty($file[$i])) {
// начало строк
echo '<div class="bg2">
<div class="cs">
';
$str=trim($file[$i]);
$array=explode('||',$str);
$id_user=$array[0];
$user=search_user($id_user);
$time=date("H:i d/m/y",$array[1]);
$id_mess=$i+1;
$mess=trim(stripslashes($array[2]));
$mess=htmlspecialchars($mess);
$mess=str_replace('[br/]',"<br />\r\n",$mess);
$mess=smile($mess);
$mess=preg_replace('|http://([0-9a-z\-\.\?\/\=\+\_\&\;\:\%\#\-\)\(\!\,\]\[\~]+)|i','<a href="http://$1">http://$1</a>',$mess);
echo '<a href="/user.php?user='.$id_user.'"><b>'.$user.'</b></a> '.online_tag($id_user).'';
if ($status=='Admin') {
echo ' (<a href="mini_forum.php?act=set_mess&id_mess='.$id_mess.'&topic_id='.$topic_id.'">?</a>)';
}
echo '<br />
<b>'.$time.'</b><br />
'.$mess.'<br />
';
// Конец строк
echo '<div class="line"></div>
</div></div>
';
}}
echo '</div>
</div>
</div>
<div class="t1">
<div class="t2">
<div class="t3">
<div class="t4">
<div class="tcs">
<div class="bg3">
';
$page_nav=ceil($count_mess/7);
if ($page<=$page_nav and $page_nav>1) {
echo 'Страницы: ';
$pages=3;
$link=0;
$link2=0;
if ($page>($page_nav-$pages)) {
$link2=$page_nav-$page;
$link2=$pages-$link2;
}
if ($page>($pages+1) and $page_nav>7) {
echo '<a href="mini_forum.php?page=1&act='.$act.'&topic_id='.$topic_id.'">1</a> ';
}
if (($page-$pages)>2 and $page_nav>8) {
echo ' ... ';
}
for ($i=(($page-$pages)-$link2); $i<$page; $i++) {
if ($i>0) {
echo '<a href="mini_forum.php?page='.$i.'&act='.$act.'&topic_id='.$topic_id.'">'.$i.'</a> ';
$link++;
}}
$link=$pages-$link;
echo '<b>'.$page.'</b> ';
for ($i=($page+1); $i<((($page+$pages)+1)+$link); $i++) {
if ($i<=$page_nav) {
echo '<a href="mini_forum.php?page='.$i.'&act='.$act.'&topic_id='.$topic_id.'">'.$i.'</a> ';
}}
if (($page+$pages)<($page_nav-1) and $page_nav>8) {
echo ' ... ';
}
if ($page<($page_nav-$pages) and $page_nav>7) {
echo '<a href="mini_forum.php?page='.$page_nav.'&act='.$act.'&topic_id='.$topic_id.'">'.$page_nav.'</a>';
}
echo '<br />
';
}} else {
echo '<div class="bg2">
<div class="cs">
Сообщений нет!<br />
</div>
</div>
</div>
</div>
</div>
<div class="t1">
<div class="t2">
<div class="t3">
<div class="t4">
<div class="tcs">
<div class="bg3">
';
}
echo '<a href="mini_forum.php">Темы</a><br />
<a href="/">Главная</a><br />
</div>
</div>
</div>
</div>
</div>
</div>
'.foot_tags($timestart);
} else if ($act=="new_mess") {
################################################################################
////////////////////////////////Создаем Сообщение///////////////////////////////
################################################################################
if (!empty($status)) {
$topic_id=htmlspecialchars($_GET['topic_id']);
if (!file_exists($path.'/data/mini_forum/'.$topic_id.'.dat')) { exit; }
$file=@file($path.'/data/mini_forum/'.$topic_id.'.dat');
$count=count($file);
$page_nav=ceil($count/7);
if (!empty($_POST['submit'])) {
if (!empty($_POST['mess'])) {
$mess=stripslashes(trim($_POST['mess']));
$mess=substr($mess,0,1500);
$mess=str_replace(array("\r\n","\n","
","\r"),"[br/]",$mess);
$mess=str_replace('||','II',$mess);
/*
if ($count>24) {
unset($file[0]);
@file_put_contents($path.'/data/mini_chat.dat',$file);
}
*/
$file=array_reverse($file);
for($i=0;$i<3;$i++) {
if (!empty($file[$i])) {
$str=trim($file[$i]);
$array=explode('||',$str);
$check_mess=$array[2];
if ($mess==$check_mess) {
echo head_tags('Ошибка записи').'
<div class="t1">
<div class="t2">
<div class="t3">
<div class="bg2">
<div class="cs">
Вы пишете предыдущее сообщение!<br />
</div>
</div>
</div>
</div>
</div>
<div class="t1">
<div class="t2">
<div class="t3">
<div class="t4">
<div class="tcs">
<div class="bg3">
<a href="mini_forum.php?act=viewtopic&topic_id='.$topic_id.'&page='.$page_nav.'">Сообщения</a><br />
<a href="mini_forum.php?">Темы</a><br />
<a href="/">Главная</a><br />
</div>
</div>
</div>
</div>
</div>
</div>
'.foot_tags($timestart); exit;
}}}
if ($fopen=fopen($path.'/data/mini_forum/'.$topic_id.'.dat','a')) {
fputs($fopen,"$id||$time||$mess\r\n");
fclose($fopen);
$_SESSION['text']='Сообщение успешно добавлено!<br />';
$messages=@file_get_contents($path.'/data/mini_forum/topic_count.dat')+1;
@file_put_contents($path.'/data/mini_forum/topic_count.dat',$messages);
$file=@file($path.'/data/mini_forum/'.$topic_id.'.dat');
$count=count($file);
$page_nav=ceil($count/7);
}}
header("location: mini_forum.php?act=viewtopic&topic_id=$topic_id&page=$page_nav&rand=".rand(1111,9999)."&".SID); exit;
}}} else if ($act=="set_mess") {
################################################################################
///////////////////////////////////Редактор/////////////////////////////////////
################################################################################
if ($status=='Admin') {
$id_mess=htmlspecialchars($_GET['id_mess']);
$topic_id=htmlspecialchars($_GET['topic_id']);
if (!file_exists($path.'/data/mini_forum/'.$topic_id.'.dat')) { exit; }
if (empty($_POST['mess'])) {
$file=@file($path.'/data/mini_forum/'.$topic_id.'.dat');
$count=count($file);
$page_nav=ceil($count/7);
$str=trim($file[$id_mess-1]);
$array=explode('||',$str);
$mess=htmlspecialchars($array[2]);
$mess=str_replace('[br/]',"\r\n",$mess);
echo head_tags('Редактор').'
<div class="t1">
<div class="t2">
<div class="t3">
<div class="tcs">
<div class="t2">
<div class="bg1">
<form action="mini_forum.php?act=set_mess&topic_id='.$topic_id.'&id_mess='.$id_mess.'" method="post">
Текст сообщения:<br />
<textarea cols="25" rows="5" name="mess">'.$mess.'</textarea><br />
<input type="submit" value="Изменить" />
<input type="submit" name="del" value="Удалить" />
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="t1">
<div class="t2">
<div class="t3">
<div class="t4">
<div class="tcs">
<div class="bg3">
<a href="mini_forum.php?act=viewtopic&topic_id='.$topic_id.'&page='.$page_nav.'">Сообщения</a><br />
<a href="mini_forum.php?">Темы</a><br />
<a href="/">Главная</a><br />
</div>
</div>
</div>
</div>
</div>
</div>
'.foot_tags($timestart);
} elseif (empty($_POST['del'])) {
$file=@file($path.'/data/mini_forum/'.$topic_id.'.dat');
$count=count($file);
$page_nav=ceil($count/7);
$id_mess=$_GET['id_mess'];
$str=trim($file[$id_mess-1]);
$array=explode('||',$str);
$id_user=$array[0];
$time=$array[1];
$topic=@$array[3];
$mess=stripslashes(trim($_POST['mess']));
$mess=substr($mess,0,1500);
$mess=str_replace(array("\r\n","\n","
","\r"),"[br/]",$mess);
$mess=str_replace('||','II',$mess);
$file[$id_mess-1]="$id_user||$time||$mess||$topic\r\n";
if (@file_put_contents($path.'/data/mini_forum/'.$topic_id.'.dat',$file)) {
$_SESSION['text']='Сообщение исправлено!<br />';
}
header("location: mini_forum.php?act=viewtopic&topic_id=$topic_id&page=$page_nav&rand=".rand(1111,9999)."&".SID); exit;
} else {
$id_mess=$_GET['id_mess'];
if ($id_mess>1) {
$file=@file($path.'/data/mini_forum/'.$topic_id.'.dat');
unset($file[$id_mess-1]);
@file_put_contents($path.'/data/mini_forum/'.$topic_id.'.dat',$file);
$messages=@file_get_contents($path.'/data/mini_forum/topic_count.dat')-1;
@file_put_contents($path.'/data/mini_forum/topic_count.dat',$messages);
$_SESSION['text']='Сообщение удалено!<br />';
} else {
$_SESSION['text']='Вы не можете удалить первое сообщение!<br />';
}
$file=@file($path.'/data/mini_forum/'.$topic_id.'.dat');
$count=count($file);
$page_nav=ceil($count/7);
header("location: mini_forum.php?act=viewtopic&topic_id=$topic_id&page=$page_nav&rand=".rand(1111,9999)."&".SID); exit;
}}}
?>