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 * first implementation is a trivial heuristic based on ppt character stream :
18 * text sequence always starts with a 00 9F 0F 04 sequence followed by a 15 bytes
20 * In this sequence is a A8 0F or A0 0F or AA 0F followed by a little-indian encoding of text buffer size
21 * A8 0F denotes for ASCII text (local system monobyte encoding)
22 * A0 0F denotes for UTF-16 encoding
23 * AA 0F are non textual sequences
24 * texts are either in ASCII or UTF-16
25 * text ends on a new sequence start, or on a 00 00 NULL UTF-16 end of stream
27 * based on these following rules, here is a little empiric texte extractor for PPT
31 * @param object $resource
34 function get_text_for_indexing_ppt(&$resource){
39 // SECURITY : do not allow non admin execute anything on system !!
40 if (!isadmin($USER->id
)) return;
42 $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"));
46 while (preg_match('/\x00\x9F\x0F\x04.{9}(......)(.*)/s', $remains, $matches)){
47 $unpacked = unpack("ncode/Llength", $matches[1]);
48 $sequencecode = $unpacked['code'];
49 $length = $unpacked['length'];
50 // print "length : ".$length." ; segment type : ".sprintf("%x", $sequencecode)."<br/>";
51 $followup = $matches[2];
52 // local system encoding sequence
53 if ($sequencecode == 0xA80F){
54 $aFragment = substr($followup, 0, $length);
55 $remains = substr($followup, $length);
56 $fragments[] = $aFragment;
58 // denotes unicode encoded sequence
59 elseif ($sequencecode == 0xA00F){
60 $aFragment = substr($followup, 0, $length);
61 // $aFragment = mb_convert_encoding($aFragment, 'UTF-16', 'UTF-8');
62 $aFragment = preg_replace('/\xA0\x00\x19\x20/s', "'", $aFragment); // some quotes
63 $aFragment = preg_replace('/\x00/s', "", $aFragment);
64 $remains = substr($followup, $length);
65 $fragments[] = $aFragment;
71 $indextext = implode(' ', $fragments);
72 $indextext = preg_replace('/\x19\x20/', "'", $indextext); // some quotes
73 $indextext = preg_replace('/\x09/', '', $indextext); // some extra chars
74 $indextext = preg_replace('/\x0D/', "\n", $indextext); // some quotes
75 $indextext = preg_replace('/\x0A/', "\n", $indextext); // some quotes
76 $indextextprint = implode('<hr/>', $fragments);
79 // $logppt = fopen("C:/php5/logs/pptlog", "w");
80 // fwrite($logppt, $indextext);
83 if (!empty($CFG->block_search_limit_index_body
)){
84 $indextext = shorten($text, $CFG->block_search_limit_index_body
);
87 $indextext = mb_convert_encoding($indextext, 'UTF8', 'auto');