get_para1.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. include("../log/pref_log.php");
  3. require_once "../public/_pdo.php";
  4. require_once "../config.php";
  5. require_once "../redis/function.php";
  6. require_once "../db/pali_sent.php";
  7. require_once "../db/pali_sim_sent.php";
  8. $mRedis = redis_connect();
  9. define("_MAX_CHAPTER_LEN_", 20000);
  10. if (isset($_GET["book"])) {
  11. $_book = $_GET["book"];
  12. } else {
  13. $_book = 0;
  14. }
  15. if (isset($_GET["par"])) {
  16. $_para = $_GET["par"];
  17. } else {
  18. $_para = 0;
  19. }
  20. if (isset($_GET["start"])) {
  21. $_start = $_GET["start"];
  22. }
  23. if (isset($_GET["begin"])) {
  24. $_start = $_GET["begin"];
  25. }
  26. if (isset($_GET["end"])) {
  27. $_end = $_GET["end"];
  28. }
  29. $_view = $_GET["view"];
  30. $output["toc"] = array();
  31. $output["sentences"] = array();
  32. $output["head"] = 0;
  33. $output["title"]="";
  34. $output["subtitle"]="";
  35. $output["summary"]="";
  36. $output["content"]="";
  37. $output["owner"]="";
  38. $output["username"]=array("username"=>"","nickname"=>"");
  39. $output["status"]="";
  40. if ($_view == "sent") {
  41. $output["content"] = "{{". $_book . "-" . $_para . "-". $_start . "-" . $_end . "}}";
  42. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  43. exit;
  44. }
  45. if ($_view == "simsent" || $_view == "sim") {
  46. $mPaliSent = new PaliSentence($mRedis);
  47. $mPaliSim = new PaliSimSentence($mRedis);
  48. if(!isset($_GET["id"])){
  49. $id = $mPaliSent->getId($_book,$_para,$_begin,$_end);
  50. }
  51. else{
  52. $id = $_GET["id"];
  53. }
  54. {
  55. $sent_list[] = $mPaliSent->getInfo($id);
  56. $arrList = $mPaliSim->getSimById($id);
  57. if($arrList){
  58. foreach ($arrList as $key => $value) {
  59. # code...
  60. $sent_list = $mPaliSent->getInfo($value["id"]);
  61. $output["content"] .= "{{". $sent_list["book"] . "-" . $sent_list["paragraph"] . "-". $sent_list["begin"] . "-" . $sent_list["end"] . "}}";
  62. }
  63. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  64. }
  65. }
  66. exit;
  67. }
  68. $paraBegin=0;
  69. $paraEnd=0;
  70. PDO_Connect(_FILE_DB_PALITEXT_);
  71. $query = "SELECT level , parent, chapter_len,chapter_strlen FROM "._TABLE_PALI_TEXT_." WHERE book= ? AND paragraph= ?";
  72. $FetchParInfo = PDO_FetchRow($query, array($_book, $_para));
  73. if ($FetchParInfo) {
  74. switch ($_view) {
  75. case 'chapter':
  76. # code...
  77. if($FetchParInfo["level"]>0 && $FetchParInfo["level"]<8){
  78. //是标题
  79. $paraBegin = $_para;
  80. $paraEnd = $_para + $FetchParInfo["chapter_len"] - 1;
  81. }
  82. else{
  83. #不是标题,加载所在段落
  84. $paraBegin = $FetchParInfo["parent"];
  85. $query = "SELECT level , parent, chapter_len,chapter_strlen FROM "._TABLE_PALI_TEXT_." WHERE book= ? AND paragraph= ?";
  86. $FetchParInfo = PDO_FetchRow($query, array($_book, $paraBegin));
  87. $paraEnd = $paraBegin + $FetchParInfo["chapter_len"] - 1;
  88. }
  89. break;
  90. case 'para':
  91. $paraBegin = $_para;
  92. $paraEnd = $_para;
  93. # code...
  94. break;
  95. default:
  96. # code...
  97. $paraBegin = $_para;
  98. $paraEnd = $_para;
  99. break;
  100. }
  101. //获取下级目录
  102. $query = "SELECT level,paragraph,toc FROM "._TABLE_PALI_TEXT_." WHERE book= ? AND (paragraph BETWEEN ?AND ? ) AND level < 8 ";
  103. $toc = PDO_FetchAll($query, array($_book, $paraBegin, $paraEnd));
  104. if(count($toc)>0){
  105. $output["title"] = $toc[0]["toc"];
  106. }
  107. if(count($toc)>1){
  108. $currLevel = $toc[0]["level"];
  109. $ulLevel = 0;
  110. foreach ($toc as $key => $value) {
  111. # code...
  112. if($value["level"] > $currLevel ){
  113. $ulLevel++;
  114. }
  115. else if($value["level"] < $currLevel ){
  116. $ulLevel--;
  117. }
  118. $currLevel = $value["level"];
  119. for ($i=0; $i < $ulLevel; $i++) {
  120. # code...
  121. $output["content"] .= " ";
  122. }
  123. $output["content"] .= "- [{$value["toc"]}](../article/index.php?view=chapter&book={$_book}&par={$value["paragraph"]})\n";
  124. }
  125. }
  126. if ($FetchParInfo["chapter_strlen"] > _MAX_CHAPTER_LEN_ && $_view === "chapter" && count($toc) > 1) {
  127. #文档过大,只加载目录
  128. if ($toc[1]["paragraph"] - $_para > 1) {
  129. # 中间有间隔
  130. $paraBegin = $_para;
  131. $paraEnd = $toc[1]["paragraph"] - 1;
  132. $output["head"] = 1;
  133. } else {
  134. #中间无间隔
  135. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  136. exit;
  137. }
  138. }
  139. PDO_Connect(_FILE_DB_PALI_SENTENCE_);
  140. $query = "SELECT book,paragraph, word_begin as begin, word_end as end FROM "._TABLE_PALI_SENT_." WHERE book= ? AND (paragraph BETWEEN ? AND ? ) ";
  141. $sent_list = PDO_FetchAll($query, array($_book, $paraBegin, $paraEnd));
  142. $iCurrPara=0;
  143. $output["sent_list"] = $sent_list;
  144. foreach ($sent_list as $key => $value) {
  145. # code...
  146. if($value["paragraph"]!==$iCurrPara){
  147. $output["content"] .= "\n\n";
  148. $iCurrPara = $value["paragraph"];
  149. if($_view=="chapter" && $paraBegin != $_para){
  150. if($_para==$value["paragraph"]){
  151. $output["content"] .= "<div id='para_focus' class='focus'>\n\n";
  152. }
  153. }
  154. if($_view=="chapter" && $paraBegin!=$_para){
  155. if($_para==$value["paragraph"]-1){
  156. $output["content"] .= "\n\n</div>";
  157. }
  158. }
  159. $output["content"] .= "<div class='page_number' page='{$iCurrPara}'>{$iCurrPara}</div>\n\n";
  160. }
  161. $output["content"] .= "{{". $value["book"] . "-" . $value["paragraph"] . "-". $value["begin"] . "-" . $value["end"] . "}}";
  162. }
  163. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  164. } else {
  165. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  166. }
  167. PrefLog();