<?php
		$home_url = Mage::helper('core/url')->getHomeUrl();
		//$post_title_slug = $this->getRequest()->getParam('p');
		$currentUrl = Mage::helper('core/url')->getCurrentUrl();
		$post_title_slug = substr( $currentUrl, strrpos( $currentUrl, '/' )+1 );
		$post_id = Mage::getModel('blogmate/blog')->getBlogIdBySlug($post_title_slug);
		?>

		<div class="comments-wrapper">
			
				<h2>
					<?php echo $this->__('Comments') ?>
				</h2>
                <ul class="commentlist">
			
		<?php

			$processor = Mage::getModel('core/email_template_filter');
			$category_post_collection = $this->getCollection();
			$home_url = Mage::helper('core/url')->getHomeUrl();
			$comment_count = 0;
			// echo $this->getPagerHtml();
			foreach ($category_post_collection as $post_key => $post_value) {
				++$comment_count;
				//$blog_url = $home_url.'blog/view/post/p/'.$post_value['title_slug'].'/';
				$urlKey = $post_value['title_slug'];
				    $curl = Mage::getUrl('blog/view/post/p/'.$urlKey, array('_direct' => $urlKey)); 
				    $cnt=Mage::getModel('blogmate/blog')->chkIfExists('index/'.$urlKey,$urlKey);
				    $store_id=Mage::app()->getStore()->getId();
				    if($cnt==0 && ($urlKey !=''))
				    {	
					    $curl1=$post_value['title_slug'];
					    $rewrite = Mage::getModel('core/url_rewrite');
					    $rewrite->setStoreId($store_id)
					    ->setIdPath('index/'.$urlKey)
					    ->setRequestPath($curl1)
					    ->setTargetPath('blog/view/post/p/'.$urlKey)
					    ->setIsSystem(true)
					    ->save();

				    }
				    $blog_url =$curl; 
				?>
                              <li class="comment">
				<div id="post-29" class="comment-wrapper">
                                      <div class="comment-author vcard">
                                         <span class="author"><?php echo ucfirst($processor->filter($post_value['user_name'])) ?></span>
                                      </div> <!--comment-author vcard-->
                                      <div class="comment-meta">
                                         <time class="entry-date" datetime="<?php echo date('c', strtotime($post_value['created_at']));?>"><?php echo date('D, M d, Y h:i:s a', strtotime($post_value['created_at']));?></time>.
                                      </div> <!--comment-meta-->
				      <div class="comment-body">
				          <?php echo ucfirst($processor->filter($post_value['comment']));?>
				      </div>
					<?php /* <footer class="entry-meta">
						<?php echo ucfirst($processor->filter($post_value['user_name'])),' posted on'?>
						<time class="entry-date" datetime="<?php echo date('c', strtotime($post_value['created_at']));?>"><?php echo date('D, M d, Y h:i:s a', strtotime($post_value['created_at']));?></time>.
					</footer> */ ?>
				</div>
                              </li> <!--comment-->
				<?php
			}
			if($comment_count == 0) {
				?>
				<div id="post-29" class="post-29 post type-post status-publish format-standard hentry category-daytrips">
					<div class="entry-content">
						<?php echo Mage::helper('blogmate')->__('There are no comments under this post.') ?>
					</div>
				</div>
				<?php
			}
			?>
                        </ul> <!--commentlist-->
			</div> <!--comments-wrapper-->

			<?php
			$comment_config = Mage::getStoreConfig('blogmate/comment_setting');
			$session = Mage::getSingleton('customer/session');
			if($comment_config['login'] && !$session->isLoggedIn()){
				?>
				<h4 class="legend"><?php echo Mage::helper('blogmate')->__('Submit Comment') ?></h4>
				<label for="name"><?php echo Mage::helper('blogmate')->__('Login required to submit comment.') ?></label>
				<?php
			}
			else {
			?>
                          <div class="comments-form-wrapper clearfix">
                                <h2><?php echo Mage::helper('blogmate')->__('Leave A reply') ?></h2>
				<form action="" id="postComment" method="post" class="comment-form">
								<div class="field">
									<label for="name"><?php echo Mage::helper('blogmate')->__('Name') ?><em class="required">*</em></label>
									<input name="user_name" id="user" value="<?php echo $this->getCommentName(); ?>" title="<?php echo $this->__('Name') ?>" class="required-entry input-text" type="text" />
								</div>

								<div class="field">
									<label for="email"><?php echo Mage::helper('blogmate')->__('Email') ?><em class="required">*</em></label>
									<input name="user_email" id="email" value="<?php echo $this->getCommentEmail(); ?>" title="<?php echo $this->__('Email') ?>" class="required-entry input-text validate-email" type="text" />
								</div>
								<div class="clear"></div>
								<div class="field aw-blog-comment-area">
									<label for="comment"><?php echo Mage::helper('blogmate')->__('Comment') ?><em class="required">*</em></label>
									<textarea name="comment" id="comment" title="<?php echo Mage::helper('blogmate')->__('Comment') ?>" class="required-entry input-text" cols="50" rows="5"><?php echo $this->getCommentText(); ?></textarea>
								</div>
					<div class="button-set" style="width:96%">
						<input name="blog_id" type="hidden" value="<?php echo $post_id ?>" />
						<button class="bnt-comment" type="submit"><span><span><?php echo Mage::helper('blogmate')->__('Add Comment') ?></span></span></button>
					</div>
				</form>
                          </div> <!--comments-form-wrapper clearfix-->
				<script type="text/javascript">
					var contactForm = new VarienForm('postComment', false);
				</script>

      <?php
     	}
      ?>