Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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: 02.04.2025, 15:01 - Dateigröße: 7.07 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      * @param array $ignore_types user types to ignore
068      */
069      public function load_users(array $user_ids, array $ignore_types = array())
070      {
071          $user_ids[] = ANONYMOUS;
072   
073          // Make user_ids unique and convert to integer.
074          $user_ids = array_map('intval', array_unique($user_ids));
075   
076          // Do not load users we already have in $this->users
077          $user_ids = array_diff($user_ids, array_keys($this->users));
078   
079          if (count($user_ids))
080          {
081              $sql = 'SELECT *
082                  FROM ' . $this->users_table . '
083                  WHERE ' . $this->db->sql_in_set('user_id', $user_ids) . '
084                      AND ' . $this->db->sql_in_set('user_type', $ignore_types, true, true);
085              $result = $this->db->sql_query($sql);
086   
087              while ($row = $this->db->sql_fetchrow($result))
088              {
089                  $this->users[$row['user_id']] = $row;
090              }
091              $this->db->sql_freeresult($result);
092          }
093      }
094   
095      /**
096      * Load a user by username
097      *
098      * Stores the full data in the user cache so they do not need to be loaded again
099      * Returns the user id so you may use get_user() from the returned value
100      *
101      * @param string $username Raw username to load (will be cleaned)
102      * @return int User ID for the username
103      */
104      public function load_user_by_username($username)
105      {
106          $sql = 'SELECT *
107              FROM ' . $this->users_table . "
108              WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($username)) . "'";
109          $result = $this->db->sql_query($sql);
110          $row = $this->db->sql_fetchrow($result);
111          $this->db->sql_freeresult($result);
112   
113          if ($row)
114          {
115              $this->users[$row['user_id']] = $row;
116   
117              return $row['user_id'];
118          }
119   
120          return ANONYMOUS;
121      }
122   
123      /**
124      * Get a user row from our users cache
125      *
126      * @param int $user_id User ID of the user you want to retrieve
127      * @param bool $query Should we query the database if this user has not yet been loaded?
128      *                         Typically this should be left as false and you should make sure
129      *                         you load users ahead of time with load_users()
130      * @return array|bool Row from the database of the user or Anonymous if the user wasn't loaded/does not exist
131      *                         or bool False if the anonymous user was not loaded
132      */
133      public function get_user($user_id, $query = false)
134      {
135          if (isset($this->users[$user_id]))
136          {
137              return $this->users[$user_id];
138          }
139          // 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)
140          else if ($query || $user_id == ANONYMOUS)
141          {
142              $this->load_users(array($user_id));
143   
144              return $user_id != ANONYMOUS ? $this->get_user($user_id) : $this->users[$user_id] ?? false;
145          }
146   
147          return $this->get_user(ANONYMOUS);
148      }
149   
150      /**
151      * Get username
152      *
153      * @param int $user_id User ID of the user you want to retrieve the username for
154      * @param string $mode The mode to load (same as get_username_string). One of the following:
155      *             profile (for getting an url to the profile)
156      *             username (for obtaining the username)
157      *             colour (for obtaining the user colour)
158      *             full (for obtaining a html string representing a coloured link to the users profile)
159      *             no_profile (the same as full but forcing no profile link)
160      * @param string $guest_username Optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then.
161      * @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}
162      * @param bool $query Should we query the database if this user has not yet been loaded?
163      *                         Typically this should be left as false and you should make sure
164      *                         you load users ahead of time with load_users()
165      * @return string
166      */
167      public function get_username($user_id, $mode, $guest_username = false, $custom_profile_url = false, $query = false)
168      {
169          if (!($user = $this->get_user($user_id, $query)))
170          {
171              return '';
172          }
173   
174          return get_username_string($mode, $user['user_id'], $user['username'], $user['user_colour'], $guest_username, $custom_profile_url);
175      }
176   
177      /**
178      * Get avatar
179      *
180      * @param int $user_id User ID of the user you want to retrieve the avatar for
181      * @param bool $query Should we query the database if this user has not yet been loaded?
182      *                         Typically this should be left as false and you should make sure
183      *                         you load users ahead of time with load_users()
184      * @param bool $lazy If true, will be lazy loaded (requires JS)
185      * @return string
186      */
187      public function get_avatar($user_id, $query = false, $lazy = false)
188      {
189          if (!($user = $this->get_user($user_id, $query)))
190          {
191              return '';
192          }
193   
194          $row = array(
195              'avatar'        => $user['user_avatar'],
196              'avatar_type'    => $user['user_avatar_type'],
197              'avatar_width'    => $user['user_avatar_width'],
198              'avatar_height'    => $user['user_avatar_height'],
199          );
200   
201          return phpbb_get_avatar($row, 'USER_AVATAR', false, $lazy);
202      }
203   
204      /**
205      * Get rank
206      *
207      * @param int $user_id User ID of the user you want to retrieve the rank for
208      * @param bool $query Should we query the database if this user has not yet been loaded?
209      *                         Typically this should be left as false and you should make sure
210      *                         you load users ahead of time with load_users()
211      * @return array Array with keys 'rank_title', 'rank_img', and 'rank_img_src'
212      */
213      public function get_rank($user_id, $query = false)
214      {
215          if (!($user = $this->get_user($user_id, $query)))
216          {
217              return '';
218          }
219   
220          if (!function_exists('phpbb_get_user_rank'))
221          {
222              include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext);
223          }
224   
225          $rank = array(
226              'rank_title',
227              'rank_img',
228              'rank_img_src',
229          );
230   
231          $user_rank_data = phpbb_get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']));
232          $rank['rank_title'] = $user_rank_data['title'];
233          $rank['rank_img'] = $user_rank_data['img'];
234          $rank['rank_img_src'] = $user_rank_data['img_src'];
235   
236          return $rank;
237      }
238  }
239