> <label class="description" for="<?php echo $element_id; ?> "><?php echo esc_html($description); ?> </label> <?php if ($rating_item_type == "star_rating") { $template_part_name = 'star-rating'; if ($use_custom_star_images) { $template_part_name = 'custom-star-images'; } $default_option_value = 0; mr_get_template_part('rating-form', $template_part_name, true, array('max_option_value' => $max_option_value, 'default_option_value' => $default_option_value, 'element_id' => $element_id, 'icon_classes' => $icon_classes, 'rating_item_type' => $rating_item_type)); } else { if ($rating_item_type == 'select') { mr_get_template_part('rating-form', 'select', true, array('element_id' => $element_id, 'max_option_value' => $max_option_value, 'default_option_value' => $default_option_value, 'rating_item_type' => $rating_item_type)); } else { // radio mr_get_template_part('rating-form', 'radio', true, array('default_option_value' => $default_option_value, 'element_id' => $element_id, 'max_option_value' => $max_option_value, 'rating_item_type' => $rating_item_type)); } } ?> <span id="<?php echo $element_id; ?> -error" class="mr-error"></span> </p>
?> " action="#"> <?php do_action('mr_rating_form_before_rating_items', $post_id, $rating_items); /** * Rating Items */ foreach ((array) $rating_items as $rating_item) { $rating_item_id = $rating_item['rating_item_id']; $element_id = 'rating-item-' . $rating_item_id . '-' . MR_Rating_Form::$sequence; $description = $rating_item['description']; $rating_item_type = $rating_item['type']; $max_option_value = $rating_item['max_option_value']; $default_option_value = $rating_item['default_option_value']; $rating_item_type = $rating_item['type']; mr_get_template_part('rating-form', 'rating-item', true, array('rating_item_id' => $rating_item_id, 'element_id' => $element_id, 'description' => $description, 'max_option_value' => $max_option_value, 'default_option_value' => $default_option_value, 'class' => null, 'style' => null, 'icon_classes' => $icon_classes, 'use_custom_star_images' => $use_custom_star_images, 'element_id' => $element_id, 'rating_item_type' => $rating_item_type)); ?> <!-- hidden field to get rating item id --> <input type="hidden" value="<?php echo $rating_item_id; ?> " class="rating-item-<?php echo $post_id; ?> -<?php echo MR_Rating_Form::$sequence; ?> " id="hidden-rating-item-id-<?php echo $rating_item_id; ?> " />
<a class="title" href="<?php echo esc_attr(get_the_permalink($post_id)); ?> "><?php echo esc_html($post_obj->post_title); ?> </a> <?php if ($featured_img_shown == true) { ?> <br /> <?php } mr_get_template_part('rating-result', null, true, array('no_rating_results_text' => '', 'ignore_count' => true, 'show_rich_snippets' => false, 'show_title' => false, 'before_title' => $before_title, 'after_title' => $after_title, 'show_date' => false, 'show_count' => $show_count, 'result_type' => $result_type, 'class' => $class . ' rating-result-list-' . $post_id, 'rating_result' => $rating_result, 'before_count' => $before_count, 'after_count' => $after_count, 'post_id' => $post_id, 'preserve_max_option' => false, 'before_date' => $before_date, 'after_date' => $after_date, 'icon_classes' => $icon_classes, 'use_custom_star_images' => $use_custom_star_images, 'image_width' => $image_width, 'image_height' => $image_height)); if ($featured_img_shown && isset($show_date) && $show_date == true && isset($rating_result['entry_date'])) { ?> <br /> <span class="entry-date"><?php echo "{$before_date}" . mysql2date(get_option('date_format'), $rating_result['entry_date']) . "{$after_date}"; ?> </span> <?php } ?> </td> <?php if (!$featured_img_shown && isset($show_date) && $show_date == true && isset($rating_result['entry_date'])) { ?> <td>
/** * Displays a rating results list. This is used by the Rating Result List widet and shortcode. * * @param unknown_type $params * @return string */ public static function display_rating_results_list($params = array()) { $general_settings = (array) get_option(Multi_Rating::GENERAL_SETTINGS); $custom_text_settings = (array) get_option(Multi_Rating::CUSTOM_TEXT_SETTINGS); $style_settings = (array) get_option(Multi_Rating::STYLE_SETTINGS); $font_awesome_version = $style_settings[Multi_Rating::FONT_AWESOME_VERSION_OPTION]; $icon_classes = MR_Utils::get_icon_classes($font_awesome_version); $use_custom_star_images = $style_settings[Multi_Rating::USE_CUSTOM_STAR_IMAGES]; $image_width = $style_settings[Multi_Rating::CUSTOM_STAR_IMAGE_WIDTH]; $image_height = $style_settings[Multi_Rating::CUSTOM_STAR_IMAGE_HEIGHT]; extract(wp_parse_args($params, array('title' => $custom_text_settings[Multi_Rating::RATING_RESULTS_LIST_TITLE_TEXT_OPTION], 'before_title' => '<h4>', 'after_title' => '</h4>', 'no_rating_results_text' => $custom_text_settings[Multi_Rating::NO_RATING_RESULTS_TEXT_OPTION], 'show_count' => true, 'echo' => true, 'show_category_filter' => true, 'category_id' => 0, 'limit' => 10, 'show_rank' => true, 'result_type' => Multi_Rating::STAR_RATING_RESULT_TYPE, 'show_title' => true, 'class' => '', 'taxonomy' => null, 'term_id' => 0, 'filter_button_text' => $custom_text_settings[Multi_Rating::FILTER_BUTTON_TEXT_OPTION], 'category_label_text' => $custom_text_settings[Multi_Rating::FILTER_LABEL_TEXT_OPTION], 'show_featured_img' => true, 'image_size' => 'thumbnail', 'sort_by' => 'highest_rated', 'filter_label_text' => $custom_text_settings[Multi_Rating::FILTER_LABEL_TEXT_OPTION], 'show_filter' => false))); // temp if (is_string($show_category_filter)) { $show_category_filter = $show_category_filter == 'true' ? true : false; $show_filter = $show_category_filter; } if (is_string($show_filter)) { $show_filter = $show_filter == 'true' ? true : false; } if (is_string($show_count)) { $show_count = $show_count == 'true' ? true : false; } if (is_string($echo)) { $echo = $echo == 'true' ? true : false; } if (is_string($show_rank)) { $show_rank = $show_rank == 'true' ? true : false; } if (is_string($show_title)) { $show_title = $show_title == 'true' ? true : false; } if (is_string($show_featured_img)) { $show_featured_img = $show_featured_img == 'true' ? true : false; } // show the filter for taxonomy if ($show_filter == true && isset($_REQUEST['term-id'])) { // override category id if set in HTTP request $term_id = $_REQUEST['term-id']; } if ($show_filter && $taxonomy == null) { $taxonomy = 'category'; } if ($category_id != 0) { $term_id = $category_id; $taxonomy = 'category'; } if ($term_id == 0) { $term_id = null; // so that all terms are returned } $rating_results = Multi_Rating_API::get_rating_results(array('limit' => $limit, 'taxonomy' => $taxonomy, 'term_id' => $term_id, 'result_type' => $result_type, 'sort_by' => $sort_by)); ob_start(); mr_get_template_part('rating-result', 'list', true, array('show_title' => $show_title, 'show_count' => $show_count, 'show_filter' => $show_filter, 'category_id' => $category_id, 'before_title' => $before_title, 'after_title' => $after_title, 'title' => $title, 'show_rank' => $show_rank, 'no_rating_results_text' => $no_rating_results_text, 'result_type' => $result_type, 'taxonomy' => $taxonomy, 'term_id' => $term_id, 'filter_button_text' => $filter_button_text, 'filter_label_text' => $filter_label_text, 'show_featured_img' => $show_featured_img, 'image_size' => $image_size, 'show_rich_snippets' => false, 'class' => $class . ' rating-results-list', 'rating_results' => $rating_results, 'before_count' => '(', 'after_count' => ')', 'ignore_count' => false, 'preserve_max_option' => false, 'before_date' => '', 'after_date' => '', 'icon_classes' => $icon_classes, 'use_custom_star_images' => $use_custom_star_images, 'image_width' => $image_width, 'image_height' => $image_height)); $html = ob_get_contents(); ob_end_clean(); $html = apply_filters('mr_template_html', $html); if ($echo == true) { echo $html; } return $html; }
} else { if ($result_type == Multi_Rating::PERCENTAGE_RESULT_TYPE) { mr_get_template_part('rating-result', 'percentage', true, array('rating_result' => $rating_result)); } else { // star rating $max_stars = 5; $star_result = $rating_result['adjusted_star_result']; if ($preserve_max_option) { $max_stars = $rating_result['total_max_option_value']; $star_result = $rating_result['adjusted_score_result']; } $template_part_name = 'star-rating'; if ($use_custom_star_images) { $template_part_name = 'custom-star-images'; } mr_get_template_part('rating-result', $template_part_name, true, array('max_stars' => $max_stars, 'star_result' => $star_result, 'icon_classes' => $icon_classes, 'image_height' => $image_height, 'image_width' => $image_width)); } } do_action('mr_rating_result_after_result_type'); if ($show_count && $count != null) { $before_count = apply_filters('mr_rating_result_before_count', $before_count, $count); $after_count = apply_filters('mr_rating_result_after_count', $after_count, $count); ?> <span class="count"><?php echo $before_count . number_format($count) . $after_count; ?> </span> <?php } if ($show_date == true && isset($rating_result['entry_date'])) { $before_date = apply_filters('mr_rating_result_before_date', $before_date, $count);
/** * Saves a rating form entry. */ public static function save_rating() { $ajax_nonce = $_POST['nonce']; if (wp_verify_nonce($ajax_nonce, Multi_Rating::ID . '-nonce')) { global $wpdb; $rating_items = $_POST['ratingItems']; $post_id = $_POST['postId']; $ip_address = MR_Utils::get_ip_address(); $entry_date_mysql = current_time('mysql'); $sequence = isset($_POST['sequence']) ? $_POST['sequence'] : ''; // WPML get original pst id for default language if (function_exists('icl_object_id')) { global $sitepress; $post_id = icl_object_id($post_id, get_post_type($post_id), true, $sitepress->get_default_language()); } $data = array('sequence' => $sequence, 'post_id' => $post_id); $general_settings = (array) get_option(Multi_Rating::GENERAL_SETTINGS); $custom_text_settings = (array) get_option(Multi_Rating::CUSTOM_TEXT_SETTINGS); // get user id global $wp_roles; $user = wp_get_current_user(); $user_id = $user->ID; // stores any validation results, custom validation results can be added through filters $validation_results = array(); $validation_results = MR_Utils::validate_save_rating_restricton($validation_results, $post_id); $validation_results = MR_Utils::validate_rating_item_required($validation_results, $rating_items); $validation_results = apply_filters('mr_after_rating_form_validation_save', $validation_results, $data); if (MR_Utils::has_validation_error($validation_results)) { echo json_encode(array('status' => 'error', 'data' => $data, 'validation_results' => $validation_results)); die; } // everything is OK so now insert the rating form entry and entry values into the database tables $wpdb->insert($wpdb->prefix . Multi_Rating::RATING_ITEM_ENTRY_TBL_NAME, array('post_id' => $post_id, 'entry_date' => $entry_date_mysql, 'ip_address' => $ip_address, 'user_id' => $user_id), array('%d', '%s', '%s', '%d')); $rating_entry_id = $wpdb->insert_id; foreach ($rating_items as $rating_item) { $rating_item_id = $rating_item['id']; $rating_item_value = $rating_item['value']; $wpdb->insert($wpdb->prefix . Multi_Rating::RATING_ITEM_ENTRY_VALUE_TBL_NAME, array('rating_item_entry_id' => $rating_entry_id, 'rating_item_id' => $rating_item_id, 'value' => $rating_item_value), array('%d', '%d', '%d')); } // Set cookie if restriction type is used foreach ($general_settings[Multi_Rating::SAVE_RATING_RESTRICTION_TYPES_OPTION] as $save_rating_restriction_type) { if ($save_rating_restriction_type == 'cookie') { if (!headers_sent()) { $save_rating_restriction_hours = $general_settings[Multi_Rating::SAVE_RATING_RESTRICTION_HOURS_OPTION]; setcookie(Multi_Rating::POST_SAVE_RATING_COOKIE . '-' . $post_id, true, time() + 60 * 60 * $save_rating_restriction_hours, COOKIEPATH, COOKIE_DOMAIN, false, true); } break; } } $rating_items = Multi_Rating_API::get_rating_items(array('post_id' => $post_id)); $rating_result = Multi_Rating_API::calculate_rating_result(array('post_id' => $post_id, 'rating_items' => $rating_items)); $rating_results_cache = $general_settings[Multi_Rating::RATING_RESULTS_CACHE_OPTION]; if ($rating_results_cache == true) { // update rating results cache update_post_meta($post_id, Multi_Rating::RATING_RESULTS_POST_META_KEY, $rating_result); } $style_settings = (array) get_option(Multi_Rating::STYLE_SETTINGS); $font_awesome_version = $style_settings[Multi_Rating::FONT_AWESOME_VERSION_OPTION]; $icon_classes = MR_Utils::get_icon_classes($font_awesome_version); $use_custom_star_images = $style_settings[Multi_Rating::USE_CUSTOM_STAR_IMAGES]; $image_width = $style_settings[Multi_Rating::CUSTOM_STAR_IMAGE_WIDTH]; $image_height = $style_settings[Multi_Rating::CUSTOM_STAR_IMAGE_HEIGHT]; $rating_results_position = get_post_meta($post_id, Multi_Rating::RATING_RESULTS_POSITION_POST_META, true); $position_settings = (array) get_option(Multi_Rating::POSITION_SETTINGS); // use default rating results position if ($rating_results_position == '') { $rating_results_position = $position_settings[Multi_Rating::RATING_RESULTS_POSITION_OPTION]; } ob_start(); mr_get_template_part('rating-result', null, true, array('no_rating_results_text' => '', 'show_rich_snippets' => false, 'show_title' => false, 'show_date' => false, 'show_count' => true, 'result_type' => Multi_Rating::STAR_RATING_RESULT_TYPE, 'class' => 'rating-result-' . $post_id . ' ' . $rating_results_position . ' mr-filter', 'rating_result' => $rating_result, 'before_count' => '(', 'after_count' => ')', 'post_id' => $post_id, 'ignore_count' => false, 'preserve_max_option' => false, 'before_date' => '', 'after_date' => '', 'icon_classes' => $icon_classes, 'use_custom_star_images' => $use_custom_star_images, 'image_width' => $image_width, 'image_height' => $image_height)); $html = ob_get_contents(); ob_end_clean(); $data['html'] = $html; // if the custom text does not contain %, then there's no need to substitute the message $message = $custom_text_settings[Multi_Rating::RATING_FORM_SUBMIT_SUCCESS_MESSAGE_OPTION]; if (strpos($message, '%') !== false) { $message = MR_Utils::substitute_message($message, $user, Multi_Rating_API::calculate_rating_item_entry_result($rating_entry_id, $rating_items)); } $data['rating_result'] = $rating_result; $data['hide_rating_form'] = $general_settings[Multi_Rating::HIDE_RATING_FORM_AFTER_SUBMIT_OPTION]; echo json_encode(array('status' => 'success', 'data' => $data, 'message' => $message, 'validation_results' => $validation_results)); } die; }