#1064 Allow personalised 'view in browser' links for mass emails
authorJKingsnorth <john@johnkingsnorth.co.uk>
Fri, 21 Jun 2019 11:05:18 +0000 (12:05 +0100)
committerJKingsnorth <john@johnkingsnorth.co.uk>
Fri, 21 Jun 2019 11:05:18 +0000 (12:05 +0100)
CRM/Core/SelectValues.php
CRM/Mailing/Page/View.php
CRM/Mailing/Tokens.php
CRM/Utils/Token.php

index 497e0904fa0cb09543b51f5f7eb34f612e1b0100..b67f98c262602eca8c76b5bf173c886b74c41bcb 100644 (file)
@@ -493,6 +493,7 @@ class CRM_Core_SelectValues {
       '{domain.address}' => ts('Domain (organization) address'),
       '{domain.phone}' => ts('Domain (organization) phone'),
       '{domain.email}' => ts('Domain (organization) email'),
+      '{mailing.key}' => ts('Mailing key'),
       '{mailing.name}' => ts('Mailing name'),
       '{mailing.group}' => ts('Mailing group'),
       '{mailing.viewUrl}' => ts('Mailing permalink'),
index 878434004ea5d9b30c4aa23fe393b885621d41dc..961b4b5b84397e0e279161acd14b14c4747638dd 100644 (file)
@@ -97,6 +97,10 @@ class CRM_Mailing_Page_View extends CRM_Core_Page {
       $this->_mailingID = CRM_Utils_Request::retrieve('id', 'String', CRM_Core_DAO::$_nullObject, TRUE);
     }
 
+    // Retrieve contact ID and checksum from the URL
+    $cs = CRM_Utils_Request::retrieve('cs', 'String');
+    $cid = CRM_Utils_Request::retrieve('cid', 'Int');
+
     // # CRM-7651
     // override contactID from the function level if passed in
     if (isset($contactID) &&
@@ -104,6 +108,12 @@ class CRM_Mailing_Page_View extends CRM_Core_Page {
     ) {
       $this->_contactID = $contactID;
     }
+
+    // Support checksummed view of the mailing to replace tokens
+    elseif (!empty($cs) && !empty($cid) && CRM_Contact_BAO_Contact_Utils::validChecksum($cid, $cs)) {
+      $this->_contactID = $cid;
+    }
+
     else {
       $this->_contactID = CRM_Core_Session::getLoggedInContactID();
     }
index efde6376b2e261e0919c6229a9d5327967a9272f..16b5ccac23fd0f588465c391ed17e0fbad366f6d 100644 (file)
@@ -42,6 +42,7 @@ class CRM_Mailing_Tokens extends \Civi\Token\AbstractTokenSubscriber {
   public function __construct() {
     parent::__construct('mailing', [
       'id' => ts('Mailing ID'),
+      'key' => ts('Mailing Key'),
       'name' => ts('Mailing Name'),
       'group' => ts('Mailing Group(s)'),
       'subject' => ts('Mailing Subject'),
index d9014d7760ae41dbade150bf5ea5765e11222ba5..8fcc5567130f00f1a18f5963a7ce3b98e3ba4a1f 100644 (file)
@@ -51,6 +51,7 @@ class CRM_Utils_Token {
     ],
     'mailing' => [
       'id',
+      'key',
       'name',
       'group',
       'subject',
@@ -466,6 +467,14 @@ class CRM_Utils_Token {
         $value = $mailing ? $mailing->id : 'undefined';
         break;
 
+      // Key is the ID, or the hash when the hash URLs setting is enabled
+      case 'key':
+        $value = $mailing->id;
+        if ($hash = CRM_Mailing_BAO_Mailing::getMailingHash($value)) {
+          $value = $hash;
+        }
+        break;
+
       case 'name':
         $value = $mailing ? $mailing->name : 'Mailing Name';
         break;