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 | 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 +1 -0
- js/rater-js-rtl.js +6 -4
- js/rater-js.js +7 -5
- js/yasr-admin.js +1 -1
- js/yasr-front.js +86 -50
- lib/YasrRichSnippetAdditionalFields.php +7 -2
- lib/admin/editor/yasr-editor-functions.php +0 -4
- lib/admin/editor/yasr-metabox-schema.php +21 -21
- lib/admin/settings/yasr-settings-functions.php +104 -54
- lib/admin/settings/yasr-settings-migration-functions.php +90 -91
- lib/rest/classes/YasrCustomEndpoint.php +151 -0
- lib/rest/classes/YasrCustomFields.php +146 -0
- lib/rest/classes/YasrPostMeta.php +76 -0
- lib/rest/yasr-rest.php +24 -0
- lib/shortcodes/classes/YasrMultiSet.php +164 -0
- lib/shortcodes/classes/YasrOverallRating.php +94 -0
- lib/shortcodes/classes/YasrRankings.php +304 -0
- lib/shortcodes/classes/YasrShortcode.php +91 -0
- lib/shortcodes/classes/YasrVisitorMultiSet.php +181 -0
- lib/shortcodes/classes/YasrVisitorVotes.php +438 -0
- lib/shortcodes/yasr-shortcode-functions.php +327 -0
- lib/yasr-db-classes.php +9 -4
- lib/yasr-db-functions.php +1 -1
- lib/yasr-functions.php +46 -58
- readme.txt +22 -8
- yet-another-stars-rating.php +65 -60
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
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
|
|
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 =
|
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
|
189 |
-
|
190 |
-
|
191 |
-
|
|
|
|
|
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 |
-
|
185 |
-
|
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 |
-
|
193 |
-
|
194 |
-
|
|
|
|
|
|
|
195 |
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
readOnly: readonly,
|
201 |
-
element: document.getElementById(htmlId),
|
202 |
|
203 |
-
|
|
|
204 |
|
205 |
-
|
206 |
-
document.getElementById('yasr-visitor-votes-container-after-stars-' + uniqueId).innerHTML = yasrCommonData.loaderHtml;
|
207 |
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
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 |
-
|
223 |
-
this.disable();
|
224 |
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
|
|
|
|
230 |
|
231 |
-
|
|
|
232 |
|
233 |
-
|
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][
|
|
|
|
|
|
|
|
|
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(
|
29 |
|
30 |
//itemType select
|
31 |
-
$yasr_nonce_review_type = wp_nonce_field(
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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=
|
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 |
-
'
|
110 |
-
__('
|
111 |
-
'
|
112 |
'yasr_general_settings_tab',
|
113 |
'yasr_general_options_section_id',
|
114 |
$option
|
115 |
);
|
116 |
add_settings_field(
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
);
|
124 |
add_settings_field(
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
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> </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> </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> </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> </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> </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> </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 |
-
}
|
31 |
-
|
32 |
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
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 |
-
}
|
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 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
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 |
-
}
|
87 |
-
|
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 |
-
|
104 |
-
|
|
|
|
|
|
|
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 |
-
}
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
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') . ":
|
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') . ":
|
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 |
+
|
209 |
+
/**
|
210 |
+
* Loop the query for the Highest Rated chart
|
211 |
+
*/
|
212 |
+
protected function vvHighestRated () {
|
213 |
+
if ($this->query_result_highest_rated_visitor) {
|
214 |
+
|
215 |
+
$this->shortcode_html .= $this->vv_highest_rated_table;
|
216 |
+
|
217 |
+
foreach ($this->query_result_highest_rated_visitor as $result) {
|
218 |
+
$rating = round($result->result, 1);
|
219 |
+
$post_title = wp_strip_all_tags(get_the_title($result->post_id));
|
220 |
+
$link = get_permalink($result->post_id); //Get permalink from post id
|
221 |
+
$yasr_top_ten_html_id = 'yasr-10-highest-rater-' . str_shuffle(uniqid());
|
222 |
+
|
223 |
+
//print the rows
|
224 |
+
$this->returnTableRows($result->post_id,
|
225 |
+
$rating,
|
226 |
+
$result->number_of_votes,
|
227 |
+
$post_title,
|
228 |
+
$link,
|
229 |
+
$yasr_top_ten_html_id
|
230 |
+
);
|
231 |
+
|
232 |
+
} //End foreach
|
233 |
+
|
234 |
+
$this->shortcode_html .= "</table>";
|
235 |
+
|
236 |
+
} //end if $query_result
|
237 |
+
|
238 |
+
else {
|
239 |
+
$this->shortcode_html = __("You've not enought data",'yet-another-stars-rating') . "<br />";
|
240 |
+
}
|
241 |
+
}
|
242 |
+
|
243 |
+
/**
|
244 |
+
* @param $post_id
|
245 |
+
* @param $rating
|
246 |
+
* @param $number_of_votes
|
247 |
+
* @param $post_title
|
248 |
+
* @param $link
|
249 |
+
* @param $yasr_top_ten_html_id
|
250 |
+
*/
|
251 |
+
protected function returnTableRows ($post_id, $rating, $number_of_votes, $post_title, $link, $yasr_top_ten_html_id) {
|
252 |
+
$star_size = $this->starSize();
|
253 |
+
|
254 |
+
$html_stars = "<div
|
255 |
+
class='yasr-rater-stars'
|
256 |
+
id='$yasr_top_ten_html_id'
|
257 |
+
data-rater-postid='$post_id'
|
258 |
+
data-rater-starsize=$star_size
|
259 |
+
data-rating='$rating'>
|
260 |
+
</div>";
|
261 |
+
|
262 |
+
//if number of votes === null means that the caller is loopHighestRatedOverall
|
263 |
+
if ($number_of_votes === null) {
|
264 |
+
|
265 |
+
$div_html_stars=apply_filters('yasr_filter_highest_rated_stars', $html_stars, $rating);
|
266 |
+
|
267 |
+
if ($div_html_stars === $html_stars) {
|
268 |
+
$div_html_stars .= "<span class='yasr-highest-rated-text'>"
|
269 |
+
. __('Rating:', 'yet-another-stars-rating') . " $rating
|
270 |
+
</span>";
|
271 |
+
}
|
272 |
+
|
273 |
+
$this->shortcode_html .= "<tr>
|
274 |
+
<td class='yasr-top-10-overall-left'>
|
275 |
+
<a href='$link'>$post_title</a>
|
276 |
+
</td>
|
277 |
+
<td class='yasr-top-10-overall-right'>
|
278 |
+
$div_html_stars
|
279 |
+
</td>
|
280 |
+
</tr>";
|
281 |
+
|
282 |
+
}
|
283 |
+
|
284 |
+
//otherwise is vvMostRated or vvHighestRated
|
285 |
+
else {
|
286 |
+
$this->shortcode_html .= "<tr>
|
287 |
+
<td class='yasr-top-10-most-highest-left'>
|
288 |
+
<a href='$link'>$post_title</a>
|
289 |
+
</td>
|
290 |
+
<td class='yasr-top-10-most-highest-right'>
|
291 |
+
$html_stars
|
292 |
+
<br />
|
293 |
+
["
|
294 |
+
. __('Total:', 'yet-another-stars-rating') .
|
295 |
+
"$number_of_votes " .
|
296 |
+
__('Average', 'yet-another-stars-rating') .
|
297 |
+
" $rating]
|
298 |
+
</td>
|
299 |
+
</tr>";
|
300 |
+
|
301 |
+
}
|
302 |
+
} //end function returnTableRows
|
303 |
+
|
304 |
+
}
|
lib/shortcodes/classes/YasrShortcode.php
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
/**
|
27 |
+
* Class YasrShortcode
|
28 |
+
*
|
29 |
+
* @since 2.1.5
|
30 |
+
*
|
31 |
+
*/
|
32 |
+
class YasrShortcode {
|
33 |
+
public $shortcode_html;
|
34 |
+
public $post_id; //false
|
35 |
+
public $size; //large
|
36 |
+
public $readonly; //false
|
37 |
+
public $set_id; //1
|
38 |
+
public $show_average; //null
|
39 |
+
public $shorcode_name;
|
40 |
+
|
41 |
+
public function __construct($atts, $shortcode_name) {
|
42 |
+
$this->shorcode_name = $shortcode_name;
|
43 |
+
|
44 |
+
if ($atts !== false) {
|
45 |
+
$atts = shortcode_atts(
|
46 |
+
array(
|
47 |
+
'size' => 'large',
|
48 |
+
'postid' => false,
|
49 |
+
'readonly' => false,
|
50 |
+
'setid' => 1,
|
51 |
+
'show_average' => null
|
52 |
+
),
|
53 |
+
$atts,
|
54 |
+
$shortcode_name
|
55 |
+
);
|
56 |
+
|
57 |
+
if ($atts['postid'] === false) {
|
58 |
+
$this->post_id = get_the_ID();
|
59 |
+
} else {
|
60 |
+
$this->post_id = (int) $atts['postid'];
|
61 |
+
}
|
62 |
+
$this->size = sanitize_text_field($atts['size']);
|
63 |
+
$this->readonly = sanitize_text_field($atts['readonly']);
|
64 |
+
$this->set_id = (int) $atts['setid'];
|
65 |
+
$this->show_average = sanitize_text_field($atts['show_average']);
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Return the stars size according to size attribute in shortcode.
|
71 |
+
* If not used, return 32 (default value)
|
72 |
+
*
|
73 |
+
* @return int
|
74 |
+
*/
|
75 |
+
protected function starSize() {
|
76 |
+
if ($this->shorcode_name === 'yasr_top_ten_highest_rated'
|
77 |
+
|| $this->shorcode_name === 'yasr_most_or_highest_rated_posts') {
|
78 |
+
return 24;
|
79 |
+
}
|
80 |
+
|
81 |
+
$size = $this->size;
|
82 |
+
$px_size = 32; //default value
|
83 |
+
|
84 |
+
if ($size === 'small') {
|
85 |
+
$px_size = 16;
|
86 |
+
} elseif ($size === 'medium') {
|
87 |
+
$px_size = 24;
|
88 |
+
}
|
89 |
+
return $px_size;
|
90 |
+
}
|
91 |
+
}
|
lib/shortcodes/classes/YasrVisitorMultiSet.php
ADDED
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 YasrVisitorMultiSet
|
27 |
+
*/
|
28 |
+
class YasrVisitorMultiSet extends YasrMultiSet {
|
29 |
+
|
30 |
+
protected $loader_html;
|
31 |
+
protected $button_html;
|
32 |
+
protected $button_html_disabled;
|
33 |
+
protected $button;
|
34 |
+
protected $star_readonly;
|
35 |
+
protected $span_message_content;
|
36 |
+
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Print Yasr Visitor MultiSet
|
40 |
+
*
|
41 |
+
* @param void
|
42 |
+
* @return string
|
43 |
+
*/
|
44 |
+
public function printVisitorMultiSet () {
|
45 |
+
|
46 |
+
$ajax_nonce_visitor_multiset = wp_create_nonce("yasr_nonce_insert_visitor_rating_multiset");
|
47 |
+
|
48 |
+
$this->shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
|
49 |
+
|
50 |
+
$image = YASR_IMG_DIR . "/loader.gif";
|
51 |
+
$this->loader_html = "<span class='yasr-loader-multiset-visitor'
|
52 |
+
id='yasr-loader-multiset-visitor-$this->post_id-$this->set_id'>
|
53 |
+
<img src='$image' title='yasr-loader' alt='yasr-loader'>
|
54 |
+
</span>";
|
55 |
+
|
56 |
+
$this->button_html = "<input type='submit'
|
57 |
+
name='submit'
|
58 |
+
id='yasr-send-visitor-multiset-$this->post_id-$this->set_id'
|
59 |
+
class='button button-primary yasr-send-visitor-multiset'
|
60 |
+
data-postid='$this->post_id'
|
61 |
+
data-setid='$this->set_id'
|
62 |
+
value='" . __('Submit!', 'yet-another-stars-rating') . "'
|
63 |
+
/>";
|
64 |
+
|
65 |
+
$this->button_html_disabled = "<input type='submit'
|
66 |
+
disabled='disabled'
|
67 |
+
class='button button-primary'
|
68 |
+
id='yasr-send-visitor-multiset-disabled'
|
69 |
+
disabled='disabled'
|
70 |
+
value='" . __('Submit!', 'yet-another-stars-rating') . "'
|
71 |
+
/>";
|
72 |
+
|
73 |
+
//check cookie and assign default values
|
74 |
+
$this->multisetAttributes();
|
75 |
+
|
76 |
+
$set_name_content = YasrMultiSetData::returnVisitorMultiSetContent($this->post_id, $this->set_id);
|
77 |
+
|
78 |
+
if (!$set_name_content) {
|
79 |
+
$this->shortcode_html .= __('No MultiSet found with this ID', 'yet-another-stars-rating');
|
80 |
+
return $this->shortcode_html;
|
81 |
+
}
|
82 |
+
|
83 |
+
$this->shortcode_html .= "<table class='yasr_table_multi_set_shortcode'>";
|
84 |
+
|
85 |
+
$this->printMultisetRows($set_name_content, true);
|
86 |
+
|
87 |
+
//Submit row and button
|
88 |
+
$this->shortcode_html .="<tr>
|
89 |
+
<td colspan='2'>
|
90 |
+
$this->button
|
91 |
+
$this->loader_html
|
92 |
+
<span class='yasr-visitor-multiset-message'>$this->span_message_content</span>
|
93 |
+
</td>
|
94 |
+
</tr>
|
95 |
+
";
|
96 |
+
|
97 |
+
$this->shortcode_html .= "</table>";
|
98 |
+
$this->shortcode_html .= '<!-- End Yasr Multi Set Visitor Shortcode-->';
|
99 |
+
|
100 |
+
wp_localize_script(
|
101 |
+
'yasrfront',
|
102 |
+
"yasrMultiSetData",
|
103 |
+
array(
|
104 |
+
'nonceVisitor' => $ajax_nonce_visitor_multiset,
|
105 |
+
'setType' => $this->set_id
|
106 |
+
)
|
107 |
+
);
|
108 |
+
|
109 |
+
return $this->shortcode_html;
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* This function first check if a cookie is set,
|
114 |
+
* Then who can rate and set attributes to:
|
115 |
+
* $this->button
|
116 |
+
* $this->star_readonly
|
117 |
+
* $this->span_message_content
|
118 |
+
*
|
119 |
+
* @param void
|
120 |
+
* @return void
|
121 |
+
*
|
122 |
+
*/
|
123 |
+
protected function multisetAttributes() {
|
124 |
+
$yasr_cookiename = 'yasr_multi_visitor_cookie';
|
125 |
+
|
126 |
+
//Check cookie and if voting is allowed only to logged in users
|
127 |
+
if (isset($_COOKIE[$yasr_cookiename])) {
|
128 |
+
$cookie_data = stripslashes($_COOKIE[ $yasr_cookiename ]);
|
129 |
+
|
130 |
+
//By default, json_decode return an object, true to return an array
|
131 |
+
$cookie_data = json_decode($cookie_data, true);
|
132 |
+
|
133 |
+
if (is_array($cookie_data)) {
|
134 |
+
foreach ($cookie_data as $value) {
|
135 |
+
$cookie_post_id = (int)$value['post_id'];
|
136 |
+
$cookie_set_id = (int)$value['set_id'];
|
137 |
+
|
138 |
+
if ($cookie_post_id === $this->post_id && $cookie_set_id === $this->set_id) {
|
139 |
+
$this->button = "";
|
140 |
+
$this->star_readonly = 'true';
|
141 |
+
$this->span_message_content = __('Thank you for voting!', 'yet-another-stars-rating');
|
142 |
+
|
143 |
+
//Stop doing foreach, here we've found the rating for current post
|
144 |
+
break;
|
145 |
+
} else {
|
146 |
+
$this->button = $this->button_html;
|
147 |
+
$this->star_readonly = 'false';
|
148 |
+
$this->span_message_content = "";
|
149 |
+
}
|
150 |
+
}
|
151 |
+
}
|
152 |
+
} else {
|
153 |
+
//If user is not logged in
|
154 |
+
if (!is_user_logged_in()) {
|
155 |
+
if (YASR_ALLOWED_USER === 'allow_anonymous') {
|
156 |
+
$this->button = $this->button_html;
|
157 |
+
$this->star_readonly = 'false';
|
158 |
+
$this->span_message_content = "";
|
159 |
+
} elseif (YASR_ALLOWED_USER === 'logged_only') {
|
160 |
+
$this->button = $this->button_html_disabled;
|
161 |
+
$this->star_readonly = 'true';
|
162 |
+
$this->span_message_content = '<span class="yasr-visitor-votes-must-sign-in">';
|
163 |
+
|
164 |
+
if (defined('YASR_CUSTOM_TEXT_MUST_SIGN_IN') && YASR_CUSTOM_TEXT_MUST_SIGN_IN !== '') {
|
165 |
+
$this->span_message_content .= YASR_CUSTOM_TEXT_MUST_SIGN_IN;
|
166 |
+
} else {
|
167 |
+
$this->span_message_content .= __('You must sign in to vote', 'yet-another-stars-rating');
|
168 |
+
}
|
169 |
+
$this->span_message_content .= '</span>';
|
170 |
+
}
|
171 |
+
} //End if user logged in
|
172 |
+
|
173 |
+
//User is logged in
|
174 |
+
else {
|
175 |
+
$this->button = $this->button_html;
|
176 |
+
$this->star_readonly = 'false';
|
177 |
+
$this->span_message_content = "";
|
178 |
+
}
|
179 |
+
}
|
180 |
+
}
|
181 |
+
}
|
lib/shortcodes/classes/YasrVisitorVotes.php
ADDED
@@ -0,0 +1,438 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
* Class YasrVisitorVotes
|
26 |
+
* Print Yasr Visitor Votes
|
27 |
+
*/
|
28 |
+
class YasrVisitorVotes extends YasrShortcode {
|
29 |
+
|
30 |
+
protected $is_singular;
|
31 |
+
protected $unique_id;
|
32 |
+
protected $ajax_nonce_visitor;
|
33 |
+
protected $span_text_after_stars;
|
34 |
+
|
35 |
+
public function __construct($atts, $shortcode_name) {
|
36 |
+
parent::__construct($atts, $shortcode_name);
|
37 |
+
|
38 |
+
if (is_singular()) {
|
39 |
+
$this->is_singular = 'true';
|
40 |
+
} else {
|
41 |
+
$this->is_singular = 'false';
|
42 |
+
}
|
43 |
+
|
44 |
+
$this->unique_id = str_shuffle(uniqid());
|
45 |
+
$this->ajax_nonce_visitor = wp_create_nonce("yasr_nonce_insert_visitor_rating");
|
46 |
+
|
47 |
+
$this->shortcode_html = '<!--Yasr Visitor Votes Shortcode-->';
|
48 |
+
$this->shortcode_html .= "<div id='yasr_visitor_votes_$this->post_id' class='yasr-visitor-votes'>";
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
public function printVisitorVotesAjax() {
|
53 |
+
|
54 |
+
$htmlid = 'yasr-visitor-votes-rater-' . $this->unique_id ;
|
55 |
+
|
56 |
+
$this->textBeforeAfterStars(false, false);
|
57 |
+
|
58 |
+
$this->shortcode_html .= "<div id='$htmlid'
|
59 |
+
class='yasr-rater-stars-visitor-votes'
|
60 |
+
data-rater-postid='$this->post_id'
|
61 |
+
data-rater-starsize='".$this->starSize()."'
|
62 |
+
data-rater-nonce='$this->ajax_nonce_visitor'
|
63 |
+
data-issingular='$this->is_singular'
|
64 |
+
></div>";
|
65 |
+
|
66 |
+
return $this->returnYasrVisitorVotes(false);
|
67 |
+
|
68 |
+
}
|
69 |
+
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Print the visitor votes shortcode
|
73 |
+
*
|
74 |
+
* @return string|null
|
75 |
+
*/
|
76 |
+
public function printVisitorVotes() {
|
77 |
+
|
78 |
+
$htmlid = 'yasr-visitor-votes-rater-' . $this->unique_id ;
|
79 |
+
|
80 |
+
//return int
|
81 |
+
$stored_votes = YasrDatabaseRatings::getVisitorVotes($this->post_id);
|
82 |
+
|
83 |
+
$number_of_votes = $stored_votes['number_of_votes'];
|
84 |
+
if ($number_of_votes > 0) {
|
85 |
+
$average_rating = $stored_votes['sum_votes']/$number_of_votes;
|
86 |
+
} else {
|
87 |
+
$average_rating = 0;
|
88 |
+
}
|
89 |
+
|
90 |
+
$average_rating=round($average_rating, 1);
|
91 |
+
|
92 |
+
//if this come from yasr_visitor_votes_readonly...
|
93 |
+
if ($this->readonly === true || $this->readonly === "yes") {
|
94 |
+
$htmlid = 'yasr-visitor-votes-readonly-rater-'.$this->unique_id;
|
95 |
+
|
96 |
+
$this->shortcode_html = "<div class='yasr-rater-stars-visitor-votes'
|
97 |
+
id='$htmlid'
|
98 |
+
data-rating='$average_rating'
|
99 |
+
data-rater-starsize='".$this->starSize()."'
|
100 |
+
data-rater-postid='$this->post_id'
|
101 |
+
data-rater-readonly='true'>
|
102 |
+
</div>";
|
103 |
+
|
104 |
+
return $this->shortcode_html;
|
105 |
+
}
|
106 |
+
|
107 |
+
$cookie_value = self::checkCookie($this->post_id);
|
108 |
+
$stars_enabled = self::starsEnalbed($cookie_value);
|
109 |
+
|
110 |
+
if($stars_enabled === 'true_logged' || $stars_enabled === 'true_not_logged') {
|
111 |
+
$this->readonly = 'false'; //Always false if user is logged in
|
112 |
+
} else {
|
113 |
+
$this->readonly = 'true';
|
114 |
+
}
|
115 |
+
|
116 |
+
$this->textBeforeAfterStars($number_of_votes, $average_rating);
|
117 |
+
|
118 |
+
$this->shortcode_html .= "<div id='$htmlid'
|
119 |
+
class='yasr-rater-stars-visitor-votes'
|
120 |
+
data-rater-postid='$this->post_id'
|
121 |
+
data-rating='$average_rating'
|
122 |
+
data-rater-starsize='".$this->starSize()."'
|
123 |
+
data-rater-readonly='$this->readonly'
|
124 |
+
data-rater-nonce='$this->ajax_nonce_visitor'
|
125 |
+
data-issingular='$this->is_singular'>
|
126 |
+
</div>";
|
127 |
+
|
128 |
+
return $this->returnYasrVisitorVotes($cookie_value);
|
129 |
+
|
130 |
+
} //end function
|
131 |
+
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Function that checks if cookie exists and set the value
|
135 |
+
*
|
136 |
+
* @param $post_id int|bool
|
137 |
+
* @return int |bool
|
138 |
+
*/
|
139 |
+
public static function checkCookie ($post_id = false) {
|
140 |
+
//name of cookie to check
|
141 |
+
$yasr_cookiename = 'yasr_visitor_vote_cookie';
|
142 |
+
|
143 |
+
$cookie_value = false;
|
144 |
+
|
145 |
+
if($post_id === false) {
|
146 |
+
$post_id = get_the_ID();
|
147 |
+
}
|
148 |
+
|
149 |
+
if (isset($_COOKIE[$yasr_cookiename])) {
|
150 |
+
$cookie_data = stripslashes($_COOKIE[$yasr_cookiename]);
|
151 |
+
|
152 |
+
//By default, json_decode return an object, true to return an array
|
153 |
+
$cookie_data = json_decode($cookie_data, true);
|
154 |
+
|
155 |
+
if (is_array($cookie_data)) {
|
156 |
+
foreach ($cookie_data as $value) {
|
157 |
+
$cookie_post_id = (int)$value['post_id'];
|
158 |
+
if ($cookie_post_id === $post_id) {
|
159 |
+
$cookie_value = (int)$value['rating'];
|
160 |
+
//Stop doing foreach, here we've found the rating for current post
|
161 |
+
break;
|
162 |
+
}
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
//I've to check $cookie_value !== false before because
|
167 |
+
//if $cookie_value is false, $cookie_value < 1 return true (...wtf...)
|
168 |
+
if($cookie_value !== false) {
|
169 |
+
if ($cookie_value > 5) {
|
170 |
+
$cookie_value = 5;
|
171 |
+
} elseif ($cookie_value < 1) {
|
172 |
+
$cookie_value = 1;
|
173 |
+
}
|
174 |
+
}
|
175 |
+
//return int
|
176 |
+
return $cookie_value;
|
177 |
+
}
|
178 |
+
|
179 |
+
//if cookie is not set (return false)
|
180 |
+
return $cookie_value;
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Enable or disable stars
|
185 |
+
*
|
186 |
+
* @param $cookie_value
|
187 |
+
*
|
188 |
+
* @return string|bool;
|
189 |
+
*/
|
190 |
+
public static function starsEnalbed ($cookie_value) {
|
191 |
+
|
192 |
+
$is_user_logged_in = is_user_logged_in();
|
193 |
+
|
194 |
+
//Logged in user is always able to vote
|
195 |
+
if ($is_user_logged_in === true) {
|
196 |
+
return 'true_logged';
|
197 |
+
}
|
198 |
+
|
199 |
+
//If only logged in users can vote
|
200 |
+
if (YASR_ALLOWED_USER === 'logged_only') {
|
201 |
+
//IF user is not logged in
|
202 |
+
if ($is_user_logged_in === false) {
|
203 |
+
return 'false_not_logged';
|
204 |
+
}
|
205 |
+
}
|
206 |
+
|
207 |
+
//if anonymous are allowed to vote
|
208 |
+
if (YASR_ALLOWED_USER === 'allow_anonymous') {
|
209 |
+
//I've to check if is user is not logged in
|
210 |
+
if ($is_user_logged_in === false) {
|
211 |
+
//if cookie !== false means that exists, and user can't vote
|
212 |
+
if ($cookie_value !== false) {
|
213 |
+
return 'false_already_voted';
|
214 |
+
}
|
215 |
+
return 'true_not_logged';
|
216 |
+
}
|
217 |
+
} //end if YASR_ALLOWED_USER === 'allow_anonymous'
|
218 |
+
|
219 |
+
//this should never happen
|
220 |
+
return false;
|
221 |
+
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* This function show default (or custom) text depending if rating is allowed or not
|
226 |
+
*
|
227 |
+
* @param void
|
228 |
+
* @return int|bool|void
|
229 |
+
*/
|
230 |
+
public static function showTextBelowStars ($cookie_value) {
|
231 |
+
|
232 |
+
$stars_enabled = self::starsEnalbed($cookie_value);
|
233 |
+
$span_bottom_line = false;
|
234 |
+
$span_bottom_line_content = false;
|
235 |
+
|
236 |
+
//If user is logged
|
237 |
+
if ($stars_enabled === 'true_logged') {
|
238 |
+
//Check if a logged in user has already rated for this post
|
239 |
+
$vote_if_user_already_rated = YasrDatabaseRatings::visitorVotesHasUserVoted();
|
240 |
+
|
241 |
+
//If user has already rated
|
242 |
+
if ($vote_if_user_already_rated) {
|
243 |
+
$span_bottom_line_content = "<span class='yasr-already-voted-text' >"
|
244 |
+
.__("You've already voted this article with", 'yet-another-stars-rating') .
|
245 |
+
" $vote_if_user_already_rated" .
|
246 |
+
"</span>";
|
247 |
+
}
|
248 |
+
} //true_logged
|
249 |
+
|
250 |
+
elseif ($stars_enabled === 'false_already_voted') {
|
251 |
+
$span_bottom_line_content = "<span class='yasr-already-voted-text'>";
|
252 |
+
if (YASR_TEXT_BEFORE_STARS === 1 && YASR_CUSTOM_TEXT_USER_VOTED != '') {
|
253 |
+
$span_bottom_line_content .= YASR_CUSTOM_TEXT_USER_VOTED;
|
254 |
+
} else {
|
255 |
+
$span_bottom_line_content .=
|
256 |
+
__('You\'ve already voted this article with', 'yet-another-stars-rating') . ' ' . $cookie_value;
|
257 |
+
}
|
258 |
+
$span_bottom_line_content .= '</span>';
|
259 |
+
}
|
260 |
+
|
261 |
+
//If only logged in users can vote
|
262 |
+
elseif ($stars_enabled === 'false_not_logged') {
|
263 |
+
$span_bottom_line_content = "<span class='yasr-visitor-votes-must-sign-in'>";
|
264 |
+
//if custom text is defined
|
265 |
+
if (defined('YASR_CUSTOM_TEXT_MUST_SIGN_IN') && YASR_CUSTOM_TEXT_MUST_SIGN_IN !== '') {
|
266 |
+
$span_bottom_line_content .= YASR_CUSTOM_TEXT_MUST_SIGN_IN;
|
267 |
+
} else {
|
268 |
+
$span_bottom_line_content .= __('You must sign in to vote', 'yet-another-stars-rating');
|
269 |
+
}
|
270 |
+
$span_bottom_line_content .= '</span>';
|
271 |
+
}
|
272 |
+
|
273 |
+
if($span_bottom_line_content !== false) {
|
274 |
+
$span_bottom_line = "<span class='yasr-small-block-bold'>";
|
275 |
+
//remove \n in the string and use trim
|
276 |
+
$span_bottom_line .= $span_bottom_line_content;
|
277 |
+
$span_bottom_line .= '</span>';
|
278 |
+
}
|
279 |
+
|
280 |
+
return $span_bottom_line;
|
281 |
+
}
|
282 |
+
|
283 |
+
/**
|
284 |
+
* If enabled in the settings, this function will show the custom text
|
285 |
+
* before or after the stars in yasr_visitor_votes
|
286 |
+
* Otherwise, shows default text
|
287 |
+
*
|
288 |
+
* Set $number_of_votes and $average_rating to false if comes from ajax
|
289 |
+
*
|
290 |
+
* @param $number_of_votes bool | int
|
291 |
+
* @param $average_rating bool | int | float
|
292 |
+
* @return void
|
293 |
+
*/
|
294 |
+
protected function textBeforeAfterStars ($number_of_votes, $average_rating) {
|
295 |
+
|
296 |
+
//if is not int, and is not false, set to 0
|
297 |
+
if(!is_int($number_of_votes) && $number_of_votes !== false) {
|
298 |
+
$number_of_votes = 0;
|
299 |
+
}
|
300 |
+
|
301 |
+
//if is not int, AND is not float, AND is not FALSE, set to 0
|
302 |
+
if(!is_int($average_rating) && !is_float($average_rating) && $average_rating !== false) {
|
303 |
+
$average_rating = 0;
|
304 |
+
}
|
305 |
+
|
306 |
+
$this->span_text_after_stars = "<span class='yasr-total-average-container'
|
307 |
+
id='yasr-total-average-text-". $this->unique_id ."'>";
|
308 |
+
|
309 |
+
$number_of_votes_container = '<span id="yasr-vv-votes-number-container-'. $this->unique_id .'">';
|
310 |
+
$average_rating_container = '<span id="yasr-vv-average-container-'. $this->unique_id .'">';
|
311 |
+
$closing_span = '</span>';
|
312 |
+
|
313 |
+
if (YASR_TEXT_BEFORE_STARS === 1 && YASR_TEXT_BEFORE_VISITOR_RATING != '') {
|
314 |
+
$text_before_star = str_replace(
|
315 |
+
'%total_count%',
|
316 |
+
$number_of_votes_container.$number_of_votes.$closing_span,
|
317 |
+
YASR_TEXT_BEFORE_VISITOR_RATING
|
318 |
+
);
|
319 |
+
|
320 |
+
$text_before_star = str_replace(
|
321 |
+
'%average%',
|
322 |
+
$average_rating_container.$average_rating.$closing_span,
|
323 |
+
$text_before_star
|
324 |
+
);
|
325 |
+
|
326 |
+
$this->shortcode_html .= "<div class='yasr-container-custom-text-and-visitor-rating'>
|
327 |
+
<span id='yasr-custom-text-before-visitor-rating'>"
|
328 |
+
. $text_before_star .
|
329 |
+
"</span>
|
330 |
+
</div>";
|
331 |
+
}
|
332 |
+
|
333 |
+
if (YASR_TEXT_BEFORE_STARS === 1 && YASR_TEXT_AFTER_VISITOR_RATING != '') {
|
334 |
+
$text_after_star = str_replace(
|
335 |
+
'%total_count%',
|
336 |
+
$number_of_votes_container.$number_of_votes. $closing_span,
|
337 |
+
YASR_TEXT_AFTER_VISITOR_RATING
|
338 |
+
);
|
339 |
+
|
340 |
+
$text_after_star = str_replace(
|
341 |
+
'%average%',
|
342 |
+
$average_rating_container.$average_rating.$closing_span,
|
343 |
+
$text_after_star
|
344 |
+
);
|
345 |
+
$this->span_text_after_stars .= $text_after_star;
|
346 |
+
}
|
347 |
+
|
348 |
+
//If no customization, default value that has only span after
|
349 |
+
else {
|
350 |
+
$this->span_text_after_stars .= '['
|
351 |
+
. __('Total:', 'yet-another-stars-rating')
|
352 |
+
. ' '
|
353 |
+
. $number_of_votes_container
|
354 |
+
. $number_of_votes
|
355 |
+
. $closing_span
|
356 |
+
. ' '
|
357 |
+
. __('Average:', 'yet-another-stars-rating')
|
358 |
+
. ' '
|
359 |
+
. $average_rating_container
|
360 |
+
. $average_rating
|
361 |
+
. $closing_span
|
362 |
+
. '/5]';
|
363 |
+
}
|
364 |
+
|
365 |
+
$this->span_text_after_stars .= '</span>';
|
366 |
+
|
367 |
+
return;
|
368 |
+
}
|
369 |
+
|
370 |
+
/**
|
371 |
+
* This function will return the html code for the dashicons
|
372 |
+
*
|
373 |
+
* @param void
|
374 |
+
*
|
375 |
+
* @return string
|
376 |
+
*/
|
377 |
+
protected function visitorStats () {
|
378 |
+
if (YASR_VISITORS_STATS === 'yes') {
|
379 |
+
global $yasr_plugin_imported;
|
380 |
+
|
381 |
+
//default
|
382 |
+
$span_dashicon = "<span class='dashicons dashicons-chart-bar yasr-dashicons-visitor-stats'
|
383 |
+
data-postid='$this->post_id' id='yasr-total-average-dashicon-$this->post_id'></span>";
|
384 |
+
|
385 |
+
if (is_array($yasr_plugin_imported)) {
|
386 |
+
$plugin_import_date = null; //avoid undefined
|
387 |
+
if (array_key_exists('wppr', $yasr_plugin_imported)) {
|
388 |
+
$plugin_import_date = $yasr_plugin_imported['wppr']['date'];
|
389 |
+
}
|
390 |
+
|
391 |
+
if (array_key_exists('kksr', $yasr_plugin_imported)) {
|
392 |
+
$plugin_import_date = $yasr_plugin_imported['kksr']['date'];
|
393 |
+
}
|
394 |
+
|
395 |
+
if (array_key_exists('mr', $yasr_plugin_imported)) {
|
396 |
+
$plugin_import_date = $yasr_plugin_imported['mr']['date'];
|
397 |
+
}
|
398 |
+
|
399 |
+
//remove hour from date
|
400 |
+
$plugin_import_date=strtok($plugin_import_date,' ');
|
401 |
+
|
402 |
+
$post_date = get_the_date('Y-m-d', $this->post_id);
|
403 |
+
|
404 |
+
//if one of these plugin has been imported and post is older then import, hide stats
|
405 |
+
if ($post_date < $plugin_import_date) {
|
406 |
+
$span_dashicon = "";
|
407 |
+
}
|
408 |
+
} //End if $yasr_plugin_imported
|
409 |
+
} else {
|
410 |
+
//Yasr_visitor_stats are disabled
|
411 |
+
$span_dashicon = "";
|
412 |
+
}
|
413 |
+
return $span_dashicon;
|
414 |
+
}
|
415 |
+
|
416 |
+
/**
|
417 |
+
* Return Yasr Visitor Votes
|
418 |
+
*
|
419 |
+
* @param $cookie_value int|bool
|
420 |
+
* @return string
|
421 |
+
*/
|
422 |
+
protected function returnYasrVisitorVotes ($cookie_value) {
|
423 |
+
$span_container_after_stars = "<span id='yasr-visitor-votes-container-after-stars-$this->unique_id'
|
424 |
+
class='yasr-visitor-votes-after-stars-class'>";
|
425 |
+
|
426 |
+
$this->shortcode_html .= $span_container_after_stars;
|
427 |
+
$this->shortcode_html .= $this->visitorStats();
|
428 |
+
$this->shortcode_html .= $this->span_text_after_stars;
|
429 |
+
if($cookie_value !== false) {
|
430 |
+
$this->shortcode_html .= self::showTextBelowStars($cookie_value);
|
431 |
+
}
|
432 |
+
$this->shortcode_html .= '</span>'; //Close yasr-visitor-votes-after-stars and yasr_visitor_votes
|
433 |
+
$this->shortcode_html .= '</div>'; //close all
|
434 |
+
$this->shortcode_html .= '<!--End Yasr Visitor Votes Shortcode-->';
|
435 |
+
|
436 |
+
return $this->shortcode_html;
|
437 |
+
}
|
438 |
+
}
|
lib/shortcodes/yasr-shortcode-functions.php
ADDED
@@ -0,0 +1,327 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
* Callback function for the spl_autoload_register above.
|
27 |
+
*
|
28 |
+
* @param $class
|
29 |
+
*/
|
30 |
+
function yasr_autoload_shortcodes($class) {
|
31 |
+
/**
|
32 |
+
* If the class being requested does not start with 'Yasr' prefix,
|
33 |
+
* it's not in Yasr Project
|
34 |
+
*/
|
35 |
+
if (0 !== strpos($class, 'Yasr')) {
|
36 |
+
return;
|
37 |
+
}
|
38 |
+
$file_name = YASR_ABSOLUTE_PATH . '/lib/shortcodes/classes/' . $class . '.php';
|
39 |
+
|
40 |
+
// check if file exists, just to be sure
|
41 |
+
if (file_exists($file_name)) {
|
42 |
+
require($file_name);
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
//AutoLoad YAsr Shortcode Classes, only when a object is created
|
47 |
+
spl_autoload_register('yasr_autoload_shortcodes');
|
48 |
+
|
49 |
+
|
50 |
+
/****** Add shortcode for overall rating ******/
|
51 |
+
add_shortcode('yasr_overall_rating', 'shortcode_overall_rating_callback');
|
52 |
+
|
53 |
+
/**
|
54 |
+
* @param $atts
|
55 |
+
*
|
56 |
+
* @return string|void|null
|
57 |
+
*/
|
58 |
+
function shortcode_overall_rating_callback ($atts) {
|
59 |
+
//do not run in admin (problem with tinymce)
|
60 |
+
if(is_admin()) {
|
61 |
+
return;
|
62 |
+
}
|
63 |
+
|
64 |
+
if (YASR_SHOW_OVERALL_IN_LOOP === 'disabled' && !is_singular() && is_main_query()) {
|
65 |
+
return;
|
66 |
+
}
|
67 |
+
|
68 |
+
$shortcode_name = 'yasr_overall_rating';
|
69 |
+
$overall_rating = new YasrOverallRating($atts, $shortcode_name);
|
70 |
+
|
71 |
+
return $overall_rating->printOverallRating();
|
72 |
+
|
73 |
+
} //end function
|
74 |
+
|
75 |
+
|
76 |
+
/****** Add shortcode for user vote ******/
|
77 |
+
|
78 |
+
add_shortcode('yasr_visitor_votes', 'shortcode_visitor_votes_callback');
|
79 |
+
|
80 |
+
/**
|
81 |
+
* @param $atts
|
82 |
+
*
|
83 |
+
* @return string|void|null
|
84 |
+
*/
|
85 |
+
function shortcode_visitor_votes_callback($atts) {
|
86 |
+
//do not run in admin (problem with tinymce)
|
87 |
+
if(is_admin()) {
|
88 |
+
return;
|
89 |
+
}
|
90 |
+
|
91 |
+
if (YASR_SHOW_VISITOR_VOTES_IN_LOOP === 'disabled' && !is_singular() && is_main_query()) {
|
92 |
+
return;
|
93 |
+
}
|
94 |
+
|
95 |
+
$shortcode_name = 'yasr_visitor_votes';
|
96 |
+
$visitor_votes = new YasrVisitorVotes($atts, $shortcode_name);
|
97 |
+
|
98 |
+
if(YASR_ENABLE_AJAX === 'yes') {
|
99 |
+
return $visitor_votes->printVisitorVotesAjax();
|
100 |
+
}
|
101 |
+
return $visitor_votes->printVisitorVotes();
|
102 |
+
|
103 |
+
} //End function shortcode_visitor_votes_callback
|
104 |
+
|
105 |
+
/****** Add shortcode for multiple set ******/
|
106 |
+
|
107 |
+
add_shortcode ('yasr_multiset', 'yasr_multiset_callback');
|
108 |
+
|
109 |
+
/**
|
110 |
+
* @param $atts
|
111 |
+
*
|
112 |
+
* @return string|void|null
|
113 |
+
*/
|
114 |
+
function yasr_multiset_callback($atts) {
|
115 |
+
//do not run in admin (problem with tinymce)
|
116 |
+
if(is_admin()) {
|
117 |
+
return;
|
118 |
+
}
|
119 |
+
|
120 |
+
$shortcode_name = 'yasr_multiset';
|
121 |
+
$multiset = new YasrMultiSet($atts, $shortcode_name);
|
122 |
+
|
123 |
+
return $multiset->printMultiset();
|
124 |
+
}
|
125 |
+
|
126 |
+
/****** Add shortcode for multiset writable by users ******/
|
127 |
+
|
128 |
+
add_shortcode ('yasr_visitor_multiset', 'yasr_visitor_multiset_callback');
|
129 |
+
|
130 |
+
/**
|
131 |
+
* @param $atts
|
132 |
+
*
|
133 |
+
* @return string|void|null
|
134 |
+
*/
|
135 |
+
function yasr_visitor_multiset_callback($atts) {
|
136 |
+
//do not run in admin (problem with tinymce)
|
137 |
+
if(is_admin()) {
|
138 |
+
return;
|
139 |
+
}
|
140 |
+
|
141 |
+
$shortcode_name = 'yasr_visitor_multiset';
|
142 |
+
$multiset = new YasrVisitorMultiSet($atts, $shortcode_name);
|
143 |
+
|
144 |
+
return $multiset->printVisitorMultiSet();
|
145 |
+
}
|
146 |
+
|
147 |
+
|
148 |
+
/****** Add top 10 highest rated post *****/
|
149 |
+
|
150 |
+
add_shortcode ('yasr_top_ten_highest_rated', 'yasr_top_ten_highest_rated_callback');
|
151 |
+
|
152 |
+
/**
|
153 |
+
* @param $atts
|
154 |
+
*
|
155 |
+
* @return string|void|null
|
156 |
+
*/
|
157 |
+
function yasr_top_ten_highest_rated_callback() {
|
158 |
+
//do not run in admin (problem with tinymce)
|
159 |
+
if(is_admin()) {
|
160 |
+
return;
|
161 |
+
}
|
162 |
+
|
163 |
+
$top_ten_highest_obj = new YasrRankings(false, 'yasr_top_ten_highest_rated');
|
164 |
+
|
165 |
+
return $top_ten_highest_obj->returnHighestRatedOverall();
|
166 |
+
} //End function
|
167 |
+
|
168 |
+
|
169 |
+
/****** Add top 10 most rated / highest rated post *****/
|
170 |
+
|
171 |
+
add_shortcode ('yasr_most_or_highest_rated_posts', 'yasr_most_or_highest_rated_posts_callback');
|
172 |
+
|
173 |
+
/**
|
174 |
+
*
|
175 |
+
* @return string|void|null
|
176 |
+
*/
|
177 |
+
function yasr_most_or_highest_rated_posts_callback () {
|
178 |
+
//do not run in admin (problem with tinymce)
|
179 |
+
if(is_admin()) {
|
180 |
+
return;
|
181 |
+
}
|
182 |
+
|
183 |
+
$most_highest_obj = new YasrRankings(false, 'yasr_most_or_highest_rated_posts');
|
184 |
+
|
185 |
+
return $most_highest_obj->vvReturnMostHighestRatedPost();
|
186 |
+
} //End function
|
187 |
+
|
188 |
+
|
189 |
+
/****** Add top 5 most active reviewer ******/
|
190 |
+
|
191 |
+
add_shortcode ('yasr_top_5_reviewers', 'yasr_top_5_reviewers_callback');
|
192 |
+
|
193 |
+
/**
|
194 |
+
* @return string|void
|
195 |
+
*/
|
196 |
+
function yasr_top_5_reviewers_callback () {
|
197 |
+
//do not run in admin (problem with tinymce)
|
198 |
+
if(is_admin()) {
|
199 |
+
return;
|
200 |
+
}
|
201 |
+
|
202 |
+
global $wpdb;
|
203 |
+
|
204 |
+
$query_result = $wpdb->get_results("SELECT COUNT( pm.post_id ) AS total_count, p.post_author AS reviewer
|
205 |
+
FROM $wpdb->posts AS p, $wpdb->postmeta AS pm
|
206 |
+
WHERE pm.post_id = p.ID
|
207 |
+
AND pm.meta_key = 'yasr_overall_rating'
|
208 |
+
AND p.post_status = 'publish'
|
209 |
+
GROUP BY reviewer
|
210 |
+
ORDER BY (total_count) DESC
|
211 |
+
LIMIT 5");
|
212 |
+
|
213 |
+
|
214 |
+
if ($query_result) {
|
215 |
+
|
216 |
+
$shortcode_html = '
|
217 |
+
<!-- Yasr Top 5 Reviewers Shortcode-->
|
218 |
+
';
|
219 |
+
|
220 |
+
$shortcode_html .= "
|
221 |
+
<table class=\"yasr-table-chart\">
|
222 |
+
<tr>
|
223 |
+
<th>Author</th>
|
224 |
+
<th>Reviews</th>
|
225 |
+
</tr>
|
226 |
+
";
|
227 |
+
|
228 |
+
foreach ($query_result as $result) {
|
229 |
+
|
230 |
+
$user_data = get_userdata($result->reviewer);
|
231 |
+
|
232 |
+
if ($user_data) {
|
233 |
+
$user_profile = get_author_posts_url($result->reviewer);
|
234 |
+
}
|
235 |
+
|
236 |
+
else {
|
237 |
+
$user_profile = '#';
|
238 |
+
$user_data = new stdClass;
|
239 |
+
$user_data->user_login = 'Anonymous';
|
240 |
+
}
|
241 |
+
|
242 |
+
|
243 |
+
$shortcode_html .= "<tr>
|
244 |
+
<td><a href=\"$user_profile\">$user_data->user_login</a></td>
|
245 |
+
<td>$result->total_count</td>
|
246 |
+
</tr>";
|
247 |
+
|
248 |
+
}
|
249 |
+
|
250 |
+
$shortcode_html .= "</table>";
|
251 |
+
|
252 |
+
$shortcode_html .= '
|
253 |
+
<!-- End Yasr Top 5 Reviewers Shortcode-->
|
254 |
+
';
|
255 |
+
|
256 |
+
return $shortcode_html;
|
257 |
+
|
258 |
+
}
|
259 |
+
|
260 |
+
_e('Problem while retrieving the top 5 most active reviewers. Did you publish any review?');
|
261 |
+
|
262 |
+
} //End top 5 reviewers function
|
263 |
+
|
264 |
+
|
265 |
+
/****** Add top 10 most active user *****/
|
266 |
+
|
267 |
+
add_shortcode ('yasr_top_ten_active_users', 'yasr_top_ten_active_users_callback');
|
268 |
+
|
269 |
+
/**
|
270 |
+
* @return string|void
|
271 |
+
*/
|
272 |
+
function yasr_top_ten_active_users_callback () {
|
273 |
+
//do not run in admin (problem with tinymce)
|
274 |
+
if(is_admin()) {
|
275 |
+
return;
|
276 |
+
}
|
277 |
+
|
278 |
+
global $wpdb;
|
279 |
+
|
280 |
+
$query_result = $wpdb->get_results("SELECT COUNT( user_id ) as total_count, user_id as user
|
281 |
+
FROM " . YASR_LOG_TABLE . ", $wpdb->posts AS p
|
282 |
+
WHERE post_id = p.ID
|
283 |
+
AND p.post_status = 'publish'
|
284 |
+
GROUP BY user_id
|
285 |
+
ORDER BY ( total_count ) DESC
|
286 |
+
LIMIT 10");
|
287 |
+
|
288 |
+
if ($query_result) {
|
289 |
+
$shortcode_html = '<!-- Yasr Top 10 Active Users Shortcode-->';
|
290 |
+
|
291 |
+
$shortcode_html .= "
|
292 |
+
<table class=\"yasr-table-chart\">
|
293 |
+
<tr>
|
294 |
+
<th>UserName</th>
|
295 |
+
<th>Number of votes</th>
|
296 |
+
</tr>
|
297 |
+
";
|
298 |
+
|
299 |
+
foreach ($query_result as $result) {
|
300 |
+
$user_data = get_userdata($result->user);
|
301 |
+
|
302 |
+
if ($user_data) {
|
303 |
+
$user_profile = get_author_posts_url($result->user);
|
304 |
+
} else {
|
305 |
+
$user_profile = '#';
|
306 |
+
$user_data = new stdClass;
|
307 |
+
$user_data->user_login = 'Anonymous';
|
308 |
+
}
|
309 |
+
|
310 |
+
$shortcode_html .= "<tr>
|
311 |
+
<td><a href=\"$user_profile\">$user_data->user_login</a></td>
|
312 |
+
<td>$result->total_count</td>
|
313 |
+
</tr>";
|
314 |
+
|
315 |
+
}
|
316 |
+
|
317 |
+
$shortcode_html .= "</table>";
|
318 |
+
$shortcode_html .= '<!--End Yasr Top 10 Active Users Shortcode-->';
|
319 |
+
|
320 |
+
return $shortcode_html;
|
321 |
+
}
|
322 |
+
|
323 |
+
_e("Problem while retrieving the top 10 active users chart. Are you sure you have votes to show?");
|
324 |
+
|
325 |
+
} //End function
|
326 |
+
|
327 |
+
|
lib/yasr-db-classes.php
CHANGED
@@ -25,7 +25,7 @@ if (!defined('ABSPATH')) {
|
|
25 |
class YasrDatabaseRatings {
|
26 |
|
27 |
/**
|
28 |
-
* @param $post_id
|
29 |
*
|
30 |
* @return mixed|null
|
31 |
*/
|
@@ -37,9 +37,13 @@ class YasrDatabaseRatings {
|
|
37 |
}
|
38 |
|
39 |
$overall_rating = get_post_meta($post_id, 'yasr_overall_rating', true);
|
40 |
-
|
|
|
41 |
$overall_rating = 0;
|
42 |
}
|
|
|
|
|
|
|
43 |
return $overall_rating;
|
44 |
}
|
45 |
|
@@ -109,6 +113,8 @@ class YasrDatabaseRatings {
|
|
109 |
|
110 |
if ($rating === null) {
|
111 |
$rating = false;
|
|
|
|
|
112 |
}
|
113 |
return $rating;
|
114 |
}
|
@@ -289,9 +295,8 @@ class YasrMultiSetData {
|
|
289 |
|
290 |
if (!empty($result)) {
|
291 |
return $result;
|
292 |
-
} else {
|
293 |
-
return false;
|
294 |
}
|
|
|
295 |
}
|
296 |
|
297 |
|
25 |
class YasrDatabaseRatings {
|
26 |
|
27 |
/**
|
28 |
+
* @param $post_id void|bool|int
|
29 |
*
|
30 |
* @return mixed|null
|
31 |
*/
|
37 |
}
|
38 |
|
39 |
$overall_rating = get_post_meta($post_id, 'yasr_overall_rating', true);
|
40 |
+
|
41 |
+
if (!$overall_rating || $overall_rating < 0) {
|
42 |
$overall_rating = 0;
|
43 |
}
|
44 |
+
if($overall_rating > 5) {
|
45 |
+
$overall_rating = 5;
|
46 |
+
}
|
47 |
return $overall_rating;
|
48 |
}
|
49 |
|
113 |
|
114 |
if ($rating === null) {
|
115 |
$rating = false;
|
116 |
+
} else {
|
117 |
+
$rating = (int)$rating;
|
118 |
}
|
119 |
return $rating;
|
120 |
}
|
295 |
|
296 |
if (!empty($result)) {
|
297 |
return $result;
|
|
|
|
|
298 |
}
|
299 |
+
return false;
|
300 |
}
|
301 |
|
302 |
|
lib/yasr-db-functions.php
CHANGED
@@ -67,8 +67,8 @@ function yasr_on_activation_install($network_wide) {
|
|
67 |
$option['blogposting_organization_name'] = get_bloginfo('name');
|
68 |
$option['blogposting_organization_logo'] = get_site_icon_url();
|
69 |
$option['allowed_user'] = 'allow_anonymous';
|
70 |
-
$option['metabox_overall_rating'] = 'stars'; //This is not in settings page but in overall rating metabox
|
71 |
$option['visitors_stats'] = 'yes';
|
|
|
72 |
|
73 |
add_option("yasr_general_options", $option); //Write here the default value if there is not option
|
74 |
|
67 |
$option['blogposting_organization_name'] = get_bloginfo('name');
|
68 |
$option['blogposting_organization_logo'] = get_site_icon_url();
|
69 |
$option['allowed_user'] = 'allow_anonymous';
|
|
|
70 |
$option['visitors_stats'] = 'yes';
|
71 |
+
$option['enable_ajax'] = 'no';
|
72 |
|
73 |
add_option("yasr_general_options", $option); //Write here the default value if there is not option
|
74 |
|
lib/yasr-functions.php
CHANGED
@@ -102,17 +102,13 @@ function yasr_add_scripts() {
|
|
102 |
' <img src=' . YASR_IMG_DIR . 'loader.gif title="yasr-loader" alt="yasr-loader">
|
103 |
</div>';
|
104 |
|
105 |
-
$tooltip_values = __("bad, poor, ok, good, super", 'yet-another-stars-rating');
|
106 |
-
$tooltip_values_exploded = explode(", ", $tooltip_values);
|
107 |
-
|
108 |
wp_localize_script('yasrfront', 'yasrCommonData',
|
109 |
array(
|
110 |
-
'
|
111 |
'ajaxurl' => admin_url('admin-ajax.php'),
|
112 |
-
'loggedUser' => is_user_logged_in(),
|
113 |
'visitorStatsEnabled' => YASR_VISITORS_STATS,
|
114 |
-
'tooltipValues' => $tooltip_values_exploded,
|
115 |
'loaderHtml' => $yasr_visitor_votes_loader,
|
|
|
116 |
)
|
117 |
);
|
118 |
|
@@ -163,7 +159,6 @@ function yasr_add_admin_scripts($hook) {
|
|
163 |
|
164 |
}
|
165 |
|
166 |
-
|
167 |
}
|
168 |
|
169 |
/*** Css rules for stars set, from version 1.2.7
|
@@ -430,22 +425,15 @@ function yasr_add_schema($content) {
|
|
430 |
}
|
431 |
}
|
432 |
|
433 |
-
if (!is_singular() && is_main_query() || is_404() || did_action('get_footer')) {
|
434 |
-
return $content;
|
435 |
-
}
|
436 |
-
|
437 |
-
if (!has_shortcode($content, 'yasr_visitor_votes') && !has_shortcode($content, 'yasr_overall_rating')) {
|
438 |
return $content;
|
439 |
}
|
440 |
|
441 |
$overall_rating = YasrDatabaseRatings::getOverallRating();
|
442 |
$visitor_votes = YasrDatabaseRatings::getVisitorVotes(false);
|
443 |
|
444 |
-
|
445 |
-
|
446 |
-
if (!$visitor_votes['number_of_votes'] || !$visitor_votes['sum_votes']) {
|
447 |
-
$visitor_votes['number_of_votes'] = 0;
|
448 |
-
$visitor_votes['sum_votes'] = 0;
|
449 |
}
|
450 |
|
451 |
//can't be between 0.1 and 1
|
@@ -453,6 +441,8 @@ function yasr_add_schema($content) {
|
|
453 |
$overall_rating = 1;
|
454 |
}
|
455 |
|
|
|
|
|
456 |
$script_type = '<script type="application/ld+json">';
|
457 |
$end_script_type = '</script>';
|
458 |
|
@@ -466,7 +456,7 @@ function yasr_add_schema($content) {
|
|
466 |
return $content . $script_type . $filtered_schema . $end_script_type;
|
467 |
}
|
468 |
|
469 |
-
$rich_snippet[
|
470 |
|
471 |
$author = get_the_author();
|
472 |
$review_name = wp_strip_all_tags(get_the_title());
|
@@ -499,60 +489,59 @@ function yasr_add_schema($content) {
|
|
499 |
$post_image_size = @getimagesize($post_image_url_absolute); //the @ should be useless, just to be safe
|
500 |
}
|
501 |
|
502 |
-
$rich_snippet[
|
503 |
|
504 |
if ($review_choosen === 'Place') {
|
505 |
-
$rich_snippet[
|
506 |
}
|
507 |
|
508 |
elseif ($review_choosen === 'Other' || $review_choosen === 'BlogPosting') {
|
509 |
-
$rich_snippet[
|
510 |
-
$rich_snippet[
|
511 |
-
$rich_snippet[
|
512 |
-
$rich_snippet[
|
513 |
-
|
514 |
-
|
515 |
);
|
516 |
-
$rich_snippet[
|
517 |
-
|
518 |
-
|
519 |
);
|
520 |
-
$rich_snippet[
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
),
|
529 |
);
|
530 |
|
531 |
-
$rich_snippet[
|
532 |
|
533 |
-
$rich_snippet[
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
);
|
539 |
|
540 |
}
|
541 |
|
542 |
-
$rich_snippet[
|
543 |
$rich_snippet['description'] = $review_name;
|
544 |
-
$rich_snippet[
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
);
|
550 |
|
551 |
//Do not add rating if blogposting
|
552 |
if ($review_choosen !== 'Other' && $review_choosen !== 'BlogPosting') {
|
553 |
-
|
554 |
-
|
555 |
-
$rich_snippet["Review"] = array(
|
556 |
'@type' => 'Review',
|
557 |
'name' => $review_name,
|
558 |
'author' => array(
|
@@ -574,7 +563,7 @@ function yasr_add_schema($content) {
|
|
574 |
//So, is post is selected as review, exclude AggregateRating
|
575 |
if($is_post_a_review !== 'yes') {
|
576 |
if ($visitor_votes) {
|
577 |
-
if ($visitor_votes['sum_votes']
|
578 |
$average_rating = $visitor_votes['sum_votes'] / $visitor_votes['number_of_votes'];
|
579 |
$average_rating = round($average_rating, 1);
|
580 |
|
@@ -600,10 +589,10 @@ function yasr_add_schema($content) {
|
|
600 |
|
601 |
if (is_singular() && is_main_query() && !is_404()) {
|
602 |
return $content . $script_type . json_encode($rich_snippet) . $end_script_type;
|
603 |
-
} else {
|
604 |
-
return $content;
|
605 |
}
|
606 |
|
|
|
|
|
607 |
} //End function
|
608 |
|
609 |
/**
|
@@ -753,8 +742,6 @@ function yasr_cache_enabler_support($post_id, $is_singular) {
|
|
753 |
else {
|
754 |
do_action('ce_clear_cache');
|
755 |
}
|
756 |
-
|
757 |
-
|
758 |
}
|
759 |
}
|
760 |
|
@@ -892,6 +879,7 @@ function yasr_unique_multidim_array($array, $key) {
|
|
892 |
|
893 |
|
894 |
//Delete caches for supported plugins
|
|
|
895 |
add_action('yasr_action_on_visitor_vote', 'yasr_delete_cache');
|
896 |
add_action('yasr_action_on_visitor_multiset_vote', 'yasr_delete_cache');
|
897 |
|
@@ -938,7 +926,7 @@ function yasr_check_valid_url($url) {
|
|
938 |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
939 |
|
940 |
//Check the response
|
941 |
-
if (($http_code ==
|
942 |
return true;
|
943 |
} else {
|
944 |
return false;
|
102 |
' <img src=' . YASR_IMG_DIR . 'loader.gif title="yasr-loader" alt="yasr-loader">
|
103 |
</div>';
|
104 |
|
|
|
|
|
|
|
105 |
wp_localize_script('yasrfront', 'yasrCommonData',
|
106 |
array(
|
107 |
+
'restEndpoint' => esc_url_raw(rest_url()),
|
108 |
'ajaxurl' => admin_url('admin-ajax.php'),
|
|
|
109 |
'visitorStatsEnabled' => YASR_VISITORS_STATS,
|
|
|
110 |
'loaderHtml' => $yasr_visitor_votes_loader,
|
111 |
+
'nonce' => wp_create_nonce('wp_rest')
|
112 |
)
|
113 |
);
|
114 |
|
159 |
|
160 |
}
|
161 |
|
|
|
162 |
}
|
163 |
|
164 |
/*** Css rules for stars set, from version 1.2.7
|
425 |
}
|
426 |
}
|
427 |
|
428 |
+
if ((!is_singular() && is_main_query()) || is_404() || did_action('get_footer')) {
|
|
|
|
|
|
|
|
|
429 |
return $content;
|
430 |
}
|
431 |
|
432 |
$overall_rating = YasrDatabaseRatings::getOverallRating();
|
433 |
$visitor_votes = YasrDatabaseRatings::getVisitorVotes(false);
|
434 |
|
435 |
+
if (!$overall_rating && !$visitor_votes['number_of_votes'] && !$visitor_votes['sum_votes']) {
|
436 |
+
return $content;
|
|
|
|
|
|
|
437 |
}
|
438 |
|
439 |
//can't be between 0.1 and 1
|
441 |
$overall_rating = 1;
|
442 |
}
|
443 |
|
444 |
+
$is_post_a_review = get_post_meta(get_the_ID(), 'yasr_post_is_review', true);
|
445 |
+
|
446 |
$script_type = '<script type="application/ld+json">';
|
447 |
$end_script_type = '</script>';
|
448 |
|
456 |
return $content . $script_type . $filtered_schema . $end_script_type;
|
457 |
}
|
458 |
|
459 |
+
$rich_snippet['@context'] = 'http://schema.org/';
|
460 |
|
461 |
$author = get_the_author();
|
462 |
$review_name = wp_strip_all_tags(get_the_title());
|
489 |
$post_image_size = @getimagesize($post_image_url_absolute); //the @ should be useless, just to be safe
|
490 |
}
|
491 |
|
492 |
+
$rich_snippet['@type'] = $review_choosen;
|
493 |
|
494 |
if ($review_choosen === 'Place') {
|
495 |
+
$rich_snippet['@type'] = 'LocalBusiness';
|
496 |
}
|
497 |
|
498 |
elseif ($review_choosen === 'Other' || $review_choosen === 'BlogPosting') {
|
499 |
+
$rich_snippet['@type'] = 'BlogPosting';
|
500 |
+
$rich_snippet['datePublished'] = $date;
|
501 |
+
$rich_snippet['headline'] = $review_name;
|
502 |
+
$rich_snippet['mainEntityOfPage'] = array(
|
503 |
+
'@type' => 'WebPage',
|
504 |
+
'@id' => get_permalink()
|
505 |
);
|
506 |
+
$rich_snippet['author'] = array(
|
507 |
+
'@type' => 'Person',
|
508 |
+
'name' => "$author"
|
509 |
);
|
510 |
+
$rich_snippet['publisher'] = array(
|
511 |
+
'@type' => 'Organization',
|
512 |
+
'name' => wp_strip_all_tags(YASR_BLOGPOSTING_ORGANIZATION_NAME), //already sanitized in the settings, just to be safe
|
513 |
+
'logo' => array(
|
514 |
+
'@type' => 'ImageObject',
|
515 |
+
'url' => $logo_image_url,
|
516 |
+
'width' => $logo_image_size[0],
|
517 |
+
'height' => $logo_image_size[1]
|
518 |
),
|
519 |
);
|
520 |
|
521 |
+
$rich_snippet['dateModified'] = $date_modified;
|
522 |
|
523 |
+
$rich_snippet['image'] = array(
|
524 |
+
'@type' => 'ImageObject',
|
525 |
+
'url' => $post_image_url,
|
526 |
+
'width' => $post_image_size[0],
|
527 |
+
'height' => $post_image_size[1]
|
528 |
);
|
529 |
|
530 |
}
|
531 |
|
532 |
+
$rich_snippet['name'] = $review_name;
|
533 |
$rich_snippet['description'] = $review_name;
|
534 |
+
$rich_snippet['image'] = array(
|
535 |
+
'@type' => 'ImageObject',
|
536 |
+
'url' => $post_image_url,
|
537 |
+
'width' => $post_image_size[0],
|
538 |
+
'height' => $post_image_size[1]
|
539 |
);
|
540 |
|
541 |
//Do not add rating if blogposting
|
542 |
if ($review_choosen !== 'Other' && $review_choosen !== 'BlogPosting') {
|
543 |
+
if ($overall_rating) {
|
544 |
+
$rich_snippet['Review'] = array(
|
|
|
545 |
'@type' => 'Review',
|
546 |
'name' => $review_name,
|
547 |
'author' => array(
|
563 |
//So, is post is selected as review, exclude AggregateRating
|
564 |
if($is_post_a_review !== 'yes') {
|
565 |
if ($visitor_votes) {
|
566 |
+
if ($visitor_votes['sum_votes'] !== 0 && $visitor_votes['number_of_votes'] !== 0) {
|
567 |
$average_rating = $visitor_votes['sum_votes'] / $visitor_votes['number_of_votes'];
|
568 |
$average_rating = round($average_rating, 1);
|
569 |
|
589 |
|
590 |
if (is_singular() && is_main_query() && !is_404()) {
|
591 |
return $content . $script_type . json_encode($rich_snippet) . $end_script_type;
|
|
|
|
|
592 |
}
|
593 |
|
594 |
+
return $content;
|
595 |
+
|
596 |
} //End function
|
597 |
|
598 |
/**
|
742 |
else {
|
743 |
do_action('ce_clear_cache');
|
744 |
}
|
|
|
|
|
745 |
}
|
746 |
}
|
747 |
|
879 |
|
880 |
|
881 |
//Delete caches for supported plugins
|
882 |
+
//Can't use is_singular() here because always return false
|
883 |
add_action('yasr_action_on_visitor_vote', 'yasr_delete_cache');
|
884 |
add_action('yasr_action_on_visitor_multiset_vote', 'yasr_delete_cache');
|
885 |
|
926 |
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
927 |
|
928 |
//Check the response
|
929 |
+
if (($http_code == '200') || ($http_code == '302')) {
|
930 |
return true;
|
931 |
} else {
|
932 |
return false;
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Requires at least: 4.9.0
|
|
5 |
Contributors: Dudo
|
6 |
Tested up to: 5.4
|
7 |
Requires PHP: 5.3
|
8 |
-
Stable tag: 2.
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
|
@@ -30,14 +30,14 @@ You can either place the overall rating automatically at the beginning or the en
|
|
30 |
You can give your users the ability to vote, pasting the shortcode [yasr_visitor_votes] where you want the stars to appear.
|
31 |
If you're using the new Gutenberg editor, just click on the "+" icon to add a block and search for Yasr Visitor Votes
|
32 |
Again, this can be placed automatically at the beginning or the end of each post; the option is in "Settings" -> "Yet Another Stars Rating: Settings".
|
33 |
-
[
|
34 |
|
35 |
= Multi Set =
|
36 |
Multisets give the opportunity to score different aspects for each review: for example, if you're reviewing a videogame, you can create the aspects "Graphics",
|
37 |
"Gameplay", "Story", etc.
|
38 |
|
39 |
= Migration tools =
|
40 |
-
You can easily migrate from WP-PostRatings
|
41 |
A tab will appear in the settings if one of these plugin is detected.
|
42 |
|
43 |
= Supported Languages =
|
@@ -99,11 +99,16 @@ If you're using the new Gutenberg editor, you don't need at all: just use the bl
|
|
99 |
If, instead, you're using the classic editor, in the visual tab just click the "Yasr Shortcode" button above the editor
|
100 |
|
101 |
= Does it work with caching plugins? =
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
*
|
106 |
-
*
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
= Why I don't see stars in google? =
|
109 |
Please be sure that if you use mostly the "yasr_visitor_votes" shortcode, you've to select "Aggregate Rating" to the question "Which rich snippet do you want to use?" in the General Settings.
|
@@ -125,12 +130,21 @@ If doesn't, it's suggested to ask in a SEO oriented forum.
|
|
125 |
|
126 |
The full changelog can be found in the plugin's directory. Recent entries:
|
127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
= 2.2.9 =
|
129 |
* FIXED: in the editor screen, if a Multi Set already has ratings, and then try to update only one, all the other
|
130 |
fields where reset
|
131 |
* ENHANCEMENT: rich snippet are returned only if a YASR shortcode is in the post or page
|
132 |
* ENHANCEMENT: changed classes names star-rating and star-value in yasr-star-rating and yasr-star-value. **DELETE YOUR BROWSER CACHE**
|
133 |
|
|
|
134 |
= 2.2.8 =
|
135 |
* FIXED: empty schema field can return error on existing post or page.
|
136 |
|
5 |
Contributors: Dudo
|
6 |
Tested up to: 5.4
|
7 |
Requires PHP: 5.3
|
8 |
+
Stable tag: 2.3.0
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
|
30 |
You can give your users the ability to vote, pasting the shortcode [yasr_visitor_votes] where you want the stars to appear.
|
31 |
If you're using the new Gutenberg editor, just click on the "+" icon to add a block and search for Yasr Visitor Votes
|
32 |
Again, this can be placed automatically at the beginning or the end of each post; the option is in "Settings" -> "Yet Another Stars Rating: Settings".
|
33 |
+
[Click here if you use a caching plugin](https://wordpress.org/plugins/yet-another-stars-rating/#does%20it%20work%20with%20caching%20plugins%3F)
|
34 |
|
35 |
= Multi Set =
|
36 |
Multisets give the opportunity to score different aspects for each review: for example, if you're reviewing a videogame, you can create the aspects "Graphics",
|
37 |
"Gameplay", "Story", etc.
|
38 |
|
39 |
= Migration tools =
|
40 |
+
You can easily migrate from *WP-PostRatings*, *kk Star Ratings*, *Rate My Post* and *Multi Rating*
|
41 |
A tab will appear in the settings if one of these plugin is detected.
|
42 |
|
43 |
= Supported Languages =
|
99 |
If, instead, you're using the classic editor, in the visual tab just click the "Yasr Shortcode" button above the editor
|
100 |
|
101 |
= Does it work with caching plugins? =
|
102 |
+
From version 2.3.0 YASR works with *every caching plugin available out there*.
|
103 |
+
In the settings, just select "yes" to "Load results with AJAX".
|
104 |
+
YASR has been tested with:
|
105 |
+
* Wp Super Cache
|
106 |
+
* LiteSpeed Cache
|
107 |
+
* Wp Fastest Cache
|
108 |
+
* WP-Optimize
|
109 |
+
* Cache Enabler
|
110 |
+
* Hyper Cache
|
111 |
+
* Wp Rocket
|
112 |
|
113 |
= Why I don't see stars in google? =
|
114 |
Please be sure that if you use mostly the "yasr_visitor_votes" shortcode, you've to select "Aggregate Rating" to the question "Which rich snippet do you want to use?" in the General Settings.
|
130 |
|
131 |
The full changelog can be found in the plugin's directory. Recent entries:
|
132 |
|
133 |
+
= 2.3.0 =
|
134 |
+
* NEW FEATURE: YASR now support all caching plugin available out there.
|
135 |
+
Just select "yes" at the question "Load results with AJAX" in the settings page.
|
136 |
+
* ENHANCEMENT: Added itemListElement in recipeInstructions
|
137 |
+
* TWEAKED: rich snippet are returned only if rating is found
|
138 |
+
* TWEAKED: Huge Code Refactor
|
139 |
+
* Minor changes
|
140 |
+
|
141 |
= 2.2.9 =
|
142 |
* FIXED: in the editor screen, if a Multi Set already has ratings, and then try to update only one, all the other
|
143 |
fields where reset
|
144 |
* ENHANCEMENT: rich snippet are returned only if a YASR shortcode is in the post or page
|
145 |
* ENHANCEMENT: changed classes names star-rating and star-value in yasr-star-rating and yasr-star-value. **DELETE YOUR BROWSER CACHE**
|
146 |
|
147 |
+
|
148 |
= 2.2.8 =
|
149 |
* FIXED: empty schema field can return error on existing post or page.
|
150 |
|
yet-another-stars-rating.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
|
6 |
* Description: Yasr - Yet Another Stars Rating is a powerful way to add SEO-friendly user-generated reviews and
|
7 |
* testimonials to your website posts, pages and CPT, without affecting its speed.
|
8 |
-
* Version: 2.
|
9 |
* Author: Dario Curvino
|
10 |
* Author URI: https://dariocurvino.it/
|
11 |
* Text Domain: yet-another-stars-rating
|
@@ -45,7 +45,7 @@ if ( !function_exists( 'yasr_fs' ) ) {
|
|
45 |
|
46 |
if ( !isset( $yasr_fs ) ) {
|
47 |
// Include Freemius SDK.
|
48 |
-
require_once
|
49 |
try {
|
50 |
$yasr_fs = fs_dynamic_init( array(
|
51 |
'id' => '256',
|
@@ -77,70 +77,78 @@ if ( !function_exists( 'yasr_fs' ) ) {
|
|
77 |
yasr_fs();
|
78 |
// Signal that SDK was initiated.
|
79 |
do_action( 'yasr_fs_loaded' );
|
80 |
-
define( 'YASR_VERSION_NUM', '2.
|
81 |
//Plugin relative path
|
82 |
-
define(
|
83 |
//Plugin RELATIVE PATH without slashes (just the directory's name)
|
84 |
-
define(
|
85 |
//Plugin language directory: here I've to use relative path
|
86 |
//because load_plugin_textdomain wants relative and not absolute path
|
87 |
-
define(
|
88 |
//Js directory absolute
|
89 |
-
define(
|
90 |
//CSS directory absolute
|
91 |
-
define(
|
92 |
//IMG directory absolute
|
93 |
-
define(
|
94 |
/****** Getting options ******/
|
95 |
//Get general options
|
96 |
$yasr_stored_options = get_option( 'yasr_general_options' );
|
97 |
global $yasr_stored_options ;
|
98 |
-
define(
|
99 |
|
100 |
if ( YASR_AUTO_INSERT_ENABLED === 1 ) {
|
101 |
-
define(
|
102 |
-
define(
|
103 |
-
define(
|
104 |
-
define(
|
105 |
-
define(
|
106 |
-
define(
|
107 |
} else {
|
108 |
-
define(
|
109 |
-
define(
|
110 |
-
define(
|
111 |
-
define(
|
112 |
-
define(
|
113 |
-
define(
|
114 |
}
|
115 |
|
116 |
-
define(
|
117 |
-
define(
|
118 |
-
define(
|
119 |
|
120 |
-
if ( YASR_TEXT_BEFORE_STARS
|
121 |
-
define(
|
122 |
-
define(
|
123 |
-
define(
|
124 |
-
define(
|
125 |
-
define(
|
126 |
}
|
127 |
|
128 |
-
define(
|
129 |
-
define(
|
130 |
-
define(
|
131 |
-
define(
|
132 |
|
133 |
if ( isset( $yasr_stored_options['blogposting_organization_name'] ) ) {
|
134 |
-
define(
|
135 |
} else {
|
136 |
-
define(
|
137 |
}
|
138 |
|
139 |
if ( isset( $yasr_stored_options['blogposting_organization_logo'] ) ) {
|
140 |
if ( filter_var( $yasr_stored_options['blogposting_organization_logo'], FILTER_VALIDATE_URL ) !== false ) {
|
141 |
-
define(
|
142 |
}
|
143 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
//Get stored style options
|
145 |
$style_options = get_option( 'yasr_style_options' );
|
146 |
global $style_options ;
|
@@ -148,29 +156,29 @@ if ( !function_exists( 'yasr_fs' ) ) {
|
|
148 |
if ( $style_options ) {
|
149 |
|
150 |
if ( isset( $style_options['textarea'] ) ) {
|
151 |
-
define(
|
152 |
} else {
|
153 |
-
define(
|
154 |
}
|
155 |
|
156 |
|
157 |
if ( isset( $style_options['scheme_color_multiset'] ) ) {
|
158 |
-
define(
|
159 |
} else {
|
160 |
-
define(
|
161 |
}
|
162 |
|
163 |
|
164 |
if ( isset( $style_options['stars_set_free'] ) ) {
|
165 |
-
define(
|
166 |
} else {
|
167 |
-
define(
|
168 |
}
|
169 |
|
170 |
} else {
|
171 |
-
define(
|
172 |
-
define(
|
173 |
-
define(
|
174 |
}
|
175 |
|
176 |
//Multi set options
|
@@ -178,24 +186,21 @@ if ( !function_exists( 'yasr_fs' ) ) {
|
|
178 |
if ( $multi_set_options ) {
|
179 |
|
180 |
if ( isset( $multi_set_options['show_average'] ) ) {
|
181 |
-
define(
|
182 |
} else {
|
183 |
-
define(
|
184 |
}
|
185 |
|
186 |
}
|
187 |
/****** End Getting options ******/
|
188 |
-
// Include function file
|
189 |
require YASR_ABSOLUTE_PATH . '/lib/yasr-functions.php';
|
190 |
require YASR_ABSOLUTE_PATH . '/lib/yasr-db-functions.php';
|
191 |
require YASR_ABSOLUTE_PATH . '/lib/yasr-db-classes.php';
|
192 |
require YASR_ABSOLUTE_PATH . '/lib/yasr-ajax-functions.php';
|
193 |
-
require YASR_ABSOLUTE_PATH . '/lib/yasr-shortcode-functions.php';
|
194 |
require YASR_ABSOLUTE_PATH . '/lib/yasr-widgets.php';
|
195 |
require YASR_ABSOLUTE_PATH . '/lib/YasrRichSnippetAdditionalFields.php';
|
196 |
-
require YASR_ABSOLUTE_PATH . '/lib/rest/YasrPostMeta.php';
|
197 |
-
require YASR_ABSOLUTE_PATH . '/lib/rest/YasrCustomFields.php';
|
198 |
-
require YASR_ABSOLUTE_PATH . '/lib/rest/YasrCustomEndpoint.php';
|
199 |
require YASR_ABSOLUTE_PATH . '/lib/rest/yasr-rest.php';
|
200 |
|
201 |
if ( is_admin() ) {
|
@@ -209,14 +214,14 @@ if ( !function_exists( 'yasr_fs' ) ) {
|
|
209 |
}
|
210 |
|
211 |
global $wpdb ;
|
212 |
-
define(
|
213 |
-
define(
|
214 |
-
define(
|
215 |
-
define(
|
216 |
-
define(
|
217 |
//Text for button in settings pages
|
218 |
$save_settings_text = __( 'Save All Settings', 'yet-another-stars-rating' );
|
219 |
-
define(
|
220 |
//use json_decode for compatibility with php <7
|
221 |
//https://wordpress.org/support/topic/error-after-update-to-version-2-0-6/
|
222 |
$supported_schema_types = json_encode( array(
|
5 |
* Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
|
6 |
* Description: Yasr - Yet Another Stars Rating is a powerful way to add SEO-friendly user-generated reviews and
|
7 |
* testimonials to your website posts, pages and CPT, without affecting its speed.
|
8 |
+
* Version: 2.3.0
|
9 |
* Author: Dario Curvino
|
10 |
* Author URI: https://dariocurvino.it/
|
11 |
* Text Domain: yet-another-stars-rating
|
45 |
|
46 |
if ( !isset( $yasr_fs ) ) {
|
47 |
// Include Freemius SDK.
|
48 |
+
require_once __DIR__ . '/freemius/start.php';
|
49 |
try {
|
50 |
$yasr_fs = fs_dynamic_init( array(
|
51 |
'id' => '256',
|
77 |
yasr_fs();
|
78 |
// Signal that SDK was initiated.
|
79 |
do_action( 'yasr_fs_loaded' );
|
80 |
+
define( 'YASR_VERSION_NUM', '2.3.0' );
|
81 |
//Plugin relative path
|
82 |
+
define( 'YASR_ABSOLUTE_PATH', __DIR__ );
|
83 |
//Plugin RELATIVE PATH without slashes (just the directory's name)
|
84 |
+
define( 'YASR_RELATIVE_PATH', dirname( plugin_basename( __FILE__ ) ) );
|
85 |
//Plugin language directory: here I've to use relative path
|
86 |
//because load_plugin_textdomain wants relative and not absolute path
|
87 |
+
define( 'YASR_LANG_DIR', YASR_RELATIVE_PATH . '/languages/' );
|
88 |
//Js directory absolute
|
89 |
+
define( 'YASR_JS_DIR', plugins_url() . '/' . YASR_RELATIVE_PATH . '/js/' );
|
90 |
//CSS directory absolute
|
91 |
+
define( 'YASR_CSS_DIR', plugins_url() . '/' . YASR_RELATIVE_PATH . '/css/' );
|
92 |
//IMG directory absolute
|
93 |
+
define( 'YASR_IMG_DIR', plugins_url() . '/' . YASR_RELATIVE_PATH . '/img/' );
|
94 |
/****** Getting options ******/
|
95 |
//Get general options
|
96 |
$yasr_stored_options = get_option( 'yasr_general_options' );
|
97 |
global $yasr_stored_options ;
|
98 |
+
define( 'YASR_AUTO_INSERT_ENABLED', (int) $yasr_stored_options['auto_insert_enabled'] );
|
99 |
|
100 |
if ( YASR_AUTO_INSERT_ENABLED === 1 ) {
|
101 |
+
define( 'YASR_AUTO_INSERT_WHAT', $yasr_stored_options['auto_insert_what'] );
|
102 |
+
define( 'YASR_AUTO_INSERT_WHERE', $yasr_stored_options['auto_insert_where'] );
|
103 |
+
define( 'YASR_AUTO_INSERT_ALIGN', $yasr_stored_options['auto_insert_align'] );
|
104 |
+
define( 'YASR_AUTO_INSERT_SIZE', $yasr_stored_options['auto_insert_size'] );
|
105 |
+
define( 'YASR_AUTO_INSERT_EXCLUDE_PAGES', $yasr_stored_options['auto_insert_exclude_pages'] );
|
106 |
+
define( 'YASR_AUTO_INSERT_CUSTOM_POST_ONLY', $yasr_stored_options['auto_insert_custom_post_only'] );
|
107 |
} else {
|
108 |
+
define( 'YASR_AUTO_INSERT_WHAT', null );
|
109 |
+
define( 'YASR_AUTO_INSERT_WHERE', null );
|
110 |
+
define( 'YASR_AUTO_INSERT_ALIGN', null );
|
111 |
+
define( 'YASR_AUTO_INSERT_SIZE', null );
|
112 |
+
define( 'YASR_AUTO_INSERT_EXCLUDE_PAGES', null );
|
113 |
+
define( 'YASR_AUTO_INSERT_CUSTOM_POST_ONLY', null );
|
114 |
}
|
115 |
|
116 |
+
define( 'YASR_SHOW_OVERALL_IN_LOOP', $yasr_stored_options['show_overall_in_loop'] );
|
117 |
+
define( 'YASR_SHOW_VISITOR_VOTES_IN_LOOP', $yasr_stored_options['show_visitor_votes_in_loop'] );
|
118 |
+
define( 'YASR_TEXT_BEFORE_STARS', (int) $yasr_stored_options['text_before_stars'] );
|
119 |
|
120 |
+
if ( YASR_TEXT_BEFORE_STARS === 1 ) {
|
121 |
+
define( 'YASR_TEXT_BEFORE_OVERALL', htmlspecialchars_decode( $yasr_stored_options['text_before_overall'] ) );
|
122 |
+
define( 'YASR_TEXT_BEFORE_VISITOR_RATING', htmlspecialchars_decode( $yasr_stored_options['text_before_visitor_rating'] ) );
|
123 |
+
define( 'YASR_TEXT_AFTER_VISITOR_RATING', htmlspecialchars_decode( $yasr_stored_options['text_after_visitor_rating'] ) );
|
124 |
+
define( 'YASR_CUSTOM_TEXT_USER_VOTED', htmlspecialchars_decode( $yasr_stored_options['custom_text_user_voted'] ) );
|
125 |
+
define( 'YASR_CUSTOM_TEXT_MUST_SIGN_IN', htmlspecialchars_decode( $yasr_stored_options['custom_text_must_sign_in'] ) );
|
126 |
}
|
127 |
|
128 |
+
define( 'YASR_VISITORS_STATS', $yasr_stored_options['visitors_stats'] );
|
129 |
+
define( 'YASR_ALLOWED_USER', $yasr_stored_options['allowed_user'] );
|
130 |
+
define( 'YASR_ENABLE_IP', $yasr_stored_options['enable_ip'] );
|
131 |
+
define( 'YASR_ITEMTYPE', $yasr_stored_options['snippet_itemtype'] );
|
132 |
|
133 |
if ( isset( $yasr_stored_options['blogposting_organization_name'] ) ) {
|
134 |
+
define( 'YASR_BLOGPOSTING_ORGANIZATION_NAME', $yasr_stored_options['blogposting_organization_name'] );
|
135 |
} else {
|
136 |
+
define( 'YASR_BLOGPOSTING_ORGANIZATION_NAME', '' );
|
137 |
}
|
138 |
|
139 |
if ( isset( $yasr_stored_options['blogposting_organization_logo'] ) ) {
|
140 |
if ( filter_var( $yasr_stored_options['blogposting_organization_logo'], FILTER_VALIDATE_URL ) !== false ) {
|
141 |
+
define( 'YASR_BLOGPOSTING_ORGANIZATION_LOGO', $yasr_stored_options['blogposting_organization_logo'] );
|
142 |
}
|
143 |
}
|
144 |
+
|
145 |
+
if ( isset( $yasr_stored_options['enable_ajax'] ) ) {
|
146 |
+
define( 'YASR_ENABLE_AJAX', $yasr_stored_options['enable_ajax'] );
|
147 |
+
} else {
|
148 |
+
define( 'YASR_ENABLE_AJAX', 'no' );
|
149 |
+
//default value
|
150 |
+
}
|
151 |
+
|
152 |
//Get stored style options
|
153 |
$style_options = get_option( 'yasr_style_options' );
|
154 |
global $style_options ;
|
156 |
if ( $style_options ) {
|
157 |
|
158 |
if ( isset( $style_options['textarea'] ) ) {
|
159 |
+
define( 'YASR_CUSTOM_CSS_RULES', $style_options['textarea'] );
|
160 |
} else {
|
161 |
+
define( 'YASR_CUSTOM_CSS_RULES', null );
|
162 |
}
|
163 |
|
164 |
|
165 |
if ( isset( $style_options['scheme_color_multiset'] ) ) {
|
166 |
+
define( 'YASR_SCHEME_COLOR', $style_options['scheme_color_multiset'] );
|
167 |
} else {
|
168 |
+
define( 'YASR_SCHEME_COLOR', null );
|
169 |
}
|
170 |
|
171 |
|
172 |
if ( isset( $style_options['stars_set_free'] ) ) {
|
173 |
+
define( 'YASR_STARS_SET', $style_options['stars_set_free'] );
|
174 |
} else {
|
175 |
+
define( 'YASR_STARS_SET', null );
|
176 |
}
|
177 |
|
178 |
} else {
|
179 |
+
define( 'YASR_CUSTOM_CSS_RULES', null );
|
180 |
+
define( 'YASR_SCHEME_COLOR', null );
|
181 |
+
define( 'YASR_STARS_SET', null );
|
182 |
}
|
183 |
|
184 |
//Multi set options
|
186 |
if ( $multi_set_options ) {
|
187 |
|
188 |
if ( isset( $multi_set_options['show_average'] ) ) {
|
189 |
+
define( 'YASR_MULTI_SHOW_AVERAGE', $multi_set_options['show_average'] );
|
190 |
} else {
|
191 |
+
define( 'YASR_MULTI_SHOW_AVERAGE', 'yes' );
|
192 |
}
|
193 |
|
194 |
}
|
195 |
/****** End Getting options ******/
|
196 |
+
// Include function file both sides
|
197 |
require YASR_ABSOLUTE_PATH . '/lib/yasr-functions.php';
|
198 |
require YASR_ABSOLUTE_PATH . '/lib/yasr-db-functions.php';
|
199 |
require YASR_ABSOLUTE_PATH . '/lib/yasr-db-classes.php';
|
200 |
require YASR_ABSOLUTE_PATH . '/lib/yasr-ajax-functions.php';
|
201 |
+
require YASR_ABSOLUTE_PATH . '/lib/shortcodes/yasr-shortcode-functions.php';
|
202 |
require YASR_ABSOLUTE_PATH . '/lib/yasr-widgets.php';
|
203 |
require YASR_ABSOLUTE_PATH . '/lib/YasrRichSnippetAdditionalFields.php';
|
|
|
|
|
|
|
204 |
require YASR_ABSOLUTE_PATH . '/lib/rest/yasr-rest.php';
|
205 |
|
206 |
if ( is_admin() ) {
|
214 |
}
|
215 |
|
216 |
global $wpdb ;
|
217 |
+
define( 'YASR_MULTI_SET_NAME_TABLE', $wpdb->prefix . 'yasr_multi_set' );
|
218 |
+
define( 'YASR_MULTI_SET_FIELDS_TABLE', $wpdb->prefix . 'yasr_multi_set_fields' );
|
219 |
+
define( 'YASR_LOG_MULTI_SET', $wpdb->prefix . 'yasr_log_multi_set' );
|
220 |
+
define( 'YASR_LOG_TABLE', $wpdb->prefix . 'yasr_log' );
|
221 |
+
define( 'YASR_LOADER_IMAGE', YASR_IMG_DIR . '/loader.gif' );
|
222 |
//Text for button in settings pages
|
223 |
$save_settings_text = __( 'Save All Settings', 'yet-another-stars-rating' );
|
224 |
+
define( 'YASR_SAVE_All_SETTINGS_TEXT', $save_settings_text );
|
225 |
//use json_decode for compatibility with php <7
|
226 |
//https://wordpress.org/support/topic/error-after-update-to-version-2-0-6/
|
227 |
$supported_schema_types = json_encode( array(
|