<?php
/**
 * Copyright © 2015 Ihor Vansach (ihor@magefan.com). All rights reserved.
 * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
 *
 * Glory to Ukraine! Glory to the heroes!
 */
?>
<?php
/**
 * Blog sidebar recent posts template
 *
 * @var $block \Magefan\Blog\Block\Sidebar\Recent
 */
?>

<?php
	$_postCollection = $block->getPostCollection();
?>
<div class="recent-posts">
<?php if ($_postCollection->count()) { ?>
    <div class="owl-carousel" id="blog-carousel">
    <?php foreach ($_postCollection as $_post) { ?>
    <?php
        $post_date = $_post->getData("publish_time");
    ?>
        <div class="item">
            <div class="row">
                <div class="col-md-5">
                    <div class="post-image">
                    <?php if($post_image = $_post->getFeaturedImage()): ?>
                        <img src="<?php echo $post_image; ?>" alt=""/>
                    <?php endif; ?>
                    </div>
                </div>
                <div class="col-md-7">
                    <div class="post-date">
                        <span class="day"><?php echo date("j", strtotime($post_date)); ?></span>
                        <span class="month"><?php echo date("M", strtotime($post_date)); ?></span>
                    </div>
                    <div class="postTitle">
                        <h2><a href="<?php echo $_post->getPostUrl() ?>" ><?php echo $block->escapeHtml($_post->getTitle()) ?></a></h2>
                    </div>
                    <?php
                        $content = $_post->getContent();
                        $pageBraker = '<!-- pagebreak -->';
                        
                        $isMb = function_exists('mb_strpos');
                        $p = $isMb ? strpos($content, $pageBraker) : mb_strpos($content, $pageBraker);

                        if ($p) {
                            $content = substr($content, 0, $p);
                        }

                        $short_content = $this->helper('Smartwave\Porto\Helper\Data')->filterContent($content);
/*                    ?>
                    <div class="postContent"><?php echo $short_content; ?></div>
                    <a class="readmore" href="<?php echo $_post->getPostUrl(); ?>"><?php echo __("Read more >");?></a>
*/ ?>                </div>
            </div>
        </div>
    <?php } ?>
    </div>
<?php } ?>
</div>
<script type="text/javascript">
  require([
    'jquery',
    'owl.carousel/owl.carousel.min'
  ], function ($) {
    var blog_owl = $("#blog-carousel");
    blog_owl.owlCarousel({
      autoplay: true,
      autoplayTimeout: 5000,
      autoplayHoverPause: true,
      nav: true,
      navRewind: true,
      loop: true,
      lazyLoad: true,
      margin: 10,
      dots: false,
      navText: ["<em class='porto-icon-left-open-huge'></em>","<em class='porto-icon-right-open-huge'></em>"],
      responsive: {
            0: {
                items:1
            },
            768: {
                items:1
            },
            992: {
                items:2
            },
            1200: {
                items:2
            }
        }
    });

    var banner_owl = $("#banner-slider-demo-1");
    banner_owl.owlCarousel({
      items: 1,
      autoplay: true,
      autoplayTimeout: 5000,
      autoplayHoverPause: true,
      dots: true,
      nav: false,
      navRewind: true,
      animateIn: 'fadeIn',
      animateOut: 'fadeOut',
      loop: true,
      lazyLoad: true,
      navText: ["<em class='porto-icon-chevron-left'></em>","<em class='porto-icon-chevron-right'></em>"]
    });
  });
</script>
