function.php 5.8 KB

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