Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

manager.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 7.97 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\avatar;
 015   
 016  class manager
 017  {
 018      /**
 019      * phpBB configuration
 020      * @var \phpbb\config\config
 021      */
 022      protected $config;
 023   
 024      /**
 025      * Array that contains a list of enabled drivers
 026      * @var array
 027      */
 028      static protected $enabled_drivers = false;
 029   
 030      /**
 031      * Array that contains all available avatar drivers which are passed via the
 032      * service container
 033      * @var array
 034      */
 035      protected $avatar_drivers;
 036   
 037      /**
 038      * Default avatar data row
 039      * @var array
 040      */
 041      static protected $default_row = array(
 042          'avatar'        => '',
 043          'avatar_type'    => '',
 044          'avatar_width'    => 0,
 045          'avatar_height'    => 0,
 046      );
 047   
 048      /**
 049      * Construct an avatar manager object
 050      *
 051      * @param \phpbb\config\config $config phpBB configuration
 052      * @param array $avatar_drivers Avatar drivers passed via the service container
 053      */
 054      public function __construct(\phpbb\config\config $config, $avatar_drivers)
 055      {
 056          $this->config = $config;
 057          $this->register_avatar_drivers($avatar_drivers);
 058      }
 059   
 060      /**
 061      * Register avatar drivers
 062      *
 063      * @param array $avatar_drivers Service collection of avatar drivers
 064      */
 065      protected function register_avatar_drivers($avatar_drivers)
 066      {
 067          if (!empty($avatar_drivers))
 068          {
 069              foreach ($avatar_drivers as $driver)
 070              {
 071                  $this->avatar_drivers[$driver->get_name()] = $driver;
 072              }
 073          }
 074      }
 075   
 076      /**
 077      * Get the driver object specified by the avatar type
 078      *
 079      * @param string $avatar_type Avatar type; by default an avatar's service container name
 080      * @param bool $load_enabled Load only enabled avatars
 081      *
 082      * @return object Avatar driver object
 083      */
 084      public function get_driver($avatar_type, $load_enabled = true)
 085      {
 086          if (self::$enabled_drivers === false)
 087          {
 088              $this->load_enabled_drivers();
 089          }
 090   
 091          $avatar_drivers = ($load_enabled) ? self::$enabled_drivers : $this->get_all_drivers();
 092   
 093          // Legacy stuff...
 094          switch ($avatar_type)
 095          {
 096              case AVATAR_GALLERY:
 097                  $avatar_type = 'avatar.driver.local';
 098              break;
 099              case AVATAR_UPLOAD:
 100                  $avatar_type = 'avatar.driver.upload';
 101              break;
 102              case AVATAR_REMOTE:
 103                  $avatar_type = 'avatar.driver.remote';
 104              break;
 105          }
 106   
 107          if (!isset($avatar_drivers[$avatar_type]))
 108          {
 109              return null;
 110          }
 111   
 112          /*
 113          * There is no need to handle invalid avatar types as the following code
 114          * will cause a ServiceNotFoundException if the type does not exist
 115          */
 116          $driver = $this->avatar_drivers[$avatar_type];
 117   
 118          return $driver;
 119      }
 120   
 121      /**
 122      * Load the list of enabled drivers
 123      * This is executed once and fills self::$enabled_drivers
 124      */
 125      protected function load_enabled_drivers()
 126      {
 127          if (!empty($this->avatar_drivers))
 128          {
 129              self::$enabled_drivers = array();
 130              foreach ($this->avatar_drivers as $driver)
 131              {
 132                  if ($this->is_enabled($driver))
 133                  {
 134                      self::$enabled_drivers[$driver->get_name()] = $driver->get_name();
 135                  }
 136              }
 137              asort(self::$enabled_drivers);
 138          }
 139      }
 140   
 141      /**
 142      * Get a list of all avatar drivers
 143      *
 144      * As this function will only be called in the ACP avatar settings page, it
 145      * doesn't make much sense to cache the list of all avatar drivers like the
 146      * list of the enabled drivers.
 147      *
 148      * @return array Array containing a list of all avatar drivers
 149      */
 150      public function get_all_drivers()
 151      {
 152          $drivers = array();
 153   
 154          if (!empty($this->avatar_drivers))
 155          {
 156              foreach ($this->avatar_drivers as $driver)
 157              {
 158                  $drivers[$driver->get_name()] = $driver->get_name();
 159              }
 160              asort($drivers);
 161          }
 162   
 163          return $drivers;
 164      }
 165   
 166      /**
 167      * Get a list of enabled avatar drivers
 168      *
 169      * @return array Array containing a list of the enabled avatar drivers
 170      */
 171      public function get_enabled_drivers()
 172      {
 173          if (self::$enabled_drivers === false)
 174          {
 175              $this->load_enabled_drivers();
 176          }
 177   
 178          return self::$enabled_drivers;
 179      }
 180   
 181      /**
 182      * Strip out user_, group_, or other prefixes from array keys
 183      *
 184      * @param array    $row            User data or group data
 185      * @param string $prefix            Prefix of data keys (e.g. user), should not include the trailing underscore
 186      *
 187      * @return array    User or group data with keys that have been
 188      *            stripped from the preceding "user_" or "group_"
 189      *            Also the group id is prefixed with g, when the prefix group is removed.
 190      */
 191      static public function clean_row($row, $prefix = '')
 192      {
 193          // Upon creation of a user/group $row might be empty
 194          if (empty($row))
 195          {
 196              return self::$default_row;
 197          }
 198   
 199          $output = array();
 200          foreach ($row as $key => $value)
 201          {
 202              $key = preg_replace("#^(?:{$prefix}_)#", '', $key);
 203              $output[$key] = $value;
 204          }
 205   
 206          if ($prefix === 'group' && isset($output['id']))
 207          {
 208              $output['id'] = 'g' . $output['id'];
 209          }
 210   
 211          return $output;
 212      }
 213   
 214      /**
 215      * Clean driver names that are returned from template files
 216      * Underscores are replaced with dots
 217      *
 218      * @param string $name Driver name
 219      *
 220      * @return string Cleaned driver name
 221      */
 222      static public function clean_driver_name($name)
 223      {
 224          return str_replace(array('\\', '_'), '.', $name);
 225      }
 226   
 227      /**
 228      * Prepare driver names for use in template files
 229      * Dots are replaced with underscores
 230      *
 231      * @param string $name Clean driver name
 232      *
 233      * @return string Prepared driver name
 234      */
 235      static public function prepare_driver_name($name)
 236      {
 237          return str_replace('.', '_', $name);
 238      }
 239   
 240      /**
 241      * Check if avatar is enabled
 242      *
 243      * @param object $driver Avatar driver object
 244      *
 245      * @return bool True if avatar is enabled, false if it's disabled
 246      */
 247      public function is_enabled($driver)
 248      {
 249          $config_name = $this->get_driver_config_name($driver);
 250   
 251          return $this->config["allow_avatar_{$config_name}"];
 252      }
 253   
 254      /**
 255      * Get the settings array for enabling/disabling an avatar driver
 256      *
 257      * @param object $driver Avatar driver object
 258      *
 259      * @return array Array of configuration options as consumed by acp_board
 260      */
 261      public function get_avatar_settings($driver)
 262      {
 263          $config_name = $this->get_driver_config_name($driver);
 264   
 265          return array(
 266              'allow_avatar_' . $config_name    => array('lang' => 'ALLOW_' . strtoupper(str_replace('\\', '_', $config_name)),        'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => false),
 267          );
 268      }
 269   
 270      /**
 271      * Get the config name of an avatar driver
 272      *
 273      * @param object $driver Avatar driver object
 274      *
 275      * @return string Avatar driver config name
 276      */
 277      public function get_driver_config_name($driver)
 278      {
 279          return preg_replace('#^phpbb\\\\avatar\\\\driver\\\\#', '', get_class($driver));
 280      }
 281   
 282      /**
 283      * Replace "error" strings with their real, localized form
 284      *
 285      * @param \phpbb\user phpBB User object
 286      * @param array    $error Array containing error strings
 287      *        Key values can either be a string with a language key or an array
 288      *        that will be passed to vsprintf() with the language key in the
 289      *        first array key.
 290      *
 291      * @return array Array containing the localized error strings
 292      */
 293      public function localize_errors(\phpbb\user $user, $error)
 294      {
 295          foreach ($error as $key => $lang)
 296          {
 297              if (is_array($lang))
 298              {
 299                  $lang_key = array_shift($lang);
 300                  $error[$key] = vsprintf($user->lang($lang_key), $lang);
 301              }
 302              else
 303              {
 304                  $error[$key] = $user->lang("$lang");
 305              }
 306          }
 307   
 308          return $error;
 309      }
 310   
 311      /**
 312      * Handle deleting avatars
 313      *
 314      * @param \phpbb\db\driver\driver_interface $db phpBB dbal
 315      * @param \phpbb\user    $user phpBB user object
 316      * @param array          $avatar_data Cleaned user data containing the user's
 317      *                               avatar data
 318      * @param string         $table Database table from which the avatar should be deleted
 319      * @param string         $prefix Prefix of user data columns in database
 320      * @return null
 321      */
 322      public function handle_avatar_delete(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, $avatar_data, $table, $prefix)
 323      {
 324          if ($driver = $this->get_driver($avatar_data['avatar_type']))
 325          {
 326              $driver->delete($avatar_data);
 327          }
 328   
 329          $result = self::$default_row;
 330   
 331          foreach ($result as $key => $value)
 332          {
 333              $result[$prefix . $key] = $value;
 334              unset($result[$key]);
 335          }
 336   
 337          $sql = 'UPDATE ' . $table . '
 338                  SET ' . $db->sql_build_array('UPDATE', $result) . '
 339                  WHERE ' . $prefix . 'id = ' . (int) $avatar_data['id'];
 340          $db->sql_query($sql);
 341      }
 342  }
 343