MyBB PHP Cross Reference Discussion Forums

Source: /global.php - 739 lines - 21734 bytes - Summary - Text - Print

Description: MyBB 1.6 Copyright 2010 MyBB Group, All Rights Reserved

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  $working_dir = dirname(__FILE__);
  13  if(!$working_dir)
  14  {
  15      $working_dir = '.';
  16  }
  17  
  18  // Load main MyBB core file which begins all of the magic
  19  require_once $working_dir."/inc/init.php";
  20  
  21  $shutdown_queries = array();
  22  
  23  // Read the usergroups cache as well as the moderators cache
  24  $groupscache = $cache->read("usergroups");
  25  
  26  // If the groups cache doesn't exist, update it and re-read it
  27  if(!is_array($groupscache))
  28  {
  29      $cache->update_usergroups();
  30      $groupscache = $cache->read("usergroups");
  31  }
  32  
  33  if(!defined('THIS_SCRIPT'))
  34  {
  35      define('THIS_SCRIPT', '');
  36  }
  37  
  38  $current_page = my_strtolower(basename(THIS_SCRIPT));
  39  
  40  // Send page headers - don't send no-cache headers for attachment.php
  41  if($current_page != "attachment.php")
  42  {
  43      send_page_headers();
  44  }
  45  
  46  // Do not use session system for defined pages
  47  if((@isset($mybb->input['action']) && @isset($nosession[$mybb->input['action']])) || (@isset($mybb->input['thumbnail']) && $current_page == 'attachment.php'))
  48  {
  49      define("NO_ONLINE", 1);
  50  }
  51  
  52  // Create session for this user
  53  require_once  MYBB_ROOT."inc/class_session.php";
  54  $session = new session;
  55  $session->init();
  56  $mybb->session = &$session;
  57  
  58  $mybb->user['ismoderator'] = is_moderator("", "", $mybb->user['uid']);
  59  
  60  // Set our POST validation code here
  61  $mybb->post_code = generate_post_check();
  62  
  63  // Set and load the language
  64  if(!empty($mybb->input['language']) && $lang->language_exists($mybb->input['language']) && verify_post_check($mybb->input['my_post_key'], true))
  65  {
  66      $mybb->settings['bblanguage'] = $mybb->input['language'];
  67      // If user is logged in, update their language selection with the new one
  68      if($mybb->user['uid'])
  69      {
  70          if($mybb->cookies['mybblang'])
  71          {
  72              my_unsetcookie("mybblang");
  73          }
  74  
  75          $db->update_query("users", array("language" => $db->escape_string($mybb->settings['bblanguage'])), "uid='{$mybb->user['uid']}'");
  76      }
  77      // Guest = cookie
  78      else
  79      {
  80          my_setcookie("mybblang", $mybb->settings['bblanguage']);
  81      }
  82      $mybb->user['language'] = $mybb->settings['bblanguage'];
  83  }
  84  // Cookied language!
  85  else if(!$mybb->user['uid'] && !empty($mybb->cookies['mybblang']) && $lang->language_exists($mybb->cookies['mybblang']))
  86  {
  87      $mybb->settings['bblanguage'] = $mybb->cookies['mybblang'];
  88  }
  89  else if(!isset($mybb->settings['bblanguage']))
  90  {
  91      $mybb->settings['bblanguage'] = "english";
  92  }
  93  
  94  // Load language
  95  $lang->set_language($mybb->settings['bblanguage']);
  96  $lang->load("global");
  97  $lang->load("messages");
  98  $newpmmsg = '';
  99  
 100  // Run global_start plugin hook now that the basics are set up
 101  $plugins->run_hooks("global_start");
 102  
 103  if(function_exists('mb_internal_encoding') && !empty($lang->settings['charset']))
 104  {
 105      @mb_internal_encoding($lang->settings['charset']);
 106  }
 107  
 108  // Select the board theme to use.
 109  $loadstyle = '';
 110  $load_from_forum = 0;
 111  $style = array();
 112  
 113  // This user has a custom theme set in their profile
 114  if(isset($mybb->user['style']) && intval($mybb->user['style']) != 0)
 115  {
 116      $loadstyle = "tid='".$mybb->user['style']."'";
 117  }
 118  
 119  $valid = array(
 120      "showthread.php", 
 121      "forumdisplay.php",
 122      "newthread.php",
 123      "newreply.php",
 124      "ratethread.php",
 125      "editpost.php",
 126      "polls.php",
 127      "sendthread.php",
 128      "printthread.php",
 129      "moderation.php"
 130  );
 131  
 132  if(in_array($current_page, $valid))
 133  {
 134      cache_forums();
 135  
 136      // If we're accessing a post, fetch the forum theme for it and if we're overriding it
 137      if(!empty($mybb->input['pid']) && THIS_SCRIPT != "polls.php")
 138      {
 139          $query = $db->simple_select("posts", "fid", "pid = '".intval($mybb->input['pid'])."'", array("limit" => 1));
 140          $fid = $db->fetch_field($query, "fid");
 141  
 142          if($fid)
 143          {
 144              $style = $forum_cache[$fid];
 145              $load_from_forum = 1;
 146          }
 147      }
 148      // We have a thread id and a forum id, we can easily fetch the theme for this forum
 149      else if(!empty($mybb->input['tid']))
 150      {
 151          $query = $db->simple_select("threads", "fid", "tid = '".intval($mybb->input['tid'])."'", array("limit" => 1));
 152          $fid = $db->fetch_field($query, "fid");
 153  
 154          if($fid)
 155          {
 156              $style = $forum_cache[$fid];
 157              $load_from_forum = 1;
 158          }
 159      }
 160      // If we're accessing poll results, fetch the forum theme for it and if we're overriding it
 161      else if(!empty($mybb->input['pid']) && THIS_SCRIPT == "polls.php")
 162      {
 163          $query = $db->simple_select("threads", "fid", "poll = '".intval($mybb->input['pid'])."'", array("limit" => 1));
 164          $fid = $db->fetch_field($query, "fid");
 165  
 166          if($fid)
 167          {
 168              $style = $forum_cache[$fid];
 169              $load_from_forum = 1;
 170          }
 171      }
 172      // We have a forum id - simply load the theme from it
 173      else if($mybb->input['fid'])
 174      {
 175          $style = $forum_cache[intval($mybb->input['fid'])];
 176          $load_from_forum = 1;
 177      }
 178  }
 179  unset($valid);
 180  
 181  // From all of the above, a theme was found
 182  if(isset($style['style']) && $style['style'] > 0)
 183  {
 184      // This theme is forced upon the user, overriding their selection
 185      if($style['overridestyle'] == 1 || !isset($mybb->user['style']))
 186      {
 187          $loadstyle = "tid='".intval($style['style'])."'";
 188      }
 189  }
 190  
 191  // After all of that no theme? Load the board default
 192  if(empty($loadstyle))
 193  {
 194      $loadstyle = "def='1'";
 195  }
 196  
 197  // Fetch the theme to load from the database
 198  $query = $db->simple_select("themes", "name, tid, properties, stylesheets", $loadstyle, array('limit' => 1));
 199  $theme = $db->fetch_array($query);
 200  
 201  // No theme was found - we attempt to load the master or any other theme
 202  if(!$theme['tid'])
 203  {
 204      // Missing theme was from a forum, run a query to set any forums using the theme to the default
 205      if($load_from_forum == 1)
 206      {
 207          $db->update_query("forums", array("style" => 0), "style='{$style['style']}'");
 208      }
 209      // Missing theme was from a user, run a query to set any users using the theme to the default
 210      else if($load_from_user == 1)
 211      {
 212          $db->update_query("users", array("style" => 0), "style='{$style['style']}'");
 213      }
 214      // Attempt to load the master or any other theme if the master is not available
 215      $query = $db->simple_select("themes", "name, tid, properties, stylesheets", "", array("order_by" => "tid", "limit" => 1));
 216      $theme = $db->fetch_array($query);
 217  }
 218  $theme = @array_merge($theme, unserialize($theme['properties']));
 219  
 220  // Fetch all necessary stylesheets
 221  $stylesheets = '';
 222  $theme['stylesheets'] = unserialize($theme['stylesheets']);
 223  $stylesheet_scripts = array("global", basename($_SERVER['PHP_SELF']));
 224  foreach($stylesheet_scripts as $stylesheet_script)
 225  {
 226      $stylesheet_actions = array("global");
 227      if(!empty($mybb->input['action']))
 228      {
 229          $stylesheet_actions[] = $mybb->input['action'];
 230      }
 231      // Load stylesheets for global actions and the current action
 232      foreach($stylesheet_actions as $stylesheet_action)
 233      {
 234          if(!$stylesheet_action)
 235          {
 236              continue;
 237          }
 238          
 239          if(!empty($theme['stylesheets'][$stylesheet_script][$stylesheet_action]))
 240          {
 241              // Actually add the stylesheets to the list
 242              foreach($theme['stylesheets'][$stylesheet_script][$stylesheet_action] as $page_stylesheet)
 243              {
 244                  if(!empty($already_loaded[$page_stylesheet]))
 245                  {
 246                      continue;
 247                  }
 248                  $stylesheets .= "<link type=\"text/css\" rel=\"stylesheet\" href=\"{$mybb->settings['bburl']}/{$page_stylesheet}\" />\n";
 249                  $already_loaded[$page_stylesheet] = 1;
 250              }
 251          }
 252      }
 253  }
 254  
 255  // Are we linking to a remote theme server?
 256  if(substr($theme['imgdir'], 0, 7) == "http://" || substr($theme['imgdir'], 0, 8) == "https://")
 257  {
 258      // If a language directory for the current language exists within the theme - we use it
 259      if(!empty($mybb->user['language']))
 260      {
 261          $theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->user['language'];
 262      }
 263      else
 264      {
 265          // Check if a custom language directory exists for this theme
 266          if(!empty($mybb->settings['bblanguage']))
 267          {
 268              $theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->settings['bblanguage'];
 269          }
 270          // Otherwise, the image language directory is the same as the language directory for the theme
 271          else
 272          {
 273              $theme['imglangdir'] = $theme['imgdir'];
 274          }
 275      }
 276  }
 277  else
 278  {
 279      if(!@is_dir($theme['imgdir']))
 280      {
 281          $theme['imgdir'] = "images";
 282      }
 283  
 284      // If a language directory for the current language exists within the theme - we use it
 285      if(!empty($mybb->user['language']) && is_dir($theme['imgdir'].'/'.$mybb->user['language']))
 286      {
 287          $theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->user['language'];
 288      }
 289      else
 290      {
 291          // Check if a custom language directory exists for this theme
 292          if(is_dir($theme['imgdir'].'/'.$mybb->settings['bblanguage']))
 293          {
 294              $theme['imglangdir'] = $theme['imgdir'].'/'.$mybb->settings['bblanguage'];
 295          }
 296          // Otherwise, the image language directory is the same as the language directory for the theme
 297          else
 298          {
 299              $theme['imglangdir'] = $theme['imgdir'];
 300          }
 301      }
 302  }
 303  
 304  // Theme logo - is it a relative URL to the forum root? Append bburl
 305  if(!preg_match("#^(\.\.?(/|$)|([a-z0-9]+)://)#i", $theme['logo']) && substr($theme['logo'], 0, 1) != "/")
 306  {
 307      $theme['logo'] = $mybb->settings['bburl']."/".$theme['logo'];
 308  }
 309  
 310  // Load Main Templates and Cached Templates
 311  if(isset($templatelist))
 312  {
 313      $templatelist .= ',';
 314  }
 315  $templatelist .= "headerinclude,header,footer,gobutton,htmldoctype,header_welcomeblock_member,header_welcomeblock_guest,header_welcomeblock_member_admin,global_pm_alert,global_unreadreports";
 316  $templatelist .= ",global_pending_joinrequests,nav,nav_sep,nav_bit,nav_sep_active,nav_bit_active,footer_languageselect,header_welcomeblock_member_moderator,redirect,error";
 317  $templatelist .= ",global_boardclosed_warning,global_bannedwarning,error_inline,error_nopermission_loggedin,error_nopermission";
 318  $templates->cache($db->escape_string($templatelist));
 319  
 320  // Set the current date and time now
 321  $datenow = my_date($mybb->settings['dateformat'], TIME_NOW, '', false);
 322  $timenow = my_date($mybb->settings['timeformat'], TIME_NOW);
 323  $lang->welcome_current_time = $lang->sprintf($lang->welcome_current_time, $datenow.', '.$timenow);
 324  
 325  // Format the last visit date of this user appropriately
 326  if(isset($mybb->user['lastvisit']))
 327  {
 328      $lastvisit = my_date($mybb->settings['dateformat'], $mybb->user['lastvisit']) . ', ' . my_date($mybb->settings['timeformat'], $mybb->user['lastvisit']);
 329  }
 330  
 331  // Otherwise, they've never visited before
 332  else
 333  {
 334      $lastvisit = $lang->lastvisit_never;
 335  }
 336  
 337  // If the board is closed and we have an Administrator, show board closed warning
 338  $bbclosedwarning = '';
 339  if($mybb->settings['boardclosed'] == 1 && $mybb->usergroup['cancp'] == 1)
 340  {
 341      eval("\$bbclosedwarning = \"".$templates->get("global_boardclosed_warning")."\";");
 342  }
 343  
 344  // Prepare the main templates for use
 345  unset($admincplink);
 346  
 347  // Load appropriate welcome block for the current logged in user
 348  if($mybb->user['uid'] != 0)
 349  {
 350      // User can access the admin cp and we're not hiding admin cp links, fetch it
 351      if($mybb->usergroup['cancp'] == 1 && $mybb->config['hide_admin_links'] != 1)
 352      {
 353          $admin_dir = $config['admin_dir'];
 354          eval("\$admincplink = \"".$templates->get("header_welcomeblock_member_admin")."\";");
 355      }
 356      
 357      if($mybb->usergroup['canmodcp'] == 1)
 358      {
 359          eval("\$modcplink = \"".$templates->get("header_welcomeblock_member_moderator")."\";");
 360      }
 361      
 362      // Format the welcome back message
 363      $lang->welcome_back = $lang->sprintf($lang->welcome_back, build_profile_link($mybb->user['username'], $mybb->user['uid']), $lastvisit);
 364  
 365      // Tell the user their PM usage
 366      $lang->welcome_pms_usage = $lang->sprintf($lang->welcome_pms_usage, my_number_format($mybb->user['pms_unread']), my_number_format($mybb->user['pms_total']));
 367      eval("\$welcomeblock = \"".$templates->get("header_welcomeblock_member")."\";");
 368  }
 369  // Otherwise, we have a guest
 370  else
 371  {
 372      switch($mybb->settings['username_method'])
 373      {
 374          case 0:
 375              $login_username = $lang->login_username;
 376              break;
 377          case 1:
 378              $login_username = $lang->login_username1;
 379              break;
 380          case 2:
 381              $login_username = $lang->login_username2;
 382              break;
 383          default:
 384              $login_username = $lang->login_username;
 385              break;
 386      }
 387      eval("\$welcomeblock = \"".$templates->get("header_welcomeblock_guest")."\";");
 388  }
 389  
 390  $pending_joinrequests = '';
 391  
 392  // Read the group leaders cache
 393  $groupleaders = $cache->read("groupleaders");
 394  if($mybb->user['uid'] != 0 && is_array($groupleaders) && array_key_exists($mybb->user['uid'], $groupleaders))
 395  {
 396      $groupleader = $groupleaders[$mybb->user['uid']];
 397      
 398      $gids = "";
 399      foreach($groupleader as $user)
 400      {
 401          if($user['canmanagerequests'] != 1)
 402          {
 403              continue;
 404          }
 405          
 406          $gids .= ",{$user['gid']}";
 407      }
 408      
 409      $query = $db->simple_select("joinrequests", "COUNT(uid) as total", "gid IN (0{$gids})");
 410      $total_joinrequests = $db->fetch_field($query, "total");
 411      
 412      $pending_joinrequests = "";
 413      if($total_joinrequests > 0)
 414      {
 415          if($total_joinrequests == 1)
 416          {
 417              $lang->pending_joinrequests = $lang->pending_joinrequest;
 418          }
 419          else
 420          {
 421              $lang->pending_joinrequests = $lang->sprintf($lang->pending_joinrequests, $total_joinrequests);
 422          }
 423          eval("\$pending_joinrequests = \"".$templates->get("global_pending_joinrequests")."\";");
 424      }
 425  }
 426  
 427  $unreadreports = '';
 428  // This user is a moderator, super moderator or administrator
 429  if($mybb->usergroup['cancp'] == 1 || $mybb->user['ismoderator'] && $mybb->usergroup['canmodcp'])
 430  {
 431      // Read the reported posts cache
 432      $reported = $cache->read("reportedposts");
 433  
 434      // 0 or more reported posts currently exist
 435      if($reported['unread'] > 0)
 436      {
 437          if($reported['unread'] == 1)
 438          {
 439              $lang->unread_reports = $lang->unread_report;
 440          }
 441          else
 442          {
 443              $lang->unread_reports = $lang->sprintf($lang->unread_reports, $reported['unread']);
 444          }
 445          eval("\$unreadreports = \"".$templates->get("global_unreadreports")."\";");
 446      }
 447  }
 448  
 449  // Got a character set?
 450  if($lang->settings['charset'])
 451  {
 452      $charset = $lang->settings['charset'];
 453  }
 454  // If not, revert to UTF-8
 455  else
 456  {
 457      $charset = "UTF-8";
 458  }
 459  
 460  // Is this user apart of a banned group?
 461  $bannedwarning = '';
 462  if($mybb->usergroup['isbannedgroup'] == 1)
 463  {
 464      // Fetch details on their ban
 465      $query = $db->simple_select("banned", "*", "uid='{$mybb->user['uid']}'", array('limit' => 1));
 466      $ban = $db->fetch_array($query);
 467      if($ban['uid'])
 468      {
 469          // Format their ban lift date and reason appropriately
 470          if($ban['lifted'] > 0)
 471          {
 472              $banlift = my_date($mybb->settings['dateformat'], $ban['lifted']) . ", " . my_date($mybb->settings['timeformat'], $ban['lifted']);
 473          }
 474          else 
 475          {
 476              $banlift = $lang->banned_lifted_never;
 477          }
 478          $reason = htmlspecialchars_uni($ban['reason']);
 479      }
 480      if(empty($reason))
 481      {
 482          $reason = $lang->unknown;
 483      }
 484      if(empty($banlift))
 485      {
 486          $banlift = $lang->unknown;
 487      }
 488      // Display a nice warning to the user
 489      eval("\$bannedwarning = \"".$templates->get("global_bannedwarning")."\";");
 490  }
 491  
 492  $lang->ajax_loading = str_replace("'", "\\'", $lang->ajax_loading);
 493  
 494  // Check if this user has a new private message.
 495  $pm_notice = '';
 496  if(isset($mybb->user['pmnotice']) && $mybb->user['pmnotice'] == 2 && $mybb->user['pms_unread'] > 0 && $mybb->settings['enablepms'] != 0 && $mybb->usergroup['canusepms'] != 0 && $mybb->usergroup['canview'] != 0 && ($current_page != "private.php" || $mybb->input['action'] != "read"))
 497  {
 498      if(!$parser)
 499      {
 500          require_once  MYBB_ROOT.'inc/class_parser.php';
 501          $parser = new postParser;
 502      }
 503  
 504      $query = $db->query("
 505          SELECT pm.subject, pm.pmid, fu.username AS fromusername, fu.uid AS fromuid
 506          FROM ".TABLE_PREFIX."privatemessages pm
 507          LEFT JOIN ".TABLE_PREFIX."users fu ON (fu.uid=pm.fromid)
 508          WHERE pm.folder='1' AND pm.uid='{$mybb->user['uid']}' AND pm.status='0'
 509          ORDER BY pm.dateline DESC
 510          LIMIT 1
 511      ");
 512  
 513      $pm = $db->fetch_array($query);
 514      $pm['subject'] = $parser->parse_badwords($pm['subject']);
 515      
 516      if($pm['fromuid'] == 0)
 517      {
 518          $pm['fromusername'] = $lang->mybb_engine;
 519          $user_text = $pm['fromusername'];
 520      }
 521      else
 522      {
 523          $user_text = build_profile_link($pm['fromusername'], $pm['fromuid']);
 524      }
 525  
 526      if($mybb->user['pms_unread'] == 1)
 527      {
 528          $privatemessage_text = $lang->sprintf($lang->newpm_notice_one, $user_text, $pm['pmid'], htmlspecialchars_uni($pm['subject']));
 529      }
 530      else
 531      {
 532          $privatemessage_text = $lang->sprintf($lang->newpm_notice_multiple, $mybb->user['pms_unread'], $user_text, $pm['pmid'], htmlspecialchars_uni($pm['subject']));
 533      }
 534      eval("\$pm_notice = \"".$templates->get("global_pm_alert")."\";");
 535  }
 536  
 537  // Set up some of the default templates
 538  eval("\$headerinclude = \"".$templates->get("headerinclude")."\";");
 539  eval("\$gobutton = \"".$templates->get("gobutton")."\";");
 540  eval("\$htmldoctype = \"".$templates->get("htmldoctype", 1, 0)."\";");
 541  eval("\$header = \"".$templates->get("header")."\";");
 542  
 543  $copy_year = my_date("Y", TIME_NOW);
 544  
 545  // Are we showing version numbers in the footer?
 546  if($mybb->settings['showvernum'] == 1)
 547  {
 548      $mybbversion = ' '.$mybb->version;
 549  }
 550  else
 551  {
 552      $mybbversion = '';
 553  }
 554  
 555  // Check to see if we have any tasks to run
 556  $task_cache = $cache->read("tasks");
 557  if(!$task_cache['nextrun'])
 558  {
 559      $task_cache['nextrun'] = TIME_NOW;
 560  }
 561  if($task_cache['nextrun'] <= TIME_NOW)
 562  {
 563      $task_image = "<img src=\"{$mybb->settings['bburl']}/task.php\" border=\"0\" width=\"1\" height=\"1\" alt=\"\" />";
 564  }
 565  else
 566  {
 567      $task_image = '';
 568  }
 569  
 570  // Are we showing the quick language selection box?
 571  $lang_select = $lang_options = '';
 572  if($mybb->settings['showlanguageselect'] != 0)
 573  {
 574      $languages = $lang->get_languages();
 575      foreach($languages as $key => $language)
 576      {
 577          $language = htmlspecialchars_uni($language);
 578          // Current language matches
 579          if($lang->language == $key)
 580          {
 581              $lang_options .= "<option value=\"{$key}\" selected=\"selected\">&nbsp;&nbsp;&nbsp;{$language}</option>\n";
 582          }
 583          else
 584          {
 585              $lang_options .= "<option value=\"{$key}\">&nbsp;&nbsp;&nbsp;{$language}</option>\n";
 586          }
 587      }
 588      
 589      $lang_redirect_url = get_current_location(true, 'language');
 590      
 591      eval("\$lang_select = \"".$templates->get("footer_languageselect")."\";");
 592  }
 593  
 594  // DST Auto detection enabled?
 595  $auto_dst_detection = '';
 596  if($mybb->user['uid'] > 0 && $mybb->user['dstcorrection'] == 2)
 597  {
 598      $auto_dst_detection = "<script type=\"text/javascript\">if(MyBB) { Event.observe(window, 'load', function() { MyBB.detectDSTChange('".($mybb->user['timezone']+$mybb->user['dst'])."'); }); }</script>\n";
 599  }
 600  
 601  eval("\$footer = \"".$templates->get("footer")."\";");
 602  
 603  // Add our main parts to the navigation
 604  $navbits = array();
 605  $navbits[0]['name'] = $mybb->settings['bbname_orig'];
 606  $navbits[0]['url'] = $mybb->settings['bburl']."/index.php";
 607  
 608  // Set the link to the archive.
 609  $archive_url = $mybb->settings['bburl']."/archive/index.php";
 610  
 611  // Check banned ip addresses
 612  if(is_banned_ip($session->ipaddress, true))
 613  {
 614      if ($mybb->user['uid'])
 615      {
 616          $db->delete_query("sessions", "ip='".$db->escape_string($session->ipaddress)."' OR uid='{$mybb->user['uid']}'");
 617      }
 618      else
 619      {
 620          $db->delete_query("sessions", "ip='".$db->escape_string($session->ipaddress)."'");
 621      }
 622      error($lang->error_banned);
 623  }
 624  
 625  $closed_bypass = array(
 626      "member.php" => array(
 627          "login",
 628          "do_login",
 629          "logout",
 630      ),
 631      "captcha.php",
 632  );
 633  
 634  // If the board is closed, the user is not an administrator and they're not trying to login, show the board closed message
 635  if($mybb->settings['boardclosed'] == 1 && $mybb->usergroup['cancp'] != 1 && !in_array($current_page, $closed_bypass) && (!is_array($closed_bypass[$current_page]) || !in_array($mybb->input['action'], $closed_bypass[$current_page])))
 636  {
 637      // Show error
 638      $lang->error_boardclosed .= "<blockquote>{$mybb->settings['boardclosed_reason']}</blockquote>";
 639      error($lang->error_boardclosed);
 640      exit;
 641  }
 642  
 643  // Load Limiting
 644  if($mybb->usergroup['cancp'] != 1 && $mybb->settings['load'] > 0 && ($load = get_server_load()) && $load != $lang->unknown && $load > $mybb->settings['load'])
 645  {
 646      // User is not an administrator and the load limit is higher than the limit, show an error
 647      error($lang->error_loadlimit);
 648  }
 649  
 650  // If there is a valid referrer in the URL, cookie it
 651  if(!$mybb->user['uid'] && $mybb->settings['usereferrals'] == 1 && (isset($mybb->input['referrer']) || isset($mybb->input['referrername'])))
 652  {
 653      if(isset($mybb->input['referrername']))
 654      {
 655          $condition = "username='".$db->escape_string($mybb->input['referrername'])."'";
 656      }
 657      else
 658      {
 659          $condition = "uid='".intval($mybb->input['referrer'])."'";
 660      }
 661      $query = $db->simple_select("users", "uid", $condition, array('limit' => 1));
 662      $referrer = $db->fetch_array($query);
 663      if($referrer['uid'])
 664      {
 665          my_setcookie("mybb[referrer]", $referrer['uid']);
 666      }
 667  }
 668  
 669  if($mybb->usergroup['canview'] != 1)
 670  {
 671      // Check pages allowable even when not allowed to view board
 672      if(defined("ALLOWABLE_PAGE"))
 673      {
 674          if(is_string(ALLOWABLE_PAGE))
 675          {
 676              $allowable_actions = explode(',', ALLOWABLE_PAGE);
 677              
 678              if(!in_array($mybb->input['action'], $allowable_actions))
 679              {
 680                  error_no_permission();
 681              }
 682              
 683              unset($allowable_actions);
 684          }
 685          else if(ALLOWABLE_PAGE !== 1)
 686          {
 687              error_no_permission();
 688          }
 689      }
 690      else
 691      {
 692          error_no_permission();
 693      }
 694  }
 695  
 696  // Find out if this user of ours is using a banned email address.
 697  // If they are, redirect them to change it
 698  if($mybb->user['uid'] && is_banned_email($mybb->user['email']) && $mybb->settings['emailkeep'] != 1)
 699  {
 700      if(THIS_SCRIPT != "usercp.php" || THIS_SCRIPT == "usercp.php" && $mybb->input['action'] != "email" && $mybb->input['action'] != "do_email")
 701      {
 702          redirect("usercp.php?action=email");
 703      }
 704      else if($mybb->request_method != "post")
 705      {
 706          $banned_email_error = inline_error(array($lang->banned_email_warning));
 707      }
 708  }
 709  
 710  // work out which items the user has collapsed
 711  $colcookie = empty($mybb->cookies['collapsed']) ? false : $mybb->cookies['collapsed'];
 712  
 713  // set up collapsable items (to automatically show them us expanded)
 714  $collapsed = array('boardstats' => '', 'boardstats_e' => '', 'quickreply' => '', 'quickreply_e' => '');
 715  $collapsedimg = $collapsed;
 716  
 717  if($colcookie)
 718  {
 719      $col = explode("|", $colcookie);
 720      if(!is_array($col))
 721      {
 722          $col[0] = $colcookie; // only one item
 723      }
 724      unset($collapsed);
 725      foreach($col as $key => $val)
 726      {
 727          $ex = $val."_e";
 728          $co = $val."_c";
 729          $collapsed[$co] = "display: show;";
 730          $collapsed[$ex] = "display: none;";
 731          $collapsedimg[$val] = "_collapsed";
 732      }
 733  }
 734  
 735  // Run hooks for end of global.php
 736  $plugins->run_hooks("global_end");
 737  
 738  $globaltime = $maintimer->getTime();
 739  ?>

title

Description

title

Description

title

Description

title

title

Body