Skip to content
Browse files

Merge branch 'MDL-35669-master-2' of git://github.com/micaherne/moodle

  • Loading branch information...
2 parents cf45206 + f127b1a commit 1203b6ea052d96941f18abd55d36642efa96d51c @stronk7 stronk7 committed Oct 1, 2012
Showing with 18 additions and 2 deletions.
  1. +1 −0 admin/settings/users.php
  2. +2 −0 lang/en/admin.php
  3. +15 −2 lib/outputcomponents.php
View
1 admin/settings/users.php
@@ -151,6 +151,7 @@
'institution' => new lang_string('institution'),
)));
$temp->add(new admin_setting_configcheckbox('enablegravatar', new lang_string('enablegravatar', 'admin'), new lang_string('enablegravatar_help', 'admin'), 0));
+ $temp->add(new admin_setting_configtext('gravatardefaulturl', new lang_string('gravatardefaulturl', 'admin'), new lang_string('gravatardefaulturl_help', 'admin'), 'mm'));
}
$ADMIN->add('roles', $temp);
View
2 lang/en/admin.php
@@ -553,6 +553,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.';
View
17 lib/outputcomponents.php
@@ -384,12 +384,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) {
- return new moodle_url("https://secure.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $defaulturl->out(false)));
+ return new moodle_url("https://secure.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $gravatardefault));
} else {
- return new moodle_url("http://www.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $defaulturl->out(false)));
+ return new moodle_url("http://www.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $gravatardefault));
}
}

0 comments on commit 1203b6e

Please sign in to comment.
Something went wrong with that request. Please try again.