function axiom_options_merge_new_values(&$post_options, &$custom_options, &$post_data, $mode, $override) { $need_save = false; foreach ($post_options as $id => $field) { if ($override != 'general' && (!isset($field['override']) || !in_array($override, explode(',', $field['override'])))) { continue; } if (!isset($field['std'])) { continue; } if ($override != 'general' && !isset($post_data[$id . '_inherit'])) { continue; } if ($id == 'reviews_marks' && $mode == 'export') { continue; } $need_save = true; if ($mode == 'save' || $mode == 'export') { if ($override != 'general' && axiom_is_inherit_option($post_data[$id . '_inherit'])) { $new = ''; } else { if (isset($post_data[$id])) { // Prepare specific (combined) fields if (!empty($field['subset'])) { $sbs = $post_data[$field['subset']]; $field['val'][$sbs] = $post_data[$id]; $post_data[$id] = $field['val']; } if ($field['type'] == 'socials') { if (!empty($field['cloneable'])) { foreach ($post_data[$id] as $k => $v) { $post_data[$id][$k] = array('url' => stripslashes($v), 'icon' => stripslashes($post_data[$id . '_icon'][$k])); } } else { $post_data[$id] = array('url' => stripslashes($post_data[$id]), 'icon' => stripslashes($post_data[$id . '_icon'])); } } else { if (is_array($post_data[$id])) { foreach ($post_data[$id] as $k => $v) { $post_data[$id][$k] = stripslashes($v); } } else { $post_data[$id] = stripslashes($post_data[$id]); } } // Add cloneable index if (!empty($field['cloneable'])) { $rez = array(); foreach ($post_data[$id] as $k => $v) { $rez[$post_data[$id . '_numbers'][$k]] = $v; } $post_data[$id] = $rez; } $new = $post_data[$id]; // Post type specific data handling if ($id == 'reviews_marks') { $new = join(',', $new); if (($avg = axiom_reviews_get_average_rating($new)) > 0) { $new = axiom_reviews_marks_to_save($new); } } } else { $new = $field['type'] == 'checkbox' ? 'false' : ''; } } } else { $new = $field['std']; } $custom_options[$id] = $new !== '' || $override == 'general' ? $new : 'inherit'; } return $need_save; }
function axiom_post_save_custom_options($custom_options, $post_type, $post_id) { if (isset($custom_options['reviews_marks'])) { if (($avg = axiom_reviews_get_average_rating($custom_options['reviews_marks'])) > 0) { update_post_meta($post_id, 'reviews_avg', $avg); } } return $custom_options; }
function axiom_reviews_get_markup($field, $value, $editable = false, $clear = false, $snippets = false) { $max_level = max(5, (int) axiom_get_custom_option('reviews_max_level')); $step = $max_level < 100 ? 0.1 : 1; $prec = pow(10, axiom_strpos($step, '.') === false ? 0 : axiom_strlen($step) - axiom_strpos($step, '.') - 1); $output = '<div class="reviews_editor">'; $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] == '' || axiom_is_inherit_option($marks[$i])) { $marks[$i] = 0; } $marks[$i] = min($max_level, max(0, round($marks[$i] * $prec) / $prec + 0)); $output .= '<div class="reviews_item reviews_max_level_' . esc_attr($max_level) . '" data-max-level="' . esc_attr($max_level) . '" data-step="' . esc_attr($step) . '">' . '<div class="reviews_criteria">' . $sb . '</div>' . trim(axiom_reviews_get_summary_stars($marks[$i], $editable)) . '</div>'; $i++; } } $output .= '</div>'; $output .= isset($field['accept']) && $field['accept'] ? '<div class="reviews_accept">' . do_shortcode('[trx_button]' . __('Accept your votes', 'axiom') . '[/trx_button]') . '</div>' : ''; $avg = axiom_reviews_get_average_rating($value); $avg = min($max_level, max(0, round($avg * $prec) / $prec + 0)); $output .= ' <div class="reviews_summary"> <div class="reviews_item reviews_max_level_' . esc_attr($max_level) . '" data-step="' . esc_attr($step) . '"> <div class="reviews_criteria">' . (isset($field['descr']) ? $field['descr'] : __('Summary', 'axiom')) . '</div> ' . trim(axiom_reviews_get_summary_stars($avg, false, $snippets)) . ' </div> </div> '; return $output; }