From: JKingsnorth Date: Fri, 21 Jun 2019 11:05:18 +0000 (+0100) Subject: #1064 Allow personalised 'view in browser' links for mass emails X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b56b8b0e21208f6e0575f5dfebf3bcea0eb17070;p=civicrm-core.git #1064 Allow personalised 'view in browser' links for mass emails --- diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 497e0904fa..b67f98c262 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -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'), diff --git a/CRM/Mailing/Page/View.php b/CRM/Mailing/Page/View.php index 878434004e..961b4b5b84 100644 --- a/CRM/Mailing/Page/View.php +++ b/CRM/Mailing/Page/View.php @@ -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(); } diff --git a/CRM/Mailing/Tokens.php b/CRM/Mailing/Tokens.php index efde6376b2..16b5ccac23 100644 --- a/CRM/Mailing/Tokens.php +++ b/CRM/Mailing/Tokens.php @@ -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'), diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index d9014d7760..8fcc556713 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -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;