Просмотр файла forum/includes/showtopic.php

Размер файла: 12.01Kb
  1. <?php
  2. # Script by seg0ro http://mobilarts.ru
  3. # Not for sale!!!
  4.  
  5.  
  6. $cur_page = isset($_GET['page']) ? intval($_GET['page']) : 1;
  7. if ($user_id){
  8. $lastPost = explode(':|:', $topicRes['lastpost']);
  9. $sql->query("SELECT * FROM `forum_readed` WHERE `topic` = '$topic' AND `user_id` = '$user_id' LIMIT 1 ");
  10. if ($sql->num_rows() > 0){
  11. $readedRes = $sql->fetch();
  12. if ($topicRes['time'] > $readedRes['time'])
  13. $sql->query("UPDATE `forum_readed` SET `time` = '".time()."', `lastpost` = '".$lastPost['1']."' WHERE `topic` = '$topic' AND `user_id` = '$user_id' ");
  14. }else{
  15. $sql->query("INSERT INTO `forum_readed` SET `topic` = '$topic', `user_id` = '$user_id', `time` = '".time()."', `lastpost` = '".$lastPost['1']."' ");
  16. }
  17. }
  18. //$pollSet = $sql->query('select `poll_set` from `forum_topics` where `id` = '.$topic)->result();
  19. echo forum_counter();
  20.  
  21. $tree = array('<a href="index.php">Форум</a>', '<a href="index.php?forum='.$topicRes['refid'].'">'.text::output($topicRefid['name']).'</a>', text::output($topicRes['name']));
  22. echo '<div name="up" id="up" class="fmenu"><a href="#down">↓</a> ';
  23. foreach ($tree as $menu)
  24. {
  25. echo $menu . ' &nbsp; ';
  26. }
  27. echo '</div>';
  28.  
  29. if ($topicRes['close'])
  30. echo '<div class="rmenu">Тема закрыта!</div>';
  31.  
  32. if ($topicRes['poll_name']){
  33. if ($user_id)
  34. $pollCheck = $sql->query("SELECT COUNT(*) FROM `forum_polled` WHERE `refid` = '$topic' AND `user_id` = '$user_id' LIMIT 1 ")->result();
  35.  
  36.  
  37. echo '<div class="msg"><strong>'.text::output($topicRes['poll_name']).'</strong><br />';
  38. if ($pollSet['poll_close'] == 0 && !isset($_GET['results']) && $user_id && $pollCheck == 0 && !$topicRes['close']){
  39. echo '<form action="index.php?act=poll&amp;topic='.$topic.'&amp;page='.$cur_page.'" method="post">';
  40. while ($pollRes = mysqli_fetch_assoc($pollReq))
  41. {
  42. echo '<label><input type="'.($pollSet['poll_mod'] < 1 ? 'radio' : 'checkbox').'" name="var[]" value="'.$pollRes['id'].'" /> '.text::output($pollRes['name']).'</label><br />';
  43. }
  44. echo '<input type="submit" name="poll" value="Отдать голос" /><br /><a href="index.php?topic='.$topic.'&amp;page='.$cur_page.'&amp;results"><strong>Результаты</strong></a></form>';
  45. }else{
  46. while ($pollRes = mysqli_fetch_assoc($pollReq)){
  47. echo text::output($pollRes['name']).' ('.$pollRes['count'].')<br />';
  48. $poll_count = $pollSet['total_polls'] ? @round(100 / $pollSet['total_polls'] * $pollRes['count']) : 0;
  49. echo '<div style="background: #fff; border: 1px solid #ccc;"><div style="background:green; height: 5px; width: '.$poll_count.'%; min-width: 3px"></div></div>';
  50. }
  51.  
  52. echo 'Проголосовало: '.($user_id ? '<a href="index.php?act=polled&amp;topic='.$topic.'">'.$pollSet['total_polled'].'</a>' : $pollSet['total_polled']);
  53. if ($user_id && !$pollCheck && !$pollSet['poll_close'])
  54. echo '<br /><a href="index.php?topic='.$topic.'&amp;page='.$cur_page.'"><strong>Отдать голос</strong></a>';
  55. }
  56. echo '</div>';
  57. }
  58.  
  59. $total = $sql->query("SELECT COUNT(*) FROM `forum_posts` WHERE `refid` = '$topic' ")->result();
  60. $page = new page($total, $set['p_str']);
  61. if ($total){
  62. $req = mysqli_query($sql->db, "SELECT `forum_posts`.*, `forum_posts`.`id` AS `pid`, `forum_posts`.`user` AS `name`, `user`.`nick`, `user`.`id`, `user`.`pol` FROM `forum_posts` LEFT JOIN `user` ON `forum_posts`.`user_id` = `user`.`id` WHERE `forum_posts`.`refid` = '$topic' ORDER BY `forum_posts`.`time` ASC LIMIT ".$page->limit());
  63.  
  64.  
  65. $page->display('index.php?topic='.$topic.'&amp;');
  66.  
  67. if ($topicRes['clip'] && $cur_page > 1){
  68. echo '<div class="user">';
  69. $firstPost =$sql->query("SELECT `forum_posts`.*, `forum_posts`.`id` AS `pid`, `user`.`id`, `user`.`pol`, `user`.`nick` FROM `forum_posts` LEFT JOIN `user` ON `forum_posts`.`user_id` = `user`.`id` WHERE `forum_posts`.`refid` = '$topic' ORDER BY `forum_posts`.`time` ASC LIMIT 1 ")->fetch();
  70.  
  71. $postHeader .= ' <span class="gray">'.Core::time($firstPost['time']).'</span> <a href="index.php?post='.$firstPost['pid'].'" title="Ссылка на пост">#1</a>';
  72. $postText = quote(text::output($firstPost['text']));
  73.  
  74. if ($firstPost['files']){
  75. $postFile = $sql->query("SELECT * FROM `forum_files` WHERE `refid` = '".$firstPost['pid']."' LIMIT ".$firstPost['files']." ");
  76. $postText .= '<div class="func">Файл(ы):<br />';
  77. while ($postFileRes = $sql->fetch()){
  78. $postText .= show_file($postFileRes).'<br />';
  79. }
  80. $postText .= '</div>';
  81. }
  82.  
  83. if ($firstPost['edit']){
  84. $edit = explode(':|:', $firstPost['edit']);
  85. $postText .= '<div style="font-size: x-small; color: gray">Изменил(а) '.$edit['0'].' '.Core::time($edit['1']).'</div>';
  86. }
  87. if ($firstPost['rating'] > 0) $color = 'C0FFC0';
  88. elseif ($firstPost['rating'] < 0) $color = 'F196A8';
  89. else $color = 'CCCCCC';
  90. if ($user_id && $firstPost['user_id'] != $user_id){
  91. $postText .= '<div style="font-size: x-small">Рейтинг: <a href="index.php?act=rating&amp;topic='.$topic.'&amp;post='.$firstPost['pid'].'&amp;plus"><img src="images/plus.png" alt="+" /></a> <span style="background:#'.$color.'">&nbsp;'.$firstPost['rating'].'&nbsp;</span> <a href="index.php?act=rating&amp;topic='.$topic.'&amp;post='.$firstPost['pid'].'&amp;minus"><img src="images/minus.png" alt="-" /></a></div>';
  92. }else{
  93. $postText .= '<div style="font-size: x-small">Рейтинг: <span style="background:#'.$color.'">&nbsp;'.$firstPost['rating'].'&nbsp;</span></div>';
  94. }
  95. $postSub = '';
  96. if ((($user_id == $firstPost['user_id']) && !$topicRes['close']) || $moder){
  97. $postSub .= '<a href="index.php?act=editpost&amp;topic='.$topic.'&amp;post='.$firstPost['pid'].'&amp;page='.$page.'">Изменить</a> | <a href="index.php?act=delpost&amp;topic='.$topic.'&amp;post='.$firstPost['pid'].'&amp;page='.$page.'">Удалить</a>';
  98. }
  99. $postText .= '<br />'.$postSub;
  100. $postArray = array('staus' => $postHeader, 'post' => $postText);
  101. echo Core::user_show($firstPost, $postArray);
  102. echo '</div>';
  103. }
  104.  
  105. if ($moder)
  106. echo '<form action="index.php?act=massdelpost&amp;topic='.$topic.'&amp;page='.$cur_page.'" method="post">';
  107. $i = $page->start();
  108. while ($res = $sql->fetch($req)){
  109. ++$i;
  110. echo $i % 2 ? '<div name="p'.$res['pid'].'" id="p'.$res['pid'].'" class="p_m">' : '<div name="p'.$res['pid'].'" id="p'.$res['pid'].'" class="p_t">';
  111. $header = ' <span class="gray">'.Core::time($res['time']).'</span> <a href="index.php?post='.$res['pid'].'" title="Ссылка на пост">#'.$i.'</a>';
  112.  
  113. $text = quote(text::output($res['text']));
  114.  
  115.  
  116. if ($res['files']){
  117. $file = $sql->query("SELECT * FROM `forum_files` WHERE `refid` = '".$res['pid']."' LIMIT ".$res['files']." ");
  118. $text .= '<div class="func">Файл(ы):<br />';
  119. while($fileRes = $sql->fetch()){
  120. $text .= show_file($fileRes).'<br />';
  121. }
  122. $text .= '</div>';
  123. }
  124. if ($res['edit']){
  125. $edit = explode(':|:', $res['edit']);
  126. $text .= '<div style="font-size: x-small; color: gray">Изменил(а) '.$edit['0'].' '.Core::time($edit['1']).'</div>';
  127. }
  128. if ($res['rating'] > 0) $color = 'C0FFC0';
  129. elseif ($res['rating'] < 0) $color = 'F196A8';
  130. else $color = 'CCCCCC';
  131. if ($user_id && $res['user_id'] != $user_id && !$topicRes['close']){
  132. $text .= '<div style="font-size: x-small">Рейтинг: <a href="index.php?act=rating&amp;topic='.$topic.'&amp;post='.$res['pid'].'&amp;plus"><img src="images/plus.png" alt="+" /></a> <span style="background:#'.$color.'">&nbsp;'.$res['rating'].'&nbsp;</span> <a href="index.php?act=rating&amp;topic='.$topic.'&amp;post='.$res['pid'].'&amp;minus"><img src="images/minus.png" alt="-" /></a></div>';
  133. }else{
  134. $text .= '<div style="font-size: x-small">Рейтинг: <span style="background:#'.$color.'">&nbsp;'.$res['rating'].'&nbsp;</span></div>';
  135. }
  136. $sub = '';
  137. if (($user_id && $user_id != $res['user_id'] && !$topicRes['close']) || ($user_id != $res['user_id'] && $moder)){
  138. $sub .= '<a href="index.php?act=addpost&amp;post='.$res['pid'].'&amp;topic='.$topic.'&amp;page='.$cur_page.'">Ответ</a> <a href="index.php?act=addpost&amp;quote&amp;post='.$res['pid'].'&amp;topic='.$topic.'&amp;page='.$cur_page.'">Цитата</a>';
  139. }
  140.  
  141. if ((($user_id == $res['user_id'] && !$topicRes['close'] && $res['time'] > time() - 300) || ($user_id == $res['user_id'] && (!$i && (!$cur_page || $cur_page == 1)))) || ($moder)){
  142. $sub .= ' <a href="index.php?act=editpost&amp;topic='.$topic.'&amp;post='.$res['pid'].'&amp;page='.$cur_page.'">Изменить</a> | <a href="index.php?act=delpost&amp;topic='.$topic.'&amp;post='.$res['pid'].'&amp;page='.$cur_page.'">Удалить</a>';
  143. }
  144. if ($moder)
  145. $sub .= '<input type="checkbox" name="delch[]" value="'.$res['pid'].'" /> ';
  146.  
  147. $text .= $sub;
  148.  
  149. $array = array('status' => $header, 'post' => $text);
  150. echo Core::user_show($res, $array);
  151. echo '</div>';
  152. }
  153. if (!$i) echo '<div class="p_m">Неверные данные. Убедитесь в правильности ввода страницы!</div>';
  154.  
  155. if ($moder)
  156. echo '<div class="rmenu"><input type="submit" value="Удалить" /></div></form>';
  157.  
  158. }else{
  159. echo '<div class="p_m">Пусто</div>';
  160. }
  161.  
  162. if (($user_id && !$topicRes['close']) || $moder){
  163. echo '<div class="msg"><form id="form" name="form" action="index.php?act=addpost&amp;topic='.$topic.'&amp;page='.$cur_page.'" method="post">';
  164.  
  165. echo 'Быстрый ответ <img style="cursor: pointer;" onclick="alert(this.title);" src="images/question.png" alt="?" title="Для предпросмотра или прикрепления файлов нажмите на кнопку: Расшир. форма" />:<br /><textarea name="text"></textarea>';
  166. echo '<br /><input type="submit" name="send" value="Отправить" /> <input type="submit" name="preview" value="Расшир. форма" />';
  167.  
  168. echo '</form></div>';
  169. }
  170.  
  171. if ($total){
  172. echo '<div name="down" id="down" class="fmenu"><a href="#up">↑</a> Сообщений: '.$total.'</div>';
  173.  
  174. $page->display('index.php?topic='.$topic.'&amp;');
  175.  
  176. }
  177.  
  178. $onltime = time() - 300;
  179. $online_u = $sql->query("SELECT COUNT(*) FROM `user` WHERE `date_last` > $onltime AND `url` = 'forum,$topic' ")->result();
  180.  
  181. if ($topicRes['curator']){
  182. $curator = $sql->query("SELECT `lastdate`, `sex`, `datereg`, `id`, `name` FROM `users` WHERE `id` = '".$topicRes['curator']."' LIMIT 1 ")->fetch();
  183. $arrayCurator = array('header' => '', 'body' => '', 'sub' => '', 'iphide' => 1);
  184. core::$user_set['avatar'] = 0;
  185. echo '<p>Куратор темы: '.functions::display_user($curator, $arrayCurator).'</p>';
  186. }
  187.  
  188. echo '<p><a href="index.php?act=search&amp;topic='.$topic.'">Поиск</a><br />
  189. <a href="index.php?act=onforum&amp;topic='.$topic.'">Кто в теме</a> ('.$online_u.')<br />
  190. <a href="rss.php?topic='.$topic.'">Rss-канал</a><br />
  191. <a href="index.php?act=loadtopic&amp;topic='.$topic.'&amp;">Скачать тему</a><br />
  192. ';
  193.  
  194. if ($user_id){
  195. $favourites = $sql->query("SELECT COUNT(*) FROM `forum_favourites` WHERE `topic` = '$topic' AND `user_id` = '$user_id' LIMIT 1 ")->result();
  196. echo $favourites ? '<a href="index.php?act=my&amp;delfavourite&amp;topic='.$topic.'&amp;page='.$cur_page.'">Из избранного</a><br />' : '<a href="index.php?act=my&amp;addfavourite&amp;topic='.$topic.'&amp;page='.$cur_page.'">В избранное</a><br />';
  197. }
  198.  
  199. echo '<a href="index.php?act=files&amp;topic='.$topic.'">Файлы темы</a></p>';
  200.  
  201. if ($moder){
  202. echo '<div class="rmenu"><a href="index.php?act=edittopic&amp;topic='.$topic.'&amp;page='.$cur_page.'">Изменить</a> &nbsp; ';
  203. echo $moder ? ' <a href="index.php?act=deltopic&amp;topic='.$topic.'">Удалить</a> &nbsp; ' : '';
  204. echo ' <a href="index.php?act=movetopic&amp;topic='.$topic.'&amp;page='.$cur_page.'">Перенести</a>';
  205. echo '</div>';
  206. }