[Fusionforge-commits] r15661 - trunk/src/common/docman

Franck VILLAUME nerville at fusionforge.org
Sun Jun 3 18:47:45 CEST 2012


Author: nerville
Date: 2012-06-03 18:47:44 +0200 (Sun, 03 Jun 2012)
New Revision: 15661

Modified:
   trunk/src/common/docman/Document.class.php
   trunk/src/common/docman/Parsedata.class.php
Log:
fix filesize and parser

Modified: trunk/src/common/docman/Document.class.php
===================================================================
--- trunk/src/common/docman/Document.class.php	2012-06-03 15:51:50 UTC (rev 15660)
+++ trunk/src/common/docman/Document.class.php	2012-06-03 16:47:44 UTC (rev 15661)
@@ -147,7 +147,7 @@
 		}
 
 		// If $filetype is "text/plain", $body convert UTF-8 encoding.
-		if (strcasecmp($filetype,"text/plain") === 0 &&
+		if (strcasecmp($filetype, "text/plain") === 0 &&
 			function_exists('mb_convert_encoding') &&
 			function_exists('mb_detect_encoding')) {
 			$data = mb_convert_encoding($data, 'UTF-8', mb_detect_encoding($data));
@@ -156,11 +156,10 @@
 		// key words for in-document search
 		if ($this->Group->useDocmanSearch()) {
 			$kw = new Parsedata();
-			$kwords = $kw->get_parse_data($data, htmlspecialchars($title), htmlspecialchars($description), $filetype);
+			$kwords = $kw->get_parse_data($data, htmlspecialchars($title), htmlspecialchars($description), $filetype, $filename);
 		} else {
 			$kwords ='';
 		}
-		$filesize = strlen($data);
 
 		db_begin();
 		$result = db_query_params('INSERT INTO doc_data (group_id, title, description, createdate, doc_group,
@@ -174,7 +173,7 @@
 							$doc_initstatus,
 							$filename,
 							$filetype,
-							$filesize,
+							filesize($data),
 							$kwords,
 							$user_id)
 					);
@@ -825,13 +824,13 @@
 			// key words for in-document search
 			if ($this->Group->useDocmanSearch()) {
 				$kw = new Parsedata();
-				$kwords = $kw->get_parse_data($data, htmlspecialchars($title), htmlspecialchars($description), $filetype);
+				$kwords = $kw->get_parse_data($data, htmlspecialchars($title), htmlspecialchars($description), $filetype, $filename);
 			} else {
 				$kwords = '';
 			}
 
 			$res = db_query_params('UPDATE doc_data SET filesize=$1, data_words=$2 WHERE group_id=$3 AND docid=$4',
-						array(strlen($data),
+						array(filesize($data),
 							$kwords,
 							$this->Group->getID(),
 							$this->getID())

Modified: trunk/src/common/docman/Parsedata.class.php
===================================================================
--- trunk/src/common/docman/Parsedata.class.php	2012-06-03 15:51:50 UTC (rev 15660)
+++ trunk/src/common/docman/Parsedata.class.php	2012-06-03 16:47:44 UTC (rev 15661)
@@ -41,24 +41,17 @@
 		$this->parsers = $this->get_parser_list($this->p_path);
 	}
 
-	function get_parse_data($data, $title, $description, $filetype) {
+	function get_parse_data($data, $title, $description, $filetype, $filename) {
 		$parser = "";
 		$rep = "";
 		if (array_key_exists($filetype, $this->parsers)) {
 			// parse data if good parser exists
 			$parser = $this->p_path.$this->parsers[$filetype];
-			$filename = tempnam("/tmp/", "tmp");
-			$handle = fopen($filename, "w");
-			fwrite($handle, $data);
-			fclose($handle);
-			$cmd = "php -f $parser $filename";
+			$cmd = "php -f $parser $data";
 			$rep = shell_exec($cmd);
-			if (file_exists($filename)) {
-				unlink($filename);
-			}
 		}
-		// always parse titre and description
-		$data1 = utf8_decode("$title $description");
+		// always parse title, description, filename and filetype
+		$data1 = utf8_decode("$title $description $filename $filetype");
 		// temporary file for treatement
 		$filename = tempnam("/tmp", "tmp");
 		$handle = fopen($filename, "w");




More information about the Fusionforge-commits mailing list