public function tagManagementTreeAction() { $this->checkPermission("tag_snippet_management"); $tags = []; $list = new Tag\Config\Listing(); $items = $list->load(); foreach ($items as $item) { $tags[] = ["id" => $item->getName(), "text" => $item->getName()]; } $this->_helper->json($tags); }
/** * */ 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); }