get_para1.php 5.1 KB

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