/** * includes a document * * @param $include * @param array $params * @return string */ public function inc($include, $params = null, $cacheEnabled = true) { if (!is_array($params)) { $params = []; } // check if output-cache is enabled, if so, we're also using the cache here $cacheKey = null; $cacheConfig = false; if ($cacheEnabled) { if ($cacheConfig = Tool\Frontend::isOutputCacheEnabled()) { // cleanup params to avoid serializing Element\ElementInterface objects $cacheParams = $params; $cacheParams["~~include-document"] = $include; array_walk($cacheParams, function (&$value, $key) { if ($value instanceof Element\ElementInterface) { $value = $value->getId(); } elseif (is_object($value) && method_exists($value, "__toString")) { $value = (string) $value; } }); $cacheKey = "tag_inc__" . md5(serialize($cacheParams)); if ($content = Cache::load($cacheKey)) { return $content; } } } $editmodeBackup = \Zend_Registry::get("pimcore_editmode"); \Zend_Registry::set("pimcore_editmode", false); $includeBak = $include; // this is if $this->inc is called eg. with $this->href() as argument if (!$include instanceof Model\Document\PageSnippet && is_object($include) && method_exists($include, "__toString")) { $include = (string) $include; } if (is_string($include)) { try { $include = Model\Document::getByPath($include); } catch (\Exception $e) { $include = $includeBak; } } elseif (is_numeric($include)) { try { $include = Model\Document::getById($include); } catch (\Exception $e) { $include = $includeBak; } } $params = array_merge($params, array("document" => $include)); $content = ""; if ($include instanceof Model\Document\PageSnippet && $include->isPublished()) { if ($include->getAction() && $include->getController()) { $content = $this->action($include->getAction(), $include->getController(), $include->getModule(), $params); } elseif ($include->getTemplate()) { $content = $this->action("default", "default", null, $params); } // in editmode, we need to parse the returned html from the document include // add a class and the pimcore id / type so that it can be opened in editmode using the context menu // if there's no first level HTML container => add one (wrapper) if ($this->editmode) { include_once "simple_html_dom.php"; $editmodeClass = " pimcore_editable pimcore_tag_inc "; // this is if the content that is included does already contain markup/html // this is needed by the editmode to highlight included documents if ($html = str_get_html($content)) { $childs = $html->find("*"); if (is_array($childs)) { foreach ($childs as $child) { $child->class = $child->class . $editmodeClass; $child->pimcore_type = $include->getType(); $child->pimcore_id = $include->getId(); } } $content = $html->save(); $html->clear(); unset($html); } else { // add a div container if the include doesn't contain markup/html $content = '<div class="' . $editmodeClass . '" pimcore_id="' . $include->getId() . '" pimcore_type="' . $include->getType() . '">' . $content . '</div>'; } } // we need to add a component id to all first level html containers $componentId = ""; if ($this->document instanceof Model\Document) { $componentId .= 'document:' . $this->document->getId() . '.'; } $componentId .= 'type:inc.name:' . $include->getId(); $content = \Pimcore\Tool\Frontend::addComponentIdToHtml($content, $componentId); } \Zend_Registry::set("pimcore_editmode", $editmodeBackup); // write contents to the cache, if output-cache is enabled if ($cacheConfig) { Cache::save($content, $cacheKey, array("output", "output_inline"), $cacheConfig["lifetime"]); } return $content; }
/** * @see Document\Tag\TagInterface::frontend * @return string */ public function frontend() { if (!$this->options["controller"] && !$this->options["action"]) { $this->options["controller"] = Config::getSystemConfig()->documents->default_controller; $this->options["action"] = Config::getSystemConfig()->documents->default_action; } $document = null; if ($this->o instanceof Document) { $document = $this->o; } if (method_exists($this->o, "isPublished")) { if (!$this->o->isPublished()) { return ""; } } if ($this->o instanceof Element\ElementInterface) { $blockparams = array("action", "controller", "module", "template"); $params = array("template" => isset($this->options["template"]) ? $this->options["template"] : null, "object" => $this->o, "element" => $this->o, "document" => $document, "id" => $this->id, "type" => $this->type, "subtype" => $this->subtype, "pimcore_request_source" => "renderlet", "disableBlockClearing" => true); foreach ($this->options as $key => $value) { if (!array_key_exists($key, $params) && !in_array($key, $blockparams)) { $params[$key] = $value; } } if ($this->getView() != null) { try { $content = $this->getView()->action($this->options["action"], $this->options["controller"], isset($this->options["module"]) ? $this->options["module"] : null, $params); // we need to add a component id to all first level html containers $componentId = 'document:' . $this->getDocumentId() . '.type:tag-renderlet.name:' . $this->type . "-" . $this->subtype . "-" . $this->id; $content = \Pimcore\Tool\Frontend::addComponentIdToHtml($content, $componentId); return $content; } catch (\Exception $e) { if (\Pimcore::inDebugMode()) { return "ERROR: " . $e->getMessage() . " (for details see debug.log)"; } \Logger::error($e); } } } }
/** * @see Document\Tag\TagInterface::frontend * @return string */ public function frontend() { if ($this->getView() instanceof \Zend_View) { try { if ($this->snippet instanceof Document\Snippet) { $params = $this->options; $params["document"] = $this->snippet; if ($this->snippet->isPublished()) { // check if output-cache is enabled, if so, we're also using the cache here $cacheKey = null; if ($cacheConfig = \Pimcore\Tool\Frontend::isOutputCacheEnabled()) { // cleanup params to avoid serializing Element\ElementInterface objects $cacheParams = $params; array_walk($cacheParams, function (&$value, $key) { if ($value instanceof Model\Element\ElementInterface) { $value = $value->getId(); } }); $cacheKey = "tag_snippet__" . md5(serialize($cacheParams)); if ($content = Cache::load($cacheKey)) { return $content; } } $content = $this->getView()->action($this->snippet->getAction(), $this->snippet->getController(), $this->snippet->getModule(), $params); // write contents to the cache, if output-cache is enabled if ($cacheConfig) { Cache::save($content, $cacheKey, array("output", "output_inline"), $cacheConfig["lifetime"]); } // we need to add a component id to all first level html containers $componentId = 'document:' . $this->getDocumentId() . '.type:tag-snippet.name:' . $this->snippet->getId(); $content = \Pimcore\Tool\Frontend::addComponentIdToHtml($content, $componentId); return $content; } return ""; } } catch (\Exception $e) { if (\Pimcore::inDebugMode()) { return "ERROR: " . $e->getMessage() . " (for details see debug.log)"; } \Logger::error($e); } } else { return null; } }