bold_search.php 13 KB

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