Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / search / documents / physical_pdf.php
blob12765b06863e33a736314e5738da48493bda3308
1 <?php
2 /**
3 * Global Search Engine for Moodle
4 * add-on 1.8+ : Valery Fremaux [valery.fremaux@club-internet.fr]
5 * 2007/08/02
7 * this is a format handler for getting text out of a proprietary binary format
8 * so it can be indexed by Lucene search engine
9 */
11 function get_text_for_indexing_pdf(&$resource){
12 global $CFG, $USER;
14 // SECURITY : do not allow non admin execute anything on system !!
15 if (!isadmin($USER->id)) return;
17 // just call pdftotext over stdout and capture the output
18 if (!empty($CFG->block_search_pdf_to_text_cmd)){
19 preg_match("/^\S+/", $CFG->block_search_pdf_to_text_cmd, $matches);
20 if (!file_exists("{$CFG->dirroot}/{$matches[0]}")){
21 mtrace('Error with pdf to text converter command : exectuable not found.');
23 else{
24 $file = $CFG->dataroot.'/'.$resource->course.'/'.$resource->reference;
25 $text_converter_cmd = "{$CFG->dirroot}/{$CFG->block_search_pdf_to_text_cmd} $file -";
26 $result = shell_exec($text_converter_cmd);
27 if ($result){
28 return $result;
30 else{
31 mtrace('Error with pdf to text converter command : execution failed.');
32 return '';
36 else {
37 mtrace('Error with pdf to text converter command : command not set up. Execute once search block configuration.');
38 return '';