1+ <?php
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+
30+ require_once ('../../lib/config.inc.php ' );
31+ require_once ('../../lib/app.inc.php ' );
32+
33+ //* Check permissions for module
34+ $ app ->auth ->check_module_permissions ('admin ' );
35+
36+ //* This is only allowed for administrators
37+ if (!$ app ->auth ->is_admin ()) die ('only allowed for administrators. ' );
38+
39+ $ app ->uses ('tpl ' );
40+
41+ $ app ->tpl ->newTemplate ('form.tpl.htm ' );
42+ $ app ->tpl ->setInclude ('content_tpl ' , 'templates/language_complete.htm ' );
43+
44+ //* reading languages
45+ $ language_option = '' ;
46+ $ error = '' ;
47+ $ msg = '' ;
48+ $ selected_language = (isset ($ _REQUEST ['lng_select ' ]))?substr ($ _REQUEST ['lng_select ' ],0 ,2 ):'en ' ;
49+ if (!preg_match ("/^[a-z]{2}$/i " , $ selected_language )) die ('unallowed characters in selected language name. ' );
50+
51+ $ handle = opendir (ISPC_ROOT_PATH .'/lib/lang/ ' );
52+ while ($ file = readdir ($ handle )) {
53+ if ($ file != '. ' && $ file != '.. ' ) {
54+ $ tmp_lng = substr ($ file ,0 ,-4 );
55+ if ($ tmp_lng !='' && $ tmp_lng != 'en ' ) {
56+ $ selected = ($ tmp_lng == $ selected_language )?'SELECTED ' :'' ;
57+ $ language_option .= "<option value=' $ tmp_lng' $ selected> $ tmp_lng</option> " ;
58+ //if(isset($_POST['lng_new']) && $_POST['lng_new'] == $tmp_lng) $error = 'Language exists already.';
59+ }
60+ }
61+ }
62+ $ app ->tpl ->setVar ('language_option ' ,$ language_option );
63+ $ app ->tpl ->setVar ('error ' ,$ error );
64+
65+ // Export the language file
66+ if (isset ($ _POST ['lng_select ' ]) && $ error == '' ) {
67+
68+ // complete the global langauge file
69+ merge_langfile (ISPC_LIB_PATH ."/lang/ " .$ selected_language .".lng " ,ISPC_LIB_PATH ."/lang/en.lng " );
70+
71+ // Go trough all language files
72+ $ bgcolor = '#FFFFFF ' ;
73+ $ language_files_list = array ();
74+ $ handle = @opendir (ISPC_WEB_PATH );
75+ while ($ file = @readdir ($ handle )) {
76+ if ($ file != '. ' && $ file != '.. ' ) {
77+ if (@is_dir (ISPC_WEB_PATH .'/ ' .$ file .'/lib/lang ' )) {
78+ $ handle2 = opendir (ISPC_WEB_PATH .'/ ' .$ file .'/lib/lang ' );
79+ while ($ lang_file = @readdir ($ handle2 )) {
80+ if ($ lang_file != '. ' && $ lang_file != '.. ' && substr ($ lang_file ,0 ,2 ) == 'en ' ) {
81+ $ target_lang_file = $ selected_language .substr ($ lang_file ,2 );
82+ merge_langfile (ISPC_WEB_PATH .'/ ' .$ file .'/lib/lang/ ' .$ target_lang_file ,ISPC_WEB_PATH .'/ ' .$ file .'/lib/lang/ ' .$ lang_file );
83+ }
84+ }
85+ }
86+ }
87+ }
88+ }
89+
90+ function merge_langfile ($ langfile ,$ masterfile ) {
91+ global $ msg ;
92+
93+ if (is_file ($ langfile )) {
94+
95+ // Load the english language file
96+ include ($ masterfile );
97+ if (isset ($ wb ) && is_array ($ wb )) {
98+ $ wb_master = $ wb ;
99+ unset($ wb );
100+ } else {
101+ $ wb_master = array ();
102+ }
103+
104+ // Load the incomplete language file
105+ $ wb = array ();
106+ include ($ langfile );
107+
108+ $ n = 0 ;
109+ foreach ($ wb_master as $ key => $ val ) {
110+ if (!isset ($ wb [$ key ])) {
111+ $ wb [$ key ] = $ val ;
112+ $ n ++;
113+ }
114+ }
115+
116+ $ file_content = "<?php \n" ;
117+ foreach ($ wb as $ key => $ val ) {
118+ $ val = str_replace ("' " ,'' ,$ val );
119+ $ val = str_replace ('" ' ,'' ,$ val );
120+ $ file_content .= '$wb[ ' ."' $ key' " .'] = ' ."' $ val'; \n" ;
121+ }
122+ $ file_content .= "?> \n" ;
123+
124+ $ msg .= "Added $ n lines to the file $ langfile<br /> " ;
125+ file_put_contents ($ langfile ,$ file_content );
126+ } else {
127+ $ msg .= "File does not exist yet. Copied file $ masterfile to $ langfile<br /> " ;
128+ copy ($ masterfile ,$ langfile );
129+ }
130+ }
131+
132+
133+
134+
135+ $ app ->tpl ->setVar ('msg ' ,$ msg );
136+
137+ //* load language file
138+ $ lng_file = 'lib/lang/ ' .$ _SESSION ['s ' ]['language ' ].'_language_complete.lng ' ;
139+ include ($ lng_file );
140+ $ app ->tpl ->setVar ($ wb );
141+
142+ $ app ->tpl_defaults ();
143+ $ app ->tpl ->pparse ();
144+
145+
146+ ?>
0 commit comments