<?php

// Exit if accessed directly
if ( !defined('ABSPATH')) exit;

/**
 * The function hooks in displaying the theme functions.
 *
 * @package WordPress
 * @subpackage TDFramework
 * @since framework 1.0
 */

if ( ! function_exists( 'core_theme_wrap_before' ) ) {
/**
 * Theme row wrapper open
 * @since framework 1.0
 */
	function core_theme_wrap_before(){
		echo '<div class="theme-wrap">';
	} // core_theme_wrap_before()
}

if ( ! function_exists( 'core_theme_wrap_after' ) ) {
/**
 * Theme row wrapper open
 * @since framework 1.0
 */
	function core_theme_wrap_after(){
		echo '</div><!-- .theme-wrap -->';
	} // core_theme_wrap_after()
}
add_action('core_theme_hook_in_header', 'core_theme_wrap_before', 1);
add_action('core_theme_hook_in_header', 'core_theme_wrap_after', 100);
add_action('core_theme_hook_before_content', 'core_theme_wrap_before', 1);
add_action('core_theme_hook_after_content', 'core_theme_wrap_after', 100);
add_action('core_theme_hook_footer_content', 'core_theme_wrap_before', 1);
add_action('core_theme_hook_footer_content', 'core_theme_wrap_after', 100);

if ( ! function_exists( 'core_theme_wrap_after' ) ) {
/**
 * Browser Happy
 * @since framework 1.0
 */
	function core_theme_browser_happy(){

		$response = wp_check_browser_version();

		if ( $response && $response['upgrade'] ) {
			add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' );
			if ( $response['insecure'] )
				echo add_filter( 'core_theme_hook_before_container', __( 'You are using an insecure browser!', THEME_SLUG ), 'wp_dashboard_browser_nag' );
			else
				echo add_filter( 'core_theme_hook_before_container', __( 'Your browser is out of date!', THEME_SLUG ), 'wp_dashboard_browser_nag' );
		}

	} // core_theme_browser_happy()
}
//add_action('core_theme_hook_before_container', 'core_theme_browser_happy');

if ( ! function_exists( 'core_theme_favicon' ) ) {
/**
 * Theme Favicon
 * @since framework 1.0
 */
	function core_theme_favicon(){
		$favicon_uri = core_options_get('favicon');
		if ($favicon_uri)
			echo '<link rel="shortcut icon" href="' . $favicon_uri . '">';
	} // core_theme_favicon()
}
add_action('wp_head', 'core_theme_favicon', 5);


if ( ! function_exists( 'core_theme_seo' ) ) {
/**
 * Theme Favicon
 * @since framework 1.0
 */
	function core_theme_seo(){
		// SEO Basic Activation
		$seobasic = core_options_get('seobasic');
		if ( $seobasic ){
			core_seo_basic('meta');
		}
	} // core_theme_seo()
}
add_action('wp_head', 'core_theme_seo', 1);


if ( ! function_exists( 'core_theme_load_page_styles' ) ) {
/**
 * Load Page Styles
 * @since framework 1.0
 */
	function core_theme_load_page_styles(){
		get_template_part('tdframework/theme-styles');
	} // core_theme_load_page_styles()
}
add_action('wp_head', 'core_theme_load_page_styles', 100);

// Google fonts using the wp_enqueue script
// Fonts that need to be loaded through the Google Fonts API
function core_theme_font_url( $fonts = array('font_menu', 'font_heading', 'font_paragraph') ) {
	global $theme_load_fonts, $core_fonts;
	$theme_load_fonts = array();
	$prev_font = array();
	$font_url = '';
	$family = '';
	$subset = array();

	foreach($fonts as $option) {
		$font = core_options_get($option);
		array_push($theme_load_fonts, $font);
	}

	foreach ($theme_load_fonts as $font) {
		if (!in_array($font,$prev_font) && in_array($font, $core_fonts["Google fonts"])) {
			array_push( $prev_font, $font );
		}
	}

	$family = join("|", $prev_font);

	$subsets = explode(',', preg_replace('/\s+/', '', core_options_get('font_subsets') ) );

	foreach ($subsets as $set) {
		if ( in_array($set, array('latin','cyrillic-ext','greek-ext','greek','vietnamese','latin-ext','cyrillic') ) ) {
			array_push($subset, $set);
		}
	}

	if ( ! empty($subset) ) {
		$args = array( 'family' => urlencode( $family ), 'subset' => join(',', $subset) );
	} else {
		$args = array( 'family' => urlencode( $family ) );
	}

	$font_url = add_query_arg( $args, "//fonts.googleapis.com/css" );

	return $font_url;
}

function core_theme_enqueue_fonts() {
	wp_enqueue_style( 'theme-google-fonts', core_theme_font_url(), array(), null );
}
add_action( 'wp_enqueue_scripts', 'core_theme_enqueue_fonts' );

if ( ! function_exists( 'core_theme_social_search' ) ) {
/**
 * Search box
 * @since framework 1.0
 */
	function core_theme_social_search(){
		echo '<div id="theme-search-box"><a href="#"><i class="social_icons icon-search fa fa-search"></i></a>';
		get_template_part('searchform');
		echo '</div></div>';
	} // core_theme_social_icons()
}
add_action('core_theme_hook_in_header', 'core_theme_social_search', 20);

if ( ! function_exists( 'core_theme_social_icons' ) ) {
/**
 * Social Icons
 * @since framework 1.0
 */
	/*function core_theme_footer_social_icons(){
		echo '<div class="sociables">';
        if ( function_exists( 'core_sociables' ) ) {
            core_sociables('social_icons');
        }else{
            echo 'You haven\'t installed or activated the TD Sociables plugin!';   
        }
		echo '</div>';
	} // core_theme_social_icons()
    */
    
    function core_theme_social_icons(){
		echo '<div class="grid-right col-sixs fit sociables">';
        if ( function_exists( 'core_sociables' ) ) {
            core_sociables('social_icons');
        }else{
            echo 'You haven\'t installed or activated the TD Sociables plugin!';   
        }
        echo '</div>';
        //core_sociables('social_icons');
		//echo "</div>";
	} // core_theme_social_icons()
}
add_action('core_theme_hook_in_header', 'core_theme_social_icons', 15);


if ( ! function_exists( 'core_theme_logo' ) ) {
/**
 * Theme Logo
 * @since framework 1.0
 */
	function core_theme_logo(){

	?>
		<div id="theme-logo" style="text-align: <?php if (core_options_get('logo_align')) echo core_options_get('logo_align'); ?>;" class="grid col-sixs">

		<?php if(core_options_get('logo') == '') : ?>
			<hgroup>
				<h1 id="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>
				<h2 id="site-description"><?php bloginfo( 'description' ); ?></h2>
			</hgroup>
		<?php else : ?>
			<a href="<?php echo home_url(); ?>">
				<img src="<?php echo core_options_get('logo'); ?>" alt="<?php echo bloginfo('name'); ?>">
			</a>
		<?php endif; ?>
		</div><!-- ends here #theme-logo -->

	<?php
	} // core_theme_logo()
}
add_action('core_theme_hook_in_header', 'core_theme_logo', 10);


if ( ! function_exists( 'core_theme_menu_main' ) ) {
/**
 * Main Navigation Menu
 *
 * @since framework 1.0
 */
	function core_theme_menu_main(){
		echo '<nav id="site-navigation" class="theme-row clearfix">';
		core_theme_wrap_before();
		core_layout_menu('main');

		// WooCommerce cart
		if (is_woocommerce_activated()) {
			global $woocommerce;

			echo '<div class="theme-woocommerce-cart">';
			theme_woocommerce_cart();
			echo '</div>';
		}

	    core_theme_wrap_after();
	    echo '</nav><!-- ends here #theme-row -->';
	} // core_theme_menu_main()
}
add_action('core_theme_hook_before_wrapper', 'core_theme_menu_main');

if ( ! function_exists( 'core_theme_top_menu' ) ) {
/**
 * Top Navigation Menu
 *
 * @since framework 1.0
 */
	function core_theme_top_menu(){
		echo '<nav id="top-navigation">';
		core_layout_menu('topmenu');
	    echo '</nav><!-- ends here #top-navigation -->';
	} // core_theme_top_menu()
}
add_action('core_theme_hook_in_header', 'core_theme_top_menu');


if ( ! function_exists( 'core_theme_slider_area' ) ) {
/**
 * Slider Area
 *
 * @since framework 1.0
 */
	function core_theme_slider_area(){

		$post_type = get_post_type();
		$category = get_query_var('cat');
		$current_category = get_category ($category);
		$slug = '';
		$slider = 'none';

		if ( is_singular() && (is_page() || is_single()) ) {
			$post_type = $post_type;
			$slug = $slug;
		} else {
			$post_type = 'theme';
			$slug = '_layout-default';
		}

		if ( is_archive() ){
			$post_type = 'theme';

			if ( is_category() )
				$slug = '_'.$current_category->slug;

			elseif ( is_author() )
				$slug = '_layout-author';

			elseif ( is_tag() )
				$slug = '_layout-tag';

			else
				$slug = '_layout-archive';
		}

		if ( is_404() ){
			$post_type = 'theme';
			$slug = '_layout-404';
		}

		if ( is_search() ){
			$post_type = 'theme';
			$slug = '_layout-search';
		}

		if (!$post_type)
			return;

		$slider = apply_filters('slider_area', $slider);

		if( $slider == 'none' )
			$slider = core_options_get('slider'.$slug, $post_type);

		if (!$slider || $slider == 'none')
			return;

		if ( is_category() ){
			// Slider widget
			$widget_position = '';
			$widget_sidebar = '';
		} else {
			// Slider widget
			$widget_position = core_options_get('widget_position', $post_type);
			$widget_sidebar = core_options_get('widget_sidebar', $post_type);
		}


		echo '<div id="theme_slider_area" class="theme-row clearfix">';
		core_theme_wrap_before();
		// Left widget
		if ($widget_position == 'left' && $widget_sidebar) {
			?>
			<div class="grid col-four">
				<ul class="border-box" id="theme-slider-widget">
					<?php dynamic_sidebar($widget_sidebar); ?>
				</ul>
			</div>
			<div class="grid col-eight fit">
				<div class="border-box" id="theme-slider">
					<?php core_slider($slider); ?>
				</div>
			</div>
			<div class="clearfix"></div>
			<?php

		// Right widget
		} else if ($widget_position == 'right' && $widget_sidebar) {
			?>
			<div class="grid col-eight">
				<div class="border-box" id="theme-slider">
					<?php core_slider($slider); ?>
				</div>
			</div>
			<div class="grid col-four fit">
				<ul class="border-box" id="theme-slider-widget">
					<?php dynamic_sidebar($widget_sidebar); ?>
				</ul>
			</div>
			<div class="clearfix"></div>
			<?php

		// No widget
		} else {
			?>
			<div class="grid col-twelve">
				<div id="theme-slider">
					<?php core_slider($slider); ?>
				</div>
			</div>
			<div class="clearfix"></div>
			<?php
		}
		core_theme_wrap_after();
	    echo '</div><!-- ends here #theme_slider_area -->';
	} // core_theme_slider_area()
}
add_action('core_theme_hook_before_wrapper', 'core_theme_slider_area');


if ( ! function_exists( 'core_theme_custom_content' ) ) {
/**
 * Custom Content Area
 *
 * @since framework 1.0
 */
	function core_theme_custom_content(){
		$content = theme_custom_content();
		if ($content && $content != 'none') {
			echo "<div id=\"theme-custom-content\" class=\"theme-row clearfix\">\n";
			echo "<div class=\"bg\">\n";
			core_theme_wrap_before();
			echo do_shortcode($content);
			core_theme_wrap_after();
			core_theme_wrap_after();
			echo "</div><!-- ends here .theme-custom -->";
		}
	} // core_theme_custom_content()
}
add_action('core_theme_hook_before_wrapper', 'core_theme_custom_content');


if ( ! function_exists( 'core_theme_breadcrumb' ) ) {
/**
 * Breadcrumb
 *
 * @since framework 1.0
 */
	function core_theme_breadcrumb(){
		if (core_options_get('breadcrumbs') == true ) {
			echo '<div class="theme-breadcrumbs breadcrumb-list">';
			echo core_breadcrumbs(' \ ', '<i class="icon-home fa fa-home"></i> ');
			echo '</div>';
		}
	} // core_theme_breadcrumb()
}
//add_action('core_theme_hook_entry_header', 'core_theme_breadcrumb');


if ( ! function_exists( 'core_theme_entry_content' ) ) {
/**
 * Post content: entry content just after the_content()
 *
 * @since framework 1.0
 */
	function core_theme_entry_content(){

	} // core_theme_entry_content()
}


if ( ! function_exists( 'core_theme_featured_image' ) ) {
/**
 * Theme Favicon
 * @since framework 1.0
 */
	function core_theme_featured_image(){
		// Featured image
		$featured_img = (int)core_options_get('featured_img');
		if (has_post_thumbnail() && $featured_img) {
			echo '<div class="featured-image">';
			the_post_thumbnail('post-featured');
			echo '</div>';
		}
	} // core_theme_featured_image()
}
//add_action('', 'core_theme_featured_image');


if ( ! function_exists( 'core_theme_entry_footer_meta' ) ) {
/**
 * Post content: entry header
 *
 * @since framework 1.0
 */
	function core_theme_entry_footer_meta(){

	} // core_theme_entry_footer_meta()
}

if ( ! function_exists( 'core_theme_footer_widget_container' ) ) {
/**
 * Footer Widget Area
 *
 * @since framework 1.0
 */
 	function core_theme_footer_widget_container(){
 		$layout = core_layout_current();

 		if( $layout['footer']->slug != 'none' ){
 			echo '<div id="footer-widget" class="theme-row clearfix">';
		 	echo '<div id="footer-widget-area" class="widget_container">';
			do_action('core_footer');
			echo '<div class="clear"></div>';
			echo '</div>';
			echo '</div>';
 		}
 	} // core_theme_footer_widget_container()
}
add_action('core_theme_hook_after_wrapper', 'core_theme_footer_widget_container', 5);


if ( ! function_exists( 'core_theme_footer_background' ) ) {
/**
 * Footer Menu
 *
 * @since framework 1.0
 */
	function core_theme_footer_background(){
		echo '<div id="footer-background">';
		echo '</div>';
	} // core_theme_footer_background()
}
add_action('core_theme_hook_footer_after', 'core_theme_footer_background', 99);



if ( ! function_exists( 'core_theme_footer_menu' ) ) {
/**
 * Footer Menu
 *
 * @since framework 1.0
 */
	function core_theme_footer_menu($columns='twelve'){
		if( core_layout_menu('footer') ){
			echo '<nav class="grid col-'.$columns.'">';
			core_layout_menu('footer');
		    echo '</nav><!-- ends here .footer_menu -->';
		}
	} // core_theme_footer_menu()
}
add_action('core_theme_hook_footer_content', 'core_theme_footer_menu', 5);


if ( ! function_exists( 'core_theme_copyright' ) ) {
/**
 * Copyright
 *
 * @since framework 1.0
 */
	function core_theme_copyright(){
		echo '<div id="theme-copyright" class="grid col-twelve copyright">';

		$copyright_link = core_options_get('copyright_link');
		$copyright_name = core_options_get('copyright_name');
		$copyright_html = core_options_get('copyright_html');
		$copyright_year = date('Y');

		if (!$copyright_html) {
			if (!$copyright_link)
				$copyright_link = site_url();

			echo '&copy; ', $copyright_year, ' <a href="', $copyright_link, '">',$copyright_name, '</a>';
		} else
			echo $copyright_html;

	    echo '</div><!-- ends here .copyright -->';
	} // core_theme_copyright()
}
add_action('core_theme_hook_footer_content', 'core_theme_copyright');


if ( ! function_exists( 'core_theme_powered' ) ) {
/**
 * Powered by
 *
 * @since framework 1.0
 */
	function core_theme_powered(){
		echo '<div class="grid col-six fit powered">';
	    echo '        <a href="#" title="', get_bloginfo('name'),'">';
	    echo '                ', get_bloginfo('name'),'</a>';
	    echo '        ', __('powered by', THEME_SLUG),' <a href="http://wordpress.org/" title="WordPress">';
	    echo '                WordPress</a>';
	    echo '</div><!-- ends here .powered -->';
	} // core_theme_powered()
}
//add_action('core_theme_hook_footer_content', 'core_theme_powered');


if ( ! function_exists( 'core_theme_to_top' ) ) {
/**
 * Back to top link
 *
 * @since framework 1.0
 */
	function core_theme_to_top(){
		echo '<div class="scroll-top"><a href="#scroll-top" title="scroll to top"><i class="icon-caret-up fa fa-caret-up"></i></a></div>';
	} // core_theme_to_top()
}
add_action('core_theme_hook_footer_content', 'core_theme_to_top');


if ( ! function_exists( 'core_theme_google_analytics' ) ) {
/**
 * Google Analytics
 *
 * @since framework 1.0
 */
	function core_theme_google_analytics(){
		$google_analytics= '';

		// add google analytics settings
		$google_analytics = core_options_get('google_analytics');
		if ($google_analytics){
			echo '<script type="text/javascript">';
			echo strip_tags($google_analytics);
			echo '</script>';
		}
	} // core_theme_google_analytics()
}
add_action('wp_head', 'core_theme_google_analytics', 101);


if ( ! function_exists( 'core_theme_custom_js' ) ) {
/**
 * Custom Js
 *
 * @since framework 1.0
 */
	function core_theme_custom_js(){
		$custom_js = '';

		// add custom javascripts
		$custom_js = core_options_get('custom_js');
		if ($custom_js){
			echo '<script type="text/javascript">';
			echo strip_tags($custom_js) . "\n";
			echo '</script>';
		}
	} // core_theme_custom_js()
}
add_action('wp_footer', 'core_theme_custom_js', 10);

if ( ! function_exists( 'core_theme_custom_css' ) ) {
/**
 * Custom Css
 *
 * @since framework 1.0
 */
	function core_theme_custom_css(){
		$custom_css ='';

		// add custom javascripts
		$custom_css = core_options_get('custom_css');
		if ($custom_css)
			echo strip_tags($custom_css);
	} // core_theme_custom_css()
}
add_action('core_theme_hook_styles', 'core_theme_custom_css');

if ( ! function_exists( 'core_theme_customize' ) ) {
/**
 * Customize Demo Pane
 *
 * @since framework 1.0
 */
	function core_theme_customize(){
		// add demo settings
		$customize = core_options_get('customize');
		if($customize)
			core_demo_settings_enable(true);
	} // core_theme_customize()
}
add_action('core_theme_hook_after_container', 'core_theme_customize');



if ( ! function_exists( 'core_theme_loader' ) ) {
/**
 * Container Class
 *
 * @since Mikmag 2.0
 */
	function core_theme_loader() {
		$core_loader = core_options_get('core_loader');
		if ( $core_loader ) {
			echo '<div class="core-loader">';
			echo '<div class="content">';

			echo '<div class="logo">';
			$logo = core_options_get('logo');
			if($logo)
				echo '<a href="', home_url(), '"><img src="', $logo, '" alt="', get_bloginfo('title'), '" /></a>';
			else
				echo '<a href="', home_url(), '">', get_bloginfo('name'), '</a>';

			echo '</div>';

			echo '<div class="indicator">';
			echo '<img src="', CORE_URI, '/images/core-loader.gif" alt="loading" title="loading">';
			echo '</div>';

			echo '</div>';
			echo '</div>';
		}
	}
}
add_action('core_theme_hook_before_container', 'core_theme_loader');

/**
 * Ads
 *
 * @since framework 1.0
 */
function core_theme_content_ad_header() {
	if ( core_ads_get('header') )
		echo core_ads_get('header');
}
add_action('core_theme_hook_in_header', 'core_theme_content_ad_header', 5);

function core_theme_content_ad_before() {
	if ( core_ads_get('content_before') )
		echo core_ads_get('content_before');
}
add_action('core_theme_hook_before_entry_content', 'core_theme_content_ad_before');

function core_theme_content_ad_after() {
	if ( core_ads_get('content_after') )
		echo core_ads_get('content_after');
}
add_action('core_theme_hook_after_entry_content', 'core_theme_content_ad_after');


if ( ! function_exists( 'core_theme_container_class' ) ) {
/**
 * Container Class
 *
 * @since framework 1.0
 */
	function core_theme_container_class(){
		// add custom container class in the template
		$layout_style = core_options_get('layout_style');
		if($layout_style)
			echo $layout_style . ' hfeed';
		else
			echo 'hfeed';
	} // core_theme_container_class()
}
add_action('container_class', 'core_theme_container_class');


// Custom CSS for content color schemes
// TODO: Move CSS rules into customizable array, or something similar
//
function core_colorschemes_css() {
	$scheme = null;

	// Get scheme from post\page or category
	if ( is_singular() && (is_page() || is_single()) )
		$scheme = core_options_get('colorscheme', get_post_type());
	else //if(is_page() || is_single())
		$scheme = core_options_get('layout-default_colorscheme', 'theme');

	if (is_archive()){

		if (!$scheme && is_category()) {
			$obj = get_queried_object();
			$scheme = core_options_get('category_colorscheme_' .$obj->slug);
		} elseif (is_author())
			$scheme = core_options_get('layout-author_colorscheme', 'theme');

		elseif (is_tag())
			$scheme = core_options_get('layout-tag_colorscheme', 'theme');
		else
			$scheme = core_options_get('layout-archive_colorscheme', 'theme');
	}

	if (is_404())
		$scheme = core_options_get('layout-404_colorscheme', 'theme');

	if (is_search())
		$scheme = core_options_get('layout-search_colorscheme', 'theme');

	$scheme = apply_filters('color_scheme', $scheme);

	if( !$scheme)
		return;

	$schemes = core_options_get('colorschemes');

	if (!isset($schemes[$scheme]))
		return;

	$scheme = $schemes[$scheme];

	// Calculate rgba() strings
	$backgroundcolor = core_hex2rgb($scheme['color-background']);
	$backgroundcolor['alpha'] = intval($scheme['opacity-background']) / 100;

	// Outline is 60% alpha of original
	$outline = core_hex2rgb($scheme['color-background']);
	$outline['alpha'] = intval($scheme['opacity-background']) / 100 * 0.6;

	// Content block CSS
	echo '#wrapper {';
	echo 'background-color: ', core_color2rgba($backgroundcolor), ';';
	//echo 'outline-color: ', core_color2rgba($outline), ';';
	echo 'color: #', $scheme['color-paragraph'], ';';
	echo '} ';

	// Heading shortcodes
	echo 'div.shortcode-header h1,';
	echo 'div.shortcode-header h2,';
	echo 'div.shortcode-header h3,';
	echo 'div.shortcode-header h4,';
	echo 'div.shortcode-header h5,';
	echo 'div.shortcode-header h6 {';
	echo 'background-color: ', core_color2rgba($backgroundcolor), ';';
	echo '} ';

	// Anchor CSS
	//echo '.theme-content a {';
	//echo 'color: #', $scheme['color-paragraph'], ';';
	//echo '}';

	// Comment form
	echo '#commentform p,';
	echo '#commentform a {';
	echo 'color: #', $scheme['color-paragraph'], ';';
	echo '} ';

	// Headings CSS
	echo '.theme-content h1,';
	echo '.theme-content h2,';
	echo '.theme-content h3,';
	echo '.theme-content h4,';
	echo '.theme-content h5,';
	echo '.theme-content h6 {';
	echo 'color: #', $scheme['color-headings'], ';';
	echo '} ';
}
add_action('core_custom_css', 'core_colorschemes_css');


if ( ! function_exists( 'core_theme_content_nav' ) ) :
/**
 * Display navigation to next/previous pages when applicable
 *
 * @since framework 1.0
 */
function core_theme_content_nav( $nav_id ) {
	global $wp_query, $post;

	// Don't print empty markup on single pages if there's nowhere to navigate.
	if ( is_single() ) {
		$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
		$next = get_adjacent_post( false, '', false );

		if ( ! $next && ! $previous )
			return;
	}

	// Don't print empty markup in archives if there's only one page.
	if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
		return;

	$nav_class = ( is_single() ) ? 'navigation single' : 'navigation paging';

	?>
	<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
		<h1 class="screen-reader-text"><?php _e( 'Post navigation', THEME_SLUG ); ?></h1>

	<?php if ( is_single() ) : // navigation links for single posts ?>

		<?php previous_post_link( '<div class="previous">%link</div>', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', THEME_SLUG ) . '</span> %title' ); ?>
		<?php next_post_link( '<div class="next">%link</div>', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', THEME_SLUG ) . '</span>' ); ?>

	<?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>

		<?php if ( get_next_posts_link() ) : ?>
		<div class="previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', THEME_SLUG ) ); ?></div>
		<?php endif; ?>

		<?php if ( get_previous_posts_link() ) : ?>
		<div class="next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', THEME_SLUG ) ); ?></div>
		<?php endif; ?>

	<?php endif; ?>

	</nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
	<?php
} // core_theme_content_nav
endif;

if ( ! function_exists( 'core_theme_comment' ) ) :
/**
 * Template for comments and pingbacks.
 *
 * Used as a callback by wp_list_comments() for displaying the comments.
 *
 * @since framework 1.0
 */
function core_theme_comment( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment;
	switch ( $comment->comment_type ) :
		case 'pingback' :
		case 'trackback' :
	?>
	<li class="post pingback">
		<p><?php _e( 'Pingback:', THEME_SLUG ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', THEME_SLUG ), '  <span class="edit-link icon-pencil fa fa-pencil"> ', '<span>' ); ?></p>
	<?php
			break;
		default :
	?>
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
		<article id="comment-<?php comment_ID(); ?>" class="comment-body">
			<footer>
				<div class="comment-author vcard">
					<?php echo get_avatar( $comment, 40 ); ?>
					<?php printf( __( '%s <span class="says">says:</span>', THEME_SLUG ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
				</div><!-- .comment-author .vcard -->
				<?php if ( $comment->comment_approved == '0' ) : ?>
					<em><?php _e( 'Your comment is awaiting moderation.', THEME_SLUG ); ?></em>
					<br />
				<?php endif; ?>

				<div class="comment-meta commentmetadata">
					<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><time datetime="<?php comment_time( 'c' ); ?>">
					<?php printf( _x( '%1$s at %2$s', '1: date, 2: time', THEME_SLUG ), get_comment_date(), get_comment_time() ); ?>
					</time></a>
					<?php edit_comment_link( __( 'Edit', THEME_SLUG ), '  <span class="edit-link"> ', '<span>' ); ?>
				</div><!-- .comment-meta .commentmetadata -->
			</footer>

			<div class="comment-content"><?php comment_text(); ?></div>
			<?php if ( comments_open() ) : ?>
			<div class="reply">
				<i class="icon-reply fa fa-reply"></i>
				<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
			</div><!-- .reply -->
			<?php endif; ?>
		</article><!-- #comment-## -->

	<?php
			break;
	endswitch;
} // core_theme_comment()
endif; // ends check for core_theme_comment()

if ( ! function_exists( 'core_theme_posted_on' ) ) {
/**
 * Prints HTML with meta information for the current post-date/time and author.
 *
 * @since framework 1.0
 */
	function core_theme_posted_on() {
		$meta = core_options_get('meta');
		if (!is_page() && $meta) {

			printf( '<div class="entry-meta"><i class="icon-calendar fa fa-calendar"></i> <a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><span class="byline"> &nbsp;<span class="author vcard"><i class="icon-user fa fa-user"></i> <a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span></div><!-- .entry-meta -->',
				esc_url( get_permalink() ),
				esc_attr( get_the_time() ),
				esc_attr( get_the_date( 'c' ) ),
				esc_html( get_the_date() ),
				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
				esc_attr( sprintf( __( 'View all posts by %s', THEME_SLUG ), get_the_author() ) ),
				get_the_author()
			);
		}
	} // core_theme_posted_on()
}
add_action('core_theme_hook_entry_header', 'core_theme_posted_on');


if ( ! function_exists( 'core_theme_posted_in' ) ) :
/**
 * Prints HTML with meta information for the current categories, tags, comments.
 *
 * @since framework 1.0
 */
 	function core_theme_posted_in() {
		$meta = core_options_get('meta');
		if ( 'post' == get_post_type() && $meta ) : // Hide category and tag text for pages on Search ?>
		<?php
			/* translators: used between list items, there is a space after the comma */
			$categories_list = get_the_category_list( __( ', ', THEME_SLUG ) );
			if ( $categories_list && core_theme_categorized_blog() ) :
		?>
		<span class="cat-links">
			<i class="icon-folder-close fa fa-folder-close"></i>
			<?php echo $categories_list; ?>
		</span>

		<?php endif; // End if categories ?>

		<?php
			/* translators: used between list items, there is a space after the comma */
			$tags_list = get_the_tag_list( '', __( ', ', THEME_SLUG ) );
			if ( $tags_list ) :
		?>
		<span class="sep"> | </span>
		<span class="tags-links">
			<i class="icon-tags fa fa-tags"></i>
			<?php echo $tags_list; ?>
		</span>

		<?php endif; // End if $tags_list ?>
		<?php //endif; // End if 'post' == get_post_type() ?>

		<?php if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
		<span class="sep"> | </span>
		<span class="comments-link"> <i class="icon-comments fa fa-comments"></i> <?php comments_popup_link( __( 'Leave a comment', THEME_SLUG ), __( '1 Comment', THEME_SLUG ), __( '% Comments', THEME_SLUG ) ); ?></span>
		<!-- <span class="sep"> | </span> -->
		<?php endif;
		endif;
	} // core_theme_posted_in()
endif;


if ( ! function_exists( 'core_theme_entry_meta' ) ) :
/**
 * Prints HTML with meta information for the current post-date/time and author.
 *
 * @since Mikmag 2.0
 */

 function core_theme_entry_meta(){
 /* translators: used between list items, there is a space after the comma */
	$category_list = get_the_category_list( __( ', ', THEME_SLUG ) );

	/* translators: used between list items, there is a space after the comma */
	$tag_list = get_the_tag_list( '', __( ', ', THEME_SLUG ) );

	if ( ! core_theme_categorized_blog() ) {
		// This blog only has 1 category so we just need to worry about tags in the meta text
		if ( '' != $tag_list ) {
			$meta_text = __( 'This entry was tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', THEME_SLUG );
		} else {
			$meta_text = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', THEME_SLUG );
		}

	} else {
		// But this blog has loads of categories so we should probably display them here
		if ( '' != $tag_list ) {
			$meta_text = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', THEME_SLUG );
		} else {
			$meta_text = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', THEME_SLUG );
		}

	} // end check for categories on this blog

	printf(
		$meta_text,
		$category_list,
		$tag_list,
		get_permalink(),
		the_title_attribute( 'echo=0' )
	);
} // core_theme_entry_meta()
endif;
add_action('core_theme_hook_entry_footer_meta', 'core_theme_entry_meta');

/**
 * Returns true if a blog has more than 1 category
 *
 * @since framework 1.0
 */
function core_theme_categorized_blog() {
	if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
		// Create an array of all the categories that are attached to posts
		$all_the_cool_cats = get_categories( array(
			'hide_empty' => 1,
		) );

		// Count the number of categories that are attached to the posts
		$all_the_cool_cats = count( $all_the_cool_cats );

		set_transient( 'all_the_cool_cats', $all_the_cool_cats );
	}

	if ( '1' != $all_the_cool_cats ) {
		// This blog has more than 1 category so core_theme_categorized_blog should return true
		return true;
	} else {
		// This blog has only 1 category so core_theme_categorized_blog should return false
		return false;
	}
} // core_theme_categorized_blog()

/**
 * Flush out the transients used in core_theme_categorized_blog
 *
 * @since framework 1.0
 */
function core_theme_category_transient_flusher() {
	// Like, beat it. Dig?
	delete_transient( 'all_the_cool_cats' );
} // core_theme_category_transient_flusher()
add_action( 'edit_category', 'core_theme_category_transient_flusher' );
add_action( 'save_post', 'core_theme_category_transient_flusher' );

/**
 * Post Format Support
 *********************************************************************/

if ( ! function_exists( 'core_theme_entry_date' ) ) :
/**
 * Prints HTML with date information for current post.
 *
 * Create your own core_theme_entry_date() to override in a child theme.
 *
 * @since Twenty Thirteen 1.0
 *
 * @param boolean $echo Whether to echo the date. Default true.
 * @return string
 */
function core_theme_entry_date( $echo = true ) {
	$format_prefix = ( has_post_format( 'chat' ) || has_post_format( 'status' ) ) ? _x( '%1$s on %2$s', '1: post format name. 2: date', 'twentythirteen' ): '%2$s';

	$date = sprintf( '<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span>',
		esc_url( get_permalink() ),
		esc_attr( sprintf( __( 'Permalink to %s', 'twentythirteen' ), the_title_attribute( 'echo=0' ) ) ),
		esc_attr( get_the_date( 'c' ) ),
		esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
	);

	if ( $echo )
		echo $date;

	return $date;
}
endif;

/**
 * Returns the URL from the post.
 *
 * @uses get_the_link() to get the URL in the post meta (if it exists) or
 * the first link found in the post content.
 *
 * Falls back to the post permalink if no URL is found in the post.
 *
 * @since Twenty Thirteen 1.0
 * @return string URL
 */
function core_theme_get_link_url() {
	$content = get_the_content();
	$has_url = get_url_in_content( $content );

	return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
}


function add_flexslider_js(){
	wp_enqueue_script( 'flexslider', CORE_URI . '/slider/slider-flexslider/jquery.flexslider-min.js', array(), '2.1', true );
} // add_flexslider_js()


// Outputs the page title and breadcrumbs before a template page
//
function core_theme_page_title() {
	if ( !is_home() && !is_front_page() && !is_singular() ) {
		global $post;
		echo '<div class="title-row">';
		if (core_options_get('titles') == true){
			if (is_category())
				echo '<h1 class="title entry-title">',single_cat_title( '', false ), '</h1>';
			elseif (is_archive() && is_day() )
				printf( __( '<h1 class="title entry-title">Daily Archives: %s', 'themedutch' ), get_the_date() . '</h1>' );
			elseif (is_archive() && is_month() )
				printf( __( '<h1 class="title entry-title">Monthly Archives: %s', 'themedutch' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'themedutch' ) ) . '</h1>' );
			elseif (is_archive() && is_year() )
				printf( __( '<h1 class="title entry-title">Yearly Archives: %s', 'themedutch' ), get_the_date( _x( 'Y', 'yearly archives date format', 'themedutch' ) ) . '</h1>' );
			elseif (is_tag() )
				printf( __( '<h1 class="title entry-title">Showing posts with tag: %s', 'themedutch' ), single_term_title("", false) . '</h1>' );
			elseif (is_search() )
				printf( __( '<h1 class="title entry-title">Search Results: %s', 'themedutch' ) , '"<span>' . get_search_query() . '</span>"' . '</h1>' );
			//else
			//	echo '<h1 class="title entry-title">', get_the_title(), '</h1>';
		}

		if (core_options_get('breadcrumbs') == true ) {
			core_theme_breadcrumb();
		}
		echo '</div>';

	}
}
add_action('core_before_template', 'core_theme_page_title');



?>