[ Index ]

PHP Cross Reference of MyBB 1.8.27

title

Body

[close]

/admin/modules/home/ -> module_meta.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  // Disallow direct access to this file for security reasons
  12  if(!defined("IN_MYBB"))
  13  {
  14      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  15  }
  16  
  17  /**
  18   * @return bool true
  19   */
  20  function home_meta()
  21  {
  22      global $page, $lang, $plugins;
  23  
  24      $sub_menu = array();
  25      $sub_menu['10'] = array("id" => "dashboard", "title" => $lang->dashboard, "link" => "index.php?module=home-dashboard");
  26      $sub_menu['20'] = array("id" => "preferences", "title" => $lang->preferences, "link" => "index.php?module=home-preferences");
  27      $sub_menu['30'] = array("id" => "docs", "title" => $lang->mybb_documentation, "link" => "https://docs.mybb.com");
  28      $sub_menu['40'] = array("id" => "credits", "title" => $lang->mybb_credits, "link" => "https://mybb.com/credits");
  29      $sub_menu = $plugins->run_hooks("admin_home_menu", $sub_menu);
  30  
  31      $page->add_menu_item($lang->home, "home", "index.php", 1, $sub_menu);
  32  
  33      return true;
  34  }
  35  
  36  /**
  37   * @param string $action
  38   *
  39   * @return string
  40   */
  41  function home_action_handler($action)
  42  {
  43      global $page, $db, $lang, $plugins;
  44  
  45      $page->active_module = "home";
  46  
  47      $actions = array(
  48          'preferences' => array('active' => 'preferences', 'file' => 'preferences.php'),
  49          'version_check' => array('active' => 'version_check', 'file' => 'version_check.php'),
  50          'dashboard' => array('active' => 'dashboard', 'file' => 'index.php')
  51      );
  52  
  53      if(!isset($actions[$action]))
  54      {
  55          $page->active_action = "dashboard";
  56      }
  57      else
  58      {
  59          $page->active_action = $actions[$action]['active'];
  60      }
  61  
  62      $actions = $plugins->run_hooks("admin_home_action_handler", $actions);
  63  
  64      if($page->active_action == "dashboard")
  65      {
  66          // Quick Access
  67          $sub_menu = array();
  68          $sub_menu['10'] = array("id" => "add_forum", "title" => $lang->add_new_forum, "link" => "index.php?module=forum-management&action=add", "module" => "forum", "action" => "management");
  69          $sub_menu['20'] = array("id" => "search", "title" => $lang->search_for_users, "link" => "index.php?module=user-users&action=search", "module" => "user", "action" => "users");
  70          $sub_menu['30'] = array("id" => "themes", "title" => $lang->themes, "link" => "index.php?module=style-themes", "module" => "style", "action" => "themes");
  71          $sub_menu['40'] = array("id" => "templates", "title" => $lang->templates, "link" => "index.php?module=style-templates", "module" => "style", "action" => "templates");
  72          $sub_menu['50'] = array("id" => "plugins", "title" => $lang->plugins, "link" => "index.php?module=config-plugins", "module" => "config", "action" => "plugins");
  73          $sub_menu['60'] = array("id" => "backupdb", "title" => $lang->database_backups, "link" => "index.php?module=tools-backupdb", "module" => "tools", "action" => "backupdb");
  74  
  75          foreach($sub_menu as $id => $sub)
  76          {
  77              if(!check_admin_permissions(array("module" => $sub['module'], "action" => $sub['action']), false))
  78              {
  79                  unset($sub_menu[$id]);
  80              }
  81          }
  82  
  83          $sub_menu = $plugins->run_hooks("admin_home_menu_quick_access", $sub_menu);
  84  
  85          if(!empty($sub_menu))
  86          {
  87              $sidebar = new SidebarItem($lang->quick_access);
  88              $sidebar->add_menu_items($sub_menu, $page->active_action);
  89              $page->sidebar .= $sidebar->get_markup();
  90          }
  91  
  92          // Online Administrators in the last 30 minutes
  93          $timecut = TIME_NOW-60*30;
  94          $query = $db->simple_select("adminsessions", "uid, ip, useragent", "lastactive > {$timecut}");
  95          $online_users = "<ul class=\"menu online_admins\">";
  96          $online_admins = array();
  97  
  98          // If there's only 1 user online, it has to be us.
  99          if($db->num_rows($query) == 1)
 100          {
 101              $user = $db->fetch_array($query);
 102              global $mybb;
 103  
 104              // Are we on a mobile device?
 105              // Stolen from http://stackoverflow.com/a/10989424
 106              $user_type = "desktop";
 107              if(is_mobile($user["useragent"]))
 108              {
 109                  $user_type = "mobile";
 110              }
 111  
 112              $online_admins[$mybb->user['username']] = array(
 113                  "uid" => $mybb->user['uid'],
 114                  "username" => $mybb->user['username'],
 115                  "ip" => $user["ip"],
 116                  "type" => $user_type
 117              );
 118          }
 119          else
 120          {
 121              $uid_in = array();
 122              while($user = $db->fetch_array($query))
 123              {
 124                  $uid_in[] = $user['uid'];
 125  
 126                  $user_type = "desktop";
 127                  if(is_mobile($user['useragent']))
 128                  {
 129                      $user_type = "mobile";
 130                  }
 131  
 132                  $online_admins[$user['uid']] = array(
 133                      "ip" => $user['ip'],
 134                      "type" => $user_type
 135                  );
 136              }
 137  
 138              $query = $db->simple_select("users", "uid, username", "uid IN(".implode(',', $uid_in).")", array('order_by' => 'username'));
 139              while($user = $db->fetch_array($query))
 140              {
 141                  $online_admins[$user['username']] = array(
 142                      "uid" => $user['uid'],
 143                      "username" => $user['username'],
 144                      "ip" => $online_admins[$user['uid']]['ip'],
 145                      "type" => $online_admins[$user['uid']]['type']
 146                  );
 147                  unset($online_admins[$user['uid']]);
 148              }
 149          }
 150  
 151          $done_users = array();
 152  
 153          asort($online_admins);
 154  
 155          foreach($online_admins as $user)
 156          {
 157              if(!isset($done_users["{$user['uid']}.{$user['ip']}"]))
 158              {
 159                  if($user['type'] == "mobile")
 160                  {
 161                      $class = " class=\"mobile_user\"";
 162                  }
 163                  else
 164                  {
 165                      $class = "";
 166                  }
 167                  $ip_address = my_inet_ntop($db->unescape_binary($user['ip']));
 168                  $online_users .= "<li title=\"{$lang->ipaddress} {$ip_address}\"{$class}>".build_profile_link(htmlspecialchars_uni($user['username']).' ('.$ip_address.')', $user['uid'], "_blank")."</li>";
 169                  $done_users["{$user['uid']}.{$user['ip']}"] = 1;
 170              }
 171          }
 172          $online_users .= "</ul>";
 173          $sidebar = new SidebarItem($lang->online_admins);
 174          $sidebar->set_contents($online_users);
 175  
 176          $page->sidebar .= $sidebar->get_markup();
 177      }
 178  
 179      if(isset($actions[$action]))
 180      {
 181          $page->active_action = $actions[$action]['active'];
 182          return $actions[$action]['file'];
 183      }
 184      else
 185      {
 186          $page->active_action = "dashboard";
 187          return "index.php";
 188      }
 189  }
 190  


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref