Bumped the version up to 1.9.3
[moodle.git] / search / documents / physical_pdf.php
blobffbd45216827bfdfe093fea47dea7e9032320d33
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 * @param object $resource
18 * @uses CFG, USER
20 function get_text_for_indexing_pdf(&$resource){
21 global $CFG, $USER;
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]);
39 else{
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);
44 if ($result){
45 return $result;
47 else{
48 mtrace('Error with pdf to text converter command : execution failed for '.$text_converter_cmd.'. Check for execution permission on pdf converter executable.');
49 return '';
53 else {
54 mtrace('Error with pdf to text converter command : command not set up. Execute once search block configuration.');
55 return '';