devhelper/src/Modules/Core/d3_dev_oxemail.php

312 lines
9.0 KiB
PHP
Raw Normal View History

<?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.
*
* http://www.shopmodule.com
*
* @copyright © Data Development, Thomas Dartsch
2018-02-23 12:30:57 +01:00
* @author Data Development - Daniel Seifert <info@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\Devhelper\Modules\Core;
use D3\Devhelper\Modules\Application\Model as ModuleModel;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry;
2020-11-11 23:59:40 +01:00
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
2020-11-11 22:29:10 +01:00
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInterface;
class d3_dev_oxemail extends d3_dev_oxemail_parent
{
/**
2018-02-23 12:30:57 +01:00
* @param ModuleModel\d3_dev_oxorder $oOrder
* @param $sType
* @return mixed|string
*/
public function d3GetOrderMailContent($oOrder, $sType)
{
2018-02-23 12:30:57 +01:00
if (Registry::getConfig()->getActiveShop()->isProductiveMode()) {
return '';
}
switch (strtolower($sType)) {
case 'owner_html':
$sTpl = $this->_sOrderOwnerTemplate;
break;
case 'owner_plain':
$sTpl = $this->_sOrderOwnerPlainTemplate;
break;
case 'user_plain':
$sTpl = $this->_sOrderUserPlainTemplate;
break;
case 'user_html':
default:
$sTpl = $this->_sOrderUserTemplate;
}
2020-11-11 22:29:10 +01:00
$myConfig = Registry::getConfig();
$oShop = $this->_getShop();
// cleanup
$this->_clearMailer();
// add user defined stuff if there is any
$oOrder = $this->_addUserInfoOrderEMail($oOrder);
$oUser = $oOrder->getOrderUser();
$this->setUser($oUser);
// send confirmation to shop owner
// send not pretending from order user, as different email domain rise spam filters
2018-02-23 12:30:57 +01:00
$this->setFrom($oShop->getFieldData('oxowneremail'));
$oLang = Registry::getLang();
$iOrderLang = $oLang->getObjectTplLanguage();
// if running shop language is different from admin lang. set in config
// we have to load shop in config language
if ($oShop->getLanguage() != $iOrderLang) {
$oShop = $this->_getShop($iOrderLang);
}
$this->setSmtp($oShop);
// create messages
$this->setViewData("order", $oOrder);
// Process view data array through oxoutput processor
$this->_processViewArray();
2020-11-11 23:59:40 +01:00
$renderer = $this->getRenderer();
return $renderer->renderTemplate($myConfig->getTemplatePath($sTpl, false), $this->getViewData());
2020-11-11 22:29:10 +01:00
}
/**
* from OXID 6.2, required because private in Email class
* Templating instance getter
*
* @return TemplateRendererInterface
*/
protected function getRenderer()
{
2020-11-11 23:59:40 +01:00
$bridge = ContainerFactory::getInstance()->getContainer()
2020-11-11 22:29:10 +01:00
->get(TemplateRendererBridgeInterface::class);
$bridge->setEngine($this->_getSmarty());
return $bridge->getTemplateRenderer();
}
/**
2018-02-23 12:30:57 +01:00
* @param ModuleModel\d3_dev_d3inquiry $oInquiry
*
* @param $sType
*
* @return mixed|string
*/
public function d3GetInquiryMailContent($oInquiry, $sType )
{
2018-02-23 12:30:57 +01:00
if (Registry::getConfig()->getActiveShop()->isProductiveMode()) {
return '';
}
switch (strtolower($sType)) {
case 'owner_html':
$sTpl = $this->_sInquiryOwnerTemplate;
break;
case 'owner_plain':
$sTpl = $this->_sInquiryOwnerPlainTemplate;
break;
case 'user_plain':
$sTpl = $this->_sInquiryUserPlainTemplate;
break;
case 'user_html':
default:
$sTpl = $this->_sInquiryUserTemplate;
}
2020-11-11 22:29:10 +01:00
$myConfig = Registry::getConfig();
$oShop = $this->_getShop();
// cleanup
$this->_clearMailer();
// add user defined stuff if there is any
$oInquiry = $this->_addUserInfoOrderEMail($oInquiry);
$oUser = $oInquiry->getInquiryUser();
$this->setUser($oUser);
// send confirmation to shop owner
// send not pretending from order user, as different email domain rise spam filters
2018-02-23 12:30:57 +01:00
$this->setFrom($oShop->getFieldData('oxowneremail'));
$oLang = Registry::getLang();
$iOrderLang = $oLang->getObjectTplLanguage();
// if running shop language is different from admin lang. set in config
// we have to load shop in config language
if ($oShop->getLanguage() != $iOrderLang) {
$oShop = $this->_getShop($iOrderLang);
}
$this->setSmtp($oShop);
// create messages
$this->setViewData("inquiry", $oInquiry);
// Process view data array through oxoutput processor
$this->_processViewArray();
2020-11-11 23:59:40 +01:00
$renderer = $this->getRenderer();
return $renderer->renderTemplate($myConfig->getTemplatePath($sTpl, false), $this->getViewData());
}
2020-11-11 22:29:10 +01:00
2020-11-11 23:59:40 +01:00
/**
* @param $aRecInfo
* @param array $aCc
* @return array
*/
public function d3ChangeRecipient($aRecInfo, array $aCc): array
{
if (($sNewRecipient = $this->getNewRecipient($aRecInfo[0]))
&& $sNewRecipient != $aRecInfo[0]
) {
$aRecInfo[1] = $aRecInfo[1] . " (" . $aRecInfo[0] . ")";
$aRecInfo[0] = $sNewRecipient;
$aCc[] = $aRecInfo;
} elseif (($sNewRecipient = $this->getNewRecipient($aRecInfo[0]))) {
$aCc[] = $aRecInfo;
}
return $aCc;
}
/**
* @return bool
* @throws StandardException
*/
protected function _sendMail()
{
2018-02-23 12:30:57 +01:00
if (Registry::getConfig()->getActiveShop()->isProductiveMode()) {
return parent::_sendMail();
}
$this->d3clearRecipients();
$this->d3clearReplies();
$this->d3clearReplyTo();
$this->d3clearCC();
$this->d3clearBCC();
if (count($this->getRecipient())) {
return parent::_sendMail();
}
return true;
}
2020-11-11 23:59:40 +01:00
/**
* @return bool
* @throws StandardException
*/
protected function sendMail()
{
if (Registry::getConfig()->getActiveShop()->isProductiveMode()) {
return parent::sendMail();
}
$this->d3clearRecipients();
$this->d3clearReplies();
$this->d3clearReplyTo();
$this->d3clearCC();
$this->d3clearBCC();
if (count($this->getRecipient())) {
return parent::sendMail();
}
return true;
}
public function d3clearRecipients()
{
$aRecipients = array();
if (is_array($this->_aRecipients) && count($this->_aRecipients)) {
foreach ($this->_aRecipients as $aRecInfo) {
2020-11-11 23:59:40 +01:00
$aRecipients = $this->d3ChangeRecipient($aRecInfo, $aRecipients);
}
}
$this->_aRecipients = $aRecipients;
}
public function d3clearReplies()
{
$aRecipients = array();
if (is_array($this->_aReplies) && count($this->_aReplies)) {
foreach ($this->_aReplies as $aRecInfo) {
2020-11-11 23:59:40 +01:00
$aRecipients = $this->d3ChangeRecipient($aRecInfo, $aRecipients);
}
}
$this->_aReplies = $aRecipients;
}
public function d3clearReplyTo()
{
$aRecipients = array();
if (is_array($this->ReplyTo) && count($this->ReplyTo)) {
foreach ($this->ReplyTo as $aRecInfo) {
2020-11-11 23:59:40 +01:00
$aRecipients = $this->d3ChangeRecipient($aRecInfo, $aRecipients);
}
}
$this->ReplyTo = $aRecipients;
}
public function d3clearCC()
{
$aCc = array();
if (is_array($this->cc) && count($this->cc)) {
foreach ($this->cc as $aRecInfo) {
2020-11-11 23:59:40 +01:00
$aCc = $this->d3ChangeRecipient($aRecInfo, $aCc);
}
}
$this->cc = $aCc;
}
public function d3clearBCC()
{
$aCc = array();
if (is_array($this->bcc) && count($this->bcc)) {
foreach ($this->bcc as $aRecInfo) {
2020-11-11 23:59:40 +01:00
$aCc = $this->d3ChangeRecipient($aRecInfo, $aCc);
}
}
$this->bcc = $aCc;
}
/**
* @param $sMailAddress
*
* @return bool|string
*/
public function getNewRecipient($sMailAddress)
{
2020-11-11 22:29:10 +01:00
if (Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_BLOCKMAIL)) {
return false;
2020-11-11 22:29:10 +01:00
} elseif (Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_REDIRECTMAIL)) {
return trim(Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_REDIRECTMAIL));
}
return $sMailAddress;
}
}