';
print_string('clicktoopen', 'url', "
$fullurl");
echo '
';
echo $OUTPUT->footer();
die;
}
/**
* Display embedded url file.
* @param object $url
* @param object $cm
* @param object $course
* @return does not return
*/
function url_display_embed($url, $cm, $course) {
global $CFG, $PAGE, $OUTPUT;
$mimetype = resourcelib_guess_url_mimetype($url->externalurl);
$fullurl = url_get_full_url($url, $cm, $course);
$title = $url->name;
$link = html_writer::tag('a', $fullurl, array('href'=>str_replace('&', '&', $fullurl)));
$clicktoopen = get_string('clicktoopen', 'url', $link);
$moodleurl = new moodle_url($fullurl);
$extension = resourcelib_get_extension($url->externalurl);
$mediamanager = core_media_manager::instance($PAGE);
$embedoptions = array(
core_media_manager::OPTION_TRUSTED => true,
core_media_manager::OPTION_BLOCK => true
);
if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image
$code = resourcelib_embed_image($fullurl, $title);
} else if ($mediamanager->can_embed_url($moodleurl, $embedoptions)) {
// Media (audio/video) file.
$code = $mediamanager->embed_url($moodleurl, $title, 0, 0, $embedoptions);
} else {
// anything else - just try object tag enlarged as much as possible
$code = resourcelib_embed_general($fullurl, $title, $clicktoopen, $mimetype);
}
url_print_header($url, $cm, $course);
url_print_heading($url, $cm, $course);
echo $code;
url_print_intro($url, $cm, $course);
echo $OUTPUT->footer();
die;
}
/**
* Decide the best display format.
* @param object $url
* @return int display type constant
*/
function url_get_final_display_type($url) {
global $CFG;
if ($url->display != RESOURCELIB_DISPLAY_AUTO) {
return $url->display;
}
// detect links to local moodle pages
if (strpos($url->externalurl, $CFG->wwwroot) === 0) {
if (strpos($url->externalurl, 'file.php') === false and strpos($url->externalurl, '.php') !== false ) {
// most probably our moodle page with navigation
return RESOURCELIB_DISPLAY_OPEN;
}
}
static $download = array('application/zip', 'application/x-tar', 'application/g-zip', // binary formats
'application/pdf', 'text/html'); // these are known to cause trouble for external links, sorry
static $embed = array('image/gif', 'image/jpeg', 'image/png', 'image/svg+xml', // images
'application/x-shockwave-flash', 'video/x-flv', 'video/x-ms-wm', // video formats
'video/quicktime', 'video/mpeg', 'video/mp4',
'audio/mp3', 'audio/x-realaudio-plugin', 'x-realaudio-plugin', // audio formats,
);
$mimetype = resourcelib_guess_url_mimetype($url->externalurl);
if (in_array($mimetype, $download)) {
return RESOURCELIB_DISPLAY_DOWNLOAD;
}
if (in_array($mimetype, $embed)) {
return RESOURCELIB_DISPLAY_EMBED;
}
// let the browser deal with it somehow
return RESOURCELIB_DISPLAY_OPEN;
}
/**
* Get the parameters that may be appended to URL
* @param object $config url module config options
* @return array array describing opt groups
*/
function url_get_variable_options($config) {
global $CFG;
$options = array();
$options[''] = array('' => get_string('chooseavariable', 'url'));
$options[get_string('course')] = array(
'courseid' => 'id',
'coursefullname' => get_string('fullnamecourse'),
'courseshortname' => get_string('shortnamecourse'),
'courseidnumber' => get_string('idnumbercourse'),
'coursesummary' => get_string('summary'),
'courseformat' => get_string('format'),
);
$options[get_string('modulename', 'url')] = array(
'urlinstance' => 'id',
'urlcmid' => 'cmid',
'urlname' => get_string('name'),
'urlidnumber' => get_string('idnumbermod'),
);
$options[get_string('miscellaneous')] = array(
'sitename' => get_string('fullsitename'),
'serverurl' => get_string('serverurl', 'url'),
'currenttime' => get_string('time'),
'lang' => get_string('language'),
);
if (!empty($config->secretphrase)) {
$options[get_string('miscellaneous')]['encryptedcode'] = get_string('encryptedcode');
}
$options[get_string('user')] = array(
'userid' => 'id',
'userusername' => get_string('username'),
'useridnumber' => get_string('idnumber'),
'userfirstname' => get_string('firstname'),
'userlastname' => get_string('lastname'),
'userfullname' => get_string('fullnameuser'),
'useremail' => get_string('email'),
'usericq' => get_string('icqnumber'),
'userphone1' => get_string('phone1'),
'userphone2' => get_string('phone2'),
'userinstitution' => get_string('institution'),
'userdepartment' => get_string('department'),
'useraddress' => get_string('address'),
'usercity' => get_string('city'),
'usertimezone' => get_string('timezone'),
'userurl' => get_string('webpage'),
);
if ($config->rolesinparams) {
$roles = role_fix_names(get_all_roles());
$roleoptions = array();
foreach ($roles as $role) {
$roleoptions['course'.$role->shortname] = get_string('yourwordforx', '', $role->localname);
}
$options[get_string('roles')] = $roleoptions;
}
return $options;
}
/**
* Get the parameter values that may be appended to URL
* @param object $url module instance
* @param object $cm
* @param object $course
* @param object $config module config options
* @return array of parameter values
*/
function url_get_variable_values($url, $cm, $course, $config) {
global $USER, $CFG;
$site = get_site();
$coursecontext = context_course::instance($course->id);
$values = array (
'courseid' => $course->id,
'coursefullname' => format_string($course->fullname, true, array('context' => $coursecontext)),
'courseshortname' => format_string($course->shortname, true, array('context' => $coursecontext)),
'courseidnumber' => $course->idnumber,
'coursesummary' => $course->summary,
'courseformat' => $course->format,
'lang' => current_language(),
'sitename' => format_string($site->fullname, true, array('context' => $coursecontext)),
'serverurl' => $CFG->wwwroot,
'currenttime' => time(),
'urlinstance' => $url->id,
'urlcmid' => $cm->id,
'urlname' => format_string($url->name, true, array('context' => $coursecontext)),
'urlidnumber' => $cm->idnumber,
);
if (isloggedin()) {
$values['userid'] = $USER->id;
$values['userusername'] = $USER->username;
$values['useridnumber'] = $USER->idnumber;
$values['userfirstname'] = $USER->firstname;
$values['userlastname'] = $USER->lastname;
$values['userfullname'] = fullname($USER);
$values['useremail'] = $USER->email;
$values['usericq'] = $USER->icq;
$values['userphone1'] = $USER->phone1;
$values['userphone2'] = $USER->phone2;
$values['userinstitution'] = $USER->institution;
$values['userdepartment'] = $USER->department;
$values['useraddress'] = $USER->address;
$values['usercity'] = $USER->city;
$now = new DateTime('now', core_date::get_user_timezone_object());
$values['usertimezone'] = $now->getOffset() / 3600.0; // Value in hours for BC.
$values['userurl'] = $USER->url;
}
// weak imitation of Single-Sign-On, for backwards compatibility only
// NOTE: login hack is not included in 2.0 any more, new contrib auth plugin
// needs to be createed if somebody needs the old functionality!
if (!empty($config->secretphrase)) {
$values['encryptedcode'] = url_get_encrypted_parameter($url, $config);
}
//hmm, this is pretty fragile and slow, why do we need it here??
if ($config->rolesinparams) {
$coursecontext = context_course::instance($course->id);
$roles = role_fix_names(get_all_roles($coursecontext), $coursecontext, ROLENAME_ALIAS);
foreach ($roles as $role) {
$values['course'.$role->shortname] = $role->localname;
}
}
return $values;
}
/**
* BC internal function
* @param object $url
* @param object $config
* @return string
*/
function url_get_encrypted_parameter($url, $config) {
global $CFG;
if (file_exists("$CFG->dirroot/local/externserverfile.php")) {
require_once("$CFG->dirroot/local/externserverfile.php");
if (function_exists('extern_server_file')) {
return extern_server_file($url, $config);
}
}
return md5(getremoteaddr().$config->secretphrase);
}
/**
* Optimised mimetype detection from general URL
* @param $fullurl
* @param int $size of the icon.
* @return string|null mimetype or null when the filetype is not relevant.
*/
function url_guess_icon($fullurl, $size = null) {
global $CFG;
require_once("$CFG->libdir/filelib.php");
if (substr_count($fullurl, '/') < 3 or substr($fullurl, -1) === '/') {
// Most probably default directory - index.php, index.html, etc. Return null because
// we want to use the default module icon instead of the HTML file icon.
return null;
}
$icon = file_extension_icon($fullurl, $size);
$htmlicon = file_extension_icon('.htm', $size);
$unknownicon = file_extension_icon('', $size);
// We do not want to return those icon types, the module icon is more appropriate.
if ($icon === $unknownicon || $icon === $htmlicon) {
return null;
}
return $icon;
}