OXID eShop CE  4.10.8
 All Classes Namespaces Files Functions Variables Pages
oxemail.php
Go to the documentation of this file.
1 <?php
5 require oxRegistry::getConfig()->getConfigParam('sCoreDir') . "/phpmailer/class.phpmailer.php";
6 require oxRegistry::getConfig()->getConfigParam('sCoreDir') . "/phpmailer/class.smtp.php";
7 
8 
14 class oxEmail extends PHPMailer
15 {
16 
22  public $SMTP_PORT = 25;
23 
29  protected $_sForgotPwdTemplate = "email/html/forgotpwd.tpl";
30 
36  protected $_sForgotPwdTemplatePlain = "email/plain/forgotpwd.tpl";
37 
43  protected $_sNewsletterOptInTemplate = "email/html/newsletteroptin.tpl";
44 
50  protected $_sNewsletterOptInTemplatePlain = "email/plain/newsletteroptin.tpl";
51 
57  protected $_sSuggestTemplate = "email/html/suggest.tpl";
58 
64  protected $_sSuggestTemplatePlain = "email/plain/suggest.tpl";
65 
71  protected $_sInviteTemplate = "email/html/invite.tpl";
72 
78  protected $_sInviteTemplatePlain = "email/plain/invite.tpl";
79 
85  protected $_sSenedNowTemplate = "email/html/ordershipped.tpl";
86 
92  protected $_sSenedNowTemplatePlain = "email/plain/ordershipped.tpl";
93 
99  protected $_sSendDownloadsTemplate = "email/html/senddownloadlinks.tpl";
100 
106  protected $_sSendDownloadsTemplatePlain = "email/plain/senddownloadlinks.tpl";
107 
113  protected $_sWishListTemplate = "email/html/wishlist.tpl";
114 
120  protected $_sWishListTemplatePlain = "email/plain/wishlist.tpl";
121 
127  protected $_sRegisterTemplate = "email/html/register.tpl";
128 
134  protected $_sRegisterTemplatePlain = "email/plain/register.tpl";
135 
141  protected $_sReminderMailTemplate = "email/html/owner_reminder.tpl";
142 
148  protected $_sOrderUserTemplate = "email/html/order_cust.tpl";
149 
155  protected $_sOrderUserPlainTemplate = "email/plain/order_cust.tpl";
156 
162  protected $_sOrderOwnerTemplate = "email/html/order_owner.tpl";
163 
169  protected $_sOrderOwnerPlainTemplate = "email/plain/order_owner.tpl";
170 
171  // #586A - additional templates for more customizable subjects
172 
178  protected $_sOrderUserSubjectTemplate = "email/html/order_cust_subj.tpl";
179 
185  protected $_sOrderOwnerSubjectTemplate = "email/html/order_owner_subj.tpl";
186 
192  protected $_sOwnerPricealarmTemplate = "email/html/pricealarm_owner.tpl";
193 
199  protected $_sPricealamrCustomerTemplate = "email_pricealarm_customer.tpl";
200 
206  protected $_aShops = array();
207 
213  protected $_blInlineImgEmail = null;
214 
220  protected $_aRecipients = array();
221 
227  protected $_aReplies = array();
228 
234  protected $_aAttachments = array();
235 
241  protected $_oSmarty = null;
242 
248  protected $_aViewData = array();
249 
255  protected $_oShop = null;
256 
262  protected $_sCharSet = null;
263 
267  public function __construct()
268  {
269  //enabling exception handling in phpmailer class
270  parent::__construct(true);
271 
272  $myConfig = $this->getConfig();
273 
274  $this->_setMailerPluginDir();
275  $this->setSmtp();
276 
277  $this->setUseInlineImages($myConfig->getConfigParam('blInlineImgEmail'));
278  $this->setMailWordWrap(100);
279 
280  $this->isHtml(true);
281  $this->setLanguage("en", $myConfig->getConfigParam('sShopDir') . "/core/phpmailer/language/");
282 
283  $this->_getSmarty();
284  }
285 
297  public function __call($sMethod, $aArgs)
298  {
299  if (defined('OXID_PHP_UNIT')) {
300  if (substr($sMethod, 0, 4) == "UNIT") {
301  $sMethod = str_replace("UNIT", "_", $sMethod);
302  }
303  if (method_exists($this, $sMethod)) {
304  return call_user_func_array(array(& $this, $sMethod), $aArgs);
305  }
306  }
307 
308  throw new oxSystemComponentException("Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")" . PHP_EOL);
309  }
310 
316  public function getConfig()
317  {
318  if ($this->_oConfig == null) {
319  $this->_oConfig = oxRegistry::getConfig();
320  }
321 
322  return $this->_oConfig;
323  }
324 
330  public function setConfig($oConfig)
331  {
332  $this->_oConfig = $oConfig;
333  }
334 
335 
341  protected function _getSmarty()
342  {
343  if ($this->_oSmarty === null) {
344  $this->_oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
345  }
346 
347  //setting default view
348  $this->_oSmarty->assign("oEmailView", $this);
349 
350  return $this->_oSmarty;
351  }
352 
360  public function send()
361  {
362  // if no recipients found, skipping sending
363  if (count($this->getRecipient()) < 1) {
364  return false;
365  }
366 
367  $myConfig = $this->getConfig();
368  $this->setCharSet();
369 
370  if ($this->_getUseInlineImages()) {
371  $this->_includeImages(
372  $myConfig->getImageDir(), $myConfig->getImageUrl(false, false), $myConfig->getPictureUrl(null, false),
373  $myConfig->getImageDir(), $myConfig->getPictureDir(false)
374  );
375  }
376 
377  $this->_makeOutputProcessing();
378 
379  // try to send mail via SMTP
380  if ($this->getMailer() == 'smtp') {
381  $blRet = $this->_sendMail();
382 
383  // if sending failed, try to send via mail()
384  if (!$blRet) {
385  // failed sending via SMTP, sending notification to shop owner
386  $this->_sendMailErrorMsg();
387 
388  // trying to send using standard mailer
389  $this->setMailer('mail');
390  $blRet = $this->_sendMail();
391  }
392  } else {
393  // sending mail via mail()
394  $this->setMailer('mail');
395  $blRet = $this->_sendMail();
396  }
397 
398  if (!$blRet) {
399  // failed sending, giving up, trying to send notification to shop owner
400  $this->_sendMailErrorMsg();
401  }
402 
403  return $blRet;
404  }
405 
414  protected function _setSmtpProtocol($sUrl)
415  {
416  $sProtocol = '';
417  $sSmtpHost = $sUrl;
418  $aMatch = array();
419  if (getStr()->preg_match('@^([0-9a-z]+://)?(.*)$@i', $sUrl, $aMatch)) {
420  if ($aMatch[1]) {
421  if (($aMatch[1] == 'ssl://') || ($aMatch[1] == 'tls://')) {
422  $this->set("SMTPSecure", substr($aMatch[1], 0, 3));
423  } else {
424  $sProtocol = $aMatch[1];
425  }
426  }
427  $sSmtpHost = $aMatch[2];
428  }
429 
430  return $sProtocol . $sSmtpHost;
431  }
432 
440  public function setSmtp($oShop = null)
441  {
442  $myConfig = $this->getConfig();
443  $oShop = ($oShop) ? $oShop : $this->_getShop();
444 
445  $sSmtpUrl = $this->_setSmtpProtocol($oShop->oxshops__oxsmtp->value);
446 
447  if (!$this->_isValidSmtpHost($sSmtpUrl)) {
448  $this->setMailer("mail");
449 
450  return;
451  }
452 
453  $this->setHost($sSmtpUrl);
454  $this->setMailer("smtp");
455 
456  if ($oShop->oxshops__oxsmtpuser->value) {
457  $this->_setSmtpAuthInfo($oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value);
458  }
459 
460  if ($myConfig->getConfigParam('iDebug') == 6) {
461  $this->_setSmtpDebug(true);
462  }
463  }
464 
472  protected function _isValidSmtpHost($sSmtpHost)
473  {
474  $blIsSmtp = false;
475  if ($sSmtpHost) {
476  $sSmtpPort = $this->SMTP_PORT;
477  $aMatch = array();
478  if (getStr()->preg_match('@^(.*?)(:([0-9]+))?$@i', $sSmtpHost, $aMatch)) {
479  $sSmtpHost = $aMatch[1];
480  $sSmtpPort = (int) $aMatch[3];
481  if (!$sSmtpPort) {
482  $sSmtpPort = $this->SMTP_PORT;
483  }
484  }
485  if ($blIsSmtp = (bool) ($rHandle = @fsockopen($sSmtpHost, $sSmtpPort, $iErrNo, $sErrStr, 30))) {
486  // closing connection ..
487  fclose($rHandle);
488  }
489  }
490 
491  return $blIsSmtp;
492  }
493 
503  public function sendOrderEmailToUser($oOrder, $sSubject = null)
504  {
505  $myConfig = $this->getConfig();
506 
507  // add user defined stuff if there is any
508  $oOrder = $this->_addUserInfoOrderEMail($oOrder);
509 
510  $oShop = $this->_getShop();
511  $this->_setMailParams($oShop);
512 
513  $oUser = $oOrder->getOrderUser();
514  $this->setUser($oUser);
515 
516  // create messages
517  $oSmarty = $this->_getSmarty();
518  $this->setViewData("order", $oOrder);
519 
520  if ($myConfig->getConfigParam("bl_perfLoadReviews")) {
521  $this->setViewData("blShowReviewLink", true);
522  }
523 
524  // Process view data array through oxOutput processor
525  $this->_processViewArray();
526 
527  $this->setBody($oSmarty->fetch($this->_sOrderUserTemplate));
528  $this->setAltBody($oSmarty->fetch($this->_sOrderUserPlainTemplate));
529 
530  // #586A
531  if ($sSubject === null) {
532  if ($oSmarty->template_exists($this->_sOrderUserSubjectTemplate)) {
533  $sSubject = $oSmarty->fetch($this->_sOrderUserSubjectTemplate);
534  } else {
535  $sSubject = $oShop->oxshops__oxordersubject->getRawValue() . " (#" . $oOrder->oxorder__oxordernr->value . ")";
536  }
537  }
538 
539  $this->setSubject($sSubject);
540 
541  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
542 
543  $this->setRecipient($oUser->oxuser__oxusername->value, $sFullName);
544  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
545 
546  $blSuccess = $this->send();
547 
548  return $blSuccess;
549  }
550 
560  public function sendOrderEmailToOwner($oOrder, $sSubject = null)
561  {
562  $myConfig = $this->getConfig();
563 
564  $oShop = $this->_getShop();
565 
566  // cleanup
567  $this->_clearMailer();
568 
569  // add user defined stuff if there is any
570  $oOrder = $this->_addUserInfoOrderEMail($oOrder);
571 
572  $oUser = $oOrder->getOrderUser();
573  $this->setUser($oUser);
574 
575  // send confirmation to shop owner
576  // send not pretending from order user, as different email domain rise spam filters
577  $this->setFrom($oShop->oxshops__oxowneremail->value);
578 
579  $oLang = oxRegistry::getLang();
580  $iOrderLang = $oLang->getObjectTplLanguage();
581 
582  // if running shop language is different from admin lang. set in config
583  // we have to load shop in config language
584  if ($oShop->getLanguage() != $iOrderLang) {
585  $oShop = $this->_getShop($iOrderLang);
586  }
587 
588  $this->setSmtp($oShop);
589 
590  // create messages
591  $oSmarty = $this->_getSmarty();
592  $this->setViewData("order", $oOrder);
593 
594  // Process view data array through oxoutput processor
595  $this->_processViewArray();
596 
597  $this->setBody($oSmarty->fetch($myConfig->getTemplatePath($this->_sOrderOwnerTemplate, false)));
598  $this->setAltBody($oSmarty->fetch($myConfig->getTemplatePath($this->_sOrderOwnerPlainTemplate, false)));
599 
600  //Sets subject to email
601  // #586A
602  if ($sSubject === null) {
603  if ($oSmarty->template_exists($this->_sOrderOwnerSubjectTemplate)) {
604  $sSubject = $oSmarty->fetch($this->_sOrderOwnerSubjectTemplate);
605  } else {
606  $sSubject = $oShop->oxshops__oxordersubject->getRawValue() . " (#" . $oOrder->oxorder__oxordernr->value . ")";
607  }
608  }
609 
610  $this->setSubject($sSubject);
611  $this->setRecipient($oShop->oxshops__oxowneremail->value, $oLang->translateString("order"));
612 
613  if ($oUser->oxuser__oxusername->value != "admin") {
614  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
615  $this->setReplyTo($oUser->oxuser__oxusername->value, $sFullName);
616  }
617 
618  $blSuccess = $this->send();
619 
620  // add user history
621  $oRemark = oxNew("oxremark");
622  $oRemark->oxremark__oxtext = new oxField($this->getAltBody(), oxField::T_RAW);
623  $oRemark->oxremark__oxparentid = new oxField($oUser->getId(), oxField::T_RAW);
624  $oRemark->oxremark__oxtype = new oxField("o", oxField::T_RAW);
625  $oRemark->save();
626 
627 
628  if ($myConfig->getConfigParam('iDebug') == 6) {
629  oxRegistry::getUtils()->showMessageAndExit("");
630  }
631 
632  return $blSuccess;
633  }
634 
644  public function sendRegisterConfirmEmail($oUser, $sSubject = null)
645  {
646  // setting content ident
647 
648  $this->setViewData("contentident", "oxregisteraltemail");
649  $this->setViewData("contentplainident", "oxregisterplainaltemail");
650 
651  // sending email
652  return $this->sendRegisterEmail($oUser, $sSubject);
653  }
654 
664  public function sendRegisterEmail($oUser, $sSubject = null)
665  {
666  // add user defined stuff if there is any
667  $oUser = $this->_addUserRegisterEmail($oUser);
668 
669  // shop info
670  $oShop = $this->_getShop();
671 
672  //set mail params (from, fromName, smtp )
673  $this->_setMailParams($oShop);
674 
675  // create messages
676  $oSmarty = $this->_getSmarty();
677  $this->setUser($oUser);
678 
679  // Process view data array through oxOutput processor
680  $this->_processViewArray();
681 
682  $this->setBody($oSmarty->fetch($this->_sRegisterTemplate));
683  $this->setAltBody($oSmarty->fetch($this->_sRegisterTemplatePlain));
684 
685  $this->setSubject(($sSubject !== null) ? $sSubject : $oShop->oxshops__oxregistersubject->getRawValue());
686 
687  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
688 
689  $this->setRecipient($oUser->oxuser__oxusername->value, $sFullName);
690  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
691 
692  return $this->send();
693  }
694 
704  public function sendForgotPwdEmail($sEmailAddress, $sSubject = null)
705  {
706  $result = false;
707 
708  $oShop = $this->_addForgotPwdEmail($this->_getShop());
709 
710  $sOxId = $this->_getUserIdByUserName($sEmailAddress, $oShop->getId());
711  $oUser = oxNew('oxuser');
712  if ($sOxId && $oUser->load($sOxId)) {
713  // create messages
714  $oSmarty = $this->_getSmarty();
715  $this->setUser($oUser);
716  $this->_processViewArray();
717 
718  $this->_setMailParams($oShop);
719  $this->setBody($oSmarty->fetch($this->_sForgotPwdTemplate));
720  $this->setAltBody($oSmarty->fetch($this->_sForgotPwdTemplatePlain));
721  $this->setSubject(($sSubject !== null) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->getRawValue());
722 
723  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
724  $sRecipientAddress = $oUser->oxuser__oxusername->getRawValue();
725 
726  $this->setRecipient($sRecipientAddress, $sFullName);
727  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
728 
729  if (!$this->send()) {
730  $result = -1; // failed to send
731  } else {
732  $result = true; // success
733  }
734  }
735 
736  return $result;
737  }
738 
749  public function sendContactMail($sEmailAddress = null, $sSubject = null, $sMessage = null)
750  {
751 
752  // shop info
753  $oShop = $this->_getShop();
754 
755  //set mail params (from, fromName, smtp)
756  $this->_setMailParams($oShop);
757 
758  $this->setBody($sMessage);
759  $this->setSubject($sSubject);
760 
761  $this->setRecipient($oShop->oxshops__oxinfoemail->value, "");
762  $this->setFrom($oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue());
763  $this->setReplyTo($sEmailAddress, "");
764 
765  return $this->send();
766  }
767 
777  public function sendNewsletterDbOptInMail($oUser, $sSubject = null)
778  {
779  $oLang = oxRegistry::getLang();
780 
781  // add user defined stuff if there is any
782  $oUser = $this->_addNewsletterDbOptInMail($oUser);
783 
784  // shop info
785  $oShop = $this->_getShop();
786 
787  //set mail params (from, fromName, smtp)
788  $this->_setMailParams($oShop);
789 
790  // create messages
791  $oSmarty = $this->_getSmarty();
792  $sConfirmCode = md5($oUser->oxuser__oxusername->value . $oUser->oxuser__oxpasssalt->value);
793  $this->setViewData("subscribeLink", $this->_getNewsSubsLink($oUser->oxuser__oxid->value, $sConfirmCode));
794  $this->setUser($oUser);
795 
796  // Process view data array through oxOutput processor
797  $this->_processViewArray();
798 
799  $this->setBody($oSmarty->fetch($this->_sNewsletterOptInTemplate));
800  $this->setAltBody($oSmarty->fetch($this->_sNewsletterOptInTemplatePlain));
801  $this->setSubject(($sSubject !== null) ? $sSubject : oxRegistry::getLang()->translateString("NEWSLETTER") . " " . $oShop->oxshops__oxname->getRawValue());
802 
803  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
804 
805  $this->setRecipient($oUser->oxuser__oxusername->value, $sFullName);
806  $this->setFrom($oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue());
807  $this->setReplyTo($oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue());
808 
809  return $this->send();
810  }
811 
820  protected function _getNewsSubsLink($sId, $sConfirmCode = null)
821  {
822  $myConfig = $this->getConfig();
823  $iActShopLang = $myConfig->getActiveShop()->getLanguage();
824 
825  $sUrl = $myConfig->getShopHomeURL() . 'cl=newsletter&amp;fnc=addme&amp;uid=' . $sId;
826  $sUrl .= '&amp;lang=' . $iActShopLang;
827  $sUrl .= ($sConfirmCode) ? '&amp;confirm=' . $sConfirmCode : "";
828 
829  return $sUrl;
830  }
831 
842  public function sendNewsletterMail($oNewsLetter, $oUser, $sSubject = null)
843  {
844  // shop info
845  $oShop = $this->_getShop();
846 
847  //set mail params (from, fromName, smtp)
848  $this->_setMailParams($oShop);
849 
850  $sBody = $oNewsLetter->getHtmlText();
851 
852  if (!empty($sBody)) {
853  $this->setBody($sBody);
854  $this->setAltBody($oNewsLetter->getPlainText());
855  } else {
856  $this->isHtml(false);
857  $this->setBody($oNewsLetter->getPlainText());
858  }
859 
860  $this->setSubject(($sSubject !== null) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->getRawValue());
861 
862  $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
863  $this->setRecipient($oUser->oxuser__oxusername->value, $sFullName);
864  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
865 
866  return $this->send();
867  }
868 
869 
879  public function sendSuggestMail($oParams, $oProduct)
880  {
881  $myConfig = $this->getConfig();
882 
883  //sets language of shop
884  $iCurrLang = $myConfig->getActiveShop()->getLanguage();
885 
886  // shop info
887  $oShop = $this->_getShop($iCurrLang);
888 
889  //sets language to article
890  if ($oProduct->getLanguage() != $iCurrLang) {
891  $oProduct->setLanguage($iCurrLang);
892  $oProduct->load($oProduct->getId());
893  }
894 
895  // mailer stuff
896  // send not pretending from suggesting user, as different email domain rise spam filters
897  $this->setFrom($oShop->oxshops__oxinfoemail->value);
898  $this->setSMTP();
899 
900  // create messages
901  $oSmarty = $this->_getSmarty();
902  $this->setViewData("product", $oProduct);
903  $this->setUser($oParams);
904 
905  $sArticleUrl = $oProduct->getLink();
906 
907  //setting recommended user id
908  if ($myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser()) {
909  $sArticleUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator($sArticleUrl);
910  $sArticleUrl .= "su=" . $oActiveUser->getId();
911  }
912 
913  $this->setViewData("sArticleUrl", $sArticleUrl);
914 
915  // Process view data array through oxOutput processor
916  $this->_processViewArray();
917 
918  $this->setBody($oSmarty->fetch($this->_sSuggestTemplate));
919  $this->setAltBody($oSmarty->fetch($this->_sSuggestTemplatePlain));
920  $this->setSubject($oParams->send_subject);
921 
922  $this->setRecipient($oParams->rec_email, $oParams->rec_name);
923  $this->setReplyTo($oParams->send_email, $oParams->send_name);
924 
925  return $this->send();
926  }
927 
936  public function sendInviteMail($oParams)
937  {
938  $myConfig = $this->getConfig();
939 
940  //sets language of shop
941  $iCurrLang = $myConfig->getActiveShop()->getLanguage();
942 
943  // shop info
944  $oShop = $this->_getShop($iCurrLang);
945 
946  // mailer stuff
947  $this->setFrom($oParams->send_email, $oParams->send_name);
948  $this->setSMTP();
949 
950  // create messages
951  $oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
952  $this->setUser($oParams);
953 
954  $sHomeUrl = $this->getViewConfig()->getHomeLink();
955 
956  //setting recommended user id
957  if ($myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser()) {
958  $sHomeUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator($sHomeUrl);
959  $sHomeUrl .= "su=" . $oActiveUser->getId();
960  }
961 
962  if (is_array($oParams->rec_email) && count($oParams->rec_email) > 0) {
963  foreach ($oParams->rec_email as $sEmail) {
964  if (!empty($sEmail)) {
965  $sRegisterUrl = oxRegistry::get("oxUtilsUrl")->appendParamSeparator($sHomeUrl);
966  //setting recipient user email
967  $sRegisterUrl .= "re=" . md5($sEmail);
968  $this->setViewData("sHomeUrl", $sRegisterUrl);
969 
970  // Process view data array through oxoutput processor
971  $this->_processViewArray();
972 
973  $this->setBody($oSmarty->fetch($this->_sInviteTemplate));
974 
975  $this->setAltBody($oSmarty->fetch($this->_sInviteTemplatePlain));
976  $this->setSubject($oParams->send_subject);
977 
978  $this->setRecipient($sEmail);
979  $this->setReplyTo($oParams->send_email, $oParams->send_name);
980  $this->send();
981  $this->clearAllRecipients();
982  }
983  }
984 
985  return true;
986  }
987 
988  return false;
989  }
990 
1000  public function sendSendedNowMail($oOrder, $sSubject = null)
1001  {
1002  $myConfig = $this->getConfig();
1003 
1004  $iOrderLang = (int) (isset($oOrder->oxorder__oxlang->value) ? $oOrder->oxorder__oxlang->value : 0);
1005 
1006  // shop info
1007  $oShop = $this->_getShop($iOrderLang);
1008 
1009  //set mail params (from, fromName, smtp)
1010  $this->_setMailParams($oShop);
1011 
1012  //create messages
1013  $oLang = oxRegistry::getLang();
1014  $oSmarty = $this->_getSmarty();
1015  $this->setViewData("order", $oOrder);
1016  $this->setViewData("shopTemplateDir", $myConfig->getTemplateDir(false));
1017 
1018  if ($myConfig->getConfigParam("bl_perfLoadReviews")) {
1019  $this->setViewData("blShowReviewLink", true);
1020  $oUser = oxNew('oxuser');
1021  $this->setViewData("reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value));
1022  }
1023 
1024  // Process view data array through oxoutput processor
1025  $this->_processViewArray();
1026 
1027  // #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
1028  $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
1029  //V send email in order language
1030  $iOldTplLang = $oLang->getTplLanguage();
1031  $iOldBaseLang = $oLang->getTplLanguage();
1032  $oLang->setTplLanguage($iOrderLang);
1033  $oLang->setBaseLanguage($iOrderLang);
1034 
1035  $oSmarty->security_settings['INCLUDE_ANY'] = true;
1036  // force non admin to get correct paths (tpl, img)
1037  $myConfig->setAdminMode(false);
1038  $this->setBody($oSmarty->fetch($this->_sSenedNowTemplate));
1039  $this->setAltBody($oSmarty->fetch($this->_sSenedNowTemplatePlain));
1040  $myConfig->setAdminMode(true);
1041  $oLang->setTplLanguage($iOldTplLang);
1042  $oLang->setBaseLanguage($iOldBaseLang);
1043  // set it back
1044  $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'];
1045 
1046  //Sets subject to email
1047  $this->setSubject(($sSubject !== null) ? $sSubject : $oShop->oxshops__oxsendednowsubject->getRawValue());
1048 
1049  $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
1050 
1051  $this->setRecipient($oOrder->oxorder__oxbillemail->value, $sFullName);
1052  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1053 
1054  return $this->send();
1055  }
1056 
1066  public function sendDownloadLinksMail($oOrder, $sSubject = null)
1067  {
1068  $myConfig = $this->getConfig();
1069 
1070  $iOrderLang = (int) (isset($oOrder->oxorder__oxlang->value) ? $oOrder->oxorder__oxlang->value : 0);
1071 
1072  // shop info
1073  $oShop = $this->_getShop($iOrderLang);
1074 
1075  //set mail params (from, fromName, smtp)
1076  $this->_setMailParams($oShop);
1077 
1078  //create messages
1079  $oLang = oxRegistry::getLang();
1080  $oSmarty = $this->_getSmarty();
1081  $this->setViewData("order", $oOrder);
1082  $this->setViewData("shopTemplateDir", $myConfig->getTemplateDir(false));
1083 
1084  $oUser = oxNew('oxuser');
1085  $this->setViewData("reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value));
1086 
1087  // Process view data array through oxoutput processor
1088  $this->_processViewArray();
1089 
1090  // #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
1091  $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
1092  //V send email in order language
1093  $iOldTplLang = $oLang->getTplLanguage();
1094  $iOldBaseLang = $oLang->getTplLanguage();
1095  $oLang->setTplLanguage($iOrderLang);
1096  $oLang->setBaseLanguage($iOrderLang);
1097 
1098  $oSmarty->security_settings['INCLUDE_ANY'] = true;
1099  // force non admin to get correct paths (tpl, img)
1100  $myConfig->setAdminMode(false);
1101  $this->setBody($oSmarty->fetch($this->_sSendDownloadsTemplate));
1102  $this->setAltBody($oSmarty->fetch($this->_sSendDownloadsTemplatePlain));
1103  $myConfig->setAdminMode(true);
1104  $oLang->setTplLanguage($iOldTplLang);
1105  $oLang->setBaseLanguage($iOldBaseLang);
1106  // set it back
1107  $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'];
1108 
1109  //Sets subject to email
1110  $this->setSubject(($sSubject !== null) ? $sSubject : $oLang->translateString("DOWNLOAD_LINKS", null, false));
1111 
1112  $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
1113 
1114  $this->setRecipient($oOrder->oxorder__oxbillemail->value, $sFullName);
1115  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1116 
1117  return $this->send();
1118  }
1119 
1134  public function sendBackupMail($aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError)
1135  {
1136  // shop info
1137  $oShop = $this->_getShop();
1138 
1139  //set mail params (from, fromName, smtp)
1140  $this->_setMailParams($oShop);
1141 
1142  $this->setBody($sMessage);
1143  $this->setSubject($sSubject);
1144 
1145  $this->setRecipient($oShop->oxshops__oxinfoemail->value, "");
1146  $sEmailAddress = $sEmailAddress ? $sEmailAddress : $oShop->oxshops__oxowneremail->value;
1147 
1148  $this->setFrom($sEmailAddress, "");
1149  $this->setReplyTo($sEmailAddress, "");
1150 
1151  //attaching files
1152  $blAttashSucc = true;
1153  $sAttPath = oxRegistry::get("oxUtilsFile")->normalizeDir($sAttPath);
1154  foreach ($aAttFiles as $iNum => $sAttFile) {
1155  $sFullPath = $sAttPath . $sAttFile;
1156  if (@is_readable($sFullPath) && @is_file($sFullPath)) {
1157  $blAttashSucc = $this->addAttachment($sFullPath, $sAttFile);
1158  } else {
1159  $blAttashSucc = false;
1160  $aError[] = array(5, $sAttFile); //"Error: backup file $sAttFile not found";
1161  }
1162  }
1163 
1164  if (!$blAttashSucc) {
1165  $aError[] = array(4, ""); //"Error: backup files was not sent to email ...";
1166  $this->clearAttachments();
1167 
1168  return false;
1169  }
1170 
1171  $aStatus[] = 3; //"Mailing backup files ...";
1172  $blSend = $this->send();
1173  $this->clearAttachments();
1174 
1175  return $blSend;
1176  }
1177 
1188  public function sendEmail($sTo, $sSubject, $sBody)
1189  {
1190  //set mail params (from, fromName, smtp)
1191  $this->_setMailParams();
1192 
1193  if (is_array($sTo)) {
1194  foreach ($sTo as $sAddress) {
1195  $this->setRecipient($sAddress, "");
1196  $this->setReplyTo($sAddress, "");
1197  }
1198  } else {
1199  $this->setRecipient($sTo, "");
1200  $this->setReplyTo($sTo, "");
1201  }
1202 
1203  //may be changed later
1204  $this->isHtml(false);
1205 
1206  $this->setSubject($sSubject);
1207  $this->setBody($sBody);
1208 
1209  return $this->send();
1210  }
1211 
1220  public function sendStockReminder($aBasketContents, $sSubject = null)
1221  {
1222  $blSend = false;
1223 
1224  $oArticleList = oxNew("oxarticlelist");
1225  $oArticleList->loadStockRemindProducts($aBasketContents);
1226 
1227  // nothing to remind?
1228  if ($oArticleList->count()) {
1229  $oShop = $this->_getShop();
1230 
1231  //set mail params (from, fromName, smtp... )
1232  $this->_setMailParams($oShop);
1233  $oLang = oxRegistry::getLang();
1234 
1235  $oSmarty = $this->_getSmarty();
1236  $this->setViewData("articles", $oArticleList);
1237 
1238  // Process view data array through oxOutput processor
1239  $this->_processViewArray();
1240 
1241  $this->setRecipient($oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue());
1242  $this->setFrom($oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue());
1243  $this->setBody($oSmarty->fetch($this->getConfig()->getTemplatePath($this->_sReminderMailTemplate, false)));
1244  $this->setAltBody("");
1245  $this->setSubject(($sSubject !== null) ? $sSubject : $oLang->translateString('STOCK_LOW'));
1246 
1247  $blSend = $this->send();
1248  }
1249 
1250  return $blSend;
1251  }
1252 
1261  public function sendWishlistMail($oParams)
1262  {
1263  $myConfig = $this->getConfig();
1264 
1265  $this->_clearMailer();
1266 
1267  // shop info
1268  $oShop = $this->_getShop();
1269 
1270  // mailer stuff
1271  $this->setFrom($oParams->send_email, $oParams->send_name);
1272  $this->setSMTP();
1273 
1274  // create messages
1275  $oSmarty = $this->_getSmarty();
1276  $this->setUser($oParams);
1277 
1278  // Process view data array through oxoutput processor
1279  $this->_processViewArray();
1280 
1281  $this->setBody($oSmarty->fetch($this->_sWishListTemplate));
1282  $this->setAltBody($oSmarty->fetch($this->_sWishListTemplatePlain));
1283  $this->setSubject($oParams->send_subject);
1284 
1285  $this->setRecipient($oParams->rec_email, $oParams->rec_name);
1286  $this->setReplyTo($oParams->send_email, $oParams->send_name);
1287 
1288  return $this->send();
1289  }
1290 
1301  public function sendPriceAlarmNotification($aParams, $oAlarm, $sSubject = null)
1302  {
1303  $this->_clearMailer();
1304  $oShop = $this->_getShop();
1305 
1306  //set mail params (from, fromName, smtp)
1307  $this->_setMailParams($oShop);
1308 
1309  $iAlarmLang = $oAlarm->oxpricealarm__oxlang->value;
1310 
1311  $oArticle = oxNew("oxarticle");
1312  //$oArticle->setSkipAbPrice( true );
1313  $oArticle->loadInLang($iAlarmLang, $aParams['aid']);
1314  $oLang = oxRegistry::getLang();
1315 
1316  // create messages
1317  $oSmarty = $this->_getSmarty();
1318  $this->setViewData("product", $oArticle);
1319  $this->setViewData("email", $aParams['email']);
1320  $this->setViewData("bidprice", $oLang->formatCurrency($oAlarm->oxpricealarm__oxprice->value, $oCur));
1321 
1322  // Process view data array through oxOutput processor
1323  $this->_processViewArray();
1324 
1325  $this->setRecipient($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1326  $this->setSubject(($sSubject !== null) ? $sSubject : $oLang->translateString('PRICE_ALERT_FOR_PRODUCT', $iAlarmLang) . " " . $oArticle->oxarticles__oxtitle->getRawValue());
1327  $this->setBody($oSmarty->fetch($this->_sOwnerPricealarmTemplate));
1328  $this->setFrom($aParams['email'], "");
1329  $this->setReplyTo($aParams['email'], "");
1330 
1331  return $this->send();
1332  }
1333 
1345  public function sendPricealarmToCustomer($sRecipient, $oAlarm, $sBody = null, $sReturnMailBody = null)
1346  {
1347  $this->_clearMailer();
1348 
1349  $oShop = $this->_getShop();
1350 
1351  if ($oShop->getId() != $oAlarm->oxpricealarm__oxshopid->value) {
1352  $oShop = oxNew("oxshop");
1353  $oShop->load($oAlarm->oxpricealarm__oxshopid->value);
1354  $this->setShop($oShop);
1355  }
1356 
1357  //set mail params (from, fromName, smtp)
1358  $this->_setMailParams($oShop);
1359 
1360  // create messages
1361  $oSmarty = $this->_getSmarty();
1362 
1363  $this->setViewData("product", $oAlarm->getArticle());
1364  $this->setViewData("oPriceAlarm", $oAlarm);
1365  $this->setViewData("bidprice", $oAlarm->getFProposedPrice());
1366  $this->setViewData("currency", $oAlarm->getPriceAlarmCurrency());
1367 
1368  // Process view data array through oxoutput processor
1369  $this->_processViewArray();
1370 
1371  $this->setRecipient($sRecipient, $sRecipient);
1372  $this->setSubject($oShop->oxshops__oxname->value);
1373 
1374  if ($sBody === null) {
1375  $sBody = $oSmarty->fetch($this->_sPricealamrCustomerTemplate);
1376  }
1377 
1378  $this->setBody($sBody);
1379 
1380  $this->addAddress($sRecipient, $sRecipient);
1381  $this->setReplyTo($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1382 
1383  if ($sReturnMailBody) {
1384  return $this->getBody();
1385  } else {
1386  return $this->send();
1387  }
1388  }
1389 
1399  protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
1400  {
1401  $sBody = $this->getBody();
1402  if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
1403 
1404  $oFileUtils = oxRegistry::get("oxUtilsFile");
1405  $blReSetBody = false;
1406 
1407  // preparing imput
1408  $sDynImageDir = $oFileUtils->normalizeDir($sDynImageDir);
1409  $sImageDir = $oFileUtils->normalizeDir($sImageDir);
1410  $sImageDirNoSSL = $oFileUtils->normalizeDir($sImageDirNoSSL);
1411 
1412  if (is_array($matches) && count($matches)) {
1413  $aImageCache = array();
1414  $myUtils = oxRegistry::getUtils();
1415  $myUtilsObject = oxUtilsObject::getInstance();
1416  $oImgGenerator = oxNew("oxDynImgGenerator");
1417 
1418  foreach ($matches as $aImage) {
1419 
1420  $image = $aImage[1];
1421  $sFileName = '';
1422  if (strpos($image, $sDynImageDir) === 0) {
1423  $sFileName = $oFileUtils->normalizeDir($sAbsDynImageDir) . str_replace($sDynImageDir, '', $image);
1424  } elseif (strpos($image, $sImageDir) === 0) {
1425  $sFileName = $oFileUtils->normalizeDir($sAbsImageDir) . str_replace($sImageDir, '', $image);
1426  } elseif (strpos($image, $sImageDirNoSSL) === 0) {
1427  $sFileName = $oFileUtils->normalizeDir($sAbsImageDir) . str_replace($sImageDirNoSSL, '', $image);
1428  }
1429 
1430  if ($sFileName && !@is_readable($sFileName)) {
1431  $sFileName = $oImgGenerator->getImagePath($sFileName);
1432  }
1433 
1434  if ($sFileName) {
1435  $sCId = '';
1436  if (isset($aImageCache[$sFileName]) && $aImageCache[$sFileName]) {
1437  $sCId = $aImageCache[$sFileName];
1438  } else {
1439  $sCId = $myUtilsObject->generateUID();
1440  $sMIME = $myUtils->oxMimeContentType($sFileName);
1441  if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
1442  if ($this->addEmbeddedImage($sFileName, $sCId, "image", "base64", $sMIME)) {
1443  $aImageCache[$sFileName] = $sCId;
1444  } else {
1445  $sCId = '';
1446  }
1447  }
1448  }
1449  if ($sCId && $sCId == $aImageCache[$sFileName]) {
1450  if ($sReplTag = str_replace($image, 'cid:' . $sCId, $aImage[0])) {
1451  $sBody = str_replace($aImage[0], $sReplTag, $sBody);
1452  $blReSetBody = true;
1453  }
1454  }
1455  }
1456  }
1457  }
1458 
1459  if ($blReSetBody) {
1460  $this->setBody($sBody);
1461  }
1462  }
1463  }
1464 
1470  public function setSubject($sSubject = null)
1471  {
1472  // A. HTML entities in subjects must be replaced
1473  $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>'), $sSubject);
1474 
1475  $this->set("Subject", $sSubject);
1476  }
1477 
1483  public function getSubject()
1484  {
1485  return $this->Subject;
1486  }
1487 
1495  public function setBody($sBody = null, $blClearSid = true)
1496  {
1497  if ($blClearSid) {
1498  $sBody = $this->_clearSidFromBody($sBody);
1499  }
1500 
1501  $this->set("Body", $sBody);
1502  }
1503 
1509  public function getBody()
1510  {
1511  return $this->Body;
1512  }
1513 
1521  public function setAltBody($sAltBody = null, $blClearSid = true)
1522  {
1523  if ($blClearSid) {
1524  $sAltBody = $this->_clearSidFromBody($sAltBody);
1525  }
1526 
1527  // A. alt body is used for plain text emails so we should eliminate HTML entities
1528  $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>'), $sAltBody);
1529 
1530  $this->set("AltBody", $sAltBody);
1531  }
1532 
1538  public function getAltBody()
1539  {
1540  return $this->AltBody;
1541  }
1542 
1549  public function setRecipient($sAddress = null, $sName = null)
1550  {
1551  try {
1552  if ($this->getConfig()->isUtf() && function_exists('idn_to_ascii') ) {
1553  $sAddress = idn_to_ascii($sAddress);
1554  }
1555 
1556  parent::AddAddress($sAddress, $sName);
1557 
1558  // copying values as original class does not allow to access recipients array
1559  $this->_aRecipients[] = array($sAddress, $sName);
1560  } catch (Exception $oEx) {
1561  }
1562  }
1563 
1571  public function getRecipient()
1572  {
1573  return $this->_aRecipients;
1574  }
1575 
1579  public function clearAllRecipients()
1580  {
1581  $this->_aRecipients = array();
1583  }
1584 
1594  public function setReplyTo($sEmail = null, $sName = null)
1595  {
1596  if (!oxRegistry::getUtils()->isValidEmail($sEmail)) {
1597  $sEmail = $this->_getShop()->oxshops__oxorderemail->value;
1598  }
1599 
1600  $this->_aReplies[] = array($sEmail, $sName);
1601 
1602  try {
1603  parent::addReplyTo($sEmail, $sName);
1604  } catch (Exception $oEx) {
1605  }
1606  }
1607 
1613  public function getReplyTo()
1614  {
1615  return $this->_aReplies;
1616  }
1617 
1621  public function clearReplyTos()
1622  {
1623  $this->_aReplies = array();
1625  }
1626 
1632  public function setFrom($address, $name = null, $auto = true)
1633  {
1634  $address = substr($address, 0, 150);
1635  $name = substr($name, 0, 150);
1636 
1637  $success = false;
1638  try {
1639  $success = parent::setFrom($address, $name, $auto);
1640  } catch (Exception $exception) {
1641  }
1642 
1643  return $success;
1644  }
1645 
1651  public function getFrom()
1652  {
1653  return $this->From;
1654  }
1655 
1661  public function getFromName()
1662  {
1663  return $this->FromName;
1664  }
1665 
1672  public function setCharSet($sCharSet = null)
1673  {
1674  if ($sCharSet) {
1675  $this->_sCharSet = $sCharSet;
1676  } else {
1677  $this->_sCharSet = oxRegistry::getLang()->translateString("charset");
1678  }
1679  $this->set("CharSet", $this->_sCharSet);
1680  }
1681 
1687  public function setMailer($sMailer = null)
1688  {
1689  $this->set("Mailer", $sMailer);
1690  }
1691 
1697  public function getMailer()
1698  {
1699  return $this->Mailer;
1700  }
1701 
1707  public function setHost($sHost = null)
1708  {
1709  $this->set("Host", $sHost);
1710  }
1711 
1717  public function getErrorInfo()
1718  {
1719  return $this->ErrorInfo;
1720  }
1721 
1728  public function setMailWordWrap($iWordWrap = null)
1729  {
1730  $this->set("WordWrap", $iWordWrap);
1731  }
1732 
1738  public function setUseInlineImages($blUseImages = null)
1739  {
1740  $this->_blInlineImgEmail = $blUseImages;
1741  }
1742 
1746  public function addAttachment(
1747  $path,
1748  $name = '',
1749  $encoding = 'base64',
1750  $type = 'application/octet-stream',
1751  $disposition = 'attachment'
1752  ) {
1753  $this->_aAttachments[] = array($path, $name, $encoding, $type, $disposition);
1754  $result = false;
1755 
1756  try {
1757  $result = parent::addAttachment($path, $name, $encoding, $type, $disposition);
1758  } catch (Exception $exception) {
1759  }
1760 
1761  return $result;
1762  }
1763 
1767  public function addEmbeddedImage(
1768  $path,
1769  $cid,
1770  $name = '',
1771  $encoding = 'base64',
1772  $type = 'application/octet-stream',
1773  $disposition = 'inline'
1774  ) {
1775  $this->_aAttachments[] = array(
1776  $path,
1777  basename($path),
1778  $name,
1779  $encoding,
1780  $type,
1781  false,
1782  $disposition,
1783  $cid
1784  );
1785 
1786  return parent::addEmbeddedImage($path, $cid, $name, $encoding, $type, $disposition);
1787  }
1788 
1794  public function getAttachments()
1795  {
1796  return $this->_aAttachments;
1797  }
1798 
1804  public function clearAttachments()
1805  {
1806  $this->_aAttachments = array();
1807 
1808  return parent::clearAttachments();
1809  }
1810 
1820  public function headerLine($sName, $sValue)
1821  {
1822  if (stripos($sName, 'X-') !== false) {
1823  return;
1824  }
1825 
1826  return parent::headerLine($sName, $sValue);
1827  }
1828 
1834  protected function _getUseInlineImages()
1835  {
1836  return $this->_blInlineImgEmail;
1837  }
1838 
1844  protected function _sendMailErrorMsg()
1845  {
1846  // build addresses
1847  $aRecipients = $this->getRecipient();
1848 
1849  $sOwnerMessage = "Error sending eMail(" . $this->getSubject() . ") to: \n\n";
1850 
1851  foreach ($aRecipients as $aEMail) {
1852  $sOwnerMessage .= $aEMail[0];
1853  $sOwnerMessage .= (!empty($aEMail[1])) ? ' (' . $aEMail[1] . ')' : '';
1854  $sOwnerMessage .= " \n ";
1855  }
1856  $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
1857 
1858  // shop info
1859  $oShop = $this->_getShop();
1860 
1861  $blRet = @mail($oShop->oxshops__oxorderemail->value, "eMail problem in shop!", $sOwnerMessage);
1862 
1863  return $blRet;
1864  }
1865 
1875  protected function _addUserInfoOrderEMail($oOrder)
1876  {
1877  return $oOrder;
1878  }
1879 
1889  protected function _addUserRegisterEmail($oUser)
1890  {
1891  return $oUser;
1892  }
1893 
1903  protected function _addForgotPwdEmail($oShop)
1904  {
1905  return $oShop;
1906  }
1907 
1917  protected function _addNewsletterDbOptInMail($oUser)
1918  {
1919  return $oUser;
1920  }
1921 
1925  protected function _clearMailer()
1926  {
1927  $this->clearAllRecipients();
1928  $this->clearReplyTos();
1929  $this->clearAttachments();
1930 
1931  //workaround for phpmailer as it doesn't cleanup as it should
1932  $this->error_count = 0;
1933  $this->ErrorInfo = '';
1934  }
1935 
1941  protected function _setMailParams($oShop = null)
1942  {
1943  $this->_clearMailer();
1944 
1945  if (!$oShop) {
1946  $oShop = $this->_getShop();
1947  }
1948 
1949  $this->setFrom($oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
1950  $this->setSmtp($oShop);
1951  }
1952 
1962  protected function _getShop($iLangId = null, $iShopId = null)
1963  {
1964  if ($iLangId === null && $iShopId === null) {
1965  if (isset($this->_oShop)) {
1966  return $this->_oShop;
1967  } else {
1968  return $this->_oShop = $this->getConfig()->getActiveShop();
1969  }
1970  }
1971 
1972  $myConfig = $this->getConfig();
1973 
1974  $oShop = oxNew('oxShop');
1975  if ($iShopId !== null) {
1976  $oShop->setShopId($iShopId);
1977  }
1978  if ($iLangId !== null) {
1979  $oShop->setLanguage($iLangId);
1980  }
1981  $oShop->load($myConfig->getShopId());
1982 
1983  return $oShop;
1984  }
1985 
1992  protected function _setSmtpAuthInfo($sUserName = null, $sUserPassword = null)
1993  {
1994  $this->set("SMTPAuth", true);
1995  $this->set("Username", $sUserName);
1996  $this->set("Password", $sUserPassword);
1997  }
1998 
2004  protected function _setSmtpDebug($blDebug = null)
2005  {
2006  $this->set("SMTPDebug", $blDebug);
2007  }
2008 
2012  protected function _setMailerPluginDir()
2013  {
2014  $this->set("PluginDir", getShopBasePath() . "core/phpmailer/");
2015  }
2016 
2021  protected function _makeOutputProcessing()
2022  {
2023  $oOutput = oxNew("oxOutput");
2024  $this->setBody($oOutput->process($this->getBody(), "oxemail"));
2025  $this->setAltBody($oOutput->process($this->getAltBody(), "oxemail"));
2026  $oOutput->processEmail($this);
2027  }
2028 
2034  protected function _sendMail()
2035  {
2036  $blResult = false;
2037  try {
2038  $blResult = parent::send();
2039  } catch (Exception $oException) {
2040  $oEx = oxNew("oxException");
2041  $oEx->setMessage($oException->getMessage());
2042  $oEx->debugOut();
2043  if ($this->getConfig()->getConfigParam('iDebug') != 0) {
2044  throw $oEx;
2045  }
2046  }
2047 
2048  return $blResult;
2049  }
2050 
2051 
2055  protected function _processViewArray()
2056  {
2057  $oSmarty = $this->_getSmarty();
2058  $oOutputProcessor = oxNew("oxOutput");
2059 
2060  // processing all view data
2061  foreach ($this->_aViewData as $sKey => $sValue) {
2062  $oSmarty->assign($sKey, $sValue);
2063  }
2064 
2065  // processing assigned smarty variables
2066  $aNewSmartyArray = $oOutputProcessor->processViewArray($oSmarty->get_template_vars(), "oxemail");
2067 
2068  foreach ($aNewSmartyArray as $key => $val) {
2069  $oSmarty->assign($key, $val);
2070  }
2071  }
2072 
2078  public function getCharset()
2079  {
2080  if (!$this->_sCharSet) {
2081  return oxRegistry::getLang()->translateString("charset");
2082  } else {
2083  return $this->CharSet;
2084  }
2085  }
2086 
2092  public function getShop()
2093  {
2094  return $this->_getShop();
2095  }
2096 
2102  public function setShop($oShop)
2103  {
2104  $this->_oShop = $oShop;
2105  }
2106 
2112  public function getViewConfig()
2113  {
2114  return $this->getConfig()->getActiveView()->getViewConfig();
2115  }
2116 
2122  public function getView()
2123  {
2124  return $this->getConfig()->getActiveView();
2125  }
2126 
2132  public function getCurrency()
2133  {
2134  $oConfig = oxRegistry::getConfig();
2135 
2136  return $oConfig->getActShopCurrencyObject();
2137  }
2138 
2145  public function setViewData($sKey, $sValue)
2146  {
2147  $this->_aViewData[$sKey] = $sValue;
2148  }
2149 
2155  public function getViewData()
2156  {
2157  return $this->_aViewData;
2158  }
2159 
2167  public function getViewDataItem($sKey)
2168  {
2169  if (isset($this->_aViewData[$sKey])) {
2170  return $this->_aViewData;
2171  }
2172  }
2173 
2179  public function setUser($oUser)
2180  {
2181  $this->_aViewData["oUser"] = $oUser;
2182  }
2183 
2189  public function getUser()
2190  {
2191  return $this->_aViewData["oUser"];
2192  }
2193 
2201  public function getOrderFileList($sOrderId)
2202  {
2203  $oOrderList = oxNew('oxOrderFileList');
2204  $oOrderList->loadOrderFiles($sOrderId);
2205 
2206  if (count($oOrderList) > 0) {
2207  return $oOrderList;
2208  }
2209 
2210  return false;
2211  }
2212 
2220  private function _clearSidFromBody($sAltBody)
2221  {
2222  return oxStr::getStr()->preg_replace('/(\?|&(amp;)?)(force_)?(admin_)?sid=[A-Z0-9\.]+/i', '\1shp=' . $this->getConfig()->getShopId(), $sAltBody);
2223  }
2224 
2231  private function _getUserIdByUserName($sUserName, $ShopId)
2232  {
2233  $sSelect = "SELECT `OXID`
2234  FROM `oxuser`
2235  WHERE `OXACTIVE` = 1
2236  AND `OXUSERNAME` = ?
2237  AND `OXPASSWORD` != ''";
2238 
2239  if ($this->getConfig()->getConfigParam('blMallUsers')) {
2240  $sSelect .= "ORDER BY OXSHOPID = ? DESC";
2241  } else {
2242  $sSelect .= "AND OXSHOPID = ?";
2243  }
2244 
2245  $sOxId = oxDb::getDb()->getOne(
2246  $sSelect,
2247  array(
2248  $sUserName,
2249  $ShopId)
2250  );
2251 
2252  return $sOxId;
2253  }
2254 }