AntonLV 8 ani în urmă
părinte
comite
5770897526

+ 18 - 0
inc/classes/BxDolCronEmailQueue.php

@@ -0,0 +1,18 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+class BxDolCronEmailQueue extends BxDolCron
+{
+    public function processing()
+    {
+    	BxDolEmailQueue::getInstance()->send((int)getParam('sys_eq_send_per_start'));
+    }
+}
+
+/** @} */

+ 85 - 0
inc/classes/BxDolEmailQueue.php

@@ -0,0 +1,85 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+class BxDolEmailQueue extends BxDolFactory implements iBxDolSingleton
+{
+    protected $_oQuery;
+
+    protected function __construct()
+    {
+        if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
+            trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
+
+        parent::__construct();
+
+        $this->_oQuery = new BxDolEmailQueueQuery();
+    }
+
+    /**
+     * Prevent cloning the instance
+     */
+    public function __clone()
+    {
+        if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
+            trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
+    }
+
+    /**
+     * Get singleton instance of the class
+     */
+    static function getInstance()
+    {
+        if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
+            $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolEmailQueue();
+
+        return $GLOBALS['bxDolClasses'][__CLASS__];
+    }
+
+    /**
+     * Add message to mail queue
+     *
+     * @param string $sEmail - recipient email
+     * @param string $sSubject - message subject
+     * @param string $sBody - message body
+     * @return true on success, false on error
+     */
+    public function add($sEmail, $sSubject, $sBody, $sHeaders = '', $sParams = '')
+    {
+        return (int)$this->_oQuery->insertItem(array(
+        	'email' => $sEmail,
+            'subject' => $sSubject,
+            'body' => $sBody,
+            'headers' => $sHeaders,
+        	'params' => $sParams
+        )) > 0;
+    }
+
+	/**
+	 * Send some number of email form mail queue
+	 *
+	 * @param int $iLimit - number of emails to send
+	 * @return real number of sent emails
+	 */
+    function send($iLimit = 1)
+    {
+        $aSent = array();
+
+    	$aMails = $this->_oQuery->getItems(array('type' => 'to_send', 'start' => 0, 'per_page' => $iLimit));
+    	foreach($aMails as $iId => $aMail)
+    	    if(call_user_func_array('mail', array_slice($aMail, 1)))
+    	        $aSent[] = $iId;
+
+        if(!empty($aSent) && is_array($aSent))
+            $this->_oQuery->deleteItem($aSent);
+
+    	return count($aSent);
+    }
+}
+
+/** @} */

+ 72 - 0
inc/classes/BxDolEmailQueueQuery.php

@@ -0,0 +1,72 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+/**
+ * Database queries for BxDolEmailQueue object.
+ * @see BxDolEmailQueue
+ */
+class BxDolEmailQueueQuery extends BxDolDb
+{
+    protected $_sTable;
+
+    public function __construct()
+    {
+        parent::__construct();
+
+        $this->_sTable = 'sys_email_queue';
+    }
+
+    public function getItems($aParams = array())
+    {
+    	$aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
+
+    	$sSelectClause = '*';
+    	$sWhereClause = '';
+    	$sLimitClause = isset($aParams['start']) && !empty($aParams['per_page']) ? "LIMIT " . $aParams['start'] . ", " . $aParams['per_page'] : "";
+
+    	if(!empty($aParams['type']))
+            switch($aParams['type']) {
+                case 'to_send':
+                    $aMethod['name'] = 'getAllWithKey';
+                    $aMethod['params'][1] = 0;
+                    $aMethod['params'][2] = array();
+                    $aMethod['params'][3] = PDO::FETCH_NUM;
+                    break;
+            }
+
+        $aMethod['params'][0] = "SELECT " . $sSelectClause . " FROM `" . $this->_sTable . "` WHERE 1 " . $sWhereClause . $sLimitClause;
+        return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
+    }
+
+    public function insertItem($aValues)
+    {
+        if(empty($aValues) || !is_array($aValues))
+            return false;
+
+        return $this->query("INSERT INTO `" . $this->_sTable . "` SET " . $this->arrayToSQL($aValues));
+    }
+
+	public function updateItem($aValues, $aWhere)
+    {
+        if(empty($aValues) || !is_array($aValues) || empty($aWhere) || !is_array($aWhere))
+            return false;
+
+        return (int)$this->query("UPDATE `" . $this->_sTable . "` SET " . $this->arrayToSQL($aValues) . " WHERE " . $this->arrayToSQL($aWhere, ' AND ')) > 0;
+    }
+
+    public function deleteItem($mixedId)
+    {
+    	if(!is_array($mixedId))
+    		$mixedId = array($mixedId);
+
+        return (int)$this->query("DELETE FROM `" . $this->_sTable . "` WHERE `id` IN (" . $this->implode_escape($mixedId) . ")") > 0;
+    }
+}
+
+/** @} */

+ 15 - 11
inc/utils.inc.php

@@ -271,7 +271,7 @@ function htmlspecialchars_adv( $string )
 /**
 /**
  * Send mail to user by parsing email template
  * Send mail to user by parsing email template
  */
  */
-function sendMailTemplate($sTemplateName, $iAccountId = 0, $iProfileId = 0, $aReplaceVars = array(), $iEmailType = BX_EMAIL_NOTIFY)
+function sendMailTemplate($sTemplateName, $iAccountId = 0, $iProfileId = 0, $aReplaceVars = array(), $iEmailType = BX_EMAIL_NOTIFY, $bAddToQueue = false)
 {
 {
     $oProfile = BxDolProfile::getInstance($iProfileId);
     $oProfile = BxDolProfile::getInstance($iProfileId);
 
 
@@ -286,13 +286,13 @@ function sendMailTemplate($sTemplateName, $iAccountId = 0, $iProfileId = 0, $aRe
     if (!$aTemplate)
     if (!$aTemplate)
         return false;
         return false;
 
 
-    return sendMail($oAccount->getEmail(), $aTemplate['Subject'], $aTemplate['Body'], 0, array(), $iEmailType);
+    return sendMail($oAccount->getEmail(), $aTemplate['Subject'], $aTemplate['Body'], 0, array(), $iEmailType, 'html', false, array(), $bAddToQueue);
 }
 }
 
 
 /**
 /**
  * Send system email 
  * Send system email 
  */
  */
-function sendMailTemplateSystem($sTemplateName, $aReplaceVars = array(), $iEmailType = BX_EMAIL_SYSTEM)
+function sendMailTemplateSystem($sTemplateName, $aReplaceVars = array(), $iEmailType = BX_EMAIL_SYSTEM, $bAddToQueue = false)
 {
 {
     $oEmailTemplates = BxDolEmailTemplates::getInstance();
     $oEmailTemplates = BxDolEmailTemplates::getInstance();
 
 
@@ -303,7 +303,7 @@ function sendMailTemplateSystem($sTemplateName, $aReplaceVars = array(), $iEmail
     if (!$aTemplate)
     if (!$aTemplate)
         return false;
         return false;
 
 
-    return sendMail(getParam('site_email'), $aTemplate['Subject'], $aTemplate['Body'], 0, array(), $iEmailType);
+    return sendMail(getParam('site_email'), $aTemplate['Subject'], $aTemplate['Body'], 0, array(), $iEmailType, 'html', false, array(), $bAddToQueue);
 }
 }
 /**
 /**
  * Send email function
  * Send email function
@@ -317,9 +317,10 @@ function sendMailTemplateSystem($sTemplateName, $aReplaceVars = array(), $iEmail
  * @param $sEmailFlag - use 'html' for HTML email message
  * @param $sEmailFlag - use 'html' for HTML email message
  * @param $isDisableAlert - disable alert
  * @param $isDisableAlert - disable alert
  * @param $aCustomHeaders - custom email headers
  * @param $aCustomHeaders - custom email headers
+ * @param $bAddToQueue - add message to email queue
  * @return true if message was send or false otherwise
  * @return true if message was send or false otherwise
  */
  */
-function sendMail($sRecipientEmail, $sMailSubject, $sMailBody, $iRecipientID = 0, $aPlus = array(), $iEmailType = BX_EMAIL_NOTIFY, $sEmailFlag = 'html', $isDisableAlert = false, $aCustomHeaders = array())
+function sendMail($sRecipientEmail, $sMailSubject, $sMailBody, $iRecipientID = 0, $aPlus = array(), $iEmailType = BX_EMAIL_NOTIFY, $sEmailFlag = 'html', $isDisableAlert = false, $aCustomHeaders = array(), $bAddToQueue = false)
 {
 {
     // make sure that recipient's email is valid and message isn't empty
     // make sure that recipient's email is valid and message isn't empty
     if (!$sMailBody || !$sRecipientEmail || preg_match('/\(2\)$/', $sRecipientEmail))
     if (!$sMailBody || !$sRecipientEmail || preg_match('/\(2\)$/', $sRecipientEmail))
@@ -402,21 +403,24 @@ function sendMail($sRecipientEmail, $sMailSubject, $sMailBody, $iRecipientID = 0
         unset($aAlert['override_result']);
         unset($aAlert['override_result']);
     }
     }
 
 
-    // send mail
-    if( 'html' == $sEmailFlag) {
+    // prepare HTML/Plain message
+    if($sEmailFlag == 'html')
         $sMailHeader = "Content-type: text/html; charset=UTF-8\r\n" . $sMailHeader;
         $sMailHeader = "Content-type: text/html; charset=UTF-8\r\n" . $sMailHeader;
-        $iSendingResult = mail( $sRecipientEmail, $sMailSubject, $sMailBody, $sMailHeader, $sMailParameters );
-    } else {
+    else {
         $sMailHeader = "Content-type: text/plain; charset=UTF-8\r\n" . $sMailHeader;
         $sMailHeader = "Content-type: text/plain; charset=UTF-8\r\n" . $sMailHeader;
         $sMailBody = html2txt($sMailBody);
         $sMailBody = html2txt($sMailBody);
-        $iSendingResult = mail( $sRecipientEmail, $sMailSubject, html2txt($sMailBody), $sMailHeader, $sMailParameters );
     }
     }
 
 
+    // send mail or put it into queue
+    $bResult = false;
+    if(!$bAddToQueue || !($bResult = BxDolEmailQueue::getInstance()->add($sRecipientEmail, $sMailSubject, $sMailBody, $sMailHeader, $sMailParameters)))
+        $bResult = mail($sRecipientEmail, $sMailSubject, $sMailBody, $sMailHeader, $sMailParameters);     
+
     // system alert
     // system alert
     if (!$isDisableAlert)
     if (!$isDisableAlert)
         bx_alert('system', 'send_mail', (isset($aRecipientInfo['ID']) ? $aRecipientInfo['ID'] : 0), '', $aAlert);
         bx_alert('system', 'send_mail', (isset($aRecipientInfo['ID']) ? $aRecipientInfo['ID'] : 0), '', $aAlert);
 
 
-    return $iSendingResult;
+    return $bResult;
 }
 }
 
 
 /*
 /*

Fișier diff suprimat deoarece este prea mare
+ 12 - 0
install/sql/system.sql


+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1283,6 +1283,7 @@
 	<string name="_adm_stg_cpt_option_sys_embedly_api_key"><![CDATA[Embed.ly API key (fill in to use instead of Iframely)]]></string>
 	<string name="_adm_stg_cpt_option_sys_embedly_api_key"><![CDATA[Embed.ly API key (fill in to use instead of Iframely)]]></string>
 	<string name="_adm_stg_cpt_option_sys_embedly_api_pattern"><![CDATA[Embed.ly API pattern (fill in to use instead of Iframely)]]></string>
 	<string name="_adm_stg_cpt_option_sys_embedly_api_pattern"><![CDATA[Embed.ly API pattern (fill in to use instead of Iframely)]]></string>
 	<string name="_adm_stg_cpt_option_sys_iframely_api_key"><![CDATA[Iframely API key]]></string>
 	<string name="_adm_stg_cpt_option_sys_iframely_api_key"><![CDATA[Iframely API key]]></string>
+	<string name="_adm_stg_cpt_option_sys_eq_send_per_start"><![CDATA[Number of messages to send from queue per run]]></string>
 	<string name="_adm_stg_cpt_option_sys_oauth_key"><![CDATA[UNA account key]]></string>
 	<string name="_adm_stg_cpt_option_sys_oauth_key"><![CDATA[UNA account key]]></string>
 	<string name="_adm_stg_cpt_option_sys_oauth_secret"><![CDATA[UNA account secret]]></string>
 	<string name="_adm_stg_cpt_option_sys_oauth_secret"><![CDATA[UNA account secret]]></string>
 	<string name="_adm_stg_cpt_option_sys_page_cache_enable"><![CDATA[Enable Page cache]]></string>
 	<string name="_adm_stg_cpt_option_sys_page_cache_enable"><![CDATA[Enable Page cache]]></string>

+ 1 - 3
modules/boonex/notifications/classes/BxNtfsResponse.php

@@ -275,9 +275,7 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
 
 
     protected function sendNotificationEmail($oProfile, $sContent)
     protected function sendNotificationEmail($oProfile, $sContent)
     {
     {
-        sendMailTemplate('bx_notifications_new_event', $oProfile->getAccountId(), $oProfile->id(), array(
-            'content' => $sContent
-        ));
+        sendMailTemplate('bx_notifications_new_event', $oProfile->getAccountId(), $oProfile->id(), array('content' => $sContent), BX_EMAIL_NOTIFY, true);
     }
     }
 
 
     protected function sendNotificationPush($oProfile, $aContent)
     protected function sendNotificationPush($oProfile, $aContent)

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -1281,6 +1281,7 @@
     <string name="_adm_stg_cpt_option_sys_embedly_api_key"><![CDATA[Ключ Embed.ly API (заполните, чтобы использовать вместо Iframely)]]></string>
     <string name="_adm_stg_cpt_option_sys_embedly_api_key"><![CDATA[Ключ Embed.ly API (заполните, чтобы использовать вместо Iframely)]]></string>
     <string name="_adm_stg_cpt_option_sys_embedly_api_pattern"><![CDATA[Шаблон Embed.ly API (заполните, чтобы использовать вместо Iframely)]]></string>
     <string name="_adm_stg_cpt_option_sys_embedly_api_pattern"><![CDATA[Шаблон Embed.ly API (заполните, чтобы использовать вместо Iframely)]]></string>
     <string name="_adm_stg_cpt_option_sys_iframely_api_key"><![CDATA[Ключ Iframely API]]></string>
     <string name="_adm_stg_cpt_option_sys_iframely_api_key"><![CDATA[Ключ Iframely API]]></string>
+    <string name="_adm_stg_cpt_option_sys_eq_send_per_start"><![CDATA[Количество сообщенией, отправляемое из очереди при каждом запуске]]></string>
 	<string name="_adm_stg_cpt_option_sys_oauth_key"><![CDATA[UNA-аккаунт - Key (ключ)]]></string>
 	<string name="_adm_stg_cpt_option_sys_oauth_key"><![CDATA[UNA-аккаунт - Key (ключ)]]></string>
 	<string name="_adm_stg_cpt_option_sys_oauth_secret"><![CDATA[UNA-аккаунт - Secret (секретное слово)]]></string>
 	<string name="_adm_stg_cpt_option_sys_oauth_secret"><![CDATA[UNA-аккаунт - Secret (секретное слово)]]></string>
 	<string name="_adm_stg_cpt_option_sys_page_cache_enable"><![CDATA[Задействовать кэш для страниц]]></string>
 	<string name="_adm_stg_cpt_option_sys_page_cache_enable"><![CDATA[Задействовать кэш для страниц]]></string>

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff