Example #1
0
 /**
  * @param Email $email
  * @param bool  $allowBcc            Honor BCC if set in email
  * @param array $slots               Slots configured in theme
  * @param array $assetAttachments    Assets to send
  * @param bool  $ignoreTrackingPixel Do not append tracking pixel HTML
  */
 public function setEmail(Email $email, $allowBcc = true, $slots = array(), $assetAttachments = array(), $ignoreTrackingPixel = false)
 {
     $this->email = $email;
     $subject = $email->getSubject();
     // Convert short codes to emoji
     $subject = EmojiHelper::toEmoji($subject, 'short');
     // Set message settings from the email
     $this->setSubject($subject);
     $fromEmail = $email->getFromAddress();
     $fromName = $email->getFromName();
     if (!empty($fromEmail) && !empty($fromEmail)) {
         $this->setFrom($fromEmail, $fromName);
     } else {
         if (!empty($fromEmail)) {
             $this->setFrom($fromEmail, $this->from);
         } else {
             if (!empty($fromName)) {
                 $this->setFrom(key($this->from), $fromName);
             }
         }
     }
     $replyTo = $email->getReplyToAddress();
     if (!empty($replyTo)) {
         $this->setReplyTo($replyTo);
     }
     if ($allowBcc) {
         $bccAddress = $email->getBccAddress();
         if (!empty($bccAddress)) {
             $this->addBcc($bccAddress);
         }
     }
     if ($plainText = $email->getPlainText()) {
         $this->setPlainText($plainText);
     }
     $template = $email->getTemplate();
     if (!empty($template)) {
         if (empty($slots)) {
             $template = $email->getTemplate();
             $slots = $this->factory->getTheme($template)->getSlots('email');
         }
         if (isset($slots[$template])) {
             $slots = $slots[$template];
         }
         $customHtml = $this->setTemplate('MauticEmailBundle::public.html.php', array('slots' => $slots, 'content' => $email->getContent(), 'email' => $email, 'template' => $template), true);
     } else {
         // Tak on the tracking pixel token
         $customHtml = $email->getCustomHtml();
     }
     // Convert short codes to emoji
     $customHtml = EmojiHelper::toEmoji($customHtml, 'short');
     $this->setBody($customHtml, 'text/html', null, $ignoreTrackingPixel);
     // Reset attachments
     $this->assets = $this->attachedAssets = array();
     if (empty($assetAttachments)) {
         if ($assets = $email->getAssetAttachments()) {
             foreach ($assets as $asset) {
                 $this->attachAsset($asset);
             }
         }
     } else {
         foreach ($assetAttachments as $asset) {
             $this->attachAsset($asset);
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getPlainText()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getPlainText', array());
     return parent::getPlainText();
 }
Example #3
0
 /**
  * {@inheritdoc}
  *
  * @param Email $entity
  * @param       $unlock
  *
  * @return mixed
  */
 public function saveEntity($entity, $unlock = true)
 {
     $now = new DateTimeHelper();
     $type = $entity->getEmailType();
     if (empty($type)) {
         // Just in case JS failed
         $entity->setEmailType('template');
     }
     // Ensure that list emails are published
     if ($entity->getEmailType() == 'list') {
         $entity->setIsPublished(true);
         $entity->setPublishDown(null);
         $entity->setPublishUp(null);
     }
     //set the author for new pages
     if (!$entity->isNew()) {
         //increase the revision
         $revision = $entity->getRevision();
         $revision++;
         $entity->setRevision($revision);
     }
     // Ensure links in template content don't have encoded ampersands
     if ($entity->getTemplate()) {
         $content = $entity->getContent();
         foreach ($content as $key => $value) {
             $content[$key] = $this->cleanUrlsInContent($value);
         }
         $entity->setContent($content);
     } else {
         // Ensure links in HTML don't have encoded ampersands
         $htmlContent = $this->cleanUrlsInContent($entity->getCustomHtml());
         $entity->setCustomHtml($htmlContent);
     }
     // Ensure links in PLAIN TEXT don't have encoded ampersands
     $plainContent = $this->cleanUrlsInContent($entity->getPlainText());
     $entity->setPlainText($plainContent);
     // Reset the variant hit and start date if there are any changes and if this is an A/B test
     // Do it here in addition to the blanket resetVariants call so that it's available to the event listeners
     $changes = $entity->getChanges();
     $parent = $entity->getVariantParent();
     if ($parent !== null && !empty($changes) && empty($this->inConversion)) {
         $entity->setVariantSentCount(0);
         $entity->setVariantReadCount(0);
         $entity->setVariantStartDate($now->getDateTime());
     }
     parent::saveEntity($entity, $unlock);
     // If parent, add this entity as a child of the parent so that it populates the list in the tab (due to Doctrine hanging on to entities in memory)
     if ($parent) {
         $parent->addVariantChild($entity);
     }
     // Reset associated variants if applicable due to changes
     if ($entity->isVariant() && !empty($changes) && empty($this->inConversion)) {
         $dateString = $now->toUtcString();
         $parentId = !empty($parent) ? $parent->getId() : $entity->getId();
         $this->getRepository()->resetVariants($parentId, $dateString);
         //if the parent was changed, then that parent/children must also be reset
         if (isset($changes['variantParent'])) {
             $this->getRepository()->resetVariants($changes['variantParent'][0], $dateString);
         }
     }
 }
Example #4
0
 /**
  * @param Email $email
  * @param bool  $allowBcc            Honor BCC if set in email
  * @param array $slots               Slots configured in theme
  * @param array $assetAttachments    Assets to send
  * @param bool  $ignoreTrackingPixel Do not append tracking pixel HTML
  */
 public function setEmail(Email $email, $allowBcc = true, $slots = [], $assetAttachments = [], $ignoreTrackingPixel = false)
 {
     $this->email = $email;
     $subject = $email->getSubject();
     // Convert short codes to emoji
     $subject = EmojiHelper::toEmoji($subject, 'short');
     // Set message settings from the email
     $this->setSubject($subject);
     $fromEmail = $email->getFromAddress();
     $fromName = $email->getFromName();
     if (!empty($fromEmail) && !empty($fromEmail)) {
         $this->setFrom($fromEmail, $fromName);
     } elseif (!empty($fromEmail)) {
         $this->setFrom($fromEmail, $this->from);
     } elseif (!empty($fromName)) {
         $this->setFrom(key($this->from), $fromName);
     }
     $replyTo = $email->getReplyToAddress();
     if (!empty($replyTo)) {
         $this->setReplyTo($replyTo);
     }
     if ($allowBcc) {
         $bccAddress = $email->getBccAddress();
         if (!empty($bccAddress)) {
             $this->addBcc($bccAddress);
         }
     }
     if ($plainText = $email->getPlainText()) {
         $this->setPlainText($plainText);
     }
     $BCcontent = $email->getContent();
     $customHtml = $email->getCustomHtml();
     // Process emails created by Mautic v1
     if (empty($customHtml) && !empty($BCcontent)) {
         $template = $email->getTemplate();
         if (empty($slots)) {
             $template = $email->getTemplate();
             $slots = $this->factory->getTheme($template)->getSlots('email');
         }
         if (isset($slots[$template])) {
             $slots = $slots[$template];
         }
         $this->processSlots($slots, $email);
         $logicalName = $this->factory->getHelper('theme')->checkForTwigTemplate(':' . $template . ':email.html.php');
         $customHtml = $this->setTemplate($logicalName, ['slots' => $slots, 'content' => $email->getContent(), 'email' => $email, 'template' => $template], true);
     }
     // Convert short codes to emoji
     $customHtml = EmojiHelper::toEmoji($customHtml, 'short');
     $this->setBody($customHtml, 'text/html', null, $ignoreTrackingPixel);
     // Reset attachments
     $this->assets = $this->attachedAssets = [];
     if (empty($assetAttachments)) {
         if ($assets = $email->getAssetAttachments()) {
             foreach ($assets as $asset) {
                 $this->attachAsset($asset);
             }
         }
     } else {
         foreach ($assetAttachments as $asset) {
             $this->attachAsset($asset);
         }
     }
 }