Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

user_loader.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 6.78 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb;
 015   
 016  /**
 017  * User loader class
 018  *
 019  * This handles loading users from the database and
 020  * storing in them in a temporary cache so we do not
 021  * have to query the same user multiple times in
 022  * different services.
 023  */
 024  class user_loader
 025  {
 026      /** @var \phpbb\db\driver\driver_interface */
 027      protected $db = null;
 028   
 029      /** @var string */
 030      protected $phpbb_root_path = null;
 031   
 032      /** @var string */
 033      protected $php_ext = null;
 034   
 035      /** @var string */
 036      protected $users_table = null;
 037   
 038      /**
 039      * Users loaded from the DB
 040      *
 041      * @var array Array of user data that we've loaded from the DB
 042      */
 043      protected $users = array();
 044   
 045      /**
 046      * User loader constructor
 047      *
 048      * @param \phpbb\db\driver\driver_interface $db A database connection
 049      * @param string $phpbb_root_path Path to the phpbb includes directory.
 050      * @param string $php_ext php file extension
 051      * @param string $users_table The name of the database table (phpbb_users)
 052      */
 053      public function __construct(\phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext, $users_table)
 054      {
 055          $this->db = $db;
 056   
 057          $this->phpbb_root_path = $phpbb_root_path;
 058          $this->php_ext = $php_ext;
 059   
 060          $this->users_table = $users_table;
 061      }
 062   
 063      /**
 064      * Load user helper
 065      *
 066      * @param array $user_ids
 067      */
 068      public function load_users(array $user_ids)
 069      {
 070          $user_ids[] = ANONYMOUS;
 071   
 072          // Make user_ids unique and convert to integer.
 073          $user_ids = array_map('intval', array_unique($user_ids));
 074   
 075          // Do not load users we already have in $this->users
 076          $user_ids = array_diff($user_ids, array_keys($this->users));
 077   
 078          if (sizeof($user_ids))
 079          {
 080              $sql = 'SELECT *
 081                  FROM ' . $this->users_table . '
 082                  WHERE ' . $this->db->sql_in_set('user_id', $user_ids);
 083              $result = $this->db->sql_query($sql);
 084   
 085              while ($row = $this->db->sql_fetchrow($result))
 086              {
 087                  $this->users[$row['user_id']] = $row;
 088              }
 089              $this->db->sql_freeresult($result);
 090          }
 091      }
 092   
 093      /**
 094      * Load a user by username
 095      *
 096      * Stores the full data in the user cache so they do not need to be loaded again
 097      * Returns the user id so you may use get_user() from the returned value
 098      *
 099      * @param string $username Raw username to load (will be cleaned)
 100      * @return int User ID for the username
 101      */
 102      public function load_user_by_username($username)
 103      {
 104          $sql = 'SELECT *
 105              FROM ' . $this->users_table . "
 106              WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($username)) . "'";
 107          $result = $this->db->sql_query($sql);
 108          $row = $this->db->sql_fetchrow($result);
 109          $this->db->sql_freeresult($result);
 110   
 111          if ($row)
 112          {
 113              $this->users[$row['user_id']] = $row;
 114   
 115              return $row['user_id'];
 116          }
 117   
 118          return ANONYMOUS;
 119      }
 120   
 121      /**
 122      * Get a user row from our users cache
 123      *
 124      * @param int $user_id User ID of the user you want to retreive
 125      * @param bool $query Should we query the database if this user has not yet been loaded?
 126      *                         Typically this should be left as false and you should make sure
 127      *                         you load users ahead of time with load_users()
 128      * @return array|bool Row from the database of the user or Anonymous if the user wasn't loaded/does not exist
 129      *                         or bool False if the anonymous user was not loaded
 130      */
 131      public function get_user($user_id, $query = false)
 132      {
 133          if (isset($this->users[$user_id]))
 134          {
 135              return $this->users[$user_id];
 136          }
 137          // Query them if we must (if ANONYMOUS is sent as the user_id and we have not loaded Anonymous yet, we must load Anonymous as a last resort)
 138          else if ($query || $user_id == ANONYMOUS)
 139          {
 140              $this->load_users(array($user_id));
 141   
 142              return $this->get_user($user_id);
 143          }
 144   
 145          return $this->get_user(ANONYMOUS);
 146      }
 147   
 148      /**
 149      * Get username
 150      *
 151      * @param int $user_id User ID of the user you want to retreive the username for
 152      * @param string $mode The mode to load (same as get_username_string). One of the following:
 153      *             profile (for getting an url to the profile)
 154      *             username (for obtaining the username)
 155      *             colour (for obtaining the user colour)
 156      *             full (for obtaining a html string representing a coloured link to the users profile)
 157      *             no_profile (the same as full but forcing no profile link)
 158      * @param string $guest_username Optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then.
 159      * @param string $custom_profile_url Optional parameter to specify a profile url. The user id get appended to this url as &amp;u={user_id}
 160      * @param bool $query Should we query the database if this user has not yet been loaded?
 161      *                         Typically this should be left as false and you should make sure
 162      *                         you load users ahead of time with load_users()
 163      * @return string
 164      */
 165      public function get_username($user_id, $mode, $guest_username = false, $custom_profile_url = false, $query = false)
 166      {
 167          if (!($user = $this->get_user($user_id, $query)))
 168          {
 169              return '';
 170          }
 171   
 172          return get_username_string($mode, $user['user_id'], $user['username'], $user['user_colour'], $guest_username, $custom_profile_url);
 173      }
 174   
 175      /**
 176      * Get avatar
 177      *
 178      * @param int $user_id User ID of the user you want to retreive the avatar for
 179      * @param bool $query Should we query the database if this user has not yet been loaded?
 180      *                         Typically this should be left as false and you should make sure
 181      *                         you load users ahead of time with load_users()
 182      * @return string
 183      */
 184      public function get_avatar($user_id, $query = false)
 185      {
 186          if (!($user = $this->get_user($user_id, $query)))
 187          {
 188              return '';
 189          }
 190   
 191          if (!function_exists('get_user_avatar'))
 192          {
 193              include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext);
 194          }
 195   
 196          return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height']);
 197      }
 198   
 199      /**
 200      * Get rank
 201      *
 202      * @param int $user_id User ID of the user you want to retreive the rank for
 203      * @param bool $query Should we query the database if this user has not yet been loaded?
 204      *                         Typically this should be left as false and you should make sure
 205      *                         you load users ahead of time with load_users()
 206      * @return array Array with keys 'rank_title', 'rank_img', and 'rank_img_src'
 207      */
 208      public function get_rank($user_id, $query = false)
 209      {
 210          if (!($user = $this->get_user($user_id, $query)))
 211          {
 212              return '';
 213          }
 214   
 215          if (!function_exists('phpbb_get_user_rank'))
 216          {
 217              include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext);
 218          }
 219   
 220          $rank = array(
 221              'rank_title',
 222              'rank_img',
 223              'rank_img_src',
 224          );
 225   
 226          $user_rank_data = phpbb_get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']));
 227          $rank['rank_title'] = $user_rank_data['title'];
 228          $rank['rank_img'] = $user_rank_data['img'];
 229          $rank['rank_img_src'] = $user_rank_data['img_src'];
 230   
 231          return $rank;
 232      }
 233  }
 234