MDL-27718 Files embedded into the course summary and section summaries are migrated...
[moodle.git] / search / documents / physical_doc.php
bloba6beb18600e9284c99f24dcdb26298befa6f6c14
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
11 * @version revised for Moodle 2.0
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 * @param string $directfile if the resource is given as a direct file path, use it as reference to the file
21 * @uses $CFG
23 function get_text_for_indexing_doc(&$resource, $directfile = ''){
24 global $CFG;
26 // SECURITY : do not allow non admin execute anything on system !!
27 if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) return;
29 // adds moodle root switch if none was defined
30 if (!isset($CFG->block_search_usemoodleroot)){
31 set_config('block_search_usemoodleroot', 1);
34 $moodleroot = ($CFG->block_search_usemoodleroot) ? "{$CFG->dirroot}/" : '' ;
36 // just call pdftotext over stdout and capture the output
37 if (!empty($CFG->block_search_word_to_text_cmd)){
38 if (!file_exists("{$moodleroot}{$CFG->block_search_word_to_text_cmd}")){
39 mtrace('Error with MSWord to text converter command : executable not found at '.$moodleroot.$CFG->block_search_word_to_text_cmd);
40 } else {
41 if ($directfile == ''){
42 $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
43 } else {
44 $file = escapeshellarg("{$CFG->dataroot}/{$directfile}");
46 $command = trim($CFG->block_search_word_to_text_cmd);
47 $text_converter_cmd = "{$moodleroot}{$command} -m UTF-8.txt $file";
48 if ($CFG->block_search_word_to_text_env){
49 putenv($CFG->block_search_word_to_text_env);
51 mtrace("Executing : $text_converter_cmd");
52 $result = shell_exec($text_converter_cmd);
53 if ($result){
54 return mb_convert_encoding($result, 'UTF-8', 'auto');
55 } else {
56 mtrace('Error with MSWord to text converter command : execution failed. ');
57 return '';
60 } else {
61 mtrace('Error with MSWord to text converter command : command not set up. Execute once search block configuration.');
62 return '';