visuddhinanda 4 rokov pred
rodič
commit
96daafff4f

+ 25 - 3
app/article/my_article.js

@@ -195,7 +195,13 @@ function my_article_edit(id) {
 					html += "<input type='hidden' name='tag' value='" + result.tag + "'/>";
 					html += "<input type='hidden' name='status' value='" + result.status + "'/>";
 
-					//html += "<input type='checkbox' name='import' />" + gLocal.gui.import + gLocal.gui.text;
+					html += "<div style='display:none;'>";
+					html +=
+						"<input type='checkbox' name='import' id='import_custom_book'  />" +
+						gLocal.gui.import +
+						gLocal.gui.text;
+					html += "</div>";
+
 					html += "<div>";
 					//html += "<div id='article_collect' vui='collect-dlg' ></div>"
 					html += "<div style='display:flex;'>";
@@ -207,8 +213,9 @@ function my_article_edit(id) {
 					html += "<span style='flex:1;'>" + gLocal.gui.status + "</span>";
 					html += '<span id="aritcle_status" style="flex:7;"></span>';
 					html += "</div>";
+					html += '<div style="width:100%;" >';
 					html +=
-						'<div style="display:none;width:100%;" ><span style="flex:3;margin: auto;">' +
+						'<span style="flex:3;margin: auto;">' +
 						gLocal.gui.language_select +
 						'</span>	<input id="article_lang_select"  style="flex:7;width:100%;" type="input" onchange="article_lang_change()"  placeholder="' +
 						gLocal.gui.input +
@@ -271,7 +278,21 @@ function article_preview() {
 	$("#preview_inner").html(note_init($("#article_content").val()));
 	note_refresh_new();
 }
-
+function my_article_custom_book() {
+	$content = $("#article_content").val();
+	if ($content == "") {
+		alert("内容不能为空");
+		return;
+	}
+	if ($content.indexOf("{{") >= 0) {
+		alert("不能包含句子模版");
+		return;
+	}
+	if (confirm("将此文档转换为自定义书模版吗?") == true) {
+		document.querySelector("#import_custom_book").checked = true;
+		my_article_save();
+	}
+}
 function my_article_save() {
 	$.ajax({
 		type: "POST", //方法类型
@@ -283,6 +304,7 @@ function my_article_save() {
 
 			if (result.status == 0) {
 				alert(gLocal.gui.saved + gLocal.gui.successful);
+				window.location.reload();
 			} else {
 				alert("error:" + result.message);
 			}

+ 11 - 1
app/article/my_article_edit.php

@@ -72,7 +72,7 @@ require_once '../studio/index_head.php';
 
 				<span class="icon_btn_div">
 					<span class="icon_btn_tip"><?php echo $_local->gui->back ;?></span>
-					<button id="icon_btn" type="button" class="icon_btn"  onclick="my_article_save()">
+					<button id="icon_btn" type="button" class="icon_btn" >
 						<a href="../article/my_article_index.php" >
 							<svg class="icon">
 								<use xlink:href="../studio/svg/icon.svg#return"></use>
@@ -92,7 +92,17 @@ require_once '../studio/index_head.php';
 
 				
 			</div>
+			
 			<div style="display:flex;">
+				<span class="icon_btn_div">
+					<span class="icon_btn_tip"><?php echo "自定义书" ;?></span>
+					<button id="edit_custom_book" type="button" class="icon_btn"  onclick="my_article_custom_book()">
+						<svg class="icon">
+							<use xlink:href="../studio/svg/icon.svg#ic_save"></use>
+						</svg>
+					</button>
+				</span>
+
 				<div id="article_collect" vui='collect-dlg' ></div>
 				<span class="icon_btn_div">
 					<span class="icon_btn_tip"><?php echo $_local->gui->scan_in_reader ;?></span>

+ 27 - 88
app/article/my_article_post.php

@@ -6,6 +6,7 @@ require_once '../hostsetting/function.php';
 require_once "../ucenter/active.php";
 require_once "../article/function.php";
 require_once "../redis/function.php";
+require_once "../db/custom_book.php";
 
 add_edit_event(_ARTICLE_EDIT_,$_POST["id"]);
 
@@ -24,97 +25,35 @@ if($power<20){
 
 $_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(""._FILE_DB_SENTENCE_);
 
-        # 开始一个事务,关闭自动提交 
-        $PDO->beginTransaction();
-        $query="INSERT INTO sentence ('id','block_id','channal','book','paragraph','begin','end','tag','author','editor','text','language','ver','status','strlen','create_time','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(),
-                                    "",
-                                    $_POST["channal"],
-                                    $currBook,
-                                    $para,
-                                    $sentNum,
-                                    $sentNum,
-                                    "",
-                                    "[]",
-                                    $_COOKIE["userid"],
-                                    $data,
-                                    $_POST["lang"],
-                                    1,
-                                    1,
-                                    mb_strlen($data,"UTF-8"),
-                                    mTime(),
-                                    mTime(),
-                                    mTime()
-                                ));                
-            }
+if($_POST["import"]=='on'){
+	#导入自定义书
+	$custom_book = new CustomBook($redis);
+	$_lang = explode("_",$_POST["lang"]);
+	if(count($_lang)===3){
+		$lang = $_lang[2];
+	}
+	else if(count($_lang)===1){
+		$lang = $_lang[0];
+	}
+	else{
+		$respond["status"]=1;
+		$respond["message"]="无法识别的语言".$_POST["lang"];
+		echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+		exit;
+	}
 
-        }
-        $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;
-        }		        
-    }
+	$respond = $custom_book->new($_POST["title"],$_content,$lang);
+	if($respond["status"]==0){
+		$_content = $respond["content"];
+	}
+	else{
+		echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+		exit;
+	}
 }
-*/
+
+
 PDO_Connect(_FILE_DB_USER_ARTICLE_);
 
 $query="UPDATE article SET title = ? , subtitle = ? , summary = ?, content = ?  , tag = ? , setting = ? , status = ? , receive_time= ?  , modify_time= ?   where  id = ?  ";

+ 138 - 0
app/db/custom_book.php

@@ -0,0 +1,138 @@
+<?php
+require_once "../path.php";
+require_once "../db/table.php";
+require_once '../hostsetting/function.php';
+
+class CustomBook extends Table
+{
+    function __construct($redis=false) {
+		parent::__construct(_FILE_DB_USER_CUSTOM_BOOK_, "custom_book", "", "",$redis);
+    }
+
+	public function new($title,$data,$lang)
+	{
+		$respond['status']=0;
+		$respond['message']="";
+		$respond['content']="";
+
+		$sent = explode("\n",$data);
+		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"]="设置书号错误";
+					return $respond;
+				}
+			}
+			else{
+				$respond["status"]=1;
+				$respond["message"]="获取书号错误";
+				return $respond;
+			}
+
+			$query="INSERT INTO {$this->table} ('book_id','title','owner','lang','status','modify_time','create_time') VALUES (?, ?, ?, ?, ?, ?, ?)";
+
+			$stmt = $this->execute($query,array($currBook,$title,$_COOKIE["userid"],$lang,10,mTime(),mTime()));
+			if($stmt){
+				$CSent = new CustomBookSentence($this->redis);
+				$respond = $CSent->insert($currBook,$sent,$lang);
+			}
+			else{
+				$respond["status"]=1;
+				$respond["message"]="插入新书失败";
+			}
+		}
+		return $respond;
+	}
+}
+
+class CustomBookSentence extends Table
+{
+    function __construct($redis=false) {
+		parent::__construct(_FILE_DB_USER_CUSTOM_BOOK_, "custom_book_sentence", "", "",$redis);
+    }
+
+	public function insert($book,$content,$lang)
+	{
+		$respond['status']=0;
+		$respond['message']="";
+		$respond['content']="";
+		# 开始一个事务,关闭自动提交 
+		$this->dbh->beginTransaction();
+		$query="INSERT INTO custom_book_sentence ('book','paragraph','begin','end','length','text','lang','owner','status','create_time','modify_time') VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+		
+		$sth = $this->dbh->prepare($query);
+		
+		$para = 1;
+		$sentNum = 0;
+		$newText =  "";
+		foreach ($content 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 .='{{'."{$book}-{$para}-{$sentNum}-{$sentNum}"."}}\n";
+				$sth->execute(
+						array(
+							$book,
+							$para,
+							$sentNum,
+							$sentNum,
+							mb_strlen($data,"UTF-8"),
+							$data,
+							$lang,
+							$_COOKIE["userid"],
+							10,
+							mTime(),
+							mTime()
+						));                
+			}
+
+		}
+		$this->dbh->commit();
+		
+		if (!$sth || ($sth && $sth->errorCode() != 0)) {
+			#  识别错误且回滚更改  
+			$this->dbh->rollBack();
+			$error = $this->dbh->errorInfo();
+			$respond['status']=1;
+			$respond['message']=$error[2];
+			$respond['content']="";
+		}
+		else{
+			$respond['status']=0;
+			$respond['message']="成功";
+			$respond['content']=$newText;
+		}	
+
+		return $respond;
+	}
+
+	public function getText($book,$para,$start,$end){
+		$query="SELECT text FROM custom_book_sentence WHERE book = ? AND paragraph = ? AND begin=? AND end = ?";
+		$result = $this->fetch($query,array($book,$para,$start,$end));
+		if($result){
+			return $result["text"];
+		}
+		else{
+			return "unkow";
+		}
+	}
+
+}
+
+?>

+ 18 - 0
app/db/table.php

@@ -40,6 +40,24 @@ class Table
 			return false;
 		}
 	}
+
+	function execute($query, $params=null){
+		if (isset($params)) {
+			$stmt = $this->dbh->prepare($query);
+			if($stmt){
+				$stmt->execute($params);
+				return $stmt;				
+			}
+			else{
+				return false;
+			}
+
+		} else {
+			return $this->dbh->query($query);
+		}
+	}
+
+
 	public function syncList($time){
 
 	}

+ 1 - 0
app/path.php

@@ -121,3 +121,4 @@ define("_FILE_DB_USER_SENTENCE_HISTORAY_", "sqlite:" . __DIR__ . "/../tmp/user/u
 define("_FILE_DB_USER_ACTIVE_", "sqlite:" . __DIR__ . "/../tmp/user/user_active.db3");
 define("_FILE_DB_USER_ACTIVE_LOG_", "sqlite:" . __DIR__ . "/../tmp/user/user_active_log.db3");
 define("_FILE_DB_USER_SHARE_", "sqlite:" . __DIR__ . "/../tmp/user/share.db3");
+define("_FILE_DB_USER_CUSTOM_BOOK_", "sqlite:" . __DIR__ . "/../tmp/user/custom_book.db3");

+ 13 - 4
app/term/note.php

@@ -7,6 +7,7 @@ require_once "../ucenter/function.php";
 require_once "../usent/function.php";
 require_once "../pali_text/function.php";
 require_once "../redis/function.php";
+require_once "../db/custom_book.php";
 
 $redis = redis_connect();
 
@@ -88,6 +89,7 @@ if (count($channal_list) > 0) {
 }
 
 # 查询有阅读权限的channel 结束
+$custom_book = new CustomBookSentence($redis);
 
 foreach ($_data as $key => $value) {
     # code...
@@ -112,10 +114,17 @@ foreach ($_data as $key => $value) {
     }
 	$pali_sim = 0;
     if ($redis != false) {
-        $result = $redis->hGet('pali://sent/' . $bookId . "_" . $para . "_" . $begin . "_" . $end,"pali");
-		$palitext = $result;
-		$pali_text_id = $redis->hGet('pali://sent/' . $bookId . "_" . $para . "_" . $begin . "_" . $end,"id");
-		$pali_sim = $redis->hGet('pali://sent/' . $bookId . "_" . $para . "_" . $begin . "_" . $end,"sim_count");
+		if($bookId<1000){
+			$result = $redis->hGet('pali://sent/' . $bookId . "_" . $para . "_" . $begin . "_" . $end,"pali");
+			$palitext = $result;
+			$pali_text_id = $redis->hGet('pali://sent/' . $bookId . "_" . $para . "_" . $begin . "_" . $end,"id");
+			$pali_sim = $redis->hGet('pali://sent/' . $bookId . "_" . $para . "_" . $begin . "_" . $end,"sim_count");
+		}
+		else{
+			$palitext = $custom_book->getText($bookId,$para,$begin,$end);
+			$pali_text_id = 0;
+		}
+
     } else {
         $query = "SELECT id,html FROM 'pali_sent' WHERE book = ? AND paragraph = ? AND begin = ? AND end = ? ";
         $sth = $db_pali_sent->prepare($query);