Yasr – Yet Another Stars Rating - Version 2.1.3

Version Description

  • FIXED: in some older (and rare) mysql or mariadb versions, the function JSON_OBJECT is not supported. This was causing the import of multiset data failing since version 2.0.9
  • FIXED: in backed, multiset rating didn't get saved if set_id
Download this release

Release Info

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

Code changes from version 2.1.2 to 2.1.3

lib/admin/yasr-update-functions.php CHANGED
@@ -12,77 +12,36 @@ 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
- $old_yasr_table = $wpdb->prefix . 'yasr_multi_values';
20
 
21
- if (version_compare($yasr_version_installed,'1.7.3') === -1) {
22
- $wpdb->query("ALTER TABLE " . YASR_MULTI_SET_FIELDS_TABLE .
23
- " CHANGE field_name field_name varchar(40)
24
- COLLATE 'utf8_unicode_ci' NOT NULL
25
- AFTER parent_set_id;
26
- ");
27
- }
28
 
29
- if (version_compare($yasr_version_installed,'2.0.4') === -1) {
30
- $yasr_stored_options['auto_insert_align'] = 'left';
31
- update_option('yasr_general_options', $yasr_stored_options);
32
- }
33
-
34
- //remove end 2020
35
- if (version_compare($yasr_version_installed,'2.0.9') === -1) {
36
-
37
- //drop useless multi_set_id on yasr log table
38
- $wpdb->query("ALTER TABLE " . YASR_LOG_TABLE . " DROP multi_set_id");
39
-
40
- //change user_id in bigint 20 (just like the users table do)
41
- //change vote to useless 11,1 to 2,1
42
- //format DECIMAL(M, D) where M is the maximum number of digits (the precision) and D is the
43
- //number of digits to the right of the decimal point (the scale).
44
- $wpdb->query("ALTER TABLE " . YASR_LOG_TABLE .
45
- " CHANGE user_id user_id bigint(20) NOT NULL AFTER post_id,
46
- CHANGE vote vote decimal(2,1) NOT NULL AFTER user_id");
47
-
48
- $sql_yasr_log_multi_set_table = "CREATE TABLE ". YASR_LOG_MULTI_SET ." (
49
- id bigint(20) NOT NULL AUTO_INCREMENT,
50
- field_id int(2) NOT NULL,
51
- set_type int(2) NOT NULL,
52
- post_id bigint(20) NOT NULL,
53
- vote decimal(2,1) NOT NULL,
54
- user_id bigint(20) NOT NULL,
55
- date datetime NOT NULL,
56
- ip varchar(45) COLLATE 'utf8_unicode_ci' NOT NULL,
57
- PRIMARY KEY (id),
58
- UNIQUE KEY id (id)
59
- ) COLLATE 'utf8_unicode_ci'";
60
-
61
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
62
-
63
- dbDelta($sql_yasr_log_multi_set_table);
64
 
65
  $sql_import_author_multiset = $wpdb->get_results(
66
  "SELECT post_id, set_type AS set_id,
67
- CONCAT(
68
- '[',
69
- GROUP_CONCAT(
70
- JSON_OBJECT(
71
- 'field', field_id,
72
- 'rating', votes
73
- )
74
- ),
75
- ']'
76
- ) AS fields_and_ratings
77
- FROM $old_yasr_table
78
- WHERE post_id IN (
79
- SELECT post_id
80
  FROM $old_yasr_table
81
- GROUP BY post_id
82
- HAVING SUM(votes)>0
83
- )
84
- GROUP BY post_id, set_type
85
- ORDER BY post_id, set_type", ARRAY_A
 
 
 
86
  );
87
 
88
  if(!empty($sql_import_author_multiset)) {
@@ -122,73 +81,125 @@ function yasr_update_version() {
122
  }
123
 
124
  }
125
-
126
  }
127
 
128
- //remove end 2020
129
- if (version_compare($yasr_version_installed,'2.1.0') === -1) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
- //delete all transient that use multiset
132
- $sql_delete_transient = "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  DELETE FROM {$wpdb->options}
134
  WHERE option_name LIKE '_transient_yasr_visitor_multi_set_%'
135
  OR option_name LIKE '_transient_timeout_yasr_visitor_multi_set_%'
136
  ";
137
 
138
- $wpdb->query($sql_delete_transient);
139
-
140
- $sql_import_multiset = $wpdb->get_results(
141
- "SELECT
142
- post_id,
143
- set_type,
144
- field_id,
145
- number_of_votes,
146
- sum_votes/number_of_votes as average
147
- FROM $old_yasr_table
148
- WHERE number_of_votes > 0
149
- AND sum_votes > 0
150
- ORDER BY post_id, set_type", ARRAY_A
151
- );
 
152
 
153
- if(!empty($sql_import_multiset)) {
154
- foreach ($sql_import_multiset as $multiset_ratings) {
155
- for ($i=0; $i<$multiset_ratings['number_of_votes']; $i++) {
156
- $rating_to_save = array (
157
- 'field_id' => $multiset_ratings['field_id'],
158
- 'set_type' => $multiset_ratings['set_type'],
159
- 'post_id' => $multiset_ratings['post_id'],
160
- 'vote' => $multiset_ratings['average']
161
- );
162
- $data_format = array ('%d', '%d', '%d', '%f');
163
- $wpdb->insert(YASR_LOG_MULTI_SET, $rating_to_save, $data_format);
 
164
  }
165
  }
166
  }
167
- }
168
 
169
- //remove begin 2021
170
- //this fix a bug of table not created on version 2.0.9 and 2.1.0
171
- if (version_compare($yasr_version_installed,'2.1.1') === -1) {
172
- $multi_set_name_exists = $wpdb->get_var("SELECT COUNT(1) FROM ". YASR_MULTI_SET_NAME_TABLE);
173
 
174
- $multi_set_field_exists = $wpdb->get_var("SELECT COUNT(1) FROM ". YASR_MULTI_SET_FIELDS_TABLE);
175
 
176
- if($multi_set_name_exists === NULL || $multi_set_field_exists === NULL) {
177
- yasr_create_tables();
 
178
  }
179
- }
180
 
181
- /*
182
- * On version 2.1.0 set_id in YASR_MULTI_SET_NAME_TABLE is set as autoincrement by default
183
- * In the existing installations, set_id could be = 0
184
- * Altering set_id to auto_increment will cause a change from 0 to 1
185
- * Here is the fix
186
- */
187
-
188
- if ($yasr_version_installed === '2.1.0' || $yasr_version_installed === '2.1.1') {
189
- //First I've to check if the column set_id is auto increment
190
- $column_auto_increment = null;
191
- $sql_check_auto_increment = "
192
  SELECT EXTRA
193
  FROM INFORMATION_SCHEMA.COLUMNS
194
  WHERE TABLE_NAME='" . YASR_MULTI_SET_NAME_TABLE . "'
@@ -196,51 +207,73 @@ function yasr_update_version() {
196
  AND EXTRA like '%auto_increment%'
197
  ";
198
 
199
- $column_auto_increment = $wpdb->get_var($sql_check_auto_increment);
200
 
201
- //if the column is not auto increment, return
202
- if($column_auto_increment !== 'auto_increment') {
203
- return;
204
- } else {
205
 
206
- $set_with_id_zero_exists = $wpdb->get_results("
207
  SELECT parent_set_id FROM "
208
- . YASR_MULTI_SET_FIELDS_TABLE .
209
- " WHERE parent_set_id = 0
210
  LIMIT 1", ARRAY_A
211
- );
212
 
213
- //if there is no field with parent_set_id = 0, return
214
- if (empty($set_with_id_zero_exists)) {
215
- return;
216
- } else {
217
- $sql_no_auto_increment = $wpdb->query("ALTER TABLE " . YASR_MULTI_SET_NAME_TABLE .
218
- " CHANGE set_id set_id int(2)
219
  NOT NULL FIRST");
220
 
221
- //if autoincrement has been removed,
222
- //change set value from 1 to 0
223
- //At this point, we're 100% sure that 1 was 0 before
224
- if($sql_no_auto_increment === true) {
225
- $wpdb->update(
226
- YASR_MULTI_SET_NAME_TABLE,
227
- //new data
228
- array (
229
- 'set_id' => 0
230
- ),
231
- //where
232
- array (
233
- 'set_id' => 1
234
- ),
235
- '%d',
236
- '%d'
237
  );
 
238
  }
 
239
  }
240
 
241
  }
242
 
243
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
 
245
  /****** End backward compatibility functions ******/
246
  if ($yasr_version_installed != YASR_VERSION_NUM) {
12
  //do only in admin
13
 
14
  if (is_admin()) {
 
15
  global $yasr_version_installed;
16
+ global $wpdb;
17
  global $yasr_stored_options;
18
 
19
+ function import_multiset_author () {
20
 
21
+ global $wpdb;
 
 
 
 
 
 
22
 
23
+ $old_yasr_table = $wpdb->prefix . 'yasr_multi_values';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  $sql_import_author_multiset = $wpdb->get_results(
26
  "SELECT post_id, set_type AS set_id,
27
+ CONCAT(
28
+ '[',
29
+ GROUP_CONCAT(
30
+ CONCAT(
31
+ '{\"field\":', field_id,', \"rating\":',votes,'}'
32
+ )
33
+ ),
34
+ ']'
35
+ ) AS fields_and_ratings
 
 
 
 
36
  FROM $old_yasr_table
37
+ WHERE post_id IN (
38
+ SELECT post_id
39
+ FROM $old_yasr_table
40
+ GROUP BY post_id
41
+ HAVING SUM(votes)>0
42
+ )
43
+ GROUP BY post_id, set_type
44
+ ORDER BY post_id, set_type", ARRAY_A
45
  );
46
 
47
  if(!empty($sql_import_author_multiset)) {
81
  }
82
 
83
  }
 
84
  }
85
 
86
+ if ($yasr_version_installed !== false) {
87
+
88
+ if (version_compare($yasr_version_installed, '1.7.3') === -1) {
89
+ $wpdb->query("ALTER TABLE " . YASR_MULTI_SET_FIELDS_TABLE .
90
+ " CHANGE field_name field_name varchar(40)
91
+ COLLATE 'utf8_unicode_ci' NOT NULL
92
+ AFTER parent_set_id;
93
+ ");
94
+ }
95
+
96
+ if (version_compare($yasr_version_installed, '2.0.4') === -1) {
97
+ $yasr_stored_options['auto_insert_align'] = 'left';
98
+ update_option('yasr_general_options', $yasr_stored_options);
99
+ }
100
+
101
+ //remove end 2020
102
+ if (version_compare($yasr_version_installed, '2.0.9') === -1) {
103
 
104
+ //drop useless multi_set_id on yasr log table
105
+ $wpdb->query("ALTER TABLE " . YASR_LOG_TABLE . " DROP multi_set_id");
106
+
107
+ //change user_id in bigint 20 (just like the users table do)
108
+ //change vote to useless 11,1 to 2,1
109
+ //format DECIMAL(M, D) where M is the maximum number of digits (the precision) and D is the
110
+ //number of digits to the right of the decimal point (the scale).
111
+ $wpdb->query("ALTER TABLE " . YASR_LOG_TABLE .
112
+ " CHANGE user_id user_id bigint(20) NOT NULL AFTER post_id,
113
+ CHANGE vote vote decimal(2,1) NOT NULL AFTER user_id");
114
+
115
+ $sql_yasr_log_multi_set_table = "CREATE TABLE " . YASR_LOG_MULTI_SET . " (
116
+ id bigint(20) NOT NULL AUTO_INCREMENT,
117
+ field_id int(2) NOT NULL,
118
+ set_type int(2) NOT NULL,
119
+ post_id bigint(20) NOT NULL,
120
+ vote decimal(2,1) NOT NULL,
121
+ user_id bigint(20) NOT NULL,
122
+ date datetime NOT NULL,
123
+ ip varchar(45) COLLATE 'utf8_unicode_ci' NOT NULL,
124
+ PRIMARY KEY (id),
125
+ UNIQUE KEY id (id)
126
+ ) COLLATE 'utf8_unicode_ci'";
127
+
128
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
129
+
130
+ dbDelta($sql_yasr_log_multi_set_table);
131
+
132
+ import_multiset_author();
133
+
134
+ }
135
+
136
+ //remove end 2020
137
+ if (version_compare($yasr_version_installed, '2.1.0') === -1) {
138
+
139
+ $old_yasr_table = $wpdb->prefix . 'yasr_multi_values';
140
+
141
+ //delete all transient that use multiset
142
+ $sql_delete_transient = "
143
  DELETE FROM {$wpdb->options}
144
  WHERE option_name LIKE '_transient_yasr_visitor_multi_set_%'
145
  OR option_name LIKE '_transient_timeout_yasr_visitor_multi_set_%'
146
  ";
147
 
148
+ $wpdb->query($sql_delete_transient);
149
+
150
+ $sql_import_multiset = $wpdb->get_results(
151
+ "SELECT
152
+ post_id,
153
+ set_type,
154
+ field_id,
155
+ number_of_votes,
156
+ sum_votes/number_of_votes as average
157
+ FROM $old_yasr_table
158
+ WHERE number_of_votes > 0
159
+ AND sum_votes > 0
160
+ ORDER BY post_id, set_type",
161
+ ARRAY_A
162
+ );
163
 
164
+ if (!empty($sql_import_multiset)) {
165
+ foreach ($sql_import_multiset as $multiset_ratings) {
166
+ for ($i = 0; $i < $multiset_ratings['number_of_votes']; $i++) {
167
+ $rating_to_save = array(
168
+ 'field_id' => $multiset_ratings['field_id'],
169
+ 'set_type' => $multiset_ratings['set_type'],
170
+ 'post_id' => $multiset_ratings['post_id'],
171
+ 'vote' => $multiset_ratings['average']
172
+ );
173
+ $data_format = array('%d', '%d', '%d', '%f');
174
+ $wpdb->insert(YASR_LOG_MULTI_SET, $rating_to_save, $data_format);
175
+ }
176
  }
177
  }
178
  }
 
179
 
180
+ //remove begin 2021
181
+ //this fix a bug of table not created on version 2.0.9 and 2.1.0
182
+ if (version_compare($yasr_version_installed, '2.1.1') === -1) {
183
+ $multi_set_name_exists = $wpdb->get_var("SELECT COUNT(1) FROM " . YASR_MULTI_SET_NAME_TABLE);
184
 
185
+ $multi_set_field_exists = $wpdb->get_var("SELECT COUNT(1) FROM " . YASR_MULTI_SET_FIELDS_TABLE);
186
 
187
+ if ($multi_set_name_exists === NULL || $multi_set_field_exists === NULL) {
188
+ yasr_create_tables();
189
+ }
190
  }
 
191
 
192
+ /*
193
+ * On version 2.1.0 set_id in YASR_MULTI_SET_NAME_TABLE is set as autoincrement by default
194
+ * In the existing installations, set_id could be = 0
195
+ * Altering set_id to auto_increment will cause a change from 0 to 1
196
+ * Here is the fix
197
+ */
198
+
199
+ if ($yasr_version_installed === '2.1.0' || $yasr_version_installed === '2.1.1') {
200
+ //First I've to check if the column set_id is auto increment
201
+ $column_auto_increment = null;
202
+ $sql_check_auto_increment = "
203
  SELECT EXTRA
204
  FROM INFORMATION_SCHEMA.COLUMNS
205
  WHERE TABLE_NAME='" . YASR_MULTI_SET_NAME_TABLE . "'
207
  AND EXTRA like '%auto_increment%'
208
  ";
209
 
210
+ $column_auto_increment = $wpdb->get_var($sql_check_auto_increment);
211
 
212
+ //if the column is not auto increment, return
213
+ if ($column_auto_increment !== 'auto_increment') {
214
+ return;
215
+ } else {
216
 
217
+ $set_with_id_zero_exists = $wpdb->get_results("
218
  SELECT parent_set_id FROM "
219
+ . YASR_MULTI_SET_FIELDS_TABLE .
220
+ " WHERE parent_set_id = 0
221
  LIMIT 1", ARRAY_A
222
+ );
223
 
224
+ //if there is no field with parent_set_id = 0, return
225
+ if (empty($set_with_id_zero_exists)) {
226
+ return;
227
+ } else {
228
+ $sql_no_auto_increment = $wpdb->query("ALTER TABLE " . YASR_MULTI_SET_NAME_TABLE .
229
+ " CHANGE set_id set_id int(2)
230
  NOT NULL FIRST");
231
 
232
+ //if autoincrement has been removed,
233
+ //change set value from 1 to 0
234
+ //At this point, we're 100% sure that 1 was 0 before
235
+ if ($sql_no_auto_increment === true) {
236
+ $wpdb->update(
237
+ YASR_MULTI_SET_NAME_TABLE,
238
+ //new data
239
+ array(
240
+ 'set_id' => 0
241
+ ),
242
+ //where
243
+ array(
244
+ 'set_id' => 1
245
+ ),
246
+ '%d',
247
+ '%d'
248
  );
249
+ }
250
  }
251
+
252
  }
253
 
254
  }
255
 
256
+ //yasr before 2.1.3 was using JSON_OBJECT to import data.
257
+ //This function doesn't works with all servers, and import can fail
258
+ //Here I check if no meta exists and try to import it again
259
+ if ($yasr_version_installed === '2.0.9' || $yasr_version_installed === '2.1.0'
260
+ || $yasr_version_installed === '2.1.1' || $yasr_version_installed === '2.1.2') {
261
+
262
+ $sql_meta_multiset = $wpdb->query('
263
+ SELECT *
264
+ FROM ' . $wpdb->postmeta .
265
+ ' WHERE (meta_key LIKE \'%yasr_multiset_author_votes%\'
266
+ OR meta_value LIKE \'%yasr_multiset_author_votes%\')
267
+ ');
268
+
269
+ //if no meta are found, try to import data again
270
+ if ($sql_meta_multiset === 0) {
271
+ import_multiset_author();
272
+ }
273
+
274
+ }
275
+
276
+ } //Endif yasr_version_installed !== false
277
 
278
  /****** End backward compatibility functions ******/
279
  if ($yasr_version_installed != YASR_VERSION_NUM) {
readme.txt CHANGED
@@ -5,7 +5,7 @@ Requires at least: 4.3.0
5
  Contributors: Dudo
6
  Tested up to: 5.4
7
  Requires PHP: 5.3
8
- Stable tag: 2.1.2
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,6 +125,12 @@ 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.1.2 =
129
  * NEW FEATURE: is now possible to import rating from Multi Rating
130
  * TWEAKED: updated freemius sdk to version 2.3.2
5
  Contributors: Dudo
6
  Tested up to: 5.4
7
  Requires PHP: 5.3
8
+ Stable tag: 2.1.3
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.1.3 =
129
+ * FIXED: in some older (and rare) mysql or mariadb versions, the function JSON_OBJECT is not supported.
130
+ This was causing the import of multiset data failing since version 2.0.9
131
+ * FIXED: in backed, multiset rating didn't get saved if set_id = 0
132
+ * Minor changes
133
+
134
  = 2.1.2 =
135
  * NEW FEATURE: is now possible to import rating from Multi Rating
136
  * TWEAKED: updated freemius sdk to version 2.3.2
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.1.2
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.1.2' );
80
  //Plugin relative path
81
  define( "YASR_ABSOLUTE_PATH", dirname( __FILE__ ) );
82
  //Plugin RELATIVE PATH without slashes (just the directory's name)
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.1.3
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.1.3' );
80
  //Plugin relative path
81
  define( "YASR_ABSOLUTE_PATH", dirname( __FILE__ ) );
82
  //Plugin RELATIVE PATH without slashes (just the directory's name)