Skip to content

Commit b7afdec

Browse files
committed
Added language file editor.
1 parent a6efc78 commit b7afdec

File tree

10 files changed

+1237
-0
lines changed

10 files changed

+1237
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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_add.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+
$handle = opendir(ISPC_ROOT_PATH.'/lib/lang/');
53+
while ($file = readdir ($handle)) {
54+
if ($file != '.' && $file != '..') {
55+
$tmp_lng = substr($file,0,-4);
56+
if($tmp_lng !='') {
57+
$selected = ($tmp_lng == $selected_language)?'SELECTED':'';
58+
$language_option .= "<option value='$tmp_lng' $selected>$tmp_lng</option>";
59+
if(isset($_POST['lng_new']) && $_POST['lng_new'] == $tmp_lng) $error = 'Language exists already.';
60+
}
61+
}
62+
}
63+
$app->tpl->setVar('language_option',$language_option);
64+
$app->tpl->setVar('error',$error);
65+
66+
if(isset($_POST['lng_new']) && strlen($_POST['lng_new']) == 2 && $error == '') {
67+
$lng_new = $_POST['lng_new'];
68+
if(!preg_match("/^[a-z]{2}$/i", $lng_new)) die('unallowed characters in language name.');
69+
70+
//* Make a copy of every language file
71+
$bgcolor = '#FFFFFF';
72+
$language_files_list = array();
73+
$handle = @opendir(ISPC_WEB_PATH);
74+
while ($file = @readdir ($handle)) {
75+
if ($file != '.' && $file != '..') {
76+
if(@is_dir(ISPC_WEB_PATH.'/'.$file.'/lib/lang')) {
77+
$handle2 = opendir(ISPC_WEB_PATH.'/'.$file.'/lib/lang');
78+
while ($lang_file = @readdir ($handle2)) {
79+
if ($lang_file != '.' && $lang_file != '..' && substr($lang_file,0,2) == $selected_language) {
80+
$new_lang_file = $lng_new.substr($lang_file,2);
81+
//echo ISPC_WEB_PATH.'/'.$file.'/lib/lang/'.$lang_file.' ## '.ISPC_WEB_PATH.'/'.$file.'/lib/lang/'.$new_lang_file;
82+
copy(ISPC_WEB_PATH.'/'.$file.'/lib/lang/'.$lang_file,ISPC_WEB_PATH.'/'.$file.'/lib/lang/'.$new_lang_file);
83+
$msg = 'Added new language '.$lng_new;
84+
}
85+
}
86+
}
87+
}
88+
}
89+
}
90+
91+
$app->tpl->setVar('msg',$msg);
92+
93+
//* load language file
94+
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_language_add.lng';
95+
include($lng_file);
96+
$app->tpl->setVar($wb);
97+
98+
$app->tpl_defaults();
99+
$app->tpl->pparse();
100+
101+
102+
?>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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_edit.htm');
46+
47+
$lang = $_REQUEST['lang'];
48+
$module = $_REQUEST['module'];
49+
$lang_file = $_REQUEST['lang_file'];
50+
51+
if(!preg_match("/^[a-z]+$/i", $lang)) die('unallowed characters in language name.');
52+
if(!preg_match("/^[a-z_]+$/i", $module)) die('unallowed characters in module name.');
53+
if(!preg_match("/^[a-z\._]+$/i", $lang_file)) die('unallowed characters in language file name.');
54+
55+
$msg = '';
56+
57+
//* Save data
58+
if(isset($_POST['records']) && is_array($_POST['records'])) {
59+
$file_content = "<?php\n";
60+
foreach($_POST['records'] as $key => $val) {
61+
$val = stripslashes($val);
62+
$val = str_replace("'",'',$val);
63+
$val = str_replace('"','',$val);
64+
$file_content .= '$wb['."'$key'".'] = '."'$val';\n";
65+
$msg = 'File saved.';
66+
}
67+
$file_content .= "?>\n";
68+
file_put_contents(ISPC_WEB_PATH."/$module/lib/lang/$lang_file" ,$file_content);
69+
}
70+
71+
72+
$app->tpl->setVar(array('module' => $module,'lang_file' => $lang_file, 'lang' => $lang, 'msg' => $msg));
73+
74+
include(ISPC_WEB_PATH."/$module/lib/lang/$lang_file");
75+
76+
$keyword_list = array();
77+
if(isset($wb) && is_array($wb)) {
78+
foreach($wb as $key => $val) {
79+
$keyword_list[] = array('key' => $key, 'val' => $val);
80+
}
81+
82+
$app->tpl->setLoop('records', $keyword_list);
83+
unset($wb);
84+
}
85+
86+
87+
//* load language file
88+
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_language_edit.lng';
89+
include($lng_file);
90+
$app->tpl->setVar($wb);
91+
92+
$app->tpl_defaults();
93+
$app->tpl->pparse();
94+
95+
96+
?>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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_list.htm');
46+
47+
48+
//* reading languages
49+
$language_option = '';
50+
$selected_language = (isset($_REQUEST['lng_select']))?substr($_REQUEST['lng_select'],0,2):'en';
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 !='') {
56+
$selected = ($tmp_lng == $selected_language)?'SELECTED':'';
57+
$language_option .= "<option value='$tmp_lng' $selected>$tmp_lng</option>";
58+
}
59+
}
60+
}
61+
$app->tpl->setVar('language_option',$language_option);
62+
// $app->tpl->setLoop('records', $language_list);
63+
64+
//* list all language files of the selected language
65+
$bgcolor = '#FFFFFF';
66+
$language_files_list = array();
67+
$handle = @opendir(ISPC_WEB_PATH);
68+
while ($file = @readdir ($handle)) {
69+
if ($file != '.' && $file != '..') {
70+
if(@is_dir(ISPC_WEB_PATH.'/'.$file.'/lib/lang')) {
71+
$handle2 = opendir(ISPC_WEB_PATH.'/'.$file.'/lib/lang');
72+
while ($lang_file = @readdir ($handle2)) {
73+
if ($lang_file != '.' && $lang_file != '..' && substr($lang_file,0,2) == $selected_language) {
74+
$bgcolor = ($bgcolor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF';
75+
$language_files_list[] = array( 'module' => $file,
76+
'lang_file' => $lang_file,
77+
'bgcolor' => $bgcolor,
78+
'lang' => $selected_language);
79+
}
80+
}
81+
}
82+
}
83+
}
84+
85+
$app->tpl->setLoop('records', $language_files_list);
86+
87+
88+
89+
90+
//* load language file
91+
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_language_list.lng';
92+
include($lng_file);
93+
$app->tpl->setVar($wb);
94+
95+
$app->tpl_defaults();
96+
$app->tpl->pparse();
97+
98+
99+
?>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$wb["list_head_txt"] = 'Add new language';
3+
$wb["language_select_txt"] = 'Select language basis';
4+
$wb["language_new_txt"] = 'New language';
5+
$wb['btn_save_txt'] = 'Create new language file set';
6+
$wb['btn_cancel_txt'] = 'Back';
7+
?>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
$wb['list_head_txt'] = 'Language file editor';
3+
$wb['language_select_txt'] = 'Select language';
4+
$wb['module_txt'] = 'Module';
5+
$wb['lang_file_txt'] = 'Language file';
6+
$wb['btn_save_txt'] = 'Save';
7+
$wb['btn_cancel_txt'] = 'Back';
8+
?>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
$wb["list_head_txt"] = 'Language file editor';
3+
$wb["language_select_txt"] = 'Select language';
4+
$wb["module_txt"] = 'Module';
5+
$wb["lang_file_txt"] = 'Language file';
6+
?>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br />
2+
<p class="frmText11">
3+
<tmpl_var name="language_select_txt">: <select name="lng_select">{tmpl_var name='language_option'}</select>
4+
<tmpl_var name="language_new_txt">: <input type="text" name="lng_new" value="" class="text" size="2" maxlength="2" />
5+
</p>
6+
<tmpl_if name="msg">
7+
<p class="msg" ><tmpl_var name="msg"></p>
8+
</tmpl_if>
9+
<tmpl_if name="error">
10+
<p class="error" ><tmpl_var name="error"></p>
11+
</tmpl_if>
12+
<input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/language_add.php');"><div class="buttonEnding"></div>
13+
<input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/language_list.php');"><div class="buttonEnding"></div>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br />
2+
<table width="100%" border="0" cellspacing="0" cellpadding="4">
3+
<tr>
4+
<td class="tblHead"><tmpl_var name="key_txt"></td>
5+
<td class="tblHead"><tmpl_var name="value_txt"></td>
6+
</tr>
7+
<tr>
8+
<td colspan="2">&nbsp;</td>
9+
</tr>
10+
<tmpl_loop name="records">
11+
<tr bgcolor="{tmpl_var name="bgcolor"}">
12+
<td class="frmText11">{tmpl_var name="key"}</td>
13+
<td class="frmText11"><input name="records[{tmpl_var name="key"}]" type="text" class="text" value="{tmpl_var name='val'}" size="50" maxlength="255"></td>
14+
</tr>
15+
</tmpl_loop>
16+
<tr>
17+
<td colspan="2">&nbsp;</td>
18+
</tr>
19+
<tmpl_if name="msg">
20+
<tr>
21+
<td class="msg" colspan="2"><tmpl_var name="msg"></td>
22+
</tr>
23+
<tr>
24+
<td colspan="2">&nbsp;</td>
25+
</tr>
26+
</tmpl_if>
27+
<tr>
28+
<td>&nbsp;</td>
29+
<td><input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/language_edit.php');"><div class="buttonEnding"></div>
30+
<input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/language_list.php?lng_select={tmpl_var name='lang'}');"><div class="buttonEnding"></div>
31+
</td>
32+
</tr>
33+
</table>
34+
<input type="hidden" name="lang" value="{tmpl_var name='lang'}">
35+
<input type="hidden" name="lang_file" value="{tmpl_var name='lang_file'}">
36+
<input type="hidden" name="module" value="{tmpl_var name='module'}">

0 commit comments

Comments
 (0)