Yasr – Yet Another Stars Rating - Version 1.0.3

Version Description

  • TWEAKED: shortcodes doesn't echo javascrfipt anymore. wp_localize_script is used instead
  • Minor changes on settings api
Download this release

Release Info

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

Code changes from version 1.0.2 to 1.0.3

js/yasr-front.js CHANGED
@@ -1,37 +1,77 @@
1
/****** Yasr shortcode page ******/
2
3
- function yasrVisitorsVotes (tooltipValues, postid, ajaxurl, size, loggedUser, voteIfUserAlredyRated, loaderHtml, nonceVisitor) {
4
5
- jQuery('#yasr_rateit_visitor_votes_' + postid).bind('over', function (event, value) { jQuery(this).attr('title', tooltipValues[value-1]); });
6
7
//Should be useless from version 0.7.9, just to be safe
8
- if (voteIfUserAlredyRated == "0" ) {
9
- voteIfUserAlredyRated = false;
10
}
11
12
- jQuery('#yasr_rateit_visitor_votes_' + postid).on('rated', function() {
13
14
var el = jQuery(this);
15
var value = el.rateit('value');
16
var value = value.toFixed(1); //
17
18
if (value < 1) {
19
- jQuery('#yasr_visitor_votes_' + postid).html('You can\'t vote 0');
20
}
21
22
else {
23
24
- jQuery('#yasr_visitor_votes_' + postid).html(loaderHtml);
25
26
- //If loggedin user and has already rated for a post/page update the vote
27
- if (loggedUser && voteIfUserAlredyRated) {
28
29
var data = {
30
action: 'yasr_update_visitor_rating',
31
rating: value,
32
- post_id: postid,
33
- size: size,
34
- nonce_visitor: nonceVisitor
35
};
36
37
}
@@ -42,17 +82,17 @@
42
var data = {
43
action: 'yasr_send_visitor_rating',
44
rating: value,
45
- post_id: postid,
46
- size: size,
47
- nonce_visitor: nonceVisitor
48
};
49
50
}
51
52
//Send value to the Server
53
- jQuery.post(ajaxurl, data, function(response) {
54
//response
55
- jQuery('#yasr_visitor_votes_' + postid).html(response);
56
jQuery('.rateit').rateit();
57
58
}) ;
@@ -61,10 +101,11 @@
61
62
});//End function insert/update vote
63
64
- } //End function yasr visitor votes
65
-
66
-
67
- function yasrVisitorsMultiSet (postId, setType, ajaxurl, nonce) {
68
69
//will have field id and vote
70
var ratingObject = "";
@@ -72,7 +113,7 @@
72
//an array with all the ratingonjects
73
var ratingArray = new Array();
74
75
- jQuery('.yasr-visitor-multi-'+postId+'-'+setType).on('rated', function() {
76
var el = jQuery(this);
77
var value = el.rateit('value');
78
var value = value.toFixed(1);
@@ -90,27 +131,27 @@
90
91
});
92
93
- jQuery('#yasr-send-visitor-multiset-'+postId+'-'+setType).on('click', function() {
94
95
- jQuery('#yasr-send-visitor-multiset-'+postId+'-'+setType).hide();
96
97
- var cookiename = "yasr_multi_visitor_vote_" + postId+'_'+setType;
98
99
- jQuery('#yasr-loader-multiset-visitor-'+postId+'-'+setType).show();
100
101
var data = {
102
103
action: 'yasr_visitor_multiset_field_vote',
104
- nonce: nonce,
105
- post_id: postId,
106
rating: ratingArray,
107
- set_type: setType
108
109
}
110
111
//Send value to the Server
112
- jQuery.post(ajaxurl, data, function(response) {
113
- jQuery('#yasr-loader-multiset-visitor-'+postId+'-'+setType).text(response);
114
});
115
116
});
@@ -118,7 +159,7 @@
118
} //End function
119
120
121
- function yasrMostOrHighestRatedChart (ajaxurl) {
122
123
//By default, hide the highest rated chart
124
jQuery('#yasr-highest-rated-posts').hide();
@@ -173,11 +214,11 @@
173
}
174
175
//used in shortcode page and ajax page
176
- function yasrDrawTipsProgress(postid, ajaxurl) {
177
178
var varTipsContent = null;
179
180
- jQuery('#yasr-total-average-dashicon-' + postid).tooltip({
181
182
position: { my: 'center bottom' , at: 'center top-10' },
183
tooltipClass: "yasr-visitors-stats-tooltip",
@@ -187,10 +228,10 @@
187
188
var data = {
189
action: 'yasr_stats_visitors_votes',
190
- post_id: postid
191
}
192
193
- jQuery.post(ajaxurl, data, function(response) {
194
varTipsContent = response;
195
tipsContent(response);
196
});
@@ -209,7 +250,7 @@
209
210
});
211
212
- jQuery('#yasr-total-average-dashicon-' + postid).on("hover", function(){
213
jQuery(this).tooltip('enable').tooltip('open');
214
jQuery('.ui-helper-hidden-accessible').children(':first').removeAttr('style');
215
jQuery('.ui-helper-hidden-accessible').children(':last', this).remove();
1
+
2
+ /*** Constant used by yasr
3
+
4
+ yasrCommonData (postid, ajaxurl, loggedUser)
5
+
6
+ yasrVisitorsVotesData (tooltipValues, starSize, voteIfUserAlredyRated, loaderHtml, nonceVisitor, visitorStatsEnabled )
7
+
8
+ yasrMultiSetData (setType, nonce)
9
+
10
+
11
+ ***/
12
+
13
+
14
/****** Yasr shortcode page ******/
15
16
+ document.addEventListener('DOMContentLoaded', function(event) {
17
+
18
+ //if is defined yasrVisitorsVotesData means that the shortcode is used
19
+ if (typeof yasrVisitorsVotesData !== 'undefined') {
20
+
21
+ yasrVisitorsVotes ();
22
+
23
+ if (yasrVisitorsVotesData.visitorStatsEnabled == 'yes') {
24
25
+ yasrDrawTipsProgress ();
26
+
27
+ }
28
+
29
+ }
30
+
31
+ //If is not undefined yasrMultiSetData means that the shortcode yasr_visitor_multiset is used
32
+ if (typeof yasrMultiSetData !== 'undefined') {
33
+
34
+ yasrVisitorsMultiSet ();
35
+
36
+ }
37
+
38
+ });
39
+
40
+
41
+ /*** Yasr visitor Votes ***/
42
+
43
+ function yasrVisitorsVotes () {
44
+
45
+ jQuery('#yasr_rateit_visitor_votes_' + yasrCommonData.postid).bind('over', function (event, value) { jQuery(this).attr('title', yasrVisitorsVotesData.tooltipValues[value-1]); });
46
47
//Should be useless from version 0.7.9, just to be safe
48
+ if (yasrVisitorsVotesData.voteIfUserAlredyRated == "0" ) {
49
+ yasrVisitorsVotesData.voteIfUserAlredyRated = false;
50
}
51
52
+ jQuery('#yasr_rateit_visitor_votes_' + yasrCommonData.postid).on('rated', function() {
53
54
var el = jQuery(this);
55
var value = el.rateit('value');
56
var value = value.toFixed(1); //
57
58
if (value < 1) {
59
+ jQuery('#yasr_visitor_votes_' + yasrCommonData.postid).html('You can\'t vote 0');
60
}
61
62
else {
63
64
+ jQuery('#yasr_visitor_votes_' + yasrCommonData.postid).html(yasrVisitorsVotesData.loaderHtml);
65
66
+ //If logged in user and has already rated for a post/page update the vote
67
+ if (yasrCommonData.loggedUser && yasrVisitorsVotesData.voteIfUserAlredyRated) {
68
69
var data = {
70
action: 'yasr_update_visitor_rating',
71
rating: value,
72
+ post_id: yasrCommonData.postid,
73
+ size: yasrVisitorsVotesData.starSize,
74
+ nonce_visitor: yasrVisitorsVotesData.nonceVisitor
75
};
76
77
}
82
var data = {
83
action: 'yasr_send_visitor_rating',
84
rating: value,
85
+ post_id: yasrCommonData.postid,
86
+ size: yasrVisitorsVotesData.starSize,
87
+ nonce_visitor: yasrVisitorsVotesData.nonceVisitor
88
};
89
90
}
91
92
//Send value to the Server
93
+ jQuery.post(yasrCommonData.ajaxurl, data, function(response) {
94
//response
95
+ jQuery('#yasr_visitor_votes_' + yasrCommonData.postid).html(response);
96
jQuery('.rateit').rateit();
97
98
}) ;
101
102
});//End function insert/update vote
103
104
+ }
105
+ /*** End Yasr Visitor Votes ***/
106
+
107
+
108
+ function yasrVisitorsMultiSet () {
109
110
//will have field id and vote
111
var ratingObject = "";
113
//an array with all the ratingonjects
114
var ratingArray = new Array();
115
116
+ jQuery('.yasr-visitor-multi-'+yasrCommonData.postid+'-'+yasrMultiSetData.setType).on('rated', function() {
117
var el = jQuery(this);
118
var value = el.rateit('value');
119
var value = value.toFixed(1);
131
132
});
133
134
+ jQuery('#yasr-send-visitor-multiset-'+yasrCommonData.postid+'-'+yasrMultiSetData.setType).on('click', function() {
135
136
+ jQuery('#yasr-send-visitor-multiset-'+yasrCommonData.postid+'-'+yasrMultiSetData.setType).hide();
137
138
+ var cookiename = "yasr_multi_visitor_vote_" +yasrCommonData.postid+'_'+yasrMultiSetData.setType;
139
140
+ jQuery('#yasr-loader-multiset-visitor-'+yasrCommonData.postid+'-'+yasrMultiSetData.setType).show();
141
142
var data = {
143
144
action: 'yasr_visitor_multiset_field_vote',
145
+ nonce: yasrMultiSetData.nonce,
146
+ post_id: yasrCommonData.postid,
147
rating: ratingArray,
148
+ set_type: yasrMultiSetData.setType
149
150
}
151
152
//Send value to the Server
153
+ jQuery.post(yasrCommonData.ajaxurl, data, function(response) {
154
+ jQuery('#yasr-loader-multiset-visitor-'+yasrCommonData.postid+'-'+yasrMultiSetData.setType).text(response);
155
});
156
157
});
159
} //End function
160
161
162
+ function yasrMostOrHighestRatedChart () {
163
164
//By default, hide the highest rated chart
165
jQuery('#yasr-highest-rated-posts').hide();
214
}
215
216
//used in shortcode page and ajax page
217
+ function yasrDrawTipsProgress () {
218
219
var varTipsContent = null;
220
221
+ jQuery('#yasr-total-average-dashicon-' + yasrCommonData.postid).tooltip({
222
223
position: { my: 'center bottom' , at: 'center top-10' },
224
tooltipClass: "yasr-visitors-stats-tooltip",
228
229
var data = {
230
action: 'yasr_stats_visitors_votes',
231
+ post_id: yasrCommonData.postid
232
}
233
234
+ jQuery.post(yasrCommonData.ajaxurl, data, function(response) {
235
varTipsContent = response;
236
tipsContent(response);
237
});
250
251
});
252
253
+ jQuery('#yasr-total-average-dashicon-' + yasrCommonData.postid).on("hover", function(){
254
jQuery(this).tooltip('enable').tooltip('open');
255
jQuery('.ui-helper-hidden-accessible').children(':first').removeAttr('style');
256
jQuery('.ui-helper-hidden-accessible').children(':last', this).remove();
lib/yasr-functions.php CHANGED
@@ -61,6 +61,17 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
61
62
wp_enqueue_script( 'yasrfront', YASR_JS_DIR . 'yasr-front.js' , array('jquery', 'rateit'), '1.0.0', TRUE );
63
64
}
65
66
function yasr_add_admin_scripts () {
61
62
wp_enqueue_script( 'yasrfront', YASR_JS_DIR . 'yasr-front.js' , array('jquery', 'rateit'), '1.0.0', TRUE );
63
64
+ wp_localize_script ('yasrfront', 'yasrCommonData', array(
65
+
66
+ 'postid' => get_the_ID(),
67
+ 'ajaxurl' => admin_url('admin-ajax.php'),
68
+ 'loggedUser' => is_user_logged_in(),
69
+
70
+
71
+ )
72
+
73
+ );
74
+
75
}
76
77
function yasr_add_admin_scripts () {
lib/yasr-settings-functions.php CHANGED
@@ -27,7 +27,8 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
27
function yasr_general_options_init() {
28
register_setting(
29
'yasr_general_options_group', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
30
- 'yasr_general_options' //The name of an option to sanitize and save.
31
);
32
33
$option = get_option( 'yasr_general_options' );
@@ -493,6 +494,32 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
493
}
494
495
496
/************ End Yasr General Settings ************/
497
498
@@ -1301,7 +1328,8 @@ add_action( 'admin_init', 'yasr_style_options_init' ); //This is for auto insert
1301
function yasr_style_options_init() {
1302
register_setting(
1303
'yasr_style_options_group', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
1304
- 'yasr_style_options' //The name of an option to sanitize and save.
1305
);
1306
1307
$style_options = get_option( 'yasr_style_options' );
@@ -1334,6 +1362,21 @@ add_action( 'admin_init', 'yasr_style_options_init' ); //This is for auto insert
1334
}
1335
1336
1337
function yasr_go_pro () {
1338
1339
?>
27
function yasr_general_options_init() {
28
register_setting(
29
'yasr_general_options_group', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
30
+ 'yasr_general_options', //The name of an option to sanitize and save.
31
+ 'yasr_general_options_sanitize'
32
);
33
34
$option = get_option( 'yasr_general_options' );
494
}
495
496
497
+ function yasr_general_options_sanitize($option) {
498
+
499
+ //Array to return
500
+ $output = array();
501
+
502
+ // Loop through each of the incoming options
503
+ foreach( $option as $key => $value ) {
504
+
505
+ // Check to see if the current option has a value. If so, process it.
506
+ if( isset( $option[$key] ) ) {
507
+
508
+ // Strip all HTML and PHP tags and properly handle quoted strings
509
+ $output[$key] = strip_tags( stripslashes( $option[ $key ] ) );
510
+
511
+ } // end if
512
+
513
+ } // end foreach
514
+
515
+ // Return the array processing any additional functions filtered by this action
516
+ //do not return $output but do apply_filter first,
517
+
518
+ return $output;
519
+
520
+ }
521
+
522
+
523
/************ End Yasr General Settings ************/
524
525
1328
function yasr_style_options_init() {
1329
register_setting(
1330
'yasr_style_options_group', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
1331
+ 'yasr_style_options', //The name of an option to sanitize and save.
1332
+ 'yasr_style_options_sanitize'
1333
);
1334
1335
$style_options = get_option( 'yasr_style_options' );
1362
}
1363
1364
1365
+ function yasr_style_options_sanitize ($style_options) {
1366
+
1367
+ foreach ($style_options as $key => $value) {
1368
+
1369
+ $output[$key] = strip_tags( stripslashes( $style_options[$key] ) );
1370
+
1371
+ }
1372
+
1373
+ return $output;
1374
+
1375
+
1376
+ }
1377
+
1378
+
1379
+
1380
function yasr_go_pro () {
1381
1382
?>
lib/yasr-shortcode-functions.php CHANGED
@@ -317,57 +317,27 @@ function shortcode_visitor_votes_callback ($atts) {
317
$shortcode_html .= "</div>";
318
319
320
- $var_tooltip_values = __("bad, poor, ok, good, super", 'yet-another-stars-rating');
321
- $var_tooltip_values= json_encode($var_tooltip_values);
322
-
323
- $var_post_id = json_encode($post_id);
324
- $var_ajax_url = json_encode(admin_url('admin-ajax.php'));
325
- $var_size = json_encode($size);
326
- $var_logged_user = json_encode(is_user_logged_in());
327
- $var_vote_if_user_already_rated = json_encode($vote_if_user_already_rated);
328
- $var_loader_html = json_encode("$loader_html");
329
- $var_nonce_visitor = json_encode("$ajax_nonce_visitor");
330
-
331
- $var_visitor_stats_enabled = json_encode(YASR_VISITORS_STATS);
332
-
333
- $javascript = "
334
-
335
- <script type=\"text/javascript\">
336
-
337
- document.addEventListener('DOMContentLoaded', function(event) {
338
-
339
- var stringTooltipValues = $var_tooltip_values;
340
- var arrayTooltipValues = stringTooltipValues.split(', ');
341
- var postid = $var_post_id;
342
- var ajaxurl = $var_ajax_url;
343
- var size = $var_size;
344
- var loggedUser = $var_logged_user;
345
- var voteIfUserAlredyRated = $var_vote_if_user_already_rated;
346
- var loaderHtml = $var_loader_html;
347
- var nonceVisitor = $var_nonce_visitor;
348
-
349
- yasrVisitorsVotes(arrayTooltipValues, postid, ajaxurl, size, loggedUser, voteIfUserAlredyRated, loaderHtml, nonceVisitor);
350
-
351
- var visitorStatsEnabled = $var_visitor_stats_enabled;
352
-
353
- //If stats are enabled call the function
354
- if (visitorStatsEnabled == 'yes') {
355
- yasrDrawTipsProgress (postid, ajaxurl);
356
- }
357
-
358
- });
359
-
360
- </script>
361
-
362
- ";
363
-
364
365
//IF show visitor votes in loop is disabled use is_singular && is_main query
366
if ( YASR_SHOW_VISITOR_VOTES_IN_LOOP === 'disabled' ) {
367
368
if( is_singular() && is_main_query() ) {
369
370
- return $shortcode_html . $javascript;
371
372
}
373
@@ -376,7 +346,7 @@ function shortcode_visitor_votes_callback ($atts) {
376
//If overall rating in loop is enabled don't use is_singular && is main_query
377
elseif ( YASR_SHOW_VISITOR_VOTES_IN_LOOP === 'enabled' ) {
378
379
- return $shortcode_html . $javascript;
380
381
}
382
@@ -698,30 +668,14 @@ function yasr_visitor_multiset_callback ( $atts ) {
698
699
}
700
701
- $var_post_id = json_encode($post_id);
702
- $var_set_id = json_encode($setid);
703
- $var_ajax_url = json_encode(admin_url('admin-ajax.php'));
704
- $var_ajax_nonce_visitor_multiset = json_encode($ajax_nonce_visitor_multiset);
705
-
706
- $javascript = "
707
-
708
- <script type=\"text/javascript\">
709
-
710
- document.addEventListener('DOMContentLoaded', function(event) {
711
-
712
- var postId = $var_post_id;
713
- var setType = $setid;
714
- var ajaxurl = $var_ajax_url;
715
- var nonce = $var_ajax_nonce_visitor_multiset;
716
-
717
- yasrVisitorsMultiSet (postId, setType, ajaxurl, nonce);
718
-
719
- });
720
721
- </script>
722
- ";
723
724
- return $shortcode_html . $javascript;
725
726
}
727
317
$shortcode_html .= "</div>";
318
319
320
+ $tooltip_values = __("bad, poor, ok, good, super", 'yet-another-stars-rating');
321
+ $tooltip_values_exploded = explode(", ", $tooltip_values);
322
+
323
+ $ajax_url = admin_url('admin-ajax.php');
324
+
325
+ wp_localize_script( 'yasrfront', 'yasrVisitorsVotesData', array(
326
+ 'tooltipValues' => $tooltip_values_exploded,
327
+ 'starSize' => $size,
328
+ 'voteIfUserAlredyRated' => $vote_if_user_already_rated,
329
+ 'loaderHtml' => $loader_html,
330
+ 'nonceVisitor' => $ajax_nonce_visitor,
331
+ 'visitorStatsEnabled' => YASR_VISITORS_STATS
332
+ )
333
+ );
334
335
//IF show visitor votes in loop is disabled use is_singular && is_main query
336
if ( YASR_SHOW_VISITOR_VOTES_IN_LOOP === 'disabled' ) {
337
338
if( is_singular() && is_main_query() ) {
339
340
+ return $shortcode_html;
341
342
}
343
346
//If overall rating in loop is enabled don't use is_singular && is main_query
347
elseif ( YASR_SHOW_VISITOR_VOTES_IN_LOOP === 'enabled' ) {
348
349
+ return $shortcode_html;
350
351
}
352
668
669
}
670
671
+ wp_localize_script( 'yasrfront', 'yasrMultiSetData', array(
672
+ 'setType' => $setid,
673
+ 'nonce' => $ajax_nonce_visitor_multiset
674
+ )
675
+ );
676
677
678
+ return $shortcode_html;
679
680
}
681
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: 5 star, admin, administrator, AJAX, five-star, javascript, jquery, post r
4
Requires at least: 3.5
5
Contributors: Dudo
6
Tested up to: 4.3.1
7
- Stable tag: 1.0.2
8
License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
10
Yet Another Stars Rating is a simple plugin which allows you and / or your visitor to rate a post or element. Ideal for review's website
@@ -121,6 +121,11 @@ Of course not: you can easily add it on the visual editor just by clicking on th
121
122
== Changelog ==
123
124
= 1.0.2 =
125
* TWEAKED: Max length for multiset fields in now 40 instead 23
126
* FIXED: Fixed a bug in multiset editing
4
Requires at least: 3.5
5
Contributors: Dudo
6
Tested up to: 4.3.1
7
+ Stable tag: 1.0.3
8
License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
10
Yet Another Stars Rating is a simple plugin which allows you and / or your visitor to rate a post or element. Ideal for review's website
121
122
== Changelog ==
123
124
+ = 1.0.3 =
125
+ * TWEAKED: shortcodes doesn't echo javascrfipt anymore. wp_localize_script is used instead
126
+ * Minor changes on settings api
127
+
128
+
129
= 1.0.2 =
130
* TWEAKED: Max length for multiset fields in now 40 instead 23
131
* FIXED: Fixed a bug in multiset editing
yet-another-stars-rating.php CHANGED
@@ -3,7 +3,7 @@
3
* Plugin Name: Yet Another Stars Rating
4
* Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
5
* Description: Rating system with rich snippets
6
- * Version: 1.0.2
7
* Author: Dario Curvino
8
* Author URI: https://yetanotherstarsrating.com/
9
* Text Domain: yet-another-stars-rating
@@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
30
*/
31
32
33
- define('YASR_VERSION_NUM', '1.0.2');
34
35
//Plugin relative path
36
define( "YASR_RELATIVE_PATH", dirname(__FILE__) );
3
* Plugin Name: Yet Another Stars Rating
4
* Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
5
* Description: Rating system with rich snippets
6
+ * Version: 1.0.3
7
* Author: Dario Curvino
8
* Author URI: https://yetanotherstarsrating.com/
9
* Text Domain: yet-another-stars-rating
30
*/
31
32
33
+ define('YASR_VERSION_NUM', '1.0.3');
34
35
//Plugin relative path
36
define( "YASR_RELATIVE_PATH", dirname(__FILE__) );