Procházet zdrojové kódy

频道译文编辑 初步实现

visuddhinanda před 5 roky
rodič
revize
2c2d5ad1ba

+ 25 - 0
app/channal/channal.js

@@ -0,0 +1,25 @@
+var _my_channal = null;
+
+$.post(
+      "../channal/get.php",
+      {
+
+      },
+      function(data){
+          try{
+              _my_channal = JSON.parse(data);
+          }
+          catch(e){
+              console.error(e);
+          }
+      }
+    );
+
+function channal_getById(id) {
+    for (const iterator of _my_channal) {
+        if(iterator.id==id){
+            return iterator;
+        }
+    }
+    return false;
+}

+ 13 - 0
app/channal/get.php

@@ -0,0 +1,13 @@
+<?php
+//
+
+require_once "../path.php";
+require_once "../public/_pdo.php";
+
+global $PDO;
+PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
+$query = "select * from channal where owner = '{$_COOKIE["userid"]}'   limit 0,100";
+$Fetch = PDO_FetchAll($query);
+echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
+
+?>				

+ 1 - 1
app/lang/lang_list.json

@@ -172,7 +172,7 @@
   { "english": "Aymara", "name": "aymar aru", "code": "ay" },
   { "english": "Azerbaijani", "name": "azərbaycan dili", "code": "az" },
   { "english": "Chinese", "name": "中文", "code": "zh" },
-  { "english": "Chinese", "name": "漢語", "code": "zh-hant" },
+  { "english": "Chinese", "name": "繁体中文", "code": "zh-hant" },
   { "english": "Chinese", "name": "简体中文", "code": "zh-hans" },
   { "english": "Cree", "name": "ᓀᐦᐃᔭᐍᐏᐣ", "code": "cr" },
   { "english": "Estonian", "name": "eesti, eesti keel", "code": "et" },

+ 2 - 2
app/pcdl/reader.php

@@ -635,8 +635,8 @@ else{
 			$query = "SELECT book, paragraph,begin, end, text from 'pali_sent' where id IN ( {$sim_sents} ) ";
 			$FetchSim = PDO_FetchAll($query);
 			foreach ($FetchSim as $key => $value) {
-				$strSimSent .= "<div><a href=''>". $value["text"]."</div>";
-				$strSimSent .= "<div>"._get_para_path($value["book"],$value["paragraph"])."</div><br/>";
+				$strSimSent .= "<div>". $value["text"]."</div>";
+				$strSimSent .= "<div><a href='../pcdl/reader.php?view=para&book={$value["book"]}&para={$value["paragraph"]}'>"._get_para_path($value["book"],$value["paragraph"])."</a></div><br/>";
 			}
 		}
 	}

+ 2 - 0
app/studio/editor.php

@@ -52,6 +52,7 @@ else{$currDevice="computer";}
 	<script language="javascript" src="js/relation.js"></script>
 
 
+
 	<script language="javascript" src="js/relation_list.json"></script>
 	
 	<script language="javascript" src="sent/sent.js"></script>
@@ -69,6 +70,7 @@ else{$currDevice="computer";}
 	<script src="../uwbw/update.js"></script>
 	<script src="../usent/usent.js"></script>
 	<script src="../fileindex/file_info.js"></script>
+	<script language="javascript" src="../channal/channal.js"></script>
 	
 
 	<script language="javascript">

+ 1 - 1
app/studio/js/editor.js

@@ -3193,7 +3193,7 @@ function refreshPartMeaningSelect() {
 	output += "</button>";
 
 	output += "<button style='margin-left:auto; padding: 1px 6px;' onclick=\"input_org_switch('input_org_select','input_om')\">";
-	output += "<svg class=\"icon\"><use xlink=\"http://www.w3.org/1999/xlink\" href=\"svg/icon.svg#ic_mode_edit\">";
+	output += "<svg class='icon'><use xlink='http://www.w3.org/1999/xlink' href='svg/icon.svg#ic_mode_edit'>";
 	output += "</button>";
 	output += "</div>";
 

+ 139 - 29
app/studio/js/render.js

@@ -1507,7 +1507,8 @@ function renderWordParBlockInner(elementBlock) {
         //逐句翻译块开始
         output += "<div id='sent_div_" + wID + "' class='translate_sent'>";
         output += "<div class='translate_sent_head'>";
-        output += "<div class='translate_sent_head_toolbar'>";
+        output +=
+          "<div class='translate_sent_head_toolbar' style='display:none;'>";
         output += "<span></span>";
         output +=
           "<span onclick=\"show_tran_net('" +
@@ -1529,9 +1530,21 @@ function renderWordParBlockInner(elementBlock) {
           paragraph,
           sent_begin,
           word_id,
-          1,
-          false
+          0,
+          true
         );
+        if (_my_channal != null) {
+          for (const iterator of _my_channal) {
+            output += render_tran_sent_block(
+              book,
+              paragraph,
+              sent_begin,
+              word_id,
+              iterator.id,
+              false
+            );
+          }
+        }
         //句子预览结束
         output += "</div>";
 
@@ -1725,6 +1738,17 @@ function render_tran_sent_block(
     objSent = _user_sent_buffer.getSentText(book, para, begin, end, channal);
 
     if (objSent == false) {
+      objSent = new Object();
+      objSent.text = "";
+      if (doc_head("lang") == "") {
+        objSent.language = "en";
+      } else {
+        objSent.language = doc_head("lang");
+      }
+      objSent.id = "";
+      objSent.tag = "[]";
+      objSent.author = "{}";
+
       sent_text = "";
     } else {
       sent_text = objSent.text;
@@ -1742,7 +1766,12 @@ function render_tran_sent_block(
   if (channal == 0) {
     output += "<span class='author'>" + sender + "</span><span>[滤]</span>";
   } else {
-    output += "频道名";
+    let thischannal = channal_getById(channal);
+    if (thischannal) {
+      output += thischannal.name;
+    } else {
+      output += "未知的频道名";
+    }
   }
   output += "</div>";
   output +=
@@ -1760,9 +1789,6 @@ function render_tran_sent_block(
   if (readonly) {
     output += sent_text;
   } else {
-    if (objSent == false) {
-      sent_text = "点击编辑";
-    }
     output +=
       "<span onclick=\"sent_edit_click('" +
       book +
@@ -1774,16 +1800,37 @@ function render_tran_sent_block(
       end +
       "','" +
       channal +
-      "',)\">" +
-      sent_text +
-      "</span>";
+      "',)\">";
+    if (objSent.text == null || objSent.text == "") {
+      output += "<span style='color:gray;'>";
+      output +=
+        "<svg class='icon'><use xlink='http://www.w3.org/1999/xlink' href='svg/icon.svg#ic_mode_edit'>";
+      output += "</span>";
+    } else {
+      output += objSent.text;
+    }
+
+    output += "</span>";
   }
 
   output += "</div>";
   if (readonly == false) {
     output += "<div style='display:none;'>";
     output +=
-      "<textarea class='trans_sent_edit' style='background-color: #f8f8fa;color: black;border-color: silver;' book='" +
+      "<textarea id='trans_sent_edit_" +
+      book +
+      "_" +
+      para +
+      "_" +
+      begin +
+      "_" +
+      end +
+      "_" +
+      channal +
+      "' class='trans_sent_edit' style='background-color: #f8f8fa;color: black;border-color: silver;' " +
+      "sent_id='" +
+      objSent.id +
+      "' book='" +
       book +
       "'  para='" +
       para +
@@ -1793,25 +1840,19 @@ function render_tran_sent_block(
       end +
       "'  channal='" +
       channal +
+      "'  author='" +
+      objSent.author +
+      "'  lang='" +
+      objSent.language +
+      "'  tag='" +
+      objSent.tag +
       "' >";
-    output += sent_text;
+    output += objSent.text;
     output += "</textarea>";
-    output += "</div>";
-  }
-  output +=
-    "<div class='trans_text_info'>" +
-    "<span><span class='tag'>tag</span></span>" +
-    "<span><span class='tools'>";
-  if (readonly) {
-    output += "<button>采纳</button>";
-  } else {
-    output += "<button>保存</button>";
-  }
-
-  if (channal == 0) {
-    //百家言 显示更多按钮
+    output += "<div class='trans_text_info'>";
+    output += "<span></span>";
     output +=
-      "<button onclick=\"show_tran_net('" +
+      "<button onclick=\"trans_text_save('" +
       book +
       "','" +
       para +
@@ -1819,13 +1860,82 @@ function render_tran_sent_block(
       begin +
       "','" +
       end +
-      "')\">更多</button>";
+      "','" +
+      channal +
+      "')\">保存</button>";
+    output += "</div>";
+    output += "</div>";
   }
 
-  output += "</span><span>" + usent_count + "</span></span>" + "</div>";
+  if (readonly) {
+    output +=
+      "<div class='trans_text_info'>" +
+      "<span></span>" +
+      "<span><span class='tools'>";
+
+    output += "<button>采纳</button>";
+
+    if (channal == 0) {
+      //百家言 显示更多按钮
+      output +=
+        "<button onclick=\"show_tran_net('" +
+        book +
+        "','" +
+        para +
+        "','" +
+        begin +
+        "','" +
+        end +
+        "')\">更多</button>";
+    }
+
+    output += "</span><span>" + usent_count + "</span></span>";
+    output += "</div>";
+  }
+  output += "</div>";
   return output;
 }
 
+function trans_text_save(book, para, begin, end, channal) {
+  let textarea = $(
+    "#trans_sent_edit_" +
+      book +
+      "_" +
+      para +
+      "_" +
+      begin +
+      "_" +
+      end +
+      "_" +
+      channal
+  );
+  if (textarea) {
+    let objsent = new Object();
+    objsent.id = textarea.attr("sent_id");
+    objsent.book = book;
+    objsent.paragraph = para;
+    objsent.begin = begin;
+    objsent.end = end;
+    objsent.channal = channal;
+    objsent.author = textarea.attr("author");
+    objsent.lang = textarea.attr("lang");
+    objsent.text = textarea.val();
+    let sents = new Array();
+    sents.push(objsent);
+    $.post(
+      "../usent/update.php",
+      {
+        data: JSON.stringify(sents),
+      },
+      function (data, status) {
+        if (status == "success") {
+          let result = JSON.parse(data);
+          console.log(result);
+        }
+      }
+    );
+  }
+}
 function sent_edit_click(book, para, begin, end, channal) {
   $(".trans_sent_edit").parent().hide(200);
   $(

+ 106 - 6
app/usent/update.php

@@ -7,21 +7,55 @@ include "../public/_pdo.php";
 include "../public/function.php";
 
 
-$aData=json_decode($_POST["data"]);
+$aData=json_decode($_POST["data"],TRUE);
 
 PDO_Connect("sqlite:"._FILE_DB_SENTENCE_);
 
-/* 开始一个事务,关闭自动提交 */
+//查询没有id的哪些是数据库里已经存在的,防止多次提交同一条记录造成一个句子 多个channal
+$newList = array();
+$oldList = array();
+$query = "SELECT id FROM sentence WHERE book = ? and paragraph = ? and  begin = ? and end = ? and channal = ? limit 0 , 1 ";
+foreach ($aData as $data) {
+	if(!isset($data["id"]) || empty($data["id"])){
+		$id = PDO_FetchOne($query,array($data["book"],
+																	   $data["paragraph"],
+																	   $data["begin"],
+																	   $data["end"],
+																	   $data["channal"]
+																	   ));
+		if(empty($id)){
+			$newList[] = $data;
+		}
+		else{
+			$data["id"] = $id;
+			$oldList[] = $data;
+		}
+	}
+	else{
+		$oldList[] = $data;
+	}
+}
+
+/* 修改现有数据 */
 $PDO->beginTransaction();
 $query="UPDATE sentence SET text= ?  , status = ? , receive_time= ?  , modify_time= ?   where  id= ?  ";
 $sth = $PDO->prepare($query);
 
-foreach ($aData as $data) {
-    $sth->execute(array($data->text, $data->status, mTime(),$data->time,$data->id));
+foreach ($oldList as $data) {
+	if(isset($data["id"])){
+		if(isset($data["time"])){
+			$modify_time = $data["time"];
+		}
+		else{
+			$modify_time = mTime();
+		}
+		$sth->execute(array($data["text"], $data["status"], mTime(),$modify_time,$data["id"]));
+	} 
 }
+
 $PDO->commit();
 
-$respond=array("status"=>0,"message"=>"");
+$respond=array("status"=>0,"message"=>"","insert_error"=>"","new_list"=>array());
 
 if (!$sth || ($sth && $sth->errorCode() != 0)) {
 	/*  识别错误且回滚更改  */
@@ -33,6 +67,72 @@ if (!$sth || ($sth && $sth->errorCode() != 0)) {
 else{
 	$respond['status']=0;
 	$respond['message']="成功";
-}		
+}
+
+
+/* 插入数据 */
+$PDO->beginTransaction();
+$query = "INSERT INTO sentence (id, 
+														parent,
+														book,
+														paragraph,
+														begin,
+														end,
+														channal,
+														tag,
+														author,
+														editor,
+														text,
+														language,
+														ver,
+														status,
+														modify_time,
+														receive_time
+														) 
+										VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
+$sth = $PDO->prepare($query);
+$new_id = array();
+foreach ($newList as $data) {
+		$uuid = UUID::v4();
+		if($data["parent"]){
+			$parent = $data["parent"];
+		}
+		else{
+			$parent  = "";
+		}
+		$sth->execute(array($uuid,
+										  $parent,
+										  $data["book"], 
+										  $data["paragraph"], 
+										  $data["begin"], 
+										  $data["end"], 
+										  $data["channal"], 
+										  $data["tag"], 
+										  $data["author"], 
+										  $_COOKIE["userid"],
+										  $data["text"],
+										  $data["language"],
+										  1,
+										  7,
+										  mTime(),
+										  mTime()
+										));
+		$new_id[] = array($uuid,$data["book"],$data["paragraph"],$data["begin"],$data["end"],$data["channal"]);
+}
+$PDO->commit();
+
+
+if (!$sth || ($sth && $sth->errorCode() != 0)) {
+	/*  识别错误且回滚更改  */
+	$PDO->rollBack();
+	$error = PDO_ErrorInfo();
+	$respond['insert_error']=$error[2];
+	$respond['new_list']=array();
+}
+else{
+	$respond['insert_error']=0;
+	$respond['new_list']=$new_id;
+}
+
 echo json_encode($respond, JSON_UNESCAPED_UNICODE);
 ?>

+ 2 - 3
app/usent/usent_ref.js

@@ -71,10 +71,9 @@ class USentResult {
           for (const sent of iterator.data) {
             if (sent.channal == channal) {
               return sent;
-            } else {
-              return false;
-            }
+            } 
           }
+          return false;
         }
       }
     }