[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

/ -> viewforum.php (source)

   1  <?php
   2  /** 
   3  *
   4  * @package phpBB3
   5  * @version $Id: viewforum.php,v 1.307 2006/11/12 15:35:43 acydburn Exp $
   6  * @copyright (c) 2005 phpBB Group 
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
   8  *
   9  */
  10  
  11  /**
  12  * @ignore
  13  */
  14  define('IN_PHPBB', true);
  15  $phpbb_root_path = './';
  16  $phpEx = substr(strrchr(__FILE__, '.'), 1);
  17  include($phpbb_root_path . 'common.'.$phpEx);
  18  include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  19  
  20  // Start session
  21  $user->session_begin();
  22  $auth->acl($user->data);
  23  
  24  // Start initial var setup
  25  $forum_id    = request_var('f', 0);
  26  $mark_read    = request_var('mark', '');
  27  $start        = request_var('start', 0);
  28  
  29  $sort_days    = request_var('st', ((!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0));
  30  $sort_key    = request_var('sk', ((!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't'));
  31  $sort_dir    = request_var('sd', ((!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd'));
  32  
  33  // Check if the user has actually sent a forum ID with his/her request
  34  // If not give them a nice error page.
  35  if (!$forum_id)
  36  {
  37      trigger_error('NO_FORUM');
  38  }
  39  
  40  $sql_from = FORUMS_TABLE . ' f';
  41  $lastread_select = '';
  42  
  43  // Grab appropriate forum data
  44  if ($config['load_db_lastread'] && $user->data['is_registered'])
  45  {
  46      $sql_from .= ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
  47          AND ft.forum_id = f.forum_id)';
  48      $lastread_select .= ', ft.mark_time';
  49  }
  50  
  51  if ($user->data['is_registered'])
  52  {
  53      $sql_from .= ' LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON (fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'] . ')';
  54      $lastread_select .= ', fw.notify_status';
  55  }
  56  
  57  $sql = "SELECT f.* $lastread_select
  58      FROM $sql_from
  59      WHERE f.forum_id = $forum_id";
  60  $result = $db->sql_query($sql);
  61  $forum_data = $db->sql_fetchrow($result);
  62  $db->sql_freeresult($result);
  63  
  64  if (!$forum_data)
  65  {
  66      trigger_error('NO_FORUM');
  67  }
  68  
  69  
  70  // Configure style, language, etc.
  71  $user->setup('viewforum', $forum_data['forum_style']);
  72  
  73  // Redirect to login upon emailed notification links
  74  if (isset($_GET['e']) && !$user->data['is_registered'])
  75  {
  76      login_box('', $user->lang['LOGIN_NOTIFY_FORUM']);
  77  }
  78  
  79  // Permissions check
  80  if (!$auth->acl_gets('f_list', 'f_read', $forum_id))
  81  {
  82      if ($user->data['user_id'] != ANONYMOUS)
  83      {
  84          trigger_error($user->lang['SORRY_AUTH_READ']);
  85      }
  86  
  87      login_box('', $user->lang['LOGIN_VIEWFORUM']);
  88  }
  89  
  90  // Is this forum a link? ... User got here either because the
  91  // number of clicks is being tracked or they guessed the id
  92  if ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'])
  93  {
  94      // Does it have click tracking enabled?
  95      if ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK)
  96      {
  97          $sql = 'UPDATE ' . FORUMS_TABLE . '
  98              SET forum_posts = forum_posts + 1
  99              WHERE forum_id = ' . $forum_id;
 100          $db->sql_query($sql);
 101      }
 102  
 103      redirect($forum_data['forum_link']);
 104  }
 105  
 106  // Forum is passworded ... check whether access has been granted to this
 107  // user this session, if not show login box
 108  if ($forum_data['forum_password'])
 109  {
 110      login_forum_box($forum_data);
 111  }
 112  
 113  // Build navigation links
 114  generate_forum_nav($forum_data);
 115  
 116  // Forum Rules
 117  if ($auth->acl_get('f_read', $forum_id))
 118  {
 119      generate_forum_rules($forum_data);
 120  }
 121  
 122  // Do we have subforums?
 123  $active_forum_ary = $moderators = array();
 124  
 125  if ($forum_data['left_id'] != $forum_data['right_id'] - 1)
 126  {
 127      list($active_forum_ary, $moderators) = display_forums($forum_data, $config['load_moderators'], $config['load_moderators']);
 128  }
 129  else
 130  {
 131      $template->assign_var('S_HAS_SUBFORUM', false);
 132      get_moderators($moderators, $forum_id);
 133  }
 134  
 135  // Dump out the page header and load viewforum template
 136  page_header($user->lang['VIEW_FORUM'] . ' - ' . $forum_data['forum_name']);
 137  
 138  $template->set_filenames(array(
 139      'body' => 'viewforum_body.html')
 140  );
 141  
 142  make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"), $forum_id);
 143  
 144  // Not postable forum or showing active topics?
 145  if (!($forum_data['forum_type'] == FORUM_POST || (($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) && $forum_data['forum_type'] == FORUM_CAT)))
 146  {
 147      page_footer();
 148  }
 149  
 150  // Ok, if someone has only list-access, we only display the forum list
 151  if (!$auth->acl_get('f_read', $forum_id))
 152  {
 153      page_footer();
 154  }
 155  
 156  // Handle marking posts
 157  if ($mark_read == 'topics')
 158  {
 159      markread('topics', $forum_id);
 160  
 161      $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
 162      meta_refresh(3, $redirect_url);
 163  
 164      trigger_error($user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
 165  }
 166  
 167  // Is a forum specific topic count required?
 168  if ($forum_data['forum_topics_per_page'])
 169  {
 170      $config['topics_per_page'] = $forum_data['forum_topics_per_page'];
 171  }
 172  
 173  // Do the forum Prune thang - cron type job ...
 174  if ($forum_data['prune_next'] < time() && $forum_data['enable_prune'])
 175  {
 176      $template->assign_var('RUN_CRON_TASK', '<img src="' . $phpbb_root_path . 'cron.' . $phpEx . '?cron_type=prune_forum&amp;f=' . $forum_id . '" width="1" height="1" />');
 177  }
 178  
 179  // Forum rules and subscription info
 180  $s_watching_forum = $s_watching_forum_img = array();
 181  $s_watching_forum['link'] = $s_watching_forum['title'] = '';
 182  if (($config['email_enable'] || $config['jab_enable']) && $config['allow_forum_notify'] && $auth->acl_get('f_subscribe', $forum_id))
 183  {
 184      $notify_status = (isset($forum_data['notify_status'])) ? $forum_data['notify_status'] : NULL;
 185      watch_topic_forum('forum', $s_watching_forum, $s_watching_forum_img, $user->data['user_id'], $forum_id, 0, $notify_status);
 186  }
 187  
 188  $s_forum_rules = '';
 189  gen_forum_auth_level('forum', $forum_id, $forum_data['forum_status']);
 190  
 191  // Topic ordering options
 192  $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
 193  
 194  $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
 195  $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views');
 196  
 197  $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
 198  gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
 199  
 200  // Limit topics to certain time frame, obtain correct topic count
 201  if ($sort_days)
 202  {
 203      $min_post_time = time() - ($sort_days * 86400);
 204  
 205      $sql = 'SELECT COUNT(topic_id) AS num_topics
 206          FROM ' . TOPICS_TABLE . "
 207          WHERE forum_id = $forum_id
 208              AND topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ")
 209              AND topic_last_post_time >= $min_post_time
 210          " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND topic_approved = 1');
 211      $result = $db->sql_query($sql);
 212      $topics_count = (int) $db->sql_fetchfield('num_topics');
 213      $db->sql_freeresult($result);
 214  
 215      if (isset($_POST['sort']))
 216      {
 217          $start = 0;
 218      }
 219      $sql_limit_time = "AND t.topic_last_post_time >= $min_post_time";
 220  
 221      // Make sure we have information about day selection ready
 222      $template->assign_var('S_SORT_DAYS', true);
 223  }
 224  else
 225  {
 226      $topics_count = ($auth->acl_get('m_approve', $forum_id)) ? $forum_data['forum_topics_real'] : $forum_data['forum_topics'];
 227      $sql_limit_time = '';
 228  }
 229  
 230  // Basic pagewide vars
 231  $post_alt = ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['FORUM_LOCKED'] : $user->lang['POST_NEW_TOPIC'];
 232  
 233  // Display active topics?
 234  $s_display_active = ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
 235  
 236  $template->assign_vars(array(
 237      'PAGINATION'    => generate_pagination(append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&amp;$u_sort_param"), $topics_count, $config['topics_per_page'], $start),
 238      'PAGE_NUMBER'    => on_page($topics_count, $config['topics_per_page'], $start),
 239      'TOTAL_TOPICS'    => ($s_display_active) ? false : (($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count)),
 240      'MODERATORS'    => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '',
 241  
 242      'POST_IMG'                    => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', $post_alt) : $user->img('button_topic_new', $post_alt),
 243      'NEWEST_POST_IMG'            => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
 244      'LAST_POST_IMG'                => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
 245      'FOLDER_IMG'                => $user->img('topic_read', 'NO_NEW_POSTS'),
 246      'FOLDER_NEW_IMG'            => $user->img('topic_unread', 'NEW_POSTS'),
 247      'FOLDER_HOT_IMG'            => $user->img('topic_read_hot', 'NO_NEW_POSTS_HOT'),
 248      'FOLDER_HOT_NEW_IMG'        => $user->img('topic_unread_hot', 'NEW_POSTS_HOT'),
 249      'FOLDER_LOCKED_IMG'            => $user->img('topic_read_locked', 'NO_NEW_POSTS_LOCKED'),
 250      'FOLDER_LOCKED_NEW_IMG'        => $user->img('topic_unread_locked', 'NEW_POSTS_LOCKED'),
 251      'FOLDER_STICKY_IMG'            => $user->img('sticky_read', 'POST_STICKY'),
 252      'FOLDER_STICKY_NEW_IMG'        => $user->img('sticky_unread', 'POST_STICKY'),
 253      'FOLDER_ANNOUNCE_IMG'        => $user->img('announce_read', 'POST_ANNOUNCEMENT'),
 254      'FOLDER_ANNOUNCE_NEW_IMG'    => $user->img('announce_unread', 'POST_ANNOUNCEMENT'),
 255      'FOLDER_MOVED_IMG'            => $user->img('topic_moved', 'TOPIC_MOVED'),
 256      'REPORTED_IMG'                => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
 257      'UNAPPROVED_IMG'            => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
 258      'GOTO_PAGE_IMG'                => $user->img('icon_post_target', 'GOTO_PAGE'),
 259  
 260      'L_NO_TOPICS'             => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'],
 261  
 262      'S_IS_POSTABLE'            => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
 263      'S_DISPLAY_ACTIVE'        => $s_display_active,
 264      'S_SELECT_SORT_DIR'        => $s_sort_dir,
 265      'S_SELECT_SORT_KEY'        => $s_sort_key,
 266      'S_SELECT_SORT_DAYS'    => $s_limit_days,
 267      'S_TOPIC_ICONS'            => ($s_display_active && sizeof($active_forum_ary)) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false),
 268      'S_WATCH_FORUM_LINK'    => $s_watching_forum['link'],
 269      'S_WATCH_FORUM_TITLE'    => $s_watching_forum['title'],
 270      'S_FORUM_ACTION'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&amp;start=$start"),
 271      'S_DISPLAY_SEARCHBOX'    => ($auth->acl_get('f_search', $forum_id)) ? true : false,
 272      'S_SEARCHBOX_ACTION'    => append_sid("{$phpbb_root_path}search.$phpEx", 'fid[]=' . $forum_id),
 273      'S_SINGLE_MODERATOR'    => (!empty($moderators[$forum_id]) && sizeof($moderators[$forum_id]) > 1) ? false : true,
 274  
 275      'U_MCP'                => ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&amp;i=main&amp;mode=forum_view", true, $user->session_id) : '',
 276      'U_POST_NEW_TOPIC'    => append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=post&amp;f=' . $forum_id),
 277      'U_VIEW_FORUM'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&amp;$u_sort_param&amp;start=$start"),
 278      'U_MARK_TOPICS'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&amp;mark=topics"))
 279  );
 280  
 281  // Grab icons
 282  $icons = $cache->obtain_icons();
 283  
 284  // Grab all topic data
 285  $rowset = $announcement_list = $topic_list = $global_announce_list = array();
 286  
 287  $sql_array = array(
 288      'SELECT'    => 't.*',
 289      'FROM'        => array(
 290          TOPICS_TABLE        => 't'
 291      ),
 292      'LEFT_JOIN'    => array(),
 293  );
 294  
 295  $sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1';
 296  
 297  if ($user->data['is_registered'])
 298  {
 299      if ($config['load_db_track'])
 300      {
 301          $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
 302          $sql_array['SELECT'] .= ', tp.topic_posted';
 303      }
 304  
 305      if ($config['load_db_lastread'])
 306      {
 307          $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']);
 308          $sql_array['SELECT'] .= ', tt.mark_time';
 309  
 310          if ($s_display_active && sizeof($active_forum_ary))
 311          {
 312              $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']);
 313              $sql_array['SELECT'] .= ', ft.mark_time AS forum_mark_time';
 314          }
 315      }
 316  }
 317  
 318  if ($forum_data['forum_type'] == FORUM_POST)
 319  {
 320      // Obtain announcements ... removed sort ordering, sort by time in all cases
 321      $sql = $db->sql_build_query('SELECT', array(
 322          'SELECT'    => $sql_array['SELECT'],
 323          'FROM'        => $sql_array['FROM'],
 324          'LEFT_JOIN'    => $sql_array['LEFT_JOIN'],
 325      
 326          'WHERE'        => 't.forum_id IN (' . $forum_id . ', 0)
 327              AND t.topic_type IN (' . POST_ANNOUNCE . ', ' . POST_GLOBAL . ')',
 328  
 329          'ORDER_BY'    => 't.topic_time DESC',
 330      ));
 331      $result = $db->sql_query($sql);
 332  
 333      while ($row = $db->sql_fetchrow($result))
 334      {
 335          $rowset[$row['topic_id']] = $row;
 336          $announcement_list[] = $row['topic_id'];
 337  
 338          if ($row['topic_type'] == POST_GLOBAL)
 339          {
 340              $global_announce_list[$row['topic_id']] = true;
 341          }
 342      }
 343      $db->sql_freeresult($result);
 344  }
 345  
 346  // If the user is trying to reach late pages, start searching from the end
 347  $store_reverse = false;
 348  $sql_limit = $config['topics_per_page'];
 349  if ($start > $topics_count / 2)
 350  {
 351      $store_reverse = true;
 352  
 353      if ($start + $config['topics_per_page'] > $topics_count)
 354      {
 355          $sql_limit = min($config['topics_per_page'], max(1, $topics_count - $start));
 356      }
 357  
 358      // Select the sort order
 359      $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
 360      $sql_start = max(0, $topics_count - $sql_limit - $start);
 361  }
 362  else
 363  {
 364      // Select the sort order
 365      $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
 366      $sql_start = $start;
 367  }
 368  
 369  // SQL array for obtaining topics/stickies
 370  $sql_array = array(
 371      'SELECT'        => $sql_array['SELECT'],
 372      'FROM'            => $sql_array['FROM'],
 373      'LEFT_JOIN'        => $sql_array['LEFT_JOIN'],
 374  
 375      'WHERE'            => (($forum_data['forum_type'] == FORUM_POST || !sizeof($active_forum_ary)) ? 't.forum_id = ' . $forum_id : $db->sql_in_set('t.forum_id', $active_forum_ary['forum_id'])) . "
 376          AND t.topic_type = {SQL_TOPIC_TYPE}
 377          $sql_approved
 378          $sql_limit_time",
 379  
 380      'ORDER_BY'        => $sql_sort_order,
 381  );
 382  
 383  // If store_reverse, then first obtain topics, then stickies, else the other way around...
 384  // Funnily enough you typically save one query if going from the last page to the middle (store_reverse) because
 385  // the number of stickies are not known
 386  $sql = $db->sql_build_query('SELECT', $sql_array);
 387  $sql = str_replace('{SQL_TOPIC_TYPE}', ($store_reverse) ? POST_NORMAL : POST_STICKY, $sql);
 388  $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
 389  
 390  $shadow_topic_list = array();
 391  $num_rows = 0;
 392  while ($row = $db->sql_fetchrow($result))
 393  {
 394      if ($row['topic_status'] == ITEM_MOVED)
 395      {
 396          $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
 397      }
 398  
 399      $rowset[$row['topic_id']] = $row;
 400      $topic_list[] = $row['topic_id'];
 401      $num_rows++;
 402  }
 403  $db->sql_freeresult($result);
 404  
 405  // If the number of topics exceeds the sql limit then we do not need to retrieve the remaining topic type
 406  if ($num_rows < $sql_limit)
 407  {
 408      $sql = $db->sql_build_query('SELECT', $sql_array);
 409      $sql = str_replace('{SQL_TOPIC_TYPE}', ($store_reverse) ? POST_STICKY : POST_NORMAL, $sql);
 410      $result = $db->sql_query_limit($sql, $sql_limit - $num_rows, $sql_start);
 411  
 412      while ($row = $db->sql_fetchrow($result))
 413      {
 414          if ($row['topic_status'] == ITEM_MOVED)
 415          {
 416              $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
 417          }
 418  
 419          $rowset[$row['topic_id']] = $row;
 420          $topic_list[] = $row['topic_id'];
 421      }
 422      $db->sql_freeresult($result);
 423  }
 424  
 425  // If we have some shadow topics, update the rowset to reflect their topic informations
 426  if (sizeof($shadow_topic_list))
 427  {
 428      $sql = 'SELECT *
 429          FROM ' . TOPICS_TABLE . '
 430          WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list));
 431      $result = $db->sql_query($sql);
 432  
 433      while ($row = $db->sql_fetchrow($result))
 434      {
 435          $orig_topic_id = $shadow_topic_list[$row['topic_id']];
 436  
 437          // We want to retain some values
 438          $row = array_merge($row, array(
 439              'topic_moved_id'    => $rowset[$orig_topic_id]['topic_moved_id'],
 440              'topic_status'        => $rowset[$orig_topic_id]['topic_status'])
 441          );
 442  
 443          $rowset[$orig_topic_id] = $row;
 444      }
 445      $db->sql_freeresult($result);
 446  }
 447  unset($shadow_topic_list);
 448  
 449  $topic_list = ($store_reverse) ? array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list);
 450  $topic_tracking_info = $tracking_topics = array();
 451  
 452  // Okay, lets dump out the page ...
 453  if (sizeof($topic_list))
 454  {
 455      $mark_forum_read = true;
 456      $mark_time_forum = 0;
 457  
 458      // Active topics?
 459      if ($s_display_active && sizeof($active_forum_ary))
 460      {
 461          // Generate topic forum list...
 462          $topic_forum_list = array();
 463          foreach ($rowset as $t_id => $row)
 464          {
 465              $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread'] && $user->data['is_registered']) ? $row['forum_mark_time'] : 0;
 466              $topic_forum_list[$row['forum_id']]['topics'][] = $t_id;
 467          }
 468  
 469          if ($config['load_db_lastread'] && $user->data['is_registered'])
 470          {
 471              foreach ($topic_forum_list as $f_id => $topic_row)
 472              {
 473                  $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), false);
 474              }
 475          }
 476          else if ($config['load_anon_lastread'] || $user->data['is_registered'])
 477          {
 478              foreach ($topic_forum_list as $f_id => $topic_row)
 479              {
 480                  $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], false);
 481              }
 482          }
 483  
 484          unset($topic_forum_list);
 485      }
 486      else
 487      {
 488          if ($config['load_db_lastread'] && $user->data['is_registered'])
 489          {
 490              $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list);
 491              $mark_time_forum = (!empty($forum_data['mark_time'])) ? $forum_data['mark_time'] : $user->data['user_lastmark'];
 492          }
 493          else if ($config['load_anon_lastread'] || $user->data['is_registered'])
 494          {
 495              $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, $global_announce_list);
 496  
 497              if (!$user->data['is_registered'])
 498              {
 499                  $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
 500              }
 501              $mark_time_forum = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
 502          }
 503      }
 504  
 505      $s_type_switch = 0;
 506      foreach ($topic_list as $topic_id)
 507      {
 508          $row = &$rowset[$topic_id];
 509  
 510          // This will allow the style designer to output a different header
 511          // or even seperate the list of announcements from sticky and normal topics
 512          $s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
 513  
 514          // Replies
 515          $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
 516  
 517          if ($row['topic_status'] == ITEM_MOVED)
 518          {
 519              $topic_id = $row['topic_moved_id'];
 520              $unread_topic = false;
 521          }
 522          else
 523          {
 524              $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
 525          }
 526  
 527          // Get folder img, topic status/type related informations
 528          $folder_img = $folder_alt = $topic_type = '';
 529          topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
 530  
 531          // Generate all the URIs ...
 532          $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
 533  
 534          $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id)) ? true : false;
 535          $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id)) ? true : false;
 536          $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&amp;t=$topic_id", true, $user->session_id) : '';
 537  
 538          // Send vars to template
 539          $template->assign_block_vars('topicrow', array(
 540              'FORUM_ID'                    => $forum_id,
 541              'TOPIC_ID'                    => $topic_id,
 542              'TOPIC_AUTHOR'                => ($row['topic_first_poster_name']) ? $row['topic_first_poster_name'] : $user->lang['GUEST'],
 543              'TOPIC_AUTHOR_COLOUR'        => ($row['topic_first_poster_colour']) ? '#' . $row['topic_first_poster_colour'] : '',
 544              'FIRST_POST_TIME'            => $user->format_date($row['topic_time']),
 545              'LAST_POST_SUBJECT'            => censor_text($row['topic_last_post_subject']),
 546              'LAST_POST_TIME'            => $user->format_date($row['topic_last_post_time']),
 547              'LAST_VIEW_TIME'            => $user->format_date($row['topic_last_view_time']),
 548              'LAST_POST_AUTHOR'            => ($row['topic_last_poster_name']) ? $row['topic_last_poster_name'] : $user->lang['GUEST'],
 549              'LAST_POST_AUTHOR_COLOUR'    => ($row['topic_last_poster_colour']) ? '#' . $row['topic_last_poster_colour'] : '',
 550  
 551              'PAGINATION'        => topic_generate_pagination($replies, $view_topic_url),
 552              'REPLIES'            => $replies,
 553              'VIEWS'                => $row['topic_views'],
 554              'TOPIC_TITLE'        => censor_text($row['topic_title']),
 555              'TOPIC_TYPE'        => $topic_type,
 556  
 557              'TOPIC_FOLDER_IMG'        => $user->img($folder_img, $folder_alt),
 558              'TOPIC_FOLDER_IMG_SRC'    => $user->img($folder_img, $folder_alt, false, '', 'src'),
 559              'TOPIC_ICON_IMG'        => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
 560              'TOPIC_ICON_IMG_WIDTH'    => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
 561              'TOPIC_ICON_IMG_HEIGHT'    => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
 562              'ATTACH_ICON_IMG'        => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
 563              'UNAPPROVED_IMG'        => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
 564  
 565              'S_TOPIC_TYPE'            => $row['topic_type'],
 566              'S_USER_POSTED'            => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
 567              'S_UNREAD_TOPIC'        => $unread_topic,
 568              'S_TOPIC_REPORTED'        => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $forum_id)) ? true : false,
 569              'S_TOPIC_UNAPPROVED'    => $topic_unapproved,
 570              'S_POSTS_UNAPPROVED'    => $posts_unapproved,
 571              'S_HAS_POLL'            => ($row['poll_start']) ? true : false,
 572              'S_POST_ANNOUNCE'        => ($row['topic_type'] == POST_ANNOUNCE) ? true : false,
 573              'S_POST_GLOBAL'            => ($row['topic_type'] == POST_GLOBAL) ? true : false,
 574              'S_POST_STICKY'            => ($row['topic_type'] == POST_STICKY) ? true : false,
 575              'S_TOPIC_LOCKED'        => ($row['topic_status'] == ITEM_LOCKED) ? true : false,
 576              'S_TOPIC_MOVED'            => ($row['topic_status'] == ITEM_MOVED) ? true : false,
 577  
 578              'U_NEWEST_POST'            => $view_topic_url . '&amp;view=unread#unread',
 579              'U_LAST_POST'            => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
 580              'U_LAST_POST_AUTHOR'    => ($row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['topic_last_poster_id']) : '',
 581              'U_TOPIC_AUTHOR'        => ($row['topic_poster'] != ANONYMOUS && $row['topic_poster']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['topic_poster']) : '',
 582              'U_VIEW_TOPIC'            => $view_topic_url,
 583              'U_MCP_REPORT'            => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=reports&amp;f=' . $forum_id . '&amp;t=' . $topic_id, true, $user->session_id),
 584              'U_MCP_QUEUE'            => $u_mcp_queue,
 585  
 586              'S_TOPIC_TYPE_SWITCH'    => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test)
 587          );
 588  
 589          $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
 590  
 591          if ($unread_topic)
 592          {
 593              $mark_forum_read = false;
 594          }
 595  
 596          unset($rowset[$topic_id]);
 597      }
 598  }
 599  
 600  // This is rather a fudge but it's the best I can think of without requiring information
 601  // on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find
 602  // any it updates the forum last read cookie. This requires that the user visit the forum
 603  // after reading a topic
 604  if ($forum_data['forum_type'] == FORUM_POST && sizeof($topic_list) && $mark_forum_read)
 605  {
 606      update_forum_tracking_info($forum_id, $forum_data['forum_last_post_time'], false, $mark_time_forum);
 607  }
 608  
 609  page_footer();
 610  
 611  ?>


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6