<?php
/**
 * NavThemes Custom Functions
 *
 */
   
   function abulogics_logo(){
	   ?>
        <hgroup>
          <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
            <?php bloginfo( 'name' ); ?>
            </a></h1>
          <p class="site-description">
            <?php bloginfo( 'description' ); ?>
          </p>
        </hgroup>
        <?php 
	   
   }


   
   	/* ----------------------------------------------------------------------------------- */
	/* Post Meta 
	/* ----------------------------------------------------------------------------------- */

   
   if ( ! function_exists( 'abulogics_entry_meta_header' ) ) :
   
/**
 * Set up post entry meta.
 *
 * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
 *
 * Create your own twentytwelve_entry_meta() to override in a child theme.
 *
 * @since NavThemes 1.0
 */
function abulogics_entry_meta_header() {
	

	$date = sprintf( '<span class="date"><i class="fa fa-clock-o"></i><a href="%1$s" title="%2$s" rel="bookmark"><time itemprop="datePublished" datetime="%3$s">%4$s</time></a></span>',
		esc_url( get_permalink() ),
		esc_attr( get_the_time() ),
		esc_attr( get_the_date( 'c' ) ),
		esc_html( get_the_date() )
	);

	$author = sprintf( '<span itemprop="author"><i class="fa fa-user"></i><span class="author"><a href="%1$s" title="%2$s" rel="">%3$s</a></span></span>',
		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
		esc_attr( sprintf( __( 'View all posts by %s', 'abulogics' ), get_the_author() ) ),
		get_the_author()
	);
	
	$comment_number = get_comments_number();
	$comment_number = sprintf( _n( '1 Comment', '%s Comments', $comment_number, 'abulogics' ), $comment_number );
	$comment_number =  sprintf( ' <span class="comments" itemprop="interactionCount"> <i class="fa fa-comment"></i><a href="%1$s" title="%2$s" rel="comments">%2$s</a></span>',
		get_comments_link(),
		$comment_number
	);


  
 	
	$utility_text = __( ' %1$s %3$s %4$s %5$s %2$s ', 'abulogics' );	

		echo $date ;
		echo $author ;
		echo $comment_number ;
}

endif;


   if ( ! function_exists( 'abulogics_entry_meta_footer' ) ) :
   
/**
 * Set up post entry meta.
 *
 * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
 *
 * Create your own twentytwelve_entry_meta() to override in a child theme.
 *
 * @since NavThemes 1.0
 */
function abulogics_entry_meta_footer() {
	
	// Translators: used between list items, there is a space after the comma.
	$categories_list = '<span class="category" itemprop="articleSection"><i class="fa fa-bookmark"></i>'. get_the_category_list( __( ', ', 'abulogics' ) ) . "</span>";
	
	
	// Translators: used between list items, there is a space after the comma.
	$tag_list = '<span class="tags"> <i class="fa fa-tags"></i>'. get_the_tag_list( '', __( ', ', 'abulogics' ) ). '</span>';

		echo $categories_list ;
		echo $tag_list ;
}
endif;




/* ----------------------------------------------------------------------------------- */
/*	 Comment  
/* ----------------------------------------------------------------------------------- */

 
 
 if ( ! function_exists( 'abulogics_comment' ) ) :
/**
 * Template for comments and pingbacks.
 *
 * Used as a callback by wp_list_comments() for displaying the comments.
 *
 */
function abulogics_comment( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment;
	switch ( $comment->comment_type ) :
		case 'pingback' :
		case 'trackback' :
		// Display trackbacks differently than normal comments.
	?>
	<li <?php comment_class(); ?> id="comment-<?php echo comment_ID(); ?>">
		<p><?php _e( 'Pingback:', 'abulogics' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'abulogics' ), '<span class="edit-link">', '</span>' ); ?></p>
        </li>
	<?php
			break;
		default :
		// Proceed with normal comments.
		global $post;
	?>
     
     <li class="comment_block" id="comment-<?php comment_ID(); ?>">
     
         <div class="col-md-10 col-sm-10">
            <div class=" col-md-2 col-sm-2"><?php echo get_avatar( $comment, 44 ); ?></div>
            <div class="col-md-10 col-sm-10 no-padding">
                <h3><?php printf( '<cite><b class="fn">%1$s</b> %2$s</cite>',
                            get_comment_author_link(),
                            // If current post author is also comment author, make it known visually.
                            ( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'abulogics' ) . '</span>' : ''
                        ); ?>
             </h3>
            <span><?php
                        printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
                            esc_url( get_comment_link( $comment->comment_ID ) ),
                            get_comment_time( 'c' ),
                            /* translators: 1: date, 2: time */
                            sprintf( __( '%1$s at %2$s', 'abulogics' ), get_comment_date(), get_comment_time() )
                        );
                    ?></span>
                    
            <?php if ( '0' == $comment->comment_approved ) : ?>
                    <i class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'abulogics' ); ?></i>
                <?php endif; ?>
            
            <p> 		<?php comment_text(); ?>
                    <?php edit_comment_link( __( 'Edit', 'abulogics' ), '<p class="edit-link">', '</p>' ); ?>  
             </p>
            </div>
        </div>
        <div class="col-md-2 col-sm-2"><?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'abulogics' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?></div>
      <div class="clearfix"></div>
          
          </li>                 
                                 
	<?php
		break;
	endswitch; // end comment_type check
}
endif;
 

 	
   	/* ----------------------------------------------------------------------------------- */
	/* Search Pagination
	/* ----------------------------------------------------------------------------------- */

	function abulogics_number_post_nav() { 

			if( is_singular() )
				return;
		
			global $wp_query;
		
			/** Stop execution if there's only 1 page */
			if( $wp_query->max_num_pages <= 1 )
				return;
		
			$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
			$max   = intval( $wp_query->max_num_pages );
		
			/**	Add current page to the array */
			if ( $paged >= 1 )
				$links[] = $paged;
		
			/**	Add the pages around the current page to the array */
			if ( $paged >= 3 ) {
				$links[] = $paged - 1;
				$links[] = $paged - 2;
			}
		
			if ( ( $paged + 2 ) <= $max ) {
				$links[] = $paged + 2;
				$links[] = $paged + 1;
			}
		
			echo '<div class="navigation"><ul>' . "\n";
		
			/**	Previous Post Link */
			if ( get_previous_posts_link() )
				printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
		
			/**	Link to first page, plus ellipses if necessary */
			if ( ! in_array( 1, $links ) ) {
				$class = 1 == $paged ? ' class="active"' : '';
		
				printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
		
				if ( ! in_array( 2, $links ) )
					echo '<li>&middot;&middot;&middot;</li>';
			}
		
			/**	Link to current page, plus 2 pages in either direction if necessary */
			sort( $links );
			foreach ( (array) $links as $link ) {
				$class = $paged == $link ? ' class="active"' : '';
				printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
			}
		
			/**	Link to last page, plus ellipses if necessary */
			if ( ! in_array( $max, $links ) ) {
				if ( ! in_array( $max - 1, $links ) )
					echo '<li>&middot;&middot;&middot;</li>' . "\n";
		
				$class = $paged == $max ? ' class="active"' : '';
				printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
			}
		
			/**	Next Post Link */
			if ( get_next_posts_link() )
				printf( '<li>%s</li>' . "\n", get_next_posts_link() );
		
			echo '</ul></div>' . "\n";

		}


	// Get Words from a string
	function get_words($content,$word_count=10,$suffix=''){
		$pieces = explode(" ", $content);
		echo $first_part = implode(" ", array_splice($pieces, 0, $word_count)) . $suffix ;
		
	}

 

   	/* ----------------------------------------------------------------------------------- */
	/* Post Thumbnail
	/* ----------------------------------------------------------------------------------- */

	
	if ( ! function_exists( 'abulogics_post_thumbnail' ) ) :
	/**
	 * Display an optional post thumbnail.
	 *
	 * Wraps the post thumbnail in an anchor element on index views, or a div
	 * element when on single views.
	 *
	 */
	function abulogics_post_thumbnail($image=null) {
	
		if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
			return;
		}
		
		if ( is_singular() && $image == null) :
	
		?>
		<div class="post-thumbnail">
			<?php the_post_thumbnail( 'large'); ?>
		</div><!-- .post-thumbnail -->
    	
	  <?php elseif ($image != null) : ?>
        	
		<a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
			<?php
				the_post_thumbnail( $image , array( 'alt' => get_the_title() ) );
			?>
		</a>
  	
     <?php else : ?>
	
		<a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
			<?php
				the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) );
			?>
		</a>
	
	<?php
    	endif;
	 
	}
	endif;
	 
 
 
 // MENU
 function abulogics_nav_description( $item_output, $item, $depth, $args ) {

$item_output = str_replace( '>' . $args->link_before . $item->title, ' itemprop="url" >' . $args->link_before. '<span itemprop="name">' . $item->title . '</span>', $item_output );
	
	return $item_output;
}

add_filter( 'walker_nav_menu_start_el', 'abulogics_nav_description', 10, 4 );
