This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
forked from BeehiveForum/BeehiveForum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bh_update_language.php
135 lines (87 loc) · 4.08 KB
/
bh_update_language.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
<?php
/*======================================================================
Copyright Project BeehiveForum 2002
This file is part of BeehiveForum.
BeehiveForum 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.
BeehiveForum 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 Beehive; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
======================================================================*/
// Constant to define where the include files are
define("BH_INCLUDE_PATH", "./forum/include/");
include_once(BH_INCLUDE_PATH. "format.inc.php");
// Prevent time out
set_time_limit(0);
// Output the content as text.
header('Content-Type: text/plain');
// Get our target language file.
if (isset($_SERVER['argv'][1]) && strlen(trim(stripslashes_array($_SERVER['argv'][1]))) > 0) {
$target_language_file = trim(stripslashes_array($_SERVER['argv'][1]));
if (!$lang_fix = file(BH_INCLUDE_PATH. "/languages/$target_language_file")) {
echo "Failed to load language file ($target_language_file). Check working directory and filename\n";
exit;
}
}else {
echo "No target language file specified";
exit;
}
// Get our optional updates file
if (isset($_SERVER['argv'][2]) && strlen(trim(stripslashes_array($_SERVER['argv'][2]))) > 0) {
$additions_file = trim(stripslashes_array($_SERVER['argv'][2]));
if (!$lang_add = file(BH_INCLUDE_PATH. "/languages/$additions_file")) {
$lang_add = array();
}
}else {
$lang_add = array();
}
if (@file_exists(BH_INCLUDE_PATH. "languages/en.inc.php")) {
$lang_en = file(BH_INCLUDE_PATH. "languages/en.inc.php");
foreach ($lang_en as $lang_en_line) {
$lang_en_line = trim($lang_en_line);
$line_matched = false;
$lang_matches = array();
if (preg_match('/^\$lang((\[[^\]]+\])+)/iu', $lang_en_line, $lang_matches)) {
foreach ($lang_add as $lang_add_line) {
$lang_add_line = trim($lang_add_line);
$preg_lang_add_match = preg_quote("\$lang{$lang_matches[1]}", "/");
$lang_add_matches = array();
if (preg_match("/^{$preg_lang_add_match}[^\"]+\"(.+)\";?/iu", $lang_add_line, $lang_add_matches)) {
if (isset($lang_add_matches[1]) && strlen(trim($lang_add_matches[1])) > 0) {
echo "\$lang{$lang_matches[1]} = \"{$lang_add_matches[1]}\";\n";
$line_matched = true;
break;
}
}
}
if ($line_matched === false) {
foreach ($lang_fix as $lang_fix_line) {
$lang_fix_line = trim($lang_fix_line);
$preg_lang_fix_match = preg_quote("\$lang{$lang_matches[1]}", "/");
$lang_fix_matches = array();
if (preg_match("/^{$preg_lang_fix_match}[^\"]+\"(.+)\";?/iu", $lang_fix_line, $lang_fix_matches)) {
if (isset($lang_fix_matches[1]) && strlen(trim($lang_fix_matches[1])) > 0) {
echo "\$lang{$lang_matches[1]} = \"{$lang_fix_matches[1]}\";\n";
$line_matched = true;
break;
}
}
}
}
}else {
echo "$lang_en_line\n";
$line_matched = true;
}
}
}else {
echo "Failed to load English language file (en.inc.php). Check working directory and filename";
exit;
}
?>