diff --git a/admin/settings/users.php b/admin/settings/users.php
index cade4ee..cced89e 100644
--- a/admin/settings/users.php
+++ b/admin/settings/users.php
@@ -131,6 +131,8 @@ if ($hassiteconfig
$temp->add(new admin_setting_configmulticheckbox('extrauserselectorfields',
get_string('extrauserselectorfields', 'admin'), get_string('configextrauserselectorfields', 'admin'), array('email' => '1'),
array('email' => get_string('email'), 'idnumber' => get_string('idnumber'), 'username' => get_string('username'), )));
+
+ $temp->add(new admin_setting_configselect('enablegravatar', get_string('enablegravatar', 'admin'), get_string('configenablegravatar', 'admin'), 0, array(0 => get_string('gravatardontshowany'), 1 => get_string('gravatarshowbydefault'), 2 => get_string('gravatarletuserdecide'))));
}
$ADMIN->add('roles', $temp);
diff --git a/lang/en/admin.php b/lang/en/admin.php
index ed2e235..e795d0b 100755
--- a/lang/en/admin.php
+++ b/lang/en/admin.php
@@ -193,6 +193,7 @@ $string['configenablecalendarexport'] = 'Enable exporting or subscribing to cale
$string['configenablecomments'] = 'Enable comments';
$string['configenablecourserequests'] = 'This will allow any user to request a course be created.';
$string['configenableglobalsearch'] = 'This setting enables global text searching in resources and activities, it is not compatible with PHP 4.';
+$string['configenablegravatar'] = 'This setting will add an option to the "edit profile" page to allow the user to display a Gravatar picture. If a user has not uploaded a profile picture, Moodle will try to display a Gravatar picture for that user. If no Gravatar picture is found, the default profile picture is displayed. See http://www.gravatar.com/ for more information.';
$string['configenablegroupmembersonly'] = 'If enabled, access to activities can be restricted to group members only. This may result in an increased server load. In addition, gradebook categories must be set up in a certain way to ensure that activities are hidden from non-group members.';
$string['configenablehtmlpurifier'] = 'Use HTML Purifier instead of KSES for cleaning of untrusted text. HTML Purifier is actively developed and is believed to be more secure, but it is more resource intensive. Expect minor visual differences in the resulting html code. Please note that embed and object tags can not be enabled, MathML tags and old lang tags are not supported.';
$string['configenablerssfeeds'] = 'This switch will enable RSS feeds from across the site. To actually see any change you will need to enable RSS feeds in the individual modules too - go to the Modules settings under Admin Configuration.';
@@ -466,6 +467,7 @@ $string['enablecalendarexport'] = 'Enable calendar export';
$string['enablecomments'] = 'Enable comments';
$string['enablecourserequests'] = 'Enable course requests';
$string['enableglobalsearch'] = 'Enable global search';
+$string['enablegravatar'] = 'Enable Gravatar for profile pictures';
$string['enablegroupmembersonly'] = 'Enable group members only';
$string['enablehtmlpurifier'] = 'Enable HTML Purifier';
$string['enablerecordcache'] = 'Enable record cache';
diff --git a/lang/en/moodle.php b/lang/en/moodle.php
index 30a7769..517a3d7 100644
--- a/lang/en/moodle.php
+++ b/lang/en/moodle.php
@@ -750,6 +750,10 @@ See the Moodle License information page for full details:
http://docs.moodle.org/en/License';
$string['grade'] = 'Grade';
$string['grades'] = 'Grades';
+$string['gravatarbeingused'] = 'Your Gravatar picture is currently being used (if available). You can override this by uploading a different picture below.';
+$string['gravatardontshowany'] = 'NO, don\'t show any Gravatar pictures';
+$string['gravatarshowbydefault'] = 'YES, show them by default';
+$string['gravatarletuserdecide'] = 'YES, but don\'t them by default (let the user decide)';
$string['group'] = 'Group';
$string['groupadd'] = 'Add new group';
$string['groupaddusers'] = 'Add selected to group';
@@ -1689,6 +1693,7 @@ $string['used'] = 'Used';
$string['usedinnplaces'] = 'Used in {$a} places';
$string['useformaintheme'] = 'Use for modern browsers';
$string['useforlegacytheme'] = 'Use for old browsers';
+$string['usegravatar'] = 'Use Gravatar picture (if available)';
$string['usemessageform'] = 'or use the form below to send a message to the selected students';
$string['user'] = 'User';
$string['userconfirmed'] = 'Confirmed {$a}';
diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php
index df49641..7dea165 100644
--- a/lib/outputrenderers.php
+++ b/lib/outputrenderers.php
@@ -1765,12 +1765,16 @@ class core_renderer extends renderer_base {
$usercontext = get_context_instance(CONTEXT_USER, $user->id);
$src = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', $file);
- } else if ($user->picture == 2) {
- //TODO: gravatar user icon support
-
} else { // Print default user pictures (use theme version if available)
$class .= ' defaultuserpic';
$src = $this->pix_url('u/' . $file);
+ if (isset($CFG->enablegravatar)
+ && ($CFG->enablegravatar == 1
+ || ($CFG->enablegravatar == 2 && $user->picture == 2))
+ ) {
+ // Display Gravatar picture (w/ fallback to default user picture)
+ $src = 'http://www.gravatar.com/avatar.php?gravatar_id='.md5(strtolower($user->email)).'&default='.urlencode($src).'&size='.$size;
+ }
}
$attributes = array('src'=>$src, 'alt'=>$alt, 'class'=>$class, 'width'=>$size, 'height'=>$size);
diff --git a/user/edit_form.php b/user/edit_form.php
index bb529d9..5d338d2 100644
--- a/user/edit_form.php
+++ b/user/edit_form.php
@@ -77,6 +77,9 @@ class user_edit_form extends moodleform {
$image_el =& $mform->getElement('currentpicture');
if ($user and $user->picture) {
$image_el->setValue($OUTPUT->user_picture($user, array('courseid'=>SITEID, 'size'=>64)));
+ } else if (isset($CFG->enablegravatar) && $CFG->enablegravatar == 1) {
+ // provide an explanation when Gravatar images are being used by default
+ $image_el->setValue(get_string('gravatarbeingused'));
} else {
$image_el->setValue(get_string('none'));
}
diff --git a/user/editadvanced_form.php b/user/editadvanced_form.php
index 95483f4..8e8bcd1 100644
--- a/user/editadvanced_form.php
+++ b/user/editadvanced_form.php
@@ -104,6 +104,9 @@ class user_editadvanced_form extends moodleform {
$image_el =& $mform->getElement('currentpicture');
if ($user and $user->picture) {
$image_el->setValue($OUTPUT->user_picture($user, array('courseid'=>SITEID)));
+ } else if (isset($CFG->enablegravatar) && $CFG->enablegravatar == 1) {
+ // provide an explanation when Gravatar images are being used by default
+ $image_el->setValue(get_string('gravatarbeingused'));
} else {
$image_el->setValue(get_string('none'));
}
diff --git a/user/editlib.php b/user/editlib.php
index 3a95e92..29548bb 100644
--- a/user/editlib.php
+++ b/user/editlib.php
@@ -34,7 +34,7 @@ function useredit_update_user_preference($usernew) {
}
function useredit_update_picture(&$usernew, $userform) {
- global $CFG, $DB;
+ global $CFG, $DB, $USER;
require_once("$CFG->libdir/gdlib.php");
$fs = get_file_storage();
@@ -44,11 +44,24 @@ function useredit_update_picture(&$usernew, $userform) {
$fs->delete_area_files($context->id, 'user', 'icon'); // drop all areas
$DB->set_field('user', 'picture', 0, array('id'=>$usernew->id));
- } else if ($iconfile = $userform->save_temp_file('imagefile')) {
+ } else if (isset($usernew->imagefile) && $iconfile = $userform->save_temp_file('imagefile')) {
if (process_new_icon($context, 'user', 'icon', 0, $iconfile)) {
$DB->set_field('user', 'picture', 1, array('id'=>$usernew->id));
}
@unlink($iconfile);
+ } else if (isset($CFG->enablegravatar) && $CFG->enablegravatar == 2
+ && isset($usernew->usegravatar) && $usernew->usegravatar
+ ) {
+ // They're not using Gravatar, but want to
+ $DB->set_field('user', 'picture', 2, array('id'=>$usernew->id));
+ } else if (empty($usernew->usegravatar) && $USER->picture == 2) {
+ // They're using Gravatar, but want to switch back
+ if ($fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png')) {
+ // Attempt to switch back to the picture they were using before
+ $DB->set_field('user', 'picture', 1, array('id'=>$usernew->id));
+ } else {
+ $DB->set_field('user', 'picture', 0, array('id'=>$usernew->id));
+ }
}
}
@@ -243,15 +256,26 @@ function useredit_shared_definition(&$mform, $editoroptions = null) {
$mform->addElement('static', 'currentpicture', get_string('currentpicture'));
- $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
- $mform->setDefault('deletepicture', 0);
+ if ($USER->picture == 1) {
+ // it only makes sense to display this checkbox if they've actually uploaded a picture
+ $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
+ $mform->setDefault('deletepicture', 0);
+ }
- $mform->addElement('filepicker', 'imagefile', get_string('newpicture'));
- $mform->addHelpButton('imagefile', 'newpicture');
+ if (empty($CFG->enablegravatar) || !($CFG->enablegravatar == 2 && $USER->picture == 2)) {
+ $mform->addElement('filepicker', 'imagefile', get_string('newpicture'));
+ $mform->addHelpButton('imagefile', 'newpicture');
+ }
$mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
$mform->setType('imagealt', PARAM_MULTILANG);
+ if (isset($CFG->enablegravatar) && $CFG->enablegravatar == 2) {
+ // display this checkbox when Gravatar is available but disabled by default
+ $mform->addElement('checkbox', 'usegravatar', get_string('usegravatar'));
+ $mform->setDefault('usegravatar', $USER->picture == 2 ? 1 : 0);
+ }
+
}
if (!empty($CFG->usetags)) {