Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * This class introduces component to the system and provides all the | |
14 | * information about it. It needs to extend CRM_Core_Component_Info | |
15 | * abstract class. | |
16 | * | |
17 | * @package CRM | |
ca5cec67 | 18 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
19 | */ |
20 | class CRM_Mailing_Info extends CRM_Core_Component_Info { | |
21 | ||
e7c15cb6 | 22 | /** |
7e8c8317 | 23 | * @var string |
e7c15cb6 CW |
24 | * @inheritDoc |
25 | */ | |
6a488035 TO |
26 | protected $keyword = 'mailing'; |
27 | ||
e0ef6999 | 28 | /** |
e7c15cb6 | 29 | * @inheritDoc |
e0ef6999 EM |
30 | * @return array |
31 | */ | |
6a488035 | 32 | public function getInfo() { |
be2fb01f | 33 | return [ |
6a488035 TO |
34 | 'name' => 'CiviMail', |
35 | 'translatedName' => ts('CiviMail'), | |
e300cf31 | 36 | 'title' => ts('CiviCRM Mailing Engine'), |
6a488035 TO |
37 | 'search' => 1, |
38 | 'showActivitiesInCore' => 1, | |
be2fb01f | 39 | ]; |
6a488035 TO |
40 | } |
41 | ||
ced9bfed | 42 | /** |
25606795 | 43 | * Get AngularJS modules and their dependencies. |
ced9bfed EM |
44 | * |
45 | * @return array | |
46 | * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules) | |
47 | * @see CRM_Utils_Hook::angularModules | |
48 | */ | |
4aef704e | 49 | public function getAngularModules() { |
56621a6c KJ |
50 | // load angular files only if valid permissions are granted to the user |
51 | if (!CRM_Core_Permission::check('access CiviMail') | |
011c7136 KJ |
52 | && !CRM_Core_Permission::check('create mailings') |
53 | && !CRM_Core_Permission::check('schedule mailings') | |
54 | && !CRM_Core_Permission::check('approve mailings') | |
56621a6c | 55 | ) { |
be2fb01f | 56 | return []; |
56621a6c | 57 | } |
8456e727 | 58 | global $civicrm_root; |
56621a6c | 59 | |
be2fb01f CW |
60 | $reportIds = []; |
61 | $reportTypes = ['detail', 'opened', 'bounce', 'clicks']; | |
78414681 | 62 | foreach ($reportTypes as $report) { |
be2fb01f | 63 | $result = civicrm_api3('ReportInstance', 'get', [ |
78414681 | 64 | 'sequential' => 1, |
7e8c8317 SL |
65 | 'report_id' => 'mailing/' . $report, |
66 | ]); | |
56e3a6f6 | 67 | if (!empty($result['values'])) { |
68 | $reportIds[$report] = $result['values'][0]['id']; | |
69 | } | |
78414681 | 70 | } |
be2fb01f | 71 | $result = []; |
8456e727 TO |
72 | $result['crmMailing'] = include "$civicrm_root/ang/crmMailing.ang.php"; |
73 | $result['crmMailingAB'] = include "$civicrm_root/ang/crmMailingAB.ang.php"; | |
74 | $result['crmD3'] = include "$civicrm_root/ang/crmD3.ang.php"; | |
983052fe | 75 | |
8099bfee | 76 | $config = CRM_Core_Config::singleton(); |
6bea4a47 TO |
77 | $session = CRM_Core_Session::singleton(); |
78 | $contactID = $session->get('userID'); | |
d979898e | 79 | |
25606795 | 80 | // Generic params. |
be2fb01f CW |
81 | $params = [ |
82 | 'options' => ['limit' => 0], | |
a0f40af4 | 83 | 'sequential' => 1, |
be2fb01f CW |
84 | ]; |
85 | $groupNames = civicrm_api3('Group', 'get', $params + [ | |
31815c2b SL |
86 | 'is_active' => 1, |
87 | 'check_permissions' => TRUE, | |
be2fb01f CW |
88 | 'return' => ['title', 'visibility', 'group_type', 'is_hidden'], |
89 | ]); | |
90 | $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + [ | |
a0f40af4 | 91 | 'is_active' => 1, |
be2fb01f CW |
92 | 'return' => ['name', 'component_type', 'is_default', 'body_html', 'body_text'], |
93 | ]); | |
6bea4a47 | 94 | |
be2fb01f | 95 | $emailAdd = civicrm_api3('Email', 'get', [ |
44a7c67d TO |
96 | 'sequential' => 1, |
97 | 'return' => "email", | |
98 | 'contact_id' => $contactID, | |
be2fb01f | 99 | ]); |
a0f40af4 | 100 | |
be2fb01f | 101 | $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + [ |
44a7c67d | 102 | 'sequential' => 1, |
a0f40af4 | 103 | 'is_active' => 1, |
be2fb01f CW |
104 | 'return' => ["id", "msg_title"], |
105 | 'workflow_id' => ['IS NULL' => ""], | |
106 | ]); | |
107 | $mailTokens = civicrm_api3('Mailing', 'gettokens', [ | |
108 | 'entity' => ['contact', 'mailing'], | |
8099bfee | 109 | 'sequential' => 1, |
be2fb01f CW |
110 | ]); |
111 | $fromAddress = civicrm_api3('OptionValue', 'get', $params + [ | |
d979898e | 112 | 'option_group_id' => "from_email_address", |
84deca8b | 113 | 'domain_id' => CRM_Core_Config::domainID(), |
be2fb01f | 114 | ]); |
c00b95ef ML |
115 | $enabledLanguages = CRM_Core_I18n::languages(TRUE); |
116 | $isMultiLingual = (count($enabledLanguages) > 1); | |
b845ba46 | 117 | // FlexMailer is a refactoring of CiviMail which provides new hooks/APIs/docs. If the sysadmin has opted to enable it, then use that instead of CiviMail. |
be2fb01f | 118 | $requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver::singleton()->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS, []) : CRM_Utils_Token::getRequiredTokens(); |
a0f40af4 | 119 | CRM_Core_Resources::singleton() |
be2fb01f CW |
120 | ->addSetting([ |
121 | 'crmMailing' => [ | |
703875d8 | 122 | 'templateTypes' => CRM_Mailing_BAO_Mailing::getTemplateTypes(), |
be2fb01f | 123 | 'civiMails' => [], |
8099bfee | 124 | 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents), |
be2fb01f | 125 | 'groupNames' => [], |
d1aefa39 | 126 | // @todo this is not used in core. Remove once Mosaico no longer depends on it. |
31815c2b | 127 | 'testGroupNames' => $groupNames['values'], |
a0f40af4 CW |
128 | 'headerfooterList' => $headerfooterList['values'], |
129 | 'mesTemplate' => $mesTemplate['values'], | |
130 | 'emailAdd' => $emailAdd['values'], | |
a0f40af4 CW |
131 | 'mailTokens' => $mailTokens['values'], |
132 | 'contactid' => $contactID, | |
2d7b8444 | 133 | 'requiredTokens' => $requiredTokens, |
aaffa79f | 134 | 'enableReplyTo' => (int) Civi::settings()->get('replyTo'), |
135 | 'disableMandatoryTokensCheck' => (int) Civi::settings()->get('disable_mandatory_tokens_check'), | |
a0f40af4 | 136 | 'fromAddress' => $fromAddress['values'], |
be2fb01f | 137 | 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', [ |
7e8c8317 SL |
138 | 'id' => 'user_contact_id', |
139 | 'return' => 'email', | |
140 | ]), | |
a0f40af4 CW |
141 | 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()), |
142 | 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(), | |
78414681 | 143 | 'reportIds' => $reportIds, |
c00b95ef ML |
144 | 'enabledLanguages' => $enabledLanguages, |
145 | 'isMultiLingual' => $isMultiLingual, | |
be2fb01f CW |
146 | ], |
147 | ]) | |
148 | ->addPermissions([ | |
a0f40af4 | 149 | 'view all contacts', |
84fd40f3 | 150 | 'edit all contacts', |
a0f40af4 CW |
151 | 'access CiviMail', |
152 | 'create mailings', | |
153 | 'schedule mailings', | |
154 | 'approve mailings', | |
155 | 'delete in CiviMail', | |
867299da | 156 | 'edit message templates', |
be2fb01f | 157 | ]); |
983052fe | 158 | |
4aef704e | 159 | return $result; |
160 | } | |
983052fe | 161 | |
4aef704e | 162 | /** |
e0ef6999 EM |
163 | * @return bool |
164 | */ | |
00be9182 | 165 | public static function workflowEnabled() { |
6a488035 TO |
166 | $config = CRM_Core_Config::singleton(); |
167 | ||
168 | // early exit, since not true for most | |
169 | if (!$config->userSystem->is_drupal || | |
170 | !function_exists('module_exists') | |
171 | ) { | |
172 | return FALSE; | |
173 | } | |
174 | ||
175 | if (!module_exists('rules')) { | |
176 | return FALSE; | |
177 | } | |
178 | ||
aaffa79f | 179 | $enableWorkflow = Civi::settings()->get('civimail_workflow'); |
6a488035 | 180 | |
f7dbf5d9 | 181 | return $enableWorkflow && $config->userSystem->is_drupal; |
6a488035 TO |
182 | } |
183 | ||
e0ef6999 | 184 | /** |
e7c15cb6 | 185 | * @inheritDoc |
e0ef6999 | 186 | * @param bool $getAllUnconditionally |
221b21b4 AH |
187 | * @param bool $descriptions |
188 | * Whether to return permission descriptions | |
e0ef6999 EM |
189 | * |
190 | * @return array | |
191 | */ | |
221b21b4 | 192 | public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) { |
be2fb01f CW |
193 | $permissions = [ |
194 | 'access CiviMail' => [ | |
221b21b4 | 195 | ts('access CiviMail'), |
be2fb01f CW |
196 | ], |
197 | 'access CiviMail subscribe/unsubscribe pages' => [ | |
221b21b4 AH |
198 | ts('access CiviMail subscribe/unsubscribe pages'), |
199 | ts('Subscribe/unsubscribe from mailing list group'), | |
be2fb01f CW |
200 | ], |
201 | 'delete in CiviMail' => [ | |
221b21b4 AH |
202 | ts('delete in CiviMail'), |
203 | ts('Delete Mailing'), | |
be2fb01f CW |
204 | ], |
205 | 'view public CiviMail content' => [ | |
221b21b4 | 206 | ts('view public CiviMail content'), |
be2fb01f CW |
207 | ], |
208 | ]; | |
6a488035 | 209 | |
33777e4a | 210 | if (self::workflowEnabled() || $getAllUnconditionally) { |
be2fb01f | 211 | $permissions['create mailings'] = [ |
de4bf197 | 212 | ts('create mailings'), |
be2fb01f CW |
213 | ]; |
214 | $permissions['schedule mailings'] = [ | |
de4bf197 | 215 | ts('schedule mailings'), |
be2fb01f CW |
216 | ]; |
217 | $permissions['approve mailings'] = [ | |
de4bf197 | 218 | ts('approve mailings'), |
be2fb01f | 219 | ]; |
221b21b4 AH |
220 | } |
221 | ||
222 | if (!$descriptions) { | |
223 | foreach ($permissions as $name => $attr) { | |
224 | $permissions[$name] = array_shift($attr); | |
225 | } | |
6a488035 TO |
226 | } |
227 | ||
228 | return $permissions; | |
229 | } | |
230 | ||
e0ef6999 | 231 | /** |
e7c15cb6 | 232 | * @inheritDoc |
e0ef6999 EM |
233 | * @return null |
234 | */ | |
6a488035 TO |
235 | public function getUserDashboardElement() { |
236 | // no dashboard element for this component | |
237 | return NULL; | |
238 | } | |
239 | ||
e0ef6999 EM |
240 | /** |
241 | * @return null | |
242 | */ | |
6a488035 TO |
243 | public function getUserDashboardObject() { |
244 | // no dashboard element for this component | |
245 | return NULL; | |
246 | } | |
247 | ||
e0ef6999 | 248 | /** |
e7c15cb6 | 249 | * @inheritDoc |
e0ef6999 EM |
250 | * @return array |
251 | */ | |
6a488035 | 252 | public function registerTab() { |
be2fb01f | 253 | return [ |
2ede60ec DL |
254 | 'title' => ts('Mailings'), |
255 | 'id' => 'mailing', | |
256 | 'url' => 'mailing', | |
257 | 'weight' => 45, | |
be2fb01f | 258 | ]; |
6a488035 TO |
259 | } |
260 | ||
b04115b4 CW |
261 | /** |
262 | * @inheritDoc | |
263 | * @return string | |
264 | */ | |
265 | public function getIcon() { | |
266 | return 'crm-i fa-envelope-o'; | |
267 | } | |
268 | ||
e0ef6999 | 269 | /** |
e7c15cb6 | 270 | * @inheritDoc |
e0ef6999 EM |
271 | * @return array |
272 | */ | |
6a488035 | 273 | public function registerAdvancedSearchPane() { |
be2fb01f | 274 | return [ |
353ffa53 | 275 | 'title' => ts('Mailings'), |
6a488035 | 276 | 'weight' => 20, |
be2fb01f | 277 | ]; |
6a488035 TO |
278 | } |
279 | ||
e0ef6999 | 280 | /** |
e7c15cb6 | 281 | * @inheritDoc |
e0ef6999 EM |
282 | * @return null |
283 | */ | |
6a488035 TO |
284 | public function getActivityTypes() { |
285 | return NULL; | |
286 | } | |
287 | ||
e0ef6999 | 288 | /** |
fe482240 | 289 | * add shortcut to Create New. |
e0ef6999 EM |
290 | * @param $shortCuts |
291 | */ | |
35f7561f TO |
292 | public function creatNewShortcut(&$shortCuts) { |
293 | } | |
96025800 | 294 | |
6a488035 | 295 | } |