Inheritance: extends AbstractModel
Esempio n. 1
0
 /**
  * @param \Zend_Controller_Request_Abstract $request
  * @throws mixed
  */
 protected function _handleError(\Zend_Controller_Request_Abstract $request)
 {
     // remove zend error handler
     $front = \Zend_Controller_Front::getInstance();
     $front->unregisterPlugin("Zend_Controller_Plugin_ErrorHandler");
     $response = $this->getResponse();
     if ($response->isException() && !$this->_isInsideErrorHandlerLoop) {
         // get errorpage
         try {
             // enable error handler
             $front->setParam('noErrorHandler', false);
             $errorPath = Config::getSystemConfig()->documents->error_pages->default;
             if (Site::isSiteRequest()) {
                 $site = Site::getCurrentSite();
                 $errorPath = $site->getErrorDocument();
             }
             if (empty($errorPath)) {
                 $errorPath = "/";
             }
             $document = Document::getByPath($errorPath);
             if (!$document instanceof Document\Page) {
                 // default is home
                 $document = Document::getById(1);
             }
             if ($document instanceof Document\Page) {
                 $params = Tool::getRoutingDefaults();
                 if ($module = $document->getModule()) {
                     $params["module"] = $module;
                 }
                 if ($controller = $document->getController()) {
                     $params["controller"] = $controller;
                     $params["action"] = "index";
                 }
                 if ($action = $document->getAction()) {
                     $params["action"] = $action;
                 }
                 $this->setErrorHandler($params);
                 $request->setParam("document", $document);
                 \Zend_Registry::set("pimcore_error_document", $document);
                 // ensure that a viewRenderer exists, and is enabled
                 if (!\Zend_Controller_Action_HelperBroker::hasHelper("viewRenderer")) {
                     $viewRenderer = new \Pimcore\Controller\Action\Helper\ViewRenderer();
                     \Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
                 }
                 $viewRenderer = \Zend_Controller_Action_HelperBroker::getExistingHelper("viewRenderer");
                 $viewRenderer->setNoRender(false);
                 if ($viewRenderer->view === null) {
                     $viewRenderer->initView(PIMCORE_WEBSITE_PATH . "/views");
                 }
             }
         } catch (\Exception $e) {
             \Logger::emergency("error page not found");
         }
     }
     // call default ZF error handler
     parent::_handleError($request);
 }
Esempio n. 2
0
 /**
  * Loads a list of thumanils for the specicifies parameters, returns an array of Thumbnail elements
  *
  * @return array
  */
 public function load()
 {
     $sites = [];
     $sitesData = $this->db->fetchCol("SELECT id FROM sites" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($sitesData as $siteData) {
         $sites[] = Model\Site::getById($siteData);
     }
     $this->model->setSites($sites);
     return $sites;
 }
Esempio n. 3
0
 /**
  * @param Document $document
  * @return bool
  */
 public static function isDocumentInCurrentSite($document)
 {
     if (Site::isSiteRequest()) {
         $site = Site::getCurrentSite();
         if ($site instanceof Site) {
             return self::isDocumentInSite($site, $document);
         }
     }
     return true;
 }
 private function getErrorDocument()
 {
     $config = Config::getSystemConfig();
     $errorDocPath = $config->documents->error_pages->default;
     if (Site::isSiteRequest()) {
         $site = Site::getCurrentSite();
         $errorDocPath = $site->getErrorDocument();
     }
     $errorDoc = Document::getByPath($errorDocPath);
     \Zend_Registry::set("pimcore_error_document", $errorDoc);
     return $errorDoc;
 }
Esempio n. 5
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();
             $cacheKey = $cacheKey . "_site_" . $siteId;
         }
         if (!($config = Cache::load($cacheKey))) {
             $settingsArray = array();
             $cacheTags = array("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;
 }
Esempio n. 6
0
 /**
  * @param \Zend_Controller_Request_Abstract $request
  */
 public function routeStartup(\Zend_Controller_Request_Abstract $request)
 {
     // this is a filter which checks for common used files (by browser, crawlers, ...) and prevent the default
     // error page, because this is more resource-intensive than exiting right here
     $found = false;
     foreach (self::$files as $pattern) {
         if (preg_match($pattern, $request->getPathInfo())) {
             $found = true;
             break;
         }
     }
     if ($found) {
         if ($request->getPathInfo() == "/robots.txt") {
             // check for site
             try {
                 $domain = Tool::getHostname();
                 $site = Site::getByDomain($domain);
             } catch (\Exception $e) {
             }
             $siteSuffix = "";
             if ($site instanceof Site) {
                 $siteSuffix = "-" . $site->getId();
             }
             // send correct headers
             header("Content-Type: text/plain; charset=utf8");
             while (@ob_end_flush()) {
             }
             // check for configured robots.txt in pimcore
             $robotsPath = PIMCORE_CONFIGURATION_DIRECTORY . "/robots" . $siteSuffix . ".txt";
             if (is_file($robotsPath)) {
                 readfile($robotsPath);
             } else {
                 echo "User-agent: *\nDisallow:";
                 // default behavior
             }
             exit;
         }
         // if no other rule matches, exit anyway with a 404, to prevent the error page to be shown
         header('HTTP/1.1 404 Not Found');
         echo "HTTP/1.1 404 Not Found\nFiltered by common files filter";
         exit;
     }
 }
Esempio n. 7
0
 /**
  * Checks for a suitable redirect
  * @throws Exception
  * @param bool $override
  * @return void
  */
 protected function checkForRedirect($override = false)
 {
     // not for admin requests
     if (Tool::isFrontentRequestByAdmin()) {
         return;
     }
     try {
         $front = \Zend_Controller_Front::getInstance();
         $config = Config::getSystemConfig();
         // get current site if available
         $sourceSite = null;
         if (Site::isSiteRequest()) {
             $sourceSite = Site::getCurrentSite();
         }
         $cacheKey = "system_route_redirect";
         if (empty($this->redirects) && !($this->redirects = Cache::load($cacheKey))) {
             $list = new Redirect\Listing();
             $list->setOrder("DESC");
             $list->setOrderKey("priority");
             $this->redirects = $list->load();
             Cache::save($this->redirects, $cacheKey, array("system", "redirect", "route"), null, 998);
         }
         $requestScheme = $_SERVER['HTTPS'] == 'on' ? \Zend_Controller_Request_Http::SCHEME_HTTPS : \Zend_Controller_Request_Http::SCHEME_HTTP;
         $matchRequestUri = $_SERVER["REQUEST_URI"];
         $matchUrl = $requestScheme . "://" . $_SERVER["HTTP_HOST"] . $matchRequestUri;
         foreach ($this->redirects as $redirect) {
             $matchAgainst = $matchRequestUri;
             if ($redirect->getSourceEntireUrl()) {
                 $matchAgainst = $matchUrl;
             }
             // if override is true the priority has to be 99 which means that overriding is ok
             if (!$override || $override && $redirect->getPriority() == 99) {
                 if (@preg_match($redirect->getSource(), $matchAgainst, $matches)) {
                     // check for a site
                     if ($sourceSite) {
                         if ($sourceSite->getId() != $redirect->getSourceSite()) {
                             continue;
                         }
                     }
                     array_shift($matches);
                     $target = $redirect->getTarget();
                     if (is_numeric($target)) {
                         $d = Document::getById($target);
                         if ($d instanceof Document\Page || $d instanceof Document\Link || $d instanceof Document\Hardlink) {
                             $target = $d->getFullPath();
                         } else {
                             \Logger::error("Target of redirect no found (Document-ID: " . $target . ")!");
                             continue;
                         }
                     }
                     // replace escaped % signs so that they didn't have effects to vsprintf (PIMCORE-1215)
                     $target = str_replace("\\%", "###URLENCODE_PLACEHOLDER###", $target);
                     $url = vsprintf($target, $matches);
                     $url = str_replace("###URLENCODE_PLACEHOLDER###", "%", $url);
                     // support for pcre backreferences
                     $url = replace_pcre_backreferences($url, $matches);
                     if ($redirect->getTargetSite() && !preg_match("@http(s)?://@i", $url)) {
                         try {
                             $targetSite = Site::getById($redirect->getTargetSite());
                             // if the target site is specified and and the target-path is starting at root (not absolute to site)
                             // the root-path will be replaced so that the page can be shown
                             $url = preg_replace("@^" . $targetSite->getRootPath() . "/@", "/", $url);
                             $url = $requestScheme . "://" . $targetSite->getMainDomain() . $url;
                         } catch (\Exception $e) {
                             \Logger::error("Site with ID " . $redirect->getTargetSite() . " not found.");
                             continue;
                         }
                     } else {
                         if (!preg_match("@http(s)?://@i", $url) && $config->general->domain && $redirect->getSourceEntireUrl()) {
                             // prepend the host and scheme to avoid infinite loops when using "domain" redirects
                             $url = ($front->getRequest()->isSecure() ? "https" : "http") . "://" . $config->general->domain . $url;
                         }
                     }
                     // pass-through parameters if specified
                     $queryString = $_SERVER["QUERY_STRING"];
                     if ($redirect->getPassThroughParameters() && !empty($queryString)) {
                         $glue = "?";
                         if (strpos($url, "?")) {
                             $glue = "&";
                         }
                         $url .= $glue;
                         $url .= $queryString;
                     }
                     header($redirect->getHttpStatus());
                     header("Location: " . $url, true, $redirect->getStatusCode());
                     // log all redirects to the redirect log
                     \Pimcore\Log\Simple::log("redirect", Tool::getAnonymizedClientIp() . " \t Custom-Redirect ID: " . $redirect->getId() . " , Source: " . $_SERVER["REQUEST_URI"] . " -> " . $url);
                     exit;
                 }
             }
         }
     } catch (\Exception $e) {
         // no suitable route found
     }
 }
Esempio n. 8
0
 /**
  * @param array $urlOptions
  * @param null $name
  * @param bool $reset
  * @param bool $encode
  * @return string|void
  * @throws \Exception
  */
 public function url(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
 {
     if (!$urlOptions) {
         $urlOptions = array();
     }
     // when using $name = false we don't use the default route (happens when $name = null / ZF default behavior)
     // but just the query string generation using the given parameters
     // eg. $this->url(["foo" => "bar"], false) => /?foo=bar
     if ($name === null) {
         if (Staticroute::getCurrentRoute() instanceof Staticroute) {
             $name = Staticroute::getCurrentRoute()->getName();
         }
     }
     $siteId = null;
     if (Site::isSiteRequest()) {
         $siteId = Site::getCurrentSite()->getId();
     }
     // check for a site in the options, if valid remove it from the options
     $hostname = null;
     if (isset($urlOptions["site"])) {
         $config = Config::getSystemConfig();
         $site = $urlOptions["site"];
         if (!empty($site)) {
             try {
                 $site = Site::getBy($site);
                 unset($urlOptions["site"]);
                 $hostname = $site->getMainDomain();
                 $siteId = $site->getId();
             } catch (\Exception $e) {
                 \Logger::warn("passed site doesn't exists");
                 \Logger::warn($e);
             }
         } else {
             if ($config->general->domain) {
                 $hostname = $config->general->domain;
             }
         }
     }
     if ($name && ($route = Staticroute::getByName($name, $siteId))) {
         // assemble the route / url in Staticroute::assemble()
         $url = $route->assemble($urlOptions, $reset, $encode);
         // if there's a site, prepend the host to the generated URL
         if ($hostname && !preg_match("/^http/i", $url)) {
             $url = "//" . $hostname . $url;
         }
         if (Config::getSystemConfig()->documents->allowcapitals == 'no') {
             $urlParts = parse_url($url);
             $url = str_replace($urlParts["path"], strtolower($urlParts["path"]), $url);
         }
         return $url;
     }
     // this is to add support for arrays as values for the default \Zend_View_Helper_Url
     $unset = array();
     foreach ($urlOptions as $optionName => $optionValues) {
         if (is_array($optionValues)) {
             foreach ($optionValues as $key => $value) {
                 $urlOptions[$optionName . "[" . $key . "]"] = $value;
             }
             $unset[] = $optionName;
         }
     }
     foreach ($unset as $optionName) {
         unset($urlOptions[$optionName]);
     }
     try {
         return parent::url($urlOptions, $name, $reset, $encode);
     } catch (\Exception $e) {
         if (Tool::isFrontentRequestByAdmin()) {
             // routes can be site specific, so in editmode it's possible that we don't get
             // the right route (sites are not registered in editmode), so we cannot throw exceptions there
             return "ERROR_IN_YOUR_URL_CONFIGURATION:~ROUTE--" . $name . "--DOES_NOT_EXIST";
         }
         throw new \Exception("Route '" . $name . "' for building the URL not found");
     }
 }
Esempio n. 9
0
 /**
  * @param array $urlOptions
  * @param null $name
  * @param bool $reset
  * @param bool $encode
  * @return string|void
  * @throws \Exception
  */
 public function url(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
 {
     if (!$urlOptions) {
         $urlOptions = array();
     }
     if (!$name) {
         if (Staticroute::getCurrentRoute() instanceof Staticroute) {
             $name = Staticroute::getCurrentRoute()->getName();
         }
     }
     $siteId = null;
     if (Site::isSiteRequest()) {
         $siteId = Site::getCurrentSite()->getId();
     }
     // check for a site in the options, if valid remove it from the options
     $hostname = null;
     if (isset($urlOptions["site"])) {
         $config = Config::getSystemConfig();
         $site = $urlOptions["site"];
         if (!empty($site)) {
             try {
                 $site = Site::getBy($site);
                 unset($urlOptions["site"]);
                 $hostname = $site->getMainDomain();
                 $siteId = $site->getId();
             } catch (\Exception $e) {
                 \Logger::warn("passed site doesn't exists");
                 \Logger::warn($e);
             }
         } else {
             if ($config->general->domain) {
                 $hostname = $config->general->domain;
             }
         }
     }
     if ($name && ($route = Staticroute::getByName($name, $siteId))) {
         // assemble the route / url in Staticroute::assemble()
         $url = $route->assemble($urlOptions, $reset, $encode);
         // if there's a site, prepend the host to the generated URL
         if ($hostname && !preg_match("/^http/i", $url)) {
             $url = "//" . $hostname . $url;
         }
         if (Config::getSystemConfig()->documents->allowcapitals == 'no') {
             $urlParts = parse_url($url);
             $url = str_replace($urlParts["path"], strtolower($urlParts["path"]), $url);
         }
         return $url;
     }
     // this is to add support for arrays as values for the default \Zend_View_Helper_Url
     $unset = array();
     foreach ($urlOptions as $optionName => $optionValues) {
         if (is_array($optionValues)) {
             foreach ($optionValues as $key => $value) {
                 $urlOptions[$optionName . "[" . $key . "]"] = $value;
             }
             $unset[] = $optionName;
         }
     }
     foreach ($unset as $optionName) {
         unset($urlOptions[$optionName]);
     }
     try {
         return parent::url($urlOptions, $name, $reset, $encode);
     } catch (\Exception $e) {
         throw new \Exception("Route '" . $name . "' for building the URL not found");
     }
 }
Esempio n. 10
0
 /**
  * @throws \Zend_Controller_Router_Exception
  */
 public function init()
 {
     // this is only executed once per request (first request)
     if (self::$isInitial) {
         \Pimcore::getEventManager()->trigger("frontend.controller.preInit", $this);
     }
     parent::init();
     // log exceptions if handled by error_handler
     $this->checkForErrors();
     // general definitions
     if (self::$isInitial) {
         \Pimcore::unsetAdminMode();
         Document::setHideUnpublished(true);
         Object\AbstractObject::setHideUnpublished(true);
         Object\AbstractObject::setGetInheritedValues(true);
         Object\Localizedfield::setGetFallbackValues(true);
     }
     // assign variables
     $this->view->controller = $this;
     // init website config
     $config = Config::getWebsiteConfig();
     $this->config = $config;
     $this->view->config = $config;
     $document = $this->getParam("document");
     if (!$document instanceof Document) {
         \Zend_Registry::set("pimcore_editmode", false);
         $this->editmode = false;
         $this->view->editmode = false;
         self::$isInitial = false;
         // check for a locale first, and set it if available
         if ($this->getParam("pimcore_parentDocument")) {
             // this is a special exception for renderlets in editmode (ajax request), because they depend on the locale of the parent document
             // otherwise there'll be notices like:  Notice: 'No translation for the language 'XX' available.'
             if ($parentDocument = Document::getById($this->getParam("pimcore_parentDocument"))) {
                 if ($parentDocument->getProperty("language")) {
                     $this->setLocaleFromDocument($parentDocument->getProperty("language"));
                 }
             }
         }
         // no document available, continue, ...
         return;
     } else {
         $this->setDocument($document);
         // register global locale if the document has the system property "language"
         if ($this->getDocument()->getProperty("language")) {
             $this->setLocaleFromDocument($this->getDocument()->getProperty("language"));
         }
         if (self::$isInitial) {
             // append meta-data to the headMeta() view helper,  if it is a document-request
             if (!Model\Staticroute::getCurrentRoute() && $this->getDocument() instanceof Document\Page) {
                 if (is_array($this->getDocument()->getMetaData())) {
                     foreach ($this->getDocument()->getMetaData() as $meta) {
                         $this->view->headMeta()->addRaw($meta);
                     }
                 }
             }
         }
     }
     // this is only executed once per request (first request)
     if (self::$isInitial) {
         // contains the logged in user if necessary
         $user = null;
         // default is to set the editmode to false, is enabled later if necessary
         \Zend_Registry::set("pimcore_editmode", false);
         if (Tool::isFrontentRequestByAdmin()) {
             $this->disableBrowserCache();
             // start admin session & get logged in user
             $user = Authentication::authenticateSession();
         }
         if (\Pimcore::inDebugMode()) {
             $this->disableBrowserCache();
         }
         if (!$this->document->isPublished()) {
             if (Tool::isFrontentRequestByAdmin()) {
                 if (!$user) {
                     throw new \Zend_Controller_Router_Exception("access denied for " . $this->document->getFullPath());
                 }
             } else {
                 throw new \Zend_Controller_Router_Exception("access denied for " . $this->document->getFullPath());
             }
         }
         // logged in users only
         if ($user) {
             // set the user to registry so that it is available via \Pimcore\Tool\Admin::getCurrentUser();
             \Zend_Registry::set("pimcore_admin_user", $user);
             // document editmode
             if ($this->getParam("pimcore_editmode")) {
                 \Zend_Registry::set("pimcore_editmode", true);
                 // check if there is the document in the session
                 $docKey = "document_" . $this->getDocument()->getId();
                 $docSession = Session::getReadOnly("pimcore_documents");
                 if ($docSession->{$docKey}) {
                     // if there is a document in the session use it
                     $this->setDocument($docSession->{$docKey});
                 } else {
                     // set the latest available version for editmode if there is no doc in the session
                     $latestVersion = $this->getDocument()->getLatestVersion();
                     if ($latestVersion) {
                         $latestDoc = $latestVersion->loadData();
                         if ($latestDoc instanceof Document\PageSnippet) {
                             $this->setDocument($latestDoc);
                         }
                     }
                 }
                 // register editmode plugin
                 $front = \Zend_Controller_Front::getInstance();
                 $front->registerPlugin(new \Pimcore\Controller\Plugin\Frontend\Editmode($this), 1000);
             }
             // document preview
             if ($this->getParam("pimcore_preview")) {
                 // get document from session
                 $docKey = "document_" . $this->getParam("document")->getId();
                 $docSession = Session::getReadOnly("pimcore_documents");
                 if ($docSession->{$docKey}) {
                     $this->setDocument($docSession->{$docKey});
                 }
             }
             // object preview
             if ($this->getParam("pimcore_object_preview")) {
                 $key = "object_" . $this->getParam("pimcore_object_preview");
                 $session = Session::getReadOnly("pimcore_objects");
                 if ($session->{$key}) {
                     $object = $session->{$key};
                     // add the object to the registry so every call to Object::getById() will return this object instead of the real one
                     \Zend_Registry::set("object_" . $object->getId(), $object);
                 }
             }
             // for version preview
             if ($this->getParam("pimcore_version")) {
                 // only get version data at the first call || because of embedded Snippets ...
                 if (!\Zend_Registry::isRegistered("pimcore_version_active")) {
                     $version = Model\Version::getById($this->getParam("pimcore_version"));
                     $this->setDocument($version->getData());
                     \Zend_Registry::set("pimcore_version_active", true);
                 }
             }
         }
         // for public versions
         if ($this->getParam("v")) {
             try {
                 $version = Model\Version::getById($this->getParam("v"));
                 if ($version->getPublic()) {
                     $this->setDocument($version->getData());
                 }
             } catch (\Exception $e) {
             }
         }
         // check for persona
         if ($this->getDocument() instanceof Document\Page) {
             $this->getDocument()->setUsePersona(null);
             // reset because of preview and editmode (saved in session)
             if ($this->getParam("_ptp") && self::$isInitial) {
                 $this->getDocument()->setUsePersona($this->getParam("_ptp"));
             }
         }
         // check if document is a wrapped hardlink, if this is the case send a rel=canonical header to the source document
         if ($this->getDocument() instanceof Document\Hardlink\Wrapper\WrapperInterface) {
             // get the cononical (source) document
             $hardlinkCanonicalSourceDocument = Document::getById($this->getDocument()->getId());
             $request = $this->getRequest();
             $canonical = null;
             if (\Pimcore\Tool\Frontend::isDocumentInCurrentSite($hardlinkCanonicalSourceDocument)) {
                 $canonical = $request->getScheme() . "://" . $request->getHttpHost() . $hardlinkCanonicalSourceDocument->getFullPath();
             } elseif (Model\Site::isSiteRequest()) {
                 $sourceSite = \Pimcore\Tool\Frontend::getSiteForDocument($hardlinkCanonicalSourceDocument);
                 if ($sourceSite) {
                     if ($sourceSite->getMainDomain()) {
                         $sourceSiteRelPath = preg_replace("@^" . preg_quote($sourceSite->getRootPath(), "@") . "@", "", $hardlinkCanonicalSourceDocument->getRealFullPath());
                         $canonical = $request->getScheme() . "://" . $sourceSite->getMainDomain() . $sourceSiteRelPath;
                     }
                 }
             }
             if ($canonical) {
                 $this->getResponse()->setHeader("Link", '<' . $canonical . '>; rel="canonical"');
             }
         }
         \Pimcore::getEventManager()->trigger("frontend.controller.postInit", $this);
     }
     // set some parameters
     $this->editmode = \Zend_Registry::get("pimcore_editmode");
     $this->view->editmode = \Zend_Registry::get("pimcore_editmode");
     self::$isInitial = false;
 }
Esempio n. 11
0
 /**
  * @param $element
  * @return array
  */
 protected function getTreeNodeConfig($element)
 {
     $childDocument = $element;
     $tmpDocument = array("id" => $childDocument->getId(), "text" => $childDocument->getKey(), "type" => $childDocument->getType(), "path" => $childDocument->getFullPath(), "basePath" => $childDocument->getPath(), "locked" => $childDocument->isLocked(), "lockOwner" => $childDocument->getLocked() ? true : false, "published" => $childDocument->isPublished(), "elementType" => "document", "leaf" => true, "permissions" => array("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::isExtJS5()) {
         $tmpDocument["expandable"] = $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) {
         }
     } else {
         if ($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");
         } else {
             if (method_exists($childDocument, "getTreeNodeConfig")) {
                 $tmp = $childDocument->getTreeNodeConfig();
                 $tmpDocument = array_merge($tmpDocument, $tmp);
             }
         }
     }
     $tmpDocument["qtipCfg"] = array("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;
         }
     }
     $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;
 }
Esempio n. 12
0
 /**
  * @param Site $site
  * @param Document $document
  * @return int
  */
 public function getDocumentIdFromHardlinkInSameSite(Site $site, Document $document)
 {
     return $this->db->fetchOne("SELECT documents.id FROM documents\n            LEFT JOIN documents_hardlink ON documents.id = documents_hardlink.id\n            WHERE documents_hardlink.sourceId = ? AND documents.path LIKE ?", array($document->getId(), $site->getRootPath() . "/%"));
 }
Esempio n. 13
0
 /**
  * @param string $path
  * @param array $params
  * @return array|bool
  * @throws \Exception
  */
 public function match($path, $params = [])
 {
     if (@preg_match($this->getPattern(), $path)) {
         // check for site
         if ($this->getSiteId()) {
             if (!Site::isSiteRequest() || $this->getSiteId() != Site::getCurrentSite()->getId()) {
                 return false;
             }
         }
         // we need to unset this 3 params here, because otherwise the defaults wouldn't have an effect if used
         // in combination with dynamic action/controller/module configurations
         unset($params["controller"], $params["action"], $params["module"]);
         $params = array_merge($this->getDefaultsArray(), $params);
         $variables = explode(",", $this->getVariables());
         preg_match_all($this->getPattern(), $path, $matches);
         if (is_array($matches) && count($matches) > 1) {
             foreach ($matches as $index => $match) {
                 if (isset($variables[$index - 1]) && $variables[$index - 1]) {
                     $paramValue = urldecode($match[0]);
                     if (!empty($paramValue) || !array_key_exists($variables[$index - 1], $params)) {
                         $params[$variables[$index - 1]] = $paramValue;
                     }
                 }
             }
         }
         $controller = $this->getController();
         $action = $this->getAction();
         $module = trim($this->getModule());
         // check for dynamic controller / action / module
         $dynamicRouteReplace = function ($item, $params) {
             if (strpos($item, "%") !== false) {
                 uksort($params, function ($a, $b) {
                     // order by key length, longer key have priority
                     // (%abcd prior %ab, so that %ab doesn't replace %ab in [%ab]cd)
                     return strlen($b) - strlen($a);
                 });
                 foreach ($params as $key => $value) {
                     $dynKey = "%" . $key;
                     if (strpos($item, $dynKey) !== false) {
                         return str_replace($dynKey, $value, $item);
                     }
                 }
             }
             return $item;
         };
         $controller = $dynamicRouteReplace($controller, $params);
         $action = $dynamicRouteReplace($action, $params);
         $module = $dynamicRouteReplace($module, $params);
         $params["controller"] = $controller;
         $params["action"] = $action;
         if (!empty($module)) {
             $params["module"] = $module;
         }
         // remember for reverse assemble
         $this->_values = $params;
         return $params;
     }
     return [];
 }
Esempio n. 14
0
 /**
  *
  */
 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);
 }
Esempio n. 15
0
 /**
  * @return string
  */
 public function getPath()
 {
     // check for site, if so rewrite the path for output
     try {
         if (!\Pimcore::inAdmin() && Site::isSiteRequest()) {
             $site = Site::getCurrentSite();
             if ($site instanceof Site) {
                 if ($site->getRootDocument() instanceof Document\Page && $site->getRootDocument() !== $this) {
                     $rootPath = $site->getRootPath();
                     $rootPath = preg_quote($rootPath);
                     return preg_replace("@^" . $rootPath . "@", "", $this->path);
                 }
             }
         }
     } catch (\Exception $e) {
         \Logger::error($e);
     }
     return $this->path;
 }
Esempio n. 16
0
 /**
  * @param $activeDocument
  * @param null $navigationRootDocument
  * @param null $htmlMenuIdPrefix
  * @param null $pageCallback
  * @param bool|string $cache
  * @return mixed|\Zend_Navigation
  * @throws \Exception
  * @throws \Zend_Navigation_Exception
  */
 public function getNavigation($activeDocument, $navigationRootDocument = null, $htmlMenuIdPrefix = null, $pageCallback = null, $cache = true)
 {
     $cacheEnabled = (bool) $cache;
     $this->_htmlMenuIdPrefix = $htmlMenuIdPrefix;
     if (!$navigationRootDocument) {
         $navigationRootDocument = Document::getById(1);
     }
     $siteSuffix = "";
     if (Site::isSiteRequest()) {
         $site = Site::getCurrentSite();
         $siteSuffix = "__site_" . $site->getId();
     }
     $cacheId = $navigationRootDocument->getId();
     if (is_string($cache)) {
         $cacheId .= "_" . $cache;
     }
     $cacheKey = "navigation_" . $cacheId . $siteSuffix;
     $navigation = CacheManager::load($cacheKey);
     if (!$navigation || !$cacheEnabled) {
         $navigation = new \Zend_Navigation();
         if ($navigationRootDocument->hasChilds()) {
             $rootPage = $this->buildNextLevel($navigationRootDocument, true, $pageCallback);
             $navigation->addPages($rootPage);
         }
         // we need to force caching here, otherwise the active classes and other settings will be set and later
         // also written into cache (pass-by-reference) ... when serializing the data directly here, we don't have this problem
         if ($cacheEnabled) {
             CacheManager::save($navigation, $cacheKey, ["output", "navigation"], null, 999, true);
         }
     }
     // set active path
     $activePage = $navigation->findOneBy("realFullPath", $activeDocument->getRealFullPath());
     if (!$activePage) {
         // find by link target
         $activePage = $navigation->findOneBy("uri", $activeDocument->getRealFullPath());
     }
     if ($activePage) {
         // we found an active document, so we can build the active trail by getting respectively the parent
         $this->addActiveCssClasses($activePage, true);
     } else {
         // we don't have an active document, so we try to build the trail on our own
         $allPages = $navigation->findAllBy("uri", "/.*/", true);
         foreach ($allPages as $page) {
             $activeTrail = false;
             if (strpos($activeDocument->getRealFullPath(), $page->getRealFullPath() . "/") === 0) {
                 $activeTrail = true;
             }
             if ($page->getDocumentType() == "link") {
                 if (strpos($activeDocument->getFullPath(), $page->getUri() . "/") === 0) {
                     $activeTrail = true;
                 }
             }
             if ($activeTrail) {
                 $page->setActive(true);
                 $page->setClass($page->getClass() . " active active-trail");
             }
         }
     }
     return $navigation;
 }
 /**
  * @param $activeDocument
  * @param null $navigationRootDocument
  * @param null $htmlMenuIdPrefix
  * @param null $pageCallback
  * @param bool|string $cache
  * @return mixed|\Zend_Navigation
  * @throws \Exception
  * @throws \Zend_Navigation_Exception
  */
 public function getNavigation($activeDocument, $navigationRootDocument = null, $htmlMenuIdPrefix = null, $pageCallback = null, $cache = true)
 {
     $cacheEnabled = (bool) $cache;
     $this->_htmlMenuIdPrefix = $htmlMenuIdPrefix;
     if (!$navigationRootDocument) {
         $navigationRootDocument = Document::getById(1);
     }
     $cacheKeys = [];
     if (Site::isSiteRequest()) {
         $site = Site::getCurrentSite();
         $cacheKeys[] = "site__" . $site->getId();
     }
     $cacheKeys[] = "root_id__" . $navigationRootDocument->getId();
     if (is_string($cache)) {
         $cacheKeys[] = "custom__" . $cache;
     }
     if ($pageCallback instanceof \Closure) {
         $cacheKeys[] = "pageCallback_" . closureHash($pageCallback);
     }
     $cacheKey = "nav_" . md5(serialize($cacheKeys));
     $navigation = CacheManager::load($cacheKey);
     if (!$navigation || !$cacheEnabled) {
         $navigation = new \Zend_Navigation();
         if ($navigationRootDocument->hasChilds()) {
             $rootPage = $this->buildNextLevel($navigationRootDocument, true, $pageCallback);
             $navigation->addPages($rootPage);
         }
         // we need to force caching here, otherwise the active classes and other settings will be set and later
         // also written into cache (pass-by-reference) ... when serializing the data directly here, we don't have this problem
         if ($cacheEnabled) {
             CacheManager::save($navigation, $cacheKey, ["output", "navigation"], null, 999, true);
         }
     }
     // set active path
     $front = \Zend_Controller_Front::getInstance();
     $request = $front->getRequest();
     // try to find a page matching exactly the request uri
     $activePages = $navigation->findAllBy("uri", $request->getRequestUri());
     if (empty($activePages)) {
         // try to find a page matching the path info
         $activePages = $navigation->findAllBy("uri", $request->getPathInfo());
     }
     if (empty($activePages)) {
         // use the provided pimcore document
         $activePages = $navigation->findAllBy("realFullPath", $activeDocument->getRealFullPath());
     }
     if (empty($activePages)) {
         // find by link target
         $activePages = $navigation->findAllBy("uri", $activeDocument->getFullPath());
     }
     // cleanup active pages from links
     // pages have priority, if we don't find any active page, we use all we found
     $tmpPages = [];
     foreach ($activePages as $page) {
         if ($page instanceof Uri && $page->getDocumentType() != "link") {
             $tmpPages[] = $page;
         }
     }
     if (count($tmpPages)) {
         $activePages = $tmpPages;
     }
     if (!empty($activePages)) {
         // we found an active document, so we can build the active trail by getting respectively the parent
         foreach ($activePages as $activePage) {
             $this->addActiveCssClasses($activePage, true);
         }
     } else {
         // we don't have an active document, so we try to build the trail on our own
         $allPages = $navigation->findAllBy("uri", "/.*/", true);
         foreach ($allPages as $page) {
             $activeTrail = false;
             if ($page->getUri() && strpos($activeDocument->getRealFullPath(), $page->getUri() . "/") === 0) {
                 $activeTrail = true;
             }
             if ($page instanceof Uri) {
                 if ($page->getDocumentType() == "link") {
                     if ($page->getUri() && strpos($activeDocument->getFullPath(), $page->getUri() . "/") === 0) {
                         $activeTrail = true;
                     }
                 }
             }
             if ($activeTrail) {
                 $page->setActive(true);
                 $page->setClass($page->getClass() . " active active-trail");
             }
         }
     }
     return $navigation;
 }
Esempio n. 18
0
 /**
  * @return array|mixed
  * @throws \Zend_Exception
  */
 protected function getData()
 {
     if (\Zend_Registry::isRegistered("Zend_Locale")) {
         $locale = (string) \Zend_Registry::get("Zend_Locale");
     } else {
         return array();
     }
     $siteId = "";
     try {
         $site = Model\Site::getCurrentSite();
         if ($site instanceof Model\Site) {
             $siteId = $site->getId();
         }
     } catch (\Exception $e) {
         // not inside a site
     }
     $cacheKey = "glossary_" . $locale . "_" . $siteId;
     try {
         $data = \Zend_Registry::get($cacheKey);
         return $data;
     } catch (\Exception $e) {
     }
     if (!($data = Model\Cache::load($cacheKey))) {
         $list = new Model\Glossary\Listing();
         $list->setCondition("(language = ? OR language IS NULL OR language = '') AND (site = ? OR site IS NULL OR site = '')", array($locale, $siteId));
         $list->setOrderKey("LENGTH(`text`)", false);
         $list->setOrder("DESC");
         $data = $list->getDataArray();
         $data = $this->prepareData($data);
         Model\Cache::save($data, $cacheKey, array("glossary"), null, 995);
         \Zend_Registry::set($cacheKey, $data);
     }
     return $data;
 }
Esempio n. 19
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;
 }