Till Brehm
2014-08-14 9edea9976bd605071e0694a90d704266c0b7e0f9
commit | author | age
8dd29e 1 <?php
T 2 /*
3 Copyright (c) 2008, Till Brehm, projektfarm Gmbh
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
8
9     * Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright notice,
12       this list of conditions and the following disclaimer in the documentation
13       and/or other materials provided with the distribution.
14     * Neither the name of ISPConfig nor the names of its contributors
15       may be used to endorse or promote products derived from this software without
16       specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
7fe908 30 require_once '../../lib/config.inc.php';
MC 31 require_once '../../lib/app.inc.php';
8dd29e 32
T 33 //* Check permissions for module
34 $app->auth->check_module_permissions('admin');
9edea9 35 $app->auth->check_security_permissions('admin_allow_langedit');
91624b 36 if($conf['demo_mode'] == true) $app->error('This function is disabled in demo mode.');
8dd29e 37
T 38 //* This is only allowed for administrators
39 if(!$app->auth->is_admin()) die('only allowed for administrators.');
40
41 $app->uses('tpl');
42
43 $app->tpl->newTemplate('form.tpl.htm');
44 $app->tpl->setInclude('content_tpl', 'templates/language_complete.htm');
45
46 //* reading languages
47 $language_option = '';
48 $error = '';
49 $msg = '';
7fe908 50 $selected_language = (isset($_REQUEST['lng_select']))?substr($_REQUEST['lng_select'], 0, 2):'en';
8dd29e 51 if(!preg_match("/^[a-z]{2}$/i", $selected_language)) die('unallowed characters in selected language name.');
T 52
7fe908 53 $handle = opendir(ISPC_ROOT_PATH.'/lib/lang/');
MC 54 while ($file = readdir($handle)) {
55     if ($file != '.' && $file != '..') {
56         $tmp_lng = substr($file, 0, -4);
8dd29e 57         if($tmp_lng !='' && $tmp_lng != 'en') {
T 58             $selected = ($tmp_lng == $selected_language)?'SELECTED':'';
59             $language_option .= "<option value='$tmp_lng' $selected>$tmp_lng</option>";
60             //if(isset($_POST['lng_new']) && $_POST['lng_new'] == $tmp_lng) $error = 'Language exists already.';
61         }
62     }
63 }
7fe908 64 $app->tpl->setVar('language_option', $language_option);
MC 65 $app->tpl->setVar('error', $error);
8dd29e 66
T 67 // Export the language file
68 if(isset($_POST['lng_select']) && $error == '') {
7fe908 69
8dd29e 70     // complete the global langauge file
7fe908 71     merge_langfile(ISPC_LIB_PATH."/lang/".$selected_language.".lng", ISPC_LIB_PATH."/lang/en.lng");
MC 72
8dd29e 73     // Go trough all language files
T 74     $bgcolor = '#FFFFFF';
75     $language_files_list = array();
7fe908 76     $handle = @opendir(ISPC_WEB_PATH);
MC 77     while ($file = @readdir($handle)) {
78         if ($file != '.' && $file != '..') {
79             if(@is_dir(ISPC_WEB_PATH.'/'.$file.'/lib/lang')) {
8dd29e 80                 $handle2 = opendir(ISPC_WEB_PATH.'/'.$file.'/lib/lang');
7fe908 81                 while ($lang_file = @readdir($handle2)) {
MC 82                     if ($lang_file != '.' && $lang_file != '..' && substr($lang_file, 0, 2) == 'en') {
83                         $target_lang_file = $selected_language.substr($lang_file, 2);
84                         merge_langfile(ISPC_WEB_PATH.'/'.$file.'/lib/lang/'.$target_lang_file, ISPC_WEB_PATH.'/'.$file.'/lib/lang/'.$lang_file);
8dd29e 85                     }
T 86                 }
dea284 87                 $handle2 = opendir(ISPC_WEB_PATH.'/'.$file.'/lib/lang');
7fe908 88                 while ($lang_file = @readdir($handle2)) {
MC 89                     if ($lang_file != '.' && $lang_file != '..' && substr($lang_file, 0, 2) == $selected_language) {
90                         $master_lang_file=ISPC_WEB_PATH.'/'.$file.'/lib/lang/en'.substr($lang_file, 2);
dea284 91                         $target_lang_file=ISPC_WEB_PATH.'/'.$file.'/lib/lang/'.$lang_file;
F 92                         if(!file_exists($master_lang_file)){
7fe908 93                             unlink($target_lang_file);
MC 94                             $msg.="File $target_lang_file removed because does not exist in master language<br />";
dea284 95                         }
F 96                     }
97                 }//Finish of remove the files how not exists in master language
8dd29e 98             }
T 99         }
100     }
7fe908 101     if($msg=='')
MC 102         $msg="No files created, removed or modified<br />";
8dd29e 103 }
T 104
7fe908 105 function merge_langfile($langfile, $masterfile) {
8dd29e 106     global $msg;
7fe908 107
8dd29e 108     if(is_file($langfile)) {
7fe908 109
8dd29e 110         // Load the english language file
7fe908 111         include $masterfile;
8dd29e 112         if(isset($wb) && is_array($wb)) {
T 113             $wb_master = $wb;
114             unset($wb);
115         } else {
116             $wb_master = array();
117         }
7fe908 118
8dd29e 119         // Load the incomplete language file
T 120         $wb = array();
7fe908 121         include $langfile;
MC 122
8dd29e 123         $n = 0;
T 124         foreach($wb_master as $key => $val) {
125             if(!isset($wb[$key])) {
126                 $wb[$key] = $val;
127                 $n++;
128             }
129         }
7fe908 130
c2d926 131         $r = 0;
F 132         foreach($wb as $key => $val) {
133             if(!isset($wb_master[$key])) {
134                 unset($wb[$key]);
135                 $r++;
136             }
137         }
7fe908 138
8dd29e 139         $file_content = "<?php\n";
T 140         foreach($wb as $key => $val) {
7fe908 141             $val = str_replace("'", "\\'", $val);
MC 142             $val = str_replace('"', '\"', $val);
8dd29e 143             $file_content .= '$wb['."'$key'".'] = '."'$val';\n";
T 144         }
145         $file_content .= "?>\n";
7fe908 146
15b753 147         if($n!=0)
7fe908 148             $msg .= "Added $n lines to the file $langfile<br />";
c2d926 149         if($r!=0)
7fe908 150             $msg .= "Removed $r lines to the file $langfile<br />";
MC 151         file_put_contents($langfile , $file_content);
8dd29e 152     } else {
T 153         $msg .= "File does not exist yet. Copied file $masterfile to $langfile<br />";
7fe908 154         copy($masterfile, $langfile);
8dd29e 155     }
T 156 }
157
7fe908 158 $app->tpl->setVar('msg', $msg);
8dd29e 159
7fe908 160 //* load language file
8dd29e 161 $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_language_complete.lng';
7fe908 162 include $lng_file;
8dd29e 163 $app->tpl->setVar($wb);
T 164
165 $app->tpl_defaults();
166 $app->tpl->pparse();
167
168
7fe908 169 ?>