2
0

get_para1.php 7.3 KB

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