/** * Returns the document path. * * @return string */ public function getPath() { // check for site, if so rewrite the path for output try { if (\Pimcore\Tool::isFrontend() && 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); $link = preg_replace("@^" . $rootPath . "@", "", $this->path); return $link; } } } } catch (\Exception $e) { Logger::error($e); } return $this->path; }
/** * @static * @throws Exception|\Zend_Controller_Router_Exception */ public static function run() { self::setSystemRequirements(); // detect frontend (website) $frontend = Tool::isFrontend(); // enable the output-buffer, why? see in self::outputBufferStart() //if($frontend) { self::outputBufferStart(); //} self::initAutoloader(); self::initConfiguration(); self::setupFramework(); // config is loaded now init the real logger self::initLogger(); // initialize cache Cache::init(); // load plugins and modules (=core plugins) self::initModules(); self::initPlugins(); // init front controller $front = \Zend_Controller_Front::getInstance(); $conf = Config::getSystemConfig(); if (!$conf) { // redirect to installer if configuration isn't present if (!preg_match("/^\\/install.*/", $_SERVER["REQUEST_URI"])) { header("Location: /install/"); exit; } } if (self::inDebugMode() && $frontend && !$conf->general->disable_whoops && !defined("HHVM_VERSION")) { $whoops = new \Whoops\Run(); $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); $jsonErrorHandler = new \Whoops\Handler\JsonResponseHandler(); $jsonErrorHandler->onlyForAjaxRequests(true); $whoops->pushHandler($jsonErrorHandler); $whoops->register(); // add event handler before Pimcore::shutdown() to ensure fatal errors are handled by Whoops self::getEventManager()->attach("system.shutdown", array($whoops, "handleShutdown"), 10000); } $front->registerPlugin(new Controller\Plugin\ErrorHandler(), 1); $front->registerPlugin(new Controller\Plugin\Maintenance(), 2); // register general pimcore plugins for frontend if ($frontend) { $front->registerPlugin(new Controller\Plugin\Thumbnail(), 795); $front->registerPlugin(new Controller\Plugin\Less(), 799); $front->registerPlugin(new Controller\Plugin\AdminButton(), 806); } if (Tool::useFrontendOutputFilters(new \Zend_Controller_Request_Http())) { $front->registerPlugin(new Controller\Plugin\HybridAuth(), 792); $front->registerPlugin(new Controller\Plugin\QrCode(), 793); $front->registerPlugin(new Controller\Plugin\CommonFilesFilter(), 794); $front->registerPlugin(new Controller\Plugin\WysiwygAttributes(), 796); $front->registerPlugin(new Controller\Plugin\Webmastertools(), 797); $front->registerPlugin(new Controller\Plugin\Analytics(), 798); $front->registerPlugin(new Controller\Plugin\TagManagement(), 804); $front->registerPlugin(new Controller\Plugin\Targeting(), 805); $front->registerPlugin(new Controller\Plugin\EuCookieLawNotice(), 807); $front->registerPlugin(new Controller\Plugin\HttpErrorLog(), 850); $front->registerPlugin(new Controller\Plugin\Cache(), 901); // for caching } self::initControllerFront($front); // set router $router = $front->getRouter(); $routeAdmin = new \Zend_Controller_Router_Route('admin/:controller/:action/*', array('module' => 'admin', "controller" => "index", "action" => "index")); $routeInstall = new \Zend_Controller_Router_Route('install/:controller/:action/*', array('module' => 'install', "controller" => "index", "action" => "index")); $routeUpdate = new \Zend_Controller_Router_Route('admin/update/:controller/:action/*', array('module' => 'update', "controller" => "index", "action" => "index")); $routePlugins = new \Zend_Controller_Router_Route('admin/plugin/:controller/:action/*', array('module' => 'pluginadmin', "controller" => "index", "action" => "index")); $routeExtensions = new \Zend_Controller_Router_Route('admin/extensionmanager/:controller/:action/*', array('module' => 'extensionmanager', "controller" => "index", "action" => "index")); $routeReports = new \Zend_Controller_Router_Route('admin/reports/:controller/:action/*', array('module' => 'reports', "controller" => "index", "action" => "index")); $routePlugin = new \Zend_Controller_Router_Route('plugin/:module/:controller/:action/*', array("controller" => "index", "action" => "index")); $routeWebservice = new \Zend_Controller_Router_Route('webservice/:controller/:action/*', array("module" => "webservice", "controller" => "index", "action" => "index")); $routeSearchAdmin = new \Zend_Controller_Router_Route('admin/search/:controller/:action/*', array("module" => "searchadmin", "controller" => "index", "action" => "index")); // website route => custom router which check for a suitable document $routeFrontend = new Controller\Router\Route\Frontend(); $router->addRoute('default', $routeFrontend); // only do this if not frontend => performance issue if (!$frontend) { $router->addRoute("install", $routeInstall); $router->addRoute('plugin', $routePlugin); $router->addRoute('admin', $routeAdmin); $router->addRoute('update', $routeUpdate); $router->addRoute('plugins', $routePlugins); $router->addRoute('extensionmanager', $routeExtensions); $router->addRoute('reports', $routeReports); $router->addRoute('searchadmin', $routeSearchAdmin); if ($conf instanceof \Zend_Config and $conf->webservice and $conf->webservice->enabled) { $router->addRoute('webservice', $routeWebservice); } // check if this request routes into a plugin, if so check if the plugin is enabled if (preg_match("@^/plugin/([^/]+)/.*@", $_SERVER["REQUEST_URI"], $matches)) { $pluginName = $matches[1]; if (!Pimcore\ExtensionManager::isEnabled("plugin", $pluginName)) { \Pimcore\Tool::exitWithError("Plugin is disabled. To use this plugin please enable it in the extension manager!"); } } // force the main (default) domain for "admin" requests if ($conf->general->domain && $conf->general->domain != Tool::getHostname()) { $url = ($_SERVER['HTTPS'] == "on" ? "https" : "http") . "://" . $conf->general->domain . $_SERVER["REQUEST_URI"]; header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $url, true, 301); exit; } } // check if webdav is configured and add router if ($conf instanceof \Zend_Config) { if ($conf->assets->webdav->hostname) { $routeWebdav = new \Zend_Controller_Router_Route_Hostname($conf->assets->webdav->hostname, array("module" => "admin", 'controller' => 'asset', 'action' => 'webdav')); $router->addRoute('webdav', $routeWebdav); } } $front->setRouter($router); self::getEventManager()->trigger("system.startup", $front); // throw exceptions also when in preview or in editmode (documents) to see it immediately when there's a problem with this page $throwExceptions = false; if (Tool::isFrontentRequestByAdmin()) { $user = \Pimcore\Tool\Authentication::authenticateSession(); if ($user instanceof User) { $throwExceptions = true; } } // run dispatcher // this is also standard for /admin/ requests -> error handling is done in Pimcore_Controller_Action_Admin if (!PIMCORE_DEBUG && !$throwExceptions && !PIMCORE_DEVMODE) { @ini_set("display_errors", "Off"); @ini_set("display_startup_errors", "Off"); $front->dispatch(); } else { @ini_set("display_errors", "On"); @ini_set("display_startup_errors", "On"); $front->throwExceptions(true); try { $front->dispatch(); } catch (\Zend_Controller_Router_Exception $e) { if (!headers_sent()) { header("HTTP/1.0 404 Not Found"); } \Logger::err($e); throw new \Zend_Controller_Router_Exception("No route, document, custom route or redirect is matching the request: " . $_SERVER["REQUEST_URI"] . " | \n" . "Specific ERROR: " . $e->getMessage()); } catch (\Exception $e) { if (!headers_sent()) { header("HTTP/1.0 500 Internal Server Error"); } throw $e; } } }
/** * Returns the full path of the document including the filename * * @return string */ public function getFullPath() { $path = $this->getPath() . $this->getFilename(); if (\Pimcore\Tool::isFrontend()) { $path = urlencode_ignore_slash($path); $results = \Pimcore::getEventManager()->trigger("frontend.path.asset", $this); if ($results->count()) { $path = $results->last(); } } return $path; }