public static function convertToInlineCss(PostRenderMessageContentEvent $objEvent)
 {
     if (Environment::getUrlBasename() != 'preview') {
         $arrInlineStylesheetContents = static::getStylesheetContents($objEvent->getMessage()->getLayout(), static::AVISOTA_CSS_MODE_INLINE);
         if (!empty($arrInlineStylesheetContents)) {
             $objEvent->setContent(DOM::convertToInlineCss($objEvent->getContent(), implode(' ', $arrInlineStylesheetContents)));
         }
     }
 }
 /**
  * Inject the GA parameters to each url in the newsletter.
  *
  * @param PostRenderMessageContentEvent|RenderMessageEvent $event
  */
 public function injectGA(PostRenderMessageContentEvent $event)
 {
     $message = $event->getMessage();
     if (!$message->getGaEnable()) {
         return;
     }
     $content = $event->getContent();
     $query = http_build_query(array('utm_source' => 'Newsletter ' . $message->getSubject(), 'utm_medium' => 'E-Mail', 'utm_campaign' => $message->getGaCampaign() ?: $message->getSubject(), 'utm_term' => $message->getGaTerm()));
     $base = \Environment::get('base');
     $content = preg_replace_callback('~href=(["\'])(.*)\\1~U', function ($matches) use($query, $base) {
         $url = $matches[2];
         if (preg_match('~^\\w+:~', $url) && substr($url, 0, strlen($base)) != $base) {
             return $matches[0];
         }
         $parts = parse_url($url);
         if ($parts['query']) {
             $parts['query'] .= '&' . $query;
         } else {
             $parts['query'] = $query;
         }
         $url = $parts['scheme'] . '://';
         if ($parts['user']) {
             $url .= $parts['user'];
             if ($parts['pass']) {
                 $url .= ':' . $parts['pass'];
             }
             $url .= '@';
         }
         $url .= $parts['host'];
         if ($parts['port']) {
             $url .= ':' . $parts['port'];
         }
         $url .= $parts['path'];
         $url .= '?' . $parts['query'];
         if ($parts['fragment']) {
             $url .= '#' . $parts['fragment'];
         }
         return sprintf('href="%s"', htmlentities($url, ENT_QUOTES, 'UTF-8'));
     }, $content);
     $event->setContent($content);
 }