AntonLV 8 anni fa
parent
commit
b36abf2741

+ 2 - 2
inc/classes/BxDolCronEmailQueue.php → inc/classes/BxDolCronQueueEmail.php

@@ -7,11 +7,11 @@
  * @{
  */
 
-class BxDolCronEmailQueue extends BxDolCron
+class BxDolCronQueueEmail extends BxDolCron
 {
     public function processing()
     {
-    	BxDolEmailQueue::getInstance()->send((int)getParam('sys_eq_send_per_start'));
+    	BxDolQueueEmail::getInstance()->send((int)getParam('sys_eq_send_per_start'));
     }
 }
 

+ 18 - 0
inc/classes/BxDolCronQueuePush.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 BxDolCronQueuePush extends BxDolCron
+{
+    public function processing()
+    {
+    	BxDolQueuePush::getInstance()->send((int)getParam('sys_push_queue_send_per_start'));
+    }
+}
+
+/** @} */

+ 84 - 0
inc/classes/BxDolPush.php

@@ -0,0 +1,84 @@
+<?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 BxDolPush extends BxDolDb implements iBxDolSingleton
+{
+    protected $_sAppId;
+    protected $_sRestApi;
+
+    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->_sAppId = getParam('sys_push_app_id');
+        $this->_sRestApi = getParam('sys_push_rest_api');
+    }
+
+    /**
+     * 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
+     */
+    public static function getInstance()
+    {
+        if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
+            $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolPush();
+
+        return $GLOBALS['bxDolClasses'][__CLASS__];
+    }
+    
+    public function send($iProfileId, $aMessage, $bAddToQueue = false)
+    {
+        if(empty($this->_sAppId) || empty($this->_sRestApi))
+            return false;
+
+        if($bAddToQueue && BxDolQueuePush::getInstance()->add($iProfileId, $aMessage))
+            return true;
+
+		$aFields = array(
+			'app_id' => $this->_sAppId,
+			'filters' => array(
+		        array('field' => 'tag', 'key' => 'user', 'relation' => '=', 'value' => $iProfileId)
+            ),
+			'contents' => !empty($aMessage['contents']) && is_array($aMessage['contents']) ? $aMessage['contents'] : array(),
+			'headings' => !empty($aMessage['headings']) && is_array($aMessage['headings']) ? $aMessage['headings'] : array(),
+			'url' => !empty($aMessage['url']) ? $aMessage['url'] : '',
+			'chrome_web_icon' => !empty($aMessage['icon']) ? $aMessage['icon'] : ''
+		);
+
+		$oChannel = curl_init();
+		curl_setopt($oChannel, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
+		curl_setopt($oChannel, CURLOPT_HTTPHEADER, array(
+			'Content-Type: application/json; charset=utf-8',
+			'Authorization: Basic ' . $this->_sRestApi
+		));
+		curl_setopt($oChannel, CURLOPT_RETURNTRANSFER, true);
+		curl_setopt($oChannel, CURLOPT_HEADER, false);
+		curl_setopt($oChannel, CURLOPT_POST, true);
+		curl_setopt($oChannel, CURLOPT_POSTFIELDS, json_encode($aFields));
+		curl_setopt($oChannel, CURLOPT_SSL_VERIFYPEER, false);
+
+		$sResult = curl_exec($oChannel);
+		curl_close($oChannel);
+
+		return $sResult;
+    }
+}
+
+/** @} */

+ 3 - 35
inc/classes/BxDolEmailQueue.php → inc/classes/BxDolQueue.php

@@ -7,7 +7,7 @@
  * @{
  */
 
-class BxDolEmailQueue extends BxDolFactory implements iBxDolSingleton
+class BxDolQueue extends BxDolFactory
 {
     protected $_oQuery;
 
@@ -17,8 +17,6 @@ class BxDolEmailQueue extends BxDolFactory implements iBxDolSingleton
             trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
 
         parent::__construct();
-
-        $this->_oQuery = new BxDolEmailQueueQuery();
     }
 
     /**
@@ -30,49 +28,19 @@ class BxDolEmailQueue extends BxDolFactory implements iBxDolSingleton
             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)
+    public 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)))
+    	    if(call_user_func_array(array($this, '_send'), array_slice($aMail, 1)))
     	        $aSent[] = $iId;
 
         if(!empty($aSent) && is_array($aSent))

+ 58 - 0
inc/classes/BxDolQueueEmail.php

@@ -0,0 +1,58 @@
+<?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 BxDolQueueEmail extends BxDolQueue implements iBxDolSingleton
+{
+    protected function __construct()
+    {
+        parent::__construct();
+
+        $this->_oQuery = new BxDolQueueEmailQuery();
+    }
+
+    /**
+     * Get singleton instance of the class
+     */
+    static function getInstance()
+    {
+        if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
+            $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolQueueEmail();
+
+        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;
+    }
+
+    /**
+     * Internal method which performs sending using predefined list of params.
+     */
+    protected function _send($sEmail, $sSubject, $sBody, $sHeaders = '', $sParams = '')
+    {
+        return mail($sEmail, $sSubject, $sBody, $sHeaders, $sParams);
+    }
+}
+
+/** @} */

+ 24 - 0
inc/classes/BxDolQueueEmailQuery.php

@@ -0,0 +1,24 @@
+<?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 BxDolQueueEmail object.
+ * @see BxDolQueueEmail
+ */
+class BxDolQueueEmailQuery extends BxDolQueueQuery
+{
+    public function __construct()
+    {
+        parent::__construct();
+
+        $this->_sTable = 'sys_queue_email';
+    }
+}
+
+/** @} */

+ 54 - 0
inc/classes/BxDolQueuePush.php

@@ -0,0 +1,54 @@
+<?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 BxDolQueuePush extends BxDolQueue implements iBxDolSingleton
+{
+    protected function __construct()
+    {
+        parent::__construct();
+
+        $this->_oQuery = new BxDolQueuePushQuery();
+    }
+
+    /**
+     * Get singleton instance of the class
+     */
+    static function getInstance()
+    {
+        if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
+            $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolQueuePush();
+
+        return $GLOBALS['bxDolClasses'][__CLASS__];
+    }
+
+    /**
+     * Add message to push queue
+     *
+     * @param integer $iProfileId - recipient profile ID
+     * @param array $aMessage - array with Push message 
+     * @return true on success, false on error
+     */
+    public function add($iProfileId, $aMessage)
+    {
+        return (int)$this->_oQuery->insertItem(array(
+        	'profile_id' => $iProfileId,
+            'message' => serialize($aMessage)
+        )) > 0;
+    }
+
+    /**
+     * Internal method which performs sending using predefined list of params.
+     */
+    protected function _send($iProfileId, $sMessage)
+    {
+        return BxDolPush::getInstance()->send($iProfileId, unserialize($sMessage));
+    }
+}
+
+/** @} */

+ 24 - 0
inc/classes/BxDolQueuePushQuery.php

@@ -0,0 +1,24 @@
+<?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 BxDolQueuePush object.
+ * @see BxDolQueuePush
+ */
+class BxDolQueuePushQuery extends BxDolQueueQuery
+{
+    public function __construct()
+    {
+        parent::__construct();
+
+        $this->_sTable = 'sys_queue_push';
+    }
+}
+
+/** @} */

+ 15 - 5
inc/classes/BxDolEmailQueueQuery.php → inc/classes/BxDolQueueQuery.php

@@ -8,22 +8,23 @@
  */
 
 /**
- * Database queries for BxDolEmailQueue object.
- * @see BxDolEmailQueue
+ * Database queries for BxDolQueue object.
+ * @see BxDolQueue
  */
-class BxDolEmailQueueQuery extends BxDolDb
+class BxDolQueueQuery extends BxDolDb
 {
     protected $_sTable;
 
     public function __construct()
     {
         parent::__construct();
-
-        $this->_sTable = 'sys_email_queue';
     }
 
     public function getItems($aParams = array())
     {
+        if(empty($this->_sTable))
+            return array();
+
     	$aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
 
     	$sSelectClause = '*';
@@ -46,6 +47,9 @@ class BxDolEmailQueueQuery extends BxDolDb
 
     public function insertItem($aValues)
     {
+        if(empty($this->_sTable))
+            return false;
+
         if(empty($aValues) || !is_array($aValues))
             return false;
 
@@ -54,6 +58,9 @@ class BxDolEmailQueueQuery extends BxDolDb
 
 	public function updateItem($aValues, $aWhere)
     {
+        if(empty($this->_sTable))
+            return false;
+
         if(empty($aValues) || !is_array($aValues) || empty($aWhere) || !is_array($aWhere))
             return false;
 
@@ -62,6 +69,9 @@ class BxDolEmailQueueQuery extends BxDolDb
 
     public function deleteItem($mixedId)
     {
+        if(empty($this->_sTable))
+            return false;
+
     	if(!is_array($mixedId))
     		$mixedId = array($mixedId);
 

+ 1 - 1
inc/utils.inc.php

@@ -413,7 +413,7 @@ function sendMail($sRecipientEmail, $sMailSubject, $sMailBody, $iRecipientID = 0
 
     // send mail or put it into queue
     $bResult = false;
-    if(!$bAddToQueue || !($bResult = BxDolEmailQueue::getInstance()->add($sRecipientEmail, $sMailSubject, $sMailBody, $sMailHeader, $sMailParameters)))
+    if(!$bAddToQueue || !($bResult = BxDolQueueEmail::getInstance()->add($sRecipientEmail, $sMailSubject, $sMailBody, $sMailHeader, $sMailParameters)))
         $bResult = mail($sRecipientEmail, $sMailSubject, $sMailBody, $sMailHeader, $sMailParameters);     
 
     // system alert

File diff suppressed because it is too large
+ 0 - 0
install/sql/system.sql


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

@@ -1283,7 +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_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_eq_send_per_start"><![CDATA[Number of messages to send from queue per run]]></string>
+	<string name="_adm_stg_cpt_option_sys_eq_send_per_start"><![CDATA[Number of messages to send from mail 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_secret"><![CDATA[UNA account secret]]></string>
 	<string name="_adm_stg_cpt_option_sys_page_cache_enable"><![CDATA[Enable Page cache]]></string>
@@ -1296,6 +1296,7 @@
     <string name="_adm_stg_cpt_option_sys_push_rest_api"><![CDATA[REST API Key]]></string>
     <string name="_adm_stg_cpt_option_sys_push_short_name"><![CDATA[Short name (required only for http sites. It must match the Subdomain you entered on the Web Push settings on the OneSignal dashboard)]]></string>
     <string name="_adm_stg_cpt_option_sys_push_safari_id"><![CDATA[Apple Safari Web ID on the Web Push settings]]></string>
+    <string name="_adm_stg_cpt_option_sys_push_queue_send_per_start"><![CDATA[Number of messages to send from Push queue per run]]></string>
 	<string name="_adm_stg_cpt_option_sys_recaptcha_key_private"><![CDATA[reCAPTCHA private key]]></string>
 	<string name="_adm_stg_cpt_option_sys_recaptcha_key_public"><![CDATA[reCAPTCHA public key]]></string>
 	<string name="_adm_stg_cpt_option_sys_redirect_after_account_added"><![CDATA[Redirect after account creation to]]></string>

+ 6 - 31
modules/boonex/notifications/classes/BxNtfsResponse.php

@@ -284,44 +284,19 @@ class BxNtfsResponse extends BxBaseModNotificationsResponse
 
     protected function sendNotificationPush($oProfile, $aContent)
     {
-        $CNF = &$this->_oModule->_oConfig->CNF;
+        $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
 
-        $sAppId = getParam('sys_push_app_id');
-        $sRestApi = getParam('sys_push_rest_api');
-        if(empty($sAppId) || empty($sRestApi))
-            return;
-
-		$sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
-
-		$aFields = array(
-			'app_id' => $sAppId,
-			'filters' => array(
-		        array("field" => "tag", "key" => "user", "relation" => "=", "value" => $oProfile->id())
-            ),
-			'contents' => array(
+        return BxDolPush::getInstance()->send($oProfile->id(), array(
+		    'contents' => array(
     			 $sLanguage => $aContent['message']
     		),
 			'headings' => array(
 				 $sLanguage => _t('_bx_ntfs_push_new_event_subject', getParam('site_title'))
 			),
 			'url' => $aContent['url'],
-			'chrome_web_icon' => $aContent['icon']
-		);
-
-		$oChannel = curl_init();
-		curl_setopt($oChannel, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
-		curl_setopt($oChannel, CURLOPT_HTTPHEADER, array(
-			'Content-Type: application/json; charset=utf-8',
-			'Authorization: Basic ' . $sRestApi
-		));
-		curl_setopt($oChannel, CURLOPT_RETURNTRANSFER, true);
-		curl_setopt($oChannel, CURLOPT_HEADER, false);
-		curl_setopt($oChannel, CURLOPT_POST, true);
-		curl_setopt($oChannel, CURLOPT_POSTFIELDS, json_encode($aFields));
-		curl_setopt($oChannel, CURLOPT_SSL_VERIFYPEER, false);
-
-		$sResult = curl_exec($oChannel);
-		curl_close($oChannel);
+			'icon' => $aContent['icon']
+		
+		), true);
     }
 
     protected function _getObjectOwnerId($aExtras)

+ 3 - 2
modules/boonex/russian/data/langs/system/ru.xml

@@ -1281,7 +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_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_eq_send_per_start"><![CDATA[Количество сообщенией, отправляемое из очереди при каждом запуске]]></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_secret"><![CDATA[UNA-аккаунт - Secret (секретное слово)]]></string>
 	<string name="_adm_stg_cpt_option_sys_page_cache_enable"><![CDATA[Задействовать кэш для страниц]]></string>
@@ -1293,7 +1293,8 @@
     <string name="_adm_stg_cpt_option_sys_push_app_id"><![CDATA[OneSignal App ID]]></string>
     <string name="_adm_stg_cpt_option_sys_push_rest_api"><![CDATA[REST API Key]]></string>
     <string name="_adm_stg_cpt_option_sys_push_short_name"><![CDATA[Короткое имя (требуется только если у вас https сайт. Оно должно совпадать с поддоменом, введёным, в настройках пуш оповещений на OneSignal)]]></string>
-    <string name="_adm_stg_cpt_option_sys_push_safari_id"><![CDATA[Apple Safari Web ID в натройках Web Push]]></string>    
+    <string name="_adm_stg_cpt_option_sys_push_safari_id"><![CDATA[Apple Safari Web ID в натройках Web Push]]></string>
+    <string name="_adm_stg_cpt_option_sys_push_queue_send_per_start"><![CDATA[Количество сообщенией, отправляемое из Push очереди при каждом запуске]]></string>    
 	<string name="_adm_stg_cpt_option_sys_recaptcha_key_private"><![CDATA[reCAPTCHA - приватный ключ]]></string>
 	<string name="_adm_stg_cpt_option_sys_recaptcha_key_public"><![CDATA[reCAPTCHA - публичный ключ]]></string>
 	<string name="_adm_stg_cpt_option_sys_redirect_after_account_added"><![CDATA[Перенаправлять после создания аккаунта на]]></string>

Some files were not shown because too many files changed in this diff