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

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