Last active
September 1, 2020 20:53
-
-
Save wpsoul/248ccc1f7bd2f555cd8d02cbf359386f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////// | |
// Score box | |
////////////////////////////////////////////////////////////////// | |
if( !function_exists('wpsm_scorebox_shortcode') ) { | |
function wpsm_scorebox_shortcode( $atts, $content = null ) { | |
extract(shortcode_atts(array( | |
'criterias' => 'editor', | |
'simplestar' => '', | |
'offerbtn' => 'yes', | |
'id' => '', | |
'title'=> '', | |
'proscons' => '', | |
'prostitle' => 'PROS:', | |
'constitle' => 'CONS:', | |
'ce_enable'=> '', | |
), $atts)); | |
ob_start(); | |
?> | |
<?php if(isset($atts['id']) && $atts['id']) :?> | |
<?php $revid = $atts['id'];?> | |
<?php else :?> | |
<?php if (!is_singular() || is_front_page()) {return; } ?> | |
<?php $revid = get_the_ID();?> | |
<?php endif ;?> | |
<?php if(isset($atts['title']) && $atts['title']) :?> | |
<?php $title = $atts['title'];?> | |
<?php else :?> | |
<?php $title = esc_html__('Average Score', 'rehub-theme');?> | |
<?php endif ;?> | |
<?php $args = array('no_found_rows' => 1,'p' => $revid, 'post_type' => 'any'); $query = new WP_Query($args);?> | |
<?php if ($query->have_posts()) : ?> | |
<?php while ($query->have_posts()) : $query->the_post(); global $post; ?> | |
<div class="wpsm_score_box"> | |
<?php if($post->post_type == 'product'):?> | |
<?php $score = get_post_meta((int)$revid, 'rehub_review_overall_score', true);?> | |
<?php if($score) :?> | |
<div class="wpsm_score_title rehub-main-font"> | |
<span class="overall-text"><?php echo esc_attr($title); ?></span> | |
<span class="overall-score"><?php echo round($score, 1) ?></span> | |
</div> | |
<div class="wpsm_inside_scorebox"> | |
<?php if ($simplestar == 'yes') :?> | |
<div class="rating_bar"><?php echo rehub_get_user_rate() ; ?></div> | |
<?php endif ;?> | |
<?php | |
$thecriteria = get_post_meta((int)$revid, '_review_post_criteria', true); | |
$firstcriteria = $thecriteria[0]['review_post_name']; | |
?> | |
<?php if($firstcriteria) : ?> | |
<div class="rate_bar_wrap"> | |
<div class="review-criteria"> | |
<?php foreach ($thecriteria as $criteria) { ?> | |
<?php $perc_criteria = $criteria['review_post_score']*10; ?> | |
<div class="rate-bar clearfix" data-percent="<?php echo ''.$perc_criteria; ?>%"> | |
<div class="rate-bar-title"><span><?php echo ''.$criteria['review_post_name']; ?></span></div> | |
<div class="rate-bar-bar r_score_<?php echo round($criteria['review_post_score']); ?>"></div> | |
<div class="rate-bar-percent"><?php echo ''.$criteria['review_post_score']; ?></div> | |
</div> | |
<?php } ?> | |
</div> | |
</div> | |
<?php endif; ?> | |
<?php if($proscons):?> | |
<?php | |
$prosvalues = get_post_meta((int)$revid, '_review_post_pros_text', true); | |
$consvalues = get_post_meta((int)$revid, '_review_post_cons_text', true); | |
?> | |
<!-- PROS CONS BLOCK--> | |
<div class="prosconswidget"> | |
<?php if(!empty($prosvalues)):?> | |
<div class="wpsm_pros mb30 mt10"> | |
<div class="title_pros"><?php echo esc_attr($prostitle);?></div> | |
<ul> | |
<?php $prosvalues = explode(PHP_EOL, $prosvalues);?> | |
<?php foreach ($prosvalues as $prosvalue) { | |
if(!$prosvalue) continue; | |
echo '<li>'.$prosvalue.'</li>'; | |
}?> | |
</ul> | |
</div> | |
<?php endif;?> | |
<?php if(!empty($consvalues)):?> | |
<div class="wpsm_cons"> | |
<div class="title_cons"><?php echo esc_attr($constitle);?></div> | |
<ul> | |
<?php $consvalues = explode(PHP_EOL, $consvalues);?> | |
<?php foreach ($consvalues as $consvalue) { | |
if(!$consvalue) continue; | |
echo '<li>'.$consvalue.'</li>'; | |
}?> | |
</ul> | |
</div> | |
<?php endif;?> | |
</div> | |
<!-- PROS CONS BLOCK END--> | |
<?php endif;?> | |
</div> | |
<?php endif;?> | |
<?php if ($offerbtn=="yes") :?> | |
<div class="btn_score_btm priced_block"> | |
<?php do_action('rhwoo_template_single_add_to_cart');?> | |
</div> | |
<?php endif ;?> | |
<?php else:?> | |
<?php if(vp_metabox('rehub_post.rehub_framework_post_type') == 'review') :?> | |
<?php $overal_score = rehub_get_overall_score(); | |
if($overal_score !='0') :?> | |
<div class="wpsm_score_image"> | |
<?php $offer_brand_url = esc_url(get_post_meta( get_the_ID(), 'rehub_offer_logo_url', true ));?> | |
<?php if($offer_brand_url):?> | |
<?php WPSM_image_resizer::show_static_resized_image(array('lazy'=> true, 'src'=> $offer_brand_url, 'crop'=> false, 'height'=> 120));?> | |
<?php endif;?> | |
</div> | |
<div class="wpsm_inside_scorebox"> | |
<?php if ($simplestar == 'yes') :?><div class="rating_bar"><?php echo rehub_get_user_rate() ; ?></div><?php endif ;?> | |
<?php if ($criterias == 'editor' || $criterias == 'both') :?> | |
<?php $thecriteria = vp_metabox('rehub_post.review_post.0.review_post_criteria'); $firstcriteria = $thecriteria[0]['review_post_name']; ?> | |
<?php if($firstcriteria) : ?> | |
<div class="rate_bar_wrap"> | |
<div class="review-criteria"> | |
<?php foreach ($thecriteria as $criteria) { ?> | |
<?php $perc_criteria = $criteria['review_post_score']*10; ?> | |
<div class="rate-bar clearfix" data-percent="<?php echo ''.$perc_criteria; ?>%"> | |
<div class="rate-bar-title"><span><?php echo ''.$criteria['review_post_name']; ?></span></div> | |
<div class="rate-bar-bar r_score_<?php echo round($criteria['review_post_score']); ?>"></div> | |
<div class="rate-bar-percent"><?php echo ''.$criteria['review_post_score']; ?></div> | |
</div> | |
<?php } ?> | |
</div> | |
</div> | |
<?php endif; ?> | |
<?php endif ;?> | |
<?php if ($criterias == 'user' || $criterias == 'both') :?> | |
<?php $postAverage = get_post_meta(get_the_ID(), 'post_user_average', true); ?> | |
<?php if($postAverage !='0' && $postAverage !='') : ?> | |
<div class="rate_bar_wrap"> | |
<?php $user_rates = get_post_meta(get_the_ID(), 'post_user_raitings', true); $usercriterias = $user_rates['criteria']; ?> | |
<div class="review-criteria user-review-criteria"> | |
<div class="r_criteria"> | |
<?php foreach ($usercriterias as $usercriteria) { ?> | |
<?php $perc_criteria = $usercriteria['average']*10; ?> | |
<div class="rate-bar user-rate-bar clearfix" data-percent="<?php echo ''.$perc_criteria; ?>%"> | |
<div class="rate-bar-title"><span><?php echo ''.$usercriteria['name']; ?></span></div> | |
<div class="rate-bar-bar r_score_<?php echo round($usercriteria['average']); ?>"></div> | |
<div class="rate-bar-percent"><?php echo ''.$usercriteria['average']; ?></div> | |
</div> | |
<?php } ?> | |
</div> | |
</div> | |
</div> | |
<?php endif; ?> | |
<?php endif ;?> | |
<?php if($proscons):?> | |
<?php | |
$prosvalues = vp_metabox('rehub_post.review_post.0.review_post_pros_text'); | |
$consvalues = vp_metabox('rehub_post.review_post.0.review_post_cons_text'); | |
?> | |
<!-- PROS CONS BLOCK--> | |
<div class="prosconswidget"> | |
<?php if(!empty($prosvalues)):?> | |
<div class="wpsm_pros mb30 mt10"> | |
<div class="title_pros"><?php echo esc_attr($prostitle);?></div> | |
<ul> | |
<?php $prosvalues = explode(PHP_EOL, $prosvalues);?> | |
<?php foreach ($prosvalues as $prosvalue) { | |
echo '<li>'.$prosvalue.'</li>'; | |
}?> | |
</ul> | |
</div> | |
<?php endif;?> | |
<?php if(!empty($consvalues)):?> | |
<div class="wpsm_cons"> | |
<div class="title_cons"><?php echo esc_attr($constitle);?></div> | |
<ul> | |
<?php $consvalues = explode(PHP_EOL, $consvalues);?> | |
<?php foreach ($consvalues as $consvalue) { | |
echo '<li>'.$consvalue.'</li>'; | |
}?> | |
</ul> | |
</div> | |
<?php endif;?> | |
</div> | |
<!-- PROS CONS BLOCK END--> | |
<?php endif;?> | |
</div> | |
<?php endif;?> | |
<?php endif;?> | |
<?php if ($offerbtn=="yes") :?> | |
<div class="btn_score_btm"> | |
<?php rehub_generate_offerbtn('wrapperclass=block_btnblock mobile_block_btnclock mb5 text-center');?> | |
<div class="centered_brand_logo"> | |
<?php WPSM_Postfilters::re_show_brand_tax('logo'); //show brand logo?> | |
</div> | |
</div> | |
<?php endif ;?> | |
<?php endif ;?> | |
<?php if ($ce_enable && defined('\ContentEgg\PLUGIN_PATH')) :?> | |
<div class="wpsm_inside_scorebox_ce"> | |
<?php | |
$cegg_field_array = rehub_option('save_meta_for_ce'); | |
$cegg_fields = array(); | |
if (!empty($cegg_field_array) && is_array($cegg_field_array)) { | |
foreach ($cegg_field_array as $cegg_field) { | |
if ($cegg_field == 'none' || $cegg_field == ''){ continue;} | |
$cegg_field_value = \ContentEgg\application\components\ContentManager::getViewData($cegg_field, $post->ID); | |
if (!empty ($cegg_field_value) && is_array($cegg_field_value)) { | |
$cegg_fields[$cegg_field]= $cegg_field_value; | |
} | |
} | |
if (!empty($cegg_fields) && is_array($cegg_fields)) { | |
$all_items = array(); | |
foreach ($cegg_fields as $module_id => $items) { | |
foreach ($items as $item_ar) { | |
$item_ar['module_id'] = $module_id; | |
$all_items[] = $item_ar; | |
} | |
} | |
?> | |
<div class="btn_score_btm rh_deal_block"> | |
<?php foreach ($all_items as $key => $item) :?> | |
<?php | |
$currency_code = (!empty($item['currencyCode'])) ? $item['currencyCode'] : ''; | |
$offer_price = (!empty($item['price'])) ? \ContentEgg\application\helpers\TemplateHelper::formatPriceCurrency($item['price'], $currency_code) : ''; | |
$offer_price_old = (!empty($item['priceOld'])) ? \ContentEgg\application\helpers\TemplateHelper::formatPriceCurrency($item['priceOld'], $currency_code) : ''; | |
$offer_title = (!empty($item['title'])) ? $item['title'] : ''; | |
$offer_post_url = (!empty($item['url'])) ? $item['url'] : ''; | |
$offer_url = apply_filters('rh_post_offer_url_filter', $offer_post_url ); | |
?> | |
<?php if (!empty($item['domain'])):?> | |
<?php $domain = $item['domain'];?> | |
<?php elseif (!empty($item['extra']['domain'])):?> | |
<?php $domain = $item['extra']['domain'];?> | |
<?php else:?> | |
<?php $domain = '';?> | |
<?php endif;?> | |
<?php $merchant = (!empty($item['merchant'])) ? $item['merchant'] : ''; ?> | |
<?php $logo = \ContentEgg\application\helpers\TemplateHelper::getMerhantLogoUrl($item, true);?> | |
<div class="deal_block_row"> | |
<div class="rh-deal-pricetable"> | |
<div class="rh-deal-left"> | |
<div class="rh-deal-name"> | |
<h5><a href="<?php echo esc_url($offer_url); ?>" class="no-color-link"><?php echo esc_attr($offer_title);?></a></h5> | |
</div> | |
<?php if ($logo):?> | |
<div class="rh-deal-brandlogo"> | |
<?php if($logo) :?> | |
<?php WPSM_image_resizer::show_static_resized_image(array('lazy'=> false, 'src'=> $logo, 'crop'=> false, 'width'=> 70, 'height'=> 70));?> | |
<?php endif ;?> | |
</div> | |
<?php elseif ($merchant):?> | |
<div class="rh-deal-tag"> | |
<span><?php echo esc_attr($merchant);?></span> | |
</div> | |
<?php endif;?> | |
</div> | |
<div class="rh-deal-right"> | |
<?php if(!empty($offer_price)) : ?> | |
<div class="rh-deal-price"> | |
<ins><?php echo ''.$offer_price ?></ins> | |
<?php if(!empty($offer_price_old)) : ?> | |
<del> | |
<?php echo ''.$offer_price_old ?> | |
</del> | |
<?php endif ;?> | |
</div> | |
<?php endif ;?> | |
<div class="rh-deal-btn"> | |
<a href="<?php echo esc_url($offer_url) ?>" class="re_track_btn rh-deal-compact-btn btn_offer_block" target="_blank" rel="nofollow"> | |
<?php if(rehub_option('rehub_btn_text') !='') :?> | |
<?php echo rehub_option('rehub_btn_text') ; ?> | |
<?php else :?> | |
<?php esc_html_e('Buy Now', 'rehub-theme') ?> | |
<?php endif ;?> | |
</a> | |
</div> | |
</div> | |
</div> | |
</div> | |
<?php endforeach;?> | |
</div> | |
<?php | |
} | |
} | |
?> | |
</div> | |
<?php endif ;?> | |
</div> | |
<?php endwhile; endif; wp_reset_postdata(); ?> | |
<?php | |
$output = ob_get_contents(); | |
ob_end_clean(); | |
return $output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment