note.php 11 KB

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