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
17 * @param object $resource
20 function get_text_for_indexing_pdf(&$resource){
23 // SECURITY : do not allow non admin execute anything on system !!
24 if (!isadmin($USER->id
)) return;
26 // adds moodle root switch if none was defined
27 if (!isset($CFG->block_search_usemoodleroot
)){
28 set_config('block_search_usemoodleroot', 1);
31 $moodleroot = ($CFG->block_search_usemoodleroot
) ?
"{$CFG->dirroot}/" : '' ;
33 // just call pdftotext over stdout and capture the output
34 if (!empty($CFG->block_search_pdf_to_text_cmd
)){
35 preg_match("/^\S+/", $CFG->block_search_pdf_to_text_cmd
, $matches);
36 if (!file_exists("{$moodleroot}{$matches[0]}")){
37 mtrace('Error with pdf to text converter command : executable not found at '.$moodleroot.$matches[0]);
40 $file = escapeshellarg($CFG->dataroot
.'/'.$resource->course
.'/'.$resource->reference
);
41 $command = trim($CFG->block_search_pdf_to_text_cmd
);
42 $text_converter_cmd = "{$moodleroot}{$command} $file -";
43 $result = shell_exec($text_converter_cmd);
48 mtrace('Error with pdf to text converter command : execution failed for '.$text_converter_cmd.'. Check for execution permission on pdf converter executable.');
54 mtrace('Error with pdf to text converter command : command not set up. Execute once search block configuration.');