save() public static method

public static save ( $data, $key, array $tags = [], null $lifetime = null, integer $priority, boolean $force = false ) : boolean | void
$data
$key
$tags array
$lifetime null
$priority integer
$force boolean
return boolean | void
コード例 #1
0
ファイル: HttpErrorLog.php プロジェクト: elavarasann/pimcore
 /**
  *
  */
 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\Cache::save($responseData, $cacheKey, array("output"), 900, 9992);
         }
     }
 }
コード例 #2
0
ファイル: RobotsTxt.php プロジェクト: emanuel-london/pimcore
 /**
  * @param $domain
  */
 public function __construct($domain)
 {
     $this->_domain = $domain;
     try {
         $robotsUrl = $domain . '/robots.txt';
         $cacheKey = "robots_" . crc32($robotsUrl);
         if (!($robotsTxt = Cache::load($cacheKey))) {
             $robotsTxt = \Pimcore\Tool::getHttpData($robotsUrl);
             Cache::save($robotsTxt, $cacheKey, array("system"), 3600, 999, true);
         }
         $this->_rules = $this->_makeRules($robotsTxt);
     } catch (\Exception $e) {
     }
 }
コード例 #3
0
ファイル: HttpErrorLog.php プロジェクト: solverat/pimcore
 /**
  *
  */
 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 && !session_id()) {
             // do not cache if there's no data or an active session
             if ($this->cacheKey) {
                 \Pimcore\Cache::save($responseData, $this->cacheKey, ["output"], 900, 9992);
             }
         }
     }
 }
コード例 #4
0
ファイル: Cse.php プロジェクト: sfie/pimcore
 /**
  *
  */
 public function load()
 {
     $client = Api::getSimpleClient();
     $config = $this->getConfig();
     $perPage = $this->getPerPage();
     $offset = $this->getOffset();
     $query = $this->getQuery();
     if ($client) {
         $search = new \Google_Service_Customsearch($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 (empty($perPage)) {
                 $perPage = 10;
             }
             $config["num"] = $perPage;
             $cacheKey = "google_cse_" . md5($query . serialize($config));
             // this is just a protection so that no query get's sent twice in a request (loops, ...)
             if (\Zend_Registry::isRegistered($cacheKey)) {
                 $result = \Zend_Registry::get($cacheKey);
             } else {
                 if (!($result = Cache::load($cacheKey))) {
                     $result = $search->cse->listCse($query, $config);
                     Cache::save($result, $cacheKey, array("google_cse"), 3600, 999);
                     \Zend_Registry::set($cacheKey, $result);
                 }
             }
             $this->readGoogleResponse($result);
             return $this->getResults(false);
         }
         return array();
     } else {
         throw new \Exception("Google Simple API Key is not configured in System-Settings.");
     }
 }
コード例 #5
0
ファイル: AbstractDao.php プロジェクト: solverat/pimcore
 /**
  * @param string $table
  * @param bool $cache
  * @return array|mixed
  */
 public function getValidTableColumns($table, $cache = true)
 {
     $cacheKey = self::CACHEKEY . $table;
     if (\Zend_Registry::isRegistered($cacheKey)) {
         $columns = \Zend_Registry::get($cacheKey);
     } else {
         $columns = Cache::load($cacheKey);
         if (!$columns || !$cache) {
             $columns = [];
             $data = $this->db->fetchAll("SHOW COLUMNS FROM " . $table);
             foreach ($data as $d) {
                 $columns[] = $d["Field"];
             }
             Cache::save($columns, $cacheKey, ["system", "resource"], null, 997);
         }
         \Zend_Registry::set($cacheKey, $columns);
     }
     return $columns;
 }
コード例 #6
0
ファイル: Embed.php プロジェクト: solverat/pimcore
 /**
  * @see Document\Tag\TagInterface::frontend
  * @return string
  */
 public function frontend()
 {
     if ($this->url) {
         $config = $this->getOptions();
         if (!isset($config["params"])) {
             $config["params"] = [];
         }
         foreach (["width", "height"] as $property) {
             if (isset($config[$property])) {
                 $config["params"][$property] = $config[$property];
             }
         }
         $cacheKey = "doc_embed_" . crc32(serialize([$this->url, $config]));
         if (!($html = \Pimcore\Cache::load($cacheKey))) {
             $embera = new \Embera\Embera($config);
             $html = $embera->autoEmbed($this->url);
             \Pimcore\Cache::save($html, $cacheKey, ["embed"], 86400, 1, true);
         }
         return $html;
     }
     return "";
 }
コード例 #7
0
ファイル: Translate.php プロジェクト: emanuel-london/pimcore
 /**
  * @param null $data
  * @param $locale
  * @param array $options
  * @return array
  */
 protected function _loadTranslationData($data, $locale, array $options = array())
 {
     $locale = (string) $locale;
     $tmpKeyParts = explode("\\", self::getBackend());
     $cacheKey = "Translate_" . array_pop($tmpKeyParts) . "_data_" . $locale;
     if (!($data = Cache::load($cacheKey))) {
         $data = array("__pimcore_dummy" => "only_a_dummy");
         $listClass = self::getBackend() . "\\Listing";
         $list = new $listClass();
         if ($list->isCacheable()) {
             $list->setCondition("language = ?", array($locale));
             $translations = $list->loadRaw();
             foreach ($translations as $translation) {
                 $data[mb_strtolower($translation["key"])] = Tool\Text::removeLineBreaks($translation["text"]);
             }
             Cache::save($data, $cacheKey, array("translator", "translator_website", "translate"), null, 999);
             $this->isCacheable = true;
         } else {
             $this->isCacheable = false;
         }
     }
     $this->_translate[$locale] = $data;
     return $this->_translate;
 }
コード例 #8
0
ファイル: Dao.php プロジェクト: elavarasann/pimcore
 /**
  * @return array|mixed
  */
 public function getAllTranslations()
 {
     $cacheKey = static::getTableName() . "_data";
     if (!($translations = 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"]);
             //for legacy support
             if ($translations[$t["key"]]->getDate() < $t["creationDate"]) {
                 $translations[$t["key"]]->setDate($t["creationDate"]);
             }
             $translations[$t["key"]]->setCreationDate($t["creationDate"]);
             $translations[$t["key"]]->setModificationDate($t["modificationDate"]);
         }
         Cache::save($translations, $cacheKey, array("translator", "translate"), 999);
     }
     return $translations;
 }
コード例 #9
0
ファイル: Config.php プロジェクト: pimcore/pimcore
 /**
  * @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;
 }
コード例 #10
0
ファイル: Config.php プロジェクト: solverat/pimcore
 /**
  * @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 = [];
             $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;
 }
コード例 #11
0
ファイル: Cache.php プロジェクト: emanuel-london/pimcore
 /**
  *
  */
 public function end()
 {
     if ($this->captureEnabled) {
         $this->captureEnabled = false;
         $tags = array("in_template");
         if (!$this->lifetime) {
             $tags[] = "output";
         }
         $content = ob_get_clean();
         CacheManager::save($content, $this->key, $tags, $this->lifetime, 996, true);
         echo $content;
     }
 }
コード例 #12
0
ファイル: Site.php プロジェクト: solverat/pimcore
 /**
  * @param $domain
  * @return mixed|Site|string
  * @throws \Exception
  */
 public static function getByDomain($domain)
 {
     // cached because this is called in the route (Pimcore_Controller_Router_Route_Frontend)
     $cacheKey = "site_domain_" . md5($domain);
     if (!($site = \Pimcore\Cache::load($cacheKey))) {
         $site = new self();
         try {
             $site->getDao()->getByDomain($domain);
         } catch (\Exception $e) {
             \Logger::debug($e);
             $site = "failed";
         }
         \Pimcore\Cache::save($site, $cacheKey, ["system", "site"]);
     }
     if ($site == "failed" || !$site) {
         $msg = "there is no site for the requested domain [" . $domain . "], content was [" . $site . "]";
         \Logger::debug($msg);
         throw new \Exception($msg);
     }
     return $site;
 }
コード例 #13
0
ファイル: Document.php プロジェクト: pimcore/pimcore
 public function getText($page = null)
 {
     if (\Pimcore\Document::isAvailable() && \Pimcore\Document::isFileTypeSupported($this->getFilename())) {
         $cacheKey = "asset_document_text_" . $this->getId() . "_" . ($page ? $page : "all");
         if (!($text = Cache::load($cacheKey))) {
             $document = \Pimcore\Document::getInstance();
             $text = $document->getText($page, $this->getFileSystemPath());
             Cache::save($text, $cacheKey, $this->getCacheTags(), null, 99, true);
             // force cache write
         }
         return $text;
     } else {
         Logger::error("Couldn't get text out of document " . $this->getRealFullPath() . " no document adapter is available");
     }
     return null;
 }
コード例 #14
0
ファイル: Tool.php プロジェクト: elavarasann/pimcore
 /**
  * @return array|mixed
  * @throws \Zend_Locale_Exception
  */
 public static function getSupportedLocales()
 {
     // List of locales that are no longer part of CLDR
     // this was also changed in the Zend Framework, but here we need to provide an appropriate alternative
     // since this information isn't public in \Zend_Locale :-(
     $aliases = ['az_AZ' => true, 'bs_BA' => true, 'ha_GH' => true, 'ha_NE' => true, 'ha_NG' => true, 'kk_KZ' => true, 'ks_IN' => true, 'mn_MN' => true, 'ms_BN' => true, 'ms_MY' => true, 'ms_SG' => true, 'pa_IN' => true, 'pa_PK' => true, 'shi_MA' => true, 'sr_BA' => true, 'sr_ME' => true, 'sr_RS' => true, 'sr_XK' => true, 'tg_TJ' => true, 'tzm_MA' => true, 'uz_AF' => true, 'uz_UZ' => true, 'vai_LR' => true, 'zh_CN' => true, 'zh_HK' => true, 'zh_MO' => true, 'zh_SG' => true, 'zh_TW' => true];
     $locale = \Zend_Locale::findLocale();
     $cacheKey = "system_supported_locales_" . strtolower((string) $locale);
     if (!($languageOptions = Cache::load($cacheKey))) {
         // we use the locale here, because \Zend_Translate only supports locales not "languages"
         $languages = \Zend_Locale::getLocaleList();
         $languages = array_merge($languages, $aliases);
         $languageOptions = array();
         foreach ($languages as $code => $active) {
             if ($active) {
                 $translation = \Zend_Locale::getTranslation($code, "language");
                 if (!$translation) {
                     $tmpLocale = new \Zend_Locale($code);
                     $lt = \Zend_Locale::getTranslation($tmpLocale->getLanguage(), "language");
                     $tt = \Zend_Locale::getTranslation($tmpLocale->getRegion(), "territory");
                     if ($lt && $tt) {
                         $translation = $lt . " (" . $tt . ")";
                     }
                 }
                 if (!$translation) {
                     $translation = $code;
                 }
                 $languageOptions[$code] = $translation;
             }
         }
         asort($languageOptions);
         Cache::save($languageOptions, $cacheKey, ["system"]);
     }
     return $languageOptions;
 }
コード例 #15
0
ファイル: Snippet.php プロジェクト: solverat/pimcore
 /**
  * @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;
     }
 }
コード例 #16
0
ファイル: View.php プロジェクト: jjpeters67/pimcore
 /**
  * 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;
 }
コード例 #17
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);
     }
     $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
     $activePage = $navigation->findOneBy("uri", $request->getRequestUri());
     if (!$activePage) {
         // try to find a page matching the path info
         $activePage = $navigation->findOneBy("uri", $request->getPathInfo());
     }
     if (!$activePage) {
         // use the provided pimcore document
         $activePage = $navigation->findOneBy("realFullPath", $activeDocument->getRealFullPath());
     }
     if (!$activePage) {
         // find by link target
         $activePage = $navigation->findOneBy("uri", $activeDocument->getFullPath());
     }
     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->getUri() . "/") === 0) {
                 $activeTrail = true;
             }
             if ($page instanceof Uri) {
                 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;
 }
コード例 #18
0
ファイル: Frontend.php プロジェクト: jansarmir/pimcore
 /**
  * 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);
                     if (empty($url)) {
                         // vsprintf() failed, just ose the original again
                         $url = $target;
                     }
                     $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
     }
 }
コード例 #19
0
ファイル: Document.php プロジェクト: elavarasann/pimcore
 /**
  * Get a list of properties (including the inherited)
  *
  * @return Property[]
  */
 public function getProperties()
 {
     if ($this->properties === null) {
         // try to get from cache
         $cacheKey = "document_properties_" . $this->getId();
         $properties = \Pimcore\Cache::load($cacheKey);
         if (!is_array($properties)) {
             $properties = $this->getDao()->getProperties();
             $elementCacheTag = $this->getCacheTag();
             $cacheTags = array("document_properties" => "document_properties", $elementCacheTag => $elementCacheTag);
             \Pimcore\Cache::save($properties, $cacheKey, $cacheTags);
         }
         $this->setProperties($properties);
     }
     return $this->properties;
 }
コード例 #20
0
ファイル: Dao.php プロジェクト: pimcore/pimcore
 /**
  * @return array|mixed
  */
 public function getAllTranslations()
 {
     $cacheKey = static::getTableName() . "_data";
     if (!($translations = Cache::load($cacheKey))) {
         $itemClass = static::getItemClass();
         $translations = [];
         $select = $this->db->select();
         // create base
         $select->from([static::getTableName()]);
         if ($this->onCreateQueryCallback) {
             $closure = $this->onCreateQueryCallback;
             $closure($select);
         }
         $translationsData = $this->db->fetchAll($select);
         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"]);
             //for legacy support
             if ($translations[$t["key"]]->getDate() < $t["creationDate"]) {
                 $translations[$t["key"]]->setDate($t["creationDate"]);
             }
             $translations[$t["key"]]->setCreationDate($t["creationDate"]);
             $translations[$t["key"]]->setModificationDate($t["modificationDate"]);
         }
         Cache::save($translations, $cacheKey, ["translator", "translate"], 999);
     }
     return $translations;
 }
コード例 #21
0
 /**
  * @return \Zend_Config
  */
 protected function getConfig()
 {
     if ($this->config) {
         return $this->config;
     }
     $config = Cache::load(self::CONFIG_CACHE_KEY);
     if (!$config) {
         $config = new \Zend_Config_Xml((string) new FileLocator(self::CONFIG_FILE), null, true);
         Cache::save($config, self::CONFIG_CACHE_KEY);
     }
     $this->config = $config;
     return $this->config;
 }
コード例 #22
0
ファイル: Glossary.php プロジェクト: emanuel-london/pimcore
 /**
  * @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 = CacheManger::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);
         CacheManger::save($data, $cacheKey, array("glossary"), null, 995);
         \Zend_Registry::set($cacheKey, $data);
     }
     return $data;
 }
コード例 #23
0
ファイル: AbstractObject.php プロジェクト: solverat/pimcore
 /**
  * @return Property[]
  */
 public function getProperties()
 {
     if ($this->o_properties === null) {
         // try to get from cache
         $cacheKey = "object_properties_" . $this->getId();
         $properties = Cache::load($cacheKey);
         if (!is_array($properties)) {
             $properties = $this->getDao()->getProperties();
             $elementCacheTag = $this->getCacheTag();
             $cacheTags = ["object_properties" => "object_properties", $elementCacheTag => $elementCacheTag];
             Cache::save($properties, $cacheKey, $cacheTags);
         }
         $this->setProperties($properties);
     }
     return $this->o_properties;
 }
コード例 #24
0
ファイル: CDN.php プロジェクト: elavarasann/pimcore
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if ($this->enabled) {
         include_once "simple_html_dom.php";
         $body = $this->getResponse()->getBody();
         $html = str_get_html($body);
         if ($html) {
             $elements = $html->find("link[rel=stylesheet], img, script[src]");
             foreach ($elements as $element) {
                 if ($element->tag == "link") {
                     if ($this->pathMatch($element->href)) {
                         $element->href = $this->rewritePath($element->href);
                     }
                 } else {
                     if ($element->tag == "img") {
                         if ($this->pathMatch($element->src)) {
                             $element->src = $this->rewritePath($element->src);
                         }
                     } else {
                         if ($element->tag == "script") {
                             if ($this->pathMatch($element->src)) {
                                 $element->src = $this->rewritePath($element->src);
                             }
                         }
                     }
                 }
             }
             $body = $html->save();
             $html->clear();
             unset($html);
             $this->getResponse()->setBody($body);
             // save storage
             CacheManager::save($this->cachedItems, self::cacheKey, array(), 3600);
         }
     }
 }
コード例 #25
0
ファイル: Cache.php プロジェクト: solverat/pimcore
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if ($this->enabled && session_id()) {
         $this->disable("session in use");
     }
     if ($this->disableReason) {
         $this->getResponse()->setHeader("X-Pimcore-Output-Cache-Disable-Reason", $this->disableReason, true);
     }
     if ($this->enabled && $this->getResponse()->getHttpResponseCode() == 200) {
         try {
             if ($this->lifetime && $this->addExpireHeader) {
                 // add cache control for proxies and http-caches like varnish, ...
                 $this->getResponse()->setHeader("Cache-Control", "public, max-age=" . $this->lifetime, true);
                 // add expire header
                 $date = new \DateTime("now");
                 $date->add(new \DateInterval("PT" . $this->lifetime . "S"));
                 $this->getResponse()->setHeader("Expires", $date->format(\DateTime::RFC1123), true);
             }
             $now = new \DateTime("now");
             $cacheItem = ["headers" => $this->getResponse()->getHeaders(), "rawHeaders" => $this->getResponse()->getRawHeaders(), "content" => $this->getResponse()->getBody(), "date" => $now->format(\DateTime::ISO8601)];
             $cacheKey = $this->defaultCacheKey;
             $deviceDetector = Tool\DeviceDetector::getInstance();
             if ($deviceDetector->wasUsed()) {
                 $cacheKey .= "_" . $deviceDetector->getDevice();
             }
             CacheManager::save($cacheItem, $cacheKey, ["output"], $this->lifetime, 1000);
         } catch (\Exception $e) {
             \Logger::error($e);
             return;
         }
     } else {
         // output-cache was disabled, add "output" as cleared tag to ensure that no other "output" tagged elements
         // like the inc and snippet cache get into the cache
         CacheManager::addClearedTag("output_inline");
     }
 }
コード例 #26
0
ファイル: TagManagement.php プロジェクト: sfie/pimcore
 /**
  *
  */
 public function dispatchLoopShutdown()
 {
     if (!\Pimcore\Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     $cacheKey = "outputfilter_tagmngt";
     $tags = 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);
             }
         }
         Cache::save($tags, $cacheKey, array("tagmanagement"), null, 100);
     }
     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);
 }