Skip to content

Commit

Permalink
[#5] add option to turn on/off the token fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Feb 21, 2019
1 parent aa621e1 commit 23ce233
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
9 changes: 9 additions & 0 deletions CRM/Mailingtools/Form/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ public function buildQuickForm() {
FALSE
);

// Token Tools
$this->add(
'checkbox',
'fix_hash_token',
E::ts('Fix {contact.hash} Token')
);


// load contacts
$this->renderContact($current_values, 'link');

Expand Down Expand Up @@ -187,6 +195,7 @@ protected function getSettingsInForm() {
'anonymous_link_url',
'anonymous_link_permission',
'anonymous_link_contact_id',
'fix_hash_token',
);
}

Expand Down
21 changes: 13 additions & 8 deletions mailingtools.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,19 @@ function mailingtools_civicrm_alterAPIPermissions($entity, $action, &$params, &$
* - make sure that hash is there
*/
function mailingtools_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null) {
// make sure 'hash' is there:
if (!empty($tokens['contact'])) {
if (in_array('hash', $tokens['contact']) || !empty($tokens['contact']['hash'])) {
// hash token is requested
foreach ($values as $contact_id => &$contact_values) {
if (empty($contact_values['hash'])) {
CRM_Contact_BAO_Contact_Utils::generateChecksum($contact_id);
$contact_values['hash'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact_id, 'hash');
$config = CRM_Mailingtools_Config::singleton();

$fix_hash_token = $config->getSetting('fix_hash_token');
if ($fix_hash_token) {
// make sure 'hash' is there:
if (!empty($tokens['contact'])) {
if (in_array('hash', $tokens['contact']) || !empty($tokens['contact']['hash'])) {
// hash token is requested
foreach ($values as $contact_id => &$contact_values) {
if (empty($contact_values['hash'])) {
CRM_Contact_BAO_Contact_Utils::generateChecksum($contact_id);
$contact_values['hash'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contact_id, 'hash');
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions templates/CRM/Mailingtools/Form/Settings.hlp
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@
<p>{ts domain="de.systopia.mailingtools"}You can define a contact ID to be used as a <i>the</i> anonymous contact.{/ts}</p>
<p>{ts domain="de.systopia.mailingtools"}If you don't do that, the contact with the smallest ID will be used in any tracked click events.{/ts}</p>
{/htxt}

{htxt id="id-mailtools-fix-hash-token"}
<p>{ts domain="de.systopia.mailingtools"}If you have problems filling the {literal}{contact.hash}{/literal} token with Mosaico/Flexmailer, you may try activating this option.{/ts}</p>
{/htxt}
22 changes: 16 additions & 6 deletions templates/CRM/Mailingtools/Form/Settings.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
| written permission from the original author(s). |
+-------------------------------------------------------*}

<h3>{ts domain='de.systopia.mailingtools'}Custom Mail Header Fields{/ts}</h3>
<br/><h3>{ts domain='de.systopia.mailingtools'}Custom Mail Header Fields{/ts}</h3><br/>

<div class="crm-section mailingtools mailingtools-custommailheader">
<div class="crm-section mailingtools mailingtools">
<div class="crm-section">
<div class="label">{$form.extra_mail_header_key.label}</div>
<div class="content">{$form.extra_mail_header_key.html}</div>
Expand All @@ -26,7 +26,7 @@
<div class="clear"></div>
</div>

<h3>{ts domain='de.systopia.mailingtools'}Anonymous Open Tracking{/ts}</h3>
<br/><h3>{ts domain='de.systopia.mailingtools'}Anonymous Open Tracking{/ts}</h3><br/>
<div class="crm-section">
<div class="label">{$form.anonymous_open_enabled.label} <a onclick='CRM.help("{ts domain='de.systopia.mailingtools'}Anonymous Open Tracking{/ts}", {literal}{"id":"id-mailtools-anonymous-open-enable","file":"CRM\/Mailingtools\/Form\/Settings"}{/literal}); return false;' href="#" title="{ts domain='de.systopia.mailingtools'}Help{/ts}" class="helpicon">&nbsp;</a></div>
<div class="content">{$form.anonymous_open_enabled.html}</div>
Expand All @@ -52,7 +52,7 @@
</div>
<h3>{ts domain='de.systopia.mailingtools'}Anonymous Link Tracking{/ts}</h3>
<br/><h3>{ts domain='de.systopia.mailingtools'}Anonymous Link Tracking{/ts}</h3><br/>
<div class="crm-section">
<div class="label">{$form.anonymous_link_enabled.label} <a onclick='CRM.help("{ts domain='de.systopia.mailingtools'}Anonymous Link Tracking{/ts}", {literal}{"id":"id-mailtools-anonymous-link-enable","file":"CRM\/Mailingtools\/Form\/Settings"}{/literal}); return false;' href="#" title="{ts domain='de.systopia.mailingtools'}Help{/ts}" class="helpicon">&nbsp;</a></div>
<div class="content">{$form.anonymous_link_enabled.html}</div>
Expand All @@ -78,7 +78,7 @@
</div>
<h3>{ts domain='de.systopia.mailingtools'}Bounce Mailbox Retention{/ts}</h3>
<br/><h3>{ts domain='de.systopia.mailingtools'}Bounce Mailbox Retention{/ts}</h3><br/>
<p>{ts domain='de.systopia.mailingtools'}Retention Time is interpreted as days. If no value is configured, no mails will be deleted.{/ts}</p>
<div class="crm-section">
Expand All @@ -93,8 +93,18 @@
</div>
<br/><h3>{ts domain='de.systopia.mailingtools'}Token Tools{/ts}</h3><br/>
<div class="crm-section">
<div class="label">{$form.fix_hash_token.label} <a onclick='CRM.help("{ts domain='de.systopia.mailingtools'}Anonymous Contact ID{/ts}", {literal}{"id":"id-mailtools-fix-hash-token","file":"CRM\/Mailingtools\/Form\/Settings"}{/literal}); return false;' href="#" title="{ts domain='de.systopia.mailingtools'}Help{/ts}" class="helpicon">&nbsp;</a></div>
<div class="content">{$form.fix_hash_token.html}</div>
<div class="clear"></div>
</div>
</div>
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
Expand All @@ -104,7 +114,7 @@
<br/><br/><br/><br/>
<h3>{ts domain='de.systopia.mailingtools'}Additional Bounce Patterns{/ts}</h3>
<br/><h3>{ts domain='de.systopia.mailingtools'}Additional Bounce Patterns{/ts}</h3>
<p><i>{ts domain='de.systopia.mailingtools'}Add additional Bounce pattern to the Database. Checks first if pattern is already available. Outputs the number of pattern added/ignored from the specified file.{/ts}</i></p>
<div class="crm-section mailingtools mailingtools-custommailheader">
Expand Down

0 comments on commit 23ce233

Please sign in to comment.