get_para1.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. require_once "../config.php";
  3. require_once "../log/pref_log.php";
  4. require_once "../public/_pdo.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. if (isset($_GET["channel"])) {
  30. $_channel = $_GET["channel"];
  31. }
  32. $_view = $_GET["view"];
  33. $output["toc"] = array();
  34. $output["sentences"] = array();
  35. $output["head"] = 0;
  36. $output["title"]="";
  37. $output["subtitle"]="";
  38. $output["summary"]="";
  39. $output["content"]="";
  40. $output["owner"]="";
  41. $output["username"]=array("username"=>"","nickname"=>"");
  42. $output["status"]="";
  43. $dns = _FILE_DB_PALI_TOC_;
  44. $dbh_toc = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
  45. $dbh_toc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  46. if ($_view == "sent") {
  47. $output["content"] = "{{". $_book . "-" . $_para . "-". $_start . "-" . $_end . "}}";
  48. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  49. exit;
  50. }
  51. if ($_view == "simsent" || $_view == "sim") {
  52. $mPaliSent = new PaliSentence($mRedis);
  53. $mPaliSim = new PaliSimSentence($mRedis);
  54. if(!isset($_GET["id"])){
  55. $id = $mPaliSent->getId($_book,$_para,$_begin,$_end);
  56. }
  57. else{
  58. $id = $_GET["id"];
  59. }
  60. {
  61. $sent_list[] = $mPaliSent->getInfo($id);
  62. $arrList = $mPaliSim->getSimById($id);
  63. if($arrList){
  64. foreach ($arrList as $key => $value) {
  65. # code...
  66. $sent_list = $mPaliSent->getInfo($value["id"]);
  67. $output["content"] .= "{{". $sent_list["book"] . "-" . $sent_list["paragraph"] . "-". $sent_list["begin"] . "-" . $sent_list["end"] . "}}";
  68. }
  69. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  70. }
  71. }
  72. exit;
  73. }
  74. $paraBegin=0;
  75. $paraEnd=0;
  76. PDO_Connect(_FILE_DB_PALITEXT_);
  77. $query = "SELECT level , parent, chapter_len,chapter_strlen FROM "._TABLE_PALI_TEXT_." WHERE book= ? AND paragraph= ? order by paragraph asc";
  78. $FetchParInfo = PDO_FetchRow($query, array($_book, $_para));
  79. if ($FetchParInfo) {
  80. switch ($_view) {
  81. case 'chapter':
  82. # code...
  83. if($FetchParInfo["level"]>0 && $FetchParInfo["level"]<8){
  84. //是标题
  85. $paraBegin = $_para;
  86. $paraEnd = $_para + $FetchParInfo["chapter_len"] - 1;
  87. }
  88. else{
  89. #不是标题,加载所在段落
  90. $paraBegin = $FetchParInfo["parent"];
  91. $query = "SELECT level , parent, chapter_len,chapter_strlen FROM "._TABLE_PALI_TEXT_." WHERE book= ? AND paragraph= ? order by paragraph asc";
  92. $FetchParInfo = PDO_FetchRow($query, array($_book, $paraBegin));
  93. $paraEnd = $paraBegin + $FetchParInfo["chapter_len"] - 1;
  94. }
  95. break;
  96. case 'para':
  97. $paraBegin = $_para;
  98. $paraEnd = $_para;
  99. # code...
  100. break;
  101. default:
  102. # code...
  103. $paraBegin = $_para;
  104. $paraEnd = $_para;
  105. break;
  106. }
  107. //获取下级目录
  108. $query = "SELECT level,paragraph,toc FROM "._TABLE_PALI_TEXT_." WHERE book= ? AND (paragraph BETWEEN ?AND ? ) AND level < 8 order by paragraph asc";
  109. $toc = PDO_FetchAll($query, array($_book, $paraBegin, $paraEnd));
  110. if(count($toc)>0){
  111. $output["title"] = $toc[0]["toc"];
  112. }
  113. /*
  114. 目录
  115. */
  116. if(isset($_channel)){
  117. $firstChannel = explode(',',$_channel)[0];
  118. }
  119. $sTocOutput = "\n\n";
  120. if(count($toc)>1){
  121. $currLevel = $toc[0]["level"];
  122. $ulLevel = 0;
  123. $minLevel = 8;
  124. foreach ($toc as $key => $value) {
  125. if($value["level"] < $minLevel ){
  126. $minLevel = $value["level"];
  127. }
  128. }
  129. foreach ($toc as $key => $value) {
  130. # code...
  131. if(empty($value["toc"])){
  132. $sToc = "unnamed";
  133. }else{
  134. $sToc = $value["toc"];
  135. }
  136. $sToc = str_replace(['[',']'],[' [','] '],$sToc);
  137. if($value["level"] > $currLevel ){
  138. $ulLevel++;
  139. }
  140. else if($value["level"] < $currLevel ){
  141. $ulLevel--;
  142. }
  143. $currLevel = $value["level"];
  144. $space = "";
  145. for ($i=$minLevel; $i < $currLevel; $i++) {
  146. # code...
  147. $space .= " ";
  148. }
  149. //目录进度
  150. if(isset($firstChannel)){
  151. $query = "SELECT title , progress FROM "._TABLE_PROGRESS_CHAPTER_." WHERE book= ? AND para= ? AND channel_id=?";
  152. $sth_title = $dbh_toc->prepare($query);
  153. $sth_title->execute(array($_book, $value["paragraph"], $firstChannel));
  154. $trans_title = $sth_title->fetch(PDO::FETCH_ASSOC);
  155. if ($trans_title) {
  156. if(!empty($trans_title['title'])){
  157. $sToc = $trans_title['title'];
  158. }
  159. $progress = "<".sprintf('%d',$trans_title['progress']*100)."%";
  160. }else{
  161. $progress = "";
  162. }
  163. }
  164. $sTocOutput .= $space . "- [{$sToc}](../article/index.php?view=chapter&book={$_book}&par={$value["paragraph"]}){$progress}\n";
  165. }
  166. }
  167. $sTocOutput .= "\n\n";
  168. if ($FetchParInfo["chapter_strlen"] > _MAX_CHAPTER_LEN_ && $_view === "chapter" && count($toc) > 1) {
  169. #文档过大,只加载目录
  170. if ($toc[1]["paragraph"] - $_para > 1) {
  171. # 中间有间隔
  172. $paraBegin = $_para;
  173. $paraEnd = $toc[1]["paragraph"] - 1;
  174. $output["head"] = 1;
  175. } else {
  176. #中间无间隔
  177. $output["content"] .= $sTocOutput;
  178. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  179. exit;
  180. }
  181. }
  182. PDO_Connect(_FILE_DB_PALI_SENTENCE_);
  183. $query = "SELECT book,paragraph, word_begin as begin, word_end as end FROM "._TABLE_PALI_SENT_." WHERE book= ? AND (paragraph BETWEEN ? AND ? ) order by paragraph,word_begin asc";
  184. $sent_list = PDO_FetchAll($query, array($_book, $paraBegin, $paraEnd));
  185. $iCurrPara=0;
  186. $output["sent_list"] = $sent_list;
  187. foreach ($sent_list as $key => $value) {
  188. # code...
  189. if($value["paragraph"]!==$iCurrPara){
  190. $output["content"] .= "\n\n";
  191. $iCurrPara = $value["paragraph"];
  192. if($_view=="chapter" && $paraBegin != $_para){
  193. if($_para==$value["paragraph"]){
  194. $output["content"] .= "<div id='para_focus' class='focus'>\n\n";
  195. }
  196. }
  197. if($_view=="chapter" && $paraBegin!=$_para){
  198. if($_para==$value["paragraph"]-1){
  199. $output["content"] .= "\n\n</div>";
  200. }
  201. }
  202. $output["content"] .= "<div class='page_number' page='{$iCurrPara}'>{$iCurrPara}</div>\n\n";
  203. }
  204. $output["content"] .= "{{". $value["book"] . "-" . $value["paragraph"] . "-". $value["begin"] . "-" . $value["end"] . "}}";
  205. }
  206. $output["content"] .= $sTocOutput;
  207. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  208. } else {
  209. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  210. }
  211. PrefLog();