Yasr – Yet Another Stars Rating - Version 2.3.0

Version Description

  • NEW FEATURE: YASR now support all caching plugin available out there. Just select "yes" at the question "Load results with AJAX" in the settings page.
  • ENHANCEMENT: Added itemListElement in recipeInstructions
  • TWEAKED: rich snippet are returned only if rating is found
  • TWEAKED: Huge Code Refactor
  • Minor changes
Download this release

Release Info

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

Code changes from version 2.2.9 to 2.3.0

css/yasr.css CHANGED
@@ -4,6 +4,7 @@
4
display:inline-block;
5
background-position: 0 0;
6
background-repeat: repeat-x;
7
}
8
9
.yasr-star-rating[data-title]:hover:after {
4
display:inline-block;
5
background-position: 0 0;
6
background-repeat: repeat-x;
7
+ vertical-align: bottom;
8
}
9
10
.yasr-star-rating[data-title]:hover:after {
js/rater-js-rtl.js CHANGED
@@ -196,10 +196,12 @@
196
throw new Error("Value must be a number or undefined.");
197
}
198
199
- if (value < 0 || value > stars) {
200
- var ratingError = new Error("Value too high. Please set a rating of " + stars + " or below.");
201
- ratingError.name = "ratingError";
202
- throw ratingError;
203
}
204
205
rating = value;
196
throw new Error("Value must be a number or undefined.");
197
}
198
199
+ if (value < 0) {
200
+ value = 0;
201
+ }
202
+
203
+ if ( value > 5) {
204
+ value = 5;
205
}
206
207
rating = value;
js/rater-js.js CHANGED
@@ -22,7 +22,7 @@
22
}
23
}
24
25
- var stars = options.max || 5;
26
var starSize = options.starSize || 16;
27
var step = options.step || 1;
28
var onHover = options.onHover;
@@ -185,10 +185,12 @@
185
throw new Error("Value must be a number or undefined.");
186
}
187
188
- if (value < 0 || value > stars) {
189
- var ratingError = new Error("Value too high. Please set a rating of " + stars + " or below.");
190
- ratingError.name = "ratingError";
191
- throw ratingError;
192
}
193
194
rating = value;
22
}
23
}
24
25
+ var stars = 5;
26
var starSize = options.starSize || 16;
27
var step = options.step || 1;
28
var onHover = options.onHover;
185
throw new Error("Value must be a number or undefined.");
186
}
187
188
+ if (value < 0) {
189
+ value = 0;
190
+ }
191
+
192
+ if ( value > 5) {
193
+ value = 5;
194
}
195
196
rating = value;
js/yasr-admin.js CHANGED
@@ -124,7 +124,7 @@ function YasrSettingsPage(activeTab, nMultiSet, autoInsertEnabled, textBeforeSta
124
var data = {
125
action: 'yasr_get_multi_set',
126
set_id: jQuery('#yasr_select_edit_set').val()
127
- }
128
129
jQuery.post(ajaxurl, data, function (response) {
130
jQuery('#yasr-multi-set-response').show();
124
var data = {
125
action: 'yasr_get_multi_set',
126
set_id: jQuery('#yasr_select_edit_set').val()
127
+ };
128
129
jQuery.post(ajaxurl, data, function (response) {
130
jQuery('#yasr-multi-set-response').show();
js/yasr-front.js CHANGED
@@ -38,17 +38,12 @@ document.addEventListener('DOMContentLoaded', function(event) {
38
39
//Check to draw tooltips
40
if (yasrRaterVVInDom) {
41
-
42
if (yasrCommonData.visitorStatsEnabled === 'yes') {
43
-
44
var yasrStatsInDom = document.getElementsByClassName('yasr-dashicons-visitor-stats');
45
-
46
if (yasrStatsInDom) {
47
yasrDrawTipsProgress (yasrStatsInDom);
48
}
49
-
50
}
51
-
52
}
53
54
if (typeof yasrMostHighestRanking !== 'undefined') {
@@ -116,14 +111,12 @@ function yasrDrawTipsProgress (yasrStatsInDom) {
116
onShow: function onShow(tip) {
117
118
if (htmlId !== htmlIdChecked) {
119
-
120
jQuery.post(yasrCommonData.ajaxurl, data, function (response) {
121
response = JSON.parse(response);
122
tip.setContent(response);
123
124
});
125
}
126
-
127
},
128
onHidden: function onHidden() {
129
htmlIdChecked = htmlId;
@@ -181,60 +174,59 @@ function yasrVisitorVotesFront (yasrRaterVVInDom) {
181
182
(function(i) {
183
184
- var postId = yasrRaterVVInDom.item(i).getAttribute('data-rater-postid');
185
- var htmlId = yasrRaterVVInDom.item(i).id;
186
- var uniqueId = htmlId.replace('yasr-visitor-votes-rater-', '');
187
- var starSize = parseInt(yasrRaterVVInDom.item(i).getAttribute('data-rater-starsize'));
188
- var readonly = yasrRaterVVInDom.item(i).getAttribute('data-rater-readonly');
189
- var nonce = yasrRaterVVInDom.item(i).getAttribute('data-rater-nonce');
190
- var isSingular = yasrRaterVVInDom.item(i).getAttribute('data-issingular');
191
192
- //Convert string to boolean
193
- readonly = yasrTrueFalseStringConvertion(readonly);
194
- isSingular = yasrTrueFalseStringConvertion (isSingular);
195
196
- raterJs({
197
- starSize: starSize,
198
- step: 1,
199
- showToolTip: false,
200
- readOnly: readonly,
201
- element: document.getElementById(htmlId),
202
203
- rateCallback: function rateCallback(rating, done) {
204
205
- //show the loader
206
- document.getElementById('yasr-visitor-votes-container-after-stars-' + uniqueId).innerHTML = yasrCommonData.loaderHtml;
207
208
- //Just leave 1 number after the .
209
- rating = rating.toFixed(1);
210
- //Be sure is a number and not a string
211
- rating = parseFloat(rating);
212
-
213
- //Creating an object with data to send
214
- var data = {
215
- action: 'yasr_send_visitor_rating',
216
- rating: rating,
217
- post_id: postId,
218
- nonce_visitor: nonce,
219
- is_singular : isSingular
220
- };
221
222
- this.setRating(rating);
223
- this.disable();
224
225
- //Send value to the Server
226
- jQuery.post(yasrCommonData.ajaxurl, data, function (response) {
227
- //decode json
228
- response = JSON.parse(response);
229
- document.getElementById('yasr-visitor-votes-container-after-stars-' + uniqueId).innerHTML = response;
230
231
- });
232
233
- done();
234
235
- }
236
237
- });
238
239
})(i);
240
@@ -242,6 +234,50 @@ function yasrVisitorVotesFront (yasrRaterVVInDom) {
242
243
}
244
245
function yasrRaterVisitorsMultiSet (yasrMultiSetVisitorInDom) {
246
247
//will have field id and vote
38
39
//Check to draw tooltips
40
if (yasrRaterVVInDom) {
41
if (yasrCommonData.visitorStatsEnabled === 'yes') {
42
var yasrStatsInDom = document.getElementsByClassName('yasr-dashicons-visitor-stats');
43
if (yasrStatsInDom) {
44
yasrDrawTipsProgress (yasrStatsInDom);
45
}
46
}
47
}
48
49
if (typeof yasrMostHighestRanking !== 'undefined') {
111
onShow: function onShow(tip) {
112
113
if (htmlId !== htmlIdChecked) {
114
jQuery.post(yasrCommonData.ajaxurl, data, function (response) {
115
response = JSON.parse(response);
116
tip.setContent(response);
117
118
});
119
}
120
},
121
onHidden: function onHidden() {
122
htmlIdChecked = htmlId;
174
175
(function(i) {
176
177
+ let rating = yasrRaterVVInDom.item(i).getAttribute('data-rating');
178
+ let readonly = yasrRaterVVInDom.item(i).getAttribute('data-rater-readonly');
179
180
+ let postId = yasrRaterVVInDom.item(i).getAttribute('data-rater-postid');
181
+ let htmlId = yasrRaterVVInDom.item(i).id;
182
+ let uniqueId = htmlId.replace('yasr-visitor-votes-rater-', '');
183
+ let starSize = parseInt(yasrRaterVVInDom.item(i).getAttribute('data-rater-starsize'));
184
+ let nonce = yasrRaterVVInDom.item(i).getAttribute('data-rater-nonce');
185
+ let isSingular = yasrRaterVVInDom.item(i).getAttribute('data-issingular');
186
187
+ let containerVotesNumber = 'yasr-vv-votes-number-container-' + uniqueId;
188
+ let containerAverageNumber = 'yasr-vv-average-container-' + uniqueId;
189
+ let containerAfterStarsID = 'yasr-visitor-votes-container-after-stars-' + uniqueId;
190
+ let spanBottom = false;
191
192
+ //this means that attribute data-rating is not set
193
+ if (rating === null && readonly === null) {
194
195
+ let urlVisitorVotes = 'wp/v2/posts/' + postId + '?_fields=yasr_visitor_votes&_wpnonce='+yasrCommonData.nonce;
196
197
+ fetch(yasrCommonData.restEndpoint + urlVisitorVotes).then(response => {
198
+ return response.json();
199
+ }).then(data => {
200
+ // Work with JSON data here
201
202
+ readonly = data.yasr_visitor_votes.stars_attributes.read_only;
203
204
+ if (data.yasr_visitor_votes.number_of_votes > 0) {
205
+ rating = data.yasr_visitor_votes.sum_votes / data.yasr_visitor_votes.number_of_votes;
206
+ } else {
207
+ rating = 0;
208
+ }
209
+ rating = rating.toFixed(1);
210
+ rating = parseFloat(rating);
211
212
+ document.getElementById(containerVotesNumber).innerHTML = data.yasr_visitor_votes.number_of_votes;
213
+ document.getElementById(containerAverageNumber).innerHTML = rating;
214
215
+ yasrSetVisitorVotesRater(starSize, rating, postId, readonly, htmlId, uniqueId, nonce, isSingular, containerAfterStarsID);
216
217
+ //insert span with text after the average
218
+ if(data.yasr_visitor_votes.stars_attributes.span_bottom !== false) {
219
+ spanBottom = data.yasr_visitor_votes.stars_attributes.span_bottom;
220
+ let yasrTotalAverageContainer = document.getElementById(containerAfterStarsID);
221
+ yasrTotalAverageContainer.insertAdjacentHTML('beforeend', spanBottom);
222
+ }
223
224
+ }).catch(err => {
225
+ // Do something for an error here
226
+ });
227
+ } else {
228
+ yasrSetVisitorVotesRater(starSize, rating, postId, readonly, htmlId, uniqueId, nonce, isSingular, containerAfterStarsID);
229
+ }
230
231
})(i);
232
234
235
}
236
237
+ function yasrSetVisitorVotesRater (starSize, rating, postId, readonly, htmlId, uniqueId, nonce, isSingular, containerAfterStarsID) {
238
+
239
+ //Be sure is a number and not a string
240
+ rating = parseFloat(rating);
241
+
242
+ //raterjs accept only boolean for readOnly element
243
+ readonly = yasrTrueFalseStringConvertion(readonly);
244
+
245
+ raterJs({
246
+ starSize: starSize,
247
+ rating: rating,
248
+ step: 1,
249
+ showToolTip: false,
250
+ readOnly: readonly,
251
+ element: document.getElementById(htmlId),
252
+
253
+ rateCallback: function rateCallback(rating, done) {
254
+ //show the loader
255
+ document.getElementById(containerAfterStarsID).innerHTML = yasrCommonData.loaderHtml;
256
+
257
+ //Creating an object with data to send
258
+ var data = {
259
+ action: 'yasr_send_visitor_rating',
260
+ rating: rating,
261
+ post_id: postId,
262
+ nonce_visitor: nonce,
263
+ is_singular : isSingular
264
+ };
265
+
266
+ this.setRating(rating);
267
+ this.disable();
268
+
269
+ //Send value to the Server
270
+ jQuery.post(yasrCommonData.ajaxurl, data, function (response) {
271
+ //decode json
272
+ response = JSON.parse(response);
273
+ document.getElementById(containerAfterStarsID).innerHTML = response;
274
+ });
275
+ done();
276
+ }
277
+ });
278
+
279
+ }
280
+
281
function yasrRaterVisitorsMultiSet (yasrMultiSetVisitorInDom) {
282
283
//will have field id and vote
lib/YasrRichSnippetAdditionalFields.php CHANGED
@@ -80,12 +80,17 @@ class YasrRichSnippetAdditionalFields {
80
81
if(!empty($saved_data['yasr_recipe_recipeinstructions'])) {
82
$instruction_array = explode(PHP_EOL, $saved_data['yasr_recipe_recipeinstructions']);
83
-
84
$i=0;
85
foreach ($instruction_array as $instrunction) {
86
$instruction_array_clean[$i]['@type'] = "HowToStep";
87
- $instruction_array_clean[$i]['text'] = $instrunction;
88
$i++;
89
}
90
}
91
80
81
if(!empty($saved_data['yasr_recipe_recipeinstructions'])) {
82
$instruction_array = explode(PHP_EOL, $saved_data['yasr_recipe_recipeinstructions']);
83
$i=0;
84
+ $j=1;
85
foreach ($instruction_array as $instrunction) {
86
$instruction_array_clean[$i]['@type'] = "HowToStep";
87
+ $instruction_array_clean[$i]["itemListElement"] = array(
88
+ '@type' => 'ListItem',
89
+ 'position' => $j,
90
+ 'name' => $instrunction
91
+ );
92
$i++;
93
+ $j++;
94
}
95
}
96
lib/admin/editor/yasr-editor-functions.php CHANGED
@@ -73,13 +73,11 @@ add_action('yasr_add_admin_scripts_end', 'yasr_add_js_constant_gutenberg');
73
function yasr_add_js_constant_gutenberg($hook) {
74
75
if ($hook === 'post.php' || $hook === 'post-new.php') {
76
-
77
if (YASR_AUTO_INSERT_ENABLED == 1) {
78
$auto_insert = YASR_AUTO_INSERT_WHAT;
79
} else {
80
$auto_insert = 'disabled';
81
}
82
-
83
wp_localize_script(
84
'yasradmin',
85
'yasrConstantGutenberg',
@@ -88,9 +86,7 @@ function yasr_add_js_constant_gutenberg($hook) {
88
'defaultItemType' => YASR_ITEMTYPE,
89
)
90
);
91
-
92
}
93
-
94
}
95
96
73
function yasr_add_js_constant_gutenberg($hook) {
74
75
if ($hook === 'post.php' || $hook === 'post-new.php') {
76
if (YASR_AUTO_INSERT_ENABLED == 1) {
77
$auto_insert = YASR_AUTO_INSERT_WHAT;
78
} else {
79
$auto_insert = 'disabled';
80
}
81
wp_localize_script(
82
'yasradmin',
83
'yasrConstantGutenberg',
86
'defaultItemType' => YASR_ITEMTYPE,
87
)
88
);
89
}
90
}
91
92
lib/admin/editor/yasr-metabox-schema.php CHANGED
@@ -25,10 +25,10 @@ if (!defined('ABSPATH')) {
25
global $post;
26
27
//is post review
28
- $yasr_nonce_is_post_review = wp_nonce_field("yasr_nonce_is_post_review_action", "yasr_nonce_is_post_review");
29
30
//itemType select
31
- $yasr_nonce_review_type = wp_nonce_field("yasr_nonce_review_type_action", "yasr_nonce_review_type");
32
33
//get all additional post meta
34
$saved_data = get_post_meta($post->ID, 'yasr_schema_additional_fields', true);
@@ -65,7 +65,7 @@ foreach ($array_item_type_info as $item_type) {
65
<?php _e('Is this a review?', 'yet-another-stars-rating'); ?>
66
<br />
67
<div class="yasr-onoffswitch-big" id="yasr-switcher-post-is-review">
68
- <input type="checkbox" name="yasr_is_post_review" class="yasr-onoffswitch-checkbox" value="yes"
69
id="yasr-post-is-review-switch" <?php if ($post->yasr_post_is_review === 'yes') echo " checked='checked' "; ?> >
70
<label class="yasr-onoffswitch-label" for="yasr-post-is-review-switch">
71
<span class="yasr-onoffswitch-inner"></span>
@@ -89,7 +89,7 @@ foreach ($array_item_type_info as $item_type) {
89
<div class="yasr-itemtype-row-container-label-input">
90
<label for="yasr-product-brand">Brand</label>
91
<input type="text" name="yasr_product_brand" id="yasr-product-brand"
92
- value="<?php echo $saved_data['yasr_product_brand'] ?>"
93
>
94
</div>
95
<div class="yasr-itemtype-row-container-description">
@@ -99,7 +99,7 @@ foreach ($array_item_type_info as $item_type) {
99
<div class="yasr-itemtype-row-container-label-input">
100
<label for="yasr-product-sku">Sku</label>
101
<input type="text" name="yasr_product_sku" id="yasr-product-sku"
102
- value="<?php echo $saved_data['yasr_product_sku'] ?>"
103
>
104
</div>
105
<div class="yasr-itemtype-row-container-description">
@@ -122,7 +122,7 @@ foreach ($array_item_type_info as $item_type) {
122
</select>
123
<label for="yasr-product-global-identifier-value" style="width: auto; margin-left: 10px;">Value</label>
124
<input type="text" name="yasr_product_global_identifier_value" id="yasr-product-global-identifier-value"
125
- value="<?php echo $saved_data['yasr_product_global_identifier_value'] ?>"
126
>
127
</div>
128
@@ -139,19 +139,19 @@ foreach ($array_item_type_info as $item_type) {
139
<div class="yasr-itemtype-row-container-label-input">
140
<label for="yasr-product-price">Price</label>
141
<input type="text" name="yasr_product_price" id="yasr-product-price"
142
- value="<?php echo $saved_data['yasr_product_price'] ?>"
143
>
144
</div>
145
<div class="yasr-itemtype-row-container-label-input">
146
<label for="yasr-product-price-currency">Currency</label>
147
<input type="text" name="yasr_product_price_currency" id="yasr-product-price-currency"
148
- value="<?php echo $saved_data['yasr_product_price_currency'] ?>"
149
>
150
</div>
151
<div class="yasr-itemtype-row-container-label-input">
152
<label for="yasr-product-price-valid-until">Price Valid Until</label>
153
<input type="text" name="yasr_product_price_valid_until" id="yasr-product-price-valid-until"
154
- value="<?php echo $saved_data['yasr_product_price_valid_until'] ?>"
155
>
156
</div>
157
<div class="yasr-itemtype-row-container-label-input">
@@ -174,7 +174,7 @@ foreach ($array_item_type_info as $item_type) {
174
<div class="yasr-itemtype-row-container-label-input">
175
<label for="yasr-product-price-url">Url</label>
176
<input type="text" name="yasr_product_price_url" id="yasr-product-price-url"
177
- value="<?php echo $saved_data['yasr_product_price_url'] ?>"
178
>
179
</div>
180
@@ -198,7 +198,7 @@ foreach ($array_item_type_info as $item_type) {
198
<div class="yasr-itemtype-row-container-label-input">
199
<label for="yasr-localbusiness-address">Address</label>
200
<input type="text" name="yasr_localbusiness_address" id="yasr-localbusiness-address"
201
- value="<?php echo $saved_data['yasr_localbusiness_address'] ?>"
202
>
203
</div>
204
<div class="yasr-itemtype-row-container-description">
@@ -208,7 +208,7 @@ foreach ($array_item_type_info as $item_type) {
208
<div class="yasr-itemtype-row-container-label-input">
209
<label for="yasr-localbusiness-pricerange">PriceRange</label>
210
<input type="text" name="yasr_localbusiness_pricerange" id="yasr-localbusiness-pricerange"
211
- value="<?php echo $saved_data['yasr_localbusiness_pricerange'] ?>"
212
>
213
</div>
214
<div class="yasr-itemtype-row-container-description">
@@ -220,7 +220,7 @@ foreach ($array_item_type_info as $item_type) {
220
<div class="yasr-itemtype-row-container-label-input">
221
<label for="yasr-localbusiness-telephone">Telephone</label>
222
<input type="text" name="yasr_localbusiness_telephone" id="yasr-localbusiness-telephone"
223
- value="<?php echo $saved_data['yasr_localbusiness_telephone'] ?>"
224
>
225
</div>
226
<div class="yasr-itemtype-row-container-description">
@@ -237,7 +237,7 @@ foreach ($array_item_type_info as $item_type) {
237
<div class="yasr-itemtype-row-container-label-input">
238
<label for="yasr-recipe-cooktime">cookTime</label>
239
<input type="text" name="yasr_recipe_cooktime" id="yasr-recipe-cooktime"
240
- value="<?php echo $saved_data['yasr_recipe_cooktime'] ?>"
241
>
242
</div>
243
<div class="yasr-itemtype-row-container-description">
@@ -247,7 +247,7 @@ foreach ($array_item_type_info as $item_type) {
247
<div class="yasr-itemtype-row-container-label-input">
248
<label for="yasr-recipe-preptime">prepTime</label>
249
<input type="text" name="yasr_recipe_preptime" id="yasr-recipe-preptime"
250
- value="<?php echo $saved_data['yasr_recipe_preptime'] ?>"
251
>
252
</div>
253
<div class="yasr-itemtype-row-container-description">
@@ -258,7 +258,7 @@ foreach ($array_item_type_info as $item_type) {
258
<div class="yasr-itemtype-row-container-label-input">
259
<label for="yasr-recipe-description">description</label>
260
<input type="text" name="yasr_recipe_description" id="yasr-recipe-description"
261
- value="<?php echo $saved_data['yasr_recipe_description'] ?>"
262
>
263
</div>
264
<div class="yasr-itemtype-row-container-description">
@@ -268,7 +268,7 @@ foreach ($array_item_type_info as $item_type) {
268
<div class="yasr-itemtype-row-container-label-input">
269
<label for="yasr-recipe-keywords">keywords</label>
270
<input type="text" name="yasr_recipe_keywords" id="yasr-recipe-keywords"
271
- value="<?php echo $saved_data['yasr_recipe_keywords'] ?>"
272
>
273
</div>
274
<div class="yasr-itemtype-row-container-description">
@@ -279,7 +279,7 @@ foreach ($array_item_type_info as $item_type) {
279
<div class="yasr-itemtype-row-container-label-input">
280
<label for="yasr-recipe-nutrition">nutrition</label>
281
<input type="text" name="yasr_recipe_nutrition" id="yasr-recipe-nutrition"
282
- value="<?php echo $saved_data['yasr_recipe_nutrition'] ?>"
283
>
284
</div>
285
<div class="yasr-itemtype-row-container-description">
@@ -290,7 +290,7 @@ foreach ($array_item_type_info as $item_type) {
290
<div class="yasr-itemtype-row-container-label-input">
291
<label for="yasr-recipe-category">recipeCategory</label>
292
<input type="text" name="yasr_recipe_recipecategory" id="yasr-recipe-category"
293
- value="<?php echo $saved_data['yasr_recipe_recipecategory'] ?>"
294
>
295
</div>
296
<div class="yasr-itemtype-row-container-description">
@@ -301,7 +301,7 @@ foreach ($array_item_type_info as $item_type) {
301
<div class="yasr-itemtype-row-container-label-input">
302
<label for="yasr-recipe-cuisine">recipeCuisine</label>
303
<input type="text" name="yasr_recipe_recipecuisine" id="yasr-recipe-cuisine"
304
- value="<?php echo $saved_data['yasr_recipe_recipecuisine'] ?>"
305
>
306
</div>
307
<div class="yasr-itemtype-row-container-description">
@@ -345,7 +345,7 @@ foreach ($array_item_type_info as $item_type) {
345
<div class="yasr-itemtype-row-container-label-input">
346
<label for="yasr-recipe-video">Video</label>
347
<input type="text" name="yasr_recipe_video" id="yasr-recipe-video"
348
- value="<?php echo $saved_data['yasr_recipe_video'] ?>"
349
>
350
</div>
351
<div class="yasr-itemtype-row-container-description">
25
global $post;
26
27
//is post review
28
+ $yasr_nonce_is_post_review = wp_nonce_field('yasr_nonce_is_post_review_action', 'yasr_nonce_is_post_review');
29
30
//itemType select
31
+ $yasr_nonce_review_type = wp_nonce_field('yasr_nonce_review_type_action', 'yasr_nonce_review_type');
32
33
//get all additional post meta
34
$saved_data = get_post_meta($post->ID, 'yasr_schema_additional_fields', true);
65
<?php _e('Is this a review?', 'yet-another-stars-rating'); ?>
66
<br />
67
<div class="yasr-onoffswitch-big" id="yasr-switcher-post-is-review">
68
+ <input type="checkbox" name="yasr_is_post_review" class="yasr-onoffswitch-checkbox" value='yes'
69
id="yasr-post-is-review-switch" <?php if ($post->yasr_post_is_review === 'yes') echo " checked='checked' "; ?> >
70
<label class="yasr-onoffswitch-label" for="yasr-post-is-review-switch">
71
<span class="yasr-onoffswitch-inner"></span>
89
<div class="yasr-itemtype-row-container-label-input">
90
<label for="yasr-product-brand">Brand</label>
91
<input type="text" name="yasr_product_brand" id="yasr-product-brand"
92
+ value='<?php echo $saved_data['yasr_product_brand'] ?>'
93
>
94
</div>
95
<div class="yasr-itemtype-row-container-description">
99
<div class="yasr-itemtype-row-container-label-input">
100
<label for="yasr-product-sku">Sku</label>
101
<input type="text" name="yasr_product_sku" id="yasr-product-sku"
102
+ value='<?php echo $saved_data['yasr_product_sku'] ?>'
103
>
104
</div>
105
<div class="yasr-itemtype-row-container-description">
122
</select>
123
<label for="yasr-product-global-identifier-value" style="width: auto; margin-left: 10px;">Value</label>
124
<input type="text" name="yasr_product_global_identifier_value" id="yasr-product-global-identifier-value"
125
+ value='<?php echo $saved_data['yasr_product_global_identifier_value'] ?>'
126
>
127
</div>
128
139
<div class="yasr-itemtype-row-container-label-input">
140
<label for="yasr-product-price">Price</label>
141
<input type="text" name="yasr_product_price" id="yasr-product-price"
142
+ value='<?php echo $saved_data['yasr_product_price'] ?>'
143
>
144
</div>
145
<div class="yasr-itemtype-row-container-label-input">
146
<label for="yasr-product-price-currency">Currency</label>
147
<input type="text" name="yasr_product_price_currency" id="yasr-product-price-currency"
148
+ value='<?php echo $saved_data['yasr_product_price_currency'] ?>'
149
>
150
</div>
151
<div class="yasr-itemtype-row-container-label-input">
152
<label for="yasr-product-price-valid-until">Price Valid Until</label>
153
<input type="text" name="yasr_product_price_valid_until" id="yasr-product-price-valid-until"
154
+ value='<?php echo $saved_data['yasr_product_price_valid_until'] ?>'
155
>
156
</div>
157
<div class="yasr-itemtype-row-container-label-input">
174
<div class="yasr-itemtype-row-container-label-input">
175
<label for="yasr-product-price-url">Url</label>
176
<input type="text" name="yasr_product_price_url" id="yasr-product-price-url"
177
+ value='<?php echo $saved_data['yasr_product_price_url'] ?>'
178
>
179
</div>
180
198
<div class="yasr-itemtype-row-container-label-input">
199
<label for="yasr-localbusiness-address">Address</label>
200
<input type="text" name="yasr_localbusiness_address" id="yasr-localbusiness-address"
201
+ value='<?php echo $saved_data['yasr_localbusiness_address'] ?>'
202
>
203
</div>
204
<div class="yasr-itemtype-row-container-description">
208
<div class="yasr-itemtype-row-container-label-input">
209
<label for="yasr-localbusiness-pricerange">PriceRange</label>
210
<input type="text" name="yasr_localbusiness_pricerange" id="yasr-localbusiness-pricerange"
211
+ value='<?php echo $saved_data['yasr_localbusiness_pricerange'] ?>'
212
>
213
</div>
214
<div class="yasr-itemtype-row-container-description">
220
<div class="yasr-itemtype-row-container-label-input">
221
<label for="yasr-localbusiness-telephone">Telephone</label>
222
<input type="text" name="yasr_localbusiness_telephone" id="yasr-localbusiness-telephone"
223
+ value='<?php echo $saved_data['yasr_localbusiness_telephone'] ?>'
224
>
225
</div>
226
<div class="yasr-itemtype-row-container-description">
237
<div class="yasr-itemtype-row-container-label-input">
238
<label for="yasr-recipe-cooktime">cookTime</label>
239
<input type="text" name="yasr_recipe_cooktime" id="yasr-recipe-cooktime"
240
+ value='<?php echo $saved_data['yasr_recipe_cooktime'] ?>'
241
>
242
</div>
243
<div class="yasr-itemtype-row-container-description">
247
<div class="yasr-itemtype-row-container-label-input">
248
<label for="yasr-recipe-preptime">prepTime</label>
249
<input type="text" name="yasr_recipe_preptime" id="yasr-recipe-preptime"
250
+ value='<?php echo $saved_data['yasr_recipe_preptime'] ?>'
251
>
252
</div>
253
<div class="yasr-itemtype-row-container-description">
258
<div class="yasr-itemtype-row-container-label-input">
259
<label for="yasr-recipe-description">description</label>
260
<input type="text" name="yasr_recipe_description" id="yasr-recipe-description"
261
+ value='<?php echo $saved_data['yasr_recipe_description'] ?>'
262
>
263
</div>
264
<div class="yasr-itemtype-row-container-description">
268
<div class="yasr-itemtype-row-container-label-input">
269
<label for="yasr-recipe-keywords">keywords</label>
270
<input type="text" name="yasr_recipe_keywords" id="yasr-recipe-keywords"
271
+ value='<?php echo $saved_data['yasr_recipe_keywords'] ?>'
272
>
273
</div>
274
<div class="yasr-itemtype-row-container-description">
279
<div class="yasr-itemtype-row-container-label-input">
280
<label for="yasr-recipe-nutrition">nutrition</label>
281
<input type="text" name="yasr_recipe_nutrition" id="yasr-recipe-nutrition"
282
+ value='<?php echo $saved_data['yasr_recipe_nutrition'] ?>'
283
>
284
</div>
285
<div class="yasr-itemtype-row-container-description">
290
<div class="yasr-itemtype-row-container-label-input">
291
<label for="yasr-recipe-category">recipeCategory</label>
292
<input type="text" name="yasr_recipe_recipecategory" id="yasr-recipe-category"
293
+ value='<?php echo $saved_data['yasr_recipe_recipecategory'] ?>'
294
>
295
</div>
296
<div class="yasr-itemtype-row-container-description">
301
<div class="yasr-itemtype-row-container-label-input">
302
<label for="yasr-recipe-cuisine">recipeCuisine</label>
303
<input type="text" name="yasr_recipe_recipecuisine" id="yasr-recipe-cuisine"
304
+ value='<?php echo $saved_data['yasr_recipe_recipecuisine'] ?>'
305
>
306
</div>
307
<div class="yasr-itemtype-row-container-description">
345
<div class="yasr-itemtype-row-container-label-input">
346
<label for="yasr-recipe-video">Video</label>
347
<input type="text" name="yasr_recipe_video" id="yasr-recipe-video"
348
+ value='<?php echo $saved_data['yasr_recipe_video'] ?>'
349
>
350
</div>
351
<div class="yasr-itemtype-row-container-description">
lib/admin/settings/yasr-settings-functions.php CHANGED
@@ -68,6 +68,10 @@ function yasr_general_options_init() {
68
$option['blogposting_organization_logo'] = get_site_icon_url();
69
}
70
71
$description_auto_insert = sprintf(__('Auto Insert Options %s
72
Automatically adds YASR in your post or page. %s
73
Disable this if you prefer to use shortcodes.',
@@ -106,28 +110,28 @@ function yasr_general_options_init() {
106
$option
107
);
108
add_settings_field(
109
- 'yasr_show_overall_in_loop',
110
- __('Show "Overall Rating" in Archive Page?', 'yet-another-stars-rating'),
111
- 'yasr_show_overall_in_loop_callback',
112
'yasr_general_settings_tab',
113
'yasr_general_options_section_id',
114
$option
115
);
116
add_settings_field(
117
- 'yasr_show_visitor_votes_in_loop',
118
- __('Show "Visitor Votes" in Archive Page?', 'yet-another-stars-rating'),
119
- 'yasr_show_visitor_votes_in_loop_callback',
120
- 'yasr_general_settings_tab',
121
- 'yasr_general_options_section_id',
122
- $option
123
);
124
add_settings_field(
125
- 'yasr_allow_only_logged_in_id',
126
- __('Allow only logged in user to vote?', 'yet-another-stars-rating'),
127
- 'yasr_allow_only_logged_in_callback',
128
- 'yasr_general_settings_tab',
129
- 'yasr_general_options_section_id',
130
- $option
131
);
132
add_settings_field(
133
'yasr_enable_ip',
@@ -145,6 +149,15 @@ function yasr_general_options_init() {
145
'yasr_general_options_section_id',
146
$option
147
);
148
}
149
150
function yasr_section_callback() {
@@ -515,6 +528,43 @@ function yasr_visitors_stats_callback($option) {
515
516
}
517
518
function yasr_show_overall_in_loop_callback($option) {
519
520
?>
@@ -559,12 +609,6 @@ function yasr_show_visitor_votes_in_loop_callback($option) {
559
560
<?php _e('If you enable this, "Visitor Votes" will be showed not only in the single article or page, but also in pages like Home Page, category pages or archives.', 'yet-another-stars-rating') ?>
561
562
- <p>&nbsp;</p>
563
-
564
- <?php
565
- submit_button(YASR_SAVE_All_SETTINGS_TEXT);
566
- ?>
567
-
568
<br/>
569
570
<hr>
@@ -573,39 +617,6 @@ function yasr_show_visitor_votes_in_loop_callback($option) {
573
574
}
575
576
- function yasr_allow_only_logged_in_callback($option) {
577
-
578
- ?>
579
-
580
- <input type='radio' name='yasr_general_options[allowed_user]' value='logged_only'
581
- class='yasr_auto_insert_loggedonly' <?php if ($option['allowed_user'] === 'logged_only') {
582
- echo " checked=\"checked\" ";
583
- } ?> />
584
- <?php _e('Allow only logged-in users', 'yet-another-stars-rating') ?>
585
- <br/>
586
-
587
- <input type='radio' name='yasr_general_options[allowed_user]' value='allow_anonymous'
588
- class='yasr_auto_insert_loggedonly' <?php if ($option['allowed_user'] === 'allow_anonymous') {
589
- echo " checked=\"checked\" ";
590
- } ?> />
591
- <?php _e('Allow everybody (logged in and anonymous)', 'yet-another-stars-rating') ?>
592
- <br/>
593
-
594
- <br /><br />
595
- <?php
596
- _e(
597
- 'Select who can rate your posts for yasr_visitor_votes shortcode.',
598
- 'yet-another-stars-rating')
599
- ?>
600
-
601
- <p>&nbsp;</p>
602
-
603
- <hr>
604
-
605
- <?php
606
-
607
- } //End function
608
-
609
function yasr_enable_ip_callback($option) {
610
611
?>
@@ -728,6 +739,7 @@ function yasr_choose_snippet_callback($option) {
728
729
</div>
730
731
732
<p>&nbsp;</p>
733
@@ -735,6 +747,35 @@ function yasr_choose_snippet_callback($option) {
735
736
} //End function yasr_choose_snippet_callback
737
738
function yasr_general_options_sanitize($option) {
739
740
//Array to return
@@ -849,6 +890,15 @@ function yasr_general_options_sanitize($option) {
849
$output['enable_ip'] = 'yes';
850
}
851
852
return $output;
853
854
}
68
$option['blogposting_organization_logo'] = get_site_icon_url();
69
}
70
71
+ if(!isset($option['enable_ajax'])) {
72
+ $option['enable_ajax'] = 'no';
73
+ }
74
+
75
$description_auto_insert = sprintf(__('Auto Insert Options %s
76
Automatically adds YASR in your post or page. %s
77
Disable this if you prefer to use shortcodes.',
110
$option
111
);
112
add_settings_field(
113
+ 'yasr_allow_only_logged_in_id',
114
+ __('Allow only logged in user to vote?', 'yet-another-stars-rating'),
115
+ 'yasr_allow_only_logged_in_callback',
116
'yasr_general_settings_tab',
117
'yasr_general_options_section_id',
118
$option
119
);
120
add_settings_field(
121
+ 'yasr_show_overall_in_loop',
122
+ __('Show "Overall Rating" in Archive Page?', 'yet-another-stars-rating'),
123
+ 'yasr_show_overall_in_loop_callback',
124
+ 'yasr_general_settings_tab',
125
+ 'yasr_general_options_section_id',
126
+ $option
127
);
128
add_settings_field(
129
+ 'yasr_show_visitor_votes_in_loop',
130
+ __('Show "Visitor Votes" in Archive Page?', 'yet-another-stars-rating'),
131
+ 'yasr_show_visitor_votes_in_loop_callback',
132
+ 'yasr_general_settings_tab',
133
+ 'yasr_general_options_section_id',
134
+ $option
135
);
136
add_settings_field(
137
'yasr_enable_ip',
149
'yasr_general_options_section_id',
150
$option
151
);
152
+
153
+ add_settings_field(
154
+ 'yasr_load_with_ajax',
155
+ __('Load results with AJAX', 'yet-another-stars-rating'),
156
+ 'yasr_load_with_ajax_callback',
157
+ 'yasr_general_settings_tab',
158
+ 'yasr_general_options_section_id',
159
+ $option
160
+ );
161
}
162
163
function yasr_section_callback() {
528
529
}
530
531
+ function yasr_allow_only_logged_in_callback($option) {
532
+
533
+ ?>
534
+
535
+ <input type='radio' name='yasr_general_options[allowed_user]' value='logged_only'
536
+ class='yasr_auto_insert_loggedonly' <?php if ($option['allowed_user'] === 'logged_only') {
537
+ echo " checked=\"checked\" ";
538
+ } ?> />
539
+ <?php _e('Allow only logged-in users', 'yet-another-stars-rating') ?>
540
+ <br/>
541
+
542
+ <input type='radio' name='yasr_general_options[allowed_user]' value='allow_anonymous'
543
+ class='yasr_auto_insert_loggedonly' <?php if ($option['allowed_user'] === 'allow_anonymous') {
544
+ echo " checked=\"checked\" ";
545
+ } ?> />
546
+ <?php _e('Allow everybody (logged in and anonymous)', 'yet-another-stars-rating') ?>
547
+ <br/>
548
+
549
+ <br /><br />
550
+ <?php
551
+ _e(
552
+ 'Select who can rate your posts for yasr_visitor_votes shortcode.',
553
+ 'yet-another-stars-rating')
554
+ ?>
555
+
556
+ <p>&nbsp;</p>
557
+
558
+ <?php
559
+ submit_button(YASR_SAVE_All_SETTINGS_TEXT);
560
+ ?>
561
+
562
+ <hr>
563
+
564
+ <?php
565
+
566
+ } //End function
567
+
568
function yasr_show_overall_in_loop_callback($option) {
569
570
?>
609
610
<?php _e('If you enable this, "Visitor Votes" will be showed not only in the single article or page, but also in pages like Home Page, category pages or archives.', 'yet-another-stars-rating') ?>
611
612
<br/>
613
614
<hr>
617
618
}
619
620
function yasr_enable_ip_callback($option) {
621
622
?>
739
740
</div>
741
742
+ <hr />
743
744
<p>&nbsp;</p>
745
747
748
} //End function yasr_choose_snippet_callback
749
750
+ function yasr_load_with_ajax_callback($option) {
751
+ ?>
752
+
753
+ <div class="yasr-onoffswitch-big">
754
+ <input type="checkbox" name="yasr_general_options[enable_ajax]" class="yasr-onoffswitch-checkbox"
755
+ id="yasr-general-options-enable-ajax-switch" <?php if ($option['enable_ajax'] === 'yes') {
756
+ echo " checked='checked' ";
757
+ } ?> >
758
+ <label class="yasr-onoffswitch-label" for="yasr-general-options-enable-ajax-switch">
759
+ <span class="yasr-onoffswitch-inner"></span>
760
+ <span class="yasr-onoffswitch-switch"></span>
761
+ </label>
762
+ </div>
763
+
764
+ <br/>
765
+
766
+ <?php
767
+ _e('This should be enabled if you\'re using caching plugins.
768
+ Not required for yasr_overall_rating and yasr_multiset.',
769
+ 'yet-another-stars-rating'
770
+ );
771
+ ?>
772
+
773
+ <p>&nbsp;</p>
774
+
775
+ <?php
776
+
777
+ } //End function
778
+
779
function yasr_general_options_sanitize($option) {
780
781
//Array to return
890
$output['enable_ip'] = 'yes';
891
}
892
893
+ //Same as above but for enable_ip key
894
+ if (!array_key_exists('enable_ajax', $output)) {
895
+ $output['enable_ajax'] = 'no';
896
+ }
897
+ //if exists must be string 'yes'
898
+ else {
899
+ $output['enable_ajax'] = 'yes';
900
+ }
901
+
902
return $output;
903
904
}
lib/admin/settings/yasr-settings-migration-functions.php CHANGED
@@ -8,9 +8,8 @@ class YasrSearchAndImportRatingPlugin {
8
//only check for active plugin, since import from table will be not used
9
if (is_plugin_active('wp-postratings/wp-postratings.php')) {
10
return true;
11
- } else {
12
- return false;
13
}
14
}
15
16
//Search for KK STar Rating
@@ -18,26 +17,23 @@ class YasrSearchAndImportRatingPlugin {
18
//only check for active plugin, since import from table will be not used
19
if (is_plugin_active('kk-star-ratings/index.php')) {
20
return true;
21
- } else {
22
- return false;
23
}
24
}
25
26
//Search for Rate My Post
27
function yasr_search_rmp () {
28
if (is_plugin_active('rate-my-post/rate-my-post.php')) {
29
return true;
30
- } else {
31
- global $wpdb;
32
33
- $rmp_table = $wpdb->prefix . 'rmp_analytics';
34
35
- if ($wpdb->get_var("SHOW TABLES LIKE '$rmp_table'") == $rmp_table) {
36
- return true;
37
- } else {
38
- return false;
39
- }
40
}
41
}
42
43
//Search for Multi Rating
@@ -45,116 +41,119 @@ class YasrSearchAndImportRatingPlugin {
45
//only check for active plugin, since import from table will be not used
46
if (is_plugin_active('multi-rating/multi-rating.php')) {
47
return true;
48
- } else {
49
- return false;
50
}
51
}
52
53
- function yasr_count_wppr_query_number () {
54
$number_of_query_transient = get_transient('yasr_wppr_import_query_number');
55
56
if($number_of_query_transient !== false) {
57
return $number_of_query_transient;
58
- } else {
59
- $logs = $this->yasr_return_wppr_data();
60
-
61
- //set counter to 0
62
- $i = 0;
63
-
64
- if (empty($logs)) {
65
- return 0;
66
- } else {
67
- //count insert queries
68
- foreach ($logs as $column) {
69
- for ($j=1; $j<=$column->ratings_users; $j++) {
70
- $i ++;
71
- }
72
- }
73
- }
74
75
- set_transient('yasr_wppr_import_query_number', $i, DAY_IN_SECONDS);
76
- return $i;
77
}
78
79
}
80
81
- function yasr_count_kksr_query_number () {
82
$number_of_query_transient = get_transient('yasr_kksr_import_query_number');
83
84
if($number_of_query_transient !== false) {
85
return $number_of_query_transient;
86
- } else {
87
- $logs = $this->yasr_return_kksr_data();
88
-
89
- //set counter to 0
90
- $i = 0;
91
-
92
- if (empty($logs)) {
93
- return 0;
94
- } else {
95
- //count insert queries
96
- foreach ($logs as $column) {
97
- for ($j=1; $j<=$column->ratings_users; $j++) {
98
- $i ++;
99
- }
100
- }
101
- }
102
103
- set_transient('yasr_kksr_import_query_number', $i, DAY_IN_SECONDS);
104
- return $i;
105
}
106
107
}
108
109
- function yasr_count_rmp_query_number () {
110
global $wpdb;
111
112
$number_of_query_transient = get_transient('yasr_rmp_import_query_number');
113
114
if($number_of_query_transient !== false) {
115
return $number_of_query_transient;
116
- } else {
117
- $logs = $this->yasr_return_rmp_data();
118
-
119
- if (empty($logs)) {
120
- return 0;
121
- } else {
122
- set_transient('yasr_rmp_import_query_number', $wpdb->num_rows, DAY_IN_SECONDS);
123
- return $wpdb->num_rows;
124
- }
125
}
126
127
}
128
129
- function yasr_count_mr_query_number () {
130
$number_of_query_transient = get_transient('yasr_mr_import_query_number');
131
132
if($number_of_query_transient !== false) {
133
return $number_of_query_transient;
134
- } else {
135
- $logs=$this->yasr_return_mr_data();
136
-
137
- //set counter to 0
138
- $i = 0;
139
-
140
- if (empty($logs)) {
141
- return 0;
142
- } else {
143
- //count insert queries
144
- foreach ($logs as $column) {
145
- for ($j=1; $j<=$column->ratings_users; $j++) {
146
- $i ++;
147
- }
148
- }
149
}
150
- set_transient('yasr_mr_import_query_number', $i, DAY_IN_SECONDS);
151
- return $i;
152
}
153
154
}
155
156
//Import WpPostRating Data
157
- function yasr_return_wppr_data () {
158
global $wpdb;
159
160
$logs = $wpdb->get_results("
@@ -173,9 +172,9 @@ class YasrSearchAndImportRatingPlugin {
173
174
if (empty($logs)) {
175
return 0;
176
- } else {
177
- return $logs;
178
}
179
}
180
181
//Import KK Star Rating Data
@@ -198,12 +197,12 @@ class YasrSearchAndImportRatingPlugin {
198
199
if (empty($logs)) {
200
return 0;
201
- } else {
202
- return $logs;
203
}
204
}
205
206
- function yasr_return_rmp_data() {
207
global $wpdb;
208
209
$rmp_table=$wpdb->prefix . 'rmp_analytics';
@@ -221,13 +220,13 @@ class YasrSearchAndImportRatingPlugin {
221
222
if (empty($logs)) {
223
return 0;
224
- } else {
225
- return $logs;
226
}
227
}
228
229
//Import Multi Rating Data
230
- function yasr_return_mr_data() {
231
global $wpdb;
232
233
$logs = $wpdb->get_results("
@@ -246,9 +245,9 @@ class YasrSearchAndImportRatingPlugin {
246
247
if (empty($logs)) {
248
return 0;
249
- } else {
250
- return $logs;
251
}
252
}
253
254
}
8
//only check for active plugin, since import from table will be not used
9
if (is_plugin_active('wp-postratings/wp-postratings.php')) {
10
return true;
11
}
12
+ return false;
13
}
14
15
//Search for KK STar Rating
17
//only check for active plugin, since import from table will be not used
18
if (is_plugin_active('kk-star-ratings/index.php')) {
19
return true;
20
}
21
+ return false;
22
}
23
24
//Search for Rate My Post
25
function yasr_search_rmp () {
26
if (is_plugin_active('rate-my-post/rate-my-post.php')) {
27
return true;
28
+ }
29
+ global $wpdb;
30
31
+ $rmp_table = $wpdb->prefix . 'rmp_analytics';
32
33
+ if ($wpdb->get_var("SHOW TABLES LIKE '$rmp_table'") === $rmp_table) {
34
+ return true;
35
}
36
+ return false;
37
}
38
39
//Search for Multi Rating
41
//only check for active plugin, since import from table will be not used
42
if (is_plugin_active('multi-rating/multi-rating.php')) {
43
return true;
44
}
45
+ return false;
46
}
47
48
+ public function yasr_count_wppr_query_number () {
49
$number_of_query_transient = get_transient('yasr_wppr_import_query_number');
50
51
if($number_of_query_transient !== false) {
52
return $number_of_query_transient;
53
+ }
54
55
+ $logs = $this->yasr_return_wppr_data();
56
+
57
+ //set counter to 0
58
+ $i = 0;
59
+
60
+ if (empty($logs)) {
61
+ return 0;
62
}
63
64
+ //count insert queries
65
+ foreach ($logs as $column) {
66
+ for ($j=1; $j<=$column->ratings_users; $j++) {
67
+ $i ++;
68
+ }
69
+ }
70
+
71
+ set_transient('yasr_wppr_import_query_number', $i, DAY_IN_SECONDS);
72
+
73
+ return $i;
74
+
75
}
76
77
+ public function yasr_count_kksr_query_number () {
78
$number_of_query_transient = get_transient('yasr_kksr_import_query_number');
79
80
if($number_of_query_transient !== false) {
81
return $number_of_query_transient;
82
+ }
83
+
84
+ $logs = $this->yasr_return_kksr_data();
85
86
+ //set counter to 0
87
+ $i = 0;
88
+
89
+ if (empty($logs)) {
90
+ return 0;
91
}
92
93
+ //count insert queries
94
+ foreach ($logs as $column) {
95
+ for ($j=1; $j<=$column->ratings_users; $j++) {
96
+ $i ++;
97
+ }
98
+ }
99
+
100
+ set_transient('yasr_kksr_import_query_number', $i, DAY_IN_SECONDS);
101
+
102
+ return $i;
103
+
104
}
105
106
+ public function yasr_count_rmp_query_number () {
107
global $wpdb;
108
109
$number_of_query_transient = get_transient('yasr_rmp_import_query_number');
110
111
if($number_of_query_transient !== false) {
112
return $number_of_query_transient;
113
}
114
115
+ $logs = $this->yasr_return_rmp_data();
116
+
117
+ if (empty($logs)) {
118
+ return 0;
119
+ }
120
+
121
+ set_transient('yasr_rmp_import_query_number', $wpdb->num_rows, DAY_IN_SECONDS);
122
+
123
+ return $wpdb->num_rows;
124
+
125
}
126
127
+ public function yasr_count_mr_query_number () {
128
$number_of_query_transient = get_transient('yasr_mr_import_query_number');
129
130
if($number_of_query_transient !== false) {
131
return $number_of_query_transient;
132
+ }
133
+
134
+ $logs =$this->yasr_return_mr_data();
135
+
136
+ //set counter to 0
137
+ $i = 0;
138
+
139
+ if (empty($logs)) {
140
+ return 0;
141
+ }
142
+
143
+ //count insert queries
144
+ foreach ($logs as $column) {
145
+ for ($j=1; $j<=$column->ratings_users; $j++) {
146
+ $i ++;
147
}
148
}
149
+ set_transient('yasr_mr_import_query_number', $i, DAY_IN_SECONDS);
150
+
151
+ return $i;
152
153
}
154
155
//Import WpPostRating Data
156
+ public function yasr_return_wppr_data () {
157
global $wpdb;
158
159
$logs = $wpdb->get_results("
172
173
if (empty($logs)) {
174
return 0;
175
}
176
+
177
+ return $logs;
178
}
179
180
//Import KK Star Rating Data
197
198
if (empty($logs)) {
199
return 0;
200
}
201
+
202
+ return $logs;
203
}
204
205
+ public function yasr_return_rmp_data() {
206
global $wpdb;
207
208
$rmp_table=$wpdb->prefix . 'rmp_analytics';
220
221
if (empty($logs)) {
222
return 0;
223
}
224
+
225
+ return $logs;
226
}
227
228
//Import Multi Rating Data
229
+ public function yasr_return_mr_data() {
230
global $wpdb;
231
232
$logs = $wpdb->get_results("
245
246
if (empty($logs)) {
247
return 0;
248
}
249
+
250
+ return $logs;
251
}
252
253
}
lib/rest/classes/YasrCustomEndpoint.php ADDED
@@ -0,0 +1,151 @@
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')) {
4
+ exit('You\'re not allowed to see this page');
5
+ } // Exit if accessed directly
6
+
7
+ class YasrCustomEndpoint extends WP_REST_Controller {
8
+
9
+ /**
10
+ * Constructor
11
+ */
12
+ public function __construct() {
13
+ add_action('rest_api_init', array( $this, 'customEndpoint'));
14
+ }
15
+
16
+
17
+ /**
18
+ * All the functions that need parameters
19
+ */
20
+ public function customEndpoint () {
21
+ /*
22
+ * Param for this route must be
23
+ * YOURSITE/wp-json/yet-another-stars-rating/v1/yasr-multiset/<ID>?post_id=<ID>
24
+ * OPTIONAL &visitor=1
25
+ *
26
+ */
27
+ $namespace = 'yet-another-stars-rating/';
28
+ $version = 'v1/';
29
+ $base = 'yasr-multiset';
30
+
31
+ register_rest_route(
32
+ $namespace . $version . $base . '/',
33
+ '(?P<set_id>\d+)',
34
+ array(
35
+ 'methods' => WP_REST_Server::READABLE,
36
+ 'callback' => array($this, 'authorMultiSet'),
37
+ 'args' => array(
38
+ 'set_id' => array(
39
+ 'required' => true,
40
+ 'sanitize_callback' => array($this, 'sanitizeInput')
41
+ ),
42
+ 'post_id' => array(
43
+ 'required' => true,
44
+ 'sanitize_callback' => array($this, 'sanitizeInput')
45
+ ),
46
+ 'visitor' => array(
47
+ 'default' => 0,
48
+ 'required' => false,
49
+ 'sanitize_callback' => array($this, 'sanitizeInput')
50
+ ),
51
+ ),
52
+ )
53
+ );
54
+
55
+ }
56
+
57
+ /**
58
+ *
59
+ * Return Author Multi Set
60
+ *
61
+ * @param WP_REST_Request $request
62
+ *
63
+ * @return WP_Error|WP_REST_Response
64
+ */
65
+ public function authorMultiSet ($request) {
66
+ /*
67
+ * Get cleaned params
68
+ */
69
+
70
+ $set_id = $request['set_id'];
71
+ $post_id = $request['post_id'];
72
+ $visitor = $request['visitor'];
73
+
74
+ $data_to_return = array(
75
+ 'set_id' => $set_id
76
+ );
77
+
78
+ $invalid_set = false;
79
+
80
+ //if $visitor === 1 then get data from yasr_visitor_multiset
81
+ if($visitor === 1) {
82
+ $data_to_return['yasr_visitor_multiset'] = YasrMultiSetData::returnVisitorMultiSetContent($post_id, $set_id);
83
+ if ($data_to_return['yasr_visitor_multiset'] === false) {
84
+ $invalid_set = true;
85
+ }
86
+ } else {
87
+ $data_to_return['yasr_multiset'] = YasrMultiSetData::returnMultisetContent($post_id, $set_id);
88
+ if ($data_to_return['yasr_multiset'] === false) {
89
+ $invalid_set = true;
90
+ }
91
+ }
92
+
93
+ if ($invalid_set === true) {
94
+ return new WP_Error(
95
+ 'invalid_multiset',
96
+ __('This Multi Set doesn\'t exists', 'yet-another-stars-rating'),
97
+ 400
98
+ );
99
+ }
100
+
101
+ $response = new WP_REST_Response($data_to_return);
102
+ $response->set_status(200);
103
+
104
+ return $response;
105
+ }
106
+
107
+ /**
108
+ * @param $param
109
+ * @param $request
110
+ * @param $key
111
+ *
112
+ * @return int|void|WP_Error
113
+ */
114
+ public function sanitizeInput ($param, $request, $key) {
115
+ if($key === 'set_id') {
116
+ return (int)$param;
117
+ }
118
+
119
+ if($key === 'post_id') {
120
+ $post_id = (int)$param;
121
+
122
+ /*if post_id is null means that is not set in the request.
123
+ * (int) will convert it to 0.
124
+ * When WordPress is installed, the first post has ID = 1
125
+ */
126
+ if ($post_id === 0) {
127
+ return new WP_Error (
128
+ 'wrong_post_id',
129
+ __('Invalid Post ID', 'yet-another-stars-rating'),
130
+ 400
131
+ );
132
+ }
133
+
134
+ //Check if exists a post with this ID
135
+ if (get_post($post_id) === null) {
136
+ return new WP_Error (
137
+ 'wrong_post_id',
138
+ __('Post ID doesn\'t exists', 'yet-another-stars-rating'),
139
+ 404
140
+ );
141
+ }
142
+ return $post_id;
143
+ }
144
+
145
+ if($key === 'visitor') {
146
+ return (int)$param;
147
+ }
148
+
149
+ return;
150
+ }
151
+ }
lib/rest/classes/YasrCustomFields.php ADDED
@@ -0,0 +1,146 @@
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')) {
4
+ exit('You\'re not allowed to see this page');
5
+ } // Exit if accessed directly
6
+
7
+ class YasrCustomFields extends WP_REST_Controller {
8
+
9
+ /**
10
+ * Constructor
11
+ */
12
+ public function __construct() {
13
+ add_action('rest_api_init', array( $this, 'customFields'));
14
+ }
15
+
16
+
17
+ /**
18
+ * Add a new response in
19
+ * YOURSITE.COM/wp-json/wp/v2/posts
20
+ */
21
+ public function customFields () {
22
+
23
+ /**
24
+ * Add <yasr-visitor-votes> in
25
+ * YOURSITE.COM/wp-json/wp/v2/posts
26
+ */
27
+ $this->visitorVotes();
28
+ $this->allItemTypes();
29
+ $this->itemTypesAdditionalFields();
30
+ }
31
+
32
+ /**
33
+ * Helper function to return visitorVotes
34
+ */
35
+ private function visitorVotes() {
36
+ $post_types = yasr_return_all_post_types();
37
+ $yasr_vv_schema = array(
38
+ 'description' => 'Yasr Visitor Votes Data',
39
+ 'type' => 'object',
40
+ 'context' => array('view', 'edit'),
41
+ // In JSON Schema you can specify object properties in the properties attribute.
42
+ 'properties' => array
43
+ (
44
+ 'sum_votes' => array(
45
+ 'type' => 'integer',
46
+ ),
47
+ 'number_of_votes' => array(
48
+ 'type' => 'integer',
49
+ ),
50
+ 'read_only' => array(
51
+ 'type' => 'boolean',
52
+ ),
53
+ ),
54
+ );
55
+
56
+ //Register Visitor Votes
57
+ register_rest_field(
58
+ $post_types,
59
+ 'yasr_visitor_votes',
60
+ array(
61
+ 'get_callback' => array($this, 'returnArrayVisitorVotes'),
62
+ 'update_callback' => null,
63
+ 'schema' => $yasr_vv_schema
64
+ )
65
+ );
66
+
67
+ }
68
+
69
+ //can't be private
70
+ protected function returnArrayVisitorVotes() {
71
+
72
+ //default values
73
+ $array_to_return = array(
74
+ 'number_of_votes' => 0,
75
+ 'sum_votes' => 0,
76
+ 'stars_attributes' => array(
77
+ 'read_only' => true,
78
+ 'span_bottom' => false
79
+ )
80
+ );
81
+
82
+ $cookie_value = YasrVisitorVotes::checkCookie();
83
+ $stars_enabled = YasrVisitorVotes::starsEnalbed($cookie_value);
84
+
85
+ //if user is enabled to rate, readonly must be false
86
+ if($stars_enabled === 'true_logged' || $stars_enabled === 'true_not_logged') {
87
+ $array_to_return['stars_attributes']['read_only'] = false;
88
+ }
89
+
90
+ $array_to_return['stars_attributes']['span_bottom'] = YasrVisitorVotes::showTextBelowStars($cookie_value);
91
+
92
+ $array_visitor_votes = YasrDatabaseRatings::getVisitorVotes();
93
+
94
+ $array_to_return['number_of_votes'] = $array_visitor_votes['number_of_votes'];
95
+ $array_to_return['sum_votes'] = $array_visitor_votes['sum_votes'];
96
+
97
+ return $array_to_return;
98
+
99
+ }
100
+
101
+ /**
102
+ * Helper function to return supported itemtype
103
+ */
104
+ private function allItemTypes() {
105
+ $post_types = yasr_return_all_post_types();
106
+ $yasr_itemtype_schema = array(
107
+ 'description' => 'Yasr Supported Item Types',
108
+ 'type' => 'object',
109
+ 'context' => array('edit'),
110
+ );
111
+
112
+ //Register Visitor Votes
113
+ register_rest_field(
114
+ $post_types,
115
+ 'yasr_all_itemtypes',
116
+ array(
117
+ 'get_callback' => function() {return json_decode(YASR_SUPPORTED_SCHEMA_TYPES); },
118
+ 'update_callback' => null,
119
+ 'schema' => $yasr_itemtype_schema
120
+ )
121
+ );
122
+ }
123
+
124
+ /**
125
+ * Helper function to return supported itemtype additional info
126
+ */
127
+ private function itemTypesAdditionalFields() {
128
+ $post_types = yasr_return_all_post_types();
129
+ $yasr__additional_itemtype_schema = array(
130
+ 'description' => 'Yasr Item Types Additional Info',
131
+ 'type' => 'object',
132
+ 'context' => array('edit'),
133
+ );
134
+
135
+ //Register Visitor Votes
136
+ register_rest_field(
137
+ $post_types,
138
+ 'yasr_all_itemtypes',
139
+ array(
140
+ 'get_callback' => function() {return json_decode(YASR_SUPPORTED_SCHEMA_TYPES_ADDITIONAL_FIELDS); },
141
+ 'update_callback' => null,
142
+ 'schema' => $yasr__additional_itemtype_schema
143
+ )
144
+ );
145
+ }
146
+ }
lib/rest/classes/YasrPostMeta.php ADDED
@@ -0,0 +1,76 @@
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')) {
4
+ exit('You\'re not allowed to see this page');
5
+ } // Exit if accessed directly
6
+
7
+ class YasrPostMeta {
8
+ /**
9
+ * Constructor
10
+ */
11
+ public function __construct() {
12
+ add_action('init', array( $this, 'postMeta' ));
13
+ }
14
+
15
+ /*
16
+ * Get Yasr Post Meta Values and insert in the rest response
17
+ * YOURSITE.COM/wp-json/wp/v2/posts?_field=meta
18
+ * or
19
+ * YOURSITE.COM/wp-json/wp/v2/posts/<POSTID>?_field=meta
20
+ *
21
+ */
22
+
23
+ public function postMeta () {
24
+ register_meta(
25
+ 'post',
26
+ 'yasr_overall_rating',
27
+ array(
28
+ 'show_in_rest' => true,
29
+ 'single' => true,
30
+ 'type' => 'number',
31
+ 'auth_callback' => function() {
32
+ return current_user_can('edit_posts');
33
+ }
34
+ )
35
+ );
36
+
37
+ register_meta(
38
+ 'post',
39
+ 'yasr_post_is_review',
40
+ array(
41
+ 'show_in_rest' => true,
42
+ 'single' => true,
43
+ 'type' => 'string',
44
+ 'auth_callback' => function() {
45
+ return current_user_can('edit_posts');
46
+ }
47
+ )
48
+ );
49
+
50
+ register_meta(
51
+ 'post',
52
+ 'yasr_auto_insert_disabled',
53
+ array(
54
+ 'show_in_rest' => true,
55
+ 'single' => true,
56
+ 'type' => 'string',
57
+ 'auth_callback' => function() {
58
+ return current_user_can('edit_posts');
59
+ }
60
+ )
61
+ );
62
+
63
+ register_meta(
64
+ 'post',
65
+ 'yasr_review_type',
66
+ array(
67
+ 'show_in_rest' => true,
68
+ 'single' => true,
69
+ 'type' => 'string',
70
+ 'auth_callback' => function() {
71
+ return current_user_can('edit_posts');
72
+ }
73
+ )
74
+ );
75
+ }
76
+ }
lib/rest/yasr-rest.php CHANGED
@@ -4,6 +4,30 @@ if (!defined('ABSPATH')) {
4
exit('You\'re not allowed to see this page');
5
} // Exit if accessed directly
6
7
//get all post meta and return it in the meta[] response
8
$yasr_post_meta = new YasrPostMeta();
9
4
exit('You\'re not allowed to see this page');
5
} // Exit if accessed directly
6
7
+ //AutoLoad Yasr Response, only when a object is created
8
+ spl_autoload_register('yasr_autoload_rest_response');
9
+
10
+ /**
11
+ * Callback function for the spl_autoload_register above.
12
+ *
13
+ * @param $class
14
+ */
15
+ function yasr_autoload_rest_response($class) {
16
+ /**
17
+ * If the class being requested does not start with 'Yasr' prefix,
18
+ * it's not in Yasr Project
19
+ */
20
+ if (0 !== strpos($class, 'Yasr')) {
21
+ return;
22
+ }
23
+ $file_name = YASR_ABSOLUTE_PATH . '/lib/rest/classes/' . $class . '.php';
24
+
25
+ // check if file exists, just to be sure
26
+ if (file_exists($file_name)) {
27
+ require($file_name);
28
+ }
29
+ }
30
+
31
//get all post meta and return it in the meta[] response
32
$yasr_post_meta = new YasrPostMeta();
33
lib/shortcodes/classes/YasrMultiSet.php ADDED
@@ -0,0 +1,164 @@
1
+ <?php
2
+ /*
3
+
4
+ Copyright 2014 Dario Curvino (email : d.curvino@tiscali.it)
5
+
6
+ This program is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 2 of the License, or
9
+ (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with this program. If not, see <http://www.gnu.org/licenses/>
18
+ */
19
+
20
+ if (!defined('ABSPATH')) {
21
+ exit('You\'re not allowed to see this page');
22
+ } // Exit if accessed directly
23
+
24
+
25
+ /**
26
+ * Class YasrMultiSet
27
+ */
28
+ class YasrMultiSet extends YasrShortcode {
29
+ /**
30
+ * @return string | bool
31
+ */
32
+ public function printMultiset () {
33
+
34
+ $this->shortcode_html = '<!-- Yasr Multi Set Shortcode-->';
35
+
36
+ $multiset_content = YasrMultiSetData::returnMultisetContent($this->post_id, $this->set_id);
37
+
38
+ if ($multiset_content === false) {
39
+ $string = __('No Set Found with this ID', 'yet-another-stars-rating');
40
+ return $this->shortcode_html . $string;
41
+ }
42
+
43
+ $this->shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
44
+ $this->shortcode_html .= '<table class="yasr_table_multi_set_shortcode">';
45
+ $this->star_readonly = 'true';
46
+
47
+ $this->printMultisetRows($multiset_content);
48
+
49
+ $this->shortcode_html .= "</table>";
50
+ $this->shortcode_html .= '<!--End Yasr Multi Set Shortcode-->';
51
+
52
+ return $this->shortcode_html;
53
+ }
54
+
55
+
56
+ /**
57
+ *
58
+ * This function insert into $this->shortcode_html the rows of both multisets (average included)
59
+ *
60
+ * @param $multiset_content
61
+ * @param bool $visitor_multiset
62
+ *
63
+ * @return void
64
+ *
65
+ */
66
+ protected function printMultisetRows($multiset_content, $visitor_multiset=false) {
67
+
68
+ $multiset_string = 'yasr-average-multiset-';
69
+ if ($visitor_multiset === true) {
70
+ $multiset_string = 'yasr-visitor-multi-set-average-';
71
+ }
72
+
73
+ foreach ($multiset_content as $set_content) {
74
+ $unique_id_identifier = 'yasr-multiset-' . str_shuffle(uniqid());
75
+
76
+ $average_rating = round($set_content['average_rating'], 1);
77
+
78
+ $html_stars = "<div class='yasr-multiset-visitors-rater'
79
+ id='$unique_id_identifier'
80
+ data-rater-postid='$this->post_id'
81
+ data-rater-setid='$this->set_id'
82
+ data-rater-set-field-id='$set_content[id]'
83
+ data-rating='$average_rating'
84
+ data-rater-readonly='$this->star_readonly'>
85
+ </div>";
86
+
87
+ $span_container_number_of_votes = '';
88
+ if ($visitor_multiset === true) {
89
+ $span_container_number_of_votes = '<span class="yasr-visitor-multiset-vote-count">'
90
+ . $set_content['number_of_votes'] .
91
+ '</span>';
92
+ }
93
+
94
+ $this->shortcode_html .= '<tr>
95
+ <td>
96
+ <span class="yasr-multi-set-name-field">' . $set_content['name'] . '</span>
97
+ </td>
98
+ <td>'
99
+ . $html_stars . $span_container_number_of_votes .
100
+ '</td>
101
+ </tr>';
102
+
103
+ } //End foreach
104
+
105
+ //If average row should be showed
106
+ if ($this->show_average_multiset() === true) {
107
+ //get the average of the multiset
108
+ $multiset_average = YasrMultiSetData::returnMultiSetAverage($this->post_id, $this->set_id, $visitor_multiset);
109
+
110
+ //print it
111
+ $this->shortcode_html .= $this->printAverageRowMultiSet($multiset_average, $multiset_string);
112
+ }
113
+
114
+ }
115
+
116
+ /**
117
+ * This function return the html code of the average multiset
118
+ *
119
+ * @since 2.1.0
120
+ *
121
+ * @param $multiset_average
122
+ * @param $multiset_string
123
+ *
124
+ * @return string
125
+ */
126
+ protected function printAverageRowMultiSet($multiset_average, $multiset_string) {
127
+ $average_txt = __("Average", "yet-another-stars-rating");
128
+ $html_average = null;
129
+
130
+ //Show average row
131
+ if ($this->show_average_multiset() === true) {
132
+ $unique_id_identifier = $multiset_string . str_shuffle(uniqid());
133
+
134
+ $html_average = "<tr>
135
+ <td colspan='2' class='yasr-multiset-average'>
136
+ <div class='yasr-multiset-average'>
137
+ <span class='yasr-multiset-average-text'>$average_txt</span>
138
+ <div class='yasr-rater-stars' id='$unique_id_identifier'
139
+ data-rating='$multiset_average' data-rater-readonly='true'
140
+ data-rater-starsize='24'></div>
141
+ </div>
142
+ </td>
143
+ </tr>";
144
+ }
145
+
146
+ return $html_average;
147
+ }
148
+
149
+ /**
150
+ * Return true or false if average should be displayed
151
+ *
152
+ * @return bool
153
+ */
154
+ public function show_average_multiset() {
155
+ if ($this->show_average === '' && YASR_MULTI_SHOW_AVERAGE !== 'no' ||
156
+ $this->show_average !== '' && $this->show_average !== 'no') {
157
+ return true;
158
+ }
159
+ else {
160
+ return false;
161
+ }
162
+ }
163
+
164
+ }
lib/shortcodes/classes/YasrOverallRating.php ADDED
@@ -0,0 +1,94 @@
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 YasrOverallRating
27
+ * Print Yasr Overall Rating
28
+ */
29
+ class YasrOverallRating extends YasrShortcode {
30
+
31
+ protected $html_stars;
32
+ protected $overall_rating;
33
+
34
+ /**
35
+ * Print the visitor votes shortcode
36
+ *
37
+ * @return string|null
38
+ */
39
+
40
+ function printOverallRating () {
41
+
42
+ $stars_size = $this->starSize();
43
+ $this->overall_rating = YasrDatabaseRatings::getOverallRating($this->post_id);
44
+
45
+ $this->shortcode_html = '<!--Yasr Overall Rating Shortcode-->';
46
+
47
+ //generate an unique id to be sure that every element has a different ID
48
+ $unique_id = str_shuffle(uniqid());
49
+ $overall_rating_html_id = 'yasr-overall-rating-rater-' . $unique_id;
50
+
51
+ $this->html_stars = "<div class='yasr-overall-rating'>
52
+ <div class='yasr-rater-stars'
53
+ id='$overall_rating_html_id'
54
+ data-rating='$this->overall_rating'
55
+ data-rater-starsize='$stars_size' >
56
+ </div>
57
+ </div>";
58
+
59
+ $this->customTextBefore();
60
+ $this->shortcode_html .= '<!--End Yasr Overall Rating Shortcode-->';
61
+
62
+ //If overall rating in loop is enabled don't use is_singular && is main_query
63
+ if (YASR_SHOW_OVERALL_IN_LOOP === 'enabled') {
64
+ return $this->shortcode_html;
65
+ } //default
66
+ else {
67
+ if (is_singular() && is_main_query()) {
68
+ return $this->shortcode_html;
69
+ }
70
+ return null;
71
+ }
72
+ }
73
+
74
+ /**
75
+ * If enabled in the settings, this function will show the custom text
76
+ * before or after the stars in yasr_visitor_votes
77
+ *
78
+ * @param void
79
+ * @return void
80
+ *
81
+ */
82
+ protected function customTextBefore() {
83
+ if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_BEFORE_OVERALL != '') {
84
+ $text_before_star = str_replace('%overall_rating%', $this->overall_rating, YASR_TEXT_BEFORE_OVERALL);
85
+ $this->shortcode_html = "<div class='yasr-container-custom-text-and-overall'>
86
+ <span id='yasr-custom-text-before-overall'>" . $text_before_star . "</span>
87
+ $this->html_stars
88
+ </div>";
89
+ } else {
90
+ $this->shortcode_html .= $this->html_stars;
91
+ }
92
+ }
93
+
94
+ }
lib/shortcodes/classes/YasrRankings.php ADDED
@@ -0,0 +1,304 @@
1
+ <?php
2
+ /*
3
+
4
+ Copyright 2014 Dario Curvino (email : d.curvino@tiscali.it)
5
+
6
+ This program is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 2 of the License, or
9
+ (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with this program. If not, see <http://www.gnu.org/licenses/>
18
+ */
19
+
20
+ if (!defined('ABSPATH')) {
21
+ exit('You\'re not allowed to see this page');
22
+ } // Exit if accessed directly
23
+
24
+
25
+ /**
26
+ * Class YasrRankings
27
+ */
28
+ class YasrRankings extends YasrShortcode {
29
+
30
+ protected $query_highest_rated_overall;
31
+ protected $query_result_most_rated_visitor;
32
+ protected $query_result_highest_rated_visitor;
33
+ protected $vv_highest_rated_table;
34
+ protected $vv_most_rated_table;
35
+
36
+ /*
37
+ *
38
+ * */
39
+ public function returnHighestRatedOverall () {
40
+ $this->shortcode_html = '<!-- Yasr Most Or Highest Rated Shortcode-->';
41
+
42
+ global $wpdb;
43
+
44
+ $this->query_highest_rated_overall = $wpdb->get_results("
45
+ SELECT pm.meta_value AS overall_rating,
46
+ pm.post_id AS post_id
47
+ FROM $wpdb->postmeta AS pm,
48
+ $wpdb->posts AS p
49
+ WHERE pm.post_id = p.ID
50
+ AND p.post_status = 'publish'
51
+ AND pm.meta_key = 'yasr_overall_rating'
52
+ ORDER BY pm.meta_value DESC,
53
+ pm.post_id
54
+ LIMIT 10"
55
+ );
56
+
57
+ $this->loopHighestRatedOverall();
58
+
59
+ $this->shortcode_html .= '<!--End Yasr Top 10 highest Rated Shortcode-->';
60
+ return $this->shortcode_html;
61
+
62
+ }
63
+
64
+ protected function loopHighestRatedOverall($text_position=false, $text=false) {
65
+ if ($this->query_highest_rated_overall) {
66
+ $this->shortcode_html .= "<table class='yasr-table-chart'>";
67
+
68
+ foreach ($this->query_highest_rated_overall as $result) {
69
+ $post_title = wp_strip_all_tags(get_the_title($result->post_id));
70
+ $link = get_permalink($result->post_id); //Get permalink from post id
71
+ $yasr_top_ten_html_id = 'yasr-highest_rated-' . str_shuffle(uniqid());
72
+
73
+ $this->returnTableRows($result->post_id,
74
+ $result->overall_rating,
75
+ null,
76
+ $post_title,
77
+ $link, $yasr_top_ten_html_id);
78
+
79
+
80
+ } //End foreach
81
+ $this->shortcode_html .= "</table>";
82
+ }
83
+ else {
84
+ _e("You don't have any votes stored", 'yet-another-stars-rating');
85
+ }
86
+
87
+ }
88
+
89
+ /**
90
+ * Create the queries for the rankings
91
+ *
92
+ * Return the full html for the shortcode
93
+ *
94
+ * @return string $this->shortcode_html;
95
+ */
96
+ public function vvReturnMostHighestRatedPost() {
97
+ $this->shortcode_html = '<!-- Yasr Most Or Highest Rated Shortcode-->';
98
+
99
+ global $wpdb;
100
+
101
+ $this->query_result_most_rated_visitor = $wpdb->get_results(
102
+ "SELECT post_id,
103
+ COUNT(post_id) AS number_of_votes,
104
+ SUM(vote) AS sum_votes
105
+ FROM " . YASR_LOG_TABLE . ",
106
+ $wpdb->posts AS p
107
+ WHERE post_id = p.ID
108
+ AND p.post_status = 'publish'
109
+ GROUP BY post_id
110
+ HAVING number_of_votes > 1
111
+ ORDER BY number_of_votes DESC,
112
+ post_id DESC
113
+ LIMIT 10"
114
+ );
115
+
116
+ //count run twice but access data only once: tested with query monitor and asked
117
+ //here http://stackoverflow.com/questions/39201235/does-count-run-twice/39201492
118
+ $this->query_result_highest_rated_visitor = $wpdb->get_results(
119
+ "SELECT post_id,
120
+ COUNT(post_id) AS number_of_votes,
121
+ (SUM(vote) / COUNT(post_id)) AS result
122
+ FROM " . YASR_LOG_TABLE . " ,
123
+ $wpdb->posts AS p
124
+ WHERE post_id = p.ID
125
+ AND p.post_status = 'publish'
126
+ GROUP BY post_id
127
+ HAVING COUNT(post_id) >= 2
128
+ ORDER BY result DESC,
129
+ number_of_votes DESC
130
+ LIMIT 10"
131
+ );
132
+
133
+ $this->vv_highest_rated_table = "<table class='yasr-table-chart' id='yasr-highest-rated-posts'>
134
+ <tr class='yasr-visitor-votes-title'>
135
+ <th>" . __('Post / Page', 'yet-another-stars-rating') . "</th>
136
+ <th>" . __('Order By', 'yet-another-stars-rating') . ":&nbsp;&nbsp;
137
+ <span id='link-yasr-most-rated-posts'>
138
+ <a href='' onclick='yasrShowMost(); return false'>"
139
+ . __("Most Rated", 'yet-another-stars-rating') .
140
+ "</a> |
141
+ <span id='yasr_multi_chart_link_to_nothing'>"
142
+ . __("Highest Rated", 'yet-another-stars-rating') .
143
+ "</span>
144
+ </th>
145
+ </tr>";
146
+
147
+ $this->vv_most_rated_table = "<table class='yasr-table-chart' id='yasr-most-rated-posts'>
148
+ <tr class='yasr-visitor-votes-title'>
149
+ <th>" . __('Post / Page', 'yet-another-stars-rating') . " </th>
150
+ <th>" . __('Order By', 'yet-another-stars-rating') . ":&nbsp;&nbsp;
151
+ <span id='yasr_multi_chart_link_to_nothing'>"
152
+ . __('Most Rated', 'yet-another-stars-rating') .
153
+ "</span> |
154
+ <span id='link-yasr-highest-rated-posts'>
155
+ <a href='' onclick='yasrShowHighest(); return false'>"
156
+ . __('Highest Rated', 'yet-another-stars-rating') .
157
+ "</a>
158
+ </span>
159
+ </th>
160
+ </tr>";
161
+
162
+ $this->vvMostRated();
163
+ $this->vvHighestRated();
164
+
165
+ $this->shortcode_html .= '<!-- End Yasr Most Or Highest Rated Shortcode-->';
166
+
167
+ wp_localize_script( 'yasrfront', "yasrMostHighestRanking", array(
168
+ 'enable' => 'yes'
169
+ )
170
+ );
171
+
172
+ return $this->shortcode_html;
173
+
174
+ }
175
+
176
+ /**
177
+ * Loop the query for the Most Rated chart
178
+ */
179
+ protected function vvMostRated() {
180
+ if ($this->query_result_most_rated_visitor) {
181
+
182
+ $this->shortcode_html .= $this->vv_most_rated_table;
183
+
184
+ foreach ($this->query_result_most_rated_visitor as $result) {
185
+ $rating = round($result->sum_votes / $result->number_of_votes, 1);
186
+ $post_title = wp_strip_all_tags(get_the_title($result->post_id));
187
+ $link = get_permalink($result->post_id); //Get permalink from post id
188
+ $yasr_top_ten_html_id = 'yasr-10-most-rated-' . str_shuffle(uniqid());
189
+
190
+ //print the rows
191
+ $this->returnTableRows($result->post_id,
192
+ $rating,
193
+ $result->number_of_votes,
194
+ $post_title,
195
+ $link,
196
+ $yasr_top_ten_html_id
197
+ );
198
+
199
+ } //End foreach
200
+ $this->shortcode_html .= "</table>" ;
201
+
202
+ } //End if $query_result_most_rated)
203
+
204
+ else {
205
+ $this->shortcode_html = __("You've not enough data",'yet-another-stars-rating') . "<br />";
206
+ }
207
+ }
208
+
</