[ticket/15886] Class variable, comment splitting, events since tag, class names

PHPBB3-15886
This commit is contained in:
mrgoldy 2018-12-29 13:11:51 +01:00
parent d356fa9f97
commit d79eb72fc1

View file

@ -13,27 +13,35 @@
namespace phpbb\group; 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 class helper
{ {
/** @var \phpbb\auth\auth */ /** @var auth */
protected $auth; protected $auth;
/** @var \phpbb\cache\service */ /** @var cache\service */
protected $cache; protected $cache;
/** @var \phpbb\config\config */ /** @var config */
protected $config; protected $config;
/** @var \phpbb\language\language */ /** @var language */
protected $language; protected $language;
/** @var \phpbb\event\dispatcher_interface */ /** @var dispatcher_interface */
protected $phpbb_dispatcher; protected $phpbb_dispatcher;
/** @var \phpbb\path_helper */ /** @var path_helper */
protected $phpbb_path_helper; protected $phpbb_path_helper;
/** @var \phpbb\user */ /** @var user */
protected $user; protected $user;
/** @var string phpBB root path */ /** @var string phpBB root path */
@ -42,20 +50,23 @@ class helper
/** @var string PHP file extension */ /** @var string PHP file extension */
protected $php_ext; protected $php_ext;
/** @var array Return templates for a group name string */
protected $name_strings;
/** /**
* Constructor * Constructor
* *
* @param \phpbb\auth\auth $auth Authentication object * @param auth $auth Authentication object
* @param \phpbb\cache\service $cache Cache object * @param cache\service $cache Cache service object
* @param \phpbb\config\config $config Configuration object * @param config $config Configuration object
* @param \phpbb\language\language $language Language object * @param language $language Language object
* @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object * @param dispatcher_interface $phpbb_dispatcher Event dispatcher object
* @param \phpbb\path_helper $phpbb_path_helper Path helper object * @param path_helper $phpbb_path_helper Path helper object
* @param \phpbb\user $user User object * @param user $user User object
* @param string $phpbb_root_path phpBB root path * @param string $phpbb_root_path phpBB root path
* @param string $php_ext PHP file extension * @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->auth = $auth;
$this->cache = $cache; $this->cache = $cache;
@ -67,6 +78,14 @@ class helper
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext; $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. * 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 int $group_id The group id
* @param string $group_name The group name * @param string $group_name The group name
* @param string $group_colour The group colour * @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) 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&amp;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 // This switch makes sure we only run code required for the mode
switch ($mode) switch ($mode)
{ {
@ -139,7 +154,7 @@ class helper
// For anonymous the link leads to a login page. // For anonymous the link leads to a login page.
if ($group_id && ($this->user->data['user_id'] == ANONYMOUS || $this->auth->acl_get('u_viewprofile'))) if ($group_id && ($this->user->data['user_id'] == ANONYMOUS || $this->auth->acl_get('u_viewprofile')))
{ {
$profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&amp;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 . '&amp;g=' . (int) $group_id : str_replace(array('={GROUP_ID}', '=%7BGROUP_ID%7D'), '=' . (int) $group_id, $this->name_strings['base_url']);
} }
else else
{ {
@ -158,16 +173,18 @@ class helper
if (!isset($group_name_string)) 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 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 * 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 group_colour The group colour
* @var string custom_profile_url Optional parameter to specify a profile url. * @var string custom_profile_url Optional parameter to specify a profile url.
* @var string group_name_string The string that has been generated * @var string group_name_string The string that has been generated
* @var array _profile_cache Array of original return templates * @var array name_strings Array of original return templates
* @since 3.2.5-RC1 * @since 3.2.6-RC1
*/ */
$vars = array( $vars = array(
'mode', 'mode',
@ -188,7 +205,7 @@ class helper
'group_colour', 'group_colour',
'custom_profile_url', 'custom_profile_url',
'group_name_string', 'group_name_string',
'_profile_cache', 'name_strings',
); );
extract($this->phpbb_dispatcher->trigger_event('core.modify_group_name_string', compact($vars))); 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 * @event core.get_group_rank_before
* @var array group_data Array with group's data * @var array group_data Array with group's data
* @since 3.2.5-RC1 * @since 3.2.6-RC1
*/ */
$vars = array('group_data'); $vars = array('group_data');
@ -245,7 +262,7 @@ class helper
* @event core.get_group_rank_after * @event core.get_group_rank_after
* @var array group_data Array with group's data * @var array group_data Array with group's data
* @var array group_rank_data Group rank data * @var array group_rank_data Group rank data
* @since 3.2.5-RC1 * @since 3.2.6-RC1
*/ */
$vars = array( $vars = array(