function.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. require_once __DIR__ . '/casesuf.inc';
  3. require_once __DIR__ . '/config.php';
  4. require_once __DIR__ . '/../path.php';
  5. $_book_index = null; //书的列表
  6. /*
  7. $mode:
  8. 0
  9. */
  10. function getPaliWordBase($word, $mode = 0)
  11. {
  12. global $case;
  13. //去除尾查
  14. $newWord = array();
  15. for ($row = 0; $row < count($case); $row++) {
  16. $len = mb_strlen($case[$row][1], "UTF-8");
  17. $end = mb_substr($word, 0 - $len, null, "UTF-8");
  18. if ($end == $case[$row][1]) {
  19. $base = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $case[$row][0];
  20. if ($base != $word) {
  21. $type = ".n.";
  22. $gramma = $case[$row][2];
  23. $parts = "{$base}+{$case[$row][1]}";
  24. if (isset($newWord[$base])) {
  25. array_push($newWord[$base], array("type" => $type,
  26. "gramma" => $gramma,
  27. "parts" => $parts,
  28. ));
  29. } else {
  30. $newWord[$base] = array(array("type" => $type,
  31. "gramma" => $gramma,
  32. "parts" => $parts,
  33. ));
  34. }
  35. }
  36. }
  37. }
  38. return ($newWord);
  39. }
  40. function _load_book_index()
  41. {
  42. global $_book_index, $_dir_lang, $currLanguage, $_dir_book_index;
  43. if (file_exists($_dir_lang . $currLanguage . ".json")) {
  44. $_book_index = json_decode(file_get_contents($_dir_book_index . "a/" . $currLanguage . ".json"));
  45. } else {
  46. $_book_index = json_decode(file_get_contents($_dir_book_index . "a/default.json"));
  47. }
  48. //print_r($_book_index);
  49. }
  50. function _get_book_info($index)
  51. {
  52. global $_book_index;
  53. foreach ($_book_index as $book) {
  54. if ($book->row == $index) {
  55. return ($book);
  56. }
  57. }
  58. return (null);
  59. }
  60. function _get_book_path($index)
  61. {
  62. global $_book_index;
  63. }
  64. function _get_para_path($book, $paragraph)
  65. {
  66. $dns = "" . _FILE_DB_PALITEXT_;
  67. $dbh = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
  68. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  69. $path = "";
  70. $parent = $paragraph;
  71. $deep = 0;
  72. $sFirstParentTitle = "";
  73. //循环查找父标题 得到整条路径
  74. while ($parent > -1) {
  75. $query = "select * from pali_text where \"book\" = ? and \"paragraph\" = ? limit 0,1";
  76. $stmt = $dbh->prepare($query);
  77. $stmt->execute(array($book, $parent));
  78. $FetParent = $stmt->fetch(PDO::FETCH_ASSOC);
  79. $toc = "<chapter book='{$book}' para='{$parent}' title='{$FetParent["toc"]}'>{$FetParent["toc"]}</chapter>";
  80. if ($path == "") {
  81. if ($FetParent["level"] < 100) {
  82. $path = $toc;
  83. } else {
  84. $path = "<para book='{$book}' para='{$parent}' title='{$FetParent["toc"]}'>{$paragraph}</para>";
  85. }
  86. } else {
  87. $path = $toc . $path;
  88. }
  89. if ($sFirstParentTitle == "") {
  90. $sFirstParentTitle = $FetParent["toc"];
  91. }
  92. $parent = $FetParent["parent"];
  93. $deep++;
  94. if ($deep > 5) {
  95. break;
  96. }
  97. }
  98. $dbh = null;
  99. return ($path);
  100. }
  101. class UUID
  102. {
  103. public static function v3($namespace, $name)
  104. {
  105. if (!self::is_valid($namespace)) {
  106. return false;
  107. }
  108. // Get hexadecimal components of namespace
  109. $nhex = str_replace(array('-', '{', '}'), '', $namespace);
  110. // Binary Value
  111. $nstr = '';
  112. // Convert Namespace UUID to bits
  113. for ($i = 0; $i < strlen($nhex); $i += 2) {
  114. $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
  115. }
  116. // Calculate hash value
  117. $hash = md5($nstr . $name);
  118. return sprintf('%08s-%04s-%04x-%04x-%12s',
  119. // 32 bits for "time_low"
  120. substr($hash, 0, 8),
  121. // 16 bits for "time_mid"
  122. substr($hash, 8, 4),
  123. // 16 bits for "time_hi_and_version",
  124. // four most significant bits holds version number 3
  125. (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
  126. // 16 bits, 8 bits for "clk_seq_hi_res",
  127. // 8 bits for "clk_seq_low",
  128. // two most significant bits holds zero and one for variant DCE1.1
  129. (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
  130. // 48 bits for "node"
  131. substr($hash, 20, 12)
  132. );
  133. }
  134. public static function v4()
  135. {
  136. return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  137. // 32 bits for "time_low"
  138. mt_rand(0, 0xffff), mt_rand(0, 0xffff),
  139. // 16 bits for "time_mid"
  140. mt_rand(0, 0xffff),
  141. // 16 bits for "time_hi_and_version",
  142. // four most significant bits holds version number 4
  143. mt_rand(0, 0x0fff) | 0x4000,
  144. // 16 bits, 8 bits for "clk_seq_hi_res",
  145. // 8 bits for "clk_seq_low",
  146. // two most significant bits holds zero and one for variant DCE1.1
  147. mt_rand(0, 0x3fff) | 0x8000,
  148. // 48 bits for "node"
  149. mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
  150. );
  151. }
  152. public static function v5($namespace, $name)
  153. {
  154. if (!self::is_valid($namespace)) {
  155. return false;
  156. }
  157. // Get hexadecimal components of namespace
  158. $nhex = str_replace(array('-', '{', '}'), '', $namespace);
  159. // Binary Value
  160. $nstr = '';
  161. // Convert Namespace UUID to bits
  162. for ($i = 0; $i < strlen($nhex); $i += 2) {
  163. $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
  164. }
  165. // Calculate hash value
  166. $hash = sha1($nstr . $name);
  167. return sprintf('%08s-%04s-%04x-%04x-%12s',
  168. // 32 bits for "time_low"
  169. substr($hash, 0, 8),
  170. // 16 bits for "time_mid"
  171. substr($hash, 8, 4),
  172. // 16 bits for "time_hi_and_version",
  173. // four most significant bits holds version number 5
  174. (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
  175. // 16 bits, 8 bits for "clk_seq_hi_res",
  176. // 8 bits for "clk_seq_low",
  177. // two most significant bits holds zero and one for variant DCE1.1
  178. (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
  179. // 48 bits for "node"
  180. substr($hash, 20, 12)
  181. );
  182. }
  183. public static function is_valid($uuid)
  184. {
  185. return preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' .
  186. '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $uuid) === 1;
  187. }
  188. }
  189. function pali2english($subject)
  190. {
  191. $subject = mb_strtolower($subject, 'UTF-8');
  192. $search = array('ā', 'ī', 'ū', 'ṅ', 'ñ', 'ṇ', 'ṭ', 'ḍ', 'ḷ', 'ṃ');
  193. $replace = array('a', 'i', 'u', 'n', 'n', 'n', 't', 'd', 'l', 'm');
  194. $title_en = str_replace($search, $replace, $subject);
  195. return ($title_en);
  196. }
  197. function mTime()
  198. {
  199. return (sprintf("%d", microtime(true) * 1000));
  200. }
  201. function getLanguageCode($inString)
  202. {
  203. return ("zh-cn");
  204. }