← All changes
|
back/dynamics/subscription/SubscriptionInsertion.php
+128
-67
10.11.1
→
11.1.0
View file →
| @@ -6,13 +6,19 @@ | ||
| 6 | 6 | use AcyMailing\Classes\ListClass; |
| 7 | 7 | |
| 8 | 8 | trait SubscriptionInsertion |
| 9 | 9 | { |
| 10 | + //Set this variable to true once the list unsubscribe is added so we don't add it twice | |
| 10 | 11 | private $addedListUnsubscribe = []; |
| 12 | + //Keep all lists and IDs for users so we don't do the query twice | |
| 11 | 13 | private $lists = []; |
| 14 | + //Keep all listsowner information so we don't do the query again and again | |
| 12 | 15 | private $listsowner = []; |
| 16 | + //Keep the list information there | |
| 13 | 17 | private $listsinfo = []; |
| 18 | + //Used to know if we should add a List-Unsubscribe header | |
| 14 | 19 | private $unsubscribeLink = []; |
| 20 | + // Used for list-unsubscribe to store the mail's list ids | |
| 15 | 21 | private $mailLists = []; |
| 16 | 22 | private $userClass = null; |
| 17 | 23 | |
| 18 | 24 | public function dynamicText(?int $mailId): ?object |
| @@ -25,8 +31,9 @@ | ||
| 25 | 31 | $others = []; |
| 26 | 32 | $others['unsubscribe'] = ['name' => acym_translation('ACYM_UNSUBSCRIBE_LINK'), 'default' => 'ACYM_UNSUBSCRIBE']; |
| 27 | 33 | $others['unsubscribeall'] = ['name' => acym_translation('ACYM_UNSUBSCRIBE_ALL_LISTS_LINK'), 'default' => 'ACYM_UNSUBSCRIBE_ALL_LISTS']; |
| 28 | 34 | $others['direct_unsubscribe'] = ['name' => acym_translation('ACYM_DIRECT_UNSUBSCRIBE_LINK'), 'default' => 'ACYM_UNSUBSCRIBE']; |
| 35 | + $others['disable_tracking'] = ['name' => acym_translation('ACYM_DISABLE_TRACKING_LINK'), 'default' => 'ACYM_DISABLE_TRACKING']; | |
| 29 | 36 | $others['confirm'] = ['name' => acym_translation('ACYM_CONFIRM_SUBSCRIPTION_LINK'), 'default' => 'ACYM_CONFIRM_SUBSCRIPTION']; |
| 30 | 37 | $others['subscribe'] = ['name' => acym_translation('ACYM_SUBSCRIBE_LINK'), 'default' => 'ACYM_SUBSCRIBE']; |
| 31 | 38 | |
| 32 | 39 | ?> |
| @@ -40,9 +47,9 @@ | ||
| 40 | 47 | selectedSubscriptionDText = tagName; |
| 41 | 48 | let defaultText = []; |
| 42 | 49 | <?php |
| 43 | 50 | foreach ($others as $tagname => $tag) { |
| 44 | - echo 'defaultText["'.$tagname.'"] = "'.acym_translation($tag['default'], true).'";'; | |
| 51 | + echo 'defaultText["'.esc_attr($tagname).'"] = '.json_encode(acym_translation($tag['default'])).';'; | |
| 45 | 52 | } |
| 46 | 53 | ?> |
| 47 | 54 | jQuery('.selected_row').removeClass('selected_row'); |
| 48 | 55 | jQuery('#tr_' + tagName).addClass('selected_row'); |
| @@ -123,61 +130,67 @@ | ||
| 123 | 130 | }); |
| 124 | 131 | } |
| 125 | 132 | </script> |
| 126 | 133 | <?php |
| 127 | - $text = '<div class="acym__popup__listing text-center grid-x"> | |
| 128 | - <h1 class="acym__title acym__title__secondary text-center cell">'.acym_translation('ACYM_SUBSCRIPTION').'</h1> | |
| 129 | - <div class="grid-x medium-12 cell acym__row__no-listing text-left acym_vcenter"> | |
| 130 | - <div class="grid-x cell medium-5 small-12 acym__listing__title acym__listing__title__dynamics acym__subscription__subscription acym_vcenter"> | |
| 131 | - <label class="small-3 margin-bottom-0" for="acym__popup__subscription__tagtext">'.acym_translation('ACYM_TEXT').': </label> | |
| 132 | - <input class="small-9" type="text" name="tagtext" id="acym__popup__subscription__tagtext" onchange="setSubscriptionTag();"> | |
| 133 | - </div> | |
| 134 | - <div class="medium-1"></div> | |
| 135 | - <div style="display: none;" id="select_lists_zone" class="grid-x cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics"> | |
| 136 | - <p class="shrink" id="acym__popup__subscription__text__list">'.acym_translation('ACYM_LISTS_SELECTED').'</p> | |
| 137 | - <p class="shrink" id="acym__popup__subscription__listids"></p> | |
| 138 | - </div> | |
| 139 | - </div>'; | |
| 140 | - $text .= ' | |
| 141 | - <div class="cell grid-x">'; | |
| 134 | + //Add an area where the user will be able to select another text to add | |
| 135 | + echo '<div class="acym__popup__listing text-center grid-x"> | |
| 136 | + <h1 class="acym__title acym__title__secondary text-center cell">'.esc_html(acym_translation('ACYM_SUBSCRIPTION')).'</h1> | |
| 137 | + <div class="grid-x medium-12 cell acym__row__no-listing text-left acym_vcenter"> | |
| 138 | + <div class="grid-x cell medium-5 small-12 acym__listing__title acym__listing__title__dynamics acym__subscription__subscription acym_vcenter"> | |
| 139 | + <label class="small-3 margin-bottom-0" for="acym__popup__subscription__tagtext">'.esc_html(acym_translation('ACYM_TEXT')).': </label> | |
| 140 | + <input class="small-9" type="text" name="tagtext" id="acym__popup__subscription__tagtext" onchange="setSubscriptionTag();"> | |
| 141 | + </div> | |
| 142 | + <div class="medium-1"></div> | |
| 143 | + <div style="display: none;" id="select_lists_zone" class="grid-x cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics"> | |
| 144 | + <p class="shrink" id="acym__popup__subscription__text__list">'.esc_html(acym_translation('ACYM_LISTS_SELECTED')).'</p> | |
| 145 | + <p class="shrink" id="acym__popup__subscription__listids"></p> | |
| 146 | + </div> | |
| 147 | + </div> | |
| 148 | + <div class="cell grid-x">'; | |
| 142 | 149 | |
| 143 | 150 | foreach ($others as $tagname => $tag) { |
| 144 | 151 | $onclick = "changeSubscriptionTag('".$tagname."');"; |
| 145 | - if ($tagname == 'subscribe') { | |
| 152 | + if ($tagname === 'subscribe') { | |
| 146 | 153 | $onclick .= 'displayLists();return false;'; |
| 147 | - } elseif ($tagname == 'direct_unsubscribe') { | |
| 154 | + } elseif ($tagname === 'direct_unsubscribe') { | |
| 148 | 155 | $onclick .= 'displayDirectUnsubscribeRedirect();return false;'; |
| 149 | - } elseif ($tagname == 'unsubscribeall') { | |
| 156 | + } elseif ($tagname === 'unsubscribeall') { | |
| 150 | 157 | $onclick .= 'displayUnsubscribeAllRedirect();return false;'; |
| 151 | 158 | } |
| 152 | - $text .= '<div class="grid-x small-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="'.$onclick.'" id="tr_'.$tagname.'" >'; | |
| 153 | - $text .= '<div class="cell small-12 acym__listing__title acym__listing__title__dynamics">'.$tag['name'].'</div>'; | |
| 154 | - $text .= '</div>'; | |
| 159 | + | |
| 160 | + echo '<div class="grid-x small-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="'.esc_attr($onclick).'" id="tr_'.esc_attr( | |
| 161 | + $tagname | |
| 162 | + ).'" >'; | |
| 163 | + echo '<div class="cell small-12 acym__listing__title acym__listing__title__dynamics">'.wp_kses( | |
| 164 | + $tag['name'], | |
| 165 | + [ | |
| 166 | + 'b' => [], | |
| 167 | + ] | |
| 168 | + ).'</div>'; | |
| 169 | + echo '</div>'; | |
| 155 | 170 | } |
| 156 | - $text .= '</div> | |
| 157 | - <div class="medium-1"></div> | |
| 158 | - <div class="medium-10 text-left">'; | |
| 159 | - $text .= acym_modalPaginationLists( | |
| 171 | + echo '</div> | |
| 172 | + <div class="medium-1"></div> | |
| 173 | + <div class="medium-10 text-left">'; | |
| 174 | + acym_modalPaginationLists( | |
| 160 | 175 | 'acym__popup__subscription__change', |
| 161 | 176 | '' |
| 162 | 177 | ); |
| 163 | - $text .= ' | |
| 164 | - <div style="display: none;" id="acym__popup__plugin__direct_unsubscribe__modal" class="grid-x cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics"> | |
| 165 | - <label>'.acym_translation('ACYM_REDIRECTION_URL').'</label> | |
| 178 | + echo '<div style="display: none;" id="acym__popup__plugin__direct_unsubscribe__modal" class="grid-x cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics"> | |
| 179 | + <label>'.esc_html(acym_translation('ACYM_REDIRECTION_URL')).'</label> | |
| 166 | 180 | <input type="text" id="acym__popup__direct_unsubscribe__redirect" placeholder="https://example.com/unsubscribed" /> |
| 167 | 181 | <p id="acym__popup__direct_unsubscribe__preview" class="acym_smalltext text-gray"></p> |
| 168 | - </div>'; | |
| 169 | - | |
| 170 | - $text .= ' | |
| 182 | + </div> | |
| 171 | 183 | <div style="display: none;" id="acym__popup__plugin__unsubscribeall__modal" class="grid-x cell medium-6 small-12 acym__listing__title acym__listing__title__dynamics"> |
| 172 | - <label>'.acym_translation('ACYM_REDIRECTION_URL').'</label> | |
| 173 | - <input type="text" id="acym__popup__unsubscribeall__redirect" placeholder="https://example.com/all-unsubscribed" /> | |
| 174 | - <p id="acym__popup__unsubscribeall__preview" class="acym_smalltext text-gray"></p> | |
| 175 | - </div>'; | |
| 176 | - $text .= ' </div> | |
| 177 | - <div class="medium-1"></div> | |
| 178 | - </div>'; | |
| 184 | + <label>'.esc_html(acym_translation('ACYM_REDIRECTION_URL')).'</label> | |
| 185 | + <input type="text" id="acym__popup__unsubscribeall__redirect" placeholder="https://example.com/all-unsubscribed" /> | |
| 186 | + <p id="acym__popup__unsubscribeall__preview" class="acym_smalltext text-gray"></p> | |
| 187 | + </div> | |
| 188 | + </div> | |
| 189 | + <div class="medium-1"></div> | |
| 190 | + </div>'; | |
| 179 | 191 | |
| 192 | + // List tags | |
| 180 | 193 | $others = []; |
| 181 | 194 | $others['name'] = acym_translation('ACYM_LIST_NAME'); |
| 182 | 195 | $others['description'] = acym_translation('ACYM_LIST_DESCRIPTION'); |
| 183 | 196 | $others['names'] = acym_translation('ACYM_LIST_NAMES'); |
| @@ -183,47 +196,62 @@ | ||
| 183 | 196 | $others['names'] = acym_translation('ACYM_LIST_NAMES'); |
| 184 | 197 | $others['descriptions'] = acym_translation('ACYM_LIST_DESCRIPTIONS'); |
| 185 | 198 | $others['id'] = acym_translation('ACYM_LIST_ID', true); |
| 186 | 199 | |
| 187 | - $text .= '<div class="acym__popup__listing text-center grid-x"> | |
| 188 | - <h1 class="acym__title acym__title__secondary text-center cell">'.acym_translation('ACYM_LIST').'</h1> | |
| 189 | - <div class="cell grid-x">'; | |
| 200 | + echo '<div class="acym__popup__listing text-center grid-x"> | |
| 201 | + <h1 class="acym__title acym__title__secondary text-center cell">'.esc_html(acym_translation('ACYM_LIST')).'</h1> | |
| 202 | + <div class="cell grid-x">'; | |
| 190 | 203 | |
| 191 | 204 | foreach ($others as $tagname => $tag) { |
| 192 | - $text .= '<div class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriptionTag(\'list\');setTag(\'{list:'.$tagname.'}\', jQuery(this));" id="tr_'.$tagname.'"> | |
| 193 | - <div class="cell medium-12 small-12 acym__listing__title acym__listing__title__dynamics">'.$tag.'</div> | |
| 194 | - </div>'; | |
| 205 | + echo '<div class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriptionTag(\'list\');setTag(\'{list:'.esc_attr( | |
| 206 | + $tagname | |
| 207 | + ).'}\', jQuery(this));" id="tr_'.esc_attr($tagname).'"> | |
| 208 | + <div class="cell medium-12 small-12 acym__listing__title acym__listing__title__dynamics">'.esc_html($tag).'</div> | |
| 209 | + </div>'; | |
| 195 | 210 | } |
| 196 | 211 | |
| 197 | - $text .= '</div></div>'; | |
| 212 | + echo '</div></div>'; | |
| 198 | 213 | |
| 199 | - $text .= '<div class="acym__popup__listing text-center grid-x"> | |
| 200 | - <span class="acym__title acym__title__secondary text-center cell">'.acym_translation('ACYM_CAMPAIGN').'</span> | |
| 201 | - <div class="cell grid-x">'; | |
| 214 | + // Newsletter tags | |
| 215 | + echo '<div class="acym__popup__listing text-center grid-x"> | |
| 216 | + <span class="acym__title acym__title__secondary text-center cell">'.esc_html(acym_translation('ACYM_CAMPAIGN')).'</span> | |
| 217 | + <div class="cell grid-x">'; | |
| 202 | 218 | $othersMail = ['campaignid', 'subject']; |
| 203 | 219 | |
| 204 | 220 | foreach ($othersMail as $tag) { |
| 205 | - $text .= '<div class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriptionTag(\'mail\');setTag(\'{mail:'.$tag.'}\', jQuery(this));" id="tr_'.$tag.'"> | |
| 206 | - <div class="cell medium-12 small-12 acym__listing__title acym__listing__title__dynamics">'.$tag.'</div> | |
| 207 | - </div>'; | |
| 221 | + echo '<div class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriptionTag(\'mail\');setTag(\'{mail:'.esc_attr( | |
| 222 | + $tag | |
| 223 | + ).'}\', jQuery(this));" id="tr_'.esc_attr($tag).'"> | |
| 224 | + <div class="cell medium-12 small-12 acym__listing__title acym__listing__title__dynamics">'.esc_html($tag).'</div> | |
| 225 | + </div>'; | |
| 208 | 226 | } |
| 209 | - $text .= '</div></div>'; | |
| 227 | + echo '</div></div>'; | |
| 210 | 228 | |
| 211 | - $text .= '<div class="acym__popup__listing text-center grid-x"> | |
| 212 | - <span class="acym__title acym__title__secondary text-center cell">'.acym_translation('ACYM_AUTO').' '.acym_translation('ACYM_CAMPAIGNS').'</span> | |
| 213 | - <div class="cell grid-x">'; | |
| 214 | - $autoMail = ['number_generated' => ['name' => acym_translation('ACYM_ISSUE_NB'), 'default' => '#1']]; | |
| 229 | + // Smart newsletter tags | |
| 230 | + echo '<div class="acym__popup__listing text-center grid-x"> | |
| 231 | + <span class="acym__title acym__title__secondary text-center cell">'.esc_html(acym_translation('ACYM_AUTO').' '.acym_translation('ACYM_CAMPAIGNS')).'</span> | |
| 232 | + <div class="cell grid-x">'; | |
| 215 | 233 | |
| 234 | + $autoMail = [ | |
| 235 | + 'number_generated' => [ | |
| 236 | + 'name' => acym_translation('ACYM_ISSUE_NB'), | |
| 237 | + 'default' => '#1', | |
| 238 | + ], | |
| 239 | + ]; | |
| 240 | + | |
| 216 | 241 | foreach ($autoMail as $tag => $oneTag) { |
| 217 | 242 | $tagInserted = $tag; |
| 218 | - if (!empty($oneTag['default'])) $tagInserted = $tag.'|default:'.$oneTag['default']; | |
| 219 | - $text .= '<div class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriptionTag(\'automail\');setTag(\'{automail:'.$tagInserted.'}\', jQuery(this));" id="tr_'.$tag.'"> | |
| 220 | - <div class="cell medium-12 small-12 acym__listing__title acym__listing__title__dynamics">'.$oneTag['name'].'</div> | |
| 221 | - </div>'; | |
| 243 | + if (!empty($oneTag['default'])) { | |
| 244 | + $tagInserted = $tag.'|default:'.$oneTag['default']; | |
| 245 | + } | |
| 246 | + | |
| 247 | + echo '<div class="grid-x medium-12 cell acym__row__no-listing acym__listing__row__popup text-left" onclick="changeSubscriptionTag(\'automail\');setTag(\'{automail:'.esc_attr( | |
| 248 | + $tagInserted | |
| 249 | + ).'}\', jQuery(this));" id="tr_'.esc_attr($tag).'"> | |
| 250 | + <div class="cell medium-12 small-12 acym__listing__title acym__listing__title__dynamics">'.esc_html($oneTag['name']).'</div> | |
| 251 | + </div>'; | |
| 222 | 252 | } |
| 223 | - $text .= '</div></div>'; | |
| 224 | - | |
| 225 | - echo $text; | |
| 253 | + echo '</div></div>'; | |
| 226 | 254 | } |
| 227 | 255 | |
| 228 | 256 | public function replaceUserInformation(object &$email, ?object &$user, bool $send = true): void |
| 229 | 257 | { |
| @@ -231,8 +259,9 @@ | ||
| 231 | 259 | return; |
| 232 | 260 | } |
| 233 | 261 | $this->replacelisttags($email, $user, $send); |
| 234 | 262 | |
| 263 | + // Check if we should add the List-Unsubscribe header | |
| 235 | 264 | if (empty($user->id) || !empty($this->addedListUnsubscribe[$email->id][$user->id])) return; |
| 236 | 265 | if (empty($this->unsubscribeLink[$email->id]) || !method_exists($email, 'addCustomHeader')) return; |
| 237 | 266 | |
| 238 | 267 | |
| @@ -237,8 +266,9 @@ | ||
| 237 | 266 | |
| 238 | 267 | |
| 239 | 268 | $this->addedListUnsubscribe[$email->id][$user->id] = true; |
| 240 | 269 | |
| 270 | + // Prepare the mailto parameters for the header | |
| 241 | 271 | $mailto = ''; |
| 242 | 272 | if ($this->config->get('auto_bounce', 0)) { |
| 243 | 273 | $mailto = $this->config->get('bounce_email'); |
| 244 | 274 | } |
| @@ -245,8 +275,9 @@ | ||
| 245 | 275 | if (empty($mailto)) { |
| 246 | 276 | $mailto = empty($email->replyemail) ? $this->config->get('replyto_email') : $email->replyemail; |
| 247 | 277 | } |
| 248 | 278 | |
| 279 | + // No bounce address, no reply-to address on the email or the configuration | |
| 249 | 280 | if (empty($mailto)) { |
| 250 | 281 | return; |
| 251 | 282 | } |
| 252 | 283 | |
| @@ -257,8 +288,9 @@ | ||
| 257 | 288 | $lists = $mailClass->getAllListsByMailId($email->id); |
| 258 | 289 | $this->mailLists[$email->id] = empty($lists) ? null : array_keys($lists); |
| 259 | 290 | } |
| 260 | 291 | |
| 292 | + // Make sure we unsubscribe from the correct lists and not all the lists | |
| 261 | 293 | if (!empty($this->mailLists[$email->id])) { |
| 262 | 294 | $userClass = $this->getUserClass(); |
| 263 | 295 | $userLists = $userClass->getSubscriptionStatus($user->id, [], UserClass::STATUS_SUBSCRIBED); |
| 264 | 296 | if (!empty($userLists)) { |
| @@ -269,13 +301,13 @@ | ||
| 269 | 301 | } |
| 270 | 302 | } |
| 271 | 303 | } |
| 272 | 304 | |
| 273 | - $unsubscribeLink = str_replace( | |
| 305 | + $unsubscribeLink = htmlspecialchars_decode(str_replace( | |
| 274 | 306 | ['{subscriber:id}', '{subscriber:key|urlencode}'], |
| 275 | 307 | [$user->id, urlencode($user->key)], |
| 276 | 308 | $this->unsubscribeLink[$email->id] |
| 277 | - ); | |
| 309 | + )); | |
| 278 | 310 | $email->addCustomHeader('List-Unsubscribe', '<'.$unsubscribeLink.'&ajax=1>, <mailto:'.$mailto.'?subject=unsubscribe_user_'.$user->id.'&body='.$body.'>'); |
| 279 | 311 | $email->addCustomHeader('List-Unsubscribe-Post', 'List-Unsubscribe=One-Click'); |
| 280 | 312 | } |
| 281 | 313 | |
| @@ -324,8 +356,9 @@ | ||
| 324 | 356 | $tags[$key] = $oneTag->default; |
| 325 | 357 | } |
| 326 | 358 | } |
| 327 | 359 | |
| 360 | + // Available tags: {automail:number_generated} | |
| 328 | 361 | private function replaceAutomailTags(&$email) |
| 329 | 362 | { |
| 330 | 363 | $result = $this->pluginHelper->extractTags($email, 'automail'); |
| 331 | 364 | $tags = []; |
| @@ -351,8 +384,9 @@ | ||
| 351 | 384 | |
| 352 | 385 | $this->pluginHelper->replaceTags($email, $tags); |
| 353 | 386 | } |
| 354 | 387 | |
| 388 | + //Available tags: {list:name} , {list:count} , {list:count|listid:0} (to count all users), {list:members}, {list:owner} | |
| 355 | 389 | private function replacelisttags(&$email, &$user, $send) |
| 356 | 390 | { |
| 357 | 391 | $tags = $this->pluginHelper->extractTags($email, 'list'); |
| 358 | 392 | if (empty($tags)) { |
| @@ -404,8 +438,9 @@ | ||
| 404 | 438 | return $listid; |
| 405 | 439 | } |
| 406 | 440 | } |
| 407 | 441 | |
| 442 | + //We could not find a list id there... maybe there is no subscription in which case we take the first one... | |
| 408 | 443 | if (!empty($mailLists)) { |
| 409 | 444 | $this->lists[$mailid][$subid] = array_shift($mailLists); |
| 410 | 445 | |
| 411 | 446 | return $this->lists[$mailid][$subid]; |
| @@ -411,8 +446,9 @@ | ||
| 411 | 446 | return $this->lists[$mailid][$subid]; |
| 412 | 447 | } |
| 413 | 448 | |
| 414 | 449 | if (!empty($subid) && !empty($email->type) && $email->type === MailClass::TYPE_WELCOME) { |
| 450 | + //Last list the user subscribed to... | |
| 415 | 451 | $listid = acym_loadResult( |
| 416 | 452 | 'SELECT list.id |
| 417 | 453 | FROM #__acym_list AS list |
| 418 | 454 | JOIN #__acym_user_has_list AS userlist ON list.id = userlist.list_id |
| @@ -426,8 +462,9 @@ | ||
| 426 | 462 | } |
| 427 | 463 | } |
| 428 | 464 | |
| 429 | 465 | if (!empty($subid) && !empty($email->type) && $email->type === MailClass::TYPE_UNSUBSCRIBE) { |
| 466 | + //Last list the user unsubscribed from... | |
| 430 | 467 | $listid = acym_loadResult( |
| 431 | 468 | 'SELECT list.id |
| 432 | 469 | FROM #__acym_list AS list |
| 433 | 470 | JOIN #__acym_user_has_list AS userlist ON list.id = userlist.list_id |
| @@ -440,8 +477,9 @@ | ||
| 440 | 477 | return $listid; |
| 441 | 478 | } |
| 442 | 479 | } |
| 443 | 480 | |
| 481 | + //Still no list? well, lets load the first list the user is subscribed to then | |
| 444 | 482 | if (!empty($userLists)) { |
| 445 | 483 | $listIds = array_keys($userLists); |
| 446 | 484 | $this->lists[$mailid][$subid] = array_shift($listIds); |
| 447 | 485 | |
| @@ -469,8 +507,12 @@ | ||
| 469 | 507 | |
| 470 | 508 | return implode(isset($parameter->separator) ? $parameter->separator : ', ', $lists); |
| 471 | 509 | } |
| 472 | 510 | |
| 511 | + /** | |
| 512 | + * Replace data about the list owner | |
| 513 | + * Use the tag: {list:owner|field:name} or {list:owner|field:username} or {list:owner|field:email} | |
| 514 | + */ | |
| 473 | 515 | private function listowner(&$email, &$user, &$parameter) |
| 474 | 516 | { |
| 475 | 517 | if (empty($user->id)) { |
| 476 | 518 | return ''; |
| @@ -574,9 +616,9 @@ | ||
| 574 | 616 | } |
| 575 | 617 | |
| 576 | 618 | private function replaceSubscriptionTags(&$email) |
| 577 | 619 | { |
| 578 | - $match = '#(?:{|%7B)(confirm|unsubscribe(?:\|[^}]+)*|unsubscribeall(?:\|[^}]+)*|direct_unsubscribe(?:\|[^}]+)*|subscribe(?:\|[^}]+)*)(?:}|%7D)(.*)(?:{|%7B)/(confirm|unsubscribe|direct_unsubscribe|unsubscribeall|subscribe)(?:}|%7D)#Uis'; | |
| 620 | + $match = '#(?:{|%7B)(confirm|unsubscribe(?:\|[^}]+)*|unsubscribeall(?:\|[^}]+)*|direct_unsubscribe(?:\|[^}]+)*|disable_tracking(?:\|[^}]+)*|subscribe(?:\|[^}]+)*)(?:}|%7D)(.*)(?:{|%7B)/(confirm|unsubscribe|direct_unsubscribe|unsubscribeall|disable_tracking|subscribe)(?:}|%7D)#Uis'; | |
| 579 | 621 | $variables = ['subject', 'body']; |
| 580 | 622 | $found = false; |
| 581 | 623 | $results = []; |
| 582 | 624 | foreach ($variables as $var) { |
| @@ -582,11 +624,13 @@ | ||
| 582 | 624 | foreach ($variables as $var) { |
| 583 | 625 | if (empty($email->$var)) continue; |
| 584 | 626 | |
| 585 | 627 | $found = preg_match_all($match, $email->$var, $results[$var]) || $found; |
| 628 | + //we unset the results so that we won't handle it later... it will save some memory and processing | |
| 586 | 629 | if (empty($results[$var][0])) unset($results[$var]); |
| 587 | 630 | } |
| 588 | 631 | |
| 632 | + //If we didn't find anything... | |
| 589 | 633 | if (!$found) return; |
| 590 | 634 | |
| 591 | 635 | $tags = []; |
| 592 | 636 | $this->addedListUnsubscribe[$email->id] = []; |
| @@ -591,8 +635,9 @@ | ||
| 591 | 635 | $tags = []; |
| 592 | 636 | $this->addedListUnsubscribe[$email->id] = []; |
| 593 | 637 | foreach ($results as $var => $allresults) { |
| 594 | 638 | foreach ($allresults[0] as $i => $oneTag) { |
| 639 | + //Don't need to process twice a tag we already have! | |
| 595 | 640 | if (isset($tags[$oneTag])) continue; |
| 596 | 641 | |
| 597 | 642 | $tags[$oneTag] = $this->replaceSubscriptionTag($allresults, $i, $email); |
| 598 | 643 | } |
| @@ -607,8 +652,9 @@ | ||
| 607 | 652 | |
| 608 | 653 | $lang = $this->getLanguage($email->links_language); |
| 609 | 654 | |
| 610 | 655 | if ($parameters->id === 'confirm') { |
| 656 | + // subscription confirmation link | |
| 611 | 657 | $myLink = acym_frontendLink('frontusers&task=confirm&userId={subscriber:id}&userKey={subscriber:key|urlencode}'.$lang); |
| 612 | 658 | if (empty($allresults[2][$i])) { |
| 613 | 659 | return $myLink; |
| 614 | 660 | } |
| @@ -614,8 +660,9 @@ | ||
| 614 | 660 | } |
| 615 | 661 | |
| 616 | 662 | return '<a target="_blank" href="'.$myLink.'"><span class="acym_confirm acym_link">'.$allresults[2][$i].'</span></a>'; |
| 617 | 663 | } elseif ($parameters->id === 'subscribe') { |
| 664 | + // direct subscription link | |
| 618 | 665 | if (empty($parameters->lists)) { |
| 619 | 666 | return acym_translation('ACYM_EXPORT_SELECT_LIST'); |
| 620 | 667 | } |
| 621 | 668 | $lists = explode(',', $parameters->lists); |
| @@ -647,8 +694,22 @@ | ||
| 647 | 694 | return $myLink; |
| 648 | 695 | } |
| 649 | 696 | |
| 650 | 697 | return '<a style="text-decoration:none;" target="_blank" href="'.$myLink.'"><span class="acym_unsubscribe_direct acym_link">'.$allresults[2][$i].'</span></a>'; |
| 698 | + } elseif ($parameters->id === 'disable_tracking') { | |
| 699 | + $myLink = acym_frontendLink( | |
| 700 | + 'frontusers&task=disableTracking' | |
| 701 | + .'&userId={subscriber:id}' | |
| 702 | + .'&userKey={subscriber:key|urlencode}' | |
| 703 | + .'&mail_id='.$email->id | |
| 704 | + .$lang | |
| 705 | + ); | |
| 706 | + | |
| 707 | + if (empty($allresults[2][$i])) { | |
| 708 | + return $myLink; | |
| 709 | + } | |
| 710 | + | |
| 711 | + return '<a style="text-decoration:none;" target="_blank" href="'.$myLink.'"><span class="acym_disable_tracking acym_link">'.$allresults[2][$i].'</span></a>'; | |
| 651 | 712 | } else { |
| 652 | 713 | $baseLink = 'frontusers'.$lang.'&mail_id='.$email->id; |
| 653 | 714 | if ($parameters->id === 'unsubscribe') { |
| 654 | 715 | $unsubscribeLink = $baseLink.'&task=unsubscribe&userId={subscriber:id}&userKey={subscriber:key|urlencode}'; |