Jelajahi Sumber

:bug: 术语搜索没有判断拼写

visuddhinanda 5 tahun lalu
induk
melakukan
4a76d83fa1
4 mengubah file dengan 110 tambahan dan 50 penghapusan
  1. 11 1
      app/term/note.js
  2. 11 2
      app/term/term.js
  3. 69 35
      app/term/term_get.php
  4. 19 12
      app/usent/sent_post.php

+ 11 - 1
app/term/note.js

@@ -546,7 +546,17 @@ function note_sent_save() {
             result.end +
             "_" +
             result.channal
-        ).html(marked(result.text));
+        ).html(
+          marked(
+            term_std_str_to_tran(
+              result.text,
+              result.channal,
+              result.editor,
+              result.lang
+            )
+          )
+        );
+        term_updata_translation();
         for (const iterator of _arrData) {
           if (
             iterator.book == result.book &&

+ 11 - 2
app/term/term.js

@@ -501,7 +501,11 @@ function term_lookup_my(pali, channal = "", owner = "", lang = "") {
   }
   for (const iterator of arrMyTerm) {
     if (owner != "") {
-      if (owner == iterator.owner && iterator.language == lang) {
+      if (
+        iterator.word == pali &&
+        owner == iterator.owner &&
+        iterator.language.indexOf(lang) >= 0
+      ) {
         return iterator;
       }
     }
@@ -860,12 +864,17 @@ function term_get_dict() {
     termword.lang = $(this).attr("lang");
     termwordlist.push(termword);
   });
-  //let wordquery = "('" + termwordlist.join("','") + "')";
+
+  let readonly = true;
+  if (_display == "sent") {
+    readonly = false;
+  }
   $.post(
     "../term/term_get.php",
     {
       words: JSON.stringify(termwordlist),
       channal: _channal,
+      readonly: readonly,
     },
     function (data, status) {
       if (data.length > 0) {

+ 69 - 35
app/term/term_get.php

@@ -8,56 +8,90 @@ require_once "../path.php";
 require_once "../public/_pdo.php";
 require_once '../public/function.php';
 require_once '../ucenter/function.php';
+require_once '../channal/function.php';
 
 PDO_Connect("sqlite:"._FILE_DB_TERM_);
 
 $output = array();
 if(isset($_POST["words"])){
     $wordlist = json_decode($_POST["words"]);
-
-    foreach ($wordlist as $key => $value) {
-        # code...
-        $pali = $value->pali;
-        $parm = array();
-        $parm[] = $pali;       
-
-        $otherCase = "";
-        if($value->channal != ""){
-            $otherCase .= " channal = ? ";
-            $parm[] = $value->channal;
-        }
-
-        if($value->editor != ""){
-            if($otherCase != ""){
-                $otherCase .= " OR ";
-            }
-            $otherCase .= " owner = ? ";
-            $parm[] = $value->editor;
-        }
-
-        if($value->lang != ""){
-            if($otherCase != ""){
-                $otherCase .= " OR ";
+    if($_POST["readonly"]=="false" && !empty($_POST["channal"])){
+        $channal = explode(",",$_POST["channal"]);
+        $channal_info = new Channal();
+        $channal_owner = array();
+        foreach ($channal as $key => $value) {
+            # code...
+            $info = $channal_info->getChannal($value);
+            if($info){
+                $channal_owner[$info["owner"]]=1;
             }
-            $otherCase .= " language = ? ";
-            $parm[] = $value->lang;
-        }
-
-        if($otherCase==""){
-            $query = "SELECT * FROM term WHERE word = ? ";
         }
-        else{
-            $query = "SELECT * FROM term WHERE word = ? AND ( $otherCase )";
+        /*  创建一个填充了和params相同数量占位符的字符串 */
+        $place_holders = implode(',', array_fill(0, count($channal), '?'));
+        $owner_holders = implode(',', array_fill(0, count($channal_owner), '?'));
+        $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note  FROM term WHERE channal IN ($place_holders) OR owner IN ($owner_holders)";
+        foreach ($channal_owner as $key => $value) {
+            # code...
+            $channal[] = $key;
         }
-
-        $fetch = PDO_FetchAll($query,$parm);
+        $fetch = PDO_FetchAll($query,$channal);
         $userinfo = new UserInfo();
+        $user = array();
+        foreach ($channal_owner as $key => $value) {
+            # code...
+            $user[$key]=$userinfo->getName($key);
+        }
         foreach ($fetch as $key => $value) {
             # code...
-            $fetch[$key]["user"]=$userinfo->getName($value["owner"]);
+            $fetch[$key]["user"] = $user[$key];
             $output[] =  $fetch[$key];
         }
     }
+    else{
+        foreach ($wordlist as $key => $value) {
+            # code...
+            $pali = $value->pali;
+            $parm = array();
+            $parm[] = $pali;       
+
+            $otherCase = "";
+            if($value->channal != ""){
+                $otherCase .= " channal = ? ";
+                $parm[] = $value->channal;
+            }
+
+            if($value->editor != ""){
+                if($otherCase != ""){
+                    $otherCase .= " OR ";
+                }
+                $otherCase .= " owner = ? ";
+                $parm[] = $value->editor;
+            }
+
+            if($value->lang != ""){
+                if($otherCase != ""){
+                    $otherCase .= " OR ";
+                }
+                $otherCase .= " language = ? ";
+                $parm[] = $value->lang;
+            }
+
+            if($otherCase==""){
+                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM term WHERE word = ? ";
+            }
+            else{
+                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM term WHERE word = ? AND ( $otherCase )";
+            }
+
+            $fetch = PDO_FetchAll($query,$parm);
+            $userinfo = new UserInfo();
+            foreach ($fetch as $key => $value) {
+                # code...
+                $fetch[$key]["user"]=$userinfo->getName($value["owner"]);
+                $output[] =  $fetch[$key];
+            }
+        }
+    }
 }
 echo json_encode($output, JSON_UNESCAPED_UNICODE);
 ?>

+ 19 - 12
app/usent/sent_post.php

@@ -4,14 +4,6 @@ require_once "../path.php";
 require_once "../public/_pdo.php";
 require_once "../public/function.php";
 
-$respond=array("status"=>0,"message"=>"");
-$respond['book']=$_POST["book"];
-$respond['para']=$_POST["para"];
-$respond['begin']=$_POST["begin"];
-$respond['end']=$_POST["end"];
-$respond['channal']=$_POST["channal"];
-$respond['text']=$_POST["text"];
-
 #检查是否登陆
 if(!isset($_COOKIE["userid"])){
     $respond["status"] = 1;
@@ -20,13 +12,28 @@ if(!isset($_COOKIE["userid"])){
     exit;
 }
 
+$respond=array("status"=>0,"message"=>"");
+$respond['book']=$_POST["book"];
+$respond['para']=$_POST["para"];
+$respond['begin']=$_POST["begin"];
+$respond['end']=$_POST["end"];
+$respond['channal']=$_POST["channal"];
+$respond['text']=$_POST["text"];
+$respond['editor']=$_COOKIE["userid"];
+
 #先查询对此channal是否有权限修改
 $cooperation = 0;
+$text_lang = "en";
 if(isset($_POST["channal"])){
    PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
-    $query = "SELECT owner FROM channal WHERE id=?";
-    $fetch = PDO_FetchOne($query,array($_POST["channal"]));
-    if($fetch && $fetch==$_COOKIE["userid"]){
+    $query = "SELECT owner, lang FROM channal WHERE id=?";
+    $fetch = PDO_FetchRow($query,array($_POST["channal"]));
+    
+    if($fetch){
+        $text_lang = $fetch["lang"];
+    }
+    $respond['lang']=$text_lang;
+    if($fetch && $fetch["owner"]==$_COOKIE["userid"]){
         #自己的channal
         $cooperation = 1;
     }
@@ -89,7 +96,7 @@ if(isset($_POST["id"])){
 										  "[]", 
 										  $_COOKIE["userid"],
 										  $_POST["text"],
-										  $_POST["lang"],
+										  $text_lang ,
 										  1,
 										  7,
 										  mb_strlen($_POST["text"],"UTF-8"),