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)=\\\"([0-9a-z]+)\\\"/", "", $body); $this->getResponse()->setBody($body); }
public function dispatchLoopShutdown() { if (!Pimcore_Tool::isHtmlResponse($this->getResponse())) { return; } if ($this->enabled) { $body = $this->getResponse()->getBody(); $body = Minify_HTML::minify($body); $this->getResponse()->setBody($body); } }
public function dispatchLoopShutdown() { if (!Pimcore_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) { $styles = $html->find("link[rel=stylesheet], style[type=text/css]"); $stylesheetContent = ""; foreach ($styles as $style) { if ($style->tag == "style") { $stylesheetContent .= $style->innertext; } else { if ($style->media == "screen" || !$style->media) { $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); $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" media="screen" type="text/css" href="' . str_replace(PIMCORE_DOCUMENT_ROOT, "", $stylesheetPath) . '" />' . "\n"; } $body = $html->save(); $this->getResponse()->setBody($body); } } }
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(); } } }
public function dispatchLoopShutdown() { if (!Pimcore_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) { $scripts = $html->find("script[src]"); $scriptContent = ""; foreach ($scripts as $script) { $source = $script->src; $path = ""; if (is_file("file://" . PIMCORE_ASSET_DIRECTORY . $source)) { $path = "file://" . PIMCORE_ASSET_DIRECTORY . $source; } else { if (is_file("file://" . PIMCORE_DOCUMENT_ROOT . $source)) { $path = "file://" . PIMCORE_DOCUMENT_ROOT . $source; } } if (is_file($path)) { $scriptContent .= file_get_contents($path) . "\n\n"; if ($script->next_sibling()->tag != "script" || !$script->next_sibling()->src) { $scriptPath = $this->writeJsTempFile($scriptContent); $scriptContent = ""; $script->outertext = '<script type="text/javascript" src="' . str_replace(PIMCORE_DOCUMENT_ROOT, "", $scriptPath) . '"></script>' . "\n"; } else { $script->outertext = ""; } } else { if ($script->prev_sibling()->tag == "script") { if (strlen($scriptContent) > 0) { $scriptPath = $this->writeJsTempFile($scriptContent); $scriptContent = ""; $script->outertext = '<script type="text/javascript" src="' . str_replace(PIMCORE_DOCUMENT_ROOT, "", $scriptPath) . '"></script>' . "\n" . $script->outertext; } } } } $body = $html->save(); $this->getResponse()->setBody($body); } } }
public function dispatchLoopShutdown() { if (!Pimcore_Tool::isHtmlResponse($this->getResponse())) { return; } if ($this->enabled && ($code = Pimcore_Google_Analytics::getCode())) { // analytics include_once "simple_html_dom.php"; $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 = strpos($body, "</head>"); if ($headEndPosition !== false) { $body = substr_replace($body, $code . "</head>", $headEndPosition, 7); } $this->getResponse()->setBody($body); } }
public function dispatchLoopShutdown() { if (!Pimcore_Tool::isHtmlResponse($this->getResponse())) { return; } if ($this->enabled && Pimcore_Google_Analytics::isConfigured()) { // analytics include_once "simple_html_dom.php"; $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 = strpos($body, "</head>"); if ($headEndPosition !== false) { $body = substr_replace($body, Pimcore_Google_Analytics::getCode() . "</head>", $headEndPosition, 7); } // website optimizer if ($this->document) { $top = Pimcore_Google_Analytics::getOptimizerTop($this->document); $bottom = Pimcore_Google_Analytics::getOptimizerBottom($this->document); $conversion = Pimcore_Google_Analytics::getOptimizerConversion($this->document); if ($top || $bottom || $conversion) { $html = str_get_html($body); if ($html) { $body = $html->find("body", 0); if ($top && $bottom) { $body->innertext = $top . $body->innertext . $bottom; } else { if ($conversion) { $body->innertext = $body->innertext . $conversion; } else { if ($bottom) { $body->innertext = $body->innertext . $bottom; } } } $body = $html->save(); } } } $this->getResponse()->setBody($body); } }
public function dispatchLoopShutdown() { if (!Pimcore_Tool::isHtmlResponse($this->getResponse())) { return; } if ($this->supported && $this->enabled) { include_once "simple_html_dom.php"; $body = $this->getResponse()->getBody(); $html = str_get_html($body); if ($html) { $images = $html->find("img"); foreach ($images as $image) { $source = $image->src; $path = null; if (strpos($source, "http") === false) { // check asset folder 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 (is_file($path)) { if (@filesize($path) < 20000) { // only files < 20k because of IE8, 20000 because it's better to be a little bit under the limit try { $mimetype = MIME_Type::autoDetect($path); if (is_string($mimetype)) { $image->src = 'data:' . $mimetype . ';base64,' . base64_encode(file_get_contents($path)); } } catch (Exception $e) { } } } } } $body = $html->save(); $this->getResponse()->setBody($body); } } }
public function dispatchLoopShutdown() { if (!Pimcore_Tool::isHtmlResponse($this->getResponse())) { return; } $cacheKey = "outputfilter_tagmngt"; $tags = Pimcore_Model_Cache::load($cacheKey); if (!is_array($tags)) { $dir = Tool_Tag_Config::getWorkingDir(); $tags = array(); $files = scandir($dir); foreach ($files as $file) { if (strpos($file, ".xml")) { $name = str_replace(".xml", "", $file); $tags[] = Tool_Tag_Config::getByName($name); } } Pimcore_Model_Cache::save($tags, $cacheKey, array("tagmanagement"), null, 100); } if (empty($tags)) { return; } include_once "simple_html_dom.php"; $body = $this->getResponse()->getBody(); $html = str_get_html($body); $requestParams = array_merge($_GET, $_POST); if ($html) { foreach ($tags as $tag) { $method = strtolower($tag->getHttpMethod()); $pattern = $tag->getUrlPattern(); $textPattern = $tag->getTextPattern(); if (($method == strtolower($this->getRequest()->getMethod()) || empty($method)) && (empty($pattern) || @preg_match($pattern, $this->getRequest()->getRequestUri())) && (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"])) { $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 = str_get_html($body); } } } } } } $this->getResponse()->setBody($body); } }
public function dispatchLoopShutdown() { if (!Pimcore_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(); $this->getResponse()->setBody($body); // save storage Pimcore_Model_Cache::save($this->cachedItems, self::cacheKey, array(), 3600); } } }