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

Размер файла: 4.7Kb
  1. <?php
  2. # Script by seg0ro http://mobilarts.ru
  3. # Not for sale!!!
  4.  
  5. # fixed
  6.  
  7. $set['title'] .= ' | Новые, последние темы';
  8. include H . 'engine/includes/head.php';
  9.  
  10. if (!$user_id){
  11. echo Core::msg_show('Только для авторизованных!<br /><a href="index.php">Форум</a>');
  12. include H . 'engine/includes/foot.php';
  13. }
  14.  
  15. $timeRes = isset($_REQUEST['time']) ? abs(intval($_REQUEST['time'])) : null;
  16. if ($timeRes)
  17. $time = time() - $timeRes * 3600;
  18.  
  19. $unread = isset($_GET['unread']) ? 1 : 0;
  20. $nav = '';
  21.  
  22. if ($unread || isset($_GET['reset'])){
  23. $tree = '<a href="index.php">Форум</a> / Непрочитанные';
  24. $nav = 'unread&amp;';
  25. }else{
  26. $nav = $time ? 'time='.$timeRes.'&amp;' : '';
  27. $tree = '<a href="index.php">Форум</a> / Последние темы'.($time ? ' за '.$timeRes.' час.' : '');
  28. }
  29. echo '<div class="fmenu">'.$tree.'</div>';
  30.  
  31. if (isset($_GET['reset'])){
  32.  
  33. $sql->query("SELECT `forum_topics`.`id`, `forum_topics`.`lastpost` FROM `forum_topics` LEFT JOIN `forum_readed` ON `forum_topics`.`id` = `forum_readed`.`topic` AND `forum_readed`.`user_id` = '$user_id' WHERE `forum_readed`.`topic` Is Null ");
  34. while ($res = $sql->fetch()){
  35. $lastPost = explode(':|:', $res['lastpost']);
  36. $sql->query("INSERT INTO `forum_readed` SET
  37. `topic` = '".$res['id']."',
  38. `user_id` = '$user_id',
  39. `time` = '".time()."',
  40. `lastpost` = '".$lastPost[1]."' ", true);
  41. }
  42. $sql->query("SELECT `forum_topics`.`id`, `forum_topics`.`lastpost` FROM `forum_topics` LEFT JOIN `forum_readed` ON `forum_topics`.`id` = `forum_readed`.`topic` AND `forum_readed`.`user_id` = '$user_id' WHERE `forum_topics`.`time` > `forum_readed`.`time` ");
  43. while ($res = $sql->fetch()){
  44. $lastPost = explode(':|:', $res['lastpost']);
  45. $sql->query("UPDATE `forum_readed` SET
  46. `time` = '".time()."',
  47. `lastpost` = '".$lastPost[1]."'
  48. WHERE `topic` = '".$res['id']."' AND `user_id` = '$user_id' ", true);
  49. }
  50.  
  51. echo '<div class="post">Все темы приняты как прочитанные<br /><a href="index.php">Форум</a></div>';
  52. include H . 'engine/includes/foot.php';
  53. }
  54.  
  55. if ($unread){
  56. $total = $sql->query("SELECT COUNT(*) FROM `forum_topics` LEFT JOIN `forum_readed` ON `forum_topics`.`id` = `forum_readed`.`topic` AND `forum_readed`.`user_id` = '$user_id' WHERE (`forum_readed`.`topic` Is Null OR `forum_topics`.`time` > `forum_readed`.`time`) ")->result();
  57. }else{
  58. $total = $sql->query("SELECT COUNT(*) FROM `forum_topics` ".($time ? "WHERE `forum_topics`.`time` > '".$time."' " : ""))->result();
  59. }
  60. $page = new page($total, $set['p_str']);
  61. if ($total){
  62. $page->display('index.php?act=last&amp;'.$nav);
  63.  
  64. if ($unread){
  65. $req = $sql->query("SELECT *, `forum_topics`.`time` AS `topictime`, `forum_topics`.`lastpost` AS `lastpost` FROM `forum_topics` LEFT JOIN `forum_readed` ON `forum_topics`.`id` = `forum_readed`.`topic` AND `forum_readed`.`user_id` = '$user_id' WHERE (`forum_readed`.`topic` Is Null OR `forum_topics`.`time` > `forum_readed`.`time`) ORDER BY `forum_topics`.`time` DESC LIMIT ".$page->limit());
  66. }else{
  67. $req = $sql->query("SELECT *, `forum_topics`.`time` AS `topictime` FROM `forum_topics` ".($time ? "WHERE `time` > '$time' " : "")."ORDER BY `time` DESC LIMIT ".$page->limit());
  68. }
  69.  
  70. while ($res = $sql->fetch()){
  71. echo $i % 2 ? '<div class="p_t">' : '<div class="p_m">';
  72. $sub = 'Автор: '.$res['user'];
  73. if ($res['count'] > 1){
  74. $lastPost = explode(':|:', $res['lastpost']);
  75. $sub .= ' <a href="index.php?post='.$lastPost[1].'">Последн.</a>: '.$lastPost[0];
  76. }
  77. $sub .= ' '.Core::time($res['topictime']).'<br />';
  78. $sub .= 'Подфорум: <a href="index.php?forum='.$res['refid'].'">'.$res['forum'].'</a>';
  79. echo show_topic($res, $sub, ($unread ? 1 : 0));
  80. echo '</div>';
  81. ++$i;
  82. }
  83. if (!$i) echo '<div class="p_m">Неверные данные. Убедитесь в правильности ввода страницы!</div>';
  84.  
  85. echo '<div class="fmenu">Тем: '.$total.'</div>';
  86. $page->display('index.php?act=last&amp;'.$nav);
  87.  
  88. }else{
  89. echo '<div class="p_m">Пусто</div>';
  90. }
  91.  
  92. if ($unread && $total)
  93. echo '<div class="menu_razd"><a href="index.php?act=last&amp;reset">Принять как прочитанное</a></div>';
  94. echo '<form class="post" action="index.php?act=last" method="get">
  95. <input type="hidden" name="act" value="last" />
  96. Показать за период (час.) <input type="text" size="2" name="time" value="'.($timeRes ? $timeRes : '24').'" /> <input type="submit" value="OK" />';
  97. if ($time || $unread)
  98. echo '<br /><a href="index.php?act=last">Показать все</a>';
  99. echo '</form>';