瀏覽代碼

选经标题显示语言优化

visuddhinanda 5 年之前
父節點
當前提交
36a2ee5ad6

+ 10 - 11
app/palicanon/book_tag.php

@@ -2,18 +2,18 @@
 require_once '../path.php';
 
 $tag =  str_getcsv($_GET["tag"],",");//
-$arrBookTag=json_decode(file_get_contents("../public/book_tag/en.json"));
+$arrBookTag=json_decode(file_get_contents("../public/book_tag/en.json"),true);
 $countTag = count($tag);
 $output = array();
 foreach ($arrBookTag as $bookkey => $bookvalue) {
     $isfind = 0;
     foreach ($tag as $tagkey => $tagvalue) {
-        if(strpos($bookvalue->tag,':'.$tagvalue.':') !== FALSE){
+        if(strpos($bookvalue["tag"],':'.$tagvalue.':') !== FALSE){
             $isfind++;
         }
     }
     if($isfind==$countTag){
-        $output[] = array($bookvalue);
+        $output[] = $bookvalue;
     }
 }
 
@@ -35,22 +35,23 @@ $dbh_res->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
 foreach ($output as $key => $value) {
 	# code...
-		$book = (int)$value[0]->book;
-		$para = (int)$value[0]->para;
-		$level = (int)$value[0]->level;
+	$book = (int)$value["book"];
+	$para = (int)$value["para"];
+	$level = (int)$value["level"];
 	if(count($output)<100 || (count($output)>100 && $level==1)){
 		$query = "SELECT * FROM pali_text WHERE book = ? and paragraph = ?";
 		$stmt = $dbh_pali_text->prepare($query);
 		$stmt->execute(array($book,$para));
 		$paraInfo = $stmt->fetch(PDO::FETCH_ASSOC);
+
 		if($paraInfo){	
 			# 查进度
 			$query = "SELECT lang, all_trans from progress_chapter where book=? and para=?";
 			$stmt = $dbh_toc->prepare($query);
 			$sth_toc = $dbh_toc->prepare($query);
 			$sth_toc->execute(array($book,$para));
-			$paraProgress = $sth_toc->fetchAll(PDO::FETCH_ASSOC);
-			$output[$key][0]->progress=$paraProgress;
+			$paraProgress = $sth_toc->fetch(PDO::FETCH_ASSOC);
+			$output[$key]["progress"]=$paraProgress;
 		
 			#查标题
 			if(isset($_GET["lang"])){
@@ -60,13 +61,11 @@ foreach ($output as $key => $value) {
 				$sth_title->execute(array($book,$para,$_GET["lang"]));
 				$trans_title = $sth_title->fetch(PDO::FETCH_ASSOC);
 				if($trans_title){
-					$output[$key][0]->trans_title=$trans_title['title'];
+					$output[$key]["trans_title"]=$trans_title['title'];
 				}
 			}
 		}
-
 	}
-	
 }
 
 echo json_encode($output, JSON_UNESCAPED_UNICODE);

+ 1 - 1
app/palicanon/get_chapter_children.php

@@ -40,7 +40,7 @@ if($paraInfo){
 			$stmt = $dbh_toc->prepare($query);
 			$sth_toc = $dbh_toc->prepare($query);
 			$sth_toc->execute(array($value["book"],$value["para"]));
-			$paraProgress = $sth_toc->fetchAll(PDO::FETCH_ASSOC);
+			$paraProgress = $sth_toc->fetch(PDO::FETCH_ASSOC);
 			$paraList[$key]["progress"]=$paraProgress;
 
 			#查标题

+ 32 - 14
app/palicanon/palicanon.js

@@ -54,11 +54,19 @@ function tag_changed() {
 		strTags = main_tag;
 	}
 	console.log(strTags);
+	let lang = getCookie("language");
+	if (lang == "zh-cn") {
+		lang = "zh-hans";
+	} else if (lang == "zh-tw") {
+		lang = "zh-hant";
+	} else if (lang == "") {
+		lang = "en";
+	}
 	$.get(
 		"book_tag.php",
 		{
 			tag: strTags,
-			lang: "zh-hant",
+			lang: lang,
 		},
 		function (data, status) {
 			let arrBookList = JSON.parse(data);
@@ -68,7 +76,7 @@ function tag_changed() {
 
 			for (const iterator of arrBookList) {
 				let tag0 = "";
-				let tags = iterator[0].tag.split("::");
+				let tags = iterator.tag.split("::");
 				let currTag = new Array();
 				currTag[main_tag] = 1;
 				for (const scondTag of list_tag) {
@@ -93,14 +101,8 @@ function tag_changed() {
 					}
 				}
 
-				if (arrBookList.length < 100 || (arrBookList.length > 100 && iterator[0].level == 1)) {
-					arrChapter.push({
-						book: iterator[0].book,
-						para: iterator[0].para,
-						level: iterator[0].level,
-						title: iterator[0].title,
-						progress: [],
-					});
+				if (arrBookList.length < 100 || (arrBookList.length > 100 && iterator.level == 1)) {
+					arrChapter.push(iterator);
 				}
 			}
 
@@ -119,14 +121,30 @@ function tag_changed() {
 }
 
 function palicanon_load_chapter(book, para, div_index = 1) {
+	let lang = getCookie("language");
+	if (lang == "zh-cn") {
+		lang = "zh-hans";
+	} else if (lang == "zh-tw") {
+		lang = "zh-hant";
+	} else if (lang == "") {
+		lang = "en";
+	}
 	$.get(
 		"get_chapter_children.php",
 		{
 			book: book,
 			para: para,
-			lang: "zh-hant",
+			lang: lang,
 		},
 		function (data, status) {
+			let lang = getCookie("language");
+			if (lang == "zh-cn") {
+				lang = "zh-hans";
+			} else if (lang == "zh-tw") {
+				lang = "zh-hant";
+			} else if (lang == "") {
+				lang = "en";
+			}
 			let arrChapterList = JSON.parse(data);
 			palicanon_chapter_list_apply(arrChapterList, div_index);
 			$.get(
@@ -134,7 +152,7 @@ function palicanon_load_chapter(book, para, div_index = 1) {
 				{
 					book: book,
 					para: para,
-					lang: "zh-hant",
+					lang: lang,
 				},
 				function (data, status) {
 					let arrChapterInfo = JSON.parse(data);
@@ -251,10 +269,10 @@ function palicanon_render_chapter_row(chapter) {
 	html += '	<div class="title_2" lang="pali">' + chapter.title + "</div>";
 	html += "</div>";
 	html += '<div class="resource">';
-	if (chapter.progress && chapter.progress.length > 0) {
+	if (chapter.progress) {
 		let r = 12;
 		let perimeter = 2 * Math.PI * r;
-		let stroke1 = parseInt(perimeter * chapter.progress[0].all_trans);
+		let stroke1 = parseInt(perimeter * chapter.progress.all_trans);
 		let stroke2 = perimeter - stroke1;
 		html += '<svg class="progress_circle" width="30" height="30" viewbox="0,0,30,30">';
 		html += '<circle class="progress_bg" cx="15" cy="15" r="12" stroke-width="5"  fill="none"></circle>';

+ 4 - 1
app/palicanon/style.css

@@ -55,6 +55,9 @@
 	font-size: 80%;
 	color: unset;
 }
+.chapter_list .title {
+	text-transform: capitalize;
+}
 .chapter_list .title div:lang(pali) {
 	font-size: 80%;
 }
@@ -63,7 +66,7 @@
 	background-color: chocolate;
 	color: whitesmoke;
 }
-
+/*書標題特殊樣式*/
 .chapter_list .level_1 {
 	background: linear-gradient(45deg, brown 20%, transparent 90%);
 	color: whitesmoke;

+ 19 - 0
app/upgrade/pali_toc_create.php

@@ -0,0 +1,19 @@
+<?php
+#升级段落完成度数据库
+require_once '../path.php';
+
+
+$dns = "sqlite:"._FILE_DB_PALI_TOC_;
+$dbh_toc = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
+$dbh_toc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
+
+//建立数据库
+$_sql = file_get_contents("pali_toc.sql");
+$_arr = explode(';', $_sql);
+//执行sql语句
+foreach ($_arr as $_value) {
+	$dbh_toc->query($_value.';');
+}
+echo $dns."建立数据库成功";
+
+?>

+ 2 - 0
pali_title/10_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p10,2,1,book,Subodhālaṅkāro,明瞭解意,system

+ 2 - 0
pali_title/11_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p11,2,1,book,Subodhālaṅkāraṭīkā,明瞭解意疏,system

+ 2 - 0
pali_title/12_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p12,2,1,book,Bālāvatāra,巴利初學入門,system

+ 2 - 0
pali_title/13_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p13,2,1,book,Moggallānasuttapāṭho,摩嘎拉那語法,system

+ 2 - 0
pali_title/14_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p14,2,1,book,Kaccāyanabyākaraṇaṃ,咖吒亞那語法,system

+ 2 - 0
pali_title/15_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p15,2,1,book,"Saddanītippakaraṇaṃ (padamālā)","論語法(一)",system

+ 2 - 0
pali_title/16_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p16,2,1,book,"Saddanītippakaraṇaṃ (dhātumālā)","論語法(二)",system

+ 2 - 0
pali_title/17_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p17,2,1,book,Padarūpasiddhi,句身成就,system

+ 2 - 0
pali_title/18_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p18,2,1,book,"Moggallāna pañcikā ṭīkā","摩嘎拉那潘基卡",system

+ 2 - 0
pali_title/1_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p1,2,1,book,Namakkārapāḷi,禮敬複註,system

+ 2 - 0
pali_title/2_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p2,2,1,book,Mahāpaṇāmapāṭha,大禮敬,system

+ 2 - 0
pali_title/3_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p3,2,1,book,Lakkhaṇāto,品質——佛之禮贊偈,system

+ 2 - 0
pali_title/4_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p4,2,1,chapter,Suttavandanā,禮敬經典,system

+ 2 - 0
pali_title/5_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p5,2,1,book,Jinālaṅkāra,勝者莊嚴,system

+ 2 - 0
pali_title/6_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p6,2,1,chapter,Kamalāñjali,蓮花合掌,system

+ 2 - 0
pali_title/7_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p7,2,1,chapter,Pajjamadhu,道之蜜,system

+ 2 - 0
pali_title/8_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p8,2,1,chapter,Buddhaguṇagāthāvalī,佛陀功德頌,system

+ 2 - 0
pali_title/9_zh-hant.csv

@@ -0,0 +1,2 @@
+id,book,par_num,level,class,title,text,author
+NULL,p9,2,1,book,Abhidhānappadīpikāṭīkā,名詞燈明疏,system