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();
 }
 function __construct()
 {
     $this->plugin_slug = 'reviewer';
     $this->templates_option = RWP_Reviewer::get_option('rwp_templates');
     $this->preferences_option = RWP_Reviewer::get_option('rwp_preferences');
     $this->set_table_fields();
 }
 function __construct()
 {
     $this->plugin_slug = 'reviewer';
     $this->templates_option = RWP_Reviewer::get_option('rwp_templates');
     $this->preferences_option = RWP_Reviewer::get_option('rwp_preferences');
     $this->review_fields = RWP_Reviews_Meta_Box::get_review_fields();
     //$this->template_fields 		= RWP_Template_Manager_Page::get_template_fields();
     $this->set_review_types();
 }
 public static function get_form()
 {
     $parent = 'rwp_rl';
     $form = '<div id="rwp-reviews-list-form">';
     $form .= '<form name="rwp_rl_form" id="rwp-rl-form">';
     $form .= '<table class="form-table">';
     $form .= '<tbody>';
     $form .= '<tr valign="top">';
     $form .= '<th scope="row">' . __('Reviews List Title', 'reviewer') . '</th>';
     $form .= '<td><input type="text" name="' . $parent . '[title]" value="" /></td>';
     $form .= '</tr>';
     $templates = RWP_Reviewer::get_option('rwp_templates');
     $form .= '<tr valign="top">';
     $form .= '<th scope="row">' . __('Reviews List Template', 'reviewer') . '</th>';
     $form .= '<td>';
     foreach ($templates as $template_id => $template) {
         $form .= '<span class="rwp-block"><input type="checkbox" name="' . $parent . '[template]" value="' . $template_id . '" /> ' . $template['template_name'] . '</span>';
     }
     $form .= '</td>';
     $form .= '</tr>';
     $form .= '<tr valign="top">';
     $form .= '<th scope="row">' . __('Scores Options', 'reviewer') . '</th>';
     $form .= '<td>';
     $form .= '<span class="rwp-block"><input type="checkbox" name="' . $parent . '[stars]" value="yes" /> ' . __('Show scores as stars', 'reviewer') . '</span>';
     $form .= '</td>';
     $form .= '</tr>';
     $sortings = array('latest' => __('Latest boxes', 'reviewer'), 'top_score' => __('Top scores boxes by reviewer', 'reviewer'), 'top_rated' => __('Top rated boxes by users', 'reviewer'), 'top_users_scores' => __('Top score boxes by users', 'reviewer'), 'combo_1' => __('Combo 1 | Average of reviewer and users scores', 'reviewer'));
     $form .= '<tr valign="top">';
     $form .= '<th scope="row">' . __('Reviews List Sorting', 'reviewer') . '</th>';
     $form .= '<td>';
     $form .= '<select name="' . $parent . '[sorting]">';
     foreach ($sortings as $sorting_id => $sorting) {
         $form .= '<option value="' . $sorting_id . '">' . $sorting . '</option>';
     }
     $form .= '</select>';
     $form .= '</td>';
     $form .= '</tr>';
     $form .= '<tr valign="top">';
     $form .= '<th scope="row">' . __('Number of reviews to display', 'reviewer') . '</th>';
     $form .= '<td><input type="text" name="' . $parent . '[count]" value="" placeholder="5" /></td>';
     $form .= '</tr>';
     $form .= '<tr valign="top">';
     $form .= '<th scope="row">' . __('Reviews List Layout', 'reviewer') . '</th>';
     $form .= '<td>';
     $form .= '<input type="radio" name="' . $parent . '[layout]" value="auto" checked /> Full width <br/>';
     $form .= '<input type="radio" name="' . $parent . '[layout]" value="inline" /> Inline';
     $form .= '</td>';
     $form .= '</tr>';
     //$form .= '';
     $form .= '</tbody>';
     $form .= '</table>';
     $form .= '<input id="rwp-rl-gen-btn" class="button button-primary" type="button"  value="' . __('Generate Shortcode', 'reviewer') . '"  />';
     $form .= '</form>';
     $form .= '</div>';
     return $form;
 }
 public function __construct()
 {
     parent::__construct();
     $this->set_colors_palettes();
     $this->template_fields = RWP_Template_Manager_Page::get_template_fields();
     $this->menu_slug = 'reviewer-template-manager-page';
     $this->option_name = 'rwp_templates';
     $this->option_value = RWP_Reviewer::get_option($this->option_name);
     $this->add_menu_page();
     $this->register_page_fields();
     $this->add_fix_image_uploading();
 }
 public function __construct()
 {
     parent::__construct();
     global $current_user;
     get_currentuserinfo();
     $this->user = $current_user;
     $this->set_support_fields();
     $this->menu_slug = 'reviewer-support-page';
     $this->parent_menu_slug = 'reviewer-main-page';
     $this->option_name = 'rwp_support';
     $this->option_value = RWP_Reviewer::get_option($this->option_name);
     $this->add_menu_page();
     $this->register_page_fields();
 }
 public static function ajax_callback_duplicate()
 {
     if (isset($_POST['templateId'])) {
         $templates = RWP_Reviewer::get_option('rwp_templates');
         if (isset($templates[$_POST['templateId']])) {
             $id = uniqid('rwp_template_');
             $new = $templates[$_POST['templateId']];
             $new['template_id'] = $id;
             $new['template_name'] = $new['template_name'] . ' ' . __('Copy', 'reviewer');
             $templates[$id] = $new;
         }
         update_option('rwp_templates', $templates);
     }
     die(json_encode(array('msg' => __('Template duplicated', 'reviewer'), 'html' => self::get_template_thumb($new))));
 }
Beispiel #8
0
 public static function ajax_callback()
 {
     $res = array('code' => 400, 'data' => array('msg' => __('The form was not submitted correctly', 'reviewer')));
     if (RWP_DEMO_MODE) {
         $res['data']['msg'] = __('The user review feature is disabled for demo mode.', 'reviewer');
         die(json_encode($res));
     }
     $fields = array('review_id', 'post_id', 'user_id', 'user_email', 'scores', 'user_name', 'title', 'comment', 'method', 'template', 'captcha');
     // Check if fields are set
     foreach ($fields as $key) {
         if (!isset($_POST[$key])) {
             die(json_encode($res));
         }
     }
     // Review ID
     $review_id = $_POST['review_id'];
     // Post ID
     $post_id = intval($_POST['post_id']);
     // User ID
     $user = wp_get_current_user();
     $user_id = $user instanceof WP_User && $user->ID == intval($_POST['user_id']) ? $user->ID : 0;
     // Cookie name
     $cookie_name = 'rwp_rating_' . $post_id . '_' . $review_id . '_' . $user_id;
     // Check if user already rated
     if (isset($_COOKIE[$cookie_name])) {
         $res['data']['msg'] = __('You have already rated.', 'reviewer');
         die(json_encode($res));
     }
     // Blacklist
     $blacklist = get_post_meta($post_id, 'rwp_rating_blacklist', true);
     if (isset($blacklist[$post_id . '-' . $review_id]) && in_array($user_id, $blacklist[$post_id . '-' . $review_id])) {
         $res['data']['msg'] = __('You have already rated!', 'reviewer');
         die(json_encode($res));
     }
     // Get post reviews
     $reviews = get_post_meta($post_id, 'rwp_reviews', true);
     // Review
     $review = isset($reviews[$review_id]) ? $reviews[$review_id] : array();
     // Templates
     $templates_option = RWP_Reviewer::get_option('rwp_templates');
     if (!isset($templates_option[$_POST['template']])) {
         die(json_encode($res));
     }
     // Preferences
     $preferences_option = RWP_Reviewer::get_option('rwp_preferences');
     // Review Template
     $template = $templates_option[$_POST['template']];
     // Review rating options
     //$rating_options = self::review_field( 'review_user_rating_options', $review, true );
     $rating_options = self::template_field('template_user_rating_options', $template, true);
     // Validate form fields
     $errors = array();
     // Captcha
     if (in_array('rating_option_captcha', $rating_options)) {
         $session_key = 'rwp-captcha-' . $post_id . '-' . $review_id;
         if (!isset($_SESSION[$session_key])) {
             $res['data']['msg'] = __('Captcha is not set, contact the Support Team', 'reviewer');
             die(json_encode($res));
         }
         //echo  $_SESSION[ $session_key ].  ' - ' . $_POST['captcha'];
         if ($_SESSION[$session_key] != $_POST['captcha']) {
             $captcha = RWP_Captcha::get_instance();
             $image = $captcha->generate($post_id, $review_id);
             $res['code'] = 401;
             $res['data']['msg'] = __('Secure code is not correct', 'reviewer');
             $res['data']['captcha'] = $image;
             die(json_encode($res));
         }
     }
     // Name
     if (in_array('rating_option_name', $rating_options)) {
         if ($user_id == 0) {
             $user_name = trim($_POST['user_name']);
             if (empty($user_name)) {
                 $errors[] = __('Your name is required', 'reviewer');
             }
             //$user_name = wp_kses_post( $user_name );
             $user_name = sanitize_text_field(stripslashes_deep($user_name));
         } else {
             $user_name = '';
         }
     } else {
         $user_name = '';
     }
     // Email
     if (in_array('rating_option_email', $rating_options)) {
         if ($user_id == 0) {
             $email = trim($_POST['user_email']);
             if (empty($email)) {
                 $errors[] = __('Your email is required', 'reviewer');
             } elseif (!is_email($email)) {
                 $errors[] = __('Your email is not valid', 'reviewer');
             }
         } else {
             $email = '';
         }
     } else {
         $email = '';
     }
     // Title
     if (in_array('rating_option_title', $rating_options)) {
         $title = trim($_POST['title']);
         if (empty($title)) {
             $errors[] = __('A review title is required', 'reviewer');
         }
         $title = sanitize_text_field(stripslashes_deep($title));
         // Check limits
         $limit = self::preferences_field('preferences_rating_title_limits', $preferences_option, true);
         $range = explode('-', $limit);
         $min = intval($range[0]);
         $max = $range[1] == 'inf' ? false : intval($range[1]);
         $len = strlen($title);
         if ($len < $min) {
             $errors[] = sprintf(__('The minimum number of characters is %d for review title', 'reviewer'), $min);
         }
         if ($max !== false && $len > $max) {
             $errors[] = sprintf(__('The maximum number of characters is %d for review title', 'reviewer'), $max);
         }
         //$title = wp_kses_post( $title );
     } else {
         $title = '';
     }
     // Comment
     if (in_array('rating_option_comment', $rating_options)) {
         $comment = trim($_POST['comment']);
         if (empty($comment)) {
             $errors[] = __('A review comment is required', 'reviewer');
         }
         $comment = implode("\n", array_map('sanitize_text_field', explode("\n", stripslashes_deep($comment))));
         // Check limits
         $limit = self::preferences_field('preferences_rating_comment_limits', $preferences_option, true);
         $range = explode('-', $limit);
         $min = intval($range[0]);
         $max = $range[1] == 'inf' ? false : intval($range[1]);
         $len = strlen($comment);
         if ($len < $min) {
             $errors[] = sprintf(__('The minimum number of characters is %d for review comment', 'reviewer'), $min);
         }
         if ($max !== false && $len > $max) {
             $errors[] = sprintf(__('The maximum number of characters is %d for review comment', 'reviewer'), $max);
         }
         //$comment = wp_kses_post( $comment );
     } else {
         $comment = '';
     }
     // Method
     $method = trim($_POST['method']);
     // Criteria count
     $criteria_count = count($template['template_criterias']);
     // Score
     $score = array();
     switch ($method) {
         case 'five_stars':
             $score_value = floatval($_POST['scores']);
             // Check if the 0 <= score <= 5
             if ($score_value < 0 || $score_value > 5) {
                 die(json_encode($res));
             }
             $score_value = RWP_Reviewer::get_in_base(5, $template['template_maximum_score'], $score_value);
             $precision = RWP_Reviewer::get_decimal_places(self::preferences_field('preferences_step', $preferences_option, true));
             $score_value = round($score_value, $precision);
             $order = self::template_field('template_criteria_order', $template, true);
             $criteria = self::template_field('template_criterias', $template, true);
             $order = $order == null ? array_keys($criteria) : $order;
             foreach ($order as $i) {
                 $score[$i] = $score_value;
             }
             break;
         case 'full_five_stars':
             if (is_array($_POST['scores']) && count($_POST['scores']) == $criteria_count) {
                 foreach ($_POST['scores'] as $s) {
                     $score_value = floatval($s['val']);
                     // Check if the 0 <= score <= 5
                     if ($score_value < 0 || $score_value > 5) {
                         die(json_encode($res));
                     }
                     $score_value = RWP_Reviewer::get_in_base(5, $template['template_maximum_score'], $score_value);
                     $precision = RWP_Reviewer::get_decimal_places(self::preferences_field('preferences_step', $preferences_option, true));
                     $score_value = round($score_value, $precision);
                     $score[$s['i']] = $score_value;
                 }
             } else {
                 for ($i = 0; $i < $criteria_count; $i++) {
                     $score[] = 0;
                 }
             }
             break;
         default:
             // Slider rating mode
             if (is_array($_POST['scores']) && count($_POST['scores']) == $criteria_count) {
                 foreach ($_POST['scores'] as $s) {
                     $score[$s['i']] = $s['val'];
                 }
             } else {
                 for ($i = 0; $i < $criteria_count; $i++) {
                     $score[] = 0;
                 }
             }
             break;
     }
     // Validate Scores
     $allow_zero_pref = self::preferences_field('preferences_rating_allow_zero', $preferences_option, true);
     if ($allow_zero_pref == 'no') {
         foreach ($score as $value) {
             if ($value == 0) {
                 $errors[] = __('Scores with zero value are not allowed', 'reviewer');
                 break;
             }
         }
     }
     // Check errors
     if (!empty($errors)) {
         if (in_array('rating_option_captcha', $rating_options)) {
             $captcha = RWP_Captcha::get_instance();
             $image = $captcha->generate($post_id, $review_id);
             $res['captcha'] = $image;
         } else {
             $res['captcha'] = '';
         }
         $res['code'] = 405;
         $res['data'] = $errors;
         die(json_encode($res));
     }
     // Status
     $moderation = self::preferences_field('preferences_rating_before_appears', $preferences_option, true);
     $status = $moderation == 'nothing' ? 'published' : 'pending';
     // Update pending count
     if ($status == 'pending') {
         $key = 'rwp_pending_ratings';
         $pend_count = get_option($key, 0);
         $pend_count++;
         update_option($key, $pend_count);
     }
     $rating = array('rating_id' => uniqid('rwp_rating_'), 'rating_post_id' => $post_id, 'rating_review_id' => $review_id, 'rating_score' => $score, 'rating_user_id' => $user_id, 'rating_user_name' => $user_name, 'rating_user_email' => $email, 'rating_title' => $title, 'rating_comment' => $comment, 'rating_date' => current_time('timestamp'), 'rating_status' => $status, 'rating_template' => $template['template_id']);
     // Save ratings
     $process = add_post_meta($post_id, 'rwp_rating_' . $review_id, $rating);
     // Check process res
     if ($process === FALSE) {
         $res['data']['msg'] = $template['template_failure_message'];
         die(json_encode($res));
     }
     // Likes
     $likes = get_post_meta($post_id, 'rwp_likes', true);
     if (is_array($likes)) {
         $likes[$rating['rating_id']] = array('yes' => 0, 'no' => 0, 'post_id' => $post_id, 'review_id' => $review_id);
     } else {
         $likes = array('' . $rating['rating_id'] => array('yes' => 0, 'no' => 0, 'post_id' => $post_id, 'review_id' => $review_id));
     }
     // Update
     update_post_meta($post_id, 'rwp_likes', $likes);
     if ($moderation == 'nothing') {
         // Success!
         $res['code'] = 200;
         $res['data'] = array('msg' => $template['template_success_message'], 'rating' => $rating);
     } else {
         // Success!
         $res['code'] = 201;
         $res['data'] = array('msg' => self::template_field('template_moderation_message', $template, true), 'rating' => $rating);
     }
     // Set the cookie
     setcookie($cookie_name, 'true', time() + 60 * 60 * 24 * 30, '/');
     // Update Blacklist
     if ($user_id > 0) {
         if (is_array($blacklist)) {
             $blacklist[$post_id . '-' . $review_id][] = $user_id;
         } else {
             $blacklist = array();
             $blacklist[$post_id . '-' . $review_id][] = $user_id;
         }
         update_post_meta($post_id, 'rwp_rating_blacklist', $blacklist);
     }
     // Notification
     $notification_pref = intval(self::preferences_field('preferences_notification', $preferences_option, true));
     $notification_email = self::preferences_field('preferences_notification_email', $preferences_option, true);
     if ($notification_pref > 0) {
         // Check if notification is enabled
         $notification_key = 'rwp_notification_ratings';
         $notification_ratings = RWP_Reviewer::get_option($notification_key);
         $notification_ratings[] = $rating['rating_id'];
         $notification_count = count($notification_ratings);
         if ($notification_count >= $notification_pref) {
             $sending = self::send_notification($notification_ratings, $notification_email);
             if ($sending) {
                 update_option($notification_key, array());
             } else {
                 update_option($notification_key, $notification_ratings);
             }
         } else {
             update_option($notification_key, $notification_ratings);
         }
     }
     die(json_encode($res));
 }
<?php

if (!$this->is_users_rating_disabled()) {
    $data = RWP_Reviewer::get_users_overall_score($this->ratings_scores, $this->post_id, $this->review_field('review_id', true));
    $score = $data['score'];
    $count = $data['count'];
    $theme = $this->template_field('template_theme', true);
    $this->snippets->add('aggregateRating', array());
    $this->snippets->add('aggregateRating.@type', 'AggregateRating');
    $this->snippets->add('aggregateRating.ratingValue', $score);
    $this->snippets->add('aggregateRating.worstRating', $this->template_field('template_minimum_score', true));
    $this->snippets->add('aggregateRating.bestRating', $this->template_field('template_maximum_score', true));
    $this->snippets->add('aggregateRating.ratingCount', $count);
    ?>

<div 
    class="rwp-users-score <?php 
    if ($is_UR) {
        echo 'rwp-ur';
    }
    ?>
" 

    <?php 
    if ($theme != 'rwp-theme-8') {
        ?>
   	style="background: <?php 
        $this->template_field('template_users_score_box_color');
        ?>
; " 
    <?php 
            echo '</div><!-- /criterion -->';
            break;
        case 'rwp-theme-3':
            echo '<div class="rwp-criterion">';
            echo $this->get_knobs($score);
            echo '<span class="rwp-criterion-label" style="line-height: ' . $font_size . 'px;">' . $criteria[$i] . '</span>';
            echo '</div><!-- /criterion -->';
            break;
        case 'rwp-theme-2':
            echo '<div class="rwp-criterion">';
            echo '<span class="rwp-criterion-label" style="line-height: ' . $font_size . 'px;">' . $criteria[$i] . '</span>';
            echo $this->get_stars($score, $max);
            echo '</div><!-- /criterion -->';
            break;
        case 'rwp-theme-1':
        default:
            echo '<div class="rwp-criterion">';
            echo '<div class="rwp-criterion-text">';
            echo '<span class="rwp-criterion-label" style="line-height: ' . $font_size . 'px;">' . $criteria[$i] . '</span>';
            echo '<span class="rwp-criterion-score" style="line-height: ' . $score_size . 'px; font-size: ' . $score_size . 'px;">' . RWP_Reviewer::format_number($score) . '</span>';
            echo '</div><!-- /criterion-text -->';
            echo '<div class="rwp-criterion-bar-base">';
            echo $this->get_score_bar($score);
            echo '</div><!-- /criterion-bar -->';
            echo '</div><!-- /criterion -->';
            break;
    }
}
?>

</div> <!-- /scores -->
Beispiel #11
0
 private static function get_stars($scores = array(), $max = 10, $stars = 5, $icon = '')
 {
     $avg = is_array($scores) ? RWP_Reviewer::get_avg($scores) : floatval($scores);
     $value = RWP_Reviewer::get_in_base($max, $stars, $avg);
     $int_value = intval($value);
     $decimal_value = $value - $int_value;
     if ($decimal_value >= 0.4 && $decimal_value <= 0.6) {
         $score = $int_value + 0.5;
     } else {
         if ($decimal_value > 0.6) {
             $score = $int_value + 1;
         } else {
             $score = $int_value;
         }
     }
     $count = $stars * 2;
     $html = '<div class="rwp-str rwp-api-rating-wrapper">';
     $j = 0;
     for ($i = 0; $i < $count; $i++) {
         $oe = $i % 2 == 0 ? 'rwp-o' : 'rwp-e';
         $fx = $j < $score ? 'rwp-f' : 'rwp-x';
         $html .= '<span class="rwp-s ' . $oe . ' ' . $fx . '" style="background-image: url(' . $icon . ');"></span>';
         $j += 0.5;
     }
     $html .= '</div><!-- /stars -->';
     return $html;
 }
 public function activation_notice()
 {
     $support = RWP_Reviewer::get_option('rwp_support');
     if (!isset($support['support_copy_id'])) {
         echo '<div class="update-nag">';
         echo '<p>' . __('Thank you for purchasing the Reviewer Plugin. Activate your copy in order to get support.', $this->plugin_slug) . ' <a href="">' . __('Activate Now', $this->plugin_slug) . '</a></p>';
         echo '</div>';
     }
 }
if (!$is_UR) {
    ?>
<div 
    class="rwp-overall-score <?php 
    echo $this->is_users_rating_disabled() ? 'rwp-only' : '';
    ?>
" 
    style="background: <?php 
    $this->template_field('template_total_score_box_color');
    ?>
;" 
>

    <?php 
    $custom_score = $this->review_field('review_custom_overall_score', true);
    $overall = empty($custom_score) ? RWP_Reviewer::get_review_overall_score($this->review) : $custom_score;
    $theme = $this->template_field('template_theme', true);
    $this->snippets->add('review.reviewRating', array());
    $this->snippets->add('review.reviewRating.@type', 'Rating');
    $this->snippets->add('review.reviewRating.ratingValue', $overall);
    $this->snippets->add('review.reviewRating.worstRating', $this->template_field('template_minimum_score', true));
    $this->snippets->add('review.reviewRating.bestRating', $this->template_field('template_maximum_score', true));
    ?>
        
    <?php 
    if ($theme != 'rwp-theme-4') {
        ?>
        <span  class="rwp-overlall-score-value"><?php 
        echo $overall;
        ?>
</span>
 protected function get_stars($scores = array(), $stars = 5)
 {
     $avg = is_array($scores) ? RWP_Reviewer::get_avg($scores) : floatval($scores);
     $value = RWP_Reviewer::get_in_base($this->template_field('template_maximum_score', true), $stars, $avg);
     $int_value = intval($value);
     $decimal_value = $value - $int_value;
     if ($decimal_value >= 0.4 && $decimal_value <= 0.6) {
         $score = $int_value + 0.5;
     } else {
         if ($decimal_value > 0.6) {
             $score = $int_value + 1;
         } else {
             $score = $int_value;
         }
     }
     $count = $stars * 2;
     $html = '<div class="rwp-str">';
     $j = 0;
     for ($i = 0; $i < $count; $i++) {
         $oe = $i % 2 == 0 ? 'rwp-o' : 'rwp-e';
         $fx = $j < $score ? 'rwp-f' : 'rwp-x';
         $html .= '<span class="rwp-s ' . $oe . ' ' . $fx . '" style="background-image: url(' . $this->template_field('template_rate_image', true) . ');"></span>';
         $j += 0.5;
     }
     $html .= '</div><!-- /stars -->';
     return $html;
 }
 protected function get_score_bar($score, $template, $theme = '', $size = 0)
 {
     $max = floatval($template['template_maximum_score']);
     $value = floatval($score);
     $range = explode('-', $template['template_score_percentages']);
     $low = floatval($range[0]);
     $high = floatval($range[1]);
     $pct = round($value / $max * 100, 1);
     if ($pct < $low) {
         $color = $template['template_low_score_color'];
     } else {
         if ($pct > $high) {
             $color = $template['template_high_score_color'];
         } else {
             $color = $template['template_medium_score_color'];
         }
     }
     $in = !empty($theme) ? '<span class="rwp-criterion-score" style="font-size: ' . ($size + 2) . 'px;">' . RWP_Reviewer::format_number($score) . '</span>' : '';
     return '<div class="rwp-score-bar" style="width: ' . $pct . '%; background: ' . $color . ';">' . $in . '</div>';
 }
 public static function ajax_callback()
 {
     $restore_value = RWP_Reviewer::get_option('rwp_restore');
     if (!empty($restore_value)) {
         die(json_encode(array('msg' => __('Data already restored', 'reviewer'))));
     }
     // - - - Templates - - -
     $previous_templates = RWP_Reviewer::get_option('rwp_reviewer_templates');
     $templates = RWP_Reviewer::get_option('rwp_templates');
     foreach ($previous_templates as $t) {
         $temp = array();
         $temp['template_id'] = $t['template_id'];
         $temp['template_name'] = $t['template_title'];
         $temp['template_minimum_score'] = $t['template_items_rage']['min'];
         $temp['template_maximum_score'] = $t['template_items_rage']['max'];
         $temp['template_score_percentages'] = '30-69';
         foreach ($t['template_items'] as $criterion) {
             $temp['template_criterias'][] = $criterion['label'];
         }
         switch ($t['template_theme']) {
             case 'rwp_bars_theme':
                 $theme = 'rwp-theme-1';
                 break;
             case 'rwp_bars_mini_theme':
                 $theme = 'rwp-theme-5';
                 break;
             case 'rwp_stars_theme':
                 $theme = 'rwp-theme-2';
                 break;
             case 'rwp_stars_mini_theme':
                 $theme = 'rwp-theme-6';
                 break;
             case 'rwp_circles_theme':
                 $theme = 'rwp-theme-3';
                 break;
             case 'rwp_big_circles_theme':
                 $theme = 'rwp-theme-7';
                 break;
             default:
                 $theme = 'rwp-theme-1';
                 break;
         }
         $temp['template_theme'] = $theme;
         $temp['template_text_color'] = $t['template_text_color'];
         $temp['template_total_score_box_color'] = $t['template_total_score_color_box'];
         $temp['template_users_score_box_color'] = '#566473';
         $temp['template_high_score_color'] = $t['template_scores_colors']['high_score'];
         $temp['template_medium_score_color'] = $t['template_scores_colors']['medium_score'];
         $temp['template_low_score_color'] = $t['template_scores_colors']['low_score'];
         $temp['template_pros_label_color'] = $t['template_pros_settings']['label_color'];
         $temp['template_pros_label_font_size'] = $t['template_pros_settings']['label_size'];
         $temp['template_pros_text_font_size'] = $t['template_pros_settings']['text_size'];
         $temp['template_cons_label_color'] = $t['template_cons_settings']['label_color'];
         $temp['template_cons_label_font_size'] = $t['template_cons_settings']['label_size'];
         $temp['template_cons_text_font_size'] = $t['template_cons_settings']['text_size'];
         $temp['template_total_score_label'] = $t['template_total_score_label'];
         $temp['template_users_score_label'] = 'Users Score';
         $temp['template_pros_label'] = $t['template_pros_settings']['label'];
         $temp['template_cons_label'] = $t['template_cons_settings']['label'];
         $temp['template_message_to_rate'] = 'Leave your rating';
         $temp['template_message_to_rate_login'] = '******';
         $temp['template_success_message'] = 'Thank you for your rating';
         $temp['template_failure_message'] = 'Error during rate process';
         $temp['template_rate_image'] = RWP_PLUGIN_URL . 'public/assets/images/rating-star.png';
         $templates[$temp['template_id']] = $temp;
     }
     // Save new templates
     $res = update_option('rwp_templates', $templates);
     // - - - Reviews - - -
     global $wpdb;
     // Get posts ids that contain reviews
     $post_meta = $wpdb->get_results("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'rwp_reviews';", ARRAY_A);
     $posts = array();
     foreach ($post_meta as $p) {
         $posts[] = $p['post_id'];
     }
     // Loop all posts
     foreach ($posts as $post_id) {
         $revs = array();
         // Get post reviews
         $reviews = get_post_meta($post_id, 'rwp_reviews', true);
         if (!empty($reviews)) {
             // Check if there are reviews
             // Store old reviews
             update_post_meta($post_id, 'rwp_old_reviews', $reviews);
             // Loop all reviews
             foreach ($reviews as $review) {
                 $review_id = $review['review_id'];
                 $revs[$review_id]['review_id'] = $review['review_id'];
                 $revs[$review_id]['review_title'] = $review['review_title'];
                 $revs[$review_id]['review_template'] = $review['review_template'];
                 $revs[$review_id]['review_scores'] = $review['review_items'];
                 $revs[$review_id]['review_pros'] = $review['review_good_stuff'];
                 $revs[$review_id]['review_cons'] = $review['review_bad_stuff'];
             }
             // Save updated reviews
             update_post_meta($post_id, 'rwp_reviews', $revs);
         }
     }
     update_option('rwp_restore', 1);
     die(json_encode(array('msg' => __('Restore completed', 'reviewer'))));
 }
 public function get_knobs($score)
 {
     $max = $this->template_field('template_maximum_score', true);
     $min = $this->template_field('template_minimum_score', true);
     $value = RWP_Reviewer::get_in_base($this->template_field('template_maximum_score', true), $max, floatval($score));
     $range = explode('-', $this->template_field('template_score_percentages', true));
     $low = floatval($range[0]);
     $high = floatval($range[1]);
     $pct = round($value / $max * 100, 1);
     if ($pct < $low) {
         $color = $this->template_field('template_low_score_color', true);
     } else {
         if ($pct > $high) {
             $color = $this->template_field('template_high_score_color', true);
         } else {
             $color = $this->template_field('template_medium_score_color', true);
         }
     }
     return '<input type="text" value="' . $value . '" class="rwp-knob" data-min="' . $min . '" data-max="' . $max . '" data-fgColor="' . $color . '" />';
 }
 public static function get_score_bar($score = array(), $template = array(), $theme = '', $size = 0)
 {
     $avg = is_array($score) ? RWP_Reviewer::get_avg($score) : floatval($score);
     $max = floatval(self::template_field('template_maximum_score', $template, true));
     $value = floatval($avg);
     $range = explode('-', self::template_field('template_score_percentages', $template, true));
     $low = floatval($range[0]);
     $high = floatval($range[1]);
     $pct = round($value / $max * 100, 1);
     if ($pct < $low) {
         $color = self::template_field('template_low_score_color', $template, true);
     } else {
         if ($pct > $high) {
             $color = self::template_field('template_high_score_color', $template, true);
         } else {
             $color = self::template_field('template_medium_score_color', $template, true);
         }
     }
     $in = !empty($theme) ? '<span class="rwp-criterion-score" style="font-size: ' . ($size + 2) . 'px;">' . RWP_Reviewer::format_number($avg) . '</span>' : '';
     return '<div class="rwp-score-bar" style="width: ' . $pct . '%; background: ' . $color . ';">' . $in . '</div>';
 }
 function column_rwp_reviews_table_review_score($item)
 {
     $type = isset($item['review_type']) ? $item['review_type'] : 'PAR+UR';
     if ($type == 'PAR+UR') {
         $overall = isset($item['review_scores']) ? round(RWP_Reviewer::get_avg($item['review_scores']), 1) : 0;
         $score = isset($item['review_custom_overall_score']) && !empty($item['review_custom_overall_score']) ? $item['review_custom_overall_score'] : $overall;
         return '<strong>' . $score . '</strong> / ' . $this->templates[$item['review_template']]['template_maximum_score'];
     } else {
         return '---';
     }
 }
        <span class="rwp-total-score-label"><?php 
    echo $this->template['template_total_score_label'];
    ?>
</span>
    </div><!--/total-score-->
    
    <?php 
}
?>

    <?php 
if ($this->pref['preferences_authorization'] != 'disabled') {
    ?>

    <?php 
    $data = RWP_Reviewer::get_users_overall_score($review['review_ratings_scores'], $review['review_post_id'], $review['review_id']);
    $score = $data['score'];
    $count = $data['count'];
    $count_label = $count == 1 ? $this->template_field('template_users_count_label_s', true) : $this->template_field('template_users_count_label_p', true);
    ?>

    <div class="rwp-users-score-wrap <?php 
    echo $is_UR ? 'rwp-ur' : '';
    ?>
"<?php 
    $this->style_users_score();
    ?>
>
        <span class="rwp-users-score"><?php 
    echo $score;
    ?>
 public static function sort_score($a, $b)
 {
     $avg_a = RWP_Reviewer::get_avg($a['rating_score']);
     $avg_b = RWP_Reviewer::get_avg($b['rating_score']);
     if ($avg_a == $avg_b) {
         return 0;
     }
     return $avg_a > $avg_b ? -1 : 1;
 }
Beispiel #22
0
    echo $review_title;
    ?>
</a>

			<div class="rwp-rl-scores-wrap">

			    <div class="rwp-rl-total-score-wrap">			        
			    	<span class="rwp-rl-total-score-label"><?php 
    echo $reviews[$i]['review_score']['label'];
    ?>
</span> 
			        <span class="rwp-rl-total-score" style="color:<?php 
    echo $reviews[$i]['review_color'];
    ?>
"><?php 
    echo $stars == 'yes' ? RWP_Reviewer::get_stars($reviews[$i]['review_score']['overall'], $templates[$reviews[$i]['review_template']]) : $reviews[$i]['review_score']['overall'];
    ?>
</span>
			    </div><!--/total-score-->

			    <?php 
    if (isset($reviews[$i]['review_custom_tabs']) && !empty($reviews[$i]['review_custom_tabs'])) {
        ?>

				    <?php 
        foreach ($reviews[$i]['review_custom_tabs'] as $tab) {
            if (empty($tab['tab_value'])) {
                continue;
            }
            ?>
				    	
Beispiel #23
0
 public function validate_fields($fields)
 {
     global $wpdb;
     // Validation
     if (!isset($fields['io_action'])) {
         add_settings_error($this->option_name, 'rwp-backup-error3', __('The form was not submitted correctly!', $this->plugin_slug), 'error');
         return $this->option_value;
     }
     $wp_options = array('rwp_templates', 'rwp_preferences', 'rwp_support');
     if ($fields['io_action'] == 'rwp_export') {
         // EXPORT
         // - - - IO Process - - -
         // Templates, Preferences, Support
         $content = array();
         foreach ($wp_options as $option_key) {
             $data = RWP_Reviewer::get_option($option_key);
             if (empty($data)) {
                 continue;
             }
             $content[$option_key] = maybe_serialize($data);
         }
         // Reviews
         $post_meta = $wpdb->get_results("SELECT * FROM {$wpdb->postmeta} WHERE meta_key = 'rwp_reviews';", ARRAY_A);
         if ($post_meta) {
             $reviews = array();
             foreach ($post_meta as $value) {
                 $reviews[] = array('post_id' => $value['post_id'], 'meta_value' => $value['meta_value']);
             }
             $content['rwp_reviews'] = $reviews;
         }
         // Tables
         $post_meta = $wpdb->get_results("SELECT * FROM {$wpdb->postmeta} WHERE meta_key = 'rwp_tables';", ARRAY_A);
         if ($post_meta) {
             $tables = array();
             foreach ($post_meta as $value) {
                 $tables[] = array('post_id' => $value['post_id'], 'meta_value' => $value['meta_value']);
             }
             $content['rwp_tables'] = $tables;
         }
         // Ratings
         $post_meta = $wpdb->get_results("SELECT * FROM {$wpdb->postmeta} WHERE meta_key LIKE 'rwp_rating%';", ARRAY_A);
         if ($post_meta) {
             $ratings = array();
             foreach ($post_meta as $value) {
                 $ratings[] = array('post_id' => $value['post_id'], 'meta_key' => $value['meta_key'], 'meta_value' => $value['meta_value']);
             }
             $content['rwp_ratings'] = $ratings;
         }
         //RWP_Reviewer::pretty_print( $content ); flush(); die();
         // Creating the file
         $filename = RWP_PLUGIN_PATH . 'backup/Reviewer_Plugin_Backup_' . date('Y-m-d_H-i-s') . '.json';
         $fp = fopen($filename, 'w');
         if ($fp === false) {
             // No privileges to open the file
             add_settings_error($this->option_name, 'rwp-backup-error1', __('Unable to create the backup file. Check you have the privileges to write on reviewer/backup folder', $this->plugin_slug), 'error');
             return $this->option_value;
         }
         fputs($fp, json_encode($content));
         fclose($fp);
         if (!is_file($filename)) {
             add_settings_error($this->option_name, 'rwp-backup-error2', __('Unable to verify the new backup file.', $this->plugin_slug), 'error');
             return $this->option_value;
         }
         add_settings_error($this->option_name, 'rwp-backup-ok', __('Success! You can dowload your Reviewer backup file from the list down below. You can find all backup file inside the reviewer/backup folder.', $this->plugin_slug), 'updated');
         $this->option_value['last_exporting'] = date('Y-m-d H-i-s');
         return $this->option_value;
     } else {
         // IMPORT
         // Validation
         if (!isset($_FILES[$this->option_name])) {
             add_settings_error($this->option_name, 'rwp-backup-error5', __('Unable upload backup file.', $this->plugin_slug), 'error');
             return $this->option_value;
         }
         // Type check
         //if( 'application/json' != $_FILES[ $this->option_name ]['type']['io_file'] ) {
         //	add_settings_error( $this->option_name, 'rwp-backup-error6', __( 'Please upload a json file that contains a backup of Reviewer plugin.', $this->plugin_slug ), 'error' );
         //	return $this->option_value;
         //}
         // Get Data
         $json_file = @file_get_contents($_FILES[$this->option_name]['tmp_name']['io_file']);
         $data = json_decode($json_file, true);
         $errors = array();
         // Options
         foreach ($wp_options as $option_key) {
             if (!isset($data[$option_key])) {
                 continue;
             }
             //delete_option($option_key);
             $res = update_option($option_key, maybe_unserialize($data[$option_key]));
             $r = get_option($option_key);
             //RWP_Reviewer::pretty_print( $r );
             // if( !$res )
             // 	$errors[] = sprintf( __('Unable to restore %s option', $this->plugin_slug), $option_key );
         }
         //RWP_Reviewer::pretty_print($_SERVER); flush(); die();
         // Postmeta
         $wp_postmeta = array('rwp_reviews', 'rwp_tables');
         foreach ($wp_postmeta as $meta_key) {
             if (!isset($data[$meta_key])) {
                 continue;
             }
             foreach ($data[$meta_key] as $meta) {
                 $res = update_post_meta($meta['post_id'], $meta_key, maybe_unserialize($meta['meta_value']));
                 // if( $res !== false )
                 // 	$errors[] = sprintf( __('Unable to restore %s post_meta', $this->plugin_slug), $meta_key );
             }
         }
         // Ratings
         $meta_key = 'rwp_ratings';
         if (!isset($data[$meta_key])) {
             foreach ($data[$meta_key] as $meta) {
                 $res = update_post_meta($meta['post_id'], $meta['meta_key'], maybe_unserialize($meta['meta_value']));
             }
             if (!empty($errors)) {
                 add_settings_error($this->option_name, 'rwp-backup-error7', implode('<br/>', $errors), 'update-nag');
             } else {
                 add_settings_error($this->option_name, 'rwp-backup-import-ok', __('The backup was successfully imported.', $this->plugin_slug), 'updated');
             }
         }
         //RWP_Reviewer::pretty_print( $errors ); flush(); die();
         $this->option_value['last_importing'] = date('Y-m-d H-i-s');
         return $this->option_value;
     }
 }
 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;
 }