Файл: modules/chat/index.php
Строк: 56
<?php
/**
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) 2013, Taras Chornyi, Sergiy Mazurenko, Ivan Kotliar
* @link http://perf-engine.net
* @package PerfEngine
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
$locate = 'in_chat';
if(isset($_GET['write']))
{
$text = substr(input($_POST['text']), 0, 2000);
if(!empty($text) && antiflood('chat', 'text', $text) == false)
{
$db->query("INSERT INTO `chat` SET `text` = '$text', `time` = '". time() ."', `user_id` = '". User::Id() ."'");
// print_r($db->errorInfo());
redirect('/chat?'.rand(1, 9999));
}
}
elseif(isset($_GET['clear']) && User::level() >= 5)
{
$db->query("TRUNCATE TABLE `chat`");
redirect('/chat?'.rand(1, 9999));
}
elseif(isset($_GET['delete']) && User::level() >= 4)
{
$pid = num($_GET['delete']);
$db->query('DELETE FROM `chat` WHERE `id` = "'.$pid.'" LIMIT 1');
redirect('/chat?'.rand(1, 9999));
}
$title = _t('chat');
include_header($title);
$tpl->div('title', _t('chat'));
echo '<div class="menu">
<form action="/chat?write" method="post">';
textarea(2, '', (isset($_GET['reply']) ? '[b]'.tnick(input($_GET['reply'])).'[/b], ' : null));
echo (User::logged() ? '<br/><input type="submit" value="'._t('send').'" /> ' : false).'[<a href="/chat?'.rand(1, 9999).'">'._t('refresh').'</a>]
</form></div>';
$chat_r = $db->query("SELECT * FROM `chat`")->rowCount();
$pages = new Paginator($chat_r, $ames);
if($chat_r == 0)
{
$tpl->div('menu', _t('no_posts'));
}
else
{
$chats = $db->query("SELECT * FROM `chat` ORDER BY time DESC LIMIT $start, $ames");
foreach($chats as $chat)
{
$tpl->div('post', (User::level() >= 4 ? '<span style="float:right;">[<a href="/chat?delete='.$chat['id'].'">x</a>]</span>' : null).'
'.(User::Id() != $chat['user_id'] ? '<span style="float: right;">[<a href="/chat?reply='.$chat['user_id'].'">'._t('reply').'</a>]</span>' : null). nick($chat['user_id'], rtime($chat['time'])).'
'.output($chat['text']));
}
$pages->view('&');
}
$add_room = (User::logged() && $user['level'] >= 4 ? NAV .'<a href="/chat?clear">'. _t('clear') .'</a><br/>' : NULL);
$tpl->div('block', $add_room . HICO .'<a href="/">'. _t('home').'</a>');
include_footer();
?>