2011-04-17 19:29:41 -07:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package avatar
|
2011-04-18 10:44:29 -07:00
|
|
|
* @copyright (c) 2011 phpBB Group
|
2011-04-17 19:29:41 -07:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
if (!defined('IN_PHPBB'))
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-18 10:44:29 -07:00
|
|
|
* @package avatar
|
2011-04-17 19:29:41 -07:00
|
|
|
*/
|
|
|
|
class phpbb_avatar_manager
|
|
|
|
{
|
|
|
|
private $phpbb_root_path;
|
2011-04-18 10:44:29 -07:00
|
|
|
private $phpEx;
|
2011-04-17 19:29:41 -07:00
|
|
|
private $config;
|
2012-04-07 19:19:13 +02:00
|
|
|
private $request;
|
2011-04-17 19:29:41 -07:00
|
|
|
private $cache;
|
|
|
|
private static $valid_drivers = false;
|
|
|
|
|
2011-04-17 21:58:51 -07:00
|
|
|
/**
|
|
|
|
* @TODO
|
|
|
|
**/
|
2012-04-07 19:19:13 +02:00
|
|
|
public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache = null)
|
2011-04-17 19:29:41 -07:00
|
|
|
{
|
|
|
|
$this->phpbb_root_path = $phpbb_root_path;
|
2011-04-18 10:44:29 -07:00
|
|
|
$this->phpEx = $phpEx;
|
2011-04-17 19:29:41 -07:00
|
|
|
$this->config = $config;
|
2012-04-07 19:19:13 +02:00
|
|
|
$this->request = $request;
|
2011-04-17 19:29:41 -07:00
|
|
|
$this->cache = $cache;
|
|
|
|
}
|
|
|
|
|
2011-04-17 21:58:51 -07:00
|
|
|
/**
|
|
|
|
* @TODO
|
|
|
|
**/
|
2011-04-18 10:44:29 -07:00
|
|
|
public function get_driver($avatar_type, $new = false)
|
2011-04-17 19:29:41 -07:00
|
|
|
{
|
|
|
|
if (self::$valid_drivers === false)
|
|
|
|
{
|
|
|
|
$this->load_valid_drivers();
|
|
|
|
}
|
|
|
|
|
2011-04-20 23:14:38 -07:00
|
|
|
// Legacy stuff...
|
|
|
|
switch ($avatar_type)
|
|
|
|
{
|
2011-06-15 12:38:17 -07:00
|
|
|
case AVATAR_GALLERY:
|
2011-04-20 23:14:38 -07:00
|
|
|
$avatar_type = 'local';
|
|
|
|
break;
|
|
|
|
case AVATAR_UPLOAD:
|
|
|
|
$avatar_type = 'upload';
|
|
|
|
break;
|
|
|
|
case AVATAR_REMOTE:
|
|
|
|
$avatar_type = 'remote';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-17 19:29:41 -07:00
|
|
|
if (isset(self::$valid_drivers[$avatar_type]))
|
|
|
|
{
|
2011-04-18 10:44:29 -07:00
|
|
|
if ($new || !is_object(self::$valid_drivers[$avatar_type]))
|
2011-04-17 19:29:41 -07:00
|
|
|
{
|
|
|
|
$class_name = 'phpbb_avatar_driver_' . $avatar_type;
|
2012-04-07 19:19:13 +02:00
|
|
|
self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache);
|
2011-04-17 19:29:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return self::$valid_drivers[$avatar_type];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-17 21:58:51 -07:00
|
|
|
/**
|
|
|
|
* @TODO
|
|
|
|
**/
|
2011-04-17 19:29:41 -07:00
|
|
|
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();
|
|
|
|
|
|
|
|
$iterator = new DirectoryIterator($this->phpbb_root_path . 'includes/avatar/driver');
|
|
|
|
|
|
|
|
foreach ($iterator as $file)
|
|
|
|
{
|
2011-04-18 10:44:29 -07:00
|
|
|
// Match all files that appear to be php files
|
|
|
|
if (preg_match("/^(.*)\.{$this->phpEx}$/", $file, $match))
|
2011-04-17 19:29:41 -07:00
|
|
|
{
|
|
|
|
self::$valid_drivers[] = $match[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self::$valid_drivers = array_flip(self::$valid_drivers);
|
|
|
|
|
|
|
|
if ($this->cache)
|
|
|
|
{
|
|
|
|
$this->cache->put('avatar_drivers', self::$valid_drivers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-17 21:58:51 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @TODO
|
|
|
|
**/
|
|
|
|
public function get_valid_drivers() {
|
|
|
|
if (self::$valid_drivers === false)
|
|
|
|
{
|
|
|
|
$this->load_valid_drivers();
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_keys(self::$valid_drivers);
|
|
|
|
}
|
2011-04-17 19:29:41 -07:00
|
|
|
}
|