note.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <?php
  2. require_once "../path.php";
  3. require_once "../public/_pdo.php";
  4. require_once "../public/function.php";
  5. require_once "../channal/function.php";
  6. require_once "../ucenter/function.php";
  7. require_once "../usent/function.php";
  8. require_once "../pali_text/function.php";
  9. require_once "../redis/function.php";
  10. $redis = redis_connect();
  11. $_channal = new Channal();
  12. $_userinfo = new UserInfo();
  13. $_sentPr = new SentPr($redis);
  14. $_pali_text = new PaliText($redis);
  15. $_pali_book = new PaliBook($redis);
  16. $_data = array();
  17. if (isset($_POST["data"])) {
  18. $_data = json_decode($_POST["data"], true);
  19. } else {
  20. if (isset($_GET["id"])) {
  21. $id = $_GET["id"];
  22. } else {
  23. echo "error: no id";
  24. return;
  25. }
  26. if (isset($_GET["info"])) {
  27. $info = $_GET["info"];
  28. } else {
  29. echo "error: no info";
  30. return;
  31. }
  32. $_data[] = array("id" => $id, "data" => $info);
  33. }
  34. if (isset($_POST["setting"])) {
  35. $_setting = json_decode($_POST["setting"], true);
  36. } else {
  37. $_setting["lang"] = "";
  38. $_setting["channal"] = "";
  39. }
  40. $dns = "" . _FILE_DB_PALI_SENTENCE_;
  41. $db_pali_sent = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
  42. $db_pali_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  43. $dns = "" . _FILE_DB_PALI_SENTENCE_SIM_;
  44. $db_pali_sent_sim = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
  45. $db_pali_sent_sim->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  46. $dns = "" . _FILE_DB_SENTENCE_;
  47. $db_trans_sent = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
  48. $db_trans_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  49. $output = array();
  50. #查询有阅读权限的channel
  51. $channal_list = array();
  52. if (isset($_COOKIE["userid"])) {
  53. PDO_Connect( _FILE_DB_CHANNAL_);
  54. $query = "SELECT id from channal where owner = ? limit 0,100";
  55. $Fetch_my = PDO_FetchAll($query, array($_COOKIE["userid"]));
  56. foreach ($Fetch_my as $key => $value) {
  57. # code...
  58. $channal_list[] = $value["id"];
  59. }
  60. # 找协作的
  61. $Fetch_coop = array();
  62. $query = "SELECT channal_id FROM cooperation WHERE user_id = ? ";
  63. $coop_channal = PDO_FetchAll($query, array($_COOKIE["userid"]));
  64. if (count($coop_channal) > 0) {
  65. foreach ($coop_channal as $key => $value) {
  66. # code...
  67. $channal_list[] = $value["channal_id"];
  68. }
  69. }
  70. /* 创建一个填充了和params相同数量占位符的字符串 */
  71. }
  72. if (count($channal_list) > 0) {
  73. $channel_place_holders = implode(',', array_fill(0, count($channal_list), '?'));
  74. $channel_query = " OR channal IN ($channel_place_holders)";
  75. } else {
  76. $channel_query = "";
  77. }
  78. # 查询有阅读权限的channel 结束
  79. foreach ($_data as $key => $value) {
  80. # code...
  81. $id = $value["id"];
  82. $arrInfo = explode("@", $value["data"]);
  83. if (isset($arrInfo[1])) {
  84. $sentChannal = $arrInfo[1];
  85. } else {
  86. $sentChannal = "";
  87. }
  88. if (isset($arrInfo[0])) {
  89. $arrSent = str_getcsv($arrInfo[0], "-");
  90. $bookId = $arrSent[0];
  91. $para = $arrSent[1];
  92. $begin = $arrSent[2];
  93. $end = $arrSent[3];
  94. } else {
  95. $bookId = 0;
  96. $para = 0;
  97. $begin = 0;
  98. $end = 0;
  99. }
  100. $pali_sim = 0;
  101. if ($redis != false) {
  102. $result = $redis->hGet('pali://sent/' . $bookId . "_" . $para . "_" . $begin . "_" . $end,"pali");
  103. $palitext = $result;
  104. $pali_text_id = $redis->hGet('pali://sent/' . $bookId . "_" . $para . "_" . $begin . "_" . $end,"id");
  105. $pali_sim = $redis->hGet('pali://sent/' . $bookId . "_" . $para . "_" . $begin . "_" . $end,"sim_count");
  106. } else {
  107. $query = "SELECT id,html FROM 'pali_sent' WHERE book = ? AND paragraph = ? AND begin = ? AND end = ? ";
  108. $sth = $db_pali_sent->prepare($query);
  109. $sth->execute(array($bookId, $para, $begin, $end));
  110. $row = $sth->fetch(PDO::FETCH_ASSOC);
  111. if ($row) {
  112. $palitext = $row['html'];
  113. $pali_text_id = $row['id'];
  114. } else {
  115. $palitext = "";
  116. $pali_text_id = 0;
  117. }
  118. //查询相似句
  119. $query = "SELECT count FROM 'sent_sim_index' WHERE sent_id = ? ";
  120. $sth = $db_pali_sent_sim->prepare($query);
  121. $sth->execute(array($pali_text_id));
  122. $row = $sth->fetch(PDO::FETCH_ASSOC);
  123. if ($row) {
  124. $pali_sim = $row["count"]; //explode(",",$row["sim_sents"]) ;
  125. }
  126. }
  127. //find out translation 查询译文
  128. $tran = "";
  129. $translation = array();
  130. $tran_channal = array();
  131. try {
  132. if (empty($_setting["channal"])) {
  133. if ($sentChannal == "") {
  134. $query = "SELECT * FROM sentence WHERE book= ? AND paragraph= ? AND begin= ? AND end= ? AND strlen >0 and (status = 30 {$channel_query} ) order by modify_time DESC limit 0 ,1 ";
  135. $channal = "";
  136. } else {
  137. $query = "SELECT * FROM sentence WHERE book= ? AND paragraph= ? AND begin= ? AND end= ? AND strlen >0 AND channal = ? limit 0 ,1 ";
  138. }
  139. } else {
  140. $query = "SELECT * FROM sentence WHERE book= ? AND paragraph= ? AND begin= ? AND end= ? AND strlen >0 AND channal = ? limit 0 ,1 ";
  141. $channal = $_setting["channal"];
  142. }
  143. $stmt = $db_trans_sent->prepare($query);
  144. if (empty($_setting["channal"])) {
  145. #没有指定channel
  146. if ($sentChannal == "") {
  147. #句子信息也没指定channel 查找默认译文
  148. $parm = array($bookId, $para, $begin, $end);
  149. $parm = array_merge_recursive($parm, $channal_list);
  150. $stmt->execute($parm);
  151. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  152. if ($Fetch) {
  153. $tran = $Fetch["text"];
  154. $translation[] = array("id" => $Fetch["id"],
  155. "book"=>$bookId,
  156. "para"=>$para,
  157. "begin"=>$begin,
  158. "end"=>$end,
  159. "text" => $Fetch["text"],
  160. "lang" => $Fetch["language"],
  161. "channal" => $Fetch["channal"],
  162. "status" => $Fetch["status"],
  163. "editor" => $Fetch["editor"],
  164. "editor_name"=>$_userinfo->getName($Fetch["editor"]),
  165. "update_time"=>$Fetch["modify_time"]
  166. );
  167. if (!empty($Fetch["channal"])) {
  168. $tran_channal[$Fetch["channal"]] = $Fetch["channal"];
  169. }
  170. }
  171. } else {
  172. #句子信息包含channel
  173. #{{book-para-begin-end@channelid}}
  174. $stmt->execute(array($bookId, $para, $begin, $end, $sentChannal));
  175. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  176. if ($Fetch) {
  177. $tran = $Fetch["text"];
  178. $translation[] = array("id" => $Fetch["id"],
  179. "book"=>$bookId,
  180. "para"=>$para,
  181. "begin"=>$begin,
  182. "end"=>$end,
  183. "text" => $Fetch["text"],
  184. "lang" => $Fetch["language"],
  185. "channal" => $Fetch["channal"],
  186. "status" => $Fetch["status"],
  187. "editor" => $Fetch["editor"],
  188. "editor_name"=>$_userinfo->getName($Fetch["editor"]),
  189. "update_time"=>$Fetch["modify_time"]
  190. );
  191. $tran_channal[$Fetch["channal"]] = $Fetch["channal"];
  192. }
  193. }
  194. } else {
  195. #指定了channel
  196. $arrChannal = explode(",", $_setting["channal"]);
  197. foreach ($arrChannal as $key => $value) {
  198. # code...
  199. $stmt->execute(array($bookId, $para, $begin, $end, $value));
  200. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  201. if ($Fetch) {
  202. $translation[] = array("id" => $Fetch["id"],
  203. "book"=>$bookId,
  204. "para"=>$para,
  205. "begin"=>$begin,
  206. "end"=>$end,
  207. "text" => $Fetch["text"],
  208. "lang" => $Fetch["language"],
  209. "channal" => $value,
  210. "status" => $Fetch["status"],
  211. "editor" => $Fetch["editor"],
  212. "editor_name"=>$_userinfo->getName($Fetch["editor"]),
  213. "update_time"=>$Fetch["modify_time"]
  214. );
  215. } else {
  216. $translation[] = array("id" => "",
  217. "book"=>$bookId,
  218. "para"=>$para,
  219. "begin"=>$begin,
  220. "end"=>$end,
  221. "text" => "",
  222. "lang" => "",
  223. "channal" => $value,
  224. "status" => 0,
  225. "editor" => false,
  226. "editor_name"=>false,
  227. "update_time"=>false
  228. );
  229. }
  230. $tran_channal[$value] = $value;
  231. }
  232. }
  233. $tran_count = 1;
  234. } catch (Exception $e) {
  235. $tran = $e->getMessage();
  236. //echo 'Caught exception: ', $e->getMessage(), "\n";
  237. }
  238. foreach ($tran_channal as $key => $value) {
  239. # code...
  240. $tran_channal[$key] = $_channal->getChannal($key);
  241. $tran_channal[$key]["mypower"] = $_channal->getPower($key);
  242. }
  243. foreach ($translation as $key => $value) {
  244. # code...
  245. if (!empty($value["channal"])) {
  246. $translation[$key]["channalinfo"] = $tran_channal[$value["channal"]];
  247. $translation[$key]["mypower"] = $tran_channal[$value["channal"]]["mypower"];
  248. $translation[$key]["status"] = $tran_channal[$value["channal"]]["status"];
  249. #查询句子pr
  250. $translation[$key]["pr_new"]=$_sentPr->getNewPrNumber($value["book"],$value["para"],$value["begin"],$value["end"],$value["channal"]);
  251. $translation[$key]["pr_all"]=$_sentPr->getAllPrNumber($value["book"],$value["para"],$value["begin"],$value["end"],$value["channal"]);
  252. } else {
  253. $translation[$key]["channalinfo"] = false;
  254. }
  255. }
  256. //查询路径
  257. $arrPath = $_pali_text->getPath($bookId, $para);
  258. if(count($arrPath)>0){
  259. $ref = $_pali_text->getPathHtml($arrPath);
  260. $pathTopLevel = $arrPath[count($arrPath)-1];
  261. $bookTitle = $_pali_book->getBookTitle($pathTopLevel["book"],$pathTopLevel["para"]);
  262. }
  263. else{
  264. $ref="";
  265. $bookTitle="";
  266. }
  267. //$para_path = _get_para_path($bookId, $para);
  268. $output[] = array("id" => $id,
  269. "palitext" => $palitext,
  270. "pali_sent_id" => $pali_text_id,
  271. "tran" => $tran,
  272. "translation" => $translation,
  273. "ref" => $ref,
  274. "booktitle"=>$bookTitle,
  275. "tran_count" => $tran_count,
  276. "book" => $bookId,
  277. "para" => $para,
  278. "begin" => $begin,
  279. "end" => $end,
  280. "sim" => $pali_sim,
  281. );
  282. }
  283. echo json_encode($output, JSON_UNESCAPED_UNICODE);