diff --git a/include/class.thread.php b/include/class.thread.php index 5c0ac5d972fea363ff3ccf2cc184fdab5ae89386..b98b33535071b7858af9941510f3f40ae10257c0 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -138,9 +138,12 @@ class Thread { .' ORDER BY thread.created '.$order; $entries = array(); - if(($res=db_query($sql)) && db_num_rows($res)) - while($rec=db_fetch_array($res)) + if(($res=db_query($sql)) && db_num_rows($res)) { + while($rec=db_fetch_array($res)) { + $rec['body'] = new ThreadBody($rec['body'], $rec['format']); $entries[] = $rec; + } + } return $entries; } @@ -969,9 +972,7 @@ Class ThreadEntry { $vars['body'] = new TextThreadBody($vars['body']); } - // Drop stripped images. NOTE: This should be done before - // ->convert() because the strippedImages list will not propagate to - // the newly converted thread body + // Drop stripped images if ($vars['attachments']) { foreach ($vars['body']->getStrippedImages() as $cid) { foreach ($vars['attachments'] as $i=>$a) { @@ -994,8 +995,7 @@ Class ThreadEntry { } } - if (!($body = Format::sanitize( - (string) $vars['body']->convertTo('html')))) + if (!($body = (string) $vars['body'])) $body = '-'; //Special tag used to signify empty message as stored. $poster = $vars['poster']; @@ -1006,6 +1006,7 @@ Class ThreadEntry { .' ,thread_type='.db_input($vars['type']) .' ,ticket_id='.db_input($vars['ticketId']) .' ,title='.db_input(Format::sanitize($vars['title'], true)) + .' ,format='.db_input($vars['body']->getType()) .' ,staff_id='.db_input($vars['staffId']) .' ,user_id='.db_input($vars['userId']) .' ,poster='.db_input($poster) @@ -1260,6 +1261,22 @@ class ThreadBody /* extends SplString */ { $this->type = $type; } + function isEmpty() { + return !$this->body || $this->body == '-'; + } + + function display() { + if ($this->isEmpty()) + return '(empty)'; + + switch (strtolower($this->type)) { + case 'text': + return '<div style="white-space:pre-wrap">'.$this->body.'</div>'; + case 'html': + return Format::display($this->body); + } + } + function convertTo($type) { if ($type === $this->type) return $this; @@ -1307,6 +1324,10 @@ class ThreadBody /* extends SplString */ { return $this->embedded_images; } + function getType() { + return $this->type; + } + function __toString() { return $this->body; } @@ -1336,5 +1357,9 @@ class HtmlThreadBody extends ThreadBody { return 'src="cid:'.$info['cid'].'"'; }, $body); } + + function __toString() { + return Format::sanitize($this->body); + } } ?> diff --git a/include/client/view.inc.php b/include/client/view.inc.php index f26737719309736c0863e03877e7a9a1c302e60a..8f61eea8e443fb061d8b706bc565e63bb67915ce 100644 --- a/include/client/view.inc.php +++ b/include/client/view.inc.php @@ -101,8 +101,6 @@ foreach (DynamicFormEntry::forTicket($ticket->getId()) as $idx=>$form) { if($ticket->getThreadCount() && ($thread=$ticket->getClientThread())) { $threadType=array('M' => 'message', 'R' => 'response'); foreach($thread as $entry) { - if ($entry['body'] == '-') - $entry['body'] = '(EMPTY)'; //Making sure internal notes are not displayed due to backend MISTAKES! if(!$threadType[$entry['thread_type']]) continue; @@ -112,7 +110,7 @@ if($ticket->getThreadCount() && ($thread=$ticket->getClientThread())) { ?> <table class="thread-entry <?php echo $threadType[$entry['thread_type']]; ?>" cellspacing="0" cellpadding="1" width="800" border="0"> <tr><th><?php echo Format::db_datetime($entry['created']); ?> <span class="textra"></span><span><?php echo $poster; ?></span></th></tr> - <tr><td class="thread-body"><div><?php echo Format::viewableImages(Format::display($entry['body'])); ?></div></td></tr> + <tr><td class="thread-body"><div><?php echo $entry['body']->display(); ?></div></td></tr> <?php if($entry['attachments'] && ($tentry=$ticket->getThreadEntry($entry['id'])) diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index 1f05d04a5daf6445e1683d083862ca32937510de..eee9fe1cc059f95e232a636e2e286501aa11df30 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -342,10 +342,7 @@ $tcount+= $ticket->getNumNotes(); /* -------- Messages & Responses & Notes (if inline)-------------*/ $types = array('M', 'R', 'N'); if(($thread=$ticket->getThreadEntries($types))) { - foreach($thread as $entry) { - if ($entry['body'] == '-') - $entry['body'] = '(EMPTY)'; - ?> + foreach($thread as $entry) { ?> <table class="thread-entry <?php echo $threadTypes[$entry['thread_type']]; ?>" cellspacing="0" cellpadding="1" width="940" border="0"> <tr> <th colspan="4" width="100%"> @@ -365,7 +362,7 @@ $tcount+= $ticket->getNumNotes(); </tr> <tr><td colspan="4" class="thread-body" id="thread-id-<?php echo $entry['id']; ?>"><div><?php - echo Format::viewableImages(Format::display($entry['body'])); ?></div></td></tr> + echo $entry['body']->display(); ?></div></td></tr> <?php if($entry['attachments'] && ($tentry = $ticket->getThreadEntry($entry['id']))