mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 12:45:04 +01:00
New feature for resources ... Local File Resources
A Resource Parameter controls this (it defaults to OFF). When on, you see a third button when selecting a file, which lets you select a LOCAL file on your own filesystem (but it isn't uploaded). The local file is included in the web page when viewed. All users see a link that helps them set up a user_preference for the location of these files on their own system (usually a CD_ROM drive).
This commit is contained in:
parent
a7bd52d8e4
commit
713d78eafa
@ -38,6 +38,20 @@
|
||||
<?php print_string("configsecretphrase", "resource") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">resource_allowlocalfiles:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($choices);
|
||||
$choices["0"] = get_string("no");
|
||||
$choices["1"] = get_string("yes");
|
||||
choose_from_menu ($choices, "resource_allowlocalfiles", $CFG->resource_allowlocalfiles, "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configallowlocalfiles", "resource") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">resource_filterexternalpages:</td>
|
||||
<td>
|
||||
|
@ -32,6 +32,12 @@ if (!isset($CFG->resource_parametersettings)) {
|
||||
set_config("resource_parametersettings", "0");
|
||||
}
|
||||
|
||||
if (!isset($CFG->resource_allowlocalfiles)) {
|
||||
set_config("resource_allowlocalfiles", "0");
|
||||
}
|
||||
|
||||
define('RESOURCE_LOCALPATH', 'LOCALPATH');
|
||||
|
||||
$RESOURCE_WINDOW_OPTIONS = array('resizable', 'scrollbars', 'directories', 'location',
|
||||
'menubar', 'toolbar', 'status', 'height', 'width');
|
||||
|
||||
|
@ -39,6 +39,11 @@
|
||||
button_to_popup_window ("/files/index.php?id=$form->course&choose=form.reference", "coursefiles", $strchooseafile, 500, 750, $strchooseafile);
|
||||
echo "<input type=\"button\" name=\"searchbutton\" value=\"$strsearch ...\" ".
|
||||
"onclick=\"return window.open('$CFG->resource_websearch', 'websearch', 'menubar=1,location=1,directories=1,toolbar=1,scrollbars,resizable,width=800,height=600');\" />\n";
|
||||
if ($CFG->resource_allowlocalfiles) {
|
||||
button_to_popup_window ("/mod/resource/type/file/localfile.php?choose=form.reference",
|
||||
"localfiles", get_string('localfilechoose', 'resource'), 400, 600,
|
||||
get_string('localfilechoose', 'resource'));
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
49
mod/resource/type/file/localfile.php
Normal file
49
mod/resource/type/file/localfile.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php // $Id$
|
||||
|
||||
require('../../../../config.php');
|
||||
require('../../lib.php');
|
||||
|
||||
$choose = required_param('choose');
|
||||
|
||||
require_login();
|
||||
|
||||
if (!$CFG->resource_allowlocalfiles) {
|
||||
error('You cannot access this script');
|
||||
}
|
||||
|
||||
print_header(get_string('localfilechoose', 'resource'));
|
||||
|
||||
print_simple_box(get_string('localfileinfo', 'resource'), 'center');
|
||||
|
||||
$chooseparts = explode('.', $choose);
|
||||
|
||||
?>
|
||||
<script language="javascript" type="text/javascript">
|
||||
<!--
|
||||
function set_value(txt) {
|
||||
if (txt.indexOf('/') > -1) {
|
||||
path = txt.substring(txt.indexOf('/'),txt.length);
|
||||
} else if (txt.indexOf('\\') > -1) {
|
||||
path = txt.substring(txt.indexOf('\\'),txt.length);
|
||||
} else {
|
||||
window.close();
|
||||
}
|
||||
opener.document.forms['<?php echo $chooseparts[0]."'].".$chooseparts[1] ?>.value = '<?php p(RESOURCE_LOCALPATH) ?>'+path;
|
||||
window.close();
|
||||
}
|
||||
-->
|
||||
</script>
|
||||
|
||||
<br />
|
||||
<div align="center" class="form">
|
||||
<form name="myform">
|
||||
<input type="file" size="60" name="myfile"><br />
|
||||
<input type="button" value="<?php print_string('localfileselect','resource') ?>"
|
||||
onClick="return set_value(document.myform.myfile.value)">
|
||||
<input type="button" value="<?php print_string('cancel') ?>"
|
||||
onClick="window.close()">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
55
mod/resource/type/file/localpath.php
Normal file
55
mod/resource/type/file/localpath.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php // $Id$
|
||||
|
||||
require('../../../../config.php');
|
||||
require('../../lib.php');
|
||||
|
||||
$pathname = optional_param('pathname', '');
|
||||
|
||||
if ($pathname) {
|
||||
if (confirm_sesskey()) {
|
||||
set_user_preference('resource_localpath', $pathname);
|
||||
}
|
||||
?>
|
||||
<script language="javascript" type="text/javascript">
|
||||
<!--
|
||||
window.close();
|
||||
-->
|
||||
</script>
|
||||
<?php
|
||||
exit;
|
||||
}
|
||||
|
||||
print_header(get_string('localfilechoose', 'resource'));
|
||||
|
||||
print_simple_box(get_string('localfilepath', 'resource', $CFG->wwwroot.'/user/edit.php?course='.SITEID), 'center');
|
||||
|
||||
?>
|
||||
<script language="javascript" type="text/javascript">
|
||||
<!--
|
||||
function set_value(txt) {
|
||||
if (txt.indexOf('/') > -1) {
|
||||
txt = txt.substring(0,txt.lastIndexOf('/'));
|
||||
} else if (txt.indexOf('\\') > -1) {
|
||||
txt = txt.substring(0,txt.lastIndexOf('\\'));
|
||||
}
|
||||
document.myform.pathname.value = txt;
|
||||
document.myform.submit();
|
||||
}
|
||||
-->
|
||||
</script>
|
||||
|
||||
<br />
|
||||
<div align="center" class="form">
|
||||
<form name="myform" action="localpath.php" method="post">
|
||||
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>">
|
||||
<input type="hidden" name="pathname" value="">
|
||||
<input type="file" size="60" name="myfile"><br />
|
||||
<input type="button" value="<?php print_string('localfileselect','resource') ?>"
|
||||
onClick="return set_value(document.myform.myfile.value)">
|
||||
<input type="button" value="<?php print_string('cancel') ?>"
|
||||
onClick="window.close()">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -265,7 +265,21 @@ function display() {
|
||||
$fullurl .= '&'.$querystring;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
} else if ($CFG->resource_allowlocalfiles and (strpos($resource->reference, RESOURCE_LOCALPATH) === 0)) { // Localpath
|
||||
$localpath = get_user_preferences('resource_localpath', 'D:');
|
||||
$relativeurl = str_replace(RESOURCE_LOCALPATH, $localpath, $resource->reference);
|
||||
|
||||
if ($querystring) {
|
||||
$relativeurl .= '?'.$querystring;
|
||||
}
|
||||
|
||||
$relativeurl = str_replace('\\', '/', $relativeurl);
|
||||
$relativeurl = str_replace(' ', '%20', $relativeurl);
|
||||
$fullurl = 'file:///'.htmlentities($relativeurl);
|
||||
$localpath = true;
|
||||
|
||||
} else { // Normal uploaded file
|
||||
if ($CFG->slasharguments) {
|
||||
$relativeurl = "/file.php/{$course->id}/{$resource->reference}";
|
||||
if ($querystring) {
|
||||
@ -280,6 +294,22 @@ function display() {
|
||||
$fullurl = "$CFG->wwwroot$relativeurl";
|
||||
}
|
||||
|
||||
/// Print a notice and redirect if we are trying to access a file on a local file system
|
||||
/// and the config setting has been disabled
|
||||
if (!$CFG->resource_allowlocalfiles and (strpos($resource->reference, RESOURCE_LOCALPATH) === 0)) {
|
||||
if ($inpopup) {
|
||||
print_header($pagetitle, $course->fullname);
|
||||
} else {
|
||||
print_header($pagetitle, $course->fullname, "$this->navigation {$resource->name}", "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm));
|
||||
}
|
||||
notify(get_string('notallowedlocalfileaccess', 'resource', ''));
|
||||
if ($inpopup) {
|
||||
close_window_button();
|
||||
}
|
||||
print_footer('none');
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
/// Check whether this is supposed to be a popup, but was called directly
|
||||
|
||||
@ -323,7 +353,11 @@ function display() {
|
||||
echo "<title>{$course->shortname}: {$resource->name}</title></head>\n";
|
||||
echo "<frameset rows=\"$CFG->resource_framesize,*\">";
|
||||
echo "<frame src=\"view.php?id={$cm->id}&type={$resource->type}&frameset=top\" />";
|
||||
echo "<frame src=\"$fullurl\" />";
|
||||
if (!empty($localpath)) { // Show it like this so we interpose some HTML
|
||||
echo "<frame src=\"view.php?id={$cm->id}&type={$resource->type}&inpopup=true\" />";
|
||||
} else {
|
||||
echo "<frame src=\"$fullurl\" />";
|
||||
}
|
||||
echo "</frameset>";
|
||||
echo "</html>";
|
||||
exit;
|
||||
@ -340,8 +374,14 @@ function display() {
|
||||
if (!empty($_GET['frameset']) and $_GET['frameset'] == "top") {
|
||||
print_header($pagetitle, $course->fullname, "$this->navigation {$resource->name}", "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent"));
|
||||
|
||||
echo "<center><font size=\"-1\">".text_to_html($resource->summary, true, false)."</font></center>";
|
||||
echo "</body></html>";
|
||||
$options->para = false;
|
||||
echo '<div class="summary">'.format_text($resource->summary, FORMAT_HTML, $options).'</div>';
|
||||
if (!empty($localpath)) { // Show some help
|
||||
echo '<div align="right" class="helplink">';
|
||||
link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</body></html>';
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -369,9 +409,9 @@ function display() {
|
||||
} else {
|
||||
$c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'.
|
||||
'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'.
|
||||
'font=Arial&fontColour=3333FF&buffer=10&waitForPlay=no&autoPlay=yes&'.
|
||||
'volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource');
|
||||
'font=Arial&fontColour=3333FF&buffer=10&waitForPlay=no&autoPlay=yes';
|
||||
}
|
||||
$c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource');
|
||||
$c = htmlentities($c);
|
||||
echo '<div class="mp3player" align="center">';
|
||||
echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
|
||||
@ -449,6 +489,12 @@ function display() {
|
||||
}
|
||||
|
||||
} else { // Display the resource on it's own
|
||||
if (!empty($localpath)) { // Show a link to help work around browser security
|
||||
echo '<div align="right" class="helplink">';
|
||||
link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
|
||||
echo '</div>';
|
||||
echo "<center><p>(<a href=\"$fullurl\">$fullurl</a>)</p></center>";
|
||||
}
|
||||
redirect($fullurl);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user