<?php
/*
The file contain blog functions.
*/
function theguard_show_postmore() {
    global $secretlab;
if (isset($secretlab['is_related_posts'])) {
    $sl_related_post = $secretlab['is_related_posts'];
    if ($sl_related_post == 1) {
        theguard_postmore_query();
    }
}
}

function theguard_postmore_query() {
    global $post, $secretlab;
    $backup = $post;
    $tags = wp_get_post_tags($post->ID);
    if ($tags) {
        $tag_ids = array();
        foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;

        $args=array(
            'tag__in' => $tag_ids,
            'post__not_in' => array($post->ID),
            'showposts'=>3, // Number of related posts that will be shown.
        );
        $my_query = new wp_query($args);
        if( $my_query->have_posts() ) {
            if (isset($secretlab['related_posts_title'])) {
                $sl_related_title = $secretlab['related_posts_title'];
                if ($sl_related_title == 1) {
                    echo '<h3>' . $sl_related_title . '</h3>';
                }
            }
            echo '<div class="related">';
            while ($my_query->have_posts()) {
                $my_query->the_post();
                ?>
                <div class="rblock">

                    <figure class="thumb">
                        <?php
                        if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                            the_post_thumbnail('theguard_services');
                        } else {
                            
                        }
                        ?>
                        <div class="vanish">
                            <a href="<?php the_permalink(); ?>"><i class="fa fa-eye"></i></a>
                        </div>
                    </figure>

                    <h6><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h6>

                </div>
                <?php
            }
            echo '</div>';
        }
    }
    $post = $backup;
    wp_reset_postdata();
}

// Date and continue link for post feed
if ( ! function_exists( 'theguard_entry_date' ) ) :
    function theguard_entry_date() {
        global $post, $secretlab;
        $p = $post;

        $sl_show_post_date = isset($secretlab['show_post_date']) ? $secretlab['show_post_date'] : 1;
        if ($sl_show_post_date == 1) {
                echo ' <span class="date">';
                echo '<a href="'.get_permalink($p->ID).'">';
                echo '<time class="entry-date" datetime="'.get_the_date( 'c' ).'">'.the_time('F j, Y').'</time>';
                echo '</a>';
                echo '</span>';
        }
    }
endif;

/**
 * Print HTML with meta information for current post: categories, comments counter, author, and date.
 *
 * Create your own theguard_entry_meta() to override in a child theme.
 *
 */
if ( ! function_exists( 'theguard_entry_meta' ) ) :

    function theguard_entry_meta()  {
        global $secretlab;
        //if (is_sticky() && is_home() && !is_paged())

        // Post author
        if (isset($secretlab['show_post_author'])) {
            if ($secretlab['show_post_author'] == 1) {
                if ('post' == get_post_type()) {
                    printf('<span class="vcard author author_name"><i class="fa fa-user"></i> <a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
                        esc_url(get_author_posts_url(get_the_author_meta('ID'))),
                        esc_attr(sprintf(esc_html__('View all posts by %s', 'the-guard'), get_the_author())),
                        get_the_author()
                    );
                }
            }
        } else {
            printf('<span class="vcard author author_name"><i class="fa fa-user"></i> <a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
                esc_url(get_author_posts_url(get_the_author_meta('ID'))),
                esc_attr(sprintf(esc_html__('View all posts by %s', 'the-guard'), get_the_author())),
                get_the_author()
            );
        }

        // Categories: used between list items, there is a space after the comma.
        $categories_list = get_the_category_list(esc_html__(', ', 'the-guard'));
        if (isset($secretlab['show_post_category'])) {
            if ($secretlab['show_post_category'] == 1) {
                if ($categories_list) {
                    echo '<span class="categories-links"><i class="fa fa-list"></i> ' . $categories_list . '</span>';
                }
            }
        } else {
            echo '<span class="categories-links"><i class="fa fa-list"></i> ' . $categories_list . '</span>';
        }

        //Post data
        if (isset($secretlab['show_post_date'])) {
            if ($secretlab['show_post_date'] == 1) {
                if (is_single()) {
                    echo '<span class="post_date date updated"><i class="fa fa-calendar"></i> ' . get_the_time('F j, Y') . '</span>';
                }
            }
        } else {
            echo '<span class="post_date date updated"><i class="fa fa-calendar"></i> ' . get_the_time('F j, Y') . '</span>';
        }

        // Comments counter
        if (isset($secretlab['show_comments_count'])) {
            if ($secretlab['show_comments_count'] == 1) {
                if (comments_open(get_the_ID())) {
                    echo '<span class="comments-link"><i class="fa fa-comments"></i> ';
                    comments_popup_link(esc_html__('Leave a comment', 'the-guard'), esc_html__('1 Comment', 'the-guard'), esc_html__('% Comments', 'the-guard'));
                    echo '</span>';
                }
            }
        } else {
            echo '<span class="comments-link"><i class="fa fa-comments"></i> ';
            comments_popup_link(esc_html__('Leave a comment', 'the-guard'), esc_html__('1 Comment', 'the-guard'), esc_html__('% Comments', 'the-guard'));
            echo '</span>';
        }
    }
endif;

/**
 * Print HTML with meta information for current post: categories, comments counter, author, and date.
 *
 * Create your own theguard_entry_meta() to override in a child theme.
 *
 */
if ( ! function_exists( 'theguard_entry_meta_short' ) ) :

    function theguard_entry_meta_short() {
        global $secretlab;


        // Post author
        if (isset($secretlab['show_post_author'])) {
            if ($secretlab['show_post_author'] == 1) {
                if ('post' == get_post_type()) {
                    printf('<span class="author vcard"><i class="fa fa-user"></i> <a class="url fn n theauthor" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
                        esc_url(get_author_posts_url(get_the_author_meta('ID'))),
                        esc_attr(sprintf(esc_html__('View all posts by %s', 'the-guard'), get_the_author())),
                        get_the_author()
                    );
                }
            }
        } else {
            printf('<span class="author vcard"><i class="fa fa-user"></i> <a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
                esc_url(get_author_posts_url(get_the_author_meta('ID'))),
                esc_attr(sprintf(esc_html__('View all posts by %s', 'the-guard'), get_the_author())),
                get_the_author()
            );
        }

        //Post data

        if (isset($secretlab['show_post_date'])) {
            if ($secretlab['show_post_date'] == 1) {
                if (isset($secretlab['blog-columns'])) {
                    $sl_blog_columns = $secretlab['blog-columns'];
                    $sl_blog_sidebars = $secretlab['blog-sidebar-layout'];
                    if (!is_single()) {
                        if ($sl_blog_columns == 4 and $sl_blog_sidebars == 1) {
                            echo '<span class="date updated"><i class="fa fa-calendar"></i> <a href="';
                            the_permalink();
                            echo '"">' . get_the_time('M j, Y') . '</a></span>';
                        } else {
                            echo '<span class="date updated"><i class="fa fa-calendar"></i> <a href="';
                            the_permalink();
                            echo '"">' . get_the_time('F j, Y') . '</a></span>';
                        }
                    }
                }

            }
        } else {
            if (!is_single()) {
                echo '<span class="date updated"><i class="fa fa-calendar"></i> <a href="';
                the_permalink();
                echo '"">' . get_the_time('F j, Y') . '</a></span>';
            }
        }

        // Comments counter

        if (isset($secretlab['show_comments_count'])) {
            if ($secretlab['show_comments_count'] == 1) {
                if (comments_open(get_the_ID())) {
                    echo '<span class="comments-link"><i class="fa fa-comments"></i> ';

                    if (isset($secretlab['blog-columns'])) {
                        $sl_blog_columns = $secretlab['blog-columns'];
                        $sl_blog_sidebars = $secretlab['blog-sidebar-layout'];
                        if (!is_single()) {
                            if ($sl_blog_columns == 3 and $sl_blog_sidebars == 1) {
                                echo wp_count_comments(get_the_ID())->approved;
                            } else {
                                comments_popup_link(esc_html__('0 Comments', 'the-guard'), esc_html__('1 Comment', 'the-guard'), esc_html__('% Comments', 'the-guard'));
                            }
                        }
                    }
                    echo '</span>';
                }
            }
        } else {
            if (!is_single()) {
                echo '<span class="comments-link"><i class="fa fa-comments"></i> ';
                comments_number(esc_html__('0 Comments', 'the-guard'), esc_html__('1 Comment', 'the-guard'), esc_html__('% Comments', 'the-guard'));
                echo '</span>';
            }
        }
    }
endif;

/**
 * Display navigation to next/previous post when applicable.
 *
 */
if ( ! function_exists( 'theguard_post_nav' ) ) :

    function theguard_post_nav() {
        global $post;

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

        if ( ! $next && ! $previous )
            return;
        ?>
        <nav class="navigation post-navigation" role="navigation">
            <div class="nav-links clearfix">

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

            </div><!-- .nav-links -->
        </nav><!-- .navigation -->
        <?php
    }
endif;

/* Prev & Next Post Narrow Icons */
if ( ! function_exists( 'theguard_post_navicon' ) ) :
    /**
     * Display navigation to next/previous post when applicable.
     *
     */
    function theguard_post_navicon() {
        global $post;

        // Don't print empty markup if there's nowhere to navigate.
        $iprevious = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
        $inext     = get_adjacent_post( false, '', false );

        if ( ! $inext && ! $iprevious )
            return;
        ?>
        <div class="post-navigation-icon" role="navigation">
            <?php next_post_link( '%link', '<span class="icon-arrow-left22"></span>', TRUE ); ?>
            <?php previous_post_link( '%link', '<span class="icon-arrow-right22"></span>', TRUE ); ?>
        </div>
        <?php
    }
endif;

// Display of CSS class, for column option of tag, category, archive and index page
function theguard_number_of_columns() {
    global $secretlab;
    if (isset($secretlab['blog-columns'])) {
        $sl_blog_sidebars = $secretlab['blog-sidebar-layout'];
        $sl_sidebars = $secretlab['sidebar-layout'];
        $sl_blog_columns = $secretlab['blog-columns'];

        if ( ! is_single()) {
         if ( $sl_blog_columns == 2 and $sl_blog_sidebars == 1 ) {
                echo ' blog2columnpage';
            } else {
             if ( $sl_blog_columns == 3 and $sl_blog_sidebars == 1 ) {
                 echo ' blog3columnpage';
             } else {
                 if ( $sl_blog_sidebars == 3 or $sl_blog_sidebars == 4 or $sl_sidebars == 3 or $sl_sidebars ==4 ) {
                     echo ' onecolumnnsb';
                 } else {
                     echo ' onecolumn';
                 }

             }
         }
        }
    }
}

// Blog 2 column format vesrion 2
function theguard_2_columns_v2() {
    global $secretlab;
    if (isset($secretlab['blog-columns'])) {
        $sl_blog_columns = $secretlab['blog-columns'];
        $sl_blog_sidebars = $secretlab['blog-sidebar-layout'];
        if ( ! is_single()) {
            if ( $sl_blog_columns == 4 and $sl_blog_sidebars == 1) {
                echo '<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 digital-format">';
            }
        }
    }
}
// Blog 2 column format vesrion 2 closing tag
function theguard_2_columns_v2_end() {
    global $secretlab;
    if (isset($secretlab['blog-columns'])) {

        $sl_blog_columns = $secretlab['blog-columns'];
        $sl_blog_sidebars = $secretlab['blog-sidebar-layout'];
        if ( ! is_single()) {
            if ( $sl_blog_columns == 4 and $sl_blog_sidebars == 1) {
                echo '</div>';
            }
        }
    }
}
// Blog 2 column format vesrion 2 closing tag
function theguard_2_columns_v2_thumb() {
    global $secretlab;
    if (isset($secretlab['blog-columns'])) {
        $sl_blog_columns = $secretlab['blog-columns'];
        $sl_blog_sidebars = $secretlab['blog-sidebar-layout'];
        if ( ! is_single()) {
            if ( $sl_blog_columns == 4 and $sl_blog_sidebars == 1) {
                the_post_thumbnail('theguard_smalldigital');
            } else {
                the_post_thumbnail();
            }
        }
    } else {
        the_post_thumbnail();
    }
}
// Tags for blog post
function theguard_tags() {
    global $secretlab;
    if (isset($secretlab['show_post_tags'])) {
        $sl_show_post_tags = $secretlab['show_post_tags'];
        if ($sl_show_post_tags == 1) {
            $tag_list = get_the_tag_list('', ' ');
            if ($tag_list) {
                echo '<span class="tags-links"><b>' . esc_html__('Tags', 'the-guard') . ':</b> ' . $tag_list . '</span>';
            }
        }
    } else {
        $tag_list = get_the_tag_list('', ' ');
        if ($tag_list) {
            echo '<span class="tags-links"><b>' . esc_html__('Tags', 'the-guard') . ':</b> ' . $tag_list . '</span>';
        }
    }
}
// Comment layout 
function sell_comment($comment, $args, $depth){
    $c = $GLOBALS['comment'];
	$GLOBALS['comment'] = $comment;
	echo '<li ';
	comment_class();
	echo 'id="li-comment-';
	comment_ID();
	echo '">';
	echo '<div id="comment-';
	comment_ID();
	echo '">';
	echo '<footer class="comment-meta">';
	echo '<div class="comment-author vcard">';
	echo '<div class="wrapper" data-anim="base wrapper">';
	echo get_avatar( $comment, $args['avatar_size'] );
	echo '<div class="circle" data-anim="base left"></div>
							<div class="circle" data-anim="base right"></div>
						</div>';


	printf('<b class="fn">%s</b> <span class="says">'.esc_html__( 'says', 'the-guard' ).'</span>', get_comment_author_link( $comment ));
	echo '</div>';
	if ($comment->comment_approved == '0') {
		echo '<em>'.esc_html__( 'Your comment is awaiting moderation.', 'the-guard' ).'</em><br />';
	}

	echo '<div class="comment-metadata"><a href="';
	echo htmlspecialchars( get_comment_link( $comment->comment_ID ) );
	echo '">';
	printf(esc_html__('%1$s at %2$s', 'the-guard'), get_comment_date(), get_comment_time());
	echo '</a>';
	edit_comment_link(esc_html__('(Edit)', 'the-guard'),'  ','');
	echo '</div>
	</footer>';
	echo '<div class="comment-content"';
	comment_text();
	echo '</div>';
	echo '<div class="reply">';
	comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth'])));
	echo '</div>
</div>';
    $GLOBALS['comment'] = $c;
}



?>
