isHtmlResponse() public static method

public static isHtmlResponse ( Zend_Controller_Response_Abstract $response ) : boolean
$response Zend_Controller_Response_Abstract
return boolean
コード例 #1
1
    /**
     *
     */
    public function dispatchLoopShutdown()
    {
        if (!Tool::isHtmlResponse($this->getResponse())) {
            return;
        }
        $siteKey = \Pimcore\Tool\Frontend::getSiteKey();
        $reportConfig = \Pimcore\Config::getReportConfig();
        if ($this->enabled && isset($reportConfig->tagmanager->sites->{$siteKey}->containerId)) {
            $containerId = $reportConfig->tagmanager->sites->{$siteKey}->containerId;
            if ($containerId) {
                $code = <<<CODE
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id={$containerId}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{$containerId}');</script>
<!-- End Google Tag Manager -->
CODE;
                $body = $this->getResponse()->getBody();
                // insert code after the opening <body> tag
                $body = preg_replace("@<body(>|.*?[^?]>)@", "<body\$1\n\n" . $code, $body);
                $this->getResponse()->setBody($body);
            }
        }
    }
コード例 #2
1
ファイル: MinifyJs.php プロジェクト: Cruiser13/pimcore-minify
 public function dispatchLoopShutdown()
 {
     if (!Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if (!Tool::useFrontendOutputFilters($this->getRequest()) && !$this->getRequest()->getParam("pimcore_preview")) {
         return;
     }
     if (\Pimcore::inDebugMode()) {
         return;
     }
     if ($this->enabled) {
         include_once "simple_html_dom.php";
         $body = $this->getResponse()->getBody();
         $html = str_get_html($body);
         if ($html) {
             $html = $this->searchForScriptSrcAndReplace($html);
             $html = $this->searchForInlineScriptAndReplace($html);
             $body = $html->save();
             $html->clear();
             unset($html);
         }
         $this->getResponse()->setBody($body);
     }
 }
コード例 #3
0
ファイル: AdminButton.php プロジェクト: Gerhard13/pimcore
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if (!Tool::useFrontendOutputFilters($this->getRequest()) && !$this->getRequest()->getParam("pimcore_preview")) {
         return;
     }
     if (isset($_COOKIE["pimcore_admin_sid"])) {
         try {
             // we should not start a session here as this can break the functionality of the site if
             // the website itself uses sessions, so we include the code, and check asynchronously if the user is logged in
             // this is done by the embedded script
             $body = $this->getResponse()->getBody();
             $document = $this->getRequest()->getParam("document");
             if ($document instanceof Model\Document && !Model\Staticroute::getCurrentRoute()) {
                 $documentId = $document->getId();
             }
             if (!isset($documentId) || !$documentId) {
                 $documentId = "null";
             }
             $code = '<script type="text/javascript" src="/admin/admin-button/script?documentId=' . $documentId . '"></script>';
             // search for the end <head> tag, and insert the google analytics code before
             // this method is much faster than using simple_html_dom and uses less memory
             $bodyEndPosition = stripos($body, "</body>");
             if ($bodyEndPosition !== false) {
                 $body = substr_replace($body, $code . "\n\n</body>\n", $bodyEndPosition, 7);
             }
             $this->getResponse()->setBody($body);
         } catch (\Exception $e) {
             \Logger::error($e);
         }
     }
 }
コード例 #4
0
 public function dispatchLoopShutdown()
 {
     if (!Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if (\Pimcore::inDebugMode()) {
         return;
     }
     if (!Tool::useFrontendOutputFilters($this->getRequest()) && !$this->getRequest()->getParam("pimcore_preview")) {
         return;
     }
     if ($this->enabled) {
         include_once "simple_html_dom.php";
         $body = $this->getResponse()->getBody();
         $html = str_get_html($body);
         if ($html) {
             $styles = $html->find("link[rel=stylesheet], style[type=text/css]");
             $stylesheetContent = "";
             foreach ($styles as $style) {
                 if ($style->tag == "style") {
                     $stylesheetContent .= $style->innertext;
                 } else {
                     $source = $style->href;
                     $path = "";
                     if (is_file(PIMCORE_ASSET_DIRECTORY . $source)) {
                         $path = PIMCORE_ASSET_DIRECTORY . $source;
                     } else {
                         if (is_file(PIMCORE_DOCUMENT_ROOT . $source)) {
                             $path = PIMCORE_DOCUMENT_ROOT . $source;
                         }
                     }
                     if (!empty($path) && is_file("file://" . $path)) {
                         $content = file_get_contents($path);
                         $content = $this->correctReferences($source, $content);
                         if ($style->media && $style->media != "all") {
                             $content = "@media " . $style->media . " {" . $content . "}";
                         }
                         $stylesheetContent .= $content;
                         $style->outertext = "";
                     }
                 }
             }
             if (strlen($stylesheetContent) > 1) {
                 $stylesheetPath = PIMCORE_TEMPORARY_DIRECTORY . "/minified_css_" . md5($stylesheetContent) . ".css";
                 if (!is_file($stylesheetPath)) {
                     $stylesheetContent = \Minify_CSS::minify($stylesheetContent);
                     // put minified contents into one single file
                     file_put_contents($stylesheetPath, $stylesheetContent);
                     chmod($stylesheetPath, 0766);
                 }
                 $head = $html->find("head", 0);
                 $head->innertext = $head->innertext . "\n" . '<link rel="stylesheet" type="text/css" href="' . str_replace(PIMCORE_DOCUMENT_ROOT, "", $stylesheetPath) . '" />' . "\n";
             }
             $body = $html->save();
             $html->clear();
             unset($html);
             $this->getResponse()->setBody($body);
         }
     }
 }
コード例 #5
0
ファイル: EuCookieLawNotice.php プロジェクト: sfie/pimcore
    /**
     *
     */
    public function dispatchLoopShutdown()
    {
        $config = \Pimcore\Config::getSystemConfig();
        if (!$config->general->show_cookie_notice || !Tool::useFrontendOutputFilters($this->getRequest()) || !Tool::isHtmlResponse($this->getResponse())) {
            return;
        }
        $template = file_get_contents(__DIR__ . "/EuCookieLawNotice/template.html");
        # cleanup code
        $template = preg_replace('/[\\r\\n\\t]+/', ' ', $template);
        #remove new lines, spaces, tabs
        $template = preg_replace('/>[\\s]+</', '><', $template);
        #remove new lines, spaces, tabs
        $template = preg_replace('/[\\s]+/', ' ', $template);
        #remove new lines, spaces, tabs
        $translations = $this->getTranslations();
        foreach ($translations as $key => &$value) {
            $value = htmlentities($value, ENT_COMPAT, "UTF-8");
            $template = str_replace("%" . $key . "%", $value, $template);
        }
        $linkContent = "";
        if (array_key_exists("linkTarget", $translations)) {
            $linkContent = '<a href="' . $translations["linkTarget"] . '" data-content="' . $translations["linkText"] . '"></a>';
        }
        $template = str_replace("%link%", $linkContent, $template);
        $templateCode = \Zend_Json::encode($template);
        $code = '
            <script>
                (function () {
                    var ls = window["localStorage"];
                    if(ls && !ls.getItem("pc-cookie-accepted")) {

                        var code = ' . $templateCode . ';
                        var ci = window.setInterval(function () {
                            if(document.body) {
                                clearInterval(ci);
                                document.body.insertAdjacentHTML("beforeend", code);

                                document.getElementById("pc-button").onclick = function () {
                                    document.getElementById("pc-cookie-notice").style.display = "none";
                                    ls.setItem("pc-cookie-accepted", "true");
                                };
                            }
                        }, 100);
                    }
                })();
            </script>
        ';
        $body = $this->getResponse()->getBody();
        // search for the end <head> tag, and insert the google analytics code before
        // this method is much faster than using simple_html_dom and uses less memory
        $headEndPosition = stripos($body, "</head>");
        if ($headEndPosition !== false) {
            $body = substr_replace($body, $code . "</head>", $headEndPosition, 7);
        }
        $this->getResponse()->setBody($body);
    }
コード例 #6
0
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!\Pimcore\Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     // removes the non-valid html attributes which are used by the wysiwyg editor for ID based linking
     $body = $this->getResponse()->getBody();
     $body = preg_replace("/ pimcore_(id|type|disable_thumbnail)=\\\"([0-9a-z]+)\\\"/", "", $body);
     $this->getResponse()->setBody($body);
 }
コード例 #7
0
ファイル: Less.php プロジェクト: ChristophWurst/pimcore
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!\Pimcore\Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if ($this->enabled) {
         include_once "simple_html_dom.php";
         $body = $this->getResponse()->getBody();
         $body = \Pimcore\Tool\Less::processHtml($body);
         $this->getResponse()->setBody($body);
     }
 }
コード例 #8
0
ファイル: Less.php プロジェクト: pawansgi92/pimcore2
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!\Pimcore\Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if ($this->enabled) {
         include_once "simple_html_dom.php";
         if ($this->getRequest()->getParam("pimcore_editmode")) {
             $this->editmode();
         } else {
             $this->frontend();
         }
     }
 }
コード例 #9
0
ファイル: Analytics.php プロジェクト: ChristophWurst/pimcore
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if ($this->enabled && ($code = AnalyticsHelper::getCode())) {
         // analytics
         $body = $this->getResponse()->getBody();
         // search for the end <head> tag, and insert the google analytics code before
         // this method is much faster than using simple_html_dom and uses less memory
         $headEndPosition = stripos($body, "</head>");
         if ($headEndPosition !== false) {
             $body = substr_replace($body, $code . "</head>", $headEndPosition, 7);
         }
         $this->getResponse()->setBody($body);
     }
 }
コード例 #10
0
ファイル: GoogleTagManager.php プロジェクト: pimcore/pimcore
    /**
     *
     */
    public function dispatchLoopShutdown()
    {
        if (!Tool::isHtmlResponse($this->getResponse())) {
            return;
        }
        $siteKey = \Pimcore\Tool\Frontend::getSiteKey();
        $reportConfig = \Pimcore\Config::getReportConfig();
        if ($this->enabled && isset($reportConfig->tagmanager->sites->{$siteKey}->containerId)) {
            $containerId = $reportConfig->tagmanager->sites->{$siteKey}->containerId;
            if ($containerId) {
                $codeHead = <<<CODE


<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{$containerId}');</script>
<!-- End Google Tag Manager -->


CODE;
                $codeBody = <<<CODE


<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id={$containerId}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->


CODE;
                $body = $this->getResponse()->getBody();
                // search for the end <head> tag, and insert the google tag manager code before
                // this method is much faster than using simple_html_dom and uses less memory
                $headEndPosition = stripos($body, "</head>");
                if ($headEndPosition !== false) {
                    $body = substr_replace($body, $codeHead . "</head>", $headEndPosition, 7);
                }
                // insert code after the opening <body> tag
                $body = preg_replace("@<body(>|.*?[^?]>)@", "<body\$1\n\n" . $codeBody, $body);
                $this->getResponse()->setBody($body);
            }
        }
    }
コード例 #11
0
 public function dispatchLoopShutdown()
 {
     if (!Tool::isHtmlResponse($this->getResponse())) {
         return FALSE;
     }
     $body = $this->getResponse()->getBody();
     $htmlData = $this->getEventData();
     if (isset($htmlData['header']) && !empty($htmlData['header'])) {
         $headEndPosition = stripos($body, "</head>");
         if ($headEndPosition !== false) {
             $body = substr_replace($body, $htmlData['header'] . "</head>", $headEndPosition, 7);
         }
     }
     if (isset($htmlData['footer']) && !empty($htmlData['footer'])) {
         $bodyEndPosition = stripos($body, "</body>");
         if ($bodyEndPosition !== false) {
             $body = substr_replace($body, $htmlData['footer'] . "</body>", $bodyEndPosition, 7);
         }
     }
     $this->getResponse()->setBody($body);
 }
コード例 #12
0
ファイル: ViewRenderer.php プロジェクト: Gerhard13/pimcore
 /**
  *
  */
 public function postDispatch()
 {
     if ($this->_shouldRender()) {
         if (method_exists($this->getActionController(), "getRenderScript")) {
             if ($script = $this->getActionController()->getRenderScript()) {
                 $this->renderScript($script);
             }
         }
     }
     parent::postDispatch();
     // append custom styles to response body
     if ($this->getActionController() instanceof FrontendController) {
         $doc = $this->getActionController()->getDocument();
         if (Tool::isHtmlResponse($this->getResponse()) && $doc && method_exists($doc, "getCss") && $doc->getCss() && !$this->getRequest()->getParam("pimcore_editmode")) {
             $code = '<style type="text/css" id="pimcore_styles_' . $doc->getId() . '">';
             $code .= "\n\n" . $doc->getCss() . "\n\n";
             $code .= '</style>';
             $name = $this->getResponseSegment();
             $this->getResponse()->appendBody($code, $name);
         }
     }
 }
コード例 #13
0
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!Asset\Image\Thumbnail::isPictureElementInUse()) {
         return;
     }
     if (!Asset\Image\Thumbnail::getEmbedPicturePolyfill()) {
         return;
     }
     if (!\Pimcore\Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     // analytics
     $body = $this->getResponse()->getBody();
     // search for the end <head> tag, and insert the google analytics code before
     // this method is much faster than using simple_html_dom and uses less memory
     $code = '<script type="text/javascript" src="/pimcore/static/js/frontend/picturePolyfill.min.js" defer></script>';
     $headEndPosition = stripos($body, "</head>");
     if ($headEndPosition !== false) {
         $body = substr_replace($body, $code . "</head>", $headEndPosition, 7);
     }
     $this->getResponse()->setBody($body);
 }
コード例 #14
0
ファイル: CDN.php プロジェクト: ChristophWurst/pimcore
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if ($this->enabled) {
         include_once "simple_html_dom.php";
         $body = $this->getResponse()->getBody();
         $html = str_get_html($body);
         if ($html) {
             $elements = $html->find("link[rel=stylesheet], img, script[src]");
             foreach ($elements as $element) {
                 if ($element->tag == "link") {
                     if ($this->pathMatch($element->href)) {
                         $element->href = $this->rewritePath($element->href);
                     }
                 } else {
                     if ($element->tag == "img") {
                         if ($this->pathMatch($element->src)) {
                             $element->src = $this->rewritePath($element->src);
                         }
                     } else {
                         if ($element->tag == "script") {
                             if ($this->pathMatch($element->src)) {
                                 $element->src = $this->rewritePath($element->src);
                             }
                         }
                     }
                 }
             }
             $body = $html->save();
             $html->clear();
             unset($html);
             $this->getResponse()->setBody($body);
             // save storage
             CacheManager::save($this->cachedItems, self::cacheKey, array(), 3600);
         }
     }
 }
コード例 #15
0
ファイル: Targeting.php プロジェクト: quorak/pimcore
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if ($this->enabled) {
         $targets = array();
         $personas = array();
         $dataPush = array("personas" => $this->personas, "method" => strtolower($this->getRequest()->getMethod()));
         if (count($this->events) > 0) {
             $dataPush["events"] = $this->events;
         }
         if ($this->document instanceof Document\Page && !Model\Staticroute::getCurrentRoute()) {
             $dataPush["document"] = $this->document->getId();
             if ($this->document->getPersonas()) {
                 if ($_GET["_ptp"]) {
                     // if a special version is requested only return this id as target group for this page
                     $dataPush["personas"][] = (int) $_GET["_ptp"];
                 } else {
                     $docPersonas = explode(",", trim($this->document->getPersonas(), " ,"));
                     //  cast the values to int
                     array_walk($docPersonas, function (&$value) {
                         $value = (int) trim($value);
                     });
                     $dataPush["personas"] = array_merge($dataPush["personas"], $docPersonas);
                 }
             }
             // check for persona specific variants of this page
             $personaVariants = array();
             foreach ($this->document->getElements() as $key => $tag) {
                 if (preg_match("/^persona_-([0-9]+)-_/", $key, $matches)) {
                     $id = (int) $matches[1];
                     if (Model\Tool\Targeting\Persona::isIdActive($id)) {
                         $personaVariants[] = $id;
                     }
                 }
             }
             if (!empty($personaVariants)) {
                 $personaVariants = array_values(array_unique($personaVariants));
                 $dataPush["personaPageVariants"] = $personaVariants;
             }
         }
         // no duplicates
         $dataPush["personas"] = array_unique($dataPush["personas"]);
         $activePersonas = array();
         foreach ($dataPush["personas"] as $id) {
             if (Model\Tool\Targeting\Persona::isIdActive($id)) {
                 $activePersonas[] = $id;
             }
         }
         $dataPush["personas"] = $activePersonas;
         if ($this->document) {
             // @TODO: cache this
             $list = new Model\Tool\Targeting\Rule\Listing();
             $list->setCondition("active = 1");
             foreach ($list->load() as $target) {
                 $redirectUrl = $target->getActions()->getRedirectUrl();
                 if (is_numeric($redirectUrl)) {
                     $doc = \Document::getById($redirectUrl);
                     if ($doc instanceof \Document) {
                         $target->getActions()->redirectUrl = $doc->getFullPath();
                     }
                 }
                 $targets[] = $target;
             }
             $list = new Model\Tool\Targeting\Persona\Listing();
             $list->setCondition("active = 1");
             foreach ($list->load() as $persona) {
                 $personas[] = $persona;
             }
         }
         $code = '<script type="text/javascript" src="/pimcore/static/js/frontend/geoip.js/"></script>';
         $code .= '<script type="text/javascript">';
         $code .= 'var pimcore = pimcore || {};';
         $code .= 'pimcore["targeting"] = {};';
         $code .= 'pimcore["targeting"]["dataPush"] = ' . \Zend_Json::encode($dataPush) . ';';
         $code .= 'pimcore["targeting"]["targetingRules"] = ' . \Zend_Json::encode($targets) . ';';
         $code .= 'pimcore["targeting"]["personas"] = ' . \Zend_Json::encode($personas) . ';';
         $code .= '</script>';
         $code .= '<script type="text/javascript" src="/pimcore/static/js/frontend/targeting.js"></script>';
         $code .= "\n";
         // analytics
         $body = $this->getResponse()->getBody();
         // search for the end <head> tag, and insert the google analytics code before
         // this method is much faster than using simple_html_dom and uses less memory
         $headEndPosition = stripos($body, "<head>");
         if ($headEndPosition !== false) {
             $body = substr_replace($body, "<head>\n" . $code, $headEndPosition, 7);
         }
         $this->getResponse()->setBody($body);
     }
 }
コード例 #16
0
ファイル: TagManagement.php プロジェクト: jansarmir/pimcore
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!\Pimcore\Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     $list = new Tag\Config\Listing();
     $tags = $list->load();
     if (empty($tags)) {
         return;
     }
     $html = null;
     $body = $this->getResponse()->getBody();
     $requestParams = array_merge($_GET, $_POST);
     foreach ($tags as $tag) {
         $method = strtolower($tag->getHttpMethod());
         $pattern = $tag->getUrlPattern();
         $textPattern = $tag->getTextPattern();
         // site check
         if (Site::isSiteRequest() && $tag->getSiteId()) {
             if (Site::getCurrentSite()->getId() != $tag->getSiteId()) {
                 continue;
             }
         } else {
             if (!Site::isSiteRequest() && $tag->getSiteId()) {
                 continue;
             }
         }
         $requestPath = rtrim($this->getRequest()->getPathInfo(), "/");
         if (($method == strtolower($this->getRequest()->getMethod()) || empty($method)) && (empty($pattern) || @preg_match($pattern, $requestPath)) && (empty($textPattern) || strpos($body, $textPattern) !== false)) {
             $paramsValid = true;
             foreach ($tag->getParams() as $param) {
                 if (!empty($param["name"])) {
                     if (!empty($param["value"])) {
                         if (!array_key_exists($param["name"], $requestParams) || $requestParams[$param["name"]] != $param["value"]) {
                             $paramsValid = false;
                         }
                     } else {
                         if (!array_key_exists($param["name"], $requestParams)) {
                             $paramsValid = false;
                         }
                     }
                 }
             }
             if (is_array($tag->getItems()) && $paramsValid) {
                 foreach ($tag->getItems() as $item) {
                     if (!empty($item["element"]) && !empty($item["code"]) && !empty($item["position"])) {
                         if (!$html) {
                             include_once "simple_html_dom.php";
                             $html = str_get_html($body);
                         }
                         if ($html) {
                             $element = $html->find($item["element"], 0);
                             if ($element) {
                                 if ($item["position"] == "end") {
                                     $element->innertext = $element->innertext . "\n\n" . $item["code"] . "\n\n";
                                 } else {
                                     // beginning
                                     $element->innertext = "\n\n" . $item["code"] . "\n\n" . $element->innertext;
                                 }
                                 // we havve to reinitialize the html object, otherwise it causes problems with nested child selectors
                                 $body = $html->save();
                                 $html->clear();
                                 unset($html);
                                 $html = null;
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($html && method_exists($html, "clear")) {
         $html->clear();
         unset($html);
     }
     $this->getResponse()->setBody($body);
 }