3 * FusionForge document manager
5 * Copyright 2005, Fabio Bertagnin
6 * Copyright 2009-2010, Franck Villaume - Capgemini
7 * Copyright 2011-2012, Franck Villaume - TrivialDev
8 * Copyright (C) 2011-2012 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 __construct() {
40 $this->p_path = dirname(__FILE__).'/engine/';
41 $this->parsers = $this->get_parser_list($this->p_path);
44 function get_parse_data($data, $title, $description, $filetype, $filename) {
47 if (array_key_exists($filetype, $this->parsers)) {
48 // parse data if good parser exists
49 $parser = $this->p_path.$this->parsers[$filetype];
50 $cmd = "php -f $parser $data";
51 $rep = shell_exec($cmd);
53 // always parse title, description, filename and filetype
54 $data1 = utf8_decode("$title $description $filename $filetype");
55 // temporary file for treatement
56 $filename = tempnam("/tmp", "tmp");
57 $handle = fopen($filename, "w");
58 fwrite($handle, $data1);
60 $cmd = $this->p_path.$this->parsers["text/plain"];
61 $cmd = "php -f $cmd $filename";
62 $rep1 = shell_exec($cmd);
63 // dont need to unlink the filename because parser_text already remove it
64 return preg_replace("/\n/", " ", "$rep $rep1");
67 function get_parser_list($parser_path) {
68 $file = $parser_path."parser_list.txt";
70 $handle = fopen($file, "r");
72 $buff = fread($handle, 2048);
73 $lines = explode("\n", $buff);
74 foreach ($lines as $a) {
75 if (trim($a) != "" && substr($a, 0,1) != "#") {
76 $a2 = explode ("|", $a);
77 $rep[$a2[0]] = $a2[1];
87 // c-file-style: "bsd"