diff options
Diffstat (limited to 'phpBB/phpbb/group')
-rw-r--r-- | phpBB/phpbb/group/helper.php | 87 |
1 files changed, 52 insertions, 35 deletions
diff --git a/phpBB/phpbb/group/helper.php b/phpBB/phpbb/group/helper.php index fc657a59a2..3b4796f3b2 100644 --- a/phpBB/phpbb/group/helper.php +++ b/phpBB/phpbb/group/helper.php @@ -13,27 +13,35 @@ namespace phpbb\group; +use phpbb\auth\auth; +use phpbb\cache; +use phpbb\config\config; +use phpbb\language\language; +use phpbb\event\dispatcher_interface; +use phpbb\path_helper; +use phpbb\user; + class helper { - /** @var \phpbb\auth\auth */ + /** @var auth */ protected $auth; - /** @var \phpbb\cache\service */ + /** @var cache\service */ protected $cache; - /** @var \phpbb\config\config */ + /** @var config */ protected $config; - /** @var \phpbb\language\language */ + /** @var language */ protected $language; - /** @var \phpbb\event\dispatcher_interface */ + /** @var dispatcher_interface */ protected $phpbb_dispatcher; - /** @var \phpbb\path_helper */ + /** @var path_helper */ protected $phpbb_path_helper; - /** @var \phpbb\user */ + /** @var user */ protected $user; /** @var string phpBB root path */ @@ -42,20 +50,23 @@ class helper /** @var string PHP file extension */ protected $php_ext; + /** @var array Return templates for a group name string */ + protected $name_strings; + /** * Constructor * - * @param \phpbb\auth\auth $auth Authentication object - * @param \phpbb\cache\service $cache Cache object - * @param \phpbb\config\config $config Configuration object - * @param \phpbb\language\language $language Language object - * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object - * @param \phpbb\path_helper $phpbb_path_helper Path helper object - * @param \phpbb\user $user User object - * @param string $phpbb_root_path phpBB root path - * @param string $php_ext PHP file extension + * @param auth $auth Authentication object + * @param cache\service $cache Cache service object + * @param config $config Configuration object + * @param language $language Language object + * @param dispatcher_interface $phpbb_dispatcher Event dispatcher object + * @param path_helper $phpbb_path_helper Path helper object + * @param user $user User object + * @param string $phpbb_root_path phpBB root path + * @param string $php_ext PHP file extension */ - public function __construct(\phpbb\auth\auth $auth, \phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\language\language $language, \phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\path_helper $phpbb_path_helper, \phpbb\user $user, $phpbb_root_path, $php_ext) + public function __construct(auth $auth, cache\service $cache, config $config, language $language, dispatcher_interface $phpbb_dispatcher, path_helper $phpbb_path_helper, user $user, $phpbb_root_path, $php_ext) { $this->auth = $auth; $this->cache = $cache; @@ -67,6 +78,14 @@ class helper $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + + $this->name_strings = array( + 'base_url' => append_sid("{$phpbb_root_path}memberlist.{$php_ext}", 'mode=group&g={GROUP_ID}'), + 'tpl_noprofile' => '<span class="username">{GROUP_NAME}</span>', + 'tpl_noprofile_colour' => '<span class="username-coloured" style="color: {GROUP_COLOUR};">{GROUP_NAME}</span>', + 'tpl_profile' => '<a class="username" href="{PROFILE_URL}">{GROUP_NAME}</a>', + 'tpl_profile_colour' => '<a class="username-coloured" href="{PROFILE_URL}" style="color: {GROUP_COLOUR};">{GROUP_NAME}</a>', + ); } /** @@ -82,7 +101,11 @@ class helper /** * Get group name details for placing into templates. * - * @param string $mode Can be profile (for getting an url to the profile), group_name (for obtaining the group name), colour (for obtaining the group colour), full (for obtaining a html string representing a coloured link to the group's profile) or no_profile (the same as full but forcing no profile link) + * @param string $mode profile (for getting an url to the profile), + * group_name (for obtaining the group name), + * colour (for obtaining the group colour), + * full (for obtaining a coloured group name link to the group's profile), + * no_profile (the same as full but forcing no profile link) * @param int $group_id The group id * @param string $group_name The group name * @param string $group_colour The group colour @@ -92,14 +115,6 @@ class helper */ public function get_name_string($mode, $group_id, $group_name, $group_colour = '', $custom_profile_url = false) { - $_profile_cache = array( - 'base_url' => append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=group&g={GROUP_ID}'), - 'tpl_noprofile' => '<span class="username">{GROUP_NAME}</span>', - 'tpl_noprofile_colour' => '<span class="username-coloured" style="color: {GROUP_COLOUR};">{GROUP_NAME}</span>', - 'tpl_profile' => '<a class="username" href="{PROFILE_URL}">{GROUP_NAME}</a>', - 'tpl_profile_colour' => '<a class="username-coloured" href="{PROFILE_URL}" style="color: {GROUP_COLOUR};">{GROUP_NAME}</a>', - ); - // This switch makes sure we only run code required for the mode switch ($mode) { @@ -139,7 +154,7 @@ class helper // For anonymous the link leads to a login page. if ($group_id && ($this->user->data['user_id'] == ANONYMOUS || $this->auth->acl_get('u_viewprofile'))) { - $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&g=' . (int) $group_id : str_replace(array('={GROUP_ID}', '=%7BGROUP_ID%7D'), '=' . (int) $group_id, $_profile_cache['base_url']); + $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&g=' . (int) $group_id : str_replace(array('={GROUP_ID}', '=%7BGROUP_ID%7D'), '=' . (int) $group_id, $this->name_strings['base_url']); } else { @@ -158,16 +173,18 @@ class helper if (!isset($group_name_string)) { - if (($mode === 'full' && !$profile_url) || $mode === 'no_profile') + if (($mode === 'full' && empty($profile_url)) || $mode === 'no_profile') { - $group_name_string = str_replace(array('{GROUP_COLOUR}', '{GROUP_NAME}'), array($group_colour, $group_name), (!$group_colour) ? $_profile_cache['tpl_noprofile'] : $_profile_cache['tpl_noprofile_colour']); + $group_name_string = str_replace(array('{GROUP_COLOUR}', '{GROUP_NAME}'), array($group_colour, $group_name), (!$group_colour) ? $this->name_strings['tpl_noprofile'] : $this->name_strings['tpl_noprofile_colour']); } else { - $group_name_string = str_replace(array('{PROFILE_URL}', '{GROUP_COLOUR}', '{GROUP_NAME}'), array($profile_url, $group_colour, $group_name), (!$group_colour) ? $_profile_cache['tpl_profile'] : $_profile_cache['tpl_profile_colour']); + $group_name_string = str_replace(array('{PROFILE_URL}', '{GROUP_COLOUR}', '{GROUP_NAME}'), array($profile_url, $group_colour, $group_name), (!$group_colour) ? $this->name_strings['tpl_profile'] : $this->name_strings['tpl_profile_colour']); } } + $name_strings = $this->name_strings; + /** * Use this event to change the output of the group name * @@ -178,8 +195,8 @@ class helper * @var string group_colour The group colour * @var string custom_profile_url Optional parameter to specify a profile url. * @var string group_name_string The string that has been generated - * @var array _profile_cache Array of original return templates - * @since 3.2.5-RC1 + * @var array name_strings Array of original return templates + * @since 3.2.6-RC1 */ $vars = array( 'mode', @@ -188,7 +205,7 @@ class helper 'group_colour', 'custom_profile_url', 'group_name_string', - '_profile_cache', + 'name_strings', ); extract($this->phpbb_dispatcher->trigger_event('core.modify_group_name_string', compact($vars))); @@ -216,7 +233,7 @@ class helper * * @event core.get_group_rank_before * @var array group_data Array with group's data - * @since 3.2.5-RC1 + * @since 3.2.6-RC1 */ $vars = array('group_data'); @@ -245,7 +262,7 @@ class helper * @event core.get_group_rank_after * @var array group_data Array with group's data * @var array group_rank_data Group rank data - * @since 3.2.5-RC1 + * @since 3.2.6-RC1 */ $vars = array( |