<?php
$aOptions = SofaiBloggr::initOptions( false );
$latestcomments_title = ( strlen( $aOptions[ 'latestcomments_title' ] ) > 0 ) ? stripslashes( $aOptions[ 'latestcomments_title' ] ) : 'Recently Commented';
$latestcomments_numbr = ( strlen( $aOptions[ 'latestcomments_numbr' ] ) > 0 ) ? stripslashes( $aOptions[ 'latestcomments_numbr' ] ) : '1';
$readmore = ( strlen( $aOptions[ 'readmore' ] ) > 0 ) ? stripslashes( $aOptions[ 'readmore' ] ) : '...Read More';
?>

<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date, comment_approved, comment_type, comment_author_url, comment_author_email, SUBSTRING(comment_content, 1, 90) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date DESC LIMIT " . $latestcomments_numbr;
$commentos = $wpdb->get_results( $sql );
?>

<div id="coments" class="section">
<h2 class="sectionheader"><?php echo $latestcomments_title; ?></h2>
<?php
if( $commentos ) {
	echo '<ol class="comment-list">';
	foreach( $commentos as $commenty ) {
?>
	<li>
		<div class="comment-info">
			<span class="date"><?php echo date( 'M j, Y', strtotime( $commenty->comment_date ) ); ?></span> 
			by 
			<span class="user"><?php echo $commenty->comment_author; ?></span>
			<span class="gravatar">
            <?php
			$author_email = $commenty->comment_author_email;
			echo get_avatar( $author_email, '45' );
			?>
            </span>
		</div>
		<div class="comment">
			<p><?php echo $commenty->com_excerpt; ?><a href="<?php echo get_permalink( $commenty->ID ); ?>" title="On <?php echo $commenty->post_title; ?>"><?php echo $readmore; ?></a></p>
		</div>
	</li>
<?php 
	}
	echo '</ol>';
} else { 
?>
<p>No comments found!</p>
<?php 
} 
?>
</div><!-- // comments end -->
    