note.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. require_once "../public/_pdo.php";
  3. require_once "../public/function.php";
  4. require_once "../channal/function.php";
  5. require_once "../path.php";
  6. $_channal = new Channal();
  7. $_data = array();
  8. if(isset($_POST["data"])){
  9. $_data = json_decode($_POST["data"],true);
  10. }
  11. else{
  12. if(isset($_GET["id"])){
  13. $id=$_GET["id"];
  14. }
  15. else{
  16. echo "error: no id";
  17. return;
  18. }
  19. if(isset($_GET["info"])){
  20. $info=$_GET["info"];
  21. }
  22. else{
  23. echo "error: no info";
  24. return;
  25. }
  26. $_data[] = array("id"=>$id,"data"=>$info);
  27. }
  28. if(isset($_POST["setting"])){
  29. $_setting = json_decode($_POST["setting"],true);
  30. }
  31. else{
  32. $_setting["lang"] = "";
  33. $_setting["channal"] = "";
  34. }
  35. $dns = "sqlite:"._FILE_DB_PALI_SENTENCE_;
  36. $db_pali_sent = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  37. $db_pali_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  38. $dns = "sqlite:"._FILE_DB_PALI_SENTENCE_SIM_;
  39. $db_pali_sent_sim = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  40. $db_pali_sent_sim->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  41. $dns = "sqlite:"._FILE_DB_SENTENCE_;
  42. $db_trans_sent = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  43. $db_trans_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  44. $output = array();
  45. foreach ($_data as $key => $value) {
  46. # code...
  47. $id = $value["id"];
  48. $arrInfo = explode("@",$value["data"]);
  49. if(isset($arrInfo[1])){
  50. $sentChannal = $arrInfo[1];
  51. }
  52. else{
  53. $sentChannal = "";
  54. }
  55. if(isset($arrInfo[0])){
  56. $arrSent = str_getcsv($arrInfo[0],"-");
  57. $bookId=$arrSent[0];
  58. $para=$arrSent[1];
  59. $begin=$arrSent[2];
  60. $end=$arrSent[3];
  61. }
  62. else{
  63. $bookId=0;
  64. $para=0;
  65. $begin=0;
  66. $end=0;
  67. }
  68. $query="SELECT id,html FROM 'pali_sent' WHERE book = ? AND paragraph = ? AND begin = ? AND end = ? ";
  69. $sth = $db_pali_sent->prepare($query);
  70. $sth->execute(array($bookId,$para,$begin,$end));
  71. $row = $sth->fetch(PDO::FETCH_ASSOC);
  72. if ($row) {
  73. $palitext= $row['html'];
  74. $pali_text_id = $row['id'];
  75. } else {
  76. $palitext="";
  77. $pali_text_id = 0;
  78. }
  79. $query="SELECT count FROM 'sent_sim_index' WHERE sent_id = ? ";
  80. $sth = $db_pali_sent_sim->prepare($query);
  81. $sth->execute(array($pali_text_id));
  82. $row = $sth->fetch(PDO::FETCH_ASSOC);
  83. if($row){
  84. $pali_sim= $row["count"];//explode(",",$row["sim_sents"]) ;
  85. }
  86. else{
  87. $pali_sim=0;
  88. }
  89. //查询相似句
  90. //find out translation 查询译文
  91. $tran="";
  92. $translation = array();
  93. $tran_channal = array();
  94. try{
  95. if(empty($_setting["channal"])){
  96. if($sentChannal==""){
  97. $query="SELECT * FROM sentence WHERE book= ? AND paragraph= ? AND begin= ? AND end= ? AND strlen >0 order by modify_time DESC limit 0 ,1 ";
  98. $channal = "";
  99. }
  100. else{
  101. $query="SELECT * FROM sentence WHERE book= ? AND paragraph= ? AND begin= ? AND end= ? AND strlen >0 AND channal = ? limit 0 ,1 ";
  102. }
  103. }
  104. else{
  105. $query="SELECT * FROM sentence WHERE book= ? AND paragraph= ? AND begin= ? AND end= ? AND strlen >0 AND channal = ? limit 0 ,1 ";
  106. $channal = $_setting["channal"];
  107. }
  108. $stmt = $db_trans_sent->prepare($query);
  109. if(empty($_setting["channal"])){
  110. if($sentChannal==""){
  111. $stmt->execute(array($bookId,$para,$begin,$end));
  112. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  113. if($Fetch){
  114. $tran = $Fetch["text"];
  115. $translation[]=array("id"=>$Fetch["id"],"text"=>$Fetch["text"],"lang"=>$Fetch["language"],"channal"=>$Fetch["channal"],"editor"=>$Fetch["editor"]);
  116. if(!empty($Fetch["channal"])){
  117. $tran_channal[$Fetch["channal"]] = $Fetch["channal"];
  118. }
  119. }
  120. }
  121. else{
  122. $stmt->execute(array($bookId,$para,$begin,$end,$sentChannal));
  123. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  124. if($Fetch){
  125. $tran = $Fetch["text"];
  126. $translation[]=array("id"=>$Fetch["id"],"text"=>$Fetch["text"],"lang"=>$Fetch["language"],"channal"=>$Fetch["channal"],"editor"=>$Fetch["editor"]);
  127. $tran_channal[$Fetch["channal"]] = $Fetch["channal"];
  128. }
  129. }
  130. }
  131. else{
  132. $arrChannal = explode(",",$_setting["channal"]);
  133. foreach ($arrChannal as $key => $value) {
  134. # code...
  135. $stmt->execute(array($bookId,$para,$begin,$end,$value));
  136. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  137. if($Fetch){
  138. $translation[]=array("id"=>$Fetch["id"],"text"=>$Fetch["text"],"lang"=>$Fetch["language"],"channal"=>$value,"editor"=>$Fetch["editor"]);
  139. }
  140. else{
  141. $translation[]=array("id"=>"","text"=>"","lang"=>"","channal"=>$value);
  142. }
  143. $tran_channal[$value] = $value;
  144. }
  145. }
  146. $tran_count = 1;
  147. }
  148. catch (Exception $e) {
  149. $tran = $e->getMessage();
  150. //echo 'Caught exception: ', $e->getMessage(), "\n";
  151. }
  152. foreach ($tran_channal as $key => $value) {
  153. # code...
  154. $tran_channal[$key] = $_channal->getChannal($key);
  155. }
  156. foreach ($translation as $key => $value) {
  157. # code...
  158. if($value["channal"]){
  159. $translation[$key]["channalinfo"]=$tran_channal[$value["channal"]];
  160. }
  161. else{
  162. $translation[$key]["channalinfo"]=false;
  163. }
  164. }
  165. //查询路径
  166. $para_path=_get_para_path($bookId,$para);
  167. $output[]=array("id"=>$id,
  168. "palitext"=>$palitext,
  169. "pali_sent_id"=>$pali_text_id,
  170. "tran"=>$tran,
  171. "translation"=>$translation,
  172. "ref"=>$para_path,
  173. "tran_count"=>$tran_count,
  174. "book"=>$bookId,
  175. "para"=>$para,
  176. "begin"=>$begin,
  177. "end"=>$end,
  178. "sim"=>$pali_sim
  179. );
  180. }
  181. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  182. ?>