Explorar o código

添加文章到作品集

visuddhinanda %!s(int64=5) %!d(string=hai) anos
pai
achega
f49fa13b06

+ 44 - 0
app/article/add_article_to_collect.php

@@ -0,0 +1,44 @@
+<?php
+//查询term字典
+
+require_once "../path.php";
+require_once "../public/_pdo.php";
+require_once '../public/function.php';
+require_once '../ucenter/function.php';
+
+$output  = array();
+$respond = array();
+if(isset($_POST["id"])){
+    $data = json_decode($_POST["data"]);
+    $title = $_POST["title"];
+    PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+    $article_id=$_POST["id"];
+    $query = "DELETE FROM article_list WHERE article_id = ? ";
+     PDO_Execute($query,array($article_id));
+     if(count($data)>0){
+        /* 开始一个事务,关闭自动提交 */
+        $PDO->beginTransaction();
+        $query = "INSERT INTO article_list (collect_id, article_id,level,title) VALUES (?, ?, ? , ?)";
+        $sth = $PDO->prepare($query);
+        foreach ($data as $row) {
+            $sth->execute(array($row,$article_id,1,$title));
+        }
+        $PDO->commit();
+        if (!$sth || ($sth && $sth->errorCode() != 0)) {
+            /*  识别错误且回滚更改  */
+            $PDO->rollBack();
+            $error = PDO_ErrorInfo();
+            $respond['status']=1;
+            $respond['message']=$error[2];
+        }
+        else{
+            $respond['status']=0;
+            $respond['message']="成功";
+        }	         
+     }
+
+	echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+
+}
+
+?>

+ 95 - 0
app/article/add_to_collect_dlg.js

@@ -0,0 +1,95 @@
+function add_to_collect_dlg_init() {
+  $("[vui='collect-dlg']").each(function () {
+    $(this).css("position", "relative");
+    $(this).html(
+      "<span class='button_add_to_collect'>添加到作品集</span><div class='float_dlg'></div>"
+    );
+  });
+
+  $(".button_add_to_collect").click(function () {
+    let html = "";
+    let article_id = $(this).parent().attr("a_id");
+    html += "<div id='add_to_collect_dlg_" + article_id + "'>";
+    html += "<div >";
+    html += "<input type='input'  placeholder='搜索文集' />";
+    html += "</div>";
+    html += "<div>";
+    html += "<div class='exist'>";
+    html += "</div>";
+    html += "<div class='others'>";
+    html += "</div>";
+    html += "</div>";
+    html += "<div style='display:flex;'>";
+    html += "<button onclick='collect_new()'>New Collect</button>";
+    html +=
+      "<button onclick=\"article_add_to_collect_ok('" +
+      article_id +
+      "')\">Finish</button>";
+    html += "<button onclick='article_add_to_collect_cancel()'>Cancel</button>";
+    html += "</div>";
+    html += "</div>";
+    $(this).siblings(".float_dlg").first().append(html);
+    $(this).siblings(".float_dlg").first().show();
+    $.get(
+      "../article/list_article_in_collect.php",
+      {
+        id: article_id,
+      },
+      function (data, status) {
+        let collect_list = JSON.parse(data);
+
+        let id = collect_list.article_id;
+        let html_exist = "";
+        for (const iterator of collect_list.exist) {
+          html_exist +=
+            "<div><input type='checkbox' class='collect' collect_id='" +
+            iterator.id +
+            "' checked />";
+          html_exist += iterator.title;
+          html_exist += "</div>";
+        }
+        $("#add_to_collect_dlg_" + id)
+          .find(".exist")
+          .first()
+          .html(html_exist);
+
+        let html_others = "";
+        for (const iterator of collect_list.others) {
+          html_others +=
+            "<div><input type='checkbox' class='collect' collect_id='" +
+            iterator.id +
+            "' />";
+          html_others += iterator.title;
+          html_others += "</div>";
+        }
+        $("#add_to_collect_dlg_" + id)
+          .find(".others")
+          .first()
+          .html(html_others);
+      }
+    );
+  });
+}
+
+function article_add_to_collect_ok(article_id) {
+  let obj = document.querySelectorAll(".collect");
+  let collect_id = new Array();
+  for (const iterator of obj) {
+    if (iterator.checked == true) {
+      collect_id.push(iterator.getAttributeNode("collect_id").value);
+    }
+  }
+  $.post(
+    "../article/add_article_to_collect.php",
+    {
+      id: article_id,
+      title: $("#input_article_title").val(),
+      data: JSON.stringify(collect_id),
+    },
+    function (data) {
+      let result = JSON.parse(data);
+    }
+  );
+}
+
+function article_add_to_collect_cancel() {}

+ 4 - 4
app/article/article_add_dlg.js

@@ -1,6 +1,6 @@
-var _dlg_div;
+var _article_add_dlg_div;
 function article_add_dlg_init(div) {
 function article_add_dlg_init(div) {
-  _dlg_div = div;
+  _article_add_dlg_div = div;
   let html = "";
   let html = "";
   html += "<div id='article_add_dlg'>";
   html += "<div id='article_add_dlg'>";
   html += "<div >";
   html += "<div >";
@@ -19,10 +19,10 @@ function article_add_dlg_init(div) {
 }
 }
 
 
 function article_add_dlg_show() {
 function article_add_dlg_show() {
-  $("#" + _dlg_div).show();
+  $("#" + _article_add_dlg_div).show();
 }
 }
 function article_add_dlg_hide() {
 function article_add_dlg_hide() {
-  $("#" + _dlg_div).hide();
+  $("#" + _article_add_dlg_div).hide();
 }
 }
 function article_add_cancel() {
 function article_add_cancel() {
   article_add_dlg_hide();
   article_add_dlg_hide();

+ 2 - 7
app/article/collect_list.php

@@ -12,13 +12,8 @@ if(isset($_GET["userid"])){
     $userid=$_GET["userid"];
     $userid=$_GET["userid"];
     $query = "SELECT * from collect  where owner = ".$PDO->quote($userid)." and status <> 0 order by modify_time DESC";
     $query = "SELECT * from collect  where owner = ".$PDO->quote($userid)." and status <> 0 order by modify_time DESC";
     $Fetch = PDO_FetchAll($query);
     $Fetch = PDO_FetchAll($query);
-    if($Fetch){
-        /*
-
-        */
-        echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
-        exit;
-    }
+    echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
+    exit;
 }
 }
 
 
 echo json_encode(array(), JSON_UNESCAPED_UNICODE);	
 echo json_encode(array(), JSON_UNESCAPED_UNICODE);	

+ 39 - 0
app/article/list_article_in_collect.php

@@ -0,0 +1,39 @@
+<?php
+//查询term字典
+
+require_once "../path.php";
+require_once "../public/_pdo.php";
+require_once '../public/function.php';
+require_once '../ucenter/function.php';
+
+$output  = array();
+if(isset($_GET["id"])){
+    PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+    $article_id=$_GET["id"];
+    $query = "SELECT collect_id as id from article_list  where article_id = ?  ";
+    $exist = PDO_FetchAll($query,array($article_id));
+    $exist_id = array();
+    for ($i=0; $i < count($exist) ; $i++) { 
+        # query collect title
+        $query = "SELECT title from collect  where id = ?  ";
+        $exist[$i]["title"] = PDO_FetchOne($query,array($exist[$i]["id"]));        
+        $exist_id[$exist[$i]["id"]] = 1;
+    }
+    $output["exist"] = $exist;
+
+    $query = "SELECT id,title from collect  where owner = ? AND status <> 0 order by modify_time DESC limit 0,10";
+    $others = PDO_FetchAll($query,array($_COOKIE["userid"])); 
+    foreach ($others as $key => $value) {
+        # remove exist record
+        if(!isset($exist_id[$value["id"]])){
+            $output["others"][] = $value;
+        }
+    }
+    $output["article_id"]=$article_id;
+    echo json_encode($output, JSON_UNESCAPED_UNICODE);
+}
+else{
+    echo json_encode(array(), JSON_UNESCAPED_UNICODE);	
+}
+
+?>

+ 6 - 2
app/article/my_article.js

@@ -93,7 +93,7 @@ function my_article_edit(id) {
         try {
         try {
           let html = "";
           let html = "";
           let result = JSON.parse(data);
           let result = JSON.parse(data);
-
+          $("#article_collect").attr("a_id", result.id);
           html += '<div class="" style="padding:5px;">';
           html += '<div class="" style="padding:5px;">';
           html += '<div style="max-width:2em;flex:1;"></div>';
           html += '<div style="max-width:2em;flex:1;"></div>';
           html += "<input type='hidden' name='id' value='" + result.id + "'/>";
           html += "<input type='hidden' name='id' value='" + result.id + "'/>";
@@ -130,10 +130,14 @@ function my_article_edit(id) {
           $("#article_list").html(html);
           $("#article_list").html(html);
           $("#aritcle_status").html(render_status(result.status));
           $("#aritcle_status").html(render_status(result.status));
           let html_title =
           let html_title =
-            "<input type='input' name='title' value='" + result.title + "' />";
+            "<input id='input_article_title' type='input' name='title' value='" +
+            result.title +
+            "' />";
           $("#article_title").html(html_title);
           $("#article_title").html(html_title);
           $("#preview_inner").html(note_init(result.content));
           $("#preview_inner").html(note_init(result.content));
           note_refresh_new();
           note_refresh_new();
+
+          add_to_collect_dlg_init();
         } catch (e) {
         } catch (e) {
           console.error(e);
           console.error(e);
         }
         }

+ 2 - 0
app/article/my_article_edit.php

@@ -7,6 +7,7 @@ require_once '../studio/index_head.php';
 	<script language="javascript" src="../term/note.js"></script>
 	<script language="javascript" src="../term/note.js"></script>
 	<script language="javascript" src="../term/term.js"></script>
 	<script language="javascript" src="../term/term.js"></script>
 	<script language="javascript" src="../public/js/marked.js"></script>
 	<script language="javascript" src="../public/js/marked.js"></script>
+	<script language="javascript" src="../article/add_to_collect_dlg.js"></script>
 	<script >
 	<script >
 	var gCurrPage="article";
 	var gCurrPage="article";
 	</script>
 	</script>
@@ -57,6 +58,7 @@ require_once '../studio/index_head.php';
 			<div style="display:flex;">
 			<div style="display:flex;">
 				<a href="../article/my_article_index.php">返回</a>
 				<a href="../article/my_article_index.php">返回</a>
 				<span id="article_title"></span>
 				<span id="article_title"></span>
+				<div id="article_collect" vui='collect-dlg' ></div>
 			</div>
 			</div>
 			<div style="display:flex;">
 			<div style="display:flex;">
 				<div id="aritcle_status"></div>
 				<div id="aritcle_status"></div>

+ 1 - 8
app/article/my_article_index.php

@@ -28,14 +28,7 @@ require_once '../studio/index_head.php';
 	.case_dropdown-content>.active{
 	.case_dropdown-content>.active{
 		background-color:gray;
 		background-color:gray;
 	}
 	}
-	.float_dlg{
-		display: none;
-    width: 15em;
-    position: absolute;
-    right: 0;
-    background-color: var(--btn-hover-bg-color);
-    padding: 10px;
-	}
+
 	</style>
 	</style>
 
 
 	<?php
 	<?php

+ 10 - 0
app/studio/css/style.css

@@ -4404,3 +4404,13 @@ note {
 .input_bar {
 .input_bar {
   flex: 9;
   flex: 9;
 }
 }
+.float_dlg {
+  display: none;
+  width: 25em;
+  position: absolute;
+  right: 0;
+  background-color: var(--btn-hover-bg-color);
+  padding: 10px;
+  border-radius: 5px;
+  box-shadow: 0 0 10px var(--main-color);
+}

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

@@ -60,12 +60,20 @@ function palitext_calculator() {
   }
   }
 }
 }
 //添加新的段落块
 //添加新的段落块
-function addNewBlockToHTML(bookId, parId) {
+function addNewBlockToHTML(bookId, parId, begin = -1, end = -1) {
   parHeadingLevel = 0;
   parHeadingLevel = 0;
   parTitle = "";
   parTitle = "";
   var divBlock = document.createElement("div");
   var divBlock = document.createElement("div");
   var typId = document.createAttribute("id");
   var typId = document.createAttribute("id");
-  typId.nodeValue = "par_" + bookId + "_" + (parId - 1);
+  if (begin == -1 && end == -1) {
+    //基于段落的块
+    typId.nodeValue = "par_" + bookId + "_" + (parId - 1);
+  } else {
+    //基于句子的块
+    typId.nodeValue =
+      "par_" + bookId + "_" + (parId - 1) + "_" + begin + "_" + end;
+  }
+
   divBlock.attributes.setNamedItem(typId);
   divBlock.attributes.setNamedItem(typId);
   var typClass = document.createAttribute("class");
   var typClass = document.createAttribute("class");
   typClass.nodeValue = "pardiv";
   typClass.nodeValue = "pardiv";
@@ -260,16 +268,29 @@ function insertBlockToHtml(element) {
   xmlParInfo = element.getElementsByTagName("info")[0];
   xmlParInfo = element.getElementsByTagName("info")[0];
   xmlParData = element.getElementsByTagName("data")[0];
   xmlParData = element.getElementsByTagName("data")[0];
 
 
-  bookId = getNodeText(xmlParInfo, "book");
-  paragraph = getNodeText(xmlParInfo, "paragraph");
+  let bookId = getNodeText(xmlParInfo, "book");
+  let paragraph = getNodeText(xmlParInfo, "paragraph");
+  let base_on = getNodeText(xmlParInfo, "base");
+  let begin = getNodeText(xmlParInfo, "begin");
+  let end = getNodeText(xmlParInfo, "end");
+
   type = getNodeText(xmlParInfo, "type");
   type = getNodeText(xmlParInfo, "type");
   language = getNodeText(xmlParInfo, "language");
   language = getNodeText(xmlParInfo, "language");
   bId = getNodeText(xmlParInfo, "id");
   bId = getNodeText(xmlParInfo, "id");
 
 
-  blockId = "par_" + bookId + "_" + (paragraph - 1);
-  var htmlBlock = document.getElementById(blockId);
-  if (htmlBlock == null) {
-    addNewBlockToHTML(bookId, paragraph);
+  let htmlBlock;
+  if (base_on == "sentence") {
+    blockId = "par_" + bookId + "_" + (paragraph - 1) + "_" + begin + "_" + end;
+    htmlBlock = document.getElementById(blockId);
+    if (htmlBlock == null) {
+      addNewBlockToHTML(bookId, paragraph, begin, end);
+    }
+  } else {
+    blockId = "par_" + bookId + "_" + (paragraph - 1);
+    htmlBlock = document.getElementById(blockId);
+    if (htmlBlock == null) {
+      addNewBlockToHTML(bookId, paragraph);
+    }
   }
   }
 
 
   if (!isParInView(getParIndex(bookId, paragraph))) {
   if (!isParInView(getParIndex(bookId, paragraph))) {

+ 117 - 0
app/studio/project_load_article.php

@@ -0,0 +1,117 @@
+<?php
+/*
+get xml doc from db
+*/
+require_once "../path.php";
+require_once "../public/_pdo.php";
+require_once "../public/function.php";
+
+$id=$_GET["id"];
+
+PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+$query = "select * from article where id=".$PDO->quote($id);
+$Fetch = PDO_FetchAll($query);
+if(count($Fetch)>0){
+	echo "<set>\n";
+	echo $Fetch[0]["doc_info"];
+	echo "\n<dict></dict>\n";
+	echo "<message></message>\n";
+	echo "<body>\n";
+	
+	$dh_wbw = new PDO("sqlite:"._FILE_DB_USER_WBW_, "", "",array(PDO::ATTR_PERSISTENT=>true));
+    $dh_wbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+
+	$dh_sent = new PDO("sqlite:"._FILE_DB_SENTENCE_, "", "",array(PDO::ATTR_PERSISTENT=>true));
+    $dh_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+	
+	$blockList = explode("\n",$Fetch[0]["content"]) ;
+	
+	foreach($blockList as $block){
+		$info = explode("-",$block); 
+		switch($block->type){
+			case "6":
+			{
+				$albumId = UUID::v4();
+				$query="select * from wbw_block where id='".$block->block_id."'";
+				$stmt = $dh_wbw->query($query);
+				$FetchBlock = $stmt->fetchAll(PDO::FETCH_ASSOC);
+				echo "\n<block>";
+				echo "<info>\n";
+				
+				echo "<type>wbw</type>";
+				echo "<book>{$FetchBlock[0]["book"]}</book>";
+				echo "<paragraph>{$FetchBlock[0]["paragraph"]}</paragraph>";
+				echo "<level>100</level>";
+				echo "<title>title</title>";
+				echo "<album_id>{$block->channal}</album_id>";
+				echo "<album_guid>{$block->channal}</album_guid>";
+				echo "<author>{$FetchBlock[0]["owner"]}</author>";
+				echo "<language>{$FetchBlock[0]["lang"]}</language>";
+				echo "<version>1</version>";
+				echo "<edition>1</edition>";
+				echo "<id>{$block->block_id}</id>";
+				echo "</info>\n";		
+				echo "<data>\n";
+				$query="select * from wbw where block_id='".$block->block_id."'";
+				$stmt = $dh_wbw->query($query);
+				$wbw_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
+				foreach($wbw_data as $word){
+					echo $word["data"];	
+					echo "\r\n";	
+				}
+				echo "</data>";
+				echo "</block>\n";
+				break;
+			}
+			case 2:
+			{
+				$albumId = UUID::v4();
+				$query="select * from sent_block where id='".$block->block_id."'";
+				$stmt = $dh_sent->query($query);
+				$FetchBlock = $stmt->fetchAll(PDO::FETCH_ASSOC);
+				if(count($FetchBlock)>0){
+					echo "\n<block>\n";
+					echo "<info>\n";
+					
+					echo "<type>translate</type>";
+					echo "<book>{$FetchBlock[0]["book"]}</book>";
+					echo "<paragraph>{$FetchBlock[0]["paragraph"]}</paragraph>";
+					echo "<level>100</level>";
+					echo "<title>title</title>";
+					echo "<album_id>{$block->channal}</album_id>";
+					echo "<album_guid>{$block->channal}</album_guid>";
+					echo "<author>{$FetchBlock[0]["author"]}</author>";
+					echo "<editor>{$FetchBlock[0]["editor"]}</editor>";
+					echo "<language>{$FetchBlock[0]["lang"]}</language>";
+					echo "<version>1</version>";
+					echo "<edition>1</edition>";
+					echo "<id>{$block->block_id}</id>";
+					echo "<parent>{$FetchBlock[0]["parent_id"]}</parent>";
+					echo "</info>\n";
+					echo "<data>\n";
+					$query="select * from sentence where block_id='".$block->block_id."'";
+					$stmt = $dh_sent->query($query);
+					$sent_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
+					foreach($sent_data as $sent){
+						echo "<sen>";
+						echo "<id>{$sent["id"]}</id>";
+						echo "<begin>{$sent["begin"]}</begin>";
+						echo "<end>{$sent["end"]}</end>";
+						echo "<text>{$sent["text"]}</text>";
+						echo "<status>{$sent["status"]}</status>";
+						echo "</sen>";						
+					}
+					echo "</data>\n";
+					echo "</block>\n";
+				}
+				break;
+			}
+		}
+		
+	}
+				
+	echo "</body>\n";
+	echo "</set>";
+}
+
+?>