comparison interface/tagging_text_20130814150100.php_old @ 0:b12c99b7c3f0

commit for previous development
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 19 Jan 2015 17:13:49 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b12c99b7c3f0
1 <?php
2 header("Content-Type: text/html;charset=utf-8");
3
4 if (isset($_GET['id'])) {
5 $section_id = $_GET['id'];
6 } else {
7 $get_book_id = $_GET['book'];
8 $get_start = $_GET['start'];
9 $get_end = $_GET['end'];
10 }
11
12 include_once('../Lib_mb_utf8.php');
13
14 set_time_limit(0);
15 ini_set('memory_limit', '-1');
16
17 $link_mysql = mysql_connect('localhost', 'root', 'ilove!@34');
18 mysql_query("SET NAMES utf8");
19
20 if (!$link_mysql) {
21 die('Could not connect: ' . mysql_error());
22 }
23
24 $db_selected = mysql_select_db('Gazetteer', $link_mysql);
25 if (!$db_selected) {
26 die ('Can\'t use foo : ' . mysql_error());
27 }
28
29 if (!function_exists("GetSQLValueString")) {
30 function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
31 {
32 $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
33
34 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
35
36 switch ($theType) {
37 case "text":
38 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
39 break;
40 case "long":
41 case "int":
42 $theValue = ($theValue != "") ? intval($theValue) : "NULL";
43 break;
44 case "double":
45 $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
46 break;
47 case "date":
48 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
49 break;
50 case "defined":
51 $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
52 break;
53 }
54 return $theValue;
55 }
56 }
57
58 $query = sprintf("SELECT * FROM `sections` WHERE `id`=\"%s\"", $section_id);
59 $result = mysql_query($query);
60 while ($row = mysql_fetch_assoc($result)) {
61 $bookId=$row['books_id'];
62 $startPage=$row['start_page'];
63 $endPage=$row['end_page'];
64 }
65
66 $contentString="";
67 if ( file_exists("parsing_files/".$section_id.".txt") ) {
68 $contentString=file_get_contents("parsing_files/".$section_id.".txt");
69 $stringInput = $contentString;
70 $stringInput = preg_replace("/ /u", "○", $stringInput);
71 $stringInput = preg_replace("/\n/u", "<br>", $stringInput);
72 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_blank\">\\1</a>】", $stringInput);
73 } else {
74 $query = sprintf("SELECT `content`, `line`, `books_id` FROM `contents` WHERE `books_id`=\"%s\" AND `line`>=%d AND `line`<=%d", $bookId, $startPage, $endPage);
75 $result = mysql_query($query);
76 while ($row = mysql_fetch_assoc($result)) {
77 $contentString.="【".$row['line']."】".$row['content']."\n";
78 }
79 $stringInput = $contentString;
80 $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput);
81 $stringInput = preg_replace("/ /u", "○", $stringInput);
82 $stringInput = preg_replace("/\n/u", "<br>", $stringInput);
83 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_blank\">\\1</a>】", $stringInput);
84 }
85
86
87 $taglistArray="";
88 $query = sprintf("SELECT * FROM `taglist` ORDER BY `tag` ASC");
89 $result = mysql_query($query);
90 while ($row = mysql_fetch_assoc($result)) {
91 $taglistArray[] = array( $row['id'], $row['name'], $row['tag'], $row['color'] );
92 }
93
94 function sortFunction($a,$b) {
95 return strlen($b)-strlen($a);
96 }
97
98 $wordlistArray="";
99 $query = sprintf("SELECT * FROM `wordlist` ORDER BY `name` ASC");
100 $result = mysql_query($query);
101 while ($row = mysql_fetch_assoc($result)) {
102 $listString = file_get_contents("wordlist/".$row['id'].".txt");
103 $listString = preg_replace("/<div>/u", "\n", $listString);
104 $listString = preg_replace("/<\/div>/u", "", $listString);
105 $listString = preg_replace("/<span(.*?)>/u", "", $listString);
106 $listString = preg_replace("/<\/span>/u", "", $listString);
107 //$listString = preg_replace("/\n/u", "|", $listString);
108
109 $wordlistArray2 = explode( "\n", $listString );
110 usort($wordlistArray2,'sortFunction');
111 foreach ( $wordlistArray2 as $index=>$value ) {
112 $wordlistArray2[$index] = implode("○?", preg_split("/(?<!^)(?!$)/u", $value));
113 }
114 foreach ( $wordlistArray2 as $index=>$value ) {
115 if ($value=="") unset($wordlistArray2[$index]);
116
117 }
118 $listString = implode("|", $wordlistArray2);
119
120 if ( $listString[0]=="|" ) $listString = substr($listString, 1);
121 $wordlistArray[] = array( $row['id'], $row['name'], $listString );
122 }
123
124 ?>
125
126 <html>
127 <head>
128 <title></title>
129 <script src="../jquery-1.10.2.min.js"></script>
130 <style>
131 dynasty
132 {
133 color:red;
134 }
135 nianhao
136 {
137 color:blue;
138 }
139 name
140 {
141 color:orange;
142 }
143 #editable-area {
144 line-height:160%;
145 letter-spacing:1.5px;
146 font-size:21px;
147 }
148 <?php
149 foreach ( $taglistArray as $taglistValue ) {
150 echo $taglistValue[2]."\n{\ncolor:".$taglistValue[3]."\n}\n";
151
152 echo ".span_".$taglistValue[2]."\n{\nbackground-color:".$taglistValue[3]."\n}\n";
153 }
154 ?>
155 </style>
156 <script type="text/javascript">
157 var stringBeforeChange="";
158
159 window.onbeforeunload = function() {
160 return "Are you sure?";
161 };
162
163 $(document).ready(function(){
164 //run once
165 var el=$('#follow-scroll');
166 var originalelpos=el.offset().top; // take it where it originally is on the page
167
168 //run on scroll
169 $(window).scroll(function(){
170 var el = $('#follow-scroll'); // important! (local)
171 var elpos = el.offset().top; // take current situation
172 var windowpos = $(window).scrollTop();
173 var finaldestination = windowpos+originalelpos;
174 el.stop().animate({'top':finaldestination},500);
175 });
176 });
177
178 /*
179 $(document).on("mouseup", function (e) {
180 e.stopPropagation();
181 $('.questionMarkClass').remove();
182 $('.tagItemDivClass').remove();
183 alert("Remove");
184 });
185
186
187 $(document).on("click", '.questionMarkClass', function (e) {
188 e.stopPropagation();
189 });
190 */
191
192 function removeTagNewDiv( eventObject, tagName, tagObject ) {
193 saveUndoText();
194 var newdiv = document.createElement("div");
195 newdiv.id = "questionMarkId";
196 newdiv.setAttribute("class", "questionMarkClass");
197 newdiv.style.cssText = 'top:'+eventObject.pageY+'; left:'+eventObject.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px';
198 newdiv.innerHTML = "Tag: "+tagName+"<br>Value: "+tagObject.text()+"<br>";
199
200
201 var newbutton = $('<button>Remove this</button>').mouseup(function (e2) {
202 var textKeep = $(this).parent().parent().html();
203 var regexText=/<div(.*?)<\/div>/g;
204 var replaceText="";
205 textKeep = textKeep.replace(regexText, replaceText);
206
207 $(this).parent().parent().replaceWith( textKeep );
208 });
209 newbutton.appendTo(newdiv);
210
211 var newbutton = $('<button>Remove all</button>').mouseup(function (e2) {
212 var textKeep = $(this).parent().parent().html();
213 var regexText=/<div(.*?)<\/div>/g;
214 var replaceText="";
215 textKeep = textKeep.replace(regexText, replaceText);
216
217 $(this).parent().parent().replaceWith( textKeep );
218
219 var el = document.getElementById("editable-area");
220 var regexText=new RegExp("<"+tagName+">("+textKeep+")</"+tagName+">", "g");
221 var replaceText="$1";
222 var str="" + el.innerHTML;
223
224 if ( str.match(regexText)==null ) {
225 alert( "Removed 1 entity!" );
226 } else {
227 alert( "Removed "+(parseInt(str.match(regexText).length)+1)+" entities!" );
228 }
229 el.innerHTML = str.replace(regexText, replaceText);
230 });
231 newbutton.appendTo(newdiv);
232
233 var newbutton = $('<button>Remove all(with newline)</button>').mouseup(function (e2) {
234 var textKeep = $(this).parent().parent().html();
235 var regexText=/<div(.*?)<\/div>/g;
236 var replaceText="";
237 textKeep = textKeep.replace(regexText, replaceText);
238
239 $(this).parent().remove();
240
241 var el = document.getElementById("editable-area");
242 var regexText=new RegExp("<br><"+tagName+">("+textKeep+")</"+tagName+">", "g");
243 var replaceText="$1";
244 var str="" + el.innerHTML;
245
246 alert( "Removed "+str.match(regexText).length+" entities!" );
247 el.innerHTML = str.replace(regexText, replaceText);
248 });
249 newbutton.appendTo(newdiv);
250
251 tagObject.append(newdiv);
252 }
253
254
255 <?php
256 foreach ( $taglistArray as $taglistValue ) {
257 echo '$(document).on("click", "'.$taglistValue[2].'", function (e) {'."\n";
258 echo "\t".'if ( $(this).prop("tagName").toLowerCase() != "'.$taglistValue[2].'" ) return 0;'."\n";
259 echo "\t".'if ( $("#editTextId").html() != "Edit the text" ) return 0;'."\n";
260 echo "\tremoveTagNewDiv( e, \"".$taglistValue[2]."\", $(this) );\n";
261 echo "});\n";
262 }
263 ?>
264 $(document).on("click", "name", function (e) {
265 if ( $("#editTextId").html() != "Edit the text" ) return 0;
266 if ( $(this).prop("tagName").toLowerCase() != "name" ) return 0;
267 removeTagNewDiv( e, "name", $(this) );
268 });
269
270 $(document).on("mouseup", '#editable-area', function (e) {
271 $('.questionMarkClass').remove();
272 $('.tagItemDivClass').remove();
273
274 if ( $("#editTextId").html() != "Edit the text" ) return 0;
275 var selection = getSelected();
276 range = getSelected().getRangeAt(0);
277
278 container = document.createElement("div");
279 container.appendChild(selection.getRangeAt(0).cloneContents());
280
281 if(selection && (selection = new String(selection).replace(/^\s+|\s+$/g,''))) {
282
283 var newdiv = document.createElement("div");
284 newdiv.id = "tagItemDivId";
285 newdiv.setAttribute("class", "tagItemDivClass");
286 newdiv.style.cssText = 'top:'+e.pageY+'; left:'+e.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px';
287
288 //console.log(selection.getRangeAt(0).cloneContents());
289 if ( container.innerHTML.indexOf( "br" ) != -1 ) {
290 var newselect = document.createElement("select");
291 newselect.id = "TitletagType";
292 <?php
293 foreach ( $taglistArray as $taglistValue ) {
294 echo "newselect.innerHTML += \"<option value='".$taglistValue[2]."'>".$taglistValue[1]."</option>\";\n";
295 }
296 ?>
297
298 newdiv.appendChild(newselect);
299
300 newdiv.innerHTML += "<input id=\"TitletagName\"></br>";
301 newdiv.innerHTML += "<button onclick=\"addTagTitle( range, container )\">Add Title Tag To Each Line</button></br>";
302 newdiv.innerHTML += "<button onclick=\"exportTable( range, container )\">Export As A Table</button>";
303 } else {
304 newdiv.innerHTML = "Tag: "+String(selection)+"<br>";
305
306 newdiv.innerHTML += "<button onclick=\"tagwithtitle( range, '"+String(selection)+"' )\">Tag As Title</button></br>";
307
308 <?php
309 foreach ( $taglistArray as $taglistValue ) {
310 if ( $taglistValue[2] == "person") {
311 echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n";
312 echo "newdiv.innerHTML += \"<button accesskey=\\\"2\\\" onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n";
313 } else {
314 echo "newdiv.innerHTML += \"<button onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n";
315 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n";
316 }
317 }
318 ?>
319 }
320 $('body').append(newdiv);
321 }
322 //e.stopPropagation();
323 });
324
325 function addTagTitle( range, container ) {
326 tag = "<"+$('#TitletagType').val()+">〈"+$('#TitletagName').val()+"〉</"+$('#TitletagType').val()+">";
327 range.deleteContents();
328 var stringtemp = container.innerHTML;
329 var regexText=/<br>/g;
330 var replaceText="<br>"+tag;
331 stringtemp = stringtemp.replace(regexText, replaceText);
332
333 var newdiv = document.createElement("aaaa");
334 newdiv.innerHTML = tag+stringtemp;
335 range.insertNode(newdiv);
336
337 var el = document.getElementById("editable-area");
338
339 var regexText=/<aaaa>/gi;
340 var replaceText='';
341 el.innerHTML = el.innerHTML.replace(regexText, replaceText);
342
343 var regexText=/<\/aaaa>/gi;
344 var replaceText='';
345 el.innerHTML = el.innerHTML.replace(regexText, replaceText);
346 }
347
348 function exportTable( range, container ) {
349 var form = document.createElement("form");
350 form.setAttribute("method", "post");
351 form.setAttribute("action", "exportTable.php");
352 form.setAttribute("target", "_blank");
353
354 var hiddenField = document.createElement("input");
355 hiddenField.setAttribute("name", "content");
356 hiddenField.setAttribute("value", container.innerHTML);
357 form.appendChild(hiddenField);
358
359 var hiddenField = document.createElement("input");
360 hiddenField.setAttribute("name", "sectionid");
361 hiddenField.setAttribute("value", "<?php echo $section_id; ?>");
362 form.appendChild(hiddenField);
363
364 //document.body.appendChild(form);
365 form.submit();
366 }
367
368 function exportPage() {
369 var startPage = $('#exportPageStart').val();
370 var endPage = $('#exportPageEnd').val();
371
372 var el = document.getElementById("editable-area");
373 var str="" + el.innerHTML;
374
375 var regexText="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】";
376
377 var form = document.createElement("form");
378 form.setAttribute("method", "post");
379 form.setAttribute("action", "exportTable.php");
380 form.setAttribute("target", "_blank");
381
382 var hiddenField = document.createElement("input");
383 hiddenField.setAttribute("name", "content");
384 hiddenField.setAttribute("value", str.match(new RegExp(regexText, "g")));
385 form.appendChild(hiddenField);
386
387 var hiddenField = document.createElement("input");
388 hiddenField.setAttribute("name", "sectionid");
389 hiddenField.setAttribute("value", "<?php echo $section_id; ?>");
390 form.appendChild(hiddenField);
391
392 //document.body.appendChild(form);
393 form.submit();
394 }
395
396 function exportAll() {
397
398 var el = document.getElementById("editable-area");
399 var str="" + el.innerHTML;
400
401 var form = document.createElement("form");
402 form.setAttribute("method", "post");
403 form.setAttribute("action", "exportTable.php");
404 form.setAttribute("target", "_blank");
405
406 var hiddenField = document.createElement("input");
407 hiddenField.setAttribute("name", "content");
408 hiddenField.setAttribute("value", str);
409 form.appendChild(hiddenField);
410
411 var hiddenField = document.createElement("input");
412 hiddenField.setAttribute("name", "sectionid");
413 hiddenField.setAttribute("value", "<?php echo $section_id; ?>");
414 form.appendChild(hiddenField);
415
416 //document.body.appendChild(form);
417 form.submit();
418 }
419
420 function cleanUpTextArea() {
421 var el = document.getElementById("editable-area");
422
423 var regexText=/<div>/gi;
424 var replaceText='<br>';
425 el.innerHTML = el.innerHTML.replace(regexText, replaceText);
426
427 var regexText=/<\/div>/gi;
428 var replaceText='';
429 el.innerHTML = el.innerHTML.replace(regexText, replaceText);
430
431
432 var regexText=/<span style="(.*?)">/gi;
433 var replaceText='';
434 el.innerHTML = el.innerHTML.replace(regexText, replaceText);
435
436 var regexText=/<\/span>/gi;
437 var replaceText='';
438 el.innerHTML = el.innerHTML.replace(regexText, replaceText);
439 }
440
441 function Undo() {
442 var el = document.getElementById("editable-area");
443 el.innerHTML = stringBeforeChange;
444 stringBeforeChange="";
445 var el = document.getElementById("buttonUndo");
446 el.disabled = true;
447 }
448
449 function saveUndoText() {
450 var el = document.getElementById("editable-area");
451 stringBeforeChange = el.innerHTML;
452 var el = document.getElementById("buttonUndo");
453 el.disabled = false;
454 }
455
456 function editText() {
457 var el = document.getElementById("editable-area");
458 if ( $("#editTextId").html() == "Edit the text" ) {
459 saveUndoText();
460 el.contentEditable = true;
461 $("button").attr("disabled", true);
462 $("#editTextId").attr("disabled", false);
463 $("#editTextId").html("Edit completed!");
464 } else {
465 el.contentEditable = false;
466 cleanUpTextArea();
467 $("button").attr("disabled", false);
468 $("#editTextId").html("Edit the text");
469 }
470 }
471
472 function saveText() {
473 var el = document.getElementById("editable-area");
474
475 $.ajax({
476 url : 'save_full_text.php',
477 async : false,
478 type : 'POST',
479 data : 'text='+encodeURIComponent(el.innerHTML)+'&filename=<?php echo $section_id; ?>'
480 }).done(function(result) {
481 alert("Saved!");
482 });
483
484 }
485
486 function preg_quote (str, delimiter) {
487 // http://kevin.vanzonneveld.net
488 // + original by: booeyOH
489 // + improved by: Ates Goral (http://magnetiq.com)
490 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
491 // + bugfixed by: Onno Marsman
492 // + improved by: Brett Zamir (http://brett-zamir.me)
493 // * example 1: preg_quote("$40");
494 // * returns 1: '\$40'
495 // * example 2: preg_quote("*RRRING* Hello?");
496 // * returns 2: '\*RRRING\* Hello\?'
497 // * example 3: preg_quote("\\.+*?[^]$(){}=!<>|:");
498 // * returns 3: '\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:'
499 return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&');
500 }
501
502 function replaceRegex() {
503 saveUndoText();
504 var el = document.getElementById("editable-area");
505 var regexText=document.getElementById("regexText").value;
506 var replaceText=document.getElementById("replaceText").value;
507 var str="" + el.innerHTML;
508
509
510 alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" );
511 el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText);
512
513 //document.styleSheets[0].addRule("tag001", "color:green;")
514 }
515
516 function replaceSmartRegex() {
517 saveUndoText();
518 var el = document.getElementById("editable-area");
519 var regexText=document.getElementById("regexText").value;
520
521 <?php
522 foreach ( $wordlistArray as $wordlistValue ) {
523 echo "\tvar regexText1=\"List ".$wordlistValue[1]."\";\n";
524 echo "\tregexText1 = preg_quote(regexText1);\n";
525 echo "\tvar replaceText1=\"".$wordlistValue[2]."\";\n";
526 echo "\tregexText = regexText.replace(new RegExp(regexText1, \"g\"), replaceText1);\n\n";
527 }
528 ?>
529
530 var replaceText=document.getElementById("replaceText").value;
531 var str="" + el.innerHTML;
532
533 alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" );
534 el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText);
535
536 //document.styleSheets[0].addRule("tag001", "color:green;")
537 }
538
539 //Tagging Items
540 function getSelected() {
541 if(window.getSelection) {
542 return window.getSelection();
543 } else if (document.getSelection) {
544 return document.getSelection();
545 } else {
546 var selection = document.selection && document.selection.createRange();
547 if(selection.text) {
548 return selection.text;
549 }
550 return false;
551 }
552 return false;
553 }
554
555 function tagStringWithTag( stringValue, tag ) {
556 var el = document.getElementById("editable-area");
557 var regexText="("+String(stringValue)+")";
558 if ( tag=="person") {
559 var replaceText="<br><"+tag+">$1</"+tag+">";
560 } else {
561 var replaceText="<"+tag+">$1</"+tag+">";
562 }
563 var str="" + el.innerHTML;
564
565 $('.tagItemDivClass').remove();
566 alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" );
567 el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText);
568 }
569
570
571 function tagwithtitle( range, stringSelection ) {
572 range.deleteContents();
573 //var newdiv = document.createElement("br");
574 //range.insertNode(newdiv);
575 range.insertNode(document.createTextNode("〈"+stringSelection+"〉"));
576 var newdiv = document.createElement("br");
577 range.insertNode(newdiv);
578 }
579
580 function tagwithOnlytag( range, stringSelection, tag ) {
581 range.deleteContents();
582 var newdiv = document.createElement(tag);
583 newdiv.innerHTML = stringSelection;
584 range.insertNode(newdiv);
585 if ( tag=="person") {
586 var newdiv = document.createElement("br");
587 range.insertNode(newdiv);
588 }
589 $('.tagItemDivClass').remove();
590 }
591
592 function tagNameWithLastName() {
593 saveUndoText();
594 var el = document.getElementById("editable-area");
595 var regexText=/(○|】|^)(王|李|張|趙|劉|陳|楊|吳|黃|黄|朱|孫|郭|胡|呂|高|宋|徐|程|林|鄭|范|何|韓|曹|馬|許|田|馮|杜|周|曾|汪|蘇|董|方|蔡|梁|石|謝|賈|薛|彭|崔|唐|潘|鄧|史|錢|侯|魏|羅|葉|沈|孟|姚|傅|丁|章|蕭|蔣|盧|陸|袁|晁|譚|邵|歐陽|孔|詹|俞|尹|廖|閻|洪|夏|雷|葛|文|柳|陶|毛|丘|龔|蒲|邢|郝|龐|安|裴|折|施|游|金|鄒|湯|虞|嚴|鍾)([^○]{1,3}|○[^○])(?=(○|$))/g;
596 var replaceText="$1<br><person>$2$3</person>$4";
597 var str="" + el.innerHTML;
598
599 alert( "Tagged "+str.match(regexText).length+" entities!" );
600 el.innerHTML = str.replace(regexText, replaceText);
601 }
602
603 function tagNameWithLastName2() {
604 saveUndoText();
605 var el = document.getElementById("editable-area");
606 var regexText="(○|】|^)("+$('#surname').val()+")([^○]{1,3}|○.)(?=(○|$))";
607 var replaceText="$1<br><person>$2$3</person>$4";
608 var str="" + el.innerHTML;
609
610 alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" );
611 el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText);
612 }
613
614 function tagTime() {
615 saveUndoText();
616 var el = document.getElementById("editable-area");
617 var str="" + el.innerHTML;
618
619 var regexText=/(<?php echo $wordlistArray[0][2]; ?>)(○?)(一|二|三|四|五|六|七|八|九)?(○?)(十)?(○?)(一|二|三|四|五|六|七|八|九|元|十)(○?)(年)/g;
620 var replaceText="<time>$1$2$3$4$5$6$7$8$9</time>";
621 var matchedCount = str.match(regexText).length;
622 str = str.replace(regexText, replaceText);
623
624 var regexText=/(?!(>))(<?php echo $wordlistArray[0][2]; ?>)/g;
625 var replaceText="<time>$1$2</time>";
626 matchedCount += str.match(regexText).length;
627 el.innerHTML = str.replace(regexText, replaceText);
628
629 var regexText=/(一|二|三|四|五|六|七|八|九)?(○?)(十)?(○?)(一|二|三|四|五|六|七|八|九|元|十)(○?)(年)(?!(<))/g;
630 var replaceText="<time>$1$2$3$4$5$6$7</time>";
631 matchedCount += str.match(regexText).length;
632 el.innerHTML = str.replace(regexText, replaceText);
633
634 alert( "Tagged "+matchedCount+" entities!" );
635 }
636
637 function tagBiogAddr() {
638 saveUndoText();
639 var el = document.getElementById("editable-area");
640 var str="" + el.innerHTML;
641
642 var regexText=/(○)([^○]{1,6})(○?)(人)/g;
643 var replaceText="$1<biog_addr>$2</biog_addr>$3$4";
644 el.innerHTML = str.replace(regexText, replaceText);
645
646 alert( "Tagged "+str.match(regexText).length+" entities!" );
647 }
648
649 function smartRegexNew() {
650 $('#smartRegexPopUpDiv').css("display", "block");
651 $('#smartRegexPopUpDiv').css("background-color", "White");
652 $('#smartRegexPopUpDiv').css("width", "400px");
653 $('#smartRegexPopUpDiv').css("height", "300px");
654 $('#smartRegexPopUpDiv').css("top", "100px");
655 $('#smartRegexPopUpDiv').css("left", "-200px");
656 $('#smartRegexPopUpDiv').css("border", "1px solid black");
657 $('#smartRegexPopUpDiv').css("padding", "5px");
658
659 $('#smartRegexPopUpAdd').attr("disabled", false);
660 $('#smartRegexPopUpEdit').attr("disabled", "disabled");
661 $('#smartRegexPopUpDel').attr("disabled", "disabled");
662 $('#smartRegexPopUpBack').attr("disabled", "disabled");
663 $('#smartRegexPopUpFor').attr("disabled", "disabled");
664 }
665
666 function replaceSmartClose() {
667 $('#smartRegexPopUpDiv').css("display", "none");
668 $("#smartRegexPopUpSelectWord").val("NULL");
669 $("#smartRegexPopUpText").val("");
670 $("#smartRegexPopUpName").val("");
671 }
672
673 function replaceSmartEdit(){
674 thisObject = $('#smartRegexPopUpDiv').attr("editID");
675
676 $('#'+thisObject).attr("class", "span_"+$("#smartRegexPopUpSelectTag").val());
677 $('#'+thisObject).attr("regexText", $("#smartRegexPopUpText").val());
678 $('#'+thisObject).attr("regexReplace", $("#smartRegexPopUpSelectTag").val());
679 }
680
681 function replaceSmartDel() {
682 thisObject = $('#smartRegexPopUpDiv').attr("editID");
683 $('#'+thisObject).remove();
684 }
685
686 function replaceSmartFor() {
687 thisObject = $('#smartRegexPopUpDiv').attr("editID");
688 var wahaha = $('#'+thisObject).clone();
689 $('#'+thisObject).insertAfter( $('#'+thisObject).next() );
690 }
691
692 function replaceSmartBack() {
693 thisObject = $('#smartRegexPopUpDiv').attr("editID");
694 var wahaha = $('#'+thisObject).clone();
695 $('#'+thisObject).insertBefore( $('#'+thisObject).prev() );
696 }
697
698 function replaceSmartAdd() {
699 var newdiv = document.createElement("span");
700 newdiv.innerHTML = " "+$("#smartRegexPopUpName").val()+" ";
701 $(newdiv).css("border", "1px solid black");
702 $(newdiv).css("width", "100px");
703
704 $(newdiv).attr("class", "span_"+$("#smartRegexPopUpSelectTag").val());
705 $(newdiv).attr("id", "span_"+$("#smartRegexPopUpName").val());
706 $(newdiv).attr("regexText", $("#smartRegexPopUpText").val());
707 $(newdiv).attr("regexReplace", $("#smartRegexPopUpSelectTag").val());
708
709 $('#smartRegexShowDiv').append(newdiv);
710
711 replaceSmartClose();
712 }
713
714 $(document).on("click", '#smartRegexShowDiv > span', function (e) {
715 $('#smartRegexPopUpDiv').css("display", "block");
716 $('#smartRegexPopUpDiv').css("background-color", "White");
717 $('#smartRegexPopUpDiv').css("width", "400px");
718 $('#smartRegexPopUpDiv').css("height", "300px");
719 $('#smartRegexPopUpDiv').css("top", "100px");
720 $('#smartRegexPopUpDiv').css("left", "-200px");
721 $('#smartRegexPopUpDiv').css("border", "1px solid black");
722 $('#smartRegexPopUpDiv').css("padding", "5px");
723
724 $('#smartRegexPopUpDiv').attr("editID", $(this).attr("id"));
725
726 $('#smartRegexPopUpName').val($(this).html());
727 $('#smartRegexPopUpText').val($(this).attr("regexText"));
728 $('#smartRegexPopUpSelectTag').val($(this).attr("regexReplace"));
729
730 $('#smartRegexPopUpAdd').attr("disabled", "disabled");
731 $('#smartRegexPopUpEdit').attr("disabled", false);
732 $('#smartRegexPopUpDel').attr("disabled", false);
733 $('#smartRegexPopUpBack').attr("disabled", false);
734 $('#smartRegexPopUpFor').attr("disabled", false);
735 });
736
737 function smartRegexEmpty() {
738 $('#smartRegexShowDiv').html("");
739 }
740
741 function replaceSmartRun() {
742
743 var replaceSmartRegexString = "";
744 var replaceSmartReplaceString = "";
745 var count=1;
746
747 $('#smartRegexShowDiv').children('span').each(function () {
748 replaceSmartRegexString += "(" + $(this).attr("regexText") + ")";
749 if ( $(this).attr("regexReplace") == "notag" ) {
750 replaceSmartReplaceString += "$" + count;
751 } else {
752 replaceSmartReplaceString += "<" + $(this).attr("regexReplace") + ">" + "$" + count + "</"+ $(this).attr("regexReplace") +">";
753 }
754 count++;
755 });
756
757 //alert(replaceSmartRegexString);
758 //alert(replaceSmartReplaceString);
759 saveUndoText();
760 var el = document.getElementById("editable-area");
761 var str="" + el.innerHTML;
762
763 alert( "Tagged "+str.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" );
764 el.innerHTML = str.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString);
765
766 }
767
768 function replaceSmartRunSpace() {
769
770 var replaceSmartRegexString = "";
771 var replaceSmartReplaceString = "";
772 var count=1;
773
774 $('#smartRegexShowDiv').children('span').each(function () {
775 //alert($(this).attr("regexText"));
776 replaceSmartRegexString += "(" + $(this).attr("regexText") + ")(○*)";
777 if ( $(this).attr("regexReplace") == "notag" ) {
778 replaceSmartReplaceString += "$" + count;
779 } else {
780 replaceSmartReplaceString += "<" + $(this).attr("regexReplace") + ">" + "$" + count + "</"+ $(this).attr("regexReplace") +">";
781 }
782 count++;
783 replaceSmartReplaceString += "$" + count;
784 count++;
785 });
786
787 //alert(replaceSmartRegexString);
788 //alert(replaceSmartReplaceString);
789 saveUndoText();
790 var el = document.getElementById("editable-area");
791 var str="" + el.innerHTML;
792
793 alert( "Tagged "+str.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" );
794 el.innerHTML = str.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString);
795
796 }
797
798 function smartRegexSave() {
799 var x;
800 var name=prompt("Please enter this Regex name",RegexLoadedName);
801 if (name!=null){
802 $.ajax({
803 url : 'save_regex.php',
804 async : false,
805 type : 'POST',
806 data : 'text='+encodeURIComponent($('#smartRegexShowDiv').html())+'&filename='+name
807 }).done(function(result) {
808 alert("Saved!");
809 });
810 }
811 }
812
813 function smartRegexLoad() {
814
815
816 $('#load_regex_div').html("");
817 $('#load_regex_div').css("display", "block");
818 $('#load_regex_div').css("border", "1px solid black");
819 $('#load_regex_div').css("background-color", "White");
820 $('#load_regex_div').css("width", "200px");
821 $('#load_regex_div').css("height", "150px");
822 $('#load_regex_div').css("top", "100px");
823 $('#load_regex_div').css("left", "-200px");
824
825 var newselect = document.createElement("select");
826 newselect.id = "loadRegexSelect";
827
828 $.ajax({
829 type: 'GET',
830 url: 'load_regex.php',
831 dataType: 'json',
832 success: function (data) {
833 $.each(data, function(index, element) {
834 newselect.innerHTML += "<option value=\""+index+"\">"+index+"</option>\n";
835 //alert(index);
836 //alert(element);
837 var newdiv = document.createElement("div");
838 $(newdiv).css("display", "none");
839 $(newdiv).html(element);
840 $(newdiv).attr("id", "div_"+index);
841 $('#load_regex_div').append(newdiv);
842 });
843 }
844 });
845
846 $('#load_regex_div').append(newselect);
847 var newbutton = document.createElement("button");
848 $(newbutton).html("Load");
849 $(newbutton).attr("onclick", "loadRegexAdd()");
850 $('#load_regex_div').append(newbutton);
851 var newbutton = document.createElement("button");
852 $(newbutton).html("Close");
853 $(newbutton).attr("onclick", "$('#load_regex_div').css(\"display\", \"none\");");
854 $('#load_regex_div').append(newbutton);
855 }
856
857 var RegexLoadedName = "";
858 function loadRegexAdd() {
859 RegexLoadedName = $('#loadRegexSelect').val();
860 var divName = "div_"+$('#loadRegexSelect').val();
861 $('#smartRegexShowDiv').html( $('#'+divName).html() );
862 $('#load_regex_div').css("display", "none");
863 }
864
865 $(document).on("change", '#smartRegexPopUpSelectWord', function (e) {
866 <?php
867 foreach ( $wordlistArray as $wordlistValue ) {
868 echo "if ( $('#smartRegexPopUpSelectWord').val() == \"".$wordlistValue[0]."\") {";
869 echo "$('#smartRegexPopUpText').val(\"".$wordlistValue[2]."\");";
870 echo "}";
871 }
872 ?>
873 });
874
875 </script>
876 </head>
877 <body>
878 <table width="1250" border="1">
879 <tr>
880 <td width="980">
881 <div id="editable-area" class="area"><?php echo $stringInput; ?></div>
882 </td>
883 <td width="270" valign="top">
884 <div id="follow-scroll" style="position:absolute; width: 220" width="220">
885 <div id="load_regex_div" style="position: absolute; display: none"></div>
886 <div id="smartRegexPopUpDiv" style="position: absolute; display: none">
887 Name: <input id="smartRegexPopUpName"></input><br><br>
888 Word List:
889 <select id="smartRegexPopUpSelectWord">
890 <option value="NULL" selected>無</option>
891 <?php
892 foreach ( $wordlistArray as $wordlistValue ) {
893 echo "<option value=\"".$wordlistValue[0]."\">".$wordlistValue[1]."</option>\n";
894 }
895 ?>
896 </select>
897 <br>
898 OR (USE "|" TO SEPARATE WORDS):<br>
899 <TEXTAREA id="smartRegexPopUpText" COLS=30 ROWS=4></TEXTAREA><br><br>
900 Tag:
901 <select id="smartRegexPopUpSelectTag">
902 <?php
903 foreach ( $taglistArray as $taglistValue ) {
904 echo "<option value=\"".$taglistValue[2]."\">".$taglistValue[1]."</option>\n";
905 }
906 ?>
907 <option value="NOTAG">不標記</option>
908 </select><br>
909 <button id="smartRegexPopUpAdd" onclick="replaceSmartAdd()" style="height: 30px; width: 50px">Add</button>
910 <button id="smartRegexPopUpEdit" onclick="replaceSmartEdit()" style="height: 30px; width: 50px">Edit</button>
911 <button id="smartRegexPopUpDel" onclick="replaceSmartDel()" style="height: 30px; width: 50px">Delete</button>
912 <button id="smartRegexPopUpBack" onclick="replaceSmartBack()" style="height: 30px; width: 50px"><<</button>
913 <button id="smartRegexPopUpFor" onclick="replaceSmartFor()" style="height: 30px; width: 50px">>></button>
914 <button onclick="replaceSmartClose()" style="height: 30px; width: 50px">Close</button>
915 </div>
916 <form action="javascript:void(0);">
917 <fieldset>
918 <legend>Replace By <i><b>Smart Regex</b></i>©:</legend>
919 <div id="smartRegexShowDiv"></div><br>
920 <button onclick="smartRegexNew()" style="height: 30px; width: 220px">Add Regex Group</button></br>
921 <button onclick="replaceSmartRun()" style="height: 30px; width: 220px">Run</button></br>
922 <button onclick="replaceSmartRunSpace()" style="height: 30px; width: 220px">Run(Allow space between Group)</button></br>
923 <button onclick="smartRegexSave()" style="height: 30px; width: 70px">Save</button>
924 <button onclick="smartRegexLoad()" style="height: 30px; width: 70px">Load</button>
925 <button onclick="smartRegexEmpty()" style="height: 30px; width: 70px">Clear</button></br>
926 </fieldset>
927
928 <fieldset>
929 <legend>Tag by rule:</legend>
930 <button onclick="tagNameWithLastName()" style="height: 30px; width: 220px">Tag Word Begin With Surname</button></br>
931 <button onclick="tagNameWithLastName2()" style="height: 30px; width: 170px">Tag Word Begin With</button><input type="text" size="2" id="surname"></br>
932 <!--<button onclick="tagTime()" style="height: 30px; width: 220px">Tag Time</button></br>-->
933 <!--<button onclick="tagBiogAddr()" style="height: 30px; width: 220px">Tag BiogAddr</button></br>-->
934 <button onclick="Undo()" style="height: 30px; width: 220px" id="buttonUndo" disabled="true">Undo</button>
935 </fieldset>
936
937 <fieldset>
938 <legend>Edit:</legend>
939 <!--<button onclick="cleanUpTextArea()" style="height: 30px; width: 220px">Reform the text</button></br>-->
940 <button onclick="saveText()" style="height: 30px; width: 220px">Save the text</button></br>
941 <button onclick="editText()" id="editTextId" style="height: 30px; width: 220px">Edit the text</button></br>
942 </br>
943 <button onclick="window.open('edit_wordlist.php')" style="height: 30px; width: 220px">Manage Word List</button></br>
944 <button onclick="window.open('edit_taglist.php')" style="height: 30px; width: 220px">Manage Tag List</button></br>
945 </fieldset>
946
947 <fieldset>
948 <legend>Export:</legend>
949 Page: <input type="text" size="5" id="exportPageStart">to<input type="text" size="5" id="exportPageEnd"><br>
950 <button onclick="exportPage()" style="height: 30px; width: 220px">Export</button></br>
951 <button onclick="exportAll()" style="height: 30px; width: 220px">Export All</button></br>
952 </fieldset>
953
954 <fieldset>
955 <legend>Replace By <i><b>Regex</b></i>:</legend>
956 Regex: <input type="text" size="30" id="regexText"></br>
957 Replace: <input type="text" size="30" id="replaceText"><br>
958 <button onclick="replaceSmartRegex()">Replace!</button>
959 </fieldset>
960 </form>
961 </div>
962 </td>
963 </tr>
964 </table>
965 </body>
966 </html>