visuddhinanda 5 سال پیش
والد
کامیت
25de52df2c

+ 9 - 56
app/article/index.php

@@ -7,6 +7,7 @@ require_once "../pcdl/html_head.php";
 	<script src="../term/term.js"></script>
 	<script src="../term/note.js"></script>
 	<script src="./article.js"></script>
+	<link type="text/css" rel="stylesheet" href="../term/term.css"/>
 	<script>
 	<?php
 	$_id = "";
@@ -34,47 +35,14 @@ require_once "../pcdl/html_head.php";
 	body{
 		font-size:12pt;
 	}
-	.term_link,.term_link_new{
-		color: blue;
-		padding-left: 2px;
-		padding-right: 2px;
-	}
-	.term_link_new{
-		color:red;
-	}
+
 	#search_result{
 		position: absolute;
 		background: wheat;
 		max-width: 95%;
 		width: 24em;
 	}
-	note:hover chapter{
-		display:inline;
-	} 
-	.ref>chapter:first-child{
-		display:inline;
-	}
-	chapter{
-		display:none;
-		color: var(--box-bg-color1);
-		text-decoration: none;
-		cursor: pointer;
-	}
-	chapter:hover{
-		color: var(--link-color);
-		text-decoration: underline;
-	}
-	para{
-		background-color: var(--drop-bg-color);
-		padding: 2px 8px;
-		text-decoration: none;
-		cursor: pointer;
-		color: var(--btn-border-color);
-		border-radius: 5px;
-	}
-	para:hover{
-		text-decoration: underline;
-	}
+
 	.icon{
 		width: 15px;
 		height: 15px;
@@ -173,22 +141,7 @@ require_once "../pcdl/html_head.php";
 	.term_block_bar_left_info{
 		    padding-left: 8px;
 	}
-	.term_meaning{
-		font-weight: 700;
-	}
-	.term_author{
-		font-size: 80%;
-		color: gray;
-	}
-	.term_tag{
-		font-size: 80%;
-		font-weight: 500;
-		margin: 0 8px;
-	}
-	.term_link {
-	cursor: pointer;
-	position: relative;
-	}
+
 	.main_view{
 		padding: 0 1em;
 		max-width: 1280px;
@@ -271,7 +224,9 @@ require_once "../pcdl/html_head.php";
 	#contents{
 		min-height: 400px;
 	}
-	
+	#contents li{
+		white-space: normal;
+	}
 	#right_pannal{
 		flex:3;
 		max-width:20em;
@@ -279,9 +234,7 @@ require_once "../pcdl/html_head.php";
 	#head_bar{
 		height:unset;
 	}
-	.term_link:hover .guide_contence {
-		display: inline-block;
-	}
+
 <?php
 		if(isset($_GET["display"]) && $_GET["display"]=="para"){
 ?>
@@ -383,7 +336,7 @@ term_word_link_fun("wiki_goto_word");
 		</div>
 		<div class="fun_frame">
 			<div class="title">Translations</div>
-			<div class="content" style="max-height:10em;">
+			<div id="channal_list" class="content" style="max-height:10em;">
 			</div>
 		</div>
 	</div>

+ 0 - 0
app/article/my_article.del.php


+ 89 - 14
app/article/my_article.js

@@ -1,3 +1,4 @@
+var _display = "para";
 function my_article_list() {
   $.get(
     "../article/list.php",
@@ -53,6 +54,8 @@ function render_status(status) {
     { id: 3, name: "公开", tip: "所有人均可看到" },
   ];
   html += '<div class="case_dropdown">';
+  html += '<input type="hidden" name="status"  value ="' + status + '" />';
+
   for (const iterator of objStatus) {
     if (iterator.id == status) {
       html += "<div >" + iterator.name + "</div>";
@@ -65,7 +68,7 @@ function render_status(status) {
     if (iterator.id == status) {
       active = "active";
     }
-    html += "<a class='" + active + "'  onclick='setStatus()'>";
+    html += "<a class='" + active + "'  onclick='setStatus(this)'>";
     html += "<div style='font-size:110%'>" + iterator.name + "</div>";
     html += "<div style='font-size:80%'>" + iterator.tip + "</div>";
     html += "</a>";
@@ -89,31 +92,44 @@ function my_article_edit(id) {
 
           html += '<div class="" style="padding:5px;">';
           html += '<div style="max-width:2em;flex:1;"></div>';
-          html += "<div style='flex:2;'>" + result.title + "</div>";
+          html += "<input type='hidden' name='id' value='" + result.id + "'/>";
           html +=
-            "<div style='flex:2;'>" + render_status(result.status) + "</div>";
-          html += "<div style='flex:1;'>Copy Link</div>";
+            "<input type='hidden' name='tag' value='" + result.tag + "'/>";
           html +=
-            "<div style='flex:1;'><a href='../article/my_article_edit.php?id=" +
-            result.id +
-            "'>Edit</a></div>";
+            "<input type='hidden' name='summary' value='" +
+            result.summary +
+            "'/>";
+          html += "<input type='hidden' name='id' value='" + result.id + "'/>";
           html +=
-            "<div style='flex:1;'><a href='../article/?id=" +
-            result.id +
-            "' target='_blank'>Preview</a></div>";
-          html += "<div style='flex:1;'>15</div>";
+            "<input type='hidden' name='status' value='" +
+            result.status +
+            "'/>";
+
+          html += "<button onclick='article_preview()'>Preview</button>";
+          html += "<input type='checkbox' name='import' />Import Data";
           html += "</div>";
           html += "<div style='display:flex;'>";
-          html += "<div style='flex:5;'>";
+          html += "<div style='flex:4;'>";
+
           html +=
-            "<textarea style='height:500px;'>" + result.content + "</textarea>";
+            "<textarea id='article_content' name='content' style='height:500px;'>" +
+            result.content +
+            "</textarea>";
           html += "</div>";
-          html += "<div style='flex:5;'>";
 
+          html += "<div id='preview_div'>";
+          html += "<div id='preview_inner' ></div>";
           html += "</div>";
+
           html += "</div>";
 
           $("#article_list").html(html);
+          $("#aritcle_status").html(render_status(result.status));
+          let html_title =
+            "<input type='input' name='title' value='" + result.title + "' />";
+          $("#article_title").html(html_title);
+          $("#preview_inner").html(note_init(result.content));
+          note_refresh_new();
         } catch (e) {
           console.error(e);
         }
@@ -123,3 +139,62 @@ function my_article_edit(id) {
     }
   );
 }
+
+function article_preview() {
+  $("#preview_inner").html(note_init($("#article_content").val()));
+  note_refresh_new();
+}
+
+function my_article_save() {
+  $.ajax({
+    //几个参数需要注意一下
+    type: "POST", //方法类型
+    dataType: "json", //预期服务器返回的数据类型
+    url: "../article/my_article_post.php", //url
+    data: $("#article_edit").serialize(),
+    success: function (result) {
+      console.log(result); //打印服务端返回的数据(调试用)
+
+      if (result.status == 0) {
+        alert("保存成功");
+      } else {
+        alert("error:" + result.message);
+      }
+    },
+    error: function (data, status) {
+      alert("异常!" + data.responseText);
+      switch (status) {
+        case "timeout":
+          break;
+        case "error":
+          break;
+        case "notmodified":
+          break;
+        case "parsererror":
+          break;
+        default:
+          break;
+      }
+    },
+  });
+}
+
+function course_validate_required(field, alerttxt) {
+  with (field) {
+    if (value == null || value == "") {
+      alert(alerttxt);
+      return false;
+    } else {
+      return true;
+    }
+  }
+}
+
+function course_validate_form(thisform) {
+  with (thisform) {
+    if (course_validate_required(title, "Title must be filled out!") == false) {
+      title.focus();
+      return false;
+    }
+  }
+}

+ 30 - 8
app/article/my_article_edit.php

@@ -4,6 +4,9 @@ require_once '../studio/index_head.php';
 <body id="file_list_body" >
 
 	<script language="javascript" src="../article/my_article.js"></script>
+	<script language="javascript" src="../term/note.js"></script>
+	<script language="javascript" src="../term/term.js"></script>
+	<script language="javascript" src="../public/js/marked.js"></script>
 	<script >
 	var gCurrPage="article";
 	</script>
@@ -27,31 +30,48 @@ require_once '../studio/index_head.php';
 	.case_dropdown-content>.active{
 		background-color:gray;
 	}
+	.file_list_block {
+    max-width: 100%;
+    margin-right: 1em;
+	}
+	.index_inner {
+    margin-left: 16em;
+    margin-top: 5em;
+}
+#preview_div {
+    flex: 6;
+    overflow-y: scroll;
+    height: 550px;
+}
+
 	</style>
 
 	<?php
 	require_once '../studio/index_tool_bar.php';
 	?>
 		
-	<div class="index_inner " style="margin-left: 18em;margin-top: 5em;">
+	<div class="index_inner " >
+	<form id="article_edit" action="##" onsubmit="return false"  method="POST" >
 	<div class="file_list_block">
 		<div class="tool_bar">
-			<div><a href="../article/my_article_index.php">返回</a><span id="article_title"></span></div>
-			<div>
+			<div style="display:flex;">
+				<a href="../article/my_article_index.php">返回</a>
+				<span id="article_title"></span>
+			</div>
+			<div style="display:flex;">
+				<div id="aritcle_status"></div>
 				<span class="icon_btn_div">
 					<span class="icon_btn_tip"></span>
-					<button id="file_add" type="button" class="icon_btn" title=" ">
-						<a href="../course/my_course_index.php?op=new">
+					<button id="edit_save" type="button" class="icon_btn" title=" " onclick="my_article_save()">
 						<svg class="icon">
-							<use xlink:href="../studio/svg/icon.svg#ic_add_circle"></use>
+							<use xlink:href="../studio/svg/icon.svg#ic_save"></use>
 						</svg>
-						</a>
 					</button>
 				</span>
 				
 				<span class="icon_btn_div">				
 					<span class="icon_btn_tip">回收站</span>
-					<button id="to_recycle" type="button" class="icon_btn" onclick="file_del()" title=" ">
+					<button id="to_recycle" type="button" class="icon_btn" onclick="article_del()" title=" ">
 						<svg class="icon">
 							<use xlink:href="../studio/svg/icon.svg#ic_delete"></use>
 						</svg>
@@ -63,7 +83,9 @@ require_once '../studio/index_head.php';
 		<div id="article_list"  class="file_list_block" style="">
 
 		</div>
+
 	</div>
+</form>
 	</div>
 	
 <script>

+ 109 - 0
app/article/my_article_post.php

@@ -0,0 +1,109 @@
+<?php
+require_once "../path.php";
+require_once "../public/_pdo.php";
+require_once '../public/function.php';
+require_once '../hostsetting/function.php';
+$respond=array("status"=>0,"message"=>"");
+$_content = $_POST["content"];
+
+if($_POST["import"]=='on'){
+    $sent = explode("\n",$_POST["content"]);
+    if($sent && count($sent)>0){
+        $setting =  new Hostsetting();
+        $max_book = $setting->get("max_book_number");
+        if($max_book){
+            $currBook = $max_book+1;
+            $setbooknum = $setting->set("max_book_number",$currBook);
+            if($setbooknum==false){
+                $respond["status"]=1;
+                $respond["message"]="设置书号错误";
+                echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+                exit;
+            }
+        }
+        else{
+            $respond["status"]=1;
+            $respond["message"]="获取书号错误";
+            echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+            exit;
+        }
+        PDO_Connect("sqlite:"._FILE_DB_SENTENCE_);
+
+        /* 开始一个事务,关闭自动提交 */
+        $PDO->beginTransaction();
+        $query="INSERT INTO sentence ('id','block_id','book','paragraph','begin','end','tag','author','editor','text','language','ver','status','strlen','modify_time','receive_time') VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+        
+        $sth = $PDO->prepare($query);
+        
+        $para = 1;
+        $sentNum = 0;
+        $newText =  "";
+        foreach ($sent as $data) {
+            $data = trim($data);
+            if($data==""){
+                $para++;
+                $sentNum = 0;
+                $newText .="\n";
+                continue;
+            }
+            else{
+                $sentNum=$sentNum+10;
+            }
+            if(mb_substr($data,0,2,"UTF-8")=="{{"){
+                $newText .=$data."\n";
+            }
+            else{
+                $newText .='{{'."{$currBook}-{$para}-{$sentNum}-{$sentNum}"."}}\n";
+                $sth->execute(
+                        array(UUID::v4(),
+                                    "",
+                                    $currBook,
+                                    $para,
+                                    $sentNum,
+                                    $sentNum,
+                                    "",
+                                    "[]",
+                                    $_COOKIE["userid"],
+                                    $data,
+                                    "my",
+                                    1,
+                                    1,
+                                    mb_strlen($data,"UTF-8"),
+                                    mTime(),
+                                    mTime()
+                                ));                
+            }
+
+        }
+        $PDO->commit();
+        
+        if (!$sth || ($sth && $sth->errorCode() != 0)) {
+            /*  识别错误且回滚更改  */
+            $PDO->rollBack();
+            $error = PDO_ErrorInfo();
+            $respond['status']=1;
+            $respond['message']=$error[2];
+            echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+            exit;
+        }
+        else{
+            $respond['status']=0;
+            $respond['message']="成功";
+            $_content = $newText;
+        }		        
+    }
+}
+
+PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+
+$query="UPDATE article SET title = ? , subtitle = ? , summary = ?, content = ?  , tag = ? , setting = ? , status = ? , receive_time= ?  , modify_time= ?   where  id = ?  ";
+$sth = $PDO->prepare($query);
+$sth->execute(array($_POST["title"] , $_POST["subtitle"] ,$_POST["summary"], $_content , $_POST["tag"] , $_POST["setting"] , $_POST["status"] ,   mTime() , mTime() , $_POST["id"]));
+$respond=array("status"=>0,"message"=>"");
+if (!$sth || ($sth && $sth->errorCode() != 0)) {
+	$error = PDO_ErrorInfo();
+	$respond['status']=1;
+	$respond['message']=$error[2];
+}
+echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+?>

+ 0 - 0
app/article/my_article_put.php


+ 48 - 0
app/hostsetting/function.php

@@ -0,0 +1,48 @@
+<?php
+require_once '../path.php';
+
+class Hostsetting
+{
+    public $dbh;
+    public function __construct() {
+        $dns = "sqlite:"._FILE_DB_HOSTSETTING_;
+        $this->dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
+        $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
+    }
+
+    public function get($key){
+        if($this->dbh){
+            $query = "SELECT value FROM setting WHERE key= ? ";
+            $stmt = $this->dbh->prepare($query);
+            $stmt->execute(array($key));
+            $row = $stmt->fetch(PDO::FETCH_NUM);
+            if ($row) {
+                return $row[0];
+            } else {
+                return false;
+            }
+        }
+        else{
+            return false;
+        }
+    }
+
+    public function set($key,$value){
+        if($this->dbh){
+            $query = "UPDATE setting SET value = ?  WHERE key= ? ";
+            $stmt = $this->dbh->prepare($query);
+            $stmt->execute(array($value,$key));
+            if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+                $error = PDO_ErrorInfo();
+                return false;
+            }
+            else{
+                return true;
+            }
+        }
+        else{
+            return false;
+        }
+    }
+}
+?>

+ 1 - 0
app/path.php

@@ -70,5 +70,6 @@ define("_FILE_DB_USER_STATISTICS_"  , __DIR__."/../tmp/user/statistics.db3");
 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");
 
 ?>

+ 12 - 1
app/term/note.js

@@ -292,6 +292,17 @@ function note_json_html(in_json) {
     "<div class='tran'>" +
     marked(term_std_str_to_tran(in_json.tran)) +
     "</div>";
-  output += "<div class='ref'>" + in_json.ref + "</div>";
+  output += "<div class='ref'>" + in_json.ref;
+  output +=
+    "<span class='sent_no'>" +
+    in_json.book +
+    "-" +
+    in_json.para +
+    "-" +
+    in_json.begin +
+    "-" +
+    in_json.end +
+    "<span>" +
+    "</div>";
   return output;
 }

+ 58 - 0
app/term/term.css

@@ -0,0 +1,58 @@
+.term_link:hover .guide_contence {
+  display: inline-block;
+}
+
+.term_meaning {
+  font-weight: 700;
+}
+.term_author {
+  font-size: 80%;
+  color: gray;
+}
+.term_tag {
+  font-size: 80%;
+  font-weight: 500;
+  margin: 0 8px;
+}
+.term_link {
+  cursor: pointer;
+  position: relative;
+}
+
+.term_link,
+.term_link_new {
+  color: blue;
+  padding-left: 2px;
+  padding-right: 2px;
+}
+.term_link_new {
+  color: red;
+}
+
+note:hover chapter {
+  display: inline;
+}
+.ref > chapter:first-child {
+  display: inline;
+}
+chapter {
+  display: none;
+  color: var(--box-bg-color1);
+  text-decoration: none;
+  cursor: pointer;
+}
+chapter:hover {
+  color: var(--link-color);
+  text-decoration: underline;
+}
+para {
+  background-color: var(--drop-bg-color);
+  padding: 2px 8px;
+  text-decoration: none;
+  cursor: pointer;
+  color: var(--btn-border-color);
+  border-radius: 5px;
+}
+para:hover {
+  text-decoration: underline;
+}

+ 1 - 0
app/time.php

@@ -1,3 +1,4 @@
 <?php
 echo time();
+phpinfo();
 ?>