forked from coppermine-gallery/cpg1.6.x
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlang_check.php
232 lines (215 loc) · 5.63 KB
/
lang_check.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
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2016 Coppermine Dev Team
v1.0 originally written by Gregory Demar
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3
as published by the Free Software Foundation.
********************************************
Coppermine version: 1.6.01
$HeadURL$
**********************************************/
define('IN_COPPERMINE', true);
define('SMILIES_PHP', true);
define('ALBMGR_PHP', true);
define('BANNING_PHP', true);
define('BRIDGEMGR_PHP', true);
define('CALENDAR_PHP', true);
define('CATMGR_PHP', true);
define('CONTACT_PHP', true);
define('ADMIN_PHP', true);
define('DB_ECARD_PHP', true);
define('DB_INPUT_PHP', true);
define('DELETE_PHP', true);
define('DISPLAYIMAGE_PHP', true);
define('ECARDS_PHP', true);
define('REPORT_FILE_PHP', true);
define('EDITPICS_PHP', true);
define('FORGOT_PASSWD_PHP', true);
define('GROUPMGR_PHP', true);
define('INDEX_PHP', true);
define('INSTALL_PHP', true);
define('KEYWORDMGR_PHP', true);
define('LANGMGR_PHP', true);
define('LOGIN_PHP', true);
define('LOGOUT_PHP', true);
define('MINIBROWSER_PHP', true);
define('MODE_PHP', true);
define('MODIFYALB_PHP', true);
define('PHPINFO_PHP', true);
define('PICMGR_PHP', true);
define('PLUGINMGR_PHP', true);
define('RATEPIC_PHP', true);
define('REGISTER_PHP', true);
define('PROFILE_PHP', true);
define('REVIEWCOM_PHP', true);
define('SIDEBAR_PHP', true);
define('SEARCH_PHP', true);
define('SEARCHNEW_PHP', true);
define('SEND_ACTIVATION_PHP', true);
define('STAT_DETAILS_PHP', true);
define('UPLOAD_PHP', true);
define('UPLOAD_H5A', true);
define('USERMGR_PHP', true);
define('UPDATE_PHP', true);
define('UTIL_PHP', true);
define('VERSIONCHECK_PHP', true);
define('VIEWLOG_PHP', true);
//define('XP_PUBLISH_PHP', true);
class Lang
{
public $vars;
public function __construct ($lang='english.php')
{
require "lang/{$lang}";
$this->vars = get_defined_vars();
}
}
$action = !empty($_GET['act']) ? $_GET['act'] : null;
$opt_chk = $action=='chk' ? ' selected' : '';
$opt_scn = $action=='scn' ? ' selected' : '';
echo <<<EOT
<!DOCTYPE html>
<html>
<head>
<title>Language File Check for Coppermine Photo Gallery</title>
<style>
div {
padding:6px;
border:1px solid #CCC;
background-color:#FFE;
overflow-x: scroll;
}
h2 {
margin-top:4px;
}
h3 {
margin-bottom:0;
text-decoration:underline;
}
code {
white-space:nowrap;
}
.lvl1 {
margin-left:2em;
}
.lvl2 {
margin-left:4em;
}
div.aform {
background-color:#EEF;
padding-top:.7em;
padding-bottom:.7em;
}
</style>
</head>
<body>
<div class="aform">
<form action="">
<select name="act">
<option value="chk"{$opt_chk}>Check other languages against English</option>
<option value="scn"{$opt_scn}>Scan PHP files for language useage</option>
</select>
<button type="submit" name="doit" value="1">Perform Action</button>
</form>
</div><br />
EOT;
if ($action) $en = new Lang();
if ($action == 'scn') {
$eno = new Lang();
$enMissing = array();
scanForUsage($en, '.');
if ($enMissing) {
echo '<div><h3>Language references that are not in english.php</h3><br />';
foreach ($enMissing as $l=>$fr) {
echo '<b>File:</b> '.$fr[0].'<br />';
echo '<b>Ref:</b> '.$l.' [ '.$fr[1].' ]<br /><br />';
}
echo '</div><br />';
}
echo '<div><h3>Language string definitions (in english.php) that were not directly referenced in any PHP file</h3><br />';
splay($en->vars);
echo'</div>';
} elseif ($action == 'chk') {
$langs = array();
foreach (scandir('lang') as $f) {
if ($f[0] === '.') continue;
if (substr($f, 0, 7) === 'english') continue;
$langs[] = $f;
}
foreach ($langs as $lang) {
$lobj = new Lang($lang);
echo '<div><h2>Language file: '.$lang.'</h2>';
$misses = array_diff_key_recursive($en->vars, $lobj->vars);
if ($misses) {
echo "<h3>Missing translations.</h3><br />";
splay($misses);
}
$misses = array_diff_key_recursive($lobj->vars, $en->vars);
if ($misses) {
echo "<h3>Translations that could (possibly) be removed.</h3><br />";
splay($misses);
}
echo '</div><br /><br />';
}
}
function splay ($nodes, $ind=0)
{
foreach ($nodes as $k=>$var) {
if ($var) {
if ($ind) {
echo '<span class="lvl'.$ind.'">["'.$k.'"]</span>';
echo is_array($var) ? '<br />' : ' => ';
} else {
echo '<b>Group:</b> '.$k.'<br />';
}
if (is_array($var)) {
splay($var, $ind+1);
} else {
$sc = $ind ? '' : 'lvl1';
echo '<span class="'.$sc.'">"<code>'.htmlentities($var).'</code>"</span><br />';
}
if (!$ind) echo '<br />';
}
}
}
function array_diff_key_recursive (array $arr1, array $arr2)
{
$diff = array_diff_key($arr1, $arr2);
$intersect = array_intersect_key($arr1, $arr2);
foreach ($intersect as $k => $v) {
if (is_array($arr1[$k]) && is_array($arr2[$k])) {
$d = array_diff_key_recursive($arr1[$k], $arr2[$k]);
if ($d) {
$diff[$k] = $d;
}
}
}
return $diff;
}
function scanForUsage (&$en, $dir)
{
global $eno, $enMissing;
foreach (scandir($dir) as $f) {
if ($f[0] === '.') continue;
$fpath = ($dir=='.'?'':($dir.'/')).$f;
if (is_dir($fpath)) {
if ($fpath!='lang') scanForUsage($en, $fpath);
} else {
if (substr($f, -4) != '.php') continue;
preg_match_all('|\$lang_([^\s\[]+)\[[\'"](\w+)[\'"]\]|', file_get_contents($fpath), $mtchs, PREG_SET_ORDER);
foreach ($mtchs as $mtch) {
if (isset($eno->vars['lang_'.$mtch[1]][$mtch[2]])) {
unset($en->vars['lang_'.$mtch[1]][$mtch[2]]);
} else {
if (substr($mtch[1],0,7) != 'plugin_') $enMissing['lang_'.$mtch[1]] = array($fpath,$mtch[2]);
}
}
}
}
}
?>
</body>
</html>