aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2012-11-21 16:20:14 +0100
committerMarc Alexander <admin@m-a-styles.de>2012-11-21 16:20:14 +0100
commitb7b14f9a056190c6a01c98f6eec9e60ad73d7564 (patch)
tree36d2f23fdbe70982e59aaf5461361a21022baa74 /phpBB/includes
parent858c59279c0f8b07412dec676c96d9b291d91897 (diff)
downloadforums-b7b14f9a056190c6a01c98f6eec9e60ad73d7564.tar
forums-b7b14f9a056190c6a01c98f6eec9e60ad73d7564.tar.gz
forums-b7b14f9a056190c6a01c98f6eec9e60ad73d7564.tar.bz2
forums-b7b14f9a056190c6a01c98f6eec9e60ad73d7564.tar.xz
forums-b7b14f9a056190c6a01c98f6eec9e60ad73d7564.zip
[feature/avatars] Use constant for URL and fix usage of getimagesize
We now use a constant for the gravatar URL. Additionally the usage of getimagesize() was reduced. It should only be run if the user didn't specify both the width and height of the avatar. PHPBB3-10018
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/avatar/driver/gravatar.php55
1 files changed, 39 insertions, 16 deletions
diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php
index 036800fd45..a73a28a234 100644
--- a/phpBB/includes/avatar/driver/gravatar.php
+++ b/phpBB/includes/avatar/driver/gravatar.php
@@ -21,6 +21,8 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver
{
+ const GRAVATAR_URL = 'https://secure.gravatar.com/avatar/';
+
/**
* @inheritdoc
*/
@@ -54,8 +56,7 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver
*/
public function get_custom_html($row, $ignore_config = false, $alt = '')
{
- $html = '<img src="https://secure.gravatar.com/avatar/' . md5(strtolower(trim($row['avatar']))) .
- (($row['avatar_width'] || $row['avatar_height']) ? ('?s=' . max($row['avatar_width'], $row['avatar_height'])) : '') . '" ' .
+ $html = '<img src="' . $this->get_gravatar_url($row) . '" ' .
($row['avatar_width'] ? ('width="' . $row['avatar_width'] . '" ') : '') .
($row['avatar_height'] ? ('height="' . $row['avatar_height'] . '" ') : '') .
'alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
@@ -81,14 +82,14 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver
*/
public function process_form($template, $row, &$error)
{
- $email = $this->request->variable('av_gravatar_email', '');
- $width = $this->request->variable('av_gravatar_width', 0);
- $height = $this->request->variable('av_gravatar_height', 0);
+ $row['avatar'] = $this->request->variable('av_gravatar_email', '');
+ $row['avatar_width'] = $this->request->variable('av_gravatar_width', 0);
+ $row['avatar_height'] = $this->request->variable('av_gravatar_height', 0);
require_once($this->phpbb_root_path . 'includes/functions_user' . $this->phpEx);
$error = array_merge($error, validate_data(array(
- 'email' => $email,
+ 'email' => $row['avatar'],
), array(
'email' => array(
array('string', false, 6, 60),
@@ -101,12 +102,16 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver
}
// Make sure getimagesize works...
- if (function_exists('getimagesize'))
+ if (function_exists('getimagesize') && ($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0))
{
- // build URL
- $url = 'https://secure.gravatar.com/' . md5(strtolower(trim($email)));
+ /**
+ * default to the minimum of the maximum allowed avatar size if the size
+ * is not or only partially entered
+ */
+ $row['avatar_width'] = $row['avatar_height'] = min($this->config['avatar_max_width'], $this->config['avatar_max_height']);
+ $url = $this->get_gravatar_url($row);
- if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false))
+ if (($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0) && (($image_data = @getimagesize($url)) === false))
{
$error[] = 'UNABLE_GET_IMAGE_SIZE';
return false;
@@ -118,20 +123,38 @@ class phpbb_avatar_driver_gravatar extends phpbb_avatar_driver
return false;
}
- $width = ($width && $height) ? $width : $image_data[0];
- $height = ($width && $height) ? $height : $image_data[1];
+ $row['avatar_width'] = ($row['avatar_width'] && $row['avatar_height']) ? $row['avatar_width'] : $image_data[0];
+ $row['avatar_height'] = ($row['avatar_width'] && $row['avatar_height']) ? $row['avatar_height'] : $image_data[1];
}
- if ($width <= 0 || $height <= 0)
+ if ($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0)
{
$error[] = 'AVATAR_NO_SIZE';
return false;
}
return array(
- 'avatar' => $email,
- 'avatar_width' => $width,
- 'avatar_height' => $height,
+ 'avatar' => $row['avatar'],
+ 'avatar_width' => $row['avatar_width'],
+ 'avatar_height' => $row['avatar_height'],
);
}
+
+ /**
+ * Build gravatar URL for output on page
+ *
+ * @return string The gravatar URL
+ */
+ protected function get_gravatar_url($row)
+ {
+ $url = self::GRAVATAR_URL;
+ $url .= md5(strtolower(trim($row['avatar'])));
+
+ if ($row['avatar_width'] || $row['avatar_height'])
+ {
+ $url .= '?s=' . max($row['avatar_width'], $row['avatar_height']);
+ }
+
+ return $url;
+ }
}