public function do_shortcode_users($atts) { extract(shortcode_atts(array('id' => '', 'post' => get_the_ID(), 'size' => '24', 'stars' => '5'), $atts)); $review_id = intval($id); $post_id = intval($post); $size = intval($size); $stars = intval($stars); // Get post reviews $reviews = get_post_meta($post_id, 'rwp_reviews', true); // Check if user has inserted a valid review ID if (!isset($reviews[$review_id])) { return '<p>' . __('No review found! Insert a valid review ID.', $this->plugin_slug) . '</p>'; } // Get Review $this->review = $reviews[$id]; // Get Template $templates = RWP_Reviewer::get_option('rwp_templates'); $this->template = isset($templates[$this->review['review_template']]) ? $templates[$this->review['review_template']] : array(); $max = $this->template_field('template_maximum_score', true); $min = $this->template_field('template_minimum_score', true); $singles = RWP_Reviewer::get_ratings_single_scores($post_id, $review_id, $this->review_field('review_template', true)); $scores = RWP_Reviewer::get_users_overall_score($singles, $post_id, $this->review_field('review_id', true)); $avg = $scores['score']; $count = $scores['count']; $score = $this->map_range($avg, $min, $max, 0, $stars); $count_label = $count == 1 ? $this->template_field('template_users_count_label_s', true) : $this->template_field('template_users_count_label_p', true); ob_start(); echo $this->get_stars($score, $size, $stars); echo '<div class="rwp-rating-stars-count">(' . $count . ' ' . $count_label . ')</div>'; //RWP_Reviewer::pretty_print( $this->review ); //RWP_Reviewer::pretty_print( $this->template ); return ob_get_clean(); }
public static function get_review_users_rating_in_html($post_id = 0, $review_id = 1) { $result = array(); $reviews = get_post_meta($post_id, 'rwp_reviews', true); // Get post reviews if (is_array($reviews)) { // Check if the post has reviews foreach ($reviews as $r) { // Find the review defined in $review_id if ($r['review_id'] == $review_id) { $review = $r; break; } } $ratings = RWP_Reviewer::get_ratings_single_scores($post_id, $review_id, $review['review_template']); $templates = get_option('rwp_templates'); $template_id = $review['review_template']; if (isset($templates[$template_id])) { $icon_url = $templates[$template_id]['template_rate_image']; $max = $templates[$template_id]['template_maximum_score']; echo $max; $ratings['html'] = self::get_stars($ratings['scores'], $max, 5, $icon_url); $result = $ratings; } } return $result; }
public function get_table_reviews($table_reviews) { global $wpdb; $posts = array(); $reviews = array(); $result = array(); foreach ($table_reviews as $review_ids) { // Extract ids $ids = explode(':', $review_ids); $posts[] = $ids[0]; $reviews[$ids[0]][] = $ids[1]; } $posts = array_unique($posts); $query = ""; $query .= "SELECT * FROM {$wpdb->postmeta} WHERE meta_key = 'rwp_reviews' AND ( "; $last_post_id = array_pop($posts); foreach ($posts as $post_id) { $query .= " post_id = {$post_id} OR"; } $query .= " post_id = {$last_post_id} );"; $post_meta = $wpdb->get_results($query, ARRAY_A); foreach ($post_meta as $meta) { $revs = unserialize($meta['meta_value']); foreach ($revs as $review_id => $review) { if (isset($review['review_status']) && $review['review_status'] == 'draft') { continue; } if (in_array($review_id, $reviews[$meta['post_id']])) { $review['review_post_id'] = $meta['post_id']; $review['review_ratings_scores'] = RWP_Reviewer::get_ratings_single_scores($meta['post_id'], $review['review_id'], $review['review_template']); $result[] = $review; } } } return $result; }
public function do_shortcode($atts) { extract(shortcode_atts(array('id' => '', 'theme' => '', 'template' => '', 'rating' => '', 'branch' => '', 'post' => get_the_ID()), $atts)); $this->post_id = $post; $post_id = $post; //return "Review " . $theme; $review_id = intval($id); //echo "Review ID: " . $review_id; //echo "Branch: " . $branch . '<br/>'; if ($review_id != $this->auto_review_id) { // Manul Review // Get post reviews $reviews = get_post_meta($this->post_id, 'rwp_reviews', true); // Check if user has inserted a valid review ID if (!isset($reviews[$id])) { return '<p>' . __('No review found! Insert a valid review ID.', $this->plugin_slug) . '</p>'; } // Get Review $this->review = $reviews[$id]; } else { // Auto Review $this->review = $this->get_auto_review($template); } // Get Options $this->preferences = RWP_Reviewer::get_option('rwp_preferences'); $templates = RWP_Reviewer::get_option('rwp_templates'); $this->template = isset($templates[$this->review['review_template']]) ? $templates[$this->review['review_template']] : array(); $this->template['template_theme'] = empty($theme) ? $this->template['template_theme'] : 'rwp-theme-' . $theme; // Ratings per page $this->ratings_per_page = $this->preferences_field('preferences_users_reviews_per_page', true); // Rating param $this->preferences['preferences_rating_mode'] = empty($rating) ? $this->preferences['preferences_rating_mode'] : $rating; // Utility variable $this->is_UR = $this->review_field('review_type', true) == 'UR' ? true : false; $img = $this->review_field('review_image', true); if ($this->review_field('review_use_featured_image', true) == 'no') { $this->has_img = !empty($img) ? true : false; } else { $this->has_img = has_post_thumbnail($this->post_id); } // Ratings $ratings = get_post_meta($post_id, 'rwp_rating_' . $this->review['review_id']); $this->ratings = is_array($ratings) ? $ratings : array(); // Filter ratings $moderation = $this->preferences_field('preferences_rating_before_appears', true); $this->ratings = RWP_Reviewer::filter_ratings($this->ratings, $moderation); $rating_blacklist = get_post_meta($post_id, 'rwp_rating_blacklist', true); $this->rating_blacklist = is_array($rating_blacklist) ? $rating_blacklist : array(); $likes_blacklist = get_post_meta($post_id, 'rwp_likes_blacklist', true); $this->likes_blacklist = is_array($likes_blacklist) ? $likes_blacklist : array(); $likes = get_post_meta($post_id, 'rwp_likes', true); $this->likes = is_array($likes) ? $likes : array(); // Ratings Scores $this->ratings_scores = RWP_Reviewer::get_ratings_single_scores($this->post_id, $this->review_field('review_id', true), $this->review_field('review_template', true)); // Branch $this->branch = $branch; // Google rich snippets $this->snippets = new RWP_Snippets(); ob_start(); include 'themes/layout.php'; //RWP_Reviewer::pretty_print( $this->ratings ); //RWP_Reviewer::pretty_print( $this->rating_blacklist ); //RWP_Reviewer::pretty_print( $this->likes ); //RWP_Reviewer::pretty_print( $this->likes_blacklist ); //RWP_Reviewer::pretty_print( $this->review ); //RWP_Reviewer::pretty_print( $this->template ); //RWP_Reviewer::pretty_print( $this->preferences ); return ob_get_clean(); }
function column_rwp_reviews_table_review_users_score($item) { $ratings_scores = RWP_Reviewer::get_ratings_single_scores($item['review_post_id'], $item['review_id'], $item['review_template']); $data = RWP_Reviewer::get_users_overall_score($ratings_scores, $item['review_post_id'], $item['review_id']); $score = $data['score']; $count = $data['count']; return '<strong>' . $score . '</strong> / ' . $this->templates[$item['review_template']]['template_maximum_score'] . ' | # ' . $count . ''; }
public static function manage_review($review, $post_id, $sort) { $templates = RWP_Reviewer::get_option('rwp_templates'); $template = $templates[self::review_field('review_template', $review, true)]; $return = array(); $return['review_title'] = self::review_field('review_title', $review, true); $return['review_image'] = self::review_field('review_image', $review, true); $return['review_type'] = self::review_field('review_type', $review, true); $return['review_id'] = self::review_field('review_id', $review, true); $return['review_type'] = self::review_field('review_type', $review, true); $return['review_title_options'] = self::review_field('review_title_options', $review, true); $return['review_custom_tabs'] = self::review_field('review_custom_tabs', $review, true); $return['review_template'] = self::review_field('review_template', $review, true); $return['review_use_featured_image'] = self::review_field('review_use_featured_image', $review, true); $template_tabs = self::template_field('template_custom_tabs', $template, true); foreach ($return['review_custom_tabs'] as $tab_key => $tab_value) { $return['review_custom_tabs'][$tab_key]['tab_label'] = $template_tabs[$tab_key]['tab_label']; } $return['review_color'] = self::review_field('review_type', $review, true) == 'UR' ? self::template_field('template_users_score_box_color', $template, true) : self::template_field('template_total_score_box_color', $template, true); switch ($sort) { case 'top_users_scores': $ratings_scores = RWP_Reviewer::get_ratings_single_scores($post_id, $return['review_id'], self::review_field('review_template', $review, true)); $data = RWP_Reviewer::get_users_overall_score($ratings_scores, $post_id, $return['review_id']); $overall = array('overall' => $data['score'], 'label' => $template['template_users_score_label']); break; case 'combo_1': $author_custom_score = self::review_field('review_custom_overall_score', $review, true); $author_score = empty($custom_score) ? RWP_Reviewer::get_review_overall_score($review) : $custom_score; $ratings_scores = RWP_Reviewer::get_ratings_single_scores($post_id, $return['review_id'], self::review_field('review_template', $review, true)); $users_score = RWP_Reviewer::get_users_overall_score($ratings_scores, $post_id, $return['review_id']); $o = $users_score['count'] > 0 ? round(($author_score + $users_score['score']) / 2, 1) : $author_score; $overall = array('overall' => $o, 'label' => __('Score', 'reviewer')); break; case 'top_rated': $ratings_scores = RWP_Reviewer::get_ratings_single_scores($post_id, $return['review_id'], self::review_field('review_template', $review, true)); $data = RWP_Reviewer::get_users_overall_score($ratings_scores, $post_id, $return['review_id']); $overall = array('overall' => $data['count'], 'label' => __('Ratings', 'reviewer')); break; case 'latest': case 'top_score': default: $custom_score = self::review_field('review_custom_overall_score', $review, true); $data = empty($custom_score) ? RWP_Reviewer::get_review_overall_score($review) : $custom_score; $overall = array('overall' => $data, 'label' => $template['template_total_score_label']); break; } $return['review_score'] = $overall; return $return; }