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

if (!defined('AMINA_NIVOSLIDER3')) include_once(AMINA_PATH.'/app/nivoslider3.php');

if (!defined('LAL_BASIC_TITLE')) {
	define('LAL_BASIC_TITLE', true);
	echo '<link rel="stylesheet" href="'.$latest_list_url.'/latest.list.css" media="screen">'."\n";
}

$dList = array();
$img = array();

//Thumbnail
list($thumb_w, $thumb_h) = explode("x", $opt['thumb']);

//Default Value;
$opt['subj'] = ($opt['subj'] > 0) ? $opt['subj'] : $subject_len; //Subject Length
$opt['date'] = $opt['date'] ? $opt['date'] : 1; //Date Type
$opt['subj_icon'] = $opt['subj_icon'] ? $opt['subj_icon'] : 'chevron-circle-right';
if($opt['icon'] == 'none') $opt['subj_icon'] = '';
$opt['star_type'] = $opt['star_type'] ? $opt['star_type'] : 's'; //Star Type

//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");

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

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

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

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

//fancyBox
$fbox_w = $fbox_q = '';
if($opt['fbox']) {
	if($opt['fbox'] == 'full') {
		$fbox_w = 'class="fbox-full" ';
	} else {
		$fbox_w = 'class="fbox-win" ';
		$fbox_q = '&frame=2';

		if($opt['fbox'] > 1) {
			$fbox_w .= 'data-fbox-width="'.$opt['fbox'].'" ';
			$fbox_q .= '&fwidth='.$opt['fbox'];
		}
	}
} 

$j = 0;
for ($i=0; $i < count($list); $i++) {

	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']);

	if($img_url) {
		$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 & Secret
		$is_blind = 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']) {
			$list[$i]['wr_content'] = $list[$i]['wr_3'] = '비밀글입니다.';
		}

		//Item Output
		if($opt['caption'] != 'none') {
			//Details
			$details_item = '';
			$details_css = 'la-data-first';
			for($k=0; $k < $dCount; $k++) {
				$dItem = $dList[$k];
				$dItem_var = amina_details($dItem, $list[$i], $opt['date'], $opt['star'], $opt['star_type']);
				$dItem_var = $dItem_var ? amina_icon($fa[$dItem]).$dItem_var : '';
				$details_item .= '<b class=\''.$details_css.' la-data-'.$dItem.'\'>'.$dItem_var.'</b>';
				$details_css = 'la-data';
			}

			if($details_item) $details_item = '<span class=\'la-details\'>'.$details_item.'</span>';

			$post_icon = ''; //Post Icon
			if($opt['subj'] != 'none') {
				$post_icon = $opt['subj_icon'];
				if($is_rank) { //Rank
					$post_icon = '<span class=\'la-rank la-rank-'.$list[$i]['wr_rank'].'\'>'.$list[$i]['wr_rank'].'</span>';
				} else if($post_icon) {
					if($is_blind) {
						$post_icon = 'eye-slash';
					} else if($list[$i]['is_notice']) {
						$post_icon = 'bell';
					} else if($list[$i]['icon_secret']) {
						$post_icon = 'lock';
					} else if($list[$i]['icon_new']) {
						$post_icon = 'chevron-circle-right';
					} else if($list[$i]['icon_hot']) {
						$post_icon = 'thumbs-up';
					} else if($opt['attach_icon']) {
						if($wr_post['video'] == "video") {
							$post_icon = 'video-camera';
						} else if($wr_post['photo'] == "photo") {
							$post_icon = 'picture';
						} else if($wr_post['file'] == "file") {
							$post_icon = 'download';
						}
					}

					$post_icon = '<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 = ($opt['cate'] && $list[$i]['ca_name']) ? '['.$list[$i]['ca_name'].'] '.amina_cut($list[$i]['wr_subject'], $opt['subj']) : amina_cut($list[$i]['wr_subject'], $opt['subj']);
				$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>";
			}
		}
		$img[$j]['caption'] = ($details_item || $subject) ? ' title="'.$details_item.$post_icon.$subject.'"' : '';
		$img[$j]['img'] = ($opt['thumb_w'] > 0) ? amina_make_thumb($img_url, $thumb_w, $thumb_h, 100) : $img_url;
		$img[$j]['href'] = ($opt['href'] == 'link' && $list[$i]['wr_link1']) ? $list[$i]['link_href'][1] : $list[$i]['href'];
		$j++;
	}
}

$img_cnt = count($img);

if($img_cnt > 0) {
	$is_post = true;
} else {
	unset($img);
	$is_post = false;
	$caption_subject = str_replace("\"", "", amina_text($config['cf_title']));
	if(is_dir(THEMA_PATH.'/logo/')) {
		$handle = opendir(THEMA_PATH.'/logo/');
		while ($file = readdir($handle)) {
			if(preg_match("/\.(jpg|jpeg|bmp|gif|png)$/i", $file)) {
				$img[]['img'] = THEMA_URL.'/logo/'.$file;
			}
		}
		closedir($handle);
		$img_cnt = count($img);
	}

	if($img_cnt > 0) {
		;
	} else {
		unset($img);
		$handle = opendir($latest_list_path.'/logo/');
		while ($file = readdir($handle)) {
			if(preg_match("/\.(jpg|jpeg|bmp|gif|png)$/i", $file)) {
				$img[]['img'] = $latest_list_url.'/logo/'.$file;
			}
		}
		closedir($handle);
		$img_cnt = count($img);
	}
}

if($opt['rdm']) shuffle($img);

//Effefct
$opt['effect'] = $opt['effect'] ? $opt['effect'] : 'random';
$opt['slice'] = ($opt['slice'] > 0) ? $opt['slice'] : 15;
$opt['boxcol'] = ($opt['boxcol'] > 0) ? $opt['boxcol'] : 8;
$opt['boxrow'] = ($opt['boxrow'] > 0) ? $opt['boxrow'] : 4;
$opt['speed'] = ($opt['speed'] > 0) ? $opt['speed'] : 1000;
$opt['pause'] = ($opt['pause'] > 0) ? $opt['pause'] : 3000;
$opt['hover'] = $opt['hover'] ? 'true' : 'false';
$opt['arrow'] = $opt['arrow'] ? 'true' : 'false';

//ID 랜덤 설정
$chars_array = range('a','k');
shuffle($chars_array);
$la_id = implode('', $chars_array);

?>

<style>
	.<?php echo $la_id; ?> .nivoSlider { padding-bottom: <?php echo $opt['img_h'] ? $opt['img_h'] : '35%'; ?>; }
</style>

<div class="lal-basic-title <?php echo $la_id; ?><?php echo $opt['list'] ? ' '.$opt['list'] : ''; ?>">
	<div class="la-box">
		<div class="la-list">
			<div id="<?php echo $la_id; ?>" class="nivoSlider">
			<?php 
				for($i=0; $i < $img_cnt; $i++) {
					if($opt['caption'] != 'none') {	
						if(!$is_post && $opt['subj'] != 'none') { 
							$img[$i]['caption'] = ' title="'.$caption_subject.'"';
						}
					}
					$a_href = ($img[$i]['href'] && $opt['href'] != 'none') ? ' '.$fbox_w.'href="'.$img[$i]['href'].$fbox_q.$img[$i]['href_cmt'].'"'.$opt['href_target'] : '';
					echo '<a'.$a_href.'><img src="'.$img[$i]['img'].'"'.$img[$i]['caption'].' alt="" /></a>'."\n";
				} 
			?>
			</div>
			<div class="clear"></div>
		</div>
	</div>
</div>

<script src="<?php echo $latest_list_url; ?>/js/jquery.nivo.slider.pack.js"></script>
<script>
	addLoadEvent(function() {
	   $('#<?php echo $la_id; ?>').nivoSlider({
	        effect: '<?php echo $opt['effect']; ?>', // Specify sets like: 'fold,fade,sliceDown'
		    slices: <?php echo $opt['slice']; ?>, // For slice animations
	        boxCols: <?php echo $opt['boxcol']; ?>, // For box animations
		    boxRows: <?php echo $opt['boxrow']; ?>, // For box animations
	        animSpeed: <?php echo $opt['speed']; ?>, // Slide transition speed
		    pauseTime: <?php echo $opt['pause']; ?>, // How long each slide will show
	        startSlide: 0, // Set starting Slide (0 index)
		    directionNav: <?php echo $opt['arrow']; ?>, // Next & Prev navigation
	        pauseOnHover: <?php echo $opt['hover']; ?>, // Stop animation while hovering
	        controlNav: false
		});
	});
</script>
