MDL-12763 - proxy_url() in langimport was doing its own custom proxied

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
This commit is contained in:
poltawski 2007-12-29 20:03:03 +00:00
parent 8bbfc1e321
commit 6e1cc99de7
2 changed files with 11 additions and 26 deletions

View file

@ -132,7 +132,7 @@
if (!$availablelangs = proxy_url($source)) { if (!$availablelangs = proxy_url($source)) {
error ('can not read from course'); print_error('cannotdownloadlanguageupdatelist');
} }
//and build an associative array //and build an associative array
@ -360,39 +360,23 @@
} }
//returns an array of languages, or false if can not read from source //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) { function proxy_url($url) {
global $CFG; global $CFG;
if ($CFG->proxyhost && $CFG->proxyport) { $availablelangs = array();
$proxy_fp = fsockopen($CFG->proxyhost, $CFG->proxyport); if( $content = download_file_content($url) ){
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; $alllines = split("\n", $content);
while(!feof($proxy_fp)) { foreach($alllines as $line){
$string = fgets($proxy_fp, 1024); if(!empty($line)){
if(!$headers_done){ $availablelangs[] = split(',', $line);
// A new line indicates end of HTTP headers
$headers_done = ("\r\n" == $string);
} else {
$availablelangs[] = split(',', $string);
} }
} }
fclose($proxy_fp);
} else { //proxy not in use return $availablelangs;
if ($fp = fopen($url, 'r')){ /// attempt to get the list from Moodle.org. }else{
while(!feof ($fp)) { return false;
$availablelangs[] = split(',', fgets($fp,1024));
}
} else { /// fopen failed, return false.
return false;
}
} }
return $availablelangs;
} }
?> ?>

View file

@ -8,6 +8,7 @@ $string['cannotcreatelangdir'] = 'Cannot create lang dir.';
$string['cannotcreatetempdir'] = 'Cannot create temp 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['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['cannotdownloadcomponents'] = 'Cannot download components.';
$string['cannotdownloadlanguageupdatelist'] = 'Cannot download list of language updates from download.moodle.org';
$string['cannotdownloadzipfile'] = 'Cannot download ZIP file.'; $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['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.'; $string['cannotfindcomponent'] = 'Cannot find component.';