瀏覽代碼

怎加句子历史记录功能

visuddhinanda 5 年之前
父節點
當前提交
c221ddfafa

+ 128 - 142
app/article/article.js

@@ -5,162 +5,148 @@ var _author = "";
 var _display = "";
 var _collect_id = "";
 
-function article_onload() {}
+function article_onload() {
+	historay_init();
+}
 function articel_load(id) {
-  if (id == "") {
-    return;
-  }
-  $.get(
-    "../article/get.php",
-    {
-      id: id,
-      setting: "",
-    },
-    function (data, status) {
-      if (status == "success") {
-        try {
-          let result = JSON.parse(data);
-          if (result) {
-            $("#article_title").html(result.title);
-            $("#article_subtitle").html(result.subtitle);
-            $("#article_author").html(
-              result.username.nickname + "@" + result.username.username
-            );
-            $("#contents").html(note_init(result.content));
-            note_refresh_new();
-          }
-        } catch (e) {
-          console.error(e);
-        }
-      } else {
-        console.error("ajex error");
-      }
-    }
-  );
+	if (id == "") {
+		return;
+	}
+	$.get(
+		"../article/get.php",
+		{
+			id: id,
+			setting: "",
+		},
+		function (data, status) {
+			if (status == "success") {
+				try {
+					let result = JSON.parse(data);
+					if (result) {
+						$("#article_title").html(result.title);
+						$("#article_subtitle").html(result.subtitle);
+						$("#article_author").html(result.username.nickname + "@" + result.username.username);
+						$("#contents").html(note_init(result.content));
+						note_refresh_new();
+					}
+				} catch (e) {
+					console.error(e);
+				}
+			} else {
+				console.error("ajex error");
+			}
+		}
+	);
 }
 
 function collect_load(id) {
-  if (id == "") {
-    return;
-  }
-  $.get(
-    "../article/collect_get.php",
-    {
-      id: id,
-      setting: "",
-    },
-    function (data, status) {
-      if (status == "success") {
-        try {
-          let result = JSON.parse(data);
-          if (result) {
-            $("#article_title").html(result.title);
-            if (result.subtitle) {
-              $("#article_subtitle").html(result.subtitle);
-            }
-            $("#article_author").html(
-              result.username.nickname + "@" + result.username.username
-            );
-            $("#contents").html(marked(result.summary));
+	if (id == "") {
+		return;
+	}
+	$.get(
+		"../article/collect_get.php",
+		{
+			id: id,
+			setting: "",
+		},
+		function (data, status) {
+			if (status == "success") {
+				try {
+					let result = JSON.parse(data);
+					if (result) {
+						$("#article_title").html(result.title);
+						if (result.subtitle) {
+							$("#article_subtitle").html(result.subtitle);
+						}
+						$("#article_author").html(result.username.nickname + "@" + result.username.username);
+						$("#contents").html(marked(result.summary));
 
-            let article_list = JSON.parse(result.article_list);
-            render_article_list(article_list);
-          }
-        } catch (e) {
-          console.error(e);
-        }
-      } else {
-        console.error("ajex error");
-      }
-    }
-  );
+						let article_list = JSON.parse(result.article_list);
+						render_article_list(article_list);
+					}
+				} catch (e) {
+					console.error(e);
+				}
+			} else {
+				console.error("ajex error");
+			}
+		}
+	);
 }
 
 function articel_load_collect(article_id) {
-  $.get(
-    "../article/collect_get.php",
-    {
-      article: article_id,
-      setting: "",
-    },
-    function (data, status) {
-      if (status == "success") {
-        try {
-          let result = JSON.parse(data);
-          if (result && result.length > 0) {
-            $("#collect_title").html(result[0].title);
-            let article_list = JSON.parse(result[0].article_list);
-            render_article_list(article_list);
-          }
-        } catch (e) {
-          console.error(e);
-        }
-      } else {
-        console.error("ajex error");
-      }
-    }
-  );
+	$.get(
+		"../article/collect_get.php",
+		{
+			article: article_id,
+			setting: "",
+		},
+		function (data, status) {
+			if (status == "success") {
+				try {
+					let result = JSON.parse(data);
+					if (result && result.length > 0) {
+						$("#collect_title").html(result[0].title);
+						let article_list = JSON.parse(result[0].article_list);
+						render_article_list(article_list);
+					}
+				} catch (e) {
+					console.error(e);
+				}
+			} else {
+				console.error("ajex error");
+			}
+		}
+	);
 }
 
 function render_article_list(article_list) {
-  let html = "";
-  html += "<ul>";
-  let display = "";
-  if (_display == "para") {
-    display = "&display=para";
-  }
-  let prevArticle = "无";
-  let nextArticle = "无";
-  for (let index = 0; index < article_list.length; index++) {
-    const element = article_list[index];
-    if (element.article == _articel_id) {
-      if (index > 0) {
-        const prev = article_list[index - 1];
-        prevArticle =
-          "<a href='../article/index.php?id=" +
-          prev.article +
-          display +
-          "'>" +
-          prev.title +
-          "</a>";
-      }
-      if (index < article_list.length - 1) {
-        const next = article_list[index + 1];
-        nextArticle =
-          "<a href='../article/index.php?id=" +
-          next.article +
-          display +
-          "'>" +
-          next.title +
-          "</a>";
-      }
-      $("#contents_nav_left").html(prevArticle);
-      $("#contents_nav_right").html(nextArticle);
-    }
-    html +=
-      "<li class='level_" +
-      element.level +
-      "'>" +
-      "<a href='../article/index.php?id=" +
-      element.article +
-      display +
-      "'>" +
-      element.title +
-      "</a></li>";
-  }
+	let html = "";
+	html += "<ul>";
+	let display = "";
+	if (_display == "para") {
+		display = "&display=para";
+	}
+	let prevArticle = "无";
+	let nextArticle = "无";
+	for (let index = 0; index < article_list.length; index++) {
+		const element = article_list[index];
+		if (element.article == _articel_id) {
+			if (index > 0) {
+				const prev = article_list[index - 1];
+				prevArticle = "<a href='../article/index.php?id=" + prev.article + display + "'>" + prev.title + "</a>";
+			}
+			if (index < article_list.length - 1) {
+				const next = article_list[index + 1];
+				nextArticle = "<a href='../article/index.php?id=" + next.article + display + "'>" + next.title + "</a>";
+			}
+			$("#contents_nav_left").html(prevArticle);
+			$("#contents_nav_right").html(nextArticle);
+		}
+		html +=
+			"<li class='level_" +
+			element.level +
+			"'>" +
+			"<a href='../article/index.php?id=" +
+			element.article +
+			display +
+			"'>" +
+			element.title +
+			"</a></li>";
+	}
 
-  html += "</ul>";
+	html += "</ul>";
 
-  $("#toc_content").html(html);
+	$("#toc_content").html(html);
 }
 
 function set_channal(channalid) {
-  let url = "../article/index.php?id=" + _articel_id;
-  if (channalid != "") {
-    url += "&channal=" + channalid;
-  }
-  if (_display != "") {
-    url += "&display=" + _display;
-  }
-  location.assign(url);
+	let url = "../article/index.php?id=" + _articel_id;
+	if (channalid != "") {
+		url += "&channal=" + channalid;
+	}
+	if (_display != "") {
+		url += "&display=" + _display;
+	}
+	location.assign(url);
 }

+ 1 - 1
app/article/index.php

@@ -292,7 +292,7 @@ require_once "../pcdl/html_head.php";
 	ntf_init();				
 	click_dropdown_init();
 	note_create();
-
+	historay_init();
 	if(_collect_id==""){
 		articel_load(_articel_id);
 		articel_load_collect(_articel_id);

+ 1 - 0
app/article/my_article_edit.php

@@ -54,6 +54,7 @@ require_once '../studio/index_head.php';
 }
 #preview_inner{
 	background-color: var(--bg-color);
+	color: var(--main-color);
 }
 	</style>
 

+ 1 - 0
app/path.php

@@ -71,5 +71,6 @@ define("_FILE_DB_CHANNAL_"  , __DIR__."/../tmp/user/channal.db3");
 define("_FILE_DB_USER_DICT_"  , __DIR__."/../tmp/user/udict.db3");
 define("_FILE_DB_USER_ARTICLE_"  , __DIR__."/../tmp/user/article.db3");
 define("_FILE_DB_HOSTSETTING_"  , __DIR__."/../tmp/user/hostsetting.db3");
+define("_FILE_DB_USER_SENTENCE_HISTORAY_"  , __DIR__."/../tmp/user/usent_historay.db3");
 
 ?>

+ 1 - 1
app/pcdl/html_head.php

@@ -59,7 +59,7 @@ else{
 	<script src="../term/term_edit_dlg.js"></script>
 	<link type="text/css" rel="stylesheet" href="../term/term_edit_dlg.css"/>	
 	<script src="../uwbw/wbw_channal_list.js"></script>
-	
+	<script src="../usent/historay.js"></script>
 	<script >
 	<?php require_once '../public/load_lang_js.php';?>
 	</script>

+ 4 - 2
app/term/note.js

@@ -7,7 +7,7 @@ var _author = "";
 var _arrData = new Array();
 var _channalData;
 
-const MAX_NOTE_NEST = 2;
+var MAX_NOTE_NEST = 2;
 
 /*
 {{203-1654-23-45@11@en@*}}
@@ -493,7 +493,9 @@ function note_json_html(in_json) {
 		output += "<span class = 'tip_buttom'>Share</span>";
 		output += "<span class = 'tip_buttom'>Copy</span>";
 		output += "<span class = 'tip_buttom'>Digest</span>";
-		output += "<span class = 'tip_buttom'>History</span>";
+		output += "<span class = 'tip_buttom' ";
+		output += " onclick=\"history_show('" + iterator.id + "')\"";
+		output += ">History</span>";
 		output += "<span class = 'tip_buttom'>Expand</span>";
 		output += "</div>";
 		//句子工具栏结束

+ 1 - 1
app/term/term.css

@@ -105,7 +105,7 @@ note > .tran > .tran_text_tool_bar::after {
 	border-color: transparent transparent var(--box-bg-color1) transparent;
 }
 
-.tran:hover .tran_text_tool_bar {
+.tran:hover > .tran_text_tool_bar {
 	display: block;
 }
 .tip_buttom {

+ 15 - 4
app/ucenter/function.php

@@ -40,28 +40,39 @@ function ucenter_getA($userid,$fields="nickname"){
 
 class UserInfo
 {
-    public $dbh;
+    private $dbh;
+    private $buffer;
     public function __construct() {
         $dns = "sqlite:"._FILE_DB_USERINFO_;
         $this->dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
         $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
+        $buffer = array();
     }
 
     public function getName($id){
+        if(empty($id)){
+            return array("nickname"=>"","username"=>"");
+        }
+        if(isset($buffer[$id])){
+            return $buffer[$id];
+        }
         if($this->dbh){
             $query = "SELECT nickname,username FROM user WHERE userid= ? ";
             $stmt = $this->dbh->prepare($query);
             $stmt->execute(array($id));
             $user = $stmt->fetchAll(PDO::FETCH_ASSOC);
             if(count($user)>0){
-                return array("nickname"=>$user[0]["nickname"],"username"=>$user[0]["username"]);
+                $buffer[$id] = array("nickname"=>$user[0]["nickname"],"username"=>$user[0]["username"]);
+                return $buffer[$id];
             }
             else{
-                return array("nickname"=>"","username"=>"");
+                $buffer[$id] =array("nickname"=>"","username"=>"");
+                return $buffer[$id];
             }            
         }
         else{
-            return array("nickname"=>"","username"=>"");
+            $buffer[$id] =array("nickname"=>"","username"=>"");
+            return $buffer[$id];
         }
     }
 }

+ 74 - 0
app/usent/historay.js

@@ -0,0 +1,74 @@
+function historay_init() {
+	$("body").append('<div id="sent_history_dlg" title="History"><div id="sent_history_content"></div></div>');
+	$("#sent_history_dlg").dialog({
+		autoOpen: false,
+		width: 550,
+		buttons: [
+			{
+				text: "Save",
+				click: function () {
+					$(this).dialog("close");
+				},
+			},
+			{
+				text: "Cancel",
+				click: function () {
+					$(this).dialog("close");
+				},
+			},
+		],
+	});
+}
+
+function history_show(id) {
+	$.get(
+		"../usent/historay_get.php",
+		{
+			id: id,
+		},
+		function (data) {
+			let result = JSON.parse(data);
+			let html = "";
+			if (result.status == 0) {
+				let currDate = new Date();
+
+				for (const iterator of result.data) {
+					let pass = currDate.getTime() - iterator.date;
+					let strPassTime = "";
+					if (pass < 60 * 1000) {
+						//一分钟内
+						strPassTime = Math.floor(pass / 1000) + "秒前";
+					} else if (pass < 3600 * 1000) {
+						//一小时内
+						strPassTime = Math.floor(pass / 1000 / 60) + "分钟前";
+					} else if (pass < 3600 * 24 * 1000) {
+						//一天内
+						strPassTime = Math.floor(pass / 1000 / 3600) + "小时前";
+					} else if (pass < 3600 * 24 * 7 * 1000) {
+						//一周内
+						strPassTime = Math.floor(pass / 1000 / 3600 / 24) + "天前";
+					} else if (pass < 3600 * 24 * 30 * 1000) {
+						//一个月内
+						strPassTime = Math.floor(pass / 1000 / 3600 / 24 / 7) + "周前";
+					} else {
+						//超过一个月
+						strPassTime = Math.floor(pass / 1000 / 3600 / 24 / 30) + "月前";
+					}
+					if (iterator.userinfo.username == getCookie("username")) {
+						html += "<div class=''>You</div>";
+					} else {
+						html += "<div class=''>" + iterator.userinfo.nickname + "</div>";
+					}
+
+					html += "<div class=''>" + strPassTime + "</div>";
+					html += "<div class=''>" + iterator.text + "</div>";
+					html += "<div class=''><button>restore</button></div>";
+				}
+				$("#sent_history_content").html(html);
+				$("#sent_history_dlg").dialog("open");
+			} else {
+				ntf_show(result.error);
+			}
+		}
+	);
+}

+ 25 - 0
app/usent/historay_get.php

@@ -0,0 +1,25 @@
+<?php
+#句子的历史记录
+require_once "../path.php";
+require_once "../public/_pdo.php";
+require_once "../public/function.php";
+require_once "../ucenter/function.php";
+
+$respond['id']=$_GET["id"];
+$respond['status']=0;
+$respond['error']="";
+$respond['data']=array();
+PDO_Connect("sqlite:"._FILE_DB_USER_SENTENCE_HISTORAY_);
+$query =  "SELECT sent_id,  user_id,  text,  date, landmark FROM  sent_historay  WHERE sent_id = ? LIMIT 0,200";
+$fetch = PDO_FetchAll($query,array($_GET["id"]));
+
+
+$_userinfo = new UserInfo();
+
+foreach ($fetch as $key => $value) {
+    # code...
+    $fetch[$key]["userinfo"]=$_userinfo->getName($value["user_id"]);
+}
+$respond['data'] = $fetch;
+echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+?>

+ 50 - 6
app/usent/sent_post.php

@@ -11,7 +11,13 @@ if(!isset($_COOKIE["userid"])){
     echo json_encode($respond, JSON_UNESCAPED_UNICODE);
     exit;
 }
-
+if(isset($_POST["landmark"])){
+    $_landmark = $_POST["landmark"];
+}
+else{
+    $_landmark = "";
+}
+//回传数据
 $respond=array("status"=>0,"message"=>"");
 $respond['book']=$_POST["book"];
 $respond['para']=$_POST["para"];
@@ -97,7 +103,8 @@ else{
 														) 
 										VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
             $stmt = $PDO->prepare($query);
-            $stmt->execute(array(UUID::v4(),
+            $newId = UUID::v4();
+            $stmt->execute(array($newId,
 										  "",
 										  $_POST["book"], 
 										  $_POST["para"], 
@@ -125,11 +132,19 @@ else{
                 exit;
             }
             else{
-                $respond['data']=array();
+                # 没错误
+                # 更新historay
+                #没错误 更新历史记录
+                $respond['message']=update_historay($newId,$_COOKIE["userid"] ,$_POST["text"],$_landmark);
+                if($respond['message']!==""){
+                    $respond['status']=1;
+                    echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+                    exit;
+                }
             }
         }
         else{
-            #没权限
+            #TO DO没权限 插入建议数据
             $respond['message']="没有权限";
             $respond['status']=1;
         }
@@ -156,12 +171,18 @@ else{
                 exit;
             }
             else{
-                #没错误
+                #没错误 更新历史记录
 
+                $respond['message']=update_historay($_id,$_COOKIE["userid"] ,$_POST["text"],$_landmark);
+                if($respond['message']!==""){
+                    $respond['status']=1;
+                    echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+                    exit;                   
+                }
             }
         }
         else{
-            #没权限 建议
+            #TO DO没权限 插入建议数据
             $respond['message']="没有权限";
             $respond['status']=1;
         }
@@ -169,4 +190,27 @@ else{
 
 
 echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+
+
+function update_historay($sent_id,$user_id,$text,$landmark){
+    # 更新historay
+    PDO_Connect("sqlite:"._FILE_DB_USER_SENTENCE_HISTORAY_);
+    $query =  "INSERT INTO sent_historay (sent_id,  user_id,  text,  date, landmark) VALUES (? , ? , ? , ? , ? )";
+    $stmt  = PDO_Execute($query,
+                                        array($sent_id,
+                                                 $user_id, 
+                                                 $text ,
+                                                mTime(),
+                                                $landmark
+                                            ));
+    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    /*  识别错误  */
+    $error = PDO_ErrorInfo();
+        return $error[2];
+    }
+    else{
+    #没错误
+        return "";
+    }
+}
 ?>

+ 2 - 2
app/usent/update.php

@@ -1,6 +1,6 @@
 <?php
 /*
-get xml doc from db
+向句子库中插入或更新数据
 */
 require_once "../path.php";
 require_once "../public/_pdo.php";
@@ -36,7 +36,7 @@ foreach ($aData as $data) {
 		$oldList[] = $data;
 	}
 }
-$update_list = array(); //已经成功修改数据库的数据列表 回传客户端
+$update_list = array(); //已经成功修改数据库的数据 回传客户端
 
 /* 修改现有数据 */
 $PDO->beginTransaction();