]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12698, MDL-12569 - componentlib & langimport improvements and fixes; merged from...
authorskodak <skodak>
Sun, 30 Dec 2007 22:19:36 +0000 (22:19 +0000)
committerskodak <skodak>
Sun, 30 Dec 2007 22:19:36 +0000 (22:19 +0000)
admin/environment.php
admin/langimport.php
install.php
install/stringnames.txt
lang/en_utf8/admin.php
lang/en_utf8/error.php
lib/componentlib.class.php
lib/languages.md5

index 4ceaa2f3ff48f25e2857817b361beb395eba7981..0003a25d2493265ba79dac3e22df5057c3883899 100644 (file)
@@ -68,7 +68,7 @@
             $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
             switch ($status) {
                 case ERROR:
-                    if ($cd->get_error() == 'remotedownloadnotallowed') {
+                    if ($cd->get_error() == 'remotedownloaderror') {
                         $a = new stdClass();
                         $a->url = 'http://download.moodle.org/environment/environment.zip';
                         $a->dest= $CFG->dataroot.'/';
index 0ae768bd75fe3a825cd2bfc8fd98324a02e152e4..317f4dbf70d8f5a02a57c6ce313412b99f219c00 100755 (executable)
@@ -6,6 +6,8 @@
 
     require_once('../config.php');
     require_once($CFG->libdir.'/adminlib.php');
+    require_once($CFG->libdir.'/filelib.php');
+    require_once($CFG->libdir.'/componentlib.class.php');
 
     admin_externalpage_setup('langimport');
 
     $sitelang      = optional_param('sitelangconfig', '', PARAM_FILE);
 
     define('INSTALLATION_OF_SELECTED_LANG', 2);
-    define('CHANGE_SITE_LANG', 3);
     define('DELETION_OF_SELECTED_LANG', 4);
     define('UPDATE_ALL_LANG', 5);
 
-    $strlang = get_string('langimport','admin');
-
-    $strlanguage = get_string("language");
-    $strthislanguage = get_string("thislanguage");
-    $title = $strlang;
-
-    admin_externalpage_print_header();
+    $strlang         = get_string('langimport','admin');
+    $strlanguage     = get_string('language');
+    $strthislanguage = get_string('thislanguage');
+    $title           = $strlang;
 
     //reset and diagnose lang cache permissions
     @unlink($CFG->dataroot.'/cache/languages');
     if (file_exists($CFG->dataroot.'/cache/languages')) {
-        notify('Language cache can not be deleted, please check permissions in dataroot.');
+        error('Language cache can not be deleted, please fix permissions in dataroot/cache/languages!');
     }
     get_list_of_languages(true); //refresh lang cache
 
+    $notice_ok     = array();
+    $notice_error = array();
+
     switch ($mode){
 
         case INSTALLATION_OF_SELECTED_LANG:    ///installation of selected language pack
                 @mkdir ($CFG->dataroot.'/temp/');    //make it in case it's a fresh install, it might not be there
                 @mkdir ($CFG->dataroot.'/lang/');
 
-                require_once($CFG->libdir.'/componentlib.class.php');
                 if ($cd = new component_installer('http://download.moodle.org', 'lang16',
                                                     $pack.'.zip', 'languages.md5', 'lang')) {
                     $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
                     switch ($status) {
 
-                        case ERROR: 
-                            if ($cd->get_error() == 'remotedownloadnotallowed') {
-                                $a = new stdClass();
+                        case ERROR:
+                            if ($cd->get_error() == 'remotedownloaderror') {
+                                $a = new object();
                                 $a->url = 'http://download.moodle.org/lang16/'.$pack.'.zip';
                                 $a->dest= $CFG->dataroot.'/lang';
-                                error(get_string($cd->get_error(), 'error', $a));
+                                error(get_string($cd->get_error(), 'error', $a), 'langimport.php');
                             } else {
-                                error(get_string($cd->get_error(), 'error'));
+                                error(get_string($cd->get_error(), 'error'), 'langimport.php');
                             }
                         break;
 
                         case INSTALLED:
-                            get_list_of_languages(true); //refresh lang cache
-                            redirect('langimport.php', get_string('langpackupdated','admin',$pack), -1);
+                            $notice_ok[] = get_string('langpackinstalled','admin',$pack);
                         break;
 
                         case UPTODATE:
             }
         break;
 
-        case CHANGE_SITE_LANG:    //change site language
-
-            if (confirm_sesskey()) {
-                $langconfig = get_record('config','name','lang');
-                $langconfig->value = $sitelang;
-                if (!empty($sitelang) && update_record('config',$langconfig)){
-                    redirect('langimport.php', get_string('sitelangchanged','admin'));
-                } else {
-                    error('Could not update the default site language!');
-                }
-            }
-
-        break;
         case DELETION_OF_SELECTED_LANG:    //delete a directory(ies) containing a lang pack completely
 
-            if (!$confirm && confirm_sesskey()) {
+            if ($uninstalllang == 'en_utf8') {
+                $notice_error[] = 'en_utf8 can not be uninstalled!';
+
+            } else if (!$confirm && confirm_sesskey()) {
+                admin_externalpage_print_header();
                 notice_yesno(get_string('uninstallconfirm', 'admin', $uninstalllang),
-                             'langimport.php?mode=4&amp;uninstalllang='.$uninstalllang.'&amp;confirm=1&amp;sesskey='.sesskey(),
+                             'langimport.php?mode='.DELETION_OF_SELECTED_LANG.'&amp;uninstalllang='.$uninstalllang.'&amp;confirm=1&amp;sesskey='.sesskey(),
                              'langimport.php');
+                print_footer();
+                die;
+
             } else if (confirm_sesskey()) {
-                if ($uninstalllang == 'en_utf8') {
-                    error ('en_utf8 can not be uninstalled!');
-                }
                 $dest1 = $CFG->dataroot.'/lang/'.$uninstalllang;
                 $dest2 = $CFG->dirroot.'/lang/'.$uninstalllang;
                 $rm1 = false;
                 get_list_of_languages(true); //refresh lang cache
                 //delete the direcotries
                 if ($rm1 or $rm2) {
-                    redirect('langimport.php', get_string('langpackremoved','admin'), 3);
+                    $notice_ok[] = get_string('langpackremoved','admin');
                 } else {    //nothing deleted, possibly due to permission error
-                    error('An error has occurred, language pack is not completely uninstalled, please check file permissions');
+                    $notice_error[] = 'An error has occurred, language pack is not completely uninstalled, please check file permissions';
                 }
             }
         break;
 
             //0th pull a list from download.moodle.org,
             //key = langname, value = md5
-            $source = 'http://download.moodle.org/lang16/languages.md5';
             $md5array = array();
             $updated = 0;    //any packs updated?
             $alllangs = array_keys(get_list_of_languages(false, true)); //get all available langs
             $packs = array();    //all the packs that needs updating
 
 
-            if (!$availablelangs = proxy_url($source)) {
+            if (!$availablelangs = get_remote_list_of_languages()) {
                 print_error('cannotdownloadlanguageupdatelist');
             }
 
                 $md5array[$alang[0]] = $alang[1];
             }
 
-            //filtering out non-16 packs
+            //filtering out non-16 and unofficial packs
             foreach ($alllangs as $clang) {
+                if (!array_key_exists($clang, $md5array)) {
+                    $notice_ok[] = get_string('langpackupdateskipped', 'admin', $clang);
+                    continue;
+                }
                 $dest1 = $CFG->dataroot.'/lang/'.$clang;
                 $dest2 = $CFG->dirroot.'/lang/'.$clang;
 
                 if ($pack == 'en_utf8') {    // no update for en_utf8
                     continue;
                 }
+
                 //1. delete old director(ies)
 
                 $dest1 = $CFG->dataroot.'/lang/'.$pack;
                 $rm1 = false;
                 $rm2 = false;
                 if (file_exists($dest1)) {
-                    $rm1 = remove_dir($dest1);
+                    if (!remove_dir($dest1)) {
+                        $notice_error[] = 'Could not delete old directory '.$dest1.', update of '.$pack.' failed, please check permissions.';
+                        continue;
+                    }
                 }
                 if (file_exists($dest2)) {
-                    $rm2 = remove_dir($dest2);
-                }
-                if (!($rm1 || $rm2)) {
-                    error ('could not delete old directory, update failed');
+                    if (!remove_dir($dest2)) {
+                        $notice_error[] = 'Could not delete old directory '.$dest2.', update of '.$pack.' failed, please check permissions.';
+                        continue;
+                    }
                 }
 
                 //2. copy & unzip into new
 
-                require_once($CFG->libdir.'/componentlib.class.php');
                 if ($cd = new component_installer('http://download.moodle.org', 'lang16',
                                        $pack.'.zip', 'languages.md5', 'lang')) {
                 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
                 switch ($status) {
 
                     case ERROR:
-                        if ($cd->get_error() == 'remotedownloadnotallowed') {
+                        if ($cd->get_error() == 'remotedownloaderror') {
                             $a = new stdClass();
                             $a->url = 'http://download.moodle.org/lang16/'.$pack.'.zip';
                             $a->dest= $CFG->dataroot.'/lang';
-                            error(get_string($cd->get_error(), 'error', $a));
+                            error(get_string($cd->get_error(), 'error', $a)); // not probable
                         } else {
-                            error(get_string($cd->get_error(), 'error'));
+                            error(get_string($cd->get_error(), 'error')); // not probable
                         }
                     break;
                     case UPTODATE:
                         //Print error string or whatever you want to do
                     break;
                     case INSTALLED:
-                        notify(get_string('langpackupdated','admin',$pack), 'notifysuccess');
+                        $notice_ok[] = get_string('langpackupdated', 'admin', $pack);
                         $updated = true;
                         //Print/do whatever you want
                     break;
             }
 
             if ($updated) {
-                notice(get_string('langupdatecomplete','admin'), 'langimport.php');
+                $notice_ok[] = get_string('langupdatecomplete','admin');
             } else {
-                notice(get_string('nolangupdateneeded','admin'), 'langimport.php');
+                $notice_ok[] = get_string('nolangupdateneeded','admin');
             }
 
         break;
+    }    //close of main switch
 
-        default:    //display choice mode
 
-            $source = 'http://download.moodle.org/lang16/languages.md5';
-            $remote = 0;    //flag for reading from remote or local
+    admin_externalpage_print_header();
 
-            if ($availablelangs = proxy_url($source)) {
-                $remote = 1;
-            } else {
-                $availablelangs = get_local_list_of_languages();
-            }
-/*
-            if ($fp = fopen($source, 'r')){    /// attempt to get the list from Moodle.org.
-                while(!feof ($fp)) {
-                    $availablelangs[] = split(',', fgets($fp,1024));
-                }
-                $remote = 1;    //can read from download.moodle.org
-            } else {    /// fopen failed, we find local copy of list.
-                $availablelangs = get_local_list_of_languages();
-            }
-*/
-            if (!$remote) {
-                print_box_start();
-                print_string('remotelangnotavailable','admin',$CFG->dataroot.'/lang/');
-                print_box_end();
-            }
+    $installedlangs = get_list_of_languages(true, true);
 
-            print_box_start();
-            echo '<table summary="">';
-            echo '<tr><td align="center" valign="top">';
-            echo '<form id="uninstallform" action="langimport.php?mode=4" method="post">';
-            echo '<fieldset class="invisiblefieldset">';
-            echo '<input name="sesskey" type="hidden" value="'.sesskey().'" />';
-            $installedlangs = get_list_of_languages(false, true);
+    if ($availablelangs = get_remote_list_of_languages()) {
+        $remote = 1;
+    } else {
+        $remote = 0;    //flag for reading from remote or local
+        $availablelangs = get_local_list_of_languages();
+    }
 
-            /// display installed langs here
+    if (!$remote) {
+        print_box_start();
+        print_string('remotelangnotavailable', 'admin', $CFG->dataroot.'/lang/');
+        print_box_end();
+    }
 
-            echo '<label for="uninstalllang">'.get_string('installedlangs','admin')."</label><br />\n";
-            echo '<select name="uninstalllang" id="uninstalllang" size="15">';
-            foreach ($installedlangs as $clang =>$ilang){
-                echo '<option value="'.$clang.'">'.$ilang.'</option>';
-            }
-            echo '</select>';
-            echo '<br /><input type="submit" value="'.get_string('uninstall','admin').'" />';
-            echo '</fieldset>';
-            echo '</form>';
-            echo '<form id="updateform" action="langimport.php?mode=5" method="post">';
-            echo '<div>';
-            echo '<br /><input type="submit" value="'.get_string('updatelangs','admin').'" />';
-            echo '</div>';
-            echo '</form>';
-
-            /// Display option to change site language
-
-            /// display to be installed langs here
-
-            echo '</td><td align="center" valign="top">';
-            //availabe langs table
-            $empty = 1;    //something to pring
-
-            /// if this language pack is not already installed, then we allow installation
-
-            echo '<form id="installform" method="post" action="langimport.php?mode=2">';
-            echo '<fieldset class="invisiblefieldset">';
-            echo '<input name="sesskey" type="hidden" value="'.sesskey().'" />';
-            echo '<label for="pack">'.get_string('availablelangs','admin')."</label><br />\n";
-            if ($remote) {
-                echo '<select name="pack" id="pack" size="15">';
-            }
+    if ($notice_ok) {
+        $info = implode('<br />', $notice_ok);
+        notify($info, 'notifysuccess');
+    }
 
-            foreach ($availablelangs as $alang) {
-                if (trim($alang[0]) != "en_utf8") {
-                    if ($remote){
-                        if (substr($alang[0], -5) == '_utf8') {   //Remove the _utf8 suffix from the lang to show
-                            $shortlang = substr($alang[0], 0, -5);
-                        } else {
-                            $shortlang = $alang[0];
-                        }
-                        if (!is_installed_lang($alang[0], $alang[1])){    //if not already installed
-                            echo '<option value="'.$alang[0].'">'.$alang[2].' ('.$shortlang.')</option>';
-                        }
-                    } else {    //print list in local format, and instruction to install
-                        echo '<tr><td>'.$alang[2].'</td><td><a href="http://download.moodle.org/lang16/'.$alang[0].'.zip">'.get_string('download','admin').'</a></td></tr>';
-                    }
-                    $empty = 0;
-                }
-            }
-            if ($remote) {
-                echo '</select>';
-                echo '<br /><input type="submit" value="'.$THEME->larrow.' '.get_string('install','admin').'" />';
-            }
-            echo '</fieldset>';
-            echo '</form>';
+    if ($notice_error) {
+        $info = implode('<br />', $notice_error);
+        notify($info, 'notifyproblem');
+    }
+
+    print_box_start();
+    echo '<table summary="">';
+    echo '<tr><td align="center" valign="top">';
+    echo '<form id="uninstallform" action="langimport.php?mode='.DELETION_OF_SELECTED_LANG.'" method="post">';
+    echo '<fieldset class="invisiblefieldset">';
+    echo '<input name="sesskey" type="hidden" value="'.sesskey().'" />';
+
+    /// display installed langs here
+
+    echo '<label for="uninstalllang">'.get_string('installedlangs','admin')."</label><br />\n";
+    echo '<select name="uninstalllang" id="uninstalllang" size="15">';
+    foreach ($installedlangs as $clang =>$ilang){
+        echo '<option value="'.$clang.'">'.$ilang.'</option>';
+    }
+    echo '</select>';
+    echo '<br /><input type="submit" value="'.get_string('uninstall','admin').'" />';
+    echo '</fieldset>';
+    echo '</form>';
+
+    if ($remote) {
+        echo '<form id="updateform" action="langimport.php?mode='.UPDATE_ALL_LANG.'" method="post">';
+        echo '<div>';
+        echo '<br /><input type="submit" value="'.get_string('updatelangs','admin').'" />';
+        echo '</div>';
+        echo '</form>';
+    }
+
+    /// Display option to change site language
+
+    /// display to be installed langs here
+
+    echo '</td><td align="center" valign="top">';
+    //availabe langs table
+    $empty = 1;    //something to pring
+
+    /// if this language pack is not already installed, then we allow installation
+
+    echo '<form id="installform" method="post" action="langimport.php?mode='.INSTALLATION_OF_SELECTED_LANG.'">';
+    echo '<fieldset class="invisiblefieldset">';
+    echo '<input name="sesskey" type="hidden" value="'.sesskey().'" />';
+    echo '<label for="pack">'.get_string('availablelangs','admin')."</label><br />\n";
+    if ($remote) {
+        echo '<select name="pack" id="pack" size="15">';
+    }
 
-            if ($empty) {
-                echo '<br />';
-                print_string('nolanguagetodownload','admin');
+    foreach ($availablelangs as $alang) {
+        if ($alang[0] == '') {
+            continue;
+        }
+        if (trim($alang[0]) != "en_utf8") {
+            if ($remote) {
+                if (substr($alang[0], -5) == '_utf8') {   //Remove the _utf8 suffix from the lang to show
+                    $shortlang = substr($alang[0], 0, -5);
+                } else {
+                    $shortlang = $alang[0];
+                }
+                if (!is_installed_lang($alang[0], $alang[1])){    //if not already installed
+                    echo '<option value="'.$alang[0].'">'.$alang[2].' ('.$shortlang.')</option>';
+                }
+            } else {    //print list in local format, and instruction to install
+                echo '<tr><td>'.$alang[2].'</td><td><a href="http://download.moodle.org/lang16/'.$alang[0].'.zip">'.get_string('download','admin').'</a></td></tr>';
             }
+            $empty = 0;
+        }
+    }
+    if ($remote) {
+        echo '</select>';
+        echo '<br /><input type="submit" value="'.$THEME->larrow.' '.get_string('install','admin').'" />';
+    }
+    echo '</fieldset>';
+    echo '</form>';
 
-            //close available langs table
-            echo '</td></tr></table>';
-            print_box_end();
-        break;
+    if ($empty) {
+        echo '<br />';
+        print_string('nolanguagetodownload','admin');
+    }
 
-    }    //close of main switch
+    //close available langs table
+    echo '</td></tr></table>';
+    print_box_end();
 
     admin_externalpage_print_footer();
 
-    /* returns a list of available language packs from a
+    /**
+     * Returns a list of available language packs from a
      * local copy shipped with standard moodle distro
      * this is for site that can't perform fopen
      * @return array
      */
     function get_local_list_of_languages() {
         global $CFG;
-        $source = $CFG->wwwroot.'/lib/languages.md5';
+        $source = $CFG->dirroot.'/lib/languages.md5';
         $availablelangs = array();
-        if ($fp = fopen($source, 'r')){
+        if ($fp = fopen($source, 'r')) {
             while(!feof ($fp)) {
                 $availablelangs[] = split(',', fgets($fp,1024));
             }
         return $availablelangs;
     }
 
-    /* checks the md5 of the zip file, grabbed from download.moodle.org,
+    /**
+     * checks the md5 of the zip file, grabbed from download.moodle.org,
      * against the md5 of the local language file from last update
      * @param string $lang
      * @param string $md5check
         return false;
     }
 
-    //returns an array of languages, or false if can not read from source
-    function proxy_url($url) {
-        global $CFG;
-
+    /**
+     * Returns the latest list of available language packs from
+     * moodle.org
+     * @return array or false if can not download
+     */
+    function get_remote_list_of_languages() {
+        $source = 'http://download.moodle.org/lang16/languages.md5';
         $availablelangs = array();
 
-        if( $content = download_file_content($url) ){
-
+        if ($content = download_file_content($source)) {
             $alllines = split("\n", $content);
-            foreach($alllines as $line){
-                if(!empty($line)){
+            foreach($alllines as $line) {
+                if (!empty($line)){
                     $availablelangs[] = split(',', $line);
                 }
             }
-
             return $availablelangs;
-        }else{
+
+        } else {
             return false;
         }
     }
index 1cd2368f9bc9f4024f134ee97f0ac585e6cf1657..18e8156ee3c80d665ed3385fb60179831e1318d0 100644 (file)
@@ -470,7 +470,7 @@ if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
         $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
         switch ($status) {
             case ERROR:
-                if ($cd->get_error() == 'remotedownloadnotallowed') {
+                if ($cd->get_error() == 'remotedownloaderror') {
                     $a = new stdClass();
                     $a->url = 'http://download.moodle.org/lang16/'.$pack.'.zip';
                     $a->dest= $CFG->dataroot.'/lang';
index 243e1551d0d425bc6a486f822bed894e290eca77..e565e5569f94a9ed5869ed38e095d31d965542ff 100644 (file)
@@ -124,6 +124,7 @@ postgres7
 previous
 qtyperqpwillberemoved
 qtyperqpwillberemovedanyway
+remotedownloaderror
 remotedownloadnotallowed
 report
 restricted
index 60627483c7218e10d9034edc6edeff0bfb740698..65c806965bd3bd26328fdd8dc43393ac931575de 100644 (file)
@@ -400,10 +400,12 @@ $string['langimportsuccess'] = 'Language pack successfully upgraded';
 $string['langlist'] = 'Languages on language menu';
 $string['langmenu'] = 'Display language menu';
 $string['langnoeditenglish'] = 'Can\'t overwrite the base english language pack. Please switch lang directory to make local changes';
+$string['langpackinstalled'] = 'Language pack $a was successfully installed';
 $string['langpackmaintaining'] = 'Language pack maintaining';
 $string['langpackremoved'] = 'Language pack was uninstalled';
 $string['langpacks'] = 'Language packs';
-$string['langpackupdated'] = 'Language pack $a was successfully installed';
+$string['langpackupdated'] = 'Language pack $a was successfully updated';
+$string['langpackupdateskipped'] = 'Update of $a language pack skipped';
 $string['langpackwillbeupdated'] = 'Note for translators: During the upgrade, Moodle will try to update your language pack. Your modifications in non-local language folders will be overwritten.';
 $string['langrmyourself'] = 'To prevent data loss, lang.php is not able to overwrite existing file with empty content. Please, remove the file manually in order to get rid of it.';
 $string['languagesettings'] = 'Language settings';
@@ -651,7 +653,7 @@ $string['uninstallconfirm'] = 'You are about to completely uninstall language pa
 $string['unsupported'] = 'Unsupported';
 $string['updateaccounts'] = 'Update existing accounts';
 $string['updatecomponent'] = 'Update Component';
-$string['updatelangs'] = 'Update all local language packs';
+$string['updatelangs'] = 'Update all installed language packs';
 $string['updatetimezones'] = 'Update timezones';
 $string['upgradeforumread'] = 'A new feature has been added in Moodle 1.5 to track read/unread forum posts.<br />To use this functionality you need to <a href=\"$a\">update your tables</a>.';
 $string['upgradeforumreadinfo'] = 'A new feature has been added in Moodle 1.5 to track read/unread forum posts.  To use this functionality you need to update your tables with all the tracking information for existing posts.  Depending on the size of your site this can take a long time (hours) and can be quite taxing on the database, so it\'s best to do it during a quiet period.  However, your site will continue functioning during this upgrade and users won\'t be affected.  Once you start this process you should let it finish (keep your browser window open).  However, if you stop the process by closing the window: don\'t worry, you can start over.<br /><br />Do you want to start the upgrading process now?';
index 56ec11b7d0e0f92060340e0be805e6d84fda48f4..001ce459d258635a96d70820d7a1afaf29c11da7 100644 (file)
@@ -83,6 +83,7 @@ $string['pagenotexist'] = 'An unusual error occurred (tried to reach a page that
 $string['pleasereport'] = 'If you have time, please let us know what you were trying to do when the error occurred:';
 $string['pluginrequirementsnotmet'] = 'Plugin \"$a->pluginname\" ($a->pluginversion) could not be installed.  It requires a newer version of Moodle (currently you are using $a->currentmoodle, you need $a->requiremoodle).';
 $string['processingstops'] = 'Processing stops here. Remaining records ignored.';
+$string['remotedownloaderror'] = 'Download of component to your server failed, please verify proxy settings, PHP cURL extension is highly recommended.<br /><br />You must download the <a href=\"$a->url\">$a->url</a> file manually, copy it to \"$a->dest\" in your server and unzip it there.';
 $string['remotedownloadnotallowed'] = 'Download of components to your server isn\'t allowed (allow_url_fopen is disabled).<br /><br />You must download the <a href=\"$a->url\">$a->url</a> file manually, copy it to \"$a->dest\" in your server and unzip it there.';
 $string['restricteduser'] = 'Sorry, but your current account \"$a\" is restricted from doing that.';
 $string['scheduledbackupsdisabled'] = 'Scheduled backups have been disabled by the server admin';
index e4e1758903aa2dee42ed5d4a6f8cd7e289cddb33..1130393d6e7616a1bb882edd20dc646427706e65 100644 (file)
@@ -7,7 +7,7 @@
 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
 //          http://moodle.com                                            //
 //                                                                       //
-// Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
+// Copyright (C) 1999 onwards Martin Dougiamas     http://dougiamas.com  //
 //           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
 //                                                                       //
 // This program is free software; you can redistribute it and/or modify  //
 // This library includes all the necessary stuff to use the one-click
 // download and install feature of Moodle, used to keep updated some
 // items like languages, pear, enviroment... i.e, components.
-// 
-// It has been developed harcoding some important limits that are 
+//
+// It has been developed harcoding some important limits that are
 // explained below:
 //    - It only can check, download and install items under moodledata.
 //    - Every downloadeable item must be one zip file.
 //    - The zip file root content must be 1 directory, i.e, everything
 //      is stored under 1 directory.
-//    - Zip file name and root directory must have the same name (but 
+//    - Zip file name and root directory must have the same name (but
 //      the .zip extension, of course).
 //    - Every .zip file must be defined in one .md5 file that will be
 //      stored in the same remote directory than the .zip file.
 //    - The name of such .md5 file is free, although it's recommended
-//      to use the same name than the .zip (that's the default 
+//      to use the same name than the .zip (that's the default
 //      assumption if no specified).
 //    - Every remote .md5 file will be a comma separated (CVS) file where each
 //      line will follow this format:
@@ -52,7 +52,6 @@
 //        - Will contain the md5 od the latest installed component
 // With all these details present, the process will perform this tasks:
 //    - Perform security checks. Only admins are allowed to use this for now.
-//    - Perform server checks. fopen must allow to open remote URLs.
 //    - Read the .md5 file from source (1).
 //    - Extract the correct line for the .zip being requested.
 //    - Compare it with the local .md5 file (2).
 //        - If different:
 //            - ERROR. Old package won't be modified. We shouldn't
 //              reach here ever.
-//    - If fopen is not available, a message text about how to do
-//      the process manually (remotedownloadnotallowed) must be
-//      built to explain it.
+//    - If component download is not possible, a message text about how to do
+//      the process manually (remotedownloaderror) must be displayed to explain it.
 //
 // General Usage:
 //
 // To install one component:
 //
 //     require_once($CFG->libdir.'/componentlib.class.php');
-//     if ($cd = new component_installer('http://download.moodle.org', 'lang16', 
+//     if ($cd = new component_installer('http://download.moodle.org', 'lang16',
 //                                       'es_utf8.zip', 'languages.md5', 'lang')) {
 //         $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
 //         switch ($status) {
-//             case ERROR: 
-//                 if ($cd->get_error() == 'remotedownloadnotallowed') {
+//             case ERROR:
+//                 if ($cd->get_error() == 'remotedownloaderror') {
 //                     $a = new stdClass();
 //                     $a->url = 'http://download.moodle.org/lang16/es_utf8.zip';
 //                     $a->dest= $CFG->dataroot.'/lang';
@@ -144,7 +142,7 @@ define('INSTALLED',       3);
 class component_installer {
 
     var $sourcebase;   /// Full http URL, base for downloadable items
-    var $zippath;      /// Relative path (from sourcebase) where the 
+    var $zippath;      /// Relative path (from sourcebase) where the
                        /// downloadeable item resides.
     var $zipfilename;  /// Name of the .zip file to be downloaded
     var $md5filename;  /// Name of the .md5 file to be read
@@ -166,12 +164,12 @@ class component_installer {
      * without performing any check at all.
      *
      * @param string Full http URL, base for downloadeable items
-     * @param string Relative path (from sourcebase) where the 
+     * @param string Relative path (from sourcebase) where the
      *               downloadeable item resides
      * @param string Name of the .zip file to be downloaded
-     * @param string Name of the .md5 file to be read (default '' = same 
+     * @param string Name of the .md5 file to be read (default '' = same
      *               than zipfilename)
-     * @param string Relative path (from moodledata) where the .zip file will 
+     * @param string Relative path (from moodledata) where the .zip file will
      *               be expanded (default='' = moodledataitself)
      * @return object
      */
@@ -193,8 +191,7 @@ class component_installer {
 
     /**
      * This function will check if everything is properly set to begin
-     * one installation. It'll check for fopen wrappers enabled and
-     * admin privileges. Also, it will check for required settings
+     * one installation. Also, it will check for required settings
      * and will fill everything as needed.
      *
      * @return boolean true/false (plus detailed error in errorstring)
@@ -204,11 +201,6 @@ class component_installer {
 
         $this->requisitesok = false;
 
-        /// Check for fopen remote enabled
-        if (!ini_get('allow_url_fopen')) {
-            $this->errorstring='remotedownloadnotallowed';
-            return false;
-        }
     /// Check that everything we need is present
         if (empty($this->sourcebase) || empty($this->zippath) || empty($this->zipfilename)) {
             $this->errorstring='missingrequiredfield';
@@ -231,7 +223,7 @@ class component_installer {
                 return false;
             }
         }
-    /// Calculate the componentnamea
+    /// Calculate the componentname
         $pos = stripos($this->zipfilename, '.zip');
         $this->componentname = substr($this->zipfilename, 0, $pos);
     /// Calculate md5filename if it's empty
@@ -304,7 +296,7 @@ class component_installer {
         $destinationdir = $CFG->dataroot.'/'.$this->destpath;
         $destinationcomponent = $destinationdir.'/'.$this->componentname;
         @remove_dir($destinationcomponent.'_old');     //Deleting possible old components before
-        @rename ($destinationcomponent, $destinationcomponent.'_old');  //Moving to a safe place  
+        @rename ($destinationcomponent, $destinationcomponent.'_old');  //Moving to a safe place
     /// Unzip new version
         if (!unzip_file($zipfile, $destinationdir, false)) {
         /// Error so, go back to the older
@@ -359,7 +351,7 @@ class component_installer {
        }
     }
 
-    /** 
+    /**
      * This function will change the zip file to install on the fly
      * to allow the class to process different components of the
      * same md5 file without intantiating more objects.
@@ -416,7 +408,9 @@ class component_installer {
         }
     /// Get all components of md5 file
         if (!$comp_arr = $this->get_all_components_md5()) {
-            $this->errorstring='cannotdownloadcomponents';
+            if (empty($this->errorstring)) {
+                $this->errorstring='cannotdownloadcomponents';
+            }
             return false;
         }
     /// Search for the componentname component
@@ -436,8 +430,8 @@ class component_installer {
         return $component[1];
     }
 
-    /** 
-     * This function allows you to retrieve the complete array of components found in 
+    /**
+     * This function allows you to retrieve the complete array of components found in
      * the md5filename
      *
      * @return array array of components in md5 file or false if error
@@ -493,12 +487,15 @@ class component_installer {
                 $this->cachedmd5components[$source] = $comp_arr;
             } else {
             /// Return error
-                $this->errorstring='cannotdownloadcomponents';
+                $this->errorstring='remotedownloaderror';
                 return false;
             }
         }
-    /// If there is no commponents, error
-        if (empty($comp_arr)) {
+    /// If there is no commponents or erros found, error
+        if (!empty($this->errorstring)) {
+             return false;
+
+        } else if (empty($comp_arr)) {
              $this->errorstring='cannotdownloadcomponents';
              return false;
         }
@@ -515,7 +512,7 @@ class component_installer {
     }
 
     /** This function returns the extramd5 field (optional in md5 file)
-     * 
+     *
      * @return string the extramd5 field
      */
     function get_extra_md5_field() {
index 5c9b16ba241dd8a17f885f5fd6a357520a0d76be..e18daf39b433dbe9c4a624cea36c4531b3fba721 100644 (file)
@@ -4,7 +4,7 @@ be_utf8,f38e8e0b312376eec708fd9f95aa04fb,Беларуская
 bg_utf8,676f4a9b93800c1cacbf9ca4ee5010b2,Български
 bs_utf8,9ad1de9a6ab3f54f59eeab8d7ce867d1,Bosanski
 ca_utf8,dbe5f8d6a111839a5d89533a5ce37815,Català
-cs_utf8,87ae11d3bac8effd71a06b43da80f401,Cestina
+cs_utf8,87ae11d3bac8effd71a06b43da80f401,Čeština
 da_utf8,066302a39241bfd7db7b3dfa0e53d658,Dansk
 de_du_utf8,c5cc95e33762bb1b4faba54824b383f6,Deutsch - Du
 de_utf8,d04fcaf901ae31a65c273211650c7239,Deutsch