<?php 
/*
**U2自动链 数据库读取类
**inc/links.class.php
**By 冬筠 qq426420
*/
class linkscs{
	var $db;
	function linkscs($dbhandle)
	{
		$this->db = $dbhandle;
	}
	//显示所有网站
	function getlinks($page = 1, $prePageNum)
	{
	$start_limit = !empty($page) ? ($page - 1) * $prePageNum : 0;
	$limit = $prePageNum ? "LIMIT $start_limit, $prePageNum" : '';
	$res = $this->db->query("select * from ".l_dbt."link where result='2' order by uptime desc $limit");
	$links = array();
	while($row = $this->db->fetch_array($res))
	{
	$links[] = $row;
	}
	return $links;
	}
	//获取指定分类的网站列表
	function getclinks($page = 1,$prePageNum,$cid=1)
	{
	$start_limit = !empty($page) ? ($page - 1) * $prePageNum : 0;
	$limit = $prePageNum ? "LIMIT $start_limit, $prePageNum" : '';
	$res = $this->db->query("select * from  ".l_dbt."link where classid=$cid and result='2' order by uptime desc $limit");
	$links = array();
	while($row = $this->db->fetch_array($res))
	{
	$links[] = $row;
	}
return $links;
}
	//显示所有相关网站
	function gettagslinks($page = 1, $prePageNum, $keyword)
	{
	$start_limit = !empty($page) ? ($page - 1) * $prePageNum : 0;
	$limit = $prePageNum ? "LIMIT $start_limit, $prePageNum" : '';
//and (keywords LIKE '%$keyword%' or title LIKE '%$keyword%') 
	$res = $this->db->query("select * from ".l_dbt."link where result='2' and MATCH (title,keywords) AGAINST ('$keyword*' IN BOOLEAN MODE) order by id desc $limit");
	$links = array();
	while($row = $this->db->fetch_array($res))
	{
	$links[] = $row;
	}
	return $links;
	}
	//显示所有网站排行
	function gettoplinks($page = 1, $prePageNum,$op='id')
	{
	$ttts = array('uptime', 'dayct', 'weekct', 'monthct', 'id', 'upding','count');
	$op = (!empty($op) && in_array($op, $ttts))?$op:'id';
	$start_limit = !empty($page) ? ($page - 1) * $prePageNum : 0;
	$limit = $prePageNum ? "LIMIT $start_limit, $prePageNum" : '';
	$res = $this->db->query("select * from ".l_dbt."link where result='2' order by $op desc $limit");
	$links = array();
	while($row = $this->db->fetch_array($res))
	{
	$links[] = $row;
	}
	return $links;
	}
	//获取网站条数
	function getlinknum($virtue='1', $setvirtue='1',$keyword='0')
	{
	$where = ' '.$virtue.'='.$setvirtue.'';
if($keyword){
	$res = $this->db->query("select * from ".l_dbt."link where result='2' and MATCH (title,keywords) AGAINST ('$keyword*' IN BOOLEAN MODE)" );
} else {
	$res = $this->db->query("select * from ".l_dbt."link where result='2' and $where" );
}
	$Num = $this->db->num_rows($res);
	return $Num;
	}
	//显示网站排行
	function getplinks($limit=20,$op='id')
	{
	$ttts = array('uptime', 'dayct', 'weekct', 'monthct', 'id', 'upding','count');
	$op = (!empty($op) && in_array($op, $ttts))?$op:'id';
	$res = $this->db->query("select * from ".l_dbt."link where result='2' order by $op desc limit 0,$limit");
	$links = array();
	while($row = $this->db->fetch_array($res))
	{
	$links[] = $row;
	}
	return $links;
	}
	//显示推荐网站
	function gettjlinks($limit=20,$op='id')
	{
	$ttts = array('uptime', 'dayct', 'weekct', 'monthct', 'id', 'upding','count');
	$op = (!empty($op) && in_array($op, $ttts))?$op:'id';
	$res = $this->db->query("select * from ".l_dbt."link where result='2' and  style='1' order by $op desc limit 0,$limit");
	$links = array();
	while($row = $this->db->fetch_array($res))
	{
	$links[] = $row;
	}
	return $links;
	}
	//显示所有分类
	function getclass($uid=0)
	{
	$res = $this->db->query("select * from ".l_dbt."sclass where upid='$uid'");
	$links = array();
	while($row = $this->db->fetch_array($res))
	{
	$links[] = $row;
	}
	return $links;
	}
	//获取分类数
	function getclassnum()
	{
	$res = $this->db->query("select * from ".l_dbt."sclass where upid>'0'");
	$Num = $this->db->num_rows($res);
	return $Num;
	}
	}
?>