oxemail.php

Go to the documentation of this file.
00001 <?php
00005 require oxConfig::getInstance()->getConfigParam( 'sCoreDir' ) . "/phpmailer/class.phpmailer.php";
00006 
00007 
00013 class oxEmail extends PHPMailer
00014 {
00020     public $SMTP_PORT = 25;
00021 
00027     protected $_sForgotPwdTemplate = "email/html/forgotpwd.tpl";
00028 
00034     protected $_sForgotPwdTemplatePlain = "email/plain/forgotpwd.tpl";
00035 
00041     protected $_sNewsletterOptInTemplate = "email/html/newsletteroptin.tpl";
00042 
00048     protected $_sNewsletterOptInTemplatePlain = "email/plain/newsletteroptin.tpl";
00049 
00055     protected $_sSuggestTemplate = "email/html/suggest.tpl";
00056 
00062     protected $_sSuggestTemplatePlain = "email/plain/suggest.tpl";
00063 
00069     protected $_sInviteTemplate = "email/html/invite.tpl";
00070 
00076     protected $_sInviteTemplatePlain = "email/plain/invite.tpl";
00077 
00083     protected $_sSenedNowTemplate = "email/html/sendednow.tpl";
00084 
00090     protected $_sSenedNowTemplatePlain = "email/plain/sendednow.tpl";
00091 
00097     protected $_sWishListTemplate = "email/html/wishlist.tpl";
00098 
00104     protected $_sWishListTemplatePlain = "email/plain/wishlist.tpl";
00105 
00111     protected $_sRegisterTemplate = "email/html/register.tpl";
00112 
00118     protected $_sRegisterTemplatePlain = "email/plain/register.tpl";
00119 
00125     protected $_sReminderMailTemplate = "email/html/owner_reminder.tpl";
00126 
00132     protected $_sOrderUserTemplate          = "email/html/order_cust.tpl";
00133 
00139     protected $_sOrderUserPlainTemplate     = "email/plain/order_cust.tpl";
00140 
00146     protected $_sOrderOwnerTemplate         = "email/html/order_owner.tpl";
00147 
00153     protected $_sOrderOwnerPlainTemplate    = "email/plain/order_owner.tpl";
00154 
00155     // #586A - additional templates for more customizable subjects
00156 
00162     protected $_sOrderUserSubjectTemplate   = "email/html/order_cust_subj.tpl";
00163 
00169     protected $_sOrderOwnerSubjectTemplate  = "email/html/order_owner_subj.tpl";
00170 
00176     protected $_sOwnerPricealarmTemplate    = "email/html/pricealarm_owner.tpl";
00177 
00183     protected $_sPricealamrCustomerTemplate    = "email_pricealarm_customer.tpl";
00184 
00190     protected $_aShops = array();
00191 
00197     protected $_blInlineImgEmail = null;
00198 
00204     protected $_aRecipients = array();
00205 
00211     protected $_aReplies = array();
00212 
00218     protected $_aAttachments = array();
00219 
00225     protected $_oSmarty = null;
00226 
00232     protected $_aViewData = array();
00233 
00239     protected $_oShop = null;
00240 
00246     protected $_sCharSet = null;
00247 
00251     public function __construct()
00252     {
00253         //enabling exception handling in phpmailer class
00254         parent::__construct( true );
00255 
00256         $myConfig = $this->getConfig();
00257 
00258         $this->_setMailerPluginDir();
00259         $this->setSmtp();
00260 
00261         $this->setUseInlineImages( $myConfig->getConfigParam('blInlineImgEmail') );
00262         $this->setMailWordWrap( 100 );
00263 
00264         $this->isHtml( true );
00265         $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
00266 
00267         $this->_getSmarty();
00268     }
00269 
00281     public function __call( $sMethod, $aArgs )
00282     {
00283         if ( defined( 'OXID_PHP_UNIT' ) ) {
00284             if ( substr( $sMethod, 0, 4) == "UNIT" ) {
00285                 $sMethod = str_replace( "UNIT", "_", $sMethod );
00286             }
00287             if ( method_exists( $this, $sMethod)) {
00288                 return call_user_func_array( array( & $this, $sMethod ), $aArgs );
00289             }
00290         }
00291 
00292         throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")".PHP_EOL);
00293     }
00294 
00300     public function getConfig()
00301     {
00302         if ( $this->_oConfig == null ) {
00303             $this->_oConfig = oxConfig::getInstance();
00304         }
00305 
00306         return $this->_oConfig;
00307     }
00308 
00316     public function setConfig( $oConfig )
00317     {
00318         $this->_oConfig = $oConfig;
00319     }
00320 
00321 
00327     protected function _getSmarty()
00328     {
00329         if ( $this->_oSmarty === null ) {
00330             $this->_oSmarty = oxUtilsView::getInstance()->getSmarty();
00331         }
00332 
00333         //setting default view
00334         $this->_oSmarty->assign( "oEmailView", $this );
00335 
00336         return $this->_oSmarty;
00337     }
00338 
00346     public function send()
00347     {
00348         // if no recipients found, skipping sending
00349         if ( count( $this->getRecipient() ) < 1 ) {
00350             return false;
00351         }
00352 
00353         $myConfig = $this->getConfig();
00354         $this->setCharSet();
00355 
00356         if ( $this->_getUseInlineImages() ) {
00357             $this->_includeImages( $myConfig->getImageDir(), $myConfig->getImageUrl( false, false ), $myConfig->getPictureUrl(null, false),
00358                                    $myConfig->getImageDir(), $myConfig->getPictureDir(false));
00359         }
00360 
00361         $this->_makeOutputProcessing();
00362 
00363         // try to send mail via SMTP
00364         if ( $this->getMailer() == 'smtp' ) {
00365             $blRet = $this->_sendMail();
00366 
00367             // if sending failed, try to send via mail()
00368             if ( !$blRet ) {
00369                 // failed sending via SMTP, sending notification to shop owner
00370                 $this->_sendMailErrorMsg();
00371 
00372                 // trying to send using standard mailer
00373                 $this->setMailer( 'mail' );
00374                 $blRet = $this->_sendMail();
00375             }
00376         } else {
00377             // sending mail via mail()
00378             $this->setMailer( 'mail' );
00379             $blRet = $this->_sendMail();
00380         }
00381 
00382         if ( !$blRet ) {
00383             // failed sending, giving up, trying to send notification to shop owner
00384             $this->_sendMailErrorMsg();
00385         }
00386 
00387         return $blRet;
00388     }
00389 
00398     protected function _setSmtpProtocol($sUrl)
00399     {
00400         $sProtocol = '';
00401         $sSmtpHost = $sUrl;
00402         $aMatch = array();
00403         if ( getStr()->preg_match('@^([0-9a-z]+://)?(.*)$@i', $sUrl, $aMatch ) ) {
00404             if ($aMatch[1]) {
00405                 if (($aMatch[1] == 'ssl://') || ($aMatch[1] == 'tls://')) {
00406                     $this->set( "SMTPSecure", substr($aMatch[1], 0, 3) );
00407                 } else {
00408                     $sProtocol = $aMatch[1];
00409                 }
00410             }
00411             $sSmtpHost = $aMatch[2];
00412         }
00413 
00414         return $sProtocol.$sSmtpHost;
00415     }
00416 
00424     public function setSmtp( $oShop = null )
00425     {
00426         $myConfig = $this->getConfig();
00427         $oShop = ( $oShop ) ? $oShop : $this->_getShop();
00428 
00429         $sSmtpUrl = $this->_setSmtpProtocol($oShop->oxshops__oxsmtp->value);
00430 
00431         if ( !$this->_isValidSmtpHost( $sSmtpUrl ) ) {
00432             $this->setMailer( "mail" );
00433             return;
00434         }
00435 
00436         $this->setHost( $sSmtpUrl );
00437         $this->setMailer( "smtp" );
00438 
00439         if ( $oShop->oxshops__oxsmtpuser->value ) {
00440             $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
00441         }
00442 
00443         if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
00444             $this->_setSmtpDebug( true );
00445         }
00446     }
00447 
00455     protected function _isValidSmtpHost( $sSmtpHost )
00456     {
00457         $blIsSmtp = false;
00458         if ( $sSmtpHost ) {
00459             $sSmtpPort = $this->SMTP_PORT;
00460             $aMatch = array();
00461             if ( getStr()->preg_match('@^(.*?)(:([0-9]+))?$@i', $sSmtpHost, $aMatch)) {
00462                 $sSmtpHost = $aMatch[1];
00463                 $sSmtpPort = (int)$aMatch[3];
00464                 if (!$sSmtpPort) {
00465                     $sSmtpPort = $this->SMTP_PORT;
00466                 }
00467             }
00468             if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $sSmtpPort, $iErrNo, $sErrStr, 30 )) ) {
00469                 // closing connection ..
00470                 fclose( $rHandle );
00471             }
00472         }
00473 
00474         return $blIsSmtp;
00475     }
00476 
00486     public function sendOrderEmailToUser( $oOrder, $sSubject = null )
00487     {
00488         $myConfig = $this->getConfig();
00489 
00490         // add user defined stuff if there is any
00491         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00492 
00493         $oShop = $this->_getShop();
00494         $this->_setMailParams( $oShop );
00495 
00496         $oUser = $oOrder->getOrderUser();
00497         $this->setUser( $oUser );
00498 
00499         // create messages
00500         $oSmarty = $this->_getSmarty();
00501         $this->setViewData( "order", $oOrder);
00502 
00503         // Process view data array through oxoutput processor
00504         $this->_processViewArray();
00505 
00506         $this->setBody( $oSmarty->fetch( $this->_sOrderUserTemplate ) );
00507         $this->setAltBody( $oSmarty->fetch( $this->_sOrderUserPlainTemplate ) );
00508 
00509         // #586A
00510         if ( $sSubject === null ) {
00511             if ( $oSmarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00512                 $sSubject = $oSmarty->fetch( $this->_sOrderUserSubjectTemplate );
00513             } else {
00514                 $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
00515             }
00516         }
00517 
00518         $this->setSubject( $sSubject );
00519 
00520         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00521 
00522         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00523         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00524 
00525         $blSuccess = $this->send();
00526 
00527         return $blSuccess;
00528     }
00529 
00539     public function sendOrderEmailToOwner( $oOrder, $sSubject = null )
00540     {
00541         $myConfig = $this->getConfig();
00542 
00543         $oShop = $this->_getShop();
00544 
00545         // cleanup
00546         $this->_clearMailer();
00547 
00548         // add user defined stuff if there is any
00549         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00550 
00551         $oUser = $oOrder->getOrderUser();
00552         $this->setUser( $oUser );
00553 
00554         // send confirmation to shop owner
00555         // send not pretending from order user, as different email domain rise spam filters
00556         $this->setFrom( $oShop->oxshops__oxowneremail->value );
00557 
00558         $oLang = oxLang::getInstance();
00559         $iOrderLang = $oLang->getObjectTplLanguage();
00560 
00561         // if running shop language is different from admin lang. set in config
00562         // we have to load shop in config language
00563         if ( $oShop->getLanguage() != $iOrderLang ) {
00564             $oShop = $this->_getShop( $iOrderLang );
00565         }
00566 
00567         $this->setSmtp( $oShop );
00568 
00569         // create messages
00570         $oSmarty = $this->_getSmarty();
00571         $this->setViewData( "order", $oOrder );
00572 
00573         // Process view data array through oxoutput processor
00574         $this->_processViewArray();
00575 
00576         $this->setBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerTemplate, false ) ) );
00577         $this->setAltBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerPlainTemplate, false ) ) );
00578 
00579         //Sets subject to email
00580         // #586A
00581         if ( $sSubject === null ) {
00582             if ( $oSmarty->template_exists( $this->_sOrderOwnerSubjectTemplate) ) {
00583                 $sSubject = $oSmarty->fetch( $this->_sOrderOwnerSubjectTemplate );
00584             } else {
00585                  $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
00586             }
00587         }
00588 
00589         $this->setSubject( $sSubject );
00590         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oLang->translateString("order") );
00591 
00592         if ( $oUser->oxuser__oxusername->value != "admin" )
00593             $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00594             $this->setReplyTo( $oUser->oxuser__oxusername->value, $sFullName );
00595 
00596         $blSuccess = $this->send();
00597 
00598         // add user history
00599         $oRemark = oxNew( "oxremark" );
00600         $oRemark->oxremark__oxtext      = new oxField($this->getAltBody(), oxField::T_RAW);
00601         $oRemark->oxremark__oxparentid  = new oxField($oUser->getId(), oxField::T_RAW);
00602         $oRemark->oxremark__oxtype      = new oxField("o", oxField::T_RAW);
00603         $oRemark->save();
00604 
00605 
00606         if ( $myConfig->getConfigParam( 'iDebug' ) == 6) {
00607             oxUtils::getInstance()->showMessageAndExit( "" );
00608         }
00609 
00610         return $blSuccess;
00611     }
00612 
00622     public function sendRegisterConfirmEmail( $oUser, $sSubject = null )
00623     {
00624         // setting content ident
00625 
00626         $this->setViewData( "contentident", "oxregisteraltemail" );
00627         $this->setViewData( "contentplainident", "oxregisterplainaltemail" );
00628 
00629         // sending email
00630         return $this->sendRegisterEmail( $oUser, $sSubject );
00631     }
00632 
00642     public function sendRegisterEmail( $oUser, $sSubject = null )
00643     {
00644         // add user defined stuff if there is any
00645         $oUser = $this->_addUserRegisterEmail( $oUser );
00646 
00647         // shop info
00648         $oShop = $this->_getShop();
00649 
00650         //set mail params (from, fromName, smtp )
00651         $this->_setMailParams( $oShop );
00652 
00653         // create messages
00654         $oSmarty = $this->_getSmarty();
00655         $this->setUser( $oUser );
00656 
00657         // Process view data array through oxoutput processor
00658         $this->_processViewArray();
00659 
00660         $this->setBody( $oSmarty->fetch( $this->_sRegisterTemplate ) );
00661         $this->setAltBody( $oSmarty->fetch( $this->_sRegisterTemplatePlain ) );
00662 
00663         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxregistersubject->getRawValue() );
00664 
00665         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00666 
00667         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00668         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00669 
00670         return $this->send();
00671     }
00672 
00682     public function sendForgotPwdEmail( $sEmailAddress, $sSubject = null )
00683     {
00684         $myConfig = $this->getConfig();
00685         $oDb = oxDb::getDb();
00686 
00687         // shop info
00688         $oShop = $this->_getShop();
00689 
00690         // add user defined stuff if there is any
00691         $oShop = $this->_addForgotPwdEmail( $oShop );
00692 
00693         //set mail params (from, fromName, smtp)
00694         $this->_setMailParams( $oShop );
00695 
00696         // user
00697         $sWhere = "oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote( $sEmailAddress )." and oxuser.oxpassword != ''";
00698         $sOrder = "";
00699         if ( $myConfig->getConfigParam( 'blMallUsers' )) {
00700             $sOrder = "order by oxshopid = '".$oShop->getId()."' desc";
00701         } else {
00702             $sWhere .= " and oxshopid = '".$oShop->getId()."'";
00703         }
00704 
00705         $sSelect = "select oxid from oxuser where $sWhere $sOrder";
00706         if ( ( $sOxId = $oDb->getOne( $sSelect ) ) ) {
00707 
00708             $oUser = oxNew( 'oxuser' );
00709             if ( $oUser->load($sOxId) ) {
00710                 // create messages
00711                 $oSmarty = $this->_getSmarty();
00712                 $this->setUser( $oUser );
00713 
00714                 // Process view data array through oxoutput processor
00715                 $this->_processViewArray();
00716 
00717                 $this->setBody( $oSmarty->fetch( $this->_sForgotPwdTemplate ) );
00718 
00719                 $this->setAltBody( $oSmarty->fetch( $this->_sForgotPwdTemplatePlain ) );
00720 
00721                 //sets subject of email
00722                 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->getRawValue() );
00723 
00724                 $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00725 
00726                 $this->setRecipient( $sEmailAddress, $sFullName );
00727                 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00728 
00729                 return $this->send();
00730             }
00731         }
00732 
00733         return false;
00734     }
00735 
00746     public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00747     {
00748 
00749         // shop info
00750         $oShop = $this->_getShop();
00751 
00752         //set mail params (from, fromName, smtp)
00753         $this->_setMailParams( $oShop );
00754 
00755         $this->setBody( $sMessage );
00756         $this->setSubject( $sSubject );
00757 
00758         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00759         $this->setFrom( $sEmailAddress, "" );
00760         $this->setReplyTo( $sEmailAddress, "" );
00761 
00762         return $this->send();
00763     }
00764 
00774     public function sendNewsletterDbOptInMail( $oUser, $sSubject = null )
00775     {
00776         $oLang = oxLang::getInstance();
00777 
00778         // add user defined stuff if there is any
00779         $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00780 
00781         // shop info
00782         $oShop = $this->_getShop();
00783 
00784         //set mail params (from, fromName, smtp)
00785         $this->_setMailParams( $oShop );
00786 
00787         // create messages
00788         $oSmarty = $this->_getSmarty();
00789         $this->setViewData( "subscribeLink", $this->_getNewsSubsLink($oUser->oxuser__oxid->value) );
00790         $this->setUser( $oUser );
00791 
00792         // Process view data array through oxoutput processor
00793         $this->_processViewArray();
00794 
00795         $this->setBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplate ) );
00796         $this->setAltBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplatePlain ) );
00797         $this->setSubject( ( $sSubject !== null ) ? $sSubject : oxLang::getInstance()->translateString("EMAIL_NEWSLETTERDBOPTINMAIL_SUBJECT") . " " . $oShop->oxshops__oxname->getRawValue() );
00798 
00799         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00800 
00801         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00802         $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00803         $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00804 
00805         return $this->send();
00806     }
00807 
00815     protected function _getNewsSubsLink( $sId )
00816     {
00817         $myConfig = $this->getConfig();
00818         $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00819 
00820         $sUrl = $myConfig->getShopHomeURL().'cl=newsletter&amp;fnc=addme&amp;uid='.$sId;
00821         $sUrl.= ( $iActShopLang ) ? '&amp;lang='.$iActShopLang : "";
00822         return $sUrl;
00823     }
00824 
00835     public function sendNewsletterMail( $oNewsLetter, $oUser, $sSubject = null )
00836     {
00837         // shop info
00838         $oShop = $this->_getShop();
00839 
00840         //set mail params (from, fromName, smtp)
00841         $this->_setMailParams( $oShop );
00842 
00843         $sBody = $oNewsLetter->getHtmlText();
00844 
00845         if ( !empty($sBody) ) {
00846             $this->setBody( $sBody );
00847             $this->setAltBody( $oNewsLetter->getPlainText() );
00848         } else {
00849             $this->isHtml( false );
00850             $this->setBody( $oNewsLetter->getPlainText() );
00851         }
00852 
00853         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->getRawValue() );
00854 
00855         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00856         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00857         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00858 
00859         return $this->send();
00860     }
00861 
00871     public function sendSuggestMail( $oParams, $oProduct )
00872     {
00873         $myConfig = $this->getConfig();
00874 
00875         //sets language of shop
00876         $iCurrLang = $myConfig->getActiveShop()->getLanguage();
00877 
00878         // shop info
00879         $oShop = $this->_getShop( $iCurrLang );
00880 
00881         //sets language to article
00882         if ( $oProduct->getLanguage() != $iCurrLang ) {
00883             $oProduct->setLanguage( $iCurrLang );
00884             $oProduct->load( $oProduct->getId() );
00885         }
00886 
00887         // mailer stuff
00888         // send not pretending from suggesting user, as different email domain rise spam filters
00889         $this->setFrom( $oShop->oxshops__oxinfoemail->value );
00890         $this->setSMTP();
00891 
00892         // create messages
00893         $oSmarty = $this->_getSmarty();
00894         $this->setViewData( "product", $oProduct );
00895         $this->setUser( $oParams );
00896 
00897         $sArticleUrl = $oProduct->getLink();
00898 
00899         //setting recommended user id
00900         if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
00901             $sArticleUrl  = oxUtilsUrl::getInstance()->appendParamSeparator( $sArticleUrl );
00902             $sArticleUrl .= "su=" . $oActiveUser->getId();
00903         }
00904 
00905         $this->setViewData( "sArticleUrl", $sArticleUrl );
00906 
00907         // Process view data array through oxoutput processor
00908         $this->_processViewArray();
00909 
00910         $this->setBody( $oSmarty->fetch( $this->_sSuggestTemplate ) );
00911         $this->setAltBody( $oSmarty->fetch( $this->_sSuggestTemplatePlain ) );
00912         $this->setSubject( $oParams->send_subject );
00913 
00914         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00915         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00916 
00917         return $this->send();
00918     }
00919 
00928     public function sendInviteMail( $oParams )
00929     {
00930         $myConfig = $this->getConfig();
00931 
00932         //sets language of shop
00933         $iCurrLang = $myConfig->getActiveShop()->getLanguage();
00934 
00935         // shop info
00936         $oShop = $this->_getShop( $iCurrLang );
00937 
00938         // mailer stuff
00939         $this->setFrom( $oParams->send_email, $oParams->send_name );
00940         $this->setSMTP();
00941 
00942         // create messages
00943         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00944         $this->setUser( $oParams );
00945 
00946         $sHomeUrl = $this->getViewConfig()->getHomeLink();
00947 
00948         //setting recommended user id
00949         if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
00950             $sHomeUrl  = oxUtilsUrl::getInstance()->appendParamSeparator( $sHomeUrl );
00951             $sHomeUrl .= "su=" . $oActiveUser->getId();
00952         }
00953 
00954         if ( is_array($oParams->rec_email) && count($oParams->rec_email) > 0  ) {
00955             foreach ( $oParams->rec_email as $sEmail ) {
00956                 if ( !empty( $sEmail ) ) {
00957                     $sRegisterUrl  = oxUtilsUrl::getInstance()->appendParamSeparator( $sHomeUrl );
00958                     //setting recipient user email
00959                     $sRegisterUrl .= "re=" . md5($sEmail);
00960                     $this->setViewData( "sHomeUrl", $sRegisterUrl );
00961 
00962                     // Process view data array through oxoutput processor
00963                     $this->_processViewArray();
00964 
00965                     $this->setBody( $oSmarty->fetch( $this->_sInviteTemplate ) );
00966 
00967                     $this->setAltBody( $oSmarty->fetch( $this->_sInviteTemplatePlain ) );
00968                     $this->setSubject( $oParams->send_subject );
00969 
00970                     $this->setRecipient( $sEmail );
00971                     $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00972                     $this->send();
00973                     $this->clearAllRecipients();
00974                 }
00975             }
00976             return true;
00977         }
00978 
00979         return false;
00980     }
00981 
00991     public function sendSendedNowMail( $oOrder, $sSubject = null )
00992     {
00993         $myConfig = $this->getConfig();
00994 
00995         $iOrderLang = (int) ( isset( $oOrder->oxorder__oxlang->value ) ? $oOrder->oxorder__oxlang->value : 0 );
00996 
00997         // shop info
00998         $oShop = $this->_getShop( $iOrderLang );
00999 
01000         //set mail params (from, fromName, smtp)
01001         $this->_setMailParams( $oShop );
01002 
01003         //create messages
01004         $oLang = oxLang::getInstance();
01005         $oSmarty = $this->_getSmarty();
01006         $this->setViewData( "order", $oOrder );
01007         $this->setViewData( "shopTemplateDir", $myConfig->getTemplateDir(false) );
01008 
01009         //deprecated var
01010         $oUser = oxNew( 'oxuser' );
01011         $this->setViewData( "reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
01012 
01013         // Process view data array through oxoutput processor
01014         $this->_processViewArray();
01015 
01016         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
01017         $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
01018         //V send email in order language
01019         $iOldTplLang = $oLang->getTplLanguage();
01020         $iOldBaseLang = $oLang->getTplLanguage();
01021         $oLang->setTplLanguage( $iOrderLang );
01022         $oLang->setBaseLanguage( $iOrderLang );
01023 
01024         $oSmarty->security_settings['INCLUDE_ANY'] = true;
01025         // force non admin to get correct paths (tpl, img)
01026         $myConfig->setAdminMode( false );
01027         $this->setBody( $oSmarty->fetch( $this->_sSenedNowTemplate ) );
01028         $this->setAltBody( $oSmarty->fetch( $this->_sSenedNowTemplatePlain ) );
01029         $myConfig->setAdminMode( true );
01030         $oLang->setTplLanguage( $iOldTplLang );
01031         $oLang->setBaseLanguage( $iOldBaseLang );
01032         // set it back
01033         $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
01034 
01035         //Sets subject to email
01036         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxsendednowsubject->getRawValue() );
01037 
01038         $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
01039 
01040         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
01041         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01042 
01043         return $this->send();
01044     }
01045 
01060     public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
01061     {
01062         // shop info
01063         $oShop = $this->_getShop();
01064 
01065         //set mail params (from, fromName, smtp)
01066         $this->_setMailParams( $oShop );
01067 
01068         $this->setBody( $sMessage );
01069         $this->setSubject( $sSubject );
01070 
01071         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
01072         $sEmailAddress = $sEmailAddress ? $sEmailAddress : $oShop->oxshops__oxowneremail->value;
01073 
01074         $this->setFrom( $sEmailAddress, "" );
01075         $this->setReplyTo( $sEmailAddress, "" );
01076 
01077         //attaching files
01078         $blAttashSucc = true;
01079         $sAttPath = oxUtilsFile::getInstance()->normalizeDir($sAttPath);
01080         foreach ( $aAttFiles as $iNum => $sAttFile ) {
01081             $sFullPath = $sAttPath . $sAttFile;
01082             if ( @is_readable( $sFullPath ) && @is_file( $sFullPath ) ) {
01083                 $blAttashSucc = $this->addAttachment( $sFullPath, $sAttFile );
01084             } else {
01085                 $blAttashSucc = false;
01086                 $aError[] = array( 5, $sAttFile );   //"Error: backup file $sAttFile not found";
01087             }
01088         }
01089 
01090         if ( !$blAttashSucc ) {
01091             $aError[] = array( 4, "" );   //"Error: backup files was not sent to email ...";
01092             $this->clearAttachments();
01093             return false;
01094         }
01095 
01096         $aStatus[] = 3;     //"Mailing backup files ...";
01097         $blSend = $this->send();
01098         $this->clearAttachments();
01099 
01100         return $blSend;
01101     }
01102 
01113     public function sendEmail( $sTo, $sSubject, $sBody )
01114     {
01115         //set mail params (from, fromName, smtp)
01116         $this->_setMailParams();
01117 
01118         if ( is_array($sTo) ) {
01119             foreach ($sTo as $sAddress) {
01120                 $this->setRecipient( $sAddress, "" );
01121                 $this->setReplyTo( $sAddress, "" );
01122             }
01123         } else {
01124             $this->setRecipient( $sTo, "" );
01125             $this->setReplyTo( $sTo, "" );
01126         }
01127 
01128         //may be changed later
01129         $this->isHtml( false );
01130 
01131         $this->setSubject( $sSubject );
01132         $this->setBody( $sBody );
01133 
01134         return $this->send();
01135     }
01136 
01145     public function sendStockReminder( $aBasketContents, $sSubject = null )
01146     {
01147         $blSend = false;
01148 
01149         $oArticleList = oxNew( "oxarticlelist" );
01150         $oArticleList->loadStockRemindProducts( $aBasketContents );
01151 
01152         // nothing to remind?
01153         if ( $oArticleList->count() ) {
01154             $oShop = $this->_getShop();
01155 
01156             //set mail params (from, fromName, smtp... )
01157             $this->_setMailParams( $oShop );
01158             $oLang = oxLang::getInstance();
01159 
01160             $oSmarty = $this->_getSmarty();
01161             $this->setViewData( "articles", $oArticleList );
01162 
01163             // Process view data array through oxoutput processor
01164             $this->_processViewArray();
01165 
01166             $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
01167             $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
01168             $this->setBody( $oSmarty->fetch( $this->getConfig()->getTemplatePath( $this->_sReminderMailTemplate, false ) ) );
01169             $this->setAltBody( "" );
01170             $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_STOCKREMINDER_SUBJECT' ) );
01171 
01172             $blSend = $this->send();
01173         }
01174 
01175         return $blSend;
01176     }
01177 
01186     public function sendWishlistMail( $oParams )
01187     {
01188         $myConfig = $this->getConfig();
01189 
01190         $this->_clearMailer();
01191 
01192         // shop info
01193         $oShop = $this->_getShop();
01194 
01195         // mailer stuff
01196         $this->setFrom( $oParams->send_email, $oParams->send_name );
01197         $this->setSMTP();
01198 
01199         // create messages
01200         $oSmarty = $this->_getSmarty();
01201         $this->setUser( $oParams );
01202 
01203         // Process view data array through oxoutput processor
01204         $this->_processViewArray();
01205 
01206         $this->setBody( $oSmarty->fetch( $this->_sWishListTemplate ) );
01207         $this->setAltBody( $oSmarty->fetch( $this->_sWishListTemplatePlain ) );
01208         $this->setSubject( $oParams->send_subject );
01209 
01210         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
01211         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
01212 
01213         return $this->send();
01214     }
01215 
01226     public function sendPriceAlarmNotification( $aParams, $oAlarm, $sSubject = null )
01227     {
01228         $this->_clearMailer();
01229         $oShop = $this->_getShop();
01230 
01231         //set mail params (from, fromName, smtp)
01232         $this->_setMailParams( $oShop );
01233 
01234         $iAlarmLang = $oAlarm->oxpricealarm__oxlang->value;
01235 
01236         $oArticle = oxNew( "oxarticle" );
01237         $oArticle->setSkipAbPrice( true );
01238         $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
01239         $oLang = oxLang::getInstance();
01240 
01241         // create messages
01242         $oSmarty = $this->_getSmarty();
01243         $this->setViewData( "product", $oArticle );
01244         $this->setViewData( "email", $aParams['email']);
01245         $this->setViewData( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
01246 
01247         // Process view data array through oxoutput processor
01248         $this->_processViewArray();
01249 
01250         $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01251         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->getRawValue() );
01252         $this->setBody( $oSmarty->fetch( $this->_sOwnerPricealarmTemplate ) );
01253         $this->setFrom( $aParams['email'], "" );
01254         $this->setReplyTo( $aParams['email'], "" );
01255 
01256         return $this->send();
01257     }
01258 
01270     public function sendPricealarmToCustomer( $sRecipient, $oAlarm, $sBody = null, $sReturnMailBody = null )
01271     {
01272         $this->_clearMailer();
01273 
01274         $oShop = $this->_getShop();
01275 
01276         if ( $oShop->getId() != $oAlarm->oxpricealarm__oxshopid->value) {
01277             $oShop = oxNew( "oxshop" );
01278             $oShop->load( $oAlarm->oxpricealarm__oxshopid->value);
01279             $this->setShop( $oShop );
01280         }
01281 
01282         //set mail params (from, fromName, smtp)
01283         $this->_setMailParams( $oShop );
01284 
01285         // create messages
01286         $oSmarty = $this->_getSmarty();
01287 
01288         $this->setViewData( "product", $oAlarm->getArticle() );
01289         $this->setViewData( "oPriceAlarm", $oAlarm );
01290         $this->setViewData( "bidprice", $oAlarm->getFProposedPrice() );
01291         $this->setViewData( "currency", $oAlarm->getPriceAlarmCurrency() );
01292 
01293         // Process view data array through oxoutput processor
01294         $this->_processViewArray();
01295 
01296         $this->setRecipient( $sRecipient, $sRecipient );
01297         $this->setSubject( $oShop->oxshops__oxname->value );
01298 
01299         if ( $sBody === null ) {
01300             $sBody = $oSmarty->fetch( $this->_sPricealamrCustomerTemplate );
01301         }
01302 
01303         $this->setBody( $sBody );
01304 
01305         $this->addAddress( $sRecipient, $sRecipient );
01306         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01307 
01308         if ( $sReturnMailBody ) {
01309             return $this->getBody();
01310         } else {
01311             return $this->send();
01312         }
01313     }
01314 
01326     protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01327     {
01328         $sBody = $this->getBody();
01329         if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01330 
01331             $oFileUtils = oxUtilsFile::getInstance();
01332             $blReSetBody = false;
01333 
01334             // preparing imput
01335             $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01336             $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01337             $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01338 
01339             if (is_array($matches) && count($matches)) {
01340                 $aImageCache = array();
01341                 $myUtils = oxUtils::getInstance();
01342                 $myUtilsObject = oxUtilsObject::getInstance();
01343                 $oImgGenerator = oxNew( "oxDynImgGenerator" );
01344 
01345                 foreach ($matches as $aImage) {
01346 
01347                     $image = $aImage[1];
01348                     $sFileName = '';
01349                     if ( strpos( $image, $sDynImageDir ) === 0 ) {
01350                         $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01351                     } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01352                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01353                     } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01354                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01355                     }
01356 
01357                     if ( $sFileName && !@is_readable( $sFileName ) ) {
01358                         $sFileName = $oImgGenerator->getImagePath( $sFileName );
01359                     }
01360 
01361                     if ( $sFileName ) {
01362                         $sCId = '';
01363                         if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01364                             $sCId = $aImageCache[$sFileName];
01365                         } else {
01366                             $sCId = $myUtilsObject->generateUID();
01367                             $sMIME = $myUtils->oxMimeContentType($sFileName);
01368                             if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01369                                 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01370                                     $aImageCache[$sFileName] = $sCId;
01371                                 } else {
01372                                     $sCId = '';
01373                                 }
01374                             }
01375                         }
01376                         if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01377                             if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01378                                 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01379                                 $blReSetBody = true;
01380                             }
01381                         }
01382                     }
01383                 }
01384             }
01385 
01386             if ( $blReSetBody ) {
01387                 $this->setBody( $sBody );
01388             }
01389         }
01390     }
01391 
01399     public function setSubject( $sSubject = null )
01400     {
01401         // A. HTML entites in subjects must be replaced
01402         $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
01403 
01404         $this->set( "Subject", $sSubject );
01405     }
01406 
01412     public function getSubject()
01413     {
01414         return $this->Subject;
01415     }
01416 
01426     public function setBody( $sBody = null, $blClearSid = true )
01427     {
01428         if ( $blClearSid ) {
01429             $sBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&amp;shp=' . $this->getConfig()->getShopId(), $sBody);
01430         }
01431 
01432         $this->set( "Body", $sBody );
01433     }
01434 
01440     public function getBody()
01441     {
01442         return $this->Body;
01443     }
01444 
01454     public function setAltBody( $sAltBody = null, $blClearSid = true )
01455     {
01456         if ( $blClearSid ) {
01457             $sAltBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&amp;shp=' . $this->getConfig()->getShopId(), $sAltBody);
01458         }
01459 
01460         // A. alt body is used for plain text emails so we should eliminate HTML entities
01461         $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
01462 
01463         $this->set( "AltBody", $sAltBody );
01464     }
01465 
01471     public function getAltBody()
01472     {
01473         return $this->AltBody;
01474     }
01475 
01484     public function setRecipient( $sAddress = null, $sName = null )
01485     {
01486         try {
01487             parent::AddAddress( $sAddress, $sName );
01488 
01489             // copying values as original class does not allow to access recipients array
01490             $this->_aRecipients[] = array( $sAddress, $sName );
01491         } catch( Exception $oEx ) {
01492         }
01493     }
01494 
01502     public function getRecipient()
01503     {
01504         return $this->_aRecipients;
01505     }
01506 
01513     public function clearAllRecipients()
01514     {
01515         $this->_aRecipients = array();
01516         parent::clearAllRecipients();
01517     }
01518 
01530     public function setReplyTo( $sEmail = null, $sName = null )
01531     {
01532         if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01533             $sEmail = $this->_getShop()->oxshops__oxorderemail->value;
01534         }
01535 
01536         $this->_aReplies[] = array( $sEmail, $sName );
01537 
01538         try {
01539             parent::addReplyTo( $sEmail, $sName );
01540         } catch( Exception $oEx ) {
01541         }
01542     }
01543 
01549     public function getReplyTo()
01550     {
01551         return $this->_aReplies;
01552     }
01553 
01559     public function clearReplyTos()
01560     {
01561         $this->_aReplies = array();
01562         parent::clearReplyTos();
01563     }
01564 
01573     public function setFrom( $sFromAdress, $sFromName = null )
01574     {
01575         // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
01576         // this is simple but must work
01577         // dodger Task #1532 field "From" in emails from shops
01578         $sFromAdress = substr($sFromAdress, 0, 150);
01579         $sFromName   = substr($sFromName, 0, 150);
01580 
01581         try {
01582             parent::setFrom( $sFromAdress, $sFromName );
01583         } catch( Exception $oEx ) {
01584         }
01585     }
01586 
01592     public function getFrom()
01593     {
01594         return $this->From;
01595     }
01596 
01602     public function getFromName()
01603     {
01604         return $this->FromName;
01605     }
01606 
01615     public function setCharSet( $sCharSet = null )
01616     {
01617         if ( $sCharSet ) {
01618             $this->_sCharSet = $sCharSet;
01619         } else {
01620             $this->_sCharSet = oxLang::getInstance()->translateString( "charset" );
01621         }
01622         $this->set( "CharSet", $this->_sCharSet );
01623     }
01624 
01632     public function setMailer( $sMailer = null )
01633     {
01634         $this->set( "Mailer", $sMailer );
01635     }
01636 
01642     public function getMailer()
01643     {
01644         return $this->Mailer;
01645     }
01646 
01654     public function setHost( $sHost = null )
01655     {
01656         $this->set( "Host", $sHost );
01657     }
01658 
01664     public function getErrorInfo()
01665     {
01666         return $this->ErrorInfo;
01667     }
01668 
01677     public function setMailWordWrap( $iWordWrap = null )
01678     {
01679         $this->set( "WordWrap", $iWordWrap );
01680     }
01681 
01689     public function setUseInlineImages( $blUseImages = null )
01690     {
01691         $this->_blInlineImgEmail = $blUseImages;
01692     }
01693 
01704     public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01705     {
01706         $this->_aAttachments[] = array( $sAttPath, $sAttFile, $sEncoding, $sType );
01707         $blResult = false;
01708 
01709         try {
01710              $blResult = parent::addAttachment( $sAttPath, $sAttFile, $sEncoding, $sType );
01711         } catch( Exception $oEx ) {
01712         }
01713 
01714         return $blResult;
01715     }
01716 
01728     public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01729     {
01730         $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01731         return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01732     }
01733 
01739     public function getAttachments()
01740     {
01741         return $this->_aAttachments;
01742     }
01743 
01749     public function clearAttachments()
01750     {
01751         $this->_aAttachments = array();
01752         return parent::clearAttachments();
01753     }
01754 
01764     public function headerLine($sName, $sValue)
01765     {
01766         if (stripos($sName, 'X-') !== false) {
01767             return;
01768         }
01769         return parent::headerLine($sName, $sValue);
01770     }
01771 
01777     protected function _getUseInlineImages()
01778     {
01779         return $this->_blInlineImgEmail;
01780     }
01781 
01787     protected function _sendMailErrorMsg()
01788     {
01789         // build addresses
01790         $sToAdress  = "";
01791         $sToName    = "";
01792 
01793         $aRecipients = $this->getRecipient();
01794 
01795         $sOwnerMessage  = "Error sending eMail(". $this->getSubject().") to: \n\n";
01796 
01797         foreach ( $aRecipients as $aEMail ) {
01798             $sOwnerMessage .= $aEMail[0];
01799             $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01800             $sOwnerMessage .= " \n ";
01801         }
01802         $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01803 
01804         // shop info
01805         $oShop = $this->_getShop();
01806 
01807         $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop!", $sOwnerMessage);
01808 
01809         return $blRet;
01810     }
01811 
01821     protected function _addUserInfoOrderEMail( $oOrder )
01822     {
01823         return $oOrder;
01824     }
01825 
01835     protected function _addUserRegisterEmail( $oUser )
01836     {
01837         return $oUser;
01838     }
01839 
01849     protected function _addForgotPwdEmail( $oShop )
01850     {
01851         return $oShop;
01852     }
01853 
01863     protected function _addNewsletterDbOptInMail( $oUser )
01864     {
01865         return $oUser;
01866     }
01867 
01873     protected function _clearMailer()
01874     {
01875         $this->clearAllRecipients();
01876         $this->clearReplyTos();
01877         $this->clearAttachments();
01878 
01879         //workaround for phpmailer as it doesn't cleanup as it should
01880         $this->error_count = 0;
01881         $this->ErrorInfo   = '';
01882     }
01883 
01891     protected function _setMailParams( $oShop = null )
01892     {
01893         $this->_clearMailer();
01894 
01895         if ( !$oShop ) {
01896             $oShop = $this->_getShop();
01897         }
01898 
01899         $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01900         $this->setSmtp( $oShop );
01901     }
01902 
01912     protected function _getShop( $iLangId = null, $iShopId = null )
01913     {
01914 
01915         if ( isset( $this->_oShop ) ) {
01916             return $this->_oShop;
01917         }
01918 
01919         $myConfig = $this->getConfig();
01920 
01921         if ( $iLangId === null ) {
01922             $oShop = $myConfig->getActiveShop();
01923         } else {
01924             $oShop = oxNew( 'oxshop' );
01925             $oShop->loadInLang( $iLangId, $myConfig->getShopId() );
01926         }
01927 
01928         return $this->_oShop = $oShop;
01929     }
01930 
01939     protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
01940     {
01941         $this->set( "SMTPAuth", true );
01942         $this->set( "Username", $sUserName );
01943         $this->set( "Password", $sUserPassword );
01944     }
01945 
01953     protected function _setSmtpDebug( $blDebug = null )
01954     {
01955         $this->set( "SMTPDebug", $blDebug );
01956     }
01957 
01963     protected function _setMailerPluginDir()
01964     {
01965         $this->set( "PluginDir", getShopBasePath() . "core/phpmailer/" );
01966     }
01967 
01974     protected function _makeOutputProcessing()
01975     {
01976         $oOutput = oxNew( "oxoutput" );
01977         $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
01978         $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
01979         $oOutput->processEmail( $this );
01980     }
01981 
01987     protected function _sendMail()
01988     {
01989         $blResult = false;
01990         try {
01991              $blResult = parent::send();
01992         } catch( Exception $oEx ) {
01993         }
01994 
01995         return $blResult;
01996     }
01997 
01998 
02004     protected function _processViewArray()
02005     {
02006         $oSmarty = $this->_getSmarty();
02007         $oOutputProcessor = oxNew( "oxoutput" );
02008 
02009         // processing all setted view data
02010         foreach ( $this->_aViewData as $sKey => $sValue ) {
02011             $oSmarty->assign( $sKey, $sValue );
02012         }
02013 
02014         // processing assigned smarty variables
02015         $aNewSmartyArray  = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
02016 
02017         foreach ( $aNewSmartyArray as $key => $val ) {
02018             $oSmarty->assign( $key, $val );
02019         }
02020     }
02021 
02027     public function getCharset()
02028     {
02029         if ( !$this->_sCharSet ) {
02030             return oxLang::getInstance()->translateString("charset");
02031         } else {
02032             return $this->CharSet;
02033         }
02034     }
02035 
02041     public function getShop()
02042     {
02043         return $this->_getShop();
02044     }
02045 
02053     public function setShop( $oShop )
02054     {
02055         $this->_oShop = $oShop;
02056     }
02057 
02063     public function getViewConfig()
02064     {
02065         return $this->getConfig()->getActiveView()->getViewConfig();
02066     }
02067 
02073     public function getView()
02074     {
02075         return $this->getConfig()->getActiveView();
02076     }
02077 
02083     public function getCurrency()
02084     {
02085         $oConfig = oxConfig::getInstance();
02086 
02087         return $oConfig->getActShopCurrencyObject();
02088     }
02089 
02098     public function setViewData( $sKey, $sValue )
02099     {
02100         $this->_aViewData[$sKey] = $sValue;
02101     }
02102 
02108     public function getViewData()
02109     {
02110         return $this->_aViewData;
02111     }
02112 
02120     public function getViewDataItem( $sKey )
02121     {
02122         if ( isset($this->_aViewData[$sKey]) ) {
02123             return $this->_aViewData;
02124         }
02125     }
02126 
02134     public function setUser( $oUser)
02135     {
02136         $this->_aViewData["oUser"] = $oUser;
02137     }
02138 
02144     public function getUser()
02145     {
02146         return $this->_aViewData["oUser"];
02147     }
02148 
02149 }