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+ // Checking permissions for the module
34+ if (!stristr ($ _SESSION ['s ' ]['user ' ]['modules ' ],'admin ' )) {
35+ header ('Location: ../index.php ' );
36+ exit ;
37+ }
38+
39+ //* This is only allowed for administrators
40+ if (!$ app ->auth ->is_admin ()) die ('only allowed for administrators. ' );
41+
42+ $ app ->uses ('tpl ' );
43+
44+ $ app ->tpl ->newTemplate ('form.tpl.htm ' );
45+ $ app ->tpl ->setInclude ('content_tpl ' , 'templates/language_export.htm ' );
46+
47+ //* reading languages
48+ $ language_option = '' ;
49+ $ error = '' ;
50+ $ msg = '' ;
51+ $ selected_language = (isset ($ _REQUEST ['lng_select ' ]))?substr ($ _REQUEST ['lng_select ' ],0 ,2 ):'en ' ;
52+ if (!preg_match ("/^[a-z]{2}$/i " , $ selected_language )) die ('unallowed characters in selected language name. ' );
53+
54+ $ handle = opendir (ISPC_ROOT_PATH .'/lib/lang/ ' );
55+ while ($ file = readdir ($ handle )) {
56+ if ($ file != '. ' && $ file != '.. ' ) {
57+ $ tmp_lng = substr ($ file ,0 ,-4 );
58+ if ($ tmp_lng !='' ) {
59+ $ selected = ($ tmp_lng == $ selected_language )?'SELECTED ' :'' ;
60+ $ language_option .= "<option value=' $ tmp_lng' $ selected> $ tmp_lng</option> " ;
61+ //if(isset($_POST['lng_new']) && $_POST['lng_new'] == $tmp_lng) $error = 'Language exists already.';
62+ }
63+ }
64+ }
65+ $ app ->tpl ->setVar ('language_option ' ,$ language_option );
66+ $ app ->tpl ->setVar ('error ' ,$ error );
67+
68+ // Export the language file
69+ if (isset ($ _POST ['lng_select ' ]) && $ error == '' ) {
70+ //$lng_select = $_POST['lng_select'];
71+ //if(!preg_match("/^[a-z]{2}$/i", $lng_select)) die('unallowed characters in language name.');
72+
73+ // This variable contains the content of the language files
74+ $ content = '' ;
75+ $ content .= "---|ISPConfig Language File| " .$ conf ["app_version " ]."| " .$ selected_language ."\n" ;
76+
77+ //* get the global language file
78+ $ content .= "--|global| " .$ selected_language ."| " .$ selected_language .".lng \n" ;
79+ $ content .= file_get_contents (ISPC_LIB_PATH ."/lang/ " .$ selected_language .".lng " )."\n" ;
80+
81+ //* Get the global file of the module
82+ //$content .= "---|$module|$selected_language|\n";
83+ //copy(ISPC_WEB_PATH."/$module/lib/lang/$selected_language.lng",ISPC_WEB_PATH."/$module/lib/lang/$lng_new.lng");
84+ $ bgcolor = '#FFFFFF ' ;
85+ $ language_files_list = array ();
86+ $ handle = @opendir (ISPC_WEB_PATH );
87+ while ($ file = @readdir ($ handle )) {
88+ if ($ file != '. ' && $ file != '.. ' ) {
89+ if (@is_dir (ISPC_WEB_PATH .'/ ' .$ file .'/lib/lang ' )) {
90+ $ handle2 = opendir (ISPC_WEB_PATH .'/ ' .$ file .'/lib/lang ' );
91+ while ($ lang_file = @readdir ($ handle2 )) {
92+ if ($ lang_file != '. ' && $ lang_file != '.. ' && substr ($ lang_file ,0 ,2 ) == $ selected_language ) {
93+ $ content .= "--| " .$ file ."| " .$ selected_language ."| " .$ lang_file ."\n" ;
94+ $ content .= file_get_contents (ISPC_WEB_PATH .'/ ' .$ file .'/lib/lang/ ' .$ lang_file )."\n" ;
95+ $ msg .= 'Exported language file ' .$ lang_file .'<br /> ' ;
96+ }
97+ }
98+ }
99+ }
100+ }
101+
102+ $ content .= '---|EOF ' ;
103+
104+ // Write the language file
105+ file_put_contents (ISPC_WEB_TEMP_PATH .'/ ' .$ selected_language .'.lng ' , $ content );
106+
107+ $ msg = "Exported language file to: <a href='temp/ $ selected_language.lng' target='_blank'>/temp/ " .$ selected_language .'.lng</a> ' ;
108+
109+ //$msg = nl2br($content);
110+ }
111+
112+ $ app ->tpl ->setVar ('msg ' ,$ msg );
113+
114+ //* load language file
115+ $ lng_file = 'lib/lang/ ' .$ _SESSION ['s ' ]['language ' ].'_language_export.lng ' ;
116+ include ($ lng_file );
117+ $ app ->tpl ->setVar ($ wb );
118+
119+ $ app ->tpl_defaults ();
120+ $ app ->tpl ->pparse ();
121+
122+
123+ ?>
0 commit comments