From 0ab727fb35e5ae1d8316d96c6752ee9ebec4c185 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Tue, 25 Jan 2011 11:01:17 +0100 Subject: [PATCH] MDL-26034 myprofile block cleanup --- blocks/myprofile/block_myprofile.php | 138 ++++++------------- blocks/myprofile/edit_form.php | 6 +- blocks/myprofile/lang/en/block_myprofile.php | 30 +++- blocks/myprofile/version.php | 13 +- 4 files changed, 87 insertions(+), 100 deletions(-) diff --git a/blocks/myprofile/block_myprofile.php b/blocks/myprofile/block_myprofile.php index fe03b67bfd0..73daf368d97 100644 --- a/blocks/myprofile/block_myprofile.php +++ b/blocks/myprofile/block_myprofile.php @@ -1,5 +1,4 @@ . /** - * Displays the user's profile information. + * Block displaying information about current logged-in user. + * + * This block can be used as anti cheating measure, you + * can easily check the logged-in user matches the person + * operating the computer. * - * @package blocks + * @package block + * @subpackage myprofile * @copyright 2010 Remote-Learner.net * @author Olav Jordan * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + /** - * Displays the user's profile information. + * Displays the current user's profile information. * * @copyright 2010 Remote-Learner.net * @author Olav Jordan @@ -51,8 +57,8 @@ class block_myprofile extends block_base { return $this->content; } - if (!isloggedin()){ - return ''; // Never useful unless you are logged in + if (!isloggedin() or isguestuser()) { + return ''; // Never useful unless you are logged in as real users } $this->content = new stdClass; @@ -60,169 +66,114 @@ class block_myprofile extends block_base { $this->content->footer = ''; $course = $this->page->course; - if ($PAGE->context->contextlevel == CONTEXT_USER) { - $user = $DB->get_record('user', array('id' => $PAGE->context->instanceid)); - } else { - $user = $USER; - } - - if ($course->id == SITEID) { - $coursecontext = get_context_instance(CONTEXT_SYSTEM); - } else { - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context - // Make sure they can view the course - if (!is_viewing($coursecontext)) { - return ''; - } - } - - - // TODO: clean up the following even more if (!isset($this->config->display_picture) || $this->config->display_picture == 1) { $this->content->text .= '
'; - $this->content->text .= $OUTPUT->user_picture($user, array('courseid'=>$course->id, 'size'=>'100', 'class'=>'profilepicture')); // The new class makes CSS easier + $this->content->text .= $OUTPUT->user_picture($USER, array('courseid'=>$course->id, 'size'=>'100', 'class'=>'profilepicture')); // The new class makes CSS easier $this->content->text .= '
'; } - $this->content->text .= '
'.fullname($user).'
'; + $this->content->text .= '
'.fullname($USER).'
'; if(!isset($this->config->display_country) || $this->config->display_country == 1) { $countries = get_string_manager()->get_list_of_countries(); - if (isset($countries[$user->country])) { + if (isset($countries[$USER->country])) { $this->content->text .= '
'; - $this->content->text .= get_string('country') . ': ' . $countries[$user->country]; + $this->content->text .= get_string('country') . ': ' . $countries[$USER->country]; $this->content->text .= '
'; } } if(!isset($this->config->display_city) || $this->config->display_city == 1) { $this->content->text .= '
'; - $this->content->text .= get_string('city') . ': ' . $user->city; + $this->content->text .= get_string('city') . ': ' . format_string($USER->city); $this->content->text .= '
'; } if(!isset($this->config->display_email) || $this->config->display_email == 1) { $this->content->text .= ''; } - if(!empty($this->config->display_icq) && !empty($user->icq)) { + if(!empty($this->config->display_icq) && !empty($USER->icq)) { $this->content->text .= '
'; - $this->content->text .= 'ICQ: ' . $user->icq; + $this->content->text .= 'ICQ: ' . s($USER->icq); $this->content->text .= '
'; } - if(!empty($this->config->display_skype) && !empty($user->skype)) { + if(!empty($this->config->display_skype) && !empty($USER->skype)) { $this->content->text .= '
'; - $this->content->text .= 'Skype: ' . $user->skype; + $this->content->text .= 'Skype: ' . s($USER->skype); $this->content->text .= '
'; } - if(!empty($this->config->display_yahoo) && !empty($user->yahoo)) { + if(!empty($this->config->display_yahoo) && !empty($USER->yahoo)) { $this->content->text .= '
'; - $this->content->text .= 'Yahoo: ' . $user->yahoo; + $this->content->text .= 'Yahoo: ' . s($USER->yahoo); $this->content->text .= '
'; } - if(!empty($this->config->display_aim) && !empty($user->aim)) { + if(!empty($this->config->display_aim) && !empty($USER->aim)) { $this->content->text .= '
'; - $this->content->text .= 'AIM: ' . $user->aim; + $this->content->text .= 'AIM: ' . s($USER->aim); $this->content->text .= '
'; } - if(!empty($this->config->display_msn) && !empty($user->msn)) { + if(!empty($this->config->display_msn) && !empty($USER->msn)) { $this->content->text .= '
'; - $this->content->text .= 'MSN: ' . $user->msn; + $this->content->text .= 'MSN: ' . s($USER->msn); $this->content->text .= '
'; } - if(!empty($this->config->display_phone1) && !empty($user->phone1)) { + if(!empty($this->config->display_phone1) && !empty($USER->phone1)) { $this->content->text .= '
'; - $this->content->text .= get_string('phone').': ' . $user->phone1; + $this->content->text .= get_string('phone').': ' . s($USER->phone1); $this->content->text .= '
'; } - if(!empty($this->config->display_phone2) && !empty($user->phone2)) { + if(!empty($this->config->display_phone2) && !empty($USER->phone2)) { $this->content->text .= '
'; - $this->content->text .= get_string('phone').': ' . $user->phone2; + $this->content->text .= get_string('phone').': ' . s($USER->phone2); $this->content->text .= '
'; } - if(!empty($this->config->display_institution) && !empty($user->institution)) { + if(!empty($this->config->display_institution) && !empty($USER->institution)) { $this->content->text .= '
'; - $this->content->text .= $user->institution; + $this->content->text .= format_string($USER->institution); $this->content->text .= '
'; } - if(!empty($this->config->display_address) && !empty($user->address)) { + if(!empty($this->config->display_address) && !empty($USER->address)) { $this->content->text .= '
'; - $this->content->text .= $user->address; + $this->content->text .= format_string($USER->address); $this->content->text .= '
'; } - if(!empty($this->config->display_firstaccess) && !empty($user->firstaccess)) { + if(!empty($this->config->display_firstaccess) && !empty($USER->firstaccess)) { $this->content->text .= '
'; - $this->content->text .= get_string('firstaccess').': ' . userdate($user->firstaccess); + $this->content->text .= get_string('firstaccess').': ' . userdate($USER->firstaccess); $this->content->text .= '
'; } - if(!empty($this->config->display_lastaccess) && !empty($user->lastaccess)) { + if(!empty($this->config->display_lastaccess) && !empty($USER->lastaccess)) { $this->content->text .= '
'; - $this->content->text .= get_string('lastaccess').': ' . userdate($user->lastaccess); + $this->content->text .= get_string('lastaccess').': ' . userdate($USER->lastaccess); $this->content->text .= '
'; } - if(!empty($this->config->display_currentlogin) && !empty($user->currentlogin)) { + if(!empty($this->config->display_currentlogin) && !empty($USER->currentlogin)) { $this->content->text .= '
'; - $this->content->text .= get_string('login').': ' . userdate($user->currentlogin); + $this->content->text .= get_string('login').': ' . userdate($USER->currentlogin); $this->content->text .= '
'; } - if(!empty($this->config->display_lastip) && !empty($user->lastip)) { + if(!empty($this->config->display_lastip) && !empty($USER->lastip)) { $this->content->text .= '
'; - $this->content->text .= 'IP: ' . $user->lastip; - $this->content->text .= '
'; - } - - $editscript = NULL; - if (isguestuser($user)) { - // guest account can not be edited - - } else if (is_mnet_remote_user($user)) { - // cannot edit remote users - - } else if (isguestuser() or !isloggedin()) { - // guests and not logged in can not edit own profile - - } else if ($USER->id == $user->id) { - $systemcontext = get_context_instance(CONTEXT_SYSTEM); - if (has_capability('moodle/user:update', $systemcontext)) { - $editscript = '/user/editadvanced.php'; - } else if (has_capability('moodle/user:editownprofile', $systemcontext)) { - $editscript = '/user/edit.php'; - } - - } else { - $systemcontext = get_context_instance(CONTEXT_SYSTEM); - $personalcontext = get_context_instance(CONTEXT_USER, $user->id); - if (has_capability('moodle/user:update', $systemcontext) and !is_primary_admin($user->id)){ - $editscript = '/user/editadvanced.php'; - } else if (has_capability('moodle/user:editprofile', $personalcontext) and !is_primary_admin($user->id)){ - //teachers, parents, etc. - $editscript = '/user/edit.php'; - } - } - - - if ($editscript) { - $this->content->text .= '
'; - $this->content->text .= ''.get_string('editmyprofile').''; + $this->content->text .= 'IP: ' . $USER->lastip; $this->content->text .= '
'; } - return $this->content; } @@ -304,4 +255,3 @@ class block_myprofile extends block_base { } } -?> diff --git a/blocks/myprofile/edit_form.php b/blocks/myprofile/edit_form.php index 4605853bf03..4500c0e9ae6 100644 --- a/blocks/myprofile/edit_form.php +++ b/blocks/myprofile/edit_form.php @@ -1,5 +1,4 @@ . +defined('MOODLE_INTERNAL') || die(); + /** * Form for editing profile block settings * - * @package blocks + * @package block + * @subpackage myprofile * @copyright 2010 Remote-Learner.net * @author Olav Jordan * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/blocks/myprofile/lang/en/block_myprofile.php b/blocks/myprofile/lang/en/block_myprofile.php index 09c256d9362..74dea912362 100644 --- a/blocks/myprofile/lang/en/block_myprofile.php +++ b/blocks/myprofile/lang/en/block_myprofile.php @@ -1,6 +1,31 @@ . + +/** + * Strings for component 'block_myprofile', language 'en', branch 'MOODLE_20_STABLE' + * + * @package block + * @subpackage myprofile + * @copyright 2010 Remote-Learner.net + * @author Olav Jordan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['pluginname'] = 'Logged in user'; +$string['myprofile_settings'] = 'Visible user information'; $string['contentsettings'] = 'Display settings for content region'; $string['display_picture'] = 'Display picture'; $string['display_country'] = 'Display country'; @@ -20,4 +45,3 @@ $string['display_firstaccess'] = 'Display first access'; $string['display_lastaccess'] = 'Display last access'; $string['display_currentlogin'] = 'Display current login'; $string['display_lastip'] = 'Display last IP'; -?> diff --git a/blocks/myprofile/version.php b/blocks/myprofile/version.php index fa4218c7fc1..b845d6eeb5c 100644 --- a/blocks/myprofile/version.php +++ b/blocks/myprofile/version.php @@ -1,5 +1,4 @@ . +/** + * Current user info block. + * + * @package block + * @subpackage myprofile + * @copyright 2010 Remote-Learner.net + * @author Olav Jordan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + $plugin->version = 2009123100; -- 2.43.0