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 * this is a format handler for getting text out of a proprietary binary format
13 * so it can be indexed by Lucene search engine
18 * @param object $resource
21 function get_text_for_indexing_doc(&$resource){
24 // SECURITY : do not allow non admin execute anything on system !!
25 if (!isadmin($USER->id
)) return;
27 $moodleroot = (@$CFG->block_search_usemoodleroot
) ?
"{$CFG->dirroot}/" : '' ;
29 // just call pdftotext over stdout and capture the output
30 if (!empty($CFG->block_search_word_to_text_cmd
)){
31 if (!file_exists("{$moodleroot}{$CFG->block_search_word_to_text_cmd}")){
32 mtrace('Error with MSWord to text converter command : exectuable not found.');
35 $file = escapeshellarg($CFG->dataroot
.'/'.$resource->course
.'/'.$resource->reference
);
36 $command = trim($CFG->block_search_word_to_text_cmd
);
37 $text_converter_cmd = "{$moodleroot}{$command} $file";
38 if ($CFG->block_search_word_to_text_env
){
39 putenv($CFG->block_search_word_to_text_env
);
41 mtrace("Executing : $text_converter_cmd");
42 $result = shell_exec($text_converter_cmd);
44 return mb_convert_encoding($result, 'UTF8', 'auto');
47 mtrace('Error with MSWord to text converter command : execution failed. ');
53 mtrace('Error with MSWord to text converter command : command not set up. Execute once search block configuration.');