/** * Return profile icon url for a user. Use this to quickly get a url * when you already have a bunch of user records with profileicon id & * email address. * * Avoids reloading the 'no user photo' image for each user separately * when we know they have no profile icon, and avoids the redirect to * gravatar. */ function profile_icon_url($user, $maxwidth = 40, $maxheight = 40) { if (is_array($user)) { $user = (object) $user; } if (!property_exists($user, 'profileicon') || !property_exists($user, 'email')) { throw new SystemException('profile_icon_url requires a user with profileicon & email properties'); } $thumb = get_config('wwwroot') . 'thumb.php'; $sizeparams = 'maxwidth=' . $maxwidth . '&maxheight=' . $maxheight; $notfound = $thumb . '?type=profileiconbyid&' . $sizeparams . '&id=0'; if (!empty($user->profileicon)) { return $thumb . '?type=profileiconbyid&' . $sizeparams . '&id=' . $user->profileicon; } else { if (get_config('remoteavatars')) { return remote_avatar($user->email, array('maxw' => $maxwidth, 'maxh' => $maxheight), $notfound); } } return $notfound; }
define('MENUITEM', 'content/profileicons'); define('SECTION_PLUGINTYPE', 'artefact'); define('SECTION_PLUGINNAME', 'file'); define('SECTION_PAGE', 'profileicons'); require dirname(dirname(dirname(__FILE__))) . '/init.php'; define('TITLE', get_string('profileicons', 'artefact.file')); $settingsform = new Pieform(array('name' => 'settings', 'renderer' => 'oneline', 'autofocus' => false, 'presubmitcallback' => '', 'elements' => array('default' => array('type' => 'submit', 'value' => get_string('Default', 'artefact.file')), 'delete' => array('type' => 'submit', 'value' => get_string('Delete', 'artefact.file'))))); $uploadform = pieform(array('name' => 'upload', 'class' => 'form-upload', 'jsform' => true, 'presubmitcallback' => 'preSubmit', 'postsubmitcallback' => 'postSubmit', 'plugintype' => 'artefact', 'pluginname' => 'file', 'elements' => array('file' => array('type' => 'file', 'title' => get_string('profileicon', 'artefact.file'), 'rules' => array('required' => true), 'maxfilesize' => get_max_upload_size(false)), 'title' => array('type' => 'text', 'title' => get_string('imagetitle', 'artefact.file')), 'submit' => array('type' => 'submit', 'class' => 'btn-success', 'value' => get_string('upload'))))); $strnoimagesfound = json_encode(get_string('noimagesfound', 'artefact.file')); $struploadingfile = json_encode(get_string('uploadingfile', 'artefact.file')); $wwwroot = get_config('wwwroot'); $notfound = $THEME->get_image_url('no_userphoto'); if (!get_config('remoteavatars')) { $ravatar = $notfound; } else { $ravatar = remote_avatar($USER->get('email'), array('maxw' => '100', 'maxh' => '100'), $notfound); } $profileiconattachedtoportfolioitems = json_encode(get_string('profileiconattachedtoportfolioitems', 'artefact.file')); $profileiconappearsinviews = json_encode(get_string('profileiconappearsinviews', 'artefact.file')); $profileiconappearsinskins = json_encode(get_string('profileiconappearsinskins', 'artefact.file')); $confirmdeletefile = json_encode(get_string('confirmdeletefile', 'artefact.file')); $setdefault = json_encode(get_string('setdefault', 'artefact.file')); $markfordeletion = json_encode(get_string('markfordeletion', 'artefact.file')); $IJS = <<<EOF formchangemanager.add('settings'); var profileiconschecker = formchangemanager.find('settings'); var table = new TableRenderer( 'profileicons', 'profileicons.json.php',
/** * Return the remote avatar associated to the email. * If the avatar does not exist, return anonymous avatar * * @param string $email Email address of the user * @param mixed $size Size of the image * @returns string $url The remote avatar URL */ function remote_avatar_url($email, $size) { global $THEME; $s = 100; $newsize = image_get_new_dimensions($s, $s, $size); if ($newsize) { $s = min($newsize['w'], $newsize['h']); } // Available sizes of the 'no_userphoto' image: $allowedsizes = array(16, 20, 25, 40, 50, 60, 100); if (!in_array($s, $allowedsizes)) { log_warn('remote_avatar_url: size should be in (' . join(', ', $allowedsizes) . ')'); } else { $s = 40; } $notfound = $THEME->get_image_url('no_userphoto' . $s); if (!empty($email) && get_config('remoteavatars')) { return remote_avatar($email, $s, $notfound); } return $notfound; }
$maxage = 604800; // 1 week } else { $maxage = 600; // 10 minutes } header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $maxage) . ' GMT'); header('Cache-Control: max-age=' . $maxage); header('Pragma: public'); readfile($path); exit; } } } // Look for an appropriate image on gravatar.com if ($useremail and $gravatarurl = remote_avatar($useremail, $size, $notfound)) { redirect($gravatarurl); } // We couldn't find an image for this user. Attempt to use the 'no user // photo' image for the current theme // We can cache such images $maxage = 604800; // 1 week if ($earlyexpiry) { $maxage = 600; // 10 minutes } header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $maxage) . ' GMT'); header('Cache-Control: max-age=' . $maxage); header('Pragma: public'); // NOTE: the institutional admin branch allows the theme to be locked