<?php


/**
 * 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 string
 * @author Luzuk <support@luzuk.com>
 * */
function testimonialShortCode($pageId = null, $isCustomizer = false, $i = null) {

    ob_start();

    $args = array('post_type' => 'our-testimonial');
    if (!empty($pageId)) {
        $args['page_id'] = absint($pageId);
    }
    $colCls = '';
    // if($isCustomizer == true){
    $cols = get_theme_mod('test_npp_count', 5);
    $cols++;
    switch($cols){
        
    }
    $icons = array(1=>'heart', 2=>'star', 3=>'flash', 4=>'bell',5=>'heart', 6=>'star', 7=>'flash', 8=>'bell');     
    // }
    $text = '';
    $query = new WP_Query($args);
    if ($query->have_posts()):
        $postN = 0;

        while ($query->have_posts()) : $query->the_post();
            $luzuk_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'total-team-thumb');
              if ($isCustomizer === true) {
                    $testimonial_area_designation = get_theme_mod('testimonial_area_designation' . $i);
                } else {
                    $testimonial_area_designation = '';
                }
            $post = get_post();

                            //designation
        $designation = get_post_meta($post->ID, 'designation', false);
        $testimonial_area_designation = !empty($designation[0]) ? $designation[0] : '';

            ?>
        <div class="item innertest-item">
            <div testimonials-match-height="groupName" class="ts-area-single">
                <div class="ts-circle one"></div>
                <div class="col-md-3 col-sm-2 col-xs-3 pd-0">
                    <div class="ts-area-thumb">
                        <img src="<?php echo (!empty($luzuk_image[0])) ? $luzuk_image[0] : get_template_directory_uri() . '/images/team-thumb.png' ?>" class="img-responsive" alt="<?php the_title(); ?>" />
                    </div>
                </div>
                 <div class="col-md-9 col-sm-10 col-xs-9">
                    <div class="con-inn">
                        <h3 class="ts-area-title"><?php the_title(); ?></h3>
                        <div class="text-designation">
                          <?php echo ($testimonial_area_designation); ?>
                        </div> 
                    </div>
                </div>
                <div class="clearfix"></div>
                <div class="ts-area-content">             
                    <div class="ts-area-bx">
                        <div class="ts-area-c section-area-text ">   
                            <p>
                                <?php
                                    if (has_excerpt()) {
                                        echo get_the_excerpt();
                                    } else {
                                        echo get_the_content();
                                    }
                                ?> 
                            </p> 
                        </div>
                        <i class="fa fa-quote-right" aria-hidden="true"></i>  
                        <div class="clearfix"></div>
                    </div>
                </div>
                <div class="ts-circle two"></div>
            </div>
    <script>
        jQuery.noConflict();
        $(function(){
            function tsareasingleHeight(){
                var ht = 0;
                $('.inner_contentbox .ts-area-single').each(function(i){
                    var tHt = $(this).height();
                    if(ht<tHt){
                        ht=tHt;
                    }
                });
                $('.inner_contentbox .ts-area-single').height(ht+'px');
            }
            tsareasingleHeight();
        });
        $( window ).resize(function(){
            tsareasingleHeight();
        });
    </script>
</div>
    <?php
endwhile;
$text = ob_get_contents();
ob_clean();
endif;
wp_reset_postdata();
return $text;
}


/**
 * Use for the show the gallery 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 string
 * @author Luzuk <support@luzuk.com>
 * */


/*gallery*/ 

function galleryShortCode($pageId = null, $isCustomizer = false, $i = null) {

    ob_start();

    $args = array('post_type' => 'our-gallery');
    if (!empty($pageId)) {
        $args['page_id'] = absint($pageId);
    }
    $args['posts_per_page'] = -1;
    $colCls = '';
    // if($isCustomizer == true){
    $cols = get_theme_mod('luzuk_gallery_npp_count', 2);  
    ++$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-12';
        break;
        case 3:
        case 5:
        case 6:
        case 9:
        $colCls = 'col-md-4 col-sm-6 col-xs-12';
        break;
        case 4:
        case 7:
        case 8:
        case 10:
        case 11:
        case 12:
        $colCls = 'col-md-3 col-sm-6 col-xs-12';
        break;
        default:
        $colCls = 'col-md-4 col-sm-6 col-xs-12';
        break;
    }
    // }
    $text = '';
    $query = new WP_Query($args);
    if ($query->have_posts()):
        $postN = 0;

        while ($query->have_posts()) : $query->the_post();
            $luzuk_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'medium_large');
            
            if ($isCustomizer === true) {
                $team_gallery = get_theme_mod('team_gallery' . $i);
                
            } else {
                $team_gallery = '';
                
            }

            $post = get_post();
            $teamgallery = get_post_meta($post->ID, 'teamgallery', false);
            $team_gallery = !empty($teamgallery[0]) ? $teamgallery[0] : '';
        ?> 
            <!-- <div class=" galleryitems"> -->
                <div class="boxes <?php echo $colCls;?>">
                    <div class="galleryboxes">
                         <?php
                         if (has_post_thumbnail()) {
                            $image_url = $luzuk_image[0];
                        } else {
                            $image_url = get_template_directory_uri() . '/images/about1.jpg';
                        }
                        ?>
                        <a href="#<?php the_ID(); ?>">
                            <div class="box">
                                <div class="box-video">
                                    <img alt="<?php the_title(); ?>" src="<?php echo esc_url($image_url); ?>" /> 
                                    <div class="overlay"></div>
                                    <i class="fa fa-play-circle" aria-hidden="true"></i>
                                </div>
                            </div>
                            <div class="gcontain">    
                                <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
                            </div>
                        </a> 
                        <div class="popup-content">
                            <div id="<?php the_ID(); ?>">
                                <iframe width="850" height="500" src="<?php echo ($team_gallery) ?>" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
                            </div>
                        </div> 
                    </div>
                </div>
            <!-- </div>  --> 
          <?php
    endwhile;
    $text = ob_get_contents();
    ob_clean();
endif;
wp_reset_postdata();
return $text;
}





/**
 * Get list of all categories from woocommerce theme
 * @param int $isObject return type in array of object default is true
 * @param int $itemPerPagenumber of items per page default -1
 * @param int $isParents to show the only parents default '0'
 * @param int $orderby name of field ordeing with default 'name'
 * @param int $order assending of deseinging default 'ASC'
 * @param int $hideEmpty show the empty categories or not default 'false'
 * @return Array/Object 
 * @author Luzuk 
 * @since version 1.0
 **/
function getPostCategories($isObject = true, $id=0, $isParents = 0, $itemPerPagenumber = -1, $orderby='name', $order='ASC', $hideEmpty = false){
    $categories = array();
    // echo 'asdlkfjoasdoh';
    $args = array(
        'taxonomy' => 'video-category',
        'orderby' => $orderby, // 'slug',
        'hide_empty' => $hideEmpty,
        'number'=> 0
    );

    if($isParents == 0 ){
        $args['parent'] = $isParents;
    }

    if(!empty($id) && $id >0 ){
        $args['term_taxonomy_id'] = $id;
    }
    $parent_terms = get_terms($args);
    // print_r($parent_terms);
    foreach ($parent_terms as $pterm) {
        if($isObject === true){
            $categories[] = $pterm;
        }elseif(!empty($pterm->term_id)){
            $categories[$pterm->term_id] = $pterm->name;
            // echo '&*&*&';
        }
        
    }
    // print_r($categories);
    return $categories;
}    