]> git.mjollnir.org Git - moodle.git/commitdiff
fixing several error messages
authordiml <diml>
Sun, 6 Apr 2008 21:01:28 +0000 (21:01 +0000)
committerdiml <diml>
Sun, 6 Apr 2008 21:01:28 +0000 (21:01 +0000)
enhancing security of command injections.
allowing space in pathes for files.
allowing binding with tools out of moodleroot

blocks/search/config_global.html
search/documents/chat_document.php
search/documents/physical_doc.php
search/documents/physical_htm.php
search/documents/physical_pdf.php
search/documents/resource_document.php
search/documents/techproject_document.php
search/documents/wiki_document.php

index d60de30daaf85d21afc8eba4d255cfae5716a294..be8041c74c270c53215add86fc95d1ac046ec126 100644 (file)
             } ?>"/><br/><br/>
         </td>
     </tr>
+    <tr>
+        <td valign="top" align="right">
+            <b><?php print_string('usemoodleroot', 'block_search') ?>:</b>
+        </td>
+        <td valign="top" align="left">
+        <?php 
+            $usemoodleroot = (isset($CFG->block_search_usemoodleroot)) ? 'checked="checked"' : '' ; 
+            $notusemoodleroot = (!isset($CFG->block_search_usemoodleroot)) ? 'checked="checked"' : '' ; 
+        ?>
+          <input id="block_search_usemoodleroot" type="radio" name="block_search_usemoodleroot" <?php echo $usemoodleroot ?> value="1"/> <?php print_string('yes') ?> - 
+          <input id="block_search_usemoodleroot" type="radio" name="block_search_usemoodleroot" <?php echo $notusemoodleroot ?> value="0"/> <?php print_string('no') ?> 
+          <br/><br/>
+        </td>
+    </tr>
     <tr>
         <td valign="top" align="right">
             <b><?php print_string('configpdftotextcmd', 'block_search') ?>:</b>
index ff624916df13a13618cf28eb50c962d08a13c745..4361d32d73c11b56359fe00716bcaba65eba4322 100644 (file)
@@ -76,7 +76,9 @@ function chat_make_link($cm_id, $start, $end) {
 * fetches all the records for a given session and assemble them as a unique track
 * we revamped here the code of report.php for making sessions, but without any output.
 * note that we should collect sessions "by groups" if groupmode() is SEPARATEGROUPS.
-* @param chat_id the database
+* @param int $chat_id the database
+* @param int $fromtime
+* @param int $totime
 * @uses CFG
 * @return an array of objects representing the chat sessions.
 */
@@ -100,8 +102,7 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
             foreach($messages as $aMessage){
                 $groupedMessages[$aMessage->groupid][] = $aMessage;
             }
-        }
-        else{
+        } else {
             $groupedMessages[-1] = &$messages;
         }
         $sessiongap = 5 * 60;    // 5 minutes silence means a new session
@@ -128,9 +129,8 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
                         $tracks[count($tracks) - 1]->content .= ' '.$message->message;
                         $tracks[count($tracks) - 1]->sessionstart = $message->timestamp;
                     }
-                } 
+                } else {
                 // we initiate a new session track (backwards)
-                else {
                     $track = new Object();
                     $track->sessionend = $message->timestamp;
                     $track->sessionstart = $message->timestamp;
@@ -175,7 +175,7 @@ function chat_get_content_for_index(&$chat) {
             foreach($sessionTracks as $aTrackId => $aTrack) {
                 foreach($aTrack->sessionusers as $aUserId){
                     $user = get_record('user', 'id', $aUserId);
-                    $aTrack->authors = ($user) ? $user->firstname.' '.$user->lastname : '' ;
+                    $aTrack->authors = ($user) ? fullname($user) : '' ;
                     $documents[] = new ChatTrackSearchDocument(get_object_vars($aTrack), $cm->id, $chat->course, $aTrack->groupid, $context->id);
                 }
             }
@@ -208,8 +208,8 @@ function chat_single_document($id, $itemtype) {
         if ($tracks){
             $aTrack = $tracks[0];
             $document = new ChatTrackSearchDocument(get_object_vars($aTrack), $cm->id, $chat->course, $aTrack->groupid, $context->id);
+            return $document;
         }
-        return $document;
     }
     return null;
 }
index 28356721edc987f9c1095a763bf26d86be4ba3b5..3b5f1c07ec9c3f47124fd9157ea7d0e524d8c676 100644 (file)
@@ -23,26 +23,28 @@ function get_text_for_indexing_doc(&$resource){
     
     // SECURITY : do not allow non admin execute anything on system !!
     if (!isadmin($USER->id)) return;
-    
+
     $moodleroot = (@$CFG->block_search_usemoodleroot) ? "{$CFG->dirroot}/" : '' ;
 
     // just call pdftotext over stdout and capture the output
     if (!empty($CFG->block_search_word_to_text_cmd)){
         if (!file_exists("{$moodleroot}{$CFG->block_search_word_to_text_cmd}")){
-            mtrace('Error with MSWord to text converter command : executable not found.');
+            mtrace('Error with MSWord to text converter command : exectuable not found.');
         }
         else{
             $file = escapeshellarg($CFG->dataroot.'/'.$resource->course.'/'.$resource->reference);
-            $text_converter_cmd = "\"{$moodleroot}{$CFG->block_search_word_to_text_cmd}\" \"$file\"";
+            $command = trim($CFG->block_search_word_to_text_cmd);
+            $text_converter_cmd = "{$moodleroot}{$command} \"$file\"";
             if ($CFG->block_search_word_to_text_env){
                 putenv($CFG->block_search_word_to_text_env);
             }
+            mtrace("Executing : $text_converter_cmd");
             $result = shell_exec($text_converter_cmd);
             if ($result){
                 return mb_convert_encoding($result, 'UTF8', 'auto');
             }
             else{
-                mtrace('Error with MSWord to text converter command : execution failed.');
+                mtrace('Error with MSWord to text converter command : execution failed. ');
                 return '';
             }
         }
index 5df8524a4f5e1a3b179e9c03679319279df62e64..b336443ea9870b6670177c36b4e664f8a4202cb5 100644 (file)
@@ -39,6 +39,7 @@ function get_text_for_indexing_htm(&$resource){
     // filter all html tags
     // $text = clean_text($text, FORMAT_PLAIN);
     // NOTE : this is done in ResourceSearchDocument __constructor
+    $text = preg_replace("/<!--[^>]*?-->/", '', $text);
     
     if (!empty($CFG->block_search_limit_index_body)){
         $text = shorten($text, $CFG->block_search_limit_index_body);
index fb48cc2eccde582ba9efc2790bf0b8ca0f106f29..8ea7abfd1a6263428df04a4dae93c459842a49a3 100644 (file)
@@ -28,12 +28,13 @@ function get_text_for_indexing_pdf(&$resource){
     // just call pdftotext over stdout and capture the output
     if (!empty($CFG->block_search_pdf_to_text_cmd)){
         preg_match("/^\S+/", $CFG->block_search_pdf_to_text_cmd, $matches);
-        if (!file_exists("{$moodleroot}{$matches[0]}")){
+        if (!file_exists("{$moodleroot}/{$matches[0]}")){
             mtrace('Error with pdf to text converter command : exectuable not found.');
         }
         else{
             $file = escapeshellarg($CFG->dataroot.'/'.$resource->course.'/'.$resource->reference);
-            $text_converter_cmd = "\"{$moodleroot}{$CFG->block_search_pdf_to_text_cmd}\" \"$file\" -";
+            $command = trim($CFG->block_search_pdf_to_text_cmd);
+            $text_converter_cmd = "{$moodleroot}/{$command} \"$file\" -";
             $result = shell_exec($text_converter_cmd);
             if ($result){
                 return $result;
index 918bb10c8bd07a27406c29e50f17af29cea353a2..0258aa6b07ddf7b58ce6464ca7c0f7a7a205c5ee 100644 (file)
@@ -75,6 +75,7 @@ function resource_iterator() {
 * this function does not need a content iterator, returns all the info
 * itself;
 * @param notneeded to comply API, remember to fake the iterator array though
+* @uses CFG
 * @return an array of searchable documents
 */
 function resource_get_content_for_index(&$notneeded) {
@@ -162,7 +163,10 @@ function resource_get_physical_file(&$resource, $context_id, $getsingle, &$docum
     global $CFG;
     
     // cannot index empty references
-    if (empty($resource->reference)) return false;
+    if (empty($resource->reference)){
+        mtrace("Cannot index, empty reference.");
+        return false;
+    }
 
     // cannot index remote resources
     if (resource_is_url($resource->reference)){
@@ -173,6 +177,7 @@ function resource_get_physical_file(&$resource, $context_id, $getsingle, &$docum
     $fileparts = pathinfo($resource->reference);
     // cannot index unknown or masked types
     if (empty($fileparts['extension'])) {
+        mtrace("Cannot index without explicit extension.");
         return false;
     }
     
@@ -196,15 +201,15 @@ function resource_get_physical_file(&$resource, $context_id, $getsingle, &$docum
         $resource->alltext = $function_name($resource);
         if (!empty($resource->alltext)){
             if ($getsingle){
-                return new ResourceSearchDocument(get_object_vars($resource), $context_id);
-            }
-            else{
+                $single = new ResourceSearchDocument(get_object_vars($resource), $context_id);
+                mtrace("finished file $resource->name as {$resource->reference}");
+                return $single;
+            } else {
                 $documents[] = new ResourceSearchDocument(get_object_vars($resource), $context_id);
             }
             mtrace("finished file $resource->name as {$resource->reference}");
         }
-    }
-    else{
+    } else {
         mtrace("fulltext handler not found for $ext type");
     }
     return false;
@@ -257,8 +262,7 @@ function resource_single_document($id, $itemtype) {
             $document = resource_get_physical_file($resource, true, $context->id);
             if (!$document) mtrace("Warning : this document {$resource->name} will not be indexed");
             return $document;
-        }
-        else{
+        } else {
             return new ResourceSearchDocument(get_object_vars($resource), $context->id);
         }
     }
index 6b36ddcf929121eb8ceea42991293f7fe2bac057..52976d1928307db2f7f37b167444f4b5244b8ce4 100644 (file)
@@ -91,6 +91,7 @@ function techproject_get_content_for_index(&$techproject) {
         foreach($entries as $anEntry) {
             if ($anEntry) {
                 if (strlen($anEntry->description) > 0) {
+                    $anEntry->author = '';
                     $documents[] = new TechprojectEntrySearchDocument(get_object_vars($anEntry), $techproject->course, $context->id);
                 } 
             } 
@@ -120,18 +121,22 @@ function techproject_single_document($id, $itemtype) {
     switch ($itemtype){
         case 'requirement':{
             $entry = get_record('techproject_requirement', 'id', $id);
+            $entry->author = '';
             break;
         }
         case 'specification':{
             $entry = get_record('techproject_specification', 'id', $id);
+            $entry->author = '';
             break;
         }
         case 'milestone':{
             $entry = get_record('techproject_milestone', 'id', $id);
+            $entry->author = '';
             break;
         }
         case 'deliverable':{
             $entry = get_record('techproject_deliverable', 'id', $id);
+            $entry->author = '';
             break;
         }
         case 'task':{
index 23a53168374105f041093a1c90310646e662e572..23ed2f8a366198539f8dd7feca70ce5f4310c828 100644 (file)
@@ -39,7 +39,7 @@ class WikiSearchDocument extends SearchDocument {
         $doc->contextid     = $context_id;
 
         $doc->title     = $page['pagename'];
-        $doc->date      = $page['timemodified'];
+        $doc->date      = $page['lastmodified'];
         //remove '(ip.ip.ip.ip)' from wiki author field
         $doc->author    = preg_replace('/\(.*?\)/', '', $page['author']);
         $doc->contents  = $page['content'];
@@ -138,7 +138,7 @@ function wiki_get_latest_pages(&$entry) {
     if ($ids = get_records('wiki_pages', 'wiki', $entry->id, '', 'distinct pagename')) {
         if ($pagesets = get_records('wiki_pages', 'wiki', $entry->id, '', 'distinct pagename')) {
             foreach ($pagesets as $aPageset) {
-                $pages[] = wiki_get_latest_page($entry, $aPageset->id);
+                $pages[] = wiki_get_latest_page($entry, $aPageset->pagename);
             } 
         } else {
             return false;