2009-10-31 22:02:05 +00:00
|
|
|
<?PHP
|
2001-11-22 06:23:56 +00:00
|
|
|
// This function fetches user pictures from the data directory
|
2002-08-09 09:09:36 +00:00
|
|
|
// Syntax: pix.php/userid/f1.jpg or pix.php/userid/f2.jpg
|
|
|
|
// OR: ?file=userid/f1.jpg or ?file=userid/f2.jpg
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2009-10-31 22:02:05 +00:00
|
|
|
// disable moodle specific debug messages and any errors in output
|
|
|
|
define('NO_DEBUG_DISPLAY', true);
|
|
|
|
|
2004-12-14 18:57:51 +00:00
|
|
|
require_once('../config.php');
|
2005-03-07 12:10:22 +00:00
|
|
|
require_once($CFG->libdir.'/filelib.php');
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2008-11-01 22:30:18 +00:00
|
|
|
if (!empty($CFG->forcelogin) and !isloggedin()) {
|
|
|
|
// protect images if login required and not logged in;
|
|
|
|
// do not use require_login() because it is expensive and not suitable here anyway
|
2009-12-16 21:50:45 +00:00
|
|
|
redirect($OUTPUT->pix_url('u/f1'));
|
2008-11-01 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-05 21:37:20 +00:00
|
|
|
$relativepath = get_file_argument();
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-12-14 18:57:51 +00:00
|
|
|
$args = explode('/', trim($relativepath, '/'));
|
2002-08-09 09:09:36 +00:00
|
|
|
|
2004-12-14 18:57:51 +00:00
|
|
|
if (count($args) == 2) {
|
|
|
|
$userid = (integer)$args[0];
|
2008-11-01 19:37:07 +00:00
|
|
|
// do not serve images of deleted users
|
|
|
|
if ($user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0, 'picture'=>1))) {
|
|
|
|
$image = $args[1];
|
|
|
|
$pathname = make_user_directory($userid, true) . "/$image";
|
|
|
|
if (file_exists($pathname) and !is_dir($pathname)) {
|
|
|
|
send_file($pathname, $image);
|
|
|
|
}
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2007-01-26 20:15:54 +00:00
|
|
|
// picture was deleted - use default instead
|
2009-12-16 21:50:45 +00:00
|
|
|
redirect($OUTPUT->pix_url('u/f1'));
|