<?php
/**
 * Custom template tags
 */

/*-----------------------------------------------------------------------------------*/
/*	Layout Classes
/*-----------------------------------------------------------------------------------*/
if ( ! function_exists( 'bloomy_layout_class' ) ) :
	function bloomy_layout_class() {
		
		$bloomy_class = '';
		
		if( is_home() || is_front_page() || is_search() ) {
            $bloomy_class = bloomy_theme_mod('main_layout');
		}
		elseif( is_archive() || is_author() ) {
            $bloomy_class = bloomy_theme_mod('archive_layout');
		}
		elseif( is_single() || is_page() ) {
            $bloomy_class = bloomy_theme_mod('single_layout');
		}
		
		echo esc_attr( $bloomy_class );
	}
endif;

/*-----------------------------------------------------------------------------------*/
/*	Add Span tag Around Categories and Archives Post Count
/*-----------------------------------------------------------------------------------*/
if(!function_exists('bloomy_cat_count')){ 
	function bloomy_cat_count($links) {
		return str_replace(array('</a> (',')'), array('<span class="cat-count">',' </span></a>'), $links);
	}
}
add_filter('wp_list_categories', 'bloomy_cat_count');

if(!function_exists('bloomy_archive_count')){ 
	function bloomy_archive_count($links) {
	  	return str_replace(array('</a>&nbsp;(',')'), array('<span class="cat-count">',' </span></a>'), $links);
	}
}
add_filter('get_archives_link', 'bloomy_archive_count');

/*-----------------------------------------------------------------------------------*/
/*	Modify <!--more--> Tag in Posts
/*-----------------------------------------------------------------------------------*/
// Prevent Page Scroll When Clicking the More Link
function remove_more_link_scroll( $link ) {
	$link = preg_replace( '|#more-[0-9]+|', '', $link );
	return $link;
}
add_filter( 'the_content_more_link', 'remove_more_link_scroll' );

/*-----------------------------------------------------------------------------------*/
/*	Custom Logo
/*-----------------------------------------------------------------------------------*/
/**
 * Displays the optional custom logo.
 *
 * Does nothing if the custom logo is not available.
 *
 */
function bloomy_custom_logo() {
    if ( has_custom_logo() ) {
        the_custom_logo();
    }
    else { ?>
        <?php if( is_front_page() || is_home() || is_404() ) { ?>
            <h1 id="logo" class="logo" itemprop="headline">
                <a href="<?php echo esc_url(home_url( '/' )); ?>"><?php bloginfo( 'name' ); ?></a>
            </h1>
        <?php } else { ?>
            <h2 id="logo" class="logo" itemprop="headline">
                <a href="<?php echo esc_url(home_url( '/' )); ?>"><?php bloginfo( 'name' ); ?></a>
            </h2>
        <?php } ?>
        <?php if ( bloomy_theme_mod( 'tagline' ) == 'show' ) { ?>
        <p class="site-description" itemprop="description">
            <?php bloginfo( 'description' ); ?>
        </p>
        <?php }
    }
}

/*-----------------------------------------------------------------------------------*/
/*	Pagination
/*-----------------------------------------------------------------------------------*/
if ( ! function_exists( 'bloomy_paging_nav' ) ) :
/**
 * Display navigation to next/previous set of posts when applicable.
 *
 */
function bloomy_paging_nav() {
	if ( bloomy_theme_mod( 'pagination_type' ) == 'num') :
		if ( is_rtl() ) {
            the_posts_pagination( array(
                'mid_size'  => 1,
                'prev_text' => '&rarr; ' . esc_html__( 'Previous', 'bloomy' ),
                'next_text' => esc_html__( 'Next', 'bloomy' ).' &larr;',
            ) );
        } else {
            the_posts_pagination( array(
                'mid_size'  => 1,
                'prev_text' => '&larr; ' . esc_html__( 'Previous', 'bloomy' ),
                'next_text' => esc_html__( 'Next', 'bloomy' ).' &rarr;',
            ) );
        }
	else:
	?>
		<nav class="norm-pagination clearfix" role="navigation">
            <div class="nav-previous"><?php next_posts_link( '&#10094; ' . esc_html__( 'Older Entries', 'bloomy' ) ); ?></div>
            <div class="nav-next"><?php previous_posts_link( esc_html__( 'Newer Entries', 'bloomy' ).' &#10095;' ); ?></div>
		</nav>
	<?php
	endif;
}
endif;
