<?php
if ( ! function_exists( 'moment_set_global' ) ) :
/**
 * Setting global values for all saved customizer values
 *
 * @since Moment 1.0.0
 *
 * @param null
 * @return null
 *
 */
function moment_set_global() {
    /*Getting saved values start*/
    $GLOBALS['moment_customizer_all_values'] = moment_get_all_options(1);
}
endif;
add_action( 'moment_action_before_head', 'moment_set_global', 0 );

if ( ! function_exists( 'moment_doctype' ) ) :
/**
 * Doctype Declaration
 *
 * @since Moment 1.0.0
 *
 * @param null
 * @return null
 *
 */
function moment_doctype() {
    ?>
    <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
    <div class="cover">
        <div id="pointx3load">
            <div id="pt1"></div>
            <div id="pt2"></div>
            <div id="pt3"></div>
            <div id="pt4"></div>
            <div id="pt5"></div>
        </div>
    </div>
<?php
}
endif;
add_action( 'moment_action_before_head', 'moment_doctype', 10 );

if ( ! function_exists( 'moment_before_wp_head' ) ) :
/**
 * Before wp head codes
 *
 * @since Moment 1.0.0
 *
 * @param null
 * @return null
 *
 */
function moment_before_wp_head() {
    ?>
        <meta charset="<?php bloginfo( 'charset' ); ?>">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="profile" href="http://gmpg.org/xfn/11">
        <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<?php
}
endif;
add_action( 'moment_action_before_wp_head', 'moment_before_wp_head', 10 );

if( ! function_exists( 'moment_default_layout' ) ) :
    /**
     * Moment default layout function
     *
     * @since  Moment 1.0.0
     *
     * @param int
     * @return string
     */
    function moment_default_layout( $post_id = null ){

        global $moment_customizer_all_values,$post;
        $moment_default_layout = $moment_customizer_all_values['moment-default-layout'];
        if( is_home()){
            $post_id = get_option( 'page_for_posts' );
        }
        if( null == $post_id && isset ( $post->ID ) ){
            $post_id = $post->ID;
        }
        $moment_default_layout_meta = get_post_meta( $post_id, 'moment-default-layout', true );

        if( false != $moment_default_layout_meta ) {
            $moment_default_layout = $moment_default_layout_meta;
        }
        return $moment_default_layout;
    }
endif;

if ( ! function_exists( 'moment_body_class' ) ) :
/**
 * add body class
 *
 * @since Moment 1.0.0
 *
 * @param null
 * @return null
 *
 */
function moment_body_class( $moment_body_classes ) {
    if(!is_front_page() || ( is_front_page() && 1 != moment_if_all_disable())){
        $moment_default_layout = moment_default_layout();
        if( !empty( $moment_default_layout ) ){
            if( 'left-sidebar' == $moment_default_layout ){
                $moment_body_classes[] = 'salientthemes-left-sidebar';
            }
            elseif( 'right-sidebar' == $moment_default_layout ){
                $moment_body_classes[] = 'salientthemes-right-sidebar';
            }
            elseif( 'both-sidebar' == $moment_default_layout ){
                $moment_body_classes[] = 'salientthemes-both-sidebar';
            }
            elseif( 'no-sidebar' == $moment_default_layout ){
                $moment_body_classes[] = 'salientthemes-no-sidebar';
            }
            else{
                $moment_body_classes[] = 'salientthemes-right-sidebar';
            }
        }
        else{
            $moment_body_classes[] = 'salientthemes-right-sidebar';
        }
    }
    return $moment_body_classes;

}
endif;
add_action( 'body_class', 'moment_body_class', 10, 1);

if ( ! function_exists( 'moment_before_page_start' ) ) :
/**
 * intro loader
 *
 * @since Moment 1.0.0
 *
 * @param null
 * @return null
 *
 */
function moment_before_page_start() {
    global $moment_customizer_all_values;
    /*intro loader*/
}
endif;
add_action( 'moment_action_before', 'moment_before_page_start', 10 );

if ( ! function_exists( 'moment_page_start' ) ) :
/**
 * page start
 *
 * @since Moment 1.0.0
 *
 * @param null
 * @return null
 *
 */
function moment_page_start() {
?>
    <div id="page" class="site">
<?php
}
endif;
add_action( 'moment_action_before', 'moment_page_start', 15 );

if ( ! function_exists( 'moment_skip_to_content' ) ) :
/**
 * Skip to content
 *
 * @since Moment 1.0.0
 *
 * @param null
 * @return null
 *
 */
function moment_skip_to_content() {
    ?>
    <a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'moment' ); ?></a>
<?php
}
endif;
add_action( 'moment_action_before_header', 'moment_skip_to_content', 10 );

if ( ! function_exists( 'moment_top_header_section' ) ) :
/**
 * Top header section
 *
 * @since Moment 1.0.0
 *
 * @param null
 * @return null
 *
 */
function moment_top_header_section() {
    ?>
<?php
}
endif;
add_action( 'moment_action_top_header', 'moment_top_header_section', 10 );


if ( ! function_exists( 'moment_header' ) ) :
/**
 * Main header
 *
 * @since Moment 1.0.0
 *
 * @param null
 * @return null
 *
 */
function moment_header() {
    global $moment_customizer_all_values;
    global $wp_version; ?>
        <header id="masthead" class="wrapper site-header" role="banner">
        <div class="container">
            <div class="row">
                <div class="column-md-3 column-sd-12 column-xsd-12 rtl-fright">
                    <div class="site-branding">
                        <?php if (version_compare($wp_version, '4.4.2', '<=')) { ?>
                            <?php if ( is_front_page() && is_home() ){
                                if ( isset($moment_customizer_all_values['moment-logo']) && !empty($moment_customizer_all_values['moment-logo'])) :
                                    if ( is_front_page() && is_home() ){
                                        echo '<h1 class="site-title">';
                                    }
                                    else{
                                        echo '<p class="site-title">';
                                    }
                                    ?>
                                    <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
                                        <img class="header-logo" src="<?php echo esc_url($moment_customizer_all_values['moment-logo']); ?>" alt="<?php bloginfo( 'name' )?>">
                                    </a>
                                    <?php if ( is_front_page() && is_home() ){
                                        echo '</h1>';
                                    }
                                    else{
                                        echo '</p>';
                                    }
                                ?>
                                <?php else :
                                    if ( is_front_page() && is_home() ){
                                        echo '<h1 class="site-title">';
                                    }
                                    else{
                                        echo '<p class="site-title">';
                                    }
                                    ?>
                                    <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
                                        <?php
                                        if ( 1 == $moment_customizer_all_values['moment-enable-title'] ) :
                                            bloginfo( 'name' );
                                        endif;
                                        ?>
                                    </a>
                                        <?php
                                        if ( 1 == $moment_customizer_all_values['moment-enable-tagline'] ) :
                                            echo '<p class="site-description">'. get_bloginfo('description' ).'</p>';
                                        endif;
                                        ?>
                                    <?php if ( is_front_page() && is_home() ){
                                        echo '</h1>';
                                    }
                                    else{
                                        echo '</p>';
                                    }
                                endif; ?>
                            <?php }
                            } 
                        else { 
                            moment_the_custom_logo(); ?>
                            <?php if ( is_front_page() && is_home() ) : ?>
                                <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
                            <?php else : ?>
                                <p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
                            <?php endif;

                            $description = get_bloginfo( 'description', 'display' );
                            if ( $description || is_customize_preview() ) : ?>
                                <h2 class="site-description"><?php echo $description; ?></h2>
                            <?php endif; 
                        } 
                    ?>
                    </div><!-- .site-branding -->
                </div>
                <div class="column-md-7 column-sd-12 column-xsd-12 rtl-fleft">
                    <a href="#site-navigation" id="hamburger"><span></span></a>
                    <nav id="site-navigation" class="main-navigation" role="navigation">
                        <?php wp_nav_menu( array( 
                        'theme_location' => 'primary',
                        'container' => false,
                        ) ); ?>
                    </nav> 
                </div>
                <div class="column-md-2 column-sd-12 column-xsd-12 rtl-fleft">
                    <?php
                    $moment_show_social = $moment_customizer_all_values['moment-enable-social-icons'];
                    if( has_nav_menu( 'social' ) && 1 == $moment_show_social ){
                        ?>
                        <div class="social-widget salientthemes-social-section social-icon-only">
                            <?php
                            wp_nav_menu( array(
                                'theme_location' => 'social',
                                'container' => false
                            ) );
                            ?>
                        </div>
                    <?php
                    }
                    ?>
                </div>
            </div>
        </div>
        </header><!-- #masthead -->
<?php
}
endif;
add_action( 'moment_action_header', 'moment_header', 10 );

if( ! function_exists( 'moment_add_breadcrumb' ) ) :

/**
 * Breadcrumb
 *
 * @since Moment 1.0.0
 *
 * @param null
 * @return null
 *
 */
    function moment_add_breadcrumb(){
        global $moment_customizer_all_values;
        // Bail if Breadcrumb disabled
        $breadcrumb_enable_breadcrumb = $moment_customizer_all_values['moment-enable-breadcrumb' ];
        if ( 1 != $breadcrumb_enable_breadcrumb ) {
            return;
        }
        // Bail if Home Page
        if ( is_front_page() || is_home() ) {
            return;
        }
        echo '<div id="breadcrumb" class="wrapper wrap-breadcrumb"><div class="container">';
         moment_simple_breadcrumb();
        echo '</div><!-- .container --></div><!-- #breadcrumb -->';
        return;
    }
endif;
add_action( 'moment_action_after_title', 'moment_add_breadcrumb', 10 );


if( ! function_exists( 'moment_featured_slider' ) ) :

/**
 * Breadcrumb
 *
 * @since Moment 1.0.0
 *
 * @param null
 * @return null
 *
 */
    function moment_featured_slider(){
        global $moment_customizer_all_values;
        // Bail if Breadcrumb disabled
        global $post, $wp_query;

        // Slider status.
        $featured_slider_status = $moment_customizer_all_values['moment-feature-slider-enable-on'];

        // Get Page ID outside Loop.
        $page_id = $wp_query->get_queried_object_id();

        // Front page displays in Reading Settings.
        $page_on_front  = absint( get_option( 'page_on_front' ) );
        $page_for_posts = absint( get_option( 'page_for_posts' ) );
        switch ( $featured_slider_status ) {
            case 'entire-site':
                do_action('moment_featured_slider');
                break;

            case 'front-index-page':
                if (is_front_page()) {
                    do_action('moment_featured_slider');
                }
                break;

            case 'home-page':
                if ( $page_on_front === $page_id && $page_on_front > 0 ) {
                    do_action('moment_featured_slider');
                }
                break;

            default:
                break;
        }
    }
endif;
add_action( 'moment_action_for_slider', 'moment_featured_slider', 10 );


