<?php 

/* ========================================================================== */
/* set post meta items
 * ========================================================================== */
if ( ! function_exists( 'littlejump_get_postmeta' ) ):
	function littlejump_get_postmeta() {

		$default_meta_list = get_theme_mod( 'postmeta_list', 
						   apply_filters( 'littlejump_postmeta_list_defaults', array( 'date', 'category', 'comments' ) )
						  );
		$default_meta_list = ! is_array( $default_meta_list ) ? explode( '_', $default_meta_list ) : $default_meta_list;

		$meta_list           = apply_filters( 'littlejump_post_meta_list', $default_meta_list );
		$displayed_meta_list = $meta_list;

		if ( is_customize_preview() ) {
			$all       = array_merge( $meta_list, array( 'date', 'category', 'comments', 'tags', 'author' ) );
			$meta_list = array_unique( $all );
		}

		if ( empty( $meta_list ) ) {
			return;
		}

		$meta_html = array();

		foreach ( $meta_list as $meta ) {
			$preview = ( ! in_array( $meta, $displayed_meta_list ) ) ? ' hide' : '';
			switch ( $meta ) {
				case 'date':
					$meta_html[ $meta ] = '<span class="date' . $preview . '">' . get_the_time( get_option( 'date_format' ) ) . '</span>';
					break;
				case 'author':
					$meta_html[ $meta ] = '<span class="author' . $preview . '">' . get_the_author() . '</span>';
					break;
				case 'category':
					$meta_html[ $meta ] = '<span class="category' . $preview . '">' . get_the_category_list( ', ' ) . '</span>';
					break;
				case 'comments':
					$meta_html[ $meta ] = '<span class="comments' . $preview . '"><a href="' . get_comments_link() . '">' . __( 'Comments', 'little-jump' ) . ': ' . get_comments_number() . '</a></span>';
					break;
				case 'tags':
					$meta_html[ $meta ] = '<span class="tags' . $preview . '">' . get_the_tag_list( __( 'Tags: ', 'little-jump' ), ', ' ) . '</span>';
					break;
			}
		}
		$meta_html = apply_filters( 'littlejump_post_meta_list_html', $meta_html );


		$html = '';
		foreach ( $meta_list as $meta ) {
			$html .= $meta_html[ $meta ];
		}

		$html = apply_filters( 'littlejump_post_meta_html', $html );

		echo '<aside class="meta">';
		echo $html;
		echo '</aside>';
	}
endif;
add_action( 'littlejump_after_post_title', 'littlejump_get_postmeta', 10 );


/* ========================================================================== */
/* set custom posts classes
 * ========================================================================== */
if ( ! function_exists( 'littlejump_set_post_class' ) ) :
	function littlejump_set_post_class( $classes ) {

		if ( ! is_singular() && 'post' == get_post_type() ) {
			$classes[] = 'anons';
		}

		if ( is_search() ) {
			$classes[] = 'serp';
		}
		return $classes;
	}
endif;
add_filter( 'post_class', 'littlejump_set_post_class' );

/* ========================================================================== */
/* Set Post Excerpt Read More Link
 * ========================================================================== */
if ( ! function_exists( 'littlejump_the_more_link' ) ):
	function littlejump_the_more_link() {
		?>
		<p class="more-link-box">
			<a class="more-link" href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php _e( 'Read more', 'little-jump' ); ?></a>
		</p>
		<?php
	}
endif;
add_action( 'littlejump_after_post_excerpt', 'littlejump_the_more_link' );

function littlejump_excerpt_more( $more ) {
	return ' ...';
}
add_filter('excerpt_more', 'littlejump_excerpt_more');

?>