]> git.mjollnir.org Git - moodle.git/commitdiff
- Adding error trapping to the fetching function and giving error messages accordandly.
authorwillcast <willcast>
Fri, 28 Nov 2003 03:27:24 +0000 (03:27 +0000)
committerwillcast <willcast>
Fri, 28 Nov 2003 03:27:24 +0000 (03:27 +0000)
- Adding Moodle as the web agent!!! :)

PLEASE, edit the new language strings if necessary.

lang/en/resource.php
mod/resource/lib.php

index 3518c4bb18d73be9fae6b245ba044e3b7f7d4786..0554bc1e2b2098f4da7c34f59c2ee3f5103fc7ad 100644 (file)
@@ -12,6 +12,9 @@ $string['editingaresource'] = 'Editing a resource';
 $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';
@@ -31,7 +34,8 @@ $string['newwidth'] = 'Default window width (in pixels)';
 $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';
index 6a5bffb46f5f66426520ded9a42eb7fd0f36fb41..b12a2ded0bf82d0139cf883b7f6a036eb5fef157 100644 (file)
@@ -173,35 +173,50 @@ function resource_fetch_remote_file ($cm, $url, $headers = "" ) {
     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;
     }
@@ -264,7 +279,7 @@ function resource_redirect_tags($text, $url, $tagtoparse, $keytoparse,$prefix =
             //     /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;