<?php 
defined('C5_EXECUTE') or die("Access Denied.");
$textHelper = Loader::helper("text");
$imgHelper = Loader::Helper('image');
?>
<div id="blog-index">
	<?php  
	$isFirst = true; //So first item in list can have a different css class (e.g. no top border)
	$excerptBlocks = ($controller->truncateSummaries ? 1 : null); //1 is the number of blocks to include in the excerpt
	$truncateChars = ($controller->truncateSummaries ? $controller->truncateChars : 0);
	foreach ($cArray as $cobj):
		$title = $cobj->getCollectionName();
		$date = $cobj->getCollectionDatePublic(DATE_APP_GENERIC_MDY_FULL);
		$author = $cobj->getVersionObject()->getVersionAuthorUserName();
		$link = $nh->getLinkToCollection($cobj);
		$firstClass = $isFirst ? 'first-entry' : '';
		$img = $cobj->getAttribute('feature_image');
		$thumb = $imgHelper->getThumbnail($img, 720, 250, true);
		
		$entryController = Loader::controller($cobj);
		if(method_exists($entryController,'getCommentCountString')) {
			$comments = $entryController->getCommentCountString('%s '.t('Comment'), '%s '.t('Comments'));
		}
		$isFirst = false;
	?>
	<div class="entry <?php  echo $firstClass; ?>">
		<div class="title">
        	<?php if ($img) { ?>
            <a href="<?php  echo $link; ?>" title="<?php echo $title?>">
            <img class="ccm-output-thumbnail" src="<?php echo $thumb->src; ?>" width="<?php echo $thumb->width; ?>" height="<?php echo $thumb->height; ?>" alt="<?php echo $title?>" />
            </a>
            <?php } ?>
            <h3 class="post-title">
                <a href="<?php  echo $link; ?>"><?php  echo $title; ?></a>
            </h3>
            <small class="meta">
                <span><i class="icon-user"></i> <?php  echo $author; ?></span> <span class="ccm-autonav-breadcrumb-sep">||</span> <span><i class="icon-calendar"></i> <?php  echo $date; ?></span>
            </small>
		</div>
		<div class="excerpt">
			<?php 
			$a = new Area('Main');
			$a->disableControls();
			$a->display($cobj);
			?>
		</div>
		<div class="ccm-spacer"></div>
		<div class="meta">
			<?php if ($comments) { ?><span><i class="icon-comment"></i> <?php  echo $comments; ?></span> <?php } ?><a href="<?php  echo $link; ?>"><?php  echo t('Read full post'); ?> &raquo;</a>
		</div>
	</div>
	<hr class="blog-entry-divider"/>
	<?php  endforeach; ?>
</div>

<div class="blog-index-foot">
	<?php  if(!$previewMode && $controller->rss):
		$btID = $b->getBlockTypeID();
		$bt = BlockType::getByID($btID);
		$uh = Loader::helper('concrete/urls');
		$rssUrl = $controller->getRssUrl($b, 'blog_rss');
		$rssIcon = $uh->getBlockTypeAssetsURL($bt, 'rss.png');
		$rssTitle = $controller->rssTitle;
	?>
		<div id="rss">
			<a href="<?php  echo $rssUrl; ?>" target="_blank"><?php  echo t('Subscribe to RSS Feed')?></a>
			<a href="<?php  echo $rssUrl; ?>" target="_blank"><img src="<?php  echo $rssIcon; ?>" width="14" height="14" alt="<?php  echo t('RSS Icon')?>" title="<?php  echo t('RSS Feed')?>" /></a>
		</div>
		<link href="<?php  echo BASE_URL.$rssUrl; ?>" rel="alternate" type="application/rss+xml" title="<?php  echo $rssTitle; ?>" />
	<?php  endif; ?>
	

	<?php  if ($paginate && $num > 0 && is_object($pl)): ?>
		<div id="pagination">
			<?php 
			$summary = $pl->getSummary();
			if ($summary->pages > 1):
				$paginator = $pl->getPagination();
			?>
				<span class="pagination-left">&laquo; <?php  echo $paginator->getPrevious('Newer Posts'); ?></span>
				<span class="pagination-right"><?php  echo $paginator->getNext('Older Posts'); ?> &raquo;</span>
				<?php  echo $paginator->getPages(); ?>
			<?php  endif; ?>
		</div>
	<?php  endif; ?>
</div>