3 * Global Search Engine for Moodle
7 * @subpackage document_wrappers
8 * @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
10 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
12 * @note : The Adobe SWF Converters library is not GPL, although it can be of free use in some
13 * situations. This file is provided for convenience, but should use having a glance at
14 * {@link http://www.adobe.com/licensing/developer/}
16 * this is a format handler for getting text out of a proprietary binary format
17 * so it can be indexed by Lucene search engine
21 * @param object $resource
24 function get_text_for_indexing_swf(&$resource, $directfile = ''){
27 // SECURITY : do not allow non admin execute anything on system !!
28 if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM
))) return;
30 // adds moodle root switch if none was defined
31 if (!isset($CFG->block_search_usemoodleroot
)){
32 set_config('block_search_usemoodleroot', 1);
35 $moodleroot = ($CFG->block_search_usemoodleroot
) ?
"{$CFG->dirroot}/" : '' ;
37 // just call pdftotext over stdout and capture the output
38 if (!empty($CFG->block_search_pdf_to_text_cmd
)){
39 $command = trim($CFG->block_search_swf_to_text_cmd
);
40 if (!file_exists("{$moodleroot}{$command}")){
41 mtrace('Error with swf to text converter command : executable not found as '.$moodleroot.$command);
43 if ($directfile == ''){
44 $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
46 $file = escapeshellarg("{$CFG->dataroot}/{$directfile}");
48 $text_converter_cmd = "{$moodleroot}{$command} -t $file";
49 $result = shell_exec($text_converter_cmd);
51 // result is in html. We must strip it off
52 $result = preg_replace("/<[^>]*>/", '', $result);
53 $result = preg_replace("/<!--[^>]*-->/", '', $result);
54 $result = html_entity_decode($result, ENT_COMPAT
, 'UTF-8');
55 $result = mb_convert_encoding($result, 'UTF-8', 'auto');
60 mtrace('Error with swf to text converter command : execution failed for '.$text_converter_cmd.'. Check for execution permission on swf converter executable.');
65 mtrace('Error with swf to text converter command : command not set up. Execute once search block configuration.');