3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
36 class CRM_Mailing_Info
extends CRM_Core_Component_Info
{
41 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 = array('detail', 'opened', 'bounce', 'clicks');
78 foreach ($reportTypes as $report) {
79 $result = civicrm_api3('ReportInstance', 'get', array(
81 'report_id' => 'mailing/' . $report));
82 if (!empty($result['values'])) {
83 $reportIds[$report] = $result['values'][0]['id'];
87 $result['crmMailing'] = include "$civicrm_root/ang/crmMailing.ang.php";
88 $result['crmMailingAB'] = include "$civicrm_root/ang/crmMailingAB.ang.php";
89 $result['crmD3'] = include "$civicrm_root/ang/crmD3.ang.php";
91 $config = CRM_Core_Config
::singleton();
92 $session = CRM_Core_Session
::singleton();
93 $contactID = $session->get('userID');
97 'options' => array('limit' => 0),
100 $groupNames = civicrm_api3('Group', 'get', $params +
array(
102 'check_permissions' => TRUE,
103 'return' => array('title', 'visibility', 'group_type', 'is_hidden'),
105 $headerfooterList = civicrm_api3('MailingComponent', 'get', $params +
array(
107 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'),
110 $emailAdd = civicrm_api3('Email', 'get', array(
113 'contact_id' => $contactID,
116 $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params +
array(
119 'return' => array("id", "msg_title"),
120 'workflow_id' => array('IS NULL' => ""),
122 $mailTokens = civicrm_api3('Mailing', 'gettokens', array(
123 'entity' => array('contact', 'mailing'),
126 $fromAddress = civicrm_api3('OptionValue', 'get', $params +
array(
127 'option_group_id' => "from_email_address",
128 'domain_id' => CRM_Core_Config
::domainID(),
130 $enabledLanguages = CRM_Core_I18n
::languages(TRUE);
131 $isMultiLingual = (count($enabledLanguages) > 1);
132 // 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.
133 $requiredTokens = defined('CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS') ? Civi\Core\Resolver
::singleton()->call(CIVICRM_FLEXMAILER_HACK_REQUIRED_TOKENS
, array()) : CRM_Utils_Token
::getRequiredTokens();
134 CRM_Core_Resources
::singleton()
136 'crmMailing' => array(
137 'templateTypes' => CRM_Mailing_BAO_Mailing
::getTemplateTypes(),
138 'civiMails' => array(),
139 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents
),
140 'groupNames' => array(),
141 // @todo this is not used in core. Remove once Mosaico no longer depends on it.
142 'testGroupNames' => $groupNames['values'],
143 'headerfooterList' => $headerfooterList['values'],
144 'mesTemplate' => $mesTemplate['values'],
145 'emailAdd' => $emailAdd['values'],
146 'mailTokens' => $mailTokens['values'],
147 'contactid' => $contactID,
148 'requiredTokens' => $requiredTokens,
149 'enableReplyTo' => (int) Civi
::settings()->get('replyTo'),
150 'disableMandatoryTokensCheck' => (int) Civi
::settings()->get('disable_mandatory_tokens_check'),
151 'fromAddress' => $fromAddress['values'],
152 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array(
153 'id' => 'user_contact_id',
156 'visibility' => CRM_Utils_Array
::makeNonAssociative(CRM_Core_SelectValues
::groupVisibility()),
157 'workflowEnabled' => CRM_Mailing_Info
::workflowEnabled(),
158 'reportIds' => $reportIds,
159 'enabledLanguages' => $enabledLanguages,
160 'isMultiLingual' => $isMultiLingual,
163 ->addPermissions(array(
170 'delete in CiviMail',
171 'edit message templates',
180 public static function workflowEnabled() {
181 $config = CRM_Core_Config
::singleton();
183 // early exit, since not true for most
184 if (!$config->userSystem
->is_drupal ||
185 !function_exists('module_exists')
190 if (!module_exists('rules')) {
194 $enableWorkflow = Civi
::settings()->get('civimail_workflow');
196 return ($enableWorkflow &&
197 $config->userSystem
->is_drupal
203 * @param bool $getAllUnconditionally
204 * @param bool $descriptions
205 * Whether to return permission descriptions
209 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
210 $permissions = array(
211 'access CiviMail' => array(
212 ts('access CiviMail'),
214 'access CiviMail subscribe/unsubscribe pages' => array(
215 ts('access CiviMail subscribe/unsubscribe pages'),
216 ts('Subscribe/unsubscribe from mailing list group'),
218 'delete in CiviMail' => array(
219 ts('delete in CiviMail'),
220 ts('Delete Mailing'),
222 'view public CiviMail content' => array(
223 ts('view public CiviMail content'),
227 if (self
::workflowEnabled() ||
$getAllUnconditionally) {
228 $permissions['create mailings'] = array(
229 ts('create mailings'),
231 $permissions['schedule mailings'] = array(
232 ts('schedule mailings'),
234 $permissions['approve mailings'] = array(
235 ts('approve mailings'),
239 if (!$descriptions) {
240 foreach ($permissions as $name => $attr) {
241 $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 registerAdvancedSearchPane() {
285 'title' => ts('Mailings'),
294 public function getActivityTypes() {
299 * add shortcut to Create New.
302 public function creatNewShortcut(&$shortCuts) {