Till Brehm
2014-08-14 9edea9976bd605071e0694a90d704266c0b7e0f9
commit | author | age
a172b7 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';
a172b7 32
910093 33 //* Check permissions for module
T 34 $app->auth->check_module_permissions('admin');
9edea9 35 $app->auth->check_security_permissions('admin_allow_langedit');
a172b7 36
T 37 //* This is only allowed for administrators
38 if(!$app->auth->is_admin()) die('only allowed for administrators.');
91624b 39 if($conf['demo_mode'] == true) $app->error('This function is disabled in demo mode.');
a172b7 40
T 41 $app->uses('tpl');
42
43 $app->tpl->newTemplate('form.tpl.htm');
44 $app->tpl->setInclude('content_tpl', 'templates/language_export.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';
a172b7 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);
a172b7 57         if($tmp_lng !='') {
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);
a172b7 66
T 67 // Export the language file
68 if(isset($_POST['lng_select']) && $error == '') {
69     //$lng_select = $_POST['lng_select'];
70     //if(!preg_match("/^[a-z]{2}$/i", $lng_select)) die('unallowed characters in language name.');
7fe908 71
a172b7 72     // This variable contains the content of the language files
T 73     $content = '';
74     $content .= "---|ISPConfig Language File|".$conf["app_version"]."|".$selected_language."\n";
7fe908 75
a172b7 76     //* get the global language file
T 77     $content .= "--|global|".$selected_language."|".$selected_language.".lng\n";
78     $content .= file_get_contents(ISPC_LIB_PATH."/lang/".$selected_language.".lng")."\n";
7fe908 79
a172b7 80     //* Get the global file of the module
T 81     //$content .= "---|$module|$selected_language|\n";
82     //copy(ISPC_WEB_PATH."/$module/lib/lang/$selected_language.lng",ISPC_WEB_PATH."/$module/lib/lang/$lng_new.lng");
83     $bgcolor = '#FFFFFF';
84     $language_files_list = array();
7fe908 85     $handle = @opendir(ISPC_WEB_PATH);
MC 86     while ($file = @readdir($handle)) {
87         if ($file != '.' && $file != '..') {
88             if(@is_dir(ISPC_WEB_PATH.'/'.$file.'/lib/lang')) {
a172b7 89                 $handle2 = opendir(ISPC_WEB_PATH.'/'.$file.'/lib/lang');
7fe908 90                 while ($lang_file = @readdir($handle2)) {
MC 91                     if ($lang_file != '.' && $lang_file != '..' && substr($lang_file, 0, 2) == $selected_language) {
a172b7 92                         $content .= "--|".$file."|".$selected_language."|".$lang_file."\n";
T 93                         $content .= file_get_contents(ISPC_WEB_PATH.'/'.$file.'/lib/lang/'.$lang_file)."\n";
94                         $msg .= 'Exported language file '.$lang_file.'<br />';
95                     }
96                 }
97             }
98         }
99     }
7fe908 100
a172b7 101     $content .= '---|EOF';
7fe908 102
a172b7 103     // Write the language file
T 104     file_put_contents(ISPC_WEB_TEMP_PATH.'/'.$selected_language.'.lng', $content);
7fe908 105
a172b7 106     $msg = "Exported language file to: <a href='temp/$selected_language.lng' target='_blank'>/temp/".$selected_language.'.lng</a>';
7fe908 107
a172b7 108     //$msg = nl2br($content);
T 109 }
110
7fe908 111 $app->tpl->setVar('msg', $msg);
a172b7 112
7fe908 113 //* load language file
a172b7 114 $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_language_export.lng';
7fe908 115 include $lng_file;
a172b7 116 $app->tpl->setVar($wb);
T 117
118 $app->tpl_defaults();
119 $app->tpl->pparse();
120
121
7fe908 122 ?>