Commit 758da9ec authored by Stefan Galinski's avatar Stefan Galinski 🎮
Browse files

[TASK] Cleanup and several fixes and simplifications

parent 779e2092
......@@ -57,7 +57,6 @@ class SendMailCommandController extends CommandController {
$mailsToSend = $this->mailRepository->findMailsToSend($sendCount);
foreach ($mailsToSend as $mailToSend) {
/** @var Mail $mailToSend */
$fromAddress = $mailToSend->getFromAddress();
$toAddress = $mailToSend->getToAddress();
$ccAddresses = GeneralUtility::trimExplode(',', $mailToSend->getCcAddresses());
......@@ -88,5 +87,3 @@ class SendMailCommandController extends CommandController {
$this->persistenceManager->persistAll();
}
}
?>
......@@ -339,21 +339,12 @@ class MailController extends ActionController {
public function sendTestMailAction(
$emailAddress, $selectedExtensionKey, $selectedTemplateKey, $selectedLanguageLeft, $selectedLanguageRight
) {
if (!filter_var($this->settings['mail']['test']['from'], FILTER_VALIDATE_EMAIL)) {
$message = LocalizationUtility::translate('backend.invalid_test_email', 'sg_mail');
$this->addFlashMessage($message, '', FlashMessage::ERROR);
$arguments = $this->request->getArguments();
$this->redirect('index', NULL, NULL, $arguments);
}
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */
$mailTemplateService = $objectManager->get(MailTemplateService::class);
$mailTemplateService->setLanguage($selectedLanguageLeft);
$mailTemplateService->setToAddresses($emailAddress);
$mailTemplateService->setFromAddress($this->settings['mail']['test']['from']);
$mailTemplateService->setFromAddress('noreply@example.org');
$mailTemplateService->setTemplateName($selectedTemplateKey);
$mailTemplateService->setExtensionKey($selectedExtensionKey);
$mailIsSend = $mailTemplateService->sendEmail($this->settings['mail']['test']['subject'], TRUE);
......@@ -363,7 +354,7 @@ class MailController extends ActionController {
$mailTemplateService = $objectManager->get(MailTemplateService::class);
$mailTemplateService->setLanguage($selectedLanguageRight);
$mailTemplateService->setToAddresses($emailAddress);
$mailTemplateService->setFromAddress($this->settings['mail']['test']['from']);
$mailTemplateService->setFromAddress('noreply@example.org');
$mailTemplateService->setTemplateName($selectedTemplateKey);
$mailTemplateService->setExtensionKey($selectedExtensionKey);
$mailIsSend = $mailTemplateService->sendEmail($this->settings['mail']['test']['subject'], TRUE);
......@@ -379,6 +370,5 @@ class MailController extends ActionController {
$arguments = $this->request->getArguments();
$this->redirect('index', NULL, NULL, $arguments);
}
}
......@@ -32,7 +32,6 @@ use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
* Template domain model
*/
class Template extends AbstractEntity {
/**
* @var string
*/
......@@ -127,5 +126,4 @@ class Template extends AbstractEntity {
public function setContent($content) {
$this->content = $content;
}
}
......@@ -5,7 +5,7 @@ namespace SGalinski\SgMail\Domain\Repository;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
......@@ -78,5 +78,3 @@ abstract class AbstractRepository extends Repository {
return $statement;
}
}
?>
......@@ -28,7 +28,6 @@ namespace SGalinski\SgMail\Domain\Repository;
use TYPO3\CMS\Extbase\Persistence\Generic\Query;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
* Repository for the Mail object
......
......@@ -33,7 +33,6 @@ use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
* Repository for the Template object
*/
class TemplateRepository extends AbstractRepository {
/**
* @param string $extensionKey
* @param string $templateName
......
<?php
namespace SGalinski\SgMail\Service;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Lang\LanguageService;
use Typoheads\Formhandler\Finisher\AbstractFinisher;
namespace SGalinski\SgMail\Service;
/***************************************************************
* Copyright notice
......@@ -30,6 +26,11 @@ use Typoheads\Formhandler\Finisher\AbstractFinisher;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Lang\LanguageService;
use Typoheads\Formhandler\Finisher\AbstractFinisher;
/**
* Class FormhandlerFinisherService
*
......@@ -94,5 +95,4 @@ class FormhandlerFinisherService extends AbstractFinisher {
public function validateConfig() {
parent::validateConfig();
}
}
......@@ -2,14 +2,6 @@
namespace SGalinski\SgMail\Service;
use SGalinski\SgMail\Domain\Model\Mail;
use SGalinski\SgMail\Domain\Model\Template;
use SGalinski\SgMail\Domain\Repository\MailRepository;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Fluid\View\StandaloneView;
/***************************************************************
* Copyright notice
*
......@@ -34,6 +26,14 @@ use TYPO3\CMS\Fluid\View\StandaloneView;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\SgMail\Domain\Model\Mail;
use SGalinski\SgMail\Domain\Model\Template;
use SGalinski\SgMail\Domain\Repository\MailRepository;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* MailTemplateService
*/
......@@ -168,10 +168,9 @@ class MailTemplateService {
* @param string $templatePath
* @param string $description
* @param array $markers
* @return string
* @return void
*/
public static function registerTemplate($extension, $templateName, $templatePath, $description, array $markers) {
MailTemplateService::$registerArray[$extension][$templateName] = [
'templatePath' => $templatePath,
'description' => $description,
......@@ -198,7 +197,6 @@ class MailTemplateService {
* @return boolean email was sent or added to mail queue successfully?
*/
public function sendEmail($subject = '', $isPreview = FALSE) {
/** @var Template $template */
$template = $this->templateRepository->findTemplate(
$this->extensionKey, $this->templateName, $this->language
......@@ -286,7 +284,7 @@ class MailTemplateService {
/**
* @param array $registerArray
* @return MailTemplateService
* @return void
*/
public static function setRegisterArray(array $registerArray) {
self::$registerArray = $registerArray;
......@@ -395,5 +393,4 @@ class MailTemplateService {
$this->priority = $priority;
return $this;
}
}
......@@ -5,7 +5,7 @@ namespace SGalinski\SgMail\Service;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
......
......@@ -5,7 +5,7 @@ namespace SGalinski\SgMail\Session;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
......@@ -122,5 +122,3 @@ class PhpSession implements SingletonInterface {
unset($_SESSION[$this->sessionKey]);
}
}
?>
......@@ -5,7 +5,7 @@ namespace SGalinski\SgMail\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
......@@ -26,32 +26,12 @@ namespace SGalinski\SgMail\ViewHelpers;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
/**
* Abstract view helper
*/
class AbstractViewHelper extends AbstractBackendViewHelper {
/**
* Returns an instance of the page renderer
*
* @deprecated Implement the following migration if the extension just needs to support > 7.5.
* @return PageRenderer
*/
public function getPageRenderer() {
// Migration
// return $this->objectManager->get(\TYPO3\CMS\Core\Page\PageRenderer::class);
if (TYPO3_MODE === 'BE') {
$pageRenderer = $this->getDocInstance()->getPageRenderer();
} else {
/** @noinspection PhpUndefinedMethodInspection */
$pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
}
return $pageRenderer;
}
/**
* Returns the base url of the site
*
......@@ -69,5 +49,3 @@ class AbstractViewHelper extends AbstractBackendViewHelper {
return $baseUrl;
}
}
?>
<?php
namespace SGalinski\SgMail\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* View helper to add custom css files
*
* Example:
* {namespace lfe=SGalinski\Lfeditor\ViewHelpers}
* <lfe:addCssFile cssFile="{f:uri.resource(path: 'StyleSheets/Frontend.css')}" />
*/
class AddCssFileViewHelper extends AbstractViewHelper {
/**
* Adds a custom css file
*
* @param string $cssFile
* @return void
*/
public function render($cssFile) {
$cssFile = (TYPO3_MODE === 'FE' ? $this->getBaseUrl() : '') . $cssFile;
$this->getPageRenderer()->addCssFile($cssFile, 'stylesheet', 'all', '', FALSE);
}
}
?>
......@@ -2,29 +2,32 @@
namespace SGalinski\SgMail\ViewHelpers\Be\Menus;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* Class ActionMenuItemViewHelper
*
......@@ -33,7 +36,7 @@ namespace SGalinski\SgMail\ViewHelpers\Be\Menus;
*
* @package SGalinski\SgMail\ViewHelpers\Be\Menus
*/
class ActionMenuItemViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {
class ActionMenuItemViewHelper extends AbstractTagBasedViewHelper {
/**
* @var string
*/
......@@ -53,9 +56,6 @@ class ActionMenuItemViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\Abstract
$uriBuilder = $this->controllerContext->getUriBuilder();
$uri = $uriBuilder->reset()->uriFor($action, $arguments, $controller);
$this->tag->addAttribute('value', $uri);
$currentRequest = $this->controllerContext->getRequest();
$currentController = $currentRequest->getControllerName();
$currentAction = $currentRequest->getControllerActionName();
$this->tag->setContent($label);
return $this->tag->render();
}
......
......@@ -5,7 +5,7 @@ namespace SGalinski\SgMail\ViewHelpers\Be\Menus;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
......
......@@ -5,7 +5,7 @@ namespace SGalinski\SgMail\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
......@@ -38,35 +38,36 @@ class ExtendedIfViewHelper extends AbstractConditionViewHelper {
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('condition', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE);
$this->registerArgument('or', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE);
$this->registerArgument('or2', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE);
$this->registerArgument('or3', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE);
$this->registerArgument('or4', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE);
$this->registerArgument('and', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE);
$this->registerArgument('and2', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE);
$this->registerArgument('and3', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE);
$this->registerArgument('and4', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE);
$this->registerArgument('negate', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE);
}
/**
* renders <f:then> child if $condition or $or is true, otherwise renders <f:else> child.
*
* @return string
*/
public function render() {
if ($this->evaluateConditionFunctionExists()) {
return parent::render();
}
// @todo Remove the following part if only > 7.5 support.
$conditionResult = ($this->arguments['condition'] || $this->arguments['or'] || $this->arguments['or2'] || $this->arguments['or3'] || $this->arguments['or4'])
&& $this->arguments['and'] && $this->arguments['and2'] && $this->arguments['and3'] && $this->arguments['and4'];
if ($this->arguments['negate'] ? !$conditionResult : $conditionResult) {
return $this->renderThenChild();
} else {
return $this->renderElseChild();
}
$this->registerArgument(
'condition', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
$this->registerArgument(
'or', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
$this->registerArgument(
'or2', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
$this->registerArgument(
'or3', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
$this->registerArgument(
'or4', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
$this->registerArgument(
'and', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE
);
$this->registerArgument(
'and2', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE
);
$this->registerArgument(
'and3', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE
);
$this->registerArgument(
'and4', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, TRUE
);
$this->registerArgument(
'negate', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
}
/**
......@@ -89,16 +90,4 @@ class ExtendedIfViewHelper extends AbstractConditionViewHelper {
return isset($arguments['negate']) && $arguments['negate'] ? !$conditionResult : $conditionResult;
}
/**
* Returns true, if the function evaluateCondition exists in the AbstractConditionViewHelper class.
*
* @deprecated Remove this function if only > 7.5 support.
* @return boolean
*/
protected function evaluateConditionFunctionExists() {
return method_exists('TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper', 'evaluateCondition');
}
}
?>
<?php
namespace SGalinski\SgMail\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the AY project. The AY project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* View helper to render language labels to
* json array to be used in js applications.
*
* Renders to AY.lang.'extension name' object
*
* Example:
* {namespace rs=SGalinski\RsEvents\ViewHelpers}
* <rs:inlineLanguageLabels labels="label01,label02" />
*/
class InlineLanguageLabelsViewHelper extends AbstractViewHelper {
/**
* Renders the required javascript to make the language labels available
*
* @param string $labels Comma separated list of label keys to include
* @param boolean $htmlEscape
* @return string
*/
public function render($labels = '', $htmlEscape = FALSE) {
$extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
$labels = GeneralUtility::trimExplode(',', $labels, TRUE);
$languageArray = array();
foreach ($labels as $key) {
$value = LocalizationUtility::translate($key, $extensionName);
$languageArray[$key] = ($htmlEscape ? htmlentities($value) : $value);
}
return '
<script type="text/javascript">
var AY = AY || {};
AY.lang = AY.lang || {};
AY.lang.' . $extensionName . ' = AY.lang.' . $extensionName . ' || {};
var languageLabels = ' . json_encode($languageArray) . ';
for (label in languageLabels) {
AY.lang.' . $extensionName . '[label] = languageLabels[label];
}
</script>
';
}
}
?>
......@@ -40,8 +40,7 @@ return [
'disabled' => 'hidden',
],
'default_sortby' => 'ORDER BY sent ASC, priority DESC',
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('sg_mail') .
'Resources/Public/Icons/ModuleIconTCA.svg'
'iconfile' => 'EXT:sg_mail/Resources/Public/Icons/ModuleIconTCA.svg'
],
'interface' => [
'showRecordFieldList' => 'hidden, mail_subject, mail_body, to_address, from_address, sent, priority',
......
......@@ -27,8 +27,8 @@
return [
'ctrl' => [
'title' => 'LLL:EXT:sg_mail/Resources/Private/Language/locallang_db.xlf:tx_sgmail_domain_model_template',
'label' => 'template',
'label_alt' => '',
'label' => 'extension_key',
'label_alt' => 'template_name',
'label_alt_force' => TRUE,
'tstamp' => 'tstamp',
'crdate' => 'crdate',
......@@ -40,8 +40,7 @@ return [
'disabled' => 'hidden',
],
'default_sortby' => 'ORDER BY extension_key ASC, template_name ASC',
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('sg_mail') .
'Resources/Public/Icons/ModuleIconTCA.svg'
'iconfile' => 'EXT:sg_mail/Resources/Public/Icons/ModuleIconTCA.svg'
],
'interface' => [
'showRecordFieldList' => 'extension_key, template_name, language, content, subject',
......
......@@ -3,6 +3,5 @@ plugin.tx_sgmail {
templateRootPath = EXT:sg_mail/Resources/Private/Templates/
partialRootPath = EXT:sg_mail/Resources/Private/Partials/
layoutRootPath = EXT:sg_mail/Resources/Private/Layouts/
publicRootPath = EXT:sg_mail/Resources/Public/
}
}
module.tx_sgmail {
view {
templateRootPath = {$plugin.tx_sgcmail.view.templateRootPath}
partialRootPath = {$plugin.tx_sgcmail.view.partialRootPath}
layoutRootPath = {$plugin.