<?php

/**
 * Provide a public-facing view for the plugin
 *
 * This file is used to markup the public-facing aspects of the plugin.
 *
 * @link       http://example.com
 * @since      1.0.0
 *
 * @package    WP_Review_Pro
 * @subpackage WP_Review_Pro/public/partials
 */

 	//db function variables
	global $wpdb;
	$table_name = $wpdb->prefix . 'wpfb_post_templates';
	
 //use the template id to find template in db, echo error if we can't find it or just don't display anything
 	//Get the form--------------------------
	$tid = htmlentities($a['tid']);
	$tid = intval($tid);
	//$currentform = $wpdb->get_results("SELECT * FROM $table_name WHERE id = ".$tid);
	
	$currentform = $wpdb->get_results($wpdb->prepare(
		"SELECT * FROM $table_name WHERE id =  %s",
		$tid
	));
	
	//template misc stuff
	$template_misc_array = json_decode($currentform[0]->template_misc, true);
	
	$totalreviewsnum ='';
	$reviewratingsarray = Array();
	$reviewratingsarrayavg ='';
	
	//check to make sure template found
	if(isset($currentform[0])){
		$formid = intval($currentform[0]->id);
		
		//get all the reviews based on template filters
		$shortcodepageid ='';
		if(isset($a['pageid'])){
			$shortcodepageid = $a['pageid'];
		}
		$shortcodelang='';
		if(isset($a['langcode'])){
			$shortcodelang = $a['langcode'];
		}
		$shortcodetag='';
		if(isset($a['tag'])){
			$shortcodetag = $a['tag'];
		}
		$sc_strhasone='';
		if(isset($a['strhasone'])){
			$sc_strhasone = $a['strhasone'];
		}
		$sc_strhasall='';
		if(isset($a['strhasall'])){
			$sc_strhasall = $a['strhasall'];
		}
		$sc_strnot='';
		if(isset($a['strnot'])){
			$sc_strnot = $a['strnot'];
		}
		
		require_once("getreviews_class.php");
		$reviewsclass = new GetReviews_Functions();
		
		//if we are hiding all reviews in badge settings then do not even look for them.
		//hide all the reviews!
		if(!isset($template_misc_array['bhreviews'])){
			$template_misc_array['bhreviews']='';
		}
		if($template_misc_array['bhreviews']=="yes"){
			$totalreviews = Array();
			$totalreviewsarray = Array();
		} else {
			//not hiding reviews so find them.
			$totalreviewsarray = $reviewsclass->wppro_queryreviews($currentform,$startoffset=0,$totaltoget=0,$notinstring='',$shortcodepageid,$shortcodelang,'','','','','',$shortcodetag,$sc_strhasone,$sc_strhasall,$sc_strnot);
			$totalreviews = $totalreviewsarray['reviews'];
		}
		//$totalreviewsarray['totalcount']
		//$totalreviewsarray['totalavg']

		//if $template_misc_array['aisummary']=='yes' then we need to add the ai summary as the first review to $totalreviews and delete the last review
		if(isset($template_misc_array['aisummary']) && $template_misc_array['aisummary']=='yes'){
			$template_misc_array['reviewtypesarray'] = $totalreviewsarray['reviewtypesarray'];
			if(isset($template_misc_array['aitype']) && $template_misc_array['aitype']=='firstreview'){
				// AI summary logic will be implemented here
				$ai_summary_data = json_decode(stripslashes($template_misc_array['aisummarytext']), true);
				// Extract AI summary data
				$ai_overall_sentiment = isset($ai_summary_data['overall_sentiment']) ? $ai_summary_data['overall_sentiment'] : 'positive';
				$ai_average_rating = isset($ai_summary_data['average_rating']) ? floatval($ai_summary_data['average_rating']) : 5.0;
				$ai_common_praises = isset($ai_summary_data['common_praises']) ? $ai_summary_data['common_praises'] : array();
				$ai_common_complaints = isset($ai_summary_data['common_complaints']) ? $ai_summary_data['common_complaints'] : array();
				$ai_summary_text = isset($ai_summary_data['summary_text']) ? $ai_summary_data['summary_text'] : '';

				if($template_misc_array['show_praises']=='yes'){
					$ai_summary_text = $ai_summary_text . "<br><br><b>Praises:</b><br>" . implode(", ", $ai_common_praises);
				}
				if($template_misc_array['show_complaints']=='yes'){
					$ai_summary_text = $ai_summary_text . "<br><br><b>Complaints:</b><br>" . (empty($ai_common_complaints) ? __('none', 'wp-review-slider-pro') : implode(", ", $ai_common_complaints));
				}

				$imgs_url = esc_url( plugins_url( 'imgs/', __FILE__ ) );
				//create a new review object
				$ai_summary_review = new stdClass();
				$ai_summary_review->id = 0;
				$ai_summary_review->review_text = $ai_summary_text;
				$ai_summary_review->review_title  = 'AI Generated Summary';
				$ai_summary_review->rating = $ai_average_rating;
				$ai_summary_review->sentiment = $ai_overall_sentiment;
				$ai_summary_review->praises = $ai_common_praises;
				$ai_summary_review->complaints = $ai_common_complaints;
				//define the rest of the review object so we don't get errors
				$ai_summary_review->reviewer_name = 'AI Summary';
				$ai_summary_review->reviewer_email = 'ai@summary.com';
				$ai_summary_review->reviewer_url = '';
				$ai_summary_review->reviewer_ip = '';
				$templaceid = "template_".$currentform[0]->id;
				$table_name_avg = $wpdb->prefix . 'wpfb_total_averages';
				$currentlocation = $wpdb->get_results("SELECT * FROM $table_name_avg WHERE `btp_id` = '".$templaceid."' LIMIT 1");
				$badgetotal = intval($currentlocation[0]->total);
				$badgetotaldb = intval($currentlocation[0]->total_indb);
				if($badgetotaldb>$badgetotal){
					$badgetotaltemp = $badgetotaldb;
				} else {
					$badgetotaltemp = $badgetotal;
				}
				$ai_summary_review->created_time_stamp = "Based on ".$badgetotaltemp." reviews";
				$ai_summary_review->type = 'ai';
				$ai_summary_review->pagename  = 'AI Summary';
				$ai_summary_review->mediathumburlsarrayjson  = '';
				$ai_summary_review->mediaurlsarrayjson  = '';
				//$ai_summary_review->created_time_stamp  = time();
				$ai_summary_review->translateparent  = '';
				$ai_summary_review->review_length  = 10;
				$ai_summary_review->review_length_char  = 100;
				$imgs_url = esc_url( plugins_url( 'imgs/', __FILE__ ) );
				$ai_summary_review->userpic = $imgs_url . "ai_avatar_min.png";


				//add the ai summary as the first review
				array_unshift($totalreviews, $ai_summary_review);
				//delete the last review
				array_pop($totalreviews);
			}

		}
		
		//print_r($totalreviews);
	
		$reviewsperpage= $currentform[0]->display_num*$currentform[0]->display_num_rows;
		
	
		
			
	//only continue if some reviews found
	$makingslideshow=false;
	$ismakingslideshow = "no";
	if(count($totalreviews)>0 || $template_misc_array['bhreviews']=="yes"){

	//------------add style
		$iswidget = '';
		// Check template count - if > 25, generate CSS inline instead of bulk loading
		$template_count = (int) get_option('wprevpro_template_count', 0);
		if ($template_count > 25) {
			// Generate CSS inline for this template only
			$gettemplatestylecode = $reviewsclass->wppro_gettemplatestylecode(
				array($currentform[0]), 
				'', 
				$template_misc_array
			);
			echo "<div>".$gettemplatestylecode."</div>";
		} else {
			// Register template for bulk CSS generation (not used anymore, but kept for compatibility)
			WP_Review_Pro_Public::register_template_for_css($formid, false);
		}
		//---------end add style-----------------------
		
		$loading_img_url = esc_url( plugins_url( 'imgs/', __FILE__ ) ).'loading_ripple.gif';
		
		//add banner
		if(!isset($template_misc_array['header_banner'])){
			$template_misc_array['header_banner']='';
		}
		
			$templatepagevals['avg_indb']="";
			$templatepagevals['total_indb']="";
			$templatepagevals['avg']="";
			$templatepagevals['total']="";
			
		if($template_misc_array['header_banner']=='txt' || $template_misc_array['header_banner']=='b1'){
			//need to get totals and averages from table.
			$pagetypedetailsarray = Array();
			$temptemplant = "template_".$formid;
			$table_name_temp = $wpdb->prefix . 'wpfb_total_averages';
			$templatepagevals = $wpdb->get_row("SELECT * FROM $table_name_temp WHERE `btp_id` = '".$temptemplant."' ",ARRAY_A );
			
		if(isset($templatepagevals['pagetypedetails']) && $templatepagevals['pagetypedetails']!=''){
			$pagetypedetailsarray = json_decode($templatepagevals['pagetypedetails'],true);
		}
		//print_r($templatepagevals);
		//print_r($pagetypedetailsarray);
		}

		//add ai summary to header if set
		$headeraisummary = '';
		if((isset($template_misc_array['header_ai']) && $template_misc_array['header_ai']=="yes") || (isset($template_misc_array['abovereviews_ai']) && $template_misc_array['abovereviews_ai']=="yes")){
			// Parse the AI summary JSON data
			$ai_summary_data = json_decode(stripslashes($template_misc_array['aisummarytext']), true);
			
			if($ai_summary_data && is_array($ai_summary_data)){
				// Extract AI summary data
				$overall_sentiment = isset($ai_summary_data['overall_sentiment']) ? $ai_summary_data['overall_sentiment'] : 'positive';
				$average_rating = isset($ai_summary_data['average_rating']) ? floatval($ai_summary_data['average_rating']) : 5.0;
				$common_praises = isset($ai_summary_data['common_praises']) ? $ai_summary_data['common_praises'] : array();
				$common_complaints = isset($ai_summary_data['common_complaints']) ? $ai_summary_data['common_complaints'] : array();
				$summary_text = isset($ai_summary_data['summary_text']) ? $ai_summary_data['summary_text'] : '';
				
				// Build structured HTML for header AI summary
				$headeraisummary = '<div class="wprev-header-ai-summary"';
				$style_parts = array();
				//print_r($template_misc_array);
				//echo $template_misc_array['bgcolor1'];
				if(isset($template_misc_array['bgcolor1'])) {
					$style_parts[] = 'background-color: '.$template_misc_array['bgcolor1'];
				}
				if(isset($template_misc_array['bradius'])) {
					$style_parts[] = 'border-radius: '.$template_misc_array['bradius'].'px';
				}
				if(isset($template_misc_array['bcolor'])) {
					$style_parts[] = 'border-color: '.$template_misc_array['bcolor'];
				}
				if(isset($template_misc_array['tcolor1'])) {
					$style_parts[] = 'color: '.$template_misc_array['tcolor1'];
				}
				if(!empty($style_parts)) {
					$headeraisummary .= ' style="'.implode('; ', $style_parts).'"';
				}
				$headeraisummary .= '>';

				
				// AI Summary Header
				$headeraisummary .= '<div class="wprev-header-ai-summary-header">';
				$headeraisummary .= '<div class="wprev-header-ai-summary-title"><img loading="lazy" src="'.WPREV_PLUGIN_URL.'/public/partials/imgs/ai_avatar_min.png" alt="AI Summary Avatar" class="wprevpro_avatarimg wprev-header-ai-summary-icon">AI Review Summary</div>';
				
				// Add source type icons in top right
				
				if(isset($template_misc_array['reviewtypesarray']) && !empty($template_misc_array['reviewtypesarray'])){
					$headeraisummary .= '<div class="wprevpro_ai_header_types_div"> <div class="wprevpro_ai_header_types  wprevpro_ai_summary_types_logo">';
					$imgs_url = WPREV_PLUGIN_URL.'/public/partials/imgs/';
					$widthheighticon = 'width="16" height="16"';
					$count = 0;
					foreach($template_misc_array['reviewtypesarray'] as $reviewtype){
						if($reviewtype!='' && $reviewtype!='Manual' && $reviewtype!='ai' && $count < 3){
							$tempreviewtypelower = strtolower($reviewtype);
							$tempfileext = "svg";
							if ( !file_exists( WPREV_PLUGIN_DIR."/public/partials/imgs/".$tempreviewtypelower."_small_icon.svg" ) ) {
								$tempfileext = "png";
							}
							$headeraisummary .= '<img '.$widthheighticon.' src="'.$imgs_url.$tempreviewtypelower.'_small_icon.'.$tempfileext.'" alt="'.$reviewtype.' logo" class="wprevpro_ai_summary_source_icon aisummarytypeslogo" style="margin-left: 4px;">';
							$count++;
						}
					}
					$headeraisummary .= '</div></div>';
				}
				
				$headeraisummary .= '</div>';
				
				// Summary Text
				if(!empty($summary_text)){
					$headeraisummary .= '<div class="wprev-header-ai-summary-text">' . esc_html($summary_text) . '</div>';
				}
				
				// Praises Section
				if(!empty($common_praises) && (!isset($template_misc_array['show_praises']) || $template_misc_array['show_praises'] == 'yes')){
					$headeraisummary .= '<div style="margin-bottom: 8px;">';
					$headeraisummary .= '<div style="font-weight: bold; margin-bottom: 4px; font-size: 14px;">What customers love:</div>';
					$headeraisummary .= '<div style="line-height: 1.5;">' . implode(' • ', array_map('esc_html', $common_praises)) . '</div>';
					$headeraisummary .= '</div>';
				}
				
				// Complaints Section
				if(!empty($common_complaints) && (!isset($template_misc_array['show_complaints']) || $template_misc_array['show_complaints'] == 'yes')){
					$headeraisummary .= '<div style="margin-bottom: 8px;">';
					$headeraisummary .= '<div style="font-weight: bold; margin-bottom: 4px; font-size: 14px;">Areas for improvement:</div>';
					$headeraisummary .= '<div style="line-height: 1.5;">' . implode(' • ', array_map('esc_html', $common_complaints)) . '</div>';
					$headeraisummary .= '</div>';
				}
				
				$headeraisummary .= '</div>';
			}
		}

			
		//add header text if set
		if(isset($template_misc_array['header_text']) && $template_misc_array['header_text']!='' && $template_misc_array['header_banner']!='no' && $template_misc_array['header_banner']!='b1'){
			
			//$arrallowedtags = array('em' => array(), 'i' => array(), 'strong' => array(), 'b' => array());
			$arrallowedtags = array(
				'a' => array(
					'href' => array(),
					'title' => array()
				),
				'b' => array('class' => array(),
					'id' => array()),
				'em' => array('class' => array(),
					'id' => array()),
				'strong' => array('class' => array(),
					'id' => array()),
				'i' => array(
					'class' => array(),
					'id' => array()
					),
				'span' => array(
					'class' => array(),
					'id' => array()
					),
			);
			$tempheadertext= '<div id="wprev_header_txt_id_'.$formid.'" class="wprev_header_txt"><'.wp_kses($template_misc_array['header_text_tag'],$arrallowedtags).'>'.wp_kses($template_misc_array['header_text'],$arrallowedtags).'</'.wp_kses($template_misc_array['header_text_tag'],$arrallowedtags).'></div>';
			
			

			
			if(!isset($template_misc_array['header_filter_opt'])){$template_misc_array['header_filter_opt']='';}
			
			$tempavg = $templatepagevals['avg_indb']; //default to use review list values
			$temptotal = $templatepagevals['total_indb'];
			
			if($template_misc_array['header_filter_opt']=='source'){
				//try to use source var
				$tempavg = $templatepagevals['avg'];
				$temptotal = $templatepagevals['total'];
			}
			
			//If this header is on a template that uses the product ID filter then we need to change the total/avg.
			if($template_misc_array['postfilter']=='yes'){
				$tempavg = $totalreviewsarray['totalavg'];
				$temptotal = $totalreviewsarray['totalcount'];
			}

			
			$tempheadertext=str_replace("{avgrating}",$tempavg,$tempheadertext);
			$tempheadertext=str_replace("{totalratings}",$temptotal,$tempheadertext);

			
			echo $tempheadertext;
			if(isset($template_misc_array['header_ai']) && $template_misc_array['header_ai']=="yes"){
			echo $headeraisummary;
			}
		}
		
		//banner style 1, will possibly use this for other banners styles and just change html.
		if($template_misc_array['header_banner']=='b1'){

			$tempavg = $templatepagevals['avg_indb']; //default to use review list values
			$temptotal = $templatepagevals['total_indb'];

			if($template_misc_array['bn_filter_opt']=='source'){
				//try to use source var
				$tempavg = $templatepagevals['avg'];
				$temptotal = $templatepagevals['total'];
		}
		$tempavg = number_format((float)$tempavg, 1, '.', '');
		
		// Ensure $upperhtml is always initialized
		$upperhtml = '';
		//create upper html.
		if(count($pagetypedetailsarray)>0){
			$upperhtml = '';
				foreach($pagetypedetailsarray as $page => $value) {
					$addicon = true;
					$lowertype = strtolower($page);
					$fileext = "png";
					//check for svg. 
					$svgarray = unserialize(WPREV_SVG_ARRAY);
					if (in_array($page, $svgarray)) {
						//found svg.
						$fileext = "svg";
					}
				
					$temptypeavg = $value['avg_indb'];
					$temptotalind = $value['total_indb'];
					if($template_misc_array['bn_filter_opt']=='source'){
						$temptypeavg = $value['avg'];
						$temptotalind = $value['total'];
					}
					if($temptypeavg<1){
						//in case we have zero from source site
						$temptypeavg = $value['avg_indb'];
					}
					$temptypeavg = number_format((float)$temptypeavg, 1, '.', '');
					
					//check for changes in submitted text and if we should display it.
					$subtext = $page;
					if($page=="Submitted"){
							$subtext = sanitize_text_field($template_misc_array['bnshowsubtext']);
							if($template_misc_array['bnshowsub']!='yes') {
								$addicon = false;
							}
					}
					if($page=="Manual"){
							$subtext = sanitize_text_field($template_misc_array['bnshowmantext']);
							if($template_misc_array['bnshowman']!='yes') {
								$addicon = false;
							}
					}
					
					if($addicon){
					$banner_imgsrc = WPREV_PLUGIN_URL.'/public/partials/imgs/'.$lowertype.'_small_icon.'.$fileext.'?time=7';
					$banner_display_type = $lowertype;
					$custom_icons_bnr = unserialize(WPREV_CUSTOM_SOURCES_ICON_URLS_ARRAY);
					if(is_array($custom_icons_bnr) && !empty($custom_icons_bnr)){
						if(isset($custom_icons_bnr[$page])){
							// Direct match on original-case page key
							$banner_imgsrc = $custom_icons_bnr[$page];
							$banner_display_type = strtolower($page);
					} elseif(is_numeric($page)){
						// Pagetype stored as a numeric placeholder due to a legacy data bug.
						// Look up the real source type and page name via the page row and its reviews.
						$ta_tbl = $wpdb->prefix.'wpfb_total_averages';
						$rv_tbl  = $wpdb->prefix.'wpfb_reviews';
						$matching_row = $wpdb->get_row($wpdb->prepare(
							"SELECT btp_id, btp_name FROM $ta_tbl WHERE btp_type='page' AND pagetype=%s LIMIT 1", $page
						), ARRAY_A);
						if($matching_row){
							if(!empty($matching_row['btp_name'])){
								$subtext = $matching_row['btp_name'];
							}
							$real_type = $wpdb->get_var($wpdb->prepare(
								"SELECT type FROM $rv_tbl WHERE pageid=%s AND type!='' LIMIT 1", $matching_row['btp_id']
							));
							if($real_type && isset($custom_icons_bnr[$real_type])){
								$banner_imgsrc = $custom_icons_bnr[$real_type];
								$banner_display_type = strtolower($real_type);
							}
						}
					}
					}
				$upperhtml = $upperhtml . '<span class="wprev_banner_top_source" data-stype="'.$banner_display_type.'"><img src="'.$banner_imgsrc.'" alt="'.$banner_display_type.' logo" class="wppro_banner_icon">'.$subtext.' '.$temptypeavg.'</span>';
					}
					
				};
			}

			
			//starhtml setup-------------
			$starhtml ='';
			$roundtohalf ='';
			if($tempavg>0){
			$roundtohalf = round($tempavg * 2) / 2;
			}
			for ($x = 1; $x <= $roundtohalf; $x++) {
				$starhtml = $starhtml.'<span class="svgicons svg-wprsp-star-full"></span>';
			}
			if($roundtohalf==1.5||$roundtohalf==2.5||$roundtohalf==3.5||$roundtohalf==4.5){
				//add another half
				//$starhtml = $starhtml.'<span class="wprsp-star-half"></span>';
				$starhtml = $starhtml.'<span class="svgicons svg-wprsp-star-half"></span>';
				$x++;
			}
			//if x is less than 5 need another star or half
			$starleft = 5 - $x;
			for ($x = 0; $x <= $starleft; $x++) {
				//$starhtml = $starhtml.'<span class="wprsp-star-empty"></span>';
				$starhtml = $starhtml.'<span class="svgicons svg-wprsp-star-empty"></span>';
			}
			
			//review us btn setup.----------
			if(!isset($template_misc_array['revus_btnaction'])){
				$template_misc_array['revus_btnaction'] = '';
			}
			if(!isset($template_misc_array['revus_btnlink'])){
				$template_misc_array['revus_btnlink'] = '';
			}
			
			
			$revus_txtval = 'Review Us';
			$revusbtnhtml = "";
			$revuslinkstart = "";
			$revuslinkend = "";
			$revuslinkhref = "";
			if(isset($template_misc_array['bnrevusbtn']) && $template_misc_array['bnrevusbtn']=='yes'){
				
				if(isset($template_misc_array['revus_txtval']) && $template_misc_array['revus_txtval']!=''){
					$revus_txtval =sanitize_text_field($template_misc_array['revus_txtval']);
				}
				$revusbtnhtml ='<div class="wprevpro_bnrevus_btn">'.$revus_txtval.'</div>';
				

				if($template_misc_array['revus_btnaction']=="link"){
					$revuslinkstart = '<a href="'.sanitize_text_field($template_misc_array['revus_btnlink']).'" target="_blank">';
					$revuslinkend = "</a>";
					$revusbtnhtml = $revuslinkstart.$revusbtnhtml.$revuslinkend;
					
				} else if($template_misc_array['revus_btnaction']=="ddlinks"){
					//multiple links, we need to build hidden drop down list that we show when clicked or pushed
					$revusbtnhtml = '<div class="wprevpro_bnrevus_btn wprevdropbtn">'.$revus_txtval.'</div>
					<div class="wprevdropdown-content">';
					if(!isset($template_misc_array['revus_btnln'])){$template_misc_array['revus_btnln']=Array();}
					if(!isset($template_misc_array['revus_btnlu'])){$template_misc_array['revus_btnlu']=Array();}
					for ($x = 1; $x <= 6; $x++) {
						if(isset($template_misc_array['revus_btnlu'][$x]) && isset($template_misc_array['revus_btnln'][$x])){
							if($template_misc_array['revus_btnlu'][$x]!='' && $template_misc_array['revus_btnln'][$x]!=''){
						$revusbtnhtml = $revusbtnhtml. '<a target="_blank" href="'.sanitize_text_field($template_misc_array['revus_btnlu'][$x]).'">'.sanitize_text_field($template_misc_array['revus_btnln'][$x]).'</a>';
							}
						}
					}
					$revusbtnhtml = $revusbtnhtml. '</div>';
				} else if($template_misc_array['revus_btnaction']=="form"){
					//need to add form to page and pop-up when pushing the button.
					//$template_misc_array['revus_puform'] is form id.
					$revusbtnhtml ='<div class="wprevpro_bnrevus_btn bnrevuspopform" data-formid="'.$template_misc_array['revus_puform'].'">'.$revus_txtval.'</div>';
					
					//get form array from db
					$reviewformid = intval($template_misc_array['revus_puform']);
	
					$formhtml=$this->getformhtml($reviewformid);
					echo $formhtml;
					
				}
			}
			
			$tempheadertext='<div id="wprev_banner_id_'.$formid.'" data-tid="'.$formid.'" class="wprev_banner_outer wprevb1"><div class="wprev_banner_top"><span class="wprev_banner_top_source cursel">'.__('All Reviews', 'wp-review-slider-pro').' '.$tempavg.'</span>'.$upperhtml.'</div><div class="wprev_banner_bottom"><div class="wprev_banner_bottom_t">'.__('Overall Rating', 'wp-review-slider-pro').'</div><div class="wprev_banner_bottom_b"><span class="wprev_avgrevs">'.$tempavg.'</span> <span class="starloc1 wprevpro_star_imgs wprevpro_star_imgsloc1">'.$starhtml.'</span> <span class="wprev_totrevs">'.$temptotal.' '.__('reviews', 'wp-review-slider-pro').'</span></div><div class="wprevpro_bnrevus_div">'.$revusbtnhtml.'</div></div>';
			
			
			echo $tempheadertext;
			if(isset($template_misc_array['header_ai']) && $template_misc_array['header_ai']=="yes"){
				echo $headeraisummary;
				}
			echo '</div>';
		}
		//===end add banner==============
		
		if(isset($template_misc_array['abovereviews_ai']) && $template_misc_array['abovereviews_ai']=="yes"){
			echo $headeraisummary;
		}
		
		
		//add search bar if turned on
		if(!isset($template_misc_array['header_search'])){
			$template_misc_array['header_search']='';
		}
		if(!isset($template_misc_array['header_sort'])){
			$template_misc_array['header_sort']='';
		}
		//add quick search tags if turned on
		if(!isset($template_misc_array['header_tag'])){
			$template_misc_array['header_tag']='';
		}
		if(!isset($template_misc_array['header_tags'])){
			$template_misc_array['header_tags']='';
		}
		if(!isset($template_misc_array['header_rating'])){
			$template_misc_array['header_rating']='';
			$template_misc_array['header_langcodes']='';
		}
		if(!isset($template_misc_array['header_rtypes'])){
			$template_misc_array['header_rtypes']='';
		}
		if(!isset($template_misc_array['header_source'])){
			$template_misc_array['header_source']='';
		}
		
		//need to track if we are forcing load more so we can hide button later if needed.
		$forceloadmore = false;

		//if any header search is turned on or banner then we need to force on load more
		if($template_misc_array['header_search']=='yes' || $template_misc_array['header_sort']=='yes' || $template_misc_array['header_tag']=='yes' || $template_misc_array['header_rating']=='yes' || $template_misc_array['header_langcodes']=='yes' || $template_misc_array['header_rtypes']=='yes' || $template_misc_array['header_source']=='yes' || $template_misc_array['header_banner']=='b1'){
			if(!isset($currentform[0]->load_more) || $currentform[0]->load_more!="yes"){
				$currentform[0]->load_more='yes';
				$forceloadmore = true;
			}

		}
		if( $currentform[0]->load_more=='yes' && ($template_misc_array['header_search']=='yes' || $template_misc_array['header_sort']=='yes' || $template_misc_array['header_tag']=='yes' || $template_misc_array['header_rating']=='yes' || $template_misc_array['header_langcodes']=='yes' || $template_misc_array['header_source']=='yes' || $template_misc_array['header_rtypes']=='yes')){
			
			echo "<div id='wprev_search_sort_bar_id_".$formid."' data-tid='".$formid."' class='wprev_search_sort_bar'>";
			
			if($template_misc_array['header_search']=='yes'){
				echo '<input class="wprev_searchsort wprev_search" id="wprevpro_header_search_input" type="text" name="wprevpro_header_search_input" placeholder="'.esc_html($template_misc_array['header_search_place']).'" value="">';
			}
			if($template_misc_array['header_sort']=='yes'){
				echo '<select class="wprev_searchsort wprev_sort" name="wprevpro_header_sort" id="wprevpro_header_sort">
						<option value="" disabled selected>'.esc_html($template_misc_array['header_sort_place']).'</option>
						<option value="newest">'.__('Newest', 'wp-review-slider-pro').'</option>
						<option value="oldest">'.__('Oldest', 'wp-review-slider-pro').'</option>
						<option value="highest">'.__('Highest', 'wp-review-slider-pro').'</option>
						<option value="lowest">'.__('Lowest', 'wp-review-slider-pro').'</option>
						<option value="longest">'.__('Longest', 'wp-review-slider-pro').'</option>
						<option value="shortest">'.__('Shortest', 'wp-review-slider-pro').'</option>
						<option value="random">'.__('Random', 'wp-review-slider-pro').'</option>
				</select>';
			}
			if($template_misc_array['header_rating']=='yes'){
				echo '<select class="wprev_searchsort wprev_sort" name="wprevpro_header_rating" id="wprevpro_header_rating">
						<option value="unset" selected>'.esc_html($template_misc_array['header_rating_place']).'</option>
						<option value="1">'.__('1', 'wp-review-slider-pro').'</option>
						<option value="2">'.__('2', 'wp-review-slider-pro').'</option>
						<option value="3">'.__('3', 'wp-review-slider-pro').'</option>
						<option value="4">'.__('4', 'wp-review-slider-pro').'</option>
						<option value="5">'.__('5', 'wp-review-slider-pro').'</option>
				</select>';
			}
			if($template_misc_array['header_source']=='yes'){
				//get list of source pages and ids
				//pull distinct page names and page ids from reviews table
				$reviews_table_name = $wpdb->prefix . 'wpfb_reviews';
				//$tempquery = 	"SELECT DISTINCT pageid,pagename,type,from_url FROM ".$reviews_table_name." WHERE pageid IS NOT NULL";
				$tempquery = "select * from ".$reviews_table_name." group by pageid";
				$fbpagesrows = $wpdb->get_results($tempquery);

							//if we are selecting pages in the filter then we need to remove the ones not selected here.
								if($currentform[0]->rpage!=""){
									$rpagearray = json_decode($currentform[0]->rpage);
									//need to also check for &amp; in pageid, this is because of it getting saved wrong.
									if(isset($rpagearray) && is_array($rpagearray)){
										foreach ($rpagearray as &$value) {
											if(strpos($value, '&')){
												$newpageid = str_replace("&", "&amp;", $value);
												$rpagearraynew[] = $newpageid;
											}
										}
									}
									if(isset($rpagearraynew) && is_array($rpagearraynew)){
										$rpagearray = array_merge($rpagearray, $rpagearraynew);
									}
									//print_r($rpagearray);
								}
								
				echo '<select class="wprev_searchsort wprev_sort" name="wprevpro_header_source" id="wprevpro_header_source">
						<option value="unset" selected>'.esc_html($template_misc_array['header_source_place']).'</option>';
					foreach ( $fbpagesrows as $fbpage ){
						if($fbpage->pageid!=""){

							if(is_array($rpagearray) && count($rpagearray)>0){
								if (in_array($fbpage->pageid, $rpagearray)){
								  echo '<option value="'.$fbpage->pageid.'">'.$fbpage->pagename.'</option>';
								}
							} else {
								echo '<option value="'.$fbpage->pageid.'">'.$fbpage->pagename.'</option>';
							}
						}
					}
				echo '</select>';
			}
			if($template_misc_array['header_langcodes']=='yes'){
				$langcodestring = $template_misc_array['header_langcodes_list'];
				$langcodestring = preg_replace('/\s/', '', $langcodestring);	//remove whitespaces
				$langcodearray = array_filter(explode(",",$langcodestring));
				echo '<select class="wprev_searchsort wprev_sort" name="wprevpro_header_langcodes" id="wprevpro_header_langcodes">
						<option value="unset" selected>'.esc_html($template_misc_array['header_langcodes_place']).'</option>';
				foreach ($langcodearray as $value){ 
					echo '<option value="'.$value.'">'.$value.'</option>';
				} 
				echo '</select>';
			}
			//add loading image if needed
			if($template_misc_array['header_sort']=='yes' || $template_misc_array['header_search']=='yes' || $template_misc_array['header_rating']=='yes' || $template_misc_array['header_langcodes']=='yes'){
				echo '<img loading="lazy" src="'.$loading_img_url.'" alt="loading image" class="wprppagination_loading_image_search" style="display:none;">';
			}
			
			if($template_misc_array['header_tag']=='yes' & $template_misc_array['header_tags']!=''){
				//get array of header tags
				$str = esc_html( $template_misc_array['header_tags']);
				$tagarray = explode(",",$str);
				if(is_array($tagarray) && count($tagarray)>0){
					echo '<div class="wprevpro_searchtags_div">';
					$arrlength = count($tagarray);
					for($x = 0; $x < $arrlength; $x++) {
						echo '<span class="wprevpro_stag">'.trim($tagarray[$x]).'</span>';
					}
					echo '<img loading="lazy" src="'.$loading_img_url.'" class="wprppagination_loading_image_tag" style="display:none;">';
					echo '</div>';
				}
				//print_r($tagarray);
			}
			
			//adding header rtypes buttons if set.
			if(isset($template_misc_array['header_rtypes']) && $template_misc_array['header_rtypes']=='yes'){
				echo '<div class="wprevpro_rtypes_div">';
				//find types listed in this template. coming from get_reviewsclass
				foreach($totalreviewsarray['reviewtypesarray'] as $temptype){
					if($temptype!='' && $temptype!='Manual'){
						
						$img = WPREV_PLUGIN_URL."/public/partials/imgs/".strtolower($temptype)."_small_icon.png";
						$imgdir = WPREV_PLUGIN_DIR."public/partials/imgs/".strtolower($temptype)."_small_icon.png";
						//echo $img;
						if(file_exists($imgdir)){
							echo '<span class="wprevpro_stype_btn"><img class="wprevrtypebtn" src="'.$img.'" alt="'.$temptype.' filter" height="32">'.esc_html($temptype).'</span>';
						} else {
							echo '<span class="wprevpro_stype_btn">'.esc_html($temptype).'</span>';
						}
					}
				}
				// create html for each type.
				echo '<img loading="lazy" src="'.$loading_img_url.'" class="wprppagination_rtypes_loading_img" style="display:none;">';
				echo '</div>';
			}
			
			echo '</div>';
			
		}
		//=========end add search sort=================
		
		
		//=======start badge option ================
		
		//if we are adding a badge then wrap the slider in another outer div with flex box and add another div beside slider.
		if(!isset($template_misc_array['blocation'])){$template_misc_array['blocation']="";}
		
		if($template_misc_array['blocation']!=""){
			
			//preset in case this is an old template
			if(!isset($template_misc_array['bname'])){$template_misc_array['bname']='';}
			if(!isset($template_misc_array['bimgurl'])){$template_misc_array['bimgurl']='';}
			if(!isset($template_misc_array['bbtnurl'])){$template_misc_array['bbtnurl']='';}
			if(!isset($template_misc_array['bnameurl'])){$template_misc_array['bnameurl']='';}
			if(!isset($template_misc_array['bbtncolor'])){$template_misc_array['bbtncolor']='';}
			if(!isset($template_misc_array['bbkcolor'])){$template_misc_array['bbkcolor']='';}
			if(!isset($template_misc_array['bbradius'])){$template_misc_array['bbradius']='';}
			if(!isset($template_misc_array['bdropsh'])){$template_misc_array['bdropsh']='';}
			if(!isset($template_misc_array['bcenter'])){$template_misc_array['bcenter']='';}
			if(!isset($template_misc_array['bhname'])){$template_misc_array['bhname']='';}
			if(!isset($template_misc_array['bhphoto'])){$template_misc_array['bhphoto']='';}
			if(!isset($template_misc_array['bhbased'])){$template_misc_array['bhbased']='';}
			if(!isset($template_misc_array['bhbtn'])){$template_misc_array['bhbtn']='';}
			if(!isset($template_misc_array['filtersource'])){$template_misc_array['filtersource']='';}
			if(!isset($template_misc_array['bhpow'])){$template_misc_array['bhpow']='';}
			if(!isset($template_misc_array['bshape'])){$template_misc_array['bshape']='';}
			if(!isset($template_misc_array['brevus_fontcolor'])){$template_misc_array['brevus_fontcolor']='';}
			if(!isset($template_misc_array['brevus_txtval'])){$template_misc_array['brevus_txtval']='';}
			if(!isset($template_misc_array['bbtnurlopenin'])){$template_misc_array['bbtnurlopenin']='';}
			
			//get badge info
			$businessname = $template_misc_array['bname'];
			$imageurl = $template_misc_array['bimgurl'];
			$butnlinkurl = $template_misc_array['bbtnurl'];
			//echo $butnlinkurl;
			if($butnlinkurl=="" && isset($totalreviews[0]->from_url)){
				//echo "here";
				$butnlinkurl=$totalreviews[0]->from_url;
			}
			//echo $butnlinkurl;
			
			$bnameurl = $template_misc_array['bnameurl'];
			//if blank then link to location in first review.
			if($bnameurl=="" && isset($totalreviews[0]->from_url)){
				$bnameurl=$totalreviews[0]->from_url;
			}
			$bbtnurlopenin = $template_misc_array['bbtnurlopenin'];
			
			$bbtncolor = esc_html($template_misc_array['bbtncolor']);
			$bbackgroundcolor = esc_html($template_misc_array['bbkcolor']);
			$bborderradius = intval(esc_html($template_misc_array['bbradius']));
			$bdropsh = esc_html($template_misc_array['bdropsh']);
			$bcenter = esc_html($template_misc_array['bcenter']);	//center the image above and center text below.
			$bshape = esc_html($template_misc_array['bshape']);	//round or square
			
			$brevus_fontcolor = esc_html($template_misc_array['brevus_fontcolor']);
			
			$bhname = esc_html($template_misc_array['bhname']);	//hide the name
			$bhnameclass = "";
			if($bhname =="yes"){$bhnameclass = "badgehideclass";}
			
			$bhphoto = esc_html($template_misc_array['bhphoto']);	//hide the photo
			$bhphotoclass = "";
			if($bhphoto =="yes"){$bhphotoclass = "badgehideclass";}
			
			$bhbased = esc_html($template_misc_array['bhbased']);	//hide the based on text
			$bhbasedclass = "";
			if($bhbased =="yes"){$bhbasedclass = "badgehideclass";}
			
			$bhbtn = esc_html($template_misc_array['bhbtn']);	//hide the review us button
			$bhbtnclass = "";
			if($bhbtn =="yes"){$bhbtnclass = "badgehideclass";}
			
			$bhpow = esc_html($template_misc_array['bhpow']);	//hide the powered by
			$bhpowclass = "";
			if($bhpow =="yes"){$bhpowclass = "badgehideclass";}
			
			$brevus_txtval = __('Review Us', 'wp-review-slider-pro');
			if($template_misc_array['brevus_txtval']!=""){
				$brevus_txtval = esc_html($template_misc_array['brevus_txtval']);
			}

			$brevusbtnhtml = "test";
			$brevuslinkstart = "";
			$brevuslinkend = "";
			$brevuslinkhref = "";
			if($bhbtnclass!="yes"){		//we are showing a button, what kind......
				
			$brevusbtnhtml ='<div class="wprevpro_bbnrevus_btn">'.$brevus_txtval.'</div>';
			if($template_misc_array['brevus_btnaction']=="link"){
				$temptarget = 'target="_blank"';
				if($bbtnurlopenin=="same"){
					$temptarget = '';
				}
				$brevusbtnhtml = '<a class="wprev-google-wr-a" href="'.sanitize_url($butnlinkurl).'" '.$temptarget.'>'.$brevus_txtval.'</a>';
				
			} else if($template_misc_array['brevus_btnaction']=="ddlinks"){
					//multiple links, we need to build hidden drop down list that we show when clicked or pushed
					$brevusbtnhtml = '<div class="wprevpro_bbnrevus_btn wprevdropbtnb wprev-google-wr-a">'.$brevus_txtval.'</div>
					<div class="wprevdropdown-content_badge">';
					if(!isset($template_misc_array['brevus_btnln'])){$template_misc_array['brevus_btnln']=Array();}
					if(!isset($template_misc_array['brevus_btnlu'])){$template_misc_array['brevus_btnlu']=Array();}
					$temptarget = 'target="_blank"';
					if($bbtnurlopenin=="same"){
						$temptarget = '';
					}
					for ($x = 1; $x <= 6; $x++) {
						if(isset($template_misc_array['brevus_btnlu'][$x]) && isset($template_misc_array['brevus_btnln'][$x])){
							if($template_misc_array['brevus_btnlu'][$x]!='' && $template_misc_array['brevus_btnln'][$x]!=''){
						$brevusbtnhtml = $brevusbtnhtml. '<a '.$temptarget.' href="'.sanitize_text_field($template_misc_array['brevus_btnlu'][$x]).'">'.sanitize_text_field($template_misc_array['brevus_btnln'][$x]).'</a>';
							}
						}
					}
					$brevusbtnhtml = $brevusbtnhtml. '</div>';
				} else if($template_misc_array['brevus_btnaction']=="form"){
					//need to add form to page and pop-up when pushing the button.
					//$template_misc_array['revus_puform'] is form id.
					$brevusbtnhtml ='<div class="wprevpro_bbnrevus_btn bnrevuspopform wprev-google-wr-a" data-formid="'.$template_misc_array['brevus_puform'].'">'.$brevus_txtval.'</div>';
					
					//get form array from db
					$reviewformid = intval($template_misc_array['brevus_puform']);
	
					$formhtml=$this->getformhtml($reviewformid);
					echo $formhtml;
					
				}
			}
			

			$badge_style = "";
			$badge_style = $badge_style . '.wprev-google-wr-a {background: '.$bbtncolor.' !important; color:'.$brevus_fontcolor.' !important}';
			$badge_style = $badge_style . '.wprev-google-wr-a:hover {background: '.$bbtncolor.'de !important;}';

			$badge_style = $badge_style . '.wprev-google-place {background: '.$bbackgroundcolor.' !important;border-radius:'.$bborderradius.'px !important;}';
			if($bdropsh=="yes"){
				$badge_style = $badge_style . '.wprev-google-place {box-shadow: rgba(0, 0, 0, .08) 2px 2px 3px 0px !important;}';
			} else {
				$badge_style = $badge_style . '.wprev-google-place {box-shadow: rgba(0, 0, 0, .00) 0px 0px 0px 0px !important; border: 0px solid #f5f5f5 !important;}';
			}
			if($bcenter=="yes" && $template_misc_array['blocation']!="abovewide"){
				$badge_style = $badge_style . '.wprev-google-place {flex-direction: column !important;align-items: center !important;}';
				$badge_style = $badge_style . '.wprev-google-right {display: flex!important;align-items: center!important;flex-direction: column!important;}';
				$badge_style = $badge_style . '.wprev-google-name{margin-bottom: 3px !important;}';
			}
			if($bshape=="round"){
				$badge_style = $badge_style . 'img.sprev-google-left-src {border-radius: 50% !important;}';
			}
			
			//finally getting average and total here.
			$templaceid = "template_".$currentform[0]->id;
			$badgeavg = "";
			$badgetotal = "";
			if($templaceid!=""){
				//grab average and total for each from avg total
				//If this header is on a template that uses the product ID filter then we need to change the total/avg.
				if($template_misc_array['postfilter']=='yes'){
					$templaceid = $totalreviewsarray['reviewspagesarray'][0];
				}
				$table_name_avg = $wpdb->prefix . 'wpfb_total_averages';
				$currentlocation = $wpdb->get_results("SELECT * FROM $table_name_avg WHERE `btp_id` = '".$templaceid."' LIMIT 1");

				
				$revtypearray = json_decode($currentlocation[0]->pagetypedetails,true);
				//print_r($revtypearray);
				
				//we have to filter this out if we are filtering by page or type.

				$badgeavg = $currentlocation[0]->avg;
				$badgetotal = intval($currentlocation[0]->total);
				
				$typeicons="";
				if (!empty($revtypearray) && is_iterable($revtypearray)) {
					foreach ($revtypearray as $xtype => $ytypearray) {
						//either svg or png
						$tempfileext = "svg";
						if ( !file_exists( WPREV_PLUGIN_DIR."/public/partials/imgs/".strtolower($xtype)."_small_icon.svg" ) ) {
							$tempfileext = "png";
						}
						$tempfilesrcall = WPREV_PLUGIN_URL.'/public/partials/imgs/'.strtolower($xtype).'_small_icon.'.$tempfileext;

						//if $xtype is in WPREV_CUSTOM_SOURCES_ICON_URLS_ARRAY then use the icon_url from the array
					$custom_sources_icon_urls_array = unserialize(WPREV_CUSTOM_SOURCES_ICON_URLS_ARRAY);
					if(is_array($custom_sources_icon_urls_array) && isset($custom_sources_icon_urls_array[$xtype])){
						$tempfilesrcall = $custom_sources_icon_urls_array[$xtype];
						}

					  //echo "$xtype : $ytypearray <br>";
					  $typeicons = $typeicons . '<img width="16" height="16" src="'.$tempfilesrcall.'" alt="'.$xtype.' Logo" class="wprevpro_badge_site_logo wprevsiteicon ">';
					  //$typeicons2 = $typeicons2 . '<img width="18" height="18" src="'.WPREV_PLUGIN_URL.'/public/partials/imgs/'.strtolower($xtype).'_small_icon.'.$tempfileext.'" alt="'.$xtype.' Logo" class="wprevpro_badge_site_logo2 wprevsiteicon ">';
					}
				}
			}

			//if aiinbadge is yes then add the ai summary to the badge
			$badgeaisummary = '';
			if(isset($template_misc_array['aiinbadge']) && $template_misc_array['aiinbadge']=="yes"){
				// Parse the AI summary JSON data
				$ai_summary_data = json_decode(stripslashes($template_misc_array['aisummarytext']), true);
				
				if($ai_summary_data && is_array($ai_summary_data)){
					// Extract AI summary data
					$overall_sentiment = isset($ai_summary_data['overall_sentiment']) ? $ai_summary_data['overall_sentiment'] : 'positive';
					$average_rating = isset($ai_summary_data['average_rating']) ? floatval($ai_summary_data['average_rating']) : 5.0;
					$common_praises = isset($ai_summary_data['common_praises']) ? $ai_summary_data['common_praises'] : array();
					$common_complaints = isset($ai_summary_data['common_complaints']) ? $ai_summary_data['common_complaints'] : array();
					$summary_text = isset($ai_summary_data['summary_text']) ? $ai_summary_data['summary_text'] : '';
					
					// Build structured HTML for badge AI summary
					$badgeaisummary = '<div class="wprev-google-ai-summary" style="padding: 16px;flex-basis: 100%;min-width: 200px;">';
					
					// AI Summary Header
					$badgeaisummary .= '<div style="display: flex; align-items: center; margin-bottom: 12px;">';
					$badgeaisummary .= '<img loading="lazy" src="'.WPREV_PLUGIN_URL.'/public/partials/imgs/ai_avatar_min.png" alt="AI Summary Avatar" class="wprevpro_avatarimg wprev-header-ai-summary-icon">';
					$badgeaisummary .= '<div style="font-weight: bold; font-size: 16px; color: #1f2937;">AI Summary</div>';
					$badgeaisummary .= '</div>';
					
					// Summary Text
					if(!empty($summary_text)){
						$badgeaisummary .= '<div style="margin-bottom: 12px; line-height: 1.6; color: #374151;">' . esc_html($summary_text) . '</div>';
					}
					
					// Praises Section
					if(!empty($common_praises) && (!isset($template_misc_array['show_praises']) || $template_misc_array['show_praises'] == 'yes')){
						$badgeaisummary .= '<div style="margin-bottom: 8px;">';
						$badgeaisummary .= '<div style="font-weight: bold; margin-bottom: 4px; font-size: 14px;">What customers love:</div>';
						$badgeaisummary .= '<div style="color: #6b7280; line-height: 1.5;">' . implode(' • ', array_map('esc_html', $common_praises)) . '</div>';
						$badgeaisummary .= '</div>';
					}
					
					// Complaints Section
					if(!empty($common_complaints) && (!isset($template_misc_array['show_complaints']) || $template_misc_array['show_complaints'] == 'yes')){
						$badgeaisummary .= '<div style="margin-bottom: 8px;">';
						$badgeaisummary .= '<div style="font-weight: bold; margin-bottom: 4px; font-size: 14px;">Areas for improvement:</div>';
						$badgeaisummary .= '<div style="color: #6b7280; line-height: 1.5;">' . implode(' • ', array_map('esc_html', $common_complaints)) . '</div>';
						$badgeaisummary .= '</div>';
					}
					
					$badgeaisummary .= '</div>';
				} else {
					// Fallback to raw text if JSON parsing fails
					$badgeaisummary = '';
				}
			}

			//if this is left mid then add a style
			if($template_misc_array['blocation']=="leftmid" || $template_misc_array['blocation']=="rightmid" ){
				$badge_style = $badge_style . '.wprev_outer_wb {align-items: center !important;}';
			}
			//if this is above then we slightly change html again
			if($template_misc_array['blocation']=="above"){
				$badge_style = $badge_style . '.wprev_outer_wb {flex-direction: column !important;}.wprev_badge_div.badgeleft {margin-left: auto !important;margin-right: auto !important;}';
			}
			//if this is above and wide then we change html again
			$badgeabovewide1 = '';
			$badgeabovewide2 = '';
			$badgeabovewideclose ='';
			if($template_misc_array['blocation']=="abovewide"){
				
					$tempmargin = "margin: 0px 20px !important;";	//for grid
				if($currentform[0]->createslider == "yes"){		//for normal slider
					$tempmargin = "margin: 0px 50px !important;";
				}
				if($currentform[0]->createslider == "sli"){		//for slick slider
					$tempmargin = "margin: 0px 50px !important;";
				}
				
				
				$badge_style = $badge_style . '.wprev_outer_wb {flex-direction: column !important;}.wprev_badge_div.badgeleft {'.$tempmargin.'}.wprev-google-place {justify-content: space-between !important;align-items: center !important;}.wprev-google-leftboth {display: flex !important;}';
				$badgeabovewide1 = '<div class="wprev-google-leftboth">';
				$badgeabovewide2 = '<div class="wprev-google-right">';
				$badgeabovewideclose = '</div>'; 
			}
			
			$bimgsize = 50;
			if(isset($template_misc_array['bimgsize']) &&  $template_misc_array['bimgsize']>0){
				$bimgsize =$template_misc_array['bimgsize'];
				$badge_style = $badge_style . 'img.sprev-google-left-src {min-width: '.$bimgsize.'px !important;min-height: '.$bimgsize.'px !important;}';
			}
			
			echo "<style>".$badge_style."</style>";
			echo '<div class="wprev_outer_wb">'; 
			
			$badgehtml = '<div class="wprev-google-place">'.$badgeabovewide1.'<div class="wprev-google-left '.$bhphotoclass.'"><img class="sprev-google-left-src" src="'.esc_url($imageurl).'" alt="'.esc_attr($businessname).'" width="'.$bimgsize.'" height="'.$bimgsize.'" title="'.esc_attr($businessname).'"></div><div class="wprev-google-right"><div class="wprev-google-name '.$bhnameclass.'"><a href="'.esc_url($bnameurl).'" target="_blank" rel="nofollow noopener"><span class="wprev-businessname">'.esc_html($businessname).'</span></a></div><div class="wprevstardiv"><span class="wprev-google-rating">'.$badgeavg.'</span><span class="wprevpro_star_imgs_T1"><span class="starloc1 wprevpro_star_imgs wprevpro_star_imgsloc1"><span class="svgicons svg-wprsp-star"></span><span class="svgicons svg-wprsp-star"></span><span class="svgicons svg-wprsp-star"></span><span class="svgicons svg-wprsp-star"></span><span class="svgicons svg-wprsp-star"></span></span></span></div><div class="wprev-google-basedon '.$bhbasedclass.'">Based on <span class="wprev_btot">'.$badgetotal.'</span> reviews</div>'.$badgeabovewideclose.$badgeabovewideclose.$badgeabovewide2.'<div class="wprev-google-powered '.$bhpowclass.'"><img class="wprev-google-powered-img" src="'.WPREV_PLUGIN_URL.'/public/partials/imgs/poweredbygooglew.png" alt="powered by " width="82" height="18" title="powered by ">'.$typeicons.'</div><div class="wprev-google-wr '.$bhbtnclass.'">'.$brevusbtnhtml.'</div></div>'.$badgeaisummary.'</div>';
			//echo $badgeaisummary;
							
		}
		//actually adding badge html here for left and top
		if($template_misc_array['blocation']=="left" || $template_misc_array['blocation']=="leftmid" || $template_misc_array['blocation']=="above" || $template_misc_array['blocation']=="abovewide"){

			echo '<div class="wprev_badge_div badgeleft">';
			//this is where we could load badge styles in Pro version.
			
			echo $badgehtml;
			//echo $badgeaisummary;
				
			echo '</div>';
			
		}
		if($template_misc_array['blocation']!=""){
			echo '<div class="wprev_badge_div badgereviewscontainer">';
		}
	//=====end add badge, more at end.
		
		



		//find out if making same height and addclass so we can ues in js
		if($currentform[0]->review_same_height=='yes' || $currentform[0]->review_same_height=='cur' || $currentform[0]->review_same_height=='yea'){
			$notsameheight="";
		} else {
			//only using for non-slider
			$notsameheight="revnotsameheight";
		}

		//get total reviews and reviews per a row
		$totalreviewsnum = count($totalreviews);
		
		//check if total number of reviews is less than or equal to reviewsonslide and masonry turned on then do not create slider
		if(	$currentform[0]->display_masonry=="yes" && $totalreviewsnum<=$reviewsperpage && $currentform[0]->createslider != "no"){
			$currentform[0]->createslider ="no";
		}
		
		//need to pass this to javascript file
		$revsameheight = 'no';
		if($currentform[0]->review_same_height!=""){
			if($currentform[0]->review_same_height=='yes' || $currentform[0]->review_same_height=='cur' || $currentform[0]->review_same_height=='yea'){
				$revsameheight = 'yes';
			}
		}
		
		//if making slide show then add it here
		if($currentform[0]->createslider == "yes"){
			//make sure we have enough to create a show here
			if($totalreviewsnum>$reviewsperpage){
				$makingslideshow = true;
				$ismakingslideshow = "yes";
				$rtltag = '';
				if ( is_rtl() ) {
					$rtltag = 'dir="rtl"';
				}
				$mobileoneperslide = "";
				$animateHeightslider = '';
				if(isset($currentform[0]->slidermobileview) && $currentform[0]->slidermobileview == "one"){
					$mobileoneperslide = 'data-onemobil="yes"';
				}
				if($currentform[0]->sliderheight!="" && $currentform[0]->sliderheight=='yes'){
					$animateHeightslider = 'animateheight';
				}
				
				//attributes passing to js.----------
				if($currentform[0]->sliderautoplay!="" && $currentform[0]->sliderautoplay=='yes'){
					$autoplay = 'true';
					$autoplayjson ='"autoplay": true';
				} else {
					$autoplay = 'false';
					$autoplayjson ='"autoplay": false';
				}
				if($currentform[0]->sliderspeed!="" && intval($currentform[0]->sliderspeed)>0){
					$sliderspeed = intval($currentform[0]->sliderspeed);
					$sliderspeedjson =',"sliderspeed": '.$sliderspeed;
				} else {
					$sliderspeed = "750";
					$sliderspeedjson =',"sliderspeed": '.$sliderspeed;
				}
				
				if($currentform[0]->sliderdelay!="" && intval($currentform[0]->sliderdelay)>0){
					$delay = intval($currentform[0]->sliderdelay)*1000 + $sliderspeed;;
					$delayjson =',"delay": '.$delay;
				} else {
					$delay = 3000 + $sliderspeed;
					$delayjson =',"delay": '.$delay;
				}
				if($currentform[0]->sliderdirection=='vertical' || $currentform[0]->sliderdirection=='horizontal' || $currentform[0]->sliderdirection=='fade'){
					$animation = $currentform[0]->sliderdirection;
					$animationjson =',"animation": "'.$animation.'"';
				} else {
					$animation = 'horizontal';
					$animationjson =',"animation": "'.$animation.'"';
				}

				if($currentform[0]->sliderarrows!="" && $currentform[0]->sliderarrows=='no'){
					$arrows = 'false';
					$arrowsjson =',"arrows": '.$arrows;
				} else {
					$arrows = 'true';
					$arrowsjson =',"arrows": '.$arrows;
				}
				$forceheight ='';
				$forceheightjson =',"forceheight": "no"';
				if($currentform[0]->review_same_height!=""){
					if($currentform[0]->review_same_height=='yes' || $currentform[0]->review_same_height=='cur' || $currentform[0]->review_same_height=='yea'){
						$forceheightjson =',"forceheight": "yes"';
					}
				}
				if($currentform[0]->sliderheight!="" && $currentform[0]->sliderheight=='yes' && $forceheight==''){
					$animateHeight = 'true';
					$animateHeightjson =',"animateHeight": '.$animateHeight;
				} else {
					$animateHeight = 'false';
					$animateHeightjson =',"animateHeight": '.$animateHeight;
				}
				//for making the arrows not move
				$sliderarrowheightjson =',"sliderarrowheight": "no"';
				if(!isset($inslideout)){
					$inslideout='';
				}
				if($arrows == 'true' && $inslideout!="yes"){
					$sliderarrowheightjson =',"sliderarrowheight": "yes"';
				}
				//for adding load more js if needed.
				$loadmorerslijson = ',"loadmorersli": "no"';
				if(isset($currentform[0]->load_more) && $currentform[0]->load_more=="yes"){
					$loadmorerslijson = ',"loadmorersli": "yes"';
				}
				$totalreviewsarrayjson = ',"totalreviewsarray": 0';
				if($totalreviewsarray['totalcount']>0){
				$totalreviewsarrayjson = ',"totalreviewsarray": '.$totalreviewsarray['totalcount'];
				}
				$reviewsperpagejson = ',"reviewsperpage": '.$reviewsperpage;
				
				$checkfloatdelayjson = ',"checkfloatdelay": 0';
				if(isset($insidefloat) && $animatedelay>0){
					//go back to the first slide .5 seconds before
					$slideanimatedelay = $animatedelay*1000-50;
					$checkfloatdelayjson = ',"checkfloatdelay": '.$slideanimatedelay;
				}
				$thissliderid = ',"sliderid":'.$currentform[0]->id;
				$iswidgetjson = ',"iswidget":false';
				
				echo '<div style="display:none;" class="wprevpro wprev-slider '.$notsameheight.' '.$animateHeightslider.'" '.$mobileoneperslide.' '.$rtltag.' id="wprev-slider-'.$currentform[0]->id.'" data-revsameheight="'.$revsameheight.'" data-slideprops=\'{'.$autoplayjson.''.$delayjson.''.$animationjson.''.$sliderspeedjson .''.$arrowsjson.''.$animateHeightjson.''.$forceheightjson.''.$sliderarrowheightjson.''.$loadmorerslijson.''.$totalreviewsarrayjson.''.$reviewsperpagejson.''.$checkfloatdelayjson.''.$thissliderid.''.$iswidgetjson.'}\'>';
				
			} else {
				echo '<div class="wprevpro wprev-no-slider '.$notsameheight.'" id="wprev-slider-'.$currentform[0]->id.'">';
			}
		} else if($currentform[0]->createslider == "sli"){
			echo '<div class="wprevpro wprev-slick-slider '.$notsameheight.'" id="wprev-slider-'.$currentform[0]->id.'">';
		} else {
			//not making slideshow
			echo '<div class="wprevpro wprev-no-slider '.$notsameheight.'" id="wprev-slider-'.$currentform[0]->id.'">';

		}		
		

		if($currentform[0]->createslider == "yes" && $makingslideshow){
					echo '<ul>';
			$totalreviewschunked = array_chunk($totalreviews, $reviewsperpage);
		} else if($currentform[0]->createslider == "sli"){
			$totalreviewschunked = array_chunk($totalreviews, $reviewsperpage);
		} else {
			if($totalreviewsnum>0){
			$totalreviewschunked = array_chunk($totalreviews, $totalreviewsnum);
			} else {
				//$totalreviewschunked = array_chunk($totalreviews, $totalreviewsnum);
			}
		}
		
		//================================
		//if making slick slider------------
		//==================================
		$slickrtl = '';
		$slickrtlhtml ='';
		$slickavatarnav = false;
		if($currentform[0]->createslider == "sli"){
				
			//avatar navigation
			$dataavatartemplate = 'data-avatartemplate="0"';
			$sli_asnavfor = '';
			if(isset($template_misc_array['sli_avatarnav']) && $template_misc_array['sli_avatarnav']=='yes'){
				$slickavatarnav = true;
				//force slidestoscroll to 1.
				$sli_slidestoscroll =',"slidesToScroll": 1';
				//change template setting to avatar only.
				$dataavatartemplate = 'data-avatartemplate="'.esc_attr($currentform[0]->style).'"';
				//change the $totalreviewschunked to force one slide at a time and then will use previous value to add another slider with just faces
				$totalreviewschunkedoriginal = $totalreviewschunked;
				$reviewsperpagetemp = 1;
				$totalreviewschunked = array_chunk($totalreviews, $reviewsperpagetemp);
				$org_display_num_rows = intval($currentform[0]->display_num_rows);
				$org_display_num = intval($currentform[0]->display_num);
				$currentform[0]->display_num_rows = 1;
				$currentform[0]->display_num = 1;
				$currentform[0]->sliderarrows = 'no';
				$currentform[0]->sliderdots='no';

				$sli_asnavfor =', "asNavFor": "#wprevgoslickidnav_'.intval($currentform[0]->id).'"';
			}
			
			
			if ( is_rtl() ) {
					$slickrtl = ', "rtl":true';
					$slickrtlhtml = 'dir="rtl"';
				}
			$sli_rows = ', "rows":'.intval($currentform[0]->display_num_rows).'';		//used to create a grid mode with slidesPerRow
			$slidesetup ='"slidesToShow": '.intval($currentform[0]->display_num);
			$sli_slidestoscroll =',"slidesToScroll": '.intval($currentform[0]->display_num);
			//fix if only a few reviews returned.
			if($totalreviewsnum < $currentform[0]->display_num){
				$slidesetup ='"slidesToShow": '.intval($totalreviewsnum);
				$sli_slidestoscroll =',"slidesToScroll": '.intval($totalreviewsnum);
				$sli_rows = ', "rows":1';
			}
			$sli_autoplay = '';
			$sli_autoplaySpeed = '';
			$sli_autoplaySpeedval = 3000;
			
			$sli_infinite =',"infinite": false';
			$sli_Speedval = 750;
			$sli_Speed = ',"speed": '.$sli_Speedval.'';
			$sli_dots = ',"dots": true';
			$sli_arrows = ',"arrows": true';
			$sli_adaptiveheight = ',"adaptiveHeight": false';
			$sli_fade = ',"fade":false';
			$sli_dataloadmore = 'data-loadmore="no"';
			
			//if we are loading more at end
			if(isset($currentform[0]->load_more) && $currentform[0]->load_more=="yes"){
				$sli_dataloadmore = 'data-loadmore="yes"';
			}

			//slides to scroll one at a time
			if(isset($template_misc_array['sli_slidestoscroll']) && $template_misc_array['sli_slidestoscroll']=='yes'){
				$sli_slidestoscroll =',"slidesToScroll": 1';
			}
			
			if($currentform[0]->sliderautoplay!="" && $currentform[0]->sliderautoplay=='yes'){
				$sli_autoplay = ',"autoplay": true';
			}
			if($currentform[0]->sliderdelay!="" && $sli_autoplay!=''){
				$sli_autoplaySpeedval = intval($currentform[0]->sliderdelay)*1000;
				$sli_autoplaySpeed = ',"autoplaySpeed": '.$sli_autoplaySpeedval.'';
				//change to linear easing if 0 delay.
				if($sli_autoplaySpeedval==0){
					$sli_autoplaySpeed = $sli_autoplaySpeed . ',"cssEase": "linear"';
				}
			}
			//echo $currentform[0]->sliderspeed;
			if($currentform[0]->sliderspeed!="" && intval($currentform[0]->sliderspeed)>0){
				$sli_Speedval = intval($currentform[0]->sliderspeed);
				$sli_Speed = ',"speed": '.$sli_Speedval.'';
			}
			if($currentform[0]->sliderdirection=='fade'){
				if($currentform[0]->display_num>1){
					//have to force slidesToScroll to slidesToShow
					$sli_slidestoscroll =',"slidesToScroll": '.$currentform[0]->display_num;
					$sli_Speed = ',"speed": 0,"cssEase": "linear"';
					//have to hack a solution if we are showing more than one review and fade is true
					$sli_transition = $sli_Speedval/1000;
					//add some CSS
					echo '<style>#wprev-slider-'.$currentform[0]->id.' .slickwprev-slide:not(.slickwprev-current):not(.slickwprev-active) {opacity: 0;transition: opacity '.$sli_transition.'s linear;}
					#wprev-slider-'.$currentform[0]->id.' .slickwprev-active{opacity: 1;transition: opacity '.$sli_transition.'s linear;}</style>';
				} else {
					$sli_fade = ',"fade":true';
				}
			}
			//hiding or showing dots
			if($currentform[0]->sliderdots=='no'){
				$sli_dots = ',"dots": false';
			}
			//hide or showing arrows
			if($currentform[0]->sliderarrows=='no'){
				$sli_arrows = ',"arrows": false';
			}
			//adaptive height
			if($currentform[0]->sliderheight=='yes'){
				$sli_adaptiveheight = ',"adaptiveHeight": true';
				//we have to hack this if it is more than one review per a slide, code is js file.
				echo '<style>#wprev-slider-'.$currentform[0]->id.' .slick-list {transition: all .5s ease;}</style>';
			}
			//infinite slide
			if(isset($template_misc_array['sli_infinite']) && $template_misc_array['sli_infinite']=='yes'){
				$sli_infinite =',"infinite": true';
			}
			//center mode
			if(isset($template_misc_array['sli_centermode']) && $template_misc_array['sli_centermode']=='yes'){
				$sli_centermode =',"centerMode": true';
				//force to show and scroll one slide since this is center mode
				//$slidesetup ='"slidesToShow": 1';
				//$sli_slidestoscroll =',"slidesToScroll": 1';
			} else {
				$sli_centermode =',"centerMode": false';
			}
			//center mode padding
			$sli_centermode_padding = ',"centerPadding": "40px"';
			if(isset($template_misc_array['sli_centermode_padding']) && $template_misc_array['sli_centermode_padding']>0){
				$sli_centermode_padding =',"centerPadding": "'.$template_misc_array['sli_centermode_padding'].'px"';
			}
			
			//if we are doing continous slide then we need to force scroll one at a time.
			if($sli_autoplaySpeedval==0){
			$sli_slidestoscroll =',"slidesToScroll": 1';
			}


			echo '<div id="wprevgoslickid_'.esc_attr($currentform[0]->id).'" '.$slickrtlhtml.' style="display:none;" class="wprevgoslick w3_wprs-row" '.$dataavatartemplate.' data-totalreviewsnum="'.$totalreviewsnum.'" data-revsperrow="'.intval($currentform[0]->display_num).'" data-wprevmasonry="'.esc_attr($currentform[0]->display_masonry).'" '.$sli_dataloadmore.' data-avatarnav="no" data-revsameheight="'.$revsameheight.'" data-slickwprev=\'{'.$slidesetup.''.$sli_slidestoscroll.''.$sli_dots.''.$sli_arrows.''.$sli_infinite.''.$sli_Speed.''.$sli_adaptiveheight.$sli_centermode.$sli_fade.$sli_centermode_padding.$slickrtl.$sli_rows.$sli_autoplay.$sli_autoplaySpeed.$sli_asnavfor.'}\'>';
		}
		//---------end slick slider-----------------------
		
		//only using this variable for using filter on sli ajax load
		$sliusingfilter=false;
	
		//loop through each chunk
		foreach ( $totalreviewschunked as $reviewschunked ){
			//echo "loop1";
			$totalreviewstemp = $reviewschunked;
			//print_r($totalreviewstemp);
			//need to break $totalreviewstemp up based on how many rows, create an multi array containing them
			if($currentform[0]->display_num_rows>1 && count($totalreviewstemp)>$currentform[0]->display_num){
				//count of reviews total is greater than display per row then we need to break in to multiple rows
				for ($row = 0; $row < $currentform[0]->display_num_rows; $row++) {
					$n=1;
					foreach ( $totalreviewstemp as $tempreview ){
						//echo "<br>".$tempreview->reviewer_name;
						if($n>($row*$currentform[0]->display_num) && $n<=(($row+1)*$currentform[0]->display_num)){
							//echo $row."-".$n."-".$tempreview->reviewer_name."<br>";
							$rowarray[$row][$n]=$tempreview;
						}
						$n++;
					}
				}
			} else {
				//everything on one row so just put in multi array
				$rowarray[0]=$totalreviewstemp;
			}
			
			//if making slide show
			if($makingslideshow){
					echo '<li>';
			}

			//include the correct tid here
			if($currentform[0]->style=="1" || $currentform[0]->style=="2" || $currentform[0]->style=="3" || $currentform[0]->style=="4" || $currentform[0]->style=="5" || $currentform[0]->style=="6" || $currentform[0]->style=="7" || $currentform[0]->style=="8" || $currentform[0]->style=="9" || $currentform[0]->style=="10" || $currentform[0]->style=="11" || $currentform[0]->style=="12" || $currentform[0]->style=="13" || $currentform[0]->style=="14" || $currentform[0]->style=="15"){
				$iswidget=false;
				//display_masonry-------------
				//print_r($currentform[0]);
				if(	$currentform[0]->display_masonry=="yes" && $currentform[0]->createslider != "sli"){
					if($makingslideshow){
						$masonryclass = "wprs_masonry";
						$masonryclass_item = "wprs_masonry_item";
					} else {
						$masonryclass = "wprs_masonry_js";
						$masonryclass_item = "wprs_masonry_item_js";
					}
					echo '<div class="'.$masonryclass.'" data-numcol="'.$currentform[0]->display_num.'">';
				}	//display_masonry-------------

				$iswidget=false;
				$ajaxsliload = false;


				if($currentform[0]->style=='1'){
					include(plugin_dir_path( __FILE__ ) . 'template_style_'.$currentform[0]->style.'.php');
				} else {
					if ( wrsp_fs()->can_use_premium_code() ) {
						include(plugin_dir_path( __FILE__ ) . 'template_style_'.$currentform[0]->style.'.php');
					}
				}
				
				
				//display_masonry------------
				if(	$currentform[0]->display_masonry=="yes" && $currentform[0]->createslider != "sli"){
					echo '</div>';
				}
				//display_masonry------------
			}
			

			//if making slide show then end loop here
			if($makingslideshow){
					echo '</li>';
			}
			
			unset($rowarray);
			
		}	//end loop chunks
		
		//end slick div here.
		if($currentform[0]->createslider == "sli"){
			echo '</div>';
		}
		//if we are creating avatar navigation then we create another simple slider here with just avatars that will control slider above
		//=============================
		if($slickavatarnav){
			$totalreviewschunked = $totalreviewschunkedoriginal;
			$totalreviewschunked = array_chunk($totalreviews, $reviewsperpage);
			//$currentform[0]->display_num_rows = $org_display_num_rows;
			$currentform[0]->display_num_rows = 1;
			$currentform[0]->display_num = $org_display_num;
			if ( is_rtl() ) {
				$slickrtl = ', rtl:true';
			}
			$sli_rows = ', "rows":'.intval($currentform[0]->display_num_rows).'';		//used to create a grid mode with slidesPerRow
			$slidesetup ='"slidesToShow": '.intval($currentform[0]->display_num);
			$sli_autoplay = '';
			$sli_autoplaySpeed = '';
			$sli_slidestoscroll =',"slidesToScroll": 1';
			$sli_arrows = ',"arrows": true';
			$sli_fade = ',"fade":false';
			$sli_adaptiveheight = ',"adaptiveHeight": false';
			echo '<div class="wprevgoslicknavcontainer"><div id="wprevgoslickidnav_'.intval($currentform[0]->id).'" style="display:none;" class="wprevgoslick w3_wprs-row-padding" '.$dataavatartemplate.' data-avatarnav="yes" '.$sli_dataloadmore.' data-wprevmasonry="'.esc_attr($currentform[0]->display_masonry).'" data-slickwprev=\'{'.$slidesetup.''.$sli_slidestoscroll.''.$sli_dots.''.$sli_arrows.''.$sli_infinite.''.$sli_Speed.''.$sli_adaptiveheight.', "asNavFor": "#wprevgoslickid_'.intval($currentform[0]->id).'", "centerMode": true'.$sli_fade.', "centerPadding": "0px"'.$slickrtl.$sli_rows.$sli_autoplay.$sli_autoplaySpeed.'}\'>';
			
			//loop through each chunk
		foreach ( $totalreviewschunked as $reviewschunked ){

			$totalreviewstemp = $reviewschunked;
			//everything on one row so just put in multi array
			$rowarray[0]=$totalreviewstemp;
				
				include(plugin_dir_path( __FILE__ ) . 'avatarnav.php');
				unset($rowarray);
		}
		echo '</div></div>';

		}//===============================================
		
		

		//---add load more button if turned on
		$jslastslide ='';
		if(isset($currentform[0]->load_more) && $currentform[0]->load_more=="yes"){
			//if sort is random or picking reviews then we need to add the ids to button so we can test and do a NOT IN call 
			$notinstring='';
			//if($currentform[0]->display_order=="random" && $currentform[0]->showreviewsbyid!=""){
				$alreadygrabbedreviews=Array();
				for ($x = 0; $x < count($totalreviews); $x++) {
					if(isset($totalreviews[$x]->id)){
						$alreadygrabbedreviews[] = $totalreviews[$x]->id;
					}
				}
				$notinstring= implode(",",$alreadygrabbedreviews);
			//}
			//($currentform,$iswidget,$makingslideshow, $notinstring='',$shortcodepageid='',$shortcodelang='',$cpostid='' )
			$cpostid = get_the_ID();
			$getloadmorebtnhtml = $reviewsclass->wppro_getloadmorebtnhtml($currentform,$iswidget,$makingslideshow,$notinstring,$shortcodepageid,$shortcodelang,$cpostid,$totalreviewsarray['totalcount'],$shortcodetag,$forceloadmore);
			
			//echo out html in hidden div for load more functionality, jslastslide is now loaded via js file since v11.6.3
			echo $getloadmorebtnhtml['echothis'];
			
			//only add if we need it.
			if($totalreviewsarray['totalcount']>$reviewsperpage){
				$jslastslide = $getloadmorebtnhtml['jslastslide'];
			}
		}
		
			
		//if making slide show add this stuff. 
		if($makingslideshow){
			echo '</ul></div>';
				
		} else {
			echo '</div>';
		}
		
		if(isset($template_misc_array['blocation']) && $template_misc_array['blocation']!=""){
			echo '</div>'; //end badge right
		}
		
		//actually adding badge html here for right side
			if($template_misc_array['blocation']=="right" || $template_misc_array['blocation']=="rightmid"){

				echo '<div class="wprev_badge_div badgeright">';
				//this is where we could load badge styles in Pro version.
				
				echo $badgehtml;
					
				echo '</div>';
			}
			
		//end badge div if we are adding one.
		if(isset($template_misc_array['blocation']) && $template_misc_array['blocation']!=""){
			echo '</div>';	
		}
		
		

		//google snippet html
		$tempsnippethtml = $reviewsclass->wppro_getgooglesnippet($currentform,$totalreviewsarray['totalcount'],$totalreviewsarray['totalavg'],$totalreviews);
		echo $tempsnippethtml;
	 
	}
}
?>