MDL-16553 Assignment, student view: whitespace fix
[moodle.git] / search / documents / physical_swf.php
blob2d8a2628c8bdae170228a1fcd170cd39945dbd0a
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 * @note : The Adobe SWF Converters library is not GPL, although it can be of free use in some
13 * situations. This file is provided for convenience, but should use having a glance at
14 * {@link http://www.adobe.com/licensing/developer/}
16 * this is a format handler for getting text out of a proprietary binary format
17 * so it can be indexed by Lucene search engine
20 /**
21 * @param object $resource
22 * @uses $CFG
24 function get_text_for_indexing_swf(&$resource, $directfile = ''){
25 global $CFG;
27 // SECURITY : do not allow non admin execute anything on system !!
28 if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) return;
30 // adds moodle root switch if none was defined
31 if (!isset($CFG->block_search_usemoodleroot)){
32 set_config('block_search_usemoodleroot', 1);
35 $moodleroot = ($CFG->block_search_usemoodleroot) ? "{$CFG->dirroot}/" : '' ;
37 // just call pdftotext over stdout and capture the output
38 if (!empty($CFG->block_search_pdf_to_text_cmd)){
39 $command = trim($CFG->block_search_swf_to_text_cmd);
40 if (!file_exists("{$moodleroot}{$command}")){
41 mtrace('Error with swf to text converter command : executable not found as '.$moodleroot.$command);
42 } else {
43 if ($directfile == ''){
44 $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
45 } else {
46 $file = escapeshellarg("{$CFG->dataroot}/{$directfile}");
48 $text_converter_cmd = "{$moodleroot}{$command} -t $file";
49 $result = shell_exec($text_converter_cmd);
51 // result is in html. We must strip it off
52 $result = preg_replace("/<[^>]*>/", '', $result);
53 $result = preg_replace("/<!--[^>]*-->/", '', $result);
54 $result = html_entity_decode($result, ENT_COMPAT, 'UTF-8');
55 $result = mb_convert_encoding($result, 'UTF-8', 'auto');
57 if ($result){
58 return $result;
59 } else {
60 mtrace('Error with swf to text converter command : execution failed for '.$text_converter_cmd.'. Check for execution permission on swf converter executable.');
61 return '';
64 } else {
65 mtrace('Error with swf to text converter command : command not set up. Execute once search block configuration.');
66 return '';