Yasr – Yet Another Stars Rating - Version 2.0.9

Version Description

  • TWEAKED: This is the first of two important releases for YASR. Some changes in the database has been done. BACKUP YOUR DATABASE BEFORE UPDATING
  • FIXED: RTL support in admin area
Download this release

Release Info

Developer Dudo
Plugin Icon 128x128 Yasr – Yet Another Stars Rating
Version 2.0.9
Comparing to
See all releases

Code changes from version 2.0.8 to 2.0.9

js/yasr-admin.js CHANGED
@@ -62,24 +62,25 @@ function yasrPrintMetaBoxOverall(overallRating) {
62
 
63
  /****** Yasr Metabox Multiple Rating ******/
64
 
65
- function yasrAdminMultiSet(nMultiSet, postid, setId, nonceMulti) {
66
 
67
  nMultiSet = parseInt(nMultiSet);
68
 
69
  if (nMultiSet === 1) {
70
 
71
- yasrPrintAdminMultiSet(setId, postid, nonceMulti, nMultiSet);
72
 
73
  } else {
74
 
75
  jQuery('#yasr-button-select-set').on("click", function () {
76
 
77
  //get the multi data
 
78
  var setId = jQuery('#select_set').val();
79
 
80
  jQuery("#yasr-loader-select-multi-set").show();
81
 
82
- yasrPrintAdminMultiSet(setId, postid, nonceMulti);
83
 
84
  return false; // prevent default click action from happening!
85
 
@@ -90,7 +91,7 @@ function yasrAdminMultiSet(nMultiSet, postid, setId, nonceMulti) {
90
  }
91
 
92
  //print the table
93
- function yasrPrintAdminMultiSet(setId, postid, nonceMulti, nMultiSet) {
94
 
95
  var data_id = {
96
  action: 'yasr_send_id_nameset',
@@ -101,7 +102,7 @@ function yasrPrintAdminMultiSet(setId, postid, nonceMulti, nMultiSet) {
101
  jQuery.post(ajaxurl, data_id, function (response) {
102
 
103
  //Hide the loader near the select only if more multiset are used
104
- if (nMultiSet !== 1) {
105
  document.getElementById('yasr-loader-select-multi-set').style.display = 'none';
106
  }
107
 
@@ -117,7 +118,8 @@ function yasrPrintAdminMultiSet(setId, postid, nonceMulti, nMultiSet) {
117
 
118
  content += '<tr>';
119
  content += '<td>' + valueName + '</td>';
120
- content += '<td><div class="yasr-multiset-admin" id="yasr-multiset-admin-' + valueID + '" data-rating="' + valueRating + '" data-multi-idfield="' + valueID + '"></div>';
 
121
  content += '<span id="yasr-loader-multi-set-field-' + valueID + '" style="display: none">';
122
  content += '<img src="' + yasrCommonDataAdmin.loaderHtml + '"></span>';
123
  content += '</span>';
@@ -134,7 +136,7 @@ function yasrPrintAdminMultiSet(setId, postid, nonceMulti, nMultiSet) {
134
  document.getElementById('yasr-multi-set-admin-choose-text').style.display = 'block';
135
 
136
  //Set rater for divs
137
- yasrSetRaterAdminMulti(postid, setId, nonceMulti);
138
 
139
  //Show shortcode
140
  document.getElementById('yasr-multi-set-admin-explain').style.display = 'block';
@@ -149,17 +151,22 @@ function yasrPrintAdminMultiSet(setId, postid, nonceMulti, nMultiSet) {
149
  }
150
 
151
  //Rater for multiset
152
- function yasrSetRaterAdminMulti(postid, setId, nonceMulti) {
 
 
 
153
 
154
  var yasrMultiSetAdmin = document.getElementsByClassName('yasr-multiset-admin');
155
 
 
 
 
 
156
  for (var i = 0; i < yasrMultiSetAdmin.length; i++) {
157
 
158
  (function (i) {
159
 
160
  var htmlId = yasrMultiSetAdmin.item(i).id;
161
- var idField = yasrMultiSetAdmin.item(i).getAttribute('data-multi-idfield');
162
-
163
  var elem = document.getElementById(htmlId);
164
 
165
  raterJs({
@@ -174,28 +181,24 @@ function yasrSetRaterAdminMulti(postid, setId, nonceMulti) {
174
  rating = rating.toFixed(1);
175
  //Be sure is a number and not a string
176
  rating = parseFloat(rating);
177
- this.setRating(rating) //Set the rating
178
-
179
- document.getElementById("yasr-loader-multi-set-field-" + idField).style.display = '';
180
 
181
- jQuery("#yasr-loader-multi-set-field-" + idField).show();
182
 
183
- var data = {
184
- action: 'yasr_send_id_field_with_vote',
185
- nonce: nonceMulti,
186
- rating: rating,
187
- post_id: postid,
188
- id_field: idField,
189
- set_type: setId
190
  };
191
 
192
- //Send value to the Server
193
- jQuery.post(ajaxurl, data, function () {
194
- document.getElementById("yasr-loader-multi-set-field-" + idField).style.display = 'none';
195
- });
196
 
197
- done();
 
 
 
198
 
 
199
  }
200
 
201
  });
62
 
63
  /****** Yasr Metabox Multiple Rating ******/
64
 
65
+ function yasrAdminMultiSet(nMultiSet, postid, setId) {
66
 
67
  nMultiSet = parseInt(nMultiSet);
68
 
69
  if (nMultiSet === 1) {
70
 
71
+ yasrPrintAdminMultiSet(setId, postid, false);
72
 
73
  } else {
74
 
75
  jQuery('#yasr-button-select-set').on("click", function () {
76
 
77
  //get the multi data
78
+ //overwrite setID
79
  var setId = jQuery('#select_set').val();
80
 
81
  jQuery("#yasr-loader-select-multi-set").show();
82
 
83
+ yasrPrintAdminMultiSet(setId, postid, true);
84
 
85
  return false; // prevent default click action from happening!
86
 
91
  }
92
 
93
  //print the table
94
+ function yasrPrintAdminMultiSet(setId, postid, moreThanOneMultiSet) {
95
 
96
  var data_id = {
97
  action: 'yasr_send_id_nameset',
102
  jQuery.post(ajaxurl, data_id, function (response) {
103
 
104
  //Hide the loader near the select only if more multiset are used
105
+ if (moreThanOneMultiSet === true) {
106
  document.getElementById('yasr-loader-select-multi-set').style.display = 'none';
107
  }
108
 
118
 
119
  content += '<tr>';
120
  content += '<td>' + valueName + '</td>';
121
+ content += '<td><div class="yasr-multiset-admin" id="yasr-multiset-admin-' + valueID + '" data-rating="'
122
+ + valueRating + '" data-multi-idfield="' + valueID + '"></div>';
123
  content += '<span id="yasr-loader-multi-set-field-' + valueID + '" style="display: none">';
124
  content += '<img src="' + yasrCommonDataAdmin.loaderHtml + '"></span>';
125
  content += '</span>';
136
  document.getElementById('yasr-multi-set-admin-choose-text').style.display = 'block';
137
 
138
  //Set rater for divs
139
+ yasrSetRaterAdminMulti(setId);
140
 
141
  //Show shortcode
142
  document.getElementById('yasr-multi-set-admin-explain').style.display = 'block';
151
  }
152
 
153
  //Rater for multiset
154
+ function yasrSetRaterAdminMulti(setId) {
155
+
156
+ //update hidden field
157
+ document.getElementById('yasr-multiset-id').value = setId;
158
 
159
  var yasrMultiSetAdmin = document.getElementsByClassName('yasr-multiset-admin');
160
 
161
+ //an array with all the ratings objects
162
+ var ratingArray = [];
163
+ var ratingValue = false;
164
+
165
  for (var i = 0; i < yasrMultiSetAdmin.length; i++) {
166
 
167
  (function (i) {
168
 
169
  var htmlId = yasrMultiSetAdmin.item(i).id;
 
 
170
  var elem = document.getElementById(htmlId);
171
 
172
  raterJs({
181
  rating = rating.toFixed(1);
182
  //Be sure is a number and not a string
183
  rating = parseFloat(rating);
184
+ this.setRating(rating); //Set the rating
 
 
185
 
186
+ var setIdField = parseInt(elem.getAttribute('data-multi-idfield'));
187
 
188
+ ratingObject = {
189
+ field: setIdField,
190
+ rating: rating
 
 
 
 
191
  };
192
 
193
+ //creating rating array
194
+ ratingArray.push(ratingObject);
 
 
195
 
196
+ ratingValue = JSON.stringify(ratingArray);
197
+
198
+ //update hidden field
199
+ document.getElementById('yasr-multiset-author-votes').value = ratingValue;
200
 
201
+ done();
202
  }
203
 
204
  });
js/yasr-front.js CHANGED
@@ -32,9 +32,7 @@ document.addEventListener('DOMContentLoaded', function(event) {
32
  var yasrMultiSetVisitorInDom = document.getElementsByClassName('yasr-multiset-visitors-rater');
33
 
34
  if (yasrMultiSetVisitorInDom.length > 0) {
35
-
36
  yasrRaterVisitorsMultiSet(yasrMultiSetVisitorInDom)
37
-
38
  }
39
 
40
 
32
  var yasrMultiSetVisitorInDom = document.getElementsByClassName('yasr-multiset-visitors-rater');
33
 
34
  if (yasrMultiSetVisitorInDom.length > 0) {
 
35
  yasrRaterVisitorsMultiSet(yasrMultiSetVisitorInDom)
 
36
  }
37
 
38
 
lib/admin/editor/yasr-metabox-multiple-rating.php CHANGED
@@ -24,7 +24,7 @@ $multi_set = yasr_get_multi_set();
24
 
25
  $post_id = get_the_ID();
26
 
27
- $ajax_nonce_multi = wp_create_nonce( "yasr_nonce_insert_multi_rating" );
28
 
29
  $set_id=NULL;
30
 
@@ -39,7 +39,7 @@ if ($n_multi_set > 1) {
39
  ?>
40
 
41
  <br />
42
- <select id ="select_set">
43
  <?php foreach ($multi_set as $name) { ?>
44
  <option value="<?php echo $name->set_id ?>"><?php echo $name->set_name ?></option>
45
  <?php } //End foreach ?>
@@ -72,6 +72,9 @@ elseif ($n_multi_set === 1) {
72
  <?php _e( 'Choose a vote for each element', 'yet-another-stars-rating' ); ?>
73
  </span>
74
 
 
 
 
75
  <table class="yasr_table_multi_set_admin" id="yasr-table-multi-set-admin">
76
 
77
  </table>
@@ -95,9 +98,8 @@ elseif ($n_multi_set === 1) {
95
  var nMultiSet = <?php echo (json_encode("$n_multi_set")); ?>;
96
  var postid = <?php echo (the_ID()); ?>;
97
  var setId = <?php echo( json_encode( "$set_id" ) ); ?>;
98
- var nonceMulti = <?php echo (json_encode("$ajax_nonce_multi")); ?>
99
 
100
- yasrAdminMultiSet(nMultiSet, postid, setId, nonceMulti);
101
 
102
  });
103
 
24
 
25
  $post_id = get_the_ID();
26
 
27
+ $yasr_nonce_multi = wp_nonce_field( "yasr_nonce_save_multi_values_action", "yasr_nonce_save_multi_values");
28
 
29
  $set_id=NULL;
30
 
39
  ?>
40
 
41
  <br />
42
+ <select id="select_set">
43
  <?php foreach ($multi_set as $name) { ?>
44
  <option value="<?php echo $name->set_id ?>"><?php echo $name->set_name ?></option>
45
  <?php } //End foreach ?>
72
  <?php _e( 'Choose a vote for each element', 'yet-another-stars-rating' ); ?>
73
  </span>
74
 
75
+ <input type="hidden" name="yasr_multiset_author_votes" id="yasr-multiset-author-votes" value="">
76
+ <input type="hidden" name="yasr_multiset_id" id="yasr-multiset-id" value="">
77
+
78
  <table class="yasr_table_multi_set_admin" id="yasr-table-multi-set-admin">
79
 
80
  </table>
98
  var nMultiSet = <?php echo (json_encode("$n_multi_set")); ?>;
99
  var postid = <?php echo (the_ID()); ?>;
100
  var setId = <?php echo( json_encode( "$set_id" ) ); ?>;
 
101
 
102
+ yasrAdminMultiSet(nMultiSet, postid, setId);
103
 
104
  });
105
 
lib/admin/settings/yasr-settings-functions-multiset-page.php CHANGED
@@ -52,9 +52,7 @@ global $wpdb;
52
  //delete all transient that use multiset
53
  $sql_delete_transient = "
54
  DELETE FROM {$wpdb->options}
55
- WHERE option_name LIKE '_transient_yasr_get_multi_set_values_and_field_%'
56
- OR option_name LIKE '_transient_yasr_visitor_multi_set_%'
57
- OR option_name LIKE '_transient_timeout_yasr_get_multi_set_values_and_field_%'
58
  OR option_name LIKE '_transient_timeout_yasr_visitor_multi_set_%'
59
  ";
60
 
52
  //delete all transient that use multiset
53
  $sql_delete_transient = "
54
  DELETE FROM {$wpdb->options}
55
+ WHERE option_name LIKE '_transient_yasr_visitor_multi_set_%'
 
 
56
  OR option_name LIKE '_transient_timeout_yasr_visitor_multi_set_%'
57
  ";
58
 
lib/admin/settings/yasr-settings-migration-functions.php CHANGED
@@ -213,7 +213,6 @@ function yasr_import_wppr_callback() {
213
  YASR_LOG_TABLE,
214
  array(
215
  'post_id' => $column->post_id,
216
- 'multi_set_id' => '-1',
217
  'user_id' => 0, //not stored on wp post rating
218
  'vote' => $column->ratings_average,
219
  'date' => '', //not stored on wp post rating
@@ -286,7 +285,6 @@ function yasr_import_kksr_callback() {
286
  YASR_LOG_TABLE,
287
  array(
288
  'post_id' => $column->post_id,
289
- 'multi_set_id' => '-1',
290
  'user_id' => 0, //not stored on KK star rating
291
  'vote' => $column->ratings_average,
292
  'date' => 'kkstarratings', //not stored KK star rating
@@ -351,7 +349,6 @@ function yasr_import_ratemypost_callback() {
351
  YASR_LOG_TABLE,
352
  array(
353
  'post_id' => $column->post_id,
354
- 'multi_set_id' => '-1',
355
  'user_id' => 0, //seems like rate my post store all users like -1, so I cant import the user_id
356
  'vote' => $column->vote,
357
  'date' => $column->date,
213
  YASR_LOG_TABLE,
214
  array(
215
  'post_id' => $column->post_id,
 
216
  'user_id' => 0, //not stored on wp post rating
217
  'vote' => $column->ratings_average,
218
  'date' => '', //not stored on wp post rating
285
  YASR_LOG_TABLE,
286
  array(
287
  'post_id' => $column->post_id,
 
288
  'user_id' => 0, //not stored on KK star rating
289
  'vote' => $column->ratings_average,
290
  'date' => 'kkstarratings', //not stored KK star rating
349
  YASR_LOG_TABLE,
350
  array(
351
  'post_id' => $column->post_id,
 
352
  'user_id' => 0, //seems like rate my post store all users like -1, so I cant import the user_id
353
  'vote' => $column->vote,
354
  'date' => $column->date,
lib/admin/settings/yasr-stats-functions.php CHANGED
@@ -101,7 +101,6 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
101
  'cb' => '<input type="checkbox" />',
102
  'id' => 'ID',
103
  'post_id' => 'Title',
104
- 'multi_set_id' => 'Description',
105
  'user_id' => 'User ID',
106
  'vote' => 'Vote',
107
  'date' => 'Date',
@@ -112,13 +111,11 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
112
  'cb' => '<input type="checkbox" />',
113
  'id' => 'ID',
114
  'post_id' => 'Title',
115
- 'multi_set_id' => 'Description',
116
  'user_id' => 'User ID',
117
  'vote' => 'Vote',
118
  'date' => 'Date'
119
  );
120
  }
121
-
122
  return $columns;
123
  }
124
 
@@ -128,7 +125,7 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
128
  * @return Array
129
  */
130
  public function get_hidden_columns() {
131
- return array( 'id', 'multi_set_id' );
132
  }
133
 
134
  /**
101
  'cb' => '<input type="checkbox" />',
102
  'id' => 'ID',
103
  'post_id' => 'Title',
 
104
  'user_id' => 'User ID',
105
  'vote' => 'Vote',
106
  'date' => 'Date',
111
  'cb' => '<input type="checkbox" />',
112
  'id' => 'ID',
113
  'post_id' => 'Title',
 
114
  'user_id' => 'User ID',
115
  'vote' => 'Vote',
116
  'date' => 'Date'
117
  );
118
  }
 
119
  return $columns;
120
  }
121
 
125
  * @return Array
126
  */
127
  public function get_hidden_columns() {
128
+ return array( 'id' );
129
  }
130
 
131
  /**
lib/admin/yasr-update-functions.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit( 'You\'re not allowed to see this page' );
5
+ } // Exit if accessed directly
6
+
7
+ //Update version number and backward compatibility functions
8
+ //declared on yasr-update-functions.php
9
+ add_action('plugins_loaded', 'yasr_update_version');
10
+
11
+ function yasr_update_version() {
12
+ //do only in admin
13
+
14
+ if (is_admin()) {
15
+ global $wpdb;
16
+ global $yasr_version_installed;
17
+ global $yasr_stored_options;
18
+
19
+ if ($yasr_version_installed && $yasr_version_installed < '2.0.9') {
20
+
21
+ //drop useless multi_set_id on yasr log table
22
+ $wpdb->query("ALTER TABLE " . YASR_LOG_TABLE . " DROP multi_set_id");
23
+
24
+ //change user_id in bigint 20 (just like the users table do)
25
+ //change vote to useless 11,1 to 2,1
26
+ //format DECIMAL(M, D) where M is the maximum number of digits (the precision) and D is the
27
+ //number of digits to the right of the decimal point (the scale).
28
+ $wpdb->query("ALTER TABLE " . YASR_LOG_TABLE .
29
+ " CHANGE user_id user_id bigint(20) NOT NULL AFTER post_id,
30
+ CHANGE vote vote decimal(2,1) NOT NULL AFTER user_id");
31
+
32
+ $sql_yasr_log_multi_set_table = "CREATE TABLE ". YASR_LOG_MULTI_SET ." (
33
+ id bigint(20) NOT NULL AUTO_INCREMENT,
34
+ field_id int(2) NOT NULL,
35
+ set_type int(2) NOT NULL,
36
+ post_id bigint(20) NOT NULL,
37
+ vote decimal(2,1) NOT NULL,
38
+ user_id bigint(20) NOT NULL,
39
+ date datetime NOT NULL,
40
+ ip varchar(45) COLLATE 'utf8_unicode_ci' NOT NULL,
41
+ PRIMARY KEY (id),
42
+ UNIQUE KEY id (id)
43
+ ) COLLATE 'utf8_unicode_ci'";
44
+
45
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
46
+
47
+ dbDelta($sql_yasr_log_multi_set_table);
48
+
49
+ $sql_import_author_multiset = $wpdb->get_results(
50
+ "SELECT post_id, set_type AS set_id,
51
+ CONCAT(
52
+ '[',
53
+ GROUP_CONCAT(
54
+ JSON_OBJECT(
55
+ 'field', field_id,
56
+ 'rating', votes
57
+ )
58
+ ),
59
+ ']'
60
+ ) AS fields_and_ratings
61
+ FROM " . YASR_MULTI_SET_VALUES_TABLE . "
62
+ WHERE post_id IN (
63
+ SELECT post_id
64
+ FROM " . YASR_MULTI_SET_VALUES_TABLE . "
65
+ GROUP BY post_id
66
+ HAVING SUM(votes)>0
67
+ )
68
+ GROUP BY post_id, set_type
69
+ ORDER BY post_id, set_type", ARRAY_A
70
+ );
71
+
72
+ if(!empty($sql_import_author_multiset)) {
73
+ //just the same code used in yasr_save_multiset_editor
74
+ $i = 0;
75
+ foreach ($sql_import_author_multiset as $multiset_ratings) {
76
+
77
+ $post_id = $multiset_ratings['post_id'];
78
+ $set_id = (int)$multiset_ratings['set_id'];
79
+ $field_and_vote_array = json_decode($multiset_ratings['fields_and_ratings']);
80
+
81
+ //convert in a object with json_decode
82
+ $data_to_save[$i] = array(
83
+ 'set_id' => $set_id,
84
+ 'fields_and_ratings' => $field_and_vote_array
85
+ );
86
+
87
+ $set_post_meta_values = get_post_meta($post_id, 'yasr_multiset_author_votes',true);
88
+
89
+ if ($set_post_meta_values) {
90
+ //first, loop saved fields and ratings
91
+ foreach ($set_post_meta_values as $saved_set) {
92
+ //if the saved set is different from the one that we're trying to save,
93
+ //append data to save to the post meta
94
+ if ($saved_set['set_id'] !== $set_id) {
95
+ //increment i
96
+ $i++;
97
+ $data_to_save[$i]['set_id'] = $saved_set['set_id'];
98
+ $data_to_save[$i]['fields_and_ratings'] = $saved_set['fields_and_ratings'];
99
+
100
+ }
101
+ }
102
+ }
103
+ update_post_meta($multiset_ratings['post_id'], 'yasr_multiset_author_votes', $data_to_save);
104
+ //empty array
105
+ $data_to_save = array();
106
+ }
107
+
108
+ }
109
+
110
+ }
111
+
112
+ if ($yasr_version_installed && $yasr_version_installed < '2.0.4') {
113
+ $yasr_stored_options['auto_insert_align'] = 'left';
114
+ update_option('yasr_general_options', $yasr_stored_options);
115
+ }
116
+
117
+ if ($yasr_version_installed && $yasr_version_installed < '1.7.3') {
118
+ $wpdb->query("ALTER TABLE " . YASR_MULTI_SET_FIELDS_TABLE .
119
+ " CHANGE field_name field_name varchar(40)
120
+ COLLATE 'utf8_unicode_ci' NOT NULL
121
+ AFTER parent_set_id;
122
+ ");
123
+ }
124
+
125
+ /****** End backward compatibility functions ******/
126
+
127
+ if ($yasr_version_installed != YASR_VERSION_NUM) {
128
+ update_option('yasr-version', YASR_VERSION_NUM);
129
+ }
130
+
131
+ }
132
+
133
+ }
lib/yasr-ajax-functions.php CHANGED
@@ -51,112 +51,6 @@ add_action( 'wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback'
51
  }
52
 
53
 
54
- /****** Get multiple value and insert into database, used in yasr-metabox-multiple-rating ******/
55
-
56
- add_action( 'wp_ajax_yasr_send_id_field_with_vote', 'yasr_get_multiple_votes_callback' );
57
-
58
- function yasr_get_multiple_votes_callback() {
59
-
60
- if (isset($_POST['post_id']) && isset($_POST['rating']) && isset($_POST['id_field']) && isset($_POST['set_type'])) {
61
- $post_id = $_POST['post_id'];
62
- $vote = $_POST['rating'];
63
- $id_field = $_POST['id_field'];
64
- $set_type = $_POST['set_type'];
65
- $nonce = $_POST['nonce'];
66
-
67
- if ($post_id == '' || $set_type == '' || $id_field == '') {
68
- exit();
69
- }
70
-
71
- }
72
- else {
73
- exit();
74
- }
75
-
76
- if ( ! current_user_can( 'publish_posts' ) ) {
77
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'yet-another-stars-rating' ) );
78
- }
79
-
80
- if ( ! wp_verify_nonce( $nonce, 'yasr_nonce_insert_multi_rating' ) ) {
81
- die( 'Security check' );
82
- }
83
-
84
- delete_transient( 'yasr_get_multi_set_values_and_field_' . $post_id . '_' . $set_type );
85
-
86
- global $wpdb;
87
-
88
- //Check if vote already exist
89
- $vote_already_exist=$wpdb->get_results($wpdb->prepare("SELECT id FROM " . YASR_MULTI_SET_VALUES_TABLE . "
90
- WHERE post_id = %d
91
- AND set_type = %d
92
- AND field_id = %d
93
- ",
94
- $post_id, $set_type, $id_field));
95
-
96
- //If vote already exist, overwrite it
97
- if ($vote_already_exist) {
98
- foreach ($vote_already_exist as $index_id) {
99
- $id = $index_id->id;
100
- }
101
- $query_success=$wpdb->update(
102
- YASR_MULTI_SET_VALUES_TABLE,
103
- array (
104
- 'id'=>$id,
105
- 'post_id'=>$post_id,
106
- 'field_id'=>$id_field,
107
- 'votes'=>$vote,
108
- 'set_type'=>$set_type
109
- ),
110
- array (
111
- 'id'=>$id
112
- ),
113
- array ("%d", "%d", "%d", "%f", "%d"),
114
- array ("%d")
115
- );
116
-
117
- if($query_success) {
118
- echo $vote;
119
- }
120
- } //End if vote already exist
121
-
122
- //If vote doesn't exist create a new one
123
- else {
124
-
125
- //get the highest id in table
126
- $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_VALUES_TABLE . " ORDER BY id DESC LIMIT 1 ");
127
-
128
- if (!$highest_id) {
129
- $new_id=0;
130
- }
131
-
132
- foreach ($highest_id as $id) {
133
- $new_id=$id->id + 1;
134
- }
135
-
136
- $result=$wpdb->replace(
137
- YASR_MULTI_SET_VALUES_TABLE,
138
- array (
139
- 'id' => $new_id,
140
- 'post_id'=>$post_id,
141
- 'field_id'=>$id_field,
142
- 'votes'=>$vote,
143
- 'set_type'=>$set_type
144
- ),
145
- array ("%d", "%d", "%d", "%f", "%d")
146
- );
147
-
148
- if($result) {
149
- echo $vote;
150
- }
151
-
152
- } //End else
153
-
154
- die();
155
-
156
- } //End callback function
157
-
158
-
159
-
160
  /****** Create the content for the button shortcode in Tinymce ******/
161
 
162
  //Add ajax action that will be called from the .js for button in tinymce
@@ -723,7 +617,6 @@ add_action( 'wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback'
723
  YASR_LOG_TABLE,
724
  array (
725
  'post_id' => $post_id,
726
- 'multi_set_id' => -1,
727
  'user_id' => $current_user->ID,
728
  'vote' => $rating,
729
  'date' => date('Y-m-d H:i:s'),
@@ -741,12 +634,10 @@ add_action( 'wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback'
741
  //insert the new row
742
  //use ! instead of === FALSE
743
  if (!$result_update_log) {
744
-
745
  $result_insert_log = $wpdb->insert (
746
  YASR_LOG_TABLE,
747
  array (
748
  'post_id' => $post_id,
749
- 'multi_set_id' => -1,
750
  'user_id' => $current_user->ID,
751
  'vote' => $rating,
752
  'date' => date('Y-m-d H:i:s'),
@@ -754,7 +645,6 @@ add_action( 'wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback'
754
  ),
755
  array ('%d', '%d', '%d', '%s', '%s', '%s')
756
  );
757
-
758
  }
759
 
760
  }
@@ -769,7 +659,6 @@ add_action( 'wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback'
769
  YASR_LOG_TABLE,
770
  array (
771
  'post_id' => $post_id,
772
- 'multi_set_id' => -1,
773
  'user_id' => $current_user->ID,
774
  'vote' => $rating,
775
  'date' => date('Y-m-d H:i:s'),
51
  }
52
 
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  /****** Create the content for the button shortcode in Tinymce ******/
55
 
56
  //Add ajax action that will be called from the .js for button in tinymce
617
  YASR_LOG_TABLE,
618
  array (
619
  'post_id' => $post_id,
 
620
  'user_id' => $current_user->ID,
621
  'vote' => $rating,
622
  'date' => date('Y-m-d H:i:s'),
634
  //insert the new row
635
  //use ! instead of === FALSE
636
  if (!$result_update_log) {
 
637
  $result_insert_log = $wpdb->insert (
638
  YASR_LOG_TABLE,
639
  array (
640
  'post_id' => $post_id,
 
641
  'user_id' => $current_user->ID,
642
  'vote' => $rating,
643
  'date' => date('Y-m-d H:i:s'),
645
  ),
646
  array ('%d', '%d', '%d', '%s', '%s', '%s')
647
  );
 
648
  }
649
 
650
  }
659
  YASR_LOG_TABLE,
660
  array (
661
  'post_id' => $post_id,
 
662
  'user_id' => $current_user->ID,
663
  'vote' => $rating,
664
  'date' => date('Y-m-d H:i:s'),
lib/yasr-db-functions.php CHANGED
@@ -98,16 +98,23 @@ function yasr_create_tables () {
98
  $yasr_multi_set_table = $prefix . 'multi_set';
99
  $yasr_multi_set_fields = $prefix . 'multi_set_fields';
100
  $yasr_multi_values_table = $prefix . 'multi_values';
 
101
  $yasr_log_table = $prefix . 'log';
102
 
103
- $sql_yasr_multi_set_table = "CREATE TABLE IF NOT EXISTS $yasr_multi_set_table (
 
 
 
 
 
 
104
  set_id int(2) NOT NULL,
105
  set_name varchar(64) COLLATE utf8_unicode_ci NOT NULL,
106
  UNIQUE KEY set_id (set_id),
107
  UNIQUE KEY set_name (set_name)
108
  ) COLLATE 'utf8_unicode_ci';";
109
 
110
- $sql_yasr_multi_set_fields = "CREATE TABLE IF NOT EXISTS $yasr_multi_set_fields (
111
  id bigint(20) NOT NULL,
112
  parent_set_id int(2) NOT NULL,
113
  field_name varchar(40) COLLATE utf8_unicode_ci NOT NULL,
@@ -116,7 +123,8 @@ function yasr_create_tables () {
116
  UNIQUE KEY id (id)
117
  ) COLLATE 'utf8_unicode_ci';";
118
 
119
- $sql_yasr_multi_value_table = "CREATE TABLE IF NOT EXISTS $yasr_multi_values_table (
 
120
  id bigint(20) NOT NULL,
121
  field_id int(2) NOT NULL,
122
  set_type int (2) NOT NULL,
@@ -126,25 +134,42 @@ function yasr_create_tables () {
126
  sum_votes decimal(11, 1) NOT NULL,
127
  PRIMARY KEY (id),
128
  UNIQUE KEY id (id)
129
- ) COLLATE 'utf8_unicode_ci';;";
130
 
131
- $sql_yasr_log_table = "CREATE TABLE IF NOT EXISTS $yasr_log_table (
 
132
  id bigint(20) NOT NULL AUTO_INCREMENT,
 
 
133
  post_id bigint(20) NOT NULL,
134
- multi_set_id int(2) NOT NULL,
135
- user_id int(11) NOT NULL,
136
- vote decimal(11,1) NOT NULL,
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  date datetime NOT NULL,
138
  ip varchar(45) COLLATE utf8_unicode_ci NOT NULL,
139
  PRIMARY KEY (id),
140
  UNIQUE KEY id (id)
141
- ) COLLATE 'utf8_unicode_ci';;";
142
 
143
 
144
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
145
 
146
  dbDelta($sql_yasr_multi_set_table);
147
  dbDelta($sql_yasr_multi_set_fields);
 
148
  dbDelta($sql_yasr_multi_value_table);
149
  dbDelta($sql_yasr_log_table);
150
  }
@@ -266,33 +291,75 @@ function yasr_get_multi_set() {
266
 
267
 
268
  /****** Get multi set values and field's name, used in ajax function and shortcode function ******/
269
- function yasr_get_multi_set_values_and_field($post_id, $set_type) {
270
 
271
- $result = get_transient('yasr_get_multi_set_values_and_field_' . $post_id . '_' . $set_type);
272
 
273
- if ($result !== false) {
274
- return $result;
275
- } else {
 
276
 
277
- global $wpdb;
 
 
278
 
279
- $result = $wpdb->get_results($wpdb->prepare("SELECT f.field_name AS name, f.field_id AS id, v.votes AS vote
280
- FROM " . YASR_MULTI_SET_FIELDS_TABLE . " AS f, " . YASR_MULTI_SET_VALUES_TABLE . " AS v
281
- WHERE f.parent_set_id=%d
282
- AND f.field_id = v.field_id
283
- AND v.post_id = %d
284
- AND v.set_type = %d
285
- AND f.parent_set_id=v.set_type
286
- ORDER BY f.field_id ASC", $set_type, $post_id, $set_type));
287
 
288
- if (!empty($result)) {
289
- set_transient('yasr_get_multi_set_values_and_field_' . $post_id . '_' . $set_type, $result, WEEK_IN_SECONDS);
290
- }
291
 
292
- return $result;
 
 
 
 
 
 
 
 
 
 
 
 
293
 
 
 
294
  }
295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
 
297
  }
298
 
@@ -307,100 +374,16 @@ function yasr_return_multi_set_values_admin($post_id, $set_id) {
307
  exit(__('Missing post or set id', 'yet-another-stars-rating'));
308
  }
309
 
310
- //delete transient first
311
- delete_transient('yasr_get_multi_set_values_and_field_' . $post_id . '_' . $set_id);
312
-
313
- $set_values = yasr_get_multi_set_values_and_field($post_id, $set_id);
314
-
315
- global $wpdb;
316
-
317
- $index = 0;
318
-
319
- //If this is a new post or post has no multi values data
320
- if (!$set_values) {
321
-
322
- //Get Set fields name
323
- $set_name = $wpdb->get_results($wpdb->prepare("SELECT field_name AS name, field_id AS id
324
- FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
325
- WHERE parent_set_id=%d
326
- ORDER BY field_id ASC",
327
- $set_id));
328
-
329
- foreach ($set_name as $name) {
330
 
331
- //// first, I've to rate all the values to -1, or if someone is leaved empty /////
332
- //// will disappear later
333
 
334
- //get the highest id in table cause it is not AI
335
- $highest_id = $wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_VALUES_TABLE . " ORDER BY id DESC LIMIT 1 ");
336
-
337
- if (!$highest_id) {
338
- $new_id = 0;
339
- }
340
-
341
- foreach ($highest_id as $id) {
342
- $new_id = $id->id + 1;
343
- }
344
-
345
- $query_success = $wpdb->replace(
346
- YASR_MULTI_SET_VALUES_TABLE,
347
- array(
348
- 'id' => $new_id,
349
- 'post_id' => $post_id,
350
- 'field_id' => $name->id,
351
- 'votes' => '-1',
352
- 'set_type' => $set_id,
353
- 'number_of_votes' => '0',
354
- 'sum_votes' => '0'
355
- ),
356
- array("%d", "%d", "%d", "%s", "%d", "%d", "%d")
357
- );
358
-
359
-
360
- $array_to_return[$index]['value_name'] = $name->name;
361
- $array_to_return[$index]['value_rating'] = 0;
362
- $array_to_return[$index]['value_id'] = $name->id;
363
-
364
- $index ++;
365
-
366
- } //End foreach
367
-
368
- } //
369
-
370
- //else means that post already has vote and here I show it
371
- else {
372
-
373
- foreach ($set_values as $set_content) {
374
-
375
- if ($set_content->vote < 0) {
376
- $set_content->vote = 0;
377
- }
378
-
379
- $integer_vote = floor($set_content->vote);
380
- if ($set_content->vote < ($integer_vote + 0.3)) {
381
- $set_content->vote = $integer_vote;
382
- } elseif ($set_content->vote >= ($integer_vote + 0.3) AND $set_content->vote < ($integer_vote + 0.7)) {
383
- $set_content->vote = $integer_vote + 0.5;
384
- } elseif ($set_content->vote >= ($integer_vote + 0.7)) {
385
- $set_content->vote = $integer_vote + 1;
386
- }
387
-
388
- $array_to_return[$index]['value_name'] = $set_content->name;
389
- $array_to_return[$index]['value_rating'] = $set_content->vote;
390
- $array_to_return[$index]['value_id'] = $set_content->id;
391
-
392
- $index ++;
393
-
394
- } //End foreach
395
-
396
-
397
- }
398
 
399
  echo json_encode($array_to_return);
400
 
401
- die();
402
-
403
-
404
  }
405
 
406
 
@@ -415,7 +398,8 @@ function yasr_get_multi_set_visitor($post_id, $set_type) {
415
 
416
  global $wpdb;
417
 
418
- $result = $wpdb->get_results($wpdb->prepare("SELECT f.field_name AS name, f.field_id AS id, v.number_of_votes AS number_of_votes, v.sum_votes AS sum_votes
 
419
  FROM " . YASR_MULTI_SET_FIELDS_TABLE . " AS f, " . YASR_MULTI_SET_VALUES_TABLE . " AS v
420
  WHERE f.parent_set_id=%d
421
  AND f.field_id = v.field_id
@@ -905,7 +889,6 @@ function yasr_insert_overall_rating_callback($post_id) {
905
 
906
  }
907
 
908
-
909
  add_action('save_post', 'yasr_insert_review_type_callback');
910
 
911
  function yasr_insert_review_type_callback($post_id) {
@@ -975,6 +958,69 @@ function yasr_post_a_review($post_id) {
975
  }
976
 
977
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
978
  /******* Add post_meta on save_post if this post is excluded for auto insert *******/
979
 
980
  if (YASR_AUTO_INSERT_ENABLED == 1) {
98
  $yasr_multi_set_table = $prefix . 'multi_set';
99
  $yasr_multi_set_fields = $prefix . 'multi_set_fields';
100
  $yasr_multi_values_table = $prefix . 'multi_values';
101
+ $yasr_log_multi_set = $prefix . 'log_multi_set';
102
  $yasr_log_table = $prefix . 'log';
103
 
104
+ //Do not use IF TABLE EXISTS here
105
+ //see https://wordpress.stackexchange.com/a/302538/48442
106
+ //since this function is called only on plugin activation AND if yasr-version is not found in
107
+ //wp-option, there is no need to check if table exists, unless the user manually remove yasr-version option
108
+ //but not the yasr tables.
109
+
110
+ $sql_yasr_multi_set_table = "CREATE TABLE $yasr_multi_set_table (
111
  set_id int(2) NOT NULL,
112
  set_name varchar(64) COLLATE utf8_unicode_ci NOT NULL,
113
  UNIQUE KEY set_id (set_id),
114
  UNIQUE KEY set_name (set_name)
115
  ) COLLATE 'utf8_unicode_ci';";
116
 
117
+ $sql_yasr_multi_set_fields = "CREATE TABLE $yasr_multi_set_fields (
118
  id bigint(20) NOT NULL,
119
  parent_set_id int(2) NOT NULL,
120
  field_name varchar(40) COLLATE utf8_unicode_ci NOT NULL,
123
  UNIQUE KEY id (id)
124
  ) COLLATE 'utf8_unicode_ci';";
125
 
126
+ //Since version
127
+ $sql_yasr_multi_value_table = "CREATE TABLE $yasr_multi_values_table (
128
  id bigint(20) NOT NULL,
129
  field_id int(2) NOT NULL,
130
  set_type int (2) NOT NULL,
134
  sum_votes decimal(11, 1) NOT NULL,
135
  PRIMARY KEY (id),
136
  UNIQUE KEY id (id)
137
+ ) COLLATE 'utf8_unicode_ci';";
138
 
139
+ //Since version 2.0.9 is installed but not used yet
140
+ $sql_yasr_log_multi_set_table = "CREATE TABLE $yasr_log_multi_set (
141
  id bigint(20) NOT NULL AUTO_INCREMENT,
142
+ field_id int(2) NOT NULL,
143
+ set_type int(2) NOT NULL,
144
  post_id bigint(20) NOT NULL,
145
+ vote decimal(2,1) NOT NULL,
146
+ user_id bigint(20) NOT NULL,
147
+ date datetime NOT NULL,
148
+ ip varchar(45) COLLATE 'utf8_unicode_ci' NOT NULL,
149
+ PRIMARY KEY (id),
150
+ UNIQUE KEY id (id)
151
+ ) COLLATE 'utf8_unicode_ci';";
152
+
153
+ //Since version 2.0.9 user_id is bigint 20 and vote decimal 2,1
154
+ //format DECIMAL(M, D) where M is the maximum number of digits (the precision) and D is the
155
+ //number of digits to the right of the decimal point (the scale).
156
+ $sql_yasr_log_table = "CREATE TABLE $yasr_log_table (
157
+ id bigint(20) NOT NULL AUTO_INCREMENT,
158
+ post_id bigint(20) NOT NULL,
159
+ user_id bigint(20) NOT NULL,
160
+ vote decimal(2,1) NOT NULL,
161
  date datetime NOT NULL,
162
  ip varchar(45) COLLATE utf8_unicode_ci NOT NULL,
163
  PRIMARY KEY (id),
164
  UNIQUE KEY id (id)
165
+ ) COLLATE 'utf8_unicode_ci';";
166
 
167
 
168
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
169
 
170
  dbDelta($sql_yasr_multi_set_table);
171
  dbDelta($sql_yasr_multi_set_fields);
172
+ dbDelta($sql_yasr_log_multi_set_table);
173
  dbDelta($sql_yasr_multi_value_table);
174
  dbDelta($sql_yasr_log_table);
175
  }
291
 
292
 
293
  /****** Get multi set values and field's name, used in ajax function and shortcode function ******/
294
+ function yasr_get_multi_set_fields($set_id) {
295
 
296
+ global $wpdb;
297
 
298
+ $result = $wpdb->get_results($wpdb->prepare(
299
+ "SELECT f.field_id AS id, f.field_name AS name
300
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . " AS f
301
+ WHERE f.parent_set_id=%d", $set_id), ARRAY_A);
302
 
303
+ if (empty($result)) {
304
+ return false;
305
+ }
306
 
307
+ return $result;
 
 
 
 
 
 
 
308
 
309
+ }
 
 
310
 
311
+ /** This functions returns an array with all the value to print the multiset
312
+ * @since 2.0.9
313
+ *
314
+ * @param integer $post_id
315
+ * @param integer $set_id the set id
316
+ * @param array $set_fields an array with fields names and id
317
+ * @param array $set_post_meta_values an array with fields id and rating, can be empty
318
+ * @param bool $create_transient
319
+ *
320
+ * @return bool|array $array_to_return An array with field name, id and rating
321
+ */
322
+
323
+ function yasr_return_multiset_array_with_ratings ($set_id, $set_fields, $set_post_meta_values) {
324
 
325
+ if (!is_int($set_id) || !$set_fields ) {
326
+ return false;
327
  }
328
 
329
+ //initalize empty array
330
+ $array_to_return = array();
331
+
332
+ //index
333
+ $i = 0;
334
+
335
+ //always returns field id and name
336
+ foreach ($set_fields as $fields_ids_and_names) {
337
+ $array_to_return[$i]['value_id'] = (int)$fields_ids_and_names['id'];
338
+ $array_to_return[$i]['value_name'] = $fields_ids_and_names['name'];
339
+ $array_to_return[$i]['value_rating'] = 0;
340
+
341
+ //if there is post meta
342
+ if ($set_post_meta_values) {
343
+ //first, loop saved fields and ratings
344
+ foreach ($set_post_meta_values as $saved_set_id) {
345
+ //if the saved set is the same selected
346
+ if ($saved_set_id['set_id'] === $set_id) {
347
+ //loop the saved arrays
348
+ foreach ($saved_set_id['fields_and_ratings'] as $single_value) {
349
+ //if field id is the same, add the rating
350
+ if ($array_to_return[$i]['value_id'] === $single_value->field) {
351
+ //save the rating
352
+ $array_to_return[$i]['value_rating'] = $single_value->rating;
353
+ }
354
+ }
355
+ }
356
+ }
357
+ }
358
+ //this is for list the set names
359
+ $i++;
360
+ }
361
+
362
+ return $array_to_return;
363
 
364
  }
365
 
374
  exit(__('Missing post or set id', 'yet-another-stars-rating'));
375
  }
376
 
377
+ //set fields name and ids
378
+ $set_fields = yasr_get_multi_set_fields($set_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
 
380
+ //set meta values
381
+ $set_post_meta_values = get_post_meta($post_id, 'yasr_multiset_author_votes', true);
382
 
383
+ $array_to_return = yasr_return_multiset_array_with_ratings($set_id, $set_fields, $set_post_meta_values);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
 
385
  echo json_encode($array_to_return);
386
 
 
 
 
387
  }
388
 
389
 
398
 
399
  global $wpdb;
400
 
401
+ $result = $wpdb->get_results($wpdb->prepare("SELECT f.field_name AS name, f.field_id AS id,
402
+ v.number_of_votes AS number_of_votes, v.sum_votes AS sum_votes
403
  FROM " . YASR_MULTI_SET_FIELDS_TABLE . " AS f, " . YASR_MULTI_SET_VALUES_TABLE . " AS v
404
  WHERE f.parent_set_id=%d
405
  AND f.field_id = v.field_id
889
 
890
  }
891
 
 
892
  add_action('save_post', 'yasr_insert_review_type_callback');
893
 
894
  function yasr_insert_review_type_callback($post_id) {
958
  }
959
 
960
 
961
+ /****** Get multiple value and insert into database, used in yasr-metabox-multiple-rating ******/
962
+
963
+ add_action('save_post', 'yasr_save_multiset_editor');
964
+
965
+ function yasr_save_multiset_editor($post_id) {
966
+
967
+ if (isset($_POST['yasr_multiset_author_votes']) && isset($_POST['yasr_multiset_id'])) {
968
+ $field_and_vote_array = json_decode(sanitize_text_field(stripslashes($_POST['yasr_multiset_author_votes'])));
969
+ $set_id = (int) $_POST['yasr_multiset_id'];
970
+ $nonce = $_POST['yasr_nonce_save_multi_values'];
971
+
972
+ if ($set_id == '' || $field_and_vote_array == '') {
973
+ return;
974
+ }
975
+
976
+ } else {
977
+ return;
978
+ }
979
+
980
+ if (!current_user_can('publish_posts')) {
981
+ wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
982
+ }
983
+
984
+ if (!wp_verify_nonce($nonce, 'yasr_nonce_save_multi_values_action')) {
985
+ die('Security check');
986
+ }
987
+
988
+ $i = 0;
989
+
990
+ $data_to_save[$i] = array(
991
+ 'set_id' => (int)$set_id,
992
+ 'fields_and_ratings' => $field_and_vote_array
993
+ );
994
+
995
+ $i++;
996
+
997
+ $set_post_meta_values = get_post_meta($post_id, 'yasr_multiset_author_votes',true);
998
+
999
+ //If data for this post already exists
1000
+ if ($set_post_meta_values) {
1001
+ //first, loop saved fields and ratings
1002
+ foreach ($set_post_meta_values as $saved_set_id) {
1003
+ //if the saved set is different from the one that we're trying to save,
1004
+ //append data to save to the post meta
1005
+ if ($saved_set_id['set_id'] !== $set_id) {
1006
+
1007
+ $data_to_save[$i]['set_id'] = $saved_set_id['set_id'];
1008
+ $data_to_save[$i]['fields_and_ratings'] = $saved_set_id['fields_and_ratings'];
1009
+
1010
+ $i++;
1011
+ //Append data to save to the post meta
1012
+
1013
+ } //if the set is not stored
1014
+ }
1015
+ }
1016
+
1017
+ // Write new data
1018
+ update_post_meta($post_id, 'yasr_multiset_author_votes', $data_to_save);
1019
+
1020
+
1021
+
1022
+ } //End callback function
1023
+
1024
  /******* Add post_meta on save_post if this post is excluded for auto insert *******/
1025
 
1026
  if (YASR_AUTO_INSERT_ENABLED == 1) {
lib/yasr-functions.php CHANGED
@@ -100,9 +100,15 @@ function yasr_add_admin_scripts($hook) {
100
 
101
  do_action('yasr_add_admin_scripts_begin');
102
 
 
 
 
 
 
 
103
  wp_enqueue_style('yasrcss', YASR_CSS_DIR . 'yasr-admin.css', false, YASR_VERSION_NUM, 'all');
104
  wp_enqueue_script('yasradmin', YASR_JS_DIR . 'yasr-admin.js', array('jquery'), YASR_VERSION_NUM, true);
105
- wp_enqueue_script('rater', YASR_JS_DIR . 'rater-js.js', '', YASR_VERSION_NUM, true);
106
 
107
  do_action('yasr_add_admin_scripts_end', $hook);
108
 
100
 
101
  do_action('yasr_add_admin_scripts_begin');
102
 
103
+ $rater_file_to_include = 'rater-js.js';
104
+
105
+ if (is_rtl()) {
106
+ $rater_file_to_include = 'rater-js-rtl.js';
107
+ }
108
+
109
  wp_enqueue_style('yasrcss', YASR_CSS_DIR . 'yasr-admin.css', false, YASR_VERSION_NUM, 'all');
110
  wp_enqueue_script('yasradmin', YASR_JS_DIR . 'yasr-admin.js', array('jquery'), YASR_VERSION_NUM, true);
111
+ wp_enqueue_script('rater', YASR_JS_DIR . $rater_file_to_include, '', YASR_VERSION_NUM, true);
112
 
113
  do_action('yasr_add_admin_scripts_end', $hook);
114
 
lib/yasr-shortcode-functions.php CHANGED
@@ -381,8 +381,6 @@ add_shortcode ('yasr_multiset', 'shortcode_multi_set_callback');
381
 
382
  function shortcode_multi_set_callback($atts) {
383
 
384
- global $wpdb;
385
-
386
  // Attributes
387
  $atts = shortcode_atts(
388
  array(
@@ -394,8 +392,8 @@ function shortcode_multi_set_callback($atts) {
394
  'yasr_multiset'
395
  );
396
 
397
- $post_id = $atts['postid'];
398
- $setid = $atts['setid'];
399
  $show_average = $atts['show_average'];
400
 
401
  //If it's not specified use get_the_id
@@ -405,73 +403,72 @@ function shortcode_multi_set_callback($atts) {
405
 
406
  $shortcode_html = '<!-- Yasr Multi Set Shortcode-->';
407
 
408
- $multiset_vote_sum = 0;
409
- $multiset_rows_number = 0; //
410
-
411
- $set_name_content = yasr_get_multi_set_values_and_field($post_id, $setid);
412
-
413
- if (!$set_name_content) {
414
-
415
- $set_name_content=$wpdb->get_results($wpdb->prepare("SELECT field_name AS name, field_id AS id
416
- FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
417
- WHERE parent_set_id=%d
418
- ORDER BY field_id ASC", $setid));
419
-
420
- //if it still to be empty (e.g. wrong id passed)
421
- if (!$set_name_content) {
422
- return $shortcode_html;
423
- }
424
 
 
 
 
 
425
  }
426
 
427
- $shortcode_html.="<table class=\"yasr_table_multi_set_shortcode\">";
 
 
428
 
429
- //this is to avoid undefined, may happens when an user inser
430
- //the shortcode without insert vote (only happens if more than 1 multiset are used)
431
 
432
- $set_content = new stdClass();
433
- $set_content->vote = null; //avoid undefined
434
 
435
- foreach ($set_name_content as $set_content) {
436
  //Avoid undefined if vote does not exists
437
- if (!isset($set_content->vote)) {
438
- $set_content->vote = 0;
439
- }
440
-
441
- $shortcode_html .= "<tr><td><span class=\"yasr-multi-set-name-field\">$set_content->name </span></td>";
442
-
443
- $unique_id_identifier = $post_id . '_' . $setid . '_' . $set_content->id;
444
 
445
- $shortcode_html .= "<td><div class=\"yasr-rater-stars\" id=\"yasr-rater-multiset-$unique_id_identifier\" data-rater-postid=\"$post_id\" data-rating=\"$set_content->vote\" data-rater-starsize=\"16\"></div></td>
446
- </tr>";
 
 
 
 
 
 
 
 
 
 
 
 
 
447
 
448
- $multiset_vote_sum = $multiset_vote_sum + $set_content->vote;
449
  $multiset_rows_number++;
450
 
451
  }
452
 
453
- if ($show_average !== false && $show_average !=='no' || $show_average === false && YASR_MULTI_SHOW_AVERAGE !== 'no') {
454
  $multiset_average = $multiset_vote_sum / $multiset_rows_number;
455
  $multiset_average = round($multiset_average, 1);
456
 
457
  $average_txt = __("Average", "yet-another-stars-rating");
458
 
459
- $average_unique_id_identifier = 'yasr-multiset-average_' . $post_id . '_' . $setid;
460
 
461
- $shortcode_html .= "<tr>
462
- <td colspan='2' class='yasr-multiset-average'>
463
- <span class='yasr-multiset-average-text'>$average_txt</span>
464
- <div class='yasr-rater-stars' id=\"$average_unique_id_identifier\"
465
- data-rater-postid=\"$post_id\" data-rating=\"$multiset_average\"
466
- data-rater-starsize=\"24\"></div>
 
 
467
  </td>
468
- </tr>";
469
-
470
 
471
  }
472
 
473
  $shortcode_html.="</table>";
474
-
475
  $shortcode_html .= '<!--End Yasr Multi Set Shortcode-->';
476
 
477
  return $shortcode_html;
@@ -739,9 +736,7 @@ function yasr_top_ten_highest_rated_callback() {
739
  } //End foreach
740
 
741
  $shortcode_html .= "</table>";
742
-
743
  $shortcode_html .= '<!--End Yasr Top 10 highest Rated Shortcode-->';
744
-
745
  return $shortcode_html;
746
 
747
  } //end if $query_result
381
 
382
  function shortcode_multi_set_callback($atts) {
383
 
 
 
384
  // Attributes
385
  $atts = shortcode_atts(
386
  array(
392
  'yasr_multiset'
393
  );
394
 
395
+ $post_id = (int)$atts['postid'];
396
+ $set_id = (int)$atts['setid'];
397
  $show_average = $atts['show_average'];
398
 
399
  //If it's not specified use get_the_id
403
 
404
  $shortcode_html = '<!-- Yasr Multi Set Shortcode-->';
405
 
406
+ //set fields name and ids
407
+ $set_fields = yasr_get_multi_set_fields($set_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
 
409
+ //If there is no set for that id, return
410
+ if (!$set_fields) {
411
+ $string = __('No Set Found with this ID', 'yet-another-stars-rating');
412
+ return $shortcode_html . $string;
413
  }
414
 
415
+ //set meta values
416
+ $set_post_meta_values = get_post_meta($post_id, 'yasr_multiset_author_votes', true);
417
+ $multiset_content = yasr_return_multiset_array_with_ratings($set_id, $set_fields, $set_post_meta_values);
418
 
419
+ $multiset_vote_sum = 0;//avoid undefined variable
420
+ $multiset_rows_number = 0;//avoid undefined variable
421
 
422
+ $shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
423
+ $shortcode_html.='<table class="yasr_table_multi_set_shortcode">';
424
 
425
+ foreach ($multiset_content as $set_content) {
426
  //Avoid undefined if vote does not exists
427
+ $unique_id_identifier = str_shuffle(uniqid());
 
 
 
 
 
 
428
 
429
+ $shortcode_html .= '<tr>
430
+ <td>
431
+ <span class="yasr-multi-set-name-field">'
432
+ . $set_content['value_name'] .
433
+ '</span>
434
+ </td>
435
+ <td>
436
+ <div class="yasr-rater-stars"
437
+ id="'.$unique_id_identifier.'"
438
+ data-rater-postid="'.$post_id.'"
439
+ data-rating="'.$set_content['value_rating'].'"
440
+ data-rater-starsize="16">
441
+ </div>
442
+ </td>
443
+ </tr>';
444
 
445
+ $multiset_vote_sum = $multiset_vote_sum + $set_content['value_rating'];
446
  $multiset_rows_number++;
447
 
448
  }
449
 
450
+ if ($show_average !== false && $show_average !== 'no' || $show_average === false && YASR_MULTI_SHOW_AVERAGE !== 'no') {
451
  $multiset_average = $multiset_vote_sum / $multiset_rows_number;
452
  $multiset_average = round($multiset_average, 1);
453
 
454
  $average_txt = __("Average", "yet-another-stars-rating");
455
 
456
+ $average_unique_id_identifier = str_shuffle(uniqid());
457
 
458
+ $shortcode_html .= '<tr>
459
+ <td colspan="2" class="yasr-multiset-average">
460
+ <span class="yasr-multiset-average-text">'.$average_txt.'</span>
461
+ <div class="yasr-rater-stars"
462
+ id="'.$average_unique_id_identifier.'"
463
+ data-rater-postid="'.$post_id.'"
464
+ data-rating="'.$multiset_average.'"
465
+ data-rater-starsize="24"></div>
466
  </td>
467
+ </tr>';
 
468
 
469
  }
470
 
471
  $shortcode_html.="</table>";
 
472
  $shortcode_html .= '<!--End Yasr Multi Set Shortcode-->';
473
 
474
  return $shortcode_html;
736
  } //End foreach
737
 
738
  $shortcode_html .= "</table>";
 
739
  $shortcode_html .= '<!--End Yasr Top 10 highest Rated Shortcode-->';
 
740
  return $shortcode_html;
741
 
742
  } //end if $query_result
readme.txt CHANGED
@@ -3,9 +3,9 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
3
  Tags: ratings, rating, postrating, google rating, 5 star, review, reviews, star rating, vote, votes, blocks
4
  Requires at least: 4.3.0
5
  Contributors: Dudo
6
- Tested up to: 5.3
7
  Requires PHP: 5.3
8
- Stable tag: 2.0.8
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Boost the way people interact with your website, e-commerce or blog with an easy and intuitive WordPress rating system!
@@ -125,8 +125,13 @@ If doesn't, it's suggested to ask in a SEO oriented forum.
125
 
126
  The full changelog can be found in the plugin's directory. Recent entries:
127
 
 
 
 
 
 
128
  = 2.0.8 =
129
- * NEW FEATURE: Added a bos to the top right, that will allow to select if the post is a review or not.
130
  More info here [here](https://yetanotherstarsrating.com/yasr-rich-snippets/)
131
  * FIXED: warning that in some rare circumstances may appear in yasr_schema function
132
 
3
  Tags: ratings, rating, postrating, google rating, 5 star, review, reviews, star rating, vote, votes, blocks
4
  Requires at least: 4.3.0
5
  Contributors: Dudo
6
+ Tested up to: 5.3.2
7
  Requires PHP: 5.3
8
+ Stable tag: 2.0.9
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Boost the way people interact with your website, e-commerce or blog with an easy and intuitive WordPress rating system!
125
 
126
  The full changelog can be found in the plugin's directory. Recent entries:
127
 
128
+ = 2.0.9 =
129
+ * TWEAKED: This is the first of two important releases for YASR. Some changes in the database has been done.
130
+ **BACKUP YOUR DATABASE BEFORE UPDATING**
131
+ * FIXED: RTL support in admin area
132
+
133
  = 2.0.8 =
134
+ * NEW FEATURE: Added a box to the top right, that will allow to select if the post is a review or not.
135
  More info here [here](https://yetanotherstarsrating.com/yasr-rich-snippets/)
136
  * FIXED: warning that in some rare circumstances may appear in yasr_schema function
137
 
yet-another-stars-rating.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Yet Another Stars Rating
5
  * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
6
  * Description: Yasr - Yet Another Stars Rating is a powerful way to add SEO-friendly user-generated reviews and testimonials to your website posts, pages and CPT, without affecting its speed.
7
- * Version: 2.0.8
8
  * Author: Dario Curvino
9
  * Author URI: https://dariocurvino.it/
10
  * Text Domain: yet-another-stars-rating
@@ -76,7 +76,7 @@ if ( !function_exists( 'yasr_fs' ) ) {
76
  yasr_fs();
77
  // Signal that SDK was initiated.
78
  do_action( 'yasr_fs_loaded' );
79
- define( 'YASR_VERSION_NUM', '2.0.8' );
80
  //Plugin relative path
81
  define( "YASR_ABSOLUTE_PATH", dirname( __FILE__ ) );
82
  //Plugin RELATIVE PATH without slashes (just the directory's name)
@@ -196,14 +196,14 @@ if ( !function_exists( 'yasr_fs' ) ) {
196
  require YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions.php';
197
  require YASR_ABSOLUTE_PATH . '/lib/admin/class-wp-list-table.php';
198
  require YASR_ABSOLUTE_PATH . '/lib/admin/editor/yasr-editor-functions.php';
 
199
  }
200
 
201
  global $wpdb ;
202
- define( "YASR_VOTES_TABLE", $wpdb->prefix . 'yasr_votes' );
203
- //Used in background
204
  define( "YASR_MULTI_SET_NAME_TABLE", $wpdb->prefix . 'yasr_multi_set' );
205
  define( "YASR_MULTI_SET_FIELDS_TABLE", $wpdb->prefix . 'yasr_multi_set_fields' );
206
  define( "YASR_MULTI_SET_VALUES_TABLE", $wpdb->prefix . 'yasr_multi_values' );
 
207
  define( "YASR_LOG_TABLE", $wpdb->prefix . 'yasr_log' );
208
  define( "YASR_LOADER_IMAGE", YASR_IMG_DIR . "/loader.gif" );
209
  //Text for button in settings pages
@@ -245,33 +245,6 @@ if ( !function_exists( 'yasr_fs' ) ) {
245
  );
246
  //when blog is deleted
247
  add_filter( 'wpmu_drop_tables', 'yasr_on_delete_blog' );
248
- /****** backward compatibility functions ******/
249
- add_action( 'plugins_loaded', 'yasr_update_version' );
250
- function yasr_update_version()
251
- {
252
- //do only in admin
253
-
254
- if ( is_admin() ) {
255
- global $wpdb ;
256
- global $yasr_version_installed ;
257
- global $yasr_stored_options ;
258
-
259
- if ( $yasr_version_installed && $yasr_version_installed < '2.0.4' ) {
260
- $yasr_stored_options['auto_insert_align'] = 'left';
261
- update_option( 'yasr_general_options', $yasr_stored_options );
262
- }
263
-
264
- if ( $yasr_version_installed && $yasr_version_installed < '1.7.3' ) {
265
- $wpdb->query( "ALTER TABLE " . YASR_MULTI_SET_FIELDS_TABLE . " CHANGE field_name field_name varchar(40) \n COLLATE 'utf8_unicode_ci' NOT NULL \n AFTER parent_set_id;\n " );
266
- }
267
- /****** End backward compatibility functions ******/
268
- if ( $yasr_version_installed != YASR_VERSION_NUM ) {
269
- update_option( 'yasr-version', YASR_VERSION_NUM );
270
- }
271
- }
272
-
273
- }
274
-
275
  //this add a link under the plugin name, must be in the main plugin file
276
  add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'yasr_add_links_below_plugin_name' );
277
  function yasr_add_links_below_plugin_name( $links )
4
  * Plugin Name: Yet Another Stars Rating
5
  * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
6
  * Description: Yasr - Yet Another Stars Rating is a powerful way to add SEO-friendly user-generated reviews and testimonials to your website posts, pages and CPT, without affecting its speed.
7
+ * Version: 2.0.9
8
  * Author: Dario Curvino
9
  * Author URI: https://dariocurvino.it/
10
  * Text Domain: yet-another-stars-rating
76
  yasr_fs();
77
  // Signal that SDK was initiated.
78
  do_action( 'yasr_fs_loaded' );
79
+ define( 'YASR_VERSION_NUM', '2.0.9' );
80
  //Plugin relative path
81
  define( "YASR_ABSOLUTE_PATH", dirname( __FILE__ ) );
82
  //Plugin RELATIVE PATH without slashes (just the directory's name)
196
  require YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions.php';
197
  require YASR_ABSOLUTE_PATH . '/lib/admin/class-wp-list-table.php';
198
  require YASR_ABSOLUTE_PATH . '/lib/admin/editor/yasr-editor-functions.php';
199
+ require YASR_ABSOLUTE_PATH . '/lib/admin/yasr-update-functions.php';
200
  }
201
 
202
  global $wpdb ;
 
 
203
  define( "YASR_MULTI_SET_NAME_TABLE", $wpdb->prefix . 'yasr_multi_set' );
204
  define( "YASR_MULTI_SET_FIELDS_TABLE", $wpdb->prefix . 'yasr_multi_set_fields' );
205
  define( "YASR_MULTI_SET_VALUES_TABLE", $wpdb->prefix . 'yasr_multi_values' );
206
+ define( "YASR_LOG_MULTI_SET", $wpdb->prefix . 'yasr_log_multi_set' );
207
  define( "YASR_LOG_TABLE", $wpdb->prefix . 'yasr_log' );
208
  define( "YASR_LOADER_IMAGE", YASR_IMG_DIR . "/loader.gif" );
209
  //Text for button in settings pages
245
  );
246
  //when blog is deleted
247
  add_filter( 'wpmu_drop_tables', 'yasr_on_delete_blog' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  //this add a link under the plugin name, must be in the main plugin file
249
  add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'yasr_add_links_below_plugin_name' );
250
  function yasr_add_links_below_plugin_name( $links )