Exemple #1
0
 public static function DeleteComment($id)
 {
     try {
         $safeId = ensureInt($id);
     } catch (Exception $e) {
         throw new Exception('删除评论时出错:' . $e->getMessage());
         return null;
     }
     $commentInfo = self::GetCommentInfo($id);
     $cacheKey = 'postcomment_' . $commentPost['comment_post`'];
     $cache = getCache($cacheKey);
     if ($commentInfo && $cache) {
         while (list($key, $value) = each($cache)) {
             if ($value['comment_id'] == $safeId) {
                 unset($cache[$key]);
                 break;
             }
         }
         setCache($cacheKey, $cache);
     }
     $cacheKey = 'commentinfo_' . $safeId;
     setCache($cacheKey, null);
     $sql = "delete from wa_comment where comment_id = {$safeId} limit 1";
     $ret = runSql($sql);
     if (!$ret) {
         throw new Exception('删除评论时出错。');
         return null;
     }
     return $ret;
 }
Exemple #2
0
function mysql_query_cache($sql, $linkIdentifier = false, $timeout = 4)
{
    $mysqli = $GLOBALS['mysqli'];
    //首先调用上面的getCache函数,如果返回值不为false的话,就说明是从memcached服务器获取的数据
    //如果返回false,此时就需要直接从数据库中获取数据了。
    //需要注意的是这里使用操作的命令加上sql语句的md5码作为一个特定的key,可能大家觉得使用数据项的
    //名称作为key会比较自然一点。运行memcached加上"-vv"参数,并且不作为daemon运行的话,可以看见
    //memcached处理时输出的相关信息
    if (!($cache = getCache(md5("mysql_query" . $sql)))) {
        $cache = false;
        $r = mysqli_query($mysqli, $sql);
        $fields = mysqli_fetch_fields($r);
        //读取数据库,并将结果放入$cache数组中
        for ($i = 0; $row = mysqli_fetch_array($r); $i++) {
            $j = 0;
            foreach ($fields as $val) {
                $cache[$i][$val->name] = $row[$j];
                $j++;
            }
        }
        //将数据放入memcached服务器中,如果memcached服务器没有开的话,此语句什么也不会做
        //如果开启了服务器的话,数据将会被缓存到memcached服务器中
        if (!setCache(md5("mysql_query" . $sql), $cache, $timeout)) {
            # If we get here, there isn’t a memcache daemon running or responding
            echo "apt-get install memcached";
        }
    }
    return $cache;
}
Exemple #3
0
function mysql_query_cache($sql, $linkIdentifier = false, $timeout = MEMCACHE_STATICDATA_TIMEOUT, $goSilent = true)
{
    global $memCache;
    if (is_null($memCache)) {
        mc_open();
    }
    if (($cache = getCache(md5("mysql_query" . $sql))) === false) {
        if (!$goSilent) {
            dprintf("mysql_query_cache(): using MySQL data.", $sql);
        }
        $cache = false;
        $r = $linkIdentifier !== false ? mysql_query($sql, $linkIdentifier) : mysql_query($sql);
        if (is_resource($r) && ($rows = mysql_num_rows($r)) !== 0) {
            while ($row = mysql_fetch_assoc($r)) {
                $results[] = $row;
            }
            $cache = serialize($results);
            if (!setCache(md5("mysql_query" . $sql), $cache, $timeout)) {
                # If we get here, there isn't a memcache daemon running or responding
                if (!$goSilent) {
                    dprintf("mysql_query_cache(): failed to update memcached");
                }
            }
            mysql_free_result($r);
        }
    } else {
        if (!$goSilent) {
            dprintf("mysql_query_cache(): using memcached data.");
        }
    }
    return unserialize($cache);
}
  /**
   * 前期执行
   */
  public function _initialize(){
	//配置
	$configs = getCache('Config:list');
	$this->configs = $configs;
	$this->assign('configs',$configs);
    //dump($configs);exit;
	//购物车
	/*
	$shopcart=  session('shopcart');
	$this->shopcartnum = count($shopcart);
	$this->assign('shopcartnum', count($shopcart));
	*/
	//上级
	if($_GET['r']){
	  cookie('r',$_GET['r']);
	}
	//会员信息
	$member_msg = session('member_msg');
	$user = unserialize(authcode($member_msg,'DECODE'));
    $user['id'] = 107;//模拟用户

	if($user){
	  if($user['openid'] && !$user['id']){
		$to_url = C('MEMBER_SITE_URL').'/Member/message';
	    header("location:".$to_url);exit;
	  }
	  $model = D('Member');
	  $data['a.id'] = $user['id'];
	  $db_pre = C('DB_PREFIX');
	  $user = $model->alias('a')->join('`'.$db_pre.'member_wallet` as b on a.id=b.member_id')->join('`'.$db_pre.'member_msg` as c on a.id=c.member_id')->field('a.id,a.pid,a.nickname,logo,lv,lv_name,email,utype,username,realname,mobile,password,salt,pv_id,ct_id,province,city,create_time,last_login_time,balance,frozen,c.sex')->where($data)->find();
	  //echo $model->getlastsql();exit;
	  if($user['balance']==null){
		$data['update_time'] = time();
		$model->add($data);
	    $user['balance'] = 0;
		$user['frozen'] = 0;
		$user['update_time'] = time();
	  }
	  //dump($user);
	  $user['username'] = $user['username'] ? $user['username'] : $user['mobile'];
	  $this->user = $user;
	  $this->assign('user',$user);
	}
	$this->iswx = isWeixin();//是否微信浏览器
	$this->login_url = C('SITE_URL').'/index.php/Public/login';
	$this->register_url = C('SITE_URL').'/index.php/Public/register';
	if(!IS_AJAX){
		if($_SERVER['QUERY_STRING']){
		  $from_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
		}else{
		  $from_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];	
		}
		$from_url_except = array('login','register','reg_do','verify','checkLogin','check_username','check_email','get_city');
		if(array_search(ACTION_NAME,$from_url_except)===false && CONTROLLER_NAME!='Public'){
		  $_SESSION['self_url'] = $from_url;
		}	
	}
	
	$this->assign('self_url',$_SESSION['self_url']);
  }
 public function testServices()
 {
     $ins = getAuth();
     $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\Auth\IAuth::class, $ins);
     $ins = getView();
     $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\View\IView::class, $ins);
     $ins = getLog();
     $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\Log\ILog::class, $ins);
     //        $ins = getDB();
     //        $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\Database\MedooDB::class, $ins);
     //        $ins = getRedis();
     //        $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\Database\PRedis::class, $ins);
     //        $ins = getDataPool();
     //        $this->assertInstanceOf(\Wwtg99\DataPool\Common\IDataPool::class, $ins);
     $ins = getCache();
     $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\Storage\Cache::class, $ins);
     $ins = getSession();
     $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\Storage\SessionUtil::class, $ins);
     $ins = getCookie();
     $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\Storage\CookieUtil::class, $ins);
     $ins = getOValue();
     $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\Storage\OldValue::class, $ins);
     $ins = getAssets();
     $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\View\AssetsManager::class, $ins);
     $ins = getMailer();
     $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\Utils\Mail::class, $ins);
     $ins = Flight::Express();
     $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\Utils\Express::class, $ins);
     $ins = getPlugin('php');
     $this->assertInstanceOf(\Wwtg99\Flight2wwu\Component\Plugin\IPlugin::class, $ins);
 }
Exemple #6
0
function mysql_query_cache($sql, $linkIdentifier = false, $timeout = 4)
{
    //首先调用上面的getCache函数,如果返回值不为false的话,就说明是从memcached服务器获取的数据
    //如果返回false,此时就需要直接从数据库中获取数据了。
    //需要注意的是这里使用操作的命令加上sql语句的md5码作为一个特定的key,可能大家觉得使用数据项的
    //名称作为key会比较自然一点。运行memcached加上"-vv"参数,并且不作为daemon运行的话,可以看见
    //memcached处理时输出的相关信息
    if (!($cache = getCache(md5("mysql_query" . $sql)))) {
        $cache = false;
        $r = $linkIdentifier != false ? mysql_query($sql, $linkIdentifier) : mysql_query($sql);
        //读取数据库,并将结果放入$cache数组中
        if (is_resource($r) && ($rows = mysql_num_rows($r)) != 0) {
            for ($i = 0; $i < $rows; $i++) {
                $fields = mysql_num_fields($r);
                $row = mysql_fetch_array($r);
                for ($j = 0; $j < $fields; $j++) {
                    if ($i == 0) {
                        $columns[$j] = mysql_field_name($r, $j);
                    }
                    $cache[$i][$columns[$j]] = $row[$j];
                }
            }
            //将数据放入memcached服务器中,如果memcached服务器没有开的话,此语句什么也不会做
            //如果开启了服务器的话,数据将会被缓存到memcached服务器中
            if (!setCache(md5("mysql_query" . $sql), $cache, $timeout)) {
                # If we get here, there isn’t a memcache daemon running or responding
            }
        }
    }
    return $cache;
}
Exemple #7
0
function generateCache($file, $content)
{
    $cache_file = getCache($file);
    $dir = dirname($cache_file);
    mkdir($dir, 0777, true);
    file_put_contents($cache_file, $content);
    touchCache($file);
}
    public function run()
    {
        global $_FANWE;
        $root = array();
        $root['return'] = 1;
        $key = 'm/sharecate';
        $cache_list = getCache($key);
        if ($cache_list !== NULL || TIME_UTC - $cache_list['cache_time'] > 600) {
            $cate_list = array();
            $min_time = $this->getQuarterMinTime();
            $max_time = getTodayTime();
            FanweService::instance()->cache->loadCache('albums');
            $album_cate = $_FANWE['cache']['albums']['category'];
            foreach ($album_cate as $k => $v) {
                $cate = array();
                $cate['cate_id'] = $v['id'];
                $cate['cate_name'] = $v['name'];
                $cate['short_name'] = $v['name'];
                $cate['cate_code'] = $v['cate_code'];
                $cate['cate_icon'] = FS("Image")->getImageUrl($v['img'], 2);
                $cate['desc'] = $v['desc'];
                $cate['create_time'] = $v['create_time'];
                //获取本季分享数量
                $share_count_sql = 'select count(DISTINCT s.share_id) from ' . FDB::table("share") . ' as s 
					INNER JOIN ' . FDB::table("album_share") . ' as al on s.share_id = al.share_id where al.cid = ' . $v['id'] . " and s.day_time >= {$min_time} AND s.day_time <= {$max_time} ";
                $cate['share_count'] = FDB::resultFirst($share_count_sql);
                $cate['img_tags'] = array();
                $img_size = 320;
                $sql = 'select s.share_id,al.title,sp.img from ' . FDB::table("share") . ' as s
					INNER JOIN ' . FDB::table("album_share") . ' as als ON s.share_id = als.share_id 
					INNER JOIN ' . FDB::table("album") . ' as al ON als.album_id = al.id
					INNER JOIN ' . FDB::table("share_photo") . " as sp ON s.share_id = sp.share_id \r\n\t\t\t\t\tWHERE s.day_time >= {$min_time} AND s.day_time <= {$max_time} AND als.cid = " . $v['id'] . " GROUP BY s.share_id ORDER BY s.share_id desc limit 5";
                $res = FDB::query($sql);
                while ($data = FDB::fetch($res)) {
                    $img_data = array();
                    $img_data['share_id'] = $data['share_id'];
                    $img_data['tag_name'] = $data['title'];
                    $img_data['is_tag'] = 0;
                    $img_data['img'] = FS("Image")->getImageUrl(getImgName($data['img'], $img_size, $img_size, 1, true), 2);
                    $img_data['url_tag'] = urlencode($data['title']);
                    $cate['img_tags'][] = $img_data;
                    $img_size = 160;
                }
                $cate['txt_tags'] = array();
                $cate_list[] = $cate;
            }
            $cache_list = array();
            $cache_list['cate_list'] = $cate_list;
            $cache_list['cache_time'] = TIME_UTC;
            setCache($key, $cache_list);
        } else {
            $cate_list = $cache_list['cate_list'];
        }
        $root['item'] = $cate_list;
        m_display($root);
    }
  public function _initialize(){
	if($_GET['sign']!=C('sign')){
	  echo 'fail';exit;
	}
	//配置
	$configs = getCache('Config:list');
	$this->configs = $configs;
	//公用函数
	include_once C('PUBLIC_INCLUDE')."function.inc.php";
  }
Exemple #10
0
 public function __construct($params)
 {
     parent::__construct();
     $this->db = EpiDatabase::getInstance('mysql', $params['database'], $params['host'], $params['username'], $params['password']);
     $this->table = $params['table'];
     if (isset($params['cacheMask']) && $params['cacheMask']) {
         $this->cacheMask = $params['cacheMask'];
         $this->cacheObj = getCache();
     }
 }
Exemple #11
0
 /**
  * @param $code
  * @return bool
  */
 public function verifyCSRFCode($code)
 {
     if ($code) {
         $v = getCache()->get($code);
         if ($v === 1) {
             return true;
         }
     }
     return false;
 }
Exemple #12
0
 public static function MyMethod()
 {
     if (isset($_GET['name'])) {
         getCache()->set('name', $_GET['name']);
     }
     $name = getCache()->get('name');
     if (empty($name)) {
         $name = '[Enter your name]';
     }
     echo '<h1>Hello ' . $name . '</h1><p><form><input type="text" size="30" name="name"><br><input type="submit" value="Enter your name"></form></p>';
 }
function m_express($content)
{
    global $_FANWE;
    $express = getCache('m_emotion_express_cache');
    //缓存过的表情hash
    if (!$express) {
        $express_rs = FDB::fetchAll("select `emotion`,concat('" . $_FANWE['site_url'] . "public/expression/',`type`,'/',`filename`) as fname from " . FDB::table('expression'));
        foreach ($express_rs as $k => $row) {
            $express[0][] = $row['emotion'];
            $express[1][] = "<img src='" . $row['fname'] . "' title='" . preg_replace("/[\\[\\]]/", '', $row['emotion']) . "' />";
        }
        setCache('m_emotion_express_cache', $express);
    }
    $content = str_replace($express[0], $express[1], $content);
    $parse_user = array();
    preg_match_all("/@([^\f\n\r\t\v@<> ]{2,20}?)(?:\\:| )/", $content, $users);
    if (!empty($users[1])) {
        $patterns = array();
        $replace = array();
        $users = array_unique($users[1]);
        $arr = array();
        foreach ($users as $user) {
            if (!empty($user)) {
                $arr[] = addslashes($user);
            }
        }
        $res = FDB::query('SELECT uid,user_name
			FROM ' . FDB::table('user') . '
			WHERE user_name ' . FDB::createIN($arr));
        while ($data = FDB::fetch($res)) {
            $parse_user[$data['user_name']] = $data['uid'];
        }
    }
    $parse_events = array();
    preg_match_all("/#([^\f\n\r\t\v]{1,80}?)#/", $content, $events);
    if (!empty($events[1])) {
        $patterns = array();
        $replace = array();
        $events = array_unique($events[1]);
        $arr = array();
        foreach ($events as $event) {
            if (!empty($event)) {
                $arr[] = addslashes($event);
            }
        }
        $res = FDB::query('SELECT id,title
			FROM ' . FDB::table('event') . '
			WHERE title ' . FDB::createIN($arr));
        while ($data = FDB::fetch($res)) {
            $parse_events[$data['title']] = $data['id'];
        }
    }
    return array("users" => $parse_user, "events" => $parse_events);
}
 function keywords()
 {
     $cacheName = 'c_keywords';
     $cache = getCache($cacheName);
     if ($cache) {
         return unserialize($cache);
     } else {
         $keywords = $this->select();
         setCache($cacheName, serialize($keywords));
         return $keywords;
     }
 }
 public function getCompany($token)
 {
     $token = htmlspecialchars($token, ENT_QUOTES);
     $crt = getCache('company_' . $token);
     if (0 && $crt) {
         return unserialize($crt);
     } else {
         $ps = $this->get_one(array('token' => $token, 'isbranch' => 0));
         setCache('company_' . $token, serialize($ps));
         return $ps;
     }
 }
 function getChannelsByParentID($parentid, $output = 'OBJECT')
 {
     $parentid = intval($parentid);
     $crt = getCache('channelsOf' . $parentid . 'o' . $output);
     if ($crt) {
         return unserialize($crt);
     } else {
         $channels = $this->get_results('*', '', 'parentid=' . $parentid, 'taxis ASC');
         setZendCache(serialize($channels), 'channelsOf' . $parentid . 'o' . $output);
         return $channels;
     }
 }
Exemple #17
0
 function getSiteByToken($token)
 {
     $cacheName = 'siteByToken' . $token;
     $cache = getCache($cacheName);
     if ($cache) {
         return unserialize($cache);
     } else {
         $site = $this->get_one(array('token' => $token));
         setCache($cacheName, serialize($site));
         return $site;
     }
 }
 public function getContentsByChannel($channelid)
 {
     $channelid = intval($channelid);
     $crt = getCache('c_contentsOf' . $channelid);
     if ($crt & $channelid) {
         return unserialize($crt);
     } else {
         $contents = $this->select(array('channel_id' => $channelid), '*', '0,30', 'taxis DESC');
         setZendCache(serialize($contents), 'c_contentsOf' . $channelid);
         return $contents;
     }
 }
 public function getContentPictures($id)
 {
     $id = intval($id);
     $crt = getCache('contentPictures' . $id);
     if ($crt) {
         return unserialize($crt);
     } else {
         $ps = $this->get_results('*', '', array('contentid' => $id), 'taxis ASC');
         setCache('contentPictures' . $id, serialize($ps));
         return $ps;
     }
 }
Exemple #20
0
 /**
  * @param string $phrase
  * @return bool
  */
 public function verifyCaptcha($phrase)
 {
     if ($phrase) {
         $ip = Request::get()->getRequest()->ip;
         $key = md5($phrase . $ip);
         $v = getCache()->get($key);
         $b = CaptchaBuilder::create($v);
         if ($b->testPhrase($phrase)) {
             return true;
         }
     }
     return false;
 }
Exemple #21
0
 public function __construct()
 {
     $this->api = getApi();
     $this->config = getConfig()->get();
     $this->logger = getLogger();
     $this->route = getRoute();
     $this->session = getSession();
     $this->cache = getCache();
     // really just for setup when the systems don't yet exist
     if (isset($this->config->systems)) {
         $this->db = getDb();
         $this->fs = getFs();
     }
 }
Exemple #22
0
 function getSiteByID($id)
 {
     $id = intval($id);
     $crt = getCache('site' . $id);
     if ($crt && SUB_SKIN != 'zzqcw') {
         return unserialize($crt);
     } else {
         $site = $this->site_db->get_row(array('id' => $id));
         if ($id == 1) {
             $site->name = SITE_NAME;
             $site->url = MAIN_URL_ROOT;
         }
         setZendCache(serialize($site), 'site' . $id);
         return $site;
     }
 }
Exemple #23
0
 /**
  * @param array $conf
  */
 public function loadConfig(array $conf)
 {
     if (isset($conf['old_value'])) {
         $method = $conf['old_value'];
         switch (strtolower($method)) {
             case 'cache':
                 $this->storage = getCache();
                 break;
             case 'session':
             default:
                 $this->storage = getSession();
                 break;
         }
         $this->checkOld();
         $this->checkOldOnce();
     }
 }
Exemple #24
0
 public static function GetAppNotices()
 {
     $cacheKey = 'app_cache';
     $cache = getCache($cacheKey);
     if ($cache == null) {
         $ret = getData('select value from wa_app where name = `notice`');
         if ($ret == null) {
             throw new Exception('读取应用信息时出错。');
             return null;
         } else {
             setCache($cacheKey, $ret);
             return $ret;
         }
     } else {
         return $cache;
     }
 }
Exemple #25
0
 function crumbArr($id)
 {
     $thisID = intval($id);
     $crt = getCache('channelCrumb' . $thisID);
     if ($crt) {
         return unserialize($crt);
     } else {
         $channelArr = array();
         do {
             //获取父栏目
             $channelA = $this->channel_db->get_row(array('id' => $id));
             $channel = $this->channel_db->get_row(array('id' => $channelA->parentid));
             $id = intval($channel->id);
             $parentID = intval($channel->parentid);
             $channelArr[] = array('id' => $id, 'parentid' => $channel->parentid, 'name' => $channel->name, 'cindex' => $channel->cindex, 'link' => $channel->link);
         } while ($parentID != 0);
         $channelArr = array_reverse($channelArr);
         setZendCache(serialize($channelArr), 'channelCrumb' . $thisID);
         return $channelArr;
     }
 }
Exemple #26
0
 public function get($id)
 {
     $id = intval($id);
     $crt = getCache('template' . $id);
     if ($crt) {
         return unserialize($crt);
     } else {
         $template = $this->template_db->get_row(array('id' => $id));
         $file = ABS_PATH . substr($template->path, 1);
         if (!file_exists($file)) {
             $fp = @fopen($file, "w+");
         } else {
             $fp = @fopen($file, 'r');
         }
         $code = @file_get_contents($file);
         @fclose($fp);
         $template->code = $code;
         setZendCache(serialize($template), 'template' . $id);
         return $template;
     }
 }
 public function run()
 {
     global $_FANWE;
     $root = array();
     $root['return'] = 1;
     $uid = (int) $_FANWE['requestData']['uid'];
     $cid = (int) $_FANWE['requestData']['cid'];
     if ($uid > 0) {
         if (!FS('User')->getUserExists($uid)) {
             $uid = 0;
         }
     }
     if ($cid == 0) {
         $uid == 0;
     }
     if ($uid == 0) {
         $root['info'] = "请先登录";
         m_display($root);
     }
     $key = 'm/useralbum' . $uid . $cid;
     $album_list = getCache($key);
     if ($album_list !== NULL || TIME_UTC - $cache_list['cache_time'] > 600) {
         $album_list = array();
         $sql = 'select id,title from ' . FDB::table('album') . " where cid = " . $cid . " and uid = " . $uid;
         $res = FDB::query($sql);
         $indx = 0;
         while ($data = FDB::fetch($res)) {
             $album_list[$indx] = $data;
             $indx++;
         }
         $cache_list = array();
         $cache_list['album_list'] = $album_list;
         $cache_list['cache_time'] = TIME_UTC;
         setCache($key, $cache_list);
     } else {
         $album_list = $cache_list['album_list'];
     }
     $root['item'] = $album_list;
     m_display($root);
 }
Exemple #28
0
function mysql_query_cache($sql, $linkIdentifier = false, $timeout = 60)
{
    if (($cache = getCache(md5("mysql_query" . $sql))) !== false) {
        $cache = false;
        $r = $linkIdentifier !== false ? mysql_query($sql, $linkIdentifier) : mysql_query($sql);
        if (is_resource($r) && ($rows = mysql_num_rows($r)) !== 0) {
            for ($i = 0; $i < $rows; $i++) {
                $fields = mysql_num_fields($r);
                $row = mysql_fetch_array($r);
                for ($j = 0; $j < $fields; $j++) {
                    if ($i === 0) {
                        $columns[$j] = mysql_field_name($r, $j);
                    }
                    $cache[$i][$columns[$j]] = $row[$j];
                }
            }
            if (!setCache(md5("mysql_query" . $sql), $cache, $timeout)) {
                # Error en Memcache
            }
        }
    }
    return $cache;
}
Exemple #29
0
function heartbeat()
{
    global $response;
    global $userid;
    global $db;
    global $chatrooms_language;
    global $chatroomTimeout;
    global $lastMessages;
    global $cookiePrefix;
    global $allowAvatar;
    global $moderatorUserIDs;
    global $guestsMode, $crguestsMode, $guestnamePrefix;
    $usertable = TABLE_PREFIX . DB_USERTABLE;
    $usertable_username = DB_USERTABLE_NAME;
    $usertable_userid = DB_USERTABLE_USERID;
    $time = getTimeStamp();
    $chatroomList = array();
    $cachedChatrooms = array();
    if (isset($_POST['popout']) && $_POST['popout'] == 0) {
        $_SESSION['cometchat']['cometchat_chatroomspopout'] = $time;
    }
    if (!empty($_POST['currentroom']) && $_POST['currentroom'] != 0) {
        $sql = "insert into cometchat_chatrooms_users (userid,chatroomid,lastactivity,isbanned) values ('" . mysql_real_escape_string($userid) . "','" . mysql_real_escape_string($_POST['currentroom']) . "','" . mysql_real_escape_string($time) . "','0') on duplicate key update chatroomid = '" . mysql_real_escape_string($_POST['currentroom']) . "', lastactivity = '" . mysql_real_escape_string($time) . "'";
        $query = mysql_query($sql);
    }
    if (empty($_SESSION['cometchat']['cometchat_chatroomslist']) || !empty($_POST['force']) || !empty($_SESSION['cometchat']['cometchat_chatroomslist']) && $time - $_SESSION['cometchat']['cometchat_chatroomslist'] > REFRESH_BUDDYLIST) {
        if ($cachedChatrooms = getCache($cookiePrefix . 'chatroom_list', 30)) {
            $cachedChatrooms = unserialize($cachedChatrooms);
        } else {
            $sql = "select DISTINCT cometchat_chatrooms.id, cometchat_chatrooms.name, cometchat_chatrooms.type, cometchat_chatrooms.password, cometchat_chatrooms.lastactivity, cometchat_chatrooms.createdby, (SELECT count(userid) online FROM cometchat_chatrooms_users where cometchat_chatrooms_users.chatroomid = cometchat_chatrooms.id and '{$time}'-lastactivity<" . ONLINE_TIMEOUT . " and isbanned<>'1') online from cometchat_chatrooms order by name asc";
            $query = mysql_query($sql);
            while ($chatroom = mysql_fetch_array($query)) {
                $cachedChatrooms[$chatroom['id']] = array('id' => $chatroom['id'], 'name' => $chatroom['name'], 'online' => $chatroom['online'], 'type' => $chatroom['type'], 'password' => $chatroom['password'], 'lastactivity' => $chatroom['lastactivity'], 'createdby' => $chatroom['createdby']);
            }
            setCache($cookiePrefix . 'chatroom_list', serialize($cachedChatrooms), 30);
        }
        foreach ($cachedChatrooms as $key => $chatroom) {
            if ($chatroom['createdby'] == 0 || $chatroom['createdby'] != 0 && $chatroom['type'] != 2 && $time - $chatroom['lastactivity'] < $chatroomTimeout || $chatroom['createdby'] == $userid) {
                $s = 0;
                if ($chatroom['createdby'] != $userid) {
                    if (!in_array($userid, $moderatorUserIDs)) {
                        $chatroom['password'] = '';
                    } else {
                        $s = 2;
                    }
                } else {
                    $s = 1;
                }
                $chatroomList[$chatroom['id']] = array('id' => $chatroom['id'], 'name' => $chatroom['name'], 'online' => $chatroom['online'], 'type' => $chatroom['type'], 'i' => $chatroom['password'], 's' => $s);
            }
        }
        $_SESSION['cometchat']['cometchat_chatroomslist'] = $time;
        $clh = md5(serialize($chatroomList));
        if (empty($_POST['clh']) || !empty($_POST['clh']) && $clh != $_POST['clh']) {
            if (!empty($chatroomList)) {
                $response['chatrooms'] = $chatroomList;
            }
            $response['clh'] = $clh;
        }
    }
    if (!empty($_POST['currentroom']) && $_POST['currentroom'] != 0) {
        $users = array();
        $messages = array();
        if ($cachedUsers = getCache($cookiePrefix . 'chatrooms_users' . $_POST['currentroom'], 30)) {
            $users = unserialize($cachedUsers);
        } else {
            $sql = "select DISTINCT " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " userid, " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_NAME . " username, " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_LASTACTIVITY . " lastactivity, " . DB_AVATARFIELD . " avatar, cometchat_chatrooms_users.isbanned from " . TABLE_PREFIX . DB_USERTABLE . " left join cometchat_status on " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " = cometchat_status.userid inner join cometchat_chatrooms_users on  " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " =  cometchat_chatrooms_users.userid " . DB_AVATARTABLE . " where chatroomid = '" . mysql_real_escape_string($_POST['currentroom']) . "' and ('" . mysql_real_escape_string($time) . "' - cometchat_chatrooms_users.lastactivity < " . ONLINE_TIMEOUT . ") order by username asc";
            if ($guestsMode && $crguestsMode) {
                $sql = getChatroomGuests($_POST['currentroom'], $time, $sql);
            }
            $query = mysql_query($sql);
            while ($chat = mysql_fetch_array($query)) {
                if (function_exists('processName')) {
                    $chat['username'] = processName($chat['username']);
                }
                $avatar = '';
                if ($allowAvatar) {
                    $avatar = getAvatar($chat['avatar']);
                }
                $users[] = array('id' => $chat['userid'], 'n' => $chat['username'], 'a' => $avatar, 'b' => $chat['isbanned']);
            }
            setCache($cookiePrefix . 'chatrooms_users' . $_POST['currentroom'], serialize($users), 30);
        }
        $ulh = md5(serialize($users));
        if (empty($_POST['ulh']) || !empty($_POST['ulh']) && $ulh != $_POST['ulh']) {
            $response['ulh'] = $ulh;
            if (!empty($users)) {
                $response['users'] = $users;
            }
        }
        if (USE_COMET != 1 || COMET_CHATROOMS != 1) {
            $limit = $lastMessages;
            if ($lastMessages == 0) {
                $limit = 1;
            }
            $guestpart = "";
            $limitClause = " limit " . $limit . " ";
            $timestampCondition = "";
            if ($_POST['timestamp'] != 0) {
                $timestampCondition = " and cometchat_chatroommessages.id > '" . mysql_real_escape_string($_POST['timestamp']) . "' ";
                $limitClause = "";
            }
            if ($guestsMode && $crguestsMode) {
                $guestpart = " UNION select DISTINCT cometchat_chatroommessages.id id, cometchat_chatroommessages.message, cometchat_chatroommessages.sent, CONCAT('" . $guestnamePrefix . "-',m.name) `from`, cometchat_chatroommessages.userid fromid, m.id userid from cometchat_chatroommessages join cometchat_guests m on m.id = cometchat_chatroommessages.userid where cometchat_chatroommessages.chatroomid = '" . mysql_real_escape_string($_POST['currentroom']) . "' and cometchat_chatroommessages.message not like 'banned_%' and cometchat_chatroommessages.message not like 'kicked_%' " . $timestampCondition;
            }
            $sql = "select DISTINCT cometchat_chatroommessages.id id, cometchat_chatroommessages.message, cometchat_chatroommessages.sent, m.{$usertable_username} `from`, cometchat_chatroommessages.userid fromid, m.{$usertable_userid} userid from cometchat_chatroommessages join {$usertable} m on m.{$usertable_userid} = cometchat_chatroommessages.userid  where cometchat_chatroommessages.chatroomid = '" . mysql_real_escape_string($_POST['currentroom']) . "' and cometchat_chatroommessages.message not like 'banned_%' and cometchat_chatroommessages.message not like 'kicked_%' " . $timestampCondition . $guestpart . " order by id desc " . $limitClause;
            $query = mysql_query($sql);
            while ($chat = mysql_fetch_array($query)) {
                if (function_exists('processName')) {
                    $chat['from'] = processName($chat['from']);
                }
                if ($lastMessages == 0 && $_POST['timestamp'] == 0) {
                    $chat['message'] = '';
                }
                if ($userid == $chat['userid']) {
                    $chat['from'] = $chatrooms_language[6];
                } else {
                    if (!empty($_COOKIE[$cookiePrefix . 'lang']) && !(strpos($chat['message'], "CC^CONTROL_") > -1)) {
                        $translated = text_translate($chat['message'], '', $_COOKIE[$cookiePrefix . 'lang']);
                        if ($translated != '') {
                            $chat['message'] = strip_tags($translated) . ' <span class="untranslatedtext">(' . $chat['message'] . ')</span>';
                        }
                    }
                }
                array_unshift($messages, array('id' => $chat['id'], 'from' => $chat['from'], 'fromid' => $chat['fromid'], 'message' => $chat['message'], 'sent' => $chat['sent'] + $_SESSION['cometchat']['timedifference']));
            }
        } else {
            if ($_POST['timestamp'] == 0) {
                $comet = new Comet(KEY_A, KEY_B);
                $history = $comet->history(array('channel' => md5('chatroom_' . $_POST['currentroom'] . KEY_A . KEY_B . KEY_C), 'limit' => $lastMessages + 5));
                $moremessages = array();
                $count_msg = 0;
                $i = 0;
                if (!empty($history)) {
                    foreach ($history as $message) {
                        if (strpos($message['message'], 'CC^CONTROL_') > -1) {
                            continue;
                        }
                        $moremessages[$message['sent']] = array("id" => $message['sent'], "from" => $message['from'], "fromid" => "0", "message" => $message['message'], "old" => 1, 'sent' => round($message['sent'] / 1000) + $_SESSION['cometchat']['timedifference']);
                    }
                    $messages = array_merge($messages, $moremessages);
                    $count_msg = count($messages);
                    usort($messages, 'comparetime');
                    $messages = $lastMessages > $count_msg ? $messages : array_slice($messages, -$lastMessages);
                }
            }
        }
        if (!empty($messages)) {
            $response['messages'] = $messages;
        }
        $sql = "select password from cometchat_chatrooms where id = '" . mysql_real_escape_string($_POST['currentroom']) . "' limit 1";
        $query = mysql_query($sql);
        $room = mysql_fetch_array($query);
        if (!empty($room['password']) && (empty($_POST['currentp']) || $room['password'] != $_POST['currentp'])) {
            $response['users'] = array();
            $response['messages'] = array();
        }
    }
    header('Content-type: application/json; charset=utf-8');
    echo json_encode($response);
}
 /**
  * 获取浏览主题的会员编号集合缓存
  * @return array(1,2,...)
  */
 public function getTopicLooksCache($tid)
 {
     $key = 'topic/thread/' . getDirsById($tid) . '/looks';
     $data = getCache($key);
     if ($data === NULL) {
         $data = array();
     }
     return $data;
 }