/**
  * Method for testing creating a simple notification for the current user.
  */
 public function actionGenerateManageSubscriptionHash()
 {
     if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) {
         throw new NotSupportedException();
     }
     $contact = RandomDataUtil::getRandomValueFromArray(Contact::getAll());
     $personId = $contact->getClassId('Person');
     $marketingList = RandomDataUtil::getRandomValueFromArray(MarketingList::getAll());
     $marketingListId = $marketingList->id;
     $model = RandomDataUtil::getRandomValueFromArray(CampaignItem::getAll());
     $modelId = $model->id;
     $modelType = get_class($model);
     $hash = GlobalMarketingFooterUtil::resolveHash($personId, $marketingListId, $modelId, $modelType, false);
     echo 'index.php/marketingLists/external/manageSubscriptions?hash=' . $hash;
 }
 public function testMakeFormAndSetConfigurationFromForm()
 {
     $form = MarketingConfigurationFormAdapter::makeFormFromMarketingConfiguration();
     $this->assertEquals(GlobalMarketingFooterUtil::getContentByType(false), $form->autoresponderOrCampaignFooterPlainText);
     $this->assertEquals(GlobalMarketingFooterUtil::getContentByType(true), $form->autoresponderOrCampaignFooterRichText);
     //User is not root so he cant change batch size
     $form->autoresponderOrCampaignFooterPlainText = 'abc';
     $form->autoresponderOrCampaignFooterRichText = 'def';
     MarketingConfigurationFormAdapter::setConfigurationFromForm($form);
     $form = MarketingConfigurationFormAdapter::makeFormFromMarketingConfiguration();
     $this->assertEquals('abc', $form->autoresponderOrCampaignFooterPlainText);
     $this->assertEquals('def', $form->autoresponderOrCampaignFooterRichText);
     //User is root so he can change batch size
     $super = User::getByUsername('super');
     $super->setIsRootUser();
     Yii::app()->user->userModel = $super;
     $form->autoresponderOrCampaignFooterPlainText = 'cba';
     $form->autoresponderOrCampaignFooterRichText = 'fed';
     MarketingConfigurationFormAdapter::setConfigurationFromForm($form);
     $form = MarketingConfigurationFormAdapter::makeFormFromMarketingConfiguration();
     $this->assertEquals('cba', $form->autoresponderOrCampaignFooterPlainText);
     $this->assertEquals('fed', $form->autoresponderOrCampaignFooterRichText);
 }
 /**
  * Resolve content for merge tags and return resolution result
  * @param $content
  * @param RedBeanModel $attachedModel
  * @param int $emailTemplateType
  * @param int $errorOnFirstMissing
  * @param null $language
  * @param array $invalidTags
  * @param null $marketingListId
  * @param bool $preview
  * @param null $modelId
  * @param null $modelType
  * @param null $personId
  * @param bool $isHtmlContent
  * @return bool
  * @throws NotSupportedException
  */
 public static function resolveContentForMergeTags(&$content, RedBeanModel $attachedModel = null, $emailTemplateType = EmailTemplate::TYPE_CONTACT, $errorOnFirstMissing = MergeTagsToModelAttributesAdapter::ERROR_ON_FIRST_INVALID_TAG, $language = null, array &$invalidTags = array(), $marketingListId = null, $preview = false, $modelId = null, $modelType = null, $personId = null, $isHtmlContent = false)
 {
     $params = GlobalMarketingFooterUtil::resolveFooterMergeTagsArray($personId, $marketingListId, $modelId, $modelType, !$preview, $preview, $isHtmlContent);
     $util = MergeTagsUtilFactory::make($emailTemplateType, $language, $content);
     $resolvedContent = $util->resolveMergeTags($attachedModel, $invalidTags, $language, $errorOnFirstMissing, $params);
     if ($resolvedContent !== false) {
         $content = $resolvedContent;
         return true;
     }
     return false;
 }
 protected function resolveMergeTagParams()
 {
     return GlobalMarketingFooterUtil::resolveFooterMergeTagsArray(1, 2, 3, 'AutoresponderItem', false, true);
 }
 protected function renderSpecialTagsContent()
 {
     $content = ZurmoHtml::tag('h4', array(), 'Special Tags');
     $content = ZurmoHtml::tag('div', array('id' => 'mergetag-special-tags-head'), $content);
     $specialTagsContent = null;
     $specialTagsItems = array();
     $specialTagsItems[] = $this->renderBoldMergeTag(MergeTagsUtil::TAG_PREFIX . "MODEL" . MergeTagsUtil::CAPITAL_DELIMITER . "URL" . MergeTagsUtil::TAG_SUFFIX) . " : prints absolute url to the current model attached to template.";
     $specialTagsItems[] = $this->renderBoldMergeTag(MergeTagsUtil::TAG_PREFIX . "BASE" . MergeTagsUtil::CAPITAL_DELIMITER . "URL" . MergeTagsUtil::TAG_SUFFIX) . " : prints absolute url to the current install without trailing slash.";
     $specialTagsItems[] = $this->renderBoldMergeTag(MergeTagsUtil::TAG_PREFIX . "APPLICATION" . MergeTagsUtil::CAPITAL_DELIMITER . "NAME" . MergeTagsUtil::TAG_SUFFIX) . " : prints application name as set in global settings > application name.";
     $specialTagsItems[] = $this->renderBoldMergeTag(MergeTagsUtil::TAG_PREFIX . "CURRENT" . MergeTagsUtil::CAPITAL_DELIMITER . "YEAR" . MergeTagsUtil::TAG_SUFFIX) . " : prints current year.";
     $specialTagsItems[] = $this->renderBoldMergeTag(MergeTagsUtil::TAG_PREFIX . "LAST" . MergeTagsUtil::CAPITAL_DELIMITER . "YEAR" . MergeTagsUtil::TAG_SUFFIX) . " : prints last year.";
     $specialTagsItems[] = $this->renderBoldMergeTag(MergeTagsUtil::TAG_PREFIX . 'OWNERS' . MergeTagsUtil::CAPITAL_DELIMITER . 'AVATAR' . MergeTagsUtil::CAPITAL_DELIMITER . 'SMALL' . MergeTagsUtil::TAG_SUFFIX) . " : prints the owner's small avatar image (32x32).";
     $specialTagsItems[] = $this->renderBoldMergeTag(MergeTagsUtil::TAG_PREFIX . 'OWNERS' . MergeTagsUtil::CAPITAL_DELIMITER . 'AVATAR' . MergeTagsUtil::CAPITAL_DELIMITER . 'MEDIUM ' . MergeTagsUtil::TAG_SUFFIX) . " : prints the owner's medium avatar image (64x64).";
     $specialTagsItems[] = $this->renderBoldMergeTag(MergeTagsUtil::TAG_PREFIX . 'OWNERS' . MergeTagsUtil::CAPITAL_DELIMITER . 'AVATAR' . MergeTagsUtil::CAPITAL_DELIMITER . 'LARGE' . MergeTagsUtil::TAG_SUFFIX) . " : prints the owner's large avatar image (128x128).";
     $specialTagsItems[] = $this->renderBoldMergeTag(MergeTagsUtil::TAG_PREFIX . 'OWNERS' . MergeTagsUtil::CAPITAL_DELIMITER . 'EMAIL' . MergeTagsUtil::CAPITAL_DELIMITER . 'SIGNATURE' . MergeTagsUtil::TAG_SUFFIX) . " : prints the owner's email signature.";
     $specialTagsItems[] = $this->renderBoldMergeTag(MergeTagsUtil::TAG_PREFIX . 'GLOBAL' . MergeTagsUtil::CAPITAL_DELIMITER . 'MARKETING' . MergeTagsUtil::CAPITAL_DELIMITER . 'FOOTER' . MergeTagsUtil::CAPITAL_DELIMITER . 'PLAIN' . MergeTagsUtil::CAPITAL_DELIMITER . 'TEXT' . MergeTagsUtil::TAG_SUFFIX) . " : prints the Global Marketing Footer(Plain Text).";
     $specialTagsItems[] = $this->renderBoldMergeTag(MergeTagsUtil::TAG_PREFIX . 'GLOBAL' . MergeTagsUtil::CAPITAL_DELIMITER . 'MARKETING' . MergeTagsUtil::CAPITAL_DELIMITER . 'FOOTER' . MergeTagsUtil::CAPITAL_DELIMITER . 'HTML' . MergeTagsUtil::TAG_SUFFIX) . " : prints the Global Marketing Footer(Rich Text).";
     $specialTagsItems[] = $this->renderBoldMergeTag(GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag()) . " : prints unsubscribe url.";
     $specialTagsItems[] = $this->renderBoldMergeTag(GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag()) . " : prints manage subscriptions url.";
     foreach ($specialTagsItems as $specialTagsItem) {
         $specialTagsContent .= ZurmoHtml::tag('li', array(), $specialTagsItem);
     }
     $specialTagsContent = ZurmoHtml::tag('ul', array(), $specialTagsContent);
     $specialTagsContent = ZurmoHtml::tag('div', array('id' => 'mergetag-special-tags-body'), $specialTagsContent);
     $content .= $specialTagsContent;
     $content = ZurmoHtml::tag('div', array('id' => 'mergetag-special-tags'), $content);
     return $content;
 }
                                                <!-- /standard article (right text) -->

                                            </td>
                                        </tr>
                                        <!-- /CONTENT -->

                                        <!-- FOOTER -->
                                        <tr>
                                            <td>
                                                <table bgcolor="#cccccc" text="#ffffff" width="100%" cellpadding="0" cellspacing="0" border="0">
                                                    <tr>
                                                        <td>
                                                            <table align="left" bgcolor="#cccccc" text="#333333" width="280" cellpadding="10" cellspacing="0" border="0" class="footer-left">
                                                                <tr>
                                                                    <td style="color:#333333;">
                                                                             <p> ' . GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag() . ' <br/> ' . GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag() . '</p>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                            <table align="right" bgcolor="#cccccc" text="#333333" width="280" cellpadding="10" cellspacing="0" border="0" class="footer-right">
                                                                <tr>
                                                                    <td style="color:#333333;">
                                                                        <p>
                                                                            <a href="#" target="_blank"><img style="margin-left:1em;" align="right" src="' . PlaceholderImageUtil::resolveUrlForThemeFile('/default/images/demo/email-template-demo-one/facebook.gif') . '" width="32" height="32" border="0" alt="Facebook" /></a>
                                                                            <a href="#" target="_blank"><img style="margin-left:1em;" align="right" src="' . PlaceholderImageUtil::resolveUrlForThemeFile('/default/images/demo/email-template-demo-one/googleplus.gif') . '" width="32" height="32" border="0" alt="Google+" /></a>
                                                                            <a href="#" target="_blank"><img style="margin-left:1em;" align="right" src="' . PlaceholderImageUtil::resolveUrlForThemeFile('/default/images/demo/email-template-demo-one/linkedin.gif') . '" width="32" height="32" border="0" alt="LinkedIn" /></a>
                                                                            <a href="#" target="_blank"><img style="margin-left:1em;" align="right" src="' . PlaceholderImageUtil::resolveUrlForThemeFile('/default/images/demo/email-template-demo-one/twitter.gif') . '" width="32" height="32" border="0" alt="Twitter" /></a>
                                                                            <a href="#" target="_blank"><img style="margin-left:1em;" align="right" src="' . PlaceholderImageUtil::resolveUrlForThemeFile('/default/images/demo/email-template-demo-one/youtube.gif') . '" width="32" height="32" border="0" alt="YouTube" /></a>
                                                                        </p>
                                                                    </td>
                                                                </tr>
 /**
  * @depends testDetailsJsonActionForWorkflow
  */
 public function testDetailsJsonActionWithMergeTagResolution()
 {
     $contact = ContactTestHelper::createContactByNameForOwner('test', $this->user);
     $emailTemplateId = self::getModelIdByModelNameAndName('EmailTemplate', 'marketing 01');
     $emailTemplate = EmailTemplate::getById($emailTemplateId);
     $unsubscribePlaceholder = GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag();
     $manageSubscriptionsPlaceholder = GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag();
     $emailTemplate->textContent = "Test text content with contact tag: [[FIRST^NAME]] {$unsubscribePlaceholder}";
     $emailTemplate->htmlContent = "Test html content with contact tag: [[FIRST^NAME]] {$manageSubscriptionsPlaceholder}";
     $this->assertTrue($emailTemplate->save());
     $this->setGetArray(array('id' => $emailTemplateId, 'renderJson' => true, 'includeFilesInJson' => false, 'contactId' => $contact->id));
     // @ to avoid headers already sent error.
     $content = @$this->runControllerWithExitExceptionAndGetContent('emailTemplates/default/detailsJson');
     $emailTemplateDetailsResolvedArray = CJSON::decode($content);
     $this->assertNotEmpty($emailTemplateDetailsResolvedArray);
     $this->assertEquals('Test text content with contact tag: test ', $emailTemplateDetailsResolvedArray['textContent']);
     $this->assertEquals('Test html content with contact tag: test ', $emailTemplateDetailsResolvedArray['htmlContent']);
 }
 public function actionDetailsJson($id, $includeFilesInJson = false, $contactId = null)
 {
     $contactId = (int) $contactId;
     $emailTemplate = static::getModelAndCatchNotFoundAndDisplayError('EmailTemplate', intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($emailTemplate);
     header('Content-type: application/json');
     if ($contactId != null) {
         $contact = Contact::getById($contactId);
         $textContent = $emailTemplate->textContent;
         $htmlContent = $emailTemplate->htmlContent;
         GlobalMarketingFooterUtil::removeFooterMergeTags($textContent);
         GlobalMarketingFooterUtil::removeFooterMergeTags($htmlContent);
         // we have already stripped off the merge tags that could introduce problems,
         // no need to send actual data for personId, modelId, modelType and marketingListId.
         AutoresponderAndCampaignItemsUtil::resolveContentsForMergeTags($textContent, $htmlContent, $contact, null, null, null, null);
         $emailTemplate->setTreatCurrentUserAsOwnerForPermissions(true);
         $emailTemplate->textContent = stripslashes($textContent);
         $emailTemplate->htmlContent = stripslashes($htmlContent);
         $emailTemplate->setTreatCurrentUserAsOwnerForPermissions(false);
     }
     $emailTemplate = $this->resolveEmailTemplateAsJson($emailTemplate, $includeFilesInJson);
     echo $emailTemplate;
     Yii::app()->end(0, false);
 }
 /**
  * @depends testResolveManageSubscriptionsUrlWithMissingSomeOptionalParams
  */
 public function testResolveManageSubscriptionsUrlWithoutModel()
 {
     $errorOnFirstMissing = MergeTagsToModelAttributesAdapter::DO_NOT_ERROR_ON_FIRST_INVALID_TAG;
     $model = null;
     $params = array('personId' => 1, 'marketingListId' => 2, 'modelId' => 3, 'modelType' => 'AutoresponderItem', 'createNewActivity' => true, 'preview' => false);
     $expected = GlobalMarketingFooterUtil::resolveManageSubscriptionsUrlByArray($params);
     $this->assertContains('marketingLists/external/manageSubscriptions?hash=', $expected);
     $resolved = SpecialMergeTagsAdapter::resolve('manageSubscriptionsUrl', $model, $errorOnFirstMissing, $params);
     $this->assertContains('marketingLists/external/manageSubscriptions?hash=', $resolved);
     $expectedHash = static::extractHashFromUrl($expected);
     $resolvedHash = static::extractHashFromUrl($resolved);
     $expectedReversed = EmailMessageActivityUtil::resolveQueryStringArrayForHash($expectedHash);
     $resolvedReversed = EmailMessageActivityUtil::resolveQueryStringArrayForHash($resolvedHash);
     $this->assertEquals($expectedReversed, $resolvedReversed);
 }
 protected static function resolveContentForMergeTags(&$content)
 {
     $language = null;
     $errorOnFirstMissing = true;
     $templateType = EmailTemplate::TYPE_CONTACT;
     $invalidTags = array();
     $textMergeTagsUtil = MergeTagsUtilFactory::make($templateType, $language, $content);
     $params = GlobalMarketingFooterUtil::resolveFooterMergeTagsArray(1, 2, 3, 'AutoresponderITem', true, false);
     $content = $textMergeTagsUtil->resolveMergeTags(Yii::app()->user->userModel, $invalidTags, $language, $errorOnFirstMissing, $params);
     return $content !== false;
 }
 /**
  * @depends testCreateAndGetEmailTemplateById
  */
 public function testUnsubscribeAndManageSubscriptionsMergeTagsValidation()
 {
     $emailTemplate = new EmailTemplate();
     $emailTemplate->type = EmailTemplate::TYPE_CONTACT;
     $emailTemplate->subject = 'Another Test subject';
     $emailTemplate->name = 'Another Test Email Template';
     $emailTemplate->textContent = GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag() . ', ' . GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag();
     $emailTemplate->htmlContent = GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag() . ', ' . GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag();
     $emailTemplate->builtType = EmailTemplate::BUILT_TYPE_PASTED_HTML;
     $emailTemplate->modelClassName = 'Contact';
     $validated = $emailTemplate->validate(null, false, true);
     $this->assertTrue($validated);
     $this->assertEmpty($emailTemplate->getErrors());
 }
 /**
  * @depends testOptOutAction
  */
 public function testSubscribeActionAfterOptOutActionDisableOptOut()
 {
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $marketingList = MarketingList::getByName('marketingList 04');
     $this->assertNotEmpty($marketingList);
     $marketingList = $marketingList[0];
     $marketingListId = $marketingList->id;
     $contact = Contact::getByName('contact 05 contact 05son');
     $this->assertNotEmpty($contact);
     $contact = $contact[0];
     $this->assertEquals(1, $contact->primaryEmail->optOut);
     $personId = $contact->getClassId('Person');
     $member = MarketingListMember::getByMarketingListIdContactIdAndUnsubscribed($marketingList->id, $contact->id, 1);
     $this->assertNotEmpty($member);
     Yii::app()->user->userModel = null;
     $hash = GlobalMarketingFooterUtil::resolveHash($personId, $marketingListId, 1, 'AutoresponderItem', false);
     $this->setGetArray(array('hash' => $hash));
     @$this->runControllerWithRedirectExceptionAndGetUrl($this->subscribeUrl);
     $content = $this->runControllerWithNoExceptionsAndGetContent($this->manageSubscriptionsUrl);
     $this->assertContains('<td>marketingList 01</td>', $content);
     $this->assertContains('<td>marketingList 03</td>', $content);
     $this->assertContains('marketingLists/external/subscribe?hash=', $content);
     $this->assertContains('id="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_', $content);
     $this->assertContains('id="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_', $content);
     $this->assertContains('type="radio" name="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_', $content);
     $this->assertContains('id="marketingListsManageSubscriptionListView-toggleUnsubscribed_' . $marketingListId . '_0" checked="checked" type="radio" name="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_' . $marketingListId, $content);
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $contact = Contact::getByName('contact 05 contact 05son');
     $this->assertNotEmpty($contact);
     $contact = $contact[0];
     $this->assertEquals(0, $contact->primaryEmail->optOut);
 }
 protected function renderToggleSubscriptionSwitch($marketingListId, $subscribed)
 {
     $template = ZurmoHtml::tag('div', array('class' => 'switch-state clearfix'), '{input}{label}');
     $createNewActivity = false;
     if ($marketingListId == $this->sourceMarketingListId) {
         $createNewActivity = true;
     }
     $hash = GlobalMarketingFooterUtil::resolveHash($this->personId, $marketingListId, $this->modelId, $this->modelType, $createNewActivity);
     $subscribeUrl = $this->getSubscribeUrlByHash($hash);
     $unsubscribeUrl = $this->getUnsubscribeUrlByHash($hash);
     $checkedValue = $subscribeUrl;
     if (!$subscribed) {
         $checkedValue = $unsubscribeUrl;
     }
     $baseId = static::TOGGLE_UNSUBSCRIPTION_LINK_CLASS . '_' . $marketingListId;
     $content = ZurmoHTML::radioButtonList($baseId, $checkedValue, self::getDropDownArray($subscribeUrl, $unsubscribeUrl), array('separator' => '', 'template' => $template));
     return ZurmoHtml::tag('div', array('class' => 'switch'), $content);
 }
 /**
  * @depends testProcessDueCampaignItemWithManageSubscriptionsUrlMergeTag
  */
 public function testProcessDueCampaignItemWithUnsubscribeAndManageSubscriptionsUrlMergeTags()
 {
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     $contact = ContactTestHelper::createContactByNameForOwner('contact 17', $this->user);
     $contact->primaryEmail = $email;
     $this->assertTrue($contact->save());
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 17', 'description', null, null);
     MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
     $campaign = CampaignTestHelper::createCampaign('campaign 15', 'subject 15', GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag() . ', ' . GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag(), GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag() . ', ' . GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag(), 'testFromName', '*****@*****.**', null, null, null, null, $marketingList);
     $processed = 0;
     $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
     $this->processDueItem($campaignItem);
     $textContent = $campaignItem->emailMessage->content->textContent;
     $htmlContent = $campaignItem->emailMessage->content->htmlContent;
     $this->assertNotEquals($campaign->textContent, $textContent);
     $this->assertNotEquals($campaign->htmlContent, $htmlContent);
     $this->assertContains('localhost', $textContent);
     $this->assertEquals(1, substr_count($textContent, '/marketingLists/external/unsubscribe?hash='));
     $this->assertContains('localhost', $htmlContent);
     $this->assertEquals(1, substr_count($htmlContent, '/marketingLists/external/unsubscribe?hash='));
     $this->assertContains('<img width="1" height="1" src="localhost', $htmlContent);
     $this->assertContains('/tracking/default/track?id=', $htmlContent);
     $this->assertContains(', localhost', $textContent);
     $this->assertEquals(1, substr_count($textContent, '/marketingLists/external/manageSubscriptions?hash='));
     $this->assertContains(', localhost', $htmlContent);
     $this->assertEquals(1, substr_count($htmlContent, '/marketingLists/external/manageSubscriptions?hash='));
     $this->assertContains('<img width="1" height="1" src="localhost', $htmlContent);
     $this->assertContains('/tracking/default/track?id=', $htmlContent);
 }
 protected static function resolveMergeTagsParams($marketingListId, $modelId, $modelType, $isHtmlContent = false)
 {
     $params = GlobalMarketingFooterUtil::resolveFooterMergeTagsArray(static::$personId, $marketingListId, $modelId, $modelType, true, false, $isHtmlContent);
     return $params;
 }
 protected function resolveMergeTagParams()
 {
     // TODO: @Shoaibi: Critical0: We have to send in dummy data to allow resolution of unsubscribe
     // and manage subscriptions merge tags.
     return GlobalMarketingFooterUtil::resolveFooterMergeTagsArray(1, 2, 3, 'AutoresponderItem', false, true);
 }
 /**
  * @depends testProcessDueAutoresponderItemWithManageSubscriptionsUrlMergeTag
  */
 public function testProcessDueAutoresponderItemWithUnsubscribeAndManageSubscriptionsUrlMergeTags()
 {
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     $contact = ContactTestHelper::createContactByNameForOwner('contact 12', $this->user);
     $contact->primaryEmail = $email;
     $this->assertTrue($contact->save());
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 12', 'description', 'CustomFromName', '*****@*****.**');
     $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 12', GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag() . ', ' . GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag(), GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag() . ', ' . GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag(), 1, Autoresponder::OPERATION_SUBSCRIBE, true, $marketingList);
     $processed = 0;
     $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $autoresponderItem = AutoresponderItemTestHelper::createAutoresponderItem($processed, $processDateTime, $autoresponder, $contact);
     $this->processDueItem($autoresponderItem);
     $this->assertEquals(1, $autoresponderItem->processed);
     $textContent = $autoresponderItem->emailMessage->content->textContent;
     $htmlContent = $autoresponderItem->emailMessage->content->htmlContent;
     $this->assertNotEquals($autoresponder->textContent, $textContent);
     $this->assertNotEquals($autoresponder->htmlContent, $htmlContent);
     $this->assertContains('localhost', $textContent);
     $this->assertEquals(1, substr_count($textContent, '/marketingLists/external/unsubscribe?hash='));
     $this->assertContains('localhost', $htmlContent);
     $this->assertEquals(1, substr_count($htmlContent, '/marketingLists/external/unsubscribe?hash='));
     $this->assertContains('<img width="1" height="1" src="localhost', $htmlContent);
     $this->assertContains('/tracking/default/track?id=', $htmlContent);
     $this->assertEquals(2, substr_count($textContent, 'localhost'));
     $this->assertEquals(1, substr_count($textContent, '/marketingLists/external/manageSubscriptions?hash='));
     $this->assertContains(', localhost', $htmlContent);
     $this->assertEquals(1, substr_count($htmlContent, '/marketingLists/external/manageSubscriptions?hash='));
     $this->assertContains('<img width="1" height="1" src="localhost', $htmlContent);
     $this->assertContains('/tracking/default/track?id=', $htmlContent);
 }
 /**
  * Given a MarketingConfigurationForm, save the marketing configuration global values.
  */
 public static function setConfigurationFromForm(MarketingConfigurationForm $form)
 {
     GlobalMarketingFooterUtil::setContentByType($form->autoresponderOrCampaignFooterPlainText, false);
     GlobalMarketingFooterUtil::setContentByType($form->autoresponderOrCampaignFooterRichText, true);
 }
 /**
  * @depends testGetByContentTypeReturnsDefaultWithNoneSet
  */
 public function testSetByContentType()
 {
     GlobalMarketingFooterUtil::setContentByType('plain', false);
     $plainTextFooter = GlobalMarketingFooterUtil::getContentByType(false);
     $this->assertNotNull($plainTextFooter);
     $this->assertEquals('plain', $plainTextFooter);
     GlobalMarketingFooterUtil::setContentByType('rich', true);
     $richTextFooter = GlobalMarketingFooterUtil::getContentByType(true);
     $this->assertNotNull($richTextFooter);
     $this->assertEquals('rich', $richTextFooter);
 }
 protected static function resolveGlobalMarketingFooterPlainText()
 {
     return GlobalMarketingFooterUtil::getContentByType(false, true);
 }
 public function testUnsubscribeActionToPublicMarketingListByGuestFromExternalController()
 {
     $personId = static::$contact->getClassId('Person');
     Yii::app()->user->userModel = null;
     $hash = GlobalMarketingFooterUtil::resolveHash($personId, static::$marketingList->id, 0, 'AutoresponderItem', false);
     $this->setGetArray(array('hash' => $hash));
     $content = $this->runControllerWithNoExceptionsAndGetContent($this->externalManageSubscriptionsUrl);
     $this->assertContains('id="marketingListsManageSubscriptionListView-toggleUnsubscribed_' . static::$marketingList->id . '_0" checked="checked" type="radio" name="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_' . static::$marketingList->id, $content);
     $this->assertContains('id="marketingListsManageSubscriptionListView-toggleUnsubscribed_' . static::$marketingList->id . '_1" type="radio" name="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_' . static::$marketingList->id, $content);
     @$this->runControllerWithRedirectExceptionAndGetUrl($this->externalUnsubscribeUrl);
     $content = $this->runControllerWithNoExceptionsAndGetContent($this->externalManageSubscriptionsUrl);
     $this->assertNotEmpty($content);
     $this->assertContains('id="marketingListsManageSubscriptionListView-toggleUnsubscribed_' . static::$marketingList->id . '_0" type="radio" name="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_' . static::$marketingList->id, $content);
     $this->assertContains('id="marketingListsManageSubscriptionListView-toggleUnsubscribed_' . static::$marketingList->id . '_1" checked="checked" type="radio" name="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_' . static::$marketingList->id, $content);
     $this->assertEquals(1, MarketingListMember::getCount());
 }
 /**
  * [[MODEL^URL]] : prints absolute url to the current model attached to template.
  * [[BASE^URL]] : prints absolute url to the current install without trailing slash.
  * [[APPLICATION^NAME]] : prints application name as set in global settings > application name.
  * [[CURRENT^YEAR]] : prints current year.
  * [[LAST^YEAR]] : prints last year.
  * [[OWNERS^AVATAR^SMALL]] : prints the owner's small avatar image (32x32).
  * [[OWNERS^AVATAR^MEDIUM ]] : prints the owner's medium avatar image (32x32).
  * [[OWNERS^AVATAR^LARGE]] : prints the owner's large avatar image (32x32).
  * [[OWNERS^EMAIL^SIGNATURE]] : prints the owner's email signature.
  * [[UNSUBSCRIBE^URL]] : prints unsubscribe url.
  * [[MANAGE^SUBSCRIPTIONS^URL]] : prints manage subscriptions url.
  * @return array
  */
 protected function getSpecialTagsData()
 {
     return array(array('id' => 'modelUrl', 'label' => Zurmo::t('EmailTemplatesModule', 'Model URL'), 'dataValue' => MergeTagsUtil::TAG_PREFIX . 'MODEL' . MergeTagsUtil::CAPITAL_DELIMITER . 'URL' . MergeTagsUtil::TAG_SUFFIX), array('id' => 'baseUrl', 'label' => Zurmo::t('EmailTemplatesModule', 'Base URL'), 'dataValue' => MergeTagsUtil::TAG_PREFIX . 'BASE' . MergeTagsUtil::CAPITAL_DELIMITER . 'URL' . MergeTagsUtil::TAG_SUFFIX), array('id' => 'applicationName', 'label' => Zurmo::t('ZurmoModule', 'Application Name'), 'dataValue' => MergeTagsUtil::TAG_PREFIX . 'APPLICATION' . MergeTagsUtil::CAPITAL_DELIMITER . 'NAME' . MergeTagsUtil::TAG_SUFFIX), array('id' => 'currentYear', 'label' => Zurmo::t('EmailTemplatesModule', 'Current Year'), 'dataValue' => MergeTagsUtil::TAG_PREFIX . 'CURRENT' . MergeTagsUtil::CAPITAL_DELIMITER . 'YEAR' . MergeTagsUtil::TAG_SUFFIX), array('id' => 'lastYear', 'label' => Zurmo::t('EmailTemplatesModule', 'Last Year'), 'dataValue' => MergeTagsUtil::TAG_PREFIX . 'LAST' . MergeTagsUtil::CAPITAL_DELIMITER . 'YEAR' . MergeTagsUtil::TAG_SUFFIX), array('id' => 'ownersAvatarSmall', 'label' => Zurmo::t('EmailTemplatesModule', 'Owner\'s Avatar Small'), 'dataValue' => MergeTagsUtil::TAG_PREFIX . 'OWNERS' . MergeTagsUtil::CAPITAL_DELIMITER . 'AVATAR' . MergeTagsUtil::CAPITAL_DELIMITER . 'SMALL' . MergeTagsUtil::TAG_SUFFIX), array('id' => 'ownersAvatarMedium', 'label' => Zurmo::t('EmailTemplatesModule', 'Owner\'s Avatar Medium'), 'dataValue' => MergeTagsUtil::TAG_PREFIX . 'OWNERS' . MergeTagsUtil::CAPITAL_DELIMITER . 'AVATAR' . MergeTagsUtil::CAPITAL_DELIMITER . 'MEDIUM' . MergeTagsUtil::TAG_SUFFIX), array('id' => 'ownersAvatarLarge', 'label' => Zurmo::t('EmailTemplatesModule', 'Owner\'s Avatar Large'), 'dataValue' => MergeTagsUtil::TAG_PREFIX . 'OWNERS' . MergeTagsUtil::CAPITAL_DELIMITER . 'AVATAR' . MergeTagsUtil::CAPITAL_DELIMITER . 'LARGE' . MergeTagsUtil::TAG_SUFFIX), array('id' => 'ownersEmailSignature', 'label' => Zurmo::t('EmailTemplatesModule', 'Owner\'s Email Signature'), 'dataValue' => MergeTagsUtil::TAG_PREFIX . 'OWNERS' . MergeTagsUtil::CAPITAL_DELIMITER . 'EMAIL' . MergeTagsUtil::CAPITAL_DELIMITER . 'SIGNATURE' . MergeTagsUtil::TAG_SUFFIX), array('id' => 'unsubscribeUrl', 'label' => Zurmo::t('EmailTemplatesModule', 'Unsubscribe URL'), 'dataValue' => GlobalMarketingFooterUtil::resolveUnsubscribeUrlMergeTag()), array('id' => 'manageSubscriptionsUrl', 'label' => Zurmo::t('EmailTemplatesModule', 'Manage Subscriptions URL'), 'dataValue' => GlobalMarketingFooterUtil::resolveManageSubscriptionsMergeTag()));
 }
 /**
  * Given a MarketingConfigurationForm, save the marketing configuration global values.
  */
 public static function setConfigurationFromForm(MarketingConfigurationForm $form)
 {
     GlobalMarketingFooterUtil::setContentByType($form->autoresponderOrCampaignFooterPlainText, false);
     GlobalMarketingFooterUtil::setContentByType($form->autoresponderOrCampaignFooterRichText, true);
     ZurmoConfigurationUtil::setByModuleName('MarketingModule', 'UseAutoresponderOrCampaignOwnerMailSettings', $form->useAutoresponderOrCampaignOwnerMailSettings);
 }