highlight searched terms in the message view pane

This commit is contained in:
SJ 2013-06-29 17:59:57 +02:00
parent fbf5bc8b2c
commit 9431f19fd9
4 changed files with 28 additions and 8 deletions

View File

@ -21,15 +21,16 @@ class ControllerMessageView extends Controller {
$this->document->title = $this->data['text_message']; $this->document->title = $this->data['text_message'];
$this->data['id'] = ''; $this->data['id'] = '';
$this->data['search'] = '';
$this->data['rcpt'] = array(); $this->data['rcpt'] = array();
if(isset($_SERVER['REQUEST_URI'])) { $a = preg_split("/\//", $_SERVER['REQUEST_URI']); $this->data['id'] = $a[count($a)-1]; } if(isset($_SERVER['REQUEST_URI'])) { $a = preg_split("/\//", $_SERVER['REQUEST_URI']); $this->data['id'] = $a[count($a)-1]; }
if($this->request->server['REQUEST_METHOD'] == 'POST') { if($this->request->server['REQUEST_METHOD'] == 'POST') {
$this->data['id'] = $this->request->post['id']; $this->data['id'] = $this->request->post['id'];
$this->data['search'] = $this->request->post['search'];
} }
if(!verify_piler_id($this->data['id'])) { if(!verify_piler_id($this->data['id'])) {
AUDIT(ACTION_UNKNOWN, '', '', $this->data['id'], 'unknown id: ' . $this->data['id']); AUDIT(ACTION_UNKNOWN, '', '', $this->data['id'], 'unknown id: ' . $this->data['id']);
die("invalid id: " . $this->data['id']); die("invalid id: " . $this->data['id']);
@ -54,7 +55,7 @@ class ControllerMessageView extends Controller {
} }
if($this->request->server['REQUEST_METHOD'] == 'POST') { if($this->request->server['REQUEST_METHOD'] == 'POST' && isset($this->request->post['tag'])) {
$this->model_search_message->add_message_tag($this->data['id'], $_SESSION['uid'], $this->request->post['tag']); $this->model_search_message->add_message_tag($this->data['id'], $_SESSION['uid'], $this->request->post['tag']);
header("Location: " . $_SERVER['HTTP_REFERER']); header("Location: " . $_SERVER['HTTP_REFERER']);
exit; exit;
@ -64,7 +65,7 @@ class ControllerMessageView extends Controller {
$this->data['attachments'] = $this->model_search_message->get_attachment_list($this->data['piler_id']); $this->data['attachments'] = $this->model_search_message->get_attachment_list($this->data['piler_id']);
$this->data['message'] = $this->model_search_message->extract_message($this->data['piler_id']); $this->data['message'] = $this->model_search_message->extract_message($this->data['piler_id'], $this->data['search']);
$this->data['message']['tag'] = $this->model_search_message->get_message_tag($this->data['id'], $_SESSION['uid']); $this->data['message']['tag'] = $this->model_search_message->get_message_tag($this->data['id'], $_SESSION['uid']);
$this->data['message']['note'] = $this->model_search_message->get_message_note($this->data['id'], $_SESSION['uid']); $this->data['message']['note'] = $this->model_search_message->get_message_note($this->data['id'], $_SESSION['uid']);

View File

@ -229,7 +229,7 @@ class ModelSearchMessage extends Model {
} }
public function extract_message($id = '') { public function extract_message($id = '', $terms = '') {
$header = ""; $header = "";
$body_chunk = ""; $body_chunk = "";
$is_header = 1; $is_header = 1;
@ -363,13 +363,26 @@ class ModelSearchMessage extends Model {
return array('from' => $this->decode_my_str($from), return array('from' => $this->decode_my_str($from),
'to' => $this->decode_my_str($to), 'to' => $this->decode_my_str($to),
'subject' => $this->decode_my_str($subject), 'subject' => $this->highlight_search_terms($this->decode_my_str($subject), $terms),
'date' => $this->decode_my_str($date), 'date' => $this->decode_my_str($date),
'message' => $message 'message' => $this->highlight_search_terms($message, $terms)
); );
} }
private function highlight_search_terms($s = '', $terms = array()) {
$terms = explode(" ", $terms);
if(count($terms) <= 0) { return $s; }
while(list($k, $v) = each($terms)) {
$s = preg_replace("/$v/i", "<span class=\"message_highlight\">$v</span>", $s);
}
return $s;
}
private function check_boundary($boundary, $line) { private function check_boundary($boundary, $line) {
for($i=0; $i<count($boundary); $i++){ for($i=0; $i<count($boundary); $i++){

View File

@ -246,9 +246,14 @@ var Piler =
view_message:function(id) view_message:function(id)
{ {
Piler.log("[view_message]"); var search = $('#_search').val();
jQuery.ajax('/message.php/' + id, { cache: true }) Piler.log("[view_message]", id, search);
jQuery.ajax('/message.php', {
data: { id: id, search: search },
type: "POST"
})
.done( function(a) { .done( function(a) {
if(a.indexOf('<?php print PILER_LOGIN_HELPER_PLACEHOLDER; ?>') > 0) { if(a.indexOf('<?php print PILER_LOGIN_HELPER_PLACEHOLDER; ?>') > 0) {

View File

@ -154,6 +154,7 @@
.splitter-h { cursor: n-resize; cursor: row-resize; background-position: center 2px; } .splitter-h { cursor: n-resize; cursor: row-resize; background-position: center 2px; }
.splitter-v { cursor: e-resize; cursor: col-resize; background-position: 2px center; } .splitter-v { cursor: e-resize; cursor: col-resize; background-position: 2px center; }
.message_highlight { background: lightblue; }
} }