Mercurial > hg > extraction-interface
changeset 4:883ad980a43b
add dynasty column to table books
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/add_dynasty.php Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,99 @@ +<?php + +include_once('Lib_mb_utf8.php'); +include_once('config.php'); +set_time_limit(0); +ini_set('memory_limit', '-1'); + +$link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); +mysql_query("SET NAMES utf8"); + +if (!$link_mysql) { + die('Could not connect: ' . mysql_error()); +} + +$db_selected = mysql_select_db($mysql_database, $link_mysql); +if (!$db_selected) { + die ('Can\'t use foo : ' . mysql_error()); +} + + +function add_dynasty($dynasty_info){ + $dynasty = $dynasty_info[0]; + $start_year = $dynasty_info[1]; + $end_year = $dynasty_info[2]; + + $dir_path = "dynasty_period_list/"; + $myfile = fopen($dir_path.$dynasty.".txt", "r") or die("Unable to open file!"); + + // Output one line until end-of-file + while(!feof($myfile)) { + $line = fgets($myfile); + $splited_line = preg_split('/\r\n|\r|\n/', $line); + $matched_period = $splited_line[0]; + + $query="SELECT id, period, start_year FROM books WHERE period='".$matched_period."'"; + + $result=mysql_query($query); + + if(!$result){ + echo json_encode("Failed during querying records."); + return; + } + while($row=mysql_fetch_assoc($result)){ + echo $row['id']." ".$row['period']."<br>"; + if ($row['start_year'] > ($start_year-10) && $row['start_year'] < ($end_year+10)) { + // write $dynasty into record + $query="UPDATE books SET dynasty='".$dynasty."' WHERE id='".$row['id']."'"; + $res=mysql_query($query); + if(!$res){ + echo json_encode("Failed during querying records."); + return; + } + } + + } + echo "----------".$matched_period." books number: ".mysql_num_rows($result)."<br>"; + } + + fclose($myfile); + +} + + + +$dynasty = array("漢",-140,200); +add_dynasty($dynasty); +$dynasty = array("三國",220,280); +add_dynasty($dynasty); +$dynasty = array("晉",265,420); +add_dynasty($dynasty); +$dynasty = array("南北朝",386,589); +add_dynasty($dynasty); +$dynasty = array("隋",581,618); +add_dynasty($dynasty); +$dynasty = array("唐",618,907); +add_dynasty($dynasty); +$dynasty = array("五代",907,959); +add_dynasty($dynasty); +$dynasty = array("宋",960,1279); +add_dynasty($dynasty); +$dynasty = array("遼",916,1125); +add_dynasty($dynasty); +$dynasty = array("金",1115,1234); +add_dynasty($dynasty); +$dynasty = array("元",1260,1367); +add_dynasty($dynasty); +$dynasty = array("西夏",1032,1227); +add_dynasty($dynasty); +$dynasty = array("明",1368,1644); +add_dynasty($dynasty); +$dynasty = array("清",1616,1911); +add_dynasty($dynasty); +$dynasty = array("民國",1911,9999); +add_dynasty($dynasty); + + +// dynasty list ref: http://dict.revised.moe.edu.tw/htm/fulu/nh.htm + +?> \ No newline at end of file
--- a/interface/add_missing_books_to_sections.php Mon Jan 26 12:19:39 2015 +0100 +++ b/interface/add_missing_books_to_sections.php Tue Jan 27 16:40:30 2015 +0100 @@ -16,19 +16,11 @@ if (!$db_selected) { die ('Can\'t use foo : ' . mysql_error()); } -?> -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<html> - <head - </head> - <body> - <?php - add_missing_books_to_sections(); - - ?> - </body> -</html> +add_missing_books_to_sections(); + + + \ No newline at end of file
--- a/interface/check_sections.php Mon Jan 26 12:19:39 2015 +0100 +++ b/interface/check_sections.php Tue Jan 27 16:40:30 2015 +0100 @@ -71,18 +71,19 @@ function checkSections_sort_by($sort_by){ switch ($sort_by) { case 'time': - $query="(SELECT name AS book_name,level1,level2,period,start_year,id from books ORDER BY start_year)"; + $query="(SELECT name AS book_name,level1,level2,period,dynasty,start_year,id from books ORDER BY start_year)"; $result = mysql_query($query); echo mysql_num_rows($result)." result(s)<br><br>"; echo "<table>"; echo "<tr>"; - echo "<td class='bookName'>book name<td class='level1'>level1<td class='level2'>level2<td class='period'>period<td class='start_year'>start_year"; + echo "<td class='bookName'>book name<td class='level1'>level1<td class='level2'>level2<td class='period'>period<td class='dynasty'>dynasty<td class='start_year'>start_year"; while ($row = mysql_fetch_assoc($result)) { $str="<tr>"; $str.="<td>".$row['book_name']; $str.="<td>".$row['level1']; $str.="<td>".$row['level2']; $str.="<td>".$row['period']; + $str.="<td>".$row['dynasty']; $str.="<td>".$row['start_year']; $str.="<td><a href='check_sections_details.php?book_id=".$row['id']."&count=100"."' target='_blank'>"."click here"."</a>"; echo $str; @@ -106,7 +107,7 @@ <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link href="css/search.css" type="text/css" rel="stylesheet"/> - <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> <!--<script src="js/check_sections.js" charset="utf-8"></script>!--> </head> <body>
--- a/interface/check_sections_details.php Mon Jan 26 12:19:39 2015 +0100 +++ b/interface/check_sections_details.php Tue Jan 27 16:40:30 2015 +0100 @@ -100,13 +100,13 @@ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> - <link href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" type="text/css" rel="stylesheet"/> + <link href="https://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" type="text/css" rel="stylesheet"/> <!-- <link href="css/search.css" type="text/css" rel="stylesheet"/> --> <link href="css/check_sections.css" type="text/css" rel="stylesheet"/> - <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> <script src="js/check_sections_details.js" type="text/javascript"></script> - <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js" type="text/javascript"></script> + <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js" type="text/javascript"></script> <!--<script src="js/check_sections.js" charset="utf-8"></script>!--> </head> <body>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/三國.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,33 @@ +黃初 +太和 +青龍 +景初 +正始 +嘉平 +正元 +甘露 +景元 +咸熙 +章武 +建興 +延熙 +景耀 +炎興 +黃武 +黃龍 +嘉禾 +赤烏 +太元 +神鳳 +建興 +五鳳 +太平 +永安 +元興 +甘露 +寶鼎 +建衡 +鳳凰 +天鍹 +天璽 +天紀 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/五代.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,15 @@ +開平 +乾化 +貞明 +龍德 +同光 +天成 +長興 +應順 +清泰 +天福 +開運 +天福 +乾祐 +廣順 +顯德 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/元.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,15 @@ +中統 +至元 +元貞 +大德 +至大 +皇慶 +延祐 +至治 +泰定 +致和 +天曆 +至順 +元統 +至元 +至正 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/南北朝.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,93 @@ +永初 +景平 +元嘉 +孝建 +大明 +永光 +景和 +泰始 +泰豫 +元徽 +昇明 +建元 +永明 +隆昌 +延興 +建武 +永泰 +永元 +中興 +天監 +普通 +大通 +中大通 +大同 +中大同 +太清 +大寶 +天正 +承聖 +天成 +紹泰 +太平 +永定 +天嘉 +天康 +光大 +太建 +至德 +禎明 +登國 +皇始 +天興 +天賜 +永興 +神瑞 +泰常 +始光 +神麚 +延和 +太延 +太平真君 +正平 +承平 +興安 +興光 +太安 +和平 +天安 +皇興 +延興 +承明 +太和 +景明 +正始 +永平 +延昌 +熙平 +神龜 +正光 +孝昌 +武泰 +建義 +永安 +建明 +普泰 +中興 +太昌 +永興 +永熙 +天平 +元象 +興和 +武定 +大統 +天保 +乾明 +皇建 +太寧 +河清 +天統 +武平 +隆化 +承光 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/唐.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,57 @@ +武德 +貞觀 +永徽 +顯慶 +龍朔 +麟德 +乾封 +總章 +咸亨 +上元 +儀鳳 +調露 +永隆 +開耀 +永淳 +弘道 +嗣聖 +神龍 +景龍 +唐隆 +景雲 +太極 +延和 +先天 +開元 +天寶 +至德 +乾元 +上元 +寶應 +廣德 +永泰 +大曆 +建中 +興元 +貞元 +永貞 +元和 +長慶 +寶曆 +太和 +開成 +會昌 +大中 +咸通 +乾符 +廣明 +中和 +光啟 +文德 +龍紀 +大順 +景福 +乾寧 +光化 +天復 +天祐 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/宋.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,57 @@ +建隆 +乾德 +開寶 +太平興國 +雍熙 +端拱 +淳化 +至道 +咸平 +景德 +大中祥符 +天禧 +乾興 +天聖 +明道 +景祐 +寶元 +康定 +慶曆 +皇祐 +至和 +嘉祐 +治平 +熙寧 +元豐 +元祐 +紹聖 +元符 +建中靖國 +崇寧 +大觀 +政和 +重和 +宣和 +靖康 +建炎 +紹興 +隆興 +乾道 +淳熙 +紹熙 +慶元 +嘉泰 +開禧 +嘉定 +寶慶 +紹定 +端平 +嘉熙 +淳祐 +寶祐 +開慶 +景定 +咸淳 +德祐 +景炎 +祥興 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/明.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,21 @@ +洪武 +建文 +永樂 +洪熙 +宣德 +正統 +景泰 +天順 +成化 +弘治 +正德 +嘉靖 +隆慶 +萬曆 +萬厯 +萬歷 +泰昌 +天啟 +天啓 +崇禎 +永曆 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/晉.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,36 @@ +泰始 +咸寧 +太康 +太熙 +永熙 +永平 +元康 +永康 +永寧 +太安 +永安 +建武 +永安 +永興 +光熙 +永嘉 +建興 +建武 +太興 +永昌 +太寧 +咸和 +咸康 +建元 +永和 +升平 +隆和 +興寧 +太和 +咸安 +寧康 +太元 +隆安 +元興 +義熙 +元熙 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/民國.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,1 @@ +民國 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/清.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,15 @@ +天命 +天聰 +崇德 +順治 +康熙 +雍正 +乾隆 +嘉慶 +嘉靖 +道光 +咸豐 +同治 +光緒 +光緖 +宣統 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/漢.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,83 @@ +建元 +崇正 +元光 +元朔大徳 +元狩 +元鼎 +元封 +太初 +天漢 +太始 +征和 +後元 +始元 +元鳳 +元平 +本始 +地節 +元康 +神爵 +五鳳 +甘露 +黃龍 +初元 +永光 +建昭 +竟寧 +建始 +河平 +陽朔 +鴻嘉 +永始 +元延 +綏和 +建平 +元壽 +元始 +居攝 +初始 +更始 +始建國 +天鳳 +地皇 +建武 +建武中元 +中元 +永平 +建初 +元和 +章和 +永元 +元興 +延平 +永初 +元初 +永寧 +建光 +延光 +永建 +陽嘉 +永和 +漢安 +建康 +永喜 +本初 +建和 +和平 +元嘉 +永興 +永壽 +延熹 +永康 +建寧 +熹平 +光和 +中平 +光熹 +昭寧 +永漢 +中平 +初平 +興平 +建安 +延康 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/西夏.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,32 @@ +顯道 +開運 +廣運 +大慶 +天授禮法延祚 +延嗣寧國 +天祐垂聖 +福聖承道 +奲都 +拱化 +乾道 +天賜禮盛國慶 +大安 +天安禮定 +天儀治平 +天祐民安 +永安 +貞觀 +雍寧 +元德 +正德 +大德 +大慶 +人慶 +天盛 +乾祐 +天慶 +應天 +皇建 +光定 +乾定 +寶義 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/遼.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,22 @@ +神冊 +天贊 +天顯 +會同 +大同 +天祿 +應曆 +保寧 +乾亨 +統和 +開泰 +太平 +景福 +重熙 +清寧 +咸雍 +太康 +大安 +壽昌 +乾統 +天慶 +保大 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/金.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,21 @@ +收國 +天輔 +天會 +天眷 +皇統 +天德 +貞元 +正隆 +大定 +明昌 +承安 +泰和 +大安 +崇慶 +至寧 +貞祐 +興定 +元光 +正大 +開興 +天興 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/dynasty_period_list/隋.txt Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,4 @@ +開皇 +仁壽 +大業 +義寧 \ No newline at end of file
--- a/interface/intermediate_results/missing_books.csv Mon Jan 26 12:19:39 2015 +0100 +++ b/interface/intermediate_results/missing_books.csv Tue Jan 27 16:40:30 2015 +0100 @@ -398,6 +398,7 @@ 38467,"興平縣志" 17469,"興平縣志" 38409,"三原縣志" +40265,"武功縣志" 35460,"武功縣續志" 38395,"華州志" 38429,"郃陽縣志"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interface/tagging_text_20150127.php Tue Jan 27 16:40:30 2015 +0100 @@ -0,0 +1,1155 @@ +<?php +header("Content-Type: text/html;charset=utf-8"); + +if (isset($_GET['id'])) { + $section_id = $_GET['id']; +} else { + $get_book_id = $_GET['book']; + $get_start = $_GET['start']; + $get_end = $_GET['end']; +} + +include_once('Lib_mb_utf8.php'); +include_once('config.php'); + +set_time_limit(0); +ini_set('memory_limit', '-1'); + +$link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); +mysql_query("SET NAMES utf8"); + +if (!$link_mysql) { + die('Could not connect: ' . mysql_error()); +} + +$db_selected = mysql_select_db($mysql_database, $link_mysql); +if (!$db_selected) { + die ('Can\'t use foo : ' . mysql_error()); +} + +if (!function_exists("GetSQLValueString")) { +function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") +{ + $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; + + $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); + + switch ($theType) { + case "text": + $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; + break; + case "long": + case "int": + $theValue = ($theValue != "") ? intval($theValue) : "NULL"; + break; + case "double": + $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; + break; + case "date": + $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; + break; + case "defined": + $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; + break; + } + return $theValue; +} +} + +$query = sprintf("SELECT * FROM `sections` WHERE `id`=\"%s\"", $section_id); +$result = mysql_query($query); +while ($row = mysql_fetch_assoc($result)) { + $bookId=$row['books_id']; + $startPage=$row['start_page']; + $endPage=$row['end_page']; +} + +$contentString=""; +if ( file_exists("parsing_files/".$section_id.".txt") ) { + $contentString=file_get_contents("parsing_files/".$section_id.".txt"); + $stringInput = $contentString; + $stringInput = preg_replace("/ /u", "○", $stringInput); + $stringInput = preg_replace("/\n/u", "<br>", $stringInput); + $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); +} else { + $query = sprintf("SELECT `content`, `line`, `books_id` FROM `contents` WHERE `books_id`=\"%s\" AND `line`>=%d AND `line`<=%d", $bookId, $startPage, $endPage); + $result = mysql_query($query); + while ($row = mysql_fetch_assoc($result)) { + $contentString.="【".$row['line']."】".$row['content']."\n"; + } + $stringInput = $contentString; + $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput); + $stringInput = preg_replace("/ /u", "○", $stringInput); + $stringInput = preg_replace("/\n/u", "<br>", $stringInput); + $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); +} + + +$taglistArray=""; +$query = sprintf("SELECT * FROM `taglist` WHERE `systemName`='%s' ORDER BY `tag` ASC", $systemNAME); +$result = mysql_query($query); +while ($row = mysql_fetch_assoc($result)) { + $taglistArray[] = array( $row['id'], $row['name'], $row['tag'], $row['color'] ); +} + +function sortFunction($a,$b) { + return strlen($b)-strlen($a); +} + +$wordlistArray=""; +$query = sprintf("SELECT * FROM `wordlist` WHERE `systemName`='%s' ORDER BY `name` ASC", $systemNAME); +$result = mysql_query($query); +while ($row = mysql_fetch_assoc($result)) { + $listString = file_get_contents("wordlist/".$row['id'].".txt"); + $listString = preg_replace("/<div>/u", "\n", $listString); + $listString = preg_replace("/<\/div>/u", "", $listString); + $listString = preg_replace("/<span(.*?)>/u", "", $listString); + $listString = preg_replace("/<\/span>/u", "", $listString); + //$listString = preg_replace("/\n/u", "|", $listString); + + $wordlistArray2 = explode( "\n", $listString ); + usort($wordlistArray2,'sortFunction'); + foreach ( $wordlistArray2 as $index=>$value ) { + $wordlistArray2[$index] = implode("○?", preg_split("/(?<!^)(?!$)/u", $value)); + } + foreach ( $wordlistArray2 as $index=>$value ) { + if ($value=="") unset($wordlistArray2[$index]); + + } + $listString = implode("|", $wordlistArray2); + + if ( $listString[0]=="|" ) $listString = substr($listString, 1); + $wordlistArray[] = array( $row['id'], $row['name'], $listString ); +} + +?> + +<html> +<head> +<title></title> +<script src="./jquery-1.10.2.min.js"></script> +<style> +dynasty +{ + color:red; +} +nianhao +{ + color:blue; +} +name +{ + color:orange; +} +#editable-area { + line-height:160%; + letter-spacing:1.5px; + font-size:21px; +} +<?php +foreach ( $taglistArray as $taglistValue ) { + echo $taglistValue[2]."\n{\ncolor:".$taglistValue[3]."\n}\n"; + + echo ".span_".$taglistValue[2]."\n{\nbackground-color:".$taglistValue[3]."\n}\n"; +} +?> +</style> +<script type="text/javascript"> +var stringBeforeChange=""; +var stringBeforeChangeStack = []; +var lastAddTag=""; + +window.onbeforeunload = function() { + return "Are you sure?"; +}; + +$(document).ready(function(){ + //run once + var el=$('#follow-scroll'); + var originalelpos=el.offset().top; // take it where it originally is on the page + + //run on scroll + $(window).scroll(function(){ + var el = $('#follow-scroll'); // important! (local) + var elpos = el.offset().top; // take current situation + var windowpos = $(window).scrollTop(); + var finaldestination = windowpos+originalelpos; + el.stop().animate({'top':finaldestination},500); + }); +}); + +/* +$(document).on("mouseup", function (e) { + e.stopPropagation(); + $('.questionMarkClass').remove(); + $('.tagItemDivClass').remove(); + alert("Remove"); +}); + + +$(document).on("click", '.questionMarkClass', function (e) { + e.stopPropagation(); +}); +*/ + +function removeTagNewDiv( eventObject, tagName, tagObject ) { + saveUndoText(); + var newdiv = document.createElement("div"); + newdiv.id = "questionMarkId"; + newdiv.setAttribute("class", "questionMarkClass"); + newdiv.style.cssText = 'top:'+eventObject.pageY+'; left:'+eventObject.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px'; + newdiv.innerHTML = "Tag: "+tagName+"<br>Value: "+tagObject.text()+"<br>"; + + + var newbutton = $('<button>Remove this</button>').mouseup(function (e2) { + var textKeep = $(this).parent().parent().html(); + var regexText=/<div(.*?)<\/div>/g; + var replaceText=""; + textKeep = textKeep.replace(regexText, replaceText); + + $(this).parent().parent().replaceWith( textKeep ); + }); + newbutton.appendTo(newdiv); + + var newbutton = $('<button>Remove this(with newline)</button>').mouseup(function (e2) { + var textKeep = $(this).parent().parent().html(); + var regexText=/<div(.*?)<\/div>/g; + var replaceText=""; + textKeep = textKeep.replace(regexText, replaceText); + + var newLineBefore = $(this).parent().parent().prev(); + if ( newLineBefore.prop("tagName") == "BR" ) { + $(this).parent().parent().prev().replaceWith( ); + } + $(this).parent().parent().replaceWith( textKeep ); + }); + newbutton.appendTo(newdiv); + + var newbutton = $('<button>Remove all</button>').mouseup(function (e2) { + var textKeep = $(this).parent().parent().html(); + var regexText=/<div(.*?)<\/div>/g; + var replaceText=""; + textKeep = textKeep.replace(regexText, replaceText); + + $(this).parent().parent().replaceWith( textKeep ); + + var el = document.getElementById("editable-area"); + var regexText=new RegExp("<"+tagName+">("+textKeep+")</"+tagName+">", "g"); + var replaceText="$1"; + var str="" + el.innerHTML; + + if ( str.match(regexText)==null ) { + alert( "Removed 1 entity!" ); + } else { + alert( "Removed "+(parseInt(str.match(regexText).length)+1)+" entities!" ); + } + el.innerHTML = str.replace(regexText, replaceText); + }); + newbutton.appendTo(newdiv); + + var newbutton = $('<button>Remove all(with newline)</button>').mouseup(function (e2) { + var textKeep = $(this).parent().parent().html(); + var regexText=/<div(.*?)<\/div>/g; + var replaceText=""; + textKeep = textKeep.replace(regexText, replaceText); + + $(this).parent().remove(); + + var el = document.getElementById("editable-area"); + var regexText=new RegExp("<br><"+tagName+">("+textKeep+")</"+tagName+">", "g"); + var replaceText="$1"; + var str="" + el.innerHTML; + + alert( "Removed "+str.match(regexText).length+" entities!" ); + el.innerHTML = str.replace(regexText, replaceText); + }); + newbutton.appendTo(newdiv); + + tagObject.append(newdiv); +} + + +<?php +foreach ( $taglistArray as $taglistValue ) { + echo '$(document).on("click", "'.$taglistValue[2].'", function (e) {'."\n"; + echo "\t".'if ( $(this).prop("tagName").toLowerCase() != "'.$taglistValue[2].'" ) return 0;'."\n"; + echo "\t".'if ( $("#editTextId").html() != "Edit the text" ) return 0;'."\n"; + echo "\tremoveTagNewDiv( e, \"".$taglistValue[2]."\", $(this) );\n"; + echo "});\n"; +} +?> +$(document).on("click", "name", function (e) { + if ( $("#editTextId").html() != "Edit the text" ) return 0; + if ( $(this).prop("tagName").toLowerCase() != "name" ) return 0; + removeTagNewDiv( e, "name", $(this) ); +}); + +$(document).on("mouseup", '#editable-area', function (e) { + $('.questionMarkClass').remove(); + $('.tagItemDivClass').remove(); + + if ( $("#editTextId").html() != "Edit the text" ) return 0; + var selection = getSelected(); + range = getSelected().getRangeAt(0); + + container = document.createElement("div"); + container.appendChild(selection.getRangeAt(0).cloneContents()); + + if(selection && (selection = new String(selection).replace(/^\s+|\s+$/g,''))) { + + var newdiv = document.createElement("div"); + newdiv.id = "tagItemDivId"; + newdiv.setAttribute("class", "tagItemDivClass"); + newdiv.style.cssText = 'top:'+e.pageY+'; left:'+e.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px'; + + //console.log(selection.getRangeAt(0).cloneContents()); + if ( container.innerHTML.indexOf( "br" ) != -1 ) { + var newselect = document.createElement("select"); + newselect.id = "TitletagType"; + <?php + foreach ( $taglistArray as $taglistValue ) { + echo "newselect.innerHTML += \"<option value='".$taglistValue[2]."'>".$taglistValue[1]."</option>\";\n"; + } + ?> + newdiv.appendChild(newselect); + + //matchValue = .match(); + myRegexp = new RegExp("〈(.*?)〉", "g") + matchValue = myRegexp.exec(String(selection)); + + if ( matchValue != null ) { + newdiv.innerHTML += "<input id=\"TitletagName\" value=\""+ matchValue[1] +"\"></br>"; + } else { + newdiv.innerHTML += "<input id=\"TitletagName\" value=\"\"></br>"; + } + newdiv.innerHTML += "<button onclick=\"addTagTitle( range, container )\">Add Title Tag To Each Line</button></br>"; + + newdiv.innerHTML += "<button onclick=\"exportTable( range, container )\">Export As A Table</button></br></br>"; + + var newselect = document.createElement("select"); + newselect.id = "RemoveTitletagType"; + <?php + foreach ( $taglistArray as $taglistValue ) { + echo "newselect.innerHTML += \"<option value='".$taglistValue[2]."'>".$taglistValue[1]."</option>\";\n"; + } + ?> + newdiv.appendChild(newselect); + + newdiv.innerHTML += "<input id=\"RemoveTitletagName\" value=\"\"></br>"; + newdiv.innerHTML += "<button onclick=\"removeTagTitle( range, container )\">Remove</button></br>"; + } else { + newdiv.innerHTML = "Tag: "+String(selection)+"<br>"; + + newdiv.innerHTML += "<button accesskey=\"2\" onclick=\"tagwithtitle( range, '"+String(selection)+"' )\">Tag As Title</button></br>"; + + <?php + foreach ( $taglistArray as $taglistValue ) { + if ( $taglistValue[2] == "person") { + echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(No BR)</button>\";\n"; + echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."2' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; + echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; + } else if ($taglistValue[2] == "post_time") { + echo "newdiv.innerHTML += \"<button accesskey=\\\"3\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; + echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; + } else if ($taglistValue[2] == "office") { + echo "newdiv.innerHTML += \"<button accesskey=\\\"4\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; + echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; + } else { + echo "newdiv.innerHTML += \"<button onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; + echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; + } + } + ?> + } + $('body').append(newdiv); + + $('#TitletagType').val(lastAddTag); + } + //e.stopPropagation(); +}); + +function removeTagTitle( range, container ) { + saveUndoText(); + range.deleteContents(); + + lastAddTag = $('#RemoveTitletagType').val(); + + var stringtemp = container.innerHTML; + + if ( $('#RemoveTitletagName').val() == "" ) { + var regexText="<"+lastAddTag+">〈(.*?)〉</"+lastAddTag+">"; + var replaceText=""; + stringtemp = stringtemp.replace(new RegExp(regexText, "g"), replaceText); + + var regexText="<"+lastAddTag+">(.*?)</"+lastAddTag+">"; + var replaceText="$1"; + stringtemp = stringtemp.replace(new RegExp(regexText, "g"), replaceText); + } else { + var regexText="<"+lastAddTag+">〈"+$('#RemoveTitletagName').val()+"〉</"+lastAddTag+">"; + var replaceText=""; + stringtemp = stringtemp.replace(new RegExp(regexText, "g"), replaceText); + + var regexText="<"+lastAddTag+">("+$('#RemoveTitletagName').val()+")</"+lastAddTag+">"; + var replaceText="$1"; + stringtemp = stringtemp.replace(new RegExp(regexText, "g"), replaceText); + } + + var newdiv = document.createElement("aaaa"); + newdiv.innerHTML = stringtemp; + range.insertNode(newdiv); + + var el = document.getElementById("editable-area"); + + var regexText=/<aaaa>/gi; + var replaceText=''; + el.innerHTML = el.innerHTML.replace(regexText, replaceText); + + var regexText=/<\/aaaa>/gi; + var replaceText=''; + el.innerHTML = el.innerHTML.replace(regexText, replaceText); + + $('.tagItemDivClass').remove(); +} + +function addTagTitle( range, container ) { + saveUndoText(); + lastAddTag = $('#TitletagType').val(); + tag = "<"+$('#TitletagType').val()+">〈"+$('#TitletagName').val()+"〉</"+$('#TitletagType').val()+">"; + range.deleteContents(); + var stringtemp = container.innerHTML; + var regexText=/<br>/g; + var replaceText="<br>"+tag; + stringtemp = stringtemp.replace(regexText, replaceText); + + var newdiv = document.createElement("aaaa"); + newdiv.innerHTML = tag+stringtemp; + range.insertNode(newdiv); + + var el = document.getElementById("editable-area"); + + var regexText=/<aaaa>/gi; + var replaceText=''; + el.innerHTML = el.innerHTML.replace(regexText, replaceText); + + var regexText=/<\/aaaa>/gi; + var replaceText=''; + el.innerHTML = el.innerHTML.replace(regexText, replaceText); + + $('.tagItemDivClass').remove(); +} + +function exportTable( range, container ) { + //MsgBox("enter function"); + var form = document.createElement("form"); + form.setAttribute("method", "post"); + form.setAttribute("action", "exportTable.php"); + form.setAttribute("target", "_blank"); + + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "content"); + hiddenField.setAttribute("value", container.innerHTML); + form.appendChild(hiddenField); + + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "sectionid"); + hiddenField.setAttribute("value", "<?php echo $section_id; ?>"); + form.appendChild(hiddenField); + + if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { + document.body.appendChild(form); + form.submit(); + } else { + form.submit(); // works under IE and Chrome, but not FF + } +} + +function exportPage() { + var startPage = $('#exportPageStart').val(); + var endPage = $('#exportPageEnd').val(); + + var el = document.getElementById("editable-area"); + var str="" + el.innerHTML; + + var regexText="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】"; + + var form = document.createElement("form"); + form.setAttribute("method", "post"); + form.setAttribute("action", "exportTable.php"); + form.setAttribute("target", "_blank"); + + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "content"); + hiddenField.setAttribute("value", str.match(new RegExp(regexText, "g"))); + form.appendChild(hiddenField); + + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "sectionid"); + hiddenField.setAttribute("value", "<?php echo $section_id; ?>"); + form.appendChild(hiddenField); + + if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { + document.body.appendChild(form); + form.submit(); + } else { + form.submit(); // works under IE and Chrome, but not FF + } +} + +function exportAll() { + var el = document.getElementById("editable-area"); + var str="" + el.innerHTML; + + var form = document.createElement("form"); + form.setAttribute("method", "post"); + form.setAttribute("action", "exportTable.php"); + form.setAttribute("target", "_blank"); + + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "content"); + hiddenField.setAttribute("value", str); + form.appendChild(hiddenField); + + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "sectionid"); + hiddenField.setAttribute("value", "<?php echo $section_id; ?>"); + form.appendChild(hiddenField); + + if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { + document.body.appendChild(form); + form.submit(); + } else { + form.submit(); // works under IE and Chrome, but not FF + } +} + +function cleanUpTextArea() { + var el = document.getElementById("editable-area"); + + var regexText=/<div>/gi; + var replaceText='<br>'; + el.innerHTML = el.innerHTML.replace(regexText, replaceText); + + var regexText=/<\/div>/gi; + var replaceText=''; + el.innerHTML = el.innerHTML.replace(regexText, replaceText); + + + var regexText=/<span style="(.*?)">/gi; + var replaceText=''; + el.innerHTML = el.innerHTML.replace(regexText, replaceText); + + var regexText=/<\/span>/gi; + var replaceText=''; + el.innerHTML = el.innerHTML.replace(regexText, replaceText); +} + +function Undo() { + if ( stringBeforeChangeStack.length > 0 ) { + var el = document.getElementById("editable-area"); + el.innerHTML = stringBeforeChangeStack.pop(); + } else { + var el = document.getElementById("buttonUndo"); + el.disabled = true; + } +} + +function saveUndoText() { + var el = document.getElementById("editable-area"); + //stringBeforeChange = el.innerHTML; + stringBeforeChangeStack.push(el.innerHTML); + var el = document.getElementById("buttonUndo"); + el.disabled = false; +} + +function editText() { + var el = document.getElementById("editable-area"); + if ( $("#editTextId").html() == "Edit the text" ) { + saveUndoText(); + el.contentEditable = true; + $("button").attr("disabled", true); + $("#editTextId").attr("disabled", false); + $("#editTextId").html("Edit completed!"); + } else { + el.contentEditable = false; + cleanUpTextArea(); + $("button").attr("disabled", false); + $("#editTextId").html("Edit the text"); + } +} + +function saveText() { + var el = document.getElementById("editable-area"); + + $.ajax({ + url : 'save_full_text.php', + async : false, + type : 'POST', + data : 'text='+encodeURIComponent(el.innerHTML)+'&filename=<?php echo $section_id; ?>' + }).done(function(result) { + alert("Saved!"); + }); + +} + +function preg_quote (str, delimiter) { + // http://kevin.vanzonneveld.net + // + original by: booeyOH + // + improved by: Ates Goral (http://magnetiq.com) + // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) + // + bugfixed by: Onno Marsman + // + improved by: Brett Zamir (http://brett-zamir.me) + // * example 1: preg_quote("$40"); + // * returns 1: '\$40' + // * example 2: preg_quote("*RRRING* Hello?"); + // * returns 2: '\*RRRING\* Hello\?' + // * example 3: preg_quote("\\.+*?[^]$(){}=!<>|:"); + // * returns 3: '\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:' + return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&'); +} + +function replaceRegex() { + saveUndoText(); + + var startPage = $('#regexPageStart2').val(); + var endPage = $('#regexPageEnd2').val(); + var el = document.getElementById("editable-area"); + var str="" + el.innerHTML; + + var regexText=document.getElementById("regexText").value; + var replaceText=document.getElementById("replaceText").value; + var str="" + el.innerHTML; + + if ( startPage == "" ) { + alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" ); + el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText); + } else { + var regexText2="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】"; + var partString = ""+str.match(new RegExp(regexText2, "g")); + alert(partString); + + alert( "Tagged "+partString.match(new RegExp(regexText, "g")).length+" entities!" ); + var resultString = partString.replace(new RegExp(regexText, "g"), replaceText); + + str="" + el.innerHTML; + el.innerHTML = str.replace(new RegExp(regexText, "g"), resultString); + } + + //document.styleSheets[0].addRule("tag001", "color:green;") +} + +function replaceSmartRegex() { + saveUndoText(); + var startPage = $('#regexPageStart2').val(); + var endPage = $('#regexPageEnd2').val(); + + var el = document.getElementById("editable-area"); + var regexText=document.getElementById("regexText").value; + + <?php + foreach ( $wordlistArray as $wordlistValue ) { + echo "\tvar regexText1=\"List ".$wordlistValue[1]."\";\n"; + echo "\tregexText1 = preg_quote(regexText1);\n"; + echo "\tvar replaceText1=\"".$wordlistValue[2]."\";\n"; + echo "\tregexText = regexText.replace(new RegExp(regexText1, \"g\"), replaceText1);\n\n"; + } + ?> + + var replaceText=document.getElementById("replaceText").value; + var str="" + el.innerHTML; + + if ( startPage == "" ) { + alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" ); + el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText); + } else { + var regexText2="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】"; + var partString = ""+str.match(new RegExp(regexText2, "g")); + alert(partString); + + alert( "Tagged "+partString.match(new RegExp(regexText, "g")).length+" entities!" ); + var resultString = partString.replace(new RegExp(regexText, "g"), replaceText); + + str="" + el.innerHTML; + el.innerHTML = str.replace(new RegExp(regexText2, "g"), resultString); + } + //document.styleSheets[0].addRule("tag001", "color:green;") +} + +//Tagging Items +function getSelected() { + if(window.getSelection) { + return window.getSelection(); + } else if (document.getSelection) { + return document.getSelection(); + } else { + var selection = document.selection && document.selection.createRange(); + if(selection.text) { + return selection.text; + } + return false; + } + return false; +} + +function tagStringWithTag( stringValue, tag ) { + saveUndoText(); + var el = document.getElementById("editable-area"); + var regexText="("+String(stringValue)+")"; + if ( tag=="person") { + var replaceText="<br><"+tag+">$1</"+tag+">"; + } else { + var replaceText="<"+tag+">$1</"+tag+">"; + } + var str="" + el.innerHTML; + + $('.tagItemDivClass').remove(); + alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" ); + el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText); +} + + +function tagwithtitle( range, stringSelection ) { + saveUndoText(); + range.deleteContents(); + //var newdiv = document.createElement("br"); + //range.insertNode(newdiv); + range.insertNode(document.createTextNode("〈"+stringSelection+"〉")); + var newdiv = document.createElement("br"); + range.insertNode(newdiv); + + $('.tagItemDivClass').remove(); +} + +function tagwithOnlytag( range, stringSelection, tag ) { + saveUndoText(); + + range.deleteContents(); + if ( tag=="person2") { + var newdiv = document.createElement("person"); + newdiv.innerHTML = stringSelection; + range.insertNode(newdiv); + var newdiv = document.createElement("br"); + range.insertNode(newdiv); + } else { + var newdiv = document.createElement(tag); + newdiv.innerHTML = stringSelection; + range.insertNode(newdiv); + } + $('.tagItemDivClass').remove(); +} + +function tagNameWithLastName() { + saveUndoText(); + var el = document.getElementById("editable-area"); + var regexText=/(○|】|^)(王|李|張|趙|劉|陳|楊|吳|黃|黄|朱|孫|郭|胡|呂|高|宋|徐|程|林|鄭|范|何|韓|曹|馬|許|田|馮|杜|周|曾|汪|蘇|董|方|蔡|梁|石|謝|賈|薛|彭|崔|唐|潘|鄧|史|錢|侯|魏|羅|葉|沈|孟|姚|傅|丁|章|蕭|蔣|盧|陸|袁|晁|譚|邵|歐陽|孔|詹|俞|尹|廖|閻|洪|夏|雷|葛|文|柳|陶|毛|丘|龔|蒲|邢|郝|龐|安|裴|折|施|游|金|鄒|湯|虞|嚴|鍾)([^○(舉人|縣人|歲貢|間任)]{1,3}|○[^○])(?=(○|$))/g; + var replaceText="$1<br><person>$2$3</person>$4"; + var str="" + el.innerHTML; + + alert( "Tagged "+str.match(regexText).length+" entities!" ); + el.innerHTML = str.replace(regexText, replaceText); +} + +function tagNameWithLastName2() { + saveUndoText(); + var el = document.getElementById("editable-area"); + var regexText="(○|】|^)("+$('#surname').val()+")([^○(舉人|縣人|歲貢|間任)]{1,3}|○[^○])(?=(○|$))"; + var replaceText="$1<br><person>$2$3</person>$4"; + var str="" + el.innerHTML; + + alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" ); + el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText); +} + +function tagTime() { + saveUndoText(); + var el = document.getElementById("editable-area"); + var str="" + el.innerHTML; + + var regexText=/(<?php echo $wordlistArray[0][2]; ?>)(○?)(一|二|三|四|五|六|七|八|九)?(○?)(十)?(○?)(一|二|三|四|五|六|七|八|九|元|十)(○?)(年)/g; + var replaceText="<time>$1$2$3$4$5$6$7$8$9</time>"; + var matchedCount = str.match(regexText).length; + str = str.replace(regexText, replaceText); + + var regexText=/(?!(>))(<?php echo $wordlistArray[0][2]; ?>)/g; + var replaceText="<time>$1$2</time>"; + matchedCount += str.match(regexText).length; + el.innerHTML = str.replace(regexText, replaceText); + + var regexText=/(一|二|三|四|五|六|七|八|九)?(○?)(十)?(○?)(一|二|三|四|五|六|七|八|九|元|十)(○?)(年)(?!(<))/g; + var replaceText="<time>$1$2$3$4$5$6$7</time>"; + matchedCount += str.match(regexText).length; + el.innerHTML = str.replace(regexText, replaceText); + + alert( "Tagged "+matchedCount+" entities!" ); +} + +function tagBiogAddr() { + saveUndoText(); + var el = document.getElementById("editable-area"); + var str="" + el.innerHTML; + + var regexText=/(○)([^○]{1,6})(○?)(人)/g; + var replaceText="$1<biog_addr>$2</biog_addr>$3$4"; + el.innerHTML = str.replace(regexText, replaceText); + + alert( "Tagged "+str.match(regexText).length+" entities!" ); +} + +function smartRegexNew() { + $('#smartRegexPopUpDiv').css("display", "block"); + $('#smartRegexPopUpDiv').css("background-color", "White"); + $('#smartRegexPopUpDiv').css("width", "400px"); + $('#smartRegexPopUpDiv').css("height", "300px"); + $('#smartRegexPopUpDiv').css("top", "100px"); + $('#smartRegexPopUpDiv').css("left", "-200px"); + $('#smartRegexPopUpDiv').css("border", "1px solid black"); + $('#smartRegexPopUpDiv').css("padding", "5px"); + + $('#smartRegexPopUpAdd').attr("disabled", false); + $('#smartRegexPopUpEdit').attr("disabled", "disabled"); + $('#smartRegexPopUpDel').attr("disabled", "disabled"); + $('#smartRegexPopUpBack').attr("disabled", "disabled"); + $('#smartRegexPopUpFor').attr("disabled", "disabled"); +} + +function replaceSmartClose() { + $('#smartRegexPopUpDiv').css("display", "none"); + $("#smartRegexPopUpSelectWord").val("NULL"); + $("#smartRegexPopUpText").val(""); + $("#smartRegexPopUpName").val(""); +} + +function replaceSmartEdit(){ + thisObject = $('#smartRegexPopUpDiv').attr("editID"); + + $('#smartRegexShowDiv > #'+thisObject).attr("class", "span_"+$("#smartRegexPopUpSelectTag").val()); + $('#smartRegexShowDiv > #'+thisObject).attr("regexText", $("#smartRegexPopUpText").val()); + $('#smartRegexShowDiv > #'+thisObject).attr("regexReplace", $("#smartRegexPopUpSelectTag").val()); +} + +function replaceSmartDel() { + thisObject = $('#smartRegexPopUpDiv').attr("editID"); + $('#smartRegexShowDiv > #'+thisObject).remove(); +} + +function replaceSmartFor() { + thisObject = $('#smartRegexPopUpDiv').attr("editID"); + //var wahaha = $('#'+thisObject).clone(); + //var hahawa = $('#'+thisObject).next(); + //$('#'+thisObject).remove(); + //wahaha.insertAfter(hahawa); + $('#smartRegexShowDiv > #'+thisObject).insertAfter( $('#'+thisObject).next() ); +} + +function replaceSmartBack() { + thisObject = $('#smartRegexPopUpDiv').attr("editID"); + //var wahaha = $('#'+thisObject).clone(); + //var hahawa = $('#'+thisObject).prev(); + //$('#'+thisObject).remove(); + //wahaha.insertBefore(hahawa); + $('#smartRegexShowDiv > #'+thisObject).insertBefore( $('#'+thisObject).prev() ); +} + +function replaceSmartAdd() { + var newdiv = document.createElement("span"); + newdiv.innerHTML = " "+$("#smartRegexPopUpName").val()+" "; + $(newdiv).css("border", "1px solid black"); + $(newdiv).css("width", "100px"); + + $(newdiv).attr("class", "span_"+$("#smartRegexPopUpSelectTag").val()); + $(newdiv).attr("id", "span_"+$("#smartRegexPopUpName").val()); + $(newdiv).attr("regexText", $("#smartRegexPopUpText").val()); + $(newdiv).attr("regexReplace", $("#smartRegexPopUpSelectTag").val()); + + $('#smartRegexShowDiv').append(newdiv); + + replaceSmartClose(); +} + +$(document).on("click", '#smartRegexShowDiv > span', function (e) { + $('#smartRegexPopUpDiv').css("display", "block"); + $('#smartRegexPopUpDiv').css("background-color", "White"); + $('#smartRegexPopUpDiv').css("width", "400px"); + $('#smartRegexPopUpDiv').css("height", "300px"); + $('#smartRegexPopUpDiv').css("top", "100px"); + $('#smartRegexPopUpDiv').css("left", "-200px"); + $('#smartRegexPopUpDiv').css("border", "1px solid black"); + $('#smartRegexPopUpDiv').css("padding", "5px"); + + $('#smartRegexPopUpDiv').attr("editID", $(this).attr("id")); + + $('#smartRegexPopUpName').val($(this).html()); + $('#smartRegexPopUpText').val($(this).attr("regexText")); + $('#smartRegexPopUpSelectTag').val($(this).attr("regexReplace")); + + $('#smartRegexPopUpAdd').attr("disabled", "disabled"); + $('#smartRegexPopUpEdit').attr("disabled", false); + $('#smartRegexPopUpDel').attr("disabled", false); + $('#smartRegexPopUpBack').attr("disabled", false); + $('#smartRegexPopUpFor').attr("disabled", false); +}); + +function smartRegexEmpty() { + $('#smartRegexShowDiv').html(""); +} + +function replaceSmartRun() { + + var replaceSmartRegexString = ""; + var replaceSmartReplaceString = ""; + var count=1; + + saveUndoText(); + + $('#smartRegexShowDiv').children('span').each(function () { + replaceSmartRegexString += "(" + $(this).attr("regexText") + ")"; + if ( $(this).attr("regexReplace") == "notag" ) { + replaceSmartReplaceString += "$" + count; + } else if ( $(this).attr("regexReplace") == "title" ) { + replaceSmartReplaceString += "<br>〈" + "$" + count + "〉<br>"; + } else { + replaceSmartReplaceString += "<" + $(this).attr("regexReplace") + ">" + "$" + count + "</"+ $(this).attr("regexReplace") +">"; + } + count++; + }); + + + var startPage = $('#regexPageStart').val(); + var endPage = $('#regexPageEnd').val(); + var el = document.getElementById("editable-area"); + var str="" + el.innerHTML; + + if ( startPage == "" ) { + alert( "Tagged "+str.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" ); + el.innerHTML = str.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString); + } else { + var regexText="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】"; + var partString = ""+str.match(new RegExp(regexText, "g")); + alert(partString); + + alert( "Tagged "+partString.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" ); + var resultString = partString.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString); + + str="" + el.innerHTML; + el.innerHTML = str.replace(new RegExp(regexText, "g"), resultString); + } +} + +function replaceSmartRunSpace() { + + var replaceSmartRegexString = ""; + var replaceSmartReplaceString = ""; + var count=1; + saveUndoText(); + + $('#smartRegexShowDiv').children('span').each(function () { + //alert($(this).attr("regexText")); + replaceSmartRegexString += "(" + $(this).attr("regexText") + ")(○*)"; + if ( $(this).attr("regexReplace") == "notag" ) { + replaceSmartReplaceString += "$" + count; + } else if ( $(this).attr("regexReplace") == "title" ) { + replaceSmartReplaceString += "<br>〈" + "$" + count + "〉<br>"; + } else { + replaceSmartReplaceString += "<" + $(this).attr("regexReplace") + ">" + "$" + count + "</"+ $(this).attr("regexReplace") +">"; + } + count++; + replaceSmartReplaceString += "$" + count; + count++; + }); + + var startPage = $('#regexPageStart').val(); + var endPage = $('#regexPageEnd').val(); + var el = document.getElementById("editable-area"); + var str="" + el.innerHTML; + + if ( startPage == "" ) { + alert( "Tagged "+str.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" ); + el.innerHTML = str.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString); + } else { + var regexText="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】"; + var partString = ""+str.match(new RegExp(regexText, "g")); + alert(partString); + + alert( "Tagged "+partString.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" ); + var resultString = partString.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString); + + str="" + el.innerHTML; + el.innerHTML = str.replace(new RegExp(regexText, "g"), resultString); + } + + //alert( "Tagged "+str.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" ); + //el.innerHTML = str.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString); +} + +function smartRegexSave() { + var x; + var name=prompt("Please enter this Regex name",RegexLoadedName); + if (name!=null){ + $.ajax({ + url : 'save_regex.php', + async : false, + type : 'POST', + data : 'text='+encodeURIComponent($('#smartRegexShowDiv').html())+'&filename='+name + }).done(function(result) { + alert("Saved!"); + }); + } +} + +function smartRegexLoad() { + + + $('#load_regex_div').html(""); + $('#load_regex_div').css("display", "block"); + $('#load_regex_div').css("border", "1px solid black"); + $('#load_regex_div').css("background-color", "White"); + $('#load_regex_div').css("width", "200px"); + $('#load_regex_div').css("height", "150px"); + $('#load_regex_div').css("top", "100px"); + $('#load_regex_div').css("left", "-200px"); + + var newselect = document.createElement("select"); + newselect.id = "loadRegexSelect"; + + $.ajax({ + type: 'GET', + url: 'load_regex.php', + dataType: 'json', + cache: false, + success: function (data) { + $.each(data, function(index, element) { + newselect.innerHTML += "<option value=\""+index+"\">"+index+"</option>\n"; + //alert(index); + //alert(element); + var newdiv = document.createElement("div"); + $(newdiv).css("display", "none"); + $(newdiv).html(element); + $(newdiv).attr("id", "div_"+index); + $('#load_regex_div').append(newdiv); + }); + } + }); + + $('#load_regex_div').append(newselect); + var newbutton = document.createElement("button"); + $(newbutton).html("Load"); + $(newbutton).attr("onclick", "loadRegexAdd()"); + $('#load_regex_div').append(newbutton); + var newbutton = document.createElement("button"); + $(newbutton).html("Close"); + $(newbutton).attr("onclick", "$('#load_regex_div').css(\"display\", \"none\");"); + $('#load_regex_div').append(newbutton); +} + +var RegexLoadedName = ""; +function loadRegexAdd() { + RegexLoadedName = $('#loadRegexSelect').val(); + var divName = "div_"+$('#loadRegexSelect').val(); + $('#smartRegexShowDiv').html( $('#'+divName).html() ); + $('#load_regex_div').css("display", "none"); +} + +$(document).on("change", '#smartRegexPopUpSelectWord', function (e) { +<?php + foreach ( $wordlistArray as $wordlistValue ) { + echo "if ( $('#smartRegexPopUpSelectWord').val() == \"".$wordlistValue[0]."\") {"; + echo "$('#smartRegexPopUpText').val(\"".$wordlistValue[2]."\");"; + echo "}"; + } +?> +}); + +</script> +</head> +<body> +<table width="1250" border="1"> + <tr> + <td width="980"> + <div id="editable-area" class="area" style="max-width: 980"><?php echo $stringInput; ?></div> + </td> + <td width="270" valign="top"> + <div id="follow-scroll" style="position:absolute; width: 220" width="220"> + <div id="load_regex_div" style="position: absolute; display: none"></div> + <div id="smartRegexPopUpDiv" style="position: absolute; display: none"> + Name: <input id="smartRegexPopUpName"></input><br><br> + Word List: + <select id="smartRegexPopUpSelectWord"> + <option value="NULL" selected>無</option> + <?php + foreach ( $wordlistArray as $wordlistValue ) { + echo "<option value=\"".$wordlistValue[0]."\">".$wordlistValue[1]."</option>\n"; + } + ?> + </select> + <br> + OR (USE "|" TO SEPARATE WORDS):<br> + <TEXTAREA id="smartRegexPopUpText" COLS=30 ROWS=4></TEXTAREA><br><br> + Tag: + <select id="smartRegexPopUpSelectTag"> + <?php + foreach ( $taglistArray as $taglistValue ) { + echo "<option value=\"".$taglistValue[2]."\">".$taglistValue[1]."</option>\n"; + } + echo "<option value=\"title\">Title</option>\n"; + ?> + <option value="NOTAG">不標記</option> + </select><br> + <button id="smartRegexPopUpAdd" onclick="replaceSmartAdd()" style="height: 30px; width: 50px">Add</button> + <button id="smartRegexPopUpEdit" onclick="replaceSmartEdit()" style="height: 30px; width: 50px">Edit</button> + <button id="smartRegexPopUpDel" onclick="replaceSmartDel()" style="height: 30px; width: 50px">Delete</button> + <button id="smartRegexPopUpBack" onclick="replaceSmartBack()" style="height: 30px; width: 50px"><<</button> + <button id="smartRegexPopUpFor" onclick="replaceSmartFor()" style="height: 30px; width: 50px">>></button> + <button onclick="replaceSmartClose()" style="height: 30px; width: 50px">Close</button> + </div> + <form action="javascript:void(0);"> + <fieldset> + <legend>Replace By <i><b>Smart Regex</b></i>©:</legend> + <div id="smartRegexShowDiv"></div><br> + <button onclick="smartRegexNew()" style="height: 30px; width: 220px">Add Regex Group</button></br> + Range: <input type="text" size="5" id="regexPageStart">to<input type="text" size="5" id="regexPageEnd"><br> + <button onclick="replaceSmartRun()" style="height: 30px; width: 220px">Run</button></br> + <button onclick="replaceSmartRunSpace()" style="height: 30px; width: 220px">Run(Allow space between Group)</button></br> + <button onclick="smartRegexSave()" style="height: 30px; width: 70px">Save</button> + <button onclick="smartRegexLoad()" style="height: 30px; width: 70px">Load</button> + <button onclick="smartRegexEmpty()" style="height: 30px; width: 70px">Clear</button></br> + </fieldset> + + <fieldset> + <legend>Tag by rule:</legend> + <button onclick="tagNameWithLastName()" style="height: 30px; width: 220px">Tag Word Begin With Surname</button></br> + <button onclick="tagNameWithLastName2()" style="height: 30px; width: 170px">Tag Word Begin With</button><input type="text" size="2" id="surname"></br> + <!--<button onclick="tagTime()" style="height: 30px; width: 220px">Tag Time</button></br>--> + <!--<button onclick="tagBiogAddr()" style="height: 30px; width: 220px">Tag BiogAddr</button></br>--> + <button onclick="Undo()" style="height: 30px; width: 220px" id="buttonUndo" disabled="true">Undo</button> + </fieldset> + + <fieldset> + <legend>Edit:</legend> + <!--<button onclick="cleanUpTextArea()" style="height: 30px; width: 220px">Reform the text</button></br>--> + <button onclick="saveText()" style="height: 30px; width: 220px">Save the text</button></br> + <button onclick="editText()" id="editTextId" style="height: 30px; width: 220px">Edit the text</button></br> + </br> + <button onclick="window.open('edit_wordlist.php')" style="height: 30px; width: 220px">Manage Word List</button></br> + <button onclick="window.open('edit_taglist.php')" style="height: 30px; width: 220px">Manage Tag List</button></br> + </fieldset> + + <fieldset> + <legend>Export:</legend> + Page: <input type="text" size="5" id="exportPageStart">to<input type="text" size="5" id="exportPageEnd"><br> + <button onclick="exportPage()" style="height: 30px; width: 220px">Export</button></br> + <button onclick="exportAll()" style="height: 30px; width: 220px">Export All</button></br> + </fieldset> + + <fieldset> + <legend>Replace By <i><b>Regex</b></i>:</legend> + Range: <input type="text" size="5" id="regexPageStart2">to<input type="text" size="5" id="regexPageEnd2"><br> + Regex: <input type="text" size="30" id="regexText"></br> + Replace: <input type="text" size="30" id="replaceText"><br> + <button onclick="replaceSmartRegex()">Replace!</button> + </fieldset> + </form> + </div> + </td> + </tr> +</table> +</body> +</html>