<?php
/*
The file contain functions for Woocommerce.
*/

/**
 * Extend the default WordPress body classes.
 *
 * Adds body classes to denote:
 * 1. Single or multiple authors.
 * 2. Active widgets in the sidebar to change the layout and spacing.
 * 3. When avatars are disabled in discussion settings.
 *
 *
 * @param array $classes A list of existing body class values.
 * @return array The filtered body class list.
 */
function theguard_body_class( $classes ) {
    if ( ! is_multi_author() )
        $classes[] = 'single-author';

    if ( is_active_sidebar( 'sidebar-2' ) && ! is_attachment() && ! is_404() )
        $classes[] = 'sidebar';

    if ( ! get_option( 'show_avatars' ) )
        $classes[] = 'no-avatars';

    return $classes;
}
add_filter( 'body_class', 'theguard_body_class' );

/*
 * Adjust content_width value for video post formats and attachment templates.
*/
if ( ! isset( $content_width ) ) {
    $content_width = 1140;
}
function theguard_content_width() {
    global $content_width;

    if ( is_attachment() )
        $content_width = 724;
    elseif ( has_post_format( 'audio' ) )
        $content_width = 484;
}
add_action( 'template_redirect', 'theguard_content_width' );

/**
 * Display navigation to next/previous set of posts when applicable.
 *
 */
if ( ! function_exists( 'theguard_paging_nav' ) ) :
    function theguard_paging_nav() {
        global $wp_query;

        // Don't print empty markup if there's only one page.
        if ( $wp_query->max_num_pages < 2 )
            return;
        ?>
        <nav class="navigation paging-navigation" role="navigation">
            <div class="nav-links clearfix">

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

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

            </div><!-- .nav-links -->
        </nav><!-- .navigation -->
        <?php
    }
endif;
/**
 * Print the attached image with a link to the next attached image.
 */
if ( ! function_exists( 'theguard_the_attached_image' ) ) :

    function theguard_the_attached_image() {
        /**
         * Filter the image attachment size to use.
         *
         * @since Twenty thirteen 1.0
         *
         * @param array $size {
         *     @type int The attachment height in pixels.
         *     @type int The attachment width in pixels.
         * }
         */
        $attachment_size     = apply_filters( 'theguard_attachment_size', array( 724, 724 ) );
        $next_attachment_url = wp_get_attachment_url();
        $post                = get_post();

        /*
         * Grab the IDs of all the image attachments in a gallery so we can get the URL
         * of the next adjacent image in a gallery, or the first image (if we're
         * looking at the last image in a gallery), or, in a gallery of one, just the
         * link to that image file.
         */
        $attachment_ids = get_posts( array(
            'post_parent'    => $post->post_parent,
            'fields'         => 'ids',
            'numberposts'    => -1,
            'post_status'    => 'inherit',
            'post_type'      => 'attachment',
            'post_mime_type' => 'image',
            'order'          => 'ASC',
            'orderby'        => 'menu_order ID',
        ) );

        // If there is more than 1 attachment in a gallery...
        if ( count( $attachment_ids ) > 1 ) {
            foreach ( $attachment_ids as $attachment_id ) {
                if ( $attachment_id == $post->ID ) {
                    $next_id = current( $attachment_ids );
                    break;
                }
            }

            // get the URL of the next image attachment...
            if ( $next_id )
                $next_attachment_url = get_attachment_link( $next_id );

            // or get the URL of the first image attachment.
            else
                $next_attachment_url = get_attachment_link( reset( $attachment_ids ) );
        }

        printf( '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>',
            esc_url( wp_get_attachment_url() ),
            the_title_attribute( array( 'echo' => false ) ),
            wp_get_attachment_image( $post->ID, $attachment_size )
        );
    }
endif;

// Column Control of Service Category page
function theguard_services_column_control()
{
    global $secretlab;
    if (isset ($secretlab['sell_serv_col'])) {
        $sl_serv_col = $secretlab['sell_serv_col'];
        if ($sl_serv_col == 1) {
            echo 'col-lg-6 col-md-6 col-sm-6 col-xs-12';
        }
        if ($sl_serv_col == 2) {
            echo 'col-lg-4 col-md-4 col-sm-6 col-xs-12';
        }
    } else {
        echo 'col-lg-6 col-md-6 col-sm-6 col-xs-12';
    }
}
// Column Control clear of Service Category page
function theguard_services_column_clear() {
    global $secretlab;
    if (isset ($secretlab['sell_serv_col'])) {
        $sl_serv_col = $secretlab['sell_serv_col'];
        if ($sl_serv_col == 1) {
            echo 'twocol';
        }
        if ($sl_serv_col == 2) {
            echo 'threecol';
        }
    } else {
        echo 'threecol';
    }
}

// Column Control of Case Category page
function theguard_case_column_control() {
    global $secretlab;
    if (isset ($secretlab['lawyer_cases_col'])) {
        $sl_serv_col = $secretlab['lawyer_cases_col'];
        if ($sl_serv_col == 1) {
            echo 'col-lg-12 col-md-12 col-sm-12 col-xs-12';
        }
        if ($sl_serv_col == 2) {
            echo 'col-lg-6 col-md-6 col-sm-12 col-xs-12 col2';
        }
    } else {
        echo 'col-lg-12 col-md-12 col-sm-12 col-xs-12';
    }
}
// Cases/portfolio excerpt length
function sell_excerpt_length_portf() {
    global $post;
    echo theguard_get_excerpt($post, $post->post_excerpt, 20);
}
// "Read more" button text for Services page
if ( ! function_exists( 'theguard_portfolio_rmore' ) ) {
    function theguard_portfolio_rmore()
    {
        global $secretlab;
        if (isset($secretlab['portfolio_arch_rmore'])) {
            if (!empty($secretlab['portfolio_arch_rmore'])) {
                echo esc_html($secretlab['portfolio_arch_rmore']);
            }
        }
    }
}

// Column Control of Teammate Category page
function theguard_team_column_control() {
    global $secretlab;
    if (isset ($secretlab['teammate_col'])) {
        $sl_serv_col = $secretlab['teammate_col'];
        if ($sl_serv_col == 1) {
            echo 'col-lg-4 col-md-4 col-sm-6 col-xs-12';
        }
        if ($sl_serv_col == 2) {
            echo 'col-lg-3 col-md-3 col-sm-4 col-xs-12 col4';
        }
    } else {
        echo 'col-lg-6 col-md-6 col-sm-6 col-xs-12';
    }
}

// Headline 1
if ( ! function_exists( 'theguard_heading_header4' ) ) {
    function theguard_heading_header4()
    {
        if (is_single()) {
            global $secretlab;
            if (isset ($secretlab['header-layout'])) {
                $sl_head_lay = $secretlab['header-layout'];
                if ($sl_head_lay != 6) {
                    echo '<h1 class="entry-title title single-title">';
                    the_title();
                    echo '</h1>';
                }
            } else {
                echo '<h1 class="entry-title title single-title">';
                the_title();
                echo '</h1>';
            }
        }
    }
}

//Scroll to top button
if ( ! function_exists( 'theguard_scroll_button' ) ) {
    function theguard_scroll_button()
    {
        global $secretlab;
        if (isset ($secretlab['scroll-to-top'])) {
            if ($secretlab['scroll-to-top'] == 1) {
                if (isset ($secretlab['back_to_top'])) {
                    echo '<a href="#" id="scroller">'.esc_html($secretlab['back_to_top']).' <i class="fa fa-arrow-up"></i></a>';
                }
            }
        }
    }
}

// Title for Case Study page
if ( ! function_exists( 'theguard_portfolio_title' ) ) {
    function theguard_portfolio_title()
    {
        global $secretlab;
        if (isset($secretlab['cases_arch_title'])) {
            if (!empty($secretlab['cases_arch_title'])) {
                echo esc_html($secretlab['cases_arch_title']);
            }
        }
    }
}
if ( ! function_exists( 'theguard_portfolio_desc' ) ) {
    function theguard_portfolio_desc()
    {
        global $secretlab;
        $allowed_html = array(
            'a' => array(
                'href' => array(),
                'title' => array()
            ),
            'img' => array(
                'src' => array(),
                'title' => array(),
                'alt' => array(),
                'class' => array(),
            ),
            'br' => array(),
            'em' => array(),
            'strong' => array(),
            'h1' => array(),
            'h2' => array(),
            'h3' => array(),
            'h4' => array(),
            'h5' => array(),
            'h6' => array(),
            'p' => array(
                'style' => array(),
            ),
            'b' => array(),
            'i' => array(),
            'u' => array(),
            'ol' => array(),
            'ul' => array(),
            'li' => array(),
            'code' => array(),
            'del' => array()
        );
        if (isset ($secretlab['portfolio_arch_desc'])) {
            $sl_padesc = $secretlab['portfolio_arch_desc'];
            echo '<div class="col-lg-12 descr_arch">'.wp_kses($sl_padesc, $allowed_html).'</div>';
        }
    }
}
// Hide H1 in team page if Header 6 activated
if ( ! function_exists( 'theguard_hide_portfolio' ) ) {
    function theguard_hide_portfolio() {
        global $secretlab;
        if (isset ($secretlab['header-layout'])) {
            $sl_header_layout = $secretlab['header-layout'];
            if ($sl_header_layout != 6) {
                echo '<header class="archive-header"><h1 class="archive-title">';
                theguard_portfolio_title();
                echo '</h1></header>';
            }
            theguard_portfolio_desc();
        }
    }
}

// Title for Services page
if ( ! function_exists( 'theguard_services_title' ) ) {
    function theguard_services_title()
    {
        global $secretlab;
        if (isset($secretlab['services_arch_title'])) {
            if (!empty($secretlab['services_arch_title'])) {
                echo esc_html($secretlab['services_arch_title']);
            }
        }
    }
}
if ( ! function_exists( 'theguard_services_desc' ) ) {
    function theguard_services_desc()
    {
        global $secretlab;
        $allowed_html = array(
            'a' => array(
                'href' => array(),
                'title' => array()
            ),
            'img' => array(
                'src' => array(),
                'title' => array(),
                'alt' => array(),
                'class' => array(),
            ),
            'br' => array(),
            'em' => array(),
            'strong' => array(),
            'h1' => array(),
            'h2' => array(),
            'h3' => array(),
            'h4' => array(),
            'h5' => array(),
            'h6' => array(),
            'p' => array(
                'style' => array(),
            ),
            'b' => array(),
            'i' => array(),
            'u' => array(),
            'ol' => array(),
            'ul' => array(),
            'li' => array(),
            'code' => array(),
            'del' => array()
        );
        if (isset ($secretlab['services_arch_desc'])) {
            $sl_sadesc = $secretlab['services_arch_desc'];
            echo '<div class="col-lg-12 descr_arch">'.wp_kses($sl_sadesc, $allowed_html).'</div>';
        }
    }
}
// "Read more" button text for Services page
if ( ! function_exists( 'theguard_services_rmore' ) ) {
    function theguard_services_rmore()
    {
        global $secretlab;
        if (isset($secretlab['services_arch_rmore'])) {
            if (!empty($secretlab['services_arch_rmore'])) {
                echo esc_html($secretlab['services_arch_rmore']);
            }
        }
    }
}
// Hide H1 in team page if Header 6 activated
if ( ! function_exists( 'theguard_hide_services' ) ) {
    function theguard_hide_services() {
        global $secretlab;
        if (isset ($secretlab['header-layout'])) {
            $sl_header_layout = $secretlab['header-layout'];
            if ($sl_header_layout != 6) {
                echo '<header class="archive-header"><h1 class="archive-title">';
                theguard_services_title();
                echo '</h1></header>';
            }
            theguard_services_desc();
        }
    }
}


// Title for Team page
if ( ! function_exists( 'theguard_team_title' ) ) {
    function theguard_team_title()
    {
        global $secretlab;
        if (isset($secretlab['teammate_arch_title'])) {
            if (!empty($secretlab['teammate_arch_title'])) {
                echo esc_html($secretlab['teammate_arch_title']);
            }
        }
    }
}
if ( ! function_exists( 'theguard_team_desc' ) ) {
    function theguard_team_desc()
    {
        global $secretlab;
        $allowed_html = array(
            'a' => array(
                'href' => array(),
                'title' => array()
            ),
            'img' => array(
                'src' => array(),
                'title' => array(),
                'alt' => array(),
                'class' => array(),
            ),
            'br' => array(),
            'em' => array(),
            'strong' => array(),
            'h1' => array(),
            'h2' => array(),
            'h3' => array(),
            'h4' => array(),
            'h5' => array(),
            'h6' => array(),
            'p' => array(
                'style' => array(),
            ),
            'b' => array(),
            'i' => array(),
            'u' => array(),
            'ol' => array(),
            'ul' => array(),
            'li' => array(),
            'code' => array(),
            'del' => array()
        );
        if (isset ($secretlab['team_arch_desc'])) {
            $sl_tadesc = $secretlab['team_arch_desc'];
            echo '<div class="col-lg-12 descr_arch">'.wp_kses($sl_tadesc, $allowed_html).'</div>';
        }
    }
}
// Some phrases for translate at Theme Options
if ( ! function_exists( 'theguard_teampageh3_title' ) ) {
    function theguard_teampageh3_title() {
        global $secretlab;
        if (isset($secretlab['team_page_h3'])) {
            if (!empty($secretlab['team_page_h3'])) {
                echo esc_html($secretlab['team_page_h3']);
            }
        }
    }
}
if ( ! function_exists( 'theguard_teampage_phone' ) ) {
    function theguard_teampage_phone() {
        global $secretlab;
        if (isset($secretlab['team_phone'])) {
            if (!empty($secretlab['team_phone'])) {
                echo esc_html($secretlab['team_phone']);
            }
        }
    }
}
if ( ! function_exists( 'theguard_teampage_email' ) ) {
    function theguard_teampage_email() {
        global $secretlab;
        if (isset($secretlab['team_email'])) {
            if (!empty($secretlab['team_email'])) {
                echo esc_html($secretlab['team_email']);
            }
        }
    }
}
if ( ! function_exists( 'theguard_teampage_social' ) ) {
    function theguard_teampage_social() {
        global $secretlab;
        if (isset($secretlab['team_social'])) {
            if (!empty($secretlab['team_social'])) {
                echo esc_html($secretlab['team_social']);
            }
        }
    }
}
if ( ! function_exists( 'theguard_teampage_about' ) ) {
    function theguard_teampage_about() {
        global $secretlab;
        if (isset($secretlab['team_page_about'])) {
            if (!empty($secretlab['team_page_about'])) {
                echo esc_html($secretlab['team_page_about']);
            }
        }
    }
}

// Heading contact at team page
if ( ! function_exists( 'theguard_hide_team' ) ) {
    function theguard_hide_team() {
        global $secretlab;
        if (isset ($secretlab['header-layout'])) {
            $sl_header_layout = $secretlab['header-layout'];
            if ($sl_header_layout != 6) {
                echo '<header class="archive-header"><h1 class="archive-title">';
                theguard_team_title();
                echo '</h1></header>';
            }
            theguard_team_desc();
        }
    }
}


// Title for Testimonials page
if ( ! function_exists( 'theguard_testi_title' ) ) {
    function theguard_testi_title(){
        global $secretlab;
        if (isset($secretlab['testimonials_arch_title'])) {
            if (!empty($secretlab['testimonials_arch_title'])) {
                echo esc_html($secretlab['testimonials_arch_title']);
            }
        }
    }
}
if ( ! function_exists( 'theguard_testi_desc' ) ) {
    function theguard_testi_desc(){
        global $secretlab;
        $allowed_html = array(
            'a' => array(
                'href' => array(),
                'title' => array()
            ),
            'img' => array(
                'src' => array(),
                'title' => array(),
                'alt' => array(),
                'class' => array(),
            ),
            'br' => array(),
            'em' => array(),
            'strong' => array(),
            'h1' => array(),
            'h2' => array(),
            'h3' => array(),
            'h4' => array(),
            'h5' => array(),
            'h6' => array(),
            'p' => array(
                'style' => array(),
            ),
            'b' => array(),
            'i' => array(),
            'u' => array(),
            'ol' => array(),
            'ul' => array(),
            'li' => array(),
            'code' => array(),
            'del' => array()
        );
        if (isset ($secretlab['testi_arch_desc'])) {
            $sl_teadesc = $secretlab['testi_arch_desc'];
            echo '<div class="col-lg-12 descr_arch">'.wp_kses($sl_teadesc, $allowed_html).'</div>';
        }
    }
}
// Hide H1 in testimonials page if Header 6 activated
if ( ! function_exists( 'theguard_hide_testim' ) ) {
    function theguard_hide_testim() {
        global $secretlab;
        if (isset ($secretlab['header-layout'])) {
            $sl_header_layout = $secretlab['header-layout'];
            if ($sl_header_layout != 6) {
                echo '<header class="archive-header"><h1 class="archive-title">';
                theguard_testi_title();
                echo '</h1></header>';
            }
            theguard_testi_desc();
        }
    }
}

// Page H1 heading
if ( ! function_exists( 'theguard_entry_header' ) ) {
    function theguard_entry_header() {
        if (class_exists( 'Redux' )) {
            if (isset($secretlab['single-header'])) {
                if ($secretlab['single-header'] == 1) {
                    echo '<h1 class="archive-title">' . get_the_title() . '</h1>';
                }
            }
        } else {
            echo '<h1 class="archive-title">' . get_the_title() . '</h1>';
        }
    }
}
?>
