[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/ -> index.php (source)

   1  <?php
   2  /***************************************************************************
   3   *                                index.php
   4   *                            -------------------
   5   *   begin                : Saturday, Feb 13, 2001
   6   *   copyright            : (C) 2001 The phpBB Group
   7   *   email                : support@phpbb.com
   8   *
   9   *   $Id: index.php 5502 2006-01-28 11:13:39Z acydburn $
  10   *
  11   *
  12   ***************************************************************************/
  13  
  14  /***************************************************************************
  15   *
  16   *   This program is free software; you can redistribute it and/or modify
  17   *   it under the terms of the GNU General Public License as published by
  18   *   the Free Software Foundation; either version 2 of the License, or
  19   *   (at your option) any later version.
  20   *
  21   ***************************************************************************/
  22  
  23  define('IN_PHPBB', true);
  24  $phpbb_root_path = './';
  25  include ($phpbb_root_path . 'extension.inc');
  26  include($phpbb_root_path . 'common.'.$phpEx);
  27  
  28  //
  29  // Start session management
  30  //
  31  $userdata = session_pagestart($user_ip, PAGE_INDEX);
  32  init_userprefs($userdata);
  33  //
  34  // End session management
  35  //
  36  
  37  $viewcat = ( !empty($HTTP_GET_VARS[POST_CAT_URL]) ) ? $HTTP_GET_VARS[POST_CAT_URL] : -1;
  38  
  39  if( isset($HTTP_GET_VARS['mark']) || isset($HTTP_POST_VARS['mark']) )
  40  {
  41      $mark_read = ( isset($HTTP_POST_VARS['mark']) ) ? $HTTP_POST_VARS['mark'] : $HTTP_GET_VARS['mark'];
  42  }
  43  else
  44  {
  45      $mark_read = '';
  46  }
  47  
  48  //
  49  // Handle marking posts
  50  //
  51  if( $mark_read == 'forums' )
  52  {
  53      if( $userdata['session_logged_in'] )
  54      {
  55          setcookie($board_config['cookie_name'] . '_f_all', time(), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
  56      }
  57  
  58      $template->assign_vars(array(
  59          "META" => '<meta http-equiv="refresh" content="3;url='  .append_sid("index.$phpEx") . '">')
  60      );
  61  
  62      $message = $lang['Forums_marked_read'] . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a> ');
  63  
  64      message_die(GENERAL_MESSAGE, $message);
  65  }
  66  //
  67  // End handle marking posts
  68  //
  69  
  70  $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_t"]) : array();
  71  $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_f"]) : array();
  72  
  73  //
  74  // If you don't use these stats on your index you may want to consider
  75  // removing them
  76  //
  77  $total_posts = get_db_stat('postcount');
  78  $total_users = get_db_stat('usercount');
  79  $newest_userdata = get_db_stat('newestuser');
  80  $newest_user = $newest_userdata['username'];
  81  $newest_uid = $newest_userdata['user_id'];
  82  
  83  if( $total_posts == 0 )
  84  {
  85      $l_total_post_s = $lang['Posted_articles_zero_total'];
  86  }
  87  else if( $total_posts == 1 )
  88  {
  89      $l_total_post_s = $lang['Posted_article_total'];
  90  }
  91  else
  92  {
  93      $l_total_post_s = $lang['Posted_articles_total'];
  94  }
  95  
  96  if( $total_users == 0 )
  97  {
  98      $l_total_user_s = $lang['Registered_users_zero_total'];
  99  }
 100  else if( $total_users == 1 )
 101  {
 102      $l_total_user_s = $lang['Registered_user_total'];
 103  }
 104  else
 105  {
 106      $l_total_user_s = $lang['Registered_users_total'];
 107  }
 108  
 109  
 110  //
 111  // Start page proper
 112  //
 113  $sql = "SELECT c.cat_id, c.cat_title, c.cat_order
 114      FROM " . CATEGORIES_TABLE . " c 
 115      ORDER BY c.cat_order";
 116  if( !($result = $db->sql_query($sql)) )
 117  {
 118      message_die(GENERAL_ERROR, 'Could not query categories list', '', __LINE__, __FILE__, $sql);
 119  }
 120  
 121  $category_rows = array();
 122  while ($row = $db->sql_fetchrow($result))
 123  {
 124      $category_rows[] = $row;
 125  }
 126  $db->sql_freeresult($result);
 127  
 128  if( ( $total_categories = count($category_rows) ) )
 129  {
 130      //
 131      // Define appropriate SQL
 132      //
 133      switch(SQL_LAYER)
 134      {
 135          case 'postgresql':
 136              $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id 
 137                  FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u
 138                  WHERE p.post_id = f.forum_last_post_id 
 139                      AND u.user_id = p.poster_id  
 140                      UNION (
 141                          SELECT f.*, NULL, NULL, NULL, NULL
 142                          FROM " . FORUMS_TABLE . " f
 143                          WHERE NOT EXISTS (
 144                              SELECT p.post_time
 145                              FROM " . POSTS_TABLE . " p
 146                              WHERE p.post_id = f.forum_last_post_id  
 147                          )
 148                      )
 149                      ORDER BY cat_id, forum_order";
 150              break;
 151  
 152          case 'oracle':
 153              $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id 
 154                  FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u
 155                  WHERE p.post_id = f.forum_last_post_id(+)
 156                      AND u.user_id = p.poster_id(+)
 157                  ORDER BY f.cat_id, f.forum_order";
 158              break;
 159  
 160          default:
 161              $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
 162                  FROM (( " . FORUMS_TABLE . " f
 163                  LEFT JOIN " . POSTS_TABLE . " p ON p.post_id = f.forum_last_post_id )
 164                  LEFT JOIN " . USERS_TABLE . " u ON u.user_id = p.poster_id )
 165                  ORDER BY f.cat_id, f.forum_order";
 166              break;
 167      }
 168      if ( !($result = $db->sql_query($sql)) )
 169      {
 170          message_die(GENERAL_ERROR, 'Could not query forums information', '', __LINE__, __FILE__, $sql);
 171      }
 172  
 173      $forum_data = array();
 174      while( $row = $db->sql_fetchrow($result) )
 175      {
 176          $forum_data[] = $row;
 177      }
 178      $db->sql_freeresult($result);
 179  
 180      if ( !($total_forums = count($forum_data)) )
 181      {
 182          message_die(GENERAL_MESSAGE, $lang['No_forums']);
 183      }
 184  
 185      //
 186      // Obtain a list of topic ids which contain
 187      // posts made since user last visited
 188      //
 189      if ($userdata['session_logged_in'])
 190      {
 191          // 60 days limit
 192          if ($userdata['user_lastvisit'] < (time() - 5184000))
 193          {
 194              $userdata['user_lastvisit'] = time() - 5184000;
 195          }
 196  
 197          $sql = "SELECT t.forum_id, t.topic_id, p.post_time 
 198              FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p 
 199              WHERE p.post_id = t.topic_last_post_id 
 200                  AND p.post_time > " . $userdata['user_lastvisit'] . " 
 201                  AND t.topic_moved_id = 0"; 
 202          if ( !($result = $db->sql_query($sql)) )
 203          {
 204              message_die(GENERAL_ERROR, 'Could not query new topic information', '', __LINE__, __FILE__, $sql);
 205          }
 206  
 207          $new_topic_data = array();
 208          while( $topic_data = $db->sql_fetchrow($result) )
 209          {
 210              $new_topic_data[$topic_data['forum_id']][$topic_data['topic_id']] = $topic_data['post_time'];
 211          }
 212          $db->sql_freeresult($result);
 213      }
 214  
 215      //
 216      // Obtain list of moderators of each forum
 217      // First users, then groups ... broken into two queries
 218      //
 219      $sql = "SELECT aa.forum_id, u.user_id, u.username 
 220          FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g, " . USERS_TABLE . " u
 221          WHERE aa.auth_mod = " . TRUE . " 
 222              AND g.group_single_user = 1 
 223              AND ug.group_id = aa.group_id 
 224              AND g.group_id = aa.group_id 
 225              AND u.user_id = ug.user_id 
 226          GROUP BY u.user_id, u.username, aa.forum_id 
 227          ORDER BY aa.forum_id, u.user_id";
 228      if ( !($result = $db->sql_query($sql)) )
 229      {
 230          message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
 231      }
 232  
 233      $forum_moderators = array();
 234      while( $row = $db->sql_fetchrow($result) )
 235      {
 236          $forum_moderators[$row['forum_id']][] = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=" . $row['user_id']) . '">' . $row['username'] . '</a>';
 237      }
 238      $db->sql_freeresult($result);
 239  
 240      $sql = "SELECT aa.forum_id, g.group_id, g.group_name 
 241          FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g 
 242          WHERE aa.auth_mod = " . TRUE . " 
 243              AND g.group_single_user = 0 
 244              AND g.group_type <> " . GROUP_HIDDEN . "
 245              AND ug.group_id = aa.group_id 
 246              AND g.group_id = aa.group_id 
 247          GROUP BY g.group_id, g.group_name, aa.forum_id 
 248          ORDER BY aa.forum_id, g.group_id";
 249      if ( !($result = $db->sql_query($sql)) )
 250      {
 251          message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
 252      }
 253  
 254      while( $row = $db->sql_fetchrow($result) )
 255      {
 256          $forum_moderators[$row['forum_id']][] = '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=" . $row['group_id']) . '">' . $row['group_name'] . '</a>';
 257      }
 258      $db->sql_freeresult($result);
 259  
 260      //
 261      // Find which forums are visible for this user
 262      //
 263      $is_auth_ary = array();
 264      $is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata, $forum_data);
 265  
 266      //
 267      // Start output of page
 268      //
 269      define('SHOW_ONLINE', true);
 270      $page_title = $lang['Index'];
 271      include($phpbb_root_path . 'includes/page_header.'.$phpEx);
 272  
 273      $template->set_filenames(array(
 274          'body' => 'index_body.tpl')
 275      );
 276  
 277      $template->assign_vars(array(
 278          'TOTAL_POSTS' => sprintf($l_total_post_s, $total_posts),
 279          'TOTAL_USERS' => sprintf($l_total_user_s, $total_users),
 280          'NEWEST_USER' => sprintf($lang['Newest_user'], '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$newest_uid") . '">', $newest_user, '</a>'), 
 281  
 282          'FORUM_IMG' => $images['forum'],
 283          'FORUM_NEW_IMG' => $images['forum_new'],
 284          'FORUM_LOCKED_IMG' => $images['forum_locked'],
 285  
 286          'L_FORUM' => $lang['Forum'],
 287          'L_TOPICS' => $lang['Topics'],
 288          'L_REPLIES' => $lang['Replies'],
 289          'L_VIEWS' => $lang['Views'],
 290          'L_POSTS' => $lang['Posts'],
 291          'L_LASTPOST' => $lang['Last_Post'], 
 292          'L_NO_NEW_POSTS' => $lang['No_new_posts'],
 293          'L_NEW_POSTS' => $lang['New_posts'],
 294          'L_NO_NEW_POSTS_LOCKED' => $lang['No_new_posts_locked'], 
 295          'L_NEW_POSTS_LOCKED' => $lang['New_posts_locked'], 
 296          'L_ONLINE_EXPLAIN' => $lang['Online_explain'], 
 297  
 298          'L_MODERATOR' => $lang['Moderators'], 
 299          'L_FORUM_LOCKED' => $lang['Forum_is_locked'],
 300          'L_MARK_FORUMS_READ' => $lang['Mark_all_forums'], 
 301  
 302          'U_MARK_READ' => append_sid("index.$phpEx?mark=forums"))
 303      );
 304  
 305      //
 306      // Let's decide which categories we should display
 307      //
 308      $display_categories = array();
 309  
 310      for ($i = 0; $i < $total_forums; $i++ )
 311      {
 312          if ($is_auth_ary[$forum_data[$i]['forum_id']]['auth_view'])
 313          {
 314              $display_categories[$forum_data[$i]['cat_id']] = true;
 315          }
 316      }
 317  
 318      //
 319      // Okay, let's build the index
 320      //
 321      for($i = 0; $i < $total_categories; $i++)
 322      {
 323          $cat_id = $category_rows[$i]['cat_id'];
 324  
 325          //
 326          // Yes, we should, so first dump out the category
 327          // title, then, if appropriate the forum list
 328          //
 329          if (isset($display_categories[$cat_id]) && $display_categories[$cat_id])
 330          {
 331              $template->assign_block_vars('catrow', array(
 332                  'CAT_ID' => $cat_id,
 333                  'CAT_DESC' => $category_rows[$i]['cat_title'],
 334                  'U_VIEWCAT' => append_sid("index.$phpEx?" . POST_CAT_URL . "=$cat_id"))
 335              );
 336  
 337              if ( $viewcat == $cat_id || $viewcat == -1 )
 338              {
 339                  for($j = 0; $j < $total_forums; $j++)
 340                  {
 341                      if ( $forum_data[$j]['cat_id'] == $cat_id )
 342                      {
 343                          $forum_id = $forum_data[$j]['forum_id'];
 344  
 345                          if ( $is_auth_ary[$forum_id]['auth_view'] )
 346                          {
 347                              if ( $forum_data[$j]['forum_status'] == FORUM_LOCKED )
 348                              {
 349                                  $folder_image = $images['forum_locked']; 
 350                                  $folder_alt = $lang['Forum_locked'];
 351                              }
 352                              else
 353                              {
 354                                  $unread_topics = false;
 355                                  if ( $userdata['session_logged_in'] )
 356                                  {
 357                                      if ( !empty($new_topic_data[$forum_id]) )
 358                                      {
 359                                          $forum_last_post_time = 0;
 360  
 361                                          while( list($check_topic_id, $check_post_time) = @each($new_topic_data[$forum_id]) )
 362                                          {
 363                                              if ( empty($tracking_topics[$check_topic_id]) )
 364                                              {
 365                                                  $unread_topics = true;
 366                                                  $forum_last_post_time = max($check_post_time, $forum_last_post_time);
 367  
 368                                              }
 369                                              else
 370                                              {
 371                                                  if ( $tracking_topics[$check_topic_id] < $check_post_time )
 372                                                  {
 373                                                      $unread_topics = true;
 374                                                      $forum_last_post_time = max($check_post_time, $forum_last_post_time);
 375                                                  }
 376                                              }
 377                                          }
 378  
 379                                          if ( !empty($tracking_forums[$forum_id]) )
 380                                          {
 381                                              if ( $tracking_forums[$forum_id] > $forum_last_post_time )
 382                                              {
 383                                                  $unread_topics = false;
 384                                              }
 385                                          }
 386  
 387                                          if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
 388                                          {
 389                                              if ( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] > $forum_last_post_time )
 390                                              {
 391                                                  $unread_topics = false;
 392                                              }
 393                                          }
 394  
 395                                      }
 396                                  }
 397  
 398                                  $folder_image = ( $unread_topics ) ? $images['forum_new'] : $images['forum']; 
 399                                  $folder_alt = ( $unread_topics ) ? $lang['New_posts'] : $lang['No_new_posts']; 
 400                              }
 401  
 402                              $posts = $forum_data[$j]['forum_posts'];
 403                              $topics = $forum_data[$j]['forum_topics'];
 404  
 405                              if ( $forum_data[$j]['forum_last_post_id'] )
 406                              {
 407                                  $last_post_time = create_date($board_config['default_dateformat'], $forum_data[$j]['post_time'], $board_config['board_timezone']);
 408  
 409                                  $last_post = $last_post_time . '<br />';
 410  
 411                                  $last_post .= ( $forum_data[$j]['user_id'] == ANONYMOUS ) ? ( ($forum_data[$j]['post_username'] != '' ) ? $forum_data[$j]['post_username'] . ' ' : $lang['Guest'] . ' ' ) : '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '='  . $forum_data[$j]['user_id']) . '">' . $forum_data[$j]['username'] . '</a> ';
 412                                  
 413                                  $last_post .= '<a href="' . append_sid("viewtopic.$phpEx?"  . POST_POST_URL . '=' . $forum_data[$j]['forum_last_post_id']) . '#' . $forum_data[$j]['forum_last_post_id'] . '"><img src="' . $images['icon_latest_reply'] . '" border="0" alt="' . $lang['View_latest_post'] . '" title="' . $lang['View_latest_post'] . '" /></a>';
 414                              }
 415                              else
 416                              {
 417                                  $last_post = $lang['No_Posts'];
 418                              }
 419  
 420                              if ( count($forum_moderators[$forum_id]) > 0 )
 421                              {
 422                                  $l_moderators = ( count($forum_moderators[$forum_id]) == 1 ) ? $lang['Moderator'] : $lang['Moderators'];
 423                                  $moderator_list = implode(', ', $forum_moderators[$forum_id]);
 424                              }
 425                              else
 426                              {
 427                                  $l_moderators = '&nbsp;';
 428                                  $moderator_list = '&nbsp;';
 429                              }
 430  
 431                              $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
 432                              $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
 433  
 434                              $template->assign_block_vars('catrow.forumrow',    array(
 435                                  'ROW_COLOR' => '#' . $row_color,
 436                                  'ROW_CLASS' => $row_class,
 437                                  'FORUM_FOLDER_IMG' => $folder_image, 
 438                                  'FORUM_NAME' => $forum_data[$j]['forum_name'],
 439                                  'FORUM_DESC' => $forum_data[$j]['forum_desc'],
 440                                  'POSTS' => $forum_data[$j]['forum_posts'],
 441                                  'TOPICS' => $forum_data[$j]['forum_topics'],
 442                                  'LAST_POST' => $last_post,
 443                                  'MODERATORS' => $moderator_list,
 444  
 445                                  'L_MODERATOR' => $l_moderators, 
 446                                  'L_FORUM_FOLDER_ALT' => $folder_alt, 
 447  
 448                                  'U_VIEWFORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"))
 449                              );
 450                          }
 451                      }
 452                  }
 453              }
 454          }
 455      } // for ... categories
 456  
 457  }// if ... total_categories
 458  else
 459  {
 460      message_die(GENERAL_MESSAGE, $lang['No_forums']);
 461  }
 462  
 463  //
 464  // Generate the page
 465  //
 466  $template->pparse('body');
 467  
 468  include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
 469  
 470  ?>


Generated: Mon Jan 14 19:21:40 2013 Cross-referenced by PHPXref 0.7.1