Rev 1130 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
557 | daniel-mar | 1 | #!/usr/bin/env 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 | |||
1116 | daniel-mar | 25 | $all_cont = "<?php\n"; |
360 | daniel-mar | 26 | $all_cont .= "__halt_compiler();\n"; // avoid that the FastPHP code explorer runs crazy |
27 | $all_cont .= "?>\n"; |
||
28 | |||
29 | $it = new RecursiveDirectoryIterator($dir); |
||
30 | foreach(new RecursiveIteratorIterator($it) as $file) { |
||
597 | daniel-mar | 31 | if (strpos(str_replace('\\','/',realpath($file)),'/vendor/') !== false) continue; // ignore third-party-code |
360 | daniel-mar | 32 | if (strpos(str_replace('\\','/',realpath($file)),'/dev/') !== false) continue; // ignore development utilities |
33 | if (basename($file) == 'ipv4_functions.inc.php') continue; // 3P |
||
34 | if (basename($file) == 'ipv6_functions.inc.php') continue; // 3P |
||
35 | if (basename($file) == 'gmp_supplement.inc.php') continue; // 3P |
||
36 | if (basename($file) == 'xml_utils.inc.php') continue; // 3P |
||
37 | if (basename($file) == 'uuid_utils.inc.php') continue; // 3P |
||
38 | if (basename($file) == 'oid_utils.inc.php') continue; // 3P |
||
39 | if (basename($file) == 'oidinfo_api.inc.php') continue; // 3P |
||
40 | if (basename($file) == 'anti_xss.inc.php') continue; // 3P |
||
41 | if ($file->getExtension() == 'js') { |
||
42 | |||
43 | $cont = file_get_contents($file); |
||
44 | |||
45 | $ary = explode("\n",$cont); |
||
46 | $cont = ''; |
||
47 | foreach ($ary as $a) { |
||
48 | if (stripos($a,'do not translate') === false) { |
||
49 | $cont .= "$a\n"; |
||
50 | } |
||
51 | } |
||
52 | |||
53 | $cont = preg_replace('@_L\\((\'|")(.*)\\1@smU', '_L(...', $cont); |
||
54 | |||
55 | $ary = explode("\n",$cont); |
||
56 | $cont = ''; |
||
57 | foreach ($ary as $a) { |
||
58 | $cont .= wordwrap(trim($a), 80)."\n"; |
||
59 | } |
||
60 | |||
61 | $all_cont .= "=============== ".realpath($file)." ===============\n"; |
||
62 | $all_cont .= $cont."\n\n"; |
||
63 | |||
64 | } |
||
65 | if ($file->getExtension() == 'php') { |
||
66 | $cont = file_get_contents($file); |
||
67 | |||
68 | $ary = explode("\n",$cont); |
||
69 | $cont = ''; |
||
70 | foreach ($ary as $a) { |
||
71 | if (stripos($a,'do not translate') === false) { |
||
72 | $cont .= "$a\n"; |
||
73 | } |
||
74 | } |
||
75 | |||
76 | $cont = phpRemoveComments($cont); |
||
77 | |||
78 | $cont = str_replace('<li>', '', $cont); |
||
79 | $cont = str_replace('</li>', '', $cont); |
||
80 | $cont = str_replace('<ul>', '', $cont); |
||
81 | $cont = str_replace('</ul>', '', $cont); |
||
82 | $cont = str_replace('<th>', '', $cont); |
||
83 | $cont = str_replace('</th>', '', $cont); |
||
84 | $cont = str_replace('<pre>', '', $cont); |
||
85 | $cont = str_replace('</pre>', '', $cont); |
||
86 | $cont = str_replace('</a>', '', $cont); |
||
87 | $cont = str_replace('<br>', '', $cont); |
||
88 | $cont = str_replace('<br/>', '', $cont); |
||
89 | $cont = str_replace('<br />', '', $cont); |
||
90 | $cont = str_replace('<h1>', '', $cont); |
||
91 | $cont = str_replace('</h1>', '', $cont); |
||
92 | $cont = str_replace('<h2>', '', $cont); |
||
93 | $cont = str_replace('</h2>', '', $cont); |
||
94 | $cont = str_replace('<h3>', '', $cont); |
||
95 | $cont = str_replace('</h3>', '', $cont); |
||
96 | $cont = str_replace('<p>', '', $cont); |
||
97 | $cont = str_replace('</p>', '', $cont); |
||
98 | $cont = str_replace('<th width="25%">', '', $cont); |
||
99 | $cont = str_replace('<th width="50%">', '', $cont); |
||
100 | $cont = str_replace('</th>', '', $cont); |
||
101 | $cont = str_replace('<td>', '', $cont); |
||
102 | $cont = str_replace('</td>', '', $cont); |
||
103 | $cont = str_replace('<tr>', '', $cont); |
||
104 | $cont = str_replace('</tr>', '', $cont); |
||
105 | $cont = str_replace('<b>', '', $cont); |
||
106 | $cont = str_replace('</b>', '', $cont); |
||
107 | $cont = str_replace('<i>', '', $cont); |
||
108 | $cont = str_replace('</i>', '', $cont); |
||
109 | $cont = str_replace('<u>', '', $cont); |
||
110 | $cont = str_replace('</u>', '', $cont); |
||
111 | $cont = preg_replace('@<form.+>@ismU', '', $cont); |
||
112 | $cont = preg_replace('@<table.+>@ismU', '', $cont); |
||
113 | $cont = str_replace('</form>', '', $cont); |
||
114 | $cont = str_replace('</table>', '', $cont); |
||
115 | |||
116 | $cont = str_replace('\\\\', chr(1), $cont); |
||
117 | $cont = str_replace('\\"', chr(2), $cont); |
||
118 | $cont = str_replace("\\'", chr(3), $cont); |
||
119 | |||
120 | $cont = preg_replace_callback('@("|\').*\\1@ismU', function($treffer) { |
||
121 | $x = $treffer[0]; |
||
122 | |||
123 | if (strpos($x,'_L(') !== false) { |
||
124 | echo "Attention: '_L(' inside a string?! at <pre>'.htmlentities($x).'</pre>\n"; |
||
125 | } |
||
126 | |||
127 | $x = str_replace('(', chr(4), $x); |
||
128 | |||
1130 | daniel-mar | 129 | return str_replace(')', chr(5), $x); |
360 | daniel-mar | 130 | }, $cont); |
131 | |||
132 | $cont = preg_replace('@_L\\((\'|")(.*)\\1@smU', '_L(...', $cont); |
||
133 | |||
1186 | daniel-mar | 134 | $cont = preg_replace('@logger\\(\\)\\->log\\([^\n]*\\)@mU', 'logger()->log(...)', $cont); |
135 | $cont = preg_replace('@config\\(\\)\\->getValue\\([^\n]*\\)@mU', 'config()->getValue(...)', $cont); |
||
136 | $cont = preg_replace('@config\\(\\)\\->setValue\\([^\n]*\\)@mU', 'config()->setValue(...)', $cont); |
||
137 | $cont = preg_replace('@prepareConfigKey\\([^\n]*\\)@mU', 'prepareConfigKey(...)', $cont); |
||
138 | $cont = preg_replace('@baseConfig\\(\\)\\->getValue\\([^\n]*\\)@mU', 'baseConfig()->getValue(...)', $cont); |
||
139 | $cont = preg_replace('@query\\([^\n]*\\)@mU', 'query(...)', $cont); |
||
140 | $cont = preg_replace('@query\\([^\n]*\\)@mU', 'query(...)', $cont); |
||
141 | $cont = preg_replace('@registerAllPlugins\\([^\n]*\\);@mU', 'registerAllPlugins(...)', $cont); |
||
360 | daniel-mar | 142 | |
1186 | daniel-mar | 143 | $cont = preg_replace('@\\[(\'|")([^\n]*)\\1\\]@mU', '[...]', $cont); |
144 | $cont = preg_replace('@header\\([^\n]*\\);@mU', 'header(...)', $cont); |
||
145 | $cont = preg_replace('@setcookie\\([^\n]*\\);@mU', 'header(...)', $cont); |
||
146 | $cont = preg_replace('@file_exists\\((\'|")([^\n]*)\\1\\)@mU', 'file_exists(...)', $cont); |
||
147 | $cont = preg_replace('@is_dir\\((\'|")([^\n]*)\\1\\)@mU', 'is_dir(...)', $cont); |
||
148 | $cont = preg_replace('@ini_get\\((\'|")([^\n]*)\\1\\)@mU', 'ini_get(...)', $cont); |
||
149 | $cont = preg_replace('@realpath\\((\'|")([^\n]*)\\1\\)@mU', 'realpath(...)', $cont); |
||
360 | daniel-mar | 150 | |
151 | $cont = preg_replace('@include_once(.+);@ismU', '', $cont); |
||
152 | $cont = preg_replace('@require_once(.+);@ismU', '', $cont); |
||
153 | $cont = preg_replace('@==\\s*(\'|").*\\1@ismU', '==...', $cont); |
||
154 | $cont = preg_replace('@!=\\s*(\'|").*\\1@ismU', '!=...', $cont); |
||
155 | |||
156 | $cont = str_replace(chr(1), "\\\\", $cont); |
||
157 | $cont = str_replace(chr(2), '\\"', $cont); |
||
158 | $cont = str_replace(chr(3), "\\'", $cont); |
||
159 | $cont = str_replace(chr(4), "(", $cont); |
||
160 | $cont = str_replace(chr(5), ")", $cont); |
||
161 | |||
162 | $cont = str_replace("\t", "", $cont); |
||
163 | |||
164 | $cont = str_replace("''", '', $cont); |
||
165 | $cont = str_replace('""', '', $cont); |
||
166 | |||
167 | $cont = str_replace("'.'", '', $cont); |
||
168 | $cont = str_replace('"."', '', $cont); |
||
169 | |||
170 | $cont = str_replace("':'", '', $cont); |
||
171 | $cont = str_replace('":"', '', $cont); |
||
172 | |||
173 | $cont = str_replace("';'", '', $cont); |
||
174 | $cont = str_replace('";"', '', $cont); |
||
175 | |||
176 | $cont = str_replace('"\\n"', '', $cont); |
||
177 | |||
178 | $cont = str_replace('"\\r\\n"', '', $cont); |
||
179 | |||
180 | $ary = explode("\n",$cont); |
||
181 | $cont = ''; |
||
182 | foreach ($ary as $a) { |
||
183 | $cont .= wordwrap($a, 80)."\n"; |
||
184 | } |
||
185 | |||
186 | $all_cont .= "=============== ".realpath($file)." ===============\n"; |
||
187 | $all_cont .= $cont."\n\n"; |
||
188 | $all_cont .= "?>\n"; |
||
189 | } |
||
190 | } |
||
191 | |||
192 | $outfile = __DIR__.'/.nontranslated.tmp'; |
||
193 | $fastphp = 'C:\\Program Files (x86)\\FastPHP\\FastPHPEditor.exe'; |
||
194 | |||
195 | file_put_contents($outfile, $all_cont); |
||
196 | |||
197 | if (file_exists($fastphp)) { |
||
198 | system('"'.$fastphp.'" "'.$outfile.'"'); |
||
199 | unlink($outfile); |
||
200 | } else { |
||
201 | echo "Generated file $outfile\n"; |
||
202 | } |
||
203 | |||
204 | # --- |
||
205 | |||
1130 | daniel-mar | 206 | /** |
207 | * @param string $fileStr |
||
208 | * @return string |
||
209 | */ |
||
210 | function phpRemoveComments(string $fileStr): string { |
||
360 | daniel-mar | 211 | |
212 | // https://stackoverflow.com/questions/503871/best-way-to-automatically-remove-comments-from-php-code |
||
213 | |||
214 | $newStr = ''; |
||
215 | |||
216 | $commentTokens = array(T_COMMENT); |
||
217 | |||
361 | daniel-mar | 218 | if (defined('T_DOC_COMMENT')) $commentTokens[] = T_DOC_COMMENT; // PHP 5 |
219 | if (defined('T_ML_COMMENT')) $commentTokens[] = T_ML_COMMENT; // PHP 4 |
||
360 | daniel-mar | 220 | |
221 | $tokens = token_get_all($fileStr); |
||
222 | |||
223 | foreach ($tokens as $token) { |
||
361 | daniel-mar | 224 | if (is_array($token)) { |
225 | if (in_array($token[0], $commentTokens)) continue; |
||
226 | $token = $token[1]; |
||
227 | } |
||
228 | $newStr .= $token; |
||
360 | daniel-mar | 229 | } |
230 | |||
231 | return $newStr; |
||
232 | |||
233 | } |