3 * Global Search Engine for Moodle
7 * @subpackage document_wrappers
8 * @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
9 * @contributor Tatsuva Shirai 20090530
11 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
13 * this is a format handler for getting text out of a proprietary binary format
14 * so it can be indexed by Lucene search engine
19 * @param object $resource
22 function get_text_for_indexing_doc(&$resource, $directfile = ''){
25 // SECURITY : do not allow non admin execute anything on system !!
26 if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM
))) return;
28 $moodleroot = (@$CFG->block_search_usemoodleroot
) ?
"{$CFG->dirroot}/" : '' ;
30 // just call antiword over stdout and capture the output
31 if (!empty($CFG->block_search_word_to_text_cmd
)){
32 // we need to remove any line command options...
33 preg_match("/^\S+/", $CFG->block_search_word_to_text_cmd
, $matches);
34 if (!file_exists("{$moodleroot}{$matches[0]}")){
35 mtrace('Error with MSWord to text converter command : executable not found at '.$moodleroot.$CFG->block_search_word_to_text_cmd
);
37 if ($directfile == ''){
38 $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
40 $file = escapeshellarg("{$CFG->dataroot}/{$directfile}");
42 $command = trim($CFG->block_search_word_to_text_cmd
);
43 $text_converter_cmd = "{$moodleroot}{$command} -m UTF-8.txt $file";
44 if ($CFG->block_search_word_to_text_env
){
45 putenv($CFG->block_search_word_to_text_env
);
47 mtrace("Executing : $text_converter_cmd");
48 $result = shell_exec($text_converter_cmd);
50 return mb_convert_encoding($result, 'UTF-8', 'auto');
52 mtrace('Error with MSWord to text converter command : execution failed. ');
57 mtrace('Error with MSWord to text converter command : command not set up. Execute once search block configuration.');