PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/protected/extensions/HanZi/HanZiTools.php

https://bitbucket.org/hiscaler/firefly-ultimate
PHP | 2248 lines | 1270 code | 748 blank | 230 comment | 187 complexity | dafd0de477cfe1f0550486d31a57de79 MD5 | raw file
Possible License(s): LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. error_reporting(0);
  3. define('DS', DIRECTORY_SEPARATOR);
  4. define('HANZILIB', dirname(__FILE__) . DS . 'data' . DS);
  5. class HanZiTools {
  6. /**
  7. * this extention base pzpinyin
  8. * @link http://code.google.com/p/pzphp/wiki/PrimezeroTools
  9. */
  10. ## ______________________________________________________________________________________________
  11. ## HanziTools - __construct .. constructor may act as pre-flight checklist?
  12. function __construct() {
  13. if (!file_exists(HANZILIB . "idx33.txt")) {
  14. exit("idx33.txt - pinyin-hanzi index not found");
  15. } elseif (!file_exists(HANZILIB . "idx55.txt")) {
  16. exit("idx55.txt - pinyintype index not found");
  17. } elseif (!file_exists(HANZILIB . "idx88.txt")) {
  18. exit("idx88.txt - traditional index not found");
  19. } elseif (!file_exists(HANZILIB . "idx99.txt")) {
  20. exit("idx99.txt - simplified index not found");
  21. }
  22. }
  23. ## ______________________________________________________________________________________________
  24. ## HanziTools - Mega Methods ... the methods that take all the glory
  25. ## usually with one parameter tied behind their back ...
  26. ## Modifying code below this line may help, but may also harm.
  27. function pzkelvin_go($n, $display = FALSE) {
  28. $n = $this->pzkelvin_temperature_convert($n, $display);
  29. return $n;
  30. }
  31. function pznumbers_go($n) {
  32. $n = $this->pznumbers_convert($n);
  33. return $n;
  34. }
  35. function pzpinyin_tonedisplay_convert_to_number($n) {
  36. $n = $this->pzpinyin_tonedisplay_change($n, 'tone_number');
  37. return $n;
  38. }
  39. function pzpinyin_tonedisplay_convert_to_mark($n) {
  40. $n = $this->pzpinyin_tonedisplay_change($n, 'tone_mark');
  41. return $n;
  42. }
  43. function pzpinyin_pinyintype_hanyu_pinyin_to_zhuyin($n) {
  44. $n = $this->pzpinyin_pinyintype_change($n, 'zhuyin', 'zhuyin');
  45. return $n;
  46. }
  47. function pzpinyin_pinyintype_zhuyin_to_hanyu_pinyin($n) {
  48. $n = $this->pzpinyin_pinyintype_change($n, 'hanyu_pinyin', 'zhuyin');
  49. return $n;
  50. }
  51. function pzpinyin_pinyintype_hanyu_pinyin_to_yale($n) {
  52. $n = $this->pzpinyin_pinyintype_change($n, 'yale', 'yale');
  53. return $n;
  54. }
  55. function pzpinyin_pinyintype_yale_to_hanyu_pinyin($n) {
  56. $n = $this->pzpinyin_pinyintype_change($n, 'hanyu_pinyin', 'yale');
  57. return $n;
  58. }
  59. function pzpinyin_pinyintype_hanyu_pinyin_to_tongyong_pinyin($n) {
  60. $n = $this->pzpinyin_pinyintype_change($n, 'tongyong_pinyin', 'tongyong_pinyin');
  61. return $n;
  62. }
  63. function pzpinyin_pinyintype_tongyong_pinyin_to_hanyu_pinyin($n) {
  64. $n = $this->pzpinyin_pinyintype_change($n, 'hanyu_pinyin', 'tongyong_pinyin');
  65. return $n;
  66. }
  67. ## ______________________________________________________________________________________________
  68. ## HanziTools - Puny (Helper) Methods ... the methods that make the Mega Methods look good.
  69. ## Modifying code below this line may not yield added nutritional value.
  70. // zzzzz....
  71. function pzpinyin_cmp($a, $b) {
  72. // nothing in here //
  73. return strlen($a) < strlen($b); // returns TRUE OR FALSE (1 | 0)
  74. }
  75. // zzzzzzzz.......
  76. function pzpinyin_pinyintable_trimwalk(&$pinyinItem) {
  77. $pinyinItem = trim($pinyinItem);
  78. }
  79. // zzzzzzzzz....
  80. function pzpinyin_pinyin_cleanup($query) {
  81. $query = str_replace("u:", "uu", $query);
  82. $query = str_replace("v", "uu", $query);
  83. $query = stripslashes($query);
  84. return $query;
  85. }
  86. function pzpinyin_tonedisplay_stripnumbers($n) {
  87. $n = str_replace("0", "", $n);
  88. $n = str_replace("9", "", $n);
  89. $n = str_replace("8", "", $n);
  90. $n = str_replace("7", "", $n);
  91. $n = str_replace("6", "", $n);
  92. $n = str_replace("5", "", $n);
  93. $n = str_replace("4", "", $n);
  94. $n = str_replace("3", "", $n);
  95. $n = str_replace("2", "", $n);
  96. $n = str_replace("1", "", $n);
  97. return $n;
  98. }
  99. function pzpinyin_pinyintype_listall() {
  100. $romans = array(// perhaps this should be placed in an external file for re-deployment
  101. 0 => "zhuyin",
  102. 1 => "wade_giles",
  103. 2 => "mps2",
  104. 3 => "yale",
  105. 4 => "tongyong_pinyin",
  106. 5 => "hanyu_pinyin",
  107. 6 => "gyr1",
  108. 7 => "gyr2",
  109. 8 => "gyr3",
  110. 9 => "gyr4"
  111. );
  112. return $romans;
  113. }
  114. // transcribes Chinese into pinyin character-by-character
  115. function pzpinyin_hanyu_pinyin_transcribe_to_hanzi($inputString) {
  116. // takes string and breaks into array
  117. $arrayFromString = str_split($inputString);
  118. // tablet is where the characters are transcribed
  119. $tablet = "";
  120. // let us look at each character
  121. foreach ($arrayFromString as $eachCharacter) {
  122. // keep knitting with this new string
  123. $tablet = $tablet . $this->pzpinyin_gethanzi_by_pinyin($eachCharacter);
  124. }
  125. return $tablet;
  126. }
  127. // end FCN pzpinyin_transcribe_to_hanzi
  128. function pzpinyin_tonemarks_loadindex() {
  129. $tone_marks_array = array(
  130. "u:1e" => "üe", "u:2e" => "ǘe", "u:3e" => "ǚe", "u:4e" => "ǜe",
  131. "uu1an" => "üan", "uu2an" => "ǘan", "uu3an" => "ǚan", "uu4an" => "ǜan",
  132. "u:1an" => "üan", "u:2an" => "ǘan", "u:3an" => "ǚan", "u:4an" => "ǜan",
  133. "un1" => "ūn", "un2" => "ún", "un3" => "ŭn", "un4" => "ùn",
  134. "uang1" => "uāng", "uang2" => "uáng", "uang3" => "uăng", "uang4" => "uàng",
  135. "uan1" => "uān", "uan2" => "uán", "uan3" => "uăn", "uan4" => "uàn",
  136. "un1" => "ūn", "un2" => "ún", "un3" => "ŭn", "un4" => "ùn",
  137. "ui1" => "uī", "ui2" => "uí", "ui3" => "uĭ", "ui4" => "uì",
  138. "uai1" => "uāi", "uai2" => "uái", "uai3" => "uăi", "uai4" => "uài",
  139. "uo1" => "uō", "uo2" => "uó", "uo3" => "uŏ", "uo4" => "uò",
  140. "ua1" => "uā", "ua2" => "uá", "ua3" => "uă", "ua4" => "uà",
  141. "iong1" => "iōng", "iong2" => "ióng", "iong3" => "iŏng", "iong4" => "iòng",
  142. "ing1" => "īng", "ing2" => "íng", "ing3" => "ĭng", "ing4" => "ìng",
  143. "iang1" => "iāng", "iang2" => "iáng", "iang3" => "iăng", "iang4" => "iàng",
  144. "in1" => "īn", "in2" => "ín", "in3" => "ĭn", "in4" => "ìn",
  145. "ian1" => "iān", "ian2" => "ián", "ian3" => "iăn", "ian4" => "iàn",
  146. "iu1" => "iū", "iu2" => "iú", "iu3" => "iŭ", "iu4" => "iù",
  147. "ie1" => "iē", "ie2" => "ié", "ie3" => "iĕ", "ie4" => "iè",
  148. "iao1" => "iāo", "iao2" => "iáo", "iao3" => "iăo", "iao4" => "iào",
  149. "ia1" => "iā", "ia2" => "iá", "ia3" => "iă", "ia4" => "ià",
  150. "ong1" => "ōng", "ong2" => "óng", "ong3" => "ŏng", "ong4" => "òng",
  151. "eng1" => "ēng", "eng2" => "éng", "eng3" => "ĕng", "eng4" => "èng",
  152. "ang1" => "āng", "ang2" => "áng", "ang3" => "ăng", "ang4" => "àng",
  153. "en1" => "ēn", "en2" => "én", "en3" => "ĕn", "en4" => "èn",
  154. "an1" => "ān", "an2" => "án", "an3" => "ăn", "an4" => "àn",
  155. "ou1" => "ōu", "ou2" => "óu", "ou3" => "ŏu", "ou4" => "òu",
  156. "ao1" => "āo", "ao2" => "áo", "ao3" => "ăo", "ao4" => "ào",
  157. "ei1" => "ēi", "ei2" => "éi", "ei3" => "ĕi", "ei4" => "èi",
  158. "ai1" => "āi", "ai2" => "ái", "ai3" => "ăi", "ai4" => "ài",
  159. "er1" => "ēr", "er2" => "ér", "er3" => "ĕr", "er4" => "èr",
  160. "uue1" => "üe", "uue2" => "ǘe", "uue3" => "ǚe", "uue4" => "ǜe",
  161. "uu1" => "ü", "uu2" => "ǘ", "uu3" => "ǚ", "uu4" => "ǜ",
  162. "u:e1" => "üe", "u:e2" => "ǘe", "u:e3" => "ǚe", "u:e4" => "ǜe",
  163. "u:1" => "ü", "u:2" => "ǘ", "u:3" => "ǚ", "u:4" => "ǜ",
  164. "a1" => "ā", "a2" => "á", "a3" => "ă", "a4" => "à",
  165. "e1" => "ē", "e2" => "é", "e3" => "ĕ", "e4" => "è",
  166. "i1" => "ī", "i2" => "í", "i3" => "ĭ", "i4" => "ì",
  167. "o1" => "ō", "o2" => "ó", "o3" => "ŏ", "o4" => "ò",
  168. "u1" => "ū", "u2" => "ú", "u3" => "ŭ", "u4" => "ù" // no comma here
  169. // last one out closes the door
  170. );
  171. return $tone_marks_array; // array containing tonemarks - tonenumbers
  172. }
  173. // end FUNCTION pzpinyin_tonemarks_load
  174. function pzpinyin_tonedisplay_change($inputPhrase, $conversion_mode = 'tone_mark') {
  175. // conversion_mode = 'tone_number' - convert from tone mark to tone number
  176. // conversion_mode = 'tone_mark' - convert from tone number to tone mark
  177. $eachWord = explode(" ", $inputPhrase);
  178. $tone_marks_array = $this->pzpinyin_tonemarks_loadindex();
  179. foreach ($eachWord as $dummy_key => &$word) {
  180. foreach ($tone_marks_array as $tone_number => $tone_mark) {
  181. if ($conversion_mode == 'tone_mark') {
  182. $word = str_replace($tone_number, $tone_mark, $word);
  183. } elseif ($conversion_mode == 'tone_number') {
  184. $word = str_replace($tone_mark, $tone_number, $word);
  185. }
  186. } // end FOREACH tone_marks_array
  187. $converted_words[] = $word;
  188. } // end foreach WORD
  189. $converted_phrase = implode(" ", $converted_words);
  190. return $converted_phrase; // string of converted pinyin phrase
  191. }
  192. // end FUNCTION pzpinyin_tonedisplay_change
  193. function pzpinyin_pinyintype_loadindex() {
  194. $py_table = array();
  195. $str_from_file = file_get_contents(HANZILIB . 'idx55.txt');
  196. $lines_from_txt = explode("\n", $str_from_file);
  197. foreach ($lines_from_txt as $lines) {
  198. $py_table[] = explode("\t", trim($lines));
  199. }
  200. foreach ($py_table as &$t) {
  201. array_walk($t, array($this, 'pzpinyin_pinyintable_trimwalk'));
  202. }
  203. return $py_table; // array containing pinyin table
  204. }
  205. // end FUNCTION loadPinyinIndex
  206. function pzpinyin_pinyintype_array_load($inputpinyin = "yale") {
  207. $py_table = $this->pzpinyin_pinyintype_loadindex(HANZILIB . 'idx55.txt');
  208. $pinyintype_array = array();
  209. // IDX55.TXT - CHEATSHEET
  210. // 0 - zhuyin; 1 - wade_giles; 2 - mps2; 3 - yale; 4 - tongyong pinyin;
  211. // 5 - hanyu pinyin; 6 - gyr1; 7 - gyr2; 8 - gyr3; 9 - gyr4;
  212. switch ($inputpinyin) {
  213. case "yale":
  214. foreach ($py_table as $key => $hole) {
  215. $pinyintype_array[trim($hole[5] . '4')] = trim($hole[3] . "4");
  216. $pinyintype_array[trim($hole[5] . '3')] = trim($hole[3] . "3");
  217. $pinyintype_array[trim($hole[5] . '2')] = trim($hole[3] . "2");
  218. $pinyintype_array[trim($hole[5] . '1')] = trim($hole[3] . "1");
  219. }
  220. break; // end case yale
  221. case "tongyong_pinyin":
  222. foreach ($py_table as $key => $hole) {
  223. $pinyintype_array[trim($hole[5] . '4')] = trim($hole[4] . "4");
  224. $pinyintype_array[trim($hole[5] . '3')] = trim($hole[4] . "3");
  225. $pinyintype_array[trim($hole[5] . '2')] = trim($hole[4] . "2");
  226. $pinyintype_array[trim($hole[5] . '1')] = trim($hole[4] . "1");
  227. }
  228. break; // end case tongyong_pinyin
  229. case "zhuyin":
  230. // hole[5] - hanyu_pinyin ... hole[0] - zhuyin
  231. foreach ($py_table as $key => $hole) {
  232. $pinyintype_array[trim($hole[5] . '4')] = trim($hole[0] . "ˋ");
  233. $pinyintype_array[trim($hole[5] . '3')] = trim($hole[0] . "ˇ");
  234. $pinyintype_array[trim($hole[5] . '2')] = trim($hole[0] . "ˊ");
  235. $pinyintype_array[trim($hole[5] . '1')] = trim($hole[0]);
  236. $pinyintype_array[trim($hole[5])] = trim($hole[0]);
  237. }
  238. break;
  239. default:
  240. echo "--";
  241. break;
  242. }
  243. return $pinyintype_array; // returns pinyintype - hanyupinyin
  244. }
  245. // end FUNCTION pzpinyin_pinyintype_array_load
  246. function pzpinyin_pinyintype_change($inputPhrase, $conversion_mode = 'hanyu_pinyin', $conversion_set = 'yale') {
  247. $eachWord = explode(" ", $inputPhrase);
  248. $pinyintype_array = $this->pzpinyin_pinyintype_array_load($conversion_set);
  249. //print_r($pinyintype_array);
  250. foreach ($eachWord as $dummy_key => &$word) {
  251. // uasort works better for zhuyin->pinyin
  252. /** !! experimental block * */
  253. if ($conversion_mode == 'hanyu_pinyin') {
  254. // uasort works better for zhuyin->pinyin
  255. uasort($pinyintype_array, array($this, "pzpinyin_cmp"));
  256. } else {
  257. // uksort works better for pinyin->zhuyin
  258. uksort($pinyintype_array, array($this, "pzpinyin_cmp"));
  259. }
  260. foreach ($pinyintype_array as $hanyu_pinyin => $otherpinyintype) {
  261. if ($conversion_mode == 'hanyu_pinyin') {
  262. $word = str_replace($otherpinyintype, $hanyu_pinyin, $word);
  263. } else {
  264. $word = str_replace($hanyu_pinyin, $otherpinyintype, $word);
  265. }
  266. } // end FOREACH tongyong_array
  267. $converted_words[] = $word;
  268. } // end foreach WORD
  269. $converted_phrase = implode(" ", $converted_words);
  270. return $converted_phrase; // string of converted pinyin phrase
  271. }
  272. // end FUNCTION pzpinyin_pinyintype_change
  273. ## !! EXPERIMENTAL ## MAYBE NO LONGER NEEDED ?!
  274. // pzpinyin_gethanzi_by_pinyin
  275. // convert numerals or pinyin to Hanzi
  276. function pzpinyin_gethanzi_by_pinyin($inputPinyin) {
  277. // numbers 0 - 9 --> Hanzi
  278. $decoder_ring['0'] = urldecode("%E3%80%87"); //0
  279. $decoder_ring['1'] = urldecode("%E4%B8%80"); //1
  280. $decoder_ring['2'] = urldecode("%E4%BA%8C"); //2
  281. $decoder_ring['3'] = urldecode("%E4%B8%89"); //3
  282. $decoder_ring['4'] = urldecode("%E5%9B%9B"); //4
  283. $decoder_ring['5'] = urldecode("%E4%BA%94"); //5
  284. $decoder_ring['6'] = urldecode("%E5%85%AD"); //6
  285. $decoder_ring['7'] = urldecode("%E4%B8%83"); //7
  286. $decoder_ring['8'] = urldecode("%E5%85%AB"); //8
  287. $decoder_ring['9'] = urldecode("%E4%B9%9D"); //9
  288. // no-tone pinyin for numbers 0 - 9 --> Hanzi
  289. $decoder_ring['ling'] = urldecode("%E3%80%87"); //0
  290. $decoder_ring['yi'] = urldecode("%E4%B8%80"); //1
  291. $decoder_ring['er'] = urldecode("%E4%BA%8C"); //2
  292. $decoder_ring['san'] = urldecode("%E4%B8%89"); //3
  293. $decoder_ring['si'] = urldecode("%E5%9B%9B"); //4
  294. $decoder_ring['wu'] = urldecode("%E4%BA%94"); //5
  295. $decoder_ring['liu'] = urldecode("%E5%85%AD"); //6
  296. $decoder_ring['qi'] = urldecode("%E4%B8%83"); //7
  297. $decoder_ring['ba'] = urldecode("%E5%85%AB"); //8
  298. $decoder_ring['jiu'] = urldecode("%E4%B9%9D"); //9
  299. #size delimiters / classifiers
  300. #biggie = bigyi = 100 million
  301. $decoder_ring['biggie'] = urldecode("%E5%84%84"); // 100,000,000 ONE HUNDRED MILLION
  302. $decoder_ring['wan'] = urldecode("%E8%90%AC"); // 10,000 TEN THOUSAND
  303. $decoder_ring['qian'] = urldecode("%E5%8D%83"); // 1,000 THOUSAND
  304. $decoder_ring['bai'] = urldecode("%E7%99%BE"); // 100 HUNDRED
  305. $decoder_ring['shi'] = urldecode("%E5%8D%81"); // 10 TEN
  306. # fractional
  307. $decoder_ring['zhi'] = urldecode("%E4%B9%8B"); // delimiter qty fractional
  308. # qty of 2 TRADITIONAL CHINESE CHARACTERS
  309. $decoder_ring['liang'] = urldecode("%E5%85%A9"); // a pair of ...
  310. # AM and PM for clock times
  311. $decoder_ring['am'] = urldecode("%E4%B8%8A%E5%8D%88"); // 00:00 AM
  312. $decoder_ring['pm'] = urldecode("%E4%B8%8B%E5%8D%88"); // 00:00 PM
  313. # negative number flag
  314. $decoder_ring['nian'] = urldecode("%E5%B9%B4"); // year
  315. $decoder_ring['yue'] = urldecode("%E6%9C%88"); // month
  316. $decoder_ring['ri'] = urldecode("%E6%97%A5"); // formal
  317. // $decoder_ring['hao'] = urldecode("%E5%8F%B7"); // informal
  318. # negative number flag
  319. $decoder_ring['fu'] = urldecode("%E8%B2%A0"); // negative number
  320. # clock time delimiters TRADITIONAL CHARACTERS (LONG-FORM) CHINESE
  321. $decoder_ring['zhong'] = urldecode("%E9%8D%BE"); // clock end-delimiter
  322. $decoder_ring['dian'] = urldecode("%E9%BB%9E"); // hour classifier
  323. $decoder_ring['fen'] = urldecode("%E5%88%86"); // minute classifier
  324. // OR money classifier (1/100 yuan)
  325. $decoder_ring['ke'] = urldecode("%E5%88%BB"); // quarter-hour classifer
  326. # clock time delimiters TRADITIONAL CHARACTERS (LONG-FORM) CHINESE
  327. $decoder_ring['mao'] = urldecode("%E6%AF%9B"); // money classifer (1/10 yuan)
  328. $decoder_ring['kuai'] = urldecode("%E5%A1%8A"); // money classifer (1 yuan)
  329. if (@$decoder_ring[(string) $inputPinyin]) {
  330. // simply returns hanzi string. no spills. no mess.
  331. return $decoder_ring[(string) $inputPinyin];
  332. } // end IF
  333. return $inputPinyin;
  334. }
  335. // end FCN pzpinyin_gethanzi_by_pinyin
  336. // pzpinyin_hearpinyin
  337. ## !!! EXPERIMENTAL !!! ##
  338. function pzpinyin_hearpinyin($qc, $pacer = "8t88") {
  339. /* * *
  340. @SUPPORT FILES: Quicktime methods
  341. @SUPPORT FILES: Pinyin Tone Bank
  342. @SUPPORT FILES: README file (optional, of course)
  343. */
  344. // ** REQUIRES CLEANUP ** //
  345. // if root, sounds_directory = ""
  346. // if subdirectory, just enter name "voz" or "sounds"
  347. $sounds_directory = "";
  348. // pacer appears to be a counter for each iteration in a while/for loop situation
  349. // qc appears to be pinyin query string
  350. if ($qc == "") {
  351. return FALSE;
  352. }
  353. $ggx = $pacer;
  354. $uc = explode(" ", $qc);
  355. $uu = 1;
  356. $pp = 5;
  357. foreach ($uc as $g) {
  358. $peanut = rand(1, 3000) * 3;
  359. $cashew = rand(2, $peanut);
  360. $gx = $g;
  361. $pacer++;
  362. $pacelap = $g . "_" . $pacer . "_" . md5($g . $pacer . $cashew);
  363. // in windows, you need to have a max height/width of 0 (zero) for "invisble player"
  364. // cannot get rid of the player dots in Mac OS X yet ...
  365. $osxdims = 0;
  366. if (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac OS X')) {
  367. $osxdims = 1;
  368. // must have a minimum height/width of 1 for the EMBED in Mac OS X, otherwise will not work
  369. // yes, the dot is there, but it is better than the sound not work, right?
  370. // and yes, i talk to myself whilst i code teh_poetry
  371. }
  372. // 0.8.4 // fixes issue ISSUE 84
  373. if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), "msie 7")) {
  374. $pinyin_sound_embed_tags[] = "
  375. <div style='position:absolute;'>
  376. <OBJECT width=$osxdims height=$osxdims
  377. classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B'
  378. codebase='http://www.apple.com/qtactivex/qtplugin.cab'
  379. id=$pacelap>
  380. <param name='src' value='" . $sounds_directory . "$gx.mp3'>
  381. <param name='autoplay' value='false'>
  382. <param name='controller' value='false'>
  383. <EMBED
  384. cache=true
  385. bgcolor=#ffffe0
  386. width=$osxdims
  387. height=$osxdims
  388. src=" . $sounds_directory . "$gx.mp3
  389. TYPE='video/quicktime'
  390. qtsrc=" . $sounds_directory . "$gx.mp3
  391. PLUGINSPAGE=www.apple.com/quicktime/download
  392. name=$pacelap
  393. id=$pacelap
  394. enablejavascript=true
  395. autostart=false>
  396. </EMBED>
  397. </OBJECT></div>";
  398. } else {
  399. // version 0.4 no more echoed output
  400. // resolves issues of printing prior to sending headers by PHP
  401. $pinyin_sound_embed_tags[] = "
  402. <EMBED
  403. cache=true
  404. bgcolor=#ffffe0
  405. width=$osxdims
  406. height=$osxdims
  407. src=" . $sounds_directory . "$gx.mp3
  408. TYPE='video/quicktime'
  409. qtsrc=" . $sounds_directory . "$gx.mp3
  410. PLUGINSPAGE=www.apple.com/quicktime/download
  411. name='$pacelap'
  412. id='$pacelap'
  413. enablejavascript=true
  414. autostart=false>
  415. </EMBED>";
  416. // 0.8.4 opera issue?
  417. // opera cannot see past the DIV arrh! need reference
  418. // maybe getElementByID?
  419. } // END IF FOR BROWSER EMBED OR EMBED/OBJECT DETECTION
  420. $pinyin_sound_links[] = "<a class=pinyinsound
  421. href='http://www.primezero.com/chinese/find?q=$g'
  422. onmouseover=PlayPY('$pacelap');
  423. onmouseout=StopPY('$pacelap');>" .
  424. $this->pzpinyin_tones_number_to_mark($g) . "</a>";
  425. } // foreach
  426. // need the <BR> between the EMBEDS and the pinyin sounds links ...
  427. $output = "" . implode(" ", $pinyin_sound_embed_tags) .
  428. "<font size=1><br></font>" . implode(" ", $pinyin_sound_links);
  429. return trim($output);
  430. }
  431. function pzhanzi_hanzi_pinyin_index_build($filename) {
  432. // maybe will need to change this to build Hanzi-Pinyin Index
  433. // maybe will change if anyone cares about the naming
  434. #suppose your handle opens a useful character index
  435. $handle = fopen($filename, "r");
  436. #if you can grip the handle
  437. if ($handle) {
  438. #while you haven't finished gripping the handle
  439. while (!feof($handle)) {
  440. #grease the handle with buffer
  441. $buffer = fgets($handle);
  442. #chop the buffer into edible slices
  443. $slices = explode("\t", $buffer);
  444. # slice-0 is chinese character (bread)
  445. $bread = $slices[0];
  446. # slice-1 is hanyu pinyin in numerical notation (cheese)
  447. @$open_faced_pinyin_sandwich[$bread] = $slices[1];
  448. } // end WHILE
  449. } // end IF
  450. #TADA! your open faced pinyin sandwich
  451. return $open_faced_pinyin_sandwich;
  452. }
  453. // end FCN pzhanzi_hanzi_pinyin_index_build
  454. # cleans up a lot of messy characters when we are talking about converting inside articles.
  455. # perhaps this needs its own class to also provide error-handling features
  456. function pzhanzi_input_cleanup($qx) {
  457. $qx = $this->pzpinyin_tonedisplay_stripnumbers($qx);
  458. $qx = str_replace("(", "", $qx);
  459. $qx = str_replace(")", "", $qx);
  460. $qx = str_replace(".", "", $qx);
  461. $qx = str_replace(" ", "", $qx);
  462. $qx = str_replace(",", "", $qx);
  463. $qx = str_replace("'", "", $qx);
  464. $qx = str_replace("\"", "", $qx);
  465. $qx = str_replace(";", "", $qx);
  466. $qx = str_replace(":", "", $qx);
  467. #now let's see how we can remove some chinese punctuation
  468. $qx = urlencode($qx);
  469. $qx = str_replace("%EF%BC%8C", "", $qx);
  470. $qx = str_replace("%E3%80%81", "", $qx);
  471. $qx = str_replace("%7C", "", $qx);
  472. $qx = str_replace("%3A", "", $qx);
  473. $qx = str_replace("%EF%BC%9A", "", $qx);
  474. $qx = str_replace("+", "", $qx);
  475. $qx = str_replace("%E3%80%82", "", $qx);
  476. $qx = str_replace("%E3%80%8A", "", $qx);
  477. $qx = str_replace("%E3%80%8B", "", $qx);
  478. $qx = str_replace("%EF%BC%89", "", $qx);
  479. $qx = str_replace("%EF%BC%88", "", $qx);
  480. $qx = urldecode($qx);
  481. return $qx;
  482. }
  483. // end FCN pzhanzi_query_cleanup
  484. ## !! EXPERIMENTAL ##
  485. // throwback to Java style of storing data in String databases :-)
  486. function pzhanzi_daxie_xiaoxie_loadindex() {
  487. $x1 = "零壹貳參肆伍陸柒捌玖拾佰仟萬億";
  488. $x2 = "〇一二三四五六七八九十百千萬億";
  489. $daxie = str_split($x1, 3);
  490. $xiaoxie = str_split($x2, 3);
  491. $daxie_array = array_combine($xiaoxie, $daxie);
  492. return $daxie_array;
  493. }
  494. ## !! EXPERIMENTAL ##
  495. // throwback to Java style of storing data in String databases :-)
  496. function pzhanzi_xiaoxie_to_daxie($daxie) {
  497. $daxie_array = $this->pzhanzi_daxie_xiaoxie_loadindex();
  498. foreach ($daxie_array as $k => $da) {
  499. $daxie = str_replace($k, $da, $daxie);
  500. }
  501. return $daxie;
  502. }
  503. // combining hanzi_to_pinyin and add ruby display - maybe also try hanzi to zhuyin
  504. // @param: (string) inputHanzi
  505. // @param: (string) rubydisplay (optional.. sorta)
  506. // @return: (string) converted_phrase
  507. function pzhanzi_hanzi_to_pinyin($inputHanzi, $rubydisplay = FALSE) {
  508. // does not always clean up the string
  509. $inputHanzi = $this->pzhanzi_input_cleanup($inputHanzi);
  510. $eachWord = explode(" ", $inputHanzi);
  511. # COMBINE both open-face sandwiches (traditional and simplified chinese hanzi2pinyin indexes)
  512. $combined_index = $this->pzhanzi_hanzi_pinyin_index_build(HANZILIB . 'idx88.txt') + $this->pzhanzi_hanzi_pinyin_index_build(HANZILIB . 'idx99.txt');
  513. foreach ($eachWord as $dummy_key => &$word) {
  514. uasort($combined_index, array($this, "pzpinyin_cmp"));
  515. foreach ($combined_index as $hanziside => $pinyinside) {
  516. if ($rubydisplay === TRUE) {
  517. // http://en.wikipedia.org/wiki/Ruby_character
  518. // <ruby><rb>**ruby**base</rb><rp>(</rp><rt>**rubytext**</rt><rp>)</rp></ruby>
  519. $pinyinside = "<ruby><rb><font size=6 color=navy> $hanziside </font></rb>
  520. <rp>(</rp><rt><font size=3 color=gray> $pinyinside </font></rt><rp>)</rp></ruby>";
  521. $word = str_replace($hanziside, $pinyinside, $word);
  522. } else {
  523. $word = str_replace($hanziside, $pinyinside, $word);
  524. }
  525. } // end FOREACH hanzi side versus pinyin side
  526. $converted_words[] = $word;
  527. } // end foreach WORD
  528. $converted_phrase = implode(" ", $converted_words);
  529. // fixes issue 128 ..
  530. $converted_phrase = str_replace("\n", " ", $converted_phrase);
  531. return $converted_phrase; // string of converted pinyin phrase
  532. }
  533. // end FUNCTION pzpinyin_pinyintype_change
  534. function pzhanzi_traditional_to_simplified($inputHanzi) {
  535. // does not always clean up the string
  536. $inputHanzi = $this->pzhanzi_input_cleanup($inputHanzi);
  537. $eachWord = explode(" ", $inputHanzi);
  538. # COMBINE both open-face sandwiches (traditional and simplified chinese hanzi2pinyin indexes)
  539. $combined_index = $this->pzhanzi_hanzi_pinyin_index_build(HANZILIB . 'idx33.txt');
  540. foreach ($eachWord as $dummy_key => &$word) {
  541. uasort($combined_index, array($this, "pzpinyin_cmp"));
  542. foreach ($combined_index as $tradside => $simpside) {
  543. $word = str_replace($tradside, $simpside, $word);
  544. } // end FOREACH hanzi side versus pinyin side
  545. $converted_words[] = $word;
  546. } // end foreach WORD
  547. $converted_phrase = implode(" ", $converted_words);
  548. // fixes issue 128 ..
  549. $converted_phrase = str_replace("\n", "", $converted_phrase);
  550. return $converted_phrase; // string of converted pinyin phrase
  551. }
  552. // end FUNCTION pzpinyin_pinyintype_change
  553. // ** EXPERIMENTAL ** ... STILL *SIGH* ...//
  554. function pzcedict_entry_getvalues($m, $def_array = FALSE) {
  555. # four delimiters, later can be function arguments, maybe?
  556. $py_start = "["; // pinyin starts here
  557. $py_end = "]"; // pinyin ends here
  558. $defs_separator = "/"; // separates multiple definitions /this/that/the_other/
  559. $part_separator = " "; // separates part of each entry CHINESE, PINYIN, THEN DEFINITIONS
  560. # LINE-SKIPPING CODE HERE ... *LALLY DAAAAA *LALLY DAAAAA *LALLY DAAAAA
  561. if (ord($m) == 35) { // if this is a comment line .. just FOGHETABOUT-IT ...
  562. return NULL; // return nothing
  563. }
  564. // ** maybe ... NEED A SEPARATE CLASS FOR HANDLING OF LANGUAGE PROCESSING ERRORS ** //
  565. try {
  566. # no args? AAH!!!
  567. if (!func_get_arg(0)) {
  568. throw new Exception("the ONE AND ONLY parameter is missing!
  569. PLEASE INPUT A SINGLE LINE FROM CEDICT 8809<p>");
  570. }
  571. try {
  572. # we are missing any of the 3 important delimiters... AAH!!!
  573. if (!strpos($m, $py_start) || !strpos($m, $py_end) || !strpos($m, $defs_separator)) {
  574. throw new Exception("ah!");
  575. }
  576. try {
  577. // echo ord($m); // checks for leading characters ... looks ok
  578. # line doesn't start with traditional character?... AAH!!!
  579. // the last character of the first character set
  580. $back_m = substr(substr($m, 0, strpos($m, " ")), -3, 3);
  581. // does the first character or the last character of the first character set look like
  582. if (ord(urlencode($m)) === 37 || ord(urlencode($back_m)) == 37) {
  583. } else {
  584. throw new Exception("ahh!");
  585. }
  586. } catch (Exception $e) {
  587. return "CEDICT format error -- CHARACTER syntax error 8802 --
  588. FIRST OR LAST CHARACTER OF THE FIRST CHARACTER SET
  589. DOES NOT TO APPEAR TO BE CHINESE<p>";
  590. } // end TRYCATCH character
  591. } catch (Exception $e) {
  592. return "CEDICT format error -- DELIMITER syntax error 8801 --
  593. MUST FOLLOW CEDICT LINE SYNTAX<p>";
  594. } // end TRYCATCH delimiter
  595. } catch (Exception $e) {
  596. return "PLEASE PROVIDE A LINE FROM CEDICT -- LINE input error 8808";
  597. } // end TRYCATCH no parameters
  598. # this grabs the traditional characters before the first space
  599. $trad_chars = substr($m, 0, strpos($m, $part_separator));
  600. $trad_chars = trim($trad_chars); // groom output, remove whitespace from in front and in back
  601. # this grabs the simplified characters between the first space and the space touching pinyin
  602. $simp_chars = substr($m, strpos($m, $part_separator), strpos($m, $py_start) - strpos($m, $part_separator));
  603. $simp_chars = trim($simp_chars); // groom output // groom output, remove whitespace from in front and in back
  604. # this grabs the pin1 yin1 sounds within the [ ] brackets
  605. $pinyin = substr($m, (strpos($m, $py_start) + 1), strpos($m, $py_end) - strpos($m, $py_start) - 1);
  606. $pinyin = trim(strtolower($pinyin)); // groom output // groom output, remove whitespace from in front and in back
  607. # this is the remaining portion of the string until the end of the line... pal...
  608. $definitionExtract = substr($m, strpos($m, $py_end) + 1);
  609. ## returns array from the Land of Make Believe! DING! DING!
  610. $trolley['trad'] = (string) $trad_chars;
  611. $trolley['simp'] = (string) $simp_chars;
  612. $trolley['py'] = (string) $pinyin;
  613. if ($def_array === TRUE) {
  614. # each of the definitions are delimited by a /
  615. $eachDef = explode($defs_separator, $definitionExtract);
  616. ## the following algorithm may be faster than array_walk,
  617. ## i have no idea yet ( i don't know why i care yet )
  618. #brings order to galaxy of defintions (A-Z sorting)
  619. sort($eachDef);
  620. // #print_r($eachDef); // just checking output prior to array_shift
  621. # cleans front of the array, if there are any NULL elements, front since blank is front side
  622. while (trim($eachDef[0]) == "") {
  623. array_shift($eachDef); // chop!!
  624. }
  625. // #print_r($eachDef); // just checking output again, looks good
  626. $trolley['defs'] = (array) $eachDef;
  627. // var_dump($trolley); // one for the road. one last check.
  628. } else {
  629. $trolley['defs'] = (string) $definitionExtract;
  630. }
  631. return $trolley; // returns the ARRAY of ENGLISH, CHINESE, and DEFINITIONS .. as promised.
  632. }
  633. // end FCN pzcedict_entry_get_values
  634. ## !!! EXPERIMENTAL !!! ##
  635. function pzcedict_metadata_describe($filename) {
  636. $metadata = array();
  637. $handle = fopen($filename, "r"); // USES raw unchanged CEDICT flatfile
  638. $row = 1;
  639. if ($handle) {
  640. while (!feof($handle)) {
  641. $line = fgets($handle, 9000);
  642. if (strstr($line, "#!")) {
  643. $metadataline = explode("=", $line);
  644. $key = str_replace("#!", "", $metadataline[0]);
  645. $metadata[$key] = $metadataline[1];
  646. }
  647. } // end WHILE
  648. fclose($handle);
  649. } // end IF
  650. return $metadata;
  651. }
  652. // end FCN get_metadata
  653. ## ______________________________________________________________________________________________
  654. ## HanziTools - pznumbers_ -- processing numbers and quantities into Chinese
  655. ## Puny Methods below this line ...
  656. function pznumbers_convert($n) {
  657. // n is actual number
  658. // m is the switch for the operation
  659. $m = $this->pznumbers_detex($n);
  660. switch ($m) {
  661. case 'regex_fraction':
  662. return $this->pznumbers_fraction_calculate($n);
  663. break;
  664. case 'regex_percent':
  665. return $this->pznumbers_fraction_calculate($n, 1); // toggling percent
  666. break;
  667. case 'regex_time':
  668. return $this->pznumbers_time_calculate($n);
  669. break;
  670. case 'regex_time_am_pm':
  671. return $this->pznumbers_time_calculate($n);
  672. break;
  673. case 'regex_decimal':
  674. return $this->pznumbers_decimal_calculate($n);
  675. break;
  676. case 'regex_whole_number':
  677. return $this->pznumbers_bignumber_calculate($n);
  678. break;
  679. case 'regex_yearonly':
  680. return $this->pznumbers_yearonly_calculate($n);
  681. break;
  682. case 'regex_money':
  683. return $this->pznumbers_money_calculate($n);
  684. break;
  685. case 'regex_money_commas':
  686. return $this->pznumbers_money_calculate($n);
  687. break;
  688. case 'regex_whole_commas':
  689. return $this->pznumbers_bignumber_calculate($n);
  690. break;
  691. case 'regex_decimal_commas':
  692. return $this->pznumbers_decimal_calculate($n);
  693. break;
  694. case 'regex_date_long_1':
  695. return $this->pznumbers_date_calculate($n);
  696. break;
  697. case 'regex_date_short_1':
  698. if ($n = $this->pznumbers_checkdate_short_isvalid($n)) {
  699. return $this->pznumbers_date_calculate($n);
  700. } else {
  701. return FALSE;
  702. }
  703. break;
  704. case 'regex_date_short_2':
  705. if ($n = $this->pznumbers_checkdate_short_isvalid($n)) {
  706. return $this->pznumbers_date_calculate($n);
  707. } else {
  708. return FALSE;
  709. }
  710. break;
  711. case 'regex_dur_weeks':
  712. return $this->pznumbers_duration_weeks($n);
  713. break;
  714. case 'regex_dur_months':
  715. return $this->pznumbers_duration_months($n);
  716. break;
  717. case 'regex_dur_days':
  718. return $this->pznumbers_duration_days($n);
  719. break;
  720. case 'regex_dur_hours':
  721. return $this->pznumbers_duration_hours($n);
  722. break;
  723. case 'regex_dur_minutes':
  724. return $this->pznumbers_duration_minutes($n);
  725. break;
  726. case 'regex_ordinal':
  727. return $this->pznumbers_ordinal($n);
  728. break;
  729. default:
  730. return FALSE; // just returns FALSE if not converted
  731. break;
  732. } //end SWITCH statement
  733. }
  734. // end FCN pznumbers_convert
  735. function pznumbers_detex($q) {
  736. $q = strtolower($q);
  737. $delimit_date = "([-/_\.])";
  738. $any_month_longname = "(january|february|march|april|may|june|july|august|september|october|november|december)";
  739. $any_month_shortname = "(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
  740. $regex_array['regex_dur_minutes'] = "^([0-9]{1,12}) minutes[s]?";
  741. $regex_array['regex_dur_hours'] = "^([0-9]{1,12}) hour[s]?";
  742. $regex_array['regex_dur_days'] = "^([0-9]{1,12}) day[s]?";
  743. $regex_array['regex_ordinal'] = "^([2-9]*(1st|2nd|3rd|[4-9]th)|[2-9]0th|1[0-9]th)";
  744. $regex_array['regex_dur_weeks'] = "^([0-9]{1,12}) week[s]?";
  745. $regex_array['regex_dur_months'] = "^([0-9]{1,12}) month[s]?";
  746. // July 29, 2005
  747. $regex_array['regex_date_long_1'] = "^" . $any_month_longname . " [0-9]{1,2}, [0-9]{4,4}$";
  748. // MM-DD-YYYY
  749. $regex_array['regex_date_short_1'] = "^[0-9]{1,2}" . $delimit_date . "[0-9]{1,2}" . $delimit_date . "[0-9]{4}$";
  750. // YYYY-MM-DD
  751. $regex_array['regex_date_short_2'] = "^[0-9]{4}" . $delimit_date . "[0-9]{1,2}" . $delimit_date . "[0-9]{1,2}$";
  752. $regex_array['regex_yearonly'] = "^(year) ([0-9]{1,4})$";
  753. $regex_array['regex_money'] = "^[$]+([0-9]{1,12})(\.([0-9]{2}))?$";
  754. $regex_array['regex_money_commas'] = "^[$]+[0-9]{1,3}(\,[0-9]{3})*(\.([0-9]{2}))?$";
  755. $regex_array['regex_fraction'] = "^[-]?([0-9]{1,12})/([0-9]{1,12})$";
  756. $regex_array['regex_percent'] = "^[-]?([0-9]{1,12})%";
  757. $regex_array['regex_time'] = "^([1-9]|[1][0-9]|[2][0-3]|[0][0]):([0-5][0-9])$";
  758. $regex_array['regex_time_am_pm'] = "^ *(1[0-2]|[1-9]):[0-5][0-9] *(a|p|A|P)(m|M) *$";
  759. $regex_array['regex_decimal'] = "^[-]?([0-9]{1,12})\.([0-9]{1,12})$";
  760. $regex_array['regex_decimal_commas'] = "^[-]?[0-9]{1,3}(\,[0-9]{3})*\.([0-9]{1,12})$";
  761. $regex_array['regex_whole_number'] = "^[-]?([0-9]{1,12})$";
  762. $regex_array['regex_whole_commas'] = "^[-]?[0-9]{1,3}(\,[0-9]{3})*$";
  763. foreach ($regex_array as $regex_key => $regex_value) {
  764. if (eregi($regex_value, $q, $regs)) {
  765. return $regex_key;
  766. } // end IF REGEX
  767. } // end FOREACH
  768. }
  769. // end FCN detexNumbers
  770. function pznumbers_ordinal($n) {
  771. # husking the ordinal suffixes
  772. $n = str_replace("st", "", $n);
  773. $n = str_replace("nd", "", $n);
  774. $n = str_replace("rd", "", $n);
  775. $n = str_replace("th", "", $n);
  776. $n = $this->pzpinyin_gethanzi_by_pinyin('di') . $this->pznumbers_bignumber_calculate($n);
  777. return $n;
  778. }
  779. function pznumbers_duration_minutes($n) {
  780. # husking minutes
  781. $n = str_replace(" minutes", "", $n);
  782. $n = str_replace(" minute", "", $n);
  783. $n = $this->pznumbers_bignumber_calculate($n) .
  784. $this->pzpinyin_gethanzi_by_pinyin('fen') .
  785. $this->pzpinyin_gethanzi_by_pinyin('zhong');
  786. return $n;
  787. }
  788. function pznumbers_duration_hours($n) {
  789. # husking hours
  790. $n = str_replace(" hours", "", $n);
  791. $n = str_replace(" hour", "", $n);
  792. $n = $this->pznumbers_bignumber_calculate($n) .
  793. $this->pzpinyin_gethanzi_by_pinyin('ge') .
  794. $this->pzpinyin_gethanzi_by_pinyin('xiaoshi');
  795. return $n;
  796. }
  797. function pznumbers_duration_days($n) {
  798. # husking days
  799. $n = str_replace(" days", "", $n);
  800. $n = str_replace(" day", "", $n);
  801. $n = $this->pznumbers_bignumber_calculate($n) .
  802. $this->pzpinyin_gethanzi_by_pinyin('tian');
  803. return $n;
  804. }
  805. function pznumbers_duration_weeks($n) {
  806. # husking weeks
  807. $n = str_replace(" weeks", "", $n);
  808. $n = str_replace(" week", "", $n);
  809. $n = $this->pznumbers_bignumber_calculate($n) .
  810. $this->pzpinyin_gethanzi_by_pinyin('ge') .
  811. $this->pzpinyin_gethanzi_by_pinyin('xingqi');
  812. return $n;
  813. }
  814. function pznumbers_duration_months($n) {
  815. # husking months
  816. $n = str_replace(" months", "", $n);
  817. $n = str_replace(" month", "", $n);
  818. $n = $this->pznumbers_bignumber_calculate($n) .
  819. $this->pzpinyin_gethanzi_by_pinyin('ge') .
  820. $this->pzpinyin_gethanzi_by_pinyin('yue');
  821. return $n;
  822. }
  823. function pznumbers_delimiters_normalize($n, $m) {
  824. $n = str_replace("-", $m, $n);
  825. $n = str_replace("_", $m, $n);
  826. $n = str_replace(".", $m, $n);
  827. return $n;
  828. }
  829. function pznumbers_date_calculate($inputDate) {
  830. $year = $this->pzpinyin_hanyu_pinyin_transcribe_to_hanzi(date("Y", strtotime($inputDate)));
  831. $month = $this->pznumbers_bignumber_calculate(date("n", strtotime($inputDate)));
  832. $day = $this->pznumbers_bignumber_calculate(date("j", strtotime($inputDate)));
  833. $myChineseDate = $year . $this->pzpinyin_gethanzi_by_pinyin('nian'); // YEAR
  834. $myChineseDate .= $month . $this->pzpinyin_gethanzi_by_pinyin('yue'); // MONTH
  835. $myChineseDate .= $day . $this->pzpinyin_gethanzi_by_pinyin('ri'); // DAY (RI or HAO)
  836. return $myChineseDate;
  837. }
  838. function pznumbers_checkdate_short_isvalid($inputDate) {
  839. $calendar_year = "";
  840. $calendar_month = "";
  841. $calendar_day = "";
  842. $month_array = array(
  843. 1 => "January",
  844. 2 => "February",
  845. 3 => "March",
  846. 4 => "April",
  847. 5 => "May",
  848. 6 => "June",
  849. 7 => "July",
  850. 8 => "August",
  851. 9 => "September",
  852. 10 => "October",
  853. 11 => "November",
  854. 12 => "December"
  855. );
  856. $mon_array = array();
  857. foreach ($month_array as $ma) {
  858. $mon_array[] = strtolower(substr($ma, 0, 3));
  859. }
  860. $check_array = explode("/", $this->pznumbers_delimiters_normalize($inputDate, "/"));
  861. // print_r($check_array);
  862. // MUST BE A TRIPLET
  863. if (count($check_array) !== 3) {
  864. return FALSE;
  865. }
  866. // // YYYY-MM-DD
  867. if (strlen($check_array[0]) == 4) {
  868. $calendar_year = (int) $check_array[0];
  869. array_shift($check_array);
  870. // // MM-DD-YYYY
  871. } elseif (strlen($check_array[2]) == 4) {
  872. $calendar_year = (int) $check_array[2];
  873. array_pop($check_array);
  874. }
  875. $calendar_month = (int) $check_array[0];
  876. if ($calendar_month > 12) {
  877. return FALSE;
  878. }
  879. $calendar_day = (int) $check_array[1];
  880. $calendar_month_name = $month_array[$calendar_month];
  881. $month_days_possible = date("t", strtotime("$calendar_month_name 1, $calendar_year"));
  882. if ($calendar_day > $month_days_possible) {
  883. return FALSE;
  884. }
  885. $date_to_check = $calendar_month_name . " " . $calendar_day . ", " . $calendar_year;
  886. // NOTE: LOOK AT THE FIRST DAY OF THE MONTH, TO FIND THE CORRECT MONTH.
  887. // IF YOU HAVE A CALENDAR OF 32, IT WILL BLEED TO THE NEXT DAY BECAUSE OF THE UNIX TIMESTAMP
  888. return $date_to_check;
  889. }
  890. function pznumbers_yearonly_calculate($n) {
  891. $n = str_replace("year ", "", $n);
  892. return $this->pzpinyin_hanyu_pinyin_transcribe_to_hanzi($n) . $this->pzpinyin_gethanzi_by_pinyin('nian');
  893. }
  894. function pznumbers_money_calculate($n) {
  895. $n = str_replace(",", "", $n);
  896. $kuai_count = 0; // 1 yuan
  897. $mao_count = 0; // 1/10 of yuan
  898. $fen_count = 0; // 1/100 of yuan
  899. $dollars = "";
  900. $cents = "";
  901. $kuai = "";
  902. $mao = "";
  903. $fen = "";
  904. $mao_unit = "";
  905. $kuai_unit = "";
  906. $fen_unit = "";
  907. $money_only = explode("$", $n);
  908. if (strpos($n, ".")) {
  909. $dollars_and_cents = explode(".", $money_only[1]);
  910. $dollars = $kuai_count = $dollars_and_cents[0];
  911. $kuai = $this->pznumbers_bignumber_calculate($dollars);
  912. $cents = $dollars_and_cents[1];
  913. } else {
  914. $dollars = $kuai_count = $money_only[1];
  915. $kuai = $this->pznumbers_bignumber_calculate($dollars);
  916. }
  917. if ($dollars == 2) {
  918. $kuai = $this->pzpinyin_gethanzi_by_pinyin('liang');
  919. }
  920. if ($kuai) {
  921. $kuai_unit = $this->pzpinyin_gethanzi_by_pinyin('kuai');
  922. }
  923. while ($cents >= 10) {
  924. $cents = $cents - 10;
  925. $mao_count++;
  926. $mao_unit = $this->pzpinyin_gethanzi_by_pinyin('mao');
  927. }
  928. if ($mao_count) {
  929. if ($mao_count == 2) {
  930. $mao = $this->pzpinyin_gethanzi_by_pinyin('liang');
  931. } else {
  932. $mao = $this->pznumbers_bignumber_calculate($mao_count);
  933. }
  934. }
  935. $fen_count = (int) $cents;
  936. if ($fen_count) {
  937. if ($cents == 2) {
  938. $fen = $this->pzpinyin_gethanzi_by_pinyin('liang');
  939. } else {
  940. $fen = $this->pznumbers_bignumber_calculate($fen_count);
  941. }
  942. $fen_unit = $this->pzpinyin_gethanzi_by_pinyin('fen');
  943. }
  944. // if there are only dollars ... play this tune
  945. if (!$fen_count && !$mao_count) {
  946. return $kuai . $kuai_unit;
  947. }
  948. // if we have between 0 and 1 .. (only cents) .. play this tun
  949. if (!$kuai_count && ($mao_count || $fen_count)) {
  950. return $mao . $mao_unit . $fen . $fen_unit;
  951. }
  952. // otherwise, play all of this ...
  953. return $kuai . $kuai_unit . $mao . $mao_unit . $fen . $fen_unit;
  954. }
  955. // PERCENT + FRACTION ARE TOGETHER ...
  956. // DECIMAL WILL ADDED AGAIN AS OF VERSION 0.5.3
  957. function pznumbers_decimal_calculate($n) {
  958. $t = explode(".", $n);
  959. $leftSide = $t[0]; // left side of the decimal
  960. $riteSide = $t[1]; // right side of the decimal
  961. $leftSide = $this->pznumbers_bignumber_calculate($leftSide);
  962. $riteSide = $this->pzpinyin_hanyu_pinyin_transcribe_to_hanzi($riteSide);
  963. $myDecimal = $leftSide . $this->pzpinyin_gethanzi_by_pinyin('dian') . $riteSide;
  964. return $myDecimal;
  965. }
  966. function pznumbers_fraction_calculate($n, $forcePercent = 0) {
  967. if ($forcePercent) {
  968. $t = explode("%", $n); // delimiter is % sign
  969. } else {
  970. $t = explode("/", $n); // delimiter is / sign
  971. }
  972. $leftSide = $t[0];
  973. $riteSide = $t[1];
  974. $negativeNumber = 0;
  975. if ($leftSide < 0) {
  976. $negativeNumber = 1;
  977. $leftSide = $leftSide / -1;
  978. }
  979. $leftSide = $this->pznumbers_bignumber_calculate($leftSide);
  980. $riteSide = $this->pznumbers_bignumber_calculate($riteSide);
  981. if ($riteSide == 100 || $forcePercent) {
  982. // precisely BAI , not YI BAI
  983. $riteSide = $this->pzpinyin_gethanzi_by_pinyin('bai');
  984. }
  985. //** flips the values around and orders for presentation
  986. $myFraction = $riteSide . $this->pzpinyin_gethanzi_by_pinyin('fen') . $this->pzpinyin_gethanzi_by_pinyin('zhi') . $leftSide;
  987. if ($negativeNumber) {
  988. $myFraction = $this->pzpinyin_gethanzi_by_pinyin('fu') . $myFraction;
  989. }
  990. return $myFraction;
  991. }
  992. function pznumbers_time_calculate($inputTime) {
  993. $am_pm = 'am';
  994. $hours = ""; // converted hours
  995. $minutes = ""; // converted minutes
  996. $timex = "";
  997. $inputTime = strtolower(trim($inputTime));
  998. //** peel off AM or PM from the input string
  999. if (substr($inputTime, -2, 2) == "am") {
  1000. $t = explode("am", $inputTime);
  1001. $timex = trim($t[0]);
  1002. } else if (substr($inputTime, -2, 2) == "pm") {
  1003. $t = explode("pm", $inputTime);
  1004. $timex = trim($t[0]);
  1005. $am_pm = 'pm';
  1006. } else {
  1007. $timex = $inputTime;
  1008. }
  1009. //** split the clock time into hours and minutes
  1010. $timeSplit = explode(":", $timex);
  1011. $h = (int) $timeSplit[0]; // hours
  1012. $m = (int) $timeSplit[1]; // minutes
  1013. if ($h > 11) {
  1014. $am_pm = 'pm';
  1015. $h = $h - 12;
  1016. }
  1017. // if in the midnight hour
  1018. if ($h == 0) {
  1019. $h = 12;
  1020. }
  1021. $hours = $this->pznumbers_number_calculate($h);
  1022. $hours = $this->pznumbers_time_hours_cleanup($hours);
  1023. if ($m == 0) {
  1024. return $this->pzpinyin_gethanzi_by_pinyin($am_pm) . $hours . $this->pzpinyin_gethanzi_by_pinyin('dian');
  1025. } else if ($m < 10) {
  1026. $minutes = $this->pznumbers_time_minutes_cleanup($m);
  1027. } else {
  1028. $minutes = $this->pznumbers_number_calculate($m);
  1029. }
  1030. $myResult = $this->pzpinyin_gethanzi_by_pinyin($am_pm) . $hours . $this->pzpinyin_gethanzi_by_pinyin('dian') . $this->pzpinyin_gethanzi_by_pinyin($minutes) . $this->pzpinyin_gethanzi_by_pinyin('fen');
  1031. return $myResult;
  1032. }
  1033. function pznumbers_number_calculate($n) {
  1034. $n = str_replace(",", "", $n);
  1035. // n = number
  1036. // g = graphical output
  1037. $Qian = 0;
  1038. $Bai = 0;
  1039. $Shi = 0;
  1040. $leftOver = 0;
  1041. $wanUnit = "";
  1042. $qianUnit = "";
  1043. $baiUnit = "";
  1044. $shiUni

Large files files are truncated, but you can click here to view the full file