Преглед изворни кода

在note中新建或打开editor

visuddhinanda пре 5 година
родитељ
комит
5a67cf2eca

+ 2 - 5
app/article/index.php

@@ -285,17 +285,14 @@ require_once "../pcdl/html_head.php";
 </div>
 </div>
 
-<!-- ui-dialog -->
-<div id="dialog" title="Dialog Title">
-	<div id="edit_dialog_content"></div>
-</div>
+
 
 <script>
 	$(document).ready(function(){
 	ntf_init();				
 	click_dropdown_init();
 	note_create();
-	term_edit_dlg_init();
+
 	if(_collect_id==""){
 		articel_load(_articel_id);
 		articel_load_collect(_articel_id);

+ 1 - 1
app/doc/load_channal_para.php

@@ -36,7 +36,7 @@ else{
 	echo "        <ver>1</ver>\n";
 	echo "        <toc></toc>\n";
 	echo "        <style></style>\n";
-	echo "        <title>{$book}-{$para}</title>\n";
+	echo "        <title>{$book}-{$paralist[0]}</title>\n";
 	echo "    </head>\n";
 	echo "\n<dict></dict>\n";
 	echo "<message></message>\n";

+ 1 - 0
app/pcdl/html_head.php

@@ -58,6 +58,7 @@ else{
 		?>
 	<script src="../term/term_edit_dlg.js"></script>
 	<link type="text/css" rel="stylesheet" href="../term/term_edit_dlg.css"/>	
+	<script src="../uwbw/wbw_channal_list.js"></script>
 	
 	<script >
 	<?php require_once '../public/load_lang_js.php';?>

+ 0 - 5
app/reader/index.php

@@ -363,17 +363,12 @@ require_once "../pcdl/html_head.php";
 </div>
 </div>
 
-<!-- ui-dialog -->
-<div id="dialog" title="Dialog Title">
-	<div id="edit_dialog_content"></div>
-</div>
 
 <script>
 	$(document).ready(function(){
 	ntf_init();				
 	click_dropdown_init();
 	note_create();
-	term_edit_dlg_init();
 	reader_load();
 	});
 

+ 4 - 0
app/reader/reader.js

@@ -243,3 +243,7 @@ function set_channal(channalid) {
 	}
 	location.assign(url);
 }
+
+function edit_wbw(book, para) {
+	wbw_channal_list_open(book, [para]);
+}

+ 24 - 3
app/term/note.js

@@ -31,7 +31,13 @@ var _channalData;
 
 */
 function note_create() {
-	$("#dialog").dialog({
+	wbw_channal_list_init();
+	note_sent_edit_dlg_init();
+	term_edit_dlg_init();
+}
+function note_sent_edit_dlg_init() {
+	$("body").append('<div id="note_sent_edit_dlg" title="Edit"><div id="edit_dialog_content"></div></div>');
+	$("#note_sent_edit_dlg").dialog({
 		autoOpen: false,
 		width: 550,
 		buttons: [
@@ -51,7 +57,6 @@ function note_create() {
 		],
 	});
 }
-
 function note_init(input) {
 	let output = "<div>";
 	let newString = input.replace(/\{\{/g, '<note info="');
@@ -398,6 +403,18 @@ function note_json_html(in_json) {
 		gLocal.gui.copy_link +
 		"</a>";
 	output += "<a onclick='copy_text(this)'>" + gLocal.gui.copy + "“" + gLocal.gui.pāli + "”</a>";
+	output +=
+		"<a onclick=\"edit_in_studio('" +
+		in_json.book +
+		"','" +
+		in_json.para +
+		"','" +
+		in_json.begin +
+		"','" +
+		in_json.end +
+		"')\">" +
+		gLocal.gui.edit_now +
+		"</a>";
 	output += "<a onclick='add_to_list()'>" + gLocal.gui.add_to_edit_list + "</a>";
 	output += "</div>";
 	output += "</div>";
@@ -500,7 +517,7 @@ function note_edit_sentence(book, para, begin, end, channal) {
 		}
 	}
 
-	$("#dialog").dialog("open");
+	$("#note_sent_edit_dlg").dialog("open");
 }
 
 function note_sent_save() {
@@ -567,3 +584,7 @@ function copy_ref(book, para, begin, end) {
 	let strRef = "{{" + book + "-" + para + "-" + begin + "-" + end + "}}";
 	copy_to_clipboard(strRef);
 }
+
+function edit_in_studio(book, para, begin, end) {
+	wbw_channal_list_open(book, [para]);
+}

+ 271 - 0
app/uwbw/create_wbw.php

@@ -0,0 +1,271 @@
+<?php
+//工程文件操作
+//建立,
+require_once '../path.php';
+require_once "../public/_pdo.php";
+require_once "../public/function.php";
+define("MAX_LETTER" ,20000);
+
+$output["status"]=0;
+$output["error"]="";
+$output{"book"}="";
+$output{"para"}="";
+$output{"channel"}="";
+
+if(isset($_POST["book"])){
+    $_book = $_POST["book"];
+}
+else{
+    $output["status"]=1;
+    $output["error"]="#no_param book";
+    echo json_encode($output, JSON_UNESCAPED_UNICODE);
+    exit;
+}
+if(isset($_POST["para"])){
+    $_para = json_decode($_POST["para"]);
+}
+else{
+    $output["status"]=1;
+    $output["error"]="#no_param paragraph";
+    echo json_encode($output, JSON_UNESCAPED_UNICODE);
+    exit;
+}
+if(isset($_POST["channel"])){
+    $_channel = $_POST["channel"];
+}
+else{
+    $output["status"]=1;
+    $output["error"]="#no_param channel";
+    echo json_encode($output, JSON_UNESCAPED_UNICODE);
+    exit;
+}
+$output{"book"}=$_book;
+$output{"para"}=$_para;
+$output{"channel"}=$_channel;
+
+//判断单词数量 太大的不能加载
+PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
+$params = array(1, 21, 63, 171);
+/*  创建一个填充了和params相同数量占位符的字符串 */
+$place_holders = implode(',', array_fill(0, count($_para), '?'));
+
+$query = "SELECT sum(lenght) FROM pali_text WHERE   paragraph IN ($place_holders) AND book = ?";
+$param_letter = $_para;
+$param_letter[] = $_book;
+$sum_len = PDO_FetchOne($query,$param_letter);
+
+if($sum_len>MAX_LETTER){
+    $output["status"]=1;
+    $output["error"]="#oversize_to_load";
+    echo json_encode($output, JSON_UNESCAPED_UNICODE);
+    exit;
+}
+
+
+# 查询数据库是否有数据,没有就建立
+// 查询逐词解析库
+PDO_Connect("sqlite:"._FILE_DB_USER_WBW_);
+
+//模板库
+$db_tpl = "sqlite:"._DIR_PALICANON_TEMPLET_."/p".$_book."_tpl.db3";
+$dbh_tpl = new PDO($db_tpl, "", "");
+$dbh_tpl->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+
+#用户逐词译库
+$db_wbw = "sqlite:"._FILE_DB_USER_WBW_;
+$dbh_wbw= new PDO($db_wbw, "", "");
+$dbh_wbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+
+foreach ($_para as $key => $para) {
+    # code...
+    $query = "SELECT count(*) FROM wbw_block WHERE channal = ? AND book= ? and paragraph = ? ";
+    $FetchWBW = PDO_FetchOne($query,array($_channel,$_book,$para));
+    if($FetchWBW==0){
+        #建立
+        //写入数据库
+        // 开始一个事务,关闭自动提交
+        #更新block库
+        $block_id=UUID::v4();
+        $trans_block_id = UUID::v4();
+        $block_data = array($block_id,
+                                         "",
+                                         $_channel,
+                                         $_COOKIE["userid"],
+                                         $_book,
+                                         $para,
+                                         "",
+                                         $_POST["lang"],
+                                         1,
+                                         mTime(),
+                                         mTime()
+                                        );
+        $block_list[] = array("channal"=>$_channel,
+                                        "type"=>6,//word by word
+                                        "book"=>$_book,
+                                        "paragraph"=>$para,
+                                        "block_id"=>$block_id,
+                                        "readonly"=>false
+                                    );
+        $dbh_wbw->beginTransaction();
+        $query="INSERT INTO wbw_block ('id',
+                                                                 'parent_id',
+                                                                 'channal',
+                                                                 'owner',
+                                                                 'book',
+                                                                 'paragraph',
+                                                                 'style',
+                                                                 'lang',
+                                                                 'status',
+                                                                 'modify_time',
+                                                                 'receive_time')
+                                                  VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
+        $stmt_wbw = $dbh_wbw->prepare($query);
+        $stmt_wbw->execute($block_data);
+        // 提交更改 
+        $dbh_wbw->commit();
+        if (!$stmt_wbw || ($stmt_wbw && $stmt_wbw->errorCode() != 0)) {
+            $error = $dbh_wbw->errorInfo();
+            $output["status"]=1;
+            $output["error"]=$error[2];
+            echo json_encode($output, JSON_UNESCAPED_UNICODE);
+            eixt;
+        }
+
+        #逐词解析库
+        $query="SELECT * FROM 'main' WHERE paragraph = ? ";
+        
+        $sth = $dbh_tpl->prepare($query);
+        $sth->execute(array($para));
+        
+        $level=100;
+        $title="";
+        while($result = $sth->fetch(PDO::FETCH_ASSOC))
+        {
+            if($result["gramma"]=="?"){
+                $wGrammar="";
+            }
+            else{
+                $wGrammar=$result["gramma"];
+            }
+
+            $strXml="<word>";
+            $strXml.="<pali>{$result["word"]}</pali>";
+            $strXml.="<real>{$result["real"]}</real>";
+            $wordid = "p{$result["book"]}-{$result["paragraph"]}-{$result["wid"]}"; 
+            $strXml.="<id>{$wordid}</id>";
+            $strXml.="<type s=\"0\">{$result["type"]}</type>";
+            $strXml.="<gramma s=\"0\">{$wGrammar}</gramma>";
+            $strXml.="<mean s=\"0\"></mean>";
+            $strXml.="<org s=\"0\">".mb_strtolower($result["part"], 'UTF-8')."</org>";
+            $strXml.="<om s=\"0\"></om>";
+            $strXml.="<case s=\"0\">{$result["type"]}#{$wGrammar}</case>";
+            $strXml.="<style>{$result["style"]}</style>";
+            $strXml.="<status>0</status>";
+            $strXml.="</word>";
+            $wbw_data[] = array(UUID::v4(),
+                                              $block_id,
+                                              $_book,
+                                              $para,
+                                              $result["wid"],
+                                              $result["real"],
+                                              $strXml,
+                                              mTime(),
+                                              mTime(),
+                                              1,
+                                              $_COOKIE["userid"]
+                                            );
+        }
+                
+            // 开始一个事务,关闭自动提交
+
+            $dbh_wbw->beginTransaction();
+            $query="INSERT INTO wbw ('id',
+                                                           'block_id',
+                                                           'book',
+                                                           'paragraph',
+                                                           'wid',
+                                                           'word',
+                                                           'data',
+                                                           'modify_time',
+                                                           'receive_time',
+                                                           'status',
+                                                           'owner'
+                                                           ) 
+                                           VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
+            $stmt_wbw = $dbh_wbw->prepare($query);
+            foreach($wbw_data as $oneParam){
+                $stmt_wbw->execute($oneParam);
+            }
+            // 提交更改 
+            $dbh_wbw->commit();
+            if (!$stmt_wbw || ($stmt_wbw && $stmt_wbw->errorCode() != 0)) {
+                $error = $dbh_wbw->errorInfo();
+                $output["status"]=1;
+                $output["error"]=$error[2];
+                echo json_encode($output, JSON_UNESCAPED_UNICODE);
+                eixt;
+            }
+
+    }
+}
+
+/*TO DO 
+            //更新服务器端文件列表
+            $db_file = _FILE_DB_FILEINDEX_;
+            PDO_Connect("sqlite:$db_file");
+            $query="INSERT INTO fileindex ('id',
+                                        'parent_id',
+                                        'channal',
+                                        'user_id',
+                                        'book',
+                                        'paragraph',
+                                        'file_name',
+                                        'title',
+                                        'tag',
+                                        'status',
+                                        'create_time',
+                                        'modify_time',
+                                        'accese_time',
+                                        'file_size',
+                                        'share',
+                                        'doc_info',
+                                        'doc_block',
+                                        'receive_time'
+                                        ) 
+                            VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+            $stmt = $PDO->prepare($query);
+            $doc_id=UUID::v4();
+            $file_name = $book . '_' . $create_para . '_' . time();
+            $newData=array(
+                           $doc_id,
+                           "",
+                           $_POST["channal"],
+                           $uid,
+                           $book,
+                           $create_para,
+                           $file_name,
+                           $user_title,
+                           $tag,
+                           1,
+                           mTime(),
+                           mTime(),
+                           mTime(),
+                           $filesize,
+                           0,
+                           $doc_head,
+                           json_encode($block_list, JSON_UNESCAPED_UNICODE),
+                           mTime()
+                           );
+            $stmt->execute($newData);
+            if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+                $error = PDO_ErrorInfo();
+                echo "error - $error[2] <br>";
+            }
+            else{
+                echo "成功新建一个文件.";
+            }
+
+*/
+echo json_encode($output, JSON_UNESCAPED_UNICODE);
+
+?>

+ 79 - 0
app/uwbw/wbw_channal_list.js

@@ -0,0 +1,79 @@
+var _wbw_channel;
+function wbw_channal_list_init() {
+	$("body").append(
+		'<div id="wbw_channal_list_dlg" title="Open WBW"><div id="wbw_channal_list_dlg_content"></div></div>'
+	);
+	$("#wbw_channal_list_dlg").dialog({
+		autoOpen: false,
+		width: 550,
+		buttons: [
+			{
+				text: "Cancel",
+				click: function () {
+					$(this).dialog("close");
+				},
+			},
+		],
+	});
+}
+
+function wbw_channal_list_open(book, paralist) {
+	$.post(
+		"../uwbw/wbw_channel_list.php",
+		{
+			book: book,
+			para: JSON.stringify(paralist),
+		},
+		function (data) {
+			_wbw_channel = JSON.parse(data);
+			if (_wbw_channel.status == 0) {
+				let html = "";
+				let i = 0;
+				for (let index = 0; index < _wbw_channel.data.length; index++) {
+					const element = _wbw_channel.data[index];
+					html += "<div>";
+					html += "<span>";
+					html += "<button onclick=\"wbw_create('" + index + "')\">打开</button>";
+					html += "</span>";
+					html += "<span>" + i + "</span>";
+					html += "<span>" + element.name + "</span>";
+					html += "<span>" + element.lang + "</span>";
+					html += "<span>" + element.wbw_para + "/" + element.count + "</span>";
+					html += "</div>";
+				}
+
+				$("#wbw_channal_list_dlg_content").html(html);
+				$("#wbw_channal_list_dlg").dialog("open");
+			} else {
+				ntf_show(_wbw_channel.error);
+			}
+		}
+	);
+}
+
+function wbw_create(index) {
+	$.post(
+		"../uwbw/create_wbw.php",
+		{
+			book: _wbw_channel.book,
+			para: _wbw_channel.para,
+			lang: _wbw_channel.data[index].lang,
+			channel: _wbw_channel.data[index].id,
+		},
+		function (data) {
+			let msg = JSON.parse(data);
+			if (msg.status == 0) {
+				$("#wbw_channal_list_dlg_content").html("正在打开编辑窗口");
+				let book = msg.book;
+				let paralist = msg.para.join(",");
+				let channel = msg.channel;
+				let url =
+					"../studio/editor.php?op=openchannal&book=" + book + "&para=" + paralist + "&channal=" + channel;
+				window.open(url, "_blank");
+				$("#wbw_channal_list_dlg").dialog("close");
+			} else {
+				ntf_show(msg.error);
+			}
+		}
+	);
+}

+ 42 - 0
app/uwbw/wbw_channel_list.php

@@ -0,0 +1,42 @@
+<?php
+require_once '../path.php';
+require_once "../public/_pdo.php";
+require_once "../public/function.php";
+
+$output["status"]=0;
+$output["error"]="";
+$output["data"]="";
+if(!isset($_COOKIE["userid"])){
+    $output["status"]=1;
+    $output["error"]="#not_login";
+    echo json_encode(output, JSON_UNESCAPED_UNICODE);
+    exit;
+}
+
+    $_book = $_POST["book"];
+    $_para = json_decode($_POST["para"]);
+    $output["para"]=$_POST["para"];
+    $output["book"]=$_POST["book"];
+    
+    /*  创建一个填充了和params相同数量占位符的字符串 */
+    $place_holders = implode(',', array_fill(0, count($_para), '?'));
+    $params = $_para;
+    $params[]=$_book;
+
+    PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
+    $query = "SELECT * FROM channal WHERE owner = ?  LIMIT 0,100";
+    $FetchChannal = PDO_FetchAll($query,array($_COOKIE["userid"]));
+    $i=0;
+    foreach($FetchChannal as $key=>$row){
+        PDO_Connect("sqlite:"._FILE_DB_USER_WBW_);
+
+        $queryParam = $params;
+        $queryParam[]=$row["id"];
+        $query = "SELECT count(*) FROM wbw_block WHERE  paragraph IN ($place_holders)  AND book = ? AND channal = ? ";
+        $wbwCount = PDO_FetchOne($query,$queryParam);
+        $FetchChannal[$key]["wbw_para"] = $wbwCount;
+        $FetchChannal[$key]["count"] = count($_para);
+    }
+    $output["data"]=$FetchChannal;
+    echo json_encode($output, JSON_UNESCAPED_UNICODE);
+?>

+ 54 - 54
app/wiki/wiki.js

@@ -22,79 +22,79 @@ var _author = "";
 function wiki_index_init() {}
 
 function wiki_load_id(guid) {
-  note_lookup_guid_json(guid, "wiki_contents");
+	note_create();
+	note_lookup_guid_json(guid, "wiki_contents");
 }
 
 function wiki_load_word(word) {
-  term_get_word_to_div(word, "wiki_contents", wiki_word_loaded);
+	note_create();
+	term_get_word_to_div(word, "wiki_contents", wiki_word_loaded);
 }
 function wiki_goto_word(guid, strWord) {
-  window.open("wiki.php?word=" + strWord, "_blank");
+	window.open("wiki.php?word=" + strWord, "_blank");
 }
 function wiki_word_loaded(wordlist) {
-  $("#doc_title").text(
-    wordlist[0].word + "[" + wordlist[0].meaning + "]-圣典百科"
-  );
+	$("#doc_title").text(wordlist[0].word + "[" + wordlist[0].meaning + "]-圣典百科");
 }
 
 function term_show_win(guid, word) {
-  window.location.assign("wiki.php?word=" + word);
+	window.location.assign("wiki.php?word=" + word);
 }
 
 function wiki_search_keyup(e, obj) {
-  var keynum;
-  var keychar;
-  var numcheck;
+	var keynum;
+	var keychar;
+	var numcheck;
 
-  if ($("#wiki_search_input").val() == "") {
-    $("#search_result").html("");
-    return;
-  }
+	if ($("#wiki_search_input").val() == "") {
+		$("#search_result").html("");
+		return;
+	}
 
-  if (window.event) {
-    // IE
-    keynum = e.keyCode;
-  } else if (e.which) {
-    // Netscape/Firefox/Opera
-    keynum = e.which;
-  }
-  var keychar = String.fromCharCode(keynum);
-  if (keynum == 13) {
-    //dict_search(obj.value);
-  } else {
-    wiki_pre_search(obj.value);
-  }
+	if (window.event) {
+		// IE
+		keynum = e.keyCode;
+	} else if (e.which) {
+		// Netscape/Firefox/Opera
+		keynum = e.which;
+	}
+	var keychar = String.fromCharCode(keynum);
+	if (keynum == 13) {
+		//dict_search(obj.value);
+	} else {
+		wiki_pre_search(obj.value);
+	}
 }
 
 function wiki_pre_search(keyword) {
-  $.get(
-    "../term/term.php",
-    {
-      op: "pre",
-      word: keyword,
-      format: "json",
-    },
-    function (data, status) {
-      let result = JSON.parse(data);
-      let html = "<ul class='wiki_search_list'>";
-      if (result.length > 0) {
-        for (x in result) {
-          html +=
-            "<li><a href='wiki.php?op=get&word=" +
-            result[x].word +
-            "'>" +
-            result[x].word +
-            "[" +
-            result[x].meaning +
-            "]</a></li>";
-        }
-      }
-      html += "</ul>";
-      $("#search_result").html(html);
-    }
-  );
+	$.get(
+		"../term/term.php",
+		{
+			op: "pre",
+			word: keyword,
+			format: "json",
+		},
+		function (data, status) {
+			let result = JSON.parse(data);
+			let html = "<ul class='wiki_search_list'>";
+			if (result.length > 0) {
+				for (x in result) {
+					html +=
+						"<li><a href='wiki.php?op=get&word=" +
+						result[x].word +
+						"'>" +
+						result[x].word +
+						"[" +
+						result[x].meaning +
+						"]</a></li>";
+				}
+			}
+			html += "</ul>";
+			$("#search_result").html(html);
+		}
+	);
 }
 
 function set_channal(channalid) {
-  location.assign("../wiki/wiki.php?word=" + _word + "&channal=" + channalid);
+	location.assign("../wiki/wiki.php?word=" + _word + "&channal=" + channalid);
 }