<?php
defined('PHP168_PATH') or die();

/**
* 内容列表
**/

/**
* your code
**/

//页面缓存参数
$PAGE_CACHE_PARAM['ttl'] = empty($this_module->CONFIG['list_page_cache_ttl']) ? 0 : $this_module->CONFIG['list_page_cache_ttl'];
page_cache($PAGE_CACHE_PARAM);

$category->get_cache();

//子分类
$subcategories = array();
if(isset($category->categories[$cid]['categories'])){
	$subcategories = $category->categories[$cid]['categories'];
	$CATEGORY = $category->get_children_ids($cid) + array($cid);
}else{
	$CATEGORY = $cid;
}

//栏目允许列表
if($CAT['type'] == 2){
	$select = select();
	$select->from($this_module->table .' AS i', 'i.*');
	$select->in('i.cid', $CATEGORY);
	
	$orderby = empty($CAT['CONFIG']['orderby']) ? 'i.timestamp' : $CAT['CONFIG']['orderby'];
	$orderby .= empty($CAT['CONFIG']['orderby_desc']) ? ' DESC' : ' ASC';
	$select->order($orderby);
	
	$sphinx = $this_module->CONFIG['sphinx'];
	$sphinx['index'] = $this_system->sphinx_indexes(array($MODEL => 1));
	
	$field_set = false;
	/*
	//自定义字段处理
	foreach($URL_PARAMS as $k => $v){
		
		switch($v){
		
		case 'param':
			$param = isset($URL_PARAMS[$k +1]) ? intval($URL_PARAMS[$k +1]) : 0;
			
			$select->in('i.param', $param);
			$field_set = true;
		break;
		
		}
	}
	*/
	
	//当前分类的内容数
	$count = $field_set ? 0 : $CAT['item_count'];
	
	$list = $core->list_item(
		$select,
		array(
			'count' => &$count,
			'page' => &$page,
			'page_size' => $CAT['page_size'],
			'sphinx' => $sphinx
		)
	);
	
	foreach($list as $k => $v){
		$v['#category'] = &$category->categories[$v['cid']];
		$list[$k]['url'] = p8_url($this_module, $v, 'view');
		$list[$k]['frame'] = attachment_url($v['frame']);
		$list[$k]['full_title'] = $v['title'];
		
		//分类名称
		$list[$k]['category_name'] = $v['#category']['name'];
		//分类URL
		$list[$k]['category_url'] = $v['#category']['url'];
		
		if(!empty($v['title_color'])) $list[$k]['title'] = '<font color="'. $v['title_color'] .'">'. $list[$k]['title'] .'</font>';
		if(!empty($v['title_bold'])) $list[$k]['title'] = '<b>'. $list[$k]['title'] .'</b>';
	}
	
	$CAT['is_category'] = true;
	$pages = list_page(array(
		'count' => $count,
		'page' => $page,
		'page_size' => $CAT['page_size'],
		'url' => p8_url($this_module, $CAT, 'list', false)
	));
}

//初始化标签
$LABEL_POSTFIX = array();
//如果分类有自己的标签后缀
if(!empty($CAT['label_postfix'])) array_push($LABEL_POSTFIX, $CAT['label_postfix']);

$list_template = '';
//自定义的分类列表页模板
include template($this_module, $CAT['list_template']);

//保存页面缓存
page_cache();
