示例#1
0
 public function onEmailGenerate(EmailSendEvent $event)
 {
     $content = $event->getContent();
     $regex = '/' . $this->leadFieldRegex . '/';
     $lead = $event->getLead();
     preg_match_all($regex, $content, $matches);
     if (!empty($matches[1])) {
         $tokenList = array();
         foreach ($matches[1] as $key => $match) {
             $token = $matches[0][$key];
             if (isset($tokenList[$token])) {
                 continue;
             }
             $fallbackCheck = explode('|', $match);
             $fallback = $urlencode = false;
             if (isset($fallbackCheck[1])) {
                 // There is a fallback or to be urlencoded
                 $alias = $fallbackCheck[0];
                 if ($fallbackCheck[1] === 'true') {
                     $urlencode = true;
                     $fallback = '';
                 } else {
                     $fallback = $fallbackCheck[1];
                 }
             } else {
                 $alias = $match;
             }
             $value = !empty($lead[$alias]) ? $lead[$alias] : $fallback;
             $tokenList[$token] = $urlencode ? urlencode($value) : $value;
         }
         $event->addTokens($tokenList);
         unset($tokenList);
     }
 }
 /**
  * @param EmailSendEvent $event
  */
 public function onEmailGenerate(EmailSendEvent $event)
 {
     $lead = $event->getLead();
     $leadId = $lead !== null ? $lead['id'] : null;
     $email = $event->getEmail();
     $tokens = $this->generateTokensFromContent($event, $leadId, $event->getSource(), $email === null ? null : $email->getId());
     $event->addTokens($tokens);
 }
示例#3
0
 /**
  * Trigger point actions for email send
  *
  * @param EmailSendEvent $event
  */
 public function onEmailSend(EmailSendEvent $event)
 {
     if ($leadArray = $event->getLead()) {
         $lead = $this->factory->getEntityManager()->getReference('MauticLeadBundle:Lead', $leadArray['id']);
     } else {
         return;
     }
     $this->factory->getModel('point')->triggerAction('email.send', $event->getEmail(), null, $lead);
 }
 /**
  * Search and replace tokens with content
  *
  * @param EmailSendEvent $event
  */
 public function onEmailGenerate(EmailSendEvent $event)
 {
     // Get content
     $content = $event->getContent();
     // Search and replace tokens
     $content = str_replace('{extendedplugin}', 'world!', $content);
     // Set updated content
     $event->setContent($content);
 }
示例#5
0
 /**
  * @param EmailSendEvent $event
  */
 public function onEmailGenerate(EmailSendEvent $event)
 {
     $content = $event->getContent();
     $lead = $event->getLead();
     $tokenList = self::findLeadTokens($content, $lead);
     if (count($tokenList)) {
         $event->addTokens($tokenList);
         unset($tokenList);
     }
 }
 /**
  * Add an unsubscribe email to the List-Unsubscribe header if applicable
  *
  * @param Events\EmailSendEvent $event
  */
 public function onEmailSend(Events\EmailSendEvent $event)
 {
     if ($unsubscribeEmail = $event->getHelper()->generateUnsubscribeEmail()) {
         $headers = $event->getTextHeaders();
         $existing = isset($headers['List-Unsubscribe']) ? $headers['List-Unsubscribe'] : '';
         $unsubscribeEmail = "<mailto:{$unsubscribeEmail}>";
         $updatedHeader = $existing ? $unsubscribeEmail . ", " . $existing : $unsubscribeEmail;
         $event->addTextHeader('List-Unsubscribe', $updatedHeader);
     }
 }
示例#7
0
 /**
  * @param EmailSendEvent $event
  *
  * @return void
  */
 public function decodeTokens(EmailSendEvent $event)
 {
     // Find and replace encoded tokens for trackable URL conversion
     $content = $event->getContent();
     $content = preg_replace('/(%7B)(.*?)(%7D)/i', '{$2}', $content);
     $event->setContent($content);
     if ($plainText = $event->getPlainText()) {
         $plainText = preg_replace('/(%7B)(.*?)(%7D)/i', '{$2}', $plainText);
         $event->setPlainText($plainText);
     }
 }
 /**
  * @param EmailSendEvent $event
  */
 public function onEmailGenerate(EmailSendEvent $event)
 {
     $oLVExtra = $this->getExtra();
     $sCodiceHTML = '';
     $sCodiceHTML .= '<b>Latest Stable Kernel</b><br />';
     $sCodiceHTML .= '' . $oLVExtra->ver . '';
     $sCodiceTesto = '';
     $sCodiceTesto .= 'Latest Stable Kernel' . "\n";
     $sCodiceTesto .= '' . $oLVExtra->ver . '' . "\n";
     $content = $event->getContent();
     $content = str_replace('{linuxver_lastver}', $sCodiceHTML, $content);
     $event->setContent($content);
     $contentText = $event->getPlainText();
     $contentText = str_replace('{linuxver_lastver}', $sCodiceTesto, $contentText);
     $event->setPlainText($contentText);
     //$event->addToken('{linuxver_lastver}', $sCodice);
 }
示例#9
0
 /**
  * @param EmailSendEvent $event
  */
 public function decodeTokens(EmailSendEvent $event)
 {
     // Find and replace encoded tokens for trackable URL conversion
     $content = $event->getContent();
     $content = preg_replace('/(%7B)(.*?)(%7D)/i', '{$2}', $content, -1, $count);
     $event->setContent($content);
     if ($plainText = $event->getPlainText()) {
         $plainText = preg_replace('/(%7B)(.*?)(%7D)/i', '{$2}', $plainText);
         $event->setPlainText($plainText);
     }
     $lead = $event->getLead();
     $email = $event->getEmail();
     $dynamicContentAsArray = $email instanceof Email ? $email->getDynamicContent() : null;
     if (!empty($dynamicContentAsArray)) {
         $tokenEvent = new TokenReplacementEvent(null, $lead, ['lead' => null, 'dynamicContent' => $dynamicContentAsArray]);
         $this->dispatcher->dispatch(EmailEvents::TOKEN_REPLACEMENT, $tokenEvent);
         $event->addTokens($tokenEvent->getTokens());
     }
 }
示例#10
0
 public function onEmailGenerate(EmailSendEvent $event)
 {
     $idHash = $event->getIdHash();
     if ($idHash == null) {
         // Generate a bogus idHash to prevent errors for routes that may include it
         $idHash = uniqid();
     }
     $model = $this->factory->getModel('email');
     $event->addToken('{unsubscribe_text}', $this->translator->trans('mautic.email.unsubscribe.text', array('%link%' => $model->buildUrl('mautic_email_unsubscribe', array('idHash' => $idHash)))));
     $event->addToken('{unsubscribe_url}', $model->buildUrl('mautic_email_unsubscribe', array('idHash' => $idHash)));
     $event->addToken('{webview_text}', $this->translator->trans('mautic.email.webview.text', array('%link%' => $model->buildUrl('mautic_email_webview', array('idHash' => $idHash)))));
     $event->addToken('{webview_url}', $model->buildUrl('mautic_email_webview', array('idHash' => $idHash)));
 }
示例#11
0
 /**
  * @param EmailSendEvent $event
  */
 public function onEmailGenerate(EmailSendEvent $event)
 {
     // Combine all possible content to find tokens across them
     $content = $event->getSubject();
     $content .= $event->getContent();
     $content .= $event->getPlainText();
     $lead = $event->getLead();
     $tokenList = TokenHelper::findLeadTokens($content, $lead);
     if (count($tokenList)) {
         $event->addTokens($tokenList);
         unset($tokenList);
     }
 }
示例#12
0
 /**
  * Converts links to trackable links and tokens
  *
  * @param EmailSendEvent $event
  * @param                $persistEntities
  * @param                $trackedLinks
  * @param                $tokens
  * @param                $email
  */
 protected function convertTrackableLinks(EmailSendEvent $event, &$persistEntities, &$trackedLinks, $tokens, Email $email = null)
 {
     /** @var \Mautic\PageBundle\Model\RedirectModel $redirectModel */
     $redirectModel = $this->factory->getModel('page.redirect');
     // Parse the content for links
     $body = $event->getContent();
     // Find links using DOM to only find <a> tags
     $libxmlPreviousState = libxml_use_internal_errors(true);
     libxml_use_internal_errors(true);
     $dom = new \DOMDocument();
     $dom->loadHTML('<?xml encoding="UTF-8">' . $body);
     libxml_clear_errors();
     libxml_use_internal_errors($libxmlPreviousState);
     $links = $dom->getElementsByTagName('a');
     $foundLinks = array();
     foreach ($links as $link) {
         $url = $link->getAttribute('href');
         // The editor will have converted & to &amp; but DOMDocument will have converted them back so this must be accounted for
         $url = str_replace('&', '&amp;', $url);
         // Ensure a valid URL
         if (substr($url, 0, 4) !== 'http' && substr($url, 0, 3) !== 'ftp' || in_array($url, $foundLinks) || in_array($url, $trackedLinks)) {
             continue;
         }
         if (stripos($url, 'http://{') !== false || strpos($url, 'https://{') !== false) {
             // The editor appended an URL token with http
             continue;
         }
         // deprecated support for externallink @todo remove with 2.0
         if (isset($trackedLinks['{externallink=' . $url . '}'])) {
             // Skip it and assume that the links are already converted via the token
             continue;
         }
         $foundLinks[$url] = $url;
     }
     // Process plain text as well
     $plainText = $event->getPlainText();
     if (!empty($plainText)) {
         // Plaintext links
         preg_match_all('@(?<![.*">])\\b(?:(?:https?|ftp|file)://|[a-z]\\.)[-A-Z0-9+&#/%=~_|$?!:,.]*[A-Z0-9+&#/%=~_|$]@i', $plainText, $matches);
         if (!empty($matches[0])) {
             foreach ($matches[0] as $url) {
                 // Remove anything left on at the end; just in case
                 $url = preg_replace('/^\\PL+|\\PL\\z/', '', trim($url));
                 // Ensure a valid URL
                 if (substr($url, 0, 4) !== 'http' && substr($url, 0, 3) !== 'ftp' && !in_array($url, $foundLinks) && !in_array($url, $trackedLinks)) {
                     continue;
                 }
                 if (stripos($url, 'http://{') !== false || strpos($url, 'https://{') !== false) {
                     // The editor appended an URL token with http
                     continue;
                 }
                 // deprecated support for externallink @todo remove with 2.0
                 if (isset($trackedLinks['{externallink=' . $url . '}'])) {
                     // Skip it and assume that the links are already converted via the token
                     continue;
                 }
                 $foundLinks[$url] = $url;
             }
         }
     }
     if (!empty($foundLinks)) {
         $links = $redirectModel->getRedirectListByUrls($foundLinks, $email);
         foreach ($links as $url => $link) {
             if (!$link->getId() && !isset($persistEntities[$url])) {
                 $persistEntities[$url] = $link;
             }
             $trackedLinks[$url] = $link;
         }
     }
     unset($foundLinks, $links);
 }
 /**
  * Search and replace tokens with content
  *
  * @param EmailSendEvent $event
  */
 public function onEmailGenerate(EmailSendEvent $event)
 {
     $active = $this->factory->getParameter('active');
     if (!$active) {
         return;
     }
     // Get content
     $content = $event->getContent();
     $email = $event->getEmail();
     if (empty($email)) {
         return;
     }
     $email_id = $email->getId();
     $content = str_replace('{extendedplugin}', 'world!', $content);
     $utm_campaign = $utm_source = $this->factory->getParameter('utm_source');
     $utm_content = '';
     $utm_medium = $this->factory->getParameter('utm_medium');
     $utm_campaign_type = $this->factory->getParameter('utm_campaign');
     $utm_content_type = $this->factory->getParameter('utm_content');
     $remove_accents = $this->factory->getParameter('remove_accents');
     switch ($utm_campaign_type) {
         case 'name':
             $utm_campaign = $email->getName();
             break;
         case 'subject':
             $utm_campaign = $email->getSubject();
             break;
         case 'category':
             if (is_null($email->getCategory())) {
                 $utm_campaign = $email->getSubject();
             } else {
                 $utm_campaign = $email->getCategory()->getTitle();
             }
             break;
     }
     switch ($utm_content_type) {
         case 'name':
             $utm_content = $email->getName();
             break;
         case 'subject':
             $utm_content = $email->getSubject();
             break;
         case 'category':
             if (is_null($email->getCategory())) {
                 $utm_content = $email->getSubject();
             } else {
                 $utm_content = $email->getCategory()->getTitle();
             }
             break;
     }
     if ($remove_accents) {
         setlocale(LC_CTYPE, 'en_US.UTF8');
         $str_campaign = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $utm_campaign);
         $str_campaign = str_replace(' ', '-', $str_campaign);
         $str_campaign = preg_replace('/\\s+/', '-', $str_campaign);
         $utm_campaign = strtolower($str_campaign);
         $str_content = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $utm_content);
         $str_content = str_replace(' ', '-', $str_content);
         $str_content = preg_replace('/\\s+/', '-', $str_content);
         $utm_content = strtolower($str_content);
     }
     $content = $this->add_analytics_tracking_to_urls($content, $utm_source, $utm_campaign, $utm_content, $utm_medium);
     $content = $this->add_analytics_tracking_to_urls2($content, $utm_source, $utm_campaign, $utm_content, $utm_medium);
     $event->setContent($content);
 }
示例#14
0
 /**
  * @param EmailSendEvent $event
  */
 public function onEmailGenerate(EmailSendEvent $event)
 {
     $content = $event->getContent();
     $plainText = $event->getPlainText();
     $clickthrough = $event->shouldAppendClickthrough() ? $event->generateClickthrough() : [];
     $this->emailIsInternalSend = $event->isInternalSend();
     $this->emailEntity = $event->getEmail();
     $tokens = $this->tokenHelper->findPageTokens($content . $plainText, $clickthrough);
     $event->addTokens($tokens);
 }
示例#15
0
 /**
  * Trigger point actions for email send
  *
  * @param EmailSendEvent $event
  */
 public function onEmailSend(EmailSendEvent $event)
 {
     $this->factory->getModel('point')->triggerAction('email.send', $event->getEmail());
 }
示例#16
0
 /**
  * Converts links to trackable links and tokens
  *
  * @param EmailSendEvent $event
  *
  * @return array
  */
 protected function convertTrackableLinks(EmailSendEvent $event)
 {
     // Get a list of tokens for the tokenized link conversion
     $currentTokens = $event->getTokens();
     /** @var \Mautic\PageBundle\Model\RedirectModel $redirectModel */
     $redirectModel = $this->factory->getModel('page.redirect');
     // Parse the content for links
     $body = $event->getContent();
     // Find links using DOM to only find <a> tags
     $libxmlPreviousState = libxml_use_internal_errors(true);
     libxml_use_internal_errors(true);
     $dom = new \DOMDocument();
     $dom->loadHTML('<?xml encoding="UTF-8">' . $body);
     libxml_clear_errors();
     libxml_use_internal_errors($libxmlPreviousState);
     $links = $dom->getElementsByTagName('a');
     $foundLinks = $tokenizedLinks = array();
     foreach ($links as $link) {
         $url = $link->getAttribute('href');
         // The editor will have converted & to &amp; but DOMDocument will have converted them back so this must be accounted for
         $url = str_replace('&', '&amp;', $url);
         $this->validateLink($url, $currentTokens, $foundLinks);
     }
     // Process plain text as well
     $plainText = $event->getPlainText();
     if (!empty($plainText)) {
         // Plaintext links
         preg_match_all('@(?<![.*">])\\b(?:(?:https?|ftp|file)://|[a-z]\\.)[-A-Z0-9+&#/%=~_|$?!:,.]*[A-Z0-9+&#/%=~_|$]@i', $plainText, $matches);
         if (!empty($matches[0])) {
             foreach ($matches[0] as $url) {
                 // Remove anything left on at the end; just in case
                 $url = preg_replace('/^\\PL+|\\PL\\z/', '', trim($url));
                 $this->validateLink($url, $currentTokens, $foundLinks);
             }
         }
     }
     $trackedLinks = array();
     if (!empty($foundLinks)) {
         $links = $redirectModel->getRedirectListByUrls($foundLinks, $this->emailEntity);
         foreach ($links as $url => $link) {
             if (!$link->getId() && !isset($persistEntities[$url])) {
                 $persistEntities[$url] = $link;
             }
             $trackedLinks[$url] = $link;
         }
     }
     if (!empty($persistEntities)) {
         // Save redirect entities
         $redirectModel->getRepository()->saveEntities($persistEntities);
     }
     unset($foundLinks, $links, $persistEntities);
     return $trackedLinks;
 }
示例#17
0
 /**
  * Parses content for URLs and tokens.
  *
  * @param EmailSendEvent $event
  * @param                $emailId
  *
  * @return mixed
  */
 protected function parseContentForUrls(EmailSendEvent $event, $emailId)
 {
     static $convertedContent = [];
     // Prevent parsing the exact same content over and over
     if (!isset($convertedContent[$event->getContentHash()])) {
         $html = $event->getContent();
         $text = $event->getPlainText();
         $contentTokens = $event->getTokens();
         list($content, $trackables) = $this->pageTrackableModel->parseContentForTrackables([$html, $text], $contentTokens, $emailId ? 'email' : null, $emailId);
         list($html, $text) = $content;
         unset($content);
         if ($html) {
             $event->setContent($html);
         }
         if ($text) {
             $event->setPlainText($text);
         }
         $convertedContent[$event->getContentHash()] = $trackables;
         // Don't need to preserve Trackable or Redirect entities in memory
         $this->em->clear('Mautic\\PageBundle\\Entity\\Redirect');
         $this->em->clear('Mautic\\PageBundle\\Entity\\Trackable');
         unset($html, $text, $trackables);
     }
     return $convertedContent[$event->getContentHash()];
 }
示例#18
0
 /**
  * @param EmailSendEvent $event
  *
  * @return void
  */
 public function onEmailGenerate(EmailSendEvent $event)
 {
     $content = $event->getContent();
     $plainText = $event->getPlainText();
     $clickthrough = $event->shouldAppendClickthrough() ? $event->generateClickthrough() : array();
     $this->emailIsInternalSend = $event->isInternalSend();
     $this->emailEntity = $event->getEmail();
     $tokens = array_merge($this->generatePageTokens($content . $plainText, $clickthrough), $this->generateExternalLinkTokens($content . $plainText, $clickthrough));
     $event->addTokens($tokens);
 }
示例#19
0
 /**
  * Converts links to trackable links and tokens
  *
  * @param EmailSendEvent $event
  *
  * @return array
  */
 protected function convertTrackableLinks(EmailSendEvent $event)
 {
     $taggedDoNotTrack = array();
     // Get a list of tokens for the tokenized link conversion
     $currentTokens = $event->getTokens();
     // Parse the content for links
     $body = $event->getContent();
     // Find links using DOM to only find <a> tags
     $libxmlPreviousState = libxml_use_internal_errors(true);
     libxml_use_internal_errors(true);
     $dom = new \DOMDocument();
     $dom->loadHTML('<?xml encoding="UTF-8">' . $body);
     libxml_clear_errors();
     libxml_use_internal_errors($libxmlPreviousState);
     $links = $dom->getElementsByTagName('a');
     $foundLinks = $tokenizedLinks = array();
     /** @var \DOMElement $link */
     foreach ($links as $link) {
         $url = $link->getAttribute('href');
         // The editor will have converted & to &amp; but DOMDocument will have converted them back so this must be accounted for
         $url = str_replace('&', '&amp;', $url);
         // Check for a do not track
         if ($link->hasAttribute('mautic:disable-tracking')) {
             $taggedDoNotTrack[$url] = true;
             continue;
         }
         $this->validateLink($url, $currentTokens, $foundLinks);
     }
     // Process plain text as well
     $plainText = $event->getPlainText();
     if (!empty($plainText)) {
         // Plaintext links
         preg_match_all('/((https?|ftps?):\\/\\/)([a-zA-Z0-9-\\.{}]*[a-zA-Z0-9=}]*)(\\??)([^\\s\\]]+)?/i', $plainText, $matches);
         if (!empty($matches[0])) {
             foreach ($matches[0] as $url) {
                 $url = trim($url);
                 // Validate the link if it has not already been marked as do not track by attribute in the HTML version
                 if (!isset($taggedDoNotTrack[$url])) {
                     $this->validateLink($url, $currentTokens, $foundLinks);
                 }
             }
         }
     }
     /** @var \Mautic\PageBundle\Model\RedirectModel $redirectModel */
     $redirectModel = $this->factory->getModel('page.redirect');
     if (!empty($foundLinks)) {
         $links = $redirectModel->getRedirectListByUrls($foundLinks, $this->emailEntity);
         foreach ($links as $url => $link) {
             if (!$link->getId() && !isset($persistEntities[$url])) {
                 $persistEntities[$url] = $link;
             }
             $this->emailTrackedLinkSettings['trackedLinks'][$url] = $link;
         }
     }
     if (!empty($persistEntities)) {
         // Save redirect entities
         $redirectModel->getRepository()->saveEntities($persistEntities);
     }
     unset($foundLinks, $links, $persistEntities);
 }