--- 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); --- 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'] = 'This setting enables group members only feature. Please note it is incresing your server load and it is necessary to use some advanced tricks in the gradebook.'; $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'; --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -751,6 +751,9 @@ See the Moodle License information page for full details: http://docs.moodle.org/en/License'; $string['grade'] = 'Grade'; $string['grades'] = 'Grades'; +$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'; @@ -1691,6 +1694,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}'; --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1740,12 +1740,13 @@ 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 (!empty($CFG->enablegravatar) && $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); --- 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,6 +44,19 @@ 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 (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)); + } + } else if ($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)); @@ -252,6 +265,17 @@ function useredit_shared_definition(&$mform, $editoroptions = null) { $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"'); $mform->setType('imagealt', PARAM_MULTILANG); + if (!empty($CFG->enablegravatar)) { + $mform->addElement('checkbox', 'usegravatar', get_string('usegravatar')); + if ($CFG->enablegravatar == 1) { + // When we're showing them by default, check the box if they have NOT uploaded a picture. + $mform->setDefault('usegravatar', $USER->picture == 0 ? 1 : 0); + } else if ($CFG->enablegravatar == 2) { + // When we're letting them choose, check the box if they're already showing one. + $mform->setDefault('usegravatar', $USER->picture == 2 ? 1 : 0); + } + } + } if (!empty($CFG->usetags)) {