Yasr – Yet Another Stars Rating - Version 2.0.0

Version Description

  • NEW FEATURE: is now possible to import date from:
  • Wp Post Ratings
  • KK Star Ratings
  • Rate My Post
  • FIXED: in editor screen, multi set didn't shows up if more than 1 was used
  • TWEAKED: minor changes
Download this release

Release Info

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

Code changes from version 1.9.9 to 2.0.0

changelog.txt CHANGED
@@ -1,3 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  = 1.9.0 =
2
  * NEW FEATURE: yasr_visitor_votes is now a Gutenberg block
3
  * FIXED: In Gutenberg, when using yasr_overall_rating block, if post is rated and size or post_id is changed, stars got full filled
@@ -7,10 +21,6 @@
7
  * TWEAKED: added a div with class "yasr-overall-rating" in the front end shortcode to allow customization
8
  * TWEAKED: dropped out support for extensions
9
  * TWEAKED: minor changes
10
- [//]: # fs_premium_only_begin
11
- * TWEAKED: if enabled, use curl instead of file_get_contents
12
- * FIXED: missing text in the image upload sections
13
- [//]: # fs_premium_only_end
14
 
15
  = 1.8.9 =
16
  * FIXED: updated freemius sdk to version 2.2.4
@@ -40,10 +50,6 @@
40
 
41
  = 1.8.3 =
42
  * FIXED: multiset doesn't show up in the edit screen if only 1 is used
43
- [//]: # fs_premium_only_begin
44
- * FIXED: Missing stars in Yasr Custom Rankings
45
- * TWEAKED: oxygen icon
46
- [//]: # fs_premium_only_end
47
 
48
  = 1.8.2 =
49
  * FIXED: widgets didn't load in front end
@@ -54,11 +60,6 @@
54
  = 1.8.0 =
55
  * This is a very important release. A lot of code has been cleaned up/rewritten. Images are not png anymore, but svg.
56
  Everthing is now fresher and even more lightweight then before. If you customized your stars set, check it again in the settings.
57
- [//]: # fs_premium_only_begin
58
- * FIXED: string when the rating of a review is updated
59
- * FIXED: Javascript error when the current user has not left a review for a post or page
60
- * FIXED: undefined constant
61
- [//]: # fs_premium_only_end
62
 
63
  = 1.7.4 =
64
  * Css fixes
@@ -68,10 +69,6 @@ Everthing is now fresher and even more lightweight then before. If you customize
68
  * TWEAKED: progress bars doesn't use jquery anymore, it's css only
69
  * TWEAKED: tooltip for yasr_visitor_votes doesn't use jquery anymore, but uses [tippy](https://atomiks.github.io/tippyjs/) instead
70
  * TWEAKED: A lot of under the hood changes
71
- [//]: # fs_premium_only_begin
72
- * FIXED: Cookie check wasn't working
73
- * TWEAKED: Review in comments now can work without Jquery
74
- [//]: # fs_premium_only_end
75
 
76
  = 1.7.2 =
77
  * FIXED: yasr_visitor_multiset didn't work
1
+ = 1.9.4 =
2
+ * NEW: In the settings, is now possible to customize the "you must sign in" text; two html tags are supported: < strong > and < p >
3
+ * FIXED: Update transient to show the new average when a rating get deleted from the panel
4
+ * TWEAKED: Code cleanup
5
+
6
+ = 1.9.3 =
7
+ * Minor changes and code cleanup.
8
+
9
+ = 1.9.2 =
10
+ * FIXED: Javascript error on some mobile device
11
+
12
+ = 1.9.1 =
13
+ * FIXED: In some (rare) case, overall rating get empty with Gutenberg
14
+
15
  = 1.9.0 =
16
  * NEW FEATURE: yasr_visitor_votes is now a Gutenberg block
17
  * FIXED: In Gutenberg, when using yasr_overall_rating block, if post is rated and size or post_id is changed, stars got full filled
21
  * TWEAKED: added a div with class "yasr-overall-rating" in the front end shortcode to allow customization
22
  * TWEAKED: dropped out support for extensions
23
  * TWEAKED: minor changes
 
 
 
 
24
 
25
  = 1.8.9 =
26
  * FIXED: updated freemius sdk to version 2.2.4
50
 
51
  = 1.8.3 =
52
  * FIXED: multiset doesn't show up in the edit screen if only 1 is used
 
 
 
 
53
 
54
  = 1.8.2 =
55
  * FIXED: widgets didn't load in front end
60
  = 1.8.0 =
61
  * This is a very important release. A lot of code has been cleaned up/rewritten. Images are not png anymore, but svg.
62
  Everthing is now fresher and even more lightweight then before. If you customized your stars set, check it again in the settings.
 
 
 
 
 
63
 
64
  = 1.7.4 =
65
  * Css fixes
69
  * TWEAKED: progress bars doesn't use jquery anymore, it's css only
70
  * TWEAKED: tooltip for yasr_visitor_votes doesn't use jquery anymore, but uses [tippy](https://atomiks.github.io/tippyjs/) instead
71
  * TWEAKED: A lot of under the hood changes
 
 
 
 
72
 
73
  = 1.7.2 =
74
  * FIXED: yasr_visitor_multiset didn't work
css/yasr-admin.css CHANGED
@@ -580,6 +580,28 @@
580
 
581
  /**** End Yasr Aspect & Styles tab ***/
582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
583
 
584
  /*** Popup in tinymce ***/
585
 
580
 
581
  /**** End Yasr Aspect & Styles tab ***/
582
 
583
+ /**** Migration Tools Page ****/
584
+
585
+ .title-plugin-found{
586
+ font-size: 18px;
587
+ font-weight: bold;
588
+ color: #2ca02c;
589
+ }
590
+
591
+ .yasr-alert-box {
592
+ margin-top: 15px;
593
+ margin-bottom: 15px;
594
+ margin-left: 10px;
595
+ padding: 10px;
596
+ padding-left: 30px;
597
+ border: #ff806e 2px dashed;
598
+ width: 70%;
599
+ }
600
+
601
+ /**** End Migration Tools Page ****/
602
+
603
+
604
+
605
 
606
  /*** Popup in tinymce ***/
607
 
js/src/yasr-guten-panel.js CHANGED
@@ -132,4 +132,4 @@ registerPlugin( 'yasr-sidebar', {
132
  icon: 'star-half',
133
  title: __( 'Yasr: Page Settings', 'yet-another-stars-rating' ),
134
  render: yasrSidebar
135
- } );
132
  icon: 'star-half',
133
  title: __( 'Yasr: Page Settings', 'yet-another-stars-rating' ),
134
  render: yasrSidebar
135
+ } );
js/yasr-admin.js CHANGED
@@ -81,6 +81,8 @@ function yasrAdminMultiSet(nMultiSet, postid, setId, nonceMulti) {
81
 
82
  yasrPrintAdminMultiSet(setId, postid, nonceMulti);
83
 
 
 
84
  });
85
 
86
  }
@@ -330,7 +332,7 @@ function YasrSettingsPage(activeTab, nMultiSet, autoInsertEnabled, textBeforeSta
330
  return false;
331
  }
332
 
333
- var newTextBoxDiv = jQuery(document.createElement('tr'))
334
 
335
  newTextBoxDiv.html('<td colspan="2">Element #' + counter + ' <input type="text" name="edit-multi-set-element-' + counter + '" value="" ></td>');
336
 
@@ -406,43 +408,71 @@ function YasrSettingsPage(activeTab, nMultiSet, autoInsertEnabled, textBeforeSta
406
 
407
  }
408
 
409
- function YasrAsk5Stars(nonceHideAskRating) {
410
 
411
- //This will call an ajax action that set a site transite to hide
412
- //for a week the metabok
413
- jQuery('#yasr-ask-five-star-later').on("click", function () {
414
 
415
- jQuery('#yasr-ask-five-stars').hide();
416
 
417
- var data = {
418
- action: 'yasr_hide_ask_rating_metabox',
419
- choose: 'hide',
420
- nonce: nonceHideAskRating
421
 
 
 
 
 
 
422
  };
423
 
424
- jQuery.post(ajaxurl, data);
 
 
 
425
 
426
  });
427
 
 
428
 
429
- //This will close the ask rating metabox forever
430
- jQuery('#yasr-ask-five-close').on("click", function () {
 
431
 
432
- jQuery('#yasr-ask-five-stars').hide();
433
 
434
  var data = {
435
- action: 'yasr_hide_ask_rating_metabox',
436
- choose: 'close',
437
- nonce: nonceHideAskRating
438
  };
439
 
440
- jQuery.post(ajaxurl, data);
 
 
 
441
 
442
  });
443
 
 
444
 
445
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
 
447
  /****** End Yasr Settings Page ******/
448
 
81
 
82
  yasrPrintAdminMultiSet(setId, postid, nonceMulti);
83
 
84
+ return false; // prevent default click action from happening!
85
+
86
  });
87
 
88
  }
332
  return false;
333
  }
334
 
335
+ var newTextBoxDiv = jQuery(document.createElement('tr'));
336
 
337
  newTextBoxDiv.html('<td colspan="2">Element #' + counter + ' <input type="text" name="edit-multi-set-element-' + counter + '" value="" ></td>');
338
 
408
 
409
  }
410
 
 
411
 
412
+ /****** Migration tools page ******/
413
+ document.addEventListener('DOMContentLoaded', function(event) {
 
414
 
415
+ jQuery('#yasr-import-ratemypost-submit').on('click', function() {
416
 
417
+ //show loader on click
418
+ document.getElementById('yasr-import-ratemypost-answer').innerHTML = '<img src="'
419
+ +yasrCommonDataAdmin.loaderHtml+'"</img>';
 
420
 
421
+ var nonce = document.getElementById('yasr-import-rmp-nonce').value;
422
+
423
+ var data = {
424
+ action: 'yasr_import_ratemypost',
425
+ nonce: nonce
426
  };
427
 
428
+ jQuery.post(ajaxurl, data, function (response) {
429
+ response = JSON.parse(response);
430
+ document.getElementById('yasr-import-ratemypost-answer').innerHTML = response;
431
+ });
432
 
433
  });
434
 
435
+ jQuery('#yasr-import-wppr-submit').on('click', function() {
436
 
437
+ //show loader on click
438
+ document.getElementById('yasr-import-wppr-answer').innerHTML = '<img src="'
439
+ +yasrCommonDataAdmin.loaderHtml+'"</img>';
440
 
441
+ var nonce = document.getElementById('yasr-import-wppr-nonce').value;
442
 
443
  var data = {
444
+ action: 'yasr_import_wppr',
445
+ nonce: nonce
 
446
  };
447
 
448
+ jQuery.post(ajaxurl, data, function (response) {
449
+ //response = JSON.parse(response);
450
+ document.getElementById('yasr-import-wppr-answer').innerHTML = response;
451
+ });
452
 
453
  });
454
 
455
+ jQuery('#yasr-import-kksr-submit').on('click', function() {
456
 
457
+ //show loader on click
458
+ document.getElementById('yasr-import-kksr-answer').innerHTML = '<img src="'
459
+ +yasrCommonDataAdmin.loaderHtml+'"</img>';
460
+
461
+ var nonce = document.getElementById('yasr-import-kksr-nonce').value;
462
+
463
+ var data = {
464
+ action: 'yasr_import_kksr',
465
+ nonce: nonce
466
+ };
467
+
468
+ jQuery.post(ajaxurl, data, function (response) {
469
+ //response = JSON.parse(response);
470
+ document.getElementById('yasr-import-kksr-answer').innerHTML = response;
471
+ });
472
+
473
+ });
474
+
475
+ });
476
 
477
  /****** End Yasr Settings Page ******/
478
 
lib/admin/settings/yasr-settings-functions-misc.php CHANGED
@@ -1,41 +1,123 @@
1
  <?php
2
 
3
- function yasr_upgrade_pro_box($position = false) {
 
 
 
4
 
5
- if (yasr_fs()->is_free_plan()) {
6
 
7
- if ($position && $position == "bottom") {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  $yasr_upgrade_class = "yasr-donatedivbottom";
9
  } else {
10
  $yasr_upgrade_class = "yasr-donatedivdx";
11
  }
12
-
13
  ?>
14
 
15
- <div class="<?php echo $yasr_upgrade_class ?>" style="display: none">
 
 
16
 
17
  <h2 class="yasr-donate-title" style="color: #34A7C1">
18
- <?php _e('Upgrade to YASR Pro', 'yet-another-stars-rating'); ?>
 
 
19
  </h2>
20
 
21
  <div class="yasr-upgrade-to-pro">
22
  <ul>
23
- <li><strong><?php _e(' User Reviews', 'yet-another-stars-rating'); ?></strong></li>
24
- <li><strong><?php _e(' Custom Rankings', 'yet-another-stars-rating'); ?></strong></li>
25
- <li><strong><?php _e(' 20 + ready to use themes', 'yet-another-stars-rating'); ?></strong></li>
26
- <li><strong><?php _e(' Upload your own theme', 'yet-another-stars-rating'); ?></strong></li>
27
- <li><strong><?php _e(' Dedicate support', 'yet-another-stars-rating'); ?></strong></li>
28
- <li><strong><?php _e(' ...And much more!!', 'yet-another-stars-rating'); ?></strong></li>
 
 
 
 
 
 
 
 
 
 
 
 
29
  </ul>
30
- <a href="<?php echo yasr_fs()->get_upgrade_url(); ?>">
 
 
31
  <button class="button button-primary">Upgrade Now</button>
32
  </a>
33
  </div>
34
 
35
  </div>
36
 
37
- <?php
38
-
39
  }
40
 
41
  }
@@ -45,41 +127,32 @@ function yasr_upgrade_pro_box($position = false) {
45
  * Since version 1.9.5
46
  *
47
  */
48
-
49
- function yasr_resources_box($position = false) {
50
-
51
- if ($position && $position == "bottom") {
52
  $yasr_metabox_class = "yasr-donatedivbottom";
53
- } else {
54
  $yasr_metabox_class = "yasr-donatedivdx";
55
  }
56
-
57
- $div = "<div class='$yasr_metabox_class' id='yasr-resources-box' style='display:none;'>";
58
-
59
  $text = '<div class="yasr-donate-title">Resources</div>';
60
  $text .= '<div class="yasr-donate-single-resource">
61
  <span class="dashicons dashicons-star-filled" style="color: #ccc"></span>
62
- <a target="blank" href="http://yetanotherstarsrating.com/">'
63
- . __('YASR official website', 'yet-another-stars-rating') .
64
- '</a>
65
  </div>';
66
  $text .= '<div class="yasr-donate-single-resource">
67
  <span class="dashicons dashicons-edit" style="color: #ccc"></span>
68
- <a target="blank" href="https://yetanotherstarsrating.com/yasr-basics-shortcode/">'
69
- . __('Documentation', 'yet-another-stars-rating') .
70
- '</a>
71
  </div>';
72
  $text .= '<div class="yasr-donate-single-resource">
73
  <span class="dashicons dashicons-book-alt" style="color: #ccc"></span>
74
- <a target="blank" href="https://yetanotherstarsrating.com/f-a-q/">'
75
- . __('F.A.Q.', 'yet-another-stars-rating') .
76
- '</a>
77
  </div>';
78
  $text .= '<div class="yasr-donate-single-resource">
79
  <span class="dashicons dashicons-video-alt3" style="color: #ccc"></span>
80
- <a target="blank" href="https://www.youtube.com/channel/UCU5jbO1PJsUUsCNbME9S-Zw">'
81
- . __('Youtube channel', 'yet-another-stars-rating') .
82
- '</a>
83
  </div>';
84
  $text .= '<div class="yasr-donate-single-resource">
85
  <span class="dashicons dashicons-smiley" style="color: #ccc"></span>
@@ -87,29 +160,24 @@ function yasr_resources_box($position = false) {
87
  Yasr Pro
88
  </a>
89
  </div>';
90
-
91
-
92
  $div_and_text = $div . $text . '</div>';
93
-
94
- echo $div_and_text;
95
-
96
  }
97
 
98
  /** Add a box on the right for asking to rate 5 stars on Wordpress.org
99
  * Since version 0.9.0
100
  */
101
-
102
- function yasr_ask_rating($position = false) {
103
-
104
- if ($position && $position == "bottom") {
105
  $yasr_metabox_class = "yasr-donatedivbottom";
106
- } else {
107
  $yasr_metabox_class = "yasr-donatedivdx";
108
  }
109
-
110
- $div = "<div class='$yasr_metabox_class' id='yasr-ask-five-stars' style='display:none;'>";
111
-
112
- $text = '<div class="yasr-donate-title">' . __('Can I ask your help?', 'yet-another-stars-rating') .'</div>';
113
  $text .= '<div style="font-size: 32px; color: #F1CB32; text-align:center; margin-bottom: 20px; margin-top: -5px;">
114
  <span class="dashicons dashicons-star-filled" style="font-size: 26px;"></span>
115
  <span class="dashicons dashicons-star-filled" style="font-size: 26px;"></span>
@@ -117,67 +185,55 @@ function yasr_ask_rating($position = false) {
117
  <span class="dashicons dashicons-star-filled" style="font-size: 26px;"></span>
118
  <span class="dashicons dashicons-star-filled" style="font-size: 26px;"></span>
119
  </div>';
120
- $text .= __('Please rate YASR 5 stars on', 'yet-another-stars-rating');
121
  $text .= ' <a href="https://wordpress.org/support/view/plugin-reviews/yet-another-stars-rating?filter=5">
122
  WordPress.org.</a><br />';
123
- $text .= __(' It will require just 1 min but it\'s a HUGE help for me. Thank you.', 'yet-another-stars-rating');
124
  $text .= "<br /><br />";
125
  $text .= "<em>> Dario Curvino</em>";
126
-
127
  $div_and_text = $div . $text . '</div>';
128
-
129
- echo $div_and_text;
130
-
131
  }
132
 
133
-
134
  /****
135
  Yasr Right settings panel, since version 1.9.5
136
  ****/
137
-
138
- function yasr_right_settings_panel($position = false) {
139
- do_action('yasr_right_settings_panel_box', $position);
140
- yasr_upgrade_pro_box($position);
141
- yasr_resources_box($position);
142
- yasr_ask_rating($position);
143
  }
144
 
145
-
146
  /** Change default admin footer on yasr settings pages
147
  * $text is the default wordpress text
148
  * Since 0.8.9
149
  */
150
-
151
- add_filter('admin_footer_text', 'yasr_custom_admin_footer');
152
-
153
- function yasr_custom_admin_footer($text) {
154
-
155
- if (isset($_GET['page'])) {
156
  $yasr_page = $_GET['page'];
157
-
158
- if ($yasr_page == 'yasr_settings_page') {
159
  $custom_text = ' | <i>';
160
  $custom_text .= sprintf(
161
- __('Thank you for using <a href="%s" target="_blank">Yet Another Stars Rating</a>.
162
- Please <a href="%s" target="_blank">rate it</a> 5 stars on <a href="%s" target="_blank">WordPress.org</a>',
163
- 'yet-another-stars-rating'
164
- ),
165
  'https://yetanotherstarsrating.com',
166
  'https://wordpress.org/support/view/plugin-reviews/yet-another-stars-rating?filter=5',
167
  'https://wordpress.org/support/view/plugin-reviews/yet-another-stars-rating?filter=5'
168
  );
169
  $custom_text .= '</i>';
170
-
171
  return $text . $custom_text;
172
-
173
  } else {
174
  return $text;
175
  }
176
-
177
  } else {
178
  return $text;
179
  }
180
 
181
  }
182
-
183
- ?>
1
  <?php
2
 
3
+ /**Drow settings tab*/
4
+ function yasr_settings_tabs( $active_tab )
5
+ {
6
+ ?>
7
 
8
+ <h2 class="nav-tab-wrapper yasr-no-underline">
9
 
10
+ <a href="?page=yasr_settings_page&tab=general_settings"
11
+ class="nav-tab <?php
12
+ if ( $active_tab === 'general_settings' ) {
13
+ echo 'nav-tab-active' ;
14
+ }
15
+ ?>">
16
+ <?php
17
+ _e( "General Settings", 'yet-another-stars-rating' );
18
+ ?>
19
+ </a>
20
+
21
+ <a href="?page=yasr_settings_page&tab=manage_multi" class="nav-tab <?php
22
+ if ( $active_tab === 'manage_multi' ) {
23
+ echo 'nav-tab-active' ;
24
+ }
25
+ ?>">
26
+ <?php
27
+ _e( "Multi Sets", 'yet-another-stars-rating' );
28
+ ?>
29
+ </a>
30
+
31
+ <a href="?page=yasr_settings_page&tab=style_options"
32
+ class="nav-tab <?php
33
+ if ( $active_tab === 'style_options' ) {
34
+ echo 'nav-tab-active' ;
35
+ }
36
+ ?>">
37
+ <?php
38
+ _e( "Aspect & Styles", 'yet-another-stars-rating' );
39
+ ?>
40
+ </a>
41
+
42
+ <?php
43
+ do_action( 'yasr_add_settings_tab', $active_tab );
44
+ $rating_plugin_exists = new yasrSearchExistingRatingPlugin();
45
+
46
+ if ( $rating_plugin_exists->yasr_search_wppr() || $rating_plugin_exists->yasr_search_rmp() || $rating_plugin_exists->yasr_search_kksr() ) {
47
+ ?>
48
+ <a href="?page=yasr_settings_page&tab=migration_tools" class="nav-tab <?php
49
+ if ( $active_tab === 'migration_tools' ) {
50
+ echo 'nav-tab-active' ;
51
+ }
52
+ ?>">
53
+ <?php
54
+ _e( "Migration Tools", 'yet-another-stars-rating' );
55
+ ?>
56
+ </a>
57
+ <?php
58
+ }
59
+
60
+ ?>
61
+
62
+ </h2>
63
+
64
+ <?php
65
+ }
66
+
67
+ function yasr_upgrade_pro_box( $position = false )
68
+ {
69
+
70
+ if ( yasr_fs()->is_free_plan() ) {
71
+
72
+ if ( $position && $position == "bottom" ) {
73
  $yasr_upgrade_class = "yasr-donatedivbottom";
74
  } else {
75
  $yasr_upgrade_class = "yasr-donatedivdx";
76
  }
77
+
78
  ?>
79
 
80
+ <div class="<?php
81
+ echo $yasr_upgrade_class ;
82
+ ?>" style="display: none">
83
 
84
  <h2 class="yasr-donate-title" style="color: #34A7C1">
85
+ <?php
86
+ _e( 'Upgrade to YASR Pro', 'yet-another-stars-rating' );
87
+ ?>
88
  </h2>
89
 
90
  <div class="yasr-upgrade-to-pro">
91
  <ul>
92
+ <li><strong><?php
93
+ _e( ' User Reviews', 'yet-another-stars-rating' );
94
+ ?></strong></li>
95
+ <li><strong><?php
96
+ _e( ' Custom Rankings', 'yet-another-stars-rating' );
97
+ ?></strong></li>
98
+ <li><strong><?php
99
+ _e( ' 20 + ready to use themes', 'yet-another-stars-rating' );
100
+ ?></strong></li>
101
+ <li><strong><?php
102
+ _e( ' Upload your own theme', 'yet-another-stars-rating' );
103
+ ?></strong></li>
104
+ <li><strong><?php
105
+ _e( ' Dedicate support', 'yet-another-stars-rating' );
106
+ ?></strong></li>
107
+ <li><strong><?php
108
+ _e( ' ...And much more!!', 'yet-another-stars-rating' );
109
+ ?></strong></li>
110
  </ul>
111
+ <a href="<?php
112
+ echo yasr_fs()->get_upgrade_url() ;
113
+ ?>">
114
  <button class="button button-primary">Upgrade Now</button>
115
  </a>
116
  </div>
117
 
118
  </div>
119
 
120
+ <?php
 
121
  }
122
 
123
  }
127
  * Since version 1.9.5
128
  *
129
  */
130
+ function yasr_resources_box( $position = false )
131
+ {
132
+
133
+ if ( $position && $position == "bottom" ) {
134
  $yasr_metabox_class = "yasr-donatedivbottom";
135
+ } else {
136
  $yasr_metabox_class = "yasr-donatedivdx";
137
  }
138
+
139
+ $div = "<div class='{$yasr_metabox_class}' id='yasr-resources-box' style='display:none;'>";
 
140
  $text = '<div class="yasr-donate-title">Resources</div>';
141
  $text .= '<div class="yasr-donate-single-resource">
142
  <span class="dashicons dashicons-star-filled" style="color: #ccc"></span>
143
+ <a target="blank" href="http://yetanotherstarsrating.com/">' . __( 'YASR official website', 'yet-another-stars-rating' ) . '</a>
 
 
144
  </div>';
145
  $text .= '<div class="yasr-donate-single-resource">
146
  <span class="dashicons dashicons-edit" style="color: #ccc"></span>
147
+ <a target="blank" href="https://yetanotherstarsrating.com/yasr-basics-shortcode/">' . __( 'Documentation', 'yet-another-stars-rating' ) . '</a>
 
 
148
  </div>';
149
  $text .= '<div class="yasr-donate-single-resource">
150
  <span class="dashicons dashicons-book-alt" style="color: #ccc"></span>
151
+ <a target="blank" href="https://yetanotherstarsrating.com/f-a-q/">' . __( 'F.A.Q.', 'yet-another-stars-rating' ) . '</a>
 
 
152
  </div>';
153
  $text .= '<div class="yasr-donate-single-resource">
154
  <span class="dashicons dashicons-video-alt3" style="color: #ccc"></span>
155
+ <a target="blank" href="https://www.youtube.com/channel/UCU5jbO1PJsUUsCNbME9S-Zw">' . __( 'Youtube channel', 'yet-another-stars-rating' ) . '</a>
 
 
156
  </div>';
157
  $text .= '<div class="yasr-donate-single-resource">
158
  <span class="dashicons dashicons-smiley" style="color: #ccc"></span>
160
  Yasr Pro
161
  </a>
162
  </div>';
 
 
163
  $div_and_text = $div . $text . '</div>';
164
+ echo $div_and_text ;
 
 
165
  }
166
 
167
  /** Add a box on the right for asking to rate 5 stars on Wordpress.org
168
  * Since version 0.9.0
169
  */
170
+ function yasr_ask_rating( $position = false )
171
+ {
172
+
173
+ if ( $position && $position == "bottom" ) {
174
  $yasr_metabox_class = "yasr-donatedivbottom";
175
+ } else {
176
  $yasr_metabox_class = "yasr-donatedivdx";
177
  }
178
+
179
+ $div = "<div class='{$yasr_metabox_class}' id='yasr-ask-five-stars' style='display:none;'>";
180
+ $text = '<div class="yasr-donate-title">' . __( 'Can I ask your help?', 'yet-another-stars-rating' ) . '</div>';
 
181
  $text .= '<div style="font-size: 32px; color: #F1CB32; text-align:center; margin-bottom: 20px; margin-top: -5px;">
182
  <span class="dashicons dashicons-star-filled" style="font-size: 26px;"></span>
183
  <span class="dashicons dashicons-star-filled" style="font-size: 26px;"></span>
185
  <span class="dashicons dashicons-star-filled" style="font-size: 26px;"></span>
186
  <span class="dashicons dashicons-star-filled" style="font-size: 26px;"></span>
187
  </div>';
188
+ $text .= __( 'Please rate YASR 5 stars on', 'yet-another-stars-rating' );
189
  $text .= ' <a href="https://wordpress.org/support/view/plugin-reviews/yet-another-stars-rating?filter=5">
190
  WordPress.org.</a><br />';
191
+ $text .= __( ' It will require just 1 min but it\'s a HUGE help for me. Thank you.', 'yet-another-stars-rating' );
192
  $text .= "<br /><br />";
193
  $text .= "<em>> Dario Curvino</em>";
 
194
  $div_and_text = $div . $text . '</div>';
195
+ echo $div_and_text ;
 
 
196
  }
197
 
 
198
  /****
199
  Yasr Right settings panel, since version 1.9.5
200
  ****/
201
+ function yasr_right_settings_panel( $position = false )
202
+ {
203
+ do_action( 'yasr_right_settings_panel_box', $position );
204
+ yasr_upgrade_pro_box( $position );
205
+ yasr_resources_box( $position );
206
+ yasr_ask_rating( $position );
207
  }
208
 
 
209
  /** Change default admin footer on yasr settings pages
210
  * $text is the default wordpress text
211
  * Since 0.8.9
212
  */
213
+ add_filter( 'admin_footer_text', 'yasr_custom_admin_footer' );
214
+ function yasr_custom_admin_footer( $text )
215
+ {
216
+
217
+ if ( isset( $_GET['page'] ) ) {
 
218
  $yasr_page = $_GET['page'];
219
+
220
+ if ( $yasr_page == 'yasr_settings_page' ) {
221
  $custom_text = ' | <i>';
222
  $custom_text .= sprintf(
223
+ __( 'Thank you for using <a href="%s" target="_blank">Yet Another Stars Rating</a>.
224
+ Please <a href="%s" target="_blank">rate it</a> 5 stars on <a href="%s" target="_blank">WordPress.org</a>', 'yet-another-stars-rating' ),
 
 
225
  'https://yetanotherstarsrating.com',
226
  'https://wordpress.org/support/view/plugin-reviews/yet-another-stars-rating?filter=5',
227
  'https://wordpress.org/support/view/plugin-reviews/yet-another-stars-rating?filter=5'
228
  );
229
  $custom_text .= '</i>';
 
230
  return $text . $custom_text;
 
231
  } else {
232
  return $text;
233
  }
234
+
235
  } else {
236
  return $text;
237
  }
238
 
239
  }
 
 
lib/admin/settings/yasr-settings-functions-multiset-page.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $error_new_multi_set = yasr_process_new_multi_set_form(); //defined in yasr-settings-functions
26
+ $error_edit_multi_set = yasr_process_edit_multi_set_form(); //defined in yasr-settings-functions
27
+
28
+ if ($error_new_multi_set) {
29
+ echo "<div class=\"error\"> <p> <strong>";
30
+
31
+ foreach ($error_new_multi_set as $error) {
32
+ _e($error, 'yet-another-stars-rating');
33
+ echo "<br />";
34
+ }
35
+
36
+ echo "</strong></p></div>";
37
+ }
38
+
39
+ if ($error_edit_multi_set) {
40
+ echo "<div class=\"error\"> <p> <strong>";
41
+
42
+ foreach ($error_edit_multi_set as $error) {
43
+ _e($error, 'yet-another-stars-rating');
44
+ echo "<br />";
45
+ }
46
+
47
+ echo "</strong></p></div>";
48
+ }
49
+
50
+ global $wpdb;
51
+
52
+ //delete all transient that use multiset
53
+ $sql_delete_transient = "
54
+ DELETE FROM {$wpdb->options}
55
+ WHERE option_name LIKE '_transient_yasr_get_multi_set_values_and_field_%'
56
+ OR option_name LIKE '_transient_yasr_visitor_multi_set_%'
57
+ OR option_name LIKE '_transient_timeout_yasr_get_multi_set_values_and_field_%'
58
+ OR option_name LIKE '_transient_timeout_yasr_visitor_multi_set_%'
59
+ ";
60
+
61
+ $wpdb->query($sql_delete_transient);
62
+
63
+ $multi_set = yasr_get_multi_set();
64
+ $n_multi_set = $wpdb->num_rows; //wpdb->num_rows always store the last of the last query
65
+
66
+ ?>
67
+
68
+ <div class="yasr-settingsdiv">
69
+ <h3> <?php _e("Manage Multi Set", 'yet-another-stars-rating'); ?></h3>
70
+
71
+ <p>
72
+ <a href="#"
73
+ id="yasr-multi-set-doc-link"><?php _e("What is a Multi Set?", 'yet-another-stars-rating') ?></a>
74
+ </p>
75
+
76
+ <div id="yasr-multi-set-doc-box" style="display:none">
77
+ <?php _e(
78
+ "Multi Set allows you to insert a rate for each aspect about the product / local business /
79
+ whetever you're reviewing, example in the image below.",
80
+ 'yet-another-stars-rating'
81
+ );
82
+
83
+ echo "<br /><br /><img src=" . YASR_IMG_DIR . "/yasr-multi-set.png> <br /> <br />";
84
+
85
+ _e(
86
+ "You can create up to 99 different Multi Set and each one can contain up to 9 different fields.
87
+ Once you've saved it, you can insert the rates while typing your article in the box below the editor,
88
+ as you can see in this image (click to see it larger)",
89
+ 'yet-another-stars-rating'
90
+ );
91
+
92
+ echo "<br /><br /><a href=\"" . YASR_IMG_DIR . "yasr-multi-set-insert-rate.jpg\"><img src=" . YASR_IMG_DIR . "/yasr-multi-set-insert-rate-small.jpg></a> <br /> <br />";
93
+
94
+ _e(
95
+ 'In order to insert your Multi Sets into a post or page, you can either past the short code that will
96
+ appear at the bottom of the box or just click on the star in the graphic editor and select "Insert Multi Set".',
97
+ 'yet-another-stars-rating'
98
+ );
99
+
100
+ ?>
101
+ <br/> <br/>
102
+ <a href="#"
103
+ id="yasr-multi-set-doc-link-hide"><?php _e("Close this message", 'yet-another-stars-rating') ?></a>
104
+ </div>
105
+
106
+ <div class="yasr-multi-set-left">
107
+ <div class="yasr-new-multi-set">
108
+ <?php yasr_display_multi_set_form(); ?>
109
+ </div>
110
+ </div>
111
+
112
+ <div class="yasr-multi-set-right">
113
+ <?php yasr_edit_multi_form(); ?>
114
+ <div id="yasr-multi-set-response" style="display:none">
115
+ </div>
116
+ </div>
117
+
118
+ <div class="yasr-space-settings-div">
119
+ </div>
120
+
121
+
122
+ <div class="yasr-multi-set-choose-theme">
123
+ <!--This allow to choose if show average or no-->
124
+ <form action="options.php" method="post" id="yasr_multiset_form">
125
+ <?php
126
+ settings_fields('yasr_multiset_options_group');
127
+ do_settings_sections('yasr_multiset_tab');
128
+ submit_button(__('Save'));
129
+ ?>
130
+ </form>
131
+ </div>
132
+
133
+
134
+ </div>
135
+
lib/admin/settings/yasr-settings-functions-multiset.php CHANGED
@@ -18,194 +18,202 @@ You should have received a copy of the GNU General Public License
18
  along with this program. If not, see <http://www.gnu.org/licenses/>
19
  */
20
 
21
- if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // Exit if accessed directly
 
 
22
 
23
  /**************** Add yasr multiset options and settings ************/
24
 
25
- add_action( 'admin_init', 'yasr_multiset_options_init' ); //This is for general options
26
 
27
  function yasr_multiset_options_init() {
28
- register_setting(
29
- 'yasr_multiset_options_group', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
30
- 'yasr_multiset_options', //The name of an option to sanitize and save.
31
- 'yasr_sanitize_multiset_options'
32
- );
33
 
34
- $option_multiset = get_option( 'yasr_multiset_options' );
35
 
36
- if ($option_multiset === FALSE) {
 
 
37
 
38
- $option_multiset = array();
 
 
39
 
40
- }
41
-
42
- if (!isset($option_multiset['show_average'])) {
43
-
44
- $option_multiset['show_average'] = 'yes';
45
-
46
- }
47
-
48
- add_settings_section( 'yasr_multiset_options_section_id', '', 'yasr_multiset_section_callback', 'yasr_multiset_tab' );
49
- add_settings_field( 'yasr_multiset_hide_average_id', __('Show average?', 'yet-another-stars-rating'), 'yasr_multiset_hide_average_callback', 'yasr_multiset_tab', 'yasr_multiset_options_section_id', $option_multiset );
50
 
51
  }
52
 
53
- function yasr_multiset_section_callback () {
54
 
55
- //Silence
56
 
57
  }
58
 
59
- function yasr_multiset_hide_average_callback ($option_multiset) {
60
 
61
- ?>
62
 
63
- <div class="yasr-onoffswitch-big">
64
- <input type="checkbox" name="yasr_multiset_options[show_average]" class="yasr-onoffswitch-checkbox" id="yasr-multiset-options-show-average-switch" <?php if ($option_multiset['show_average']==='yes') echo " checked='checked' "; ?> >
65
- <label class="yasr-onoffswitch-label" for="yasr-multiset-options-show-average-switch">
66
- <span class="yasr-onoffswitch-inner"></span>
67
- <span class="yasr-onoffswitch-switch"></span>
68
- </label>
69
- </div>
 
 
 
70
 
71
- <br />
72
 
73
- <br />
74
 
75
- <?php
76
 
77
- _e("If you select no, the \"Average\" row will not be displayed. You can override this in the single multi set by using the parameter \"show_average\"", "yasr");
78
 
79
  }
80
 
81
 
82
- function yasr_sanitize_multiset_options ($option_multiset) {
83
-
84
- if (!array_key_exists('show_average', $option_multiset)) {
85
-
86
- $option_multiset['show_average'] = 'no';
87
 
88
- }
 
 
 
 
89
 
90
- else {
91
-
92
- $option_multiset['show_average'] = 'yes';
93
-
94
- }
95
-
96
- return $option_multiset;
97
 
98
  }
99
 
100
 
101
  /****** Create a form for settings page to create new multi set ******/
102
  function yasr_display_multi_set_form() {
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
- ?>
 
 
105
 
106
- <h4 class="yasr-multi-set-form-headers"><?php _e("Add New Multiple Set", 'yet-another-stars-rating'); ?></h4>
107
- <em><?php _e('Name, Element#1 and Element#2 MUST be filled and must be long at least 3 characters', 'yet-another-stars-rating') ?></em>
108
- <p>
109
- <form action="<?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>" id="form_add_multi_set" method="post">
110
- <strong><?php _e("Name", 'yet-another-stars-rating')?></strong>
111
- <input type="text" name="multi-set-name" id="new-multi-set-name" class="input-text-multi-set">
112
- <!--input type="hidden" name="action" value="yasr_new_multi_set_form" />-->
113
 
114
- <p></p>
115
- <?php _e("You can insert up to nine elements", 'yet-another-stars-rating') ?>
116
- <br />
117
 
118
- <?php for($i=1; $i<=9; $i++) {
 
119
 
120
- echo "<strong>" . __("Element ", 'yet-another-stars-rating') . "#$i" . "</strong>";
121
- ?>
122
- <input type="text" name="multi-set-name-element-<?php echo $i ?>" id="multi-set-name-element-<?php echo $i ?>" class="input-text-multi-set">
123
- <br />
124
 
125
- <?php } //End foreach
126
 
127
- wp_nonce_field( 'add-multi-set', 'add-nonce-new-multi-set' ) ?><!-- a little security to process on submission -->
 
 
 
 
128
 
129
- <br />
130
- <input type="submit" value="<?php _e("Create New Set", 'yet-another-stars-rating') ?>" class="button-primary"/>
131
- </form>
132
 
133
- <?php
 
 
 
 
 
134
  } //End function
135
 
136
 
137
  function yasr_edit_multi_form() {
138
 
139
- global $wpdb;
140
 
141
- $multi_set=yasr_get_multi_set();
142
 
143
- $n_multi_set = $wpdb->num_rows; //wpdb->num_rows always store the last of the last query
144
 
145
- if ($n_multi_set > 1) {
146
- ?>
147
 
148
- <div class="yasr-manage-multiset">
149
 
150
- <h4 class="yasr-multi-set-form-headers"><?php _e("Manage Multiple Set" , 'yet-another-stars-rating'); ?></h4>
151
 
152
- <?php _e('Wich set do you want to edit or remove?', 'yet-another-stars-rating')?>
153
 
154
- <select id ="yasr_select_edit_set">
155
- <?php foreach ($multi_set as $name) { ?>
156
- <option value="<?php echo $name->set_id ?>"><?php echo $name->set_name ?></option>
157
- <?php } //End foreach ?>
158
- </select>
159
 
160
- <button href="#" class="button-delete" id="yasr-button-select-set-edit-form"><?php _e("Select"); ?></button>
161
 
162
 
163
- </div>
164
 
165
- <?php
166
 
167
- } //End if n_multi_set >1
168
 
169
- elseif ($n_multi_set == 1) {
170
 
171
- $set_name=$wpdb->get_results("SELECT field_name AS name, field_id AS id, parent_set_id AS set_id
172
  FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
173
  ORDER BY field_id ASC");
174
 
175
- foreach ($multi_set as $find_set_id) {
176
- $set_type = $find_set_id->set_id;
177
- }
178
 
179
- ?>
180
 
181
- <div class="yasr-manage-multiset-single">
182
 
183
- <h4 class="yasr-multi-set-form-headers"><?php _e("Manage Multiple Set", 'yet-another-stars-rating'); ?></h4>
184
 
185
- <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>" id="form_edit_multi_set" method="post">
 
186
 
187
- <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />
188
 
189
- <table id="yasr-table-form-edit-multi-set">
190
- <tr>
191
 
192
- <td id="yasr-table-form-edit-multi-set-header">
193
- <?php _e('Field name', 'yet-another-stars-rating') ?>
194
- </td>
195
 
196
- <td id="yasr-table-form-edit-multi-set-remove">
197
- <?php _e('Remove', 'yet-another-stars-rating') ?>
198
- </td>
199
 
200
- </tr>
201
 
202
- <?php
203
 
204
- $i=1;
205
 
206
- foreach ($set_name as $name) {
207
 
208
- echo "
209
  <tr>
210
 
211
  <td width=\"80%\">
@@ -220,14 +228,14 @@ function yasr_edit_multi_form() {
220
  </tr>
221
  ";
222
 
223
- $i++;
224
 
225
- }
226
 
227
 
228
- $i = $i-1; //This is the number of the fields
229
 
230
- echo "
231
 
232
  <input type=\"hidden\" name=\"yasr-edit-form-number-elements\" id=\"yasr-edit-form-number-elements\" value=\"$i\">
233
 
@@ -248,81 +256,81 @@ function yasr_edit_multi_form() {
248
 
249
  ";
250
 
251
- echo "<p>";
252
- _e("If you remove something you will remove all the votes for that set or field. This operation CAN'T BE undone." , 'yet-another-stars-rating');
253
- echo "</p>";
254
-
255
- wp_nonce_field( 'edit-multi-set', 'add-nonce-edit-multi-set' )
256
 
257
- ?>
258
 
259
- <div id="yasr-element-limit" style="display:none; color:red"><?php _e("You can use up to 9 elements" , 'yet-another-stars-rating') ?></div>
260
 
261
- <input type="button" class="button-delete" id="yasr-add-field-edit-multiset" value="<?php _e('Add element', 'yet-another-stars-rating'); ?>">
 
262
 
263
- <input type="submit" value="<?php _e('Save changes', 'yet-another-stars-rating') ?>" class="button-primary" >
 
264
 
265
- </form>
 
266
 
267
- </div>
268
 
269
- <?php
270
- }
271
 
272
- else {
273
- _e("No Multiple Set were found", 'yet-another-stars-rating');
274
- }
 
275
 
276
  }//End function
277
 
278
 
279
  /****** Get and output multiple set in a form and table, used in settings page ******/
280
 
281
- add_action( 'wp_ajax_yasr_get_multi_set', 'yasr_get_multi_set_callback' );
282
 
283
  function yasr_get_multi_set_callback() {
284
- if (isset($_POST['set_id']) && $_POST['set_id'] != '' ) {
285
- $set_type = $_POST['set_id'];
286
- }
287
- else {
288
- exit ();
289
- }
290
 
291
- global $wpdb;
292
 
293
- $set_name=$wpdb->get_results($wpdb->prepare("SELECT field_name AS name, field_id AS id
294
  FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
295
  WHERE parent_set_id=%d
296
  ORDER BY field_id ASC", $set_type));
297
 
298
 
 
299
 
300
- ?>
301
-
302
- <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>" id="form_edit_multi_set" method="post">
303
- <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />
304
 
305
 
306
- <table id="yasr-table-form-edit-multi-set">
307
- <tr>
308
 
309
- <td id="yasr-table-form-edit-multi-set-header">
310
- <?php _e('Field name', 'yet-another-stars-rating') ?>
311
- </td>
312
 
313
- <td id="yasr-table-form-edit-multi-set-remove">
314
- <?php _e('Remove', 'yet-another-stars-rating') ?>
315
- </td>
316
 
317
- </tr>
318
 
319
- <?php
320
 
321
- $i=1;
322
 
323
- foreach ($set_name as $name) {
324
 
325
- echo "
326
  <tr>
327
 
328
  <td width=\"80%\">
@@ -337,14 +345,14 @@ function yasr_get_multi_set_callback() {
337
  </tr>
338
  ";
339
 
340
- $i++;
341
 
342
- }
343
 
344
 
345
- $i = $i-1; //This is the number of the fields
346
 
347
- echo "
348
 
349
  <input type=\"hidden\" name=\"yasr-edit-form-number-elements\" id=\"yasr-edit-form-number-elements\" value=\"$i\">
350
 
@@ -365,25 +373,27 @@ function yasr_get_multi_set_callback() {
365
 
366
  ";
367
 
368
- echo "<p>";
369
- _e("If you remove something you will remove all the votes for that set or field. This operation CAN'T BE undone." , 'yet-another-stars-rating');
370
- echo "</p>";
371
 
372
- wp_nonce_field( 'edit-multi-set', 'add-nonce-edit-multi-set' )
373
 
374
- ?>
375
 
376
- <div id="yasr-element-limit" style="display:none; color:red"><?php _e("You can use up to 9 elements" , 'yet-another-stars-rating') ?></div>
 
377
 
378
- <input type="button" class="button-delete" id="yasr-add-field-edit-multiset" value="<?php _e('Add element', 'yet-another-stars-rating'); ?>">
 
379
 
380
- <input type="submit" value="<?php _e('Save changes', 'yet-another-stars-rating') ?>" class="button-primary" >
381
 
382
- </form>
383
 
384
- <?php
385
 
386
- die();
387
 
388
  } //End function
389
 
@@ -391,435 +401,428 @@ function yasr_get_multi_set_callback() {
391
  /****** Validate new multi set form ******/
392
  function yasr_process_new_multi_set_form() {
393
 
394
- if ( isset( $_POST['multi-set-name'])) {
395
-
396
- global $wpdb;
397
 
398
- if ( !current_user_can( 'manage_options' ) ) {
399
- wp_die( 'You are not allowed to be on this page.' );
400
- }
401
 
402
- // Check nonce field
403
- check_admin_referer( 'add-multi-set', 'add-nonce-new-multi-set' );
 
404
 
405
- $array_errors = array();
406
- $error = FALSE;
407
 
408
- //IF thes fields are not empty go ahed
409
- if ($_POST['multi-set-name']!='' && $_POST['multi-set-name-element-1']!='' && $_POST['multi-set-name-element-2']!='' ) {
410
 
411
- $multi_set_name = ucfirst(strtolower($_POST['multi-set-name']));
 
412
 
413
- $multi_set_name_element_=array();
414
 
415
- $multi_set_name_element_[1]=$_POST['multi-set-name-element-1'];
416
- $multi_set_name_element_[2]=$_POST['multi-set-name-element-2'];
417
 
418
- //If multi set name is shorter than 3 characher come back
419
- if (mb_strlen($multi_set_name) < 3 || mb_strlen($multi_set_name_element_[1]) <3 || mb_strlen($multi_set_name_element_[2]) < 3 ) {
420
- $array_errors[] = "Content field must be longer than 3 chars";
421
- $error=TRUE;
422
- }
423
 
 
 
 
 
 
424
 
425
- if (mb_strlen($multi_set_name) > 40 || mb_strlen($multi_set_name_element_[1]) > 40 || mb_strlen($multi_set_name_element_[2]) > 40 ) {
426
- $array_errors[] = "Content field must be shorter than 40 chars";
427
- $error=TRUE;
428
- }
429
 
430
- //Check if a set with that name already exists
431
- $check_name_exists=$wpdb->get_results("SELECT set_name FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id ASC");
 
 
432
 
433
- foreach ($check_name_exists as $set_name) {
 
434
 
435
- if ($multi_set_name==$set_name->set_name) {
436
- $array_errors[] = "You already have a set with this name";
437
- $error=TRUE;
438
- }
439
 
440
- }
 
 
 
441
 
442
- $element_filled=2;
443
 
444
- //If filled get the element from 3 to 9
445
- for($i=3; $i<=9; $i++) {
446
 
447
- if (isset($_POST["multi-set-name-element-$i"]) && $_POST["multi-set-name-element-$i"]!='') {
 
448
 
449
- $multi_set_name_element_[$i]=$_POST["multi-set-name-element-$i"];
450
 
451
- if (mb_strlen($multi_set_name_element_[$i]) < 3) {
452
- $array_errors[] = "Field # $i must be at least 3 characters";
453
- $error=TRUE;
454
- }
455
 
456
- if (mb_strlen($multi_set_name_element_[$i]) > 40) {
457
- $array_errors[] = "Field # $i must be shorter than 40 characters";
458
- $error=TRUE;
459
- }
460
 
461
- $element_filled++;
462
- }
 
 
463
 
464
- }
 
465
 
466
- //If there isnt any error write in the table
467
- if (!$error) {
468
 
469
- //get the highest id in table
470
- $highest_id=$wpdb->get_results("SELECT set_id FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id DESC LIMIT 1 ");
471
 
472
- if (!$highest_id) {
473
- $name_table_new_id=0;
474
- }
475
 
476
- foreach ($highest_id as $id) {
477
- $name_table_new_id=$id->set_id + 1;
478
- }
479
 
480
- $insert_multi_name_success = $wpdb->replace(
481
- YASR_MULTI_SET_NAME_TABLE,
482
- array(
483
- 'set_id' =>$name_table_new_id,
484
- 'set_name' =>$multi_set_name
485
- ),
486
- array ('%d', '%s')
487
- );
488
 
489
- //If multi set name hase been inserted, now we're going to insert elements
490
- if ($insert_multi_name_success) {
 
 
 
 
 
 
491
 
492
- //get the highest id in table
493
- $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
494
 
495
- if (!$highest_id) {
496
- $field_table_new_id=0;
497
- }
498
 
499
- foreach ($highest_id as $id) {
500
- $field_table_new_id=$id->id + 1;
501
- }
502
 
503
- for ($i=1; $i<=$element_filled; $i++) {
504
- $insert_set_value=$wpdb->replace(
505
- YASR_MULTI_SET_FIELDS_TABLE,
506
- array(
507
- 'id' => $field_table_new_id,
508
- 'parent_set_id' =>$name_table_new_id,
509
- 'field_name' =>$multi_set_name_element_[$i],
510
- 'field_id' =>$i
511
- ),
512
- array ('%d', '%d', '%s', '%d')
513
- );
514
- $field_table_new_id++; //Avoid overwrite
515
- } //End for
516
 
517
- if ($insert_set_value) {
518
- echo "<div class=\"updated\"><p><strong>";
519
- _e("Settings Saved", 'yet-another-stars-rating');
520
- echo "</strong></p></div> ";
521
- }
 
 
 
 
 
 
 
 
522
 
523
- else {
524
- _e("Something goes wrong trying insert set field name. Please report it", 'yet-another-stars-rating');
525
- }
 
 
 
 
526
 
527
- } //End if $insert_multi_name_success
528
 
529
- else {
530
- _e("Something goes wrong trying insert Multi Set name. Please report it", 'yet-another-stars-rating');
531
- }
532
 
533
- } //End if !$error
534
 
535
- } //End if $_POST['multi-set-name']!=''
536
 
537
- //Else multi set's name and first 2 elements are empty
538
- else {
539
- $array_errors[] = "Multi Set's name and first 2 elements can't be empty";
540
- $error=TRUE;
541
- }
542
 
543
- if ($error) {
544
- return $array_errors;
545
- }
546
 
547
- } //End if ( isset( $_POST['multi-set-name']) ) {
548
 
549
  } //End yasr_process_new_multi_set_form() function
550
 
551
  function yasr_process_edit_multi_set_form() {
552
 
553
- $error = FALSE;
554
-
555
- if ( isset( $_POST['yasr_edit_multi_set_form']) ) {
556
-
557
- $set_id = $_POST['yasr_edit_multi_set_form'];
558
 
559
- $number_of_stored_elements = $_POST['yasr-edit-form-number-elements'];
560
 
561
- global $wpdb;
562
 
563
- $array_errors = array();
564
 
565
- if ( !current_user_can( 'manage_options' ) ) {
566
- wp_die( 'You are not allowed to be on this page.' );
567
- }
568
 
569
- // Check nonce field
570
- check_admin_referer( 'edit-multi-set', 'add-nonce-edit-multi-set' );
571
 
 
 
 
572
 
573
- //Check if user want to delete entire set
 
574
 
575
- if (isset($_POST["yasr-remove-multi-set"])) {
576
 
577
- $remove_set = $wpdb->delete (
578
- YASR_MULTI_SET_NAME_TABLE,
579
- array(
580
- 'set_id' => $set_id,
581
- ),
582
- array ('%d')
583
- );
584
 
585
- $remove_set_values = $wpdb->delete (
586
- YASR_MULTI_SET_FIELDS_TABLE,
587
- array(
588
- 'parent_set_id' => $set_id,
589
- ),
590
- array ('%d')
591
- );
592
 
593
- $remove_set_votes = $wpdb->delete (
594
- YASR_MULTI_SET_VALUES_TABLE,
595
- array(
596
- 'set_type' => $set_id,
597
- ),
598
- array ('%d')
599
- );
600
 
601
- if ($remove_set==FALSE) {
602
- $error = TRUE;
603
- $array_errors[] .= __("Something goes wrong trying to delete a Multi Set . Please report it", 'yet-another-stars-rating');
604
- }
 
 
 
605
 
 
 
 
 
 
 
 
606
 
607
- //Comment this out, if try to delete an empty set print error
608
- /*if ($remove_set_values==FALSE) {
609
- $error = TRUE;
610
- $array_errors[] .= __("Something goes wrong trying to delete data fields for a set. Please report it", 'yet-another-stars-rating');
611
- }
612
- */
613
 
614
- //Comment this out, will echo error even if the value for that field it's just empty
615
- /*if ($remove_set_votes==FALSE) {
616
- $error = TRUE;
617
- $array_errors[] .= __("Something goes wrong trying to delete data values for a set. Please report it", 'yet-another-stars-rating');
618
- }*/
619
 
620
- }
 
 
 
 
 
621
 
622
- for ($i = 0; $i <= 9; $i++) {
 
 
 
 
623
 
624
- //Than, check if the user want to remove some field
625
- if (isset($_POST["remove-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) ) {
626
 
627
- $field_to_remove = $_POST["remove-element-$i"];
628
 
629
- $remove_field = $wpdb->delete (
630
- YASR_MULTI_SET_FIELDS_TABLE,
631
- array(
632
- 'parent_set_id' => $set_id,
633
- 'field_id' =>$field_to_remove
634
- ),
635
- array ('%d', '%d')
636
- );
637
 
638
- $remove_values = $wpdb->delete (
639
- YASR_MULTI_SET_VALUES_TABLE,
640
- array(
641
- 'set_type' => $set_id,
642
- 'field_id' =>$field_to_remove
643
- ),
644
- array ('%d', '%d')
645
- );
646
 
647
- if ($remove_field == FALSE) {
648
- $error = TRUE;
649
- $array_errors[] = __("Something goes wrong trying to delete a Multi Set's element. Please report it", 'yet-another-stars-rating');
650
- }
 
 
 
 
651
 
 
 
 
 
 
 
 
 
652
 
653
- //Comment this out, will echo error even if the value for that field it's just empty
654
- /*if ($remove_values == FALSE) {
655
- $error = TRUE;
656
- $array_errors[] = __("Something goes wrong trying to delete data value for an element. Please report it", 'yet-another-stars-rating');
657
- }*/
658
 
659
 
660
- } //End if isset $_POST['remove-element-$i']
 
 
 
 
661
 
662
 
663
- //update the stored elements with the new ones
664
- if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i <= $number_of_stored_elements ) {
665
 
666
- $field_name = $_POST["edit-multi-set-element-$i"];
667
 
668
- $field_id = $_POST["db-id-for-element-$i"];
 
669
 
670
- //if elements name is shorter than 3 chars
671
- if (mb_strlen($field_name) <3) {
672
- $array_errors[] = __("Field # $i must be at least 3 characters", 'yet-another-stars-rating');
673
- $error=TRUE;
674
- }
675
 
676
- if(mb_strlen($field_name) > 40) {
677
- $array_errors[] = __("Field # $i must be shorter than 40 characters", 'yet-another-stars-rating');
678
- $error=TRUE;
679
- }
680
 
681
- else {
 
 
 
 
682
 
683
- //Check if field name is changed
684
- $field_name_in_db = $wpdb->get_results($wpdb->prepare("SELECT field_name FROM " . YASR_MULTI_SET_FIELDS_TABLE . " WHERE field_id=%d AND parent_set_id=%d", $field_id, $set_id ) );
 
 
685
 
686
- foreach ($field_name_in_db as $field_in_db) {
687
- $field_name_in_database = $field_in_db->field_name;
688
- }
689
 
690
- //if field name in db is different from field name in form update it
691
- if ($field_name_in_database != $field_name) {
 
692
 
693
- $insert_field_name=$wpdb->update(
694
- YASR_MULTI_SET_FIELDS_TABLE,
695
 
696
- array(
697
- 'field_name' =>$field_name,
698
- ),
699
 
700
- array(
701
- 'parent_set_id' =>$set_id,
702
- 'field_id' =>$field_id
703
- ),
704
 
705
- array ('%s'),
 
 
 
706
 
707
- array ('%d', '%d')
708
 
709
- );
710
 
711
- if ($insert_field_name == FALSE) {
712
- $error = TRUE;
713
- $array_errors[] = __("Something goes wrong trying to update a Multi Set's element. Please report it", 'yet-another-stars-rating');
714
- }
715
 
716
- } //End if ($field_name_in_database != $field_name) {
 
 
 
717
 
718
- }
719
 
720
- } //End if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["remove-element-$i"]) && $i<=$number_of_stored_elements )
721
 
 
722
 
723
- //If $i > number of stored elements, user is adding new elements, so we're going to insert the new ones
724
- if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i > $number_of_stored_elements ) {
725
 
726
- $field_name = $_POST["edit-multi-set-element-$i"];
 
727
 
728
- //if elements name is shorter than 3 chars return error. I use mb_strlen($field_name) > 1
729
- //because I don't wont return error if an user add an empty field. An empty field will be
730
- //just ignored
731
- if (mb_strlen($field_name) > 1 && mb_strlen($field_name) < 3) {
732
- $array_errors[] = __("Field # $i must be at least 3 characters", 'yet-another-stars-rating');
733
- $error=TRUE;
734
- }
735
 
736
- if(mb_strlen($field_name) > 40) {
737
- $array_errors[] = __("Field # $i must be shorter than 40 characters", 'yet-another-stars-rating');
738
- $error=TRUE;
739
- }
 
 
 
740
 
741
- //if field is not empty
742
- elseif ($field_name != '') {
 
 
 
743
 
744
- $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
745
 
746
- $highest_field_id = $wpdb->get_results("SELECT field_id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY field_id DESC LIMIT 1 ");
747
 
748
- foreach ($highest_id as $id) {
749
- $field_table_new_id=$id->id + 1;
750
- }
751
 
752
- foreach ($highest_field_id as $id) {
753
- $new_field_id = $id->field_id+1;
754
- }
755
 
756
- $insert_set_value=$wpdb->replace(
757
- YASR_MULTI_SET_FIELDS_TABLE,
758
- array(
759
- 'id' => $field_table_new_id,
760
- 'parent_set_id' =>$set_id,
761
- 'field_name' =>$field_name,
762
- 'field_id' =>$new_field_id
763
- ),
764
- array ('%d', '%d', '%s', '%d')
765
- );
766
 
767
- //now, I've to find which post is using the edited multi set and add the new field with value 0
768
 
769
- //get the highest id
770
- $highest_id_value_table = $wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_VALUES_TABLE . " ORDER BY id DESC LIMIT 1 ");
771
 
772
- foreach ($highest_id_value_table as $id) {
773
- $field_value_table_new_id=$id->id + 1;
774
- }
775
 
776
- //get all the post id that are using this multiset
777
- $array_post_id = $wpdb->get_results($wpdb->prepare("SELECT post_id
778
  FROM " . YASR_MULTI_SET_VALUES_TABLE .
779
- " WHERE set_type=%d
780
  GROUP BY post_id", $set_id));
781
 
782
- //Insert the new fields
783
- foreach ($array_post_id as $postid) {
784
 
785
- $insert_new_field_values_table = $wpdb->insert(
786
- YASR_MULTI_SET_VALUES_TABLE,
787
- array(
788
- 'id' => $field_value_table_new_id,
789
- 'set_type' => $set_id,
790
- 'field_id' => $new_field_id,
791
- 'post_id' => $postid->post_id
792
- ),
793
- array ('%d', '%d', '%d', '%d')
794
- );
795
 
796
- $field_value_table_new_id++;
797
 
798
- }
799
 
800
- if ($insert_set_value == FALSE) {
801
- $error = TRUE;
802
- $array_errors[] = __("Something goes wrong trying to insert set field name in edit form. Please report it", 'yet-another-stars-rating');
803
- }
804
 
805
- } //end else
806
- }
807
 
808
 
809
- } //End for
810
 
811
 
812
- if ($error) {
813
- return $array_errors;
814
- }
815
- else {
816
- echo "<div class=\"updated\"><p><strong>";
817
- _e("Settings Saved", 'yet-another-stars-rating');
818
- echo "</strong></p></div> ";
819
- }
820
 
821
 
822
- } //End if isset( $_POST['yasr_edit_multi_set_form']
823
 
824
 
825
  } //End yasr_process_edit_multi_set_form() function
18
  along with this program. If not, see <http://www.gnu.org/licenses/>
19
  */
20
 
21
+ if (!defined('ABSPATH')) {
22
+ exit('You\'re not allowed to see this page');
23
+ } // Exit if accessed directly
24
 
25
  /**************** Add yasr multiset options and settings ************/
26
 
27
+ add_action('admin_init', 'yasr_multiset_options_init'); //This is for general options
28
 
29
  function yasr_multiset_options_init() {
30
+ register_setting(
31
+ 'yasr_multiset_options_group', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
32
+ 'yasr_multiset_options', //The name of an option to sanitize and save.
33
+ 'yasr_sanitize_multiset_options'
34
+ );
35
 
36
+ $option_multiset = get_option('yasr_multiset_options');
37
 
38
+ if ($option_multiset === false) {
39
+ $option_multiset = array();
40
+ }
41
 
42
+ if (!isset($option_multiset['show_average'])) {
43
+ $option_multiset['show_average'] = 'yes';
44
+ }
45
 
46
+ add_settings_section('yasr_multiset_options_section_id', '', 'yasr_multiset_section_callback', 'yasr_multiset_tab');
47
+ add_settings_field('yasr_multiset_hide_average_id', __('Show average?', 'yet-another-stars-rating'), 'yasr_multiset_hide_average_callback', 'yasr_multiset_tab', 'yasr_multiset_options_section_id', $option_multiset);
 
 
 
 
 
 
 
 
48
 
49
  }
50
 
51
+ function yasr_multiset_section_callback() {
52
 
53
+ //Silence
54
 
55
  }
56
 
57
+ function yasr_multiset_hide_average_callback($option_multiset) {
58
 
59
+ ?>
60
 
61
+ <div class="yasr-onoffswitch-big">
62
+ <input type="checkbox" name="yasr_multiset_options[show_average]" class="yasr-onoffswitch-checkbox"
63
+ id="yasr-multiset-options-show-average-switch" <?php if ($option_multiset['show_average'] === 'yes') {
64
+ echo " checked='checked' ";
65
+ } ?> >
66
+ <label class="yasr-onoffswitch-label" for="yasr-multiset-options-show-average-switch">
67
+ <span class="yasr-onoffswitch-inner"></span>
68
+ <span class="yasr-onoffswitch-switch"></span>
69
+ </label>
70
+ </div>
71
 
72
+ <br/>
73
 
74
+ <br/>
75
 
76
+ <?php
77
 
78
+ _e("If you select no, the \"Average\" row will not be displayed. You can override this in the single multi set by using the parameter \"show_average\"", "yasr");
79
 
80
  }
81
 
82
 
83
+ function yasr_sanitize_multiset_options($option_multiset) {
 
 
 
 
84
 
85
+ if (!array_key_exists('show_average', $option_multiset)) {
86
+ $option_multiset['show_average'] = 'no';
87
+ } else {
88
+ $option_multiset['show_average'] = 'yes';
89
+ }
90
 
91
+ return $option_multiset;
 
 
 
 
 
 
92
 
93
  }
94
 
95
 
96
  /****** Create a form for settings page to create new multi set ******/
97
  function yasr_display_multi_set_form() {
98
+ ?>
99
+
100
+ <h4 class="yasr-multi-set-form-headers">
101
+ <?php _e("Add New Multiple Set", 'yet-another-stars-rating'); ?>
102
+ </h4>
103
+
104
+ <p>
105
+ <em>
106
+ <?php _e('Name, Element#1 and Element#2 MUST be filled and must be long at least 3 characters',
107
+ 'yet-another-stars-rating') ?>
108
+ </em>
109
+ </p>
110
 
111
+ <div>
112
+ <form action="<?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>"
113
+ id="form_add_multi_set" method="post">
114
 
115
+ <?php wp_nonce_field('add-multi-set', 'add-nonce-new-multi-set') //Must be inside the form ?>
 
 
 
 
 
 
116
 
117
+ <strong><?php _e("Name", 'yet-another-stars-rating') ?></strong>
 
 
118
 
119
+ <input type="text" name="multi-set-name" id="new-multi-set-name" class="input-text-multi-set">
120
+ <br />
121
 
122
+ <?php _e("You can insert up to nine elements", 'yet-another-stars-rating') ?>
123
+ <br/>
 
 
124
 
125
+ <?php for ($i = 1; $i <= 9; $i ++) {
126
 
127
+ echo "<strong>" . __('Element ', 'yet-another-stars-rating') . "#$i" . "</strong>";
128
+ ?>
129
+ <input type="text" name="multi-set-name-element-<?php echo $i ?>" id="multi-set-name-element-<?php echo $i ?>"
130
+ class="input-text-multi-set">
131
+ <br/>
132
 
133
+ <?php } //End foreach ?>
 
 
134
 
135
+ <br/>
136
+ <input type="submit" value="<?php _e("Create New Set", 'yet-another-stars-rating') ?>" class="button-primary"/>
137
+ </form>
138
+ </div>
139
+
140
+ <?php
141
  } //End function
142
 
143
 
144
  function yasr_edit_multi_form() {
145
 
146
+ global $wpdb;
147
 
148
+ $multi_set = yasr_get_multi_set();
149
 
150
+ $n_multi_set = $wpdb->num_rows; //wpdb->num_rows always store the last of the last query
151
 
152
+ if ($n_multi_set > 1) {
153
+ ?>
154
 
155
+ <div class="yasr-manage-multiset">
156
 
157
+ <h4 class="yasr-multi-set-form-headers"><?php _e("Manage Multiple Set", 'yet-another-stars-rating'); ?></h4>
158
 
159
+ <?php _e('Wich set do you want to edit or remove?', 'yet-another-stars-rating') ?>
160
 
161
+ <select id="yasr_select_edit_set">
162
+ <?php foreach ($multi_set as $name) { ?>
163
+ <option value="<?php echo $name->set_id ?>"><?php echo $name->set_name ?></option>
164
+ <?php } //End foreach ?>
165
+ </select>
166
 
167
+ <button href="#" class="button-delete" id="yasr-button-select-set-edit-form"><?php _e("Select"); ?></button>
168
 
169
 
170
+ </div>
171
 
172
+ <?php
173
 
174
+ } //End if n_multi_set >1
175
 
176
+ elseif ($n_multi_set == 1) {
177
 
178
+ $set_name = $wpdb->get_results("SELECT field_name AS name, field_id AS id, parent_set_id AS set_id
179
  FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
180
  ORDER BY field_id ASC");
181
 
182
+ foreach ($multi_set as $find_set_id) {
183
+ $set_type = $find_set_id->set_id;
184
+ }
185
 
186
+ ?>
187
 
188
+ <div class="yasr-manage-multiset-single">
189
 
190
+ <h4 class="yasr-multi-set-form-headers"><?php _e("Manage Multiple Set", 'yet-another-stars-rating'); ?></h4>
191
 
192
+ <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>"
193
+ id="form_edit_multi_set" method="post">
194
 
195
+ <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>"/>
196
 
197
+ <table id="yasr-table-form-edit-multi-set">
198
+ <tr>
199
 
200
+ <td id="yasr-table-form-edit-multi-set-header">
201
+ <?php _e('Field name', 'yet-another-stars-rating') ?>
202
+ </td>
203
 
204
+ <td id="yasr-table-form-edit-multi-set-remove">
205
+ <?php _e('Remove', 'yet-another-stars-rating') ?>
206
+ </td>
207
 
208
+ </tr>
209
 
210
+ <?php
211
 
212
+ $i = 1;
213
 
214
+ foreach ($set_name as $name) {
215
 
216
+ echo "
217
  <tr>
218
 
219
  <td width=\"80%\">
228
  </tr>
229
  ";
230
 
231
+ $i ++;
232
 
233
+ }
234
 
235
 
236
+ $i = $i - 1; //This is the number of the fields
237
 
238
+ echo "
239
 
240
  <input type=\"hidden\" name=\"yasr-edit-form-number-elements\" id=\"yasr-edit-form-number-elements\" value=\"$i\">
241
 
256
 
257
  ";
258
 
259
+ echo "<p>";
260
+ _e("If you remove something you will remove all the votes for that set or field. This operation CAN'T BE undone.", 'yet-another-stars-rating');
261
+ echo "</p>";
 
 
262
 
263
+ wp_nonce_field('edit-multi-set', 'add-nonce-edit-multi-set')
264
 
265
+ ?>
266
 
267
+ <div id="yasr-element-limit"
268
+ style="display:none; color:red"><?php _e("You can use up to 9 elements", 'yet-another-stars-rating') ?></div>
269
 
270
+ <input type="button" class="button-delete" id="yasr-add-field-edit-multiset"
271
+ value="<?php _e('Add element', 'yet-another-stars-rating'); ?>">
272
 
273
+ <input type="submit" value="<?php _e('Save changes', 'yet-another-stars-rating') ?>"
274
+ class="button-primary">
275
 
276
+ </form>
277
 
278
+ </div>
 
279
 
280
+ <?php
281
+ } else {
282
+ _e("No Multiple Set were found", 'yet-another-stars-rating');
283
+ }
284
 
285
  }//End function
286
 
287
 
288
  /****** Get and output multiple set in a form and table, used in settings page ******/
289
 
290
+ add_action('wp_ajax_yasr_get_multi_set', 'yasr_get_multi_set_callback');
291
 
292
  function yasr_get_multi_set_callback() {
293
+ if (isset($_POST['set_id']) && $_POST['set_id'] != '') {
294
+ $set_type = $_POST['set_id'];
295
+ } else {
296
+ exit ();
297
+ }
 
298
 
299
+ global $wpdb;
300
 
301
+ $set_name = $wpdb->get_results($wpdb->prepare("SELECT field_name AS name, field_id AS id
302
  FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
303
  WHERE parent_set_id=%d
304
  ORDER BY field_id ASC", $set_type));
305
 
306
 
307
+ ?>
308
 
309
+ <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>"
310
+ id="form_edit_multi_set" method="post">
311
+ <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>"/>
 
312
 
313
 
314
+ <table id="yasr-table-form-edit-multi-set">
315
+ <tr>
316
 
317
+ <td id="yasr-table-form-edit-multi-set-header">
318
+ <?php _e('Field name', 'yet-another-stars-rating') ?>
319
+ </td>
320
 
321
+ <td id="yasr-table-form-edit-multi-set-remove">
322
+ <?php _e('Remove', 'yet-another-stars-rating') ?>
323
+ </td>
324
 
325
+ </tr>
326
 
327
+ <?php
328
 
329
+ $i = 1;
330
 
331
+ foreach ($set_name as $name) {
332
 
333
+ echo "
334
  <tr>
335
 
336
  <td width=\"80%\">
345
  </tr>
346
  ";
347
 
348
+ $i ++;
349
 
350
+ }
351
 
352
 
353
+ $i = $i - 1; //This is the number of the fields
354
 
355
+ echo "
356
 
357
  <input type=\"hidden\" name=\"yasr-edit-form-number-elements\" id=\"yasr-edit-form-number-elements\" value=\"$i\">
358
 
373
 
374
  ";
375
 
376
+ echo "<p>";
377
+ _e("If you remove something you will remove all the votes for that set or field. This operation CAN'T BE undone.", 'yet-another-stars-rating');
378
+ echo "</p>";
379
 
380
+ wp_nonce_field('edit-multi-set', 'add-nonce-edit-multi-set')
381
 
382
+ ?>
383
 
384
+ <div id="yasr-element-limit"
385
+ style="display:none; color:red"><?php _e("You can use up to 9 elements", 'yet-another-stars-rating') ?></div>
386
 
387
+ <input type="button" class="button-delete" id="yasr-add-field-edit-multiset"
388
+ value="<?php _e('Add element', 'yet-another-stars-rating'); ?>">
389
 
390
+ <input type="submit" value="<?php _e('Save changes', 'yet-another-stars-rating') ?>" class="button-primary">
391
 
392
+ </form>
393
 
394
+ <?php
395
 
396
+ die();
397
 
398
  } //End function
399
 
401
  /****** Validate new multi set form ******/
402
  function yasr_process_new_multi_set_form() {
403
 
404
+ if (isset($_POST['multi-set-name'])) {
 
 
405
 
406
+ global $wpdb;
 
 
407
 
408
+ if (!current_user_can('manage_options')) {
409
+ wp_die('You are not allowed to be on this page.');
410
+ }
411
 
412
+ // Check nonce field
413
+ check_admin_referer('add-multi-set', 'add-nonce-new-multi-set');
414
 
415
+ $array_errors = array();
416
+ $error = false;
417
 
418
+ //IF thes fields are not empty go ahed
419
+ if ($_POST['multi-set-name'] != '' && $_POST['multi-set-name-element-1'] != '' && $_POST['multi-set-name-element-2'] != '') {
420
 
421
+ $multi_set_name = ucfirst(strtolower($_POST['multi-set-name']));
422
 
423
+ $multi_set_name_element_ = array();
 
424
 
425
+ $multi_set_name_element_[1] = $_POST['multi-set-name-element-1'];
426
+ $multi_set_name_element_[2] = $_POST['multi-set-name-element-2'];
 
 
 
427
 
428
+ //If multi set name is shorter than 3 characher come back
429
+ if (mb_strlen($multi_set_name) < 3 || mb_strlen($multi_set_name_element_[1]) < 3 || mb_strlen($multi_set_name_element_[2]) < 3) {
430
+ $array_errors[] = "Content field must be longer than 3 chars";
431
+ $error = true;
432
+ }
433
 
 
 
 
 
434
 
435
+ if (mb_strlen($multi_set_name) > 40 || mb_strlen($multi_set_name_element_[1]) > 40 || mb_strlen($multi_set_name_element_[2]) > 40) {
436
+ $array_errors[] = "Content field must be shorter than 40 chars";
437
+ $error = true;
438
+ }
439
 
440
+ //Check if a set with that name already exists
441
+ $check_name_exists = $wpdb->get_results("SELECT set_name FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id ASC");
442
 
443
+ foreach ($check_name_exists as $set_name) {
 
 
 
444
 
445
+ if ($multi_set_name == $set_name->set_name) {
446
+ $array_errors[] = "You already have a set with this name";
447
+ $error = true;
448
+ }
449
 
450
+ }
451
 
452
+ $element_filled = 2;
 
453
 
454
+ //If filled get the element from 3 to 9
455
+ for ($i = 3; $i <= 9; $i ++) {
456
 
457
+ if (isset($_POST["multi-set-name-element-$i"]) && $_POST["multi-set-name-element-$i"] != '') {
458
 
459
+ $multi_set_name_element_[$i] = $_POST["multi-set-name-element-$i"];
 
 
 
460
 
461
+ if (mb_strlen($multi_set_name_element_[$i]) < 3) {
462
+ $array_errors[] = "Field # $i must be at least 3 characters";
463
+ $error = true;
464
+ }
465
 
466
+ if (mb_strlen($multi_set_name_element_[$i]) > 40) {
467
+ $array_errors[] = "Field # $i must be shorter than 40 characters";
468
+ $error = true;
469
+ }
470
 
471
+ $element_filled ++;
472
+ }
473
 
474
+ }
 
475
 
476
+ //If there isnt any error write in the table
477
+ if (!$error) {
478
 
479
+ //get the highest id in table
480
+ $highest_id = $wpdb->get_results("SELECT set_id FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id DESC LIMIT 1 ");
 
481
 
482
+ if (!$highest_id) {
483
+ $name_table_new_id = 0;
484
+ }
485
 
486
+ foreach ($highest_id as $id) {
487
+ $name_table_new_id = $id->set_id + 1;
488
+ }
 
 
 
 
 
489
 
490
+ $insert_multi_name_success = $wpdb->replace(
491
+ YASR_MULTI_SET_NAME_TABLE,
492
+ array(
493
+ 'set_id' => $name_table_new_id,
494
+ 'set_name' => $multi_set_name
495
+ ),
496
+ array('%d', '%s')
497
+ );
498
 
499
+ //If multi set name hase been inserted, now we're going to insert elements
500
+ if ($insert_multi_name_success) {
501
 
502
+ //get the highest id in table
503
+ $highest_id = $wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
 
504
 
505
+ if (!$highest_id) {
506
+ $field_table_new_id = 0;
507
+ }
508
 
509
+ foreach ($highest_id as $id) {
510
+ $field_table_new_id = $id->id + 1;
511
+ }
 
 
 
 
 
 
 
 
 
 
512
 
513
+ for ($i = 1; $i <= $element_filled; $i ++) {
514
+ $insert_set_value = $wpdb->replace(
515
+ YASR_MULTI_SET_FIELDS_TABLE,
516
+ array(
517
+ 'id' => $field_table_new_id,
518
+ 'parent_set_id' => $name_table_new_id,
519
+ 'field_name' => $multi_set_name_element_[$i],
520
+ 'field_id' => $i
521
+ ),
522
+ array('%d', '%d', '%s', '%d')
523
+ );
524
+ $field_table_new_id ++; //Avoid overwrite
525
+ } //End for
526
 
527
+ if ($insert_set_value) {
528
+ echo "<div class=\"updated\"><p><strong>";
529
+ _e("Settings Saved", 'yet-another-stars-rating');
530
+ echo "</strong></p></div> ";
531
+ } else {
532
+ _e("Something goes wrong trying insert set field name. Please report it", 'yet-another-stars-rating');
533
+ }
534
 
535
+ } //End if $insert_multi_name_success
536
 
537
+ else {
538
+ _e("Something goes wrong trying insert Multi Set name. Please report it", 'yet-another-stars-rating');
539
+ }
540
 
541
+ } //End if !$error
542
 
543
+ } //End if $_POST['multi-set-name']!=''
544
 
545
+ //Else multi set's name and first 2 elements are empty
546
+ else {
547
+ $array_errors[] = "Multi Set's name and first 2 elements can't be empty";
548
+ $error = true;
549
+ }
550
 
551
+ if ($error) {
552
+ return $array_errors;
553
+ }
554
 
555
+ } //End if ( isset( $_POST['multi-set-name']) ) {
556
 
557
  } //End yasr_process_new_multi_set_form() function
558
 
559
  function yasr_process_edit_multi_set_form() {
560
 
561
+ $error = false;
 
 
 
 
562
 
563
+ if (isset($_POST['yasr_edit_multi_set_form'])) {
564
 
565
+ $set_id = $_POST['yasr_edit_multi_set_form'];
566
 
567
+ $number_of_stored_elements = $_POST['yasr-edit-form-number-elements'];
568
 
569
+ global $wpdb;
 
 
570
 
571
+ $array_errors = array();
 
572
 
573
+ if (!current_user_can('manage_options')) {
574
+ wp_die('You are not allowed to be on this page.');
575
+ }
576
 
577
+ // Check nonce field
578
+ check_admin_referer('edit-multi-set', 'add-nonce-edit-multi-set');
579
 
 
580
 
581
+ //Check if user want to delete entire set
 
 
 
 
 
 
582
 
583
+ if (isset($_POST["yasr-remove-multi-set"])) {
 
 
 
 
 
 
584
 
585
+ $remove_set = $wpdb->delete(
586
+ YASR_MULTI_SET_NAME_TABLE,
587
+ array(
588
+ 'set_id' => $set_id,
589
+ ),
590
+ array('%d')
591
+ );
592
 
593
+ $remove_set_values = $wpdb->delete(
594
+ YASR_MULTI_SET_FIELDS_TABLE,
595
+ array(
596
+ 'parent_set_id' => $set_id,
597
+ ),
598
+ array('%d')
599
+ );
600
 
601
+ $remove_set_votes = $wpdb->delete(
602
+ YASR_MULTI_SET_VALUES_TABLE,
603
+ array(
604
+ 'set_type' => $set_id,
605
+ ),
606
+ array('%d')
607
+ );
608
 
609
+ if ($remove_set == false) {
610
+ $error = true;
611
+ $array_errors[] .= __("Something goes wrong trying to delete a Multi Set . Please report it", 'yet-another-stars-rating');
612
+ }
 
 
613
 
 
 
 
 
 
614
 
615
+ //Comment this out, if try to delete an empty set print error
616
+ /*if ($remove_set_values==FALSE) {
617
+ $error = TRUE;
618
+ $array_errors[] .= __("Something goes wrong trying to delete data fields for a set. Please report it", 'yet-another-stars-rating');
619
+ }
620
+ */
621
 
622
+ //Comment this out, will echo error even if the value for that field it's just empty
623
+ /*if ($remove_set_votes==FALSE) {
624
+ $error = TRUE;
625
+ $array_errors[] .= __("Something goes wrong trying to delete data values for a set. Please report it", 'yet-another-stars-rating');
626
+ }*/
627
 
628
+ }
 
629
 
630
+ for ($i = 0; $i <= 9; $i ++) {
631
 
632
+ //Than, check if the user want to remove some field
633
+ if (isset($_POST["remove-element-$i"]) && !isset($_POST["yasr-remove-multi-set"])) {
 
 
 
 
 
 
634
 
635
+ $field_to_remove = $_POST["remove-element-$i"];
 
 
 
 
 
 
 
636
 
637
+ $remove_field = $wpdb->delete(
638
+ YASR_MULTI_SET_FIELDS_TABLE,
639
+ array(
640
+ 'parent_set_id' => $set_id,
641
+ 'field_id' => $field_to_remove
642
+ ),
643
+ array('%d', '%d')
644
+ );
645
 
646
+ $remove_values = $wpdb->delete(
647
+ YASR_MULTI_SET_VALUES_TABLE,
648
+ array(
649
+ 'set_type' => $set_id,
650
+ 'field_id' => $field_to_remove
651
+ ),
652
+ array('%d', '%d')
653
+ );
654
 
655
+ if ($remove_field == false) {
656
+ $error = true;
657
+ $array_errors[] = __("Something goes wrong trying to delete a Multi Set's element. Please report it", 'yet-another-stars-rating');
658
+ }
 
659
 
660
 
661
+ //Comment this out, will echo error even if the value for that field it's just empty
662
+ /*if ($remove_values == FALSE) {
663
+ $error = TRUE;
664
+ $array_errors[] = __("Something goes wrong trying to delete data value for an element. Please report it", 'yet-another-stars-rating');
665
+ }*/
666
 
667
 
668
+ } //End if isset $_POST['remove-element-$i']
 
669
 
 
670
 
671
+ //update the stored elements with the new ones
672
+ if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i <= $number_of_stored_elements) {
673
 
674
+ $field_name = $_POST["edit-multi-set-element-$i"];
 
 
 
 
675
 
676
+ $field_id = $_POST["db-id-for-element-$i"];
 
 
 
677
 
678
+ //if elements name is shorter than 3 chars
679
+ if (mb_strlen($field_name) < 3) {
680
+ $array_errors[] = __("Field # $i must be at least 3 characters", 'yet-another-stars-rating');
681
+ $error = true;
682
+ }
683
 
684
+ if (mb_strlen($field_name) > 40) {
685
+ $array_errors[] = __("Field # $i must be shorter than 40 characters", 'yet-another-stars-rating');
686
+ $error = true;
687
+ } else {
688
 
689
+ //Check if field name is changed
690
+ $field_name_in_db = $wpdb->get_results($wpdb->prepare("SELECT field_name FROM " . YASR_MULTI_SET_FIELDS_TABLE . " WHERE field_id=%d AND parent_set_id=%d", $field_id, $set_id));
 
691
 
692
+ foreach ($field_name_in_db as $field_in_db) {
693
+ $field_name_in_database = $field_in_db->field_name;
694
+ }
695
 
696
+ //if field name in db is different from field name in form update it
697
+ if ($field_name_in_database != $field_name) {
698
 
699
+ $insert_field_name = $wpdb->update(
700
+ YASR_MULTI_SET_FIELDS_TABLE,
 
701
 
702
+ array(
703
+ 'field_name' => $field_name,
704
+ ),
 
705
 
706
+ array(
707
+ 'parent_set_id' => $set_id,
708
+ 'field_id' => $field_id
709
+ ),
710
 
711
+ array('%s'),
712
 
713
+ array('%d', '%d')
714
 
715
+ );
 
 
 
716
 
717
+ if ($insert_field_name == false) {
718
+ $error = true;
719
+ $array_errors[] = __("Something goes wrong trying to update a Multi Set's element. Please report it", 'yet-another-stars-rating');
720
+ }
721
 
722
+ } //End if ($field_name_in_database != $field_name) {
723
 
724
+ }
725
 
726
+ } //End if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["remove-element-$i"]) && $i<=$number_of_stored_elements )
727
 
 
 
728
 
729
+ //If $i > number of stored elements, user is adding new elements, so we're going to insert the new ones
730
+ if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i > $number_of_stored_elements) {
731
 
732
+ $field_name = $_POST["edit-multi-set-element-$i"];
 
 
 
 
 
 
733
 
734
+ //if elements name is shorter than 3 chars return error. I use mb_strlen($field_name) > 1
735
+ //because I don't wont return error if an user add an empty field. An empty field will be
736
+ //just ignored
737
+ if (mb_strlen($field_name) > 1 && mb_strlen($field_name) < 3) {
738
+ $array_errors[] = __("Field # $i must be at least 3 characters", 'yet-another-stars-rating');
739
+ $error = true;
740
+ }
741
 
742
+ if (mb_strlen($field_name) > 40) {
743
+ $array_errors[] = __("Field # $i must be shorter than 40 characters", 'yet-another-stars-rating');
744
+ $error = true;
745
+ } //if field is not empty
746
+ elseif ($field_name != '') {
747
 
748
+ $highest_id = $wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
749
 
750
+ $highest_field_id = $wpdb->get_results("SELECT field_id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY field_id DESC LIMIT 1 ");
751
 
752
+ foreach ($highest_id as $id) {
753
+ $field_table_new_id = $id->id + 1;
754
+ }
755
 
756
+ foreach ($highest_field_id as $id) {
757
+ $new_field_id = $id->field_id + 1;
758
+ }
759
 
760
+ $insert_set_value = $wpdb->replace(
761
+ YASR_MULTI_SET_FIELDS_TABLE,
762
+ array(
763
+ 'id' => $field_table_new_id,
764
+ 'parent_set_id' => $set_id,
765
+ 'field_name' => $field_name,
766
+ 'field_id' => $new_field_id
767
+ ),
768
+ array('%d', '%d', '%s', '%d')
769
+ );
770
 
771
+ //now, I've to find which post is using the edited multi set and add the new field with value 0
772
 
773
+ //get the highest id
774
+ $highest_id_value_table = $wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_VALUES_TABLE . " ORDER BY id DESC LIMIT 1 ");
775
 
776
+ foreach ($highest_id_value_table as $id) {
777
+ $field_value_table_new_id = $id->id + 1;
778
+ }
779
 
780
+ //get all the post id that are using this multiset
781
+ $array_post_id = $wpdb->get_results($wpdb->prepare("SELECT post_id
782
  FROM " . YASR_MULTI_SET_VALUES_TABLE .
783
+ " WHERE set_type=%d
784
  GROUP BY post_id", $set_id));
785
 
786
+ //Insert the new fields
787
+ foreach ($array_post_id as $postid) {
788
 
789
+ $insert_new_field_values_table = $wpdb->insert(
790
+ YASR_MULTI_SET_VALUES_TABLE,
791
+ array(
792
+ 'id' => $field_value_table_new_id,
793
+ 'set_type' => $set_id,
794
+ 'field_id' => $new_field_id,
795
+ 'post_id' => $postid->post_id
796
+ ),
797
+ array('%d', '%d', '%d', '%d')
798
+ );
799
 
800
+ $field_value_table_new_id ++;
801
 
802
+ }
803
 
804
+ if ($insert_set_value == false) {
805
+ $error = true;
806
+ $array_errors[] = __("Something goes wrong trying to insert set field name in edit form. Please report it", 'yet-another-stars-rating');
807
+ }
808
 
809
+ } //end else
810
+ }
811
 
812
 
813
+ } //End for
814
 
815
 
816
+ if ($error) {
817
+ return $array_errors;
818
+ } else {
819
+ echo "<div class=\"updated\"><p><strong>";
820
+ _e("Settings Saved", 'yet-another-stars-rating');
821
+ echo "</strong></p></div> ";
822
+ }
 
823
 
824
 
825
+ } //End if isset( $_POST['yasr_edit_multi_set_form']
826
 
827
 
828
  } //End yasr_process_edit_multi_set_form() function
lib/admin/settings/yasr-settings-functions.php CHANGED
@@ -17,190 +17,78 @@ GNU General Public License for more details.
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
- if ( !defined( 'ABSPATH' ) ) {
21
- exit( 'You\'re not allowed to see this page' );
22
- }
23
- // Exit if accessed directly
24
- function yasr_settings_tabs( $active_tab )
25
- {
26
- ?>
27
-
28
- <h2 class="nav-tab-wrapper yasr-no-underline">
29
-
30
- <a href="?page=yasr_settings_page&tab=general_settings"
31
- class="nav-tab <?php
32
- if ( $active_tab === 'general_settings' ) {
33
- echo 'nav-tab-active' ;
34
- }
35
- ?>">
36
- <?php
37
- _e( "General Settings", 'yet-another-stars-rating' );
38
- ?>
39
- </a>
40
-
41
- <a href="?page=yasr_settings_page&tab=manage_multi" class="nav-tab <?php
42
- if ( $active_tab === 'manage_multi' ) {
43
- echo 'nav-tab-active' ;
44
- }
45
- ?>">
46
- <?php
47
- _e( "Multi Sets", 'yet-another-stars-rating' );
48
- ?>
49
- </a>
50
-
51
- <a href="?page=yasr_settings_page&tab=style_options"
52
- class="nav-tab <?php
53
- if ( $active_tab === 'style_options' ) {
54
- echo 'nav-tab-active' ;
55
- }
56
- ?>">
57
- <?php
58
- _e( "Aspect & Styles", 'yet-another-stars-rating' );
59
- ?>
60
- </a>
61
 
 
 
 
62
 
63
- <?php
64
- do_action( 'yasr_add_settings_tab', $active_tab );
65
- ?>
66
 
67
- </h2>
68
 
69
- <?php
70
- }
71
 
72
- /************ Add yasr general options ***********/
73
- add_action( 'admin_init', 'yasr_general_options_init' );
74
- //This is for general options
75
- function yasr_general_options_init()
76
- {
77
  register_setting(
78
- 'yasr_general_options_group',
79
- // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
80
- 'yasr_general_options',
81
- //The name of an option to sanitize and save.
82
  'yasr_general_options_sanitize'
83
  );
84
- $option = get_option( 'yasr_general_options' );
 
 
85
  //This is to avoid undefined offset
86
-
87
- if ( $option && $option['auto_insert_enabled'] == 0 ) {
88
- $option['auto_insert_what'] = 'overall_rating';
89
- $option['auto_insert_where'] = 'top';
90
- $option['auto_insert_exclude_pages'] = 'yes';
91
- $option['auto_insert_size'] = 'large';
92
  $option['auto_insert_custom_post_only'] = 'no';
93
  }
94
-
95
  //This is to avoid undefined offset
96
-
97
- if ( $option && $option['text_before_stars'] == 0 ) {
98
- $option['text_before_overall'] = '';
99
  $option['text_before_visitor_rating'] = '';
100
- $option['text_after_visitor_rating'] = '';
101
- $option['custom_text_user_voted'] = '';
102
- $option['custom_text_must_sign_in'] = '';
103
  }
104
-
105
  //if it's not blogposting avoid undefined variable
106
- if ( !isset( $option['blogposting_organization_name'] ) ) {
107
- $option['blogposting_organization_name'] = get_bloginfo( 'name' );
108
  }
109
- if ( !isset( $option['blogposting_organization_logo'] ) ) {
 
110
  $option['blogposting_organization_logo'] = get_site_icon_url();
111
  }
112
- add_settings_section(
113
- 'yasr_general_options_section_id',
114
- __( 'General settings', 'yet-another-stars-rating' ),
115
- 'yasr_section_callback',
116
- 'yasr_general_settings_tab'
117
- );
118
- add_settings_field(
119
- 'yasr_use_auto_insert_id',
120
- __( 'Auto insert options', 'yet-another-stars-rating' ),
121
- 'yasr_auto_insert_callback',
122
- 'yasr_general_settings_tab',
123
- 'yasr_general_options_section_id',
124
- $option
125
- );
126
- add_settings_field(
127
- 'yasr_custom_text',
128
- __( 'Insert custom text to show before / after stars', 'yet-another-stars-rating' ),
129
- 'yasr_custom_text_callback',
130
- 'yasr_general_settings_tab',
131
- 'yasr_general_options_section_id',
132
- $option
133
- );
134
- add_settings_field(
135
- 'yasr_show_overall_in_loop',
136
- __( 'Show "Overall Rating" in Archive Page?', 'yet-another-stars-rating' ),
137
- 'yasr_show_overall_in_loop_callback',
138
- 'yasr_general_settings_tab',
139
- 'yasr_general_options_section_id',
140
- $option
141
- );
142
- add_settings_field(
143
- 'yasr_show_visitor_votes_in_loop',
144
- __( 'Show "Visitor Votes" in Archive Page?', 'yet-another-stars-rating' ),
145
- 'yasr_show_visitor_votes_in_loop_callback',
146
- 'yasr_general_settings_tab',
147
- 'yasr_general_options_section_id',
148
- $option
149
- );
150
- add_settings_field(
151
- 'yasr_visitors_stats',
152
- __( 'Do you want show stats for visitors votes?', 'yet-another-stars-rating' ),
153
- 'yasr_visitors_stats_callback',
154
- 'yasr_general_settings_tab',
155
- 'yasr_general_options_section_id',
156
- $option
157
- );
158
- add_settings_field(
159
- 'yasr_allow_only_logged_in_id',
160
- __( 'Allow only logged in user to vote?', 'yet-another-stars-rating' ),
161
- 'yasr_allow_only_logged_in_callback',
162
- 'yasr_general_settings_tab',
163
- 'yasr_general_options_section_id',
164
- $option
165
- );
166
- add_settings_field(
167
- 'yasr_enable_ip',
168
- __( 'Do you want to save ip address?', 'yet-another-stars-rating' ),
169
- 'yasr_enable_ip_callback',
170
- 'yasr_general_settings_tab',
171
- 'yasr_general_options_section_id',
172
- $option
173
- );
174
- add_settings_field(
175
- 'yasr_choose_snippet_id',
176
- __( 'Rich snippet options', 'yet-another-stars-rating' ),
177
- 'yasr_choose_snippet_callback',
178
- 'yasr_general_settings_tab',
179
- 'yasr_general_options_section_id',
180
- $option
181
- );
182
  }
183
 
184
- function yasr_section_callback()
185
- {
186
  //_e('Manage auto insert', 'yet-another-stars-rating');
187
  }
188
 
189
- function yasr_auto_insert_callback( $option )
190
- {
191
  ?>
192
 
193
  <div>
194
- <strong><?php
195
- _e( 'Use Auto Insert?', 'yet-another-stars-rating' );
196
- ?></strong>
197
  <div class="yasr-onoffswitch-big">
198
  <input type="checkbox" name="yasr_general_options[auto_insert_enabled]" class="yasr-onoffswitch-checkbox"
199
- value="1" id="yasr_auto_insert_switch" <?php
200
- if ( $option['auto_insert_enabled'] == 1 ) {
201
- echo " checked='checked' " ;
202
- }
203
- ?> >
204
  <label class="yasr-onoffswitch-label" for="yasr_auto_insert_switch">
205
  <span class="yasr-onoffswitch-inner"></span>
206
  <span class="yasr-onoffswitch-switch"></span>
@@ -209,249 +97,184 @@ function yasr_auto_insert_callback( $option )
209
 
210
  <p>&nbsp;</p>
211
 
212
- <strong><?php
213
- _e( 'What?', 'yet-another-stars-rating' );
214
- ?></strong>
215
 
216
  <div class="yasr-indented-answer">
217
 
218
  <input type="radio" name="yasr_general_options[auto_insert_what]" value="overall_rating"
219
- class="yasr-auto-insert-options-class" <?php
220
- if ( $option['auto_insert_what'] === 'overall_rating' ) {
221
- echo " checked=\"checked\" " ;
222
- }
223
- ?> >
224
- <?php
225
- _e( 'Overall Rating / Author Rating', 'yet-another-stars-rating' );
226
- ?>
227
  <br/>
228
 
229
  <input type="radio" name="yasr_general_options[auto_insert_what]" value="visitor_rating"
230
- class="yasr-auto-insert-options-class" <?php
231
- if ( $option['auto_insert_what'] === 'visitor_rating' ) {
232
- echo " checked=\"checked\" " ;
233
- }
234
- ?> >
235
- <?php
236
- _e( 'Visitor Votes', 'yet-another-stars-rating' );
237
- ?>
238
  <br/>
239
 
240
  <input type="radio" name="yasr_general_options[auto_insert_what]" value="both"
241
- class="yasr-auto-insert-options-class" <?php
242
- if ( $option['auto_insert_what'] === 'both' ) {
243
- echo " checked=\"checked\" " ;
244
- }
245
- ?> >
246
- <?php
247
- _e( 'Both', 'yet-another-stars-rating' );
248
- ?>
249
 
250
  <p>&nbsp;</p>
251
 
252
  </div>
253
 
254
- <strong><?php
255
- _e( 'Where?', 'yet-another-stars-rating' );
256
- ?></strong>
257
 
258
  <div class="yasr-indented-answer">
259
 
260
  <input type="radio" name="yasr_general_options[auto_insert_where]" value="top"
261
- class="yasr-auto-insert-options-class" <?php
262
- if ( $option['auto_insert_where'] === 'top' ) {
263
- echo " checked=\"checked\" " ;
264
- }
265
- ?> >
266
- <?php
267
- _e( 'Before the post', 'yet-another-stars-rating' );
268
- ?>
269
  <br/>
270
 
271
  <input type="radio" name="yasr_general_options[auto_insert_where]" value="bottom"
272
- class="yasr-auto-insert-options-class" <?php
273
- if ( $option['auto_insert_where'] === 'bottom' ) {
274
- echo " checked=\"checked\" " ;
275
- }
276
- ?> >
277
- <?php
278
- _e( 'After the post', 'yet-another-stars-rating' );
279
- ?>
280
  <br/>
281
 
282
  <p>&nbsp;</p>
283
 
284
  </div>
285
 
286
- <strong><?php
287
- _e( 'Size', 'yet-another-stars-rating' );
288
- ?></strong>
289
 
290
  <div class="yasr-indented-answer">
291
 
292
  <div class="yasr-option-size">
293
  <input type="radio" name="yasr_general_options[auto_insert_size]" value="small"
294
- class="yasr-auto-insert-options-class" <?php
295
- if ( $option['auto_insert_size'] === 'small' ) {
296
- echo " checked=\"checked\" " ;
297
- }
298
- ?> >
299
- <img src="<?php
300
- echo YASR_IMG_DIR . "yasr-stars-small.png" ;
301
- ?>" class="yasr-img-option-size"><span
302
- class="yasr-text-options-size"><?php
303
- _e( 'Small', 'yet-another-stars-rating' );
304
- ?></span>
305
  </div>
306
 
307
  <div class="yasr-option-size">
308
  <input type="radio" name="yasr_general_options[auto_insert_size]" value="medium"
309
- class="yasr-auto-insert-options-class" <?php
310
- if ( $option['auto_insert_size'] === 'medium' ) {
311
- echo " checked=\"checked\" " ;
312
- }
313
- ?> >
314
- <img src="<?php
315
- echo YASR_IMG_DIR . "yasr-stars-medium.png" ;
316
- ?>" class="yasr-img-option-size"><span
317
- class="yasr-text-options-size"><?php
318
- _e( 'Medium', 'yet-another-stars-rating' );
319
- ?></span>
320
  </div>
321
 
322
  <div class="yasr-option-size">
323
  <input type="radio" name="yasr_general_options[auto_insert_size]" value="large"
324
- class="yasr-auto-insert-options-class" <?php
325
- if ( $option['auto_insert_size'] === 'large' ) {
326
- echo " checked=\"checked\" " ;
327
- }
328
- ?> >
329
- <img src="<?php
330
- echo YASR_IMG_DIR . "yasr-stars-large.png" ;
331
- ?>" class="yasr-img-option-size"><span
332
- class="yasr-text-options-size"><?php
333
- _e( 'Large', 'yet-another-stars-rating' );
334
- ?></span>
335
  </div>
336
 
337
  <p>&nbsp;</p>
338
 
339
  </div>
340
 
341
- <strong><?php
342
- _e( 'Exclude Pages?', 'yet-another-stars-rating' );
343
- ?></strong>
344
 
345
  <div class="yasr-indented-answer">
346
  <input type="radio" name="yasr_general_options[auto_insert_exclude_pages]" value="yes"
347
- class="yasr-auto-insert-options-class" <?php
348
- if ( $option['auto_insert_exclude_pages'] === 'yes' ) {
349
- echo " checked=\"checked\" " ;
350
- }
351
- ?> >
352
- <?php
353
- _e( 'Yes', 'yet-another-stars-rating' );
354
- ?>
355
 
356
  &nbsp;&nbsp;&nbsp;
357
 
358
  <input type="radio" name="yasr_general_options[auto_insert_exclude_pages]" value="no"
359
- class="yasr-auto-insert-options-class" <?php
360
- if ( $option['auto_insert_exclude_pages'] === 'no' ) {
361
- echo " checked=\"checked\" " ;
362
- }
363
- ?> >
364
- <?php
365
- _e( 'No', 'yet-another-stars-rating' );
366
- ?>
367
  <br/>
368
 
369
  <p>&nbsp;</p>
370
 
371
  </div>
372
 
373
- <?php
374
- $custom_post_types = yasr_get_custom_post_type( 'bool' );
375
-
376
- if ( $custom_post_types ) {
377
- ?>
378
- <strong><?php
379
- _e( 'Use only in custom post types?', 'yet-another-stars-rating' );
380
- ?></strong>
381
  <div class="yasr-indented-answer">
382
  <input type="radio" name="yasr_general_options[auto_insert_custom_post_only]" value="yes"
383
- class="yasr-auto-insert-options-class" <?php
384
- if ( $option['auto_insert_custom_post_only'] === 'yes' ) {
385
- echo " checked=\"checked\" " ;
386
- }
387
- ?> >
388
- <?php
389
- _e( 'Yes', 'yet-another-stars-rating' );
390
- ?>
391
 
392
  &nbsp;&nbsp;&nbsp;
393
 
394
  <input type="radio" name="yasr_general_options[auto_insert_custom_post_only]" value="no"
395
- class="yasr-auto-insert-options-class" <?php
396
- if ( $option['auto_insert_custom_post_only'] === 'no' ) {
397
- echo " checked=\"checked\" " ;
398
- }
399
- ?> >
400
- <?php
401
- _e( 'No', 'yet-another-stars-rating' );
402
- ?>
403
 
404
  <p>
405
 
406
- <?php
407
- _e( "You see this because you use custom post types.", 'yet-another-stars-rating' );
408
- ?>
409
  <br/>
410
- <?php
411
- _e( "If you want to use auto insert only in custom post types, choose Yes", 'yet-another-stars-rating' );
412
- ?>
413
 
414
  <p>&nbsp;</p>
415
 
416
  </div>
417
 
418
- <?php
419
- } else {
420
- ?>
 
 
421
  <input type="hidden" name="yasr_general_options[auto_insert_custom_post_only]" value="no" ?>
422
- <?php
423
- }
424
-
425
- ?>
426
 
427
- <?php
428
- submit_button( __( 'Save Settings' ) );
429
- ?>
 
 
 
 
430
 
431
  </div>
432
 
433
  <hr />
434
 
435
- <?php
436
- }
 
 
 
 
 
 
 
 
 
437
 
438
- //End yasr_auto_insert_callback
439
- function yasr_custom_text_callback( $option )
440
- {
441
- $text_before_overall = htmlspecialchars_decode( "{$option['text_before_overall']}" );
442
- $text_before_visitor_rating = htmlspecialchars_decode( "{$option['text_before_visitor_rating']}" );
443
- $text_after_visitor_rating = htmlspecialchars_decode( "{$option['text_after_visitor_rating']}" );
444
- $custom_text_user_votes = htmlspecialchars_decode( "{$option['custom_text_user_voted']}" );
445
- $custom_text_must_sign_in = htmlspecialchars_decode( "{$option['custom_text_must_sign_in']}" );
446
  ?>
447
 
448
  <div class="yasr-onoffswitch-big">
449
  <input type="checkbox" name="yasr_general_options[text_before_stars]" class="yasr-onoffswitch-checkbox"
450
- id="yasr-general-options-text-before-stars-switch" <?php
451
- if ( $option['text_before_stars'] == 1 ) {
452
- echo " checked='checked' " ;
453
- }
454
- ?> >
455
  <label class="yasr-onoffswitch-label" for="yasr-general-options-text-before-stars-switch">
456
  <span class="yasr-onoffswitch-inner"></span>
457
  <span class="yasr-onoffswitch-switch"></span>
@@ -462,102 +285,86 @@ function yasr_custom_text_callback( $option )
462
 
463
  <input type='text' name='yasr_general_options[text_before_overall]'
464
  id="yasr-general-options-custom-text-before-overall"
465
- class='yasr-general-options-text-before' <?php
466
- printf( 'value="%s"', $text_before_overall );
467
- ?>
468
  maxlength="40"/>
469
- <?php
470
- _e( 'Custom text to display before Overall Rating', 'yet-another-stars-rating' );
471
- ?>
472
 
473
  <br/> <br/> <br/>
474
 
475
  <input type='text' name='yasr_general_options[text_before_visitor_rating]'
476
  id="yasr-general-options-custom-text-before-visitor"
477
- class='yasr-general-options-text-before' <?php
478
- printf( 'value="%s"', $text_before_visitor_rating );
479
- ?>
480
  maxlength="80"/>
481
- <?php
482
- _e( 'Custom text to display BEFORE Visitor Rating', 'yet-another-stars-rating' );
483
- ?>
484
 
485
  <br/> <br/>
486
 
487
  <input type='text' name='yasr_general_options[text_after_visitor_rating]'
488
  id="yasr-general-options-custom-text-after-visitor"
489
- class='yasr-general-options-text-before' <?php
490
- printf( 'value="%s"', $text_after_visitor_rating );
491
- ?>
492
  maxlength="80"/>
493
- <?php
494
- _e( 'Custom text to display AFTER Visitor Rating', 'yet-another-stars-rating' );
495
- ?>
496
 
497
  <br/> <br/> <br/>
498
 
499
  <input type='text' name='yasr_general_options[custom_text_must_sign_in]'
500
  id="yasr-general-options-custom-text-must-sign-in"
501
- class='yasr-general-options-text-before' <?php
502
- printf( 'value="%s"', $custom_text_must_sign_in );
503
- ?>
504
  maxlength="60"/>
505
- <?php
506
- _e( 'Custom text to display when login is required to vote', 'yet-another-stars-rating' );
507
- ?>
508
 
509
  <br/> <br/>
510
 
511
  <input type='text' name='yasr_general_options[custom_text_user_voted]'
512
  id="yasr-general-options-custom-text-already-rated"
513
- class='yasr-general-options-text-before' <?php
514
- printf( 'value="%s"', $custom_text_user_votes );
515
- ?>
516
  maxlength="60"/>
517
- <?php
518
- _e( 'Custom text to display when a non logged user has already rated', 'yet-another-stars-rating' );
519
- ?>
520
 
521
 
522
  <br/> <br/>
523
 
524
- <a href="#" id="yasr-doc-custom-text-link"><?php
525
- _e( 'Help', 'yet-another-stars-rating' );
526
- ?></a>
527
 
528
  <div id="yasr-doc-custom-text-div" class="yasr-help-box-settings">
529
 
530
- <?php
531
- $string_custom_overall = sprintf( __( 'In the first field you can use %s pattern to show the overall rating.', 'yet-another-stars-rating' ), '<strong>%overall_rating%</strong>' );
532
- $string_custom_visitor = sprintf( __( 'In the Second and Third fields you can use %s pattern to show the
533
- total count, and %s pattern to show the average', 'yet-another-stars-rating' ), '<strong>%total_count%</strong>', '<strong>%average%</strong>' );
534
- echo $string_custom_overall ;
535
- echo '<br /><br/>' ;
536
- echo $string_custom_visitor ;
537
- echo '<br /><br/>' ;
538
- _e( 'You can use these html tags:', 'yet-another-stars-rating' );
539
- echo ' <strong>' . htmlspecialchars( '<strong>, <p>' ) . '.</strong>' ;
540
- ?>
 
 
 
 
 
 
541
 
542
  </div>
543
 
544
  <p>&nbsp;</p>
545
 
546
- <?php
547
- submit_button( __( 'Save Settings' ) );
 
 
548
  }
549
 
550
- function yasr_show_overall_in_loop_callback( $option )
551
- {
552
  ?>
553
 
554
  <div class="yasr-onoffswitch-big">
555
  <input type="checkbox" name="yasr_general_options[show_overall_in_loop]" class="yasr-onoffswitch-checkbox"
556
- id="yasr-show-overall-in-loop-switch" <?php
557
- if ( $option['show_overall_in_loop'] === 'enabled' ) {
558
- echo " checked='checked' " ;
559
- }
560
- ?> >
561
  <label class="yasr-onoffswitch-label" for="yasr-show-overall-in-loop-switch">
562
  <span class="yasr-onoffswitch-inner"></span>
563
  <span class="yasr-onoffswitch-switch"></span>
@@ -566,9 +373,7 @@ function yasr_show_overall_in_loop_callback( $option )
566
 
567
  <br/> <br/>
568
 
569
- <?php
570
- _e( 'If you enable this, "Overall Rating" will be showed not only in the single article or page, but also in pages like Home Page, category pages or archives.', 'yet-another-stars-rating' );
571
- ?>
572
 
573
  <p>&nbsp;</p>
574
 
@@ -576,20 +381,19 @@ function yasr_show_overall_in_loop_callback( $option )
576
 
577
  <hr>
578
 
579
- <?php
 
580
  }
581
 
582
- function yasr_show_visitor_votes_in_loop_callback( $option )
583
- {
584
  ?>
585
 
586
  <div class="yasr-onoffswitch-big">
587
  <input type="checkbox" name="yasr_general_options[show_visitor_votes_in_loop]" class="yasr-onoffswitch-checkbox"
588
- id="yasr-show-visitor-votes-in-loop-switch" <?php
589
- if ( $option['show_visitor_votes_in_loop'] === 'enabled' ) {
590
- echo " checked='checked' " ;
591
- }
592
- ?> >
593
  <label class="yasr-onoffswitch-label" for="yasr-show-visitor-votes-in-loop-switch">
594
  <span class="yasr-onoffswitch-inner"></span>
595
  <span class="yasr-onoffswitch-switch"></span>
@@ -598,9 +402,7 @@ function yasr_show_visitor_votes_in_loop_callback( $option )
598
 
599
  <br/> <br/>
600
 
601
- <?php
602
- _e( 'If you enable this, "Visitor Votes" will be showed not only in the single article or page, but also in pages like Home Page, category pages or archives.', 'yet-another-stars-rating' );
603
- ?>
604
 
605
  <p>&nbsp;</p>
606
 
@@ -608,20 +410,19 @@ function yasr_show_visitor_votes_in_loop_callback( $option )
608
 
609
  <hr>
610
 
611
- <?php
 
612
  }
613
 
614
- function yasr_visitors_stats_callback( $option )
615
- {
616
  ?>
617
 
618
  <div class="yasr-onoffswitch-big">
619
  <input type="checkbox" name="yasr_general_options[visitors_stats]" class="yasr-onoffswitch-checkbox"
620
- id="yasr-general-options-visitors-stats-switch" <?php
621
- if ( $option['visitors_stats'] === 'yes' ) {
622
- echo " checked='checked' " ;
623
- }
624
- ?> >
625
  <label class="yasr-onoffswitch-label" for="yasr-general-options-visitors-stats-switch">
626
  <span class="yasr-onoffswitch-inner"></span>
627
  <span class="yasr-onoffswitch-switch"></span>
@@ -634,55 +435,46 @@ function yasr_visitors_stats_callback( $option )
634
 
635
  <hr>
636
 
637
- <?php
 
638
  }
639
 
640
- function yasr_allow_only_logged_in_callback( $option )
641
- {
642
  ?>
643
 
644
  <input type='radio' name='yasr_general_options[allowed_user]' value='logged_only'
645
- class='yasr_auto_insert_loggedonly' <?php
646
- if ( $option['allowed_user'] === 'logged_only' ) {
647
- echo " checked=\"checked\" " ;
648
- }
649
- ?> />
650
- <?php
651
- _e( 'Allow only logged-in users', 'yet-another-stars-rating' );
652
- ?>
653
  <br/>
654
 
655
  <input type='radio' name='yasr_general_options[allowed_user]' value='allow_anonymous'
656
- class='yasr_auto_insert_loggedonly' <?php
657
- if ( $option['allowed_user'] === 'allow_anonymous' ) {
658
- echo " checked=\"checked\" " ;
659
- }
660
- ?> />
661
- <?php
662
- _e( 'Allow everybody (logged in and anonymous)', 'yet-another-stars-rating' );
663
- ?>
664
  <br/>
665
 
666
  <p>&nbsp;</p>
667
 
668
  <hr>
669
 
670
- <?php
671
- }
 
 
 
672
 
673
- //End function
674
- function yasr_enable_ip_callback( $option )
675
- {
676
  ?>
677
 
678
 
679
  <div class="yasr-onoffswitch-big">
680
  <input type="checkbox" name="yasr_general_options[enable_ip]" class="yasr-onoffswitch-checkbox"
681
- id="yasr-general-options-enable-ip-switch" <?php
682
- if ( $option['enable_ip'] === 'yes' ) {
683
- echo " checked='checked' " ;
684
- }
685
- ?> >
686
  <label class="yasr-onoffswitch-label" for="yasr-general-options-enable-ip-switch">
687
  <span class="yasr-onoffswitch-inner"></span>
688
  <span class="yasr-onoffswitch-switch"></span>
@@ -691,74 +483,69 @@ function yasr_enable_ip_callback( $option )
691
 
692
  <br/>
693
 
694
- <?php
 
695
  $string = sprintf(
696
- __( 'Please note that to comply with the %s EU law, you %s MUST %s warn your users that you\'re storing their ip. %s
697
- If in doubt, leave no.', 'yet-another-stars-rating' ),
698
- '<a href="https://en.wikipedia.org/wiki/General_Data_Protection_Regulation">GDPR</a>',
699
- '<strong>',
700
- '</strong>',
701
- '<br />'
702
  );
703
- echo $string ;
 
 
704
  ?>
705
 
706
  <br/>
707
 
708
  <hr>
709
 
710
- <?php
711
- }
 
 
 
712
 
713
- //End function
714
- function yasr_choose_snippet_callback( $option )
715
- {
716
  $blogposting_organization_name = $option['blogposting_organization_name'];
717
  $blogposting_organization_logo = $option['blogposting_organization_logo'];
 
718
  ?>
719
 
720
- <strong><?php
721
- _e( 'Which rich snippet do you want to use?', 'yet-another-stars-rating' );
722
- ?></strong>
723
 
724
  <div class="yasr-indented-answer">
725
  <input type="radio" name="yasr_general_options[snippet]" value="overall_rating"
726
- class="yasr_choose_snippet" <?php
727
- if ( $option['snippet'] === 'overall_rating' ) {
728
- echo " checked=\"checked\" " ;
729
- }
730
- ?> >
731
- <?php
732
- _e( 'Review Rating', 'yet-another-stars-rating' );
733
- ?>
734
  <br/>
735
 
736
  <input type="radio" name="yasr_general_options[snippet]" value="visitor_rating"
737
- class="yasr_choose_snippet" <?php
738
- if ( $option['snippet'] === 'visitor_rating' ) {
739
- echo " checked=\"checked\" " ;
740
- }
741
- ?> >
742
- <?php
743
- _e( 'Aggregate Rating', 'yet-another-stars-rating' );
744
- ?>
745
  <br/>
746
 
747
  <p>&nbsp;</p>
748
 
749
- <a href="#" id="yasr-snippet-explained-link"><?php
750
- _e( "What is this?", 'yet-another-stars-rating' );
751
- ?></a>
752
 
753
  <div id="yasr-snippet-explained" class="yasr-help-box-settings">
754
- <?php
755
- _e( 'If you select "Review Rating", rating average is get from yasr_overall_rating shortcode.
756
- Your site will be indexed from search engines like this: ', 'yet-another-stars-rating' );
757
- echo "<br /><br /><img src=" . YASR_IMG_DIR . "yasr_review.png>" ;
758
- echo "<br /> <br />" ;
759
- _e( 'If, instead, you choose "Aggregate Rating", your site will be indexed like this', 'yet-another-stars-rating' );
760
- echo "<br /><br /><img src=" . YASR_IMG_DIR . "yasr_aggregate.jpg>" ;
761
- ?>
 
 
 
762
  </div>
763
 
764
  </div>
@@ -767,99 +554,67 @@ function yasr_choose_snippet_callback( $option )
767
 
768
  <br/>
769
 
770
- <strong><?php
771
- _e( 'Select default item type for all post or pages', 'yet-another-stars-rating' );
772
- ?></strong>
773
 
774
  <div class="yasr-indented-answer" id="yasr-choose-snippet-type">
775
 
776
  <input type="radio" name="yasr_general_options[snippet_itemtype]" value="Product"
777
- class="yasr_choose_snippet" <?php
778
- if ( $option['snippet_itemtype'] === 'Product' ) {
779
- echo " checked=\"checked\" " ;
780
- }
781
- ?> >
782
- <?php
783
- _e( 'Product', 'yet-another-stars-rating' );
784
- ?>
785
  <br/>
786
 
787
  <input type="radio" name="yasr_general_options[snippet_itemtype]" value="Place"
788
- class="yasr_choose_snippet" <?php
789
- if ( $option['snippet_itemtype'] === 'Place' ) {
790
- echo " checked=\"checked\" " ;
791
- }
792
- ?> >
793
- <?php
794
- _e( 'Place', 'yet-another-stars-rating' );
795
- ?>
796
  <br/>
797
 
798
  <input type="radio" name="yasr_general_options[snippet_itemtype]" value="Recipe"
799
- class="yasr_choose_snippet" <?php
800
- if ( $option['snippet_itemtype'] === 'Recipe' ) {
801
- echo " checked=\"checked\" " ;
802
- }
803
- ?> >
804
- <?php
805
- _e( 'Recipe', 'yet-another-stars-rating' );
806
- ?>
807
  <br/>
808
 
809
  <input type="radio" name="yasr_general_options[snippet_itemtype]" value="Other" class="yasr_choose_snippet"
810
- id="yasr_choose_snippet_blogposting" <?php
811
- if ( $option['snippet_itemtype'] === 'Other' ) {
812
- echo " checked=\"checked\" " ;
813
- }
814
- ?> >
815
- <?php
816
- _e( 'BlogPosting' );
817
- ?>
818
  <br/>
819
 
820
 
821
  <div class="yasr-help-box-settings" id="yasr-blogPosting-additional-info" style="display:block">
822
 
823
- <?php
824
- _e( "If you need to use BlogPosting as item type, even for just one post or page, please fill these forms", "yet-another-stars-rating" );
825
- ?>
826
 
827
  <br/> <br/>
828
 
829
  <input type='text' name='yasr_general_options[blogposting_organization_name]'
830
  id="yasr-general-options-blogposting-organization-name"
831
- class="yasr-blogPosting-additional-info-inputs" <?php
832
- printf( 'value="%s"', $blogposting_organization_name );
833
- ?>
834
  maxlength="180"/>
835
- <?php
836
- _e( 'Publisher name (e.g. Google)', 'yet-another-stars-rating' );
837
- ?>
838
 
839
  <br/> <br/>
840
 
841
  <input type='text' name='yasr_general_options[blogposting_organization_logo]'
842
  id="yasr-general-options-blogposting-organization-logo"
843
- class="yasr-blogPosting-additional-info-inputs" <?php
844
- printf( 'value="%s"', $blogposting_organization_logo );
845
- ?>
846
  maxlength="300"/>
847
- <?php
848
- _e( 'Logo Url (if empty siteicon will be used instead)', 'yet-another-stars-rating' );
849
- ?>
850
 
851
  </div>
852
 
853
 
854
  <br/>
855
 
856
- <small><?php
857
- _e( 'You can always change it in the single post or page.', 'yet-another-stars-rating' );
858
- ?></small>
859
  <br/>
860
- <small><?php
861
- _e( 'This will affect only the post/page where you didn\'t change manually the itemtype yet.', 'yet-another-stars-rating' );
862
- ?> </small>
863
 
864
  <p>&nbsp;</p>
865
 
@@ -868,113 +623,140 @@ function yasr_choose_snippet_callback( $option )
868
 
869
  <p>&nbsp;</p>
870
 
871
- <?php
872
- }
 
 
 
873
 
874
- //End function yasr_choose_snippet_callback
875
- function yasr_general_options_sanitize( $option )
876
- {
877
  //Array to return
878
  $output = array();
 
879
  $tidy_installed = false;
880
- if ( extension_loaded( 'tidy' ) ) {
 
881
  $tidy_installed = true;
882
  }
 
883
  // Loop through each of the incoming options
884
- foreach ( $option as $key => $value ) {
885
  // Check to see if the current option has a value. If so, process it.
886
-
887
- if ( isset( $option[$key] ) ) {
888
  //Tags are not allowed for any fields
889
  $allowed_tags = '';
 
890
  //except these ones
891
-
892
- if ( $key == 'text_before_overall' || $key == 'text_before_visitor_rating' || $key == 'text_after_visitor_rating' || $key == 'custom_text_must_sign_in' || $key == 'custom_text_user_voted' ) {
 
 
893
  $allowed_tags = '<strong><p>';
 
894
  // handle quoted strings and allow some tags
895
- $output[$key] = strip_tags( stripslashes( $option[$key] ), $allowed_tags );
 
896
  //if tidy extension is enabled, fix errors in html
897
-
898
- if ( $tidy_installed === true ) {
899
- $tidy = new Tidy();
900
- $output[$key] = $tidy->repairString( $output[$key], array(
901
- 'show-body-only' => true,
902
- ) );
903
  }
904
-
905
- } else {
 
906
  // handle quoted strings and allow no tags
907
- $output[$key] = strip_tags( stripslashes( $option[$key] ), $allowed_tags );
908
  }
909
-
910
  //Always use htmlspecialchars
911
- $output[$key] = htmlspecialchars( $output[$key] );
912
- if ( $key == 'blogposting_organization_logo' ) {
 
913
  //if is not a valid url get_site_icon_url instead
914
- if ( filter_var( $value, FILTER_VALIDATE_URL ) === false ) {
915
  $output[$key] = get_site_icon_url();
916
  }
917
  }
918
- }
919
-
920
- // end if
921
- }
922
- // end foreach
923
  //if in array doesn't exists [auto_insert_enabled] key, create it and set to 0
924
-
925
- if ( !array_key_exists( 'auto_insert_enabled', $output ) ) {
926
  $output['auto_insert_enabled'] = 0;
927
- } else {
 
 
928
  $output['auto_insert_enabled'] = 1;
929
  }
930
-
 
931
  //Same as above but for [show_overall_in_loop] key
932
-
933
- if ( !array_key_exists( 'show_overall_in_loop', $output ) ) {
934
  $output['show_overall_in_loop'] = 'disabled';
935
- } else {
 
 
936
  $output['show_overall_in_loop'] = 'enabled';
937
  }
938
-
 
939
  //Same as above but for [show_visitor_votes_in_loop] key
940
-
941
- if ( !array_key_exists( 'show_visitor_votes_in_loop', $output ) ) {
942
  $output['show_visitor_votes_in_loop'] = 'disabled';
943
- } else {
 
 
944
  $output['show_visitor_votes_in_loop'] = 'enabled';
945
  }
946
-
947
  //Same as above but for text_before_stars key
948
-
949
- if ( !array_key_exists( 'text_before_stars', $output ) ) {
950
  $output['text_before_stars'] = 0;
951
- } else {
 
 
952
  $output['text_before_stars'] = 1;
953
  }
954
-
955
  //Same as above but for visitors_stats key
956
-
957
- if ( !array_key_exists( 'visitors_stats', $output ) ) {
958
  $output['visitors_stats'] = 'no';
959
- } else {
 
 
960
  $output['visitors_stats'] = 'yes';
961
  }
962
-
963
  //Same as above but for enable_ip key
964
-
965
- if ( !array_key_exists( 'enable_ip', $output ) ) {
966
  $output['enable_ip'] = 'no';
967
- } else {
 
 
968
  $output['enable_ip'] = 'yes';
969
  }
970
-
971
  return $output;
 
972
  }
973
 
 
974
  /************ End Yasr General Settings ************/
 
 
975
  //include multiset functions
976
- include YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions-multiset.php';
 
977
  //include style functions
978
- include YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions-style.php';
 
979
  //Misc
980
- include YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions-misc.php';
 
 
 
 
 
 
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
+ /************ Add yasr general options ***********/
 
 
26
 
27
+ add_action('admin_init', 'yasr_general_options_init'); //This is for general options
28
 
29
+ function yasr_general_options_init() {
 
30
 
 
 
 
 
 
31
  register_setting(
32
+ 'yasr_general_options_group', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
33
+ 'yasr_general_options', //The name of an option to sanitize and save.
 
 
34
  'yasr_general_options_sanitize'
35
  );
36
+
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'] = 'overall_rating';
42
+ $option['auto_insert_where'] = 'top';
43
+ $option['auto_insert_exclude_pages'] = 'yes';
44
+ $option['auto_insert_size'] = 'large';
 
45
  $option['auto_insert_custom_post_only'] = 'no';
46
  }
47
+
48
  //This is to avoid undefined offset
49
+ if ($option && $option['text_before_stars'] == 0) {
50
+ $option['text_before_overall'] = '';
 
51
  $option['text_before_visitor_rating'] = '';
52
+ $option['text_after_visitor_rating'] = '';
53
+ $option['custom_text_user_voted'] = '';
54
+ $option['custom_text_must_sign_in'] = '';
55
  }
56
+
57
  //if it's not blogposting avoid undefined variable
58
+ if (!isset($option['blogposting_organization_name'])) {
59
+ $option['blogposting_organization_name'] = get_bloginfo('name');
60
  }
61
+
62
+ if (!isset($option['blogposting_organization_logo'])) {
63
  $option['blogposting_organization_logo'] = get_site_icon_url();
64
  }
65
+
66
+ add_settings_section('yasr_general_options_section_id', __('General settings', 'yet-another-stars-rating'), 'yasr_section_callback', 'yasr_general_settings_tab');
67
+ add_settings_field('yasr_use_auto_insert_id', __('Auto insert options', 'yet-another-stars-rating'), 'yasr_auto_insert_callback', 'yasr_general_settings_tab', 'yasr_general_options_section_id', $option);
68
+ add_settings_field('yasr_custom_text', __('Insert custom text to show before / after stars', 'yet-another-stars-rating'), 'yasr_custom_text_callback', 'yasr_general_settings_tab', 'yasr_general_options_section_id', $option);
69
+ add_settings_field('yasr_show_overall_in_loop', __('Show "Overall Rating" in Archive Page?', 'yet-another-stars-rating'), 'yasr_show_overall_in_loop_callback', 'yasr_general_settings_tab', 'yasr_general_options_section_id', $option);
70
+ add_settings_field('yasr_show_visitor_votes_in_loop', __('Show "Visitor Votes" in Archive Page?', 'yet-another-stars-rating'), 'yasr_show_visitor_votes_in_loop_callback', 'yasr_general_settings_tab', 'yasr_general_options_section_id', $option);
71
+ add_settings_field('yasr_visitors_stats', __('Do you want show stats for visitors votes?', 'yet-another-stars-rating'), 'yasr_visitors_stats_callback', 'yasr_general_settings_tab', 'yasr_general_options_section_id', $option);
72
+ add_settings_field('yasr_allow_only_logged_in_id', __('Allow only logged in user to vote?', 'yet-another-stars-rating'), 'yasr_allow_only_logged_in_callback', 'yasr_general_settings_tab', 'yasr_general_options_section_id', $option);
73
+ add_settings_field('yasr_enable_ip', __('Do you want to save ip address?', 'yet-another-stars-rating'), 'yasr_enable_ip_callback', 'yasr_general_settings_tab', 'yasr_general_options_section_id', $option);
74
+ add_settings_field('yasr_choose_snippet_id', __('Rich snippet options', 'yet-another-stars-rating'), 'yasr_choose_snippet_callback', 'yasr_general_settings_tab', 'yasr_general_options_section_id', $option);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  }
76
 
77
+ function yasr_section_callback() {
 
78
  //_e('Manage auto insert', 'yet-another-stars-rating');
79
  }
80
 
81
+ function yasr_auto_insert_callback($option) {
82
+
83
  ?>
84
 
85
  <div>
86
+ <strong><?php _e('Use Auto Insert?', 'yet-another-stars-rating'); ?></strong>
 
 
87
  <div class="yasr-onoffswitch-big">
88
  <input type="checkbox" name="yasr_general_options[auto_insert_enabled]" class="yasr-onoffswitch-checkbox"
89
+ value="1" id="yasr_auto_insert_switch" <?php if ($option['auto_insert_enabled'] == 1) {
90
+ echo " checked='checked' ";
91
+ } ?> >
 
 
92
  <label class="yasr-onoffswitch-label" for="yasr_auto_insert_switch">
93
  <span class="yasr-onoffswitch-inner"></span>
94
  <span class="yasr-onoffswitch-switch"></span>
97
 
98
  <p>&nbsp;</p>
99
 
100
+ <strong><?php _e('What?', 'yet-another-stars-rating'); ?></strong>
 
 
101
 
102
  <div class="yasr-indented-answer">
103
 
104
  <input type="radio" name="yasr_general_options[auto_insert_what]" value="overall_rating"
105
+ class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_what'] === 'overall_rating') {
106
+ echo " checked=\"checked\" ";
107
+ } ?> >
108
+ <?php _e('Overall Rating / Author Rating', 'yet-another-stars-rating') ?>
 
 
 
 
109
  <br/>
110
 
111
  <input type="radio" name="yasr_general_options[auto_insert_what]" value="visitor_rating"
112
+ class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_what'] === 'visitor_rating') {
113
+ echo " checked=\"checked\" ";
114
+ } ?> >
115
+ <?php _e('Visitor Votes', 'yet-another-stars-rating') ?>
 
 
 
 
116
  <br/>
117
 
118
  <input type="radio" name="yasr_general_options[auto_insert_what]" value="both"
119
+ class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_what'] === 'both') {
120
+ echo " checked=\"checked\" ";
121
+ } ?> >
122
+ <?php _e('Both', 'yet-another-stars-rating') ?>
 
 
 
 
123
 
124
  <p>&nbsp;</p>
125
 
126
  </div>
127
 
128
+ <strong><?php _e('Where?', 'yet-another-stars-rating'); ?></strong>
 
 
129
 
130
  <div class="yasr-indented-answer">
131
 
132
  <input type="radio" name="yasr_general_options[auto_insert_where]" value="top"
133
+ class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_where'] === 'top') {
134
+ echo " checked=\"checked\" ";
135
+ } ?> >
136
+ <?php _e('Before the post', 'yet-another-stars-rating') ?>
 
 
 
 
137
  <br/>
138
 
139
  <input type="radio" name="yasr_general_options[auto_insert_where]" value="bottom"
140
+ class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_where'] === 'bottom') {
141
+ echo " checked=\"checked\" ";
142
+ } ?> >
143
+ <?php _e('After the post', 'yet-another-stars-rating') ?>
 
 
 
 
144
  <br/>
145
 
146
  <p>&nbsp;</p>
147
 
148
  </div>
149
 
150
+ <strong><?php _e('Size', 'yet-another-stars-rating'); ?></strong>
 
 
151
 
152
  <div class="yasr-indented-answer">
153
 
154
  <div class="yasr-option-size">
155
  <input type="radio" name="yasr_general_options[auto_insert_size]" value="small"
156
+ class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_size'] === 'small') {
157
+ echo " checked=\"checked\" ";
158
+ } ?> >
159
+ <img src="<?php echo YASR_IMG_DIR . "yasr-stars-small.png" ?>" class="yasr-img-option-size"><span
160
+ class="yasr-text-options-size"><?php _e('Small', 'yet-another-stars-rating') ?></span>
 
 
 
 
 
 
161
  </div>
162
 
163
  <div class="yasr-option-size">
164
  <input type="radio" name="yasr_general_options[auto_insert_size]" value="medium"
165
+ class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_size'] === 'medium') {
166
+ echo " checked=\"checked\" ";
167
+ } ?> >
168
+ <img src="<?php echo YASR_IMG_DIR . "yasr-stars-medium.png" ?>" class="yasr-img-option-size"><span
169
+ class="yasr-text-options-size"><?php _e('Medium', 'yet-another-stars-rating') ?></span>
 
 
 
 
 
 
170
  </div>
171
 
172
  <div class="yasr-option-size">
173
  <input type="radio" name="yasr_general_options[auto_insert_size]" value="large"
174
+ class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_size'] === 'large') {
175
+ echo " checked=\"checked\" ";
176
+ } ?> >
177
+ <img src="<?php echo YASR_IMG_DIR . "yasr-stars-large.png" ?>" class="yasr-img-option-size"><span
178
+ class="yasr-text-options-size"><?php _e('Large', 'yet-another-stars-rating') ?></span>
 
 
 
 
 
 
179
  </div>
180
 
181
  <p>&nbsp;</p>
182
 
183
  </div>
184
 
185
+ <strong><?php _e('Exclude Pages?', 'yet-another-stars-rating'); ?></strong>
 
 
186
 
187
  <div class="yasr-indented-answer">
188
  <input type="radio" name="yasr_general_options[auto_insert_exclude_pages]" value="yes"
189
+ class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_exclude_pages'] === 'yes') {
190
+ echo " checked=\"checked\" ";
191
+ } ?> >
192
+ <?php _e('Yes', 'yet-another-stars-rating'); ?>
 
 
 
 
193
 
194
  &nbsp;&nbsp;&nbsp;
195
 
196
  <input type="radio" name="yasr_general_options[auto_insert_exclude_pages]" value="no"
197
+ class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_exclude_pages'] === 'no') {
198
+ echo " checked=\"checked\" ";
199
+ } ?> >
200
+ <?php _e('No', 'yet-another-stars-rating'); ?>
 
 
 
 
201
  <br/>
202
 
203
  <p>&nbsp;</p>
204
 
205
  </div>
206
 
207
+ <?php
208
+
209
+ $custom_post_types = yasr_get_custom_post_type('bool');
210
+
211
+ if ($custom_post_types) { ?>
212
+ <strong><?php _e('Use only in custom post types?', 'yet-another-stars-rating'); ?></strong>
 
 
213
  <div class="yasr-indented-answer">
214
  <input type="radio" name="yasr_general_options[auto_insert_custom_post_only]" value="yes"
215
+ class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_custom_post_only'] === 'yes') {
216
+ echo " checked=\"checked\" ";
217
+ } ?> >
218
+ <?php _e('Yes', 'yet-another-stars-rating'); ?>
 
 
 
 
219
 
220
  &nbsp;&nbsp;&nbsp;
221
 
222
  <input type="radio" name="yasr_general_options[auto_insert_custom_post_only]" value="no"
223
+ class="yasr-auto-insert-options-class" <?php if ($option['auto_insert_custom_post_only'] === 'no') {
224
+ echo " checked=\"checked\" ";
225
+ } ?> >
226
+ <?php _e('No', 'yet-another-stars-rating'); ?>
 
 
 
 
227
 
228
  <p>
229
 
230
+ <?php _e("You see this because you use custom post types.", 'yet-another-stars-rating'); ?>
 
 
231
  <br/>
232
+ <?php _e("If you want to use auto insert only in custom post types, choose Yes", 'yet-another-stars-rating'); ?>
 
 
233
 
234
  <p>&nbsp;</p>
235
 
236
  </div>
237
 
238
+ <?php
239
+ }
240
+
241
+ else {
242
+ ?>
243
  <input type="hidden" name="yasr_general_options[auto_insert_custom_post_only]" value="no" ?>
244
+ <?php
245
+ }
 
 
246
 
247
+ ?>
248
+
249
+ <?php
250
+
251
+ submit_button(__('Save Settings'));
252
+
253
+ ?>
254
 
255
  </div>
256
 
257
  <hr />
258
 
259
+ <?php
260
+
261
+ } //End yasr_auto_insert_callback
262
+
263
+ function yasr_custom_text_callback($option) {
264
+
265
+ $text_before_overall = htmlspecialchars_decode("$option[text_before_overall]");
266
+ $text_before_visitor_rating = htmlspecialchars_decode("$option[text_before_visitor_rating]");
267
+ $text_after_visitor_rating = htmlspecialchars_decode("$option[text_after_visitor_rating]");
268
+ $custom_text_user_votes = htmlspecialchars_decode("$option[custom_text_user_voted]");
269
+ $custom_text_must_sign_in = htmlspecialchars_decode("$option[custom_text_must_sign_in]");
270
 
 
 
 
 
 
 
 
 
271
  ?>
272
 
273
  <div class="yasr-onoffswitch-big">
274
  <input type="checkbox" name="yasr_general_options[text_before_stars]" class="yasr-onoffswitch-checkbox"
275
+ id="yasr-general-options-text-before-stars-switch" <?php if ($option['text_before_stars'] == 1) {
276
+ echo " checked='checked' ";
277
+ } ?> >
 
 
278
  <label class="yasr-onoffswitch-label" for="yasr-general-options-text-before-stars-switch">
279
  <span class="yasr-onoffswitch-inner"></span>
280
  <span class="yasr-onoffswitch-switch"></span>
285
 
286
  <input type='text' name='yasr_general_options[text_before_overall]'
287
  id="yasr-general-options-custom-text-before-overall"
288
+ class='yasr-general-options-text-before' <?php printf('value="%s"', $text_before_overall); ?>
 
 
289
  maxlength="40"/>
290
+ <?php _e('Custom text to display before Overall Rating', 'yet-another-stars-rating') ?>
 
 
291
 
292
  <br/> <br/> <br/>
293
 
294
  <input type='text' name='yasr_general_options[text_before_visitor_rating]'
295
  id="yasr-general-options-custom-text-before-visitor"
296
+ class='yasr-general-options-text-before' <?php printf('value="%s"', $text_before_visitor_rating); ?>
 
 
297
  maxlength="80"/>
298
+ <?php _e('Custom text to display BEFORE Visitor Rating', 'yet-another-stars-rating') ?>
 
 
299
 
300
  <br/> <br/>
301
 
302
  <input type='text' name='yasr_general_options[text_after_visitor_rating]'
303
  id="yasr-general-options-custom-text-after-visitor"
304
+ class='yasr-general-options-text-before' <?php printf('value="%s"', $text_after_visitor_rating); ?>
 
 
305
  maxlength="80"/>
306
+ <?php _e('Custom text to display AFTER Visitor Rating', 'yet-another-stars-rating') ?>
 
 
307
 
308
  <br/> <br/> <br/>
309
 
310
  <input type='text' name='yasr_general_options[custom_text_must_sign_in]'
311
  id="yasr-general-options-custom-text-must-sign-in"
312
+ class='yasr-general-options-text-before' <?php printf('value="%s"', $custom_text_must_sign_in); ?>
 
 
313
  maxlength="60"/>
314
+ <?php _e('Custom text to display when login is required to vote', 'yet-another-stars-rating') ?>
 
 
315
 
316
  <br/> <br/>
317
 
318
  <input type='text' name='yasr_general_options[custom_text_user_voted]'
319
  id="yasr-general-options-custom-text-already-rated"
320
+ class='yasr-general-options-text-before' <?php printf('value="%s"', $custom_text_user_votes); ?>
 
 
321
  maxlength="60"/>
322
+ <?php _e('Custom text to display when a non logged user has already rated', 'yet-another-stars-rating') ?>
 
 
323
 
324
 
325
  <br/> <br/>
326
 
327
+ <a href="#" id="yasr-doc-custom-text-link"><?php _e('Help', 'yet-another-stars-rating'); ?></a>
 
 
328
 
329
  <div id="yasr-doc-custom-text-div" class="yasr-help-box-settings">
330
 
331
+ <?php
332
+ $string_custom_overall = sprintf(__('In the first field you can use %s pattern to show the overall rating.',
333
+ 'yet-another-stars-rating'), '<strong>%overall_rating%</strong>');
334
+
335
+ $string_custom_visitor = sprintf(__('In the Second and Third fields you can use %s pattern to show the
336
+ total count, and %s pattern to show the average', 'yet-another-stars-rating'),
337
+ '<strong>%total_count%</strong>', '<strong>%average%</strong>');
338
+
339
+ echo $string_custom_overall;
340
+ echo '<br /><br/>';
341
+ echo $string_custom_visitor;
342
+ echo '<br /><br/>';
343
+
344
+ _e('You can use these html tags:', 'yet-another-stars-rating');
345
+ echo ' <strong>' . htmlspecialchars('<strong>, <p>') . '.</strong>';
346
+
347
+ ?>
348
 
349
  </div>
350
 
351
  <p>&nbsp;</p>
352
 
353
+ <?php
354
+
355
+ submit_button(__('Save Settings'));
356
+
357
  }
358
 
359
+ function yasr_show_overall_in_loop_callback($option) {
360
+
361
  ?>
362
 
363
  <div class="yasr-onoffswitch-big">
364
  <input type="checkbox" name="yasr_general_options[show_overall_in_loop]" class="yasr-onoffswitch-checkbox"
365
+ id="yasr-show-overall-in-loop-switch" <?php if ($option['show_overall_in_loop'] === 'enabled') {
366
+ echo " checked='checked' ";
367
+ } ?> >
 
 
368
  <label class="yasr-onoffswitch-label" for="yasr-show-overall-in-loop-switch">
369
  <span class="yasr-onoffswitch-inner"></span>
370
  <span class="yasr-onoffswitch-switch"></span>
373
 
374
  <br/> <br/>
375
 
376
+ <?php _e('If you enable this, "Overall Rating" will be showed not only in the single article or page, but also in pages like Home Page, category pages or archives.', 'yet-another-stars-rating') ?>
 
 
377
 
378
  <p>&nbsp;</p>
379
 
381
 
382
  <hr>
383
 
384
+ <?php
385
+
386
  }
387
 
388
+ function yasr_show_visitor_votes_in_loop_callback($option) {
389
+
390
  ?>
391
 
392
  <div class="yasr-onoffswitch-big">
393
  <input type="checkbox" name="yasr_general_options[show_visitor_votes_in_loop]" class="yasr-onoffswitch-checkbox"
394
+ id="yasr-show-visitor-votes-in-loop-switch" <?php if ($option['show_visitor_votes_in_loop'] === 'enabled') {
395
+ echo " checked='checked' ";
396
+ } ?> >
 
 
397
  <label class="yasr-onoffswitch-label" for="yasr-show-visitor-votes-in-loop-switch">
398
  <span class="yasr-onoffswitch-inner"></span>
399
  <span class="yasr-onoffswitch-switch"></span>
402
 
403
  <br/> <br/>
404
 
405
+ <?php _e('If you enable this, "Visitor Votes" will be showed not only in the single article or page, but also in pages like Home Page, category pages or archives.', 'yet-another-stars-rating') ?>
 
 
406
 
407
  <p>&nbsp;</p>
408
 
410
 
411
  <hr>
412
 
413
+ <?php
414
+
415
  }
416
 
417
+ function yasr_visitors_stats_callback($option) {
418
+
419
  ?>
420
 
421
  <div class="yasr-onoffswitch-big">
422
  <input type="checkbox" name="yasr_general_options[visitors_stats]" class="yasr-onoffswitch-checkbox"
423
+ id="yasr-general-options-visitors-stats-switch" <?php if ($option['visitors_stats'] === 'yes') {
424
+ echo " checked='checked' ";
425
+ } ?> >
 
 
426
  <label class="yasr-onoffswitch-label" for="yasr-general-options-visitors-stats-switch">
427
  <span class="yasr-onoffswitch-inner"></span>
428
  <span class="yasr-onoffswitch-switch"></span>
435
 
436
  <hr>
437
 
438
+ <?php
439
+
440
  }
441
 
442
+ function yasr_allow_only_logged_in_callback($option) {
443
+
444
  ?>
445
 
446
  <input type='radio' name='yasr_general_options[allowed_user]' value='logged_only'
447
+ class='yasr_auto_insert_loggedonly' <?php if ($option['allowed_user'] === 'logged_only') {
448
+ echo " checked=\"checked\" ";
449
+ } ?> />
450
+ <?php _e('Allow only logged-in users', 'yet-another-stars-rating') ?>
 
 
 
 
451
  <br/>
452
 
453
  <input type='radio' name='yasr_general_options[allowed_user]' value='allow_anonymous'
454
+ class='yasr_auto_insert_loggedonly' <?php if ($option['allowed_user'] === 'allow_anonymous') {
455
+ echo " checked=\"checked\" ";
456
+ } ?> />
457
+ <?php _e('Allow everybody (logged in and anonymous)', 'yet-another-stars-rating') ?>
 
 
 
 
458
  <br/>
459
 
460
  <p>&nbsp;</p>
461
 
462
  <hr>
463
 
464
+ <?php
465
+
466
+ } //End function
467
+
468
+ function yasr_enable_ip_callback($option) {
469
 
 
 
 
470
  ?>
471
 
472
 
473
  <div class="yasr-onoffswitch-big">
474
  <input type="checkbox" name="yasr_general_options[enable_ip]" class="yasr-onoffswitch-checkbox"
475
+ id="yasr-general-options-enable-ip-switch" <?php if ($option['enable_ip'] === 'yes') {
476
+ echo " checked='checked' ";
477
+ } ?> >
 
 
478
  <label class="yasr-onoffswitch-label" for="yasr-general-options-enable-ip-switch">
479
  <span class="yasr-onoffswitch-inner"></span>
480
  <span class="yasr-onoffswitch-switch"></span>
483
 
484
  <br/>
485
 
486
+ <?php
487
+
488
  $string = sprintf(
489
+ __('Please note that to comply with the %s EU law, you %s MUST %s warn your users that you\'re storing their ip. %s
490
+ If in doubt, leave no.',
491
+ 'yet-another-stars-rating'
492
+ ),
493
+ '<a href="https://en.wikipedia.org/wiki/General_Data_Protection_Regulation">GDPR</a>',
494
+ '<strong>', '</strong>', '<br />'
495
  );
496
+
497
+ echo $string;
498
+
499
  ?>
500
 
501
  <br/>
502
 
503
  <hr>
504
 
505
+ <?php
506
+
507
+ } //End function
508
+
509
+ function yasr_choose_snippet_callback($option) {
510
 
 
 
 
511
  $blogposting_organization_name = $option['blogposting_organization_name'];
512
  $blogposting_organization_logo = $option['blogposting_organization_logo'];
513
+
514
  ?>
515
 
516
+ <strong><?php _e('Which rich snippet do you want to use?', 'yet-another-stars-rating'); ?></strong>
 
 
517
 
518
  <div class="yasr-indented-answer">
519
  <input type="radio" name="yasr_general_options[snippet]" value="overall_rating"
520
+ class="yasr_choose_snippet" <?php if ($option['snippet'] === 'overall_rating') {
521
+ echo " checked=\"checked\" ";
522
+ } ?> >
523
+ <?php _e('Review Rating', 'yet-another-stars-rating') ?>
 
 
 
 
524
  <br/>
525
 
526
  <input type="radio" name="yasr_general_options[snippet]" value="visitor_rating"
527
+ class="yasr_choose_snippet" <?php if ($option['snippet'] === 'visitor_rating') {
528
+ echo " checked=\"checked\" ";
529
+ } ?> >
530
+ <?php _e('Aggregate Rating', 'yet-another-stars-rating') ?>
 
 
 
 
531
  <br/>
532
 
533
  <p>&nbsp;</p>
534
 
535
+ <a href="#" id="yasr-snippet-explained-link"><?php _e("What is this?", 'yet-another-stars-rating') ?></a>
 
 
536
 
537
  <div id="yasr-snippet-explained" class="yasr-help-box-settings">
538
+ <?php
539
+
540
+ _e('If you select "Review Rating", rating average is get from yasr_overall_rating shortcode.
541
+ Your site will be indexed from search engines like this: ', 'yet-another-stars-rating');
542
+ echo "<br /><br /><img src=" . YASR_IMG_DIR . "yasr_review.png>";
543
+
544
+ echo "<br /> <br />";
545
+
546
+ _e('If, instead, you choose "Aggregate Rating", your site will be indexed like this', 'yet-another-stars-rating');
547
+ echo "<br /><br /><img src=" . YASR_IMG_DIR . "yasr_aggregate.jpg>";
548
+ ?>
549
  </div>
550
 
551
  </div>
554
 
555
  <br/>
556
 
557
+ <strong><?php _e('Select default item type for all post or pages', 'yet-another-stars-rating'); ?></strong>
 
 
558
 
559
  <div class="yasr-indented-answer" id="yasr-choose-snippet-type">
560
 
561
  <input type="radio" name="yasr_general_options[snippet_itemtype]" value="Product"
562
+ class="yasr_choose_snippet" <?php if ($option['snippet_itemtype'] === 'Product') {
563
+ echo " checked=\"checked\" ";
564
+ } ?> >
565
+ <?php _e('Product', 'yet-another-stars-rating') ?>
 
 
 
 
566
  <br/>
567
 
568
  <input type="radio" name="yasr_general_options[snippet_itemtype]" value="Place"
569
+ class="yasr_choose_snippet" <?php if ($option['snippet_itemtype'] === 'Place') {
570
+ echo " checked=\"checked\" ";
571
+ } ?> >
572
+ <?php _e('Place', 'yet-another-stars-rating') ?>
 
 
 
 
573
  <br/>
574
 
575
  <input type="radio" name="yasr_general_options[snippet_itemtype]" value="Recipe"
576
+ class="yasr_choose_snippet" <?php if ($option['snippet_itemtype'] === 'Recipe') {
577
+ echo " checked=\"checked\" ";
578
+ } ?> >
579
+ <?php _e('Recipe', 'yet-another-stars-rating') ?>
 
 
 
 
580
  <br/>
581
 
582
  <input type="radio" name="yasr_general_options[snippet_itemtype]" value="Other" class="yasr_choose_snippet"
583
+ id="yasr_choose_snippet_blogposting" <?php if ($option['snippet_itemtype'] === 'Other') {
584
+ echo " checked=\"checked\" ";
585
+ } ?> >
586
+ <?php _e('BlogPosting') ?>
 
 
 
 
587
  <br/>
588
 
589
 
590
  <div class="yasr-help-box-settings" id="yasr-blogPosting-additional-info" style="display:block">
591
 
592
+ <?php _e("If you need to use BlogPosting as item type, even for just one post or page, please fill these forms", "yet-another-stars-rating"); ?>
 
 
593
 
594
  <br/> <br/>
595
 
596
  <input type='text' name='yasr_general_options[blogposting_organization_name]'
597
  id="yasr-general-options-blogposting-organization-name"
598
+ class="yasr-blogPosting-additional-info-inputs" <?php printf('value="%s"', $blogposting_organization_name); ?>
 
 
599
  maxlength="180"/>
600
+ <?php _e('Publisher name (e.g. Google)', 'yet-another-stars-rating') ?>
 
 
601
 
602
  <br/> <br/>
603
 
604
  <input type='text' name='yasr_general_options[blogposting_organization_logo]'
605
  id="yasr-general-options-blogposting-organization-logo"
606
+ class="yasr-blogPosting-additional-info-inputs" <?php printf('value="%s"', $blogposting_organization_logo); ?>
 
 
607
  maxlength="300"/>
608
+ <?php _e('Logo Url (if empty siteicon will be used instead)', 'yet-another-stars-rating') ?>
 
 
609
 
610
  </div>
611
 
612
 
613
  <br/>
614
 
615
+ <small><?php _e('You can always change it in the single post or page.', 'yet-another-stars-rating'); ?></small>
 
 
616
  <br/>
617
+ <small><?php _e('This will affect only the post/page where you didn\'t change manually the itemtype yet.', 'yet-another-stars-rating'); ?> </small>
 
 
618
 
619
  <p>&nbsp;</p>
620
 
623
 
624
  <p>&nbsp;</p>
625
 
626
+ <?php
627
+
628
+ } //End function yasr_choose_snippet_callback
629
+
630
+ function yasr_general_options_sanitize($option) {
631
 
 
 
 
632
  //Array to return
633
  $output = array();
634
+
635
  $tidy_installed = false;
636
+
637
+ if (extension_loaded('tidy')) {
638
  $tidy_installed = true;
639
  }
640
+
641
  // Loop through each of the incoming options
642
+ foreach ($option as $key => $value) {
643
  // Check to see if the current option has a value. If so, process it.
644
+ if (isset($option[$key])) {
645
+
646
  //Tags are not allowed for any fields
647
  $allowed_tags = '';
648
+
649
  //except these ones
650
+ if ($key == 'text_before_overall' || $key == 'text_before_visitor_rating' ||
651
+ $key == 'text_after_visitor_rating' || $key == 'custom_text_must_sign_in' ||
652
+ $key == 'custom_text_user_voted') {
653
+
654
  $allowed_tags = '<strong><p>';
655
+
656
  // handle quoted strings and allow some tags
657
+ $output[$key] = strip_tags(stripslashes($option[$key]), $allowed_tags);
658
+
659
  //if tidy extension is enabled, fix errors in html
660
+ if ($tidy_installed === true) {
661
+ $tidy = new Tidy();
662
+ $output[$key] = $tidy->repairString($output[$key], array('show-body-only' => true));
 
 
 
663
  }
664
+
665
+ }
666
+ else {
667
  // handle quoted strings and allow no tags
668
+ $output[$key] = strip_tags(stripslashes($option[$key]), $allowed_tags);
669
  }
670
+
671
  //Always use htmlspecialchars
672
+ $output[$key] = htmlspecialchars($output[$key]);
673
+
674
+ if ($key == 'blogposting_organization_logo') {
675
  //if is not a valid url get_site_icon_url instead
676
+ if (filter_var($value, FILTER_VALIDATE_URL) === false) {
677
  $output[$key] = get_site_icon_url();
678
  }
679
  }
680
+
681
+ } // end if
682
+
683
+ } // end foreach
684
+
685
  //if in array doesn't exists [auto_insert_enabled] key, create it and set to 0
686
+ if (!array_key_exists('auto_insert_enabled', $output)) {
 
687
  $output['auto_insert_enabled'] = 0;
688
+ }
689
+ //if exists value must be 1
690
+ else {
691
  $output['auto_insert_enabled'] = 1;
692
  }
693
+
694
+
695
  //Same as above but for [show_overall_in_loop] key
696
+ if (!array_key_exists('show_overall_in_loop', $output)) {
 
697
  $output['show_overall_in_loop'] = 'disabled';
698
+ }
699
+ //if exists must be string 'enabled'
700
+ else {
701
  $output['show_overall_in_loop'] = 'enabled';
702
  }
703
+
704
+
705
  //Same as above but for [show_visitor_votes_in_loop] key
706
+ if (!array_key_exists('show_visitor_votes_in_loop', $output)) {
 
707
  $output['show_visitor_votes_in_loop'] = 'disabled';
708
+ }
709
+ //if exists must be string 'enabled'
710
+ else {
711
  $output['show_visitor_votes_in_loop'] = 'enabled';
712
  }
713
+
714
  //Same as above but for text_before_stars key
715
+ if (!array_key_exists('text_before_stars', $output)) {
 
716
  $output['text_before_stars'] = 0;
717
+ }
718
+ //if exists must be 1
719
+ else {
720
  $output['text_before_stars'] = 1;
721
  }
722
+
723
  //Same as above but for visitors_stats key
724
+ if (!array_key_exists('visitors_stats', $output)) {
 
725
  $output['visitors_stats'] = 'no';
726
+ }
727
+ //if exists must be string 'yes'
728
+ else {
729
  $output['visitors_stats'] = 'yes';
730
  }
731
+
732
  //Same as above but for enable_ip key
733
+ if (!array_key_exists('enable_ip', $output)) {
 
734
  $output['enable_ip'] = 'no';
735
+ }
736
+ //if exists must be string 'yes'
737
+ else {
738
  $output['enable_ip'] = 'yes';
739
  }
740
+
741
  return $output;
742
+
743
  }
744
 
745
+
746
  /************ End Yasr General Settings ************/
747
+
748
+
749
  //include multiset functions
750
+ include(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions-multiset.php');
751
+
752
  //include style functions
753
+ include(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions-style.php');
754
+
755
  //Misc
756
+ include(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions-misc.php');
757
+
758
+ //load functions migration
759
+ include (YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-migration-functions.php');
760
+
761
+
762
+ ?>
lib/admin/settings/yasr-settings-migration-functions.php ADDED
@@ -0,0 +1,408 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /****** Check for previous rate my post INSTALLATION *******/
4
+ class yasrSearchExistingRatingPlugin {
5
+
6
+ function yasr_search_wppr () {
7
+ //only check for active plugin, since import from table will be not used
8
+ if (is_plugin_active('wp-postratings/wp-postratings.php')) {
9
+ return true;
10
+ }
11
+ }
12
+
13
+ function yasr_search_kksr () {
14
+ //only check for active plugin, since import from table will be not used
15
+ if (is_plugin_active('kk-star-ratings/index.php')) {
16
+ return true;
17
+ }
18
+ }
19
+
20
+ function yasr_search_rmp () {
21
+ if (is_plugin_active('rate-my-post/rate-my-post.php')) {
22
+ return true;
23
+ } else {
24
+ global $wpdb;
25
+
26
+ $rmp_table = $wpdb->prefix . 'rmp_analytics';
27
+
28
+ if ($wpdb->get_var("SHOW TABLES LIKE '$rmp_table'") == $rmp_table) {
29
+ return true;
30
+ } else {
31
+ return false;
32
+ }
33
+ }
34
+ }
35
+
36
+ function yasr_import_wppr_query_number () {
37
+
38
+ $number_of_query_transient = get_transient('yasr_wppr_import_query_number');
39
+
40
+ if($number_of_query_transient !== false) {
41
+ return $number_of_query_transient;
42
+ } else {
43
+
44
+ global $wpdb;
45
+
46
+ $logs = $wpdb->get_results("
47
+ SELECT pm.post_id,
48
+ MAX(CASE WHEN pm.meta_key = 'ratings_average' THEN pm.meta_value END) as ratings_average,
49
+ MAX(CASE WHEN pm.meta_key = 'ratings_users' THEN pm.meta_value END) as ratings_users
50
+ FROM $wpdb->postmeta as pm,
51
+ $wpdb->posts as p
52
+ WHERE pm.meta_key IN ('ratings_average', 'ratings_users')
53
+ AND pm.meta_value <> 0
54
+ AND pm.post_id = p.ID
55
+ GROUP BY pm.post_id ASC
56
+ ORDER BY pm.post_id ASC
57
+ "
58
+ );
59
+
60
+ //set counter to 0
61
+ $i = 0;
62
+
63
+ if (empty($logs)) {
64
+ return 0;
65
+ } else {
66
+ //count insert queries
67
+ foreach ($logs as $column) {
68
+ for ($j=1; $j<=$column->ratings_users; $j++) {
69
+ $i ++;
70
+ }
71
+ }
72
+ }
73
+
74
+ set_transient('yasr_wppr_import_query_number', $i, DAY_IN_SECONDS);
75
+ return $i;
76
+ }
77
+
78
+ }
79
+
80
+ function yasr_import_kksr_query_number () {
81
+
82
+ $number_of_query_transient = get_transient('yasr_kksr_import_query_number');
83
+
84
+ if($number_of_query_transient !== false) {
85
+ return $number_of_query_transient;
86
+ } else {
87
+ global $wpdb;
88
+
89
+ $logs=$wpdb->get_results("
90
+ SELECT pm.post_id,
91
+ MAX(CASE WHEN pm.meta_key = '_kksr_avg' THEN pm.meta_value END) as ratings_average,
92
+ MAX(CASE WHEN pm.meta_key = '_kksr_casts' THEN pm.meta_value END) as ratings_users
93
+ FROM $wpdb->postmeta as pm,
94
+ $wpdb->posts as p
95
+ WHERE pm.meta_key IN ('_kksr_avg', '_kksr_casts')
96
+ AND pm.meta_value <> 0
97
+ AND pm.post_id = p.ID
98
+ GROUP BY pm.post_id ASC
99
+ ORDER BY pm.post_id ASC
100
+ "
101
+ );
102
+
103
+ //set counter to 0
104
+ $i = 0;
105
+
106
+ if (empty($logs)) {
107
+ return 0;
108
+ } else {
109
+ //count insert queries
110
+ foreach ($logs as $column) {
111
+ for ($j=1; $j<=$column->ratings_users; $j++) {
112
+ $i ++;
113
+ }
114
+ }
115
+ }
116
+
117
+ set_transient('yasr_kksr_import_query_number', $i, DAY_IN_SECONDS);
118
+ return $i;
119
+ }
120
+
121
+ }
122
+
123
+ function yasr_import_rmp_query_number () {
124
+
125
+ $number_of_query_transient = get_transient('yasr_rmp_import_query_number');
126
+
127
+ if($number_of_query_transient !== false) {
128
+ return $number_of_query_transient;
129
+ } else {
130
+ global $wpdb;
131
+
132
+ $rmp_table=$wpdb->prefix . 'rmp_analytics';
133
+
134
+ //get logs
135
+ $logs=$wpdb->get_results("
136
+ SELECT rmp.post AS post_id,
137
+ rmp.value as vote,
138
+ rmp.time AS date,
139
+ p.ID
140
+ FROM $rmp_table AS rmp,
141
+ $wpdb->posts AS p
142
+ WHERE rmp.post = p.id"
143
+ );
144
+
145
+ if (empty($logs)) {
146
+ return 0;
147
+ } else {
148
+
149
+ set_transient('yasr_rmp_import_query_number', $wpdb->num_rows, DAY_IN_SECONDS);
150
+
151
+ return $wpdb->num_rows;
152
+ }
153
+ }
154
+
155
+ }
156
+ }
157
+
158
+ add_action( 'wp_ajax_yasr_import_wppr', 'yasr_import_wppr_callback' );
159
+
160
+ function yasr_import_wppr_callback() {
161
+
162
+ if($_POST['nonce']) {
163
+ $nonce = $_POST['nonce'];
164
+ } else {
165
+ exit();
166
+ }
167
+
168
+ if (!wp_verify_nonce( $nonce, 'yasr-import-wppr-action' ) ) {
169
+ die('Error while checking nonce');
170
+ }
171
+
172
+ if (!current_user_can( 'manage_options' ) ) {
173
+ die(__( 'You do not have sufficient permissions to access this page.', 'yet-another-stars-rating' ));
174
+ }
175
+
176
+ global $wpdb;
177
+
178
+
179
+ //get logs
180
+ //With Wp Post Rating I need to import postmeta.
181
+ //It has his own table too, but can be disabled in the settings.
182
+ //The only way to be sure is get the postmeta
183
+ $logs=$wpdb->get_results("
184
+ SELECT pm.post_id,
185
+ MAX(CASE WHEN pm.meta_key = 'ratings_average' THEN pm.meta_value END) as ratings_average,
186
+ MAX(CASE WHEN pm.meta_key = 'ratings_users' THEN pm.meta_value END) as ratings_users
187
+ FROM $wpdb->postmeta as pm,
188
+ $wpdb->posts as p
189
+ WHERE pm.meta_key IN ('ratings_average', 'ratings_users')
190
+ AND pm.meta_value <> 0
191
+ AND pm.post_id = p.ID
192
+ GROUP BY pm.post_id ASC
193
+ ORDER BY pm.post_id ASC
194
+ "
195
+ );
196
+
197
+ if(empty($logs)) {
198
+ echo json_encode(__('No WP Post Rating data found'));
199
+ } else {
200
+ /****** Insert logs ******/
201
+ foreach ($logs as $column) {
202
+
203
+ //force to be int
204
+ $column->ratings_users = (int)$column->ratings_users;
205
+
206
+ for ($i=1; $i<=$column->ratings_users; $i++) {
207
+
208
+ //check if rating_average is not null.
209
+ //I found out that sometimes Wp Post Rating can save value with null data (sigh!!)
210
+ if ($column->ratings_average !== null) {
211
+
212
+ $result = $wpdb->replace(
213
+ YASR_LOG_TABLE,
214
+ array(
215
+ 'post_id' => $column->post_id,
216
+ 'multi_set_id' => '-1',
217
+ 'user_id' => 0, //not stored on wp post rating
218
+ 'vote' => $column->ratings_average,
219
+ 'date' => '', //not stored on wp post rating
220
+ 'ip' => 'wppostrating'//not stored on wp post rating
221
+ ),
222
+ array('%d', '%s', '%d', '%s', '%s', '%s')
223
+ );
224
+ }
225
+ }
226
+ }
227
+
228
+ if ($result) {
229
+ yasr_save_option_imported_plugin('wppr');
230
+
231
+ $string_to_return = __('Woot! All data have been imported!', 'yet-another-stars-rating');
232
+ echo json_encode($string_to_return);
233
+ }
234
+
235
+ }
236
+
237
+ die();
238
+ }
239
+
240
+ add_action( 'wp_ajax_yasr_import_kksr', 'yasr_import_kksr_callback' );
241
+
242
+ function yasr_import_kksr_callback() {
243
+
244
+ if($_POST['nonce']) {
245
+ $nonce = $_POST['nonce'];
246
+ } else {
247
+ exit();
248
+ }
249
+
250
+ if (!wp_verify_nonce( $nonce, 'yasr-import-kksr-action' ) ) {
251
+ die('Error while checking nonce');
252
+ }
253
+
254
+ if (!current_user_can( 'manage_options' ) ) {
255
+ die(__( 'You do not have sufficient permissions to access this page.', 'yet-another-stars-rating' ));
256
+ }
257
+
258
+ global $wpdb;
259
+
260
+
261
+ //get logs
262
+ //With KK star rating I need to import postmeta.
263
+ //The only way to be sure is get the postmeta
264
+ $logs=$wpdb->get_results("
265
+ SELECT pm.post_id,
266
+ MAX(CASE WHEN pm.meta_key = '_kksr_avg' THEN pm.meta_value END) as ratings_average,
267
+ MAX(CASE WHEN pm.meta_key = '_kksr_casts' THEN pm.meta_value END) as ratings_users
268
+ FROM $wpdb->postmeta as pm,
269
+ $wpdb->posts as p
270
+ WHERE pm.meta_key IN ('_kksr_avg', '_kksr_casts')
271
+ AND pm.meta_value <> 0
272
+ AND pm.post_id = p.ID
273
+ GROUP BY pm.post_id ASC
274
+ ORDER BY pm.post_id ASC
275
+ "
276
+ );
277
+
278
+ if(empty($logs)) {
279
+ echo json_encode(__('No KK Star Ratings data found'));
280
+ } else {
281
+ /****** Insert logs ******/
282
+ foreach ($logs as $column) {
283
+
284
+ for ($i=1; $i<=$column->ratings_users; $i++) {
285
+ $result = $wpdb->replace(
286
+ YASR_LOG_TABLE,
287
+ array(
288
+ 'post_id' => $column->post_id,
289
+ 'multi_set_id' => '-1',
290
+ 'user_id' => 0, //not stored on KK star rating
291
+ 'vote' => $column->ratings_average,
292
+ 'date' => 'kkstarratings', //not stored KK star rating
293
+ 'ip' => 'kkstarratings'//not stored KK star rating
294
+ ),
295
+ array('%d', '%s', '%d', '%s', '%s', '%s')
296
+ );
297
+ }
298
+ }
299
+
300
+ if ($result) {
301
+ yasr_save_option_imported_plugin('kksr');
302
+
303
+ $string_to_return = __('Woot! All data have been imported!', 'yet-another-stars-rating');
304
+ echo json_encode($string_to_return);
305
+ }
306
+
307
+ }
308
+
309
+ die();
310
+ }
311
+
312
+ add_action( 'wp_ajax_yasr_import_ratemypost', 'yasr_import_ratemypost_callback' );
313
+
314
+ function yasr_import_ratemypost_callback() {
315
+
316
+ if($_POST['nonce']) {
317
+ $nonce = $_POST['nonce'];
318
+ } else {
319
+ exit();
320
+ }
321
+
322
+ if (!wp_verify_nonce( $nonce, 'yasr-import-ratemypost-action' ) ) {
323
+ die('Error while checking nonce');
324
+ }
325
+
326
+ if (!current_user_can( 'manage_options' ) ) {
327
+ die(__( 'You do not have sufficient permissions to access this page.', 'yet-another-stars-rating' ));
328
+ }
329
+
330
+ global $wpdb;
331
+
332
+ $rmp_table=$wpdb->prefix . 'rmp_analytics';
333
+
334
+ //get logs
335
+ $logs=$wpdb->get_results("
336
+ SELECT rmp.post AS post_id,
337
+ rmp.value as vote,
338
+ rmp.time AS date,
339
+ p.ID
340
+ FROM $rmp_table AS rmp,
341
+ $wpdb->posts AS p
342
+ WHERE rmp.post = p.id"
343
+ );
344
+
345
+ if(empty($logs)) {
346
+ echo json_encode(__('No Rate My Post data found'));
347
+ } else {
348
+ /****** Insert logs ******/
349
+ foreach ($logs as $column) {
350
+ $result = $wpdb->replace(
351
+ YASR_LOG_TABLE,
352
+ array(
353
+ 'post_id' => $column->post_id,
354
+ 'multi_set_id' => '-1',
355
+ 'user_id' => 0, //seems like rate my post store all users like -1, so I cant import the user_id
356
+ 'vote' => $column->vote,
357
+ 'date' => $column->date,
358
+ 'ip' => 'ratemypost'
359
+ ),
360
+ array('%d', '%s', '%d', '%s', '%s', '%s')
361
+ );
362
+ }
363
+
364
+ if ($result) {
365
+ yasr_save_option_imported_plugin('rmp');
366
+
367
+ $string_to_return = __('Woot! All data have been imported!', 'yet-another-stars-rating');
368
+ echo json_encode($string_to_return);
369
+ }
370
+ }
371
+ die();
372
+ }
373
+
374
+ function yasr_save_option_imported_plugin($plugin) {
375
+
376
+ global $wpdb;
377
+
378
+ //delete all transient related to yasr_visitor_votes
379
+ $sql_delete_transient = "
380
+ DELETE FROM {$wpdb->options}
381
+ WHERE option_name LIKE '_transient_yasr_visitor_votes_%'
382
+ OR option_name LIKE '_transient_timeout_yasr_visitor_votes_%'
383
+ ";
384
+
385
+ $wpdb->query($sql_delete_transient);
386
+
387
+ //get actual data
388
+ $plugin_imported = get_option('yasr_plugin_imported');
389
+ //Add plugin just imported as a key
390
+ $plugin_imported[$plugin] = array('date' => date('Y-m-d H:i:s'));
391
+ //update option
392
+ update_option('yasr_plugin_imported', $plugin_imported, false);
393
+ }
394
+
395
+ function yasr_import_plugin_alert_box($plugin, $number_of_queries) {
396
+
397
+ echo '<div class="yasr-alert-box">';
398
+ echo sprintf(__(
399
+ 'To import %s seems like %s %d %s INSERT queries are necessary. %s
400
+ There is nothing wrong with that, but some hosting provider can have a query limit/hour. %s
401
+ I strongly suggest to contact your hosting and ask about your plan limit',
402
+ 'yet-another-stars-rating'
403
+ ),$plugin, '<strong>', $number_of_queries, '</strong>', '<br />','<br />');
404
+ echo '</div>';
405
+
406
+ }
407
+
408
+ ?>
lib/admin/settings/yasr-settings-migration-page.php ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $plugin_imported = get_option('yasr_plugin_imported');
26
+
27
+ ?>
28
+
29
+ <h3><?php _e('Migration Tools', 'yet-another-stars-rating'); ?></h3>
30
+
31
+ <table class="form-table" id="yasr-pro-charts-options">
32
+
33
+ <!--Overall Rating Chart-->
34
+ <tr>
35
+ <td>
36
+ <p>
37
+ <strong>
38
+ <?php
39
+ _e('With Yasr you can migrate ratings from the following plugins:')
40
+ ?>
41
+ </strong>
42
+ </p>
43
+ <div class="yasr-indented-answer">
44
+ <p>WP-PostRatings</p>
45
+ <p>kk Star Ratings</p>
46
+ <p>Rate My Post</p>
47
+ </div>
48
+ </td>
49
+ </tr>
50
+ <tr>
51
+ <td>
52
+ <div>
53
+ <?php
54
+ $rating_plugin_exists = new yasrSearchExistingRatingPlugin;
55
+
56
+ if($rating_plugin_exists->yasr_search_wppr()){
57
+ $nonce_import_wppr = wp_create_nonce('yasr-import-wppr-action');
58
+ ?>
59
+ <span class="title-plugin-found">
60
+ <?php _e('Plugin found: WP-PostRatings' , 'yet-another-stars-rating'); ?>
61
+ </span>
62
+ <?php
63
+
64
+ $number_of_stars = (int)get_option('postratings_max', false);
65
+
66
+ if ($number_of_stars && $number_of_stars !== 5) {
67
+ echo '<div class="yasr-indented-answer" style="margin-top: 10px;">';
68
+ echo sprintf(__('You\' re using a star set different from 5 %s
69
+ Import can not be done', 'yet-another-stars-rating'), '<br />');
70
+ echo '</div>';
71
+ } else {
72
+
73
+ echo '<div class="yasr-indented-answer" style="margin-top: 10px;">';
74
+ echo sprintf(__(
75
+ '%s Please note: %s depending on the settings, Wp-PostRatings may save data in different ways. %s
76
+ The only way to be sure to get ALL data is, for every single post or page, getting the total
77
+ number of votes, and save the current average as the rating for all votes. %s
78
+ E.g. A post has 130 votes with an average of 4.4: since is impossible to know the single rating,
79
+ Yasr will import 130 votes with 4.4. %s
80
+ Because of this, statistics in front end will be disabled for all post or page published before
81
+ the import.',
82
+ 'yet-another-stars-rating'
83
+ ), '<strong>', '</strong>', '<br />', '<br />', '<br />');
84
+ echo '</div>';
85
+
86
+ if (is_array($plugin_imported) && array_key_exists('wppr', $plugin_imported)) {
87
+ echo '<div class="yasr-indented-answer" style="margin-top: 10px;">'
88
+ . __('You\'ve already imported WP-PostRatings data on', 'yet-another-stars-rating') .
89
+ '&nbsp;<strong>' . $plugin_imported['wppr']['date'] . '</strong>
90
+ </div>';
91
+ } else {
92
+
93
+ $number_of_queries_wppr = (int) $rating_plugin_exists->yasr_import_wppr_query_number();
94
+
95
+ if ($number_of_queries_wppr > 1000) {
96
+ yasr_import_plugin_alert_box('WP-PostRatings', $number_of_queries_wppr);
97
+ }
98
+
99
+ ?>
100
+ <div class="yasr-indented-answer">
101
+ <button class="button-primary" id="yasr-import-wppr-submit">
102
+ <?php _e('Import data', 'yet-another-stars-rating') ?>
103
+ </button>
104
+ <input type="hidden" id="yasr-import-wppr-nonce"
105
+ value="<?php echo $nonce_import_wppr ?>">
106
+ </div>
107
+ <div id="yasr-import-wppr-answer" class="yasr-indented-answer">
108
+ </div>
109
+
110
+ <div class="yasr-space-settings-div">
111
+ </div>
112
+
113
+ <?php
114
+ }
115
+
116
+ }
117
+ ?>
118
+
119
+ <?php
120
+ }
121
+
122
+ if($rating_plugin_exists->yasr_search_kksr()){
123
+ $nonce_import_kksr = wp_create_nonce('yasr-import-kksr-action');
124
+ ?>
125
+ <span class="title-plugin-found">
126
+ <?php _e('Plugin found: KK Star Ratings' , 'yet-another-stars-rating'); ?>
127
+ </span>
128
+ <?php
129
+
130
+ echo '<div class="yasr-indented-answer" style="margin-top: 10px;">';
131
+ echo sprintf(__(
132
+ '%s Please note: %s KK Star Ratings doesn\'t save information about the single vote. %s
133
+ The only way to be sure to get ALL data is, for every single post or page, getting the total
134
+ number of votes, and save the current average as the rating for all votes. %s
135
+ E.g. A post has 130 votes with an average of 4.4: since is impossible to know the single rating,
136
+ Yasr will import 130 votes 4.4 votes. %s
137
+ Because of this, statistics in front end will be disabled for all post or page published before
138
+ the import.%s
139
+ If you use a rating scale different than 1 to 5, all ratings will be converted to work with a
140
+ 5 ratings star scale.',
141
+ 'yet-another-stars-rating'
142
+ ), '<strong>', '</strong>', '<br />', '<br />', '<br />', '<br />');
143
+ echo '</div>';
144
+
145
+ if (is_array($plugin_imported) && array_key_exists('kksr', $plugin_imported)) {
146
+ echo '<div class="yasr-indented-answer" style="margin-top: 10px;">'
147
+ .__('You\'ve already imported KK Star Rating data on', 'yet-another-stars-rating').
148
+ '&nbsp;<strong>'.$plugin_imported['kksr']['date']. '</strong>
149
+ </div>';
150
+ } else {
151
+
152
+ $number_of_queries_kksr = (int)$rating_plugin_exists->yasr_import_kksr_query_number();
153
+
154
+ if($number_of_queries_kksr > 1000) {
155
+ yasr_import_plugin_alert_box ('KK Stars Rating', $number_of_queries_kksr);
156
+ }
157
+
158
+ ?>
159
+ <div class="yasr-indented-answer">
160
+ <button class="button-primary" id="yasr-import-kksr-submit">
161
+ <?php _e('Import data', 'yet-another-stars-rating') ?>
162
+ </button>
163
+ <input type="hidden" id="yasr-import-kksr-nonce" value="<?php echo $nonce_import_kksr ?>">
164
+ </div>
165
+ <div id="yasr-import-kksr-answer" class="yasr-indented-answer">
166
+ </div>
167
+
168
+ <div class="yasr-space-settings-div">
169
+ </div>
170
+
171
+ <?php
172
+ }
173
+ ?>
174
+
175
+ <?php
176
+ }
177
+
178
+ if ($rating_plugin_exists->yasr_search_rmp()) {
179
+ $nonce_import_rmp = wp_create_nonce('yasr-import-ratemypost-action');
180
+ ?>
181
+ <span class="title-plugin-found">
182
+ <?php _e('Plugin found: Rate My Post' , 'yet-another-stars-rating'); ?>
183
+ </span>
184
+ <?php
185
+ if (is_array($plugin_imported) && array_key_exists('rmp', $plugin_imported)) {
186
+ echo '<div class="yasr-indented-answer">'
187
+ .__('You\'ve already imported Rate My Post data on', 'yet-another-stars-rating').
188
+ '&nbsp;<strong>'.$plugin_imported['rmp']['date']. '</strong>
189
+ </div>';
190
+ } else {
191
+ $number_of_queries_rmp = (int)$rating_plugin_exists->yasr_import_rmp_query_number();
192
+
193
+ if($number_of_queries_rmp > 1000) {
194
+ yasr_import_plugin_alert_box ('Rate My Post', $number_of_queries_rmp);
195
+ }
196
+ ?>
197
+ <div class="yasr-indented-answer">
198
+ <button class="button-primary" id="yasr-import-ratemypost-submit">
199
+ <?php _e('Import data', 'yet-another-stars-rating') ?>
200
+ </button>
201
+ <input type="hidden" id="yasr-import-rmp-nonce" value="<?php echo $nonce_import_rmp ?>">
202
+ </div>
203
+ <div id="yasr-import-ratemypost-answer" class="yasr-indented-answer">
204
+ </div>
205
+ <?php
206
+ }
207
+ ?>
208
+
209
+ <?php
210
+ }
211
+ ?>
212
+ </div>
213
+ </td>
214
+ </tr>
215
+
216
+ <!--Most or highest rated chart-->
217
+
218
+ </table>
lib/admin/yasr-admin-actions.php CHANGED
@@ -15,7 +15,6 @@ function yasr_filter_style_options_callback($style_options) {
15
  }
16
 
17
  return $style_options;
18
-
19
  }
20
 
21
 
@@ -25,7 +24,14 @@ add_action('yasr_style_options_add_settings_field', 'yasr_style_options_add_sett
25
 
26
  function yasr_style_options_add_settings_field_callback($style_options) {
27
 
28
- add_settings_field('yasr_style_options_choose_stars_lite', __('Choose Stars Set', 'yet-another-stars-rating'), 'yasr_style_options_choose_stars_lite_callback', 'yasr_style_tab', 'yasr_style_options_section_id', $style_options);
 
 
 
 
 
 
 
29
 
30
  }
31
 
@@ -107,11 +113,8 @@ function yasr_style_options_choose_stars_lite_callback($style_options) {
107
 
108
  </script>
109
 
110
-
111
  <?php
112
-
113
- submit_button(__('Save Settings'));
114
-
115
- }
116
 
117
  ?>
15
  }
16
 
17
  return $style_options;
 
18
  }
19
 
20
 
24
 
25
  function yasr_style_options_add_settings_field_callback($style_options) {
26
 
27
+ add_settings_field(
28
+ 'yasr_style_options_choose_stars_lite',
29
+ __('Choose Stars Set', 'yet-another-stars-rating'),
30
+ 'yasr_style_options_choose_stars_lite_callback',
31
+ 'yasr_style_tab',
32
+ 'yasr_style_options_section_id',
33
+ $style_options
34
+ );
35
 
36
  }
37
 
113
 
114
  </script>
115
 
 
116
  <?php
117
+ submit_button(__('Save Settings'));
118
+ }
 
 
119
 
120
  ?>
lib/yasr-ajax-functions.php CHANGED
@@ -28,27 +28,27 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
28
  /****** Get Set name from post or page and output the set,
29
  used in yasr-metabox-multiple-rating******/
30
 
31
- add_action( 'wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback' );
32
 
33
- function yasr_output_multiple_set_callback() {
34
 
35
- if(isset($_POST['set_id']) && isset($_POST['post_id']) && $_POST['post_id'] != '' && $_POST['set_id'] != '' ) {
36
- $set_id = (int)$_POST['set_id'];
37
- $post_id = (int)$_POST['post_id'];
38
- }
39
- else {
40
- exit();
41
- }
42
 
43
- if ( ! current_user_can( 'publish_posts' ) ) {
44
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'yet-another-stars-rating' ) );
45
- }
46
 
47
- yasr_return_multi_set_values_admin($post_id, $set_id);
48
 
49
- die();
50
 
51
- }
52
 
53
 
54
  /****** Get multiple value and insert into database, used in yasr-metabox-multiple-rating ******/
@@ -657,57 +657,6 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
657
 
658
  }
659
 
660
-
661
-
662
- /****** Ajax function called to hide the ask rating mateabox ******/
663
-
664
- add_action( 'wp_ajax_yasr_hide_ask_rating_metabox', 'yasr_hide_ask_rating_metabox' );
665
-
666
- function yasr_hide_ask_rating_metabox () {
667
-
668
- if ( ! current_user_can( 'manage_options' ) ) {
669
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'yet-another-stars-rating' ) );
670
- }
671
-
672
- if (isset($_POST['nonce']) && isset($_POST['choose']) ) {
673
-
674
- $choose = $_POST['choose'];
675
- $nonce = $_POST['nonce'];
676
-
677
- }
678
-
679
- else {
680
-
681
- exit();
682
-
683
- }
684
-
685
- if ( ! wp_verify_nonce($nonce, 'yasr_nonce_hide_ask_rating')) {
686
-
687
- die( 'Security check' );
688
-
689
- }
690
-
691
- if ($choose == 'hide') {
692
-
693
- //set transient for a week
694
- set_site_transient( 'yasr_hide_ask_rating', 'hide', DAY_IN_SECONDS * 7 );
695
-
696
- }
697
-
698
- elseif ($choose == 'close') {
699
-
700
- //it will not close forever, but for 1 year
701
- set_site_transient( 'yasr_hide_ask_rating', 'close', YEAR_IN_SECONDS );
702
-
703
- }
704
-
705
- die();
706
-
707
- }
708
-
709
-
710
-
711
  /********************* END Admin ajax functions ****************/
712
 
713
 
28
  /****** Get Set name from post or page and output the set,
29
  used in yasr-metabox-multiple-rating******/
30
 
31
+ add_action( 'wp_ajax_yasr_send_id_nameset', 'yasr_output_multiple_set_callback' );
32
 
33
+ function yasr_output_multiple_set_callback() {
34
 
35
+ if(isset($_POST['set_id']) && isset($_POST['post_id']) && $_POST['post_id'] != '' && $_POST['set_id'] != '' ) {
36
+ $set_id = (int)$_POST['set_id'];
37
+ $post_id = (int)$_POST['post_id'];
38
+ }
39
+ else {
40
+ exit();
41
+ }
42
 
43
+ if ( ! current_user_can( 'publish_posts' ) ) {
44
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'yet-another-stars-rating' ) );
45
+ }
46
 
47
+ yasr_return_multi_set_values_admin($post_id, $set_id);
48
 
49
+ die();
50
 
51
+ }
52
 
53
 
54
  /****** Get multiple value and insert into database, used in yasr-metabox-multiple-rating ******/
657
 
658
  }
659
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
660
  /********************* END Admin ajax functions ****************/
661
 
662
 
lib/yasr-db-functions.php CHANGED
@@ -144,7 +144,7 @@ function yasr_get_overall_rating($post_id = false, $create_transient = true) {
144
  }
145
 
146
  if (!$post_id) {
147
- return;
148
  }
149
 
150
  $post_id = (int) $post_id;
144
  }
145
 
146
  if (!$post_id) {
147
+ return null;
148
  }
149
 
150
  $post_id = (int) $post_id;
lib/yasr-functions.php CHANGED
@@ -36,30 +36,37 @@ function yasr_add_scripts() {
36
  //Run after default css are loaded
37
  do_action('yasr_add_front_script_css');
38
 
39
- //If choosen is light or not dark (force to be default)
40
- if (YASR_SCHEME_COLOR === 'light' || YASR_SCHEME_COLOR != 'dark') {
41
- wp_enqueue_style('yasrcsslightscheme', YASR_CSS_DIR . 'yasr-table-light.css', array('yasrcss'), YASR_VERSION_NUM, 'all');
42
- } elseif (YASR_SCHEME_COLOR === 'dark') {
43
- wp_enqueue_style('yasrcssdarkscheme', YASR_CSS_DIR . 'yasr-table-dark.css', array('yasrcss'), YASR_VERSION_NUM, 'all');
 
 
44
  }
45
 
 
 
 
46
  if (YASR_CUSTOM_CSS_RULES) {
47
  wp_add_inline_style('yasrcss', YASR_CUSTOM_CSS_RULES);
48
  }
49
 
50
- if (!is_rtl()) {
51
- wp_enqueue_script('rater', YASR_JS_DIR . 'rater-js.js', '', YASR_VERSION_NUM, true);
52
- } else {
53
- wp_enqueue_script('rater', YASR_JS_DIR . 'rater-js-rtl.js', '', YASR_VERSION_NUM, true);
54
- }
55
 
 
 
 
56
 
 
57
  wp_enqueue_script('yasrfront', YASR_JS_DIR . 'yasr-front.js', array('jquery', 'rater'), YASR_VERSION_NUM, true);
58
  wp_enqueue_script('tippy', YASR_JS_DIR . 'tippy.all.min.js', '', '3.6.0', true);
59
 
60
  do_action('yasr_add_front_script_js');
61
 
62
- $yasr_visitor_votes_loader = '<div id="loader-visitor-rating" style="display: inline">&nbsp; ' . ' <img src=' . YASR_IMG_DIR . 'loader.gif title="yasr-loader" alt="yasr-loader"></div>';
 
 
63
 
64
  $tooltip_values = __("bad, poor, ok, good, super", 'yet-another-stars-rating');
65
  $tooltip_values_exploded = explode(", ", $tooltip_values);
@@ -82,6 +89,10 @@ function yasr_add_admin_scripts($hook) {
82
 
83
  global $yasr_settings_page;
84
 
 
 
 
 
85
  if ($hook === 'index.php' || $hook === 'edit.php' || $hook === 'post.php' || $hook === 'post-new.php' ||
86
  $hook === 'edit-comments.php' || $hook === $yasr_settings_page ||
87
  $hook === 'yet-another-stars-rating_page_yasr_stats_page'
@@ -90,13 +101,9 @@ function yasr_add_admin_scripts($hook) {
90
  do_action('yasr_add_admin_scripts_begin');
91
 
92
  wp_enqueue_style('yasrcss', YASR_CSS_DIR . 'yasr-admin.css', false, YASR_VERSION_NUM, 'all');
93
-
94
  wp_enqueue_script('yasradmin', YASR_JS_DIR . 'yasr-admin.js', array('jquery'), YASR_VERSION_NUM, true);
95
-
96
  wp_enqueue_script('rater', YASR_JS_DIR . 'rater-js.js', '', YASR_VERSION_NUM, true);
97
 
98
- wp_enqueue_script('yasr_shortcode_creator', YASR_JS_DIR . 'yasr-shortcode-creator.js', array('jquery'), YASR_VERSION_NUM, true);
99
-
100
  do_action('yasr_add_admin_scripts_end', $hook);
101
 
102
  $yasr_loader = YASR_IMG_DIR . 'loader.gif';
@@ -275,9 +282,7 @@ if (YASR_AUTO_INSERT_ENABLED == 1) {
275
  }
276
 
277
  $auto_insert_shortcode = null; //To avoid undefined variable notice outside the loop (if (is_singular) )
278
-
279
  $overall_rating_code = '[yasr_overall_rating size="' . YASR_AUTO_INSERT_SIZE . '"]';
280
-
281
  $visitor_votes_code = '[yasr_visitor_votes size="' . YASR_AUTO_INSERT_SIZE . '"]';
282
 
283
  if (YASR_AUTO_INSERT_WHAT === 'overall_rating') {
@@ -332,11 +337,11 @@ if (YASR_AUTO_INSERT_ENABLED == 1) {
332
  return $content_and_stars;
333
  } //else return only if it is not a page
334
  elseif (YASR_AUTO_INSERT_EXCLUDE_PAGES === 'yes') {
335
- if (!is_page()) {
336
- return $content_and_stars;
337
  } //If is a page return the content without stars
338
  else {
339
- return $content;
340
  }
341
  }
342
 
@@ -354,7 +359,7 @@ function yasr_add_schema($content) {
354
 
355
  //Add buddypress compatibility
356
  if (function_exists('bp_is_active')) {
357
- //Return content only if is page. This will disable schema for all page.
358
  //If I try to return $content after if (YASR_SNIPPET == 'overall_rating')
359
  //or (YASR_SNIPPET == 'visitor_rating') $content will have only wp content, losing the buddypress one
360
  if (is_page()) {
36
  //Run after default css are loaded
37
  do_action('yasr_add_front_script_css');
38
 
39
+ $yasr_multiset_theme_handle= 'yasrcsslightscheme';
40
+ $yasr_multiset_theme = 'yasr-table-light.css';
41
+
42
+ //default css is the light one
43
+ if (YASR_SCHEME_COLOR === 'dark') {
44
+ $yasr_multiset_theme_handle = 'yasrcssdarkscheme';
45
+ $yasr_multiset_theme = 'yasr-table-dark.css';
46
  }
47
 
48
+ wp_enqueue_style($yasr_multiset_theme_handle, YASR_CSS_DIR . $yasr_multiset_theme, array('yasrcss'),
49
+ YASR_VERSION_NUM, 'all');
50
+
51
  if (YASR_CUSTOM_CSS_RULES) {
52
  wp_add_inline_style('yasrcss', YASR_CUSTOM_CSS_RULES);
53
  }
54
 
55
+ $rater_file_to_include = 'rater-js.js';
 
 
 
 
56
 
57
+ if (is_rtl()) {
58
+ $rater_file_to_include = 'rater-js-rtl.js';
59
+ }
60
 
61
+ wp_enqueue_script('rater', YASR_JS_DIR . $rater_file_to_include, '', YASR_VERSION_NUM, true);
62
  wp_enqueue_script('yasrfront', YASR_JS_DIR . 'yasr-front.js', array('jquery', 'rater'), YASR_VERSION_NUM, true);
63
  wp_enqueue_script('tippy', YASR_JS_DIR . 'tippy.all.min.js', '', '3.6.0', true);
64
 
65
  do_action('yasr_add_front_script_js');
66
 
67
+ $yasr_visitor_votes_loader = '<div id="loader-visitor-rating" style="display: inline">&nbsp; '.
68
+ ' <img src=' . YASR_IMG_DIR . 'loader.gif title="yasr-loader" alt="yasr-loader">
69
+ </div>';
70
 
71
  $tooltip_values = __("bad, poor, ok, good, super", 'yet-another-stars-rating');
72
  $tooltip_values_exploded = explode(", ", $tooltip_values);
89
 
90
  global $yasr_settings_page;
91
 
92
+ if ($hook === 'edit.php' || $hook === 'post.php' || $hook === 'post-new.php') {
93
+ wp_enqueue_script('yasr_shortcode_creator', YASR_JS_DIR . 'yasr-shortcode-creator.js', array('jquery'), YASR_VERSION_NUM, true);
94
+ }
95
+
96
  if ($hook === 'index.php' || $hook === 'edit.php' || $hook === 'post.php' || $hook === 'post-new.php' ||
97
  $hook === 'edit-comments.php' || $hook === $yasr_settings_page ||
98
  $hook === 'yet-another-stars-rating_page_yasr_stats_page'
101
  do_action('yasr_add_admin_scripts_begin');
102
 
103
  wp_enqueue_style('yasrcss', YASR_CSS_DIR . 'yasr-admin.css', false, YASR_VERSION_NUM, 'all');
 
104
  wp_enqueue_script('yasradmin', YASR_JS_DIR . 'yasr-admin.js', array('jquery'), YASR_VERSION_NUM, true);
 
105
  wp_enqueue_script('rater', YASR_JS_DIR . 'rater-js.js', '', YASR_VERSION_NUM, true);
106
 
 
 
107
  do_action('yasr_add_admin_scripts_end', $hook);
108
 
109
  $yasr_loader = YASR_IMG_DIR . 'loader.gif';
282
  }
283
 
284
  $auto_insert_shortcode = null; //To avoid undefined variable notice outside the loop (if (is_singular) )
 
285
  $overall_rating_code = '[yasr_overall_rating size="' . YASR_AUTO_INSERT_SIZE . '"]';
 
286
  $visitor_votes_code = '[yasr_visitor_votes size="' . YASR_AUTO_INSERT_SIZE . '"]';
287
 
288
  if (YASR_AUTO_INSERT_WHAT === 'overall_rating') {
337
  return $content_and_stars;
338
  } //else return only if it is not a page
339
  elseif (YASR_AUTO_INSERT_EXCLUDE_PAGES === 'yes') {
340
+ if (is_page()) {
341
+ return $content;
342
  } //If is a page return the content without stars
343
  else {
344
+ return $content_and_stars;
345
  }
346
  }
347
 
359
 
360
  //Add buddypress compatibility
361
  if (function_exists('bp_is_active')) {
362
+ //If this is a page, return $content withous adding schema.
363
  //If I try to return $content after if (YASR_SNIPPET == 'overall_rating')
364
  //or (YASR_SNIPPET == 'visitor_rating') $content will have only wp content, losing the buddypress one
365
  if (is_page()) {
lib/yasr-shortcode-functions.php CHANGED
@@ -268,9 +268,33 @@ function shortcode_visitor_votes_callback($atts) {
268
  }
269
 
270
  if (YASR_VISITORS_STATS === 'yes') {
271
- $span_dashicon = "<span class=\"dashicons dashicons-chart-bar yasr-dashicons-visitor-stats \"
272
- data-postid=\"$post_id\" id=\"yasr-total-average-dashicon-$post_id\"></span>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  } else {
 
274
  $span_dashicon = "";
275
  }
276
 
268
  }
269
 
270
  if (YASR_VISITORS_STATS === 'yes') {
271
+ //default
272
+ $span_dashicon = "<span class='dashicons dashicons-chart-bar yasr-dashicons-visitor-stats'
273
+ data-postid='$post_id' id='yasr-total-average-dashicon-$post_id'></span>";
274
+
275
+ if (is_array(YASR_PLUGIN_IMPORTED)) {
276
+ if (array_key_exists('wppr', YASR_PLUGIN_IMPORTED)) {
277
+ $plugin_import_date = YASR_PLUGIN_IMPORTED['wppr']['date'];
278
+ }
279
+
280
+ if (array_key_exists('kksr', YASR_PLUGIN_IMPORTED)) {
281
+ $plugin_import_date = YASR_PLUGIN_IMPORTED['kksr']['date'];
282
+ }
283
+
284
+ //remove hour from date
285
+ $plugin_import_date=strtok($plugin_import_date,' ');
286
+
287
+ $post_date = get_the_date('Y-m-d', $post_id);
288
+
289
+ //if wppr has been imported and post is older then import, hide stats
290
+ if ($post_date < $plugin_import_date) {
291
+ $span_dashicon = "";
292
+ }
293
+
294
+ }
295
+
296
  } else {
297
+ //Yasr_visitor_stats are disabled
298
  $span_dashicon = "";
299
  }
300
 
readme.txt CHANGED
@@ -5,15 +5,17 @@ Requires at least: 4.3.0
5
  Contributors: Dudo
6
  Tested up to: 5.2.2
7
  Requires PHP: 5.3
8
- Stable tag: 1.9.9
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Boost the way people interact with your website, e-commerce or blog with an easy and intuitive WordPress rating system!
12
 
13
  == Description ==
14
- Improving the user experience (UX) with your website is a top priority for everyone who cares about their online activity, as it promotes familiarity and loyalty with your brand, and enhances visibility of your activity.
 
15
 
16
- Yasr - Yet Another Stars Rating is a powerful way to add SEO-friendly user-generated reviews and testimonials to your website posts, pages and CPT, without affecting its speed.
 
17
 
18
  = How To use =
19
 
@@ -34,6 +36,9 @@ Again, this can be placed automatically at the beginning or the end of each post
34
  Multisets give the opportunity to score different aspects for each review: for example, if you're reviewing a videogame, you can create the aspects "Graphics",
35
  "Gameplay", "Story", etc.
36
 
 
 
 
37
 
38
  = Supported Languages =
39
 
@@ -128,6 +133,14 @@ If doesn't, it's suggested to ask in a SEO oriented forum.
128
 
129
  The full changelog can be found in the plugin's directory. Recent entries:
130
 
 
 
 
 
 
 
 
 
131
  = 1.9.9 =
132
  * FIXED: added a further check every time get_the_title function is called
133
 
@@ -147,22 +160,3 @@ The full changelog can be found in the plugin's directory. Recent entries:
147
  * TWEAKED: settings redesigned
148
  * TWEAKED: code cleanup
149
 
150
-
151
- = 1.9.3 =
152
- * Minor changes and code cleanup.
153
-
154
-
155
- = 1.9.2 =
156
- * FIXED: Javascript error on some mobile device
157
-
158
- = 1.9.1 =
159
- * FIXED: In some (rare) case, overall rating get empty with Gutenberg
160
-
161
-
162
- = Additional Info =
163
- External Libraries: [Rater](https://github.com/fredolss/rater-js)
164
- [tippy](https://atomiks.github.io/tippyjs/)
165
-
166
- Flat star icon made by[Freepik](http://www.freepik.com)
167
- from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/)
168
-
5
  Contributors: Dudo
6
  Tested up to: 5.2.2
7
  Requires PHP: 5.3
8
+ Stable tag: 2.0.0
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Boost the way people interact with your website, e-commerce or blog with an easy and intuitive WordPress rating system!
12
 
13
  == Description ==
14
+ Improving the user experience (UX) with your website is a top priority for everyone who cares about their online activity,
15
+ as it promotes familiarity and loyalty with your brand, and enhances visibility of your activity.
16
 
17
+ Yasr - Yet Another Stars Rating is a powerful way to add SEO-friendly user-generated reviews and testimonials to your
18
+ website posts, pages and CPT, without affecting its speed.
19
 
20
  = How To use =
21
 
36
  Multisets give the opportunity to score different aspects for each review: for example, if you're reviewing a videogame, you can create the aspects "Graphics",
37
  "Gameplay", "Story", etc.
38
 
39
+ = Migration tools =
40
+ From version 2.0 you can easily migrate from WP-PostRatings, kk Star Ratings and Rate My Post.
41
+ A tab will appear in the settings if one of these plugin is detected.
42
 
43
  = Supported Languages =
44
 
133
 
134
  The full changelog can be found in the plugin's directory. Recent entries:
135
 
136
+ = 2.0.0 =
137
+ * NEW FEATURE: is now possible to import date from:
138
+ - Wp Post Ratings
139
+ - KK Star Ratings
140
+ - Rate My Post
141
+ * FIXED: in editor screen, multi set didn't shows up if more than 1 was used
142
+ * TWEAKED: minor changes
143
+
144
  = 1.9.9 =
145
  * FIXED: added a further check every time get_the_title function is called
146
 
160
  * TWEAKED: settings redesigned
161
  * TWEAKED: code cleanup
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
yasr-settings-page.php CHANGED
@@ -26,8 +26,6 @@ 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
- $ajax_nonce_hide_ask_rating = wp_create_nonce("yasr_nonce_hide_ask_rating");
30
-
31
  $n_multi_set = null; //Evoid undefined variable when printed outside multiset tab
32
 
33
  ?>
@@ -38,32 +36,6 @@ $n_multi_set = null; //Evoid undefined variable when printed outside multiset ta
38
 
39
  <?php
40
 
41
- $error_new_multi_set = yasr_process_new_multi_set_form(); //defined in yasr-settings-functions
42
- $error_edit_multi_set = yasr_process_edit_multi_set_form(); //defined in yasr-settings-functions
43
-
44
- if ($error_new_multi_set) {
45
- echo "<div class=\"error\"> <p> <strong>";
46
-
47
- foreach ($error_new_multi_set as $error) {
48
- _e($error, 'yet-another-stars-rating');
49
- echo "<br />";
50
- }
51
-
52
- echo "</strong></p></div>";
53
- }
54
-
55
- if ($error_edit_multi_set) {
56
- echo "<div class=\"error\"> <p> <strong>";
57
-
58
- foreach ($error_edit_multi_set as $error) {
59
- _e($error, 'yet-another-stars-rating');
60
- echo "<br />";
61
- }
62
-
63
- echo "</strong></p></div>";
64
- }
65
-
66
-
67
  if (isset($_GET['tab'])) {
68
  $active_tab = $_GET['tab'];
69
  } else {
@@ -74,7 +46,6 @@ $n_multi_set = null; //Evoid undefined variable when printed outside multiset ta
74
  yasr_settings_tabs($active_tab);
75
 
76
  if ($active_tab == 'general_settings') {
77
-
78
  ?>
79
 
80
  <div class="yasr-settingsdiv">
@@ -96,100 +67,32 @@ $n_multi_set = null; //Evoid undefined variable when printed outside multiset ta
96
 
97
  <?php
98
 
99
-
100
  } //End if tab 'general_settings'
101
 
102
 
103
  if ($active_tab === 'manage_multi') {
104
 
105
- global $wpdb;
106
 
107
- //delete all transient that use multiset
108
- $sql_delete_transient = "
109
- DELETE FROM {$wpdb->options}
110
- WHERE option_name LIKE '_transient_yasr_get_multi_set_values_and_field_%'
111
- OR option_name LIKE '_transient_yasr_visitor_multi_set_%'
112
- OR option_name LIKE '_transient_timeout_yasr_get_multi_set_values_and_field_%'
113
- OR option_name LIKE '_transient_timeout_yasr_visitor_multi_set_%'
114
- ";
115
 
116
- $wpdb->query($sql_delete_transient);
117
 
118
- $multi_set = yasr_get_multi_set();
119
 
120
- $n_multi_set = $wpdb->num_rows; //wpdb->num_rows always store the last of the last query
121
 
122
  ?>
123
 
124
- <div class="yasr-settingsdiv">
125
-
126
- <h3> <?php _e("Manage Multi Set", 'yet-another-stars-rating'); ?></h3>
127
-
128
- <p>
129
-
130
- <a href="#"
131
- id="yasr-multi-set-doc-link"><?php _e("What is a Multi Set?", 'yet-another-stars-rating') ?></a>
132
-
133
- </p>
134
-
135
- <div id="yasr-multi-set-doc-box" style="display:none">
136
- <?php _e("Multi Set allows you to insert a rate for each aspect about the product / local business / whetever you're reviewing, example in the image below.", 'yet-another-stars-rating');
137
-
138
- echo "<br /><br /><img src=" . YASR_IMG_DIR . "/yasr-multi-set.png> <br /> <br />";
139
-
140
- _e("You can create up to 99 different Multi Set and each one can contain up to 9 different fields. Once you've saved it, you can insert the rates while typing your article in the box below the editor, as you can see in this image (click to see it larger)", 'yet-another-stars-rating');
141
-
142
- echo "<br /><br /><a href=\"" . YASR_IMG_DIR . "yasr-multi-set-insert-rate.jpg\"><img src=" . YASR_IMG_DIR . "/yasr-multi-set-insert-rate-small.jpg></a> <br /> <br />";
143
-
144
- _e("In order to insert your Multi Sets into a post or page, you can either past the short code that will appear at the bottom of the box or just click on the star in the graphic editor and select \"Insert Multi Set\".", 'yet-another-stars-rating');
145
 
 
 
 
 
 
 
146
  ?>
147
-
148
- <br/> <br/>
149
-
150
- <a href="#"
151
- id="yasr-multi-set-doc-link-hide"><?php _e("Close this message", 'yet-another-stars-rating') ?></a>
152
-
153
- </div>
154
-
155
- <div class="yasr-multi-set-left">
156
-
157
- <div class="yasr-new-multi-set">
158
-
159
- <?php yasr_display_multi_set_form(); ?>
160
-
161
- </div> <!--yasr-new-multi-set-->
162
-
163
- </div> <!--End yasr-multi-set-left-->
164
-
165
- <div class="yasr-multi-set-right">
166
-
167
- <?php yasr_edit_multi_form(); ?>
168
-
169
- <div id="yasr-multi-set-response" style="display:none">
170
-
171
- </div>
172
-
173
- </div> <!--End yasr-multi-set-right-->
174
-
175
- <div class="yasr-space-settings-div">
176
- </div>
177
-
178
-
179
- <div class="yasr-multi-set-choose-theme">
180
-
181
- <!--This allow to choose color for multiset-->
182
- <form action="options.php" method="post" id="yasr_multiset_form">
183
- <?php
184
- settings_fields('yasr_multiset_options_group');
185
- do_settings_sections('yasr_multiset_tab');
186
- submit_button(__('Save'));
187
- ?>
188
- </form>
189
-
190
- </div>
191
-
192
-
193
  </div>
194
 
195
  <?php
@@ -199,25 +102,19 @@ $n_multi_set = null; //Evoid undefined variable when printed outside multiset ta
199
  <div class="yasr-space-settings-div">
200
  </div>
201
 
202
- <?php
203
-
204
- } //End if ($active_tab=='manage_multi')
205
 
 
206
 
207
- if ($active_tab == 'style_options') {
208
-
209
  ?>
210
-
211
- <?php do_action('yasr_add_content_top_style_options_tab', $active_tab); ?>
212
-
213
  <div class="yasr-settingsdiv">
214
- <form action="options.php" method="post" enctype='multipart/form-data' id="yasr_settings_form">
215
- <?php
216
- settings_fields('yasr_style_options_group');
217
- do_settings_sections('yasr_style_tab');
218
- submit_button(__('Save'));
219
- ?>
220
- </form>
221
  </div>
222
 
223
  <?php
@@ -227,17 +124,13 @@ $n_multi_set = null; //Evoid undefined variable when printed outside multiset ta
227
  <div class="yasr-space-settings-div">
228
  </div>
229
 
230
- <?php do_action('yasr_add_content_bottom_style_options_tab', $active_tab); ?>
231
-
232
-
233
  <?php
234
 
235
- } //End tab style
236
 
237
 
238
  do_action('yasr_settings_check_active_tab', $active_tab);
239
 
240
-
241
  yasr_right_settings_panel('bottom');
242
 
243
  ?>
@@ -247,19 +140,13 @@ $n_multi_set = null; //Evoid undefined variable when printed outside multiset ta
247
 
248
 
249
  <script type="text/javascript">
250
-
251
  jQuery(document).ready(function () {
252
-
253
  var activeTab = <?php echo(json_encode("$active_tab")); ?>;
254
  var nMultiSet = <?php echo(json_encode("$n_multi_set")); ?> ;//Null in php is different from javascript NULL
255
  var autoInsertEnabled = <?php echo(json_encode(YASR_AUTO_INSERT_ENABLED)); ?>;
256
  var textBeforeStars = <?php echo(json_encode(YASR_TEXT_BEFORE_STARS)); ?>;
257
- var nonceHideAskRating = <?php echo(json_encode("$ajax_nonce_hide_ask_rating")); ?>
258
 
259
- YasrSettingsPage(activeTab, nMultiSet, autoInsertEnabled, textBeforeStars);
260
-
261
- YasrAsk5Stars(nonceHideAskRating);
262
 
263
  }); //End jquery document ready
264
-
265
  </script>
26
  wp_die(__('You do not have sufficient permissions to access this page.', 'yet-another-stars-rating'));
27
  }
28
 
 
 
29
  $n_multi_set = null; //Evoid undefined variable when printed outside multiset tab
30
 
31
  ?>
36
 
37
  <?php
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  if (isset($_GET['tab'])) {
40
  $active_tab = $_GET['tab'];
41
  } else {
46
  yasr_settings_tabs($active_tab);
47
 
48
  if ($active_tab == 'general_settings') {
 
49
  ?>
50
 
51
  <div class="yasr-settingsdiv">
67
 
68
  <?php
69
 
 
70
  } //End if tab 'general_settings'
71
 
72
 
73
  if ($active_tab === 'manage_multi') {
74
 
75
+ include (YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-functions-multiset-page.php');
76
 
77
+ yasr_right_settings_panel();
 
 
 
 
 
 
 
78
 
79
+ } //End if ($active_tab=='manage_multi')
80
 
 
81
 
82
+ if ($active_tab === 'style_options') {
83
 
84
  ?>
85
 
86
+ <?php do_action('yasr_add_content_top_style_options_tab', $active_tab); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
+ <div class="yasr-settingsdiv">
89
+ <form action="options.php" method="post" enctype='multipart/form-data' id="yasr_settings_form">
90
+ <?php
91
+ settings_fields('yasr_style_options_group');
92
+ do_settings_sections('yasr_style_tab');
93
+ submit_button(__('Save'));
94
  ?>
95
+ </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  </div>
97
 
98
  <?php
102
  <div class="yasr-space-settings-div">
103
  </div>
104
 
105
+ <?php do_action('yasr_add_content_bottom_style_options_tab', $active_tab);
 
 
106
 
107
+ } //End tab style
108
 
109
+ if ($active_tab === 'migration_tools') {
 
110
  ?>
 
 
 
111
  <div class="yasr-settingsdiv">
112
+ <?php
113
+ //include migration functions
114
+ include(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-settings-migration-page.php');
115
+ ?>
116
+ <div class="yasr-space-settings-div">
117
+ </div>
 
118
  </div>
119
 
120
  <?php
124
  <div class="yasr-space-settings-div">
125
  </div>
126
 
 
 
 
127
  <?php
128
 
129
+ } //End tab migration
130
 
131
 
132
  do_action('yasr_settings_check_active_tab', $active_tab);
133
 
 
134
  yasr_right_settings_panel('bottom');
135
 
136
  ?>
140
 
141
 
142
  <script type="text/javascript">
 
143
  jQuery(document).ready(function () {
 
144
  var activeTab = <?php echo(json_encode("$active_tab")); ?>;
145
  var nMultiSet = <?php echo(json_encode("$n_multi_set")); ?> ;//Null in php is different from javascript NULL
146
  var autoInsertEnabled = <?php echo(json_encode(YASR_AUTO_INSERT_ENABLED)); ?>;
147
  var textBeforeStars = <?php echo(json_encode(YASR_TEXT_BEFORE_STARS)); ?>;
 
148
 
149
+ YasrSettingsPage(activeTab, nMultiSet, autoInsertEnabled, textBeforeStars);
 
 
150
 
151
  }); //End jquery document ready
 
152
  </script>
yasr-stats-page.php CHANGED
@@ -28,8 +28,6 @@ if (!current_user_can('manage_options')) {
28
 
29
  require(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-stats-functions.php');
30
 
31
- $ajax_nonce_hide_ask_rating = wp_create_nonce("yasr_nonce_hide_ask_rating");
32
-
33
  ?>
34
 
35
  <div class="wrap">
@@ -83,17 +81,4 @@ $ajax_nonce_hide_ask_rating = wp_create_nonce("yasr_nonce_hide_ask_rating");
83
  ?>
84
 
85
  <!--End div wrap-->
86
- </div>
87
-
88
-
89
- <script type="text/javascript">
90
-
91
- jQuery(document).ready(function () {
92
-
93
- var nonceHideAskRating = <?php echo(json_encode("$ajax_nonce_hide_ask_rating")); ?>
94
-
95
- YasrAsk5Stars(nonceHideAskRating);
96
-
97
- }); //End jquery document ready
98
-
99
- </script>
28
 
29
  require(YASR_ABSOLUTE_PATH . '/lib/admin/settings/yasr-stats-functions.php');
30
 
 
 
31
  ?>
32
 
33
  <div class="wrap">
81
  ?>
82
 
83
  <!--End div wrap-->
84
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
yet-another-stars-rating.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Yet Another Stars Rating
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 testimonials to your website posts, pages and CPT, without affecting its speed.
7
- * Version: 1.9.9
8
  * Author: Dario Curvino
9
  * Author URI: https://dariocurvino.it/
10
  * Text Domain: yet-another-stars-rating
@@ -76,7 +76,7 @@ if ( !function_exists( 'yasr_fs' ) ) {
76
  yasr_fs();
77
  // Signal that SDK was initiated.
78
  do_action( 'yasr_fs_loaded' );
79
- define( 'YASR_VERSION_NUM', '1.9.9' );
80
  //Plugin relative path
81
  define( "YASR_ABSOLUTE_PATH", dirname( __FILE__ ) );
82
  //Plugin RELATIVE PATH without slashes (just the directory's name)
@@ -207,6 +207,8 @@ if ( !function_exists( 'yasr_fs' ) ) {
207
  define( "YASR_LOADER_IMAGE", YASR_IMG_DIR . "/loader.gif" );
208
  $yasr_version_installed = get_option( 'yasr-version' );
209
  global $yasr_version_installed ;
 
 
210
  //Run this only on plugin activation (doesn't work on update)
211
  register_activation_hook( __FILE__, 'yasr_on_activation' );
212
  function yasr_on_activation()
@@ -228,8 +230,12 @@ if ( !function_exists( 'yasr_fs' ) ) {
228
  global $wpdb ;
229
  global $yasr_version_installed ;
230
  global $yasr_stored_options ;
231
- if ( $yasr_version_installed && $yasr_version_installed < '1.7.3' ) {
232
- $wpdb->query( "ALTER TABLE " . YASR_MULTI_SET_FIELDS_TABLE . " CHANGE field_name field_name varchar(40) \n COLLATE 'utf8_unicode_ci' NOT NULL AFTER parent_set_id;" );
 
 
 
 
233
  }
234
 
235
  if ( $yasr_version_installed && $yasr_version_installed < '1.6.5' ) {
4
  * Plugin Name: Yet Another Stars Rating
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 testimonials to your website posts, pages and CPT, without affecting its speed.
7
+ * Version: 2.0.0
8
  * Author: Dario Curvino
9
  * Author URI: https://dariocurvino.it/
10
  * Text Domain: yet-another-stars-rating
76
  yasr_fs();
77
  // Signal that SDK was initiated.
78
  do_action( 'yasr_fs_loaded' );
79
+ define( 'YASR_VERSION_NUM', '2.0.0' );
80
  //Plugin relative path
81
  define( "YASR_ABSOLUTE_PATH", dirname( __FILE__ ) );
82
  //Plugin RELATIVE PATH without slashes (just the directory's name)
207
  define( "YASR_LOADER_IMAGE", YASR_IMG_DIR . "/loader.gif" );
208
  $yasr_version_installed = get_option( 'yasr-version' );
209
  global $yasr_version_installed ;
210
+ $yasr_plugin_imported = get_option( 'yasr_plugin_imported' );
211
+ define( 'YASR_PLUGIN_IMPORTED', $yasr_plugin_imported );
212
  //Run this only on plugin activation (doesn't work on update)
213
  register_activation_hook( __FILE__, 'yasr_on_activation' );
214
  function yasr_on_activation()
230
  global $wpdb ;
231
  global $yasr_version_installed ;
232
  global $yasr_stored_options ;
233
+ if ($yasr_version_installed && $yasr_version_installed < '1.7.3') {
234
+ $wpdb->query("ALTER TABLE " . YASR_MULTI_SET_FIELDS_TABLE .
235
+ " CHANGE field_name field_name varchar(40)
236
+ COLLATE 'utf8_unicode_ci' NOT NULL
237
+ AFTER parent_set_id;
238
+ ");
239
  }
240
 
241
  if ( $yasr_version_installed && $yasr_version_installed < '1.6.5' ) {