function.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. require_once __DIR__ . '/casesuf.inc';
  3. require_once __DIR__ . '/config.php';
  4. require_once __DIR__ . '/../config.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, _DB_USERNAME_, _DB_PASSWORD_, 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 "._TABLE_PALI_TEXT_." where book = ? and paragraph = ?";
  76. $stmt = $dbh->prepare($query);
  77. $stmt->execute(array($book, $parent));
  78. $FetParent = $stmt->fetch(PDO::FETCH_ASSOC);
  79. if($FetParent){
  80. $toc = "<chapter book='{$book}' para='{$parent}' title='{$FetParent["toc"]}'>{$FetParent["toc"]}</chapter>";
  81. if ($path == "") {
  82. if ($FetParent["level"] < 100) {
  83. $path = $toc;
  84. } else {
  85. $path = "<para book='{$book}' para='{$parent}' title='{$FetParent["toc"]}'>{$paragraph}</para>";
  86. }
  87. } else {
  88. $path = $toc . $path;
  89. }
  90. if ($sFirstParentTitle == "") {
  91. $sFirstParentTitle = $FetParent["toc"];
  92. }
  93. $parent = $FetParent["parent"];
  94. }else{
  95. break;
  96. }
  97. $deep++;
  98. if ($deep > 5) {
  99. break;
  100. }
  101. }
  102. $dbh = null;
  103. return ($path);
  104. }
  105. class UUID
  106. {
  107. public static function v3($namespace, $name)
  108. {
  109. if (!self::is_valid($namespace)) {
  110. return false;
  111. }
  112. // Get hexadecimal components of namespace
  113. $nhex = str_replace(array('-', '{', '}'), '', $namespace);
  114. // Binary Value
  115. $nstr = '';
  116. // Convert Namespace UUID to bits
  117. for ($i = 0; $i < strlen($nhex); $i += 2) {
  118. $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
  119. }
  120. // Calculate hash value
  121. $hash = md5($nstr . $name);
  122. return sprintf('%08s-%04s-%04x-%04x-%12s',
  123. // 32 bits for "time_low"
  124. substr($hash, 0, 8),
  125. // 16 bits for "time_mid"
  126. substr($hash, 8, 4),
  127. // 16 bits for "time_hi_and_version",
  128. // four most significant bits holds version number 3
  129. (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
  130. // 16 bits, 8 bits for "clk_seq_hi_res",
  131. // 8 bits for "clk_seq_low",
  132. // two most significant bits holds zero and one for variant DCE1.1
  133. (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
  134. // 48 bits for "node"
  135. substr($hash, 20, 12)
  136. );
  137. }
  138. public static function v4()
  139. {
  140. return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  141. // 32 bits for "time_low"
  142. mt_rand(0, 0xffff), mt_rand(0, 0xffff),
  143. // 16 bits for "time_mid"
  144. mt_rand(0, 0xffff),
  145. // 16 bits for "time_hi_and_version",
  146. // four most significant bits holds version number 4
  147. mt_rand(0, 0x0fff) | 0x4000,
  148. // 16 bits, 8 bits for "clk_seq_hi_res",
  149. // 8 bits for "clk_seq_low",
  150. // two most significant bits holds zero and one for variant DCE1.1
  151. mt_rand(0, 0x3fff) | 0x8000,
  152. // 48 bits for "node"
  153. mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
  154. );
  155. }
  156. public static function v5($namespace, $name)
  157. {
  158. if (!self::is_valid($namespace)) {
  159. return false;
  160. }
  161. // Get hexadecimal components of namespace
  162. $nhex = str_replace(array('-', '{', '}'), '', $namespace);
  163. // Binary Value
  164. $nstr = '';
  165. // Convert Namespace UUID to bits
  166. for ($i = 0; $i < strlen($nhex); $i += 2) {
  167. $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
  168. }
  169. // Calculate hash value
  170. $hash = sha1($nstr . $name);
  171. return sprintf('%08s-%04s-%04x-%04x-%12s',
  172. // 32 bits for "time_low"
  173. substr($hash, 0, 8),
  174. // 16 bits for "time_mid"
  175. substr($hash, 8, 4),
  176. // 16 bits for "time_hi_and_version",
  177. // four most significant bits holds version number 5
  178. (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
  179. // 16 bits, 8 bits for "clk_seq_hi_res",
  180. // 8 bits for "clk_seq_low",
  181. // two most significant bits holds zero and one for variant DCE1.1
  182. (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
  183. // 48 bits for "node"
  184. substr($hash, 20, 12)
  185. );
  186. }
  187. public static function is_valid($uuid)
  188. {
  189. return preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?' .
  190. '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $uuid) === 1;
  191. }
  192. }
  193. function pali2english($subject)
  194. {
  195. $subject = mb_strtolower($subject, 'UTF-8');
  196. $search = array('ā', 'ī', 'ū', 'ṅ', 'ñ', 'ṇ', 'ṭ', 'ḍ', 'ḷ', 'ṃ');
  197. $replace = array('a', 'i', 'u', 'n', 'n', 'n', 't', 'd', 'l', 'm');
  198. $title_en = str_replace($search, $replace, $subject);
  199. return ($title_en);
  200. }
  201. function mTime()
  202. {
  203. return (sprintf("%d", microtime(true) * 1000));
  204. }
  205. function getLanguageCode($inString)
  206. {
  207. return ("zh-cn");
  208. }