[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/includes/ -> page_header.php (source)

   1  <?php
   2  /***************************************************************************
   3   *                              page_header.php
   4   *                            -------------------
   5   *   begin                : Saturday, Feb 13, 2001
   6   *   copyright            : (C) 2001 The phpBB Group
   7   *   email                : support@phpbb.com
   8   *
   9   *   $Id: page_header.php 5283 2005-10-30 15:17:14Z 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  if ( !defined('IN_PHPBB') )
  24  {
  25      die("Hacking attempt");
  26  }
  27  
  28  define('HEADER_INC', TRUE);
  29  
  30  //
  31  // gzip_compression
  32  //
  33  $do_gzip_compress = FALSE;
  34  if ( $board_config['gzip_compress'] )
  35  {
  36      $phpver = phpversion();
  37  
  38      $useragent = (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) ? $HTTP_SERVER_VARS['HTTP_USER_AGENT'] : getenv('HTTP_USER_AGENT');
  39  
  40      if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) )
  41      {
  42          if ( extension_loaded('zlib') )
  43          {
  44              ob_start('ob_gzhandler');
  45          }
  46      }
  47      else if ( $phpver > '4.0' )
  48      {
  49          if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') )
  50          {
  51              if ( extension_loaded('zlib') )
  52              {
  53                  $do_gzip_compress = TRUE;
  54                  ob_start();
  55                  ob_implicit_flush(0);
  56  
  57                  header('Content-Encoding: gzip');
  58              }
  59          }
  60      }
  61  }
  62  
  63  //
  64  // Parse and show the overall header.
  65  //
  66  $template->set_filenames(array(
  67      'overall_header' => ( empty($gen_simple_header) ) ? 'overall_header.tpl' : 'simple_header.tpl')
  68  );
  69  
  70  //
  71  // Generate logged in/logged out status
  72  //
  73  if ( $userdata['session_logged_in'] )
  74  {
  75      $u_login_logout = 'login.'.$phpEx.'?logout=true&amp;sid=' . $userdata['session_id'];
  76      $l_login_logout = $lang['Logout'] . ' [ ' . $userdata['username'] . ' ]';
  77  }
  78  else
  79  {
  80      $u_login_logout = 'login.'.$phpEx;
  81      $l_login_logout = $lang['Login'];
  82  }
  83  
  84  $s_last_visit = ( $userdata['session_logged_in'] ) ? create_date($board_config['default_dateformat'], $userdata['user_lastvisit'], $board_config['board_timezone']) : '';
  85  
  86  //
  87  // Get basic (usernames + totals) online
  88  // situation
  89  //
  90  $logged_visible_online = 0;
  91  $logged_hidden_online = 0;
  92  $guests_online = 0;
  93  $online_userlist = '';
  94  $l_online_users = '';
  95  
  96  if (defined('SHOW_ONLINE'))
  97  {
  98  
  99      $user_forum_sql = ( !empty($forum_id) ) ? "AND s.session_page = " . intval($forum_id) : '';
 100      $sql = "SELECT u.username, u.user_id, u.user_allow_viewonline, u.user_level, s.session_logged_in, s.session_ip
 101          FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s
 102          WHERE u.user_id = s.session_user_id
 103              AND s.session_time >= ".( time() - 300 ) . "
 104              $user_forum_sql
 105          ORDER BY u.username ASC, s.session_ip ASC";
 106      if( !($result = $db->sql_query($sql)) )
 107      {
 108          message_die(GENERAL_ERROR, 'Could not obtain user/online information', '', __LINE__, __FILE__, $sql);
 109      }
 110  
 111      $userlist_ary = array();
 112      $userlist_visible = array();
 113  
 114      $prev_user_id = 0;
 115      $prev_user_ip = $prev_session_ip = '';
 116  
 117      while( $row = $db->sql_fetchrow($result) )
 118      {
 119          // User is logged in and therefor not a guest
 120          if ( $row['session_logged_in'] )
 121          {
 122              // Skip multiple sessions for one user
 123              if ( $row['user_id'] != $prev_user_id )
 124              {
 125                  $style_color = '';
 126                  if ( $row['user_level'] == ADMIN )
 127                  {
 128                      $row['username'] = '<b>' . $row['username'] . '</b>';
 129                      $style_color = 'style="color:#' . $theme['fontcolor3'] . '"';
 130                  }
 131                  else if ( $row['user_level'] == MOD )
 132                  {
 133                      $row['username'] = '<b>' . $row['username'] . '</b>';
 134                      $style_color = 'style="color:#' . $theme['fontcolor2'] . '"';
 135                  }
 136  
 137                  if ( $row['user_allow_viewonline'] )
 138                  {
 139                      $user_online_link = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=" . $row['user_id']) . '"' . $style_color .'>' . $row['username'] . '</a>';
 140                      $logged_visible_online++;
 141                  }
 142                  else
 143                  {
 144                      $user_online_link = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=" . $row['user_id']) . '"' . $style_color .'><i>' . $row['username'] . '</i></a>';
 145                      $logged_hidden_online++;
 146                  }
 147  
 148                  if ( $row['user_allow_viewonline'] || $userdata['user_level'] == ADMIN )
 149                  {
 150                      $online_userlist .= ( $online_userlist != '' ) ? ', ' . $user_online_link : $user_online_link;
 151                  }
 152              }
 153  
 154              $prev_user_id = $row['user_id'];
 155          }
 156          else
 157          {
 158              // Skip multiple sessions for one user
 159              if ( $row['session_ip'] != $prev_session_ip )
 160              {
 161                  $guests_online++;
 162              }
 163          }
 164  
 165          $prev_session_ip = $row['session_ip'];
 166      }
 167      $db->sql_freeresult($result);
 168  
 169      if ( empty($online_userlist) )
 170      {
 171          $online_userlist = $lang['None'];
 172      }
 173      $online_userlist = ( ( isset($forum_id) ) ? $lang['Browsing_forum'] : $lang['Registered_users'] ) . ' ' . $online_userlist;
 174  
 175      $total_online_users = $logged_visible_online + $logged_hidden_online + $guests_online;
 176  
 177      if ( $total_online_users > $board_config['record_online_users'])
 178      {
 179          $board_config['record_online_users'] = $total_online_users;
 180          $board_config['record_online_date'] = time();
 181  
 182          $sql = "UPDATE " . CONFIG_TABLE . "
 183              SET config_value = '$total_online_users'
 184              WHERE config_name = 'record_online_users'";
 185          if ( !$db->sql_query($sql) )
 186          {
 187              message_die(GENERAL_ERROR, 'Could not update online user record (nr of users)', '', __LINE__, __FILE__, $sql);
 188          }
 189  
 190          $sql = "UPDATE " . CONFIG_TABLE . "
 191              SET config_value = '" . $board_config['record_online_date'] . "'
 192              WHERE config_name = 'record_online_date'";
 193          if ( !$db->sql_query($sql) )
 194          {
 195              message_die(GENERAL_ERROR, 'Could not update online user record (date)', '', __LINE__, __FILE__, $sql);
 196          }
 197      }
 198  
 199      if ( $total_online_users == 0 )
 200      {
 201          $l_t_user_s = $lang['Online_users_zero_total'];
 202      }
 203      else if ( $total_online_users == 1 )
 204      {
 205          $l_t_user_s = $lang['Online_user_total'];
 206      }
 207      else
 208      {
 209          $l_t_user_s = $lang['Online_users_total'];
 210      }
 211  
 212      if ( $logged_visible_online == 0 )
 213      {
 214          $l_r_user_s = $lang['Reg_users_zero_total'];
 215      }
 216      else if ( $logged_visible_online == 1 )
 217      {
 218          $l_r_user_s = $lang['Reg_user_total'];
 219      }
 220      else
 221      {
 222          $l_r_user_s = $lang['Reg_users_total'];
 223      }
 224  
 225      if ( $logged_hidden_online == 0 )
 226      {
 227          $l_h_user_s = $lang['Hidden_users_zero_total'];
 228      }
 229      else if ( $logged_hidden_online == 1 )
 230      {
 231          $l_h_user_s = $lang['Hidden_user_total'];
 232      }
 233      else
 234      {
 235          $l_h_user_s = $lang['Hidden_users_total'];
 236      }
 237  
 238      if ( $guests_online == 0 )
 239      {
 240          $l_g_user_s = $lang['Guest_users_zero_total'];
 241      }
 242      else if ( $guests_online == 1 )
 243      {
 244          $l_g_user_s = $lang['Guest_user_total'];
 245      }
 246      else
 247      {
 248          $l_g_user_s = $lang['Guest_users_total'];
 249      }
 250  
 251      $l_online_users = sprintf($l_t_user_s, $total_online_users);
 252      $l_online_users .= sprintf($l_r_user_s, $logged_visible_online);
 253      $l_online_users .= sprintf($l_h_user_s, $logged_hidden_online);
 254      $l_online_users .= sprintf($l_g_user_s, $guests_online);
 255  }
 256  
 257  //
 258  // Obtain number of new private messages
 259  // if user is logged in
 260  //
 261  if ( ($userdata['session_logged_in']) && (empty($gen_simple_header)) )
 262  {
 263      if ( $userdata['user_new_privmsg'] )
 264      {
 265          $l_message_new = ( $userdata['user_new_privmsg'] == 1 ) ? $lang['New_pm'] : $lang['New_pms'];
 266          $l_privmsgs_text = sprintf($l_message_new, $userdata['user_new_privmsg']);
 267  
 268          if ( $userdata['user_last_privmsg'] > $userdata['user_lastvisit'] )
 269          {
 270              $sql = "UPDATE " . USERS_TABLE . "
 271                  SET user_last_privmsg = " . $userdata['user_lastvisit'] . "
 272                  WHERE user_id = " . $userdata['user_id'];
 273              if ( !$db->sql_query($sql) )
 274              {
 275                  message_die(GENERAL_ERROR, 'Could not update private message new/read time for user', '', __LINE__, __FILE__, $sql);
 276              }
 277  
 278              $s_privmsg_new = 1;
 279              $icon_pm = $images['pm_new_msg'];
 280          }
 281          else
 282          {
 283              $s_privmsg_new = 0;
 284              $icon_pm = $images['pm_new_msg'];
 285          }
 286      }
 287      else
 288      {
 289          $l_privmsgs_text = $lang['No_new_pm'];
 290  
 291          $s_privmsg_new = 0;
 292          $icon_pm = $images['pm_no_new_msg'];
 293      }
 294  
 295      if ( $userdata['user_unread_privmsg'] )
 296      {
 297          $l_message_unread = ( $userdata['user_unread_privmsg'] == 1 ) ? $lang['Unread_pm'] : $lang['Unread_pms'];
 298          $l_privmsgs_text_unread = sprintf($l_message_unread, $userdata['user_unread_privmsg']);
 299      }
 300      else
 301      {
 302          $l_privmsgs_text_unread = $lang['No_unread_pm'];
 303      }
 304  }
 305  else
 306  {
 307      $icon_pm = $images['pm_no_new_msg'];
 308      $l_privmsgs_text = $lang['Login_check_pm'];
 309      $l_privmsgs_text_unread = '';
 310      $s_privmsg_new = 0;
 311  }
 312  
 313  //
 314  // Generate HTML required for Mozilla Navigation bar
 315  //
 316  if (!isset($nav_links))
 317  {
 318      $nav_links = array();
 319  }
 320  
 321  $nav_links_html = '';
 322  $nav_link_proto = '<link rel="%s" href="%s" title="%s" />' . "\n";
 323  while( list($nav_item, $nav_array) = @each($nav_links) )
 324  {
 325      if ( !empty($nav_array['url']) )
 326      {
 327          $nav_links_html .= sprintf($nav_link_proto, $nav_item, append_sid($nav_array['url']), $nav_array['title']);
 328      }
 329      else
 330      {
 331          // We have a nested array, used for items like <link rel='chapter'> that can occur more than once.
 332          while( list(,$nested_array) = each($nav_array) )
 333          {
 334              $nav_links_html .= sprintf($nav_link_proto, $nav_item, $nested_array['url'], $nested_array['title']);
 335          }
 336      }
 337  }
 338  
 339  // Format Timezone. We are unable to use array_pop here, because of PHP3 compatibility
 340  $l_timezone = explode('.', $board_config['board_timezone']);
 341  $l_timezone = (count($l_timezone) > 1 && $l_timezone[count($l_timezone)-1] != 0) ? $lang[sprintf('%.1f', $board_config['board_timezone'])] : $lang[number_format($board_config['board_timezone'])];
 342  //
 343  // The following assigns all _common_ variables that may be used at any point
 344  // in a template.
 345  //
 346  $template->assign_vars(array(
 347      'SITENAME' => $board_config['sitename'],
 348      'SITE_DESCRIPTION' => $board_config['site_desc'],
 349      'PAGE_TITLE' => $page_title,
 350      'LAST_VISIT_DATE' => sprintf($lang['You_last_visit'], $s_last_visit),
 351      'CURRENT_TIME' => sprintf($lang['Current_time'], create_date($board_config['default_dateformat'], time(), $board_config['board_timezone'])),
 352      'TOTAL_USERS_ONLINE' => $l_online_users,
 353      'LOGGED_IN_USER_LIST' => $online_userlist,
 354      'RECORD_USERS' => sprintf($lang['Record_online_users'], $board_config['record_online_users'], create_date($board_config['default_dateformat'], $board_config['record_online_date'], $board_config['board_timezone'])),
 355      'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text,
 356      'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread,
 357      'PRIVATE_MESSAGE_NEW_FLAG' => $s_privmsg_new,
 358  
 359      'PRIVMSG_IMG' => $icon_pm,
 360  
 361      'L_USERNAME' => $lang['Username'],
 362      'L_PASSWORD' => $lang['Password'],
 363      'L_LOGIN_LOGOUT' => $l_login_logout,
 364      'L_LOGIN' => $lang['Login'],
 365      'L_LOG_ME_IN' => $lang['Log_me_in'],
 366      'L_AUTO_LOGIN' => $lang['Log_me_in'],
 367      'L_INDEX' => sprintf($lang['Forum_Index'], $board_config['sitename']),
 368      'L_REGISTER' => $lang['Register'],
 369      'L_PROFILE' => $lang['Profile'],
 370      'L_SEARCH' => $lang['Search'],
 371      'L_PRIVATEMSGS' => $lang['Private_Messages'],
 372      'L_WHO_IS_ONLINE' => $lang['Who_is_Online'],
 373      'L_MEMBERLIST' => $lang['Memberlist'],
 374      'L_FAQ' => $lang['FAQ'],
 375      'L_USERGROUPS' => $lang['Usergroups'],
 376      'L_SEARCH_NEW' => $lang['Search_new'],
 377      'L_SEARCH_UNANSWERED' => $lang['Search_unanswered'],
 378      'L_SEARCH_SELF' => $lang['Search_your_posts'],
 379      'L_WHOSONLINE_ADMIN' => sprintf($lang['Admin_online_color'], '<span style="color:#' . $theme['fontcolor3'] . '">', '</span>'),
 380      'L_WHOSONLINE_MOD' => sprintf($lang['Mod_online_color'], '<span style="color:#' . $theme['fontcolor2'] . '">', '</span>'),
 381  
 382      'U_SEARCH_UNANSWERED' => append_sid('search.'.$phpEx.'?search_id=unanswered'),
 383      'U_SEARCH_SELF' => append_sid('search.'.$phpEx.'?search_id=egosearch'),
 384      'U_SEARCH_NEW' => append_sid('search.'.$phpEx.'?search_id=newposts'),
 385      'U_INDEX' => append_sid('index.'.$phpEx),
 386      'U_REGISTER' => append_sid('profile.'.$phpEx.'?mode=register'),
 387      'U_PROFILE' => append_sid('profile.'.$phpEx.'?mode=editprofile'),
 388      'U_PRIVATEMSGS' => append_sid('privmsg.'.$phpEx.'?folder=inbox'),
 389      'U_PRIVATEMSGS_POPUP' => append_sid('privmsg.'.$phpEx.'?mode=newpm'),
 390      'U_SEARCH' => append_sid('search.'.$phpEx),
 391      'U_MEMBERLIST' => append_sid('memberlist.'.$phpEx),
 392      'U_MODCP' => append_sid('modcp.'.$phpEx),
 393      'U_FAQ' => append_sid('faq.'.$phpEx),
 394      'U_VIEWONLINE' => append_sid('viewonline.'.$phpEx),
 395      'U_LOGIN_LOGOUT' => append_sid($u_login_logout),
 396      'U_GROUP_CP' => append_sid('groupcp.'.$phpEx),
 397  
 398      'S_CONTENT_DIRECTION' => $lang['DIRECTION'],
 399      'S_CONTENT_ENCODING' => $lang['ENCODING'],
 400      'S_CONTENT_DIR_LEFT' => $lang['LEFT'],
 401      'S_CONTENT_DIR_RIGHT' => $lang['RIGHT'],
 402      'S_TIMEZONE' => sprintf($lang['All_times'], $l_timezone),
 403      'S_LOGIN_ACTION' => append_sid('login.'.$phpEx),
 404  
 405      'T_HEAD_STYLESHEET' => $theme['head_stylesheet'],
 406      'T_BODY_BACKGROUND' => $theme['body_background'],
 407      'T_BODY_BGCOLOR' => '#'.$theme['body_bgcolor'],
 408      'T_BODY_TEXT' => '#'.$theme['body_text'],
 409      'T_BODY_LINK' => '#'.$theme['body_link'],
 410      'T_BODY_VLINK' => '#'.$theme['body_vlink'],
 411      'T_BODY_ALINK' => '#'.$theme['body_alink'],
 412      'T_BODY_HLINK' => '#'.$theme['body_hlink'],
 413      'T_TR_COLOR1' => '#'.$theme['tr_color1'],
 414      'T_TR_COLOR2' => '#'.$theme['tr_color2'],
 415      'T_TR_COLOR3' => '#'.$theme['tr_color3'],
 416      'T_TR_CLASS1' => $theme['tr_class1'],
 417      'T_TR_CLASS2' => $theme['tr_class2'],
 418      'T_TR_CLASS3' => $theme['tr_class3'],
 419      'T_TH_COLOR1' => '#'.$theme['th_color1'],
 420      'T_TH_COLOR2' => '#'.$theme['th_color2'],
 421      'T_TH_COLOR3' => '#'.$theme['th_color3'],
 422      'T_TH_CLASS1' => $theme['th_class1'],
 423      'T_TH_CLASS2' => $theme['th_class2'],
 424      'T_TH_CLASS3' => $theme['th_class3'],
 425      'T_TD_COLOR1' => '#'.$theme['td_color1'],
 426      'T_TD_COLOR2' => '#'.$theme['td_color2'],
 427      'T_TD_COLOR3' => '#'.$theme['td_color3'],
 428      'T_TD_CLASS1' => $theme['td_class1'],
 429      'T_TD_CLASS2' => $theme['td_class2'],
 430      'T_TD_CLASS3' => $theme['td_class3'],
 431      'T_FONTFACE1' => $theme['fontface1'],
 432      'T_FONTFACE2' => $theme['fontface2'],
 433      'T_FONTFACE3' => $theme['fontface3'],
 434      'T_FONTSIZE1' => $theme['fontsize1'],
 435      'T_FONTSIZE2' => $theme['fontsize2'],
 436      'T_FONTSIZE3' => $theme['fontsize3'],
 437      'T_FONTCOLOR1' => '#'.$theme['fontcolor1'],
 438      'T_FONTCOLOR2' => '#'.$theme['fontcolor2'],
 439      'T_FONTCOLOR3' => '#'.$theme['fontcolor3'],
 440      'T_SPAN_CLASS1' => $theme['span_class1'],
 441      'T_SPAN_CLASS2' => $theme['span_class2'],
 442      'T_SPAN_CLASS3' => $theme['span_class3'],
 443  
 444      'NAV_LINKS' => $nav_links_html)
 445  );
 446  
 447  //
 448  // Login box?
 449  //
 450  if ( !$userdata['session_logged_in'] )
 451  {
 452      $template->assign_block_vars('switch_user_logged_out', array());
 453      //
 454      // Allow autologin?
 455      //
 456      if (!isset($board_config['allow_autologin']) || $board_config['allow_autologin'] )
 457      {
 458          $template->assign_block_vars('switch_allow_autologin', array());
 459          $template->assign_block_vars('switch_user_logged_out.switch_allow_autologin', array());
 460      }
 461  }
 462  else
 463  {
 464      $template->assign_block_vars('switch_user_logged_in', array());
 465  
 466      if ( !empty($userdata['user_popup_pm']) )
 467      {
 468          $template->assign_block_vars('switch_enable_pm_popup', array());
 469      }
 470  }
 471  
 472  // Add no-cache control for cookies if they are set
 473  //$c_no_cache = (isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_data'])) ? 'no-cache="set-cookie", ' : '';
 474  
 475  // Work around for "current" Apache 2 + PHP module which seems to not
 476  // cope with private cache control setting
 477  if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2'))
 478  {
 479      header ('Cache-Control: no-cache, pre-check=0, post-check=0');
 480  }
 481  else
 482  {
 483      header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
 484  }
 485  header ('Expires: 0');
 486  header ('Pragma: no-cache');
 487  
 488  $template->pparse('overall_header');
 489  
 490  ?>


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