Commit e52eb3e1 authored by Francois Marier's avatar Francois Marier
Browse files

Switch to using profileicon instead of profileiconbyid as much as possible



Add a new parameter (earlyexpiry) to maintain the existing behaviour of not
caching the logged in user's images for more than 10 minutes in case they
change their icon.
Signed-off-by: default avatarFrancois Marier <francois@catalyst.net.nz>
parent 2ae95164
......@@ -194,7 +194,7 @@ function get_desired_fields(&$allfields, $desiredfields, $section) {
$return = array();
$return["{$section}description"] = array(
'type' => 'html',
'labelhtml' => ($section == 'about') ? '<div id="profileicon"><a href="' . get_config('wwwroot') . 'artefact/file/profileicons.php"><img src="' . get_config('wwwroot') . 'thumb.php?type=profileiconbyid&maxsize=100&id=' . intval($USER->get('profileicon')) . '" alt=""></a></div>' : '',
'labelhtml' => ($section == 'about') ? '<div id="profileicon"><a href="' . get_config('wwwroot') . 'artefact/file/profileicons.php"><img src="' . get_config('wwwroot') . 'thumb.php?type=profileicon&maxsize=100&id=' . intval($USER->get('id')) . '" alt=""></a></div>' : '',
'value' => get_string("{$section}description", 'artefact.internal')
);
foreach ($desiredfields as $field) {
......
......@@ -2130,9 +2130,9 @@ function onlineusers_sideblock() {
if ($onlineusers) {
foreach ($onlineusers as &$user) {
// Use 'profileiconbyid' for the current user, just in case they change their profile icon
if ($user->id == $USER->get('id')) {
$user->profileiconurl = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . (int)$user->profileicon . '&size=20x20';
// Use a shorter caching time for the current user, just in case they change their profile icon
$user->profileiconurl = get_config('wwwroot') . 'thumb.php?type=profileicon&id=' . $user->id . '&size=20x20&earlyexpiry=1';
}
else {
$user->profileiconurl = get_config('wwwroot') . 'thumb.php?type=profileicon&id=' . $user->id . '&size=20x20';
......
......@@ -2,7 +2,7 @@
<div class="fl center">
<div id="profilepict">
<a href="{$WWWROOT}user/view.php?id={$user->id}"><img src="{$WWWROOT}thumb.php?type=profileiconbyid&amp;maxwidth=100&amp;maxheight=100&amp;id={$user->profileicon}" alt=""></a>
<a href="{$WWWROOT}user/view.php?id={$user->id}"><img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxwidth=100&amp;maxheight=100&amp;id={$user->id}" alt=""></a>
<div id="profilename"><a href="{$WWWROOT}user/view.php?id={$user->id}">{$user|display_name|escape}</a></div>
</div>
{if $loginas}
......
<h3><a href="{$WWWROOT}user/view.php?id={$sbdata.id}">{$sbdata.myname|escape}</a> <span class="s" id="profile-sideblock-username">(<a href="{$WWWROOT}user/view.php?id={$sbdata.id}">{$sbdata.username|escape}</a>)</span></h3>
<div class="sideblock-content">
<div id="user-profileicon"><a href="{$WWWROOT}user/view.php?id={$sbdata.id}"><img src="{$WWWROOT}thumb.php?type=profileiconbyid&amp;maxwidth=50&amp;maxheight=50&amp;id={$sbdata.profileicon}" alt="" width="50" height="50"></a></div>
<div id="user-profileicon"><a href="{$WWWROOT}user/view.php?id={$sbdata.id}"><img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxwidth=50&amp;maxheight=50&amp;id={$sbdata.id}&amp;earlyexpiry=1" alt="" width="50" height="50"></a></div>
{if $sbdata.mnetloggedinfrom} <p>{$sbdata.mnetloggedinfrom}</p>
{/if}
<ul>
......
......@@ -38,6 +38,7 @@ switch ($type) {
case 'profileicon':
$id = param_integer('id', 0);
$size = get_imagesize_parameters();
$earlyexpiry = param_boolean('earlyexpiry');
$useremail = null;
if ($id) {
......@@ -70,7 +71,7 @@ switch ($type) {
// user can change it at any time. But we can cache
// 'profileiconbyid' for quite a while, because it will
// never change
if ($type == 'profileiconbyid') {
if ($type == 'profileiconbyid' and !$earlyexpiry) {
$maxage = 604800; // 1 week
}
else {
......@@ -87,7 +88,7 @@ switch ($type) {
}
// Look for an appropriate image on gravatar.com
if ($useremail and $gravatarurl = gravatar_icon($useremail, '', $size)) {
if ($useremail and $gravatarurl = gravatar_icon($useremail, $size, $earlyexpiry)) {
redirect($gravatarurl);
}
......@@ -95,7 +96,10 @@ switch ($type) {
// photo' image for the current theme
// We can cache such images
$maxage = 604800;
$maxage = 604800; // 1 week
if ($earlyexpiry) {
$maxage = 600; // 10 minutes
}
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
......@@ -169,12 +173,13 @@ switch ($type) {
/**
* Return a Gravatar URL if one exists for the given user.
*
* @param string $email Email address of the user
* @param object $size Maximum size of the image
* @param string $email Email address of the user
* @param object $size Maximum size of the image
* @param boolean $earlyexpiry
*
* @returns string The URL of the image or FALSE if none was found
*/
function gravatar_icon($email, $size=null) {
function gravatar_icon($email, $size, $earlyexpiry) {
$md5sum = md5(strtolower($email));
$s = 100;
......@@ -184,7 +189,7 @@ function gravatar_icon($email, $size=null) {
}
$url = "http://www.gravatar.com/avatar/{$md5sum}.jpg?r=g&s=$s";
$notfound = get_config('wwwroot').'/thumb.php?type=profileiconbyid';
$notfound = get_config('wwwroot').'thumb.php?type=profileiconbyid' . ($earlyexpiry ? '&earlyexpiry=1' : '');
return "$url&d=".urlencode($notfound);
}
......
Markdown is supported
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