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();
 }
 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 function do_shortcode($atts)
 {
     extract(shortcode_atts(array('id' => '', 'post' => get_the_ID()), $atts));
     $this->post_id = $post;
     $post_id = $post;
     // Get post tables
     $tables = get_post_meta($this->post_id, 'rwp_tables', true);
     // Check if user has inserted a valid table ID
     if (!isset($tables[$id])) {
         return '<p>' . __('No table found! Insert a valid table ID.', $this->plugin_slug) . '</p>';
     }
     // All templates
     $templates_option = RWP_Reviewer::get_option('rwp_templates');
     // Set table
     $this->table = $tables[$id];
     // Set template
     $this->template = $templates_option[$this->table['table_template']];
     // Preferences
     $this->pref = RWP_Reviewer::get_option('rwp_preferences');
     // Check if user has inserted one review in table
     if (empty($this->table['table_reviews'])) {
         return '<p>' . __('Add reviews to table.', $this->plugin_slug) . '</p>';
     }
     // Get table reviews
     $this->reviews = $this->get_table_reviews($this->table['table_reviews']);
     $table_theme = $this->get_table_theme();
     //RWP_Reviewer::pretty_print($this->reviews); //return;
     ob_start();
     include 'themes/layout-table.php';
     //RWP_Reviewer::pretty_print( $this->table );
     //RWP_Reviewer::pretty_print( $this->template );
     //RWP_Reviewer::pretty_print( $this->reviews );
     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->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->menu_slug = 'reviewer-reviews-page';
     $this->parent_menu_slug = 'reviewer-main-page';
     $this->templates_option = RWP_Reviewer::get_option('rwp_templates');
     $this->add_menu_page();
     // Localize
     add_action('admin_enqueue_scripts', array($this, 'localize_script'));
 }
 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))));
 }
 public function __construct()
 {
     // widget actual processes
     $this->plugin_slug = 'reviewer';
     $this->templates = RWP_Reviewer::get_option('rwp_templates');
     $this->preferences = RWP_Reviewer::get_option('rwp_preferences');
     $template_fields = RWP_Template_Manager_Page::get_template_fields();
     $this->ratings_options = $template_fields['template_user_rating_options']['options'];
     unset($this->ratings_options['rating_option_captcha'], $this->ratings_options['rating_option_email'], $this->ratings_options['rating_option_like']);
     $this->ratings_options['rating_option_post_title'] = __('Post Title', $this->plugin_slug);
     $this->ratings_options['rating_option_link'] = __('Show Link', $this->plugin_slug);
     add_action('init', array($this, 'set_widget_fields'));
     $options = array('description' => __('Reviewer Plugin Widget allows you to display your latest, top score users reviews.', $this->plugin_slug), 'name' => 'Reviewer | Users Reviews');
     parent::__construct('rwp-ratings-widget', '', $options);
 }
Beispiel #11
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));
 }
 function __construct($ratings)
 {
     // Set parent defaults
     parent::__construct(array('ajax' => false));
     $this->ratings = $ratings;
     $this->templates = RWP_Reviewer::get_option('rwp_templates');
     $this->preferences = RWP_Reviewer::get_option('rwp_preferences');
 }
 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 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();
 }
 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>';
     }
 }
 public static function get_ratings_single_scores($post_id, $review_id, $template_id)
 {
     // Old Rating
     //$ratings 		= get_post_meta( $post_id, 'rwp_ratings', true );
     //$old_ratings	= ( isset( $ratings[ $review_id ] ) ) ? $ratings[ $review_id ] : array( 'rating_count' => 0, 'rating_total_score' => 0 );
     // Templates
     $templates = self::get_option('rwp_templates');
     $template = isset($templates[$template_id]) ? $templates[$template_id] : array();
     // Preferences
     $preferences = RWP_Reviewer::get_option('rwp_preferences');
     // New Ratings
     $ratings = get_post_meta($post_id, 'rwp_rating_' . $review_id);
     $new_ratings = is_array($ratings) ? $ratings : array();
     $moderation = self::preferences_field('preferences_rating_before_appears', $preferences, true);
     $new_ratings = RWP_Reviewer::filter_ratings($new_ratings, $moderation);
     if (empty($template)) {
         return array();
     }
     $order = self::template_field('template_criteria_order', $template, true);
     $criteria = self::template_field('template_criterias', $template, true);
     $order = $order == null ? array_keys($criteria) : $order;
     $scores = array();
     $count = count($new_ratings);
     if ($count > 0) {
         $precision = self::get_decimal_places(self::preferences_field('preferences_step', $preferences, true));
         foreach ($order as $i) {
             $scores[$i] = 0;
         }
         foreach ($new_ratings as $rating) {
             if (!is_array($rating)) {
                 $rating = maybe_unserialize($rating);
             }
             foreach ($order as $i) {
                 $scores[$i] += isset($rating['rating_score']) && isset($rating['rating_score'][$i]) ? $rating['rating_score'][$i] : 0;
             }
         }
         foreach ($order as $i) {
             $scores[$i] = round($scores[$i] / $count, $precision);
         }
     } else {
         foreach ($order as $i) {
             $scores[$i] = 0;
         }
     }
     //self::pretty_print($new_ratings);
     //self::pretty_print($old_ratings);
     //self::pretty_print($scores);
     return array('scores' => $scores, 'count' => $count);
 }
Beispiel #17
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;
 }