3 * FusionForge document manager
5 * Copyright 2005, Fabio Bertagnin
6 * Copyright 2009-2010, Franck Villaume - Capgemini
7 * Copyright 2011-2013, 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
39 function __construct() {
40 $this->p_path = dirname(__FILE__).'/engine/';
41 $this->parsers = $this->get_parser_list($this->p_path);
45 * get_parse_data - analyse content and metadata
47 * @param string the path of the file to be analysed
48 * @param string the file title
49 * @param string the file description
50 * @param string the file type
51 * @param string the filename
52 * @return string the analysed content
54 function get_parse_data($data, $title, $description, $filetype, $filename) {
57 if (array_key_exists($filetype, $this->parsers)) {
58 // parse data if good parser exists
59 $parser = $this->p_path.$this->parsers[$filetype];
60 $cmd = "php -f $parser $data";
61 $rep = shell_exec($cmd);
63 // always parse title, description, filename and filetype
64 $data1 = utf8_decode("$title $description $filename $filetype");
65 // temporary file for treatement
66 $filename = tempnam(forge_get_config('data_path'), 'tmp');
67 $handle = fopen($filename, 'w');
68 fwrite($handle, $data1);
70 $cmd = $this->p_path.$this->parsers['text/plain'];
71 $cmd = "php -f $cmd $filename";
72 $rep1 = shell_exec($cmd);
73 if ( file_exists ($filename ) ) {
76 // dont need to unlink the filename because parser_text already remove it
77 return preg_replace("/\n/", " ", "$rep $rep1");
81 * get_parser_list - get the list of available parsers
83 * @param string the path where are located the parsers
84 * @return array available parsers
86 function get_parser_list($parser_path) {
87 $file = $parser_path.'parser_list.txt';
89 $handle = fopen($file, 'r');
91 $buff = fread($handle, 2048);
92 $lines = explode("\n", $buff);
93 foreach ($lines as $a) {
94 if (trim($a) != "" && substr($a, 0,1) != "#") {
95 $a2 = explode ("|", $a);
96 $rep[$a2[0]] = $a2[1];
106 // c-file-style: "bsd"