Skip to content

Commit a172b75

Browse files
committed
Finished language editor.
1 parent d496758 commit a172b75

File tree

10 files changed

+313
-4
lines changed

10 files changed

+313
-4
lines changed

install/tpl/config.inc.php.master

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
Copyright (c) 2007, Till Brehm, Falko Timme, projektfarm Gmbh
3+
Copyright (c) 2008, Till Brehm, Falko Timme, projektfarm Gmbh
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without modification,
@@ -55,7 +55,7 @@ define('ISPC_CLASS_PATH', ISPC_ROOT_PATH.'/lib/classes');
5555
define('ISPC_WEB_PATH', ISPC_ROOT_PATH.'/web');
5656
define('ISPC_THEMES_PATH', ISPC_ROOT_PATH.'/web/themes');
5757

58-
define('ISPC_TEMP_PATH', ISPC_ROOT_PATH.'/temp');
58+
define('ISPC_WEB_TEMP_PATH', ISPC_WEB_PATH.'/temp'); // Path for downloads, accessible via browser
5959
define('ISPC_CACHE_PATH', ISPC_ROOT_PATH.'/cache');
6060

6161
//** Interface settings

interface/lib/config.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
define('ISPC_WEB_PATH', ISPC_ROOT_PATH.'/web');
4949
define('ISPC_THEMES_PATH', ISPC_ROOT_PATH.'/web/themes');
5050

51-
define('ISPC_TEMP_PATH', ISPC_ROOT_PATH.'/temp');
51+
define('ISPC_WEB_TEMP_PATH', ISPC_WEB_PATH.'/temp'); // Path for downloads, accessible via browser
5252
define('ISPC_CACHE_PATH', ISPC_ROOT_PATH.'/cache');
5353

5454
define('ISPC_INTERFACE_MODULES_ENABLED', 'mail,sites,dns');

interface/lib/lang/de.lng

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
$wb['301'] = 'Modul für User nicht erlaubt.';
3-
$wb['302'] = 'Modul ung�ltig.';
3+
$wb['302'] = 'Modul ungültig.';
44
$wb['303'] = ' ';
55
$wb['304'] = ' Dieses Formular dient zum Anlegen eines englischsprachigen Eintrags zus�tzlich zu Ihrem deutschen Eintrag. Bitte vervollst�ndigen Sie die Daten, soweit erforderlich, in Englisch - die Inhalte aus den Drop-Down-Men�s werden automatisch �bersetzt:';
66
$wb['1001'] = 'Der Benutzername und das Passwort d�rfen nicht leer sein!';
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
?>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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_import.htm');
46+
$msg = '';
47+
$error = '';
48+
49+
// Export the language file
50+
if(isset($_FILES['file']['name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
51+
$lines = file($_FILES['file']['tmp_name']);
52+
// initial check
53+
$parts = explode('|',$lines[0]);
54+
if($parts[0] == '---' && $parts[1] == 'ISPConfig Language File') {
55+
if($parts[2] != $conf["app_version"]) {
56+
$error .= 'Application version does not match. Appversion: '.$conf["app_version"].' Lanfile version: '.$parts[2];
57+
} else {
58+
unset($lines[0]);
59+
60+
$buffer = '';
61+
$langfile_path = '';
62+
// all other lines
63+
foreach($lines as $line) {
64+
$parts = explode('|',$line);
65+
if(is_array($parts) && count($parts) > 0 && $parts[0] == '--') {
66+
// Write language file, if its not the first file
67+
if($buffer != '' && $langfile_path != '') {
68+
if(@$_REQUEST['overwrite'] != 1 && @is_file($langfile_path)) {
69+
$error .= "File exists, not written: $langfile_path<br />";
70+
} else {
71+
$msg .= "File written: $langfile_path<br />";
72+
// file_put_contents($langfile_path,$buffer);
73+
}
74+
}
75+
// empty buffer and set variables
76+
$buffer = '';
77+
$module_name = $parts[1];
78+
$selected_language = $parts[2];
79+
$file_name = $parts[3];
80+
if(!preg_match("/^[a-z]{2}$/i", $selected_language)) die('unallowed characters in selected language name.');
81+
if(!preg_match("/^[a-z_]+$/i", $module_name)) die('unallowed characters in module name.');
82+
if(!preg_match("/^[a-z\._]+$/i", $file_name) || stristr($file_name,'..')) die('unallowed characters in language file name.');
83+
if($module_name == 'global') {
84+
$langfile_path = trim(ISPC_LIB_PATH."/lang/".$selected_language.".lng");
85+
} else {
86+
$langfile_path = trim(ISPC_WEB_PATH.'/'.$module_name.'/lib/lang/'.$file_name);
87+
}
88+
} else {
89+
$buffer .= $line;
90+
}
91+
}
92+
}
93+
}
94+
}
95+
96+
$app->tpl->setVar('msg',$msg);
97+
$app->tpl->setVar('error',$error);
98+
99+
//* load language file
100+
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_language_import.lng';
101+
include($lng_file);
102+
$app->tpl->setVar($wb);
103+
104+
$app->tpl_defaults();
105+
$app->tpl->pparse();
106+
107+
108+
?>
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"] = 'Export language files';
3+
$wb["language_select_txt"] = 'Select language';
4+
$wb['btn_save_txt'] = 'Export the selected language file set';
5+
$wb['btn_cancel_txt'] = 'Back';
6+
?>
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"] = 'Import language file';
3+
$wb["language_import_txt"] = 'Select language file';
4+
$wb['btn_save_txt'] = 'Import the selected language file';
5+
$wb["language_overwrite_txt"] = 'Overwrite file, if exists.';
6+
$wb['btn_cancel_txt'] = 'Back';
7+
?>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
</p>
5+
<tmpl_if name="msg">
6+
<p class="msg" ><tmpl_var name="msg"></p>
7+
</tmpl_if>
8+
<tmpl_if name="error">
9+
<p class="error" ><tmpl_var name="error"></p>
10+
</tmpl_if>
11+
<input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/language_export.php');"><div class="buttonEnding"></div>
12+
<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: 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_import_txt">: <input type="file" name="file" id="file" /><br />
4+
<tmpl_var name="language_overwrite_txt"> <input type="checkbox" name="overwrite" value="1" id="overwrite" />
5+
</p>
6+
<input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitUploadForm('pageForm','admin/language_import.php');"><div class="buttonEnding"></div>
7+
<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>
8+
<tmpl_if name="error">
9+
<p class="error" ><tmpl_var name="error"></p>
10+
</tmpl_if>
11+
<tmpl_if name="msg">
12+
<p class="msg" ><tmpl_var name="msg"></p>
13+
</tmpl_if>

interface/web/js/scrigo.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,46 @@ function submitForm(formname,target) {
107107
*/
108108
}
109109

110+
function submitUploadForm(formname,target) {
111+
112+
var submitFormCallback = {
113+
success: function(o) {
114+
if(o.responseText.indexOf('HEADER_REDIRECT:') > -1) {
115+
var parts = o.responseText.split(':');
116+
//alert(parts[1]);
117+
loadContent(parts[1]);
118+
//redirect = parts[1];
119+
//window.setTimeout('loadContent(redirect)', 1000);
120+
} else {
121+
document.getElementById('pageContent').innerHTML = o.responseText;
122+
}
123+
},
124+
upload: function(o) {
125+
if(o.responseText.indexOf('HEADER_REDIRECT:') > -1) {
126+
var parts = o.responseText.split(':');
127+
//alert(parts[1]);
128+
loadContent(parts[1]);
129+
//redirect = parts[1];
130+
//window.setTimeout('loadContent(redirect)', 1000);
131+
} else {
132+
document.getElementById('pageContent').innerHTML = o.responseText;
133+
}
134+
},
135+
failure: function(o) {
136+
alert('Ajax Request was not successful. 1');
137+
}
138+
}
139+
140+
YAHOO.util.Connect.setForm(formname,true);
141+
var submitFormObj = YAHOO.util.Connect.asyncRequest('POST', target, submitFormCallback);
142+
/*
143+
if(redirect != '') {
144+
loadContent(redirect);
145+
redirect = '';
146+
}
147+
*/
148+
}
149+
110150
function loadContent(pagename) {
111151
var pageContentCallback2 = {
112152
success: function(o) {

0 commit comments

Comments
 (0)