]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11845 Support for config proxy options when downloading language packs (& other...
authorsam_marshall <sam_marshall>
Thu, 6 Dec 2007 18:12:42 +0000 (18:12 +0000)
committersam_marshall <sam_marshall>
Thu, 6 Dec 2007 18:12:42 +0000 (18:12 +0000)
admin/timezoneimport.php
lib/componentlib.class.php

index 33400b659c4d4c0b653abe253cb1f30c2d40169d..086d95525eb09909a7bd8e67ded118d8b5150146 100644 (file)
@@ -6,7 +6,8 @@
     require_once($CFG->libdir.'/adminlib.php');
     require_once($CFG->libdir.'/filelib.php');
     require_once($CFG->libdir.'/olson.php');
-
+    require_once($CFG->libdir.'/snoopy/Snoopy.class.inc');
+    
     admin_externalpage_setup('timezoneimport');
 
     $ok = optional_param('ok', 0, PARAM_BOOL);
     }
 
 /// Otherwise, let's try moodle.org's copy
+    $snoopy = new Snoopy;
+    $snoopy->proxy_host = $CFG->proxyhost;
+    $snoopy->proxy_port = $CFG->proxyport;
 
     $source = 'http://download.moodle.org/timezones/';
-    if (!$importdone and ini_get('allow_url_fopen')) {
-        if (is_readable($source) && $contents = file_get_contents($source)) {  // Grab whole page
-            if ($file = fopen($CFG->dataroot.'/temp/timezones.txt', 'w')) {            // Make local copy
-                fwrite($file, $contents);
-                fclose($file);
-                if ($timezones = get_records_csv($CFG->dataroot.'/temp/timezones.txt', 'timezone')) {  // Parse it
-                    update_timezone_records($timezones);
-                    $importdone = $source;
-                }
-                unlink($CFG->dataroot.'/temp/timezones.txt');
+    if (!$importdone && $snoopy->fetch($source)) {
+        if ($file = fopen($CFG->dataroot.'/temp/timezones.txt', 'w')) {            // Make local copy
+            fwrite($file, $snoopy->results);
+            fclose($file);
+            if ($timezones = get_records_csv($CFG->dataroot.'/temp/timezones.txt', 'timezone')) {  // Parse it
+                update_timezone_records($timezones);
+                $importdone = $source;
             }
+            unlink($CFG->dataroot.'/temp/timezones.txt');
         }
     }
 
index cef12b9385c98c3c4c6db5a01533159dee65de42..c899a7596d01c241fb299b2a0d1e8ace701210f3 100644 (file)
 // error to be retrieved by one standard get_string() call against the error.php lang file.
 //
 // That's all!
+global $CFG;
+require_once($CFG->libdir.'/snoopy/Snoopy.class.inc');
 
 // Some needed constants
 define('ERROR',           0);
@@ -141,7 +143,7 @@ define('INSTALLED',       3);
  */
 class component_installer {
 
-    var $sourcebase;   /// Full http URL, base for downloadeable items
+    var $sourcebase;   /// Full http URL, base for downloadable items
     var $zippath;      /// Relative path (from sourcebase) where the 
                        /// downloadeable item resides.
     var $zipfilename;  /// Name of the .zip file to be downloaded
@@ -271,7 +273,14 @@ class component_installer {
     /// Download zip file and save it to temp
         $source = $this->sourcebase.'/'.$this->zippath.'/'.$this->zipfilename;
         $zipfile= $CFG->dataroot.'/temp/'.$this->zipfilename;
-        if ($contents = file_get_contents($source)) {
+
+    /// Prepare Snoopy client and set up proxy info
+        $snoopy = new Snoopy;
+        global $CFG;
+        $snoopy->proxy_host = $CFG->proxyhost;
+        $snoopy->proxy_port = $CFG->proxyport;
+        if($snoopy->fetch($source)) {
+            $contents = $snoopy->results;
             if ($file = fopen($zipfile, 'w')) {
                 if (!fwrite($file, $contents)) {
                     fclose($file);
@@ -458,12 +467,20 @@ class component_installer {
         } else {
         /// Not downloaded, let's do it now
             $availablecomponents = array();
-            if ($fp = fopen($source, 'r')) {
-            /// Read from URL, each line will be one component
-                while(!feof ($fp)) {
-                    $availablecomponents[] = split(',', fgets($fp,1024));
+
+            /// Prepare Snoopy client and set up proxy info
+            $snoopy = new Snoopy;
+            global $CFG;
+            $snoopy->proxy_host = $CFG->proxyhost;
+            $snoopy->proxy_port = $CFG->proxyport;
+
+            if ($snoopy->fetch($source)) {
+            /// Split text into lines
+                $lines=preg_split('/\r?\n/',$snoopy->results);
+            /// Each line will be one component
+                foreach($lines as $line) {
+                    $availablecomponents[] = split(',', $line);
                 }
-                fclose($fp);
             /// If no components have been found, return error
                 if (empty($availablecomponents)) {
                     $this->errorstring='cannotdownloadcomponents';