<?php



if(!defined('IN_DISCUZ')) {

	exit('Access Denied');

}



$id = intval($_GET['fid']);

$order = $_GET['order'];

$fids = $id ? $id : array(); //array(2,3,4)可以直接添加需要显示的版块FID，留空不添加显示全部版块图片帖子

$pagenum = '15';  //首页每页显示的帖子数量



if($order){

	$url = "portal.php?order=$order#tab_anchor";

}else{

	$url = "portal.php?#tab_anchor";

}



function fetch_photo($fids, $page, $perpage = false, $order) {

	$fids = dintval($fids, true);

	if (in_array($order, array('dateline', 'views', 'replies', 'digest'))){

		$order = $order ? $order : 'dateline';

	}else{

		$order = 'dateline';

	}

	$perpage = intval($perpage) ? intval($perpage) : 8;

	$page = max(1, intval($page));

	$start = ($page - 1) * $perpage;

	$parameter = array('forum_thread');

	$wherearr = array('attachment=2', 'displayorder>=0', 'special=0');

	if($order=='digest'){

		$wherearr[] = 'digest>0';

	}

	if (!empty($fids)) {

		$parameter[] = $fids;

		$wherearr[] = is_array($fids) && $fids ? 'fid IN(%n)' : 'fid=%d';

	}

	$wheresql = !empty($wherearr) && is_array($wherearr) ? ' WHERE '.implode(' AND ', $wherearr) : '';

	$count = DB::result_first('SELECT COUNT(*) FROM %t '.$wheresql, $parameter);



	$rs=DB::query('SELECT * FROM %t '.$wheresql.' ORDER BY '.DB::order($order, 'DESC').DB::limit($start, $perpage), $parameter);



	while ($rw=DB::fetch($rs)){

		$tableid=substr($rw['tid'],-1,1);

		$rw['aid']=DB::result_first("SELECT aid FROM ".DB::table("forum_attachment_$tableid")." WHERE tid ='{$rw['tid']}'AND isimage !=0 ORDER BY aid ASC LIMIT 0 , 1");

		$threadlist[]=$rw;

	}



	if ($count && $threadlist) {

		return array('count' => $count, 'threadlist' => $threadlist);

	}

}



if(!isset($_G['cache']['forums'])){

	loadcache('forums');

}



?>
