"MDL-14932, accessibility imporvement, see tracker"
[moodle-linuxchix.git] / search / documents / physical_doc.php
blobca053bde51d6eb4c41353f90f64398e19401b91c
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 * @date 2008/03/31
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
16 /**
17 * MS Word extractor
18 * @param object $resource
19 * @uses CFG, USER
21 function get_text_for_indexing_doc(&$resource){
22 global $CFG, $USER;
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.');
34 else{
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);
43 if ($result){
44 return mb_convert_encoding($result, 'UTF8', 'auto');
46 else{
47 mtrace('Error with MSWord to text converter command : execution failed. ');
48 return '';
52 else {
53 mtrace('Error with MSWord to text converter command : command not set up. Execute once search block configuration.');
54 return '';