Файл: system/classes/Comments.php
Строк: 112
<?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
*/
class Comments
{
protected $module;
protected $module_id;
protected $params;
protected $ret;
protected $mod;
public function __construct($module, $module_id, $params = false, $ret = '', $mod = '')
{
global $db;
if($module != '' && $module_id != '' && $module_id != 0 && $db->query("SELECT * FROM `".($mod != '' ? $mod : $module)."` WHERE `id` = '".$module_id ."'")->rowCount() != 0)
{
$this->module = $module;
$this->module_id = abs(intval($module_id));
$this->params = $params;
$this->ret = $ret;
$this->mod = $mod;
}
elseif($mod != '' && $db->query("SELECT * FROM `{$mod}` WHERE `id` = '".$module_id ."'")->rowCount() == 0)
{
// echo "<b>Undefined module or wrong request id!</b>n<br/>
// Change $module or $module_idn";
@notFound();
// die('<div class="error">Comments not found!</div>');
}
else
{
// echo "<b>Undefined module or wrong request id!</b>n<br/>
// Change $module or $module_idn";
@notFound();
// die('<div class="error">Comments not found!</div>');
}
}
public function view()
{
global $db, $user, $ames, $start, $lang, $tpl, $settings;
$comments_r = $db->query("SELECT * FROM `{$this->module}_comms` WHERE `{$this->module}_id` = '".$this->module_id ."' ". ($this->params != "" ? $this->params : NULL) ."")->rowCount();
$pages = new Paginator($comments_r, $ames);
if(User::logged() && $settings['fast_mess'] == 1)
{
$tpl->div('post', '<form action="/'.$this->module.'/add_comment?act=create&'. $this->module .'_id='. $this->module_id .'" method="post">
<textarea name="text" rows="5" cols="26">'.(isset($_GET['reply_to']) ? '[b]'.tnick(num($_GET['reply_to'])).'[/b], ' : NULL).'</textarea>
<br/>
<input type="submit" name="create" value="'. _t('send') .'" /><br/>
</form>');
}
if($comments_r == 0)
{
echo $tpl->div('menu', _t('no_posts'));
}
else
{
$comments_q = $db->query("SELECT * FROM `{$this->module}_comms` WHERE `{$this->module}_id` = '".$this->module_id ."' ". ($this->params != "" ? $this->params : NULL) ." ORDER BY time DESC LIMIT $start, $ames");
while($comments = $comments_q->fetch())
{
echo '<div class="post">
'.(User::logged() && User::Id() != $comments['user_id'] ? '<span style="float:right;">[<a href="/'.$this->module.'/add_comment?act=create&'.$this->module.'_id='.$this->module_id.'&reply_to='.$comments['user_id'].'">'._t('reply').'</a>]</span>' : null) . ($user['level'] >=5 || $comments['user_id'] == $user['id'] ? '<span style="float:right;">[<a href="/'. $this->module .'/delete_comment/'. abs(intval($_GET['id'])) .'/?post_id='. $comments['id'] .'">x</a>]</span>' : NULL)
. nick($comments['user_id'], '<small>'.rtime($comments['time']).'</small>') . '
'. output($comments['text']) .'<br/>
</div>';
}
$pages->view();
}
}
public function add($text)
{
global $db, $user;
$text = mb_substr(input($text), 0, 5000);
if(!empty($text) && !empty($this->module_id) && antiflood((!empty($this->ret) ? $this->ret ."_comms": $this->module."_comms"), 'text', substr(input($text), 0, 3000)) == false)
{
$module_id = abs(intval($this->module_id));
// $db->query("SELECT * FROM `". (!empty($this->mod) ? $this->mod : $this->module)."` WHERE `id` = '". $module_id ."'");
// var_dump($db->errorInfo());
// exit;
if($db->query("SELECT * FROM `". (!empty($this->mod) ? $this->mod : $this->module)."` WHERE `id` = '". $module_id ."'")->rowCount() != 0)
{
$db->query("INSERT INTO `". (!empty($this->ret) ? $this->ret ."_comms":$this->module."_comms")."` (`". (!empty($this->ret) ? $this->ret ."_id" : $this->module."_id")."`, `text`, `time`, `user_id`) VALUES('".$module_id ."', '". $text ."', '". time() ."', '". $user['id'] ."')");
$db->query("UPDATE `users` SET `balance` = '".(User::profile('balance')+1)."' WHERE `id` = '". User::Id() ."'");
// var_dump($db->errorInfo());
// exit;
if(!empty($this->ret)) { $this->module = $this->ret; }
}
else
{
// redirect("/{$this->module}/".$module_id ."");
echo 'Error';
}
}
else
{
// redirect("/{$this->module}/".$module_id ."");
echo 'Error';
}
}
public function delete($post_ids)
{
global $db;
$post_id = abs(intval($post_ids));
if(!empty($this->ret)) { $this->module = $this->ret; }
$db->query("DELETE FROM `".$this->module."_comms` WHERE `id` = '". $post_id ."'");
// print_r($db->errorInfo());
header('Location: /'. $this->module .'/comments/'. $this->module_id);
exit;
}
}