<?php
class EmptyAction extends CommonAction{
	Public function index()
	{
		$action=MODULE_NAME;
		$this->homepage($action);
	}
	private function homepage($home)
	{
		load('extend');
		$home=H(filterSpecial($home));
		$u=M('user');
		$data=array();
		$data['homepage']=$home;
		$rs=$u->where($data)->find();
		if($rs)
		{	
			$id=$rs['id'];
			//关注度
			$bgz=$gztr=0;
			$att=M('attention');
			$bgz=$att->where('obj='.$id)->count();
			$gztr=$att->where('userid='.$id)->count();
			if(!$bgz)
				$bgz=0;
			if(!$gztr)
				$gztr=0;
			$this->assign('bgz',$bgz);
			$this->assign('gztr',$gztr);
			//我的话题
			$this->assign('mytag',$this->mytag($id));
			$this->assign('mygroup',$this->mygroup($id));
			//
			$attenuser=R("Catch","rUserAttention");
			$this->assign('gzuser',$attenuser);
			//其他用户来访时显示用户的微博
			$tg=M('topic');
			$mylist="";
			if(getUserID()==$id)
			{
				//读取用户的关注
				$this->assign('pagetitle',getUserAccount()."关注的微博");
				$tguserid="";
				$att=M('attention');
				$attlist=$att->where('userid='.$id)->select();
				for($i=0;$i<count($attlist);$i++)
				{
					$tguserid.=$attlist[$i]['objuser'].',';
				}
				$where['userid']  = array('instr', '('.$tguserid.')');
				$mylist=$tg->query("select * from __TABLE__ where instr('".$tguserid."',userid) and status=1 order by id desc limit 0,10");
				//
			}
			else
			{
				$wdata['userid']=$id;
				$wdata['status']=1;
				$this->assign('pagetitle',getUserNameID($id)."的微博");
				$mylist=$tg->where($wdata)->limit(10)->order('id desc')->select();
			}
			$this->assign('list',$mylist);
			//
			$username=getUserNameID($id);
			parent::showSiteInfo($username."--个人首页",$username,$username);
			//
			$this->assign('rs',$rs);
			$this->display('Index:homepage');	
		}
		else
		{
			$this->error('404');
		}

	}
	private function mytag($id)
	{
		$tag=M('topic_tag');
		$list=$tag->where('create_user='.$id)->order('id desc')->limit(10)->select();
		return $list;
	}
	private function mygroup($id)
	{
		$tag=M('topic');
		$list=$tag->where('userid='.$id)->group('groupid')->limit(10)->select();
		return $list;
	}
}
?>