Explorar el Código

Ticket #4558 - Build-in API support: URLs in email/push notifications.

AntonLV hace 2 años
padre
commit
f9565ef523

+ 37 - 26
inc/classes/BxDolPush.php

@@ -132,17 +132,29 @@ class BxDolPush extends BxDolFactory implements iBxDolSingleton
         if($bAddToQueue && BxDolQueuePush::getInstance()->add($iProfileId, $aMessage))
         if($bAddToQueue && BxDolQueuePush::getInstance()->add($iProfileId, $aMessage))
             return true;        
             return true;        
     
     
-		$aFields = array(
-			'app_id' => $this->_sAppId,
-			'filters' => array(
-		        array('field' => 'tag', 'key' => 'user_hash', 'relation' => '=', 'value' => encryptUserId($iProfileId))
-            ),
-			'contents' => !empty($aMessage['contents']) && is_array($aMessage['contents']) ? $aMessage['contents'] : array(),
-			'headings' => !empty($aMessage['headings']) && is_array($aMessage['headings']) ? $aMessage['headings'] : array(),
+        if(($sRootUrl = getParam('sys_api_url_root_push')) !== '') {
+            if(substr(BX_DOL_URL_ROOT, -1) == '/' && substr($sRootUrl, -1) != '/')
+                $sRootUrl .= '/';
+
+            if(!empty($aMessage['url']))
+                $aMessage['url'] = str_replace(BX_DOL_URL_ROOT, $sRootUrl, $aMessage['url']);
+
+            if(empty($aMessage['contents']) && is_array($aMessage['contents']))
+                foreach($aMessage['contents'] as $sKey => $sValue)
+                    $aMessage['contents'][$sKey] = str_replace(BX_DOL_URL_ROOT, $sRootUrl, $sValue);
+        }
+
+        $aFields = [
+            'app_id' => $this->_sAppId,
+            'filters' => [
+                ['field' => 'tag', 'key' => 'user_hash', 'relation' => '=', 'value' => encryptUserId($iProfileId)]
+            ],
+            'contents' => !empty($aMessage['contents']) && is_array($aMessage['contents']) ? $aMessage['contents'] : [],
+            'headings' => !empty($aMessage['headings']) && is_array($aMessage['headings']) ? $aMessage['headings'] : [],
             'web_url' => !empty($aMessage['url']) ? $aMessage['url'] : '',
             'web_url' => !empty($aMessage['url']) ? $aMessage['url'] : '',
             'data' => array('url' => !empty($aMessage['url']) ? $aMessage['url'] : ''),
             'data' => array('url' => !empty($aMessage['url']) ? $aMessage['url'] : ''),
             'chrome_web_icon' => !empty($aMessage['icon']) ? $aMessage['icon'] : '',
             'chrome_web_icon' => !empty($aMessage['icon']) ? $aMessage['icon'] : '',
-		);
+        ];
 
 
         if ('on' == getParam('bx_nexus_option_push_notifications_count')) {
         if ('on' == getParam('bx_nexus_option_push_notifications_count')) {
             $iBadgeCount = $this->getNotificationsCount($iProfileId);
             $iBadgeCount = $this->getNotificationsCount($iProfileId);
@@ -150,29 +162,28 @@ class BxDolPush extends BxDolFactory implements iBxDolSingleton
             $aFields['ios_badgeCount'] = $iBadgeCount;
             $aFields['ios_badgeCount'] = $iBadgeCount;
         }
         }
 
 
-		$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);
-        
+        $oChannel = curl_init();
+        curl_setopt($oChannel, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
+        curl_setopt($oChannel, CURLOPT_HTTPHEADER, [
+                '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);
+
         $oResult = @json_decode($sResult, true);
         $oResult = @json_decode($sResult, true);
-        if(isset($oResult['errors'])){
+        if(isset($oResult['errors']))
             foreach($oResult['errors'] as $sError) {  
             foreach($oResult['errors'] as $sError) {  
                 bx_log('sys_push', $sError . " Message:" . json_encode($aMessage));
                 bx_log('sys_push', $sError . " Message:" . json_encode($aMessage));
             }
             }
-        }
 
 
-		return $sResult;
+        return $sResult;
     }
     }
 }
 }
 
 

+ 9 - 1
inc/utils.inc.php

@@ -441,12 +441,20 @@ function _sendMail($sRecipientEmail, $sMailSubject, $sMailBody, $iRecipientID =
     // parse template
     // parse template
     if ($aPlus || $iRecipientID || $oAccount) {
     if ($aPlus || $iRecipientID || $oAccount) {
         if(!is_array($aPlus))
         if(!is_array($aPlus))
-            $aPlus = array();
+            $aPlus = [];
+
         $oEmailTemplates = BxDolEmailTemplates::getInstance();
         $oEmailTemplates = BxDolEmailTemplates::getInstance();
         $sMailSubject = $oEmailTemplates->parseContent($sMailSubject, $aPlus, !$iRecipientID && $oAccount ? $oAccount->id() : 0, $iRecipientID);
         $sMailSubject = $oEmailTemplates->parseContent($sMailSubject, $aPlus, !$iRecipientID && $oAccount ? $oAccount->id() : 0, $iRecipientID);
         $sMailBody = $oEmailTemplates->parseContent($sMailBody, $aPlus, !$iRecipientID && $oAccount ? $oAccount->id() : 0, $iRecipientID);
         $sMailBody = $oEmailTemplates->parseContent($sMailBody, $aPlus, !$iRecipientID && $oAccount ? $oAccount->id() : 0, $iRecipientID);
     }
     }
 
 
+    if(($sRootUrl = getParam('sys_api_url_root_email')) !== '') {
+        if(substr(BX_DOL_URL_ROOT, -1) == '/' && substr($sRootUrl, -1) != '/')
+            $sRootUrl .= '/';
+
+        $sMailBody = str_replace(BX_DOL_URL_ROOT, $sRootUrl, $sMailBody);
+    }
+
     // email message headers
     // email message headers
     $sMailHeader = '';
     $sMailHeader = '';
     foreach ($aCustomHeaders as $sHeaderName => $sHeaderValue)
     foreach ($aCustomHeaders as $sHeaderName => $sHeaderValue)

+ 3 - 1
install/sql/system.sql

@@ -741,7 +741,9 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_api_access_unsafe_services', '_adm_stg_cpt_option_sys_api_access_unsafe_services', '', 'checkbox', '', '', '', 30),
 (@iCategoryId, 'sys_api_access_unsafe_services', '_adm_stg_cpt_option_sys_api_access_unsafe_services', '', 'checkbox', '', '', '', 30),
 (@iCategoryId, 'sys_api_cookie_path', '_adm_stg_cpt_option_sys_api_cookie_path', '/', 'digit', '', '', '', 40),
 (@iCategoryId, 'sys_api_cookie_path', '_adm_stg_cpt_option_sys_api_cookie_path', '/', 'digit', '', '', '', 40),
 (@iCategoryId, 'sys_api_cookie_secure', '_adm_stg_cpt_option_sys_api_cookie_secure', '', 'checkbox', '', '', '', 42),
 (@iCategoryId, 'sys_api_cookie_secure', '_adm_stg_cpt_option_sys_api_cookie_secure', '', 'checkbox', '', '', '', 42),
-(@iCategoryId, 'sys_api_cookie_samesite', '_adm_stg_cpt_option_sys_api_cookie_samesite', 'Lax', 'select', 'None,Lax,Strict', '', '', 44);
+(@iCategoryId, 'sys_api_cookie_samesite', '_adm_stg_cpt_option_sys_api_cookie_samesite', 'Lax', 'select', 'None,Lax,Strict', '', '', 44),
+(@iCategoryId, 'sys_api_url_root_email', '_adm_stg_cpt_option_sys_api_url_root_email', '', 'digit', '', '', '', 50),
+(@iCategoryId, 'sys_api_url_root_push', '_adm_stg_cpt_option_sys_api_url_root_push', '', 'digit', '', '', '', 51);
 
 
 
 
 --
 --

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

@@ -1745,6 +1745,8 @@
     <string name="_adm_stg_cpt_option_sys_api_search_sections"><![CDATA[Search sections]]></string>
     <string name="_adm_stg_cpt_option_sys_api_search_sections"><![CDATA[Search sections]]></string>
     <string name="_adm_stg_cpt_option_sys_api_extended_units"><![CDATA[Use extended units]]></string>
     <string name="_adm_stg_cpt_option_sys_api_extended_units"><![CDATA[Use extended units]]></string>
     <string name="_adm_stg_cpt_option_sys_api_conn_in_prof_units"><![CDATA[Use connections lists in profiles/groups units]]></string>
     <string name="_adm_stg_cpt_option_sys_api_conn_in_prof_units"><![CDATA[Use connections lists in profiles/groups units]]></string>
+    <string name="_adm_stg_cpt_option_sys_api_url_root_email"><![CDATA[Site main URL in email notifications]]></string>
+    <string name="_adm_stg_cpt_option_sys_api_url_root_push"><![CDATA[Site main URL in push notifications]]></string>
     <string name="_adm_stg_cpt_option_sys_viewport_meta_tag"><![CDATA[Viewport meta tag]]></string>
     <string name="_adm_stg_cpt_option_sys_viewport_meta_tag"><![CDATA[Viewport meta tag]]></string>
 
 
     <string name="_adm_stg_cpt_category_pwa_manifest"><![CDATA[Manifest]]></string>
     <string name="_adm_stg_cpt_category_pwa_manifest"><![CDATA[Manifest]]></string>

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

@@ -1720,6 +1720,8 @@
     <string name="_adm_stg_cpt_option_sys_api_search_sections"><![CDATA[Искать в]]></string>
     <string name="_adm_stg_cpt_option_sys_api_search_sections"><![CDATA[Искать в]]></string>
     <string name="_adm_stg_cpt_option_sys_api_extended_units"><![CDATA[Использовать расширенные юниты]]></string>
     <string name="_adm_stg_cpt_option_sys_api_extended_units"><![CDATA[Использовать расширенные юниты]]></string>
     <string name="_adm_stg_cpt_option_sys_api_conn_in_prof_units"><![CDATA[Использовать списки связей в блоках профилей/групп.]]></string>
     <string name="_adm_stg_cpt_option_sys_api_conn_in_prof_units"><![CDATA[Использовать списки связей в блоках профилей/групп.]]></string>
+    <string name="_adm_stg_cpt_option_sys_api_url_root_email"><![CDATA[Основной URL-адрес сайта в уведомлениях по электронной почте]]></string>
+    <string name="_adm_stg_cpt_option_sys_api_url_root_push"><![CDATA[Основной URL-адрес сайта в push-уведомлениях]]></string>
     <string name="_adm_stg_cpt_option_sys_viewport_meta_tag"><![CDATA[Метатег области просмотра]]></string>
     <string name="_adm_stg_cpt_option_sys_viewport_meta_tag"><![CDATA[Метатег области просмотра]]></string>
 
 
     <string name="_adm_stg_cpt_category_pwa_manifest"><![CDATA[Manifest]]></string>
     <string name="_adm_stg_cpt_category_pwa_manifest"><![CDATA[Manifest]]></string>