Exemple #1
0
 /**
  * Searches for a file at the filesystem of the game
  *
  * @param   string  $s_directory  directory name
  * @param   string  $s_file       filename with subdirectory
  * @param   string  $s_extension  extension to search for
  * @return  string|bool         Returns FALSE if the file is not found, otherwise the path
  *
  * @copyright   The original copyright hold the developers of the Kohana PHP frameworks.
  *              This method is a modified one.
  */
 public static function find_file($s_directory, $s_file, $s_extension = NULL)
 {
     if (Cache::getInstance()->exists('file_' . $s_file)) {
         return Cache::getInstance()->get('file_' . $s_file);
     }
     if (is_null($s_extension)) {
         $s_extension = EXT;
     } else {
         $s_extension ? $s_extension = ".{$s_extension}" : ($s_extension = '');
     }
     // Create a partial path of the filename
     $path = $s_directory . DIRECTORY_SEPARATOR . $s_file . $s_extension;
     // The file has not been found yet
     $m_found = FALSE;
     foreach (self::$a_paths as $directory) {
         if (is_file($directory . $path)) {
             // A path has been found, so set it and stop searching
             $m_found = $directory . $path;
             // if file was found and isn't cached, then cached it for one-day
             if (!Cache::getInstance()->exists('file_' . $s_file)) {
                 Cache::getInstance()->set("file_" . $s_file, $m_found, 86400);
             }
             break;
         }
     }
     return $m_found;
 }
 public function getGeoInfo($ip)
 {
     $cache = Cache::getInstance();
     $return = $cache->get('geo:' . $ip);
     if ($cache->wasResultFound()) {
         if (DEBUG_BAR) {
             Bootstrap::getInstance()->debugbar['messages']->addMessage("Cached GeoInfo: {$ip}");
         }
         return $return;
     }
     $client = new \GuzzleHttp\Client();
     //'https://geoip.maxmind.com/geoip/v2.1/city/me
     $res = $client->get($this->url . $ip, array('auth' => array($this->user, $this->password)));
     $body = $res->getBody(true);
     $json = json_decode($body);
     $return = array('countryCode' => $json->country->iso_code, 'countryName' => $json->country->names->en, 'state' => $json->subdivisions[0]->names->en, 'city' => $json->city->names->en);
     if (empty($return['city'])) {
         $return['city'] = 'Unknown';
     }
     if (empty($return['state'])) {
         $return['state'] = 'Unknown';
     }
     $cache->set('geo:' . $ip, $return, 3600);
     return $return;
 }
Exemple #3
0
 /**
  * Unlock
  */
 public function remove()
 {
     if ($this->key and Cache::getInstance()->get($this->key) == $this->rnd) {
         Cache::getInstance()->remove($this->key);
         $this->key = null;
     }
 }
Exemple #4
0
 public function testSetValueWithoutNamespaceWorks()
 {
     $cache = Cache::getInstance(array('driver' => 'array'));
     $cache->setNamespace('namespace', true);
     $cache->set('foo', 'bar');
     $this->assertEquals('bar', $cache->get('foo'));
 }
 public function _index()
 {
     $search = $_GET['search_field'];
     if (empty($search) || $search == "图片/作者/画集") {
         echo "<script>history.back(-1);</script>";
     }
     //查找用户
     $user = new user();
     $usersearch = $user->model->Get('all', array("NickName` LIKE '%{$search}%"), array(0, 5));
     if (empty($usersearch)) {
         $searchuser = "******";
     }
     foreach ($usersearch as $userresult) {
         $username = $userresult->NickName;
         $userid = $userresult->UserId;
         $searchuser .= '<div style="width:180px;float:left;"><div style="float:left"><a href="/user/' . $userid . '" title="' . $username . '"><img src="/upload/avatar_small/' . $userid . '_small.jpg"/></a></div><a href="/user/' . $userid . '" title="' . $username . '"><h4 style="color:#09F;">' . $username . '</h4></a></div>';
     }
     //查找标签
     $mem = Cache::getInstance();
     $tagdef = new tagdefine();
     $tags = $tagdef->model->Get('all', array("TagName` LIKE '%{$search}%"), array(0, 5));
     if (empty($tags)) {
         $tagline = "<h3>没有找到相关标签</h3>";
     }
     foreach ($tags as $tag) {
         $tagname = $tag->TagName;
         $postings = $mem->get($tagname);
         //var_dump($postings);
         $image = new image();
         $image->model->lockMutiQuery();
         foreach ($postings as $key => $value) {
             $image->model->Get_By_ImageId($key);
         }
         $image->model->MultiQuery();
         $imgs = $image->model->getresult();
         $favor = new favourite();
         $tagline .= '<div class="tagsinput"><a href="/tag/' . $tagname . '"><span class="tag"><span>' . $tagname . '&nbsp;&nbsp;</span></span></a>';
         foreach ($imgs as $r2) {
             //var_dump($r2);
             $tagline .= '<div style="margin:8px;"><div><a href="/files/' . $r2->imgurl . ' "><img src="/thumbnails/' . $r2->imgurl . '"/></a></div><div><a href="/user/' . $r2->author . '">' . $r2->user->NickName . '</a></br>描述:' . $r2->Description . '</div></div>';
         }
     }
     //查找画集
     $imggroup = new imagegroup();
     $searchgroup = $imggroup->model->Get('all', array("GroupName` LIKE '%{$search}%"), array(0, 5));
     if (empty($searchgroup)) {
         $groupline = "<h3>没有相关的画集</h3>";
     }
     $image = new image();
     foreach ($searchgroup as $groups) {
         $id = $groups->ImagegroupId;
         $imgs = $image->model->Get('all', array("GroupId={$id}"), array(0, 1));
         foreach ($imgs as $img) {
             $imgurl = rawurlencode($img->imgurl);
         }
         $groupline .= '<div><div><a href="/imagegroup/' . $id . '"><img src="/thumbnails/' . $imgurl . '"/></a></div><div><b>' . $groups->GroupName . '</b></br>' . $groups->user->NickName . '</div></div>';
     }
     $this->values = array("searchuser" => $searchuser, "title" => "搜索:{$search}", "searchtext" => $search, "searchtag" => $tagline, "searchgroup" => $groupline);
     $this->RenderTemplate('index');
 }
Exemple #6
0
 /**
  * Sets the nodes to work with.
  * @param array $nodes
  *
  * @return integer Number of nodes added.
  */
 public function setNodes(array $nodes)
 {
     $cache = Cache::getInstance();
     $available_servers = trim($cache->get($this->loadbalancer_cache_key));
     // CacheDisk returns " " when no cache.
     if (empty($available_servers)) {
         foreach ($nodes as $key => $node_properties) {
             $this->addNodeIfAvailable($key, $node_properties);
         }
         // Save in cache available servers (even if none):
         $serialized_nodes = serialize(array('nodes' => $this->nodes, 'total_weights' => $this->total_weights));
         $cache->set($this->loadbalancer_cache_key, $serialized_nodes, self::CACHE_EXPIRATION);
     } else {
         $available_servers = unserialize($available_servers);
         $this->nodes = $available_servers['nodes'];
         $this->total_weights = $available_servers['total_weights'];
     }
     $num_nodes = count($this->nodes);
     if (1 > $num_nodes) {
         // This exception will be shown for CACHE_EXPIRATION seconds until servers are up again.
         $message = "No available servers in profile";
         trigger_error($message);
         throw new Exception_500($message);
     }
     return $num_nodes;
 }
 function display($params)
 {
     $Log_Model = new Log_Model();
     $CACHE = Cache::getInstance();
     $options_cache = Option::getAll();
     extract($options_cache);
     $page = isset($params[4]) && $params[4] == 'page' ? abs(intval($params[5])) : 1;
     $author = isset($params[1]) && $params[1] == 'author' ? intval($params[2]) : '';
     $pageurl = '';
     $user_cache = $CACHE->readCache('user');
     if (!isset($user_cache[$author])) {
         show_404_page();
     }
     $author_name = $user_cache[$author]['name'];
     //page meta
     $site_title = $author_name . ' - ' . $site_title;
     $sqlSegment = "and author={$author} order by date desc";
     $sta_cache = $CACHE->readCache('sta');
     $lognum = $sta_cache[$author]['lognum'];
     $total_pages = ceil($lognum / $index_lognum);
     if ($page > $total_pages) {
         $page = $total_pages;
     }
     $start_limit = ($page - 1) * $index_lognum;
     $pageurl .= Url::author($author, 'page');
     $Log_Model = new Log_Model();
     $logs = $Log_Model->getLogsForHome($sqlSegment, $page, $index_lognum);
     $page_url = pagination($lognum, $index_lognum, $page, $pageurl);
     include View::getView('header');
     include View::getView('log_list');
 }
function S($name, $value = '', $expire = '', $type = '', $options = null)
{
    static $_cache = array();
    alias_import('Cache');
    //取得缓存对象实例
    $cache = Cache::getInstance($type, $options);
    if ('' !== $value) {
        if (is_null($value)) {
            // 删除缓存
            $result = $cache->rm($name);
            if ($result) {
                unset($_cache[$type . '_' . $name]);
            }
            return $result;
        } else {
            // 缓存数据
            $cache->set($name, $value, $expire);
            $_cache[$type . '_' . $name] = $value;
        }
        return;
    }
    if (isset($_cache[$type . '_' . $name])) {
        return $_cache[$type . '_' . $name];
    }
    // 获取缓存数据
    $value = $cache->get($name);
    $_cache[$type . '_' . $name] = $value;
    return $value;
}
Exemple #9
0
 static function getAll()
 {
     $CACHE = Cache::getInstance();
     $options_cache = $CACHE->readCache('options');
     $options_cache['site_title'] = $options_cache['site_title'] ? $options_cache['site_title'] : $options_cache['blogname'];
     $options_cache['site_description'] = $options_cache['site_description'] ? $options_cache['site_description'] : $options_cache['bloginfo'];
     return $options_cache;
 }
Exemple #10
0
 function deleteAll($conditions, $params = array())
 {
     if (!empty($this->cache) and Base::getConfig('cache') >= 1 and Base::getConfig('cache_query') >= 1) {
         $cache = Cache::getInstance($this->tablename . '.queries');
         $cache->destroy();
     }
     return parent::deleteAll($conditions, $params);
 }
Exemple #11
0
 public function _initialize()
 {
     //$this->cache = Cache::getInstance('File', array('expire' => '60'));
     $s = microtime(1);
     //localhost 超级慢 ?
     $this->cache = Cache::getInstance('Redis');
     $e = microtime(1);
     //echo $e - $s;
 }
Exemple #12
0
 /**
  * 性能优化
  */
 public function performOp()
 {
     if ($_GET['type'] == 'clear') {
         $lang = Language::getLangContent();
         $cache = Cache::getInstance(C('cache.type'));
         $cache->clear();
         showMessage($lang['nc_common_op_succ']);
     }
     Tpl::showpage('setting.perform_opt');
 }
Exemple #13
0
 public static function __callstatic($method, $args)
 {
     if (self::$handler === null) {
         Cache::getInstance(C('CACHE_DRIVER', null, 'memcache'));
     }
     //调用缓存驱动的方法
     if (method_exists(self::$handler, $method)) {
         return call_user_func_array(array(self::$handler, $method), $args);
     }
 }
Exemple #14
0
 public static function GetFromCached()
 {
     $mem = Cache::getInstance();
     if (!$mem->get("allow")) {
         return false;
     }
     self::$allow = $mem->get("allow");
     self::$parents = $mem->get("parents");
     self::$Rolelist = $mem->get("role");
 }
Exemple #15
0
 public function __construct($config)
 {
     $redis_config = array('tcp' => $config->redis->tcp, 'host' => $config->redis->host, 'port' => $config->redis->port, 'database' => $config->redis->database);
     $this->_redis_handler = Cache::getInstance($redis_config);
     //session前缀
     if (isset($config->redis->cache_key_prefix)) {
         $this->_cache_key_prefix = $config->redis->cache_key_prefix;
     }
     parent::__construct();
 }
Exemple #16
0
 function getNaviNameByType($type)
 {
     $CACHE = Cache::getInstance();
     $navi_cache = $CACHE->readCache('navi');
     foreach ($navi_cache as $val) {
         if ($val['type'] == $type) {
             return $val['naviname'];
         }
     }
     return '';
 }
Exemple #17
0
 /**
  * Save data to cache.
  *
  * @param string  $key   Data to save as.
  * @param mixed   $value Data to save.
  * @param boolean $db    Cache to database.
  *
  * @return void
  */
 public static function saveData($key, $value, $db = false)
 {
     $cache = Cache::getInstance();
     $cache->data[$key] = $value;
     if ($key != 'ModelCachingFields' && $db && Config::getSetting('cache_to_database', false, false) && Clockwork::isModuleLoaded('Data/Database')) {
         $lifespan = $db === true ? 0 : $db;
         if (($obj = Caching::create($key, '*`key`')) === false) {
             $obj = new Caching();
         }
         $obj->set('key', $key)->set('value', serialize($value))->set('object', is_object($value) ? get_class($value) : '')->set('lifespan', $lifespan)->save();
     }
 }
Exemple #18
0
	/**
	 * 初始化,未启用内存保存时默认使用lock表存储
	 *
	 * @param unknown_type $type
	 */
	private static function init($type){
		if (C('cache_open')){
			self::$lock = Cache::getInstance('cacheredis');
		}else{
			self::$lock = new lock();
		}
		if (!isset(self::$processid[$type])){
			$ip = sprintf('%u',ip2long(getIp()));
			self::$processid[$type] = str_pad($ip,10,'0').self::parsekey($type);;
			self::$lockid[$type] = str_pad($ip,11,'0').self::parsekey($type);;
		}
	}
Exemple #19
0
 function display($params)
 {
     $Log_Model = new Log_Model();
     $CACHE = Cache::getInstance();
     $options_cache = Option::getAll();
     extract($options_cache);
     $page = isset($params[4]) && $params[4] == 'page' ? abs(intval($params[5])) : 1;
     $sortid = '';
     if (!empty($params[2])) {
         if (is_numeric($params[2])) {
             $sortid = intval($params[2]);
         } else {
             $sort_cache = $CACHE->readCache('sort');
             foreach ($sort_cache as $key => $value) {
                 $alias = addslashes(urldecode(trim($params[2])));
                 if (array_search($alias, $value, true)) {
                     $sortid = $key;
                     break;
                 }
             }
         }
     }
     $pageurl = '';
     $sort_cache = $CACHE->readCache('sort');
     if (!isset($sort_cache[$sortid])) {
         show_404_page();
     }
     $sort = $sort_cache[$sortid];
     $sortName = $sort['sortname'];
     //page meta
     $site_title = $sortName . ' - ' . $site_title;
     if (!empty($sort_cache[$sortid]['description'])) {
         $site_description = $sort_cache[$sortid]['description'];
     }
     if ($sort['pid'] != 0 || empty($sort['children'])) {
         $sqlSegment = "and sortid={$sortid}";
     } else {
         $sortids = array_merge(array($sortid), $sort['children']);
         $sqlSegment = "and sortid in (" . implode(',', $sortids) . ")";
     }
     $sqlSegment .= " order by sortop desc, date desc";
     $lognum = $Log_Model->getLogNum('n', $sqlSegment);
     $total_pages = ceil($lognum / $index_lognum);
     if ($page > $total_pages) {
         $page = $total_pages;
     }
     $pageurl .= Url::sort($sortid, 'page');
     $logs = $Log_Model->getLogsForHome($sqlSegment, $page, $index_lognum);
     $page_url = pagination($lognum, $index_lognum, $page, $pageurl);
     $template = !empty($sort['template']) && file_exists(TEMPLATE_PATH . $sort['template'] . '.php') ? $sort['template'] : 'log_list';
     include View::getView('header');
     include View::getView($template);
 }
Exemple #20
0
 public function collectCates()
 {
     setTimeLimit(3600);
     $ccate = FDB::fetchFirst('SELECT * FROM ' . FDB::table('goods_cate_collect') . ' LIMIT 0,1');
     if (!$ccate) {
         return false;
     }
     FDB::query('DELETE FROM ' . FDB::table('goods_cate_collect') . " WHERE id = '{$ccate['id']}'");
     global $_FANWE;
     Cache::getInstance()->loadCache('business');
     //QQ号
     define('PAIPAI_API_UIN', trim($_FANWE['cache']['business']['paipai']['uin']));
     //令牌
     define('PAIPAI_API_APPOAUTHID', trim($_FANWE['cache']['business']['paipai']['appoauthid']));
     //APP_KEY
     define('PAIPAI_API_APPOAUTHKEY', trim($_FANWE['cache']['business']['paipai']['appoauthkey']));
     define('PAIPAI_API_ACCESSTOKEN', trim($_FANWE['cache']['business']['paipai']['accesstoken']));
     define('PAIPAI_API_USERID', trim($_FANWE['cache']['business']['paipai']['userid']));
     $sdk = new PaiPaiOpenApiOauth(PAIPAI_API_APPOAUTHID, PAIPAI_API_APPOAUTHKEY, PAIPAI_API_ACCESSTOKEN, PAIPAI_API_UIN);
     $sdk->setApiPath("/attr/getNavigationChildList.xhtml");
     $sdk->setMethod("get");
     $sdk->setCharset("utf-8");
     $sdk->setFormat("json");
     $params =& $sdk->getParams();
     $params["navigationId"] = $ccate['cid'];
     //请求数据
     $json = $sdk->invoke();
     $json = preg_replace("/[\r\n]/", '', $json);
     preg_match("/getNavigationChildListSuccess\\((.+?)\\);\\}catch\\(/", $json, $list);
     $list = json_decode($list[1], true);
     $sort_file = FANWE_ROOT . '/public/records/cate.sort.php';
     $sort = (int) @file_get_contents($sort_file);
     if (isset($list['childList'])) {
         foreach ($list['childList'] as $item) {
             $cate = array();
             $cate['type'] = 'paipai';
             $cate['id'] = (int) $item['navigationId'];
             if ($cate['id'] > 0) {
                 $cate['pid'] = $ccate['cid'] == 0 ? '' : $ccate['cid'];
                 $cate['name'] = (string) $item['navigationName'];
                 $cate['pids'] = empty($ccate['pids']) ? $cate['pid'] : $ccate['pids'] . ',' . $cate['pid'];
                 $cate['sort'] = ++$sort;
                 FDB::insert('goods_cates', $cate, false, true);
                 if ((int) $item['isClass'] == 0) {
                     FDB::insert('goods_cate_collect', array('id' => 'NULL', 'cid' => $cate['id'], 'pids' => $cate['pids']));
                 }
             }
         }
         @file_put_contents($sort_file, $sort);
     }
     return true;
 }
 static function verifyVCode($token, $tel, $code)
 {
     $Cache = Cache::getInstance('File', array('expire' => '610'));
     $truth_code = $Cache->get('vcode_' . $token . $tel);
     if (!empty($truth_code) && $truth_code == $code) {
         Log::record('verifyvcode succeed:' . $token . ":" . $tel . ":" . $code . "", Log::DEBUG);
         Log::save();
         return true;
     }
     Log::record('verifyvcode fail:' . $token . ":" . $tel . ":" . $code . ":" . $truth_code);
     Log::save();
     return false;
 }
Exemple #22
0
 function addComment($params)
 {
     $name = isset($_POST['comname']) ? addslashes(trim($_POST['comname'])) : '';
     $content = isset($_POST['comment']) ? addslashes(trim($_POST['comment'])) : '';
     $mail = isset($_POST['commail']) ? addslashes(trim($_POST['commail'])) : '';
     $url = isset($_POST['comurl']) ? addslashes(trim($_POST['comurl'])) : '';
     $imgcode = isset($_POST['imgcode']) ? addslashes(trim(strtoupper($_POST['imgcode']))) : '';
     $blogId = isset($_POST['gid']) ? intval($_POST['gid']) : -1;
     $pid = isset($_POST['pid']) ? intval($_POST['pid']) : 0;
     if (ISLOGIN === true) {
         $CACHE = Cache::getInstance();
         $user_cache = $CACHE->readCache('user');
         $name = addslashes($user_cache[UID]['name_orig']);
         $mail = addslashes($user_cache[UID]['mail']);
         $url = addslashes(BLOG_URL);
     }
     if ($url && strncasecmp($url, 'http', 4)) {
         $url = 'http://' . $url;
     }
     doAction('comment_post');
     $Comment_Model = new Comment_Model();
     $Comment_Model->setCommentCookie($name, $mail, $url);
     if ($Comment_Model->isLogCanComment($blogId) === false) {
         emMsg('评论失败:该文章已关闭评论');
     } elseif ($Comment_Model->isCommentExist($blogId, $name, $content) === true) {
         emMsg('评论失败:已存在相同内容评论');
     } elseif (ROLE == ROLE_VISITOR && $Comment_Model->isCommentTooFast() === true) {
         emMsg('评论失败:您提交评论的速度太快了,请稍后再发表评论');
     } elseif (empty($name)) {
         emMsg('评论失败:请填写姓名');
     } elseif (strlen($name) > 20) {
         emMsg('评论失败:姓名不符合规范');
     } elseif ($mail != '' && !checkMail($mail)) {
         emMsg('评论失败:邮件地址不符合规范');
     } elseif (ISLOGIN == false && $Comment_Model->isNameAndMailValid($name, $mail) === false) {
         emMsg('评论失败:禁止使用管理员昵称或邮箱评论');
     } elseif (!empty($url) && preg_match("/^(http|https)\\:\\/\\/[^<>'\"]*\$/", $url) == false) {
         emMsg('评论失败:主页地址不符合规范', 'javascript:history.back(-1);');
     } elseif (empty($content)) {
         emMsg('评论失败:请填写评论内容');
     } elseif (strlen($content) > 8000) {
         emMsg('评论失败:内容不符合规范');
     } elseif (ROLE == ROLE_VISITOR && Option::get('comment_needchinese') == 'y' && !preg_match('/[\\x{4e00}-\\x{9fa5}]/iu', $content)) {
         emMsg('评论失败:评论内容需包含中文');
     } elseif (ISLOGIN == false && Option::get('comment_code') == 'y' && session_start() && (empty($imgcode) || $imgcode !== $_SESSION['code'])) {
         emMsg('评论失败:验证码错误');
     } else {
         $_SESSION['code'] = null;
         $Comment_Model->addComment($name, $content, $mail, $url, $imgcode, $blogId, $pid);
     }
 }
 public function getDeliveryService()
 {
     // If Cache exists, we return it
     $cache_key = md5($this->module->name . '.getDeliveryService.' . $this->city);
     if ($result = Cache::getInstance()->get($cache_key)) {
         return json_decode($result, true);
     }
     $url = 'http://localhost/api/index.php';
     $params = '?mca_email=' . Configuration::get('MYMOD_CA_EMAIL') . '&mca_token=' . Configuration::get('MYMOD_CA_TOKEN') . '&method=getShippingCost&city=' . $this->city;
     $result = json_decode(file_get_contents($url . $params), true);
     // Cache result
     Cache::getInstance()->set($cache_key, json_encode($result));
     return $result;
 }
 private function getToken()
 {
     $Cache = Cache::getInstance('File', array('expire' => '3600'));
     $access_token = $Cache->get("access_token");
     if (!empty($access_token)) {
         return $access_token;
     }
     $tokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->appid . "&secret=" . $this->secret;
     $remote_resp = file_get_contents($tokenUrl);
     $ret_json = json_decode($remote_resp, true);
     $access_token = $ret_json['access_token'];
     $Cache->set("access_token", $access_token);
     return $access_token;
 }
Exemple #25
0
    public function getColor()
    {
        global $link;
        $cache_key = 'color-list-data';
        if (!($result = Cache::getInstance()->get($cache_key))) {
            $result = Db::getInstance()->ExecuteS('SELECT * 
					FROM `' . _DB_PREFIX_ . 'color` ORDER BY `top` ASC');
            foreach ($result as &$row) {
                $row['link'] = $link->getLink($row['rewrite']);
            }
            //Cache::getInstance()->set($cache_key,$result);
        }
        return $result;
    }
Exemple #26
0
 protected function getAllOpt()
 {
     $r = array('gravatar' => self::get('gravatar'), 'googleapis' => self::get('googleapis'), 'worg' => self::get('worg'));
     foreach ($r as $key => $test) {
         if (is_null($test)) {
             $m = Database::getInstance();
             $m->query('INSERT INTO `' . DB_PREFIX . "options` (`option_name`,`option_value`) VALUES ('moecdn_{$key}','" . self::$options[$key] . "');");
             $c = Cache::getInstance();
             $c->updateCache('options');
             unset($r[$key]);
         }
     }
     return $r;
 }
 public function public_cache()
 {
     if (isset($_GET['type'])) {
         import("Dir");
         import('Cacheapi');
         $Cache = new Cacheapi();
         $Cachepath = RUNTIME_PATH;
         $Dir = new Dir();
         $type = $this->_get("type");
         switch ($type) {
             case "site":
                 try {
                     $Dir->del($Cachepath);
                     $Dir->del($Cachepath . "Data/");
                     $Dir->del($Cachepath . "Data/_fields/");
                 } catch (Exception $exc) {
                 }
                 try {
                     $cache = Cache::getInstance();
                     $cache->clear();
                 } catch (Exception $exc) {
                 }
                 $modules = array(array('name' => "菜单,模型,栏目缓存更新成功!", 'function' => 'site_cache', 'param' => ''), array('name' => "模型字段缓存更新成功!", 'function' => 'model_field_cache', 'param' => ''), array('name' => "模型content处理类缓存更新成功!", 'function' => 'model_content_cache', 'param' => ''), array('name' => "会员相关缓存更新成功!", 'function' => 'member_cache', 'param' => ''), array('name' => "应用更新成功!", 'function' => 'appstart_cache', 'param' => ''), array('name' => "敏感词缓存生成成功!", 'function' => 'censorword_cache', 'param' => ''));
                 foreach ($modules as $k => $v) {
                     try {
                         if ($v['function']) {
                             $Cache->{$v}['function']();
                         }
                     } catch (Exception $exc) {
                     }
                 }
                 $this->success("站点数据缓存更新成功!", U('Index/public_cache'));
                 break;
             case "template":
                 $Dir->delDir($Cachepath . "Cache/");
                 $this->success("模板缓存清理成功!", U('Index/public_cache'));
                 break;
             case "logs":
                 $Dir->del($Cachepath . "Logs/");
                 $this->success("站点日志清理成功!", U('Index/public_cache'));
                 break;
             default:
                 $this->error("请选择清楚缓存类型!");
                 break;
         }
     } else {
         $this->display("Index:cache");
     }
 }
Exemple #28
0
 private function __construct()
 {
     // fetch current page
     $page = '/';
     if (isset($_REQUEST['page'])) {
         $page = trim($_REQUEST['page']);
     }
     // update pages
     $this->page = $page;
     $this->config = Config::getInstance();
     // get instance of Template
     $this->template = new Template();
     $this->posts = Posts::getInstance();
     $this->cache = Cache::getInstance();
     $this->route();
 }
 public function index()
 {
     //动态缓存
     //找缓存类的对象
     $cache = Cache::getInstance();
     $t = $cache->get("t");
     //获得缓存数据
     if ($t == NULL) {
         $t = time();
         $cache->set("t", $t, 3);
         //设置缓存数据
     }
     //$cache->rm("t");//删除指定缓存
     $this->assign("t", $t);
     $this->display();
 }
 public function create(RESTApiRequest $request, $parent_id)
 {
     $type = $request->getData('type');
     $media_id = (int) $request->getData('media_id');
     if (empty($type)) {
         throw new RESTBadRequest("Type is empty");
     }
     if (empty($media_id)) {
         throw new RESTBadRequest("Media ID is empty");
     }
     if (empty($this->types_map[$type])) {
         throw new RESTBadRequest("Type is not supported");
     }
     $media = \Mysql::getInstance()->from($this->types_map[$type]['target'])->where(array('id' => $media_id))->get()->first();
     if (empty($media)) {
         throw new RESTNotFound("Media not found");
     }
     $cache = \Cache::getInstance();
     $playback_session = $cache->get($parent_id . '_playback');
     if (!empty($playback_session) && is_array($playback_session)) {
         if ($playback_session['type'] == 'tv-channel' && isset($playback_session['id']) && $playback_session['id'] == $media_id && !empty($playback_session['streamer_id'])) {
             $now_playing_streamer_id = $playback_session['streamer_id'];
         } else {
             if ($playback_session['type'] == 'video' && isset($playback_session['id']) && $playback_session['id'] == $media_id && !empty($playback_session['storage'])) {
                 $storage_name = $playback_session['storage'];
             } else {
                 if ($playback_session['type'] == 'karaoke' && isset($playback_session['id']) && $playback_session['id'] == $media_id && !empty($playback_session['storage'])) {
                     $storage_name = $playback_session['storage'];
                 } else {
                     if ($playback_session['type'] == 'tv-archive' && isset($playback_session['id']) && $playback_session['id'] == $media_id && !empty($playback_session['storage'])) {
                         $storage_name = $playback_session['storage'];
                     }
                 }
             }
         }
     }
     if ($type == 'tv-archive') {
         $channel = \Itv::getChannelById($media['ch_id']);
         $now_playing_content = $channel ? $channel['name'] : '--';
     } else {
         $now_playing_content = $media[$this->types_map[$type]['title_field']];
     }
     \Mysql::getInstance()->insert('user_log', array('uid' => $parent_id, 'action' => 'play', 'param' => $now_playing_content, 'time' => 'NOW()', 'type' => $this->types_map[$type]['code']));
     return \Mysql::getInstance()->update('users', array('now_playing_type' => $this->types_map[$type]['code'], 'now_playing_link_id' => $media_id, 'now_playing_content' => $now_playing_content, 'now_playing_streamer_id' => isset($now_playing_streamer_id) ? $now_playing_streamer_id : 0, 'storage_name' => isset($storage_name) ? $storage_name : '', 'now_playing_start' => 'NOW()', 'last_active' => 'NOW()'), array('id' => $parent_id))->result();
 }