PageRenderTime 65ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/forum.php

https://bitbucket.org/bluefirex/itschi-software
PHP | 126 lines | 98 code | 21 blank | 7 comment | 13 complexity | 83e18ef6364657449452ed85f0cc37c8 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * @package com.Itschi.forum.index
  5. * @since 2007/05/25
  6. *
  7. */
  8. require 'base.php';
  9. if ($user->row && isset($_GET['mark'])) {
  10. // include 'lib/functions/topic.php';
  11. functions::topic()->mark_forum();
  12. }
  13. if ($config['enable_bots']) {
  14. $bots = $cache->get('bots');
  15. }
  16. $online = array();
  17. $res = $db->query('
  18. SELECT u.username, u.user_id, u.user_level, o.online_agent
  19. FROM ' . ONLINE_TABLE . ' o
  20. LEFT JOIN ' . USERS_TABLE . ' u ON o.user_id > 0 AND u.user_id = o.user_id
  21. WHERE o.online_lastvisit > ' . (time() - 300)
  22. );
  23. while ($row = $db->fetch_array($res)) {
  24. if ($row['user_id']) {
  25. $online[strtolower($row['username'])] = array(
  26. 'IS_BOT' => false,
  27. 'LEGEND' => $user->legend($row['user_level']),
  28. 'USERNAME' => $row['username'],
  29. 'ID' => $row['user_id']
  30. );
  31. } else if ($config['enable_bots']) {
  32. foreach ($bots as $bot) {
  33. if (preg_match('/' . preg_quote($bot['bot_agent'], '/') . '/', $row['online_agent'])) {
  34. $online[strtolower($bot['bot_name'])] = array(
  35. 'IS_BOT' => true,
  36. 'BOT_NAME' => $bot['bot_name']
  37. );
  38. break;
  39. }
  40. }
  41. }
  42. }
  43. $db->free_result($res);
  44. ksort($online);
  45. $s = '';
  46. foreach ($online as $row) {
  47. $row['SEPARATOR'] = $s;
  48. template::assignBlock('online', $row);
  49. $s = ', ';
  50. }
  51. $res = $db->query(
  52. ($user->row) ? '
  53. SELECT f.*, t.mark_time
  54. FROM ' . FORUMS_TABLE . ' f
  55. LEFT JOIN ' . FORUMS_TRACK_TABLE . ' t ON t.forum_id = f.forum_id AND t.user_id = ' . $user->row['user_id'] . '
  56. WHERE ' . ($user->row['user_level'] + 1) . ' >= f.forum_level AND forum_toplevel = 0
  57. ORDER BY f.forum_order
  58. ' : '
  59. SELECT *
  60. FROM ' . FORUMS_TABLE . '
  61. WHERE forum_level = 0 AND forum_toplevel = 0
  62. ORDER BY forum_order
  63. ');
  64. while ($row = $db->fetch_array($res)) {
  65. $forum = array(
  66. 'NAME' => $row['forum_name'],
  67. 'IS_CATEGORY' => $row['is_category']
  68. );
  69. $subforums = array();
  70. $fRes = $db->query("SELECT * FROM " . FORUMS_TABLE . " WHERE forum_toplevel = '" . $row['forum_id'] . "'");
  71. while ($fRow = $db->fetch_array($fRes)) {
  72. $subforums[] = $fRow;
  73. }
  74. if (!$row['is_category']) {
  75. $forum = array_merge($forum, array(
  76. 'ID' => $row['forum_id'],
  77. 'ICON' => (($row['forum_closed']) ? 'closed' : '') . (($user->row['user_id'] && max($row['mark_time'], $user->row['user_register']) < $row['forum_last_post_time']) ? 'new' : '') . 'topic',
  78. 'TOPICS' => number_format($row['forum_topics'], 0, '', '.'),
  79. 'POSTS' => number_format($row['forum_posts'], 0, '', '.'),
  80. 'DESCRIPTION' => $row['forum_description'],
  81. 'LAST_POST_TIME' => date('d.m.y H:i', $row['forum_last_post_time']),
  82. 'LAST_POST_USER_LEGEND' => $user->legend($row['forum_last_post_user_level']),
  83. 'LAST_POST_ID' => $row['forum_last_post_id'],
  84. 'LAST_POST_USER_ID' => $row['forum_last_post_user_id'],
  85. 'LAST_POST_USERNAME' => $row['forum_last_post_username'],
  86. 'LAST_POST_TOPIC_ID' => $row['forum_last_post_topic_id'],
  87. 'READ' => (($user->row['user_id'] && max($row['mark_time'], $user->row['user_register']) < $row['forum_last_post_time']) ? false : true),
  88. 'SUBFORUMS' => $subforums
  89. ));
  90. }
  91. template::assignBlock('forums', $forum);
  92. }
  93. $db->free_result($res);
  94. template::assign(array(
  95. 'TITLE_TAG' => 'Forum | ',
  96. 'USERS' => number_format($config['users_num'], 0, '', '.'),
  97. 'TOPICS' => number_format($config['topics_num'], 0, '', '.'),
  98. 'POSTS' => number_format($config['posts_num'], 0, '', '.'),
  99. 'NEWEST_USERNAME' => $config['newest_username'],
  100. 'NEWEST_USER_ID' => $config['newest_user_id'],
  101. 'NEWEST_USER_LEGEND' => $user->legend($config['newest_user_level'])
  102. ));
  103. template::display('forum');
  104. ?>