public static function compile($path, $source = null) { $conf = Pimcore_Config::getSystemConfig(); $compiledContent = ""; // check if the file is already compiled in the cache $cacheKey = "less_file_" . md5_file($path); if ($contents = Pimcore_Model_Cache::load($cacheKey)) { return $contents; } // use the original less compiler if configured if ($conf->outputfilters->lesscpath) { $output = array(); exec($conf->outputfilters->lesscpath . " " . $path, $output); $compiledContent = implode($output); // add a comment to the css so that we know it's compiled by lessc if (!empty($compiledContent)) { $compiledContent = "\n\n/**** compiled with lessc (node.js) ****/\n\n" . $compiledContent; } } // use php implementation of lessc if it doesn't work if (empty($compiledContent)) { $less = new lessc(); $less->importDir = dirname($path); $compiledContent = $less->parse(file_get_contents($path)); // add a comment to the css so that we know it's compiled by lessphp $compiledContent = "\n\n/**** compiled with lessphp ****/\n\n" . $compiledContent; } if ($source) { // correct references inside the css $compiledContent = self::correctReferences($source, $compiledContent); } // put the compiled contents into the cache Pimcore_Model_Cache::save($compiledContent, $cacheKey, array("less")); return $compiledContent; }
protected function getStorage() { if ($this->cachedItems === null) { $this->cachedItems = array(); if ($items = Pimcore_Model_Cache::load(self::cacheKey)) { $this->cachedItems = $items; } } return $this->cachedItems; }
public function start() { if ($this->editmode && !$this->force) { return false; } if ($content = Pimcore_Model_Cache::load($this->key)) { echo $content; return true; } $this->captureEnabled = true; ob_start(); return false; }
/** * @static * @return mixed|Zend_Config */ public static function getWebsiteConfig() { try { $config = Zend_Registry::get("pimcore_config_website"); } catch (Exception $e) { $cacheKey = "website_config"; if (!($config = Pimcore_Model_Cache::load($cacheKey))) { $websiteSettingFile = PIMCORE_CONFIGURATION_DIRECTORY . "/website.xml"; $settingsArray = array(); if (is_file($websiteSettingFile)) { $rawConfig = new Zend_Config_Xml($websiteSettingFile); $arrayData = $rawConfig->toArray(); foreach ($arrayData as $key => $value) { $s = null; if ($value["type"] == "document") { $s = Document::getByPath($value["data"]); } else { if ($value["type"] == "asset") { $s = Asset::getByPath($value["data"]); } else { if ($value["type"] == "object") { $s = Object_Abstract::getByPath($value["data"]); } else { if ($value["type"] == "bool") { $s = (bool) $value["data"]; } else { if ($value["type"] == "text") { $s = (string) $value["data"]; } } } } } if ($s) { $settingsArray[$key] = $s; } } } $config = new Zend_Config($settingsArray, true); Pimcore_Model_Cache::save($config, $cacheKey, array("websiteconfig", "system", "config"), null, 998); } self::setWebsiteConfig($config); } return $config; }
/** * @param string $domain * @return Site */ public static function getByDomain($domain) { // cached because this is called in the route (Pimcore_Controller_Router_Route_Frontend) $cacheKey = "site_domain_" . str_replace(array(".", "-"), "_", $domain); if (!($site = Pimcore_Model_Cache::load($cacheKey))) { $site = new self(); try { $site->getResource()->getByDomain($domain); } catch (Exception $e) { $site = "failed"; } Pimcore_Model_Cache::save($site, $cacheKey, array("system", "site")); } if ($site == "failed" || !$site) { throw new Exception("there is no site for the requested domain"); } return $site; }
/** * @param string $table * @param bool $cache * @return array|mixed */ protected function getValidTableColumns($table, $cache = true) { $cacheKey = "system_resource_columns_" . $table; if (Zend_Registry::isRegistered($cacheKey)) { $columns = Zend_Registry::get($cacheKey); } else { $columns = Pimcore_Model_Cache::load($cacheKey); if (!$columns || !$cache) { $columns = array(); $data = $this->db->fetchAll("SHOW COLUMNS FROM " . $table); foreach ($data as $d) { $columns[] = $d["Field"]; } Pimcore_Model_Cache::save($columns, $cacheKey, array("system", "resource"), null, 997); } Zend_Registry::set($cacheKey, $columns); } return $columns; }
/** * */ public function load() { $client = Pimcore_Google_Api::getSimpleClient(); $config = $this->getConfig(); $perPage = $this->getPerPage(); $offset = $this->getOffset(); $query = $this->getQuery(); if ($client) { $search = new apiCustomsearchService($client); // determine language $language = ""; if (Zend_Registry::isRegistered("Zend_Locale")) { $locale = Zend_Registry::get("Zend_Locale"); $language = $locale->getLanguage(); } if (!array_key_exists("hl", $config) && !empty($language)) { $config["hl"] = $language; } if (!array_key_exists("lr", $config) && !empty($language)) { $config["lr"] = "lang_" . $language; } if ($query) { if ($offset) { $config["start"] = $offset + 1; } if ($perPage) { $config["num"] = $perPage; } $cacheKey = "google_cse_" . md5($query . serialize($config)); if (!($result = Pimcore_Model_Cache::load($cacheKey))) { $result = $search->cse->listCse($query, $config); Pimcore_Model_Cache::save($result, $cacheKey, array("google_cse"), 3600, 999); } $this->readGoogleResponse($result); return $this->getResults(); } return array(); } else { throw new Exception("Google Simple API Key is not configured in System-Settings."); } }
public function getAllTranslations() { $cacheKey = static::getTableName() . "_data"; if (!($translations = Pimcore_Model_Cache::load($cacheKey))) { $itemClass = static::getItemClass(); $translations = array(); $translationsData = $this->db->fetchAll("SELECT * FROM " . static::getTableName()); foreach ($translationsData as $t) { if (!$translations[$t["key"]]) { $translations[$t["key"]] = new $itemClass(); $translations[$t["key"]]->setKey($t["key"]); } $translations[$t["key"]]->addTranslation($t["language"], $t["text"]); if ($translations[$t["key"]]->getDate() < $t["date"]) { $translations[$t["key"]]->setDate($t["date"]); } } Pimcore_Model_Cache::save($translations, $cacheKey, array("translator", "translate"), 999); } return $translations; }
public function translateAdmin($key = "") { if ($key) { $locale = $_REQUEST["systemLocale"]; if (!$locale) { if (Zend_Registry::isRegistered("Zend_Locale")) { $locale = Zend_Registry::get("Zend_Locale"); } else { $locale = new Zend_Locale("en"); } } if ($locale) { $cacheKey = "translator_admin"; if (!($translate = Pimcore_Model_Cache::load($cacheKey))) { $translate = new Pimcore_Translate_Admin($locale); Pimcore_Model_Cache::save($translate, $cacheKey, array("translator", "translator_admin", "translate"), null, 804); } $this->setTranslator($translate); $this->setLocale($locale); return call_user_func_array(array($this, "translate"), func_get_args()); } } return $key; }
public function initTranslation() { if (Zend_Registry::isRegistered("Zend_Translate")) { $translator = Zend_Registry::get("Zend_Translate"); } else { // setup Zend_Translate try { $locale = Zend_Registry::get("Zend_Locale"); $cacheKey = "translator_website"; if (!($translate = Pimcore_Model_Cache::load($cacheKey))) { $translate = new Pimcore_Translate_Website($locale); Pimcore_Model_Cache::save($translate, $cacheKey, array("translator", "translator_website", "translate"), null, 999); } if (Pimcore_Tool::isValidLanguage($locale)) { $translate->setLocale($locale); } else { Logger::error("You want to use an invalid language which is not defined in the system settings: " . $locale); // fall back to the first (default) language defined $languages = Pimcore_Tool::getValidLanguages(); if ($languages[0]) { Logger::error("Using '" . $languages[0] . "' as a fallback, because the language '" . $locale . "' is not defined in system settings"); $translate->setLocale($languages[0]); } else { throw new Exception("You have not defined a language in the system settings (Website -> Frontend-Languages), please add at least one language."); } } // register the translator in Zend_Registry with the key "Zend_Translate" to use the translate helper for Zend_View Zend_Registry::set("Zend_Translate", $translate); } catch (Exception $e) { Logger::error("initialization of Pimcore_Translate failed"); Logger::error($e); } } return $translator; }
public function routeStartup(Zend_Controller_Request_Abstract $request) { $requestUri = $request->getRequestUri(); $excludePatterns = array(); // only enable GET method if (!$request->isGet()) { return $this->disable(); } try { $conf = Pimcore_Config::getSystemConfig(); if ($conf->cache) { $conf = $conf->cache; if (!$conf->enabled) { return $this->disable(); } if ($conf->lifetime) { $this->setLifetime((int) $conf->lifetime); } if ($conf->excludePatterns) { $confExcludePatterns = explode(",", $conf->excludePatterns); if (!empty($confExcludePatterns)) { $excludePatterns = $confExcludePatterns; } } if ($conf->excludeCookie) { $cookies = explode(",", strval($conf->excludeCookie)); foreach ($cookies as $cookie) { if (isset($_COOKIE[trim($cookie)])) { return $this->disable(); } } } } else { return $this->disable(); } } catch (Exception $e) { return $this->disable(); } foreach ($excludePatterns as $pattern) { if (preg_match($pattern, $requestUri)) { return $this->disable(); } } $appendKey = ""; // this is for example for the image-data-uri plugin if ($request->getParam("pimcore_cache_tag_suffix")) { $tags = $request->getParam("pimcore_cache_tag_suffix"); if (is_array($tags)) { $appendKey = "_" . implode("_", $tags); } } $this->cacheKey = "output_" . md5(Pimcore_Tool::getHostname() . $requestUri) . $appendKey; if ($cacheItem = Pimcore_Model_Cache::load($this->cacheKey, true)) { header("X-Pimcore-Cache-Tag: " . $this->cacheKey, true, 200); header("X-Pimcore-Cache-Date: " . $cacheItem["date"]); foreach ($cacheItem["rawHeaders"] as $header) { header($header); } foreach ($cacheItem["headers"] as $header) { header($header['name'] . ': ' . $header['value'], $header['replace']); } echo $cacheItem["content"]; exit; } }
protected function getData() { if (Zend_Registry::isRegistered("Zend_Locale")) { $locale = Zend_Registry::get("Zend_Locale"); } else { return array(); } $siteId = ""; try { $site = Site::getCurrentSite(); if ($site instanceof Site) { $siteId = $site->getId(); } } catch (Exception $e) { // not inside a site } $cacheKey = "glossary_" . $locale->getLanguage() . "_" . $siteId; try { $data = Zend_Registry::get($cacheKey); return $data; } catch (Exception $e) { } if (!($data = Pimcore_Model_Cache::load($cacheKey))) { $list = new Glossary_List(); $list->setCondition("(language = ? OR language IS NULL OR language = '') AND (site = ? OR site IS NULL OR site = '')", array($locale->getLanguage(), $siteId)); $list->setOrderKey("LENGTH(`text`)", false); $list->setOrder("DESC"); $data = $list->getDataArray(); $data = $this->prepareData($data); Pimcore_Model_Cache::save($data, $cacheKey, array("glossary"), null, 995); Zend_Registry::set($cacheKey, $data); } return $data; }
/** * Checks for a suitable redirect * @throws Exception * @param bool $override * @return void */ protected function checkForRedirect($override = false) { try { $cacheKey = "system_route_redirect"; if (empty($this->redirects) && !($this->redirects = Pimcore_Model_Cache::load($cacheKey))) { $list = new Redirect_List(); $list->setOrder("DESC"); $list->setOrderKey("priority"); $this->redirects = $list->load(); Pimcore_Model_Cache::save($this->redirects, $cacheKey, array("system", "redirect", "route"), null, 998); } foreach ($this->redirects as $redirect) { // 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(), $_SERVER["REQUEST_URI"], $matches)) { array_shift($matches); $target = $redirect->getTarget(); if (is_numeric($target)) { $d = Document::getById($target); if ($d instanceof Document_Page) { $target = $d->getFullPath(); } else { throw new Exception("Target of redirect no found!"); } } $url = vsprintf($target, $matches); header($redirect->getHttpStatus()); header("Location: " . $url); exit; } } } } catch (Exception $e) { // no suitable route found } }
/** * Checks for a suitable redirect * @throws Exception * @param bool $override * @return void */ protected function checkForRedirect($override = false) { try { $cacheKey = "system_route_redirect"; if (empty($this->redirects) && !($this->redirects = Pimcore_Model_Cache::load($cacheKey))) { $list = new Redirect_List(); $list->setOrder("DESC"); $list->setOrderKey("priority"); $this->redirects = $list->load(); Pimcore_Model_Cache::save($this->redirects, $cacheKey, array("system", "redirect", "route"), null, 998); } foreach ($this->redirects as $redirect) { // 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(), $_SERVER["REQUEST_URI"], $matches)) { array_shift($matches); $target = $redirect->getTarget(); if (is_numeric($target)) { $d = Document::getById($target); if ($d instanceof Document_Page) { $target = $d->getFullPath(); } else { throw new Exception("Target of redirect no found!"); } } // 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); header($redirect->getHttpStatus()); header("Location: " . $url, true, $redirect->getStatusCode()); // log all redirects to the redirect log Pimcore_Log_Simple::log("redirect", Pimcore_Tool::getClientIp() . " \t Source: " . $_SERVER["REQUEST_URI"] . " -> " . $url); exit; } } } } catch (Exception $e) { // no suitable route found } }
/** * @return Property[] */ public function getProperties() { if ($this->properties === null) { // try to get from cache $cacheKey = "asset_properties_" . $this->getId(); if (!($properties = Pimcore_Model_Cache::load($cacheKey))) { $properties = $this->getResource()->getProperties(); Pimcore_Model_Cache::save($properties, $cacheKey, array("asset_properties", "properties")); } $this->setProperties($properties); } return $this->properties; }
/** * @param string $name * @return Staticroute */ public static function getByName($name) { // check if pimcore already knows the id for this $name, if yes just return it /*if(array_key_exists($name, self::$nameIdMappingCache)) { return self::getById(self::$nameIdMappingCache[$name]); }*/ //cache staticroutes by name $cacheKey = 'staticroute_' . preg_replace("/[^0-9a-zA-Z_]/", "_", $name); if (!($route = Pimcore_Model_Cache::load($cacheKey))) { // create a tmp object to obtain the id $route = new self(); try { $route->getResource()->getByName($name); Pimcore_Model_Cache::save($route, $cacheKey, array('staticroute')); } catch (Exception $e) { Logger::error($e); return null; } } return $route; // to have a singleton in a way. like all instances of Element_Interface do also, like Object_Abstract /*if($route->getId() > 0) { // add it to the mini-per request cache self::$nameIdMappingCache[$name] = $route->getId(); return self::getById($route->getId()); }*/ }
protected function getData() { try { $locale = Zend_Registry::get("Zend_Locale"); } catch (Exception $e) { return array(); } $cacheKey = "glossary_" . $locale->getLanguage(); try { $data = Zend_Registry::get($cacheKey); return $data; } catch (Exception $e) { } if (!($data = Pimcore_Model_Cache::load($cacheKey))) { $list = new Glossary_List(); $list->setCondition("language = ?", $locale->getLanguage()); $list->setOrderKey("LENGTH(`text`)", false); $list->setOrder("DESC"); $data = $list->getDataArray(); $data = $this->prepareData($data); Pimcore_Model_Cache::save($data, $cacheKey, array("glossary"), null, 995); Zend_Registry::set($cacheKey, $data); } return $data; }
public function dispatchLoopShutdown() { if (!Pimcore_Tool::isHtmlResponse($this->getResponse())) { return; } $cacheKey = "outputfilter_tagmngt"; $tags = Pimcore_Model_Cache::load($cacheKey); if (!is_array($tags)) { $dir = Tool_Tag_Config::getWorkingDir(); $tags = array(); $files = scandir($dir); foreach ($files as $file) { if (strpos($file, ".xml")) { $name = str_replace(".xml", "", $file); $tags[] = Tool_Tag_Config::getByName($name); } } Pimcore_Model_Cache::save($tags, $cacheKey, array("tagmanagement"), null, 100); } if (empty($tags)) { return; } include_once "simple_html_dom.php"; $body = $this->getResponse()->getBody(); $html = str_get_html($body); $requestParams = array_merge($_GET, $_POST); if ($html) { foreach ($tags as $tag) { $method = strtolower($tag->getHttpMethod()); $pattern = $tag->getUrlPattern(); $textPattern = $tag->getTextPattern(); if (($method == strtolower($this->getRequest()->getMethod()) || empty($method)) && (empty($pattern) || @preg_match($pattern, $this->getRequest()->getRequestUri())) && (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"])) { $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 = str_get_html($body); } } } } } } $this->getResponse()->setBody($body); } }
if ($num != 1) { throw new Exception("Database query faulty response."); } // === FILESYSTEM === try { $putData = sha1(time()); file_put_contents(PIMCORE_TEMPORARY_DIRECTORY . '/check_write.tmp', $putData); $getData = file_get_contents(PIMCORE_TEMPORARY_DIRECTORY . '/check_write.tmp'); unlink(PIMCORE_TEMPORARY_DIRECTORY . '/check_write.tmp'); } catch (Exception $e) { throw new Exception('Unable to read/write a file. [' . $e->getCode() . ']'); } if ($putData !== $getData) { throw new Exception('Error writing/reading a file.'); } // === CACHE === try { Pimcore_Model_Cache::setForceImmediateWrite(true); Pimcore_Model_Cache::save($putData, $putData, array('check_write')); $getData = Pimcore_Model_Cache::load($putData); Pimcore_Model_Cache::clearTag("check_write"); } catch (Exception $e) { throw new Exception('Pimcore cache error [' . $e->getCode() . ']'); } if ($putData !== $getData) { throw new Exception('Pimcore cache failure - content mismatch.'); } echo "SUCCESS"; } catch (Exception $e) { echo "FAILURE: " . $e->getMessage(); }