Yasr – Yet Another Stars Rating - Version 2.7.2

Version Description

  • NEW FEATURE: new shortcode: yasr_visitor_multi_set_ranking : this will show rankings from yasr_visitor_multiset
  • TWEAKED: minor fixes
Download this release

Release Info

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

Code changes from version 2.7.1 to 2.7.2

admin/class-wp-list-table.php CHANGED
@@ -338,7 +338,7 @@ class YASR_WP_List_Table {
338
  return;
339
  }
340
 
341
- $input_id = $input_id . '-search-input';
342
 
343
  if ( ! empty( $_REQUEST['orderby'] ) ) {
344
  echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
@@ -965,7 +965,7 @@ class YASR_WP_List_Table {
965
  // If the primary column doesn't exist fall back to the
966
  // first non-checkbox column.
967
  if ( ! isset( $columns[ $default ] ) ) {
968
- $default = YASR_WP_List_Table::get_default_primary_column_name();
969
  }
970
 
971
  /**
338
  return;
339
  }
340
 
341
+ $input_id .= '-search-input';
342
 
343
  if ( ! empty( $_REQUEST['orderby'] ) ) {
344
  echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
965
  // If the primary column doesn't exist fall back to the
966
  // first non-checkbox column.
967
  if ( ! isset( $columns[ $default ] ) ) {
968
+ $default = $this->get_default_primary_column_name();
969
  }
970
 
971
  /**
admin/css/yasr-admin.css CHANGED
@@ -167,6 +167,10 @@
167
  .form-table th {
168
  border-right: 1px solid #ddd;
169
  }
 
 
 
 
170
 
171
  /*** End top navigation ***/
172
 
@@ -310,6 +314,7 @@
310
  align-content: stretch;
311
  padding-top: 10px;
312
  padding-bottom: 10px;
 
313
  }
314
 
315
  .yasr-builder-shortcode-container {
@@ -322,7 +327,7 @@
322
  margin-bottom: 20px;
323
  }
324
 
325
- #yasr-builder-shortcode-buttons-container{
326
  padding-left: 10px;
327
  }
328
 
@@ -500,6 +505,28 @@
500
  clear: both;
501
  }
502
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
503
  .yasr-settings-row-35 {
504
  padding-left: 10px;
505
  display: flex;
@@ -507,7 +534,6 @@
507
  }
508
 
509
  .yasr-settings-row-35 > div {
510
- /*It is 35 and applyed space between*/
511
  flex: 0 0 35%;
512
  padding-top: 20px;
513
  }
@@ -520,7 +546,7 @@
520
  }
521
 
522
  .yasr-settings-row-45 > div {
523
- /*It is 45 and applyed space between*/
524
  flex: 0 0 45%;
525
  }
526
 
167
  .form-table th {
168
  border-right: 1px solid #ddd;
169
  }
170
+ /** The rule above show a border in the table head **/
171
+ .yasr-rankings th {
172
+ border-right: none;
173
+ }
174
 
175
  /*** End top navigation ***/
176
 
314
  align-content: stretch;
315
  padding-top: 10px;
316
  padding-bottom: 10px;
317
+ padding-left: 10px;
318
  }
319
 
320
  .yasr-builder-shortcode-container {
327
  margin-bottom: 20px;
328
  }
329
 
330
+ #yasr-builder-shortcode-buttons-container {
331
  padding-left: 10px;
332
  }
333
 
505
  clear: both;
506
  }
507
 
508
+ .yasr-settings-row-24 {
509
+ padding-left: 10px;
510
+ display: flex;
511
+ flex-wrap: wrap;
512
+ }
513
+
514
+ .yasr-settings-row-24 > div {
515
+ flex: 0 0 24%;
516
+ padding-top: 30px;
517
+ }
518
+
519
+ .yasr-settings-row-33 {
520
+ padding-left: 10px;
521
+ display: flex;
522
+ flex-wrap: wrap;
523
+ }
524
+
525
+ .yasr-settings-row-33 > div {
526
+ flex: 0 0 33%;
527
+ padding-top: 30px;
528
+ }
529
+
530
  .yasr-settings-row-35 {
531
  padding-left: 10px;
532
  display: flex;
534
  }
535
 
536
  .yasr-settings-row-35 > div {
 
537
  flex: 0 0 35%;
538
  padding-top: 20px;
539
  }
546
  }
547
 
548
  .yasr-settings-row-45 > div {
549
+ /*It is 45 and applied space between*/
550
  flex: 0 0 45%;
551
  }
552
 
admin/editor/YasrOnSavePost.php CHANGED
@@ -58,8 +58,6 @@ class YasrOnSavePost {
58
  return;
59
  }
60
 
61
- $update_result = null;
62
-
63
  if (isset($_POST['yasr_overall_rating'])) {
64
  $rating = $_POST['yasr_overall_rating'];
65
  $nonce = $_POST['yasr_nonce_overall_rating'];
@@ -147,12 +145,11 @@ class YasrOnSavePost {
147
  }
148
 
149
  private function saveItemTypesFields($snippet_type) {
150
- $snippet_type = strtolower($snippet_type);
151
  $array_item_type_info = json_decode(YASR_SUPPORTED_SCHEMA_TYPES_ADDITIONAL_FIELDS, true);
152
- $array_to_save = array();
153
 
154
  foreach ($array_item_type_info as $item_type_name) {
155
-
156
  $nonce_action = $item_type_name . '_nonce_action';
157
  $nonce_name = $item_type_name . '_nonce_name';
158
 
@@ -205,7 +202,6 @@ class YasrOnSavePost {
205
  }
206
 
207
  private function saveMultisetEditor() {
208
-
209
  if (isset($_POST['yasr_multiset_author_votes']) && isset($_POST['yasr_multiset_id'])) {
210
  $field_and_vote_array = json_decode(sanitize_text_field(stripslashes($_POST['yasr_multiset_author_votes'])));
211
  $set_id = (int) $_POST['yasr_multiset_id'];
58
  return;
59
  }
60
 
 
 
61
  if (isset($_POST['yasr_overall_rating'])) {
62
  $rating = $_POST['yasr_overall_rating'];
63
  $nonce = $_POST['yasr_nonce_overall_rating'];
145
  }
146
 
147
  private function saveItemTypesFields($snippet_type) {
148
+ $snippet_type = strtolower($snippet_type);
149
  $array_item_type_info = json_decode(YASR_SUPPORTED_SCHEMA_TYPES_ADDITIONAL_FIELDS, true);
150
+ $array_to_save = array();
151
 
152
  foreach ($array_item_type_info as $item_type_name) {
 
153
  $nonce_action = $item_type_name . '_nonce_action';
154
  $nonce_name = $item_type_name . '_nonce_name';
155
 
202
  }
203
 
204
  private function saveMultisetEditor() {
 
205
  if (isset($_POST['yasr_multiset_author_votes']) && isset($_POST['yasr_multiset_id'])) {
206
  $field_and_vote_array = json_decode(sanitize_text_field(stripslashes($_POST['yasr_multiset_author_votes'])));
207
  $set_id = (int) $_POST['yasr_multiset_id'];
admin/editor/yasr-editor-functions.php CHANGED
@@ -479,7 +479,6 @@ function yasr_output_multiple_set_callback() {
479
  $set_id = (int) $_POST['set_id'];
480
  $post_id = (int) $_POST['post_id'];
481
 
482
-
483
  //set fields name and ids
484
  $set_fields = YasrMultiSetData::multisetFieldsAndID($set_id);
485
 
479
  $set_id = (int) $_POST['set_id'];
480
  $post_id = (int) $_POST['post_id'];
481
 
 
482
  //set fields name and ids
483
  $set_fields = YasrMultiSetData::multisetFieldsAndID($set_id);
484
 
admin/editor/yasr-metabox-multiple-rating.php CHANGED
@@ -18,7 +18,9 @@ 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
  $multi_set = YasrMultiSetData::returnMultiSetNames();
24
  $post_id = get_the_ID();
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
  $multi_set = YasrMultiSetData::returnMultiSetNames();
26
  $post_id = get_the_ID();
admin/editor/yasr-metabox-schema.php CHANGED
@@ -68,8 +68,13 @@ $itemType_obj = new YasrMetaboxSchemaFields($saved_data);
68
  <?php _e('Is this a review?', 'yet-another-stars-rating'); ?>
69
  <br />
70
  <div class="yasr-onoffswitch-big" id="yasr-switcher-post-is-review">
71
- <input type="checkbox" name="yasr_is_post_review" class="yasr-onoffswitch-checkbox" value='yes'
72
- id="yasr-post-is-review-switch" <?php if ($post->yasr_post_is_review === 'yes') echo " checked='checked' "; ?> >
 
 
 
 
 
73
  <label class="yasr-onoffswitch-label" for="yasr-post-is-review-switch">
74
  <span class="yasr-onoffswitch-inner"></span>
75
  <span class="yasr-onoffswitch-switch"></span>
68
  <?php _e('Is this a review?', 'yet-another-stars-rating'); ?>
69
  <br />
70
  <div class="yasr-onoffswitch-big" id="yasr-switcher-post-is-review">
71
+ <input type="checkbox"
72
+ name="yasr_is_post_review"
73
+ class="yasr-onoffswitch-checkbox"
74
+ value='yes'
75
+ id="yasr-post-is-review-switch"
76
+ <?php if ($post->yasr_post_is_review === 'yes') {echo " checked='checked' ";} ?>
77
+ >
78
  <label class="yasr-onoffswitch-label" for="yasr-post-is-review-switch">
79
  <span class="yasr-onoffswitch-inner"></span>
80
  <span class="yasr-onoffswitch-switch"></span>
admin/editor/yasr-metabox-top-right.php CHANGED
@@ -80,8 +80,13 @@ wp_nonce_field('yasr_nonce_is_post_review_action', 'yasr_nonce_is_post_review');
80
  <?php _e('Disable auto insert for this post or page?', 'yet-another-stars-rating'); ?>
81
  <br />
82
  <div class="yasr-onoffswitch-big yasr-onoffswitch-big-center" id="yasr-switcher-disable-auto-insert">
83
- <input type="checkbox" name="yasr_auto_insert_disabled" class="yasr-onoffswitch-checkbox" value="yes"
84
- id="yasr-auto-insert-disabled-switch" <?php if ($is_this_post_exluded === 'yes') echo " checked='checked' "; ?> >
 
 
 
 
 
85
  <label class="yasr-onoffswitch-label" for="yasr-auto-insert-disabled-switch">
86
  <span class="yasr-onoffswitch-inner"></span>
87
  <span class="yasr-onoffswitch-switch"></span>
80
  <?php _e('Disable auto insert for this post or page?', 'yet-another-stars-rating'); ?>
81
  <br />
82
  <div class="yasr-onoffswitch-big yasr-onoffswitch-big-center" id="yasr-switcher-disable-auto-insert">
83
+ <input type="checkbox"
84
+ name="yasr_auto_insert_disabled"
85
+ class="yasr-onoffswitch-checkbox"
86
+ value="yes"
87
+ id="yasr-auto-insert-disabled-switch"
88
+ <?php if ($is_this_post_exluded === 'yes') {echo " checked='checked' ";} ?>
89
+ >
90
  <label class="yasr-onoffswitch-label" for="yasr-auto-insert-disabled-switch">
91
  <span class="yasr-onoffswitch-inner"></span>
92
  <span class="yasr-onoffswitch-switch"></span>
admin/js/src/yasr-settings-rankings.js CHANGED
@@ -9,7 +9,6 @@ if(tabClass.length > 0){
9
  }
10
 
11
  if (activeTab === 'rankings') {
12
-
13
  let elementsClassParents = '.yasr-builder-elements-parents'; //class shared between all elements
14
  let elementsClassChilds = '.yasr-builder-elements-childs'; //class shared between all elements
15
 
@@ -29,59 +28,86 @@ if (activeTab === 'rankings') {
29
  document.getElementById('yasr-builder-shortcode').textContent = '['+shortcode+']';
30
  document.getElementById('yasr-builder-copy-shortcode').setAttribute('data-shortcode', '['+shortcode+']');
31
 
32
- const previewButton = document.getElementById('yasr-builder-button-preview');
33
- const copyButton = document.getElementById('yasr-builder-copy-shortcode');
34
- const previewDiv = document.getElementById('yasr-builder-preview');
 
35
 
36
  //This is the select for data Source
37
- const selectDataSource = document.getElementById('yasr-ranking-source');
38
- const divView = document.getElementById('builder-vv-default-view');
39
- const divVotes = document.getElementById('builder-vv-required-votes');
40
- const divSize = document.getElementById('builder-stars-size');
41
- const divOverallTxt = document.getElementById('builder-overall-text');
42
- const divUsername = document.getElementById('builder-username-options');
43
- const divCategory = document.getElementById('builder-category');
44
- const divCpt = document.getElementById('builder-cpt');
 
 
 
 
 
45
 
46
  let dataSource = selectDataSource.value;
47
  let previewClicked = false;
48
 
49
  //if on page load is overall_rating (e.g. on page refresh) text div must be displayed
50
  if(dataSource === 'yasr_ov_ranking') {
51
- yasrBuilderOvOptions(divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt);
 
 
 
 
 
 
52
  }
53
- else if(selectDataSource.value === 'yasr_most_active_users' || selectDataSource.value === 'yasr_top_reviewers') {
54
- yasrBuilderNoStarsOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt);
55
  }
56
 
57
  //event listener for all change events
58
  document.addEventListener('change', event => {
59
  if(event.target.id === 'yasr-ranking-source') {
60
- //when event is on main select, be sure the preview div is empty
61
 
 
 
 
 
 
62
  previewDiv.innerHTML = '';
 
 
 
63
  if(event.target.value === 'yasr_ov_ranking') {
64
- yasrBuilderOvOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt);
65
  }
66
  else if(event.target.value === 'yasr_most_active_users' || event.target.value === 'yasr_top_reviewers') {
67
- yasrBuilderNoStarsOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt);
 
 
 
 
 
68
  }
69
  //By default, show setting for yasr_most_or_highest_rated_posts
70
  else {
71
- yasrBuilderVvOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt)
72
  }
 
73
  //be sure shortcodeAttributes is initialized again
74
- shortcodeAttributes = yasrReturnShortcodeAttributes();
75
  shortcodeAttributes['name'] = event.target.value;
76
- shortcode = shortcodeAttributes['name'];
77
  }
78
  else {
 
 
 
79
  //use this filter to add new attributes
80
  filterShortcodeAttributes = wp.hooks.applyFilters('yasrBuilderFilterShortcode', shortcodeAttributes);
81
 
82
  //loop the shortcodeAttributes array from 'rows'
83
  //and if the key is found in filterShortcodeAttributes make the assigment
84
- for(let i=1; shortcodeAttributes.length; i++) {
85
  if(filterShortcodeAttributes.hasOwnProperty(shortcodeAttributes[i])) {
86
  shortcodeAttributes[i] = filterShortcodeAttributes[i];
87
  }
@@ -89,6 +115,7 @@ if (activeTab === 'rankings') {
89
 
90
  shortcode =
91
  shortcodeAttributes['name']+
 
92
  shortcodeAttributes['rows']+
93
  shortcodeAttributes['view']+
94
  shortcodeAttributes['minvotesmost']+
@@ -124,9 +151,25 @@ if (activeTab === 'rankings') {
124
  previewClicked = true;
125
  }
126
 
 
 
 
 
 
127
  function yasrBuilderDoFetch(event) {
128
- const shortcode = selectDataSource.value
129
- const fullShortcode = document.getElementById('yasr-builder-shortcode').textContent;
 
 
 
 
 
 
 
 
 
 
 
130
  fetch(ajaxurl +'?action=yasr_rankings_preview_shortcode&shortcode='+shortcode+'&full_shortcode='+fullShortcode)
131
  .then(response => {
132
  if (response.ok === true) {
@@ -153,9 +196,12 @@ if (activeTab === 'rankings') {
153
  }
154
  })
155
  .then(response => {
156
- if (shortcode === 'yasr_ov_ranking' || shortcode === 'yasr_most_or_highest_rated_posts') {
157
- yasrDrawRankings();
158
- }
 
 
 
159
  })
160
  }
161
 
@@ -167,6 +213,7 @@ if (activeTab === 'rankings') {
167
  function yasrReturnShortcodeAttributes() {
168
  return {
169
  name: 'yasr_most_or_highest_rated_posts',
 
170
  rows: '',
171
  size: '',
172
  view: '',
@@ -181,7 +228,11 @@ if (activeTab === 'rankings') {
181
  }
182
 
183
 
184
- function yasrBuilderOvOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt) {
 
 
 
 
185
  //show custom text for overall
186
  divOverallTxt.style.display = '';
187
  divSize.style.display = '';
@@ -192,10 +243,12 @@ if (activeTab === 'rankings') {
192
  if(divCpt !== null) {
193
  divCpt.style.display = '';
194
  }
195
-
 
 
196
  }
197
 
198
- function yasrBuilderVvOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt) {
199
  divView.style.display = ''
200
  divVotes.style.display = '';
201
  divSize.style.display = '';
@@ -205,19 +258,39 @@ if (activeTab === 'rankings') {
205
  if(divCpt !== null) {
206
  divCpt.style.display = '';
207
  }
 
 
 
208
  }
209
 
210
- function yasrBuilderNoStarsOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt) {
211
  divUsername.style.display = '';
212
  divOverallTxt.style.display = 'none';
213
  divView.style.display = 'none';
214
  divVotes.style.display = 'none';
215
  divSize.style.display = 'none';
216
  divCategory.style.display = 'none';
217
-
218
  if(divCpt !== null) {
219
  divCpt.style.display = 'none';
220
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  }
222
 
223
  }
9
  }
10
 
11
  if (activeTab === 'rankings') {
 
12
  let elementsClassParents = '.yasr-builder-elements-parents'; //class shared between all elements
13
  let elementsClassChilds = '.yasr-builder-elements-childs'; //class shared between all elements
14
 
28
  document.getElementById('yasr-builder-shortcode').textContent = '['+shortcode+']';
29
  document.getElementById('yasr-builder-copy-shortcode').setAttribute('data-shortcode', '['+shortcode+']');
30
 
31
+ //Buttons
32
+ const previewButton = document.getElementById('yasr-builder-button-preview');
33
+ const copyButton = document.getElementById('yasr-builder-copy-shortcode');
34
+ const previewDiv = document.getElementById('yasr-builder-preview');
35
 
36
  //This is the select for data Source
37
+ const selectDataSource = document.getElementById('yasr-ranking-source');
38
+ const selectMultiset = document.getElementById('yasr-ranking-multiset-select');
39
+
40
+ //Ranking attributes
41
+ const divParamsContainer = document.getElementById('yasr-builder-params-container');
42
+ const divView = document.getElementById('builder-vv-default-view');
43
+ const divVotes = document.getElementById('builder-vv-required-votes');
44
+ const divSize = document.getElementById('builder-stars-size');
45
+ const divOverallTxt = document.getElementById('builder-overall-text');
46
+ const divUsername = document.getElementById('builder-username-options');
47
+ const divCategory = document.getElementById('builder-category');
48
+ const divCpt = document.getElementById('builder-cpt');
49
+ const divMultiSet = document.getElementById('yasr-ranking-multiset');
50
 
51
  let dataSource = selectDataSource.value;
52
  let previewClicked = false;
53
 
54
  //if on page load is overall_rating (e.g. on page refresh) text div must be displayed
55
  if(dataSource === 'yasr_ov_ranking') {
56
+ yasrBuilderOvOptions(divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt, divMultiSet);
57
+ }
58
+ else if(dataSource === 'yasr_most_active_users' || dataSource === 'yasr_top_reviewers') {
59
+ yasrBuilderNoStarsOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt, divMultiSet);
60
+ }
61
+ else if(dataSource === 'yasr_visitor_multi_set_ranking') {
62
+ yasrBuilderMultisetOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt, divMultiSet);
63
  }
64
+ else {
65
+ yasrBuilderVvOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt, divMultiSet)
66
  }
67
 
68
  //event listener for all change events
69
  document.addEventListener('change', event => {
70
  if(event.target.id === 'yasr-ranking-source') {
 
71
 
72
+ //be sure to reset the class of the container to the default one
73
+ divParamsContainer.className = '';
74
+ divParamsContainer.classList.add('yasr-settings-row-33');
75
+
76
+ //when event is on main select, be sure the preview div is empty
77
  previewDiv.innerHTML = '';
78
+ //reset attributes
79
+ shortcodeAttributes = yasrReturnShortcodeAttributes();
80
+
81
  if(event.target.value === 'yasr_ov_ranking') {
82
+ yasrBuilderOvOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt, divMultiSet);
83
  }
84
  else if(event.target.value === 'yasr_most_active_users' || event.target.value === 'yasr_top_reviewers') {
85
+ yasrBuilderNoStarsOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt, divMultiSet);
86
+ }
87
+ else if(event.target.value === 'yasr_visitor_multi_set_ranking') {
88
+ yasrBuilderMultisetOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt, divMultiSet);
89
+ //get the value of the first option(array key 0) in the select
90
+ shortcodeAttributes['setid'] = ' setid='+selectMultiset[0].value;
91
  }
92
  //By default, show setting for yasr_most_or_highest_rated_posts
93
  else {
94
+ yasrBuilderVvOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt, divMultiSet)
95
  }
96
+
97
  //be sure shortcodeAttributes is initialized again
 
98
  shortcodeAttributes['name'] = event.target.value;
99
+ shortcode = shortcodeAttributes['name']+shortcodeAttributes['setid'];
100
  }
101
  else {
102
+ if(event.target.id === 'yasr-ranking-multiset-select') {
103
+ shortcodeAttributes['setid'] = ' setid=' + event.target.value;
104
+ }
105
  //use this filter to add new attributes
106
  filterShortcodeAttributes = wp.hooks.applyFilters('yasrBuilderFilterShortcode', shortcodeAttributes);
107
 
108
  //loop the shortcodeAttributes array from 'rows'
109
  //and if the key is found in filterShortcodeAttributes make the assigment
110
+ for(let i=2; shortcodeAttributes.length; i++) {
111
  if(filterShortcodeAttributes.hasOwnProperty(shortcodeAttributes[i])) {
112
  shortcodeAttributes[i] = filterShortcodeAttributes[i];
113
  }
115
 
116
  shortcode =
117
  shortcodeAttributes['name']+
118
+ shortcodeAttributes['setid']+
119
  shortcodeAttributes['rows']+
120
  shortcodeAttributes['view']+
121
  shortcodeAttributes['minvotesmost']+
151
  previewClicked = true;
152
  }
153
 
154
+ /**
155
+ * This function do the fetch that calls admin-ajax / yasr_rankings_preview_shortcode
156
+ *
157
+ * @param event
158
+ */
159
  function yasrBuilderDoFetch(event) {
160
+ const shortcode = selectDataSource.value
161
+ const fullShortcode = document.getElementById('yasr-builder-shortcode').textContent;
162
+
163
+ //in this array we put the shortcode that need yasrDrawRankings() to work
164
+ let shortcodesDrawRankings = [
165
+ 'yasr_ov_ranking',
166
+ 'yasr_most_or_highest_rated_posts',
167
+ 'yasr_visitor_multi_set_ranking'
168
+ ];
169
+
170
+ //hooke here to add shortcode
171
+ shortcodesDrawRankings = wp.hooks.applyFilters('yasrBuilderDrawRankingsShortcodes', shortcodesDrawRankings);
172
+
173
  fetch(ajaxurl +'?action=yasr_rankings_preview_shortcode&shortcode='+shortcode+'&full_shortcode='+fullShortcode)
174
  .then(response => {
175
  if (response.ok === true) {
196
  }
197
  })
198
  .then(response => {
199
+ shortcodesDrawRankings.forEach(element => {
200
+ //if the shortcode is in the array
201
+ if(shortcode === element) {
202
+ yasrDrawRankings();
203
+ }
204
+ });
205
  })
206
  }
207
 
213
  function yasrReturnShortcodeAttributes() {
214
  return {
215
  name: 'yasr_most_or_highest_rated_posts',
216
+ setid: '',
217
  rows: '',
218
  size: '',
219
  view: '',
228
  }
229
 
230
 
231
+ function yasrBuilderOvOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt, divMultiSet) {
232
+ //Here the div must not be 33 but 24
233
+ divParamsContainer.className = '';
234
+ divParamsContainer.classList.add('yasr-settings-row-24');
235
+
236
  //show custom text for overall
237
  divOverallTxt.style.display = '';
238
  divSize.style.display = '';
243
  if(divCpt !== null) {
244
  divCpt.style.display = '';
245
  }
246
+ if(divMultiSet !== null) {
247
+ divMultiSet.style.display = 'none';
248
+ }
249
  }
250
 
251
+ function yasrBuilderVvOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt, divMultiSet) {
252
  divView.style.display = ''
253
  divVotes.style.display = '';
254
  divSize.style.display = '';
258
  if(divCpt !== null) {
259
  divCpt.style.display = '';
260
  }
261
+ if(divMultiSet !== null) {
262
+ divMultiSet.style.display = 'none';
263
+ }
264
  }
265
 
266
+ function yasrBuilderNoStarsOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt, divMultiSet) {
267
  divUsername.style.display = '';
268
  divOverallTxt.style.display = 'none';
269
  divView.style.display = 'none';
270
  divVotes.style.display = 'none';
271
  divSize.style.display = 'none';
272
  divCategory.style.display = 'none';
 
273
  if(divCpt !== null) {
274
  divCpt.style.display = 'none';
275
  }
276
+ if(divMultiSet !== null) {
277
+ divMultiSet.style.display = 'none';
278
+ }
279
+ }
280
+
281
+ function yasrBuilderMultisetOptions (divOverallTxt, divSize, divView, divVotes, divUsername, divCategory, divCpt, divMultiSet) {
282
+ divView.style.display = ''
283
+ divVotes.style.display = '';
284
+ divSize.style.display = '';
285
+ divCategory.style.display = '';
286
+ divOverallTxt.style.display = 'none';
287
+ divUsername.style.display = 'none';
288
+ if(divCpt !== null) {
289
+ divCpt.style.display = '';
290
+ }
291
+ if(divMultiSet !== null) {
292
+ divMultiSet.style.display = '';
293
+ }
294
  }
295
 
296
  }
admin/js/yasr-settings.js CHANGED
@@ -1 +1 @@
1
- !function(t){var e={};function r(a){if(e[a])return e[a].exports;var n=e[a]={i:a,l:!1,exports:{}};return t[a].call(n.exports,n,n.exports,r),n.l=!0,n.exports}r.m=t,r.c=e,r.d=function(t,e,a){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:a})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var a=Object.create(null);if(r.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(a,n,function(e){return t[e]}.bind(null,n));return a},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){r(1),t.exports=r(2)},function(t,e){var r;if(document.getElementsByClassName("nav-tab-active").length>0&&(r=document.getElementsByClassName("nav-tab-active")[0].id),"general_settings"===r){var a=document.getElementById("yasr_auto_insert_switch").checked,n=document.getElementById("yasr-general-options-stars-title-switch").checked,o=document.getElementById("yasr-general-options-text-before-stars-switch").checked;!1===a&&jQuery(".yasr-auto-insert-options-class").prop("disabled",!0),!1===n&&jQuery(".yasr-stars-title-options-class").prop("disabled",!0),document.getElementById("yasr_auto_insert_switch").addEventListener("change",(function(){this.checked?jQuery(".yasr-auto-insert-options-class").prop("disabled",!1):jQuery(".yasr-auto-insert-options-class").prop("disabled",!0)})),document.getElementById("yasr-general-options-stars-title-switch").addEventListener("change",(function(){this.checked?jQuery(".yasr-stars-title-options-class").prop("disabled",!1):jQuery(".yasr-stars-title-options-class").prop("disabled",!0)})),!1===o&&jQuery(".yasr-general-options-text-before").find(":input").prop("disabled",!0),document.getElementById("yasr-general-options-text-before-stars-switch").addEventListener("change",(function(){this.checked?(jQuery(".yasr-general-options-text-before").find(":input").prop("disabled",!1),jQuery("#yasr-general-options-custom-text-before-overall").val("Our Score"),jQuery("#yasr-general-options-custom-text-before-visitor").val("Click to rate this post!"),jQuery("#yasr-general-options-custom-text-after-visitor").val("[Total: %total_count% Average: %average%]"),jQuery("#yasr-general-options-custom-text-must-sign-in").val("You must sign in to vote"),jQuery("#yasr-general-options-custom-text-already-rated").val("You have already voted for this article with %rating%")):jQuery(".yasr-general-options-text-before").find(":input").prop("disabled",!0)}))}if("style_options"===r&&(wp.codeEditor.initialize(document.getElementById("yasr_style_options_textarea"),yasr_cm_settings),jQuery("#yasr-color-scheme-preview-link").on("click",(function(){return jQuery("#yasr-color-scheme-preview").toggle("slow"),!1})),wp.hooks.doAction("yasrStyleOptions")),"manage_multi"===r){var s=parseInt(document.getElementById("n-multiset").value);if(jQuery("#yasr-multi-set-doc-link").on("click",(function(){jQuery("#yasr-multi-set-doc-box").toggle("slow")})),jQuery("#yasr-multi-set-doc-link-hide").on("click",(function(){jQuery("#yasr-multi-set-doc-box").toggle("slow")})),1===s){var i=jQuery("#yasr-edit-form-number-elements").attr("value");i++,jQuery("#yasr-add-field-edit-multiset").on("click",(function(){if(i>9)return jQuery("#yasr-element-limit").show(),jQuery("#yasr-add-field-edit-multiset").hide(),!1;var t=jQuery(document.createElement("tr"));t.html('<td colspan="2">Element #'+i+' <input type="text" name="edit-multi-set-element-'+i+'" value="" ></td>'),t.appendTo("#yasr-table-form-edit-multi-set"),i++}))}else s>1&&(jQuery("#yasr-button-select-set-edit-form").on("click",(function(){var t={action:"yasr_get_multi_set",set_id:jQuery("#yasr_select_edit_set").val()};return jQuery.post(ajaxurl,t,(function(t){jQuery("#yasr-multi-set-response").show(),jQuery("#yasr-multi-set-response").html(t)})),!1})),jQuery(document).ajaxComplete((function(){var t=jQuery("#yasr-edit-form-number-elements").attr("value");t++,jQuery("#yasr-add-field-edit-multiset").on("click",(function(){if(t>9)return jQuery("#yasr-element-limit").show(),jQuery("#yasr-add-field-edit-multiset").hide(),!1;var e=jQuery(document.createElement("tr"));e.html('<td colspan="2">Element #'+t+' <input type="text" name="edit-multi-set-element-'+t+'" value="" ></td>'),e.appendTo("#yasr-table-form-edit-multi-set"),t++}))})))}"migration_tools"===r&&(jQuery("#yasr-import-ratemypost-submit").on("click",(function(){document.getElementById("yasr-import-ratemypost-answer").innerHTML='<img src="'+yasrCommonData.loaderHtml+'"</img>';var t={action:"yasr_import_ratemypost",nonce:document.getElementById("yasr-import-rmp-nonce").value};jQuery.post(ajaxurl,t,(function(t){t=JSON.parse(t),document.getElementById("yasr-import-ratemypost-answer").innerHTML=t}))})),jQuery("#yasr-import-wppr-submit").on("click",(function(){document.getElementById("yasr-import-wppr-answer").innerHTML='<img src="'+yasrCommonData.loaderHtml+'"</img>';var t={action:"yasr_import_wppr",nonce:document.getElementById("yasr-import-wppr-nonce").value};jQuery.post(ajaxurl,t,(function(t){document.getElementById("yasr-import-wppr-answer").innerHTML=t}))})),jQuery("#yasr-import-kksr-submit").on("click",(function(){document.getElementById("yasr-import-kksr-answer").innerHTML='<img src="'+yasrCommonData.loaderHtml+'"</img>';var t={action:"yasr_import_kksr",nonce:document.getElementById("yasr-import-kksr-nonce").value};jQuery.post(ajaxurl,t,(function(t){document.getElementById("yasr-import-kksr-answer").innerHTML=t}))})),jQuery("#yasr-import-mr-submit").on("click",(function(){document.getElementById("yasr-import-mr-answer").innerHTML='<img src="'+yasrCommonData.loaderHtml+'"</img>';var t={action:"yasr_import_mr",nonce:document.getElementById("yasr-import-mr-nonce").value};jQuery.post(ajaxurl,t,(function(t){document.getElementById("yasr-import-mr-answer").innerHTML=t}))})))},function(t,e,r){"use strict";var a,n;r.r(e);var o=new Uint8Array(16);function s(){if(!n&&!(n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return n(o)}var i=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var l=function(t){return"string"==typeof t&&i.test(t)},u=[],c=0;c<256;++c)u.push((c+256).toString(16).substr(1));var d=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(u[t[e+0]]+u[t[e+1]]+u[t[e+2]]+u[t[e+3]]+"-"+u[t[e+4]]+u[t[e+5]]+"-"+u[t[e+6]]+u[t[e+7]]+"-"+u[t[e+8]]+u[t[e+9]]+"-"+u[t[e+10]]+u[t[e+11]]+u[t[e+12]]+u[t[e+13]]+u[t[e+14]]+u[t[e+15]]).toLowerCase();if(!l(r))throw TypeError("Stringified UUID is invalid");return r};for(var m=function(t,e,r){var a=(t=t||{}).random||(t.rng||s)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,e){r=r||0;for(var n=0;n<16;++n)e[r+n]=a[n];return e}return d(a)},y=wp.i18n.__,p=["yasr-rater-stars","yasr-rater-stars-vv","yasr-multiset-visitors-rater"],g=0;g<p.length;g++)f(p[g]);function f(t){var e=document.getElementsByClassName(t);if(e.length>0){if("yasr-rater-stars"!==t&&"yasr-ranking-stars"!==t||function(t){for(var e=0;e<t.length;e++)if(!1===t.item(e).classList.contains("yasr-star-rating")){var r=t.item(e),a=r.id;v(r.getAttribute("data-rater-starsize"),a,r)}}(e),"yasr-rater-stars-vv"===t&&(function(t){for(var e=0;e<t.length;e++)!function(e){if(!1===t.item(e).classList.contains("yasr-star-rating")){var r=t.item(e),a=r.getAttribute("data-rating"),n=r.getAttribute("data-readonly-attribute"),o=r.getAttribute("data-rater-readonly");null===n&&(n=!1),n=b(n),o=b(o),!0===n&&(o=!0);var s=r.getAttribute("data-rater-postid"),i=r.id,l=i.replace("yasr-visitor-votes-rater-",""),u=parseInt(r.getAttribute("data-rater-starsize")),c=r.getAttribute("data-rater-nonce"),d=r.getAttribute("data-issingular"),m="yasr-vv-votes-number-container-"+l,p="yasr-vv-average-container-"+l,g=document.getElementById(m),f=document.getElementById(p),v="yasr-vv-loader-"+l,_=!1;if("yes"===yasrCommonData.ajaxEnabled){var E=r.getAttribute("data-cpt");""===E&&(E="posts");var w="wp/v2/"+E+"/"+s+"?_fields=yasr_visitor_votes&_wpnonce="+yasrCommonData.nonce;jQuery.get(yasrCommonData.restEndpoint+w).done((function(t){var e;(e=!0===n||t.yasr_visitor_votes.stars_attributes.read_only,a=(a=t.yasr_visitor_votes.number_of_votes>0?t.yasr_visitor_votes.sum_votes/t.yasr_visitor_votes.number_of_votes:0).toFixed(1),a=parseFloat(a),h(u,a,s,e,i,l,c,d,g,f,v),!0!==n)&&(null!==g&&(g.innerHTML=t.yasr_visitor_votes.number_of_votes),null!==f&&(f.innerHTML=a),!1!==t.yasr_visitor_votes.stars_attributes.span_bottom&&(_=t.yasr_visitor_votes.stars_attributes.span_bottom,document.getElementById(v).innerHTML=_))})).fail((function(t,e,r,m){console.info(y("YASR ajax call failed. Showing ratings from html","yet-another-stars-rating")),h(u,a,s,o,i,l,c,d,g,f,v),!0!==n&&(document.getElementById("yasr-below-stars-hidden-"+l).style.display="")}))}else h(u,a,s,o,i,l,c,d,g,f,v)}}(e)}(e),"yes"===yasrCommonData.visitorStatsEnabled)){var r=document.getElementsByClassName("yasr-dashicons-visitor-stats");r&&function(t){for(var e=!1,r=0;r<t.length;r++)!function(r){var a="#"+t.item(r).id,n={action:"yasr_stats_visitors_votes",post_id:t.item(r).getAttribute("data-postid")};tippy(a,{content:'<span style="color: #0a0a0a">Loading...</span>',theme:"yasr",arrow:"true",arrowType:"round",onShow:function(t){a!==e&&jQuery.post(yasrCommonData.ajaxurl,n,(function(e){e=JSON.parse(e),t.setContent(e)}))},onHidden:function(){e=a}})}(r)}(r)}"yasr-multiset-visitors-rater"===t&&function(t){for(var e="",r=[],a=0;a<t.length;a++)!function(a){if(!1===t.item(a).classList.contains("yasr-star-rating")){var n=t.item(a),o=n.id,s=n.getAttribute("data-rater-readonly");s=b(s);v(16,o,n,1,s,!1,(function(t,a){var o=n.getAttribute("data-rater-postid"),s=n.getAttribute("data-rater-setid"),i=n.getAttribute("data-rater-set-field-id");t=t.toFixed(1);var l=parseInt(t);this.setRating(l),e={postid:o,setid:s,field:i,rating:l},r.push(e),a()}))}}(a);jQuery(".yasr-send-visitor-multiset").on("click",(function(){var t=this.getAttribute("data-postid"),e=this.getAttribute("data-setid"),a=this.getAttribute("data-nonce");jQuery("#yasr-send-visitor-multiset-"+t+"-"+e).hide(),jQuery("#yasr-loader-multiset-visitor-"+t+"-"+e).show();var n={action:"yasr_visitor_multiset_field_vote",nonce:a,post_id:t,rating:r,set_type:e};jQuery.post(yasrCommonData.ajaxurl,n,(function(r){jQuery("#yasr-loader-multiset-visitor-"+t+"-"+e).text(r)}))}))}(e)}}function v(t,e){var r,a=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:.1,o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],s=arguments.length>5&&void 0!==arguments[5]&&arguments[5],i=arguments.length>6&&void 0!==arguments[6]&&arguments[6];r=a||document.getElementById(e),t=parseInt(t),raterJs({starSize:t,showToolTip:!1,element:r,step:n,readOnly:o,rating:s,rateCallback:i})}function h(t,e,r,a,n,o,s,i,l,u,c){e=parseFloat(e),a=b(a);v(t,n,document.getElementById(n),1,a,e,(function(t,e){document.getElementById(c).innerHTML=yasrCommonData.loaderHtml;var a={action:"yasr_send_visitor_rating",rating:t,post_id:r,nonce_visitor:s,is_singular:i};this.setRating(t),this.disable(),jQuery.post(yasrCommonData.ajaxurl,a,(function(t){t=JSON.parse(t),null!==l&&(l.innerHTML=t.number_of_votes),null!==u&&(u.innerHTML=t.average_rating),document.getElementById(c).innerHTML=t.rating_saved_text})),e()}))}function b(t){return null!=t&&""!==t||(t=!0),"true"!==t&&"1"!==t||(t=!0),"false"!==t&&"0"!==t||(t=!1),t}function _(t){return(_="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function E(t,e){for(var r=0;r<e.length;r++){var a=e[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}function w(t,e){return(w=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function I(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,a=j(t);if(e){var n=j(this).constructor;r=Reflect.construct(a,arguments,n)}else r=a.apply(this,arguments);return k(this,r)}}function k(t,e){return!e||"object"!==_(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function j(t){return(j=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}M();var B=wp.i18n.__,R=wp.element.render;function x(t){var e="yasr-ranking-element-"+m(),r=document.getElementById(t.tableId).dataset.rankingSize;return React.createElement("div",{id:e,ref:function(){return v(r,e,!1,.1,!0,t.rating)}})}function C(t){if(void 0!==t.post.number_of_votes)return React.createElement("span",{className:"yasr-most-rated-text"},"[",B("Total:","yet-another-stars-rating")," ",t.post.number_of_votes,"  ",B("Average:","yet-another-stars-rating")," ",t.post.rating,"]");var e=t.text;return React.createElement("span",{className:"yasr-highest-rated-text"},e," ",t.post.rating)}function Q(t){return React.createElement("td",{className:t.colClass},React.createElement("a",{href:t.post.link},function(t){if("string"!=typeof t||-1===t.indexOf("&"))return t;void 0===a&&(a=document.implementation&&document.implementation.createHTMLDocument?document.implementation.createHTMLDocument("").createElement("textarea"):document.createElement("textarea")),a.innerHTML=t;var e=a.textContent;return a.innerHTML="",e}(t.post.title)))}function T(t){var e="after",r=B("Rating:","yet-another-stars-rating"),a=new URLSearchParams(t.rankingParams);return null!==a.get("text_position")&&(e=a.get("text_position")),null!==a.get("custom_txt")&&(r=a.get("custom_txt")),"before"===e?React.createElement("td",{className:t.colClass},React.createElement(C,{post:t.post,tableId:t.tableId,text:r}),React.createElement(x,{rating:t.post.rating,tableId:t.tableId})):React.createElement("td",{className:t.colClass},React.createElement(x,{rating:t.post.rating,tableId:t.tableId}),React.createElement(C,{post:t.post,tableId:t.tableId,text:r}))}function L(t){var e="",r="";return"overall_rating"===t.source?(e="yasr-top-10-overall-left",r="yasr-top-10-overall-right"):"visitor_votes"===t.source&&(e="yasr-top-10-most-highest-left",r="yasr-top-10-most-highest-right"),React.createElement("tr",{className:t.trClass},React.createElement(Q,{colClass:e,post:t.post}),React.createElement(T,{colClass:r,post:t.post,tableId:t.tableId,rankingParams:t.rankingParams}))}function S(t){return React.createElement("tbody",{id:t.tBodyId,style:{display:t.show}},t.data.map((function(e,r){var a="yasr-rankings-td-colored";return"overall_rating"===t.source&&(a="yasr-rankings-td-white"),r%2==0&&(a="yasr-rankings-td-white","overall_rating"===t.source&&(a="yasr-rankings-td-colored")),React.createElement(L,{key:e.post_id,source:t.source,tableId:t.tableId,rankingParams:t.rankingParams,post:e,trClass:a})})))}var H=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&w(t,e)}(o,React.Component);var e,r,a,n=I(o);function o(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,o),(e=n.call(this,t)).state={error:null,isLoaded:!1,data:[],tableId:t.tableId,source:t.source,rankingParams:t.params},e}return e=o,(r=[{key:"componentDidMount",value:function(){var t=this,e=JSON.parse(document.getElementById(this.state.tableId).dataset.rankingData),r={};if("yes"!==yasrCommonData.ajaxEnabled)console.info(B("Ajax Disabled, getting data from source","yet-another-stars-rating")),this.setState({isLoaded:!0,data:e});else if(!1!==this.state.source){var a=this.returnRestUrl();Promise.all(a.map((function(t){return fetch(t).then((function(t){return!0===t.ok?t.json():(console.info(B("Ajax Call Failed. Getting data from source")),"KO")})).then((function(t){"KO"===t?r=e:("overall_rating"===t.source&&(r=t),"visitor_votes"===t.source&&(r[t.show]=t.data_vv))})).catch((function(t){r=e,console.info(B(t))}))}))).then((function(e){t.setState({isLoaded:!0,data:r})})).catch((function(e){console.info(B(e)),t.setState({isLoaded:!0,data:r})}))}else this.setState({error:B("Invalid Data Source","yet-another-stars-rating")})}},{key:"returnRestUrl",value:function(){var t=""!==this.state.rankingParams?this.state.rankingParams:"",e=this.state.source,r=!1,a="yet-another-stars-rating/v1/yasr-rankings/",n="";if(""!==t&&!1!==t){var o=new URLSearchParams(t);null!==o.get("order_by")&&(n+="order_by="+o.get("order_by")),null!==o.get("limit")&&(n+="&limit="+o.get("limit")),null!==o.get("ctg")?n+="&ctg="+o.get("ctg"):null!==o.get("cpt")&&(n+="&cpt="+o.get("cpt")),""!==n&&(n="&"+(n=n.replace(/\s+/g,"")))}else n="";if("overall_rating"===e&&(r=[yasrCommonData.restEndpoint+a+"?source="+e+n]),"visitor_votes"===e){var s="",i="";if(""!==t){var l=new URLSearchParams(t);null!==l.get("required_votes[most]")&&(s="&required_votes="+l.get("required_votes[most]")),null!==l.get("required_votes[highest]")&&(i="&required_votes="+l.get("required_votes[highest]"))}r=[yasrCommonData.restEndpoint+a+"?show=most&source="+e+n+s,yasrCommonData.restEndpoint+a+"?show=highest&source="+e+n+i]}return r}},{key:"rankingTableHead",value:function(t,e){var r=this.state.tableId,a="link-most-rated-posts-"+r,n="link-highest-rated-posts-"+r;if("visitor_votes"===t){var o=React.createElement("span",null,React.createElement("span",{id:a},B("Most Rated","yet-another-stars-rating"))," | ",React.createElement("a",{href:"#",id:n,onClick:this.switchTBody.bind(this)},B("Highest Rated","yet-another-stars-rating")));return"highest"===e&&(o=React.createElement("span",null,React.createElement("span",{id:n},B("Highest Rated","yet-another-stars-rating"))," | ",React.createElement("a",{href:"#",id:a,onClick:this.switchTBody.bind(this)},B("Most Rated","yet-another-stars-rating")))),React.createElement("thead",null,React.createElement("tr",{className:"yasr-rankings-td-colored yasr-rankings-heading"},React.createElement("th",null,"Post"),React.createElement("th",null,B("Order By","yet-another-stars-rating-pro"),":  ",o)))}return React.createElement(React.Fragment,null)}},{key:"switchTBody",value:function(t){t.preventDefault();var e=t.target.id,r=this.state.tableId,a="link-most-rated-posts-"+r,n="link-highest-rated-posts-"+r,o="most-rated-posts-"+r,s="highest-rated-posts-"+r,i=document.getElementById(e),l=document.createElement("span");l.innerHTML=i.innerHTML,l.id=i.id,i.parentNode.replaceChild(l,i),e===a&&(document.getElementById(s).style.display="none",document.getElementById(o).style.display="",l=document.getElementById(n),i.innerHTML=l.innerHTML,i.id=l.id,l.parentNode.replaceChild(i,l)),e===n&&(document.getElementById(o).style.display="none",document.getElementById(s).style.display="",l=document.getElementById(a),i.innerHTML=l.innerHTML,i.id=l.id,l.parentNode.replaceChild(i,l))}},{key:"rankingTableBody",value:function(){var t=this.state,e=t.data,r=t.source,a=t.rankingParams;if("overall_rating"===r)return React.createElement(S,{data:e.data_overall,tableId:this.state.tableId,tBodyId:"overall_"+this.state.tableId,rankingParams:a,show:"table-row-group",source:r});if("visitor_votes"===r){var n=e.most,o=e.highest,s="most",i="table-row-group",l="none",u=new URLSearchParams(a);return null!==u.get("view")&&(s=u.get("view")),"highest"===s&&(i="none",l="table-row-group"),React.createElement(React.Fragment,null,this.rankingTableHead(r,s),React.createElement(S,{data:n,tableId:this.state.tableId,tBodyId:"most-rated-posts-"+this.state.tableId,rankingParams:a,show:i,source:r}),React.createElement(S,{data:o,tableId:this.state.tableId,tBodyId:"highest-rated-posts-"+this.state.tableId,rankingParams:a,show:l,source:r}))}}},{key:"render",value:function(){var t=this.state,e=t.error,r=t.isLoaded;return e?React.createElement("tbody",null,React.createElement("tr",null,React.createElement("td",null,console.log(e),"Error"))):!1===r?React.createElement("tbody",null,React.createElement("tr",null,React.createElement("td",null,B("Loading Charts","yet-another-stars-rating")))):React.createElement(React.Fragment,null,this.rankingTableBody())}}])&&E(e.prototype,r),a&&E(e,a),o}();function M(){var t=document.getElementsByClassName("yasr-stars-rankings");if(t.length>0)for(var e=0;e<t.length;e++){var r=t.item(e).id,a=t.item(e).dataset.rankingSource,n=JSON.parse(t.item(e).dataset.rankingParams),o=document.getElementById(r),s=!1;"overall_rating"!==a&&"visitor_votes"!==a||(s=a),R(React.createElement(H,{source:s,tableId:r,params:n}),o)}}var P,O=wp.i18n.__;if(document.getElementsByClassName("nav-tab-active").length>0&&(P=document.getElementsByClassName("nav-tab-active")[0].id),"rankings"===P){var A,D=function(t){var e=K.value,r=document.getElementById("yasr-builder-shortcode").textContent;fetch(ajaxurl+"?action=yasr_rankings_preview_shortcode&shortcode="+e+"&full_shortcode="+r).then((function(t){return!0===t.ok?t.json():(console.info(O("Ajax Call Failed. Shortcode preview can't be done","yet-another-stars-rating")),"KO")})).catch((function(t){console.info(t)})).then((function(t){if("KO"!==t){var e=document.createElement("div");e.innerHTML=t,V.childNodes.length>0?V.replaceChild(e,V.childNodes[0]):V.appendChild(e)}})).then((function(t){"yasr_ov_ranking"!==e&&"yasr_most_or_highest_rated_posts"!==e||M()}))},N=function(t,e,r,a,n,o,s){t.style.display="",e.style.display="",o.style.display="",r.style.display="none",a.style.display="none",n.style.display="none",null!==s&&(s.style.display="")},F=function(t,e,r,a,n,o,s){n.style.display="",t.style.display="none",r.style.display="none",a.style.display="none",e.style.display="none",o.style.display="none",null!==s&&(s.style.display="none")};jQuery(".yasr-builder-elements-parents").prop("disabled",!0),jQuery(".yasr-builder-elements-childs").prop("disabled",!0),wp.hooks.doAction("yasrBuilderBegin",".yasr-builder-elements-parents",".yasr-builder-elements-childs");var z=[],U={name:"yasr_most_or_highest_rated_posts",rows:"",size:"",view:"",minvotesmost:"",minvoteshg:"",txtPosition:"",txt:"",display:"",category:"",cpt:""};A=U.name,document.getElementById("yasr-builder-shortcode").textContent="["+A+"]",document.getElementById("yasr-builder-copy-shortcode").setAttribute("data-shortcode","["+A+"]");var q=document.getElementById("yasr-builder-button-preview"),J=document.getElementById("yasr-builder-copy-shortcode"),V=document.getElementById("yasr-builder-preview"),K=document.getElementById("yasr-ranking-source"),Y=document.getElementById("builder-vv-default-view"),G=document.getElementById("builder-vv-required-votes"),$=document.getElementById("builder-stars-size"),W=document.getElementById("builder-overall-text"),X=document.getElementById("builder-username-options"),Z=document.getElementById("builder-category"),tt=document.getElementById("builder-cpt"),et=K.value,rt=!1;"yasr_ov_ranking"===et?N(W,$,Y,G,X,Z,tt):"yasr_most_active_users"!==K.value&&"yasr_top_reviewers"!==K.value||F(W,$,Y,G,X,Z,tt),document.addEventListener("change",(function(t){if("yasr-ranking-source"===t.target.id)V.innerHTML="","yasr_ov_ranking"===t.target.value?N(W,$,Y,G,X,Z,tt):"yasr_most_active_users"===t.target.value||"yasr_top_reviewers"===t.target.value?F(W,$,Y,G,X,Z,tt):function(t,e,r,a,n,o,s){r.style.display="",a.style.display="",e.style.display="",o.style.display="",t.style.display="none",n.style.display="none",null!==s&&(s.style.display="")}(W,$,Y,G,X,Z,tt),(U={name:"yasr_most_or_highest_rated_posts",rows:"",size:"",view:"",minvotesmost:"",minvoteshg:"",txtPosition:"",txt:"",display:"",category:"",cpt:""}).name=t.target.value,A=U.name;else{z=wp.hooks.applyFilters("yasrBuilderFilterShortcode",U);for(var e=1;U.length;e++)z.hasOwnProperty(U[e])&&(U[e]=z[e]);A=U.name+U.rows+U.view+U.minvotesmost+U.minvoteshg+U.size+U.txtPosition+U.txt+U.display+U.category+U.cpt}document.getElementById("yasr-builder-shortcode").textContent="["+A+"]",document.getElementById("yasr-builder-copy-shortcode").setAttribute("data-shortcode","["+A+"]"),!0===rt&&"yasr-ranking-source"!==t.target.id&&"yasr-builder-category-radio"!==t.target.name&&D()})),J.onclick=function(t){var e=document.getElementById(t.target.id);copyToClipboard(e.getAttribute("data-shortcode"))},q.onclick=function(t){D(),rt=!0}}}]);
1
+ !function(t){var e={};function r(a){if(e[a])return e[a].exports;var n=e[a]={i:a,l:!1,exports:{}};return t[a].call(n.exports,n,n.exports,r),n.l=!0,n.exports}r.m=t,r.c=e,r.d=function(t,e,a){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:a})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var a=Object.create(null);if(r.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(a,n,function(e){return t[e]}.bind(null,n));return a},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){r(1),t.exports=r(2)},function(t,e){var r;if(document.getElementsByClassName("nav-tab-active").length>0&&(r=document.getElementsByClassName("nav-tab-active")[0].id),"general_settings"===r){var a=document.getElementById("yasr_auto_insert_switch").checked,n=document.getElementById("yasr-general-options-stars-title-switch").checked,s=document.getElementById("yasr-general-options-text-before-stars-switch").checked;!1===a&&jQuery(".yasr-auto-insert-options-class").prop("disabled",!0),!1===n&&jQuery(".yasr-stars-title-options-class").prop("disabled",!0),document.getElementById("yasr_auto_insert_switch").addEventListener("change",(function(){this.checked?jQuery(".yasr-auto-insert-options-class").prop("disabled",!1):jQuery(".yasr-auto-insert-options-class").prop("disabled",!0)})),document.getElementById("yasr-general-options-stars-title-switch").addEventListener("change",(function(){this.checked?jQuery(".yasr-stars-title-options-class").prop("disabled",!1):jQuery(".yasr-stars-title-options-class").prop("disabled",!0)})),!1===s&&jQuery(".yasr-general-options-text-before").find(":input").prop("disabled",!0),document.getElementById("yasr-general-options-text-before-stars-switch").addEventListener("change",(function(){this.checked?(jQuery(".yasr-general-options-text-before").find(":input").prop("disabled",!1),jQuery("#yasr-general-options-custom-text-before-overall").val("Our Score"),jQuery("#yasr-general-options-custom-text-before-visitor").val("Click to rate this post!"),jQuery("#yasr-general-options-custom-text-after-visitor").val("[Total: %total_count% Average: %average%]"),jQuery("#yasr-general-options-custom-text-must-sign-in").val("You must sign in to vote"),jQuery("#yasr-general-options-custom-text-already-rated").val("You have already voted for this article with %rating%")):jQuery(".yasr-general-options-text-before").find(":input").prop("disabled",!0)}))}if("style_options"===r&&(wp.codeEditor.initialize(document.getElementById("yasr_style_options_textarea"),yasr_cm_settings),jQuery("#yasr-color-scheme-preview-link").on("click",(function(){return jQuery("#yasr-color-scheme-preview").toggle("slow"),!1})),wp.hooks.doAction("yasrStyleOptions")),"manage_multi"===r){var o=parseInt(document.getElementById("n-multiset").value);if(jQuery("#yasr-multi-set-doc-link").on("click",(function(){jQuery("#yasr-multi-set-doc-box").toggle("slow")})),jQuery("#yasr-multi-set-doc-link-hide").on("click",(function(){jQuery("#yasr-multi-set-doc-box").toggle("slow")})),1===o){var i=jQuery("#yasr-edit-form-number-elements").attr("value");i++,jQuery("#yasr-add-field-edit-multiset").on("click",(function(){if(i>9)return jQuery("#yasr-element-limit").show(),jQuery("#yasr-add-field-edit-multiset").hide(),!1;var t=jQuery(document.createElement("tr"));t.html('<td colspan="2">Element #'+i+' <input type="text" name="edit-multi-set-element-'+i+'" value="" ></td>'),t.appendTo("#yasr-table-form-edit-multi-set"),i++}))}else o>1&&(jQuery("#yasr-button-select-set-edit-form").on("click",(function(){var t={action:"yasr_get_multi_set",set_id:jQuery("#yasr_select_edit_set").val()};return jQuery.post(ajaxurl,t,(function(t){jQuery("#yasr-multi-set-response").show(),jQuery("#yasr-multi-set-response").html(t)})),!1})),jQuery(document).ajaxComplete((function(){var t=jQuery("#yasr-edit-form-number-elements").attr("value");t++,jQuery("#yasr-add-field-edit-multiset").on("click",(function(){if(t>9)return jQuery("#yasr-element-limit").show(),jQuery("#yasr-add-field-edit-multiset").hide(),!1;var e=jQuery(document.createElement("tr"));e.html('<td colspan="2">Element #'+t+' <input type="text" name="edit-multi-set-element-'+t+'" value="" ></td>'),e.appendTo("#yasr-table-form-edit-multi-set"),t++}))})))}"migration_tools"===r&&(jQuery("#yasr-import-ratemypost-submit").on("click",(function(){document.getElementById("yasr-import-ratemypost-answer").innerHTML='<img src="'+yasrCommonData.loaderHtml+'"</img>';var t={action:"yasr_import_ratemypost",nonce:document.getElementById("yasr-import-rmp-nonce").value};jQuery.post(ajaxurl,t,(function(t){t=JSON.parse(t),document.getElementById("yasr-import-ratemypost-answer").innerHTML=t}))})),jQuery("#yasr-import-wppr-submit").on("click",(function(){document.getElementById("yasr-import-wppr-answer").innerHTML='<img src="'+yasrCommonData.loaderHtml+'"</img>';var t={action:"yasr_import_wppr",nonce:document.getElementById("yasr-import-wppr-nonce").value};jQuery.post(ajaxurl,t,(function(t){document.getElementById("yasr-import-wppr-answer").innerHTML=t}))})),jQuery("#yasr-import-kksr-submit").on("click",(function(){document.getElementById("yasr-import-kksr-answer").innerHTML='<img src="'+yasrCommonData.loaderHtml+'"</img>';var t={action:"yasr_import_kksr",nonce:document.getElementById("yasr-import-kksr-nonce").value};jQuery.post(ajaxurl,t,(function(t){document.getElementById("yasr-import-kksr-answer").innerHTML=t}))})),jQuery("#yasr-import-mr-submit").on("click",(function(){document.getElementById("yasr-import-mr-answer").innerHTML='<img src="'+yasrCommonData.loaderHtml+'"</img>';var t={action:"yasr_import_mr",nonce:document.getElementById("yasr-import-mr-nonce").value};jQuery.post(ajaxurl,t,(function(t){document.getElementById("yasr-import-mr-answer").innerHTML=t}))})))},function(t,e,r){"use strict";var a,n;r.r(e);var s=new Uint8Array(16);function o(){if(!n&&!(n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return n(s)}var i=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var l=function(t){return"string"==typeof t&&i.test(t)},d=[],u=0;u<256;++u)d.push((u+256).toString(16).substr(1));var c=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(d[t[e+0]]+d[t[e+1]]+d[t[e+2]]+d[t[e+3]]+"-"+d[t[e+4]]+d[t[e+5]]+"-"+d[t[e+6]]+d[t[e+7]]+"-"+d[t[e+8]]+d[t[e+9]]+"-"+d[t[e+10]]+d[t[e+11]]+d[t[e+12]]+d[t[e+13]]+d[t[e+14]]+d[t[e+15]]).toLowerCase();if(!l(r))throw TypeError("Stringified UUID is invalid");return r};for(var y=function(t,e,r){var a=(t=t||{}).random||(t.rng||o)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,e){r=r||0;for(var n=0;n<16;++n)e[r+n]=a[n];return e}return c(a)},m=wp.i18n.__,p=["yasr-rater-stars","yasr-rater-stars-vv","yasr-multiset-visitors-rater"],g=0;g<p.length;g++)f(p[g]);function f(t){var e=document.getElementsByClassName(t);if(e.length>0){if("yasr-rater-stars"!==t&&"yasr-ranking-stars"!==t||function(t){for(var e=0;e<t.length;e++)if(!1===t.item(e).classList.contains("yasr-star-rating")){var r=t.item(e),a=r.id;v(r.getAttribute("data-rater-starsize"),a,r)}}(e),"yasr-rater-stars-vv"===t&&(function(t){for(var e=0;e<t.length;e++)!function(e){if(!1===t.item(e).classList.contains("yasr-star-rating")){var r=t.item(e),a=r.getAttribute("data-rating"),n=r.getAttribute("data-readonly-attribute"),s=r.getAttribute("data-rater-readonly");null===n&&(n=!1),n=b(n),s=b(s),!0===n&&(s=!0);var o=r.getAttribute("data-rater-postid"),i=r.id,l=i.replace("yasr-visitor-votes-rater-",""),d=parseInt(r.getAttribute("data-rater-starsize")),u=r.getAttribute("data-rater-nonce"),c=r.getAttribute("data-issingular"),y="yasr-vv-votes-number-container-"+l,p="yasr-vv-average-container-"+l,g=document.getElementById(y),f=document.getElementById(p),v="yasr-vv-loader-"+l,_=!1;if("yes"===yasrCommonData.ajaxEnabled){var E=r.getAttribute("data-cpt");""===E&&(E="posts");var k="wp/v2/"+E+"/"+o+"?_fields=yasr_visitor_votes&_wpnonce="+yasrCommonData.nonce;jQuery.get(yasrCommonData.restEndpoint+k).done((function(t){var e;(e=!0===n||t.yasr_visitor_votes.stars_attributes.read_only,a=(a=t.yasr_visitor_votes.number_of_votes>0?t.yasr_visitor_votes.sum_votes/t.yasr_visitor_votes.number_of_votes:0).toFixed(1),a=parseFloat(a),h(d,a,o,e,i,l,u,c,g,f,v),!0!==n)&&(null!==g&&(g.innerHTML=t.yasr_visitor_votes.number_of_votes),null!==f&&(f.innerHTML=a),!1!==t.yasr_visitor_votes.stars_attributes.span_bottom&&(_=t.yasr_visitor_votes.stars_attributes.span_bottom,document.getElementById(v).innerHTML=_))})).fail((function(t,e,r,y){console.info(m("YASR ajax call failed. Showing ratings from html","yet-another-stars-rating")),h(d,a,o,s,i,l,u,c,g,f,v),!0!==n&&(document.getElementById("yasr-below-stars-hidden-"+l).style.display="")}))}else h(d,a,o,s,i,l,u,c,g,f,v)}}(e)}(e),"yes"===yasrCommonData.visitorStatsEnabled)){var r=document.getElementsByClassName("yasr-dashicons-visitor-stats");r&&function(t){for(var e=!1,r=0;r<t.length;r++)!function(r){var a="#"+t.item(r).id,n={action:"yasr_stats_visitors_votes",post_id:t.item(r).getAttribute("data-postid")};tippy(a,{content:'<span style="color: #0a0a0a">Loading...</span>',theme:"yasr",arrow:"true",arrowType:"round",onShow:function(t){a!==e&&jQuery.post(yasrCommonData.ajaxurl,n,(function(e){e=JSON.parse(e),t.setContent(e)}))},onHidden:function(){e=a}})}(r)}(r)}"yasr-multiset-visitors-rater"===t&&function(t){for(var e="",r=[],a=0;a<t.length;a++)!function(a){if(!1===t.item(a).classList.contains("yasr-star-rating")){var n=t.item(a),s=n.id,o=n.getAttribute("data-rater-readonly");o=b(o);v(16,s,n,1,o,!1,(function(t,a){var s=n.getAttribute("data-rater-postid"),o=n.getAttribute("data-rater-setid"),i=n.getAttribute("data-rater-set-field-id");t=t.toFixed(1);var l=parseInt(t);this.setRating(l),e={postid:s,setid:o,field:i,rating:l},r.push(e),a()}))}}(a);jQuery(".yasr-send-visitor-multiset").on("click",(function(){var t=this.getAttribute("data-postid"),e=this.getAttribute("data-setid"),a=this.getAttribute("data-nonce");jQuery("#yasr-send-visitor-multiset-"+t+"-"+e).hide(),jQuery("#yasr-loader-multiset-visitor-"+t+"-"+e).show();var n={action:"yasr_visitor_multiset_field_vote",nonce:a,post_id:t,rating:r,set_type:e};jQuery.post(yasrCommonData.ajaxurl,n,(function(r){jQuery("#yasr-loader-multiset-visitor-"+t+"-"+e).text(r)}))}))}(e)}}function v(t,e){var r,a=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:.1,s=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],o=arguments.length>5&&void 0!==arguments[5]&&arguments[5],i=arguments.length>6&&void 0!==arguments[6]&&arguments[6];r=a||document.getElementById(e),t=parseInt(t),raterJs({starSize:t,showToolTip:!1,element:r,step:n,readOnly:s,rating:o,rateCallback:i})}function h(t,e,r,a,n,s,o,i,l,d,u){e=parseFloat(e),a=b(a);v(t,n,document.getElementById(n),1,a,e,(function(t,e){document.getElementById(u).innerHTML=yasrCommonData.loaderHtml;var a={action:"yasr_send_visitor_rating",rating:t,post_id:r,nonce_visitor:o,is_singular:i};this.setRating(t),this.disable(),jQuery.post(yasrCommonData.ajaxurl,a,(function(t){t=JSON.parse(t),null!==l&&(l.innerHTML=t.number_of_votes),null!==d&&(d.innerHTML=t.average_rating),document.getElementById(u).innerHTML=t.rating_saved_text})),e()}))}function b(t){return null!=t&&""!==t||(t=!0),"true"!==t&&"1"!==t||(t=!0),"false"!==t&&"0"!==t||(t=!1),t}function _(t){return(_="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function E(t,e){for(var r=0;r<e.length;r++){var a=e[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}function k(t,e){return(k=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function w(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,a=j(t);if(e){var n=j(this).constructor;r=Reflect.construct(a,arguments,n)}else r=a.apply(this,arguments);return I(this,r)}}function I(t,e){return!e||"object"!==_(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function j(t){return(j=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}M();var B=wp.i18n.__,R=wp.element.render;function x(t){var e="yasr-ranking-element-"+y(),r=document.getElementById(t.tableId).dataset.rankingSize;return React.createElement("div",{id:e,ref:function(){return v(r,e,!1,.1,!0,t.rating)}})}function C(t){if(void 0!==t.post.number_of_votes)return React.createElement("span",{className:"yasr-most-rated-text"},"[",B("Total:","yet-another-stars-rating")," ",t.post.number_of_votes,"  ",B("Average:","yet-another-stars-rating")," ",t.post.rating,"]");var e=t.text;return React.createElement("span",{className:"yasr-highest-rated-text"},e," ",t.post.rating)}function Q(t){return React.createElement("td",{className:t.colClass},React.createElement("a",{href:t.post.link},function(t){if("string"!=typeof t||-1===t.indexOf("&"))return t;void 0===a&&(a=document.implementation&&document.implementation.createHTMLDocument?document.implementation.createHTMLDocument("").createElement("textarea"):document.createElement("textarea")),a.innerHTML=t;var e=a.textContent;return a.innerHTML="",e}(t.post.title)))}function L(t){var e="after",r=B("Rating:","yet-another-stars-rating"),a=new URLSearchParams(t.rankingParams);return null!==a.get("text_position")&&(e=a.get("text_position")),null!==a.get("custom_txt")&&(r=a.get("custom_txt")),"before"===e?React.createElement("td",{className:t.colClass},React.createElement(C,{post:t.post,tableId:t.tableId,text:r}),React.createElement(x,{rating:t.post.rating,tableId:t.tableId})):React.createElement("td",{className:t.colClass},React.createElement(x,{rating:t.post.rating,tableId:t.tableId}),React.createElement(C,{post:t.post,tableId:t.tableId,text:r}))}function T(t){var e="",r="";return"overall_rating"===t.source?(e="yasr-top-10-overall-left",r="yasr-top-10-overall-right"):"visitor_votes"===t.source&&(e="yasr-top-10-most-highest-left",r="yasr-top-10-most-highest-right"),React.createElement("tr",{className:t.trClass},React.createElement(Q,{colClass:e,post:t.post}),React.createElement(L,{colClass:r,post:t.post,tableId:t.tableId,rankingParams:t.rankingParams}))}function S(t){return React.createElement("tbody",{id:t.tBodyId,style:{display:t.show}},t.data.map((function(e,r){var a="yasr-rankings-td-colored";return"overall_rating"===t.source&&(a="yasr-rankings-td-white"),r%2==0&&(a="yasr-rankings-td-white","overall_rating"===t.source&&(a="yasr-rankings-td-colored")),React.createElement(T,{key:e.post_id,source:t.source,tableId:t.tableId,rankingParams:t.rankingParams,post:e,trClass:a})})))}var H=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&k(t,e)}(s,React.Component);var e,r,a,n=w(s);function s(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,s),(e=n.call(this,t)).state={error:null,isLoaded:!1,data:[],tableId:t.tableId,source:t.source,rankingParams:t.params},e}return e=s,(r=[{key:"componentDidMount",value:function(){var t=this,e=JSON.parse(document.getElementById(this.state.tableId).dataset.rankingData),r={};if("yes"!==yasrCommonData.ajaxEnabled)console.info(B("Ajax Disabled, getting data from source","yet-another-stars-rating")),this.setState({isLoaded:!0,data:e});else if(this.state.source){var a=this.returnRestUrl();Promise.all(a.map((function(t){return fetch(t).then((function(t){return!0===t.ok?t.json():(console.info(B("Ajax Call Failed. Getting data from source")),"KO")})).then((function(t){"KO"===t?r=e:"overall_rating"===t.source?r=t:r[t.show]=t.data_vv})).catch((function(t){r=e,console.info(B(t))}))}))).then((function(e){t.setState({isLoaded:!0,data:r})})).catch((function(e){console.info(B(e)),t.setState({isLoaded:!0,data:r})}))}else this.setState({error:B("Invalid Data Source","yet-another-stars-rating")})}},{key:"returnRestUrl",value:function(){var t,e=""!==this.state.rankingParams?this.state.rankingParams:"",r=this.state.source,a="yet-another-stars-rating/v1/yasr-rankings/",n="";if(""!==e&&!1!==e){var s=new URLSearchParams(e);null!==s.get("order_by")&&(n+="order_by="+s.get("order_by")),null!==s.get("limit")&&(n+="&limit="+s.get("limit")),null!==s.get("ctg")?n+="&ctg="+s.get("ctg"):null!==s.get("cpt")&&(n+="&cpt="+s.get("cpt")),""!==n&&(n="&"+(n=n.replace(/\s+/g,""))),"visitor_multi"===r&&null!==s.get("setid")&&(n+="&setid="+s.get("setid"))}else n="";if("overall_rating"===r)t=[yasrCommonData.restEndpoint+a+"?source="+r+n];else{var o="",i="";if(""!==e){var l=new URLSearchParams(e);null!==l.get("required_votes[most]")&&(o="&required_votes="+l.get("required_votes[most]")),null!==l.get("required_votes[highest]")&&(i="&required_votes="+l.get("required_votes[highest]"))}t=[yasrCommonData.restEndpoint+a+"?show=most&source="+r+n+o,yasrCommonData.restEndpoint+a+"?show=highest&source="+r+n+i]}return t}},{key:"rankingTableHead",value:function(t,e){var r=this.state.tableId,a="link-most-rated-posts-"+r,n="link-highest-rated-posts-"+r;if("overall_rating"!==t){var s=React.createElement("span",null,React.createElement("span",{id:a},B("Most Rated","yet-another-stars-rating"))," | ",React.createElement("a",{href:"#",id:n,onClick:this.switchTBody.bind(this)},B("Highest Rated","yet-another-stars-rating")));return"highest"===e&&(s=React.createElement("span",null,React.createElement("span",{id:n},B("Highest Rated","yet-another-stars-rating"))," | ",React.createElement("a",{href:"#",id:a,onClick:this.switchTBody.bind(this)},B("Most Rated","yet-another-stars-rating")))),React.createElement("thead",null,React.createElement("tr",{className:"yasr-rankings-td-colored yasr-rankings-heading"},React.createElement("th",null,"Post"),React.createElement("th",null,B("Order By","yet-another-stars-rating-pro"),":  ",s)))}return React.createElement(React.Fragment,null)}},{key:"switchTBody",value:function(t){t.preventDefault();var e=t.target.id,r=this.state.tableId,a="link-most-rated-posts-"+r,n="link-highest-rated-posts-"+r,s="most-rated-posts-"+r,o="highest-rated-posts-"+r,i=document.getElementById(e),l=document.createElement("span");l.innerHTML=i.innerHTML,l.id=i.id,i.parentNode.replaceChild(l,i),e===a&&(document.getElementById(o).style.display="none",document.getElementById(s).style.display="",l=document.getElementById(n),i.innerHTML=l.innerHTML,i.id=l.id,l.parentNode.replaceChild(i,l)),e===n&&(document.getElementById(s).style.display="none",document.getElementById(o).style.display="",l=document.getElementById(a),i.innerHTML=l.innerHTML,i.id=l.id,l.parentNode.replaceChild(i,l))}},{key:"rankingTableBody",value:function(){var t=this.state,e=t.data,r=t.source,a=t.rankingParams;if("overall_rating"===r)return React.createElement(S,{data:e.data_overall,tableId:this.state.tableId,tBodyId:"overall_"+this.state.tableId,rankingParams:a,show:"table-row-group",source:r});var n=e.most,s=e.highest,o="most",i="table-row-group",l="none",d=new URLSearchParams(a);return null!==d.get("view")&&(o=d.get("view")),"highest"===o&&(i="none",l="table-row-group"),React.createElement(React.Fragment,null,this.rankingTableHead(r,o),React.createElement(S,{data:n,tableId:this.state.tableId,tBodyId:"most-rated-posts-"+this.state.tableId,rankingParams:a,show:i,source:r}),React.createElement(S,{data:s,tableId:this.state.tableId,tBodyId:"highest-rated-posts-"+this.state.tableId,rankingParams:a,show:l,source:r}))}},{key:"render",value:function(){var t=this.state,e=t.error,r=t.isLoaded;return e?React.createElement("tbody",null,React.createElement("tr",null,React.createElement("td",null,console.log(e),"Error"))):!1===r?React.createElement("tbody",null,React.createElement("tr",null,React.createElement("td",null,B("Loading Charts","yet-another-stars-rating")))):React.createElement(React.Fragment,null,this.rankingTableBody())}}])&&E(e.prototype,r),a&&E(e,a),s}();function M(){var t=document.getElementsByClassName("yasr-stars-rankings");if(t.length>0)for(var e=0;e<t.length;e++){var r=t.item(e).id,a=JSON.parse(t.item(e).dataset.rankingSource),n=JSON.parse(t.item(e).dataset.rankingParams),s=document.getElementById(r);R(React.createElement(H,{source:a,tableId:r,params:n}),s)}}var O,P=wp.i18n.__;if(document.getElementsByClassName("nav-tab-active").length>0&&(O=document.getElementsByClassName("nav-tab-active")[0].id),"rankings"===O){var A,N=function(t){var e=G.value,r=document.getElementById("yasr-builder-shortcode").textContent,a=["yasr_ov_ranking","yasr_most_or_highest_rated_posts","yasr_visitor_multi_set_ranking"];a=wp.hooks.applyFilters("yasrBuilderDrawRankingsShortcodes",a),fetch(ajaxurl+"?action=yasr_rankings_preview_shortcode&shortcode="+e+"&full_shortcode="+r).then((function(t){return!0===t.ok?t.json():(console.info(P("Ajax Call Failed. Shortcode preview can't be done","yet-another-stars-rating")),"KO")})).catch((function(t){console.info(t)})).then((function(t){if("KO"!==t){var e=document.createElement("div");e.innerHTML=t,Y.childNodes.length>0?Y.replaceChild(e,Y.childNodes[0]):Y.appendChild(e)}})).then((function(t){a.forEach((function(t){e===t&&M()}))}))},D=function(t,e,r,a,n,s,o,i){W.className="",W.classList.add("yasr-settings-row-24"),t.style.display="",e.style.display="",s.style.display="",r.style.display="none",a.style.display="none",n.style.display="none",null!==o&&(o.style.display=""),null!==i&&(i.style.display="none")},F=function(t,e,r,a,n,s,o,i){r.style.display="",a.style.display="",e.style.display="",s.style.display="",t.style.display="none",n.style.display="none",null!==o&&(o.style.display=""),null!==i&&(i.style.display="none")},z=function(t,e,r,a,n,s,o,i){n.style.display="",t.style.display="none",r.style.display="none",a.style.display="none",e.style.display="none",s.style.display="none",null!==o&&(o.style.display="none"),null!==i&&(i.style.display="none")},U=function(t,e,r,a,n,s,o,i){r.style.display="",a.style.display="",e.style.display="",s.style.display="",t.style.display="none",n.style.display="none",null!==o&&(o.style.display=""),null!==i&&(i.style.display="")};jQuery(".yasr-builder-elements-parents").prop("disabled",!0),jQuery(".yasr-builder-elements-childs").prop("disabled",!0),wp.hooks.doAction("yasrBuilderBegin",".yasr-builder-elements-parents",".yasr-builder-elements-childs");var q=[],J={name:"yasr_most_or_highest_rated_posts",setid:"",rows:"",size:"",view:"",minvotesmost:"",minvoteshg:"",txtPosition:"",txt:"",display:"",category:"",cpt:""};A=J.name,document.getElementById("yasr-builder-shortcode").textContent="["+A+"]",document.getElementById("yasr-builder-copy-shortcode").setAttribute("data-shortcode","["+A+"]");var V=document.getElementById("yasr-builder-button-preview"),K=document.getElementById("yasr-builder-copy-shortcode"),Y=document.getElementById("yasr-builder-preview"),G=document.getElementById("yasr-ranking-source"),$=document.getElementById("yasr-ranking-multiset-select"),W=document.getElementById("yasr-builder-params-container"),X=document.getElementById("builder-vv-default-view"),Z=document.getElementById("builder-vv-required-votes"),tt=document.getElementById("builder-stars-size"),et=document.getElementById("builder-overall-text"),rt=document.getElementById("builder-username-options"),at=document.getElementById("builder-category"),nt=document.getElementById("builder-cpt"),st=document.getElementById("yasr-ranking-multiset"),ot=G.value,it=!1;"yasr_ov_ranking"===ot?D(et,tt,X,Z,rt,at,nt,st):"yasr_most_active_users"===ot||"yasr_top_reviewers"===ot?z(et,tt,X,Z,rt,at,nt,st):"yasr_visitor_multi_set_ranking"===ot?U(et,tt,X,Z,rt,at,nt,st):F(et,tt,X,Z,rt,at,nt,st),document.addEventListener("change",(function(t){if("yasr-ranking-source"===t.target.id)W.className="",W.classList.add("yasr-settings-row-33"),Y.innerHTML="",J={name:"yasr_most_or_highest_rated_posts",setid:"",rows:"",size:"",view:"",minvotesmost:"",minvoteshg:"",txtPosition:"",txt:"",display:"",category:"",cpt:""},"yasr_ov_ranking"===t.target.value?D(et,tt,X,Z,rt,at,nt,st):"yasr_most_active_users"===t.target.value||"yasr_top_reviewers"===t.target.value?z(et,tt,X,Z,rt,at,nt,st):"yasr_visitor_multi_set_ranking"===t.target.value?(U(et,tt,X,Z,rt,at,nt,st),J.setid=" setid="+$[0].value):F(et,tt,X,Z,rt,at,nt,st),J.name=t.target.value,A=J.name+J.setid;else{"yasr-ranking-multiset-select"===t.target.id&&(J.setid=" setid="+t.target.value),q=wp.hooks.applyFilters("yasrBuilderFilterShortcode",J);for(var e=2;J.length;e++)q.hasOwnProperty(J[e])&&(J[e]=q[e]);A=J.name+J.setid+J.rows+J.view+J.minvotesmost+J.minvoteshg+J.size+J.txtPosition+J.txt+J.display+J.category+J.cpt}document.getElementById("yasr-builder-shortcode").textContent="["+A+"]",document.getElementById("yasr-builder-copy-shortcode").setAttribute("data-shortcode","["+A+"]"),!0===it&&"yasr-ranking-source"!==t.target.id&&"yasr-builder-category-radio"!==t.target.name&&N()})),K.onclick=function(t){var e=document.getElementById(t.target.id);copyToClipboard(e.getAttribute("data-shortcode"))},V.onclick=function(t){N(),it=!0}}}]);
admin/settings/classes/YasrSettingsRankings.php CHANGED
@@ -23,10 +23,18 @@ if (!defined('ABSPATH')) {
23
 
24
  class YasrSettingsRankings {
25
 
26
- public $custom_post_types;
 
 
27
 
28
  public function __construct($custom_post_types) {
29
  $this->custom_post_types = $custom_post_types;
 
 
 
 
 
 
30
  }
31
 
32
  public function selectRanking () {
@@ -44,13 +52,21 @@ class YasrSettingsRankings {
44
  'yasr_most_active_users',
45
  'yasr_top_reviewers'
46
  );
 
 
 
 
 
 
 
 
47
  $name = 'yasr-ranking-source';
48
  $id = 'yasr-ranking-source';
49
 
50
  echo YasrPhpFieldsHelper::select(
51
  '',
52
  '',
53
- $source_array,
54
  $name,
55
  $id,
56
  'yasr_visitor_votes'
@@ -162,9 +178,7 @@ class YasrSettingsRankings {
162
  </select>
163
  </label>
164
  <br />
165
- <?php
166
- echo sprintf(__(" votes required %s for most rated", 'yet-another-stars-rating'), '<br />');
167
- ?>
168
  </div>
169
 
170
  <!-- Min. number of votes for highest rated -->
@@ -185,9 +199,7 @@ class YasrSettingsRankings {
185
  </select>
186
  </label>
187
  <br />
188
- <?php
189
- echo sprintf(__(" votes required %s for highest rated", 'yet-another-stars-rating'), '<br />');
190
- ?>
191
  </div>
192
  </div>
193
  <?php
@@ -368,4 +380,32 @@ class YasrSettingsRankings {
368
  </div>
369
  <?php
370
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
  }
23
 
24
  class YasrSettingsRankings {
25
 
26
+ public $custom_post_types;
27
+ private $multi_set_array;
28
+ private $n_multi_set;
29
 
30
  public function __construct($custom_post_types) {
31
  $this->custom_post_types = $custom_post_types;
32
+ $this->multi_set_array = YasrMultiSetData::returnMultiSetNames();
33
+
34
+ global $wpdb;
35
+ //wpdb->num_rows always store the the count number of rows of the last query
36
+ $this->n_multi_set = $wpdb->num_rows;
37
+
38
  }
39
 
40
  public function selectRanking () {
52
  'yasr_most_active_users',
53
  'yasr_top_reviewers'
54
  );
55
+
56
+ if($this->n_multi_set > 0) {
57
+ $source_array[] = 'yasr_visitor_multi_set_ranking';
58
+ }
59
+
60
+ //Use this filter to add (or remove) new elements
61
+ $select_array = apply_filters('yasr_settings_select_ranking', $source_array);
62
+
63
  $name = 'yasr-ranking-source';
64
  $id = 'yasr-ranking-source';
65
 
66
  echo YasrPhpFieldsHelper::select(
67
  '',
68
  '',
69
+ $select_array,
70
  $name,
71
  $id,
72
  'yasr_visitor_votes'
178
  </select>
179
  </label>
180
  <br />
181
+ <?php _e('votes required for most rated', 'yet-another-stars-rating'); ?>
 
 
182
  </div>
183
 
184
  <!-- Min. number of votes for highest rated -->
199
  </select>
200
  </label>
201
  <br />
202
+ <?php _e('votes required for highest rated', 'yet-another-stars-rating'); ?>
 
 
203
  </div>
204
  </div>
205
  <?php
380
  </div>
381
  <?php
382
  }
383
+
384
+ public function multiset() {
385
+ if ($this->n_multi_set > 0) {
386
+ ?>
387
+ <div class="yasr-builder-div-fluid" id="yasr-ranking-multiset">
388
+ <strong>
389
+ <?php
390
+ _e('Choose Multi Set', 'yet-another-stars-rating');
391
+ ?>
392
+ </strong>
393
+ <!-- Min. number of votes for most rated -->
394
+ <div>
395
+ <label for="yasr-ranking-multiset-select">
396
+ <select id="yasr-ranking-multiset-select" autocomplete="off">
397
+ <?php
398
+ foreach ($this->multi_set_array as $name) {
399
+ echo "<option value='$name->set_id'>$name->set_name</option>";
400
+ } //End foreach
401
+ ?>
402
+ </select>
403
+ </label>
404
+ </div>
405
+ </div>
406
+ <?php
407
+ }
408
+
409
+ }
410
+
411
  }
admin/settings/migrations/yasr-settings-migration-page.php CHANGED
@@ -36,7 +36,7 @@ $plugin_imported = get_option('yasr_plugin_imported');
36
  $rating_plugin_exists = new YasrImportRatingPlugins;
37
 
38
  if (!$rating_plugin_exists->yasr_search_wppr() && !$rating_plugin_exists->yasr_search_rmp()
39
- && !$rating_plugin_exists->yasr_search_kksr() && !!$rating_plugin_exists->yasr_search_mr()) {
40
  ?>
41
  <span class="title-noplugin-found">
42
  <?php _e('No supported plugin has been found' , 'yet-another-stars-rating'); ?>
36
  $rating_plugin_exists = new YasrImportRatingPlugins;
37
 
38
  if (!$rating_plugin_exists->yasr_search_wppr() && !$rating_plugin_exists->yasr_search_rmp()
39
+ && !$rating_plugin_exists->yasr_search_kksr() && !$rating_plugin_exists->yasr_search_mr()) {
40
  ?>
41
  <span class="title-noplugin-found">
42
  <?php _e('No supported plugin has been found' , 'yet-another-stars-rating'); ?>
admin/settings/rankings/yasr-ranking-builder.php CHANGED
@@ -54,10 +54,12 @@ $cr_setting = new YasrSettingsRankings($custom_post_types);
54
  </div>
55
 
56
  <!-- First Row -->
57
- <div class="yasr-builder-ranking-container">
58
  <?php
59
  //Data Source
60
  $cr_setting->selectRanking();
 
 
61
  //rows
62
  $cr_setting->rows();
63
  //default view or VV
@@ -74,7 +76,7 @@ $cr_setting = new YasrSettingsRankings($custom_post_types);
74
  </div>
75
 
76
  <!--Second Row -->
77
- <div class="yasr-builder-ranking-container" style="margin-top: 15px">
78
  <?php
79
  $cr_setting->categories();
80
 
54
  </div>
55
 
56
  <!-- First Row -->
57
+ <div id="yasr-builder-params-container" class="yasr-settings-row-33">
58
  <?php
59
  //Data Source
60
  $cr_setting->selectRanking();
61
+ //settings for select set id
62
+ $cr_setting->multiset();
63
  //rows
64
  $cr_setting->rows();
65
  //default view or VV
76
  </div>
77
 
78
  <!--Second Row -->
79
+ <div class="yasr-builder-ranking-container" style="margin-top: 20px">
80
  <?php
81
  $cr_setting->categories();
82
 
admin/yasr-admin-actions-ajax.php CHANGED
@@ -36,9 +36,13 @@ function yasr_users_dashboard_widget_callback() {
36
  $log_widget->userWidget();
37
  } //End callback function
38
 
 
39
  add_action('wp_ajax_yasr_rankings_preview_shortcode', 'yasr_rankings_preview_shortcode');
 
 
 
 
40
  function yasr_rankings_preview_shortcode() {
41
-
42
  if(!isset($_GET['shortcode']) || !isset($_GET['full_shortcode'])) {
43
  die();
44
  }
36
  $log_widget->userWidget();
37
  } //End callback function
38
 
39
+ //Action to print the shortcode in "Ranking tab"
40
  add_action('wp_ajax_yasr_rankings_preview_shortcode', 'yasr_rankings_preview_shortcode');
41
+ /**
42
+ * @author Dario Curvino <@dudo>
43
+ * @since 2.6.3
44
+ */
45
  function yasr_rankings_preview_shortcode() {
 
46
  if(!isset($_GET['shortcode']) || !isset($_GET['full_shortcode'])) {
47
  die();
48
  }
includes/classes/YasrMultiSetData.php CHANGED
@@ -28,11 +28,6 @@ if (!defined('ABSPATH')) {
28
  * Class YasrMultiSetData
29
  */
30
  class YasrMultiSetData {
31
- /**
32
- * @var array $array_to_return
33
- */
34
- public static $array_to_return = array();
35
-
36
 
37
  /****** Get multi set name ******/
38
  public static function returnMultiSetNames() {
@@ -156,6 +151,7 @@ class YasrMultiSetData {
156
  */
157
 
158
  public static function returnArrayFieldsRatingsAuthor($set_id, $set_fields, $post_id=false) {
 
159
  $set_id = (int)$set_id;
160
 
161
  if (!$set_fields) {
@@ -173,9 +169,9 @@ class YasrMultiSetData {
173
  $i = 0;
174
  //always returns field id and name
175
  foreach ($set_fields as $fields_ids_and_names) {
176
- self::$array_to_return[$i]['id'] = (int) $fields_ids_and_names['id'];
177
- self::$array_to_return[$i]['name'] = $fields_ids_and_names['name'];
178
- self::$array_to_return[$i]['average_rating'] = 0;
179
 
180
  //if there is post meta
181
  if ($set_post_meta_values) {
@@ -186,9 +182,9 @@ class YasrMultiSetData {
186
  //loop the saved arrays
187
  foreach ($saved_set_id['fields_and_ratings'] as $single_value) {
188
  //if field id is the same, add the rating
189
- if (self::$array_to_return[$i]['id'] === $single_value->field) {
190
  //save the rating
191
- self::$array_to_return[$i]['average_rating'] = $single_value->rating;
192
  }
193
  }
194
  }
@@ -197,7 +193,7 @@ class YasrMultiSetData {
197
  //this is for list the set names
198
  $i ++;
199
  }
200
- return self::$array_to_return;
201
  }
202
 
203
  /** This functions returns an array with all the value to print the multiset
@@ -222,7 +218,6 @@ class YasrMultiSetData {
222
  */
223
 
224
  public static function returnArrayFieldsRatingsVisitor($set_id, $set_fields, $post_id=false) {
225
-
226
  $array_to_return = array();
227
 
228
  global $wpdb;
28
  * Class YasrMultiSetData
29
  */
30
  class YasrMultiSetData {
 
 
 
 
 
31
 
32
  /****** Get multi set name ******/
33
  public static function returnMultiSetNames() {
151
  */
152
 
153
  public static function returnArrayFieldsRatingsAuthor($set_id, $set_fields, $post_id=false) {
154
+ $array_to_return = array ();
155
  $set_id = (int)$set_id;
156
 
157
  if (!$set_fields) {
169
  $i = 0;
170
  //always returns field id and name
171
  foreach ($set_fields as $fields_ids_and_names) {
172
+ $array_to_return[$i]['id'] = (int) $fields_ids_and_names['id'];
173
+ $array_to_return[$i]['name'] = $fields_ids_and_names['name'];
174
+ $array_to_return[$i]['average_rating'] = 0;
175
 
176
  //if there is post meta
177
  if ($set_post_meta_values) {
182
  //loop the saved arrays
183
  foreach ($saved_set_id['fields_and_ratings'] as $single_value) {
184
  //if field id is the same, add the rating
185
+ if ($array_to_return[$i]['id'] === $single_value->field) {
186
  //save the rating
187
+ $array_to_return[$i]['average_rating'] = $single_value->rating;
188
  }
189
  }
190
  }
193
  //this is for list the set names
194
  $i ++;
195
  }
196
+ return $array_to_return;
197
  }
198
 
199
  /** This functions returns an array with all the value to print the multiset
218
  */
219
 
220
  public static function returnArrayFieldsRatingsVisitor($set_id, $set_fields, $post_id=false) {
 
221
  $array_to_return = array();
222
 
223
  global $wpdb;
includes/classes/YasrPhpFieldsHelper.php CHANGED
@@ -289,9 +289,10 @@ if (!class_exists('YasrPhpFieldsHelper') ) {
289
  * @param $class
290
  * @param bool $db_value
291
  * @param bool $id
292
- * return void
293
  * @param bool $txt_label
 
294
  *
 
295
  * @since 2.3.3
296
  */
297
  public static function radioSelectSize($name, $class, $db_value=false, $id=false, $txt_label=true, $newline=false) {
289
  * @param $class
290
  * @param bool $db_value
291
  * @param bool $id
 
292
  * @param bool $txt_label
293
+ * @param bool $newline
294
  *
295
+ * return void
296
  * @since 2.3.3
297
  */
298
  public static function radioSelectSize($name, $class, $db_value=false, $id=false, $txt_label=true, $newline=false) {
includes/classes/YasrRankingData.php CHANGED
@@ -37,13 +37,13 @@ class YasrRankingData {
37
  public static function rankingOverallGetResults($atts) {
38
  global $wpdb;
39
 
40
- //return custom query here
41
  //must returns rating and post_id
42
  $query = apply_filters('yasr_rankings_query_ov', $atts);
43
 
44
- //if query === $sql_params (both are falses) means that filters doesn't exists
45
  if($query === $atts) {
46
- //default query
47
  $query = "SELECT pm.meta_value AS rating,
48
  pm.post_id AS post_id
49
  FROM $wpdb->postmeta AS pm,
@@ -55,42 +55,38 @@ class YasrRankingData {
55
  ORDER BY pm.meta_value DESC,
56
  pm.post_id
57
  LIMIT 10";
58
- }
59
 
60
- $query_result = $wpdb->get_results($query);
 
 
 
61
 
62
- if ($query_result) {
63
- return $query_result;
64
  }
65
  return false;
66
  }
67
 
68
  /**
69
- * Run $wpdb->get_results for VV
70
  *
71
  * @author Dario Curvino <@dudo>
72
  * @since 2.5.2
73
  *
74
- * @param bool|array $atts
75
  * @param $ranking
76
- * @param bool $required_votes
77
  *
78
  * @return array|false|object|void
79
  */
80
 
81
- public static function rankingVVGetResults($atts, $ranking, $required_votes=false) {
82
  global $wpdb;
83
 
84
- if($required_votes !== false) {
85
- $atts['required_votes'] = $required_votes;
86
- }
87
-
88
  //hooks here to return a query
89
  $query = apply_filters('yasr_rankings_query_vv', $atts, $ranking);
90
 
91
  //if no custom query is hooked
92
  if($query === $atts) {
93
-
94
  $common_query = "SELECT post_id,
95
  COUNT(post_id) AS number_of_votes,
96
  ROUND(SUM(vote) / COUNT(post_id),1) AS rating
@@ -112,9 +108,15 @@ class YasrRankingData {
112
  $limit = ' LIMIT 10';
113
  $query = $common_query . $order_by . $limit;
114
 
 
 
 
115
  }
116
 
117
- return $wpdb->get_results($query);
 
 
 
118
  }
119
 
120
  /***
@@ -147,9 +149,16 @@ class YasrRankingData {
147
  ORDER BY total_count DESC
148
  LIMIT 5";
149
 
 
 
 
 
150
  }
151
 
152
- return $wpdb->get_results($query);
 
 
 
153
  }
154
 
155
  /***
@@ -164,7 +173,7 @@ class YasrRankingData {
164
 
165
  //return custom query here
166
  //must returns rating and post_id
167
- $query = apply_filters('yasr_rankings_query_tu', $atts);
168
 
169
  //if query === $sql_params (both are falses) means that filters doesn't exists
170
  if($query === $atts) {
@@ -178,8 +187,73 @@ class YasrRankingData {
178
  ORDER BY ( total_count ) DESC
179
  LIMIT 10";
180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  }
182
 
183
- return $wpdb->get_results($query);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  }
 
185
  }
37
  public static function rankingOverallGetResults($atts) {
38
  global $wpdb;
39
 
40
+ //return custom query_result here
41
  //must returns rating and post_id
42
  $query = apply_filters('yasr_rankings_query_ov', $atts);
43
 
44
+ //if query_results === $sql_params means that filters doesn't exists
45
  if($query === $atts) {
46
+ //default query_results
47
  $query = "SELECT pm.meta_value AS rating,
48
  pm.post_id AS post_id
49
  FROM $wpdb->postmeta AS pm,
55
  ORDER BY pm.meta_value DESC,
56
  pm.post_id
57
  LIMIT 10";
 
58
 
59
+ $query_results = $wpdb->get_results($query);
60
+ } else {
61
+ $query_results = $query;
62
+ }
63
 
64
+ if ($query_results) {
65
+ return $query_results;
66
  }
67
  return false;
68
  }
69
 
70
  /**
71
+ * Returns yasr_most_or_highest_rated_posts with no params and 10 rows.
72
  *
73
  * @author Dario Curvino <@dudo>
74
  * @since 2.5.2
75
  *
76
+ * @param array $atts
77
  * @param $ranking
 
78
  *
79
  * @return array|false|object|void
80
  */
81
 
82
+ public static function rankingVVGetResults($atts, $ranking) {
83
  global $wpdb;
84
 
 
 
 
 
85
  //hooks here to return a query
86
  $query = apply_filters('yasr_rankings_query_vv', $atts, $ranking);
87
 
88
  //if no custom query is hooked
89
  if($query === $atts) {
 
90
  $common_query = "SELECT post_id,
91
  COUNT(post_id) AS number_of_votes,
92
  ROUND(SUM(vote) / COUNT(post_id),1) AS rating
108
  $limit = ' LIMIT 10';
109
  $query = $common_query . $order_by . $limit;
110
 
111
+ $query_results = $wpdb->get_results($query);
112
+ } else {
113
+ $query_results = $query;
114
  }
115
 
116
+ if ($query_results) {
117
+ return $query_results;
118
+ }
119
+ return false;
120
  }
121
 
122
  /***
149
  ORDER BY total_count DESC
150
  LIMIT 5";
151
 
152
+ $query_results = $wpdb->get_results($query);
153
+
154
+ } else {
155
+ $query_results = $query;
156
  }
157
 
158
+ if ($query_results) {
159
+ return $query_results;
160
+ }
161
+ return false;
162
  }
163
 
164
  /***
173
 
174
  //return custom query here
175
  //must returns rating and post_id
176
+ $query = apply_filters('yasr_rankings_query_tu', $atts);
177
 
178
  //if query === $sql_params (both are falses) means that filters doesn't exists
179
  if($query === $atts) {
187
  ORDER BY ( total_count ) DESC
188
  LIMIT 10";
189
 
190
+ $query_results = $wpdb->get_results($query);
191
+
192
+ } else {
193
+ $query_results = $query;
194
+ }
195
+
196
+ if ($query_results) {
197
+ return $query_results;
198
+ }
199
+ return false;
200
+ }
201
+
202
+ /**
203
+ * @author Dario Curvino <@dudo>
204
+ * @since 2.7.2
205
+ *
206
+ * @param int|bool|string $set_id
207
+ * @param string $ranking
208
+ * @param false $sql_atts
209
+ *
210
+ * @return array|false|object
211
+ */
212
+ public static function rankingMultiVV ($set_id, $ranking='most', $sql_atts=false) {
213
+ global $wpdb;
214
+
215
+ //if set_id is not set (e.g. in rest parameter setid is not set)
216
+ if($set_id === NULL) {
217
+ $set_id = YASR_FIRST_SETID;
218
  }
219
 
220
+ $set_id = (int)$set_id;
221
+
222
+ //hooks here to return a query
223
+ $query = apply_filters('yasr_rankings_multivv_query', $sql_atts, $ranking, $set_id);
224
+
225
+ //if no custom query is hooked
226
+ if($query === $sql_atts) {
227
+ $query = $wpdb->prepare(
228
+ "SELECT CAST((SUM(l.vote)/COUNT(l.vote)) AS DECIMAL(2,1)) AS rating,
229
+ COUNT(l.vote) AS number_of_votes,
230
+ l.post_id
231
+ FROM " . YASR_LOG_MULTI_SET . " AS l,
232
+ $wpdb->posts AS p
233
+ WHERE l.set_type = %d
234
+ AND p.ID = l.post_id
235
+ AND p.post_status = 'publish'
236
+ GROUP BY l.post_id",
237
+ '%d'
238
+ );
239
+ if ($ranking === 'highest') {
240
+ $query .= ' ORDER BY rating DESC';
241
+ }
242
+ else {
243
+ $query .= ' ORDER BY number_of_votes DESC';
244
+ }
245
+ $query .= ' LIMIT 10';
246
+
247
+ $query_results = $wpdb->get_results($query);
248
+
249
+ } else {
250
+ $query_results = $query;
251
+ }
252
+
253
+ if ($query_results) {
254
+ return $query_results;
255
+ }
256
+ return false;
257
  }
258
+
259
  }
includes/js/src/ranking.js CHANGED
@@ -232,7 +232,8 @@ class YasrRanking extends React.Component {
232
  });
233
  }
234
  else {
235
- if (this.state.source !== false) {
 
236
  const urlYasrRankingApi = this.returnRestUrl();
237
  Promise.all(urlYasrRankingApi.map((url) =>
238
  fetch(url)
@@ -257,7 +258,7 @@ class YasrRanking extends React.Component {
257
  //if data is from visitor votes, create an array like this
258
  //data[most]
259
  //data[highest]
260
- if(response.source === 'visitor_votes') {
261
  data[response.show] = response.data_vv
262
  }
263
  }
@@ -301,7 +302,7 @@ class YasrRanking extends React.Component {
301
  returnRestUrl(){
302
  let queryParams = ((this.state.rankingParams !== '') ? this.state.rankingParams : '');
303
  let dataSource = this.state.source;
304
- let urlYasrRankingApi = false;
305
  const yasrRankingsApiPath = 'yet-another-stars-rating/v1/yasr-rankings/';
306
 
307
  let cleanedQuery = '';
@@ -328,6 +329,13 @@ class YasrRanking extends React.Component {
328
  cleanedQuery = cleanedQuery.replace(/\s+/g, '');
329
  cleanedQuery = '&'+cleanedQuery;
330
  }
 
 
 
 
 
 
 
331
  } else {
332
  cleanedQuery = '';
333
  }
@@ -335,8 +343,7 @@ class YasrRanking extends React.Component {
335
  if(dataSource === 'overall_rating') {
336
  urlYasrRankingApi = [yasrCommonData.restEndpoint + yasrRankingsApiPath + '?source=' + dataSource + cleanedQuery];
337
  }
338
-
339
- if(dataSource === 'visitor_votes') {
340
  let requiredMost = '';
341
  let requiredHighest = '';
342
 
@@ -374,7 +381,7 @@ class YasrRanking extends React.Component {
374
  const idLinkMost = 'link-most-rated-posts-'+tableId;
375
  const idLinkHighest = 'link-highest-rated-posts-'+tableId;
376
 
377
- if(source === 'visitor_votes') {
378
  let containerLink = <span>
379
  <span id={idLinkMost}>
380
  {__('Most Rated', 'yet-another-stars-rating')}
@@ -487,7 +494,7 @@ class YasrRanking extends React.Component {
487
  )
488
  }
489
 
490
- if(source === 'visitor_votes') {
491
  const vvMost = data.most;
492
  const vvHighest = data.highest;
493
  const display = 'table-row-group';
@@ -578,16 +585,11 @@ export function yasrDrawRankings () {
578
  if (yasrRankingsInDom.length > 0) {
579
  for (let i = 0; i < yasrRankingsInDom.length; i++) {
580
  const tableId = yasrRankingsInDom.item(i).id;
581
- const source = yasrRankingsInDom.item(i).dataset.rankingSource;
582
  const params = JSON.parse(yasrRankingsInDom.item(i).dataset.rankingParams);
583
  const rankingTable = document.getElementById(tableId);
584
 
585
- let dataSource = false
586
- if(source === 'overall_rating' || source === 'visitor_votes') {
587
- dataSource = source;
588
- }
589
-
590
- render(<YasrRanking source={dataSource} tableId={tableId} params={params}/>, rankingTable);
591
  }
592
  }
593
 
232
  });
233
  }
234
  else {
235
+ if (this.state.source) {
236
+ //fet the rest urls
237
  const urlYasrRankingApi = this.returnRestUrl();
238
  Promise.all(urlYasrRankingApi.map((url) =>
239
  fetch(url)
258
  //if data is from visitor votes, create an array like this
259
  //data[most]
260
  //data[highest]
261
+ else {
262
  data[response.show] = response.data_vv
263
  }
264
  }
302
  returnRestUrl(){
303
  let queryParams = ((this.state.rankingParams !== '') ? this.state.rankingParams : '');
304
  let dataSource = this.state.source;
305
+ let urlYasrRankingApi;
306
  const yasrRankingsApiPath = 'yet-another-stars-rating/v1/yasr-rankings/';
307
 
308
  let cleanedQuery = '';
329
  cleanedQuery = cleanedQuery.replace(/\s+/g, '');
330
  cleanedQuery = '&'+cleanedQuery;
331
  }
332
+
333
+ if(dataSource === 'visitor_multi') {
334
+ if(params.get('setid') !== null) {
335
+ cleanedQuery += '&setid=' + params.get('setid');
336
+ }
337
+ }
338
+
339
  } else {
340
  cleanedQuery = '';
341
  }
343
  if(dataSource === 'overall_rating') {
344
  urlYasrRankingApi = [yasrCommonData.restEndpoint + yasrRankingsApiPath + '?source=' + dataSource + cleanedQuery];
345
  }
346
+ else {
 
347
  let requiredMost = '';
348
  let requiredHighest = '';
349
 
381
  const idLinkMost = 'link-most-rated-posts-'+tableId;
382
  const idLinkHighest = 'link-highest-rated-posts-'+tableId;
383
 
384
+ if(source !== 'overall_rating') {
385
  let containerLink = <span>
386
  <span id={idLinkMost}>
387
  {__('Most Rated', 'yet-another-stars-rating')}
494
  )
495
  }
496
 
497
+ else {
498
  const vvMost = data.most;
499
  const vvHighest = data.highest;
500
  const display = 'table-row-group';
585
  if (yasrRankingsInDom.length > 0) {
586
  for (let i = 0; i < yasrRankingsInDom.length; i++) {
587
  const tableId = yasrRankingsInDom.item(i).id;
588
+ const source = JSON.parse(yasrRankingsInDom.item(i).dataset.rankingSource);
589
  const params = JSON.parse(yasrRankingsInDom.item(i).dataset.rankingParams);
590
  const rankingTable = document.getElementById(tableId);
591
 
592
+ render(<YasrRanking source={source} tableId={tableId} params={params}/>, rankingTable);
 
 
 
 
 
593
  }
594
  }
595
 
includes/js/yasr-front.js CHANGED
@@ -1 +1 @@
1
- !function(t){var e={};function r(a){if(e[a])return e[a].exports;var n=e[a]={i:a,l:!1,exports:{}};return t[a].call(n.exports,n,n.exports,r),n.l=!0,n.exports}r.m=t,r.c=e,r.d=function(t,e,a){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:a})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var a=Object.create(null);if(r.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(a,n,function(e){return t[e]}.bind(null,n));return a},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){t.exports=r(1)},function(t,e,r){"use strict";var a,n;r.r(e),r.d(e,"yasrSearchStarsDom",(function(){return j})),r.d(e,"yasrSetRaterValue",(function(){return L}));var o=new Uint8Array(16);function s(){if(!n&&!(n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return n(o)}var i=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var l=function(t){return"string"==typeof t&&i.test(t)},c=[],u=0;u<256;++u)c.push((u+256).toString(16).substr(1));var d=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(c[t[e+0]]+c[t[e+1]]+c[t[e+2]]+c[t[e+3]]+"-"+c[t[e+4]]+c[t[e+5]]+"-"+c[t[e+6]]+c[t[e+7]]+"-"+c[t[e+8]]+c[t[e+9]]+"-"+c[t[e+10]]+c[t[e+11]]+c[t[e+12]]+c[t[e+13]]+c[t[e+14]]+c[t[e+15]]).toLowerCase();if(!l(r))throw TypeError("Stringified UUID is invalid");return r};var m=function(t,e,r){var a=(t=t||{}).random||(t.rng||s)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,e){r=r||0;for(var n=0;n<16;++n)e[r+n]=a[n];return e}return d(a)};function y(t){return(y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function f(t,e){for(var r=0;r<e.length;r++){var a=e[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}function g(t,e){return(g=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function p(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,a=h(t);if(e){var n=h(this).constructor;r=Reflect.construct(a,arguments,n)}else r=a.apply(this,arguments);return v(this,r)}}function v(t,e){return!e||"object"!==y(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function h(t){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var b=wp.i18n.__,_=wp.element.render;function E(t){var e="yasr-ranking-element-"+m(),r=document.getElementById(t.tableId).dataset.rankingSize;return React.createElement("div",{id:e,ref:function(){return L(r,e,!1,.1,!0,t.rating)}})}function R(t){if(void 0!==t.post.number_of_votes)return React.createElement("span",{className:"yasr-most-rated-text"},"[",b("Total:","yet-another-stars-rating")," ",t.post.number_of_votes,"  ",b("Average:","yet-another-stars-rating")," ",t.post.rating,"]");var e=t.text;return React.createElement("span",{className:"yasr-highest-rated-text"},e," ",t.post.rating)}function I(t){return React.createElement("td",{className:t.colClass},React.createElement("a",{href:t.post.link},function(t){if("string"!=typeof t||-1===t.indexOf("&"))return t;void 0===a&&(a=document.implementation&&document.implementation.createHTMLDocument?document.implementation.createHTMLDocument("").createElement("textarea"):document.createElement("textarea")),a.innerHTML=t;var e=a.textContent;return a.innerHTML="",e}(t.post.title)))}function k(t){var e="after",r=b("Rating:","yet-another-stars-rating"),a=new URLSearchParams(t.rankingParams);return null!==a.get("text_position")&&(e=a.get("text_position")),null!==a.get("custom_txt")&&(r=a.get("custom_txt")),"before"===e?React.createElement("td",{className:t.colClass},React.createElement(R,{post:t.post,tableId:t.tableId,text:r}),React.createElement(E,{rating:t.post.rating,tableId:t.tableId})):React.createElement("td",{className:t.colClass},React.createElement(E,{rating:t.post.rating,tableId:t.tableId}),React.createElement(R,{post:t.post,tableId:t.tableId,text:r}))}function w(t){var e="",r="";return"overall_rating"===t.source?(e="yasr-top-10-overall-left",r="yasr-top-10-overall-right"):"visitor_votes"===t.source&&(e="yasr-top-10-most-highest-left",r="yasr-top-10-most-highest-right"),React.createElement("tr",{className:t.trClass},React.createElement(I,{colClass:e,post:t.post}),React.createElement(k,{colClass:r,post:t.post,tableId:t.tableId,rankingParams:t.rankingParams}))}function C(t){return React.createElement("tbody",{id:t.tBodyId,style:{display:t.show}},t.data.map((function(e,r){var a="yasr-rankings-td-colored";return"overall_rating"===t.source&&(a="yasr-rankings-td-white"),r%2==0&&(a="yasr-rankings-td-white","overall_rating"===t.source&&(a="yasr-rankings-td-colored")),React.createElement(w,{key:e.post_id,source:t.source,tableId:t.tableId,rankingParams:t.rankingParams,post:e,trClass:a})})))}var S=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&g(t,e)}(o,React.Component);var e,r,a,n=p(o);function o(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,o),(e=n.call(this,t)).state={error:null,isLoaded:!1,data:[],tableId:t.tableId,source:t.source,rankingParams:t.params},e}return e=o,(r=[{key:"componentDidMount",value:function(){var t=this,e=JSON.parse(document.getElementById(this.state.tableId).dataset.rankingData),r={};if("yes"!==yasrCommonData.ajaxEnabled)console.info(b("Ajax Disabled, getting data from source","yet-another-stars-rating")),this.setState({isLoaded:!0,data:e});else if(!1!==this.state.source){var a=this.returnRestUrl();Promise.all(a.map((function(t){return fetch(t).then((function(t){return!0===t.ok?t.json():(console.info(b("Ajax Call Failed. Getting data from source")),"KO")})).then((function(t){"KO"===t?r=e:("overall_rating"===t.source&&(r=t),"visitor_votes"===t.source&&(r[t.show]=t.data_vv))})).catch((function(t){r=e,console.info(b(t))}))}))).then((function(e){t.setState({isLoaded:!0,data:r})})).catch((function(e){console.info(b(e)),t.setState({isLoaded:!0,data:r})}))}else this.setState({error:b("Invalid Data Source","yet-another-stars-rating")})}},{key:"returnRestUrl",value:function(){var t=""!==this.state.rankingParams?this.state.rankingParams:"",e=this.state.source,r=!1,a="yet-another-stars-rating/v1/yasr-rankings/",n="";if(""!==t&&!1!==t){var o=new URLSearchParams(t);null!==o.get("order_by")&&(n+="order_by="+o.get("order_by")),null!==o.get("limit")&&(n+="&limit="+o.get("limit")),null!==o.get("ctg")?n+="&ctg="+o.get("ctg"):null!==o.get("cpt")&&(n+="&cpt="+o.get("cpt")),""!==n&&(n="&"+(n=n.replace(/\s+/g,"")))}else n="";if("overall_rating"===e&&(r=[yasrCommonData.restEndpoint+a+"?source="+e+n]),"visitor_votes"===e){var s="",i="";if(""!==t){var l=new URLSearchParams(t);null!==l.get("required_votes[most]")&&(s="&required_votes="+l.get("required_votes[most]")),null!==l.get("required_votes[highest]")&&(i="&required_votes="+l.get("required_votes[highest]"))}r=[yasrCommonData.restEndpoint+a+"?show=most&source="+e+n+s,yasrCommonData.restEndpoint+a+"?show=highest&source="+e+n+i]}return r}},{key:"rankingTableHead",value:function(t,e){var r=this.state.tableId,a="link-most-rated-posts-"+r,n="link-highest-rated-posts-"+r;if("visitor_votes"===t){var o=React.createElement("span",null,React.createElement("span",{id:a},b("Most Rated","yet-another-stars-rating"))," | ",React.createElement("a",{href:"#",id:n,onClick:this.switchTBody.bind(this)},b("Highest Rated","yet-another-stars-rating")));return"highest"===e&&(o=React.createElement("span",null,React.createElement("span",{id:n},b("Highest Rated","yet-another-stars-rating"))," | ",React.createElement("a",{href:"#",id:a,onClick:this.switchTBody.bind(this)},b("Most Rated","yet-another-stars-rating")))),React.createElement("thead",null,React.createElement("tr",{className:"yasr-rankings-td-colored yasr-rankings-heading"},React.createElement("th",null,"Post"),React.createElement("th",null,b("Order By","yet-another-stars-rating-pro"),":  ",o)))}return React.createElement(React.Fragment,null)}},{key:"switchTBody",value:function(t){t.preventDefault();var e=t.target.id,r=this.state.tableId,a="link-most-rated-posts-"+r,n="link-highest-rated-posts-"+r,o="most-rated-posts-"+r,s="highest-rated-posts-"+r,i=document.getElementById(e),l=document.createElement("span");l.innerHTML=i.innerHTML,l.id=i.id,i.parentNode.replaceChild(l,i),e===a&&(document.getElementById(s).style.display="none",document.getElementById(o).style.display="",l=document.getElementById(n),i.innerHTML=l.innerHTML,i.id=l.id,l.parentNode.replaceChild(i,l)),e===n&&(document.getElementById(o).style.display="none",document.getElementById(s).style.display="",l=document.getElementById(a),i.innerHTML=l.innerHTML,i.id=l.id,l.parentNode.replaceChild(i,l))}},{key:"rankingTableBody",value:function(){var t=this.state,e=t.data,r=t.source,a=t.rankingParams;if("overall_rating"===r)return React.createElement(C,{data:e.data_overall,tableId:this.state.tableId,tBodyId:"overall_"+this.state.tableId,rankingParams:a,show:"table-row-group",source:r});if("visitor_votes"===r){var n=e.most,o=e.highest,s="most",i="table-row-group",l="none",c=new URLSearchParams(a);return null!==c.get("view")&&(s=c.get("view")),"highest"===s&&(i="none",l="table-row-group"),React.createElement(React.Fragment,null,this.rankingTableHead(r,s),React.createElement(C,{data:n,tableId:this.state.tableId,tBodyId:"most-rated-posts-"+this.state.tableId,rankingParams:a,show:i,source:r}),React.createElement(C,{data:o,tableId:this.state.tableId,tBodyId:"highest-rated-posts-"+this.state.tableId,rankingParams:a,show:l,source:r}))}}},{key:"render",value:function(){var t=this.state,e=t.error,r=t.isLoaded;return e?React.createElement("tbody",null,React.createElement("tr",null,React.createElement("td",null,console.log(e),"Error"))):!1===r?React.createElement("tbody",null,React.createElement("tr",null,React.createElement("td",null,b("Loading Charts","yet-another-stars-rating")))):React.createElement(React.Fragment,null,this.rankingTableBody())}}])&&f(e.prototype,r),a&&f(e,a),o}();for(var x=wp.i18n.__,B=["yasr-rater-stars","yasr-rater-stars-vv","yasr-multiset-visitors-rater"],T=0;T<B.length;T++)j(B[T]);function j(t){var e=document.getElementsByClassName(t);if(e.length>0){if("yasr-rater-stars"!==t&&"yasr-ranking-stars"!==t||function(t){for(var e=0;e<t.length;e++)if(!1===t.item(e).classList.contains("yasr-star-rating")){var r=t.item(e),a=r.id;L(r.getAttribute("data-rater-starsize"),a,r)}}(e),"yasr-rater-stars-vv"===t&&(function(t){for(var e=0;e<t.length;e++)!function(e){if(!1===t.item(e).classList.contains("yasr-star-rating")){var r=t.item(e),a=r.getAttribute("data-rating"),n=r.getAttribute("data-readonly-attribute"),o=r.getAttribute("data-rater-readonly");null===n&&(n=!1),n=O(n),o=O(o),!0===n&&(o=!0);var s=r.getAttribute("data-rater-postid"),i=r.id,l=i.replace("yasr-visitor-votes-rater-",""),c=parseInt(r.getAttribute("data-rater-starsize")),u=r.getAttribute("data-rater-nonce"),d=r.getAttribute("data-issingular"),m="yasr-vv-votes-number-container-"+l,y="yasr-vv-average-container-"+l,f=document.getElementById(m),g=document.getElementById(y),p="yasr-vv-loader-"+l,v=!1;if("yes"===yasrCommonData.ajaxEnabled){var h=r.getAttribute("data-cpt");""===h&&(h="posts");var b="wp/v2/"+h+"/"+s+"?_fields=yasr_visitor_votes&_wpnonce="+yasrCommonData.nonce;jQuery.get(yasrCommonData.restEndpoint+b).done((function(t){var e;(e=!0===n||t.yasr_visitor_votes.stars_attributes.read_only,a=(a=t.yasr_visitor_votes.number_of_votes>0?t.yasr_visitor_votes.sum_votes/t.yasr_visitor_votes.number_of_votes:0).toFixed(1),a=parseFloat(a),P(c,a,s,e,i,l,u,d,f,g,p),!0!==n)&&(null!==f&&(f.innerHTML=t.yasr_visitor_votes.number_of_votes),null!==g&&(g.innerHTML=a),!1!==t.yasr_visitor_votes.stars_attributes.span_bottom&&(v=t.yasr_visitor_votes.stars_attributes.span_bottom,document.getElementById(p).innerHTML=v))})).fail((function(t,e,r,m){console.info(x("YASR ajax call failed. Showing ratings from html","yet-another-stars-rating")),P(c,a,s,o,i,l,u,d,f,g,p),!0!==n&&(document.getElementById("yasr-below-stars-hidden-"+l).style.display="")}))}else P(c,a,s,o,i,l,u,d,f,g,p)}}(e)}(e),"yes"===yasrCommonData.visitorStatsEnabled)){var r=document.getElementsByClassName("yasr-dashicons-visitor-stats");r&&function(t){for(var e=!1,r=0;r<t.length;r++)!function(r){var a="#"+t.item(r).id,n={action:"yasr_stats_visitors_votes",post_id:t.item(r).getAttribute("data-postid")};tippy(a,{content:'<span style="color: #0a0a0a">Loading...</span>',theme:"yasr",arrow:"true",arrowType:"round",onShow:function(t){a!==e&&jQuery.post(yasrCommonData.ajaxurl,n,(function(e){e=JSON.parse(e),t.setContent(e)}))},onHidden:function(){e=a}})}(r)}(r)}"yasr-multiset-visitors-rater"===t&&function(t){for(var e="",r=[],a=0;a<t.length;a++)!function(a){if(!1===t.item(a).classList.contains("yasr-star-rating")){var n=t.item(a),o=n.id,s=n.getAttribute("data-rater-readonly");s=O(s);L(16,o,n,1,s,!1,(function(t,a){var o=n.getAttribute("data-rater-postid"),s=n.getAttribute("data-rater-setid"),i=n.getAttribute("data-rater-set-field-id");t=t.toFixed(1);var l=parseInt(t);this.setRating(l),e={postid:o,setid:s,field:i,rating:l},r.push(e),a()}))}}(a);jQuery(".yasr-send-visitor-multiset").on("click",(function(){var t=this.getAttribute("data-postid"),e=this.getAttribute("data-setid"),a=this.getAttribute("data-nonce");jQuery("#yasr-send-visitor-multiset-"+t+"-"+e).hide(),jQuery("#yasr-loader-multiset-visitor-"+t+"-"+e).show();var n={action:"yasr_visitor_multiset_field_vote",nonce:a,post_id:t,rating:r,set_type:e};jQuery.post(yasrCommonData.ajaxurl,n,(function(r){jQuery("#yasr-loader-multiset-visitor-"+t+"-"+e).text(r)}))}))}(e)}}function L(t,e){var r,a=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:.1,o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],s=arguments.length>5&&void 0!==arguments[5]&&arguments[5],i=arguments.length>6&&void 0!==arguments[6]&&arguments[6];r=a||document.getElementById(e),t=parseInt(t),raterJs({starSize:t,showToolTip:!1,element:r,step:n,readOnly:o,rating:s,rateCallback:i})}function P(t,e,r,a,n,o,s,i,l,c,u){e=parseFloat(e),a=O(a);L(t,n,document.getElementById(n),1,a,e,(function(t,e){document.getElementById(u).innerHTML=yasrCommonData.loaderHtml;var a={action:"yasr_send_visitor_rating",rating:t,post_id:r,nonce_visitor:s,is_singular:i};this.setRating(t),this.disable(),jQuery.post(yasrCommonData.ajaxurl,a,(function(t){t=JSON.parse(t),null!==l&&(l.innerHTML=t.number_of_votes),null!==c&&(c.innerHTML=t.average_rating),document.getElementById(u).innerHTML=t.rating_saved_text})),e()}))}function O(t){return null!=t&&""!==t||(t=!0),"true"!==t&&"1"!==t||(t=!0),"false"!==t&&"0"!==t||(t=!1),t}!function(){var t=document.getElementsByClassName("yasr-stars-rankings");if(t.length>0)for(var e=0;e<t.length;e++){var r=t.item(e).id,a=t.item(e).dataset.rankingSource,n=JSON.parse(t.item(e).dataset.rankingParams),o=document.getElementById(r),s=!1;"overall_rating"!==a&&"visitor_votes"!==a||(s=a),_(React.createElement(S,{source:s,tableId:r,params:n}),o)}}()}]);
1
+ !function(t){var e={};function r(a){if(e[a])return e[a].exports;var n=e[a]={i:a,l:!1,exports:{}};return t[a].call(n.exports,n,n.exports,r),n.l=!0,n.exports}r.m=t,r.c=e,r.d=function(t,e,a){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:a})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var a=Object.create(null);if(r.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(a,n,function(e){return t[e]}.bind(null,n));return a},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){t.exports=r(1)},function(t,e,r){"use strict";var a,n;r.r(e),r.d(e,"yasrSearchStarsDom",(function(){return j})),r.d(e,"yasrSetRaterValue",(function(){return L}));var o=new Uint8Array(16);function s(){if(!n&&!(n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return n(o)}var i=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var l=function(t){return"string"==typeof t&&i.test(t)},c=[],u=0;u<256;++u)c.push((u+256).toString(16).substr(1));var d=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(c[t[e+0]]+c[t[e+1]]+c[t[e+2]]+c[t[e+3]]+"-"+c[t[e+4]]+c[t[e+5]]+"-"+c[t[e+6]]+c[t[e+7]]+"-"+c[t[e+8]]+c[t[e+9]]+"-"+c[t[e+10]]+c[t[e+11]]+c[t[e+12]]+c[t[e+13]]+c[t[e+14]]+c[t[e+15]]).toLowerCase();if(!l(r))throw TypeError("Stringified UUID is invalid");return r};var m=function(t,e,r){var a=(t=t||{}).random||(t.rng||s)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,e){r=r||0;for(var n=0;n<16;++n)e[r+n]=a[n];return e}return d(a)};function y(t){return(y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function g(t,e){for(var r=0;r<e.length;r++){var a=e[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}function f(t,e){return(f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function p(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,a=h(t);if(e){var n=h(this).constructor;r=Reflect.construct(a,arguments,n)}else r=a.apply(this,arguments);return v(this,r)}}function v(t,e){return!e||"object"!==y(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function h(t){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var b=wp.i18n.__,_=wp.element.render;function E(t){var e="yasr-ranking-element-"+m(),r=document.getElementById(t.tableId).dataset.rankingSize;return React.createElement("div",{id:e,ref:function(){return L(r,e,!1,.1,!0,t.rating)}})}function R(t){if(void 0!==t.post.number_of_votes)return React.createElement("span",{className:"yasr-most-rated-text"},"[",b("Total:","yet-another-stars-rating")," ",t.post.number_of_votes,"  ",b("Average:","yet-another-stars-rating")," ",t.post.rating,"]");var e=t.text;return React.createElement("span",{className:"yasr-highest-rated-text"},e," ",t.post.rating)}function I(t){return React.createElement("td",{className:t.colClass},React.createElement("a",{href:t.post.link},function(t){if("string"!=typeof t||-1===t.indexOf("&"))return t;void 0===a&&(a=document.implementation&&document.implementation.createHTMLDocument?document.implementation.createHTMLDocument("").createElement("textarea"):document.createElement("textarea")),a.innerHTML=t;var e=a.textContent;return a.innerHTML="",e}(t.post.title)))}function k(t){var e="after",r=b("Rating:","yet-another-stars-rating"),a=new URLSearchParams(t.rankingParams);return null!==a.get("text_position")&&(e=a.get("text_position")),null!==a.get("custom_txt")&&(r=a.get("custom_txt")),"before"===e?React.createElement("td",{className:t.colClass},React.createElement(R,{post:t.post,tableId:t.tableId,text:r}),React.createElement(E,{rating:t.post.rating,tableId:t.tableId})):React.createElement("td",{className:t.colClass},React.createElement(E,{rating:t.post.rating,tableId:t.tableId}),React.createElement(R,{post:t.post,tableId:t.tableId,text:r}))}function w(t){var e="",r="";return"overall_rating"===t.source?(e="yasr-top-10-overall-left",r="yasr-top-10-overall-right"):"visitor_votes"===t.source&&(e="yasr-top-10-most-highest-left",r="yasr-top-10-most-highest-right"),React.createElement("tr",{className:t.trClass},React.createElement(I,{colClass:e,post:t.post}),React.createElement(k,{colClass:r,post:t.post,tableId:t.tableId,rankingParams:t.rankingParams}))}function C(t){return React.createElement("tbody",{id:t.tBodyId,style:{display:t.show}},t.data.map((function(e,r){var a="yasr-rankings-td-colored";return"overall_rating"===t.source&&(a="yasr-rankings-td-white"),r%2==0&&(a="yasr-rankings-td-white","overall_rating"===t.source&&(a="yasr-rankings-td-colored")),React.createElement(w,{key:e.post_id,source:t.source,tableId:t.tableId,rankingParams:t.rankingParams,post:e,trClass:a})})))}var S=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&f(t,e)}(o,React.Component);var e,r,a,n=p(o);function o(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,o),(e=n.call(this,t)).state={error:null,isLoaded:!1,data:[],tableId:t.tableId,source:t.source,rankingParams:t.params},e}return e=o,(r=[{key:"componentDidMount",value:function(){var t=this,e=JSON.parse(document.getElementById(this.state.tableId).dataset.rankingData),r={};if("yes"!==yasrCommonData.ajaxEnabled)console.info(b("Ajax Disabled, getting data from source","yet-another-stars-rating")),this.setState({isLoaded:!0,data:e});else if(this.state.source){var a=this.returnRestUrl();Promise.all(a.map((function(t){return fetch(t).then((function(t){return!0===t.ok?t.json():(console.info(b("Ajax Call Failed. Getting data from source")),"KO")})).then((function(t){"KO"===t?r=e:"overall_rating"===t.source?r=t:r[t.show]=t.data_vv})).catch((function(t){r=e,console.info(b(t))}))}))).then((function(e){t.setState({isLoaded:!0,data:r})})).catch((function(e){console.info(b(e)),t.setState({isLoaded:!0,data:r})}))}else this.setState({error:b("Invalid Data Source","yet-another-stars-rating")})}},{key:"returnRestUrl",value:function(){var t,e=""!==this.state.rankingParams?this.state.rankingParams:"",r=this.state.source,a="yet-another-stars-rating/v1/yasr-rankings/",n="";if(""!==e&&!1!==e){var o=new URLSearchParams(e);null!==o.get("order_by")&&(n+="order_by="+o.get("order_by")),null!==o.get("limit")&&(n+="&limit="+o.get("limit")),null!==o.get("ctg")?n+="&ctg="+o.get("ctg"):null!==o.get("cpt")&&(n+="&cpt="+o.get("cpt")),""!==n&&(n="&"+(n=n.replace(/\s+/g,""))),"visitor_multi"===r&&null!==o.get("setid")&&(n+="&setid="+o.get("setid"))}else n="";if("overall_rating"===r)t=[yasrCommonData.restEndpoint+a+"?source="+r+n];else{var s="",i="";if(""!==e){var l=new URLSearchParams(e);null!==l.get("required_votes[most]")&&(s="&required_votes="+l.get("required_votes[most]")),null!==l.get("required_votes[highest]")&&(i="&required_votes="+l.get("required_votes[highest]"))}t=[yasrCommonData.restEndpoint+a+"?show=most&source="+r+n+s,yasrCommonData.restEndpoint+a+"?show=highest&source="+r+n+i]}return t}},{key:"rankingTableHead",value:function(t,e){var r=this.state.tableId,a="link-most-rated-posts-"+r,n="link-highest-rated-posts-"+r;if("overall_rating"!==t){var o=React.createElement("span",null,React.createElement("span",{id:a},b("Most Rated","yet-another-stars-rating"))," | ",React.createElement("a",{href:"#",id:n,onClick:this.switchTBody.bind(this)},b("Highest Rated","yet-another-stars-rating")));return"highest"===e&&(o=React.createElement("span",null,React.createElement("span",{id:n},b("Highest Rated","yet-another-stars-rating"))," | ",React.createElement("a",{href:"#",id:a,onClick:this.switchTBody.bind(this)},b("Most Rated","yet-another-stars-rating")))),React.createElement("thead",null,React.createElement("tr",{className:"yasr-rankings-td-colored yasr-rankings-heading"},React.createElement("th",null,"Post"),React.createElement("th",null,b("Order By","yet-another-stars-rating-pro"),":  ",o)))}return React.createElement(React.Fragment,null)}},{key:"switchTBody",value:function(t){t.preventDefault();var e=t.target.id,r=this.state.tableId,a="link-most-rated-posts-"+r,n="link-highest-rated-posts-"+r,o="most-rated-posts-"+r,s="highest-rated-posts-"+r,i=document.getElementById(e),l=document.createElement("span");l.innerHTML=i.innerHTML,l.id=i.id,i.parentNode.replaceChild(l,i),e===a&&(document.getElementById(s).style.display="none",document.getElementById(o).style.display="",l=document.getElementById(n),i.innerHTML=l.innerHTML,i.id=l.id,l.parentNode.replaceChild(i,l)),e===n&&(document.getElementById(o).style.display="none",document.getElementById(s).style.display="",l=document.getElementById(a),i.innerHTML=l.innerHTML,i.id=l.id,l.parentNode.replaceChild(i,l))}},{key:"rankingTableBody",value:function(){var t=this.state,e=t.data,r=t.source,a=t.rankingParams;if("overall_rating"===r)return React.createElement(C,{data:e.data_overall,tableId:this.state.tableId,tBodyId:"overall_"+this.state.tableId,rankingParams:a,show:"table-row-group",source:r});var n=e.most,o=e.highest,s="most",i="table-row-group",l="none",c=new URLSearchParams(a);return null!==c.get("view")&&(s=c.get("view")),"highest"===s&&(i="none",l="table-row-group"),React.createElement(React.Fragment,null,this.rankingTableHead(r,s),React.createElement(C,{data:n,tableId:this.state.tableId,tBodyId:"most-rated-posts-"+this.state.tableId,rankingParams:a,show:i,source:r}),React.createElement(C,{data:o,tableId:this.state.tableId,tBodyId:"highest-rated-posts-"+this.state.tableId,rankingParams:a,show:l,source:r}))}},{key:"render",value:function(){var t=this.state,e=t.error,r=t.isLoaded;return e?React.createElement("tbody",null,React.createElement("tr",null,React.createElement("td",null,console.log(e),"Error"))):!1===r?React.createElement("tbody",null,React.createElement("tr",null,React.createElement("td",null,b("Loading Charts","yet-another-stars-rating")))):React.createElement(React.Fragment,null,this.rankingTableBody())}}])&&g(e.prototype,r),a&&g(e,a),o}();for(var x=wp.i18n.__,B=["yasr-rater-stars","yasr-rater-stars-vv","yasr-multiset-visitors-rater"],T=0;T<B.length;T++)j(B[T]);function j(t){var e=document.getElementsByClassName(t);if(e.length>0){if("yasr-rater-stars"!==t&&"yasr-ranking-stars"!==t||function(t){for(var e=0;e<t.length;e++)if(!1===t.item(e).classList.contains("yasr-star-rating")){var r=t.item(e),a=r.id;L(r.getAttribute("data-rater-starsize"),a,r)}}(e),"yasr-rater-stars-vv"===t&&(function(t){for(var e=0;e<t.length;e++)!function(e){if(!1===t.item(e).classList.contains("yasr-star-rating")){var r=t.item(e),a=r.getAttribute("data-rating"),n=r.getAttribute("data-readonly-attribute"),o=r.getAttribute("data-rater-readonly");null===n&&(n=!1),n=O(n),o=O(o),!0===n&&(o=!0);var s=r.getAttribute("data-rater-postid"),i=r.id,l=i.replace("yasr-visitor-votes-rater-",""),c=parseInt(r.getAttribute("data-rater-starsize")),u=r.getAttribute("data-rater-nonce"),d=r.getAttribute("data-issingular"),m="yasr-vv-votes-number-container-"+l,y="yasr-vv-average-container-"+l,g=document.getElementById(m),f=document.getElementById(y),p="yasr-vv-loader-"+l,v=!1;if("yes"===yasrCommonData.ajaxEnabled){var h=r.getAttribute("data-cpt");""===h&&(h="posts");var b="wp/v2/"+h+"/"+s+"?_fields=yasr_visitor_votes&_wpnonce="+yasrCommonData.nonce;jQuery.get(yasrCommonData.restEndpoint+b).done((function(t){var e;(e=!0===n||t.yasr_visitor_votes.stars_attributes.read_only,a=(a=t.yasr_visitor_votes.number_of_votes>0?t.yasr_visitor_votes.sum_votes/t.yasr_visitor_votes.number_of_votes:0).toFixed(1),a=parseFloat(a),P(c,a,s,e,i,l,u,d,g,f,p),!0!==n)&&(null!==g&&(g.innerHTML=t.yasr_visitor_votes.number_of_votes),null!==f&&(f.innerHTML=a),!1!==t.yasr_visitor_votes.stars_attributes.span_bottom&&(v=t.yasr_visitor_votes.stars_attributes.span_bottom,document.getElementById(p).innerHTML=v))})).fail((function(t,e,r,m){console.info(x("YASR ajax call failed. Showing ratings from html","yet-another-stars-rating")),P(c,a,s,o,i,l,u,d,g,f,p),!0!==n&&(document.getElementById("yasr-below-stars-hidden-"+l).style.display="")}))}else P(c,a,s,o,i,l,u,d,g,f,p)}}(e)}(e),"yes"===yasrCommonData.visitorStatsEnabled)){var r=document.getElementsByClassName("yasr-dashicons-visitor-stats");r&&function(t){for(var e=!1,r=0;r<t.length;r++)!function(r){var a="#"+t.item(r).id,n={action:"yasr_stats_visitors_votes",post_id:t.item(r).getAttribute("data-postid")};tippy(a,{content:'<span style="color: #0a0a0a">Loading...</span>',theme:"yasr",arrow:"true",arrowType:"round",onShow:function(t){a!==e&&jQuery.post(yasrCommonData.ajaxurl,n,(function(e){e=JSON.parse(e),t.setContent(e)}))},onHidden:function(){e=a}})}(r)}(r)}"yasr-multiset-visitors-rater"===t&&function(t){for(var e="",r=[],a=0;a<t.length;a++)!function(a){if(!1===t.item(a).classList.contains("yasr-star-rating")){var n=t.item(a),o=n.id,s=n.getAttribute("data-rater-readonly");s=O(s);L(16,o,n,1,s,!1,(function(t,a){var o=n.getAttribute("data-rater-postid"),s=n.getAttribute("data-rater-setid"),i=n.getAttribute("data-rater-set-field-id");t=t.toFixed(1);var l=parseInt(t);this.setRating(l),e={postid:o,setid:s,field:i,rating:l},r.push(e),a()}))}}(a);jQuery(".yasr-send-visitor-multiset").on("click",(function(){var t=this.getAttribute("data-postid"),e=this.getAttribute("data-setid"),a=this.getAttribute("data-nonce");jQuery("#yasr-send-visitor-multiset-"+t+"-"+e).hide(),jQuery("#yasr-loader-multiset-visitor-"+t+"-"+e).show();var n={action:"yasr_visitor_multiset_field_vote",nonce:a,post_id:t,rating:r,set_type:e};jQuery.post(yasrCommonData.ajaxurl,n,(function(r){jQuery("#yasr-loader-multiset-visitor-"+t+"-"+e).text(r)}))}))}(e)}}function L(t,e){var r,a=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:.1,o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],s=arguments.length>5&&void 0!==arguments[5]&&arguments[5],i=arguments.length>6&&void 0!==arguments[6]&&arguments[6];r=a||document.getElementById(e),t=parseInt(t),raterJs({starSize:t,showToolTip:!1,element:r,step:n,readOnly:o,rating:s,rateCallback:i})}function P(t,e,r,a,n,o,s,i,l,c,u){e=parseFloat(e),a=O(a);L(t,n,document.getElementById(n),1,a,e,(function(t,e){document.getElementById(u).innerHTML=yasrCommonData.loaderHtml;var a={action:"yasr_send_visitor_rating",rating:t,post_id:r,nonce_visitor:s,is_singular:i};this.setRating(t),this.disable(),jQuery.post(yasrCommonData.ajaxurl,a,(function(t){t=JSON.parse(t),null!==l&&(l.innerHTML=t.number_of_votes),null!==c&&(c.innerHTML=t.average_rating),document.getElementById(u).innerHTML=t.rating_saved_text})),e()}))}function O(t){return null!=t&&""!==t||(t=!0),"true"!==t&&"1"!==t||(t=!0),"false"!==t&&"0"!==t||(t=!1),t}!function(){var t=document.getElementsByClassName("yasr-stars-rankings");if(t.length>0)for(var e=0;e<t.length;e++){var r=t.item(e).id,a=JSON.parse(t.item(e).dataset.rankingSource),n=JSON.parse(t.item(e).dataset.rankingParams),o=document.getElementById(r);_(React.createElement(S,{source:a,tableId:r,params:n}),o)}}()}]);
includes/rest/classes/YasrCustomEndpoint.php CHANGED
@@ -186,21 +186,20 @@ class YasrCustomEndpoint extends WP_REST_Controller {
186
  /*
187
  * Get cleaned params
188
  */
189
- $source = $request['source'];
190
  $sql_params = false;
191
 
 
192
  $sql_params = apply_filters('yasr_rest_filter_ranking_request', $sql_params, $request);
193
 
194
  $data_to_return = array(
195
  'source' => $source
196
  );
197
 
198
- $no_data = false;
199
-
200
  if($source === 'overall_rating') {
201
  $overall_data = YasrRankingData::rankingOverallGetResults($sql_params);
202
  if($overall_data === false){
203
- $no_data = true;
204
  }
205
  else {
206
  $data_to_return['data_overall'] = YasrRankings::rankingData($overall_data);
@@ -214,15 +213,31 @@ class YasrCustomEndpoint extends WP_REST_Controller {
214
 
215
  $vv_data = YasrRankingData::rankingVVGetResults($sql_params, $ranking);
216
  if($vv_data === false){
217
- $no_data = true;
218
  }
219
  else {
220
  $data_to_return['data_vv'] = YasrRankings::rankingData($vv_data);
221
  }
222
  }
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
 
225
- if ($no_data === true) {
226
  return new WP_Error(
227
  'no_data',
228
  __('No posts found. Try remove some filters', 'yet-another-stars-rating'),
@@ -283,7 +298,7 @@ class YasrCustomEndpoint extends WP_REST_Controller {
283
  }
284
 
285
  if($key === 'source') {
286
- if($param === 'overall_rating' || $param === 'visitor_votes') {
287
  return trim($param);
288
  }
289
  }
186
  /*
187
  * Get cleaned params
188
  */
189
+ $source = $request['source'];
190
  $sql_params = false;
191
 
192
+ //hooks here to add params
193
  $sql_params = apply_filters('yasr_rest_filter_ranking_request', $sql_params, $request);
194
 
195
  $data_to_return = array(
196
  'source' => $source
197
  );
198
 
 
 
199
  if($source === 'overall_rating') {
200
  $overall_data = YasrRankingData::rankingOverallGetResults($sql_params);
201
  if($overall_data === false){
202
+ $data_to_return = false;
203
  }
204
  else {
205
  $data_to_return['data_overall'] = YasrRankings::rankingData($overall_data);
213
 
214
  $vv_data = YasrRankingData::rankingVVGetResults($sql_params, $ranking);
215
  if($vv_data === false){
216
+ $data_to_return = false;
217
  }
218
  else {
219
  $data_to_return['data_vv'] = YasrRankings::rankingData($vv_data);
220
  }
221
  }
222
 
223
+ if($source === 'visitor_multi') {
224
+ //outside 'most', only 'highest' is allowed
225
+ $ranking = ($request['show'] === 'highest') ? $request['show'] : 'most';
226
+ $data_to_return['show'] = $ranking;
227
+
228
+ $vm_data = YasrRankingData::rankingMultiVV($request['setid'], $ranking, $sql_params);
229
+ if($vm_data === false){
230
+ $data_to_return = false;
231
+ }
232
+ else {
233
+ $data_to_return['data_vv'] = YasrRankings::rankingData($vm_data);
234
+ }
235
+ }
236
+
237
+ //hook here to add other "source" params to check
238
+ $data_to_return = apply_filters('yasr_rest_add_custom_endpoint', $data_to_return, $source, $request, $sql_params);
239
 
240
+ if ($data_to_return === false) {
241
  return new WP_Error(
242
  'no_data',
243
  __('No posts found. Try remove some filters', 'yet-another-stars-rating'),
298
  }
299
 
300
  if($key === 'source') {
301
+ if($param === 'overall_rating' || $param === 'visitor_votes' || $param = 'visitor_multi' ) {
302
  return trim($param);
303
  }
304
  }
includes/rest/classes/YasrPostMeta.php CHANGED
@@ -20,6 +20,7 @@ class YasrPostMeta {
20
  *
21
  */
22
  public function registerPostMeta () {
 
23
  register_meta(
24
  'post',
25
  'yasr_overall_rating',
20
  *
21
  */
22
  public function registerPostMeta () {
23
+ //'post' here works also for CPT
24
  register_meta(
25
  'post',
26
  'yasr_overall_rating',
includes/shortcodes/classes/YasrNoStarsRankings.php CHANGED
@@ -31,7 +31,7 @@ class YasrNoStarsRankings extends YasrShortcode {
31
  */
32
  public function returnTopReviewers($atts) {
33
 
34
- $this->shortcode_html = '<!-- Yasr '.$this->shorcode_name.' Shortcode-->';
35
 
36
  $sql_atts = apply_filters('yasr_tr_rankings_atts', false, $atts);
37
  $query_result = YasrRankingData::rankingTopReviewers($sql_atts);
@@ -43,7 +43,7 @@ class YasrNoStarsRankings extends YasrShortcode {
43
  'yet-another-stars-rating');
44
  }
45
 
46
- $this->shortcode_html .= '<!-- Yasr '.$this->shorcode_name.' Shortcode-->';
47
 
48
  return $this->shortcode_html;
49
 
@@ -56,7 +56,7 @@ class YasrNoStarsRankings extends YasrShortcode {
56
  */
57
  public function returnTopUsers($atts) {
58
 
59
- $this->shortcode_html = '<!-- Yasr '.$this->shorcode_name.' Shortcode-->';
60
 
61
  $sql_atts = apply_filters('yasr_tu_rankings_atts', false, $atts);
62
  $query_result = YasrRankingData::rankingTopUsers($sql_atts);
@@ -68,7 +68,7 @@ class YasrNoStarsRankings extends YasrShortcode {
68
  'yet-another-stars-rating');
69
  }
70
 
71
- $this->shortcode_html .= '<!-- Yasr '.$this->shorcode_name.' Shortcode-->';
72
 
73
  return $this->shortcode_html;
74
 
@@ -80,7 +80,7 @@ class YasrNoStarsRankings extends YasrShortcode {
80
  * @return string
81
  */
82
  private function returnTableHeader() {
83
- if($this->shorcode_name === 'yasr_most_active_users' || 'yasr_top_ten_active_users') {
84
  $first_header = 'User';
85
  $second_header = 'Number of votes';
86
  } else {
31
  */
32
  public function returnTopReviewers($atts) {
33
 
34
+ $this->shortcode_html = '<!-- Yasr '.$this->shortcode_name.' Shortcode-->';
35
 
36
  $sql_atts = apply_filters('yasr_tr_rankings_atts', false, $atts);
37
  $query_result = YasrRankingData::rankingTopReviewers($sql_atts);
43
  'yet-another-stars-rating');
44
  }
45
 
46
+ $this->shortcode_html .= '<!-- Yasr '.$this->shortcode_name.' Shortcode-->';
47
 
48
  return $this->shortcode_html;
49
 
56
  */
57
  public function returnTopUsers($atts) {
58
 
59
+ $this->shortcode_html = '<!-- Yasr '.$this->shortcode_name.' Shortcode-->';
60
 
61
  $sql_atts = apply_filters('yasr_tu_rankings_atts', false, $atts);
62
  $query_result = YasrRankingData::rankingTopUsers($sql_atts);
68
  'yet-another-stars-rating');
69
  }
70
 
71
+ $this->shortcode_html .= '<!-- Yasr '.$this->shortcode_name.' Shortcode-->';
72
 
73
  return $this->shortcode_html;
74
 
80
  * @return string
81
  */
82
  private function returnTableHeader() {
83
+ if($this->shortcode_name === 'yasr_most_active_users' || 'yasr_top_ten_active_users') {
84
  $first_header = 'User';
85
  $second_header = 'Number of votes';
86
  } else {
includes/shortcodes/classes/YasrRankings.php CHANGED
@@ -27,8 +27,8 @@ if (!defined('ABSPATH')) {
27
  class YasrRankings extends YasrShortcode {
28
 
29
  protected $query_highest_rated_overall;
30
- protected $query_result_most_rated_visitor;
31
- protected $query_result_highest_rated_visitor;
32
 
33
  /**
34
  * Returns the shortcode for yasr_ov_ranking
@@ -40,15 +40,13 @@ class YasrRankings extends YasrShortcode {
40
  public function returnHighestRatedOverall ($atts) {
41
  $this->shortcode_html = '<!-- Yasr Highest Rated Shortcode-->';
42
 
43
- //hook in this filter to get cleaned_atts to use in yasr_ov_ranking
44
- //false is the default value to assign to cleaned_atts
45
- $cleaned_atts = apply_filters('yasr_ov_rankings_atts', false, $atts);
46
- $this->query_highest_rated_overall = YasrRankingData::rankingOverallGetResults($cleaned_atts);
47
 
48
- //hook in this filter to making $cleaned_atts ready to be printed in shortcode
49
- $cleaned_params = apply_filters('yasr_ov_rankings_cleaned_atts', $cleaned_atts);
50
 
51
- $this->returnTableOverall($cleaned_params);
52
  $this->shortcode_html .= '<!--End Yasr Top 10 highest Rated Shortcode-->';
53
 
54
  return $this->shortcode_html;
@@ -76,7 +74,7 @@ class YasrRankings extends YasrShortcode {
76
  class='yasr-rankings yasr-stars-rankings'
77
  id=$table_id
78
  data-ranking-data='".json_encode($array_with_title)."'
79
- data-ranking-source='overall_rating'
80
  data-ranking-params='$table_attributes'
81
  data-ranking-size='".$this->starSize()."'
82
  >";
@@ -84,55 +82,96 @@ class YasrRankings extends YasrShortcode {
84
  $this->shortcode_html .= "</table>";
85
  }
86
  else {
87
- $this->shortcode_html .= __("No data found", 'yet-another-stars-rating');
 
 
88
  }
89
 
90
  }
91
 
92
  /**
93
- * Returns the shortcode for yasr_most_or_highest_rated_posts
94
  *
95
- * @param $atts
 
96
  *
97
  * @return string
98
  */
99
- public function vvReturnMostHighestRated ($atts) {
100
  $this->shortcode_html = '<!-- Yasr Most Or Highest Rated Shortcode -->';
101
 
102
- //hook in this filter to get sql_atts to use in yasr_ov_ranking
103
- //false is the default value to assign to sql_atts
104
- $sql_atts = apply_filters('yasr_vv_rankings_atts', false, $atts);
 
 
 
 
 
105
 
106
- if($sql_atts !== false) {
107
- $required_votes_most = $sql_atts['required_votes']['most'];
108
- $required_votes_highest = $sql_atts['required_votes']['highest'];
109
- } else {
110
- $required_votes_most = 1;
111
- $required_votes_highest = 1;
112
- }
113
 
114
- $this->query_result_most_rated_visitor = YasrRankingData::rankingVVGetResults($sql_atts, 'most', $required_votes_most);
115
- $this->query_result_highest_rated_visitor = YasrRankingData::rankingVVGetResults($sql_atts, 'highest', $required_votes_highest);
116
 
117
- //hook in this filter to making $sql_atts ready for wp_localize_script
118
- $cleaned_params = apply_filters('yasr_vv_rankings_cleaned_atts', $sql_atts);
119
-
120
- $this->returnTableVV($cleaned_params);
121
  $this->shortcode_html .= '<!--End Yasr TMost Or Highest Rated Shortcode -->';
122
 
123
  return $this->shortcode_html;
124
  }
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  /**
127
  * Create the queries for the rankings
128
  * Return the full html for the shortcode
129
  *
130
- * @param $sql_params array|string - params that can be used in REST API
131
  */
132
- public function returnTableVV($sql_params=null) {
133
  if($this->query_result_most_rated_visitor && $this->query_result_highest_rated_visitor) {
134
 
135
- $table_attributes = json_encode($sql_params);
 
 
 
 
 
 
136
 
137
  $array_with_title['most'] = self::rankingData($this->query_result_most_rated_visitor);
138
  $array_with_title['highest'] = self::rankingData($this->query_result_highest_rated_visitor);
@@ -143,14 +182,16 @@ class YasrRankings extends YasrShortcode {
143
  class='yasr-rankings yasr-stars-rankings'
144
  id=$table_id
145
  data-ranking-data='".json_encode($array_with_title)."'
146
- data-ranking-source='visitor_votes'
147
  data-ranking-params='$table_attributes'
148
  data-ranking-size='".$this->starSize()."'
149
  >";
150
  $this->shortcode_html .= '</table>';
151
 
152
  } else {
153
- $this->shortcode_html .= __("No data found", 'yet-another-stars-rating');
 
 
154
  }
155
 
156
  }
@@ -186,4 +227,29 @@ class YasrRankings extends YasrShortcode {
186
  return $data_array;
187
  }
188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  }
27
  class YasrRankings extends YasrShortcode {
28
 
29
  protected $query_highest_rated_overall;
30
+ public $query_result_most_rated_visitor;
31
+ public $query_result_highest_rated_visitor;
32
 
33
  /**
34
  * Returns the shortcode for yasr_ov_ranking
40
  public function returnHighestRatedOverall ($atts) {
41
  $this->shortcode_html = '<!-- Yasr Highest Rated Shortcode-->';
42
 
43
+ //hook in this filter to use shortcode atts
44
+ //$this->shorcode_name is the default value
45
+ $sql_atts = apply_filters('yasr_ov_rankings_atts', $this->shortcode_name, $atts);
 
46
 
47
+ $this->query_highest_rated_overall = YasrRankingData::rankingOverallGetResults($sql_atts);
 
48
 
49
+ $this->returnTableOverall($this->urlencodeAtts($sql_atts));
50
  $this->shortcode_html .= '<!--End Yasr Top 10 highest Rated Shortcode-->';
51
 
52
  return $this->shortcode_html;
74
  class='yasr-rankings yasr-stars-rankings'
75
  id=$table_id
76
  data-ranking-data='".json_encode($array_with_title)."'
77
+ data-ranking-source='".json_encode('overall_rating')."'
78
  data-ranking-params='$table_attributes'
79
  data-ranking-size='".$this->starSize()."'
80
  >";
82
  $this->shortcode_html .= "</table>";
83
  }
84
  else {
85
+ $this->shortcode_html .= '<div style="padding: 20px">';
86
+ $this->shortcode_html .= __('No data found', 'yet-another-stars-rating');
87
+ $this->shortcode_html .= '</div>';
88
  }
89
 
90
  }
91
 
92
  /**
93
+ * Returns the shortcode for all rankings that get data from visitor votes
94
  *
95
+ * @param $atts
96
+ * @param string $source
97
  *
98
  * @return string
99
  */
100
+ public function vvReturnMostHighestRated ($atts, $source='visitor_votes') {
101
  $this->shortcode_html = '<!-- Yasr Most Or Highest Rated Shortcode -->';
102
 
103
+ /**
104
+ * Hook here to use shortcode atts.
105
+ * If not used, will works with no support for atts
106
+ *
107
+ * @param string $this->shortcode_name Name of shortcode caller
108
+ * @param string|array $atts Shortcode atts
109
+ */
110
+ $sql_atts = apply_filters('yasr_vv_rankings_atts', $this->shortcode_name, $atts);
111
 
112
+ $this->query_result_most_rated_visitor = YasrRankingData::rankingVVGetResults($sql_atts, 'most');
 
 
 
 
 
 
113
 
114
+ $this->query_result_highest_rated_visitor = YasrRankingData::rankingVVGetResults($sql_atts, 'highest');
 
115
 
116
+ $this->returnTableVV($this->urlencodeAtts($sql_atts), $source);
 
 
 
117
  $this->shortcode_html .= '<!--End Yasr TMost Or Highest Rated Shortcode -->';
118
 
119
  return $this->shortcode_html;
120
  }
121
 
122
+ /**
123
+ * Return from shortcode yasr_visitor_multi_set_ranking
124
+ *
125
+ * @author Dario Curvino <@dudo>
126
+ * @since 2.7.2
127
+ *
128
+ * @param $atts
129
+ *
130
+ * @return string
131
+ */
132
+ public function returnMultiVisitor($atts) {
133
+ $this->shortcode_html = '<!-- Yasr Ranking by Visitor Multiset -->';
134
+
135
+ /**
136
+ * Hook here to use shortcode atts.
137
+ * If not used, shortcode will works only with setId param
138
+ *
139
+ * @param string $this->shortcode_name Name of shortcode caller
140
+ * @param string|array $atts Shortcode atts
141
+ */
142
+ $sql_atts = apply_filters('yasr_visitor_multi_set_ranking_atts', $this->shortcode_name, $atts);
143
+
144
+ $this->query_result_most_rated_visitor = YasrRankingData::rankingMultiVV($this->set_id, 'most', $sql_atts);
145
+ $this->query_result_highest_rated_visitor = YasrRankingData::rankingMultiVV($this->set_id, 'highest', $sql_atts);
146
+
147
+ //this means no filter has run, I've to create an array with the setid
148
+ //that will be later urlencoded
149
+ if($sql_atts === $this->shortcode_name) {
150
+ $sql_atts = array('setid' => $this->set_id);
151
+ }
152
+
153
+ $this->returnTableVV($this->urlencodeAtts($sql_atts), 'visitor_multi');
154
+ $this->shortcode_html .= '<!--End Yasr Ranking by Visitor Multiset -->';
155
+
156
+ return $this->shortcode_html;
157
+ }
158
+
159
  /**
160
  * Create the queries for the rankings
161
  * Return the full html for the shortcode
162
  *
163
+ * @param $urlencoded_params array|string - params that can be used in REST API
164
  */
165
+ public function returnTableVV($urlencoded_params, $source) {
166
  if($this->query_result_most_rated_visitor && $this->query_result_highest_rated_visitor) {
167
 
168
+ //This means that an hook has run
169
+ if($urlencoded_params !== $this->shortcode_name) {
170
+ $table_attributes = json_encode($urlencoded_params);
171
+ } else {
172
+ //is is useless here to pass the shortcode name into the data-params
173
+ $table_attributes = json_encode('');
174
+ }
175
 
176
  $array_with_title['most'] = self::rankingData($this->query_result_most_rated_visitor);
177
  $array_with_title['highest'] = self::rankingData($this->query_result_highest_rated_visitor);
182
  class='yasr-rankings yasr-stars-rankings'
183
  id=$table_id
184
  data-ranking-data='".json_encode($array_with_title)."'
185
+ data-ranking-source='".json_encode($source)."'
186
  data-ranking-params='$table_attributes'
187
  data-ranking-size='".$this->starSize()."'
188
  >";
189
  $this->shortcode_html .= '</table>';
190
 
191
  } else {
192
+ $this->shortcode_html .= '<div style="padding: 20px">';
193
+ $this->shortcode_html .= __('No data found', 'yet-another-stars-rating');
194
+ $this->shortcode_html .= '</div>';
195
  }
196
 
197
  }
227
  return $data_array;
228
  }
229
 
230
+ /**
231
+ * Urlencode shortcode atts
232
+ *
233
+ * @author Dario Curvino <@dudo>
234
+ * @since 2.7.2
235
+ * @param $atts
236
+ *
237
+ * @return string
238
+ */
239
+ public function urlencodeAtts ($atts) {
240
+ //If shortcode atts is === shortcode name, no filter has run, I don't need to do urlencode
241
+ if($atts === $this->shortcode_name) {
242
+ return '';
243
+ }
244
+
245
+ if(is_array($atts)) {
246
+ $urlencoded_atts = http_build_query($atts);
247
+ } else if (is_string($atts)) {
248
+ $urlencoded_atts = urlencode($atts);
249
+ } else {
250
+ $urlencoded_atts = '';
251
+ }
252
+
253
+ return $urlencoded_atts;
254
+ }
255
  }
includes/shortcodes/classes/YasrShortcode.php CHANGED
@@ -40,11 +40,11 @@ abstract class YasrShortcode
40
  //1
41
  public $show_average ;
42
  //null
43
- public $shorcode_name ;
44
  public $post_type ;
45
  public function __construct( $atts, $shortcode_name )
46
  {
47
- $this->shorcode_name = $shortcode_name;
48
 
49
  if ( $atts !== false ) {
50
  $atts = shortcode_atts( array(
@@ -79,18 +79,10 @@ abstract class YasrShortcode
79
  protected function starSize()
80
  {
81
  $size = null;
82
-
83
- if ( $this->shorcode_name === 'yasr_ov_ranking' ) {
84
- return 24;
85
- //default size
86
  }
87
-
88
-
89
- if ( $this->shorcode_name === 'yasr_most_or_highest_rated_posts' ) {
90
- return 24;
91
- //default size
92
- }
93
-
94
  if ( $size === null ) {
95
  $size = $this->size;
96
  }
40
  //1
41
  public $show_average ;
42
  //null
43
+ public $shortcode_name ;
44
  public $post_type ;
45
  public function __construct( $atts, $shortcode_name )
46
  {
47
+ $this->shortcode_name = $shortcode_name;
48
 
49
  if ( $atts !== false ) {
50
  $atts = shortcode_atts( array(
79
  protected function starSize()
80
  {
81
  $size = null;
82
+ if ( $this->shortcode_name === 'yasr_ov_ranking' || $this->shortcode_name === 'yasr_most_or_highest_rated_posts' || $this->shortcode_name === 'yasr_pro_ur_ranking' || $this->shortcode_name === 'yasr_visitor_multi_set_ranking' ) {
83
+ //default size for all rankings
84
+ $size = 'medium';
 
85
  }
 
 
 
 
 
 
 
86
  if ( $size === null ) {
87
  $size = $this->size;
88
  }
includes/shortcodes/yasr-shortcode-functions.php CHANGED
@@ -100,9 +100,9 @@ add_shortcode ('yasr_multiset', 'yasr_multiset_callback');
100
  * @param bool $content
101
  * @param bool $shortcode_tag
102
  *
103
- * @return string|void|null
104
  */
105
- function yasr_multiset_callback($atts, $content=false, $shortcode_tag=false) {
106
  $multiset = new YasrMultiSet($atts, $shortcode_tag);
107
 
108
  return $multiset->printMultiset();
@@ -117,9 +117,9 @@ add_shortcode ('yasr_visitor_multiset', 'yasr_visitor_multiset_callback');
117
  * @param bool $content
118
  * @param bool $shortcode_tag
119
  *
120
- * @return string|void|null
121
  */
122
- function yasr_visitor_multiset_callback($atts, $content=false, $shortcode_tag=false) {
123
  $multiset = new YasrVisitorMultiSet($atts, $shortcode_tag);
124
  return $multiset->printVisitorMultiSet();
125
  }
@@ -142,7 +142,7 @@ add_shortcode ('yasr_ov_ranking', 'yasr_ov_ranking_callback');
142
  * @param $content
143
  * @param $shortcode_tag
144
  *
145
- * @return string|void|null
146
  */
147
  function yasr_ov_ranking_callback($atts, $content, $shortcode_tag) {
148
  $top_ten_highest_obj = new YasrRankings(false, $shortcode_tag);
@@ -158,7 +158,7 @@ add_shortcode ('yasr_most_or_highest_rated_posts', 'yasr_most_or_highest_rated_p
158
  * @param $content
159
  * @param $shortcode_tag
160
  *
161
- * @return string|void|null
162
  */
163
  function yasr_most_or_highest_rated_posts_callback($atts, $content, $shortcode_tag) {
164
  $most_highest_obj = new YasrRankings(false, $shortcode_tag);
@@ -211,3 +211,10 @@ function yasr_ranking_users_callback ($atts, $content, $shortcode_tag) {
211
  return $ranking_users_obj->returnTopUsers($atts);
212
  } //End users rankings
213
 
 
 
 
 
 
 
 
100
  * @param bool $content
101
  * @param bool $shortcode_tag
102
  *
103
+ * @return bool|string
104
  */
105
+ function yasr_multiset_callback($atts, $content, $shortcode_tag) {
106
  $multiset = new YasrMultiSet($atts, $shortcode_tag);
107
 
108
  return $multiset->printMultiset();
117
  * @param bool $content
118
  * @param bool $shortcode_tag
119
  *
120
+ * @return string
121
  */
122
+ function yasr_visitor_multiset_callback($atts, $content, $shortcode_tag) {
123
  $multiset = new YasrVisitorMultiSet($atts, $shortcode_tag);
124
  return $multiset->printVisitorMultiSet();
125
  }
142
  * @param $content
143
  * @param $shortcode_tag
144
  *
145
+ * @return string
146
  */
147
  function yasr_ov_ranking_callback($atts, $content, $shortcode_tag) {
148
  $top_ten_highest_obj = new YasrRankings(false, $shortcode_tag);
158
  * @param $content
159
  * @param $shortcode_tag
160
  *
161
+ * @return string
162
  */
163
  function yasr_most_or_highest_rated_posts_callback($atts, $content, $shortcode_tag) {
164
  $most_highest_obj = new YasrRankings(false, $shortcode_tag);
211
  return $ranking_users_obj->returnTopUsers($atts);
212
  } //End users rankings
213
 
214
+ add_shortcode ('yasr_visitor_multi_set_ranking', 'yasr_visitor_multi_set_ranking_callback');
215
+
216
+ function yasr_visitor_multi_set_ranking_callback($atts, $content, $shortcode_tag) {
217
+ $yasr_ranking = new YasrRankings($atts, $shortcode_tag);
218
+
219
+ return $yasr_ranking->returnMultiVisitor($atts);
220
+ } //End function
includes/yasr-widgets.php CHANGED
@@ -38,7 +38,6 @@ class Yasr_Overall_Rating_Widget extends WP_Widget {
38
  * Register widget with WordPress.
39
  */
40
  function __construct() {
41
-
42
  parent::__construct(
43
  'yasr_overall_rating_widget', // Base ID
44
  __('Yasr Overall Rating', 'yet-another-stars-rating'), // Name
38
  * Register widget with WordPress.
39
  */
40
  function __construct() {
 
41
  parent::__construct(
42
  'yasr_overall_rating_widget', // Base ID
43
  __('Yasr Overall Rating', 'yet-another-stars-rating'), // Name
public/classes/YasrPublicFilters.php CHANGED
@@ -195,7 +195,7 @@ class YasrPublicFilters {
195
 
196
  //YASR adds microdata only if is_singular() && is_main_query() && !is_404()
197
  if (is_singular() && is_main_query() && !is_404()) {
198
- $rich_snippet['@context'] = 'http://schema.org/';
199
 
200
  $author = get_the_author();
201
 
195
 
196
  //YASR adds microdata only if is_singular() && is_main_query() && !is_404()
197
  if (is_singular() && is_main_query() && !is_404()) {
198
+ $rich_snippet['@context'] = 'https://schema.org/';
199
 
200
  $author = get_the_author();
201
 
readme.txt CHANGED
@@ -5,7 +5,7 @@ Requires at least: 5.0
5
  Contributors: Dudo
6
  Tested up to: 5.7
7
  Requires PHP: 5.4
8
- Stable tag: 2.7.1
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
@@ -181,6 +181,11 @@ If doesn't, you should work on your seo reputation.
181
 
182
  The full changelog can be found in the plugin's directory. Recent entries:
183
 
 
 
 
 
 
184
  = 2.7.1 =
185
  * FIXED: minor bugs that could happen in rare circumstances
186
 
5
  Contributors: Dudo
6
  Tested up to: 5.7
7
  Requires PHP: 5.4
8
+ Stable tag: 2.7.2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
181
 
182
  The full changelog can be found in the plugin's directory. Recent entries:
183
 
184
+ = 2.7.2 =
185
+ * NEW FEATURE: new shortcode: yasr_visitor_multi_set_ranking : this will show rankings from yasr_visitor_multiset
186
+ * TWEAKED: minor fixes
187
+
188
+
189
  = 2.7.1 =
190
  * FIXED: minor bugs that could happen in rare circumstances
191
 
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: Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
7
- * Version: 2.7.1
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', '2.7.1' );
80
  //Plugin absolute path
81
  //e.g. /var/www/html/plugin_development/wp-content/plugins/yet-another-stars-rating
82
  define( 'YASR_ABSOLUTE_PATH', __DIR__ );
4
  * Plugin Name: Yet Another Stars Rating
5
  * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
6
  * Description: Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
7
+ * Version: 2.7.2
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.7.2' );
80
  //Plugin absolute path
81
  //e.g. /var/www/html/plugin_development/wp-content/plugins/yet-another-stars-rating
82
  define( 'YASR_ABSOLUTE_PATH', __DIR__ );