Файл: modules/forum/topic.php
Строк: 157
<?php
/****
* @package LiveCMS
* @link livecms.org
* @author MyZik
* @version See attached file VERSION.txt
* @license See attached file LICENSE.txt
* @copyright Copyright (C) LiveCMS Development Team
****/
ob_start();
$lang_forum = load_lng('forum'); // Подключаем файл языка
$module = 'forum'; // Модуль
  /**
    * Проверяем, задан ли верный параметр
  **/
  if (!isset($_GET['id']) || empty($_GET['id']) || !is_numeric($_GET['id'])) {
    $title = $lang_forum['forum']; // Заголовок страницы
    require_once(HOME .'/incfiles/header.php');
    echo '<div class="error">' . $lang['error_parameter'] . '</div>';
    echo '<div class="home">' .
    '<img src="/design/themes/' . $set_user['theme'] . '/images/back.png" alt="" /> <a href="index.php">' . $lang['back'] . '</a>' .
    '</div>';
    require_once(HOME .'/incfiles/footer.php');
      }
  /**
    * Проверяем наличие темы
  **/
  if (mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_topics` WHERE `id` = '" . num($_GET['id']) . "'"), 0) == 0) {
    $title = $lang_forum['forum']; // Заголовок страницы
    require_once(HOME .'/incfiles/header.php');
    echo '<div class="error">' . $lang_forum['topic_not_exists'] . '</div>';
    echo '<div class="home">' .
    '<img src="/design/themes/' . $set_user['theme'] . '/images/back.png" alt="" /> <a href="index.php">' . $lang['back'] . '</a>' .
    '</div>';
    require_once(HOME .'/incfiles/footer.php');
      }
  $ID = num($_GET['id']);
  $topic = mysql_fetch_assoc(mysql_query("SELECT * FROM `cms_forum_topics` WHERE `id` = '$ID' LIMIT 1"));
  $category = mysql_fetch_assoc(mysql_query("SELECT * FROM `cms_forum_categories` WHERE `id` = '" . $topic['category_id'] . "' LIMIT 1"));
  $section = mysql_fetch_assoc(mysql_query("SELECT * FROM `cms_forum_sections` WHERE `id` = '" . $topic['section_id'] . "' LIMIT 1"));
  $title = $topic['name'] . ' / ' . $lang_forum['forum']; // Заголовок страницы
  require_once(HOME .'/incfiles/header.php'); // подключаем шапку
  /**
    * Закрытие темы
  **/
  if (isset($_GET['close']) && ($user['rights'] == 3 || $user['rights'] >= 7) && $topic['close'] == 'no') {
    mysql_query("UPDATE `cms_forum_topics` SET `close` = 'yes' WHERE `id` = '$ID' LIMIT 1");
    header("Location: topic.php?id=$ID");
    exit;
      }
  /**
    * Открытие темы
  **/
  if (isset($_GET['open']) && ($user['rights'] == 3 || $user['rights'] >= 7) && $topic['close'] == 'yes') {
    mysql_query("UPDATE `cms_forum_topics` SET `close` = 'no' WHERE `id` = '$ID' LIMIT 1");
    header("Location: topic.php?id=$ID");
    exit;
      }
  /**
    * Закрепление темы
  **/
  if (isset($_GET['up']) && ($user['rights'] == 3 || $user['rights'] >= 7) && $topic['up'] == 0) {
    mysql_query("UPDATE `cms_forum_topics` SET `up` = '1' WHERE `id` = '$ID' LIMIT 1");
    header("Location: topic.php?id=$ID");
    exit;
      }
  /**
    * Открепление темы
  **/
  if (isset($_GET['unup']) && ($user['rights'] == 3 || $user['rights'] >= 7) && $topic['up'] == '1') {
    mysql_query("UPDATE `cms_forum_topics` SET `up` = '0' WHERE `id` = '$ID' LIMIT 1");
    header("Location: topic.php?id=$ID");
    exit;
      }
  /**
    * Небольшая панель навигации
  **/
  echo '<div class="title"><a href="/forum/">' . $lang['forum'] . '</a> | <a href="category.php?id=' . $category['id'] . '">' . txt($category['name']) . '</a> | <a href="section.php?id=' . $section['id'] . '">' . txt($section['name']) . '</a></div>';
  echo '<div class="main"><b>' . $topic['name'] . '</b></div>';
  /**
    * Если тема закрыта, выводим напоминание
  **/
  if ($topic['close'] == 'yes')
    echo '<div class="error">' . $lang_forum['topic_closed'] . '</div>';
  $author = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $topic['author_id'] . "' LIMIT 1"));
  /**
    * Админские функции
  **/
  if (($user['rights'] == 3 || $user['rights'] >= 7) && $user['rights'] >= $author['rights']) {
    echo '<div class="main">' .
    ($topic['close'] == 'no' ? '<a href="topic.php?id=' . $ID . '&close">' . $lang_forum['close_topic'] . '</a>' : '<a href="topic.php?id=' . $ID . '&open">' . $lang_forum['open_topic'] . '</a>') .
    ($topic['up'] == 0 ? ' | <a href="topic.php?id=' . $ID . '&up">' . $lang_forum['up_topic'] . '</a>' : ' | <a href="topic.php?id=' . $ID . '&unup">' . $lang_forum['down_topic'] . '</a>') .
    ' | <a href="move_topic.php?id=' . $ID . '">' . $lang_forum['move_topic'] . '</a>' .
    ' | <a href="rename_topic.php?id=' . $ID . '">' . $lang_forum['rename_topic'] . '</a>' .
    ' | <a href="delete_topic.php?id=' . $ID . '">' . $lang['delete'] . '</a>' .
    '</div>';
      }
    
  /**
    * Настраиваем пагинацию
  **/
  $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_messages` WHERE `topic_id` = '$ID'"), 0);
  $req = mysql_query("SELECT * FROM `cms_forum_messages` WHERE `topic_id` = '$ID' ORDER BY `time` ASC LIMIT $start, $countMess"); 
    /**
      * Если нет результатов, выводим уведомление
    **/
  if ($total < 1) {
    echo '<div class="error">' . $lang_forum['messages_in_topic_not_found'] . '</div>';
      }
  while ($res = mysql_fetch_assoc($req)) {
    echo ($i % 2) ? '<div class="list1">' : '<div class="list2">';
    $post_text = mb_substr($res['text'], 0, 500);
    $profile = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $res['user_id'] . "' LIMIT 1"));
    // Показываем аватары
    if ($set_user['show_avatars'] == 'yes') {
      echo '<table cellpadding="0" cellspacing="0"><tr><td>';
      if (file_exists(HOME . '/files/avatar/' . $profile['id'] . '.png'))
        echo '<img src="/files/avatar/' . $profile['id'] . '.png" width="32" height="32" alt="' . $profile['login'] . '" /> ';
      else
        echo '<img src="/design/avatar_default.png" width="32" height="32" alt="' . $profile['login'] . '" /> ';
      echo '</td><td>';
    }
    // В зависимости от настроек юзера показываем его пол иконкой / текстом
    if ($set_user['sex_view'] == 'icons')
      $sex_view = '<img src="/design/themes/' . $set_user['theme'] . '/images/user_' . ($profile['sex'] == 'm' ? 'm.png' : 'w.png') . '" alt="" />';
    elseif ($set_user['sex_view'] == 'text')
      $sex_view = ($profile['sex'] == 'm' ? $lang['sex_m_text'] : $lang['sex_w_text']);
    else 
      $sex_view = '<img src="/design/themes/' . $set_user['theme'] . '/images/delete_user.png" alt="" />';
      $rights = array (
        0 => '',
        3 => '(FMod)',
        7 => '(Smd)',
        8 => '(Adm)',
      10 => '(SV!)'
          );
        $uRights =  ' <span style="color:blue">' . $rights[$profile['rights']] . '</span>';
      echo $sex_view . ' ' . (isset($user) ? '<a href="/user/profile.php?id=' . $profile['id'] . '"><b>' . $profile['login'] . '</b></a>' : '<b>' . $profile['login'] . '</b>') . (time() > $profile['date_last_entry'] + 600 ? ' <span class="red">[Off]</span>' : ' <span class="green">[On]</span>') . $uRights . ' [' . display_time($res['time']) . ']';
    // ссылки на ответ и цитирование
    echo ((isset($user)) && ($user['id'] != $profile['id']) ? ' <a href="say.php?id=' . $ID . '&post=' . $res['id'] . '">' . $lang_forum['answer_post'] . '</a> <a href="say.php?id=' . $ID . '&post=' . $res['id'] . '&quote">' . $lang_forum['quote_post'] . '</a>' : '');
      if (!empty($profile['status']))
        echo '<br /><span class="status"><img src="/design/themes/' . $set_user['theme'] . '/images/status.png" alt="Status" align="middle" /> ' . $profile['status'] . '</span>';
      if ($set_user['show_avatars'] == 'yes')
        echo '</td></tr></table>';
      else
        echo '<br />';
      // обрезаем текст
     echo ($res['text'] <= $post_text ? output(txt($res['text'])) : output(txt($post_text)) . '<br /><a href="post.php?id=' . $res['id'] . '"><b>' . $lang_forum['read_all'] . '</b></a>') .
    // если пост редактировался, показываем
    ($res['edit_count'] > 0 ? '<br /><span class="gray"><small>' . $lang_forum['post_edit'] . ' <b>' . $res['edit_count'] . ' ' . $lang_forum['edit_count'] . ', ' . $lang_forum['last'] . ': ' . $res['edit_by'] . '</b></small></span>' : '');
    // прикрепленные файлы
    $files = mysql_query("SELECT * FROM `forum_files` WHERE `post_id` = '" . $res['id'] . "'");
    if (mysql_num_rows($files) > 0) {
    echo '<br /><span class="gray">' . $lang_forum['attached_files'];
    while($file = mysql_fetch_assoc($files)) {
      $size = round(@filesize(HOME . '/files/forum/' . $file['name']) / 1024, 2);
      echo '<br /><a href="download_file.php?id=' . $file['id'] . '">' . $file['name'] . '</a> [' . $size . ' KB]';
    echo '<br />' . $lang_forum['downloads'] . ': ' . $file['downloads'] . '</span>';
         }
       }
    // действия над сообщением
   echo ($user['id'] == $profile['id'] || ($user['rights'] == 3 || $user['rights'] >= 7) ? '<br /><a href="edit_post.php?id=' . $res['id'] . '">' . $lang_forum['edit_post'] . '</a>' : '') . ($user['rights'] == 3 || $user['rights'] >= 7 ? ' | <a href="delete_post.php?id=' . $res['id'] . '">' . $lang_forum['delete_post'] . '</a>' : '') .
    '</div>';
      }
  /**
    * Форма
  **/
  if (isset($user) && $topic['close'] == 'no') {
    echo '<div class="main"><form name="message" method="post" action="say.php?id=' . $ID . '" enctype="multipart/form-data">' .
    $lang['enter_message'] . '<br />' .
    bb_panel('message', 'text') .
    '<textarea name="text"></textarea><br />' .
    $lang_forum['message_text_info'] . '<br />' .
    '<input type="checkbox" name="attach_files" value="1" /> ' . $lang_forum['attach_to_post'] . '<br />' .
    '<input type="submit" name="add" value="' . $lang['add'] . '" />' .
    '</form></div>';
    }
    /**
      * Пагинация
    **/
    if ($total > $countMess) {
      echo '<div class="home">' . display_pagination('topic.php?id=' . $ID . '&', $start, $total, $countMess) . '</div>';
      } 
  require_once(HOME .'/incfiles/footer.php'); // подключаем ноги
ob_end_flush();
?>