[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/phpbb/group/ -> helper.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\group;
  15  
  16  use phpbb\auth\auth;
  17  use phpbb\cache\service as cache;
  18  use phpbb\config\config;
  19  use phpbb\language\language;
  20  use phpbb\event\dispatcher_interface;
  21  use phpbb\path_helper;
  22  use phpbb\user;
  23  
  24  class helper
  25  {
  26      /** @var auth */
  27      protected $auth;
  28  
  29      /** @var cache */
  30      protected $cache;
  31  
  32      /** @var config */
  33      protected $config;
  34  
  35      /** @var language */
  36      protected $language;
  37  
  38      /** @var dispatcher_interface */
  39      protected $dispatcher;
  40  
  41      /** @var path_helper */
  42      protected $path_helper;
  43  
  44      /** @var user */
  45      protected $user;
  46  
  47      /** @var string phpBB root path */
  48      protected $phpbb_root_path;
  49  
  50      /** @var array Return templates for a group name string */
  51      protected $name_strings;
  52  
  53      /**
  54       * Constructor
  55       *
  56       * @param auth                    $auth            Authentication object
  57       * @param cache                    $cache            Cache service object
  58       * @param config                $config            Configuration object
  59       * @param language                $language        Language object
  60       * @param dispatcher_interface    $dispatcher        Event dispatcher object
  61       * @param path_helper            $path_helper    Path helper object
  62       * @param user                    $user            User object
  63       */
  64  	public function __construct(auth $auth, cache $cache, config $config, language $language, dispatcher_interface $dispatcher, path_helper $path_helper, user $user)
  65      {
  66          $this->auth = $auth;
  67          $this->cache = $cache;
  68          $this->config = $config;
  69          $this->language = $language;
  70          $this->dispatcher = $dispatcher;
  71          $this->path_helper = $path_helper;
  72          $this->user = $user;
  73  
  74          $this->phpbb_root_path = $path_helper->get_phpbb_root_path();
  75  
  76          /** @html Group name spans and links for usage in the template */
  77          $this->name_strings = array(
  78              'base_url'                => "{$path_helper->get_phpbb_root_path()}memberlist.{$path_helper->get_php_ext()}?mode=group&amp;g={GROUP_ID}",
  79              'tpl_noprofile'            => '<span class="username">{GROUP_NAME}</span>',
  80              'tpl_noprofile_colour'    => '<span class="username-coloured" style="color: {GROUP_COLOUR};">{GROUP_NAME}</span>',
  81              'tpl_profile'            => '<a class="username" href="{PROFILE_URL}">{GROUP_NAME}</a>',
  82              'tpl_profile_colour'    => '<a class="username-coloured" href="{PROFILE_URL}" style="color: {GROUP_COLOUR};">{GROUP_NAME}</a>',
  83          );
  84      }
  85  
  86      /**
  87       * @param $group_name string    The stored group name
  88       *
  89       * @return string        Group name or translated group name if it exists
  90       */
  91  	public function get_name($group_name)
  92      {
  93          return $this->language->is_set('G_' . utf8_strtoupper($group_name)) ? $this->language->lang('G_' . utf8_strtoupper($group_name)) : $group_name;
  94      }
  95  
  96      /**
  97       * Get group name details for placing into templates.
  98       *
  99       * @html Group name spans and links
 100       *
 101       * @param string    $mode                Profile (for getting an url to the profile),
 102       *                                            group_name (for obtaining the group name),
 103       *                                            colour (for obtaining the group colour),
 104       *                                            full (for obtaining a coloured group name link to the group's profile),
 105       *                                            no_profile (the same as full but forcing no profile link)
 106       * @param int        $group_id            The group id
 107       * @param string    $group_name            The group name
 108       * @param string    $group_colour        The group colour
 109       * @param mixed        $custom_profile_url    optional parameter to specify a profile url. The group id gets appended to this url as &amp;g={group_id}
 110       *
 111       * @return string A string consisting of what is wanted based on $mode.
 112       */
 113  	public function get_name_string($mode, $group_id, $group_name, $group_colour = '', $custom_profile_url = false)
 114      {
 115          $s_is_bots = ($group_name === 'BOTS');
 116  
 117          // This switch makes sure we only run code required for the mode
 118          switch ($mode)
 119          {
 120              case 'full':
 121              case 'no_profile':
 122              case 'colour':
 123  
 124                  // Build correct group colour
 125                  $group_colour = $group_colour ? '#' . $group_colour : '';
 126  
 127                  // Return colour
 128                  if ($mode === 'colour')
 129                  {
 130                      $group_name_string = $group_colour;
 131                      break;
 132                  }
 133  
 134              // no break;
 135  
 136              case 'group_name':
 137  
 138                  // Build correct group name
 139                  $group_name = $this->get_name($group_name);
 140  
 141                  // Return group name
 142                  if ($mode === 'group_name')
 143                  {
 144                      $group_name_string = $group_name;
 145                      break;
 146                  }
 147  
 148              // no break;
 149  
 150              case 'profile':
 151  
 152                  // Build correct profile url - only show if not anonymous and permission to view profile if registered user
 153                  // For anonymous the link leads to a login page.
 154                  if ($group_id && !$s_is_bots && ($this->user->data['user_id'] == ANONYMOUS || $this->auth->acl_get('u_viewprofile')))
 155                  {
 156                      $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, append_sid($this->name_strings['base_url']));
 157                  }
 158                  else
 159                  {
 160                      $profile_url = '';
 161                  }
 162  
 163                  // Return profile
 164                  if ($mode === 'profile')
 165                  {
 166                      $group_name_string = $profile_url;
 167                      break;
 168                  }
 169  
 170              // no break;
 171          }
 172  
 173          if (!isset($group_name_string))
 174          {
 175              if (($mode === 'full' && empty($profile_url)) || $mode === 'no_profile' || $s_is_bots)
 176              {
 177                  $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']);
 178              }
 179              else
 180              {
 181                  $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']);
 182              }
 183          }
 184  
 185          $name_strings = $this->name_strings;
 186  
 187          /**
 188           * Use this event to change the output of the group name
 189           *
 190           * @event core.modify_group_name_string
 191           * @var string    mode                profile|group_name|colour|full|no_profile
 192           * @var int        group_id            The group identifier
 193           * @var string    group_name            The group name
 194           * @var string    group_colour        The group colour
 195           * @var string    custom_profile_url    Optional parameter to specify a profile url.
 196           * @var string    group_name_string    The string that has been generated
 197           * @var array    name_strings        Array of original return templates
 198           * @since 3.2.8-RC1
 199           */
 200          $vars = array(
 201              'mode',
 202              'group_id',
 203              'group_name',
 204              'group_colour',
 205              'custom_profile_url',
 206              'group_name_string',
 207              'name_strings',
 208          );
 209          extract($this->dispatcher->trigger_event('core.modify_group_name_string', compact($vars)));
 210  
 211          return $group_name_string;
 212      }
 213  
 214      /**
 215       * Get group rank title and image
 216       *
 217       * @html Group rank image element
 218       *
 219       * @param array        $group_data        The current stored group data
 220       *
 221       * @return array                    An associative array containing the rank title (title),
 222       *                                     the rank image as full img tag (img) and the rank image source (img_src)
 223       */
 224  	public function get_rank($group_data)
 225      {
 226          $group_rank_data = array(
 227              'title'        => null,
 228              'img'        => null,
 229              'img_src'    => null,
 230          );
 231  
 232          /**
 233           * Preparing a group's rank before displaying
 234           *
 235           * @event core.get_group_rank_before
 236           * @var    array    group_data        Array with group's data
 237           * @since 3.2.8-RC1
 238           */
 239  
 240          $vars = array('group_data');
 241          extract($this->dispatcher->trigger_event('core.get_group_rank_before', compact($vars)));
 242  
 243          if (!empty($group_data['group_rank']))
 244          {
 245              // Only obtain ranks if group rank is set
 246              $ranks = $this->cache->obtain_ranks();
 247  
 248              if (isset($ranks['special'][$group_data['group_rank']]))
 249              {
 250                  $rank = $ranks['special'][$group_data['group_rank']];
 251  
 252                  $group_rank_data['title'] = $rank['rank_title'];
 253  
 254                  $group_rank_data['img_src'] = (!empty($rank['rank_image'])) ? $this->path_helper->update_web_root_path($this->phpbb_root_path . $this->config['ranks_path'] . '/' . $rank['rank_image']) : '';
 255  
 256                  /** @html Group rank image element for usage in the template */
 257                  $group_rank_data['img'] = (!empty($rank['rank_image'])) ? '<img src="' . $group_rank_data['img_src'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
 258              }
 259          }
 260  
 261          /**
 262           * Modify a group's rank before displaying
 263           *
 264           * @event core.get_group_rank_after
 265           * @var    array    group_data        Array with group's data
 266           * @var    array    group_rank_data    Group rank data
 267           * @since 3.2.8-RC1
 268           */
 269  
 270          $vars = array(
 271              'group_data',
 272              'group_rank_data',
 273          );
 274          extract($this->dispatcher->trigger_event('core.get_group_rank_after', compact($vars)));
 275  
 276          return $group_rank_data;
 277      }
 278  
 279      /**
 280       * Get group avatar.
 281       * Wrapper function for phpbb_get_group_avatar()
 282       *
 283       * @param array        $group_row        Row from the groups table
 284       * @param string    $alt            Optional language string for alt tag within image, can be a language key or text
 285       * @param bool        $ignore_config    Ignores the config-setting, to be still able to view the avatar in the UCP
 286       * @param bool        $lazy            If true, will be lazy loaded (requires JS)
 287       *
 288       * @return string                     Avatar html
 289       */
 290  	function get_avatar($group_row, $alt = 'GROUP_AVATAR', $ignore_config = false, $lazy = false)
 291      {
 292          return phpbb_get_group_avatar($group_row, $alt, $ignore_config, $lazy);
 293      }
 294  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1