wh_main.php 24 KB

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