/**
  * 重构find方法,增加缓存的调用.
  *
  * @author 笨笨天才@20101127
  *
  * $params['cache']=array('use'=>true,'config'=>'short');
  * short是core.php定义的Cache:Config,默认为null
  *
  * @param string $type                      输入类型
  * @param mixed  $params                    输入参数
  * @param bool   $params['cache']['use']    是否使用缓存标志
  * @param string $params['cache']['config'] 缓存类型
  *
  * @return mixed $data 返回值
  */
 public function find($type, $params = array())
 {
     //!isset($params['cache'])
     if (isset($params['cache']) && $params['cache']['use'] !== false) {
         //判断是否不读取缓存数据
         $cache_config = isset($params['cache']['config']) ? $params['cache']['config'] : null;
         $model = isset($this->name) ? '_' . $this->name : 'appmodel';
         $paramsHash = md5(serialize($params));
         $cache_key = $model . '_' . $type . '_' . $this->locale . '_' . $paramsHash;
         //根据模型名称,type参数,多语言,params组成缓存唯一序号
         //	echo $params['cache']['config']."----".$cache_key."<br />";
         //pr($cache_config);
         $data = cache::read($cache_key, $cache_config);
         //print_r($params);
         if ($data) {
             //	echo "cached:".$cache_key."<br /><pre>";
             return $data;
         } else {
             //echo "not find cached:".$cache_key."<br /><pre>";
             //print_r($params);
             $data = parent::find($type, $params);
             cache::write($cache_key, $data, $cache_config);
             //将数据库的值写入缓存
             return $data;
         }
     } else {
         //echo "no cache:".$cache_key."<br /><pre>";
         return parent::find($type, $params);
     }
 }
 /**
  * 函数findrank,用户等级整合数组.
  *
  * @param $condition 用户信息
  * @param $cache_key 缓存识别
  * @param $lists_formated 用户列表
  * @param $lists 用户列表
  *
  * @return $lists_formated 用户等级整合列表
  */
 public function findrank()
 {
     $condition = '';
     $cache_key = md5($this->name . '_findrank');
     $lists_formated = cache::read($cache_key);
     if ($lists_formated) {
         return $lists_formated;
     } else {
         $lists = $this->find('all', array('conditions' => $condition));
         $lists_formated = array();
         if (is_array($lists)) {
             foreach ($lists as $k => $v) {
                 $lists_formated[$v['UserRank']['id']]['UserRank'] = $v['UserRank'];
                 if (is_array($v['UserRankI18n'])) {
                     $lists_formated[$v['UserRank']['id']]['UserRankI18n'][] = $v['UserRankI18n'];
                 }
                 $lists_formated[$v['UserRank']['id']]['UserRank']['name'] = '';
                 foreach ($lists_formated[$v['UserRank']['id']]['UserRankI18n'] as $key => $val) {
                     $lists_formated[$v['UserRank']['id']]['UserRank']['name'] .= $val['name'] . ' | ';
                 }
             }
         }
         cache::write($cache_key, $lists_formated);
         return $lists_formated;
     }
 }
Exemple #3
0
 /**
  * Die ganzen Klassen in einer Cache Datei speichern
  */
 public static function saveCache()
 {
     if (self::$isNewCache) {
         $cacheFile = cache::getFileName(0, 'autoloader');
         cache::write(json_encode([self::$classes, self::$dirs]), $cacheFile);
         self::$isNewCache = false;
     }
 }
 /**
  * 函数find_template 用于选择模板
  *
  * @param $sql sql语句
  * @param $cache_key 缓存的识别码
  * @param $template 缓存中读取模板
  *
  * @return $template 模板信息
  */
 public function find_template($sql)
 {
     $cache_key = md5($this->name . '_' . $sql);
     $template = cache::read($cache_key);
     if ($template) {
         return $template;
     } else {
         $template = $this->findAll($sql);
         cache::write($cache_key, $template);
         return $template;
     }
 }
 /**
  * 函数findall_ranks,获取商品等级.
  *
  * @param $cache_key 缓存调取商品等级
  * @param $rank_price 商品等级价
  * @param $p_r 所有商品等级
  *
  * @return $rank_price 商品等级对应价格
  */
 public function findall_ranks()
 {
     $cache_key = md5('ProductRank_findall');
     $rank_price = cache::read($cache_key);
     if (!$rank_price) {
         $p_r = $this->findall();
         $rank_price = array();
         if (is_array($p_r) && sizeof($p_r) > 0) {
             foreach ($p_r as $k => $v) {
                 $rank_price[$v['ProductRank']['product_id']][$v['ProductRank']['rank_id']] = $v;
             }
         }
         cache::write($cache_key, $rank_price);
         return $rank_price;
     } else {
         return $rank_price;
     }
 }
Exemple #6
0
 /**
  * Konstruktor
  * @param string $langCode
  * @return boolean
  */
 public function __construct($langCode)
 {
     if (!$langCode) {
         $langCode = FPCM_DEFAULT_LANGUAGE_CODE;
     }
     if (!is_dir(baseconfig::$langDir . $langCode)) {
         trigger_error('Try to load undefined language: ' . $langCode);
         return false;
     }
     $this->langCode = $langCode;
     $confFile = baseconfig::$langDir . $langCode . '/lang.cfg';
     if (!file_exists($confFile)) {
         trigger_error('Unable to find language config file in: ' . $langCode);
         return false;
     }
     $this->langList[$langCode] = file_get_contents($confFile);
     $this->helpFile = baseconfig::$langDir . $langCode . '/help.php';
     $this->cache = new cache('langcache_' . $langCode, 'system');
     if (!$this->cache->isExpired()) {
         $this->langData = $this->cache->read();
         return;
     }
     $moduleLangFiles = $langCode != FPCM_DEFAULT_LANGUAGE_CODE ? glob(baseconfig::$moduleDir . '*/*/lang/' . FPCM_DEFAULT_LANGUAGE_CODE . '/*.php') : array();
     $moduleLangFiles_langcode = glob(baseconfig::$moduleDir . '*/*/lang/' . $langCode . '/*.php');
     if (is_array($moduleLangFiles_langcode)) {
         $moduleLangFiles += $moduleLangFiles_langcode;
     }
     $langfiles = array_merge(glob(baseconfig::$langDir . $langCode . '/*.php'), is_array($moduleLangFiles) ? $moduleLangFiles : array());
     foreach ($langfiles as $file) {
         if (strpos($file, 'help.php') !== false) {
             continue;
         }
         include $file;
         if (!isset($lang)) {
             trigger_error('No language data defined in:' . $file);
             continue;
         }
         $this->langData = array_merge($this->langData, $lang);
     }
     $this->cache->write($this->langData, FPCM_LANGCACHE_TIMEOUT);
 }
 public function find($type, $params = array())
 {
     //echo $this->locale;
     if (isset($this->cache_config) && $this->cache_config !== false) {
         //判断是否不读取缓存数据
         $model = isset($this->name) ? '_' . $this->name : 'appmodel';
         $paramsHash = serialize($params);
         $cache_key = md5($model . '_' . $type . '_' . $this->locale . '_' . $paramsHash);
         //根据模型名称,type参数,多语言,params组成缓存唯一序号
         $data = cache::read($cache_key, $this->cache_config);
         //print_r($data);
         if ($data) {
             return $data;
         } else {
             $data = parent::find($type, $params);
             cache::write($cache_key, $data, $this->cache_config);
             //将数据库的值写入缓存
             return $data;
         }
     } else {
         return parent::find($type, $params);
     }
 }
Exemple #8
0
    public static function getBlog()
    {
        $cacheFile = cache::getFileName(0, 'rpBlog');
        // every 12 hours
        if (cache::exist($cacheFile, 43200)) {
            $content = json_decode(cache::read($cacheFile), true);
        } else {
            $content = apiserver::getBlogFile();
            cache::write($content, $cacheFile);
        }
        $return = [];
        foreach ($content as $blog) {
            $return[] = '
					<div class="item">
						<div class="circle"></div>
						<div class="text">
							<p><a target="_blank" href="' . $blog['link'] . '">' . $blog['name'] . '</a></p>
							<small>' . date(lang::get('dateformat'), strtotime($blog['date'])) . '</small>
						</div>
					</div>
					';
        }
        return implode(PHP_EOL, $return);
    }
Exemple #9
0
 /**
  * findassoc方法,取得id=>name的数组.
  *
  * @param $locale 输入语言
  *
  * @return $lists_formated 返回取得的数组
  */
 public function findassoc($locale = '')
 {
     $condition = " Brand.status ='1' ";
     $orderby = ' orderby asc ';
     $cache_key = md5($this->name . '_' . $locale);
     $lists_formated = cache::read($cache_key);
     if ($lists_formated) {
         return $lists_formated;
     } else {
         //		$lists=$this->findall($condition,'',$orderby);
         $lists = $this->find('all', array('order' => array($orderby, 'BrandI18n.name asc'), 'fields' => array('Brand.id', 'Brand.flash_config', 'Brand.url', 'Brand.img01', 'Brand.modified', 'BrandI18n.img01', 'BrandI18n.name'), 'conditions' => array($condition)));
         $lists_formated = array();
         if (is_array($lists)) {
             foreach ($lists as $k => $v) {
                 $lists_formated[$v['Brand']['id']] = $v;
             }
         }
         cache::write($cache_key, $lists_formated);
         return $lists_formated;
     }
 }
 /**
  * findassoc方法,取得id=>name的数组.
  *
  * @param $locale 输入语言
  *
  * @return $lists_formated 返回格式化的列表
  */
 public function findassoc($locale = '')
 {
     $condition = " CategoryProduct.status ='1' ";
     $orderby = ' orderby asc ';
     $cache_key = md5($this->name . '_' . $locale);
     $lists_formated = cache::read($cache_key);
     if ($lists_formated) {
         return $lists_formated;
     } else {
         $lists = $this->findall($condition, '', $orderby);
         $lists_formated = array();
         if (is_array($lists)) {
             foreach ($lists as $k => $v) {
                 $lists_formated[$v['CategoryProduct']['id']] = $v;
             }
         }
         cache::write($cache_key, $lists_formated);
         return $lists_formated;
     }
 }
Exemple #11
0
 /**
  * Erzeugt Page-Token zur Absicherung gegen 
  * @return string
  */
 public static function createPageToken()
 {
     $str = hash(self::defaultHashAlgo, '$' . baseconfig::$rootPath . '$pageToken$' . self::getSessionCookieValue() . '$' . http::getOnly('module') . '$');
     $cache = new cache(self::getPageTokenFieldName(), self::pageTokenCacheModule);
     $cache->cleanup(self::getPageTokenFieldName(), self::pageTokenCacheModule);
     $cache->write($str, FPCM_PAGETOKENCACHE_TIMEOUT);
     unset($cache);
     return $str;
 }
Exemple #12
0
 public static function getAddons()
 {
     $cacheFile = cache::getFileName(0, 'dynaoAddons');
     // jeden halben Tag
     if (cache::exist($cacheFile, 43200)) {
         $content = json_decode(cache::read($cacheFile), true);
     } else {
         $server = 'http://api.dynao.de/addons.json';
         $ch = curl_init($server);
         curl_setopt($ch, CURLOPT_PORT, 80);
         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla (Statuscheck-Script)');
         curl_setopt($ch, CURLOPT_TIMEOUT, 0);
         curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 300);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $curl = curl_exec($ch);
         curl_close($ch);
         $content = json_decode($curl, true);
         cache::write($content, $cacheFile);
     }
     $table = table::factory(['class' => ['table', 'table-spriped', 'table-hover']]);
     $table->addCollsLayout('60, 140, *, 110');
     $table->addRow()->addCell(lang::get('vote'))->addCell(lang::get('name'))->addCell(lang::get('description'))->addCell();
     $table->addSection('tbody');
     if (is_null($content)) {
         $table->addRow()->addCell(lang::get('no_entries'), ['colspan' => 4]);
     } else {
         foreach ($content as $addon) {
             $perc = round($addon['rate_sum'] / $addon['rate_ppl'] * 10);
             if ($perc < 33) {
                 $class = 'danger';
             } elseif ($perc < 66) {
                 $class = 'warning';
             } else {
                 $class = 'success';
             }
             $table->addRow()->addCell('<span class="label label-' . $class . '">' . $perc . '%</span>')->addCell($addon['title'])->addCell($addon['description'])->addCell('<a href="' . $addon['link'] . '" target="_blank" class="btn btn-sm btn-default">' . lang::get('download') . '</a>');
         }
     }
     return $table->show();
 }
Exemple #13
0
 /**
  * Controller abrufen
  * @return array
  */
 public static function getControllers()
 {
     $controllerCache = new cache('controllerCache', 'system');
     if (!$controllerCache->isExpired()) {
         $controllerList = $controllerCache->read();
         if (is_array($controllerList)) {
             return $controllerList;
         }
     }
     include_once loader::libGetFilePath('spyc', 'Spyc.php');
     if (!file_exists(self::$controllerFiles['actions']) || !file_exists(self::$controllerFiles['ajax'])) {
         die('ERROR: Controller config files not found.');
     }
     $actions = \Spyc::YAMLLoad(self::$controllerFiles['actions']);
     $ajaxs = \Spyc::YAMLLoad(self::$controllerFiles['ajax']);
     $modules = self::initModuleControllers();
     $controllerList = array_unique(array_merge($actions, $ajaxs, $modules));
     $controllerCache->write($controllerList, FPCM_LANGCACHE_TIMEOUT);
     return $controllerList;
 }
Exemple #14
0
 public static function getModules()
 {
     $cacheFile = cache::getFileName(0, 'dynaoModules');
     // jeden halben Tag
     if (cache::exist($cacheFile, 43200)) {
         $content = json_decode(cache::read($cacheFile), true);
     } else {
         $content = apiserver::getModulesFile();
         cache::write($content, $cacheFile);
     }
     $table = table::factory(['class' => ['table', 'table-spriped', 'table-hover']]);
     $table->addCollsLayout('60, 140, *, 110');
     $table->addRow()->addCell(lang::get('vote'))->addCell(lang::get('name'))->addCell(lang::get('description'))->addCell();
     $table->addSection('tbody');
     if (is_null($content) || !$content) {
         $table->addRow()->addCell(lang::get('no_entries'), ['colspan' => 4]);
     } else {
         foreach ($content as $addon) {
             $perc = round($addon['rate_sum'] / $addon['rate_ppl'] * 10);
             if ($perc < 33) {
                 $class = 'danger';
             } elseif ($perc < 66) {
                 $class = 'warning';
             } else {
                 $class = 'success';
             }
             $table->addRow()->addCell('<span class="label label-' . $class . '">' . $perc . '%</span>')->addCell($addon['title'])->addCell($addon['description'])->addCell('<a href="' . $addon['link'] . '" target="_blank" class="btn btn-sm btn-default">' . lang::get('import') . '</a>');
         }
     }
     return $table->show();
 }
 public function get_value($value, $mode = true)
 {
     $cache_config = 'short';
     if ($mode) {
         $paramsHash = md5(serialize($value));
         $cache_key = 'pic' . '_' . $paramsHash . '_file';
         $foo = cache::read($cache_key, $cache_config);
         //var_dump($foo);echo ";";$d=file_get_contents($value); imagecreatefromstring($d);die();
         //$foo = false;
         if ($foo) {
             $foo = imagecreatefromstring($foo);
             return $foo;
         } else {
             $foo = file_get_contents($value);
             cache::write($cache_key, $foo, $cache_config);
             //写入缓存
             return imagecreatefromgif($value);
         }
     }
     return imagecreatefromgif($value);
 }
Exemple #16
0
 protected static function fetchFile($filename, $cacheKey = null, $sha256 = null)
 {
     $file = $filename;
     if (null === $cacheKey) {
         $cacheKey = $filename;
         $file = self::$baseUrl . '/' . $filename;
     }
     // url-encode $ signs in URLs as bad proxies choke on them
     if (($pos = strpos($file, '$')) && preg_match('{^https?://.*}i', $file)) {
         $file = substr($file, 0, $pos) . '%24' . substr($file, $pos + 1);
     }
     $json = @file_get_contents($file);
     if ($sha256 && $sha256 !== hash('sha256', $json)) {
         return false;
     }
     $data = json_decode($json, true);
     if ($cacheKey && !empty($json)) {
         cache::write($cacheKey, $json);
     }
     return $data;
 }
Exemple #17
0
 /**
  * find_home_article方法,查询主要文章.
  *
  * @param $locale 输入语言
  *
  * @return $home_article 返回主要文章
  */
 public function find_home_article($locale)
 {
     $cache_key = md5($this->name . '_' . $locale . '_' . 'find_home_article');
     $home_article = cache::read($cache_key);
     if ($home_article) {
         return $home_article;
     } else {
         $home_article = $this->find_home_article('all', array('order' => array('Article.modified DESC'), 'conditions' => array('Article.status' => '1', 'Article.front' => '1'), 'limit' => 10));
         cache::write($cache_key, $home_article);
         return $home_article;
     }
 }