1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-14 03:25:37 +02:00

[feature/avatars] Various cosmetic changes

Various small changes based on feedback from nn-
* Renaming $php_ext to $phpEx
* Fixing copyright years
* Explain $ignore_config
* Explain Regex
* Copypasta package error
* rename get_singleton

PHPBB3-10018
This commit is contained in:
Cullen Walsh 2011-04-18 10:44:29 -07:00 committed by Cullen Walsh
parent 7abded081d
commit f102d9a631
7 changed files with 80 additions and 68 deletions

View File

@ -2,7 +2,7 @@
/** /**
* *
* @package avatar * @package avatar
* @copyright (c) 2005, 2009 phpBB Group * @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @license http://opensource.org/licenses/gpl-license.php GNU Public License
* *
*/ */
@ -37,7 +37,13 @@ abstract class phpbb_avatar_driver
* Current $phpEx * Current $phpEx
* @type string * @type string
*/ */
protected $php_ext; protected $phpEx;
/**
* A cache driver
* @type phpbb_cache_driver_interface
*/
protected $cache;
/** /**
* This flag should be set to true if the avatar requires a nonstandard image * This flag should be set to true if the avatar requires a nonstandard image
@ -47,22 +53,27 @@ abstract class phpbb_avatar_driver
public $custom_html = false; public $custom_html = false;
/** /**
* Construct an avatar object * Construct an driver object
* *
* @param $user_row User data to base the avatar url/html on * @param $config The phpBB configuration
* @param $phpbb_root_path The path to the phpBB root
* @param $phpEx The php file extension
* @param $cache A cache driver
*/ */
public function __construct(phpbb_config $config, $phpbb_root_path, $php_ext) public function __construct(phpbb_config $config, $phpbb_root_path, $phpEx, phpbb_cache_driver_interface $cache = null)
{ {
$this->config = $config; $this->config = $config;
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext; $this->phpEx = $phpEx;
$this->cache = $cache;
} }
/** /**
* Get the avatar url and dimensions * Get the avatar url and dimensions
* *
* @param $ignore_config Whether $user or global avatar visibility settings * @param $ignore_config Whether this function should respect the users/board
* should be ignored * configuration option, or should just render the avatar anyways.
* Useful for the ACP.
* @return array Avatar data * @return array Avatar data
*/ */
public function get_data($user_row, $ignore_config = false) public function get_data($user_row, $ignore_config = false)
@ -78,8 +89,9 @@ abstract class phpbb_avatar_driver
* Returns custom html for displaying this avatar. * Returns custom html for displaying this avatar.
* Only called if $custom_html is true. * Only called if $custom_html is true.
* *
* @param $ignore_config Whether $user or global avatar visibility settings * @param $ignore_config Whether this function should respect the users/board
* should be ignored * configuration option, or should just render the avatar anyways.
* Useful for the ACP.
* @return string HTML * @return string HTML
*/ */
public function get_custom_html($user_row, $ignore_config = false) public function get_custom_html($user_row, $ignore_config = false)

View File

@ -2,7 +2,7 @@
/** /**
* *
* @package avatar * @package avatar
* @copyright (c) 2005, 2009 phpBB Group * @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @license http://opensource.org/licenses/gpl-license.php GNU Public License
* *
*/ */
@ -22,11 +22,7 @@ if (!defined('IN_PHPBB'))
class phpbb_avatar_driver_local extends phpbb_avatar_driver class phpbb_avatar_driver_local extends phpbb_avatar_driver
{ {
/** /**
* Get the avatar url and dimensions * @inheritdoc
*
* @param $ignore_config Whether $user or global avatar visibility settings
* should be ignored
* @return array Avatar data
*/ */
public function get_data($user_row, $ignore_config = false) public function get_data($user_row, $ignore_config = false)
{ {
@ -49,8 +45,8 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
} }
/** /**
* @TODO * @inheritdoc
**/ */
public function handle_form($template, &$error = array(), $submitted = false) public function handle_form($template, &$error = array(), $submitted = false)
{ {
if ($submitted) { if ($submitted) {
@ -58,6 +54,10 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
return ''; return '';
} }
$avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list');
if (!$avatar_list)
{
$avatar_list = array(); $avatar_list = array();
$path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; $path = $this->phpbb_root_path . $this->config['avatar_gallery_path'];
@ -75,6 +75,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
{ {
while (($image = readdir($ch)) !== false) while (($image = readdir($ch)) !== false)
{ {
// Match all images in the gallery folder
if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image))
{ {
$avatar_list[$cat][] = array( $avatar_list[$cat][] = array(
@ -92,6 +93,12 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
@ksort($avatar_list); @ksort($avatar_list);
if ($this->cache != null)
{
$this->cache->put('av_local_list', $avatar_list);
}
}
$category = request_var('av_local_cat', ''); $category = request_var('av_local_cat', '');
$categories = array_keys($avatar_list); $categories = array_keys($avatar_list);

View File

@ -2,7 +2,7 @@
/** /**
* *
* @package avatar * @package avatar
* @copyright (c) 2005, 2009 phpBB Group * @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @license http://opensource.org/licenses/gpl-license.php GNU Public License
* *
*/ */
@ -22,11 +22,7 @@ if (!defined('IN_PHPBB'))
class phpbb_avatar_driver_remote extends phpbb_avatar_driver class phpbb_avatar_driver_remote extends phpbb_avatar_driver
{ {
/** /**
* Get the avatar url and dimensions * @inheritdoc
*
* @param $ignore_config Whether $user or global avatar visibility settings
* should be ignored
* @return array Avatar data
*/ */
public function get_data($user_row, $ignore_config = false) public function get_data($user_row, $ignore_config = false)
{ {
@ -49,8 +45,8 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver
} }
/** /**
* @TODO * @inheritdoc
**/ */
public function handle_form($template, &$error = array(), $submitted = false) public function handle_form($template, &$error = array(), $submitted = false)
{ {
if ($submitted) { if ($submitted) {

View File

@ -2,7 +2,7 @@
/** /**
* *
* @package avatar * @package avatar
* @copyright (c) 2005, 2009 phpBB Group * @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @license http://opensource.org/licenses/gpl-license.php GNU Public License
* *
*/ */
@ -22,18 +22,14 @@ if (!defined('IN_PHPBB'))
class phpbb_avatar_driver_upload extends phpbb_avatar_driver class phpbb_avatar_driver_upload extends phpbb_avatar_driver
{ {
/** /**
* Get the avatar url and dimensions * @inheritdoc
*
* @param $ignore_config Whether $user or global avatar visibility settings
* should be ignored
* @return array Avatar data
*/ */
public function get_data($user_row, $ignore_config = false) public function get_data($user_row, $ignore_config = false)
{ {
if ($ignore_config || $this->config['allow_avatar_upload']) if ($ignore_config || $this->config['allow_avatar_upload'])
{ {
return array( return array(
'src' => $this->phpbb_root_path . 'download/file.' . $this->php_ext . '?avatar=' . $user_row['user_avatar'], 'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $user_row['user_avatar'],
'width' => $user_row['user_avatar_width'], 'width' => $user_row['user_avatar_width'],
'height' => $user_row['user_avatar_height'], 'height' => $user_row['user_avatar_height'],
); );
@ -49,8 +45,8 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver
} }
/** /**
* @TODO * @inheritdoc
**/ */
public function handle_form($template, &$error = array(), $submitted = false) public function handle_form($template, &$error = array(), $submitted = false)
{ {
if ($submitted) { if ($submitted) {

View File

@ -2,7 +2,7 @@
/** /**
* *
* @package avatar * @package avatar
* @copyright (c) 2010 phpBB Group * @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @license http://opensource.org/licenses/gpl-license.php GNU Public License
* *
*/ */
@ -16,12 +16,12 @@ if (!defined('IN_PHPBB'))
} }
/** /**
* @package acm * @package avatar
*/ */
class phpbb_avatar_manager class phpbb_avatar_manager
{ {
private $phpbb_root_path; private $phpbb_root_path;
private $php_ext; private $phpEx;
private $config; private $config;
private $cache; private $cache;
private static $valid_drivers = false; private static $valid_drivers = false;
@ -29,10 +29,10 @@ class phpbb_avatar_manager
/** /**
* @TODO * @TODO
**/ **/
public function __construct($phpbb_root_path, $php_ext = '.php', phpbb_config $config, phpbb_cache_driver_interface $cache = null) public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_cache_driver_interface $cache = null)
{ {
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext; $this->phpEx = $phpEx;
$this->config = $config; $this->config = $config;
$this->cache = $cache; $this->cache = $cache;
} }
@ -40,7 +40,7 @@ class phpbb_avatar_manager
/** /**
* @TODO * @TODO
**/ **/
public function get_singleton($avatar_type) public function get_driver($avatar_type, $new = false)
{ {
if (self::$valid_drivers === false) if (self::$valid_drivers === false)
{ {
@ -49,10 +49,10 @@ class phpbb_avatar_manager
if (isset(self::$valid_drivers[$avatar_type])) if (isset(self::$valid_drivers[$avatar_type]))
{ {
if (!is_object(self::$valid_drivers[$avatar_type])) if ($new || !is_object(self::$valid_drivers[$avatar_type]))
{ {
$class_name = 'phpbb_avatar_driver_' . $avatar_type; $class_name = 'phpbb_avatar_driver_' . $avatar_type;
self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->phpbb_root_path, $this->php_ext); self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->phpbb_root_path, $this->phpEx, $this->cache);
} }
return self::$valid_drivers[$avatar_type]; return self::$valid_drivers[$avatar_type];
@ -68,7 +68,7 @@ class phpbb_avatar_manager
**/ **/
private function load_valid_drivers() private function load_valid_drivers()
{ {
require_once($this->phpbb_root_path . 'includes/avatar/driver.' . $this->php_ext); require_once($this->phpbb_root_path . 'includes/avatar/driver.' . $this->phpEx);
if ($this->cache) if ($this->cache)
{ {
@ -83,7 +83,8 @@ class phpbb_avatar_manager
foreach ($iterator as $file) foreach ($iterator as $file)
{ {
if (preg_match("/^(.*)\.{$this->php_ext}$/", $file, $match)) // Match all files that appear to be php files
if (preg_match("/^(.*)\.{$this->phpEx}$/", $file, $match))
{ {
self::$valid_drivers[] = $match[1]; self::$valid_drivers[] = $match[1];
} }

View File

@ -1341,7 +1341,7 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false
$avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->get_driver()); $avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->get_driver());
} }
$avatar = $avatar_manager->get_singleton($user_row['user_avatar_type']); $avatar = $avatar_manager->get_driver($user_row['user_avatar_type']);
if ($avatar) if ($avatar)
{ {

View File

@ -567,7 +567,7 @@ class ucp_profile
'avatar' => "ucp_avatar_options_$driver.html", 'avatar' => "ucp_avatar_options_$driver.html",
)); ));
$avatar = $avatar_manager->get_singleton($driver); $avatar = $avatar_manager->get_driver($driver);
if (isset($_POST["submit_av_$driver"])) if (isset($_POST["submit_av_$driver"]))
{ {
if (check_form_key('ucp_avatar')) if (check_form_key('ucp_avatar'))