get.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /*
  3. 获取句子译文
  4. */
  5. require_once "../config.php";
  6. require_once "../public/_pdo.php";
  7. require_once "../public/function.php";
  8. require_once "../channal/function.php";
  9. require_once "../redis/function.php";
  10. require_once "../ucenter/function.php";
  11. require_once "../share/function.php";
  12. $redis = redis_connect();
  13. #查询有阅读权限的channel
  14. $channal_list = array();
  15. if (isset($_COOKIE["userid"])) {
  16. PDO_Connect(_FILE_DB_CHANNAL_,_DB_USERNAME_,_DB_PASSWORD_);
  17. $query = "SELECT uid from "._TABLE_CHANNEL_." where owner_uid = ? limit 100";
  18. $Fetch_my = PDO_FetchAll($query, array($_COOKIE["user_uid"]));
  19. foreach ($Fetch_my as $key => $value) {
  20. # code...
  21. $channal_list[] = $value["uid"];
  22. }
  23. # 找协作的
  24. $coop_channal = share_res_list_get($_COOKIE["userid"],2);
  25. foreach ($coop_channal as $key => $value) {
  26. # code...
  27. $channal_list[] = $value["res_id"];
  28. }
  29. }
  30. if (count($channal_list) > 0) {
  31. $channel_place_holders = implode(',', array_fill(0, count($channal_list), '?'));
  32. $channel_query = " OR channel_uid IN ($channel_place_holders)";
  33. } else {
  34. $channel_query = "";
  35. }
  36. # 查询有阅读权限的channel 结束
  37. $dbh = new PDO(_FILE_DB_SENTENCE_, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
  38. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  39. /* 开始一个事务,关闭自动提交 */
  40. if (isset($_GET["sentences"])) {
  41. #查询句子编号列表
  42. $arrSent = explode(",", $_GET["sentences"]);
  43. /* 创建一个填充了和params相同数量占位符的字符串 */
  44. $place_holders = implode(',', array_fill(0, count($arrSent), '?'));
  45. $query = "SELECT * FROM "._TABLE_SENTENCE_." WHERE uid IN ($place_holders) and (status = 30 {$channel_query} )";
  46. $stmt = $dbh->prepare($query);
  47. $stmt->execute($arrSent);
  48. } else {
  49. $book = $_GET["book"];
  50. if(isset($_GET["par"])){
  51. $para = $_GET["par"];
  52. }
  53. if(isset($_GET["para"])){
  54. $para = $_GET["para"];
  55. }
  56. $begin = $_GET["begin"];
  57. $end = $_GET["end"];
  58. if(isset($_GET["type"])){
  59. $type = $_GET["type"];
  60. }else{
  61. $type = "translation";
  62. }
  63. $query = "SELECT sent.uid as id,
  64. sent.parent_uid as parent,
  65. sent.block_uid as block_id,
  66. sent.channel_uid as channal,
  67. sent.book_id as book,
  68. sent.paragraph,
  69. sent.word_start as begin,
  70. sent.word_end as end,
  71. sent.author,
  72. sent.editor_uid as editor,
  73. sent.content as text,
  74. sent.language,
  75. sent.version as ver,
  76. sent.status,
  77. sent.strlen,
  78. sent.modify_time,
  79. channel.type
  80. FROM "._TABLE_SENTENCE_. " as sent LEFT JOIN "._TABLE_CHANNEL_." as channel ON uuid(sent.channel_uid)=channel.uid WHERE (channel.type= ? AND sent.book_id = ? AND sent.paragraph = ? AND sent.word_start = ? AND sent.word_end = ? and sent.strlen >0 and (sent.status = 30 {$channel_query} ) ) order by sent.modify_time DESC ";
  81. $stmt = $dbh->prepare($query);
  82. $parm = array($type,$book, $para, $begin, $end);
  83. $parm = array_merge_recursive($parm, $channal_list);
  84. $stmt->execute($parm);
  85. }
  86. $Fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
  87. $channel_info = new Channal($redis);
  88. $user_info = new UserInfo();
  89. foreach ($Fetch as $key => $value) {
  90. # code...
  91. $Fetch[$key]["para"]=$value["paragraph"];
  92. $channel = $channel_info->getChannal($value["channal"]);
  93. if ($channel) {
  94. $Fetch[$key]["mypower"] = $channel_info->getPower($value["channal"]);
  95. $Fetch[$key]["c_name"] = $channel["name"];
  96. $Fetch[$key]["c_owner"] = $user_info->getName($channel["owner_uid"]);
  97. $Fetch[$key]["channalinfo"] = $channel;
  98. }
  99. else{
  100. $Fetch[$key]["c_name"] = "unkow";
  101. $Fetch[$key]["c_owner"] = "unkow";
  102. }
  103. $Fetch[$key]["editor_name"]=$user_info->getName($value["editor"]);
  104. $Fetch[$key]["update_time"]=$value["modify_time"];
  105. }
  106. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);