note.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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_,_DB_USERNAME_,_DB_PASSWORD_);
  56. $query = "SELECT uid from "._TABLE_CHANNEL_." where owner_uid = ? limit 100";
  57. $Fetch_my = PDO_FetchAll($query, array($_COOKIE["user_uid"]));
  58. foreach ($Fetch_my as $key => $value) {
  59. # code...
  60. $channal_list[] = $value["uid"];
  61. }
  62. # 找协作的
  63. $coop_channal = share_res_list_get($_COOKIE["user_uid"],2);
  64. foreach ($coop_channal as $key => $value) {
  65. # code...
  66. $channal_list[] = $value["res_id"];
  67. }
  68. /* 创建一个填充了和params相同数量占位符的字符串 */
  69. }
  70. if (count($channal_list) > 0) {
  71. $channel_place_holders = implode(',', array_fill(0, count($channal_list), '?'));
  72. $channel_query = " OR channel_uid IN ($channel_place_holders)";
  73. } else {
  74. $channel_query = "";
  75. }
  76. # 查询有阅读权限的channel 结束
  77. $custom_book = new CustomBookSentence($redis);
  78. foreach ($_data as $key => $value) {
  79. # code...
  80. $id = $value["id"];
  81. $arrInfo = explode("@", $value["data"]);
  82. if (isset($arrInfo[1])) {
  83. $sentChannal = $arrInfo[1];
  84. } else {
  85. $sentChannal = "";
  86. }
  87. if (isset($arrInfo[0])) {
  88. $arrSent = str_getcsv($arrInfo[0], "-");
  89. $bookId = $arrSent[0];
  90. $para = $arrSent[1];
  91. $begin = $arrSent[2];
  92. $end = $arrSent[3];
  93. } else {
  94. $bookId = 0;
  95. $para = 0;
  96. $begin = 0;
  97. $end = 0;
  98. }
  99. $pali_sim = 0;
  100. if ($redis != false) {
  101. if($bookId<1000){
  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. }
  107. else{
  108. $palitext = $custom_book->getText($bookId,$para,$begin,$end);
  109. $pali_text_id = 0;
  110. }
  111. } else {
  112. $query = "SELECT id,html FROM 'pali_sent' WHERE book = ? AND paragraph = ? AND begin = ? AND end = ? ";
  113. $sth = $db_pali_sent->prepare($query);
  114. $sth->execute(array($bookId, $para, $begin, $end));
  115. $row = $sth->fetch(PDO::FETCH_ASSOC);
  116. if ($row) {
  117. $palitext = $row['html'];
  118. $pali_text_id = $row['id'];
  119. } else {
  120. $palitext = "";
  121. $pali_text_id = 0;
  122. }
  123. //查询相似句
  124. $query = "SELECT count FROM "._TABLE_SENT_SIM_INDEX_." WHERE sent_id = ? ";
  125. $sth = $db_pali_sent_sim->prepare($query);
  126. $sth->execute(array($pali_text_id));
  127. $row = $sth->fetch(PDO::FETCH_ASSOC);
  128. if ($row) {
  129. $pali_sim = $row["count"]; //explode(",",$row["sim_sents"]) ;
  130. }
  131. }
  132. //find out translation 查询译文
  133. $tran = "";
  134. $translation = array();
  135. $tran_channal = array();
  136. try {
  137. $query_col = "uid,channel_uid,content,language,status,editor_uid,modify_time";
  138. if (empty($_setting["channal"])) {
  139. if ($sentChannal == "") {
  140. $query = "SELECT {$query_col} FROM "._TABLE_SENTENCE_." WHERE book_id= ? AND paragraph= ? AND word_start= ? AND word_end= ? AND strlen >0 and (status = 30 {$channel_query} ) order by modify_time DESC limit 1 ";
  141. $channal = "";
  142. } else {
  143. $query = "SELECT {$query_col} FROM "._TABLE_SENTENCE_." WHERE book_id= ? AND paragraph= ? AND word_start= ? AND word_end= ? AND strlen >0 AND channel_uid = ? limit 1 ";
  144. }
  145. } else {
  146. $query = "SELECT {$query_col} FROM "._TABLE_SENTENCE_." WHERE book_id= ? AND paragraph= ? AND word_start= ? AND word_end= ? AND strlen >0 AND channel_uid = ? limit 1 ";
  147. $channal = $_setting["channal"];
  148. }
  149. $stmt = $db_trans_sent->prepare($query);
  150. if (empty($_setting["channal"])) {
  151. #没有指定channel
  152. if ($sentChannal == "") {
  153. #句子信息也没指定channel 查找默认译文
  154. $parm = array($bookId, $para, $begin, $end);
  155. $parm = array_merge_recursive($parm, $channal_list);
  156. $stmt->execute($parm);
  157. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  158. if ($Fetch) {
  159. $tran = $Fetch["content"];
  160. $translation[] = array("id" => $Fetch["uid"],
  161. "book"=>$bookId,
  162. "para"=>$para,
  163. "begin"=>$begin,
  164. "end"=>$end,
  165. "text" => $Fetch["content"],
  166. "lang" => $Fetch["language"],
  167. "channal" => $Fetch["channel_uid"],
  168. "status" => $Fetch["status"],
  169. "editor" => $Fetch["editor_uid"],
  170. "editor_name"=>$_userinfo->getName($Fetch["editor_uid"]),
  171. "update_time"=>$Fetch["modify_time"]
  172. );
  173. if (!empty($Fetch["channel_uid"])) {
  174. $tran_channal[$Fetch["channel_uid"]] = $Fetch["channel_uid"];
  175. }
  176. }
  177. } else {
  178. #句子信息包含channel
  179. #{{book-para-begin-end@channelid}}
  180. $stmt->execute(array($bookId, $para, $begin, $end, $sentChannal));
  181. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  182. if ($Fetch) {
  183. $tran = $Fetch["content"];
  184. $translation[] = array("id" => $Fetch["uid"],
  185. "book"=>$bookId,
  186. "para"=>$para,
  187. "begin"=>$begin,
  188. "end"=>$end,
  189. "text" => $Fetch["content"],
  190. "lang" => $Fetch["language"],
  191. "channal" => $Fetch["channel_uid"],
  192. "status" => $Fetch["status"],
  193. "editor" => $Fetch["editor_uid"],
  194. "editor_name"=>$_userinfo->getName($Fetch["editor_uid"]),
  195. "update_time"=>$Fetch["modify_time"]
  196. );
  197. $tran_channal[$Fetch["channel_uid"]] = $Fetch["channel_uid"];
  198. }
  199. }
  200. } else {
  201. #指定了channel
  202. $arrChannal = explode(",", $_setting["channal"]);
  203. foreach ($arrChannal as $key => $value) {
  204. # code...
  205. $stmt->execute(array($bookId, $para, $begin, $end, $value));
  206. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  207. if ($Fetch) {
  208. $translation[] = array("id" => $Fetch["uid"],
  209. "book"=>$bookId,
  210. "para"=>$para,
  211. "begin"=>$begin,
  212. "end"=>$end,
  213. "text" => $Fetch["content"],
  214. "lang" => $Fetch["language"],
  215. "channal" => $value,
  216. "status" => $Fetch["status"],
  217. "editor" => $Fetch["editor_uid"],
  218. "editor_name"=>$_userinfo->getName($Fetch["editor_uid"]),
  219. "update_time"=>$Fetch["modify_time"]
  220. );
  221. } else {
  222. $translation[] = array("id" => "",
  223. "book"=>$bookId,
  224. "para"=>$para,
  225. "begin"=>$begin,
  226. "end"=>$end,
  227. "text" => "",
  228. "lang" => "",
  229. "channal" => $value,
  230. "status" => 0,
  231. "editor" => false,
  232. "editor_name"=>false,
  233. "update_time"=>false
  234. );
  235. }
  236. $tran_channal[$value] = $value;
  237. }
  238. }
  239. $tran_count = 1;
  240. } catch (Exception $e) {
  241. $tran = $e->getMessage();
  242. //echo 'Caught exception: ', $e->getMessage(), "\n";
  243. }
  244. foreach ($tran_channal as $key => $value) {
  245. # code...
  246. $tran_channal[$key] = $_channal->getChannal($key);
  247. $tran_channal[$key]["mypower"] = $_channal->getPower($key);
  248. }
  249. foreach ($translation as $key => $value) {
  250. # code...
  251. if (!empty($value["channal"])) {
  252. $translation[$key]["channalinfo"] = $tran_channal[$value["channal"]];
  253. $translation[$key]["mypower"] = $tran_channal[$value["channal"]]["mypower"];
  254. $translation[$key]["status"] = $tran_channal[$value["channal"]]["status"];
  255. #查询句子pr
  256. $translation[$key]["pr_new"]=$_sentPr->getNewPrNumber($value["book"],$value["para"],$value["begin"],$value["end"],$value["channal"]);
  257. $translation[$key]["pr_all"]=$_sentPr->getAllPrNumber($value["book"],$value["para"],$value["begin"],$value["end"],$value["channal"]);
  258. } else {
  259. $translation[$key]["channalinfo"] = false;
  260. }
  261. }
  262. //查询路径
  263. $arrPath = $_pali_text->getPath($bookId, $para);
  264. if(count($arrPath)>0){
  265. $ref = $_pali_text->getPathHtml($arrPath);
  266. $pathTopLevel = $arrPath[count($arrPath)-1];
  267. $bookTitle = $_pali_book->getBookTitle($pathTopLevel["book"],$pathTopLevel["para"]);
  268. }
  269. else{
  270. $ref="";
  271. $bookTitle="";
  272. }
  273. //$para_path = _get_para_path($bookId, $para);
  274. $output[] = array("id" => $id,
  275. "palitext" => $palitext,
  276. "pali_sent_id" => $pali_text_id,
  277. "tran" => $tran,
  278. "translation" => $translation,
  279. "ref" => $ref,
  280. "booktitle"=>$bookTitle,
  281. "tran_count" => $tran_count,
  282. "book" => $bookId,
  283. "para" => $para,
  284. "begin" => $begin,
  285. "end" => $end,
  286. "sim" => $pali_sim,
  287. );
  288. }
  289. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  290. PrefLog();