Commit e3cd08c6 authored by Aaron Wells's avatar Aaron Wells Committed by Robert Lyon

Making profile_icon_url()'s validation a little more logical

Bug 1308294: The code doesn't *really* need profileicon or email,
because it can always fall back to showing the anonymous user icon.
However, the lack of profileicon and email fields can indicating
a coding problem, so we should show a warning if they're missing.

Change-Id: I9926b7a4457049ef097e16d7999f109a623f2644
parent 626fe28a
......@@ -2492,6 +2492,12 @@ function install_system_dashboard_view() {
* Avoids reloading the 'no user photo' image for each user separately
* when we know they have no profile icon, and avoids the redirect to
* gravatar.
* @param int|object|array $user A user ID, user object, or user data array. If an
* object, should contain profileicon or email attributes, or a user ID.
* @param int $maxwidth
* @param int $maxheight
* @return bool|string The URL of the image or FALSE if none was found
function profile_icon_url($user, $maxwidth=40, $maxheight=40) {
......@@ -2501,12 +2507,19 @@ function profile_icon_url($user, $maxwidth=40, $maxheight=40) {
$user = get_user_for_display($user);
if (!property_exists($user, 'profileicon') || !property_exists($user, 'email')) {
if (!is_numeric($user->id)) {
throw new SystemException('profile_icon_url requires a user with profileicon & email properties');
// If we were originally passed a $user that was lacking profileicon and email,
// get_user_for_display() usually won't have found it for us. So we should try
// to fill that in now, and then cache it for later calls.
if (!isset($user->profileicon) && !isset($user->email)) {
if (!isset($user->id) || !is_numeric($user->id)) {
// No data. We'll just show the anonymous icon, but log a warning message for the devs.
log_debug("profile_icon_url was passed a user object without a numeric id, a profileicon, or an email address. This is probably a coding error.");
else {
$user = get_record('usr', 'id', $user->id, null, null, null, null, 'id, profileicon, email');
// Cache this for subsequent calls
$user = get_user_for_display($user);
log_debug("profile_icon_url was passed a user without profileicon & email properties");
$user = get_record('usr', 'id', $user->id);
// Available sizes of the 'no_userphoto' image:
......@@ -2522,7 +2535,7 @@ function profile_icon_url($user, $maxwidth=40, $maxheight=40) {
return $thumb . '?type=profileiconbyid&' . $sizeparams . '&id=' . $user->profileicon;
return anonymous_icon_url($maxwidth, $maxheight, $user->email);
return anonymous_icon_url($maxwidth, $maxheight, (!empty($user->email) ? $user->email : null));
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