From 7030578bbe9e11c18b5becaf8b06e670e3c2e3cd Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 14 Jul 2013 01:32:34 -0400 Subject: [ticket/11698] Moving all autoloadable files to phpbb/ PHPBB3-11698 --- phpBB/phpbb/user_loader.php | 231 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 phpBB/phpbb/user_loader.php (limited to 'phpBB/phpbb/user_loader.php') diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php new file mode 100644 index 0000000000..37bf9648c1 --- /dev/null +++ b/phpBB/phpbb/user_loader.php @@ -0,0 +1,231 @@ +db = $db; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->users_table = $users_table; + } + + /** + * Load user helper + * + * @param array $user_ids + */ + public function load_users(array $user_ids) + { + $user_ids[] = ANONYMOUS; + + // Make user_ids unique and convert to integer. + $user_ids = array_map('intval', array_unique($user_ids)); + + // Do not load users we already have in $this->users + $user_ids = array_diff($user_ids, array_keys($this->users)); + + if (sizeof($user_ids)) + { + $sql = 'SELECT * + FROM ' . $this->users_table . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->users[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + } + } + + /** + * Load a user by username + * + * Stores the full data in the user cache so they do not need to be loaded again + * Returns the user id so you may use get_user() from the returned value + * + * @param string $username Raw username to load (will be cleaned) + * @return int User ID for the username + */ + public function load_user_by_username($username) + { + $sql = 'SELECT * + FROM ' . $this->users_table . " + WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($username)) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + $this->users[$row['user_id']] = $row; + + return $row['user_id']; + } + + return ANONYMOUS; + } + + /** + * Get a user row from our users cache + * + * @param int $user_id User ID of the user you want to retreive + * @param bool $query Should we query the database if this user has not yet been loaded? + * Typically this should be left as false and you should make sure + * you load users ahead of time with load_users() + * @return array|bool Row from the database of the user or Anonymous if the user wasn't loaded/does not exist + * or bool False if the anonymous user was not loaded + */ + public function get_user($user_id, $query = false) + { + if (isset($this->users[$user_id])) + { + return $this->users[$user_id]; + } + // 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) + else if ($query || $user_id == ANONYMOUS) + { + $this->load_users(array($user_id)); + + return $this->get_user($user_id); + } + + return $this->get_user(ANONYMOUS); + } + + /** + * Get username + * + * @param int $user_id User ID of the user you want to retreive the username for + * @param string $mode The mode to load (same as get_username_string). One of the following: + * profile (for getting an url to the profile) + * username (for obtaining the username) + * colour (for obtaining the user colour) + * full (for obtaining a html string representing a coloured link to the users profile) + * no_profile (the same as full but forcing no profile link) + * @param string $guest_username Optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. + * @param string $custom_profile_url Optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} + * @param bool $query Should we query the database if this user has not yet been loaded? + * Typically this should be left as false and you should make sure + * you load users ahead of time with load_users() + * @return string + */ + public function get_username($user_id, $mode, $guest_username = false, $custom_profile_url = false, $query = false) + { + if (!($user = $this->get_user($user_id, $query))) + { + return ''; + } + + return get_username_string($mode, $user['user_id'], $user['username'], $user['user_colour'], $guest_username, $custom_profile_url); + } + + /** + * Get avatar + * + * @param int $user_id User ID of the user you want to retreive the avatar for + * @param bool $query Should we query the database if this user has not yet been loaded? + * Typically this should be left as false and you should make sure + * you load users ahead of time with load_users() + * @return string + */ + public function get_avatar($user_id, $query = false) + { + if (!($user = $this->get_user($user_id, $query))) + { + return ''; + } + + if (!function_exists('get_user_avatar')) + { + include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); + } + + return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height']); + } + + /** + * Get rank + * + * @param int $user_id User ID of the user you want to retreive the rank for + * @param bool $query Should we query the database if this user has not yet been loaded? + * Typically this should be left as false and you should make sure + * you load users ahead of time with load_users() + * @return array Array with keys 'rank_title', 'rank_img', and 'rank_img_src' + */ + public function get_rank($user_id, $query = false) + { + if (!($user = $this->get_user($user_id, $query))) + { + return ''; + } + + if (!function_exists('get_user_rank')) + { + include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); + } + + $rank = array( + 'rank_title', + 'rank_img', + 'rank_img_src', + ); + + get_user_rank($user['user_rank'], (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']), $rank['rank_title'], $rank['rank_img'], $rank['rank_img_src']); + + return $rank; + } +} -- cgit v1.2.1 From b95fdacdd378877d277e261465da73deb06e50da Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 10 Sep 2013 14:01:09 +0200 Subject: [ticket/11700] Move all recent code to namespaces PHPBB3-11700 --- phpBB/phpbb/user_loader.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/user_loader.php') diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index 37bf9648c1..78620ab1b9 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -7,6 +7,8 @@ * */ +namespace phpbb; + /** */ if (!defined('IN_PHPBB')) @@ -22,9 +24,9 @@ if (!defined('IN_PHPBB')) * have to query the same user multiple times in * different services. */ -class phpbb_user_loader +class user_loader { - /** @var phpbb_db_driver */ + /** @var \phpbb\db\driver\driver */ protected $db = null; /** @var string */ @@ -46,12 +48,12 @@ class phpbb_user_loader /** * User loader constructor * - * @param phpbb_db_driver $db A database connection + * @param \phpbb\db\driver\driver $db A database connection * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $php_ext php file extension * @param string $users_table The name of the database table (phpbb_users) */ - public function __construct(phpbb_db_driver $db, $phpbb_root_path, $php_ext, $users_table) + public function __construct(\phpbb\db\driver\driver $db, $phpbb_root_path, $php_ext, $users_table) { $this->db = $db; -- cgit v1.2.1 From 7aa8f6461f1e85cf91931f56b95384e54fec07c2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 30 Oct 2013 13:05:28 +0100 Subject: [task/code-sniffer] Remove the IN_PHPBB check side-effect from class files. PHPBB3-11980 --- phpBB/phpbb/user_loader.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'phpBB/phpbb/user_loader.php') diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index 78620ab1b9..c1d69802f8 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -9,13 +9,6 @@ namespace phpbb; -/** -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * User loader class * -- cgit v1.2.1 From 11a9104b8a50cbc62cba0c242dee554b5209a327 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 17 Mar 2014 13:29:35 +0100 Subject: [ticket/12282] Use interface for type hinting PHPBB3-12282 --- phpBB/phpbb/user_loader.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/user_loader.php') diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index c1d69802f8..9179572277 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -19,7 +19,7 @@ namespace phpbb; */ class user_loader { - /** @var \phpbb\db\driver\driver */ + /** @var \phpbb\db\driver\driver_interface */ protected $db = null; /** @var string */ @@ -41,12 +41,12 @@ class user_loader /** * User loader constructor * - * @param \phpbb\db\driver\driver $db A database connection + * @param \phpbb\db\driver\driver_interface $db A database connection * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $php_ext php file extension * @param string $users_table The name of the database table (phpbb_users) */ - public function __construct(\phpbb\db\driver\driver $db, $phpbb_root_path, $php_ext, $users_table) + public function __construct(\phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext, $users_table) { $this->db = $db; -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- phpBB/phpbb/user_loader.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/user_loader.php') diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index 9179572277..c9707ee432 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ -- cgit v1.2.1 From 685bdc87e6480597c7d7f30a7b9477c543099d2e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 18 Aug 2014 14:04:11 +0200 Subject: [ticket/12993] Fix user_loader and memberlist PHPBB3-12993 --- phpBB/phpbb/user_loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/user_loader.php') diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index c9707ee432..e6a2429163 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -223,7 +223,7 @@ class user_loader 'rank_img_src', ); - get_user_rank($user['user_rank'], (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']), $rank['rank_title'], $rank['rank_img'], $rank['rank_img_src']); + get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']), $rank['rank_title'], $rank['rank_img'], $rank['rank_img_src']); return $rank; } -- cgit v1.2.1 From 496cc64bc63befc2bb6f250e1712cd5a00986aef Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 18 Aug 2014 16:13:32 +0200 Subject: [ticket/12993] Rename to phpbb_get_user_rank PHPBB3-12993 --- phpBB/phpbb/user_loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/user_loader.php') diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index e6a2429163..35199d8864 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -223,7 +223,7 @@ class user_loader 'rank_img_src', ); - get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']), $rank['rank_title'], $rank['rank_img'], $rank['rank_img_src']); + phpbb_get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']), $rank['rank_title'], $rank['rank_img'], $rank['rank_img_src']); return $rank; } -- cgit v1.2.1 From 5e7d9d2fcf5a78ef97287c635310c6ea28572464 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 18 Aug 2014 18:44:23 +0200 Subject: [ticket/12993] Fix includes of functions_display PHPBB3-12993 --- phpBB/phpbb/user_loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/user_loader.php') diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index 35199d8864..4da2b383c6 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -212,7 +212,7 @@ class user_loader return ''; } - if (!function_exists('get_user_rank')) + if (!function_exists('phpbb_get_user_rank')) { include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); } -- cgit v1.2.1 From fe1ab6d2efe7389ab5deb6cab0d721a1fa80c503 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 19 Aug 2014 22:25:01 +0200 Subject: [ticket/12993] Return an array instead of reference passing PHPBB3-12993 --- phpBB/phpbb/user_loader.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/user_loader.php') diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index 4da2b383c6..24e663b150 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -223,7 +223,10 @@ class user_loader 'rank_img_src', ); - phpbb_get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']), $rank['rank_title'], $rank['rank_img'], $rank['rank_img_src']); + $user_rank_data = phpbb_get_user_rank($user, (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts'])); + $rank['rank_title'] = $user_rank_data['title']; + $rank['rank_img'] = $user_rank_data['img']; + $rank['rank_img_src'] = $user_rank_data['img_src']; return $rank; } -- cgit v1.2.1 From be1d1c7d05a0b0dec259da967e2ed277fb8f632f Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Thu, 28 May 2015 18:05:07 +0200 Subject: [ticket/13882] Lazy load the notification avatars. This moves them further down the waterfall, making the page load quicker. PHPBB3-13882 --- phpBB/phpbb/user_loader.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/user_loader.php') diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index 24e663b150..5ce8ca2d4d 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -179,9 +179,10 @@ class user_loader * @param bool $query Should we query the database if this user has not yet been loaded? * Typically this should be left as false and you should make sure * you load users ahead of time with load_users() + * @param bool @lazy If true, will be lazy loaded (requires JS) * @return string */ - public function get_avatar($user_id, $query = false) + public function get_avatar($user_id, $query = false, $lazy = false) { if (!($user = $this->get_user($user_id, $query))) { @@ -193,7 +194,7 @@ class user_loader include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); } - return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height']); + return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height'], 'USER_AVATAR', false, $lazy); } /** -- cgit v1.2.1 From 91869cc43cd89109f25c35f6371becb4b3d690d9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 3 Dec 2015 16:43:00 +0100 Subject: [ticket/14334] Use phpbb_get_avatar() in user_loader PHPBB3-14334 --- phpBB/phpbb/user_loader.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'phpBB/phpbb/user_loader.php') diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index 5ce8ca2d4d..967d96d73a 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -189,12 +189,7 @@ class user_loader return ''; } - if (!function_exists('get_user_avatar')) - { - include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); - } - - return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height'], 'USER_AVATAR', false, $lazy); + return phpbb_get_avatar(\phpbb\avatar\manager::clean_row($user, 'user'), 'USER_AVATAR', false, $lazy); } /** -- cgit v1.2.1