Yasr – Yet Another Stars Rating - Version 2.3.1

Version Description

  • Code refactor, according to boilerplate standards
Download this release

Release Info

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

Code changes from version 2.3.0 to 2.3.1

Files changed (102) hide show
  1. {lib/admin → admin}/class-wp-list-table.php +0 -0
  2. lib/admin/yasr-admin-classes.php → admin/classes/YasrLogDashboardWidget.php +4 -2
  3. admin/classes/YasrOnInstall.php +182 -0
  4. {css → admin/css}/yasr-admin.css +2 -2
  5. {lib/admin → admin}/editor/YasrOnSavePost.php +0 -1
  6. lib/yasr-ajax-functions.php → admin/editor/yasr-editor-functions.php +148 -387
  7. {lib/admin → admin}/editor/yasr-metabox-below-editor.php +2 -2
  8. {lib/admin → admin}/editor/yasr-metabox-multiple-rating.php +0 -0
  9. {lib/admin → admin}/editor/yasr-metabox-schema.php +22 -22
  10. {lib/admin → admin}/editor/yasr-metabox-top-right.php +4 -6
  11. {js → admin/js}/src/yasr-guten-blocks.js +0 -0
  12. {js → admin/js}/src/yasr-guten-panel.js +0 -0
  13. {js → admin/js}/yasr-admin.js +0 -0
  14. {js → admin/js}/yasr-editor-screen.js +0 -0
  15. {js → admin/js}/yasr-guten-blocks.js +0 -0
  16. {js → admin/js}/yasr-guten-panel.js +0 -0
  17. {lib/admin/settings → admin/settings/aspect_style}/yasr-settings-functions-style.php +14 -15
  18. {lib/admin/settings → admin/settings/migrations}/yasr-settings-migration-functions.php +8 -0
  19. {lib/admin/settings → admin/settings/migrations}/yasr-settings-migration-page.php +0 -0
  20. {lib/admin/settings → admin/settings/multiset}/yasr-settings-functions-multiset-page.php +0 -0
  21. {lib/admin/settings → admin/settings/multiset}/yasr-settings-functions-multiset.php +11 -20
  22. {lib/admin → admin}/settings/yasr-settings-functions-misc.php +0 -0
  23. {lib/admin → admin}/settings/yasr-settings-functions.php +10 -14
  24. yasr-settings-page.php → admin/settings/yasr-settings-page.php +3 -4
  25. {lib/admin → admin}/settings/yasr-stats-functions.php +0 -0
  26. admin/yasr-admin-actions-ajax.php +37 -0
  27. {lib/admin → admin}/yasr-admin-actions.php +68 -6
  28. admin/yasr-admin-filters.php +32 -0
  29. admin/yasr-admin-functions.php +53 -0
  30. admin/yasr-admin-init.php +200 -0
  31. yasr-stats-page.php → admin/yasr-stats-page.php +1 -1
  32. {lib/admin → admin}/yasr-update-functions.php +1 -2
  33. img/Yasr-Stylish.png +0 -0
  34. img/create-ranking.png +0 -0
  35. img/dialog-ok-apply.png +0 -0
  36. img/paypal.png +0 -0
  37. img/yasr-user-reviews.png +0 -0
  38. img/yasr_aggregate.jpg +0 -0
  39. img/yasr_review.png +0 -0
  40. includes/classes/YasrDatabaseRatings.php +127 -0
  41. lib/yasr-db-classes.php → includes/classes/YasrMultiSetData.php +7 -101
  42. {css → includes/css}/yasr-table-dark.css +0 -0
  43. {css → includes/css}/yasr-table-light.css +0 -0
  44. {css → includes/css}/yasr.css +0 -2
  45. {img → includes/img}/dark-multi-set.png +0 -0
  46. {img → includes/img}/loader.gif +0 -0
  47. {img → includes/img}/star_0.svg +0 -0
  48. {img → includes/img}/star_1.svg +0 -0
  49. {img → includes/img}/star_2.svg +0 -0
  50. {img → includes/img}/star_3.svg +0 -0
  51. {img → includes/img}/star_oxy_0.svg +0 -0
  52. {img → includes/img}/star_oxy_1.svg +0 -0
  53. {img → includes/img}/star_tiny.png +0 -0
  54. {img → includes/img}/stars_rater.png +0 -0
  55. {img → includes/img}/stars_rater_oxy.png +0 -0
  56. {img → includes/img}/stars_rater_yasr.png +0 -0
  57. {img → includes/img}/yasr-multi-set-insert-rate-small.jpg +0 -0
  58. {img → includes/img}/yasr-multi-set-insert-rate.jpg +0 -0
  59. {img → includes/img}/yasr-multi-set.png +0 -0
  60. {img → includes/img}/yasr-pro-stars.png +0 -0
  61. {img → includes/img}/yasr-stars-large.png +0 -0
  62. {img → includes/img}/yasr-stars-medium.png +0 -0
  63. {img → includes/img}/yasr-stars-small.png +0 -0
  64. {img → includes/img}/yasr_settings_stats_disabled.png +0 -0
  65. {img → includes/img}/yasr_settings_stats_enabled.png +0 -0
  66. {js → includes/js}/rater-js-rtl.js +0 -0
  67. {js → includes/js}/rater-js.js +0 -0
  68. {js → includes/js}/tippy.all.min.js +0 -0
  69. {js → includes/js}/yasr-front.js +0 -0
  70. {lib → includes}/rest/classes/YasrCustomEndpoint.php +0 -1
  71. {lib → includes}/rest/classes/YasrCustomFields.php +2 -2
  72. {lib/rest → includes/rest/classes}/YasrPostMeta.php +0 -0
  73. {lib → includes}/rest/yasr-rest.php +1 -1
  74. {lib → includes}/shortcodes/classes/YasrMultiSet.php +3 -6
  75. {lib → includes}/shortcodes/classes/YasrOverallRating.php +0 -0
  76. {lib → includes}/shortcodes/classes/YasrRankings.php +0 -1
  77. {lib → includes}/shortcodes/classes/YasrShortcode.php +1 -1
  78. {lib → includes}/shortcodes/classes/YasrVisitorMultiSet.php +0 -1
  79. {lib → includes}/shortcodes/classes/YasrVisitorVotes.php +0 -0
  80. includes/shortcodes/yasr-shortcode-ajax.php +392 -0
  81. {lib → includes}/shortcodes/yasr-shortcode-functions.php +4 -50
  82. includes/yasr-includes-db-functions.php +61 -0
  83. includes/yasr-includes-functions.php +327 -0
  84. includes/yasr-includes-init.php +237 -0
  85. {lib → includes}/yasr-widgets.php +1 -4
  86. js/yasr-shortcode-creator.js +0 -17
  87. lib/admin/editor/yasr-editor-functions.php +0 -159
  88. lib/rest/YasrCustomEndpoint.php +0 -151
  89. lib/rest/YasrCustomFields.php +0 -110
  90. lib/rest/classes/YasrPostMeta.php +0 -76
  91. lib/yasr-db-functions.php +0 -341
  92. lib/yasr-deprecated.php +0 -182
  93. lib/yasr-functions.php +0 -985
  94. lib/yasr-shortcode-classes.php +0 -1044
  95. lib/yasr-shortcode-functions.php +0 -242
  96. {lib → public/classes}/YasrRichSnippetAdditionalFields.php +12 -7
  97. public/yasr-public-actions.php +135 -0
  98. public/yasr-public-filters.php +305 -0
  99. public/yasr-public-functions.php +75 -0
  100. public/yasr-public-init.php +59 -0
  101. readme.txt +5 -2
  102. yet-another-stars-rating.php +28 -182
{lib/admin → admin}/class-wp-list-table.php RENAMED
File without changes
lib/admin/yasr-admin-classes.php → admin/classes/YasrLogDashboardWidget.php RENAMED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  /*
4
 
5
  Copyright 2014 Dario Curvino (email : d.curvino@tiscali.it)
@@ -53,7 +52,10 @@ class YasrLogDashboardWidget {
53
  $this->is_ajax = true;
54
 
55
  if ($widget_user === 'admin') {
56
- $this->adminWidget();
 
 
 
57
  }
58
  if ($widget_user === 'user') {
59
  $this->userWidget();
1
  <?php
 
2
  /*
3
 
4
  Copyright 2014 Dario Curvino (email : d.curvino@tiscali.it)
52
  $this->is_ajax = true;
53
 
54
  if ($widget_user === 'admin') {
55
+ if (current_user_can('manage_options')) {
56
+ $this->adminWidget();
57
+ }
58
+ return;
59
  }
60
  if ($widget_user === 'user') {
61
  $this->userWidget();
admin/classes/YasrOnInstall.php ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if (!current_user_can('manage_options')) {
25
+ wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
26
+ }
27
+
28
+ /**
29
+ * Class YasrOnInstall
30
+ *
31
+ * This class get called on installation
32
+ */
33
+ class YasrOnInstall {
34
+
35
+ /**
36
+ * YasrOnInstall constructor.
37
+ *
38
+ * @param $network_wide
39
+ */
40
+ public function __construct($network_wide) {
41
+ global $wpdb;
42
+
43
+ // Creating tables for all blogs in a WordPress Multisite installation
44
+ if (is_multisite() && $network_wide) {
45
+ // Get all blogs in the network and activate plugin on each one
46
+ $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
47
+ foreach ($blog_ids as $blog_id) {
48
+ switch_to_blog($blog_id);
49
+ self::createTables();
50
+ restore_current_blog();
51
+ }
52
+ }
53
+ //Not a multisite install
54
+ else {
55
+ self::createTables();
56
+ }
57
+ //default settings
58
+ $this->defaultSettings();
59
+ }
60
+
61
+ public static function createTables () {
62
+ global $wpdb; //Database wordpress object
63
+
64
+ $prefix = $wpdb->prefix . 'yasr_'; //Table prefix
65
+
66
+ $yasr_multi_set_table = $prefix . 'multi_set';
67
+ $yasr_multi_set_fields = $prefix . 'multi_set_fields';
68
+ $yasr_log_multi_set = $prefix . 'log_multi_set';
69
+ $yasr_log_table = $prefix . 'log';
70
+
71
+ //Do not use IF TABLE EXISTS here
72
+ //see https://wordpress.stackexchange.com/a/302538/48442
73
+ //since this function is called only on plugin activation AND if yasr-version is not found in
74
+ //wp-option, there is no need to check if table exists, unless the user manually remove yasr-version option
75
+ //but not the yasr tables.
76
+
77
+ $sql_yasr_multi_set_table = "CREATE TABLE $yasr_multi_set_table (
78
+ set_id int(2) NOT NULL AUTO_INCREMENT,
79
+ set_name varchar(64) COLLATE utf8_unicode_ci NOT NULL,
80
+ UNIQUE KEY set_id (set_id),
81
+ UNIQUE KEY set_name (set_name)
82
+ ) COLLATE 'utf8_unicode_ci';";
83
+
84
+ $sql_yasr_multi_set_fields = "CREATE TABLE $yasr_multi_set_fields (
85
+ id int(3) NOT NULL AUTO_INCREMENT,
86
+ parent_set_id int(2) NOT NULL,
87
+ field_name varchar(40) COLLATE utf8_unicode_ci NOT NULL,
88
+ field_id int(2) NOT NULL,
89
+ PRIMARY KEY (id),
90
+ UNIQUE KEY id (id)
91
+ ) COLLATE 'utf8_unicode_ci';";
92
+
93
+ //Since version 2.1.0
94
+ $sql_yasr_log_multi_set_table = "CREATE TABLE $yasr_log_multi_set (
95
+ id bigint(20) NOT NULL AUTO_INCREMENT,
96
+ field_id int(2) NOT NULL,
97
+ set_type int(2) NOT NULL,
98
+ post_id bigint(20) NOT NULL,
99
+ vote decimal(2,1) NOT NULL,
100
+ user_id bigint(20) NOT NULL,
101
+ date datetime NOT NULL,
102
+ ip varchar(45) COLLATE 'utf8_unicode_ci' NOT NULL,
103
+ PRIMARY KEY (id),
104
+ UNIQUE KEY id (id)
105
+ ) COLLATE 'utf8_unicode_ci';";
106
+
107
+ //Since version 2.0.9 user_id is bigint 20 and vote decimal 2,1
108
+ //format DECIMAL(M, D) where M is the maximum number of digits (the precision) and D is the
109
+ //number of digits to the right of the decimal point (the scale).
110
+ $sql_yasr_log_table = "CREATE TABLE $yasr_log_table (
111
+ id bigint(20) NOT NULL AUTO_INCREMENT,
112
+ post_id bigint(20) NOT NULL,
113
+ user_id bigint(20) NOT NULL,
114
+ vote decimal(2,1) NOT NULL,
115
+ date datetime NOT NULL,
116
+ ip varchar(45) COLLATE utf8_unicode_ci NOT NULL,
117
+ PRIMARY KEY (id),
118
+ UNIQUE KEY id (id)
119
+ ) COLLATE 'utf8_unicode_ci';";
120
+
121
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
122
+
123
+ dbDelta($sql_yasr_multi_set_table);
124
+ dbDelta($sql_yasr_multi_set_fields);
125
+ dbDelta($sql_yasr_log_multi_set_table);
126
+ dbDelta($sql_yasr_log_table);
127
+ }
128
+
129
+ /****** Install yasr functions ******/
130
+ private function defaultSettings() {
131
+
132
+ //Write default option settings
133
+ $option = get_option('yasr_general_options');
134
+
135
+ if (!$option) {
136
+ $option = array();
137
+ $option['auto_insert_enabled'] = 1;
138
+ $option['auto_insert_what'] = 'visitor_rating';
139
+ $option['auto_insert_where'] = 'bottom';
140
+ $option['auto_insert_size'] = 'large';
141
+ $option['auto_insert_align'] = 'center';
142
+ $option['auto_insert_exclude_pages'] = 'yes';
143
+ $option['auto_insert_custom_post_only'] = 'no';
144
+ $option['show_overall_in_loop'] = 'disabled';
145
+ $option['show_visitor_votes_in_loop'] = 'disabled';
146
+ $option['text_before_stars'] = 1;
147
+ $option['text_before_overall'] = __('Our Score', 'yet-another-stars-rating');
148
+ $option['text_before_visitor_rating'] = __('Click to rate this post!', 'yet-another-stars-rating');
149
+ $option['text_after_visitor_rating'] = sprintf(
150
+ __('[Total: %s Average: %s]', 'yet-another-stars-rating'),
151
+ '%total_count%', '%average%'
152
+ );
153
+ $option['custom_text_user_voted'] = __('You must sign in to vote', 'yet-another-stars-rating');
154
+ $option['custom_text_must_sign_in'] = __('You have already voted for this article', 'yet-another-stars-rating');
155
+ $option['enable_ip'] = 'no';
156
+ $option['snippet_itemtype'] = 'Product';
157
+ $option['blogposting_organization_name'] = get_bloginfo('name');
158
+ $option['blogposting_organization_logo'] = get_site_icon_url();
159
+ $option['allowed_user'] = 'allow_anonymous';
160
+ $option['visitors_stats'] = 'yes';
161
+ $option['enable_ajax'] = 'no';
162
+
163
+ add_option("yasr_general_options", $option); //Write here the default value if there is not option
164
+
165
+ //Style set options
166
+ $style_options = array();
167
+ $style_options['scheme_color_multiset'] = 'light';
168
+ $style_options['stars_set_free'] = 'flat';
169
+
170
+ add_option("yasr_style_options", $style_options);
171
+
172
+ //multi set options
173
+ $multi_set_options = array();
174
+ $multi_set_options['show_average'] = 'yes';
175
+
176
+ add_option("yasr_multiset_options", $multi_set_options);
177
+
178
+ }
179
+
180
+ }
181
+
182
+ }
{css → admin/css}/yasr-admin.css RENAMED
@@ -2,7 +2,7 @@
2
  width: 0;
3
  position: relative;
4
  display: inline-block;
5
- background-image: url(../img/star_0.svg);
6
  background-position: 0 0;
7
  background-repeat: repeat-x;
8
  }
@@ -39,7 +39,7 @@
39
  position: absolute;
40
  height: 100%;
41
  width: 100%;
42
- background: url('../img/star_1.svg');
43
  background-repeat: repeat-x;
44
  }
45
 
2
  width: 0;
3
  position: relative;
4
  display: inline-block;
5
+ background-image: url(../../includes/img/star_0.svg);
6
  background-position: 0 0;
7
  background-repeat: repeat-x;
8
  }
39
  position: absolute;
40
  height: 100%;
41
  width: 100%;
42
+ background: url('../../includes/img/star_1.svg');
43
  background-repeat: repeat-x;
44
  }
45
 
{lib/admin → admin}/editor/YasrOnSavePost.php RENAMED
@@ -263,5 +263,4 @@ add_action('save_post', 'yasr_on_save_post_callback');
263
 
264
  function yasr_on_save_post_callback ($post_id) {
265
  new YasrOnSavePost($post_id);
266
- return;
267
  }
263
 
264
  function yasr_on_save_post_callback ($post_id) {
265
  new YasrOnSavePost($post_id);
 
266
  }
lib/yasr-ajax-functions.php → admin/editor/yasr-editor-functions.php RENAMED
@@ -16,47 +16,161 @@ 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
 
22
  if (!defined('ABSPATH')) {
23
  exit('You\'re not allowed to see this page');
24
  } // Exit if accessed directly
25
 
26
- /*************************** Admin ajax functions ***********************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- /********** Functions used while wirting a new post or page ********/
29
 
30
- /****** Get Set name from post or page and output the set,
31
- * used in yasr-metabox-multiple-rating******/
32
 
33
- add_action('wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback');
 
 
 
 
 
 
 
 
 
 
34
 
35
- function yasr_output_multiple_set_callback() {
36
 
37
- if (isset($_POST['set_id']) && isset($_POST['post_id']) && $_POST['post_id'] != '' && $_POST['set_id'] != '') {
38
- $set_id = (int) $_POST['set_id'];
39
- $post_id = (int) $_POST['post_id'];
40
- } else {
41
- exit();
 
 
 
 
 
 
 
 
 
 
 
42
  }
 
43
 
44
- if (!current_user_can(YASR_USER_CAPABILITY_EDIT_POST)) {
45
- wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  }
47
 
48
- yasr_return_multi_set_values_admin($post_id, $set_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
- die();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
 
 
 
 
 
 
52
  }
53
 
 
 
 
 
 
 
 
 
 
 
54
 
55
- /****** Create the content for the button shortcode in Tinymce ******/
 
56
 
 
57
  //Add ajax action that will be called from the .js for button in tinymce
58
  add_action('wp_ajax_yasr_create_shortcode', 'wp_ajax_yasr_create_shortcode_callback');
59
-
60
  function wp_ajax_yasr_create_shortcode_callback() {
61
  if (isset($_POST['action'])) {
62
  $action = $_POST['action'];
@@ -289,381 +403,28 @@ function wp_ajax_yasr_create_shortcode_callback() {
289
 
290
  } //End callback function
291
 
292
- /********** END Functions used while wirting a new post or page ********/
293
-
294
- /********************* END Admin ajax functions ****************/
295
-
296
-
297
- /********************* NON Admin ajax functions ****************/
298
-
299
- /****** Yasr insert visitor votes, called from yasr-shortcode-function ******/
300
-
301
- add_action('wp_ajax_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback');
302
- add_action('wp_ajax_nopriv_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback');
303
-
304
- function yasr_insert_visitor_votes_callback() {
305
-
306
- if (isset($_POST['rating']) && isset($_POST['post_id']) && isset($_POST['nonce_visitor'])) {
307
-
308
- $rating = (int) $_POST['rating'];
309
- $post_id = (int) $_POST['post_id'];
310
- $nonce_visitor = $_POST['nonce_visitor'];
311
- $is_singular = $_POST['is_singular'];
312
-
313
- if (!is_int($post_id)) {
314
- exit();
315
- }
316
-
317
- } else {
318
- exit();
319
- }
320
-
321
- $array_action_visitor_vote = array('post_id' => $post_id, 'is_singular' => $is_singular);
322
-
323
- do_action('yasr_action_on_visitor_vote', $array_action_visitor_vote);
324
-
325
- if (!wp_verify_nonce($nonce_visitor, 'yasr_nonce_insert_visitor_rating')) {
326
- die('Security check');
327
- }
328
-
329
- if ($rating < 1) {
330
- $rating = 1;
331
- } elseif ($rating > 5) {
332
- $rating = 5;
333
- }
334
-
335
- global $wpdb;
336
-
337
- $current_user = wp_get_current_user();
338
- $ip_adress = yasr_get_ip();
339
-
340
- $result_update_log = null; //avoid undefined
341
- $result_insert_log = null; //avoid undefined
342
-
343
- if (is_user_logged_in()) {
344
-
345
- //try to update first, if fails the do the insert
346
- $result_update_log = $wpdb->update(
347
- YASR_LOG_TABLE,
348
- array(
349
- 'post_id' => $post_id,
350
- 'user_id' => $current_user->ID,
351
- 'vote' => $rating,
352
- 'date' => date('Y-m-d H:i:s'),
353
- 'ip' => $ip_adress
354
- ),
355
- array(
356
- 'post_id' => $post_id,
357
- 'user_id' => $current_user->ID
358
- ),
359
- array('%d', '%d', '%d', '%s', '%s', '%s'),
360
- array('%d', '%d')
361
-
362
- );
363
-
364
- //insert the new row
365
- //use ! instead of === FALSE
366
- if (!$result_update_log) {
367
- $result_insert_log = $wpdb->insert(
368
- YASR_LOG_TABLE,
369
- array(
370
- 'post_id' => $post_id,
371
- 'user_id' => $current_user->ID,
372
- 'vote' => $rating,
373
- 'date' => date('Y-m-d H:i:s'),
374
- 'ip' => $ip_adress
375
- ),
376
- array('%d', '%d', '%d', '%s', '%s', '%s')
377
- );
378
- }
379
-
380
- } //if user is not logged in insert
381
- else {
382
-
383
- //be sure that allow anonymous is on
384
- if (YASR_ALLOWED_USER === 'allow_anonymous') {
385
- $result_insert_log = $wpdb->replace(
386
- YASR_LOG_TABLE,
387
- array(
388
- 'post_id' => $post_id,
389
- 'user_id' => $current_user->ID,
390
- 'vote' => $rating,
391
- 'date' => date('Y-m-d H:i:s'),
392
- 'ip' => $ip_adress
393
- ),
394
-
395
- array('%d', '%d', '%d', '%s', '%s', '%s')
396
- );
397
- }
398
-
399
- }
400
-
401
- if ($result_update_log || $result_insert_log) {
402
- $row_exists = YasrDatabaseRatings::getVisitorVotes($post_id);
403
-
404
- $user_votes_sum = $row_exists['sum_votes'];
405
- $number_of_votes = $row_exists['number_of_votes'];
406
-
407
- $cookiename = 'yasr_visitor_vote_cookie';
408
-
409
- $data_to_save = array(
410
- 'post_id' => $post_id,
411
- 'rating' => $rating
412
- );
413
-
414
- yasr_setcookie($cookiename, $data_to_save);
415
-
416
- $total_rating = ($user_votes_sum / $number_of_votes);
417
- $medium_rating = round($total_rating, 1);
418
-
419
- $html_to_return = '<span class="yasr-total-average-text"> ['
420
- . __('Total:', 'yet-another-stars-rating') .
421
- " $number_of_votes &nbsp; &nbsp;"
422
- . __('Average:', 'yet-another-stars-rating') .
423
- " $medium_rating/5 ]
424
- </span>";
425
- $html_to_return .= '<span class="yasr-small-block-bold" id="yasr-vote-saved">'
426
- . __('Vote Saved', 'yet-another-stars-rating') .
427
- '</span>';
428
-
429
- echo json_encode($html_to_return);
430
-
431
- }
432
-
433
- die(); // this is required to return a proper result
434
-
435
- }
436
-
437
- /****** Get Multiple value from visitor and insert into db, used in yasr-shortcode-functions ******/
438
-
439
- add_action('wp_ajax_yasr_visitor_multiset_field_vote', 'yasr_visitor_multiset_field_vote_callback');
440
- add_action('wp_ajax_nopriv_yasr_visitor_multiset_field_vote', 'yasr_visitor_multiset_field_vote_callback');
441
-
442
- function yasr_visitor_multiset_field_vote_callback() {
443
-
444
- if (isset($_POST['post_id']) && isset($_POST['rating']) && isset($_POST['set_type'])) {
445
- $post_id = (int) $_POST['post_id'];
446
- $rating = $_POST['rating'];
447
- $set_type = (int) $_POST['set_type'];
448
- $nonce = $_POST['nonce'];
449
-
450
- if (!is_int($post_id) || !is_int($set_type)) {
451
- exit("Missing post id or set type");
452
- }
453
-
454
- if ($rating == "") {
455
- exit("You must insert at least a rating");
456
- }
457
-
458
- } else {
459
- exit();
460
- }
461
-
462
- if (!wp_verify_nonce($nonce, 'yasr_nonce_insert_visitor_rating_multiset')) {
463
- die('Security Check');
464
- }
465
-
466
- $current_user = wp_get_current_user();
467
- $ip_adress = yasr_get_ip();
468
-
469
- $array_action_visitor_multiset_vote = array('post_id' => $post_id);
470
-
471
- do_action('yasr_action_on_visitor_multiset_vote', $array_action_visitor_multiset_vote);
472
-
473
- global $wpdb;
474
-
475
- $array_error = array();
476
-
477
- //clean array, so if an user rate same field twice, take only the last rating
478
- $cleaned_array = yasr_unique_multidim_array($rating, 'field');
479
-
480
- //this is a counter: if at the end of the foreach it still 0, means that an user rated in a set
481
- //and then submit another one
482
- $counter_matched_fields = 0;
483
-
484
- foreach ($cleaned_array as $rating_values) {
485
-
486
- //check if the set id in the array is the same of the clicked
487
- if ($rating_values['postid'] == $post_id && $rating_values['setid'] == $set_type) {
488
-
489
- //increase the counter
490
- $counter_matched_fields = $counter_matched_fields + 1;
491
-
492
- $id_field = $rating_values['field'];
493
- $rating = $rating_values['rating'];
494
-
495
- $query_success = $wpdb->insert(
496
- YASR_LOG_MULTI_SET,
497
- array(
498
- 'field_id' => $id_field,
499
- 'set_type' => $set_type,
500
- 'post_id' => $post_id,
501
- 'vote' => $rating,
502
- 'user_id' => $current_user->ID,
503
- 'date' => date('Y-m-d H:i:s'),
504
- 'ip' => $ip_adress
505
-
506
- ),
507
- array("%d", "%d", "%d", "%d", "%d", "%s", "%s")
508
- );
509
-
510
- if ($query_success) {
511
- $array_error[] = 0;
512
- } else {
513
- $array_error[] = 1;
514
- }
515
-
516
- } //End if $rating_values['postid'] == $post_id
517
-
518
- } //End foreach ($rating as $rating_values)
519
-
520
- if ($counter_matched_fields === 0) {
521
- $array_error[] = 1;
522
- }
523
-
524
- $error_found = false;
525
-
526
- foreach ($array_error as $error) {
527
- if ($error === 1) {
528
- $error_found = true;
529
- }
530
- }
531
-
532
- if (!$error_found) {
533
- $cookiename = 'yasr_multi_visitor_cookie';
534
-
535
- $data_to_save = array(
536
- 'post_id' => $post_id,
537
- 'set_id' => $set_type
538
- );
539
-
540
- yasr_setcookie($cookiename, $data_to_save);
541
-
542
- _e('Rating saved!', 'yet-another-stars-rating');
543
-
544
- } else {
545
- _e('Rating not saved. Please Try again', 'yet-another-stars-rating');
546
- }
547
-
548
- die();
549
-
550
- } //End callback function
551
-
552
-
553
- add_action('wp_ajax_yasr_stats_visitors_votes', 'yasr_stats_visitors_votes_callback');
554
- add_action('wp_ajax_nopriv_yasr_stats_visitors_votes', 'yasr_stats_visitors_votes_callback');
555
-
556
- function yasr_stats_visitors_votes_callback() {
557
-
558
- if (isset($_POST['post_id']) && $_POST['post_id'] !== '') {
559
- $post_id = (int)$_POST['post_id'];
560
- } else {
561
- return;
562
- }
563
-
564
- $votes_array = YasrDatabaseRatings::getVisitorVotes($post_id);
565
- $votes_number = $votes_array['number_of_votes'];
566
-
567
- if ($votes_number != 0) {
568
- $medium_rating = ($votes_array['sum_votes'] / $votes_number);
569
- } else {
570
- $medium_rating = 0;
571
- }
572
-
573
- $medium_rating = round($medium_rating, 1);
574
- $missing_vote = null; //avoid undefined variable
575
-
576
- global $wpdb;
577
-
578
- $stats = $wpdb->get_results($wpdb->prepare("SELECT ROUND( vote, 0 ) as vote, COUNT( vote ) AS n_of_votes
579
- FROM " . YASR_LOG_TABLE . "
580
- WHERE post_id=%d
581
- GROUP BY vote
582
- ORDER BY vote DESC
583
- ",
584
- $post_id),
585
- ARRAY_A);
586
-
587
- $total_votes = 0; //Avoid undefined variable if stats exists. Necessary if $stats not exists
588
-
589
- //if query return 0 write an empty array $existing_votes
590
- if (!$stats) {
591
- $existing_votes = array();
592
- } else {
593
- //Write a new array with only existing votes, and count all the number of votes
594
- foreach ($stats as $votes_array) {
595
- $existing_votes[] = $votes_array['vote'];//Create an array with only existing votes
596
- $total_votes = $total_votes + $votes_array['n_of_votes'];
597
- }
598
-
599
- }
600
-
601
- for ($i = 1; $i <= 5; $i ++) {
602
- //If query return 0 write a new $stats array with index
603
- if (!$stats) {
604
- $stats[$i] = array();
605
- $stats[$i]['vote'] = $i;
606
- $stats[$i]['n_of_votes'] = 0;
607
- } else {
608
- //If in the new array there are some vote missing create a new array
609
- if (!in_array($i, $existing_votes)) {
610
- $missing_vote[$i] = array();
611
- $missing_vote[$i]['vote'] = $i;
612
- $missing_vote[$i]['n_of_votes'] = 0;
613
- }
614
- }
615
- }
616
-
617
- //If missing_vote exists merge it
618
- if ($missing_vote) {
619
- $stats = array_merge($stats, $missing_vote);
620
  }
621
 
622
- arsort($stats); //sort it by $votes[n_of_votes]
623
-
624
- $html_to_return = '<div class="yasr-visitors-stats-tooltip">';
625
- $html_to_return .= '<span id="yasr-medium-rating-tooltip">' . $medium_rating . ' '
626
- . __('out of 5 stars', 'yet-another-stars-rating') .
627
- '</span>';
628
- $html_to_return .= '<div class="yasr-progress-bars-container">';
629
-
630
- if ($total_votes == 0) {
631
- $increase_bar_value = 0;
632
  } else {
633
- $increase_bar_value = 100 / $total_votes; //Find how much all the bars should increase per vote
634
  }
635
 
636
- $i = 5;
637
-
638
- $stars_text = __("stars", 'yet-another-stars-rating');
639
-
640
- foreach ($stats as $logged_votes) {
641
-
642
- if ($i == 1) {
643
- $stars_text = __("star", 'yet-another-stars-rating');
644
- }
645
-
646
- $value_progressbar = $increase_bar_value * $logged_votes['n_of_votes']; //value of the single bar
647
- $value_progressbar = round($value_progressbar, 2) . '%'; //use only 2 decimal
648
-
649
- $html_to_return .= "<div class='yasr-progress-bar-row-container yasr-w3-container'>
650
- <div class='yasr-progress-bar-name'>$i $stars_text</div>
651
- <div class='yasr-single-progress-bar-container'>
652
- <div class='yasr-w3-border '>
653
- <div class='yasr-w3-amber' style='height:17px;width:$value_progressbar'></div>
654
- </div></div>
655
- <div class='yasr-progress-bar-votes-count'>" . $logged_votes['n_of_votes'] . "</div><br />
656
- </div>";
657
-
658
- $i --;
659
 
660
- } //End foreach
 
661
 
662
- $html_to_return .= '</div></div>';
663
- echo json_encode($html_to_return);
664
 
665
  die();
666
-
667
- }
668
-
669
- ?>
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
+ //this load guten-block.js, only in admin side
26
+ add_action('enqueue_block_editor_assets', 'yasr_gutenberg_scripts');
27
+
28
+ function yasr_gutenberg_scripts() {
29
+
30
+ //Script
31
+ wp_enqueue_script(
32
+ 'yasr_blocks',
33
+ YASR_JS_DIR_ADMIN . 'yasr-guten-blocks.js',
34
+ array(
35
+ 'wp-i18n',
36
+ 'wp-blocks',
37
+ 'wp-components',
38
+ 'wp-element',
39
+ 'wp-editor',
40
+ )
41
+ );
42
+
43
+ wp_enqueue_script(
44
+ 'yasr_guten_panel',
45
+ YASR_JS_DIR_ADMIN . 'yasr-guten-panel.js',
46
+ array(
47
+ 'wp-plugins',
48
+ 'wp-edit-post',
49
+ 'wp-element',
50
+ 'wp-editor'
51
+ )
52
+ );
53
 
54
+ }
55
 
56
+ //This filter is used to add a new category in gutenberg
57
+ add_filter('block_categories', 'yasr_add_gutenberg_category', 10, 2);
58
 
59
+ function yasr_add_gutenberg_category($categories) {
60
+ return array_merge(
61
+ $categories,
62
+ array(
63
+ array(
64
+ 'slug' => 'yet-another-stars-rating',
65
+ 'title' => 'Yasr: Yet Another Stars Rating',
66
+ ),
67
+ )
68
+ );
69
+ }
70
 
71
+ add_action('yasr_add_admin_scripts_end', 'yasr_add_js_constant_gutenberg');
72
 
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',
84
+ array(
85
+ 'autoInsert' => $auto_insert,
86
+ 'defaultItemType' => YASR_ITEMTYPE,
87
+ )
88
+ );
89
  }
90
+ }
91
 
92
+
93
+ /****** Create 2 metaboxes in post and pages ******/
94
+ add_action('add_meta_boxes', 'yasr_add_metaboxes');
95
+
96
+ function yasr_add_metaboxes() {
97
+
98
+ //Default post type where display metabox
99
+ $post_type_where_display_metabox = array('post', 'page');
100
+
101
+ //get the custom post type
102
+ $custom_post_types = yasr_get_custom_post_type();
103
+
104
+ if ($custom_post_types) {
105
+ //First merge array then changes keys to int
106
+ $post_type_where_display_metabox = array_values(array_merge($post_type_where_display_metabox, $custom_post_types));
107
  }
108
 
109
+ //For classic editor, add this metabox
110
+ foreach ($post_type_where_display_metabox as $post_type) {
111
+ add_meta_box(
112
+ 'yasr_metabox_overall_rating',
113
+ 'YASR',
114
+ 'yasr_metabox_overall_rating_content',
115
+ $post_type,
116
+ 'side',
117
+ 'high',
118
+ //Set this to true, so this metabox will be only loaded to classic editor
119
+ array(
120
+ '__back_compat_meta_box' => true,
121
+ )
122
+ );
123
+ }
124
 
125
+ foreach ($post_type_where_display_metabox as $post_type) {
126
+ add_meta_box(
127
+ 'yasr_metabox_below_editor_metabox',
128
+ __('Yet Another Stars Rating', 'yet-another-stars-rating'),
129
+ 'yasr_metabox_below_editor_metabox_callback',
130
+ $post_type,
131
+ 'normal',
132
+ 'high'
133
+ );
134
+ }
135
+
136
+
137
+ } //End function
138
+
139
+ function yasr_metabox_overall_rating_content() {
140
+
141
+ if (current_user_can(YASR_USER_CAPABILITY_EDIT_POST)) {
142
+ include(YASR_ABSOLUTE_PATH_ADMIN . '/editor/yasr-metabox-top-right.php');
143
+ } else {
144
+ _e("You don't have enought privileges to insert Overall Rating");
145
+ }
146
+
147
+ }
148
 
149
+ function yasr_metabox_below_editor_metabox_callback() {
150
+ if (current_user_can(YASR_USER_CAPABILITY_EDIT_POST)) {
151
+ include(YASR_ABSOLUTE_PATH_ADMIN . '/editor/yasr-metabox-below-editor.php');
152
+ } else {
153
+ _e("You don't have enough privileges to insert a Multi Set");
154
+ }
155
  }
156
 
157
+ /******* Add a media content button ******/
158
+ add_action('media_buttons', 'yasr_shortcode_button_media', 99);
159
+ function yasr_shortcode_button_media() {
160
+ if (is_admin()) {
161
+ add_thickbox();
162
+ echo '<a href="#TB_inline?width=530&height=600&inlineId=yasr-tinypopup-form"
163
+ id="yasr-shortcode-creator"
164
+ class="button thickbox">
165
+ <span class="dashicons dashicons-star-half" style="vertical-align: middle;"></span> Yasr Shortcode
166
+ </a>';
167
 
168
+ }
169
+ }
170
 
171
+ /****** Create the content for the button shortcode in Tinymce ******/
172
  //Add ajax action that will be called from the .js for button in tinymce
173
  add_action('wp_ajax_yasr_create_shortcode', 'wp_ajax_yasr_create_shortcode_callback');
 
174
  function wp_ajax_yasr_create_shortcode_callback() {
175
  if (isset($_POST['action'])) {
176
  $action = $_POST['action'];
403
 
404
  } //End callback function
405
 
406
+ /****** Get Set name from post or page and output the set,
407
+ * used in yasr-metabox-multiple-rating******/
408
+ add_action('wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback');
409
+ function yasr_output_multiple_set_callback() {
410
+ if (!current_user_can(YASR_USER_CAPABILITY_EDIT_POST)) {
411
+ wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
  }
413
 
414
+ if (!empty($_POST['set_id']) && !empty($_POST['post_id'])) {
415
+ $set_id = (int) $_POST['set_id'];
416
+ $post_id = (int) $_POST['post_id'];
 
 
 
 
 
 
 
417
  } else {
418
+ die();
419
  }
420
 
421
+ //set fields name and ids
422
+ $set_fields = YasrMultiSetData::multisetFieldsAndID($set_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
423
 
424
+ //set meta values
425
+ $array_to_return = YasrMultiSetData::returnArrayFieldsRatings($set_id, $set_fields, $post_id);
426
 
427
+ echo json_encode($array_to_return);
 
428
 
429
  die();
430
+ }
 
 
 
{lib/admin → admin}/editor/yasr-metabox-below-editor.php RENAMED
@@ -41,7 +41,7 @@ $multi_set = YasrMultiSetData::returnMultiSetNames();
41
  </div>
42
 
43
  <div id="yasr-metabox-below-editor-structured-data" class="yasr-metabox-below-editor-content">
44
- <?php include(YASR_ABSOLUTE_PATH . '/lib/admin/editor/yasr-metabox-schema.php'); ?>
45
  </div>
46
 
47
  <?php
@@ -50,7 +50,7 @@ $multi_set = YasrMultiSetData::returnMultiSetNames();
50
  if ($multi_set) {
51
  ?>
52
  <div id="yasr-metabox-below-editor-multiset" class="yasr-metabox-below-editor-content" style="display:none">
53
- <?php include(YASR_ABSOLUTE_PATH . '/lib/admin/editor/yasr-metabox-multiple-rating.php'); ?>
54
  </div>
55
  <?php
56
  }
41
  </div>
42
 
43
  <div id="yasr-metabox-below-editor-structured-data" class="yasr-metabox-below-editor-content">
44
+ <?php include(YASR_ABSOLUTE_PATH_ADMIN . '/editor/yasr-metabox-schema.php'); ?>
45
  </div>
46
 
47
  <?php
50
  if ($multi_set) {
51
  ?>
52
  <div id="yasr-metabox-below-editor-multiset" class="yasr-metabox-below-editor-content" style="display:none">
53
+ <?php include(YASR_ABSOLUTE_PATH_ADMIN . '/editor/yasr-metabox-multiple-rating.php'); ?>
54
  </div>
55
  <?php
56
  }
{lib/admin → admin}/editor/yasr-metabox-multiple-rating.php RENAMED
File without changes
{lib/admin → admin}/editor/yasr-metabox-schema.php RENAMED
@@ -25,10 +25,10 @@ if (!defined('ABSPATH')) {
25
  global $post;
26
 
27
  //is post review
28
- $yasr_nonce_is_post_review = wp_nonce_field('yasr_nonce_is_post_review_action', 'yasr_nonce_is_post_review');
29
 
30
  //itemType select
31
- $yasr_nonce_review_type = wp_nonce_field('yasr_nonce_review_type_action', 'yasr_nonce_review_type');
32
 
33
  //get all additional post meta
34
  $saved_data = get_post_meta($post->ID, 'yasr_schema_additional_fields', true);
@@ -89,7 +89,7 @@ foreach ($array_item_type_info as $item_type) {
89
  <div class="yasr-itemtype-row-container-label-input">
90
  <label for="yasr-product-brand">Brand</label>
91
  <input type="text" name="yasr_product_brand" id="yasr-product-brand"
92
- value='<?php echo $saved_data['yasr_product_brand'] ?>'
93
  >
94
  </div>
95
  <div class="yasr-itemtype-row-container-description">
@@ -99,7 +99,7 @@ foreach ($array_item_type_info as $item_type) {
99
  <div class="yasr-itemtype-row-container-label-input">
100
  <label for="yasr-product-sku">Sku</label>
101
  <input type="text" name="yasr_product_sku" id="yasr-product-sku"
102
- value='<?php echo $saved_data['yasr_product_sku'] ?>'
103
  >
104
  </div>
105
  <div class="yasr-itemtype-row-container-description">
@@ -122,7 +122,7 @@ foreach ($array_item_type_info as $item_type) {
122
  </select>
123
  <label for="yasr-product-global-identifier-value" style="width: auto; margin-left: 10px;">Value</label>
124
  <input type="text" name="yasr_product_global_identifier_value" id="yasr-product-global-identifier-value"
125
- value='<?php echo $saved_data['yasr_product_global_identifier_value'] ?>'
126
  >
127
  </div>
128
 
@@ -139,19 +139,19 @@ foreach ($array_item_type_info as $item_type) {
139
  <div class="yasr-itemtype-row-container-label-input">
140
  <label for="yasr-product-price">Price</label>
141
  <input type="text" name="yasr_product_price" id="yasr-product-price"
142
- value='<?php echo $saved_data['yasr_product_price'] ?>'
143
  >
144
  </div>
145
  <div class="yasr-itemtype-row-container-label-input">
146
  <label for="yasr-product-price-currency">Currency</label>
147
  <input type="text" name="yasr_product_price_currency" id="yasr-product-price-currency"
148
- value='<?php echo $saved_data['yasr_product_price_currency'] ?>'
149
  >
150
  </div>
151
  <div class="yasr-itemtype-row-container-label-input">
152
  <label for="yasr-product-price-valid-until">Price Valid Until</label>
153
  <input type="text" name="yasr_product_price_valid_until" id="yasr-product-price-valid-until"
154
- value='<?php echo $saved_data['yasr_product_price_valid_until'] ?>'
155
  >
156
  </div>
157
  <div class="yasr-itemtype-row-container-label-input">
@@ -174,7 +174,7 @@ foreach ($array_item_type_info as $item_type) {
174
  <div class="yasr-itemtype-row-container-label-input">
175
  <label for="yasr-product-price-url">Url</label>
176
  <input type="text" name="yasr_product_price_url" id="yasr-product-price-url"
177
- value='<?php echo $saved_data['yasr_product_price_url'] ?>'
178
  >
179
  </div>
180
 
@@ -198,7 +198,7 @@ foreach ($array_item_type_info as $item_type) {
198
  <div class="yasr-itemtype-row-container-label-input">
199
  <label for="yasr-localbusiness-address">Address</label>
200
  <input type="text" name="yasr_localbusiness_address" id="yasr-localbusiness-address"
201
- value='<?php echo $saved_data['yasr_localbusiness_address'] ?>'
202
  >
203
  </div>
204
  <div class="yasr-itemtype-row-container-description">
@@ -208,7 +208,7 @@ foreach ($array_item_type_info as $item_type) {
208
  <div class="yasr-itemtype-row-container-label-input">
209
  <label for="yasr-localbusiness-pricerange">PriceRange</label>
210
  <input type="text" name="yasr_localbusiness_pricerange" id="yasr-localbusiness-pricerange"
211
- value='<?php echo $saved_data['yasr_localbusiness_pricerange'] ?>'
212
  >
213
  </div>
214
  <div class="yasr-itemtype-row-container-description">
@@ -220,7 +220,7 @@ foreach ($array_item_type_info as $item_type) {
220
  <div class="yasr-itemtype-row-container-label-input">
221
  <label for="yasr-localbusiness-telephone">Telephone</label>
222
  <input type="text" name="yasr_localbusiness_telephone" id="yasr-localbusiness-telephone"
223
- value='<?php echo $saved_data['yasr_localbusiness_telephone'] ?>'
224
  >
225
  </div>
226
  <div class="yasr-itemtype-row-container-description">
@@ -237,7 +237,7 @@ foreach ($array_item_type_info as $item_type) {
237
  <div class="yasr-itemtype-row-container-label-input">
238
  <label for="yasr-recipe-cooktime">cookTime</label>
239
  <input type="text" name="yasr_recipe_cooktime" id="yasr-recipe-cooktime"
240
- value='<?php echo $saved_data['yasr_recipe_cooktime'] ?>'
241
  >
242
  </div>
243
  <div class="yasr-itemtype-row-container-description">
@@ -247,7 +247,7 @@ foreach ($array_item_type_info as $item_type) {
247
  <div class="yasr-itemtype-row-container-label-input">
248
  <label for="yasr-recipe-preptime">prepTime</label>
249
  <input type="text" name="yasr_recipe_preptime" id="yasr-recipe-preptime"
250
- value='<?php echo $saved_data['yasr_recipe_preptime'] ?>'
251
  >
252
  </div>
253
  <div class="yasr-itemtype-row-container-description">
@@ -258,7 +258,7 @@ foreach ($array_item_type_info as $item_type) {
258
  <div class="yasr-itemtype-row-container-label-input">
259
  <label for="yasr-recipe-description">description</label>
260
  <input type="text" name="yasr_recipe_description" id="yasr-recipe-description"
261
- value='<?php echo $saved_data['yasr_recipe_description'] ?>'
262
  >
263
  </div>
264
  <div class="yasr-itemtype-row-container-description">
@@ -268,7 +268,7 @@ foreach ($array_item_type_info as $item_type) {
268
  <div class="yasr-itemtype-row-container-label-input">
269
  <label for="yasr-recipe-keywords">keywords</label>
270
  <input type="text" name="yasr_recipe_keywords" id="yasr-recipe-keywords"
271
- value='<?php echo $saved_data['yasr_recipe_keywords'] ?>'
272
  >
273
  </div>
274
  <div class="yasr-itemtype-row-container-description">
@@ -279,7 +279,7 @@ foreach ($array_item_type_info as $item_type) {
279
  <div class="yasr-itemtype-row-container-label-input">
280
  <label for="yasr-recipe-nutrition">nutrition</label>
281
  <input type="text" name="yasr_recipe_nutrition" id="yasr-recipe-nutrition"
282
- value='<?php echo $saved_data['yasr_recipe_nutrition'] ?>'
283
  >
284
  </div>
285
  <div class="yasr-itemtype-row-container-description">
@@ -290,7 +290,7 @@ foreach ($array_item_type_info as $item_type) {
290
  <div class="yasr-itemtype-row-container-label-input">
291
  <label for="yasr-recipe-category">recipeCategory</label>
292
  <input type="text" name="yasr_recipe_recipecategory" id="yasr-recipe-category"
293
- value='<?php echo $saved_data['yasr_recipe_recipecategory'] ?>'
294
  >
295
  </div>
296
  <div class="yasr-itemtype-row-container-description">
@@ -301,7 +301,7 @@ foreach ($array_item_type_info as $item_type) {
301
  <div class="yasr-itemtype-row-container-label-input">
302
  <label for="yasr-recipe-cuisine">recipeCuisine</label>
303
  <input type="text" name="yasr_recipe_recipecuisine" id="yasr-recipe-cuisine"
304
- value='<?php echo $saved_data['yasr_recipe_recipecuisine'] ?>'
305
  >
306
  </div>
307
  <div class="yasr-itemtype-row-container-description">
@@ -312,7 +312,7 @@ foreach ($array_item_type_info as $item_type) {
312
  <div class="yasr-itemtype-row-container-label-input">
313
  <label for="yasr-recipe-ingredient" style="vertical-align: top">recipeIngredient</label>
314
  <textarea name="yasr_recipe_recipeingredient" rows="4"
315
- id="yasr-recipe-ingredient"><?php echo $saved_data['yasr_recipe_recipeingredient'] ?></textarea>
316
  </div>
317
  <div class="yasr-itemtype-row-container-description">
318
  <?php
@@ -330,7 +330,7 @@ foreach ($array_item_type_info as $item_type) {
330
  <div class="yasr-itemtype-row-container-label-input">
331
  <label for="yasr-recipe-instructions" style="vertical-align: top">recipeInstructions</label>
332
  <textarea name="yasr_recipe_recipeinstructions" rows="4"
333
- id="yasr-recipe-instructions"><?php echo $saved_data['yasr_recipe_recipeinstructions'] ?></textarea>
334
  </div>
335
  <div class="yasr-itemtype-row-container-description">
336
  <?php
@@ -345,7 +345,7 @@ foreach ($array_item_type_info as $item_type) {
345
  <div class="yasr-itemtype-row-container-label-input">
346
  <label for="yasr-recipe-video">Video</label>
347
  <input type="text" name="yasr_recipe_video" id="yasr-recipe-video"
348
- value='<?php echo $saved_data['yasr_recipe_video'] ?>'
349
  >
350
  </div>
351
  <div class="yasr-itemtype-row-container-description">
25
  global $post;
26
 
27
  //is post review
28
+ wp_nonce_field('yasr_nonce_is_post_review_action', 'yasr_nonce_is_post_review');
29
 
30
  //itemType select
31
+ 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);
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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($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 esc_attr($saved_data['yasr_recipe_recipecuisine']); ?>'
305
  >
306
  </div>
307
  <div class="yasr-itemtype-row-container-description">
312
  <div class="yasr-itemtype-row-container-label-input">
313
  <label for="yasr-recipe-ingredient" style="vertical-align: top">recipeIngredient</label>
314
  <textarea name="yasr_recipe_recipeingredient" rows="4"
315
+ id="yasr-recipe-ingredient"><?php echo esc_textarea($saved_data['yasr_recipe_recipeingredient']); ?></textarea>
316
  </div>
317
  <div class="yasr-itemtype-row-container-description">
318
  <?php
330
  <div class="yasr-itemtype-row-container-label-input">
331
  <label for="yasr-recipe-instructions" style="vertical-align: top">recipeInstructions</label>
332
  <textarea name="yasr_recipe_recipeinstructions" rows="4"
333
+ id="yasr-recipe-instructions"><?php echo esc_textarea($saved_data['yasr_recipe_recipeinstructions']); ?></textarea>
334
  </div>
335
  <div class="yasr-itemtype-row-container-description">
336
  <?php
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 esc_url($saved_data['yasr_recipe_video']); ?>'
349
  >
350
  </div>
351
  <div class="yasr-itemtype-row-container-description">
{lib/admin → admin}/editor/yasr-metabox-top-right.php RENAMED
@@ -29,15 +29,13 @@ $post_id=get_the_ID();
29
  //equivalent to get_post_meta
30
  $overall_rating = $post->yasr_overall_rating;
31
 
32
- $yasr_nonce_overall = wp_nonce_field( "yasr_nonce_overall_rating_action", "yasr_nonce_overall_rating");
33
- $yasr_nonce_auto_insert = wp_nonce_field( "yasr_nonce_auto_insert_action", "yasr_nonce_auto_insert" );
34
- $yasr_nonce_review_type = wp_nonce_field( "yasr_nonce_review_type_action", "yasr_nonce_review_type" );
35
- $yasr_nonce_review_type = wp_nonce_field( "yasr_nonce_is_post_review_action", "yasr_nonce_is_post_review" );
36
-
37
 
38
  ?>
39
 
40
-
41
  <div id="yasr-matabox-top-right">
42
 
43
  <input type='hidden' name='yasr_overall_rating' id='yasr-overall-rating-value' value='<?php echo $overall_rating?>'>
29
  //equivalent to get_post_meta
30
  $overall_rating = $post->yasr_overall_rating;
31
 
32
+ wp_nonce_field('yasr_nonce_overall_rating_action', 'yasr_nonce_overall_rating');
33
+ wp_nonce_field('yasr_nonce_auto_insert_action', 'yasr_nonce_auto_insert');
34
+ wp_nonce_field('yasr_nonce_review_type_action', 'yasr_nonce_review_type');
35
+ wp_nonce_field('yasr_nonce_is_post_review_action', 'yasr_nonce_is_post_review');
 
36
 
37
  ?>
38
 
 
39
  <div id="yasr-matabox-top-right">
40
 
41
  <input type='hidden' name='yasr_overall_rating' id='yasr-overall-rating-value' value='<?php echo $overall_rating?>'>
{js → admin/js}/src/yasr-guten-blocks.js RENAMED
File without changes
{js → admin/js}/src/yasr-guten-panel.js RENAMED
File without changes
{js → admin/js}/yasr-admin.js RENAMED
File without changes
{js → admin/js}/yasr-editor-screen.js RENAMED
File without changes
{js → admin/js}/yasr-guten-blocks.js RENAMED
File without changes
{js → admin/js}/yasr-guten-panel.js RENAMED
File without changes
{lib/admin/settings → admin/settings/aspect_style}/yasr-settings-functions-style.php RENAMED
@@ -35,11 +35,9 @@ function yasr_style_options_init() {
35
  global $style_options;
36
 
37
  if (!$style_options || !isset($style_options['scheme_color_multiset']) || !isset($style_options['textarea'])) {
38
-
39
  $style_options = array();
40
  $style_options['scheme_color_multiset'] = 'light';
41
  $style_options['textarea'] = null;
42
-
43
  }
44
 
45
  //filter $style_options
@@ -85,12 +83,12 @@ function yasr_color_scheme_multiset_callback($style_options) {
85
  <?php
86
 
87
  _e("Light theme", 'yet-another-stars-rating');
88
- echo "<br /><br /><img src=" . YASR_IMG_DIR . "yasr-multi-set.png>";
89
 
90
  echo "<br /> <br />";
91
 
92
  _e("Dark theme", 'yet-another-stars-rating');
93
- echo "<br /><br /><img src=" . YASR_IMG_DIR . "dark-multi-set.png>";
94
  ?>
95
  </div>
96
 
@@ -101,32 +99,33 @@ function yasr_color_scheme_multiset_callback($style_options) {
101
 
102
  function yasr_style_options_textarea_callback($style_options) {
103
 
104
- _e("Please use text area below to write your own CSS styles to override the default ones.", 'yet-another-stars-rating');
 
105
  echo "<br /><strong>";
106
- _e("Leave it blank if you don't know what you're doing.", 'yet-another-stars-rating');
107
  echo "</strong><p>";
 
108
 
109
- echo("
110
- <textarea rows=\"17\" cols=\"40\" name=\"yasr_style_options[textarea]\" id=\"yasr_style_options_textarea\">$style_options[textarea]</textarea>
111
- ");
 
 
112
 
 
113
 
114
  }
115
 
116
  //sanitize
117
  function yasr_style_options_sanitize($style_options) {
118
-
119
  $style_options = apply_filters('yasr_sanitize_style_options', $style_options);
 
120
 
121
  foreach ($style_options as $key => $value) {
122
- $output[$key] = strip_tags(stripslashes($style_options[$key]));
123
-
124
- //Always use esc_html
125
- $output[$key] = esc_html($output[$key]);
126
  }
127
 
128
  return $output;
129
-
130
  }
131
 
132
  ?>
35
  global $style_options;
36
 
37
  if (!$style_options || !isset($style_options['scheme_color_multiset']) || !isset($style_options['textarea'])) {
 
38
  $style_options = array();
39
  $style_options['scheme_color_multiset'] = 'light';
40
  $style_options['textarea'] = null;
 
41
  }
42
 
43
  //filter $style_options
83
  <?php
84
 
85
  _e("Light theme", 'yet-another-stars-rating');
86
+ echo "<br /><br /><img src='" . YASR_IMG_DIR . "yasr-multi-set.png'>";
87
 
88
  echo "<br /> <br />";
89
 
90
  _e("Dark theme", 'yet-another-stars-rating');
91
+ echo "<br /><br /><img src='" . YASR_IMG_DIR . "dark-multi-set.png'>";
92
  ?>
93
  </div>
94
 
99
 
100
  function yasr_style_options_textarea_callback($style_options) {
101
 
102
+ _e('Please use text area below to write your own CSS styles to override the default ones.',
103
+ 'yet-another-stars-rating');
104
  echo "<br /><strong>";
105
+ _e('Leave it blank if you don\'t know what you\'re doing.', 'yet-another-stars-rating');
106
  echo "</strong><p>";
107
+ ?>
108
 
109
+ <textarea
110
+ rows='17'
111
+ cols='40'
112
+ name='yasr_style_options[textarea]'
113
+ id='yasr_style_options_textarea'><?php echo $style_options['textarea']?></textarea>
114
 
115
+ <?php
116
 
117
  }
118
 
119
  //sanitize
120
  function yasr_style_options_sanitize($style_options) {
 
121
  $style_options = apply_filters('yasr_sanitize_style_options', $style_options);
122
+ $output = array();
123
 
124
  foreach ($style_options as $key => $value) {
125
+ $output[$key] = sanitize_text_field($style_options[$key]);
 
 
 
126
  }
127
 
128
  return $output;
 
129
  }
130
 
131
  ?>
{lib/admin/settings → admin/settings/migrations}/yasr-settings-migration-functions.php RENAMED
@@ -284,6 +284,8 @@ function yasr_import_wppr_callback() {
284
  if(empty($logs)) {
285
  echo json_encode(__('No WP Post Rating data found'));
286
  } else {
 
 
287
  /****** Insert logs ******/
288
  foreach ($logs as $column) {
289
 
@@ -352,6 +354,8 @@ function yasr_import_kksr_callback() {
352
  if(empty($logs)) {
353
  echo json_encode(__('No KK Star Ratings data found'));
354
  } else {
 
 
355
  /****** Insert logs ******/
356
  foreach ($logs as $column) {
357
  if($column->ratings_average > 5) {
@@ -412,6 +416,8 @@ function yasr_import_ratemypost_callback() {
412
  if(empty($logs)) {
413
  echo json_encode(__('No Rate My Post data found'));
414
  } else {
 
 
415
  /****** Insert logs ******/
416
  foreach ($logs as $column) {
417
  $result = $wpdb->replace(
@@ -466,6 +472,8 @@ function yasr_import_mr_callback() {
466
  if(empty($logs)) {
467
  echo json_encode(__('No Multi Rating data found'));
468
  } else {
 
 
469
  /****** Insert logs ******/
470
  foreach ($logs as $column) {
471
 
284
  if(empty($logs)) {
285
  echo json_encode(__('No WP Post Rating data found'));
286
  } else {
287
+ $result = false;
288
+
289
  /****** Insert logs ******/
290
  foreach ($logs as $column) {
291
 
354
  if(empty($logs)) {
355
  echo json_encode(__('No KK Star Ratings data found'));
356
  } else {
357
+ $result = false;
358
+
359
  /****** Insert logs ******/
360
  foreach ($logs as $column) {
361
  if($column->ratings_average > 5) {
416
  if(empty($logs)) {
417
  echo json_encode(__('No Rate My Post data found'));
418
  } else {
419
+ $result = false;
420
+
421
  /****** Insert logs ******/
422
  foreach ($logs as $column) {
423
  $result = $wpdb->replace(
472
  if(empty($logs)) {
473
  echo json_encode(__('No Multi Rating data found'));
474
  } else {
475
+ $result = false;
476
+
477
  /****** Insert logs ******/
478
  foreach ($logs as $column) {
479
 
{lib/admin/settings → admin/settings/migrations}/yasr-settings-migration-page.php RENAMED
File without changes
{lib/admin/settings → admin/settings/multiset}/yasr-settings-functions-multiset-page.php RENAMED
File without changes
{lib/admin/settings → admin/settings/multiset}/yasr-settings-functions-multiset.php RENAMED
@@ -280,12 +280,11 @@ function yasr_edit_multi_form() {
280
  /****** Get and output multiple set in a form and table, used in settings page ******/
281
 
282
  add_action('wp_ajax_yasr_get_multi_set', 'yasr_get_multi_set_callback');
283
-
284
  function yasr_get_multi_set_callback() {
285
- if (isset($_POST['set_id']) && $_POST['set_id'] != '') {
286
- $set_type = $_POST['set_id'];
287
  } else {
288
- exit ();
289
  }
290
 
291
  global $wpdb;
@@ -296,19 +295,17 @@ function yasr_get_multi_set_callback() {
296
  FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
297
  WHERE parent_set_id= %d
298
  ORDER BY field_id",
299
- $set_type)
300
  );
301
 
302
  ?>
303
 
304
- <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>"
305
  id="form_edit_multi_set" method="post">
306
- <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>"/>
307
-
308
 
309
  <table id="yasr-table-form-edit-multi-set">
310
  <tr>
311
-
312
  <td id="yasr-table-form-edit-multi-set-header">
313
  <?php _e('Field name', 'yet-another-stars-rating') ?>
314
  </td>
@@ -316,7 +313,6 @@ function yasr_get_multi_set_callback() {
316
  <td id="yasr-table-form-edit-multi-set-remove">
317
  <?php _e('Remove', 'yet-another-stars-rating') ?>
318
  </td>
319
-
320
  </tr>
321
 
322
  <?php
@@ -324,24 +320,19 @@ function yasr_get_multi_set_callback() {
324
  $i = 1;
325
 
326
  foreach ($set_name as $name) {
327
-
328
  echo "
329
  <tr>
330
-
331
- <td width=\"80%\">
332
- Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$i\">
333
- <input type=\"hidden\" value=\"$name->id\" name=\"db-id-for-element-$i\">
334
  </td>
335
 
336
- <td width=\"20%\" style=\"text-align:center\">
337
  <input type=\"checkbox\" value=\"$name->id\" name=\"remove-element-$i\">
338
  </td>
339
-
340
  </tr>
341
  ";
342
-
343
  $i ++;
344
-
345
  }
346
 
347
  $i = $i - 1; //This is the number of the fields
@@ -358,7 +349,7 @@ function yasr_get_multi_set_callback() {
358
  <td width=\"80%\">" . __("Remove whole set?", 'yet-another-stars-rating') . "</td>
359
 
360
  <td width=\"20%\" style=\"text-align:center\">
361
- <input type=\"checkbox\" name=\"yasr-remove-multi-set\" value=\"$set_type\">
362
  </td>
363
 
364
  </tr>
280
  /****** Get and output multiple set in a form and table, used in settings page ******/
281
 
282
  add_action('wp_ajax_yasr_get_multi_set', 'yasr_get_multi_set_callback');
 
283
  function yasr_get_multi_set_callback() {
284
+ if (!empty($_POST['set_id'])) {
285
+ $set_id = (int)$_POST['set_id'];
286
  } else {
287
+ return;
288
  }
289
 
290
  global $wpdb;
295
  FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
296
  WHERE parent_set_id= %d
297
  ORDER BY field_id",
298
+ $set_id)
299
  );
300
 
301
  ?>
302
 
303
+ <form action="<?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>"
304
  id="form_edit_multi_set" method="post">
305
+ <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_id ?>"/>
 
306
 
307
  <table id="yasr-table-form-edit-multi-set">
308
  <tr>
 
309
  <td id="yasr-table-form-edit-multi-set-header">
310
  <?php _e('Field name', 'yet-another-stars-rating') ?>
311
  </td>
313
  <td id="yasr-table-form-edit-multi-set-remove">
314
  <?php _e('Remove', 'yet-another-stars-rating') ?>
315
  </td>
 
316
  </tr>
317
 
318
  <?php
320
  $i = 1;
321
 
322
  foreach ($set_name as $name) {
 
323
  echo "
324
  <tr>
325
+ <td width='80%'>
326
+ Element #$i <input type='text' value='$name->name' name='edit-multi-set-element-$i'>
327
+ <input type='hidden' value='$name->id' name='db-id-for-element-$i'>
 
328
  </td>
329
 
330
+ <td width='20%' style=\"text-align:center\">
331
  <input type=\"checkbox\" value=\"$name->id\" name=\"remove-element-$i\">
332
  </td>
 
333
  </tr>
334
  ";
 
335
  $i ++;
 
336
  }
337
 
338
  $i = $i - 1; //This is the number of the fields
349
  <td width=\"80%\">" . __("Remove whole set?", 'yet-another-stars-rating') . "</td>
350
 
351
  <td width=\"20%\" style=\"text-align:center\">
352
+ <input type=\"checkbox\" name=\"yasr-remove-multi-set\" value=\"$set_id\">
353
  </td>
354
 
355
  </tr>
{lib/admin → admin}/settings/yasr-settings-functions-misc.php RENAMED
File without changes
{lib/admin → admin}/settings/yasr-settings-functions.php RENAMED
@@ -37,7 +37,7 @@ function yasr_general_options_init() {
37
  $option = get_option('yasr_general_options');
38
 
39
  //This is to avoid undefined offset
40
- if ($option && $option['auto_insert_enabled'] == 0) {
41
  $option['auto_insert_what'] = 'visitor_rating';
42
  $option['auto_insert_where'] = 'bottom';
43
  $option['auto_insert_align'] = 'center';
@@ -47,7 +47,7 @@ function yasr_general_options_init() {
47
  }
48
 
49
  //This is to avoid undefined offset
50
- if ($option && $option['text_before_stars'] == 0) {
51
  $option['text_before_overall'] = __('Our Score', 'yet-another-stars-rating');
52
  $option['text_before_visitor_rating'] = __('Click to rate this post!', 'yet-another-stars-rating');
53
  $option['text_after_visitor_rating'] = sprintf(
@@ -331,7 +331,7 @@ function yasr_auto_insert_callback($option) {
331
 
332
  <?php
333
 
334
- $custom_post_types = yasr_get_custom_post_type('bool');
335
 
336
  if ($custom_post_types) { ?>
337
  <strong><?php _e('Use only in custom post types?', 'yet-another-stars-rating'); ?></strong>
@@ -342,7 +342,6 @@ function yasr_auto_insert_callback($option) {
342
  } ?> >
343
  <?php _e('Yes', 'yet-another-stars-rating'); ?>
344
 
345
- &nbsp;&nbsp;&nbsp;
346
 
347
  <input type="radio" name="yasr_general_options[auto_insert_custom_post_only]" value="no"
348
  class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_custom_post_only'] === 'no') {
@@ -801,9 +800,9 @@ function yasr_general_options_sanitize($option) {
801
  $allowed_tags = '';
802
 
803
  //except these ones
804
- if ($key == 'text_before_overall' || $key == 'text_before_visitor_rating' ||
805
- $key == 'text_after_visitor_rating' || $key == 'custom_text_must_sign_in' ||
806
- $key == 'custom_text_user_voted') {
807
 
808
  $allowed_tags = '<strong><p>';
809
 
@@ -825,7 +824,7 @@ function yasr_general_options_sanitize($option) {
825
  //Always use esc_html
826
  $output[$key] = esc_html($output[$key]);
827
 
828
- if ($key == 'blogposting_organization_logo') {
829
  //if is not a valid url get_site_icon_url instead
830
  if (filter_var($value, FILTER_VALIDATE_URL) === false) {
831
  $output[$key] = get_site_icon_url();
@@ -908,16 +907,13 @@ function yasr_general_options_sanitize($option) {
908
 
909
 
910
  //include multiset functions
911
- include(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions-multiset.php');
912
 
913
  //include style functions
914
- include(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions-style.php');
915
-
916
- //Misc
917
- include(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions-misc.php');
918
 
919
  //load functions migration
920
- include (YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-migration-functions.php');
921
 
922
 
923
  ?>
37
  $option = get_option('yasr_general_options');
38
 
39
  //This is to avoid undefined offset
40
+ if ($option && $option['auto_insert_enabled'] === 0) {
41
  $option['auto_insert_what'] = 'visitor_rating';
42
  $option['auto_insert_where'] = 'bottom';
43
  $option['auto_insert_align'] = 'center';
47
  }
48
 
49
  //This is to avoid undefined offset
50
+ if ($option && $option['text_before_stars'] === 0) {
51
  $option['text_before_overall'] = __('Our Score', 'yet-another-stars-rating');
52
  $option['text_before_visitor_rating'] = __('Click to rate this post!', 'yet-another-stars-rating');
53
  $option['text_after_visitor_rating'] = sprintf(
331
 
332
  <?php
333
 
334
+ $custom_post_types = yasr_get_custom_post_type();
335
 
336
  if ($custom_post_types) { ?>
337
  <strong><?php _e('Use only in custom post types?', 'yet-another-stars-rating'); ?></strong>
342
  } ?> >
343
  <?php _e('Yes', 'yet-another-stars-rating'); ?>
344
 
 
345
 
346
  <input type="radio" name="yasr_general_options[auto_insert_custom_post_only]" value="no"
347
  class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_custom_post_only'] === 'no') {
800
  $allowed_tags = '';
801
 
802
  //except these ones
803
+ if ($key === 'text_before_overall' || $key === 'text_before_visitor_rating' ||
804
+ $key === 'text_after_visitor_rating' || $key === 'custom_text_must_sign_in' ||
805
+ $key === 'custom_text_user_voted') {
806
 
807
  $allowed_tags = '<strong><p>';
808
 
824
  //Always use esc_html
825
  $output[$key] = esc_html($output[$key]);
826
 
827
+ if ($key === 'blogposting_organization_logo') {
828
  //if is not a valid url get_site_icon_url instead
829
  if (filter_var($value, FILTER_VALIDATE_URL) === false) {
830
  $output[$key] = get_site_icon_url();
907
 
908
 
909
  //include multiset functions
910
+ require(YASR_ABSOLUTE_PATH_ADMIN . '/settings/multiset/yasr-settings-functions-multiset.php');
911
 
912
  //include style functions
913
+ require(YASR_ABSOLUTE_PATH_ADMIN . '/settings/aspect_style/yasr-settings-functions-style.php');
 
 
 
914
 
915
  //load functions migration
916
+ require(YASR_ABSOLUTE_PATH_ADMIN . '/settings/migrations/yasr-settings-migration-functions.php');
917
 
918
 
919
  ?>
yasr-settings-page.php → admin/settings/yasr-settings-page.php RENAMED
@@ -45,7 +45,7 @@ $n_multi_set = null; //Avoid undefined variable when printed outside multiset ta
45
  //Do the settings tab
46
  yasr_settings_tabs($active_tab);
47
 
48
- if ($active_tab == 'general_settings') {
49
  ?>
50
 
51
  <div class="yasr-settingsdiv">
@@ -71,7 +71,7 @@ $n_multi_set = null; //Avoid undefined variable when printed outside multiset ta
71
 
72
 
73
  if ($active_tab === 'manage_multi') {
74
- include (YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions-multiset-page.php');
75
  yasr_right_settings_panel();
76
  } //End if ($active_tab=='manage_multi')
77
 
@@ -106,7 +106,7 @@ $n_multi_set = null; //Avoid undefined variable when printed outside multiset ta
106
  <div class="yasr-settingsdiv">
107
  <?php
108
  //include migration functions
109
- include(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-migration-page.php');
110
  ?>
111
  <div class="yasr-space-settings-div">
112
  </div>
@@ -141,6 +141,5 @@ $n_multi_set = null; //Avoid undefined variable when printed outside multiset ta
141
  var textBeforeStars = <?php echo(json_encode(YASR_TEXT_BEFORE_STARS)); ?>;
142
 
143
  YasrSettingsPage(activeTab, nMultiSet, autoInsertEnabled, textBeforeStars);
144
-
145
  }); //End jquery document ready
146
  </script>
45
  //Do the settings tab
46
  yasr_settings_tabs($active_tab);
47
 
48
+ if ($active_tab === 'general_settings') {
49
  ?>
50
 
51
  <div class="yasr-settingsdiv">
71
 
72
 
73
  if ($active_tab === 'manage_multi') {
74
+ include(YASR_ABSOLUTE_PATH_ADMIN . '/settings/multiset/yasr-settings-functions-multiset-page.php');
75
  yasr_right_settings_panel();
76
  } //End if ($active_tab=='manage_multi')
77
 
106
  <div class="yasr-settingsdiv">
107
  <?php
108
  //include migration functions
109
+ include(YASR_ABSOLUTE_PATH_ADMIN . '/settings/migrations/yasr-settings-migration-page.php');
110
  ?>
111
  <div class="yasr-space-settings-div">
112
  </div>
141
  var textBeforeStars = <?php echo(json_encode(YASR_TEXT_BEFORE_STARS)); ?>;
142
 
143
  YasrSettingsPage(activeTab, nMultiSet, autoInsertEnabled, textBeforeStars);
 
144
  }); //End jquery document ready
145
  </script>
{lib/admin → admin}/settings/yasr-stats-functions.php RENAMED
File without changes
admin/yasr-admin-actions-ajax.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ //ajax action
25
+ add_action('wp_ajax_yasr_change_log_page', 'yasr_widget_log_dashboard_callback');
26
+ function yasr_widget_log_dashboard_callback() {
27
+ $log_widget = new YasrLogDashboardWidget('admin');
28
+ $log_widget->adminWidget();
29
+ } //End callback function
30
+
31
+
32
+ //ajax action
33
+ add_action('wp_ajax_yasr_change_user_log_page', 'yasr_users_dashboard_widget_callback');
34
+ function yasr_users_dashboard_widget_callback() {
35
+ $log_widget = new YasrLogDashboardWidget('user');
36
+ $log_widget->userWidget();
37
+ } //End callback function
{lib/admin → admin}/yasr-admin-actions.php RENAMED
@@ -4,17 +4,79 @@ if (!defined('ABSPATH')) {
4
  exit('You\'re not allowed to see this page');
5
  } // Exit if accessed directly
6
 
 
7
 
8
- //
9
- add_filter('yasr_filter_style_options', 'yasr_filter_style_options_callback');
10
 
11
- function yasr_filter_style_options_callback($style_options) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- if (!array_key_exists('stars_set_free', $style_options)) {
14
- $style_options['stars_set_free'] = 'rater-yasr'; //..default value if not exists
 
 
 
 
 
 
 
15
  }
16
 
17
- return $style_options;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  }
19
 
20
 
4
  exit('You\'re not allowed to see this page');
5
  } // Exit if accessed directly
6
 
7
+ /****** Adding logs widget to the dashboard ******/
8
 
9
+ add_action('plugins_loaded', 'yasr_add_action_dashboard_widget_log');
 
10
 
11
+ function yasr_add_action_dashboard_widget_log() {
12
+ //This is for the admins (show all votes in the site)
13
+ if (current_user_can('manage_options')) {
14
+ add_action('wp_dashboard_setup', 'yasr_add_dashboard_widget_log');
15
+ }
16
+
17
+ //This is for all the users to see where they've voted
18
+ add_action('wp_dashboard_setup', 'yasr_add_dashboard_widget_user_log');
19
+ }
20
+
21
+ function yasr_add_dashboard_widget_log() {
22
+ wp_add_dashboard_widget(
23
+ 'yasr_widget_log_dashboard', //slug for widget
24
+ 'Recent Ratings', //widget name
25
+ 'yasr_widget_log_dashboard_callback' //function callback
26
+ );
27
+ }
28
+
29
+ //This add a dashboard log for every users
30
+ function yasr_add_dashboard_widget_user_log() {
31
+ wp_add_dashboard_widget(
32
+ 'yasr_users_dashboard_widget', //slug for widget
33
+ 'Your Ratings', //widget name
34
+ 'yasr_users_dashboard_widget_callback' //function callback
35
+ );
36
+ }
37
 
38
+ /****** Delete data value from yasr tabs when a post or page is deleted
39
+ * Added since yasr 0.3.3
40
+ ******/
41
+ add_action('admin_init', 'admin_init_delete_data_on_post_callback');
42
+
43
+ function admin_init_delete_data_on_post_callback() {
44
+
45
+ if (current_user_can('delete_posts')) {
46
+ add_action('delete_post', 'yasr_erase_data_on_post_page_remove_callback');
47
  }
48
 
49
+ }
50
+
51
+ function yasr_erase_data_on_post_page_remove_callback($post_id) {
52
+ global $wpdb;
53
+
54
+ delete_metadata('post', $post_id, 'yasr_overall_rating');
55
+ delete_metadata('post', $post_id, 'yasr_review_type');
56
+ delete_metadata('post', $post_id, 'yasr_multiset_author_votes');
57
+
58
+ //Delete multi value
59
+ $wpdb->delete(
60
+ YASR_LOG_MULTI_SET,
61
+ array(
62
+ 'post_id' => $post_id
63
+ ),
64
+ array(
65
+ '%d'
66
+ )
67
+ );
68
+
69
+ $wpdb->delete(
70
+ YASR_LOG_TABLE,
71
+ array(
72
+ 'post_id' => $post_id
73
+ ),
74
+ array(
75
+ '%d'
76
+ )
77
+ );
78
+
79
+
80
  }
81
 
82
 
admin/yasr-admin-filters.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ add_filter('yasr_filter_style_options', 'yasr_filter_style_options_callback');
25
+ function yasr_filter_style_options_callback($style_options) {
26
+
27
+ if (!array_key_exists('stars_set_free', $style_options)) {
28
+ $style_options['stars_set_free'] = 'rater-yasr'; //..default value if not exists
29
+ }
30
+
31
+ return $style_options;
32
+ }
admin/yasr-admin-functions.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ //action is in the main file
26
+ function yasr_on_create_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
27
+ if (is_plugin_active_for_network( 'yet-another-stars-rating/yet-another-stars-rating.php' )) {
28
+ switch_to_blog($blog_id);
29
+ YasrOnInstall::createTables();
30
+ restore_current_blog();
31
+ }
32
+ }
33
+
34
+ // Deleting the table whenever a blog is deleted
35
+ function yasr_on_delete_blog($tables) {
36
+ global $wpdb;
37
+
38
+ $prefix = $wpdb->prefix . 'yasr_'; //Table prefix
39
+
40
+ $yasr_multi_set_table = $prefix . 'multi_set';
41
+ $yasr_multi_set_fields = $prefix . 'multi_set_fields';
42
+ $yasr_log_multi_set = $prefix . 'log_multi_set';
43
+ $yasr_log_table = $prefix . 'log';
44
+
45
+ $tables[] = $yasr_multi_set_table;
46
+ $tables[] = $yasr_multi_set_fields;
47
+ $tables[] = $yasr_log_multi_set;
48
+ $tables[] = $yasr_log_table;
49
+
50
+ return $tables;
51
+ }
52
+
53
+ /****** Create a new Page in Administration Menu ******/
admin/yasr-admin-init.php ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if(!is_admin()) {
26
+ return;
27
+ }
28
+
29
+ //e.g. http://localhost/plugin_development/wp-content/plugins/yet-another-stars-rating/admin/js/
30
+ define('YASR_JS_DIR_ADMIN', plugins_url() . '/' . YASR_RELATIVE_PATH_ADMIN . '/js/');
31
+ //CSS directory absolute URL
32
+ define('YASR_CSS_DIR_ADMIN', plugins_url() . '/' . YASR_RELATIVE_PATH_ADMIN . '/css/');
33
+
34
+ require YASR_ABSOLUTE_PATH_ADMIN . '/yasr-update-functions.php';
35
+ require YASR_ABSOLUTE_PATH_ADMIN . '/yasr-admin-functions.php';
36
+ require YASR_ABSOLUTE_PATH_ADMIN . '/yasr-admin-actions.php';
37
+ require YASR_ABSOLUTE_PATH_ADMIN . '/yasr-admin-actions-ajax.php';
38
+ require YASR_ABSOLUTE_PATH_ADMIN . '/yasr-admin-filters.php';
39
+ require YASR_ABSOLUTE_PATH_ADMIN . '/class-wp-list-table.php';
40
+ require YASR_ABSOLUTE_PATH_ADMIN . '/settings/yasr-settings-functions-misc.php';
41
+ require YASR_ABSOLUTE_PATH_ADMIN . '/settings/yasr-settings-functions.php';
42
+ require YASR_ABSOLUTE_PATH_ADMIN . '/editor/yasr-editor-functions.php';
43
+ require YASR_ABSOLUTE_PATH_ADMIN . '/editor/YasrOnSavePost.php';
44
+
45
+ /**
46
+ * Callback function for the spl_autoload_register above.
47
+ *
48
+ * @param $class
49
+ */
50
+ function yasr_autoload_admin_classes($class) {
51
+ /**
52
+ * If the class being requested does not start with 'Yasr' prefix,
53
+ * it's not in Yasr Project
54
+ */
55
+ if (0 !== strpos($class, 'Yasr')) {
56
+ return;
57
+ }
58
+ $file_name = YASR_ABSOLUTE_PATH_ADMIN . '/classes/' . $class . '.php';
59
+
60
+ // check if file exists, just to be sure
61
+ if (file_exists($file_name)) {
62
+ require($file_name);
63
+ }
64
+ }
65
+
66
+ //AutoLoad Yasr Shortcode Classes, only when a object is created
67
+ spl_autoload_register('yasr_autoload_admin_classes');
68
+
69
+ add_action('admin_enqueue_scripts', 'yasr_add_admin_scripts');
70
+
71
+ //$hook contain the current page in the admin side
72
+ function yasr_add_admin_scripts($hook) {
73
+
74
+ global $yasr_settings_page;
75
+
76
+ if ($hook === 'post.php' || $hook === 'post-new.php') {
77
+ wp_enqueue_script(
78
+ 'yasr_classic_editor_functions',
79
+ YASR_JS_DIR_ADMIN . 'yasr-editor-screen.js',
80
+ array('jquery'),
81
+ YASR_VERSION_NUM,
82
+ true
83
+ );
84
+ }
85
+
86
+ if ($hook === 'index.php' || $hook === 'edit.php' || $hook === 'post.php' || $hook === 'post-new.php' ||
87
+ $hook === 'edit-comments.php' || $hook === $yasr_settings_page ||
88
+ $hook === 'yet-another-stars-rating_page_yasr_stats_page'
89
+ ) {
90
+
91
+ do_action('yasr_add_admin_scripts_begin');
92
+
93
+ $rater_file_to_include = 'rater-js.js';
94
+
95
+ if (is_rtl()) {
96
+ $rater_file_to_include = 'rater-js-rtl.js';
97
+ }
98
+
99
+ wp_enqueue_style(
100
+ 'yasrcss',
101
+ YASR_CSS_DIR_ADMIN . 'yasr-admin.css',
102
+ false,
103
+ YASR_VERSION_NUM,
104
+ 'all'
105
+ );
106
+
107
+ wp_enqueue_script(
108
+ 'yasradmin',
109
+ YASR_JS_DIR_ADMIN . 'yasr-admin.js',
110
+ array('jquery'),
111
+ YASR_VERSION_NUM,
112
+ true
113
+ );
114
+
115
+ wp_enqueue_script(
116
+ 'rater',
117
+ YASR_JS_DIR_INCLUDES .
118
+ $rater_file_to_include,
119
+ '',
120
+ YASR_VERSION_NUM,
121
+ true
122
+ );
123
+
124
+ do_action('yasr_add_admin_scripts_end', $hook);
125
+
126
+ $yasr_loader = YASR_IMG_DIR . 'loader.gif';
127
+
128
+ wp_localize_script(
129
+ 'yasradmin', 'yasrCommonDataAdmin',
130
+ array(
131
+ 'loaderHtml' => $yasr_loader
132
+ )
133
+ );
134
+
135
+ }
136
+
137
+ }
138
+
139
+ /* Hook to admin_menu the yasr_add_pages function above */
140
+ add_action('admin_menu', 'yasr_add_pages');
141
+
142
+ function yasr_add_pages() {
143
+
144
+ global $yasr_settings_page;
145
+
146
+ //Add Settings Page
147
+ $yasr_settings_page = add_menu_page(
148
+ __('Yet Another Stars Rating: settings', 'yet-another-stars-rating'), //Page Title
149
+ __('Yet Another Stars Rating', 'yet-another-stars-rating'), //Menu Title
150
+ 'manage_options', //capability
151
+ 'yasr_settings_page', //menu slug
152
+ 'yasr_settings_page_callback', //The function to be called to output the content for this page.
153
+ 'dashicons-star-half'
154
+ );
155
+
156
+ add_submenu_page(
157
+ 'yasr_settings_page',
158
+ 'Yet Another Stars Rating: settings',
159
+ 'Settings',
160
+ 'manage_options',
161
+ 'yasr_settings_page'
162
+ );
163
+
164
+ add_submenu_page(
165
+ 'yasr_settings_page',
166
+ 'Yet Another Stars Rating: All Rating',
167
+ 'Stats',
168
+ 'manage_options',
169
+ 'yasr_stats_page',
170
+ 'yasr_stats_page_callback'
171
+ );
172
+
173
+ if (yasr_fs()->is_free_plan() && !yasr_fs()->is_trial()) {
174
+ global $submenu;
175
+ $permalink = '#';
176
+ $contact_us_string = sprintf(
177
+ __('Contact Us %s', 'yet-another-stars-rating'),
178
+ '<span class="dashicons dashicons-lock" />'
179
+ );
180
+ $submenu['yasr_settings_page'][] = array($contact_us_string, 'manage_options', $permalink);
181
+ }
182
+
183
+ }
184
+
185
+ // Settings Page Content
186
+ function yasr_settings_page_callback() {
187
+ if (!current_user_can('manage_options')) {
188
+ wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
189
+ }
190
+ include(YASR_ABSOLUTE_PATH_ADMIN . '/settings/yasr-settings-page.php');
191
+ } //End yasr_settings_page_content
192
+
193
+
194
+ function yasr_stats_page_callback() {
195
+ if (!current_user_can('manage_options')) {
196
+ wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
197
+ }
198
+
199
+ include(YASR_ABSOLUTE_PATH_ADMIN . '/yasr-stats-page.php');
200
+ }
yasr-stats-page.php → admin/yasr-stats-page.php RENAMED
@@ -26,7 +26,7 @@ if (!current_user_can('manage_options')) {
26
  wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
27
  }
28
 
29
- require(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-stats-functions.php');
30
 
31
  ?>
32
 
26
  wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
27
  }
28
 
29
+ require(YASR_ABSOLUTE_PATH_ADMIN . '/settings/yasr-stats-functions.php');
30
 
31
  ?>
32
 
{lib/admin → admin}/yasr-update-functions.php RENAMED
@@ -10,7 +10,6 @@ add_action('plugins_loaded', 'yasr_update_version');
10
 
11
  function yasr_update_version() {
12
  //do only in admin
13
-
14
  if (is_admin()) {
15
  global $yasr_version_installed;
16
  global $wpdb;
@@ -109,7 +108,7 @@ function yasr_update_version() {
109
  $multi_set_field_exists = $wpdb->get_var("SELECT COUNT(1) FROM " . YASR_MULTI_SET_FIELDS_TABLE);
110
 
111
  if ($multi_set_name_exists === NULL || $multi_set_field_exists === NULL) {
112
- yasr_create_tables();
113
  }
114
  }
115
 
10
 
11
  function yasr_update_version() {
12
  //do only in admin
 
13
  if (is_admin()) {
14
  global $yasr_version_installed;
15
  global $wpdb;
108
  $multi_set_field_exists = $wpdb->get_var("SELECT COUNT(1) FROM " . YASR_MULTI_SET_FIELDS_TABLE);
109
 
110
  if ($multi_set_name_exists === NULL || $multi_set_field_exists === NULL) {
111
+ YasrOnInstall::createTables();
112
  }
113
  }
114
 
img/Yasr-Stylish.png DELETED
Binary file
img/create-ranking.png DELETED
Binary file
img/dialog-ok-apply.png DELETED
Binary file
img/paypal.png DELETED
Binary file
img/yasr-user-reviews.png DELETED
Binary file
img/yasr_aggregate.jpg DELETED
Binary file
img/yasr_review.png DELETED
Binary file
includes/classes/YasrDatabaseRatings.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 for get overallRating and visitorVotes values
27
+ *
28
+ * Class YasrDatabaseRatings
29
+ */
30
+ class YasrDatabaseRatings {
31
+
32
+ /**
33
+ * @param $post_id void|bool|int
34
+ *
35
+ * @return mixed|null
36
+ */
37
+ public static function getOverallRating ($post_id=false) {
38
+ //if values it's not passed get the post id, since version 1.6.9 this is just for yasr_add_schema function
39
+ //and for a further check
40
+ if (!is_int($post_id)) {
41
+ $post_id = get_the_ID();
42
+ }
43
+
44
+ $overall_rating = get_post_meta($post_id, 'yasr_overall_rating', true);
45
+
46
+ if (!$overall_rating || $overall_rating < 0) {
47
+ $overall_rating = 0;
48
+ }
49
+ if($overall_rating > 5) {
50
+ $overall_rating = 5;
51
+ }
52
+ return $overall_rating;
53
+ }
54
+
55
+ /**
56
+ * @param bool|integer $post_id
57
+ *
58
+ * @return array|bool|mixed|object|null
59
+ */
60
+ public static function getVisitorVotes ($post_id = false) {
61
+ global $wpdb;
62
+
63
+ //if values it's not passed get the post id, most of cases and default one
64
+ if (!is_int($post_id)) {
65
+ $post_id = get_the_ID();
66
+ }
67
+
68
+ $result = $wpdb->get_results(
69
+ $wpdb->prepare(
70
+ "SELECT SUM(vote) as sum_votes,
71
+ COUNT(vote) as number_of_votes FROM "
72
+ . YASR_LOG_TABLE .
73
+ " WHERE post_id=%d",
74
+ $post_id
75
+ )
76
+ );
77
+
78
+ $array_to_return = array();
79
+ foreach ($result as $user_votes) {
80
+ $array_to_return['number_of_votes'] = (int)$user_votes->number_of_votes;
81
+ $array_to_return['sum_votes'] = (int)$user_votes->sum_votes;
82
+ }
83
+ return $array_to_return;
84
+ }
85
+
86
+ /**
87
+ * Check if an user has already rated, and if so, return the rating, or false otherwise
88
+ *
89
+ * @param int | bool $post_id
90
+ *
91
+ * @return bool|string
92
+ */
93
+ public static function visitorVotesHasUserVoted($post_id = false) {
94
+ global $wpdb;
95
+
96
+ $current_user = wp_get_current_user();
97
+ $user_id = $current_user->ID;
98
+
99
+ //just to be safe
100
+ if (!is_int($post_id)) {
101
+ $post_id = get_the_ID();
102
+ }
103
+
104
+ if (!is_int($user_id)) {
105
+ return false;
106
+ }
107
+
108
+ $rating = $wpdb->get_var(
109
+ $wpdb->prepare(
110
+ "SELECT vote FROM "
111
+ . YASR_LOG_TABLE .
112
+ " WHERE post_id=%d
113
+ AND user_id=%d
114
+ LIMIT 1 ",
115
+ $post_id, $user_id
116
+ )
117
+ );
118
+
119
+ if ($rating === null) {
120
+ $rating = false;
121
+ } else {
122
+ $rating = (int)$rating;
123
+ }
124
+ return $rating;
125
+ }
126
+
127
+ }
lib/yasr-db-classes.php → includes/classes/YasrMultiSetData.php RENAMED
@@ -22,110 +22,16 @@ if (!defined('ABSPATH')) {
22
  exit('You\'re not allowed to see this page');
23
  } // Exit if accessed directly
24
 
25
- class YasrDatabaseRatings {
26
-
27
- /**
28
- * @param $post_id void|bool|int
29
- *
30
- * @return mixed|null
31
- */
32
- public static function getOverallRating ($post_id=false) {
33
- //if values it's not passed get the post id, since version 1.6.9 this is just for yasr_add_schema function
34
- //and for a further check
35
- if (!is_int($post_id)) {
36
- $post_id = get_the_ID();
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
-
50
- /**
51
- * @param bool|integer $post_id
52
- *
53
- * @return array|bool|mixed|object|null
54
- */
55
- public static function getVisitorVotes ($post_id = false) {
56
- global $wpdb;
57
-
58
- //if values it's not passed get the post id, most of cases and default one
59
- if (!is_int($post_id)) {
60
- $post_id = get_the_ID();
61
- }
62
-
63
- $result = $wpdb->get_results(
64
- $wpdb->prepare(
65
- "SELECT SUM(vote) as sum_votes,
66
- COUNT(vote) as number_of_votes FROM "
67
- . YASR_LOG_TABLE .
68
- " WHERE post_id=%d",
69
- $post_id
70
- )
71
- );
72
-
73
- $array_to_return = array();
74
- foreach ($result as $user_votes) {
75
- $array_to_return['number_of_votes'] = (int)$user_votes->number_of_votes;
76
- $array_to_return['sum_votes'] = (int)$user_votes->sum_votes;
77
- }
78
- return $array_to_return;
79
- }
80
-
81
- /**
82
- * Check if an user has already rated, and if so, return the rating, or false otherwise
83
- *
84
- * @param int | bool $post_id
85
- *
86
- * @return bool|string
87
- */
88
- public static function visitorVotesHasUserVoted($post_id = false) {
89
- global $wpdb;
90
-
91
- $current_user = wp_get_current_user();
92
- $user_id = $current_user->ID;
93
-
94
- //just to be safe
95
- if (!is_int($post_id)) {
96
- $post_id = get_the_ID();
97
- }
98
-
99
- if (!is_int($user_id)) {
100
- return false;
101
- }
102
-
103
- $rating = $wpdb->get_var(
104
- $wpdb->prepare(
105
- "SELECT vote FROM "
106
- . YASR_LOG_TABLE .
107
- " WHERE post_id=%d
108
- AND user_id=%d
109
- LIMIT 1 ",
110
- $post_id, $user_id
111
- )
112
- );
113
-
114
- if ($rating === null) {
115
- $rating = false;
116
- } else {
117
- $rating = (int)$rating;
118
- }
119
- return $rating;
120
- }
121
-
122
- }
123
-
124
  class YasrMultiSetData {
125
  /**
126
  * @var array $array_to_return
127
  */
128
- static $array_to_return = array();
129
 
130
 
131
  /****** Get multi set name ******/
@@ -166,7 +72,7 @@ class YasrMultiSetData {
166
  WHERE f.parent_set_id=%d
167
  ORDER BY f.field_id
168
  ", $set_id),
169
- ARRAY_A);
170
 
171
  if (empty($result)) {
172
  return false;
22
  exit('You\'re not allowed to see this page');
23
  } // Exit if accessed directly
24
 
25
+ /**
26
+ * All functions needed to work with MultiSet
27
+ *
28
+ * Class YasrMultiSetData
29
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  class YasrMultiSetData {
31
  /**
32
  * @var array $array_to_return
33
  */
34
+ public static $array_to_return = array();
35
 
36
 
37
  /****** Get multi set name ******/
72
  WHERE f.parent_set_id=%d
73
  ORDER BY f.field_id
74
  ", $set_id),
75
+ ARRAY_A);
76
 
77
  if (empty($result)) {
78
  return false;
{css → includes/css}/yasr-table-dark.css RENAMED
File without changes
{css → includes/css}/yasr-table-light.css RENAMED
File without changes
{css → includes/css}/yasr.css RENAMED
@@ -190,8 +190,6 @@ yasr_pro_comment_reviews_stats shortcode too***/
190
 
191
  /*** Tooltip ***/
192
 
193
-
194
-
195
  .yasr-visitors-stats-tooltip {
196
  min-width:245px;
197
  text-align: center;
190
 
191
  /*** Tooltip ***/
192
 
 
 
193
  .yasr-visitors-stats-tooltip {
194
  min-width:245px;
195
  text-align: center;
{img → includes/img}/dark-multi-set.png RENAMED
File without changes
{img → includes/img}/loader.gif RENAMED
File without changes
{img → includes/img}/star_0.svg RENAMED
File without changes
{img → includes/img}/star_1.svg RENAMED
File without changes
{img → includes/img}/star_2.svg RENAMED
File without changes
{img → includes/img}/star_3.svg RENAMED
File without changes
{img → includes/img}/star_oxy_0.svg RENAMED
File without changes
{img → includes/img}/star_oxy_1.svg RENAMED
File without changes
{img → includes/img}/star_tiny.png RENAMED
File without changes
{img → includes/img}/stars_rater.png RENAMED
File without changes
{img → includes/img}/stars_rater_oxy.png RENAMED
File without changes
{img → includes/img}/stars_rater_yasr.png RENAMED
File without changes
{img → includes/img}/yasr-multi-set-insert-rate-small.jpg RENAMED
File without changes
{img → includes/img}/yasr-multi-set-insert-rate.jpg RENAMED
File without changes
{img → includes/img}/yasr-multi-set.png RENAMED
File without changes
{img → includes/img}/yasr-pro-stars.png RENAMED
File without changes
{img → includes/img}/yasr-stars-large.png RENAMED
File without changes
{img → includes/img}/yasr-stars-medium.png RENAMED
File without changes
{img → includes/img}/yasr-stars-small.png RENAMED
File without changes
{img → includes/img}/yasr_settings_stats_disabled.png RENAMED
File without changes
{img → includes/img}/yasr_settings_stats_enabled.png RENAMED
File without changes
{js → includes/js}/rater-js-rtl.js RENAMED
File without changes
{js → includes/js}/rater-js.js RENAMED
File without changes
{js → includes/js}/tippy.all.min.js RENAMED
File without changes
{js → includes/js}/yasr-front.js RENAMED
File without changes
{lib → includes}/rest/classes/YasrCustomEndpoint.php RENAMED
@@ -51,7 +51,6 @@ class YasrCustomEndpoint extends WP_REST_Controller {
51
  ),
52
  )
53
  );
54
-
55
  }
56
 
57
  /**
51
  ),
52
  )
53
  );
 
54
  }
55
 
56
  /**
{lib → includes}/rest/classes/YasrCustomFields.php RENAMED
@@ -126,7 +126,7 @@ class YasrCustomFields extends WP_REST_Controller {
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'),
@@ -139,7 +139,7 @@ class YasrCustomFields extends WP_REST_Controller {
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
  }
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'),
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
  }
{lib/rest → includes/rest/classes}/YasrPostMeta.php RENAMED
File without changes
{lib → includes}/rest/yasr-rest.php RENAMED
@@ -20,7 +20,7 @@ function yasr_autoload_rest_response($class) {
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)) {
20
  if (0 !== strpos($class, 'Yasr')) {
21
  return;
22
  }
23
+ $file_name = YASR_ABSOLUTE_PATH_INCLUDES . '/rest/classes/' . $class . '.php';
24
 
25
  // check if file exists, just to be sure
26
  if (file_exists($file_name)) {
{lib → includes}/shortcodes/classes/YasrMultiSet.php RENAMED
@@ -21,7 +21,6 @@ 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
  */
@@ -152,13 +151,11 @@ class YasrMultiSet extends YasrShortcode {
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
  }
21
  exit('You\'re not allowed to see this page');
22
  } // Exit if accessed directly
23
 
 
24
  /**
25
  * Class YasrMultiSet
26
  */
151
  * @return bool
152
  */
153
  public function show_average_multiset() {
154
+ if ( ( $this->show_average === '' && YASR_MULTI_SHOW_AVERAGE !== 'no' ) ||
155
+ ( $this->show_average !== '' && $this->show_average !== 'no' ) ) {
156
  return true;
157
  }
158
+ return false;
 
 
159
  }
160
 
161
  }
{lib → includes}/shortcodes/classes/YasrOverallRating.php RENAMED
File without changes
{lib → includes}/shortcodes/classes/YasrRankings.php RENAMED
@@ -21,7 +21,6 @@ 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
  */
21
  exit('You\'re not allowed to see this page');
22
  } // Exit if accessed directly
23
 
 
24
  /**
25
  * Class YasrRankings
26
  */
{lib → includes}/shortcodes/classes/YasrShortcode.php RENAMED
@@ -29,7 +29,7 @@ if (!defined('ABSPATH')) {
29
  * @since 2.1.5
30
  *
31
  */
32
- class YasrShortcode {
33
  public $shortcode_html;
34
  public $post_id; //false
35
  public $size; //large
29
  * @since 2.1.5
30
  *
31
  */
32
+ abstract class YasrShortcode {
33
  public $shortcode_html;
34
  public $post_id; //false
35
  public $size; //large
{lib → includes}/shortcodes/classes/YasrVisitorMultiSet.php RENAMED
@@ -21,7 +21,6 @@ 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
  */
21
  exit('You\'re not allowed to see this page');
22
  } // Exit if accessed directly
23
 
 
24
  /**
25
  * Class YasrVisitorMultiSet
26
  */
{lib → includes}/shortcodes/classes/YasrVisitorVotes.php RENAMED
File without changes
includes/shortcodes/yasr-shortcode-ajax.php ADDED
@@ -0,0 +1,392 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /****** Yasr insert visitor votes, called from yasr-shortcode-function ******/
26
+ add_action('wp_ajax_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback');
27
+ add_action('wp_ajax_nopriv_yasr_send_visitor_rating', 'yasr_insert_visitor_votes_callback');
28
+
29
+ function yasr_insert_visitor_votes_callback() {
30
+
31
+ if (isset($_POST['rating']) && isset($_POST['post_id']) && isset($_POST['nonce_visitor'])) {
32
+
33
+ $rating = (int) $_POST['rating'];
34
+ $post_id = (int) $_POST['post_id'];
35
+ $nonce_visitor = $_POST['nonce_visitor'];
36
+ $is_singular = $_POST['is_singular'];
37
+
38
+ if (!is_int($post_id)) {
39
+ exit();
40
+ }
41
+
42
+ } else {
43
+ exit();
44
+ }
45
+
46
+ $array_action_visitor_vote = array('post_id' => $post_id, 'is_singular' => $is_singular);
47
+
48
+ do_action('yasr_action_on_visitor_vote', $array_action_visitor_vote);
49
+
50
+ if (!wp_verify_nonce($nonce_visitor, 'yasr_nonce_insert_visitor_rating')) {
51
+ die('Security check');
52
+ }
53
+
54
+ if ($rating < 1) {
55
+ $rating = 1;
56
+ } elseif ($rating > 5) {
57
+ $rating = 5;
58
+ }
59
+
60
+ global $wpdb;
61
+
62
+ $current_user = wp_get_current_user();
63
+ $ip_adress = yasr_get_ip();
64
+
65
+ $result_update_log = null; //avoid undefined
66
+ $result_insert_log = null; //avoid undefined
67
+
68
+ if (is_user_logged_in()) {
69
+
70
+ //try to update first, if fails the do the insert
71
+ $result_update_log = $wpdb->update(
72
+ YASR_LOG_TABLE,
73
+ array(
74
+ 'post_id' => $post_id,
75
+ 'user_id' => $current_user->ID,
76
+ 'vote' => $rating,
77
+ 'date' => date('Y-m-d H:i:s'),
78
+ 'ip' => $ip_adress
79
+ ),
80
+ array(
81
+ 'post_id' => $post_id,
82
+ 'user_id' => $current_user->ID
83
+ ),
84
+ array('%d', '%d', '%d', '%s', '%s', '%s'),
85
+ array('%d', '%d')
86
+
87
+ );
88
+
89
+ //insert the new row
90
+ //use ! instead of === FALSE
91
+ if (!$result_update_log) {
92
+ $result_insert_log = $wpdb->insert(
93
+ YASR_LOG_TABLE,
94
+ array(
95
+ 'post_id' => $post_id,
96
+ 'user_id' => $current_user->ID,
97
+ 'vote' => $rating,
98
+ 'date' => date('Y-m-d H:i:s'),
99
+ 'ip' => $ip_adress
100
+ ),
101
+ array('%d', '%d', '%d', '%s', '%s', '%s')
102
+ );
103
+ }
104
+
105
+ } //if user is not logged in insert
106
+ else {
107
+
108
+ //be sure that allow anonymous is on
109
+ if (YASR_ALLOWED_USER === 'allow_anonymous') {
110
+ $result_insert_log = $wpdb->replace(
111
+ YASR_LOG_TABLE,
112
+ array(
113
+ 'post_id' => $post_id,
114
+ 'user_id' => $current_user->ID,
115
+ 'vote' => $rating,
116
+ 'date' => date('Y-m-d H:i:s'),
117
+ 'ip' => $ip_adress
118
+ ),
119
+
120
+ array('%d', '%d', '%d', '%s', '%s', '%s')
121
+ );
122
+ }
123
+
124
+ }
125
+
126
+ if ($result_update_log || $result_insert_log) {
127
+ $row_exists = YasrDatabaseRatings::getVisitorVotes($post_id);
128
+
129
+ $user_votes_sum = $row_exists['sum_votes'];
130
+ $number_of_votes = $row_exists['number_of_votes'];
131
+
132
+ $cookiename = 'yasr_visitor_vote_cookie';
133
+
134
+ $data_to_save = array(
135
+ 'post_id' => $post_id,
136
+ 'rating' => $rating
137
+ );
138
+
139
+ yasr_setcookie($cookiename, $data_to_save);
140
+
141
+ $total_rating = ($user_votes_sum / $number_of_votes);
142
+ $medium_rating = round($total_rating, 1);
143
+
144
+ $html_to_return = '<span class="yasr-total-average-text"> ['
145
+ . __('Total:', 'yet-another-stars-rating') .
146
+ " $number_of_votes &nbsp; &nbsp;"
147
+ . __('Average:', 'yet-another-stars-rating') .
148
+ " $medium_rating/5 ]
149
+ </span>";
150
+ $html_to_return .= '<span class="yasr-small-block-bold" id="yasr-vote-saved">'
151
+ . __('Vote Saved', 'yet-another-stars-rating') .
152
+ '</span>';
153
+
154
+ echo json_encode($html_to_return);
155
+
156
+ }
157
+
158
+ die(); // this is required to return a proper result
159
+
160
+ }
161
+
162
+ /****** Get Multiple value from visitor and insert into db, used in yasr-shortcode-functions ******/
163
+
164
+ add_action('wp_ajax_yasr_visitor_multiset_field_vote', 'yasr_visitor_multiset_field_vote_callback');
165
+ add_action('wp_ajax_nopriv_yasr_visitor_multiset_field_vote', 'yasr_visitor_multiset_field_vote_callback');
166
+
167
+ function yasr_visitor_multiset_field_vote_callback() {
168
+
169
+ if (isset($_POST['post_id']) && isset($_POST['rating']) && isset($_POST['set_type'])) {
170
+ $post_id = (int) $_POST['post_id'];
171
+ $rating = $_POST['rating'];
172
+ $set_type = (int) $_POST['set_type'];
173
+ $nonce = $_POST['nonce'];
174
+
175
+ if (!is_int($post_id) || !is_int($set_type)) {
176
+ exit("Missing post id or set type");
177
+ }
178
+
179
+ if ($rating == "") {
180
+ exit("You must insert at least a rating");
181
+ }
182
+
183
+ } else {
184
+ exit();
185
+ }
186
+
187
+ if (!wp_verify_nonce($nonce, 'yasr_nonce_insert_visitor_rating_multiset')) {
188
+ die('Security Check');
189
+ }
190
+
191
+ $current_user = wp_get_current_user();
192
+ $ip_adress = yasr_get_ip();
193
+
194
+ $array_action_visitor_multiset_vote = array('post_id' => $post_id);
195
+
196
+ do_action('yasr_action_on_visitor_multiset_vote', $array_action_visitor_multiset_vote);
197
+
198
+ global $wpdb;
199
+
200
+ $array_error = array();
201
+
202
+ //clean array, so if an user rate same field twice, take only the last rating
203
+ $cleaned_array = yasr_unique_multidim_array($rating, 'field');
204
+
205
+ //this is a counter: if at the end of the foreach it still 0, means that an user rated in a set
206
+ //and then submit another one
207
+ $counter_matched_fields = 0;
208
+
209
+ foreach ($cleaned_array as $rating_values) {
210
+
211
+ //check if the set id in the array is the same of the clicked
212
+ if ($rating_values['postid'] == $post_id && $rating_values['setid'] == $set_type) {
213
+
214
+ //increase the counter
215
+ $counter_matched_fields = $counter_matched_fields + 1;
216
+
217
+ $id_field = $rating_values['field'];
218
+ $rating = $rating_values['rating'];
219
+
220
+ $query_success = $wpdb->insert(
221
+ YASR_LOG_MULTI_SET,
222
+ array(
223
+ 'field_id' => $id_field,
224
+ 'set_type' => $set_type,
225
+ 'post_id' => $post_id,
226
+ 'vote' => $rating,
227
+ 'user_id' => $current_user->ID,
228
+ 'date' => date('Y-m-d H:i:s'),
229
+ 'ip' => $ip_adress
230
+
231
+ ),
232
+ array("%d", "%d", "%d", "%d", "%d", "%s", "%s")
233
+ );
234
+
235
+ if ($query_success) {
236
+ $array_error[] = 0;
237
+ } else {
238
+ $array_error[] = 1;
239
+ }
240
+
241
+ } //End if $rating_values['postid'] == $post_id
242
+
243
+ } //End foreach ($rating as $rating_values)
244
+
245
+ if ($counter_matched_fields === 0) {
246
+ $array_error[] = 1;
247
+ }
248
+
249
+ $error_found = false;
250
+
251
+ foreach ($array_error as $error) {
252
+ if ($error === 1) {
253
+ $error_found = true;
254
+ }
255
+ }
256
+
257
+ if (!$error_found) {
258
+ $cookiename = 'yasr_multi_visitor_cookie';
259
+
260
+ $data_to_save = array(
261
+ 'post_id' => $post_id,
262
+ 'set_id' => $set_type
263
+ );
264
+
265
+ yasr_setcookie($cookiename, $data_to_save);
266
+
267
+ _e('Rating saved!', 'yet-another-stars-rating');
268
+
269
+ } else {
270
+ _e('Rating not saved. Please Try again', 'yet-another-stars-rating');
271
+ }
272
+
273
+ die();
274
+
275
+ } //End callback function
276
+
277
+
278
+ add_action('wp_ajax_yasr_stats_visitors_votes', 'yasr_stats_visitors_votes_callback');
279
+ add_action('wp_ajax_nopriv_yasr_stats_visitors_votes', 'yasr_stats_visitors_votes_callback');
280
+
281
+ function yasr_stats_visitors_votes_callback() {
282
+
283
+ if (isset($_POST['post_id']) && $_POST['post_id'] !== '') {
284
+ $post_id = (int)$_POST['post_id'];
285
+ } else {
286
+ return;
287
+ }
288
+
289
+ $votes_array = YasrDatabaseRatings::getVisitorVotes($post_id);
290
+ $votes_number = $votes_array['number_of_votes'];
291
+
292
+ if ($votes_number != 0) {
293
+ $medium_rating = ($votes_array['sum_votes'] / $votes_number);
294
+ } else {
295
+ $medium_rating = 0;
296
+ }
297
+
298
+ $medium_rating = round($medium_rating, 1);
299
+ $missing_vote = null; //avoid undefined variable
300
+
301
+ global $wpdb;
302
+
303
+ //create an empty array
304
+ $existing_votes = array();
305
+
306
+ $stats = $wpdb->get_results($wpdb->prepare("SELECT ROUND( vote, 0 ) as vote, COUNT( vote ) AS n_of_votes
307
+ FROM " . YASR_LOG_TABLE . "
308
+ WHERE post_id=%d
309
+ GROUP BY vote
310
+ ORDER BY vote DESC
311
+ ",
312
+ $post_id),
313
+ ARRAY_A);
314
+
315
+ $total_votes = 0; //Avoid undefined variable if stats exists. Necessary if $stats not exists
316
+
317
+ //if query return 0 write an empty array $existing_votes
318
+ if ($stats) {
319
+ //Write a new array with only existing votes, and count all the number of votes
320
+ foreach ($stats as $votes_array) {
321
+ $existing_votes[] = $votes_array['vote'];//Create an array with only existing votes
322
+ $total_votes = $total_votes + $votes_array['n_of_votes'];
323
+ }
324
+ }
325
+
326
+ for ($i = 1; $i <= 5; $i ++) {
327
+ //If query return 0 write a new $stats array with index
328
+ if (!$stats) {
329
+ $stats[$i] = array();
330
+ $stats[$i]['vote'] = $i;
331
+ $stats[$i]['n_of_votes'] = 0;
332
+ } else {
333
+ //If in the new array there are some vote missing create a new array
334
+ if (!in_array($i, $existing_votes)) {
335
+ $missing_vote[$i] = array();
336
+ $missing_vote[$i]['vote'] = $i;
337
+ $missing_vote[$i]['n_of_votes'] = 0;
338
+ }
339
+ }
340
+ }
341
+
342
+ //If missing_vote exists merge it
343
+ if ($missing_vote) {
344
+ $stats = array_merge($stats, $missing_vote);
345
+ }
346
+
347
+ arsort($stats); //sort it by $votes[n_of_votes]
348
+
349
+ $html_to_return = '<div class="yasr-visitors-stats-tooltip">';
350
+ $html_to_return .= '<span id="yasr-medium-rating-tooltip">' . $medium_rating . ' '
351
+ . __('out of 5 stars', 'yet-another-stars-rating') .
352
+ '</span>';
353
+ $html_to_return .= '<div class="yasr-progress-bars-container">';
354
+
355
+ if ($total_votes === 0) {
356
+ $increase_bar_value = 0;
357
+ } else {
358
+ $increase_bar_value = 100 / $total_votes; //Find how much all the bars should increase per vote
359
+ }
360
+
361
+ $i = 5;
362
+
363
+ $stars_text = __('stars', 'yet-another-stars-rating');
364
+
365
+ foreach ($stats as $logged_votes) {
366
+
367
+ if ($i === 1) {
368
+ $stars_text = __('star', 'yet-another-stars-rating');
369
+ }
370
+
371
+ $value_progressbar = $increase_bar_value * $logged_votes['n_of_votes']; //value of the single bar
372
+ $value_progressbar = round($value_progressbar, 2) . '%'; //use only 2 decimal
373
+
374
+ $html_to_return .= "<div class='yasr-progress-bar-row-container yasr-w3-container'>
375
+ <div class='yasr-progress-bar-name'>$i $stars_text</div>
376
+ <div class='yasr-single-progress-bar-container'>
377
+ <div class='yasr-w3-border '>
378
+ <div class='yasr-w3-amber' style='height:17px;width:$value_progressbar'></div>
379
+ </div></div>
380
+ <div class='yasr-progress-bar-votes-count'>" . $logged_votes['n_of_votes'] . "</div><br />
381
+ </div>";
382
+
383
+ $i --;
384
+
385
+ } //End foreach
386
+
387
+ $html_to_return .= '</div></div>';
388
+ echo json_encode($html_to_return);
389
+
390
+ die();
391
+
392
+ }
{lib → includes}/shortcodes/yasr-shortcode-functions.php RENAMED
@@ -35,7 +35,7 @@ function yasr_autoload_shortcodes($class) {
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)) {
@@ -43,9 +43,11 @@ function yasr_autoload_shortcodes($class) {
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');
@@ -56,11 +58,6 @@ add_shortcode('yasr_overall_rating', 'shortcode_overall_rating_callback');
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
  }
@@ -69,7 +66,6 @@ function shortcode_overall_rating_callback ($atts) {
69
  $overall_rating = new YasrOverallRating($atts, $shortcode_name);
70
 
71
  return $overall_rating->printOverallRating();
72
-
73
  } //end function
74
 
75
 
@@ -83,11 +79,6 @@ add_shortcode('yasr_visitor_votes', 'shortcode_visitor_votes_callback');
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
  }
@@ -112,11 +103,6 @@ add_shortcode ('yasr_multiset', 'yasr_multiset_callback');
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
 
@@ -133,11 +119,6 @@ add_shortcode ('yasr_visitor_multiset', 'yasr_visitor_multiset_callback');
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
 
@@ -155,11 +136,6 @@ add_shortcode ('yasr_top_ten_highest_rated', 'yasr_top_ten_highest_rated_callbac
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();
@@ -167,19 +143,12 @@ function yasr_top_ten_highest_rated_callback() {
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();
@@ -187,18 +156,11 @@ function yasr_most_or_highest_rated_posts_callback () {
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
@@ -261,20 +223,12 @@ function yasr_top_5_reviewers_callback () {
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
35
  if (0 !== strpos($class, 'Yasr')) {
36
  return;
37
  }
38
+ $file_name = YASR_ABSOLUTE_PATH_INCLUDES . '/shortcodes/classes/' . $class . '.php';
39
 
40
  // check if file exists, just to be sure
41
  if (file_exists($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
+ require YASR_ABSOLUTE_PATH_INCLUDES . '/shortcodes/yasr-shortcode-ajax.php';
50
+
51
 
52
  /****** Add shortcode for overall rating ******/
53
  add_shortcode('yasr_overall_rating', 'shortcode_overall_rating_callback');
58
  * @return string|void|null
59
  */
60
  function shortcode_overall_rating_callback ($atts) {
 
 
 
 
 
61
  if (YASR_SHOW_OVERALL_IN_LOOP === 'disabled' && !is_singular() && is_main_query()) {
62
  return;
63
  }
66
  $overall_rating = new YasrOverallRating($atts, $shortcode_name);
67
 
68
  return $overall_rating->printOverallRating();
 
69
  } //end function
70
 
71
 
79
  * @return string|void|null
80
  */
81
  function shortcode_visitor_votes_callback($atts) {
 
 
 
 
 
82
  if (YASR_SHOW_VISITOR_VOTES_IN_LOOP === 'disabled' && !is_singular() && is_main_query()) {
83
  return;
84
  }
103
  * @return string|void|null
104
  */
105
  function yasr_multiset_callback($atts) {
 
 
 
 
 
106
  $shortcode_name = 'yasr_multiset';
107
  $multiset = new YasrMultiSet($atts, $shortcode_name);
108
 
119
  * @return string|void|null
120
  */
121
  function yasr_visitor_multiset_callback($atts) {
 
 
 
 
 
122
  $shortcode_name = 'yasr_visitor_multiset';
123
  $multiset = new YasrVisitorMultiSet($atts, $shortcode_name);
124
 
136
  * @return string|void|null
137
  */
138
  function yasr_top_ten_highest_rated_callback() {
 
 
 
 
 
139
  $top_ten_highest_obj = new YasrRankings(false, 'yasr_top_ten_highest_rated');
140
 
141
  return $top_ten_highest_obj->returnHighestRatedOverall();
143
 
144
 
145
  /****** Add top 10 most rated / highest rated post *****/
 
146
  add_shortcode ('yasr_most_or_highest_rated_posts', 'yasr_most_or_highest_rated_posts_callback');
 
147
  /**
148
  *
149
  * @return string|void|null
150
  */
151
  function yasr_most_or_highest_rated_posts_callback () {
 
 
 
 
 
152
  $most_highest_obj = new YasrRankings(false, 'yasr_most_or_highest_rated_posts');
153
 
154
  return $most_highest_obj->vvReturnMostHighestRatedPost();
156
 
157
 
158
  /****** Add top 5 most active reviewer ******/
 
159
  add_shortcode ('yasr_top_5_reviewers', 'yasr_top_5_reviewers_callback');
 
160
  /**
161
  * @return string|void
162
  */
163
  function yasr_top_5_reviewers_callback () {
 
 
 
 
 
164
  global $wpdb;
165
 
166
  $query_result = $wpdb->get_results("SELECT COUNT( pm.post_id ) AS total_count, p.post_author AS reviewer
223
 
224
  } //End top 5 reviewers function
225
 
 
226
  /****** Add top 10 most active user *****/
 
227
  add_shortcode ('yasr_top_ten_active_users', 'yasr_top_ten_active_users_callback');
 
228
  /**
229
  * @return string|void
230
  */
231
  function yasr_top_ten_active_users_callback () {
 
 
 
 
 
232
  global $wpdb;
233
 
234
  $query_result = $wpdb->get_results("SELECT COUNT( user_id ) as total_count, user_id as user
includes/yasr-includes-db-functions.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Return the postmeta itemType
26
+ *
27
+ * @return bool|string
28
+ */
29
+ function yasr_get_itemType() {
30
+ $review_types = json_decode(YASR_SUPPORTED_SCHEMA_TYPES);
31
+ $post_id = get_the_ID();
32
+
33
+ if (!$post_id) {
34
+ return false;
35
+ }
36
+
37
+ $result = get_post_meta($post_id, 'yasr_review_type', true);
38
+
39
+ if ($result) {
40
+ $snippet_type = trim($result);
41
+
42
+ //to keep compatibility with version <2.2.3
43
+ if($snippet_type === 'Place') {
44
+ $snippet_type = 'LocalBusiness';
45
+ }
46
+ //to keep compatibility with version <2.2.3
47
+ if($snippet_type === 'Other') {
48
+ $snippet_type = 'BlogPosting';
49
+ }
50
+
51
+ if (!in_array($snippet_type, $review_types)) {
52
+ $snippet_type = YASR_ITEMTYPE;
53
+ }
54
+
55
+ } else {
56
+ $snippet_type = YASR_ITEMTYPE;
57
+ }
58
+
59
+ return $snippet_type;
60
+
61
+ }
includes/yasr-includes-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
+ /*** Css rules for stars set, from version 1.2.7
26
+ * Here I use add_action instead of directly use wp_add_inline_style so I can
27
+ * use remove_action if needed (e.g. Yasr Stylish)
28
+ ***/
29
+ add_action('yasr_add_front_script_css', 'yasr_css_stars_set');
30
+ add_action('yasr_add_admin_scripts_end', 'yasr_css_stars_set');
31
+
32
+ function yasr_css_stars_set() {
33
+
34
+ //if star selected is "rater", select the images
35
+ if (YASR_STARS_SET === 'rater') {
36
+ $star_grey = YASR_IMG_DIR . 'star_0.svg';
37
+ $star_yellow = YASR_IMG_DIR . 'star_1.svg';
38
+ } elseif (YASR_STARS_SET === 'rater-oxy') {
39
+ $star_grey = YASR_IMG_DIR . 'star_oxy_0.svg';
40
+ $star_yellow = YASR_IMG_DIR . 'star_oxy_1.svg';
41
+ } //by default, use the one provided by Yasr
42
+ else {
43
+ $star_grey = YASR_IMG_DIR . 'star_2.svg';
44
+ $star_yellow = YASR_IMG_DIR . 'star_3.svg';
45
+ }
46
+
47
+
48
+ $yasr_st_css = "
49
+ .yasr-star-rating {
50
+ background-image: url(\"$star_grey\");
51
+ }
52
+ .yasr-star-rating .yasr-star-value {
53
+ background: url(\"$star_yellow\") ;
54
+ }
55
+ ";
56
+
57
+ wp_add_inline_style('yasrcss', $yasr_st_css);
58
+
59
+ }
60
+
61
+ add_action('yasr_add_front_script_css', 'yasr_rtl_support');
62
+ add_action('yasr_add_admin_scripts_end', 'yasr_rtl_support');
63
+
64
+ function yasr_rtl_support() {
65
+ if (is_rtl()) {
66
+ $yasr_rtl_css = '.yasr-star-rating .yasr-star-value {
67
+ -moz-transform: scaleX(-1);
68
+ -o-transform: scaleX(-1);
69
+
70
+ -webkit-transform: scaleX(-1);
71
+ transform: scaleX(-1);
72
+ filter: FlipH;
73
+ -ms-filter: "FlipH";
74
+ right: 0;
75
+ left: auto;
76
+ }';
77
+
78
+ wp_add_inline_style('yasrcss', $yasr_rtl_css);
79
+ }
80
+ }
81
+
82
+
83
+ /****** Translating YASR ******/
84
+ add_action('init', 'yasr_translate_option', 110);
85
+
86
+ function yasr_translate_option() {
87
+ load_plugin_textdomain('yet-another-stars-rating', false, YASR_LANG_DIR);
88
+ }
89
+
90
+ /**
91
+ * Create a select menu to choose the rich snippet itemtype
92
+ *
93
+ * @param bool|string $html_id
94
+ */
95
+
96
+ function yasr_select_itemtype($html_id=false) {
97
+
98
+ if($html_id === false) {
99
+ $html_id = 'yasr-choose-reviews-types-list';
100
+ }
101
+
102
+ $review_types = json_decode(YASR_SUPPORTED_SCHEMA_TYPES);
103
+
104
+ sort($review_types);
105
+ $review_type_choosen = yasr_get_itemType();
106
+ ?>
107
+
108
+ <label for="<?php echo $html_id ?>"></label>
109
+ <select name="yasr-review-type" id="<?php echo $html_id ?>">
110
+ <?php
111
+ foreach ($review_types as $type) {
112
+ $type = trim($type);
113
+ $type_option = $type;
114
+ if ($type === $review_type_choosen) {
115
+ echo "<option value=\"$type\" selected>$type_option</option>";
116
+ } else {
117
+ echo "<option value=\"$type\">$type_option</option>";
118
+ }
119
+ }
120
+ ?>
121
+ </select>
122
+
123
+ <?php
124
+ } //End function yasr_select_itemtype()
125
+
126
+ /**
127
+ * @return bool|string[]|WP_Post_Type[]
128
+ */
129
+ function yasr_get_custom_post_type() {
130
+
131
+ $args = array(
132
+ 'public' => true,
133
+ '_builtin' => false
134
+ );
135
+
136
+ $output = 'names'; // names or objects, note names is the default
137
+ $operator = 'and'; // 'and' or 'or'
138
+
139
+ //if not found, returns an empty array
140
+ $post_types = get_post_types($args, $output, $operator);
141
+
142
+ if ($post_types) {
143
+ return ($post_types);
144
+ }
145
+
146
+ return false;
147
+ }
148
+
149
+ function yasr_return_all_post_types () {
150
+ $args = array(
151
+ 'public' => true,
152
+ );
153
+
154
+ $output = 'names';
155
+ $operator = 'and';
156
+
157
+ return get_post_types($args, $output, $operator);
158
+ }
159
+
160
+ /*** Function to set cookie, since version 0.8.3 ***/
161
+ function yasr_setcookie($cookiename, $data_to_save) {
162
+
163
+ if (!$data_to_save || !$cookiename) {
164
+ exit('Error setting yasr cookie');
165
+ }
166
+
167
+ $existing_data = array(); //avoid undefined index
168
+
169
+ if (isset($_COOKIE[$cookiename])) {
170
+
171
+ //setcookie add \ , so I need to stripslahes
172
+ $existing_data = stripslashes($_COOKIE[$cookiename]);
173
+
174
+ //By default, json_decode return an object, TRUE to return an array
175
+ $existing_data = json_decode($existing_data, true);
176
+
177
+ }
178
+
179
+ //whetever exists or not, push into at the end of array
180
+ $existing_data[] = $data_to_save;
181
+
182
+ $encoded_data = json_encode($existing_data);
183
+
184
+ setcookie($cookiename, $encoded_data, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false);
185
+
186
+ }
187
+
188
+ /*** Function to get ip, since version 0.8.8
189
+ * This code can be found on http://codex.wordpress.org/Plugin_API/Filter_Reference/pre_comment_user_ip
190
+ ***/
191
+
192
+ function yasr_get_ip() {
193
+
194
+ if (YASR_ENABLE_IP === 'yes') {
195
+ $ip = null;
196
+ $ip = apply_filters('yasr_filter_ip', $ip);
197
+
198
+ if (isset($ip)) {
199
+ return $ip;
200
+ }
201
+ $REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
202
+
203
+ if (!empty($_SERVER['X_FORWARDED_FOR'])) {
204
+ $X_FORWARDED_FOR = explode(',', $_SERVER['X_FORWARDED_FOR']);
205
+ if (!empty($X_FORWARDED_FOR)) {
206
+ $REMOTE_ADDR = trim($X_FORWARDED_FOR[0]);
207
+ }
208
+ }
209
+ /*
210
+ * Some php environments will use the $_SERVER['HTTP_X_FORWARDED_FOR']
211
+ * variable to capture visitor address information.
212
+ */
213
+
214
+ elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
215
+ $HTTP_X_FORWARDED_FOR = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
216
+ if (!empty($HTTP_X_FORWARDED_FOR)) {
217
+ $REMOTE_ADDR = trim($HTTP_X_FORWARDED_FOR[0]);
218
+ }
219
+ }
220
+ return preg_replace('/[^0-9a-f:., ]/si', '', $REMOTE_ADDR);
221
+ }
222
+ return ('X.X.X.X');
223
+ }
224
+
225
+
226
+ /*function to remove duplicate in an array for a specific key
227
+ Taken value: array to search, key
228
+ */
229
+ function yasr_unique_multidim_array($array, $key) {
230
+
231
+ $temp_array = array();
232
+ $i = 0;
233
+
234
+ //creo un array vuoto che conterrà solo gli indici
235
+ $key_array = array();
236
+
237
+ foreach ($array as $val) {
238
+ $result_search_array = array_search($val[$key], $key_array);
239
+
240
+ $key_array[$i] = $val[$key];
241
+ $temp_array[$i] = $val;
242
+
243
+ //if result is found
244
+ if ($result_search_array !== false) {
245
+ unset($key_array[$result_search_array], $temp_array[$result_search_array]);
246
+ }
247
+ $i ++;
248
+ }
249
+ sort($temp_array);
250
+ return $temp_array;
251
+ }
252
+
253
+ function yasr_check_valid_url($url) {
254
+
255
+ $timeout = 5;
256
+
257
+ //Check if url is valid
258
+ if (filter_var($url, FILTER_VALIDATE_URL) !== false) {
259
+
260
+ //Check if curl is installed
261
+ if (function_exists('curl_version')) {
262
+
263
+ $ch = curl_init();
264
+ curl_setopt($ch, CURLOPT_URL, $url);
265
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
266
+ curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
267
+
268
+ //execute curl
269
+ $http_respond = trim(strip_tags(curl_exec($ch)));
270
+ $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
271
+
272
+ //Check the response
273
+ if (($http_code == '200') || ($http_code == '302')) {
274
+ return true;
275
+ }
276
+
277
+ return false;
278
+ //close curl
279
+ curl_close($ch);
280
+
281
+ } //if curl is not installed, use file_get_contents
282
+ else {
283
+ //...but only if enabled on the server!
284
+ if (ini_get('allow_url_fopen')) {
285
+
286
+ //Change timeout for file_get_contents
287
+ ini_set('default_socket_timeout', $timeout); //5 seconds
288
+
289
+ $headers = get_headers($url, 1);
290
+ $string_to_check = '200 OK';
291
+
292
+ //check if in the first heade we've 200 OK
293
+ if (strpos($headers[0], $string_to_check) !== false) {
294
+ return true;
295
+ }
296
+
297
+ return false;
298
+ } //if url_fopen is not enabled
299
+
300
+ return false;
301
+
302
+ }
303
+ } else {
304
+ return false;
305
+ }
306
+
307
+ }
308
+
309
+
310
+ /**
311
+ * Check if the given string is a supported itemType
312
+ *
313
+ * @param string $item_type
314
+ * @return bool
315
+ *
316
+ * @since 2.1.5
317
+ */
318
+
319
+ function yasr_is_supported_schema ($item_type) {
320
+ $supported_schema_array = json_decode(YASR_SUPPORTED_SCHEMA_TYPES);
321
+
322
+ if (in_array($item_type, $supported_schema_array)) {
323
+ return true;
324
+ }
325
+
326
+ return false;
327
+ }
includes/yasr-includes-init.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ //e.g. http://localhost/plugin_development/wp-content/plugins/yet-another-stars-rating/includes/js/
25
+ define('YASR_JS_DIR_INCLUDES', plugins_url() . '/' . YASR_RELATIVE_PATH_INCLUDES . '/js/');
26
+ //CSS directory absolute URL
27
+ define('YASR_CSS_DIR_INCLUDES', plugins_url() . '/' . YASR_RELATIVE_PATH_INCLUDES . '/css/');
28
+
29
+ require YASR_ABSOLUTE_PATH_INCLUDES . '/yasr-includes-functions.php';
30
+ require YASR_ABSOLUTE_PATH_INCLUDES . '/yasr-includes-db-functions.php';
31
+ require YASR_ABSOLUTE_PATH_INCLUDES . '/yasr-widgets.php';
32
+ require YASR_ABSOLUTE_PATH_INCLUDES . '/shortcodes/yasr-shortcode-functions.php';
33
+ require YASR_ABSOLUTE_PATH_INCLUDES . '/rest/yasr-rest.php';
34
+
35
+ /**
36
+ * Callback function for the spl_autoload_register above.
37
+ *
38
+ * @param $class
39
+ */
40
+ function yasr_autoload_includes_classes($class) {
41
+ /**
42
+ * If the class being requested does not start with 'Yasr' prefix,
43
+ * it's not in Yasr Project
44
+ */
45
+ if (0 !== strpos($class, 'Yasr')) {
46
+ return;
47
+ }
48
+ $file_name = YASR_ABSOLUTE_PATH_INCLUDES . '/classes/' . $class . '.php';
49
+
50
+ // check if file exists, just to be sure
51
+ if (file_exists($file_name)) {
52
+ require($file_name);
53
+ }
54
+ }
55
+
56
+ //AutoLoad Yasr Shortcode Classes, only when a object is created
57
+ spl_autoload_register('yasr_autoload_includes_classes');
58
+
59
+ /****** Getting options ******/
60
+ //Get general options
61
+ $yasr_stored_options = get_option('yasr_general_options');
62
+
63
+ global $yasr_stored_options;
64
+
65
+ define('YASR_AUTO_INSERT_ENABLED', (int)$yasr_stored_options['auto_insert_enabled']);
66
+
67
+ if (YASR_AUTO_INSERT_ENABLED === 1) {
68
+ define('YASR_AUTO_INSERT_WHAT', $yasr_stored_options['auto_insert_what']);
69
+ define('YASR_AUTO_INSERT_WHERE', $yasr_stored_options['auto_insert_where']);
70
+ define('YASR_AUTO_INSERT_ALIGN', $yasr_stored_options['auto_insert_align']);
71
+ define('YASR_AUTO_INSERT_SIZE', $yasr_stored_options['auto_insert_size']);
72
+ define('YASR_AUTO_INSERT_EXCLUDE_PAGES', $yasr_stored_options['auto_insert_exclude_pages']);
73
+ define('YASR_AUTO_INSERT_CUSTOM_POST_ONLY', $yasr_stored_options['auto_insert_custom_post_only']);
74
+ }
75
+ else {
76
+ define('YASR_AUTO_INSERT_WHAT', null);
77
+ define('YASR_AUTO_INSERT_WHERE', null);
78
+ define('YASR_AUTO_INSERT_ALIGN', null);
79
+ define('YASR_AUTO_INSERT_SIZE', null);
80
+ define('YASR_AUTO_INSERT_EXCLUDE_PAGES', null);
81
+ define('YASR_AUTO_INSERT_CUSTOM_POST_ONLY', null);
82
+ }
83
+
84
+ define('YASR_SHOW_OVERALL_IN_LOOP', $yasr_stored_options['show_overall_in_loop']);
85
+ define('YASR_SHOW_VISITOR_VOTES_IN_LOOP', $yasr_stored_options['show_visitor_votes_in_loop']);
86
+ define('YASR_TEXT_BEFORE_STARS', (int)$yasr_stored_options['text_before_stars']);
87
+
88
+ if (YASR_TEXT_BEFORE_STARS === 1) {
89
+ define(
90
+ 'YASR_TEXT_BEFORE_OVERALL',
91
+ htmlspecialchars_decode($yasr_stored_options['text_before_overall'])
92
+ );
93
+ define(
94
+ 'YASR_TEXT_BEFORE_VISITOR_RATING',
95
+ htmlspecialchars_decode($yasr_stored_options['text_before_visitor_rating'])
96
+ );
97
+ define(
98
+ 'YASR_TEXT_AFTER_VISITOR_RATING',
99
+ htmlspecialchars_decode($yasr_stored_options['text_after_visitor_rating'])
100
+ );
101
+ define(
102
+ 'YASR_CUSTOM_TEXT_USER_VOTED',
103
+ htmlspecialchars_decode($yasr_stored_options['custom_text_user_voted'])
104
+ );
105
+ define(
106
+ 'YASR_CUSTOM_TEXT_MUST_SIGN_IN',
107
+ htmlspecialchars_decode($yasr_stored_options['custom_text_must_sign_in'])
108
+ );
109
+ }
110
+
111
+ define('YASR_VISITORS_STATS', $yasr_stored_options['visitors_stats']);
112
+ define('YASR_ALLOWED_USER', $yasr_stored_options['allowed_user']);
113
+ define('YASR_ENABLE_IP', $yasr_stored_options['enable_ip']);
114
+ define('YASR_ITEMTYPE', $yasr_stored_options['snippet_itemtype']);
115
+
116
+ if (isset($yasr_stored_options['blogposting_organization_name'])) {
117
+ define('YASR_BLOGPOSTING_ORGANIZATION_NAME', $yasr_stored_options['blogposting_organization_name']);
118
+ } else {
119
+ define('YASR_BLOGPOSTING_ORGANIZATION_NAME', '');
120
+ }
121
+
122
+ if (isset($yasr_stored_options['blogposting_organization_logo'])) {
123
+ if (filter_var($yasr_stored_options['blogposting_organization_logo'], FILTER_VALIDATE_URL) !== false) {
124
+ define('YASR_BLOGPOSTING_ORGANIZATION_LOGO', $yasr_stored_options['blogposting_organization_logo']);
125
+ }
126
+ }
127
+
128
+ if (isset($yasr_stored_options['enable_ajax'])) {
129
+ define('YASR_ENABLE_AJAX', $yasr_stored_options['enable_ajax']);
130
+ } else {
131
+ define('YASR_ENABLE_AJAX', 'no'); //default value
132
+ }
133
+
134
+ //Get stored style options
135
+ $style_options = get_option('yasr_style_options');
136
+
137
+ global $style_options;
138
+
139
+ if ($style_options) {
140
+ if (isset($style_options['textarea'])) {
141
+ define('YASR_CUSTOM_CSS_RULES', $style_options['textarea']);
142
+ } else {
143
+ define('YASR_CUSTOM_CSS_RULES', null);
144
+ }
145
+
146
+ if (isset($style_options['scheme_color_multiset'])) {
147
+ define('YASR_SCHEME_COLOR', $style_options['scheme_color_multiset']);
148
+ } else {
149
+ define('YASR_SCHEME_COLOR', null);
150
+ }
151
+
152
+ if (isset($style_options['stars_set_free'])) {
153
+ define('YASR_STARS_SET', $style_options['stars_set_free']);
154
+ } else {
155
+ define('YASR_STARS_SET', null);
156
+ }
157
+
158
+ } else {
159
+ define('YASR_CUSTOM_CSS_RULES', null);
160
+ define('YASR_SCHEME_COLOR', null);
161
+ define('YASR_STARS_SET', null);
162
+ }
163
+
164
+ //Multi set options
165
+ $multi_set_options = get_option('yasr_multiset_options');
166
+
167
+ if ($multi_set_options) {
168
+ if (isset($multi_set_options['show_average'])) {
169
+ define('YASR_MULTI_SHOW_AVERAGE', $multi_set_options['show_average']);
170
+ } else {
171
+ define('YASR_MULTI_SHOW_AVERAGE', 'yes');
172
+ }
173
+ }
174
+ /****** End Getting options ******/
175
+
176
+ global $wpdb;
177
+
178
+ define('YASR_MULTI_SET_NAME_TABLE', $wpdb->prefix . 'yasr_multi_set');
179
+ define('YASR_MULTI_SET_FIELDS_TABLE', $wpdb->prefix . 'yasr_multi_set_fields');
180
+ define('YASR_LOG_MULTI_SET', $wpdb->prefix . 'yasr_log_multi_set');
181
+ define('YASR_LOG_TABLE', $wpdb->prefix . 'yasr_log');
182
+ define('YASR_LOADER_IMAGE', YASR_IMG_DIR . '/loader.gif');
183
+
184
+ //Text for button in settings pages
185
+ $save_settings_text = __('Save All Settings', 'yet-another-stars-rating');
186
+ define('YASR_SAVE_All_SETTINGS_TEXT', $save_settings_text);
187
+
188
+ //use json_decode for compatibility with php <7
189
+ //https://wordpress.org/support/topic/error-after-update-to-version-2-0-6/
190
+ $supported_schema_types = json_encode(
191
+ array (
192
+ 'BlogPosting',
193
+ 'Book',
194
+ 'Course',
195
+ 'CreativeWorkSeason',
196
+ 'CreativeWorkSeries',
197
+ 'Episode',
198
+ 'Event',
199
+ 'Game',
200
+ 'LocalBusiness',
201
+ 'MediaObject',
202
+ 'Movie',
203
+ 'MusicPlaylist',
204
+ 'MusicRecording',
205
+ 'Product',
206
+ 'Recipe'
207
+ )
208
+ );
209
+ $array_item_type_info = json_encode(
210
+ array(
211
+ 'yasr_product_brand',
212
+ 'yasr_product_sku',
213
+ 'yasr_product_global_identifier_select',
214
+ 'yasr_product_global_identifier_value',
215
+ 'yasr_product_price',
216
+ 'yasr_product_price_currency',
217
+ 'yasr_product_price_valid_until',
218
+ 'yasr_product_price_availability',
219
+ 'yasr_product_price_url',
220
+ 'yasr_localbusiness_address',
221
+ 'yasr_localbusiness_pricerange',
222
+ 'yasr_localbusiness_telephone',
223
+ 'yasr_recipe_cooktime',
224
+ 'yasr_recipe_description',
225
+ 'yasr_recipe_keywords',
226
+ 'yasr_recipe_nutrition',
227
+ 'yasr_recipe_preptime',
228
+ 'yasr_recipe_recipecategory',
229
+ 'yasr_recipe_recipecuisine',
230
+ 'yasr_recipe_recipeingredient',
231
+ 'yasr_recipe_recipeinstructions',
232
+ 'yasr_recipe_video'
233
+ )
234
+ );
235
+
236
+ define('YASR_SUPPORTED_SCHEMA_TYPES', $supported_schema_types);
237
+ define('YASR_SUPPORTED_SCHEMA_TYPES_ADDITIONAL_FIELDS', $array_item_type_info);
{lib → includes}/yasr-widgets.php RENAMED
@@ -24,7 +24,6 @@ if (!defined('ABSPATH')) {
24
 
25
  add_action('widgets_init', 'yasr_overall_rating_widget');
26
 
27
-
28
  // register Yasr Overall Rating widget
29
  function yasr_overall_rating_widget() {
30
  register_widget('Yasr_Overall_Rating_Widget');
@@ -515,6 +514,4 @@ class Yasr_Recent_Ratings_Widget extends WP_Widget {
515
  return $instance;
516
  }
517
 
518
- } // class Yasr Visitor Votes widget
519
-
520
- ?>
24
 
25
  add_action('widgets_init', 'yasr_overall_rating_widget');
26
 
 
27
  // register Yasr Overall Rating widget
28
  function yasr_overall_rating_widget() {
29
  register_widget('Yasr_Overall_Rating_Widget');
514
  return $instance;
515
  }
516
 
517
+ } // class Yasr Visitor Votes widget
 
 
js/yasr-shortcode-creator.js DELETED
@@ -1,17 +0,0 @@
1
- // executes this when the DOM is ready
2
- jQuery(document).ready(function(){
3
-
4
- var data = {
5
- action: 'yasr_create_shortcode'
6
- }
7
-
8
- jQuery.post(ajaxurl, data, function(button_content) {
9
-
10
- var response=button_content;
11
-
12
- jQuery(response).appendTo('body').hide();
13
-
14
- });
15
- });
16
-
17
- //});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/admin/editor/yasr-editor-functions.php DELETED
@@ -1,159 +0,0 @@
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
- //this load guten-block.js, only in admin side
26
- add_action('enqueue_block_editor_assets', 'yasr_gutenberg_scripts');
27
-
28
- function yasr_gutenberg_scripts() {
29
-
30
- //Script
31
- wp_enqueue_script(
32
- 'yasr_blocks',
33
- YASR_JS_DIR . 'yasr-guten-blocks.js',
34
- array(
35
- 'wp-i18n',
36
- 'wp-blocks',
37
- 'wp-components',
38
- 'wp-element',
39
- 'wp-editor',
40
- )
41
- );
42
-
43
- wp_enqueue_script(
44
- 'yasr_guten_panel',
45
- YASR_JS_DIR . 'yasr-guten-panel.js',
46
- array(
47
- 'wp-plugins',
48
- 'wp-edit-post',
49
- 'wp-element',
50
- 'wp-editor'
51
- )
52
- );
53
-
54
- }
55
-
56
- //This filter is used to add a new category in gutenberg
57
- add_filter('block_categories', 'yasr_add_gutenberg_category', 10, 2);
58
-
59
- function yasr_add_gutenberg_category($categories) {
60
- return array_merge(
61
- $categories,
62
- array(
63
- array(
64
- 'slug' => 'yet-another-stars-rating',
65
- 'title' => 'Yasr: Yet Another Stars Rating',
66
- ),
67
- )
68
- );
69
- }
70
-
71
- add_action('yasr_add_admin_scripts_end', 'yasr_add_js_constant_gutenberg');
72
-
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',
84
- array(
85
- 'autoInsert' => $auto_insert,
86
- 'defaultItemType' => YASR_ITEMTYPE,
87
- )
88
- );
89
- }
90
- }
91
-
92
-
93
- /****** Create 2 metaboxes in post and pages ******/
94
-
95
- add_action('add_meta_boxes', 'yasr_add_metaboxes');
96
-
97
- function yasr_add_metaboxes() {
98
-
99
- //Default post type where display metabox
100
- $post_type_where_display_metabox = array('post', 'page');
101
-
102
- //get the custom post type
103
- $custom_post_types = yasr_get_custom_post_type();
104
-
105
- if ($custom_post_types) {
106
- //First merge array then changes keys to int
107
- $post_type_where_display_metabox = array_values(array_merge($post_type_where_display_metabox, $custom_post_types));
108
- }
109
-
110
- //For classic editor, add this metabox
111
- foreach ($post_type_where_display_metabox as $post_type) {
112
- add_meta_box(
113
- 'yasr_metabox_overall_rating',
114
- 'YASR',
115
- 'yasr_metabox_overall_rating_content',
116
- $post_type,
117
- 'side',
118
- 'high',
119
- //Set this to true, so this metabox will be only loaded to classic editor
120
- array(
121
- '__back_compat_meta_box' => true,
122
- )
123
- );
124
- }
125
-
126
- foreach ($post_type_where_display_metabox as $post_type) {
127
- add_meta_box(
128
- 'yasr_metabox_below_editor_metabox',
129
- __('Yet Another Stars Rating', 'yet-another-stars-rating'),
130
- 'yasr_metabox_below_editor_metabox_callback',
131
- $post_type,
132
- 'normal',
133
- 'high'
134
- );
135
- }
136
-
137
-
138
- } //End function
139
-
140
- function yasr_metabox_overall_rating_content() {
141
-
142
- if (current_user_can(YASR_USER_CAPABILITY_EDIT_POST)) {
143
- include(YASR_ABSOLUTE_PATH . '/lib/admin/editor/yasr-metabox-top-right.php');
144
- } else {
145
- _e("You don't have enought privileges to insert Overall Rating");
146
- }
147
-
148
- }
149
-
150
- function yasr_metabox_below_editor_metabox_callback() {
151
-
152
- if (current_user_can(YASR_USER_CAPABILITY_EDIT_POST)) {
153
- include(YASR_ABSOLUTE_PATH . '/lib/admin/editor/yasr-metabox-below-editor.php');
154
- } else {
155
- _e("You don't have enough privileges to insert a Multi Set");
156
- }
157
-
158
- }
159
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/rest/YasrCustomEndpoint.php DELETED
@@ -1,151 +0,0 @@
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/YasrCustomFields.php DELETED
@@ -1,110 +0,0 @@
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
- 'sum_votes' => array(
44
- 'type' => 'integer',
45
- ),
46
- 'number_of_votes' => array(
47
- 'type' => 'integer',
48
- ),
49
- ),
50
- );
51
-
52
- //Register Visitor Votes
53
- register_rest_field(
54
- $post_types,
55
- 'yasr_visitor_votes',
56
- array(
57
- 'get_callback' => function() {return YasrDatabaseRatings::getVisitorVotes(); },
58
- 'update_callback' => null,
59
- 'schema' => $yasr_vv_schema
60
- )
61
- );
62
-
63
- }
64
-
65
- /**
66
- * Helper function to return supported itemtype
67
- */
68
- private function allItemTypes() {
69
- $post_types = yasr_return_all_post_types();
70
- $yasr_itemtype_schema = array(
71
- 'description' => 'Yasr Supported Item Types',
72
- 'type' => 'object',
73
- 'context' => array('edit'),
74
- );
75
-
76
- //Register Visitor Votes
77
- register_rest_field(
78
- $post_types,
79
- 'yasr_all_itemtypes',
80
- array(
81
- 'get_callback' => function() {return json_decode(YASR_SUPPORTED_SCHEMA_TYPES); },
82
- 'update_callback' => null,
83
- 'schema' => $yasr_itemtype_schema
84
- )
85
- );
86
- }
87
-
88
- /**
89
- * Helper function to return supported itemtype additional info
90
- */
91
- private function itemTypesAdditionalFields() {
92
- $post_types = yasr_return_all_post_types();
93
- $yasr__additional_itemtype_schema = array(
94
- 'description' => 'Yasr Item Types Additional Info',
95
- 'type' => 'object',
96
- 'context' => array('edit'),
97
- );
98
-
99
- //Register Visitor Votes
100
- register_rest_field(
101
- $post_types,
102
- 'yasr_all_itemtypes',
103
- array(
104
- 'get_callback' => function() {return json_decode(YASR_SUPPORTED_SCHEMA_TYPES_ADDITIONAL_FIELDS); },
105
- 'update_callback' => null,
106
- 'schema' => $yasr__additional_itemtype_schema
107
- )
108
- );
109
- }
110
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/rest/classes/YasrPostMeta.php DELETED
@@ -1,76 +0,0 @@
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/yasr-db-functions.php DELETED
@@ -1,341 +0,0 @@
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
- /****** Install yasr functions ******/
26
- function yasr_on_activation_install($network_wide) {
27
- global $wpdb; //Database wordpress object
28
-
29
- // Creating tables for all blogs in a WordPress Multisite installation
30
- if ( is_multisite() && $network_wide ) {
31
- // Get all blogs in the network and activate plugin on each one
32
- $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
33
- foreach ( $blog_ids as $blog_id ) {
34
- switch_to_blog( $blog_id );
35
- yasr_create_tables();
36
- restore_current_blog();
37
- }
38
- } else {
39
- yasr_create_tables();
40
- }
41
-
42
- //Write default option settings
43
- $option = get_option('yasr_general_options');
44
-
45
- if (!$option) {
46
- $option = array();
47
- $option['auto_insert_enabled'] = 1;
48
- $option['auto_insert_what'] = 'visitor_rating';
49
- $option['auto_insert_where'] = 'bottom';
50
- $option['auto_insert_size'] = 'large';
51
- $option['auto_insert_align'] = 'center';
52
- $option['auto_insert_exclude_pages'] = 'yes';
53
- $option['auto_insert_custom_post_only'] = 'no';
54
- $option['show_overall_in_loop'] = 'disabled';
55
- $option['show_visitor_votes_in_loop'] = 'disabled';
56
- $option['text_before_stars'] = 1;
57
- $option['text_before_overall'] = __('Our Score', 'yet-another-stars-rating');
58
- $option['text_before_visitor_rating'] = __('Click to rate this post!', 'yet-another-stars-rating');
59
- $option['text_after_visitor_rating'] = sprintf(
60
- __('[Total: %s Average: %s]', 'yet-another-stars-rating'),
61
- '%total_count%', '%average%'
62
- );
63
- $option['custom_text_user_voted'] = __('You must sign in to vote', 'yet-another-stars-rating');
64
- $option['custom_text_must_sign_in'] = __('You have already voted for this article', 'yet-another-stars-rating');
65
- $option['enable_ip'] = 'no';
66
- $option['snippet_itemtype'] = 'Product';
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
-
75
- //Style set options
76
- $style_options = array();
77
- $style_options['scheme_color_multiset'] = 'light';
78
- $style_options['stars_set_free'] = 'flat';
79
-
80
- add_option("yasr_style_options", $style_options);
81
-
82
- //multi set options
83
- $multi_set_options = array();
84
- $multi_set_options['show_average'] = 'yes';
85
-
86
- add_option("yasr_multiset_options", $multi_set_options);
87
-
88
- }
89
-
90
- }
91
-
92
- function yasr_create_tables () {
93
-
94
- global $wpdb; //Database wordpress object
95
-
96
- $prefix = $wpdb->prefix . 'yasr_'; //Table prefix
97
-
98
- $yasr_multi_set_table = $prefix . 'multi_set';
99
- $yasr_multi_set_fields = $prefix . 'multi_set_fields';
100
- $yasr_log_multi_set = $prefix . 'log_multi_set';
101
- $yasr_log_table = $prefix . 'log';
102
-
103
- //Do not use IF TABLE EXISTS here
104
- //see https://wordpress.stackexchange.com/a/302538/48442
105
- //since this function is called only on plugin activation AND if yasr-version is not found in
106
- //wp-option, there is no need to check if table exists, unless the user manually remove yasr-version option
107
- //but not the yasr tables.
108
-
109
- $sql_yasr_multi_set_table = "CREATE TABLE $yasr_multi_set_table (
110
- set_id int(2) NOT NULL AUTO_INCREMENT,
111
- set_name varchar(64) COLLATE utf8_unicode_ci NOT NULL,
112
- UNIQUE KEY set_id (set_id),
113
- UNIQUE KEY set_name (set_name)
114
- ) COLLATE 'utf8_unicode_ci';";
115
-
116
- $sql_yasr_multi_set_fields = "CREATE TABLE $yasr_multi_set_fields (
117
- id int(3) NOT NULL AUTO_INCREMENT,
118
- parent_set_id int(2) NOT NULL,
119
- field_name varchar(40) COLLATE utf8_unicode_ci NOT NULL,
120
- field_id int(2) NOT NULL,
121
- PRIMARY KEY (id),
122
- UNIQUE KEY id (id)
123
- ) COLLATE 'utf8_unicode_ci';";
124
-
125
- //Since version 2.1.0
126
- $sql_yasr_log_multi_set_table = "CREATE TABLE $yasr_log_multi_set (
127
- id bigint(20) NOT NULL AUTO_INCREMENT,
128
- field_id int(2) NOT NULL,
129
- set_type int(2) NOT NULL,
130
- post_id bigint(20) NOT NULL,
131
- vote decimal(2,1) NOT NULL,
132
- user_id bigint(20) NOT NULL,
133
- date datetime NOT NULL,
134
- ip varchar(45) COLLATE 'utf8_unicode_ci' NOT NULL,
135
- PRIMARY KEY (id),
136
- UNIQUE KEY id (id)
137
- ) COLLATE 'utf8_unicode_ci';";
138
-
139
- //Since version 2.0.9 user_id is bigint 20 and vote decimal 2,1
140
- //format DECIMAL(M, D) where M is the maximum number of digits (the precision) and D is the
141
- //number of digits to the right of the decimal point (the scale).
142
- $sql_yasr_log_table = "CREATE TABLE $yasr_log_table (
143
- id bigint(20) NOT NULL AUTO_INCREMENT,
144
- post_id bigint(20) NOT NULL,
145
- user_id bigint(20) NOT NULL,
146
- vote decimal(2,1) NOT NULL,
147
- date datetime NOT NULL,
148
- ip varchar(45) COLLATE utf8_unicode_ci NOT NULL,
149
- PRIMARY KEY (id),
150
- UNIQUE KEY id (id)
151
- ) COLLATE 'utf8_unicode_ci';";
152
-
153
-
154
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
155
-
156
- dbDelta($sql_yasr_multi_set_table);
157
- dbDelta($sql_yasr_multi_set_fields);
158
- dbDelta($sql_yasr_log_multi_set_table);
159
- dbDelta($sql_yasr_log_table);
160
- }
161
-
162
- //action is in the main file
163
- function yasr_on_create_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
164
- if ( is_plugin_active_for_network( 'yet-another-stars-rating/yet-another-stars-rating.php' ) ) {
165
- switch_to_blog( $blog_id );
166
- yasr_create_tables();
167
- restore_current_blog();
168
- }
169
- }
170
-
171
- // Deleting the table whenever a blog is deleted
172
-
173
- function yasr_on_delete_blog($tables) {
174
- global $wpdb;
175
-
176
- $prefix = $wpdb->prefix . 'yasr_'; //Table prefix
177
-
178
- $yasr_multi_set_table = $prefix . 'multi_set';
179
- $yasr_multi_set_fields = $prefix . 'multi_set_fields';
180
- $yasr_log_multi_set = $prefix . 'log_multi_set';
181
- $yasr_log_table = $prefix . 'log';
182
-
183
- $tables[] = $yasr_multi_set_table;
184
- $tables[] = $yasr_multi_set_fields;
185
- $tables[] = $yasr_log_multi_set;
186
- $tables[] = $yasr_log_table;
187
-
188
- return $tables;
189
- }
190
-
191
-
192
- /****** Return the snippet choosen for a post or page ******/
193
- function yasr_get_itemType() {
194
-
195
- $review_types = json_decode(YASR_SUPPORTED_SCHEMA_TYPES);
196
-
197
- $post_id = get_the_ID();
198
-
199
- if (!$post_id) {
200
- return false;
201
- } else {
202
- $result = get_post_meta($post_id, 'yasr_review_type', true);
203
-
204
- if ($result) {
205
- $snippet_type = trim($result);
206
-
207
- //to keep compatibility with version <2.2.3
208
- if($snippet_type === 'Place') {
209
- $snippet_type = 'LocalBusiness';
210
- }
211
- //to keep compatibility with version <2.2.3
212
- if($snippet_type === 'Other') {
213
- $snippet_type = 'BlogPosting';
214
- }
215
-
216
- if (!in_array($snippet_type, $review_types)) {
217
- $snippet_type = YASR_ITEMTYPE;
218
- }
219
-
220
- } else {
221
- $snippet_type = YASR_ITEMTYPE;
222
- }
223
- return $snippet_type;
224
- }
225
-
226
- }
227
-
228
- /** Output the multi set while editing the page, used in
229
- * yasr-metabox-multiple-rating and yasr-ajax-function
230
- */
231
-
232
- function yasr_return_multi_set_values_admin($post_id, $set_id) {
233
-
234
- if ((!is_int($post_id)) || (!is_int($set_id))) {
235
- exit(__('Missing post or set id', 'yet-another-stars-rating'));
236
- }
237
-
238
- //set fields name and ids
239
- $set_fields = YasrMultiSetData::multisetFieldsAndID($set_id);
240
-
241
- //set meta values
242
- $array_to_return = YasrMultiSetData::returnArrayFieldsRatings($set_id, $set_fields, $post_id);
243
-
244
- echo json_encode($array_to_return);
245
-
246
- }
247
-
248
-
249
-
250
-
251
- /****** Adding logs widget to the dashboard ******/
252
-
253
- add_action('plugins_loaded', 'yasr_add_action_dashboard_widget_log');
254
-
255
- function yasr_add_action_dashboard_widget_log() {
256
- //This is for the admins (show all votes in the site)
257
- if (current_user_can('manage_options')) {
258
- add_action('wp_dashboard_setup', 'yasr_add_dashboard_widget_log');
259
- }
260
-
261
- //This is for all the users to see where they've voted
262
- add_action('wp_dashboard_setup', 'yasr_add_dashboard_widget_user_log');
263
- }
264
-
265
- function yasr_add_dashboard_widget_log() {
266
- wp_add_dashboard_widget(
267
- 'yasr_widget_log_dashboard', //slug for widget
268
- 'Recent Ratings', //widget name
269
- 'yasr_widget_log_dashboard_callback' //function callback
270
- );
271
- }
272
-
273
- //This add a dashboard log for every users
274
- function yasr_add_dashboard_widget_user_log() {
275
- wp_add_dashboard_widget(
276
- 'yasr_users_dashboard_widget', //slug for widget
277
- 'Your Ratings', //widget name
278
- 'yasr_users_dashboard_widget_callback' //function callback
279
- );
280
- }
281
-
282
- //ajax action
283
- add_action('wp_ajax_yasr_change_log_page', 'yasr_widget_log_dashboard_callback');
284
- function yasr_widget_log_dashboard_callback() {
285
- $log_widget = new YasrLogDashboardWidget('admin');
286
- $log_widget->adminWidget();
287
- } //End callback function
288
-
289
-
290
- //ajax action
291
- add_action('wp_ajax_yasr_change_user_log_page', 'yasr_users_dashboard_widget_callback');
292
- function yasr_users_dashboard_widget_callback() {
293
- $log_widget = new YasrLogDashboardWidget('user');
294
- $log_widget->userWidget();
295
- } //End callback function
296
-
297
-
298
- /****** Delete data value from yasr tabs when a post or page is deleted
299
- * Added since yasr 0.3.3
300
- ******/
301
-
302
- add_action('admin_init', 'admin_init_delete_data_on_post_callback');
303
-
304
- function admin_init_delete_data_on_post_callback() {
305
-
306
- if (current_user_can('delete_posts')) {
307
- add_action('delete_post', 'yasr_erase_data_on_post_page_remove_callback');
308
- }
309
-
310
- }
311
-
312
- function yasr_erase_data_on_post_page_remove_callback($post_id) {
313
- global $wpdb;
314
-
315
- delete_metadata('post', $post_id, 'yasr_overall_rating');
316
- delete_metadata('post', $post_id, 'yasr_review_type');
317
- delete_metadata('post', $post_id, 'yasr_multiset_author_votes');
318
-
319
- //Delete multi value
320
- $wpdb->delete(
321
- YASR_LOG_MULTI_SET,
322
- array(
323
- 'post_id' => $post_id
324
- ),
325
- array(
326
- '%d'
327
- )
328
- );
329
-
330
- $wpdb->delete(
331
- YASR_LOG_TABLE,
332
- array(
333
- 'post_id' => $post_id
334
- ),
335
- array(
336
- '%d'
337
- )
338
- );
339
-
340
-
341
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/yasr-deprecated.php DELETED
@@ -1,182 +0,0 @@
1
- <?php
2
-
3
- /*
4
- * Get overall rating from yasr_votes table used in
5
- * yasr_add_filter_for_schema(), yasr_get_id_value_callback()
6
- * and yasr_rest_get_overall_rating
7
- *
8
- */
9
-
10
- if (!defined('ABSPATH')) {
11
- exit('You\'re not allowed to see this page');
12
- } // Exit if accessed directly
13
-
14
-
15
- function yasr_get_overall_rating($post_id = false) {
16
-
17
- //if values it's not passed get the post id, since version 1.6.9 this is just for yasr_add_schema function
18
- //and for a further check
19
- if (!$post_id) {
20
- $post_id = get_the_ID();
21
- }
22
-
23
- if (!$post_id) {
24
- return null;
25
- }
26
-
27
- $post_id = (int) $post_id;
28
-
29
- $overall_rating = get_post_meta($post_id, 'yasr_overall_rating', true);
30
-
31
- return $overall_rating;
32
-
33
- }
34
-
35
- /****** Get visitor votes ******/
36
- function yasr_get_visitor_votes($post_id = false, $create_transient = true) {
37
-
38
- global $wpdb;
39
-
40
- //if values it's not passed get the post id, most of cases and default one
41
- if (!$post_id) {
42
- $post_id = get_the_ID();
43
- }
44
-
45
- if (!$post_id) {
46
- return false;
47
- }
48
-
49
- $post_id = (int)$post_id;
50
-
51
- $transient_name = 'yasr_visitor_votes_' . $post_id;
52
-
53
- $transient_visitor_votes = get_transient($transient_name);
54
-
55
- if ($transient_visitor_votes) {
56
- return $transient_visitor_votes;
57
- } else {
58
- $result = $wpdb->get_results(
59
- $wpdb->prepare(
60
- "SELECT SUM(vote) AS sum_votes, COUNT(vote) as number_of_votes FROM "
61
- . YASR_LOG_TABLE .
62
- " WHERE post_id=%d",
63
- $post_id
64
- )
65
- );
66
-
67
- if ($create_transient == true) {
68
- set_transient($transient_name, $result, WEEK_IN_SECONDS);
69
- }
70
-
71
- return $result;
72
-
73
- }
74
-
75
- }
76
-
77
-
78
- /****** Get multi set values and field's name, used in ajax function and shortcode function ******/
79
- function yasr_get_multi_set_fields($set_id) {
80
-
81
- global $wpdb;
82
-
83
- $result = $wpdb->get_results($wpdb->prepare(
84
- "SELECT f.field_id AS id, f.field_name AS name
85
- FROM " . YASR_MULTI_SET_FIELDS_TABLE . " AS f
86
- WHERE f.parent_set_id=%d
87
- ORDER BY f.field_id
88
- ", $set_id),
89
- ARRAY_A);
90
-
91
- if (empty($result)) {
92
- return false;
93
- }
94
-
95
- return $result;
96
-
97
- }
98
-
99
-
100
- /*** function that get the star size and return it***/
101
- function yasr_stars_size($size) {
102
-
103
- //$size = sanitize_text_field($size);
104
-
105
- $stars_attribute = array();
106
-
107
- if ($size === 'small') {
108
- $stars_attribute['px_size'] = '16';
109
- } elseif ($size === 'medium') {
110
- $stars_attribute['px_size'] = '24';
111
- } //default values
112
- else {
113
- $stars_attribute['px_size'] = '32';
114
- }
115
-
116
- return $stars_attribute;
117
-
118
- }
119
-
120
- /*
121
- * Show visitor votes average, READ ONLY
122
- */
123
- add_shortcode ('yasr_visitor_votes_readonly', 'yasr_visitor_votes_readonly_callback');
124
-
125
- function yasr_visitor_votes_readonly_callback($atts) {
126
-
127
- $atts['readonly'] = true;
128
-
129
- //Here I call the same function that draw the same function for yasr_visitor_votes,
130
- //passing the attribute readonly = true
131
- $shortcode_html = shortcode_visitor_votes_callback($atts);
132
-
133
- return $shortcode_html;
134
-
135
- } //End function shortcode_visitor_votes_only_stars_callback
136
-
137
-
138
- /****** Check if a logged in user has already rated. Return user vote for a post if exists ******/
139
-
140
- function yasr_check_if_user_already_voted($post_id = false) {
141
-
142
- global $wpdb;
143
-
144
- $current_user = wp_get_current_user();
145
- $user_id = $current_user->ID;
146
-
147
- //just to be safe
148
- if (!$post_id) {
149
- $post_id = get_the_ID();
150
- }
151
-
152
- if (!$post_id || !$user_id) {
153
- return false;
154
- }
155
-
156
- $rating = $wpdb->get_var(
157
- $wpdb->prepare(
158
- "SELECT vote FROM "
159
- . YASR_LOG_TABLE .
160
- " WHERE post_id=%d
161
- AND user_id=%d
162
- LIMIT 1 ",
163
- $post_id, $user_id
164
- )
165
- );
166
-
167
- if ($rating === null) {
168
- $rating = false;
169
- }
170
-
171
- return $rating;
172
-
173
- }
174
-
175
- /****** Get multi set name ******/
176
- function yasr_get_multi_set() {
177
- global $wpdb;
178
-
179
- $result = $wpdb->get_results("SELECT * FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id");
180
-
181
- return $result;
182
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/yasr-functions.php DELETED
@@ -1,985 +0,0 @@
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
- /***** Adding javascript and css *****/
27
-
28
- add_action('wp_enqueue_scripts', 'yasr_add_scripts');
29
- add_action('admin_enqueue_scripts', 'yasr_add_admin_scripts');
30
-
31
- function yasr_add_scripts() {
32
-
33
- wp_enqueue_style(
34
- 'yasrcss',
35
- YASR_CSS_DIR . 'yasr.css',
36
- false,
37
- YASR_VERSION_NUM,
38
- 'all'
39
- );
40
-
41
- wp_enqueue_style('dashicons'); //dashicons
42
-
43
- //Run after default css are loaded
44
- do_action('yasr_add_front_script_css');
45
-
46
- $yasr_multiset_theme_handle = 'yasrcsslightscheme';
47
- $yasr_multiset_theme = 'yasr-table-light.css';
48
-
49
- //default css is the light one
50
- if (YASR_SCHEME_COLOR === 'dark') {
51
- $yasr_multiset_theme_handle = 'yasrcssdarkscheme';
52
- $yasr_multiset_theme = 'yasr-table-dark.css';
53
- }
54
-
55
- wp_enqueue_style(
56
- $yasr_multiset_theme_handle,
57
- YASR_CSS_DIR . $yasr_multiset_theme,
58
- array('yasrcss'),
59
- YASR_VERSION_NUM, 'all'
60
- );
61
-
62
- if (YASR_CUSTOM_CSS_RULES) {
63
- wp_add_inline_style(
64
- 'yasrcss',
65
- YASR_CUSTOM_CSS_RULES
66
- );
67
- }
68
-
69
- $rater_file_to_include = 'rater-js.js';
70
-
71
- if (is_rtl()) {
72
- $rater_file_to_include = 'rater-js-rtl.js';
73
- }
74
-
75
- wp_enqueue_script(
76
- 'rater',
77
- YASR_JS_DIR .
78
- $rater_file_to_include,
79
- '',
80
- YASR_VERSION_NUM,
81
- true
82
- );
83
-
84
- wp_enqueue_script(
85
- 'yasrfront',
86
- YASR_JS_DIR . 'yasr-front.js',
87
- array('jquery', 'rater'),
88
- YASR_VERSION_NUM,
89
- true);
90
-
91
- wp_enqueue_script(
92
- 'tippy',
93
- YASR_JS_DIR . 'tippy.all.min.js',
94
- '',
95
- '3.6.0',
96
- true
97
- );
98
-
99
- do_action('yasr_add_front_script_js');
100
-
101
- $yasr_visitor_votes_loader = '<div id="loader-visitor-rating" style="display: inline">&nbsp; '.
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
-
115
- }
116
-
117
- //$hook contain the current page in the admin side
118
- function yasr_add_admin_scripts($hook) {
119
-
120
- global $yasr_settings_page;
121
-
122
- if ($hook === 'post.php' || $hook === 'post-new.php') {
123
- wp_enqueue_script(
124
- 'yasr_classic_editor_functions',
125
- YASR_JS_DIR . 'yasr-editor-screen.js',
126
- array('jquery'),
127
- YASR_VERSION_NUM,
128
- true
129
- );
130
- }
131
-
132
- if ($hook === 'index.php' || $hook === 'edit.php' || $hook === 'post.php' || $hook === 'post-new.php' ||
133
- $hook === 'edit-comments.php' || $hook === $yasr_settings_page ||
134
- $hook === 'yet-another-stars-rating_page_yasr_stats_page'
135
- ) {
136
-
137
- do_action('yasr_add_admin_scripts_begin');
138
-
139
- $rater_file_to_include = 'rater-js.js';
140
-
141
- if (is_rtl()) {
142
- $rater_file_to_include = 'rater-js-rtl.js';
143
- }
144
-
145
- wp_enqueue_style('yasrcss', YASR_CSS_DIR . 'yasr-admin.css', false, YASR_VERSION_NUM, 'all');
146
- wp_enqueue_script('yasradmin', YASR_JS_DIR . 'yasr-admin.js', array('jquery'), YASR_VERSION_NUM, true);
147
- wp_enqueue_script('rater', YASR_JS_DIR . $rater_file_to_include, '', YASR_VERSION_NUM, true);
148
-
149
- do_action('yasr_add_admin_scripts_end', $hook);
150
-
151
- $yasr_loader = YASR_IMG_DIR . 'loader.gif';
152
-
153
- wp_localize_script(
154
- 'yasradmin', 'yasrCommonDataAdmin',
155
- array(
156
- 'loaderHtml' => $yasr_loader
157
- )
158
- );
159
-
160
- }
161
-
162
- }
163
-
164
- /*** Css rules for stars set, from version 1.2.7
165
- * Here I use add_action instead of directly use wp_add_inline_style so I can
166
- * use remove_action if needed (e.g. Yasr Stylish)
167
- ***/
168
-
169
- add_action('yasr_add_front_script_css', 'yasr_css_stars_set');
170
- add_action('yasr_add_admin_scripts_end', 'yasr_css_stars_set');
171
-
172
- function yasr_css_stars_set() {
173
-
174
- //if star selected is "rater", select the images
175
- if (YASR_STARS_SET === 'rater') {
176
- $star_grey = YASR_IMG_DIR . 'star_0.svg';
177
- $star_yellow = YASR_IMG_DIR . 'star_1.svg';
178
- } elseif (YASR_STARS_SET === 'rater-oxy') {
179
- $star_grey = YASR_IMG_DIR . 'star_oxy_0.svg';
180
- $star_yellow = YASR_IMG_DIR . 'star_oxy_1.svg';
181
- } //by default, use the one provided by Yasr
182
- else {
183
- $star_grey = YASR_IMG_DIR . 'star_2.svg';
184
- $star_yellow = YASR_IMG_DIR . 'star_3.svg';
185
- }
186
-
187
-
188
- $yasr_st_css = "
189
- .yasr-star-rating {
190
- background-image: url(\"$star_grey\");
191
- }
192
- .yasr-star-rating .yasr-star-value {
193
- background: url(\"$star_yellow\") ;
194
- }
195
- ";
196
-
197
- wp_add_inline_style('yasrcss', $yasr_st_css);
198
-
199
- }
200
-
201
- add_action('yasr_add_front_script_css', 'yasr_rtl_support');
202
- add_action('yasr_add_admin_scripts_end', 'yasr_rtl_support');
203
-
204
- function yasr_rtl_support() {
205
-
206
- if (is_rtl()) {
207
- $yasr_rtl_css = '.yasr-star-rating .yasr-star-value {
208
- -moz-transform: scaleX(-1);
209
- -o-transform: scaleX(-1);
210
-
211
- -webkit-transform: scaleX(-1);
212
- transform: scaleX(-1);
213
- filter: FlipH;
214
- -ms-filter: "FlipH";
215
- right: 0;
216
- left: auto;
217
- }';
218
-
219
- wp_add_inline_style('yasrcss', $yasr_rtl_css);
220
-
221
- }
222
-
223
- }
224
-
225
-
226
- /****** Translating YASR ******/
227
-
228
- add_action('init', 'yasr_translate_option', 110);
229
-
230
- function yasr_translate_option() {
231
- load_plugin_textdomain('yet-another-stars-rating', false, YASR_LANG_DIR);
232
- }
233
-
234
-
235
- /****** Create a new Page in Administration Menu ******/
236
-
237
- /* Hook to admin_menu the yasr_add_pages function above */
238
- add_action('admin_menu', 'yasr_add_pages');
239
-
240
- function yasr_add_pages() {
241
-
242
- global $yasr_settings_page;
243
-
244
- //Add Settings Page
245
- $yasr_settings_page = add_menu_page(
246
- __('Yet Another Stars Rating: settings', 'yet-another-stars-rating'), //Page Title
247
- __('Yet Another Stars Rating', 'yet-another-stars-rating'), //Menu Title
248
- 'manage_options', //capability
249
- 'yasr_settings_page', //menu slug
250
- 'yasr_settings_page_callback', //The function to be called to output the content for this page.
251
- 'dashicons-star-half'
252
- );
253
-
254
- add_submenu_page(
255
- 'yasr_settings_page',
256
- 'Yet Another Stars Rating: settings',
257
- 'Settings',
258
- 'manage_options',
259
- 'yasr_settings_page'
260
- );
261
-
262
- add_submenu_page(
263
- 'yasr_settings_page',
264
- 'Yet Another Stars Rating: All Rating',
265
- 'Stats',
266
- 'manage_options',
267
- 'yasr_stats_page',
268
- 'yasr_stats_page_callback'
269
- );
270
-
271
- if (yasr_fs()->is_free_plan() && !yasr_fs()->is_trial()) {
272
- global $submenu;
273
- $permalink = '#';
274
- $contact_us_string = sprintf(
275
- __('Contact Us %s', 'yet-another-stars-rating'),
276
- '<span class="dashicons dashicons-lock" />'
277
- );
278
- $submenu['yasr_settings_page'][] = array($contact_us_string, 'manage_options', $permalink);
279
- }
280
-
281
- }
282
-
283
- // Settings Page Content
284
- function yasr_settings_page_callback() {
285
-
286
- if (!current_user_can('manage_options')) {
287
- wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
288
- }
289
-
290
- include(YASR_ABSOLUTE_PATH . '/yasr-settings-page.php');
291
-
292
- } //End yasr_settings_page_content
293
-
294
-
295
- function yasr_stats_page_callback() {
296
-
297
- if (!current_user_can('manage_options')) {
298
- wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
299
- }
300
-
301
- include(YASR_ABSOLUTE_PATH . '/yasr-stats-page.php');
302
- }
303
-
304
-
305
- /****** Auto insert overall rating and visitor rating ******/
306
-
307
- if (YASR_AUTO_INSERT_ENABLED == 1) {
308
-
309
- if (!is_admin()) {
310
- add_filter('the_content', 'yasr_auto_insert_shortcode_callback');
311
- }
312
-
313
- /**
314
- * @param $content
315
- *
316
- * @return bool|string|void
317
- */
318
- function yasr_auto_insert_shortcode_callback($content) {
319
-
320
- $post_id = get_the_ID();
321
-
322
- //check if for this post or page auto insert is off
323
- $post_excluded = get_post_meta($post_id, 'yasr_auto_insert_disabled', true);
324
-
325
- if ($post_excluded === 'yes') {
326
- return $content;
327
- }
328
-
329
- $shortcode_align = YASR_AUTO_INSERT_ALIGN;
330
-
331
- //if it is not left, or right, default is center
332
- if ($shortcode_align !== 'left' && $shortcode_align !== 'right') {
333
- $shortcode_align = 'center';
334
- }
335
-
336
- $container_div_overall='<div style="text-align:'.$shortcode_align.'" class="yasr-auto-insert-overall">';
337
- $container_div_visitor='<div style="text-align:'.$shortcode_align.'" class="yasr-auto-insert-visitor">';
338
- $closing_div = '</div>';
339
-
340
- $auto_insert_shortcode = null; //To avoid undefined variable notice outside the loop (if (is_singular) )
341
- $overall_rating_code = $container_div_overall. '[yasr_overall_rating size="' . YASR_AUTO_INSERT_SIZE . '"]' . $closing_div;
342
- $visitor_votes_code = $container_div_visitor. '[yasr_visitor_votes size="' . YASR_AUTO_INSERT_SIZE . '"]' . $closing_div;
343
-
344
- //avoid undefined
345
- $content_and_stars = false;
346
-
347
- if (YASR_AUTO_INSERT_WHAT === 'overall_rating') {
348
- switch (YASR_AUTO_INSERT_WHERE) {
349
- case 'top':
350
- $content_and_stars = $overall_rating_code . $content;
351
- break;
352
-
353
- case 'bottom':
354
- $content_and_stars = $content . $overall_rating_code;
355
- break;
356
- } //End Switch
357
- } elseif (YASR_AUTO_INSERT_WHAT === 'visitor_rating') {
358
- switch (YASR_AUTO_INSERT_WHERE) {
359
- case 'top':
360
- $content_and_stars = $visitor_votes_code . $content;
361
- break;
362
-
363
- case 'bottom':
364
- $content_and_stars = $content . $visitor_votes_code;
365
- break;
366
- } //End Switch
367
- } elseif (YASR_AUTO_INSERT_WHAT === 'both') {
368
- switch (YASR_AUTO_INSERT_WHERE) {
369
- case 'top':
370
- $content_and_stars = $overall_rating_code . $visitor_votes_code . $content;
371
- break;
372
-
373
- case 'bottom':
374
- $content_and_stars = $content . $overall_rating_code . $visitor_votes_code;
375
- break;
376
- } //End Switch
377
- }
378
-
379
- //IF auto insert must work only in custom post type
380
- if (YASR_AUTO_INSERT_CUSTOM_POST_ONLY === 'yes') {
381
-
382
- $custom_post_types = yasr_get_custom_post_type();
383
-
384
- //If is a post type return content and stars
385
- if (is_singular($custom_post_types)) {
386
- return $content_and_stars;
387
- } //else return just content
388
- else {
389
- return $content;
390
- }
391
-
392
- }
393
-
394
- //If page are not excluded
395
- if (YASR_AUTO_INSERT_EXCLUDE_PAGES === 'no') {
396
- return $content_and_stars;
397
- } //else return only if it is not a page
398
- elseif (YASR_AUTO_INSERT_EXCLUDE_PAGES === 'yes') {
399
- if (is_page()) {
400
- return $content;
401
- } //If is a page return the content without stars
402
- else {
403
- return $content_and_stars;
404
- }
405
- }
406
- return;
407
- } //End function yasr_auto_insert_shortcode_callback
408
-
409
- } //End if (YASR_AUTO_INSERT_ENABLED
410
-
411
- /****** Add review schema data at the end of the post *******/
412
-
413
-
414
- add_filter('the_content', 'yasr_add_schema');
415
-
416
- function yasr_add_schema($content) {
417
-
418
- //Add buddypress compatibility
419
- if (function_exists('bp_is_active')) {
420
- //If this is a page, return $content without adding schema.
421
- //If I try to return $content after if (YASR_SNIPPET == 'overall_rating')
422
- //or (YASR_SNIPPET == 'visitor_rating') $content will have only wp content, losing the buddypress one
423
- if (is_page()) {
424
- return $content;
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
440
- if($overall_rating > 0 && $overall_rating < 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
-
449
- $review_choosen = yasr_get_itemType();
450
-
451
- //if doesn't exists a filter for yasr_filter_schema_jsonld $review_chosen value is assigned to $filtered_schema...
452
- $filtered_schema = apply_filters('yasr_filter_schema_jsonld', $review_choosen);
453
-
454
- //So check here if $schema != $review_choosen
455
- if ($filtered_schema !== $review_choosen) {
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());
463
-
464
- $date = get_the_date('c');
465
- $date_modified = get_the_modified_date('c');
466
-
467
- $post_image_url = ''; //avoid undefined
468
- $logo_image_url = ''; //avoid undefined
469
-
470
- if (defined('YASR_BLOGPOSTING_ORGANIZATION_LOGO')) {
471
- $logo_image_url = YASR_BLOGPOSTING_ORGANIZATION_LOGO;
472
- $post_image_url = $logo_image_url; //this will be overwritten if has_post_thumbnail is true
473
-
474
- $logo_image_url_absolute = $_SERVER['DOCUMENT_ROOT'] . parse_url(YASR_BLOGPOSTING_ORGANIZATION_LOGO, PHP_URL_PATH);
475
-
476
- $post_image_size = @getimagesize($logo_image_url_absolute); //the @ should be useless, just to be safe
477
- $logo_image_size = @getimagesize($logo_image_url_absolute); //the @ should be useless, just to be safe
478
- } else {
479
- $post_image_size[0] = 0;
480
- $post_image_size[1] = 0;
481
- $logo_image_size[0] = 0;
482
- $logo_image_size[1] = 0;
483
- }
484
-
485
- //if exists featuread image get the url and overwrite the variable
486
- if (has_post_thumbnail()) {
487
- $post_image_url = wp_get_attachment_url(get_post_thumbnail_id());
488
- $post_image_url_absolute = $_SERVER['DOCUMENT_ROOT'] . parse_url($post_image_url, PHP_URL_PATH);
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(
548
- '@type' => 'Person',
549
- 'name' => $author
550
- ),
551
- 'datePublished' => $date,
552
- 'dateModified' => $date_modified,
553
- 'reviewRating' => array(
554
- '@type' => 'Rating',
555
- 'ratingValue' => $overall_rating,
556
- 'bestRating' => 5,
557
- 'worstRating' => 1
558
- ),
559
- );
560
- }
561
-
562
- //if both are included, google will index AggregateRating instead of Review.
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
-
570
- $rich_snippet['aggregateRating'] = array(
571
- '@type' => 'AggregateRating',
572
- 'ratingValue' => $average_rating,
573
- 'ratingCount' => $visitor_votes['number_of_votes'],
574
- 'bestRating' => 5,
575
- 'worstRating' => 1
576
- );
577
- }
578
- }
579
- }
580
-
581
- }
582
-
583
- //if doesn't exists a filter for yasr_filter_existing_schema, put $rich_snippet into $more_rich_snippet
584
- $more_rich_snippet = apply_filters('yasr_filter_existing_schema', $rich_snippet);
585
-
586
- if ($more_rich_snippet !== $rich_snippet && is_array($more_rich_snippet)) {
587
- $rich_snippet = $more_rich_snippet;
588
- }
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
- /**
599
- * Create a select menu to choose the rich snippet itemtype
600
- *
601
- * @param bool|string $html_id
602
- */
603
-
604
- function yasr_select_itemtype($html_id=false) {
605
-
606
- if($html_id === false) {
607
- $html_id = 'yasr-choose-reviews-types-list';
608
- }
609
-
610
- $review_types = json_decode(YASR_SUPPORTED_SCHEMA_TYPES);
611
-
612
- sort($review_types);
613
- $review_type_choosen = yasr_get_itemType();
614
- ?>
615
-
616
- <label for="<?php echo $html_id ?>"></label>
617
- <select name="yasr-review-type" id="<?php echo $html_id ?>">
618
- <?php
619
- foreach ($review_types as $type) {
620
- $type = trim($type);
621
- $type_option = $type;
622
- if ($type === $review_type_choosen) {
623
- echo "<option value=\"$type\" selected>$type_option</option>";
624
- } else {
625
- echo "<option value=\"$type\">$type_option</option>";
626
- }
627
- }
628
- ?>
629
- </select>
630
-
631
- <?php
632
- } //End function yasr_select_itemtype()
633
-
634
-
635
- /******* Add a media content button ******/
636
-
637
- add_action('media_buttons', 'yasr_shortcode_button_media', 99);
638
-
639
- function yasr_shortcode_button_media() {
640
-
641
- if (is_admin()) {
642
-
643
- add_thickbox();
644
-
645
- echo '<a href="#TB_inline?width=530&height=600&inlineId=yasr-tinypopup-form"
646
- id="yasr-shortcode-creator"
647
- class="button thickbox">
648
- <span class="dashicons dashicons-star-half" style="vertical-align: middle;"></span> Yasr Shortcode
649
- </a>';
650
-
651
- }
652
-
653
- }
654
-
655
-
656
- /****** Return the custom post type if exists
657
- * Argument is to set what to return, if array or boolean value.
658
- * Default: array******/
659
-
660
- add_action('admin_init', 'yasr_get_custom_post_type');
661
-
662
- function yasr_get_custom_post_type($return_value = 'array') {
663
-
664
- //if this is a rest request $return_value is an object called WP_REST_Request
665
- //overwrite content to 'array'
666
- if (is_object($return_value)) {
667
- if (get_class($return_value) === 'WP_REST_Request') {
668
- $return_value = 'array';
669
- }
670
- }
671
-
672
- $args = array(
673
- 'public' => true,
674
- '_builtin' => false
675
- );
676
-
677
- $output = 'names'; // names or objects, note names is the default
678
- $operator = 'and'; // 'and' or 'or'
679
-
680
- $post_types = get_post_types($args, $output, $operator);
681
-
682
- if ($post_types) {
683
- if ($return_value === 'array') {
684
- return ($post_types);
685
- } else {
686
- return true;
687
- }
688
- } else {
689
- //no external post type founds
690
- return false;
691
- }
692
-
693
- }
694
-
695
- function yasr_return_all_post_types () {
696
- $args = array(
697
- 'public' => true,
698
- );
699
-
700
- $output = 'names';
701
- $operator = 'and';
702
-
703
- $post_types = get_post_types($args, $output, $operator);
704
-
705
- return $post_types;
706
- }
707
-
708
-
709
- /*** Add support for wp super cache ***/
710
- function yasr_wp_super_cache_support($post_id) {
711
- if (function_exists('wp_cache_post_change')) {
712
- wp_cache_post_change($post_id);
713
- }
714
- }
715
-
716
- /*** Add support for wp rocket, thanks to GeekPress
717
- * https://wordpress.org/support/topic/compatibility-with-wp-rocket-2
718
- ***/
719
- function yasr_wp_rocket_support($post_id) {
720
- if (function_exists('rocket_clean_post')) {
721
- rocket_clean_post($post_id);
722
- }
723
- }
724
-
725
- /*** Add support for LiteSpeed Cache plugin, thanks to Pako69
726
- * https://wordpress.org/support/topic/yasr-is-litespeed-cache-plugin-compatible/
727
- ***/
728
- function yasr_litespeed_cache_support($post_id) {
729
- if (method_exists('LiteSpeed_Cache_API', 'purge_post') == true) {
730
- LiteSpeed_Cache_API::purge_post($post_id);
731
- }
732
- }
733
-
734
- /*** Add support for cache enabler ***/
735
- function yasr_cache_enabler_support($post_id, $is_singular) {
736
-
737
- if (has_action('ce_clear_cache') || has_action('ce_clear_post_cache')) {
738
- //IF is in the single post or page delete only that cache
739
- if ($is_singular === 'true') {
740
- do_action('ce_clear_post_cache', $post_id);
741
- } //otherwise, delete everything
742
- else {
743
- do_action('ce_clear_cache');
744
- }
745
- }
746
- }
747
-
748
-
749
- /**** Add support for Wp Fastest Cache ****/
750
- function yasr_wp_fastest_cache($post_id, $is_singular) {
751
-
752
- if ($is_singular === 'true') {
753
- if (isset($GLOBALS['wp_fastest_cache']) && method_exists($GLOBALS['wp_fastest_cache'], 'singleDeleteCache')) {
754
- $GLOBALS['wp_fastest_cache']->singleDeleteCache(false, $post_id);
755
- }
756
- } else {
757
- if (isset($GLOBALS['wp_fastest_cache']) && method_exists($GLOBALS['wp_fastest_cache'], 'deleteCache')) {
758
- $GLOBALS['wp_fastest_cache']->deleteCache();
759
- }
760
- }
761
-
762
-
763
- }
764
-
765
- /*** Function to set cookie, since version 0.8.3 ***/
766
- function yasr_setcookie($cookiename, $data_to_save) {
767
-
768
- if (!$data_to_save || !$cookiename) {
769
- exit('Error setting yasr cookie');
770
- }
771
-
772
- $existing_data = array(); //avoid undefined index
773
-
774
- if (isset($_COOKIE[$cookiename])) {
775
-
776
- //setcookie add \ , so I need to stripslahes
777
- $existing_data = stripslashes($_COOKIE[$cookiename]);
778
-
779
- //By default, json_decode return an object, TRUE to return an array
780
- $existing_data = json_decode($existing_data, true);
781
-
782
- }
783
-
784
- //whetever exists or not, push into at the end of array
785
- $existing_data[] = $data_to_save;
786
-
787
- $encoded_data = json_encode($existing_data);
788
-
789
- setcookie($cookiename, $encoded_data, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false);
790
-
791
- }
792
-
793
- /*** Function to get ip, since version 0.8.8
794
- * This code can be found on http://codex.wordpress.org/Plugin_API/Filter_Reference/pre_comment_user_ip
795
- ***/
796
-
797
- function yasr_get_ip() {
798
-
799
- if (YASR_ENABLE_IP === 'yes') {
800
-
801
- $ip = null;
802
- $ip = apply_filters('yasr_filter_ip', $ip);
803
-
804
- if (isset($ip)) {
805
- return $ip;
806
- }
807
-
808
-
809
- $REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
810
-
811
- if (!empty($_SERVER['X_FORWARDED_FOR'])) {
812
-
813
- $X_FORWARDED_FOR = explode(',', $_SERVER['X_FORWARDED_FOR']);
814
-
815
- if (!empty($X_FORWARDED_FOR)) {
816
- $REMOTE_ADDR = trim($X_FORWARDED_FOR[0]);
817
- }
818
-
819
- } /*
820
- * Some php environments will use the $_SERVER['HTTP_X_FORWARDED_FOR']
821
- * variable to capture visitor address information.
822
- */
823
-
824
- elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
825
-
826
- $HTTP_X_FORWARDED_FOR = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
827
-
828
- if (!empty($HTTP_X_FORWARDED_FOR)) {
829
- $REMOTE_ADDR = trim($HTTP_X_FORWARDED_FOR[0]);
830
- }
831
-
832
- }
833
-
834
- return preg_replace('/[^0-9a-f:\., ]/si', '', $REMOTE_ADDR);
835
-
836
- } else {
837
- return ('X.X.X.X');
838
- }
839
-
840
-
841
- }
842
-
843
-
844
- /*function to remove duplicate in an array for a specific key
845
- Taken value: array to search, key
846
- */
847
-
848
- function yasr_unique_multidim_array($array, $key) {
849
-
850
- $temp_array = array();
851
- $i = 0;
852
-
853
- //creo un array vuoto che conterrà solo gli indici
854
- $key_array = array();
855
-
856
- foreach ($array as $val) {
857
-
858
- $result_search_array = array_search($val[$key], $key_array);
859
-
860
- $key_array[$i] = $val[$key];
861
- $temp_array[$i] = $val;
862
-
863
- //if result is found
864
- if ($result_search_array !== false) {
865
-
866
- unset($key_array[$result_search_array], $temp_array[$result_search_array]);
867
-
868
- }
869
-
870
- $i ++;
871
-
872
- }
873
-
874
- sort($temp_array);
875
-
876
- return $temp_array;
877
-
878
- }
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
-
886
- function yasr_delete_cache($array_action_visitor_vote) {
887
-
888
- if (isset($array_action_visitor_vote['post_id'])) {
889
- $post_id = $array_action_visitor_vote['post_id'];
890
- } else {
891
- return;
892
- }
893
-
894
- if (isset($array_action_visitor_vote['is_singular'])) {
895
- $is_singular = $array_action_visitor_vote['is_singular'];
896
- } else {
897
- return;
898
- }
899
-
900
- yasr_wp_super_cache_support($post_id);
901
- yasr_wp_rocket_support($post_id);
902
- yasr_litespeed_cache_support($post_id);
903
- yasr_cache_enabler_support($post_id, $is_singular);
904
- yasr_wp_fastest_cache($post_id, $is_singular);
905
-
906
- }
907
-
908
-
909
- function yasr_check_valid_url($url) {
910
-
911
- $timeout = 5;
912
-
913
- //Check if url is valid
914
- if (filter_var($url, FILTER_VALIDATE_URL) !== false) {
915
-
916
- //Check if curl is installed
917
- if (function_exists('curl_version')) {
918
-
919
- $ch = curl_init();
920
- curl_setopt($ch, CURLOPT_URL, $url);
921
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
922
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
923
-
924
- //execute curl
925
- $http_respond = trim(strip_tags(curl_exec($ch)));
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;
933
- }
934
- //close curl
935
- curl_close($ch);
936
-
937
- } //if curl is not installed, use file_get_contents
938
- else {
939
-
940
- //...but only if enabled on the server!
941
- if (ini_get('allow_url_fopen')) {
942
-
943
- //Change timeout for file_get_contents
944
- ini_set('default_socket_timeout', $timeout); //5 seconds
945
-
946
- $headers = get_headers($url, 1);
947
- $string_to_check = '200 OK';
948
-
949
- //check if in the first heade we've 200 OK
950
- if (strpos($headers[0], $string_to_check) !== false) {
951
- return true;
952
- } else {
953
- return false;
954
- }
955
- } //if url_fopen is not enabled
956
- else {
957
- return false;
958
- }
959
-
960
- }
961
- } else {
962
- return false;
963
- }
964
-
965
- }
966
-
967
-
968
- /**
969
- * Check if the given string is a supported itemType
970
- *
971
- * @param string $item_type
972
- * @return bool
973
- *
974
- * @since 2.1.5
975
- */
976
-
977
- function yasr_is_supported_schema ($item_type) {
978
- $supported_schema_array = json_decode(YASR_SUPPORTED_SCHEMA_TYPES);
979
-
980
- if (in_array($item_type, $supported_schema_array)) {
981
- return true;
982
- }
983
-
984
- return false;
985
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/yasr-shortcode-classes.php DELETED
@@ -1,1044 +0,0 @@
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 YasrShortcode
27
- *
28
- * @since 2.1.5
29
- *
30
- */
31
- class YasrShortcode {
32
- public $shortcode_html;
33
- public $post_id; //false
34
- public $size; //large
35
- public $readonly; //false
36
- public $set_id; //1
37
- public $show_average; //null
38
- public $shorcode_name;
39
-
40
- public function __construct($atts, $shortcode_name) {
41
- $this->shorcode_name = $shortcode_name;
42
-
43
- if ($atts !== false) {
44
- $atts = shortcode_atts(
45
- array(
46
- 'size' => 'large',
47
- 'postid' => false,
48
- 'readonly' => false,
49
- 'setid' => 1,
50
- 'show_average' => null
51
- ),
52
- $atts,
53
- $shortcode_name
54
- );
55
-
56
- if ($atts['postid'] === false) {
57
- $this->post_id = get_the_ID();
58
- } else {
59
- $this->post_id = (int) $atts['postid'];
60
- }
61
- $this->size = sanitize_text_field($atts['size']);
62
- $this->readonly = sanitize_text_field($atts['readonly']);
63
- $this->set_id = (int) $atts['setid'];
64
- $this->show_average = sanitize_text_field($atts['show_average']);
65
- }
66
- }
67
-
68
- /**
69
- * Return the stars size according to size attribute in shortcode.
70
- * If not used, return 32 (default value)
71
- *
72
- * @return int
73
- */
74
- protected function starSize() {
75
- if ($this->shorcode_name === 'yasr_top_ten_highest_rated'
76
- || $this->shorcode_name === 'yasr_most_or_highest_rated_posts') {
77
- return 24;
78
- }
79
-
80
- $size = $this->size;
81
- $px_size = 32; //default value
82
-
83
- if ($size === 'small') {
84
- $px_size = 16;
85
- } elseif ($size === 'medium') {
86
- $px_size = 24;
87
- }
88
- return $px_size;
89
- }
90
- }
91
-
92
-
93
- /**
94
- * Class YasrOverallRating
95
- * Print Yasr Overall Rating
96
- */
97
- class YasrOverallRating extends YasrShortcode {
98
-
99
- protected $html_stars;
100
- protected $overall_rating;
101
-
102
- /**
103
- * Print the visitor votes shortcode
104
- *
105
- * @return string|null
106
- */
107
-
108
- function printOverallRating () {
109
-
110
- //do not run in admin (problem with tinymce)
111
- if(is_admin()) {
112
- return false;
113
- }
114
-
115
- $stars_size = $this->starSize();
116
- $this->overall_rating = YasrDatabaseRatings::getOverallRating($this->post_id);
117
-
118
- $this->shortcode_html = '<!--Yasr Overall Rating Shortcode-->';
119
-
120
- //generate an unique id to be sure that every element has a different ID
121
- $unique_id = str_shuffle(uniqid());
122
- $overall_rating_html_id = 'yasr-overall-rating-rater-' . $unique_id;
123
-
124
- $this->html_stars = "<div class='yasr-overall-rating'>
125
- <div class='yasr-rater-stars'
126
- id='$overall_rating_html_id'
127
- data-rating='$this->overall_rating'
128
- data-rater-starsize='$stars_size' >
129
- </div>
130
- </div>";
131
-
132
- $this->customTextBefore();
133
- $this->shortcode_html .= '<!--End Yasr Overall Rating Shortcode-->';
134
-
135
- //If overall rating in loop is enabled don't use is_singular && is main_query
136
- if (YASR_SHOW_OVERALL_IN_LOOP === 'enabled') {
137
- return $this->shortcode_html;
138
- } //default
139
- else {
140
- if (is_singular() && is_main_query()) {
141
- return $this->shortcode_html;
142
- }
143
- return null;
144
- }
145
- }
146
-
147
- /**
148
- * If enabled in the settings, this function will show the custom text
149
- * before or after the stars in yasr_visitor_votes
150
- *
151
- * @param void
152
- * @return void
153
- *
154
- */
155
- protected function customTextBefore() {
156
- if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_BEFORE_OVERALL != '') {
157
- $text_before_star = str_replace('%overall_rating%', $this->overall_rating, YASR_TEXT_BEFORE_OVERALL);
158
- $this->shortcode_html = "<div class='yasr-container-custom-text-and-overall'>
159
- <span id='yasr-custom-text-before-overall'>" . $text_before_star . "</span>
160
- $this->html_stars
161
- </div>";
162
- } else {
163
- $this->shortcode_html .= $this->html_stars;
164
- }
165
- }
166
-
167
- }
168
-
169
- /**
170
- * Class YasrVisitorVotes
171
- * Print Yasr Visitor Votes
172
- */
173
- class YasrVisitorVotes extends YasrShortcode {
174
-
175
- protected $votes_number = 0;
176
- protected $medium_rating = 0;
177
- protected $cookie_value = false; //avoid undefined
178
- protected $span_bottom_line;
179
- protected $span_text_after_stars;
180
-
181
- /**
182
- * Print the visitor votes shortcode
183
- *
184
- * @return string|null
185
- */
186
- public function printVisitorVotes() {
187
-
188
- //do not run in admin (problem with tinymce)
189
- if(is_admin()) {
190
- return false;
191
- }
192
-
193
- $stars_size = $this->starSize();
194
-
195
- $unique_id = str_shuffle(uniqid());
196
- $htmlid = 'yasr-visitor-votes-rater-' . $unique_id ;
197
- $span_container_after_stars = "<span id='yasr-visitor-votes-container-after-stars-$unique_id'
198
- class='yasr-visitor-votes-after-stars-class'>";
199
- $stored_votes = YasrDatabaseRatings::getVisitorVotes($this->post_id); //always reference it
200
-
201
- $this->votes_number = $stored_votes['number_of_votes'];
202
- if ($this->votes_number != 0) {
203
- $this->medium_rating = ($stored_votes['sum_votes']/$this->votes_number);
204
- } else {
205
- $this->medium_rating = 0;
206
- }
207
-
208
- $this->medium_rating=round($this->medium_rating, 1);
209
-
210
- if (is_singular()) {
211
- $is_singular = 'true';
212
- } else {
213
- $is_singular = 'false';
214
- }
215
-
216
- $this->shortcode_html = '<!--Yasr Visitor Votes Shortcode-->';
217
-
218
- //if this come from yasr_visitor_votes_readonly...
219
- if ($this->readonly === true || $this->readonly === "yes") {
220
- $htmlid = 'yasr-visitor-votes-readonly-rater-'.$unique_id;
221
-
222
- $this->shortcode_html = "<div class='yasr-rater-stars-visitor-votes'
223
- id='$htmlid'
224
- data-rating='$this->medium_rating'
225
- data-rater-starsize='$stars_size'
226
- data-rater-postid='$this->post_id'
227
- data-rater-readonly='true'>
228
- </div>";
229
-
230
- return $this->shortcode_html;
231
- }
232
-
233
- $ajax_nonce_visitor = wp_create_nonce("yasr_nonce_insert_visitor_rating");
234
-
235
- $this->shortcode_html .= "<div id='yasr_visitor_votes_$this->post_id' class='yasr-visitor-votes'>";
236
-
237
- $this->checkCookie();
238
- $this->allowedUser();
239
- $this->customTextBeforeAfter();
240
-
241
- $this->shortcode_html .= "<div id='$htmlid'
242
- class='yasr-rater-stars-visitor-votes'
243
- data-rater-postid='$this->post_id'
244
- data-rating='$this->medium_rating'
245
- data-rater-starsize='$stars_size'
246
- data-rater-readonly='$this->readonly'
247
- data-rater-nonce='$ajax_nonce_visitor'
248
- data-issingular='$is_singular'
249
- ></div>";
250
- $this->shortcode_html .= $span_container_after_stars;
251
- $this->shortcode_html .= $this->visitorStats();
252
- $this->shortcode_html .= $this->span_text_after_stars;
253
- $this->shortcode_html .= $this->span_bottom_line;
254
- $this->shortcode_html .= '</span>'; //Close yasr-visitor-votes-after-stars and yasr_visitor_votes
255
- $this->shortcode_html .= '</div>'; //close all
256
- $this->shortcode_html .= '<!--End Yasr Visitor Votes Shortcode-->';
257
-
258
- //If visitor_votes in loop is enabled don't use is_singular && is main_query
259
- if (YASR_SHOW_VISITOR_VOTES_IN_LOOP === 'enabled') {
260
- return $this->shortcode_html;
261
- }
262
-
263
- //default value
264
- else {
265
- if (is_singular() && is_main_query()) {
266
- return $this->shortcode_html;
267
- }
268
- return null;
269
- }
270
- } //end function
271
-
272
- /**
273
- * Function that checks if cookie exists and set the value
274
- *
275
- * @param void
276
- * @return void
277
- */
278
- protected function checkCookie () {
279
- //name of cookie to check
280
- $yasr_cookiename = 'yasr_visitor_vote_cookie';
281
-
282
- if (isset($_COOKIE[$yasr_cookiename])) {
283
- $cookie_data = stripslashes($_COOKIE[$yasr_cookiename]);
284
-
285
- //By default, json_decode return an object, true to return an array
286
- $cookie_data = json_decode($cookie_data, true);
287
-
288
- if (is_array($cookie_data)) {
289
- foreach ($cookie_data as $value) {
290
- $cookie_post_id = (int)$value['post_id'];
291
- if ($cookie_post_id === $this->post_id) {
292
- $this->cookie_value = (int)$value['rating'];
293
- //Stop doing foreach, here we've found the rating for current post
294
- break;
295
- }
296
- }
297
- }
298
- if ($this->cookie_value !== false && $this->cookie_value > 5) {
299
- $this->cookie_value = 5;
300
- } elseif ($this->cookie_value !== false && $this->cookie_value < 1) {
301
- $this->cookie_value = 1;
302
- }
303
- }
304
- }
305
-
306
- /**
307
- * This function checks who can rate to the shortcode
308
- *
309
- * @param void
310
- * @return void
311
- */
312
- protected function allowedUser () {
313
- //I've to check a logged in user that has already rated
314
- if (is_user_logged_in()) {
315
- $this->readonly = 'false'; //Always false if user is logged in
316
-
317
- //Check if a logged in user has already rated for this post
318
- $vote_if_user_already_rated = YasrDatabaseRatings::visitorVotesHasUserVoted($this->post_id);
319
-
320
- //If user has already rated
321
- if ($vote_if_user_already_rated) {
322
- $this->span_bottom_line="<span class='yasr-small-block-bold yasr-already-voted-text'
323
- id='yasr-user-vote-$this->post_id'
324
- data-yasr-already-voted='$vote_if_user_already_rated'>"
325
- .__("You've already voted this article with", 'yet-another-stars-rating') .
326
- " $vote_if_user_already_rated
327
- </span>";
328
- }
329
- } //End if user is logged
330
-
331
- //if anonymous are allowed to vote
332
- if (YASR_ALLOWED_USER === 'allow_anonymous') {
333
- //IF user is not logged in
334
- if (!is_user_logged_in()) {
335
- //if cookie exists
336
- if ($this->cookie_value) {
337
- $this->readonly = 'true';
338
- $this->span_bottom_line = "<span class='yasr-small-block-bold yasr-already-voted-text'>";
339
- if (YASR_TEXT_BEFORE_STARS == 1 && YASR_CUSTOM_TEXT_USER_VOTED != '') {
340
- $this->span_bottom_line .= YASR_CUSTOM_TEXT_USER_VOTED;
341
- } else {
342
- $this->span_bottom_line .= __('You\'ve already voted this article with', 'yet-another-stars-rating') . $this->cookie_value;
343
- }
344
- $this->span_bottom_line .= '</span>';
345
- } else {
346
- $this->readonly = 'false';
347
- }
348
- }
349
- } //end if YASR_ALLOWED_USER === 'allow_anonymous' {
350
-
351
- //If only logged in users can vote
352
- elseif (YASR_ALLOWED_USER === 'logged_only') {
353
- //IF user is not logged in
354
- if (!is_user_logged_in()) {
355
- $this->readonly = 'true'; //readonly is true if user isn't logged
356
-
357
- $this->span_bottom_line = "<span class=\"yasr-visitor-votes-must-sign-in\">";
358
-
359
- //if custom text is defined
360
- if (defined('YASR_CUSTOM_TEXT_MUST_SIGN_IN') && YASR_CUSTOM_TEXT_MUST_SIGN_IN !== '') {
361
- $this->span_bottom_line .= YASR_CUSTOM_TEXT_MUST_SIGN_IN;
362
- } else {
363
- $this->span_bottom_line .= __('You must sign in to vote', 'yet-another-stars-rating');
364
- }
365
- $this->span_bottom_line .= "</span>";
366
- }
367
-
368
- }
369
- }
370
-
371
- /**
372
- * If enabled in the settings, this function will show the custom text
373
- * before or after the stars in yasr_visitor_votes
374
- *
375
- * @param void
376
- * @return void
377
- */
378
- protected function customTextBeforeAfter () {
379
-
380
- $this->span_text_after_stars = "<span class='yasr-total-average-container'
381
- id='yasr-total-average-text_$this->post_id'>";
382
-
383
- if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_BEFORE_VISITOR_RATING != '') {
384
- $text_before_star = str_replace('%total_count%', $this->votes_number, YASR_TEXT_BEFORE_VISITOR_RATING);
385
- $text_before_star = str_replace('%average%', $this->medium_rating, $text_before_star);
386
- $this->shortcode_html .= "<div class='yasr-container-custom-text-and-visitor-rating'>
387
- <span id='yasr-custom-text-before-visitor-rating'>"
388
- . $text_before_star .
389
- "</span></div>";
390
- }
391
-
392
- if (YASR_TEXT_BEFORE_STARS == 1 && YASR_TEXT_AFTER_VISITOR_RATING != '') {
393
- $text_after_star = str_replace('%total_count%', $this->votes_number, YASR_TEXT_AFTER_VISITOR_RATING);
394
- $text_after_star = str_replace('%average%', $this->medium_rating, $text_after_star);
395
- $this->span_text_after_stars .= $text_after_star;
396
- } else {
397
- $this->span_text_after_stars .= '['
398
- . __('Total:', 'yet-another-stars-rating')
399
- . '&nbsp;' . $this->votes_number . '&nbsp; &nbsp;'
400
- . __('Average:', 'yet-another-stars-rating')
401
- . '&nbsp;' . $this->medium_rating
402
- . '/5]';
403
- }
404
-
405
- $this->span_text_after_stars .= '</span>';
406
- }
407
-
408
- /**
409
- * This function will return the html code for the dashicons
410
- *
411
- * @param void
412
- *
413
- * @return string
414
- */
415
- protected function visitorStats () {
416
- if (YASR_VISITORS_STATS === 'yes') {
417
- global $yasr_plugin_imported;
418
-
419
- //default
420
- $span_dashicon = "<span class='dashicons dashicons-chart-bar yasr-dashicons-visitor-stats'
421
- data-postid='$this->post_id' id='yasr-total-average-dashicon-$this->post_id'></span>";
422
-
423
- if (is_array($yasr_plugin_imported)) {
424
- $plugin_import_date = null; //avoid undefined
425
- if (array_key_exists('wppr', $yasr_plugin_imported)) {
426
- $plugin_import_date = $yasr_plugin_imported['wppr']['date'];
427
- }
428
-
429
- if (array_key_exists('kksr', $yasr_plugin_imported)) {
430
- $plugin_import_date = $yasr_plugin_imported['kksr']['date'];
431
- }
432
-
433
- if (array_key_exists('mr', $yasr_plugin_imported)) {
434
- $plugin_import_date = $yasr_plugin_imported['mr']['date'];
435
- }
436
-
437
- //remove hour from date
438
- $plugin_import_date=strtok($plugin_import_date,' ');
439
-
440
- $post_date = get_the_date('Y-m-d', $this->post_id);
441
-
442
- //if one of these plugin has been imported and post is older then import, hide stats
443
- if ($post_date < $plugin_import_date) {
444
- $span_dashicon = "";
445
- }
446
- } //End if $yasr_plugin_imported
447
- } else {
448
- //Yasr_visitor_stats are disabled
449
- $span_dashicon = "";
450
- }
451
- return $span_dashicon;
452
- }
453
- }
454
-
455
-
456
- /**
457
- * Class YasrMultiSet
458
- */
459
- class YasrMultiSet extends YasrShortcode {
460
- /**
461
- * @return string | bool
462
- */
463
- public function printMultiset () {
464
-
465
- //do not run in admin (problem with tinymce)
466
- if(is_admin()) {
467
- return false;
468
- }
469
-
470
- $this->shortcode_html = '<!-- Yasr Multi Set Shortcode-->';
471
-
472
- $multiset_content = YasrMultiSetData::returnMultisetContent($this->post_id, $this->set_id);
473
-
474
- if ($multiset_content === false) {
475
- $string = __('No Set Found with this ID', 'yet-another-stars-rating');
476
- return $this->shortcode_html . $string;
477
- }
478
-
479
- $this->shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
480
- $this->shortcode_html .= '<table class="yasr_table_multi_set_shortcode">';
481
- $this->star_readonly = 'true';
482
-
483
- $this->printMultisetRows($multiset_content);
484
-
485
- $this->shortcode_html .= "</table>";
486
- $this->shortcode_html .= '<!--End Yasr Multi Set Shortcode-->';
487
-
488
- return $this->shortcode_html;
489
- }
490
-
491
-
492
- /**
493
- *
494
- * This function insert into $this->shortcode_html the rows of both multisets (average included)
495
- *
496
- * @param $multiset_content
497
- * @param bool $visitor_multiset
498
- *
499
- * @return void
500
- *
501
- */
502
- protected function printMultisetRows($multiset_content, $visitor_multiset=false) {
503
-
504
- $multiset_string = 'yasr-average-multiset-';
505
- if ($visitor_multiset === true) {
506
- $multiset_string = 'yasr-visitor-multi-set-average-';
507
- }
508
-
509
- foreach ($multiset_content as $set_content) {
510
- $unique_id_identifier = 'yasr-multiset-' . str_shuffle(uniqid());
511
-
512
- $average_rating = round($set_content['average_rating'], 1);
513
-
514
- $html_stars = "<div class='yasr-multiset-visitors-rater'
515
- id='$unique_id_identifier'
516
- data-rater-postid='$this->post_id'
517
- data-rater-setid='$this->set_id'
518
- data-rater-set-field-id='$set_content[id]'
519
- data-rating='$average_rating'
520
- data-rater-readonly='$this->star_readonly'>
521
- </div>";
522
-
523
- $span_container_number_of_votes = '';
524
- if ($visitor_multiset === true) {
525
- $span_container_number_of_votes = '<span class="yasr-visitor-multiset-vote-count">'
526
- . $set_content['number_of_votes'] .
527
- '</span>';
528
- }
529
-
530
- $this->shortcode_html .= '<tr>
531
- <td>
532
- <span class="yasr-multi-set-name-field">' . $set_content['name'] . '</span>
533
- </td>
534
- <td>'
535
- . $html_stars . $span_container_number_of_votes .
536
- '</td>
537
- </tr>';
538
-
539
- } //End foreach
540
-
541
- //If average row should be showed
542
- if ($this->show_average_multiset() === true) {
543
- //get the average of the multiset
544
- $multiset_average = YasrMultiSetData::returnMultiSetAverage($this->post_id, $this->set_id, $visitor_multiset);
545
-
546
- //print it
547
- $this->shortcode_html .= $this->printAverageRowMultiSet($multiset_average, $multiset_string);
548
- }
549
-
550
- }
551
-
552
- /**
553
- * This function return the html code of the average multiset
554
- *
555
- * @since 2.1.0
556
- *
557
- * @param $multiset_average
558
- * @param $multiset_string
559
- *
560
- * @return string
561
- */
562
- protected function printAverageRowMultiSet($multiset_average, $multiset_string) {
563
- $average_txt = __("Average", "yet-another-stars-rating");
564
- $html_average = null;
565
-
566
- //Show average row
567
- if ($this->show_average_multiset() === true) {
568
- $unique_id_identifier = $multiset_string . str_shuffle(uniqid());
569
-
570
- $html_average = "<tr>
571
- <td colspan='2' class='yasr-multiset-average'>
572
- <div class='yasr-multiset-average'>
573
- <span class='yasr-multiset-average-text'>$average_txt</span>
574
- <div class='yasr-rater-stars' id='$unique_id_identifier'
575
- data-rating='$multiset_average' data-rater-readonly='true'
576
- data-rater-starsize='24'></div>
577
- </div>
578
- </td>
579
- </tr>";
580
- }
581
-
582
- return $html_average;
583
- }
584
-
585
- /**
586
- * Return true or false if average should be displayed
587
- *
588
- * @return bool
589
- */
590
- public function show_average_multiset() {
591
- if ($this->show_average === '' && YASR_MULTI_SHOW_AVERAGE !== 'no' ||
592
- $this->show_average !== '' && $this->show_average !== 'no') {
593
- return true;
594
- }
595
- else {
596
- return false;
597
- }
598
- }
599
-
600
- }
601
-
602
- /**
603
- * Class YasrVisitorMultiSet
604
- */
605
- class YasrVisitorMultiSet extends YasrMultiSet {
606
-
607
- protected $loader_html;
608
- protected $button_html;
609
- protected $button_html_disabled;
610
- protected $button;
611
- protected $star_readonly;
612
- protected $span_message_content;
613
-
614
-
615
- /**
616
- * Print Yasr Visitor MultiSet
617
- *
618
- * @param void
619
- * @return string
620
- */
621
- public function printVisitorMultiSet () {
622
-
623
- //do not run in admin (problem with tinymce)
624
- if(is_admin()) {
625
- return false;
626
- }
627
-
628
- $ajax_nonce_visitor_multiset = wp_create_nonce("yasr_nonce_insert_visitor_rating_multiset");
629
-
630
- $this->shortcode_html = '<!-- Yasr Visitor Multi Set Shortcode-->';
631
-
632
- $image = YASR_IMG_DIR . "/loader.gif";
633
- $this->loader_html = "<span class='yasr-loader-multiset-visitor'
634
- id='yasr-loader-multiset-visitor-$this->post_id-$this->set_id'>
635
- &nbsp;<img src='$image' title='yasr-loader' alt='yasr-loader'>
636
- </span>";
637
-
638
- $this->button_html = "<input type='submit'
639
- name='submit'
640
- id='yasr-send-visitor-multiset-$this->post_id-$this->set_id'
641
- class='button button-primary yasr-send-visitor-multiset'
642
- data-postid='$this->post_id'
643
- data-setid='$this->set_id'
644
- value='" . __('Submit!', 'yet-another-stars-rating') . "'
645
- />";
646
-
647
- $this->button_html_disabled = "<input type='submit'
648
- disabled='disabled'
649
- class='button button-primary'
650
- id='yasr-send-visitor-multiset-disabled'
651
- disabled='disabled'
652
- value='" . __('Submit!', 'yet-another-stars-rating') . "'
653
- />";
654
-
655
- //check cookie and assign default values
656
- $this->multisetAttributes();
657
-
658
- $set_name_content = YasrMultiSetData::returnVisitorMultiSetContent($this->post_id, $this->set_id);
659
-
660
- if (!$set_name_content) {
661
- $this->shortcode_html .= __('No MultiSet found with this ID', 'yet-another-stars-rating');
662
- return $this->shortcode_html;
663
- }
664
-
665
- $this->shortcode_html .= "<table class='yasr_table_multi_set_shortcode'>";
666
-
667
- $this->printMultisetRows($set_name_content, true);
668
-
669
- //Submit row and button
670
- $this->shortcode_html .="<tr>
671
- <td colspan='2'>
672
- $this->button
673
- $this->loader_html
674
- <span class='yasr-visitor-multiset-message'>$this->span_message_content</span>
675
- </td>
676
- </tr>
677
- ";
678
-
679
- $this->shortcode_html .= "</table>";
680
- $this->shortcode_html .= '<!-- End Yasr Multi Set Visitor Shortcode-->';
681
-
682
- wp_localize_script(
683
- 'yasrfront',
684
- "yasrMultiSetData",
685
- array(
686
- 'nonceVisitor' => $ajax_nonce_visitor_multiset,
687
- 'setType' => $this->set_id
688
- )
689
- );
690
-
691
- return $this->shortcode_html;
692
- }
693
-
694
- /**
695
- * This function first check if a cookie is set,
696
- * Then who can rate and set attributes to:
697
- * $this->button
698
- * $this->star_readonly
699
- * $this->span_message_content
700
- *
701
- * @param void
702
- * @return void
703
- *
704
- */
705
- protected function multisetAttributes() {
706
- $yasr_cookiename = 'yasr_multi_visitor_cookie';
707
-
708
- //Check cookie and if voting is allowed only to logged in users
709
- if (isset($_COOKIE[$yasr_cookiename])) {
710
- $cookie_data = stripslashes($_COOKIE[ $yasr_cookiename ]);
711
-
712
- //By default, json_decode return an object, true to return an array
713
- $cookie_data = json_decode($cookie_data, true);
714
-
715
- if (is_array($cookie_data)) {
716
- foreach ($cookie_data as $value) {
717
- $cookie_post_id = (int)$value['post_id'];
718
- $cookie_set_id = (int)$value['set_id'];
719
-
720
- if ($cookie_post_id === $this->post_id && $cookie_set_id === $this->set_id) {
721
- $this->button = "";
722
- $this->star_readonly = 'true';
723
- $this->span_message_content = __('Thank you for voting!', 'yet-another-stars-rating');
724
-
725
- //Stop doing foreach, here we've found the rating for current post
726
- break;
727
- } else {
728
- $this->button = $this->button_html;
729
- $this->star_readonly = 'false';
730
- $this->span_message_content = "";
731
- }
732
- }
733
- }
734
- } else {
735
- //If user is not logged in
736
- if (!is_user_logged_in()) {
737
- if (YASR_ALLOWED_USER === 'allow_anonymous') {
738
- $this->button = $this->button_html;
739
- $this->star_readonly = 'false';
740
- $this->span_message_content = "";
741
- } elseif (YASR_ALLOWED_USER === 'logged_only') {
742
- $this->button = $this->button_html_disabled;
743
- $this->star_readonly = 'true';
744
- $this->span_message_content = '<span class="yasr-visitor-votes-must-sign-in">';
745
-
746
- if (defined('YASR_CUSTOM_TEXT_MUST_SIGN_IN') && YASR_CUSTOM_TEXT_MUST_SIGN_IN !== '') {
747
- $this->span_message_content .= YASR_CUSTOM_TEXT_MUST_SIGN_IN;
748
- } else {
749
- $this->span_message_content .= __('You must sign in to vote', 'yet-another-stars-rating');
750
- }
751
- $this->span_message_content .= '</span>';
752
- }
753
- } //End if user logged in
754
-
755
- //User is logged in
756
- else {
757
- $this->button = $this->button_html;
758
- $this->star_readonly = 'false';
759
- $this->span_message_content = "";
760
- }
761
- }
762
- }
763
- }
764
-
765
- /**
766
- * Class YasrRankings
767
- */
768
- class YasrRankings extends YasrShortcode {
769
-
770
- protected $query_highest_rated_overall;
771
- protected $query_result_most_rated_visitor;
772
- protected $query_result_highest_rated_visitor;
773
- protected $vv_highest_rated_table;
774
- protected $vv_most_rated_table;
775
-
776
- /*
777
- *
778
- * */
779
- public function returnHighestRatedOverall () {
780
- $this->shortcode_html = '<!-- Yasr Most Or Highest Rated Shortcode-->';
781
-
782
- global $wpdb;
783
-
784
- $this->query_highest_rated_overall = $wpdb->get_results("
785
- SELECT pm.meta_value AS overall_rating,
786
- pm.post_id AS post_id
787
- FROM $wpdb->postmeta AS pm,
788
- $wpdb->posts AS p
789
- WHERE pm.post_id = p.ID
790
- AND p.post_status = 'publish'
791
- AND pm.meta_key = 'yasr_overall_rating'
792
- ORDER BY pm.meta_value DESC,
793
- pm.post_id
794
- LIMIT 10"
795
- );
796
-
797
- $this->loopHighestRatedOverall();
798
-
799
- $this->shortcode_html .= '<!--End Yasr Top 10 highest Rated Shortcode-->';
800
- return $this->shortcode_html;
801
-
802
- }
803
-
804
- protected function loopHighestRatedOverall($text_position=false, $text=false) {
805
- if ($this->query_highest_rated_overall) {
806
- $this->shortcode_html .= "<table class='yasr-table-chart'>";
807
-
808
- foreach ($this->query_highest_rated_overall as $result) {
809
- $post_title = wp_strip_all_tags(get_the_title($result->post_id));
810
- $link = get_permalink($result->post_id); //Get permalink from post id
811
- $yasr_top_ten_html_id = 'yasr-highest_rated-' . str_shuffle(uniqid());
812
-
813
- $this->returnTableRows($result->post_id,
814
- $result->overall_rating,
815
- null,
816
- $post_title,
817
- $link, $yasr_top_ten_html_id);
818
-
819
-
820
- } //End foreach
821
- $this->shortcode_html .= "</table>";
822
- }
823
- else {
824
- _e("You don't have any votes stored", 'yet-another-stars-rating');
825
- }
826
-
827
- }
828
-
829
- /**
830
- * Create the queries for the rankings
831
- *
832
- * Return the full html for the shortcode
833
- *
834
- * @return string $this->shortcode_html;
835
- */
836
- public function vvReturnMostHighestRatedPost() {
837
- $this->shortcode_html = '<!-- Yasr Most Or Highest Rated Shortcode-->';
838
-
839
- global $wpdb;
840
-
841
- $this->query_result_most_rated_visitor = $wpdb->get_results(
842
- "SELECT post_id,
843
- COUNT(post_id) AS number_of_votes,
844
- SUM(vote) AS sum_votes
845
- FROM " . YASR_LOG_TABLE . ",
846
- $wpdb->posts AS p
847
- WHERE post_id = p.ID
848
- AND p.post_status = 'publish'
849
- GROUP BY post_id
850
- HAVING number_of_votes > 1
851
- ORDER BY number_of_votes DESC,
852
- post_id DESC
853
- LIMIT 10"
854
- );
855
-
856
- //count run twice but access data only once: tested with query monitor and asked
857
- //here http://stackoverflow.com/questions/39201235/does-count-run-twice/39201492
858
- $this->query_result_highest_rated_visitor = $wpdb->get_results(
859
- "SELECT post_id,
860
- COUNT(post_id) AS number_of_votes,
861
- (SUM(vote) / COUNT(post_id)) AS result
862
- FROM " . YASR_LOG_TABLE . " ,
863
- $wpdb->posts AS p
864
- WHERE post_id = p.ID
865
- AND p.post_status = 'publish'
866
- GROUP BY post_id
867
- HAVING COUNT(post_id) >= 2
868
- ORDER BY result DESC,
869
- number_of_votes DESC
870
- LIMIT 10"
871
- );
872
-
873
- $this->vv_highest_rated_table = "<table class='yasr-table-chart' id='yasr-highest-rated-posts'>
874
- <tr class='yasr-visitor-votes-title'>
875
- <th>" . __('Post / Page', 'yet-another-stars-rating') . "</th>
876
- <th>" . __('Order By', 'yet-another-stars-rating') . ":&nbsp;&nbsp;
877
- <span id='link-yasr-most-rated-posts'>
878
- <a href='' onclick='yasrShowMost(); return false'>"
879
- . __("Most Rated", 'yet-another-stars-rating') .
880
- "</a> |
881
- <span id='yasr_multi_chart_link_to_nothing'>"
882
- . __("Highest Rated", 'yet-another-stars-rating') .
883
- "</span>
884
- </th>
885
- </tr>";
886
-
887
- $this->vv_most_rated_table = "<table class='yasr-table-chart' id='yasr-most-rated-posts'>
888
- <tr class='yasr-visitor-votes-title'>
889
- <th>" . __('Post / Page', 'yet-another-stars-rating') . " </th>
890
- <th>" . __('Order By', 'yet-another-stars-rating') . ":&nbsp;&nbsp;
891
- <span id='yasr_multi_chart_link_to_nothing'>"
892
- . __('Most Rated', 'yet-another-stars-rating') .
893
- "</span> |
894
- <span id='link-yasr-highest-rated-posts'>
895
- <a href='' onclick='yasrShowHighest(); return false'>"
896
- . __('Highest Rated', 'yet-another-stars-rating') .
897
- "</a>
898
- </span>
899
- </th>
900
- </tr>";
901
-
902
- $this->vvMostRated();
903
- $this->vvHighestRated();
904
-
905
- $this->shortcode_html .= '<!-- End Yasr Most Or Highest Rated Shortcode-->';
906
-
907
- wp_localize_script( 'yasrfront', "yasrMostHighestRanking", array(
908
- 'enable' => 'yes'
909
- )
910
- );
911
-
912
- return $this->shortcode_html;
913
-
914
- }
915
-
916
- /**
917
- * Loop the query for the Most Rated chart
918
- */
919
- protected function vvMostRated() {
920
- if ($this->query_result_most_rated_visitor) {
921
-
922
- $this->shortcode_html .= $this->vv_most_rated_table;
923
-
924
- foreach ($this->query_result_most_rated_visitor as $result) {
925
- $rating = round($result->sum_votes / $result->number_of_votes, 1);
926
- $post_title = wp_strip_all_tags(get_the_title($result->post_id));
927
- $link = get_permalink($result->post_id); //Get permalink from post id
928
- $yasr_top_ten_html_id = 'yasr-10-most-rated-' . str_shuffle(uniqid());
929
-
930
- //print the rows
931
- $this->returnTableRows($result->post_id,
932
- $rating,
933
- $result->number_of_votes,
934
- $post_title,
935
- $link,
936
- $yasr_top_ten_html_id
937
- );
938
-
939
- } //End foreach
940
- $this->shortcode_html .= "</table>" ;
941
-
942
- } //End if $query_result_most_rated)
943
-
944
- else {
945
- $this->shortcode_html = __("You've not enough data",'yet-another-stars-rating') . "<br />";
946
- }
947
- }
948
-
949
- /**
950
- * Loop the query for the Highest Rated chart
951
- */
952
- protected function vvHighestRated () {
953
- if ($this->query_result_highest_rated_visitor) {
954
-
955
- $this->shortcode_html .= $this->vv_highest_rated_table;
956
-
957
- foreach ($this->query_result_highest_rated_visitor as $result) {
958
- $rating = round($result->result, 1);
959
- $post_title = wp_strip_all_tags(get_the_title($result->post_id));
960
- $link = get_permalink($result->post_id); //Get permalink from post id
961
- $yasr_top_ten_html_id = 'yasr-10-highest-rater-' . str_shuffle(uniqid());
962
-
963
- //print the rows
964
- $this->returnTableRows($result->post_id,
965
- $rating,
966
- $result->number_of_votes,
967
- $post_title,
968
- $link,
969
- $yasr_top_ten_html_id
970
- );
971
-
972
- } //End foreach
973
-
974
- $this->shortcode_html .= "</table>";
975
-
976
- } //end if $query_result
977
-
978
- else {
979
- $this->shortcode_html = __("You've not enought data",'yet-another-stars-rating') . "<br />";
980
- }
981
- }
982
-
983
- /**
984
- * @param $post_id
985
- * @param $rating
986
- * @param $number_of_votes
987
- * @param $post_title
988
- * @param $link
989
- * @param $yasr_top_ten_html_id
990
- */
991
- protected function returnTableRows ($post_id, $rating, $number_of_votes, $post_title, $link, $yasr_top_ten_html_id) {
992
- $star_size = $this->starSize();
993
-
994
- $html_stars = "<div
995
- class='yasr-rater-stars'
996
- id='$yasr_top_ten_html_id'
997
- data-rater-postid='$post_id'
998
- data-rater-starsize=$star_size
999
- data-rating='$rating'>
1000
- </div>";
1001
-
1002
- //if number of votes === null means that the caller is loopHighestRatedOverall
1003
- if ($number_of_votes === null) {
1004
-
1005
- $div_html_stars=apply_filters('yasr_filter_highest_rated_stars', $html_stars, $rating);
1006
-
1007
- if ($div_html_stars === $html_stars) {
1008
- $div_html_stars .= "<span class='yasr-highest-rated-text'>"
1009
- . __('Rating:', 'yet-another-stars-rating') . " $rating
1010
- </span>";
1011
- }
1012
-
1013
- $this->shortcode_html .= "<tr>
1014
- <td class='yasr-top-10-overall-left'>
1015
- <a href='$link'>$post_title</a>
1016
- </td>
1017
- <td class='yasr-top-10-overall-right'>
1018
- $div_html_stars
1019
- </td>
1020
- </tr>";
1021
-
1022
- }
1023
-
1024
- //otherwise is vvMostRated or vvHighestRated
1025
- else {
1026
- $this->shortcode_html .= "<tr>
1027
- <td class='yasr-top-10-most-highest-left'>
1028
- <a href='$link'>$post_title</a>
1029
- </td>
1030
- <td class='yasr-top-10-most-highest-right'>
1031
- $html_stars
1032
- <br />
1033
- ["
1034
- . __('Total:', 'yet-another-stars-rating') .
1035
- "$number_of_votes &nbsp;&nbsp;&nbsp;" .
1036
- __('Average', 'yet-another-stars-rating') .
1037
- " $rating]
1038
- </td>
1039
- </tr>";
1040
-
1041
- }
1042
- } //end function returnTableRows
1043
-
1044
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/yasr-shortcode-functions.php DELETED
@@ -1,242 +0,0 @@
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
- if(is_admin()) {
26
- return;
27
- }
28
-
29
- require YASR_ABSOLUTE_PATH . '/lib/yasr-shortcode-classes.php';
30
-
31
- /****** Add shortcode for overall rating ******/
32
- add_shortcode('yasr_overall_rating', 'shortcode_overall_rating_callback');
33
-
34
- function shortcode_overall_rating_callback ($atts) {
35
-
36
- if (YASR_SHOW_OVERALL_IN_LOOP === 'disabled' && !is_singular() && is_main_query()) {
37
- return null;
38
- }
39
-
40
- $shortcode_name = 'yasr_overall_rating';
41
- $overall_rating = new YasrOverallRating($atts, $shortcode_name);
42
-
43
- return $overall_rating->printOverallRating();
44
-
45
- } //end function
46
-
47
-
48
- /****** Add shortcode for user vote ******/
49
-
50
- add_shortcode('yasr_visitor_votes', 'shortcode_visitor_votes_callback');
51
-
52
- function shortcode_visitor_votes_callback($atts) {
53
-
54
- if (YASR_SHOW_VISITOR_VOTES_IN_LOOP === 'disabled' && !is_singular() && is_main_query()) {
55
- return null;
56
- }
57
-
58
- $shortcode_name = 'yasr_visitor_votes';
59
- $visitor_votes = new YasrVisitorVotes($atts, $shortcode_name);
60
-
61
- return $visitor_votes->printVisitorVotes();
62
-
63
- } //End function shortcode_visitor_votes_callback
64
-
65
- /****** Add shortcode for multiple set ******/
66
-
67
- add_shortcode ('yasr_multiset', 'yasr_multiset_callback');
68
-
69
- function yasr_multiset_callback($atts) {
70
- $shortcode_name = 'yasr_multiset';
71
- $multiset = new YasrMultiSet($atts, $shortcode_name);
72
-
73
- return $multiset->printMultiset();
74
- }
75
-
76
- /****** Add shortcode for multiset writable by users ******/
77
-
78
- add_shortcode ('yasr_visitor_multiset', 'yasr_visitor_multiset_callback');
79
-
80
- function yasr_visitor_multiset_callback($atts) {
81
- $shortcode_name = 'yasr_visitor_multiset';
82
- $multiset = new YasrVisitorMultiSet($atts, $shortcode_name);
83
-
84
- return $multiset->printVisitorMultiSet();
85
- }
86
-
87
-
88
- /****** Add top 10 highest rated post *****/
89
-
90
- add_shortcode ('yasr_top_ten_highest_rated', 'yasr_top_ten_highest_rated_callback');
91
-
92
- function yasr_top_ten_highest_rated_callback() {
93
- $top_ten_highest_obj = new YasrRankings(false, 'yasr_top_ten_highest_rated');
94
-
95
- return $top_ten_highest_obj->returnHighestRatedOverall();
96
- } //End function
97
-
98
-
99
- /****** Add top 10 most rated / highest rated post *****/
100
-
101
- add_shortcode ('yasr_most_or_highest_rated_posts', 'yasr_most_or_highest_rated_posts_callback');
102
-
103
- function yasr_most_or_highest_rated_posts_callback () {
104
- $most_highest_obj = new YasrRankings(false, 'yasr_most_or_highest_rated_posts');
105
-
106
- return $most_highest_obj->vvReturnMostHighestRatedPost();
107
- } //End function
108
-
109
-
110
- /****** Add top 5 most active reviewer ******/
111
-
112
- add_shortcode ('yasr_top_5_reviewers', 'yasr_top_5_reviewers_callback');
113
-
114
- /**
115
- * @return string|void
116
- */
117
- function yasr_top_5_reviewers_callback () {
118
-
119
- global $wpdb;
120
-
121
- $query_result = $wpdb->get_results("SELECT COUNT( pm.post_id ) AS total_count, p.post_author AS reviewer
122
- FROM $wpdb->posts AS p, $wpdb->postmeta AS pm
123
- WHERE pm.post_id = p.ID
124
- AND pm.meta_key = 'yasr_overall_rating'
125
- AND p.post_status = 'publish'
126
- GROUP BY reviewer
127
- ORDER BY (total_count) DESC
128
- LIMIT 5");
129
-
130
-
131
- if ($query_result) {
132
-
133
- $shortcode_html = '
134
- <!-- Yasr Top 5 Reviewers Shortcode-->
135
- ';
136
-
137
- $shortcode_html .= "
138
- <table class=\"yasr-table-chart\">
139
- <tr>
140
- <th>Author</th>
141
- <th>Reviews</th>
142
- </tr>
143
- ";
144
-
145
- foreach ($query_result as $result) {
146
-
147
- $user_data = get_userdata($result->reviewer);
148
-
149
- if ($user_data) {
150
- $user_profile = get_author_posts_url($result->reviewer);
151
- }
152
-
153
- else {
154
- $user_profile = '#';
155
- $user_data = new stdClass;
156
- $user_data->user_login = 'Anonymous';
157
- }
158
-
159
-
160
- $shortcode_html .= "<tr>
161
- <td><a href=\"$user_profile\">$user_data->user_login</a></td>
162
- <td>$result->total_count</td>
163
- </tr>";
164
-
165
- }
166
-
167
- $shortcode_html .= "</table>";
168
-
169
- $shortcode_html .= '
170
- <!-- End Yasr Top 5 Reviewers Shortcode-->
171
- ';
172
-
173
- return $shortcode_html;
174
-
175
- }
176
-
177
- else {
178
- _e("Problem while retrieving the top 5 most active reviewers. Did you publish any review?");
179
- }
180
- return;
181
- } //End top 5 reviewers function
182
-
183
-
184
- /****** Add top 10 most active user *****/
185
-
186
- add_shortcode ('yasr_top_ten_active_users', 'yasr_top_ten_active_users_callback');
187
-
188
- /**
189
- * @return string|void
190
- */
191
- function yasr_top_ten_active_users_callback () {
192
-
193
- global $wpdb;
194
-
195
- $query_result = $wpdb->get_results("SELECT COUNT( user_id ) as total_count, user_id as user
196
- FROM " . YASR_LOG_TABLE . ", $wpdb->posts AS p
197
- WHERE post_id = p.ID
198
- AND p.post_status = 'publish'
199
- GROUP BY user_id
200
- ORDER BY ( total_count ) DESC
201
- LIMIT 10");
202
-
203
- if ($query_result) {
204
- $shortcode_html = '<!-- Yasr Top 10 Active Users Shortcode-->';
205
-
206
- $shortcode_html .= "
207
- <table class=\"yasr-table-chart\">
208
- <tr>
209
- <th>UserName</th>
210
- <th>Number of votes</th>
211
- </tr>
212
- ";
213
-
214
- foreach ($query_result as $result) {
215
- $user_data = get_userdata($result->user);
216
-
217
- if ($user_data) {
218
- $user_profile = get_author_posts_url($result->user);
219
- } else {
220
- $user_profile = '#';
221
- $user_data = new stdClass;
222
- $user_data->user_login = 'Anonymous';
223
- }
224
-
225
- $shortcode_html .= "<tr>
226
- <td><a href=\"$user_profile\">$user_data->user_login</a></td>
227
- <td>$result->total_count</td>
228
- </tr>";
229
-
230
- }
231
-
232
- $shortcode_html .= "</table>";
233
- $shortcode_html .= '<!--End Yasr Top 10 Active Users Shortcode-->';
234
-
235
- return $shortcode_html;
236
- } else {
237
- _e("Problem while retrieving the top 10 active users chart. Are you sure you have votes to show?");
238
- }
239
- return;
240
- } //End function
241
-
242
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
{lib → public/classes}/YasrRichSnippetAdditionalFields.php RENAMED
@@ -1,17 +1,19 @@
1
  <?php
2
 
3
- new YasrRichSnippetAdditionalFields();
4
-
 
 
 
 
 
5
  class YasrRichSnippetAdditionalFields {
6
 
7
- public function __construct() {
8
  add_filter('yasr_filter_existing_schema', array($this, 'additional_schema'));
9
  }
10
 
11
- function additional_schema($rich_snippet) {
12
-
13
- $review_choosen = yasr_get_itemType();
14
-
15
  $saved_data = get_post_meta(get_the_ID(), 'yasr_schema_additional_fields', true);
16
  //avoid undefined
17
  if(!is_array($saved_data)) {
@@ -30,6 +32,9 @@ class YasrRichSnippetAdditionalFields {
30
  //avoid undefined
31
  $more_rich_snippet = array();
32
 
 
 
 
33
  if($review_choosen === 'Product') {
34
  $more_rich_snippet = $this->itemProduct($saved_data);
35
  }
1
  <?php
2
 
3
+ /**
4
+ * This class hook to yasr_filter_existing_schema, get the post meta
5
+ * yasr_schema_additional_fields, and depending of the itemType selected
6
+ * returns the schema info
7
+ *
8
+ * Class YasrRichSnippetAdditionalFields
9
+ */
10
  class YasrRichSnippetAdditionalFields {
11
 
12
+ public function addFilter() {
13
  add_filter('yasr_filter_existing_schema', array($this, 'additional_schema'));
14
  }
15
 
16
+ public function additional_schema($rich_snippet) {
 
 
 
17
  $saved_data = get_post_meta(get_the_ID(), 'yasr_schema_additional_fields', true);
18
  //avoid undefined
19
  if(!is_array($saved_data)) {
32
  //avoid undefined
33
  $more_rich_snippet = array();
34
 
35
+ //get the select itemTyper
36
+ $review_choosen = yasr_get_itemType();
37
+
38
  if($review_choosen === 'Product') {
39
  $more_rich_snippet = $this->itemProduct($saved_data);
40
  }
public/yasr-public-actions.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /***** Adding javascript and css *****/
25
+ add_action('wp_enqueue_scripts', 'yasr_add_scripts');
26
+ function yasr_add_scripts() {
27
+ wp_enqueue_style(
28
+ 'yasrcss',
29
+ YASR_CSS_DIR_INCLUDES . 'yasr.css',
30
+ false,
31
+ YASR_VERSION_NUM,
32
+ 'all'
33
+ );
34
+
35
+ wp_enqueue_style('dashicons'); //dashicons
36
+
37
+ //Run after default css are loaded
38
+ do_action('yasr_add_front_script_css');
39
+
40
+ $yasr_multiset_theme_handle = 'yasrcsslightscheme';
41
+ $yasr_multiset_theme = 'yasr-table-light.css';
42
+
43
+ //default css is the light one
44
+ if (YASR_SCHEME_COLOR === 'dark') {
45
+ $yasr_multiset_theme_handle = 'yasrcssdarkscheme';
46
+ $yasr_multiset_theme = 'yasr-table-dark.css';
47
+ }
48
+
49
+ wp_enqueue_style(
50
+ $yasr_multiset_theme_handle,
51
+ YASR_CSS_DIR_INCLUDES . $yasr_multiset_theme,
52
+ array('yasrcss'),
53
+ YASR_VERSION_NUM, 'all'
54
+ );
55
+
56
+ if (YASR_CUSTOM_CSS_RULES) {
57
+ wp_add_inline_style(
58
+ 'yasrcss',
59
+ YASR_CUSTOM_CSS_RULES
60
+ );
61
+ }
62
+
63
+ $rater_file_to_include = 'rater-js.js';
64
+
65
+ if (is_rtl()) {
66
+ $rater_file_to_include = 'rater-js-rtl.js';
67
+ }
68
+
69
+ wp_enqueue_script(
70
+ 'rater',
71
+ YASR_JS_DIR_INCLUDES .
72
+ $rater_file_to_include,
73
+ '',
74
+ YASR_VERSION_NUM,
75
+ true
76
+ );
77
+
78
+ wp_enqueue_script(
79
+ 'yasrfront',
80
+ YASR_JS_DIR_INCLUDES . 'yasr-front.js',
81
+ array('jquery', 'rater'),
82
+ YASR_VERSION_NUM,
83
+ true);
84
+
85
+ wp_enqueue_script(
86
+ 'tippy',
87
+ YASR_JS_DIR_INCLUDES . 'tippy.all.min.js',
88
+ '',
89
+ '3.6.0',
90
+ true
91
+ );
92
+
93
+ do_action('yasr_add_front_script_js');
94
+
95
+ $yasr_visitor_votes_loader = '<div id="loader-visitor-rating" style="display: inline">&nbsp; '.
96
+ ' <img src=' . YASR_IMG_DIR . 'loader.gif title="yasr-loader" alt="yasr-loader">
97
+ </div>';
98
+
99
+ wp_localize_script('yasrfront', 'yasrCommonData',
100
+ array(
101
+ 'restEndpoint' => esc_url_raw(rest_url()),
102
+ 'ajaxurl' => admin_url('admin-ajax.php'),
103
+ 'visitorStatsEnabled' => YASR_VISITORS_STATS,
104
+ 'loaderHtml' => $yasr_visitor_votes_loader,
105
+ 'nonce' => wp_create_nonce('wp_rest')
106
+ )
107
+ );
108
+ }
109
+
110
+ //Delete caches for supported plugins
111
+ //Can't use is_singular() here because always return false
112
+ add_action('yasr_action_on_visitor_vote', 'yasr_delete_cache');
113
+ add_action('yasr_action_on_visitor_multiset_vote', 'yasr_delete_cache');
114
+
115
+ function yasr_delete_cache($array_action_visitor_vote) {
116
+
117
+ if (isset($array_action_visitor_vote['post_id'])) {
118
+ $post_id = $array_action_visitor_vote['post_id'];
119
+ } else {
120
+ return;
121
+ }
122
+
123
+ if (isset($array_action_visitor_vote['is_singular'])) {
124
+ $is_singular = $array_action_visitor_vote['is_singular'];
125
+ } else {
126
+ return;
127
+ }
128
+
129
+ yasr_wp_super_cache_support($post_id);
130
+ yasr_wp_rocket_support($post_id);
131
+ yasr_litespeed_cache_support($post_id);
132
+ yasr_cache_enabler_support($post_id, $is_singular);
133
+ yasr_wp_fastest_cache($post_id, $is_singular);
134
+
135
+ }
public/yasr-public-filters.php ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /****** Auto insert overall rating and visitor rating ******/
25
+ add_filter('the_content', 'yasr_auto_insert_shortcode_callback');
26
+ /**
27
+ * @param $content
28
+ *
29
+ * @return bool|string|void
30
+ */
31
+ function yasr_auto_insert_shortcode_callback($content) {
32
+
33
+ if (YASR_AUTO_INSERT_ENABLED !== 1) {
34
+ return $content;
35
+ }
36
+
37
+ $post_id = get_the_ID();
38
+
39
+ //check if for this post or page auto insert is off
40
+ $post_excluded = get_post_meta($post_id, 'yasr_auto_insert_disabled', true);
41
+
42
+ if ($post_excluded === 'yes') {
43
+ return $content;
44
+ }
45
+
46
+ $shortcode_align = YASR_AUTO_INSERT_ALIGN;
47
+
48
+ //if it is not left, or right, default is center
49
+ if ($shortcode_align !== 'left' && $shortcode_align !== 'right') {
50
+ $shortcode_align = 'center';
51
+ }
52
+
53
+ $container_div_overall='<div style="text-align:'.$shortcode_align.'" class="yasr-auto-insert-overall">';
54
+ $container_div_visitor='<div style="text-align:'.$shortcode_align.'" class="yasr-auto-insert-visitor">';
55
+ $closing_div = '</div>';
56
+
57
+ $auto_insert_shortcode = null; //To avoid undefined variable notice outside the loop (if (is_singular) )
58
+ $overall_rating_code = $container_div_overall. '[yasr_overall_rating size="' . YASR_AUTO_INSERT_SIZE . '"]' . $closing_div;
59
+ $visitor_votes_code = $container_div_visitor. '[yasr_visitor_votes size="' . YASR_AUTO_INSERT_SIZE . '"]' . $closing_div;
60
+
61
+ //avoid undefined
62
+ $content_and_stars = false;
63
+
64
+ if (YASR_AUTO_INSERT_WHAT === 'overall_rating') {
65
+ switch (YASR_AUTO_INSERT_WHERE) {
66
+ case 'top':
67
+ $content_and_stars = $overall_rating_code . $content;
68
+ break;
69
+
70
+ case 'bottom':
71
+ $content_and_stars = $content . $overall_rating_code;
72
+ break;
73
+ } //End Switch
74
+ } elseif (YASR_AUTO_INSERT_WHAT === 'visitor_rating') {
75
+ switch (YASR_AUTO_INSERT_WHERE) {
76
+ case 'top':
77
+ $content_and_stars = $visitor_votes_code . $content;
78
+ break;
79
+
80
+ case 'bottom':
81
+ $content_and_stars = $content . $visitor_votes_code;
82
+ break;
83
+ } //End Switch
84
+ } elseif (YASR_AUTO_INSERT_WHAT === 'both') {
85
+ switch (YASR_AUTO_INSERT_WHERE) {
86
+ case 'top':
87
+ $content_and_stars = $overall_rating_code . $visitor_votes_code . $content;
88
+ break;
89
+
90
+ case 'bottom':
91
+ $content_and_stars = $content . $overall_rating_code . $visitor_votes_code;
92
+ break;
93
+ } //End Switch
94
+ }
95
+
96
+ //IF auto insert must work only in custom post type
97
+ if (YASR_AUTO_INSERT_CUSTOM_POST_ONLY === 'yes') {
98
+ $custom_post_types = yasr_get_custom_post_type();
99
+ //If is a post type return content and stars
100
+ if (is_singular($custom_post_types)) {
101
+ return $content_and_stars;
102
+ } //else return just content
103
+
104
+ return $content;
105
+ }
106
+
107
+ //If page are not excluded
108
+ if (YASR_AUTO_INSERT_EXCLUDE_PAGES === 'no') {
109
+ return $content_and_stars;
110
+ }
111
+
112
+ if (YASR_AUTO_INSERT_EXCLUDE_PAGES === 'yes') {
113
+ if (is_page()) {
114
+ return $content;
115
+ } //If is a page return the content without stars
116
+
117
+ return $content_and_stars;
118
+ } //else return only if it is not a page
119
+
120
+ } //End function yasr_auto_insert_shortcode_callback
121
+
122
+
123
+ /****** Add review schema data at the end of the content *******/
124
+ add_filter('the_content', 'yasr_add_schema');
125
+ function yasr_add_schema($content) {
126
+
127
+ //Add buddypress compatibility
128
+ if (function_exists('bp_is_active')) {
129
+ //If this is a page, return $content without adding schema.
130
+ //If I try to return $content after if (YASR_SNIPPET == 'overall_rating')
131
+ //or (YASR_SNIPPET == 'visitor_rating') $content will have only wp content, losing the buddypress one
132
+ if (is_page()) {
133
+ return $content;
134
+ }
135
+ }
136
+
137
+ if (is_404() || (!is_singular() && is_main_query()) || did_action('get_footer')) {
138
+ return $content;
139
+ }
140
+
141
+ $overall_rating = YasrDatabaseRatings::getOverallRating();
142
+ $visitor_votes = YasrDatabaseRatings::getVisitorVotes(false);
143
+
144
+ if (!$overall_rating && !$visitor_votes['number_of_votes'] && !$visitor_votes['sum_votes']) {
145
+ return $content;
146
+ }
147
+
148
+ //can't be between 0.1 and 1
149
+ if($overall_rating > 0 && $overall_rating < 1) {
150
+ $overall_rating = 1;
151
+ }
152
+
153
+ $is_post_a_review = get_post_meta(get_the_ID(), 'yasr_post_is_review', true);
154
+
155
+ $script_type = '<script type="application/ld+json">';
156
+ $end_script_type = '</script>';
157
+
158
+ $review_choosen = yasr_get_itemType();
159
+
160
+ //if doesn't exists a filter for yasr_filter_schema_jsonld $review_chosen value is assigned to $filtered_schema...
161
+ $filtered_schema = apply_filters('yasr_filter_schema_jsonld', $review_choosen);
162
+
163
+ //So check here if $schema != $review_choosen
164
+ if ($filtered_schema !== $review_choosen) {
165
+ return $content . $script_type . $filtered_schema . $end_script_type;
166
+ }
167
+
168
+ $rich_snippet['@context'] = 'http://schema.org/';
169
+
170
+ $author = get_the_author();
171
+ $review_name = wp_strip_all_tags(get_the_title());
172
+
173
+ $date = get_the_date('c');
174
+ $date_modified = get_the_modified_date('c');
175
+
176
+ $post_image_url = ''; //avoid undefined
177
+ $logo_image_url = ''; //avoid undefined
178
+
179
+ if (defined('YASR_BLOGPOSTING_ORGANIZATION_LOGO')) {
180
+ $logo_image_url = YASR_BLOGPOSTING_ORGANIZATION_LOGO;
181
+ $post_image_url = $logo_image_url; //this will be overwritten if has_post_thumbnail is true
182
+
183
+ $logo_image_url_absolute = $_SERVER['DOCUMENT_ROOT'] . parse_url(YASR_BLOGPOSTING_ORGANIZATION_LOGO, PHP_URL_PATH);
184
+
185
+ $post_image_size = @getimagesize($logo_image_url_absolute); //the @ should be useless, just to be safe
186
+ $logo_image_size = @getimagesize($logo_image_url_absolute); //the @ should be useless, just to be safe
187
+ } else {
188
+ $post_image_size[0] = 0;
189
+ $post_image_size[1] = 0;
190
+ $logo_image_size[0] = 0;
191
+ $logo_image_size[1] = 0;
192
+ }
193
+
194
+ //if exists featuread image get the url and overwrite the variable
195
+ if (has_post_thumbnail()) {
196
+ $post_image_url = wp_get_attachment_url(get_post_thumbnail_id());
197
+ $post_image_url_absolute = $_SERVER['DOCUMENT_ROOT'] . parse_url($post_image_url, PHP_URL_PATH);
198
+ $post_image_size = @getimagesize($post_image_url_absolute); //the @ should be useless, just to be safe
199
+ }
200
+
201
+ $rich_snippet['@type'] = $review_choosen;
202
+
203
+ if ($review_choosen === 'Place') {
204
+ $rich_snippet['@type'] = 'LocalBusiness';
205
+ }
206
+
207
+ elseif ($review_choosen === 'Other' || $review_choosen === 'BlogPosting') {
208
+ $rich_snippet['@type'] = 'BlogPosting';
209
+ $rich_snippet['datePublished'] = $date;
210
+ $rich_snippet['headline'] = $review_name;
211
+ $rich_snippet['mainEntityOfPage'] = array(
212
+ '@type' => 'WebPage',
213
+ '@id' => get_permalink()
214
+ );
215
+ $rich_snippet['author'] = array(
216
+ '@type' => 'Person',
217
+ 'name' => (string) $author
218
+ );
219
+ $rich_snippet['publisher'] = array(
220
+ '@type' => 'Organization',
221
+ 'name' => wp_strip_all_tags(YASR_BLOGPOSTING_ORGANIZATION_NAME), //already sanitized in the settings, just to be safe
222
+ 'logo' => array(
223
+ '@type' => 'ImageObject',
224
+ 'url' => $logo_image_url,
225
+ 'width' => $logo_image_size[0],
226
+ 'height' => $logo_image_size[1]
227
+ ),
228
+ );
229
+
230
+ $rich_snippet['dateModified'] = $date_modified;
231
+
232
+ $rich_snippet['image'] = array(
233
+ '@type' => 'ImageObject',
234
+ 'url' => $post_image_url,
235
+ 'width' => $post_image_size[0],
236
+ 'height' => $post_image_size[1]
237
+ );
238
+
239
+ }
240
+
241
+ $rich_snippet['name'] = $review_name;
242
+ $rich_snippet['description'] = $review_name;
243
+ $rich_snippet['image'] = array(
244
+ '@type' => 'ImageObject',
245
+ 'url' => $post_image_url,
246
+ 'width' => $post_image_size[0],
247
+ 'height' => $post_image_size[1]
248
+ );
249
+
250
+ //Do not add rating if blogposting
251
+ if ($review_choosen !== 'Other' && $review_choosen !== 'BlogPosting') {
252
+ if ($overall_rating) {
253
+ $rich_snippet['Review'] = array(
254
+ '@type' => 'Review',
255
+ 'name' => $review_name,
256
+ 'author' => array(
257
+ '@type' => 'Person',
258
+ 'name' => $author
259
+ ),
260
+ 'datePublished' => $date,
261
+ 'dateModified' => $date_modified,
262
+ 'reviewRating' => array(
263
+ '@type' => 'Rating',
264
+ 'ratingValue' => $overall_rating,
265
+ 'bestRating' => 5,
266
+ 'worstRating' => 1
267
+ ),
268
+ );
269
+ }
270
+
271
+ //if both are included, google will index AggregateRating instead of Review.
272
+ //So, is post is selected as review, exclude AggregateRating
273
+ if($is_post_a_review !== 'yes') {
274
+ if ($visitor_votes) {
275
+ if ($visitor_votes['sum_votes'] !== 0 && $visitor_votes['number_of_votes'] !== 0) {
276
+ $average_rating = $visitor_votes['sum_votes'] / $visitor_votes['number_of_votes'];
277
+ $average_rating = round($average_rating, 1);
278
+
279
+ $rich_snippet['aggregateRating'] = array(
280
+ '@type' => 'AggregateRating',
281
+ 'ratingValue' => $average_rating,
282
+ 'ratingCount' => $visitor_votes['number_of_votes'],
283
+ 'bestRating' => 5,
284
+ 'worstRating' => 1
285
+ );
286
+ }
287
+ }
288
+ }
289
+
290
+ }
291
+
292
+ //if doesn't exists a filter for yasr_filter_existing_schema, put $rich_snippet into $more_rich_snippet
293
+ $more_rich_snippet = apply_filters('yasr_filter_existing_schema', $rich_snippet);
294
+
295
+ if ($more_rich_snippet !== $rich_snippet && is_array($more_rich_snippet)) {
296
+ $rich_snippet = $more_rich_snippet;
297
+ }
298
+
299
+ if (is_singular() && is_main_query() && !is_404()) {
300
+ return $content . $script_type . json_encode($rich_snippet) . $end_script_type;
301
+ }
302
+
303
+ return $content;
304
+
305
+ } //End function
public/yasr-public-functions.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /*** Add support for wp super cache ***/
26
+ function yasr_wp_super_cache_support($post_id) {
27
+ if (function_exists('wp_cache_post_change')) {
28
+ wp_cache_post_change($post_id);
29
+ }
30
+ }
31
+
32
+ /*** Add support for wp rocket, thanks to GeekPress
33
+ * https://wordpress.org/support/topic/compatibility-with-wp-rocket-2
34
+ ***/
35
+ function yasr_wp_rocket_support($post_id) {
36
+ if (function_exists('rocket_clean_post')) {
37
+ rocket_clean_post($post_id);
38
+ }
39
+ }
40
+
41
+ /*** Add support for LiteSpeed Cache plugin, thanks to Pako69
42
+ * https://wordpress.org/support/topic/yasr-is-litespeed-cache-plugin-compatible/
43
+ ***/
44
+ function yasr_litespeed_cache_support($post_id) {
45
+ if (method_exists('LiteSpeed_Cache_API', 'purge_post') == true) {
46
+ LiteSpeed_Cache_API::purge_post($post_id);
47
+ }
48
+ }
49
+
50
+ /*** Add support for cache enabler ***/
51
+ function yasr_cache_enabler_support($post_id, $is_singular) {
52
+ if (has_action('ce_clear_cache') || has_action('ce_clear_post_cache')) {
53
+ //IF is in the single post or page delete only that cache
54
+ if ($is_singular === 'true') {
55
+ do_action('ce_clear_post_cache', $post_id);
56
+ } //otherwise, delete everything
57
+ else {
58
+ do_action('ce_clear_cache');
59
+ }
60
+ }
61
+ }
62
+
63
+
64
+ /**** Add support for Wp Fastest Cache ****/
65
+ function yasr_wp_fastest_cache($post_id, $is_singular) {
66
+ if ($is_singular === 'true') {
67
+ if (isset($GLOBALS['wp_fastest_cache']) && method_exists($GLOBALS['wp_fastest_cache'], 'singleDeleteCache')) {
68
+ $GLOBALS['wp_fastest_cache']->singleDeleteCache(false, $post_id);
69
+ }
70
+ } else {
71
+ if (isset($GLOBALS['wp_fastest_cache']) && method_exists($GLOBALS['wp_fastest_cache'], 'deleteCache')) {
72
+ $GLOBALS['wp_fastest_cache']->deleteCache();
73
+ }
74
+ }
75
+ }
public/yasr-public-init.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ //e.g. http://localhost/plugin_development/wp-content/plugins/yet-another-stars-rating/includes/js/
25
+ define('YASR_JS_DIR_PUBLIC', plugins_url() . '/' . YASR_RELATIVE_PATH_PUBLIC . '/js/');
26
+ //CSS directory absolute URL
27
+ define('YASR_CSS_DIR_PUBLIC', plugins_url() . '/' . YASR_RELATIVE_PATH_PUBLIC . '/css/');
28
+
29
+ require YASR_ABSOLUTE_PATH_PUBLIC . '/yasr-public-functions.php';
30
+ require YASR_ABSOLUTE_PATH_PUBLIC . '/yasr-public-actions.php';
31
+ require YASR_ABSOLUTE_PATH_PUBLIC . '/yasr-public-filters.php';
32
+
33
+ /**
34
+ * Callback function for the spl_autoload_register above.
35
+ *
36
+ * @param $class
37
+ */
38
+ function yasr_autoload_public_classes($class) {
39
+ /**
40
+ * If the class being requested does not start with 'Yasr' prefix,
41
+ * it's not in Yasr Project
42
+ */
43
+ if (0 !== strpos($class, 'Yasr')) {
44
+ return;
45
+ }
46
+ $file_name = YASR_ABSOLUTE_PATH_PUBLIC . '/classes/' . $class . '.php';
47
+
48
+ // check if file exists, just to be sure
49
+ if (file_exists($file_name)) {
50
+ require($file_name);
51
+ }
52
+ }
53
+
54
+ //AutoLoad Yasr Shortcode Classes, only when a object is created
55
+ spl_autoload_register('yasr_autoload_public_classes');
56
+
57
+ //filter yasr rich snippet
58
+ $yasr_additional_rich_fields = new YasrRichSnippetAdditionalFields;
59
+ $yasr_additional_rich_fields->addFilter();
readme.txt CHANGED
@@ -3,9 +3,9 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
3
  Tags: rating, rate post, rate page, star rating, google rating, votes
4
  Requires at least: 4.9.0
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
@@ -130,6 +130,9 @@ If doesn't, it's suggested to ask in a SEO oriented forum.
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.
3
  Tags: rating, rate post, rate page, star rating, google rating, votes
4
  Requires at least: 4.9.0
5
  Contributors: Dudo
6
+ Tested up to: 5.5
7
  Requires PHP: 5.3
8
+ Stable tag: 2.3.1
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
130
 
131
  The full changelog can be found in the plugin's directory. Recent entries:
132
 
133
+ = 2.3.1 =
134
+ * Code refactor, according to boilerplate standards
135
+
136
  = 2.3.0 =
137
  * NEW FEATURE: YASR now support all caching plugin available out there.
138
  Just select "yes" at the question "Load results with AJAX" in the settings page.
yet-another-stars-rating.php CHANGED
@@ -5,11 +5,11 @@
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
12
- * Domain Path: languages
13
  * License: GPL2
14
  *
15
  *
@@ -77,196 +77,42 @@ 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.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 ;
155
-
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
185
- $multi_set_options = get_option( 'yasr_multiset_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() ) {
207
- require YASR_ABSOLUTE_PATH . '/lib/admin/yasr-admin-classes.php';
208
- require YASR_ABSOLUTE_PATH . '/lib/admin/yasr-admin-actions.php';
209
- require YASR_ABSOLUTE_PATH . '/lib/admin/editor/YasrOnSavePost.php';
210
- require YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions.php';
211
- require YASR_ABSOLUTE_PATH . '/lib/admin/class-wp-list-table.php';
212
- require YASR_ABSOLUTE_PATH . '/lib/admin/editor/yasr-editor-functions.php';
213
- require YASR_ABSOLUTE_PATH . '/lib/admin/yasr-update-functions.php';
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(
228
- 'BlogPosting',
229
- 'Book',
230
- 'Course',
231
- 'CreativeWorkSeason',
232
- 'CreativeWorkSeries',
233
- 'Episode',
234
- 'Event',
235
- 'Game',
236
- 'LocalBusiness',
237
- 'MediaObject',
238
- 'Movie',
239
- 'MusicPlaylist',
240
- 'MusicRecording',
241
- 'Product',
242
- 'Recipe'
243
- ) );
244
- $array_item_type_info = json_encode( array(
245
- 'yasr_product_brand',
246
- 'yasr_product_sku',
247
- 'yasr_product_global_identifier_select',
248
- 'yasr_product_global_identifier_value',
249
- 'yasr_product_price',
250
- 'yasr_product_price_currency',
251
- 'yasr_product_price_valid_until',
252
- 'yasr_product_price_availability',
253
- 'yasr_product_price_url',
254
- 'yasr_localbusiness_address',
255
- 'yasr_localbusiness_pricerange',
256
- 'yasr_localbusiness_telephone',
257
- 'yasr_recipe_cooktime',
258
- 'yasr_recipe_description',
259
- 'yasr_recipe_keywords',
260
- 'yasr_recipe_nutrition',
261
- 'yasr_recipe_preptime',
262
- 'yasr_recipe_recipecategory',
263
- 'yasr_recipe_recipecuisine',
264
- 'yasr_recipe_recipeingredient',
265
- 'yasr_recipe_recipeinstructions',
266
- 'yasr_recipe_video'
267
- ) );
268
- define( 'YASR_SUPPORTED_SCHEMA_TYPES', $supported_schema_types );
269
- define( 'YASR_SUPPORTED_SCHEMA_TYPES_ADDITIONAL_FIELDS', $array_item_type_info );
270
  //role to save overall_rating and multi set
271
  define( 'YASR_USER_CAPABILITY_EDIT_POST', 'edit_posts' );
272
  $yasr_version_installed = get_option( 'yasr-version' );
@@ -280,7 +126,7 @@ if ( !function_exists( 'yasr_fs' ) ) {
280
  global $yasr_version_installed ;
281
  //If this is a fresh new installation
282
  if ( !$yasr_version_installed ) {
283
- yasr_on_activation_install( $network_wide );
284
  }
285
  }
286
 
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.1
9
  * Author: Dario Curvino
10
  * Author URI: https://dariocurvino.it/
11
  * Text Domain: yet-another-stars-rating
12
+ * Domain Path: /languages
13
  * License: GPL2
14
  *
15
  *
77
  yasr_fs();
78
  // Signal that SDK was initiated.
79
  do_action( 'yasr_fs_loaded' );
80
+ define( 'YASR_VERSION_NUM', '2.3.1' );
81
+ //Plugin absolute path
82
+ //e.g. /var/www/html/plugin_development/wp-content/plugins/yet-another-stars-rating
83
  define( 'YASR_ABSOLUTE_PATH', __DIR__ );
84
  //Plugin RELATIVE PATH without slashes (just the directory's name)
85
+ //Do not use just 'yet-another-stars-rating' here, because the directory name
86
+ //can be different, e.g. yet-another-stars-rating-premium or
87
+ //yasr-2.3.1 (branch name)
88
  define( 'YASR_RELATIVE_PATH', dirname( plugin_basename( __FILE__ ) ) );
89
+ //admin absolute path
90
+ define( 'YASR_ABSOLUTE_PATH_ADMIN', YASR_ABSOLUTE_PATH . '/admin' );
91
+ //includes absolute path
92
+ define( 'YASR_ABSOLUTE_PATH_INCLUDES', YASR_ABSOLUTE_PATH . '/includes' );
93
+ //public absolute path
94
+ define( 'YASR_ABSOLUTE_PATH_PUBLIC', YASR_ABSOLUTE_PATH . '/public' );
95
+ //admin relative path
96
+ define( 'YASR_RELATIVE_PATH_ADMIN', YASR_RELATIVE_PATH . '/admin' );
97
+ //includes relative path
98
+ define( 'YASR_RELATIVE_PATH_INCLUDES', YASR_RELATIVE_PATH . '/includes' );
99
+ //public relative path
100
+ define( 'YASR_RELATIVE_PATH_PUBLIC', YASR_RELATIVE_PATH . '/public' );
101
+ //IMG directory absolute URL
102
+ define( 'YASR_IMG_DIR', plugins_url() . '/' . YASR_RELATIVE_PATH_INCLUDES . '/img/' );
103
  //Plugin language directory: here I've to use relative path
104
  //because load_plugin_textdomain wants relative and not absolute path
105
  define( 'YASR_LANG_DIR', YASR_RELATIVE_PATH . '/languages/' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  // Include function file both sides
107
+ require YASR_ABSOLUTE_PATH_INCLUDES . '/yasr-includes-init.php';
108
+ //only admin files
 
 
 
 
 
 
109
 
110
  if ( is_admin() ) {
111
+ require YASR_ABSOLUTE_PATH_ADMIN . '/yasr-admin-init.php';
112
+ } else {
113
+ require YASR_ABSOLUTE_PATH_PUBLIC . '/yasr-public-init.php';
 
 
 
 
114
  }
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  //role to save overall_rating and multi set
117
  define( 'YASR_USER_CAPABILITY_EDIT_POST', 'edit_posts' );
118
  $yasr_version_installed = get_option( 'yasr-version' );
126
  global $yasr_version_installed ;
127
  //If this is a fresh new installation
128
  if ( !$yasr_version_installed ) {
129
+ new YasrOnInstall( $network_wide );
130
  }
131
  }
132