changeset 79:e6e213b26454 extractapp

Bug fixed: file crashed after saving (preg_replace remove unnecessary symbols within br tag
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 20 Apr 2015 16:55:33 +0200
parents 960ba96efce1
children c15f53afd7a5
files models/extractapp.php views/Extractapp/TaggingText.php
diffstat 2 files changed, 98 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/models/extractapp.php	Mon Apr 20 15:44:54 2015 +0200
+++ b/models/extractapp.php	Mon Apr 20 16:55:33 2015 +0200
@@ -374,7 +374,7 @@
             $require = preg_replace("/【<a(.*?)>(.*?)<\/a>】/u", "【\\2】", $require);
             $require = preg_replace('/&amp;/u', "&", $require); 
             $require = preg_replace("/○/u", " ", $require); 
-            $require = preg_replace("/<br>/u", "\n", $require);
+            $require = preg_replace("/<br(.*?)>/u", "\n", $require);
             //$require = preg_replace("/<br>/u", "\n", $require);
 
             $require = "<text_content>".$require."</text_content>\n";
@@ -1128,7 +1128,7 @@
 
 
     // =======================================
-    
+
     private function sortFunction($a,$b) {
         return strlen($b)-strlen($a);
     }
--- a/views/Extractapp/TaggingText.php	Mon Apr 20 15:44:54 2015 +0200
+++ b/views/Extractapp/TaggingText.php	Mon Apr 20 16:55:33 2015 +0200
@@ -149,6 +149,7 @@
             return 0;
         }
         */
+        // pop_remove_tag_window is a global variable which indicates if to show the remove-popup-window
         if (pop_remove_tag_window) {
             removeTagNewDiv( e, tagName , $(this));
         };
@@ -260,111 +261,115 @@
     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; z-index:4';
-        
-        //console.log(selection.getRangeAt(0).cloneContents());
-        if ( container.innerHTML.indexOf( "br" ) != -1 ) {
-            var newselect = document.createElement("select");
-            newselect.id = "TitletagType";
-            //console.log(JSON.parse('<?php echo json_encode($taglistArray) ?>'));
+        try{
+        	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; z-index:4';
+            
+            //console.log(selection.getRangeAt(0).cloneContents());
+            if ( container.innerHTML.indexOf( "br" ) != -1 ) {
+                var newselect = document.createElement("select");
+                newselect.id = "TitletagType";
+                //console.log(JSON.parse('<?php echo json_encode($taglistArray) ?>'));
 
-            <?php 
-                foreach ( $taglistArray as $taglistValue ) {
-                    echo "newselect.innerHTML += \"<option value='".$taglistValue[2]."'>".$taglistValue[1]."</option>\";\n";
+                <?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.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>";
-            */
+                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 
+                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 {
+     			// for pop up window on edit-area for tag list
+                newdiv.innerHTML = "Tag: "+String(selection)+"<br>";
+                
+                <?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 {
- 			// for pop up window on edit-area for tag list
-            newdiv.innerHTML = "Tag: "+String(selection)+"<br>";
-            
-            <?php 
-            foreach ( $taglistArray as $taglistValue ) {
 
-                if ($taglistValue[2] == $topic_tag) {
-                	echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."2' )\\\">[TopicTag]Tag as:".$taglistValue[1]."(necessary for this topic!)</button>\";\n";
-                    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 onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n";
-                    
-                    /*
-                    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";
-            		*/
-                    break;
-            	}
-            }
-            ?>
-
-            newdiv.innerHTML += "<button accesskey=\"2\" onclick=\"tagwithtitle( range, '"+String(selection)+"' )\">Tag As Title</button></br>";
-            
-            <?php 
-            	
-			    foreach ( $taglistArray as $taglistValue ) {
-                	/*
-                	if ( $taglistValue[2] == "person") {
+                    if ($taglistValue[2] == $topic_tag) {
+                    	echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."2' )\\\">[TopicTag]Tag as:".$taglistValue[1]."(necessary for this topic!)</button>\";\n";
+                        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 onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n";
+                        
+                        /*
                         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] == $topic_tag) { 
-                		// pass
-                	} 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";
-                    } 
+                		*/
+                        break;
+                	}
+                }
+                ?>
 
-                }
-            ?>
-        }
+                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] == $topic_tag) { 
+                    		// pass
+                    	} 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";
+                        } 
 
-        //$('#tagItemDivId').addClass();  // tagItemDivId is newdiv's id
-        $('body').append(newdiv);
-        
-        $('#TitletagType').val(lastAddTag);
+                    }
+                ?>
+            }
 
-        // selected some words, so hide popping up remove-tag-window
-        pop_remove_tag_window = false;   // questionMarkID
+            //$('#tagItemDivId').addClass();  // tagItemDivId is newdiv's id
+            $('body').append(newdiv);
+            
+            $('#TitletagType').val(lastAddTag);
 
+            // selected some words, so hide popping up remove-tag-window
+            pop_remove_tag_window = false;   // questionMarkID
+        }
+        catch(err){
+            pop_remove_tag_window = true;   // questionMarkID
+            
+        }
     } else {
         // without selecting any word, so pop up remove-tag-window
         pop_remove_tag_window = true;