2
0

note.php 11 KB

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