mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 19:20:12 +01:00
highlight searched terms in the message view pane
This commit is contained in:
parent
fbf5bc8b2c
commit
9431f19fd9
@ -21,15 +21,16 @@ class ControllerMessageView extends Controller {
|
||||
$this->document->title = $this->data['text_message'];
|
||||
|
||||
$this->data['id'] = '';
|
||||
$this->data['search'] = '';
|
||||
$this->data['rcpt'] = array();
|
||||
|
||||
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') {
|
||||
$this->data['id'] = $this->request->post['id'];
|
||||
$this->data['search'] = $this->request->post['search'];
|
||||
}
|
||||
|
||||
|
||||
if(!verify_piler_id($this->data['id'])) {
|
||||
AUDIT(ACTION_UNKNOWN, '', '', $this->data['id'], 'unknown 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']);
|
||||
header("Location: " . $_SERVER['HTTP_REFERER']);
|
||||
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['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']['note'] = $this->model_search_message->get_message_note($this->data['id'], $_SESSION['uid']);
|
||||
|
||||
|
@ -229,7 +229,7 @@ class ModelSearchMessage extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function extract_message($id = '') {
|
||||
public function extract_message($id = '', $terms = '') {
|
||||
$header = "";
|
||||
$body_chunk = "";
|
||||
$is_header = 1;
|
||||
@ -363,13 +363,26 @@ class ModelSearchMessage extends Model {
|
||||
|
||||
return array('from' => $this->decode_my_str($from),
|
||||
'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),
|
||||
'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) {
|
||||
|
||||
for($i=0; $i<count($boundary); $i++){
|
||||
|
@ -246,9 +246,14 @@ var Piler =
|
||||
|
||||
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) {
|
||||
|
||||
if(a.indexOf('<?php print PILER_LOGIN_HELPER_PLACEHOLDER; ?>') > 0) {
|
||||
|
@ -154,6 +154,7 @@
|
||||
.splitter-h { cursor: n-resize; cursor: row-resize; background-position: center 2px; }
|
||||
.splitter-v { cursor: e-resize; cursor: col-resize; background-position: 2px center; }
|
||||
|
||||
.message_highlight { background: lightblue; }
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user