]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12763 - proxy_url() in langimport was doing its own custom proxied
authorpoltawski <poltawski>
Sat, 29 Dec 2007 20:03:03 +0000 (20:03 +0000)
committerpoltawski <poltawski>
Sat, 29 Dec 2007 20:03:03 +0000 (20:03 +0000)
download magic. Convert to use download_file_contents() for more
robust downloads. And also add a more helpful error message while i'm
at it.
merged from MOODLE_19_STABLE

admin/langimport.php
lang/en_utf8/error.php

index 5f8acbaf6521d1008f1470f0cf577f28c2418085..0ae768bd75fe3a825cd2bfc8fd98324a02e152e4 100755 (executable)
 
 
             if (!$availablelangs = proxy_url($source)) {
-                error ('can not read from course');
+                print_error('cannotdownloadlanguageupdatelist');
             }
 
             //and build an associative array
     }
 
     //returns an array of languages, or false if can not read from source
-    //uses a socket if proxy is set as a config variable
     function proxy_url($url) {
         global $CFG;
 
-        if ($CFG->proxyhost && $CFG->proxyport) {
+        $availablelangs = array();
 
-            $proxy_fp = fsockopen($CFG->proxyhost, $CFG->proxyport);
-            if (!$proxy_fp) {
-                return false;    //failed
-            }
-            fputs($proxy_fp, "GET $url HTTP/1.0\r\nHost: $CFG->proxyhost\r\n\r\n");
-
-            $headers_done = false;
-            while(!feof($proxy_fp)) {
-                $string = fgets($proxy_fp, 1024);
-                if(!$headers_done){
-                    // A new line indicates end of HTTP headers
-                    $headers_done = ("\r\n" == $string);
-                } else {
-                    $availablelangs[] = split(',', $string);
-                }
-            }
-            fclose($proxy_fp);
+        if( $content = download_file_content($url) ){
 
-        } else {    //proxy not in use
-            if ($fp = fopen($url, 'r')){    /// attempt to get the list from Moodle.org.
-                while(!feof ($fp)) {
-                    $availablelangs[] = split(',', fgets($fp,1024));
+            $alllines = split("\n", $content);
+            foreach($alllines as $line){
+                if(!empty($line)){
+                    $availablelangs[] = split(',', $line);
                 }
-            } else {    /// fopen failed, return false.
-                return false;
             }
+
+            return $availablelangs;
+        }else{
+            return false;
         }
-        return $availablelangs;
     }
 ?>
index 864326dc6d695772c90631239928d8744eb91f2d..56ec11b7d0e0f92060340e0be805e6d84fda48f4 100644 (file)
@@ -8,6 +8,7 @@ $string['cannotcreatelangdir'] = 'Cannot create lang dir.';
 $string['cannotcreatetempdir'] = 'Cannot create temp dir.';
 $string['cannotcustomizelocallang'] = 'You do not have permission to customize the strings translation.  This permission is controlled by the capability "moodle/site:langeditlocal". Set this capability to allow you to edit local language packages in case you want to modify translations for your site.';
 $string['cannotdownloadcomponents'] = 'Cannot download components.';
+$string['cannotdownloadlanguageupdatelist'] = 'Cannot download list of language updates from download.moodle.org';
 $string['cannotdownloadzipfile'] = 'Cannot download ZIP file.';
 $string['cannoteditmasterlang'] = 'You do not have permission to edit master language package. This permission is controlled by the capability "moodle/site:langeditmaster". Set this capability to allow you to edit master language packages in case you are the maintainer of a package.';
 $string['cannotfindcomponent'] = 'Cannot find component.';