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'))