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.
38 function __construct() {
39 $this->p_path = dirname(__FILE__).'/engine/';
40 $this->parsers = $this->get_parser_list($this->p_path);
44 * get_parse_data - analyse content and metadata
46 * @param string $data the path of the file to be analysed
47 * @param string $title the file title
48 * @param string $description the file description
49 * @param string $filetype the file type
50 * @param string $filename the filename
51 * @return string the analysed content
53 function get_parse_data($data, $title, $description, $filetype, $filename) {
56 if (array_key_exists($filetype, $this->parsers)) {
57 // parse data if good parser exists
58 $parser = $this->p_path.$this->parsers[$filetype];
59 $cmd = "php -f $parser $data";
60 $rep = shell_exec($cmd);
62 // always parse title, description, filename and filetype
63 $data1 = utf8_decode("$title $description $filename $filetype");
64 // temporary file for treatment
65 $filename = tempnam(forge_get_config('data_path'), 'tmp');
66 $handle = fopen($filename, 'w');
67 fwrite($handle, $data1);
69 $cmd = $this->p_path.$this->parsers['text/plain'];
70 $cmd = "php -f $cmd $filename";
71 $rep1 = shell_exec($cmd);
72 if ( file_exists ($filename ) ) {
75 // dont need to unlink the filename because parser_text already remove it
76 return preg_replace("/\n/", " ", "$rep $rep1");
80 * get_parser_list - get the list of available parsers
82 * @param string $parser_path the path where are located the parsers
83 * @return array available parsers
85 function get_parser_list($parser_path) {
86 $file = $parser_path.'parser_list.txt';
88 $handle = fopen($file, 'r');
90 $buff = fread($handle, 2048);
91 $lines = explode("\n", $buff);
92 foreach ($lines as $a) {
93 if (trim($a) != "" && substr($a, 0,1) != "#") {
94 $a2 = explode ("|", $a);
95 $rep[$a2[0]] = $a2[1];
105 // c-file-style: "bsd"