浏览代码

article 支持阅读三藏

visuddhinanda 4 年之前
父节点
当前提交
5c19e2e215
共有 4 个文件被更改,包括 412 次插入23 次删除
  1. 173 2
      app/article/article.js
  2. 58 21
      app/article/index.php
  3. 11 0
      app/article/style.css
  4. 170 0
      app/reader/get_para1.php

+ 173 - 2
app/article/article.js

@@ -7,10 +7,13 @@ var _lang = "";
 var _author = "";
 var _display = "";
 var _collection_id = "";
+var _book=0,_par=0,_start=0,_end=0;
+var _sent_data;
 
 function article_onload() {
 	historay_init();
 }
+
 function articel_load(id, collection_id) {
 	if (id == "") {
 		return;
@@ -145,7 +148,25 @@ function render_article_list_in_content(article_list,collectId="",articleId="")
 	});
 }
 function set_channal(channalid) {
-	let url = "../article/index.php?view=article&id=" + _articel_id;
+	let url = "../article/index.php?";
+	if (_view != "") {
+		url += "view=" + _view;
+	}	
+	if (_id != "") {
+		url += "&id=" + _id;
+	}	
+	if (_book != 0) {
+		url += "&book=" + _book;
+	}	
+	if (_par != 0) {
+		url += "&par=" + _par;
+	}	
+	if (_start != 0) {
+		url += "&start=" + _start;
+	}	
+	if (_end != 0) {
+		url += "&end=" + _end;
+	}	
 	if (_collection_id != "") {
 		url += "&collection=" + _collection_id;
 	}
@@ -164,7 +185,25 @@ function set_channal(channalid) {
 	location.assign(url);
 }
 function setMode(mode = "read") {
-	let url = "../article/index.php?view=article&id=" + _articel_id;
+	let url = "../article/index.php?";
+	if (_view != "") {
+		url += "view=" + _view;
+	}	
+	if (_id != "") {
+		url += "&id=" + _id;
+	}	
+	if (_book != 0) {
+		url += "&book=" + _book;
+	}	
+	if (_par != 0) {
+		url += "&par=" + _par;
+	}	
+	if (_start != 0) {
+		url += "&start=" + _start;
+	}	
+	if (_end != 0) {
+		url += "&end=" + _end;
+	}
 	if (_collection_id != "") {
 		url += "&collection=" + _collection_id;
 	}
@@ -206,3 +245,135 @@ function gotoArticle(articleId) {
 	}
 	location.assign(url);
 }
+
+
+function palicanon_load() {
+	let param;
+	switch (_view) {
+		case "sent":
+		case "para":
+		case "chapter":
+			param = {
+				view: _view,
+				book: _book,
+				par: _par,
+				start: _start,
+				end: _end,
+			}
+			break;
+		case "simsent":
+			param = {view: _view,id:_id};
+			break;
+		default:
+			break;
+	}
+	$.get(
+		"../reader/get_para1.php",
+		param,
+		function (data, status) {
+			if (status == "success") {
+				try {
+					let result = JSON.parse(data);
+					if (result) {
+						_sent_data=result;
+						$("#article_title").html(result.title);
+						$("#article_path_title").html(result.title);
+						$("#page_title").text(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(function () {
+							document.querySelector("#para_focus").scrollIntoView({
+								block: "end",
+								behavior: "smooth",
+							});
+						});
+						reader_draw_para_menu();
+						guide_init();
+					}
+				} catch (e) {
+					console.error(e);
+				}
+			} else {
+				console.error("ajex error");
+			}
+		}
+	);
+}
+
+function reader_get_path() {
+	$.get(
+		"../reader/get_path.php",
+		{
+			book: _book,
+			para: _par,
+		},
+		function (data) {
+			$("#article_path").html(data);
+
+			var bookTitle = $("chapter").first().html();
+			let suttaTitle = $("chapter").last().html();
+
+			$("#pali_pedia").html(bookTitle);
+			$("#article_title").html(suttaTitle);
+			$("#page_title").text(suttaTitle);
+		}
+	);
+}
+
+function reader_draw_para_menu() {
+	$(".page_number").each(function () {
+		let strPara = $(this).text();
+		$(this).addClass("case_dropdown");
+		let html = "<a name='para_" + strPara + "'></a>";
+		html += "<div class='case_dropdown-content para_menu'>";
+		if (typeof _view != "undefined" && _view != "para") {
+			html += "<a onclick=\"junp_to_para('" + _book + "','" + strPara + "')\">仅显示此段</a>";
+		}
+		html += "<a onclick=\"edit_wbw('" + _book + "','" + strPara + "')\">" + gLocal.gui.edit_now + "</a>";
+		html += "<a  onclick='goto_nissaya(" + _book + "," + strPara + ")'>" + gLocal.gui.show_nissaya + "</a>";
+		html +=
+			"<a onclick=\"copy_para_ref('" + _book + "','" + strPara + "')\">" + gLocal.gui.copy_link + "</a>";
+		html +=
+			"<a onclick=\"copy_text('" +
+			_book +
+			"','" +
+			strPara +
+			"')\">" +
+			gLocal.gui.copy +
+			"“" +
+			gLocal.gui.pāli +
+			"”</a>";
+		html +=
+			"<a onclick=\"add_to_list('" +
+			_book +
+			"','" +
+			strPara +
+			"')\">" +
+			gLocal.gui.add_to_edit_list +
+			"</a>";
+		html += "</div>";
+		$(this).append(html);
+	});
+}
+
+
+function junp_to_para(book, para) {
+	let url = "../article/?view=para&book=" + book + "&par=" + para + "&display=sent";
+	location.assign(url);
+}
+
+function copy_para_ref(book, para) {
+	let output = "";
+	for (const iterator of _sent_data.sent_list) {
+		if (iterator.book == book && iterator.paragraph == para) {
+			output += "{{" + book + "-" + para + "-" + iterator.begin + "-" + iterator.end + "}}\n";
+		}
+	}
+	output += "\n";
+	copy_to_clipboard(output);
+}
+
+function edit_wbw(book, para) {
+	wbw_channal_list_open(book, [para]);
+}

+ 58 - 21
app/article/index.php

@@ -30,6 +30,7 @@ require_once "../pcdl/html_head.php";
 
 	if(isset($_GET["id"])){
 		echo "_articel_id='".$_GET["id"]."';";
+		echo "_id='".$_GET["id"]."';";
 	}
 	if(isset($_GET["collect"])){
 		echo "_collection_id='".$_GET["collect"]."';";
@@ -50,6 +51,20 @@ require_once "../pcdl/html_head.php";
 	if(isset($_GET["author"])){
 		echo "_author='".$_GET["author"]."';";
 	}
+
+	if(isset($_GET["book"])){
+		echo "_book=".$_GET["book"].";";
+	}
+	if(isset($_GET["par"])){
+		echo "_par=".$_GET["par"].";";
+	}
+	if(isset($_GET["start"])){
+		echo "_start=".$_GET["start"].";";
+	}
+	if(isset($_GET["end"])){
+		echo "_end=".$_GET["end"].";";
+	}
+
 	if(isset($_GET["mode"]) && $_GET["mode"]=="edit" && isset($_COOKIE["userid"])){
 		#登录状态下 编辑模式
 		$_mode = "edit";
@@ -147,7 +162,9 @@ span.fancytree-node{
 	font-size: 120%;
     font-weight: 900;
 }
-
+#article_path chapter{
+	display:unset;
+}
 </style>
 
 <?php
@@ -155,25 +172,47 @@ span.fancytree-node{
 ?>
 <div id="head_bar" >
 	<div style="display:flex;">
-	<div id="article_path" >
-	</div>
-	<div id="article_path_title"></div>
+	
 	</div>
 
 	<div style="margin: auto 0;">
 		<span id="head_span">
 		<?php
 		
-		if(isset($_GET["id"])){
+		if(isset($_GET["view"]) && $_GET["view"]=="article"){
 			echo "<button class='icon_btn'  title='{$_local->gui->modify} {$_local->gui->composition_structure}'>";
 			echo "<a href='../article/my_article_edit.php?id=".$_GET["id"];
 			echo "' target='_blank'>{$_local->gui->modify}</a></button>";
-			
+		}
 			echo "<button class='icon_btn'  title='{$_local->gui->add}{$_local->gui->subfield}'>";
-			echo "<a href='../article/frame.php?id=".$_GET["id"];
+			echo "<a href='../article/frame.php?view=".$_GET["view"];
+			if(isset($_GET["id"])){
+				echo "&id=".$_GET["id"];
+			}
+			if(isset($_GET["collection"])){
+				echo "&collection=".$_GET["collection"];
+			}
+			if(isset($_GET["channel"])){
+				echo "&channel=".$_GET["channel"];
+			}
+			if(isset($_GET["lang"])){
+				echo "&lang=".$_GET["lang"];
+			}
+			if(isset($_GET["book"])){
+				echo "&book=".$_GET["book"];
+			}
+			if(isset($_GET["par"])){
+				echo "&par=".$_GET["par"];
+			}
+			if(isset($_GET["start"])){
+				echo "&start=".$_GET["start"];
+			}
+			if(isset($_GET["end"])){
+				echo "$end=".$_GET["end"];
+			}
 			echo "'>{$_local->gui->add}{$_local->gui->subfield}</a></button>";	
-			
-		}
+				
+		
 
 		?>
 		<span>
@@ -184,6 +223,10 @@ span.fancytree-node{
 </div>
 <div id="main_view" class="main_view">
 <div id="article_head" style="border-bottom: 1px solid gray;">
+	<div style="display:flex;">
+		<div id="article_path" class=""></div>
+		<div id="article_path_title"></div>
+	</div>
 	<div id="article_title" class="term_word_head_pali"></div>
 	<div id="article_subtitle"></div>
 	<div id="article_author"></div>
@@ -252,23 +295,17 @@ span.fancytree-node{
 			collect_load(_collection_id);
 		break;
 		case "sent":
-		
-		break;
-		case "simsent":
-		
-		break;
 		case "para":
-		
-		break;
 		case "chapter":
-		
-		break;
 		case "book":
-		
-		break;
 		case "series":
-		
+			palicanon_load();
+			reader_get_path();
+			
 		break;
+		case "simsent":
+			palicanon_load();
+			break;
 		default:
 			break;
 	}

+ 11 - 0
app/article/style.css

@@ -163,3 +163,14 @@ img {
 .tool_bar {
 	display: flex;
 }
+
+
+.page_number {
+    padding: 2px 2px;
+    position: absolute;
+    margin-top: 0;
+    margin-left: -30px;
+    font-family: "Noto Sans", "Noto Sans SC", "Noto Sans TC", "Padauk", Arial, Verdana;
+    color: var(--main-color1);
+    font-size: 80%;
+}

+ 170 - 0
app/reader/get_para1.php

@@ -0,0 +1,170 @@
+<?php
+require_once "../public/_pdo.php";
+require_once "../path.php";
+require_once "../redis/function.php";
+require_once "../db/pali_sent.php";
+require_once "../db/pali_sim_sent.php";
+
+$mRedis = redis_connect();
+
+define("_MAX_CHAPTER_LEN_", 20000);
+
+if (isset($_GET["book"])) {
+    $_book = $_GET["book"];
+} else {
+    $_book = 0;
+}
+if (isset($_GET["par"])) {
+    $_para = $_GET["par"];
+} else {
+    $_para = 0;
+}
+
+if (isset($_GET["start"])) {
+    $_start = $_GET["start"];
+}
+if (isset($_GET["end"])) {
+    $_end = $_GET["end"];
+}
+$_view = $_GET["view"];
+
+$output["toc"] = array();
+$output["sentences"] = array();
+$output["head"] = 0;
+
+$output["title"]="";
+$output["subtitle"]="";
+$output["summary"]="";
+$output["content"]="";
+$output["owner"]="";
+$output["username"]=array("username"=>"","nickname"=>"");
+$output["status"]="";
+
+if ($_view == "sent") {
+    $output["content"] = "{{". $_book . "-" . $_para . "-". $_start . "-" . $_end . "}}";
+    echo json_encode($output, JSON_UNESCAPED_UNICODE);
+    exit;
+}
+if ($_view == "simsent") {
+	$mPaliSent = new PaliSentence($mRedis);
+	$mPaliSim = new PaliSimSentence($mRedis);
+	if(!isset($_GET["id"])){
+		$id = $mPaliSent->getId($_book,$_para,$_begin,$_end);
+	}
+	else{
+		$id = $_GET["id"];
+	}
+	{
+		$sent_list[] = $mPaliSent->getInfo($id);
+		$arrList = $mPaliSim->getSimById($id);
+		if($arrList){
+			foreach ($arrList as $key => $value) {
+				# code...
+				$sent_list = $mPaliSent->getInfo($value["id"]);
+				$output["content"] .= "{{". $sent_list["book"] . "-" . $sent_list["paragraph"] . "-". $sent_list["begin"] . "-" . $sent_list["end"] . "}}";
+			}
+			echo json_encode($output, JSON_UNESCAPED_UNICODE);
+		}
+	}
+	exit;
+}
+
+$paraBegin=0;
+$paraEnd=0;
+
+PDO_Connect(_FILE_DB_PALITEXT_);
+$query = "SELECT level , parent, chapter_len,chapter_strlen FROM 'pali_text'  WHERE book= ? AND paragraph= ?";
+$FetchParInfo = PDO_FetchRow($query, array($_book, $_para));
+if ($FetchParInfo) {
+    switch ($_view) {
+        case 'chapter':
+            # code...
+
+			if($FetchParInfo["level"]>0 && $FetchParInfo["level"]<8){
+				//是标题
+				$paraBegin = $_para;
+            	$paraEnd = $_para + $FetchParInfo["chapter_len"] - 1;
+			}
+            else{
+				#不是标题,加载所在段落
+				$paraBegin = $FetchParInfo["parent"];
+				$query = "SELECT  level , parent, chapter_len,chapter_strlen FROM 'pali_text'  WHERE book= ? AND paragraph= ?";
+				$FetchParInfo = PDO_FetchRow($query, array($_book, $paraBegin));
+            	$paraEnd = $paraBegin + $FetchParInfo["chapter_len"] - 1;
+			}
+            break;
+        case 'para':
+            $paraBegin = $_para;
+            $paraEnd = $_para;
+            # code...
+            break;
+        default:
+            # code...
+            $paraBegin = $_para;
+            $paraEnd = $_para;
+            break;
+    }
+
+    //获取下级目录
+    $query = "SELECT level,paragraph,toc FROM 'pali_text'  WHERE book= ? AND (paragraph BETWEEN ?AND ? ) AND level < 8 ";
+    $toc = PDO_FetchAll($query, array($_book, $paraBegin, $paraEnd));
+	if(count($toc)>0){
+		$output["title"] = $toc[0]["toc"];
+	}
+	if(count($toc)>1){
+		foreach ($toc as $key => $value) {
+			# code...
+			$output["content"] .= "- {$value["toc"]}\n";
+		}		
+	}
+
+
+    if ($FetchParInfo["chapter_strlen"] > _MAX_CHAPTER_LEN_ && $_view === "chapter" && count($output["toc"]) > 1) {
+        #文档过大,只加载目录
+		if ($toc[1]["paragraph"] - $_para > 1) {
+            # 中间有间隔
+            $paraBegin = $_para;
+            $paraEnd = $toc[1]["paragraph"] - 1;
+            $output["head"] = 1;
+        } else {
+            #中间无间隔
+            echo json_encode($output, JSON_UNESCAPED_UNICODE);
+            exit;
+        }
+    }
+
+    PDO_Connect(_FILE_DB_PALI_SENTENCE_);
+
+    $query = "SELECT book,paragraph,begin, end FROM 'pali_sent' WHERE book= ? AND (paragraph BETWEEN ? AND ? ) ";
+    $sent_list = PDO_FetchAll($query, array($_book, $paraBegin, $paraEnd));
+	$iCurrPara=0;
+	$output["sent_list"] = $sent_list;
+	foreach ($sent_list as $key => $value) {
+		# code...
+		if($value["paragraph"]!==$iCurrPara){
+			$output["content"] .= "\n\n";
+			$iCurrPara = $value["paragraph"];
+
+			if($_view=="chapter" && $paraBegin != $_para){
+				if($_para==$value["paragraph"]){
+					$output["content"] .= "<div id='para_focus' class='focus'>\n\n";
+				}
+			}
+			if($_view=="chapter" && $paraBegin!=$_para){
+				if($_para==$value["paragraph"]-1){
+					$output["content"] .= "\n\n</div>";
+				}
+			}
+			$output["content"] .= "<div class='page_number' page='{$iCurrPara}'>{$iCurrPara}</div>\n\n";			
+		}
+
+		$output["content"] .= "{{". $value["book"] . "-" . $value["paragraph"] . "-". $value["begin"] . "-" . $value["end"] . "}}";
+
+	}
+    
+    echo json_encode($output, JSON_UNESCAPED_UNICODE);
+
+} else {
+    echo json_encode($output, JSON_UNESCAPED_UNICODE);
+
+}