<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

//CSS 출력
include_once ($latest_list_path.'/load.style.php');

$set = array(); 
$od = array(); 
$is = array();
$css = array();
$order = array();
$details = array();

//추출글 갯수
$list_num = count($list);

//값변환
$set['subj'] = $opt['subj'];
$set['icon'] = $opt['icon'];
$set['details'] = $opt['details'];
$set['date'] = $opt['date'];
$set['star'] = $opt['star'];
$set['cate'] = $opt['cate'];
$set['list'] = $opt['list'];
$set['sp'] = $opt['sp'];
if($opt['order']) { //랭크이미지
	$set['rank_list_icon'] = $opt['rank_list_icon'] ? $opt['rank_list_icon'] : 'basic';
	$set['rank_img_icon'] = $opt['rank_img_icon'] ? $opt['rank_img_icon'] : 'basic';
	$rank_img_url = AMINA_URL.'/skin/rank/img/'.$set['rank_img_icon'];
	$rank_list_url = AMINA_URL.'/skin/rank/list/'.$set['rank_list_icon'];
}

//출력항목 설정
$is['details'] = false;
if($set['details']) {
	$od = explode(";", $set['details']);
	for($i=0; $i < count($od); $i++) {
		$o = $i + 1;
		switch($od[$i]) {
			case 'cate'		: $set['o_cate'] = $o; break;
			case 'name'		: $set['o_name'] = $o; break;
			case 'date'		: $set['o_date'] = $o; break;
			case 'cmt'		: $set['o_cmt'] = $o; break;
			case 'hit'		: $set['o_hit'] = $o; break;
			case 'good'		: $set['o_good'] = $o; break;
			case 'nogood'	: $set['o_nogood'] = $o; break;
			case 'star'		: $set['o_star'] = $o; break;
			case 'view'		: $set['o_view'] = $o; break;
			case 'down'		: $set['o_down'] = $o; break;
		}
	}

	unset($od);

	//순서배열
	$od[0] = $set['o_cate'];
	$od[1] = $set['o_name'];
	$od[2] = $set['o_date'];
	$od[3] = $set['o_cmt'];
	$od[4] = $set['o_hit'];
	$od[5] = $set['o_good'];
	$od[6] = $set['o_nogood'];
	$od[7] = $set['o_star'];
	$od[8] = $set['o_view'];
	$od[9] = $set['o_down'];

	//값이 있는 것만 선택
	for($i=0; $i < 10; $i++) {
		if((int)$od[$i] > 0) $order[] = $od[$i];
	}

	unset($od);

	if($order) {
		$is['details'] = true;
		sort($order); //정렬

		if($set['o_cate']) {
			$is['cate'] = true;
			list($od['cate']) = array_keys($order, $set['o_cate']);
			$css[$od['cate']] = 'la-data-cate';
		}

		if($set['o_name']) {
			$is['name'] = true;
			list($od['name']) = array_keys($order, $set['o_name']);
			$css[$od['name']] = 'la-data-name';
		}

		if($set['o_date']) {
			$is['date'] = true;
			list($od['date']) = array_keys($order, $set['o_date']);
			$set['date'] = $set['date'] ? $set['date'] : 1;
			$css[$od['date']] = 'la-data-date';
		}

		if($set['o_cmt']) {
			$is['cmt'] = true;
			list($od['cmt']) = array_keys($order, $set['o_cmt']);
			$css[$od['cmt']] = 'la-data-cmt';
		}

		if($set['o_hit']) {
			$is['hit'] = true;
			list($od['hit']) = array_keys($order, $set['o_hit']);
			$css[$od['hit']] = 'la-data-hit';
		}

		if($set['o_good']) {
			$is['good'] = true;
			list($od['good']) = array_keys($order, $set['o_good']);
			$css[$od['good']] = 'la-data-good';
		}

		if($set['o_nogood']) {
			$is['nogood'] = true;
			list($od['nogood']) = array_keys($order, $set['o_nogood']);
			$css[$od['nogood']] = 'la-data-nogood';
		}

		if ($set['o_star']) {
			$is['star'] = true;
			include_once(AMINA_PATH.'/lib/star.lib.php');
			list($od['star']) = array_keys($order, $set['o_star']);
			$css[$od['star']] = 'la-data-star';
		}

		if ($set['o_view']) {
			$is['view'] = true;
			list($od['view']) = array_keys($order, $set['o_view']);
			$css[$od['view']] = 'la-data-view';
		}

		if ($set['o_down']) {
			$is['down'] = true;
			list($od['down']) = array_keys($order, $set['o_down']);
			$css[$od['down']] = 'la-data-down';
		}

		$od['cnt'] = count($order);
	}
}

$od['cnt'] = $is['details'] ? $od['cnt'] : 0; //디테일수
$set['subj'] = $set['subj'] ? $set['subj'] : $subject_len; //제목길이
$set['icon'] = $set['icon'] ? $set['icon'] : 1; //아이콘
$set['star'] = $set['star'] ? $set['star'] : 'gold'; //별점
$set['list'] = $set['list'] ? ' '.$set['list'] : ''; //스타일

//리스트 출력
echo '<div class="latest-list-basic'.$set['list'].'">'."\n";
echo '<ul>'."\n";
for ($i=0; $i < $list_num; $i++) { 

	//Sperate
	if($set['sp'] && $i > 0 && $i%$set['sp'] == 0) echo '<li class="la-sp"></li>'."\n";

	//Icon
	if($set['icon'] != "none") {
		if($list[$i]['wr_rank'] && $set['rank_list_icon'] != 'none') {
			$icon = $rank_list_url.'/'.$list[$i]['wr_rank'].'.gif';
		} else {
			if($list[$i]['is_notice']) {
				$icon = 'icon_notice.gif';
			} else if($list[$i]['icon_secret']) {
				$icon = $list[$i]['icon_new'] ? 'icon_secret_new.gif' : 'icon_secret.gif';
			} else if($list[$i]['icon_new']) {
				$icon = 'icon_new.gif';
			} else if($set['icon'] == 'qa') {
				$icon = $list[$i]['icon_reply'] ? 'icon_a.gif' : 'icon_q.gif';
			} else {
				$wr_post = amina_array_write($list[$i]['wr_10']);
				if($wr_post['video'] == "video") {
					$icon = 'icon_video.gif';
				} else if($wr_post['photo'] == 'photo') {
					$icon = 'icon_photo.gif';
				} else if($wr_post['file'] == "file") {
					$icon = 'icon_file.gif';
				} else {
					$icon = $set['icon'].'.gif';
				}
			}
			$icon = $latest_list_url.'/img/'.$icon;
		}
		$icon = '<img src="'.$icon.'" alt="" />';
	} else {
		$icon = '';
	}

	//Subject
	if($set['cate'] && $list[$i]['ca_name']) $list[$i]['wr_subject'] = "[".$list[$i]['ca_name']."] ".$list[$i]['wr_subject'];
	$list[$i]['subject'] = '<span class="la-subj">'.amina_cut($list[$i]['wr_subject'], $set['subj']).'</span>';
	if($list[$i]['is_notice']) $list[$i]['subject'] = '<b>'.$list[$i]['subject'].'</b>';

	//List
	echo '<li class="la-list">';
	echo '<a href="'.$list[$i]['href'].'"'.$opt['href_target'].'>'.$icon.$list[$i]['subject'];

	if(!$is['cmt'] && $list[$i]['wr_comment']) echo '<span class="la-cmt">+'.$list[$i]['wr_comment'].'</span>';

	if($is['details']) { //Item Output
		if($is['cate']) $details[$od['cate']] = $list[$i]['ca_name']; //Category
		if($is['name']) $details[$od['name']] = get_text(cut_str($list[$i]['wr_name'], $config['cf_cut_name'])); //Name
		if($is['date']) { //Date
			switch($set['date']) {
				case '1'	: break;
				case '2'	: $list[$i]['datetime2'] = amina_date($list[$i]['wr_datetime']); break;
				default		: $list[$i]['datetime2'] = date($set['date'], strtotime($list[$i]['wr_datetime'])); break;
			}
			$details[$od['date']] = $list[$i]['datetime2'];
		}
		if($is['cmt']) $details[$od['cmt']] = '<span>댓글 </span>'.$list[$i]['wr_comment']; //Comment
		if($is['hit']) $details[$od['hit']] = '<span>조회 </span>'.number_format($list[$i]['wr_hit']); //Hit
		if($is['good']) $details[$od['good']] = '<span>추천 </span>'.$list[$i]['wr_good']; //Good
		if($is['nogood']) $details[$od['nogood']] = '<span>비추 </span>'.$list[$i]['wr_nogood']; //Nogood
		if($is['star']) $details[$od['star']] = amina_star_mark($set['star'], $list[$i]['wr_7'], 's'); //Star
		if($is['view'] || $is['down']) {
			$wr_icon = amina_array_icon($list[$i]['wr_5']);
			if($is['view']) $details[$od['view']] = $wr_icon['po_view_point'] > 0 ? '<span>열람 </span>'.number_format($wr_icon['po_view_point']) : '<span>열람 </span>무료'; //Po View
			if($is['down']) $details[$od['down']] = $wr_icon['po_down_point'] > 0 ? '<span>다운 </span>'.number_format($wr_icon['po_down_point']) : '<span>다운 </span>무료'; //Po Down
		} 
			
		echo '<span class="la-details">';
		$z = 0;
		for($o=0; $o < $od['cnt']; $o++) { 
			if (!$details[$o]) continue;
			$css_data = ($z == 0) ? 'la-data-first ' : 'la-data ';
			echo '<span class="'.$css_data.$css[$o].'">'.$details[$o].'</span>';
			$z++;
		}
		echo '</span>';
		unset($datails);
	}
	echo '</a></li>'."\n";
}

//none
if($list_num == 0) echo '<li class="la-none">게시물이 없습니다.</li>'; 

echo '</ul>'."\n";
echo '<div class="clear"></div></div>'."\n";

?>