<?
$category_name = $arr_category['category_name'];
$category_code1 = $arr_category1['category_code'];
$category_name1 = $arr_category1['category_name'];
$category_code2 = '';
$category_name2 = '';
if (isset($arr_category2['category_code']) == true) {
	$category_code2 = $arr_category2['category_code'];
	$category_name2 = $arr_category2['category_name'];
}
$category_code3 = '';
$category_name3 = '';
if (isset($arr_category3['category_code']) == true) {
	$category_code3 = $arr_category3['category_code'];
	$category_name3 = $arr_category3['category_name'];
}
$ci =& get_instance();
$ci->load->model('web/m_contents_setting');
$arr_news_setting   = $ci->m_contents_setting->contents_setting_select(1);


$category_txt = "<a href='/m/news/category/".$category_code1."'>".$category_name1."</a>";
if ($category_name2 != '') $category_txt .= ' <img src="/img/mobile/arrow_left.gif" style="vertical-align:baseline"> <a href="/m/news/category/'.$category_code2.'">' . $category_name2."</a>";
if ($category_name3 != '') $category_txt .= ' <img src="/img/mobile/arrow_left.gif" style="vertical-align:baseline"> <a href="/m/news/category/'.$category_code3.'">' . $category_name3."</a>";
$page_title = "뉴스";
$page_title_link = '/m/#news';

if (@$_GET['page']):

	foreach ($list as $val) :

		$press_homepage = $val['press_homepage'];
		$comment_count = $val['comment_count'];
		$comment_count_txt = $comment_count;
		if ($comment_count > 9) {
			$calc_count = str_pad(1, strlen($comment_count), "0", STR_PAD_RIGHT);
			$comment_count_txt = (floor($comment_count / $calc_count)) * $calc_count;
			$comment_count_txt = $comment_count_txt . '+';
		}

		$display_date = $val['display_date'];
		$display_date_txt = substr($display_date, 0, 10);
		$display_date_txt = str_replace('-', '.', $display_date_txt);

		$title_txt = mb_strimwidth($val['title'], '0', '60', '..', 'utf-8');
		$content = preg_replace("(\<(/?[^\>]+)\>)", "", $val['content']);
		$content = strip_tags($content);
		$content_txt = mb_strimwidth($content, '0', '250', '..', 'utf-8');

		?>


		<div class="news_list_cont" style="margi-top:50px;">
			<div class="art-img2"><a href="/m/news/news_view/<?= $val['idx'] ?>"><img src="<?= $val['main_img'] ?>"
																					  width="160"></a></div>
			<div class="art-info2">
				<h2 class="art-title"><a href="/m/news/news_view/<?= $val['idx'] ?>"><?= $title_txt ?></a></h2>
				<p class="art-info"><?= $display_date_txt ?>


					<? if($arr_news_setting['etc_char1']=='Y') {?> |
						<a target="_blank" href="<?= $val['press_homepage'] ?>"><?= $val['press_name'] ?></a>
					<?}?>

					<span
						class="feedback fr"><img src="/img/mobile/img_comments.gif"> <?= $comment_count_txt ?>+</span>
				</p>
			</div>
		</div>


	<?endforeach;
	exit();
else :?>
	<?
	require_once(APPPATH . "/views/m/common/light_header.php"); ?>
	<div class="news_cont2" style="padding-top:50px">
		<div class="news_cate2" style="box-sizing: border-box;">
			<span class="beachblue" style="padding-right:5px;">기사</span>
			<span class="category fr" style="font-size:14px;line-height: 22px;">

				<?=$category_txt?>
</span>
			</span>
		</div>
		<div class="news_lists" style="padding-top: 0px; padding-bottom: 25px;">
			<div class="rankynews">
				<div class="rankytop" style="margin-bottom:10px; border-bottom: 1px solid #ddd;">
					<span <? if ($search_sort == '1') {
						echo 'class="radio_on"';
					} else {
						echo 'class="radio_off"';
					} ?> style="margin-right:10px;width: 60px;float: left;"><a
							href="/m/news/category/<?= $category_code ?>?search_sort=1">최신순</a></span>
					<span <? if ($search_sort == '2') {
						echo 'class="radio_on"';
					} else {
						echo 'class="radio_off"';
					} ?> style="float: left;width: 60px;"><a
							href="/m/news/category/<?= $category_code ?>?search_sort=2">인기순</a></span>
				</div>
			</div>

			<?


			foreach ($list as $val) :

				$press_homepage = $val['press_homepage'];
				$comment_count = $val['comment_count'];
				$comment_count_txt = $comment_count;
				if ($comment_count > 9) {
					$calc_count = str_pad(1, strlen($comment_count), "0", STR_PAD_RIGHT);
					$comment_count_txt = (floor($comment_count / $calc_count)) * $calc_count;
					$comment_count_txt = $comment_count_txt . '+';
				}

				$display_date = $val['display_date'];
				$display_date_txt = substr($display_date, 0, 10);
				$display_date_txt = str_replace('-', '.', $display_date_txt);

				$title_txt = mb_strimwidth($val['title'], '0', '60', '..', 'utf-8');
				$content = preg_replace("(\<(/?[^\>]+)\>)", "", $val['content']);
				$content = strip_tags($content);
				$content_txt = mb_strimwidth($content, '0', '250', '..', 'utf-8');

				?>


				<div class="news_list_cont">
					<div class="art-img2"><a href="/m/news/news_view/<?= $val['idx'] ?>"><img
								src="<?= $val['main_img'] ?>" width="160"></a></div>
					<div class="art-info2">
						<h2 class="art-title"><a href="/m/news/news_view/<?= $val['idx'] ?>"><?= $title_txt ?></a></h2>
						<p class="art-info"><?= $display_date_txt ?>
							<? if($arr_news_setting['etc_char1']=='Y') {?> |
							 <a target="_blank" href="<?= $val['press_homepage'] ?>"><?= $val['press_name'] ?></a>
																		  <?}?>
																		  <span
								class="feedback fr"><img src="/img/mobile/img_comments.gif"> <?= $comment_count_txt ?>+</span>
						</p>
					</div>
				</div>


			<? endforeach; ?>



		</div>

		<p style="text-align:center;">
			<button type="button" class="btn btn-default br20" style="padding:8px 40px; font-size:16px;" onclick="get_page()" id="add">더보기 <img
					src="/img/mobile/arr_down.gif" style="vertical-align:middle;"></button>
		</p>
	</div>


	</div>


	</div>
	</div>
<script>
	page = 2;
	function get_page(){


		var add = '<?=
			isset($_GET['search_sort'])?
			"&":"?";

			?>';
		a = window.location.href+add+"page="+page;
		$.ajax({
			type :"get",
			url : a,
			success : function(data){

				if(data.toString().trim().length > 0){
					$(".news_lists").append(data);
					page++;
				}
				else{
					alert("마지막 페이지 입니다.");

				}
			}

		});
	}
</script>
<? endif; ?>
