]> git.mjollnir.org Git - moodle.git/commitdiff
Big improvements on message searching. It now highlights the results, and
authormoodler <moodler>
Mon, 3 Jan 2005 12:16:06 +0000 (12:16 +0000)
committermoodler <moodler>
Mon, 3 Jan 2005 12:16:06 +0000 (12:16 +0000)
shows you the fragment containing the results (not just a shortened version)

lang/en/message.php
lang/en/moodle.php
message/history.php
message/lib.php
message/search.html
theme/standardxhtml/styles.php

index 3e612bed028170c13b7f2b6a55da4d8e9187805a..c8bb495d85fb1913e2185f2cc53461901dbf3712 100644 (file)
@@ -8,6 +8,7 @@ $string['allusers'] = 'All messages from all users';
 $string['beepnewmessage'] = 'Beep when a new message comes in';
 $string['blockcontact'] = 'Block contact';
 $string['blockedmessages'] = '$a message(s) to/from blocked users';
+$string['context'] = 'context';
 $string['deletemessagesdays'] = 'Number of days before old messages are automatically deleted';
 $string['discussion'] = 'Discussion';
 $string['emailmessages'] = 'Email messages when I am offline';
index 939f2adfca924361ad676e5fc0f66afaef615c15..d2397e6b22338a7828882b29efba1dc3e0860708 100644 (file)
@@ -680,6 +680,7 @@ $string['maximumupload'] = 'Maximum upload size';
 $string['maxsize'] = 'Max size: $a';
 $string['min'] = 'min';
 $string['mins'] = 'mins';
+$string['minutes'] = 'minutes';
 $string['miscellaneous'] = 'Miscellaneous';
 $string['missingcategory'] = 'You need to choose a category';
 $string['missingcity'] = 'Missing city/town';
index 3586a967b97c4d9f814f740d6c65a9cf73c3f5ef..f49e6b7e3da139c1b088654f9ddc993fefc65c49 100644 (file)
@@ -21,6 +21,7 @@
         $userid2 = $USER->id;    // Can only see messages involving yourself
         $user2 = $USER; 
     }
+    $search = optional_param('search', '', PARAM_CLEAN);
 
 /// Our two users are defined - let's set up the page
 
@@ -66,9 +67,9 @@
                 print_heading(userdate($message->timecreated, $blockdate), 'center', 4);
             }
             if ($message->useridfrom == $user1->id) {
-                echo message_format_message($message, $user1, $messagedate);
+                echo message_format_message($message, $user1, $messagedate, $search);
             } else {
-                echo message_format_message($message, $user2, $messagedate);
+                echo message_format_message($message, $user2, $messagedate, $search);
             }
         }
     } else {
index d22aab65c73d90cf46a60dc79d249e8afb09afa2..31d5b4bce69faab093f0013ec74dc9111fcf2b6f 100644 (file)
@@ -370,7 +370,8 @@ function message_print_search_results($frm) {
         
     /// search messages for keywords
     } else if (!empty($frm->keywordssubmit) and !empty($frm->keywords)) {
-        $keywords = explode(' ', $frm->keywords);
+        $keywordstring = clean_text(trim($frm->keywords));
+        $keywords = explode(' ', $keywordstring);
         $tome     = false;
         $fromme   = false;
         $courseid = 'none';
@@ -405,7 +406,7 @@ function message_print_search_results($frm) {
             }
 
         /// print heading with number of results
-            echo '<strong>'.get_string('keywordssearchresults', 'message', count($messages)).'</strong>';
+            echo '<p class="message_heading">'.get_string('keywordssearchresults', 'message', count($messages)).' ("'.s($keywordstring).'")</p>';
 
         /// print table headings
             echo '<table class="message_search_results">';
@@ -418,7 +419,7 @@ function message_print_search_results($frm) {
 
             $blockedcount = 0;
             $dateformat = get_string('strftimedatetime');
-            $strmore = get_string('more');
+            $strcontext = get_string('context', 'message');
             foreach ($messages as $message) {
 
             /// ignore messages to and from blocked users unless $frm->includeblocked is set
@@ -469,9 +470,8 @@ function message_print_search_results($frm) {
                 echo '<td class="message_contact">';
                 message_print_user($userto, $tocontact, $toblocked);
                 echo '</td>';
-                echo '<td class="message_summary">'.message_shorten_message($message->message, 20);
-                echo ' ...('.message_history_link($message->useridto, $message->useridfrom, true, $datestring, 
-                     $strmore.'&nbsp;<img src="'.$CFG->pixpath.'/t/log.gif" height="11" width="11" border="0">').')';
+                echo '<td class="message_summary">'.message_get_fragment($message->message, $keywords);
+                echo '<br /><div class="message_summary_link">'.message_history_link($message->useridto, $message->useridfrom, true, $keywordstring, $datestring, $strcontext).'</div>';
                 echo '</td>';
                 echo '<td class="message_date">'.userdate($message->timecreated, $dateformat).'</td>';
                 echo "</tr>\n";
@@ -574,7 +574,7 @@ function message_contact_link($userid, $linktype='add', $return=false) {
     }
 }
 
-function message_history_link ($userid1, $userid2=0, $returnstr=false, $position='', $linktext='') {
+function message_history_link($userid1, $userid2=0, $returnstr=false, $keywords='', $position='', $linktext='') {
     global $USER, $CFG;
 
     if (!$userid2) {
@@ -583,6 +583,9 @@ function message_history_link ($userid1, $userid2=0, $returnstr=false, $position
     if ($position) {
         $position = "#$position";
     }
+    if ($keywords) {
+        $keywords = "&search=".urlencode($keywords);
+    }
 
     if ($linktext == 'icon') {
         $linktext = '<img src="'.$CFG->pixpath.'/t/log.gif" height="11" width="11" border="0">';
@@ -590,7 +593,7 @@ function message_history_link ($userid1, $userid2=0, $returnstr=false, $position
         $linktext = get_string('messagehistory', 'message');
     }
 
-    $str = link_to_popup_window("/message/history.php?user1=$userid1&user2=$userid2$position", 
+    $str = link_to_popup_window("/message/history.php?user1=$userid1&user2=$userid2$keywords$position", 
                     "message_history_$user->id", $linktext, 500, 500, '', 
                     'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500', true);
 
@@ -834,6 +837,55 @@ function message_shorten_message($message, $minlength=0) {
     return substr($message, 0, $truncate);
 }
 
+
+/*
+ * Given a string and an array of keywords, this function looks
+ * for the first keyword in the string, and then chops out a
+ * small section from the text that shows that word in context.
+ */
+function message_get_fragment($message, $keywords) {
+
+    $fullsize = 120;
+    $halfsize = (int)($fullsize/2);
+
+    $message = strip_tags($message);
+
+    foreach ($keywords as $keyword) {  // Just get the first one
+        if ($keyword !== '') {
+            break;
+        }
+    }
+    if (empty($keyword)) {   // None found, so just return start of message
+        return message_shorten_message($message, 30);
+    }
+
+    $leadin = $leadout = '';
+
+/// Find the start of the fragment
+    $start = 0;
+    $length = strlen($message);
+
+    $pos = strpos($message, $keyword);
+    if ($pos > $halfsize) {
+        $start = $pos - $halfsize;
+        $leadin = '...';
+    }
+/// Find the end of the fragment
+    $end = $start + $fullsize;
+    if ($end > $length) {
+        $end = $length;
+    } else {
+        $leadout = '...';
+    }
+
+/// Pull out the fragment and format it
+
+    $fragment = substr($message, $start, $end - $start);
+    $fragment = $leadin.highlight(implode(' ',$keywords), $fragment).$leadout;
+    return $fragment;
+}
+
+
 function message_get_history($user1, $user2) {
     $messages = get_records_select('message_read', "(useridto = '$user1->id' AND useridfrom = '$user2->id') OR 
                                                     (useridto = '$user2->id' AND useridfrom = '$user1->id')", 
@@ -848,13 +900,17 @@ function message_get_history($user1, $user2) {
     return $messages;
 }
 
-function message_format_message(&$message, &$user, $format='') {
+function message_format_message(&$message, &$user, $format='', $keywords='') {
     if (empty($format)) {
         $format = get_string('strftimedaytime');
     }
     $time = userdate($message->timecreated, $format);
+    $messagetext = format_text($message->message, $message->format);
+    if ($keywords) {
+        $messagetext = highlight($keywords, $messagetext);
+    }
     return '<p><font size="-1"><strong>'.s($user->firstname).'</strong> ['.$time.']: '.
-            format_text($message->message, $message->format).'</font></p>';
+            $messagetext.'</font></p>';
 }
 
 /*
index bb159e0691ff1a7fdf1022d7e32efd9326470c61..afbea697d10a4933b865ff2b5f1645ab2bccaa8f 100644 (file)
@@ -41,7 +41,7 @@
     
     <tr><td>&nbsp;</td><td colspan="2"><input type="radio" name="keywordsoption" alt="<?php print_string('onlytome', 'message') ?>" value="tome" checked="checked" /><?php print_string('onlytome', 'message') ?></td></tr>
     <tr><td>&nbsp;</td><td colspan="2"><input type="radio" name="keywordsoption" alt="<?php print_string('onlyfromme', 'message') ?>" value="fromme" /><?php print_string('onlyfromme', 'message') ?></td></tr>
-    <tr><td>&nbsp;</td><td colspan="2"><input type="radio" name="keywordsoption" alt="<?php print_string('allmine', 'message') ?>" value="allmine" /><?php print_string('allmine', 'message') ?></td></tr>
+    <tr><td>&nbsp;</td><td colspan="2"><input type="radio" checked="checked" name="keywordsoption" alt="<?php print_string('allmine', 'message') ?>" value="allmine" /><?php print_string('allmine', 'message') ?></td></tr>
     
     <?php if (isadmin()) { ?>
     <tr><td>&nbsp;</td><td colspan="2"><input type="radio" name="keywordsoption" alt="<?php print_string('allusers', 'message') ?>" value="allusers" /><?php print_string('allusers', 'message') ?></td></tr>
index 5a8378e018bd5d1a8496f5cd2df44ed63a8394c2..f64a8cc54f19206d8a3d97afe28f4e33ed573c0f 100644 (file)
@@ -817,6 +817,10 @@ TABLE.formtable TD {
 .message_summary {
        font-size: small;
 }
+.message_summary_link {
+       font-size: small;
+    text-align: right;
+}
 .message_date {
        font-size: small;
 }