/**
     *
     */
    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);
            }
        }
    }
 /**
  * @param null $site
  * @return bool
  */
 public static function getSiteConfig($site = null)
 {
     $siteKey = \Pimcore\Tool\Frontend::getSiteKey($site);
     if (Config::getReportConfig()->webmastertools->sites->{$siteKey}->verification) {
         return Config::getReportConfig()->webmastertools->sites->{$siteKey};
     }
     return false;
 }
Exemple #3
0
 /**
  * @param null $site
  * @return bool
  */
 public static function getSiteConfig($site = null)
 {
     $siteKey = \Pimcore\Tool\Frontend::getSiteKey($site);
     $config = Config::getReportConfig();
     if (!$config->analytics) {
         return false;
     }
     if ($config->analytics->sites->{$siteKey}) {
         return Config::getReportConfig()->analytics->sites->{$siteKey};
     }
     return false;
 }
Exemple #4
0
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     $code = (string) $this->getResponse()->getHttpResponseCode();
     if ($code && ($code[0] == "4" || $code[0] == "5")) {
         $this->writeLog();
         // put the response into the cache, this is read in Pimcore_Controller_Action_Frontend::checkForErrors()
         $responseData = $this->getResponse()->getBody();
         if (strlen($responseData) > 20) {
             $cacheKey = "error_page_response_" . \Pimcore\Tool\Frontend::getSiteKey();
             \Pimcore\Model\Cache::save($responseData, $cacheKey, array("output"), 900, 9992);
         }
     }
 }
Exemple #5
0
    /**
     *
     */
    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);
            }
        }
    }
Exemple #6
0
 /**
  * @throws \Zend_Controller_Response_Exception
  */
 public function checkForErrors()
 {
     if ($error = $this->getParam('error_handler')) {
         if ($error->exception) {
             if ($error->exception instanceof \Zend_Controller_Router_Exception || $error->exception instanceof \Zend_Controller_Action_Exception) {
                 header('HTTP/1.1 404 Not Found');
                 //$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
                 $this->getResponse()->setHttpResponseCode(404);
                 // check if the resource that wasn't found is a common static file
                 // for them we don't show the error page, as generating this is very heavy in terms of performance
                 if (preg_match("/\\.(js|css|png|jpe?g|gif|eot|ttf|woff|svg|ico|map|swf|txt)\$/", $this->getRequest()->getPathInfo())) {
                     echo "HTTP/1.1 404 Not Found\nFiltered by error handler (static file exception)";
                     exit;
                 }
             } else {
                 header('HTTP/1.1 503 Service Temporarily Unavailable');
                 //$this->getResponse()->setRawHeader('HTTP/1.1 503 Service Temporarily Unavailable');
                 $this->getResponse()->setHttpResponseCode(503);
             }
             \Logger::error("Unable to find URL: " . $_SERVER["REQUEST_URI"]);
             \Logger::error($error->exception);
             \Pimcore::getEventManager()->trigger("frontend.error", $this, ["exception" => $error->exception]);
             try {
                 // check if we have the error page already in the cache
                 // the cache is written in Pimcore\Controller\Plugin\HttpErrorLog::dispatchLoopShutdown()
                 $cacheKey = "error_page_response_" . \Pimcore\Tool\Frontend::getSiteKey();
                 if ($responseBody = \Pimcore\Cache::load($cacheKey)) {
                     $this->getResponse()->setBody($responseBody);
                     $this->getResponse()->sendResponse();
                     // write to http_error log
                     $errorLogPlugin = \Zend_Controller_Front::getInstance()->getPlugin("Pimcore\\Controller\\Plugin\\HttpErrorLog");
                     if ($errorLogPlugin) {
                         $errorLogPlugin->writeLog();
                     }
                     exit;
                 } else {
                     $document = \Zend_Registry::get("pimcore_error_document");
                     $this->setDocument($document);
                     $this->setParam("document", $document);
                     $this->disableLayout();
                     // http_error log writing is done in Pimcore_Controller_Plugin_HttpErrorLog in this case
                 }
             } catch (\Exception $e) {
                 $m = "Unable to load error document";
                 Tool::exitWithError($m);
             }
         }
     }
 }