2
0

function.php 5.9 KB

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