/**
  * Render a single message content element.
  *
  * @param RenderMessageContentEvent $event
  *
  * @return string
  */
 public function renderContent(RenderMessageContentEvent $event)
 {
     global $container;
     $content = $event->getMessageContent();
     if ($content->getType() != 'downloads' || $event->getRenderedContent()) {
         return;
     }
     /** @var EntityAccessor $entityAccessor */
     $entityAccessor = $container['doctrine.orm.entityAccessor'];
     $context = $entityAccessor->getProperties($content);
     $context['files'] = array();
     foreach ($context['downloadSources'] as $index => $downloadSource) {
         $context['downloadSources'][$index] = $downloadSource = \Compat::resolveFile($downloadSource);
         $file = new \File($downloadSource, true);
         if (!$file->exists()) {
             unset($context['downloadSources'][$index]);
             continue;
         }
         $context['files'][$index] = array('url' => $downloadSource, 'size' => \System::getReadableSize(filesize(TL_ROOT . DIRECTORY_SEPARATOR . $downloadSource)), 'icon' => 'assets/contao/images/' . $file->icon, 'title' => basename($downloadSource));
     }
     if (empty($context['files'])) {
         return;
     }
     $template = new \TwigTemplate('avisota/message/renderer/default/mce_downloads', 'html');
     $buffer = $template->parse($context);
     $event->setRenderedContent($buffer);
 }
 /**
  * Render a multiple message content element.
  *
  * @param RenderMessageContentEvent $event
  *
  * @return string
  */
 public function renderContent(RenderMessageContentEvent $event)
 {
     global $container;
     $content = $event->getMessageContent();
     if ($content->getType() != 'news' || $event->getRenderedContent()) {
         return;
     }
     /** @var EntityAccessor $entityAccessor */
     $entityAccessor = $container['doctrine.orm.entityAccessor'];
     $contexts = array();
     foreach ($content->getNewsId() as $elementId) {
         $getNewsEvent = new GetNewsEvent($elementId, $content->getNewsTemplate());
         /** @var EventDispatcher $eventDispatcher */
         $eventDispatcher = $container['event-dispatcher'];
         $eventDispatcher->dispatch(ContaoEvents::NEWS_GET_NEWS, $getNewsEvent);
         $context = $entityAccessor->getProperties($content);
         $context['news'] = $getNewsEvent->getNewsHtml();
         array_push($contexts, $context);
     }
     $buffer = '';
     foreach ($contexts as $context) {
         $template = new \TwigTemplate('avisota/message/renderer/default/mce_news', 'html');
         $buffer .= $template->parse($context);
     }
     $event->setRenderedContent($buffer);
 }
 public static function replaceInsertTagsOnlineView(RenderMessageContentEvent $objEvent)
 {
     global $objPage;
     if ($objPage) {
         $strContent = $objEvent->getRenderedContent();
         $strContent = str_replace(array('%7B%7B', '%7D%7D'), array('{{', '}}'), $strContent);
         $objEvent->setRenderedContent(\Controller::replaceInsertTags($strContent));
     }
 }
 /**
  * Render a single message content element.
  *
  * @param RenderMessageContentEvent $event
  *
  * @return string
  * @internal param MessageContent $content
  * @internal param RecipientInterface $recipient
  */
 public function renderContent(RenderMessageContentEvent $event)
 {
     global $container;
     $content = $event->getMessageContent();
     if ($content->getType() != 'salutation' || $event->getRenderedContent()) {
         return;
     }
     /** @var EntityAccessor $entityAccessor */
     $entityAccessor = $container['doctrine.orm.entityAccessor'];
     $context = $entityAccessor->getProperties($content);
     $template = new \TwigTemplate('avisota/message/renderer/default/mce_salutation', 'html');
     $buffer = $template->parse($context);
     $event->setRenderedContent($buffer);
 }
 /**
  * Render a single message content element.
  *
  * @param RenderMessageContentEvent $event
  *
  * @return string
  */
 public function renderContent(RenderMessageContentEvent $event)
 {
     global $container;
     $content = $event->getMessageContent();
     if ($content->getType() != 'article' || $event->getRenderedContent() || !$content->getArticleId()) {
         return;
     }
     /** @var EntityAccessor $entityAccessor */
     $entityAccessor = $container['doctrine.orm.entityAccessor'];
     /** @var EventDispatcher $eventDispatcher */
     $eventDispatcher = $container['event-dispatcher'];
     $articles = array();
     foreach ($content->getArticleId() as $articleId) {
         if (empty($articleId)) {
             continue;
         }
         $getArticleEvent = new GetArticleEvent($articleId, !$content->getArticleFull(), $content->getCell());
         if (!$content->getArticleFull()) {
             $article = ArticleModel::findByPk($articleId);
             $article->showTeaser = 1;
             global $objPage;
             if (!$objPage) {
                 $objPage = $article->getRelated('pid');
                 $objPage->loadDetails();
             }
         }
         $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GET_ARTICLE, $getArticleEvent);
         $context = $entityAccessor->getProperties($content);
         $context['article'] = $getArticleEvent->getArticle();
         array_push($articles, $context);
     }
     $buffer = '';
     foreach ($articles as $article) {
         $template = new TwigTemplate('avisota/message/renderer/default/mce_article', 'html');
         $buffer .= $template->parse($article);
     }
     $event->setRenderedContent($buffer);
 }
 /**
  * Render a single message content element.
  *
  * @param RenderMessageContentEvent $event
  *
  * @return string
  */
 public function renderContent(RenderMessageContentEvent $event)
 {
     global $container;
     $content = $event->getMessageContent();
     if ($content->getType() != 'download' || $event->getRenderedContent()) {
         return;
     }
     /** @var EntityAccessor $entityAccessor */
     $entityAccessor = $container['doctrine.orm.entityAccessor'];
     $context = $entityAccessor->getProperties($content);
     $context['downloadSource'] = \Compat::resolveFile($context['downloadSource']);
     $file = new \File($context['downloadSource'], true);
     if (!$file->exists()) {
         return;
     }
     $context['downloadSize'] = \System::getReadableSize(filesize(TL_ROOT . DIRECTORY_SEPARATOR . $context['downloadSource']));
     $context['downloadIcon'] = 'assets/contao/images/' . $file->icon;
     if (empty($context['downloadTitle'])) {
         $context['downloadTitle'] = basename($context['downloadSource']);
     }
     $template = new \TwigTemplate('avisota/message/renderer/default/mce_download', 'html');
     $buffer = $template->parse($context);
     $event->setRenderedContent($buffer);
 }
 /**
  * Render a single message content element.
  *
  * @param RenderMessageContentEvent $event
  *
  * @return string
  * @internal param MessageContent $content
  * @internal param RecipientInterface $recipient
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function renderContent(RenderMessageContentEvent $event)
 {
     global $container;
     $content = $event->getMessageContent();
     if ($content->getType() != 'gallery' || $event->getRenderedContent()) {
         return;
     }
     /** @var EventDispatcher $eventDispatcher */
     $eventDispatcher = $container['event-dispatcher'];
     /** @var EntityAccessor $entityAccessor */
     $entityAccessor = $container['doctrine.orm.entityAccessor'];
     $context = $entityAccessor->getProperties($content);
     $size = $content->getImageSize();
     $images = array();
     $sorting = array();
     $imageSources = 'imageSources';
     if ($content->getSortBy() === 'custom') {
         $imageSources = 'orderSRC';
     }
     foreach ($context[$imageSources] as $index => $file) {
         $context[$imageSources][$index] = $file = \Compat::resolveFile($file);
         switch ($content->getSortBy()) {
             case 'name_asc':
             case 'name_desc':
                 $sorting[] = basename($file);
                 break;
             case 'date_asc':
             case 'date_desc':
                 $sorting[] = filemtime(TL_ROOT . DIRECTORY_SEPARATOR . $file);
                 break;
             case 'random':
                 $sorting[] = rand(-PHP_INT_MAX, PHP_INT_MAX);
         }
         $resizeImageEvent = new ResizeImageEvent($file, $size[0], $size[1], $size[2]);
         $eventDispatcher->dispatch(ContaoEvents::IMAGE_RESIZE, $resizeImageEvent);
         $images[] = $resizeImageEvent->getResultImage();
     }
     switch ($content->getSortBy()) {
         case 'name_asc':
             uasort($sorting, 'strnatcasecmp');
             break;
         case 'name_desc':
             uasort($sorting, 'strnatcasecmp');
             $sorting = array_reverse($sorting, true);
             break;
         case 'random':
         case 'date_asc':
             asort($sorting);
             break;
         case 'date_desc':
             arsort($sorting);
             break;
         default:
             $sorting = false;
     }
     if ($sorting) {
         $sorting = array_keys($sorting);
         uksort($images, function ($primary, $secondary) use($sorting) {
             return array_search($primary, $sorting) - array_search($secondary, $sorting);
         });
     }
     $context['rows'] = array();
     while (count($images)) {
         $row = array_slice($images, 0, $content->getPerRow());
         $images = array_slice($images, $content->getPerRow());
         while (count($row) < $content->getPerRow()) {
             $row[] = false;
         }
         $context['rows'][] = $row;
     }
     $styles = array();
     $margins = $content->getImagemargin();
     foreach (array('top', 'right', 'bottom', 'left') as $property) {
         if (!empty($margins[$property])) {
             $styles[] = sprintf('padding-%s:%s%s', $property, $margins[$property], $margins['unit']);
         }
     }
     $context['styles'] = implode(';', $styles);
     $template = new \TwigTemplate('avisota/message/renderer/default/mce_gallery', 'html');
     $buffer = $template->parse($context);
     $event->setRenderedContent($buffer);
 }
 /**
  * Render the text content element.
  *
  * @param RenderMessageContentEvent $event
  *
  * @return string
  * @internal param MessageContent $content
  * @internal param RecipientInterface $recipient
  *
  */
 public function renderText(RenderMessageContentEvent $event)
 {
     global $container;
     $content = $event->getMessageContent();
     if ($content->getType() != 'text' || $event->getRenderedContent()) {
         return;
     }
     $layout = $event->getLayout();
     if ($layout->getType() != 'mailChimp') {
         return;
     }
     /** @var EntityAccessor $entityAccessor */
     $entityAccessor = $container['doctrine.orm.entityAccessor'];
     $context = $entityAccessor->getProperties($content);
     $template = new \TwigTemplate('avisota/message/renderer/mailchimp/mce_text', 'html');
     $buffer = $template->parse($context);
     $event->setRenderedContent($buffer);
 }