<?php
class BlogAction extends CommonAction{
    public function show(){
		$group=R("Catch","rCatchGroup");
		$this->assign('group',$group);
		$id=$_GET['id'];
		if(!checkId32($id))
		{
			$this->redirect('index/index');
			exit;
		}
		$top=M('topic');
		$rs=$top->find($id);
		if($rs)
		{
			//
			load('extend');
			$attenuser=R("Catch","rUserAttention");
			$this->assign('gzuser',$attenuser);
			//
			$tag=R("Catch","rCatchTag");
			$this->assign('tag',$tag);
			$topic=R("Catch","rNewTopic");
			$toptag=R("Catch","rTagTop");
			$this->assign('topic',$topic);
			$this->assign('toptag',$toptag);
			//
			$bgz=$gztr=0;
			$att=M('attention');
			$bgz=$att->where('obj='.$rs['userid'])->count();
			$gztr=$att->where('userid='.$rs['userid'])->count();
			if(!$bgz)
				$bgz=0;
			if(!$gztr)
				$gztr=0;
			$this->assign('bgz',$bgz);
			$this->assign('gztr',$gztr);
			$this->assign('userid',$rs['userid']);
			//
			parent::showSiteInfo($rs['title'].'--微博',$rs['title']);
			//
			$data=array();
			$data['parentid']=$id;
			$count=$top->where($data)->count();
			$more=$top->where($data)->order('id desc')->select();
			$this->assign('more',$more);
			$this->assign('count',$count);
			//更新统计次数
			$top->setInc('pass','id='.$id,1);
			//
		}
		$this->assign('bloginfo',$rs);
        $this->display();
    }
	public function group()
	{
		parent::showSiteInfo('群组列表','群组列表','群组列表');
		load('extend');
		$topic=R("Catch","rNewTopic");
		$topuser=R("Catch","rUserTop");
		$toptag=R("Catch","rTagTop");
		$this->assign('topic',$topic);
		$this->assign('toptag',$toptag);
		$this->assign('topuser',$topuser);
		$list=R("Catch","rGetAllGroup");
		$this->assign('list',$list);
		$group=R("Catch","rCatchGroup");
		$tag=R("Catch","rCatchTag");
		//
		$attenuser=R("Catch","rUserAttention");
		$this->assign('gzuser',$attenuser);
		//
		$this->assign('group',$group);
		$this->assign('tag',$tag);
		$this->display();
	}
	public function gname()
	{
		load('extend');
		$topic=R("Catch","rNewTopic");
		$topuser=R("Catch","rUserTop");
		$toptag=R("Catch","rTagTop");
		$this->assign('topic',$topic);
		$this->assign('toptag',$toptag);
		$this->assign('topuser',$topuser);
		$id=$_GET['id'];
		if(!checkId32($id))
		{
			$this->redirect('index/index');
			exit;
		}
		$group=R("Catch","rCatchGroup");
		$tag=R("Catch","rCatchTag");
		$this->assign('group',$group);
		$this->assign('tag',$tag);
		//
		$attenuser=R("Catch","rUserAttention");
		$this->assign('gzuser',$attenuser);
		//
		$g=M('topic_group');
		$grs=$g->find($id);
		$this->assign('grs',$grs);
		//
		parent::showSiteInfo($grs['groupname'].'--群组',$grs['groupname'],$grs['groupname']);
		//
		$p=M("topic");
		import("ORG.Util.Page");
		$count=$p->where('groupid='.$id.' and parentid=0')->count();
		$page=new Page($count,10);
		$show=$page->show();
		$list=$p->where('groupid='.$id.' and parentid=0')->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
		foreach($list as $key=>$arr)
		{
			$rlist=$p->limit(2)->where('parentid='.$arr['id'])->order('id desc')->select();
			$list[$key]['replay']=$rlist;
		}
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->display('glist');
	}
	public function upload()
	{
		parent::islogin();
		import("ORG.Net.UploadFile");
		$upload = new UploadFile();
		$upload->maxSize=512000;
		$upload->allowExts=array('jpg','gif','png','jpeg');
		$upload->savePath=getUploadPath();
		$upload->saveRule='uniqid';
		$upload->thumb=TRUE;
		$upload->thumbMaxWidth="100,500";
		$upload->thumbMaxHeight="100,500";
		//$upload->thumbRemoveOrigin=TRUE;
		$content=filterSpecial($_POST['s_title']);
		$gid=$_POST['gid'];
		if(!checkId32($gid))
		{
			$this->error('ID错误');
			exit;
		}
		$upimg="";
		$tagid=0;
		if(!$upload->upload())
		{  
			$this->error($upload->getErrorMsg());   
		}
		else
		{ 
			$info=$upload->getUploadFileInfo();
			$upimg=$info[0]["savename"];
		}
		if(empty($upimg))
		{
			$this->error('图片不能为空');
		}
		else
		{
		//话题
			$sub=M("topic_tag");
			$subrs=$sub->where("`title`='图片分享'")->find();
			if($subrs)
			{
				$tagid=$subrs['id'];
			}
			else
			{
				$sdata=array();
				$sdata['title']='图片分享';
				$sdata['create_time']=time();
				$sdata['create_user']=getUserID();
				$tagid=$sub->add($sdata);	
			}
		//
			$data=array();
			$data['title']=$content."<br/>@@".$upimg."@@";
			$data['userid']=getUserID();
			$data['time']=time();
			$data['groupid']=$gid;
			$data['parentid']=0;
			$data['ding']=0;
			$data['cai']=0;
			$data['pass']=0;
			$data['tagid']=$tagid;
			$data['status']=1;
			$topic=M('topic');
			$rs=$topic->add($data);
			if($rs)
				$this->redirect("index/index");	
			else
				$this->error('数据处理失败');
		}
	}
	public function tag()
	{
		$id=$_GET['id'];
		if(!checkId32($id))
		{
			$this->error('ID错误');
			exit;
		}
		load('extend');
		$topic=R("Catch","rNewTopic");
		$topuser=R("Catch","rUserTop");
		$toptag=R("Catch","rTagTop");
		$this->assign('topic',$topic);
		$this->assign('toptag',$toptag);
		$this->assign('topuser',$topuser);
		//
		$group=R("Catch","rCatchGroup");
		$tag=R("Catch","rCatchTag");
		$this->assign('group',$group);
		$this->assign('tag',$tag);
		//
		$attenuser=R("Catch","rUserAttention");
		$this->assign('gzuser',$attenuser);
		//
		$g=M('topic_tag');
		$grs=$g->find($id);
		$this->assign('grs',$grs);
		//
		parent::showSiteInfo($grs['title']."--话题");
		//
		$p=M("topic");
		import("ORG.Util.Page");
		$count=$p->where('tagid='.$id)->count();
		$page=new Page($count,10);
		$show=$page->show();
		$list=$p->where('tagid='.$id)->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->display('tagshow');
	}
	public function taglist()
	{
		parent::showSiteInfo('话题列表','话题列表','话题列表');
		load('extend');
		$topic=R("Catch","rNewTopic");
		$topuser=R("Catch","rUserTop");
		$toptag=R("Catch","rTagTop");
		$this->assign('topic',$topic);
		$this->assign('toptag',$toptag);
		$this->assign('topuser',$topuser);
		//
		$attenuser=R("Catch","rUserAttention");
		$this->assign('gzuser',$attenuser);
		//
		$list=R("Catch","rGetAllTag");
		$this->assign('list',$list);
		$group=R("Catch","rCatchGroup");
		$tag=R("Catch","rCatchTag");
		$this->assign('group',$group);
		$this->assign('tag',$tag);
		$this->display();
	}
	public function user()
	{
		//
		parent::showSiteInfo("微博用户");
		load('extend');
		$group=R("Catch","rCatchGroup");
		$tag=R("Catch","rCatchTag");
		$topic=R("Catch","rNewTopic");
		$topuser=R("Catch","rUserTop");
		$toptag=R("Catch","rTagTop");
		$attenuser=R("Catch","rUserAttention");
		$this->assign('gzuser',$attenuser);
		$this->assign('topic',$topic);
		$this->assign('group',$group);
		$this->assign('tag',$tag);
		$this->assign('toptag',$toptag);
		$this->assign('topuser',$topuser);
		//
		$user=M('user');
		$list=$user->where('is_top=1')->limit(18)->order('id')->select();
		//更新用户推荐时间
		for($k=0;$k<count($list);$k++)
		{
			$site=F('site');
			$toptime=$site['hot_time'];
			if(time()-$listp[$k]['top_time']>$toptime*3600)
			{
				$where['id']=$list[$k]['id'];
				$where['is_top']=0;
				$where['top_time']=0;
				$user->save($where);
			}
		}
		//
		$this->assign('istopuser',$list);
		//
		$nlist=$user->order('id desc')->limit(20)->select();
		$this->assign('isnewuser',$nlist);
		//
		$this->display();
	}
	public function search()
	{
		$word=filterSpecial($_POST['word']);
		if(empty($word))
		{
			$this->error('内容不能为空');
		}
		else
		{
			//
			load('extend');
			//
			$group=R("Catch","rCatchGroup");
			$tag=R("Catch","rCatchTag");
			$this->assign('group',$group);
			$this->assign('tag',$tag);
			$word=H($word);
			//
			parent::showSiteInfo($word."--微博搜索");
			//
			$p=M("topic");
			import("ORG.Util.Page");
			$map['title']= array('like','%'.$word.'%');  

			$count=$p->where($map)->count();
			if($count)
			{
				$page=new Page($count,10);
				$show=$page->show();
				$list=$p->where($map)->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
				$this->assign('list',$list);
				$this->assign('page',$show);
				$this->assign('searchmsg',"关于".$word."的微博");	
			}
			else
			{
				$this->assign('searchmsg',"没有您搜索的关于".$word."的内容");
			}
			$this->display();
		}
	}
	public function moreupload()
	{
		parent::islogin();
		parent::showSiteInfo("图片批量上传--");
		//
		load('extend');
		$group=R("Catch","rCatchGroup");
		$tag=R("Catch","rCatchTag");
		$topic=R("Catch","rNewTopic");
		$topuser=R("Catch","rUserTop");
		$toptag=R("Catch","rTagTop");
		$attenuser=R("Catch","rUserAttention");
		$this->assign('gzuser',$attenuser);
		$this->assign('topic',$topic);
		$this->assign('group',$group);
		$this->assign('tag',$tag);
		$this->assign('toptag',$toptag);
		$this->assign('topuser',$topuser);
		//
		$id=$_GET['id'];
		$id=$id?$id:0;
		$tg=M('topic_group');
		$rs=$tg->find($id);
		if(!$rs)
		{
			$this->error('未知的ID');
		}
		else
		{
			$this->assign('id',$id);
		}
		
		$this->display();
	}
	public function moreUploadAction()
	{
		//cookie
		$userid=unserialize(base64_decode($_POST['cookieid']));
		$userpwd=unserialize(base64_decode($_POST['cookiewd']));
		parent::checkNotLoginCookie($userid,$userpwd);
		//
		$file_id="";
		import("ORG.Net.UploadFile");
		$upload = new UploadFile();
		$upload->maxSize=512000;
		$upload->allowExts=array('jpg','gif','png','jpeg');
		$upload->savePath=getUploadPath();
		$upload->saveRule='uniqid';
		$upload->thumb=TRUE;
		$upload->thumbMaxWidth="100,500";
		$upload->thumbMaxHeight="100,500";
		if(!$upload->upload())
		{  
			echo $upload->getErrorMsg();
			exit;
		}
		else
		{ 
			$info=$upload->getUploadFileInfo();
			$file_id=$info[0]["savename"];
		}
		echo "FILEID:" . $file_id;	// Return the file id to the script
	}
	public function moresend()
	{
		parent::islogin();
		load('extend');
		$img="";
		for($i=0;$i<5;$i++)
		{
			$imgvalue=H(replacespace($_POST['img'.$i]));
			if(!empty($imgvalue))
				$img.='@@'.$imgvalue.'@@';
		}
		$gid=$_GET['id'];
		$content=H(replacespace($_POST['content']));
		if($img=="")
		{
			$this->error('必须至少上传一张图片'.$num);
		}
		$tagid=0;
		$tg=M('topic_tag');
		$rs=$tg->where("title='图片分享'")->find();
		if($rs)
		{
			$tagid=$rs['id'];
		}
		else
		{
			$da['title']='图片分享';
			$da['create_time']=time();
			$da['create_user']=getUserID();
			$tagid=$tg->add($da);
		}
		$data=array();
		$data['title']=$content.'<br/>'.$img;
		$data['userid']=getUserID();
		$data['time']=time();
		$data['groupid']=$gid;
		$data['parentid']=0;
		$data['ding']=0;
		$data['cai']=0;
		$data['pass']=0;
		$data['tagid']=$tagid;
		$data['status']=1;
		$topic=M('topic');
		$rs=$topic->add($data);
		if($rs)
		{
			$this->redirect("index/index");	
		}
		else
			$this->error('数据处理失败');
	}
}
?>