diff --git a/plugins/yetiforce/yetiforce.php b/plugins/yetiforce/yetiforce.php index 2bdcf3e1..f0ac3301 100644 --- a/plugins/yetiforce/yetiforce.php +++ b/plugins/yetiforce/yetiforce.php @@ -95,94 +95,94 @@ public function init() $this->include_stylesheet('../../../../../libraries/@fortawesome/fontawesome-free/css/all.css'); $currentPath = getcwd(); chdir($this->rc->config->get('root_directory')); - $this->loadCurrentUser(); - - $this->rc->load_language(null, [ - 'LBL_FILE_FROM_CRM' => \App\Language::translate('LBL_FILE_FROM_CRM', 'OSSMail', false, false), - 'LBL_MAIL_TEMPLATES' => \App\Language::translate('LBL_MAIL_TEMPLATES', 'OSSMail', false, false), - 'LBL_TEMPLATES' => \App\Language::translate('LBL_TEMPLATES', 'OSSMail', false, false), - 'BTN_BLACK_LIST' => \App\Language::translate('LBL_BLACK_LIST', 'OSSMail', false, false), - 'LBL_BLACK_LIST_DESC' => \App\Language::translate('LBL_BLACK_LIST_DESC', 'OSSMail', false, false), - 'BTN_WHITE_LIST' => \App\Language::translate('LBL_WHITE_LIST', 'OSSMail', false, false), - 'LBL_WHITE_LIST_DESC' => \App\Language::translate('LBL_WHITE_LIST_DESC', 'OSSMail', false, false), - 'LBL_ALERT_NEUTRAL_LIST' => \App\Language::translate('LBL_ALERT_NEUTRAL_LIST', 'OSSMail', false, false), - 'LBL_ALERT_BLACK_LIST' => \App\Language::translate('LBL_BLACK_LIST_ALERT', 'OSSMail', false, false), - 'LBL_ALERT_WHITE_LIST' => \App\Language::translate('LBL_WHITE_LIST_ALERT', 'OSSMail', false, false), - 'LBL_ALERT_FAKE_MAIL' => \App\Language::translate('LBL_ALERT_FAKE_MAIL', 'OSSMail'), - 'BTN_ANALYSIS_DETAILS' => \App\Language::translate('BTN_ANALYSIS_DETAILS', 'OSSMail', false, false), - 'LBL_ALERT_FAKE_SENDER' => \App\Language::translate('LBL_ALERT_FAKE_SENDER', 'OSSMail'), - ]); - - if ('preview' === $this->rc->action || 'show' === $this->rc->action || '' == $this->rc->action) { - $this->include_script('preview.js'); - $this->include_stylesheet('preview.css'); - - $this->add_hook('template_object_messageattachments', [$this, 'appendIcsPreview']); - if (\App\Config::component('Mail', 'rcDetailCheckRbl', false)) { - $this->add_hook('template_object_messagesummary', [$this, 'messageSummary']); - } - $this->add_hook('message_load', [$this, 'message_load']); - - $this->add_button([ - 'command' => 'plugin.yetiforce.addSenderToList', - 'type' => 'link', - 'prop' => 1, - 'class' => 'button yfi-fa-check-circle disabled js-white-list-btn text-success', - 'classact' => 'button yfi-fa-check-circle text-success', - 'classsel' => 'button yfi-fa-check-circle pressed text-success', - 'title' => 'LBL_WHITE_LIST_DESC', - 'label' => 'BTN_WHITE_LIST', - 'innerclass' => 'inner', - ], 'toolbar'); - $this->add_button([ - 'command' => 'plugin.yetiforce.addSenderToList', - 'type' => 'link', - 'prop' => 0, - 'class' => 'button yfi-fa-ban disabled text-danger', - 'classact' => 'button yfi-fa-ban text-danger', - 'classsel' => 'button yfi-fa-ban pressed text-danger', - 'title' => 'LBL_BLACK_LIST_DESC', - 'label' => 'BTN_BLACK_LIST', - 'innerclass' => 'inner', - ], 'toolbar'); - $this->add_button([ - 'command' => 'plugin.yetiforce.loadMailAnalysis', - 'type' => 'link', - 'class' => 'button yfi-fa-book-reader disabled text-info', - 'classact' => 'button yfi-fa-book-reader text-info', - 'classsel' => 'button yfi-fa-book-reader pressed text-info', - 'title' => 'BTN_ANALYSIS_DETAILS', - 'label' => 'BTN_ANALYSIS_DETAILS', - 'innerclass' => 'inner', - ], 'toolbar'); - } elseif ('compose' === $this->rc->action) { - $this->include_script('compose.js'); - $composeAddressModules = []; - foreach (\App\Config::component('Mail', 'RC_COMPOSE_ADDRESS_MODULES') as $moduleName) { - if (\App\Privilege::isPermitted($moduleName)) { - $composeAddressModules[$moduleName] = \App\Language::translate($moduleName, $moduleName); + if ($this->loadCurrentUser()) { + $this->rc->load_language(null, [ + 'LBL_FILE_FROM_CRM' => \App\Language::translate('LBL_FILE_FROM_CRM', 'OSSMail', false, false), + 'LBL_MAIL_TEMPLATES' => \App\Language::translate('LBL_MAIL_TEMPLATES', 'OSSMail', false, false), + 'LBL_TEMPLATES' => \App\Language::translate('LBL_TEMPLATES', 'OSSMail', false, false), + 'BTN_BLACK_LIST' => \App\Language::translate('LBL_BLACK_LIST', 'OSSMail', false, false), + 'LBL_BLACK_LIST_DESC' => \App\Language::translate('LBL_BLACK_LIST_DESC', 'OSSMail', false, false), + 'BTN_WHITE_LIST' => \App\Language::translate('LBL_WHITE_LIST', 'OSSMail', false, false), + 'LBL_WHITE_LIST_DESC' => \App\Language::translate('LBL_WHITE_LIST_DESC', 'OSSMail', false, false), + 'LBL_ALERT_NEUTRAL_LIST' => \App\Language::translate('LBL_ALERT_NEUTRAL_LIST', 'OSSMail', false, false), + 'LBL_ALERT_BLACK_LIST' => \App\Language::translate('LBL_BLACK_LIST_ALERT', 'OSSMail', false, false), + 'LBL_ALERT_WHITE_LIST' => \App\Language::translate('LBL_WHITE_LIST_ALERT', 'OSSMail', false, false), + 'LBL_ALERT_FAKE_MAIL' => \App\Language::translate('LBL_ALERT_FAKE_MAIL', 'OSSMail'), + 'BTN_ANALYSIS_DETAILS' => \App\Language::translate('BTN_ANALYSIS_DETAILS', 'OSSMail', false, false), + 'LBL_ALERT_FAKE_SENDER' => \App\Language::translate('LBL_ALERT_FAKE_SENDER', 'OSSMail'), + ]); + + if ('preview' === $this->rc->action || 'show' === $this->rc->action || '' == $this->rc->action) { + $this->include_script('preview.js'); + $this->include_stylesheet('preview.css'); + + $this->add_hook('template_object_messageattachments', [$this, 'appendIcsPreview']); + if (\App\Config::component('Mail', 'rcDetailCheckRbl', false)) { + $this->add_hook('template_object_messagesummary', [$this, 'messageSummary']); } - } - $this->viewData['compose']['composeAddressModules'] = $composeAddressModules; - $this->rc->output->set_env('yf_isPermittedMailTemplates', \App\Privilege::isPermitted('EmailTemplates')); + $this->add_hook('message_load', [$this, 'message_load']); + + $this->add_button([ + 'command' => 'plugin.yetiforce.addSenderToList', + 'type' => 'link', + 'prop' => 1, + 'class' => 'button yfi-fa-check-circle disabled js-white-list-btn text-success', + 'classact' => 'button yfi-fa-check-circle text-success', + 'classsel' => 'button yfi-fa-check-circle pressed text-success', + 'title' => 'LBL_WHITE_LIST_DESC', + 'label' => 'BTN_WHITE_LIST', + 'innerclass' => 'inner', + ], 'toolbar'); + $this->add_button([ + 'command' => 'plugin.yetiforce.addSenderToList', + 'type' => 'link', + 'prop' => 0, + 'class' => 'button yfi-fa-ban disabled text-danger', + 'classact' => 'button yfi-fa-ban text-danger', + 'classsel' => 'button yfi-fa-ban pressed text-danger', + 'title' => 'LBL_BLACK_LIST_DESC', + 'label' => 'BTN_BLACK_LIST', + 'innerclass' => 'inner', + ], 'toolbar'); + $this->add_button([ + 'command' => 'plugin.yetiforce.loadMailAnalysis', + 'type' => 'link', + 'class' => 'button yfi-fa-book-reader disabled text-info', + 'classact' => 'button yfi-fa-book-reader text-info', + 'classsel' => 'button yfi-fa-book-reader pressed text-info', + 'title' => 'BTN_ANALYSIS_DETAILS', + 'label' => 'BTN_ANALYSIS_DETAILS', + 'innerclass' => 'inner', + ], 'toolbar'); + } elseif ('compose' === $this->rc->action) { + $this->include_script('compose.js'); + $composeAddressModules = []; + foreach (\App\Config::component('Mail', 'RC_COMPOSE_ADDRESS_MODULES') as $moduleName) { + if (\App\Privilege::isPermitted($moduleName)) { + $composeAddressModules[$moduleName] = \App\Language::translate($moduleName, $moduleName); + } + } + $this->viewData['compose']['composeAddressModules'] = $composeAddressModules; + $this->rc->output->set_env('yf_isPermittedMailTemplates', \App\Privilege::isPermitted('EmailTemplates')); - $this->rc->output->add_handler('yetiforce.adressbutton', [$this, 'adressButton']); - $this->add_hook('identity_select', [$this, 'identity_select']); - $this->add_hook('render_page', [$this, 'loadSignature']); + $this->rc->output->add_handler('yetiforce.adressbutton', [$this, 'adressButton']); + $this->add_hook('identity_select', [$this, 'identity_select']); + $this->add_hook('render_page', [$this, 'loadSignature']); - $this->add_hook('message_compose_body', [$this, 'message_compose_body']); - $this->add_hook('message_compose', [$this, 'message_compose']); + $this->add_hook('message_compose_body', [$this, 'message_compose_body']); + $this->add_hook('message_compose', [$this, 'message_compose']); - if ($id = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC)) { - $id = App\Purifier::purifyByType($id, 'Alnum'); - if (isset($_SESSION['compose_data_' . $id]['param']['crmmodule'])) { - $this->rc->output->set_env('yf_crmModule', $_SESSION['compose_data_' . $id]['param']['crmmodule']); - } - if (isset($_SESSION['compose_data_' . $id]['param']['crmrecord'])) { - $this->rc->output->set_env('yf_crmRecord', $_SESSION['compose_data_' . $id]['param']['crmrecord']); - } - if (isset($_SESSION['compose_data_' . $id]['param']['crmview'])) { - $this->rc->output->set_env('yf_crmView', $_SESSION['compose_data_' . $id]['param']['crmview']); + if ($id = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC)) { + $id = App\Purifier::purifyByType($id, 'Alnum'); + if (isset($_SESSION['compose_data_' . $id]['param']['crmmodule'])) { + $this->rc->output->set_env('yf_crmModule', $_SESSION['compose_data_' . $id]['param']['crmmodule']); + } + if (isset($_SESSION['compose_data_' . $id]['param']['crmrecord'])) { + $this->rc->output->set_env('yf_crmRecord', $_SESSION['compose_data_' . $id]['param']['crmrecord']); + } + if (isset($_SESSION['compose_data_' . $id]['param']['crmview'])) { + $this->rc->output->set_env('yf_crmView', $_SESSION['compose_data_' . $id]['param']['crmview']); + } } } } @@ -433,12 +433,12 @@ public function message_compose(array $args): array if (!empty($params['recordNumber']) && !empty($params['crmmodule'])) { $currentPath = getcwd(); chdir($this->rc->config->get('root_directory')); - $this->loadCurrentUser(); - - $subjectNumber = \App\Mail\RecordFinder::getRecordNumberFromString($subject, $params['crmmodule']); - $recordNumber = \App\Mail\RecordFinder::getRecordNumberFromString("[{$params['recordNumber']}]", $params['crmmodule']); - if (false === $subject || (false !== $subject && $subjectNumber !== $recordNumber)) { - $subject = "[{$params['recordNumber']}] $subject"; + if ($this->loadCurrentUser()) { + $subjectNumber = \App\Mail\RecordFinder::getRecordNumberFromString($subject, $params['crmmodule']); + $recordNumber = \App\Mail\RecordFinder::getRecordNumberFromString("[{$params['recordNumber']}]", $params['crmmodule']); + if (false === $subject || (false !== $subject && $subjectNumber !== $recordNumber)) { + $subject = "[{$params['recordNumber']}] $subject"; + } } chdir($currentPath); } @@ -790,8 +790,9 @@ protected function parseVariables(string $text): string { $currentPath = getcwd(); chdir($this->rc->config->get('root_directory')); - $this->loadCurrentUser(); - $text = \App\TextParser::getInstance()->setContent($text)->parse()->getContent(); + if ($this->loadCurrentUser()) { + $text = \App\TextParser::getInstance()->setContent($text)->parse()->getContent(); + } chdir($currentPath); return $text; } @@ -806,6 +807,9 @@ protected function loadCurrentUser(): bool if (isset($this->currentUser)) { return true; } + if (empty($_SESSION['crm']['id'])) { + return false; + } require 'include/main/WebUI.php'; $this->currentUser = \App\User::getUserModel($_SESSION['crm']['id']); App\User::setCurrentUserId($_SESSION['crm']['id']); @@ -850,9 +854,8 @@ public function getContentEmailTemplate(): void $templateId = App\Purifier::purifyByType(rcube_utils::get_input_value('id', rcube_utils::INPUT_GPC), 'Integer'); $currentPath = getcwd(); chdir($this->rc->config->get('root_directory')); - $this->loadCurrentUser(); $mail = []; - if (\App\Privilege::isPermitted('EmailTemplates', 'DetailView', $templateId)) { + if ($this->loadCurrentUser() && \App\Privilege::isPermitted('EmailTemplates', 'DetailView', $templateId)) { $mail = \App\Mail::getTemplate($templateId); if ($recordId = rcube_utils::get_input_value('record_id', rcube_utils::INPUT_GPC)) { $textParser = \App\TextParser::getInstanceById( @@ -888,109 +891,110 @@ public function appendIcsPreview(array $args): array { $currentPath = getcwd(); chdir($this->rc->config->get('root_directory')); - $this->loadCurrentUser(); - $showPart = $ics = $counterBtn = $counterList = []; - foreach ($this->icsParts as $icsPart) { - $icsContent = $this->message->get_part_content($icsPart['part'], null, true); - $calendar = \App\Integrations\Dav\Calendar::loadFromContent($icsContent); - foreach ($calendar->getRecordInstance() as $key => $recordModel) { - if (!isset($ics[$key])) { - $ics[$key] = [$recordModel, $icsPart]; - if (isset($counterBtn[$icsPart['part']])) { - ++$counterBtn[$icsPart['part']]; - } else { - $counterBtn[$icsPart['part']] = 1; + if ($this->loadCurrentUser()) { + $showPart = $ics = $counterBtn = $counterList = []; + foreach ($this->icsParts as $icsPart) { + $icsContent = $this->message->get_part_content($icsPart['part'], null, true); + $calendar = \App\Integrations\Dav\Calendar::loadFromContent($icsContent); + foreach ($calendar->getRecordInstance() as $key => $recordModel) { + if (!isset($ics[$key])) { + $ics[$key] = [$recordModel, $icsPart]; + if (isset($counterBtn[$icsPart['part']])) { + ++$counterBtn[$icsPart['part']]; + } else { + $counterBtn[$icsPart['part']] = 1; + } } } } - } - $translationMod = 'Calendar'; - $showMore = false; - foreach ($ics as $data) { - $evTemplate = '