Beispiel #1
0
 /**
  * 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;
 }
 /**
  * Javascript and CSS used by the plugin
  *
  * @since 0.1
  */
 public function assets()
 {
     wp_enqueue_script('jquery');
     // Add simple table CSS for rating form
     wp_enqueue_style('mr-frontend-style', plugins_url('assets' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'frontend-min.css', __FILE__));
     // Allow support for other versions of Font Awesome
     $style_settings = (array) get_option(Multi_Rating::STYLE_SETTINGS);
     $include_font_awesome = $style_settings[Multi_Rating::INCLUDE_FONT_AWESOME_OPTION];
     $font_awesome_version = $style_settings[Multi_Rating::FONT_AWESOME_VERSION_OPTION];
     $icon_classes = MR_Utils::get_icon_classes($font_awesome_version);
     $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
     if ($include_font_awesome) {
         if ($font_awesome_version == '4.0.3') {
             wp_enqueue_style('fontawesome', $protocol . '://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css');
         } else {
             if ($font_awesome_version == '3.2.1') {
                 wp_enqueue_style('fontawesome', $protocol . '//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css');
             } else {
                 if ($font_awesome_version == '4.1.0') {
                     wp_enqueue_style('fontawesome', $protocol . '://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css');
                 } else {
                     if ($font_awesome_version == '4.2.0') {
                         wp_enqueue_style('fontawesome', $protocol . '://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css');
                     } else {
                         if ($font_awesome_version == '4.3.0') {
                             wp_enqueue_style('fontawesome', $protocol . '://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css');
                         }
                     }
                 }
             }
         }
     }
     $config_array = array('ajax_url' => admin_url('admin-ajax.php'), 'ajax_nonce' => wp_create_nonce(Multi_Rating::ID . '-nonce'), 'icon_classes' => json_encode($icon_classes), 'use_custom_star_images' => $style_settings[Multi_Rating::USE_CUSTOM_STAR_IMAGES] == true ? "true" : "false");
     wp_enqueue_script('mr-frontend-script', plugins_url('assets' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'frontend-min.js', __FILE__), array('jquery'), Multi_Rating::VERSION, true);
     wp_localize_script('mr-frontend-script', 'mr_frontend_data', $config_array);
 }
 /**
  * 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;
 }