3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * This class introduces component to the system and provides all the
30 * information about it. It needs to extend CRM_Core_Component_Info
34 * @copyright CiviCRM LLC (c) 2004-2019
36 class CRM_Mailing_Info
extends CRM_Core_Component_Info
{
42 protected $keyword = 'mailing';
48 public function getInfo() {
51 'translatedName' => ts('CiviMail'),
52 'title' => ts('CiviCRM Mailing Engine'),
54 'showActivitiesInCore' => 1,
59 * Get AngularJS modules and their dependencies.
62 * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
63 * @see CRM_Utils_Hook::angularModules
65 public function getAngularModules() {
66 // load angular files only if valid permissions are granted to the user
67 if (!CRM_Core_Permission
::check('access CiviMail')
68 && !CRM_Core_Permission
::check('create mailings')
69 && !CRM_Core_Permission
::check('schedule mailings')
70 && !CRM_Core_Permission
::check('approve mailings')
77 $reportTypes = ['detail', 'opened', 'bounce', 'clicks'];
78 foreach ($reportTypes as $report) {
79 $result = civicrm_api3('ReportInstance', 'get', [
81 'report_id' => 'mailing/' . $report,
83 if (!empty($result['values'])) {
84 $reportIds[$report] = $result['values'][0]['id'];
88 $result['crmMailing'] = include "$civicrm_root/ang/crmMailing.ang.php";
89 $result['crmMailingAB'] = include "$civicrm_root/ang/crmMailingAB.ang.php";
90 $result['crmD3'] = include "$civicrm_root/ang/crmD3.ang.php";
92 $config = CRM_Core_Config
::singleton();
93 $session = CRM_Core_Session
::singleton();
94 $contactID = $session->get('userID');
98 'options' => ['limit' => 0],
101 $groupNames = civicrm_api3('Group', 'get', $params +
[
103 'check_permissions' => TRUE,
104 'return' => ['title', 'visibility', 'group_type', 'is_hidden'],
106 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params +
[
108 'return' => ['name', 'component_type', 'is_default', 'body_html', 'body_text'],
111 $emailAdd = civicrm_api3('Email', 'get', [
114 'contact_id' => $contactID,
117 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params +
[
120 'return' => ["id", "msg_title"],
121 'workflow_id' => ['IS NULL' => ""],
123 $mailTokens = civicrm_api3('Mailing', 'gettokens', [
124 'entity' => ['contact', 'mailing'],
127 $fromAddress = civicrm_api3('OptionValue', 'get', $params +
[
128 'option_group_id' => "from_email_address",
129 'domain_id' => CRM_Core_Config
::domainID(),
131 $enabledLanguages = CRM_Core_I18n
::languages(TRUE);
132 $isMultiLingual = (count($enabledLanguages) > 1);
133 // 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.
134 $requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver
::singleton()->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS
, []) : CRM_Utils_Token
::getRequiredTokens();
135 CRM_Core_Resources
::singleton()
138 'templateTypes' => CRM_Mailing_BAO_Mailing
::getTemplateTypes(),
140 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents
),
142 // @todo this is not used in core. Remove once Mosaico no longer depends on it.
143 'testGroupNames' => $groupNames['values'],
144 'headerfooterList' => $headerfooterList['values'],
145 'mesTemplate' => $mesTemplate['values'],
146 'emailAdd' => $emailAdd['values'],
147 'mailTokens' => $mailTokens['values'],
148 'contactid' => $contactID,
149 'requiredTokens' => $requiredTokens,
150 'enableReplyTo' => (int) Civi
::settings()->get('replyTo'),
151 'disableMandatoryTokensCheck' => (int) Civi
::settings()->get('disable_mandatory_tokens_check'),
152 'fromAddress' => $fromAddress['values'],
153 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', [
154 'id' => 'user_contact_id',
157 'visibility' => CRM_Utils_Array
::makeNonAssociative(CRM_Core_SelectValues
::groupVisibility()),
158 'workflowEnabled' => CRM_Mailing_Info
::workflowEnabled(),
159 'reportIds' => $reportIds,
160 'enabledLanguages' => $enabledLanguages,
161 'isMultiLingual' => $isMultiLingual,
171 'delete in CiviMail',
172 'edit message templates',
181 public static function workflowEnabled() {
182 $config = CRM_Core_Config
::singleton();
184 // early exit, since not true for most
185 if (!$config->userSystem
->is_drupal ||
186 !function_exists('module_exists')
191 if (!module_exists('rules')) {
195 $enableWorkflow = Civi
::settings()->get('civimail_workflow');
197 return ($enableWorkflow &&
198 $config->userSystem
->is_drupal
204 * @param bool $getAllUnconditionally
205 * @param bool $descriptions
206 * Whether to return permission descriptions
210 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
212 'access CiviMail' => [
213 ts('access CiviMail'),
215 'access CiviMail subscribe/unsubscribe pages' => [
216 ts('access CiviMail subscribe/unsubscribe pages'),
217 ts('Subscribe/unsubscribe from mailing list group'),
219 'delete in CiviMail' => [
220 ts('delete in CiviMail'),
221 ts('Delete Mailing'),
223 'view public CiviMail content' => [
224 ts('view public CiviMail content'),
228 if (self
::workflowEnabled() ||
$getAllUnconditionally) {
229 $permissions['create mailings'] = [
230 ts('create mailings'),
232 $permissions['schedule mailings'] = [
233 ts('schedule mailings'),
235 $permissions['approve mailings'] = [
236 ts('approve mailings'),
240 if (!$descriptions) {
241 foreach ($permissions as $name => $attr) {
242 $permissions[$name] = array_shift($attr);
253 public function getUserDashboardElement() {
254 // no dashboard element for this component
261 public function getUserDashboardObject() {
262 // no dashboard element for this component
270 public function registerTab() {
272 'title' => ts('Mailings'),
283 public function getIcon() {
284 return 'crm-i fa-envelope-o';
291 public function registerAdvancedSearchPane() {
293 'title' => ts('Mailings'),
302 public function getActivityTypes() {
307 * add shortcut to Create New.
310 public function creatNewShortcut(&$shortCuts) {