Commit a0cff546 authored by Son Nguyen's avatar Son Nguyen Committed by Robert Lyon
Browse files

Fix the default image url passed to gavatar. Bug 1378543

This url must not include a querystring
(see https://en.gravatar.com/site/implement/images/

)

- Return the no user photo url if the remote avatar is not found
- Try to use profile_icon_url as much as possible

Change-Id: Id18ee4469b1bd15013445f8f4dc4a582dee659e8
Signed-off-by: default avatarSon Nguyen <sonn@catalyst.net.nz>
parent 82c5cbe4
......@@ -26,7 +26,7 @@
<div class="inlinelist">
<span>{str tag="Moderators" section="interaction.forum"}:</span>
{foreach from=$forum->moderators item=mod}
<a href="{profile_url($mod)}"><img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=20&amp;id={$mod}" alt=""></a>
<a href="{profile_url($mod)}"><img src="{profile_icon_url user=$mod maxwidth=20 maxheight=20}" alt="{str tag=profileimagetext arg1=$mod|display_default_name}"></a>
<a href="{profile_url($mod)}" class="moderator">{$mod|display_name:null:true}</a>
{/foreach}
</div>
......
......@@ -5,7 +5,7 @@
<tr>
<td class="forumpostleft">
<div class="author">
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=40&amp;id={$post->poster}" alt="{str tag=profileimagetext arg1=$post->poster|display_default_name}" class="center">
<img src="{profile_icon_url user=$post->poster maxwidth=40 maxheight=40}" alt="{str tag=profileimagetext arg1=$post->poster|display_default_name}" class="center">
<div class="poster"><a href="{profile_url($post->poster)}"{if in_array($post->poster, $groupadmins)} class="groupadmin"{elseif $post->moderator} class="moderator"{/if}>{$post->poster|display_name}</a></div>
{if $post->postcount}<div class="postcount">{$post->postcount}</div>{/if}
</div>
......@@ -25,7 +25,7 @@
{elseif $edit.moderator} class="moderator"
{/if}
>
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=20&amp;id={$edit.editor}" alt="">
<img src="{profile_icon_url user=$edit.editor maxwidth=20 maxheight=20}" alt="{str tag=profileimagetext arg1=$edit.editor|display_default_name}">
{$edit.editor|display_name}
</a> - <span class="posttime">{$edit.edittime}</span>
</li>
......
......@@ -70,7 +70,7 @@
<label>{str tag="groupadminlist" section="interaction.forum"}</label>
{foreach from=$groupadmins item=groupadmin}
<span class="s inlinelist">
<a href="{profile_url($groupadmin)}"><img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=20&amp;id={$groupadmin}" alt="{str tag=profileimagetext arg1=$groupadmin|display_default_name}"></a>
<a href="{profile_url($groupadmin)}"><img src="{profile_icon_url user=$groupadmin maxwidth=20 maxheight=20}" alt="{str tag=profileimagetext arg1=$groupadmin|display_default_name}"></a>
<a href="{profile_url($groupadmin)}" class="groupadmin">{$groupadmin|display_name}</a>
</span>
{/foreach}
......@@ -79,7 +79,7 @@
<label>{str tag="moderatorslist" section="interaction.forum"}</label>
{foreach from=$moderators item=mod}
<span class="s inlinelist">
<a href="{profile_url($mod)}"><img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=20&amp;id={$mod}" alt=""></a>
<a href="{profile_url($mod)}"><img src="{profile_icon_url user=$mod maxwidth=20 maxheight=20}" alt="{str tag=profileimagetext arg1=$mod|display_default_name}"></a>
<a href="{profile_url($mod)}" class="moderator">{$mod|display_name}</a>
</span>
{/foreach}
......
......@@ -2550,6 +2550,32 @@ function anonymous_icon_url($maxwidth=40, $maxheight=40, $email=null) {
return $notfound;
}
/**
* Return the remote avatar associated to the email.
* If the avatar does not exist, return anonymous avatar
*
* @param string $email Email address of the user
* @param object $size Maximum size of the image
* @returns string $url The remote avatar URL
*/
function remote_avatar_url($email, $size) {
global $THEME;
// Available sizes of the 'no_userphoto' image:
$allowedsizes = array(16, 20, 25, 40, 50, 60, 100);
if (!in_array($size, $allowedsizes)) {
log_warn('remote_avatar_url: size should be in (' . join(', ', $allowedsizes) . ')');
}
else {
$size = 40;
}
$notfound = $THEME->get_url('images/no_userphoto' . $size . '.png');
if (!empty($email) && get_config('remoteavatars')) {
return remote_avatar($email, $size, $notfound);
}
return $notfound;
}
/**
* Return a Gravatar URL if one exists for the given user.
*
......@@ -2580,7 +2606,12 @@ function remote_avatar($email, $size, $notfound) {
if (get_config('remoteavatarbaseurl')) {
$baseurl = get_config('remoteavatarbaseurl');
}
return "{$baseurl}{$md5sum}.jpg?r=g&s=$s&d=" . urlencode($notfound);
// Check if it is a valid avatar
$result = get_headers("{$baseurl}{$md5sum}.jpg?d=404");
if ($result[0] === "HTTP/1.0 404 Not Found") {
return $notfound;
}
return "{$baseurl}{$md5sum}.jpg?r=g&s=$s";
}
/**
......
......@@ -39,15 +39,7 @@ switch ($type) {
$mimetype = $data->filetype;
}
else {
if ($useremail = $data->email) {
// We can use the email address for gravatar icon
$notfound = get_config('wwwroot').'thumb.php?type=profileiconbyid';
foreach ($_GET as $k => $v) {
if ($k != 'id' && $k != 'type') {
$notfound .= '&' . $k . '=' . $v;
}
}
}
$useremail = $data->email;
$id = null;
}
}
......@@ -83,7 +75,7 @@ switch ($type) {
}
// Look for an appropriate image on gravatar.com
if ($useremail and $gravatarurl = remote_avatar($useremail, $size, $notfound)) {
if ($useremail and $gravatarurl = remote_avatar_url($useremail, $size)) {
redirect($gravatarurl);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment