<?php
/*
 * Template 1
 */
defined('ABSPATH') or die("No script kiddies please!");
if ($layout_type == "list") {
    if (isset($reviews) && !empty($reviews)) {
        ?>
        <ul class="egpr-show-reviews-wrap egpr-lists-type egpr-clearfix">
            <?php
            for ($i = 0; $i < count($reviews); $i++) {
                $j = $i + 1;
                $author_url = (isset($reviews[$i]['author_url']) && $reviews[$i]['author_url'] != '') ? $reviews[$i]['author_url'] : '#';
                $author_name = (isset($reviews[$i]['author_name']) && $reviews[$i]['author_name'] != '') ? $reviews[$i]['author_name'] : '';
                $profile_photo_url = (isset($reviews[$i]['profile_photo_url']) && $reviews[$i]['profile_photo_url'] != '') ? $reviews[$i]['profile_photo_url'] : '';
                ?>
                <li class="egpr-sp-review">
                    <div class="egpr-main-header-section egpr-clearfix">

                        <?php if ($hide_usr_image != 1) { ?>
                            <div class="egpr-info-section egpr-left-info-section">   
                                <div class="egpr-user-review-avatar">
                                    <?php if ($profile_photo_url != '') { ?>
                                        <a <?php if($disable_user_links != "true") echo 'href="'.esc_attr($author_url).'" target="_blank"'; ?>>
                                            <img src="<?php echo esc_attr($profile_photo_url); ?>" alt="<?php echo esc_attr($author_name); ?>" title="<?php echo esc_attr($author_name); ?>">
                                        </a>
                                    <?php } else { ?>
                                        <a <?php if($disable_user_links != "true") echo 'href="'.esc_attr($author_url).'" target="_blank"'; ?>>
                                            <img src="<?php echo EGPR_FRONTEND_IMG_DIR; ?>nopreview.png">
                                        </a>
                                    <?php } ?>
                                </div>
                            </div>
                        <?php } ?>
                        <div class="egpr-info-section egpr-right-info-section">
                            <div class="egpr-user-info egpr-clearfix">
                                <div class="egpr-user-info-left-wrap">
                                    <?php if($hide_user_name != 1){?>
                                    <div class="egpr-header-title egpr-reviewer-name">
                                        <?php if (isset($reviews[$i]['author_name']) && $reviews[$i]['author_name'] != '') {
                                            ?>
                                            <a <?php if($disable_user_links != "true") echo 'href="'.esc_attr($author_url).'" target="_blank" title="View this profile."'; ?>>
                                                <span><?php echo esc_attr($author_name); ?></span>
                                            </a>
                                        <?php } ?>
                                    </div>
                                    <?php } ?>
                                    <?php if ($hide_user_rating != 1) { ?>
                                        <div class="egpr-reviewer-star">
                                            <input type="hidden" value="<?php echo esc_attr($reviews[$i]['rating']); ?>"/>
                                            <div style="display: none;"><?php echo esc_attr($reviews[$i]['rating']); ?></div>
                                            <?php
                                            $rating2 = $reviews[$i]['rating'];
                                            $whole2 = floor($reviews[$i]['rating']);      // 1
                                            $fraction2 = $rating2 - $whole2; // .25
                                            $next2 = $whole2 + 1;
                                            $fraction_percent2 = round($fraction2, 1) * 100;
                                            for ($m = 1; $m <= 5; $m++) {
                                                $full2 = ($m <= $whole2) ? 'full' : '';
                                                $half2 = ($fraction2 != '' && $m == $next2) ? 'half egpr-fraction-' . $fraction_percent2 : '';
                                                if($full2 == '' && $half2 == ''){
                                                    $new_class = "empty";
                                                  }else{
                                                    $new_class = $full2 . $half2;
                                                  }
                                                ?>
                                                <span class="egpr-star-icon <?php echo $new_class; ?>">
                                                 <i class="fa fa-star-o"></i>
                                                </span>
                                                <?php if ($half2 != '') { ?>
                                                    <style>
                                                        .egpr-reviewer-star .half.egpr-fraction-<?php echo $fraction_percent; ?>:before {
                                                            width:<?php echo $fraction_percent2; ?>%;
                                                        }
                                                    </style>
                                                <?php
                                                }
                                            }
                                            ?>
                                        </div>
                                    <?php } ?>
                                </div>
                                 <?php if($disable_date != "true"){ ?>
                                    <span class="egpr-rated-time">
                                        <?php echo esc_attr($reviews[$i]['relative_time_description']); ?>
                                    </span>
                                <?php } ?>
                            </div>
                              <?php if ($show_description == "true") {
                                  $review_description = (isset($reviews[$i]['text']) && $reviews[$i]['text'] != '')?$reviews[$i]['text']:'';
                                    if ($review_description != '') {
                                    ?>
                              <div class="egpr-content-reviews-wrapper">
                                <?php 
                              
                                if (strlen($review_description) >= $word_limit) { ?>
                                    <div class="egpr-small-description" data-id="egpr-small-description-<?php echo $random_num . $i; ?>">
                                        <?php 
                                          echo strip_tags(substr($review_description, 0,$word_limit)) . '...';
                                        ?>
                                      <span class="egpr-read-more egpr-readtxt" data-id="egpr-read-more-<?php echo $random_num;?>"><?php echo $desc_text_show;?></span>
                                    </div>
                                     <div class="egpr-full-description" data-id="egpr-full-description-<?php echo $random_num . $i; ?>" style="display:none;">
                                     <?php echo $review_description; ?>
                                     <span class="egpr-read-less egpr-readtxt" data-id="egpr-read-less-<?php echo $random_num . $i; ?>"><?php _e(esc_attr($desc_text_hide)); ?></span>
                                     </div>
                                    <?php }else{
                                         echo $review_description;
                                        }  ?>
                                </div>
                                <?php }
                            }
                            ?>
                        </div>

                    </div>
                </li>
                <?php
            }
            ?>
        </ul>
        <?php
    }
} else if ($layout_type == "slider") {
    if (isset($reviews) && !empty($reviews)) {
        ?>
        <ul id="egpr-reviews-<?php echo $random_num; ?>" class="egpr-show-reviews-wrap egpr-slider-type" data-speed="<?php echo esc_attr($speed); ?>" data-pause="<?php echo esc_attr($pause); ?>" 
            data-show-pager="<?php echo esc_attr($pager_show); ?>" 
            data-autoplay="<?php echo esc_attr($autoplay); ?>" data-pager="<?php echo esc_attr($pager_type); ?>" 
            data-mode="<?php echo esc_attr($mode); ?>"
            data-show-controls="<?php echo esc_attr($controls); ?>" data-adaptiveheight="<?php echo esc_attr($adaptive_height);?>" data-controls="<?php echo esc_attr($controls_type); ?>">
                <?php
                for ($i = 0; $i < count($reviews); $i++) {
                    $j = $i + 1;
                    $author_url = (isset($reviews[$i]['author_url']) && $reviews[$i]['author_url'] != '') ? $reviews[$i]['author_url'] : '#';
                    $author_name = (isset($reviews[$i]['author_name']) && $reviews[$i]['author_name'] != '') ? $reviews[$i]['author_name'] : '';
                    $profile_photo_url = (isset($reviews[$i]['profile_photo_url']) && $reviews[$i]['profile_photo_url'] != '') ? $reviews[$i]['profile_photo_url'] : '';
                    ?>  
                <li class="egpr-sp-review">
                    <div class="egpr-main-header-section egpr-clearfix">

                     <?php if ($hide_usr_image != 1 && $profile_photo_url != '') { ?>
                        <div class="egpr-info-section egpr-left-info-section">    
                          <div class="egpr-user-review-avatar">
                               <?php if ($profile_photo_url != '') { ?>
                                        <a <?php if($disable_user_links != "true") echo 'href="'.esc_attr($author_url).'" target="_blank"'; ?>>
                                            <img src="<?php echo esc_attr($profile_photo_url); ?>" alt="<?php echo esc_attr($author_name); ?>" title="<?php echo esc_attr($author_name); ?>">
                                        </a>
                                    <?php } else { ?>
                                        <a <?php if($disable_user_links != "true") echo 'href="'.esc_attr($author_url).'" target="_blank"'; ?>>
                                            <img src="<?php echo EGPR_FRONTEND_IMG_DIR; ?>nopreview.png">
                                        </a>
                                    <?php } ?>
                            </div>
                        </div>
                     <?php } ?>
                     <div class="egpr-info-section egpr-right-info-section">
                        <div class="egpr-user-info egpr-clearfix">
                            <div class="egpr-user-info-left-wrap">
                                <?php if($hide_user_name != 1){?>
                                    <div class="egpr-header-title egpr-reviewer-name">
                                    <?php if (isset($reviews[$i]['author_name']) && $reviews[$i]['author_name'] != '') {
                                        ?>
                                        <a <?php if($disable_user_links != "true") echo 'href="'.esc_attr($author_url).'" target="_blank" title="View this profile."'; ?>>
                                            <span><?php echo esc_attr($author_name); ?></span>
                                        </a>
                                    <?php } ?>
                                    </div>
                                <?php } ?>

                                    <?php if ($hide_user_rating != 1) { ?>
                                    <div class="egpr-reviewer-star">
                                        <input type="hidden" value="<?php echo esc_attr($reviews[$i]['rating']); ?>"/>
                                        <div style="display: none"><?php echo esc_attr($reviews[$i]['rating']); ?></div>
                                        <?php
                                        $rating3 = $reviews[$i]['rating'];
                                        $whole3 = floor($reviews[$i]['rating']);      // 1
                                        $fraction3 = $rating3 - $whole3; // .25
                                        $next3 = $whole3 + 1;
                                        $fraction_percent3 = round($fraction3, 1) * 100;
                                        for ($k = 1; $k <= 5; $k++) {
                                            $full3 = ($k <= $whole3) ? 'full' : '';
                                            $half3 = ($fraction3 != '' && $k == $next3) ? 'half egpr-fraction-' . $fraction_percent3 : '';
                                             if($full3 == '' && $half3 == ''){
                                                    $new_class3 = "empty";
                                                  }else{
                                                    $new_class3 = $full3 . $half3;
                                                  }
                                            ?>
                                            <span class="egpr-star-icon <?php echo $new_class3; ?>">
                                              <i class="fa fa-star-o"></i>
                                            </span>
                                      <?php if ($half3 != '') { ?>
                                                <style>
                                                    .egpr-reviewer-star .half.egpr-fraction-<?php echo $fraction_percent; ?>:before {
                                                        width:<?php echo $fraction_percent3; ?>%;
                                                    }
                                                </style>
                                            <?php
                                            }
                                        }
                                        ?>
                                    </div>
                                    <?php } ?>
                                </div>
                         <?php if($disable_date != "true"){ ?>
                            <span class="egpr-rated-time"><?php echo esc_attr($reviews[$i]['relative_time_description']); ?></span>
                          <?php } ?>
                             </div>
                               <?php if ($show_description == "true") {
                                  $review_description = (isset($reviews[$i]['text']) && $reviews[$i]['text'] != '')?$reviews[$i]['text']:'';
                                    if ($review_description != '') {
                                    ?>
                              <div class="egpr-content-reviews-wrapper">
                                <?php 
                              
                                if (strlen($review_description) >= $word_limit) { ?>
                                    <div class="egpr-small-description" data-id="egpr-small-description-<?php echo $random_num . $i; ?>">
                                        <?php 
                                          echo strip_tags(substr($review_description, 0,$word_limit)) . '...';
                                        ?>
                                      <span class="egpr-read-more egpr-readtxt" data-id="egpr-read-more-<?php echo $random_num;?>"><?php echo $desc_text_show;?></span>
                                    </div>
                                     <div class="egpr-full-description" data-id="egpr-full-description-<?php echo $random_num . $i; ?>" style="display:none;">
                                     <?php echo $review_description; ?>
                                     <span class="egpr-read-less egpr-readtxt" data-id="egpr-read-less-<?php echo $random_num . $i; ?>"><?php _e(esc_attr($desc_text_hide)); ?></span>
                                     </div>
                                    <?php }else{
                                         echo $review_description;
                                        }  ?>
                                </div>
                                <?php }
                            }
                            ?>
                     </div>
                    </div>
                </li>

            <?php
        }
        ?>
        </ul>
    <?php }
}
?>   