/** * 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); }
/** * @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); }
/** * @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()); } }
/** * 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()]; }
/** * 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); }