Some more API changes
This commit is contained in:
parent
0ceaafc0ec
commit
41123e987b
@ -15,6 +15,7 @@ use BusinessLogic\Statuses\DefaultStatusForAction;
|
|||||||
use BusinessLogic\Tickets\Ticket;
|
use BusinessLogic\Tickets\Ticket;
|
||||||
use Core\Constants\Priority;
|
use Core\Constants\Priority;
|
||||||
use DataAccess\Categories\CategoryGateway;
|
use DataAccess\Categories\CategoryGateway;
|
||||||
|
use DataAccess\Security\UserGateway;
|
||||||
use DataAccess\Statuses\StatusGateway;
|
use DataAccess\Statuses\StatusGateway;
|
||||||
|
|
||||||
class EmailTemplateParser {
|
class EmailTemplateParser {
|
||||||
@ -29,9 +30,15 @@ class EmailTemplateParser {
|
|||||||
*/
|
*/
|
||||||
private $categoryGateway;
|
private $categoryGateway;
|
||||||
|
|
||||||
function __construct($statusGateway, $categoryGateway) {
|
/**
|
||||||
|
* @var $userGateway UserGateway
|
||||||
|
*/
|
||||||
|
private $userGateway;
|
||||||
|
|
||||||
|
function __construct($statusGateway, $categoryGateway, $userGateway) {
|
||||||
$this->statusGateway = $statusGateway;
|
$this->statusGateway = $statusGateway;
|
||||||
$this->categoryGateway = $categoryGateway;
|
$this->categoryGateway = $categoryGateway;
|
||||||
|
$this->userGateway = $userGateway;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,20 +49,31 @@ class EmailTemplateParser {
|
|||||||
function getFormattedEmailForLanguage($templateName, $language, $ticket, $heskSettings) {
|
function getFormattedEmailForLanguage($templateName, $language, $ticket, $heskSettings) {
|
||||||
global $hesklang;
|
global $hesklang;
|
||||||
|
|
||||||
$template = self::getFromFileSystem($templateName, $language);
|
$template = self::getFromFileSystem($templateName, $language, false);
|
||||||
|
$htmlTemplate = self::getFromFileSystem($templateName, $language, true);
|
||||||
$subject = ValidEmailTemplates::getValidEmailTemplates()[$templateName];
|
$subject = ValidEmailTemplates::getValidEmailTemplates()[$templateName];
|
||||||
|
|
||||||
$subject = $this->parseSubject($subject, $ticket, $language, $heskSettings);
|
$subject = $this->parseSubject($subject, $ticket, $language, $heskSettings);
|
||||||
|
$message = $this->parseMessage($subject, $ticket, $language, $heskSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getFromFileSystem($template, $language)
|
/**
|
||||||
|
* @param $template string
|
||||||
|
* @param $language string
|
||||||
|
* @param $html bool
|
||||||
|
* @return string The template
|
||||||
|
* @throws EmailTemplateNotFoundException If the template was not found in the filesystem for the provided language
|
||||||
|
* @throws InvalidEmailTemplateException If the $template is not a valid template name
|
||||||
|
*/
|
||||||
|
private function getFromFileSystem($template, $language, $html)
|
||||||
{
|
{
|
||||||
if (!isset(ValidEmailTemplates::getValidEmailTemplates()[$template])) {
|
if (!isset(ValidEmailTemplates::getValidEmailTemplates()[$template])) {
|
||||||
throw new InvalidEmailTemplateException($template);
|
throw new InvalidEmailTemplateException($template);
|
||||||
}
|
}
|
||||||
|
$htmlFolder = $html ? 'html/' : '';
|
||||||
|
|
||||||
/* Get email template */
|
/* Get email template */
|
||||||
$file = 'language/' . $language . '/emails/' . $template . '.txt';
|
$file = "language/{$language}/emails/{$htmlFolder}{$template}.txt";
|
||||||
$absoluteFilePath = __DIR__ . '/../../../' . $file;
|
$absoluteFilePath = __DIR__ . '/../../../' . $file;
|
||||||
|
|
||||||
if (file_exists($absoluteFilePath)) {
|
if (file_exists($absoluteFilePath)) {
|
||||||
@ -71,10 +89,15 @@ class EmailTemplateParser {
|
|||||||
* @param $language string
|
* @param $language string
|
||||||
* @param $heskSettings array
|
* @param $heskSettings array
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws \Exception if common.inc.php isn't loaded
|
||||||
*/
|
*/
|
||||||
private function parseSubject($subjectTemplate, $ticket, $language, $heskSettings) {
|
private function parseSubject($subjectTemplate, $ticket, $language, $heskSettings) {
|
||||||
global $hesklang;
|
global $hesklang;
|
||||||
|
|
||||||
|
if (!function_exists('hesk_msgToPlain')) {
|
||||||
|
throw new \Exception("common.inc.php not loaded!");
|
||||||
|
}
|
||||||
|
|
||||||
if ($ticket === null) {
|
if ($ticket === null) {
|
||||||
return $subjectTemplate;
|
return $subjectTemplate;
|
||||||
}
|
}
|
||||||
@ -84,7 +107,6 @@ class EmailTemplateParser {
|
|||||||
$statusName = $defaultStatus->localizedNames[$language]->text;
|
$statusName = $defaultStatus->localizedNames[$language]->text;
|
||||||
$category = $this->categoryGateway->getAllCategories($heskSettings)[$ticket->categoryId];
|
$category = $this->categoryGateway->getAllCategories($heskSettings)[$ticket->categoryId];
|
||||||
|
|
||||||
$priority = '';
|
|
||||||
switch ($ticket->priorityId) {
|
switch ($ticket->priorityId) {
|
||||||
case Priority::CRITICAL:
|
case Priority::CRITICAL:
|
||||||
$priority = $hesklang['critical'];
|
$priority = $hesklang['critical'];
|
||||||
@ -104,10 +126,84 @@ class EmailTemplateParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Special tags
|
// Special tags
|
||||||
$msg = str_replace('%%SUBJECT%%', $ticket->subject, $subjectTemplate);
|
$subject = str_replace('%%SUBJECT%%', $ticket->subject, $subjectTemplate);
|
||||||
$msg = str_replace('%%TRACK_ID%%', $ticket->trackingId, $msg);
|
$subject = str_replace('%%TRACK_ID%%', $ticket->trackingId, $subject);
|
||||||
$msg = str_replace('%%CATEGORY%%', $category->id, $msg);
|
$subject = str_replace('%%CATEGORY%%', $category->id, $subject);
|
||||||
$msg = str_replace('%%PRIORITY%%', $priority, $msg);
|
$subject = str_replace('%%PRIORITY%%', $priority, $subject);
|
||||||
$msg = str_replace('%%STATUS%%', $statusName, $msg);
|
$subject = str_replace('%%STATUS%%', $statusName, $subject);
|
||||||
|
|
||||||
|
return $subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $messageTemplate string
|
||||||
|
* @param $ticket Ticket
|
||||||
|
* @param $language string
|
||||||
|
* @param $heskSettings array
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception if common.inc.php isn't loaded
|
||||||
|
*/
|
||||||
|
private function parseMessage($messageTemplate, $ticket, $language, $admin, $heskSettings) {
|
||||||
|
global $hesklang;
|
||||||
|
|
||||||
|
if (!function_exists('hesk_msgToPlain')) {
|
||||||
|
throw new \Exception("common.inc.php not loaded!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ticket === null) {
|
||||||
|
return $messageTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
$heskSettings['site_title'] = hesk_msgToPlain($heskSettings['site_title'], 1);
|
||||||
|
|
||||||
|
// Is email required to view ticket (for customers only)?
|
||||||
|
$heskSettings['e_param'] = $heskSettings['email_view_ticket'] ? '&e=' . rawurlencode($ticket->email) : '';
|
||||||
|
|
||||||
|
/* Generate the ticket URLs */
|
||||||
|
$trackingURL = $heskSettings['hesk_url'];
|
||||||
|
$trackingURL .= $admin ? '/' . $heskSettings['admin_dir'] . '/admin_ticket.php' : '/ticket.php';
|
||||||
|
$trackingURL .= '?track=' . $ticket['trackid'] . ($admin ? '' : $heskSettings['e_param']) . '&Refresh=' . rand(10000, 99999);
|
||||||
|
|
||||||
|
// Status name and category name
|
||||||
|
$defaultStatus = $this->statusGateway->getStatusForDefaultAction(DefaultStatusForAction::NEW_TICKET, $heskSettings);
|
||||||
|
$statusName = hesk_msgToPlain($defaultStatus->localizedNames[$language]->text);
|
||||||
|
$category = hesk_msgToPlain($this->categoryGateway->getAllCategories($heskSettings)[$ticket->categoryId]);
|
||||||
|
$owner = hesk_msgToPlain($this->userGateway->getNameForId($ticket->ownerId, $heskSettings));
|
||||||
|
|
||||||
|
switch ($ticket->priorityId) {
|
||||||
|
case Priority::CRITICAL:
|
||||||
|
$priority = $hesklang['critical'];
|
||||||
|
break;
|
||||||
|
case Priority::HIGH:
|
||||||
|
$priority = $hesklang['high'];
|
||||||
|
break;
|
||||||
|
case Priority::MEDIUM:
|
||||||
|
$priority = $hesklang['medium'];
|
||||||
|
break;
|
||||||
|
case Priority::LOW:
|
||||||
|
$priority = $hesklang['low'];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$priority = 'PRIORITY NOT FOUND';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special tags
|
||||||
|
$msg = str_replace('%%NAME%%', $ticket->name, $messageTemplate);
|
||||||
|
$msg = str_replace('%%SUBJECT%%', $ticket['subject'], $msg);
|
||||||
|
$msg = str_replace('%%TRACK_ID%%', $ticket['trackid'], $msg);
|
||||||
|
$msg = str_replace('%%TRACK_URL%%', $trackingURL, $msg);
|
||||||
|
$msg = str_replace('%%SITE_TITLE%%', $hesk_settings['site_title'], $msg);
|
||||||
|
$msg = str_replace('%%SITE_URL%%', $hesk_settings['site_url'], $msg);
|
||||||
|
$msg = str_replace('%%CATEGORY%%', $ticket['category'], $msg);
|
||||||
|
$msg = str_replace('%%PRIORITY%%', $ticket['priority'], $msg);
|
||||||
|
$msg = str_replace('%%OWNER%%', $ticket['owner'], $msg);
|
||||||
|
$msg = str_replace('%%STATUS%%', $ticket['status'], $msg);
|
||||||
|
$msg = str_replace('%%EMAIL%%', $ticket['email'], $msg);
|
||||||
|
$msg = str_replace('%%CREATED%%', $ticket['dt'], $msg);
|
||||||
|
$msg = str_replace('%%UPDATED%%', $ticket['lastchange'], $msg);
|
||||||
|
$msg = str_replace('%%ID%%', $ticket['id'], $msg);
|
||||||
|
|
||||||
|
return $subject;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,4 +31,19 @@ class UserGateway extends CommonDao {
|
|||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Replace this with a basic User retrieval
|
||||||
|
function getNameForId($id, $heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
$rs = hesk_dbQuery("SELECT `name` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` WHERE `id` = " . intval($id));
|
||||||
|
|
||||||
|
if (hesk_dbNumRows($rs) === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$row = hesk_dbFetchAssoc($rs);
|
||||||
|
|
||||||
|
return $row['name'];
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@
|
|||||||
// Core requirements
|
// Core requirements
|
||||||
define('IN_SCRIPT', 1);
|
define('IN_SCRIPT', 1);
|
||||||
define('HESK_PATH', '../');
|
define('HESK_PATH', '../');
|
||||||
|
require_once(__DIR__ . 'vendor/autoload.php');
|
||||||
require_once(__DIR__ . '/bootstrap.php');
|
require_once(__DIR__ . '/bootstrap.php');
|
||||||
require_once(__DIR__ . '/../hesk_settings.inc.php');
|
require_once(__DIR__ . '/../hesk_settings.inc.php');
|
||||||
require_once(__DIR__ . '/../inc/common.inc.php');
|
require_once(__DIR__ . '/../inc/common.inc.php');
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
"php-http/guzzle6-adapter": "^1.1",
|
"php-http/guzzle6-adapter": "^1.1",
|
||||||
"php-http/message": "^1.5",
|
"php-http/message": "^1.5",
|
||||||
"php-http/curl-client": "^1.7",
|
"php-http/curl-client": "^1.7",
|
||||||
"guzzlehttp/psr7": "^1.3"
|
"guzzlehttp/psr7": "^1.3",
|
||||||
|
"doctrine/orm": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -989,7 +989,6 @@ function hesk_ticketToPlain($ticket, $specialchars = 0, $strip = 1)
|
|||||||
}
|
}
|
||||||
} // END hesk_ticketToPlain()
|
} // END hesk_ticketToPlain()
|
||||||
|
|
||||||
|
|
||||||
function hesk_msgToPlain($msg, $specialchars = 0, $strip = 1)
|
function hesk_msgToPlain($msg, $specialchars = 0, $strip = 1)
|
||||||
{
|
{
|
||||||
$msg = preg_replace('/\<a href="(mailto:)?([^"]*)"[^\<]*\<\/a\>/i', "$2", $msg);
|
$msg = preg_replace('/\<a href="(mailto:)?([^"]*)"[^\<]*\<\/a\>/i', "$2", $msg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user