bold_search.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <?php
  2. //查询参考字典
  3. require_once '../config.php';
  4. require_once '../public/casesuf.inc';
  5. require_once '../public/union.inc';
  6. require_once "../public/_pdo.php";
  7. require_once "../public/function.php";
  8. require_once "../public/load_lang.php";
  9. _load_book_index();
  10. $op = $_GET["op"];
  11. $word = mb_strtolower($_GET["word"], 'UTF-8');
  12. $org_word = $word;
  13. $count_return = 0;
  14. global $PDO;
  15. switch ($op) {
  16. case "pre": //预查询
  17. PDO_Connect(_FILE_DB_REF_INDEX_);
  18. echo "<div>";
  19. $query = "SELECT word,count from dict where \"eword\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " limit 20";
  20. $Fetch = PDO_FetchAll($query);
  21. $iFetch = count($Fetch);
  22. if ($iFetch > 0) {
  23. for ($i = 0; $i < $iFetch; $i++) {
  24. $word = $Fetch[$i]["word"];
  25. $count = $Fetch[$i]["count"];
  26. echo "<div class='dict_word_list'>";
  27. echo "<a href='bold.php?key={$word}'>$word-$count</a>";
  28. echo "</div>";
  29. }
  30. }
  31. echo "</div>";
  32. break;
  33. case "search":
  34. $strDictTab = "<li id=\"dt_dict\" class=\"act\" onclick=\"tab_click('dict_ref','dt_dict')\">{$_local->gui->dict}</li>";
  35. //查黑体字开始
  36. $arrBookName = json_decode(file_get_contents("../public/book_name/sc.json"));
  37. echo "<div id=\"dict_bold\" style=''>";
  38. //加语尾
  39. $arrNewWord = array();
  40. for ($row = 0; $row < count($case); $row++) {
  41. $len = mb_strlen($case[$row][0], "UTF-8");
  42. $end = mb_substr($word, 0 - $len, null, "UTF-8");
  43. if ($end == $case[$row][0]) {
  44. $newWord = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $case[$row][1];
  45. $arrNewWord[$newWord] = 1;
  46. }
  47. }
  48. //加连读词尾
  49. $arrUnWord = array();
  50. for ($row = 0; $row < count($union); $row++) {
  51. $len = mb_strlen($union[$row][0], "UTF-8");
  52. foreach ($arrNewWord as $x => $x_value) {
  53. $end = mb_substr($x, 0 - $len, null, "UTF-8");
  54. if ($end == $union[$row][0]) {
  55. $newWord = mb_substr($x, 0, mb_strlen($x, "UTF-8") - $len, "UTF-8") . $union[$row][1];
  56. $arrUnWord[$newWord] = 1;
  57. }
  58. }
  59. }
  60. //将连读词和$arrNewWord混合
  61. foreach ($arrUnWord as $x => $x_value) {
  62. $arrNewWord[$x] = 1;
  63. }
  64. if (count($arrNewWord) > 0) {
  65. $strQueryWord = "(";
  66. foreach ($arrNewWord as $x => $x_value) {
  67. $strQueryWord .= "'{$x}',";
  68. }
  69. $strQueryWord = mb_substr($strQueryWord, 0, mb_strlen($strQueryWord, "UTF-8") - 1, "UTF-8");
  70. $strQueryWord .= ")";
  71. } else {
  72. $strQueryWord = "('{$word}')";
  73. }
  74. PDO_Connect(_FILE_DB_BOLD_);
  75. //查询符合的记录数
  76. $query = "SELECT count(*) as co from "._TABLE_WORD_BOLD_." where \"word2\" in $strQueryWord";
  77. $Fetch = PDO_FetchOne($query);
  78. if ($Fetch > 0) {
  79. $strDictTab .= "<li id=\"dt_bold\" onclick=\"tab_click('dict_bold','dt_bold')\">{$_local->gui->vannana}({$Fetch})</li>";
  80. echo "{$_local->gui->search}:$word {$_local->gui->find_about}{$Fetch}{$_local->gui->result}<br />";
  81. //黑体字主显示区开始
  82. echo "<div class='dict_bold_main'>";
  83. //黑体字主显示区左侧开始
  84. echo "<div class='dict_bold_left'>";
  85. echo "<button onclick=\"dict_update_bold(0)\">" . $_local->gui->filter . "</button>";
  86. /*查找实际出现的拼写
  87. $strQueryWord中是所有可能的拼写
  88. */
  89. $realQueryWord = "(";
  90. $query = "SELECT word2,count(word) as co from "._TABLE_WORD_BOLD_." where \"word2\" in $strQueryWord group by word2 order by co DESC";
  91. $Fetch = PDO_FetchAll($query);
  92. $iFetch = count($Fetch);
  93. if ($iFetch > 0) {
  94. echo "<div>";
  95. echo "<input id='bold_all_word' type='checkbox' checked='true' value='' onclick=\"dict_bold_word_all_select()\"/>{$_local->gui->all_select}<br />";
  96. for ($i = 0; $i < $iFetch; $i++) {
  97. $realQueryWord .= "'{$Fetch[$i]["word2"]}',";
  98. echo "<input id='bold_word_{$i}' type='checkbox' checked value='{$Fetch[$i]["word2"]}' />";
  99. echo "<a onclick=\"dict_bold_word_select({$i})\">";
  100. echo $Fetch[$i]["word2"] . ":" . $Fetch[$i]["co"] . "{$_local->gui->times}<br />";
  101. echo "</a>";
  102. }
  103. $realQueryWord = mb_substr($realQueryWord, 0, mb_strlen($realQueryWord, "UTF-8") - 1, "UTF-8");
  104. $realQueryWord .= ")";
  105. echo "<input id='bold_word_count' type='hidden' value='{$iFetch}' />";
  106. echo "</div>";
  107. }
  108. //查找这些词出现在哪些书中
  109. $query = "SELECT book,count(word) as co from "._TABLE_WORD_BOLD_." where \"word2\" in $realQueryWord group by book order by co DESC";
  110. $Fetch = PDO_FetchAll($query);
  111. $iFetch = count($Fetch);
  112. if ($iFetch > 0) {
  113. echo "<div id='bold_book_list'>";
  114. echo "{$_local->gui->presented_in}{$iFetch}{$_local->gui->book}:<br />";
  115. echo "<input type='checkbox' checked='true' value='' />{$_local->gui->all_select}<br />";
  116. for ($i = 0; $i < $iFetch; $i++) {
  117. $book = $Fetch[$i]["book"];
  118. $bookname = _get_book_info($book)->title;
  119. echo "<input id='bold_book_{$i}' type='checkbox' checked value='{$book}'/>";
  120. echo "<a onclick=\"dict_bold_book_select({$i})\">";
  121. echo "《{$bookname}》:{$Fetch[$i]["co"]}{$_local->gui->times}<br />";
  122. echo "</a>";
  123. }
  124. echo "<input id='bold_book_count' type='hidden' value='{$iFetch}' />";
  125. echo "</div>";
  126. }
  127. //查找这些词出现在哪些书中结束
  128. echo "</div>";
  129. //黑体字主显示区左侧结束
  130. //黑体字主显示区右侧开始
  131. echo "<div id=\"dict_bold_right\" style='flex:7;'>";
  132. //前20条记录
  133. $query = "SELECT * from "._TABLE_WORD_BOLD_." where \"word2\" in $realQueryWord limit 20";
  134. $Fetch = PDO_FetchAll($query);
  135. $iFetch = count($Fetch);
  136. if ($iFetch > 0) {
  137. PDO_Connect(_FILE_DB_PALITEXT_);
  138. for ($i = 0; $i < $iFetch; $i++) {
  139. $paliword = $Fetch[$i]["word"];
  140. $book = $Fetch[$i]["book"];
  141. $bookInfo = _get_book_info($book);
  142. $bookname = $bookInfo->title;
  143. $bookPath = $bookInfo->c1 . ">" . $bookInfo->c2 . ">" . $bookInfo->c3;
  144. $paragraph = $Fetch[$i]["paragraph"];
  145. $base = $Fetch[$i]["base"];
  146. $pali = $Fetch[$i]["pali"];
  147. echo "<div class='dict_word'>";
  148. echo "<div class='book' ><span style='font-size:110%;font-weight:700;'>《{$bookname}》</span> <tag>$bookInfo->c1</tag> <tag>$bookInfo->c2</tag> </div>";
  149. echo "<div style='font-size: 130%;font-weight: 700;'>$paliword</div>";
  150. if (strlen($pali) > 1) {
  151. echo "<div class='mean'>$pali</div>";
  152. } else {
  153. //PDO_Connect(_FILE_DB_PALITEXT_);
  154. $query = "SELECT * from "._TABLE_PALI_TEXT_." where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 20";
  155. $FetchPaliText = PDO_FetchAll($query);
  156. $countPaliText = count($FetchPaliText);
  157. if ($countPaliText > 0) {
  158. for ($iPali = 0; $iPali < $countPaliText; $iPali++) {
  159. $path = "";
  160. $parent = $FetchPaliText[0]["parent"];
  161. $deep = 0;
  162. $sFirstParentTitle = "";
  163. while ($parent > -1) {
  164. $query = "SELECT * from pali_text where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 1";
  165. $FetParent = PDO_FetchAll($query);
  166. if ($sFirstParentTitle == "") {
  167. $sFirstParentTitle = $FetParent[0]["toc"];
  168. }
  169. $path = "{$FetParent[0]["toc"]}>{$path}";
  170. $parent = $FetParent[0]["parent"];
  171. $deep++;
  172. if ($deep > 5) {
  173. break;
  174. }
  175. }
  176. $path = $bookPath . $path . "No. " . $paragraph;
  177. echo "<div class='mean' style='font-size:120%;'><a href='../reader/?view=para&book={$book}&para={$paragraph}&display=para' target='_blank'>$path</a></div>";
  178. if (substr($paliword, -1) == "n") {
  179. $paliword = substr($paliword, 0, -1);
  180. }
  181. $htmlPara = str_replace(".0", "。0", $FetchPaliText[$iPali]["html"]);
  182. $aSent = str_getcsv($htmlPara, ".");
  183. $aSentInfo = array();
  184. $aBold = array();
  185. echo "<div class='wizard_par_div'>";
  186. foreach ($aSent as $sent) {
  187. //array_push($aSentInfo,false);
  188. //array_push($aBold,false);
  189. if (stristr($sent, $paliword)) {
  190. echo "<span>{$sent}.</span><br>";
  191. // $aSent[$i]=str_replace($paliword,"<hl>{$paliword}</hl>",$aSent[$i]);
  192. //$aSentInfo[$i]=true;
  193. }
  194. //if(stristr($aSent[$i],"bld")){
  195. //$aBold[$i]=true;
  196. //}
  197. }
  198. echo "</div>";
  199. /*
  200. $output="";
  201. $bold_on=false;
  202. for($i=0;$i<count($aSent);$i++){
  203. if($aBold[$i]){
  204. if($aSentInfo[$i]){
  205. $output.=$aSent[$i]."<br>";
  206. $bold_on=true;
  207. }
  208. else{
  209. echo "<div>{$output}</div>";
  210. $output="";
  211. $bold_on=false;
  212. }
  213. }
  214. else{
  215. if($bold_on){
  216. echo "<div>{$aBold[$i]}</div>";
  217. }
  218. }
  219. }
  220. */
  221. //$light_text=str_replace($paliword,"<hl>{$paliword}</hl>",$FetchPaliText[$iPali]["vri_text"]);
  222. //$light_text=str_replace(".",".<br />",$light_text);
  223. //echo "<div class='wizard_par_div'>{$light_text}</div>";
  224. }
  225. }
  226. }
  227. echo "<div class='search_para_tools'></div>";
  228. echo "</div>";
  229. }
  230. }
  231. echo "</div>";
  232. //黑体字主显示区右侧结束
  233. echo "</div>";
  234. //黑体字主显示区结束
  235. }
  236. echo "</div>";
  237. //查黑体字结束
  238. break;
  239. case "update":
  240. $target = $_GET["target"];
  241. switch ($target) {
  242. case "bold";
  243. $arrBookName = json_decode(file_get_contents("../public/book_name/sc.json"));
  244. PDO_Connect(_FILE_DB_BOLD_);
  245. $wordlist = $_GET["wordlist"];
  246. $booklist = $_GET["booklist"];
  247. $aBookList = ltrim($booklist, "(");
  248. $aBookList = rtrim($aBookList, ")");
  249. $aBookList = str_replace("'", "", $aBookList);
  250. $aBookList = str_getcsv($aBookList);
  251. foreach ($aBookList as $oneBook) {
  252. $aInputBook["{$oneBook}"] = 1;
  253. }
  254. //查找这些词出现在哪些书中
  255. $query = "SELECT book,count(word) as co from "._TABLE_WORD_BOLD_." where \"word2\" in $wordlist group by book order by co DESC";
  256. $Fetch = PDO_FetchAll($query);
  257. $iFetch = count($Fetch);
  258. if ($iFetch > 0) {
  259. echo "<div id='bold_book_list_new'>";
  260. echo "出现在{$iFetch}本书中:<br />";
  261. echo "<input id='bold_all_book' type='checkbox' checked onclick=\"dict_bold_book_all_select()\" />全选<br />";
  262. for ($i = 0; $i < $iFetch; $i++) {
  263. $book = $Fetch[$i]["book"];
  264. $bookname = $arrBookName[$book - 1]->title;
  265. if (isset($aInputBook["{$book}"])) {
  266. $bookcheck = "checked";
  267. } else {
  268. $bookcheck = "";
  269. }
  270. echo "<input id='bold_book_{$i}' type='checkbox' $bookcheck value='{$book}'/>";
  271. echo "<a onclick=\"dict_bold_book_select({$i})\">";
  272. echo "《{$bookname}》({$Fetch[$i]["co"]})<br />";
  273. echo "</a>";
  274. }
  275. echo "<input id='bold_book_count' type='hidden' value='{$iFetch}' />";
  276. echo "</div>";
  277. }
  278. //查找这些词出现在哪些书中结束
  279. //前20条记录
  280. if ($booklist == "()") {
  281. echo "<div>请选择书名</div>";
  282. }
  283. $query = "SELECT * from "._TABLE_WORD_BOLD_." where \"word2\" in $wordlist and \"book\" in $booklist limit 20";
  284. $Fetch = PDO_FetchAll($query);
  285. $iFetch = count($Fetch);
  286. if ($iFetch > 0) {
  287. for ($i = 0; $i < $iFetch; $i++) {
  288. $paliword = $Fetch[$i]["word"];
  289. $book = $Fetch[$i]["book"];
  290. $bookname = $arrBookName[$book - 1]->title;
  291. $c1 = $arrBookName[$book - 1]->c1;
  292. $c2 = $arrBookName[$book - 1]->c2;
  293. $bookPath = "$c1>$c2";
  294. $paragraph = $Fetch[$i]["paragraph"];
  295. $base = $Fetch[$i]["base"];
  296. $pali = $Fetch[$i]["pali"];
  297. echo "<div class='dict_word'>";
  298. echo "<div class='book' ><span style='font-size:110%;font-weight:700;'>《{$bookname}》</span> <tag>$c1</tag> <tag>$2</tag> </div>";
  299. echo "<div class='mean'>$paliword</div>";
  300. if (strlen($pali) > 1) {
  301. echo "<div class='mean'>$pali</div>";
  302. } else {
  303. PDO_Connect(_FILE_DB_PALITEXT_);
  304. $query = "SELECT * from "._TABLE_PALI_TEXT_." where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 20";
  305. $FetchPaliText = PDO_FetchAll($query);
  306. $countPaliText = count($FetchPaliText);
  307. if ($countPaliText > 0) {
  308. for ($iPali = 0; $iPali < $countPaliText; $iPali++) {
  309. $path = "";
  310. $parent = $FetchPaliText[0]["parent"];
  311. $deep = 0;
  312. $sFirstParentTitle = "";
  313. while ($parent > -1) {
  314. $query = "SELECT * from "._TABLE_PALI_TEXT_." where \"book\" = '{$book}' and \"paragraph\" = '{$parent}' limit 1";
  315. $FetParent = PDO_FetchAll($query);
  316. if ($sFirstParentTitle == "") {
  317. $sFirstParentTitle = $FetParent[0]["toc"];
  318. }
  319. $path = "{$FetParent[0]["toc"]}>{$path}";
  320. $parent = $FetParent[0]["parent"];
  321. $deep++;
  322. if ($deep > 5) {
  323. break;
  324. }
  325. }
  326. $path = "<span>{$bookPath}>{$path} No. {$paragraph}</span>";
  327. //echo "<div class='mean'>$path</div>";
  328. echo "<div class='mean' style='font-size:120%;'><a href='../reader/?view=para&book={$book}&para={$paragraph}&display=para' target='_blank'>$path</a></div>";
  329. if (substr($paliword, -1) == "n") {
  330. $paliword = substr($paliword, 0, -1);
  331. }
  332. $light_text = str_replace($paliword, "<hl>{$paliword}</hl>", $FetchPaliText[$iPali]["html"]);
  333. $light_text = str_replace(".", ".<br /><br />", $light_text);
  334. echo "<div class='wizard_par_div'>{$light_text}</div>";
  335. }
  336. }
  337. }
  338. echo "<div class='search_para_tools'></div>";
  339. echo "</div>";
  340. }
  341. }
  342. break;
  343. }
  344. break;
  345. }