$string['example'] = 'Example';
$string['examplereference'] = 'Tobin, K. & Tippins, D (1993) Constructivism as a Referent for Teaching and Learning. In: K. Tobin (Ed) The Practice of Constructivism in Science Education, pp 3-21, Lawrence-Erlbaum, Hillsdale, NJ.';
$string['exampleurl'] = 'http://www.example.com/somedirectory/somefile.html';
+$string['fetcherror'] = '<p align=center><font color=#FF0000><b>ERROR</b></font></p><p align=center>An error was found when trying to retrieve the web page.</p>';
+$string['fetchclienterror'] = '<p align=center><font color=#FF0000><b>ERROR</b></font></p><p align=center>An error was found on your web client when trying to retrieve the web page (possibly a wrong URL).</p>';
+$string['fetchservererror'] = '<p align=center><font color=#FF0000><b>ERROR</b></font></p><p align=center>An error was found on the remote server when trying to retrieve the web page (possibly a program error).</p>';
$string['filename'] = 'File name';
$string['fulltext'] = 'Full text';
$string['htmlfragment'] = 'HTML fragment';
$string['newwindow'] = 'New window';
$string['newwindowopen'] = 'Display this resource in a new popup window';
$string['note'] = 'Note';
-$string['notefile'] = 'To upload more files into the course (so they appear in this list) use the \r
+$string['notefile'] = 'To upload more files into the course (so they appear in this list) use the
+
<A HREF="$a">File Manager</A>.';
$string['notypechosen'] = 'You need to choose a type. Use your back button to go back and retry.';
$string['resourcetype'] = 'Type of resource';
require_once("$CFG->libdir/snoopy/Snoopy.class.inc");
$client = new Snoopy();
- $client->agent = MAGPIE_USER_AGENT;
- $client->read_timeout = MAGPIE_FETCH_TIME_OUT;
- $client->use_gzip = MAGPIE_USE_GZIP;
+ $ua = 'Moodle/'. $CFG->release . ' (+http://moodle.org';
+ if ( $CFG->resource_usecache ) {
+ $ua = $ua . ')';
+ } else {
+ $ua = $ua . '; No cache)';
+ }
+ $client->agent = $ua;
+ $client->read_timeout = 5;
+ $client->use_gzip = true;
if (is_array($headers) ) {
$client->rawheaders = $headers;
}
@$client->fetch($url);
+ if ( $client->status >= 200 && $client->status < 300 ) {
+ $tags = array("A" => "href=",
+ "IMG" => "src=",
+ "LINK" => "href=",
+ "AREA" => "href=",
+ "FRAME" => "src=",
+ "IFRAME" => "src=",
+ "FORM" => "action=");
- $tags = array("A" => "href=",
- "IMG" => "src=",
- "LINK" => "href=",
- "AREA" => "href=",
- "FRAME" => "src=",
- "IFRAME" => "src=",
- "FORM" => "action=");
-
- foreach ($tags as $tag => $key) {
- $prefix = "fetch.php?id=$cm->id&url=";
- if ( $tag == "IMG" or $tag == "LINK" or $tag == "FORM") {
- $prefix = "";
+ foreach ($tags as $tag => $key) {
+ $prefix = "fetch.php?id=$cm->id&url=";
+ if ( $tag == "IMG" or $tag == "LINK" or $tag == "FORM") {
+ $prefix = "";
+ }
+ $client->results = resource_redirect_tags($client->results, $url, $tag, $key,$prefix);
+ }
+ } else {
+ if ( $client->status >= 400 && $client->status < 500) {
+ $client->results = get_string("fetchclienterror","resource"); // Client error
+ } elseif ( $client->status >= 500 && $client->status < 600) {
+ $client->results = get_string("fetchservererror","resource"); // Server error
+ } else {
+ $client->results = get_string("fetcherror","resource"); // Redirection? HEAD? Unknown error.
}
- $client->results = resource_redirect_tags($client->results, $url, $tag, $key,$prefix);
}
return $client;
}
function resource_redirect_tags($text, $url, $tagtoparse, $keytoparse,$prefix = "" ) {
- $valid = 0;
+ $valid = 1;
if ( strpos($url,"?") == FALSE ) {
$valid = 1;
}
// /folder/file.ext Add main root dir
// Special case: If finalurl contains a ?, it won't be parsed
- $valid = 0;
+ $valid = 1;
if ( strpos($finalurl,"?") == FALSE ) {
$valid = 1;