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

helper.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 8.95 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\group;
015   
016  use phpbb\auth\auth;
017  use phpbb\cache\service as cache;
018  use phpbb\config\config;
019  use phpbb\language\language;
020  use phpbb\event\dispatcher_interface;
021  use phpbb\path_helper;
022  use phpbb\user;
023   
024  class helper
025  {
026      /** @var auth */
027      protected $auth;
028   
029      /** @var cache */
030      protected $cache;
031   
032      /** @var config */
033      protected $config;
034   
035      /** @var language */
036      protected $language;
037   
038      /** @var dispatcher_interface */
039      protected $dispatcher;
040   
041      /** @var path_helper */
042      protected $path_helper;
043   
044      /** @var user */
045      protected $user;
046   
047      /** @var string phpBB root path */
048      protected $phpbb_root_path;
049   
050      /** @var array Return templates for a group name string */
051      protected $name_strings;
052   
053      /**
054       * Constructor
055       *
056       * @param auth                    $auth            Authentication object
057       * @param cache                    $cache            Cache service object
058       * @param config                $config            Configuration object
059       * @param language                $language        Language object
060       * @param dispatcher_interface    $dispatcher        Event dispatcher object
061       * @param path_helper            $path_helper    Path helper object
062       * @param user                    $user            User object
063       */
064      public function __construct(auth $auth, cache $cache, config $config, language $language, dispatcher_interface $dispatcher, path_helper $path_helper, user $user)
065      {
066          $this->auth = $auth;
067          $this->cache = $cache;
068          $this->config = $config;
069          $this->language = $language;
070          $this->dispatcher = $dispatcher;
071          $this->path_helper = $path_helper;
072          $this->user = $user;
073   
074          $this->phpbb_root_path = $path_helper->get_phpbb_root_path();
075   
076          /** @html Group name spans and links for usage in the template */
077          $this->name_strings = array(
078              'base_url'                => "{$path_helper->get_phpbb_root_path()}memberlist.{$path_helper->get_php_ext()}?mode=group&amp;g={GROUP_ID}",
079              'tpl_noprofile'            => '<span class="username">{GROUP_NAME}</span>',
080              'tpl_noprofile_colour'    => '<span class="username-coloured" style="color: {GROUP_COLOUR};">{GROUP_NAME}</span>',
081              'tpl_profile'            => '<a class="username" href="{PROFILE_URL}">{GROUP_NAME}</a>',
082              'tpl_profile_colour'    => '<a class="username-coloured" href="{PROFILE_URL}" style="color: {GROUP_COLOUR};">{GROUP_NAME}</a>',
083          );
084      }
085   
086      /**
087       * @param    string    $group_name    The stored group name
088       *
089       * @return string        Group name or translated group name if it exists
090       */
091      public function get_name($group_name)
092      {
093          return $this->language->is_set('G_' . utf8_strtoupper($group_name)) ? $this->language->lang('G_' . utf8_strtoupper($group_name)) : $group_name;
094      }
095   
096      /**
097       * Get group name details for placing into templates.
098       *
099       * @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  }
295