Skip to content

Commit

Permalink
MDL-35669 gravatar Provide default image URL to Gravatar
Browse files Browse the repository at this point in the history
Conflicts:
	admin/settings/users.php
	lib/outputcomponents.php
  • Loading branch information
Michael Aherne authored and stronk7 committed Oct 1, 2012
1 parent 7697512 commit 60bbf98
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions admin/settings/users.php
Expand Up @@ -150,6 +150,7 @@
'institution' => get_string('institution'),
)));
$temp->add(new admin_setting_configcheckbox('enablegravatar', get_string('enablegravatar', 'admin'), get_string('enablegravatar_help', 'admin'), 0));
$temp->add(new admin_setting_configtext('gravatardefaulturl', get_string('gravatardefaulturl', 'admin'), get_string('gravatardefaulturl_help', 'admin'), 'mm'));
}

$ADMIN->add('roles', $temp);
Expand Down
2 changes: 2 additions & 0 deletions lang/en/admin.php
Expand Up @@ -550,6 +550,8 @@
$string['gotofirst'] = 'Go to first missing string';
$string['gradebook'] = 'Gradebook';
$string['gradebookroles'] = 'Graded roles';
$string['gravatardefaulturl'] = 'Gravatar default image URL';
$string['gravatardefaulturl_help'] = 'Gravatar needs a default image to display if it is unable to find a picture for a given user. Provide a full URL for an image. If you leave this setting empty, Moodle will attempt to use the most appropriate default image for the page you are viewing. Note also that Gravatar has a number of codes which can be used to <a href="https://en.gravatar.com/site/implement/images/#default-image">generate default images</a>.';
$string['gradeexport'] = 'Primary grade export methods';
$string['guestroleid'] = 'Role for guest';
$string['guestroleid_help'] = 'This role is automatically assigned to the guest user. It is also temporarily assigned to not enrolled users that enter the course via guest enrolment plugin.';
Expand Down
17 changes: 15 additions & 2 deletions lib/outputcomponents.php
Expand Up @@ -329,12 +329,25 @@ public function get_url(moodle_page $page, renderer_base $renderer = null) {
// Hash the users email address
$md5 = md5(strtolower(trim($this->user->email)));
// Build a gravatar URL with what we know.

// Find the best default image URL we can (MDL-35669)
if (empty($CFG->gravatardefaulturl)) {
$absoluteimagepath = $page->theme->resolve_image_location('u/'.$filename, 'core');
if (strpos($absoluteimagepath, $CFG->dirroot) === 0) {
$gravatardefault = $CFG->wwwroot . substr($absoluteimagepath, strlen($CFG->dirroot));
} else {
$gravatardefault = $CFG->wwwroot . '/pix/u/' . $filename . '.png';
}
} else {
$gravatardefault = $CFG->gravatardefaulturl;
}

// If the currently requested page is https then we'll return an
// https gravatar page.
if (strpos($CFG->httpswwwroot, 'https:') === 0) {
$imageurl = new moodle_url("https://secure.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $imageurl->out(false)));
$imageurl = new moodle_url("https://secure.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $gravatardefault));
} else {
$imageurl = new moodle_url("http://www.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $imageurl->out(false)));
$imageurl = new moodle_url("http://www.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $gravatardefault));
}
}

Expand Down

0 comments on commit 60bbf98

Please sign in to comment.