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(