-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmailingtools.php
160 lines (147 loc) · 5.24 KB
/
mailingtools.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
require_once 'mailingtools.civix.php';
use CRM_Mailingtools_ExtensionUtil as E;
/**
* Implements hook_civicrm_config().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
*/
function mailingtools_civicrm_config(&$config) {
_mailingtools_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_install().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function mailingtools_civicrm_install() {
_mailingtools_civix_civicrm_install();
}
/**
* Implements hook_civicrm_enable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
*/
function mailingtools_civicrm_enable() {
_mailingtools_civix_civicrm_enable();
CRM_Mailingtools_Config::installScheduledJob();
}
/**
* Implementes hook_civicrm_alterMailParams
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterMailParams/
*
* @param $params
* @param $context
*/
function mailingtools_civicrm_alterMailParams(&$params, $context) {
CRM_Mailingtools_InjectHeader::inject_header($params, $context);
}
/**
* We will provide our own Mailer (wrapping the original one).
* so we can manipulate the content of outgoing emails
*/
function mailingtools_civicrm_alterMailer(&$mailer, $driver, $params) {
$needed = CRM_Mailingtools_Mailer::isNeeded();
if ($needed) {
$mailer = new CRM_Mailingtools_Mailer($mailer,$driver, $params);
}
}
/**
* Set permissions for API calls
*/
function mailingtools_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions) {
if ($entity == 'mailingtools' && $action == 'anonopen') {
$config = CRM_Mailingtools_Config::singleton();
$anonopen_permission = $config->getSetting('anonymous_open_permission');
if ($anonopen_permission) {
$permissions['mailingtools']['anonopen'] = array($anonopen_permission);
} else {
$permissions['mailingtools']['anonopen'] = array('access CiviCRM');
}
} elseif ($entity == 'mailingtools' && $action == 'anonurl') {
$config = CRM_Mailingtools_Config::singleton();
$anonurl_permission = $config->getSetting('anonymous_link_permission');
if ($anonurl_permission) {
$permissions['mailingtools']['anonurl'] = array($anonurl_permission);
} else {
$permissions['mailingtools']['anonurl'] = array('access CiviCRM');
}
}
}
/**
* Some token fixes
* - make sure that hash is there
*/
function mailingtools_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null) {
$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');
}
}
}
}
}
}
/**
* Implements hook_civicrm_pre
* @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_pre/
*/
function mailingtools_civicrm_pre($op, $objectName, $id, &$params) {
if ($op == 'delete' && $id) {
if ($objectName == 'Individual' || $objectName == 'Household' || $objectName == 'Organization') {
// make sure the contact used for the anonymous open/click tracking is not deleted
$config = CRM_Mailingtools_Config::singleton();
$open_contact_id = (int) $config->getSetting('anonymous_open_contact_id');
$click_contact_id = (int) $config->getSetting('anonymous_link_contact_id');
if ($id == $open_contact_id || $id == $click_contact_id) {
throw new Exception(E::ts("You cannot delete the contact currently used for anonymous open/click tracking. Remove Contact [%1] from the settings of the MailingTools extension. Caution: you will lose the anonymous mailing statistics if you delete this contact.", [1 => $id]));
}
}
}
}
/**
* implements hook_civicrm_pageRun( &$page )
* @param $page
*/
function mailingtools_civicrm_pageRun(&$page) {
$name = $page->getVar('_name');
switch ($name) {
case 'Civi\\Angular\\Page\\Main':
CRM_Mailingtools_Page_MosaicoSave::buildPagehook($page);
break;
default:
return;
}
}
/**
* This hook is called after a db write on entities.
*
* @param string $op
* The type of operation being performed.
* @param string $objectName
* The name of the object.
* @param int $objectId
* The unique identifier for the object.
* @param object $objectRef
* The reference to the object.
*
* https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_post/
*/
function mailingtools_civicrm_post($op, $objectName, $objectId, &$objectRef) {
// Trigger when EMail is edited or updated
if($objectName == "Email" && in_array($op, ['update', 'edit', 'create'])) {
// TODO
// verify Email address; if invalid then set on hold
CRM_Mailingtools_Utils::verify_email($op, $objectName, $objectId,$objectRef);
CRM_Mailingtools_Utils::check_email_dns_blacklist($objectRef->email, $objectRef->id);
}
}