<?php
include(dirname(__file__)."/../includes.php");

//日志评论api函数
function blog_com_read_base($fields="*",$condition="",$by_col="",$order="",$num="",$cache="",$cache_key=""){
	global $tablePreStr;
	$t_blog=$tablePreStr."blog";
	$t_blog_comment=$tablePreStr."blog_comment";
	$plugin_rs=array();
	$dbo=new dbex;
  dbplugin('r');
  if($num==''||$num >= 1000){
  	$limit=" limit 1000 ";
  }else{
  	$limit=" limit $num ";
  }
  if($by_col!=''){
  	$by_col=" order by $by_col ";
  }
  $sql=" select c.$fields from $t_blog as b join $t_blog_comment as c on (b.log_id=c.log_id) where b.log_pass = 1 and b.blog_limit = 0 $condition $by_col $order $limit ";
	$plugin_rs=$dbo->getRs($sql);
	return $plugin_rs;
}

function blog_com_by_bid($fields="*",$id='',$date='',$num=10){
	$fields=filt_fields($fields);
	$id_str=filt_num_array($id);
	$condition=" and c.log_id in ($id_str) ";
	if($date!=''){
		$condition.=str_replace("{date}","c.add_time",date_filter($date));
	}
	return blog_com_read_base($fields,$condition,"c.add_time","desc",$num);
}

function blog_com_by_vid($fields="*",$id='',$date='',$num=10){
	$fields=filt_fields($fields);
	$id_str=filt_num_array($id);
	$condition=" and c.visitor_id in ($id_str) ";
	if($date!=''){
		$condition.=str_replace("{date}","c.add_time",date_filter($date));
	}
	return blog_com_read_base($fields,$condition,"c.add_time","desc",$num);
}

function blog_com_by_hid($fields="*",$id='',$date='',$num=10){
	$fields=filt_fields($fields);
	$id_str=filt_num_array($id);
	$condition=" and c.host_id in ($id_str) ";
	if($date!=''){
		$condition.=str_replace("{date}","c.add_time",date_filter($date));
	}
	return blog_com_read_base($fields,$condition,"c.add_time","desc",$num);
}

?>