Subversion Repositories oidplus

Rev

Rev 366 | Rev 557 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
366 daniel-mar 1
#!/usr/bin/php
360 daniel-mar 2
<?php
3
 
4
/*
5
 * OIDplus 2.0
511 daniel-mar 6
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
360 daniel-mar 7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
 
21
$dir = __DIR__ . '/../../';
22
 
23
// ---
24
 
25
$all_cont = '';
26
 
27
$all_cont .= "<?php\n";
28
$all_cont .= "__halt_compiler();\n"; // avoid that the FastPHP code explorer runs crazy
29
$all_cont .= "?>\n";
30
 
31
$it = new RecursiveDirectoryIterator($dir);
32
foreach(new RecursiveIteratorIterator($it) as $file) {
33
        if (strpos(str_replace('\\','/',realpath($file)),'/3p/') !== false) continue; // ignore third-party-code
34
        if (strpos(str_replace('\\','/',realpath($file)),'/dev/') !== false) continue; // ignore development utilities
35
        if (basename($file) == 'ipv4_functions.inc.php') continue; // 3P
36
        if (basename($file) == 'ipv6_functions.inc.php') continue; // 3P
37
        if (basename($file) == 'gmp_supplement.inc.php') continue; // 3P
38
        if (basename($file) == 'xml_utils.inc.php') continue; // 3P
39
        if (basename($file) == 'uuid_utils.inc.php') continue; // 3P
40
        if (basename($file) == 'oid_utils.inc.php') continue; // 3P
41
        if (basename($file) == 'oidinfo_api.inc.php') continue; // 3P
42
        if (basename($file) == 'anti_xss.inc.php') continue; // 3P
43
        if ($file->getExtension() == 'js') {
44
 
45
                $cont = file_get_contents($file);
46
 
47
                $ary = explode("\n",$cont);
48
                $cont = '';
49
                foreach ($ary as $a) {
50
                        if (stripos($a,'do not translate') === false) {
51
                                $cont .= "$a\n";
52
                        }
53
                }
54
 
55
                $cont = preg_replace('@_L\\((\'|")(.*)\\1@smU', '_L(...', $cont);
56
 
57
                $ary = explode("\n",$cont);
58
                $cont = '';
59
                foreach ($ary as $a) {
60
                        $cont .= wordwrap(trim($a), 80)."\n";
61
                }
62
 
63
                $all_cont .= "=============== ".realpath($file)." ===============\n";
64
                $all_cont .= $cont."\n\n";
65
 
66
        }
67
        if ($file->getExtension() == 'php') {
68
                $cont = file_get_contents($file);
69
 
70
                $ary = explode("\n",$cont);
71
                $cont = '';
72
                foreach ($ary as $a) {
73
                        if (stripos($a,'do not translate') === false) {
74
                                $cont .= "$a\n";
75
                        }
76
                }
77
 
78
                $cont = phpRemoveComments($cont);
79
 
80
                $cont = str_replace('<li>', '', $cont);
81
                $cont = str_replace('</li>', '', $cont);
82
                $cont = str_replace('<ul>', '', $cont);
83
                $cont = str_replace('</ul>', '', $cont);
84
                $cont = str_replace('<th>', '', $cont);
85
                $cont = str_replace('</th>', '', $cont);
86
                $cont = str_replace('<pre>', '', $cont);
87
                $cont = str_replace('</pre>', '', $cont);
88
                $cont = str_replace('</a>', '', $cont);
89
                $cont = str_replace('<br>', '', $cont);
90
                $cont = str_replace('<br/>', '', $cont);
91
                $cont = str_replace('<br />', '', $cont);
92
                $cont = str_replace('<h1>', '', $cont);
93
                $cont = str_replace('</h1>', '', $cont);
94
                $cont = str_replace('<h2>', '', $cont);
95
                $cont = str_replace('</h2>', '', $cont);
96
                $cont = str_replace('<h3>', '', $cont);
97
                $cont = str_replace('</h3>', '', $cont);
98
                $cont = str_replace('<p>', '', $cont);
99
                $cont = str_replace('</p>', '', $cont);
100
                $cont = str_replace('<th width="25%">', '', $cont);
101
                $cont = str_replace('<th width="50%">', '', $cont);
102
                $cont = str_replace('</th>', '', $cont);
103
                $cont = str_replace('<td>', '', $cont);
104
                $cont = str_replace('</td>', '', $cont);
105
                $cont = str_replace('<tr>', '', $cont);
106
                $cont = str_replace('</tr>', '', $cont);
107
                $cont = str_replace('<b>', '', $cont);
108
                $cont = str_replace('</b>', '', $cont);
109
                $cont = str_replace('<i>', '', $cont);
110
                $cont = str_replace('</i>', '', $cont);
111
                $cont = str_replace('<u>', '', $cont);
112
                $cont = str_replace('</u>', '', $cont);
113
                $cont = preg_replace('@<form.+>@ismU', '', $cont);
114
                $cont = preg_replace('@<table.+>@ismU', '', $cont);
115
                $cont = str_replace('</form>', '', $cont);
116
                $cont = str_replace('</table>', '', $cont);
117
 
118
                $cont = str_replace('\\\\', chr(1), $cont);
119
                $cont = str_replace('\\"', chr(2), $cont);
120
                $cont = str_replace("\\'", chr(3), $cont);
121
 
122
                $cont = preg_replace_callback('@("|\').*\\1@ismU', function($treffer) {
123
                        $x = $treffer[0];
124
 
125
                        if (strpos($x,'_L(') !== false) {
126
                                echo "Attention: '_L(' inside a string?! at <pre>'.htmlentities($x).'</pre>\n";
127
                        }
128
 
129
                        $x = str_replace('(', chr(4), $x);
130
                        $x = str_replace(')', chr(5), $x);
131
 
132
                        /*
133
                        if (strpos($x,"\n") !== false) echo 'DEBUG: <pre>'.htmlentities($x)."</pre>\n\n\n\n\n";
134
                        */
135
 
136
                        return $x;
137
                }, $cont);
138
 
139
                $cont = preg_replace('@_L\\((\'|")(.*)\\1@smU', '_L(...', $cont);
140
 
141
                $cont = preg_replace('@logger\\(\\)\\->log\\([^\n]*\\)@smU', 'logger()->log(...)', $cont);
142
                $cont = preg_replace('@config\\(\\)\\->getValue\\([^\n]*\\)@smU', 'config()->getValue(...)', $cont);
143
                $cont = preg_replace('@config\\(\\)\\->setValue\\([^\n]*\\)@smU', 'config()->setValue(...)', $cont);
144
                $cont = preg_replace('@prepareConfigKey\\([^\n]*\\)@smU', 'prepareConfigKey(...)', $cont);
145
                $cont = preg_replace('@baseConfig\\(\\)\\->getValue\\([^\n]*\\)@smU', 'baseConfig()->getValue(...)', $cont);
146
                $cont = preg_replace('@query\\([^\n]*\\)@smU', 'query(...)', $cont);
147
                $cont = preg_replace('@query\\([^\n]*\\)@smU', 'query(...)', $cont);
148
                $cont = preg_replace('@registerAllPlugins\\([^\n]*\\);@smU', 'registerAllPlugins(...)', $cont);
149
 
150
                $cont = preg_replace('@\\[(\'|")([^\n]*)\\1\\]@smU', '[...]', $cont);
151
                $cont = preg_replace('@header\\([^\n]*\\);@smU', 'header(...)', $cont);
152
                $cont = preg_replace('@setcookie\\([^\n]*\\);@smU', 'header(...)', $cont);
153
                $cont = preg_replace('@file_exists\\((\'|")([^\n]*)\\1\\)@smU', 'file_exists(...)', $cont);
154
                $cont = preg_replace('@is_dir\\((\'|")([^\n]*)\\1\\)@smU', 'is_dir(...)', $cont);
155
                $cont = preg_replace('@ini_get\\((\'|")([^\n]*)\\1\\)@smU', 'ini_get(...)', $cont);
156
                $cont = preg_replace('@realpath\\((\'|")([^\n]*)\\1\\)@smU', 'realpath(...)', $cont);
157
 
158
                $cont = preg_replace('@include_once(.+);@ismU', '', $cont);
159
                $cont = preg_replace('@require_once(.+);@ismU', '', $cont);
160
                $cont = preg_replace('@==\\s*(\'|").*\\1@ismU', '==...', $cont);
161
                $cont = preg_replace('@!=\\s*(\'|").*\\1@ismU', '!=...', $cont);
162
 
163
                $cont = str_replace(chr(1), "\\\\", $cont);
164
                $cont = str_replace(chr(2), '\\"', $cont);
165
                $cont = str_replace(chr(3), "\\'", $cont);
166
                $cont = str_replace(chr(4), "(", $cont);
167
                $cont = str_replace(chr(5), ")", $cont);
168
 
169
                $cont = str_replace("\t", "", $cont);
170
 
171
                $cont = str_replace("''", '', $cont);
172
                $cont = str_replace('""', '', $cont);
173
 
174
                $cont = str_replace("'.'", '', $cont);
175
                $cont = str_replace('"."', '', $cont);
176
 
177
                $cont = str_replace("':'", '', $cont);
178
                $cont = str_replace('":"', '', $cont);
179
 
180
                $cont = str_replace("';'", '', $cont);
181
                $cont = str_replace('";"', '', $cont);
182
 
183
                $cont = str_replace('"\\n"', '', $cont);
184
 
185
                $cont = str_replace('"\\r\\n"', '', $cont);
186
 
187
                $ary = explode("\n",$cont);
188
                $cont = '';
189
                foreach ($ary as $a) {
190
                        $cont .= wordwrap($a, 80)."\n";
191
                }
192
 
193
                $all_cont .= "=============== ".realpath($file)." ===============\n";
194
                $all_cont .= $cont."\n\n";
195
                $all_cont .= "?>\n";
196
        }
197
}
198
 
199
$outfile = __DIR__.'/.nontranslated.tmp';
200
$fastphp = 'C:\\Program Files (x86)\\FastPHP\\FastPHPEditor.exe';
201
 
202
file_put_contents($outfile, $all_cont);
203
 
204
if (file_exists($fastphp)) {
205
        system('"'.$fastphp.'" "'.$outfile.'"');
206
        unlink($outfile);
207
} else {
208
        echo "Generated file $outfile\n";
209
}
210
 
211
# ---
212
 
213
function phpRemoveComments($fileStr) {
214
 
215
        // https://stackoverflow.com/questions/503871/best-way-to-automatically-remove-comments-from-php-code
216
 
217
        $newStr  = '';
218
 
219
        $commentTokens = array(T_COMMENT);
220
 
361 daniel-mar 221
        if (defined('T_DOC_COMMENT')) $commentTokens[] = T_DOC_COMMENT; // PHP 5
222
        if (defined('T_ML_COMMENT'))  $commentTokens[] = T_ML_COMMENT;  // PHP 4
360 daniel-mar 223
 
224
        $tokens = token_get_all($fileStr);
225
 
226
        foreach ($tokens as $token) {
361 daniel-mar 227
                if (is_array($token)) {
228
                        if (in_array($token[0], $commentTokens)) continue;
229
                        $token = $token[1];
230
                }
231
                $newStr .= $token;
360 daniel-mar 232
        }
233
 
234
        return $newStr;
235
 
236
}