changeset 112:7bdbc7fc7936 extractapp

Replace   to space
author Calvin Yeh <cyeh@mpiwg-berlin.mpg.de>
date Thu, 04 May 2017 16:57:16 +0200
parents 3eacb630b9eb
children e26945b2aa85
files models/extractapp.php
diffstat 1 files changed, 127 insertions(+), 125 deletions(-) [+]
line wrap: on
line diff
--- a/models/extractapp.php	Thu May 04 16:21:05 2017 +0200
+++ b/models/extractapp.php	Thu May 04 16:57:16 2017 +0200
@@ -16,18 +16,18 @@
  * You should have received a copy of the GNU General Public License
  * along with Extraction-interface.  If not, see <http://www.gnu.org/licenses/>.
 */
-/** 
+/**
  * ExtractappModel class is extended from the BaseModel class.
  * This is where we implement the functions/models to prepare data that been sent to views.
  * ExtractappModel is notified by Extractapp controller when there has been a change in its state,
- * and produces the output/data to the corresponding view in "views/Extractapp/". 
- * 
+ * and produces the output/data to the corresponding view in "views/Extractapp/".
+ *
 */
 
 class ExtractappModel extends BaseModel{
-    
-    protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, 
-        $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", 
+
+    protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0,
+        $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "",
         $book_meta = "", $book_dynasty = "";
 
     public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>"");
@@ -35,7 +35,7 @@
 
     public function SetTextFromFileId() {   // remove $_postdata as input
         /**
-         * Get text content from LGService by $this->file_id. 
+         * Get text content from LGService by $this->file_id.
          * After preprocessing the text string (replace space to circle symbol, link for page number, etc),
          * set $this->lg_text to the processed text gotten from LGService.
          */
@@ -78,7 +78,7 @@
         $section_meta = json_decode(file_get_contents($section_meta_url), true);
 
         $b = $section_meta['section']['book'];
-        
+
         $this->book_name = $b['name'];
         $this->book_id = $b['id'];
         /*
@@ -122,7 +122,7 @@
 
     public function SetTextFromSectionId() {  // remove $_postdata as input
         /**
-         * Get text content from LGService by $this->section_id. 
+         * Get text content from LGService by $this->section_id.
          * After preprocessing the text string (replace space to circle symbol, link for page number, etc),
          * set $this->lg_text to the processed text gotten from LGService.
          */
@@ -154,7 +154,7 @@
     }
 
     // This is only used on localhost
-    public function SetTextFromLocal($_id){     
+    public function SetTextFromLocal($_id){
         $this->section_id = $_id;
         //$this->branch_id = 1;   // local test sets branch_id to 1
         $this->messages['debug'] .= "[Debug] from my local"."<br>";
@@ -165,12 +165,12 @@
     public function SetInfoFromPreviousPage($_postdata) {
         /**
          * Get information from post data passsed by the previous page, and set variables in $this.
-         * The previous page could be: 
+         * The previous page could be:
          *
-         * (1) LGService: the first time user enters Extraction-interface, which should linked from LGService. 
+         * (1) LGService: the first time user enters Extraction-interface, which should linked from LGService.
          *
          * (2) Extraction-interface itself: changing topic then continue to tag, saving text to LGService, reload the text from LGService.
-         * 
+         *
          */
 
         if (isset($_postdata['fileId'])) {
@@ -191,7 +191,7 @@
         if (isset($_postdata['topic'])) {
             $this->topic = $_postdata['topic'];
         }
-      
+
 
         if (isset($_postdata['sectionName'])) {
             $this->section_name = $_postdata['sectionName'];
@@ -228,7 +228,7 @@
             foreach ($list2 as $v2) {
                 $num_field = count($v2);
                 $matched = true;
-                for ($i=0; $i < $num_field; $i++) { 
+                for ($i=0; $i < $num_field; $i++) {
                     if ($v1[$i] != $v2[$i]) {
                         $matched = false;
                         break;
@@ -244,13 +244,13 @@
 
             }
             if ($cnt == $cnt_list2) {
-                return false; 
+                return false;
             }
         }
         return true;
-       
+
     }
-    
+
     // === for tagging ===
     private function ReplaceLgTextWithLatestTag() {
         // modify $this->lg_text with the latest tags from database
@@ -261,7 +261,7 @@
         $taglist_infile = $this->taglist_infile;
 
         if ($taglist_infile == "") return;
-        
+
         $count_tag_indb = count($taglist_indb);
 
         foreach ($taglist_infile as $t1) {
@@ -274,7 +274,7 @@
                 if ($t2[0] == $id) {
                     $latest_tag = $t2[2];
                 }
-               
+
                 if ($tag != $t2[2]) {
                     // not match with this t2
                     $cnt += 1;
@@ -309,19 +309,19 @@
          * This is the main method for tagging text. It passes all the information to "views/Extractapp/TaggingText.php" view.
          * The information contain the text string, taglist array, wordlis array, topic, etc.
          */
-       
+
         $section_id = $this->section_id;
-        
+
         $data = array();    // data array to be passed to view
 
-        //for GetTaglistByTopicId: 
+        //for GetTaglistByTopicId:
         $taglistArray = $this->GetTaglistByTopicId($this->GetTopic());
 
         // $this->taglist_infile is set (1) from file or (2) from _postdata['taglistArray'] which comes from frontend that user decided
         // $this->taglist_infile is the most up-to-date taglist decided by user. Should be written into file.
         if( $this->TaglistSubsetIn($this->taglist_infile, $taglistArray) ) {    // TaglistSubsetIn($l1,$l2): $l1 is a subset of $l2 or not
             $this->taglist_infile = "";
-            
+
         } else {
             // taglist_infile is out-to-date
             // replace all the old tag with new ones in database
@@ -333,7 +333,7 @@
 
 
         $data['taglist_infile'] = $this->taglist_infile;    // if taglist_infile == "" means taglist in file is up-to-date (will use taglist in db), otherwise means the taglist in file
-        
+
         // book_meta
         $data['book_meta'] = $this->book_meta;
 
@@ -356,9 +356,9 @@
         $data['topic_tag_ch'] = $this->GetTopicTagName($topic_id);
 
         $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id,
-                'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, 
+                'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id,
                 'book_name'=>$this->book_name,'section_name'=>$this->section_name, 'period'=>$this->book_meta->period,
-                'current_fileId'=>$this->current_fileId); 
+                'current_fileId'=>$this->current_fileId);
 
 
         $this->messages['debug'] .= "[Debug] ";
@@ -380,7 +380,7 @@
         $data['messages'] = $this->messages;
 
         return $data;
-        
+
     }
 
     public function SaveFullText($postdata) {
@@ -391,16 +391,17 @@
                 $oldFile = file_get_contents("data/parsing_files/".$postdata['filename'].".txt");
                 file_put_contents("data/parsing_files/".$postdata['filename']."_".$date.".txt", $oldFile);
             }
-            
+
             if (get_magic_quotes_gpc()) {
                 $require = stripslashes($postdata['text']);
             } else {
                 $require = $postdata['text'];
             }
-            
+
             $require = preg_replace("/【<a(.*?)>(.*?)<\/a>】/u", "【\\2】", $require);
-            $require = preg_replace('/&amp;/u', "&", $require); 
-            $require = preg_replace("/○/u", " ", $require); 
+            $require = preg_replace('/&amp;/u', "&", $require);
+            $require = preg_replace('/&nbsp;/u', " ", $require); //avoiding invaild xml format
+            $require = preg_replace("/○/u", " ", $require);
             $require = preg_replace("/<br>/u", "\n", $require);
             $require = preg_replace("/<br>/u", "\n", $require);
             file_put_contents("data/parsing_files/".$postdata['filename'].".txt", $require);
@@ -411,7 +412,7 @@
 
     public function UpdateInfoResponsedFromLGService($response) {
         /**
-         * 
+         *
          */
 
         if (isset($response["file"])) {
@@ -424,7 +425,7 @@
         $status = (string)$response["status"];
         if ($status == "ok") {
             $this->messages['info'] .= "[Info] Saving success. <br>";
-            $this->file_id = (string)$response_file["id"]; 
+            $this->file_id = (string)$response_file["id"];
             $this->branch_id = (string)$response_branch["id"];
 
         } else if ($status == "error") {
@@ -438,7 +439,7 @@
             $response_currentFile = $response["currentFile"];
             $this->current_fileId = (string)$response_currentFile["id"];
         }
-        
+
 
     }
 
@@ -457,7 +458,7 @@
         $text .= "<topic>".$this->topic."</topic>\n";
         // --- book meta data ---
         $book = $this->book_meta;
-       
+
         $text .= "<book>\n";
             $text .= "<id>".$book->id."</id>\n";
             $text .= "<name>".$book->name."</name>\n";
@@ -473,12 +474,12 @@
             $text .= "<edition>".$book->edition."</edition>\n";
             $text .= "<in_jibengujiku>".$book->in_jibengujiku."</in_jibengujiku>\n";
             $text .= "<admin_type>".$book->admin_type."</admin_type>\n";
-       
+
             $text .= "<place_name>".$book->place_name."</place_name>\n";
             $text .= "<x>".$book->x."</x>\n";
             $text .= "<y>".$book->y."</y>\n";
         $text .= "</book>\n";
-        
+
 
         // --- section info ---
         $text .= "<section>\n";
@@ -515,7 +516,7 @@
     public function SaveFullTextToLGService($_postdata) {
         /**
          * It saves the full tagged text string in postdata to LGService.
-         * The responses returned by LGService will later be handled in 
+         * The responses returned by LGService will later be handled in
          */
 
         // --------
@@ -530,21 +531,22 @@
                     file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile);
                 }
             }
-            
+
             if (get_magic_quotes_gpc()) {
                 $require = stripslashes($_postdata['text']);
             } else {
                 $require = $_postdata['text'];
             }
- 
+
             $require = preg_replace("/【<a(.*?)>(.*?)<\/a>】/u", "【\\2】", $require);
-            $require = preg_replace('/&amp;/u', "&", $require); 
-            $require = preg_replace("/○/u", " ", $require); 
+            $require = preg_replace('/&amp;/u', "&", $require);
+            $require = preg_replace('/&nbsp;/u', " ", $require);   //avoiding invaild xml format
+            $require = preg_replace("/○/u", " ", $require);
             $require = preg_replace("/<br(.*?)>/u", "\n", $require);
             //$require = preg_replace("/<br>/u", "\n", $require);
 
             $require = "<text_content>".$require."</text_content>\n";
-            
+
             /*
             if ($_postdata['branchId'] == 0) {
                 // -- new branch case
@@ -553,12 +555,12 @@
             */
 
             $require = $this->AppendMetadata($require);
-                
+
             //saving in my local machine in developing phrase
             if ($AT_LOCAL) {
                 file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require);
             }
-        } 
+        }
 
         // ------
 
@@ -566,12 +568,12 @@
         if ($_postdata['branchId'] != 0) {
             // -- exiting branch case
             $postfields = array(
-                "text" => $require, 
+                "text" => $require,
                 "branchId" => $_postdata['branchId'],
                 "userId" => $_postdata['userId'],
                 "userPreviousFileId" => $_postdata['fileId'],
-            );  
-            $save_url = $this->save_to_LGService_url;     
+            );
+            $save_url = $this->save_to_LGService_url;
 
         } else {
             // -- new branch case
@@ -580,17 +582,17 @@
             if ($_postdata['userId']) {
                 $user_id = $_postdata['userId'];
             }
-            
+
             $postfields = array(
-                "text" => $require, 
+                "text" => $require,
                 "sectionId" => $_postdata['sectionId'],
                 "userId" => $user_id,
                 "label" => $_postdata['label'],
-            ); 
+            );
             $save_url = $this->save_new_to_LGService_url;
-        }   
+        }
 
-        
+
         // set up the curl resource
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
@@ -600,9 +602,9 @@
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
         //curl_setopt($ch, CURLOPT_HEADER, true);
-        curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
-            'Content-type: multipart/form-data;charset=utf-8'                                                          
-        ));       
+        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+            'Content-type: multipart/form-data;charset=utf-8'
+        ));
 
         //if (!$AT_LOCAL) {
         // execute the request
@@ -615,7 +617,7 @@
 
         // close curl resource to free up system resources
         curl_close($ch);
-        
+
         $response = json_decode($output, true);
         return $response;
 
@@ -640,7 +642,7 @@
 
         // Load regex file based on current topic. Only shows the regex in this topic --
         $filenames = $this->GetRegexFilenameById($topic_id);
-        
+
         // Get regex file from filesystem ----
         $data_path = "./data/"; // get the current file path, which is getcwd(), and concatenate with "/data/"
         $returnArray = array();
@@ -666,7 +668,7 @@
             // --- update topic_regex_relation table ---
             $topic_id = $_postdata['topic_id'];
             $filename = $_postdata['filename'].'.txt';
-            
+
             // check if already existing a record for this regex file
             $query = "SELECT * FROM TopicRegexRelation WHERE topic_id=".$topic_id." AND regex_filename='".$filename."'";
             $result = mysql_query($query);
@@ -679,18 +681,18 @@
                     echo json_encode("ForceSave");
                     return;
                 }
-            } 
+            }
 
-        
+
             if (!$_postdata['forcesave']) {
                 $query = "INSERT INTO TopicRegexRelation (topic_id, regex_filename) VALUES (".$topic_id.",'".$filename."')";
                 $result = mysql_query($query);
                 if (!$result) {
                     echo json_encode("ErrorDB");
                 }
-            } 
+            }
             // --- write to filesystem ---
-            
+
             /*
             $date = date('Y_m_d_H_i_s', time());
             if ( file_exists("regex_files/".$_POST['filename'].".txt") ) {
@@ -699,14 +701,14 @@
             }
             */
             $data_path = "./data/"; // get the current file path, which is getcwd(), and concatenate with "/data/"
-            
+
             if (get_magic_quotes_gpc()) {
                 $require = stripslashes($_postdata['text']);
             } else {
                 $require = $_postdata['text'];
             }
 
-            file_put_contents( $data_path."regex_files/".$_postdata['filename'].".txt", $require);   
+            file_put_contents( $data_path."regex_files/".$_postdata['filename'].".txt", $require);
 
 
         }
@@ -770,7 +772,7 @@
                             }
                         }
                     }
-                    $otherString = preg_replace("/<".$tag_name.">(.*?)<\/".$tag_name.">/u", " ", $otherString);   
+                    $otherString = preg_replace("/<".$tag_name.">(.*?)<\/".$tag_name.">/u", " ", $otherString);
                 }
             }
             $otherString = preg_replace("/○/u", "", $otherString);
@@ -780,18 +782,18 @@
             $value = preg_replace("/</u", "&lt;", $value);
             $outputTableArray[$count]["full"] = $value;
         }
-        
-        
+
+
 
         foreach ( $outputTableArray as $arrayIndex => $arrayValue ) {
             // output each row which the topic tag
-            // e.g. the original version is for 'person'           
+            // e.g. the original version is for 'person'
             if ( !isset($arrayValue[0][$_topic_tag]) ) {
                 unset($outputTableArray[$arrayIndex]);
             }
 
         }
-        // ----- 
+        // -----
 
         return $outputTableArray;
     }
@@ -884,7 +886,7 @@
 
 
         return $data;
-       
+
     }
 
     private function GetTag($_postdata) {
@@ -903,7 +905,7 @@
     }
 
     public function NewTagElement($postdata) {
-        if ($postdata['id']){   
+        if ($postdata['id']){
             list($id, $name, $tag, $color) = $this->GetTag($postdata);
 
              // for creationDate and lastChangeDate
@@ -917,13 +919,13 @@
                                 $this->GetSQLValueString($date, "date"),
                                 $this->GetSQLValueString($date, "date"));
                                 //$this->GetSQLValueString($this->systemNAME, "text"));
-            
+
             $result1 = mysql_query($query1);
             if (!$result1) {
                 //echo json_encode("error when insert into Taglist table");
                 echo 0;
                 return;
-            } 
+            }
 
             // add it to topic_tag_relation table
             $topic_id = $postdata['topic_id'];
@@ -943,15 +945,15 @@
                 echo 1;
                 //echo json_encode("error when insert into TopicTagRelation table");
             }
-        
+
         }
 
     }
 
     public function SaveTagElement($postdata) {
-        if ($postdata['id']){   
+        if ($postdata['id']){
             list($id, $name, $tag, $color) = $this->GetTag($postdata);
-            
+
             // for lastChangeDate
             $date = date('Y-m-d H:i:s', time());
 
@@ -962,7 +964,7 @@
                                 $this->GetSQLValueString($date, "date"),
                                 $this->GetSQLValueString($id, "int"));
             $result = mysql_query($query);
-                     
+
         }
 
     }
@@ -981,11 +983,11 @@
             $result = mysql_query($query);
 
         }
-       
+
     }
 
     // === for config topic ===
-    public function CreateNewTopic($_postdata) {    
+    public function CreateNewTopic($_postdata) {
         $new_topic_id = "2";  // default topic_id=1 for 'person' topic
 
         // get user input data from postdata
@@ -995,7 +997,7 @@
         $new_topic_tag = $_postdata['new_topic_tag'];
         $new_topic_tag_name = $_postdata['new_topic_tag_name'];
 
-        // -- Start Transaction -- 
+        // -- Start Transaction --
         mysql_query("BEGIN");
 
         // create records for the new topic in database
@@ -1005,21 +1007,21 @@
             topic_tag_relation: topic_id (new), tag_id (new)
 
         - need transaction for the following actions:
-            taglist.name: topic_tag name in chinese 
+            taglist.name: topic_tag name in chinese
             taglist.tag: topic_tag name in eng
             topics.tag: (the same a taglist.tag)
             topics.name_en:
-            topics.name_ch: 
-            topics.name_pinyin: 
+            topics.name_ch:
+            topics.name_pinyin:
 
-             
+
             topic_tag_relation.topic_id = new_topic_id
-            topic_tag_relation.tag_id = new_tag_id 
+            topic_tag_relation.tag_id = new_tag_id
                 which are the new record that just been created in the 'taglist' and 'topics' table
         */
 
-        // new record in topics table           
-        $query="INSERT INTO Topic (tag, name_en, name_ch, name_pinyin) VALUES ('".$new_topic_tag."','".$new_topic_name_en."','".$new_topic_name_ch."','".$new_topic_name_pi."')";  
+        // new record in topics table
+        $query="INSERT INTO Topic (tag, name_en, name_ch, name_pinyin) VALUES ('".$new_topic_tag."','".$new_topic_name_en."','".$new_topic_name_ch."','".$new_topic_name_pi."')";
         $result_topics=mysql_query($query);
         if($result_topics){
             $new_topic_id = mysql_insert_id();
@@ -1028,7 +1030,7 @@
         }
 
         // new record in taglist table
-        $query="INSERT INTO Taglist (name, tag, color) VALUES ('".$new_topic_tag_name."','".$new_topic_tag."','rgb(255, 0, 174)')";  
+        $query="INSERT INTO Taglist (name, tag, color) VALUES ('".$new_topic_tag_name."','".$new_topic_tag."','rgb(255, 0, 174)')";
         $result_taglist=mysql_query($query);
         if($result_taglist){
             $new_tag_id = mysql_insert_id();
@@ -1037,24 +1039,24 @@
         }
 
         // new record in topic_tag_relation
-        $query="INSERT INTO TopicTagRelation (topicId, tagId) VALUES ('".$new_topic_id."','".$new_tag_id."')";  
+        $query="INSERT INTO TopicTagRelation (topicId, tagId) VALUES ('".$new_topic_id."','".$new_tag_id."')";
         $result_topic_tag_relation=mysql_query($query);
         if($result_topic_tag_relation){
-            
+
         } else {
             //echo mysql_error();
         }
 
- 
+
         // --- End Transaction ---
         if ($result_taglist && $result_topics && $result_topic_tag_relation) {
-            mysql_query("COMMIT");  
-            
+            mysql_query("COMMIT");
+
         } else {
             mysql_query("ROLLBACK");
             return "error";
         }
-        
+
 
         $_postdata['topic'] = $new_topic_id;
         return $_postdata;
@@ -1062,7 +1064,7 @@
 
     public function ConfigTagsInTopic($_postdata) {
         /**
-        * 
+        *
         */
 
         $topic = $_postdata['topic'];
@@ -1098,7 +1100,7 @@
         if (!$result) {
             return json_encode("Failed during selecting/joining Taglist and TopicTagRelation table.");
         }
-        
+
         $tag_intopic = array();
         $tag_others = array();
         $tag_tmp_others = array();
@@ -1115,9 +1117,9 @@
 
         // --- check if there's any duplicated tags in tag_tmp_others. remove the duplicated tags
         $num_others = count($tag_tmp_others);
-        for ($i=0; $i < $num_others; $i++) { 
+        for ($i=0; $i < $num_others; $i++) {
             $cnt = 0;
-            for ($j=$i+1; $j < $num_others; $j++) { 
+            for ($j=$i+1; $j < $num_others; $j++) {
                 if ($tag_tmp_others[$i]['tag'] == $tag_tmp_others[$j]['tag']) {
                     break;
                 } else {
@@ -1133,7 +1135,7 @@
         // --- remove duplicated tags in tag_others that is duplicated with tags in tag_intopic
         $tag_tmp_others = $tag_others;
         $tag_others = array();
-        
+
         foreach ($tag_tmp_others as $tmp) {
             $cnt = 0;
             foreach ($tag_intopic as $intopic) {
@@ -1148,7 +1150,7 @@
                 array_push($tag_others, $tmp);
             }
         }
-        
+
         // -----
 
 
@@ -1171,7 +1173,7 @@
 
         // update topic_tag_relation by tags_ids array as `tag_id` and topic_id as `topic_id`
 
-        
+
         // --- add new topic_tag_relation ---
         foreach ($tag_ids as $tag_id) {
             $query = "SELECT * FROM TopicTagRelation WHERE tagId=".$tag_id;
@@ -1191,17 +1193,17 @@
                 // insert a row into topic_tag_relation table
                 // $queryUpdate = "INSERT INTO TopicTagRelation (topicId, tagId) VALUES (".$topic_id.",".$tag_id.")";
 
-                $date = date('Y-m-d H:i:s', time());    
+                $date = date('Y-m-d H:i:s', time());
                 $queryUpdate = sprintf("INSERT INTO TopicTagRelation (`topicId`, `tagId`, `creationDate`, `lastChangeDate`) VALUES (%s, %s, %s, %s)",
                     $this->GetSQLValueString($topic_id, "int"),
                     $this->GetSQLValueString($tag_id, "int"),
                     $this->GetSQLValueString($date, "date"),
                     $this->GetSQLValueString($date, "date"));
 
-                $resultUpdate = mysql_query($queryUpdate); 
+                $resultUpdate = mysql_query($queryUpdate);
                 if (!$resultUpdate) {
                     return json_encode("error when insert TopicTagRelation table");
-                }   
+                }
             }
 
         }
@@ -1302,7 +1304,7 @@
 
         // TODO need to reconstruct the structure for topic tag considering user may use Uppercase but only lowercase accpetable in html tag that why we store only lowercase in Taglist.tag field in database table.
         // Temporate solution is we replace " " with "_" and .lowercase(), which are as the same as we do in LGServices when create a topic and also create the correpsonding topic tag
-        
+
         $tag = str_replace(' ', '_', $tag);
         return strtolower($tag);
 
@@ -1327,7 +1329,7 @@
 
 
 
-    // =========================== 
+    // ===========================
 
     // === for manage wordlist ===
     public function EditWordlist() {
@@ -1349,7 +1351,7 @@
 
 
     public function AddNewList($postdata) {
-        if ($postdata['text']){ 
+        if ($postdata['text']){
             if (get_magic_quotes_gpc()) {
                 $name = stripslashes($postdata['text']);
             } else {
@@ -1362,7 +1364,7 @@
             $result1 = mysql_query($query1);
             file_put_contents( "data/wordlist/".mysql_insert_id().".txt", "(empty now)");
         }
-    }  
+    }
 
 
     public function SaveWordlist($postdata) {
@@ -1373,7 +1375,7 @@
                 $filename = "data/wordlist/".$postdata['filename']."_".$date.".txt";
                 $oldFile = file_get_contents("data/wordlist/".$postdata['filename'].".txt");
                 file_put_contents($filename, $oldFile);
-            } 
+            }
             /*else {
                 $filename = "data/wordlist/".$postdata['filename'].".txt";
             }
@@ -1396,7 +1398,7 @@
                 $oldFile = file_get_contents("data/wordlist/".$postdata['filename'].".txt");
                 file_put_contents("data/wordlist/".$postdata['filename']."_".$date.".txt", $oldFile);
             }
-        
+
             if (get_magic_quotes_gpc()) {
                 $require = stripslashes($postdata['text']);
             } else {
@@ -1424,7 +1426,7 @@
             return json_encode("Error: No section id");
         }
     }
-    
+
 
     /* only used locally */
     /*
@@ -1436,7 +1438,7 @@
 
         $result = $this->GetSectionsById($section_id);
 
-        
+
         while ($row = mysql_fetch_assoc($result)) {
             $bookId=$row['books_id'];
             $startPage=$row['start_page'];
@@ -1472,7 +1474,7 @@
             array_push($taglistArray, array((string)$row->id,(string)$row->name,(string)$row->tag,(string)$row->color ));
         }
         if ($taglistArray) {
-            $this->taglist_infile = $taglistArray; 
+            $this->taglist_infile = $taglistArray;
         }
 
         // --- get book meta data from file, replaced by SetBookMetaDataBySectionId(), which retrives book meta data from LGService
@@ -1515,9 +1517,9 @@
 
 
     /** This is only been called by SetTextFromLocal().
-    */        
+    */
     /*
-    private function GetSectionContent() {  
+    private function GetSectionContent() {
 
         $section_id = $this->GetSectionId();
         $section_info = $this->GetSectionInfo();
@@ -1532,7 +1534,7 @@
         $data_path = $this->GetDataPath();
         if ( file_exists($data_path."parsing_files/".$section_id.".txt") ) {
             $filename = $data_path."parsing_files/".$section_id.".txt";
-            
+
             // --- parsing meta data
             $stringInput = $this->ParseDataInFile($filename);
             // ----
@@ -1541,7 +1543,7 @@
             $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);
-            
+
             $this->branch_id = 1;   // testing at local
 
         } else {
@@ -1553,7 +1555,7 @@
             while ($row = mysql_fetch_assoc($result)) {
                 $contentString.="【".$row['line']."】".$row['content']."\n";
             }
-           
+
             // the text is from database
             $stringInput = $contentString;
             $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput);
@@ -1567,7 +1569,7 @@
     }
     */
 
-    
+
     private function GetDataPath() {
         return getcwd()."/data/"; // get the current file path, which is getcwd(), and concatenate with "/data/"
     }
@@ -1592,7 +1594,7 @@
             $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 ) {
@@ -1600,10 +1602,10 @@
             }
             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 );
         }
@@ -1613,7 +1615,7 @@
 
     }
 
-     
+
 }