Ejemplo n.º 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);
            }
        }
    }
Ejemplo n.º 2
0
 /**
  * @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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
         }
     }
 }
Ejemplo n.º 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);
            }
        }
    }
Ejemplo n.º 6
0
 /**
  *
  */
 public function getFullPath()
 {
     $path = parent::getFullPath();
     // do not use pretty url's when in admin, the current document is wrapped by a hardlink or this document isn't in the current site
     if (!\Pimcore::inAdmin() && !$this instanceof Hardlink\Wrapper\WrapperInterface && \Pimcore\Tool\Frontend::isDocumentInCurrentSite($this)) {
         // check for a pretty url
         $prettyUrl = $this->getPrettyUrl();
         if (!empty($prettyUrl) && strlen($prettyUrl) > 1) {
             return $prettyUrl;
         }
     }
     return $path;
 }
Ejemplo n.º 7
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);
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * @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);
             }
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * @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, ["output", "output_inline"], $cacheConfig["lifetime"]);
                     }
                     return $content;
                 }
                 return "";
             }
         } catch (\Exception $e) {
             if (\Pimcore::inDebugMode()) {
                 return "ERROR: " . $e->getMessage() . " (for details see debug.log)";
             }
             \Logger::error($e);
         }
     } else {
         return null;
     }
 }
Ejemplo n.º 10
0
 /**
  * Returns the full path of the document including the key (path+key)
  *
  * @return string
  */
 public function getFullPath()
 {
     // check if this document is also the site root, if so return /
     try {
         if (Site::isSiteRequest()) {
             $site = Site::getCurrentSite();
             if ($site instanceof Site) {
                 if ($site->getRootDocument()->getId() == $this->getId()) {
                     return "/";
                 }
             }
         }
     } catch (\Exception $e) {
         \Logger::error($e);
     }
     // @TODO please forgive me, this is the dirtiest hack I've ever made :(
     // if you got confused by this functionality drop me a line and I'll buy you some beers :)
     // this is for the case that a link points to a document outside of the current site
     // in this case we look for a hardlink in the current site which points to the current document
     // why this could happen: we have 2 sites, in one site there's a hardlink to the other site and on a page inside
     // the hardlink there are snippets embedded and this snippets have links pointing to a document which is also
     // inside the hardlink scope, but this is an ID link, so we cannot rewrite the link the usual way because in the
     // snippet / link we don't know anymore that whe a inside a hardlink wrapped document
     if (!\Pimcore::inAdmin() && Site::isSiteRequest() && !FrontendTool::isDocumentInCurrentSite($this)) {
         $documentService = new Document\Service();
         $parent = $this;
         while ($parent) {
             if ($hardlinkId = $documentService->getDocumentIdFromHardlinkInSameSite(Site::getCurrentSite(), $parent)) {
                 $hardlink = Document::getById($hardlinkId);
                 if (FrontendTool::isDocumentInCurrentSite($hardlink)) {
                     $siteRootPath = Site::getCurrentSite()->getRootPath();
                     $siteRootPath = preg_quote($siteRootPath);
                     $hardlinkPath = preg_replace("@^" . $siteRootPath . "@", "", $hardlink->getRealFullPath());
                     return preg_replace("@^" . preg_quote($parent->getRealFullPath()) . "@", $hardlinkPath, $this->getRealFullPath());
                     break;
                 }
             }
             $parent = $parent->getParent();
         }
         $config = \Pimcore\Config::getSystemConfig();
         $front = \Zend_Controller_Front::getInstance();
         $scheme = ($front->getRequest()->isSecure() ? "https" : "http") . "://";
         if ($site = FrontendTool::getSiteForDocument($this)) {
             if ($site->getMainDomain()) {
                 // check if current document is the root of the different site, if so, preg_replace below doesn't work, so just return /
                 if ($site->getRootDocument()->getId() == $this->getId()) {
                     return $scheme . $site->getMainDomain() . "/";
                 }
                 return $scheme . $site->getMainDomain() . preg_replace("@^" . $site->getRootPath() . "/@", "/", $this->getRealFullPath());
             }
         }
         if ($config->general->domain) {
             return $scheme . $config->general->domain . $this->getRealFullPath();
         }
     }
     $path = $this->getPath() . $this->getKey();
     return $path;
 }
Ejemplo n.º 11
0
 /**
  * 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;
 }
Ejemplo n.º 12
0
 /**
  * @static
  * @return mixed|\Zend_Config
  */
 public static function getWebsiteConfig()
 {
     if (\Zend_Registry::isRegistered("pimcore_config_website")) {
         $config = \Zend_Registry::get("pimcore_config_website");
     } else {
         $cacheKey = "website_config";
         $siteId = null;
         if (Model\Site::isSiteRequest()) {
             $siteId = Model\Site::getCurrentSite()->getId();
         } elseif (Tool::isFrontentRequestByAdmin()) {
             // this is necessary to set the correct settings in editmode/preview (using the main domain)
             $front = \Zend_Controller_Front::getInstance();
             $originDocument = $front->getRequest()->getParam("document");
             if ($originDocument) {
                 $site = Tool\Frontend::getSiteForDocument($originDocument);
                 if ($site) {
                     $siteId = $site->getId();
                 }
             }
         }
         if ($siteId) {
             $cacheKey = $cacheKey . "_site_" . $siteId;
         }
         if (!($config = Cache::load($cacheKey))) {
             $settingsArray = [];
             $cacheTags = ["website_config", "system", "config", "output"];
             $list = new Model\WebsiteSetting\Listing();
             $list = $list->load();
             foreach ($list as $item) {
                 $key = $item->getName();
                 $itemSiteId = $item->getSiteId();
                 if ($itemSiteId != 0 && $itemSiteId != $siteId) {
                     continue;
                 }
                 $s = null;
                 switch ($item->getType()) {
                     case "document":
                     case "asset":
                     case "object":
                         $s = Model\Element\Service::getElementById($item->getType(), $item->getData());
                         break;
                     case "bool":
                         $s = (bool) $item->getData();
                         break;
                     case "text":
                         $s = (string) $item->getData();
                         break;
                 }
                 if ($s instanceof Model\Element\ElementInterface) {
                     $cacheTags = $s->getCacheTags($cacheTags);
                 }
                 if (isset($s)) {
                     $settingsArray[$key] = $s;
                 }
             }
             $config = new \Zend_Config($settingsArray, true);
             Cache::save($config, $cacheKey, $cacheTags, null, 998);
         }
         self::setWebsiteConfig($config);
     }
     return $config;
 }
Ejemplo n.º 13
0
 /**
  * @param $string
  * @param null $document
  * @param null $hostUrl
  * @return mixed
  * @throws \Exception
  */
 public static function setAbsolutePaths($string, $document = null, $hostUrl = null)
 {
     if ($document && $document instanceof Model\Document == false) {
         throw new \Exception('$document has to be an instance of Document');
     }
     $replacePrefix = "";
     if (!$hostUrl && $document) {
         // try to determine if the newsletter is within a site
         $site = \Pimcore\Tool\Frontend::getSiteForDocument($document);
         if ($site) {
             $hostUrl = "http://" . $site->getMainDomain();
             $replacePrefix = $site->getRootPath();
         }
         // fallback
         if (!$hostUrl) {
             $hostUrl = \Pimcore\Tool::getHostUrl();
         }
     }
     //matches all links
     preg_match_all("@(href|src)\\s*=[\"']([^(http|mailto|javascript|data:|#)].*?(css|jpe?g|gif|png)?)[\"']@is", $string, $matches);
     if (!empty($matches[0])) {
         foreach ($matches[0] as $key => $value) {
             $path = $matches[2][$key];
             if (strpos($path, '//') === 0) {
                 $absolutePath = "http:" . $path;
             } elseif (strpos($path, '/') === 0) {
                 $absolutePath = preg_replace("@^" . $replacePrefix . "/@", "/", $path);
                 $absolutePath = $hostUrl . $absolutePath;
             } else {
                 $absolutePath = $hostUrl . "/{$path}";
                 $netUrl = new \Net_URL2($absolutePath);
                 $absolutePath = $netUrl->getNormalizedURL();
             }
             $path = preg_quote($path);
             $string = preg_replace("!([\"']){$path}([\"'])!is", "\\1" . $absolutePath . "\\2", $string);
         }
     }
     preg_match_all("@srcset\\s*=[\"'](.*?)[\"']@is", $string, $matches);
     foreach ((array) $matches[1] as $i => $value) {
         $parts = explode(',', $value);
         foreach ($parts as $key => $v) {
             $parts[$key] = $hostUrl . trim($v);
         }
         $s = ' srcset="' . implode(', ', $parts) . '" ';
         if ($matches[0][$i]) {
             $string = str_replace($matches[0][$i], $s, $string);
         }
     }
     return $string;
 }
Ejemplo n.º 14
0
 public function getSecondImageAsset($thumbnail)
 {
     $images = $this->getImages();
     if ($images->items[1] && $images->items[1]->getImage()) {
         $secondImage = $images->items[1]->getImage();
         return $secondImage->getThumbnail($thumbnail);
     } elseif (\Pimcore\Tool\Frontend::getWebsiteConfig()->fallbackImage) {
         return \Pimcore\Tool\Frontend::getWebsiteConfig()->fallbackImagee->getThumbnail($thumbnail);
     } else {
         return null;
     }
 }
Ejemplo n.º 15
0
 /**
  *
  */
 public function content()
 {
     // create info object and assign it to the view
     $info = new Area\Info();
     try {
         $info->setTag($this);
         $info->setName($this->getName());
         $info->setId($this->currentIndex["type"]);
         $info->setIndex($this->current);
         $info->setPath(str_replace(PIMCORE_DOCUMENT_ROOT, "", $this->getPathForBrick($this->currentIndex["type"])));
         $info->setConfig($this->getBrickConfig($this->currentIndex["type"]));
     } catch (\Exception $e) {
         \Logger::err($e);
     }
     if ($this->getView() instanceof \Zend_View) {
         $this->getView()->brick = $info;
         $areas = $this->getAreaDirs();
         $view = $areas[$this->currentIndex["type"]] . "/view.php";
         $action = $areas[$this->currentIndex["type"]] . "/action.php";
         $edit = $areas[$this->currentIndex["type"]] . "/edit.php";
         $options = $this->getOptions();
         $params = array();
         if (is_array($options["params"]) && array_key_exists($this->currentIndex["type"], $options["params"])) {
             if (is_array($options["params"][$this->currentIndex["type"]])) {
                 $params = $options["params"][$this->currentIndex["type"]];
             }
         }
         // assign parameters to view
         foreach ($params as $key => $value) {
             $this->getView()->assign($key, $value);
         }
         // check for action file
         if (is_file($action)) {
             include_once $action;
             $actionClassFound = true;
             $actionClassname = "\\Pimcore\\Model\\Document\\Tag\\Area\\" . ucfirst($this->currentIndex["type"]);
             if (!class_exists($actionClassname, false)) {
                 // also check the legacy prefixed class name, as this is used by some plugins
                 $actionClassname = "\\Document_Tag_Area_" . ucfirst($this->currentIndex["type"]);
                 if (!class_exists($actionClassname, false)) {
                     $actionClassFound = false;
                 }
             }
             if ($actionClassFound) {
                 $actionObject = new $actionClassname();
                 if ($actionObject instanceof Area\AbstractArea) {
                     $actionObject->setView($this->getView());
                     $areaConfig = new \Zend_Config_Xml($areas[$this->currentIndex["type"]] . "/area.xml");
                     $actionObject->setConfig($areaConfig);
                     // params
                     $params = array_merge($this->view->getAllParams(), $params);
                     $actionObject->setParams($params);
                     if ($info) {
                         $actionObject->setBrick($info);
                     }
                     if (method_exists($actionObject, "action")) {
                         $actionObject->action();
                     }
                     $this->getView()->assign('actionObject', $actionObject);
                 }
             } else {
                 $this->getView()->assign('actionObject', null);
             }
         }
         if (is_file($view)) {
             $editmode = $this->getView()->editmode;
             if (method_exists($actionObject, "getBrickHtmlTagOpen")) {
                 echo $actionObject->getBrickHtmlTagOpen($this);
             } else {
                 $dataComponentAttribute = "";
                 if (\Pimcore\View::addComponentIds()) {
                     $dataComponentId = 'document:' . $this->getDocumentId() . '.type:tag-areablock.name:' . $this->getName() . "--" . ($this->getCurrentIndex() ? $this->getCurrentIndex() : "0") . "--" . $this->currentIndex["type"];
                     $crc = \Pimcore\Tool\Frontend::getCurrentRequestUrlCrc32();
                     if ($crc) {
                         $dataComponentId = "uri:" . $crc . "." . $dataComponentId;
                     }
                     $dataComponentAttribute = 'data-component-id="' . $dataComponentId . '"';
                 }
                 echo '<div class="pimcore_area_' . $this->currentIndex["type"] . ' pimcore_area_content" ' . $dataComponentAttribute . '>';
             }
             if (is_file($edit) && $editmode) {
                 echo '<div class="pimcore_area_edit_button_' . $this->getName() . ' pimcore_area_edit_button"></div>';
                 // forces the editmode in view.php independent if there's an edit.php or not
                 if (!array_key_exists("forceEditInView", $params) || !$params["forceEditInView"]) {
                     $this->getView()->editmode = false;
                 }
             }
             $this->getView()->template($view);
             if (is_file($edit) && $editmode) {
                 $this->getView()->editmode = true;
                 echo '<div class="pimcore_area_editmode_' . $this->getName() . ' pimcore_area_editmode pimcore_area_editmode_hidden">';
                 $this->getView()->template($edit);
                 echo '</div>';
             }
             if (method_exists($actionObject, "getBrickHtmlTagClose")) {
                 echo $actionObject->getBrickHtmlTagClose($this);
             } else {
                 echo '</div>';
             }
             if (is_object($actionObject) && method_exists($actionObject, "postRenderAction")) {
                 $actionObject->postRenderAction();
             }
         }
     }
     $this->current++;
 }
Ejemplo n.º 16
0
 /**
  * @param $element Document
  * @return array
  */
 protected function getTreeNodeConfig($element)
 {
     $childDocument = $element;
     $tmpDocument = ["id" => $childDocument->getId(), "idx" => intval($childDocument->getIndex()), "text" => $childDocument->getKey(), "type" => $childDocument->getType(), "path" => $childDocument->getRealFullPath(), "basePath" => $childDocument->getRealPath(), "locked" => $childDocument->isLocked(), "lockOwner" => $childDocument->getLocked() ? true : false, "published" => $childDocument->isPublished(), "elementType" => "document", "leaf" => true, "permissions" => ["view" => $childDocument->isAllowed("view"), "remove" => $childDocument->isAllowed("delete"), "settings" => $childDocument->isAllowed("settings"), "rename" => $childDocument->isAllowed("rename"), "publish" => $childDocument->isAllowed("publish"), "unpublish" => $childDocument->isAllowed("unpublish")]];
     // add icon
     $tmpDocument["iconCls"] = "pimcore_icon_" . $childDocument->getType();
     if (\Pimcore\Tool\Admin::isExtJS6()) {
         $tmpDocument["expandable"] = $childDocument->hasChilds();
         $tmpDocument["loaded"] = !$childDocument->hasChilds();
     }
     // set type specific settings
     if ($childDocument->getType() == "page") {
         $tmpDocument["leaf"] = false;
         $tmpDocument["expanded"] = $childDocument->hasNoChilds();
         $tmpDocument["permissions"]["create"] = $childDocument->isAllowed("create");
         $tmpDocument["iconCls"] = "pimcore_icon_page";
         // test for a site
         try {
             $site = Site::getByRootId($childDocument->getId());
             $tmpDocument["iconCls"] = "pimcore_icon_site";
             unset($site->rootDocument);
             $tmpDocument["site"] = $site;
         } catch (\Exception $e) {
         }
     } elseif ($childDocument->getType() == "folder" || $childDocument->getType() == "link" || $childDocument->getType() == "hardlink") {
         $tmpDocument["leaf"] = false;
         $tmpDocument["expanded"] = $childDocument->hasNoChilds();
         if ($childDocument->hasNoChilds() && $childDocument->getType() == "folder") {
             $tmpDocument["iconCls"] = "pimcore_icon_folder";
         }
         $tmpDocument["permissions"]["create"] = $childDocument->isAllowed("create");
     } elseif (method_exists($childDocument, "getTreeNodeConfig")) {
         $tmp = $childDocument->getTreeNodeConfig();
         $tmpDocument = array_merge($tmpDocument, $tmp);
     }
     $tmpDocument["qtipCfg"] = ["title" => "ID: " . $childDocument->getId(), "text" => "Type: " . $childDocument->getType()];
     // PREVIEWS temporary disabled, need's to be optimized some time
     if ($childDocument instanceof Document\Page && Config::getSystemConfig()->documents->generatepreview) {
         $thumbnailFile = PIMCORE_TEMPORARY_DIRECTORY . "/document-page-previews/document-page-screenshot-" . $childDocument->getId() . ".jpg";
         // only if the thumbnail exists and isn't out of time
         if (file_exists($thumbnailFile) && filemtime($thumbnailFile) > $childDocument->getModificationDate() - 20) {
             $thumbnailPath = str_replace(PIMCORE_DOCUMENT_ROOT, "", $thumbnailFile);
             $tmpDocument["thumbnail"] = $thumbnailPath;
         }
     }
     if ($childDocument instanceof Document\Page) {
         $tmpDocument["url"] = $childDocument->getFullPath();
         $site = Tool\Frontend::getSiteForDocument($childDocument);
         if ($site) {
             $tmpDocument["url"] = "http://" . $site->getMainDomain() . preg_replace("@^" . $site->getRootPath() . "/?@", "/", $childDocument->getRealFullPath());
         }
     }
     $tmpDocument["cls"] = "";
     if (!$childDocument->isPublished()) {
         $tmpDocument["cls"] .= "pimcore_unpublished ";
     }
     if ($childDocument->isLocked()) {
         $tmpDocument["cls"] .= "pimcore_treenode_locked ";
     }
     if ($childDocument->getLocked()) {
         $tmpDocument["cls"] .= "pimcore_treenode_lockOwner ";
     }
     return $tmpDocument;
 }