<?php
/**************************************************
*  Created:  2010-06-08
*
*  微博广场
*
*  @Xweibo (C)1996-2099 SINA Inc.
*  @Author zhenquan <zhenquan@staff.sina.com.cn>
*
***************************************************/
class pub
{
	function default_action() {
		// 今日话题
		$db = APP :: ADP('db');
		$sql = 'SELECT `topic` FROM ' . $db->getTable(T_TODAY_TOPIC) . ' WHERE start_time<'.time() .' ORDER BY start_time DESC LIMIT 1';
		
		$today_topic = $db->getOne($sql);
		if (!empty($today_topic)) {
			TPL :: assign('today_topic', $today_topic);
		}
		$wb = APP::N('weibo');
		$each_page = 100;
		$p = 1;
		$q = array(
				'q' =>$today_topic
				);
		$data = $wb->searchStatuse($q);

		$data = APP::F('weibo_filter', $data);
		$ids = $wb->getFriendIds($uid, null, null, -1, 5000);
		if (is_array($ids) && is_array($data)) {
			foreach($data as $key => $row) {
				if (in_array($row['user']['id'], $ids['ids'])) {
					$data[$key]['user']['following'] = true;
				}
			}
			TPL :: assign('today_topic_weibo', $data);
		}
		// 随便看看
		//$data = $wb->getPublicTimeline();
		$data = APP::F('weibo_cache', $wb, 'getPublicTimeline');
		$data = APP::F('weibo_filter', $data);
		TPL :: assign('list', $data);

		// 明人推荐
		$data = $db->query('SELECT *FROM ' . $db->getTable(T_CELEBRITY) . ' ORDER BY id DESC LIMIT 12');
		TPL :: assign('celebrity', $data);

		// 同城推荐
		// //实例化存储
		$storage = APP::N('clientUser');
		//$city_id = $storage->getInfo('city_id');

		$sinaid = $storage->getInfo('sina_uid');
		//调用微博个人资料接口
		$userinfo = $wb->getUserShow($sinaid);
		//过滤过敏用户
		$userinfo = APP::F('user_filter', $userinfo, true);
		if (empty($userinfo)) {
			//提示访问的页面不存在，跳转到首页
			APP::tips(array('tpl' => 'error', 'msg'=> '抱歉，您访问的页面已被禁止浏览。'));
		}

		TPL::assign('userinfo', $userinfo);
		$param = array(
			'q' => '的',
			'province' => $userinfo['province'],
			'city' => $userinfo['city'],
			'count' =>10
			);
		//$data = $wb->searchStatuse($param);
		$data = APP::F('weibo_cache', $wb, 'searchStatuse', $param);
		$after = array();
		$uid = array();
		foreach ($data as $row) {
			if (!isset($uid[$row['user']['id']])) {
				$uid[$row['user']['id']] = 1;
				$after[] = $row;
				if (count($after) >= 5) {
					break;
				}
			}
		}
		//TPL :: assign('recommend', $data);
		TPL :: assign('recommend', $after);

		// 人气关注
		$db = APP :: ADP('db');
		$rs = $db->query('SELECT *FROM ' . $db->getTable(T_FOLLOWERS_COUNT) . ' WHERE uid NOT IN(SELECT uid FROM ' .$db->getTable(T_DISABLED_FOLLOWERS). ') ORDER BY `followers_count` DESC LIMIT 10');
		TPL :: assign('userinfo', $userinfo);
		TPL :: assign('top_followers', $rs);
		TPL :: display('teahouse');
	}
}
