<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
  <head>
    <title>Admin &gt; Blog</title>
    <?php include_once(VIEWPATH. 'includes/head.php'); ?>
    <style type="text/css">
    h4.media-heading{font-size:16px}
    .media-body>.nav>li{font-size: 11px;}
    .media-body>.nav>li>span{position:relative;display:block;}
    </style>
  </head>
  <body>
    <?php include_once(VIEWPATH. 'admin/_navbar.php'); ?>
    <div class="container">
      <ul class="breadcrumb">
        <li><a href="<?php echo site_url();?>"><i class="fa fa-home"></i></a></li>
        <li><a href="<?php echo site_url('admin');?>">Admin Panel</a></li>
        <li class="active"><span>Blog</span></li>
      </ul>
      <div class="row">
        <div class="col-sm-4 col-md-3">
          <?php include(dirname(__FILE__).'/_sidebar.php');?>
        </div>
        <div class="col-sm-8 col-md-9">
          <div class="panel panel-default">
            <div class="panel-heading">
              <?php if ($search):?>
              <h3><i class="fa fa-search"></i> Pencarian: <?php echo html_escape($search);?></h3>
              <?php elseif ($kategori):?>
              <h3><i class="fa fa-tag"></i> <?php echo html_escape($kategori['bk_nama']);?></h3>
              <?php else:?>
              <h3><i class="fa fa-sticky-note-o"></i> Posting</h3>
              <?php endif;?>
            </div>
            <div class="panel-body" style="padding-bottom: 0;">
              <div class="row">
                <div class="col-sm-4 col-md-3 col-lg-2" style="margin-bottom: 15px;">
                  <a class="btn btn-default btn-block" href="<?php echo site_url('admin/modules/blog/menulis-posting');?>"><i class="fa fa-pencil"></i> Menulis</a>
                </div>
                <div class="col-sm-8 col-md-offset-3 col-md-6 col-lg-offset-6 col-lg-4" style="margin-bottom: 15px;">
                  <form action="<?php echo site_url('admin/modules/blog');?>" method="GET">
                    <div class="input-group">
                      <input type="text" class="form-control" name="search" value="<?php echo html_escape($search);?>" placeholder="Pencarion..." />
                      <span class="input-group-btn">
                        <button class="btn btn-primary" type="submit"><i class="fa fa-search"></i></button>
                      </span>
                    </div>
                  </form>
                </div>
              </div>
            </div>
            <?php if (!$results):?>
            <div class="panel-body"><div class="alert alert-warning">Tidak ada posting.</div></div>
            <?php else:?>
            <ul class="list-group">
              <?php
                include (APPPATH.'third_party/simple_html_dom.php');
                $dom = new simple_html_dom();
                foreach ($results as $result) {
                $dom->load($result->bp_deskripsi);
                if ($image = $dom->find('img', 0)) {
                    $thumbnail = $image->src;
                } else {
                    $thumbnail = '';
                }
                $dom->clear();
              ?>
              <li class="list-group-item">                
                <div class="media">
                  <?php if ($thumbnail):?>
                  <div class="media-left">
                    <a href="<?php echo site_url('blog/'.$result->bp_slug);?>"><img class="media-object" src="<?php echo $thumbnail;?>" alt="<?php echo html_escape($result->bp_judul);?>" width="64" height="64" style="width: 64px;height: 64px;"/></a>
                  </div>
                  <?php endif;?>
                  <div class="media-body">
                    <a href="<?php echo site_url('blog/'.$result->bp_slug);?>"><h4 class="media-heading"><?php echo in_array($result->bp_id, $this->blog_model->get_set('pinned_posts')) ? '<i class="fa fa-thumb-tack"></i> ' : '';?><?php echo html_escape($result->bp_judul);?></h4></a>
                    <p><?php echo substr(trim(strip_tags($result->bp_deskripsi)), 0, 500);?></p>
                    <ul class="nav nav-pills">
                      <!--<li role="presentation"><a href="<?php echo site_url('admin/users/profil/'.$result->us_id);?>" style="padding: 5px 10px"><i class="fa fa-user-o"></i> <?php echo html_escape($result->us_name);?></a></li>-->
                      <li role="presentation"><span style="padding: 5px 10px"><i class="fa fa-calendar-o"></i> <?php echo format_tanggal($result->bp_tanggal);?></span></li>
                      <li role="presentation"><span style="padding: 5px 10px"><i class="fa fa-tags"></i> <?php echo strip_tags(implode(', ', get_post_category($result->bp_kategori)));?></span></li>
                      <li role="presentation"><span style="padding: 5px 10px"><i class="fa fa-eye"></i> <?php echo $result->bp_total_views;?></span></li>
                      <li role="presentation"><a href="<?php echo site_url('admin/modules/blog/komentar/'.$result->bp_id.'/0/1');?>" style="padding: 5px 10px"><i class="fa fa-comments"></i> <?php echo $result->bp_total_comments;?></a></li>
                      <?php if (in_array($result->bp_id, $this->blog_model->get_set('pinned_posts'))):?>
                      <li role="presentation"><a href="<?php echo site_url('admin/modules/blog/unpinned_post/'.$result->bp_id);?>" style="padding: 5px 10px"><i class="fa fa-thumb-tack"></i> Lepas Sematan</a></li>
                      <?php else:?>
                      <li role="presentation"><a href="<?php echo site_url('admin/modules/blog/pinned_post/'.$result->bp_id);?>" style="padding: 5px 10px"><i class="fa fa-thumb-tack"></i> Sematkan</a></li>
                      <?php endif;?>
                      <li role="presentation"><a href="<?php echo site_url('admin/modules/blog/edit-posting/'.$result->bp_id);?>" style="padding: 5px 10px"><i class="fa fa-edit"></i> Edit</a></li>
                      <li role="presentation"><a data-toggle="modal" data-target="#myModal" href="<?php echo site_url('admin/modules/blog/hapus-posting/'.$result->bp_id);?>" style="padding: 5px 10px"><span class="text-danger"><i class="fa fa-times"></i> Hapus</span></a></li>
                    </ul>
                  </div>
                </div>                  
              </li>
              <?php } ?>
            </ul>
            <?php
            $pagination = pagination(site_url('admin/modules/blog/index/'.($kategori ? $kategori['bk_id'] : '0')),$start,$total,$this->system->set['list_per_page'],'/%d'.($search ? '?search='.urlencode($search) : ''));
            if ($pagination) {
              echo '<div class="panel-body">'.$pagination.'</div>';
            }
            ?>
            <?php endif;?>
          </div>
        </div>
      </div>
    </div>
    <?php include_once(VIEWPATH.'includes/foot.php'); ?>
  </body>
</html>