pali_text.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. require_once "../path.php";
  3. require_once "../db/table.php";
  4. class PaliText extends Table
  5. {
  6. function __construct($redis=false) {
  7. parent::__construct(_FILE_DB_PALITEXT_, "pali_text", "", "",$redis);
  8. }
  9. public function index(){
  10. $view = $_GET["view"];
  11. switch ($view) {
  12. case 'toc':
  13. # code...
  14. $book = $_GET["book"];
  15. $par = $_GET["par"];
  16. do {
  17. # code...
  18. $parent = $this->medoo->get(
  19. $this->table,
  20. ["parent","paragraph","chapter_len","next_chapter","prev_chapter"],
  21. ["book"=>$book,"paragraph"=>$par]
  22. );
  23. $par = $parent["parent"];
  24. } while ($parent["parent"] > -1);
  25. $this->_index(["book","paragraph","level","toc","next_chapter","prev_chapter","parent"],["level[<]"=>8,"book"=>$book,"paragraph[>]"=>$parent["paragraph"],"paragraph[<]"=>$parent["paragraph"]+$parent["chapter_len"]]);
  26. echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
  27. break;
  28. default:
  29. # code...
  30. break;
  31. }
  32. }
  33. public function show(){
  34. $output = $this->medoo->get(
  35. $this->table,
  36. ["book","paragraph","level","toc","text"],
  37. ["book"=>$_GET["book"],"paragraph"=>$_GET["par"]]
  38. );
  39. if($this->medoo->error){
  40. $this->result["ok"]=false;
  41. $this->result["message"]=$this->medoo->error;
  42. }else{
  43. $this->result["data"] = $output;
  44. }
  45. echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
  46. }
  47. public function getTitle($book,$para)
  48. {
  49. if (isset($book) && isset($para)) {
  50. if($this->redis!==false){
  51. $title = $this->redis->hGet("para_title://pali","{$book}-{$para}");
  52. if($title!==FALSE){
  53. return $title;
  54. }
  55. }
  56. $title="";
  57. $query = "select * from pali_text where book = ? and paragraph = ?";
  58. $stmt = $this->dbh->prepare($query);
  59. $stmt->execute(array($book,$para));
  60. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  61. if ($result) {
  62. if($result["level"]>0 && $result["level"]<8){
  63. $title= $result["toc"];
  64. }
  65. else{
  66. $query = "select * from pali_text where book = ? and paragraph = ?";
  67. $stmt = $this->dbh->prepare($query);
  68. $stmt->execute(array($book,$result["parent"]));
  69. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  70. if ($result) {
  71. $title= $result["toc"];
  72. }
  73. else{
  74. $title= "";
  75. }
  76. }
  77. } else {
  78. $title= "";
  79. }
  80. if($this->redis){
  81. $this->redis->hSet("para_title://pali","{$book}-{$para}",$title);
  82. }
  83. return $title;
  84. } else {
  85. $title= "";
  86. }
  87. }
  88. }
  89. ?>