<?php
/*
The file contain functions for headers sections.
*/
// Favicon and apple touch icon
if ( ! function_exists( 'theguard_headicons' ) ) {
    function theguard_headicons() {
        wp_site_icon();
        global $secretlab;
        if (!function_exists('has_site_icon') || !has_site_icon()) {
            echo '<link href="' . get_template_directory_uri() . '/images/favicon.ico" rel="shortcut icon">';
        }
        if (isset ($secretlab['apple-touch-icon'])) {
            $sl_ati = $secretlab['apple-touch-icon']['url'];
            if (!empty($sl_ati)) {
                echo '<link href="' . esc_url($sl_ati) . '" rel="apple-touch-icon">';
            }
        }
    }
}
// Pageloader
if ( ! function_exists( 'theguard_pageloader' ) ) {
    function theguard_pageloader()
    {
        global $secretlab;
        if (isset ($secretlab['pageloader'])) {
            if (isset ($secretlab['pageloaderimage']['url'])) {
                $sell_image = $secretlab['pageloaderimage']['url'];
                if ($secretlab['pageloader'] == 1) {
                    echo '<div id="page-preloader"><img src="' . esc_url($sell_image) . '" alt="Wait when page loaded" /></div>';
                }
            }
        }
    }
}

// Social buttons
if ( ! function_exists( 'theguard_socialbuttons_header' ) ) {
    function theguard_socialbuttons_header()
    {
        global $secretlab;
        $sl_header_social_buttons = $secretlab['header-social-buttons'];
        if ($sl_header_social_buttons == true) {
            echo '<ul class="socialbartransparent">';
            if (isset ($secretlab['social_link_facebook'])) {
                $sl_fb = $secretlab['social_link_facebook'];
                if (!empty($sl_fb)) {
                    echo '<li><a href="' . esc_url($sl_fb) . '" target="_blank"><i class="fa fa-facebook"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_twitter'])) {
                $sl_tw = $secretlab['social_link_twitter'];
                if (!empty($sl_tw)) {
                    echo '<li><a href="' . esc_url($sl_tw) . '" target="_blank"><i class="fa fa-twitter"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_myspace'])) {
                $sl_myspace = $secretlab['social_link_myspace'];
                if (!empty($sl_myspace)) {
                    echo '<li><a href="' . esc_url($sl_myspace) . '" target="_blank"><i class="fa fa-user"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_linkedin'])) {
                $sl_linkedin = $secretlab['social_link_linkedin'];
                if (!empty($sl_linkedin)) {
                    echo '<li><a href="' . esc_url($sl_linkedin) . '" target="_blank"><i class="fa fa-linkedin"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_google'])) {
                $sl_google = $secretlab['social_link_google'];
                if (!empty($sl_google)) {
                    echo '<li><a href="' . esc_url($sl_google) . '" target="_blank"><i class="fa fa-google-plus"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_tumblr'])) {
                $sl_tumblr = $secretlab['social_link_tumblr'];
                if (!empty($sl_tumblr)) {
                    echo '<li><a href="' . esc_url($sl_tumblr) . '" target="_blank"><i class="fa fa-tumblr"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_pinterest'])) {
                $sl_pinterest = $secretlab['social_link_pinterest'];
                if (!empty($sl_pinterest)) {
                    echo '<li><a href="' . esc_url($sl_pinterest) . '" target="_blank"><i class="fa fa-pinterest-p"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_youtube'])) {
                $sl_youtube = $secretlab['social_link_youtube'];
                if (!empty($sl_youtube)) {
                    echo '<li><a href="' . esc_url($sl_youtube) . '" target="_blank"><i class="fa fa-youtube-play"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_instagram'])) {
                $sl_instagram = $secretlab['social_link_instagram'];
                if (!empty($sl_instagram)) {
                    echo '<li><a href="' . esc_url($sl_instagram) . '" target="_blank"><i class="fa fa-instagram"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_vkcom'])) {
                $sl_vkcom = $secretlab['social_link_vkcom'];
                if (!empty($sl_vkcom)) {
                    echo '<li><a href="' . esc_url($sl_vkcom) . '" target="_blank"><i class="fa fa-vk"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_reddit'])) {
                $sl_reddit = $secretlab['social_link_reddit'];
                if (!empty($sl_reddit)) {
                    echo '<li><a href="' . esc_url($sl_reddit) . '" target="_blank"><i class="fa fa-reddit-alien"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_blogger'])) {
                $sl_blogger = $secretlab['social_link_blogger'];
                if (!empty($sl_blogger)) {
                    echo '<li><a href="' . esc_url($sl_blogger) . '" target="_blank"><i class="fa fa-pencil"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_wordpress'])) {
                $sl_wordpress = $secretlab['social_link_wordpress'];
                if (!empty($sl_wordpress)) {
                    echo '<li><a href="' . esc_url($sl_wordpress) . '" target="_blank"><i class="fa fa-wordpress"></i></a></li>';
                }
            }
            if (isset ($secretlab['social_link_behance'])) {
                $sl_behance = $secretlab['social_link_behance'];
                if (!empty($sl_behance)) {
                    echo '<li><a href="' . esc_url($sl_behance) . '" target="_blank"><i class="fa fa-behance"></i></a></li>';
                }
            }
            echo '</ul>';
        }
    }
}
// Display 1 phone number in header
if ( ! function_exists( 'theguard_phone_header' ) ) {
    function theguard_phone_header()
    {
        global $secretlab;
        if (isset ($secretlab['phone'])) {
            $sl_phone = $secretlab['phone'][0];
            if (!empty($sl_phone)) {
                echo ' <p><i class="fa fa-phone"></i> ' . esc_attr($sl_phone) . '</p>';
            }
        }
    }
}

// Display 1 email in header
if ( ! function_exists( 'theguard_email_header' ) ) {
    function theguard_email_header() {
        global $secretlab;
        if (isset ($secretlab['topbar-type'])) {
            if ($secretlab['topbar-type'] == 1) {
                if (isset ($secretlab['email'][0])) {
                    $sl_email = $secretlab['email'][0];
                    if (!empty($sl_email)) {
                        echo '<p><i class="fa fa-envelope"></i> ' . esc_attr($sl_email) . '</p>';
                    }
                }
            } else {
                if (isset ($secretlab['address'][0])) {
                    $sl_addr = $secretlab['address'][0];
                    $sl_addr1 = isset($secretlab['address'][1]) && $secretlab['address'][1] != '' ? $secretlab['address'][1] : '';

                    if (!empty($sl_addr)) {
                        echo '<p><i class="fa fa-map-marker"></i> ' . esc_attr($sl_addr);
                        if($sl_addr1 != '') {echo '<i class="fa fa-map-marker"></i> ' . esc_attr($sl_addr1);}
                        echo '</p>';
                    }
                }
            }
        }
        
    }
}
// Display 1 phone number & 1 email in header
if ( ! function_exists( 'theguard_emon_header' ) ) {
    function theguard_emon_header()
    {
        global $secretlab;
        if (isset ($secretlab['phone'])) {
            if (isset ($secretlab['email'][0])) {
                $sl_phone = $secretlab['phone'][0];
                $sl_email = $secretlab['email'][0];
                if (!empty($sl_phone)) {
                    echo ' <p><i class="fa fa-phone"></i> ' . esc_attr($sl_phone) . '<br><i class="fa fa-envelope"></i> ' . esc_attr($sl_email) . '</p>';
                }
            }
        }
    }
}

// Display unlimited phone number in header
if ( ! function_exists( 'theguard_get_header_tels' ) ) {
    function theguard_get_header_tels()
    {
        global $secretlab;
        $head_phones = implode('<br><i class="fa fa-phone"></i> ', $secretlab['phone']);
        return $head_phones;
    }
}
if ( ! function_exists( 'theguard_phones_header' ) ) {
    function theguard_phones_header()
    {
        global $secretlab;
        if (isset ($secretlab['phone'])) {

            if (!empty($secretlab['phone'])) {
                echo '<p><i class="fa fa-phone"></i> ' . theguard_get_header_tels() . '</p>';
            }
        }
    }
}

// Sticky menu class
if ( ! function_exists( 'theguard_sticky_class' ) ) {
    function theguard_sticky_class()
    {
        global $secretlab;
        if (isset ($secretlab['sticky-menu'])) {
            $sl_sticky_menu = $secretlab['sticky-menu'];
            if ($sl_sticky_menu == true) {
                echo 'id="stickymenu"';
            }
        }
    }
}
// Light Logo
if ( ! function_exists( 'theguard_logo_img' ) ) {
    function theguard_logo_img()
    {
        global $secretlab;
        if (isset ($secretlab['logo-head'])) {
            $sl_top_logo = $secretlab['logo-head']['url'];
            if (!empty($sl_top_logo)) {
                echo '<a href='.home_url('/').' class="logo"><img src="' . esc_url($sl_top_logo) . '" alt="';
                if (isset ($secretlab['comp-name'])) {
                    echo esc_attr($secretlab['comp-name']);
                }
                echo '" /></a>';
            }
        } else {
            echo '<a href='.home_url('/').' class="logo"><img src="' . esc_url(get_template_directory_uri()) . '/images/logo.png" alt="'.esc_attr__( 'The Guard WordPress Theme', 'the-guard' ).'" /></a>';
        }
    }
}
// Dark Logo
if ( ! function_exists( 'theguard_logo_dark' ) ) {
    function theguard_logo_dark()
    {
        global $secretlab;
        if (isset ($secretlab['logo-head-dark'])) {
            $sl_top_logo = $secretlab['logo-head-dark']['url'];
            if (!empty($sl_top_logo)) {
                echo '<a href='.home_url('/').' class="logo"><img src="' . esc_url($sl_top_logo) . '" alt="';
                if (isset ($secretlab['comp-name'])) {
                    echo esc_attr($secretlab['comp-name']);
                }
                echo '" /></a>';
            }
        } else {
            echo '<a href='.home_url('/').' class="logo"><img src="' . esc_url(get_template_directory_uri()).'/images/logodark.png" alt="'.esc_attr__( 'The Guard WordPress Theme', 'the-guard' ).'" /></a>';
        }
    }
}
// Logo for header 3
if ( ! function_exists( 'theguard_logo_img_h3' ) ) {
    function theguard_logo_img_h3()
    {
        global $secretlab;
        if (isset ($secretlab['logo-head3'])) {
            $sl_top_logo3 = $secretlab['logo-head3']['url'];
            if (!empty($sl_top_logo3)) {
                echo '<a href='.home_url('/').' class="logo"><img src="' . esc_url($sl_top_logo3) . '" alt="';
                if (isset ($secretlab['comp-name'])) {
                    echo esc_attr($secretlab['comp-name']);
                }
                echo '" /></a>';
            }
        } else {
            echo '<a href='.home_url('/').' class="logo"><img src="' . esc_url(get_template_directory_uri()).'/images/logo.png" alt="'.esc_attr__( 'The Guard WordPress Theme', 'the-guard' ).'" /></a>';
        }

    }
}

// Search icon and form for menu
if ( ! function_exists( 'theguard_search_menu' ) ) {
    function theguard_search_menu()
    {
        global $secretlab;
        if (isset ($secretlab['search_icon_menu'])) {
            $sl_search_menu = $secretlab['search_icon_menu'];
            if ($sl_search_menu == 1) {
                echo '<li class="li-search"><a href="#" class="open-search"><span class="sicon-search-find-loupe-investigation"></span></a></li>
                  <li class="search-item-nav"><div class="search-block">
                       <form method="get" id="searchform" action="' . home_url() . '/">
                       <input type="text" placeholder="Search" class="search-input" value="" name="s" id="s" />
                       <button class="search-sbmt left10" type="submit" id="searchsubmit" ><span class="sicon-search-find-loupe-investigation"></span></button>
                       <button class="search-sbmt search-sbmt-close" type="button"><i class="fa fa-times"></i></button>
                       </form>
                  </div></li>';
            }
        }
    }
}

// Topbar
if ( ! function_exists( 'theguard_topbar' ) ) {
    function theguard_topbar() {
        global $secretlab;
        if (isset ($secretlab['header-topbar'])) {
            $sl_header_topbar = $secretlab['header-topbar'];
            if ($sl_header_topbar == 1) {
                echo '<div class="sell_topbar">
                    <div class="container">
                        <div class="row"><div class="col-md-9 col-sm-12 col-xs-12 cdata">';
                            theguard_phone_header();
                            theguard_email_header();
                            echo '</div>
                            <div class="col-md-3 col-sm-12 col-xs-12 social">';
                            theguard_socialbuttons_header();
                            echo '</div>
                        </div>
                    </div>
                </div>';
            }

        }
    }
}
// Topbar 2, mail/phobe right
if ( ! function_exists( 'theguard_topbar_r' ) ) {
    function theguard_topbar_r()
    {
        global $secretlab;
        if (isset ($secretlab['header-topbar'])) {
            $sl_header_topbar = $secretlab['header-topbar'];
            if ($sl_header_topbar == 1) {
                echo '<div class="sell_topbar">
        <div class="container">
            <div class="row">
            <div class="col-md-3 col-sm-12 col-xs-12 social">';
                theguard_socialbuttons_header();
                echo '</div>
            <div class="col-md-9 col-sm-12 col-xs-12 cdata">';
                theguard_phone_header();
                theguard_email_header();
                echo '</div>
                
            </div>
        </div>
    </div>';
            }
        }
    }
}

// Topbar header centered
if ( ! function_exists( 'theguard_topbar_c' ) ) {
    function theguard_topbar_c()
    {
        global $secretlab;
        if (isset ($secretlab['header-topbar'])) {
            $sl_header_topbar = $secretlab['header-topbar'];
            if ($sl_header_topbar == 1) {

                echo '<div class="sell_topbar">
                        <div class="container">
                            <div class="row">
                                <div class="col-md-3 col-sm-4 col-xs-12 cont">';
                                theguard_emon_header();
                                echo '</div>
                                <div class="col-md-6 col-sm-4 col-xs-12 tac">';
                                theguard_logo_img();
                                echo '</div>
                                <div class="col-md-3 col-sm-4 col-xs-12 mrgb20 social">';
                                theguard_socialbuttons_header();
                                echo '</div>
                            </div>
                        </div>
                    </div>';
            }
        }
    }
}

// number of header type
if ( ! function_exists( 'theguard_head_num' ) ) {
    function theguard_head_num()
    {
        global $secretlab;
        if (isset ($secretlab['header-layout'])) {
            $sl_header_layout = $secretlab['header-layout'];
            if (!empty($sl_header_layout)) {
                get_template_part('header' . $sl_header_layout);
            }
        } else {
            get_template_part('header1');
        }
    }
}

// boxed layout
function theguard_set_boxed_background() {

    global $secretlab, $theguard_layout;

	$sl_design_layout = isset($theguard_layout[$secretlab['theguard_design_layout']]) ? $theguard_layout[$secretlab['theguard_design_layout']] : 1;
	if ( $sl_design_layout == 2 ) {
        if (!empty($theguard_layout[$secretlab['theguard_pagetype_prefix'].'boxed-background-color'])) {
		    if (!is_array($theguard_layout[$secretlab['theguard_pagetype_prefix'].'boxed-background-color'])) {
		        $bg_color = $theguard_layout[$secretlab['theguard_pagetype_prefix'].'boxed-background-color'];
			}
			else if  (is_array($theguard_layout[$secretlab['theguard_pagetype_prefix'].'boxed-background-color'])) {
			    $bg_color = $theguard_layout[$secretlab['theguard_pagetype_prefix'].'boxed-background-color']['color'];
			} 
		}
		else {
		    $bg_color = 'transparent';
		}
		if (isset($theguard_layout[$secretlab['theguard_pagetype_prefix'].'boxed-background'])) {
		    if (! empty($theguard_layout[$secretlab['theguard_pagetype_prefix'].'boxed-background']) && !is_array($theguard_layout[$secretlab['theguard_pagetype_prefix'].'boxed-background'])) { $src = json_decode($theguard_layout[$secretlab['theguard_pagetype_prefix'].'boxed-background'], true); } 
			else { $src = $theguard_layout[$secretlab['theguard_pagetype_prefix'].'boxed-background']; }
			if ($src['url'] != 'none' && $src['url'] != '') {
			    $bg_image = 'background-image : url("'.$src['url'].'") !important; }';
			}
			else $bg_image = '';
		}
		else {
		    $bg_image = '';
		}
		echo '<style type="text/css">.mainbgr { 
                background-color : '.$bg_color.' !important;'.			           
			    $bg_image.
			  '</style>';
    }
    // Custom CSS and JS
    if (isset ($secretlab['header-nested'])) {
        if ($secretlab['header-nested'] == 1) {
            if (isset ($secretlab['header-nested-ace-js'])) {
                if (strlen($secretlab['header-nested-ace-js']) > 0 && $secretlab['header-nested-ace-js'] != 'function hello() { alert ("HELLO"); }') {
                    echo '<script type="text/javascript">' . $secretlab['header-nested-ace-js'] . '</script>';
                }
            }
        }
    }
    if (isset ($secretlab['header-nested'])) {
        if ($secretlab['header-nested'] == 1) {
            if (isset ($secretlab['header-nested-ace-css'])) {
                if (strlen($secretlab['header-nested-ace-css']) > 0 && $secretlab['header-nested-ace-css'] != 'body { margin : 0; padding : 0; }') {
                    echo '<style type="text/css">' . $secretlab['header-nested-ace-css'] . '</style>';
                }
            }
        }
    }

}


function theguard_set_boxed_layout() {

    global $secretlab, $theguard_layout;
    if (isset ($theguard_layout[$secretlab['theguard_design_layout']])) {
        $sl_design_layout = $theguard_layout[$secretlab['theguard_design_layout']];
        if ($sl_design_layout == 2) {
            echo '<div class="mainbgr"><div class="container"><div class="row">';
        }
    }
}


function theguard_set_header_sidebar_layout() {
	global $secretlab, $theguard_layout;
	$sl_sidebar_layout = isset($theguard_layout[$secretlab['theguard_pagetype_prefix'] . 'sidebar-layout']) ? $theguard_layout[$secretlab['theguard_pagetype_prefix'] . 'sidebar-layout'] : 1;
	if ($sl_sidebar_layout == 2 or $sl_sidebar_layout == 3) {
		echo '<div class="col-lg-3 col-md-3 col-sm-4 col-xs-12 widget-area">';
		if ($secretlab['theguard_page_type'] == '') $prefix = ''; else $prefix = '_';
		if (isset($theguard_layout[$secretlab['theguard_page_type'] . $prefix . 'left_sidebar_widgets'])) {
			dynamic_sidebar($theguard_layout[$secretlab['theguard_page_type'] . $prefix . 'left_sidebar_widgets']);
		} else {
			dynamic_sidebar($secretlab['theguard_page_type'] . '_default_left_sidebar');
		}
		echo '</div>';
	}
	if ($sl_sidebar_layout == 1) {
		echo '<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 main">';
	}
	if ($sl_sidebar_layout == 2) {
		echo '<div class="col-lg-6 col-md-6 col-sm-8 col-xs-12 pr40 pl40 main blogsidebarspage">';
	}
	if ($sl_sidebar_layout == 3) {
		echo '<div class="col-lg-9 col-md-9 col-sm-8 col-xs-12 pl40 main blogsidebarpage">';
	}
	if ($sl_sidebar_layout == 4) {
		echo '<div class="col-lg-9 col-md-9 col-sm-6 col-xs-12 pr40 main blogsidebarpage">';
	}

}

if ( ! function_exists( 'theguard_set_customized_slider' ) ) {
    function theguard_set_customized_slider() {
        global $secretlab, $theguard_layout;

        echo '<div class="headerslider"><div class="container-fluid">';
        if (!$secretlab['is_active_slider_plugins']) {
            echo '';
        } else {
            $sl_headerslider = $theguard_layout[$secretlab['theguard_pagetype_prefix'] . 'header14_slider'];
            if (!empty($sl_headerslider)) {

                theguard_get_customized_slider();

            }
        }
        echo '</div></div>';
    }
}

// Topbar 2
if ( ! function_exists( 'theguard_topbar2' ) ) {
    function theguard_topbar2() {
        global $secretlab;
        if (isset ($secretlab['header-topbar'])) {
            $sl_header_topbar = $secretlab['header-topbar'];
            if ($sl_header_topbar == 1) {
                echo '<div class="sell_topbar topbar2">
                <div class="container">
                    <div class="row">
                         <div class="col-md-12 col-sm-12 col-xs-12">';
                theguard_logo_img();
                theguard_topbar_cta();
                echo '<div class="phone"><i class="fa fa-mobile"></i> ';
                theguard_phone_header_noico();
                echo '<span>';
                theguard_business_hours();
                echo '</span></div>';
                echo '</div>
                        </div>
                    </div>
                </div>';
            }
        }
    }
}
// Logo choosing for Topbar 2 independly of color scheme
function theguard_topbar2_logo() {
    global $secretlab;
    $sl_design_css = isset($secretlab['design-css']) ? $secretlab['design-css'] : 1;
    if ( $sl_design_css == 1 ) {
        theguard_logo_img();
    }
    if ( $sl_design_css == 2 ) {
        theguard_logo_dark();
    }
}
// Display 1 phone number in header
if ( ! function_exists( 'theguard_phone_header_noico' ) ) {
    function theguard_phone_header_noico() {
        global $secretlab;
        if (isset ($secretlab['phone'])) {
            $sl_phone = $secretlab['phone'][0];
            if (!empty($sl_phone)) {
                echo esc_attr($sl_phone);
            }
        }
    }
}
// Business hours
if ( ! function_exists( 'theguard_business_hours' ) ) {
    function theguard_business_hours(){
        global $secretlab;
        if (isset ($secretlab['business_hours'])) {
            echo esc_attr($secretlab['business_hours']);
        }
    }
}
// CTA topbar button
if ( ! function_exists( 'theguard_topbar_cta' ) ) {
    function theguard_topbar_cta() {
        global $secretlab;
        if (isset ($secretlab['topbar-cta'])) {
            if ($secretlab['topbar-cta'] == 1) {
                if (isset ($secretlab['topbar-cta-url'])) {
                    if (isset ($secretlab['topbar-cta-buttontext'])) {
                        echo '<a href="' . $secretlab['topbar-cta-url'] . '" class="ctabtn">' . $secretlab['topbar-cta-buttontext'] . '</a>';
                    }
                }
            }
        }
    }
}
// Switch between short headers in Des 1 and 2
function sell_header6_switch() {
    global $secretlab;
    if (isset ($secretlab['design-css'])) {
        if ($secretlab['design-css'] == 1) {
            echo 'head_tr';
        } else {
            echo 'head_line';
        }
    }
}

?>
