<?php
$_siteUrl = function ($value) {
	$value = trim(html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'));
	if ($value === '') return '';
	if (!preg_match('#^https?://#i', $value)) $value = 'https://' . $value;
	if (!filter_var($value, FILTER_VALIDATE_URL)) return '';
	$scheme = strtolower((string)parse_url($value, PHP_URL_SCHEME));
	return in_array($scheme, array('http','https'), true) ? $value : '';
};
$_siteHost = function ($value) {
	return preg_replace('/^www\./i', '', (string)parse_url($value, PHP_URL_HOST));
};
$_siteExcerpt = function ($content) {
	$text = trim(preg_replace('/\s+/u', ' ', strip_tags(html_entity_decode((string)$content, ENT_QUOTES, 'UTF-8'))));
	return $text !== '' ? getStrCut($text, 105, '…') : '주스큐로 제작된 웹사이트를 만나보세요.';
};
$_siteImage = function ($upload, $date, $content, $ext) {
	if ($upload) {
		$items = getArrayString($upload);
		foreach ($items['data'] as $uid) {
			$file = getUidData($GLOBALS['table']['s_upload'], $uid);
			if (!$file['uid'] || !in_array(strtolower($file['ext']), array('jpg','jpeg','gif','png','webp'), true)) continue;
			$name = $file['tmpname'] ? $file['tmpname'] : $file['thumbname'];
			if ($name) return $file['url'].$file['folder'].'/'.$name;
		}
	}
	return getUploadImage($upload, $date, $content, $ext);
};
?>
<div id="bbslist" class="site-showcase">
	<div class="bbs-modern-head site-showcase-head"><span>MADE WITH JUSQ</span><h1><?php echo htmlspecialchars($B['name']?$B['name']:'추천 웹사이트',ENT_QUOTES,'UTF-8')?></h1><p>주스큐로 만든 멋진 홈페이지를 소개합니다.</p></div>
	<div class="info">
		<div class="article"><?php echo number_format($NUM+count($NCD))?>개의 사이트 · <?php echo $p?>/<?php echo $TPG?>페이지</div>
		<div class="category">
			<?php if($my['admin']):?><a href="<?php echo $g['s']?>/?r=<?php echo $r?>&amp;m=admin&amp;module=<?php echo $m?>&amp;uid=<?php echo $B['uid']?>"><img src="<?php echo $g['img_core']?>/_public/btn_admin.gif" alt="게시판 관리" title="게시판 관리" /></a><a href="<?php echo $g['s']?>/?r=<?php echo $r?>&amp;m=admin&amp;module=<?php echo $m?>&amp;front=skin&amp;theme=<?php echo $d['bbs']['skin']?>"><img src="<?php echo $g['img_core']?>/_public/btn_explorer.gif" alt="테마 관리" title="테마 관리" /></a><?php endif?>
			<?php if($B['category']):$_catexp=explode(',',$B['category']);$_catnum=count($_catexp)?><select aria-label="카테고리" onchange="document.bbssearchf.cat.value=this.value;document.bbssearchf.submit();"><option value="">전체 사이트</option><?php for($i=1;$i<$_catnum;$i++):if(!$_catexp[$i])continue;?><option value="<?php echo htmlspecialchars($_catexp[$i],ENT_QUOTES,'UTF-8')?>"<?php if($_catexp[$i]==$cat):?> selected="selected"<?php endif?>><?php echo htmlspecialchars($_catexp[$i],ENT_QUOTES,'UTF-8')?></option><?php endfor?></select><?php endif?>
		</div><div class="clear"></div>
	</div>
	<?php if($NUM || count($NCD)):?>
	<div class="site-card-grid">
		<?php foreach(array_merge($NCD,$RCD) as $R):?>
		<?php $_thumbimg=$_siteImage($R['upload'],$R['d_regis'],$R['content'],$d['theme']['picimgext']);$_homepage=$_siteUrl($R['adddata']);$_hostname=$_homepage?$_siteHost($_homepage):'';$_viewUrl=$g['bbs_view'].$R['uid'];?>
		<article class="site-card<?php if($R['notice']):?> is-notice<?php endif?>">
			<a class="site-card-thumb" href="<?php echo $_viewUrl?>" aria-label="<?php echo htmlspecialchars($R['subject'],ENT_QUOTES,'UTF-8')?> 상세보기">
				<?php if($_thumbimg):?><img src="<?php echo htmlspecialchars($_thumbimg,ENT_QUOTES,'UTF-8')?>" alt="<?php echo htmlspecialchars($R['subject'],ENT_QUOTES,'UTF-8')?> 홈페이지 미리보기" loading="lazy" /><?php else:?><span class="site-card-placeholder"><strong>JUSQ</strong><small>WEBSITE SHOWCASE</small></span><?php endif?>
				<?php if($R['category']):?><span class="site-card-category"><?php echo htmlspecialchars($R['category'],ENT_QUOTES,'UTF-8')?></span><?php endif?>
			</a>
			<div class="site-card-body">
				<div class="site-card-meta"><?php if($R['notice']):?><span class="site-card-notice">추천</span><?php endif?><span><?php echo getDateFormat($R['d_regis'],'Y.m.d')?></span><span>조회 <?php echo number_format($R['hit'])?></span></div>
				<h2><a href="<?php echo $_viewUrl?>"><?php echo htmlspecialchars(getStrCut($R['subject'],$d['bbs']['sbjcut'],''),ENT_QUOTES,'UTF-8')?></a></h2>
				<p><?php echo htmlspecialchars($_siteExcerpt($R['content']),ENT_QUOTES,'UTF-8')?></p>
				<div class="site-card-actions"><a class="site-detail-link" href="<?php echo $_viewUrl?>">상세보기</a><?php if($_homepage):?><a class="site-visit-link" href="<?php echo htmlspecialchars($_homepage,ENT_QUOTES,'UTF-8')?>" target="_blank" rel="noopener noreferrer external"><span><?php echo htmlspecialchars($_hostname,ENT_QUOTES,'UTF-8')?></span> 방문하기 <b aria-hidden="true">↗</b></a><?php endif?></div>
			</div>
		</article>
		<?php endforeach?>
	</div>
	<?php else:?><div class="site-card-empty"><strong>등록된 웹사이트가 없습니다.</strong><span>주스큐로 만든 첫 번째 사이트를 소개해 주세요.</span></div><?php endif?>
	<div class="bottom"><div class="btnbox1"><?php if($B['uid']):?><span class="btn00"><a href="<?php echo $g['bbs_write']?>">사이트 등록</a></span><?php endif?></div><div class="btnbox2"><span class="btn00"><a href="<?php echo $g['bbs_reset']?>">처음목록</a></span><span class="btn00"><a href="<?php echo $g['bbs_list']?>">새로고침</a></span></div><div class="clear"></div><div class="pagebox01"><?php echo getPageLink($d['theme']['pagenum'],$p,$TPG,$g['img_core'].'/page/default')?></div></div>
	<div class="searchform"><form name="bbssearchf" action="<?php echo $g['s']?>/"><input type="hidden" name="r" value="<?php echo $r?>" /><input type="hidden" name="c" value="<?php echo $c?>" /><input type="hidden" name="m" value="<?php echo $m?>" /><input type="hidden" name="bid" value="<?php echo $bid?>" /><input type="hidden" name="cat" value="<?php echo $cat?>" /><input type="hidden" name="sort" value="<?php echo $sort?>" /><input type="hidden" name="orderby" value="<?php echo $orderby?>" /><input type="hidden" name="recnum" value="<?php echo $recnum?>" /><input type="hidden" name="type" value="<?php echo $type?>" /><input type="hidden" name="iframe" value="<?php echo $iframe?>" /><input type="hidden" name="skin" value="<?php echo $skin?>" /><?php if($d['theme']['search']):?><select name="where"><option value="subject|tag"<?php if($where=='subject|tag'):?> selected="selected"<?php endif?>>제목+태그</option><option value="content"<?php if($where=='content'):?> selected="selected"<?php endif?>>본문</option></select><input type="text" name="keyword" size="30" value="<?php echo htmlspecialchars($_keyword,ENT_QUOTES,'UTF-8')?>" class="input" /><input type="submit" value="검색" class="btngray" /><?php endif?></form></div>
</div>
