<?php
$arr_search_keyword = array();
if($search_keyword!=''){
	$arr_search_keyword = explode(" ", $search_keyword);
}

?>

<? require_once(APPPATH."views/m/search/search_header.php"); ?>


	<div class="contents">
		<div class="wrap">

<? if(count($list)==0) {?>
	<div class="news_nothing">
		<div class="t_nothing"><span class="beachblue"><?=$search_keyword?></span> 에 대한 검색결과가 없습니다.</div>
		<ul>
			<li>단어의 철자가 정확한지 확인해 보세요.</li>
			<li>한글을 영어로 혹은 영어를 한글로 입력했는지 확인해보세요.</li>
			<li>검색어의 단어 수를 줄이거나, 보다 일반적인 검색어로 다시 검색해보세요.</li>
			<li>두 단어 이상의 검색어인 경우, 띄어쓰기를 확인해 보세요.</li>
			<li>검색 옵션을 변경해서 다시 검색해 보세요.</li>
		</ul>
	</div>

<?	} else {?>



			<div class="news_cont2">
				<div class="news_box_title">
					뉴스 <span class="info"><span><?=number_format($start_row)?>-<?=number_format($end_row)?></span> | <span><?=number_format($total_count)?>건</span></span>
				</div>
				<div class="serchview">
				<? if(@$_GET['content_idx']):

					$tmp = $_SERVER['REQUEST_URI'];
					$uri = explode("?",$tmp);
					$uri_org = $uri[0];
					$uri = explode("&",$uri[1]);
					$key = array();
					$value = array();
					foreach($uri as $data){
						$kv = explode("=",$data);

						if($kv[0] != "content_idx"){
							$key[] = $kv[0];
							$value[] = $kv[1];
						}

					}
					$str = array();
					foreach($key as $i => $data){
						$str[] = $data."=".$value[$i];
					}

					$str = implode("&",$str);

					$uri_org .= "?".$str;
					?>
					<a href="<?=$uri_org?>">
						<img src="/img/mobile/img_back.gif"> <span>검색어 뉴스</span> 전체 검색결과 보기
					</a>
				<?endif;?>
				</div>
				<?	$i=1;
				foreach ($list as $key=>$val) {
					$title = $val['title'];
					$content = strip_tags($val['content']);
					$title_txt = mb_strimwidth($title, '0', '60', '..', 'utf-8');
					$content_txt = mb_strimwidth($content, '0', '180', '..', 'utf-8');
					$display_date_txt = gf_article_date_text($val['display_date']);

					foreach($arr_search_keyword as $val3) {
						$title_txt 		= str_replace($val3, '<b>'.$val3.'</b>', $title_txt);
						$content_txt	= str_replace($val3, '<b>'.$val3.'</b>', $content_txt);
					}



					$share_title 	= str_replace("'", "\\'", $val['title']);
					$share_title  	= str_replace('"', '\\"', $share_title);
					$share_content  = mb_strimwidth($content, '0', '250', '..', 'utf-8');
					$share_content  = htmlspecialchars($share_content);
					$share_content  = str_replace("'", "\\'", $share_content);
					$share_content  = str_replace('”', '"', $share_content);

					$main_img = $val['main_img'];
					$press_txt = $val['press_name'];
					if($val['press_homepage']!='') {
						$press_txt = '<a href="'.$val['press_homepage'].'" target="_blank">'.$val['press_name'].'</a>';
					}
					$view_url = '/m/news/news_view/'.$val['idx'];
					$share_id_name ="news_".$val['idx'];


					?>
					<input type="hidden" name="content_<?=$share_id_name?>" id="content_<?=$share_id_name?>" value="<?=$share_content?>">
					<input type="hidden" name="title_<?=$share_id_name?>" id="title_<?=$share_id_name?>" value="<?=$share_title?>">
					<input type="hidden" name="copy_url_<?=$share_id_name?>" id="copy_url_<?=$share_id_name?>" value="<?=WWW_CROSSMAP?><?=$view_url?>">
					<input type="hidden" name="img_url_l<?=$share_id_name?>" id="img_url_<?=$share_id_name?>" value="<?=WWW_CROSSMAP?><?=$main_img?>">
				<div class="news_box">
					<div class="news_box_con">
						<h2 class="search_tit"><a href="<?=$view_url?>"><?=$title_txt?></a></h2>
						<div class="news_box_con_left">
							<div><?=$content_txt?></div>
						</div>
						<div class="news_box_detail2">

							<span><?=$press_txt?></span>
							<span><img src="/img/mobile/search_bar.gif"></span>
							<span><?=$display_date_txt?></span>
							<span><img src="/img/mobile/search_bar.gif"></span>
							<span><a href="<?=$view_url?>">크로스맵뉴스</a></span>

						</div>
						<div class="news_box_con_right<?=($val['video_url']) ? " plays_b" : ""; ?>">
							<a href="<?=$view_url?>"><img src="<?=$main_img?>"></a>
						</div>

						<?
						if(isset($arr_news_relation_article[$val['idx']])==true) {
							if(count($arr_news_relation_article[$val['idx']]) > 0 ) {?>
						<div class="relatednews">
								<? 	$i=1;
								foreach ($arr_news_relation_article[$val['idx']] as $key1=>$val1) {

									$relation_title_txt = mb_strimwidth($val1['title'], '0', '53', '..', 'utf-8');
									$press_txt = $val1['press_name'];
									if($val1['press_homepage']!='') {
										$press_txt = '<a href="'.$val1['press_homepage'].'" target="_blank">'.$val1['press_name'].'</a>';
									}

									$display_date_txt = gf_article_date_text($val1['display_date']);
									?>

									<div class="relatednews_box">
										<span class="relatednews_tit"><img src="/img/web/search_reply.gif"><a href="/m/news/news_view/<?=$val1['idx']?>"><?=$relation_title_txt?></a></span>
										<span class="relatednews_info news_box_detail2">
											<span><?=$press_txt?></span>
											<span style="color:#c2c2c2;">|</span>
											<span><?=$display_date_txt?></span>
											<span style="color:#c2c2c2;">|</span>
											<span><a href="/m/news/news_view/<?=$val1['idx']?>">크로스맵뉴스</a></span>
										</span>
									</div>
									<?
									if($i==4)	break;
									$i++;
								}

								?>

						</div>
								<div class="fr beachblue" style="margin-top: 5px;">
									<a href="/m/search/news?search_keyword=<?=$search_keyword?>&content_idx=<?=$val['idx']?>" >관련뉴스 <?=count($arr_news_relation_article[$val['idx']])?>건 전체보기&gt;</a>
								</div>
								<?
							}

						}

						?>


					</div>
				</div>

					<?}?>

				<div class="pagenumber">
					<?=$pagination?>
				</div>



			</div>

		<?}?>

		</div>
	</div>

<? require_once(APPPATH."views/m/search/search_footer_inc.php"); ?>
<?
$title = ''; $content = ''; $main_img = '';
require_once(APPPATH."views/web/comm/share_box_inc.php"); ?>
<script>
var share_key = '';
$('.share_btn').click(function(e) {
	$("#share_box").toggle();
	var key = $(this).attr('strA');

	$("#share_content").val($("#content_"+key).val());
	$("#share_title").val($("#title_"+key).val());
	$("#share_copy_url").val($("#copy_url_"+key).val());
	$("#share_img_url").val($("#img_url_"+key).val());
	$("#copy_url").val($("#copy_url_"+key).val());

    var popH = $(this).offset().top;
	var popL = $(this).offset().left;

    $('.popup_share').css('left',(popL+120)+'px');
	$('.popup_share').css('top',popH+'px');

	share_key = key;


});
</script>


