Exemplo n.º 1
0
 /**
  * @param PageDisplayEvent $event
  *
  * @return void
  */
 public function decodeTokens(PageDisplayEvent $event)
 {
     // Find and replace encoded tokens for trackable URL conversion
     $content = $event->getContent();
     $content = preg_replace('/(%7B)(.*?)(%7D)/i', '{$2}', $content);
     $event->setContent($content);
 }
Exemplo n.º 2
0
 /**
  * @param PageDisplayEvent $event
  */
 public function onPageDisplay(PageDisplayEvent $event)
 {
     $content = $event->getContent();
     $page = $event->getPage();
     $regex = '/' . $this->formRegex . '/i';
     preg_match_all($regex, $content, $matches);
     if (count($matches[0])) {
         /** @var \Mautic\FormBundle\Model\FormModel $model */
         $model = $this->factory->getModel('form');
         foreach ($matches[1] as $k => $id) {
             $form = $model->getEntity($id);
             if ($form !== null && ($form->isPublished(false) || $this->security->hasEntityAccess('form:forms:viewown', 'form:forms:viewother', $form->getCreatedBy()))) {
                 $formHtml = $form->isPublished() ? $model->getContent($form) : '<div class="mauticform-error">' . $this->translator->trans('mautic.form.form.pagetoken.notpublished') . '</div>';
                 //add the hidden page input
                 $pageInput = "\n<input type=\"hidden\" name=\"mauticform[mauticpage]\" value=\"{$page->getId()}\" />\n";
                 $formHtml = preg_replace("#</form>#", $pageInput . "</form>", $formHtml);
                 //pouplate get parameters
                 $model->populateValuesWithGetParameters($form, $formHtml);
                 $content = preg_replace('#{form=' . $id . '}#', $formHtml, $content);
             } else {
                 $content = preg_replace("#{form=" . $id . "}#", "", $content);
             }
         }
     }
     $event->setContent($content);
 }
Exemplo n.º 3
0
 /**
  * Allow event listeners to add scripts to
  * - </head> : onPageDisplay_headClose
  * - <body>  : onPageDisplay_bodyOpen
  * - </body> : onPageDisplay_bodyClose
  *
  * @param Events\PageDisplayEvent $event
  */
 public function onPageDisplay(Events\PageDisplayEvent $event)
 {
     $content = $event->getContent();
     /** @var \Mautic\CoreBundle\Templating\Helper\AssetsHelper $assetsHelper */
     $assetsHelper = $this->factory->getHelper('template.assets');
     // Get scripts to insert before </head>
     ob_start();
     $assetsHelper->outputScripts('onPageDisplay_headClose');
     $headCloseScripts = ob_get_clean();
     if ($headCloseScripts) {
         $content = str_ireplace('</head>', $headCloseScripts . "\n</head>", $content);
     }
     // Get scripts to insert after <body>
     ob_start();
     $assetsHelper->outputScripts('onPageDisplay_bodyOpen');
     $bodyOpenScripts = ob_get_clean();
     if ($bodyOpenScripts) {
         preg_match('/(<body[a-z=\\s\\-_:"\']*>)/i', $content, $matches);
         $content = str_ireplace($matches[0], $matches[0] . "\n" . $bodyOpenScripts, $content);
     }
     // Get scripts to insert before </body>
     ob_start();
     $assetsHelper->outputScripts('onPageDisplay_bodyClose');
     $bodyCloseScripts = ob_get_clean();
     if ($bodyCloseScripts) {
         $content = str_ireplace('</body>', $bodyCloseScripts . "\n</body>", $content);
     }
     $event->setContent($content);
 }
Exemplo n.º 4
0
 /**
  * @param PageDisplayEvent $event
  */
 public function onPageDisplay(PageDisplayEvent $event)
 {
     $content = $event->getContent();
     $page = $event->getPage();
     $regex = '/' . $this->formRegex . '/i';
     preg_match_all($regex, $content, $matches);
     if (count($matches[0])) {
         foreach ($matches[1] as $k => $id) {
             $form = $this->formModel->getEntity($id);
             if ($form !== null && ($form->isPublished(false) || $this->security->hasEntityAccess('form:forms:viewown', 'form:forms:viewother', $form->getCreatedBy()))) {
                 $formHtml = $form->isPublished() ? $this->formModel->getContent($form) : '<div class="mauticform-error">' . $this->translator->trans('mautic.form.form.pagetoken.notpublished') . '</div>';
                 //add the hidden page input
                 $pageInput = "\n<input type=\"hidden\" name=\"mauticform[mauticpage]\" value=\"{$page->getId()}\" />\n";
                 $formHtml = preg_replace('#</form>#', $pageInput . '</form>', $formHtml);
                 //pouplate get parameters
                 //priority populate value order by: query string (parameters) -> with lead
                 if (!$form->getInKioskMode()) {
                     $this->formModel->populateValuesWithLead($form, $formHtml);
                 }
                 $this->formModel->populateValuesWithGetParameters($form, $formHtml);
                 $content = preg_replace('#{form=' . $id . '}#', $formHtml, $content);
             } else {
                 $content = preg_replace('#{form=' . $id . '}#', '', $content);
             }
         }
     }
     $event->setContent($content);
 }
Exemplo n.º 5
0
 /**
  * @param PageDisplayEvent $event
  */
 public function onPageDisplay(PageDisplayEvent $event)
 {
     $page = $event->getPage();
     $leadId = $this->factory->getSecurity()->isAnonymous() ? $this->factory->getModel('lead')->getCurrentLead()->getId() : null;
     $tokens = $this->generateTokensFromContent($event, $leadId, array('page', $page->getId()));
     $content = $event->getContent();
     if (!empty($tokens)) {
         $content = str_ireplace(array_keys($tokens), $tokens, $content);
     }
     $event->setContent($content);
 }
Exemplo n.º 6
0
 /**
  * @param Events\PageDisplayEvent $event
  */
 public function onPageDisplay(Events\PageDisplayEvent $event)
 {
     $content = $event->getContent();
     $page = $event->getPage();
     if (strpos($content, $this->langBarRegex) !== false) {
         $langbar = $this->renderLanguageBar($page);
         $content = str_ireplace($this->langBarRegex, $langbar, $content);
     }
     if (strpos($content, $this->shareButtonsRegex) !== false) {
         $buttons = $this->renderSocialShareButtons();
         $content = str_ireplace($this->shareButtonsRegex, $buttons, $content);
     }
     $tokens = $this->generateUrlTokens($content, array('source' => array('page', $page->getId())));
     if (!empty($tokens)) {
         $content = str_ireplace(array_keys($tokens), $tokens, $content);
     }
     $event->setContent($content);
 }
Exemplo n.º 7
0
 /**
  * @param PageDisplayEvent $event
  */
 public function onPageDisplay(PageDisplayEvent $event)
 {
     $content = $event->getContent();
     $regex = '/' . $this->regex . '/i';
     preg_match_all($regex, $content, $matches);
     if (count($matches[0])) {
         foreach ($matches[1] as $k => $id) {
             $focus = $this->model->getEntity($id);
             if ($focus !== null && ($focus->isPublished() || $this->security->hasEntityAccess('plugin:focus:items:viewown', 'plugin:focus:items:viewother', $focus->getCreatedBy()))) {
                 $script = '<script src="' . $this->router->generate('mautic_focus_generate', ['id' => $id], true) . '" type="text/javascript" charset="utf-8" async="async"></script>';
                 $content = preg_replace('#{focus=' . $id . '}#', $script, $content);
             } else {
                 $content = preg_replace('#{focus=' . $id . '}#', '', $content);
             }
         }
     }
     $event->setContent($content);
 }
Exemplo n.º 8
0
 /**
  * @param Events\PageDisplayEvent $event
  */
 public function onPageDisplay(Events\PageDisplayEvent $event)
 {
     $content = $event->getContent();
     $page = $event->getPage();
     if (strpos($content, $this->langBarRegex) !== false) {
         $langbar = $this->renderLanguageBar($page);
         $content = str_ireplace($this->langBarRegex, $langbar, $content);
     }
     if (strpos($content, $this->shareButtonsRegex) !== false) {
         $buttons = $this->renderSocialShareButtons();
         $content = str_ireplace($this->shareButtonsRegex, $buttons, $content);
     }
     $clickThrough = array('source' => array('page', $page->getId()));
     $pageTokens = $this->generatePageTokens($content, $clickThrough);
     $externalTokens = $this->generateExternalLinkTokens($content, $clickThrough);
     $tokens = array_merge($pageTokens, $externalTokens);
     if (count($tokens)) {
         $content = str_ireplace(array_keys($tokens), $tokens, $content);
     }
     $event->setContent($content);
 }
Exemplo n.º 9
0
 /**
  * @param Events\PageDisplayEvent $event
  */
 public function onPageDisplay(Events\PageDisplayEvent $event)
 {
     $content = $event->getContent();
     $page = $event->getPage();
     if (strpos($content, $this->langBarRegex) !== false) {
         $langbar = $this->renderLanguageBar($page);
         $content = str_ireplace($this->langBarRegex, $langbar, $content);
     }
     if (strpos($content, $this->shareButtonsRegex) !== false) {
         $buttons = $this->renderSocialShareButtons();
         $content = str_ireplace($this->shareButtonsRegex, $buttons, $content);
     }
     if (strpos($content, $this->titleRegex) !== false) {
         $content = str_ireplace($this->titleRegex, $page->getTitle(), $content);
     }
     if (strpos($content, $this->descriptionRegex) !== false) {
         $content = str_ireplace($this->descriptionRegex, $page->getMetaDescription(), $content);
     }
     $clickThrough = ['source' => ['page', $page->getId()]];
     $tokens = $this->tokenHelper->findPageTokens($content, $clickThrough);
     if (count($tokens)) {
         $content = str_ireplace(array_keys($tokens), $tokens, $content);
     }
     $event->setContent($content);
 }