Yasr – Yet Another Stars Rating - Version 1.9.3

Version Description

  • Minor changes and code cleanup.
Download this release

Release Info

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

Code changes from version 1.9.2 to 1.9.3

Files changed (290) hide show
  1. lib/admin/settings/yasr-settings-functions-misc.php +0 -56
  2. lib/admin/yasr-editor-functions.php +63 -0
  3. lib/admin/yasr-metabox-top-right.php +1 -1
  4. lib/yasr-functions.php +9 -66
  5. lib/yasr-shortcode-functions.php +665 -678
  6. readme.txt +4 -0
  7. trunk/LICENSE +280 -0
  8. trunk/changelog.txt +666 -0
  9. trunk/css/yasr-admin.css +644 -0
  10. trunk/css/yasr-table-dark.css +48 -0
  11. trunk/css/yasr-table-light.css +53 -0
  12. trunk/css/yasr.css +218 -0
  13. trunk/freemius/LICENSE.txt +674 -0
  14. trunk/freemius/assets/css/admin/account.css +1 -0
  15. trunk/freemius/assets/css/admin/add-ons.css +2 -0
  16. trunk/freemius/assets/css/admin/affiliation.css +1 -0
  17. trunk/freemius/assets/css/admin/checkout.css +1 -0
  18. trunk/freemius/assets/css/admin/common.css +2 -0
  19. trunk/freemius/assets/css/admin/connect.css +1 -0
  20. trunk/freemius/assets/css/admin/debug.css +1 -0
  21. trunk/freemius/assets/css/admin/dialog-boxes.css +2 -0
  22. trunk/freemius/assets/css/admin/gdpr-optin-notice.css +1 -0
  23. trunk/freemius/assets/css/admin/index.php +3 -0
  24. trunk/freemius/assets/css/customizer.css +1 -0
  25. trunk/freemius/assets/css/index.php +3 -0
  26. trunk/freemius/assets/img/index.php +3 -0
  27. trunk/freemius/assets/img/plugin-icon.png +0 -0
  28. trunk/freemius/assets/img/theme-icon.png +0 -0
  29. trunk/freemius/assets/img/yet-another-stars-rating.png +0 -0
  30. trunk/freemius/assets/index.php +3 -0
  31. trunk/freemius/assets/js/index.php +3 -0
  32. trunk/freemius/assets/js/nojquery.ba-postmessage.js +140 -0
  33. trunk/freemius/assets/js/nojquery.ba-postmessage.min.js +12 -0
  34. trunk/freemius/assets/js/postmessage.js +135 -0
  35. trunk/freemius/assets/scss/_colors.scss +79 -0
  36. trunk/freemius/assets/scss/_functions.scss +0 -0
  37. trunk/freemius/assets/scss/_load.scss +4 -0
  38. trunk/freemius/assets/scss/_mixins.scss +270 -0
  39. trunk/freemius/assets/scss/_start.scss +4 -0
  40. trunk/freemius/assets/scss/_vars.scss +6 -0
  41. trunk/freemius/assets/scss/admin/_ajax-loader.scss +49 -0
  42. trunk/freemius/assets/scss/admin/_auto-install.scss +33 -0
  43. trunk/freemius/assets/scss/admin/_buttons.scss +28 -0
  44. trunk/freemius/assets/scss/admin/_deactivation-feedback.scss +55 -0
  45. trunk/freemius/assets/scss/admin/_gdpr-consent.scss +81 -0
  46. trunk/freemius/assets/scss/admin/_license-activation.scss +47 -0
  47. trunk/freemius/assets/scss/admin/_license-key-resend.scss +68 -0
  48. trunk/freemius/assets/scss/admin/_modal-common.scss +194 -0
  49. trunk/freemius/assets/scss/admin/_multisite-options.scss +40 -0
  50. trunk/freemius/assets/scss/admin/_plugin-upgrade-notice.scss +8 -0
  51. trunk/freemius/assets/scss/admin/_subscription-cancellation.scss +30 -0
  52. trunk/freemius/assets/scss/admin/_themes.scss +21 -0
  53. trunk/freemius/assets/scss/admin/_tooltip.scss +66 -0
  54. trunk/freemius/assets/scss/admin/account.scss +302 -0
  55. trunk/freemius/assets/scss/admin/add-ons.scss +449 -0
  56. trunk/freemius/assets/scss/admin/affiliation.scss +97 -0
  57. trunk/freemius/assets/scss/admin/checkout.scss +5 -0
  58. trunk/freemius/assets/scss/admin/common.scss +220 -0
  59. trunk/freemius/assets/scss/admin/connect.scss +548 -0
  60. trunk/freemius/assets/scss/admin/debug.scss +135 -0
  61. trunk/freemius/assets/scss/admin/dialog-boxes.scss +10 -0
  62. trunk/freemius/assets/scss/admin/gdpr-optin-notice.scss +17 -0
  63. trunk/freemius/assets/scss/admin/index.php +3 -0
  64. trunk/freemius/assets/scss/customizer.scss +125 -0
  65. trunk/freemius/assets/scss/index.php +3 -0
  66. trunk/freemius/config.php +388 -0
  67. trunk/freemius/includes/class-freemius-abstract.php +597 -0
  68. trunk/freemius/includes/class-freemius.php +21794 -0
  69. trunk/freemius/includes/class-fs-admin-notices.php +321 -0
  70. trunk/freemius/includes/class-fs-api.php +625 -0
  71. trunk/freemius/includes/class-fs-logger.php +691 -0
  72. trunk/freemius/includes/class-fs-options.php +431 -0
  73. trunk/freemius/includes/class-fs-plugin-updater.php +1360 -0
  74. trunk/freemius/includes/class-fs-security.php +85 -0
  75. trunk/freemius/includes/class-fs-storage.php +524 -0
  76. trunk/freemius/includes/class-fs-user-lock.php +126 -0
  77. trunk/freemius/includes/customizer/class-fs-customizer-support-section.php +102 -0
  78. trunk/freemius/includes/customizer/class-fs-customizer-upsell-control.php +157 -0
  79. trunk/freemius/includes/customizer/index.php +3 -0
  80. trunk/freemius/includes/debug/class-fs-debug-bar-panel.php +64 -0
  81. trunk/freemius/includes/debug/debug-bar-start.php +52 -0
  82. trunk/freemius/includes/debug/index.php +3 -0
  83. trunk/freemius/includes/entities/class-fs-affiliate-terms.php +128 -0
  84. trunk/freemius/includes/entities/class-fs-affiliate.php +84 -0
  85. trunk/freemius/includes/entities/class-fs-billing.php +95 -0
  86. trunk/freemius/includes/entities/class-fs-entity.php +149 -0
  87. trunk/freemius/includes/entities/class-fs-payment.php +110 -0
  88. trunk/freemius/includes/entities/class-fs-plugin-info.php +34 -0
  89. trunk/freemius/includes/entities/class-fs-plugin-license.php +269 -0
  90. trunk/freemius/includes/entities/class-fs-plugin-plan.php +145 -0
  91. trunk/freemius/includes/entities/class-fs-plugin-tag.php +50 -0
  92. trunk/freemius/includes/entities/class-fs-plugin.php +142 -0
  93. trunk/freemius/includes/entities/class-fs-pricing.php +141 -0
  94. trunk/freemius/includes/entities/class-fs-scope-entity.php +29 -0
  95. trunk/freemius/includes/entities/class-fs-site.php +230 -0
  96. trunk/freemius/includes/entities/class-fs-subscription.php +125 -0
  97. trunk/freemius/includes/entities/class-fs-user.php +62 -0
  98. trunk/freemius/includes/entities/index.php +3 -0
  99. trunk/freemius/includes/fs-core-functions.php +1322 -0
  100. trunk/freemius/includes/fs-essential-functions.php +479 -0
  101. trunk/freemius/includes/fs-plugin-info-dialog.php +1143 -0
  102. trunk/freemius/includes/i18n.php +603 -0
  103. trunk/freemius/includes/index.php +3 -0
  104. trunk/freemius/includes/l10n.php +48 -0
  105. trunk/freemius/includes/managers/class-fs-admin-menu-manager.php +969 -0
  106. trunk/freemius/includes/managers/class-fs-admin-notice-manager.php +472 -0
  107. trunk/freemius/includes/managers/class-fs-cache-manager.php +326 -0
  108. trunk/freemius/includes/managers/class-fs-gdpr-manager.php +202 -0
  109. trunk/freemius/includes/managers/class-fs-key-value-storage.php +392 -0
  110. trunk/freemius/includes/managers/class-fs-license-manager.php +104 -0
  111. trunk/freemius/includes/managers/class-fs-option-manager.php +490 -0
  112. trunk/freemius/includes/managers/class-fs-plan-manager.php +162 -0
  113. trunk/freemius/includes/managers/class-fs-plugin-manager.php +220 -0
  114. trunk/freemius/includes/managers/index.php +3 -0
  115. trunk/freemius/includes/sdk/Exceptions/ArgumentNotExistException.php +9 -0
  116. trunk/freemius/includes/sdk/Exceptions/EmptyArgumentException.php +9 -0
  117. trunk/freemius/includes/sdk/Exceptions/Exception.php +74 -0
  118. trunk/freemius/includes/sdk/Exceptions/InvalidArgumentException.php +8 -0
  119. trunk/freemius/includes/sdk/Exceptions/OAuthException.php +12 -0
  120. trunk/freemius/includes/sdk/Exceptions/index.php +3 -0
  121. trunk/freemius/includes/sdk/FreemiusBase.php +215 -0
  122. trunk/freemius/includes/sdk/FreemiusWordPress.php +704 -0
  123. trunk/freemius/includes/sdk/LICENSE.txt +340 -0
  124. trunk/freemius/includes/sdk/index.php +3 -0
  125. trunk/freemius/includes/supplements/fs-essential-functions-1.1.7.1.php +43 -0
  126. trunk/freemius/includes/supplements/fs-essential-functions-2.2.1.php +45 -0
  127. trunk/freemius/includes/supplements/index.php +3 -0
  128. trunk/freemius/index.php +3 -0
  129. trunk/freemius/languages/freemius-da_DK.mo +0 -0
  130. trunk/freemius/languages/freemius-da_DK.po +2434 -0
  131. trunk/freemius/languages/freemius-en.mo +0 -0
  132. trunk/freemius/languages/freemius-en.po +2320 -0
  133. trunk/freemius/languages/freemius-es_ES.mo +0 -0
  134. trunk/freemius/languages/freemius-es_ES.po +2433 -0
  135. trunk/freemius/languages/freemius-fr_FR.mo +0 -0
  136. trunk/freemius/languages/freemius-fr_FR.po +2433 -0
  137. trunk/freemius/languages/freemius-he_IL.mo +0 -0
  138. trunk/freemius/languages/freemius-he_IL.po +2434 -0
  139. trunk/freemius/languages/freemius-hu_HU.mo +0 -0
  140. trunk/freemius/languages/freemius-hu_HU.po +2433 -0
  141. trunk/freemius/languages/freemius-it_IT.mo +0 -0
  142. trunk/freemius/languages/freemius-it_IT.po +2437 -0
  143. trunk/freemius/languages/freemius-ja_JP.mo +0 -0
  144. trunk/freemius/languages/freemius-ja_JP.po +2436 -0
  145. trunk/freemius/languages/freemius-nl_NL.mo +0 -0
  146. trunk/freemius/languages/freemius-nl_NL.po +2434 -0
  147. trunk/freemius/languages/freemius-ru_RU.mo +0 -0
  148. trunk/freemius/languages/freemius-ru_RU.po +2433 -0
  149. trunk/freemius/languages/freemius.pot +2317 -0
  150. trunk/freemius/languages/index.php +3 -0
  151. trunk/freemius/require.php +49 -0
  152. trunk/freemius/start.php +522 -0
  153. trunk/freemius/templates/account.php +792 -0
  154. trunk/freemius/templates/account/billing.php +431 -0
  155. trunk/freemius/templates/account/index.php +3 -0
  156. trunk/freemius/templates/account/partials/activate-license-button.php +54 -0
  157. trunk/freemius/templates/account/partials/addon.php +350 -0
  158. trunk/freemius/templates/account/partials/deactivate-license-button.php +36 -0
  159. trunk/freemius/templates/account/partials/index.php +3 -0
  160. trunk/freemius/templates/account/partials/site.php +336 -0
  161. trunk/freemius/templates/account/payments.php +59 -0
  162. trunk/freemius/templates/add-ons.php +197 -0
  163. trunk/freemius/templates/add-trial-to-pricing.php +31 -0
  164. trunk/freemius/templates/admin-notice.php +76 -0
  165. trunk/freemius/templates/ajax-loader.php +1 -0
  166. trunk/freemius/templates/auto-installation.php +249 -0
  167. trunk/freemius/templates/checkout.php +329 -0
  168. trunk/freemius/templates/connect.php +932 -0
  169. trunk/freemius/templates/contact.php +128 -0
  170. trunk/freemius/templates/debug.php +726 -0
  171. trunk/freemius/templates/debug/api-calls.php +155 -0
  172. trunk/freemius/templates/debug/index.php +3 -0
  173. trunk/freemius/templates/debug/logger.php +66 -0
  174. trunk/freemius/templates/debug/plugins-themes-sync.php +76 -0
  175. trunk/freemius/templates/debug/scheduled-crons.php +136 -0
  176. trunk/freemius/templates/email.php +49 -0
  177. trunk/freemius/templates/firewall-issues-js.php +59 -0
  178. trunk/freemius/templates/forms/affiliation.php +486 -0
  179. trunk/freemius/templates/forms/deactivation/contact.php +23 -0
  180. trunk/freemius/templates/forms/deactivation/form.php +497 -0
  181. trunk/freemius/templates/forms/deactivation/index.php +3 -0
  182. trunk/freemius/templates/forms/deactivation/retry-skip.php +24 -0
  183. trunk/freemius/templates/forms/index.php +3 -0
  184. trunk/freemius/templates/forms/license-activation.php +700 -0
  185. trunk/freemius/templates/forms/optout.php +267 -0
  186. trunk/freemius/templates/forms/premium-versions-upgrade-handler.php +205 -0
  187. trunk/freemius/templates/forms/premium-versions-upgrade-metadata.php +45 -0
  188. trunk/freemius/templates/forms/resend-key.php +247 -0
  189. trunk/freemius/templates/forms/subscription-cancellation.php +277 -0
  190. trunk/freemius/templates/forms/trial-start.php +181 -0
  191. trunk/freemius/templates/gdpr-optin-js.php +66 -0
  192. trunk/freemius/templates/index.php +3 -0
  193. trunk/freemius/templates/js/index.php +3 -0
  194. trunk/freemius/templates/js/jquery.content-change.php +58 -0
  195. trunk/freemius/templates/js/open-license-activation.php +37 -0
  196. trunk/freemius/templates/js/style-premium-theme.php +45 -0
  197. trunk/freemius/templates/partials/network-activation.php +81 -0
  198. trunk/freemius/templates/plugin-icon.php +20 -0
  199. trunk/freemius/templates/plugin-info/description.php +78 -0
  200. trunk/freemius/templates/plugin-info/features.php +114 -0
  201. trunk/freemius/templates/plugin-info/index.php +3 -0
  202. trunk/freemius/templates/plugin-info/screenshots.php +34 -0
  203. trunk/freemius/templates/powered-by.php +58 -0
  204. trunk/freemius/templates/pricing.php +171 -0
  205. trunk/freemius/templates/secure-https-header.php +39 -0
  206. trunk/freemius/templates/sticky-admin-notice-js.php +39 -0
  207. trunk/freemius/templates/tabs-capture-js.php +63 -0
  208. trunk/freemius/templates/tabs.php +190 -0
  209. trunk/img/Yasr-Stylish.png +0 -0
  210. trunk/img/create-ranking.png +0 -0
  211. trunk/img/dark-multi-set.png +0 -0
  212. trunk/img/dialog-ok-apply.png +0 -0
  213. trunk/img/loader.gif +0 -0
  214. trunk/img/paypal.png +0 -0
  215. trunk/img/star_0.svg +2 -0
  216. trunk/img/star_1.svg +2 -0
  217. trunk/img/star_2.svg +5 -0
  218. trunk/img/star_3.svg +5 -0
  219. trunk/img/star_oxy_0.svg +295 -0
  220. trunk/img/star_oxy_1.svg +589 -0
  221. trunk/img/star_tiny.png +0 -0
  222. trunk/img/stars_rater.png +0 -0
  223. trunk/img/stars_rater_oxy.png +0 -0
  224. trunk/img/stars_rater_yasr.png +0 -0
  225. trunk/img/yasr-multi-set-insert-rate-small.jpg +0 -0
  226. trunk/img/yasr-multi-set-insert-rate.jpg +0 -0
  227. trunk/img/yasr-multi-set.png +0 -0
  228. trunk/img/yasr-pro-stars.png +0 -0
  229. trunk/img/yasr-stars-large.png +0 -0
  230. trunk/img/yasr-stars-medium.png +0 -0
  231. trunk/img/yasr-stars-small.png +0 -0
  232. trunk/img/yasr-user-reviews.png +0 -0
  233. trunk/img/yasr_aggregate.jpg +0 -0
  234. trunk/img/yasr_review.png +0 -0
  235. trunk/js/rater-js-rtl.js +314 -0
  236. trunk/js/rater-js.js +303 -0
  237. trunk/js/src/yasr-guten-blocks.js +475 -0
  238. trunk/js/tippy.all.min.js +1 -0
  239. trunk/js/yasr-admin.js +929 -0
  240. trunk/js/yasr-front.js +350 -0
  241. trunk/js/yasr-guten-blocks.js +568 -0
  242. trunk/js/yasr-shortcode-creator.js +17 -0
  243. trunk/languages/yet-another-stars-rating-cs_CZ.mo +0 -0
  244. trunk/languages/yet-another-stars-rating-cs_CZ.po +1163 -0
  245. trunk/languages/yet-another-stars-rating-de_DE.mo +0 -0
  246. trunk/languages/yet-another-stars-rating-de_DE.po +1615 -0
  247. trunk/languages/yet-another-stars-rating-es_ES.mo +0 -0
  248. trunk/languages/yet-another-stars-rating-es_ES.po +1224 -0
  249. trunk/languages/yet-another-stars-rating-fa_IR.mo +0 -0
  250. trunk/languages/yet-another-stars-rating-fa_IR.po +1222 -0
  251. trunk/languages/yet-another-stars-rating-fr_FR.mo +0 -0
  252. trunk/languages/yet-another-stars-rating-fr_FR.po +1384 -0
  253. trunk/languages/yet-another-stars-rating-hr.mo +0 -0
  254. trunk/languages/yet-another-stars-rating-hr.po +1125 -0
  255. trunk/languages/yet-another-stars-rating-it_IT.mo +0 -0
  256. trunk/languages/yet-another-stars-rating-it_IT.po +1494 -0
  257. trunk/languages/yet-another-stars-rating-nb_NO.mo +0 -0
  258. trunk/languages/yet-another-stars-rating-nb_NO.po +1243 -0
  259. trunk/languages/yet-another-stars-rating-nl_NL.mo +0 -0
  260. trunk/languages/yet-another-stars-rating-nl_NL.po +1430 -0
  261. trunk/languages/yet-another-stars-rating-pl_PL.mo +0 -0
  262. trunk/languages/yet-another-stars-rating-pl_PL.po +1187 -0
  263. trunk/languages/yet-another-stars-rating-pt_BR.mo +0 -0
  264. trunk/languages/yet-another-stars-rating-pt_BR.po +1115 -0
  265. trunk/languages/yet-another-stars-rating-ru_RU.mo +0 -0
  266. trunk/languages/yet-another-stars-rating-ru_RU.po +1296 -0
  267. trunk/languages/yet-another-stars-rating.mo +0 -0
  268. trunk/languages/yet-another-stars-rating.pot +1543 -0
  269. trunk/lib/admin/class-wp-list-table.php +1387 -0
  270. trunk/lib/admin/settings/yasr-settings-functions-misc.php +138 -0
  271. trunk/lib/admin/settings/yasr-settings-functions-multiset.php +828 -0
  272. trunk/lib/admin/settings/yasr-settings-functions-style.php +123 -0
  273. trunk/lib/admin/settings/yasr-settings-functions.php +883 -0
  274. trunk/lib/admin/yasr-admin-actions.php +107 -0
  275. trunk/lib/admin/yasr-editor-functions.php +143 -0
  276. trunk/lib/admin/yasr-metabox-multiple-rating.php +104 -0
  277. trunk/lib/admin/yasr-metabox-top-right.php +142 -0
  278. trunk/lib/yasr-ajax-functions.php +1248 -0
  279. trunk/lib/yasr-db-functions.php +968 -0
  280. trunk/lib/yasr-functions.php +1025 -0
  281. trunk/lib/yasr-shortcode-functions.php +1062 -0
  282. trunk/lib/yasr-stats-functions.php +278 -0
  283. trunk/lib/yasr-widgets.php +552 -0
  284. trunk/readme.txt +186 -0
  285. trunk/yasr-settings-page.php +272 -0
  286. trunk/yasr-stats-page.php +101 -0
  287. trunk/yet-another-stars-rating.php +290 -0
  288. yasr-settings-page.php +0 -7
  289. yasr-stats-page.php +0 -5
  290. yet-another-stars-rating.php +3 -3
lib/admin/settings/yasr-settings-functions-misc.php CHANGED
@@ -1,32 +1,5 @@
1
<?php
2
3
- /*** Facebook sdk, since version 0.8.8 ***/
4
-
5
- function yasr_include_fb_sdk () {
6
-
7
- $lang = get_locale();
8
-
9
- $lang = json_encode("$lang");
10
-
11
- ?>
12
-
13
- <div id="fb-root"></div>
14
- <script>
15
- (function(d, s, id) {
16
- var lang = <?php echo ($lang); ?>;
17
- var js, fjs = d.getElementsByTagName(s)[0];
18
- if (d.getElementById(id)) return;
19
- js = d.createElement(s); js.id = id;
20
- js.src = "//connect.facebook.net/"+lang+"/sdk.js#xfbml=1&version=v2.3&appId=113845018658519";
21
- fjs.parentNode.insertBefore(js, fjs);
22
- }
23
- (document, 'script', 'facebook-jssdk'));
24
- </script>
25
-
26
- <?php
27
-
28
- }
29
-
30
function yasr_upgrade_pro_box ($position=FALSE) {
31
32
if ( yasr_fs()->is_free_plan() ) {
@@ -67,35 +40,6 @@ function yasr_upgrade_pro_box ($position=FALSE) {
67
68
}
69
70
- /****** Facebook box, since version 0.8.8 ******/
71
-
72
- function yasr_fb_box ($position=FALSE) {
73
-
74
- if ($position && $position == "bottom") {
75
- $yasr_fb_class = "yasr-donatedivbottom";
76
- }
77
-
78
- else {
79
- $yasr_fb_class = "yasr-donatedivdx";
80
- }
81
-
82
- ?>
83
-
84
- <div class="<?php echo $yasr_fb_class; ?>" style="display:none">
85
-
86
- <h2><?php _e('Keep in touch!', 'yet-another-stars-rating'); ?></h2>
87
-
88
- <div class="fb-page" data-href="https://www.facebook.com/yetanotherstarsrating" data-hide-cover="false" data-show-facepile="true" data-show-posts="false">
89
- <div class="fb-xfbml-parse-ignore">
90
- <blockquote cite="https://www.facebook.com/yetanotherstarsrating"><a href="https://www.facebook.com/yetanotherstarsrating">YASR - Yet Another Stars Rating</a></blockquote>
91
- </div>
92
- </div>
93
-
94
- </div>
95
-
96
- <?php
97
-
98
- }
99
100
/** Add a box on the right for asking to rate 5 stars on Wordpress.org
101
* It must be appear after 10 logged rating, after 100 and after 1000
1
<?php
2
3
function yasr_upgrade_pro_box ($position=FALSE) {
4
5
if ( yasr_fs()->is_free_plan() ) {
40
41
}
42
43
44
/** Add a box on the right for asking to rate 5 stars on Wordpress.org
45
* It must be appear after 10 logged rating, after 100 and after 1000
lib/admin/yasr-editor-functions.php CHANGED
@@ -77,4 +77,67 @@ add_action( 'init', 'yasr_gutenberg_show_in_rest_overall_meta' );
77
}
78
79
80
?>
77
}
78
79
80
+ /****** Create 2 metaboxes in post and pages ******/
81
+
82
+ add_action( 'add_meta_boxes', 'yasr_add_metaboxes' );
83
+
84
+ function yasr_add_metaboxes() {
85
+
86
+ //Default post type where display metabox
87
+ $post_type_where_display_metabox = array('post', 'page');
88
+
89
+ //get the custom post type
90
+ $custom_post_types = yasr_get_custom_post_type();
91
+
92
+ if ($custom_post_types) {
93
+
94
+ //First merge array then changes keys to int
95
+ $post_type_where_display_metabox = array_values(array_merge($post_type_where_display_metabox, $custom_post_types));
96
+
97
+ }
98
+
99
+ //For classic editor, add this metabox
100
+ foreach ($post_type_where_display_metabox as $post_type) {
101
+ add_meta_box( 'yasr_metabox_overall_rating',
102
+ 'YASR', 'yasr_metabox_overall_rating_content', $post_type,
103
+ 'side', 'high',
104
+ //Set this to true, so this metabox will be only loaded to classic editor
105
+ array(
106
+ '__back_compat_meta_box' => true,
107
+ )
108
+ );
109
+ }
110
+
111
+ $multi_set=yasr_get_multi_set();
112
+ //If multiset are used then add the second metabox
113
+ if ($multi_set) {
114
+ foreach ($post_type_where_display_metabox as $post_type) {
115
+ add_meta_box( 'yasr_metabox_multiple_rating', __( 'Yet Another Stars Rating: Multiple set', 'yet-another-stars-rating' ), 'yasr_metabox_multiple_rating_content', $post_type, 'normal', 'high' );
116
+ }
117
+ }
118
+
119
+ } //End function
120
+
121
+ function yasr_metabox_overall_rating_content() {
122
+
123
+ if ( current_user_can( 'publish_posts' ) ) {
124
+ include(YASR_ABSOLUTE_PATH . '/lib/admin/yasr-metabox-top-right.php');
125
+ }
126
+ else {
127
+ _e("You don't have enought privileges to insert Overall Rating");
128
+ }
129
+
130
+ }
131
+
132
+ function yasr_metabox_multiple_rating_content() {
133
+
134
+ if ( current_user_can( 'publish_posts' ) ) {
135
+ include(YASR_ABSOLUTE_PATH . '/lib/admin/yasr-metabox-multiple-rating.php');
136
+ }
137
+ else {
138
+ _e("You don't have enough privileges to insert a Multi Set");
139
+ }
140
+
141
+ }
142
+
143
?>
lib/admin/yasr-metabox-top-right.php CHANGED
@@ -133,7 +133,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
133
134
var postid = <?php json_encode(the_ID()); ?>;
135
136
- var overallRating = <?php echo (json_encode($overall_rating)); ?>
137
138
yasrPrintMetaBoxOverall (postid, overallRating);
139
133
134
var postid = <?php json_encode(the_ID()); ?>;
135
136
+ var overallRating = <?php echo (json_encode($overall_rating)); ?>;
137
138
yasrPrintMetaBoxOverall (postid, overallRating);
139
lib/yasr-functions.php CHANGED
@@ -93,7 +93,7 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
93
94
wp_enqueue_script( 'rater', YASR_JS_DIR . 'rater-js.js' , '', YASR_VERSION_NUM, TRUE );
95
96
- wp_enqueue_script('yasr_shortcode_creator', YASR_JS_DIR . 'yasr-shortcode-creator.js', array('jquery'), '1.0', TRUE);
97
98
do_action('yasr_add_admin_scripts_end', $hook);
99
@@ -219,8 +219,15 @@ function yasr_rtl_support () {
219
'yasr_stats_page',
220
'yasr_stats_page_callback'
221
);
222
- }
223
224
225
// Settings Page Content
226
function yasr_settings_page_callback () {
@@ -245,70 +252,6 @@ function yasr_rtl_support () {
245
}
246
247
248
-
249
- /****** Create 2 metaboxes in post and pages ******/
250
-
251
- add_action( 'add_meta_boxes', 'yasr_add_metaboxes' );
252
-
253
- function yasr_add_metaboxes() {
254
-
255
- //Default post type where display metabox
256
- $post_type_where_display_metabox = array('post', 'page');
257
-
258
- //get the custom post type
259
- $custom_post_types = yasr_get_custom_post_type();
260
-
261
- if ($custom_post_types) {
262
-
263
- //First merge array then changes keys to int
264
- $post_type_where_display_metabox = array_values(array_merge($post_type_where_display_metabox, $custom_post_types));
265
-
266
- }
267
-
268
- //Always add this metabox
269
- foreach ($post_type_where_display_metabox as $post_type) {
270
- add_meta_box( 'yasr_metabox_overall_rating',
271
- 'YASR', 'yasr_metabox_overall_rating_content', $post_type,
272
- 'side', 'high',
273
- array(
274
- '__back_compat_meta_box' => true,
275
- )
276
- );
277
- }
278
-
279
- $multi_set=yasr_get_multi_set();
280
- //If multiset are used then add the second metabox
281
- if ($multi_set) {
282
- foreach ($post_type_where_display_metabox as $post_type) {
283
- add_meta_box( 'yasr_metabox_multiple_rating', __( 'Yet Another Stars Rating: Multiple set', 'yet-another-stars-rating' ), 'yasr_metabox_multiple_rating_content', $post_type, 'normal', 'high' );
284
- }
285
- }
286
-
287
- } //End function
288
-
289
- function yasr_metabox_overall_rating_content() {
290
-
291
- if ( current_user_can( 'publish_posts' ) ) {
292
- include(YASR_ABSOLUTE_PATH . '/lib/admin/yasr-metabox-top-right.php');
293
- }
294
- else {
295
- _e("You don't have enought privileges to insert Overall Rating");
296
- }
297
-
298
- }
299
-
300
- function yasr_metabox_multiple_rating_content() {
301
-
302
- if ( current_user_can( 'publish_posts' ) ) {
303
- include(YASR_ABSOLUTE_PATH . '/lib/admin/yasr-metabox-multiple-rating.php');
304
- }
305
- else {
306
- _e("You don't have enough privileges to insert a Multi Set");
307
- }
308
-
309
- }
310
-
311
-
312
/****** Auto insert overall rating and visitor rating ******/
313
314
if (YASR_AUTO_INSERT_ENABLED == 1) {
93
94
wp_enqueue_script( 'rater', YASR_JS_DIR . 'rater-js.js' , '', YASR_VERSION_NUM, TRUE );
95
96
+ wp_enqueue_script('yasr_shortcode_creator', YASR_JS_DIR . 'yasr-shortcode-creator.js', array('jquery'), YASR_VERSION_NUM, TRUE);
97
98
do_action('yasr_add_admin_scripts_end', $hook);
99
219
'yasr_stats_page',
220
'yasr_stats_page_callback'
221
);
222
223
+ if (yasr_fs()->is_free_plan()) {
224
+ global $submenu;
225
+ $permalink = '#';
226
+ $contact_us_string = sprintf(__('Contact Us %s', 'yet-another-stars-rating'), '<span class="dashicons dashicons-lock" />');
227
+ $submenu['yasr_settings_page'][] = array( $contact_us_string, 'manage_options', $permalink );
228
+ }
229
+
230
+ }
231
232
// Settings Page Content
233
function yasr_settings_page_callback () {
252
}
253
254
255
/****** Auto insert overall rating and visitor rating ******/
256
257
if (YASR_AUTO_INSERT_ENABLED == 1) {
lib/yasr-shortcode-functions.php CHANGED
@@ -18,320 +18,308 @@ 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' ) ) exit('You\'re not allowed to see this page'); // Exit if accessed directly
22
23
/****** Add shortcode for overall rating ******/
24
- add_shortcode ('yasr_overall_rating', 'shortcode_overall_rating_callback');
25
26
- function shortcode_overall_rating_callback ($atts) {
27
28
- if (YASR_SHOW_OVERALL_IN_LOOP === 'disabled' && !is_singular() && is_main_query()) {
29
- return;
30
- }
31
-
32
- extract( shortcode_atts (
33
- array(
34
- 'size' => 'large',
35
- 'postid' => FALSE
36
- ), $atts )
37
- );
38
-
39
- /** If postid is not passed as an element, get the current post id **/
40
- if ($postid === FALSE) {
41
- $postid = get_the_ID();
42
- }
43
-
44
- $overall_rating = yasr_get_overall_rating($postid);
45
-
46
- //if still false
47
- if (!$overall_rating) {
48
- $overall_rating = "-1";
49
- }
50
-
51
- $shortcode_html = '<!--Yasr Overall Rating Shortcode-->';
52
53
- $stars_attribute = yasr_stars_size($size);
54
55
- //generate an unique id to be sure that every element has a different ID
56
- $unique_id = str_shuffle(uniqid());
57
58
- $overall_rating_html_id = 'yasr-overall-rating-rater-' . $unique_id;
59
- $html_stars = "<div class='yasr-overall-rating'>
60
- <div class=\"yasr-rater-stars\" id=\"$overall_rating_html_id\" data-rating=\"$overall_rating\" data-rater-starsize=\"$stars_attribute[px_size]\" ></div>
61
- </div>
62
- ";
63
64
- if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_BEFORE_OVERALL != '') {
65
66
- $text_before_star = str_replace('%overall_rating%', $overall_rating, YASR_TEXT_BEFORE_OVERALL);
67
- $shortcode_html = "<div class=\"yasr-container-custom-text-and-overall\">
68
- <span id=\"yasr-custom-text-before-overall\">" . $text_before_star . "</span>
69
- $html_stars
70
- </div>";
71
72
- }
73
74
- else {
75
76
- $shortcode_html .= $html_stars;
77
78
- }
79
80
- $shortcode_html .= '<!--End Yasr Overall Rating Shortcode-->';
81
82
83
- //If overall rating in loop is enabled don't use is_singular && is main_query
84
- if ( YASR_SHOW_OVERALL_IN_LOOP === 'enabled' ) {
85
- return $shortcode_html;
86
- }
87
88
- //default
89
- else {
90
- if( is_singular() && is_main_query() ) {
91
- return $shortcode_html;
92
- }
93
- }
94
95
- } //end function
96
97
98
/****** Add shortcode for user vote ******/
99
100
add_shortcode ('yasr_visitor_votes', 'shortcode_visitor_votes_callback');
101
102
- function shortcode_visitor_votes_callback ($atts) {
103
-
104
- if (YASR_SHOW_OVERALL_IN_LOOP === 'disabled' && !is_singular() && is_main_query()) {
105
- return;
106
- }
107
-
108
- $shortcode_html = NULL; //Avoid undefined variable outside is_singular && is_main_query
109
110
- extract( shortcode_atts (
111
- array(
112
- 'size' => 'large',
113
- 'postid' => FALSE,
114
- 'readonly' => FALSE
115
- ), $atts )
116
- );
117
118
- //If it's not specified use get_the_id
119
- if (!$postid) {
120
- $post_id = get_the_ID();
121
- }
122
123
- else {
124
- $post_id = $postid;
125
- }
126
127
- $votes=yasr_get_visitor_votes($post_id); //always reference it
128
129
- $unique_id = str_shuffle(uniqid());
130
131
- $medium_rating=0; //Avoid undefined variable
132
133
- if (!$votes) {
134
- $votes=0; //Avoid undefined variable if there is not rating
135
- $votes_number=0; //Avoid undefined variable
136
- }
137
138
- else {
139
- foreach ($votes as $user_votes) {
140
- $votes_number = $user_votes->number_of_votes;
141
- if ($votes_number != 0 ) {
142
- $medium_rating = ($user_votes->sum_votes/$votes_number);
143
- }
144
- else {
145
- $medium_rating = 0;
146
- }
147
- }
148
- }
149
150
- $medium_rating=round($medium_rating, 1);
151
152
- $stars_attribute = yasr_stars_size($size);
153
154
- if(is_singular()) {
155
- $is_singular = 'true';
156
- }
157
- else {
158
- $is_singular = 'false';
159
}
160
161
- //if this come from yasr_visitor_votes_readonly...
162
- if ($readonly === TRUE || $readonly === "yes") {
163
-
164
- $htmlid = 'yasr-visitor-votes-readonly-rater-'.$unique_id;
165
- $shortcode_html = "<div class=\"yasr-rater-stars-visitor-votes\" id=\"$htmlid\" data-rating=\"$medium_rating\" data-rater-starsize=\"$stars_attribute[px_size]\" data-rater-postid=\"$post_id\" data-rater-readonly=\"true\"></div>";
166
167
- return $shortcode_html;
168
169
- }
170
-
171
- $ajax_nonce_visitor = wp_create_nonce( "yasr_nonce_insert_visitor_rating" );
172
173
- //name of cookie to check
174
- $yasr_cookiename = 'yasr_visitor_vote_cookie';
175
176
- $cookie_value = FALSE; //avoid undefined
177
178
- if (isset($_COOKIE[$yasr_cookiename])) {
179
180
- $cookie_data = stripslashes($_COOKIE[$yasr_cookiename]);
181
182
- //By default, json_decode return an object, TRUE to return an array
183
- $cookie_data = json_decode($cookie_data, TRUE);
184
185
- if (is_array($cookie_data)) {
186
187
- foreach ($cookie_data as $value) {
188
189
- $cookie_post_id = (int)$value['post_id'];
190
191
- if ($cookie_post_id === $post_id) {
192
- $cookie_value = (int)$value['rating'];
193
- //Stop doing foreach, here we've found the rating for current post
194
- break;
195
- }
196
197
}
198
-
199
- }
200
-
201
- if ($cookie_value !== FALSE && $cookie_value > 5) {
202
- $cookie_value = 5;
203
- }
204
-
205
- elseif ($cookie_value !== FALSE && $cookie_value < 1) {
206
- $cookie_value = 1;
207
}
208
-
209
}
210
211
212
- $shortcode_html = '<!--Yasr Visitor Votes Shortcode-->';
213
- $shortcode_html .= "<div id=\"yasr_visitor_votes_$post_id\" class=\"yasr-visitor-votes\">";
214
- $span_bottom_line = "";
215
-
216
- //I've to check a logged in user that has already rated
217
- if ( is_user_logged_in() ) {
218
-
219
- $readonly = 'false'; //Always false if user is logged in
220
221
- //Chek if a logged in user has already rated for this post
222
- $vote_if_user_already_rated = yasr_check_if_user_already_voted($post_id);
223
224
- //If user has already rated
225
- if ($vote_if_user_already_rated) {
226
- $span_bottom_line="<span class=\"yasr-small-block-bold yasr-already-voted-text \" id=\"yasr-user-vote-$post_id\" data-yasr-already-voted=\"$vote_if_user_already_rated\">"
227
- . __("You've already voted this article with", 'yet-another-stars-rating') . " $vote_if_user_already_rated</span>";
228
- }
229
230
- } //End if user is logged
231
232
- //if anonymous are allowed to vote
233
- if (YASR_ALLOWED_USER === 'allow_anonymous') {
234
235
- //IF user is not logged in
236
- if(!is_user_logged_in()) {
237
-
238
- //if cookie exists
239
- if($cookie_value) {
240
- $readonly = 'true';
241
- if (YASR_TEXT_BEFORE_STARS == 1 && YASR_CUSTOM_TEXT_USER_VOTED!='') {
242
- $span_bottom_line="<span class=\"yasr-small-block-bold yasr-already-voted-text\">" . YASR_CUSTOM_TEXT_USER_VOTED . " </span>";;
243
- }
244
- else {
245
- $span_bottom_line="<span class=\"yasr-small-block-bold yasr-already-voted-text \">"
246
- . __("You've already voted this article with", 'yet-another-stars-rating') . " $cookie_value</span>";
247
- }
248
- }
249
250
- else {
251
- $readonly = 'false';
252
}
253
-
254
}
255
-
256
- } //end if YASR_ALLOWED_USER === 'allow_anonymous' {
257
-
258
-
259
- //If only logged in users can vote
260
- elseif (YASR_ALLOWED_USER === 'logged_only') {
261
-
262
- //IF user is not logged in
263
- if(!is_user_logged_in()) {
264
-
265
- $readonly = 'true'; //readonly is true if user isn't logged
266
- $span_bottom_line = "<span class=\"yasr-visitor-votes-must-sign-in\">" . __("You must sign in to vote", 'yet-another-stars-rating') . "</span>";
267
-
268
- }
269
-
270
}
271
272
- if (YASR_VISITORS_STATS === 'yes') {
273
- $span_dashicon = "<span class=\"dashicons dashicons-chart-bar yasr-dashicons-visitor-stats \" data-postid=\"$post_id\" id=\"yasr-total-average-dashicon-$post_id\"></span>";
274
- }
275
276
- else {
277
- $span_dashicon = "";
278
}
279
280
281
- if(YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_BEFORE_VISITOR_RATING != '') {
282
- $text_before_star = str_replace('%total_count%', $votes_number, YASR_TEXT_BEFORE_VISITOR_RATING);
283
- $text_before_star = str_replace('%average%', $medium_rating, $text_before_star);
284
- $shortcode_html .= "<div class=\"yasr-container-custom-text-and-visitor-rating\">
285
- <span id=\"yasr-custom-text-before-visitor-rating\">" . $text_before_star . "</span></div>";
286
- }
287
288
- if(YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_AFTER_VISITOR_RATING != '') {
289
- $text_after_star = str_replace('%total_count%', $votes_number, YASR_TEXT_AFTER_VISITOR_RATING);
290
- $text_after_star = str_replace('%average%', $medium_rating, $text_after_star);
291
- $span_text_after_star = "<span class=\"yasr-total-average-container\" id=\"yasr-total-average-text_$post_id\">" . $text_after_star . "</span>";
292
- }
293
294
- else {
295
-
296
- $span_text_after_star = "<span class=\"yasr-total-average-container\" id=\"yasr-total-average-text_$post_id\">
297
- [" . __("Total: ", 'yet-another-stars-rating') . "$votes_number &nbsp; &nbsp;" . __("Average: ",'yet-another-stars-rating') . "$medium_rating/5]
298
- </span>";
299
300
- }
301
302
- $span_container_after_stars = "<span id=\"yasr-visitor-votes-container-after-stars-$unique_id\" class='yasr-visitor-votes-after-stars-class'>";
303
304
- $htmlid = 'yasr-visitor-votes-rater-' . $unique_id ;
305
306
- $shortcode_html .= "<div id=\"$htmlid\" class=\"yasr-rater-stars-visitor-votes\" data-rater-postid=\"$post_id\" data-rating=\"$medium_rating\" data-rater-starsize=\"$stars_attribute[px_size]\" data-rater-readonly=\"$readonly\" data-rater-nonce=\"$ajax_nonce_visitor\" data-issingular=\"$is_singular\"></div>";
307
308
- $shortcode_html .= $span_container_after_stars;
309
- $shortcode_html .= $span_dashicon;
310
- $shortcode_html .= $span_text_after_star;
311
- $shortcode_html .= $span_bottom_line;
312
- $shortcode_html .= '</span>'; //Close yasr-visitor-votes-after-stars and yasr_visitor_votes
313
- $shortcode_html .= '</div>'; //close all
314
- $shortcode_html .= '<!--End Yasr Visitor Votes Shortcode-->';
315
316
- //If overall rating in loop is enabled don't use is_singular && is main_query
317
- if ( YASR_SHOW_VISITOR_VOTES_IN_LOOP === 'enabled' ) {
318
319
return $shortcode_html;
320
-
321
}
322
323
- //default value
324
- else {
325
-
326
- if( is_singular() && is_main_query() ) {
327
-
328
- return $shortcode_html;
329
-
330
- }
331
-
332
- }
333
334
- } //End function shortcode_visitor_votes_callback
335
336
337
/*
@@ -339,329 +327,324 @@ add_shortcode ('yasr_visitor_votes', 'shortcode_visitor_votes_callback');
339
*/
340
add_shortcode ('yasr_visitor_votes_readonly', 'yasr_visitor_votes_readonly_callback');
341
342
- function yasr_visitor_votes_readonly_callback ($atts) {
343
344
- $atts['readonly'] = TRUE;
345
346
- //Here I call the same function that draw the same function for yasr_visitor_votes,
347
- //passing the attribute readonly = TRUE
348
- $shortcode_html = shortcode_visitor_votes_callback($atts);
349
350
- return $shortcode_html;
351
352
- } //End function shortcode_visitor_votes_only_stars_callback
353
354
355
/****** Add shortcode for multiple set ******/
356
357
add_shortcode ('yasr_multiset', 'shortcode_multi_set_callback');
358
359
- function shortcode_multi_set_callback( $atts ) {
360
-
361
- global $wpdb;
362
363
- // Attributes
364
- extract( shortcode_atts(
365
- array(
366
- 'setid' => '0',
367
- 'postid' => FALSE,
368
- 'show_average' => FALSE
369
- ), $atts )
370
- );
371
-
372
- //If it's not specified use get_the_id
373
- if (!$postid) {
374
-
375
- $post_id = get_the_ID();
376
-
377
- }
378
-
379
- else {
380
-
381
- $post_id = $postid;
382
-
383
- }
384
385
- $shortcode_html = '<!-- Yasr Multi Set Shortcode-->';
386
387
- $multiset_vote_sum = 0;
388
- $multiset_rows_number = 0; //
389
390
- $set_name_content=yasr_get_multi_set_values_and_field ($post_id, $setid);
391
392
- if (!$set_name_content) {
393
394
- $set_name_content=$wpdb->get_results($wpdb->prepare("SELECT field_name AS name, field_id AS id
395
- FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
396
- WHERE parent_set_id=%d
397
- ORDER BY field_id ASC", $setid));
398
399
- //if it still to be empty (e.g. wrong id passed)
400
- if (!$set_name_content) {
401
402
- return $shortcode_html;
403
404
- }
405
406
}
407
408
- $shortcode_html.="<table class=\"yasr_table_multi_set_shortcode\">";
409
410
- //this is to avoid undefined, may happens when an user insert the shortcode without insert vote (only happens if more than 1 multiset are used)
411
- $set_content = new stdClass();
412
- $set_content->vote = NULL; //avoid undefined
413
414
- foreach ($set_name_content as $set_content) {
415
416
- //Avoid undefined if vote does not exists
417
- if(!isset($set_content->vote)) {
418
- $set_content->vote = 0;
419
- }
420
421
- $shortcode_html .= "<tr><td><span class=\"yasr-multi-set-name-field\">$set_content->name </span></td>";
422
423
- $unique_id_identifier = $post_id . '_' . $setid . '_' . $set_content->id;
424
425
- $shortcode_html .= "<td><div class=\"yasr-rater-stars\" id=\"yasr-rater-multiset-$unique_id_identifier\" data-rater-postid=\"$post_id\" data-rating=\"$set_content->vote\" data-rater-starsize=\"16\"></div></td>
426
- </tr>";
427
428
- $multiset_vote_sum = $multiset_vote_sum + $set_content->vote;
429
- $multiset_rows_number++;
430
431
- }
432
433
- if ($show_average !== FALSE && $show_average !=='no' || $show_average === FALSE && YASR_MULTI_SHOW_AVERAGE !== 'no') {
434
435
- $multiset_average = $multiset_vote_sum / $multiset_rows_number;
436
- $multiset_average = round($multiset_average, 1);
437
438
- $average_txt = __("Average", "yet-another-stars-rating");
439
440
- $average_unique_id_identifier = 'yasr-multiset-average_' . $post_id . '_' . $setid;
441
442
- $shortcode_html .= "<tr>
443
- <td colspan='2' class='yasr-multiset-average'>
444
- <span class='yasr-multiset-average-text'>$average_txt</span>
445
- <div class='yasr-rater-stars' id=\"$average_unique_id_identifier\" data-rater-postid=\"$post_id\" data-rating=\"$multiset_average\" data-rater-starsize=\"24\"></div>
446
- </td>
447
- </tr>";
448
449
450
- }
451
452
- $shortcode_html.="</table>";
453
454
- $shortcode_html .= '<!--End Yasr Multi Set Shortcode-->';
455
456
- return $shortcode_html;
457
458
- } //End function
459
460
461
/****** Add shortcode for multiset writable by users ******/
462
463
add_shortcode ('yasr_visitor_multiset', 'yasr_visitor_multiset_callback');
464
465
- function yasr_visitor_multiset_callback ( $atts ) {
466
-
467
- $ajax_nonce_visitor_multiset = wp_create_nonce( "yasr_nonce_insert_visitor_rating_multiset" );
468
-
469
- global $wpdb;
470
-
471
- // Attributes
472
- extract( shortcode_atts(
473
- array(
474
- 'setid' => '0',
475
- 'postid' => FALSE,
476
- 'show_average' => FALSE
477
- ), $atts )
478
- );
479
480
- //If it's not specified use get_the_id
481
- if (!$postid) {
482
- $post_id = get_the_ID();
483
- }
484
-
485
- else {
486
- $post_id = $postid;
487
- }
488
489
- $image = YASR_IMG_DIR . "/loader.gif";
490
- $average_txt = __("Average", "yet-another-stars-rating");
491
- $loader_html = "<span class=\"yasr-loader-multiset-visitor\" id=\"yasr-loader-multiset-visitor-$post_id-$setid\" >&nbsp; " . ' <img src=' . "$image" .' title="yasr-loader" alt="yasr-loader"></span>';
492
- $button_html = "<input type=\"submit\" name=\"submit\" id=\"yasr-send-visitor-multiset-$post_id-$setid\" class=\"button button-primary yasr-send-visitor-multiset\" data-postid=\"$post_id\" data-setid=\"$setid\" value=\"" . __('Submit!', 'yet-another-stars-rating') . " \" />";
493
- $button_html_disabled = '<input type="submit" disabled="disabled" class="button button-primary" id="yasr-send-visitor-multiset-disabled" disabled="disabled" value="'.__('Submit!', 'yet-another-stars-rating').'" >';
494
- $yasr_cookiename = 'yasr_multi_visitor_cookie';
495
-
496
- //Check cookie and if voting is allowed only to logged in users
497
- if (isset($_COOKIE[$yasr_cookiename])) {
498
-
499
- $cookie_data = stripslashes( $_COOKIE[ $yasr_cookiename ] );
500
-
501
- //By default, json_decode return an object, TRUE to return an array
502
- $cookie_data = json_decode($cookie_data, TRUE);
503
-
504
- if (is_array($cookie_data)) {
505
506
- foreach ($cookie_data as $value) {
507
- $cookie_post_id = (int)$value['post_id'];
508
- $cookie_set_id = (int)$value['set_id'];
509
510
- if ($cookie_post_id === $post_id && $cookie_set_id == $setid) {
511
- $button = "";
512
- $star_readonly = 'true';
513
- $span_message_content = __('Thank you for voting! ', 'yet-another-stars-rating');
514
515
- //Stop doing foreach, here we've found the rating for current post
516
- break;
517
518
- }
519
- else {
520
- $button = $button_html;
521
- $star_readonly = 'false';
522
- $span_message_content = "";
523
- }
524
525
- }
526
527
- }
528
529
- }
530
531
- else {
532
533
- //If user is not logged in
534
- if (!is_user_logged_in()) {
535
536
- if (YASR_ALLOWED_USER === 'allow_anonymous') {
537
$button = $button_html;
538
$star_readonly = 'false';
539
$span_message_content = "";
540
}
541
542
- elseif (YASR_ALLOWED_USER === 'logged_only') {
543
- $button = $button_html_disabled;
544
- $star_readonly = 'true';
545
- $span_message_content = "<span class=\"yasr-visitor-votes-must-sign-in\">" . __("You must sign in to vote", 'yet-another-stars-rating') . "</span>";
546
- }
547
-
548
- } //End if user logged in
549
-
550
- //User is logged in
551
- else {
552
$button = $button_html;
553
$star_readonly = 'false';
554
$span_message_content = "";
555
}
556
557
- }
558
-
559
- $set_name_content = yasr_get_multi_set_visitor ($post_id, $setid);
560
561
- $shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
562
- $shortcode_html.="<table class=\"yasr_table_multi_set_shortcode\">";
563
-
564
- if ($set_name_content) {
565
-
566
- $multiset_vote_sum = 0;//avoid undefined variable
567
- $multiset_rows_number = 0;//avoid undefined variable
568
-
569
- foreach ($set_name_content as $set_content) {
570
571
- if($set_content->number_of_votes > 0) {
572
- $average_rating = $set_content->sum_votes / $set_content->number_of_votes;
573
- $average_rating = round($average_rating, 1);
574
- }
575
576
- else {
577
- $average_rating = 0;
578
- }
579
580
- $unique_id_identifier = 'yasr-visitor-multi-set-' . $post_id . '_' . $setid . '_' . $set_content->id;
581
- $html_stars = "<div class=\"yasr-multiset-visitors-rater\" id=\"$unique_id_identifier\" data-rater-postid=\"$post_id\" data-rater-setid=\"$setid\" data-rater-set-field-id=\"$set_content->id\" data-rating=\"$average_rating\" data-rater-readonly=\"$star_readonly\" ></div>";
582
583
- $shortcode_html .= "<tr>
584
- <td>
585
- <span class=\"yasr-multi-set-name-field\">$set_content->name </span>
586
- </td>
587
- <td>
588
- $html_stars
589
- <span class=\"yasr-visitor-multiset-vote-count\">$set_content->number_of_votes</span>
590
- </td>
591
- </tr>";
592
593
- $multiset_vote_sum = $multiset_vote_sum + $average_rating;
594
- $multiset_rows_number++;
595
-
596
- } //End foreach
597
598
- $multiset_average = $multiset_vote_sum / $multiset_rows_number;
599
- $multiset_average = round($multiset_average, 1);
600
601
- }
602
603
- //if this post has no data....
604
- else {
605
606
- $set_name=$wpdb->get_results($wpdb->prepare("SELECT field_name AS name, field_id AS id
607
- FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
608
- WHERE parent_set_id=%d
609
- ORDER BY field_id ASC", $setid));
610
611
- foreach ($set_name as $set_content) {
612
613
- $unique_id_identifier = 'yasr-visitor-multi-set-' . $post_id . '_' . $setid . '_' . $set_content->id;
614
- $html_stars = "<div class=\"yasr-multiset-visitors-rater\" id=\"$unique_id_identifier\" data-rater-postid=\"$post_id\" data-rater-setid=\"$setid\" data-rater-set-field-id=\"$set_content->id\" data-rating=0 data-rater-readonly=\"$star_readonly\" ></div>";
615
616
- $shortcode_html .= "<tr>
617
- <td>
618
- <span class=\"yasr-multi-set-name-field\">$set_content->name </span>
619
- </td>
620
- <td>
621
- $html_stars
622
- <span class=\"yasr-visitor-multiset-vote-count\">0</span>
623
- </td>
624
- </tr>";
625
626
- } //end foreach ($set_name as $set_content)
627
628
- $multiset_average = 0;
629
630
- }
631
632
- //Show average row
633
- if ($show_average !== FALSE && $show_average !=='no'|| $show_average===FALSE && YASR_MULTI_SHOW_AVERAGE !== 'no') {
634
635
- $unique_id_identifier = 'yasr-visitor-multi-set-average' . $post_id . '_' . $setid;
636
637
- $shortcode_html .= "<tr>
638
- <td colspan=\"2\" class=\"yasr-multiset-average\">
639
- $average_txt<div class=\"yasr-multiset-visitors-rater\" id=\"$unique_id_identifier\" data-rater-postid=\"$post_id\" data-rater-setid=\"$setid\" data-rater-set-field-id=\"$set_content->id\" data-rating=\"$multiset_average\" data-rater-readonly=\"true\" ></div>
640
- </td>
641
- </tr>";
642
643
- }
644
645
- //Submit row and button
646
- $shortcode_html.="<tr>
647
- <td colspan=\"2\">
648
- $button
649
- $loader_html
650
- <span class=\"yasr-visitor-multiset-message\">$span_message_content</span>
651
</td>
652
- </tr>
653
- ";
654
655
- $shortcode_html.="</table>";
656
- $shortcode_html .= '<!-- End Yasr Multi Set Visitor Shortcode-->';
657
658
- wp_localize_script( 'yasrfront', "yasrMultiSetData", array(
659
- 'nonceVisitor' => $ajax_nonce_visitor_multiset,
660
- 'setType' => $setid
661
- )
662
- );
663
664
- return $shortcode_html;
665
666
}
667
@@ -670,333 +653,337 @@ add_shortcode ('yasr_visitor_multiset', 'yasr_visitor_multiset_callback');
670
671
add_shortcode ('yasr_top_ten_highest_rated', 'yasr_top_ten_highest_rated_callback');
672
673
- function yasr_top_ten_highest_rated_callback () {
674
-
675
- global $wpdb;
676
-
677
- $query_result = $wpdb->get_results("SELECT pm.meta_value AS overall_rating, pm.post_id AS post_id
678
- FROM $wpdb->postmeta AS pm, $wpdb->posts AS p
679
- WHERE pm.post_id = p.ID
680
- AND p.post_status = 'publish'
681
- AND pm.meta_key = 'yasr_overall_rating'
682
- ORDER BY pm.meta_value DESC, pm.post_id ASC LIMIT 10");
683
684
685
- $shortcode_html = '<!-- Yasr Top 10 highest Rated Shortcode-->';
686
687
- if ($query_result) {
688
689
- $shortcode_html .= "<table class=\"yasr-table-chart\">";
690
691
- foreach ($query_result as $result) {
692
693
- $post_title = get_the_title($result->post_id);
694
- $link = get_permalink($result->post_id); //Get permalink from post it
695
696
- $yasr_top_ten_html_id = 'yasr-top-ten-rater-' . $result->post_id;
697
- $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\" data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\" data-rating=\"$result->overall_rating\"></div>";
698
699
700
- $shortcode_html .= "<tr>
701
- <td width=\"60%\" class=\"yasr-top-10-overall-left\"><a href=\"$link\">$post_title</a></td>
702
- <td width=\"40%\" class=\"yasr-top-10-overall-right\">
703
- $html_stars
704
- <span class=\"yasr-highest-rated-text\">" . __("Rating", 'yet-another-stars-rating') . " $result->overall_rating </span>
705
- </td>
706
- </tr>";
707
708
709
- } //End foreach
710
711
- $shortcode_html .= "</table>";
712
713
- $shortcode_html .= '<!--End Yasr Top 10 highest Rated Shortcode-->';
714
715
- return $shortcode_html;
716
717
- } //end if $query_result
718
719
- else {
720
- _e("You don't have any votes stored", 'yet-another-stars-rating');
721
- }
722
723
- } //End function
724
725
726
/****** Add top 10 most rated / highest rated post *****/
727
728
add_shortcode ('yasr_most_or_highest_rated_posts', 'yasr_most_or_highest_rated_posts_callback');
729
730
- function yasr_most_or_highest_rated_posts_callback () {
731
-
732
- $shortcode_html = '<!-- Yasr Most Or Highest Rated Shortcode-->';
733
734
- global $wpdb;
735
-
736
- $query_result_most_rated = $wpdb->get_results ("SELECT post_id, COUNT(post_id) AS number_of_votes, SUM(vote) AS sum_votes
737
- FROM " . YASR_LOG_TABLE . " , $wpdb->posts AS p
738
- WHERE post_id = p.ID
739
- AND p.post_status = 'publish'
740
- GROUP BY post_id
741
- HAVING number_of_votes > 1
742
- ORDER BY number_of_votes DESC, post_id ASC
743
- LIMIT 10
744
- ");
745
746
747
- //count run twice but access data only once: tested with query monitor and asked
748
- //here http://stackoverflow.com/questions/39201235/does-count-run-twice/39201492
749
- $query_result_highest = $wpdb->get_results ("SELECT post_id, COUNT(post_id) AS number_of_votes, (SUM(vote) / COUNT(post_id)) AS result
750
- FROM " . YASR_LOG_TABLE . " , $wpdb->posts AS p
751
- WHERE post_id = p.ID
752
- AND p.post_status = 'publish'
753
- GROUP BY post_id
754
- HAVING COUNT(post_id) >= 2
755
- ORDER BY result DESC, number_of_votes DESC
756
- LIMIT 10
757
- ");
758
759
- if ($query_result_most_rated) {
760
761
- $shortcode_html .= "<table class=\"yasr-table-chart\" id=\"yasr-most-rated-posts\">
762
- <tr class=\"yasr-visitor-votes-title\">
763
- <th>" . __("Post / Page" , 'yet-another-stars-rating') ." </th>
764
- <th>". __("Order By" , 'yet-another-stars-rating') .":&nbsp;&nbsp;
765
- <span id=\"yasr_multi_chart_link_to_nothing\">" . __("Most Rated" , 'yet-another-stars-rating') ."</span> |
766
- <span id=\"link-yasr-highest-rated-posts\"><a href=\"\" onclick='yasrShowHighest(); return false'>" . __("Highest Rated" , 'yet-another-stars-rating') ."</a></span>
767
- </th>
768
- </tr>"
769
- ;
770
771
- foreach ($query_result_most_rated as $result) {
772
773
- $rating = $result->sum_votes / $result->number_of_votes;
774
775
- $rating = round($rating, 1);
776
777
- $post_title = get_the_title($result->post_id);
778
779
- $link = get_permalink($result->post_id); //Get permalink from post it
780
781
- $yasr_top_ten_html_id = 'yasr-10-most-rater' . $result->post_id;
782
- $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\" data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\" data-rating=\"$rating\"></div>";
783
784
- $shortcode_html .= "<tr>
785
- <td width=\"60%\" class=\"yasr-top-10-most-highest-left\"><a href=\"$link\">$post_title</a></td>
786
- <td width=\"40%\" class=\"yasr-top-10-most-highest-right\">
787
- $html_stars
788
- <br /> [" . __( "Total:", 'yet-another-stars-rating' ) . "$result->number_of_votes &nbsp;&nbsp;&nbsp;" . __( "Average", 'yet-another-stars-rating' ) . " $rating]
789
- </td>
790
- </tr>";
791
792
- } //End foreach
793
794
- $shortcode_html .= "</table>" ;
795
796
- } //End if $query_result_most_rated)
797
798
- else {
799
- $shortcode_html = __("You've not enough data",'yet-another-stars-rating') . "<br />";
800
- }
801
802
803
- if ($query_result_highest) {
804
805
- $shortcode_html .= "<table class=\"yasr-table-chart\" id=\"yasr-highest-rated-posts\">
806
- <tr class=\"yasr-visitor-votes-title\">
807
- <th>" . __("Post / Page" , 'yet-another-stars-rating') ." </th>
808
- <th>". __("Order By" , 'yet-another-stars-rating') .":&nbsp;&nbsp;
809
- <span id=\"link-yasr-most-rated-posts\"><a href=\"\" onclick='yasrShowMost(); return false'>". __("Most Rated" , 'yet-another-stars-rating') . "</a> |
810
- <span id=\"yasr_multi_chart_link_to_nothing\">". __("Highest Rated" , 'yet-another-stars-rating') ."</span>
811
- </th>
812
- </tr>";
813
814
- foreach ($query_result_highest as $result) {
815
816
- $rating = round($result->result, 1);
817
818
- $post_title = get_the_title($result->post_id);
819
820
- $link = get_permalink($result->post_id); //Get permalink from post it
821
822
- $yasr_top_ten_html_id = 'yasr-10-highest-rater-' . $result->post_id;
823
- $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\" data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\" data-rating=\"$rating\"></div>";
824
825
- $shortcode_html .= "<tr>
826
- <td width=\"60%\" class=\"yasr-top-10-most-highest-left\"><a href=\"$link\">$post_title</a></td>
827
- <td width=\"40%\" class=\"yasr-top-10-most-highest-right\">
828
- $html_stars
829
- <br /> [" . __("Total:" , 'yet-another-stars-rating') . "$result->number_of_votes &nbsp;&nbsp;&nbsp;" . __("Average" , 'yet-another-stars-rating') . " $rating]
830
- </td>
831
- </tr>";
832
833
834
- } //End foreach
835
836
- $shortcode_html .= "</table>";
837
838
- } //end if $query_result
839
840
- else {
841
- $shortcode_html = __("You've not enought data",'yet-another-stars-rating') . "<br />";
842
- }
843
844
- $shortcode_html .= '<!-- End Yasr Most Or Highest Rated Shortcode-->';
845
846
- wp_localize_script( 'yasrfront', "yasrMostHighestRanking", array(
847
- 'enable' => 'yes'
848
- )
849
- );
850
851
- return $shortcode_html;
852
853
854
- } //End function
855
856
857
/****** Add top 5 most active reviewer ******/
858
859
add_shortcode ('yasr_top_5_reviewers', 'yasr_top_5_reviewers_callback');
860
861
- function yasr_top_5_reviewers_callback () {
862
863
- global $wpdb;
864
865
- $query_result = $wpdb->get_results("SELECT COUNT( pm.post_id ) AS total_count, p.post_author AS reviewer
866
- FROM $wpdb->posts AS p, $wpdb->postmeta AS pm
867
- WHERE pm.post_id = p.ID
868
- AND pm.meta_key = 'yasr_overall_rating'
869
- AND p.post_status = 'publish'
870
- GROUP BY reviewer
871
- ORDER BY (total_count) DESC
872
- LIMIT 5");
873
874
875
- if ($query_result) {
876
877
- $shortcode_html = '
878
- <!-- Yasr Top 5 Reviewers Shortcode-->
879
- ';
880
881
- $shortcode_html .= "
882
- <table class=\"yasr-table-chart\">
883
- <tr>
884
- <th>Author</th>
885
- <th>Reviews</th>
886
- </tr>
887
- ";
888
889
- foreach ($query_result as $result) {
890
891
- $user_data = get_userdata($result->reviewer);
892
893
- if ($user_data) {
894
895
- $user_profile = get_author_posts_url($result->reviewer);
896
897
- }
898
899
- else {
900
901
- $user_profile = '#';
902
- $user_data = new stdClass;
903
- $user_data->user_login = 'Anonymous';
904
905
- }
906
907
908
- $shortcode_html .= "<tr>
909
- <td><a href=\"$user_profile\">$user_data->user_login</a></td>
910
- <td>$result->total_count</td>
911
- </tr>";
912
913
- }
914
915
- $shortcode_html .= "</table>";
916
917
- $shortcode_html .= '
918
- <!-- End Yasr Top 5 Reviewers Shortcode-->
919
- ';
920
921
- return $shortcode_html;
922
923
- }
924
925
- else {
926
927
- _e("Problem while retrieving the top 5 most active reviewers. Did you publish any review?");
928
929
- }
930
931
- } //End top 5 reviewers function
932
933
934
/****** Add top 10 most active user *****/
935
936
add_shortcode ('yasr_top_ten_active_users', 'yasr_top_ten_active_users_callback');
937
938
- function yasr_top_ten_active_users_callback () {
939
940
- global $wpdb;
941
942
- $query_result = $wpdb->get_results("SELECT COUNT( user_id ) as total_count, user_id as user
943
- FROM " . YASR_LOG_TABLE . ", $wpdb->posts AS p
944
- WHERE post_id = p.ID
945
- AND p.post_status = 'publish'
946
- GROUP BY user_id
947
- ORDER BY ( total_count ) DESC
948
- LIMIT 10");
949
950
- if ($query_result) {
951
952
- $shortcode_html = '<!-- Yasr Top 10 Active Users Shortcode-->';
953
954
- $shortcode_html .= "
955
- <table class=\"yasr-table-chart\">
956
- <tr>
957
- <th>UserName</th>
958
- <th>Number of votes</th>
959
- </tr>
960
- ";
961
962
- foreach ($query_result as $result) {
963
964
- $user_data = get_userdata($result->user);
965
966
- if ($user_data) {
967
968
- $user_profile = get_author_posts_url($result->user);
969
970
- }
971
972
- else {
973
- $user_profile = '#';
974
- $user_data = new stdClass;
975
- $user_data->user_login = 'Anonymous';
976
- }
977
978
- $shortcode_html .= "<tr>
979
- <td><a href=\"$user_profile\">$user_data->user_login</a></td>
980
- <td>$result->total_count</td>
981
- </tr>";
982
983
- }
984
985
986
- $shortcode_html .= "</table>";
987
988
- $shortcode_html .= '<!--End Yasr Top 10 Active Users Shortcode-->';
989
990
- return $shortcode_html;
991
992
- }
993
994
- else {
995
- _e("Problem while retrieving the top 10 active users chart. Are you sure you have votes to show?");
996
- }
997
998
999
- } //End function
1000
1001
1002
//this shortcode is in the plugin but not ready to use yet.
@@ -1014,7 +1001,7 @@ function yasr_highest_rated_visitor_multi_set_callback ($atts) {
1014
), $atts )
1015
);
1016
1017
- $set_fields = FALSE;
1018
$shortcode_html = '';
1019
1020
$set_fields=$wpdb->get_results($wpdb->prepare("SELECT v.post_id, v.sum_votes / v.number_of_votes AS average, v.number_of_votes, f.field_name
@@ -1027,7 +1014,6 @@ function yasr_highest_rated_visitor_multi_set_callback ($atts) {
1027
ORDER BY f.parent_set_id ASC, f.field_id ASC, v.post_id ASC", $setid));
1028
1029
if ($set_fields) {
1030
-
1031
$shortcode_html = "
1032
<table class=\"yasr-table-chart\">";
1033
@@ -1049,7 +1035,10 @@ function yasr_highest_rated_visitor_multi_set_callback ($atts) {
1049
<a href=\"$link\">$title</a>
1050
</td>
1051
<td>
1052
- <div class=\"rateit medium\" data-rateit-starwidth=\"24\" data-rateit-starheight=\"24\" data-rateit-value=\"$average\" data-rateit-step=\"0.1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\"></div>
1053
$average" . sprintf(__(' based on %d votes', 'yet-another-stars-rating'), $results->number_of_votes); "
1054
</td>
1055
</tr>";
@@ -1063,9 +1052,7 @@ function yasr_highest_rated_visitor_multi_set_callback ($atts) {
1063
}
1064
1065
else {
1066
-
1067
_e("No results, try a different setid", "yet-another-stars-rating");
1068
-
1069
}
1070
1071
return $shortcode_html;
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
/****** Add shortcode for overall rating ******/
26
+ add_shortcode('yasr_overall_rating', 'shortcode_overall_rating_callback');
27
28
+ function shortcode_overall_rating_callback ($atts) {
29
30
+ if (YASR_SHOW_OVERALL_IN_LOOP === 'disabled' && !is_singular() && is_main_query()) {
31
+ return null;
32
+ }
33
34
+ $atts = shortcode_atts(
35
+ array(
36
+ 'size' => 'large',
37
+ 'postid' => false
38
+ ),
39
+ $atts,
40
+ 'yasr_overall_rating'
41
+ );
42
43
+ $size = $atts['size'];
44
+ $postid = $atts['postid'];
45
46
+ if ($postid === false) {
47
+ $postid = get_the_ID();
48
+ }
49
50
+ $overall_rating = yasr_get_overall_rating($postid);
51
52
+ //if still false
53
+ if (!$overall_rating) {
54
+ $overall_rating = "-1";
55
+ }
56
57
+ $shortcode_html = '<!--Yasr Overall Rating Shortcode-->';
58
59
+ $stars_attribute = yasr_stars_size($size);
60
61
+ //generate an unique id to be sure that every element has a different ID
62
+ $unique_id = str_shuffle(uniqid());
63
64
+ $overall_rating_html_id = 'yasr-overall-rating-rater-' . $unique_id;
65
+ $html_stars = "<div class='yasr-overall-rating'>
66
+ <div class=\"yasr-rater-stars\" id=\"$overall_rating_html_id\" data-rating=\"$overall_rating\" data-rater-starsize=\"$stars_attribute[px_size]\" ></div>
67
+ </div>
68
+ ";
69
70
+ if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_BEFORE_OVERALL != '') {
71
+ $text_before_star = str_replace('%overall_rating%', $overall_rating, YASR_TEXT_BEFORE_OVERALL);
72
+ $shortcode_html = "<div class=\"yasr-container-custom-text-and-overall\">
73
+ <span id=\"yasr-custom-text-before-overall\">" . $text_before_star . "</span>
74
+ $html_stars
75
+ </div>";
76
+ } else {
77
+ $shortcode_html .= $html_stars;
78
+ }
79
80
+ $shortcode_html .= '<!--End Yasr Overall Rating Shortcode-->';
81
82
+ //If overall rating in loop is enabled don't use is_singular && is main_query
83
+ if (YASR_SHOW_OVERALL_IN_LOOP === 'enabled') {
84
+ return $shortcode_html;
85
+ }
86
87
+ //default
88
+ else {
89
+ if (is_singular() && is_main_query()) {
90
+ return $shortcode_html;
91
+ }
92
+ }
93
94
+ return null;
95
+ } //end function
96
97
98
/****** Add shortcode for user vote ******/
99
100
add_shortcode ('yasr_visitor_votes', 'shortcode_visitor_votes_callback');
101
102
+ function shortcode_visitor_votes_callback($atts) {
103
104
+ if (YASR_SHOW_OVERALL_IN_LOOP === 'disabled' && !is_singular() && is_main_query()) {
105
+ return null;
106
+ }
107
108
+ $shortcode_html = null; //Avoid undefined variable outside is_singular && is_main_query
109
110
+ $atts = shortcode_atts(
111
+ array(
112
+ 'size' => 'large',
113
+ 'postid' => false,
114
+ 'readonly' => false
115
+ ),
116
+ $atts,
117
+ 'yasr_visitor_votes'
118
+ );
119
120
121
+ $size = $atts['size'];
122
+ $post_id = $atts['postid'];
123
+ $readonly = $atts['readonly'];
124
125
+ //If it's not specified use get_the_id
126
+ if ($post_id === false) {
127
+ $post_id = get_the_ID();
128
+ }
129
130
+ $votes=yasr_get_visitor_votes($post_id); //always reference it
131
132
+ $unique_id = str_shuffle(uniqid());
133
134
+ $medium_rating=0; //Avoid undefined variable
135
136
+ if (!$votes) {
137
+ $votes = null; //Avoid undefined variable if there is not rating
138
+ $votes_number=0; //Avoid undefined variable
139
+ } else {
140
+ foreach ($votes as $user_votes) {
141
+ $votes_number = $user_votes->number_of_votes;
142
143
+ if ($votes_number != 0) {
144
+ $medium_rating = ($user_votes->sum_votes/$votes_number);
145
+ } else {
146
+ $medium_rating = 0;
147
+ }
148
}
149
+ }
150
151
+ $medium_rating=round($medium_rating, 1);
152
153
+ $stars_attribute = yasr_stars_size($size);
154
155
+ if (is_singular()) {
156
+ $is_singular = 'true';
157
+ } else {
158
+ $is_singular = 'false';
159
+ }
160
161
+ //if this come from yasr_visitor_votes_readonly...
162
+ if ($readonly === true || $readonly === "yes") {
163
+ $htmlid = 'yasr-visitor-votes-readonly-rater-'.$unique_id;
164
165
+ $shortcode_html = "<div class=\"yasr-rater-stars-visitor-votes\" id=\"$htmlid\" data-rating=\"$medium_rating\"
166
+ data-rater-starsize=\"$stars_attribute[px_size]\" data-rater-postid=\"$post_id\"
167
+ data-rater-readonly=\"true\"></div>";
168
169
+ return $shortcode_html;
170
+ }
171
172
+ $ajax_nonce_visitor = wp_create_nonce("yasr_nonce_insert_visitor_rating");
173
174
+ //name of cookie to check
175
+ $yasr_cookiename = 'yasr_visitor_vote_cookie';
176
177
+ $cookie_value = false; //avoid undefined
178
179
+ if (isset($_COOKIE[$yasr_cookiename])) {
180
+ $cookie_data = stripslashes($_COOKIE[$yasr_cookiename]);
181
182
+ //By default, json_decode return an object, true to return an array
183
+ $cookie_data = json_decode($cookie_data, true);
184
185
+ if (is_array($cookie_data)) {
186
+ foreach ($cookie_data as $value) {
187
+ $cookie_post_id = (int)$value['post_id'];
188
189
+ if ($cookie_post_id === $post_id) {
190
+ $cookie_value = (int)$value['rating'];
191
+ //Stop doing foreach, here we've found the rating for current post
192
+ break;
193
}
194
}
195
}
196
197
+ if ($cookie_value !== false && $cookie_value > 5) {
198
+ $cookie_value = 5;
199
+ } elseif ($cookie_value !== false && $cookie_value < 1) {
200
+ $cookie_value = 1;
201
+ }
202
203
+ }
204
205
206
+ $shortcode_html = '<!--Yasr Visitor Votes Shortcode-->';
207
+ $shortcode_html .= "<div id=\"yasr_visitor_votes_$post_id\" class=\"yasr-visitor-votes\">";
208
+ $span_bottom_line = "";
209
210
+ //I've to check a logged in user that has already rated
211
+ if (is_user_logged_in()) {
212
+ $readonly = 'false'; //Always false if user is logged in
213
214
+ //Check if a logged in user has already rated for this post
215
+ $vote_if_user_already_rated = yasr_check_if_user_already_voted($post_id);
216
217
+ //If user has already rated
218
+ if ($vote_if_user_already_rated) {
219
+ $span_bottom_line="<span class=\"yasr-small-block-bold yasr-already-voted-text \"
220
+ id=\"yasr-user-vote-$post_id\" data-yasr-already-voted=\"$vote_if_user_already_rated\">"
221
+ . __("You've already voted this article with", 'yet-another-stars-rating') .
222
+ " $vote_if_user_already_rated</span>";
223
+ }
224
225
+ } //End if user is logged
226
+
227
+ //if anonymous are allowed to vote
228
+ if (YASR_ALLOWED_USER === 'allow_anonymous') {
229
+ //IF user is not logged in
230
+ if (!is_user_logged_in()) {
231
+ //if cookie exists
232
+ if ($cookie_value) {
233
+ $readonly = 'true';
234
+ if (YASR_TEXT_BEFORE_STARS == 1 && YASR_CUSTOM_TEXT_USER_VOTED!='') {
235
+ $span_bottom_line="<span class=\"yasr-small-block-bold yasr-already-voted-text\">"
236
+ . YASR_CUSTOM_TEXT_USER_VOTED .
237
+ " </span>";
238
+ } else {
239
+ $span_bottom_line="<span class=\"yasr-small-block-bold yasr-already-voted-text \">"
240
+ . __("You've already voted this article with", 'yet-another-stars-rating') .
241
+ " $cookie_value</span>";
242
}
243
+ } else {
244
+ $readonly = 'false';
245
}
246
}
247
+ } //end if YASR_ALLOWED_USER === 'allow_anonymous' {
248
249
250
+ //If only logged in users can vote
251
+ elseif (YASR_ALLOWED_USER === 'logged_only') {
252
+ //IF user is not logged in
253
+ if (!is_user_logged_in()) {
254
+ $readonly = 'true'; //readonly is true if user isn't logged
255
+ $span_bottom_line = "<span class=\"yasr-visitor-votes-must-sign-in\">"
256
+ . __("You must sign in to vote", 'yet-another-stars-rating').
257
+ "</span>";
258
}
259
260
+ }
261
262
+ if (YASR_VISITORS_STATS === 'yes') {
263
+ $span_dashicon = "<span class=\"dashicons dashicons-chart-bar yasr-dashicons-visitor-stats \"
264
+ data-postid=\"$post_id\" id=\"yasr-total-average-dashicon-$post_id\"></span>";
265
+ } else {
266
+ $span_dashicon = "";
267
+ }
268
269
270
+ if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_BEFORE_VISITOR_RATING != '') {
271
+ $text_before_star = str_replace('%total_count%', $votes_number, YASR_TEXT_BEFORE_VISITOR_RATING);
272
+ $text_before_star = str_replace('%average%', $medium_rating, $text_before_star);
273
+ $shortcode_html .= "<div class=\"yasr-container-custom-text-and-visitor-rating\">
274
+ <span id=\"yasr-custom-text-before-visitor-rating\">" . $text_before_star . "</span></div>";
275
+ }
276
277
+ if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_AFTER_VISITOR_RATING != '') {
278
+ $text_after_star = str_replace('%total_count%', $votes_number, YASR_TEXT_AFTER_VISITOR_RATING);
279
+ $text_after_star = str_replace('%average%', $medium_rating, $text_after_star);
280
+ $span_text_after_star = "<span class=\"yasr-total-average-container\" id=\"yasr-total-average-text_$post_id\">"
281
+ . $text_after_star .
282
+ "</span>";
283
+ } else {
284
+ $span_text_after_star = "<span class=\"yasr-total-average-container\" id=\"yasr-total-average-text_$post_id\">
285
+ [" . __("Total: ", 'yet-another-stars-rating') . "$votes_number &nbsp; &nbsp;" .
286
+ __("Average: ",'yet-another-stars-rating') . "$medium_rating/5]
287
+ </span>";
288
+ }
289
290
+ $span_container_after_stars = "<span id=\"yasr-visitor-votes-container-after-stars-$unique_id\"
291
+ class='yasr-visitor-votes-after-stars-class'>";
292
293
+ $htmlid = 'yasr-visitor-votes-rater-' . $unique_id ;
294
295
+ $shortcode_html .= "<div id=\"$htmlid\" class=\"yasr-rater-stars-visitor-votes\" data-rater-postid=\"$post_id\"
296
+ data-rating=\"$medium_rating\" data-rater-starsize=\"$stars_attribute[px_size]\"
297
+ data-rater-readonly=\"$readonly\" data-rater-nonce=\"$ajax_nonce_visitor\" data-issingular=\"$is_singular\">
298
+ </div>";
299
300
+ $shortcode_html .= $span_container_after_stars;
301
+ $shortcode_html .= $span_dashicon;
302
+ $shortcode_html .= $span_text_after_star;
303
+ $shortcode_html .= $span_bottom_line;
304
+ $shortcode_html .= '</span>'; //Close yasr-visitor-votes-after-stars and yasr_visitor_votes
305
+ $shortcode_html .= '</div>'; //close all
306
+ $shortcode_html .= '<!--End Yasr Visitor Votes Shortcode-->';
307
308
+ //If overall rating in loop is enabled don't use is_singular && is main_query
309
+ if (YASR_SHOW_VISITOR_VOTES_IN_LOOP === 'enabled') {
310
+ return $shortcode_html;
311
+ }
312
313
+ //default value
314
+ else {
315
+ if (is_singular() && is_main_query()) {
316
return $shortcode_html;
317
}
318
+ }
319
320
+ return null;
321
322
+ } //End function shortcode_visitor_votes_callback
323
324
325
/*
327
*/
328
add_shortcode ('yasr_visitor_votes_readonly', 'yasr_visitor_votes_readonly_callback');
329
330
+ function yasr_visitor_votes_readonly_callback ($atts) {
331
332
+ $atts['readonly'] = true;
333
334
+ //Here I call the same function that draw the same function for yasr_visitor_votes,
335
+ //passing the attribute readonly = true
336
+ $shortcode_html = shortcode_visitor_votes_callback($atts);
337
338
+ return $shortcode_html;
339
340
+ } //End function shortcode_visitor_votes_only_stars_callback
341
342
343
/****** Add shortcode for multiple set ******/
344
345
add_shortcode ('yasr_multiset', 'shortcode_multi_set_callback');
346
347
+ function shortcode_multi_set_callback($atts) {
348
349
+ global $wpdb;
350
351
+ // Attributes
352
+ $atts = shortcode_atts(
353
+ array(
354
+ 'setid' => '0',
355
+ 'postid' => false,
356
+ 'show_average' => false
357
+ ),
358
+ $atts,
359
+ 'yasr_multiset'
360
+ );
361
362
+ $post_id = $atts['postid'];
363
+ $setid = $atts['setid'];
364
+ $show_average = $atts['show_average'];
365
366
+ //If it's not specified use get_the_id
367
+ if (!$post_id) {
368
+ $post_id = get_the_ID();
369
+ }
370
371
+ $shortcode_html = '<!-- Yasr Multi Set Shortcode-->';
372
373
+ $multiset_vote_sum = 0;
374
+ $multiset_rows_number = 0; //
375
376
+ $set_name_content = yasr_get_multi_set_values_and_field($post_id, $setid);
377
378
+ if (!$set_name_content) {
379
380
+ $set_name_content=$wpdb->get_results($wpdb->prepare("SELECT field_name AS name, field_id AS id
381
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
382
+ WHERE parent_set_id=%d
383
+ ORDER BY field_id ASC", $setid));
384
385
+ //if it still to be empty (e.g. wrong id passed)
386
+ if (!$set_name_content) {
387
+ return $shortcode_html;
388
}
389
390
+ }
391
392
+ $shortcode_html.="<table class=\"yasr_table_multi_set_shortcode\">";
393
394
+ //this is to avoid undefined, may happens when an user inser
395
+ //the shortcode without insert vote (only happens if more than 1 multiset are used)
396
397
+ $set_content = new stdClass();
398
+ $set_content->vote = null; //avoid undefined
399
400
+ foreach ($set_name_content as $set_content) {
401
+ //Avoid undefined if vote does not exists
402
+ if (!isset($set_content->vote)) {
403
+ $set_content->vote = 0;
404
+ }
405
406
+ $shortcode_html .= "<tr><td><span class=\"yasr-multi-set-name-field\">$set_content->name </span></td>";
407
408
+ $unique_id_identifier = $post_id . '_' . $setid . '_' . $set_content->id;
409
410
+ $shortcode_html .= "<td><div class=\"yasr-rater-stars\" id=\"yasr-rater-multiset-$unique_id_identifier\" data-rater-postid=\"$post_id\" data-rating=\"$set_content->vote\" data-rater-starsize=\"16\"></div></td>
411
+ </tr>";
412
413
+ $multiset_vote_sum = $multiset_vote_sum + $set_content->vote;
414
+ $multiset_rows_number++;
415
416
+ }
417
418
+ if ($show_average !== false && $show_average !=='no' || $show_average === false && YASR_MULTI_SHOW_AVERAGE !== 'no') {
419
+ $multiset_average = $multiset_vote_sum / $multiset_rows_number;
420
+ $multiset_average = round($multiset_average, 1);
421
422
+ $average_txt = __("Average", "yet-another-stars-rating");
423
424
+ $average_unique_id_identifier = 'yasr-multiset-average_' . $post_id . '_' . $setid;
425
426
+ $shortcode_html .= "<tr>
427
+ <td colspan='2' class='yasr-multiset-average'>
428
+ <span class='yasr-multiset-average-text'>$average_txt</span>
429
+ <div class='yasr-rater-stars' id=\"$average_unique_id_identifier\"
430
+ data-rater-postid=\"$post_id\" data-rating=\"$multiset_average\"
431
+ data-rater-starsize=\"24\"></div>
432
+ </td>
433
+ </tr>";
434
435
436
+ }
437
438
+ $shortcode_html.="</table>";
439
440
+ $shortcode_html .= '<!--End Yasr Multi Set Shortcode-->';
441
442
+ return $shortcode_html;
443
444
+ } //End function
445
446
447
/****** Add shortcode for multiset writable by users ******/
448
449
add_shortcode ('yasr_visitor_multiset', 'yasr_visitor_multiset_callback');
450
451
+ function yasr_visitor_multiset_callback($atts) {
452
453
+ $ajax_nonce_visitor_multiset = wp_create_nonce( "yasr_nonce_insert_visitor_rating_multiset" );
454
455
+ global $wpdb;
456
457
+ // Attributes
458
+ $atts = shortcode_atts(
459
+ array(
460
+ 'setid' => '0',
461
+ 'postid' => false,
462
+ 'show_average' => false
463
+ ),
464
+ $atts,
465
+ 'yasr_multiset'
466
+ );
467
468
+ $post_id = $atts['postid'];
469
+ $setid = $atts['setid'];
470
+ $show_average = $atts['show_average'];
471
472
+ //If it's not specified use get_the_id
473
+ if (!$post_id) {
474
+ $post_id = get_the_ID();
475
+ }
476
477
478
+ $image = YASR_IMG_DIR . "/loader.gif";
479
+ $average_txt = __("Average", "yet-another-stars-rating");
480
+ $loader_html = "<span class=\"yasr-loader-multiset-visitor\" id=\"yasr-loader-multiset-visitor-$post_id-$setid\" >&nbsp; " . ' <img src=' . "$image" .' title="yasr-loader" alt="yasr-loader"></span>';
481
+ $button_html = "<input type=\"submit\" name=\"submit\" id=\"yasr-send-visitor-multiset-$post_id-$setid\" class=\"button button-primary yasr-send-visitor-multiset\" data-postid=\"$post_id\" data-setid=\"$setid\" value=\"" . __('Submit!', 'yet-another-stars-rating') . " \" />";
482
+ $button_html_disabled = '<input type="submit" disabled="disabled" class="button button-primary" id="yasr-send-visitor-multiset-disabled" disabled="disabled" value="'.__('Submit!', 'yet-another-stars-rating').'" >';
483
+ $yasr_cookiename = 'yasr_multi_visitor_cookie';
484
485
+ //Check cookie and if voting is allowed only to logged in users
486
+ if (isset($_COOKIE[$yasr_cookiename])) {
487
+ $cookie_data = stripslashes($_COOKIE[ $yasr_cookiename ]);
488
489
+ //By default, json_decode return an object, true to return an array
490
+ $cookie_data = json_decode($cookie_data, true);
491
492
+ if (is_array($cookie_data)) {
493
+ foreach ($cookie_data as $value) {
494
+ $cookie_post_id = (int)$value['post_id'];
495
+ $cookie_set_id = (int)$value['set_id'];
496
497
+ if ($cookie_post_id === $post_id && $cookie_set_id == $setid) {
498
+ $button = "";
499
+ $star_readonly = 'true';
500
+ $span_message_content = __('Thank you for voting! ', 'yet-another-stars-rating');
501
502
+ //Stop doing foreach, here we've found the rating for current post
503
+ break;
504
+ } else {
505
$button = $button_html;
506
$star_readonly = 'false';
507
$span_message_content = "";
508
}
509
+ }
510
+ }
511
+ }
512
513
+ else {
514
+ //If user is not logged in
515
+ if (!is_user_logged_in()) {
516
+ if (YASR_ALLOWED_USER === 'allow_anonymous') {
517
$button = $button_html;
518
$star_readonly = 'false';
519
$span_message_content = "";
520
+ } elseif (YASR_ALLOWED_USER === 'logged_only') {
521
+ $button = $button_html_disabled;
522
+ $star_readonly = 'true';
523
+ $span_message_content = "<span class=\"yasr-visitor-votes-must-sign-in\">"
524
+ . __("You must sign in to vote", 'yet-another-stars-rating') . "</span>";
525
}
526
527
+ } //End if user logged in
528
529
+ //User is logged in
530
+ else {
531
+ $button = $button_html;
532
+ $star_readonly = 'false';
533
+ $span_message_content = "";
534
+ }
535
536
+ }
537
538
+ $set_name_content = yasr_get_multi_set_visitor ($post_id, $setid);
539
540
+ $shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
541
+ $shortcode_html.="<table class=\"yasr_table_multi_set_shortcode\">";
542
543
+ if ($set_name_content) {
544
+ $multiset_vote_sum = 0;//avoid undefined variable
545
+ $multiset_rows_number = 0;//avoid undefined variable
546
547
+ foreach ($set_name_content as $set_content) {
548
+ if ($set_content->number_of_votes > 0) {
549
+ $average_rating = $set_content->sum_votes / $set_content->number_of_votes;
550
+ $average_rating = round($average_rating, 1);
551
+ } else {
552
+ $average_rating = 0;
553
+ }
554
555
+ $unique_id_identifier = 'yasr-visitor-multi-set-' . $post_id . '_' . $setid . '_' . $set_content->id;
556
+ $html_stars = "<div class=\"yasr-multiset-visitors-rater\" id=\"$unique_id_identifier\"
557
+ data-rater-postid=\"$post_id\" data-rater-setid=\"$setid\" data-rater-set-field-id=\"$set_content->id\"
558
+ data-rating=\"$average_rating\" data-rater-readonly=\"$star_readonly\" ></div>";
559
560
+ $shortcode_html .="<tr>
561
+ <td>
562
+ <span class=\"yasr-multi-set-name-field\">$set_content->name </span>
563
+ </td>
564
+ <td>
565
+ $html_stars
566
+ <span class=\"yasr-visitor-multiset-vote-count\">$set_content->number_of_votes</span>
567
+ </td>
568
+ </tr>";
569
570
+ $multiset_vote_sum = $multiset_vote_sum + $average_rating;
571
+ $multiset_rows_number++;
572
573
+ } //End foreach
574
575
+ $multiset_average = $multiset_vote_sum / $multiset_rows_number;
576
+ $multiset_average = round($multiset_average, 1);
577
578
+ }
579
580
+ //if this post has no data....
581
+ else {
582
583
+ $set_name=$wpdb->get_results($wpdb->prepare("SELECT field_name AS name, field_id AS id
584
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
585
+ WHERE parent_set_id=%d
586
+ ORDER BY field_id ASC", $setid));
587
588
+ foreach ($set_name as $set_content) {
589
+ $unique_id_identifier = 'yasr-visitor-multi-set-' . $post_id . '_' . $setid . '_' . $set_content->id;
590
+ $html_stars = "<div class=\"yasr-multiset-visitors-rater\" id=\"$unique_id_identifier\"
591
+ data-rater-postid=\"$post_id\" data-rater-setid=\"$setid\" data-rater-set-field-id=\"$set_content->id\"
592
+ data-rating=0 data-rater-readonly=\"$star_readonly\" ></div>";
593
594
+ $shortcode_html .= "<tr>
595
+ <td>
596
+ <span class=\"yasr-multi-set-name-field\">$set_content->name </span>
597
+ </td>
598
+ <td>
599
+ $html_stars
600
+ <span class=\"yasr-visitor-multiset-vote-count\">0</span>
601
+ </td>
602
+ </tr>";
603
604
+ } //end foreach ($set_name as $set_content)
605
606
+ $multiset_average = 0;
607
608
+ }
609
610
+ //Show average row
611
+ if ($show_average !== false && $show_average !=='no'|| $show_average===false && YASR_MULTI_SHOW_AVERAGE !== 'no') {
612
+ $unique_id_identifier = 'yasr-visitor-multi-set-average' . $post_id . '_' . $setid;
613
614
+ $shortcode_html .= "<tr>
615
+ <td colspan=\"2\" class=\"yasr-multiset-average\">
616
+ $average_txt
617
+ <div class=\"yasr-multiset-visitors-rater\" id=\"$unique_id_identifier\"
618
+ data-rater-postid=\"$post_id\" data-rater-setid=\"$setid\"
619
+ data-rater-set-field-id=\"$set_content->id\" data-rating=\"$multiset_average\"
620
+ data-rater-readonly=\"true\" ></div>
621
</td>
622
+ </tr>";
623
+ }
624
625
+ //Submit row and button
626
+ $shortcode_html.="<tr>
627
+ <td colspan=\"2\">
628
+ $button
629
+ $loader_html
630
+ <span class=\"yasr-visitor-multiset-message\">$span_message_content</span>
631
+ </td>
632
+ </tr>
633
+ ";
634
635
+ $shortcode_html.="</table>";
636
+ $shortcode_html .= '<!-- End Yasr Multi Set Visitor Shortcode-->';
637
638
+ wp_localize_script(
639
+ 'yasrfront',
640
+ "yasrMultiSetData",
641
+ array(
642
+ 'nonceVisitor' => $ajax_nonce_visitor_multiset,
643
+ 'setType' => $setid
644
+ )
645
+ );
646
+
647
+ return $shortcode_html;
648
649
}
650
653
654
add_shortcode ('yasr_top_ten_highest_rated', 'yasr_top_ten_highest_rated_callback');
655
656
+ function yasr_top_ten_highest_rated_callback() {
657
658
+ global $wpdb;
659
660
+ $query_result = $wpdb->get_results("SELECT pm.meta_value AS overall_rating, pm.post_id AS post_id
661
+ FROM $wpdb->postmeta AS pm, $wpdb->posts AS p
662
+ WHERE pm.post_id = p.ID
663
+ AND p.post_status = 'publish'
664
+ AND pm.meta_key = 'yasr_overall_rating'
665
+ ORDER BY pm.meta_value DESC, pm.post_id ASC LIMIT 10");
666
667
668
+ $shortcode_html = '<!-- Yasr Top 10 highest Rated Shortcode-->';
669
670
+ if ($query_result) {
671
+ $shortcode_html .= "<table class=\"yasr-table-chart\">";
672
673
+ foreach ($query_result as $result) {
674
+ $post_title = get_the_title($result->post_id);
675
+ $link = get_permalink($result->post_id); //Get permalink from post it
676
677
+ $yasr_top_ten_html_id = 'yasr-top-ten-rater-' . $result->post_id;
678
+ $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\"
679
+ data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\"
680
+ data-rating=\"$result->overall_rating\"></div>";
681
682
683
+ $shortcode_html .= "<tr>
684
+ <td width=\"60%\" class=\"yasr-top-10-overall-left\">
685
+ <a href=\"$link\">$post_title</a>
686
+ </td>
687
+ <td width=\"40%\" class=\"yasr-top-10-overall-right\">
688
+ $html_stars
689
+ <span class=\"yasr-highest-rated-text\">"
690
+ . __("Rating", 'yet-another-stars-rating') . " $result->overall_rating
691
+ </span>
692
+ </td>
693
+ </tr>";
694
695
696
+ } //End foreach
697
698
+ $shortcode_html .= "</table>";
699
700
+ $shortcode_html .= '<!--End Yasr Top 10 highest Rated Shortcode-->';
701
702
+ return $shortcode_html;
703
704
+ } //end if $query_result
705
706
+ else {
707
+ _e("You don't have any votes stored", 'yet-another-stars-rating');
708
+ }
709
710
+ } //End function
711
712
713
/****** Add top 10 most rated / highest rated post *****/
714
715
add_shortcode ('yasr_most_or_highest_rated_posts', 'yasr_most_or_highest_rated_posts_callback');
716
717
+ function yasr_most_or_highest_rated_posts_callback () {
718
719
+ $shortcode_html = '<!-- Yasr Most Or Highest Rated Shortcode-->';
720
721
+ global $wpdb;
722
723
+ $query_result_most_rated = $wpdb->get_results ("SELECT post_id, COUNT(post_id) AS number_of_votes, SUM(vote) AS sum_votes
724
+ FROM " . YASR_LOG_TABLE . " , $wpdb->posts AS p
725
+ WHERE post_id = p.ID
726
+ AND p.post_status = 'publish'
727
+ GROUP BY post_id
728
+ HAVING number_of_votes > 1
729
+ ORDER BY number_of_votes DESC, post_id ASC
730
+ LIMIT 10
731
+ ");
732
+
733
+
734
+ //count run twice but access data only once: tested with query monitor and asked
735
+ //here http://stackoverflow.com/questions/39201235/does-count-run-twice/39201492
736
+ $query_result_highest = $wpdb->get_results ("SELECT post_id, COUNT(post_id) AS number_of_votes, (SUM(vote) / COUNT(post_id)) AS result
737
+ FROM " . YASR_LOG_TABLE . " , $wpdb->posts AS p
738
+ WHERE post_id = p.ID
739
+ AND p.post_status = 'publish'
740
+ GROUP BY post_id
741
+ HAVING COUNT(post_id) >= 2
742
+ ORDER BY result DESC, number_of_votes DESC
743
+ LIMIT 10
744
+ ");
745
746
+ if ($query_result_most_rated) {
747
748
+ $shortcode_html .= "<table class=\"yasr-table-chart\" id=\"yasr-most-rated-posts\">
749
+ <tr class=\"yasr-visitor-votes-title\">
750
+ <th>" . __("Post / Page" , 'yet-another-stars-rating') ." </th>
751
+ <th>". __("Order By" , 'yet-another-stars-rating') .":&nbsp;&nbsp;
752
+ <span id=\"yasr_multi_chart_link_to_nothing\">" . __("Most Rated" , 'yet-another-stars-rating') ."</span> |
753
+ <span id=\"link-yasr-highest-rated-posts\"><a href=\"\" onclick='yasrShowHighest(); return false'>" . __("Highest Rated" , 'yet-another-stars-rating') ."</a></span>
754
+ </th>
755
+ </tr>"
756
+ ;
757
758
+ foreach ($query_result_most_rated as $result) {
759
760
+ $rating = $result->sum_votes / $result->number_of_votes;
761
762
+ $rating = round($rating, 1);
763
764
+ $post_title = get_the_title($result->post_id);
765
766
+ $link = get_permalink($result->post_id); //Get permalink from post it
767
768
+ $yasr_top_ten_html_id = 'yasr-10-most-rater' . $result->post_id;
769
+ $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\" data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\" data-rating=\"$rating\"></div>";
770
771
+ $shortcode_html .= "<tr>
772
+ <td width=\"60%\" class=\"yasr-top-10-most-highest-left\"><a href=\"$link\">$post_title</a></td>
773
+ <td width=\"40%\" class=\"yasr-top-10-most-highest-right\">
774
+ $html_stars
775
+ <br /> [" . __( "Total:", 'yet-another-stars-rating' ) . "$result->number_of_votes &nbsp;&nbsp;&nbsp;" . __( "Average", 'yet-another-stars-rating' ) . " $rating]
776
+ </td>
777
+ </tr>";
778
779
+ } //End foreach
780
781
+ $shortcode_html .= "</table>" ;
782
783
+ } //End if $query_result_most_rated)
784
785
+ else {
786
+ $shortcode_html = __("You've not enough data",'yet-another-stars-rating') . "<br />";
787
+ }
788
789
790
+ if ($query_result_highest) {
791
792
+ $shortcode_html .= "<table class=\"yasr-table-chart\" id=\"yasr-highest-rated-posts\">
793
+ <tr class=\"yasr-visitor-votes-title\">
794
+ <th>" . __("Post / Page" , 'yet-another-stars-rating') ." </th>
795
+ <th>". __("Order By" , 'yet-another-stars-rating') .":&nbsp;&nbsp;
796
+ <span id=\"link-yasr-most-rated-posts\"><a href=\"\" onclick='yasrShowMost(); return false'>". __("Most Rated" , 'yet-another-stars-rating') . "</a> |
797
+ <span id=\"yasr_multi_chart_link_to_nothing\">". __("Highest Rated" , 'yet-another-stars-rating') ."</span>
798
+ </th>
799
+ </tr>";
800
801
+ foreach ($query_result_highest as $result) {
802
803
+ $rating = round($result->result, 1);
804
805
+ $post_title = get_the_title($result->post_id);
806
807
+ $link = get_permalink($result->post_id); //Get permalink from post it
808
809
+ $yasr_top_ten_html_id = 'yasr-10-highest-rater-' . $result->post_id;
810
+ $html_stars = "<div class=\"yasr-rater-stars\" id=\"$yasr_top_ten_html_id\" data-rater-postid=\"$result->post_id\" data-rater-starsize=\"24\" data-rating=\"$rating\"></div>";
811
812
+ $shortcode_html .= "<tr>
813
+ <td width=\"60%\" class=\"yasr-top-10-most-highest-left\"><a href=\"$link\">$post_title</a></td>
814
+ <td width=\"40%\" class=\"yasr-top-10-most-highest-right\">
815
+ $html_stars
816
+ <br /> [" . __("Total:" , 'yet-another-stars-rating') . "$result->number_of_votes &nbsp;&nbsp;&nbsp;" . __("Average" , 'yet-another-stars-rating') . " $rating]
817
+ </td>
818
+ </tr>";
819
820
821
+ } //End foreach
822
823
+ $shortcode_html .= "</table>";
824
825
+ } //end if $query_result
826
827
+ else {
828
+ $shortcode_html = __("You've not enought data",'yet-another-stars-rating') . "<br />";
829
+ }
830
831
+ $shortcode_html .= '<!-- End Yasr Most Or Highest Rated Shortcode-->';