Файл: modules/forum/add_post.php
Строк: 120
<?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_forum';
if(!User::logged() || !isset($_GET['id']) || $db->query("SELECT * FROM `forum_t` WHERE `id` = '". abs(intval($_GET['id'])) ."'")->rowCount() == 0)
{
redirect('/');
}
$topic_id = abs(intval($_GET['id']));
if($db->query("SELECT `closed` FROM `forum_t` WHERE `id` = '". $topic_id ."'")->fetchColumn() != 0)
{
redirect('/forum/topic/'.$topic_id);
}
if(isset($_POST['create']) && $_GET['act'] == 'create')
{
$text = mb_substr(input($_POST['text']), 0, 10000);
if(!empty($text) && antiflood('forum_pt', 'text', $text) == false)
{
$db->query("INSERT INTO `forum_pt` SET `text` = '".$text."', `time` = '". time() ."', `user_id` = '".User::Id()."', `topic_id` = '".$topic_id."', `file` = '', `file_size` = '0', `edit_time` = '0', `edit_user_id` = '0', `count_edit` = '0', `cat_id` = '0', `name` = ''");
// print_r($db->errorInfo());
$lastPostId = $db->lastInsertId();
if(isset($_GET['reply_to']))
{
$_user_id = num($_GET['reply_to']);
if($_user_id !== User::Id())
{
$db->query("INSERT INTO `notify` SET `user_id` = '". $_user_id ."', `from_id` = '". User::Id() ."', `request_id` = '/forum/topic/".$topic_id."?page=end', `type` = 'notify_topic_reply', `read` = '0', `time` = '". time() ."'");
// print_r($db->errorInfo());
}
}
elseif(isset($_GET['quote']))
{
$_user_id = $db->query("SELECT user_id FROM `forum_pt` WHERE `topic_id` = '{$topic_id}' AND `id` = '". abs(intval($_GET['quote'])) ."'")->fetchColumn();
if($_user_id !== User::Id())
{
$db->query("INSERT INTO `notify` SET `user_id` = '". $_user_id ."', `from_id` = '". User::Id() ."', `request_id` = '/forum/topic/".$topic_id."?page=end', `type` = 'notify_topic_reply', `read` = '0', `time` = '". time() ."'");
// print_r($db->errorInfo());
}
}
$db->query("UPDATE `forum_t` SET `time_last_post` = '". time() ."', `user_last_post` = '". User::Id() ."' WHERE `id` = '".$topic_id."'");
$db->query("UPDATE `users` SET `balance` = '".(User::profile('balance')+1)."' WHERE `id` = '". User::Id() ."'");
$file_dir = ROOT .'/files/forum/';
if (isset($_FILES['file']) && $_FILES['file']['tmp_name'])
{
$patch = pathinfo($_FILES['file']['name']);
$extension = strtolower($patch['extension']);
if (!in_array($extension, explode(';', $system['files_types']))) $err = 'File extention not allowed.<br />';
$name_start = input(cyrlat($patch['filename']));
$name_end = mb_convert_encoding($name_start, "UTF-8");
$name = $name_end.'_'.substr(md5(time().$name_end), 0, 8).'.'. $extension;
if (file_exists($file_dir . $name)) $err = 'This file exists';
if(!isset($err))
{
move_uploaded_file($_FILES['file']['tmp_name'], $file_dir . $name);
$db->query("UPDATE `forum_pt` SET `file` = '". input($name) ."', `file_size` = '". $_FILES['file']['size'] ."' WHERE `id` = '".$lastPostId."'");
// print_r($db->errorInfo());
}
}
// print_r($db->errorInfo());
redirect('/forum/topic/'. abs(intval($topic_id)).'?page=end#post'.$lastPostId);
// print_r($db->errorInfo());
}
else
{
redirect('/forum/topic/'. abs(intval($topic_id)).'?page=end');
}
}
$title = _t('add_message');
include_header($title);
$tpl->div('title', _t('add_message'));
echo '<div class="menu">
<form action="/forum/add_post/'. $topic_id .'?act=create'.(isset($_GET['reply_to']) ? '&reply_to='.num($_GET['reply_to']) : (isset($_GET['quote']) ? '"e='.abs(intval($_GET['quote'])) : null)).'" method="post" enctype="multipart/form-data">
<b>'. _t('message') .'</b>:<br/>';
textarea(5, 26, (isset($_GET['reply_to']) ? '[b]'.tnick(num($_GET['reply_to'])).'[/b], ' : NULL) . (isset($_GET['quote']) ? "[quote][i][b]".tnick($db->query("SELECT user_id FROM `forum_pt` WHERE `topic_id` = '". $topic_id ."' AND `id` = '". abs(intval($_GET['quote'])) ."'")->fetchColumn())."[/b] ".date('d.m.Y, H:i', $db->query("SELECT time FROM `forum_pt` WHERE `topic_id` = '". $topic_id ."' AND `id` = '". abs(intval($_GET['quote'])) ."'")->fetchColumn())."[/i]:n".preg_replace("/[quote]|[/quote]/i", '', $db->query("SELECT text FROM `forum_pt` WHERE `topic_id` = '". $topic_id ."' AND `id` = '". abs(intval($_GET['quote'])) ."'")->fetchColumn())."n[/quote] " : NULL));
echo '<br/><b>'._t('add_file').'</b><br/>
<input type="file" name="file" /><br/>
<input name="create" type="submit" value="'. _t('create') .'" /><br/>
</form></div>';
$tpl->div('block', NAV .'<a href="/forum/topic/'.$topic_id.'?page=end">'. _t('back') .'</a><br/>' . NAV .'<a href="/forum/">'. _t('forum') .'</a><br/>' . HICO .'<a href="/">'. _t('home').'</a>');
include_footer();
?>