diff options
| author | Marc Alexander <admin@m-a-styles.de> | 2012-11-12 14:57:28 +0100 |
|---|---|---|
| committer | Marc Alexander <admin@m-a-styles.de> | 2012-11-12 14:57:28 +0100 |
| commit | 2265811cd16f6473807f647cba4693c5366324c6 (patch) | |
| tree | ff27efb016da2f8adff55e2d343c1163d26219d8 /phpBB/includes/avatar/manager.php | |
| parent | 5a5e507a14084b08e41c4d2f86f2fb6700e68eb5 (diff) | |
| parent | 0e2a30a27b92a851221be489370217b9c7bf8e07 (diff) | |
| download | forums-2265811cd16f6473807f647cba4693c5366324c6.tar forums-2265811cd16f6473807f647cba4693c5366324c6.tar.gz forums-2265811cd16f6473807f647cba4693c5366324c6.tar.bz2 forums-2265811cd16f6473807f647cba4693c5366324c6.tar.xz forums-2265811cd16f6473807f647cba4693c5366324c6.zip | |
Merge branch 'feature/avatars' of https://github.com/igorw/phpbb3 into feature/avatars
Conflicts:
phpBB/adm/style/acp_groups.html
phpBB/adm/style/acp_users_avatar.html
phpBB/includes/acp/acp_groups.php
phpBB/includes/acp/acp_users.php
phpBB/includes/functions_display.php
phpBB/install/database_update.php
phpBB/install/schemas/mssql_schema.sql
phpBB/styles/prosilver/template/ucp_avatar_options.html
Diffstat (limited to 'phpBB/includes/avatar/manager.php')
| -rw-r--r-- | phpBB/includes/avatar/manager.php | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php new file mode 100644 index 0000000000..c2c3dbbbca --- /dev/null +++ b/phpBB/includes/avatar/manager.php @@ -0,0 +1,146 @@ +<?php +/** +* +* @package avatar +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* @package avatar +*/ +class phpbb_avatar_manager +{ + private $phpbb_root_path; + private $phpEx; + private $config; + private $request; + private $extension_manager; + private $cache; + private static $valid_drivers = false; + + /** + * @TODO + **/ + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_extension_manager $extension_manager, phpbb_cache_driver_interface $cache = null) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + $this->request = $request; + $this->extension_manager = $extension_manager; + $this->cache = $cache; + } + + /** + * @TODO + **/ + public function get_driver($avatar_type) + { + if (self::$valid_drivers === false) + { + $this->load_valid_drivers(); + } + + // Legacy stuff... + switch ($avatar_type) + { + case AVATAR_GALLERY: + $avatar_type = 'phpbb_avatar_driver_local'; + break; + case AVATAR_UPLOAD: + $avatar_type = 'phpbb_avatar_driver_upload'; + break; + case AVATAR_REMOTE: + $avatar_type = 'phpbb_avatar_driver_remote'; + break; + } + + if (false === array_search($avatar_type, self::$valid_drivers)) + { + return null; + } + + $r = new ReflectionClass($avatar_type); + + if ($r->isSubClassOf('phpbb_avatar_driver')) { + $driver = new $avatar_type($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache); + } else if ($r->implementsInterface('phpbb_avatar_driver')) { + $driver = new $avatar_type(); + } else { + $message = "Invalid avatar driver class name '%s' provided. It must implement phpbb_avatar_driver_interface."; + trigger_error(sprintf($message, $avatar_type)); + } + + return $driver; + } + + /** + * @TODO + **/ + private function load_valid_drivers() + { + if ($this->cache) + { + self::$valid_drivers = $this->cache->get('avatar_drivers'); + } + + if (empty($this->valid_drivers)) + { + self::$valid_drivers = array(); + + $finder = $this->extension_manager->get_finder(); + + self::$valid_drivers = $finder + ->extension_directory('/avatar/driver/') + ->core_path('includes/avatar/driver/core/') + ->get_classes(); + + if ($this->cache) + { + $this->cache->put('avatar_drivers', self::$valid_drivers); + } + } + } + + /** + * @TODO + **/ + public function get_valid_drivers() + { + if (self::$valid_drivers === false) + { + $this->load_valid_drivers(); + } + + return self::$valid_drivers; + } + + /** + * Strip out user_ and group_ prefixes from keys + **/ + public static function clean_row($row) + { + $keys = array_keys($row); + $values = array_values($row); + + $keys = array_map( + function ($key) + { + return preg_replace('#^(?:user_|group_)#', '', $key); + }, + $keys + ); + + return array_combine($keys, $values); + } +} |
