<?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 post list item template
 *
 * @var $block \Magefan\Blog\Block\Post\AbstractPost
 */
?>
<?php
    $_helper = $this->helper('Codazon\ThemeLayoutPro\Helper\Data');
    $_post = $this->getPost();
    $_postUrl = $_post->getPostUrl();
    $_postName = $block->escapeHtml($_post->getTitle(), null, true);
    $width = $_helper->getConfig('images/blog/blog_thumbnail_image_width') ? :200;
    $height = $_helper->getConfig('images/blog/blog_thumbnail_image_height') ? :200;
    $paddingBottom = $height*100/$width;
    $imgHelper = $this->helper('Codazon\ThemeLayoutPro\Helper\Image');
    $dateFormat = $_helper->getConfig('pages/blog/date_format')?:'Y-m-d';
    $infoBlock = $this->getInfoBlock();
    $_author = $_post->getAuthor();
?>
<li class="post-holder post-holder-<?php echo $_post->getId() ?>">
    <div class="post-inner row">
        <div class="col-sm-9">
            <?php
            $_postFeatured = $_post->getData('featured_img');
            $_postImage = '';
            if ($_postFeatured) {
                $_postImage = (string)$imgHelper->init($_postFeatured)->setBaseDir('blog/cache/')->keepFrame(false)->resize($width, null);
            }
            ?>
            <?php if ($featuredImage = $_post->getFeaturedImage()) : ?>
            <div class="post-ftimg-hld">
                <a class="post-img abs-img" style="padding-bottom: <?php echo $paddingBottom ?>%" href="<?php echo $_postUrl ?>" title="<?php echo $_postName ?>">
                    <img src="<?php echo $_postImage ?>" alt="<?php echo $_postName ?>" />
                </a>
            </div>
            <?php endif ?>
        </div>
        <div class="col-sm-15">
			<div class="post-info-panel">
				<div class="post-header">
					<div class="post-title-holder clearfix">
					   
						<div class="post-date"><?= $_post->getPublishDate($dateFormat) ?></div>
						<h3 class="post-title">
							<a class="post-item-link"
							   href="<?php echo $_postUrl ?>">
								<?php echo $_postName; ?>
							</a>
						</h3>
					</div>
				</div>
				
				<div class="post-info">
                    <?php if ($_author) : ?>
					<div class="item post-author">
						<span class="label"><?php echo __('Posted by:') ?></span>
						<a title="<?php echo $infoBlock->escapeHtml($_author->getTitle()) ?>"
							<?php echo ($infoBlock->authorPageEnabled())?'href="'.$_author->getAuthorUrl().'"' : ''; ?>>
							<span><?= $_author->getTitle() ?></span>
						</a>
					</div>
                    <?php endif ?>
					<?php if ($_categoriesCount = $_post->getCategoriesCount()) : ?>
					<div class="item post-categories">
						<span class="label"><?php echo __('Categories:') ?></span>
						<?php $n = 0; foreach($_post->getParentCategories() as $ct) : $n++; ?>
							<a title="<?php echo $block->escapeHtml($ct->getTitle()) ?>" href="<?php echo $ct->getCategoryUrl() ?>">
								<?php echo $block->escapeHtml($ct->getTitle()) ?>
							</a>
							<?php if ($n != $_categoriesCount) : ?>, <?php endif ?>
						<?php endforeach ?>
					</div>
					<?php endif ?>
					<?php if ($_tagsCount = $_post->getTagsCount()) : ?>
					<div class="item post-tags">
						<span class="label"><?php echo __('Tags:') ?></span>
						<?php $n = 0; foreach($_post->getRelatedTags() as $tag) : $n++; ?>
							<a class="post-tag" title="<?php echo $block->escapeHtml($tag->getTitle()) ?>" href="<?php echo $tag->getTagUrl() ?>">
								<?php echo $block->escapeHtml($tag->getTitle()) ?>
							</a>
							<?php if ($n != $_tagsCount) : ?>, <?php endif ?>
						<?php endforeach ?>
					</div>
					<?php endif ?>
				</div>
				
				<div class="post-content">
					<div class="post-description clearfix">
						<div class="post-text-hld clearfix">
							<?php echo $block->getShorContent() ?>
						</div>
					   
					</div>
				</div>
				<div class="post-footer">
					 <a class="post-read-more" href="<?php echo $_postUrl ?>" title="<?php echo $_postName ?>"><?php echo __('Read more &#187;') ?></a>
					 <div class="addthis_toolbox addthis_default_style"
						addthis:url="<?php echo $_postUrl ?>"
						addthis:title="<?php echo $_postName; ?>"
						<?php if ($firstImage = $_post->getFirstImage()) { ?>
						addthis:media="<?php echo $firstImage ?>"
						<?php } ?>>
						<a class="addthis_button_facebook"></a>
						<a class="addthis_button_twitter"></a>
						<a class="addthis_button_email"></a>
						<a class="addthis_button_compact"></a>
					</div>
				</div>
			</div>
        </div>
    </div>
</li>