Yasr – Yet Another Stars Rating - Version 0.3.3

Version Description

  • Created a new shortcode that will allow to insert Top 10 highest rated product by author
  • When a post or page is permanently deleted, yasr will delete every votes for that post or page
  • Overall Rating is now avaible in home page and archive pages
  • Fixed "add element button" when only 1 multi set is used
  • Updated jquery cookie from 1.4.0 to 1.4.1 and minified it
  • Minor Bug fixes
Download this release

Release Info

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

Code changes from version 0.3.2 to 0.3.3

css/bigstars.css CHANGED
@@ -32,3 +32,38 @@ div.bigstars div.rateit-reset:hover
32
  {
33
  background: url('../img/star-white32.png');
34
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  {
33
  background: url('../img/star-white32.png');
34
  }
35
+
36
+
37
+ /***** Added by Dario Curvino ******/
38
+
39
+ /* Creating set 24px image with yellow color read only. Used in charts */
40
+
41
+ div.charts div.rateit-range
42
+ {
43
+
44
+ background: url('../img/star-white24.png');
45
+ height: 24px;
46
+ }
47
+
48
+ div.charts div.rateit-hover
49
+ {
50
+ background: url('../img/star-gold24.png');
51
+ }
52
+
53
+ div.charts div.rateit-selected
54
+ {
55
+ background: url('../img/star-gold24.png');
56
+ }
57
+
58
+ div.charts div.rateit-reset
59
+ {
60
+ background: url('../img/star-black24.png');
61
+ width: 24px;
62
+ height: 24px;
63
+
64
+ }
65
+
66
+ div.charts div.rateit-reset:hover
67
+ {
68
+ background: url('../img/star-white24.png');
69
+ }
css/yasr.css CHANGED
@@ -1,3 +1,5 @@
 
 
1
  #multi_rating_table
2
  {
3
  vertical-align: text-top;
@@ -7,7 +9,7 @@
7
  display: block;
8
  }
9
 
10
-
11
  h2.nav-tab-wrapper, h3.nav-tab-wrapper {
12
  border-bottom: none !important;
13
  }
@@ -16,6 +18,8 @@ h2.nav-tab-wrapper, h3.nav-tab-wrapper {
16
  background-color: white !important;
17
  }
18
 
 
 
19
 
20
  @media (min-width: 972px) {
21
 
@@ -79,6 +83,23 @@ h2.nav-tab-wrapper, h3.nav-tab-wrapper {
79
  clear: both;
80
  }
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  .yasr-multi-set-form-headers {
83
  text-align: center;
84
  }
@@ -123,15 +144,6 @@ h2.nav-tab-wrapper, h3.nav-tab-wrapper {
123
  margin-bottom: 10px;
124
  }
125
 
126
- .yasr-result-step-1{
127
- padding-left: 25px;
128
- padding-top: 10px;
129
- }
130
-
131
- .yasr-result-step-2{
132
- padding-left: 45px;
133
- }
134
-
135
  #yasr-multi-set-response {
136
  margin-top: 10px;
137
  padding: 10px;
@@ -173,28 +185,6 @@ h2.nav-tab-wrapper, h3.nav-tab-wrapper {
173
  color: red;
174
  }
175
 
176
-
177
- .yasr_table_multi_set_shortcode tr:nth-child(odd) {
178
- background: #FFFFec;
179
- }
180
- /* Define the background color for all the EVEN background rows */
181
- .yasr_table_multi_set_shortcode tr:nth-child(even) {
182
- background: #FFFFFF;
183
- }
184
-
185
- .yasr-multi-set-name-field {
186
- color: #555;
187
- }
188
-
189
- .yasr-top-10-highest-rated tr:nth-child(odd) {
190
- background: #FFFFec;
191
- }
192
- /* Define the background color for all the EVEN background rows */
193
- .yasr-top-10-highest-rated tr:nth-child(even) {
194
- background: #FFFFFF;
195
- }
196
-
197
-
198
  .yasr_table_multi_set_admin {
199
  border: 1px solid rgba(0, 0, 0, 0.1);
200
  padding: 10px;
@@ -226,6 +216,8 @@ h2.nav-tab-wrapper, h3.nav-tab-wrapper {
226
  background: #FFFFFF;
227
  }
228
 
 
 
229
 
230
  #yasr-log-container {
231
  width: 98%;
@@ -277,3 +269,26 @@ h2.nav-tab-wrapper, h3.nav-tab-wrapper {
277
  padding-top: 7px;
278
  text-align: center;
279
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /****** ADMIN RULES ******/
2
+
3
  #multi_rating_table
4
  {
5
  vertical-align: text-top;
9
  display: block;
10
  }
11
 
12
+ /*** Top menu navigation ***/
13
  h2.nav-tab-wrapper, h3.nav-tab-wrapper {
14
  border-bottom: none !important;
15
  }
18
  background-color: white !important;
19
  }
20
 
21
+ /*** End top navigation ***/
22
+
23
 
24
  @media (min-width: 972px) {
25
 
83
  clear: both;
84
  }
85
 
86
+
87
+ /*** Rules for import data from gd star rating ***/
88
+
89
+ .yasr-result-step-1{
90
+ padding-left: 25px;
91
+ padding-top: 10px;
92
+ }
93
+
94
+ .yasr-result-step-2{
95
+ padding-left: 45px;
96
+ }
97
+
98
+ /*** End rules import gd star data ***/
99
+
100
+
101
+ /*** Rules for Multi set page ***/
102
+
103
  .yasr-multi-set-form-headers {
104
  text-align: center;
105
  }
144
  margin-bottom: 10px;
145
  }
146
 
 
 
 
 
 
 
 
 
 
147
  #yasr-multi-set-response {
148
  margin-top: 10px;
149
  padding: 10px;
185
  color: red;
186
  }
187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  .yasr_table_multi_set_admin {
189
  border: 1px solid rgba(0, 0, 0, 0.1);
190
  padding: 10px;
216
  background: #FFFFFF;
217
  }
218
 
219
+ /*** End rules for multi set admin page ***/
220
+
221
 
222
  #yasr-log-container {
223
  width: 98%;
269
  padding-top: 7px;
270
  text-align: center;
271
  }
272
+
273
+
274
+ /****** NON ADMIN RULES ******/
275
+
276
+ .yasr_table_multi_set_shortcode tr:nth-child(odd) {
277
+ background: #FFFFec;
278
+ }
279
+ /* Define the background color for all the EVEN background rows */
280
+ .yasr_table_multi_set_shortcode tr:nth-child(even) {
281
+ background: #FFFFFF;
282
+ }
283
+
284
+ .yasr-multi-set-name-field {
285
+ color: #555;
286
+ }
287
+
288
+ .yasr-top-10-highest-rated tr:nth-child(odd) {
289
+ background: #FFFFec;
290
+ }
291
+ /* Define the background color for all the EVEN background rows */
292
+ .yasr-top-10-highest-rated tr:nth-child(even) {
293
+ background: #FFFFFF;
294
+ }
img/star-black24.png ADDED
Binary file
img/star-gold24.png ADDED
Binary file
img/star-red24.png ADDED
Binary file
img/star-white24.png ADDED
Binary file
js/jquery.cookie.js DELETED
@@ -1,117 +0,0 @@
1
- /*!
2
- * jQuery Cookie Plugin v1.4.0
3
- * https://github.com/carhartl/jquery-cookie
4
- *
5
- * Copyright 2013 Klaus Hartl
6
- * Released under the MIT license
7
- */
8
- (function (factory) {
9
- if (typeof define === 'function' && define.amd) {
10
- // AMD. Register as anonymous module.
11
- define(['jquery'], factory);
12
- } else {
13
- // Browser globals.
14
- factory(jQuery);
15
- }
16
- }(function ($) {
17
-
18
- var pluses = /\+/g;
19
-
20
- function encode(s) {
21
- return config.raw ? s : encodeURIComponent(s);
22
- }
23
-
24
- function decode(s) {
25
- return config.raw ? s : decodeURIComponent(s);
26
- }
27
-
28
- function stringifyCookieValue(value) {
29
- return encode(config.json ? JSON.stringify(value) : String(value));
30
- }
31
-
32
- function parseCookieValue(s) {
33
- if (s.indexOf('"') === 0) {
34
- // This is a quoted cookie as according to RFC2068, unescape...
35
- s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
36
- }
37
-
38
- try {
39
- // Replace server-side written pluses with spaces.
40
- // If we can't decode the cookie, ignore it, it's unusable.
41
- s = decodeURIComponent(s.replace(pluses, ' '));
42
- } catch(e) {
43
- return;
44
- }
45
-
46
- try {
47
- // If we can't parse the cookie, ignore it, it's unusable.
48
- return config.json ? JSON.parse(s) : s;
49
- } catch(e) {}
50
- }
51
-
52
- function read(s, converter) {
53
- var value = config.raw ? s : parseCookieValue(s);
54
- return $.isFunction(converter) ? converter(value) : value;
55
- }
56
-
57
- var config = $.cookie = function (key, value, options) {
58
-
59
- // Write
60
- if (value !== undefined && !$.isFunction(value)) {
61
- options = $.extend({}, config.defaults, options);
62
-
63
- if (typeof options.expires === 'number') {
64
- var days = options.expires, t = options.expires = new Date();
65
- t.setDate(t.getDate() + days);
66
- }
67
-
68
- return (document.cookie = [
69
- encode(key), '=', stringifyCookieValue(value),
70
- options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
71
- options.path ? '; path=' + options.path : '',
72
- options.domain ? '; domain=' + options.domain : '',
73
- options.secure ? '; secure' : ''
74
- ].join(''));
75
- }
76
-
77
- // Read
78
-
79
- var result = key ? undefined : {};
80
-
81
- // To prevent the for loop in the first place assign an empty array
82
- // in case there are no cookies at all. Also prevents odd result when
83
- // calling $.cookie().
84
- var cookies = document.cookie ? document.cookie.split('; ') : [];
85
-
86
- for (var i = 0, l = cookies.length; i < l; i++) {
87
- var parts = cookies[i].split('=');
88
- var name = decode(parts.shift());
89
- var cookie = parts.join('=');
90
-
91
- if (key && key === name) {
92
- // If second argument (value) is a function it's a converter...
93
- result = read(cookie, value);
94
- break;
95
- }
96
-
97
- // Prevent storing a cookie that we couldn't decode.
98
- if (!key && (cookie = read(cookie)) !== undefined) {
99
- result[name] = cookie;
100
- }
101
- }
102
-
103
- return result;
104
- };
105
-
106
- config.defaults = {};
107
-
108
- $.removeCookie = function (key, options) {
109
- if ($.cookie(key) !== undefined) {
110
- // Must not alter options, thus extending a fresh object...
111
- $.cookie(key, '', $.extend({}, options, { expires: -1 }));
112
- return true;
113
- }
114
- return false;
115
- };
116
-
117
- }));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/jquery.cookie.min.js ADDED
@@ -0,0 +1 @@
 
1
+ (function(e){if(typeof define==="function"&&define.amd){define(["jquery"],e)}else if(typeof exports==="object"){e(require("jquery"))}else{e(jQuery)}})(function(e){function n(e){return u.raw?e:encodeURIComponent(e)}function r(e){return u.raw?e:decodeURIComponent(e)}function i(e){return n(u.json?JSON.stringify(e):String(e))}function s(e){if(e.indexOf('"')===0){e=e.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")}try{e=decodeURIComponent(e.replace(t," "));return u.json?JSON.parse(e):e}catch(n){}}function o(t,n){var r=u.raw?t:s(t);return e.isFunction(n)?n(r):r}var t=/\+/g;var u=e.cookie=function(t,s,a){if(s!==undefined&&!e.isFunction(s)){a=e.extend({},u.defaults,a);if(typeof a.expires==="number"){var f=a.expires,l=a.expires=new Date;l.setTime(+l+f*864e5)}return document.cookie=[n(t),"=",i(s),a.expires?"; expires="+a.expires.toUTCString():"",a.path?"; path="+a.path:"",a.domain?"; domain="+a.domain:"",a.secure?"; secure":""].join("")}var c=t?undefined:{};var h=document.cookie?document.cookie.split("; "):[];for(var p=0,d=h.length;p<d;p++){var v=h[p].split("=");var m=r(v.shift());var g=v.join("=");if(t&&t===m){c=o(g,s);break}if(!t&&(g=o(g))!==undefined){c[m]=g}}return c};u.defaults={};e.removeCookie=function(t,n){if(e.cookie(t)===undefined){return false}e.cookie(t,"",e.extend({},n,{expires:-1}));return!e.cookie(t)}})
lib/yasr-ajax-functions.php CHANGED
@@ -140,7 +140,7 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
140
  echo "<td>
141
  <div class=\"rateit bigstars multi\" id=\"$name->id\" data-rateit-value=\"\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-step=\"0.5\" data-rateit-resetable=\"true\" data-rateit-readonly=\"false\"></div>
142
 
143
- <span id=\"yasr-loader-multi-set-field-$set_content->id\" style=\"display:none;\" >&nbsp;<img src=\"" . YASR_IMG_DIR . "/loader.gif\" ></span>
144
  </td>
145
  </tr>";
146
 
@@ -347,7 +347,7 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
347
  <?php } //End if
348
 
349
  elseif ($n_multi_set==1) { ?>
350
- <tr>\
351
  <th><label for="yasr-size"><?php _e("Insert Multiset:"); ?></label></th>
352
  <td>
353
  <?php foreach ($multi_set as $name) { ?>
@@ -357,14 +357,20 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
357
  </td>
358
  </tr>
359
  <?php
360
- }
361
  //End elseif ?>
362
 
 
 
 
 
 
 
363
  </table>
364
  </div>
365
 
366
  <script>
367
- // Add shortcode fore overall rating
368
  jQuery('#yasr-overall').on("click", function(){
369
  var shortcode = '[yasr_overall_rating]';
370
  // inserts the shortcode into the active editor
@@ -416,6 +422,15 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
416
  }
417
  //End elseif ?>
418
 
 
 
 
 
 
 
 
 
 
419
  </script>
420
 
421
  <?php
@@ -722,101 +737,103 @@ add_action( 'wp_ajax_yasr_change_log_page', 'yasr_change_log_page_callback' );
722
 
723
  /****** Yasr insert visitor votes, called from yasr-shortcode-function ******/
724
 
725
- add_action( 'wp_ajax_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback' );
726
- add_action( 'wp_ajax_nopriv_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback' );
727
 
728
- function yasr_insert_visitor_votes_callback () {
729
- if(isset($_POST['rating']) && isset($_POST['post_id'])) {
730
- $rating = $_POST['rating'];
731
- $post_id = $_POST['post_id'];
732
- $nonce_visitor = $_POST['nonce_visitor'];
733
- }
734
- else {
735
- exit();
736
- }
737
 
738
- if ( ! wp_verify_nonce( $nonce_visitor, 'yasr_nonce_insert_visitor_rating' ) ) {
739
- die( 'Security check' );
740
- }
741
 
742
- $row_exists_result=NULL; //Avoid Undefined variable notice
743
- $new_row_result=NULL; ////Avoid Undefined variable notice
744
 
745
- global $wpdb;
746
 
747
- $row_exists = $wpdb->get_results ("SELECT number_of_votes, sum_votes FROM " . YASR_VOTES_TABLE . "
748
- WHERE post_id=$post_id");
749
 
750
- //If post already has vote, find where it is and sum it
751
- if ($row_exists) {
752
- foreach ($row_exists as $user_votes) {
753
- $number_of_votes = $user_votes->number_of_votes;
754
- $user_votes_sum = $user_votes->sum_votes;
755
- }
756
 
757
- $number_of_votes=$number_of_votes+1;
758
- $user_votes_sum=$user_votes_sum+$rating;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
759
 
760
- $row_exists_result=$wpdb->update(
761
- YASR_VOTES_TABLE,
762
- array (
763
- 'number_of_votes' => $number_of_votes,
764
- 'sum_votes' => $user_votes_sum,
765
- ),
766
- array (
767
- 'post_id' => $post_id
768
- ),
769
- array('%d', '%s' ),
770
- array( '%d' )
771
  );
772
-
773
- } //End if row_exists
774
 
775
- else {
776
- $new_row_result=$wpdb->replace (
777
- YASR_VOTES_TABLE,
778
- array (
779
- 'post_id' => $post_id,
780
- 'number_of_votes' => 1,
781
- 'overall_rating' => '-1',
782
- 'sum_votes' => $rating
783
- ),
784
- array ('%d', "%d", "%s", "%s")
785
- );
786
- }
 
 
 
 
 
787
 
788
- if ($row_exists_result || $new_row_result ) {
789
- global $current_user;
790
- get_currentuserinfo();
 
 
 
791
 
792
- $result_insert_log = $wpdb->replace (
793
- YASR_LOG_TABLE,
794
- array (
795
- 'post_id' => $post_id,
796
- 'multi_set_id' => -1,
797
- 'user_id' => $current_user->ID,
798
- 'vote' => $rating,
799
- 'date' => date('Y-m-d H:i:s'),
800
- 'ip' => $_SERVER['REMOTE_ADDR']
801
- ),
802
- array ('%d', '%d', '%d', '%s', '%s', '%s')
803
- );
804
- }
805
 
806
- if($row_exists_result) {
807
- $total_rating = ($user_votes_sum / $number_of_votes);
808
- $total_rating=round ($total_rating, 1);
809
- echo "<div class=\"rateit bigstars\" id=\"yasr_rateit_user_votes_voted\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$total_rating\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\"></div>
810
- <br /><strong>" . __("Vote Saved" , "yasr") . "</strong><br />" . __("Average Rating", "yasr") . " $total_rating / 5 ($number_of_votes " . __("votes casts", "yasr") . ")";
811
- }
812
 
813
- elseif ($new_row_result) {
814
- echo "<div class=\"rateit bigstars\" id=\"yasr_rateit_user_votes_voted\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$rating\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\"></div>
815
- <br /><strong>". __("Vote Saved" , "yasr") . "</strong><br />Rating $rating / 5 (1 " . __("vote cast", "yasr") . ")";
816
- }
817
 
818
- die(); // this is required to return a proper result
819
- }
820
 
821
  /****** Echo a readonly star set if user has already voted for a post ******/
822
 
140
  echo "<td>
141
  <div class=\"rateit bigstars multi\" id=\"$name->id\" data-rateit-value=\"\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-step=\"0.5\" data-rateit-resetable=\"true\" data-rateit-readonly=\"false\"></div>
142
 
143
+ <span id=\"yasr-loader-multi-set-field-$name->id\" style=\"display:none;\" >&nbsp;<img src=\"" . YASR_IMG_DIR . "/loader.gif\" ></span>
144
  </td>
145
  </tr>";
146
 
347
  <?php } //End if
348
 
349
  elseif ($n_multi_set==1) { ?>
350
+ <tr>
351
  <th><label for="yasr-size"><?php _e("Insert Multiset:"); ?></label></th>
352
  <td>
353
  <?php foreach ($multi_set as $name) { ?>
357
  </td>
358
  </tr>
359
  <?php
360
+ }
361
  //End elseif ?>
362
 
363
+ <tr>
364
+ <th><label for="yasr-id"><?php _e("Top 10 overall ratings"); ?></label></th>
365
+ <td><input type="button" class="button-primary" name="yasr-top-10-overall-rating" id="yasr-top-10-overall-rating" value="Insert Top 10 highest rated"/><br />
366
+ <small><?php _e("Insert Top 10 highest rated by post author"); ?></small></td>
367
+ </tr>
368
+
369
  </table>
370
  </div>
371
 
372
  <script>
373
+ // Add shortcode for overall rating
374
  jQuery('#yasr-overall').on("click", function(){
375
  var shortcode = '[yasr_overall_rating]';
376
  // inserts the shortcode into the active editor
422
  }
423
  //End elseif ?>
424
 
425
+ // Add shortcode for top 10 by overall ratings
426
+ jQuery('#yasr-top-10-overall-rating').on("click", function(){
427
+ var shortcode = '[yasr_10_ten_highest_rated]';
428
+ // inserts the shortcode into the active editor
429
+ tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode);
430
+ // closes Thickbox
431
+ tb_remove();
432
+ });
433
+
434
  </script>
435
 
436
  <?php
737
 
738
  /****** Yasr insert visitor votes, called from yasr-shortcode-function ******/
739
 
740
+ add_action( 'wp_ajax_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback' );
741
+ add_action( 'wp_ajax_nopriv_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback' );
742
 
743
+ function yasr_insert_visitor_votes_callback () {
744
+ if(isset($_POST['rating']) && isset($_POST['post_id'])) {
745
+ $rating = $_POST['rating'];
746
+ $post_id = $_POST['post_id'];
747
+ $nonce_visitor = $_POST['nonce_visitor'];
748
+ }
749
+ else {
750
+ exit();
751
+ }
752
 
753
+ if ( ! wp_verify_nonce( $nonce_visitor, 'yasr_nonce_insert_visitor_rating' ) ) {
754
+ die( 'Security check' );
755
+ }
756
 
757
+ $row_exists_result=NULL; //Avoid Undefined variable notice
758
+ $new_row_result=NULL; ////Avoid Undefined variable notice
759
 
760
+ global $wpdb;
761
 
762
+ $row_exists = $wpdb->get_results ("SELECT number_of_votes, sum_votes FROM " . YASR_VOTES_TABLE . "
763
+ WHERE post_id=$post_id");
764
 
765
+ //If post already has vote, find where it is and sum it
766
+ if ($row_exists) {
767
+ foreach ($row_exists as $user_votes) {
768
+ $number_of_votes = $user_votes->number_of_votes;
769
+ $user_votes_sum = $user_votes->sum_votes;
770
+ }
771
 
772
+ $number_of_votes=$number_of_votes+1;
773
+ $user_votes_sum=$user_votes_sum+$rating;
774
+
775
+ $row_exists_result=$wpdb->update(
776
+ YASR_VOTES_TABLE,
777
+ array (
778
+ 'number_of_votes' => $number_of_votes,
779
+ 'sum_votes' => $user_votes_sum,
780
+ ),
781
+ array (
782
+ 'post_id' => $post_id
783
+ ),
784
+ array('%d', '%s' ),
785
+ array( '%d' )
786
+ );
787
+
788
+ } //End if row_exists
789
 
790
+ else {
791
+ $new_row_result=$wpdb->replace (
792
+ YASR_VOTES_TABLE,
793
+ array (
794
+ 'post_id' => $post_id,
795
+ 'number_of_votes' => 1,
796
+ 'overall_rating' => '-1',
797
+ 'sum_votes' => $rating
798
+ ),
799
+ array ('%d', "%d", "%s", "%s")
 
800
  );
801
+ }
 
802
 
803
+ if ($row_exists_result || $new_row_result ) {
804
+ global $current_user;
805
+ get_currentuserinfo();
806
+
807
+ $result_insert_log = $wpdb->replace (
808
+ YASR_LOG_TABLE,
809
+ array (
810
+ 'post_id' => $post_id,
811
+ 'multi_set_id' => -1,
812
+ 'user_id' => $current_user->ID,
813
+ 'vote' => $rating,
814
+ 'date' => date('Y-m-d H:i:s'),
815
+ 'ip' => $_SERVER['REMOTE_ADDR']
816
+ ),
817
+ array ('%d', '%d', '%d', '%s', '%s', '%s')
818
+ );
819
+ }
820
 
821
+ if($row_exists_result) {
822
+ $total_rating = ($user_votes_sum / $number_of_votes);
823
+ $total_rating=round ($total_rating, 1);
824
+ echo "<div class=\"rateit bigstars\" id=\"yasr_rateit_user_votes_voted\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$total_rating\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\"></div>
825
+ <br /><strong>" . __("Vote Saved" , "yasr") . "</strong><br />" . __("Average Rating", "yasr") . " $total_rating / 5 ($number_of_votes " . __("votes casts", "yasr") . ")";
826
+ }
827
 
828
+ elseif ($new_row_result) {
829
+ echo "<div class=\"rateit bigstars\" id=\"yasr_rateit_user_votes_voted\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$rating\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\"></div>
830
+ <br /><strong>". __("Vote Saved" , "yasr") . "</strong><br />Rating $rating / 5 (1 " . __("vote cast", "yasr") . ")";
831
+ }
 
 
 
 
 
 
 
 
 
832
 
833
+ die(); // this is required to return a proper result
834
+ }
 
 
 
 
835
 
 
 
 
 
836
 
 
 
837
 
838
  /****** Echo a readonly star set if user has already voted for a post ******/
839
 
lib/yasr-db-functions.php CHANGED
@@ -342,6 +342,52 @@ add_action( 'plugins_loaded', 'add_action_dashboard_widget_log' );
342
  } //End callback function
343
 
344
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
 
346
  /****** Check if a logged in user has already rated. Return user vote for a post if exists ******/
347
 
342
  } //End callback function
343
 
344
 
345
+ /****** Delete data value from yasr tabs when a post or page is deleted
346
+ Added since yasr 0.3.3
347
+ ******/
348
+
349
+ add_action ('admin_init', 'admin_init_delete_data_on_post_callback');
350
+
351
+ function admin_init_delete_data_on_post_callback () {
352
+
353
+ if ( current_user_can ('delete_posts') ) {
354
+
355
+ add_action( 'delete_post', 'yasr_erase_data_on_post_page_remove_callback' );
356
+
357
+ }
358
+
359
+ }
360
+
361
+ function yasr_erase_data_on_post_page_remove_callback($pid) {
362
+
363
+ global $wpdb;
364
+
365
+ //Delete overall rating
366
+ $wpdb->delete(
367
+ YASR_VOTES_TABLE,
368
+ array (
369
+ 'post_id' => $pid
370
+ ),
371
+ array (
372
+ '%d'
373
+ )
374
+ );
375
+
376
+ //Delete multi value
377
+ $wpdb->delete(
378
+ YASR_MULTI_SET_VALUES_TABLE,
379
+ array (
380
+ 'post_id' => $pid
381
+ ),
382
+ array (
383
+ '%d'
384
+ )
385
+ );
386
+
387
+
388
+ }
389
+
390
+
391
 
392
  /****** Check if a logged in user has already rated. Return user vote for a post if exists ******/
393
 
lib/yasr-functions.php CHANGED
@@ -13,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
13
  wp_enqueue_style( 'rateitbigstars', YASR_CSS_DIR . 'bigstars.css', array('rateitcss'), NULL, 'all' );
14
  wp_enqueue_style( 'yasrcss', YASR_CSS_DIR . 'yasr.css', array('rateitcss'), NULL, 'all' );
15
  wp_enqueue_script( 'rateit', YASR_JS_DIR . 'jquery.rateit.min.js' , array('jquery'), '1.0.20', TRUE );
16
- wp_enqueue_script( 'cookie', YASR_JS_DIR . 'jquery.cookie.js' , array('jquery', 'rateit'), '1.4.0', TRUE );
17
  }
18
 
19
 
@@ -94,7 +94,273 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
94
  }
95
 
96
 
97
- /****** Auto insert shortcode ******/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
  add_filter('the_content', 'yasr_auto_insert_shortcode_callback');
100
 
@@ -106,19 +372,17 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
106
 
107
  $auto_insert_shortcode=NULL; //To avoid undefined variable notice outside the loop (if (is_singular) )
108
 
109
- if( is_singular() && is_main_query() ) {
110
-
111
- $overall_rating_shortcode='[yasr_overall_rating]';
112
- $visitor_votes_shortcode='[yasr_visitor_votes]';
113
 
114
  if ($option['auto_insert_what']==='overall_rating') {
115
  switch ($option['auto_insert_where']) {
116
  case 'top':
117
- return $overall_rating_shortcode . $content;
118
  break;
119
 
120
  case 'bottom':
121
- return $content . $overall_rating_shortcode;
122
  break;
123
  } //End Switch
124
  } //end ($option['what']=='overall_rating')
@@ -126,11 +390,11 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
126
  elseif ($option['auto_insert_what']==='visitor_rating') {
127
  switch ($option['auto_insert_where']) {
128
  case 'top':
129
- return $visitor_votes_shortcode . $content;
130
  break;
131
 
132
  case 'bottom':
133
- return $content . $visitor_votes_shortcode;
134
  break;
135
  } //End Switch
136
  }
@@ -138,17 +402,15 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
138
  elseif ($option['auto_insert_what']==='both') {
139
  switch ($option['auto_insert_where']) {
140
  case 'top':
141
- return $overall_rating_shortcode . $visitor_votes_shortcode . $content;
142
  break;
143
 
144
  case 'bottom':
145
- return $content . $overall_rating_shortcode . $visitor_votes_shortcode;
146
  break;
147
  } //End Switch
148
  }
149
 
150
- } //End if( is_singular() && is_main_query() )
151
-
152
  return $content;
153
 
154
  } //End if ($option['enabled'] == 1)
13
  wp_enqueue_style( 'rateitbigstars', YASR_CSS_DIR . 'bigstars.css', array('rateitcss'), NULL, 'all' );
14
  wp_enqueue_style( 'yasrcss', YASR_CSS_DIR . 'yasr.css', array('rateitcss'), NULL, 'all' );
15
  wp_enqueue_script( 'rateit', YASR_JS_DIR . 'jquery.rateit.min.js' , array('jquery'), '1.0.20', TRUE );
16
+ wp_enqueue_script( 'cookie', YASR_JS_DIR . 'jquery.cookie.min.js' , array('jquery', 'rateit'), '1.4.0', TRUE );
17
  }
18
 
19
 
94
  }
95
 
96
 
97
+
98
+ /****** Return html code that will output overall rating stars. Used in auto insert overall rating ******/
99
+
100
+ function overall_rating_auto_insert_code () {
101
+
102
+ $overall_rating=yasr_get_overall_rating();
103
+
104
+ if (!$overall_rating) {
105
+ $overall_rating = "-1";
106
+ }
107
+
108
+ $shortcode_html="<div class=\"rateit bigstars\" id=\"yasr_rateit_overall\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$overall_rating\" data-rateit-step=\"0.1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
109
+ </div>";
110
+
111
+ $option = get_option( 'yasr_general_options' );
112
+
113
+ return $shortcode_html;
114
+
115
+ } //End function
116
+
117
+
118
+
119
+ /****** Return html code that will output visitor rating stars. It's almost the same
120
+ than shortcode_visitor_votes_callback used in yasr-shortcode function, but work only when
121
+ is called and have initial different conditions ******/
122
+
123
+ function visitor_votes_auto_insert_code () {
124
+
125
+ $shortcode_html = NULL; //Avoid undefined variable outside is_singular && is_main_query
126
+
127
+ if( is_singular() && is_main_query() ) {
128
+
129
+ $ajax_nonce_visitor = wp_create_nonce( "yasr_nonce_insert_visitor_rating" );
130
+
131
+ $votes=yasr_get_visitor_votes();
132
+
133
+ $medium_rating=0; //Avoid undefined variable
134
+
135
+ if (!$votes) {
136
+ $votes=0; //Avoid undefined variable if there is not overall rating
137
+ $votes_number=0; //Avoid undefined variable
138
+ }
139
+
140
+ else {
141
+ foreach ($votes as $user_votes) {
142
+ $votes_number = $user_votes->number_of_votes;
143
+ if ($votes_number !=0 ) {
144
+ $medium_rating = ($user_votes->sum_votes/$votes_number);
145
+ }
146
+ }
147
+ }
148
+
149
+ $allow_logged_option = get_option( 'yasr_general_options' );
150
+
151
+ if (!$allow_logged_option) {
152
+ $allow_logged_option = array();
153
+ $allow_logged_option['allowed_user']='allow_anonymous';
154
+ }
155
+
156
+ $image = YASR_IMG_DIR . "/loader.gif";
157
+
158
+ $loader_html = "<div id=\"loader-visitor-rating\" >&nbsp; " . __("Loading, please wait","yasr") . " <img src= \" $image \"></div>";
159
+
160
+ $medium_rating=round($medium_rating, 1);
161
+
162
+ //if anonymous are allowed to vote
163
+ if ($allow_logged_option['allowed_user']==='allow_anonymous') {
164
+
165
+ //I've to block a logged in user that has already rated
166
+ if ( is_user_logged_in() ) {
167
+
168
+ //Chek if a logged in user has already rated for this post
169
+ $vote_if_user_already_rated = yasr_check_if_user_already_voted();
170
+
171
+ //If user has already rated show readonly stars
172
+ if ($vote_if_user_already_rated) {
173
+
174
+ global $current_user;
175
+ get_currentuserinfo();
176
+
177
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes_logged_rated\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
178
+ </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ") <br /><strong>" . __("User ") . "$current_user->user_login" . __(" has already voted this article with $vote_if_user_already_rated ", "yasr") . "</strong></div>";
179
+
180
+ }
181
+
182
+ //else logged user can vote
183
+ else {
184
+
185
+ $vote_if_user_already_rated = 0;
186
+
187
+ if ($votes_number>0) {
188
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
189
+ </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ")</div>";
190
+ }
191
+
192
+ else {
193
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"0\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
194
+ </div><br /> " . __("No rating yet" , "yasr") . "</div>";
195
+ }
196
+
197
+ } //End else
198
+
199
+ } //End if user is logged
200
+
201
+
202
+ //else is not logged can vote
203
+ else {
204
+
205
+ if ($votes_number>0) {
206
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
207
+ </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ")</div>";
208
+ }
209
+
210
+ else {
211
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"0\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
212
+ </div><br /> " . __("No rating yet" , "yasr") . "</div>";
213
+ }
214
+
215
+ } //end else
216
+
217
+ } //end if ($allow_logged_option['allowed_user']==='allow_anonymous') {
218
+
219
+
220
+
221
+ //If only logged in users can vote
222
+ elseif ($allow_logged_option['allowed_user']==='logged_only') {
223
+
224
+ //If user is logged in and can vote
225
+ if ( is_user_logged_in() ) {
226
+
227
+ //Chek if a logged in user has already rated for this post
228
+ $vote_if_user_already_rated = yasr_check_if_user_already_voted();
229
+
230
+ if ($vote_if_user_already_rated) {
231
+
232
+ global $current_user;
233
+ get_currentuserinfo();
234
+
235
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes_logged_rated\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
236
+ </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ") <br /><strong>" . __("User ") . "$current_user->user_login" . __(" has already voted this article with $vote_if_user_already_rated ", "yasr") . "</strong></div>";
237
+
238
+ }
239
+
240
+ else {
241
+
242
+ if ($votes_number>0) {
243
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
244
+ </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ")</div>";
245
+ }
246
+
247
+ else {
248
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"0\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
249
+ </div><br /> " . __("No rating yet" , "yasr") . "</div>";
250
+ }
251
+
252
+ }
253
+
254
+
255
+ } //End if user is logged in
256
+
257
+ //Else mean user is not logged in
258
+ else {
259
+
260
+
261
+ if ($votes_number>0) {
262
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
263
+ </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ") <br />" . __("You must sign to vote", "yasr") . "</div>";
264
+ }
265
+
266
+ else {
267
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"0\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
268
+ </div><br /> " . __("No rating yet" , "yasr") . "<br />" . _e("You must sign to vote", "") . "</div>";
269
+ }
270
+
271
+ }
272
+
273
+ }
274
+
275
+
276
+ ?>
277
+
278
+ <script>
279
+ jQuery(document).ready(function() {
280
+
281
+ var logged_message_showed = false;
282
+
283
+ logged_message_showed = jQuery("#yasr_rateit_visitor_votes_logged_rated").attr("data-rateit-value");
284
+
285
+ if (logged_message_showed) {
286
+ logged_message_showed = true;
287
+ }
288
+
289
+
290
+
291
+ var tooltipvalues = ['bad', 'poor', 'ok', 'good', 'super'];
292
+ jQuery("#yasr_rateit_visitor_votes").bind('over', function (event, value) { jQuery(this).attr('title', tooltipvalues[value-1]); });
293
+
294
+ var postid = <?php the_ID(); ?>;
295
+ var cookiename = "yasr_visitor_vote_" + postid;
296
+
297
+ //If there is not cookie allow visitor to vote
298
+ if (!jQuery.cookie(cookiename)) {
299
+
300
+ jQuery('#yasr_rateit_visitor_votes').on('rated', function() {
301
+ var el = jQuery(this);
302
+ var value = el.rateit('value');
303
+ var value = value.toFixed(1); //
304
+ var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
305
+
306
+ jQuery('#yasr_visitor_votes').html( ' <?php echo "$loader_html" ?> ');
307
+
308
+ var data = {
309
+ action: 'yasr_send_visitor_rating',
310
+ rating: value,
311
+ post_id: postid,
312
+ nonce_visitor: "<?php echo "$ajax_nonce_visitor"; ?>"
313
+ };
314
+
315
+ //Send value to the Server
316
+ jQuery.post(ajaxurl, data, function(response) {
317
+ jQuery('#yasr_visitor_votes').html(response);
318
+ jQuery('.rateit').rateit();
319
+ //Create a cookie to disable double vote
320
+ jQuery.cookie(cookiename, value, { expires : 360 });
321
+ }) ;
322
+ });
323
+ } //End if (!jQuery.cookie(cookiename))
324
+
325
+ //Else user cannot vote
326
+ else {
327
+
328
+ //if php read only stars are not be showes echo readonly stars from cookie
329
+ if (!logged_message_showed) {
330
+
331
+ var cookievote=jQuery.cookie(cookiename);
332
+ var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
333
+
334
+ var data = {
335
+ action: 'yasr_readonly_visitor_shortcode',
336
+ rating: cookievote,
337
+ votes: <?php echo $medium_rating ?>,
338
+ votes_number: <?php echo $votes_number ?>,
339
+ post_id: postid
340
+ }
341
+
342
+ jQuery.post(ajaxurl, data, function(response) {
343
+ jQuery('#yasr_visitor_votes').html(response);
344
+ jQuery('.rateit').rateit();
345
+ });
346
+
347
+ }
348
+
349
+ } //End else !logged_user_already_rated)
350
+
351
+ });
352
+
353
+ </script>
354
+
355
+ <?php
356
+
357
+ } //End if is singular
358
+
359
+ return $shortcode_html;
360
+
361
+ } //End function shortcode_visitor_votes_callback
362
+
363
+ /****** Auto insert overall rating and visitor rating ******/
364
 
365
  add_filter('the_content', 'yasr_auto_insert_shortcode_callback');
366
 
372
 
373
  $auto_insert_shortcode=NULL; //To avoid undefined variable notice outside the loop (if (is_singular) )
374
 
375
+ $overall_rating_code = overall_rating_auto_insert_code();
376
+ $visitor_votes_code = visitor_votes_auto_insert_code();
 
 
377
 
378
  if ($option['auto_insert_what']==='overall_rating') {
379
  switch ($option['auto_insert_where']) {
380
  case 'top':
381
+ return $overall_rating_code . $content;
382
  break;
383
 
384
  case 'bottom':
385
+ return $content . $overall_rating_code;
386
  break;
387
  } //End Switch
388
  } //end ($option['what']=='overall_rating')
390
  elseif ($option['auto_insert_what']==='visitor_rating') {
391
  switch ($option['auto_insert_where']) {
392
  case 'top':
393
+ return $visitor_votes_code . $content;
394
  break;
395
 
396
  case 'bottom':
397
+ return $content . $visitor_votes_code;
398
  break;
399
  } //End Switch
400
  }
402
  elseif ($option['auto_insert_what']==='both') {
403
  switch ($option['auto_insert_where']) {
404
  case 'top':
405
+ return $overall_rating_code . $visitor_votes_code . $content;
406
  break;
407
 
408
  case 'bottom':
409
+ return $content . $overall_rating_code . $visitor_votes_code;
410
  break;
411
  } //End Switch
412
  }
413
 
 
 
414
  return $content;
415
 
416
  } //End if ($option['enabled'] == 1)
lib/yasr-settings-functions.php CHANGED
@@ -98,6 +98,9 @@
98
  <?php _e('After the post', 'yasr')?>
99
  <br />
100
 
 
 
 
101
 
102
  <?php
103
 
@@ -116,7 +119,6 @@
116
  <?php _e('Allow everybody (logged in and anonymous)', 'yasr')?>
117
  <br />
118
 
119
-
120
  <p>&nbsp;</p>
121
 
122
  <hr>
@@ -197,7 +199,6 @@ function yasr_display_multi_set_form() {
197
 
198
 
199
 
200
- /****** This function print the form to edit multi-set ******/
201
  function yasr_edit_multi_form() {
202
 
203
  $multi_set=yasr_get_multi_set();
@@ -265,22 +266,30 @@ function yasr_edit_multi_form() {
265
  <?php
266
 
267
  $i=1;
268
- foreach ($set_name as $name) {
269
- echo "
270
- <tr>
 
 
 
 
 
 
 
271
 
272
- <td width=\"80%\">
273
- Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$name->id\">
274
- </td>
275
 
276
- <td width=\"20%\" style=\"text-align:center\">
277
- <input type=\"checkbox\" name=\"remove-element-$name->id\">
278
- </td>
279
 
280
- </tr>
281
- ";
 
282
  $i++;
283
- }
284
 
285
 
286
  $i = $i-1; //This is the number of the fields
@@ -376,7 +385,15 @@ function yasr_edit_multi_form() {
376
  </tr>
377
 
378
  <?php
 
 
 
 
 
379
  foreach ($set_name as $name) {
 
 
 
380
  echo "
381
  <tr>
382
 
@@ -441,6 +458,7 @@ function yasr_edit_multi_form() {
441
 
442
 
443
 
 
444
  /****** Validate new multi set form ******/
445
  function yasr_process_new_multi_set_form()
446
  {
@@ -593,7 +611,6 @@ function yasr_process_new_multi_set_form()
593
 
594
 
595
 
596
- /****** Process Edit multi set form ******/
597
  function yasr_process_edit_multi_set_form() {
598
 
599
  $error = FALSE;
98
  <?php _e('After the post', 'yasr')?>
99
  <br />
100
 
101
+ <p>&nbsp;</p>
102
+
103
+ <hr />
104
 
105
  <?php
106
 
119
  <?php _e('Allow everybody (logged in and anonymous)', 'yasr')?>
120
  <br />
121
 
 
122
  <p>&nbsp;</p>
123
 
124
  <hr>
199
 
200
 
201
 
 
202
  function yasr_edit_multi_form() {
203
 
204
  $multi_set=yasr_get_multi_set();
266
  <?php
267
 
268
  $i=1;
269
+
270
+ //Put in an array the field_id used for this set, to avoid overwrite
271
+ $array_used_field_id = array();
272
+
273
+ foreach ($set_name as $name) {
274
+
275
+ $array_used_field_id[] .= $name->id;
276
+
277
+ echo "
278
+ <tr>
279
 
280
+ <td width=\"80%\">
281
+ Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$name->id\">
282
+ </td>
283
 
284
+ <td width=\"20%\" style=\"text-align:center\">
285
+ <input type=\"checkbox\" name=\"remove-element-$name->id\">
286
+ </td>
287
 
288
+ </tr>
289
+ ";
290
+
291
  $i++;
292
+ }
293
 
294
 
295
  $i = $i-1; //This is the number of the fields
385
  </tr>
386
 
387
  <?php
388
+
389
+ //Put in an array the field_id used for this set, to avoid overwrite
390
+
391
+ $array_used_field_id = array();
392
+
393
  foreach ($set_name as $name) {
394
+
395
+ $array_used_field_id .= $name->id;
396
+
397
  echo "
398
  <tr>
399
 
458
 
459
 
460
 
461
+
462
  /****** Validate new multi set form ******/
463
  function yasr_process_new_multi_set_form()
464
  {
611
 
612
 
613
 
 
614
  function yasr_process_edit_multi_set_form() {
615
 
616
  $error = FALSE;
lib/yasr-shortcode-functions.php CHANGED
@@ -8,86 +8,115 @@ add_shortcode ('yasr_overall_rating', 'shortcode_overall_rating_callback');
8
 
9
  function shortcode_overall_rating_callback () {
10
 
11
- $overall_rating=yasr_get_overall_rating();
12
 
13
- if (!$overall_rating) {
14
- $overall_rating = "-1";
15
- }
16
 
17
- $shortcode_html="<div class=\"rateit bigstars\" id=\"yasr_rateit_overall\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$overall_rating\" data-rateit-step=\"0.1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
18
- </div>";
19
 
20
- return $shortcode_html;
 
 
 
 
 
 
 
 
 
21
 
22
  }
23
 
 
24
  /****** Add shortcode for user vote ******/
25
 
26
  add_shortcode ('yasr_visitor_votes', 'shortcode_visitor_votes_callback');
27
 
28
  function shortcode_visitor_votes_callback () {
29
 
30
- $shortcode_html = NULL; //Avoid undefined variable outside is_singular && is_main_query
31
 
32
- if( is_singular() && is_main_query() ) {
33
 
34
- $ajax_nonce_visitor = wp_create_nonce( "yasr_nonce_insert_visitor_rating" );
35
 
36
- $votes=yasr_get_visitor_votes();
37
 
38
- $medium_rating=0; //Avoid undefined variable
39
 
40
- if (!$votes) {
41
- $votes=0; //Avoid undefined variable if there is not overall rating
42
- $votes_number=0; //Avoid undefined variable
43
- }
44
 
45
- else {
46
- foreach ($votes as $user_votes) {
47
- $votes_number = $user_votes->number_of_votes;
48
- if ($votes_number !=0 ) {
49
- $medium_rating = ($user_votes->sum_votes/$votes_number);
 
 
 
 
 
 
 
 
50
  }
51
  }
52
- }
53
 
54
- $allow_logged_option = get_option( 'yasr_general_options' );
55
 
56
- if (!$allow_logged_option) {
57
- $allow_logged_option = array();
58
- $allow_logged_option['allowed_user']='allow_anonymous';
59
- }
60
 
61
- $image = YASR_IMG_DIR . "/loader.gif";
62
 
63
- $loader_html = "<div id=\"loader-visitor-rating\" >&nbsp; " . __("Loading, please wait","yasr") . " <img src= \" $image \"></div>";
64
 
65
- $medium_rating=round($medium_rating, 1);
66
 
67
- //if anonymous are allowed to vote
68
- if ($allow_logged_option['allowed_user']==='allow_anonymous') {
69
 
70
- //I've to block a logged in user that has already rated
71
- if ( is_user_logged_in() ) {
72
 
73
- //Chek if a logged in user has already rated for this post
74
- $vote_if_user_already_rated = yasr_check_if_user_already_voted();
75
 
76
- //If user has already rated show readonly stars
77
- if ($vote_if_user_already_rated) {
78
 
79
- global $current_user;
80
- get_currentuserinfo();
81
 
82
- $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes_logged_rated\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
83
- </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ") <br /><strong>" . __("User ") . "$current_user->user_login" . __(" has already voted this article with $vote_if_user_already_rated ", "yasr") . "</strong></div>";
84
 
85
- }
86
 
87
- //else logged user can vote
88
- else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
- $vote_if_user_already_rated = 0;
 
 
91
 
92
  if ($votes_number>0) {
93
  $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
@@ -99,173 +128,158 @@ function shortcode_visitor_votes_callback () {
99
  </div><br /> " . __("No rating yet" , "yasr") . "</div>";
100
  }
101
 
102
- } //End else
 
 
103
 
104
- } //End if user is logged
105
 
106
 
107
- //else is not logged can vote
108
- else {
109
 
110
- if ($votes_number>0) {
111
- $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
112
- </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ")</div>";
113
- }
114
 
115
- else {
116
- $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"0\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
117
- </div><br /> " . __("No rating yet" , "yasr") . "</div>";
118
- }
119
 
120
- } //end else
121
-
122
- } //end if ($allow_logged_option['allowed_user']==='allow_anonymous') {
123
 
 
 
124
 
 
 
125
 
126
- //If only logged in users can vote
127
- elseif ($allow_logged_option['allowed_user']==='logged_only') {
128
 
129
- //If user is logged in and can vote
130
- if ( is_user_logged_in() ) {
131
 
132
- //Chek if a logged in user has already rated for this post
133
- $vote_if_user_already_rated = yasr_check_if_user_already_voted();
 
 
134
 
135
- if ($vote_if_user_already_rated) {
 
 
 
136
 
137
- global $current_user;
138
- get_currentuserinfo();
139
 
140
- $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes_logged_rated\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
141
- </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ") <br /><strong>" . __("User ") . "$current_user->user_login" . __(" has already voted this article with $vote_if_user_already_rated ", "yasr") . "</strong></div>";
142
 
143
- }
144
 
 
145
  else {
146
 
 
147
  if ($votes_number>0) {
148
- $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
149
- </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ")</div>";
150
  }
151
 
152
  else {
153
- $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"0\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
154
- </div><br /> " . __("No rating yet" , "yasr") . "</div>";
155
  }
156
 
157
  }
 
 
158
 
159
 
160
- } //End if user is logged in
161
 
162
- //Else mean user is not logged in
163
- else {
164
 
 
165
 
166
- if ($votes_number>0) {
167
- $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
168
- </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ") <br />" . __("You must sign to vote", "yasr") . "</div>";
169
- }
170
 
171
- else {
172
- $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"0\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
173
- </div><br /> " . __("No rating yet" , "yasr") . "<br />" . _e("You must sign to vote", "") . "</div>";
174
  }
175
 
176
- }
177
-
178
- }
179
 
 
 
180
 
181
- ?>
 
182
 
183
- <script>
184
- jQuery(document).ready(function() {
185
 
186
- var logged_message_showed = false;
 
 
 
 
187
 
188
- logged_message_showed = jQuery("#yasr_rateit_visitor_votes_logged_rated").attr("data-rateit-value");
189
 
190
- if (logged_message_showed) {
191
- logged_message_showed = true;
192
- }
 
 
 
193
 
194
-
195
-
196
- var tooltipvalues = ['bad', 'poor', 'ok', 'good', 'super'];
197
- jQuery("#yasr_rateit_visitor_votes").bind('over', function (event, value) { jQuery(this).attr('title', tooltipvalues[value-1]); });
198
-
199
- var postid = <?php the_ID(); ?>;
200
- var cookiename = "yasr_visitor_vote_" + postid;
201
-
202
- //If there is not cookie allow visitor to vote
203
- if (!jQuery.cookie(cookiename)) {
204
-
205
- jQuery('#yasr_rateit_visitor_votes').on('rated', function() {
206
- var el = jQuery(this);
207
- var value = el.rateit('value');
208
- var value = value.toFixed(1); //
209
- var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
210
-
211
- jQuery('#yasr_visitor_votes').html( ' <?php echo "$loader_html" ?> ');
212
 
213
- var data = {
214
- action: 'yasr_send_visitor_rating',
215
- rating: value,
216
- post_id: postid,
217
- nonce_visitor: "<?php echo "$ajax_nonce_visitor"; ?>"
218
- };
219
 
220
- //Send value to the Server
221
- jQuery.post(ajaxurl, data, function(response) {
222
- jQuery('#yasr_visitor_votes').html(response);
223
- jQuery('.rateit').rateit();
224
- //Create a cookie to disable double vote
225
- jQuery.cookie(cookiename, value, { expires : 360 });
226
- }) ;
227
- });
228
- } //End if (!jQuery.cookie(cookiename))
229
 
230
- //Else user cannot vote
231
- else {
232
 
233
- //if php read only stars are not be showes echo readonly stars from cookie
234
- if (!logged_message_showed) {
 
 
 
 
 
235
 
236
- var cookievote=jQuery.cookie(cookiename);
237
- var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
 
 
238
 
239
- var data = {
240
- action: 'yasr_readonly_visitor_shortcode',
241
- rating: cookievote,
242
- votes: <?php echo $medium_rating ?>,
243
- votes_number: <?php echo $votes_number ?>,
244
- post_id: postid
245
  }
246
 
247
- jQuery.post(ajaxurl, data, function(response) {
248
- jQuery('#yasr_visitor_votes').html(response);
249
- jQuery('.rateit').rateit();
250
- });
251
-
252
- }
253
 
254
- } //End else !logged_user_already_rated)
255
 
256
- });
257
 
258
- </script>
259
 
260
- <?php
261
 
262
- } //End if is singular
263
 
264
- return $shortcode_html;
265
 
266
  } //End function shortcode_visitor_votes_callback
267
 
268
 
 
269
  /****** Add shortcode for multiple set ******/
270
 
271
  add_shortcode ('yasr_multiset', 'shortcode_multi_set_callback');
@@ -317,7 +331,7 @@ function shortcode_multi_set_callback( $atts ) {
317
 
318
 
319
 
320
- /****** Add top 10 highest rated post *****
321
 
322
  add_shortcode ('yasr_10_ten_highest_rated', 'yasr_top_ten_highest_rated_callback');
323
 
@@ -325,7 +339,11 @@ function yasr_top_ten_highest_rated_callback () {
325
 
326
  global $wpdb;
327
 
328
- $query_result = $wpdb->get_results("SELECT overall_rating, post_id FROM " . YASR_VOTES_TABLE . " ORDER BY overall_rating DESC LIMIT 10");
 
 
 
 
329
 
330
  if ($query_result) {
331
 
@@ -333,15 +351,18 @@ function yasr_top_ten_highest_rated_callback () {
333
 
334
  foreach ($query_result as $result) {
335
 
 
 
336
  $post_title = get_the_title($result->post_id);
337
 
338
  $link = get_permalink($result->post_id); //Get permalink from post it
339
 
340
  $shortcode_html .= "<tr>
341
  <td><a href=\"$link\">$post_title</a></td>
342
- <td><div class=\"rateit\" data-rateit-value=\"$result->overall_rating\" data-rateit-step=\"0.1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\"></div></td>
343
  </tr>";
344
 
 
345
  } //End foreach
346
 
347
  $shortcode_html .= "</table>";
@@ -356,6 +377,6 @@ function yasr_top_ten_highest_rated_callback () {
356
 
357
  } //End function
358
 
359
- */
360
 
361
  ?>
8
 
9
  function shortcode_overall_rating_callback () {
10
 
11
+ $option = get_option( 'yasr_general_options' );
12
 
13
+ if ($option['auto_insert_enabled'] == 0 || ($option['auto_insert_enabled'] == 1 && $option['auto_insert_what'] === 'visitor_rating' )) {
 
 
14
 
15
+ $overall_rating=yasr_get_overall_rating();
 
16
 
17
+ if (!$overall_rating) {
18
+ $overall_rating = "-1";
19
+ }
20
+
21
+ $shortcode_html="<div class=\"rateit bigstars\" id=\"yasr_rateit_overall\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$overall_rating\" data-rateit-step=\"0.1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
22
+ </div>";
23
+
24
+ return $shortcode_html;
25
+
26
+ }
27
 
28
  }
29
 
30
+
31
  /****** Add shortcode for user vote ******/
32
 
33
  add_shortcode ('yasr_visitor_votes', 'shortcode_visitor_votes_callback');
34
 
35
  function shortcode_visitor_votes_callback () {
36
 
37
+ $option = get_option( 'yasr_general_options' );
38
 
39
+ if ($option['auto_insert_enabled'] == 0 || ($option['auto_insert_enabled'] == 1 && $option['auto_insert_what'] === 'overall_rating' )) {
40
 
41
+ $shortcode_html = NULL; //Avoid undefined variable outside is_singular && is_main_query
42
 
43
+ if( is_singular() && is_main_query() ) {
44
 
45
+ $ajax_nonce_visitor = wp_create_nonce( "yasr_nonce_insert_visitor_rating" );
46
 
47
+ $votes=yasr_get_visitor_votes();
 
 
 
48
 
49
+ $medium_rating=0; //Avoid undefined variable
50
+
51
+ if (!$votes) {
52
+ $votes=0; //Avoid undefined variable if there is not overall rating
53
+ $votes_number=0; //Avoid undefined variable
54
+ }
55
+
56
+ else {
57
+ foreach ($votes as $user_votes) {
58
+ $votes_number = $user_votes->number_of_votes;
59
+ if ($votes_number !=0 ) {
60
+ $medium_rating = ($user_votes->sum_votes/$votes_number);
61
+ }
62
  }
63
  }
 
64
 
65
+ $allow_logged_option = get_option( 'yasr_general_options' );
66
 
67
+ if (!$allow_logged_option) {
68
+ $allow_logged_option = array();
69
+ $allow_logged_option['allowed_user']='allow_anonymous';
70
+ }
71
 
72
+ $image = YASR_IMG_DIR . "/loader.gif";
73
 
74
+ $loader_html = "<div id=\"loader-visitor-rating\" >&nbsp; " . __("Loading, please wait","yasr") . " <img src= \" $image \"></div>";
75
 
76
+ $medium_rating=round($medium_rating, 1);
77
 
78
+ //if anonymous are allowed to vote
79
+ if ($allow_logged_option['allowed_user']==='allow_anonymous') {
80
 
81
+ //I've to block a logged in user that has already rated
82
+ if ( is_user_logged_in() ) {
83
 
84
+ //Chek if a logged in user has already rated for this post
85
+ $vote_if_user_already_rated = yasr_check_if_user_already_voted();
86
 
87
+ //If user has already rated show readonly stars
88
+ if ($vote_if_user_already_rated) {
89
 
90
+ global $current_user;
91
+ get_currentuserinfo();
92
 
93
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes_logged_rated\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
94
+ </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ") <br /><strong>" . __("User ") . "$current_user->user_login" . __(" has already voted this article with $vote_if_user_already_rated ", "yasr") . "</strong></div>";
95
 
96
+ }
97
 
98
+ //else logged user can vote
99
+ else {
100
+
101
+ $vote_if_user_already_rated = 0;
102
+
103
+ if ($votes_number>0) {
104
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
105
+ </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ")</div>";
106
+ }
107
+
108
+ else {
109
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"0\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
110
+ </div><br /> " . __("No rating yet" , "yasr") . "</div>";
111
+ }
112
+
113
+ } //End else
114
+
115
+ } //End if user is logged
116
 
117
+
118
+ //else is not logged can vote
119
+ else {
120
 
121
  if ($votes_number>0) {
122
  $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
128
  </div><br /> " . __("No rating yet" , "yasr") . "</div>";
129
  }
130
 
131
+ } //end else
132
+
133
+ } //end if ($allow_logged_option['allowed_user']==='allow_anonymous') {
134
 
 
135
 
136
 
137
+ //If only logged in users can vote
138
+ elseif ($allow_logged_option['allowed_user']==='logged_only') {
139
 
140
+ //If user is logged in and can vote
141
+ if ( is_user_logged_in() ) {
 
 
142
 
143
+ //Chek if a logged in user has already rated for this post
144
+ $vote_if_user_already_rated = yasr_check_if_user_already_voted();
 
 
145
 
146
+ if ($vote_if_user_already_rated) {
 
 
147
 
148
+ global $current_user;
149
+ get_currentuserinfo();
150
 
151
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes_logged_rated\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
152
+ </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ") <br /><strong>" . __("User ") . "$current_user->user_login" . __(" has already voted this article with $vote_if_user_already_rated ", "yasr") . "</strong></div>";
153
 
154
+ }
 
155
 
156
+ else {
 
157
 
158
+ if ($votes_number>0) {
159
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
160
+ </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ")</div>";
161
+ }
162
 
163
+ else {
164
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"0\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"false\">
165
+ </div><br /> " . __("No rating yet" , "yasr") . "</div>";
166
+ }
167
 
168
+ }
 
169
 
 
 
170
 
171
+ } //End if user is logged in
172
 
173
+ //Else mean user is not logged in
174
  else {
175
 
176
+
177
  if ($votes_number>0) {
178
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$medium_rating\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
179
+ </div><br /> " . __("Average Rating", "yasr") . " $medium_rating / 5 (" . __("$votes_number votes casts" , "yasr") . ") <br />" . __("You must sign to vote", "yasr") . "</div>";
180
  }
181
 
182
  else {
183
+ $shortcode_html="<div id=\"yasr_visitor_votes\"><div class=\"rateit bigstars\" id=\"yasr_rateit_visitor_votes\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"0\" data-rateit-step=\"1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
184
+ </div><br /> " . __("No rating yet" , "yasr") . "<br />" . _e("You must sign to vote", "") . "</div>";
185
  }
186
 
187
  }
188
+
189
+ }
190
 
191
 
192
+ ?>
193
 
194
+ <script>
195
+ jQuery(document).ready(function() {
196
 
197
+ var logged_message_showed = false;
198
 
199
+ logged_message_showed = jQuery("#yasr_rateit_visitor_votes_logged_rated").attr("data-rateit-value");
 
 
 
200
 
201
+ if (logged_message_showed) {
202
+ logged_message_showed = true;
 
203
  }
204
 
205
+
 
 
206
 
207
+ var tooltipvalues = ['bad', 'poor', 'ok', 'good', 'super'];
208
+ jQuery("#yasr_rateit_visitor_votes").bind('over', function (event, value) { jQuery(this).attr('title', tooltipvalues[value-1]); });
209
 
210
+ var postid = <?php the_ID(); ?>;
211
+ var cookiename = "yasr_visitor_vote_" + postid;
212
 
213
+ //If there is not cookie allow visitor to vote
214
+ if (!jQuery.cookie(cookiename)) {
215
 
216
+ jQuery('#yasr_rateit_visitor_votes').on('rated', function() {
217
+ var el = jQuery(this);
218
+ var value = el.rateit('value');
219
+ var value = value.toFixed(1); //
220
+ var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
221
 
222
+ jQuery('#yasr_visitor_votes').html( ' <?php echo "$loader_html" ?> ');
223
 
224
+ var data = {
225
+ action: 'yasr_send_visitor_rating',
226
+ rating: value,
227
+ post_id: postid,
228
+ nonce_visitor: "<?php echo "$ajax_nonce_visitor"; ?>"
229
+ };
230
 
231
+ //Send value to the Server
232
+ jQuery.post(ajaxurl, data, function(response) {
233
+ jQuery('#yasr_visitor_votes').html(response);
234
+ jQuery('.rateit').rateit();
235
+ //Create a cookie to disable double vote
236
+ jQuery.cookie(cookiename, value, { expires : 360 });
237
+ }) ;
238
+ });
239
+ } //End if (!jQuery.cookie(cookiename))
 
 
 
 
 
 
 
 
 
240
 
241
+ //Else user cannot vote
242
+ else {
 
 
 
 
243
 
244
+ //if php read only stars are not be showes echo readonly stars from cookie
245
+ if (!logged_message_showed) {
 
 
 
 
 
 
 
246
 
247
+ var cookievote=jQuery.cookie(cookiename);
248
+ var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
249
 
250
+ var data = {
251
+ action: 'yasr_readonly_visitor_shortcode',
252
+ rating: cookievote,
253
+ votes: <?php echo $medium_rating ?>,
254
+ votes_number: <?php echo $votes_number ?>,
255
+ post_id: postid
256
+ }
257
 
258
+ jQuery.post(ajaxurl, data, function(response) {
259
+ jQuery('#yasr_visitor_votes').html(response);
260
+ jQuery('.rateit').rateit();
261
+ });
262
 
 
 
 
 
 
 
263
  }
264
 
265
+ } //End else !logged_user_already_rated)
 
 
 
 
 
266
 
267
+ });
268
 
269
+ </script>
270
 
271
+ <?php
272
 
273
+ } //End if is singular
274
 
275
+ return $shortcode_html;
276
 
277
+ } //End if auto_insert_enabled
278
 
279
  } //End function shortcode_visitor_votes_callback
280
 
281
 
282
+
283
  /****** Add shortcode for multiple set ******/
284
 
285
  add_shortcode ('yasr_multiset', 'shortcode_multi_set_callback');
331
 
332
 
333
 
334
+ /****** Add top 10 highest rated post *****/
335
 
336
  add_shortcode ('yasr_10_ten_highest_rated', 'yasr_top_ten_highest_rated_callback');
337
 
339
 
340
  global $wpdb;
341
 
342
+ $query_result = $wpdb->get_results("SELECT v.overall_rating, v.post_id, p.post_status
343
+ FROM " . YASR_VOTES_TABLE . " AS v, $wpdb->posts AS p
344
+ WHERE v.post_id = p.ID
345
+ AND p.post_status = 'publish'
346
+ ORDER BY v.overall_rating DESC, v.id ASC LIMIT 10");
347
 
348
  if ($query_result) {
349
 
351
 
352
  foreach ($query_result as $result) {
353
 
354
+ $post_status = get_post_status($result->post_id);
355
+
356
  $post_title = get_the_title($result->post_id);
357
 
358
  $link = get_permalink($result->post_id); //Get permalink from post it
359
 
360
  $shortcode_html .= "<tr>
361
  <td><a href=\"$link\">$post_title</a></td>
362
+ <td><div class=\"rateit charts\" data-rateit-starwidth=\"24\" data-rateit-starheight=\"24\" data-rateit-value=\"$result->overall_rating\" data-rateit-step=\"0.1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\"></div></td>
363
  </tr>";
364
 
365
+
366
  } //End foreach
367
 
368
  $shortcode_html .= "</table>";
377
 
378
  } //End function
379
 
380
+
381
 
382
  ?>
readme.txt CHANGED
@@ -3,7 +3,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
3
  Tags: Rating, Review, Star, Snippet, Rich snippet, Schema, Schema.org, Serp
4
  Requires at least: 3.5
5
  Tested up to: 3.9.1
6
- Stable tag: 0.3.2
7
  License: GPL2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -48,6 +48,15 @@ If with gd-star-rating you're using a different number of stars from the default
48
 
49
  == Changelog ==
50
 
 
 
 
 
 
 
 
 
 
51
  = 0.3.2 =
52
  * Forced multiset field name to be #555 . This is to avoid reading problem when using light font color
53
 
3
  Tags: Rating, Review, Star, Snippet, Rich snippet, Schema, Schema.org, Serp
4
  Requires at least: 3.5
5
  Tested up to: 3.9.1
6
+ Stable tag: 0.3.3
7
  License: GPL2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
48
 
49
  == Changelog ==
50
 
51
+ = 0.3.3 =
52
+ * Created a new shortcode that will allow to insert Top 10 highest rated product by author
53
+ * When a post or page is permanently deleted, yasr will delete every votes for that post or page
54
+ * Overall Rating is now avaible in home page and archive pages
55
+ * Fixed "add element button" when only 1 multi set is used
56
+ * Updated jquery cookie from 1.4.0 to 1.4.1 and minified it
57
+ * Minor Bug fixes
58
+
59
+
60
  = 0.3.2 =
61
  * Forced multiset field name to be #555 . This is to avoid reading problem when using light font color
62
 
yasr-settings-page.php CHANGED
@@ -368,9 +368,9 @@ if ( !current_user_can( 'manage_options' ) ) {
368
  <?php if ($n_multi_set == 1) { ?>
369
 
370
 
371
- jQuery('#yasr-manage-multi-set-single').on('click', function() {
372
 
373
- jQuery('.yasr-manage-multiset-single').toggle();
374
 
375
  var counter = jQuery("#yasr-edit-form-number-elements").attr('value');
376
 
@@ -394,7 +394,7 @@ if ( !current_user_can( 'manage_options' ) ) {
394
 
395
  });
396
 
397
- });
398
 
399
  <?php
400
 
@@ -455,4 +455,4 @@ if ( !current_user_can( 'manage_options' ) ) {
455
 
456
  ?>
457
 
458
- </script>
368
  <?php if ($n_multi_set == 1) { ?>
369
 
370
 
371
+ //jQuery('#yasr-manage-multi-set-single').on('click', function() {
372
 
373
+ //jQuery('.yasr-manage-multiset-single').toggle();
374
 
375
  var counter = jQuery("#yasr-edit-form-number-elements").attr('value');
376
 
394
 
395
  });
396
 
397
+ // });
398
 
399
  <?php
400
 
455
 
456
  ?>
457
 
458
+ </script>
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: 0.3.2
7
  * Author: Dario Curvino
8
  * Author URI: http://profiles.wordpress.org/dudo/
9
  * License: GPL2
@@ -28,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
28
  */
29
 
30
 
31
- define('YASR_VERSION_NUM', '0.3.2');
32
 
33
  //Plugin absolute path
34
  define( "YASR_ABSOLUTE_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: 0.3.3
7
  * Author: Dario Curvino
8
  * Author URI: http://profiles.wordpress.org/dudo/
9
  * License: GPL2
28
  */
29
 
30
 
31
+ define('YASR_VERSION_NUM', '0.3.3');
32
 
33
  //Plugin absolute path
34
  define( "YASR_ABSOLUTE_PATH", dirname(__FILE__) );