3 * FusionForge document manager
5 * Copyright 2005, Fabio Bertagnin
6 * Copyright 2009-2010, Franck Villaume - Capgemini
7 * Copyright 2011, Franck Villaume - TrivialDev
8 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
9 * http://fusionforge.org
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
36 * @param string path to the parser list file
37 * @return boolean true
39 function Parsedata() {
40 $this->p_path = dirname(__FILE__).'/engine/';
41 $this->parsers = $this->get_parser_list($this->p_path);
45 function get_parse_data($data, $title, $description, $filetype) {
49 if (array_key_exists($filetype, $this->parsers)) {
50 // parse data if good parser exists
51 $parser = $this->p_path.$this->parsers[$filetype];
52 $filename = tempnam("/tmp/", "tmp");
53 $fp = fopen($filename, "w");
56 $cmd = "php -f $parser $filename";
57 $rep = shell_exec($cmd);
58 if (file_exists($filename)) {
62 // always parse titre and description
63 $data2 = utf8_decode("$title $description");
64 // temporary file for treatement
65 $filename = tempnam("/tmp", "tmp");
66 $fp = fopen($filename, "w");
69 $cmd = $this->p_path.$this->parsers["text/plain"];
70 $cmd = "php -f $cmd $filename";
71 $rep1 = shell_exec($cmd);
72 // dont need to unlink the filename because parser_text already remove it
73 return preg_replace("/\n/", " ", "$rep $rep1");
76 function get_parser_list($parser_path) {
77 $file = $parser_path."parser_list.txt";
79 $fp = fopen($file, "r");
81 $buff = fread($fp, 2048);
82 $a1 = explode("\n", $buff);
84 if (trim($a) != "" && substr($a, 0,1) != "#") {
85 $a2 = explode ("|", $a);
86 $rep[$a2[0]] = $a2[1];
96 // c-file-style: "bsd"