3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 require_once 'Mail/mime.php';
21 * Class CRM_Mailing_Event_BAO_Confirm
23 class CRM_Mailing_Event_BAO_Confirm
extends CRM_Mailing_Event_DAO_Confirm
{
26 * Confirm a pending subscription.
28 * @param int $contact_id
29 * The id of the contact.
30 * @param int $subscribe_id
31 * The id of the subscription event.
38 public static function confirm($contact_id, $subscribe_id, $hash) {
39 $se = &CRM_Mailing_Event_BAO_Subscribe
::verify(
49 // before we proceed lets just check if this contact is already 'Added'
50 // if so, we should ignore this request and hence avoid sending multiple
52 $details = CRM_Contact_BAO_GroupContact
::getMembershipDetail($contact_id, $se->group_id
);
53 if ($details && $details->status
== 'Added') {
54 // This contact is already subscribed
55 // lets return the group title
56 return CRM_Core_DAO
::getFieldValue(
57 'CRM_Contact_DAO_Group',
63 $transaction = new CRM_Core_Transaction();
65 $ce = new CRM_Mailing_Event_BAO_Confirm();
66 $ce->event_subscribe_id
= $se->id
;
67 $ce->time_stamp
= date('YmdHis');
70 CRM_Contact_BAO_GroupContact
::addContactsToGroup(
78 $transaction->commit();
80 $config = CRM_Core_Config
::singleton();
82 $domain = CRM_Core_BAO_Domain
::getDomain();
83 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain
::getNameAndEmail();
85 list($display_name, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($se->contact_id
);
87 $group = new CRM_Contact_DAO_Group();
88 $group->id
= $se->group_id
;
91 $component = new CRM_Mailing_BAO_MailingComponent();
92 $component->is_default
= 1;
93 $component->is_active
= 1;
94 $component->component_type
= 'Welcome';
96 $component->find(TRUE);
98 $html = $component->body_html
;
100 if ($component->body_text
) {
101 $text = $component->body_text
;
104 $text = CRM_Utils_String
::htmlToText($component->body_html
);
107 $bao = new CRM_Mailing_BAO_Mailing();
108 $bao->body_text
= $text;
109 $bao->body_html
= $html;
110 $tokens = $bao->getTokens();
112 $html = CRM_Utils_Token
::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
113 $html = CRM_Utils_Token
::replaceWelcomeTokens($html, $group->title
, TRUE);
115 $text = CRM_Utils_Token
::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
116 $text = CRM_Utils_Token
::replaceWelcomeTokens($text, $group->title
, FALSE);
119 'groupName' => 'Mailing Event ' . $component->component_type
,
120 'subject' => $component->subject
,
121 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>",
123 'toName' => $display_name,
124 'replyTo' => CRM_Core_BAO_Domain
::getNoReplyEmailAddress(),
125 'returnPath' => CRM_Core_BAO_Domain
::getNoReplyEmailAddress(),
129 // send - ignore errors because the desired status change has already been successful
130 $unused_result = CRM_Utils_Mail
::send($mailParams);
132 return $group->title
;