From 989d67a231cebdd11211e6db16d1290b9b7413b7 Mon Sep 17 00:00:00 2001
From: Mike Koch
Date: Mon, 12 Oct 2015 13:02:45 -0400
Subject: [PATCH 1/9] #365 Add html column to templates and canned responses
table
---
install/mods-for-hesk/sql/installSql.php | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/install/mods-for-hesk/sql/installSql.php b/install/mods-for-hesk/sql/installSql.php
index 8aa201a6..48bc8824 100644
--- a/install/mods-for-hesk/sql/installSql.php
+++ b/install/mods-for-hesk/sql/installSql.php
@@ -831,5 +831,16 @@ function execute250Scripts()
executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` (`Key`, `Value`) VALUES ('display_user_agent_information', '0')");
executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` (`Key`, `Value`) VALUES ('navbar_title_url', '" . hesk_dbEscape($hesk_settings['hesk_url']) . "'");
+ executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "std_replies` ADD COLUMN `html` MEDIUMTEXT");
+ executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` ADD COLUMN `html` MEDIUMTEXT");
+
+ $res = executeQuery("SELECT 1 FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` WHERE `Key` = 'rich_text_for_tickets' AND `Value` = 1");
+
+ // If HTML is enabled, copy the canned responses to the html column.
+ if (hesk_dbNumRows($res) > 0) {
+ executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "std_replies` SET `html` = `message`");
+ executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` SET `html` = `message`");
+ }
+
}
// END Version 2.5.0
\ No newline at end of file
From bd115aaccbf868b64aa09852b4e8697719db5830 Mon Sep 17 00:00:00 2001
From: Mike Koch
Date: Thu, 15 Oct 2015 21:56:25 -0400
Subject: [PATCH 2/9] #365 Finish install changes
---
install/mods-for-hesk/sql/installSql.php | 17 +++++++++++++----
install/mods-for-hesk/sql/uninstallSql.php | 2 ++
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/install/mods-for-hesk/sql/installSql.php b/install/mods-for-hesk/sql/installSql.php
index 48bc8824..a8c41f4f 100644
--- a/install/mods-for-hesk/sql/installSql.php
+++ b/install/mods-for-hesk/sql/installSql.php
@@ -836,11 +836,20 @@ function execute250Scripts()
$res = executeQuery("SELECT 1 FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` WHERE `Key` = 'rich_text_for_tickets' AND `Value` = 1");
- // If HTML is enabled, copy the canned responses to the html column.
+ // If HTML is enabled, copy the canned responses to the html column. Unescape them so they're ready to go for editing.
if (hesk_dbNumRows($res) > 0) {
- executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "std_replies` SET `html` = `message`");
- executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` SET `html` = `message`");
+ $canned_responses = executeQuery("SELECT `id`, `message` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "std_replies`");
+ while ($response = hesk_dbFetchAssoc($canned_responses)) {
+ $message = hesk_html_entity_decode($response['message']);
+ executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "std_replies` SET `html` = '" .
+ hesk_dbEscape($message) . "' WHERE `id` = ".intval($response['id']));
+ }
+ $ticket_templates = executeQuery("SELECT `id`, `message` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates`");
+ while ($template = hesk_dbFetchAssoc($ticket_templates)) {
+ $message = hesk_html_entity_decode($template['message']);
+ executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` SET `html` = '" .
+ hesk_dbEscape($message) . "' WHERE `id` = ".intval($template['id']));
+ }
}
-
}
// END Version 2.5.0
\ No newline at end of file
diff --git a/install/mods-for-hesk/sql/uninstallSql.php b/install/mods-for-hesk/sql/uninstallSql.php
index a330eeef..bc95edb9 100644
--- a/install/mods-for-hesk/sql/uninstallSql.php
+++ b/install/mods-for-hesk/sql/uninstallSql.php
@@ -81,6 +81,8 @@ function removeOtherColumns()
executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` DROP COLUMN `html`");
executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "stage_tickets` DROP COLUMN `html`");
executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "replies` DROP COLUMN `html`");
+ executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "std_replies` DROP COLUMN `html`");
+ executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` DROP COLUMN `html`");
// These queries are ran in case someone used an unfortunate installation they may have not properly cleaned up tables
From 8a432ec0bd835a71cde975ed30245246da721c8d Mon Sep 17 00:00:00 2001
From: Mike Koch
Date: Thu, 15 Oct 2015 22:31:24 -0400
Subject: [PATCH 3/9] #365 Get started on api
---
api/canned/index.php | 19 +++
api/core/database.inc.php | 247 ++++++++++++++++++++++++++++++
api/core/database_mysqli.inc.php | 253 +++++++++++++++++++++++++++++++
api/core/json_error.php | 11 ++
inc/common.inc.php | 13 ++
5 files changed, 543 insertions(+)
create mode 100644 api/canned/index.php
create mode 100755 api/core/database.inc.php
create mode 100755 api/core/database_mysqli.inc.php
create mode 100644 api/core/json_error.php
diff --git a/api/canned/index.php b/api/canned/index.php
new file mode 100644
index 00000000..c9c35024
--- /dev/null
+++ b/api/canned/index.php
@@ -0,0 +1,19 @@
+EXPLAIN $query
\n";
+
+ if ($res = @mysqli_query($hesk_db_link, $query))
+ {
+ return $res;
+ }
+ elseif ($hesk_settings['debug_mode'])
+ {
+ $message = $hesklang['mysql_said'] . ': ' . mysqli_error($hesk_db_link);
+ }
+ else
+ {
+ $message = $hesklang['contact_webmaster'] . $hesk_settings['webmaster_email'];
+ }
+ print_error($hesklang['cant_sql'], $message);
+ die(http_response_code(500));
+} // END hesk_dbQuery()
+
+
+function hesk_dbFetchAssoc($res)
+{
+
+ return @mysqli_fetch_assoc($res);
+
+} // END hesk_FetchAssoc()
+
+
+function hesk_dbFetchRow($res)
+{
+
+ return @mysqli_fetch_row($res);
+
+} // END hesk_FetchRow()
+
+
+function hesk_dbResult($res, $row = 0, $column = 0)
+{
+ $i=0;
+ $res->data_seek(0);
+
+ while ($tmp = @mysqli_fetch_array($res, MYSQLI_NUM))
+ {
+ if ($i==$row)
+ {
+ return $tmp[$column];
+ }
+ $i++;
+ }
+
+ return '';
+
+} // END hesk_dbResult()
+
+
+function hesk_dbInsertID()
+{
+ global $hesk_db_link;
+
+ if ($lastid = @mysqli_insert_id($hesk_db_link))
+ {
+ return $lastid;
+ }
+
+} // END hesk_dbInsertID()
+
+
+function hesk_dbFreeResult($res)
+{
+
+ return @mysqli_free_result($res);
+
+} // END hesk_dbFreeResult()
+
+
+function hesk_dbNumRows($res)
+{
+
+ return @mysqli_num_rows($res);
+
+} // END hesk_dbNumRows()
+
+
+function hesk_dbAffectedRows()
+{
+ global $hesk_db_link;
+
+ return @mysqli_affected_rows($hesk_db_link);
+
+} // END hesk_dbAffectedRows()
diff --git a/api/core/json_error.php b/api/core/json_error.php
new file mode 100644
index 00000000..61b491e6
--- /dev/null
+++ b/api/core/json_error.php
@@ -0,0 +1,11 @@
+ $older_than) && @unlink($file)) ? true : false;
From 2712f70ba1245ea7d5a785f159bbe43e9118f03a Mon Sep 17 00:00:00 2001
From: Mike Koch
Date: Fri, 16 Oct 2015 19:59:23 -0400
Subject: [PATCH 4/9] #365 Remove HTML column. It won't work
---
install/mods-for-hesk/sql/installSql.php | 20 --------------------
1 file changed, 20 deletions(-)
diff --git a/install/mods-for-hesk/sql/installSql.php b/install/mods-for-hesk/sql/installSql.php
index a8c41f4f..8aa201a6 100644
--- a/install/mods-for-hesk/sql/installSql.php
+++ b/install/mods-for-hesk/sql/installSql.php
@@ -831,25 +831,5 @@ function execute250Scripts()
executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` (`Key`, `Value`) VALUES ('display_user_agent_information', '0')");
executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` (`Key`, `Value`) VALUES ('navbar_title_url', '" . hesk_dbEscape($hesk_settings['hesk_url']) . "'");
- executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "std_replies` ADD COLUMN `html` MEDIUMTEXT");
- executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` ADD COLUMN `html` MEDIUMTEXT");
-
- $res = executeQuery("SELECT 1 FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` WHERE `Key` = 'rich_text_for_tickets' AND `Value` = 1");
-
- // If HTML is enabled, copy the canned responses to the html column. Unescape them so they're ready to go for editing.
- if (hesk_dbNumRows($res) > 0) {
- $canned_responses = executeQuery("SELECT `id`, `message` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "std_replies`");
- while ($response = hesk_dbFetchAssoc($canned_responses)) {
- $message = hesk_html_entity_decode($response['message']);
- executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "std_replies` SET `html` = '" .
- hesk_dbEscape($message) . "' WHERE `id` = ".intval($response['id']));
- }
- $ticket_templates = executeQuery("SELECT `id`, `message` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates`");
- while ($template = hesk_dbFetchAssoc($ticket_templates)) {
- $message = hesk_html_entity_decode($template['message']);
- executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "ticket_templates` SET `html` = '" .
- hesk_dbEscape($message) . "' WHERE `id` = ".intval($template['id']));
- }
- }
}
// END Version 2.5.0
\ No newline at end of file
From a559dc232ab63683768bdaccadbe927f2f287d47 Mon Sep 17 00:00:00 2001
From: Mike Koch
Date: Fri, 16 Oct 2015 22:01:56 -0400
Subject: [PATCH 5/9] #365 Add html2text dependency, initial implementation
---
inc/email_functions.inc.php | 9 +
inc/html2text/html2text.php | 32 +++
inc/html2text/src/Html2Text.php | 254 +++++++++++++++++++++++
inc/html2text/src/Html2TextException.php | 28 +++
4 files changed, 323 insertions(+)
create mode 100755 inc/html2text/html2text.php
create mode 100755 inc/html2text/src/Html2Text.php
create mode 100755 inc/html2text/src/Html2TextException.php
diff --git a/inc/email_functions.inc.php b/inc/email_functions.inc.php
index db4599c1..308e44a3 100644
--- a/inc/email_functions.inc.php
+++ b/inc/email_functions.inc.php
@@ -391,6 +391,15 @@ function hesk_mail($to, $subject, $message, $htmlMessage, $modsForHesk_settings,
$innerboundary .= '1';
}
$plaintextMessage = $message;
+ // If HTML is enabled, let's unescape everything, and call html2text. We'll assume either setting is ok.
+ if ($modsForHesk_settings['rich_text_for_tickets']
+ || $modsForHesk_settings['rich_text_for_tickets_for_customers']) {
+ if (!function_exists('convert_html_to_text')) {
+ require(HESK_PATH . 'inc/html2text/html2text.php');
+ }
+ $plaintextMessage = convert_html_to_text($plaintextMessage);
+ $plaintextMessage = fix_newlines($plaintextMessage);
+ }
$message = "--" . $outerboundary . "\n";
$message .= "Content-Type: multipart/alternative; boundary=\"" . $innerboundary . "\"\n\n";
diff --git a/inc/html2text/html2text.php b/inc/html2text/html2text.php
new file mode 100755
index 00000000..f3afbef6
--- /dev/null
+++ b/inc/html2text/html2text.php
@@ -0,0 +1,32 @@
+In particular, it tries to maintain the following features:
+ *
+ * - Links are maintained, with the 'href' copied over
+ *
- Information in the <head> is lost
+ *
+ *
+ * @param string html the input HTML
+ * @return string the HTML converted, as best as possible, to text
+ * @throws Html2TextException if the HTML could not be loaded as a {@link DOMDocument}
+ */
+ static function convert($html) {
+ // replace with spaces
+ $html = str_replace(" ", " ", $html);
+
+ $html = static::fixNewlines($html);
+
+ $doc = new \DOMDocument();
+ if (!$doc->loadHTML($html)) {
+ throw new Html2TextException("Could not load HTML - badly formed?", $html);
+ }
+
+ $output = static::iterateOverNode($doc);
+
+ // remove leading and trailing spaces on each line
+ $output = preg_replace("/[ \t]*\n[ \t]*/im", "\n", $output);
+
+ // remove leading and trailing whitespace
+ $output = trim($output);
+
+ return $output;
+ }
+
+ /**
+ * Unify newlines; in particular, \r\n becomes \n, and
+ * then \r becomes \n. This means that all newlines (Unix, Windows, Mac)
+ * all become \ns.
+ *
+ * @param string text text with any number of \r, \r\n and \n combinations
+ * @return string the fixed text
+ */
+ static function fixNewlines($text) {
+ // replace \r\n to \n
+ $text = str_replace("\r\n", "\n", $text);
+ // remove \rs
+ $text = str_replace("\r", "\n", $text);
+
+ return $text;
+ }
+
+ static function nextChildName($node) {
+ // get the next child
+ $nextNode = $node->nextSibling;
+ while ($nextNode != null) {
+ if ($nextNode instanceof \DOMElement) {
+ break;
+ }
+ $nextNode = $nextNode->nextSibling;
+ }
+ $nextName = null;
+ if ($nextNode instanceof \DOMElement && $nextNode != null) {
+ $nextName = strtolower($nextNode->nodeName);
+ }
+
+ return $nextName;
+ }
+
+ static function prevChildName($node) {
+ // get the previous child
+ $nextNode = $node->previousSibling;
+ while ($nextNode != null) {
+ if ($nextNode instanceof \DOMElement) {
+ break;
+ }
+ $nextNode = $nextNode->previousSibling;
+ }
+ $nextName = null;
+ if ($nextNode instanceof \DOMElement && $nextNode != null) {
+ $nextName = strtolower($nextNode->nodeName);
+ }
+
+ return $nextName;
+ }
+
+ static function iterateOverNode($node) {
+ if ($node instanceof \DOMText) {
+ // Replace whitespace characters with a space (equivilant to \s)
+ return preg_replace("/[\\t\\n\\f\\r ]+/im", " ", $node->wholeText);
+ }
+ if ($node instanceof \DOMDocumentType) {
+ // ignore
+ return "";
+ }
+
+ $nextName = static::nextChildName($node);
+ $prevName = static::prevChildName($node);
+
+ $name = strtolower($node->nodeName);
+
+ // start whitespace
+ switch ($name) {
+ case "hr":
+ return "------\n";
+
+ case "style":
+ case "head":
+ case "title":
+ case "meta":
+ case "script":
+ // ignore these tags
+ return "";
+
+ case "h1":
+ case "h2":
+ case "h3":
+ case "h4":
+ case "h5":
+ case "h6":
+ case "ol":
+ case "ul":
+ // add two newlines, second line is added below
+ $output = "\n";
+ break;
+
+ case "td":
+ case "th":
+ // add tab char to separate table fields
+ $output = "\t";
+ break;
+
+ case "tr":
+ case "p":
+ case "div":
+ // add one line
+ $output = "\n";
+ break;
+
+ case "li":
+ $output = "- ";
+ break;
+
+ default:
+ // print out contents of unknown tags
+ $output = "";
+ break;
+ }
+
+ // debug
+ //$output .= "[$name,$nextName]";
+
+ if (isset($node->childNodes)) {
+ for ($i = 0; $i < $node->childNodes->length; $i++) {
+ $n = $node->childNodes->item($i);
+
+ $text = static::iterateOverNode($n);
+
+ $output .= $text;
+ }
+ }
+
+ // end whitespace
+ switch ($name) {
+ case "style":
+ case "head":
+ case "title":
+ case "meta":
+ case "script":
+ // ignore these tags
+ return "";
+
+ case "h1":
+ case "h2":
+ case "h3":
+ case "h4":
+ case "h5":
+ case "h6":
+ $output .= "\n";
+ break;
+
+ case "p":
+ case "br":
+ // add one line
+ if ($nextName != "div")
+ $output .= "\n";
+ break;
+
+ case "div":
+ // add one line only if the next child isn't a div
+ if ($nextName != "div" && $nextName != null)
+ $output .= "\n";
+ break;
+
+ case "a":
+ // links are returned in [text](link) format
+ $href = $node->getAttribute("href");
+ if ($href == null) {
+ // it doesn't link anywhere
+ if ($node->getAttribute("name") != null) {
+ $output = "[$output]";
+ }
+ } else {
+ if ($href == $output || $href == "mailto:$output" || $href == "http://$output" || $href == "https://$output") {
+ // link to the same address: just use link
+ $output;
+ } else {
+ // replace it
+ $output = "[$output]($href)";
+ }
+ }
+
+ // does the next node require additional whitespace?
+ switch ($nextName) {
+ case "h1": case "h2": case "h3": case "h4": case "h5": case "h6":
+ $output .= "\n";
+ break;
+ }
+ break;
+
+ case "li":
+ $output .= "\n";
+ break;
+
+ default:
+ // do nothing
+ }
+
+ return $output;
+ }
+
+}
diff --git a/inc/html2text/src/Html2TextException.php b/inc/html2text/src/Html2TextException.php
new file mode 100755
index 00000000..ddfa8658
--- /dev/null
+++ b/inc/html2text/src/Html2TextException.php
@@ -0,0 +1,28 @@
+more_info = $more_info;
+ }
+}
From 03afe992841b1434d97fa43ee22d9e4c75f9e4ba Mon Sep 17 00:00:00 2001
From: Mike Koch
Date: Fri, 16 Oct 2015 22:49:09 -0400
Subject: [PATCH 6/9] #365 Convert HTML messages to plaintext using html2text
---
inc/email_functions.inc.php | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/inc/email_functions.inc.php b/inc/email_functions.inc.php
index 308e44a3..3349d529 100644
--- a/inc/email_functions.inc.php
+++ b/inc/email_functions.inc.php
@@ -391,15 +391,6 @@ function hesk_mail($to, $subject, $message, $htmlMessage, $modsForHesk_settings,
$innerboundary .= '1';
}
$plaintextMessage = $message;
- // If HTML is enabled, let's unescape everything, and call html2text. We'll assume either setting is ok.
- if ($modsForHesk_settings['rich_text_for_tickets']
- || $modsForHesk_settings['rich_text_for_tickets_for_customers']) {
- if (!function_exists('convert_html_to_text')) {
- require(HESK_PATH . 'inc/html2text/html2text.php');
- }
- $plaintextMessage = convert_html_to_text($plaintextMessage);
- $plaintextMessage = fix_newlines($plaintextMessage);
- }
$message = "--" . $outerboundary . "\n";
$message .= "Content-Type: multipart/alternative; boundary=\"" . $innerboundary . "\"\n\n";
@@ -675,11 +666,20 @@ function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message
$msg = str_replace('%%SITE_URL%%', $hesk_settings['site_url'], $msg);
if (isset($ticket['message'])) {
+ // If HTML is enabled, let's unescape everything, and call html2text.
if ($isForHtml) {
$htmlMessage = nl2br($ticket['message']);
$msg = str_replace('%%MESSAGE_NO_ATTACHMENTS%%', $htmlMessage, $msg);
return str_replace('%%MESSAGE%%', $htmlMessage, $msg);
}
+ if ($modsForHesk_settings['rich_text_for_tickets']
+ || $modsForHesk_settings['rich_text_for_tickets_for_customers']) {
+ if (!function_exists('convert_html_to_text')) {
+ require(HESK_PATH . 'inc/html2text/html2text.php');
+ }
+ $ticket['message'] = convert_html_to_text($ticket['message']);
+ $ticket['message'] = fix_newlines($ticket['message']);
+ }
$msg = str_replace('%%MESSAGE_NO_ATTACHMENTS%%', $ticket['message'], $msg);
return str_replace('%%MESSAGE%%', $ticket['message'], $msg);
} else {
@@ -750,6 +750,7 @@ function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message
}
}
+
// Is message tag in email template?
if (strpos($msg, '%%MESSAGE%%') !== false) {
// Replace message
@@ -757,7 +758,16 @@ function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message
$htmlMessage = nl2br($ticket['message']);
$msg = str_replace('%%MESSAGE%%', $htmlMessage, $msg);
} else {
- $msg = str_replace('%%MESSAGE%%', $ticket['message'], $msg);
+ $plainTextMessage = $ticket['message'];
+ if ($modsForHesk_settings['rich_text_for_tickets']
+ || $modsForHesk_settings['rich_text_for_tickets_for_customers']) {
+ if (!function_exists('convert_html_to_text')) {
+ require(HESK_PATH . 'inc/html2text/html2text.php');
+ }
+ $plainTextMessage = convert_html_to_text($plainTextMessage);
+ $plainTextMessage = fix_newlines($plainTextMessage);
+ }
+ $msg = str_replace('%%MESSAGE%%', $plainTextMessage, $msg);
}
// Add direct links to any attachments at the bottom of the email message OR add them as attachments, depending on the settings
From 56e37e1358213b282ce0c0f443bf2d3a30686746 Mon Sep 17 00:00:00 2001
From: Mike Koch
Date: Sat, 17 Oct 2015 20:50:16 -0400
Subject: [PATCH 7/9] #365 Use the ticket/replies HTML property for emails
Check the latest reply, or if there are no replies, the `html` property of the ticket. If html is 1, then convert html to plaintext, otherwise leave it alone.
---
inc/email_functions.inc.php | 19 +++++++++++++++----
inc/posting_functions.inc.php | 3 ++-
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/inc/email_functions.inc.php b/inc/email_functions.inc.php
index 3349d529..9a1581f0 100644
--- a/inc/email_functions.inc.php
+++ b/inc/email_functions.inc.php
@@ -672,8 +672,8 @@ function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message
$msg = str_replace('%%MESSAGE_NO_ATTACHMENTS%%', $htmlMessage, $msg);
return str_replace('%%MESSAGE%%', $htmlMessage, $msg);
}
- if ($modsForHesk_settings['rich_text_for_tickets']
- || $modsForHesk_settings['rich_text_for_tickets_for_customers']) {
+ $message_has_html = checkForHtml($ticket);
+ if ($message_has_html) {
if (!function_exists('convert_html_to_text')) {
require(HESK_PATH . 'inc/html2text/html2text.php');
}
@@ -759,8 +759,8 @@ function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message
$msg = str_replace('%%MESSAGE%%', $htmlMessage, $msg);
} else {
$plainTextMessage = $ticket['message'];
- if ($modsForHesk_settings['rich_text_for_tickets']
- || $modsForHesk_settings['rich_text_for_tickets_for_customers']) {
+ $message_has_html = checkForHtml($ticket);
+ if ($message_has_html) {
if (!function_exists('convert_html_to_text')) {
require(HESK_PATH . 'inc/html2text/html2text.php');
}
@@ -842,3 +842,14 @@ function processDirectAttachments($emailMethod, $postfields = NULL, $boundary =
return $attachments;
}
}
+
+function checkForHtml($ticket) {
+ global $hesk_settings;
+
+ $repliesRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "replies` WHERE `replyto` = ".intval($ticket['id']) . " ORDER BY `id` DESC LIMIT 1");
+ if (hesk_dbNumRows($repliesRs) != 1) {
+ return $ticket['html'];
+ }
+ $reply = hesk_dbFetchAssoc($repliesRs);
+ return $reply['html'];
+}
\ No newline at end of file
diff --git a/inc/posting_functions.inc.php b/inc/posting_functions.inc.php
index 3bc629a7..bc4559d7 100644
--- a/inc/posting_functions.inc.php
+++ b/inc/posting_functions.inc.php
@@ -168,7 +168,8 @@ function hesk_newTicket($ticket, $isVerified = true)
'dt' => hesk_date(),
'lastchange' => hesk_date(),
'id' => hesk_dbInsertID(),
- 'language' => $language
+ 'language' => $language,
+ 'html' => $ticket['html']
);
// Add custom fields to the array
From 10fb6e374d7c06985dbcf9bdf66e52f5f818d817 Mon Sep 17 00:00:00 2001
From: Mike Koch
Date: Sat, 17 Oct 2015 20:57:58 -0400
Subject: [PATCH 8/9] Remove api folder for now
---
api/canned/index.php | 19 ---
api/core/database.inc.php | 247 ------------------------------
api/core/database_mysqli.inc.php | 253 -------------------------------
api/core/json_error.php | 11 --
4 files changed, 530 deletions(-)
delete mode 100644 api/canned/index.php
delete mode 100755 api/core/database.inc.php
delete mode 100755 api/core/database_mysqli.inc.php
delete mode 100644 api/core/json_error.php
diff --git a/api/canned/index.php b/api/canned/index.php
deleted file mode 100644
index c9c35024..00000000
--- a/api/canned/index.php
+++ /dev/null
@@ -1,19 +0,0 @@
-EXPLAIN $query\n";
-
- if ($res = @mysqli_query($hesk_db_link, $query))
- {
- return $res;
- }
- elseif ($hesk_settings['debug_mode'])
- {
- $message = $hesklang['mysql_said'] . ': ' . mysqli_error($hesk_db_link);
- }
- else
- {
- $message = $hesklang['contact_webmaster'] . $hesk_settings['webmaster_email'];
- }
- print_error($hesklang['cant_sql'], $message);
- die(http_response_code(500));
-} // END hesk_dbQuery()
-
-
-function hesk_dbFetchAssoc($res)
-{
-
- return @mysqli_fetch_assoc($res);
-
-} // END hesk_FetchAssoc()
-
-
-function hesk_dbFetchRow($res)
-{
-
- return @mysqli_fetch_row($res);
-
-} // END hesk_FetchRow()
-
-
-function hesk_dbResult($res, $row = 0, $column = 0)
-{
- $i=0;
- $res->data_seek(0);
-
- while ($tmp = @mysqli_fetch_array($res, MYSQLI_NUM))
- {
- if ($i==$row)
- {
- return $tmp[$column];
- }
- $i++;
- }
-
- return '';
-
-} // END hesk_dbResult()
-
-
-function hesk_dbInsertID()
-{
- global $hesk_db_link;
-
- if ($lastid = @mysqli_insert_id($hesk_db_link))
- {
- return $lastid;
- }
-
-} // END hesk_dbInsertID()
-
-
-function hesk_dbFreeResult($res)
-{
-
- return @mysqli_free_result($res);
-
-} // END hesk_dbFreeResult()
-
-
-function hesk_dbNumRows($res)
-{
-
- return @mysqli_num_rows($res);
-
-} // END hesk_dbNumRows()
-
-
-function hesk_dbAffectedRows()
-{
- global $hesk_db_link;
-
- return @mysqli_affected_rows($hesk_db_link);
-
-} // END hesk_dbAffectedRows()
diff --git a/api/core/json_error.php b/api/core/json_error.php
deleted file mode 100644
index 61b491e6..00000000
--- a/api/core/json_error.php
+++ /dev/null
@@ -1,11 +0,0 @@
-
Date: Sat, 17 Oct 2015 20:58:43 -0400
Subject: [PATCH 9/9] Remove unused function
---
inc/common.inc.php | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/inc/common.inc.php b/inc/common.inc.php
index 963fe2f2..62406c11 100644
--- a/inc/common.inc.php
+++ b/inc/common.inc.php
@@ -154,19 +154,6 @@ function hesk_load_database_functions()
} // END hesk_load_database_functions()
-function hesk_load_api_database_functions()
-{
- require(HESK_PATH . 'api/core/json_error.php');
- // Preferrably use the MySQLi functions
- if (function_exists('mysqli_connect')) {
- require(HESK_PATH . 'api/core/database_mysqli.inc.php');
- } // Default to MySQL
- else {
- require(HESK_PATH . 'api/core/database.inc.php');
- }
-} // END hesk_load_database_functions()
-
-
function hesk_unlink($file, $older_than = 0)
{
return (is_file($file) && (!$older_than || (time() - filectime($file)) > $older_than) && @unlink($file)) ? true : false;