<?php

/*
=================================================================
Bullet Energy - by White-Master 
-----------------------------------------------------------------
http://white-master.ru/
-----------------------------------------------------------------
Copyright (c) 2011 White-Master
=================================================================
Данный код защищен авторскими правами
=================================================================
Файл: ajax_viewer.class.php
=================================================================
*/
class BulletAjaxViewer extends BulletAjax
{
   public $tpl = null;
   private $cpu = false;
   private $selfphp = '';
   public function __construct()
   {
      global $PHP_SELF;
      if (!class_exists('dle_template')) {
         include_once (ROOT_DIR . '/engine/classes/templates.class.php');
      }
      $this->tpl = new dle_template;
      $this->tpl->dir = ROOT_DIR . '/templates/' . parent::$dle_config['skin'] . '/bullet_energy/';
      if (intval(parent::$modules_config['cpu']) == 1) {
         $this->cpu = true;
      } else {
         $this->cpu = false;
      }
      $this->selfphp = $PHP_SELF;
   }
   public function user_topic_pages($option = '')
   {
      if ($this->cpu) {
         return ("<a title=\"" . parent::$modules_lang['user_9'] . "\" href=\"" . parent::$dle_config['http_home_url'] . "user/" . urlencode($option) . "/topic\">");
      } else {
         return ("<a title=\"" . parent::$modules_lang['user_9'] . "\" href=\"" . parent::$dle_config['http_home_url'] . "index.php?do=forum&amp;action=topic_user&name=" . urlencode($option) . "\">");
      }
   }
   public function user_message_pages($option = '')
   {
      if ($this->cpu) {
         return ("<a title=\"" . parent::$modules_lang['user_8'] . "\" href=\"" . parent::$dle_config['http_home_url'] . "user/" . urlencode($option) . "/message\">");
      } else {
         return ("<a title=\"" . parent::$modules_lang['user_8'] . "\" href=\"" . parent::$dle_config['http_home_url'] . "index.php?do=forum&amp;action=message_user&name=" . urlencode($option) . "\">");
      }
   }
   public function setTplMessage($data = array())
   {
      $edit = '';
      $this->tpl->load_template('short_message.tpl');
      $this->tpl->set('{messageAutorIp}', $data['message_autor_ip']);
      $this->tpl->set('[popupUserCard]', $this->card_user(array($data['message_autor'], $data['autors_id'])));
      $this->tpl->set('[/popupUserCard]', '</a>');
      $this->tpl->set('{autorName}', $data['message_autor']);
      $this->tpl->set('{moder}', '');
      $this->tpl->set('{checkbox}', '');
      $this->tpl->set('{forumPostNum}', $data['forum_post_count']);
      $this->tpl->set('{forumTopicNum}', $data['forum_topic_count']);
      $this->tpl->set('{lock}', $data['lock']);
      $this->tpl->set('{userGroup}', $data['user_group']);
      $this->tpl->set('{titleUser}', $data['titleUser']);
      if ($data['warning']) {
         $this->tpl->set('[isAccessWarning]', '');
         $this->tpl->set('[/isAccessWarning]', '');
         $this->tpl->set('{countWarning}', $data['countWarning']);
      } else {
         $this->tpl->set_block("'\\[isAccessWarning\\](.*?)\\[/isAccessWarning\\]'si", "");
      }
      if ($data['titleUser']) {
         $this->tpl->set('[titleUser]', '');
         $this->tpl->set('[/titleUser]', '');
      } else {
         $this->tpl->set_block("'\\[titleUser\\](.*?)\\[/titleUser\\]'si", "");
      }
      $this->tpl->set('{likeCountUser}', $data['likeCountUser']);
      if ($data['likeCountUser']) {
         $this->tpl->set('[likeCountUser]', '');
         $this->tpl->set('[/likeCountUser]', '');
      } else {
         $this->tpl->set_block("'\\[likeCountUser\\](.*?)\\[/likeCountUser\\]'si", "");
      }
      if ($data['countTrophies']) {
         $this->tpl->set('[isUserTrophies]', '');
         $this->tpl->set('[/isUserTrophies]', '');
      } else {
         $this->tpl->set_block("'\\[isUserTrophies\\](.*?)\\[/isUserTrophies\\]'si", "");
      }
      if ($data['isOnline'] and parent::$modules_config['online']) {
         $this->tpl->set('{isOnline}', parent::$modules_lang['msg_32']);
         $this->tpl->set('{isOnlineCss}', 'online');
      } elseif (!$data['isOnline'] and parent::$modules_config['online']) {
         $this->tpl->set('{isOnline}', parent::$modules_lang['msg_33']);
         $this->tpl->set('{isOnlineCss}', 'offline');
      } else {
         $this->tpl->set('{isOnline}', '');
         $this->tpl->set('{isOnlineCss}', '');
      }
      $this->tpl->set('[userTrophies]', $data['countTrophiesLinck']);
      $this->tpl->set('[/userTrophies]', $data['countTrophiesLinckOut']);
      $this->tpl->set('{countTrophies}', $data['countTrophies']);
      $this->tpl->set('{newsNum}', $data['news_num']);
      $this->tpl->set('{commNum}', $data['comm_num']);
      $this->tpl->set('{messageId}', $data['mesage_id']);
      $this->tpl->set('{cssName}', $data['css_name']);
      $this->tpl->set('{cssGroup}', $data['css_group']);
      $this->tpl->set('[profile]', $this->linckUserSiteProfile($data['message_autor']));
      $this->tpl->set('[/profile]', '</a>');
      $this->tpl->set('{messageLinck}', '<a class="getMessageLinck" onclick="getMessageLinck(\'' . $data['mesage_id'] . '\'); return false;" title="' . parent::$modules_lang['msg_13'] . '" href="' . parent::$linck->postLinck($data['id_topic'], $data['mesage_id'], $data['topicName']) . '">#' . $data['idPostPage'] . '</a>');
      $this->tpl->set('{regDate}', $data['reg_date']);
      $this->tpl->set('{foto}', $data['foto']);
      $this->tpl->set('{signature}', $data['signature']);
      $this->tpl->set('{reputation}', '');
      $this->tpl->set('{like}', $data['like']);
      if (trim($data['signature'])) {
         $this->tpl->set('[signatureBox]', '');
         $this->tpl->set('[/signatureBox]', '');
      } else {
         $this->tpl->set_block("'\\[signatureBox\\](.*?)\\[/signatureBox\\]'si", "");
      }
      $this->tpl->set('{icq}', $data['icq']);
      if (parent::$group_config[parent::$id_member['user_group']]['be_complaint'] and parent::$id_member['name'] != $data['message_autor']) {
         $this->tpl->set('[complaint]', "<a href=\"javascript:PostComplaint('{$data['mesage_id']}')\" class=\"edit top\">");
         $this->tpl->set('[/complaint]', '</a>');
      } else {
         $this->tpl->set_block("'\\[complaint\\](.*?)\\[/complaint\\]'si", "");
      }
      if ($data['autors_id'] == parent::$id_member['user_id'] and parent::$group_config[parent::$id_member['user_group']]['be_access_del_my_post'] and !$data['one_message']) {
         $this->tpl->set('[deleteMsg]', "<a href=\"javascript:DeleteMsg('{$data['mesage_id']}','" . parent::$login_hash . "')\" class=\"edit top\">");
         $this->tpl->set('[/deleteMsg]', '</a>');
      } elseif ($data['autors_id'] != parent::$id_member['user_id'] and parent::$id_member['user_id'] and parent::$group_config[parent::$id_member['user_group']]['be_moder_del_message_user'] and !$data['one_message']) {
         $this->tpl->set('[deleteMsg]', "<a href=\"javascript:DeleteMsg('{$data['mesage_id']}','" . parent::$login_hash . "')\" class=\"edit top\">");
         $this->tpl->set('[/deleteMsg]', '</a>');
      } else {
         $this->tpl->set_block("'\\[deleteMsg\\](.*?)\\[/deleteMsg\\]'si", "");
      }
      if ($data['autors_id'] == parent::$id_member['user_id'] and parent::$group_config[parent::$id_member['user_group']]['be_access_edit_my_post']) {
         $this->tpl->set('[msgEdit]', "<a href=\"javascript:;\" onclick=\"MsgEdit('{$data['mesage_id']}','" . parent::$login_hash . "'); return false;\" class=\"edit top\">");
         $this->tpl->set('[/msgEdit]', '</a>');
      } elseif ($data['autors_id'] != parent::$id_member['user_id'] and parent::$group_config[parent::$id_member['user_group']]['be_moder_edit_message_user']) {
         $this->tpl->set('[msgEdit]', "<a href=\"javascript:;\" onclick=\"MsgEdit('{$data['mesage_id']}','" . parent::$login_hash . "'); return false;\"  class=\"edit top\">");
         $this->tpl->set('[/msgEdit]', '</a>');
      } else {
         $this->tpl->set_block("'\\[msgEdit\\](.*?)\\[/msgEdit\\]'si", "");
      }
      $this->tpl->set('[fast]', "<a onmouseover=\"copy_fast_insert('" . str_replace(array(" ", "&#039;"), array("&nbsp;", "&amp;#039;"), $data['message_autor']) . "');\" href=\"javascript:;\" onclick=\"fast_insert('" . str_replace(array(" ", "&#039;"), array("&nbsp;", "&amp;#039;"), $data['message_autor']) . "'); return false;\">");
      $this->tpl->set('[/fast]', "</a>");
      $this->tpl->set('{messageDate}', $data['message_date']);
      if ($data['msg_edit_date']) {
         $edit = '<div class="EditMsgView">' . parent::$modules_lang['msg_12'] . $data['edit_autor'] . ' ' . date('d.m.Y в H:i', $data['msg_edit_date']) . '</div>';
      }
      if (parent::$group_config[parent::$id_member['user_group']]['be_access_hide']) {
         $data['message_text'] = str_ireplace("[hide]", "", str_ireplace("[/hide]", "", $data['message_text']));
      } else {
         $data['message_text'] = preg_replace("#\[hide\](.+?)\[/hide\]#ims", "<div class=\"HideNo\">" . parent::$modules_lang['msg_11'] . "</div>", $data['message_text']);
      }
      $this->tpl->set('{messageText}', '<div id="MsgTextBox-' . $data['mesage_id'] . '">' . $data['message_text'] . '</div>');
      $this->tpl->set('{editorInfo}', $edit);
      $this->tpl->compile('short_message');
      return $this->tpl->result['short_message'];
   }
   public function setTplPreviewTopic(array $data = array())
   {
      $this->tpl->load_template('preview_topic.tpl');
      $this->tpl->set('{foto}', $data['foto']);
      $this->tpl->set('[popupUserCard]', $this->card_user(array($data['message_autor'], $data['autors_id'])));
      $this->tpl->set('[/popupUserCard]', '</a>');
      $this->tpl->set('[profile]', $this->linckUserSiteProfile($data['message_autor']));
      $this->tpl->set('[/profile]', '</a>');
      $this->tpl->set('[linckPost]', '<a title="' . parent::$modules_lang['topic_83'] . '" href="' . parent::$linck->postLinck($data['id_topic'], $data['id'], $data['nameTopic']) . '">');
      $this->tpl->set('[/linckPost]', '</a>');
      $this->tpl->set('{messageDate}', $data['message_date']);
      $this->tpl->set('{messageAuthor}', $data['message_autor']);
      $this->tpl->set('{langPostType}', parent::$modules_lang['topic_80'] . $data['lng']);
      if (parent::$group_config[parent::$id_member['user_group']]['be_access_hide']) {
         $data['message_text'] = str_ireplace("[hide]", "", str_ireplace("[/hide]", "", $data['message_text']));
      } else {
         $data['message_text'] = preg_replace("#\[hide\](.+?)\[/hide\]#ims", "<div class=\"HideNo\">" . parent::$modules_lang['msg_11'] . "</div>", $data['message_text']);
      }
      $this->tpl->set('{messageText}', stripcslashes($data['message_text']));
      $this->tpl->compile('preview_topic');
   }
   public function langdate($format, $stamp)
   {
      return strtr(@date($format, $stamp), parent::$lang_local);
   }
   public function setTplTopicShort($data)
   {
      $this->tpl->load_template('short_topic.tpl');
      $this->tpl->set('{id}', $data['id']);
      $this->tpl->set('{title}', $data['title']);
      $this->tpl->set('{replyCount}', $data['reply_count']);
      $this->tpl->set('{pageList}', '');
      $this->tpl->set('{viewCount}', $data['view_count']);
      $this->tpl->set('{description}', $data['site_description']);
      $this->tpl->set('{autor}', $this->user_linck($data['autor']));
      $this->tpl->set('{uniqueStatusTopic}', '');
      $this->tpl->set('[linck]', parent::$linck->topic_linck($data['id'], $data['titleTopic']));
      $this->tpl->set('[/linck]', '</a>');
      $this->tpl->set('{topicPostDate}', $this->langdate(parent::$modules_config['time_step_topic_new'], $data['post_date']));
      if (parent::$group_config[parent::$id_member['user_group']]['be_moder_topic_moder_param']) {
         $this->tpl->set('{edit}', '<a href="javascript:editTopic(\'' . $data['id'] . '\')" title="Редактировать">Редактировать</a>');
      } else {
         $this->tpl->set('{edit}', '');
      }
      if (!$data['topic_approve'] and parent::$group_config[parent::$id_member['user_group']]['be_moder_topic_moder_param']) {
         $ico .= '<span title="' . parent::$modules_lang['topic_43'] . '" class="moderation">' . parent::$modules_lang['topic_43'] . '</span>';
      }
      if ($data['fixed']) {
         $ico .= '<span title="' . parent::$modules_lang['topic_41'] . '" class="sticky">' . parent::$modules_lang['topic_41'] . '</span>';
      }
      if ($data['topic_type'] == '2') {
         $ico .= '<span title="' . parent::$modules_lang['topic_42'] . '" class="clozed">' . parent::$modules_lang['topic_42'] . '</span>';
      }
      if ($ico) {
         $this->tpl->set('{icon}', $ico);
      } else {
         $this->tpl->set('{icon}', '');
      }
      //var_dump($data);
      if ($data['last']) {
         if ($data['last'][4]) {
            $this->tpl->set('{lastAutorAvatarLinck}', parent::$dle_config['http_home_url'] . 'uploads/fotos/' . $data['last'][4]);
         } else {
            $this->tpl->set('{lastAutorAvatarLinck}', parent::$dle_config['http_home_url'] . 'templates/' . parent::$dle_config['skin'] . '/bullet_energy/images/noavatar.png');
         }
         $this->tpl->set('{lastAutorName}', $data['last'][0]);
         $this->tpl->set('{lastTopicName}', stripcslashes($data['last'][2]));
         $this->tpl->set('[lastMessageLinck]', '<a href="' . $data['last'][3] . '">');
         $this->tpl->set('[/lastMessageLinck]', '</a>');
         $this->tpl->set('[popupUserCard]', $this->card_user(array($data['last'][0], $data['last'][5])));
         $this->tpl->set('[/popupUserCard]', '</a>');
         $this->tpl->set('{last_autor_name}', $this->linck_autor($data['last'][0])); //
         $this->tpl->set('{lastMessageDate}', $this->langdate('j F Y', $data['last'][1]));
         //::$ajax_handler
         $this->tpl->set('[LastMessage]', '');
         $this->tpl->set('[/LastMessage]', '');
         $this->tpl->set('[profile]', $this->linckUserSiteProfile($data['last'][0]));
         $this->tpl->set('[/profile]', '</a>');
      } else {
         $this->tpl->set_block("'\\[LastMessage\\](.*?)\\[/LastMessage\\]'si", "&nbsp;");
      }
      $this->tpl->set('{status}', $data['status_read']);
      $this->tpl->set('{unreadLinck}', '');
      $this->tpl->set('{statusTitl}', $data['statusTitl']);
      $this->tpl->compile('short_topic');
      return $this->tpl->result['short_topic'];
   }
   public function linck_autor($name)
   {
      if ($this->cpu)
         return "<a title = \"" . parent::$modules_lang['view_profile'] . "\" href=\"" . parent::$dle_config['http_home_url'] . "user/" . urlencode($name) . "/\">" . $name . "</a>";
      else
         return "<a title = \"" . parent::$modules_lang['view_profile'] . "\" href=\"" . $this->selfphp . "?subaction=userinfo&amp;user=" . urlencode($name) . "\">" . $name . "</a>";
   }
   public function linckUserSiteProfile($name = '')
   {
      if ($this->cpu)
         return "<a title=\"" . parent::$modules_lang['user_3'] . "\" href=\"" . parent::$dle_config['http_home_url'] . "user/" . urlencode($name) . "/\">";
      else
         return "<a title=\"" . parent::$modules_lang['user_3'] . "\" href=\"" . $this->selfphp . "?subaction=userinfo&amp;user=" . urlencode($name) . "\">";
   }
   public function card_user($data = array())
   {
      $go_page = "onclick=\"getUserCard('" . $data[1] . "','" . parent::$dle_config['http_home_url'] . "user/" . urlencode($data[0]) . "/','" . urlencode($data[0]) . "'); return false;\"";
      if ($this->cpu)
         return "<a title = \"" . parent::$modules_lang['card_user'] . "\" class=\"popup_profile\" {$go_page} href=\"" . parent::$dle_config['http_home_url'] . "user/" . urlencode($data[0]) . "/\">";
      else
         return "<a title = \"" . parent::$modules_lang['card_user'] . "\" class=\"popup_profile\" {$go_page} href=\"" . $this->selfphp . "?subaction=userinfo&amp;user=" . urlencode($data[0]) . "\">";
   }
   public function user_linck($name = '')
   {
      if ($this->cpu) {
         $go_page = parent::$dle_config['http_home_url'] . "user/" . urlencode($name) . "/";
      } else {
         $go_page = $this->selfphp . "?subaction=userinfo&amp;user=" . urlencode($name);
      }
      return "<a onclick=\"ShowProfile('" . urlencode($name) . "', '" . $go_page . "'); return false;\" href=\"" . $go_page . "\">" . $name . "</a>";
   }
   public function setTpluserCard($data = array())
   {
      $this->tpl->load_template('user_card_popup.tpl');
      $this->tpl->set('{foto}', $data['foto']);
      $this->tpl->set('{group}', $data['user_group']);
      $this->tpl->set('{lastdate}', $data['lastdate']);
      $this->tpl->set('{registration}', $data['reg_date']);
      $this->tpl->set('{news_num}', $data['news_num']);
      $this->tpl->set('{news}', $data['linck_news']);
      $this->tpl->set('{comments}', $data['linck_comments']);
      $this->tpl->set('{comm_num}', $data['comm_num']);
      $this->tpl->set('{icon_group}', $data['icon_group']);
      $this->tpl->set('{signature}', $data['signature']);
      $this->tpl->set('{info}', $data['info']);
      $this->tpl->set('{land}', $data['land']);
      $this->tpl->set('{icq}', $data['icq']);
      $this->tpl->set('{like}', $data['like']);
      $this->tpl->set('{message_num}', $data['forum_post_count']);
      $this->tpl->set('{topic_num}', $data['forum_topic_count']);
      $this->tpl->set('{fullname}', $data['fullname']);
      $this->tpl->set('[messageAllView]', $data['linckMsg']);
      $this->tpl->set('[/messageAllView]', "</a>");
      $this->tpl->set('[topicAllView]', $data['linckTopic']);
      $this->tpl->set('[/topicAllView]', "</a>");
      if ($data['isOnline'] and parent::$modules_config['online']) {
         $this->tpl->set('{isOnline}', parent::$modules_lang['msg_32']);
         $this->tpl->set('{isOnlineCss}', 'online');
         $this->tpl->set('[isOnline]', '');
         $this->tpl->set('[/isOnline]', '');
      } elseif (!$data['isOnline'] and parent::$modules_config['online']) {
         $this->tpl->set('{isOnline}', parent::$modules_lang['msg_33']);
         $this->tpl->set('{isOnlineCss}', 'offline');
         $this->tpl->set('[isOnline]', '');
         $this->tpl->set('[/isOnline]', '');
      } else {
         $this->tpl->set_block("'\\[isOnline\\](.*?)\\[/isOnline\\]'si", '');
      }
      $this->tpl->set('[userTrophies]', $data['countTrophiesLinck']);
      $this->tpl->set('[/userTrophies]', $data['countTrophiesLinckOut']);
      $this->tpl->set('{countTrophies}', $data['countTrophies']);
      $this->tpl->set('{titleUser}', $data['titleUser']);
      if ($data['titleUser']) {
         $this->tpl->set('[titleUser]', '');
         $this->tpl->set('[/titleUser]', '');
      } else {
         $this->tpl->set_block("'\\[titleUser\\](.*?)\\[/titleUser\\]'si", "");
      }
      if ($data['like']) {
         $this->tpl->set('[likeCountUser]', '');
         $this->tpl->set('[/likeCountUser]', '');
      } else {
         $this->tpl->set_block("'\\[likeCountUser\\](.*?)\\[/likeCountUser\\]'si", "");
      }
      if ($data['countTrophies']) {
         $this->tpl->set('[isUserTrophies]', '');
         $this->tpl->set('[/isUserTrophies]', '');
      } else {
         $this->tpl->set_block("'\\[isUserTrophies\\](.*?)\\[/isUserTrophies\\]'si", "");
      }
      $this->tpl->compile('user_card_popup');
      return "<div id='forum_user_card' title='" . parent::$modules_lang['userOne'] . ":  " . $data['name'] . "' style='display:none'>" . $this->tpl->result['user_card_popup'] . '</div>';
   }
   public function setLinckNews($user = '')
   {
      if ($this->cpu) {
         return ("<a href=\"" . parent::$dle_config['http_home_url'] . "user/" . urlencode($user) . "/news/" . "\">" . parent::$modules_lang['all_user_news'] . "</a>");
      } else {
         return ("<a href=\"" . parent::$dle_config['http_home_url'] . "?subaction=allnews&amp;user=" . urlencode($user) . "\">" . parent::$modules_lang['all_user_news'] . "</a>");
      }
   }
   public function setLinckComment($userID = '')
   {
      return "<a href=\"" . parent::$dle_config['http_home_url'] . "?do=lastcomments&amp;userid={$userID}\">" . parent::$modules_lang['last_comm'] . "</a>";
   }
   public function setTplAttachmentList($data = array())
   {
      $option = array('insert' => '', 'name' => '', 'description' => '', 'idFile' => '', 'img' => array());
      if ($data['fileType'] == 0) {
         $file = parent::$dle_config['http_home_url'] . "uploads/forum/images/" . $data['fileDateUpload'] . "/{$data['fileName']}";
         if (file_exists(ROOT_DIR . '/uploads/forum/images/' . $data['fileDateUpload'] . '/thumbs/' . $data['fileName'])) {
            $option['img'][] = "<a class=\"mini_img\" href=\"javascript:;MiniImg('{$file}')\">" . parent::$modules_lang['attachment_5'] . "</a>";
         }
         if (file_exists(ROOT_DIR . '/uploads/forum/images/' . $data['fileDateUpload'] . '/' . $data['fileName']) and parent::$modules_config['images_prev_insert']) {
            $option['img'][] = "<a class=\"ful_img\" href=\"javascript:;FullImg('{$file}')\">" . parent::$modules_lang['attachment_6'] . "</a>";
         }
         if (!file_exists(ROOT_DIR . '/uploads/forum/images/' . $data['fileDateUpload'] . '/thumbs/' . $data['fileName'])) {
            $option['img'][] = "<a class=\"ful_img\" href=\"javascript:;FullImg('{$file}')\">" . parent::$modules_lang['attachment_6'] . "</a>";
         }
         $option['insert'] = implode(' - ', $option['img']);
         $option['description'] = '<li class="descrip_file">' . parent::$modules_lang['attachment_7'] . ':</li>';
         $option['name'] = '<a class="name_file" target="_blank" href = "' . $file . '">' . $data['fileNameSiteView'] . '</a>';
      } else {
         $option['insert'] = parent::$modules_lang['attachment_8'];
         $option['name'] = $data['fileNameSiteView'];
      }
      return '<li class="file" id="' . $data['fileDbId'] . '"><div class="BoxInnertList"><span class="' . $data['fileExtensions'] . ' icon">ICO</span>
    <ol class="file_info"><li>' . $option['name'] . '</li>' . $option['description'] . '<li>' . $option['insert'] . '</li></ol><a href ="#" onclick = "DelAttach(\'' . $data['fileDbId'] . '\',\'' . parent::$login_hash . '\'); return false;" class = "delbutton">' . parent::$modules_lang['attachment_9'] . '</a></div></li>';
   }
}

?>