[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/ -> index.php (source)

   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  define("IN_MYBB", 1);
  13  define('THIS_SCRIPT', 'index.php');
  14  
  15  $templatelist = "index,index_whosonline,index_whosonline_memberbit,forumbit_depth1_cat,forumbit_depth2_cat,forumbit_depth2_forum,forumbit_depth1_forum_lastpost,forumbit_depth2_forum_lastpost,forumbit_moderators,forumbit_subforums";
  16  $templatelist .= ",index_birthdays_birthday,index_birthdays,index_loginform,index_logoutlink,index_stats,forumbit_depth3,forumbit_depth3_statusicon,index_boardstats";
  17  
  18  require_once  "./global.php";
  19  
  20  require_once  MYBB_ROOT."inc/functions_post.php";
  21  require_once  MYBB_ROOT."inc/functions_forumlist.php";
  22  require_once  MYBB_ROOT."inc/class_parser.php";
  23  $parser = new postParser;
  24  
  25  $plugins->run_hooks("index_start");
  26  
  27  // Load global language phrases
  28  $lang->load("index");
  29  
  30  $logoutlink = $loginform = '';
  31  if($mybb->user['uid'] != 0)
  32  {
  33      eval("\$logoutlink = \"".$templates->get("index_logoutlink")."\";");
  34  }
  35  else
  36  {
  37      //Checks to make sure the user can login; they haven't had too many tries at logging in.
  38      //Function call is not fatal
  39      if(login_attempt_check(false) !== false)
  40      {
  41          switch($mybb->settings['username_method'])
  42          {
  43              case 0:
  44                  $login_username = $lang->login_username;
  45                  break;
  46              case 1:
  47                  $login_username = $lang->login_username1;
  48                  break;
  49              case 2:
  50                  $login_username = $lang->login_username2;
  51                  break;
  52              default:
  53                  $login_username = $lang->login_username;
  54                  break;
  55          }
  56          eval("\$loginform = \"".$templates->get("index_loginform")."\";");
  57      }
  58  }
  59  $whosonline = '';
  60  if($mybb->settings['showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0)
  61  {
  62      // Get the online users.
  63      $timesearch = TIME_NOW - $mybb->settings['wolcutoff'];
  64      $comma = '';
  65      $query = $db->query("
  66          SELECT s.sid, s.ip, s.uid, s.time, s.location, s.location1, u.username, u.invisible, u.usergroup, u.displaygroup
  67          FROM ".TABLE_PREFIX."sessions s
  68          LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
  69          WHERE s.time>'$timesearch'
  70          ORDER BY u.username ASC, s.time DESC
  71      ");
  72  
  73      $onlinemembers = '';
  74      $forum_viewers = $doneusers = array();
  75      $botcount = $membercount = $anoncount = $guestcount = 0;
  76  
  77      // Fetch spiders
  78      $spiders = $cache->read("spiders");
  79  
  80      // Loop through all users.
  81      while($user = $db->fetch_array($query))
  82      {
  83          // Create a key to test if this user is a search bot.
  84          $botkey = my_strtolower(str_replace("bot=", '', $user['sid']));
  85  
  86          // Decide what type of user we are dealing with.
  87          if($user['uid'] > 0)
  88          {
  89              // The user is registered.
  90              if(empty($doneusers[$user['uid']]) || $doneusers[$user['uid']] < $user['time'])
  91              {
  92                  // If the user is logged in anonymously, update the count for that.
  93                  if($user['invisible'] == 1)
  94                  {
  95                      ++$anoncount;
  96                  }
  97                  ++$membercount;
  98                  if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
  99                  {
 100                      // If this usergroup can see anonymously logged-in users, mark them.
 101                      if($user['invisible'] == 1)
 102                      {
 103                          $invisiblemark = "*";
 104                      }
 105                      else
 106                      {
 107                          $invisiblemark = '';
 108                      }
 109  
 110                      // Properly format the username and assign the template.
 111                      $user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
 112                      $user['profilelink'] = build_profile_link($user['username'], $user['uid']);
 113                      eval("\$onlinemembers .= \"".$templates->get("index_whosonline_memberbit", 1, 0)."\";");
 114                      $comma = $lang->comma;
 115                  }
 116                  // This user has been handled.
 117                  $doneusers[$user['uid']] = $user['time'];
 118              }
 119          }
 120          elseif(my_strpos($user['sid'], "bot=") !== false && $spiders[$botkey])
 121          {
 122              // The user is a search bot.
 123              $onlinemembers .= $comma.format_name($spiders[$botkey]['name'], $spiders[$botkey]['usergroup']);
 124              $comma = $lang->comma;
 125              ++$botcount;
 126          }
 127          else
 128          {
 129              // The user is a guest.
 130              ++$guestcount;
 131          }
 132  
 133          if($user['location1'])
 134          {
 135              $forum_viewers[$user['location1']]++;
 136          }
 137      }
 138  
 139      // Build the who's online bit on the index page.
 140      $onlinecount = $membercount + $guestcount + $botcount;
 141  
 142      if($onlinecount != 1)
 143      {
 144          $onlinebit = $lang->online_online_plural;
 145      }
 146      else
 147      {
 148          $onlinebit = $lang->online_online_singular;
 149      }
 150      if($membercount != 1)
 151      {
 152          $memberbit = $lang->online_member_plural;
 153      }
 154      else
 155      {
 156          $memberbit = $lang->online_member_singular;
 157      }
 158      if($anoncount != 1)
 159      {
 160          $anonbit = $lang->online_anon_plural;
 161      }
 162      else
 163      {
 164          $anonbit = $lang->online_anon_singular;
 165      }
 166      if($guestcount != 1)
 167      {
 168          $guestbit = $lang->online_guest_plural;
 169      }
 170      else
 171      {
 172          $guestbit = $lang->online_guest_singular;
 173      }
 174      $lang->online_note = $lang->sprintf($lang->online_note, my_number_format($onlinecount), $onlinebit, $mybb->settings['wolcutoffmins'], my_number_format($membercount), $memberbit, my_number_format($anoncount), $anonbit, my_number_format($guestcount), $guestbit);
 175      eval("\$whosonline = \"".$templates->get("index_whosonline")."\";");
 176  }
 177  
 178  // Build the birthdays for to show on the index page.
 179  $bdays = $birthdays = '';
 180  if($mybb->settings['showbirthdays'] != 0)
 181  {
 182      // First, see what day this is.
 183      $bdaycount = 0; $bdayhidden = 0;
 184      $bdaytime = TIME_NOW;
 185      $bdaydate = my_date("j-n", $bdaytime, '', 0);
 186      $year = my_date("Y", $bdaytime, '', 0);
 187  
 188      $bdaycache = $cache->read("birthdays");
 189  
 190      if(!is_array($bdaycache))
 191      {
 192          $cache->update_birthdays();
 193          $bdaycache = $cache->read("birthdays");
 194      }
 195  
 196      $hiddencount = $today_bdays = 0;
 197      if(isset($bdaycache[$bdaydate]))
 198      {
 199          $hiddencount = $bdaycache[$bdaydate]['hiddencount'];
 200          $today_bdays = $bdaycache[$bdaydate]['users'];
 201      }
 202  
 203      $comma = '';
 204      if(!empty($today_bdays))
 205      {
 206          if(intval($mybb->settings['showbirthdayspostlimit']) > 0)
 207          {
 208              $bdayusers = array();
 209              foreach($today_bdays as $key => $bdayuser_pc)
 210              {
 211                  $bdayusers[$bdayuser_pc['uid']] = $key;
 212              }
 213  
 214              if(!empty($bdayusers))
 215              {
 216                  // Find out if our users have enough posts to be seen on our birthday list
 217                  $bday_sql = implode(",", array_keys($bdayusers));
 218                  $query = $db->simple_select("users", "uid, postnum", "uid IN ({$bday_sql})");
 219  
 220                  while($bdayuser = $db->fetch_array($query))
 221                  {
 222                      if($bdayuser['postnum'] < $mybb->settings['showbirthdayspostlimit'])
 223                      {
 224                          unset($today_bdays[$bdayusers[$bdayuser['uid']]]);
 225                      }
 226                  }
 227              }
 228          }
 229  
 230          // We still have birthdays - display them in our list!
 231          if(!empty($today_bdays))
 232          {
 233              foreach($today_bdays as $bdayuser)
 234              {
 235                  if($bdayuser['displaygroup'] == 0)
 236                  {
 237                      $bdayuser['displaygroup'] = $bdayuser['usergroup'];
 238                  }
 239  
 240                  // If this user's display group can't be seen in the birthday list, skip it
 241                  if($groupscache[$bdayuser['displaygroup']] && $groupscache[$bdayuser['displaygroup']]['showinbirthdaylist'] != 1)
 242                  {
 243                      continue;
 244                  }
 245  
 246                  $bday = explode("-", $bdayuser['birthday']);
 247                  if($year > $bday['2'] && $bday['2'] != '')
 248                  {
 249                      $age = " (".($year - $bday['2']).")";
 250                  }
 251                  else
 252                  {
 253                      $age = '';
 254                  }
 255  
 256                  $bdayuser['username'] = format_name($bdayuser['username'], $bdayuser['usergroup'], $bdayuser['displaygroup']);
 257                  $bdayuser['profilelink'] = build_profile_link($bdayuser['username'], $bdayuser['uid']);
 258                  eval("\$bdays .= \"".$templates->get("index_birthdays_birthday", 1, 0)."\";");
 259                  ++$bdaycount;
 260                  $comma = $lang->comma;
 261              }
 262          }
 263      }
 264  
 265      if($hiddencount > 0)
 266      {
 267          if($bdaycount > 0)
 268          {
 269              $bdays .= " - ";
 270          }
 271          $bdays .= "{$hiddencount} {$lang->birthdayhidden}";
 272      }
 273  
 274      // If there are one or more birthdays, show them.
 275      if($bdaycount > 0 || $hiddencount > 0)
 276      {
 277          eval("\$birthdays = \"".$templates->get("index_birthdays")."\";");
 278      }
 279  }
 280  
 281  // Build the forum statistics to show on the index page.
 282  if($mybb->settings['showindexstats'] != 0)
 283  {
 284      // First, load the stats cache.
 285      $stats = $cache->read("stats");
 286  
 287      // Check who's the newest member.
 288      if(!$stats['lastusername'])
 289      {
 290          $newestmember = "no-one";
 291      }
 292      else
 293      {
 294          $newestmember = build_profile_link($stats['lastusername'], $stats['lastuid']);
 295      }
 296  
 297      // Format the stats language.
 298      $lang->stats_posts_threads = $lang->sprintf($lang->stats_posts_threads, my_number_format($stats['numposts']), my_number_format($stats['numthreads']));
 299      $lang->stats_numusers = $lang->sprintf($lang->stats_numusers, my_number_format($stats['numusers']));
 300      $lang->stats_newestuser = $lang->sprintf($lang->stats_newestuser, $newestmember);
 301  
 302      // Find out what the highest users online count is.
 303      $mostonline = $cache->read("mostonline");
 304      if($onlinecount > $mostonline['numusers'])
 305      {
 306          $time = TIME_NOW;
 307          $mostonline['numusers'] = $onlinecount;
 308          $mostonline['time'] = $time;
 309          $cache->update("mostonline", $mostonline);
 310      }
 311      $recordcount = $mostonline['numusers'];
 312      $recorddate = my_date($mybb->settings['dateformat'], $mostonline['time']);
 313      $recordtime = my_date($mybb->settings['timeformat'], $mostonline['time']);
 314  
 315      // Then format that language string.
 316      $lang->stats_mostonline = $lang->sprintf($lang->stats_mostonline, my_number_format($recordcount), $recorddate, $recordtime);
 317  
 318      eval("\$forumstats = \"".$templates->get("index_stats")."\";");
 319  }
 320  
 321  // Show the board statistics table only if one or more index statistics are enabled.
 322  if(($mybb->settings['showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0) || $mybb->settings['showindexstats'] != 0 || ($mybb->settings['showbirthdays'] != 0 && $bdaycount > 0))
 323  {
 324      if(!is_array($stats))
 325      {
 326          // Load the stats cache.
 327          $stats = $cache->read("stats");
 328      }
 329  
 330      $post_code_string = '';
 331      if($mybb->user['uid'])
 332      {
 333          $post_code_string = "&amp;my_post_key=".$mybb->post_code;
 334      }
 335  
 336      eval("\$boardstats = \"".$templates->get("index_boardstats")."\";");
 337  }
 338  
 339  if($mybb->user['uid'] == 0)
 340  {
 341      // Build a forum cache.
 342      $query = $db->query("
 343          SELECT *
 344          FROM ".TABLE_PREFIX."forums
 345          WHERE active != 0
 346          ORDER BY pid, disporder
 347      ");
 348  
 349      $forumsread = my_unserialize($mybb->cookies['mybb']['forumread']);
 350  }
 351  else
 352  {
 353      // Build a forum cache.
 354      $query = $db->query("
 355          SELECT f.*, fr.dateline AS lastread
 356          FROM ".TABLE_PREFIX."forums f
 357          LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')
 358          WHERE f.active != 0
 359          ORDER BY pid, disporder
 360      ");
 361  }
 362  
 363  while($forum = $db->fetch_array($query))
 364  {
 365      if($mybb->user['uid'] == 0)
 366      {
 367          if(!empty($forumsread[$forum['fid']]))
 368          {
 369              $forum['lastread'] = $forumsread[$forum['fid']];
 370          }
 371      }
 372      $fcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
 373  }
 374  $forumpermissions = forum_permissions();
 375  
 376  // Get the forum moderators if the setting is enabled.
 377  if($mybb->settings['modlist'] != "off")
 378  {
 379      $moderatorcache = $cache->read("moderators");
 380  }
 381  
 382  $excols = "index";
 383  $permissioncache['-1'] = "1";
 384  $bgcolor = "trow1";
 385  
 386  // Decide if we're showing first-level subforums on the index page.
 387  if($mybb->settings['subforumsindex'] != 0)
 388  {
 389      $showdepth = 3;
 390  }
 391  else
 392  {
 393      $showdepth = 2;
 394  }
 395  $forum_list = build_forumbits();
 396  $forums = $forum_list['forum_list'];
 397  
 398  $plugins->run_hooks("index_end");
 399  
 400  eval("\$index = \"".$templates->get("index")."\";");
 401  output_page($index);
 402  
 403  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1