[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Public Profile -- a user's public profile page 19 * 20 * - each user can currently have their own page (cloned from system and then customised) 21 * - users can add any blocks they want 22 * - the administrators can define a default site public profile for users who have 23 * not created their own public profile 24 * 25 * This script implements the user's view of the public profile, and allows editing 26 * of the public profile. 27 * 28 * @package core_user 29 * @copyright 2010 Remote-Learner.net 30 * @author Hubert Chathi <[email protected]> 31 * @author Olav Jordan <[email protected]> 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 35 require_once(dirname(__FILE__) . '/../config.php'); 36 require_once($CFG->dirroot . '/my/lib.php'); 37 require_once($CFG->dirroot . '/tag/lib.php'); 38 require_once($CFG->dirroot . '/user/profile/lib.php'); 39 require_once($CFG->libdir.'/filelib.php'); 40 41 $userid = optional_param('id', 0, PARAM_INT); 42 $edit = optional_param('edit', null, PARAM_BOOL); // Turn editing on and off. 43 $reset = optional_param('reset', null, PARAM_BOOL); 44 $showallcourses = optional_param('showallcourses', 0, PARAM_INT); 45 46 $PAGE->set_url('/user/profile.php', array('id' => $userid)); 47 48 if (!empty($CFG->forceloginforprofiles)) { 49 require_login(); 50 if (isguestuser()) { 51 $SESSION->wantsurl = $PAGE->url->out(false); 52 53 $PAGE->set_context(context_system::instance()); 54 echo $OUTPUT->header(); 55 echo $OUTPUT->confirm(get_string('guestcantaccessprofiles', 'error'), 56 get_login_url(), 57 $CFG->wwwroot); 58 echo $OUTPUT->footer(); 59 die; 60 } 61 } else if (!empty($CFG->forcelogin)) { 62 require_login(); 63 } 64 65 $userid = $userid ? $userid : $USER->id; // Owner of the page. 66 if ((!$user = $DB->get_record('user', array('id' => $userid))) || ($user->deleted)) { 67 $PAGE->set_context(context_system::instance()); 68 echo $OUTPUT->header(); 69 if (!$user) { 70 echo $OUTPUT->notification(get_string('invaliduser', 'error')); 71 } else { 72 echo $OUTPUT->notification(get_string('userdeleted')); 73 } 74 echo $OUTPUT->footer(); 75 die; 76 } 77 78 $currentuser = ($user->id == $USER->id); 79 $context = $usercontext = context_user::instance($userid, MUST_EXIST); 80 81 if (!$currentuser && 82 !empty($CFG->forceloginforprofiles) && 83 !has_capability('moodle/user:viewdetails', $context) && 84 !has_coursecontact_role($userid)) { 85 86 // Course managers can be browsed at site level. If not forceloginforprofiles, allow access (bug #4366). 87 $struser = get_string('user'); 88 $PAGE->set_context(context_system::instance()); 89 $PAGE->set_title("$SITE->shortname: $struser"); // Do not leak the name. 90 $PAGE->set_heading("$SITE->shortname: $struser"); 91 $PAGE->set_url('/user/profile.php', array('id' => $userid)); 92 $PAGE->navbar->add($struser); 93 echo $OUTPUT->header(); 94 echo $OUTPUT->notification(get_string('usernotavailable', 'error')); 95 echo $OUTPUT->footer(); 96 exit; 97 } 98 99 // Get the profile page. Should always return something unless the database is broken. 100 if (!$currentpage = my_get_page($userid, MY_PAGE_PUBLIC)) { 101 print_error('mymoodlesetup'); 102 } 103 104 if (!$currentpage->userid) { 105 $context = context_system::instance(); // A trick so that we even see non-sticky blocks. 106 } 107 108 $PAGE->set_context($context); 109 $PAGE->set_pagelayout('mypublic'); 110 $PAGE->set_pagetype('user-profile'); 111 112 // Set up block editing capabilities. 113 if (isguestuser()) { // Guests can never edit their profile. 114 $USER->editing = $edit = 0; // Just in case. 115 $PAGE->set_blocks_editing_capability('moodle/my:configsyspages'); // unlikely :). 116 } else { 117 if ($currentuser) { 118 $PAGE->set_blocks_editing_capability('moodle/user:manageownblocks'); 119 } else { 120 $PAGE->set_blocks_editing_capability('moodle/user:manageblocks'); 121 } 122 } 123 124 if (has_capability('moodle/user:viewhiddendetails', $context)) { 125 $hiddenfields = array(); 126 } else { 127 $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); 128 } 129 130 if (has_capability('moodle/site:viewuseridentity', $context)) { 131 $identityfields = array_flip(explode(',', $CFG->showuseridentity)); 132 } else { 133 $identityfields = array(); 134 } 135 136 // Start setting up the page. 137 $strpublicprofile = get_string('publicprofile'); 138 139 $PAGE->blocks->add_region('content'); 140 $PAGE->set_subpage($currentpage->id); 141 $PAGE->set_title(fullname($user).": $strpublicprofile"); 142 $PAGE->set_heading(fullname($user).": $strpublicprofile"); 143 144 if (!$currentuser) { 145 $PAGE->navigation->extend_for_user($user); 146 if ($node = $PAGE->settingsnav->get('userviewingsettings'.$user->id)) { 147 $node->forceopen = true; 148 } 149 } else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) { 150 $node->forceopen = true; 151 } 152 if ($node = $PAGE->settingsnav->get('root')) { 153 $node->forceopen = false; 154 } 155 156 157 // Toggle the editing state and switches. 158 if ($PAGE->user_allowed_editing()) { 159 if ($reset !== null) { 160 if (!is_null($userid)) { 161 if (!$currentpage = my_reset_page($userid, MY_PAGE_PUBLIC, 'user-profile')) { 162 print_error('reseterror', 'my'); 163 } 164 redirect(new moodle_url('/user/profile.php', array('id' => $userid))); 165 } 166 } else if ($edit !== null) { // Editing state was specified. 167 $USER->editing = $edit; // Change editing state. 168 if (!$currentpage->userid && $edit) { 169 // If we are viewing a system page as ordinary user, and the user turns 170 // editing on, copy the system pages as new user pages, and get the 171 // new page record. 172 if (!$currentpage = my_copy_page($userid, MY_PAGE_PUBLIC, 'user-profile')) { 173 print_error('mymoodlesetup'); 174 } 175 $PAGE->set_context($usercontext); 176 $PAGE->set_subpage($currentpage->id); 177 } 178 } else { // Editing state is in session. 179 if ($currentpage->userid) { // It's a page we can edit, so load from session. 180 if (!empty($USER->editing)) { 181 $edit = 1; 182 } else { 183 $edit = 0; 184 } 185 } else { // It's a system page and they are not allowed to edit system pages. 186 $USER->editing = $edit = 0; // Disable editing completely, just to be safe. 187 } 188 } 189 190 // Add button for editing page. 191 $params = array('edit' => !$edit, 'id' => $userid); 192 193 $resetbutton = ''; 194 $resetstring = get_string('resetpage', 'my'); 195 $reseturl = new moodle_url("$CFG->wwwroot/user/profile.php", array('edit' => 1, 'reset' => 1, 'id' => $userid)); 196 197 if (!$currentpage->userid) { 198 // Viewing a system page -- let the user customise it. 199 $editstring = get_string('updatemymoodleon'); 200 $params['edit'] = 1; 201 } else if (empty($edit)) { 202 $editstring = get_string('updatemymoodleon'); 203 $resetbutton = $OUTPUT->single_button($reseturl, $resetstring); 204 } else { 205 $editstring = get_string('updatemymoodleoff'); 206 $resetbutton = $OUTPUT->single_button($reseturl, $resetstring); 207 } 208 209 $url = new moodle_url("$CFG->wwwroot/user/profile.php", $params); 210 $button = $OUTPUT->single_button($url, $editstring); 211 $PAGE->set_button($resetbutton . $button); 212 213 } else { 214 $USER->editing = $edit = 0; 215 } 216 217 // HACK WARNING! This loads up all this page's blocks in the system context. 218 if ($currentpage->userid == 0) { 219 $CFG->blockmanagerclass = 'my_syspage_block_manager'; 220 } 221 222 // Trigger a user profile viewed event. 223 $event = \core\event\user_profile_viewed::create(array( 224 'objectid' => $user->id, 225 'relateduserid' => $user->id, 226 'context' => $usercontext 227 )); 228 $event->add_record_snapshot('user', $user); 229 $event->trigger(); 230 231 // TODO WORK OUT WHERE THE NAV BAR IS! 232 echo $OUTPUT->header(); 233 echo '<div class="userprofile">'; 234 235 236 // Print the standard content of this page, the basic profile info. 237 echo $OUTPUT->heading(fullname($user)); 238 239 if (is_mnet_remote_user($user)) { 240 $sql = "SELECT h.id, h.name, h.wwwroot, 241 a.name as application, a.display_name 242 FROM {mnet_host} h, {mnet_application} a 243 WHERE h.id = ? AND h.applicationid = a.id"; 244 245 $remotehost = $DB->get_record_sql($sql, array($user->mnethostid)); 246 $a = new stdclass(); 247 $a->remotetype = $remotehost->display_name; 248 $a->remotename = $remotehost->name; 249 $a->remoteurl = $remotehost->wwwroot; 250 251 echo $OUTPUT->box(get_string('remoteuserinfo', 'mnet', $a), 'remoteuserinfo'); 252 } 253 254 echo '<div class="userprofilebox clearfix"><div class="profilepicture">'; 255 echo $OUTPUT->user_picture($user, array('size' => 100)); 256 echo '</div>'; 257 258 echo '<div class="descriptionbox"><div class="description">'; 259 // Print the description. 260 if ($user->description && !isset($hiddenfields['description'])) { 261 if (!empty($CFG->profilesforenrolledusersonly) && !$currentuser && 262 !$DB->record_exists('role_assignments', array('userid' => $user->id))) { 263 echo get_string('profilenotshown', 'moodle'); 264 } else { 265 $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user', 266 'profile', null); 267 $options = array('overflowdiv' => true); 268 echo format_text($user->description, $user->descriptionformat, $options); 269 } 270 } 271 echo '</div>'; 272 273 274 // Print all the little details in a list. 275 echo html_writer::start_tag('dl', array('class' => 'list')); 276 if (!isset($hiddenfields['country']) && $user->country) { 277 echo html_writer::tag('dt', get_string('country')); 278 echo html_writer::tag('dd', get_string($user->country, 'countries')); 279 } 280 281 if (!isset($hiddenfields['city']) && $user->city) { 282 echo html_writer::tag('dt', get_string('city')); 283 echo html_writer::tag('dd', $user->city); 284 } 285 286 if (isset($identityfields['address']) && $user->address) { 287 echo html_writer::tag('dt', get_string('address')); 288 echo html_writer::tag('dd', $user->address); 289 } 290 291 if (isset($identityfields['phone1']) && $user->phone1) { 292 echo html_writer::tag('dt', get_string('phone')); 293 echo html_writer::tag('dd', $user->phone1); 294 } 295 296 if (isset($identityfields['phone2']) && $user->phone2) { 297 echo html_writer::tag('dt', get_string('phone2')); 298 echo html_writer::tag('dd', $user->phone2); 299 } 300 301 if (isset($identityfields['institution']) && $user->institution) { 302 echo html_writer::tag('dt', get_string('institution')); 303 echo html_writer::tag('dd', $user->institution); 304 } 305 306 if (isset($identityfields['department']) && $user->department) { 307 echo html_writer::tag('dt', get_string('department')); 308 echo html_writer::tag('dd', $user->department); 309 } 310 311 if (isset($identityfields['idnumber']) && $user->idnumber) { 312 echo html_writer::tag('dt', get_string('idnumber')); 313 echo html_writer::tag('dd', $user->idnumber); 314 } 315 316 if (isset($identityfields['email']) and ($currentuser 317 or $user->maildisplay == 1 318 or has_capability('moodle/course:useremail', $context) 319 or ($user->maildisplay == 2 and enrol_sharing_course($user, $USER)))) { 320 echo html_writer::tag('dt', get_string('email')); 321 echo html_writer::tag('dd', obfuscate_mailto($user->email, '')); 322 } 323 324 if ($user->url && !isset($hiddenfields['webpage'])) { 325 $url = $user->url; 326 if (strpos($user->url, '://') === false) { 327 $url = 'http://'. $url; 328 } 329 $webpageurl = new moodle_url($url); 330 echo html_writer::tag('dt', get_string('webpage')); 331 echo html_writer::tag('dd', html_writer::link($webpageurl, s($user->url))); 332 } 333 334 if ($user->icq && !isset($hiddenfields['icqnumber'])) { 335 $imurl = new moodle_url('http://web.icq.com/wwp', array('uin' => $user->icq) ); 336 $iconurl = new moodle_url('http://web.icq.com/whitepages/online', array('icq' => $user->icq, 'img' => '5')); 337 $statusicon = html_writer::tag('img', '', array('src' => $iconurl, 'class' => 'icon icon-post', 'alt' => get_string('status'))); 338 echo html_writer::tag('dt', get_string('icqnumber')); 339 echo html_writer::tag('dd', html_writer::link($imurl, s($user->icq) . $statusicon)); 340 } 341 342 if ($user->skype && !isset($hiddenfields['skypeid'])) { 343 $imurl = 'skype:'.urlencode($user->skype).'?call'; 344 $iconurl = new moodle_url('http://mystatus.skype.com/smallicon/'.urlencode($user->skype)); 345 if (is_https()) { 346 // Bad luck, skype devs are lazy to set up SSL on their servers - see MDL-37233. 347 $statusicon = ''; 348 } else { 349 $statusicon = html_writer::empty_tag('img', 350 array('src' => $iconurl, 'class' => 'icon icon-post', 'alt' => get_string('status'))); 351 } 352 echo html_writer::tag('dt', get_string('skypeid')); 353 echo html_writer::tag('dd', html_writer::link($imurl, s($user->skype) . $statusicon)); 354 } 355 if ($user->yahoo && !isset($hiddenfields['yahooid'])) { 356 $imurl = new moodle_url('http://edit.yahoo.com/config/send_webmesg', array('.target' => $user->yahoo, '.src' => 'pg')); 357 $iconurl = new moodle_url('http://opi.yahoo.com/online', array('u' => $user->yahoo, 'm' => 'g', 't' => '0')); 358 $statusicon = html_writer::tag('img', '', 359 array('src' => $iconurl, 'class' => 'iconsmall icon-post', 'alt' => get_string('status'))); 360 echo html_writer::tag('dt', get_string('yahooid')); 361 echo html_writer::tag('dd', html_writer::link($imurl, s($user->yahoo) . $statusicon)); 362 } 363 if ($user->aim && !isset($hiddenfields['aimid'])) { 364 $imurl = 'aim:goim?screenname='.urlencode($user->aim); 365 echo html_writer::tag('dt', get_string('aimid')); 366 echo html_writer::tag('dd', html_writer::link($imurl, s($user->aim))); 367 } 368 if ($user->msn && !isset($hiddenfields['msnid'])) { 369 echo html_writer::tag('dt', get_string('msnid')); 370 echo html_writer::tag('dd', s($user->msn)); 371 } 372 373 // Print the Custom User Fields. 374 profile_display_fields($user->id); 375 376 377 if (!isset($hiddenfields['mycourses'])) { 378 if ($mycourses = enrol_get_all_users_courses($user->id, true, null, 'visible DESC, sortorder ASC')) { 379 $shown = 0; 380 $courselisting = ''; 381 foreach ($mycourses as $mycourse) { 382 if ($mycourse->category) { 383 context_helper::preload_from_record($mycourse); 384 $ccontext = context_course::instance($mycourse->id); 385 $linkattributes = null; 386 if ($mycourse->visible == 0) { 387 if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) { 388 continue; 389 } 390 $linkattributes['class'] = 'dimmed'; 391 } 392 $params = array('id' => $user->id, 'course' => $mycourse->id); 393 if ($showallcourses) { 394 $params['showallcourses'] = 1; 395 } 396 $url = new moodle_url('/user/view.php', $params); 397 $courselisting .= html_writer::link($url, $ccontext->get_context_name(false), $linkattributes); 398 $courselisting .= ', '; 399 } 400 $shown++; 401 if (!$showallcourses && $shown == $CFG->navcourselimit) { 402 $url = new moodle_url('/user/profile.php', array('id' => $user->id, 'showallcourses' => 1)); 403 $courselisting .= html_writer::link($url, '...', array('title' => get_string('viewmore'))); 404 break; 405 } 406 } 407 echo html_writer::tag('dt', get_string('courseprofiles')); 408 echo html_writer::tag('dd', rtrim($courselisting, ', ')); 409 } 410 } 411 if (!isset($hiddenfields['firstaccess'])) { 412 if ($user->firstaccess) { 413 $datestring = userdate($user->firstaccess)." (".format_time(time() - $user->firstaccess).")"; 414 } else { 415 $datestring = get_string("never"); 416 } 417 echo html_writer::tag('dt', get_string('firstsiteaccess')); 418 echo html_writer::tag('dd', $datestring); 419 } 420 if (!isset($hiddenfields['lastaccess'])) { 421 if ($user->lastaccess) { 422 $datestring = userdate($user->lastaccess)." (".format_time(time() - $user->lastaccess).")"; 423 } else { 424 $datestring = get_string("never"); 425 } 426 echo html_writer::tag('dt', get_string('lastsiteaccess')); 427 echo html_writer::tag('dd', $datestring); 428 } 429 430 if (has_capability('moodle/user:viewlastip', $usercontext) && !isset($hiddenfields['lastip'])) { 431 if ($user->lastip) { 432 $iplookupurl = new moodle_url('/iplookup/index.php', array('ip' => $user->lastip, 'user' => $user->id)); 433 $ipstring = html_writer::link($iplookupurl, $user->lastip); 434 } else { 435 $ipstring = get_string("none"); 436 } 437 echo html_writer::tag('dt', get_string('lastip')); 438 echo html_writer::tag('dd', $ipstring); 439 } 440 441 // Printing tagged interests. 442 if (!empty($CFG->usetags)) { 443 if ($interests = tag_get_tags_csv('user', $user->id) ) { 444 echo html_writer::tag('dt', get_string('interests')); 445 echo html_writer::tag('dd', $interests); 446 } 447 } 448 449 if (!isset($hiddenfields['suspended'])) { 450 if ($user->suspended) { 451 echo html_writer::tag('dt', ' '); 452 echo html_writer::tag('dd', get_string('suspended', 'auth')); 453 } 454 } 455 456 require_once($CFG->libdir . '/badgeslib.php'); 457 if (!empty($CFG->enablebadges)) { 458 profile_display_badges($user->id); 459 } 460 461 echo html_writer::end_tag('dl'); 462 echo "</div></div>"; // Closing desriptionbox and userprofilebox. 463 464 echo $OUTPUT->custom_block_region('content'); 465 466 // Print messaging link if allowed. 467 if (isloggedin() && has_capability('moodle/site:sendmessage', $context) 468 && !empty($CFG->messaging) && !isguestuser() && !isguestuser($user) && ($USER->id != $user->id)) { 469 echo '<div class="messagebox">'; 470 echo '<a href="'.$CFG->wwwroot.'/message/index.php?id='.$user->id.'">'.get_string('messageselectadd').'</a>'; 471 echo '</div>'; 472 } 473 474 echo '</div>'; // Userprofile class. 475 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |