/**
  * Convert HTML emoji to unicode bytes
  *
  * @param array|string $content
  *
  * @return array|string
  */
 public function reverseTransform($content)
 {
     if (is_array($content)) {
         foreach ($content as &$convert) {
             $convert = $this->reverseTransform($convert);
         }
     } else {
         $content = EmojiHelper::toEmoji($content);
     }
     return $content;
 }
Example #2
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);
         }
     }
 }
 /**
  * Activate the builder
  *
  * @param $objectId
  *
  * @return array|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response
  * @throws \Exception
  * @throws \Mautic\CoreBundle\Exception\FileNotFoundException
  */
 public function builderAction($objectId)
 {
     /** @var \Mautic\EmailBundle\Model\EmailModel $model */
     $model = $this->factory->getModel('email');
     //permission check
     if (strpos($objectId, 'new') !== false) {
         $isNew = true;
         if (!$this->factory->getSecurity()->isGranted('email:emails:create')) {
             return $this->accessDenied();
         }
         $entity = $model->getEntity();
         $entity->setSessionId($objectId);
     } else {
         $isNew = false;
         $entity = $model->getEntity($objectId);
         if ($entity == null || !$this->factory->getSecurity()->hasEntityAccess('email:emails:viewown', 'email:emails:viewother', $entity->getCreatedBy())) {
             return $this->accessDenied();
         }
     }
     $template = InputHelper::clean($this->request->query->get('template'));
     $slots = $this->factory->getTheme($template)->getSlots('email');
     //merge any existing changes
     $newContent = $this->factory->getSession()->get('mautic.emailbuilder.' . $objectId . '.content', array());
     $content = $entity->getContent();
     $tokens = $model->getBuilderComponents($entity, array('tokens', 'visualTokens'));
     BuilderTokenHelper::replaceTokensWithVisualPlaceholders($tokens, $content);
     if (is_array($newContent)) {
         $content = array_merge($content, $newContent);
     }
     // Replace short codes to emoji
     $content = EmojiHelper::toEmoji($content, 'short');
     return $this->render('MauticEmailBundle::builder.html.php', array('isNew' => $isNew, 'slots' => $slots, 'content' => $content, 'email' => $entity, 'template' => $template, 'basePath' => $this->request->getBasePath()));
 }
Example #4
0
 /**
  * Preview email
  *
  * @param $objectId
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function previewAction($objectId)
 {
     /** @var \Mautic\EmailBundle\Model\EmailModel $model */
     $model = $this->factory->getModel('email');
     $emailEntity = $model->getEntity($objectId);
     if ($this->factory->getSecurity()->isAnonymous() && !$emailEntity->isPublished() || !$this->factory->getSecurity()->isAnonymous() && !$this->factory->getSecurity()->hasEntityAccess('email:emails:viewown', 'email:emails:viewother', $emailEntity->getCreatedBy())) {
         return $this->accessDenied();
     }
     //bogus ID
     $idHash = 'xxxxxxxxxxxxxx';
     $template = $emailEntity->getTemplate();
     if (!empty($template)) {
         $slots = $this->factory->getTheme($template)->getSlots('email');
         $response = $this->render('MauticEmailBundle::public.html.php', array('inBrowser' => true, 'slots' => $slots, 'content' => $emailEntity->getContent(), 'email' => $emailEntity, 'lead' => null, 'template' => $template));
         //replace tokens
         $content = $response->getContent();
     } else {
         $content = $emailEntity->getCustomHtml();
     }
     // Convert emojis
     $content = EmojiHelper::toEmoji($content, 'short');
     // Override tracking_pixel
     $tokens = array('{tracking_pixel}' => '');
     // Prepare a fake lead
     /** @var \Mautic\LeadBundle\Model\FieldModel $fieldModel */
     $fieldModel = $this->factory->getModel('lead.field');
     $fields = $fieldModel->getFieldList(false, false);
     array_walk($fields, function (&$field) {
         $field = "[{$field}]";
     });
     $fields['id'] = 0;
     // Generate and replace tokens
     $event = new EmailSendEvent(null, array('content' => $content, 'email' => $emailEntity, 'idHash' => $idHash, 'tokens' => $tokens, 'internalSend' => true, 'lead' => $fields));
     $this->factory->getDispatcher()->dispatch(EmailEvents::EMAIL_ON_DISPLAY, $event);
     $content = $event->getContent(true);
     return new Response($content);
 }
Example #5
0
 /**
  * Activate the builder.
  *
  * @param $objectId
  *
  * @return array|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response
  *
  * @throws \Exception
  * @throws \Mautic\CoreBundle\Exception\FileNotFoundException
  */
 public function builderAction($objectId)
 {
     /** @var \Mautic\EmailBundle\Model\EmailModel $model */
     $model = $this->getModel('email');
     //permission check
     if (strpos($objectId, 'new') !== false) {
         $isNew = true;
         if (!$this->get('mautic.security')->isGranted('email:emails:create')) {
             return $this->accessDenied();
         }
         $entity = $model->getEntity();
         $entity->setSessionId($objectId);
     } else {
         $isNew = false;
         $entity = $model->getEntity($objectId);
         if ($entity == null || !$this->get('mautic.security')->hasEntityAccess('email:emails:viewown', 'email:emails:viewother', $entity->getCreatedBy())) {
             return $this->accessDenied();
         }
     }
     $template = InputHelper::clean($this->request->query->get('template'));
     $slots = $this->factory->getTheme($template)->getSlots('email');
     //merge any existing changes
     $newContent = $this->get('session')->get('mautic.emailbuilder.' . $objectId . '.content', []);
     $content = $entity->getContent();
     if (is_array($newContent)) {
         $content = array_merge($content, $newContent);
         // Update the content for processSlots
         $entity->setContent($content);
     }
     // Replace short codes to emoji
     $content = EmojiHelper::toEmoji($content, 'short');
     $this->processSlots($slots, $entity);
     $logicalName = $this->factory->getHelper('theme')->checkForTwigTemplate(':' . $template . ':email.html.php');
     return $this->render($logicalName, ['isNew' => $isNew, 'slots' => $slots, 'content' => $content, 'email' => $entity, 'template' => $template, 'basePath' => $this->request->getBasePath()]);
 }
Example #6
0
 /**
  * Preview email.
  *
  * @param $objectId
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function previewAction($objectId)
 {
     /** @var \Mautic\EmailBundle\Model\EmailModel $model */
     $model = $this->getModel('email');
     $emailEntity = $model->getEntity($objectId);
     if ($emailEntity === null) {
         return $this->notFound();
     }
     if ($this->get('mautic.security')->isAnonymous() && !$emailEntity->isPublished() || !$this->get('mautic.security')->isAnonymous() && !$this->get('mautic.security')->hasEntityAccess('email:emails:viewown', 'email:emails:viewother', $emailEntity->getCreatedBy())) {
         return $this->accessDenied();
     }
     //bogus ID
     $idHash = 'xxxxxxxxxxxxxx';
     $BCcontent = $emailEntity->getContent();
     $content = $emailEntity->getCustomHtml();
     if (empty($content) && !empty($BCcontent)) {
         $template = $emailEntity->getTemplate();
         $slots = $this->factory->getTheme($template)->getSlots('email');
         $assetsHelper = $this->factory->getHelper('template.assets');
         $assetsHelper->addCustomDeclaration('<meta name="robots" content="noindex">');
         $this->processSlots($slots, $emailEntity);
         $logicalName = $this->factory->getHelper('theme')->checkForTwigTemplate(':' . $template . ':email.html.php');
         $response = $this->render($logicalName, ['inBrowser' => true, 'slots' => $slots, 'content' => $emailEntity->getContent(), 'email' => $emailEntity, 'lead' => null, 'template' => $template]);
         //replace tokens
         $content = $response->getContent();
     }
     // Convert emojis
     $content = EmojiHelper::toEmoji($content, 'short');
     // Override tracking_pixel
     $tokens = ['{tracking_pixel}' => ''];
     // Prepare a fake lead
     /** @var \Mautic\LeadBundle\Model\FieldModel $fieldModel */
     $fieldModel = $this->getModel('lead.field');
     $fields = $fieldModel->getFieldList(false, false);
     array_walk($fields, function (&$field) {
         $field = "[{$field}]";
     });
     $fields['id'] = 0;
     // Generate and replace tokens
     $event = new EmailSendEvent(null, ['content' => $content, 'email' => $emailEntity, 'idHash' => $idHash, 'tokens' => $tokens, 'internalSend' => true, 'lead' => $fields]);
     $this->dispatcher->dispatch(EmailEvents::EMAIL_ON_DISPLAY, $event);
     $content = $event->getContent(true);
     return new Response($content);
 }
Example #7
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);
         }
     }
 }