Yasr – Yet Another Stars Rating - Version 0.3.4

Version Description

  • In settings page is now possible add some custom text to make appear before "Overall Rating" or "Visitor's Rating" are showed
  • In settings page is now possible to show "Overall Rating" only in the post / page or even in Home page, Archive Page, etc.
  • Removed bug that could appear in some case when removing or adding field in multiset form editor
  • After a multiset is created/edited now you get redirected on multiset settings tab and not in general settings
  • Various bugfixes
  • Under the hood changes
Download this release

Release Info

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

Code changes from version 0.3.3 to 0.3.4

css/yasr.css CHANGED
@@ -273,6 +273,27 @@ h2.nav-tab-wrapper, h3.nav-tab-wrapper {
273
 
274
  /****** NON ADMIN RULES ******/
275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  .yasr_table_multi_set_shortcode tr:nth-child(odd) {
277
  background: #FFFFec;
278
  }
273
 
274
  /****** NON ADMIN RULES ******/
275
 
276
+ #yasr-custom-text-before-overall {
277
+ padding-right: 5px;
278
+ padding-bottom: 10px;
279
+ vertical-align: top;
280
+ }
281
+
282
+ .yasr-container-custom-text-and-visitor-rating {
283
+ /**/
284
+ }
285
+
286
+ #yasr-custom-text-before-visitor-rating {
287
+ display: inline-block;
288
+ vertical-align: top;
289
+ padding-right: 15px;
290
+ }
291
+
292
+ #yasr_visitor_votes {
293
+ display: inline-block;
294
+ vertical-align: top;
295
+ }
296
+
297
  .yasr_table_multi_set_shortcode tr:nth-child(odd) {
298
  background: #FFFFec;
299
  }
lib/yasr-db-functions.php CHANGED
@@ -35,7 +35,7 @@ function yasr_install() {
35
  $sql_yasr_multi_set_fields ="CREATE TABLE IF NOT EXISTS $yasr_multi_set_fields (
36
  id bigint(20) NOT NULL,
37
  parent_set_id int(2) NOT NULL,
38
- field_name text COLLATE utf8_unicode_ci NOT NULL,
39
  field_id int(2) NOT NULL,
40
  PRIMARY KEY (id),
41
  UNIQUE KEY id (id)
@@ -71,6 +71,25 @@ function yasr_install() {
71
  dbDelta( $sql_yasr_multi_value_table );
72
  dbDelta( $sql_yasr_log_table );
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  }
75
 
76
 
35
  $sql_yasr_multi_set_fields ="CREATE TABLE IF NOT EXISTS $yasr_multi_set_fields (
36
  id bigint(20) NOT NULL,
37
  parent_set_id int(2) NOT NULL,
38
+ field_name varchar(23) COLLATE utf8_unicode_ci NOT NULL,
39
  field_id int(2) NOT NULL,
40
  PRIMARY KEY (id),
41
  UNIQUE KEY id (id)
71
  dbDelta( $sql_yasr_multi_value_table );
72
  dbDelta( $sql_yasr_log_table );
73
 
74
+
75
+ //Write default option settings
76
+ $option = get_option( 'yasr_general_options' );
77
+
78
+ if (!$option) {
79
+
80
+ $option = array();
81
+ $option['auto_insert_enabled'] = 0;
82
+ $option['auto_insert_what'] = 'overall_rating';
83
+ $option['auto_insert_where'] = 'top';
84
+ $option['show_overall_in_loop'] = 'disabled';
85
+ $option['text_before_stars'] = 0;
86
+ $option['snippet'] = 'overall_rating';
87
+ $option['allowed_user'] = 'allow_anonymous';
88
+
89
+ add_option("yasr_general_options", $option); //Write here the default value if there is not option
90
+
91
+ }
92
+
93
  }
94
 
95
 
lib/yasr-functions.php CHANGED
@@ -105,12 +105,40 @@ function overall_rating_auto_insert_code () {
105
  $overall_rating = "-1";
106
  }
107
 
108
- $shortcode_html="<div class=\"rateit bigstars\" id=\"yasr_rateit_overall\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$overall_rating\" data-rateit-step=\"0.1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
109
- </div>";
110
-
111
  $option = get_option( 'yasr_general_options' );
112
 
113
- return $shortcode_html;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
  } //End function
116
 
@@ -146,19 +174,24 @@ function visitor_votes_auto_insert_code () {
146
  }
147
  }
148
 
149
- $allow_logged_option = get_option( 'yasr_general_options' );
150
 
151
- if (!$allow_logged_option) {
152
  $allow_logged_option = array();
153
  $allow_logged_option['allowed_user']='allow_anonymous';
154
  }
155
 
 
 
 
 
156
  $image = YASR_IMG_DIR . "/loader.gif";
157
 
158
  $loader_html = "<div id=\"loader-visitor-rating\" >&nbsp; " . __("Loading, please wait","yasr") . " <img src= \" $image \"></div>";
159
 
160
  $medium_rating=round($medium_rating, 1);
161
 
 
162
  //if anonymous are allowed to vote
163
  if ($allow_logged_option['allowed_user']==='allow_anonymous') {
164
 
@@ -273,6 +306,16 @@ function visitor_votes_auto_insert_code () {
273
  }
274
 
275
 
 
 
 
 
 
 
 
 
 
 
276
  ?>
277
 
278
  <script>
@@ -356,10 +399,12 @@ function visitor_votes_auto_insert_code () {
356
 
357
  } //End if is singular
358
 
359
- return $shortcode_html;
360
 
361
  } //End function shortcode_visitor_votes_callback
362
 
 
 
363
  /****** Auto insert overall rating and visitor rating ******/
364
 
365
  add_filter('the_content', 'yasr_auto_insert_shortcode_callback');
@@ -507,31 +552,31 @@ function visitor_votes_auto_insert_code () {
507
  (Thanks to wordpress.stackexchange) ******/
508
 
509
  // init process for registering our button
510
- add_action('init', 'yasr_shortcode_button_init');
511
- function yasr_shortcode_button_init() {
512
 
513
- //Abort early if the user will never see TinyMCE
514
- if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') && get_user_option('rich_editing') == 'true')
515
  return;
516
 
517
- //Add a callback to regiser our tinymce plugin
518
- add_filter("mce_external_plugins", "yasr_register_tinymce_plugin");
519
 
520
- // Add a callback to add our button to the TinyMCE toolbar
521
- add_filter('mce_buttons', 'yasr_add_tinymce_button');
522
 
523
- }
524
 
525
 
526
- //This callback registers our plug-in
527
- function yasr_register_tinymce_plugin($plugin_array) {
528
- $plugin_array['yasr_button'] = YASR_JS_DIR . 'addButton_tinymcs.js';
529
- return $plugin_array;
530
- }
531
 
532
- //This callback adds our button to the toolbar
533
- function yasr_add_tinymce_button($buttons) {
534
- //Add the button ID to the $button array
535
- $buttons[] = "yasr_button";
536
- return $buttons;
537
- }
105
  $overall_rating = "-1";
106
  }
107
 
 
 
 
108
  $option = get_option( 'yasr_general_options' );
109
 
110
+ if($option['text_before_stars'] == 1 && $option['text_before_overall'] != '') {
111
+ $shortcode_html = "<div class=\"yasr-container-custom-text-and-overall\">
112
+ <span id=\"yasr-custom-text-before-overall\">$option[text_before_overall]</span>
113
+ <div class=\"rateit bigstars\" id=\"yasr_rateit_overall\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$overall_rating\" data-rateit-step=\"0.1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
114
+ </div>
115
+ </div>";
116
+ }
117
+
118
+ else {
119
+
120
+ $shortcode_html="<div class=\"rateit bigstars\" id=\"yasr_rateit_overall\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$overall_rating\" data-rateit-step=\"0.1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
121
+ </div>";
122
+
123
+ }
124
+
125
+ //IF show overall rating in loop is disabled use is_singular && is_main query
126
+ if ($option['show_overall_in_loop'] === 'disabled') {
127
+
128
+ if( is_singular() && is_main_query() ) {
129
+
130
+ return $shortcode_html;
131
+
132
+ }
133
+
134
+ }
135
+
136
+ //else don't
137
+ elseif ($option['show_overall_in_loop'] === 'enabled') {
138
+
139
+ return $shortcode_html;
140
+
141
+ }
142
 
143
  } //End function
144
 
174
  }
175
  }
176
 
177
+ $option = get_option( 'yasr_general_options' );
178
 
179
+ if ( !$option ) {
180
  $allow_logged_option = array();
181
  $allow_logged_option['allowed_user']='allow_anonymous';
182
  }
183
 
184
+ else {
185
+ $allow_logged_option = $option;
186
+ }
187
+
188
  $image = YASR_IMG_DIR . "/loader.gif";
189
 
190
  $loader_html = "<div id=\"loader-visitor-rating\" >&nbsp; " . __("Loading, please wait","yasr") . " <img src= \" $image \"></div>";
191
 
192
  $medium_rating=round($medium_rating, 1);
193
 
194
+
195
  //if anonymous are allowed to vote
196
  if ($allow_logged_option['allowed_user']==='allow_anonymous') {
197
 
306
  }
307
 
308
 
309
+ if($option['text_before_stars'] == 1 && $option['text_before_visitor_rating'] != '') {
310
+
311
+ $shortcode_html_tmp = "<div class=\"yasr-container-custom-text-and-visitor-rating\">
312
+ <div id=\"yasr-custom-text-before-visitor-rating\">$option[text_before_visitor_rating]</div>" . $shortcode_html . "</div>";
313
+
314
+ $shortcode_html = $shortcode_html_tmp;
315
+
316
+ }
317
+
318
+
319
  ?>
320
 
321
  <script>
399
 
400
  } //End if is singular
401
 
402
+ return $shortcode_html;
403
 
404
  } //End function shortcode_visitor_votes_callback
405
 
406
+
407
+
408
  /****** Auto insert overall rating and visitor rating ******/
409
 
410
  add_filter('the_content', 'yasr_auto_insert_shortcode_callback');
552
  (Thanks to wordpress.stackexchange) ******/
553
 
554
  // init process for registering our button
555
+ add_action('init', 'yasr_shortcode_button_init');
556
+ function yasr_shortcode_button_init() {
557
 
558
+ //Abort early if the user will never see TinyMCE
559
+ if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') && get_user_option('rich_editing') == 'true')
560
  return;
561
 
562
+ //Add a callback to regiser our tinymce plugin
563
+ add_filter("mce_external_plugins", "yasr_register_tinymce_plugin");
564
 
565
+ // Add a callback to add our button to the TinyMCE toolbar
566
+ add_filter('mce_buttons', 'yasr_add_tinymce_button');
567
 
568
+ }
569
 
570
 
571
+ //This callback registers our plug-in
572
+ function yasr_register_tinymce_plugin($plugin_array) {
573
+ $plugin_array['yasr_button'] = YASR_JS_DIR . 'addButton_tinymcs.js';
574
+ return $plugin_array;
575
+ }
576
 
577
+ //This callback adds our button to the toolbar
578
+ function yasr_add_tinymce_button($buttons) {
579
+ //Add the button ID to the $button array
580
+ $buttons[] = "yasr_button";
581
+ return $buttons;
582
+ }
lib/yasr-settings-functions.php CHANGED
@@ -13,30 +13,24 @@
13
 
14
  $option = get_option( 'yasr_general_options' );
15
 
16
- //To avoid undifined index, i put here the default value
17
- if (!$option) {
18
- $option = array();
19
- $option['auto_insert_enabled'] = 0;
20
- $option['auto_insert_what'] = 'overall_rating';
21
- $option['auto_insert_where'] = 'top';
22
- $option['snippet'] = 'overall_rating';
23
- $option['allowed_user'] = 'allow_anonymous';
24
-
25
- add_option("yasr_general_options", $option); //Write here the default value if there is not option
26
- }
27
-
28
  //This is to avoid undefined offset
29
  if ($option && $option['auto_insert_enabled']==0) {
30
  $option['auto_insert_what']='overall_rating';
31
  $option['auto_insert_where']='top';
32
  }
33
 
34
- add_settings_section( 'yasr_auto_insert_section_id', __('Auto insert Settings', 'yasr'), 'yasr_section_callback', 'yasr_settings_page' );
35
- add_settings_field( 'yasr_use_auto_insert_id', __('Use auto insert?', 'yasr'), 'yasr_auto_insert_callback', 'yasr_settings_page', 'yasr_auto_insert_section_id', $option );
36
- add_settings_field( 'yasr_what_auto_insert', __('What?', 'yasr'), 'yasr_what_auto_insert_callback', 'yasr_settings_page', 'yasr_auto_insert_section_id', $option);
37
- add_settings_field( 'yasr_where_auto_insert', __('Where?', 'yasr'), 'yasr_where_auto_insert_callback', 'yasr_settings_page', 'yasr_auto_insert_section_id', $option);
38
- add_settings_field( 'yasr_allow_only_logged_in_id', __('Allow only logged in user to vote?', 'yasr'), 'yasr_allow_only_logged_in_callback', 'yasr_settings_page', 'yasr_auto_insert_section_id', $option );
39
- add_settings_field( 'yasr_choose_snippet_id', __('Which rich snippets do you want to use?', 'yasr'), 'yasr_choose_snippet_callback', 'yasr_settings_page', 'yasr_auto_insert_section_id', $option );
 
 
 
 
 
 
40
 
41
  }
42
 
@@ -49,63 +43,134 @@
49
 
50
  ?>
51
 
52
- <?php _e('Yes', 'yasr') ?>
53
-
54
- <input type='radio' name='yasr_general_options[auto_insert_enabled]' value='1' id='yasr_auto_insert_radio_on' <?php if ($option['auto_insert_enabled']==1) echo " checked=\"checked\" "; ?> />
55
  &nbsp;&nbsp;&nbsp;
56
 
57
- <?php _e('No', 'yasr') ?>
58
  <input type='radio' name='yasr_general_options[auto_insert_enabled]' value='0' id='yasr_auto_insert_radio_off'
59
  <?php if ($option['auto_insert_enabled']==0) {
60
- echo " checked=\"checked\" />";
61
  echo ("<script>
62
  jQuery( document ).ready(function() {
63
  jQuery('.yasr_auto_insert_where_what_radio').prop('disabled', true);
64
  });
65
  </script>") ;
66
  }
 
 
 
 
 
 
 
67
  ?>
68
-
69
 
70
- <?php
71
- } //End yasr_auto_insert_callback
72
 
73
- function yasr_what_auto_insert_callback($option) {
74
- ?>
 
 
 
 
 
 
 
 
 
 
75
 
76
- <input type="radio" name="yasr_general_options[auto_insert_what]" value="overall_rating" class="yasr_auto_insert_where_what_radio" <?php if ($option['auto_insert_what']==='overall_rating') echo " checked=\"checked\" "; ?> >
77
- <?php _e('Overall Rating / Author Rating', 'yasr') ?>
78
- <br />
79
 
80
- <input type="radio" name="yasr_general_options[auto_insert_what]" value="visitor_rating" class="yasr_auto_insert_where_what_radio" <?php if ($option['auto_insert_what']==='visitor_rating') echo " checked=\"checked\" "; ?> >
81
- <?php _e('Visitor Votes', 'yasr')?>
82
- <br />
 
 
83
 
84
- <input type="radio" name="yasr_general_options[auto_insert_what]" value="both" class="yasr_auto_insert_where_what_radio" <?php if ($option['auto_insert_what']==='both') echo " checked=\"checked\" "; ?> >
85
- <?php _e('Both', 'yasr')?>
 
 
 
 
 
 
86
 
87
  <?php
88
- } //end function yasr_what_auto_insert_callback
89
 
90
- function yasr_where_auto_insert_callback($option) {
91
- ?>
92
 
93
- <input type="radio" name="yasr_general_options[auto_insert_where]" value="top" class="yasr_auto_insert_where_what_radio" <?php if ($option['auto_insert_where']==='top' ) echo " checked=\"checked\" "; ?> >
94
- <?php _e('Before the post', 'yasr')?>
 
 
 
 
 
 
 
 
 
 
95
  <br />
96
 
97
- <input type="radio" name="yasr_general_options[auto_insert_where]" value="bottom" class="yasr_auto_insert_where_what_radio" <?php if ($option['auto_insert_where']==='bottom') echo " checked=\"checked\" "; ?> >
98
- <?php _e('After the post', 'yasr')?>
99
- <br />
100
 
101
- <p>&nbsp;</p>
102
 
103
- <hr />
 
 
104
 
105
  <?php
106
 
107
  }
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
  function yasr_allow_only_logged_in_callback($option) {
111
 
@@ -119,9 +184,9 @@
119
  <?php _e('Allow everybody (logged in and anonymous)', 'yasr')?>
120
  <br />
121
 
122
- <p>&nbsp;</p>
123
 
124
- <hr>
125
 
126
  <?php
127
 
@@ -170,7 +235,7 @@ function yasr_display_multi_set_form() {
170
  <h4 class="yasr-multi-set-form-headers">Add New Multiple Set</h4>
171
  <em><?php _e('Field Name, Element#1 and Element#2 MUST be filled and must be long at least 3 characters', 'yasr') ?></em>
172
  <p>
173
- <form action="<?php echo admin_url('options-general.php?page=yasr_settings_page') ?>" id="form_add_multi_set" method="post">
174
  <strong><?php _e("Name", 'yasr')?></strong>
175
  <input type="text" name="multi-set-name" id="new-multi-set-name" class="input-text-multi-set">
176
  <input type="hidden" name="action" value="yasr_new_multi_set_form" />
@@ -246,50 +311,47 @@ function yasr_edit_multi_form() {
246
 
247
  <h4 class="yasr-multi-set-form-headers">Manage Multiple Set</h4>
248
 
249
- <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page') ?>" id="form_edit_multi_set" method="post">
250
-
251
- <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />
252
 
253
- <table id="yasr-table-form-edit-multi-set">
254
- <tr>
255
 
256
- <td id="yasr-table-form-edit-multi-set-header">
257
- <?php _e('Field name', 'yasr') ?>
258
- </td>
259
 
260
- <td id="yasr-table-form-edit-multi-set-remove">
261
- <?php _e('Remove', 'yasr') ?>
262
- </td>
263
 
264
- </tr>
 
 
265
 
266
- <?php
267
 
268
- $i=1;
269
 
270
- //Put in an array the field_id used for this set, to avoid overwrite
271
- $array_used_field_id = array();
272
 
273
- foreach ($set_name as $name) {
274
 
275
- $array_used_field_id[] .= $name->id;
 
 
 
 
 
 
276
 
277
- echo "
278
- <tr>
279
-
280
- <td width=\"80%\">
281
- Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$name->id\">
282
- </td>
283
 
284
- <td width=\"20%\" style=\"text-align:center\">
285
- <input type=\"checkbox\" name=\"remove-element-$name->id\">
286
- </td>
 
287
 
288
- </tr>
289
- ";
290
-
291
- $i++;
292
- }
293
 
294
 
295
  $i = $i-1; //This is the number of the fields
@@ -363,11 +425,11 @@ function yasr_edit_multi_form() {
363
  WHERE parent_set_id=$set_type
364
  ORDER BY field_id ASC");
365
 
366
- $i=1;
367
 
368
  ?>
369
 
370
- <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page') ?>" id="form_edit_multi_set" method="post">
371
  <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />
372
 
373
 
@@ -386,28 +448,27 @@ function yasr_edit_multi_form() {
386
 
387
  <?php
388
 
389
- //Put in an array the field_id used for this set, to avoid overwrite
390
-
391
- $array_used_field_id = array();
392
 
393
  foreach ($set_name as $name) {
394
 
395
- $array_used_field_id .= $name->id;
396
-
397
  echo "
398
  <tr>
399
 
400
  <td width=\"80%\">
401
- Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$name->id\">
 
402
  </td>
403
 
404
  <td width=\"20%\" style=\"text-align:center\">
405
- <input type=\"checkbox\" name=\"remove-element-$name->id\">
406
  </td>
407
 
408
  </tr>
409
  ";
 
410
  $i++;
 
411
  }
412
 
413
 
@@ -661,34 +722,36 @@ function yasr_process_edit_multi_set_form() {
661
  array ('%d')
662
  );
663
 
664
- if ($remove_set===FALSE) {
665
  $error = TRUE;
666
- $array_errors[] = __("Something goes wrong trying to delete a multi-set . Please report it", 'yasr');
667
  }
668
 
669
- if ($remove_set_values===FALSE) {
670
  $error = TRUE;
671
- $array_errors[] = __("Something goes wrong trying to delete data fields for a set. Please report it", 'yasr');
672
  }
673
 
674
- if ($remove_set_votes===FALSE) {
 
675
  $error = TRUE;
676
- $array_errors[] = __("Something goes wrong trying to delete data values for a set. Please report it", 'yasr');
677
- }
678
 
679
  }
680
 
681
-
682
  for ($i = 0; $i <= 9; $i++) {
683
 
684
  //Than, check if the user want to remove some field
685
  if (isset($_POST["remove-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) ) {
686
 
 
 
687
  $remove_field = $wpdb->delete (
688
  YASR_MULTI_SET_FIELDS_TABLE,
689
  array(
690
  'parent_set_id' => $set_id,
691
- 'field_id' =>$i
692
  ),
693
  array ('%d', '%d')
694
  );
@@ -697,20 +760,22 @@ function yasr_process_edit_multi_set_form() {
697
  YASR_MULTI_SET_VALUES_TABLE,
698
  array(
699
  'set_type' => $set_id,
700
- 'field_id' =>$i
701
  ),
702
  array ('%d', '%d')
703
  );
704
 
705
- if ($remove_field === FALSE) {
706
  $error = TRUE;
707
  $array_errors[] = __("Something goes wrong trying to delete a multi-set element. Please report it", 'yasr');
708
  }
709
 
710
- if ($remove_values === FALSE) {
 
 
711
  $error = TRUE;
712
  $array_errors[] = __("Something goes wrong trying to delete data value for an element. Please report it", 'yasr');
713
- }
714
 
715
 
716
  } //End if isset $_POST['remove-element-$i']
@@ -721,6 +786,8 @@ function yasr_process_edit_multi_set_form() {
721
 
722
  $field_name = $_POST["edit-multi-set-element-$i"];
723
 
 
 
724
  //if elements name is shorter than 3 chars
725
  if (mb_strlen($field_name) <3 ) {
726
  $array_errors[] = __("Field # $i must be at least 3 characters", "yasr");
@@ -729,28 +796,40 @@ function yasr_process_edit_multi_set_form() {
729
 
730
  else {
731
 
732
- $insert_field_name=$wpdb->update(
733
- YASR_MULTI_SET_FIELDS_TABLE,
734
 
735
- array(
736
- 'field_name' =>$field_name,
737
- ),
738
 
739
- array(
740
- 'parent_set_id' =>$set_id,
741
- 'field_id' =>$i
742
- ),
743
 
744
- array ('%s'),
 
745
 
746
- array ('%d', '%s', '%d')
747
-
748
- );
749
 
750
- if ($insert_field_name === FALSE) {
751
- $error = TRUE;
752
- $array_errors[] = __("Something goes wrong trying to update a multi set element. Please report it", 'yasr');
753
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
754
 
755
  }
756
 
@@ -758,7 +837,7 @@ function yasr_process_edit_multi_set_form() {
758
 
759
 
760
  //If $i > number of stored elements, user is adding new elements, so we're going to insert the new ones
761
- if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["remove-element-$i"]) && $i > $number_of_stored_elements ) {
762
 
763
  $field_name = $_POST["edit-multi-set-element-$i"];
764
 
@@ -775,23 +854,29 @@ function yasr_process_edit_multi_set_form() {
775
 
776
  $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
777
 
 
 
778
  foreach ($highest_id as $id) {
779
  $field_table_new_id=$id->id + 1;
780
  }
781
 
 
 
 
 
782
  $insert_set_value=$wpdb->replace(
783
  YASR_MULTI_SET_FIELDS_TABLE,
784
  array(
785
  'id' => $field_table_new_id,
786
  'parent_set_id' =>$set_id,
787
  'field_name' =>$field_name,
788
- 'field_id' =>$i
789
  ),
790
  array ('%d', '%d', '%s', '%d')
791
  );
792
  $field_table_new_id++; //Avoid overwrite
793
 
794
- if ($insert_set_value === FALSE) {
795
  $error = TRUE;
796
  $array_errors[] = __("Something goes wrong trying to insert set field name in edit form. Please report it", 'yasr');
797
  }
13
 
14
  $option = get_option( 'yasr_general_options' );
15
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  //This is to avoid undefined offset
17
  if ($option && $option['auto_insert_enabled']==0) {
18
  $option['auto_insert_what']='overall_rating';
19
  $option['auto_insert_where']='top';
20
  }
21
 
22
+ //This is to avoid undefined offset
23
+ if ($option && $option['text_before_stars']==0) {
24
+ $option['text_before_overall']='';
25
+ $option['text_before_visitor_rating']='';
26
+ }
27
+
28
+ add_settings_section( 'yasr_general_options_section_id', __('General settings', 'yasr'), 'yasr_section_callback', 'yasr_settings_page' );
29
+ add_settings_field( 'yasr_use_auto_insert_id', __('Use auto insert?', 'yasr'), 'yasr_auto_insert_callback', 'yasr_settings_page', 'yasr_general_options_section_id', $option );
30
+ add_settings_field( 'yasr_show_overall_in_loop', __('Show overall rating in Home Page?', 'yasr'), 'yasr_show_overall_in_loop_callback', 'yasr_settings_page', 'yasr_general_options_section_id', $option);
31
+ add_settings_field( 'yasr_custom_text', __('Insert custom text to show before stars', 'yasr'), 'yasr_custom_text_callback', 'yasr_settings_page', 'yasr_general_options_section_id', $option);
32
+ add_settings_field( 'yasr_allow_only_logged_in_id', __('Allow only logged in user to vote?', 'yasr'), 'yasr_allow_only_logged_in_callback', 'yasr_settings_page', 'yasr_general_options_section_id', $option );
33
+ add_settings_field( 'yasr_choose_snippet_id', __('Which rich snippets do you want to use?', 'yasr'), 'yasr_choose_snippet_callback', 'yasr_settings_page', 'yasr_general_options_section_id', $option );
34
 
35
  }
36
 
43
 
44
  ?>
45
 
46
+ <input type='radio' name='yasr_general_options[auto_insert_enabled]' value='1' id='yasr_auto_insert_radio_on' <?php if ($option['auto_insert_enabled']==1) echo " checked='checked' "; ?> />
47
+ <?php _e('Yes', 'yasr') ?>
 
48
  &nbsp;&nbsp;&nbsp;
49
 
50
+
51
  <input type='radio' name='yasr_general_options[auto_insert_enabled]' value='0' id='yasr_auto_insert_radio_off'
52
  <?php if ($option['auto_insert_enabled']==0) {
53
+ echo " checked='checked' />";
54
  echo ("<script>
55
  jQuery( document ).ready(function() {
56
  jQuery('.yasr_auto_insert_where_what_radio').prop('disabled', true);
57
  });
58
  </script>") ;
59
  }
60
+
61
+ else {
62
+ echo "/>";
63
+ }
64
+
65
+ _e('No', 'yasr');
66
+
67
  ?>
 
68
 
69
+ <p>&nbsp;</p>
 
70
 
71
+ <strong><?php _e('What?', 'yasr'); ?></strong>
72
+ <br />
73
+ <input type="radio" name="yasr_general_options[auto_insert_what]" value="overall_rating" class="yasr_auto_insert_where_what_radio" <?php if ($option['auto_insert_what']==='overall_rating') echo " checked=\"checked\" "; ?> >
74
+ <?php _e('Overall Rating / Author Rating', 'yasr') ?>
75
+ <br />
76
+
77
+ <input type="radio" name="yasr_general_options[auto_insert_what]" value="visitor_rating" class="yasr_auto_insert_where_what_radio" <?php if ($option['auto_insert_what']==='visitor_rating') echo " checked=\"checked\" "; ?> >
78
+ <?php _e('Visitor Votes', 'yasr')?>
79
+ <br />
80
+
81
+ <input type="radio" name="yasr_general_options[auto_insert_what]" value="both" class="yasr_auto_insert_where_what_radio" <?php if ($option['auto_insert_what']==='both') echo " checked=\"checked\" "; ?> >
82
+ <?php _e('Both', 'yasr')?>
83
 
84
+ <p>&nbsp;</p>
 
 
85
 
86
+ <strong><?php _e('Where?', 'yasr'); ?></strong>
87
+ <br />
88
+ <input type="radio" name="yasr_general_options[auto_insert_where]" value="top" class="yasr_auto_insert_where_what_radio" <?php if ($option['auto_insert_where']==='top' ) echo " checked=\"checked\" "; ?> >
89
+ <?php _e('Before the post', 'yasr')?>
90
+ <br />
91
 
92
+ <input type="radio" name="yasr_general_options[auto_insert_where]" value="bottom" class="yasr_auto_insert_where_what_radio" <?php if ($option['auto_insert_where']==='bottom') echo " checked=\"checked\" "; ?> >
93
+ <?php _e('After the post', 'yasr')?>
94
+ <br />
95
+
96
+ <p>&nbsp;</p>
97
+
98
+ <hr />
99
+
100
 
101
  <?php
102
+ } //End yasr_auto_insert_callback
103
 
 
 
104
 
105
+ function yasr_show_overall_in_loop_callback($option) {
106
+
107
+ ?>
108
+
109
+ <input type='radio' name='yasr_general_options[show_overall_in_loop]' value='enabled' class='yasr-general-option-show-overall-in-loop' <?php if ($option['show_overall_in_loop']==='enabled') echo " checked=\"checked\" "; ?> />
110
+ <?php _e('Yes', 'yasr')?>
111
+
112
+ &nbsp;&nbsp;&nbsp;
113
+
114
+ <input type='radio' name='yasr_general_options[show_overall_in_loop]' value='disabled' class='yasr-general-option-show-overall-in-loop' <?php if ($option['show_overall_in_loop']==='disabled') echo " checked=\"checked\" "; ?> />
115
+ <?php _e('No', 'yasr')?>
116
+ <br />
117
  <br />
118
 
119
+ <?php _e('If you enable this, "Overall Rating" will be showed not only in the single article or page, but also in pages like Home Page, category pages or archives.', 'yasr')?>
 
 
120
 
121
+ <p>&nbsp;</p>
122
 
123
+ <br />
124
+
125
+ <hr>
126
 
127
  <?php
128
 
129
  }
130
 
131
+ function yasr_custom_text_callback($option) {
132
+ ?>
133
+
134
+ <input type='radio' name='yasr_general_options[text_before_stars]' value='1' id='yasr_text_before_star_on' <?php if ($option['text_before_stars']==1) echo " checked='checked' "; ?> />
135
+ <?php _e('Yes', 'yasr') ?>
136
+ &nbsp;&nbsp;&nbsp;
137
+
138
+ <input type='radio' name='yasr_general_options[text_before_stars]' value='0' id='yasr_text_before_star_off'
139
+ <?php if ($option['text_before_stars']==0) {
140
+ echo " checked='checked' />";
141
+ echo ("<script>
142
+ jQuery( document ).ready(function() {
143
+ jQuery('.yasr-general-options-text-before').prop('disabled', true);
144
+ });
145
+ </script>") ;
146
+ }
147
+
148
+ else {
149
+ echo "/>";
150
+ }
151
+
152
+ _e('No', 'yasr');
153
+
154
+ ?>
155
+
156
+ <br /> <br />
157
+
158
+ <input type='text' name='yasr_general_options[text_before_overall]' class='yasr-general-options-text-before' value='<?php echo ("$option[text_before_overall]"); ?>' maxlength="40"/>
159
+ <?php _e('Custom text to display before overall rating', 'yasr')?>
160
+
161
+ <br /> <br />
162
+
163
+ <input type='text' name='yasr_general_options[text_before_visitor_rating]' class='yasr-general-options-text-before' value='<?php echo ("$option[text_before_visitor_rating]"); ?>' maxlength="40"/>
164
+ <?php _e('Custom text to display before visitor rating', 'yasr')?>
165
+
166
+
167
+ <p>&nbsp;</p>
168
+
169
+ <hr>
170
+
171
+ <?php
172
+ }
173
+
174
 
175
  function yasr_allow_only_logged_in_callback($option) {
176
 
184
  <?php _e('Allow everybody (logged in and anonymous)', 'yasr')?>
185
  <br />
186
 
187
+ <p>&nbsp;</p>
188
 
189
+ <hr>
190
 
191
  <?php
192
 
235
  <h4 class="yasr-multi-set-form-headers">Add New Multiple Set</h4>
236
  <em><?php _e('Field Name, Element#1 and Element#2 MUST be filled and must be long at least 3 characters', 'yasr') ?></em>
237
  <p>
238
+ <form action="<?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>" id="form_add_multi_set" method="post">
239
  <strong><?php _e("Name", 'yasr')?></strong>
240
  <input type="text" name="multi-set-name" id="new-multi-set-name" class="input-text-multi-set">
241
  <input type="hidden" name="action" value="yasr_new_multi_set_form" />
311
 
312
  <h4 class="yasr-multi-set-form-headers">Manage Multiple Set</h4>
313
 
314
+ <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>" id="form_edit_multi_set" method="post">
 
 
315
 
316
+ <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />
 
317
 
318
+ <table id="yasr-table-form-edit-multi-set">
319
+ <tr>
 
320
 
321
+ <td id="yasr-table-form-edit-multi-set-header">
322
+ <?php _e('Field name', 'yasr') ?>
323
+ </td>
324
 
325
+ <td id="yasr-table-form-edit-multi-set-remove">
326
+ <?php _e('Remove', 'yasr') ?>
327
+ </td>
328
 
329
+ </tr>
330
 
331
+ <?php
332
 
333
+ $i=1;
 
334
 
335
+ foreach ($set_name as $name) {
336
 
337
+ echo "
338
+ <tr>
339
+
340
+ <td width=\"80%\">
341
+ Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$i\">
342
+ <input type=\"hidden\" value=\"$name->id\" name=\"db-id-for-element-$i\">
343
+ </td>
344
 
345
+ <td width=\"20%\" style=\"text-align:center\">
346
+ <input type=\"checkbox\" value=\"$name->id\" name=\"remove-element-$i\">
347
+ </td>
 
 
 
348
 
349
+ </tr>
350
+ ";
351
+
352
+ $i++;
353
 
354
+ }
 
 
 
 
355
 
356
 
357
  $i = $i-1; //This is the number of the fields
425
  WHERE parent_set_id=$set_type
426
  ORDER BY field_id ASC");
427
 
428
+
429
 
430
  ?>
431
 
432
+ <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>" id="form_edit_multi_set" method="post">
433
  <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />
434
 
435
 
448
 
449
  <?php
450
 
451
+ $i=1;
 
 
452
 
453
  foreach ($set_name as $name) {
454
 
 
 
455
  echo "
456
  <tr>
457
 
458
  <td width=\"80%\">
459
+ Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$i\">
460
+ <input type=\"hidden\" value=\"$name->id\" name=\"db-id-for-element-$i\">
461
  </td>
462
 
463
  <td width=\"20%\" style=\"text-align:center\">
464
+ <input type=\"checkbox\" value=\"$name->id\" name=\"remove-element-$i\">
465
  </td>
466
 
467
  </tr>
468
  ";
469
+
470
  $i++;
471
+
472
  }
473
 
474
 
722
  array ('%d')
723
  );
724
 
725
+ if ($remove_set==FALSE) {
726
  $error = TRUE;
727
+ $array_errors[] .= __("Something goes wrong trying to delete a multi-set . Please report it", 'yasr');
728
  }
729
 
730
+ if ($remove_set_values==FALSE) {
731
  $error = TRUE;
732
+ $array_errors[] .= __("Something goes wrong trying to delete data fields for a set. Please report it", 'yasr');
733
  }
734
 
735
+ //Comment this out, will echo error even if the value for that field it's just empty
736
+ /*if ($remove_set_votes==FALSE) {
737
  $error = TRUE;
738
+ $array_errors[] .= __("Something goes wrong trying to delete data values for a set. Please report it", 'yasr');
739
+ }*/
740
 
741
  }
742
 
 
743
  for ($i = 0; $i <= 9; $i++) {
744
 
745
  //Than, check if the user want to remove some field
746
  if (isset($_POST["remove-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) ) {
747
 
748
+ $field_to_remove = $_POST["remove-element-$i"];
749
+
750
  $remove_field = $wpdb->delete (
751
  YASR_MULTI_SET_FIELDS_TABLE,
752
  array(
753
  'parent_set_id' => $set_id,
754
+ 'field_id' =>$field_to_remove
755
  ),
756
  array ('%d', '%d')
757
  );
760
  YASR_MULTI_SET_VALUES_TABLE,
761
  array(
762
  'set_type' => $set_id,
763
+ 'field_id' =>$field_to_remove
764
  ),
765
  array ('%d', '%d')
766
  );
767
 
768
+ if ($remove_field == FALSE) {
769
  $error = TRUE;
770
  $array_errors[] = __("Something goes wrong trying to delete a multi-set element. Please report it", 'yasr');
771
  }
772
 
773
+
774
+ //Comment this out, will echo error even if the value for that field it's just empty
775
+ /*if ($remove_values == FALSE) {
776
  $error = TRUE;
777
  $array_errors[] = __("Something goes wrong trying to delete data value for an element. Please report it", 'yasr');
778
+ }*/
779
 
780
 
781
  } //End if isset $_POST['remove-element-$i']
786
 
787
  $field_name = $_POST["edit-multi-set-element-$i"];
788
 
789
+ $field_id = $_POST["db-id-for-element-$i"];
790
+
791
  //if elements name is shorter than 3 chars
792
  if (mb_strlen($field_name) <3 ) {
793
  $array_errors[] = __("Field # $i must be at least 3 characters", "yasr");
796
 
797
  else {
798
 
799
+ //Check if field name is changed
800
+ $field_name_in_db = $wpdb->get_results("SELECT field_name FROM " . YASR_MULTI_SET_FIELDS_TABLE . " WHERE field_id=$field_id");
801
 
802
+ foreach ($field_name_in_db as $field_in_db) {
803
+ $field_name_in_database = $field_in_db->field_name;
804
+ }
805
 
806
+ //if field name in db is different from field name in form update it
807
+ if ($field_name_in_database != $field_name) {
 
 
808
 
809
+ $insert_field_name=$wpdb->update(
810
+ YASR_MULTI_SET_FIELDS_TABLE,
811
 
812
+ array(
813
+ 'field_name' =>$field_name,
814
+ ),
815
 
816
+ array(
817
+ 'parent_set_id' =>$set_id,
818
+ 'field_id' =>$field_id
819
+ ),
820
+
821
+ array ('%s'),
822
+
823
+ array ('%d', '%d')
824
+
825
+ );
826
+
827
+ if ($insert_field_name == FALSE) {
828
+ $error = TRUE;
829
+ $array_errors[] = __("Something goes wrong trying to update a multi set element. Please report it", 'yasr');
830
+ }
831
+
832
+ } //End if ($field_name_in_database != $field_name) {
833
 
834
  }
835
 
837
 
838
 
839
  //If $i > number of stored elements, user is adding new elements, so we're going to insert the new ones
840
+ if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i > $number_of_stored_elements ) {
841
 
842
  $field_name = $_POST["edit-multi-set-element-$i"];
843
 
854
 
855
  $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
856
 
857
+ $highest_field_id = $wpdb->get_results("SELECT field_id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY field_id DESC LIMIT 1 ");
858
+
859
  foreach ($highest_id as $id) {
860
  $field_table_new_id=$id->id + 1;
861
  }
862
 
863
+ foreach ($highest_field_id as $id) {
864
+ $new_field_id = $id->field_id+1;
865
+ }
866
+
867
  $insert_set_value=$wpdb->replace(
868
  YASR_MULTI_SET_FIELDS_TABLE,
869
  array(
870
  'id' => $field_table_new_id,
871
  'parent_set_id' =>$set_id,
872
  'field_name' =>$field_name,
873
+ 'field_id' =>$new_field_id
874
  ),
875
  array ('%d', '%d', '%s', '%d')
876
  );
877
  $field_table_new_id++; //Avoid overwrite
878
 
879
+ if ($insert_set_value == FALSE) {
880
  $error = TRUE;
881
  $array_errors[] = __("Something goes wrong trying to insert set field name in edit form. Please report it", 'yasr');
882
  }
lib/yasr-shortcode-functions.php CHANGED
@@ -10,22 +10,53 @@ function shortcode_overall_rating_callback () {
10
 
11
  $option = get_option( 'yasr_general_options' );
12
 
 
 
 
13
  if ($option['auto_insert_enabled'] == 0 || ($option['auto_insert_enabled'] == 1 && $option['auto_insert_what'] === 'visitor_rating' )) {
14
 
15
  $overall_rating=yasr_get_overall_rating();
16
 
17
- if (!$overall_rating) {
18
- $overall_rating = "-1";
19
- }
20
 
21
- $shortcode_html="<div class=\"rateit bigstars\" id=\"yasr_rateit_overall\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$overall_rating\" data-rateit-step=\"0.1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
22
- </div>";
 
 
 
 
 
23
 
24
- return $shortcode_html;
25
 
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- }
 
 
 
 
 
 
 
 
 
29
 
30
 
31
  /****** Add shortcode for user vote ******/
@@ -36,6 +67,9 @@ function shortcode_visitor_votes_callback () {
36
 
37
  $option = get_option( 'yasr_general_options' );
38
 
 
 
 
39
  if ($option['auto_insert_enabled'] == 0 || ($option['auto_insert_enabled'] == 1 && $option['auto_insert_what'] === 'overall_rating' )) {
40
 
41
  $shortcode_html = NULL; //Avoid undefined variable outside is_singular && is_main_query
@@ -167,8 +201,7 @@ function shortcode_visitor_votes_callback () {
167
 
168
  }
169
 
170
-
171
- } //End if user is logged in
172
 
173
  //Else mean user is not logged in
174
  else {
@@ -185,8 +218,17 @@ function shortcode_visitor_votes_callback () {
185
  }
186
 
187
  }
188
-
189
- }
 
 
 
 
 
 
 
 
 
190
 
191
 
192
  ?>
@@ -266,11 +308,11 @@ function shortcode_visitor_votes_callback () {
266
 
267
  });
268
 
269
- </script>
270
 
271
  <?php
272
 
273
- } //End if is singular
274
 
275
  return $shortcode_html;
276
 
10
 
11
  $option = get_option( 'yasr_general_options' );
12
 
13
+ //To avoid double visualization, I will insert this only if auto insert is off or if auto insert is set on visitor rating.
14
+ //If auto insert is on overall rating this shortcode must return nothing
15
+
16
  if ($option['auto_insert_enabled'] == 0 || ($option['auto_insert_enabled'] == 1 && $option['auto_insert_what'] === 'visitor_rating' )) {
17
 
18
  $overall_rating=yasr_get_overall_rating();
19
 
20
+ if (!$overall_rating) {
21
+ $overall_rating = "-1";
22
+ }
23
 
24
+ if($option['text_before_stars'] == 1 && $option['text_before_overall'] != '') {
25
+ $shortcode_html = "<div class=\"yasr-container-custom-text-and-overall\">
26
+ <span id=\"yasr-custom-text-before-overall\">$option[text_before_overall]</span>
27
+ <div class=\"rateit bigstars\" id=\"yasr_rateit_overall\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$overall_rating\" data-rateit-step=\"0.1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
28
+ </div>
29
+ </div>";
30
+ }
31
 
32
+ else {
33
 
34
+ $shortcode_html = "<div class=\"rateit bigstars\" id=\"yasr_rateit_overall\" data-rateit-starwidth=\"32\" data-rateit-starheight=\"32\" data-rateit-value=\"$overall_rating\" data-rateit-step=\"0.1\" data-rateit-resetable=\"false\" data-rateit-readonly=\"true\">
35
+ </div>";
36
+
37
+ }
38
+
39
+ //IF show overall rating in loop is disabled use is_singular && is_main query
40
+ if ($option['show_overall_in_loop'] === 'disabled') {
41
+
42
+ if( is_singular() && is_main_query() ) {
43
+
44
+ return $shortcode_html;
45
+
46
+ }
47
+
48
+ }
49
 
50
+ //else don't
51
+ elseif ($option['show_overall_in_loop'] === 'enabled') {
52
+
53
+ return $shortcode_html;
54
+
55
+ }
56
+
57
+ } //end if auto insert enabled == 0
58
+
59
+ } //end function
60
 
61
 
62
  /****** Add shortcode for user vote ******/
67
 
68
  $option = get_option( 'yasr_general_options' );
69
 
70
+ //To avoid double visualization, I will insert this only if auto insert is off or if auto insert is set on overall rating.
71
+ //If auto insert is on visitor rating this shortcode must return nothing
72
+
73
  if ($option['auto_insert_enabled'] == 0 || ($option['auto_insert_enabled'] == 1 && $option['auto_insert_what'] === 'overall_rating' )) {
74
 
75
  $shortcode_html = NULL; //Avoid undefined variable outside is_singular && is_main_query
201
 
202
  }
203
 
204
+ } //End if user is logged in
 
205
 
206
  //Else mean user is not logged in
207
  else {
218
  }
219
 
220
  }
221
+
222
+ }
223
+
224
+ if($option['text_before_stars'] == 1 && $option['text_before_visitor_rating'] != '') {
225
+
226
+ $shortcode_html_tmp = "<div class=\"yasr-container-custom-text-and-visitor-rating\">
227
+ <div id=\"yasr-custom-text-before-visitor-rating\">$option[text_before_visitor_rating]</div>" . $shortcode_html . "</div>";
228
+
229
+ $shortcode_html = $shortcode_html_tmp;
230
+
231
+ }
232
 
233
 
234
  ?>
308
 
309
  });
310
 
311
+ </script>
312
 
313
  <?php
314
 
315
+ } //End if is singular
316
 
317
  return $shortcode_html;
318
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
3
  Tags: Rating, Review, Star, Snippet, Rich snippet, Schema, Schema.org, Serp
4
  Requires at least: 3.5
5
  Tested up to: 3.9.1
6
- Stable tag: 0.3.3
7
  License: GPL2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -48,6 +48,14 @@ If with gd-star-rating you're using a different number of stars from the default
48
 
49
  == Changelog ==
50
 
 
 
 
 
 
 
 
 
51
  = 0.3.3 =
52
  * Created a new shortcode that will allow to insert Top 10 highest rated product by author
53
  * When a post or page is permanently deleted, yasr will delete every votes for that post or page
3
  Tags: Rating, Review, Star, Snippet, Rich snippet, Schema, Schema.org, Serp
4
  Requires at least: 3.5
5
  Tested up to: 3.9.1
6
+ Stable tag: 0.3.4
7
  License: GPL2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
48
 
49
  == Changelog ==
50
 
51
+ = 0.3.4 =
52
+ * In settings page is now possible add some custom text to make appear before "Overall Rating" or "Visitor's Rating" are showed
53
+ * In settings page is now possible to show "Overall Rating" only in the post / page or even in Home page, Archive Page, etc.
54
+ * Removed bug that could appear in some case when removing or adding field in multiset form editor
55
+ * After a multiset is created/edited now you get redirected on multiset settings tab and not in general settings
56
+ * Various bugfixes
57
+ * Under the hood changes
58
+
59
  = 0.3.3 =
60
  * Created a new shortcode that will allow to insert Top 10 highest rated product by author
61
  * When a post or page is permanently deleted, yasr will delete every votes for that post or page
yasr-settings-page.php CHANGED
@@ -8,8 +8,6 @@ if ( !current_user_can( 'manage_options' ) ) {
8
 
9
  ?>
10
 
11
-
12
-
13
  <div class="wrap">
14
 
15
  <h2>Yet Another Stars Rating: Settings</h2>
@@ -23,10 +21,10 @@ if ( !current_user_can( 'manage_options' ) ) {
23
  if ($error_new_multi_set) {
24
  echo "<div class=\"error\"> <p> <strong>";
25
 
26
- foreach ($error_new_multi_set as $error) {
27
- _e($error, 'yasr');
28
- echo "<br />";
29
- }
30
 
31
  echo "</strong></p></div>";
32
  }
@@ -34,25 +32,21 @@ if ( !current_user_can( 'manage_options' ) ) {
34
  if ($error_edit_multi_set) {
35
  echo "<div class=\"error\"> <p> <strong>";
36
 
37
- foreach ($error_edit_multi_set as $error) {
38
- _e($error, 'yasr');
39
- echo "<br />";
40
- }
41
 
42
  echo "</strong></p></div>";
43
  }
44
 
45
 
46
- if( isset( $_GET[ 'tab' ] ) ) {
47
-
48
  $active_tab = $_GET[ 'tab' ];
49
-
50
  }
51
 
52
  else {
53
-
54
  $active_tab = 'general_settings';
55
-
56
  }
57
 
58
 
@@ -148,19 +142,19 @@ if ( !current_user_can( 'manage_options' ) ) {
148
  <button href="#" class="button-delete" id="import-gdstar"><?php _e('Ok, Import Again'); ?></button>
149
 
150
  <div id="yasr-import-gdstar-div" style="display:none;">
151
- <strong>
152
- <?php _e("Click on Proceed to Import again Gd Star Rating Data. This may take a while!"); ?>
153
- </strong>
154
- <br />
155
- <button href="#" class="button-primary" id="import-button"> <?php _e('Proceed', 'yasr'); ?></button>
156
 
157
- <span id="loader" style="display:none;" >&nbsp;<img src="<?php echo YASR_IMG_DIR . "/loader.gif" ?>">
158
- </span>
159
-
160
- <br />
161
 
162
- <div id="result-import">
163
- </div>
164
 
165
  </div>
166
  </div>
@@ -191,58 +185,58 @@ if ( !current_user_can( 'manage_options' ) ) {
191
 
192
  <div class="yasr-settingsdiv">
193
 
194
- <h3> <?php _e("Manage multi-set"); ?></h3>
195
 
196
- <p>
197
 
198
- <a href="#" id="yasr-multi-set-doc-link"><?php _e("What is a Multi-set?") ?></a>
199
 
200
- </p>
201
 
202
- <div id="yasr-multi-set-doc-box" style="display:none">
203
- <?php _e("Multi-set allows you to insert a rate for each aspect about the product / local business / whetever
204
- you're reviewing, example in the image below.", "yasr");
205
 
206
- echo "<br /><br /><img src=" . YASR_IMG_DIR . "/yasr-multi-set.png> <br /> <br />";
207
 
208
- _e("You can create up to 99 different multi-sets and each one can contain up to 9 different fields.
209
- Once you've saved it, you can insert the rates while typing your article in the box below the editor,
210
- as you can see in this image (click to see it larger)", "yasr");
211
 
212
- echo "<br /><br /><a href=\"" . YASR_IMG_DIR ."yasr-multi-set-insert-rate.jpg\"><img src=" . YASR_IMG_DIR . "/yasr-multi-set-insert-rate-small.jpg></a> <br /> <br />";
213
 
214
- _e("In order to insert your text into a post or page, you can either past
215
- the short code that will appear at the bottom of the box or just click
216
- on the star in the graphic editor and select \"Insert Multi-Set\".", "yasr");
217
 
218
- ?>
219
 
220
- <br /> <br />
221
 
222
- <a href="#" id="yasr-multi-set-doc-link-hide"><?php _e("Close this message") ?></a>
223
 
224
- </div>
225
 
226
- <div class="yasr-multi-set-left">
227
 
228
- <div class="yasr-new-multi-set" >
229
 
230
- <?php yasr_display_multi_set_form(); ?>
231
 
232
- </div> <!--yasr-new-multi-set-->
233
 
234
 
235
- </div> <!--End yasr-multi-set-left-->
236
 
237
- <div class="yasr-multi-set-right">
238
 
239
- <?php yasr_edit_multi_form(); ?>
240
 
241
- <div id="yasr-multi-set-response" style="display:none">
242
 
243
- </div>
244
 
245
- </div> <!--End yasr-multi-set-right-->
246
 
247
 
248
  </div>
@@ -307,8 +301,18 @@ if ( !current_user_can( 'manage_options' ) ) {
307
  jQuery('.yasr_auto_insert_where_what_radio').prop('disabled', true);
308
  });
309
 
 
 
 
 
 
 
 
 
310
  jQuery('#yasr-snippet-explained-link').on('click', function () {
311
  jQuery('#yasr-snippet-explained').toggle('slow');
 
 
312
  });
313
 
314
 
@@ -355,6 +359,7 @@ if ( !current_user_can( 'manage_options' ) ) {
355
  //--------------Multi Sets Page ------------------
356
 
357
  if ($active_tab==='manage_multi') {
 
358
  ?>
359
 
360
  jQuery('#yasr-multi-set-doc-link').on('click', function() {
@@ -367,35 +372,28 @@ if ( !current_user_can( 'manage_options' ) ) {
367
 
368
  <?php if ($n_multi_set == 1) { ?>
369
 
 
370
 
371
- //jQuery('#yasr-manage-multi-set-single').on('click', function() {
372
 
373
- //jQuery('.yasr-manage-multiset-single').toggle();
374
 
375
- var counter = jQuery("#yasr-edit-form-number-elements").attr('value');
376
-
377
- counter++;
378
-
379
- jQuery("#yasr-add-field-edit-multiset").on('click', function() {
380
-
381
- if(counter>9){
382
- jQuery('#yasr-element-limit').show();
383
- jQuery('#yasr-add-field-edit-multiset').hide();
384
- return false;
385
- }
386
-
387
- var newTextBoxDiv = jQuery(document.createElement('tr'))
388
-
389
- newTextBoxDiv.html('<td colspan="2">Element #' + counter + ' <input type="text" name="edit-multi-set-element-' + counter + '" value="" ></td>');
390
-
391
- newTextBoxDiv.appendTo("#yasr-table-form-edit-multi-set");
392
-
393
- counter++;
394
 
395
  });
396
 
397
- // });
398
-
399
  <?php
400
 
401
  } //End if ($n_multi_set == 1)
@@ -407,18 +405,18 @@ if ( !current_user_can( 'manage_options' ) ) {
407
  //If more then 1 set is used...
408
  jQuery('#yasr-button-select-set-edit-form').on("click", function() {
409
 
410
- var data = {
411
- action : 'yasr_get_multi_set',
412
- set_id : jQuery('#yasr_select_edit_set').val()
413
- }
414
-
415
- jQuery.post(ajaxurl, data, function(response) {
416
- jQuery('#yasr-multi-set-response').show();
417
- jQuery('#yasr-multi-set-response').html(response);
418
- });
419
-
420
- return false; // prevent default click action from happening!
421
- e.preventDefault(); // same thing as above
422
 
423
  });
424
 
8
 
9
  ?>
10
 
 
 
11
  <div class="wrap">
12
 
13
  <h2>Yet Another Stars Rating: Settings</h2>
21
  if ($error_new_multi_set) {
22
  echo "<div class=\"error\"> <p> <strong>";
23
 
24
+ foreach ($error_new_multi_set as $error) {
25
+ _e($error, 'yasr');
26
+ echo "<br />";
27
+ }
28
 
29
  echo "</strong></p></div>";
30
  }
32
  if ($error_edit_multi_set) {
33
  echo "<div class=\"error\"> <p> <strong>";
34
 
35
+ foreach ($error_edit_multi_set as $error) {
36
+ _e($error, 'yasr');
37
+ echo "<br />";
38
+ }
39
 
40
  echo "</strong></p></div>";
41
  }
42
 
43
 
44
+ if (isset($_GET['tab'])) {
 
45
  $active_tab = $_GET[ 'tab' ];
 
46
  }
47
 
48
  else {
 
49
  $active_tab = 'general_settings';
 
50
  }
51
 
52
 
142
  <button href="#" class="button-delete" id="import-gdstar"><?php _e('Ok, Import Again'); ?></button>
143
 
144
  <div id="yasr-import-gdstar-div" style="display:none;">
145
+ <strong>
146
+ <?php _e("Click on Proceed to Import again Gd Star Rating Data. This may take a while!"); ?>
147
+ </strong>
148
+ <br />
149
+ <button href="#" class="button-primary" id="import-button"> <?php _e('Proceed', 'yasr'); ?></button>
150
 
151
+ <span id="loader" style="display:none;" >&nbsp;<img src="<?php echo YASR_IMG_DIR . "/loader.gif" ?>">
152
+ </span>
153
+
154
+ <br />
155
 
156
+ <div id="result-import">
157
+ </div>
158
 
159
  </div>
160
  </div>
185
 
186
  <div class="yasr-settingsdiv">
187
 
188
+ <h3> <?php _e("Manage multi-set"); ?></h3>
189
 
190
+ <p>
191
 
192
+ <a href="#" id="yasr-multi-set-doc-link"><?php _e("What is a Multi-set?") ?></a>
193
 
194
+ </p>
195
 
196
+ <div id="yasr-multi-set-doc-box" style="display:none">
197
+ <?php _e("Multi-set allows you to insert a rate for each aspect about the product / local business / whetever
198
+ you're reviewing, example in the image below.", "yasr");
199
 
200
+ echo "<br /><br /><img src=" . YASR_IMG_DIR . "/yasr-multi-set.png> <br /> <br />";
201
 
202
+ _e("You can create up to 99 different multi-sets and each one can contain up to 9 different fields.
203
+ Once you've saved it, you can insert the rates while typing your article in the box below the editor,
204
+ as you can see in this image (click to see it larger)", "yasr");
205
 
206
+ echo "<br /><br /><a href=\"" . YASR_IMG_DIR ."yasr-multi-set-insert-rate.jpg\"><img src=" . YASR_IMG_DIR . "/yasr-multi-set-insert-rate-small.jpg></a> <br /> <br />";
207
 
208
+ _e("In order to insert your text into a post or page, you can either past
209
+ the short code that will appear at the bottom of the box or just click
210
+ on the star in the graphic editor and select \"Insert Multi-Set\".", "yasr");
211
 
212
+ ?>
213
 
214
+ <br /> <br />
215
 
216
+ <a href="#" id="yasr-multi-set-doc-link-hide"><?php _e("Close this message") ?></a>
217
 
218
+ </div>
219
 
220
+ <div class="yasr-multi-set-left">
221
 
222
+ <div class="yasr-new-multi-set" >
223
 
224
+ <?php yasr_display_multi_set_form(); ?>
225
 
226
+ </div> <!--yasr-new-multi-set-->
227
 
228
 
229
+ </div> <!--End yasr-multi-set-left-->
230
 
231
+ <div class="yasr-multi-set-right">
232
 
233
+ <?php yasr_edit_multi_form(); ?>
234
 
235
+ <div id="yasr-multi-set-response" style="display:none">
236
 
237
+ </div>
238
 
239
+ </div> <!--End yasr-multi-set-right-->
240
 
241
 
242
  </div>
301
  jQuery('.yasr_auto_insert_where_what_radio').prop('disabled', true);
302
  });
303
 
304
+ jQuery('#yasr_text_before_star_on').on('click', function(){
305
+ jQuery('.yasr-general-options-text-before').prop('disabled', false);
306
+ });
307
+
308
+ jQuery('#yasr_text_before_star_off').on('click', function(){
309
+ jQuery('.yasr-general-options-text-before').prop('disabled', true);
310
+ });
311
+
312
  jQuery('#yasr-snippet-explained-link').on('click', function () {
313
  jQuery('#yasr-snippet-explained').toggle('slow');
314
+ return false; // prevent default click action from happening!
315
+ preventDefault(); // prevent default click action from happening!
316
  });
317
 
318
 
359
  //--------------Multi Sets Page ------------------
360
 
361
  if ($active_tab==='manage_multi') {
362
+
363
  ?>
364
 
365
  jQuery('#yasr-multi-set-doc-link').on('click', function() {
372
 
373
  <?php if ($n_multi_set == 1) { ?>
374
 
375
+ var counter = jQuery("#yasr-edit-form-number-elements").attr('value');
376
 
377
+ counter++;
378
 
379
+ jQuery("#yasr-add-field-edit-multiset").on('click', function() {
380
 
381
+ if(counter>9){
382
+ jQuery('#yasr-element-limit').show();
383
+ jQuery('#yasr-add-field-edit-multiset').hide();
384
+ return false;
385
+ }
386
+
387
+ var newTextBoxDiv = jQuery(document.createElement('tr'))
388
+
389
+ newTextBoxDiv.html('<td colspan="2">Element #' + counter + ' <input type="text" name="edit-multi-set-element-' + counter + '" value="" ></td>');
390
+
391
+ newTextBoxDiv.appendTo("#yasr-table-form-edit-multi-set");
392
+
393
+ counter++;
 
 
 
 
 
 
394
 
395
  });
396
 
 
 
397
  <?php
398
 
399
  } //End if ($n_multi_set == 1)
405
  //If more then 1 set is used...
406
  jQuery('#yasr-button-select-set-edit-form').on("click", function() {
407
 
408
+ var data = {
409
+ action : 'yasr_get_multi_set',
410
+ set_id : jQuery('#yasr_select_edit_set').val()
411
+ }
412
+
413
+ jQuery.post(ajaxurl, data, function(response) {
414
+ jQuery('#yasr-multi-set-response').show();
415
+ jQuery('#yasr-multi-set-response').html(response);
416
+ });
417
+
418
+ return false; // prevent default click action from happening!
419
+ preventDefault(); // same thing as above
420
 
421
  });
422
 
yet-another-stars-rating.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Yet Another Stars Rating
4
  * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
5
  * Description: Rating system with rich snippets
6
- * Version: 0.3.3
7
  * Author: Dario Curvino
8
  * Author URI: http://profiles.wordpress.org/dudo/
9
  * License: GPL2
@@ -28,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
28
  */
29
 
30
 
31
- define('YASR_VERSION_NUM', '0.3.3');
32
 
33
  //Plugin absolute path
34
  define( "YASR_ABSOLUTE_PATH", dirname(__FILE__) );
@@ -63,9 +63,10 @@ require (YASR_ABSOLUTE_PATH . '/lib/yasr-shortcode-functions.php');
63
 
64
  $version_installed = get_option('yasr-version') ;
65
 
 
66
  //If this is a fresh new installation or version < 0.2.0
67
 
68
- if (!$version_installed || $version_installed < '0.2.0' ) {
69
 
70
  yasr_install();
71
 
@@ -73,7 +74,7 @@ if (!$version_installed || $version_installed < '0.2.0' ) {
73
 
74
  // If user is using a version < 0.3.0 import option
75
 
76
- if (!$version_installed || $version_installed < '0.3.0' ) {
77
 
78
  $old_options = get_option ( 'yasr_auto_insert_options' );
79
 
@@ -107,8 +108,6 @@ if (!$version_installed || $version_installed < '0.3.0' ) {
107
  } //End if (!$version_installed || $version_installed < '0.3.0' )
108
 
109
 
110
- update_option('yasr-version', YASR_VERSION_NUM);
111
-
112
  global $wpdb;
113
 
114
  define ("YASR_VOTES_TABLE", $wpdb->prefix . 'yasr_votes');
@@ -122,4 +121,24 @@ define ("YASR_MULTI_SET_VALUES_TABLE", $wpdb->prefix . 'yasr_multi_values');
122
  define ("YASR_LOG_TABLE", $wpdb->prefix . 'yasr_log');
123
 
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  ?>
3
  * Plugin Name: Yet Another Stars Rating
4
  * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
5
  * Description: Rating system with rich snippets
6
+ * Version: 0.3.4
7
  * Author: Dario Curvino
8
  * Author URI: http://profiles.wordpress.org/dudo/
9
  * License: GPL2
28
  */
29
 
30
 
31
+ define('YASR_VERSION_NUM', '0.3.4');
32
 
33
  //Plugin absolute path
34
  define( "YASR_ABSOLUTE_PATH", dirname(__FILE__) );
63
 
64
  $version_installed = get_option('yasr-version') ;
65
 
66
+
67
  //If this is a fresh new installation or version < 0.2.0
68
 
69
+ if (!$version_installed ) {
70
 
71
  yasr_install();
72
 
74
 
75
  // If user is using a version < 0.3.0 import option
76
 
77
+ if ($version_installed && $version_installed < '0.3.0' ) {
78
 
79
  $old_options = get_option ( 'yasr_auto_insert_options' );
80
 
108
  } //End if (!$version_installed || $version_installed < '0.3.0' )
109
 
110
 
 
 
111
  global $wpdb;
112
 
113
  define ("YASR_VOTES_TABLE", $wpdb->prefix . 'yasr_votes');
121
  define ("YASR_LOG_TABLE", $wpdb->prefix . 'yasr_log');
122
 
123
 
124
+ if ($version_installed && $version_installed < '0.3.4') {
125
+
126
+ $wpdb->query ("ALTER TABLE " . YASR_MULTI_SET_FIELDS_TABLE . " MODIFY field_name VARCHAR( 23 )");
127
+
128
+ $option = array();
129
+ $option['auto_insert_enabled'] = 0;
130
+ $option['auto_insert_what'] = 'overall_rating';
131
+ $option['auto_insert_where'] = 'top';
132
+ $option['show_overall_in_loop'] = 'disabled';
133
+ $option['text_before_stars'] = 0;
134
+ $option['snippet'] = 'overall_rating';
135
+ $option['allowed_user'] = 'allow_anonymous';
136
+
137
+ update_option("yasr_general_options", $option);
138
+
139
+ }
140
+
141
+
142
+ update_option('yasr-version', YASR_VERSION_NUM);
143
+
144
  ?>