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

//FA Icon
$fa = array("cate"=>"tag", "name"=>"user", "date"=>"clock-o", "cmt"=>"comment", "hit"=>"eye", "good"=>"thumbs-up", "nogood"=>"thumbs-down", "star"=>"", "view"=>"leaf", "down"=>"download", "more"=>"check-circle");

//Default Value;
$set['subj'][$s] = ($set['subj'][$s] > 0) ? $set['subj'][$s] : ''; //Subject Length
$set['date'][$s] = $set['date'][$s] ? $set['date'][$s] : 1; //Date Type
$set['star_type'][$s] = $set['star_type'][$s] ? $set['star_type'][$s] : 's'; //Star Type
$set['more'][$s] = $set['more'][$s] ? $set['more'][$s] : 'More'; //More Type
$set['img_full'][$s] = $set['img_full'][$s] ? ' la-full' : ''; //Icon Type
if(!$set['subj_icon'][$s]) $set['subj_icon'][$s] = $set['icon'][$s] ? '1' : 'chevron-circle-right';

//Print
$set['print'][$s] = $set['print'][$s] ? $set['print'][$s] : 'img;subj;details;cont;btn'; //More Type
$p = explode(";", $set['print'][$s]);
$p_cnt = count($p);

//Comment
$is_subj_cmt = ($set['subj_cmt'][$s] && $set['subj_cmt'][$s] != 'none') ? true : false;
$is_cmt = $set['subj_cmt'][$s] ? false : true;

//Subj Type
$is_cmt_gul = (($opt['type'] == "newcmt" || $opt['type'] == "cmt") && $set['subj_type'][$s]) ? true : false;

//Rank
$is_rank = ($opt['order'] && $set['rank_skin'][$s] != 'none' && ($opt['type'] != "newgul" && $opt['type'] != "newcmt" && $opt['type'] != "newcmtgul")) ? true : false;
$is_img_rank = ($opt['order'] && $set['img_rank_skin'][$s] != 'none' && ($opt['type'] != "newgul" && $opt['type'] != "newcmt" && $opt['type'] != "newcmtgul")) ? true : false;

$rank_url = $img_rank_url = '';
if($is_rank && $set['rank_icon'][$s]) {
	$set['rank_icon'][$s] = $set['rank_icon'][$s] ? $set['rank_icon'][$s] : 'basic';
	$rank_url = AMINA_URL.'/misc/icon/list-rank/'.$set['rank_icon'][$s];
	$rank_ext = (file_exists(AMINA_PATH.'/misc/icon/list-rank/'.$set['rank_icon'][$s].'/1.gif')) ? '.gif' : '.png';
}

if($is_img_rank && $set['img_rank_icon'][$s]) {
	$set['img_rank_icon'][$s] = $set['img_rank_icon'][$s] ? $set['img_rank_icon'][$s] : 'basic';
	$img_rank_url = AMINA_URL.'/misc/icon/img-rank/'.$set['img_rank_icon'][$s];
	$img_rank_ext = (file_exists(AMINA_PATH.'/misc/icon/img-rank/'.$set['img_rank_icon'][$s].'/1.gif')) ? '.gif' : '.png';
}

//Icon
$icon_url = $img_icon_url = '';
if(($set['icon'][$s] && $set['icon'][$s] != "none") || ($set['subj_icon'][$s] == 'qa')) {
	$set['icon'][$s] = $set['icon'][$s] ? $set['icon'][$s] : 'basic';
	$icon_url = AMINA_URL.'/misc/icon/list-icon/'.$set['icon'][$s];
	$icon_ext = (file_exists(AMINA_PATH.'/misc/icon/list-icon/'.$set['icon'][$s].'/icon-new.gif')) ? '.gif' : '.png';
}

if($set['img_icon'][$s] != "none") {
	$set['img_icon'][$s] = $set['img_icon'][$s] ? $set['img_icon'][$s] : 'basic';
	$img_icon_url = AMINA_URL.'/misc/icon/img-icon/'.$set['img_icon'][$s];
	$img_icon_ext = (file_exists(AMINA_PATH.'/misc/icon/img-icon/'.$set['img_icon'][$s].'/icon-new.gif')) ? '.gif' : '.png';
}

//Details
$dCount = 0;
if($set['details'][$s]) {
	$dList = explode(";", $set['details'][$s]);
	$dCount = count($dList);
}

//Btn
$bCount = 0;
if($set['btn'][$s]) {
	$bList = explode(";", $set['btn'][$s]);
	$bCount = count($bList);
}

//썸네일
list($thumb_w, $thumb_h) = explode("x", $set['thumb'][$s]);
$img_hover = $set['img_hover'][$s] ? '<div class="la-img-hover"></div>' : '';

?>

<div class="la-area-img<?php echo $set['list'][$s] ? ' '.$set['list'][$s] : ''; ?>">
	<ul>
	<?php 
		for ($i=$row_start; $i < $row_end; $i++) { 

			//Value
			$wr_post = amina_array_write($list[$i]['wr_10']);
			$wr_icon = amina_array_icon($list[$i]['wr_5']);
			$list[$i]['wr_view_point'] = $wr_icon['po_view_point'];
			$list[$i]['wr_down_point'] = $wr_icon['po_down_point'];

			if($is_cmt_gul) {
				$list[$i]['wr_subject'] = $list[$i]['wr_post']; //원글제목
				$cmt_cnt = $list[$i]['wr_post_cmt']; //원글 댓글수
			} else {
				$cmt_cnt = $list[$i]['wr_comment'];
			}

			//Blind
			$is_blind = $is_secret = false;
			if($list[$i]['wr_9'] == "lock" || $list[$i]['wr_9'] == "shingo") {
				$is_blind = true;
				$list[$i]['wr_subject'] = $list[$i]['wr_content'] = $list[$i]['wr_3'] = '블라인드 처리된 글입니다.';
			} else if ($list[$i]['icon_secret']) {
				$is_secret = true;
				$list[$i]['wr_content'] = $list[$i]['wr_3'] = '비밀글입니다.';
			}

			//Href
			$list[$i]['href'] = ($opt['href'] == 'link' && $list[$i]['wr_link1']) ? $list[$i]['link_href'][1] : $list[$i]['href'];
			$a_href = $fbox_w.'href="'.$list[$i]['href'].$fbox_q.$list[$i]['href_cmt'].'"'.$opt['href_target'];

			//Image
			$image = $img_url = $img_icon = '';
			if($set['img_icon'][$s] != "none") {
				if($is_img_rank) { //Img Rank
					$img_icon = $img_rank_url ? '<span class="la-img-rank-icon"><img src="'.$img_rank_url.'/'.$list[$i]['wr_rank'].$img_rank_ext.'" alt=""></span>' : '<span class="la-img-rank la-img-rank-'.$list[$i]['wr_rank'].'">'.$list[$i]['wr_rank'].'</span>';
				} else if($img_icon_url) {
					if($list[$i]['icon_new']) {
						$img_icon = '<span class="la-img-icon la-img-new-icon"><img src="'.$img_icon_url.'/icon-new'.$img_icon_ext.'" alt=""></span>';
					} else if($list[$i]['icon_hot']) {
						$img_icon = '<span class="la-img-icon la-img-hot-icon"><img src="'.$img_icon_url.'/icon-hot'.$img_icon_ext.'" alt=""></span>';
					} else if($wr_post['video'] == "video") {
						$img_icon = '<span class="la-img-icon la-img-video-icon"><img src="'.$img_icon_url.'/icon-video'.$img_icon_ext.'" alt=""></span>';
					}
				}
			}

			if($set['photo_img'][$s]) {
				$print['img'] = '<div class="la-img-box"><div class="la-img la-full">'.$img_icon.mb_photo($member['mb_id'], $list[$i]['mb_id'], 80, 80).'</div></div>';
			} else {
				if(!$is_blind && !$is_secret) list($img_url) = amina_thumb_img($list[$i]['file'], $list[$i]['wr_6'], $list[$i]['wr_content'], 1, $list[$i]['wr_4'], $list[$i]['wr_8'], $opt['linked_img']);
				$image = ($img_url && $thumb_w) ? amina_make_thumb($img_url, $thumb_w, $thumb_h) : $img_url;
				$img_type = $set['img_full'][$s];
				if(!$image && !$set['no_img'][$s]) {
					$image = AMINA_URL.'/img/blank.gif';
					$img_type = ' no-img';
				}

				if($image) {
					switch($set['img_href'][$s]) {
						case 'img'	: $a_img_href = $img_url ? 'class="fbox" href="'.$img_url.'"'.$opt['href_target'] : $a_href; break;
						case 'link'	: $a_img_href = $list[$i]['wr_link1'] ? 'href="'.$list[$i]['link_href'][1].'" target="_blank"' : $a_href; break;
						case 'none'	: $a_img_href = ''; break;
						default		: $a_img_href = $a_href; break;
					}
					$print['img'] = '<div class="la-img-box" title="'.str_replace("\"","", $list[$i]['wr_subject']).'"><div class="la-img'.$img_type.'"><a '.$a_img_href.'>'.$img_icon.'<img src="'.$image.'" alt="" />'.$img_hover.'</a></div></div>';
				}
			}

			//Details
			$details_item = '';
			$details_css = 'la-data-first';
			for($k=0; $k < $dCount; $k++) {
				$details_item .= '<b class="'.$details_css.' la-data-'.$dList[$k].'">'.amina_icon($fa[$dList[$k]]).amina_details($dList[$k], $list[$i], $set['date'][$s], $set['star'][$s], $set['star_type'][$s]).'</b>';
				$details_css = 'la-data';
			}

			if($details_item) $print['details'] = '<div class="la-details">'.$details_item.'</div>';

			//Btn
			$btn_item = '';
			for($k=0; $k < $bCount; $k++) {
				$btn_item .= '<span class="la-btn-'.$bList[$k].'">'.amina_icon($fa[$bList[$k]]).amina_details($bList[$k], $list[$i], $set['date'][$s], $set['star'][$s], $set['star_type'][$s], $set['more'][$s]).'</span>';
			}

			if($btn_item) $print['btn'] = '<div class="la-btn"><a '.$a_href.'>'.$btn_item.'</a></div>';

			//Post Icon
			$subject = $post_icon = '';
			if($set['subj'][$s] > 0) {
				if($set['icon'][$s] != "none") {
					$post_icon = $set['subj_icon'][$s];
					if($is_rank) { //Rank
						$post_icon = $rank_url ? '<img src="'.$rank_url.'/'.$list[$i]['wr_rank'].$rank_ext.'" alt="">' : '<span class="la-rank la-rank-'.$list[$i]['wr_rank'].'">'.$list[$i]['wr_rank'].'</span>';
					} else if($post_icon) {
						if($set['subj_icon'][$s] == 'qa') $post_icon = $list[$i]['icon_reply'] ? 'icon-a' : 'icon-q';
						if($is_blind) {
							$post_icon = $icon_url ? 'icon-blind' : 'eye-slash';
						} else if($list[$i]['is_notice']) { //Notice
							$post_icon = $icon_url ? 'icon-notice' : 'bell';
						} else if($list[$i]['icon_secret']) {
							$secret_new = $list[$i]['icon_new'] ? '-new' : '';
							$post_icon = $icon_url ? 'icon-secret'.$secret_new : 'lock';
						} else if($list[$i]['icon_new']) {
							$post_icon = $icon_url ? 'icon-new' : 'chevron-circle-right';
						} else if($list[$i]['icon_hot']) {
							$post_icon = $icon_url ? 'icon-hot' : 'thumbs-up';
						} else if($set['attach_icon'][$s]) {
							if($wr_post['video'] == "video") {
								$post_icon = $icon_url ? 'icon-video' : 'video-camera';
							} else if($wr_post['photo'] == "photo") {
								$post_icon = $icon_url ? 'icon-img' : 'picture';
							} else if($wr_post['file'] == "file") {
								$post_icon = $icon_url ? 'icon-file' : 'download';
							}
						}

						$post_icon = $icon_url ? '<img src="'.$icon_url.'/'.$post_icon.$icon_ext.'" alt="" />' : '<i class="fa fa-'.$post_icon.'"></i>';
						$post_icon = ($list[$i]['icon_new'] && $post_icon) ? '<span class="la-new">'.$post_icon.'</span>' : $post_icon;
					}
				}

				//Subject	
				$subject = ($set['subj_cate'][$s] && $list[$i]['ca_name']) ? '['.$list[$i]['ca_name'].'] '.amina_cut($list[$i]['wr_subject'], $set['subj'][$s]) : amina_cut($list[$i]['wr_subject'], $set['subj'][$s]);
				$subject = $list[$i]['is_notice'] ? '<b>'.$subject.'</b>' : $subject;
				if($is_subj_cmt && $cmt_cnt > 0) $subject .= ' <span class="la-subj-cmt">+'.number_format($cmt_cnt).'</span>';

				$print['subj'] = '<div class="la-subj-box"><a '.$a_href.'>';
				if($is_cmt && $cmt_cnt > 0) $print['subj'] .= '<span class="la-cmt">+'.number_format($cmt_cnt).'</span>';
				$print['subj'] .= '<span class="la-subj">'.$post_icon.$subject.'</span></a></div>';
			}

			if($set['cont'][$s] > 0) {
				$print['cont'] = ($set['summary'][$s] && $list[$i]['wr_3']) ? '<div class="la-cont">'.amina_cut($list[$i]['wr_3'], $set['cont'][$s]).'</div>' : '<div class="la-cont">'.amina_cut($list[$i]['wr_content'], $set['cont'][$s]).'</div>';
			}
		?>
		<li class="la-box">
			<div class="la-list">
				<?php 
					for($j=0; $j < $p_cnt; $j++) {
						echo $print[$p[$j]] ? $print[$p[$j]]."\n" : '';
					}
					unset($print);
				?>
				<div class="clear"></div>
			</div>
		</li>
	<?php } ?>
	</ul>
	<div class="clear"></div>
</div>
