<?php
defined('BASEPATH') or exit('No direct script access allowed');
define('HIDE_SUBNAVBAR', true);
?>
<!DOCTYPE html>
<html>
  <head>
    <title><?php echo ($search ? 'Blog &gt; Pencarian: '.html_escape($search): ($kategori ? 'Blog &gt; '.html_escape($kategori['bk_nama']) : 'Blog'));?></title>
    <?php include_once(VIEWPATH.'includes/head.php'); ?>
    <style type="text/css">
    body{padding-top:70px;}
    .title {font-size: 22px;line-height: 1;margin: 0 0 20px;padding: 0;border-bottom: 3px solid #ffdf7e;}
    .title span {display: inline-block;margin-bottom: -3px;padding-bottom: 10px;color: #333;border-bottom: 3px solid #f90;}
    .blog-content{padding-top:320px}
    .pager{margin-top:0;margin-bottom:20px;}
    .pager>li>a{width:140px;padding:10px 20px;text-align:center;border-radius:30px}
    .blog-post-content,.blog-post-meta{padding:16px 22px}
    .blog-post{margin-bottom:30px}
    .blog-post a{text-decoration:none}
    .total-comments{margin:10px auto;color:#999;}
    .blog-comments-title,.blog-post-title{margin-bottom:5px;font-size:24px;font-weight:400;color:#333}
    a:hover .blog-post-title{color:#777 !important}
    .blog-post-meta{color:#999;display:block;border-bottom:1px solid #EDEDED}
    .blog-post-date{margin:6px auto}
    .blog-post-content p{color:#999;margin:18px auto}
    .blog-post-content .btn{padding-left:20px;padding-right:20px;border-radius:20px}
    .blog-post p{font-size:13px;font-weight:400}
    .blog-post .panel-body{padding:0}
    .blog-post .panel>img{border-top-left-radius:2px;border-top-right-radius:2px;margin: 0 auto}
    .blog-comments .panel,.blog-post .panel{-webkit-transition:all .3s ease;transition:all .3s ease}
    .blog-comments:hover .panel,.blog-post:hover .panel{-webkit-box-shadow:0 10px 20px rgba(0,0,0,.19),0 6px 6px rgba(0,0,0,.23);box-shadow:0 10px 20px rgba(0,0,0,.19),0 6px 6px rgba(0,0,0,.23)}
    .label{font-size:12px;padding:4px 12px;border-radius:16px;font-weight:400;-webkit-transition:all .15s ease;transition:all .15s ease}
    .label-light{color:#333}
    .label-light,.label-light.label-default{background-color:#EBEBEB}
    .label-light.label-inverse{background-color:#D9DCF0}
    .label-light.label-primary{background-color:#CDEAE7}
    .label-light.label-success{background-color:#DBEFDC}
    .label-light.label-info{background-color:#CDEEFC}
    .label-light.label-warning{background-color:#FFDED3}
    .label-light.label-danger{background-color:#FCDAD7}
    .blog-post-meta>span+span{margin-left:5px}
    .sidebar-module .categories li{margin:12px auto}
    </style>
  </head>
  <body>
    <?php include_once(VIEWPATH.'includes/navbar.php'); ?>
    <div class="container">
      <ul class="breadcrumb">
        <li><a href="<?php echo site_url();?>"><i class="fa fa-home"></i></a></li>
        <?php if ($search):?>
        <li><a href="<?php echo site_url('blog');?>">Blog</a></li>
        <li class="active"><span>Pencarian: <?php echo html_escape($search);?></span></li>
        <?php elseif ($kategori):?>
        <li><a href="<?php echo site_url('blog');?>">Blog</a></li>
        <li class="active"><span><?php echo html_escape($kategori['bk_nama']);?></span></li>
        <?php else:?>
        <li class="active"><span>Blog</span></li>
        <?php endif;?>
      </ul>
      <div class="row">
        <div class="col-sm-8 blog-main">
          <h1 class="title"><span><?php echo ($search ? '<i class="fa fa-search"></i> Pencarian: '.html_escape($search): ($kategori ? '<i class="fa fa-tag"></i> '.html_escape($kategori['bk_nama']) : '<i class="fa fa-sticky-note-o"></i> Posting Terbaru'));?></span></h1>
          <?php if (!$results):?>
          <div class="alert alert-warning">Tidak ada posting</div>
          <?php else:?>
          <?php if ($search && $total && $page == 1):?>
          <div class="alert alert-info">Terdapat <strong><?php echo $total;?></strong> posting pada pencarian: <strong><?php echo html_escape($search);?></strong></div>
          <?php elseif ($kategori && $total && $page == 1):?>
          <div class="alert alert-info">Terdapat <strong><?php echo $total;?></strong> posting pada kategori: <strong><?php echo html_escape($kategori['bk_nama']);?></strong></div>
          <?php endif;?>
          <?php
          include_once (APPPATH.'third_party/simple_html_dom.php');
          $dom = new simple_html_dom();
          $out = array();
          $left = array();
          $right = array();
          for ($i = 0; $i < count($results); $i++) {
            $dom->load($results[$i]['bp_deskripsi']);
            if ($image = $dom->find('img', 0)) {
              $thumbnail = $image->src;
            } else {
              $thumbnail = '';
            }
            $dom->clear();
            $x = '<section class="blog-post"><div class="panel panel-default">';
            if ($thumbnail) {
              $x .= '<img data-src="'.$thumbnail.'" class="img-responsive" alt="'.html_escape($results[$i]['bp_judul']).'"/>';
            }
            $x .= '<div class="panel-body"><div class="blog-post-meta">';
            $kat = get_post_category($results[$i]['bp_kategori'], true);
            if (isset($kat[0]))
              $x .= '<span class="label label-light label-primary">'.$kat[0].'</span>';
            else
              $x .= '<span class="label label-light label-warning"><a href="'.site_url('blog/kategori/tak-berkategori').'">Tak Berkategori</a></span>';
            $x .= '<p class="blog-post-date pull-right">' . format_tanggal($results[$i]['bp_tanggal']) .
                '</p></div><div class="blog-post-content"><a href="'.site_url('blog/'.$results[$i]['bp_slug']) .
                '" title="'.html_escape($results[$i]['bp_judul']).'"><h2 class="blog-post-title">' .
                html_escape($results[$i]['bp_judul']) . '</h2></a><p>'.substr(strip_tags($results[$i]['bp_deskripsi']), 0, 200) .
                '</p><a class="btn btn-warning btn-sm" href="' . site_url('blog/'.$results[$i]['bp_slug']).
                '">Read more &raquo;</a><span class="pull-right total-comments"><i class="fa fa-comments-o"></i> '.$results[$i]['bp_total_comments'].'</span></div></div></div></section>';
            $out[] = $x;
            if ($i % 2) {
              $right[] = $x;
            } else {
              $left[] = $x;
            }
          }
          ?>
          <div class="row hidden-xs">
            <?php if ($left):?>
            <div class="col-sm-6">
              <?php echo implode('', $left);?>
            </div>
            <?php endif;?>
            <?php if ($right):?>
            <div class="col-sm-6">
              <?php echo implode('', $right);?>
            </div>
            <?php endif;?>
          </div>
          <div class="row visible-xs">
            <div class="col-sm-6">
              <?php echo implode('</div><div class="col-sm-6">', $out);?>
            </div>
          </div>
          <nav>
            <ul class="pager">
              <?php if ($page < ceil($total / $this->system->set['list_per_page'])):?>
              <li class="previous"><a class="withripple" href="<?php echo site_url('blog/'.($kategori ? 'kategori/'.$kategori['bk_slug'].'/' : 'page/').($page + 1).($search ? '?search='.urlencode($search) : ''));?>"><span aria-hidden="true">&larr;</span> Older</a></li>
              <?php endif;?>
              <?php if ($page > 1):?>
              <li class="next"><a class="withripple" href="<?php echo site_url('blog/'.($kategori ? 'kategori/'.$kategori['bk_slug'].'/' : 'page/').($page - 1).($search ? '?search='.urlencode($search) : ''));?>">Newer <span aria-hidden="true">&rarr;</span></a></li>
              <?php endif;?>
            </ul>
          </nav>
          <?php endif;?>
        </div>
        <div class="col-sm-3 col-sm-offset-1 blog-sidebar">
          <?php include(VIEWPATH.'blog/widgets.php');?>
        </div>
      </div>
    </div>
    <?php include_once(VIEWPATH.'includes/foot.php'); ?>
    <script src="<?php echo base_url('assets/js/lazyload.min.js');?>"></script>
    <script>
      var myLazyLoad = new LazyLoad();
    </script>
  </body>
</html>