aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2012-11-12 14:57:28 +0100
committerMarc Alexander <admin@m-a-styles.de>2012-11-12 14:57:28 +0100
commit2265811cd16f6473807f647cba4693c5366324c6 (patch)
treeff27efb016da2f8adff55e2d343c1163d26219d8 /phpBB/includes
parent5a5e507a14084b08e41c4d2f86f2fb6700e68eb5 (diff)
parent0e2a30a27b92a851221be489370217b9c7bf8e07 (diff)
downloadforums-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')
-rw-r--r--phpBB/includes/acp/acp_groups.php180
-rw-r--r--phpBB/includes/acp/acp_users.php155
-rw-r--r--phpBB/includes/avatar/driver/core/local.php189
-rw-r--r--phpBB/includes/avatar/driver/core/remote.php163
-rw-r--r--phpBB/includes/avatar/driver/core/upload.php147
-rw-r--r--phpBB/includes/avatar/driver/driver.php143
-rw-r--r--phpBB/includes/avatar/driver/interface.php70
-rw-r--r--phpBB/includes/avatar/manager.php146
-rw-r--r--phpBB/includes/functions_display.php117
-rw-r--r--phpBB/includes/functions_user.php1
-rw-r--r--phpBB/includes/mcp/mcp_notes.php2
-rw-r--r--phpBB/includes/mcp/mcp_warn.php4
-rw-r--r--phpBB/includes/ucp/ucp_groups.php2
-rw-r--r--phpBB/includes/ucp/ucp_pm_viewmessage.php2
-rw-r--r--phpBB/includes/ucp/ucp_profile.php166
15 files changed, 1239 insertions, 248 deletions
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php
index b604e20094..1109c64d00 100644
--- a/phpBB/includes/acp/acp_groups.php
+++ b/phpBB/includes/acp/acp_groups.php
@@ -26,7 +26,7 @@ class acp_groups
{
global $config, $db, $user, $auth, $template, $cache;
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
- global $request;
+ global $request, $phpbb_avatar_manager;
$user->add_lang('acp/groups');
$this->tpl_name = 'acp_groups';
@@ -55,7 +55,6 @@ class acp_groups
// Clear some vars
- $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
$group_row = array();
// Grab basic data for group, if group_id is set and exists
@@ -282,8 +281,21 @@ class acp_groups
$error = array();
$user->add_lang('ucp');
- $avatar_select = basename(request_var('avatar_select', ''));
- $category = basename(request_var('category', ''));
+ // Setup avatar data for later
+ $avatars_enabled = false;
+ $avatar_drivers = null;
+ $avatar_data = null;
+ $avatar_error = array();
+
+ if ($config['allow_avatar'])
+ {
+ $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers();
+ sort($avatar_drivers);
+
+ // This is normalised data, without the group_ prefix
+ $avatar_data = phpbb_avatar_manager::clean_row($group_row);
+ }
+
// Did we submit?
if ($update)
@@ -301,12 +313,6 @@ class acp_groups
$allow_desc_urls = request_var('desc_parse_urls', false);
$allow_desc_smilies = request_var('desc_parse_smilies', false);
- $data['uploadurl'] = request_var('uploadurl', '');
- $data['remotelink'] = request_var('remotelink', '');
- $data['width'] = request_var('width', '');
- $data['height'] = request_var('height', '');
- $delete = request_var('delete', '');
-
$submit_ary = array(
'colour' => request_var('group_colour', ''),
'rank' => request_var('group_rank', 0),
@@ -323,82 +329,38 @@ class acp_groups
{
$submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0;
}
-
- $uploadfile = $request->file('uploadfile');
- if (!empty($uploadfile['tmp_name']) || $data['uploadurl'] || $data['remotelink'])
- {
- // Avatar stuff
- $var_ary = array(
- 'uploadurl' => array('string', true, 5, 255),
- 'remotelink' => array('string', true, 5, 255),
- 'width' => array('string', true, 1, 3),
- 'height' => array('string', true, 1, 3),
- );
-
- if (!($error = validate_data($data, $var_ary)))
- {
- $data['user_id'] = "g$group_id";
-
- if ((!empty($uploadfile['tmp_name']) || $data['uploadurl']) && $can_upload)
- {
- list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error);
- }
- else if ($data['remotelink'])
- {
- list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error);
- }
- }
- }
- else if ($avatar_select && $config['allow_avatar_local'])
- {
- // check avatar gallery
- if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category))
- {
- $submit_ary['avatar_type'] = AVATAR_GALLERY;
-
- list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select);
- $submit_ary['avatar'] = $category . '/' . $avatar_select;
- }
- }
- else if ($delete)
- {
- $submit_ary['avatar'] = '';
- $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0;
- }
- else if ($data['width'] && $data['height'])
- {
- // Only update the dimensions?
- if ($config['avatar_max_width'] || $config['avatar_max_height'])
+
+ if ($config['allow_avatar']) {
+ // Handle avatar
+ $driver = request_var('avatar_driver', '');
+ if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"])
{
- if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height'])
- {
- $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']);
- }
- }
+ $avatar = $phpbb_avatar_manager->get_driver($driver);
+ $result = $avatar->process_form($template, $avatar_data, $avatar_error);
- if (!sizeof($error))
- {
- if ($config['avatar_min_width'] || $config['avatar_min_height'])
+ if ($result && empty($avatar_error))
{
- if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height'])
- {
- $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']);
- }
+ // Success! Lets save the result
+
+ /*
+ $result = array(
+ 'avatar' => ...,
+ 'avatar_width' => ...,
+ 'avatar_height' => ...,
+ );
+ */
+
+ $submit_ary = array_merge($submit_ary, $result);
+ $submit_ary['avatar_type'] = $driver;
}
}
-
- if (!sizeof($error))
+ else
{
- $submit_ary['avatar_width'] = $data['width'];
- $submit_ary['avatar_height'] = $data['height'];
- }
- }
-
- if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']))) || $delete)
- {
- if (isset($group_row['group_avatar']) && $group_row['group_avatar'])
- {
- avatar_delete('group', $group_row, true);
+ // Removing the avatar
+ $submit_ary['avatar_type'] = '';
+ $submit_ary['avatar'] = '';
+ $submit_ary['avatar_width'] = 0;
+ $submit_ary['avatar_height'] = 0;
}
}
@@ -425,7 +387,7 @@ class acp_groups
'rank' => 'int',
'colour' => 'string',
'avatar' => 'string',
- 'avatar_type' => 'int',
+ 'avatar_type' => 'string',
'avatar_width' => 'int',
'avatar_height' => 'int',
'receive_pm' => 'int',
@@ -555,13 +517,54 @@ class acp_groups
$type_closed = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : '';
$type_hidden = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : '';
- $avatar_img = (!empty($group_row['group_avatar'])) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
+ // Load up stuff for avatars
+ if ($config['allow_avatar'])
+ {
+ $avatars_enabled = false;
+ $focused_driver = request_var('avatar_driver', $avatar_data['avatar_type']);
+
+ foreach ($avatar_drivers as $driver)
+ {
+ if ($config["allow_avatar_$driver"])
+ {
+ $avatars_enabled = true;
+ $template->set_filenames(array(
+ 'avatar' => "acp_avatar_options_$driver.html",
+ ));
- $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
+ $avatar = $phpbb_avatar_manager->get_driver($driver);
- if ($config['allow_avatar_local'] && $display_gallery)
+ if ($avatar->prepare_form($template, $avatar_data, $avatar_error))
+ {
+ $driver_u = strtoupper($driver);
+ $template->assign_block_vars('avatar_drivers', array(
+ 'L_TITLE' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_TITLE'), // @TODO add lang values
+ 'L_EXPLAIN' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_EXPLAIN'),
+
+ 'DRIVER' => $driver,
+ 'SELECTED' => ($driver == $focused_driver),
+ 'OUTPUT' => $template->assign_display('avatar'),
+ ));
+ }
+ }
+ }
+ }
+
+ $avatar = get_group_avatar($group_row, 'GROUP_AVATAR', true);
+
+ // Merge any avatars errors into the primary error array
+ // Drivers use lang constants, so we need to map to the actual strings
+ foreach ($avatar_error as $e)
{
- avatar_gallery($category, $avatar_select, 4);
+ if (is_array($e))
+ {
+ $key = array_shift($e);
+ $error[] = vsprintf($user->lang($key), $e);
+ }
+ else
+ {
+ $error[] = $user->lang((string) $e);
+ }
}
$back_link = request_var('back_link', '');
@@ -582,12 +585,10 @@ class acp_groups
'S_ADD_GROUP' => ($action == 'add') ? true : false,
'S_GROUP_PERM' => ($action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) ? true : false,
'S_INCLUDE_SWATCH' => true,
- 'S_CAN_UPLOAD' => $can_upload,
'S_ERROR' => (sizeof($error)) ? true : false,
'S_SPECIAL_GROUP' => ($group_type == GROUP_SPECIAL) ? true : false,
- 'S_DISPLAY_GALLERY' => ($config['allow_avatar_local'] && !$display_gallery) ? true : false,
- 'S_IN_GALLERY' => ($config['allow_avatar_local'] && $display_gallery) ? true : false,
'S_USER_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
+ 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled),
'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '',
'GROUP_NAME' => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name,
@@ -608,8 +609,7 @@ class acp_groups
'S_RANK_OPTIONS' => $rank_options,
'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)),
- 'AVATAR' => $avatar_img,
- 'AVATAR_IMAGE' => $avatar_img,
+ 'AVATAR' => (empty($avatar) ? '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />' : $avatar),
'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'],
'AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '',
'AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '',
diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php
index 82d8ef5cbb..83c19b3ba6 100644
--- a/phpBB/includes/acp/acp_users.php
+++ b/phpBB/includes/acp/acp_users.php
@@ -33,6 +33,7 @@ class acp_users
global $config, $db, $user, $auth, $template, $cache;
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
global $phpbb_dispatcher, $request;
+ global $phpbb_avatar_manager;
$user->add_lang(array('posting', 'ucp', 'acp/users'));
$this->tpl_name = 'acp_users';
@@ -453,10 +454,10 @@ class acp_users
{
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
}
-
+
$sql_ary = array(
'user_avatar' => '',
- 'user_avatar_type' => 0,
+ 'user_avatar_type' => '',
'user_avatar_width' => 0,
'user_avatar_height' => 0,
);
@@ -467,9 +468,10 @@ class acp_users
$db->sql_query($sql);
// Delete old avatar if present
- if ($user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY)
+ $driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type']);
+ if ($driver)
{
- avatar_delete('user', $user_row);
+ $driver->delete($user_row);
}
add_log('admin', 'LOG_USER_DEL_AVATAR', $user_row['username']);
@@ -1728,65 +1730,124 @@ class acp_users
case 'avatar':
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
- include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
-
- $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
- if ($submit)
+ $avatars_enabled = false;
+ if ($config['allow_avatar'])
{
+ $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers();
+ sort($avatar_drivers);
- if (!check_form_key($form_name))
+ // This is normalised data, without the user_ prefix
+ $avatar_data = phpbb_avatar_manager::clean_row($user_row);
+
+ if ($submit)
{
+ if (check_form_key($form_name))
+ {
+ $driver = request_var('avatar_driver', '');
+ if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"])
+ {
+ $avatar = $phpbb_avatar_manager->get_driver($driver);
+ $result = $avatar->process_form($template, $avatar_data, $error);
+
+ if ($result && empty($error))
+ {
+ // Success! Lets save the result in the database
+ $result = array(
+ 'user_avatar_type' => $driver,
+ 'user_avatar' => $result['avatar'],
+ 'user_avatar_width' => $result['avatar_width'],
+ 'user_avatar_height' => $result['avatar_height'],
+ );
+ $sql = 'UPDATE ' . USERS_TABLE . '
+ SET ' . $db->sql_build_array('UPDATE', $result) . '
+ WHERE user_id = ' . $user_id;
+
+ $db->sql_query($sql);
+ trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
+ }
+ }
+ else
+ {
+ // Removing the avatar
+ $result = array(
+ 'user_avatar' => '',
+ 'user_avatar_type' => '',
+ 'user_avatar_width' => 0,
+ 'user_avatar_height' => 0,
+ );
+
+ $sql = 'UPDATE ' . USERS_TABLE . '
+ SET ' . $db->sql_build_array('UPDATE', $result) . '
+ WHERE user_id = ' . $user_id;
+
+ $db->sql_query($sql);
+ trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
+ }
+ }
+ else
+ {
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
+ }
}
- if (avatar_process_user($error, $user_row, $can_upload))
+ $focused_driver = request_var('avatar_driver', $user_row['user_avatar_type']);
+
+ foreach ($avatar_drivers as $driver)
{
- trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_row['user_id']));
- }
+ if ($config["allow_avatar_$driver"])
+ {
+ $avatars_enabled = true;
+ $template->set_filenames(array(
+ 'avatar' => "acp_avatar_options_$driver.html",
+ ));
- // Replace "error" strings with their real, localised form
- $error = array_map(array($user, 'lang'), $error);
- }
+ $avatar = $phpbb_avatar_manager->get_driver($driver);
- if (!$config['allow_avatar'] && $user_row['user_avatar_type'])
- {
- $error[] = $user->lang['USER_AVATAR_NOT_ALLOWED'];
- }
- else if ((($user_row['user_avatar_type'] == AVATAR_UPLOAD) && !$config['allow_avatar_upload']) ||
- (($user_row['user_avatar_type'] == AVATAR_REMOTE) && !$config['allow_avatar_remote']) ||
- (($user_row['user_avatar_type'] == AVATAR_GALLERY) && !$config['allow_avatar_local']))
- {
- $error[] = $user->lang['USER_AVATAR_TYPE_NOT_ALLOWED'];
+ if ($avatar->prepare_form($template, $avatar_data, $error))
+ {
+ $driver_u = strtoupper($driver);
+ $template->assign_block_vars('avatar_drivers', array(
+ 'L_TITLE' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_TITLE'), // @TODO add lang values
+ 'L_EXPLAIN' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_EXPLAIN'),
+
+ 'DRIVER' => $driver,
+ 'SELECTED' => ($driver == $focused_driver),
+ 'OUTPUT' => $template->assign_display('avatar'),
+ ));
+ }
+ }
+ }
}
- // Generate users avatar
- $avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height'], 'USER_AVATAR', true) : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
-
- $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
- $avatar_select = basename(request_var('avatar_select', ''));
- $category = basename(request_var('category', ''));
-
- if ($config['allow_avatar_local'] && $display_gallery)
+ // Replace "error" strings with their real, localised form
+ $err = $error;
+ $error = array();
+ foreach ($err as $e)
{
- avatar_gallery($category, $avatar_select, 4);
+ if (is_array($e))
+ {
+ $key = array_shift($e);
+ $error[] = vsprintf($user->lang($key), $e);
+ }
+ else
+ {
+ $error[] = $user->lang((string) $e);
+ }
}
+
+ $avatar = get_user_avatar($user_row, 'USER_AVATAR', true);
$template->assign_vars(array(
- 'S_AVATAR' => true,
- 'S_CAN_UPLOAD' => $can_upload,
- 'S_UPLOAD_FILE' => ($config['allow_avatar'] && $can_upload && $config['allow_avatar_upload']) ? true : false,
- 'S_REMOTE_UPLOAD' => ($config['allow_avatar'] && $can_upload && $config['allow_avatar_remote_upload']) ? true : false,
- 'S_ALLOW_REMOTE' => ($config['allow_avatar'] && $config['allow_avatar_remote']) ? true : false,
- 'S_DISPLAY_GALLERY' => ($config['allow_avatar'] && $config['allow_avatar_local'] && !$display_gallery) ? true : false,
- 'S_IN_GALLERY' => ($config['allow_avatar'] && $config['allow_avatar_local'] && $display_gallery) ? true : false,
-
- 'AVATAR_IMAGE' => $avatar_img,
- 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'],
- 'USER_AVATAR_WIDTH' => $user_row['user_avatar_width'],
- 'USER_AVATAR_HEIGHT' => $user_row['user_avatar_height'],
-
- 'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string(),
+ 'S_AVATAR' => true,
+ 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
+ 'AVATAR' => (empty($avatar) ? '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />' : $avatar),
+
+ 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"',
+
+ 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024),
+
+ 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled),
));
break;
diff --git a/phpBB/includes/avatar/driver/core/local.php b/phpBB/includes/avatar/driver/core/local.php
new file mode 100644
index 0000000000..ca82b9c175
--- /dev/null
+++ b/phpBB/includes/avatar/driver/core/local.php
@@ -0,0 +1,189 @@
+<?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;
+}
+
+/**
+* Handles avatars selected from the board gallery
+* @package avatars
+*/
+class phpbb_avatar_driver_core_local extends phpbb_avatar_driver
+{
+ /**
+ * @inheritdoc
+ */
+ public function get_data($row, $ignore_config = false)
+ {
+ if ($ignore_config || $this->config['allow_avatar_local'])
+ {
+ return array(
+ 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'],
+ 'width' => $row['avatar_width'],
+ 'height' => $row['avatar_height'],
+ );
+ }
+ else
+ {
+ return array(
+ 'src' => '',
+ 'width' => 0,
+ 'height' => 0,
+ );
+ }
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function prepare_form($template, $row, &$error)
+ {
+ $avatar_list = $this->get_avatar_list();
+ $category = $this->request->variable('av_local_cat', '');
+
+ $categories = array_keys($avatar_list);
+
+ foreach ($categories as $cat)
+ {
+ if (!empty($avatar_list[$cat]))
+ {
+ $template->assign_block_vars('av_local_cats', array(
+ 'NAME' => $cat,
+ 'SELECTED' => ($cat == $category),
+ ));
+ }
+ }
+
+ if (!empty($avatar_list[$category]))
+ {
+ $template->assign_vars(array(
+ 'AV_LOCAL_SHOW' => true,
+ ));
+
+ $table_cols = isset($row['av_gallery_cols']) ? $row['av_gallery_cols'] : 4;
+ $row_count = $col_count = $av_pos = 0;
+ $av_count = sizeof($avatar_list[$category]);
+
+ reset($avatar_list[$category]);
+
+ while ($av_pos < $av_count)
+ {
+ $img = current($avatar_list[$category]);
+ next($avatar_list[$category]);
+
+ if ($col_count == 0)
+ {
+ ++$row_count;
+ $template->assign_block_vars('av_local_row', array(
+ ));
+ }
+
+ $template->assign_block_vars('av_local_row.av_local_col', array(
+ 'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $img['file'],
+ 'AVATAR_NAME' => $img['name'],
+ 'AVATAR_FILE' => $img['filename'],
+ ));
+
+ $col_count = ($col_count + 1) % $table_cols;
+
+ ++$av_pos;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function process_form($template, $row, &$error)
+ {
+ $avatar_list = $this->get_avatar_list();
+ $category = $this->request->variable('av_local_cat', '');
+
+ $file = $this->request->variable('av_local_file', '');
+ if (!isset($avatar_list[$category][urldecode($file)]))
+ {
+ $error[] = 'AVATAR_URL_NOT_FOUND';
+ return false;
+ }
+
+ return array(
+ 'avatar' => $category . '/' . $file,
+ 'avatar_width' => $avatar_list[$category][urldecode($file)]['width'],
+ 'avatar_height' => $avatar_list[$category][urldecode($file)]['height'],
+ );
+ }
+
+ /**
+ * @TODO
+ */
+ private function get_avatar_list()
+ {
+ $avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list');
+
+ if (!$avatar_list)
+ {
+ $avatar_list = array();
+ $path = $this->phpbb_root_path . $this->config['avatar_gallery_path'];
+
+ $dh = @opendir($path);
+
+ if ($dh)
+ {
+ while (($cat = readdir($dh)) !== false) {
+ if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat"))
+ {
+ if ($ch = @opendir("$path/$cat"))
+ {
+ while (($image = readdir($ch)) !== false)
+ {
+ // Match all images in the gallery folder
+ if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image))
+ {
+ if (function_exists('getimagesize'))
+ {
+ $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image);
+ }
+ else
+ {
+ $dims = array(0, 0);
+ }
+ $avatar_list[$cat][$image] = array(
+ 'file' => rawurlencode($cat) . '/' . rawurlencode($image),
+ 'filename' => rawurlencode($image),
+ 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))),
+ 'width' => $dims[0],
+ 'height' => $dims[1],
+ );
+ }
+ }
+ @closedir($ch);
+ }
+ }
+ }
+ @closedir($dh);
+ }
+
+ @ksort($avatar_list);
+
+ if ($this->cache != null)
+ {
+ $this->cache->put('av_local_list', $avatar_list);
+ }
+ }
+
+ return $avatar_list;
+ }
+}
diff --git a/phpBB/includes/avatar/driver/core/remote.php b/phpBB/includes/avatar/driver/core/remote.php
new file mode 100644
index 0000000000..9f5a58e75a
--- /dev/null
+++ b/phpBB/includes/avatar/driver/core/remote.php
@@ -0,0 +1,163 @@
+<?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;
+}
+
+/**
+* Handles avatars hosted remotely
+* @package avatars
+*/
+class phpbb_avatar_driver_core_remote extends phpbb_avatar_driver
+{
+ /**
+ * @inheritdoc
+ */
+ public function get_data($row, $ignore_config = false)
+ {
+ if ($ignore_config || $this->config['allow_avatar_remote'])
+ {
+ return array(
+ 'src' => $row['avatar'],
+ 'width' => $row['avatar_width'],
+ 'height' => $row['avatar_height'],
+ );
+ }
+ else
+ {
+ return array(
+ 'src' => '',
+ 'width' => 0,
+ 'height' => 0,
+ );
+ }
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function prepare_form($template, $row, &$error)
+ {
+ $template->assign_vars(array(
+ 'AV_REMOTE_WIDTH' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_local_width', 0),
+ 'AV_REMOTE_HEIGHT' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_local_width', 0),
+ 'AV_REMOTE_URL' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar']) ? $row['avatar'] : '',
+ ));
+
+ return true;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function process_form($template, $row, &$error)
+ {
+ $url = $this->request->variable('av_remote_url', '');
+ $width = $this->request->variable('av_remote_width', 0);
+ $height = $this->request->variable('av_remote_height', 0);
+
+ if (!preg_match('#^(http|https|ftp)://#i', $url))
+ {
+ $url = 'http://' . $url;
+ }
+
+ require_once($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx);
+
+ $error = array_merge($error, validate_data(array(
+ 'url' => $url,
+ ), array(
+ 'url' => array('string', true, 5, 255),
+ )));
+
+ if (!empty($error))
+ {
+ return false;
+ }
+
+ // Check if this url looks alright
+ // This isn't perfect, but it's what phpBB 3.0 did, and might as well make sure everything is compatible
+ if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $url))
+ {
+ $error[] = 'AVATAR_URL_INVALID';
+ return false;
+ }
+
+ // Make sure getimagesize works...
+ if (function_exists('getimagesize'))
+ {
+ if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false))
+ {
+ $error[] = 'UNABLE_GET_IMAGE_SIZE';
+ return false;
+ }
+
+ if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0))
+ {
+ $error[] = 'AVATAR_NO_SIZE';
+ return false;
+ }
+
+ $width = ($width && $height) ? $width : $image_data[0];
+ $height = ($width && $height) ? $height : $image_data[1];
+ }
+
+ if ($width <= 0 || $height <= 0)
+ {
+ $error[] = 'AVATAR_NO_SIZE';
+ return false;
+ }
+
+ include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx);
+ $types = fileupload::image_types();
+ $extension = strtolower(filespec::get_extension($url));
+
+ if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]])))
+ {
+ if (!isset($types[$image_data[2]]))
+ {
+ $error[] = 'UNABLE_GET_IMAGE_SIZE';
+ }
+ else
+ {
+ $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension);
+ }
+
+ return false;
+ }
+
+ if ($this->config['avatar_max_width'] || $this->config['avatar_max_height'])
+ {
+ if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height'])
+ {
+ $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height);
+ return false;
+ }
+ }
+
+ if ($this->config['avatar_min_width'] || $this->config['avatar_min_height'])
+ {
+ if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height'])
+ {
+ $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height);
+ return false;
+ }
+ }
+
+ return array(
+ 'avatar' => $url,
+ 'avatar_width' => $width,
+ 'avatar_height' => $height,
+ );
+ }
+}
diff --git a/phpBB/includes/avatar/driver/core/upload.php b/phpBB/includes/avatar/driver/core/upload.php
new file mode 100644
index 0000000000..d0ce856dbe
--- /dev/null
+++ b/phpBB/includes/avatar/driver/core/upload.php
@@ -0,0 +1,147 @@
+<?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;
+}
+
+/**
+* Handles avatars uploaded to the board
+* @package avatars
+*/
+class phpbb_avatar_driver_core_upload extends phpbb_avatar_driver
+{
+ /**
+ * @inheritdoc
+ */
+ public function get_data($row, $ignore_config = false)
+ {
+ if ($ignore_config || $this->config['allow_avatar_upload'])
+ {
+ return array(
+ 'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $row['avatar'],
+ 'width' => $row['avatar_width'],
+ 'height' => $row['avatar_height'],
+ );
+ }
+ else
+ {
+ return array(
+ 'src' => '',
+ 'width' => 0,
+ 'height' => 0,
+ );
+ }
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function prepare_form($template, $row, &$error)
+ {
+ if (!$this->can_upload())
+ {
+ return false;
+ }
+
+ $template->assign_vars(array(
+ 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false,
+ 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'],
+ ));
+
+ return true;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function process_form($template, $row, &$error)
+ {
+ if (!$this->can_upload())
+ {
+ return false;
+ }
+
+ include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx);
+
+ $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false));
+
+ $url = $this->request->variable('av_upload_url', '');
+
+ if (!empty($_FILES['av_upload_file']['name']))
+ {
+ $file = $upload->form_upload('av_upload_file');
+ }
+ else
+ {
+ $file = $upload->remote_upload($url);
+ }
+
+ $prefix = $this->config['avatar_salt'] . '_';
+ $file->clean_filename('avatar', $prefix, $row['id']);
+
+ $destination = $this->config['avatar_path'];
+
+ // Adjust destination path (no trailing slash)
+ if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\')
+ {
+ $destination = substr($destination, 0, -1);
+ }
+
+ $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
+ if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
+ {
+ $destination = '';
+ }
+
+ // Move file and overwrite any existing image
+ $file->move_file($destination, true);
+
+ if (sizeof($file->error))
+ {
+ $file->remove();
+ $error = array_merge($error, $file->error);
+ return false;
+ }
+
+ return array(
+ 'avatar' => $row['id'] . '_' . time() . '.' . $file->get('extension'),
+ 'avatar_width' => $file->get('width'),
+ 'avatar_height' => $file->get('height'),
+ );
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function delete($row)
+ {
+ $ext = substr(strrchr($row['avatar'], '.'), 1);
+ $filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $row['id'] . '.' . $ext;
+
+ if (file_exists($filename))
+ {
+ @unlink($filename);
+ }
+
+ return true;
+ }
+
+ /**
+ * @TODO
+ */
+ private function can_upload()
+ {
+ return (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on'));
+ }
+}
diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php
new file mode 100644
index 0000000000..5cebd1533d
--- /dev/null
+++ b/phpBB/includes/avatar/driver/driver.php
@@ -0,0 +1,143 @@
+<?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;
+}
+
+/**
+* Base class for avatar drivers
+* @package avatars
+*/
+abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface
+{
+ /**
+ * Current board configuration
+ * @type phpbb_config
+ */
+ protected $config;
+
+ /**
+ * Current board configuration
+ * @type phpbb_config
+ */
+ protected $request;
+
+ /**
+ * Current $phpbb_root_path
+ * @type string
+ */
+ protected $phpbb_root_path;
+
+ /**
+ * Current $phpEx
+ * @type string
+ */
+ 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
+ * tag, and will generate the html itself.
+ * @type boolean
+ */
+ public $custom_html = false;
+
+ /**
+ * Construct an driver object
+ *
+ * @param $config The phpBB configuration
+ * @param $request The request object
+ * @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_request $request, $phpbb_root_path, $phpEx, phpbb_cache_driver_interface $cache = null)
+ {
+ $this->config = $config;
+ $this->request = $request;
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->phpEx = $phpEx;
+ $this->cache = $cache;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function get_data($row, $ignore_config = false)
+ {
+ return array(
+ 'src' => '',
+ 'width' => 0,
+ 'height' => 0,
+ );
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function get_custom_html($row, $ignore_config = false)
+ {
+ return '';
+ }
+
+ /**
+ * @inheritdoc
+ **/
+ public function prepare_form($template, $row, &$error)
+ {
+ return false;
+ }
+
+ /**
+ * @inheritdoc
+ **/
+ public function process_form($template, $row, &$error)
+ {
+ return false;
+ }
+
+ /**
+ * @inheritdoc
+ **/
+ public function delete($row)
+ {
+ return true;
+ }
+
+ /**
+ * @inheritdoc
+ **/
+ public function is_enabled()
+ {
+ $driver = preg_replace('#^phpbb_avatar_driver_core_#', '', get_class($this));
+
+ return $this->config["allow_avatar_$driver"];
+ }
+
+ /**
+ * @inheritdoc
+ **/
+ public function get_template_name()
+ {
+ $driver = preg_replace('#^phpbb_avatar_driver_core_#', '', get_class($this));
+ $template = "ucp_avatar_options_$driver.html";
+
+ return $template;
+ }
+}
diff --git a/phpBB/includes/avatar/driver/interface.php b/phpBB/includes/avatar/driver/interface.php
new file mode 100644
index 0000000000..4f1c1f73cf
--- /dev/null
+++ b/phpBB/includes/avatar/driver/interface.php
@@ -0,0 +1,70 @@
+<?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;
+}
+
+/**
+* Interface for avatar drivers
+* @package avatars
+*/
+interface phpbb_avatar_driver_interface
+{
+ /**
+ * Get the avatar url and dimensions
+ *
+ * @param $ignore_config Whether this function should respect the users prefs
+ * and board configuration configuration option, or should just render
+ * the avatar anyways. Useful for the ACP.
+ * @return array Avatar data, must have keys src, width and height, e.g.
+ * ['src' => '', 'width' => 0, 'height' => 0]
+ */
+ public function get_data($row, $ignore_config = false);
+
+ /**
+ * Returns custom html for displaying this avatar.
+ * Only called if $custom_html is true.
+ *
+ * @param $ignore_config Whether this function should respect the users prefs
+ * and board configuration configuration option, or should just render
+ * the avatar anyways. Useful for the ACP.
+ * @return string HTML
+ */
+ public function get_custom_html($row, $ignore_config = false);
+
+ /**
+ * @TODO
+ **/
+ public function prepare_form($template, $row, &$error);
+
+ /**
+ * @TODO
+ **/
+ public function process_form($template, $row, &$error);
+
+ /**
+ * @TODO
+ **/
+ public function delete($row);
+
+ /**
+ * @TODO
+ **/
+ public function is_enabled();
+
+ /**
+ * @TODO
+ **/
+ public function get_template_name();
+}
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);
+ }
+}
diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php
index 73129803ee..f84652fc50 100644
--- a/phpBB/includes/functions_display.php
+++ b/phpBB/includes/functions_display.php
@@ -1313,79 +1313,86 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank
/**
* Get user avatar
*
-* @param string $avatar Users assigned avatar name
-* @param int $avatar_type Type of avatar
-* @param string $avatar_width Width of users avatar
-* @param string $avatar_height Height of users avatar
+* @param array $user_row Row from the users table
* @param string $alt Optional language string for alt tag within image, can be a language key or text
* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
*
-* @return string Avatar image
+* @return string Avatar html
*/
-function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false)
+function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false)
{
- global $user, $config, $phpbb_root_path, $phpEx;
- global $phpbb_dispatcher;
-
- $overwrite_avatar = '';
+ $row = phpbb_avatar_manager::clean_row($user_row);
+ return get_avatar($row, $alt, $ignore_config);
+}
- /**
- * Overwrite users avatar
- *
- * @event core.display_custom_bbcodes_modify_row
- * @var string avatar Users assigned avatar name
- * @var int avatar_type Type of avatar
- * @var string avatar_width Width of users avatar
- * @var string avatar_height Height of users avatar
- * @var string alt Language string for alt tag within image
- * Can be a language key or text
- * @var bool ignore_config Ignores config and force displaying avatar
- * @var string overwrite_avatar If set, this string will be the avatar
- * @since 3.1-A1
- */
- $vars = array('avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'alt', 'ignore_config', 'overwrite_avatar');
- extract($phpbb_dispatcher->trigger_event('core.user_get_avatar', compact($vars)));
+/**
+* Get group avatar
+*
+* @param array $group_row Row from the groups table
+* @param string $alt Optional language string for alt tag within image, can be a language key or text
+* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
+*
+* @return string Avatar html
+*/
+function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false)
+{
+ $row = phpbb_avatar_manager::clean_row($user_row);
+ return get_avatar($row, $alt, $ignore_config);
+}
- if ($overwrite_avatar)
- {
- return $overwrite_avatar;
- }
+/**
+* Get avatar
+*
+* @param array $row Row cleaned by phpbb_avatar_driver::clean_row
+* @param string $alt Optional language string for alt tag within image, can be a language key or text
+* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
+*
+* @return string Avatar html
+*/
+function get_avatar($row, $alt, $ignore_config = false)
+{
+ global $user, $config, $cache, $phpbb_root_path, $phpEx;
+ global $request;
+ global $phpbb_avatar_manager;
- if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config))
+ if (!$config['allow_avatar'] && !$ignore_config)
{
return '';
}
- $avatar_img = '';
+ $avatar_data = array(
+ 'src' => $row['avatar'],
+ 'width' => $row['avatar_width'],
+ 'height' => $row['avatar_height'],
+ );
+
+ $avatar = $phpbb_avatar_manager->get_driver($row['avatar_type']);
- switch ($avatar_type)
+ if ($avatar)
{
- case AVATAR_UPLOAD:
- if (!$config['allow_avatar_upload'] && !$ignore_config)
- {
- return '';
- }
- $avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
- break;
+ if ($avatar->custom_html)
+ {
+ return $avatar->get_html($row, $ignore_config);
+ }
- case AVATAR_GALLERY:
- if (!$config['allow_avatar_local'] && !$ignore_config)
- {
- return '';
- }
- $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
- break;
+ $avatar_data = $avatar->get_data($row, $ignore_config);
+ }
+ else
+ {
+ $avatar_data['src'] = '';
+ }
- case AVATAR_REMOTE:
- if (!$config['allow_avatar_remote'] && !$ignore_config)
- {
- return '';
- }
- break;
+ $html = '';
+
+ if (!empty($avatar_data['src']))
+ {
+ $html = '<img src="' . $avatar_data['src'] . '" ' .
+ ($avatar_data['width'] ? ('width="' . $avatar_data['width'] . '" ') : '') .
+ ($avatar_data['height'] ? ('height="' . $avatar_data['height'] . '" ') : '') .
+ 'alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
}
- $avatar_img .= $avatar;
- return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
+ return $html;
}
/**
diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php
index 8f9c9198f4..7cac0fb34f 100644
--- a/phpBB/includes/functions_user.php
+++ b/phpBB/includes/functions_user.php
@@ -2048,6 +2048,7 @@ function avatar_delete($mode, $row, $clean_db = false)
avatar_remove_db($row[$mode . '_avatar']);
}
$filename = get_avatar_filename($row[$mode . '_avatar']);
+
if (file_exists($phpbb_root_path . $config['avatar_path'] . '/' . $filename))
{
@unlink($phpbb_root_path . $config['avatar_path'] . '/' . $filename);
diff --git a/phpBB/includes/mcp/mcp_notes.php b/phpBB/includes/mcp/mcp_notes.php
index 59cdf3c27e..0b00d77d8f 100644
--- a/phpBB/includes/mcp/mcp_notes.php
+++ b/phpBB/includes/mcp/mcp_notes.php
@@ -179,7 +179,7 @@ class mcp_notes
}
$rank_title = $rank_img = '';
- $avatar_img = get_user_avatar($userrow['user_avatar'], $userrow['user_avatar_type'], $userrow['user_avatar_width'], $userrow['user_avatar_height']);
+ $avatar_img = get_user_avatar($userrow);
$limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
$sort_by_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_DATE'], 'c' => $user->lang['SORT_IP'], 'd' => $user->lang['SORT_ACTION']);
diff --git a/phpBB/includes/mcp/mcp_warn.php b/phpBB/includes/mcp/mcp_warn.php
index 6a8fb4c5d5..f88ac3803f 100644
--- a/phpBB/includes/mcp/mcp_warn.php
+++ b/phpBB/includes/mcp/mcp_warn.php
@@ -310,7 +310,7 @@ class mcp_warn
}
get_user_rank($user_row['user_rank'], $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src);
- $avatar_img = get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']);
+ $avatar_img = get_user_avatar($user_row);
$template->assign_vars(array(
'U_POST_ACTION' => $this->u_action,
@@ -415,7 +415,7 @@ class mcp_warn
}
get_user_rank($user_row['user_rank'], $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src);
- $avatar_img = get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']);
+ $avatar_img = get_user_avatar($user_row);
// OK, they didn't submit a warning so lets build the page for them to do so
$template->assign_vars(array(
diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php
index 9652986cf2..3aa6146081 100644
--- a/phpBB/includes/ucp/ucp_groups.php
+++ b/phpBB/includes/ucp/ucp_groups.php
@@ -438,7 +438,7 @@ class ucp_groups
$group_name = $group_row['group_name'];
$group_type = $group_row['group_type'];
- $avatar_img = (!empty($group_row['group_avatar'])) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : '<img src="' . $phpbb_root_path . 'adm/images/no_avatar.gif" alt="" />';
+ $avatar_img = (!empty($group_row['group_avatar'])) ? get_group_avatar($group_row) : '<img src="' . $phpbb_root_path . 'adm/images/no_avatar.gif" alt="" />';
$template->assign_vars(array(
'GROUP_NAME' => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name,
diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php
index c85b05f144..42b63f8ce1 100644
--- a/phpBB/includes/ucp/ucp_pm_viewmessage.php
+++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php
@@ -376,7 +376,7 @@ function get_user_information($user_id, $user_row)
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
}
- $user_row['avatar'] = ($user->optionget('viewavatars')) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']) : '';
+ $user_row['avatar'] = ($user->optionget('viewavatars')) ? get_user_avatar($user_row) : '';
get_user_rank($user_row['user_rank'], $user_row['user_posts'], $user_row['rank_title'], $user_row['rank_image'], $user_row['rank_image_src']);
diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php
index 89bf20a30f..4b0e59b9e8 100644
--- a/phpBB/includes/ucp/ucp_profile.php
+++ b/phpBB/includes/ucp/ucp_profile.php
@@ -28,8 +28,9 @@ class ucp_profile
function main($id, $mode)
{
- global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
+ global $cache, $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
global $request;
+ global $phpbb_avatar_manager;
$user->add_lang('posting');
@@ -544,79 +545,142 @@ class ucp_profile
break;
case 'avatar':
+ include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
- include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+ add_form_key('ucp_avatar');
- $display_gallery = request_var('display_gallery', '0');
- $avatar_select = basename(request_var('avatar_select', ''));
- $category = basename(request_var('category', ''));
+ $avatars_enabled = false;
- $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false;
+ if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar'))
+ {
+ $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers();
+ sort($avatar_drivers);
- add_form_key('ucp_avatar');
+ // This is normalised data, without the user_ prefix
+ $avatar_data = phpbb_avatar_manager::clean_row($user->data);
- if ($submit)
- {
- if (check_form_key('ucp_avatar'))
+ if ($submit)
{
- if (avatar_process_user($error, false, $can_upload))
+ if (check_form_key('ucp_avatar'))
{
- meta_refresh(3, $this->u_action);
- $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
- trigger_error($message);
+ $driver = request_var('avatar_driver', '');
+ if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"])
+ {
+ $avatar = $phpbb_avatar_manager->get_driver($driver);
+ $result = $avatar->process_form($template, $avatar_data, $error);
+
+ if ($result && empty($error))
+ {
+ // Success! Lets save the result in the database
+ $result = array(
+ 'user_avatar_type' => $driver,
+ 'user_avatar' => $result['avatar'],
+ 'user_avatar_width' => $result['avatar_width'],
+ 'user_avatar_height' => $result['avatar_height'],
+ );
+
+ $sql = 'UPDATE ' . USERS_TABLE . '
+ SET ' . $db->sql_build_array('UPDATE', $result) . '
+ WHERE user_id = ' . $user->data['user_id'];
+
+ $db->sql_query($sql);
+
+ meta_refresh(3, $this->u_action);
+ $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
+ trigger_error($message);
+ }
+ }
+ else
+ {
+ // They are removing their avatar or are trying to play games with us
+ if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type']))
+ {
+ $avatar->delete($avatar_data);
+ }
+
+ $result = array(
+ 'user_avatar' => '',
+ 'user_avatar_type' => '',
+ 'user_avatar_width' => 0,
+ 'user_avatar_height' => 0,
+ );
+
+ $sql = 'UPDATE ' . USERS_TABLE . '
+ SET ' . $db->sql_build_array('UPDATE', $result) . '
+ WHERE user_id = ' . $user->data['user_id'];
+
+ $db->sql_query($sql);
+
+ meta_refresh(3, $this->u_action);
+ $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
+ trigger_error($message);
+ }
+ }
+ else
+ {
+ $error[] = 'FORM_INVALID';
}
}
- else
+
+ $focused_driver = request_var('avatar_driver', $user->data['user_avatar_type']);
+
+ foreach ($avatar_drivers as $driver)
{
- $error[] = 'FORM_INVALID';
+ $avatar = $phpbb_avatar_manager->get_driver($driver);
+
+ if ($avatar->is_enabled())
+ {
+ $avatars_enabled = true;
+ $template->set_filenames(array(
+ 'avatar' => $avatar->get_template_name(),
+ ));
+
+ if ($avatar->prepare_form($template, $avatar_data, $error))
+ {
+ $driver_u = strtoupper($driver);
+
+ $template->assign_block_vars('avatar_drivers', array(
+ 'L_TITLE' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_TITLE'), // @TODO add lang values
+ 'L_EXPLAIN' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_EXPLAIN'),
+
+ 'DRIVER' => $driver,
+ 'SELECTED' => ($driver == $focused_driver),
+ 'OUTPUT' => $template->assign_display('avatar'),
+ ));
+ }
+ }
}
- // Replace "error" strings with their real, localised form
- $error = array_map(array($user, 'lang'), $error);
}
- if (!$config['allow_avatar'] && $user->data['user_avatar_type'])
- {
- $error[] = $user->lang['AVATAR_NOT_ALLOWED'];
- }
- else if ((($user->data['user_avatar_type'] == AVATAR_UPLOAD) && !$config['allow_avatar_upload']) ||
- (($user->data['user_avatar_type'] == AVATAR_REMOTE) && !$config['allow_avatar_remote']) ||
- (($user->data['user_avatar_type'] == AVATAR_GALLERY) && !$config['allow_avatar_local']))
+ // Replace "error" strings with their real, localised form
+ $err = $error;
+ $error = array();
+ foreach ($err as $e)
{
- $error[] = $user->lang['AVATAR_TYPE_NOT_ALLOWED'];
+ if (is_array($e))
+ {
+ $key = array_shift($e);
+ $error[] = vsprintf($user->lang($key), $e);
+ }
+ else
+ {
+ $error[] = $user->lang((string) $e);
+ }
}
+
+ $avatar = get_user_avatar($user->data, 'USER_AVATAR', true);
$template->assign_vars(array(
'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
- 'AVATAR' => get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height'], 'USER_AVATAR', true),
- 'AVATAR_SIZE' => $config['avatar_filesize'],
-
- 'U_GALLERY' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&amp;mode=avatar&amp;display_gallery=1'),
+ 'AVATAR' => $avatar,
- 'S_FORM_ENCTYPE' => ($can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) ? ' enctype="multipart/form-data"' : '',
+ 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"',
'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string(),
+
+ 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled),
));
- if ($config['allow_avatar'] && $display_gallery && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local'])
- {
- avatar_gallery($category, $avatar_select, 4);
- }
- else if ($config['allow_avatar'])
- {
- $avatars_enabled = (($can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) || ($auth->acl_get('u_chgavatar') && ($config['allow_avatar_local'] || $config['allow_avatar_remote']))) ? true : false;
-
- $template->assign_vars(array(
- 'AVATAR_WIDTH' => request_var('width', $user->data['user_avatar_width']),
- 'AVATAR_HEIGHT' => request_var('height', $user->data['user_avatar_height']),
-
- 'S_AVATARS_ENABLED' => $avatars_enabled,
- 'S_UPLOAD_AVATAR_FILE' => ($can_upload && $config['allow_avatar_upload']) ? true : false,
- 'S_UPLOAD_AVATAR_URL' => ($can_upload && $config['allow_avatar_remote_upload']) ? true : false,
- 'S_LINK_AVATAR' => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_remote']) ? true : false,
- 'S_DISPLAY_GALLERY' => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) ? true : false)
- );
- }
-
break;
case 'autologin_keys':