';
$criterias = $field['options'];
$marks = explode(',', $value);
if (is_array($criterias) && count($criterias) > 0) {
$i=0;
foreach ($criterias as $num=>$sb) {
if (empty($sb)) continue;
if ($clear || !isset($marks[$i]) || $marks[$i]=='' || lorem_ipsum_books_media_store_is_inherit_option($marks[$i])) $marks[$i] = 0;
$marks[$i] = min($max_level, max(0, round($marks[$i] * $prec) / $prec + 0));
$output .= '
'
. '
'.($sb).'
'
. trim(lorem_ipsum_books_media_store_reviews_get_summary_stars($marks[$i], $editable))
.'
';
$i++;
}
}
$output .= '
';
if(function_exists('lorem_ipsum_books_media_store_sc_button')){
$output .= isset($field['accept']) && $field['accept'] ? ''.lorem_ipsum_books_media_store_sc_button(array(), esc_html__('Accept your votes', 'trx_utils')).'
' : '';
}
$avg = lorem_ipsum_books_media_store_reviews_get_average_rating($value);
$avg = min($max_level, max(0, round($avg * $prec) / $prec + 0));
$output .= ''
. ($snippets ? '
' : '');
if (!$editable && $style=='text') {
$output .= sprintf($max_level<100 ? esc_html__('%s / %s', 'trx_utils') : esc_html__('%s', 'trx_utils'), number_format($avg, 1) . ($max_level < 100 ? '' : '%'), $max_level . ($max_level < 100 ? '' : '%'));
} else {
$stars = lorem_ipsum_books_media_store_strrepeat('
', $stars_count);
$output .= '
'
.'
'.($max_level < 100 || $stars_show ? $stars : '').'
'
.'
'.($max_level < 100 || $stars_show ? $stars : '').'
'
.($editable ? '
' : '')
.'
'
.'
'.($avg).'
';
}
if ($editable) {
$output .= '
';
}
$output .= '
';
return $output;
}
}
// Prepare rating marks before first using
if ( !function_exists( 'lorem_ipsum_books_media_store_reviews_marks_prepare' ) ) {
function lorem_ipsum_books_media_store_reviews_marks_prepare($marks, $cnt) {
$m = explode(',', $marks);
for ($i=0; $i < $cnt; $i++) {
if (!isset($m[$i]))
$m[$i] = 0;
else
$m[$i] = max(0, (float) $m[$i]);
}
return implode(',', $m);
}
}
// Prepare rating marks to save
if ( !function_exists( 'lorem_ipsum_books_media_store_reviews_marks_to_save' ) ) {
function lorem_ipsum_books_media_store_reviews_marks_to_save($marks) {
$max_level = max(5, (int) lorem_ipsum_books_media_store_get_custom_option('reviews_max_level'));
if ($max_level == 100) return $marks;
$m = explode(',', $marks);
$kol = count($m);
for ($i=0; $i < $kol; $i++) {
$m[$i] = round((float)$m[$i] * 100 / $max_level, 1);
}
return implode(',', $m);
}
}
// Prepare rating marks to display
if ( !function_exists( 'lorem_ipsum_books_media_store_reviews_marks_to_display' ) ) {
function lorem_ipsum_books_media_store_reviews_marks_to_display($marks) {
$max_level = max(5, (int) lorem_ipsum_books_media_store_get_custom_option('reviews_max_level'));
if ($max_level == 100) return $marks;
$m = explode(',', $marks);
$kol = count($m);
for ($i=0; $i < $kol; $i++) {
$m[$i] = round((float)$m[$i] / 100 * $max_level, 1);
}
return implode(',', $m);
}
}
// Return placeholder for reviews block
if ( !function_exists( 'lorem_ipsum_books_media_store_get_reviews_placeholder' ) ) {
function lorem_ipsum_books_media_store_get_reviews_placeholder() {
return '';
}
}
// Replace placeholder with the reviews block
if ( !function_exists( 'lorem_ipsum_books_media_store_reviews_wrapper' ) ) {
function lorem_ipsum_books_media_store_reviews_wrapper($str) {
$placeholder = lorem_ipsum_books_media_store_get_reviews_placeholder();
if (lorem_ipsum_books_media_store_strpos($str, $placeholder)!==false) {
if (($reviews_markup=lorem_ipsum_books_media_store_storage_get('reviews_markup'))!='') {
$str = str_replace($placeholder, $reviews_markup, $str);
lorem_ipsum_books_media_store_storage_set('reviews_markup', '');
}
}
return $str;
}
}
?>