Commit 8e8a46db authored by Son Nguyen's avatar Son Nguyen Committed by Gerrit Code Review
Browse files

Merge "Bug 1524095: Allow the remote avatar be fetch once per session"

parents 217bf8b0 53da3434
......@@ -59,6 +59,7 @@ function do_masquerade($why = null) {
'reason' => $why,
));
$SESSION->set('nocheckrequiredfields', null);
$SESSION->set('remoteavatar', null);
redirect(get_config('wwwroot'));
}
......
......@@ -12,6 +12,7 @@
define('INTERNAL', 1);
define('JSON', 1);
define('INSTITUTIONALSTAFF', 1);
define('SECTION_PAGE', 'usersearch');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('searchlib.php');
......
......@@ -17,6 +17,7 @@ define('TITLE', get_string('usersearch', 'admin'));
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'usersearch');
define('IGNORE_FETCH_REMOTE_AVATAR', 1);
require_once('searchlib.php');
$search = (object) array(
......
......@@ -1564,6 +1564,7 @@ class LiveUser extends User {
// Unset session variables related to authentication
$this->SESSION->set('authinstance', null);
$this->SESSION->set('remoteavatar', null);
$this->SESSION->set('nocheckrequiredfields', null);
if (get_config('installed') && !defined('INSTALLER') && $this->get('sessionid')
&& table_exists(new XMLDBTable('usr_session'))) {
......
......@@ -2854,11 +2854,13 @@ function remote_avatar_url($email, $size) {
* @returns string The URL of the image or $notfound if none was found
*/
function remote_avatar($email, $size, $notfound) {
global $SESSION;
if (!get_config('remoteavatars')) {
return false;
}
require_once('file.php');
require_once('file.php');
$md5sum = md5(strtolower($email));
$s = 100;
......@@ -2867,6 +2869,23 @@ function remote_avatar($email, $size, $notfound) {
$s = min($newsize['w'], $newsize['h']);
}
if ($avatars = $SESSION->get('remoteavatar')) {
if (isset($avatars[$md5sum])) {
if ($avatars[$md5sum] == 'notfound') {
return $notfound;
}
return $avatars[$md5sum] . "?r=g&s=$s";
}
}
$avatars = (is_array($avatars)) ? $avatars : array();
// HACK: To speed up the user search page we avoid doing an avatar fetch for each of the users in the list
// as this can make things very slow if we are return a long list. The speed increase is worth the loss of showing
// the correct image here.
if (defined('IGNORE_FETCH_REMOTE_AVATAR') && IGNORE_FETCH_REMOTE_AVATAR === 1) {
return $notfound;
}
$baseurl = 'http://www.gravatar.com/avatar/';
if (is_https() === true) {
$baseurl = 'https://secure.gravatar.com/avatar/';
......@@ -2884,9 +2903,12 @@ function remote_avatar($email, $size, $notfound) {
true
);
if (!$result || $result->error || $result->info['http_code'] == 404) {
$SESSION->set('remoteavatar', array_merge($avatars, array($md5sum => 'notfound')));
return $notfound;
}
return "{$baseurl}{$md5sum}.jpg?r=g&s=$s";
$avatar = "{$baseurl}{$md5sum}.jpg?r=g&s=$s";
$SESSION->set('remoteavatar', array_merge($avatars, array($md5sum => $avatar)));
return $avatar;
}
/**
......
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