-
Notifications
You must be signed in to change notification settings - Fork 19
/
lm.php
424 lines (364 loc) · 13.5 KB
/
lm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#!/usr/local/bin/php -q
<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 2.1 |
// +---------------------------------------------------------------------------+
// | lm.php |
// | |
// | Update a language file by merging it with english.php |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2004-2018 by the following authors: |
// | |
// | Author: Dirk Haun - dirk AT haun-online DOT de |
// +---------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+
$VERSION = '1.0.7';
define('ROOT', dirname(dirname(dirname(__DIR__))) . '/');
// Prevent PHP from reporting uninitialized variables
//error_reporting(E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
error_reporting(-1);
// name of the language file should be passed on the command line
$langfile = $GLOBALS['argv'][1];
if (empty($langfile)) {
echo "lm.php v{$VERSION}\n";
echo "This is free software; see the source for copying conditions.\n\n";
echo "Usage: {$GLOBALS['argv'][0]} langfile.php [module] > new-langfile.php\n\n";
exit;
}
$module = '';
if (!empty($GLOBALS['argv'][2])) {
$module = $GLOBALS['argv'][2];
}
$mb = false;
if (strpos($langfile, '_utf-8') !== false) {
$mb = true;
if (!function_exists('mb_strpos')) {
echo "Sorry, this script needs a PHP version that has multibyte support compiled in.\n\n";
exit;
} elseif (!function_exists('mb_ereg_replace')) {
echo "Sorry, this script needs a PHP version with the mb_ereg_replace function compiled in.\n\n";
exit;
}
mb_regex_encoding('UTF-8');
mb_internal_encoding('UTF-8');
}
define('XHTML', '');
define('TOPIC_ALL_OPTION', 'all');
define('TOPIC_NONE_OPTION', 'none');
define('TOPIC_HOMEONLY_OPTION', 'homeonly');
define('TOPIC_SELECTED_OPTION', 'selectedtopics');
define('TOPIC_ROOT', 'root');
define('RECAPTCHA_NO_SUPPORT', 0);
define('RECAPTCHA_SUPPORT_V2', 1);
define('RECAPTCHA_SUPPORT_V2_INVISIBLE', 2);
// list of all variables accessed in the language file
$_DB_mysqldump_path = '{$_DB_mysqldump_path}';
$_CONF['backup_path'] = '{$_CONF[\'backup_path\']}';
$_CONF['commentspeedlimit'] = '{$_CONF[\'commentspeedlimit\']}';
$_CONF['site_admin_url'] = '{$_CONF[\'site_admin_url\']}';
$_CONF['site_name'] = '{$_CONF[\'site_name\']}';
$_CONF['site_url'] = '{$_CONF[\'site_url\']}';
$_CONF['speedlimit'] = '{$_CONF[\'speedlimit\']}';
$_CONF['invalidloginattempts'] = '{$_CONF[\'invalidloginattempts\']}';
$_CONF['invalidloginmaxtime'] = '{$_CONF[\'invalidloginmaxtime\']}';
$_USER['username'] = '{$_USER[\'username\']}';
$failures = '{$failures}';
$from = '{$from}';
$fromemail = '{$fromemail}';
$qid = '{$qid}';
$shortmsg = '{$shortmsg}';
$successes = '{$successes}';
$topic = '{$topic}';
$type = '{$type}';
// names of constants to be used in the configselect arrays
$config_constants = array(
'TOPIC_ALL_OPTION', 'TOPIC_HOMEONLY_OPTION', 'TOPIC_SELECTED_OPTION',
);
// load the English language file
if (empty($module)) {
require_once ROOT . 'language/english.php';
} elseif ($module == 'install') {
require_once ROOT . 'public_html/admin/install/language/english.php';
} else {
require_once ROOT . 'plugins/' . $module . '/language/english.php';
}
function separator()
{
echo "###############################################################################\n";
}
function separatorThin()
{
echo "// +---------------------------------------------------------------------------+\n";
}
/**
* My mb-save replacement for some(!) string replacements
*/
function my_str_replace($s1, $s2, $s3)
{
global $mb;
if ($mb) {
return mb_ereg_replace($s1, $s2, $s3);
} else {
return str_replace($s1, $s2, $s3);
}
}
/**
* My mb-save replacement for some(!) use cases of strpos
*/
function my_strpos($s1, $s2)
{
global $mb;
if ($mb) {
return mb_strpos($s1, $s2);
} else {
return strpos($s1, $s2);
}
}
/**
* Make <br> and <hr> tags XHTML compliant
*/
function makeXHTML($txt)
{
global $mb, $module;
// fix accidentally created <brXHTML> tags in some 1.5.0b1 language files
$txt = my_str_replace('brXHTML', 'br', $txt);
if ($mb) {
$fc = mb_substr($txt, 0, 1);
} else {
$fc = substr($txt, 0, 1);
}
if ($module !== 'install') {
$txt = my_str_replace('<br>',
'<br' . $fc . ' . XHTML . ' . $fc . '>', $txt);
$txt = my_str_replace('<hr>',
'<hr' . $fc . ' . XHTML . ' . $fc . '>', $txt);
}
return $txt;
}
function prepareText($newText)
{
global $mb;
if (my_strpos($newText, '{$') === false) {
if (my_strpos($newText, '\n') === false) {
// text contains neither variables nor line feeds,
// so enclose it in single quotes
$newText = my_str_replace("'", "\'", $newText);
$quotedText = "'" . $newText . "'";
} else {
// text contains line feeds - enclose in double quotes so
// they can be interpreted
$newText = my_str_replace('"', '\"', $newText);
$quotedText = '"' . $newText . '"';
}
} else {
// text contains variables
if ($mb) {
$newText = mb_ereg_replace('\$', '\$', $newText);
// backslash attack!
$newText = mb_ereg_replace('\{\\\\\$', '{$', $newText);
$newText = mb_ereg_replace('"', '\"', $newText);
} else {
$newText = str_replace('$', '\$', $newText);
$newText = str_replace('{\$', '{$', $newText);
$newText = str_replace('"', '\"', $newText);
}
$quotedText = '"' . $newText . '"';
}
return $quotedText;
}
/**
* Merge two language arrays
* This function does all the work. Any missing text strings are copied
* over from english.php. Also does some pretty-printing.
*/
function mergeArrays($ENG, $OTHER, $arrayName, $comment = '')
{
global $mb, $config_constants;
$numElements = count($ENG);
$counter = 0;
if ($comment !== false) {
separator();
}
if (!empty($comment)) {
$comments = explode("\n", $comment);
foreach ($comments as $c) {
echo "# $c\n";
}
}
echo "\n\${$arrayName} = array(\n";
foreach ($ENG as $key => $txt) {
$counter++;
if (is_numeric($key)) {
echo " $key => ";
} else {
echo " '$key' => ";
}
if (empty($OTHER[$key])) {
// string does not exist in other language - use English text
$newText = $txt;
} else {
if (isset($ENG[$key]) && empty($ENG[$key])) {
// string is now empty in English language file - remove it
$newText = '';
} else {
// string exists in other language - keep it
$newText = $OTHER[$key];
}
}
if (!is_array($newText)) {
$newText = my_str_replace("\n", '\n', $newText);
}
if (is_array($newText)) { // mainly for the config selects
if (!empty($OTHER[$key]) && (count($ENG[$key]) != count($OTHER[$key]))) {
// In case there are new entries for a config, merge those
// into the existing one to keep the translation intact.
// Note: We can't use array_merge() or "+" since we want to
// keep the original order intact.
$newText = array();
foreach ($ENG[$key] as $eKey => $eValue) {
$oKey = array_search($eValue, $OTHER[$key], true);
if ($oKey === false) {
$newText[$eKey] = $eValue;
} else {
$newText[$oKey] = $eValue;
}
}
}
$quotedText = 'array(';
foreach ($newText as $nKey => $nTxt) {
$quotedText .= "'" . my_str_replace("'", "\'", $nKey) . "' => ";
if ($nTxt === true) {
$quotedText .= 'true';
} elseif ($nTxt === false) {
$quotedText .= 'false';
} elseif (is_numeric($nTxt)) {
$quotedText .= $nTxt;
} elseif (in_array($nTxt, $config_constants)) {
$quotedText .= $nTxt;
} else {
$quotedText .= "'" . my_str_replace("'", "\'", $nTxt) . "'";
}
$quotedText .= ', ';
}
if ($mb) {
$quotedText = mb_substr($quotedText, 0, -2);
} else {
$quotedText = substr($quotedText, 0, -2);
}
$quotedText .= ')';
// hack for this special case ...
if ($quotedText == "array('True' => 1, 'False' => '')") {
$quotedText = "array('True' => TRUE, 'False' => FALSE)";
}
// ??? $quotedText = mb_ereg_replace("\n", '\n', $quotedtext);
} else {
$quotedText = prepareText($newText);
}
$quotedText = makeXHTML($quotedText);
if ($counter != $numElements) {
$quotedText .= ',';
}
echo "$quotedText\n";
}
if ($comment === false) {
echo ");\n";
} else {
echo ");\n\n";
}
}
function mergeString($eng, $other, $name)
{
global $mb;
if (empty($other)) {
$newText = $eng;
} else {
$newText = $other;
}
$prepareText = prepareText($newText);
$prepareText = makeXHTML($prepareText);
echo "\$$name = $prepareText;\n";
}
/**
* Read the credits / copyright from the other language file.
* Assumes that it starts and ends with a separator line of # signs.
*/
function readCredits($langfile)
{
$credits = array();
$firstComment = false;
$fh = fopen($langfile, 'r');
if ($fh !== false) {
while (true) {
$line = fgets($fh);
if ($firstComment) {
$credits[] = $line;
if (strstr($line, '#####') !== false) {
// end of credits reached
break;
} elseif (strstr($line, '*/') !== false) {
// end of credits reached, Spam-X style
break;
} elseif (strstr($line, '+-----') !== false) {
$nextLine = fgets($fh);
$tst = trim($nextLine);
if (empty($tst)) {
// end of credits reached, install script style
break;
} else {
$credits[] = $nextLine;
}
}
} else {
if (strstr($line, '#####') !== false) {
// start of credits
$firstComment = true;
$credits[] = $line;
} elseif (strstr($line, '/**') !== false) {
// start of credits, Spam-X style
$firstComment = true;
$credits[] = $line;
} elseif (strstr($line, '/* Reminder:') !== false) {
// start of credits, install script style
$firstComment = true;
$credits[] = $line;
}
}
}
fclose($fh);
}
// ensure rebranding extends to the credits :)
$cSize = count($credits);
for ($i = 0; $i < $cSize; $i++) {
$credits[$i] = str_replace('GeekLog', 'Geeklog', $credits[$i]);
}
return ($credits);
}
// MAIN
$credits = readCredits($langfile);
// output starts here ...
echo "<?php\n\n";
foreach ($credits as $c) {
echo "$c"; // Note: line feeds are part of the credits
}
// load the module file which does the rest
if (empty($module)) {
require_once __DIR__ . '/include/core.inc';
} else {
require_once __DIR__ . '/include/' . $module . '.inc';
}