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 * Copyright 2012, Franck Villaume - TrivialDev
10 * http://fusionforge.org
12 * This file is part of FusionForge. FusionForge is free software;
13 * you can redistribute it and/or modify it under the terms of the
14 * GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the Licence, or (at your option)
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
37 * @param string path to the parser list file
38 * @return boolean true
40 function __construct() {
41 $this->p_path = dirname(__FILE__).'/engine/';
42 $this->parsers = $this->get_parser_list($this->p_path);
45 function get_parse_data($data, $title, $description, $filetype, $filename) {
48 if (array_key_exists($filetype, $this->parsers)) {
49 // parse data if good parser exists
50 $parser = $this->p_path.$this->parsers[$filetype];
51 $cmd = "php -f $parser $data";
52 $rep = shell_exec($cmd);
54 // always parse title, description, filename and filetype
55 $data1 = utf8_decode("$title $description $filename $filetype");
56 // temporary file for treatement
57 $filename = tempnam(forge_get_config('data_path'), 'tmp');
58 $handle = fopen($filename, 'w');
59 fwrite($handle, $data1);
61 $cmd = $this->p_path.$this->parsers['text/plain'];
62 $cmd = "php -f $cmd $filename";
63 $rep1 = shell_exec($cmd);
64 if ( file_exists ($filename ) ) {
67 // dont need to unlink the filename because parser_text already remove it
68 return preg_replace("/\n/", " ", "$rep $rep1");
71 function get_parser_list($parser_path) {
72 $file = $parser_path.'parser_list.txt';
74 $handle = fopen($file, 'r');
76 $buff = fread($handle, 2048);
77 $lines = explode("\n", $buff);
78 foreach ($lines as $a) {
79 if (trim($a) != "" && substr($a, 0,1) != "#") {
80 $a2 = explode ("|", $a);
81 $rep[$a2[0]] = $a2[1];
91 // c-file-style: "bsd"