aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/acp/acp_groups.php2
-rw-r--r--phpBB/includes/acp/acp_users.php2
-rw-r--r--phpBB/includes/avatars/avatar_base.php75
-rw-r--r--phpBB/includes/functions_display.php128
-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.php2
9 files changed, 193 insertions, 26 deletions
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php
index 607254adb5..9ad157f78a 100644
--- a/phpBB/includes/acp/acp_groups.php
+++ b/phpBB/includes/acp/acp_groups.php
@@ -553,7 +553,7 @@ 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="" />';
+ $avatar_img = (!empty($group_row['group_avatar'])) ? get_group_avatar($group_row) : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
$display_gallery = (isset($_POST['display_gallery'])) ? true : false;
diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php
index 97f4b1b5fd..390e421a51 100644
--- a/phpBB/includes/acp/acp_users.php
+++ b/phpBB/includes/acp/acp_users.php
@@ -1715,7 +1715,7 @@ class acp_users
}
// 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="" />';
+ $avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row, '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', ''));
diff --git a/phpBB/includes/avatars/avatar_base.php b/phpBB/includes/avatars/avatar_base.php
new file mode 100644
index 0000000000..c84a6e8a7f
--- /dev/null
+++ b/phpBB/includes/avatars/avatar_base.php
@@ -0,0 +1,75 @@
+<?php
+/**
+*
+* @package avatars
+* @copyright (c) 2005, 2009 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Base class for avatar modules
+* @package avatars
+*/
+class phpbb_avatar_base
+{
+ /**
+ * User data this avatar may use to generate a url or html
+ * @type array
+ */
+ private $user_row;
+
+ /**
+ * 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 avatar object
+ *
+ * @param $user_row User data to base the avatar url/html on
+ */
+ public function __construct(&$user_row)
+ {
+ $this->user_row = $user_row;
+ }
+
+ /**
+ * Get the avatar url and dimensions
+ *
+ * @param $ignore_config Whether $user or global avatar visibility settings
+ * should be ignored
+ * @return array Avatar data
+ */
+ public function get_data($ignore_config = false)
+ {
+ return array(
+ 'src' => '',
+ 'width' => 0,
+ 'height' => 0,
+ );
+ }
+
+ /**
+ * Returns custom html for displaying this avatar.
+ * Only called if $custom_html is true.
+ *
+ * @param $ignore_config Whether $user or global avatar visibility settings
+ * should be ignored
+ * @return string HTML
+ */
+ public function get_custom_html($ignore_config = false)
+ {
+ return '';
+ }
+}
diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php
index 9335cabc15..eba123be9d 100644
--- a/phpBB/includes/functions_display.php
+++ b/phpBB/includes/functions_display.php
@@ -1272,52 +1272,144 @@ 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 $user, $config, $cache, $phpbb_root_path, $phpEx;
- if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config))
+ if (!$config['allow_avatar'] && !$ignore_config)
{
return '';
}
- $avatar_img = '';
-
- switch ($avatar_type)
+ $avatar_data = array(
+ 'src' => $user_row['user_avatar'],
+ 'width' => $user_row['user_avatar_width'],
+ 'height' => $user_row['user_avatar_height'],
+ );
+
+ switch ($user_row['user_avatar_type'])
{
case AVATAR_UPLOAD:
+ // Compatibility with old avatars
if (!$config['allow_avatar_upload'] && !$ignore_config)
{
- return '';
+ $avatar_data['src'] = '';
+ }
+ else
+ {
+ $avatar_data['src'] = $phpbb_root_path . "download/file.$phpEx?avatar=" . $avatar_data['src'];
+ $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']);
}
- $avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
break;
case AVATAR_GALLERY:
+ // Compatibility with old avatars
if (!$config['allow_avatar_local'] && !$ignore_config)
{
- return '';
+ $avatar_data['src'] = '';
+ }
+ else
+ {
+ $avatar_data['src'] = $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_data['src'];
+ $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']);
}
- $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
break;
case AVATAR_REMOTE:
+ // Compatibility with old avatars
if (!$config['allow_avatar_remote'] && !$ignore_config)
{
- return '';
+ $avatar_data['src'] = '';
+ }
+ else
+ {
+ $avatar_data['src'] = str_replace(' ', '%20', $avatar_data['src']);
}
break;
+
+ default:
+ $class = 'phpbb_avatar_' . $user_row['user_avatar_type'];
+
+ if (!class_exists($class))
+ {
+ $avatar_types = $cache->get('avatar_types');
+
+ if (empty($avatar_types))
+ {
+ $avatar_types = array();
+
+ if ($dh = @opendir($phpbb_root_path . 'includes/avatars'))
+ {
+ while ($file = @readdir($dh))
+ {
+ if (preg_match("/avatar_(.*)\.$phpEx/", $file, $match))
+ {
+ $avatar_types[] = $match[1];
+ }
+ }
+
+ @closedir($dh);
+
+ sort($avatar_types);
+ $cache->put('avatar_types', $avatar_types);
+ }
+ }
+
+ if (in_array($user_row['user_avatar_type'], $avatar_types))
+ {
+ require_once($phpbb_root_path . 'includes/avatars/avatar_' . $user_row['user_avatar_type'] . '.' . $phpEx);
+ }
+ }
+
+ $avatar = new $class($user_row);
+
+ if ($avatar->custom_html)
+ {
+ return $avatar->get_custom_html($ignore_config);
+ }
+
+ $avatar_data = $avatar->get_data($ignore_config);
+
+ 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;
+}
+
+/**
+* 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(&$group_row, $alt = 'GROUP_AVATAR', $ignore_config = false)
+{
+ // Kind of abusing this functionality...
+ $avatar_row = array(
+ 'user_avatar' => $group_row['group_avatar'],
+ 'user_avatar_type' => $group_row['group_avatar_type'],
+ 'user_avatar_width' => $group_row['group_avatar_width'],
+ 'user_avatar_height' => $group_row['group_avatar_height'],
+ );
+
+ return get_user_avatar($group_row, $alt, $ignore_config);
}
diff --git a/phpBB/includes/mcp/mcp_notes.php b/phpBB/includes/mcp/mcp_notes.php
index 99dbb8d86d..fe5be5dc0b 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 d8e655000f..3af021565f 100644
--- a/phpBB/includes/mcp/mcp_warn.php
+++ b/phpBB/includes/mcp/mcp_warn.php
@@ -308,7 +308,7 @@ class mcp_warn
}
$rank_title = $rank_img = '';
- $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,
@@ -413,7 +413,7 @@ class mcp_warn
}
$rank_title = $rank_img = '';
- $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 a7c6479759..98bdf17d3f 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 c55e8850a6..a807e3a537 100644
--- a/phpBB/includes/ucp/ucp_pm_viewmessage.php
+++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php
@@ -350,7 +350,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 9d81503f0a..f61e692f32 100644
--- a/phpBB/includes/ucp/ucp_profile.php
+++ b/phpBB/includes/ucp/ucp_profile.php
@@ -587,7 +587,7 @@ class ucp_profile
$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' => get_user_avatar($user->data, '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'),