2020-10-02 11:59:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
*
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
2021-03-15 15:17:45 +01:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2020-10-02 11:59:22 +02:00
|
|
|
namespace D3\Usermanager\Modules\Application\Model;
|
|
|
|
|
|
|
|
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
|
|
|
|
use D3\ModCfg\Application\Model\Exception\d3ParameterNotFoundException;
|
|
|
|
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
|
2023-01-02 10:58:57 +01:00
|
|
|
use D3\ModCfg\Application\Model\Exception\wrongModIdException;
|
2020-12-21 10:44:49 +01:00
|
|
|
use D3\ModCfg\Application\Model\Log\d3LogInterface;
|
2021-05-10 09:27:14 +02:00
|
|
|
use D3\OxidServiceBridges\Internal\Framework\Module\Path\ModulePathResolverBridgeInterface;
|
2023-01-02 10:58:57 +01:00
|
|
|
use D3\Usermanager\Application\Model\Context\Html2TextContext;
|
|
|
|
use D3\Usermanager\Application\Model\Context\Html2TextContextInterface;
|
2020-12-21 10:44:49 +01:00
|
|
|
use D3\Usermanager\Application\Model\d3usermanager as Manager;
|
2021-03-15 15:17:45 +01:00
|
|
|
use D3\Usermanager\Application\Model\d3usermanager_renderererrorhandler;
|
2023-01-02 10:58:57 +01:00
|
|
|
use D3\Usermanager\Application\Model\d3usermanager_vars;
|
2021-03-15 15:17:45 +01:00
|
|
|
use D3\Usermanager\Application\Model\Exceptions\d3usermanager_smartyException;
|
|
|
|
use D3\Usermanager\Application\Model\Exceptions\d3usermanager_templaterendererExceptionInterface;
|
2023-01-02 10:58:57 +01:00
|
|
|
use D3\Usermanager\Application\Model\Exceptions\emptyMessageException;
|
|
|
|
use D3\Usermanager\Application\Model\MessageContentGenerator;
|
2020-10-02 11:59:22 +02:00
|
|
|
use Exception;
|
2020-12-21 10:44:49 +01:00
|
|
|
use D3\ModCfg\Application\Model\Configuration\d3_cfg_mod;
|
|
|
|
use D3\ModCfg\Application\Model\d3str;
|
|
|
|
use Html2Text\Html2Text;
|
2020-10-02 11:59:22 +02:00
|
|
|
use OxidEsales\Eshop\Application\Model\Content as Content;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Remark;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Shop as Shop;
|
2020-12-21 10:44:49 +01:00
|
|
|
use OxidEsales\Eshop\Application\Model\User as Item;
|
2020-10-02 11:59:22 +02:00
|
|
|
use OxidEsales\Eshop\Core\Config;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
2020-12-21 10:44:49 +01:00
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseException;
|
2020-10-02 11:59:22 +02:00
|
|
|
use OxidEsales\Eshop\Core\Exception\StandardException;
|
2020-12-21 10:44:49 +01:00
|
|
|
use OxidEsales\Eshop\Core\Language;
|
2020-10-02 11:59:22 +02:00
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
use OxidEsales\Eshop\Core\UtilsView;
|
2020-12-21 10:44:49 +01:00
|
|
|
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateEngineInterface;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInterface;
|
|
|
|
use Psr\Container\ContainerInterface;
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
class d3_oxemail_usermanager extends d3_oxemail_usermanager_parent
|
|
|
|
{
|
2023-01-02 10:58:57 +01:00
|
|
|
use d3usermanager_vars;
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
private $_sModId = 'd3usermanager';
|
2020-10-02 11:59:22 +02:00
|
|
|
protected $_sUserManagerInfoTemplate = 'd3usermanager_info_html.tpl';
|
|
|
|
protected $_sUserManagerInfoPlainTemplate = 'd3usermanager_info_plain.tpl';
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var Manager */
|
2020-10-02 11:59:22 +02:00
|
|
|
public $oUserManager;
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:44:49 +01:00
|
|
|
* d3_oxemail_usermanager constructor.
|
|
|
|
* @throws Exception
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2023-01-02 10:58:57 +01:00
|
|
|
if (d3GetModCfgDIC()->getParameter($this->_DIC_Instance_Id . 'modcfgid') !== $this->_sModId) {
|
|
|
|
throw oxNew(wrongModIdException::class, $this->_sModId);
|
|
|
|
}
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:44:49 +01:00
|
|
|
* @return TemplateEngineInterface
|
|
|
|
*/
|
2021-05-07 11:22:58 +02:00
|
|
|
protected function _d3GetUserManagerTemplateEngine(): TemplateEngineInterface
|
2020-12-21 10:44:49 +01:00
|
|
|
{
|
|
|
|
/** @var TemplateRendererInterface $renderer */
|
|
|
|
$renderer = $this->d3getUserManagerDIContainer()
|
|
|
|
->get(TemplateRendererBridgeInterface::class)
|
|
|
|
->getTemplateRenderer();
|
|
|
|
return $renderer->getTemplateEngine();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $aManagerNotes
|
2020-10-02 11:59:22 +02:00
|
|
|
* @return bool
|
2021-10-04 13:52:09 +02:00
|
|
|
* @throws d3usermanager_smartyException
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3sendUserManagerEmail($aManagerNotes): bool
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
startProfile(__METHOD__);
|
|
|
|
|
2021-10-04 13:52:09 +02:00
|
|
|
$oShop = $this->getShop();
|
2020-12-21 10:44:49 +01:00
|
|
|
|
|
|
|
/** @var Config $config */
|
|
|
|
$config = d3GetModCfgDIC()->get('d3ox.usermanager.'.Config::class);
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
$this->_setMailParams($oShop);
|
2020-12-21 10:44:49 +01:00
|
|
|
$this->setViewData("aNotes", $aManagerNotes);
|
|
|
|
$this->setViewData("shopTemplateDir", $config->getTemplateDir(false));
|
2020-10-02 11:59:22 +02:00
|
|
|
$this->setViewData("oShop", $oShop);
|
|
|
|
|
|
|
|
$this->_processViewArray();
|
|
|
|
|
2021-05-07 11:22:58 +02:00
|
|
|
$templateEngine = $this->_d3GetUserManagerTemplateEngine();
|
2021-03-15 15:17:45 +01:00
|
|
|
foreach ($this->getViewData() as $key => $value) {
|
|
|
|
$templateEngine->addGlobal($key, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_error_handler(
|
|
|
|
[d3GetModCfgDIC()->get(d3usermanager_renderererrorhandler::class), 'd3HandleTemplateEngineErrors']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->d3UMsetBody($templateEngine->render($this->_sUserManagerInfoTemplate));
|
|
|
|
$this->d3UMsetAltBody($templateEngine->render($this->_sUserManagerInfoPlainTemplate));
|
|
|
|
|
|
|
|
restore_error_handler();
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var d3LogInterface $oLog */
|
|
|
|
$oLog = d3GetModCfgDIC()->get('d3.usermanager.log');
|
|
|
|
$oLog->notice(
|
2020-10-02 11:59:22 +02:00
|
|
|
__CLASS__,
|
|
|
|
__FUNCTION__,
|
|
|
|
__LINE__,
|
|
|
|
'send job execution info mail',
|
|
|
|
$this->getBody()
|
|
|
|
);
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var Language $oLang */
|
|
|
|
$oLang = d3GetModCfgDIC()->get('d3ox.usermanager.'.Language::class);
|
2023-01-02 10:58:57 +01:00
|
|
|
$sSubject = $oLang->translateString('D3_USERMANAGER_MAIL_USERSUBJECT', 0);
|
2020-10-02 11:59:22 +02:00
|
|
|
$this->setSubject($sSubject);
|
|
|
|
|
|
|
|
$sFullName = $oShop->__get('oxshops__oxname')->getRawValue();
|
|
|
|
$this->setRecipient($oShop->getFieldData('oxinfoemail'), $sFullName);
|
|
|
|
$this->setReplyTo($oShop->getFieldData('oxinfoemail'), $oShop->__get('oxshops__oxname')->getRawValue());
|
|
|
|
|
|
|
|
$blSuccess = $this->send();
|
|
|
|
|
|
|
|
stopProfile(__METHOD__);
|
|
|
|
|
|
|
|
return $blSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sOxId
|
2020-12-21 10:44:49 +01:00
|
|
|
* @return Item
|
|
|
|
* @throws Exception
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3GetUserManagerUser($sOxId): Item
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
if (strstr($sOxId, '@@')) {
|
|
|
|
$aOxId = explode('@@', $sOxId);
|
|
|
|
$sOxId = $aOxId[0];
|
|
|
|
}
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var $oItem Item */
|
|
|
|
$oItem = d3GetModCfgDIC()->get('d3ox.usermanager.'.Item::class);
|
|
|
|
|
|
|
|
$oItem->load($sOxId);
|
|
|
|
return $oItem;
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sOxId
|
2020-12-21 10:44:49 +01:00
|
|
|
* @return Manager
|
|
|
|
* @throws Exception
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3getUserManager($sOxId): Manager
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var $oManager Manager */
|
|
|
|
$oManager = d3GetModCfgDIC()->get(Manager::class);
|
|
|
|
$oManager->load($sOxId);
|
|
|
|
return $oManager;
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:44:49 +01:00
|
|
|
* @param Manager $oManager
|
2020-10-02 11:59:22 +02:00
|
|
|
* @return bool
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
2020-12-21 10:44:49 +01:00
|
|
|
* @throws DatabaseException
|
2020-10-02 11:59:22 +02:00
|
|
|
* @throws StandardException
|
|
|
|
* @throws d3ShopCompatibilityAdapterException
|
|
|
|
* @throws d3_cfg_mod_exception
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function sendUserManagerMail(Manager $oManager): bool
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2023-01-02 10:58:57 +01:00
|
|
|
$blSuccess = false;
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2023-01-02 10:58:57 +01:00
|
|
|
try {
|
|
|
|
$this->oUserManager = $oManager;
|
|
|
|
$aContent = $this->getUserManagerMailContent( $oManager );
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2023-01-02 10:58:57 +01:00
|
|
|
$oShop = $this->_getShop();
|
|
|
|
$this->d3UMsetBody( $aContent['html'] );
|
|
|
|
$this->d3UMsetAltBody( $aContent['plain'] );
|
|
|
|
$this->d3UMsetSubject( $aContent['subject'] );
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2023-01-02 10:58:57 +01:00
|
|
|
$this->_d3SetUserManagerReplyAddress( $oManager, $oShop );
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2023-01-02 10:58:57 +01:00
|
|
|
$oRemark = $this->_d3SetUserManagerMailRecipients( $oShop );
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2023-01-02 10:58:57 +01:00
|
|
|
$blSuccess = $this->send();
|
|
|
|
|
|
|
|
if ( $blSuccess && $oRemark ) {
|
|
|
|
$oRemark->save();
|
|
|
|
}
|
|
|
|
} catch (emptyMessageException $e) {}
|
2020-10-02 11:59:22 +02:00
|
|
|
|
|
|
|
return $blSuccess;
|
|
|
|
}
|
|
|
|
|
2021-03-15 15:17:45 +01:00
|
|
|
/**
|
|
|
|
* @param $content
|
|
|
|
*
|
|
|
|
* @throws d3usermanager_smartyException
|
|
|
|
*/
|
|
|
|
protected function d3UMsetBody($content)
|
|
|
|
{
|
|
|
|
$this->setBody($content);
|
|
|
|
|
2021-10-04 13:52:09 +02:00
|
|
|
if (strlen($content) && false === (bool) strlen($this->getBody())) {
|
2021-05-07 11:22:58 +02:00
|
|
|
$this->d3UserManagerThrowUnequalContentException();
|
2021-03-15 15:17:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $content
|
|
|
|
*
|
|
|
|
* @throws d3usermanager_smartyException
|
|
|
|
*/
|
|
|
|
protected function d3UMsetAltBody($content)
|
|
|
|
{
|
|
|
|
$this->setAltBody($content);
|
|
|
|
|
2021-10-04 13:52:09 +02:00
|
|
|
if (strlen($content) && false === (bool) strlen($this->getAltBody())) {
|
2021-05-07 11:22:58 +02:00
|
|
|
$this->d3UserManagerThrowUnequalContentException();
|
2021-03-15 15:17:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $content
|
|
|
|
*
|
|
|
|
* @throws d3usermanager_smartyException
|
|
|
|
*/
|
|
|
|
protected function d3UMsetSubject($content)
|
|
|
|
{
|
|
|
|
$this->setSubject($content);
|
|
|
|
|
2021-10-04 13:52:09 +02:00
|
|
|
if (strlen($content) && false === (bool) strlen($this->getSubject())) {
|
2021-05-07 11:22:58 +02:00
|
|
|
$this->d3UserManagerThrowUnequalContentException();
|
2021-03-15 15:17:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 11:59:22 +02:00
|
|
|
/**
|
|
|
|
* @param Shop $oShop
|
|
|
|
*
|
|
|
|
* @return null|Remark
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
protected function _d3SetUserManagerMailRecipients(Shop $oShop): ?Remark
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
$oRemark = null;
|
|
|
|
if ($this->_d3hasUserManagerCustomerRecipient()) {
|
|
|
|
$oRemark = $this->_d3sendUserManagerMailToCustomer($oShop);
|
|
|
|
} elseif ($this->_d3hasUserManagerOwnerRecipient()) {
|
2020-12-21 10:44:49 +01:00
|
|
|
$oRemark = $this->_d3sendUserManagerMailToOwner($oShop);
|
2020-10-02 11:59:22 +02:00
|
|
|
} elseif ($this->_d3hasUserManagerCustomRecipient()) {
|
2020-12-21 10:44:49 +01:00
|
|
|
$oRemark = $this->_d3sendUserManagerMailToCustom();
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $oRemark;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $sVarName
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
|
|
|
protected function _d3getUserManagerMailOption($sVarName)
|
|
|
|
{
|
|
|
|
$aEditedValues = $this->oUserManager->getEditedValues();
|
2021-03-15 15:17:45 +01:00
|
|
|
return false === isset($aEditedValues[$sVarName]) || $aEditedValues[$sVarName] === false || $aEditedValues[$sVarName] === null ?
|
2020-10-02 11:59:22 +02:00
|
|
|
$this->oUserManager->getValue($sVarName) :
|
|
|
|
$aEditedValues[$sVarName];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
|
|
|
protected function _d3hasUserManagerCustomerRecipient()
|
|
|
|
{
|
|
|
|
return $this->_d3getUserManagerMailOption('blSendMailToCustomer');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
|
|
|
protected function _d3hasUserManagerOwnerRecipient()
|
|
|
|
{
|
|
|
|
return $this->_d3getUserManagerMailOption('blSendMailToOwner');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
|
|
|
protected function _d3hasUserManagerCustomRecipient()
|
|
|
|
{
|
|
|
|
return $this->_d3getUserManagerMailOption('blSendMailToCustom');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
|
|
|
protected function _d3getUserManagerCustomRecipientList()
|
|
|
|
{
|
|
|
|
return $this->_d3getUserManagerMailOption('sSendMailToCustomAddress');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:44:49 +01:00
|
|
|
* @param Manager $oManager
|
|
|
|
*
|
2020-10-02 11:59:22 +02:00
|
|
|
* @return array
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
|
|
|
* @throws StandardException
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
* @throws d3ShopCompatibilityAdapterException
|
|
|
|
* @throws d3_cfg_mod_exception
|
2020-12-21 10:44:49 +01:00
|
|
|
* @throws Exception
|
2021-03-15 15:17:45 +01:00
|
|
|
* @throws d3usermanager_templaterendererExceptionInterface
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2023-01-02 10:58:57 +01:00
|
|
|
public function getUserManagerMailContent(Manager $oManager, bool $checkForEmptyContents = true): array
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2021-03-15 15:17:45 +01:00
|
|
|
$aContent = [];
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2023-01-02 10:58:57 +01:00
|
|
|
$aEditedValues = $oManager->getEditedValues();
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2023-01-02 10:58:57 +01:00
|
|
|
if ($this->d3HasUserManagerEditorMailContent($aEditedValues)) {
|
|
|
|
$aContent = $aEditedValues['mail'];
|
2020-10-02 11:59:22 +02:00
|
|
|
|
2023-01-02 10:58:57 +01:00
|
|
|
if ( $aContent['genplain'] ) {
|
|
|
|
$aContent['plain'] = $this->d3generateUserManagerPlainContent( $aContent['html'] );
|
|
|
|
}
|
|
|
|
unset($aContent['genplain']);
|
|
|
|
} elseif ($oManager->getValue('sSendMailFromSource') == 'cms') {
|
|
|
|
$generator = $this->getMessageContentGenerator( $oManager );
|
|
|
|
$generator->setAllowEmptyMessageContent(true);
|
|
|
|
$oContent = $this->d3GetUserManagerContentObject();
|
|
|
|
$oContent->load($oManager->getValue('sSendMailFromContentname'));
|
|
|
|
$aContent['html'] = $generator->generateFromCms($oManager->getValue('sSendMailFromContentname'));
|
|
|
|
$aContent['subject'] = $oContent->getFieldData('oxtitle');
|
|
|
|
$aContent['plain'] = $generator->generateFromCms($oManager->getValue('sSendMailFromContentnamePlain'));
|
|
|
|
} elseif ($oManager->getValue('sSendMailFromSource') == 'template') {
|
|
|
|
$generator = $this->getMessageContentGenerator( $oManager );
|
|
|
|
$generator->setAllowEmptyMessageContent(true);
|
|
|
|
$fromTheme = $oManager->getValue('sSendMailFromTheme');
|
|
|
|
$generator->setTemplateFrom(
|
|
|
|
$fromTheme === 'admin' ? MessageContentGenerator::TEMPLATE_FROM_ADMIN :
|
|
|
|
($fromTheme === 'module' ? MessageContentGenerator::TEMPLATE_FROM_MODULE :
|
|
|
|
MessageContentGenerator::TEMPLATE_FROM_FRONTEND),
|
|
|
|
$oManager->getValue('sSendMailFromModulePath')
|
|
|
|
);
|
|
|
|
$aContent['html'] = $generator->generateFromTpl($oManager->getValue('sSendMailFromTemplatename'));
|
|
|
|
$aContent['subject'] = $generator->generateFromTpl($oManager->getValue('sSendMailFromSubject'));
|
|
|
|
$aContent['plain'] = $generator->generateFromTpl($oManager->getValue('sSendMailFromTemplatenamePlain'));
|
2021-03-15 15:17:45 +01:00
|
|
|
}
|
|
|
|
|
2023-01-02 10:58:57 +01:00
|
|
|
if ($checkForEmptyContents && (
|
|
|
|
(false === is_string($aContent['html']) || false === (bool) strlen($aContent['html'])) &&
|
|
|
|
(false === is_string($aContent['html']) || false === (bool) strlen($aContent['plain'])) &&
|
|
|
|
(false === is_string($aContent['html']) || false === (bool) strlen($aContent['subject'])))
|
|
|
|
) {
|
|
|
|
/** @var emptyMessageException $exc */
|
|
|
|
$exc = oxNew(emptyMessageException::class, 'message content is empty, '.$oManager->getFieldData('oxtitle'));
|
|
|
|
throw $exc;
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $aContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return d3str
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function getD3UserManagerStrObject(): d3str
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2020-12-21 10:44:49 +01:00
|
|
|
/** @var d3str $d3str */
|
|
|
|
$d3str = d3GetModCfgDIC()->get(d3str::class);
|
|
|
|
return $d3str;
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Content
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3GetUserManagerContentObject(): Content
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
/** @var Content $content */
|
|
|
|
$content = d3GetModCfgDIC()->get('d3ox.usermanager.'.Content::class);
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $aEditedValues
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3HasUserManagerEditorMailContent($aEditedValues): bool
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2020-12-21 10:44:49 +01:00
|
|
|
return $this->d3isUserManagerArrayEditorMailContent($aEditedValues) &&
|
2020-10-02 11:59:22 +02:00
|
|
|
$aEditedValues['mail']['subject'] &&
|
|
|
|
$aEditedValues['mail']['html'] &&
|
2020-12-21 10:44:49 +01:00
|
|
|
(
|
|
|
|
$aEditedValues['mail']['genplain'] ||
|
|
|
|
$aEditedValues['mail']['plain']
|
|
|
|
);
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $aEditedValues
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3isUserManagerArrayEditorMailContent($aEditedValues): bool
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2021-03-15 15:17:45 +01:00
|
|
|
return is_array($aEditedValues) && isset($aEditedValues['mail']) && is_array($aEditedValues['mail']);
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
/**
|
|
|
|
* @param $html
|
|
|
|
* @return string
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3generateUserManagerPlainContent($html): string
|
2020-12-21 10:44:49 +01:00
|
|
|
{
|
2023-01-02 10:58:57 +01:00
|
|
|
/** @var Html2TextContext $context */
|
|
|
|
$context = d3GetModCfgDIC()->get(Html2TextContextInterface::class);
|
|
|
|
$context->setMessage($html);
|
2020-12-21 10:44:49 +01:00
|
|
|
|
|
|
|
/** @var Html2Text $html */
|
|
|
|
$html = d3GetModCfgDIC()->get(Html2Text::class);
|
|
|
|
return $html->getText();
|
|
|
|
}
|
|
|
|
|
2020-10-02 11:59:22 +02:00
|
|
|
/**
|
|
|
|
* @return Remark
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3GetUserManagerRemark(): Remark
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
/** @var Remark $remark */
|
|
|
|
$remark = d3GetModCfgDIC()->get('d3ox.usermanager.'.Remark::class);
|
|
|
|
return $remark;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Shop $oShop
|
|
|
|
*
|
|
|
|
* @return Remark
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
protected function _d3sendUserManagerMailToCustomer(Shop $oShop): Remark
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
$sFullName = $this->oUserManager->getCurrentItem()->__get('oxuser__oxfname')->getRawValue() . " " .
|
|
|
|
$this->oUserManager->getCurrentItem()->__get('oxuser__oxlname')->getRawValue();
|
|
|
|
$this->setRecipient($this->oUserManager->getCurrentItem()->getFieldData('oxusername'), $sFullName);
|
|
|
|
|
|
|
|
if ($this->_d3hasUserManagerOwnerRecipient()) {
|
|
|
|
$this->addBCC($oShop->getFieldData('oxinfoemail'), $oShop->__get('oxshops__oxname')->getRawValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->_d3HasUserManagerCustomMailAddresses()) {
|
|
|
|
foreach ($this->_d3getUserManagerCustomMailAddressList() as $sMailAdr) {
|
|
|
|
$this->addBCC(trim($sMailAdr), trim($sMailAdr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-21 10:44:49 +01:00
|
|
|
return $this->d3generateUserManagerRemark();
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Shop $oShop
|
2020-12-21 10:44:49 +01:00
|
|
|
*
|
|
|
|
* @return Remark
|
2020-10-02 11:59:22 +02:00
|
|
|
* @throws d3ParameterNotFoundException
|
2020-12-21 10:44:49 +01:00
|
|
|
* @throws Exception
|
2020-10-02 11:59:22 +02:00
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
protected function _d3sendUserManagerMailToOwner(Shop $oShop): Remark
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
$sFullName = $oShop->__get('oxshops__oxname')->getRawValue();
|
|
|
|
$this->setRecipient($oShop->getFieldData('oxinfoemail'), $sFullName);
|
|
|
|
|
|
|
|
if ($this->_d3HasUserManagerCustomMailAddresses()) {
|
|
|
|
foreach ($this->_d3getUserManagerCustomMailAddressList() as $sMailAdr) {
|
|
|
|
$this->addBCC(trim($sMailAdr), trim($sMailAdr));
|
|
|
|
}
|
|
|
|
}
|
2020-12-21 10:44:49 +01:00
|
|
|
|
|
|
|
return $this->d3generateUserManagerRemark();
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
protected function _d3sendUserManagerMailToCustom(): Remark
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
if ($this->_d3HasUserManagerCustomMailAddresses()) {
|
|
|
|
foreach ($this->_d3getUserManagerCustomMailAddressList() as $sMailAdr) {
|
|
|
|
$this->setRecipient(trim($sMailAdr), trim($sMailAdr));
|
|
|
|
}
|
|
|
|
}
|
2020-12-21 10:44:49 +01:00
|
|
|
|
|
|
|
return $this->d3generateUserManagerRemark();
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
protected function _d3getUserManagerCustomMailAddressList(): array
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
$aMailAddressList = array();
|
|
|
|
|
|
|
|
foreach (explode(';', $this->_d3getUserManagerCustomRecipientList()) as $sAddress) {
|
|
|
|
if (strlen(trim($sAddress))) {
|
2020-12-21 10:44:49 +01:00
|
|
|
$aMailAddressList[] = trim($sAddress);
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $aMailAddressList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function _d3HasUserManagerCustomMailAddresses(): bool
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
|
|
|
return $this->_d3hasUserManagerCustomRecipient() && $this->_d3getUserManagerCustomRecipientList();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 10:44:49 +01:00
|
|
|
* @param Manager $oManager
|
2020-10-02 11:59:22 +02:00
|
|
|
* @param Shop $oShop
|
|
|
|
*/
|
2020-12-21 10:44:49 +01:00
|
|
|
protected function _d3SetUserManagerReplyAddress(Manager $oManager, Shop $oShop)
|
2020-10-02 11:59:22 +02:00
|
|
|
{
|
2021-03-15 15:17:45 +01:00
|
|
|
if (strlen(trim((string) $oManager->getValue('sSendMailReplyAddress')))) {
|
2020-12-21 10:44:49 +01:00
|
|
|
$this->setFrom(trim($oManager->getValue('sSendMailReplyAddress')));
|
2020-10-02 11:59:22 +02:00
|
|
|
$this->setReplyTo(
|
2021-03-15 15:17:45 +01:00
|
|
|
trim((string) $oManager->getValue('sSendMailReplyAddress')),
|
2020-10-02 11:59:22 +02:00
|
|
|
$oShop->__get('oxshops__oxname')->getRawValue()
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->setReplyTo($oShop->getFieldData('oxinfoemail'), $oShop->__get('oxshops__oxname')->getRawValue());
|
|
|
|
}
|
|
|
|
}
|
2020-12-21 10:44:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* add user history
|
|
|
|
* @return Remark
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3generateUserManagerRemark(): Remark
|
2020-12-21 10:44:49 +01:00
|
|
|
{
|
|
|
|
$oRemark = $this->d3GetUserManagerRemark();
|
|
|
|
$aRemarkContent = array(
|
|
|
|
'oxtext' => $this->d3GetUserManagerRemarkText(),
|
|
|
|
'oxparentid' => $this->oUserManager->getCurrentItem()->getId(),
|
|
|
|
'oxtype' => 'd3um',
|
|
|
|
);
|
|
|
|
$oRemark->assign( $aRemarkContent );
|
|
|
|
|
|
|
|
return $oRemark;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3GetUserManagerRemarkText(): string
|
2020-12-21 10:44:49 +01:00
|
|
|
{
|
|
|
|
return implode(
|
|
|
|
PHP_EOL.'---'.PHP_EOL,
|
|
|
|
[
|
|
|
|
'Recipients:',
|
|
|
|
implode(', ', array_keys($this->getAllRecipientAddresses())),
|
|
|
|
'HTML:',
|
|
|
|
$this->getBody(),
|
|
|
|
'Plain',
|
|
|
|
$this->getAltBody()
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ContainerInterface
|
|
|
|
*/
|
2021-03-15 15:17:45 +01:00
|
|
|
public function d3getUserManagerDIContainer(): ContainerInterface
|
2020-12-21 10:44:49 +01:00
|
|
|
{
|
|
|
|
return ContainerFactory::getInstance()->getContainer();
|
|
|
|
}
|
2021-03-15 15:17:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws d3usermanager_smartyException
|
|
|
|
*/
|
2021-05-07 11:22:58 +02:00
|
|
|
protected function d3UserManagerThrowUnequalContentException() : void
|
2021-03-15 15:17:45 +01:00
|
|
|
{
|
2023-01-02 10:58:57 +01:00
|
|
|
throw oxNew(d3usermanager_smartyException::class, 'empty mail content, possible file encoding error');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Manager $oManager
|
|
|
|
*
|
|
|
|
* @return MessageContentGenerator|mixed
|
|
|
|
* @throws d3ParameterNotFoundException
|
|
|
|
*/
|
|
|
|
protected function getMessageContentGenerator( Manager $oManager )
|
|
|
|
{
|
|
|
|
return oxNew( MessageContentGenerator::class, $oManager, $oManager->getCurrentItem() );
|
2021-03-15 15:17:45 +01:00
|
|
|
}
|
2020-10-02 11:59:22 +02:00
|
|
|
}
|