Yasr – Yet Another Stars Rating - Version 2.1.0

Version Description

  • TWEAKED: This is the second important release after 2.0.9. YASR Database structure is now more efficent if you're using MultiSets. If everything works, it is possible to remove the table yasr_multivalues.
  • TWEAKED: "logs" page is now called "stats"
  • NEW FEATURE: inside the "stats" page is now possible to see, and delete, stats for yasr_visitor_multiset shortcode
  • TWEAKED: Code cleanup BACKUP YOUR DATABASE BEFORE UPDATING
Download this release

Release Info

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

Code changes from version 2.0.9 to 2.1.0

lib/admin/settings/yasr-settings-functions-multiset.php CHANGED
@@ -153,7 +153,6 @@ function yasr_edit_multi_form() {
153
  ?>
154
 
155
  <div class="yasr-manage-multiset">
156
-
157
  <h4 class="yasr-multi-set-form-headers"><?php _e("Manage Multiple Set", 'yet-another-stars-rating'); ?></h4>
158
 
159
  <?php _e('Wich set do you want to edit or remove?', 'yet-another-stars-rating') ?>
@@ -165,8 +164,6 @@ function yasr_edit_multi_form() {
165
  </select>
166
 
167
  <button href="#" class="button-delete" id="yasr-button-select-set-edit-form"><?php _e("Select"); ?></button>
168
-
169
-
170
  </div>
171
 
172
  <?php
@@ -177,7 +174,7 @@ function yasr_edit_multi_form() {
177
 
178
  $set_name = $wpdb->get_results("SELECT field_name AS name, field_id AS id, parent_set_id AS set_id
179
  FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
180
- ORDER BY field_id ASC");
181
 
182
  foreach ($multi_set as $find_set_id) {
183
  $set_type = $find_set_id->set_id;
@@ -196,7 +193,6 @@ function yasr_edit_multi_form() {
196
 
197
  <table id="yasr-table-form-edit-multi-set">
198
  <tr>
199
-
200
  <td id="yasr-table-form-edit-multi-set-header">
201
  <?php _e('Field name', 'yet-another-stars-rating') ?>
202
  </td>
@@ -204,7 +200,6 @@ function yasr_edit_multi_form() {
204
  <td id="yasr-table-form-edit-multi-set-remove">
205
  <?php _e('Remove', 'yet-another-stars-rating') ?>
206
  </td>
207
-
208
  </tr>
209
 
210
  <?php
@@ -215,7 +210,6 @@ function yasr_edit_multi_form() {
215
 
216
  echo "
217
  <tr>
218
-
219
  <td width=\"80%\">
220
  Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$i\">
221
  <input type=\"hidden\" value=\"$name->id\" name=\"db-id-for-element-$i\">
@@ -224,7 +218,6 @@ function yasr_edit_multi_form() {
224
  <td width=\"20%\" style=\"text-align:center\">
225
  <input type=\"checkbox\" value=\"$name->id\" name=\"remove-element-$i\">
226
  </td>
227
-
228
  </tr>
229
  ";
230
 
@@ -232,7 +225,6 @@ function yasr_edit_multi_form() {
232
 
233
  }
234
 
235
-
236
  $i = $i - 1; //This is the number of the fields
237
 
238
  echo "
@@ -298,11 +290,14 @@ function yasr_get_multi_set_callback() {
298
 
299
  global $wpdb;
300
 
301
- $set_name = $wpdb->get_results($wpdb->prepare("SELECT field_name AS name, field_id AS id
302
- FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
303
- WHERE parent_set_id=%d
304
- ORDER BY field_id ASC", $set_type));
305
-
 
 
 
306
 
307
  ?>
308
 
@@ -349,7 +344,6 @@ function yasr_get_multi_set_callback() {
349
 
350
  }
351
 
352
-
353
  $i = $i - 1; //This is the number of the fields
354
 
355
  echo "
@@ -415,7 +409,7 @@ function yasr_process_new_multi_set_form() {
415
  $array_errors = array();
416
  $error = false;
417
 
418
- //IF thes fields are not empty go ahed
419
  if ($_POST['multi-set-name'] != '' && $_POST['multi-set-name-element-1'] != '' && $_POST['multi-set-name-element-2'] != '') {
420
 
421
  $multi_set_name = ucfirst(strtolower($_POST['multi-set-name']));
@@ -438,7 +432,7 @@ function yasr_process_new_multi_set_form() {
438
  }
439
 
440
  //Check if a set with that name already exists
441
- $check_name_exists = $wpdb->get_results("SELECT set_name FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id ASC");
442
 
443
  foreach ($check_name_exists as $set_name) {
444
 
@@ -473,55 +467,45 @@ function yasr_process_new_multi_set_form() {
473
 
474
  }
475
 
476
- //If there isnt any error write in the table
477
  if (!$error) {
478
 
479
- //get the highest id in table
480
- $highest_id = $wpdb->get_results("SELECT set_id FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id DESC LIMIT 1 ");
481
-
482
- if (!$highest_id) {
483
- $name_table_new_id = 0;
484
- }
485
-
486
- foreach ($highest_id as $id) {
487
- $name_table_new_id = $id->set_id + 1;
488
- }
489
-
490
  $insert_multi_name_success = $wpdb->replace(
491
  YASR_MULTI_SET_NAME_TABLE,
492
  array(
493
- 'set_id' => $name_table_new_id,
494
  'set_name' => $multi_set_name
495
  ),
496
- array('%d', '%s')
497
  );
498
 
499
- //If multi set name hase been inserted, now we're going to insert elements
500
  if ($insert_multi_name_success) {
501
 
502
- //get the highest id in table
503
- $highest_id = $wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
 
 
 
504
 
505
- if (!$highest_id) {
506
- $field_table_new_id = 0;
507
  }
508
 
509
- foreach ($highest_id as $id) {
510
- $field_table_new_id = $id->id + 1;
511
  }
512
 
513
  for ($i = 1; $i <= $element_filled; $i ++) {
514
  $insert_set_value = $wpdb->replace(
515
  YASR_MULTI_SET_FIELDS_TABLE,
516
  array(
517
- 'id' => $field_table_new_id,
518
- 'parent_set_id' => $name_table_new_id,
519
  'field_name' => $multi_set_name_element_[$i],
520
  'field_id' => $i
521
  ),
522
- array('%d', '%d', '%s', '%d')
523
  );
524
- $field_table_new_id ++; //Avoid overwrite
525
  } //End for
526
 
527
  if ($insert_set_value) {
@@ -563,7 +547,6 @@ function yasr_process_edit_multi_set_form() {
563
  if (isset($_POST['yasr_edit_multi_set_form'])) {
564
 
565
  $set_id = $_POST['yasr_edit_multi_set_form'];
566
-
567
  $number_of_stored_elements = $_POST['yasr-edit-form-number-elements'];
568
 
569
  global $wpdb;
@@ -599,7 +582,7 @@ function yasr_process_edit_multi_set_form() {
599
  );
600
 
601
  $remove_set_votes = $wpdb->delete(
602
- YASR_MULTI_SET_VALUES_TABLE,
603
  array(
604
  'set_type' => $set_id,
605
  ),
@@ -611,20 +594,6 @@ function yasr_process_edit_multi_set_form() {
611
  $array_errors[] .= __("Something goes wrong trying to delete a Multi Set . Please report it", 'yet-another-stars-rating');
612
  }
613
 
614
-
615
- //Comment this out, if try to delete an empty set print error
616
- /*if ($remove_set_values==FALSE) {
617
- $error = TRUE;
618
- $array_errors[] .= __("Something goes wrong trying to delete data fields for a set. Please report it", 'yet-another-stars-rating');
619
- }
620
- */
621
-
622
- //Comment this out, will echo error even if the value for that field it's just empty
623
- /*if ($remove_set_votes==FALSE) {
624
- $error = TRUE;
625
- $array_errors[] .= __("Something goes wrong trying to delete data values for a set. Please report it", 'yet-another-stars-rating');
626
- }*/
627
-
628
  }
629
 
630
  for ($i = 0; $i <= 9; $i ++) {
@@ -644,7 +613,7 @@ function yasr_process_edit_multi_set_form() {
644
  );
645
 
646
  $remove_values = $wpdb->delete(
647
- YASR_MULTI_SET_VALUES_TABLE,
648
  array(
649
  'set_type' => $set_id,
650
  'field_id' => $field_to_remove
@@ -658,13 +627,6 @@ function yasr_process_edit_multi_set_form() {
658
  }
659
 
660
 
661
- //Comment this out, will echo error even if the value for that field it's just empty
662
- /*if ($remove_values == FALSE) {
663
- $error = TRUE;
664
- $array_errors[] = __("Something goes wrong trying to delete data value for an element. Please report it", 'yet-another-stars-rating');
665
- }*/
666
-
667
-
668
  } //End if isset $_POST['remove-element-$i']
669
 
670
 
@@ -672,7 +634,6 @@ function yasr_process_edit_multi_set_form() {
672
  if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i <= $number_of_stored_elements) {
673
 
674
  $field_name = $_POST["edit-multi-set-element-$i"];
675
-
676
  $field_id = $_POST["db-id-for-element-$i"];
677
 
678
  //if elements name is shorter than 3 chars
@@ -702,14 +663,12 @@ function yasr_process_edit_multi_set_form() {
702
  array(
703
  'field_name' => $field_name,
704
  ),
705
-
706
  array(
707
  'parent_set_id' => $set_id,
708
  'field_id' => $field_id
709
  ),
710
 
711
  array('%s'),
712
-
713
  array('%d', '%d')
714
 
715
  );
@@ -745,13 +704,13 @@ function yasr_process_edit_multi_set_form() {
745
  } //if field is not empty
746
  elseif ($field_name != '') {
747
 
748
- $highest_id = $wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
749
-
750
- $highest_field_id = $wpdb->get_results("SELECT field_id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY field_id DESC LIMIT 1 ");
751
 
752
- foreach ($highest_id as $id) {
753
- $field_table_new_id = $id->id + 1;
754
- }
 
 
755
 
756
  foreach ($highest_field_id as $id) {
757
  $new_field_id = $id->field_id + 1;
@@ -760,47 +719,13 @@ function yasr_process_edit_multi_set_form() {
760
  $insert_set_value = $wpdb->replace(
761
  YASR_MULTI_SET_FIELDS_TABLE,
762
  array(
763
- 'id' => $field_table_new_id,
764
  'parent_set_id' => $set_id,
765
  'field_name' => $field_name,
766
  'field_id' => $new_field_id
767
  ),
768
- array('%d', '%d', '%s', '%d')
769
  );
770
 
771
- //now, I've to find which post is using the edited multi set and add the new field with value 0
772
-
773
- //get the highest id
774
- $highest_id_value_table = $wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_VALUES_TABLE . " ORDER BY id DESC LIMIT 1 ");
775
-
776
- foreach ($highest_id_value_table as $id) {
777
- $field_value_table_new_id = $id->id + 1;
778
- }
779
-
780
- //get all the post id that are using this multiset
781
- $array_post_id = $wpdb->get_results($wpdb->prepare("SELECT post_id
782
- FROM " . YASR_MULTI_SET_VALUES_TABLE .
783
- " WHERE set_type=%d
784
- GROUP BY post_id", $set_id));
785
-
786
- //Insert the new fields
787
- foreach ($array_post_id as $postid) {
788
-
789
- $insert_new_field_values_table = $wpdb->insert(
790
- YASR_MULTI_SET_VALUES_TABLE,
791
- array(
792
- 'id' => $field_value_table_new_id,
793
- 'set_type' => $set_id,
794
- 'field_id' => $new_field_id,
795
- 'post_id' => $postid->post_id
796
- ),
797
- array('%d', '%d', '%d', '%d')
798
- );
799
-
800
- $field_value_table_new_id ++;
801
-
802
- }
803
-
804
  if ($insert_set_value == false) {
805
  $error = true;
806
  $array_errors[] = __("Something goes wrong trying to insert set field name in edit form. Please report it", 'yet-another-stars-rating');
153
  ?>
154
 
155
  <div class="yasr-manage-multiset">
 
156
  <h4 class="yasr-multi-set-form-headers"><?php _e("Manage Multiple Set", 'yet-another-stars-rating'); ?></h4>
157
 
158
  <?php _e('Wich set do you want to edit or remove?', 'yet-another-stars-rating') ?>
164
  </select>
165
 
166
  <button href="#" class="button-delete" id="yasr-button-select-set-edit-form"><?php _e("Select"); ?></button>
 
 
167
  </div>
168
 
169
  <?php
174
 
175
  $set_name = $wpdb->get_results("SELECT field_name AS name, field_id AS id, parent_set_id AS set_id
176
  FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
177
+ ORDER BY field_id");
178
 
179
  foreach ($multi_set as $find_set_id) {
180
  $set_type = $find_set_id->set_id;
193
 
194
  <table id="yasr-table-form-edit-multi-set">
195
  <tr>
 
196
  <td id="yasr-table-form-edit-multi-set-header">
197
  <?php _e('Field name', 'yet-another-stars-rating') ?>
198
  </td>
200
  <td id="yasr-table-form-edit-multi-set-remove">
201
  <?php _e('Remove', 'yet-another-stars-rating') ?>
202
  </td>
 
203
  </tr>
204
 
205
  <?php
210
 
211
  echo "
212
  <tr>
 
213
  <td width=\"80%\">
214
  Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$i\">
215
  <input type=\"hidden\" value=\"$name->id\" name=\"db-id-for-element-$i\">
218
  <td width=\"20%\" style=\"text-align:center\">
219
  <input type=\"checkbox\" value=\"$name->id\" name=\"remove-element-$i\">
220
  </td>
 
221
  </tr>
222
  ";
223
 
225
 
226
  }
227
 
 
228
  $i = $i - 1; //This is the number of the fields
229
 
230
  echo "
290
 
291
  global $wpdb;
292
 
293
+ $set_name = $wpdb->get_results(
294
+ $wpdb->prepare(
295
+ "SELECT field_name AS name, field_id AS id
296
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
297
+ WHERE parent_set_id= %d
298
+ ORDER BY field_id",
299
+ $set_type)
300
+ );
301
 
302
  ?>
303
 
344
 
345
  }
346
 
 
347
  $i = $i - 1; //This is the number of the fields
348
 
349
  echo "
409
  $array_errors = array();
410
  $error = false;
411
 
412
+ //IF these fields are not empty go ahead
413
  if ($_POST['multi-set-name'] != '' && $_POST['multi-set-name-element-1'] != '' && $_POST['multi-set-name-element-2'] != '') {
414
 
415
  $multi_set_name = ucfirst(strtolower($_POST['multi-set-name']));
432
  }
433
 
434
  //Check if a set with that name already exists
435
+ $check_name_exists = $wpdb->get_results("SELECT set_name FROM " . YASR_MULTI_SET_NAME_TABLE);
436
 
437
  foreach ($check_name_exists as $set_name) {
438
 
467
 
468
  }
469
 
470
+ //If there isn't any error write in the table
471
  if (!$error) {
472
 
 
 
 
 
 
 
 
 
 
 
 
473
  $insert_multi_name_success = $wpdb->replace(
474
  YASR_MULTI_SET_NAME_TABLE,
475
  array(
 
476
  'set_name' => $multi_set_name
477
  ),
478
+ array('%s')
479
  );
480
 
481
+ //If multi set name has been inserted, now we're going to insert elements
482
  if ($insert_multi_name_success) {
483
 
484
+ //get the last set_id
485
+ $latest_set_id = $wpdb->get_results("SELECT set_id FROM "
486
+ . YASR_MULTI_SET_NAME_TABLE .
487
+ " ORDER BY set_id DESC
488
+ LIMIT 1", ARRAY_A);
489
 
490
+ foreach ($latest_set_id as $id) {
491
+ $set_id = $id['set_id'];
492
  }
493
 
494
+ if (!$set_id) {
495
+ $set_id = 0;
496
  }
497
 
498
  for ($i = 1; $i <= $element_filled; $i ++) {
499
  $insert_set_value = $wpdb->replace(
500
  YASR_MULTI_SET_FIELDS_TABLE,
501
  array(
502
+ 'parent_set_id' => $set_id,
 
503
  'field_name' => $multi_set_name_element_[$i],
504
  'field_id' => $i
505
  ),
506
+ array('%d', '%s', '%d')
507
  );
508
+
509
  } //End for
510
 
511
  if ($insert_set_value) {
547
  if (isset($_POST['yasr_edit_multi_set_form'])) {
548
 
549
  $set_id = $_POST['yasr_edit_multi_set_form'];
 
550
  $number_of_stored_elements = $_POST['yasr-edit-form-number-elements'];
551
 
552
  global $wpdb;
582
  );
583
 
584
  $remove_set_votes = $wpdb->delete(
585
+ YASR_LOG_MULTI_SET,
586
  array(
587
  'set_type' => $set_id,
588
  ),
594
  $array_errors[] .= __("Something goes wrong trying to delete a Multi Set . Please report it", 'yet-another-stars-rating');
595
  }
596
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597
  }
598
 
599
  for ($i = 0; $i <= 9; $i ++) {
613
  );
614
 
615
  $remove_values = $wpdb->delete(
616
+ YASR_LOG_MULTI_SET,
617
  array(
618
  'set_type' => $set_id,
619
  'field_id' => $field_to_remove
627
  }
628
 
629
 
 
 
 
 
 
 
 
630
  } //End if isset $_POST['remove-element-$i']
631
 
632
 
634
  if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i <= $number_of_stored_elements) {
635
 
636
  $field_name = $_POST["edit-multi-set-element-$i"];
 
637
  $field_id = $_POST["db-id-for-element-$i"];
638
 
639
  //if elements name is shorter than 3 chars
663
  array(
664
  'field_name' => $field_name,
665
  ),
 
666
  array(
667
  'parent_set_id' => $set_id,
668
  'field_id' => $field_id
669
  ),
670
 
671
  array('%s'),
 
672
  array('%d', '%d')
673
 
674
  );
704
  } //if field is not empty
705
  elseif ($field_name != '') {
706
 
707
+ $new_field_id = 0;
 
 
708
 
709
+ $highest_field_id = $wpdb->get_results($wpdb->prepare("SELECT field_id
710
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
711
+ WHERE parent_set_id = %d
712
+ ORDER BY field_id DESC LIMIT 1 ", $set_id)
713
+ );
714
 
715
  foreach ($highest_field_id as $id) {
716
  $new_field_id = $id->field_id + 1;
719
  $insert_set_value = $wpdb->replace(
720
  YASR_MULTI_SET_FIELDS_TABLE,
721
  array(
 
722
  'parent_set_id' => $set_id,
723
  'field_name' => $field_name,
724
  'field_id' => $new_field_id
725
  ),
726
+ array('%d', '%s', '%d')
727
  );
728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
729
  if ($insert_set_value == false) {
730
  $error = true;
731
  $array_errors[] = __("Something goes wrong trying to insert set field name in edit form. Please report it", 'yet-another-stars-rating');
lib/admin/settings/yasr-stats-functions.php CHANGED
@@ -29,11 +29,18 @@ function yasr_stats_tabs( $active_tab ) {
29
  <h2 class="nav-tab-wrapper yasr-no-underline">
30
 
31
  <a href="?page=yasr_stats_page&tab=logs" class="nav-tab
32
- <?php if ($active_tab === 'logs') {
 
 
 
 
 
 
 
33
  echo 'nav-tab-active';
34
  } ?>"
35
  >
36
- <?php _e("Logs", 'yet-another-stars-rating'); ?>
37
  </a>
38
  <?php do_action('yasr_add_stats_tab', $active_tab); ?>
39
  <a href="?page=yasr_settings_page-pricing" class="nav-tab">
@@ -50,6 +57,13 @@ function yasr_stats_tabs( $active_tab ) {
50
  * Create a new table class that will extend the WP_List_Table
51
  */
52
  class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
 
 
 
 
 
 
 
53
  /**
54
  * Prepare the items for the table to process
55
  *
@@ -62,16 +76,27 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
62
 
63
  //print bulk_Actions
64
  $this->get_bulk_actions();
65
-
66
  $this->process_bulk_action();
67
 
 
 
 
 
 
68
 
69
  global $wpdb;
70
- $data = $wpdb->get_results("SELECT * FROM " . YASR_LOG_TABLE . " ORDER BY date ASC", ARRAY_A);
 
 
 
 
 
 
 
71
 
72
  usort($data, array( &$this, 'sort_data' ));
73
 
74
- $perPage = 20;
75
  $currentPage = $this->get_pagenum();
76
  $totalItems = count($data);
77
 
@@ -96,25 +121,24 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
96
  */
97
  public function get_columns() {
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  if (YASR_ENABLE_IP === 'yes') {
100
- $columns = array(
101
- 'cb' => '<input type="checkbox" />',
102
- 'id' => 'ID',
103
- 'post_id' => 'Title',
104
- 'user_id' => 'User ID',
105
- 'vote' => 'Vote',
106
- 'date' => 'Date',
107
- 'ip' => 'IP',
108
- );
109
- } else {
110
- $columns = array(
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
  }
@@ -134,12 +158,21 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
134
  * @return Array
135
  */
136
  public function get_sortable_columns() {
137
- return array(
 
 
138
  'user_id' => array('user_id', false),
139
  'vote' => array('vote', false),
140
  'date' => array('date', false),
141
  'ip' => array('ip', false)
142
  );
 
 
 
 
 
 
 
143
  }
144
 
145
  /**
@@ -152,6 +185,12 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
152
  */
153
  protected function column_default( $item, $column_name ) {
154
 
 
 
 
 
 
 
155
  switch ($column_name) {
156
  case 'post_id':
157
  $post_id = $item[$column_name];
@@ -159,9 +198,7 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
159
  $title_post = wp_strip_all_tags(get_the_title($post_id));
160
  $link = get_permalink($post_id);
161
 
162
- $yasr_title_link = '<a href="' . $link . '">' . $title_post . '</a>';
163
-
164
- return $yasr_title_link;
165
 
166
  case 'user_id':
167
  $user_id = $item[$column_name];
@@ -169,18 +206,55 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
169
  $user = get_user_by('id', $user_id);
170
 
171
  //If !user means that the vote are anonymous
172
- if ($user == false) {
173
  $user = (object) array( 'user_login' );
174
  $user->user_login = __('anonymous', 'yet-another-stars-rating');
175
  }
176
 
177
  return $user->user_login;
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  //All other columns must return their content
180
  case 'vote':
181
- case 'date':
182
  case 'ip':
183
- return $item[ $column_name ];
184
  }
185
 
186
  }
@@ -207,7 +281,6 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
207
  $order = $_GET['order'];
208
  }
209
 
210
-
211
  $result = strcmp($a[ $orderby ], $b[ $orderby ]);
212
 
213
  if ($order === 'asc') {
@@ -240,6 +313,15 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
240
 
241
  global $wpdb;
242
 
 
 
 
 
 
 
 
 
 
243
  foreach ($_POST['yasr_logs_votes_to_delete'] as $log_id) {
244
  //force to be an int
245
  $log_id = (int)$log_id;
@@ -247,16 +329,26 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
247
  //Find the post_id
248
  $post_id = $wpdb->get_var(
249
  $wpdb->prepare(
250
- "SELECT post_id FROM "
251
- . YASR_LOG_TABLE .
252
- " WHERE id = %d",
253
  $log_id
254
  )
255
  );
256
 
 
 
 
 
 
 
 
 
 
 
257
  //delete the log id
258
  $wpdb->delete(
259
- YASR_LOG_TABLE,
260
  array(
261
  'id' => $log_id
262
  ),
@@ -264,7 +356,12 @@ class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
264
  );
265
 
266
  //delete transient
267
- $transient_name = 'yasr_visitor_votes_' . $post_id;
 
 
 
 
 
268
  delete_transient($transient_name);
269
  }
270
  }
29
  <h2 class="nav-tab-wrapper yasr-no-underline">
30
 
31
  <a href="?page=yasr_stats_page&tab=logs" class="nav-tab
32
+ <?php if ($active_tab === 'logs') {
33
+ echo 'nav-tab-active';
34
+ } ?>"
35
+ >
36
+ <?php _e("Visitor Votes", 'yet-another-stars-rating'); ?>
37
+ </a>
38
+ <a href="?page=yasr_stats_page&tab=logs_multi" class="nav-tab
39
+ <?php if ($active_tab === 'logs_multi') {
40
  echo 'nav-tab-active';
41
  } ?>"
42
  >
43
+ <?php _e("MultiSet", 'yet-another-stars-rating'); ?>
44
  </a>
45
  <?php do_action('yasr_add_stats_tab', $active_tab); ?>
46
  <a href="?page=yasr_settings_page-pricing" class="nav-tab">
57
  * Create a new table class that will extend the WP_List_Table
58
  */
59
  class YASR_Stats_Log_List_Table extends YASR_WP_List_Table {
60
+
61
+ private $active_tab;
62
+
63
+ function __construct($active_tab) {
64
+ parent::__construct();
65
+ $this->active_tab = $active_tab;
66
+ }
67
  /**
68
  * Prepare the items for the table to process
69
  *
76
 
77
  //print bulk_Actions
78
  $this->get_bulk_actions();
 
79
  $this->process_bulk_action();
80
 
81
+ $table = YASR_LOG_TABLE;
82
+
83
+ if($this->active_tab === 'logs_multi') {
84
+ $table = YASR_LOG_MULTI_SET;
85
+ }
86
 
87
  global $wpdb;
88
+
89
+ $query = "SELECT * FROM $table ORDER BY date";
90
+
91
+ if ($table === YASR_LOG_MULTI_SET) {
92
+ $query .= ', set_type, post_id DESC';
93
+ }
94
+
95
+ $data = $wpdb->get_results($query, ARRAY_A);
96
 
97
  usort($data, array( &$this, 'sort_data' ));
98
 
99
+ $perPage = 25;
100
  $currentPage = $this->get_pagenum();
101
  $totalItems = count($data);
102
 
121
  */
122
  public function get_columns() {
123
 
124
+ $columns = array(
125
+ 'cb' => '<input type="checkbox" />',
126
+ 'id' => 'ID',
127
+ 'post_id' => 'Title',
128
+ 'vote' => 'Vote',
129
+ 'user_id' => 'User ID',
130
+ 'date' => 'Date'
131
+ );
132
+
133
+ if($this->active_tab === 'logs_multi') {
134
+ //insert multiset and field name
135
+ $columns = array_slice($columns, 0, 3, true) +
136
+ array('set_type' => 'MultiSet', 'field_id' => 'Field Name') +
137
+ array_slice($columns, 3, count($columns) - 1, true) ;
138
+ }
139
+
140
  if (YASR_ENABLE_IP === 'yes') {
141
+ $columns['ip'] = 'IP';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  }
143
  return $columns;
144
  }
158
  * @return Array
159
  */
160
  public function get_sortable_columns() {
161
+
162
+ $sortable_columns = array(
163
+ 'post_id' => array('post_id', false),
164
  'user_id' => array('user_id', false),
165
  'vote' => array('vote', false),
166
  'date' => array('date', false),
167
  'ip' => array('ip', false)
168
  );
169
+
170
+ if($this->active_tab === 'logs_multi') {
171
+ $sortable_columns['set_type'] = array('set_type', false);
172
+ $sortable_columns['field_id'] = array('field_id', false);
173
+ }
174
+
175
+ return $sortable_columns;
176
  }
177
 
178
  /**
185
  */
186
  protected function column_default( $item, $column_name ) {
187
 
188
+ global $wpdb;
189
+
190
+ if (isset($item['set_type'])) {
191
+ $set_id = (int)$item['set_type'];
192
+ }
193
+
194
  switch ($column_name) {
195
  case 'post_id':
196
  $post_id = $item[$column_name];
198
  $title_post = wp_strip_all_tags(get_the_title($post_id));
199
  $link = get_permalink($post_id);
200
 
201
+ return '<a href="' . $link . '">' . $title_post . '</a>';
 
 
202
 
203
  case 'user_id':
204
  $user_id = $item[$column_name];
206
  $user = get_user_by('id', $user_id);
207
 
208
  //If !user means that the vote are anonymous
209
+ if ($user === false) {
210
  $user = (object) array( 'user_login' );
211
  $user->user_login = __('anonymous', 'yet-another-stars-rating');
212
  }
213
 
214
  return $user->user_login;
215
 
216
+ case 'set_type':
217
+ $data = $wpdb->get_results(
218
+ $wpdb->prepare(
219
+ "SELECT set_name
220
+ FROM " . YASR_MULTI_SET_NAME_TABLE . "
221
+ WHERE set_id = %d", $set_id),
222
+ ARRAY_A);
223
+
224
+ if(!empty($data)) {
225
+ return $data[0]['set_name'];
226
+ }
227
+
228
+ return __('Multi Set doesn\'t exists', 'yet-another-stars-rating');
229
+
230
+ case 'field_id':
231
+ $field_id = $item[$column_name];
232
+ $data = $wpdb->get_results(
233
+ $wpdb->prepare(
234
+ "SELECT field_name
235
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
236
+ WHERE parent_set_id = %d
237
+ AND field_id = %d",
238
+ $set_id, $field_id),
239
+ ARRAY_A);
240
+
241
+ if(!empty($data)) {
242
+ return $data[0]['field_name'];
243
+ }
244
+
245
+ return __('Field doesn\'t exists', 'yet-another-stars-rating');
246
+
247
+ case 'date':
248
+ $date = $item[$column_name];
249
+ if($item[$column_name] === '0000-00-00 00:00:00') {
250
+ $date = __('Imported Data', 'yet-another-stars-rating');
251
+ }
252
+ return $date;
253
+
254
  //All other columns must return their content
255
  case 'vote':
 
256
  case 'ip':
257
+ return $item[$column_name];
258
  }
259
 
260
  }
281
  $order = $_GET['order'];
282
  }
283
 
 
284
  $result = strcmp($a[ $orderby ], $b[ $orderby ]);
285
 
286
  if ($order === 'asc') {
313
 
314
  global $wpdb;
315
 
316
+ $table = YASR_LOG_TABLE;
317
+ $transient_name = 'yasr_visitor_votes_';
318
+ $query_set_id = false;
319
+
320
+ if($this->active_tab === 'logs_multi') {
321
+ $table = YASR_LOG_MULTI_SET;
322
+ $transient_name = 'yasr_visitor_multi_set_';
323
+ }
324
+
325
  foreach ($_POST['yasr_logs_votes_to_delete'] as $log_id) {
326
  //force to be an int
327
  $log_id = (int)$log_id;
329
  //Find the post_id
330
  $post_id = $wpdb->get_var(
331
  $wpdb->prepare(
332
+ "SELECT post_id FROM
333
+ $table
334
+ WHERE id = %d",
335
  $log_id
336
  )
337
  );
338
 
339
+ //find set_id
340
+ if($this->active_tab === 'logs_multi') {
341
+ $set_id = $wpdb->get_var(
342
+ $wpdb->prepare(
343
+ "SELECT set_type FROM $table WHERE id = %d",
344
+ $log_id
345
+ )
346
+ );
347
+ }
348
+
349
  //delete the log id
350
  $wpdb->delete(
351
+ $table,
352
  array(
353
  'id' => $log_id
354
  ),
356
  );
357
 
358
  //delete transient
359
+ $transient_name = $transient_name . $post_id;
360
+
361
+ if($this->active_tab === 'logs_multi') {
362
+ $transient_name .= "_$set_id";
363
+ }
364
+
365
  delete_transient($transient_name);
366
  }
367
  }
lib/admin/yasr-update-functions.php CHANGED
@@ -16,7 +16,23 @@ function yasr_update_version() {
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");
@@ -47,7 +63,7 @@ function yasr_update_version() {
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(
@@ -58,10 +74,10 @@ function yasr_update_version() {
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
  )
@@ -109,17 +125,55 @@ function yasr_update_version() {
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 ******/
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");
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(
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
  )
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
+ //add auto increment
141
+ $wpdb->query("ALTER TABLE " . YASR_MULTI_SET_FIELDS_TABLE . "
142
+ CHANGE id id bigint(20) NOT NULL AUTO_INCREMENT FIRST
143
+ ");
144
+
145
+ //add auto increment
146
+ $wpdb->query("ALTER TABLE " . YASR_MULTI_SET_NAME_TABLE . "
147
+ CHANGE set_id set_id int(2) NOT NULL AUTO_INCREMENT FIRST
148
+ ");
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", ARRAY_A
161
+ );
162
 
163
+ if(!empty($sql_import_multiset)) {
164
+ foreach ($sql_import_multiset as $multiset_ratings) {
165
+ for ($i=0; $i<$multiset_ratings['number_of_votes']; $i++) {
166
+ $rating_to_save = array (
167
+ 'field_id' => $multiset_ratings['field_id'],
168
+ 'set_type' => $multiset_ratings['set_type'],
169
+ 'post_id' => $multiset_ratings['post_id'],
170
+ 'vote' => $multiset_ratings['average']
171
+ );
172
+ $data_format = array ('%d', '%d', '%d', '%f');
173
+ $wpdb->insert(YASR_LOG_MULTI_SET, $rating_to_save, $data_format);
174
+ }
175
+ }
176
+ }
177
  }
178
 
179
  /****** End backward compatibility functions ******/
lib/yasr-ajax-functions.php CHANGED
@@ -558,62 +558,80 @@ add_action( 'wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback'
558
 
559
  /****** Yasr insert visitor votes, called from yasr-shortcode-function ******/
560
 
561
- add_action( 'wp_ajax_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback' );
562
- add_action( 'wp_ajax_nopriv_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback' );
563
 
564
- function yasr_insert_visitor_votes_callback () {
565
 
566
- if(isset($_POST['rating']) && isset($_POST['post_id']) && isset($_POST['nonce_visitor'])) {
567
 
568
- $rating = $_POST['rating'];
569
- $post_id = $_POST['post_id'];
570
- $nonce_visitor = $_POST['nonce_visitor'];
571
- $is_singular = $_POST['is_singular'];
572
 
573
- if($post_id == '') {
574
- exit();
575
- }
576
-
577
- }
578
-
579
- else {
580
  exit();
581
  }
582
 
583
- $array_action_visitor_vote = array('post_id' => $post_id, 'is_singular' => $is_singular);
 
 
584
 
585
- do_action('yasr_action_on_visitor_vote', $array_action_visitor_vote);
586
 
587
- if ( ! wp_verify_nonce( $nonce_visitor, 'yasr_nonce_insert_visitor_rating' ) ) {
588
- die( 'Security check' );
589
- }
590
 
591
- if ($rating < 1) {
592
- _e("Error: you can't vote 0", 'yet-another-stars-rating');
593
- die();
594
- }
595
 
596
- elseif ($rating > 5 ) {
597
- $rating = 5;
598
- }
 
599
 
600
- $transient_name = 'yasr_visitor_votes_' . $post_id;
 
 
601
 
602
- delete_transient( $transient_name );
603
 
604
- global $wpdb;
605
 
606
- $current_user = wp_get_current_user();
607
 
608
- $ip_adress = yasr_get_ip();
 
609
 
610
- $result_update_log = NULL; //avoid undefined
611
- $result_insert_log = NULL; //avoid undefined
612
 
613
- if (is_user_logged_in()) {
614
 
615
- //try to update first, if fails the do the insert
616
- $result_update_log = $wpdb->update (
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
617
  YASR_LOG_TABLE,
618
  array (
619
  'post_id' => $post_id,
@@ -622,393 +640,330 @@ add_action( 'wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback'
622
  'date' => date('Y-m-d H:i:s'),
623
  'ip' => $ip_adress
624
  ),
625
- array (
626
- 'post_id' => $post_id,
627
- 'user_id' => $current_user->ID
628
- ),
629
- array ('%d', '%d', '%d', '%s', '%s', '%s'),
630
- array ('%d', '%d')
631
-
632
  );
633
-
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'),
644
- 'ip' => $ip_adress
645
- ),
646
- array ('%d', '%d', '%d', '%s', '%s', '%s')
647
- );
648
- }
649
-
650
  }
651
 
652
- //if user is not logged in insert
653
- else {
654
 
655
- //be sure that allow anonymous is on
656
- if (YASR_ALLOWED_USER === 'allow_anonymous')
657
 
658
- $result_insert_log = $wpdb->replace (
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'),
665
- 'ip' => $ip_adress
666
- ),
667
 
668
- array ('%d', '%d', '%d', '%s', '%s', '%s')
669
- );
 
 
 
 
 
 
 
670
 
671
- }
 
672
 
673
- if($result_update_log || $result_insert_log) {
674
 
675
- $row_exists = yasr_get_visitor_votes ($post_id, $create_transient=FALSE);
676
 
677
- foreach ($row_exists as $results) {
678
- $stored_user_votes_sum = $results->sum_votes;
679
- $stored_number_of_votes = $results->number_of_votes;
680
- }
681
 
682
- $user_votes_sum = $stored_user_votes_sum;
683
- $number_of_votes = $stored_number_of_votes;
 
 
684
 
685
- $cookiename = 'yasr_visitor_vote_cookie';
 
686
 
687
- $data_to_save = array(
688
- 'post_id' => $post_id,
689
- 'rating' => $rating
690
- );
691
 
692
- yasr_setcookie($cookiename, $data_to_save);
 
 
 
693
 
694
- $total_rating = ($user_votes_sum / $number_of_votes);
695
- $medium_rating = round ($total_rating, 1);
696
 
697
- $html_to_return = '<span class="yasr-total-average-text"> [' . __( 'Total:', 'yet-another-stars-rating' ) . " $number_of_votes &nbsp; &nbsp;" . __( 'Average:', 'yet-another-stars-rating' ) . " $medium_rating/5 ]</span>";
698
- $html_to_return .= '<span class="yasr-small-block-bold" id="yasr-vote-saved">' . __( 'Vote Saved', 'yet-another-stars-rating' ) . '</span>';
699
 
700
- echo json_encode($html_to_return);
 
701
 
702
- }
703
-
704
- die(); // this is required to return a proper result
705
 
706
  }
707
 
708
- /****** Get Multiple value from visitor and insert into db, used in yasr-shortcode-functions ******/
709
 
710
- add_action( 'wp_ajax_yasr_visitor_multiset_field_vote', 'yasr_visitor_multiset_field_vote_callback' );
711
- add_action ('wp_ajax_nopriv_yasr_visitor_multiset_field_vote', 'yasr_visitor_multiset_field_vote_callback');
712
 
713
- function yasr_visitor_multiset_field_vote_callback() {
714
 
715
- if (isset($_POST['post_id']) && isset($_POST['rating']) && isset($_POST['set_type'])) {
716
- $post_id = $_POST['post_id'];
717
- $rating = $_POST['rating'];
718
- $set_type = $_POST['set_type'];
719
- $nonce = $_POST['nonce'];
720
 
721
- if ($post_id == '' || $set_type == '') {
722
- exit("Missing post id or set type");
723
- }
724
 
725
- if ($rating == "") {
726
- exit("You must insert at least a rating");
727
- }
 
 
728
 
729
- } else {
730
- exit();
731
  }
732
 
733
- if (!wp_verify_nonce($nonce, 'yasr_nonce_insert_visitor_rating_multiset')) {
734
- die('Security Check');
735
  }
736
 
737
- delete_transient('yasr_visitor_multi_set_' . $post_id . '_' . $set_type);
 
 
738
 
739
- $array_action_visitor_multiset_vote = array('post_id' => $post_id);
 
 
740
 
741
- do_action('yasr_action_on_visitor_multiset_vote', $array_action_visitor_multiset_vote);
 
742
 
743
- global $wpdb;
744
 
745
- $array_error = array();
746
 
747
- //clean array, so if an user rate same field twice, take only the last rating
748
- $cleaned_array = yasr_unique_multidim_array($rating, 'field');
749
 
750
- //this is a counter: if at the end of the foreach it still 0, means that an user rated in a set
751
- //and then submit another one
752
- $counter_matched_fields = 0;
753
 
754
- foreach ($cleaned_array as $rating_values) {
755
 
756
- //check if the set id in the array is the same of the clicked
757
- if ($rating_values['postid'] == $post_id && $rating_values['setid'] == $set_type) {
758
 
759
- //increase the counter
760
- $counter_matched_fields = $counter_matched_fields + 1;
 
761
 
762
- $id_field = $rating_values['field'];
763
- $rating = $rating_values['rating'];
764
 
765
- //Find the existing votes
766
- $existing_vote = $wpdb->get_results($wpdb->prepare("SELECT number_of_votes, sum_votes FROM " . YASR_MULTI_SET_VALUES_TABLE . "
767
- WHERE post_id = %d
768
- AND set_type = %d
769
- AND field_id = %d
770
- ", $post_id, $set_type, $id_field));
771
 
772
- if (!empty($existing_vote)) {
 
773
 
774
- foreach ($existing_vote as $user_votes) {
775
- $number_of_votes = $user_votes->number_of_votes;
776
- $user_votes_sum = $user_votes->sum_votes;
777
- }
778
-
779
- $number_of_votes = $number_of_votes + 1;
780
- $user_votes_sum = $user_votes_sum + $rating;
781
-
782
- $query_success = $wpdb->update(
783
- YASR_MULTI_SET_VALUES_TABLE,
784
- array(
785
- 'number_of_votes' => $number_of_votes,
786
- 'sum_votes' => $user_votes_sum,
787
- ),
788
- array(
789
- 'post_id' => $post_id,
790
- 'field_id' => $id_field,
791
- 'set_type' => $set_type
792
- ),
793
- array('%d', '%s'),
794
- array('%d', '%d', '%d')
795
- );
796
-
797
- } else {
798
-
799
- //Find the highest_id (it's not auto increment on db due to gd star compatibility)
800
- $highest_id = $wpdb->get_var("SELECT id FROM " . YASR_MULTI_SET_VALUES_TABLE . " ORDER BY id DESC LIMIT 1 ");
801
-
802
- //highest id is 0 in data is empty
803
- if (!$highest_id) {
804
- $new_id = 0;
805
- }
806
 
807
- $new_id = $highest_id + 1;
808
-
809
- $query_success = $wpdb->replace(
810
- YASR_MULTI_SET_VALUES_TABLE,
811
- array(
812
- 'id' => $new_id,
813
- 'post_id' => $post_id,
814
- 'field_id' => $id_field,
815
- 'set_type' => $set_type,
816
- 'number_of_votes' => 1,
817
- 'sum_votes' => $rating
818
- ),
819
- array("%d", "%d", "%d", "%d", "%d", "%d")
820
- );
821
 
822
- }
 
 
823
 
824
- if ($query_success) {
825
- $array_error[] = 0;
826
- } else {
827
- $array_error[] = 1;
828
- }
829
 
830
- } //End if $rating_values['postid'] == $post_id
831
 
832
- } //End foreach ($rating as $rating_values)
833
 
834
- if ($counter_matched_fields === 0) {
835
- $array_error[] = 1;
836
- }
837
 
838
- $error_found = false;
839
 
840
- foreach ($array_error as $error) {
841
- if ($error === 1) {
842
- $error_found = true;
843
- }
844
  }
 
845
 
846
- if (!$error_found) {
847
-
848
- $cookiename = 'yasr_multi_visitor_cookie';
849
 
850
- $data_to_save = array(
851
- 'post_id' => $post_id,
852
- 'set_id' => $set_type
853
- );
854
 
855
- yasr_setcookie($cookiename, $data_to_save);
856
 
857
- _e('Rating saved!', 'yet-another-stars-rating');
858
 
859
- } else {
860
- _e('Rating not saved. Please Try again', 'yet-another-stars-rating');
861
- }
862
 
863
- die();
864
 
865
- } //End callback function
866
 
867
 
868
- add_action( 'wp_ajax_yasr_stats_visitors_votes', 'yasr_stats_visitors_votes_callback' );
869
- add_action( 'wp_ajax_nopriv_yasr_stats_visitors_votes', 'yasr_stats_visitors_votes_callback' );
870
 
871
- function yasr_stats_visitors_votes_callback () {
872
 
873
- if(isset($_POST['post_id']) && $_POST['post_id'] != '' ) {
874
- $post_id = $_POST['post_id'];
875
- }
876
 
877
- else {
878
- exit();
879
- }
880
 
881
- $votes = yasr_get_visitor_votes($post_id);
882
 
883
- $medium_rating=0; //Avoid undefined variable
884
 
885
- if (!$votes) {
886
- $votes=0; //Avoid undefined variable if there is not overall rating
887
- $votes_number=0; //Avoid undefined variable
888
- }
889
 
890
- else {
891
- foreach ($votes as $user_votes) {
892
- $votes_number = $user_votes->number_of_votes;
893
- if ($votes_number != 0 ) {
894
- $medium_rating = ($user_votes->sum_votes/$votes_number);
895
- }
896
- else {
897
- $medium_rating = 0;
898
- }
899
  }
900
  }
 
901
 
902
- $medium_rating=round($medium_rating, 1);
903
-
904
- $missing_vote = NULL; //avoid undefined variable
905
 
906
- global $wpdb;
907
 
908
- $stats = $wpdb->get_results( $wpdb->prepare ("SELECT ROUND( vote, 0 ) as vote, COUNT( vote ) AS n_of_votes
909
- FROM ". YASR_LOG_TABLE . "
910
- WHERE post_id=%d
911
- GROUP BY vote
912
- ORDER BY vote DESC
913
- ",
914
- $post_id ),
915
- ARRAY_A);
916
 
917
- $total_votes=0; //Avoid undefined variable if stats exists. Necessary if $stats not exists
 
 
 
 
 
 
 
918
 
919
- //if query return 0 write an empty array $existing_votes
920
- if (!$stats) {
921
- $existing_votes = array();
922
- }
923
 
924
- else {
925
- //Write a new array with only existing votes, and count all the number of votes
926
- foreach ($stats as $votes) {
927
- $existing_votes[] = $votes['vote'];//Create an array with only existing votes
928
- $total_votes = $total_votes + $votes['n_of_votes'];
929
- }
930
 
 
 
 
 
 
931
  }
932
 
933
- for ($i=1; $i<=5; $i++){
934
 
935
- //If query return 0 write a new $stats array with index
936
- if (!$stats) {
937
- $stats[$i] = array();
938
- $stats[$i]['vote'] = $i;
939
- $stats[$i]['n_of_votes'] = 0;
940
- }
941
 
942
- else {
 
 
 
 
 
943
 
944
- //If in the new array there are some vote missing create a new array
945
- if(!in_array($i, $existing_votes)) {
946
- $missing_vote[$i] = array();
947
- $missing_vote[$i]['vote'] = $i;
948
- $missing_vote[$i]['n_of_votes'] = 0;
949
- }
950
 
 
 
 
 
 
951
  }
952
 
953
  }
954
 
955
- //If missing_vote exists merge it
956
- if ($missing_vote) {
957
 
958
- $stats = array_merge($stats, $missing_vote);
 
959
 
960
- }
961
 
962
- arsort($stats); //sort it by $votes[n_of_votes]
963
 
964
- $html_to_return = '<div class="yasr-visitors-stats-tooltip">';
965
 
966
- $html_to_return .= '<span id="yasr-medium-rating-tooltip">' . $medium_rating . ' ' . __('out of 5 stars', 'yet-another-stars-rating') . '</span>';
967
 
968
- $html_to_return .= '<div class="yasr-progress-bars-container">';
969
 
970
- if ($total_votes == 0) {
971
- $increase_bar_value = 0;
972
- }
973
- else {
974
- $increase_bar_value = 100 / $total_votes; //Find how much all the bars should increase per vote
975
- }
 
 
976
 
977
- $i=5;
978
 
979
- $stars_text = __("stars", 'yet-another-stars-rating');
980
 
981
- foreach ($stats as $logged_votes) {
982
 
983
- if ($i==1) {
984
- $stars_text = __("star", 'yet-another-stars-rating');
985
- }
986
 
987
- $value_progressbar = $increase_bar_value * $logged_votes['n_of_votes']; //value of the single bar
988
 
989
- $value_progressbar = round ($value_progressbar, 2) . '%'; //use only 2 decimal
990
 
991
- $html_to_return .= "<div class=\"yasr-progress-bar-row-container yasr-w3-container\">
992
- <div class=\"yasr-progress-bar-name\">$i $stars_text</div>
993
- <div class='yasr-single-progress-bar-container'>
994
- <div class=\"yasr-w3-border \">
995
- <div class=\"yasr-w3-amber\" style=\"height:17px;width:$value_progressbar\"></div>
996
- </div></div>
997
- <div class=\"yasr-progress-bar-votes-count\">" . $logged_votes['n_of_votes'] . "</div><br />
998
- </div>";
999
 
1000
- $i--;
1001
 
1002
 
1003
- } //End foreach
1004
 
1005
 
1006
- $html_to_return .= '</div></div>';
1007
 
1008
- echo json_encode($html_to_return);
1009
 
1010
- die();
1011
 
1012
- }
1013
 
1014
  ?>
558
 
559
  /****** Yasr insert visitor votes, called from yasr-shortcode-function ******/
560
 
561
+ add_action( 'wp_ajax_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback' );
562
+ add_action( 'wp_ajax_nopriv_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback' );
563
 
564
+ function yasr_insert_visitor_votes_callback () {
565
 
566
+ if(isset($_POST['rating']) && isset($_POST['post_id']) && isset($_POST['nonce_visitor'])) {
567
 
568
+ $rating = (int)$_POST['rating'];
569
+ $post_id = (int)$_POST['post_id'];
570
+ $nonce_visitor = $_POST['nonce_visitor'];
571
+ $is_singular = $_POST['is_singular'];
572
 
573
+ if(!is_int($post_id)) {
 
 
 
 
 
 
574
  exit();
575
  }
576
 
577
+ } else {
578
+ exit();
579
+ }
580
 
581
+ $array_action_visitor_vote = array('post_id' => $post_id, 'is_singular' => $is_singular);
582
 
583
+ do_action('yasr_action_on_visitor_vote', $array_action_visitor_vote);
 
 
584
 
585
+ if ( ! wp_verify_nonce( $nonce_visitor, 'yasr_nonce_insert_visitor_rating' ) ) {
586
+ die( 'Security check' );
587
+ }
 
588
 
589
+ if ($rating < 1) {
590
+ _e("Error: you can't vote 0", 'yet-another-stars-rating');
591
+ die();
592
+ }
593
 
594
+ elseif ($rating > 5 ) {
595
+ $rating = 5;
596
+ }
597
 
598
+ $transient_name = 'yasr_visitor_votes_' . $post_id;
599
 
600
+ delete_transient( $transient_name );
601
 
602
+ global $wpdb;
603
 
604
+ $current_user = wp_get_current_user();
605
+ $ip_adress = yasr_get_ip();
606
 
607
+ $result_update_log = NULL; //avoid undefined
608
+ $result_insert_log = NULL; //avoid undefined
609
 
610
+ if (is_user_logged_in()) {
611
 
612
+ //try to update first, if fails the do the insert
613
+ $result_update_log = $wpdb->update (
614
+ YASR_LOG_TABLE,
615
+ array (
616
+ 'post_id' => $post_id,
617
+ 'user_id' => $current_user->ID,
618
+ 'vote' => $rating,
619
+ 'date' => date('Y-m-d H:i:s'),
620
+ 'ip' => $ip_adress
621
+ ),
622
+ array (
623
+ 'post_id' => $post_id,
624
+ 'user_id' => $current_user->ID
625
+ ),
626
+ array ('%d', '%d', '%d', '%s', '%s', '%s'),
627
+ array ('%d', '%d')
628
+
629
+ );
630
+
631
+ //insert the new row
632
+ //use ! instead of === FALSE
633
+ if (!$result_update_log) {
634
+ $result_insert_log = $wpdb->insert (
635
  YASR_LOG_TABLE,
636
  array (
637
  'post_id' => $post_id,
640
  'date' => date('Y-m-d H:i:s'),
641
  'ip' => $ip_adress
642
  ),
643
+ array ('%d', '%d', '%d', '%s', '%s', '%s')
 
 
 
 
 
 
644
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
645
  }
646
 
647
+ }
 
648
 
649
+ //if user is not logged in insert
650
+ else {
651
 
652
+ //be sure that allow anonymous is on
653
+ if (YASR_ALLOWED_USER === 'allow_anonymous')
 
 
 
 
 
 
 
654
 
655
+ $result_insert_log = $wpdb->replace (
656
+ YASR_LOG_TABLE,
657
+ array (
658
+ 'post_id' => $post_id,
659
+ 'user_id' => $current_user->ID,
660
+ 'vote' => $rating,
661
+ 'date' => date('Y-m-d H:i:s'),
662
+ 'ip' => $ip_adress
663
+ ),
664
 
665
+ array ('%d', '%d', '%d', '%s', '%s', '%s')
666
+ );
667
 
668
+ }
669
 
670
+ if($result_update_log || $result_insert_log) {
671
 
672
+ $row_exists = yasr_get_visitor_votes ($post_id, $create_transient=FALSE);
 
 
 
673
 
674
+ foreach ($row_exists as $results) {
675
+ $stored_user_votes_sum = $results->sum_votes;
676
+ $stored_number_of_votes = $results->number_of_votes;
677
+ }
678
 
679
+ $user_votes_sum = $stored_user_votes_sum;
680
+ $number_of_votes = $stored_number_of_votes;
681
 
682
+ $cookiename = 'yasr_visitor_vote_cookie';
 
 
 
683
 
684
+ $data_to_save = array(
685
+ 'post_id' => $post_id,
686
+ 'rating' => $rating
687
+ );
688
 
689
+ yasr_setcookie($cookiename, $data_to_save);
 
690
 
691
+ $total_rating = ($user_votes_sum / $number_of_votes);
692
+ $medium_rating = round ($total_rating, 1);
693
 
694
+ $html_to_return = '<span class="yasr-total-average-text"> [' . __( 'Total:', 'yet-another-stars-rating' ) . " $number_of_votes &nbsp; &nbsp;" . __( 'Average:', 'yet-another-stars-rating' ) . " $medium_rating/5 ]</span>";
695
+ $html_to_return .= '<span class="yasr-small-block-bold" id="yasr-vote-saved">' . __( 'Vote Saved', 'yet-another-stars-rating' ) . '</span>';
696
 
697
+ echo json_encode($html_to_return);
 
 
698
 
699
  }
700
 
701
+ die(); // this is required to return a proper result
702
 
703
+ }
 
704
 
705
+ /****** Get Multiple value from visitor and insert into db, used in yasr-shortcode-functions ******/
706
 
707
+ add_action( 'wp_ajax_yasr_visitor_multiset_field_vote', 'yasr_visitor_multiset_field_vote_callback' );
708
+ add_action ('wp_ajax_nopriv_yasr_visitor_multiset_field_vote', 'yasr_visitor_multiset_field_vote_callback');
 
 
 
709
 
710
+ function yasr_visitor_multiset_field_vote_callback() {
 
 
711
 
712
+ if (isset($_POST['post_id']) && isset($_POST['rating']) && isset($_POST['set_type'])) {
713
+ $post_id = (int)$_POST['post_id'];
714
+ $rating = $_POST['rating'];
715
+ $set_type = (int)$_POST['set_type'];
716
+ $nonce = $_POST['nonce'];
717
 
718
+ if (!is_int($post_id) || !is_int($set_type)) {
719
+ exit("Missing post id or set type");
720
  }
721
 
722
+ if ($rating == "") {
723
+ exit("You must insert at least a rating");
724
  }
725
 
726
+ } else {
727
+ exit();
728
+ }
729
 
730
+ if (!wp_verify_nonce($nonce, 'yasr_nonce_insert_visitor_rating_multiset')) {
731
+ die('Security Check');
732
+ }
733
 
734
+ $current_user = wp_get_current_user();
735
+ $ip_adress = yasr_get_ip();
736
 
737
+ delete_transient('yasr_visitor_multi_set_' . $post_id . '_' . $set_type);
738
 
739
+ $array_action_visitor_multiset_vote = array('post_id' => $post_id);
740
 
741
+ do_action('yasr_action_on_visitor_multiset_vote', $array_action_visitor_multiset_vote);
 
742
 
743
+ global $wpdb;
 
 
744
 
745
+ $array_error = array();
746
 
747
+ //clean array, so if an user rate same field twice, take only the last rating
748
+ $cleaned_array = yasr_unique_multidim_array($rating, 'field');
749
 
750
+ //this is a counter: if at the end of the foreach it still 0, means that an user rated in a set
751
+ //and then submit another one
752
+ $counter_matched_fields = 0;
753
 
754
+ foreach ($cleaned_array as $rating_values) {
 
755
 
756
+ //check if the set id in the array is the same of the clicked
757
+ if ($rating_values['postid'] == $post_id && $rating_values['setid'] == $set_type) {
 
 
 
 
758
 
759
+ //increase the counter
760
+ $counter_matched_fields = $counter_matched_fields + 1;
761
 
762
+ $id_field = $rating_values['field'];
763
+ $rating = $rating_values['rating'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
764
 
765
+ $query_success = $wpdb->insert(
766
+ YASR_LOG_MULTI_SET,
767
+ array(
768
+ 'field_id' => $id_field,
769
+ 'set_type' => $set_type,
770
+ 'post_id' => $post_id,
771
+ 'vote' => $rating,
772
+ 'user_id' => $current_user->ID,
773
+ 'date' => date('Y-m-d H:i:s'),
774
+ 'ip' => $ip_adress
 
 
 
 
775
 
776
+ ),
777
+ array("%d", "%d", "%d", "%d", "%d", "%s", "%s")
778
+ );
779
 
780
+ if ($query_success) {
781
+ $array_error[] = 0;
782
+ } else {
783
+ $array_error[] = 1;
784
+ }
785
 
786
+ } //End if $rating_values['postid'] == $post_id
787
 
788
+ } //End foreach ($rating as $rating_values)
789
 
790
+ if ($counter_matched_fields === 0) {
791
+ $array_error[] = 1;
792
+ }
793
 
794
+ $error_found = false;
795
 
796
+ foreach ($array_error as $error) {
797
+ if ($error === 1) {
798
+ $error_found = true;
 
799
  }
800
+ }
801
 
802
+ if (!$error_found) {
803
+ $cookiename = 'yasr_multi_visitor_cookie';
 
804
 
805
+ $data_to_save = array(
806
+ 'post_id' => $post_id,
807
+ 'set_id' => $set_type
808
+ );
809
 
810
+ yasr_setcookie($cookiename, $data_to_save);
811
 
812
+ _e('Rating saved!', 'yet-another-stars-rating');
813
 
814
+ } else {
815
+ _e('Rating not saved. Please Try again', 'yet-another-stars-rating');
816
+ }
817
 
818
+ die();
819
 
820
+ } //End callback function
821
 
822
 
823
+ add_action( 'wp_ajax_yasr_stats_visitors_votes', 'yasr_stats_visitors_votes_callback' );
824
+ add_action( 'wp_ajax_nopriv_yasr_stats_visitors_votes', 'yasr_stats_visitors_votes_callback' );
825
 
826
+ function yasr_stats_visitors_votes_callback () {
827
 
828
+ if(isset($_POST['post_id']) && $_POST['post_id'] != '' ) {
829
+ $post_id = $_POST['post_id'];
830
+ }
831
 
832
+ else {
833
+ exit();
834
+ }
835
 
836
+ $votes = yasr_get_visitor_votes($post_id);
837
 
838
+ $medium_rating=0; //Avoid undefined variable
839
 
840
+ if (!$votes) {
841
+ $votes=0; //Avoid undefined variable if there is not overall rating
842
+ $votes_number=0; //Avoid undefined variable
843
+ }
844
 
845
+ else {
846
+ foreach ($votes as $user_votes) {
847
+ $votes_number = $user_votes->number_of_votes;
848
+ if ($votes_number != 0 ) {
849
+ $medium_rating = ($user_votes->sum_votes/$votes_number);
850
+ }
851
+ else {
852
+ $medium_rating = 0;
 
853
  }
854
  }
855
+ }
856
 
857
+ $medium_rating=round($medium_rating, 1);
 
 
858
 
859
+ $missing_vote = NULL; //avoid undefined variable
860
 
861
+ global $wpdb;
 
 
 
 
 
 
 
862
 
863
+ $stats = $wpdb->get_results( $wpdb->prepare ("SELECT ROUND( vote, 0 ) as vote, COUNT( vote ) AS n_of_votes
864
+ FROM ". YASR_LOG_TABLE . "
865
+ WHERE post_id=%d
866
+ GROUP BY vote
867
+ ORDER BY vote DESC
868
+ ",
869
+ $post_id ),
870
+ ARRAY_A);
871
 
872
+ $total_votes=0; //Avoid undefined variable if stats exists. Necessary if $stats not exists
 
 
 
873
 
874
+ //if query return 0 write an empty array $existing_votes
875
+ if (!$stats) {
876
+ $existing_votes = array();
877
+ }
 
 
878
 
879
+ else {
880
+ //Write a new array with only existing votes, and count all the number of votes
881
+ foreach ($stats as $votes) {
882
+ $existing_votes[] = $votes['vote'];//Create an array with only existing votes
883
+ $total_votes = $total_votes + $votes['n_of_votes'];
884
  }
885
 
886
+ }
887
 
888
+ for ($i=1; $i<=5; $i++){
 
 
 
 
 
889
 
890
+ //If query return 0 write a new $stats array with index
891
+ if (!$stats) {
892
+ $stats[$i] = array();
893
+ $stats[$i]['vote'] = $i;
894
+ $stats[$i]['n_of_votes'] = 0;
895
+ }
896
 
897
+ else {
 
 
 
 
 
898
 
899
+ //If in the new array there are some vote missing create a new array
900
+ if(!in_array($i, $existing_votes)) {
901
+ $missing_vote[$i] = array();
902
+ $missing_vote[$i]['vote'] = $i;
903
+ $missing_vote[$i]['n_of_votes'] = 0;
904
  }
905
 
906
  }
907
 
908
+ }
 
909
 
910
+ //If missing_vote exists merge it
911
+ if ($missing_vote) {
912
 
913
+ $stats = array_merge($stats, $missing_vote);
914
 
915
+ }
916
 
917
+ arsort($stats); //sort it by $votes[n_of_votes]
918
 
919
+ $html_to_return = '<div class="yasr-visitors-stats-tooltip">';
920
 
921
+ $html_to_return .= '<span id="yasr-medium-rating-tooltip">' . $medium_rating . ' ' . __('out of 5 stars', 'yet-another-stars-rating') . '</span>';
922
 
923
+ $html_to_return .= '<div class="yasr-progress-bars-container">';
924
+
925
+ if ($total_votes == 0) {
926
+ $increase_bar_value = 0;
927
+ }
928
+ else {
929
+ $increase_bar_value = 100 / $total_votes; //Find how much all the bars should increase per vote
930
+ }
931
 
932
+ $i=5;
933
 
934
+ $stars_text = __("stars", 'yet-another-stars-rating');
935
 
936
+ foreach ($stats as $logged_votes) {
937
 
938
+ if ($i==1) {
939
+ $stars_text = __("star", 'yet-another-stars-rating');
940
+ }
941
 
942
+ $value_progressbar = $increase_bar_value * $logged_votes['n_of_votes']; //value of the single bar
943
 
944
+ $value_progressbar = round ($value_progressbar, 2) . '%'; //use only 2 decimal
945
 
946
+ $html_to_return .= "<div class=\"yasr-progress-bar-row-container yasr-w3-container\">
947
+ <div class=\"yasr-progress-bar-name\">$i $stars_text</div>
948
+ <div class='yasr-single-progress-bar-container'>
949
+ <div class=\"yasr-w3-border \">
950
+ <div class=\"yasr-w3-amber\" style=\"height:17px;width:$value_progressbar\"></div>
951
+ </div></div>
952
+ <div class=\"yasr-progress-bar-votes-count\">" . $logged_votes['n_of_votes'] . "</div><br />
953
+ </div>";
954
 
955
+ $i--;
956
 
957
 
958
+ } //End foreach
959
 
960
 
961
+ $html_to_return .= '</div></div>';
962
 
963
+ echo json_encode($html_to_return);
964
 
965
+ die();
966
 
967
+ }
968
 
969
  ?>
lib/yasr-db-functions.php CHANGED
@@ -97,7 +97,6 @@ function yasr_create_tables () {
97
 
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
 
@@ -108,14 +107,14 @@ function yasr_create_tables () {
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,
121
  field_id int(2) NOT NULL,
@@ -123,20 +122,7 @@ function yasr_create_tables () {
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,
131
- post_id bigint(20) NOT NULL,
132
- votes decimal(2,1) NOT NULL,
133
- number_of_votes bigint(20) 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,
@@ -170,7 +156,6 @@ function yasr_create_tables () {
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
  }
176
 
@@ -192,12 +177,12 @@ function yasr_on_delete_blog($tables) {
192
 
193
  $yasr_multi_set_table = $prefix . 'multi_set';
194
  $yasr_multi_set_fields = $prefix . 'multi_set_fields';
195
- $yasr_multi_values_table = $prefix . 'multi_values';
196
  $yasr_log_table = $prefix . 'log';
197
 
198
  $tables[] = $yasr_multi_set_table;
199
  $tables[] = $yasr_multi_set_fields;
200
- $tables[] = $yasr_multi_values_table;
201
  $tables[] = $yasr_log_table;
202
 
203
  return $tables;
@@ -284,7 +269,7 @@ function yasr_get_snippet_type() {
284
  function yasr_get_multi_set() {
285
  global $wpdb;
286
 
287
- $result = $wpdb->get_results("SELECT * FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id ASC");
288
 
289
  return $result;
290
  }
@@ -298,7 +283,10 @@ function yasr_get_multi_set_fields($set_id) {
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;
@@ -398,18 +386,17 @@ function yasr_get_multi_set_visitor($post_id, $set_type) {
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
406
- AND v.post_id = %d
407
- AND v.set_type = %d
408
- AND f.parent_set_id=v.set_type
409
- ORDER BY f.field_id ASC", $set_type, $post_id, $set_type));
410
-
411
- //Should be never empty because first time it's called
412
- //all values are set to 0, just to be safe
413
  if (!empty($result)) {
414
  set_transient('yasr_visitor_multi_set_' . $post_id . '_' . $set_type, $result, WEEK_IN_SECONDS);
415
  }
@@ -468,7 +455,6 @@ function yasr_check_if_user_already_voted($post_id = false) {
468
  global $wpdb;
469
 
470
  $current_user = wp_get_current_user();
471
-
472
  $user_id = $current_user->ID;
473
 
474
  //just to be safe
@@ -481,9 +467,12 @@ function yasr_check_if_user_already_voted($post_id = false) {
481
  }
482
 
483
  $rating = $wpdb->get_var(
484
- $wpdb->prepare("SELECT vote FROM "
485
- . YASR_LOG_TABLE .
486
- " WHERE post_id=%d AND user_id=%d ORDER BY id DESC LIMIT 1 ",
 
 
 
487
  $post_id, $user_id
488
  )
489
  );
@@ -534,7 +523,7 @@ function yasr_widget_log_dashboard_callback() {
534
  $n_rows = $wpdb->get_var("SELECT COUNT(*) FROM " . YASR_LOG_TABLE);
535
 
536
  if (!$log_result) {
537
- _e("No recenet votes yet", 'yet-another-stars-rating');
538
  } else {
539
 
540
  echo "<div class=\"yasr-log-container\" id=\"yasr-log-container\">";
@@ -790,7 +779,7 @@ function yasr_erase_data_on_post_page_remove_callback($pid) {
790
 
791
  //Delete multi value
792
  $wpdb->delete(
793
- YASR_MULTI_SET_VALUES_TABLE,
794
  array(
795
  'post_id' => $pid
796
  ),
97
 
98
  $yasr_multi_set_table = $prefix . 'multi_set';
99
  $yasr_multi_set_fields = $prefix . 'multi_set_fields';
 
100
  $yasr_log_multi_set = $prefix . 'log_multi_set';
101
  $yasr_log_table = $prefix . 'log';
102
 
107
  //but not the yasr tables.
108
 
109
  $sql_yasr_multi_set_table = "CREATE TABLE $yasr_multi_set_table (
110
+ set_id int(2) NOT NULL AUTO_INCREMENT,,
111
  set_name varchar(64) COLLATE utf8_unicode_ci NOT NULL,
112
  UNIQUE KEY set_id (set_id),
113
  UNIQUE KEY set_name (set_name)
114
  ) COLLATE 'utf8_unicode_ci';";
115
 
116
  $sql_yasr_multi_set_fields = "CREATE TABLE $yasr_multi_set_fields (
117
+ id bigint(20) NOT NULL AUTO_INCREMENT,,
118
  parent_set_id int(2) NOT NULL,
119
  field_name varchar(40) COLLATE utf8_unicode_ci NOT NULL,
120
  field_id int(2) NOT NULL,
122
  UNIQUE KEY id (id)
123
  ) COLLATE 'utf8_unicode_ci';";
124
 
125
+ //Since version 2.1.0 is installed but not used yet
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  $sql_yasr_log_multi_set_table = "CREATE TABLE $yasr_log_multi_set (
127
  id bigint(20) NOT NULL AUTO_INCREMENT,
128
  field_id int(2) NOT NULL,
156
  dbDelta($sql_yasr_multi_set_table);
157
  dbDelta($sql_yasr_multi_set_fields);
158
  dbDelta($sql_yasr_log_multi_set_table);
 
159
  dbDelta($sql_yasr_log_table);
160
  }
161
 
177
 
178
  $yasr_multi_set_table = $prefix . 'multi_set';
179
  $yasr_multi_set_fields = $prefix . 'multi_set_fields';
180
+ $yasr_log_multi_set = $prefix . 'log_multi_set';
181
  $yasr_log_table = $prefix . 'log';
182
 
183
  $tables[] = $yasr_multi_set_table;
184
  $tables[] = $yasr_multi_set_fields;
185
+ $tables[] = $yasr_log_multi_set;
186
  $tables[] = $yasr_log_table;
187
 
188
  return $tables;
269
  function yasr_get_multi_set() {
270
  global $wpdb;
271
 
272
+ $result = $wpdb->get_results("SELECT * FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id");
273
 
274
  return $result;
275
  }
283
  $result = $wpdb->get_results($wpdb->prepare(
284
  "SELECT f.field_id AS id, f.field_name AS name
285
  FROM " . YASR_MULTI_SET_FIELDS_TABLE . " AS f
286
+ WHERE f.parent_set_id=%d
287
+ ORDER BY f.field_id
288
+ ", $set_id),
289
+ ARRAY_A);
290
 
291
  if (empty($result)) {
292
  return false;
386
 
387
  global $wpdb;
388
 
389
+ $result = $wpdb->get_results($wpdb->prepare("SELECT f.field_name AS name,
390
+ f.field_id AS id,
391
+ (SUM(l.vote)/COUNT(l.vote)) AS average_rating,
392
+ COUNT(l.vote) AS number_of_votes
393
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . " AS f LEFT JOIN " . YASR_LOG_MULTI_SET . " AS l
394
+ ON l.post_id = %d
395
+ AND f.field_id = l.field_id
396
  WHERE f.parent_set_id=%d
397
+ GROUP BY f.field_name, f.field_id
398
+ ORDER BY f.field_id", $post_id, $set_type));
399
+
 
 
 
 
 
400
  if (!empty($result)) {
401
  set_transient('yasr_visitor_multi_set_' . $post_id . '_' . $set_type, $result, WEEK_IN_SECONDS);
402
  }
455
  global $wpdb;
456
 
457
  $current_user = wp_get_current_user();
 
458
  $user_id = $current_user->ID;
459
 
460
  //just to be safe
467
  }
468
 
469
  $rating = $wpdb->get_var(
470
+ $wpdb->prepare(
471
+ "SELECT vote FROM "
472
+ . YASR_LOG_TABLE .
473
+ " WHERE post_id=%d
474
+ AND user_id=%d
475
+ LIMIT 1 ",
476
  $post_id, $user_id
477
  )
478
  );
523
  $n_rows = $wpdb->get_var("SELECT COUNT(*) FROM " . YASR_LOG_TABLE);
524
 
525
  if (!$log_result) {
526
+ _e("No recent votes yet", 'yet-another-stars-rating');
527
  } else {
528
 
529
  echo "<div class=\"yasr-log-container\" id=\"yasr-log-container\">";
779
 
780
  //Delete multi value
781
  $wpdb->delete(
782
+ YASR_LOG_MULTI_SET,
783
  array(
784
  'post_id' => $pid
785
  ),
lib/yasr-functions.php CHANGED
@@ -227,7 +227,7 @@ function yasr_add_pages() {
227
  add_submenu_page(
228
  'yasr_settings_page',
229
  'Yet Another Stars Rating: All Rating',
230
- 'Logs',
231
  'manage_options',
232
  'yasr_stats_page',
233
  'yasr_stats_page_callback'
@@ -264,7 +264,6 @@ function yasr_stats_page_callback() {
264
  }
265
 
266
  include(YASR_ABSOLUTE_PATH . '/yasr-stats-page.php');
267
-
268
  }
269
 
270
 
@@ -875,7 +874,7 @@ function yasr_unique_multidim_array($array, $key) {
875
  }
876
 
877
 
878
- //Delete caches for wp_super_Cache and wp_rocket
879
  add_action('yasr_action_on_visitor_vote', 'yasr_delete_cache');
880
  add_action('yasr_action_on_visitor_multiset_vote', 'yasr_delete_cache');
881
 
@@ -960,4 +959,39 @@ function yasr_check_valid_url($url) {
960
 
961
  }
962
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
963
  ?>
227
  add_submenu_page(
228
  'yasr_settings_page',
229
  'Yet Another Stars Rating: All Rating',
230
+ 'Stats',
231
  'manage_options',
232
  'yasr_stats_page',
233
  'yasr_stats_page_callback'
264
  }
265
 
266
  include(YASR_ABSOLUTE_PATH . '/yasr-stats-page.php');
 
267
  }
268
 
269
 
874
  }
875
 
876
 
877
+ //Delete caches for supported plugins
878
  add_action('yasr_action_on_visitor_vote', 'yasr_delete_cache');
879
  add_action('yasr_action_on_visitor_multiset_vote', 'yasr_delete_cache');
880
 
959
 
960
  }
961
 
962
+
963
+ /**
964
+ * @since 2.1.0
965
+ *
966
+ * @param $show_average
967
+ * @param $multiset_average
968
+ * @param $multiset_string
969
+ *
970
+ * @return string
971
+ */
972
+
973
+ function yasr_return_average_multiset($show_average, $multiset_average, $multiset_string) {
974
+
975
+ $average_txt = __("Average", "yet-another-stars-rating");
976
+
977
+ //Show average row
978
+ if ($show_average !== false && $show_average !=='no'|| $show_average===false && YASR_MULTI_SHOW_AVERAGE !== 'no') {
979
+ $unique_id_identifier = $multiset_string . str_shuffle(uniqid());
980
+
981
+ $html_average = "<tr>
982
+ <td colspan='2' class='yasr-multiset-average'>
983
+ <div class='yasr-multiset-average'>
984
+ <span class='yasr-multiset-average-text'>$average_txt</span>
985
+ <div class='yasr-rater-stars' id='$unique_id_identifier'
986
+ data-rating='$multiset_average' data-rater-readonly='true'
987
+ data-rater-starsize='24'></div>
988
+ </div>
989
+ </td>
990
+ </tr>";
991
+ }
992
+
993
+ return $html_average;
994
+
995
+ }
996
+
997
  ?>
lib/yasr-shortcode-functions.php CHANGED
@@ -202,7 +202,6 @@ function shortcode_visitor_votes_callback($atts) {
202
 
203
  }
204
 
205
-
206
  $shortcode_html = '<!--Yasr Visitor Votes Shortcode-->';
207
  $shortcode_html .= "<div id=\"yasr_visitor_votes_$post_id\" class=\"yasr-visitor-votes\">";
208
  $span_bottom_line = "";
@@ -424,7 +423,7 @@ function shortcode_multi_set_callback($atts) {
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>
@@ -447,26 +446,11 @@ function shortcode_multi_set_callback($atts) {
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-->';
@@ -484,8 +468,6 @@ function yasr_visitor_multiset_callback($atts) {
484
 
485
  $ajax_nonce_visitor_multiset = wp_create_nonce( "yasr_nonce_insert_visitor_rating_multiset" );
486
 
487
- global $wpdb;
488
-
489
  // Attributes
490
  $atts = shortcode_atts(
491
  array(
@@ -506,12 +488,17 @@ function yasr_visitor_multiset_callback($atts) {
506
  $post_id = get_the_ID();
507
  }
508
 
509
-
510
  $image = YASR_IMG_DIR . "/loader.gif";
511
- $average_txt = __("Average", "yet-another-stars-rating");
512
- $loader_html = "<span class=\"yasr-loader-multiset-visitor\" id=\"yasr-loader-multiset-visitor-$post_id-$setid\" >&nbsp; " . ' <img src=' . "$image" .' title="yasr-loader" alt="yasr-loader"></span>';
513
- $button_html = "<input type=\"submit\" name=\"submit\" id=\"yasr-send-visitor-multiset-$post_id-$setid\" class=\"button button-primary yasr-send-visitor-multiset\" data-postid=\"$post_id\" data-setid=\"$setid\" value=\"" . __('Submit!', 'yet-another-stars-rating') . " \" />";
514
- $button_html_disabled = '<input type="submit" disabled="disabled" class="button button-primary" id="yasr-send-visitor-multiset-disabled" disabled="disabled" value="'.__('Submit!', 'yet-another-stars-rating').'" >';
 
 
 
 
 
 
515
  $yasr_cookiename = 'yasr_multi_visitor_cookie';
516
 
517
  //Check cookie and if voting is allowed only to logged in users
@@ -578,96 +565,53 @@ function yasr_visitor_multiset_callback($atts) {
578
  $set_name_content = yasr_get_multi_set_visitor ($post_id, $setid);
579
 
580
  $shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
581
- $shortcode_html.="<table class=\"yasr_table_multi_set_shortcode\">";
582
-
583
- if ($set_name_content) {
584
- $multiset_vote_sum = 0;//avoid undefined variable
585
- $multiset_rows_number = 0;//avoid undefined variable
586
-
587
- foreach ($set_name_content as $set_content) {
588
- if ($set_content->number_of_votes > 0) {
589
- $average_rating = $set_content->sum_votes / $set_content->number_of_votes;
590
- $average_rating = round($average_rating, 1);
591
- } else {
592
- $average_rating = 0;
593
- }
594
-
595
- $unique_id_identifier = 'yasr-visitor-multi-set-' . $post_id . '_' . $setid . '_' . $set_content->id;
596
- $html_stars = "<div class=\"yasr-multiset-visitors-rater\" id=\"$unique_id_identifier\"
597
- data-rater-postid=\"$post_id\" data-rater-setid=\"$setid\" data-rater-set-field-id=\"$set_content->id\"
598
- data-rating=\"$average_rating\" data-rater-readonly=\"$star_readonly\" ></div>";
599
-
600
- $shortcode_html .="<tr>
601
- <td>
602
- <span class=\"yasr-multi-set-name-field\">$set_content->name </span>
603
- </td>
604
- <td>
605
- $html_stars
606
- <span class=\"yasr-visitor-multiset-vote-count\">$set_content->number_of_votes</span>
607
- </td>
608
- </tr>";
609
 
610
- $multiset_vote_sum = $multiset_vote_sum + $average_rating;
611
- $multiset_rows_number++;
612
-
613
- } //End foreach
614
-
615
- $multiset_average = $multiset_vote_sum / $multiset_rows_number;
616
- $multiset_average = round($multiset_average, 1);
617
 
 
618
  }
619
 
620
- //if this post has no data....
621
- else {
 
622
 
623
- $set_name=$wpdb->get_results($wpdb->prepare("SELECT field_name AS name, field_id AS id
624
- FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
625
- WHERE parent_set_id=%d
626
- ORDER BY field_id ASC", $setid));
627
 
628
- foreach ($set_name as $set_content) {
629
- $unique_id_identifier = 'yasr-visitor-multi-set-' . $post_id . '_' . $setid . '_' . $set_content->id;
630
- $html_stars = "<div class=\"yasr-multiset-visitors-rater\" id=\"$unique_id_identifier\"
631
- data-rater-postid=\"$post_id\" data-rater-setid=\"$setid\" data-rater-set-field-id=\"$set_content->id\"
632
- data-rating=0 data-rater-readonly=\"$star_readonly\" ></div>";
633
 
634
- $shortcode_html .= "<tr>
635
- <td>
636
- <span class=\"yasr-multi-set-name-field\">$set_content->name </span>
637
- </td>
638
- <td>
639
- $html_stars
640
- <span class=\"yasr-visitor-multiset-vote-count\">0</span>
641
- </td>
642
- </tr>";
643
 
644
- } //end foreach ($set_name as $set_content)
 
 
 
 
 
 
 
 
645
 
646
- $multiset_average = 0;
 
647
 
648
- }
649
 
650
- //Show average row
651
- if ($show_average !== false && $show_average !=='no'|| $show_average===false && YASR_MULTI_SHOW_AVERAGE !== 'no') {
652
- $unique_id_identifier = 'yasr-visitor-multi-set-average' . $post_id . '_' . $setid;
653
 
654
- $shortcode_html .= "<tr>
655
- <td colspan=\"2\" class=\"yasr-multiset-average\">
656
- $average_txt
657
- <div class=\"yasr-multiset-visitors-rater\" id=\"$unique_id_identifier\"
658
- data-rater-postid=\"$post_id\" data-rater-setid=\"$setid\"
659
- data-rater-set-field-id=\"$set_content->id\" data-rating=\"$multiset_average\"
660
- data-rater-readonly=\"true\" ></div>
661
- </td>
662
- </tr>";
663
- }
664
 
665
  //Submit row and button
666
  $shortcode_html.="<tr>
667
- <td colspan=\"2\">
668
  $button
669
  $loader_html
670
- <span class=\"yasr-visitor-multiset-message\">$span_message_content</span>
671
  </td>
672
  </tr>
673
  ";
@@ -684,6 +628,7 @@ function yasr_visitor_multiset_callback($atts) {
684
  )
685
  );
686
 
 
687
  return $shortcode_html;
688
 
689
  }
@@ -702,7 +647,7 @@ function yasr_top_ten_highest_rated_callback() {
702
  WHERE pm.post_id = p.ID
703
  AND p.post_status = 'publish'
704
  AND pm.meta_key = 'yasr_overall_rating'
705
- ORDER BY pm.meta_value DESC, pm.post_id ASC LIMIT 10");
706
 
707
 
708
  $shortcode_html = '<!-- Yasr Top 10 highest Rated Shortcode-->';
@@ -714,7 +659,7 @@ function yasr_top_ten_highest_rated_callback() {
714
  $post_title = wp_strip_all_tags(get_the_title($result->post_id));
715
  $link = get_permalink($result->post_id); //Get permalink from post it
716
 
717
- $yasr_top_ten_html_id = 'yasr-top-ten-rater-' . $result->post_id;
718
  $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\"
719
  data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\"
720
  data-rating=\"$result->overall_rating\"></div>";
@@ -764,7 +709,7 @@ function yasr_most_or_highest_rated_posts_callback () {
764
  AND p.post_status = 'publish'
765
  GROUP BY post_id
766
  HAVING number_of_votes > 1
767
- ORDER BY number_of_votes DESC, post_id ASC
768
  LIMIT 10
769
  ");
770
 
@@ -802,7 +747,7 @@ function yasr_most_or_highest_rated_posts_callback () {
802
 
803
  $link = get_permalink($result->post_id); //Get permalink from post it
804
 
805
- $yasr_top_ten_html_id = 'yasr-10-most-rater' . $result->post_id;
806
  $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\" data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\" data-rating=\"$rating\"></div>";
807
 
808
  $shortcode_html .= "<tr>
@@ -843,7 +788,7 @@ function yasr_most_or_highest_rated_posts_callback () {
843
 
844
  $link = get_permalink($result->post_id); //Get permalink from post it
845
 
846
- $yasr_top_ten_html_id = 'yasr-10-highest-rater-' . $result->post_id;
847
  $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\" data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\" data-rating=\"$rating\"></div>";
848
 
849
  $shortcode_html .= "<tr>
@@ -1025,7 +970,7 @@ function yasr_top_ten_active_users_callback () {
1025
 
1026
  //this shortcode is in the plugin but not ready to use yet.
1027
  //that's why there isn't doc about
1028
- add_shortcode ('yasr_highest_rated_visitor_multi_set', 'yasr_highest_rated_visitor_multi_set_callback');
1029
 
1030
  function yasr_highest_rated_visitor_multi_set_callback ($atts) {
1031
 
@@ -1094,6 +1039,6 @@ function yasr_highest_rated_visitor_multi_set_callback ($atts) {
1094
 
1095
  return $shortcode_html;
1096
 
1097
- }
1098
 
1099
  ?>
202
 
203
  }
204
 
 
205
  $shortcode_html = '<!--Yasr Visitor Votes Shortcode-->';
206
  $shortcode_html .= "<div id=\"yasr_visitor_votes_$post_id\" class=\"yasr-visitor-votes\">";
207
  $span_bottom_line = "";
423
 
424
  foreach ($multiset_content as $set_content) {
425
  //Avoid undefined if vote does not exists
426
+ $unique_id_identifier = 'yasr-multiset-' . str_shuffle(uniqid());
427
 
428
  $shortcode_html .= '<tr>
429
  <td>
446
 
447
  }
448
 
449
+ $multiset_average = $multiset_vote_sum / $multiset_rows_number;
450
+ $multiset_average = round($multiset_average, 1);
451
+ $multiset_string = 'yasr-average-multiset-';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
452
 
453
+ $shortcode_html .= yasr_return_average_multiset($show_average, $multiset_average, $multiset_string);
454
 
455
  $shortcode_html.="</table>";
456
  $shortcode_html .= '<!--End Yasr Multi Set Shortcode-->';
468
 
469
  $ajax_nonce_visitor_multiset = wp_create_nonce( "yasr_nonce_insert_visitor_rating_multiset" );
470
 
 
 
471
  // Attributes
472
  $atts = shortcode_atts(
473
  array(
488
  $post_id = get_the_ID();
489
  }
490
 
 
491
  $image = YASR_IMG_DIR . "/loader.gif";
492
+ $loader_html = "<span class='yasr-loader-multiset-visitor' id='yasr-loader-multiset-visitor-$post_id-$setid' >&nbsp;
493
+ <img src='$image' title='yasr-loader' alt='yasr-loader'></span>";
494
+
495
+ $button_html = "<input type='submit' name='submit' id='yasr-send-visitor-multiset-$post_id-$setid'
496
+ class='button button-primary yasr-send-visitor-multiset' data-postid='$post_id' data-setid='$setid'
497
+ value='" . __('Submit!', 'yet-another-stars-rating') . "' />";
498
+
499
+ $button_html_disabled = '<input type="submit" disabled="disabled" class="button button-primary"
500
+ id="yasr-send-visitor-multiset-disabled" disabled="disabled"
501
+ value="'.__('Submit!', 'yet-another-stars-rating').'" >';
502
  $yasr_cookiename = 'yasr_multi_visitor_cookie';
503
 
504
  //Check cookie and if voting is allowed only to logged in users
565
  $set_name_content = yasr_get_multi_set_visitor ($post_id, $setid);
566
 
567
  $shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
 
569
+ if (!$set_name_content) {
570
+ $shortcode_html = __('No MultiSet found with this ID', 'yet-another-stars-rating');
 
 
 
 
 
571
 
572
+ return $shortcode_html;
573
  }
574
 
575
+ $shortcode_html.="<table class=\"yasr_table_multi_set_shortcode\">";
576
+ $multiset_vote_sum = 0;//avoid undefined variable
577
+ $multiset_rows_number = 0;//avoid undefined variable
578
 
579
+ foreach ($set_name_content as $set_content) {
580
+ $average_rating = round($set_content->average_rating, 1);
 
 
581
 
582
+ $unique_id_identifier = 'yasr-visitor-multi-set-' . str_shuffle(uniqid());
 
 
 
 
583
 
584
+ $html_stars = "<div class='yasr-multiset-visitors-rater' id='$unique_id_identifier'
585
+ data-rater-postid='$post_id' data-rater-setid='$setid' data-rater-set-field-id='$set_content->id'
586
+ data-rating='$average_rating' data-rater-readonly='$star_readonly' ></div>";
 
 
 
 
 
 
587
 
588
+ $shortcode_html .="<tr>
589
+ <td>
590
+ <span class=\"yasr-multi-set-name-field\">$set_content->name </span>
591
+ </td>
592
+ <td>
593
+ $html_stars
594
+ <span class=\"yasr-visitor-multiset-vote-count\">$set_content->number_of_votes</span>
595
+ </td>
596
+ </tr>";
597
 
598
+ $multiset_vote_sum = $multiset_vote_sum + $average_rating;
599
+ $multiset_rows_number++;
600
 
601
+ } //End foreach
602
 
603
+ $multiset_average = $multiset_vote_sum / $multiset_rows_number;
604
+ $multiset_average = round($multiset_average, 1);
605
+ $multiset_string = 'yasr-visitor-multi-set-average-';
606
 
607
+ $shortcode_html .= yasr_return_average_multiset($show_average, $multiset_average, $multiset_string);
 
 
 
 
 
 
 
 
 
608
 
609
  //Submit row and button
610
  $shortcode_html.="<tr>
611
+ <td colspan='2'>
612
  $button
613
  $loader_html
614
+ <span class='yasr-visitor-multiset-message'>$span_message_content</span>
615
  </td>
616
  </tr>
617
  ";
628
  )
629
  );
630
 
631
+
632
  return $shortcode_html;
633
 
634
  }
647
  WHERE pm.post_id = p.ID
648
  AND p.post_status = 'publish'
649
  AND pm.meta_key = 'yasr_overall_rating'
650
+ ORDER BY pm.meta_value DESC, pm.post_id LIMIT 10");
651
 
652
 
653
  $shortcode_html = '<!-- Yasr Top 10 highest Rated Shortcode-->';
659
  $post_title = wp_strip_all_tags(get_the_title($result->post_id));
660
  $link = get_permalink($result->post_id); //Get permalink from post it
661
 
662
+ $yasr_top_ten_html_id = 'yasr-top-ten-rater-' . str_shuffle(uniqid());
663
  $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\"
664
  data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\"
665
  data-rating=\"$result->overall_rating\"></div>";
709
  AND p.post_status = 'publish'
710
  GROUP BY post_id
711
  HAVING number_of_votes > 1
712
+ ORDER BY number_of_votes DESC, post_id
713
  LIMIT 10
714
  ");
715
 
747
 
748
  $link = get_permalink($result->post_id); //Get permalink from post it
749
 
750
+ $yasr_top_ten_html_id = 'yasr-10-most-rater' . str_shuffle(uniqid());
751
  $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\" data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\" data-rating=\"$rating\"></div>";
752
 
753
  $shortcode_html .= "<tr>
788
 
789
  $link = get_permalink($result->post_id); //Get permalink from post it
790
 
791
+ $yasr_top_ten_html_id = 'yasr-10-highest-rater-' . str_shuffle(uniqid());
792
  $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\" data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\" data-rating=\"$rating\"></div>";
793
 
794
  $shortcode_html .= "<tr>
970
 
971
  //this shortcode is in the plugin but not ready to use yet.
972
  //that's why there isn't doc about
973
+ /*add_shortcode ('yasr_highest_rated_visitor_multi_set', 'yasr_highest_rated_visitor_multi_set_callback');
974
 
975
  function yasr_highest_rated_visitor_multi_set_callback ($atts) {
976
 
1039
 
1040
  return $shortcode_html;
1041
 
1042
+ }*/
1043
 
1044
  ?>
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.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,6 +125,14 @@ 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.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**
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.4
7
  Requires PHP: 5.3
8
+ Stable tag: 2.1.0
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.0 =
129
+ * TWEAKED: This is the second important release after 2.0.9. YASR Database structure is now more efficent if you're
130
+ using MultiSets. If everything works, it is possible to remove the table _yasr_multi_values.
131
+ * TWEAKED: "logs" page is now called "stats"
132
+ * NEW FEATURE: inside the "stats" page is now possible to see, and delete, stats for yasr_visitor_multiset shortcode
133
+ * TWEAKED: Code cleanup
134
+ **BACKUP YOUR DATABASE BEFORE UPDATING**
135
+
136
  = 2.0.9 =
137
  * TWEAKED: This is the first of two important releases for YASR. Some changes in the database has been done.
138
  **BACKUP YOUR DATABASE BEFORE UPDATING**
yasr-stats-page.php CHANGED
@@ -32,30 +32,27 @@ require(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-stats-functions.php');
32
 
33
  <div class="wrap">
34
 
35
- <h2>Yet Another Stars Rating: <?php _e("Logs", 'yet-another-stars-rating'); ?></h2>
36
 
37
  <?php
38
 
39
  if (isset($_GET['tab'])) {
40
  $active_tab = $_GET['tab'];
41
- }
42
-
43
- else {
44
  $active_tab = 'logs';
45
  }
46
 
47
  //Do the settings tab
48
  yasr_stats_tabs($active_tab);
49
 
50
- if ($active_tab == 'logs' || $active_tab == '') {
51
-
52
  ?>
53
 
54
  <div class="yasr-settingsdiv">
55
  <form action="#" id="" method="POST">
56
  <?php
57
  wp_nonce_field('yasr-delete-stats-logs', 'yasr-nonce-delete-stats-logs');
58
- $yasr_stats_log_table = new YASR_Stats_Log_List_Table();
59
  $yasr_stats_log_table->prepare_items();
60
  $yasr_stats_log_table->display();
61
  ?>
@@ -71,13 +68,35 @@ require(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-stats-functions.php');
71
 
72
  <?php
73
 
 
74
 
75
- } //End if tab 'general_settings'
 
76
 
77
- do_action('yasr_settings_check_active_tab', $active_tab);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- yasr_right_settings_panel('bottom');
80
 
 
 
81
  ?>
82
 
83
  <!--End div wrap-->
32
 
33
  <div class="wrap">
34
 
35
+ <h2>Yet Another Stars Rating: <?php _e("Ratings Stats", 'yet-another-stars-rating'); ?></h2>
36
 
37
  <?php
38
 
39
  if (isset($_GET['tab'])) {
40
  $active_tab = $_GET['tab'];
41
+ } else {
 
 
42
  $active_tab = 'logs';
43
  }
44
 
45
  //Do the settings tab
46
  yasr_stats_tabs($active_tab);
47
 
48
+ if ($active_tab === 'logs' || $active_tab === '') {
 
49
  ?>
50
 
51
  <div class="yasr-settingsdiv">
52
  <form action="#" id="" method="POST">
53
  <?php
54
  wp_nonce_field('yasr-delete-stats-logs', 'yasr-nonce-delete-stats-logs');
55
+ $yasr_stats_log_table = new YASR_Stats_Log_List_Table($active_tab);
56
  $yasr_stats_log_table->prepare_items();
57
  $yasr_stats_log_table->display();
58
  ?>
68
 
69
  <?php
70
 
71
+ } //End if tab 'logs'
72
 
73
+ if ($active_tab === 'logs_multi') {
74
+ ?>
75
 
76
+ <div class="yasr-settingsdiv">
77
+ <form action="#" id="" method="POST">
78
+ <?php
79
+ wp_nonce_field('yasr-delete-stats-logs', 'yasr-nonce-delete-stats-logs');
80
+ $yasr_stats_log_table = new YASR_Stats_Log_List_Table($active_tab);
81
+ $yasr_stats_log_table->prepare_items();
82
+ $yasr_stats_log_table->display();
83
+ ?>
84
+ </form>
85
+ </div>
86
+
87
+ <?php
88
+ yasr_right_settings_panel();
89
+ ?>
90
+
91
+ <div class="yasr-space-settings-div">
92
+ </div>
93
+
94
+ <?php
95
 
96
+ } //End if tab 'general_settings'
97
 
98
+ do_action('yasr_settings_check_active_tab', $active_tab);
99
+ yasr_right_settings_panel('bottom');
100
  ?>
101
 
102
  <!--End div wrap-->
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.9
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.9' );
80
  //Plugin relative path
81
  define( "YASR_ABSOLUTE_PATH", dirname( __FILE__ ) );
82
  //Plugin RELATIVE PATH without slashes (just the directory's name)
@@ -202,7 +202,6 @@ if ( !function_exists( 'yasr_fs' ) ) {
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" );
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.0
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.0' );
80
  //Plugin relative path
81
  define( "YASR_ABSOLUTE_PATH", dirname( __FILE__ ) );
82
  //Plugin RELATIVE PATH without slashes (just the directory's name)
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_LOG_MULTI_SET", $wpdb->prefix . 'yasr_log_multi_set' );
206
  define( "YASR_LOG_TABLE", $wpdb->prefix . 'yasr_log' );
207
  define( "YASR_LOADER_IMAGE", YASR_IMG_DIR . "/loader.gif" );