Вход Регистрация
Файл: system/classes/comments.php
Строк: 95
<?php
class Comments {
    protected 
$module;
    protected 
$module_id;
    protected 
$params;
    protected 
$ret;
    protected 
$mod;
    
    public function 
__construct($module = '', $module_id = '', $params = '', $ret='', $mod='') {
        if(
$module != '' && $module_id != '') {
            
$this->module = $module;
            
$this->module_id = abs(intval($module_id));
            
$this->params = $params;
            
$this->ret = $ret;
            
$this->mod = $mod;
        }
        else {
            echo 
"<b>Undefined Comments module or comments parameter id!</b>n<br/>
                    Change string 
$module and $module_idn";
        }
    }
    
    public function 
view() {
        global 
$db;
        global 
$user;
        global 
$ames;
        global 
$start;
        global 
$lang;
        global 
$tpl;
        global 
$settings;
        global 
$system;
        
$comments_r = $db->query("SELECT * FROM `". $this->module ."_comms` WHERE `". $this->module ."_id` = '".$this->module_id ."' ". ($this->params != "" ? $this->params : NULL) ."")->rowCount();
        if(isset(
$_GET['act']) && $_GET['act'] == 'spam') { 
        
$tpl->div('block', $lang->word('spam') .' <b>'.$system['spam'].'</b> '.$lang->word('sec')); 
        } 
        
$pages = new Paginator($comments_r, $ames);
        if(
$comments_r == 0) {
            echo 
$tpl->div('menu', $lang->word('no_comments'));
        }
        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">'. nick($comments['user_id']) . '  <span style="float:right">'.($comments['user_id'] != $user['id'] && $user['id'] != $comments['user_id'] && $commentst['closed'] == 0 ? '<a href="/'.$this->module.'/'.(isset($user) && $settings['fast_mess'] == 'yes' ? 'comments/' : 'add_comment/'). $comments['comments_id'] .'?'. $this->module .'_id='.$this->module_id.'&reply_to='.tnick($comments['user_id']).'" title="'. $lang->word('reply') .'">'.img('reply_11.png').'</a>': NULL) .' '.($user['level'] >=5 || $comments['user_id'] == $user['id'] ? '<a href="/'. $this->module .'/delete_comment/'. abs(intval($_GET[$this->module .'_id'])) .'/?post_id='. $comments['id'] .'" title="'. $lang->word('delete') .'">'. img('delete_11.png') .'</a> <a href="?act=edit&id='. $comments['id'] .'" title="'. $lang->word('edit') .'">'. img('edit_11.png') .'</a>' : NULL) .'</span><br/>
                '
. output($comments['text']) .'<br/>
                <small>('
.rtime($comments['time']).')</small></div>';
            }
            
$pages->view('/'. $this->module .'/'. abs(intval($_GET[$this->module .'_id'])) .'/comments/?');
        }
        if(
$settings['fast_mess'] == 'yes') { 
        
$tpl->div('post', '<form action="/'.$this->module.'/add_comment/?act=create&amp;'. $this->module .'_id='. $this->module_id .'" method="post">
                            <textarea name="text" rows="5" cols="26">'
.(isset($_GET['reply_to']) ? '[b]'.input($_GET['reply_to']).'[/b], ' : NULL).'</textarea>
                            <br/>
                            [ <a href="/pages/smiles.php">'
. $lang->word('smiles') .'</a> | <a href="/pages/tags.php">'. $lang->word('tags') .'</a> ]<br/><input type="submit" name="create" value="'. $lang->word('send') .'" /><br/>
                            </form>'
);
        }
    }
    
    public function 
add($text) {
        global 
$db;
        global 
$user;
        global 
$system;
        if(!empty(
$text) && !empty($this->module_id)) {
            
$text = substr(input($text), 0, 3000);
            
$module_id = abs(intval($this->module_id));
            if(
$db->query("SELECT * FROM `". $this->module ."` WHERE `id` = '". $module_id ."' LIMIT 1")->rowCount() != 0) {
            if(!empty(
$this->ret)) { $this->module = $this->ret; }
            
$s = $db->query("SELECT * FROM `". $this->module ."_comms` WHERE `user_id` = '". $user['id'] ."' AND `time` > '". (time()-$system['spam']) ."'")->rowCount();
            if (
$s>0) {
            
header("Location: /". $this->module ."/".$module_id ."/comments?act=spam");
            } else {
                
$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'] ."')");
                
// print_r($db->errorInfo());
                
if(!empty($this->ret)) { $this->module = $this->ret; }
                
header("Location: /". $this->module ."/".$module_id ."/comments?".$s."");
            }    
            } else {
                
header("Location: /". $this->module ."/".$module_id ."");
            }
        } else {
                
header("Location: /". $this->module ."/".$module_id ."");
        }
    }
    
    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 .'/'. $this->module_id .'/comments/');
    }
    
}
Онлайн: 3
Реклама