bold_search.php 13 KB

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