Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-35669 gravatar Provide default image URL to Gravatar

  • Loading branch information...
commit 30c9794aec9bed5f754b62905adf0fb62dcfaffc 1 parent 4891199
Michael Aherne authored stronk7 committed
View
1  admin/settings/users.php
@@ -150,6 +150,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
@@ -551,6 +551,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));
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.