<?php

/**
 * Liting the team/trainer details 
 * @param : int $pageId default is null
 * @param : boolean $isCustomizer default is false, if set to true will get the data stored with customizer
 * @param : int $i default is null, it will used as a iteration for data with customizer, this will be used only if the $isCustomizer is set to true.
 * @return: Text $text
 */
function teamShortCode($pageId = null, $isCustomizer = false, $i = null) {

    ob_start();

    $args = array('post_type' => 'lz_fitness_teams');
    if (!empty($pageId)) {
        $args['page_id'] = absint($pageId);
    }
    $colCls = '';
    // if($isCustomizer == true){
    $cols = get_theme_mod('lz_fitness_team_npp_count', 3);
    $cols++;
    switch($cols){
        case 1:
            $colCls = 'col-md-12 col-sm-12 col-xs-12';
            break;
            case 2:
            $colCls = 'col-md-6 col-sm-6 col-xs-6';
            break;
            case 3:
            $colCls = 'col-md-4 col-sm-6 col-xs-6';
            break;
            case 4:
            $colCls = 'col-md-3 col-sm-6 col-xs-6';
            break;
            default: 
            $colCls = 'col-md-4 col-sm-6 col-xs-6';
            break;
            }
                
    // }
    $text = '';
    $query = new WP_Query($args);
    if ($query->have_posts()):
        $postN = 0;

        while ($query->have_posts()) : $query->the_post();
            $lz_fitness_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'total-team-thumb');
            if ($isCustomizer === true) {
                $lz_fitness_team_designation = get_theme_mod('lz_fitness_team_designation' . $i);
                $lz_fitness_team_facebook = get_theme_mod('lz_fitness_team_facebook' . $i);
                $lz_fitness_team_twitter = get_theme_mod('lz_fitness_team_twitter' . $i);
                $lz_fitness_team_google_plus = get_theme_mod('lz_fitness_team_google_plus' . $i);
            } else {
                $lz_fitness_team_facebook = '';
                $lz_fitness_team_twitter = '';
                $lz_fitness_team_google_plus = '';
            }

            $post = get_post();
            //Social media urls
            $teamFacebook = get_post_meta($post->ID, 'teamFacebook', false);
            $lz_fitness_team_facebook = !empty($teamFacebook[0]) ? $teamFacebook[0] : '';
            $teamTwitter = get_post_meta($post->ID, 'teamTwitter', false);
            $lz_fitness_team_twitter = !empty($teamTwitter[0]) ? $teamTwitter[0] : '';
            $teamGPlus = get_post_meta($post->ID, 'teamGPlus', false);
            $lz_fitness_team_google_plus = !empty($teamGPlus[0]) ? $teamGPlus[0] : '';
            //designation
            $designation = get_post_meta($post->ID, 'designation', false);
            $lz_fitness_team_designation = !empty($designation[0]) ? $designation[0] : '';

            if (($postN % 4) == 0 && $isCustomizer == false) {
                ?>
                <div class="clearfix paddingBot20"></div>
            </div>
            <div class="row">
                <?php
            }
            ++$postN;
            ?>
            <div class="<?php echo $colCls; ?>">
                <div class="ht-team-member text-center">
                    <div class="ht-team-member-image">
                        <?php
                        if (has_post_thumbnail()) {
                            $image_url = $lz_fitness_image[0];
                        } else {
                            $image_url = get_template_directory_uri() . '/images/team-thumb.png';
                        }
                        ?>                  
                        <img src="<?php echo esc_url($image_url); ?>" alt="<?php the_title(); ?>" />
                        </div>
                        <div class="ht-title-wrap">
                            <h6 class="member-name"><?php the_title(); ?></h6>                        
                      <!--   <div class class="ht-team-member-excerpt"> -->
                            <div class="ht-team-member-excerpt-wrap">
                                <div class="ht-team-member-span">
                                    <!-- <h6><?php //the_title(); ?></h6> -->
                                    <?php if (!empty($lz_fitness_team_designation)) { ?>
                                    <div class="ht-team-designation"><?php //echo esc_html($lz_fitness_team_designation); ?></div>
                                    <?php
                                }
                                         if(has_excerpt()){
                                          echo get_the_excerpt();
                                         }else{
                                          echo lz_fitness_excerpt( get_the_content() , 100 );
                                         } 
                                ?>
                                <!-- <div class="ht-team-detail"><?php _e('Detail', 'total') ?></div> -->
                            </div>
                        </div>
                        <?php if ($lz_fitness_team_facebook || $lz_fitness_team_twitter || $lz_fitness_team_google_plus) { ?>
                        <div class="team-member-designation"><?php echo esc_html($lz_fitness_team_designation); ?></div>
                        <div class="ht-team-social-id">
                            <?php if ($lz_fitness_team_facebook) { ?>
                            <a target="_blank" href="<?php echo esc_url($lz_fitness_team_facebook) ?>"><i class="fa fa-facebook"></i></a>
                            <?php } ?>
                            <?php if ($lz_fitness_team_twitter) { ?>
                            <a target="_blank" href="<?php echo esc_url($lz_fitness_team_twitter) ?>"><i class="fa fa-twitter"></i></a>
                            <?php } ?>
                            <?php if ($lz_fitness_team_google_plus) { ?>
                            <a target="_blank" href="<?php echo esc_url($lz_fitness_team_google_plus) ?>"><i class="fa fa-google-plus"></i></a>
                            <?php } ?>
                        </div>                
                        <?php } ?>
                   <!--  </div> -->
                </div>                 
                <div class="clearfix"></div>          
            </div>
        </div>
        <?php
    endwhile;
    $text = ob_get_contents();
    ob_clean();
endif;
wp_reset_postdata();
return $text;
}

    /**
     * Use for the show the testimonials at home page and in testimonial page with shortcode
     * @param int $pageId default is null the id of a post
     * @param boolean $isCustomizer default is false if set to true it mean the output is set for the home page
     * @param int $i default null
     * @param boolean $showStaticVals default is false
     * @return void
     * @author Parag Chaure <parag.radical@outlook.com>
     * */
   function testimonialShortCode($pageId = null, $isCustomizer = false, $i = 0, $showStaticVals = false, $totalItems=0) {
    global $query;
    $args = array('post_type' => 'lz_fitness_testimoni');
    if (!empty($pageId)) {
        $args['page_id'] = absint($pageId);
    } else {
        $args['paged'] = max(1, get_query_var('paged'));
    }
    $args['posts_per_page'] = (!empty($args['posts_per_page'])) ? $args['posts_per_page'] : -1;
    $i = !empty($i) && is_numeric($i) ? $i : 0;
    $text = '';
    $query = new WP_Query($args);
    // print_r($query);
    if ($query->have_posts()):
        $cssCls = ($isCustomizer == false) ? 'row' : 'col-sm-10 col-sm-offset-1';

        ob_start();
        while ($query->have_posts()) : $query->the_post();
            $post = get_post();
            $lz_fitness_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'total-team-thumb');
           // echo"(($i == 0) || ($i%2)==0)".__LINE__;
            if(($i == 0) || ($i%1)==0){
                ?>
                <div class="item <?php if ($i == 0) { ?>active<?php } ?>">
                    <div class="row">
                        <?php
                    }
                    ?>

                    <div class="<?php echo $cssCls; ?>">
                        <?php if ($isCustomizer == false) { ?>
                        <div class="row page-testimonial-box">
                            <div class="col-md-3 col-md-offset-1 team-thumb">
                                <img src="<?php echo (!empty($lz_fitness_image[0])) ? $lz_fitness_image[0] : get_template_directory_uri() . '/images/team-thumb.png' ?>" class="img-responsive" alt="<?php the_title(); ?>" />
                           </div>
                           <div class="col-md-8 testimonial-content">
                            <?php } ?>
                            <h6 class="secondry-text"><?php the_title(); ?> <span> (<?php
                                    $name2 = get_post_meta($post->ID, 'testimonial_Sub_Title', false);
                                    echo (!empty($name2[0])) ? $name2[0] : '';
                                ?>) </span></h6>
                           <!--<div class="text-designation">
                                <?php
                                    $name2 = get_post_meta($post->ID, 'testimonial_Sub_Title', false);
                                    echo (!empty($name2[0])) ? $name2[0] : '';
                                ?>
                                </div> -->                       
                                <p><?php
                                if (has_excerpt()) {
                                    echo get_the_excerpt();
                                } else {
                                    echo lz_fitness_excerpt(get_the_content(), 250);
                                }
                                ?>
                            </p>

                            <?php if ($isCustomizer == false) { ?>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <?php } ?>
                </div>
                <?php
            //echo"\n($i+1)%2 == 0 || $totalItems == ($i+1)";
                if(($i+1)%1 == 0 || $totalItems == ($i+1)){ ?>
            </div>
        </div>
        <?php
    }
    ?>

    <?php
endwhile;
$text = ob_get_contents();
ob_clean();
ob_end_flush();
endif;
wp_reset_postdata();
    // echo $text;
return $text;
}

    /**
     * Use for the show the gallery at home page and in the page where user add this the shortcode
     * @return void
     * @author Parag Chaure <parag.radical@outlook.com>
     * */
    function galleryShortcode($args = null) {
        $args['post_type'] = 'lz_fitness_gallary';
        $args['order'] = 'ASC';
        // print_r($args);
        $gallaryHtml = '';
        $args['posts_per_page'] = (!empty($args['posts_per_page'])) ? $args['posts_per_page'] : -1;
        $class = !empty($args['ishome']) && $args['ishome'] == true ? 'gallery' : 'portfolio';
        $class = 'gallery';
        ob_start();
        ?>
        <div class="ht-<?php echo $class; ?>-post-wrap <?php if (!empty($args['ishome']) && $args['ishome'] == true) {
                echo 'container';
            } ?>">
            <div class="ht-<?php echo $class; ?>-posts ht-clearfix">
                <?php
                if (!empty($pageId)) {
                    $args['page_id'] = absint($pageId);
                }
                $text = '';
                $query = new WP_Query($args);
                // echo '<pre/>';print_r($query);
                if ($query->have_posts()) {
                    while ($query->have_posts()) : $query->the_post();
                        $pageLink = '';
                        $slider_btn_link = get_post_meta($query->ID, 'slider_btn_link', false);
                        if (!empty($slider_btn_link) && is_array($slider_btn_link)) {
                            $pageLink = esc_url(get_permalink($slider_btn_link[0]));
                        }
                        if (has_post_thumbnail()) {
                            $image_url = get_template_directory_uri() . '/images/portfolio-small-blank.png';
                            $total_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'total-portfolio-thumb');
                            $total_image_large = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
                        } else {
                            $image_url = get_template_directory_uri() . '/images/portfolio-small.png';
                            $total_image = "";
                        }
                        // echo '<pre/>';print_r($total_image);
                        ?>
                        <div class="ht-<?php echo $class; ?>">
                            <div class="ht-<?php echo $class; ?>-outer-wrap">
                                <div class="ht-<?php echo $class; ?>-wrap" style="background-image: url(<?php echo esc_url($total_image[0]) ?>);">
                                    <img src="<?php echo esc_url($total_image[0]); ?>" alt="<?php esc_attr(get_the_title()); ?>">
                                    <a class="ht-portfolio-image" data-lightbox-gallery="gallery1" href="<?php echo esc_url($total_image[0]) ?>"><i class="fa fa-search"></i></a>
                                    <div class="ht-portfolio-caption">
                                        <h5><?php echo esc_attr(get_the_title()) ?></h5>
                                        <?php if (has_post_thumbnail()) { ?>
                                            <a class="ht-portfolio-image" data-lightbox-gallery="gallery1" href="<?php echo esc_url($total_image[0]) ?>"><i class="fa fa-search"></i></a>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php
                    endwhile;
                    wp_reset_postdata();
                } else {
                    $gallaryImage = array(
                        '/images/facility.jpg',
                        '/images/sleep.jpg',
                        '/images/man-461195_1280.jpg',
                        '/images/wellness-285588_1280.jpg',
                        '/images/about.jpg',
                        '/images/relax-1690338_1920.jpg',
                        // '/images/man-461195_1280.jpg',
                    );
                    for ($i = 0; $i < count($gallaryImage); $i++) {
                        ?>
                        <div class="ht-<?php echo $class; ?>">
                            <div class="ht-<?php echo $class; ?>-outer-wrap">
                                <div class="ht-<?php echo $class; ?>-wrap" style="background-image: url(<?php echo get_template_directory_uri() . $gallaryImage[$i]; ?>);">
                                    <img src="<?php echo get_template_directory_uri() . $gallaryImage[$i]; ?>" alt="Gallary <?php echo $i + 1; ?>">
                                    <a class="ht-portfolio-image" data-lightbox-gallery="gallery1" href="<?php echo get_template_directory_uri() . $gallaryImage[$i]; ?>"><i class="fa fa-search"></i></a>
                                    <div class="ht-portfolio-caption">
                                        <h5>Gallary <?php echo $i + 1; ?></h5>
                                        <a class="ht-portfolio-image" data-lightbox-gallery="gallery1" href="<?php echo get_template_directory_uri() . $gallaryImage[$i]; ?>"><i class="fa fa-search"></i></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php }
                }
                ?>
            </div>
        </div>
        <?php
        $gallaryHtml = ob_get_contents();
        ob_clean();
        ob_end_flush();
        return $gallaryHtml;
    }

    /**
     * Use for the show the testimonials at home page and in testimonial page with shortcode
     * @param int $pageId default is null the id of a post
     * @param boolean $isCustomizer default is false if set to true it mean the output is set for the home page
     * @param int $i default null
     * @param boolean $showStaticVals default is false
     * @return void
     * @author Parag Chaure <parag.radical@outlook.com>
     * */
   function pricingShortcode() {
        ob_start();
        $cols = get_theme_mod('lz_fitness_pricing_npp_count', 2);
        $cols++;
        switch ($cols) {
            case 1:
            $colCls = 'col-md-12 col-sm-12';
            break;
            case 2:
            $colCls = 'col-md-6 col-sm-6';
            break;
            case 3:
            $colCls = 'col-md-4 col-sm-4';
            break;
            default:
            $colCls = 'col-md-3 col-sm-6';
            break;
        } 
        echo '<div id="pricing-page">';
        $showStatic = true;
        for ($i = 1; $i <= $cols; $i++) {
            $PlanPageId = get_theme_mod('lz_fitness_pricing_plan_page_' . $i);
            $planTitle  = get_theme_mod('lz_fitness_pricing_plan_name_' . $i, 'Plan');
            $planPrice  = get_theme_mod('lz_fitness_pricing_plan_price_' . $i,'9.99');
            $planContent= get_theme_mod('lz_fitness_pricing_plan_content_' . $i, '<ul><li>Service in Plan</li><li>Service in Plan </li><li>Service in Plan </li><li>Service in Plan</li><li>Service in Plan</li><li>Service in Plan </li></ul>');

            $link = get_theme_mod('pricing_plan_url'.$i);
            $url = get_theme_mod('pricing_plan_url_'.$i, '#');

            if ($PlanPageId || $planTitle || $planPrice || $planContent || $url) {
                $showStatic = false;
                ?>
                <div class="<?php echo $colCls; ?>">
                    <div class="ht-plan-block text-center">
                        <div class="ht-princing-icon"><?php echo esc_attr($planTitle); ?></div>
                        <div class="plan-amount"><sub>$</sub><?php echo esc_html($planPrice); ?></div>
                        <div class="ht-princing-excerpt">
                            <?php echo nl2br($planContent); ?>
                        </div>
                        <div class="ht-princing-link">
                           <a href="<?php echo esc_url(!empty($url)?$url:'#');?>"><?php _e('Join Now', 'lz-fitness-premium'); ?></a>
                        </div>
                    </div>
                </div>
                <?php
            }
        }
        if ($showStatic === true) {
            for ($i = 1; $i <= $cols; $i++) {
                $link = get_theme_mod('pricing_plan_url'.$i);
                 $url = get_theme_mod('pricing_plan_url_'.$i, '#');

                ?>
                <div class="<?php echo $colCls; ?>">
                    <div class="ht-plan-block text-center">
                        <div class="ht-princing-icon">Plan</div>
                        <div class="plan-amount"><sub>$</sub>9.99</div>
                        <div class="ht-princing-excerpt">
                            <?php echo nl2br("<li>Service12 in Plan</li><li>Service in Plan </li><li>Service in Plan </li><li>Service in Plan</li><li>Service in Plan</li><li>Service in Plan </li></ul>"); ?>
                        </div>
                        <div class="ht-princing-link">
                            <a href="<?php echo esc_url(!empty($url)?$url:'#');?>"><?php _e('Join Now', 'lz-fitness-premium'); ?></a>
                        </div>
                    </div>
                </div>
                <?php
            }
            echo '<div class="clearfix"></div>';
            echo '</div>';
        }

        $pricingHtml = ob_get_contents();
        // echo $pricingHtml;
        ob_flush();
        ob_clean();
    }

   