diff develop/models/extractapp.php @ 42:c245d54eab9f extractapp

config lg server url, without port
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 12 Mar 2015 17:33:30 +0100
parents 533a6c39c128
children 3d6b8fb7335d
line wrap: on
line diff
--- a/develop/models/extractapp.php	Tue Mar 10 14:13:21 2015 +0100
+++ b/develop/models/extractapp.php	Thu Mar 12 17:33:30 2015 +0100
@@ -384,7 +384,7 @@
         // save tagged text (full text) by Jorge's API to lg service
 
         // --------
-       if ($_postdata['text']){
+        if ($_postdata['text']){
             $date = date('Y_m_d_H_i_s', time());
             if ( file_exists("data/parsing_files/".$_postdata['sectionId'].".txt") ) {
                 $oldFile = file_get_contents("data/parsing_files/".$_postdata['sectionId'].".txt");
@@ -404,7 +404,6 @@
             $require = preg_replace("/<br>/u", "\n", $require);
             //$require = preg_replace("/<br>/u", "\n", $require);
 
-            // TODO: append metadata at the beginning of file
             if ($_postdata['branchId'] == 0) {
                 // -- new branch case
                 $require = "<text_content>\n".$require."</text_content>\n";
@@ -412,7 +411,7 @@
             $require = $this->AppendMetaData($require);
                 
             //saving in my local machine in developing phrase
-            file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require);
+            //file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require);
         } 
 
         // ------
@@ -431,11 +430,11 @@
         } else {
             // -- new branch case
             echo "saveNew!";
+            $user_id = "0";
             if ($_postdata['userId']) {
                 $user_id = $_postdata['userId'];
-            } else {
-                $user_id = "12";
             }
+            
             $postfields = array(
                 "text" => $require, 
                 "sectionId" => $_postdata['sectionId'],
@@ -1196,7 +1195,11 @@
 
     private function ParseMetaData($filename) {
         $text = file_get_contents($filename);
-        $xml = simplexml_load_string($text) or die("Error: Cannot load from xml string");
+        $xml = simplexml_load_string($text); //or die("Error: Cannot load from xml string");
+        if (!$xml) {
+            // when file created by section_id, read the plain text from file_get_contents
+            return $text;
+        }
 
         $this->topic = (string)$xml->topic; // set topic id