Index: trunk/extensions/wikihiero/wh_list.php |
— | — | @@ -1,8 +1,10 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -// File created by wh_generate.php version 0.2.6 |
5 | | -// 2004/03/26 pm31 18:50 |
| 4 | +// File created by wh_generate.php version 0.2.14 |
| 5 | +// 2006/03/05 pm31 13:04 |
6 | 6 | |
| 7 | +global $wh_prefabs, $wh_files; |
| 8 | + |
7 | 9 | $wh_prefabs = array( |
8 | 10 | "a&A1", |
9 | 11 | "a&b&t", |
— | — | @@ -298,8 +300,8 @@ |
299 | 301 | "C9" => array( 20, 38 ), |
300 | 302 | "Ca0" => array( 5, 50 ), |
301 | 303 | "Ca1" => array( 14, 48 ), |
302 | | - "Ca1a" => array( 14, 50 ), |
303 | | - "Ca2" => array( 16, 50 ), |
| 304 | + "Ca1a" => array( 14, 49 ), |
| 305 | + "Ca2" => array( 16, 49 ), |
304 | 306 | "Ca2a" => array( 16, 48 ), |
305 | 307 | "Cah1" => array( 5, 48 ), |
306 | 308 | "Cah1a" => array( 5, 50 ), |
Index: trunk/extensions/wikihiero/wikihiero.php |
— | — | @@ -24,1015 +24,45 @@ |
25 | 25 | // |
26 | 26 | ////////////////////////////////////////////////////////////////////////// |
27 | 27 | |
28 | | - //======================================================================== |
29 | | - // I N C L U D E S |
30 | | - include "wh_list.php"; |
31 | | - |
32 | | - //======================================================================== |
33 | | - // D E F I N E S |
34 | | - define("WH_TABLE_S", "<table border='0' cellspacing='0' cellpadding='0'>"); |
35 | | - define("WH_TABLE_E", "</table>"); |
36 | | - define("WH_TD_S", "<td align='center' valign='middle'>"); |
37 | | - define("WH_TD_E", "</td>"); |
38 | | - |
39 | | - define("WH_MODE_DEFAULT", -1); // use default mode |
40 | | - define("WH_MODE_TEXT", 0); // text only |
41 | | - define("WH_MODE_HTML", 1); // HTML without CSS |
42 | | - define("WH_MODE_STYLE", 2); // HTML and CSS // not supporter |
43 | | - define("WH_MODE_IMAGE", 3); // picture (PNG) // not supporter |
44 | | - define("WH_MODE_RAW", 4); // MdC test as it |
45 | | - |
46 | | - define("WH_TYPE_NONE", 0); |
47 | | - define("WH_TYPE_GLYPH", 1); // rendered items |
48 | | - define("WH_TYPE_CODE", 2); // single code as ':', '*', '!', '(' or ')' |
49 | | - define("WH_TYPE_SPECIAL", 3); // advanced code (more than 1 caracter) |
50 | | - define("WH_TYPE_END", 4); // end of line '!' |
51 | | - |
52 | | - define("WH_SCALE_DEFAULT", -1); // use default scale |
53 | | - define("WH_HEIGHT", 44); |
54 | | - define("WH_IMG_MARGIN", 1); // default value |
55 | | - define("WH_CARTOUCHE_WIDTH", 2); // default value |
56 | | - |
57 | | - define("WH_VER_MAJ", 0); |
58 | | - define("WH_VER_MED", 2); |
59 | | - define("WH_VER_MIN", 14); |
60 | | - |
61 | | - define("WH_IMG_DIR", "$wgScriptPath/extensions/wikihiero/img/" ); //"img/"); // |
62 | | - define("WH_IMG_PRE", "hiero_"); |
63 | | - define("WH_IMG_EXT", "png"); |
64 | | - |
65 | | - define("WH_DEBUG_MODE", false); |
66 | | - |
67 | | - //======================================================================== |
68 | | - // G L O B A L S |
69 | | - $wh_mode = WH_MODE_HTML; // default value |
70 | | - $wh_scale = 100; // default value |
71 | | - |
72 | | - $wh_phonemes = array( // convertion table phoneme -> gardiner code |
73 | | - "mSa" => "A12", |
74 | | - "xr" => "A15", |
75 | | - "Xrd" => "A17", |
76 | | - "sr" => "A21", |
77 | | - "mniw" => "A33", |
78 | | - "qiz" => "A38", |
79 | | - "iry" => "A47", |
80 | | - "Sps" => "A50", |
81 | | - "Spsi" => "A51", |
82 | | -/* |
83 | | - "x" => "J1", |
84 | | - "mAa" => "J11", |
85 | | - "gs" => "J13", |
86 | | - "im" => "J13", |
87 | | - "M" => "J15", |
88 | | - "sA" => "J17", |
89 | | - "apr" => "J20", |
90 | | - "wDa" => "J21", |
91 | | - "nD" => "J27", |
92 | | - "qd" => "J28", |
93 | | - "Xkr" => "J30", |
94 | | - "Hp" => "J5", |
95 | | - "qn" => "J8", |
96 | | -*/ |
97 | | - "x" => "Aa1", |
98 | | - "mAa" => "Aa11", |
99 | | - "gs" => "Aa13", |
100 | | - "im" => "Aa13", |
101 | | - "M" => "Aa15", |
102 | | - "sA" => "Aa17", |
103 | | - "apr" => "Aa20", |
104 | | - "wDa" => "Aa21", |
105 | | - "nD" => "Aa27", |
106 | | - "qd" => "Aa28", |
107 | | - "Xkr" => "Aa30", |
108 | | - "Hp" => "Aa5", |
109 | | - "qn" => "Aa8", |
110 | | - |
111 | | - "msi" => "B3", |
112 | | - "mAat" => "C10", |
113 | | - "HH" => "C11", |
114 | | - "DHwty" => "C3", |
115 | | - "Xnmw" => "C4", |
116 | | - "inpw" => "C6", |
117 | | - "stX" => "C7", |
118 | | - "mnw" => "C8", |
119 | | - "tp" => "D1", |
120 | | - "wDAt" => "D10", |
121 | | - "R" => "D153", |
122 | | - "fnD" => "D19", |
123 | | - "Hr" => "D2", |
124 | | - "r" => "D21", |
125 | | - "rA" => "D21", |
126 | | - "spt" => "D24", |
127 | | - "spty" => "D25", |
128 | | - "mnD" => "D27", |
129 | | - "kA" => "D28", |
130 | | - "Sny" => "D3", |
131 | | - "aHA" => "D34", |
132 | | - "a" => "D36", |
133 | | - "ir" => "D4", |
134 | | - "Dsr" => "D45", |
135 | | - "d" => "D46", |
136 | | - "Dba" => "D50", |
137 | | - "mt" => "D52", |
138 | | - "gH" => "D56", |
139 | | - "gHs" => "D56", |
140 | | - "rd" => "D56", |
141 | | - "sbq" => "D56", |
142 | | - "b" => "D58", |
143 | | - "ab" => "D59", |
144 | | - "wab" => "D60", |
145 | | - "sAH" => "D61", |
146 | | - "rmi" => "D9", |
147 | | - "zAb" => "E17", |
148 | | - "mAi" => "E22", |
149 | | - "l" => "E23", |
150 | | - "rw" => "E23", |
151 | | - "Aby" => "E24", |
152 | | - "wn" => "E34", |
153 | | - "zzmt" => "E6", |
154 | | - "wsr" => "F12", |
155 | | - "wp" => "F13", |
156 | | - "db" => "F16", |
157 | | - "Hw" => "F18", |
158 | | - "bH" => "F18", |
159 | | - "ns" => "F20", |
160 | | - "DrD" => "F21", |
161 | | - "idn" => "F21", |
162 | | - "msDr" => "F21", |
163 | | - "sDm" => "F21", |
164 | | - "kfA" => "F22", |
165 | | - "pH" => "F22", |
166 | | - "xpS" => "F23", |
167 | | - "wHm" => "F25", |
168 | | - "Xn" => "F26", |
169 | | - "sti" => "F29", |
170 | | - "Sd" => "F30", |
171 | | - "ms" => "F31", |
172 | | - "X" => "F32", |
173 | | - "sd" => "F33", |
174 | | - "ib" => "F34", |
175 | | - "nfr" => "F35", |
176 | | - "zmA" => "F36", |
177 | | - "imAx" => "F39", |
178 | | - "HAt" => "F4", |
179 | | - "Aw" => "F40", |
180 | | - "spr" => "F42", |
181 | | - "isw" => "F44", |
182 | | - "iwa" => "F44", |
183 | | - "pXr" => "F46", |
184 | | - "qAb" => "F46", |
185 | | - "SsA" => "F5", |
186 | | - "A" => "G1", |
187 | | - "mwt" => "G14", |
188 | | - "nbty" => "G16", |
189 | | - "m" => "G17", |
190 | | - "mm" => "G18", |
191 | | - "AA" => "G2", |
192 | | - "nH" => "G21", |
193 | | - "Db" => "G22", |
194 | | - "rxyt" => "G23", |
195 | | - "Ax" => "G25", |
196 | | - "dSr" => "G27", |
197 | | - "gm" => "G28", |
198 | | - "bA" => "G29", |
199 | | - "baHi" => "G32", |
200 | | - "aq" => "G35", |
201 | | - "wr" => "G36", |
202 | | - "nDs" => "G37", |
203 | | - "gb" => "G38", |
204 | | - "zA" => "G39", |
205 | | - "tyw" => "G4", |
206 | | - "pA" => "G40", |
207 | | - "xn" => "G41", |
208 | | - "wSA" => "G42", |
209 | | - "w" => "G43", |
210 | | - "ww" => "G44", |
211 | | - "mAw" => "G46", |
212 | | - "TA" => "G47", |
213 | | - "snD" => "G54", |
214 | | - "pq" => "H2", |
215 | | - "wSm" => "H2", |
216 | | - "pAq" => "H3", |
217 | | - "nr" => "H4", |
218 | | - "Sw" => "H6", |
219 | | - "aSA" => "I1", |
220 | | - "D" => "I10", |
221 | | - "DD" => "I11", |
222 | | - "Styw" => "I2", |
223 | | - "mzH" => "I3", |
224 | | - "sbk" => "I4", |
225 | | - "sAq" => "I5", |
226 | | - "km" => "I6", |
227 | | - "Hfn" => "I8", |
228 | | - "f" => "I9", |
229 | | - "in" => "K1", |
230 | | - "ad" => "K3", |
231 | | - "XA" => "K4", |
232 | | - "bz" => "K5", |
233 | | - "nSmt" => "K6", |
234 | | - "xpr" => "L1", |
235 | | - "bit" => "L2", |
236 | | - "srqt" => "L7", |
237 | | - "iAm" => "M1", |
238 | | - "wdn" => "M11", |
239 | | - "xA" => "M12", |
240 | | - "1000" => "M12", |
241 | | - "wAD" => "M13", |
242 | | - "HA" => "M16", |
243 | | - "i" => "M17", |
244 | | - "ii" => "M18", |
245 | | - "Hn" => "M2", |
246 | | - "sxt" => "M20", |
247 | | - "sm" => "M21", |
248 | | - "nn" => "M22A", |
249 | | - "sw" => "M23", |
250 | | - "rsw" => "M24", |
251 | | - "Sma" => "M26", |
252 | | - "nDm" => "M29", |
253 | | - "xt" => "M3", |
254 | | - "bnr" => "M30", |
255 | | - "bdt" => "M34", |
256 | | - "Dr" => "M36", |
257 | | - "rnp" => "M4", |
258 | | - "iz" => "M40", |
259 | | - "tr" => "M6", |
260 | | - "SA" => "M8", |
261 | | - "zSn" => "M9", |
262 | | - "pt" => "N1", |
263 | | - "Abd" => "N11", |
264 | | - "iaH" => "N11", |
265 | | - "dwA" => "N14", |
266 | | - "sbA" => "N14", |
267 | | - "dwAt" => "N15", |
268 | | - "tA" => "N16", |
269 | | - "iw" => "N18", |
270 | | - "wDb" => "N20", |
271 | | - "spAt" => "N24", |
272 | | - "xAst" => "N25", |
273 | | - "Dw" => "N26", |
274 | | - "Axt" => "N27", |
275 | | - "xa" => "N28", |
276 | | - "q" => "N29", |
277 | | - "iAt" => "N30", |
278 | | - "n" => "N35", |
279 | | - "mw" => "N35A", |
280 | | - "S" => "N37", |
281 | | - "iAdt" => "N4", |
282 | | - "idt" => "N4", |
283 | | - "Sm" => "N40", |
284 | | - "id" => "N41", |
285 | | - "hrw" => "N5", |
286 | | - "ra" => "N5", |
287 | | - "zw" => "N5", |
288 | | - "Hnmmt" => "N8", |
289 | | - "pzD" => "N9", |
290 | | - "pr" => "O1", |
291 | | - "aH" => "O11", |
292 | | - "wsxt" => "O15", |
293 | | - "kAr" => "O18", |
294 | | - "zH" => "O22", |
295 | | - "txn" => "O25", |
296 | | - "iwn" => "O28", |
297 | | - "aA" => "O29", |
298 | | - "zxnt" => "O30", |
299 | | - "z" => "O34", |
300 | | - "zb" => "O35", |
301 | | - "inb" => "O36", |
302 | | - "qnbt" => "O38A", |
303 | | - "h" => "O4", |
304 | | - "Szp" => "O42", |
305 | | - "ipt" => "O45", |
306 | | - "nxn" => "O47", |
307 | | - "niwt" => "O49", |
308 | | - "zp" => "O50", |
309 | | - "Snwt" => "O51", |
310 | | - "Hwt" => "O6", |
311 | | - "wHa" => "P4", |
312 | | - "TAw" => "P5", |
313 | | - "nfw" => "P5", |
314 | | - "aHa" => "P6", |
315 | | - "xrw" => "P8", |
316 | | - "st" => "Q1", |
317 | | - "wz" => "Q2", |
318 | | - "p" => "Q3", |
319 | | - "qrsw" => "Q6", |
320 | | - "xAt" => "R1", |
321 | | - "xAwt" => "R1", |
322 | | - "Dd" => "R11", |
323 | | - "dd" => "R11", |
324 | | - "imnt" => "R14", |
325 | | - "iAb" => "R15", |
326 | | - "wx" => "R16", |
327 | | - "xm" => "R22", |
328 | | - "Htp" => "R4", |
329 | | - "kAp" => "R5", |
330 | | - "kp" => "R5", |
331 | | - "snTr" => "R7", |
332 | | - "nTr" => "R8", |
333 | | - "nTrw" => "R8A", |
334 | | - "bd" => "R9", |
335 | | - "HDt" => "S1", |
336 | | - "mDH" => "S10", |
337 | | - "wsx" => "S11", |
338 | | - "nbw" => "S12", |
339 | | - "THn" => "S15", |
340 | | - "tHn" => "S15", |
341 | | - "mnit" => "S18", |
342 | | - "sDAw" => "S19", |
343 | | - "xtm" => "S20", |
344 | | - "sT" => "S22", |
345 | | - "dmD" => "S23", |
346 | | - "Tz" => "S24", |
347 | | - "Sndyt" => "S26", |
348 | | - "mnxt" => "S27", |
349 | | - "s" => "S29", |
350 | | - "N" => "S3", |
351 | | - "dSrt" => "S3", |
352 | | - "sf" => "S30", |
353 | | - "siA" => "S32", |
354 | | - "Tb" => "S33", |
355 | | - "anx" => "S34", |
356 | | - "Swt" => "S35", |
357 | | - "xw" => "S37", |
358 | | - "HqA" => "S38", |
359 | | - "awt" => "S39", |
360 | | - "wAs" => "S40", |
361 | | - "Dam" => "S41", |
362 | | - "abA" => "S42", |
363 | | - "sxm" => "S42", |
364 | | - "xrp" => "S42", |
365 | | - "md" => "S43", |
366 | | - "Ams" => "S44", |
367 | | - "nxxw" => "S45", |
368 | | - "K" => "S56", |
369 | | - "sxmty" => "S6", |
370 | | - "xprS" => "S7", |
371 | | - "Atf" => "S8", |
372 | | - "Swty" => "S9", |
373 | | - "pD" => "T10", |
374 | | - "sXr" => "T11", |
375 | | - "zin" => "T11", |
376 | | - "zwn" => "T11", |
377 | | - "Ai" => "T12", |
378 | | - "Ar" => "T12", |
379 | | - "rwD" => "T12", |
380 | | - "rwd" => "T12", |
381 | | - "rs" => "T13", |
382 | | - "qmA" => "T14", |
383 | | - "wrrt" => "T17", |
384 | | - "Sms" => "T18", |
385 | | - "qs" => "T19", |
386 | | - "wa" => "T21", |
387 | | - "sn" => "T22", |
388 | | - "iH" => "T24", |
389 | | - "DbA" => "T25", |
390 | | - "Xr" => "T28", |
391 | | - "nmt" => "T29", |
392 | | - "HD" => "T3", |
393 | | - "sSm" => "T31", |
394 | | - "nm" => "T34", |
395 | | - "HDD" => "T6", |
396 | | - "pd" => "T9", |
397 | | - "mA" => "U1", |
398 | | - "it" => "U10", |
399 | | - "HqAt" => "U11", |
400 | | - "Sna" => "U13", |
401 | | - "hb" => "U13", |
402 | | - "tm" => "U15", |
403 | | - "biA" => "U16", |
404 | | - "grg" => "U17", |
405 | | - "stp" => "U21", |
406 | | - "mnx" => "U22", |
407 | | - "Ab" => "U23", |
408 | | - "Hmt" => "U24", |
409 | | - "wbA" => "U26", |
410 | | - "DA" => "U28", |
411 | | - "rtH" => "U31", |
412 | | - "zmn" => "U32", |
413 | | - "ti" => "U33", |
414 | | - "xsf" => "U34", |
415 | | - "Hm" => "U36", |
416 | | - "mxAt" => "U38", |
417 | | - "mr" => "U6", |
418 | | - "100" => "V1", |
419 | | - "arq" => "V12", |
420 | | - "T" => "V13", |
421 | | - "iTi" => "V15", |
422 | | - "TmA" => "V19", |
423 | | - "XAr" => "V19", |
424 | | - "mDt" => "V19", |
425 | | - "sTA" => "V2", |
426 | | - "10" => "V20", |
427 | | - "mD" => "V20", |
428 | | - "mH" => "V22", |
429 | | - "wD" => "V24", |
430 | | - "aD" => "V26", |
431 | | - "H" => "V28", |
432 | | - "sk" => "V29", |
433 | | - "wAH" => "V29", |
434 | | - "sTAw" => "V3", |
435 | | - "nb" => "V30", |
436 | | - "k" => "V31", |
437 | | - "msn" => "V32", |
438 | | - "sSr" => "V33", |
439 | | - "idr" => "V37", |
440 | | - "wA" => "V4", |
441 | | - "snT" => "V5", |
442 | | - "sS" => "V6", |
443 | | - "Sn" => "V7", |
444 | | - "iab" => "W10", |
445 | | - "g" => "W11", |
446 | | - "nzt" => "W11", |
447 | | - "Hz" => "W14", |
448 | | - "xnt" => "W17", |
449 | | - "mi" => "W19", |
450 | | - "bAs" => "W2", |
451 | | - "Hnqt" => "W22", |
452 | | - "nw" => "W24", |
453 | | - "ini" => "W25", |
454 | | - "Hb" => "W3", |
455 | | - "Xnm" => "W9", |
456 | | - "t" => "X1", |
457 | | - "di" => "X8", |
458 | | - "rdi" => "X8", |
459 | | - "mDAt" => "Y1", |
460 | | - "mnhd" => "Y3", |
461 | | - "zS" => "Y3", |
462 | | - "mn" => "Y5", |
463 | | - "ibA" => "Y6", |
464 | | - "zSSt" => "Y8", |
465 | | - "imi" => "Z11", |
466 | | - "y" => "Z4", |
467 | | - "W" => "Z7", |
468 | | - |
469 | | - "<1" => "Ca1", //cartouche |
470 | | - "2>" => "Ca2", |
471 | | - "<2" => "Ca2a", |
472 | | - "1>" => "Ca1a", |
473 | | - "<0" => "Ca1", |
474 | | - "0>" => "Ca2", |
475 | | - "<h1" => "Cah1", //horus |
476 | | - "h1>" => "Cah1a", |
477 | | - "<h2" => "Cah2", |
478 | | - "h2>" => "Cah2a", |
479 | | - "<h3" => "Cah3", |
480 | | - "h3>" => "Cah3a", |
481 | | - "<h0" => "Cah1", |
482 | | - "h0>" => "Cah1a", |
483 | | - "<" => "Ca1", //cartouche |
484 | | - ">" => "Ca2", |
485 | | - "[&" => "Ba16", |
486 | | - "&]" => "Ba16", |
487 | | - "[{" => "Ba17", |
488 | | - "}]" => "Ba17a", |
489 | | - "[[" => "Ba15", |
490 | | - "]]" => "Ba15a", |
491 | | - "[\"" => "", |
492 | | - "\"]" => "", |
493 | | - "['" => "", |
494 | | - "']" => "", |
495 | | - ); |
496 | | - |
497 | | -/* not used yet |
498 | | - $wh_syntax = array( |
499 | | - "-", //block sepatator |
500 | | - ":", //supperposition |
501 | | - "*", //juxtaposition |
502 | | - "(", //open bracket |
503 | | - ")", //close bracket |
504 | | - "!!", //end of text |
505 | | - "!", //end of line |
506 | | - "..", //blank caracter |
507 | | - ".", //half-size blank caracter |
508 | | - "$", //color |
509 | | - "#", //shade |
510 | | - "[&", //select |
511 | | - "&]", |
512 | | - "[{", |
513 | | - "}]", |
514 | | - "[[", |
515 | | - "]]", |
516 | | - "[\"", |
517 | | - "\"]", |
518 | | - "['", |
519 | | - "']", |
520 | | - "<", //cartouche |
521 | | - ">", |
522 | | - "<1", |
523 | | - "2>", |
524 | | - "<2", |
525 | | - "1>", |
526 | | - "<0", |
527 | | - "0>", |
528 | | - "<h1", //horus |
529 | | - "h1>", |
530 | | - "<h2", |
531 | | - "h2>", |
532 | | - "<h3", |
533 | | - "h3>", |
534 | | - "<h0", |
535 | | - "h0>", |
536 | | - "++", //comment |
537 | | - "+s", //hieroglyph |
538 | | - "+t", //transcription |
539 | | - "+l", //latin-normal |
540 | | - "+i", //latin-italic |
541 | | - "+g", //latin-bold (gras) |
542 | | - "+b", //latin-bold |
543 | | - "+c", |
544 | | - ); |
545 | | -*/ |
546 | | - |
547 | | - // convertion table for text mode |
548 | | - $wh_text_conv = array( |
549 | | - "-" => " ", |
550 | | - ":" => "-", |
551 | | - "*" => "-", |
552 | | - "!" => "<br/>", |
553 | | - "." => "", |
554 | | - "=" => "", |
555 | | - "(" => "", |
556 | | - ")" => "", |
557 | | - "<1" => "(", |
558 | | - "2>" => ")|", |
559 | | - "<2" => "|(", |
560 | | - "1>" => ")", |
561 | | - "<0" => "(", |
562 | | - "0>" => ")|", |
563 | | - "<h1" => "[", //horus |
564 | | - "h1>" => "]", |
565 | | - "<h2" => "[", |
566 | | - "h2>" => "]", |
567 | | - "<h3" => "[", |
568 | | - "h3>" => "]", |
569 | | - "<h0" => "[", |
570 | | - "h0>" => "]", |
571 | | - "<" => "(", //cartouche |
572 | | - ">" => ")|", |
573 | | - ); |
574 | | - |
575 | | - //======================================================================== |
576 | | - // W I K I P E D I A S P E C I F I C |
577 | | - |
578 | | - //------------------------------------------------------------------------ |
579 | | - // WH_Register - Register MediaWiki extension |
580 | | - //------------------------------------------------------------------------ |
| 28 | + // Register MediaWiki extension |
581 | 29 | $wgExtensionFunctions[] = 'WH_Register'; |
582 | 30 | $wgExtensionCredits['parserhook'][] = array( |
583 | 31 | 'name' => 'WikiHiero', |
584 | 32 | 'author' => 'Guillaume Blanchard', |
585 | 33 | 'url' => 'http://meta.wikimedia.org/wiki/WikiHiero' |
586 | 34 | ); |
| 35 | + |
587 | 36 | function WH_Register() |
588 | 37 | { |
589 | 38 | global $wgParser; |
590 | | - $wgParser->setHook( 'hiero', 'WikiHieroHook' ); |
| 39 | + $wgParser->setHook( 'hiero', 'WikiHieroLoader' ); |
591 | 40 | } |
592 | | - |
593 | | - //------------------------------------------------------------------------ |
594 | | - // WikiHieroHook - Parser callback |
595 | | - //------------------------------------------------------------------------ |
596 | | - // hiero << text to convert |
597 | | - // return >> string with converted code |
598 | | - //------------------------------------------------------------------------ |
599 | | - function WikiHieroHook($hiero) |
| 41 | + |
| 42 | + function WikiHieroLoad() |
600 | 43 | { |
601 | | - return WikiHiero($hiero, WH_MODE_HTML); |
602 | | - } |
603 | | - |
604 | | - |
605 | | - //======================================================================== |
606 | | - // F U N C T I O N S |
607 | | - |
608 | | - //------------------------------------------------------------------------ |
609 | | - // WH_RenderGlyph - Render a glyph |
610 | | - //------------------------------------------------------------------------ |
611 | | - // glyph << glyph's code to render |
612 | | - // option << option to add into <img> tag (use for height) |
613 | | - // return >> a string to add to the stream |
614 | | - //------------------------------------------------------------------------ |
615 | | - function WH_RenderGlyph($glyph, $option="") |
616 | | - { |
617 | | - global $wh_mode; |
618 | | - global $wh_phonemes; |
619 | | - global $wh_files; |
620 | | - global $wh_scale; |
621 | | - |
622 | | - if($glyph == "..") // Render void block |
623 | | - { |
624 | | - $width = WH_HEIGHT; |
625 | | - return "<table width='{$width}px' border='0' cellspacing='0' cellpadding='0'><tr><td> </td></tr></table>"; |
| 44 | + static $loaded = false; |
| 45 | + if ( !$loaded ) { |
| 46 | + require( dirname( __FILE__ ) . '/wh_main.php' ); |
626 | 47 | } |
627 | | - else if($glyph == ".") // Render half-width void block |
628 | | - { |
629 | | - $width = WH_HEIGHT/2; |
630 | | - return "<table width='{$width}px' border='0' cellspacing='0' cellpadding='0'><tr><td> </td></tr></table>"; |
631 | | - } |
632 | | - else if($glyph == '<') // Render open cartouche |
633 | | - { |
634 | | - $height = intval(WH_HEIGHT * $wh_scale / 100); |
635 | | - $code = $wh_phonemes[$glyph]; |
636 | | - return "<img src='".htmlspecialchars(WH_IMG_DIR.WH_IMG_PRE."{$code}.".WH_IMG_EXT)."' height='{$height}px' title='".htmlspecialchars($glyph)."' alt='".htmlspecialchars($glyph)."' />"; |
637 | | - } |
638 | | - else if($glyph == '>') // Render close cartouche |
639 | | - { |
640 | | - $height = intval(WH_HEIGHT * $wh_scale / 100); |
641 | | - $code = $wh_phonemes[$glyph]; |
642 | | - return "<img src='".htmlspecialchars(WH_IMG_DIR.WH_IMG_PRE."{$code}.".WH_IMG_EXT)."' height='{$height}px' title='".htmlspecialchars($glyph)."' alt='".htmlspecialchars($glyph)."' />"; |
643 | | - } |
644 | | - |
645 | | - if(array_key_exists($glyph, $wh_phonemes)) |
646 | | - { |
647 | | - $code = $wh_phonemes[$glyph]; |
648 | | - if(array_key_exists($code, $wh_files)) |
649 | | - return "<img style='margin:".WH_IMG_MARGIN."px;' $option src='".htmlspecialchars(WH_IMG_DIR.WH_IMG_PRE."{$code}.".WH_IMG_EXT)."' title='".htmlspecialchars("{$code} [{$glyph}]")."' alt='".htmlspecialchars($glyph)."' />"; |
650 | | - else |
651 | | - return "<font title='".htmlspecialchars($code)."'>".htmlspecialchars($glyph)."</font>"; |
652 | | - } |
653 | | - else if(array_key_exists($glyph, $wh_files)) |
654 | | - return "<img style='margin:".WH_IMG_MARGIN."px;' $option src='".htmlspecialchars(WH_IMG_DIR.WH_IMG_PRE."{$glyph}.".WH_IMG_EXT)."' title='".htmlspecialchars($glyph)."' alt='".htmlspecialchars($glyph)."' />"; |
655 | | - else |
656 | | - return htmlspecialchars($glyph); |
657 | 48 | } |
658 | | - |
659 | | - //------------------------------------------------------------------------ |
660 | | - // WH_Resize - Resize a glyph |
661 | | - //------------------------------------------------------------------------ |
662 | | - // item << glyph's code |
663 | | - // is_cartouche << true if glyph inside a cartouche |
664 | | - // total << total size of a group for multi-glyph block |
665 | | - // return >> size |
666 | | - //------------------------------------------------------------------------ |
667 | | - function WH_Resize($item, $is_cartouche=false, $total=0) |
| 49 | + |
| 50 | + // MediaWiki entry point |
| 51 | + function WikiHieroLoader( $text, $attribs, &$parser ) |
668 | 52 | { |
669 | | - global $wh_phonemes; |
670 | | - global $wh_files; |
671 | | - global $wh_scale; |
672 | | - |
673 | | - if(array_key_exists($item, $wh_phonemes)) |
674 | | - $glyph = $wh_phonemes[$item]; |
675 | | - else |
676 | | - $glyph = $item; |
677 | | - |
678 | | - $margin = 2 * WH_IMG_MARGIN; |
679 | | - if($is_cartouche) |
680 | | - $margin += 2 * intval(WH_CARTOUCHE_WIDTH * $wh_scale / 100); |
681 | | - |
682 | | - if(array_key_exists($glyph, $wh_files)) |
683 | | - { |
684 | | - $height = $margin + $wh_files[$glyph][1]; |
685 | | - if($total) |
686 | | - { |
687 | | - if($total > WH_HEIGHT) |
688 | | - return (intval( $height * WH_HEIGHT / $total ) - $margin) * $wh_scale / 100; |
689 | | - else |
690 | | - return ($height - $margin) * $wh_scale / 100; |
691 | | - } |
692 | | - else |
693 | | - { |
694 | | - if($height > WH_HEIGHT) |
695 | | - return (intval( WH_HEIGHT * WH_HEIGHT / $height ) - $margin) * $wh_scale / 100; |
696 | | - else |
697 | | - return ($height - $margin) * $wh_scale / 100; |
698 | | - } |
699 | | - } |
700 | | - |
701 | | - return (WH_HEIGHT - $margin) * $wh_scale / 100; |
| 53 | + WikiHieroLoad(); |
| 54 | + $parser->setHook( 'hiero', 'WikiHieroHook' ); |
| 55 | + return WikiHieroHook( $text, $attribs, $parser ); |
702 | 56 | } |
703 | 57 | |
704 | | - //======================================================================== |
705 | | - // |
706 | | - // W i k i H i e r o |
707 | | - // |
708 | | - |
709 | | - //------------------------------------------------------------------------ |
710 | | - // WikiHiero - Render hieroglyph text |
711 | | - //------------------------------------------------------------------------ |
712 | | - // hiero << text to convert |
713 | | - // mode << convertion mode [DEFAULT|TEXT|HTML|STYLE|IMAGE] (def=HTML) |
714 | | - // scale << global scale in percentage (def=100%) |
715 | | - // line << use line [true|false] (def=false) |
716 | | - // return >> string with converted code |
717 | | - //------------------------------------------------------------------------ |
| 58 | + // Generic embedded entry point |
718 | 59 | function WikiHiero($hiero, $mode=WH_MODE_DEFAULT, $scale=WH_SCALE_DEFAULT, $line=false) |
719 | 60 | { |
720 | | - if($mode != WH_MODE_DEFAULT) |
721 | | - $wh_mode = $mode; |
722 | | - |
723 | | - switch($wh_mode) |
724 | | - { |
725 | | - case WH_MODE_TEXT: return WikiHieroText($hiero, $line); |
726 | | - case WH_MODE_HTML: return WikiHieroHTML($hiero, $scale, $line); |
727 | | - case WH_MODE_STYLE: die("ERROR: CSS version not yet implemented"); |
728 | | - case WH_MODE_IMAGE: die("ERROR: Image version not yet implemented"); |
729 | | - } |
730 | | - die("ERROR: Unknow mode!"); |
| 61 | + WikiHieroLoad(); |
| 62 | + return _WikiHiero( $hiero, $mode, $scale, $line ); |
731 | 63 | } |
732 | 64 | |
733 | | - //------------------------------------------------------------------------ |
734 | | - // WikiHieroText - Render hieroglyph text in text mode |
735 | | - //------------------------------------------------------------------------ |
736 | | - // hiero << text to convert |
737 | | - // line << use line [true|false] (def=false) |
738 | | - // return >> string with converted code |
739 | | - //------------------------------------------------------------------------ |
740 | | - function WikiHieroText($hiero, $line=false) |
741 | | - { |
742 | | - global $wh_text_conv; |
| 65 | + // If anyone needs WikiHieroHTML() etc., loader functions should be put here. |
| 66 | + // Hopefully everyone's using the general-purpose entry point above. |
743 | 67 | |
744 | | - $html = ""; |
745 | | - |
746 | | - if($line) |
747 | | - $html .= "<hr />\n"; |
748 | | - |
749 | | - for($char=0; $char<strlen($hiero); $char++) |
750 | | - { |
751 | | - if(array_key_exists($hiero[$char], $wh_text_conv)) |
752 | | - { |
753 | | - $html .= $wh_text_conv[$hiero[$char]]; |
754 | | - if($hiero[$char] == '!') |
755 | | - if($line) |
756 | | - $html .= "<hr />\n"; |
757 | | - } |
758 | | - else |
759 | | - $html .= $hiero[$char]; |
760 | | - } |
761 | | - |
762 | | - return $html; |
763 | | - } |
764 | | - |
765 | | - //------------------------------------------------------------------------ |
766 | | - // WikiHiero - Render hieroglyph text |
767 | | - //------------------------------------------------------------------------ |
768 | | - // hiero << text to convert |
769 | | - // scale << global scale in percentage (def=100%) |
770 | | - // line << use line [true|false] (def=false) |
771 | | - // return >> string with converted code |
772 | | - //------------------------------------------------------------------------ |
773 | | - function WikiHieroHTML($hiero, $scale=WH_SCALE_DEFAULT, $line=false) |
774 | | - { |
775 | | - global $wh_prefabs; |
776 | | - global $wh_files; |
777 | | - global $wh_phonemes; |
778 | | - global $wh_scale; |
779 | | - |
780 | | - if($scale != WH_SCALE_DEFAULT) |
781 | | - $wh_scale = $scale; |
782 | | - |
783 | | - $html = ""; |
784 | | - |
785 | | - if($line) |
786 | | - $html .= "<hr />\n"; |
787 | | - |
788 | | - //------------------------------------------------------------------------ |
789 | | - // Split text into block, then split block into item |
790 | | - $block = array(); |
791 | | - $block[0] = array(); |
792 | | - $block[0][0] = ""; |
793 | | - $block_id = 0; |
794 | | - $item_id = 0; |
795 | | - $parenthesis = 0; |
796 | | - $type = WH_TYPE_NONE; |
797 | | - $is_cartouche = false; |
798 | | - $is_striped = false; |
799 | | - |
800 | | - for($char=0; $char<strlen($hiero); $char++) |
801 | | - { |
802 | | - if($hiero[$char] == '(') |
803 | | - { |
804 | | - $parenthesis++; |
805 | | - } |
806 | | - else if($hiero[$char] == ')') |
807 | | - { |
808 | | - $parenthesis--; |
809 | | - } |
810 | | - if($parenthesis == 0) |
811 | | - { |
812 | | - if($hiero[$char] == '-' || $hiero[$char] == ' ') |
813 | | - { |
814 | | - if($type != WH_TYPE_NONE) |
815 | | - { |
816 | | - $block_id++; |
817 | | - $block[$block_id] = array(); |
818 | | - $item_id = 0; |
819 | | - $block[$block_id][$item_id] = ""; |
820 | | - $type = WH_TYPE_NONE; |
821 | | - } |
822 | | - } |
823 | | - } |
824 | | - else // don't slit block if inside parenthesis |
825 | | - { |
826 | | - if($hiero[$char] == '-') |
827 | | - { |
828 | | - $item_id++; |
829 | | - $block[$block_id][$item_id] = '-'; |
830 | | - $type = WH_TYPE_CODE; |
831 | | - } |
832 | | - } |
833 | | - if($hiero[$char] == '!' ) |
834 | | - { |
835 | | - if($item_id > 0) |
836 | | - { |
837 | | - $block_id++; |
838 | | - $block[$block_id] = array(); |
839 | | - $item_id = 0; |
840 | | - } |
841 | | - $block[$block_id][$item_id] = $hiero[$char]; |
842 | | - $type = WH_TYPE_END; |
843 | | - } |
844 | | - else if(ereg("[*:()]", $hiero[$char])) |
845 | | - { |
846 | | - if($type == WH_TYPE_GLYPH || $type == WH_TYPE_CODE) |
847 | | - { |
848 | | - $item_id++; |
849 | | - $block[$block_id][$item_id] = ""; |
850 | | - } |
851 | | - $block[$block_id][$item_id] = $hiero[$char]; |
852 | | - $type = WH_TYPE_CODE; |
853 | | - } |
854 | | - else if(ctype_alnum($hiero[$char]) || $hiero[$char] == '.' || $hiero[$char] == '<' || $hiero[$char] == '>') |
855 | | - { |
856 | | - if($type == WH_TYPE_END) |
857 | | - { |
858 | | - $block_id++; |
859 | | - $block[$block_id] = array(); |
860 | | - $item_id = 0; |
861 | | - $block[$block_id][$item_id] = ""; |
862 | | - } |
863 | | - else if($type == WH_TYPE_CODE) |
864 | | - { |
865 | | - $item_id++; |
866 | | - $block[$block_id][$item_id] = ""; |
867 | | - } |
868 | | - $block[$block_id][$item_id] .= $hiero[$char]; |
869 | | - $type = WH_TYPE_GLYPH; |
870 | | - } |
871 | | - } |
872 | | - |
873 | | - // DEBUG: See the block split table |
874 | | - if(WH_DEBUG_MODE) |
875 | | - { |
876 | | - foreach($block as $code) |
877 | | - { |
878 | | - echo "| "; |
879 | | - foreach($code as $item) |
880 | | - { |
881 | | - echo "$item | "; |
882 | | - } |
883 | | - echo "<br />\n"; |
884 | | - } |
885 | | - } |
886 | | - |
887 | | - $contentHtml = $tableHtml = $tableContentHtml = ""; |
888 | | - //$html .= WH_TABLE_S."<tr>\n"; |
889 | | - |
890 | | - //------------------------------------------------------------------------ |
891 | | - // Loop into all blocks |
892 | | - foreach($block as $code) |
893 | | - { |
894 | | - // simplest case, the block contain only 1 code -> render |
895 | | - if(count($code) == 1) |
896 | | - { |
897 | | - if($code[0] == "!") // end of line |
898 | | - { |
899 | | - $tableHtml = "</tr>".WH_TABLE_E.WH_TABLE_S."<tr>\n"; |
900 | | - if($line) |
901 | | - $contentHtml .= "<hr />\n"; |
902 | | - } |
903 | | - |
904 | | - else if(strchr($code[0], '<')) // start cartouche |
905 | | - { |
906 | | - $contentHtml .= WH_TD_S.WH_RenderGlyph($code[0]).WH_TD_E; |
907 | | - $is_cartouche = true; |
908 | | - $contentHtml .= "<td>".WH_TABLE_S."<tr><td height='".intval(WH_CARTOUCHE_WIDTH * $wh_scale / 100)."px' bgcolor='black'></td></tr><tr><td>".WH_TABLE_S."<tr>"; |
909 | | - } |
910 | | - |
911 | | - else if(strchr($code[0], '>')) // end cartouche |
912 | | - { |
913 | | - $contentHtml .= "</tr>".WH_TABLE_E."</td></tr><tr><td height='".intval(WH_CARTOUCHE_WIDTH * $wh_scale / 100)."px' bgcolor='black'></td></tr>".WH_TABLE_E."</td>"; |
914 | | - $is_cartouche = false; |
915 | | - $contentHtml .= WH_TD_S.WH_RenderGlyph($code[0]).WH_TD_E; |
916 | | - } |
917 | | - |
918 | | - else if($code[0] != "") // assum is glyph or '..' or '.' |
919 | | - { |
920 | | - $option = "height='".WH_Resize($code[0], $is_cartouche)."px'"; |
921 | | - |
922 | | - $contentHtml .= WH_TD_S.WH_RenderGlyph($code[0], $option).WH_TD_E; |
923 | | - } |
924 | | - } |
925 | | - // block contain more than 1 glyph |
926 | | - else |
927 | | - { |
928 | | - // convert all code into '&' to test prefabs glyph |
929 | | - $temp = ""; |
930 | | - foreach($code as $t) |
931 | | - { |
932 | | - if(ereg("[*:!()]", $t[0])) |
933 | | - $temp .= "&"; |
934 | | - else |
935 | | - $temp .= $t; |
936 | | - } |
937 | | - // test is block is into tje prefabs list |
938 | | - if(in_array($temp, $wh_prefabs)) |
939 | | - { |
940 | | - $option = "height='".WH_Resize($temp, $is_cartouche)."px'"; |
941 | | - |
942 | | - $contentHtml .= WH_TD_S.WH_RenderGlyph($temp, $option).WH_TD_E; |
943 | | - } |
944 | | - // block must be manualy compute |
945 | | - else |
946 | | - { |
947 | | - // get block total height |
948 | | - $line_max = 0; |
949 | | - $total = 0; |
950 | | - $height = 0; |
951 | | - foreach($code as $t) |
952 | | - { |
953 | | - if($t == ":") |
954 | | - { |
955 | | - if($height > $line_max) |
956 | | - $line_max = $height; |
957 | | - $total += $line_max; |
958 | | - $line_max = 0; |
959 | | - } |
960 | | - else if($t == "*") |
961 | | - { |
962 | | - if($height > $line_max) |
963 | | - $line_max = $height; |
964 | | - } |
965 | | - else |
966 | | - { |
967 | | - if(array_key_exists($t, $wh_phonemes)) |
968 | | - $glyph = $wh_phonemes[$t]; |
969 | | - else |
970 | | - $glyph = $t; |
971 | | - |
972 | | - if(array_key_exists($glyph, $wh_files)) |
973 | | - $height = 2 + $wh_files[$glyph][1]; |
974 | | - } |
975 | | - } |
976 | | - if($height > $line_max) |
977 | | - $line_max = $height; |
978 | | - $total += $line_max; |
979 | | - |
980 | | - // render all glyph into the block |
981 | | - $temp = ""; |
982 | | - foreach($code as $t) |
983 | | - { |
984 | | - if($t == ":") |
985 | | - $temp .= "<br />"; |
986 | | - else if($t == "*") |
987 | | - $temp .= " "; |
988 | | - else |
989 | | - { |
990 | | - // resize the glyph according to the block total height |
991 | | - $option = "height='".WH_Resize($t, $is_cartouche, $total)."px'"; |
992 | | - $temp .= WH_RenderGlyph($t, $option); |
993 | | - } |
994 | | - } |
995 | | - $contentHtml .= WH_TD_S.$temp.WH_TD_E; |
996 | | - } |
997 | | - $contentHtml .= "\n"; |
998 | | - } |
999 | | - if(strlen($contentHtml) > 0) |
1000 | | - { |
1001 | | - $tableContentHtml .= $tableHtml.$contentHtml; |
1002 | | - $contentHtml = $tableHtml = ""; |
1003 | | - } |
1004 | | - } |
1005 | | - if(strlen($tableContentHtml) > 0) |
1006 | | - { |
1007 | | - $html .= WH_TABLE_S."<tr>\n".$tableContentHtml."</tr>".WH_TABLE_E; |
1008 | | - } |
1009 | | - |
1010 | | - return "<table border='0' cellspacing='0' cellpadding='0' style='display:inline;' ><tr><td>\n$html\n</td></tr></table>"; |
1011 | | - } |
1012 | | - |
1013 | | - //------------------------------------------------------------------------ |
1014 | | - // WH_GetCode - Get glyph code from file name |
1015 | | - //------------------------------------------------------------------------ |
1016 | | - // file << file name |
1017 | | - // return >> string with converted code |
1018 | | - //------------------------------------------------------------------------ |
1019 | | - function WH_GetCode($file) |
1020 | | - { |
1021 | | - return substr($file, strlen(WH_IMG_PRE), -(1+strlen(WH_IMG_EXT))); |
1022 | | - } |
1023 | | - |
1024 | | - //------------------------------------------------------------------------ |
1025 | | - // WH_GetCode - Get glyph code from file name |
1026 | | - //------------------------------------------------------------------------ |
1027 | | - // return >> credit string |
1028 | | - //------------------------------------------------------------------------ |
1029 | | - function WH_Credit() |
1030 | | - { |
1031 | | - $html = ""; |
1032 | | - $html .= "<b>WikiHiero v".WH_VER_MAJ.".".WH_VER_MED.".".WH_VER_MIN."</b>\n"; |
1033 | | - $html .= "by Guillaume Blanchard (Aoineko) under GPL (2004).<br />\n"; |
1034 | | - $html .= "Hieroglyph credit: S. Rosmorduc, G. Watson, J. Hirst (under GFDL).\n"; |
1035 | | - return $html; |
1036 | | - } |
1037 | | - |
1038 | 68 | # vim: set sts=2 sw=2 ts=2 et : |
1039 | 69 | ?> |
Index: trunk/extensions/wikihiero/wh_main.php |
— | — | @@ -0,0 +1,1022 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +////////////////////////////////////////////////////////////////////////// |
| 5 | +// |
| 6 | +// WikiHiero - A PHP convert from text using "Manual for the encoding of |
| 7 | +// hieroglyphic texts for computer input" syntax to HTML entities (table and |
| 8 | +// images). |
| 9 | +// |
| 10 | +// Copyright (C) 2004 Guillaume Blanchard (Aoineko) |
| 11 | +// |
| 12 | +// This program is free software; you can redistribute it and/or |
| 13 | +// modify it under the terms of the GNU General Public License |
| 14 | +// as published by the Free Software Foundation; either version 2 |
| 15 | +// of the License, or any later version. |
| 16 | +// |
| 17 | +// This program is distributed in the hope that it will be useful, |
| 18 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | +// GNU General Public License for more details. |
| 21 | +// |
| 22 | +// You should have received a copy of the GNU General Public License |
| 23 | +// along with this program; if not, write to the Free Software |
| 24 | +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | +// |
| 26 | +////////////////////////////////////////////////////////////////////////// |
| 27 | + |
| 28 | + //======================================================================== |
| 29 | + // I N C L U D E S |
| 30 | + include "wh_list.php"; |
| 31 | + |
| 32 | + //======================================================================== |
| 33 | + // D E F I N E S |
| 34 | + define("WH_TABLE_S", "<table border='0' cellspacing='0' cellpadding='0'>"); |
| 35 | + define("WH_TABLE_E", "</table>"); |
| 36 | + define("WH_TD_S", "<td align='center' valign='middle'>"); |
| 37 | + define("WH_TD_E", "</td>"); |
| 38 | + |
| 39 | + define("WH_MODE_DEFAULT", -1); // use default mode |
| 40 | + define("WH_MODE_TEXT", 0); // text only |
| 41 | + define("WH_MODE_HTML", 1); // HTML without CSS |
| 42 | + define("WH_MODE_STYLE", 2); // HTML and CSS // not supporter |
| 43 | + define("WH_MODE_IMAGE", 3); // picture (PNG) // not supporter |
| 44 | + define("WH_MODE_RAW", 4); // MdC test as it |
| 45 | + |
| 46 | + define("WH_TYPE_NONE", 0); |
| 47 | + define("WH_TYPE_GLYPH", 1); // rendered items |
| 48 | + define("WH_TYPE_CODE", 2); // single code as ':', '*', '!', '(' or ')' |
| 49 | + define("WH_TYPE_SPECIAL", 3); // advanced code (more than 1 caracter) |
| 50 | + define("WH_TYPE_END", 4); // end of line '!' |
| 51 | + |
| 52 | + define("WH_SCALE_DEFAULT", -1); // use default scale |
| 53 | + define("WH_HEIGHT", 44); |
| 54 | + define("WH_IMG_MARGIN", 1); // default value |
| 55 | + define("WH_CARTOUCHE_WIDTH", 2); // default value |
| 56 | + |
| 57 | + define("WH_VER_MAJ", 0); |
| 58 | + define("WH_VER_MED", 2); |
| 59 | + define("WH_VER_MIN", 14); |
| 60 | + |
| 61 | + global $wgScriptPath; |
| 62 | + define("WH_IMG_DIR", $wgScriptPath . '/extensions/wikihiero/img/' ); //"img/"); // |
| 63 | + define("WH_IMG_PRE", "hiero_"); |
| 64 | + define("WH_IMG_EXT", "png"); |
| 65 | + |
| 66 | + define("WH_DEBUG_MODE", false); |
| 67 | + |
| 68 | + //======================================================================== |
| 69 | + // G L O B A L S |
| 70 | + global $wh_mode, $wh_scale, $wh_phonemes, $wh_text_conv; |
| 71 | + |
| 72 | + $wh_mode = WH_MODE_HTML; // default value |
| 73 | + $wh_scale = 100; // default value |
| 74 | + |
| 75 | + $wh_phonemes = array( // convertion table phoneme -> gardiner code |
| 76 | + "mSa" => "A12", |
| 77 | + "xr" => "A15", |
| 78 | + "Xrd" => "A17", |
| 79 | + "sr" => "A21", |
| 80 | + "mniw" => "A33", |
| 81 | + "qiz" => "A38", |
| 82 | + "iry" => "A47", |
| 83 | + "Sps" => "A50", |
| 84 | + "Spsi" => "A51", |
| 85 | +/* |
| 86 | + "x" => "J1", |
| 87 | + "mAa" => "J11", |
| 88 | + "gs" => "J13", |
| 89 | + "im" => "J13", |
| 90 | + "M" => "J15", |
| 91 | + "sA" => "J17", |
| 92 | + "apr" => "J20", |
| 93 | + "wDa" => "J21", |
| 94 | + "nD" => "J27", |
| 95 | + "qd" => "J28", |
| 96 | + "Xkr" => "J30", |
| 97 | + "Hp" => "J5", |
| 98 | + "qn" => "J8", |
| 99 | +*/ |
| 100 | + "x" => "Aa1", |
| 101 | + "mAa" => "Aa11", |
| 102 | + "gs" => "Aa13", |
| 103 | + "im" => "Aa13", |
| 104 | + "M" => "Aa15", |
| 105 | + "sA" => "Aa17", |
| 106 | + "apr" => "Aa20", |
| 107 | + "wDa" => "Aa21", |
| 108 | + "nD" => "Aa27", |
| 109 | + "qd" => "Aa28", |
| 110 | + "Xkr" => "Aa30", |
| 111 | + "Hp" => "Aa5", |
| 112 | + "qn" => "Aa8", |
| 113 | + |
| 114 | + "msi" => "B3", |
| 115 | + "mAat" => "C10", |
| 116 | + "HH" => "C11", |
| 117 | + "DHwty" => "C3", |
| 118 | + "Xnmw" => "C4", |
| 119 | + "inpw" => "C6", |
| 120 | + "stX" => "C7", |
| 121 | + "mnw" => "C8", |
| 122 | + "tp" => "D1", |
| 123 | + "wDAt" => "D10", |
| 124 | + "R" => "D153", |
| 125 | + "fnD" => "D19", |
| 126 | + "Hr" => "D2", |
| 127 | + "r" => "D21", |
| 128 | + "rA" => "D21", |
| 129 | + "spt" => "D24", |
| 130 | + "spty" => "D25", |
| 131 | + "mnD" => "D27", |
| 132 | + "kA" => "D28", |
| 133 | + "Sny" => "D3", |
| 134 | + "aHA" => "D34", |
| 135 | + "a" => "D36", |
| 136 | + "ir" => "D4", |
| 137 | + "Dsr" => "D45", |
| 138 | + "d" => "D46", |
| 139 | + "Dba" => "D50", |
| 140 | + "mt" => "D52", |
| 141 | + "gH" => "D56", |
| 142 | + "gHs" => "D56", |
| 143 | + "rd" => "D56", |
| 144 | + "sbq" => "D56", |
| 145 | + "b" => "D58", |
| 146 | + "ab" => "D59", |
| 147 | + "wab" => "D60", |
| 148 | + "sAH" => "D61", |
| 149 | + "rmi" => "D9", |
| 150 | + "zAb" => "E17", |
| 151 | + "mAi" => "E22", |
| 152 | + "l" => "E23", |
| 153 | + "rw" => "E23", |
| 154 | + "Aby" => "E24", |
| 155 | + "wn" => "E34", |
| 156 | + "zzmt" => "E6", |
| 157 | + "wsr" => "F12", |
| 158 | + "wp" => "F13", |
| 159 | + "db" => "F16", |
| 160 | + "Hw" => "F18", |
| 161 | + "bH" => "F18", |
| 162 | + "ns" => "F20", |
| 163 | + "DrD" => "F21", |
| 164 | + "idn" => "F21", |
| 165 | + "msDr" => "F21", |
| 166 | + "sDm" => "F21", |
| 167 | + "kfA" => "F22", |
| 168 | + "pH" => "F22", |
| 169 | + "xpS" => "F23", |
| 170 | + "wHm" => "F25", |
| 171 | + "Xn" => "F26", |
| 172 | + "sti" => "F29", |
| 173 | + "Sd" => "F30", |
| 174 | + "ms" => "F31", |
| 175 | + "X" => "F32", |
| 176 | + "sd" => "F33", |
| 177 | + "ib" => "F34", |
| 178 | + "nfr" => "F35", |
| 179 | + "zmA" => "F36", |
| 180 | + "imAx" => "F39", |
| 181 | + "HAt" => "F4", |
| 182 | + "Aw" => "F40", |
| 183 | + "spr" => "F42", |
| 184 | + "isw" => "F44", |
| 185 | + "iwa" => "F44", |
| 186 | + "pXr" => "F46", |
| 187 | + "qAb" => "F46", |
| 188 | + "SsA" => "F5", |
| 189 | + "A" => "G1", |
| 190 | + "mwt" => "G14", |
| 191 | + "nbty" => "G16", |
| 192 | + "m" => "G17", |
| 193 | + "mm" => "G18", |
| 194 | + "AA" => "G2", |
| 195 | + "nH" => "G21", |
| 196 | + "Db" => "G22", |
| 197 | + "rxyt" => "G23", |
| 198 | + "Ax" => "G25", |
| 199 | + "dSr" => "G27", |
| 200 | + "gm" => "G28", |
| 201 | + "bA" => "G29", |
| 202 | + "baHi" => "G32", |
| 203 | + "aq" => "G35", |
| 204 | + "wr" => "G36", |
| 205 | + "nDs" => "G37", |
| 206 | + "gb" => "G38", |
| 207 | + "zA" => "G39", |
| 208 | + "tyw" => "G4", |
| 209 | + "pA" => "G40", |
| 210 | + "xn" => "G41", |
| 211 | + "wSA" => "G42", |
| 212 | + "w" => "G43", |
| 213 | + "ww" => "G44", |
| 214 | + "mAw" => "G46", |
| 215 | + "TA" => "G47", |
| 216 | + "snD" => "G54", |
| 217 | + "pq" => "H2", |
| 218 | + "wSm" => "H2", |
| 219 | + "pAq" => "H3", |
| 220 | + "nr" => "H4", |
| 221 | + "Sw" => "H6", |
| 222 | + "aSA" => "I1", |
| 223 | + "D" => "I10", |
| 224 | + "DD" => "I11", |
| 225 | + "Styw" => "I2", |
| 226 | + "mzH" => "I3", |
| 227 | + "sbk" => "I4", |
| 228 | + "sAq" => "I5", |
| 229 | + "km" => "I6", |
| 230 | + "Hfn" => "I8", |
| 231 | + "f" => "I9", |
| 232 | + "in" => "K1", |
| 233 | + "ad" => "K3", |
| 234 | + "XA" => "K4", |
| 235 | + "bz" => "K5", |
| 236 | + "nSmt" => "K6", |
| 237 | + "xpr" => "L1", |
| 238 | + "bit" => "L2", |
| 239 | + "srqt" => "L7", |
| 240 | + "iAm" => "M1", |
| 241 | + "wdn" => "M11", |
| 242 | + "xA" => "M12", |
| 243 | + "1000" => "M12", |
| 244 | + "wAD" => "M13", |
| 245 | + "HA" => "M16", |
| 246 | + "i" => "M17", |
| 247 | + "ii" => "M18", |
| 248 | + "Hn" => "M2", |
| 249 | + "sxt" => "M20", |
| 250 | + "sm" => "M21", |
| 251 | + "nn" => "M22A", |
| 252 | + "sw" => "M23", |
| 253 | + "rsw" => "M24", |
| 254 | + "Sma" => "M26", |
| 255 | + "nDm" => "M29", |
| 256 | + "xt" => "M3", |
| 257 | + "bnr" => "M30", |
| 258 | + "bdt" => "M34", |
| 259 | + "Dr" => "M36", |
| 260 | + "rnp" => "M4", |
| 261 | + "iz" => "M40", |
| 262 | + "tr" => "M6", |
| 263 | + "SA" => "M8", |
| 264 | + "zSn" => "M9", |
| 265 | + "pt" => "N1", |
| 266 | + "Abd" => "N11", |
| 267 | + "iaH" => "N11", |
| 268 | + "dwA" => "N14", |
| 269 | + "sbA" => "N14", |
| 270 | + "dwAt" => "N15", |
| 271 | + "tA" => "N16", |
| 272 | + "iw" => "N18", |
| 273 | + "wDb" => "N20", |
| 274 | + "spAt" => "N24", |
| 275 | + "xAst" => "N25", |
| 276 | + "Dw" => "N26", |
| 277 | + "Axt" => "N27", |
| 278 | + "xa" => "N28", |
| 279 | + "q" => "N29", |
| 280 | + "iAt" => "N30", |
| 281 | + "n" => "N35", |
| 282 | + "mw" => "N35A", |
| 283 | + "S" => "N37", |
| 284 | + "iAdt" => "N4", |
| 285 | + "idt" => "N4", |
| 286 | + "Sm" => "N40", |
| 287 | + "id" => "N41", |
| 288 | + "hrw" => "N5", |
| 289 | + "ra" => "N5", |
| 290 | + "zw" => "N5", |
| 291 | + "Hnmmt" => "N8", |
| 292 | + "pzD" => "N9", |
| 293 | + "pr" => "O1", |
| 294 | + "aH" => "O11", |
| 295 | + "wsxt" => "O15", |
| 296 | + "kAr" => "O18", |
| 297 | + "zH" => "O22", |
| 298 | + "txn" => "O25", |
| 299 | + "iwn" => "O28", |
| 300 | + "aA" => "O29", |
| 301 | + "zxnt" => "O30", |
| 302 | + "z" => "O34", |
| 303 | + "zb" => "O35", |
| 304 | + "inb" => "O36", |
| 305 | + "qnbt" => "O38A", |
| 306 | + "h" => "O4", |
| 307 | + "Szp" => "O42", |
| 308 | + "ipt" => "O45", |
| 309 | + "nxn" => "O47", |
| 310 | + "niwt" => "O49", |
| 311 | + "zp" => "O50", |
| 312 | + "Snwt" => "O51", |
| 313 | + "Hwt" => "O6", |
| 314 | + "wHa" => "P4", |
| 315 | + "TAw" => "P5", |
| 316 | + "nfw" => "P5", |
| 317 | + "aHa" => "P6", |
| 318 | + "xrw" => "P8", |
| 319 | + "st" => "Q1", |
| 320 | + "wz" => "Q2", |
| 321 | + "p" => "Q3", |
| 322 | + "qrsw" => "Q6", |
| 323 | + "xAt" => "R1", |
| 324 | + "xAwt" => "R1", |
| 325 | + "Dd" => "R11", |
| 326 | + "dd" => "R11", |
| 327 | + "imnt" => "R14", |
| 328 | + "iAb" => "R15", |
| 329 | + "wx" => "R16", |
| 330 | + "xm" => "R22", |
| 331 | + "Htp" => "R4", |
| 332 | + "kAp" => "R5", |
| 333 | + "kp" => "R5", |
| 334 | + "snTr" => "R7", |
| 335 | + "nTr" => "R8", |
| 336 | + "nTrw" => "R8A", |
| 337 | + "bd" => "R9", |
| 338 | + "HDt" => "S1", |
| 339 | + "mDH" => "S10", |
| 340 | + "wsx" => "S11", |
| 341 | + "nbw" => "S12", |
| 342 | + "THn" => "S15", |
| 343 | + "tHn" => "S15", |
| 344 | + "mnit" => "S18", |
| 345 | + "sDAw" => "S19", |
| 346 | + "xtm" => "S20", |
| 347 | + "sT" => "S22", |
| 348 | + "dmD" => "S23", |
| 349 | + "Tz" => "S24", |
| 350 | + "Sndyt" => "S26", |
| 351 | + "mnxt" => "S27", |
| 352 | + "s" => "S29", |
| 353 | + "N" => "S3", |
| 354 | + "dSrt" => "S3", |
| 355 | + "sf" => "S30", |
| 356 | + "siA" => "S32", |
| 357 | + "Tb" => "S33", |
| 358 | + "anx" => "S34", |
| 359 | + "Swt" => "S35", |
| 360 | + "xw" => "S37", |
| 361 | + "HqA" => "S38", |
| 362 | + "awt" => "S39", |
| 363 | + "wAs" => "S40", |
| 364 | + "Dam" => "S41", |
| 365 | + "abA" => "S42", |
| 366 | + "sxm" => "S42", |
| 367 | + "xrp" => "S42", |
| 368 | + "md" => "S43", |
| 369 | + "Ams" => "S44", |
| 370 | + "nxxw" => "S45", |
| 371 | + "K" => "S56", |
| 372 | + "sxmty" => "S6", |
| 373 | + "xprS" => "S7", |
| 374 | + "Atf" => "S8", |
| 375 | + "Swty" => "S9", |
| 376 | + "pD" => "T10", |
| 377 | + "sXr" => "T11", |
| 378 | + "zin" => "T11", |
| 379 | + "zwn" => "T11", |
| 380 | + "Ai" => "T12", |
| 381 | + "Ar" => "T12", |
| 382 | + "rwD" => "T12", |
| 383 | + "rwd" => "T12", |
| 384 | + "rs" => "T13", |
| 385 | + "qmA" => "T14", |
| 386 | + "wrrt" => "T17", |
| 387 | + "Sms" => "T18", |
| 388 | + "qs" => "T19", |
| 389 | + "wa" => "T21", |
| 390 | + "sn" => "T22", |
| 391 | + "iH" => "T24", |
| 392 | + "DbA" => "T25", |
| 393 | + "Xr" => "T28", |
| 394 | + "nmt" => "T29", |
| 395 | + "HD" => "T3", |
| 396 | + "sSm" => "T31", |
| 397 | + "nm" => "T34", |
| 398 | + "HDD" => "T6", |
| 399 | + "pd" => "T9", |
| 400 | + "mA" => "U1", |
| 401 | + "it" => "U10", |
| 402 | + "HqAt" => "U11", |
| 403 | + "Sna" => "U13", |
| 404 | + "hb" => "U13", |
| 405 | + "tm" => "U15", |
| 406 | + "biA" => "U16", |
| 407 | + "grg" => "U17", |
| 408 | + "stp" => "U21", |
| 409 | + "mnx" => "U22", |
| 410 | + "Ab" => "U23", |
| 411 | + "Hmt" => "U24", |
| 412 | + "wbA" => "U26", |
| 413 | + "DA" => "U28", |
| 414 | + "rtH" => "U31", |
| 415 | + "zmn" => "U32", |
| 416 | + "ti" => "U33", |
| 417 | + "xsf" => "U34", |
| 418 | + "Hm" => "U36", |
| 419 | + "mxAt" => "U38", |
| 420 | + "mr" => "U6", |
| 421 | + "100" => "V1", |
| 422 | + "arq" => "V12", |
| 423 | + "T" => "V13", |
| 424 | + "iTi" => "V15", |
| 425 | + "TmA" => "V19", |
| 426 | + "XAr" => "V19", |
| 427 | + "mDt" => "V19", |
| 428 | + "sTA" => "V2", |
| 429 | + "10" => "V20", |
| 430 | + "mD" => "V20", |
| 431 | + "mH" => "V22", |
| 432 | + "wD" => "V24", |
| 433 | + "aD" => "V26", |
| 434 | + "H" => "V28", |
| 435 | + "sk" => "V29", |
| 436 | + "wAH" => "V29", |
| 437 | + "sTAw" => "V3", |
| 438 | + "nb" => "V30", |
| 439 | + "k" => "V31", |
| 440 | + "msn" => "V32", |
| 441 | + "sSr" => "V33", |
| 442 | + "idr" => "V37", |
| 443 | + "wA" => "V4", |
| 444 | + "snT" => "V5", |
| 445 | + "sS" => "V6", |
| 446 | + "Sn" => "V7", |
| 447 | + "iab" => "W10", |
| 448 | + "g" => "W11", |
| 449 | + "nzt" => "W11", |
| 450 | + "Hz" => "W14", |
| 451 | + "xnt" => "W17", |
| 452 | + "mi" => "W19", |
| 453 | + "bAs" => "W2", |
| 454 | + "Hnqt" => "W22", |
| 455 | + "nw" => "W24", |
| 456 | + "ini" => "W25", |
| 457 | + "Hb" => "W3", |
| 458 | + "Xnm" => "W9", |
| 459 | + "t" => "X1", |
| 460 | + "di" => "X8", |
| 461 | + "rdi" => "X8", |
| 462 | + "mDAt" => "Y1", |
| 463 | + "mnhd" => "Y3", |
| 464 | + "zS" => "Y3", |
| 465 | + "mn" => "Y5", |
| 466 | + "ibA" => "Y6", |
| 467 | + "zSSt" => "Y8", |
| 468 | + "imi" => "Z11", |
| 469 | + "y" => "Z4", |
| 470 | + "W" => "Z7", |
| 471 | + |
| 472 | + "<1" => "Ca1", //cartouche |
| 473 | + "2>" => "Ca2", |
| 474 | + "<2" => "Ca2a", |
| 475 | + "1>" => "Ca1a", |
| 476 | + "<0" => "Ca1", |
| 477 | + "0>" => "Ca2", |
| 478 | + "<h1" => "Cah1", //horus |
| 479 | + "h1>" => "Cah1a", |
| 480 | + "<h2" => "Cah2", |
| 481 | + "h2>" => "Cah2a", |
| 482 | + "<h3" => "Cah3", |
| 483 | + "h3>" => "Cah3a", |
| 484 | + "<h0" => "Cah1", |
| 485 | + "h0>" => "Cah1a", |
| 486 | + "<" => "Ca1", //cartouche |
| 487 | + ">" => "Ca2", |
| 488 | + "[&" => "Ba16", |
| 489 | + "&]" => "Ba16", |
| 490 | + "[{" => "Ba17", |
| 491 | + "}]" => "Ba17a", |
| 492 | + "[[" => "Ba15", |
| 493 | + "]]" => "Ba15a", |
| 494 | + "[\"" => "", |
| 495 | + "\"]" => "", |
| 496 | + "['" => "", |
| 497 | + "']" => "", |
| 498 | + ); |
| 499 | + |
| 500 | +/* not used yet |
| 501 | + $wh_syntax = array( |
| 502 | + "-", //block sepatator |
| 503 | + ":", //supperposition |
| 504 | + "*", //juxtaposition |
| 505 | + "(", //open bracket |
| 506 | + ")", //close bracket |
| 507 | + "!!", //end of text |
| 508 | + "!", //end of line |
| 509 | + "..", //blank caracter |
| 510 | + ".", //half-size blank caracter |
| 511 | + "$", //color |
| 512 | + "#", //shade |
| 513 | + "[&", //select |
| 514 | + "&]", |
| 515 | + "[{", |
| 516 | + "}]", |
| 517 | + "[[", |
| 518 | + "]]", |
| 519 | + "[\"", |
| 520 | + "\"]", |
| 521 | + "['", |
| 522 | + "']", |
| 523 | + "<", //cartouche |
| 524 | + ">", |
| 525 | + "<1", |
| 526 | + "2>", |
| 527 | + "<2", |
| 528 | + "1>", |
| 529 | + "<0", |
| 530 | + "0>", |
| 531 | + "<h1", //horus |
| 532 | + "h1>", |
| 533 | + "<h2", |
| 534 | + "h2>", |
| 535 | + "<h3", |
| 536 | + "h3>", |
| 537 | + "<h0", |
| 538 | + "h0>", |
| 539 | + "++", //comment |
| 540 | + "+s", //hieroglyph |
| 541 | + "+t", //transcription |
| 542 | + "+l", //latin-normal |
| 543 | + "+i", //latin-italic |
| 544 | + "+g", //latin-bold (gras) |
| 545 | + "+b", //latin-bold |
| 546 | + "+c", |
| 547 | + ); |
| 548 | +*/ |
| 549 | + |
| 550 | + // convertion table for text mode |
| 551 | + $wh_text_conv = array( |
| 552 | + "-" => " ", |
| 553 | + ":" => "-", |
| 554 | + "*" => "-", |
| 555 | + "!" => "<br/>", |
| 556 | + "." => "", |
| 557 | + "=" => "", |
| 558 | + "(" => "", |
| 559 | + ")" => "", |
| 560 | + "<1" => "(", |
| 561 | + "2>" => ")|", |
| 562 | + "<2" => "|(", |
| 563 | + "1>" => ")", |
| 564 | + "<0" => "(", |
| 565 | + "0>" => ")|", |
| 566 | + "<h1" => "[", //horus |
| 567 | + "h1>" => "]", |
| 568 | + "<h2" => "[", |
| 569 | + "h2>" => "]", |
| 570 | + "<h3" => "[", |
| 571 | + "h3>" => "]", |
| 572 | + "<h0" => "[", |
| 573 | + "h0>" => "]", |
| 574 | + "<" => "(", //cartouche |
| 575 | + ">" => ")|", |
| 576 | + ); |
| 577 | + |
| 578 | + //------------------------------------------------------------------------ |
| 579 | + // WikiHieroHook - Parser callback |
| 580 | + //------------------------------------------------------------------------ |
| 581 | + // hiero << text to convert |
| 582 | + // return >> string with converted code |
| 583 | + //------------------------------------------------------------------------ |
| 584 | + function WikiHieroHook($hiero) |
| 585 | + { |
| 586 | + return _WikiHiero($hiero, WH_MODE_HTML); |
| 587 | + } |
| 588 | + |
| 589 | + //======================================================================== |
| 590 | + // F U N C T I O N S |
| 591 | + |
| 592 | + //------------------------------------------------------------------------ |
| 593 | + // WH_RenderGlyph - Render a glyph |
| 594 | + //------------------------------------------------------------------------ |
| 595 | + // glyph << glyph's code to render |
| 596 | + // option << option to add into <img> tag (use for height) |
| 597 | + // return >> a string to add to the stream |
| 598 | + //------------------------------------------------------------------------ |
| 599 | + function WH_RenderGlyph($glyph, $option="") |
| 600 | + { |
| 601 | + global $wh_mode; |
| 602 | + global $wh_phonemes; |
| 603 | + global $wh_files; |
| 604 | + global $wh_scale; |
| 605 | + |
| 606 | + if($glyph == "..") // Render void block |
| 607 | + { |
| 608 | + $width = WH_HEIGHT; |
| 609 | + return "<table width='{$width}px' border='0' cellspacing='0' cellpadding='0'><tr><td> </td></tr></table>"; |
| 610 | + } |
| 611 | + else if($glyph == ".") // Render half-width void block |
| 612 | + { |
| 613 | + $width = WH_HEIGHT/2; |
| 614 | + return "<table width='{$width}px' border='0' cellspacing='0' cellpadding='0'><tr><td> </td></tr></table>"; |
| 615 | + } |
| 616 | + else if($glyph == '<') // Render open cartouche |
| 617 | + { |
| 618 | + $height = intval(WH_HEIGHT * $wh_scale / 100); |
| 619 | + $code = $wh_phonemes[$glyph]; |
| 620 | + return "<img src='".htmlspecialchars(WH_IMG_DIR.WH_IMG_PRE."{$code}.".WH_IMG_EXT)."' height='{$height}px' title='".htmlspecialchars($glyph)."' alt='".htmlspecialchars($glyph)."' />"; |
| 621 | + } |
| 622 | + else if($glyph == '>') // Render close cartouche |
| 623 | + { |
| 624 | + $height = intval(WH_HEIGHT * $wh_scale / 100); |
| 625 | + $code = $wh_phonemes[$glyph]; |
| 626 | + return "<img src='".htmlspecialchars(WH_IMG_DIR.WH_IMG_PRE."{$code}.".WH_IMG_EXT)."' height='{$height}px' title='".htmlspecialchars($glyph)."' alt='".htmlspecialchars($glyph)."' />"; |
| 627 | + } |
| 628 | + |
| 629 | + if(array_key_exists($glyph, $wh_phonemes)) |
| 630 | + { |
| 631 | + $code = $wh_phonemes[$glyph]; |
| 632 | + if(array_key_exists($code, $wh_files)) |
| 633 | + return "<img style='margin:".WH_IMG_MARGIN."px;' $option src='".htmlspecialchars(WH_IMG_DIR.WH_IMG_PRE."{$code}.".WH_IMG_EXT)."' title='".htmlspecialchars("{$code} [{$glyph}]")."' alt='".htmlspecialchars($glyph)."' />"; |
| 634 | + else |
| 635 | + return "<font title='".htmlspecialchars($code)."'>".htmlspecialchars($glyph)."</font>"; |
| 636 | + } |
| 637 | + else if(array_key_exists($glyph, $wh_files)) |
| 638 | + return "<img style='margin:".WH_IMG_MARGIN."px;' $option src='".htmlspecialchars(WH_IMG_DIR.WH_IMG_PRE."{$glyph}.".WH_IMG_EXT)."' title='".htmlspecialchars($glyph)."' alt='".htmlspecialchars($glyph)."' />"; |
| 639 | + else |
| 640 | + return htmlspecialchars($glyph); |
| 641 | + } |
| 642 | + |
| 643 | + //------------------------------------------------------------------------ |
| 644 | + // WH_Resize - Resize a glyph |
| 645 | + //------------------------------------------------------------------------ |
| 646 | + // item << glyph's code |
| 647 | + // is_cartouche << true if glyph inside a cartouche |
| 648 | + // total << total size of a group for multi-glyph block |
| 649 | + // return >> size |
| 650 | + //------------------------------------------------------------------------ |
| 651 | + function WH_Resize($item, $is_cartouche=false, $total=0) |
| 652 | + { |
| 653 | + global $wh_phonemes; |
| 654 | + global $wh_files; |
| 655 | + global $wh_scale; |
| 656 | + |
| 657 | + if(array_key_exists($item, $wh_phonemes)) |
| 658 | + $glyph = $wh_phonemes[$item]; |
| 659 | + else |
| 660 | + $glyph = $item; |
| 661 | + |
| 662 | + $margin = 2 * WH_IMG_MARGIN; |
| 663 | + if($is_cartouche) |
| 664 | + $margin += 2 * intval(WH_CARTOUCHE_WIDTH * $wh_scale / 100); |
| 665 | + |
| 666 | + if(array_key_exists($glyph, $wh_files)) |
| 667 | + { |
| 668 | + $height = $margin + $wh_files[$glyph][1]; |
| 669 | + if($total) |
| 670 | + { |
| 671 | + if($total > WH_HEIGHT) |
| 672 | + return (intval( $height * WH_HEIGHT / $total ) - $margin) * $wh_scale / 100; |
| 673 | + else |
| 674 | + return ($height - $margin) * $wh_scale / 100; |
| 675 | + } |
| 676 | + else |
| 677 | + { |
| 678 | + if($height > WH_HEIGHT) |
| 679 | + return (intval( WH_HEIGHT * WH_HEIGHT / $height ) - $margin) * $wh_scale / 100; |
| 680 | + else |
| 681 | + return ($height - $margin) * $wh_scale / 100; |
| 682 | + } |
| 683 | + } |
| 684 | + |
| 685 | + return (WH_HEIGHT - $margin) * $wh_scale / 100; |
| 686 | + } |
| 687 | + |
| 688 | + //======================================================================== |
| 689 | + // |
| 690 | + // W i k i H i e r o |
| 691 | + // |
| 692 | + |
| 693 | + //------------------------------------------------------------------------ |
| 694 | + // WikiHiero - Render hieroglyph text |
| 695 | + //------------------------------------------------------------------------ |
| 696 | + // hiero << text to convert |
| 697 | + // mode << convertion mode [DEFAULT|TEXT|HTML|STYLE|IMAGE] (def=HTML) |
| 698 | + // scale << global scale in percentage (def=100%) |
| 699 | + // line << use line [true|false] (def=false) |
| 700 | + // return >> string with converted code |
| 701 | + //------------------------------------------------------------------------ |
| 702 | + function _WikiHiero($hiero, $mode=WH_MODE_DEFAULT, $scale=WH_SCALE_DEFAULT, $line=false) |
| 703 | + { |
| 704 | + if($mode != WH_MODE_DEFAULT) |
| 705 | + $wh_mode = $mode; |
| 706 | + |
| 707 | + switch($wh_mode) |
| 708 | + { |
| 709 | + case WH_MODE_TEXT: return WikiHieroText($hiero, $line); |
| 710 | + case WH_MODE_HTML: return WikiHieroHTML($hiero, $scale, $line); |
| 711 | + case WH_MODE_STYLE: die("ERROR: CSS version not yet implemented"); |
| 712 | + case WH_MODE_IMAGE: die("ERROR: Image version not yet implemented"); |
| 713 | + } |
| 714 | + die("ERROR: Unknown mode!"); |
| 715 | + } |
| 716 | + |
| 717 | + //------------------------------------------------------------------------ |
| 718 | + // WikiHieroText - Render hieroglyph text in text mode |
| 719 | + //------------------------------------------------------------------------ |
| 720 | + // hiero << text to convert |
| 721 | + // line << use line [true|false] (def=false) |
| 722 | + // return >> string with converted code |
| 723 | + //------------------------------------------------------------------------ |
| 724 | + function WikiHieroText($hiero, $line=false) |
| 725 | + { |
| 726 | + global $wh_text_conv; |
| 727 | + |
| 728 | + $html = ""; |
| 729 | + |
| 730 | + if($line) |
| 731 | + $html .= "<hr />\n"; |
| 732 | + |
| 733 | + for($char=0; $char<strlen($hiero); $char++) |
| 734 | + { |
| 735 | + if(array_key_exists($hiero[$char], $wh_text_conv)) |
| 736 | + { |
| 737 | + $html .= $wh_text_conv[$hiero[$char]]; |
| 738 | + if($hiero[$char] == '!') |
| 739 | + if($line) |
| 740 | + $html .= "<hr />\n"; |
| 741 | + } |
| 742 | + else |
| 743 | + $html .= $hiero[$char]; |
| 744 | + } |
| 745 | + |
| 746 | + return $html; |
| 747 | + } |
| 748 | + |
| 749 | + //------------------------------------------------------------------------ |
| 750 | + // WikiHiero - Render hieroglyph text |
| 751 | + //------------------------------------------------------------------------ |
| 752 | + // hiero << text to convert |
| 753 | + // scale << global scale in percentage (def=100%) |
| 754 | + // line << use line [true|false] (def=false) |
| 755 | + // return >> string with converted code |
| 756 | + //------------------------------------------------------------------------ |
| 757 | + function WikiHieroHTML($hiero, $scale=WH_SCALE_DEFAULT, $line=false) |
| 758 | + { |
| 759 | + global $wh_prefabs; |
| 760 | + global $wh_files; |
| 761 | + global $wh_phonemes; |
| 762 | + global $wh_scale; |
| 763 | + |
| 764 | + if($scale != WH_SCALE_DEFAULT) |
| 765 | + $wh_scale = $scale; |
| 766 | + |
| 767 | + $html = ""; |
| 768 | + |
| 769 | + if($line) |
| 770 | + $html .= "<hr />\n"; |
| 771 | + |
| 772 | + //------------------------------------------------------------------------ |
| 773 | + // Split text into block, then split block into item |
| 774 | + $block = array(); |
| 775 | + $block[0] = array(); |
| 776 | + $block[0][0] = ""; |
| 777 | + $block_id = 0; |
| 778 | + $item_id = 0; |
| 779 | + $parenthesis = 0; |
| 780 | + $type = WH_TYPE_NONE; |
| 781 | + $is_cartouche = false; |
| 782 | + $is_striped = false; |
| 783 | + |
| 784 | + for($char=0; $char<strlen($hiero); $char++) |
| 785 | + { |
| 786 | + if($hiero[$char] == '(') |
| 787 | + { |
| 788 | + $parenthesis++; |
| 789 | + } |
| 790 | + else if($hiero[$char] == ')') |
| 791 | + { |
| 792 | + $parenthesis--; |
| 793 | + } |
| 794 | + if($parenthesis == 0) |
| 795 | + { |
| 796 | + if($hiero[$char] == '-' || $hiero[$char] == ' ') |
| 797 | + { |
| 798 | + if($type != WH_TYPE_NONE) |
| 799 | + { |
| 800 | + $block_id++; |
| 801 | + $block[$block_id] = array(); |
| 802 | + $item_id = 0; |
| 803 | + $block[$block_id][$item_id] = ""; |
| 804 | + $type = WH_TYPE_NONE; |
| 805 | + } |
| 806 | + } |
| 807 | + } |
| 808 | + else // don't slit block if inside parenthesis |
| 809 | + { |
| 810 | + if($hiero[$char] == '-') |
| 811 | + { |
| 812 | + $item_id++; |
| 813 | + $block[$block_id][$item_id] = '-'; |
| 814 | + $type = WH_TYPE_CODE; |
| 815 | + } |
| 816 | + } |
| 817 | + if($hiero[$char] == '!' ) |
| 818 | + { |
| 819 | + if($item_id > 0) |
| 820 | + { |
| 821 | + $block_id++; |
| 822 | + $block[$block_id] = array(); |
| 823 | + $item_id = 0; |
| 824 | + } |
| 825 | + $block[$block_id][$item_id] = $hiero[$char]; |
| 826 | + $type = WH_TYPE_END; |
| 827 | + } |
| 828 | + else if(ereg("[*:()]", $hiero[$char])) |
| 829 | + { |
| 830 | + if($type == WH_TYPE_GLYPH || $type == WH_TYPE_CODE) |
| 831 | + { |
| 832 | + $item_id++; |
| 833 | + $block[$block_id][$item_id] = ""; |
| 834 | + } |
| 835 | + $block[$block_id][$item_id] = $hiero[$char]; |
| 836 | + $type = WH_TYPE_CODE; |
| 837 | + } |
| 838 | + else if(ctype_alnum($hiero[$char]) || $hiero[$char] == '.' || $hiero[$char] == '<' || $hiero[$char] == '>') |
| 839 | + { |
| 840 | + if($type == WH_TYPE_END) |
| 841 | + { |
| 842 | + $block_id++; |
| 843 | + $block[$block_id] = array(); |
| 844 | + $item_id = 0; |
| 845 | + $block[$block_id][$item_id] = ""; |
| 846 | + } |
| 847 | + else if($type == WH_TYPE_CODE) |
| 848 | + { |
| 849 | + $item_id++; |
| 850 | + $block[$block_id][$item_id] = ""; |
| 851 | + } |
| 852 | + $block[$block_id][$item_id] .= $hiero[$char]; |
| 853 | + $type = WH_TYPE_GLYPH; |
| 854 | + } |
| 855 | + } |
| 856 | + |
| 857 | + // DEBUG: See the block split table |
| 858 | + if(WH_DEBUG_MODE) |
| 859 | + { |
| 860 | + foreach($block as $code) |
| 861 | + { |
| 862 | + echo "| "; |
| 863 | + foreach($code as $item) |
| 864 | + { |
| 865 | + echo "$item | "; |
| 866 | + } |
| 867 | + echo "<br />\n"; |
| 868 | + } |
| 869 | + } |
| 870 | + |
| 871 | + $contentHtml = $tableHtml = $tableContentHtml = ""; |
| 872 | + //$html .= WH_TABLE_S."<tr>\n"; |
| 873 | + |
| 874 | + //------------------------------------------------------------------------ |
| 875 | + // Loop into all blocks |
| 876 | + foreach($block as $code) |
| 877 | + { |
| 878 | + // simplest case, the block contain only 1 code -> render |
| 879 | + if(count($code) == 1) |
| 880 | + { |
| 881 | + if($code[0] == "!") // end of line |
| 882 | + { |
| 883 | + $tableHtml = "</tr>".WH_TABLE_E.WH_TABLE_S."<tr>\n"; |
| 884 | + if($line) |
| 885 | + $contentHtml .= "<hr />\n"; |
| 886 | + } |
| 887 | + |
| 888 | + else if(strchr($code[0], '<')) // start cartouche |
| 889 | + { |
| 890 | + $contentHtml .= WH_TD_S.WH_RenderGlyph($code[0]).WH_TD_E; |
| 891 | + $is_cartouche = true; |
| 892 | + $contentHtml .= "<td>".WH_TABLE_S."<tr><td height='".intval(WH_CARTOUCHE_WIDTH * $wh_scale / 100)."px' bgcolor='black'></td></tr><tr><td>".WH_TABLE_S."<tr>"; |
| 893 | + } |
| 894 | + |
| 895 | + else if(strchr($code[0], '>')) // end cartouche |
| 896 | + { |
| 897 | + $contentHtml .= "</tr>".WH_TABLE_E."</td></tr><tr><td height='".intval(WH_CARTOUCHE_WIDTH * $wh_scale / 100)."px' bgcolor='black'></td></tr>".WH_TABLE_E."</td>"; |
| 898 | + $is_cartouche = false; |
| 899 | + $contentHtml .= WH_TD_S.WH_RenderGlyph($code[0]).WH_TD_E; |
| 900 | + } |
| 901 | + |
| 902 | + else if($code[0] != "") // assum is glyph or '..' or '.' |
| 903 | + { |
| 904 | + $option = "height='".WH_Resize($code[0], $is_cartouche)."px'"; |
| 905 | + |
| 906 | + $contentHtml .= WH_TD_S.WH_RenderGlyph($code[0], $option).WH_TD_E; |
| 907 | + } |
| 908 | + } |
| 909 | + // block contain more than 1 glyph |
| 910 | + else |
| 911 | + { |
| 912 | + // convert all code into '&' to test prefabs glyph |
| 913 | + $temp = ""; |
| 914 | + foreach($code as $t) |
| 915 | + { |
| 916 | + if(ereg("[*:!()]", $t[0])) |
| 917 | + $temp .= "&"; |
| 918 | + else |
| 919 | + $temp .= $t; |
| 920 | + } |
| 921 | + // test is block is into tje prefabs list |
| 922 | + if(in_array($temp, $wh_prefabs)) |
| 923 | + { |
| 924 | + $option = "height='".WH_Resize($temp, $is_cartouche)."px'"; |
| 925 | + |
| 926 | + $contentHtml .= WH_TD_S.WH_RenderGlyph($temp, $option).WH_TD_E; |
| 927 | + } |
| 928 | + // block must be manualy compute |
| 929 | + else |
| 930 | + { |
| 931 | + // get block total height |
| 932 | + $line_max = 0; |
| 933 | + $total = 0; |
| 934 | + $height = 0; |
| 935 | + foreach($code as $t) |
| 936 | + { |
| 937 | + if($t == ":") |
| 938 | + { |
| 939 | + if($height > $line_max) |
| 940 | + $line_max = $height; |
| 941 | + $total += $line_max; |
| 942 | + $line_max = 0; |
| 943 | + } |
| 944 | + else if($t == "*") |
| 945 | + { |
| 946 | + if($height > $line_max) |
| 947 | + $line_max = $height; |
| 948 | + } |
| 949 | + else |
| 950 | + { |
| 951 | + if(array_key_exists($t, $wh_phonemes)) |
| 952 | + $glyph = $wh_phonemes[$t]; |
| 953 | + else |
| 954 | + $glyph = $t; |
| 955 | + |
| 956 | + if(array_key_exists($glyph, $wh_files)) |
| 957 | + $height = 2 + $wh_files[$glyph][1]; |
| 958 | + } |
| 959 | + } |
| 960 | + if($height > $line_max) |
| 961 | + $line_max = $height; |
| 962 | + $total += $line_max; |
| 963 | + |
| 964 | + // render all glyph into the block |
| 965 | + $temp = ""; |
| 966 | + foreach($code as $t) |
| 967 | + { |
| 968 | + if($t == ":") |
| 969 | + $temp .= "<br />"; |
| 970 | + else if($t == "*") |
| 971 | + $temp .= " "; |
| 972 | + else |
| 973 | + { |
| 974 | + // resize the glyph according to the block total height |
| 975 | + $option = "height='".WH_Resize($t, $is_cartouche, $total)."px'"; |
| 976 | + $temp .= WH_RenderGlyph($t, $option); |
| 977 | + } |
| 978 | + } |
| 979 | + $contentHtml .= WH_TD_S.$temp.WH_TD_E; |
| 980 | + } |
| 981 | + $contentHtml .= "\n"; |
| 982 | + } |
| 983 | + if(strlen($contentHtml) > 0) |
| 984 | + { |
| 985 | + $tableContentHtml .= $tableHtml.$contentHtml; |
| 986 | + $contentHtml = $tableHtml = ""; |
| 987 | + } |
| 988 | + } |
| 989 | + if(strlen($tableContentHtml) > 0) |
| 990 | + { |
| 991 | + $html .= WH_TABLE_S."<tr>\n".$tableContentHtml."</tr>".WH_TABLE_E; |
| 992 | + } |
| 993 | + |
| 994 | + return "<table border='0' cellspacing='0' cellpadding='0' style='display:inline;' ><tr><td>\n$html\n</td></tr></table>"; |
| 995 | + } |
| 996 | + |
| 997 | + //------------------------------------------------------------------------ |
| 998 | + // WH_GetCode - Get glyph code from file name |
| 999 | + //------------------------------------------------------------------------ |
| 1000 | + // file << file name |
| 1001 | + // return >> string with converted code |
| 1002 | + //------------------------------------------------------------------------ |
| 1003 | + function WH_GetCode($file) |
| 1004 | + { |
| 1005 | + return substr($file, strlen(WH_IMG_PRE), -(1+strlen(WH_IMG_EXT))); |
| 1006 | + } |
| 1007 | + |
| 1008 | + //------------------------------------------------------------------------ |
| 1009 | + // WH_GetCode - Get glyph code from file name |
| 1010 | + //------------------------------------------------------------------------ |
| 1011 | + // return >> credit string |
| 1012 | + //------------------------------------------------------------------------ |
| 1013 | + function WH_Credit() |
| 1014 | + { |
| 1015 | + $html = ""; |
| 1016 | + $html .= "<b>WikiHiero v".WH_VER_MAJ.".".WH_VER_MED.".".WH_VER_MIN."</b>\n"; |
| 1017 | + $html .= "by Guillaume Blanchard (Aoineko) under GPL (2004).<br />\n"; |
| 1018 | + $html .= "Hieroglyph credit: S. Rosmorduc, G. Watson, J. Hirst (under GFDL).\n"; |
| 1019 | + return $html; |
| 1020 | + } |
| 1021 | + |
| 1022 | + # vim: set sts=2 sw=2 ts=2 et : |
| 1023 | +?> |
Property changes on: trunk/extensions/wikihiero/wh_main.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 1024 | + native |
Name: svn:keywords |
2 | 1025 | + Author Date Id Revision |
Index: trunk/extensions/wikihiero/wh_generate.php |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | // |
26 | 26 | ////////////////////////////////////////////////////////////////////////// |
27 | 27 | |
28 | | - include "wikihiero.php"; |
| 28 | + include "wh_main.php"; |
29 | 29 | |
30 | 30 | if(array_key_exists("lang", $_GET)) |
31 | 31 | $lang = $_GET["lang"]; |
— | — | @@ -50,15 +50,17 @@ |
51 | 51 | $wh_prefabs = "\$wh_prefabs = array(\n"; |
52 | 52 | $wh_files = "\$wh_files = array(\n"; |
53 | 53 | |
54 | | - if(is_dir(WH_IMG_DIR)) |
| 54 | + $img_dir = dirname(__FILE__) . '/img/'; |
| 55 | + |
| 56 | + if(is_dir($img_dir)) |
55 | 57 | { |
56 | | - if ($dh = opendir(WH_IMG_DIR)) |
| 58 | + if ($dh = opendir($img_dir)) |
57 | 59 | { |
58 | 60 | while (($file = readdir($dh)) !== false) |
59 | 61 | { |
60 | 62 | if(stristr($file, WH_IMG_EXT)) |
61 | 63 | { |
62 | | - list($width, $height, $type, $attr) = getimagesize(WH_IMG_DIR.$file); |
| 64 | + list($width, $height, $type, $attr) = getimagesize($img_dir.$file); |
63 | 65 | $wh_files .= " \"".WH_GetCode($file)."\" => array( $width, $height ),\n"; |
64 | 66 | if(strchr($file,'&')) |
65 | 67 | $wh_prefabs .= " \"".WH_GetCode($file)."\",\n"; |
— | — | @@ -78,6 +80,7 @@ |
79 | 81 | fwrite($file, "<?php\n\n"); |
80 | 82 | fwrite($file, "// File created by wh_generate.php version ".WH_VER_MAJ.".".WH_VER_MED.".".WH_VER_MIN."\n"); |
81 | 83 | fwrite($file, "// ".date("Y/m/d at H:i")."\n\n"); |
| 84 | + fwrite($file, "global \$wh_prefabs, \$wh_files;\n\n"); |
82 | 85 | fwrite($file, "$wh_prefabs\n\n"); |
83 | 86 | fwrite($file, "$wh_files\n\n"); |
84 | 87 | fwrite($file, "?>"); |
— | — | @@ -90,4 +93,4 @@ |
91 | 94 | <small><?php echo WH_Credit(); ?></small> |
92 | 95 | |
93 | 96 | </body> |
94 | | -</html> |
\ No newline at end of file |
| 97 | +</html> |