<?php foreach ($this->blog_model->get_set('widgets') as $widget):?>
<?php if ($widget[0] == 'search_form'):?>
<div class="sidebar-module">
  <div class="form-group is-empty">
    <form method="get" action="<?php echo site_url('blog');?>">
      <div class="input-group">
        <input type="text" class="form-control" name="search" value="<?php echo html_escape($search);?>" placeholder="<?php echo html_escape($widget[1][0]);?>" />
        <span class="input-group-btn"><button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button></span>
      </div>
    </form>
  </div>
</div>
<?php
elseif ($widget[0] == 'recent_posts' && ($recent_posts = $this->blog_model->get_recent_posts($num = $widget[1][1]))):
if (!class_exists('simple_html_dom')) {
  include_once (APPPATH.'third_party/simple_html_dom.php');
}
$dom = new simple_html_dom();
?>
<div class="sidebar-module">
  <div class="panel panel-default">
    <div class="panel-body">
      <h4><?php echo html_escape($widget[1][0]);?></h4>
      <?php
      foreach ($recent_posts as $recent_post):
      $dom->load($recent_post['bp_deskripsi']);
      if ($image = $dom->find('img', 0)) {
         $media_left = '<div class="media-left"><a href="'.site_url('blog/'.$recent_post['bp_slug']).'"><img class="media-object" data-src="'.$image->src.'" alt="'.html_escape($recent_post['bp_judul']).'" style="width:40px !important;height:40px !important;"/></a></div>';
      } else {
         $media_left = '<div class="media-left" style="font-size: 40px;"><a href="'.site_url('blog/'.$recent_post['bp_slug']).'"><i class="fa fa-sticky-note-o"></i></a></div>';
      }
      $dom->clear();
      ?>
      <div class="media">
        <?php echo $media_left;?>
        <div class="media-body">
          <a  href="<?php echo site_url('blog/'.$recent_post['bp_slug']);?>" title="<?php echo html_escape($recent_post['bp_judul']);?>"><h5 style="margin-bottom: 5px;"><?php echo html_escape($recent_post['bp_judul']);?></h5></a>
          <span class="text-muted"><?php echo format_tanggal($recent_post['bp_tanggal']);?></span>
        </div>
      </div>
      <?php endforeach;?>
    </div>
  </div>
</div>
<?php
elseif ($widget[0] == 'pinned_posts' && ($pinned_posts = $this->blog_model->get_pinned_posts($num = 5))):
if (!class_exists('simple_html_dom')) {
  include_once (APPPATH.'third_party/simple_html_dom.php');
}
$dom = new simple_html_dom();
?>
<div class="sidebar-module">
  <div class="panel panel-default">
    <div class="panel-body">
      <h4><?php echo html_escape($widget[1][0]);?></h4>
      <?php
      $pinned_posts2 = array();
      foreach ($pinned_posts as $_pinned_post) {
        $pinned_posts2[$_pinned_post['bp_id']] = $_pinned_post;
      }
      foreach ($this->blog_model->get_set('pinned_posts') as $pinned_id):
      if (!isset($pinned_posts2[$pinned_id]))
        continue;
      $pinned_post = $pinned_posts2[$pinned_id];
      $dom->load($pinned_post['bp_deskripsi']);
      if ($image = $dom->find('img', 0)) {
         $media_left = '<div class="media-left"><a href="'.site_url('blog/'.$pinned_post['bp_slug']).'"><img class="media-object" data-src="'.$image->src.'" alt="'.html_escape($pinned_post['bp_judul']).'" style="width:40px !important;height:40px !important;"/></a></div>';
      } else {
         $media_left = '<div class="media-left" style="font-size: 40px;"><a href="'.site_url('blog/'.$pinned_post['bp_slug']).'"><i class="fa fa-sticky-note-o"></i></a></div>';
      }
      $dom->clear();
      ?>
      <div class="media">
        <?php echo $media_left;?>
        <div class="media-body">
          <a  href="<?php echo site_url('blog/'.$pinned_post['bp_slug']);?>" title="<?php echo html_escape($pinned_post['bp_judul']);?>"><h5 style="margin-bottom: 5px;"><?php echo html_escape($pinned_post['bp_judul']);?></h5></a>
          <span class="text-muted"><?php echo format_tanggal($pinned_post['bp_tanggal']);?></span>
        </div>
      </div>
      <?php endforeach;?>
    </div>
  </div>
</div>
<?php elseif ($widget[0] == 'recent_comments' && ($recent_comments = $this->blog_model->get_recent_comments($widget[1][1]))):?>
<div class="sidebar-module">
  <div class="panel panel-default">
    <div class="panel-body">
      <h4 style="margin: 0;"><?php echo html_escape($widget[1][0]);?></h4>
    </div>
    <ul class="list-group">
      <?php foreach ($recent_comments as $recent_comment):?>
      <div class="list-group-item">
        <a href="<?php echo site_url('blog/'.$recent_comment['bp_slug']);?>" title="<?php echo html_escape($recent_comment['bp_judul']);?>"><i class="fa fa-<?php echo ($recent_comment['us_id'] ? 'user' : 'user-secret');?>"></i> <?php echo html_escape($recent_comment['bc_nama']);?></a>
        <span class="text-muted">(<?php echo format_tanggal($recent_comment['bc_tanggal']);?>)</span>: <?php echo substr(html_escape($recent_comment['bc_komentar']),0,150);?>...
      </div>
      <?php endforeach;?>
    </ul>
  </div>
</div>
<?php elseif ($widget[0] == 'categories'):?>
<div class="sidebar-module">
  <div class="panel panel-default">
    <div class="panel-body">
      <h4><?php echo html_escape($widget[1][0]);?></h4>
      <ol class="categories list-unstyled">
        <?php foreach ($this->blog_model->get_categories() as $cat):?>
        <li><a class="label label-light label-primary" href="<?php echo site_url('blog/kategori/'.$cat->bk_slug);?>"><?php echo html_escape($cat->bk_nama);?></a><span class="label label-light label-default pull-right"><?php echo $cat->bk_posting;?></span></li>
        <?php endforeach;?>
        <li><a class="label label-light label-warning" href="<?php echo site_url('blog/kategori/tak-berkategori');?>">Tak Berkategori</a><span class="label label-light label-default pull-right"><?php echo $this->blog_model->get_total_uncategories();?></span></li>
      </ol>
    </div>
  </div>
</div>
<?php elseif ($widget[0] == 'html' && file_exists(VIEWPATH.'blog/'.$widget[1][1].'.html')):?>
<div class="sidebar-module">
  <div class="panel panel-default">
    <div class="panel-body">
      <h4><?php echo html_escape($widget[1][0]);?></h4>
      <p><?php echo file_get_contents(VIEWPATH.'blog/'.$widget[1][1].'.html');?></p>
    </div>
  </div>
</div>
<?php endif;?>
<?php endforeach;?>