<?php
/*
		[FuShow.cn] (C) 2013-2014 HXWY Inc.
		FuShow Friend V3.0				Id: ushow_tag.php
		Email <service@fushow.cn>		http://fushow.cn/
*/

if(!defined('IN_FUSHOW')) {
	exit('Access Denied');
}

$id = empty($_GET['id'])?0:intval($_GET['id']);
$name = empty($_GET['name'])?0:stripsearchkey($_GET['name']);
$start = empty($_GET['start'])?0:intval($_GET['start']);

$list = array();
$count = 0;

if($id || $name) {
	//分页
	$perpage = 30;
	//检查开始数
	ckstart($start, $perpage);
	
	//获取TAG
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('tag')." WHERE ".($id?"tagid='$id'":"tagname='$name'")." LIMIT 1");
	$tag = $_SGLOBAL['db']->fetch_array($query);
	if(empty($tag)) {
		showmessage('tag_does_not_exist');
	} elseif ($tag['close']) {
		showmessage('tag_locked');
	}
	
	//获取tag关联
	$prinum = 0;
	$query = $_SGLOBAL['db']->query("SELECT blog.* FROM ".tname('tagblog')." tb , ".tname('blog')." blog WHERE tb.tagid='$tag[tagid]' AND blog.blogid=tb.blogid LIMIT $start,$perpage");
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		if(empty($value['friend'])) {
			realname_set($value['uid'], $value['username']);
			$list[] = $value;
		} else {
			$prinum++;
		}
		$count++;
	}
	
	//实名
	realname_get();
	
	//分页
	$multi = smulti($start, $perpage, $count, "fushow.php?uid=$space[uid]&do=$do&id=$id");

	include_once template("fushow_tag_view");
	
} else {

	//分页
	$perpage = 100;
	//检查开始数
	ckstart($start, $perpage);
	
	//处理查询
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('tag')." ORDER BY blognum DESC LIMIT $start,$perpage");
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		$list[] = $value;
		$count++;
	}
	
	//分页
	$multi = smulti($start, $perpage, $count, "fushow.php?uid=$space[uid]&do=$do");

	include_once template("fushow_tag_list");
}

?>