/** * @throws \Zend_Json_Exception */ protected function logUsageStatistics() { $params = []; $disallowedKeys = ["_dc", "module", "controller", "action", "password"]; foreach ($this->getAllParams() as $key => $value) { if (is_json($value)) { $value = \Zend_Json::decode($value); if (is_array($value)) { array_walk_recursive($value, function (&$item, $key) { if (strpos($key, "pass") !== false) { $item = "*************"; } }); } $value = \Zend_Json::encode($value); } if (!in_array($key, $disallowedKeys) && is_string($value)) { $params[$key] = strlen($value) > 40 ? substr($value, 0, 40) . "..." : $value; } } \Pimcore\Log\Simple::log("usagelog", ($this->getUser() ? $this->getUser()->getId() : "0") . "|" . $this->getParam("module") . "|" . $this->getParam("controller") . "|" . $this->getParam("action") . "|" . @json_encode($params)); }
public function autoload($class) { // manual aliasing $classAliases = ["Pimcore\\Resource" => "Pimcore\\Db", "Pimcore_Resource" => "Pimcore\\Db", "Pimcore\\Resource\\Mysql" => "Pimcore\\Db", "Pimcore_Resource_Mysql" => "Pimcore\\Db", "Pimcore\\Log\\Log" => "Pimcore\\Log\\ApplicationLogger", "Pimcore\\Log\\Writer\\Db" => "Pimcore\\Log\\Handler\\ApplicationLoggerDb", "Pimcore\\Model\\Cache" => "Pimcore\\Cache"]; if (array_key_exists($class, $classAliases)) { class_alias($classAliases[$class], $class); return; } parent::autoload($class); // compatibility from Resource => Dao if (strpos($class, "Resource") && !class_exists($class, false) && !interface_exists($class, false)) { $daoClass = str_replace("Resource", "Dao", $class); if (Tool::classExists($daoClass) || Tool::interfaceExists($daoClass)) { if (!class_exists($class, false) && !interface_exists($class, false)) { class_alias($daoClass, $class); } } } // reverse compatibility from namespaced to prefixed class names e.g. Pimcore\Model\Document => Document if (strpos($class, "Pimcore\\") === 0) { // first check for a model, if it doesnt't work fall back to the default autoloader if (!class_exists($class, false) && !interface_exists($class, false)) { if (!$this->loadModel($class)) { $loader = \Zend_Loader_Autoloader::getInstance(); $loader->autoload($class); } } if (class_exists($class, false) || interface_exists($class, false)) { // create an alias $alias = str_replace("\\", "_", $class); $alias = preg_replace("/_Abstract([^_]+)/", "_Abstract", $alias); $alias = preg_replace("/_[^_]+Interface/", "_Interface", $alias); $alias = str_replace("_Listing_", "_List_", $alias); $alias = preg_replace("/_Listing\$/", "_List", $alias); $alias = str_replace("Object_ClassDefinition", "Object_Class", $alias); if (strpos($alias, "Pimcore_Model") === 0) { if (!preg_match("/^Pimcore_Model_(Abstract|List|Resource|Cache)/", $alias)) { $alias = str_replace("Pimcore_Model_", "", $alias); } } if (!class_exists($alias, false) && !interface_exists($alias, false)) { class_alias($class, $alias); return; // skip here, nothing more to do ... } } } // compatibility layer from prefixed to namespaced e.g. Document => Pimcore\Model\Document $isLegacyClass = preg_match("/^(Pimcore_|Asset|Dependency|Document|Element|Glossary|Metadata|Object|Property|Redirect|Schedule|Site|Staticroute|Tool|Translation|User|Version|Webservice|WebsiteSetting|Search)/", $class); if (!class_exists($class, false) && !interface_exists($class, false) && $isLegacyClass) { // this is for debugging purposes, to find legacy class names if (PIMCORE_DEBUG) { $backtrace = debug_backtrace(); foreach ($backtrace as $step) { if (isset($step["file"]) && !empty($step["file"]) && $step["function"] != "class_exists") { $logName = "legacy-class-names"; if (preg_match("@^" . preg_quote(PIMCORE_PATH, "@") . "@", $step["file"])) { $logName .= "-admin"; } \Pimcore\Log\Simple::log($logName, $class . " used in " . $step["file"] . " at line " . $step["line"]); break; } } } $namespacedClass = $class; $namespacedClass = str_replace("_List", "_Listing", $namespacedClass); $namespacedClass = str_replace("Object_Class", "Object_ClassDefinition", $namespacedClass); $namespacedClass = preg_replace("/([^_]+)_Abstract\$/", "\$1_Abstract\$1", $namespacedClass); $namespacedClass = preg_replace("/([^_]+)_Interface\$/", "\$1_\$1Interface", $namespacedClass); $namespacedClass = str_replace("_", "\\", $namespacedClass); if (strpos($namespacedClass, "Pimcore") !== 0) { $namespacedClass = "Pimcore\\Model\\" . $namespacedClass; } // check if the class is a model, if so, load it $this->loadModel($namespacedClass); if (Tool::classExists($namespacedClass) || Tool::interfaceExists($namespacedClass)) { if (!class_exists($class, false) && !interface_exists($class, false)) { class_alias($namespacedClass, $class); } } } }
/** * 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 } }
private static function log($loggername, $message) { \Pimcore\Log\Simple::log($loggername, $message); echo $message . "\n"; }