<?php
/**
 * Template Name: Home Page Template
 *
 * @package WordPress
 * @subpackage Probit
 * @since Probit 1.0
 *
 */
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}
get_header();
?>
<div id="content" role="main">
    <div class="container">
        <div class="row">
            <div class="four_block_wrap">
                <?php
                // Box 1 Started
                $box1Icon_val = $box1Icon = $box1Title_val = $box1Title = '';
                $box1Icon_val = esc_attr(get_theme_mod('block1icon'));
                $box1Icon = trim($box1Icon_val);
                $box1Title_val = esc_attr(get_theme_mod('home_below_slider_box1_title'));
                $box1Title = trim($box1Title_val);
                if (!empty($box1Icon) && !empty($box1Title)) {
                    ?>
                    <div class="col-xs-6 col-sm-3 col-md-3 text-center single_block">
                        <a <?php
                        if (get_theme_mod('home_below_slider_box1_link_open')) {
                            echo 'target="_blank"';
                        }
                        ?> title="<?php echo esc_attr(get_theme_mod('home_below_slider_box1_title')); ?>" href="<?php
                            if (get_theme_mod('home_below_slider_box1_link') == "#") {
                                echo esc_attr(get_theme_mod('home_below_slider_box1_link'));
                            } else {
                                $link1_val = esc_attr(get_theme_mod('home_below_slider_box1_link'));
                                echo $link1 = preg_match('#^https?://#i', $link1_val) === 1 ? $link1_val : "http://" . $link1_val;
                            }
                            ?>">
                                <?php
                                if (get_theme_mod('block1icon')) {
                                    ?>
                                <i class="<?php echo esc_attr(get_theme_mod('block1icon')); ?>"></i>
                                <?php
                            }
                            ?>
                            <h4><?php echo esc_attr(get_theme_mod('home_below_slider_box1_title')); ?></h4>
                        </a>
                    </div>
                    <?php
                }

                // Box 2 Started
                $box2Icon_val = $box2Icon = $box2Title_val = $box2Title = '';
                $box2Icon_val = esc_attr(get_theme_mod('block2icon'));
                $box2Icon = trim($box2Icon_val);
                $box2Title_val = esc_attr(get_theme_mod('home_below_slider_box2_title'));
                $box2Title = trim($box2Title_val);
                if (!empty($box2Icon) && !empty($box2Title)) {
                    ?>
                    <div class="col-xs-6 col-sm-3 col-md-3 text-center single_block">
                        <a <?php
                        if (get_theme_mod('home_below_slider_box2_link_open')) {
                            echo 'target="_blank"';
                        }
                        ?> title="<?php echo esc_attr(get_theme_mod('home_below_slider_box2_title')); ?>" href="<?php
                            if (get_theme_mod('home_below_slider_box2_link') == "#") {
                                echo esc_attr(get_theme_mod('home_below_slider_box2_link'));
                            } else {
                                $link2_val = esc_attr(get_theme_mod('home_below_slider_box2_link'));
                                echo $link2 = preg_match('#^https?://#i', $link2_val) === 1 ? $link2_val : "http://" . $link2_val;
                            }
                            ?>">
                                <?php
                                if (get_theme_mod('block2icon')) {
                                    ?>
                                <i class="<?php echo esc_attr(get_theme_mod('block2icon')); ?>"></i>
                                <?php
                            }
                            ?>
                            <h4><?php echo esc_attr(get_theme_mod('home_below_slider_box2_title')); ?></h4>
                        </a>
                    </div>
                    <?php
                }

                // Box 3 Started
                $box3Icon_val = $box3Icon = $box3Title_val = $box3Title = '';
                $box3Icon_val = esc_attr(get_theme_mod('block3icon'));
                $box3Icon = trim($box3Icon_val);
                $box3Title_val = esc_attr(get_theme_mod('home_below_slider_box3_title'));
                $box3Title = trim($box3Title_val);
                if (!empty($box3Icon) && !empty($box3Title)) {
                    ?>
                    <div class="col-xs-6 col-sm-3 col-md-3 text-center single_block">
                        <a <?php
                        if (get_theme_mod('home_below_slider_box3_link_open')) {
                            echo 'target="_blank"';
                        }
                        ?> title="<?php echo esc_attr(get_theme_mod('home_below_slider_box3_title')); ?>" href="<?php
                            if (get_theme_mod('home_below_slider_box3_link') == "#") {
                                echo esc_attr(get_theme_mod('home_below_slider_box3_link'));
                            } else {
                                $link3_val = esc_attr(get_theme_mod('home_below_slider_box3_link'));
                                echo $link3 = preg_match('#^https?://#i', $link3_val) === 1 ? $link3_val : "http://" . $link3_val;
                            }
                            ?>">
                                <?php
                                if (get_theme_mod('block3icon')) {
                                    ?>
                                <i class="<?php echo esc_attr(get_theme_mod('block3icon')); ?>"></i>
                                <?php
                            }
                            ?>
                            <h4><?php echo esc_attr(get_theme_mod('home_below_slider_box3_title')); ?></h4>
                        </a>
                    </div>
                    <?php
                }

                // Box 4 Started
                $box4Icon_val = $box4Icon = $box4Title_val = $box4Title = '';
                $box4Icon_val = esc_attr(get_theme_mod('block4icon'));
                $box4Icon = trim($box4Icon_val);
                $box4Title_val = esc_attr(get_theme_mod('home_below_slider_box4_title'));
                $box4Title = trim($box4Title_val);
                if (!empty($box4Icon) && !empty($box4Title)) {
                    ?>
                    <div class="col-xs-6 col-sm-3 col-md-3 text-center single_block">
                        <a <?php
                        if (get_theme_mod('home_below_slider_box4_link_open')) {
                            echo 'target="_blank"';
                        }
                        ?> title="<?php echo esc_attr(get_theme_mod('home_below_slider_box4_title')); ?>" href="<?php
                            if (get_theme_mod('home_below_slider_box4_link') == "#") {
                                echo esc_attr(get_theme_mod('home_below_slider_box4_link'));
                            } else {
                                $link4_val = esc_attr(get_theme_mod('home_below_slider_box4_link'));
                                echo $link4 = preg_match('#^https?://#i', $link4_val) === 1 ? $link4_val : "http://" . $link4_val;
                            }
                            ?>">
                                <?php
                                if (get_theme_mod('block4icon')) {
                                    ?>
                                <i class="<?php echo esc_attr(get_theme_mod('block4icon')); ?>"></i>
                                <?php
                            }
                            ?>
                            <h4><?php echo esc_attr(get_theme_mod('home_below_slider_box4_title')); ?></h4>
                        </a>
                    </div>
                    <?php
                }
                ?>

            </div>
            <?php
            $port_cat = esc_attr(get_theme_mod('port_cat'));
            if ($port_cat != 0) {
                $cat_display_array = probit_get_subcat_ids($port_cat);
                $args = array('post_type' => 'post', 'order' => 'DESC', 'posts_per_page' => -1, 'category__in' => $cat_display_array);
                $loop = new WP_Query($args);
                if ($loop->have_posts()) {
                    ?>            
                    <div class="col-xs-12 portflio_wrapper">
                        <div class="title_heading">
                            <h2 class="text-center"><?php _e('Recent Project', 'probit'); ?></h2>
                            <span></span>
                        </div>
                        <div class="portflio_slider_div">
                            <div class="row">
                                <div class='' id='portfolio_slider'>
                                    <?php
                                    while ($loop->have_posts()) : $loop->the_post();
                                        ?>
                                        <div class="col-xs-12 col-sm-4 col-md-4 text-center portfolio_slider_single_home">
                                            <div class="grid_item portfolio_item postclass">
                                                <div class="imghoverclass">
                                                    <a class="kad_portfolio_link" title="Work Space" href="<?php the_permalink(); ?>">
                                                        <?php
                                                        if (has_post_thumbnail())
                                                            the_post_thumbnail('probit-portfolio-slider-img');
                                                        else
                                                            echo '<img alt="' . esc_attr(get_the_title()) . '" src="' . esc_url(get_template_directory_uri() . '/images/no_image_370.png') . '" />';
                                                        ?>
                                                    </a>
                                                </div>
                                                <a class="portfoliolink" href="<?php the_permalink(); ?>">
                                                    <div class="piteminfo">
                                                        <h5><?php the_title(); ?></h5>
                                                    </div>
                                                </a>
                                            </div>
                                        </div>
                                        <?php
                                    endwhile;
                                    ?>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <a id="prevport-portfolio" class="prev_carousel fa fa-chevron-left" href="#" style="display: block;"></a>
                            <a id="nextport-portfolio" class="next_carousel fa fa-chevron-right" href="#" style="display: block;"></a>
                        </div>
                    </div>
                    <?php
                }
            }
            ?>
            <div class="title_heading">
                <h2 class="text-center"><?php _e('Recent News', 'probit'); ?></h2>
                <span></span>
            </div>
            <div class="col-xs-12 blog_wrapper grid-layout">
                <?php
                wp_reset_postdata();
                $not_display_array = array();
                if ($port_cat != 0) {
                    $port_child_cat = get_categories(array('child_of' => $port_cat));
                    $not_display_array[] = $port_cat;
                    if (is_array($port_child_cat) && !empty($port_child_cat)) {
                        foreach ($port_child_cat as $port_child_cat_s) {
                            $not_display_array[] = $port_child_cat_s->term_id;
                        }
                    }
                }
                $team_cat = esc_attr(get_theme_mod('team_cat'));
                if ($team_cat != 0) {
                    $team_child_cat = get_categories(array('child_of' => $team_cat));
                    $not_display_array[] = $team_cat;
                    if (is_array($team_child_cat) && !empty($team_child_cat)) {
                        foreach ($team_child_cat as $team_child_cat_s) {
                            $not_display_array[] = $team_child_cat_s->term_id;
                        }
                    }
                }
                $testimonial_cat = esc_attr(get_theme_mod('testimonial_cat'));
                if ($testimonial_cat != 0) {
                    $testimonial_child_cat = get_categories(array('child_of' => $testimonial_cat));
                    $not_display_array[] = $testimonial_cat;
                    if (is_array($testimonial_child_cat) && !empty($testimonial_child_cat)) {
                        foreach ($testimonial_child_cat as $testimonial_child_cat_s) {
                            $not_display_array[] = $testimonial_child_cat_s->term_id;
                        }
                    }
                }
                $client_cat = esc_attr(get_theme_mod('client_cat'));
                if ($client_cat != 0) {
                    $client_child_cat = get_categories(array('child_of' => $client_cat));
                    $not_display_array[] = $client_cat;
                    if (is_array($client_child_cat) && !empty($client_child_cat)) {
                        foreach ($client_child_cat as $client_child_cat_s) {
                            $not_display_array[] = $client_child_cat_s->term_id;
                        }
                    }
                }

                $args = array('post_type' => 'post', 'post_status' => 'publish', 'order_by' => 'date', 'order' => 'DESC', 'posts_per_page' => 4, 'ignore_sticky_posts' => 1, 'category__not_in' => $not_display_array);
                $i = 0;
                $loop = new WP_Query($args);
                while ($loop->have_posts()) : $loop->the_post();
                    if ($i % 2 == 0) {
                        $class = 'padding_left_0';
                    } else {
                        $class = 'padding_right_0';
                    }
                    ?>
                    <div class="col-xs-12 col-sm-12 col-md-6 blog_section <?php
                    echo $class;
                    echo " loop-" . $i;
                    ?>">
                             <?php
                             if (has_post_thumbnail()) {
                                 $content_class = 'col-sm-8';
                             } else {
                                 $content_class = 'col-sm-12';
                             }
                             ?>
                        <div class="blog_div">
                            <?php if (has_post_thumbnail()) { ?>
                                <div class="blog_img col-xs-12 col-sm-4">
                                    <a href="<?php echo the_permalink(); ?>">
                                        <?php
                                        if (has_post_thumbnail())
                                            the_post_thumbnail('probit-blog-img');
                                        else
                                            echo '<img alt="' . esc_attr(get_the_title()) . '" src="' . esc_url(get_template_directory_uri() . '/images/no_image_270.png') . '" />';

                                        if (is_sticky()) :
                                            ?>
                                            <div class="featured-post-two-column">
                                                <?php _e('Featured post', 'probit'); ?>
                                            </div>
                                            <?php
                                        endif;
                                        ?>
                                    </a>
                                </div><?php
                            }
                            ?>
                            <div class="blog_content col-xs-12 <?php echo $content_class; ?> padding_right_0">
                                <div class="blog_title pull-left">
                                    <h3 class="text-capitalize">
                                        <a href="<?php echo the_permalink(); ?>"><?php the_title(); ?></a>
                                    </h3>
                                    <div class="postmeta">
                                        <div class="postdate headerfont" itemprop="datePublished">
                                            <span class="postday"><?php echo esc_html(get_the_date("d")); ?></span>
                                            <?php echo esc_html(get_the_date("M Y")); ?>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xs-12 padding_left_0 text-justify">
                                    <p><?php echo wp_trim_words(get_the_excerpt(), 20, ' &hellip;'); ?></p>
                                </div>
                            </div>                            
                            <footer class="blog_footer text-capitalize blog-footer-two-block">
                                <span><i class="fa fa-user"></i><?php echo esc_attr(get_the_author()); ?></span>
                                <?php
                                if (comments_open()) :
                                    comments_popup_link('<span class="leave-reply"><i class="fa fa-comment"></i>0</span>', '<span class="leave-reply"><i class="fa fa-comment"></i>1</span>', '<span class="leave-reply"><i class="fa fa-comment"></i>%</span>');
                                endif; // comments_open()
                                if ('post' == get_post_type()) {
                                    // Translators: used between list items, there is a space after the comma.
                                    $categories_list = get_the_category_list(', ');
                                    $category_pieces = explode(", ", $categories_list);

                                    if ($categories_list != "") {
                                        ?>
                                        <span class="probit-two-blog"><i class="fa fa-bookmark"></i><?php echo $category_pieces[0]; ?></span>
                                        <?php
                                    }


                                    // Translators: used between list items, there is a space after the comma.
                                    $tag_list = get_the_tag_list('', ', ');
                                    $tag_pieces = explode(", ", $tag_list);

                                    if ($tag_list != "") {
                                        ?>
                                        <span class="probit-two-blog"><i class="fa fa-tag"></i><?php echo $tag_pieces[0]; ?></span>
                                        <?php
                                    }
                                }
                                ?>
                                <div class="read_more">
                                    <a href="<?php the_permalink(); ?>" class="text-capitalize"><i class="fa fa-plus"></i><?php _e('Read More', 'probit'); ?></a>
                                </div>
                            </footer>
                        </div>
                    </div>
                    <?php
                    $i++;
                endwhile;
                wp_reset_postdata();
                ?>
            </div>
        </div><!-- .row -->
    </div><!-- .container -->
    <div class="col-xs-12 portflio_wrapper">
        <div class='row'>
            <?php echo probit_testimonialDisplayfunction(); ?>
        </div>
    </div>

    <div class="container">
        <div class="row">
            <?php echo probit_ourClientDisplayfunction(); ?>
        </div><!-- .row -->
    </div><!-- .container -->
    <div class="container-fluid" style="padding: 0;">
        <?php echo probit_ourTeamShortcodeFunction(); ?>
    </div>
</div><!-- #content -->

<?php get_footer(); ?>
