/**
	 * Builds and sends e-mail
	 *
	 * @param UserTable  $user
	 * @param string     $mailFrom_email
	 * @param string     $mailFrom_name
	 * @param string     $mailTo
	 * @param string     $mailSubject
	 * @param string     $mailBody
	 * @param string     $mailHtml
	 * @param string     $mailCC
	 * @param string     $mailBCC
	 * @param string     $mailAttachments
	 * @param string[]   $extraStrings
	 * @return void
	 */
	protected function sendMail( $user, $mailFrom_email, $mailFrom_name, $mailTo, $mailSubject, $mailBody, $mailHtml, $mailCC, $mailBCC, $mailAttachments, $extraStrings ) {
		global $_CB_framework;

		cbimport( 'cb.tabs' );

		$cbUser					=	CBuser::getInstance( $user->id );

		if ( ! $cbUser ) {
			return;
		}

		$mailFrom_email			=	trim( $cbUser->replaceUserVars( $mailFrom_email, false, false, array(), false ) );
		$mailFrom_name			=	trim( $cbUser->replaceUserVars( $mailFrom_name, false, false, array(), false ) );
		$mailTo					=	trim( $cbUser->replaceUserVars( $mailTo, false, false, array(), false ) );
		$mailCC					=	trim( $cbUser->replaceUserVars( $mailCC, false, false, array(), false ) );
		$mailBCC				=	trim( $cbUser->replaceUserVars( $mailBCC, false, false, array(), false ) );
		$mailSubject			=	trim( $cbUser->replaceUserVars( CBPTXT::T( $mailSubject ), false, false, $extraStrings, false ) );
		$mailBody				=	trim( $cbUser->replaceUserVars( CBPTXT::T( $mailBody ), false, false, $extraStrings, false ) );
		$mailAttachments		=	trim( $mailAttachments );

		if ( $mailTo != '' ) {
			$mailTo				=	preg_split( '/ *, */', $mailTo );
		} else {
			return;
		}

		if ( $mailCC != '' ) {
			$mailCC				=	preg_split( '/ *, */', $mailCC );
		} else {
			$mailCC				=	null;
		}

		if ( $mailBCC != '' ) {
			$mailBCC			=	preg_split( '/ *, */', $mailBCC );
		} else {
			$mailBCC			=	null;
		}

		if ( $mailAttachments != '' ) {
			$mailAttachments	=	preg_split( '/ *, */', $mailAttachments );
		} else {
			$mailAttachments	=	null;
		}

		if ( $mailTo && ( $mailSubject || $mailBody ) ) {
			comprofilerMail( $mailFrom_email, $mailFrom_name, $mailTo, $_CB_framework->getCfg( 'sitename' ).' - '.$mailSubject, $mailBody, $mailHtml, $mailCC, $mailBCC, $mailAttachments );
		}
	}
 /**
  * Internal function to sends an email from a user to another user
  *
  * @param  UserTable|stdClass  $toUser        Receiver
  * @param  UserTable           $fromUser      Sender
  * @param  string              $replyToName   Reply-To name
  * @param  string              $replyToEmail  Reply-To email address
  * @param  string              $subject       Subject
  * @param  string              $message       HTML message for PMS
  * @param  boolean             $addPrefix     Add prefix text to explain who is sending from which site ?
  * @param  int                 $mode          false = plain text, true = HTML
  * @param  null|string         $cc            Email CC address
  * @param  null|string         $bcc           Email BCC address
  * @param  null|string         $attachment    Email attachment files
  * @param  boolean|string      $fromEmail     From email address (overrides from row email): false = from row email, null = system email, otherwise use as specified
  * @param  boolean|string      $fromName      From name (overrides from row name): false = from row name, null = system name, otherwise use a specified
  * @return boolean                            Result
  */
 private function _sendEmailMSG($toUser, $fromUser, $replyToName, $replyToEmail, $subject, $message, $addPrefix = false, $mode = 0, $cc = null, $bcc = null, $attachment = null, $fromEmail = false, $fromName = false)
 {
     global $_CB_framework, $ueConfig, $_PLUGINS, $_SERVER;
     $_PLUGINS->trigger('onBeforeSendEmailMSG', array($this, &$toUser, &$fromUser, &$subject, &$message, &$addPrefix, &$mode, &$cc, &$bcc, &$attachment));
     if ($addPrefix) {
         $toUserLanguage = CBuser::getInstance((int) $toUser->id)->getUserData()->getUserLanguage();
         $savedLanguage = CBTxt::setLanguage($toUserLanguage);
         $preMsg = $this->_replaceVariables(CBTxt::T('EMAIL_NOTE_MESSAGE_FROM_NAME_AT_SITENAME_TO_YOU', '------- This is a message from [formatname] at [sitename] ([siteurl]) to you: -------') . "\r\n\r\n", $fromUser, $mode);
         $postMsg = $this->_replaceVariables("\r\n\r\n" . CBTxt::T('EMAIL_NOTE', '------ NOTES: ------') . (isset($ueConfig['allow_email_replyto']) && $ueConfig['allow_email_replyto'] == 2 ? "\r\n\r\n" . CBTxt::T('EMAIL_NOTE_WHEN_REPLYING_CHECK_ADDRESS', 'When replying, please check carefully that the email address of [formatname] is [email].') : null) . "\r\n\r\n" . CBTxt::T('EMAIL_NOTE_UNSEEN_ADDRESS', 'This user did not see your email address. If you reply the recipient will have your email address.') . "\r\n\r\n" . CBTxt::T('EMAIL_NOTE_CONTENTS_DISCLAIMER', '[sitename] owners cannot accept any responsibility for the contents of the email and of user email addresses.'), $fromUser, $mode);
         $message = $preMsg . $message . $postMsg;
         $fromName = getNameFormat($fromUser->name, $fromUser->username, $ueConfig['name_format']) . ' @ ' . $_CB_framework->getCfg('sitename');
         CBTxt::setLanguage($savedLanguage);
     }
     $this->errorMSG = null;
     $result = comprofilerMail($fromEmail !== false ? $fromEmail : $fromUser->email, $fromName !== false ? $fromName : $fromUser->name, $toUser->email, $subject, $message, $mode, $cc, $bcc, $attachment, $replyToEmail, $replyToName, $this->mailerProperties, $this->errorMSG);
     $_PLUGINS->trigger('onAfterSendEmailMSG', array($result, $this, $toUser, $fromUser, $subject, $message, $addPrefix, $mode, $cc, $bcc, $attachment));
     return $result;
 }
 /**
  * WARNING: UNCHECKED ACCESS! On purpose unchecked access for M2M operations
  * Generates the HTML to display for a specific component-like page for the tab. WARNING: unchecked access !
  * @param  null       $tab
  * @param  UserTable  $user      the user being displayed
  * @param  int        $ui        1 for front-end, 2 for back-end
  * @param  array      $postdata  _POST data for saving edited tab content as generated with getEditTab
  * @return mixed                 either string HTML for tab content, or false if ErrorMSG generated
  */
 public function getCBpluginComponent($tab, &$user, $ui, &$postdata)
 {
     global $_CB_framework, $ueConfig, $_GET;
     cbpaidErrorHandler::on();
     $result = null;
     $do = cbGetParam($_GET, 'do');
     switch ($do) {
         case null:
             $return = $this->getTabComponent($tab, $user, $ui, $postdata);
             cbpaidErrorHandler::keepTurnedOn();
             break;
         case 'display_subscriptions':
             if ($user && $user->id && $_CB_framework->myId()) {
                 $regTitle = strip_tags(CBPTXT::T($this->params->get('regTitle', "Subscriptions")));
                 outputCbTemplate();
                 $_CB_framework->setPageTitle($regTitle);
                 $_CB_framework->appendPathWay($regTitle);
                 $pre = '<div class="cbPageOuter"><div class="cbPageInner">';
                 $post = '</div></div><div class="cbClr"> </div>';
                 $return = $pre . $this->displayUserTab($user) . $post;
             } else {
                 if ($_CB_framework->getCfg('allowUserRegistration') == '0' && (!isset($ueConfig['reg_admin_allowcbregistration']) || $ueConfig['reg_admin_allowcbregistration'] != '1')) {
                     $return = _UE_NOT_AUTHORIZED . '<br />' . _UE_DO_LOGIN;
                 } else {
                     /*
                     $registrationUrl	=	cbSef( 'index.php?option=com_comprofiler&task=registers' );
                     $registrationLink	=	'<a href="' . $registrationUrl . '">' . _UE_REGISTER . '</a>';
                     $loginRegisterText	=	sprintf( CBPTXT::Th("Please login or %s"), $registrationLink );
                     $return				=	_UE_NOT_AUTHORIZED . '<br /><br />' . $loginRegisterText;
                     */
                     $accessPlans = null;
                     $return = cbpaidControllerOffer::displaySpecificPlans($accessPlans, null, $user, '');
                 }
             }
             break;
         case 'accessdenied':
             $params = cbpaidApp::settingsParams();
             $accessRedirectLink = $params->get('subscriptionNeededRedirectLink');
             if ($accessRedirectLink) {
                 $textMessage = $params->get('subscriptionNeededText', "A membership is needed for access.");
                 $return = null;
                 cbRedirect(cbSef($accessRedirectLink, false), CBPTXT::T($textMessage), 'warning');
             } else {
                 /** @noinspection PhpIncludeInspection */
                 include_once cbpaidApp::getAbsoluteFilePath('plugin/cbsubscontent/cbsubs.content_deniedview.php');
                 $accessDeniedView = new cbpaidContentAccessDeniedView();
                 $return = $accessDeniedView->display($user, $this);
             }
             break;
         case 'displayplans':
             $plansParam = cbGetParam($_GET, 'plans');
             $plans = null;
             $preselect = null;
             if ($plansParam) {
                 $plansParam = explode('-', $plansParam);
                 foreach ($plansParam as $p) {
                     $pN = (int) $p;
                     if ($pN) {
                         $plans[] = $pN;
                         if (substr($p, -1) == 's') {
                             $preselect[] = $pN;
                         }
                     }
                 }
             }
             if ($user === null || $user->id == $_CB_framework->myId()) {
                 $introText = CBPTXT::Th($this->params->get('plansDisplayIntroText', "We suggest subscribing to following subscriptions:"));
                 $return = cbpaidControllerOffer::displaySpecificPlans($plans, $preselect, $user, $introText);
             } else {
                 $return = _UE_NOT_AUTHORIZED;
             }
             break;
         case 'massexpire':
             // cron
             $params = cbpaidApp::settingsParams();
             $key = cbGetParam($_GET, 'key');
             if ($key && $key == md5($params->get('license_number')) && $params->get('massexpirymethod', 0) >= 2) {
                 $limit = $params->get('massexpirynumber', 100);
                 // mass-expire 100 subscriptions at a time on the way if not exipring a particular user:
                 $plansMgr = cbpaidPlansMgr::getInstance();
                 $plansMgr->checkAllSubscriptions((int) $limit);
                 $return = null;
             } else {
                 $return = CBPTXT::Th("Invalid mass-expiry link: link is in global CBSubs settings.");
             }
             break;
         case 'autopayments':
             // cron
             $params = cbpaidApp::settingsParams();
             $key = cbGetParam($_GET, 'key');
             if ($key && $key == md5($params->get('license_number'))) {
                 $limit = $params->get('massautorenewalsnumber', 100);
                 // mass-autorenew 100 subscriptions at a time:
                 $results = cbpaidOrdersMgr::getInstance()->triggerScheduledAutoRecurringPayments((int) $limit);
                 $return = implode("\r\n\r\n", $results);
                 $massrenewalemail = trim($params->get('massrenewalemail', ''));
                 if ($massrenewalemail) {
                     cbimport('cb.notification');
                     $recipients = explode(',', $massrenewalemail);
                     if ($return) {
                         $body = CBPTXT::T("CBSubs has just processed auto-recurring payments as follows:") . "\r\n\r\n" . $return . "\r\n\r\n" . CBPTXT::T("This is an automated email, do not reply.") . "\r\n\r\n";
                         comprofilerMail('', '', $recipients, CBPTXT::T("CBSubs has processed auto-recurring payments"), $body);
                     }
                 }
                 if ($params->get('massrenewaloutputincron', 1) != 1) {
                     // silence output to Cron:
                     $return = null;
                 }
             } else {
                 $return = CBPTXT::Th("Invalid auto-renewals link: link is in global CBSubs settings.");
             }
             break;
         default:
             $return = sprintf(CBPTXT::Th("No valid %s action chosen"), '"do"') . '.';
             break;
     }
     cbpaidErrorHandler::off();
     return $return;
 }
 function _sendEmailMSG($to, $from, $sub, $msg, $addPrefix = false, $mode = 0, $cc = null, $bcc = null, $attachment = null)
 {
     //BB: add html
     global $_CB_framework, $ueConfig, $_SERVER;
     if ($addPrefix) {
         $uname = getNameFormat($from->name, $from->username, $ueConfig['name_format']);
         $premessage = sprintf(_UE_SENDEMAILNOTICE, $uname, cb_html_entity_decode_all($_CB_framework->getCfg('sitename')), $_CB_framework->getCfg('live_site'));
         if (isset($ueConfig['allow_email_replyto']) && $ueConfig['allow_email_replyto'] == 2) {
             $premessage .= sprintf(_UE_SENDEMAILNOTICE_REPLYTO, $uname, $from->email);
         }
         $postmessage = sprintf(_UE_SENDEMAILNOTICE_DISCLAIMER, cb_html_entity_decode_all($_CB_framework->getCfg('sitename')));
         // $premessage .=	sprintf(_UE_SENDEMAILNOTICE_MESSAGEHEADER, $uname);
         $msg = $premessage . $msg . $postmessage;
         $from->name = $uname . " @ " . cb_html_entity_decode_all($_CB_framework->getCfg('sitename'));
         // $ueConfig['reg_email_name']
     }
     //		if (class_exists("mosPHPMailer")) {
     $res = comprofilerMail($from->email, $from->name, $to->email, $sub, $msg, $mode, $cc, $bcc, $attachment, $from->replytoEmail, $from->replytoName);
     /*		} else if (function_exists( 'mosMail' )) {
     			$res = mosMail($from->email, $from->name, $to->email, $sub, $msg);
     		} else { //TODO drop this once we are dedicated to >= 4.5.2
     			$EOL			=	defined( 'PHP_EOL' ) ? PHP_EOL : '\n';	// assume Linux for old systems.
     			$header  = "MIME-Version: 1.0" . $EOL;
     			$header .= "Content-type: text/plain; charset=" . $_CB_framework->outputCharset() . $EOL;
     			$header .= "Content-Transfer-encoding: 8bit" . $EOL;
     			$fromTag  = $from->name." <" . $from->email . ">";
     			$header .= "From: ".$fromTag. $EOL;
     			$replyTag = $from->replytoName." <" . $from->replytoEmail . ">";
     			$header .= "Reply-To: ".$replyTag. $EOL;
     			$header .= "Organization: ".cb_html_entity_decode_all($_CB_framework->getCfg( 'sitename' )). $EOL;
     			$header .= "Message-ID: <".md5(uniqid(time()))."@{$_SERVER['SERVER_NAME']}>" . $EOL;
     			$header .= "Return-Path: ".$from->email. $EOL;
     			$header .= "X-Priority: 3" . $EOL;
     			$header .= "X-MSmail-Priority: Low" . $EOL;
     			$header .= "X-Mailer: PHP\r\n"; //hotmail and others dont like PHP mailer. --Microsoft Office Outlook, Build 11.0.5510
     			$header .= "X-Sender: ".$from->email. $EOL . $EOL;
     			$res =  mail($to->email, $sub, $msg, $header);
     		}
     */
     return $res;
 }
Exemple #5
0
	/**
	 * Udde PMS notification by email
	 *
	 * @access private
	 * @param int $var_msgid
	 * @param int $var_fromid
	 * @param int $var_toid
	 * @param string $var_message
	 * @param int $emn_option
	 * @param boolean $udde_sysm
	 */
	function _pmsUddeDispatchEMN($var_msgid, $var_fromid, $var_toid, $var_message, $emn_option, $udde_sysm) {
		global $_CB_database, $_CB_framework;

// --
		$params = $this->params;
		$pmsType = $params->get('pmsType', '1');
        $udde_sysm = "System";
        $config_realnames = "0";
        $config_cryptmode = 0;
        $config_cryptkey = 'uddeIMcryptkey';
        
		if ($pmsType==4) { // uddeIM 1.0+
			require_once( $_CB_framework->getCfg('absolute_path') . "/components/com_uddeim/crypt.class.php");
			
			if(file_exists( $_CB_framework->getCfg('absolute_path') . "/administrator/components/com_uddeim/config.class.php")) {
				include_once( $_CB_framework->getCfg('absolute_path') . "/administrator/components/com_uddeim/config.class.php");
			}
			$config = new uddeimconfigclass();
			if (isset($config->realnames)) {
				$config_realnames = $config->realnames;
			}
			if (isset($config->cryptmode)) {
				$config_cryptmode = $config->cryptmode;
			}
            if (file_exists( $_CB_framework->getCfg('absolute_path') . "/administrator/components/com_uddeim/uddeim_crypt.php" )) {
				require_once ( $_CB_framework->getCfg('absolute_path') . "/administrator/components/com_uddeim/uddeim_crypt.php" );
			}
			if (isset($config->cryptkey)) {
				$config_cryptkey = $config->cryptkey;
			}
			if (isset($config->emailtrafficenabled)) {
				$config_emailtrafficenabled = $config->emailtrafficenabled;		
			}
			if (isset($config->emailwithmessage)) {
				$config_emailwithmessage = $config->emailwithmessage;
			} 
			if (isset($config->emn_sendername)) {
				$config_emn_sendername = $config->emn_sendername;
			}
			if (isset($config->emn_sendermail)) {
				$config_emn_sendermail = $config->emn_sendermail;
			}			
		} else {
			if (file_exists( $_CB_framework->getCfg('absolute_path') . "/administrator/components/com_uddeim/uddeim_config.php")) {
				include_once( $_CB_framework->getCfg('absolute_path') . "/administrator/components/com_uddeim/uddeim_config.php");
			} else {
				return;
			}
		}		

// --		

		// load the uddeim lang file		
		$adminpath = $_CB_framework->getCfg('absolute_path') . "/administrator/components/com_uddeim";
		if (file_exists($adminpath.'/language/'.$_CB_framework->getCfg( 'lang' ).'.php')) {
			include_once($adminpath.'/language/'.$_CB_framework->getCfg( 'lang' ).'.php');
		} elseif (file_exists($adminpath.'/language/english.php')) {
			include_once($adminpath.'/language/english.php');
		} 
		
		// if e-mail traffic stopped, don't send.
		if (isset($config_emailtrafficenabled) && !($config_emailtrafficenabled > 0)) {
			return;
		}
		
		if (isset($config_realnames) && $config_realnames) {
			$sql = "SELECT name FROM #__users WHERE `id`=".(int) $var_fromid;
		} else {
			$sql = "SELECT username FROM #__users WHERE `id`=".(int) $var_fromid;	
		}
		$_CB_database->setQuery($sql);
		$var_fromname=$_CB_database->loadResult();
		if (!$var_fromname) {
			$var_fromname = $udde_sysm;
		}
		
		if (isset($config_realnames) && $config_realnames) {
			$sql = "SELECT name AS displayname, email FROM #__users WHERE `id`=".(int) $var_toid;	
		} else {
			$sql = "SELECT username AS displayname, email FROM #__users WHERE `id`=".(int) $var_toid;
		}
		$_CB_database->setQuery($sql);
		$results=$_CB_database->loadObjectList();
		foreach ($results as $result) {
			$var_toname = $result->displayname;
			$var_tomail = $result->email;
		}
		
		if (!$var_tomail) {
			return;
		}

		$msglink		=	cbSef( "index.php?option=com_uddeim&task=show&messageid=" . (int) $var_msgid, false );

		if ($emn_option==1) {
			$var_body = _UDDEIM_EMN_FORGETMENOT;
			$var_body = str_replace("%livesite%", $_CB_framework->getCfg( 'live_site' ), $var_body);
			$var_body = str_replace("%you%", $var_toname, $var_body);
			$var_body = str_replace("%site%", $_CB_framework->getCfg( 'sitename' ), $var_body);
			$var_body = str_replace("%msglink%", $msglink, $var_body);
		} else {
			if (isset($config_emailwithmessage) && $config_emailwithmessage) {
				$var_body = _UDDEIM_EMN_BODY_WITHMESSAGE;
				$var_body = str_replace("%livesite%", $_CB_framework->getCfg( 'live_site' ), $var_body);
				$var_body = str_replace("%you%", $var_toname, $var_body);
				$var_body = str_replace("%site%", $_CB_framework->getCfg( 'sitename' ), $var_body);
				$var_body = str_replace("%msglink%", $msglink, $var_body);
				$var_body = str_replace("%user%", $var_fromname, $var_body);
				$var_body = str_replace("%pmessage%", $var_message, $var_body);
			} else {
				$var_body = _UDDEIM_EMN_BODY_NOMESSAGE;
				$var_body = str_replace("%livesite%", $_CB_framework->getCfg( 'live_site' ), $var_body);
				$var_body = str_replace("%you%", $var_toname, $var_body);
				$var_body = str_replace("%site%", $_CB_framework->getCfg( 'sitename' ), $var_body);
				$var_body = str_replace("%msglink%", $msglink, $var_body);
				$var_body = str_replace("%user%", $var_fromname, $var_body);
			}
		}
		
		$subject = _UDDEIM_EMN_SUBJECT;
		$subject = str_replace("%livesite%", $_CB_framework->getCfg( 'live_site' ), $subject);
		$subject = str_replace("%site%", $_CB_framework->getCfg( 'sitename' ), $subject);
		$subject = str_replace("%you%", $var_toname, $subject);
		$subject = str_replace("%user%", $var_fromname, $subject);
		
/*
		$header  = "MIME-Version: 1.0\n";
		// $header .= "Content-type: text/plain; charset=iso-8859-1\n";
		$header .= "Content-type: text/plain; charset=".$this->_pmsUddeGetCharsetname($config_mailcharset)."\n";
		$header .= "Organization: ".$_CB_framework->getCfg( 'sitename' )."\n";
		$header .= "Content-Transfer-encoding: 8bit\n";
		$header .= "From: \"".$config_emn_sendername."\" <".$config_emn_sendermail.">\n";
		$header .= "Reply-To: ".$config_emn_sendermail."\n";
		$header .= "Message-ID: <".md5(uniqid(time()))."@{$_SERVER['SERVER_NAME']}>\n";
		$header .= "Return-Path: ".$config_emn_sendermail."\n";            
		$header .= "X-Priority: 3\n"; 
		$header .= "X-MSmail-Priority: Low\n"; 
	            // $header .= "X-Mailer: PHP\r\n"; //hotmail and others dont like PHP mailer. --Microsoft Office Outlook, Build 11.0.5510
		$header .= "X-Mailer: Microsoft Office Outlook, Build 11.0.5510\n";
		$header .= "X-Sender: ".$config_emn_sendermail."\n";
	            
		// debug:
		// $header.="\n".$this->_pmsMailcompatible($var_body);
 		// die($header);
		
		// -----
		if(mail ($var_tomail,$subject,$this->_pmsMailcompatible($var_body),$header)) {
*/
//		$cbNotif = new cbNotification;
//		if ($cbNotif->sendUserEmail($var_toid,$var_fromid,$subject,$this->_pmsMailcompatible($var_body))) {
		if (comprofilerMail($config_emn_sendermail, $config_emn_sendername, $var_tomail,$subject,$this->_pmsMailcompatible($var_body))) {
			// set the remindersent status of this user to true
			$sql="SELECT count(id) FROM #__uddeim_emn WHERE userid=".(int) $var_toid;
			$_CB_database->setQuery($sql);
			$exists=$_CB_database->loadResult();
			if($exists) {
				$sql="UPDATE #__uddeim_emn SET remindersent=".(int) $this->_pmsUddeGetTime(time())." WHERE userid=".(int) $var_toid;
				$_CB_database->setQuery($sql);
				if (!$_CB_database->query()) {
					die("SQL error" . $_CB_database->stderr(true));
				}	
			} else {
				$sql="INSERT INTO #__uddeim_emn (userid, status, remindersent) VALUES (".(int) $var_toid.", 0, ".(int) $this->_pmsUddeGetTime(time()).")";
				$_CB_database->setQuery($sql);
				if (!$_CB_database->query()) {
					die("SQL error" . $_CB_database->stderr(true));
				} // end if database query
			} // end else
		} // end if mail
	} // end function
Exemple #6
0
	/**
	 * @param cbautoactionsActionTable $trigger
	 * @param UserTable $user
	 */
	public function execute( $trigger, $user )
	{
		foreach ( $trigger->getParams()->subTree( 'email' ) as $row ) {
			/** @var ParamsInterface $row */
			$mailTo										=	$row->get( 'to', null, GetterInterface::STRING );

			if ( ! $mailTo ) {
				$mailTo									=	$user->get( 'email' );
			} else {
				$mailTo									=	$trigger->getSubstituteString( $mailTo );
			}

			if ( ! $mailTo ) {
				if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
					var_dump( CBTxt::T( 'AUTO_ACTION_EMAIL_NO_TO', ':: Action [action] :: Email skipped due to missing to', array( '[action]' => (int) $trigger->get( 'id' ) ) ) );
				}

				continue;
			}

			$mailSubject								=	$trigger->getSubstituteString( $row->get( 'subject', null, GetterInterface::STRING ) );

			if ( ! $mailSubject ) {
				if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
					var_dump( CBTxt::T( 'AUTO_ACTION_EMAIL_NO_SBJ', ':: Action [action] :: Email skipped due to missing subject', array( '[action]' => (int) $trigger->get( 'id' ) ) ) );
				}

				continue;
			}

			$mailBody									=	$trigger->getSubstituteString( $row->get( 'body', null, GetterInterface::RAW ), false );

			if ( ! $mailBody ) {
				if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
					var_dump( CBTxt::T( 'AUTO_ACTION_EMAIL_NO_BODY', ':: Action [action] :: Email skipped due to missing body', array( '[action]' => (int) $trigger->get( 'id' ) ) ) );
				}

				continue;
			}

			$mailHtml									=	(int) $row->get( 'mode', null, GetterInterface::INT );
			$mailCC										=	$trigger->getSubstituteString( $row->get( 'cc', null, GetterInterface::STRING ) );
			$mailBCC									=	$trigger->getSubstituteString( $row->get( 'bcc', null, GetterInterface::STRING ) );
			$mailAttachments							=	$trigger->getSubstituteString( $row->get( 'attachment', null, GetterInterface::STRING ) );
			$mailReplyToEmail							=	$trigger->getSubstituteString( $row->get( 'replyto_address', null, GetterInterface::STRING ) );
			$mailReplyToName							=	$trigger->getSubstituteString( $row->get( 'replyto_name', null, GetterInterface::STRING ) );
			$mailFromEmail								=	$trigger->getSubstituteString( $row->get( 'from_address', null, GetterInterface::STRING ) );
			$mailFromName								=	$trigger->getSubstituteString( $row->get( 'from_name', null, GetterInterface::STRING ) );
			$mailMailer									=	$row->get( 'mailer', null, GetterInterface::STRING );
			$mailProperties								=	array();

			if ( $mailTo ) {
				$mailTo									=	preg_split( ' *, *', $mailTo );
			} else {
				$mailTo									=	null;
			}

			if ( $mailCC ) {
				$mailCC									=	preg_split( ' *, *', $mailCC );
			} else {
				$mailCC									=	null;
			}

			if ( $mailBCC ) {
				$mailBCC								=	preg_split( ' *, *', $mailBCC );
			} else {
				$mailBCC								=	null;
			}

			if ( $mailAttachments ) {
				$mailAttachments						=	preg_split( ' *, *', $mailAttachments );
			} else {
				$mailAttachments						=	null;
			}

			if ( $mailReplyToEmail ) {
				$mailReplyToEmail						=	preg_split( ' *, *', $mailReplyToEmail );
			} else {
				$mailReplyToEmail						=	null;
			}

			if ( $mailReplyToName ) {
				$mailReplyToName						=	preg_split( ' *, *', $mailReplyToName );
			} else {
				$mailReplyToName						=	null;
			}

			if ( $mailMailer ) {
				$mailProperties['Mailer']				=	$mailMailer;

				if ( $mailMailer == 'smtp' ) {
					$mailProperties['SMTPAuth']			=	(int) $row->get( 'mailer_smtpauth', null, GetterInterface::INT );
					$mailProperties['Username']			=	$row->get( 'mailer_smtpuser', null, GetterInterface::STRING );
					$mailProperties['Password']			=	$row->get( 'mailer_smtppass', null, GetterInterface::STRING );
					$mailProperties['Host']				=	$row->get( 'mailer_smtphost', null, GetterInterface::STRING );

					$smtpPort							=	(int) $row->get( 'mailer_smtpport', null, GetterInterface::INT );

					if ( $smtpPort ) {
						$mailProperties['Port']			=	$smtpPort;
					}

					$smtpSecure							=	$row->get( 'mailer_smtpsecure', null, GetterInterface::STRING );

					if ( ( $smtpSecure === 'ssl' ) || ( $smtpSecure === 'tls' ) ) {
						$mailProperties['SMTPSecure']	=	$smtpSecure;
					}
				} elseif ( $mailMailer == 'sendmail' ) {
					$sendMail							=	$row->get( 'mailer_sendmail', null, GetterInterface::STRING );

					if ( $sendMail ) {
						$mailProperties['Sendmail']		=	$sendMail;
					}
				}
			}

			$error										=	null;

			if ( ! comprofilerMail( $mailFromEmail, $mailFromName, $mailTo, $mailSubject, $mailBody, $mailHtml, $mailCC, $mailBCC, $mailAttachments, $mailReplyToEmail, $mailReplyToName, $mailProperties, $error ) ) {
				if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) {
					var_dump( CBTxt::T( 'AUTO_ACTION_EMAIL_FAILED', ':: Action [action] :: Email failed to send. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $error ) ) );
				}
			}
		}
	}
	/**
	 * prepares and sends notification (email or PM)
	 *
	 * @param mixed  $to
	 * @param int    $from
	 * @param mixed  $subject
	 * @param mixed  $message
	 * @param int    $replace
	 * @param object $category
	 * @param object $group
     * @param boolean $type
	 */
    static public function getNotification( $to, $from, $subject, $message, $replace = null, $category = null, $group = null, $type = false ) {
		global $_CB_framework, $_CB_database, $ueConfig, $_CB_PMS, $_PLUGINS;

		$plugin					=	cbgjClass::getPlugin();
		$user					=&	CBuser::getUserDataInstance( $_CB_framework->myId() );
		$notifyBy				=	$plugin->params->get( 'general_notifyby', 1 );
		$generalTitle			=	CBTxt::T( $plugin->params->get( 'general_title', null ) );
		$msgSiteName			=	$_CB_framework->getCfg( 'sitename' );
		$msgOverviewName		=	( $generalTitle ? $generalTitle : $plugin->name );

		if ( isset( $from->id ) || preg_match( '!^\d+$!', $from ) ) {
			if ( is_object( $from ) ) {
				$fromId			=	$from->id;
			} else {
				$fromId			=	$from;
			}

			$cbUserFrom			=&	CBuser::getInstance( $fromId );

			if ( ! $cbUserFrom ) {
				$cbUserFrom		=&	CBuser::getInstance( null );
			}

			$userFrom			=&	$cbUserFrom->getUserData();
		}

		if ( isset( $userFrom->id ) ) {
			$fromName			=	$cbUserFrom->getField( 'formatname', null, 'html', 'none', 'profile', 0, true );
			$fromEmail			=	$userFrom->email;

			if ( $replace == 1 ) {
				$msgUserUrl		=	cbSef( 'index.php?option=com_comprofiler&task=userprofile&user='******'<a href="' . $msgUserUrl . '">' . $msgUserName . '</a>';
				$subject		=	$cbUserFrom->replaceUserVars( $subject, false );
				$message		=	$cbUserFrom->replaceUserVars( $message, false );
			}
		} else {
			$fromId				=	0;
			$fromName			=	$_CB_framework->getCfg( 'fromname' );
			$fromEmail			=	$_CB_framework->getCfg( 'mailfrom' );
		}

		if ( isset( $to->id ) || preg_match( '!^\d+$!', $to ) ) {
			if ( is_object( $to ) ) {
				$toId			=	$to->id;
			} else {
				$toId			=	$to;
			}

			$cbUserTo			=&	CBuser::getInstance( $toId );

			if ( ! $cbUserTo ) {
				$cbUserTo		=&	CBuser::getInstance( null );
			}

			$userTo				=&	$cbUserTo->getUserData();
		}

		if ( isset( $userTo->id ) ) {
			$toEmail			=	$userTo->email;

			if ( $replace == 2 ) {
				$msgUserUrl	=	cbSef( 'index.php?option=com_comprofiler&task=userprofile&user='******'formatname', null, 'html', 'none', 'profile', 0, true );
				$msgUser		=	'******' . $msgUserUrl . '">' . $msgUserName . '</a>';
				$subject		=	$cbUserTo->replaceUserVars( $subject, false );
				$message		=	$cbUserTo->replaceUserVars( $message, false );
			}
		} else {
			$toId				=	0;

			if ( cbIsValidEmail( $to ) ) {
				$toEmail		=	$to;
			} else {
				$toEmail		=	null;
			}
		}

		if ( $plugin->params->get( 'notifications_from_name' ) ) {
			$fromName			=	$plugin->params->get( 'notifications_from_name' );
		}

		if ( $plugin->params->get( 'notifications_from_address' ) ) {
			$fromEmail			=	$plugin->params->get( 'notifications_from_address' );
		}

		$msgStrings				=	array(	'[site_name]',
											'[site]',
											'[admin_override]',
											'[admins_override]',
											'[moderator_override]',
											'[moderators_override]',
											'[owner_override]',
											'[panel_override]',
											'[overview_override]',
											'[overview_name]',
											'[overview]',
											'[categories_override]',
											'[category_override]',
											'[category_id]',
											'[category_name]',
											'[category]',
											'[groups_override]',
											'[group_override]',
											'[group_id]',
											'[group_name]',
											'[group]',
											'[users_override]',
											'[user_override]',
											'[user_name]',
											'[user]'
										);

		$msgValues				=	array(	$msgSiteName,
											'<a href="' . $_CB_framework->getCfg( 'live_site' ) . '">' . $msgSiteName . '</a>',
											cbgjClass::getOverride( 'admin' ),
											cbgjClass::getOverride( 'admin', true ),
											cbgjClass::getOverride( 'moderator' ),
											cbgjClass::getOverride( 'moderator', true ),
											cbgjClass::getOverride( 'owner' ),
											cbgjClass::getOverride( 'panel' ),
											cbgjClass::getOverride( 'overview' ),
											$msgOverviewName,
											'<a href="' . cbgjClass::getPluginURL( array( 'overview' ) ) . '">' . $msgOverviewName . '</a>',
											cbgjClass::getOverride( 'category', true ),
											cbgjClass::getOverride( 'category' ),
											( isset( $category->id ) ? $category->get( 'id' ) : null ),
											( isset( $category->id ) ? $category->getName() : null ),
											( isset( $category->id ) ? $category->getName( 0, true ) : null ),
											cbgjClass::getOverride( 'group', true ),
											cbgjClass::getOverride( 'group' ),
											( isset( $group->id ) ? $group->get( 'id' ) : null ),
											( isset( $group->id ) ? $group->getName() : null ),
											( isset( $group->id ) ? $group->getName( 0, true ) : null ),
											cbgjClass::getOverride( 'user', true ),
											cbgjClass::getOverride( 'user' ),
											( isset( $msgUserName ) ? $msgUserName : null ),
											( isset( $msgUser ) ? $msgUser : null )
										);

		$_PLUGINS->trigger( 'gj_onBeforeNotification', array( array( $fromId, $fromName, $fromEmail, $toId, $toEmail, $subject, $message ), $group, $category, $user, $plugin ) );

		$subject				=	trim( strip_tags( str_replace( $msgStrings, $msgValues, $subject ) ) );
		$message				=	cbgjClass::getFilteredText( str_replace( $msgStrings, $msgValues, $message ) );

		if ( $toId ) {
			if ( ( $notifyBy == 4 ) || ( $type == 4 ) ) {
				comprofilerMail( $fromEmail, $fromName, $toEmail, $subject, $message, 1 );
			} elseif ( ( $notifyBy == 3 ) || ( $type == 3 ) ) {
				$_CB_PMS->sendPMSMSG( $toId, $fromId, $subject, $message, true );
			} elseif ( ( $notifyBy == 2 ) || ( $type == 2 ) ) {
				$_CB_PMS->sendPMSMSG( $toId, $fromId, $subject, $message, true );

				comprofilerMail( $fromEmail, $fromName, $toEmail, $subject, $message, 1 );
			} elseif ( ( $notifyBy == 1 ) || ( $type == 1 ) ) {
				if ( ! $_CB_PMS->sendPMSMSG( $toId, $fromId, $subject, $message, true ) ) {
					comprofilerMail( $fromEmail, $fromName, $toEmail, $subject, $message, 1 );
				}
			}
		} elseif ( $toEmail ) {
			comprofilerMail( $fromEmail, $fromName, $toEmail, $subject, $message, 1 );
		} else {
			$moderators			=	implode( ',', $_CB_framework->acl->get_group_parent_ids( $ueConfig['imageApproverGid'] ) );

			if ( $moderators ) {
				$query			=	'SELECT ' . $_CB_database->NameQuote( 'email' )
								.	"\n FROM " . $_CB_database->NameQuote( '#__users' ) . " AS a"
								.	"\n INNER JOIN " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS b"
								.	' ON b.' . $_CB_database->NameQuote( 'user_id' ) . ' = a.' . $_CB_database->NameQuote( 'id' );

				if ( checkJversion() == 2 ) {
					$query		.=	"\n INNER JOIN " . $_CB_database->NameQuote( '#__user_usergroup_map' ) . " AS c"
								.	' ON b.' . $_CB_database->NameQuote( 'id' ) . ' = c.' . $_CB_database->NameQuote( 'user_id' )
								.	"\n WHERE c." . $_CB_database->NameQuote( 'group_id' ) . " IN ( " . $moderators . " )";
				} else {
					$query		.=	"\n WHERE a." . $_CB_database->NameQuote( 'gid' ) . " IN ( " . $moderators . " )";
				}

				$query			.=	"\n AND a." . $_CB_database->NameQuote( 'block' ) . " = 0"
								.	"\n AND a." . $_CB_database->NameQuote( 'sendEmail' ) . " = 1"
								.	"\n AND b." . $_CB_database->NameQuote( 'confirmed' ) . " = 1"
								.	"\n AND b." . $_CB_database->NameQuote( 'approved' ) . " = 1"
								.	"\n AND b." . $_CB_database->NameQuote( 'banned' ) . " = 0";
				$_CB_database->setQuery( $query );
				$mods			=	$_CB_database->loadResultArray();

				foreach ( $mods AS $mod ) {
					comprofilerMail( $fromEmail, $fromName, $mod, $subject, $message, 1 );
				}
			}
		}

		$_PLUGINS->trigger( 'gj_onAfterNotification', array( array( $fromId, $fromName, $fromEmail, $toId, $toEmail, $subject, $message ), $group, $category, $user, $plugin ) );
	}
Exemple #8
0
	/**
	 * @param cbinvitesInviteTable $row
	 * @return bool
	 */
	static public function sendInvite( &$row )
	{
		global $_CB_framework, $_PLUGINS;

		$plugin						=	$_PLUGINS->getLoadedPlugin( 'user', 'cbinvites' );

		if ( ! $plugin ) {
			return false;
		}

		$params						=	$_PLUGINS->getPluginParams( $plugin );

		$invitePrefix				=	CBTxt::T( $params->get( 'invite_prefix', '[sitename] - ' ) );
		$inviteHeader				=	CBTxt::T( $params->get( 'invite_header', '<p>You have been invited by [username] to join [sitename]!</p><br>' ) );
		$inviteFooter				=	CBTxt::T( $params->get( 'invite_footer', '<br><p>Invite Code - [code]<br>[sitename] - [site]<br>Registration - [register]<br>[username] - [profile]</p>' ) );

		$cbUser						=	CBuser::getInstance( (int) $row->get( 'user_id' ), false );
		$user						=	$cbUser->getUserData();

		$extra						=	array(	'sitename' => $_CB_framework->getCfg( 'sitename' ),
												'site' => $_CB_framework->getCfg( 'live_site' ),
												'register' => $_CB_framework->viewUrl( 'registers', false, ( $row->get( 'code' ) ? array( 'invite_code' => $row->get( 'code' ) ) : array() ) ),
												'profile' => $_CB_framework->viewUrl( 'userprofile', false, array( 'user' => (int) $row->get( 'user_id' ) ) ),
												'code' => $row->get( 'code' ),
												'to' => $row->get( 'to' )
											);

		$mailFromName				=	Get::clean( $cbUser->replaceUserVars( $params->get( 'invite_from_name', null ), true, false, $extra ), GetterInterface::STRING );
		$mailFromAddr				=	Get::clean( $cbUser->replaceUserVars( $params->get( 'invite_from_address', null ), true, false, $extra ), GetterInterface::STRING );
		$mailTo						=	Get::clean( $cbUser->replaceUserVars( $row->get( 'to' ), true, false, $extra ), GetterInterface::STRING );
		$mailCC						=	Get::clean( $cbUser->replaceUserVars( $params->get( 'invite_cc', null ), true, false, $extra ), GetterInterface::STRING );
		$mailBCC					=	Get::clean( $cbUser->replaceUserVars( $params->get( 'invite_bcc', null ), true, false, $extra ), GetterInterface::STRING );
		$mailSubject				=	Get::clean( $cbUser->replaceUserVars( ( $invitePrefix . ( $row->get( 'subject' ) ? $row->get( 'subject' ) : CBTxt::T( 'Join Me!' ) ) ), true, false, $extra ), GetterInterface::STRING );
		$mailBody					=	Get::clean( $cbUser->replaceUserVars( ( $inviteHeader . $row->get( 'body' ) . $inviteFooter ), false, false, $extra ), GetterInterface::HTML );
		$mailAttachments			=	Get::clean( $cbUser->replaceUserVars( $params->get( 'invite_attachments', null ), true, false, $extra ), GetterInterface::STRING );

		if ( $mailTo ) {
			$mailTo					=	preg_split( ' *, *', $mailTo );
		}

		if ( $mailCC ) {
			$mailCC					=	preg_split( ' *, *', $mailCC );
		}

		if ( $mailBCC ) {
			$mailBCC				=	preg_split( ' *, *', $mailBCC );
		}

		if ( $mailAttachments ) {
			$mailAttachments		=	preg_split( ' *, *', $mailAttachments );
		}

		if ( $mailTo && $mailSubject && $mailBody ) {
			if ( ! $mailFromName ) {
				$mailFromName		=	$user->name;
				$replyToName		=	null;
			} else {
				$replyToName		=	$user->name;
			}

			if ( ! $mailFromAddr ) {
				$mailFromAddr		=	$user->email;
				$replyToAddr		=	null;
			} else {
				$replyToAddr		=	$user->email;
			}

			$error					=	null;
			$sent					=	comprofilerMail( $mailFromAddr, $mailFromName, $mailTo, $mailSubject, $mailBody, ( (int) $params->get( 'invite_editor', 2 ) >= 2 ? true : false ), $mailCC, $mailBCC, $mailAttachments, $replyToAddr, $replyToName, $error );

			if ( $sent ) {
				return true;
			} else {
				$row->setError( ( $error ? $error : CBTxt::T( 'Mailer failed to send.' ) ) );
			}
		} else {
			if ( ! $mailTo ) {
				$row->setError( CBTxt::T( 'To address missing.' ) );
			} elseif ( ! $mailSubject ) {
				$row->setError( CBTxt::T( 'Subject missing.' ) );
			} elseif ( ! $mailBody ) {
				$row->setError( CBTxt::T( 'Body missing.' ) );
			}
		}

		return false;
	}