MDL-21868 mssql generator - improve integer meta type detection
[moodle.git] / search / documents / physical_doc.php
blob145bbd1a8b85d7390e2a5022b66b070264ef6279
1 <?php
2 /**
3 * Global Search Engine for Moodle
5 * @package search
6 * @category core
7 * @subpackage document_wrappers
8 * @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
9 * @contributor Tatsuva Shirai 20090530
10 * @date 2008/03/31
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
17 /**
18 * MS Word extractor
19 * @param object $resource
20 * @uses $CFG
22 function get_text_for_indexing_doc(&$resource, $directfile = ''){
23 global $CFG;
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);
36 } else {
37 if ($directfile == ''){
38 $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
39 } else {
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);
49 if ($result){
50 return mb_convert_encoding($result, 'UTF-8', 'auto');
51 } else {
52 mtrace('Error with MSWord to text converter command : execution failed. ');
53 return '';
56 } else {
57 mtrace('Error with MSWord to text converter command : command not set up. Execute once search block configuration.');
58 return '';