From 3bfe3922c2fb2468f21ebe793e2a5399e9ecbeaa Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 28 Nov 2003 02:11:02 +0000 Subject: [PATCH] A few rearrangments in the new code for filtered external pages --- lang/en/resource.php | 1 + mod/resource/config.html | 14 ++++++++++++++ mod/resource/fetch.php | 3 +-- mod/resource/lib.php | 13 +++++++++++-- mod/resource/view.php | 11 +++++------ 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lang/en/resource.php b/lang/en/resource.php index a41815c8c1..3518c4bb18 100644 --- a/lang/en/resource.php +++ b/lang/en/resource.php @@ -5,6 +5,7 @@ $string['addresource'] = 'Add resource'; $string['chooseafile'] = 'Choose or upload a file'; $string['configdefaulturl'] = 'This value is used to prefill the URL form when creating a new URL-based resource.'; +$string['configfilterexternalpages'] = 'Enabling this setting will cause all external resources (web pages, uploaded HTML files) to be processed by the currently defined site filters (such as glossary autolinks, for example). Turning this option on may cause your course pages to slow down significantly - use with caution and only if you really need it.'; $string['configframesize'] = 'When a web page or an uploaded file is displayed within a frame, this value is the size (in pixels) of the top frame (which contains the navigation).'; $string['configwebsearch'] = 'When adding a URL as a webpage or weblink, this location is offered as a site to help the user search for the URL they want.'; $string['editingaresource'] = 'Editing a resource'; diff --git a/mod/resource/config.html b/mod/resource/config.html index 41b9234e7d..815a724ee4 100644 --- a/mod/resource/config.html +++ b/mod/resource/config.html @@ -28,6 +28,20 @@ + +

resource_filterexternalpages: + + resource_filterexternalpages, ""); + ?> + + + + + "> diff --git a/mod/resource/fetch.php b/mod/resource/fetch.php index a9667ede36..e5722cffc7 100644 --- a/mod/resource/fetch.php +++ b/mod/resource/fetch.php @@ -2,7 +2,6 @@ require_once("../../config.php"); require_once("lib.php"); - require_once("../../lib/snoopy/Snoopy.class.inc"); require_variable($id); // Course Module ID require_variable($url); // url to fetch @@ -22,4 +21,4 @@ $content = resource_fetch_remote_file($cm, $url); echo format_text($content->results,FORMAT_HTML); -?> \ No newline at end of file +?> diff --git a/mod/resource/lib.php b/mod/resource/lib.php index c17b19411a..d4ef05915b 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -28,7 +28,11 @@ if (!isset($CFG->resource_websearch)) { if (!isset($CFG->resource_defaulturl)) { set_config("resource_defaulturl", "http://"); -} +} + +if (!isset($CFG->resource_filterexternalpages)) { + set_config("resource_filterexternalpages", false); +} $RESOURCE_WINDOW_OPTIONS = array("resizable", "scrollbars", "directories", "location", "menubar", "toolbar", "status", "height", "width"); @@ -162,7 +166,12 @@ function resource_get_coursemodule_info($coursemodule) { } function resource_fetch_remote_file ($cm, $url, $headers = "" ) { - // Snoopy is an HTTP client in PHP +/// Snoopy is an HTTP client in PHP + + global $CFG; + + require_once("$CFG->libdir/snoopy/Snoopy.class.inc"); + $client = new Snoopy(); $client->agent = MAGPIE_USER_AGENT; $client->read_timeout = MAGPIE_FETCH_TIME_OUT; diff --git a/mod/resource/view.php b/mod/resource/view.php index 5f9264b2a2..186425ccb8 100644 --- a/mod/resource/view.php +++ b/mod/resource/view.php @@ -2,7 +2,6 @@ require_once("../../config.php"); require_once("lib.php"); - require_once("../../lib/snoopy/Snoopy.class.inc"); require_variable($id); // Course Module ID optional_variable($frameset, ""); @@ -56,7 +55,7 @@ break; case WEBLINK: - if ( $CFG->filterexternalpages ) { + if ($CFG->resource_filterexternalpages) { $url = "fetch.php?id=$cm->id&url=$resource->reference"; } else { $url = "$resource->reference"; @@ -74,7 +73,7 @@ echo "

".text_to_html($resource->summary, true, false)."
"; } else { - if ( $CFG->filterexternalpages ) { + if ($CFG->resource_filterexternalpages) { $url = "fetch.php?id=$cm->id&url=$resource->reference"; } else { $url = "$resource->reference"; @@ -92,7 +91,7 @@ require_once("../../files/mimetypes.php"); $inpopup = !empty($_GET["inpopup"]); - if ( $CFG->filterexternalpages ) { + if ($CFG->resource_filterexternalpages) { if ($inpopup) { $fetchingprefix = "$CFG->wwwroot/mod/resouce/fetch.php?id=$cm->id&url="; } else { @@ -161,7 +160,7 @@ echo "
"; echo "
"; echo "
"; - } elseif ( $resourcehtml and $CFG->filterexternalpages ) { + } else if ($resourcehtml and $CFG->resource_filterexternalpages) { echo "
"; $content = resource_fetch_remote_file("$fetchingprefix$fullurl"); @@ -184,7 +183,7 @@ $fullurl = "$CFG->wwwroot/file.php?file=/$course->id/$resource->reference"; } - if ( $resourcehtml and $CFG->filterexternalpages ) { + if ($resourcehtml and $CFG->resource_filterexternalpages) { echo "id&url=$fetchingprefix$fullurl\">"; } else { echo ""; -- 2.39.5