Yasr – Yet Another Stars Rating - Version 2.2.0

Version Description

  • TWEAKED: most of code of the main shortcodes has been rewritten; YASR is faster than ever.
  • FIXED: gutenberg shortcode preview yasr_top_ten_highest_rated shortcode
Download this release

Release Info

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

Code changes from version 2.1.4 to 2.2.0

js/src/yasr-guten-blocks.js CHANGED
@@ -503,14 +503,12 @@ registerBlockType(
503
  ],
504
 
505
  edit:
506
-
507
  function(props) {
508
-
509
  return (
510
  <Fragment>
511
  <YasrNoSettingsPanel />
512
  <div className={props.className}>
513
- [yasr_most_or_highest_rated_posts]
514
  </div>
515
  </Fragment>
516
  );
503
  ],
504
 
505
  edit:
 
506
  function(props) {
 
507
  return (
508
  <Fragment>
509
  <YasrNoSettingsPanel />
510
  <div className={props.className}>
511
+ [yasr_top_ten_highest_rated]
512
  </div>
513
  </Fragment>
514
  );
js/src/yasr-guten-panel.js CHANGED
@@ -64,7 +64,6 @@ class YasrDivRatingOverall extends React.Component {
64
  )
65
  }
66
 
67
-
68
  render () {
69
  return (
70
  <div>
@@ -146,9 +145,6 @@ class YasrDivIsReview extends React.Component {
146
  super(props);
147
 
148
  let isThisPostReview = wp.data.select('core/editor').getCurrentPost().meta.yasr_post_is_review;
149
-
150
- console.log(isThisPostReview);
151
-
152
  let isThisPostReviewCheckbox = false;
153
 
154
  if (isThisPostReview === 'yes') {
64
  )
65
  }
66
 
 
67
  render () {
68
  return (
69
  <div>
145
  super(props);
146
 
147
  let isThisPostReview = wp.data.select('core/editor').getCurrentPost().meta.yasr_post_is_review;
 
 
 
148
  let isThisPostReviewCheckbox = false;
149
 
150
  if (isThisPostReview === 'yes') {
js/yasr-admin.js CHANGED
@@ -259,6 +259,11 @@ function YasrSettingsPage(activeTab, nMultiSet, autoInsertEnabled, textBeforeSta
259
  return false;
260
  });
261
 
 
 
 
 
 
262
  } //End if general settings
263
 
264
  //--------------Multi Sets Page ------------------
@@ -563,10 +568,8 @@ function yasrShortcodeCreator(nMultiSet) {
563
  jQuery("#content").append(shortcode);
564
 
565
  } else {
566
-
567
  // inserts the shortcode into the active editor
568
  tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode);
569
-
570
  }
571
 
572
  // close
@@ -829,23 +832,26 @@ jQuery(document).ready(function () {
829
 
830
  });
831
 
832
- jQuery(document).ajaxComplete(function () {
833
 
834
- jQuery('.yasr-log-page-num').on('click', function () {
 
 
835
 
836
- jQuery('#yasr-loader-log-metabox').show();
 
837
 
838
- var data = {
839
- action: 'yasr_change_log_page',
840
- pagenum: jQuery(this).val(),
841
- totalpages: jQuery('#yasr-log-total-pages').data('yasr-log-total-pages')
842
- };
843
 
844
- jQuery.post(ajaxurl, data, function (response) {
845
- jQuery('#yasr-log-container').html(response); //This will hide the loader gif too
 
846
  });
847
-
848
- });
849
 
850
  });
851
 
@@ -856,41 +862,41 @@ jQuery(document).ready(function () {
856
  jQuery(document).ready(function () {
857
 
858
  //Log
859
- jQuery('.yasr-user-log-pagenum').on('click', function () {
860
-
861
  jQuery('#yasr-loader-user-log-metabox').show();
862
-
863
  var data = {
864
  action: 'yasr_change_user_log_page',
865
  pagenum: jQuery(this).val(),
866
- totalpages: jQuery('#yasr-user-log-total-pages').data('yasr-user-log-total-pages')
867
 
868
  };
869
-
870
  jQuery.post(ajaxurl, data, function (response) {
871
  jQuery('#yasr-loader-log-metabox').hide();
872
  jQuery('#yasr-user-log-container').html(response);
873
  });
874
-
875
  });
876
 
877
- jQuery(document).ajaxComplete(function () {
878
 
879
- jQuery('.yasr-user-log-page-num').on('click', function () {
 
 
880
 
881
- jQuery('#yasr-loader-user-log-metabox').show();
 
882
 
883
- var data = {
884
- action: 'yasr_change_user_log_page',
885
- pagenum: jQuery(this).val(),
886
- totalpages: jQuery('#yasr-user-log-total-pages').data('yasr-user-log-total-pages')
887
- };
888
 
889
- jQuery.post(ajaxurl, data, function (response) {
890
- jQuery('#yasr-user-log-container').html(response); //This will hide the loader gif too
 
891
  });
892
 
893
- });
894
 
895
  });
896
 
259
  return false;
260
  });
261
 
262
+ jQuery('#yasr-stats-explained-link').on('click', function () {
263
+ jQuery('#yasr-stats-explained').toggle('slow');
264
+ return false;
265
+ });
266
+
267
  } //End if general settings
268
 
269
  //--------------Multi Sets Page ------------------
568
  jQuery("#content").append(shortcode);
569
 
570
  } else {
 
571
  // inserts the shortcode into the active editor
572
  tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode);
 
573
  }
574
 
575
  // close
832
 
833
  });
834
 
835
+ jQuery(document).ajaxComplete(function (event, xhr, settings) {
836
 
837
+ //check if the ajax call is done by yasr with action yasr_change_log_page
838
+ var isYasrAjaxCall = settings.data.search("action=yasr_change_log_page");
839
+ if (isYasrAjaxCall !== -1) {
840
 
841
+ jQuery('.yasr-log-pagenum').on('click', function () {
842
+ jQuery('#yasr-loader-log-metabox').show();
843
 
844
+ var data = {
845
+ action: 'yasr_change_log_page',
846
+ pagenum: jQuery(this).val(),
847
+ totalpages: jQuery('#yasr-log-total-pages').data('yasr-log-total-pages')
848
+ };
849
 
850
+ jQuery.post(ajaxurl, data, function (response) {
851
+ jQuery('#yasr-log-container').html(response); //This will hide the loader gif too
852
+ });
853
  });
854
+ }
 
855
 
856
  });
857
 
862
  jQuery(document).ready(function () {
863
 
864
  //Log
865
+ jQuery('.yasr-user-log-page-num').on('click', function () {
 
866
  jQuery('#yasr-loader-user-log-metabox').show();
 
867
  var data = {
868
  action: 'yasr_change_user_log_page',
869
  pagenum: jQuery(this).val(),
870
+ totalpages: jQuery('#yasr-user-log-total-pages').data('yasr-log-total-pages')
871
 
872
  };
 
873
  jQuery.post(ajaxurl, data, function (response) {
874
  jQuery('#yasr-loader-log-metabox').hide();
875
  jQuery('#yasr-user-log-container').html(response);
876
  });
 
877
  });
878
 
879
+ jQuery(document).ajaxComplete(function (event, xhr, settings) {
880
 
881
+ //check if the ajax call is done by yasr with action yasr_change_log_page
882
+ var isYasrAjaxCall = settings.data.search("action=yasr_change_user_log_page");
883
+ if (isYasrAjaxCall !== -1) {
884
 
885
+ jQuery('.yasr-user-log-page-num').on('click', function () {
886
+ jQuery('#yasr-loader-user-log-metabox').show();
887
 
888
+ var data = {
889
+ action: 'yasr_change_user_log_page',
890
+ pagenum: jQuery(this).val(),
891
+ totalpages: jQuery('#yasr-user-log-total-pages').data('yasr-log-total-pages')
892
+ };
893
 
894
+ jQuery.post(ajaxurl, data, function (response) {
895
+ jQuery('#yasr-user-log-container').html(response); //This will hide the loader gif too
896
+ });
897
  });
898
 
899
+ }
900
 
901
  });
902
 
js/yasr-front.js CHANGED
@@ -65,7 +65,6 @@ document.addEventListener('DOMContentLoaded', function(event) {
65
  function yasrShowHighest () {
66
 
67
  document.getElementById('yasr-most-rated-posts').style.display = 'none';
68
-
69
  document.getElementById('yasr-highest-rated-posts').style.display = '';
70
 
71
  }
@@ -74,7 +73,6 @@ function yasrShowHighest () {
74
  function yasrShowMost () {
75
 
76
  document.getElementById('yasr-highest-rated-posts').style.display = 'none';
77
-
78
  document.getElementById('yasr-most-rated-posts').style.display = '';
79
 
80
  }
65
  function yasrShowHighest () {
66
 
67
  document.getElementById('yasr-most-rated-posts').style.display = 'none';
 
68
  document.getElementById('yasr-highest-rated-posts').style.display = '';
69
 
70
  }
73
  function yasrShowMost () {
74
 
75
  document.getElementById('yasr-highest-rated-posts').style.display = 'none';
 
76
  document.getElementById('yasr-most-rated-posts').style.display = '';
77
 
78
  }
js/yasr-guten-blocks.js CHANGED
@@ -629,7 +629,7 @@ registerBlockType('yet-another-stars-rating/overall-rating-ranking', {
629
  React.createElement(
630
  'div',
631
  { className: props.className },
632
- '[yasr_most_or_highest_rated_posts]'
633
  )
634
  );
635
  },
629
  React.createElement(
630
  'div',
631
  { className: props.className },
632
+ '[yasr_top_ten_highest_rated]'
633
  )
634
  );
635
  },
js/yasr-guten-panel.js CHANGED
@@ -189,9 +189,6 @@ var YasrDivIsReview = function (_React$Component3) {
189
  var _this3 = _possibleConstructorReturn(this, (YasrDivIsReview.__proto__ || Object.getPrototypeOf(YasrDivIsReview)).call(this, props));
190
 
191
  var isThisPostReview = wp.data.select('core/editor').getCurrentPost().meta.yasr_post_is_review;
192
-
193
- console.log(isThisPostReview);
194
-
195
  var isThisPostReviewCheckbox = false;
196
 
197
  if (isThisPostReview === 'yes') {
189
  var _this3 = _possibleConstructorReturn(this, (YasrDivIsReview.__proto__ || Object.getPrototypeOf(YasrDivIsReview)).call(this, props));
190
 
191
  var isThisPostReview = wp.data.select('core/editor').getCurrentPost().meta.yasr_post_is_review;
 
 
 
192
  var isThisPostReviewCheckbox = false;
193
 
194
  if (isThisPostReview === 'yes') {
lib/admin/editor/yasr-metabox-top-right.php CHANGED
@@ -20,13 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
20
 
21
  if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // Exit if accessed directly
22
 
23
- $post_id=get_the_ID();
24
-
25
- $overall_rating=yasr_get_overall_rating($post_id);
26
 
27
- if (!$overall_rating) {
28
- $overall_rating = "0";
29
- }
30
 
31
  $yasr_nonce_overall = wp_nonce_field( "yasr_nonce_overall_rating_action", "yasr_nonce_overall_rating");
32
  $yasr_nonce_auto_insert = wp_nonce_field( "yasr_nonce_auto_insert_action", "yasr_nonce_auto_insert" );
@@ -39,8 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
39
 
40
  <div id="yasr-matabox-top-right">
41
 
42
- <input type="hidden" name="yasr_overall_rating" id="yasr-overall-rating-value" value="<?php echo $overall_rating?>">
43
-
44
  <div id="yasr-vote-overall-stars-container">
45
  <div id="yasr-vote-overall-stars">
46
  <span id="yasr-rateit-vote-overall-text">
20
 
21
  if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // Exit if accessed directly
22
 
23
+ global $post;
 
 
24
 
25
+ $post_id=get_the_ID();
26
+ $overall_rating = $post->yasr_overall_rating;
 
27
 
28
  $yasr_nonce_overall = wp_nonce_field( "yasr_nonce_overall_rating_action", "yasr_nonce_overall_rating");
29
  $yasr_nonce_auto_insert = wp_nonce_field( "yasr_nonce_auto_insert_action", "yasr_nonce_auto_insert" );
36
 
37
  <div id="yasr-matabox-top-right">
38
 
39
+ <input type='hidden' name='yasr_overall_rating' id='yasr-overall-rating-value' value='<?php echo $overall_rating?>'>
 
40
  <div id="yasr-vote-overall-stars-container">
41
  <div id="yasr-vote-overall-stars">
42
  <span id="yasr-rateit-vote-overall-text">
lib/admin/yasr-admin-classes.php ADDED
@@ -0,0 +1,306 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+
5
+ Copyright 2014 Dario Curvino (email : d.curvino@tiscali.it)
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 2 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see <http://www.gnu.org/licenses/>
19
+ */
20
+
21
+ if (!defined('ABSPATH')) {
22
+ exit('You\'re not allowed to see this page');
23
+ } // Exit if accessed directly
24
+
25
+ /**
26
+ * Class YasrLogDashboardWidget
27
+ *
28
+ * Class to print the Dashboard widgets
29
+ *
30
+ */
31
+ class YasrLogDashboardWidget {
32
+ private $limit = 8;
33
+ private $offset = 0;
34
+ private $page_num;
35
+ private $num_of_pages;
36
+ private $n_rows;
37
+ private $log_query;
38
+ private $log_result;
39
+ private $is_ajax = false;
40
+ private $html_to_return;
41
+ private $button_class;
42
+ private $span_loader_id;
43
+ private $user_widget = false;
44
+ private $container_id;
45
+ private $span_total_pages;
46
+
47
+ public function __construct($widget_user) {
48
+ //If $_POST isset it's in ajax response
49
+ if (isset($_POST['pagenum'])) {
50
+ $this->page_num = (int)$_POST['pagenum'];
51
+ $this->num_of_pages = (int)$_POST['totalpages'];
52
+ $this->offset = (int)($this->page_num - 1) * $this->limit;
53
+ $this->is_ajax = true;
54
+
55
+ if ($widget_user === 'admin') {
56
+ $this->adminWidget();
57
+ }
58
+ if ($widget_user === 'user') {
59
+ $this->userWidget();
60
+ }
61
+ } else {
62
+ $this->page_num = 1;
63
+ }
64
+ }
65
+
66
+ /**
67
+ * This function will set the values for print the admin widget logs
68
+ *
69
+ * $this->user_widget
70
+ * $this->n_rows
71
+ * $this->log_query
72
+ * $this->container_id
73
+ * $this->span_total_pages
74
+ * $this->button_class
75
+ * $this->span_loader_id
76
+ *
77
+ */
78
+ public function adminWidget() {
79
+ global $wpdb;
80
+
81
+ //query for admin widget
82
+ $this->n_rows = $wpdb->get_var(
83
+ "SELECT COUNT(*) FROM "
84
+ . YASR_LOG_TABLE
85
+ );
86
+
87
+ $this->log_query = "SELECT * FROM "
88
+ . YASR_LOG_TABLE .
89
+ " ORDER BY date DESC LIMIT %d, %d ";
90
+
91
+ $this->container_id = 'yasr-log-container';
92
+ $this->span_total_pages = 'yasr-log-total-pages';
93
+ $this->button_class = 'yasr-log-pagenum';
94
+ $this->span_loader_id = 'yasr-loader-log-metabox';
95
+
96
+ $this->returnWidget();
97
+ }
98
+
99
+ /**
100
+ * This function will set the values for print the user widget logs
101
+ *
102
+ * $this->user_widget
103
+ * $this->n_rows
104
+ * $this->log_query
105
+ * $this->container_id
106
+ * $this->span_total_pages
107
+ * $this->button_class
108
+ * $this->span_loader_id
109
+ *
110
+ */
111
+ public function userWidget() {
112
+ $user_id = get_current_user_id();
113
+
114
+ //set true to user widget
115
+ $this->user_widget = true;
116
+
117
+ global $wpdb;
118
+
119
+ $this->n_rows = $wpdb->get_var(
120
+ $wpdb->prepare(
121
+ "SELECT COUNT(*) FROM "
122
+ . YASR_LOG_TABLE . " WHERE user_id = %d ",
123
+ $user_id));
124
+
125
+ $this->log_query = "SELECT * FROM "
126
+ . YASR_LOG_TABLE .
127
+ " WHERE user_id = $user_id
128
+ ORDER BY date
129
+ DESC LIMIT %d, %d ";
130
+
131
+ $this->container_id = 'yasr-user-log-container';
132
+ $this->span_total_pages = 'yasr-user-log-total-pages';
133
+ $this->button_class = 'yasr-user-log-page-num';
134
+ $this->span_loader_id = 'yasr-loader-user-log-metabox';
135
+
136
+ $this->returnWidget();
137
+ }
138
+
139
+ /**
140
+ * Print the widget
141
+ */
142
+ private function returnWidget() {
143
+ global $wpdb;
144
+
145
+ if($this->n_rows > 0) {
146
+ $this->num_of_pages = ceil($this->n_rows / $this->limit);
147
+ } else {
148
+ $this->num_of_pages = 1;
149
+ }
150
+
151
+ //do the query
152
+ $this->log_result = $wpdb->get_results(
153
+ $wpdb->prepare(
154
+ $this->log_query,
155
+ $this->offset, $this->limit)
156
+ );
157
+
158
+ if (!$this->log_result) {
159
+ _e("No Recent votes yet", 'yet-another-stars-rating');
160
+ } else {
161
+ $this->html_to_return = "<div class='yasr-log-container' id='$this->container_id'>";
162
+
163
+ foreach ($this->log_result as $column) {
164
+
165
+ $user = get_user_by('id', $column->user_id); //Get info user from user id
166
+
167
+ //If ! user means that the vote are anonymous
168
+ if ($user == false) {
169
+ $user = (object) array('user_login');
170
+ $user->user_login = __('anonymous', 'yet-another-stars-rating');
171
+ }
172
+
173
+ $avatar = get_avatar($column->user_id, '32'); //Get avatar from user id
174
+
175
+ $post_title = wp_strip_all_tags(get_the_title($column->post_id)); //Get post title from post id
176
+ $link = get_permalink($column->post_id); //Get post link from post id
177
+
178
+ if ($this->user_widget !== true) {
179
+ $yasr_log_vote_text = ' ' . sprintf(
180
+ __('Vote %d from %s on', 'yet-another-stars-rating'),
181
+ $column->vote,
182
+ '<strong style="color: blue">' . $user->user_login . '</strong>'
183
+ );
184
+ } else {
185
+ $yasr_log_vote_text = ' ' . sprintf(
186
+ __('You rated %s on', 'yet-another-stars-rating'),
187
+ '<strong style="color: blue">' . $column->vote . '</strong>'
188
+ );
189
+ }
190
+
191
+ //Default values (for admin widget)
192
+ $ip_span = ''; //default value
193
+
194
+ //Set value depending if we're on user or admin widget
195
+ if ($this->user_widget !== true) {
196
+ if (YASR_ENABLE_IP === 'yes') {
197
+ $ip_span = '<span class="yasr-log-ip">' . __("Ip address", 'yet-another-stars-rating') . ':
198
+ <span style="color:blue">' . $column->ip . '</span>
199
+ </span>';
200
+ }
201
+ } else {
202
+ $ip_span = '';
203
+ }
204
+
205
+ $rows_content = '<div class="yasr-log-div-child">
206
+ <div class="yasr-log-image">'
207
+ .$avatar.
208
+ '</div>
209
+ <div class="yasr-log-child-head">
210
+ <span id="yasr-log-vote">'.$yasr_log_vote_text.'</span>
211
+ <span id="yasr-log-post"><a href=&quot;'.$link.'&quot;>'.$post_title.'</a></span>
212
+ </div>
213
+ <div class="yasr-log-ip-date">'
214
+ .$ip_span.
215
+ '<span class="yasr-log-date">'.$column->date.'</span>
216
+ </div>
217
+ </div>';
218
+
219
+ $this->html_to_return .= $rows_content;
220
+
221
+ } //End foreach
222
+
223
+ $this->html_to_return .= "<div id='yasr-log-page-navigation'>";
224
+
225
+ //use data attribute instead of value of #yasr-log-total-pages, because, on ajaxresponse,
226
+ //the "last" button could not exists
227
+ $this->html_to_return .= "<span id='$this->span_total_pages' data-yasr-log-total-pages='$this->num_of_pages'>";
228
+ $this->html_to_return .= __("Pages", 'yet-another-stars-rating') . ": ($this->num_of_pages) &nbsp;&nbsp;&nbsp;";
229
+ $this->html_to_return .= '</span>';
230
+
231
+ $this->pagination();
232
+
233
+ $this->html_to_return .= '</div>'; //End yasr-log-page-navigation
234
+ $this->html_to_return .= '</div>'; //End Yasr Log Container
235
+
236
+ echo $this->html_to_return;
237
+
238
+ } // End else if !$log result
239
+
240
+ if ($this->is_ajax === true) {
241
+ die();
242
+ }
243
+
244
+ }
245
+
246
+ /**
247
+ * This function will print the row with pagination
248
+ */
249
+ private function pagination() {
250
+
251
+ if ($this->num_of_pages <= 3) {
252
+ for ($i = 1; $i <= $this->num_of_pages; $i++) {
253
+ if ($i == $this->page_num) {
254
+ $this->html_to_return .= "<button class='button-primary' value='$i'>$i</button>&nbsp;&nbsp;";
255
+ } else {
256
+ $this->html_to_return .= "<button class=$this->button_class value='$i'>$i</button>&nbsp;&nbsp;";
257
+ }
258
+ }
259
+ $this->html_to_return .= "<span id='yasr-loader-log-metabox' style='display:none;'>&nbsp;
260
+ <img alt='loader' src='" . YASR_IMG_DIR . "/loader.gif' >
261
+ </span>";
262
+ }
263
+ else {
264
+ $start_for = $this->page_num - 1;
265
+
266
+ if ($start_for <= 0) {
267
+ $start_for = 1;
268
+ }
269
+
270
+ $end_for = $this->page_num + 1;
271
+
272
+ if ($end_for >= $this->num_of_pages) {
273
+ $end_for = $this->num_of_pages;
274
+ }
275
+
276
+ if ($this->page_num >= 3) {
277
+ $this->html_to_return .= "<button class=$this->button_class value='1'>
278
+ &laquo; First </button>&nbsp;&nbsp;...&nbsp;&nbsp;";
279
+ }
280
+
281
+ for ($i = $start_for; $i <= $end_for; $i ++) {
282
+ if ($i == $this->page_num) {
283
+ $this->html_to_return .= "<button class='button-primary' value='$i'>$i</button>&nbsp;&nbsp;";
284
+ } else {
285
+ $this->html_to_return .= "<button class=$this->button_class value='$i'>$i</button>&nbsp;&nbsp;";
286
+ }
287
+ }
288
+
289
+ $num_of_page_less_one = $this->num_of_pages - 1;
290
+
291
+ if ($this->page_num != $this->num_of_pages && $this->page_num != $num_of_page_less_one) {
292
+ $this->html_to_return .= "...&nbsp;&nbsp;
293
+ <button class=$this->button_class
294
+ value='$this->num_of_pages'>
295
+ Last &raquo;</button>
296
+ &nbsp;&nbsp;";
297
+ }
298
+
299
+ $this->html_to_return .= "<span id='$this->span_loader_id' style='display:none;' >&nbsp;
300
+ <img alt='loader' src='" . YASR_IMG_DIR . "/loader.gif' >
301
+ </span>";
302
+
303
+ }
304
+
305
+ }
306
+ }
lib/admin/yasr-update-functions.php CHANGED
@@ -210,21 +210,17 @@ function yasr_update_version() {
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");
@@ -259,11 +255,9 @@ function yasr_update_version() {
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
@@ -275,6 +269,16 @@ function yasr_update_version() {
275
 
276
  } //Endif yasr_version_installed !== false
277
 
 
 
 
 
 
 
 
 
 
 
278
  /****** End backward compatibility functions ******/
279
  if ($yasr_version_installed != YASR_VERSION_NUM) {
280
  update_option('yasr-version', YASR_VERSION_NUM);
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
 
215
  $set_with_id_zero_exists = $wpdb->get_results("
216
+ SELECT parent_set_id FROM "
217
  . YASR_MULTI_SET_FIELDS_TABLE .
218
  " WHERE parent_set_id = 0
219
+ LIMIT 1", ARRAY_A
220
  );
221
 
222
+ //if array is not empty
223
+ if (!empty($set_with_id_zero_exists)) {
 
 
224
  $sql_no_auto_increment = $wpdb->query("ALTER TABLE " . YASR_MULTI_SET_NAME_TABLE .
225
  " CHANGE set_id set_id int(2)
226
  NOT NULL FIRST");
255
  if ($yasr_version_installed === '2.0.9' || $yasr_version_installed === '2.1.0'
256
  || $yasr_version_installed === '2.1.1' || $yasr_version_installed === '2.1.2') {
257
 
258
+ $sql_meta_multiset = $wpdb->query('SELECT * FROM ' . $wpdb->postmeta .
 
 
259
  ' WHERE (meta_key LIKE \'%yasr_multiset_author_votes%\'
260
+ OR meta_value LIKE \'%yasr_multiset_author_votes%\')
261
  ');
262
 
263
  //if no meta are found, try to import data again
269
 
270
  } //Endif yasr_version_installed !== false
271
 
272
+ if (version_compare($yasr_version_installed, '2.2.0') === -1) {
273
+ //delete all transient that uses multiset
274
+ $sql_delete_transient_multiset = "
275
+ DELETE FROM {$wpdb->options}
276
+ WHERE option_name LIKE '_transient_yasr_visitor_multi_set_%'
277
+ OR option_name LIKE '_transient_timeout_yasr_visitor_multi_set_%'
278
+ ";
279
+ $wpdb->query($sql_delete_transient_multiset);
280
+ }
281
+
282
  /****** End backward compatibility functions ******/
283
  if ($yasr_version_installed != YASR_VERSION_NUM) {
284
  update_option('yasr-version', YASR_VERSION_NUM);
lib/yasr-ajax-functions.php CHANGED
@@ -19,537 +19,412 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
19
 
20
  */
21
 
22
- if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // Exit if accessed directly
 
 
23
 
24
  /*************************** Admin ajax functions ***********************/
25
 
26
  /********** Functions used while wirting a new post or page ********/
27
 
28
  /****** Get Set name from post or page and output the set,
29
- used in yasr-metabox-multiple-rating******/
30
 
31
- add_action( 'wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback' );
32
 
33
- function yasr_output_multiple_set_callback() {
34
 
35
- if(isset($_POST['set_id']) && isset($_POST['post_id']) && $_POST['post_id'] != '' && $_POST['set_id'] != '' ) {
36
- $set_id = (int)$_POST['set_id'];
37
- $post_id = (int)$_POST['post_id'];
38
- }
39
- else {
40
- exit();
41
- }
42
 
43
- if ( ! current_user_can( 'publish_posts' ) ) {
44
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'yet-another-stars-rating' ) );
45
- }
46
 
47
- yasr_return_multi_set_values_admin($post_id, $set_id);
48
 
49
- die();
50
 
51
- }
52
 
53
 
54
  /****** Create the content for the button shortcode in Tinymce ******/
55
 
56
- //Add ajax action that will be called from the .js for button in tinymce
57
- add_action('wp_ajax_yasr_create_shortcode', 'wp_ajax_yasr_create_shortcode_callback');
58
 
59
- function wp_ajax_yasr_create_shortcode_callback() {
60
- if (isset($_POST['action'])) {
61
- $action=$_POST['action'];
62
- }
63
- else {
64
- exit();
65
- }
66
-
67
- global $wpdb;
68
 
69
- $multi_set=yasr_get_multi_set();
70
 
71
- $n_multi_set=$wpdb->num_rows;
 
72
 
73
- ?>
74
 
75
- <div id="yasr-tinypopup-form">
76
 
77
- <h2 class="nav-tab-wrapper yasr-underline">
78
- <a href="#" id="yasr-link-tab-main" class="nav-tab nav-tab-active yasr-nav-tab"><?php _e("Main", 'yet-another-stars-rating'); ?></a>
79
- <a href="#" id="yasr-link-tab-charts" class="nav-tab yasr-nav-tab"><?php _e("Charts" , 'yet-another-stars-rating'); ?></a>
80
- <?php do_action( 'yasr_add_tabs_on_tinypopupform'); ?>
 
 
81
 
82
- <a href="https://yetanotherstarsrating.com/yasr-basics-shortcode/" target="_blank" id="yasr-tinypopup-link-doc"><?php _e("Read the doc", 'yet-another-stars-rating'); ?></a>
 
83
 
84
- </h2>
85
 
86
- <div id="yasr-content-tab-main" class="yasr-content-tab-tinymce">
87
 
88
- <table id="yasr-table-tiny-popup-main" class="form-table">
89
 
90
- <tr>
91
- <th><label for="yasr-overall"><?php _e("Overall Rating / Review", 'yet-another-stars-rating'); ?></label></th>
92
- <td>
93
- <input type="button" class="button-primary" id="yasr-overall" name="yasr-overall" value="<?php _e("Insert Overall Rating", 'yet-another-stars-rating'); ?>" /><br />
94
- <small><?php _e("Insert Overall Rating / Review for this post", 'yet-another-stars-rating'); ?></small>
 
 
 
95
 
96
- <div id="yasr-overall-choose-size">
97
- <small><?php _e("Choose Size", 'yet-another-stars-rating'); ?><small>
98
  <div class="yasr-tinymce-button-size">
99
- <input type="button" class="button-secondary" id="yasr-overall-insert-small" name="yasr-overall-insert-small" value="<?php _e("Small", 'yet-another-stars-rating'); ?>" />
100
- <input type="button" class="button-secondary" id="yasr-overall-insert-medium" name="yasr-overall-insert-medium" value="<?php _e("Medium", 'yet-another-stars-rating'); ?>" />
101
- <input type="button" class="button-secondary" id="yasr-overall-insert-large" name="yasr-overall-insert-large" value="<?php _e("Large", 'yet-another-stars-rating'); ?>" />
 
 
 
 
 
 
102
  </div>
103
- </div>
104
 
105
- </td>
106
- </tr>
107
 
108
- <tr>
109
- <th><label for="yasr-id"><?php _e("Visitor Votes", 'yet-another-stars-rating'); ?></label></th>
110
- <td>
111
- <input type="button" class="button-primary" name="yasr-visitor-votes" id="yasr-visitor-votes" value="<?php _e("Insert Visitor Votes", 'yet-another-stars-rating'); ?>" /><br />
112
- <small><?php _e("Insert the ability for your visitor to vote", 'yet-another-stars-rating'); ?></small>
 
113
 
114
- <div id="yasr-visitor-choose-size">
115
- <small><?php _e("Choose Size", 'yet-another-stars-rating'); ?><small>
116
  <div class="yasr-tinymce-button-size">
117
- <input type="button" class="button-secondary" id="yasr-visitor-insert-small" name="yasr-visitor-insert-small" value="<?php _e("Small", 'yet-another-stars-rating'); ?>" />
118
- <input type="button" class="button-secondary" id="yasr-visitor-insert-medium" name="yasr-visitor-insert-medium" value="<?php _e("Medium", 'yet-another-stars-rating'); ?>" />
119
- <input type="button" class="button-secondary" id="yasr-visitor-insert-large" name="yasr-visitor-insert-large" value="<?php _e("Large", 'yet-another-stars-rating'); ?>" />
 
 
 
 
 
 
120
  </div>
121
- </div>
122
-
123
- </td>
124
- </tr>
125
-
126
- <?php if ($n_multi_set>1) { //If multiple Set are found ?>
127
-
128
- <tr>
129
- <th><label for="yasr-size"><?php _e("If you want to insert a Multi Set, pick one:", 'yet-another-stars-rating'); ?></label></th>
130
- <td>
131
- <?php foreach ($multi_set as $name) { ?>
132
- <input type="radio" value="<?php echo $name->set_id ?>" name="yasr_tinymce_pick_set" class="yasr_tinymce_select_set"><?php echo $name->set_name ?>
133
- <br />
134
- <?php } //End foreach ?>
135
- <small><?php _e("Choose wich set you want to insert.", 'yet-another-stars-rating'); ?></small>
136
-
137
- <p>
138
- <input type="checkbox" id="yasr-allow-vote-multiset"><?php _e("Readonly?", 'yet-another-stars-rating'); ?><br />
139
- </p>
140
-
141
- <small><?php _e("If Readonly is checked, only you can insert the votes (in the box above the editor)", 'yet-another-stars-rating'); ?></small>
142
-
143
- <p>
144
- <input type="checkbox" id="yasr-hide-average-multiset"><?php _e("Hide Average?", 'yet-another-stars-rating'); ?><br />
145
- </p>
146
-
147
- <p>
148
- <input type="button" class="button-primary" name="yasr-insert-multiset" id="yasr-insert-multiset-select" value="<?php _e("Insert Multi Set", 'yet-another-stars-rating') ?>" /><br />
149
- </p>
150
-
151
- </td>
152
- </tr>
153
-
154
- <?php } //End if
155
-
156
- elseif ($n_multi_set==1) { ?>
157
- <tr>
158
- <th><label for="yasr-size"><?php _e("Insert Multiset:", 'yet-another-stars-rating'); ?></label></th>
159
- <td>
160
- <p>
161
- <input type="checkbox" id="yasr-allow-vote-multiset"><?php _e("Readonly?", 'yet-another-stars-rating'); ?><br />
162
- </p>
163
-
164
- <small><?php _e("If Readonly is checked, only you can insert the votes (in the box above the editor)", 'yet-another-stars-rating'); ?></small>
165
-
166
- <p>
167
- <input type="checkbox" id="yasr-hide-average-multiset"><?php _e("Hide Average?", 'yet-another-stars-rating'); ?><br />
168
- </p>
169
-
170
- <?php foreach ($multi_set as $name) { ?>
171
-
172
- <button type="button" class="button-primary" id="yasr-single-set" name="yasr-single-set" value="<?php echo $name->set_id ?>" ><?php _e("Insert Multiple Set", 'yet-another-stars-rating'); ?></button>
173
-
174
- <?php } //End foreach ?>
175
- </td>
176
- </tr>
177
- <?php
178
- }
179
- //End elseif ?>
180
- </table>
181
-
182
- </div>
183
-
184
- <div id="yasr-content-tab-charts" class="yasr-content-tab-tinymce" style="display:none">
185
-
186
- <table id="yasr-table-tiny-popup-charts" class="form-table">
187
- <tr>
188
- <th><label for="yasr-10-overall"><?php _e("Ranking reviews", 'yet-another-stars-rating'); ?></label></th>
189
- <td><input type="button" class="button-primary" name="yasr-top-10-overall-rating" id="yasr-top-10-overall-rating" value="<?php _e("Insert Ranking reviews", 'yet-another-stars-rating') ?>" /><br />
190
- <small><?php _e("Insert Top 10 ranking for [yasr_overall_rating] shortcode", 'yet-another-stars-rating'); ?></small></td>
191
- </tr>
192
-
193
- <tr>
194
- <th><label for="yasr-10-highest-most-rated"><?php _e("Users' ranking", 'yet-another-stars-rating'); ?></label></th>
195
- <td><input type="button" class="button-primary" name="yasr-10-highest-most-rated" id="yasr-10-highest-most-rated" value="<?php _e("Insert Users ranking", 'yet-another-stars-rating') ?>" /><br />
196
- <small><?php _e("Insert Top 10 ranking for [yasr_visitor_votes] shortcode", 'yet-another-stars-rating'); ?></small></td>
197
- </tr>
198
-
199
- <tr>
200
- <th><label for="yasr-5-active-reviewers"><?php _e("Most active reviewers", 'yet-another-stars-rating'); ?></label></th>
201
- <td><input type="button" class="button-primary" name="yasr-5-active-reviewers" id="yasr-5-active-reviewers" value="<?php _e("Insert Most Active Reviewers", 'yet-another-stars-rating')?> " /><br />
202
- <small><?php _e("Insert Top 5 active reviewers", 'yet-another-stars-rating'); ?></small></td>
203
- </tr>
204
-
205
- <tr>
206
- <th><label for="yasr-10-active-users"><?php _e("Most Active Users", 'yet-another-stars-rating'); ?></label></th>
207
- <td><input type="button" class="button-primary" name="yasr-top-10-active-users" id="yasr-top-10-active-users" value="<?php _e("Insert Most Active Users", 'yet-another-stars-rating') ?>" /><br />
208
- <small><?php _e("Insert Top 10 voters [yasr_visitor_votes] shortcode", 'yet-another-stars-rating'); ?></small></td>
209
- </tr>
210
-
211
- </table>
212
-
213
- </div>
214
-
215
- <?php do_action( 'yasr_add_content_on_tinypopupform'); ?>
216
-
217
- </div>
218
-
219
- <script type="text/javascript">
220
-
221
- jQuery( document ).ready(function() {
222
-
223
- var nMultiSet = <?php echo (json_encode("$n_multi_set")); ?>
224
-
225
- yasrShortcodeCreator(nMultiSet);
226
-
227
-
228
- });
229
-
230
- </script>
231
-
232
- <?php
233
-
234
- die();
235
-
236
- } //End callback function
237
-
238
- /********** END Functions used while wirting a new post or page ********/
239
-
240
-
241
-
242
-
243
- /****** Display recent votes on dashboard, called from function yasr_display_dashboard_log_wiget,
244
- declared on yasr-db-function ******/
245
-
246
-
247
- add_action( 'wp_ajax_yasr_change_log_page', 'yasr_change_log_page_callback' );
248
-
249
- function yasr_change_log_page_callback () {
250
-
251
- if ( ! current_user_can( 'manage_options' ) ) {
252
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'yet-another-stars-rating' ) );
253
- }
254
-
255
- if (isset($_POST['pagenum'])) {
256
-
257
- $page_num = $_POST['pagenum'];
258
- $num_of_pages = $_POST['totalpages'];
259
-
260
- }
261
-
262
- else {
263
- $page_num = 1;
264
- }
265
-
266
- $limit = 8; //max number of row to echo
267
-
268
- $offset = ( $page_num - 1 ) * $limit;
269
-
270
- global $wpdb;
271
-
272
- $log_result = $wpdb->get_results ("SELECT * FROM ". YASR_LOG_TABLE . " ORDER BY date DESC LIMIT $offset, $limit ");
273
-
274
- if (!$log_result) {
275
- _e("No Recenet votes yet", 'yet-another-stars-rating');
276
- }
277
-
278
- else {
279
-
280
- foreach ($log_result as $column) {
281
-
282
- $user = get_user_by( 'id', $column->user_id ); //Get info user from user id
283
-
284
- //If ! user means that the vote are anonymous
285
- if ($user == FALSE) {
286
-
287
- $user = (object) array('user_login');
288
- $user->user_login = __('anonymous');
289
-
290
- }
291
-
292
- $avatar = get_avatar($column->user_id, '32'); //Get avatar from user id
293
-
294
- $title_post = wp_strip_all_tags(get_the_title($column->post_id)); //Get post title from post id
295
- $link = get_permalink( $column->post_id ); //Get post link from post id
296
-
297
- $yasr_log_vote_text = sprintf(__('Vote %d from %s on', 'yet-another-stars-rating'), $column->vote, '<strong style="color: blue">'.$user->user_login.'</strong>' );
298
-
299
- echo "
300
-
301
- <div class=\"yasr-log-div-child\">
302
-
303
- <div class=\"yasr-log-image\">
304
- $avatar
305
- </div>
306
-
307
- <div class=\"yasr-log-child-head\">
308
- <span id=\"yasr-log-vote\">$yasr_log_vote_text<span id=\"yasr-log-post\"><a href=\"$link\"> $title_post</a></span>
309
- </div>
310
-
311
- <div class=\"yasr-log-ip-date\">
312
-
313
- <span class=\"yasr-log-ip\">" . __("Ip address" , 'yet-another-stars-rating') . ": <span style=\"color:blue\">$column->ip</span></span>
314
-
315
- <span class=\"yasr-log-date\">$column->date</span>
316
-
317
- </div>
318
-
319
  </div>
320
 
321
- ";
322
-
323
- } //End foreach
324
-
325
- echo "<div id=\"yasr-log-page-navigation\">";
326
-
327
- //use data attribute instead of value of #yasr-log-total-pages, because, on ajaxresponse,
328
- //the "last" button coul not exists
329
- echo "<span id=\"yasr-log-total-pages\" data-yasr-log-total-pages=\"$num_of_pages\">";
330
-
331
- _e("Pages", 'yet-another-stars-rating'); echo ": ($num_of_pages) &nbsp;&nbsp;&nbsp;";
332
-
333
- echo "</span>";
334
-
335
- if ($num_of_pages <= 3) {
336
-
337
- for ($i=1; $i<=$num_of_pages; $i++) {
338
-
339
- if ($i == $page_num) {
340
- echo "<button class=\"button-primary\" value=\"$i\">$i</button>&nbsp;&nbsp;";
341
- }
342
-
343
- else {
344
- echo "<button class=\"yasr-log-page-num\" value=\"$i\">$i</button>&nbsp;&nbsp;";
345
-
346
- }
347
-
348
- }
349
-
350
- echo "<span id=\"yasr-loader-log-metabox\" style=\"display:none;\">&nbsp;<img src=\"" . YASR_IMG_DIR . "/loader.gif\" ></span>";
351
-
352
- }
353
-
354
- else {
355
-
356
- $start_for = $page_num - 1;
357
-
358
- if ($start_for <= 0) {
359
- $start_for = 1;
360
- }
361
-
362
- $end_for = $page_num + 1;
363
-
364
- if ($end_for >= $num_of_pages) {
365
- $end_for = $num_of_pages;
366
- }
367
-
368
- if ($page_num >= 3) {
369
- echo "<button class=\"yasr-log-page-num\" value=\"1\">&laquo; First </button>&nbsp;&nbsp;...&nbsp;&nbsp;";
370
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
 
372
- for ($i=$start_for; $i<=$end_for; $i++) {
373
 
374
- if ($i == $page_num) {
375
- echo "<button class=\"button-primary\" value=\"$i\">$i</button>&nbsp;&nbsp;";
376
- }
377
 
378
- else {
379
- echo "<button class=\"yasr-log-page-num\" value=\"$i\">$i</button>&nbsp;&nbsp;";
380
- }
 
 
 
 
 
 
 
381
 
382
- }
 
 
 
 
 
 
 
 
 
383
 
384
- $num_of_page_less_one = $num_of_pages-1;
 
 
 
 
 
 
 
 
385
 
386
- if ($page_num != $num_of_pages && $page_num != $num_of_page_less_one) {
387
- echo "...&nbsp;&nbsp;<button class=\"yasr-log-page-num\" value=\"$num_of_pages\">Last &raquo;</button>&nbsp;&nbsp;";
388
- }
 
 
 
 
 
 
 
389
 
390
- echo "<span id=\"yasr-loader-log-metabox\" style=\"display:none;\" >&nbsp;<img src=\"" . YASR_IMG_DIR . "/loader.gif\" ></span>";
391
 
392
- }
393
 
394
- echo "
395
 
396
- </div>
397
 
398
- </div>";
399
 
400
- } // End else if !$log result
401
 
402
- die();
403
 
404
- }
405
 
406
 
407
- add_action( 'wp_ajax_yasr_change_user_log_page', 'yasr_change_user_log_page_callback' );
408
 
 
409
 
410
- function yasr_change_user_log_page_callback () {
411
 
412
- if (isset($_POST['pagenum'])) {
413
 
414
- $page_num = $_POST['pagenum'];
415
- $num_of_pages = $_POST['totalpages'];
416
 
417
- }
418
 
419
- else {
420
- $page_num = 1;
421
- }
422
 
423
- $limit = 8; //max number of row to echo
424
 
425
- $offset = ( $page_num - 1 ) * $limit;
 
 
 
 
 
426
 
427
- $user_id = get_current_user_id();
428
 
429
- global $wpdb;
430
 
431
- $log_result = $wpdb->get_results ("SELECT * FROM ". YASR_LOG_TABLE . " WHERE user_id = $user_id ORDER BY date DESC LIMIT $offset, $limit ");
432
 
433
- if (!$log_result) {
434
- _e("No Recenet votes yet", 'yet-another-stars-rating');
435
- }
436
 
437
- else {
 
 
 
 
 
 
 
 
 
 
 
 
 
438
 
439
- foreach ($log_result as $column) {
440
 
441
- $avatar = get_avatar($user_id, '32'); //Get avatar from user id
442
 
443
- $title_post = wp_strip_all_tags(get_the_title( $column->post_id )); //Get post title from post id
444
- $link = get_permalink( $column->post_id ); //Get post link from post id
445
 
446
- $yasr_log_vote_text = sprintf(__('You rated %s on ', 'yet-another-stars-rating'), '<strong style="color: blue">'.$column->vote.'</strong>');
447
 
448
- echo "
449
 
450
- <div class=\"yasr-log-div-child\">
451
 
452
- <div class=\"yasr-log-image\">
453
  $avatar
454
  </div>
455
 
456
- <div class=\"yasr-log-child-head\">
457
- <span id=\"yasr-log-vote\">$yasr_log_vote_text</span><span class=\"yasr-log-post\"><a href=\"$link\">$title_post</a></span>
458
  </div>
459
 
460
- <div class=\"yasr-log-ip-date\">
461
- <span class=\"yasr-log-ip\">" . __("Ip address" , 'yet-another-stars-rating') . ": <span style=\"color:blue\">$column->ip</span></span>
462
- <span class=\"yasr-log-date\">$column->date</span>
463
  </div>
464
 
465
  </div>
466
 
467
  ";
468
 
469
- } //End foreach
470
-
471
- echo "<div id=\"yasr-log-page-navigation\">";
472
-
473
- //use data attribute instead of value of #yasr-log-total-pages, because, on ajaxresponse,
474
- //the "last" button coul not exists
475
- //This is required on ajax, not here, but still doing it here to take it simple
476
- echo "<span id=\"yasr-user-log-total-pages\" data-yasr-user-log-total-pages=\"$num_of_pages\">";
477
 
478
- _e("Pages", 'yet-another-stars-rating'); echo ": ($num_of_pages) &nbsp;&nbsp;&nbsp;";
479
 
480
- echo "</span>";
 
 
 
481
 
482
- if ($num_of_pages <= 3) {
 
483
 
484
- for ($i=1; $i<=$num_of_pages; $i++) {
485
 
486
- if ($i == $page_num) {
487
- echo "<button class=\"button-primary\" value=\"$i\">$i</button>&nbsp;&nbsp;";
488
- }
489
 
490
- else {
491
- echo "<button class=\"yasr-user-log-page-num\" value=\"$i\">$i</button>&nbsp;&nbsp;";
492
-
493
- }
494
-
495
- }
496
-
497
-
498
- echo "<span id=\"yasr-loader-user-log-metabox\" style=\"display:none;\">&nbsp;<img src=\"" . YASR_IMG_DIR . "/loader.gif\" ></span>";
499
 
500
  }
 
 
 
 
501
 
502
- else {
503
-
504
- $start_for = $page_num - 1;
505
-
506
- if ($start_for <= 0) {
507
- $start_for = 1;
508
- }
509
-
510
- $end_for = $page_num + 1;
511
 
512
- if ($end_for >= $num_of_pages) {
513
- $end_for = $num_of_pages;
514
- }
515
 
516
- if ($page_num >= 3) {
517
- echo "<button class=\"yasr-user-log-page-num\" value=\"1\">&laquo; First </button>&nbsp;&nbsp;...&nbsp;&nbsp;";
518
- }
519
 
520
- for ($i=$start_for; $i<=$end_for; $i++) {
 
 
521
 
522
- if ($i == $page_num) {
523
- echo "<button class=\"button-primary\" value=\"$i\">$i</button>&nbsp;&nbsp;";
524
- }
525
 
526
- else {
527
- echo "<button class=\"yasr-user-log-page-num\" value=\"$i\">$i</button>&nbsp;&nbsp;";
528
- }
 
 
529
 
530
- }
531
 
532
- $num_of_page_less_one = $num_of_pages-1;
533
 
534
- if ($page_num != $num_of_pages && $page_num != $num_of_page_less_one) {
535
- echo "...&nbsp;&nbsp;<button class=\"yasr-user-log-page-num\" value=\"$num_of_pages\">Last &raquo;</button>&nbsp;&nbsp;";
536
- }
537
 
538
- echo "<span id=\"yasr-user-log-container\" style=\"display:none;\" >&nbsp;<img src=\"" . YASR_IMG_DIR . "/loader.gif\" ></span>";
539
 
540
- }
541
 
542
- echo "
543
 
544
  </div>
545
 
546
  </div>";
547
 
548
- } // End else if !$log result
549
 
550
- die();
551
 
552
- }
553
 
554
  /********************* END Admin ajax functions ****************/
555
 
@@ -558,19 +433,19 @@ 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 = (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
 
@@ -582,117 +457,113 @@ function yasr_insert_visitor_votes_callback () {
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,
638
  'user_id' => $current_user->ID,
639
- 'vote' => $rating,
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
 
@@ -704,15 +575,15 @@ function yasr_insert_visitor_votes_callback () {
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)) {
@@ -732,7 +603,7 @@ function yasr_visitor_multiset_field_vote_callback() {
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
 
@@ -765,17 +636,17 @@ function yasr_visitor_multiset_field_vote_callback() {
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;
@@ -820,146 +691,123 @@ function yasr_visitor_multiset_field_vote_callback() {
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();
19
 
20
  */
21
 
22
+ if (!defined('ABSPATH')) {
23
+ exit('You\'re not allowed to see this page');
24
+ } // Exit if accessed directly
25
 
26
  /*************************** Admin ajax functions ***********************/
27
 
28
  /********** Functions used while wirting a new post or page ********/
29
 
30
  /****** Get Set name from post or page and output the set,
31
+ * used in yasr-metabox-multiple-rating******/
32
 
33
+ add_action('wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback');
34
 
35
+ function yasr_output_multiple_set_callback() {
36
 
37
+ if (isset($_POST['set_id']) && isset($_POST['post_id']) && $_POST['post_id'] != '' && $_POST['set_id'] != '') {
38
+ $set_id = (int) $_POST['set_id'];
39
+ $post_id = (int) $_POST['post_id'];
40
+ } else {
41
+ exit();
42
+ }
 
43
 
44
+ if (!current_user_can('publish_posts')) {
45
+ wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
46
+ }
47
 
48
+ yasr_return_multi_set_values_admin($post_id, $set_id);
49
 
50
+ die();
51
 
52
+ }
53
 
54
 
55
  /****** Create the content for the button shortcode in Tinymce ******/
56
 
57
+ //Add ajax action that will be called from the .js for button in tinymce
58
+ add_action('wp_ajax_yasr_create_shortcode', 'wp_ajax_yasr_create_shortcode_callback');
59
 
60
+ function wp_ajax_yasr_create_shortcode_callback() {
61
+ if (isset($_POST['action'])) {
62
+ $action = $_POST['action'];
63
+ } else {
64
+ exit();
65
+ }
 
 
 
66
 
67
+ global $wpdb;
68
 
69
+ $multi_set = yasr_get_multi_set();
70
+ $n_multi_set = $wpdb->num_rows;
71
 
72
+ ?>
73
 
74
+ <div id="yasr-tinypopup-form">
75
 
76
+ <h2 class="nav-tab-wrapper yasr-underline">
77
+ <a href="#" id="yasr-link-tab-main"
78
+ class="nav-tab nav-tab-active yasr-nav-tab"><?php _e("Main", 'yet-another-stars-rating'); ?></a>
79
+ <a href="#" id="yasr-link-tab-charts"
80
+ class="nav-tab yasr-nav-tab"><?php _e("Charts", 'yet-another-stars-rating'); ?></a>
81
+ <?php do_action('yasr_add_tabs_on_tinypopupform'); ?>
82
 
83
+ <a href="https://yetanotherstarsrating.com/yasr-basics-shortcode/" target="_blank"
84
+ id="yasr-tinypopup-link-doc"><?php _e("Read the doc", 'yet-another-stars-rating'); ?></a>
85
 
86
+ </h2>
87
 
88
+ <div id="yasr-content-tab-main" class="yasr-content-tab-tinymce">
89
 
90
+ <table id="yasr-table-tiny-popup-main" class="form-table">
91
 
92
+ <tr>
93
+ <th>
94
+ <label for="yasr-overall"><?php _e("Overall Rating / Review", 'yet-another-stars-rating'); ?></label>
95
+ </th>
96
+ <td>
97
+ <input type="button" class="button-primary" id="yasr-overall" name="yasr-overall"
98
+ value="<?php _e("Insert Overall Rating", 'yet-another-stars-rating'); ?>"/><br/>
99
+ <small><?php _e("Insert Overall Rating / Review for this post", 'yet-another-stars-rating'); ?></small>
100
 
101
+ <div id="yasr-overall-choose-size">
102
+ <small><?php _e("Choose Size", 'yet-another-stars-rating'); ?><small>
103
  <div class="yasr-tinymce-button-size">
104
+ <input type="button" class="button-secondary" id="yasr-overall-insert-small"
105
+ name="yasr-overall-insert-small"
106
+ value="<?php _e("Small", 'yet-another-stars-rating'); ?>"/>
107
+ <input type="button" class="button-secondary" id="yasr-overall-insert-medium"
108
+ name="yasr-overall-insert-medium"
109
+ value="<?php _e("Medium", 'yet-another-stars-rating'); ?>"/>
110
+ <input type="button" class="button-secondary" id="yasr-overall-insert-large"
111
+ name="yasr-overall-insert-large"
112
+ value="<?php _e("Large", 'yet-another-stars-rating'); ?>"/>
113
  </div>
114
+ </div>
115
 
116
+ </td>
117
+ </tr>
118
 
119
+ <tr>
120
+ <th><label for="yasr-id"><?php _e("Visitor Votes", 'yet-another-stars-rating'); ?></label></th>
121
+ <td>
122
+ <input type="button" class="button-primary" name="yasr-visitor-votes" id="yasr-visitor-votes"
123
+ value="<?php _e("Insert Visitor Votes", 'yet-another-stars-rating'); ?>"/><br/>
124
+ <small><?php _e("Insert the ability for your visitor to vote", 'yet-another-stars-rating'); ?></small>
125
 
126
+ <div id="yasr-visitor-choose-size">
127
+ <small><?php _e("Choose Size", 'yet-another-stars-rating'); ?><small>
128
  <div class="yasr-tinymce-button-size">
129
+ <input type="button" class="button-secondary" id="yasr-visitor-insert-small"
130
+ name="yasr-visitor-insert-small"
131
+ value="<?php _e("Small", 'yet-another-stars-rating'); ?>"/>
132
+ <input type="button" class="button-secondary" id="yasr-visitor-insert-medium"
133
+ name="yasr-visitor-insert-medium"
134
+ value="<?php _e("Medium", 'yet-another-stars-rating'); ?>"/>
135
+ <input type="button" class="button-secondary" id="yasr-visitor-insert-large"
136
+ name="yasr-visitor-insert-large"
137
+ value="<?php _e("Large", 'yet-another-stars-rating'); ?>"/>
138
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  </div>
140
 
141
+ </td>
142
+ </tr>
143
+
144
+ <?php if ($n_multi_set > 1) { //If multiple Set are found ?>
145
+
146
+ <tr>
147
+ <th>
148
+ <label for="yasr-size"><?php _e("If you want to insert a Multi Set, pick one:", 'yet-another-stars-rating'); ?></label>
149
+ </th>
150
+ <td>
151
+ <?php foreach ($multi_set as $name) { ?>
152
+ <input type="radio" value="<?php echo $name->set_id ?>" name="yasr_tinymce_pick_set"
153
+ class="yasr_tinymce_select_set"><?php echo $name->set_name ?>
154
+ <br/>
155
+ <?php } //End foreach ?>
156
+ <small><?php _e("Choose wich set you want to insert.", 'yet-another-stars-rating'); ?></small>
157
+
158
+ <p>
159
+ <input type="checkbox"
160
+ id="yasr-allow-vote-multiset"><?php _e("Readonly?", 'yet-another-stars-rating'); ?>
161
+ <br/>
162
+ </p>
163
+
164
+ <small><?php _e("If Readonly is checked, only you can insert the votes (in the box above the editor)", 'yet-another-stars-rating'); ?></small>
165
+
166
+ <p>
167
+ <input type="checkbox"
168
+ id="yasr-hide-average-multiset"><?php _e("Hide Average?", 'yet-another-stars-rating'); ?>
169
+ <br/>
170
+ </p>
171
+
172
+ <p>
173
+ <input type="button" class="button-primary" name="yasr-insert-multiset"
174
+ id="yasr-insert-multiset-select"
175
+ value="<?php _e("Insert Multi Set", 'yet-another-stars-rating') ?>"/><br/>
176
+ </p>
177
+
178
+ </td>
179
+ </tr>
180
+
181
+ <?php } //End if
182
+
183
+ elseif ($n_multi_set == 1) { ?>
184
+ <tr>
185
+ <th><label for="yasr-size"><?php _e("Insert Multiset:", 'yet-another-stars-rating'); ?></label>
186
+ </th>
187
+ <td>
188
+ <p>
189
+ <input type="checkbox"
190
+ id="yasr-allow-vote-multiset"><?php _e("Readonly?", 'yet-another-stars-rating'); ?>
191
+ <br/>
192
+ </p>
193
+
194
+ <small><?php _e("If Readonly is checked, only you can insert the votes (in the box above the editor)", 'yet-another-stars-rating'); ?></small>
195
+
196
+ <p>
197
+ <input type="checkbox"
198
+ id="yasr-hide-average-multiset"><?php _e("Hide Average?", 'yet-another-stars-rating'); ?>
199
+ <br/>
200
+ </p>
201
+
202
+ <?php foreach ($multi_set as $name) { ?>
203
+
204
+ <button type="button" class="button-primary" id="yasr-single-set" name="yasr-single-set"
205
+ value="<?php echo $name->set_id ?>"><?php _e("Insert Multiple Set", 'yet-another-stars-rating'); ?></button>
206
+
207
+ <?php } //End foreach ?>
208
+ </td>
209
+ </tr>
210
+ <?php
211
+ }
212
+ //End elseif ?>
213
+ </table>
214
 
215
+ </div>
216
 
217
+ <div id="yasr-content-tab-charts" class="yasr-content-tab-tinymce" style="display:none">
 
 
218
 
219
+ <table id="yasr-table-tiny-popup-charts" class="form-table">
220
+ <tr>
221
+ <th><label for="yasr-10-overall"><?php _e("Ranking reviews", 'yet-another-stars-rating'); ?></label>
222
+ </th>
223
+ <td><input type="button" class="button-primary" name="yasr-top-10-overall-rating"
224
+ id="yasr-top-10-overall-rating"
225
+ value="<?php _e("Insert Ranking reviews", 'yet-another-stars-rating') ?>"/><br/>
226
+ <small><?php _e("Insert Top 10 ranking for [yasr_overall_rating] shortcode", 'yet-another-stars-rating'); ?></small>
227
+ </td>
228
+ </tr>
229
 
230
+ <tr>
231
+ <th>
232
+ <label for="yasr-10-highest-most-rated"><?php _e("Users' ranking", 'yet-another-stars-rating'); ?></label>
233
+ </th>
234
+ <td><input type="button" class="button-primary" name="yasr-10-highest-most-rated"
235
+ id="yasr-10-highest-most-rated"
236
+ value="<?php _e("Insert Users ranking", 'yet-another-stars-rating') ?>"/><br/>
237
+ <small><?php _e("Insert Top 10 ranking for [yasr_visitor_votes] shortcode", 'yet-another-stars-rating'); ?></small>
238
+ </td>
239
+ </tr>
240
 
241
+ <tr>
242
+ <th>
243
+ <label for="yasr-5-active-reviewers"><?php _e("Most active reviewers", 'yet-another-stars-rating'); ?></label>
244
+ </th>
245
+ <td><input type="button" class="button-primary" name="yasr-5-active-reviewers"
246
+ id="yasr-5-active-reviewers"
247
+ value="<?php _e("Insert Most Active Reviewers", 'yet-another-stars-rating') ?> "/><br/>
248
+ <small><?php _e("Insert Top 5 active reviewers", 'yet-another-stars-rating'); ?></small></td>
249
+ </tr>
250
 
251
+ <tr>
252
+ <th>
253
+ <label for="yasr-10-active-users"><?php _e("Most Active Users", 'yet-another-stars-rating'); ?></label>
254
+ </th>
255
+ <td><input type="button" class="button-primary" name="yasr-top-10-active-users"
256
+ id="yasr-top-10-active-users"
257
+ value="<?php _e("Insert Most Active Users", 'yet-another-stars-rating') ?>"/><br/>
258
+ <small><?php _e("Insert Top 10 voters [yasr_visitor_votes] shortcode", 'yet-another-stars-rating'); ?></small>
259
+ </td>
260
+ </tr>
261
 
262
+ </table>
263
 
264
+ </div>
265
 
266
+ <?php do_action('yasr_add_content_on_tinypopupform'); ?>
267
 
268
+ </div>
269
 
270
+ <script type="text/javascript">
271
 
272
+ jQuery(document).ready(function () {
273
 
274
+ var nMultiSet = <?php echo(json_encode("$n_multi_set")); ?>
275
 
276
+ yasrShortcodeCreator(nMultiSet);
277
 
278
 
279
+ });
280
 
281
+ </script>
282
 
283
+ <?php
284
 
285
+ die();
286
 
287
+ } //End callback function
 
288
 
289
+ /********** END Functions used while wirting a new post or page ********/
290
 
291
+ //add_action('wp_ajax_yasr_change_user_log_page', 'yasr_change_user_log_page_callback');
 
 
292
 
293
+ function yasr_change_user_log_page_callback() {
294
 
295
+ if (isset($_POST['pagenum'])) {
296
+ $page_num = (int)$_POST['pagenum'];
297
+ $num_of_pages = (int)$_POST['totalpages'];
298
+ } else {
299
+ $page_num = 1;
300
+ }
301
 
302
+ $limit = 8; //max number of row to echo
303
 
304
+ $offset = ($page_num - 1) * $limit;
305
 
306
+ $user_id = get_current_user_id();
307
 
308
+ global $wpdb;
 
 
309
 
310
+ $log_result = $wpdb->get_results(
311
+ $wpdb->prepare(
312
+ "SELECT * FROM "
313
+ . YASR_LOG_TABLE .
314
+ " WHERE user_id = %d
315
+ ORDER BY date DESC
316
+ LIMIT %d, %d ",
317
+ $user_id, $offset, $limit
318
+ )
319
+ );
320
+
321
+ if (!$log_result) {
322
+ _e("No Recenet votes yet", 'yet-another-stars-rating');
323
+ } else {
324
 
325
+ foreach ($log_result as $column) {
326
 
327
+ $avatar = get_avatar($user_id, '32'); //Get avatar from user id
328
 
329
+ $title_post = wp_strip_all_tags(get_the_title($column->post_id)); //Get post title from post id
330
+ $link = get_permalink($column->post_id); //Get post link from post id
331
 
332
+ $yasr_log_vote_text = sprintf(__('You rated %s on ', 'yet-another-stars-rating'), '<strong style="color: blue">' . $column->vote . '</strong>');
333
 
334
+ echo "
335
 
336
+ <div class='yasr-log-div-child'>
337
 
338
+ <div class='yasr-log-image'>
339
  $avatar
340
  </div>
341
 
342
+ <div class='yasr-log-child-head'>
343
+ <span id='yasr-log-vote'>$yasr_log_vote_text</span><span class='yasr-log-post'><a href='$link'>$title_post</a></span>
344
  </div>
345
 
346
+ <div class='yasr-log-ip-date'>
347
+ <span class='yasr-log-ip'>" . __("Ip address", 'yet-another-stars-rating') . ": <span style='color:blue'>$column->ip</span></span>
348
+ <span class='yasr-log-date'>$column->date</span>
349
  </div>
350
 
351
  </div>
352
 
353
  ";
354
 
355
+ } //End foreach
 
 
 
 
 
 
 
356
 
357
+ echo "<div id='yasr-log-page-navigation'>";
358
 
359
+ //use data attribute instead of value of #yasr-log-total-pages, because, on ajaxresponse,
360
+ //the "last" button could not exists
361
+ //This is required on ajax, not here, but still doing it here to take it simple
362
+ echo "<span id='yasr-user-log-total-pages' data-yasr-user-log-total-pages='$num_of_pages'>";
363
 
364
+ _e("Pages", 'yet-another-stars-rating');
365
+ echo ": ($num_of_pages) &nbsp;&nbsp;&nbsp;";
366
 
367
+ echo "</span>";
368
 
369
+ if ($num_of_pages <= 3) {
 
 
370
 
371
+ for ($i = 1; $i <= $num_of_pages; $i ++) {
372
+ if ($i == $page_num) {
373
+ echo "<button class='button-primary' value='$i'>$i</button>&nbsp;&nbsp;";
374
+ } else {
375
+ echo "<button class='yasr-user-log-page-num' value='$i'>$i</button>&nbsp;&nbsp;";
 
 
 
 
376
 
377
  }
378
+ }
379
+ echo "<span id='yasr-loader-user-log-metabox' style='display:none;'>&nbsp;<img src='" . YASR_IMG_DIR . "/loader.gif' ></span>";
380
+ } else {
381
+ $start_for = $page_num - 1;
382
 
383
+ if ($start_for <= 0) {
384
+ $start_for = 1;
385
+ }
 
 
 
 
 
 
386
 
387
+ $end_for = $page_num + 1;
 
 
388
 
389
+ if ($end_for >= $num_of_pages) {
390
+ $end_for = $num_of_pages;
391
+ }
392
 
393
+ if ($page_num >= 3) {
394
+ echo "<button class='yasr-user-log-page-num' value='1'>&laquo; First </button>&nbsp;&nbsp;...&nbsp;&nbsp;";
395
+ }
396
 
397
+ for ($i = $start_for; $i <= $end_for; $i ++) {
 
 
398
 
399
+ if ($i == $page_num) {
400
+ echo "<button class='button-primary' value='$i'>$i</button>&nbsp;&nbsp;";
401
+ } else {
402
+ echo "<button class='yasr-user-log-page-num' value='$i'>$i</button>&nbsp;&nbsp;";
403
+ }
404
 
405
+ }
406
 
407
+ $num_of_page_less_one = $num_of_pages - 1;
408
 
409
+ if ($page_num != $num_of_pages && $page_num != $num_of_page_less_one) {
410
+ echo "...&nbsp;&nbsp;<button class='yasr-user-log-page-num' value='$num_of_pages'>Last &raquo;</button>&nbsp;&nbsp;";
411
+ }
412
 
413
+ echo "<span id='yasr-user-log-container' style='display:none;' >&nbsp;<img src='" . YASR_IMG_DIR . "/loader.gif' ></span>";
414
 
415
+ }
416
 
417
+ echo "
418
 
419
  </div>
420
 
421
  </div>";
422
 
423
+ } // End else if !$log result
424
 
425
+ die();
426
 
427
+ }
428
 
429
  /********************* END Admin ajax functions ****************/
430
 
433
 
434
  /****** Yasr insert visitor votes, called from yasr-shortcode-function ******/
435
 
436
+ add_action('wp_ajax_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback');
437
+ add_action('wp_ajax_nopriv_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback');
438
 
439
+ function yasr_insert_visitor_votes_callback() {
440
 
441
+ if (isset($_POST['rating']) && isset($_POST['post_id']) && isset($_POST['nonce_visitor'])) {
442
 
443
+ $rating = (int) $_POST['rating'];
444
+ $post_id = (int) $_POST['post_id'];
445
  $nonce_visitor = $_POST['nonce_visitor'];
446
+ $is_singular = $_POST['is_singular'];
447
 
448
+ if (!is_int($post_id)) {
449
  exit();
450
  }
451
 
457
 
458
  do_action('yasr_action_on_visitor_vote', $array_action_visitor_vote);
459
 
460
+ if (!wp_verify_nonce($nonce_visitor, 'yasr_nonce_insert_visitor_rating')) {
461
+ die('Security check');
462
  }
463
 
464
  if ($rating < 1) {
465
+ $rating = 1;
466
+ } elseif ($rating > 5) {
 
 
 
467
  $rating = 5;
468
  }
469
 
470
  $transient_name = 'yasr_visitor_votes_' . $post_id;
471
 
472
+ delete_transient($transient_name);
473
 
474
  global $wpdb;
475
 
476
  $current_user = wp_get_current_user();
477
+ $ip_adress = yasr_get_ip();
478
 
479
+ $result_update_log = null; //avoid undefined
480
+ $result_insert_log = null; //avoid undefined
481
 
482
  if (is_user_logged_in()) {
483
 
484
  //try to update first, if fails the do the insert
485
+ $result_update_log = $wpdb->update(
486
  YASR_LOG_TABLE,
487
+ array(
488
  'post_id' => $post_id,
489
  'user_id' => $current_user->ID,
490
+ 'vote' => $rating,
491
+ 'date' => date('Y-m-d H:i:s'),
492
+ 'ip' => $ip_adress
493
  ),
494
+ array(
495
  'post_id' => $post_id,
496
  'user_id' => $current_user->ID
497
  ),
498
+ array('%d', '%d', '%d', '%s', '%s', '%s'),
499
+ array('%d', '%d')
500
 
501
  );
502
 
503
  //insert the new row
504
  //use ! instead of === FALSE
505
  if (!$result_update_log) {
506
+ $result_insert_log = $wpdb->insert(
507
  YASR_LOG_TABLE,
508
+ array(
509
  'post_id' => $post_id,
510
  'user_id' => $current_user->ID,
511
+ 'vote' => $rating,
512
+ 'date' => date('Y-m-d H:i:s'),
513
+ 'ip' => $ip_adress
514
  ),
515
+ array('%d', '%d', '%d', '%s', '%s', '%s')
516
  );
517
  }
518
 
519
+ } //if user is not logged in insert
 
 
520
  else {
521
 
522
  //be sure that allow anonymous is on
523
+ if (YASR_ALLOWED_USER === 'allow_anonymous') {
524
+ $result_insert_log = $wpdb->replace(
 
525
  YASR_LOG_TABLE,
526
+ array(
527
  'post_id' => $post_id,
528
  'user_id' => $current_user->ID,
529
+ 'vote' => $rating,
530
+ 'date' => date('Y-m-d H:i:s'),
531
+ 'ip' => $ip_adress
532
  ),
533
 
534
+ array('%d', '%d', '%d', '%s', '%s', '%s')
535
  );
536
+ }
537
 
538
  }
539
 
540
+ if ($result_update_log || $result_insert_log) {
541
 
542
+ $row_exists_obj = new YasrDatabaseRatings();
543
+ $row_exists = $row_exists_obj->getVisitorVotes($post_id, false);
544
 
545
  foreach ($row_exists as $results) {
546
+ $stored_user_votes_sum = $results->sum_votes;
547
  $stored_number_of_votes = $results->number_of_votes;
548
  }
549
 
550
+ $user_votes_sum = $stored_user_votes_sum;
551
  $number_of_votes = $stored_number_of_votes;
552
 
553
  $cookiename = 'yasr_visitor_vote_cookie';
554
 
555
  $data_to_save = array(
556
  'post_id' => $post_id,
557
+ 'rating' => $rating
558
  );
559
 
560
  yasr_setcookie($cookiename, $data_to_save);
561
 
562
+ $total_rating = ($user_votes_sum / $number_of_votes);
563
+ $medium_rating = round($total_rating, 1);
564
 
565
+ $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>";
566
+ $html_to_return .= '<span class="yasr-small-block-bold" id="yasr-vote-saved">' . __('Vote Saved', 'yet-another-stars-rating') . '</span>';
567
 
568
  echo json_encode($html_to_return);
569
 
575
 
576
  /****** Get Multiple value from visitor and insert into db, used in yasr-shortcode-functions ******/
577
 
578
+ add_action('wp_ajax_yasr_visitor_multiset_field_vote', 'yasr_visitor_multiset_field_vote_callback');
579
+ add_action('wp_ajax_nopriv_yasr_visitor_multiset_field_vote', 'yasr_visitor_multiset_field_vote_callback');
580
 
581
  function yasr_visitor_multiset_field_vote_callback() {
582
 
583
  if (isset($_POST['post_id']) && isset($_POST['rating']) && isset($_POST['set_type'])) {
584
+ $post_id = (int) $_POST['post_id'];
585
  $rating = $_POST['rating'];
586
+ $set_type = (int) $_POST['set_type'];
587
  $nonce = $_POST['nonce'];
588
 
589
  if (!is_int($post_id) || !is_int($set_type)) {
603
  }
604
 
605
  $current_user = wp_get_current_user();
606
+ $ip_adress = yasr_get_ip();
607
 
608
  delete_transient('yasr_visitor_multi_set_' . $post_id . '_' . $set_type);
609
 
636
  $query_success = $wpdb->insert(
637
  YASR_LOG_MULTI_SET,
638
  array(
639
+ 'field_id' => $id_field,
640
+ 'set_type' => $set_type,
641
+ 'post_id' => $post_id,
642
+ 'vote' => $rating,
643
+ 'user_id' => $current_user->ID,
644
+ 'date' => date('Y-m-d H:i:s'),
645
+ 'ip' => $ip_adress
646
 
647
  ),
648
  array("%d", "%d", "%d", "%d", "%d", "%s", "%s")
649
+ );
650
 
651
  if ($query_success) {
652
  $array_error[] = 0;
691
  } //End callback function
692
 
693
 
694
+ add_action('wp_ajax_yasr_stats_visitors_votes', 'yasr_stats_visitors_votes_callback');
695
+ add_action('wp_ajax_nopriv_yasr_stats_visitors_votes', 'yasr_stats_visitors_votes_callback');
696
 
697
+ function yasr_stats_visitors_votes_callback() {
698
 
699
+ if (isset($_POST['post_id']) && $_POST['post_id'] !== '') {
700
  $post_id = $_POST['post_id'];
701
+ } else {
702
+ return;
703
  }
704
 
705
+ $visitor_votes_obj = new YasrDatabaseRatings();
706
+ $votes_array = $visitor_votes_obj->getVisitorVotes($post_id);
 
 
 
707
 
708
+ $medium_rating = 0; //Avoid undefined variable
709
 
710
+ if (is_array($votes_array) && !empty($votes_array)) {
711
+ foreach ($votes_array as $user_votes) {
 
 
 
 
 
712
  $votes_number = $user_votes->number_of_votes;
713
+ if ($votes_number != 0) {
714
+ $medium_rating = ($user_votes->sum_votes / $votes_number);
715
+ } else {
 
716
  $medium_rating = 0;
717
  }
718
  }
719
  }
720
 
721
+ $medium_rating = round($medium_rating, 1);
722
+ $missing_vote = null; //avoid undefined variable
 
723
 
724
  global $wpdb;
725
 
726
+ $stats = $wpdb->get_results($wpdb->prepare("SELECT ROUND( vote, 0 ) as vote, COUNT( vote ) AS n_of_votes
727
+ FROM " . YASR_LOG_TABLE . "
728
  WHERE post_id=%d
729
  GROUP BY vote
730
  ORDER BY vote DESC
731
  ",
732
+ $post_id),
733
+ ARRAY_A);
734
 
735
+ $total_votes = 0; //Avoid undefined variable if stats exists. Necessary if $stats not exists
736
 
737
  //if query return 0 write an empty array $existing_votes
738
  if (!$stats) {
739
  $existing_votes = array();
740
+ } else {
 
 
741
  //Write a new array with only existing votes, and count all the number of votes
742
+ foreach ($stats as $votes_array) {
743
+ $existing_votes[] = $votes_array['vote'];//Create an array with only existing votes
744
+ $total_votes = $total_votes + $votes_array['n_of_votes'];
745
  }
746
 
747
  }
748
 
749
+ for ($i = 1; $i <= 5; $i ++) {
 
750
  //If query return 0 write a new $stats array with index
751
  if (!$stats) {
752
+ $stats[$i] = array();
753
+ $stats[$i]['vote'] = $i;
754
  $stats[$i]['n_of_votes'] = 0;
755
+ } else {
 
 
 
756
  //If in the new array there are some vote missing create a new array
757
+ if (!in_array($i, $existing_votes)) {
758
+ $missing_vote[$i] = array();
759
+ $missing_vote[$i]['vote'] = $i;
760
  $missing_vote[$i]['n_of_votes'] = 0;
761
  }
 
762
  }
 
763
  }
764
 
765
  //If missing_vote exists merge it
766
  if ($missing_vote) {
 
767
  $stats = array_merge($stats, $missing_vote);
 
768
  }
769
 
770
  arsort($stats); //sort it by $votes[n_of_votes]
771
 
772
  $html_to_return = '<div class="yasr-visitors-stats-tooltip">';
773
+ $html_to_return .= '<span id="yasr-medium-rating-tooltip">' . $medium_rating . ' '
774
+ . __('out of 5 stars', 'yet-another-stars-rating') .
775
+ '</span>';
776
  $html_to_return .= '<div class="yasr-progress-bars-container">';
777
 
778
  if ($total_votes == 0) {
779
  $increase_bar_value = 0;
780
+ } else {
 
781
  $increase_bar_value = 100 / $total_votes; //Find how much all the bars should increase per vote
782
  }
783
 
784
+ $i = 5;
785
 
786
  $stars_text = __("stars", 'yet-another-stars-rating');
787
 
788
  foreach ($stats as $logged_votes) {
789
 
790
+ if ($i == 1) {
791
  $stars_text = __("star", 'yet-another-stars-rating');
792
  }
793
 
794
  $value_progressbar = $increase_bar_value * $logged_votes['n_of_votes']; //value of the single bar
795
+ $value_progressbar = round($value_progressbar, 2) . '%'; //use only 2 decimal
796
 
797
+ $html_to_return .= "<div class='yasr-progress-bar-row-container yasr-w3-container'>
798
+ <div class='yasr-progress-bar-name'>$i $stars_text</div>
 
 
799
  <div class='yasr-single-progress-bar-container'>
800
+ <div class='yasr-w3-border '>
801
+ <div class='yasr-w3-amber' style='height:17px;width:$value_progressbar'></div>
802
  </div></div>
803
+ <div class='yasr-progress-bar-votes-count'>" . $logged_votes['n_of_votes'] . "</div><br />
804
  </div>";
805
 
806
+ $i --;
 
807
 
808
  } //End foreach
809
 
 
810
  $html_to_return .= '</div></div>';
 
811
  echo json_encode($html_to_return);
812
 
813
  die();
lib/yasr-db-classes.php ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+
5
+ Copyright 2014 Dario Curvino (email : d.curvino@tiscali.it)
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 2 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see <http://www.gnu.org/licenses/>
19
+ */
20
+
21
+ if (!defined('ABSPATH')) {
22
+ exit('You\'re not allowed to see this page');
23
+ } // Exit if accessed directly
24
+
25
+ class YasrDatabaseRatings {
26
+
27
+ /**
28
+ * @param $post_id
29
+ *
30
+ * @return mixed|null
31
+ */
32
+ public function getOverallRating ($post_id=false) {
33
+ //if values it's not passed get the post id, since version 1.6.9 this is just for yasr_add_schema function
34
+ //and for a further check
35
+ if (!is_int($post_id)) {
36
+ $post_id = get_the_ID();
37
+ }
38
+ if (!is_int($post_id)) {
39
+ return null;
40
+ }
41
+ $post_id = (int)$post_id;
42
+
43
+ $overall_rating = get_post_meta($post_id, 'yasr_overall_rating', true);
44
+ if (!$overall_rating) {
45
+ $overall_rating = 0;
46
+ }
47
+ return $overall_rating;
48
+ }
49
+
50
+ /**
51
+ * @param bool|integer $post_id
52
+ * @param bool $create_transient
53
+ *
54
+ * @return array|bool|mixed|object|null
55
+ */
56
+ public function getVisitorVotes ($post_id = false, $create_transient = true) {
57
+ global $wpdb;
58
+
59
+ //if values it's not passed get the post id, most of cases and default one
60
+ if (!is_int($post_id)) {
61
+ $post_id = get_the_ID();
62
+ }
63
+
64
+ if (!is_int($post_id)) {
65
+ return false;
66
+ }
67
+
68
+ $transient_name = 'yasr_visitor_votes_' . $post_id;
69
+ $transient_visitor_votes = get_transient($transient_name);
70
+
71
+ if ($transient_visitor_votes) {
72
+ return $transient_visitor_votes;
73
+ } else {
74
+ $result = $wpdb->get_results(
75
+ $wpdb->prepare(
76
+ "SELECT SUM(vote) AS sum_votes, COUNT(vote) as number_of_votes FROM "
77
+ . YASR_LOG_TABLE .
78
+ " WHERE post_id=%d",
79
+ $post_id
80
+ )
81
+ );
82
+ if ($create_transient === true) {
83
+ set_transient($transient_name, $result, WEEK_IN_SECONDS);
84
+ }
85
+ return $result;
86
+ }
87
+
88
+ }
89
+
90
+ /**
91
+ * Check if an user has already rated, and if so, return the rating, or false otherwise
92
+ *
93
+ * @param int | bool $post_id
94
+ *
95
+ * @return bool|string
96
+ */
97
+ public function visitorVotesHasUserVoted($post_id = false) {
98
+ global $wpdb;
99
+
100
+ $current_user = wp_get_current_user();
101
+ $user_id = $current_user->ID;
102
+
103
+ //just to be safe
104
+ if (!is_int($post_id)) {
105
+ $post_id = get_the_ID();
106
+ }
107
+
108
+ if (!is_int($user_id)) {
109
+ return false;
110
+ }
111
+
112
+ $rating = $wpdb->get_var(
113
+ $wpdb->prepare(
114
+ "SELECT vote FROM "
115
+ . YASR_LOG_TABLE .
116
+ " WHERE post_id=%d
117
+ AND user_id=%d
118
+ LIMIT 1 ",
119
+ $post_id, $user_id
120
+ )
121
+ );
122
+
123
+ if ($rating === null) {
124
+ $rating = false;
125
+ }
126
+ return $rating;
127
+ }
128
+
129
+ }
130
+
131
+ class YasrMultiSetData {
132
+ /**
133
+ * @var array $array_to_return
134
+ */
135
+ protected $array_to_return = array();
136
+
137
+ /**
138
+ * This function returns an multidimensional array of multiset ID and Fields
139
+ * array (
140
+ * array (
141
+ * 'id' => '0',
142
+ * 'name' => 'Field1',
143
+ * ),
144
+ * array (
145
+ * 'id' => '1',
146
+ * 'name' => 'Field2',
147
+ * ),
148
+ * )
149
+ *
150
+ * @param int $set_id
151
+ * @return array|bool|object|null
152
+ */
153
+
154
+ public function multisetFieldsAndID($set_id) {
155
+ if (!is_int($set_id)) {
156
+ return false;
157
+ }
158
+
159
+ global $wpdb;
160
+
161
+ $result = $wpdb->get_results($wpdb->prepare(
162
+ "SELECT f.field_id AS id, f.field_name AS name
163
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . " AS f
164
+ WHERE f.parent_set_id=%d
165
+ ORDER BY f.field_id
166
+ ", $set_id),
167
+ ARRAY_A);
168
+
169
+ if (empty($result)) {
170
+ return false;
171
+ }
172
+
173
+ return $result;
174
+
175
+ }
176
+
177
+ /** This functions returns an array with all the value to print the multiset
178
+ *
179
+ * array (
180
+ * array (
181
+ * 'value_id' => 0,
182
+ * 'value_name' => 'Field 1',
183
+ * 'value_rating' => 3.5,
184
+ * ),
185
+ * array (
186
+ * 'value_id' => 1,
187
+ * 'value_name' => 'Field 2',
188
+ * 'value_rating' => 3,
189
+ * )
190
+ *
191
+ * @param integer $set_id the set id
192
+ * @param array $set_fields an array with fields names and id
193
+ * @param array $set_post_meta_values an array with fields id and rating, can be empty
194
+ *
195
+ * @return bool | array
196
+ */
197
+
198
+ public function returnArrayFieldsRatings($set_id, $set_fields, $set_post_meta_values) {
199
+
200
+ if (!is_int($set_id) || !$set_fields) {
201
+ return false;
202
+ }
203
+
204
+ //index
205
+ $i = 0;
206
+ //always returns field id and name
207
+ foreach ($set_fields as $fields_ids_and_names) {
208
+ $this->array_to_return[$i]['id'] = (int) $fields_ids_and_names['id'];
209
+ $this->array_to_return[$i]['name'] = $fields_ids_and_names['name'];
210
+ $this->array_to_return[$i]['average_rating'] = 0;
211
+
212
+ //if there is post meta
213
+ if ($set_post_meta_values) {
214
+ //first, loop saved fields and ratings
215
+ foreach ($set_post_meta_values as $saved_set_id) {
216
+ //if the saved set is the same selected
217
+ if ($saved_set_id['set_id'] === $set_id) {
218
+ //loop the saved arrays
219
+ foreach ($saved_set_id['fields_and_ratings'] as $single_value) {
220
+ //if field id is the same, add the rating
221
+ if ($this->array_to_return[$i]['id'] === $single_value->field) {
222
+ //save the rating
223
+ $this->array_to_return[$i]['average_rating'] = $single_value->rating;
224
+ }
225
+ }
226
+ }
227
+ }
228
+ }
229
+ //this is for list the set names
230
+ $i ++;
231
+ }
232
+ return $this->array_to_return;
233
+ }
234
+
235
+ /**
236
+ * @param array $multiset_content
237
+ *
238
+ * This get the multiset content, and returns the average
239
+ *
240
+ * @return int|false|float
241
+ */
242
+ public function returnMultiSetAverage($multiset_content) {
243
+ if (!is_array($multiset_content)) {
244
+ return 0;
245
+ }
246
+ //default value
247
+ $multiset_vote_sum = 0;
248
+ $multiset_rows_number = 0;
249
+
250
+ foreach ($multiset_content as $set_content) {
251
+ $multiset_vote_sum = $multiset_vote_sum + $set_content['average_rating'];
252
+ $multiset_rows_number = $multiset_rows_number+1;
253
+ }
254
+ $multiset_average = round($multiset_vote_sum/$multiset_rows_number, 1);
255
+
256
+ return $multiset_average;
257
+ }
258
+
259
+
260
+ /**
261
+ * @param $post_id
262
+ * @param $set_type
263
+ *
264
+ * @return array|mixed|object|null
265
+ */
266
+ public function returnVisitorMultiSet($post_id, $set_type) {
267
+ $post_id = (int)$post_id;
268
+ $set_type = (int)($set_type);
269
+
270
+ $result = get_transient('yasr_visitor_multi_set_' . $post_id . '_' . $set_type);
271
+
272
+ if ($result !== false) {
273
+ return $result;
274
+ }
275
+
276
+ global $wpdb;
277
+
278
+ $result = $wpdb->get_results($wpdb->prepare("SELECT f.field_name AS name,
279
+ f.field_id AS id,
280
+ (SUM(l.vote)/COUNT(l.vote)) AS average_rating,
281
+ COUNT(l.vote) AS number_of_votes
282
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . " AS f LEFT JOIN " . YASR_LOG_MULTI_SET . " AS l
283
+ ON l.post_id = %d
284
+ AND f.field_id = l.field_id
285
+ WHERE f.parent_set_id=%d
286
+ GROUP BY f.field_name, f.field_id
287
+ ORDER BY f.field_id", $post_id, $set_type), ARRAY_A);
288
+
289
+ if (!empty($result)) {
290
+ set_transient('yasr_visitor_multi_set_' . $post_id . '_' . $set_type, $result, WEEK_IN_SECONDS);
291
+ }
292
+
293
+ return $result;
294
+
295
+ }
296
+
297
+ }
lib/yasr-db-functions.php CHANGED
@@ -188,55 +188,6 @@ function yasr_on_delete_blog($tables) {
188
  return $tables;
189
  }
190
 
191
- /*
192
- * Get overall rating from yasr_votes table used in
193
- * yasr_add_filter_for_schema(), yasr_get_id_value_callback()
194
- * and yasr_rest_get_overall_rating
195
- *
196
- * From version 1.9.6 comment out transient, Have to find a way to save transient with
197
- * gutenberg without save_post or ajax action
198
- *
199
- */
200
-
201
- function yasr_get_overall_rating($post_id = false, $create_transient = true) {
202
-
203
- //if values it's not passed get the post id, since version 1.6.9 this is just for yasr_add_schema function
204
- //and for a further check
205
- if (!$post_id) {
206
- $post_id = get_the_ID();
207
- }
208
-
209
- if (!$post_id) {
210
- return null;
211
- }
212
-
213
- $post_id = (int) $post_id;
214
-
215
- //default value
216
- $overall_rating = false;
217
-
218
- /*$transient_name = 'yasr_overall_rating_' . $post_id;
219
-
220
- $transient_overall = get_transient($transient_name);*/
221
-
222
- //if transient exists return it
223
- /*if ($transient_overall) {
224
- return $transient_overall;
225
- } //get value from db
226
- else {*/
227
- $overall_rating = get_post_meta($post_id, 'yasr_overall_rating', true);
228
- //}
229
-
230
- /*if ($overall_rating) {
231
- if ($create_transient === true) {
232
- set_transient($transient_name, $overall_rating, WEEK_IN_SECONDS);
233
- }
234
- }*/
235
-
236
- return $overall_rating;
237
-
238
- }
239
-
240
 
241
  /****** Return the snippet choosen for a post or page ******/
242
  function yasr_get_snippet_type() {
@@ -275,84 +226,7 @@ function yasr_get_multi_set() {
275
  }
276
 
277
 
278
- /****** Get multi set values and field's name, used in ajax function and shortcode function ******/
279
- function yasr_get_multi_set_fields($set_id) {
280
-
281
- global $wpdb;
282
-
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;
293
- }
294
-
295
- return $result;
296
-
297
- }
298
-
299
- /** This functions returns an array with all the value to print the multiset
300
- * @since 2.0.9
301
- *
302
- * @param integer $post_id
303
- * @param integer $set_id the set id
304
- * @param array $set_fields an array with fields names and id
305
- * @param array $set_post_meta_values an array with fields id and rating, can be empty
306
- * @param bool $create_transient
307
- *
308
- * @return bool|array $array_to_return An array with field name, id and rating
309
- */
310
-
311
- function yasr_return_multiset_array_with_ratings ($set_id, $set_fields, $set_post_meta_values) {
312
-
313
- if (!is_int($set_id) || !$set_fields ) {
314
- return false;
315
- }
316
-
317
- //initalize empty array
318
- $array_to_return = array();
319
-
320
- //index
321
- $i = 0;
322
-
323
- //always returns field id and name
324
- foreach ($set_fields as $fields_ids_and_names) {
325
- $array_to_return[$i]['value_id'] = (int)$fields_ids_and_names['id'];
326
- $array_to_return[$i]['value_name'] = $fields_ids_and_names['name'];
327
- $array_to_return[$i]['value_rating'] = 0;
328
-
329
- //if there is post meta
330
- if ($set_post_meta_values) {
331
- //first, loop saved fields and ratings
332
- foreach ($set_post_meta_values as $saved_set_id) {
333
- //if the saved set is the same selected
334
- if ($saved_set_id['set_id'] === $set_id) {
335
- //loop the saved arrays
336
- foreach ($saved_set_id['fields_and_ratings'] as $single_value) {
337
- //if field id is the same, add the rating
338
- if ($array_to_return[$i]['value_id'] === $single_value->field) {
339
- //save the rating
340
- $array_to_return[$i]['value_rating'] = $single_value->rating;
341
- }
342
- }
343
- }
344
- }
345
- }
346
- //this is for list the set names
347
- $i++;
348
- }
349
-
350
- return $array_to_return;
351
-
352
- }
353
-
354
-
355
- /** Output the multi set while edit the page, used in
356
  * yasr-metabox-multiple-rating and yasr-ajax-function
357
  */
358
 
@@ -362,136 +236,27 @@ function yasr_return_multi_set_values_admin($post_id, $set_id) {
362
  exit(__('Missing post or set id', 'yet-another-stars-rating'));
363
  }
364
 
 
 
365
  //set fields name and ids
366
- $set_fields = yasr_get_multi_set_fields($set_id);
367
 
368
  //set meta values
369
  $set_post_meta_values = get_post_meta($post_id, 'yasr_multiset_author_votes', true);
370
-
371
- $array_to_return = yasr_return_multiset_array_with_ratings($set_id, $set_fields, $set_post_meta_values);
372
 
373
  echo json_encode($array_to_return);
374
 
375
  }
376
 
377
 
378
- /****** Get multi set visitor votes ******/
379
- function yasr_get_multi_set_visitor($post_id, $set_type) {
380
-
381
- $result = get_transient('yasr_visitor_multi_set_' . $post_id . '_' . $set_type);
382
-
383
- if ($result !== false) {
384
- return $result;
385
- }
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
- }
403
-
404
- return $result;
405
-
406
- }
407
-
408
-
409
- /****** Get visitor votes ******/
410
- function yasr_get_visitor_votes($post_id = false, $create_transient = true) {
411
-
412
- global $wpdb;
413
-
414
- //if values it's not passed get the post id, most of cases and default one
415
- if (!$post_id) {
416
- $post_id = get_the_ID();
417
- }
418
-
419
- if (!$post_id) {
420
- return false;
421
- }
422
-
423
- $post_id = (int)$post_id;
424
-
425
- $transient_name = 'yasr_visitor_votes_' . $post_id;
426
-
427
- $transient_visitor_votes = get_transient($transient_name);
428
-
429
- if ($transient_visitor_votes) {
430
- return $transient_visitor_votes;
431
- } else {
432
- $result = $wpdb->get_results(
433
- $wpdb->prepare(
434
- "SELECT SUM(vote) AS sum_votes, COUNT(vote) as number_of_votes FROM "
435
- . YASR_LOG_TABLE .
436
- " WHERE post_id=%d",
437
- $post_id
438
- )
439
- );
440
-
441
- if ($create_transient == true) {
442
- set_transient($transient_name, $result, WEEK_IN_SECONDS);
443
- }
444
-
445
- return $result;
446
-
447
- }
448
-
449
- }
450
-
451
- /****** Check if a logged in user has already rated. Return user vote for a post if exists ******/
452
-
453
- function yasr_check_if_user_already_voted($post_id = false) {
454
-
455
- global $wpdb;
456
-
457
- $current_user = wp_get_current_user();
458
- $user_id = $current_user->ID;
459
-
460
- //just to be safe
461
- if (!$post_id) {
462
- $post_id = get_the_ID();
463
- }
464
-
465
- if (!$post_id || !$user_id) {
466
- return false;
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
- );
479
-
480
- if ($rating === null) {
481
- $rating = false;
482
- }
483
-
484
- return $rating;
485
-
486
- }
487
 
488
 
489
  /****** Adding logs widget to the dashboard ******/
490
 
491
- add_action('plugins_loaded', 'add_action_dashboard_widget_log');
492
-
493
- function add_action_dashboard_widget_log() {
494
 
 
495
  //This is for the admins (show all votes in the site)
496
  if (current_user_can('manage_options')) {
497
  add_action('wp_dashboard_setup', 'yasr_add_dashboard_widget_log');
@@ -499,260 +264,38 @@ function add_action_dashboard_widget_log() {
499
 
500
  //This is for all the users to see where they've voted
501
  add_action('wp_dashboard_setup', 'yasr_add_dashboard_widget_user_log');
502
-
503
  }
504
 
505
  function yasr_add_dashboard_widget_log() {
506
-
507
  wp_add_dashboard_widget(
508
  'yasr_widget_log_dashboard', //slug for widget
509
  'Recent Ratings', //widget name
510
  'yasr_widget_log_dashboard_callback' //function callback
511
  );
512
-
513
  }
514
 
515
- function yasr_widget_log_dashboard_callback() {
516
-
517
- $limit = 8; //max number of row to echo
518
-
519
- global $wpdb;
520
-
521
- $log_result = $wpdb->get_results("SELECT * FROM " . YASR_LOG_TABLE . " ORDER BY date DESC LIMIT 0, $limit");
522
-
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\">";
530
-
531
- foreach ($log_result as $column) {
532
-
533
- $user = get_user_by('id', $column->user_id);
534
-
535
- //If ! user means that the vote are anonymous
536
- if ($user == false) {
537
- $user = (object) array('user_login');
538
- $user->user_login = __('anonymous');
539
- }
540
-
541
- $avatar = get_avatar($column->user_id, '32');
542
-
543
- $title_post = wp_strip_all_tags(get_the_title($column->post_id));
544
- $link = get_permalink($column->post_id);
545
-
546
- $yasr_log_vote_text =
547
- sprintf(
548
- __('Vote %d from %s on', 'yet-another-stars-rating'),
549
- $column->vote, '<strong style="color: blue">' . $user->user_login . '</strong>'
550
- );
551
-
552
- if (YASR_ENABLE_IP !== 'yes') {
553
- $column->ip = 'X.X.X.X';
554
- }
555
-
556
- echo "
557
- <div class='yasr-log-div-child'>
558
-
559
- <div class='yasr-log-image'>
560
- $avatar
561
- </div>
562
-
563
- <div class='yasr-log-child-head\'>
564
- <span id='yasr-log-vote'>$yasr_log_vote_text</span>
565
- <span class='yasr-log-post'>
566
- <a href='$link'> $title_post</a>
567
- </span>
568
- </div>
569
-
570
- <div class='yasr-log-ip-date'>
571
- <span class='yasr-log-ip'>"
572
- . __('Ip address', 'yet-another-stars-rating') .
573
- ": <span style=\"color:blue\">$column->ip</span>
574
- </span>
575
- <span class='yasr-log-date'>$column->date</span>
576
- </div>
577
-
578
- </div>";
579
-
580
- } //End foreach
581
-
582
- echo "<div id=\"yasr-log-page-navigation\">";
583
-
584
- $num_of_pages = ceil($n_rows / $limit);
585
-
586
- //use data attribute instead of value of #yasr-log-total-pages, because, on ajaxresponse,
587
- //the "last" button could not exists
588
- //This is required on ajax, not here, but still doing it here to take it simple
589
- echo "<span id=\"yasr-log-total-pages\" data-yasr-log-total-pages=\"$num_of_pages\">";
590
-
591
- _e("Pages", 'yet-another-stars-rating');
592
- echo ": ($num_of_pages) &nbsp;&nbsp;&nbsp;";
593
-
594
- echo "</span>";
595
-
596
- if ($num_of_pages <= 3) {
597
-
598
- for ($i = 1; $i <= $num_of_pages; $i ++) {
599
-
600
- if ($i == 1) {
601
- echo "<button class=\"button-primary\" value=\"$i\">$i</button>&nbsp;&nbsp;";
602
- } else {
603
- echo "<button class=\"yasr-log-pagenum\" value=\"$i\">$i</button>&nbsp;&nbsp;";
604
- }
605
-
606
- }
607
-
608
- echo "<span id=\"yasr-loader-log-metabox\" style=\"display:none;\">&nbsp;<img src=\"" . YASR_IMG_DIR . "/loader.gif\" ></span>";
609
-
610
- } else {
611
-
612
- for ($i = 1; $i <= 3; $i ++) {
613
-
614
- if ($i == 1) {
615
- echo "<button class=\"button-primary\" value=\"$i\">$i</button>&nbsp;&nbsp;";
616
- } else {
617
- echo "<button class=\"yasr-log-pagenum\" value=\"$i\">$i</button>&nbsp;&nbsp;";
618
- }
619
-
620
- }
621
-
622
- echo "...&nbsp;&nbsp;<button class=\"yasr-log-pagenum\" id=\"yasr-log-total-pages\" value=\"$num_of_pages\">Last &raquo;</button>&nbsp;&nbsp;";
623
-
624
- echo "<span id=\"yasr-loader-log-metabox\" style=\"display:none;\">&nbsp;<img src=\"" . YASR_IMG_DIR . "/loader.gif\" ></span>";
625
-
626
- }
627
-
628
- echo "
629
- </div>
630
- </div>";
631
-
632
- } //End else
633
-
634
- } //End callback function
635
-
636
  //This add a dashboard log for every users
637
- //Add action is above
638
  function yasr_add_dashboard_widget_user_log() {
639
-
640
  wp_add_dashboard_widget(
641
  'yasr_users_dashboard_widget', //slug for widget
642
  'Your Ratings', //widget name
643
  'yasr_users_dashboard_widget_callback' //function callback
644
  );
645
-
646
  }
647
 
 
 
 
 
 
 
648
 
649
- function yasr_users_dashboard_widget_callback() {
650
-
651
- $limit = 8; //max number of row to echo
652
-
653
- //Get current user id: don't need to check if is >0 cause user is logged in here
654
- $user_id = get_current_user_id();
655
-
656
- global $wpdb;
657
-
658
- $log_result = $wpdb->get_results("SELECT * FROM " . YASR_LOG_TABLE . " WHERE user_id = $user_id ORDER BY date DESC LIMIT 0, $limit");
659
-
660
- $n_rows = $wpdb->get_var("SELECT COUNT(*) FROM " . YASR_LOG_TABLE . " WHERE user_id = $user_id");
661
-
662
- if (!$log_result) {
663
- _e("No recenet votes yet", 'yet-another-stars-rating');
664
- } else {
665
-
666
- echo "<div class=\"yasr-log-container\" id=\"yasr-user-log-container\">";
667
-
668
- foreach ($log_result as $column) {
669
-
670
- $avatar = get_avatar($user_id, '32');
671
-
672
- $title_post = wp_strip_all_tags(get_the_title($column->post_id));
673
- $link = get_permalink($column->post_id);
674
-
675
- $yasr_log_vote_text = sprintf(__('You rated %s on ', 'yet-another-stars-rating'), '<strong style="color: blue">' . $column->vote . '</strong>');
676
- $yasr_log_date_text = __('Date:', 'yet-another-stars-rating');
677
-
678
- echo "
679
- <div class=\"yasr-log-div-child\" style=\"padding-bottom: 2px;\" >
680
-
681
- <div class=\"yasr-log-image\">
682
- $avatar
683
- </div>
684
-
685
- <div class=\"yasr-log-child-head\">
686
- <span id=\"yasr-log-vote\">$yasr_log_vote_text</span>
687
- <span class=\"yasr-log-post\">
688
- <a href=\"$link\">$title_post</a>
689
- </span>
690
- </div>
691
-
692
- <div class=\"yasr-log-child-head\">
693
- <strong>$yasr_log_date_text</strong>
694
- <span class=\"yasr-log-date-user\">$column->date</span>
695
- </div>
696
-
697
- </div>";
698
-
699
- } //End foreach
700
-
701
- echo "<div id=\"yasr-log-page-navigation\">";
702
-
703
- $num_of_pages = ceil($n_rows / $limit);
704
-
705
- //use data attribute instead of value of #yasr-log-total-pages, because, on ajaxresponse,
706
- //the "last" button coul not exists
707
- //This is required on ajax, not here, but still doing it here to take it simple
708
- echo "<span id=\"yasr-user-log-total-pages\" data-yasr-user-log-total-pages=\"$num_of_pages\">";
709
-
710
- _e("Pages", 'yet-another-stars-rating');
711
- echo ": ($num_of_pages) &nbsp;&nbsp;&nbsp;";
712
-
713
- echo "</span>";
714
-
715
- if ($num_of_pages <= 3) {
716
-
717
- for ($i = 1; $i <= $num_of_pages; $i ++) {
718
-
719
- if ($i == 1) {
720
- echo "<button class=\"button-primary\" value=\"$i\">$i</button>&nbsp;&nbsp;";
721
- } else {
722
- echo "<button class=\"yasr-user-log-pagenum\" value=\"$i\">$i</button>&nbsp;&nbsp;";
723
-
724
- }
725
-
726
- }
727
-
728
- echo "<span id=\"yasr-loader-user-log-metabox\" style=\"display:none;\">&nbsp;<img src=\"" . YASR_IMG_DIR . "/loader.gif\" ></span>";
729
-
730
- } else {
731
-
732
- for ($i = 1; $i <= 3; $i ++) {
733
-
734
- if ($i == 1) {
735
- echo "<button class=\"button-primary\" value=\"$i\">$i</button>&nbsp;&nbsp;";
736
- } else {
737
- echo "<button class=\"yasr-user-log-pagenum\" value=\"$i\">$i</button>&nbsp;&nbsp;";
738
- }
739
-
740
- }
741
-
742
- echo "...&nbsp;&nbsp;<button class=\"yasr-user-log-pagenum\" id=\"yasr-user-log-total-pages\" value=\"$num_of_pages\">Last &raquo;</button>&nbsp;&nbsp;";
743
-
744
- echo "<span id=\"yasr-loader-user-log-metabox\" style=\"display:none;\">&nbsp;<img src=\"" . YASR_IMG_DIR . "/loader.gif\" ></span>";
745
-
746
- }
747
-
748
- echo "
749
-
750
- </div>
751
-
752
- </div>";
753
-
754
- } //End else
755
 
 
 
 
 
 
756
  } //End callback function
757
 
758
 
@@ -881,30 +424,43 @@ function yasr_insert_overall_rating_callback($post_id) {
881
  add_action('save_post', 'yasr_insert_review_type_callback');
882
 
883
  function yasr_insert_review_type_callback($post_id) {
 
 
 
 
884
 
885
  //this mean there we're not in the classic editor
886
  if(!isset($_POST['yasr_nonce_review_type'])) {
887
  return;
888
- }
889
-
890
- if (isset($_POST['yasr-review-type'])) {
891
- $snippet_type = $_POST['yasr-review-type'];
892
- $nonce = $_POST['yasr_nonce_review_type'];
893
  } else {
894
- return;
895
- }
896
-
897
- if (!current_user_can('publish_posts')) {
898
- wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
899
  }
900
 
 
901
  if (!wp_verify_nonce($nonce, 'yasr_nonce_review_type_action')) {
902
  return;
903
  }
904
 
905
  $post_id = (int)$post_id;
906
 
907
- update_post_meta($post_id, 'yasr_review_type', $snippet_type);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
908
 
909
  }
910
 
@@ -995,8 +551,6 @@ function yasr_save_multiset_editor($post_id) {
995
  // Write new data
996
  update_post_meta($post_id, 'yasr_multiset_author_votes', $data_to_save);
997
 
998
-
999
-
1000
  } //End callback function
1001
 
1002
  /******* Add post_meta on save_post if this post is excluded for auto insert *******/
188
  return $tables;
189
  }
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
 
192
  /****** Return the snippet choosen for a post or page ******/
193
  function yasr_get_snippet_type() {
226
  }
227
 
228
 
229
+ /** Output the multi set while editing the page, used in
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  * yasr-metabox-multiple-rating and yasr-ajax-function
231
  */
232
 
236
  exit(__('Missing post or set id', 'yet-another-stars-rating'));
237
  }
238
 
239
+ $multiset_obj = new YasrMultiSetData();
240
+
241
  //set fields name and ids
242
+ $set_fields = $multiset_obj->multisetFieldsAndID($set_id);
243
 
244
  //set meta values
245
  $set_post_meta_values = get_post_meta($post_id, 'yasr_multiset_author_votes', true);
246
+ $array_to_return = $multiset_obj->returnArrayFieldsRatings($set_id, $set_fields, $set_post_meta_values);
 
247
 
248
  echo json_encode($array_to_return);
249
 
250
  }
251
 
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
 
254
 
255
  /****** Adding logs widget to the dashboard ******/
256
 
257
+ add_action('plugins_loaded', 'yasr_add_action_dashboard_widget_log');
 
 
258
 
259
+ function yasr_add_action_dashboard_widget_log() {
260
  //This is for the admins (show all votes in the site)
261
  if (current_user_can('manage_options')) {
262
  add_action('wp_dashboard_setup', 'yasr_add_dashboard_widget_log');
264
 
265
  //This is for all the users to see where they've voted
266
  add_action('wp_dashboard_setup', 'yasr_add_dashboard_widget_user_log');
 
267
  }
268
 
269
  function yasr_add_dashboard_widget_log() {
 
270
  wp_add_dashboard_widget(
271
  'yasr_widget_log_dashboard', //slug for widget
272
  'Recent Ratings', //widget name
273
  'yasr_widget_log_dashboard_callback' //function callback
274
  );
 
275
  }
276
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
277
  //This add a dashboard log for every users
 
278
  function yasr_add_dashboard_widget_user_log() {
 
279
  wp_add_dashboard_widget(
280
  'yasr_users_dashboard_widget', //slug for widget
281
  'Your Ratings', //widget name
282
  'yasr_users_dashboard_widget_callback' //function callback
283
  );
 
284
  }
285
 
286
+ //ajax action
287
+ add_action('wp_ajax_yasr_change_log_page', 'yasr_widget_log_dashboard_callback');
288
+ function yasr_widget_log_dashboard_callback() {
289
+ $log_widget = new YasrLogDashboardWidget('admin');
290
+ $log_widget->adminWidget();
291
+ } //End callback function
292
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
 
294
+ //ajax action
295
+ add_action('wp_ajax_yasr_change_user_log_page', 'yasr_users_dashboard_widget_callback');
296
+ function yasr_users_dashboard_widget_callback() {
297
+ $log_widget = new YasrLogDashboardWidget('user');
298
+ $log_widget->userWidget();
299
  } //End callback function
300
 
301
 
424
  add_action('save_post', 'yasr_insert_review_type_callback');
425
 
426
  function yasr_insert_review_type_callback($post_id) {
427
+ //if user can not publish posts
428
+ if (!current_user_can('publish_posts')) {
429
+ wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
430
+ }
431
 
432
  //this mean there we're not in the classic editor
433
  if(!isset($_POST['yasr_nonce_review_type'])) {
434
  return;
 
 
 
 
 
435
  } else {
436
+ $nonce = $_POST['yasr_nonce_review_type'];
 
 
 
 
437
  }
438
 
439
+ //check nonce
440
  if (!wp_verify_nonce($nonce, 'yasr_nonce_review_type_action')) {
441
  return;
442
  }
443
 
444
  $post_id = (int)$post_id;
445
 
446
+ //check if $_POST isset
447
+ if (isset($_POST['yasr-review-type'])) {
448
+ $snippet_type = $_POST['yasr-review-type'];
449
+
450
+ //check if $snippet_type is a supported itemType
451
+ if (yasr_is_supported_schema($snippet_type)===true) {
452
+ //if the selected item type, is the same of the default one, delete the saved postmeta
453
+ if ($snippet_type === YASR_ITEMTYPE) {
454
+ delete_post_meta($post_id, 'yasr_review_type');
455
+ } else {
456
+ update_post_meta($post_id, 'yasr_review_type', $snippet_type);
457
+ }
458
+ } else {
459
+ return;
460
+ }
461
+ } else {
462
+ return;
463
+ }
464
 
465
  }
466
 
551
  // Write new data
552
  update_post_meta($post_id, 'yasr_multiset_author_votes', $data_to_save);
553
 
 
 
554
  } //End callback function
555
 
556
  /******* Add post_meta on save_post if this post is excluded for auto insert *******/
lib/yasr-deprecated.php ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * Get overall rating from yasr_votes table used in
5
+ * yasr_add_filter_for_schema(), yasr_get_id_value_callback()
6
+ * and yasr_rest_get_overall_rating
7
+ *
8
+ */
9
+
10
+ if (!defined('ABSPATH')) {
11
+ exit('You\'re not allowed to see this page');
12
+ } // Exit if accessed directly
13
+
14
+
15
+ function yasr_get_overall_rating($post_id = false) {
16
+
17
+ //if values it's not passed get the post id, since version 1.6.9 this is just for yasr_add_schema function
18
+ //and for a further check
19
+ if (!$post_id) {
20
+ $post_id = get_the_ID();
21
+ }
22
+
23
+ if (!$post_id) {
24
+ return null;
25
+ }
26
+
27
+ $post_id = (int) $post_id;
28
+
29
+ $overall_rating = get_post_meta($post_id, 'yasr_overall_rating', true);
30
+
31
+ return $overall_rating;
32
+
33
+ }
34
+
35
+ /****** Get visitor votes ******/
36
+ function yasr_get_visitor_votes($post_id = false, $create_transient = true) {
37
+
38
+ global $wpdb;
39
+
40
+ //if values it's not passed get the post id, most of cases and default one
41
+ if (!$post_id) {
42
+ $post_id = get_the_ID();
43
+ }
44
+
45
+ if (!$post_id) {
46
+ return false;
47
+ }
48
+
49
+ $post_id = (int)$post_id;
50
+
51
+ $transient_name = 'yasr_visitor_votes_' . $post_id;
52
+
53
+ $transient_visitor_votes = get_transient($transient_name);
54
+
55
+ if ($transient_visitor_votes) {
56
+ return $transient_visitor_votes;
57
+ } else {
58
+ $result = $wpdb->get_results(
59
+ $wpdb->prepare(
60
+ "SELECT SUM(vote) AS sum_votes, COUNT(vote) as number_of_votes FROM "
61
+ . YASR_LOG_TABLE .
62
+ " WHERE post_id=%d",
63
+ $post_id
64
+ )
65
+ );
66
+
67
+ if ($create_transient == true) {
68
+ set_transient($transient_name, $result, WEEK_IN_SECONDS);
69
+ }
70
+
71
+ return $result;
72
+
73
+ }
74
+
75
+ }
76
+
77
+
78
+ /****** Get multi set values and field's name, used in ajax function and shortcode function ******/
79
+ function yasr_get_multi_set_fields($set_id) {
80
+
81
+ global $wpdb;
82
+
83
+ $result = $wpdb->get_results($wpdb->prepare(
84
+ "SELECT f.field_id AS id, f.field_name AS name
85
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . " AS f
86
+ WHERE f.parent_set_id=%d
87
+ ORDER BY f.field_id
88
+ ", $set_id),
89
+ ARRAY_A);
90
+
91
+ if (empty($result)) {
92
+ return false;
93
+ }
94
+
95
+ return $result;
96
+
97
+ }
98
+
99
+
100
+ /*** function that get the star size and return it***/
101
+ function yasr_stars_size($size) {
102
+
103
+ //$size = sanitize_text_field($size);
104
+
105
+ $stars_attribute = array();
106
+
107
+ if ($size === 'small') {
108
+ $stars_attribute['px_size'] = '16';
109
+ } elseif ($size === 'medium') {
110
+ $stars_attribute['px_size'] = '24';
111
+ } //default values
112
+ else {
113
+ $stars_attribute['px_size'] = '32';
114
+ }
115
+
116
+ return $stars_attribute;
117
+
118
+ }
119
+
120
+ /*
121
+ * Show visitor votes average, READ ONLY
122
+ */
123
+ add_shortcode ('yasr_visitor_votes_readonly', 'yasr_visitor_votes_readonly_callback');
124
+
125
+ function yasr_visitor_votes_readonly_callback($atts) {
126
+
127
+ $atts['readonly'] = true;
128
+
129
+ //Here I call the same function that draw the same function for yasr_visitor_votes,
130
+ //passing the attribute readonly = true
131
+ $shortcode_html = shortcode_visitor_votes_callback($atts);
132
+
133
+ return $shortcode_html;
134
+
135
+ } //End function shortcode_visitor_votes_only_stars_callback
136
+
137
+
138
+ /****** Check if a logged in user has already rated. Return user vote for a post if exists ******/
139
+
140
+ function yasr_check_if_user_already_voted($post_id = false) {
141
+
142
+ global $wpdb;
143
+
144
+ $current_user = wp_get_current_user();
145
+ $user_id = $current_user->ID;
146
+
147
+ //just to be safe
148
+ if (!$post_id) {
149
+ $post_id = get_the_ID();
150
+ }
151
+
152
+ if (!$post_id || !$user_id) {
153
+ return false;
154
+ }
155
+
156
+ $rating = $wpdb->get_var(
157
+ $wpdb->prepare(
158
+ "SELECT vote FROM "
159
+ . YASR_LOG_TABLE .
160
+ " WHERE post_id=%d
161
+ AND user_id=%d
162
+ LIMIT 1 ",
163
+ $post_id, $user_id
164
+ )
165
+ );
166
+
167
+ if ($rating === null) {
168
+ $rating = false;
169
+ }
170
+
171
+ return $rating;
172
+
173
+ }
lib/yasr-functions.php CHANGED
@@ -386,12 +386,13 @@ function yasr_add_schema($content) {
386
  return $content;
387
  }
388
 
389
- $overall_rating = yasr_get_overall_rating(false, false);
390
- $visitor_votes = yasr_get_visitor_votes(false, false);
 
391
 
392
  $is_post_a_review = get_post_meta(get_the_ID(), 'yasr_post_is_review', true);
393
 
394
- $visitor_rating = false; //avoid undefined
395
 
396
  if($visitor_votes != false && is_array($visitor_votes)) {
397
  foreach ($visitor_votes as $rating) {
@@ -442,7 +443,6 @@ function yasr_add_schema($content) {
442
  } else {
443
  $post_image_size[0] = 0;
444
  $post_image_size[1] = 0;
445
-
446
  $logo_image_size[0] = 0;
447
  $logo_image_size[1] = 0;
448
  }
@@ -566,7 +566,6 @@ function yasr_add_schema($content) {
566
  return $content;
567
  }
568
 
569
-
570
  } //End function
571
 
572
  /****** Create a select menu to choose the rich snippet itemtype ******/
@@ -620,8 +619,10 @@ function yasr_shortcode_button_media() {
620
 
621
  add_thickbox();
622
 
623
- echo '<a href="#TB_inline?width=530&height=600&inlineId=yasr-tinypopup-form" id="yasr-shortcode-creator" class="button thickbox">
624
- <span class="dashicons dashicons-star-half" style="vertical-align: middle;"></span> Yasr Shortcode
 
 
625
  </a>';
626
 
627
  }
@@ -681,27 +682,6 @@ function yasr_get_custom_post_type($return_value = 'array') {
681
  }
682
 
683
 
684
- /*** function that get the star size and return it***/
685
- function yasr_stars_size($size) {
686
-
687
- $size = sanitize_text_field($size);
688
-
689
- $stars_attribute = array();
690
-
691
- if ($size === 'small') {
692
- $stars_attribute['px_size'] = '16';
693
- } elseif ($size === 'medium') {
694
- $stars_attribute['px_size'] = '24';
695
- } //default values
696
- else {
697
- $stars_attribute['px_size'] = '32';
698
- }
699
-
700
- return $stars_attribute;
701
-
702
- }
703
-
704
-
705
  /*** Add support for wp super cache ***/
706
  function yasr_wp_super_cache_support($post_id) {
707
  if (function_exists('wp_cache_post_change')) {
@@ -784,7 +764,7 @@ function yasr_setcookie($cookiename, $data_to_save) {
784
 
785
  $encoded_data = json_encode($existing_data);
786
 
787
- setcookie($cookiename, $encoded_data, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN);
788
 
789
  }
790
 
@@ -963,36 +943,22 @@ function yasr_check_valid_url($url) {
963
 
964
 
965
  /**
966
- * @since 2.1.0
967
  *
968
- * @param $show_average
969
- * @param $multiset_average
970
- * @param $multiset_string
971
  *
972
- * @return string
973
  */
974
 
975
- function yasr_return_average_multiset($show_average, $multiset_average, $multiset_string) {
976
- $html_average = ''; //avoid undefined
977
- $average_txt = __("Average", "yet-another-stars-rating");
978
-
979
- //Show average row
980
- if ($show_average !== null && $show_average !=='no'|| $show_average===null && YASR_MULTI_SHOW_AVERAGE !== 'no') {
981
- $unique_id_identifier = $multiset_string . str_shuffle(uniqid());
982
 
983
- $html_average = "<tr>
984
- <td colspan='2' class='yasr-multiset-average'>
985
- <div class='yasr-multiset-average'>
986
- <span class='yasr-multiset-average-text'>$average_txt</span>
987
- <div class='yasr-rater-stars' id='$unique_id_identifier'
988
- data-rating='$multiset_average' data-rater-readonly='true'
989
- data-rater-starsize='24'></div>
990
- </div>
991
- </td>
992
- </tr>";
993
  }
994
 
995
- return $html_average;
996
  }
997
 
998
  ?>
386
  return $content;
387
  }
388
 
389
+ $database_ratings_obj = new YasrDatabaseRatings();
390
+ $overall_rating = $database_ratings_obj->getOverallRating();
391
+ $visitor_votes = $database_ratings_obj->getVisitorVotes(false, false);
392
 
393
  $is_post_a_review = get_post_meta(get_the_ID(), 'yasr_post_is_review', true);
394
 
395
+ $visitor_rating = array(); //avoid undefined
396
 
397
  if($visitor_votes != false && is_array($visitor_votes)) {
398
  foreach ($visitor_votes as $rating) {
443
  } else {
444
  $post_image_size[0] = 0;
445
  $post_image_size[1] = 0;
 
446
  $logo_image_size[0] = 0;
447
  $logo_image_size[1] = 0;
448
  }
566
  return $content;
567
  }
568
 
 
569
  } //End function
570
 
571
  /****** Create a select menu to choose the rich snippet itemtype ******/
619
 
620
  add_thickbox();
621
 
622
+ echo '<a href="#TB_inline?width=530&height=600&inlineId=yasr-tinypopup-form"
623
+ id="yasr-shortcode-creator"
624
+ class="button thickbox">
625
+ <span class="dashicons dashicons-star-half" style="vertical-align: middle;"></span> Yasr Shortcode
626
  </a>';
627
 
628
  }
682
  }
683
 
684
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
685
  /*** Add support for wp super cache ***/
686
  function yasr_wp_super_cache_support($post_id) {
687
  if (function_exists('wp_cache_post_change')) {
764
 
765
  $encoded_data = json_encode($existing_data);
766
 
767
+ setcookie($cookiename, $encoded_data, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, true);
768
 
769
  }
770
 
943
 
944
 
945
  /**
946
+ * Check if the given string is a supported itemType
947
  *
948
+ * @param string $item_type
949
+ * @return bool
 
950
  *
951
+ * @since 2.1.5
952
  */
953
 
954
+ function yasr_is_supported_schema ($item_type) {
955
+ $supported_schema_array = json_decode(YASR_SUPPORTED_SCHEMA_TYPES);
 
 
 
 
 
956
 
957
+ if (in_array($item_type, $supported_schema_array)) {
958
+ return true;
 
 
 
 
 
 
 
 
959
  }
960
 
961
+ return false;
962
  }
963
 
964
  ?>
lib/yasr-shortcode-classes.php ADDED
@@ -0,0 +1,1031 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+
5
+ Copyright 2014 Dario Curvino (email : d.curvino@tiscali.it)
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 2 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see <http://www.gnu.org/licenses/>
19
+ */
20
+
21
+ if (!defined('ABSPATH')) {
22
+ exit('You\'re not allowed to see this page');
23
+ } // Exit if accessed directly
24
+
25
+ /**
26
+ * Class YasrShortcode
27
+ *
28
+ * @since 2.1.5
29
+ *
30
+ */
31
+ class YasrShortcode {
32
+ public $shortcode_html;
33
+ public $post_id; //false
34
+ public $size; //large
35
+ public $readonly; //false
36
+ public $set_id; //1
37
+ public $show_average; //null
38
+ public $shorcode_name;
39
+
40
+ public function __construct($atts, $shortcode_name) {
41
+ $this->shorcode_name = $shortcode_name;
42
+
43
+ if ($atts !== false) {
44
+ $atts = shortcode_atts(
45
+ array(
46
+ 'size' => 'large',
47
+ 'postid' => false,
48
+ 'readonly' => false,
49
+ 'setid' => 1,
50
+ 'show_average' => null
51
+ ),
52
+ $atts,
53
+ $shortcode_name
54
+ );
55
+
56
+ if ($atts['postid'] === false) {
57
+ $this->post_id = get_the_ID();
58
+ } else {
59
+ $this->post_id = (int) $atts['postid'];
60
+ }
61
+ $this->size = sanitize_text_field($atts['size']);
62
+ $this->readonly = sanitize_text_field($atts['readonly']);
63
+ $this->set_id = (int) $atts['setid'];
64
+ $this->show_average = sanitize_text_field($atts['show_average']);
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Return the stars size according to size attribute in shortcode.
70
+ * If not used, return 32 (default value)
71
+ *
72
+ * @return int
73
+ */
74
+ protected function starSize() {
75
+ if ($this->shorcode_name === 'yasr_top_ten_highest_rated'
76
+ || $this->shorcode_name === 'yasr_most_or_highest_rated_posts') {
77
+ return 24;
78
+ }
79
+
80
+ $size = $this->size;
81
+ $px_size = 32; //default value
82
+
83
+ if ($size === 'small') {
84
+ $px_size = 16;
85
+ } elseif ($size === 'medium') {
86
+ $px_size = 24;
87
+ }
88
+ return $px_size;
89
+ }
90
+ }
91
+
92
+
93
+ /**
94
+ * Class YasrOverallRating
95
+ * Print Yasr Overall Rating
96
+ */
97
+ class YasrOverallRating extends YasrShortcode {
98
+
99
+ protected $html_stars;
100
+ protected $overall_rating;
101
+
102
+ /**
103
+ * Print the visitor votes shortcode
104
+ *
105
+ * @return string|null
106
+ */
107
+
108
+ function printOverallRating () {
109
+
110
+ //do not run in admin (problem with tinymce)
111
+ if(is_admin()) {
112
+ return false;
113
+ }
114
+
115
+ $stars_size = $this->starSize();
116
+ $overall_rating_obj = new YasrDatabaseRatings();
117
+ $this->overall_rating = $overall_rating_obj->getOverallRating($this->post_id);
118
+
119
+ $this->shortcode_html = '<!--Yasr Overall Rating Shortcode-->';
120
+
121
+ //generate an unique id to be sure that every element has a different ID
122
+ $unique_id = str_shuffle(uniqid());
123
+ $overall_rating_html_id = 'yasr-overall-rating-rater-' . $unique_id;
124
+
125
+ $this->html_stars = "<div class='yasr-overall-rating'>
126
+ <div class='yasr-rater-stars'
127
+ id='$overall_rating_html_id'
128
+ data-rating='$this->overall_rating'
129
+ data-rater-starsize='$stars_size' >
130
+ </div>
131
+ </div>";
132
+
133
+ $this->customTextBefore();
134
+ $this->shortcode_html .= '<!--End Yasr Overall Rating Shortcode-->';
135
+
136
+ //If overall rating in loop is enabled don't use is_singular && is main_query
137
+ if (YASR_SHOW_OVERALL_IN_LOOP === 'enabled') {
138
+ return $this->shortcode_html;
139
+ } //default
140
+ else {
141
+ if (is_singular() && is_main_query()) {
142
+ return $this->shortcode_html;
143
+ }
144
+ return null;
145
+ }
146
+ }
147
+
148
+ /**
149
+ * If enabled in the settings, this function will show the custom text
150
+ * before or after the stars in yasr_visitor_votes
151
+ *
152
+ * @param void
153
+ * @return void
154
+ *
155
+ */
156
+ protected function customTextBefore() {
157
+ if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_BEFORE_OVERALL != '') {
158
+ $text_before_star = str_replace('%overall_rating%', $this->overall_rating, YASR_TEXT_BEFORE_OVERALL);
159
+ $this->shortcode_html = "<div class='yasr-container-custom-text-and-overall'>
160
+ <span id='yasr-custom-text-before-overall'>" . $text_before_star . "</span>
161
+ $this->html_stars
162
+ </div>";
163
+ } else {
164
+ $this->shortcode_html .= $this->html_stars;
165
+ }
166
+ }
167
+
168
+ }
169
+
170
+ /**
171
+ * Class YasrVisitorVotes
172
+ * Print Yasr Visitor Votes
173
+ */
174
+ class YasrVisitorVotes extends YasrShortcode {
175
+
176
+ protected $votes = null;
177
+ protected $votes_number = 0;
178
+ protected $medium_rating = 0;
179
+ protected $cookie_value = false; //avoid undefined
180
+ protected $span_bottom_line;
181
+ protected $span_text_after_stars;
182
+
183
+
184
+ /**
185
+ * Print the visitor votes shortcode
186
+ *
187
+ * @return string|null
188
+ */
189
+ public function printVisitorVotes() {
190
+
191
+ //do not run in admin (problem with tinymce)
192
+ if(is_admin()) {
193
+ return false;
194
+ }
195
+
196
+ $stars_size = $this->starSize();
197
+
198
+ $unique_id = str_shuffle(uniqid());
199
+ $htmlid = 'yasr-visitor-votes-rater-' . $unique_id ;
200
+ $span_container_after_stars = "<span id='yasr-visitor-votes-container-after-stars-$unique_id'
201
+ class='yasr-visitor-votes-after-stars-class'>";
202
+
203
+ $visitor_votes_rating_obj = new YasrDatabaseRatings();
204
+ $this->votes = $visitor_votes_rating_obj->getVisitorVotes($this->post_id); //always reference it
205
+
206
+ foreach ($this->votes as $user_votes) {
207
+ $this->votes_number = $user_votes->number_of_votes;
208
+ if ($this->votes_number != 0) {
209
+ $this->medium_rating = ($user_votes->sum_votes/$this->votes_number);
210
+ } else {
211
+ $this->medium_rating = 0;
212
+ }
213
+ }
214
+
215
+ $this->medium_rating=round($this->medium_rating, 1);
216
+
217
+ if (is_singular()) {
218
+ $is_singular = 'true';
219
+ } else {
220
+ $is_singular = 'false';
221
+ }
222
+
223
+ $this->shortcode_html = '<!--Yasr Visitor Votes Shortcode-->';
224
+
225
+ //if this come from yasr_visitor_votes_readonly...
226
+ if ($this->readonly === true || $this->readonly === "yes") {
227
+ $htmlid = 'yasr-visitor-votes-readonly-rater-'.$unique_id;
228
+
229
+ $this->shortcode_html = "<div class=\"yasr-rater-stars-visitor-votes\" id=\"$htmlid\" data-rating=\"$this->medium_rating\"
230
+ data-rater-starsize=\"$stars_size\" data-rater-postid=\"$this->post_id\"
231
+ data-rater-readonly=\"true\"></div>";
232
+
233
+ return $this->shortcode_html;
234
+ }
235
+
236
+ $ajax_nonce_visitor = wp_create_nonce("yasr_nonce_insert_visitor_rating");
237
+
238
+ $this->shortcode_html .= "<div id='yasr_visitor_votes_$this->post_id' class='yasr-visitor-votes'>";
239
+
240
+ $this->checkCookie();
241
+ $this->allowedUser();
242
+ $this->customTextBeforeAfter();
243
+
244
+ $this->shortcode_html .= "<div id='$htmlid'
245
+ class='yasr-rater-stars-visitor-votes'
246
+ data-rater-postid='$this->post_id'
247
+ data-rating='$this->medium_rating'
248
+ data-rater-starsize='$stars_size'
249
+ data-rater-readonly='$this->readonly'
250
+ data-rater-nonce='$ajax_nonce_visitor'
251
+ data-issingular='$is_singular'
252
+ ></div>";
253
+ $this->shortcode_html .= $span_container_after_stars;
254
+ $this->shortcode_html .= $this->visitorStats();
255
+ $this->shortcode_html .= $this->span_text_after_stars;
256
+ $this->shortcode_html .= $this->span_bottom_line;
257
+ $this->shortcode_html .= '</span>'; //Close yasr-visitor-votes-after-stars and yasr_visitor_votes
258
+ $this->shortcode_html .= '</div>'; //close all
259
+ $this->shortcode_html .= '<!--End Yasr Visitor Votes Shortcode-->';
260
+
261
+ //If visitor_votes in loop is enabled don't use is_singular && is main_query
262
+ if (YASR_SHOW_VISITOR_VOTES_IN_LOOP === 'enabled') {
263
+ return $this->shortcode_html;
264
+ }
265
+
266
+ //default value
267
+ else {
268
+ if (is_singular() && is_main_query()) {
269
+ return $this->shortcode_html;
270
+ }
271
+ return null;
272
+ }
273
+ } //end function
274
+
275
+ /**
276
+ * Function that checks if cookie exists and set the value
277
+ *
278
+ * @param void
279
+ * @return void
280
+ */
281
+ protected function checkCookie () {
282
+ //name of cookie to check
283
+ $yasr_cookiename = 'yasr_visitor_vote_cookie';
284
+
285
+ if (isset($_COOKIE[$yasr_cookiename])) {
286
+ $cookie_data = stripslashes($_COOKIE[$yasr_cookiename]);
287
+
288
+ //By default, json_decode return an object, true to return an array
289
+ $cookie_data = json_decode($cookie_data, true);
290
+
291
+ if (is_array($cookie_data)) {
292
+ foreach ($cookie_data as $value) {
293
+ $cookie_post_id = (int)$value['post_id'];
294
+ if ($cookie_post_id === $this->post_id) {
295
+ $this->cookie_value = (int)$value['rating'];
296
+ //Stop doing foreach, here we've found the rating for current post
297
+ break;
298
+ }
299
+ }
300
+ }
301
+ if ($this->cookie_value !== false && $this->cookie_value > 5) {
302
+ $this->cookie_value = 5;
303
+ } elseif ($this->cookie_value !== false && $this->cookie_value < 1) {
304
+ $this->cookie_value = 1;
305
+ }
306
+ }
307
+ }
308
+
309
+ /**
310
+ * This function checks who can rate to the shortcode
311
+ *
312
+ * @param void
313
+ * @return void
314
+ */
315
+ protected function allowedUser () {
316
+ $visitor_votes = new YasrDatabaseRatings();
317
+
318
+ //I've to check a logged in user that has already rated
319
+ if (is_user_logged_in()) {
320
+ $this->readonly = 'false'; //Always false if user is logged in
321
+
322
+ //Check if a logged in user has already rated for this post
323
+ $vote_if_user_already_rated = $visitor_votes->visitorVotesHasUserVoted($this->post_id);
324
+
325
+ //If user has already rated
326
+ if ($vote_if_user_already_rated) {
327
+ $this->span_bottom_line="<span class='yasr-small-block-bold yasr-already-voted-text'
328
+ id='yasr-user-vote-$this->post_id'
329
+ data-yasr-already-voted='$vote_if_user_already_rated'>"
330
+ .__("You've already voted this article with", 'yet-another-stars-rating') .
331
+ " $vote_if_user_already_rated
332
+ </span>";
333
+ }
334
+ } //End if user is logged
335
+
336
+ //if anonymous are allowed to vote
337
+ if (YASR_ALLOWED_USER === 'allow_anonymous') {
338
+ //IF user is not logged in
339
+ if (!is_user_logged_in()) {
340
+ //if cookie exists
341
+ if ($this->cookie_value) {
342
+ $this->readonly = 'true';
343
+ $this->span_bottom_line = "<span class='yasr-small-block-bold yasr-already-voted-text'>";
344
+ if (YASR_TEXT_BEFORE_STARS == 1 && YASR_CUSTOM_TEXT_USER_VOTED != '') {
345
+ $this->span_bottom_line .= YASR_CUSTOM_TEXT_USER_VOTED;
346
+ } else {
347
+ $this->span_bottom_line .= __('You\'ve already voted this article with', 'yet-another-stars-rating') . $this->cookie_value;
348
+ }
349
+ $this->span_bottom_line .= '</span>';
350
+ } else {
351
+ $this->readonly = 'false';
352
+ }
353
+ }
354
+ } //end if YASR_ALLOWED_USER === 'allow_anonymous' {
355
+
356
+ //If only logged in users can vote
357
+ elseif (YASR_ALLOWED_USER === 'logged_only') {
358
+ //IF user is not logged in
359
+ if (!is_user_logged_in()) {
360
+ $this->readonly = 'true'; //readonly is true if user isn't logged
361
+
362
+ $this->span_bottom_line = "<span class=\"yasr-visitor-votes-must-sign-in\">";
363
+
364
+ //if custom text is defined
365
+ if (defined('YASR_CUSTOM_TEXT_MUST_SIGN_IN') && YASR_CUSTOM_TEXT_MUST_SIGN_IN !== '') {
366
+ $this->span_bottom_line .= YASR_CUSTOM_TEXT_MUST_SIGN_IN;
367
+ } else {
368
+ $this->span_bottom_line .= __('You must sign in to vote', 'yet-another-stars-rating');
369
+ }
370
+ $this->span_bottom_line .= "</span>";
371
+ }
372
+
373
+ }
374
+ }
375
+
376
+ /**
377
+ * If enabled in the settings, this function will show the custom text
378
+ * before or after the stars in yasr_visitor_votes
379
+ *
380
+ * @param void
381
+ * @return void
382
+ */
383
+ protected function customTextBeforeAfter () {
384
+
385
+ $this->span_text_after_stars = "<span class='yasr-total-average-container'
386
+ id='yasr-total-average-text_$this->post_id'>";
387
+
388
+ if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_BEFORE_VISITOR_RATING != '') {
389
+ $text_before_star = str_replace('%total_count%', $this->votes_number, YASR_TEXT_BEFORE_VISITOR_RATING);
390
+ $text_before_star = str_replace('%average%', $this->medium_rating, $text_before_star);
391
+ $this->shortcode_html .= "<div class='yasr-container-custom-text-and-visitor-rating'>
392
+ <span id='yasr-custom-text-before-visitor-rating'>"
393
+ . $text_before_star .
394
+ "</span></div>";
395
+ }
396
+
397
+ if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_AFTER_VISITOR_RATING != '') {
398
+ $text_after_star = str_replace('%total_count%', $this->votes_number, YASR_TEXT_AFTER_VISITOR_RATING);
399
+ $text_after_star = str_replace('%average%', $this->medium_rating, $text_after_star);
400
+ $this->span_text_after_stars .= $text_after_star;
401
+ } else {
402
+ $this->span_text_after_stars .= '['
403
+ . __('Total:', 'yet-another-stars-rating')
404
+ . '&nbsp;' . $this->votes_number . '&nbsp; &nbsp;'
405
+ . __('Average:', 'yet-another-stars-rating')
406
+ . '&nbsp;' . $this->medium_rating
407
+ . '/5]';
408
+ }
409
+
410
+ $this->span_text_after_stars .= '</span>';
411
+ }
412
+
413
+ /**
414
+ * This function will return the html code for the dashicons
415
+ *
416
+ * @param void
417
+ *
418
+ * @return string
419
+ */
420
+ protected function visitorStats () {
421
+ if (YASR_VISITORS_STATS === 'yes') {
422
+ global $yasr_plugin_imported;
423
+
424
+ //default
425
+ $span_dashicon = "<span class='dashicons dashicons-chart-bar yasr-dashicons-visitor-stats'
426
+ data-postid='$this->post_id' id='yasr-total-average-dashicon-$this->post_id'></span>";
427
+
428
+ if (is_array($yasr_plugin_imported)) {
429
+ $plugin_import_date = null; //avoid undefined
430
+ if (array_key_exists('wppr', $yasr_plugin_imported)) {
431
+ $plugin_import_date = $yasr_plugin_imported['wppr']['date'];
432
+ }
433
+
434
+ if (array_key_exists('kksr', $yasr_plugin_imported)) {
435
+ $plugin_import_date = $yasr_plugin_imported['kksr']['date'];
436
+ }
437
+
438
+ if (array_key_exists('mr', $yasr_plugin_imported)) {
439
+ $plugin_import_date = $yasr_plugin_imported['mr']['date'];
440
+ }
441
+
442
+ //remove hour from date
443
+ $plugin_import_date=strtok($plugin_import_date,' ');
444
+
445
+ $post_date = get_the_date('Y-m-d', $this->post_id);
446
+
447
+ //if one of these plugin has been imported and post is older then import, hide stats
448
+ if ($post_date < $plugin_import_date) {
449
+ $span_dashicon = "";
450
+ }
451
+ } //End if $yasr_plugin_imported
452
+ } else {
453
+ //Yasr_visitor_stats are disabled
454
+ $span_dashicon = "";
455
+ }
456
+ return $span_dashicon;
457
+ }
458
+ }
459
+
460
+
461
+ /**
462
+ * Class YasrMultiSet
463
+ */
464
+ class YasrMultiSet extends YasrShortcode {
465
+ /**
466
+ * @return string | bool
467
+ */
468
+ public function printMultiset () {
469
+
470
+ //do not run in admin (problem with tinymce)
471
+ if(is_admin()) {
472
+ return false;
473
+ }
474
+
475
+ $this->shortcode_html = '<!-- Yasr Multi Set Shortcode-->';
476
+
477
+ $multiset_obj = new YasrMultiSetData();
478
+
479
+ //set fields name and ids
480
+ $set_fields = $multiset_obj->multisetFieldsAndID($this->set_id);
481
+
482
+ //If there is no set for that id, return
483
+ if (!$set_fields) {
484
+ $string = __('No Set Found with this ID', 'yet-another-stars-rating');
485
+ return $this->shortcode_html . $string;
486
+ }
487
+
488
+ //get meta values
489
+ $set_post_meta_values = get_post_meta($this->post_id, 'yasr_multiset_author_votes', true);
490
+
491
+ $multiset_content = $multiset_obj->returnArrayFieldsRatings($this->set_id, $set_fields, $set_post_meta_values);
492
+
493
+ $this->shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
494
+ $this->shortcode_html .= '<table class="yasr_table_multi_set_shortcode">';
495
+ $this->star_readonly = 'true';
496
+
497
+ $this->printMultisetRows($multiset_content);
498
+
499
+ $this->shortcode_html .= "</table>";
500
+ $this->shortcode_html .= '<!--End Yasr Multi Set Shortcode-->';
501
+
502
+ return $this->shortcode_html;
503
+ }
504
+
505
+
506
+ protected function printMultisetRows($multiset_content, $visitor_multiset=false) {
507
+
508
+ $multiset_string = 'yasr-average-multiset-';
509
+ if ($visitor_multiset === true) {
510
+ $multiset_string = 'yasr-visitor-multi-set-average-';
511
+ }
512
+
513
+ foreach ($multiset_content as $set_content) {
514
+ $unique_id_identifier = 'yasr-multiset-' . str_shuffle(uniqid());
515
+
516
+ $average_rating = round($set_content['average_rating'], 1);
517
+
518
+ $html_stars = "<div class='yasr-multiset-visitors-rater'
519
+ id='$unique_id_identifier'
520
+ data-rater-postid='$this->post_id'
521
+ data-rater-setid='$this->set_id'
522
+ data-rater-set-field-id='$set_content[id]'
523
+ data-rating='$average_rating'
524
+ data-rater-readonly='$this->star_readonly'>
525
+ </div>";
526
+
527
+ $span_container_number_of_votes = '';
528
+ if ($visitor_multiset === true) {
529
+ $span_container_number_of_votes = '<span class="yasr-visitor-multiset-vote-count">'
530
+ . $set_content['number_of_votes'] .
531
+ '</span>';
532
+ }
533
+
534
+ $this->shortcode_html .='<tr>
535
+ <td>
536
+ <span class="yasr-multi-set-name-field">' . $set_content['name'] . '</span>
537
+ </td>
538
+ <td>'
539
+ . $html_stars . $span_container_number_of_votes .
540
+ '</td>
541
+ </tr>';
542
+
543
+ } //End foreach
544
+
545
+ $multiset_obj = new YasrMultiSetData();
546
+ //get the average of the multiset
547
+ $multiset_average = $multiset_obj->returnMultiSetAverage($multiset_content);
548
+
549
+ //print it
550
+ $this->shortcode_html .= $this->printAverageRowMultiSet($this->show_average, $multiset_average, $multiset_string);
551
+
552
+ }
553
+
554
+ /**
555
+ * @since 2.1.0
556
+ *
557
+ * @param $show_average
558
+ * @param $multiset_average
559
+ * @param $multiset_string
560
+ *
561
+ * @return string
562
+ */
563
+ protected function printAverageRowMultiSet($show_average, $multiset_average, $multiset_string) {
564
+ $average_txt = __("Average", "yet-another-stars-rating");
565
+ $html_average = null;
566
+
567
+ //Show average row
568
+ if ($show_average !== null && $show_average !== 'no'|| $show_average===null && YASR_MULTI_SHOW_AVERAGE !== 'no') {
569
+ $unique_id_identifier = $multiset_string . str_shuffle(uniqid());
570
+
571
+ $html_average = "<tr>
572
+ <td colspan='2' class='yasr-multiset-average'>
573
+ <div class='yasr-multiset-average'>
574
+ <span class='yasr-multiset-average-text'>$average_txt</span>
575
+ <div class='yasr-rater-stars' id='$unique_id_identifier'
576
+ data-rating='$multiset_average' data-rater-readonly='true'
577
+ data-rater-starsize='24'></div>
578
+ </div>
579
+ </td>
580
+ </tr>";
581
+ }
582
+
583
+ return $html_average;
584
+ }
585
+
586
+ }
587
+
588
+ /**
589
+ * Class YasrVisitorMultiSet
590
+ */
591
+ class YasrVisitorMultiSet extends YasrMultiSet {
592
+
593
+ protected $loader_html;
594
+ protected $button_html;
595
+ protected $button_html_disabled;
596
+ protected $button;
597
+ protected $star_readonly;
598
+ protected $span_message_content;
599
+
600
+
601
+ /**
602
+ * Print Yasr Visitor MultiSet
603
+ *
604
+ * @param void
605
+ * @return string
606
+ */
607
+ public function printVisitorMultiSet () {
608
+
609
+ //do not run in admin (problem with tinymce)
610
+ if(is_admin()) {
611
+ return false;
612
+ }
613
+
614
+ $multiset_obj = new YasrMultiSetData();
615
+ $ajax_nonce_visitor_multiset = wp_create_nonce("yasr_nonce_insert_visitor_rating_multiset");
616
+
617
+ $this->shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
618
+
619
+ $image = YASR_IMG_DIR . "/loader.gif";
620
+ $this->loader_html = "<span class='yasr-loader-multiset-visitor'
621
+ id='yasr-loader-multiset-visitor-$this->post_id-$this->set_id'>
622
+ &nbsp;<img src='$image' title='yasr-loader' alt='yasr-loader'>
623
+ </span>";
624
+
625
+ $this->button_html = "<input type='submit'
626
+ name='submit'
627
+ id='yasr-send-visitor-multiset-$this->post_id-$this->set_id'
628
+ class='button button-primary yasr-send-visitor-multiset'
629
+ data-postid='$this->post_id'
630
+ data-setid='$this->set_id'
631
+ value='" . __('Submit!', 'yet-another-stars-rating') . "'
632
+ />";
633
+
634
+ $this->button_html_disabled = "<input type='submit'
635
+ disabled='disabled'
636
+ class='button button-primary'
637
+ id='yasr-send-visitor-multiset-disabled'
638
+ disabled='disabled'
639
+ value='" . __('Submit!', 'yet-another-stars-rating') . "'
640
+ />";
641
+
642
+ //check cookie and assign default values
643
+ $this->multisetAttributes();
644
+
645
+ $set_name_content = $multiset_obj->returnVisitorMultiSet($this->post_id, $this->set_id);
646
+
647
+ if (!$set_name_content) {
648
+ $this->shortcode_html .= __('No MultiSet found with this ID', 'yet-another-stars-rating');
649
+ return $this->shortcode_html;
650
+ }
651
+
652
+ $this->shortcode_html .= "<table class='yasr_table_multi_set_shortcode'>";
653
+
654
+ $this->printMultisetRows($set_name_content, true);
655
+
656
+ //Submit row and button
657
+ $this->shortcode_html .="<tr>
658
+ <td colspan='2'>
659
+ $this->button
660
+ $this->loader_html
661
+ <span class='yasr-visitor-multiset-message'>$this->span_message_content</span>
662
+ </td>
663
+ </tr>
664
+ ";
665
+
666
+ $this->shortcode_html .= "</table>";
667
+ $this->shortcode_html .= '<!-- End Yasr Multi Set Visitor Shortcode-->';
668
+
669
+ wp_localize_script(
670
+ 'yasrfront',
671
+ "yasrMultiSetData",
672
+ array(
673
+ 'nonceVisitor' => $ajax_nonce_visitor_multiset,
674
+ 'setType' => $this->set_id
675
+ )
676
+ );
677
+
678
+ return $this->shortcode_html;
679
+ }
680
+
681
+ /**
682
+ * This function first check if a cookie is set,
683
+ * Then who can rate and set attributes to:
684
+ * $this->button
685
+ * $this->star_readonly
686
+ * $this->span_message_content
687
+ *
688
+ * @param void
689
+ * @return void
690
+ *
691
+ */
692
+ protected function multisetAttributes() {
693
+ $yasr_cookiename = 'yasr_multi_visitor_cookie';
694
+
695
+ //Check cookie and if voting is allowed only to logged in users
696
+ if (isset($_COOKIE[$yasr_cookiename])) {
697
+ $cookie_data = stripslashes($_COOKIE[ $yasr_cookiename ]);
698
+
699
+ //By default, json_decode return an object, true to return an array
700
+ $cookie_data = json_decode($cookie_data, true);
701
+
702
+ if (is_array($cookie_data)) {
703
+ foreach ($cookie_data as $value) {
704
+ $cookie_post_id = (int)$value['post_id'];
705
+ $cookie_set_id = (int)$value['set_id'];
706
+
707
+ if ($cookie_post_id === $this->post_id && $cookie_set_id === $this->set_id) {
708
+ $this->button = "";
709
+ $this->star_readonly = 'true';
710
+ $this->span_message_content = __('Thank you for voting!', 'yet-another-stars-rating');
711
+
712
+ //Stop doing foreach, here we've found the rating for current post
713
+ break;
714
+ } else {
715
+ $this->button = $this->button_html;
716
+ $this->star_readonly = 'false';
717
+ $this->span_message_content = "";
718
+ }
719
+ }
720
+ }
721
+ } else {
722
+ //If user is not logged in
723
+ if (!is_user_logged_in()) {
724
+ if (YASR_ALLOWED_USER === 'allow_anonymous') {
725
+ $this->button = $this->button_html;
726
+ $this->star_readonly = 'false';
727
+ $this->span_message_content = "";
728
+ } elseif (YASR_ALLOWED_USER === 'logged_only') {
729
+ $this->button = $this->button_html_disabled;
730
+ $this->star_readonly = 'true';
731
+ $this->span_message_content = '<span class="yasr-visitor-votes-must-sign-in">';
732
+
733
+ if (defined('YASR_CUSTOM_TEXT_MUST_SIGN_IN') && YASR_CUSTOM_TEXT_MUST_SIGN_IN !== '') {
734
+ $this->span_message_content .= YASR_CUSTOM_TEXT_MUST_SIGN_IN;
735
+ } else {
736
+ $this->span_message_content .= __('You must sign in to vote', 'yet-another-stars-rating');
737
+ }
738
+ $this->span_message_content .= '</span>';
739
+ }
740
+ } //End if user logged in
741
+
742
+ //User is logged in
743
+ else {
744
+ $this->button = $this->button_html;
745
+ $this->star_readonly = 'false';
746
+ $this->span_message_content = "";
747
+ }
748
+ }
749
+ }
750
+ }
751
+
752
+ /**
753
+ * Class YasrRankings
754
+ */
755
+ class YasrRankings extends YasrShortcode {
756
+
757
+ protected $query_highest_rated_overall;
758
+ protected $query_result_most_rated_visitor;
759
+ protected $query_result_highest_rated_visitor;
760
+ protected $vv_highest_rated_table;
761
+ protected $vv_most_rated_table;
762
+
763
+ /*
764
+ *
765
+ * */
766
+ public function returnHighestRatedOverall () {
767
+ $this->shortcode_html = '<!-- Yasr Most Or Highest Rated Shortcode-->';
768
+
769
+ global $wpdb;
770
+
771
+ $this->query_highest_rated_overall = $wpdb->get_results("
772
+ SELECT pm.meta_value AS overall_rating,
773
+ pm.post_id AS post_id
774
+ FROM $wpdb->postmeta AS pm,
775
+ $wpdb->posts AS p
776
+ WHERE pm.post_id = p.ID
777
+ AND p.post_status = 'publish'
778
+ AND pm.meta_key = 'yasr_overall_rating'
779
+ ORDER BY pm.meta_value DESC,
780
+ pm.post_id
781
+ LIMIT 10"
782
+ );
783
+
784
+ $this->loopHighestRatedOverall();
785
+
786
+ $this->shortcode_html .= '<!--End Yasr Top 10 highest Rated Shortcode-->';
787
+ return $this->shortcode_html;
788
+
789
+ }
790
+
791
+ protected function loopHighestRatedOverall($text_position=false, $text=false) {
792
+ if ($this->query_highest_rated_overall) {
793
+ $this->shortcode_html .= "<table class='yasr-table-chart'>";
794
+
795
+ foreach ($this->query_highest_rated_overall as $result) {
796
+ $post_title = wp_strip_all_tags(get_the_title($result->post_id));
797
+ $link = get_permalink($result->post_id); //Get permalink from post id
798
+ $yasr_top_ten_html_id = 'yasr-highest_rated-' . str_shuffle(uniqid());
799
+
800
+ $this->returnTableRows($result->post_id,
801
+ $result->overall_rating,
802
+ null,
803
+ $post_title,
804
+ $link, $yasr_top_ten_html_id);
805
+
806
+
807
+ } //End foreach
808
+ $this->shortcode_html .= "</table>";
809
+ }
810
+ else {
811
+ _e("You don't have any votes stored", 'yet-another-stars-rating');
812
+ }
813
+
814
+ }
815
+
816
+ /**
817
+ * Create the queries for the rankings
818
+ *
819
+ * Return the full html for the shortcode
820
+ *
821
+ * @return string $this->shortcode_html;
822
+ */
823
+ public function vvReturnMostHighestRatedPost() {
824
+ $this->shortcode_html = '<!-- Yasr Most Or Highest Rated Shortcode-->';
825
+
826
+ global $wpdb;
827
+
828
+ $this->query_result_most_rated_visitor = $wpdb->get_results(
829
+ "SELECT post_id,
830
+ COUNT(post_id) AS number_of_votes,
831
+ SUM(vote) AS sum_votes
832
+ FROM " . YASR_LOG_TABLE . ",
833
+ $wpdb->posts AS p
834
+ WHERE post_id = p.ID
835
+ AND p.post_status = 'publish'
836
+ GROUP BY post_id
837
+ HAVING number_of_votes > 1
838
+ ORDER BY number_of_votes DESC,
839
+ post_id DESC
840
+ LIMIT 10"
841
+ );
842
+
843
+ //count run twice but access data only once: tested with query monitor and asked
844
+ //here http://stackoverflow.com/questions/39201235/does-count-run-twice/39201492
845
+ $this->query_result_highest_rated_visitor = $wpdb->get_results(
846
+ "SELECT post_id,
847
+ COUNT(post_id) AS number_of_votes,
848
+ (SUM(vote) / COUNT(post_id)) AS result
849
+ FROM " . YASR_LOG_TABLE . " ,
850
+ $wpdb->posts AS p
851
+ WHERE post_id = p.ID
852
+ AND p.post_status = 'publish'
853
+ GROUP BY post_id
854
+ HAVING COUNT(post_id) >= 2
855
+ ORDER BY result DESC,
856
+ number_of_votes DESC
857
+ LIMIT 10"
858
+ );
859
+
860
+ $this->vv_highest_rated_table = "<table class='yasr-table-chart' id='yasr-highest-rated-posts'>
861
+ <tr class='yasr-visitor-votes-title'>
862
+ <th>" . __('Post / Page', 'yet-another-stars-rating') . "</th>
863
+ <th>" . __('Order By', 'yet-another-stars-rating') . ":&nbsp;&nbsp;
864
+ <span id='link-yasr-most-rated-posts'>
865
+ <a href='' onclick='yasrShowMost(); return false'>"
866
+ . __("Most Rated", 'yet-another-stars-rating') .
867
+ "</a> |
868
+ <span id='yasr_multi_chart_link_to_nothing'>"
869
+ . __("Highest Rated", 'yet-another-stars-rating') .
870
+ "</span>
871
+ </th>
872
+ </tr>";
873
+
874
+ $this->vv_most_rated_table = "<table class='yasr-table-chart' id='yasr-most-rated-posts'>
875
+ <tr class='yasr-visitor-votes-title'>
876
+ <th>" . __('Post / Page', 'yet-another-stars-rating') . " </th>
877
+ <th>" . __('Order By', 'yet-another-stars-rating') . ":&nbsp;&nbsp;
878
+ <span id='yasr_multi_chart_link_to_nothing'>"
879
+ . __('Most Rated', 'yet-another-stars-rating') .
880
+ "</span> |
881
+ <span id='link-yasr-highest-rated-posts'>
882
+ <a href='' onclick='yasrShowHighest(); return false'>"
883
+ . __('Highest Rated', 'yet-another-stars-rating') .
884
+ "</a>
885
+ </span>
886
+ </th>
887
+ </tr>";
888
+
889
+ $this->vvMostRated();
890
+ $this->vvHighestRated();
891
+
892
+ $this->shortcode_html .= '<!-- End Yasr Most Or Highest Rated Shortcode-->';
893
+
894
+ wp_localize_script( 'yasrfront', "yasrMostHighestRanking", array(
895
+ 'enable' => 'yes'
896
+ )
897
+ );
898
+
899
+ return $this->shortcode_html;
900
+
901
+ }
902
+
903
+ /**
904
+ * Loop the query for the Most Rated chart
905
+ */
906
+ protected function vvMostRated() {
907
+ if ($this->query_result_most_rated_visitor) {
908
+
909
+ $this->shortcode_html .= $this->vv_most_rated_table;
910
+
911
+ foreach ($this->query_result_most_rated_visitor as $result) {
912
+ $rating = round($result->sum_votes / $result->number_of_votes, 1);
913
+ $post_title = wp_strip_all_tags(get_the_title($result->post_id));
914
+ $link = get_permalink($result->post_id); //Get permalink from post id
915
+ $yasr_top_ten_html_id = 'yasr-10-most-rated-' . str_shuffle(uniqid());
916
+
917
+ //print the rows
918
+ $this->returnTableRows($result->post_id,
919
+ $rating,
920
+ $result->number_of_votes,
921
+ $post_title,
922
+ $link,
923
+ $yasr_top_ten_html_id
924
+ );
925
+
926
+ } //End foreach
927
+ $this->shortcode_html .= "</table>" ;
928
+
929
+ } //End if $query_result_most_rated)
930
+
931
+ else {
932
+ $this->shortcode_html = __("You've not enough data",'yet-another-stars-rating') . "<br />";
933
+ }
934
+ }
935
+
936
+ /**
937
+ * Loop the query for the Highest Rated chart
938
+ */
939
+ protected function vvHighestRated () {
940
+ if ($this->query_result_highest_rated_visitor) {
941
+
942
+ $this->shortcode_html .= $this->vv_highest_rated_table;
943
+
944
+ foreach ($this->query_result_highest_rated_visitor as $result) {
945
+ $rating = round($result->result, 1);
946
+ $post_title = wp_strip_all_tags(get_the_title($result->post_id));
947
+ $link = get_permalink($result->post_id); //Get permalink from post id
948
+ $yasr_top_ten_html_id = 'yasr-10-highest-rater-' . str_shuffle(uniqid());
949
+
950
+ //print the rows
951
+ $this->returnTableRows($result->post_id,
952
+ $rating,
953
+ $result->number_of_votes,
954
+ $post_title,
955
+ $link,
956
+ $yasr_top_ten_html_id
957
+ );
958
+
959
+ } //End foreach
960
+
961
+ $this->shortcode_html .= "</table>";
962
+
963
+ } //end if $query_result
964
+
965
+ else {
966
+ $this->shortcode_html = __("You've not enought data",'yet-another-stars-rating') . "<br />";
967
+ }
968
+ }
969
+
970
+ /**
971
+ * @param $post_id
972
+ * @param $rating
973
+ * @param $number_of_votes
974
+ * @param $post_title
975
+ * @param $link
976
+ * @param $yasr_top_ten_html_id
977
+ */
978
+ protected function returnTableRows ($post_id, $rating, $number_of_votes, $post_title, $link, $yasr_top_ten_html_id) {
979
+ $star_size = $this->starSize();
980
+
981
+ $html_stars = "<div
982
+ class='yasr-rater-stars'
983
+ id='$yasr_top_ten_html_id'
984
+ data-rater-postid='$post_id'
985
+ data-rater-starsize=$star_size
986
+ data-rating='$rating'>
987
+ </div>";
988
+
989
+ //if number of votes === null means that the caller is loopHighestRatedOverall
990
+ if ($number_of_votes === null) {
991
+
992
+ $div_html_stars=apply_filters('yasr_filter_highest_rated_stars', $html_stars, $rating);
993
+
994
+ if ($div_html_stars === $html_stars) {
995
+ $div_html_stars .= "<span class='yasr-highest-rated-text'>"
996
+ . __('Rating:', 'yet-another-stars-rating') . " $rating
997
+ </span>";
998
+ }
999
+
1000
+ $this->shortcode_html .= "<tr>
1001
+ <td class='yasr-top-10-overall-left'>
1002
+ <a href='$link'>$post_title</a>
1003
+ </td>
1004
+ <td class='yasr-top-10-overall-right'>
1005
+ $div_html_stars
1006
+ </td>
1007
+ </tr>";
1008
+
1009
+ }
1010
+
1011
+ //otherwise is vvMostRated or vvHighestRated
1012
+ else {
1013
+ $this->shortcode_html .= "<tr>
1014
+ <td class='yasr-top-10-most-highest-left'>
1015
+ <a href='$link'>$post_title</a>
1016
+ </td>
1017
+ <td class='yasr-top-10-most-highest-right'>
1018
+ $html_stars
1019
+ <br />
1020
+ ["
1021
+ . __('Total:', 'yet-another-stars-rating') .
1022
+ "$number_of_votes &nbsp;&nbsp;&nbsp;" .
1023
+ __('Average', 'yet-another-stars-rating') .
1024
+ " $rating]
1025
+ </td>
1026
+ </tr>";
1027
+
1028
+ }
1029
+ } //end function returnTableRows
1030
+
1031
+ }
lib/yasr-shortcode-functions.php CHANGED
@@ -22,6 +22,8 @@ if (!defined('ABSPATH')) {
22
  exit('You\'re not allowed to see this page');
23
  } // Exit if accessed directly
24
 
 
 
25
  /****** Add shortcode for overall rating ******/
26
  add_shortcode('yasr_overall_rating', 'shortcode_overall_rating_callback');
27
 
@@ -31,67 +33,11 @@ function shortcode_overall_rating_callback ($atts) {
31
  return null;
32
  }
33
 
34
- $atts = shortcode_atts(
35
- array(
36
- 'size' => 'large',
37
- 'postid' => false
38
- ),
39
- $atts,
40
- 'yasr_overall_rating'
41
- );
42
-
43
- $size = $atts['size'];
44
- $postid = $atts['postid'];
45
-
46
- if ($postid === false) {
47
- $postid = get_the_ID();
48
- }
49
-
50
- $overall_rating = yasr_get_overall_rating($postid);
51
-
52
- //if still false
53
- if (!$overall_rating) {
54
- $overall_rating = "-1";
55
- }
56
-
57
- $shortcode_html = '<!--Yasr Overall Rating Shortcode-->';
58
-
59
- $stars_attribute = yasr_stars_size($size);
60
-
61
- //generate an unique id to be sure that every element has a different ID
62
- $unique_id = str_shuffle(uniqid());
63
-
64
- $overall_rating_html_id = 'yasr-overall-rating-rater-' . $unique_id;
65
- $html_stars = "<div class='yasr-overall-rating'>
66
- <div class=\"yasr-rater-stars\" id=\"$overall_rating_html_id\" data-rating=\"$overall_rating\" data-rater-starsize=\"$stars_attribute[px_size]\" ></div>
67
- </div>
68
- ";
69
-
70
- if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_BEFORE_OVERALL != '') {
71
- $text_before_star = str_replace('%overall_rating%', $overall_rating, YASR_TEXT_BEFORE_OVERALL);
72
- $shortcode_html = "<div class=\"yasr-container-custom-text-and-overall\">
73
- <span id=\"yasr-custom-text-before-overall\">" . $text_before_star . "</span>
74
- $html_stars
75
- </div>";
76
- } else {
77
- $shortcode_html .= $html_stars;
78
- }
79
-
80
- $shortcode_html .= '<!--End Yasr Overall Rating Shortcode-->';
81
-
82
- //If overall rating in loop is enabled don't use is_singular && is main_query
83
- if (YASR_SHOW_OVERALL_IN_LOOP === 'enabled') {
84
- return $shortcode_html;
85
- }
86
 
87
- //default
88
- else {
89
- if (is_singular() && is_main_query()) {
90
- return $shortcode_html;
91
- }
92
- }
93
 
94
- return null;
95
  } //end function
96
 
97
 
@@ -105,536 +51,33 @@ function shortcode_visitor_votes_callback($atts) {
105
  return null;
106
  }
107
 
108
- $shortcode_html = null; //Avoid undefined variable outside is_singular && is_main_query
109
-
110
- $atts = shortcode_atts(
111
- array(
112
- 'size' => 'large',
113
- 'postid' => false,
114
- 'readonly' => false
115
- ),
116
- $atts,
117
- 'yasr_visitor_votes'
118
- );
119
-
120
-
121
- $size = $atts['size'];
122
- $post_id = $atts['postid'];
123
- $readonly = $atts['readonly'];
124
-
125
- //If it's not specified use get_the_id
126
- if ($post_id === false) {
127
- $post_id = get_the_ID();
128
- }
129
-
130
- $votes=yasr_get_visitor_votes($post_id); //always reference it
131
-
132
- $unique_id = str_shuffle(uniqid());
133
-
134
- $medium_rating=0; //Avoid undefined variable
135
-
136
- if (!$votes) {
137
- $votes = null; //Avoid undefined variable if there is not rating
138
- $votes_number=0; //Avoid undefined variable
139
- } else {
140
- foreach ($votes as $user_votes) {
141
- $votes_number = $user_votes->number_of_votes;
142
-
143
- if ($votes_number != 0) {
144
- $medium_rating = ($user_votes->sum_votes/$votes_number);
145
- } else {
146
- $medium_rating = 0;
147
- }
148
- }
149
- }
150
-
151
- $medium_rating=round($medium_rating, 1);
152
-
153
- $stars_attribute = yasr_stars_size($size);
154
-
155
- if (is_singular()) {
156
- $is_singular = 'true';
157
- } else {
158
- $is_singular = 'false';
159
- }
160
-
161
- //if this come from yasr_visitor_votes_readonly...
162
- if ($readonly === true || $readonly === "yes") {
163
- $htmlid = 'yasr-visitor-votes-readonly-rater-'.$unique_id;
164
-
165
- $shortcode_html = "<div class=\"yasr-rater-stars-visitor-votes\" id=\"$htmlid\" data-rating=\"$medium_rating\"
166
- data-rater-starsize=\"$stars_attribute[px_size]\" data-rater-postid=\"$post_id\"
167
- data-rater-readonly=\"true\"></div>";
168
-
169
- return $shortcode_html;
170
- }
171
-
172
- $ajax_nonce_visitor = wp_create_nonce("yasr_nonce_insert_visitor_rating");
173
-
174
- //name of cookie to check
175
- $yasr_cookiename = 'yasr_visitor_vote_cookie';
176
-
177
- $cookie_value = false; //avoid undefined
178
-
179
- if (isset($_COOKIE[$yasr_cookiename])) {
180
- $cookie_data = stripslashes($_COOKIE[$yasr_cookiename]);
181
-
182
- //By default, json_decode return an object, true to return an array
183
- $cookie_data = json_decode($cookie_data, true);
184
-
185
- if (is_array($cookie_data)) {
186
- foreach ($cookie_data as $value) {
187
- $cookie_post_id = (int)$value['post_id'];
188
-
189
- if ($cookie_post_id === $post_id) {
190
- $cookie_value = (int)$value['rating'];
191
- //Stop doing foreach, here we've found the rating for current post
192
- break;
193
- }
194
- }
195
- }
196
-
197
- if ($cookie_value !== false && $cookie_value > 5) {
198
- $cookie_value = 5;
199
- } elseif ($cookie_value !== false && $cookie_value < 1) {
200
- $cookie_value = 1;
201
- }
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 = "";
208
-
209
- //I've to check a logged in user that has already rated
210
- if (is_user_logged_in()) {
211
- $readonly = 'false'; //Always false if user is logged in
212
 
213
- //Check if a logged in user has already rated for this post
214
- $vote_if_user_already_rated = yasr_check_if_user_already_voted($post_id);
215
-
216
- //If user has already rated
217
- if ($vote_if_user_already_rated) {
218
- $span_bottom_line="<span class=\"yasr-small-block-bold yasr-already-voted-text \"
219
- id=\"yasr-user-vote-$post_id\" data-yasr-already-voted=\"$vote_if_user_already_rated\">"
220
- . __("You've already voted this article with", 'yet-another-stars-rating') .
221
- " $vote_if_user_already_rated</span>";
222
- }
223
-
224
- } //End if user is logged
225
-
226
- //if anonymous are allowed to vote
227
- if (YASR_ALLOWED_USER === 'allow_anonymous') {
228
- //IF user is not logged in
229
- if (!is_user_logged_in()) {
230
- //if cookie exists
231
- if ($cookie_value) {
232
- $readonly = 'true';
233
- if (YASR_TEXT_BEFORE_STARS == 1 && YASR_CUSTOM_TEXT_USER_VOTED!='') {
234
- $span_bottom_line="<span class=\"yasr-small-block-bold yasr-already-voted-text\">"
235
- . YASR_CUSTOM_TEXT_USER_VOTED .
236
- " </span>";
237
- } else {
238
- $span_bottom_line="<span class=\"yasr-small-block-bold yasr-already-voted-text \">"
239
- . __("You've already voted this article with", 'yet-another-stars-rating') .
240
- " $cookie_value</span>";
241
- }
242
- } else {
243
- $readonly = 'false';
244
- }
245
- }
246
- } //end if YASR_ALLOWED_USER === 'allow_anonymous' {
247
-
248
-
249
- //If only logged in users can vote
250
- elseif (YASR_ALLOWED_USER === 'logged_only') {
251
- //IF user is not logged in
252
- if (!is_user_logged_in()) {
253
- $readonly = 'true'; //readonly is true if user isn't logged
254
-
255
- $span_bottom_line = "<span class=\"yasr-visitor-votes-must-sign-in\">";
256
-
257
- //if custom text is defined
258
- if (defined('YASR_CUSTOM_TEXT_MUST_SIGN_IN') && YASR_CUSTOM_TEXT_MUST_SIGN_IN !== '') {
259
- $span_bottom_line .= YASR_CUSTOM_TEXT_MUST_SIGN_IN;
260
- } else {
261
- $span_bottom_line .= __('You must sign in to vote', 'yet-another-stars-rating');
262
- }
263
-
264
- $span_bottom_line .= "</span>";
265
- }
266
-
267
- }
268
-
269
- if (YASR_VISITORS_STATS === 'yes') {
270
-
271
- global $yasr_plugin_imported;
272
-
273
- //default
274
- $span_dashicon = "<span class='dashicons dashicons-chart-bar yasr-dashicons-visitor-stats'
275
- data-postid='$post_id' id='yasr-total-average-dashicon-$post_id'></span>";
276
-
277
- if (is_array($yasr_plugin_imported)) {
278
- if (array_key_exists('wppr', $yasr_plugin_imported)) {
279
- $plugin_import_date = $yasr_plugin_imported['wppr']['date'];
280
- }
281
-
282
- if (array_key_exists('kksr', $yasr_plugin_imported)) {
283
- $plugin_import_date = $yasr_plugin_imported['kksr']['date'];
284
- }
285
-
286
- if (array_key_exists('mr', $yasr_plugin_imported)) {
287
- $plugin_import_date = $yasr_plugin_imported['mr']['date'];
288
- }
289
-
290
- //remove hour from date
291
- $plugin_import_date=strtok($plugin_import_date,' ');
292
-
293
- $post_date = get_the_date('Y-m-d', $post_id);
294
-
295
- //if one of these plugin has been imported and post is older then import, hide stats
296
- if ($post_date < $plugin_import_date) {
297
- $span_dashicon = "";
298
- }
299
-
300
- }
301
-
302
- } else {
303
- //Yasr_visitor_stats are disabled
304
- $span_dashicon = "";
305
- }
306
-
307
-
308
- if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_BEFORE_VISITOR_RATING != '') {
309
- $text_before_star = str_replace('%total_count%', $votes_number, YASR_TEXT_BEFORE_VISITOR_RATING);
310
- $text_before_star = str_replace('%average%', $medium_rating, $text_before_star);
311
- $shortcode_html .= "<div class=\"yasr-container-custom-text-and-visitor-rating\">
312
- <span id=\"yasr-custom-text-before-visitor-rating\">" . $text_before_star . "</span></div>";
313
- }
314
-
315
- if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_AFTER_VISITOR_RATING != '') {
316
- $text_after_star = str_replace('%total_count%', $votes_number, YASR_TEXT_AFTER_VISITOR_RATING);
317
- $text_after_star = str_replace('%average%', $medium_rating, $text_after_star);
318
- $span_text_after_star = "<span class=\"yasr-total-average-container\" id=\"yasr-total-average-text_$post_id\">"
319
- . $text_after_star .
320
- "</span>";
321
- } else {
322
- $span_text_after_star = "<span class=\"yasr-total-average-container\" id=\"yasr-total-average-text_$post_id\">
323
- [" . __("Total: ", 'yet-another-stars-rating') . "$votes_number &nbsp; &nbsp;" .
324
- __('Average: ', 'yet-another-stars-rating') . "$medium_rating/5]
325
- </span>";
326
- }
327
-
328
- $span_container_after_stars = "<span id=\"yasr-visitor-votes-container-after-stars-$unique_id\"
329
- class='yasr-visitor-votes-after-stars-class'>";
330
-
331
- $htmlid = 'yasr-visitor-votes-rater-' . $unique_id ;
332
-
333
- $shortcode_html .= "<div id=\"$htmlid\" class=\"yasr-rater-stars-visitor-votes\" data-rater-postid=\"$post_id\"
334
- data-rating=\"$medium_rating\" data-rater-starsize=\"$stars_attribute[px_size]\"
335
- data-rater-readonly=\"$readonly\" data-rater-nonce=\"$ajax_nonce_visitor\" data-issingular=\"$is_singular\">
336
- </div>";
337
-
338
- $shortcode_html .= $span_container_after_stars;
339
- $shortcode_html .= $span_dashicon;
340
- $shortcode_html .= $span_text_after_star;
341
- $shortcode_html .= $span_bottom_line;
342
- $shortcode_html .= '</span>'; //Close yasr-visitor-votes-after-stars and yasr_visitor_votes
343
- $shortcode_html .= '</div>'; //close all
344
- $shortcode_html .= '<!--End Yasr Visitor Votes Shortcode-->';
345
-
346
- //If overall rating in loop is enabled don't use is_singular && is main_query
347
- if (YASR_SHOW_VISITOR_VOTES_IN_LOOP === 'enabled') {
348
- return $shortcode_html;
349
- }
350
-
351
- //default value
352
- else {
353
- if (is_singular() && is_main_query()) {
354
- return $shortcode_html;
355
- }
356
- }
357
-
358
- return null;
359
 
360
  } //End function shortcode_visitor_votes_callback
361
 
362
-
363
- /*
364
- * Show visitor votes average, READ ONLY
365
- */
366
- add_shortcode ('yasr_visitor_votes_readonly', 'yasr_visitor_votes_readonly_callback');
367
-
368
- function yasr_visitor_votes_readonly_callback($atts) {
369
-
370
- $atts['readonly'] = true;
371
-
372
- //Here I call the same function that draw the same function for yasr_visitor_votes,
373
- //passing the attribute readonly = true
374
- $shortcode_html = shortcode_visitor_votes_callback($atts);
375
-
376
- return $shortcode_html;
377
-
378
- } //End function shortcode_visitor_votes_only_stars_callback
379
-
380
-
381
  /****** Add shortcode for multiple set ******/
382
 
383
- add_shortcode ('yasr_multiset', 'shortcode_multi_set_callback');
384
-
385
- function shortcode_multi_set_callback($atts) {
386
-
387
- // Attributes
388
- $atts = shortcode_atts(
389
- array(
390
- 'setid' => '1',
391
- 'postid' => false,
392
- 'show_average' => null
393
- ),
394
- $atts,
395
- 'yasr_multiset'
396
- );
397
 
398
- $post_id = (int)$atts['postid'];
399
- $set_id = (int)$atts['setid'];
400
- $show_average = $atts['show_average'];
401
-
402
- //If it's not specified use get_the_id
403
- if (!$post_id) {
404
- $post_id = get_the_ID();
405
- }
406
-
407
- $shortcode_html = '<!-- Yasr Multi Set Shortcode-->';
408
-
409
- //set fields name and ids
410
- $set_fields = yasr_get_multi_set_fields($set_id);
411
-
412
- //If there is no set for that id, return
413
- if (!$set_fields) {
414
- $string = __('No Set Found with this ID', 'yet-another-stars-rating');
415
- return $shortcode_html . $string;
416
- }
417
-
418
- //set meta values
419
- $set_post_meta_values = get_post_meta($post_id, 'yasr_multiset_author_votes', true);
420
- $multiset_content = yasr_return_multiset_array_with_ratings($set_id, $set_fields, $set_post_meta_values);
421
-
422
- $multiset_vote_sum = 0;//avoid undefined variable
423
- $multiset_rows_number = 0;//avoid undefined variable
424
-
425
- $shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
426
- $shortcode_html.='<table class="yasr_table_multi_set_shortcode">';
427
-
428
- foreach ($multiset_content as $set_content) {
429
- //Avoid undefined if vote does not exists
430
- $unique_id_identifier = 'yasr-multiset-' . str_shuffle(uniqid());
431
-
432
- $shortcode_html .= '<tr>
433
- <td>
434
- <span class="yasr-multi-set-name-field">'
435
- . $set_content['value_name'] .
436
- '</span>
437
- </td>
438
- <td>
439
- <div class="yasr-rater-stars"
440
- id="'.$unique_id_identifier.'"
441
- data-rater-postid="'.$post_id.'"
442
- data-rating="'.$set_content['value_rating'].'"
443
- data-rater-starsize="16">
444
- </div>
445
- </td>
446
- </tr>';
447
-
448
- $multiset_vote_sum = $multiset_vote_sum + $set_content['value_rating'];
449
- $multiset_rows_number++;
450
-
451
- }
452
-
453
- $multiset_average = $multiset_vote_sum / $multiset_rows_number;
454
- $multiset_average = round($multiset_average, 1);
455
- $multiset_string = 'yasr-average-multiset-';
456
-
457
- $shortcode_html .= yasr_return_average_multiset($show_average, $multiset_average, $multiset_string);
458
-
459
- $shortcode_html.="</table>";
460
- $shortcode_html .= '<!--End Yasr Multi Set Shortcode-->';
461
-
462
- return $shortcode_html;
463
-
464
- } //End function
465
 
 
 
466
 
467
  /****** Add shortcode for multiset writable by users ******/
468
 
469
  add_shortcode ('yasr_visitor_multiset', 'yasr_visitor_multiset_callback');
470
 
471
  function yasr_visitor_multiset_callback($atts) {
 
 
472
 
473
- $ajax_nonce_visitor_multiset = wp_create_nonce( "yasr_nonce_insert_visitor_rating_multiset" );
474
-
475
- // Attributes
476
- $atts = shortcode_atts(
477
- array(
478
- 'setid' => '1',
479
- 'postid' => false,
480
- 'show_average' => null
481
- ),
482
- $atts,
483
- 'yasr_multiset'
484
- );
485
-
486
- $post_id = $atts['postid'];
487
- $setid = $atts['setid'];
488
- $show_average = $atts['show_average'];
489
-
490
- //If it's not specified use get_the_id
491
- if (!$post_id) {
492
- $post_id = get_the_ID();
493
- }
494
-
495
- $image = YASR_IMG_DIR . "/loader.gif";
496
- $loader_html = "<span class='yasr-loader-multiset-visitor' id='yasr-loader-multiset-visitor-$post_id-$setid' >&nbsp;
497
- <img src='$image' title='yasr-loader' alt='yasr-loader'></span>";
498
-
499
- $button_html = "<input type='submit' name='submit' id='yasr-send-visitor-multiset-$post_id-$setid'
500
- class='button button-primary yasr-send-visitor-multiset' data-postid='$post_id' data-setid='$setid'
501
- value='" . __('Submit!', 'yet-another-stars-rating') . "' />";
502
-
503
- $button_html_disabled = '<input type="submit" disabled="disabled" class="button button-primary"
504
- id="yasr-send-visitor-multiset-disabled" disabled="disabled"
505
- value="'.__('Submit!', 'yet-another-stars-rating').'" >';
506
- $yasr_cookiename = 'yasr_multi_visitor_cookie';
507
-
508
- //Check cookie and if voting is allowed only to logged in users
509
- if (isset($_COOKIE[$yasr_cookiename])) {
510
- $cookie_data = stripslashes($_COOKIE[ $yasr_cookiename ]);
511
-
512
- //By default, json_decode return an object, true to return an array
513
- $cookie_data = json_decode($cookie_data, true);
514
-
515
- if (is_array($cookie_data)) {
516
- foreach ($cookie_data as $value) {
517
- $cookie_post_id = (int)$value['post_id'];
518
- $cookie_set_id = (int)$value['set_id'];
519
-
520
- if ($cookie_post_id === $post_id && $cookie_set_id == $setid) {
521
- $button = "";
522
- $star_readonly = 'true';
523
- $span_message_content = __('Thank you for voting! ', 'yet-another-stars-rating');
524
-
525
- //Stop doing foreach, here we've found the rating for current post
526
- break;
527
- } else {
528
- $button = $button_html;
529
- $star_readonly = 'false';
530
- $span_message_content = "";
531
- }
532
- }
533
- }
534
- }
535
-
536
- else {
537
- //If user is not logged in
538
- if (!is_user_logged_in()) {
539
- if (YASR_ALLOWED_USER === 'allow_anonymous') {
540
- $button = $button_html;
541
- $star_readonly = 'false';
542
- $span_message_content = "";
543
- } elseif (YASR_ALLOWED_USER === 'logged_only') {
544
- $button = $button_html_disabled;
545
- $star_readonly = 'true';
546
- $span_message_content = '<span class="yasr-visitor-votes-must-sign-in">';
547
-
548
- if (defined('YASR_CUSTOM_TEXT_MUST_SIGN_IN') && YASR_CUSTOM_TEXT_MUST_SIGN_IN !== '') {
549
- $span_message_content .= YASR_CUSTOM_TEXT_MUST_SIGN_IN;
550
- } else {
551
- $span_message_content .= __('You must sign in to vote', 'yet-another-stars-rating');
552
- }
553
-
554
- $span_message_content .= '</span>';
555
-
556
- }
557
-
558
- } //End if user logged in
559
-
560
- //User is logged in
561
- else {
562
- $button = $button_html;
563
- $star_readonly = 'false';
564
- $span_message_content = "";
565
- }
566
-
567
- }
568
-
569
- $set_name_content = yasr_get_multi_set_visitor ($post_id, $setid);
570
-
571
- $shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
572
-
573
- if (!$set_name_content) {
574
- $shortcode_html = __('No MultiSet found with this ID', 'yet-another-stars-rating');
575
-
576
- return $shortcode_html;
577
- }
578
-
579
- $shortcode_html.="<table class=\"yasr_table_multi_set_shortcode\">";
580
- $multiset_vote_sum = 0;//avoid undefined variable
581
- $multiset_rows_number = 0;//avoid undefined variable
582
-
583
- foreach ($set_name_content as $set_content) {
584
- $average_rating = round($set_content->average_rating, 1);
585
-
586
- $unique_id_identifier = 'yasr-visitor-multi-set-' . str_shuffle(uniqid());
587
-
588
- $html_stars = "<div class='yasr-multiset-visitors-rater' id='$unique_id_identifier'
589
- data-rater-postid='$post_id' data-rater-setid='$setid' data-rater-set-field-id='$set_content->id'
590
- data-rating='$average_rating' data-rater-readonly='$star_readonly' ></div>";
591
-
592
- $shortcode_html .="<tr>
593
- <td>
594
- <span class=\"yasr-multi-set-name-field\">$set_content->name </span>
595
- </td>
596
- <td>
597
- $html_stars
598
- <span class=\"yasr-visitor-multiset-vote-count\">$set_content->number_of_votes</span>
599
- </td>
600
- </tr>";
601
-
602
- $multiset_vote_sum = $multiset_vote_sum + $average_rating;
603
- $multiset_rows_number++;
604
-
605
- } //End foreach
606
-
607
- $multiset_average = $multiset_vote_sum / $multiset_rows_number;
608
- $multiset_average = round($multiset_average, 1);
609
- $multiset_string = 'yasr-visitor-multi-set-average-';
610
-
611
- $shortcode_html .= yasr_return_average_multiset($show_average, $multiset_average, $multiset_string);
612
-
613
- //Submit row and button
614
- $shortcode_html.="<tr>
615
- <td colspan='2'>
616
- $button
617
- $loader_html
618
- <span class='yasr-visitor-multiset-message'>$span_message_content</span>
619
- </td>
620
- </tr>
621
- ";
622
-
623
- $shortcode_html.="</table>";
624
- $shortcode_html .= '<!-- End Yasr Multi Set Visitor Shortcode-->';
625
-
626
- wp_localize_script(
627
- 'yasrfront',
628
- "yasrMultiSetData",
629
- array(
630
- 'nonceVisitor' => $ajax_nonce_visitor_multiset,
631
- 'setType' => $setid
632
- )
633
- );
634
-
635
-
636
- return $shortcode_html;
637
-
638
  }
639
 
640
 
@@ -643,57 +86,9 @@ return $shortcode_html;
643
  add_shortcode ('yasr_top_ten_highest_rated', 'yasr_top_ten_highest_rated_callback');
644
 
645
  function yasr_top_ten_highest_rated_callback() {
 
646
 
647
- global $wpdb;
648
-
649
- $query_result = $wpdb->get_results("SELECT pm.meta_value AS overall_rating, pm.post_id AS post_id
650
- FROM $wpdb->postmeta AS pm, $wpdb->posts AS p
651
- WHERE pm.post_id = p.ID
652
- AND p.post_status = 'publish'
653
- AND pm.meta_key = 'yasr_overall_rating'
654
- ORDER BY pm.meta_value DESC, pm.post_id LIMIT 10");
655
-
656
-
657
- $shortcode_html = '<!-- Yasr Top 10 highest Rated Shortcode-->';
658
-
659
- if ($query_result) {
660
- $shortcode_html .= "<table class=\"yasr-table-chart\">";
661
-
662
- foreach ($query_result as $result) {
663
- $post_title = wp_strip_all_tags(get_the_title($result->post_id));
664
- $link = get_permalink($result->post_id); //Get permalink from post it
665
-
666
- $yasr_top_ten_html_id = 'yasr-top-ten-rater-' . str_shuffle(uniqid());
667
- $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\"
668
- data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\"
669
- data-rating=\"$result->overall_rating\"></div>";
670
-
671
-
672
- $shortcode_html .= "<tr>
673
- <td width=\"60%\" class=\"yasr-top-10-overall-left\">
674
- <a href=\"$link\">$post_title</a>
675
- </td>
676
- <td width=\"40%\" class=\"yasr-top-10-overall-right\">
677
- $html_stars
678
- <span class=\"yasr-highest-rated-text\">"
679
- . __("Rating", 'yet-another-stars-rating') . " $result->overall_rating
680
- </span>
681
- </td>
682
- </tr>";
683
-
684
-
685
- } //End foreach
686
-
687
- $shortcode_html .= "</table>";
688
- $shortcode_html .= '<!--End Yasr Top 10 highest Rated Shortcode-->';
689
- return $shortcode_html;
690
-
691
- } //end if $query_result
692
-
693
- else {
694
- _e("You don't have any votes stored", 'yet-another-stars-rating');
695
- }
696
-
697
  } //End function
698
 
699
 
@@ -702,128 +97,9 @@ function yasr_top_ten_highest_rated_callback() {
702
  add_shortcode ('yasr_most_or_highest_rated_posts', 'yasr_most_or_highest_rated_posts_callback');
703
 
704
  function yasr_most_or_highest_rated_posts_callback () {
 
705
 
706
- $shortcode_html = '<!-- Yasr Most Or Highest Rated Shortcode-->';
707
-
708
- global $wpdb;
709
-
710
- $query_result_most_rated = $wpdb->get_results ("SELECT post_id, COUNT(post_id) AS number_of_votes, SUM(vote) AS sum_votes
711
- FROM " . YASR_LOG_TABLE . " , $wpdb->posts AS p
712
- WHERE post_id = p.ID
713
- AND p.post_status = 'publish'
714
- GROUP BY post_id
715
- HAVING number_of_votes > 1
716
- ORDER BY number_of_votes DESC, post_id
717
- LIMIT 10
718
- ");
719
-
720
-
721
- //count run twice but access data only once: tested with query monitor and asked
722
- //here http://stackoverflow.com/questions/39201235/does-count-run-twice/39201492
723
- $query_result_highest = $wpdb->get_results ("SELECT post_id, COUNT(post_id) AS number_of_votes, (SUM(vote) / COUNT(post_id)) AS result
724
- FROM " . YASR_LOG_TABLE . " , $wpdb->posts AS p
725
- WHERE post_id = p.ID
726
- AND p.post_status = 'publish'
727
- GROUP BY post_id
728
- HAVING COUNT(post_id) >= 2
729
- ORDER BY result DESC, number_of_votes DESC
730
- LIMIT 10
731
- ");
732
-
733
- if ($query_result_most_rated) {
734
- $shortcode_html .= "<table class=\"yasr-table-chart\" id=\"yasr-most-rated-posts\">
735
- <tr class=\"yasr-visitor-votes-title\">
736
- <th>" . __("Post / Page" , 'yet-another-stars-rating') ." </th>
737
- <th>". __("Order By" , 'yet-another-stars-rating') .":&nbsp;&nbsp;
738
- <span id=\"yasr_multi_chart_link_to_nothing\">" . __("Most Rated" , 'yet-another-stars-rating') ."</span> |
739
- <span id=\"link-yasr-highest-rated-posts\"><a href=\"\" onclick='yasrShowHighest(); return false'>" . __("Highest Rated" , 'yet-another-stars-rating') ."</a></span>
740
- </th>
741
- </tr>"
742
- ;
743
-
744
- foreach ($query_result_most_rated as $result) {
745
-
746
- $rating = $result->sum_votes / $result->number_of_votes;
747
-
748
- $rating = round($rating, 1);
749
-
750
- $post_title = wp_strip_all_tags(get_the_title($result->post_id));
751
-
752
- $link = get_permalink($result->post_id); //Get permalink from post it
753
-
754
- $yasr_top_ten_html_id = 'yasr-10-most-rater' . str_shuffle(uniqid());
755
- $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>";
756
-
757
- $shortcode_html .= "<tr>
758
- <td width=\"60%\" class=\"yasr-top-10-most-highest-left\"><a href=\"$link\">$post_title</a></td>
759
- <td width=\"40%\" class=\"yasr-top-10-most-highest-right\">
760
- $html_stars
761
- <br /> [" . __( "Total:", 'yet-another-stars-rating' ) . "$result->number_of_votes &nbsp;&nbsp;&nbsp;" . __( "Average", 'yet-another-stars-rating' ) . " $rating]
762
- </td>
763
- </tr>";
764
-
765
- } //End foreach
766
-
767
- $shortcode_html .= "</table>" ;
768
-
769
- } //End if $query_result_most_rated)
770
-
771
- else {
772
- $shortcode_html = __("You've not enough data",'yet-another-stars-rating') . "<br />";
773
- }
774
-
775
-
776
- if ($query_result_highest) {
777
-
778
- $shortcode_html .= "<table class=\"yasr-table-chart\" id=\"yasr-highest-rated-posts\">
779
- <tr class=\"yasr-visitor-votes-title\">
780
- <th>" . __("Post / Page" , 'yet-another-stars-rating') ." </th>
781
- <th>". __("Order By" , 'yet-another-stars-rating') .":&nbsp;&nbsp;
782
- <span id=\"link-yasr-most-rated-posts\"><a href=\"\" onclick='yasrShowMost(); return false'>". __("Most Rated" , 'yet-another-stars-rating') . "</a> |
783
- <span id=\"yasr_multi_chart_link_to_nothing\">". __("Highest Rated" , 'yet-another-stars-rating') ."</span>
784
- </th>
785
- </tr>";
786
-
787
- foreach ($query_result_highest as $result) {
788
-
789
- $rating = round($result->result, 1);
790
-
791
- $post_title = wp_strip_all_tags(get_the_title($result->post_id));
792
-
793
- $link = get_permalink($result->post_id); //Get permalink from post it
794
-
795
- $yasr_top_ten_html_id = 'yasr-10-highest-rater-' . str_shuffle(uniqid());
796
- $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>";
797
-
798
- $shortcode_html .= "<tr>
799
- <td width=\"60%\" class=\"yasr-top-10-most-highest-left\"><a href=\"$link\">$post_title</a></td>
800
- <td width=\"40%\" class=\"yasr-top-10-most-highest-right\">
801
- $html_stars
802
- <br /> [" . __("Total:" , 'yet-another-stars-rating') . "$result->number_of_votes &nbsp;&nbsp;&nbsp;" . __("Average" , 'yet-another-stars-rating') . " $rating]
803
- </td>
804
- </tr>";
805
-
806
-
807
- } //End foreach
808
-
809
- $shortcode_html .= "</table>";
810
-
811
- } //end if $query_result
812
-
813
- else {
814
- $shortcode_html = __("You've not enought data",'yet-another-stars-rating') . "<br />";
815
- }
816
-
817
- $shortcode_html .= '<!-- End Yasr Most Or Highest Rated Shortcode-->';
818
-
819
- wp_localize_script( 'yasrfront', "yasrMostHighestRanking", array(
820
- 'enable' => 'yes'
821
- )
822
- );
823
-
824
- return $shortcode_html;
825
-
826
-
827
  } //End function
828
 
829
 
@@ -864,17 +140,13 @@ function yasr_top_5_reviewers_callback () {
864
  $user_data = get_userdata($result->reviewer);
865
 
866
  if ($user_data) {
867
-
868
  $user_profile = get_author_posts_url($result->reviewer);
869
-
870
  }
871
 
872
  else {
873
-
874
  $user_profile = '#';
875
  $user_data = new stdClass;
876
  $user_data->user_login = 'Anonymous';
877
-
878
  }
879
 
880
 
@@ -896,9 +168,7 @@ function yasr_top_5_reviewers_callback () {
896
  }
897
 
898
  else {
899
-
900
  _e("Problem while retrieving the top 5 most active reviewers. Did you publish any review?");
901
-
902
  }
903
 
904
  } //End top 5 reviewers function
@@ -933,16 +203,11 @@ function yasr_top_ten_active_users_callback () {
933
  ";
934
 
935
  foreach ($query_result as $result) {
936
-
937
  $user_data = get_userdata($result->user);
938
 
939
  if ($user_data) {
940
-
941
  $user_profile = get_author_posts_url($result->user);
942
-
943
- }
944
-
945
- else {
946
  $user_profile = '#';
947
  $user_data = new stdClass;
948
  $user_data->user_login = 'Anonymous';
@@ -957,7 +222,6 @@ function yasr_top_ten_active_users_callback () {
957
 
958
 
959
  $shortcode_html .= "</table>";
960
-
961
  $shortcode_html .= '<!--End Yasr Top 10 Active Users Shortcode-->';
962
 
963
  return $shortcode_html;
@@ -968,81 +232,6 @@ function yasr_top_ten_active_users_callback () {
968
  _e("Problem while retrieving the top 10 active users chart. Are you sure you have votes to show?");
969
  }
970
 
971
-
972
  } //End function
973
 
974
-
975
- //this shortcode is in the plugin but not ready to use yet.
976
- //that's why there isn't doc about
977
- /*add_shortcode ('yasr_highest_rated_visitor_multi_set', 'yasr_highest_rated_visitor_multi_set_callback');
978
-
979
- function yasr_highest_rated_visitor_multi_set_callback ($atts) {
980
-
981
- global $wpdb;
982
-
983
- // Attributes
984
- extract( shortcode_atts(
985
- array(
986
- 'setid' => '0',
987
- ), $atts )
988
- );
989
-
990
- $set_fields = false;
991
- $shortcode_html = '';
992
-
993
- $set_fields=$wpdb->get_results($wpdb->prepare("SELECT v.post_id, v.sum_votes / v.number_of_votes AS average, v.number_of_votes, f.field_name
994
- FROM " . YASR_MULTI_SET_VALUES_TABLE . " AS v, " . YASR_MULTI_SET_FIELDS_TABLE . " AS f
995
- WHERE v.set_type = %d
996
- AND v.set_type = f.parent_set_id
997
- AND v.field_id = f.field_id
998
- AND v.number_of_votes > 0
999
- AND v.sum_votes > 0
1000
- ORDER BY f.parent_set_id ASC, f.field_id ASC, v.post_id ASC", $setid));
1001
-
1002
- if ($set_fields) {
1003
- $shortcode_html = "
1004
- <table class=\"yasr-table-chart\">";
1005
-
1006
- foreach ($set_fields as $results) {
1007
-
1008
- if (!isset($field_name) || $field_name != $results->field_name ) {
1009
-
1010
- $shortcode_html .= "<tr><td colspan=\"2\"><h3> $results->field_name</h3></td></tr>";
1011
-
1012
- }
1013
-
1014
- $link = get_permalink($results->post_id);
1015
- $title = wp_strip_all_tags(get_the_title($results->post_id));
1016
-
1017
- $average = round($results->average, 1);
1018
-
1019
- $shortcode_html .= "<tr>
1020
- <td>
1021
- <a href=\"$link\">$title</a>
1022
- </td>
1023
- <td>
1024
- <div class='rateit medium' data-rateit-starwidth='24'
1025
- data-rateit-starheight=\'24' data-rateit-value=\"$average\"
1026
- data-rateit-step='0.1' data-rateit-resetable=\"false\"
1027
- data-rateit-readonly=\"true\"></div>
1028
- $average" . sprintf(__(' based on %d votes', 'yet-another-stars-rating'), $results->number_of_votes); "
1029
- </td>
1030
- </tr>";
1031
-
1032
- $field_name = $results->field_name;
1033
-
1034
- }
1035
-
1036
- $shortcode_html .= "</table>";
1037
-
1038
- }
1039
-
1040
- else {
1041
- _e("No results, try a different setid", "yet-another-stars-rating");
1042
- }
1043
-
1044
- return $shortcode_html;
1045
-
1046
- }*/
1047
-
1048
  ?>
22
  exit('You\'re not allowed to see this page');
23
  } // Exit if accessed directly
24
 
25
+ require YASR_ABSOLUTE_PATH . '/lib/yasr-shortcode-classes.php';
26
+
27
  /****** Add shortcode for overall rating ******/
28
  add_shortcode('yasr_overall_rating', 'shortcode_overall_rating_callback');
29
 
33
  return null;
34
  }
35
 
36
+ $shortcode_name = 'yasr_overall_rating';
37
+ $overall_rating = new YasrOverallRating($atts, $shortcode_name);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
+ return $overall_rating->printOverallRating();
 
 
 
 
 
40
 
 
41
  } //end function
42
 
43
 
51
  return null;
52
  }
53
 
54
+ $shortcode_name = 'yasr_visitor_votes';
55
+ $visitor_votes = new YasrVisitorVotes($atts, $shortcode_name);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
+ return $visitor_votes->printVisitorVotes();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  } //End function shortcode_visitor_votes_callback
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  /****** Add shortcode for multiple set ******/
62
 
63
+ add_shortcode ('yasr_multiset', 'yasr_multiset_callback');
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
+ function yasr_multiset_callback($atts) {
66
+ $shortcode_name = 'yasr_multiset';
67
+ $multiset = new YasrMultiSet($atts, $shortcode_name);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
+ return $multiset->printMultiset();
70
+ }
71
 
72
  /****** Add shortcode for multiset writable by users ******/
73
 
74
  add_shortcode ('yasr_visitor_multiset', 'yasr_visitor_multiset_callback');
75
 
76
  function yasr_visitor_multiset_callback($atts) {
77
+ $shortcode_name = 'yasr_visitor_multiset';
78
+ $multiset = new YasrVisitorMultiSet($atts, $shortcode_name);
79
 
80
+ return $multiset->printVisitorMultiSet();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
82
 
83
 
86
  add_shortcode ('yasr_top_ten_highest_rated', 'yasr_top_ten_highest_rated_callback');
87
 
88
  function yasr_top_ten_highest_rated_callback() {
89
+ $top_ten_highest_obj = new YasrRankings(false, 'yasr_top_ten_highest_rated');
90
 
91
+ return $top_ten_highest_obj->returnHighestRatedOverall();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  } //End function
93
 
94
 
97
  add_shortcode ('yasr_most_or_highest_rated_posts', 'yasr_most_or_highest_rated_posts_callback');
98
 
99
  function yasr_most_or_highest_rated_posts_callback () {
100
+ $most_highest_obj = new YasrRankings(false, 'yasr_most_or_highest_rated_posts');
101
 
102
+ return $most_highest_obj->vvReturnMostHighestRatedPost();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  } //End function
104
 
105
 
140
  $user_data = get_userdata($result->reviewer);
141
 
142
  if ($user_data) {
 
143
  $user_profile = get_author_posts_url($result->reviewer);
 
144
  }
145
 
146
  else {
 
147
  $user_profile = '#';
148
  $user_data = new stdClass;
149
  $user_data->user_login = 'Anonymous';
 
150
  }
151
 
152
 
168
  }
169
 
170
  else {
 
171
  _e("Problem while retrieving the top 5 most active reviewers. Did you publish any review?");
 
172
  }
173
 
174
  } //End top 5 reviewers function
203
  ";
204
 
205
  foreach ($query_result as $result) {
 
206
  $user_data = get_userdata($result->user);
207
 
208
  if ($user_data) {
 
209
  $user_profile = get_author_posts_url($result->user);
210
+ } else {
 
 
 
211
  $user_profile = '#';
212
  $user_data = new stdClass;
213
  $user_data->user_login = 'Anonymous';
222
 
223
 
224
  $shortcode_html .= "</table>";
 
225
  $shortcode_html .= '<!--End Yasr Top 10 Active Users Shortcode-->';
226
 
227
  return $shortcode_html;
232
  _e("Problem while retrieving the top 10 active users chart. Are you sure you have votes to show?");
233
  }
234
 
 
235
  } //End function
236
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  ?>
lib/yasr-widgets.php CHANGED
@@ -64,7 +64,6 @@ class Yasr_Overall_Rating_Widget extends WP_Widget {
64
  public function widget($args, $instance) {
65
 
66
  if (is_singular() && is_main_query()) {
67
-
68
  echo $args['before_widget'];
69
 
70
  if (!empty($instance['title'])) {
@@ -72,7 +71,6 @@ class Yasr_Overall_Rating_Widget extends WP_Widget {
72
  }
73
 
74
  $size = array();
75
-
76
  $size['size'] = $instance['size'];
77
 
78
  $widget_overall_rating = shortcode_overall_rating_callback($size);
@@ -221,14 +219,13 @@ class Yasr_Visitor_Votes_Widget extends WP_Widget {
221
  echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
222
  }
223
 
224
- $size = array();
225
-
226
- $size['size'] = $instance['size'];
227
-
228
  if ($instance['readonly'] === 'yes') {
229
- $widget_visitor_votes = yasr_visitor_votes_readonly_callback($size);
 
230
  } else {
231
- $widget_visitor_votes = shortcode_visitor_votes_callback($size);
232
  }
233
 
234
  echo $widget_visitor_votes;
@@ -290,15 +287,18 @@ class Yasr_Visitor_Votes_Widget extends WP_Widget {
290
  <p>
291
  <legend><?php _e('Size:', 'yet-another-stars-rating'); ?></legend>
292
  <input type="radio" name="<?php echo $this->get_field_name('size'); ?>"
293
- value="small" <?php if ($size === 'small') {echo 'checked';} ?> >Small
 
294
  <br/>
295
 
296
  <input type="radio" name="<?php echo $this->get_field_name('size'); ?>"
297
- value="medium" <?php if ($size === 'medium') {echo 'checked';} ?> >Medium
 
298
 
299
  <br/>
300
  <input type="radio" name="<?php echo $this->get_field_name('size'); ?>"
301
- value="large" <?php if ($size === 'large') {echo 'checked';} ?> >Large
 
302
  </p>
303
 
304
  <?php
@@ -316,7 +316,6 @@ class Yasr_Visitor_Votes_Widget extends WP_Widget {
316
  *
317
  */
318
  public function update($new_instance, $old_instance) {
319
-
320
  $instance = $old_instance;
321
 
322
  if (!$instance) {
@@ -329,7 +328,11 @@ class Yasr_Visitor_Votes_Widget extends WP_Widget {
329
  $instance['title'] = '';
330
  }
331
 
332
- $instance['readonly'] = strip_tags($new_instance['readonly']);
 
 
 
 
333
 
334
  if (!empty($new_instance['size'])) {
335
  $instance['size'] = strip_tags($new_instance['size']);
@@ -397,8 +400,9 @@ class Yasr_Recent_Ratings_Widget extends WP_Widget {
397
  . YASR_LOG_TABLE .
398
  " ORDER BY date DESC LIMIT 5");
399
 
 
 
400
  if ($log_result) {
401
- $widget_recent_ratings = "<table class=\"yasr-widget-recent-ratings-table\">";
402
 
403
  foreach ($log_result as $result) {
404
  $user = get_user_by('id', $result->user_id);
@@ -435,13 +439,18 @@ class Yasr_Recent_Ratings_Widget extends WP_Widget {
435
  $widget_recent_ratings .= "</td>
436
  </tr>";
437
 
438
-
439
  } //End foreach
440
 
441
- $widget_recent_ratings .= "</table>";
442
-
 
 
 
 
443
  }
444
 
 
 
445
  echo $widget_recent_ratings;
446
 
447
  echo $args['after_widget'];
64
  public function widget($args, $instance) {
65
 
66
  if (is_singular() && is_main_query()) {
 
67
  echo $args['before_widget'];
68
 
69
  if (!empty($instance['title'])) {
71
  }
72
 
73
  $size = array();
 
74
  $size['size'] = $instance['size'];
75
 
76
  $widget_overall_rating = shortcode_overall_rating_callback($size);
219
  echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
220
  }
221
 
222
+ $atts = array();
223
+ $atts['size'] = $instance['size'];
 
 
224
  if ($instance['readonly'] === 'yes') {
225
+ $atts['readonly'] = $instance['readonly'];
226
+ $widget_visitor_votes = shortcode_visitor_votes_callback($atts);
227
  } else {
228
+ $widget_visitor_votes = shortcode_visitor_votes_callback($atts);
229
  }
230
 
231
  echo $widget_visitor_votes;
287
  <p>
288
  <legend><?php _e('Size:', 'yet-another-stars-rating'); ?></legend>
289
  <input type="radio" name="<?php echo $this->get_field_name('size'); ?>"
290
+ value="small" <?php if ($size === 'small') {echo 'checked';} ?> >
291
+ <?php _e('Small:', 'yet-another-stars-rating'); ?>
292
  <br/>
293
 
294
  <input type="radio" name="<?php echo $this->get_field_name('size'); ?>"
295
+ value="medium" <?php if ($size === 'medium') {echo 'checked';} ?> >
296
+ <?php _e('Medium:', 'yet-another-stars-rating'); ?>
297
 
298
  <br/>
299
  <input type="radio" name="<?php echo $this->get_field_name('size'); ?>"
300
+ value="large" <?php if ($size === 'large') {echo 'checked';} ?> >
301
+ <?php _e('Large:', 'yet-another-stars-rating'); ?>
302
  </p>
303
 
304
  <?php
316
  *
317
  */
318
  public function update($new_instance, $old_instance) {
 
319
  $instance = $old_instance;
320
 
321
  if (!$instance) {
328
  $instance['title'] = '';
329
  }
330
 
331
+ if (!empty($new_instance['readonly'])) {
332
+ $instance['readonly'] = strip_tags($new_instance['readonly']);
333
+ } else {
334
+ $instance['readonly'] = false;
335
+ }
336
 
337
  if (!empty($new_instance['size'])) {
338
  $instance['size'] = strip_tags($new_instance['size']);
400
  . YASR_LOG_TABLE .
401
  " ORDER BY date DESC LIMIT 5");
402
 
403
+ $widget_recent_ratings = "<table class=\"yasr-widget-recent-ratings-table\">";
404
+
405
  if ($log_result) {
 
406
 
407
  foreach ($log_result as $result) {
408
  $user = get_user_by('id', $result->user_id);
439
  $widget_recent_ratings .= "</td>
440
  </tr>";
441
 
 
442
  } //End foreach
443
 
444
+ } else {
445
+ $widget_recent_ratings .= "<tr>
446
+ <td>
447
+ ". __('No recent ratings yet' , 'yet-another-stars-ratings') ."
448
+ </td>
449
+ </tr>";
450
  }
451
 
452
+ $widget_recent_ratings .= "</table>";
453
+
454
  echo $widget_recent_ratings;
455
 
456
  echo $args['after_widget'];
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.4
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
@@ -125,6 +125,11 @@ 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.4 =
129
  * FIXED: undefined variable when saving/updating post or page
130
  * TWEAKED: changed delete_post_meta with delete_metadata
@@ -199,4 +204,5 @@ External Libraries: [Rater](https://github.com/fredolss/rater-js)
199
  [tippy](https://atomiks.github.io/tippyjs/)
200
 
201
  Flat star icon made by[Freepik](http://www.freepik.com)
202
- from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/)
 
5
  Contributors: Dudo
6
  Tested up to: 5.4
7
  Requires PHP: 5.3
8
+ Stable tag: 2.2.0
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
125
 
126
  The full changelog can be found in the plugin's directory. Recent entries:
127
 
128
+ = 2.2.0 =
129
+ * TWEAKED: most of code of the main shortcodes has been rewritten; YASR is faster than ever.
130
+ * FIXED: gutenberg shortcode preview yasr_top_ten_highest_rated shortcode
131
+
132
+
133
  = 2.1.4 =
134
  * FIXED: undefined variable when saving/updating post or page
135
  * TWEAKED: changed delete_post_meta with delete_metadata
204
  [tippy](https://atomiks.github.io/tippyjs/)
205
 
206
  Flat star icon made by[Freepik](http://www.freepik.com)
207
+ from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/)
208
+
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.4
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.4' );
80
  //Plugin relative path
81
  define( "YASR_ABSOLUTE_PATH", dirname( __FILE__ ) );
82
  //Plugin RELATIVE PATH without slashes (just the directory's name)
@@ -187,11 +187,14 @@ if ( !function_exists( 'yasr_fs' ) ) {
187
  // Include function file
188
  require YASR_ABSOLUTE_PATH . '/lib/yasr-functions.php';
189
  require YASR_ABSOLUTE_PATH . '/lib/yasr-db-functions.php';
 
190
  require YASR_ABSOLUTE_PATH . '/lib/yasr-ajax-functions.php';
191
  require YASR_ABSOLUTE_PATH . '/lib/yasr-shortcode-functions.php';
192
  require YASR_ABSOLUTE_PATH . '/lib/yasr-widgets.php';
 
193
 
194
  if ( is_admin() ) {
 
195
  require YASR_ABSOLUTE_PATH . '/lib/admin/yasr-admin-actions.php';
196
  require YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions.php';
197
  require YASR_ABSOLUTE_PATH . '/lib/admin/class-wp-list-table.php';
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.2.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.2.0' );
80
  //Plugin relative path
81
  define( "YASR_ABSOLUTE_PATH", dirname( __FILE__ ) );
82
  //Plugin RELATIVE PATH without slashes (just the directory's name)
187
  // Include function file
188
  require YASR_ABSOLUTE_PATH . '/lib/yasr-functions.php';
189
  require YASR_ABSOLUTE_PATH . '/lib/yasr-db-functions.php';
190
+ require YASR_ABSOLUTE_PATH . '/lib/yasr-db-classes.php';
191
  require YASR_ABSOLUTE_PATH . '/lib/yasr-ajax-functions.php';
192
  require YASR_ABSOLUTE_PATH . '/lib/yasr-shortcode-functions.php';
193
  require YASR_ABSOLUTE_PATH . '/lib/yasr-widgets.php';
194
+ require YASR_ABSOLUTE_PATH . '/lib/yasr-deprecated.php';
195
 
196
  if ( is_admin() ) {
197
+ require YASR_ABSOLUTE_PATH . '/lib/admin/yasr-admin-classes.php';
198
  require YASR_ABSOLUTE_PATH . '/lib/admin/yasr-admin-actions.php';
199
  require YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions.php';
200
  require YASR_ABSOLUTE_PATH . '/lib/admin/class-wp-list-table.php';