Explorar o código

#4451 - Add abitly to disable Click tracking in MassMailer

roman.lesnikov@gmail.com %!s(int64=3) %!d(string=hai) anos
pai
achega
893a8d43f6

+ 19 - 18
modules/boonex/massmailer/classes/BxMassMailerModule.php

@@ -479,11 +479,12 @@ class BxMassMailerModule extends BxBaseModGeneralModule
         $aTmp = $this->getDataForCampaign($iCampaignId);
         $aTemplate = $aTmp[0];
         $aCustomHeaders = $aTmp[1];
+        $aCampaign = $aTmp[2];
               
         if (!$aTemplate)
             return false;
         
-        return $this->sendLetter($sEmail, $iCampaignId, $aCustomHeaders, getLoggedId(), $aTemplate, false);
+        return $this->sendLetter($sEmail, $iCampaignId, $aCustomHeaders, getLoggedId(), $aTemplate, false, $aCampaign['is_track_links']);
     }
           
     public function sendAll($iCampaignId)
@@ -502,7 +503,7 @@ class BxMassMailerModule extends BxBaseModGeneralModule
         $this->_oDb->deleteCampaignData($iCampaignId);
         $aAccounts = $this->getEmailsBySegment($aCampaign['segments'], $aCampaign['is_one_per_account']);
         foreach ($aAccounts as $aAccountInfo){
-            $this->sendLetter($aAccountInfo['email'], $iCampaignId, $aCustomHeaders, $aAccountInfo['account_id'], $aTemplate, true);
+            $this->sendLetter($aAccountInfo['email'], $iCampaignId, $aCustomHeaders, $aAccountInfo['account_id'], $aTemplate, true, $aCampaign['is_track_links']);
             $this->_oDb->addEmailToSentListForCampaign($iCampaignId, $aAccountInfo['email']);
 
             if (1 == rand(1, 300)) {
@@ -515,27 +516,27 @@ class BxMassMailerModule extends BxBaseModGeneralModule
         return true;
     }
     
-    private function sendLetter($sEmail, $iCampaignId, $aCustomHeaders, $iAccountId, $aTemplate, $bAddToQueue)
+    private function sendLetter($sEmail, $iCampaignId, $aCustomHeaders, $iAccountId, $aTemplate, $bAddToQueue, $bTrackKinks)
     {
         $sLetterCode = $this->_oDb->addLetter($iCampaignId, $sEmail);
         
         $aMarkers = $this->addMarkers($iAccountId, $sLetterCode);
         bx_alert($this->_aModule['name'], 'user_fields', $iCampaignId, $iAccountId, array('email' => $sEmail, 'markers' => &$aMarkers));
-        
-        $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
-        $aTemplate['Body'] = preg_replace_callback("/$regexp/siU",
-            function ($aMatch) use ($iCampaignId, $sLetterCode, $aMarkers) {
-                if ($aMatch[2] != '{unsubscribe_url}'){
-                    $sUrl = bx_replace_markers($aMatch[2], $aMarkers);
-                    $sLinkCode = $this->_oDb->addLink($sLetterCode, $sUrl, $aMatch[3], $iCampaignId);
-                    return str_replace($sUrl, BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'track/click/' . $sLinkCode . "/", $aMatch[0]);
-                }
-                else{
-                    return $aMatch[0];
-                }
-            },
-            $aTemplate['Body']);
-        
+        if ($bTrackKinks){
+            $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
+            $aTemplate['Body'] = preg_replace_callback("/$regexp/siU",
+                function ($aMatch) use ($iCampaignId, $sLetterCode, $aMarkers) {
+                    if ($aMatch[2] != '{unsubscribe_url}'){
+                        $sUrl = bx_replace_markers($aMatch[2], $aMarkers);
+                        $sLinkCode = $this->_oDb->addLink($sLetterCode, $sUrl, $aMatch[3], $iCampaignId);
+                        return str_replace($sUrl, BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'track/click/' . $sLinkCode . "/", $aMatch[0]);
+                    }
+                    else{
+                        return $aMatch[0];
+                    }
+                },
+                $aTemplate['Body']);
+        }
         $aMarkersInLetter = [];
         preg_match_all("/\{[^\}]*\}/i", $aTemplate['Body'], $aMarkersInLetter);
         if ($aMarkersInLetter[0]>0){

+ 1 - 0
modules/boonex/massmailer/install/langs/en.xml

@@ -81,6 +81,7 @@
   <string name="_bx_massmailer_form_campaign_input_body"><![CDATA[Body]]></string>
   <string name="_bx_massmailer_form_campaign_input_body_err"><![CDATA[Body can't be empty and {unsubscribe_url} marker must be present]]></string>
   <string name="_bx_massmailer_form_campaign_input_is_one_per_account"><![CDATA[One letter per one account]]></string>
+  <string name="_bx_massmailer_form_campaign_input_is_track_links"><![CDATA[Click tracking]]></string>
   <string name="_bx_massmailer_form_campaign_input_sys_test_email"><![CDATA[Email]]></string>
   <string name="_bx_massmailer_form_campaign_input_email"><![CDATA[Email]]></string>
   <string name="_bx_massmailer_form_campaign_input_sys_segments"><![CDATA[Segments]]></string>

+ 9 - 5
modules/boonex/massmailer/install/sql/install.sql

@@ -15,6 +15,7 @@ CREATE TABLE `bx_massmailer_campaigns` (
   `date_sent` int(11) NOT NULL default '0',
   `email_list` text DEFAULT NULL,
   `is_one_per_account` smallint(1) NOT NULL,
+  `is_track_links` smallint(1) NOT NULL,  
   PRIMARY KEY (`id`),
   FULLTEXT KEY `title_text` (`title`, `subject`)
 );
@@ -98,6 +99,7 @@ INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `c
 (@sName, @sName, 'reply_to', '', '', 0, 'text', '_bx_massmailer_form_campaign_input_sys_reply_to', '_bx_massmailer_form_campaign_input_reply_to', '_bx_massmailer_form_campaign_input_reply_to_info', 0, 0, 0, 2, '', '', '', 'EmailOrEmpty', '', '_bx_massmailer_form_campaign_input_reply_to_err', 'XssHtml', '', 1, 0),
 (@sName, @sName, 'body', '', '', 0, 'textarea', '_bx_massmailer_form_campaign_input_sys_body', '_bx_massmailer_form_campaign_input_body', '', 1, 0, 0, 2, '', '', '', 'UnsubscribeUrl', '', '_bx_massmailer_form_campaign_input_body_err', 'XssHtml', '', 1, 0),
 (@sName, @sName, 'is_one_per_account', '1', '', 1, 'switcher', '_bx_massmailer_form_campaign_input_sys_is_one_per_account', '_bx_massmailer_form_campaign_input_is_one_per_account', '', 0, 0, 0, 0, '', '', '', '', '', '', 'Int', '', 1, 0),
+(@sName, @sName, 'is_track_links', '1', '', 1, 'switcher', '_bx_massmailer_form_campaign_input_sys_is_track_links', '_bx_massmailer_form_campaign_input_is_track_links', '', 0, 0, 0, 0, '', '', '', '', '', '', 'Int', '', 1, 0),
 (@sName, @sName, 'email', '', '', 0, 'text', '_bx_massmailer_form_campaign_input_sys_test_email', '_bx_massmailer_form_campaign_input_email', '', 1, 0, 0, 2, '', '', '', 'Email', '', '_sys_form_account_input_email_error', 'XssHtml', '', 1, 0),
 (@sName, @sName, 'campaign_info', '_bx_massmailer_form_campaign_input_from_name_info_value', '', 0, 'value', '_bx_massmailer_form_campaign_input_sys_campaign_info', '', '', 0, 0, 0, 2, '', '', '', '', '', '', 'XssHtml', '', 1, 0),
 (@sName, @sName, 'cancel', '_bx_massmailer_form_entry_input_cancel', '', 0, 'button', '_bx_dev_bp_btn_sys_block_cancel', '', '', 0, 0, 0, 0, 'a:2:{s:7:"onclick";s:45:"$(''.bx-popup-applied:visible'').dolPopupHide()";s:5:"class";s:22:"bx-def-margin-sec-left";}', '', '', 'Avail', '', '', '', '', 0, 0),
@@ -112,8 +114,9 @@ INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_fo
 ('bx_massmailer_campaign_add', 'reply_to', 2147483647, 1, 5),
 ('bx_massmailer_campaign_add', 'body', 2147483647, 1, 6),
 ('bx_massmailer_campaign_add', 'is_one_per_account', 2147483647, 1, 7),
-('bx_massmailer_campaign_add', 'controls', 2147483647, 1, 8),
-('bx_massmailer_campaign_add', 'do_submit', 2147483647, 1, 9),
+('bx_massmailer_campaign_add', 'is_track_links', 2147483647, 1, 8),
+('bx_massmailer_campaign_add', 'controls', 2147483647, 1, 9),
+('bx_massmailer_campaign_add', 'do_submit', 2147483647, 1, 10),
 ('bx_massmailer_campaign_add', 'cancel', 2147483647, 1, 10),
 ('bx_massmailer_campaign_edit', 'title', 2147483647, 1, 1),
 ('bx_massmailer_campaign_edit', 'segments', 2147483647, 1, 2),
@@ -122,9 +125,10 @@ INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_fo
 ('bx_massmailer_campaign_edit', 'reply_to', 2147483647, 1, 5),
 ('bx_massmailer_campaign_edit', 'body', 2147483647, 1, 6),
 ('bx_massmailer_campaign_edit', 'is_one_per_account', 2147483647, 1, 7),
-('bx_massmailer_campaign_edit', 'controls', 2147483647, 1, 8),
-('bx_massmailer_campaign_edit', 'do_submit', 2147483647, 1, 9),
-('bx_massmailer_campaign_edit', 'cancel', 2147483647, 1, 10),
+('bx_massmailer_campaign_edit', 'is_track_links', 2147483647, 1, 8),
+('bx_massmailer_campaign_edit', 'controls', 2147483647, 1, 9),
+('bx_massmailer_campaign_edit', 'do_submit', 2147483647, 1, 10),
+('bx_massmailer_campaign_edit', 'cancel', 2147483647, 1, 11),
 ('bx_massmailer_campaign_send_test', 'email', 2147483647, 1, 1),
 ('bx_massmailer_campaign_send_test', 'controls2', 2147483647, 1, 2),
 ('bx_massmailer_campaign_send_test', 'do_send', 2147483647, 1, 3),

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

@@ -82,6 +82,7 @@
   <string name="_bx_massmailer_form_campaign_input_body"><![CDATA[Тело письма]]></string>
   <string name="_bx_massmailer_form_campaign_input_body_err"><![CDATA[Тело письма не может быть пустым и в нем должен обязательно присутствовать маркер {unsubscribe_url}]]></string>
   <string name="_bx_massmailer_form_campaign_input_is_one_per_account"><![CDATA[Одно письмо на один аккаунт]]></string>
+  <string name="_bx_massmailer_form_campaign_input_is_track_links"><![CDATA[Отслеживать клики]]></string>
   <string name="_bx_massmailer_form_campaign_input_sys_test_email"><![CDATA[Email]]></string>
   <string name="_bx_massmailer_form_campaign_input_email"><![CDATA[Email]]></string>
   <string name="_bx_massmailer_form_campaign_input_sys_segments"><![CDATA[Сегменты]]></string>