Verzeichnisstruktur phpBB-3.0.0
- Veröffentlicht
- 12.12.2007
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
generate_utf_confusables.php
001 <?php
002 /**
003 *
004 * @package phpBB3
005 * @version $Id$
006 * @copyright (c) 2005 phpBB Group
007 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
008 *
009 */
010
011 if (php_sapi_name() != 'cli')
012 {
013 die("This program must be run from the command line.\n");
014 }
015
016 //
017 // Security message:
018 //
019 // This script is potentially dangerous.
020 // Remove or comment the next line (die(".... ) to enable this script.
021 // Do NOT FORGET to either remove this script or disable it after you have used it.
022 //
023 die("Please read the first lines of this script for instructions on how to enable it");
024
025 set_time_limit(0);
026
027 define('IN_PHPBB', true);
028 $phpbb_root_path = '../';
029 $phpEx = substr(strrchr(__FILE__, '.'), 1);
030
031 echo "Checking for required files\n";
032 download('http://unicode.org/reports/tr39/data/confusables.txt');
033 download('http://unicode.org/Public/UNIDATA/CaseFolding.txt');
034 echo "\n";
035
036
037 /**
038 * Load the confusables table
039 */
040 echo "Loading confusables\n";
041 $unidata = file_get_contents('confusables.txt');
042
043 /**
044 * Load the CaseFolding table
045 */
046 echo "Loading CaseFolding\n";
047 $casefolds = file_get_contents('CaseFolding.txt');
048
049
050 function utf8_chr($cp)
051 {
052 if ($cp > 0xFFFF)
053 {
054 return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
055 }
056 else if ($cp > 0x7FF)
057 {
058 return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F));
059 }
060 else if ($cp > 0x7F)
061 {
062 return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F));
063 }
064 else
065 {
066 return chr($cp);
067 }
068 }
069
070 preg_match_all('/^([0-9A-F]+) ;\s((?:[0-9A-F]+ )*);.*?$/im', $unidata, $array, PREG_SET_ORDER);
071 preg_match_all('/^([0-9A-F]+); ([CFS]); ([0-9A-F]+(?: [0-9A-F]+)*);/im', $casefolds, $casefold_array);
072
073 // some that we defined ourselves
074 $uniarray = array(
075 "\xC2\xA1" => "\x69", // EXCLAMATION MARK, INVERTED => LATIN SMALL LETTER I
076 "\xC7\x83" => "\x21", // LATIN LETTER RETROFLEX CLICK => EXCLAMATION MARK
077 "\xCE\xB1" => "\x61", // GREEK SMALL LETTER ALPHA => LATIN SMALL LETTER A
078 "\xE1\x9A\x80" => "\x20", // OGHAM SPACE MARK
079
080 "\xC2\xAD" => '', // HYPHEN, SOFT => empty string
081 "\xDB\x9D" => '', // ARABIC END OF AYAH
082 "\xDC\x8F" => '', // SYRIAC ABBREVIATION MARK
083 "\xE1\xA0\x86" => '', // MONGOLIAN TODO SOFT HYPHEN
084 "\xE1\xA0\x8E" => '', // MONGOLIAN VOWEL SEPARATOR
085 "\xE2\x80\x8B" => '', // ZERO WIDTH SPACE
086 "\xE2\x80\x8C" => '', // ZERO WIDTH NON-JOINER
087 "\xE2\x80\x8D" => '', // ZERO WIDTH JOINER
088 "\xE2\x80\xA8" => '', // LINE SEPARATOR
089 "\xE2\x80\xA9" => '', // PARAGRAPH SEPARATOR
090 "\xE2\x81\xA0" => '', // WORD JOINER
091 "\xE2\x81\xA1" => '', // FUNCTION APPLICATION
092 "\xE2\x81\xA2" => '', // INVISIBLE TIMES
093 "\xE2\x81\xA3" => '', // INVISIBLE SEPARATOR
094 "\xE2\x81\xAA" => '', // [CONTROL CHARACTERS]
095 "\xE2\x81\xAB" => '', // [CONTROL CHARACTERS]
096 "\xE2\x81\xAC" => '', // [CONTROL CHARACTERS]
097 "\xE2\x81\xAD" => '', // [CONTROL CHARACTERS]
098 "\xE2\x81\xAE" => '', // [CONTROL CHARACTERS]
099 "\xE2\x81\xAF" => '', // [CONTROL CHARACTERS]
100 "\xEF\xBB\xBF" => '', // ZERO WIDTH NO-BREAK SPACE
101 "\xEF\xBF\xB9" => '', // [CONTROL CHARACTERS]
102 "\xEF\xBF\xBA" => '', // [CONTROL CHARACTERS]
103 "\xEF\xBF\xBB" => '', // [CONTROL CHARACTERS]
104 "\xEF\xBF\xBC" => '', // [CONTROL CHARACTERS]
105 "\xF0\x9D\x85\xB3" => '', // [MUSICAL CONTROL CHARACTERS]
106 "\xF0\x9D\x85\xB4" => '', // [MUSICAL CONTROL CHARACTERS]
107 "\xF0\x9D\x85\xB5" => '', // [MUSICAL CONTROL CHARACTERS]
108 "\xF0\x9D\x85\xB6" => '', // [MUSICAL CONTROL CHARACTERS]
109 "\xF0\x9D\x85\xB7" => '', // [MUSICAL CONTROL CHARACTERS]
110 "\xF0\x9D\x85\xB8" => '', // [MUSICAL CONTROL CHARACTERS]
111 "\xF0\x9D\x85\xB9" => '', // [MUSICAL CONTROL CHARACTERS]
112 "\xF0\x9D\x85\xBA" => '', // [MUSICAL CONTROL CHARACTERS]
113 );
114
115 $copy = $uniarray;
116
117 foreach ($array as $value)
118 {
119 $temp_hold = implode(array_map('utf8_chr', array_map('hexdec', explode(' ', trim($value[2])))));
120
121 if (isset($copy[utf8_chr(hexdec((string)$value[1]))]))
122 {
123 $num = '';
124 $string = utf8_chr(hexdec((string)$value[1]));
125 for ($i = 0; $i < strlen($string); $i++)
126 {
127 $num .= '\x' . str_pad(base_convert(ord($string[$i]), 10, 16), 2, '0', STR_PAD_LEFT);
128 }
129 echo $num . "\n";
130 if ($uniarray[$string] != $temp_hold)
131 {
132 echo " --> $string\n";
133 echo " --> " . $temp_hold . "\n";
134 }
135 }
136
137 // do some tests for things that transform into something with the number one
138 if (strpos($temp_hold, utf8_chr(0x0031)) !== false)
139 {
140 // any kind of letter L?
141 if (strpos($value[0], 'LETTER L') !== false || strpos($value[0], 'IOTA') !== false || strpos($value[0], 'SMALL L ') !== false || preg_match('/SMALL LIGATURE [^L]*L /', $value[0]))
142 {
143 // replace all of the mappings that transform some sort of letter l to number one instead to some sort of letter l to latin small letter l
144 $temp_hold = str_replace(utf8_chr(0x0031), utf8_chr(0x006C), $temp_hold);
145 }
146 }
147
148 // uppercased chars that were folded do not exist in this universe,
149 // no amount of normalization could ever "trick" this into not working
150 if (in_array($value[1], $casefold_array[1]))
151 {
152 continue;
153 }
154
155 $uniarray[utf8_chr(hexdec((string)$value[1]))] = $temp_hold;
156 }
157
158 echo "Writing to confusables.$phpEx\n";
159
160 $fp = fopen($phpbb_root_path . 'includes/utf/data/confusables.' . $phpEx, 'wb');
161 fwrite($fp, '<?php return ' . my_var_export($uniarray) . ';');
162 fclose($fp);
163
164 /**
165 * Return a parsable string representation of a variable
166 *
167 * This is function is limited to array/strings/integers
168 *
169 * @param mixed $var Variable
170 * @return string PHP code representing the variable
171 */
172 function my_var_export($var)
173 {
174 if (is_array($var))
175 {
176 $lines = array();
177
178 foreach ($var as $k => $v)
179 {
180 $lines[] = my_var_export($k) . '=>' . my_var_export($v);
181 }
182
183 return 'array(' . implode(',', $lines) . ')';
184 }
185 else if (is_string($var))
186 {
187 return "'" . str_replace(array('\\', "'"), array('\\\\', "\\'"), $var) . "'";
188 }
189 else
190 {
191 return $var;
192 }
193 }
194
195 /**
196 * Download a file to the develop/ dir
197 *
198 * @param string $url URL of the file to download
199 * @return void
200 */
201 function download($url)
202 {
203 global $phpbb_root_path;
204
205 if (file_exists($phpbb_root_path . 'develop/' . basename($url)))
206 {
207 return;
208 }
209
210 echo 'Downloading from ', $url, ' ';
211
212 if (!$fpr = fopen($url, 'rb'))
213 {
214 die("Can't download from $url\nPlease download it yourself and put it in the develop/ dir, kthxbai");
215 }
216
217 if (!$fpw = fopen($phpbb_root_path . 'develop/' . basename($url), 'wb'))
218 {
219 die("Can't open develop/" . basename($url) . " for output... please check your permissions or something");
220 }
221
222 $i = 0;
223 $chunk = 32768;
224 $done = '';
225
226 while (!feof($fpr))
227 {
228 $i += fwrite($fpw, fread($fpr, $chunk));
229 echo str_repeat("\x08", strlen($done));
230
231 $done = ($i >> 10) . ' KiB';
232 echo $done;
233 }
234 fclose($fpr);
235 fclose($fpw);
236
237 echo "\n";
238 }
239
240 ?>