Yasr – Yet Another Stars Rating - Version 0.9.0

Version Description

  • FIXED: Fixed bug in multisets (here https://wordpress.org/support/topic/half-stars-not-saving more info)
  • TWEAKED: Minor changes
Download this release

Release Info

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

Code changes from version 0.8.9 to 0.9.0

css/yasr-admin.css CHANGED
@@ -232,6 +232,22 @@ div.bigstars .rateit-selected
232
padding: 25px;
233
font-size: 12px;
234
}
235
}
236
237
@media (max-width: 1176px) {
232
padding: 25px;
233
font-size: 12px;
234
}
235
+
236
+ .yasr-ask-five-stars {
237
+
238
+ float:right;
239
+ display:block;
240
+ min-width: 290px;
241
+ width:15%;
242
+ margin-bottom: 10px;
243
+ background-color:#FFF;
244
+ border-left: 3px solid #7AD03A;
245
+ padding: 25px;
246
+ font-size: 14px;
247
+ /*color: #015316;*/
248
+
249
+ }
250
+
251
}
252
253
@media (max-width: 1176px) {
js/yasr-admin.js CHANGED
@@ -489,6 +489,44 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
489
490
}
491
492
/****** End Yasr Settings Page ******/
493
494
489
490
}
491
492
+ function YasrAsk5Stars(nonceHideAskRating) {
493
+
494
+ //This will call an ajax action that set a site transite to hide
495
+ //for a week the metabok
496
+ jQuery('#yasr-ask-five-star-later').on("click", function(){
497
+
498
+ jQuery('#yasr-ask-five-stars').hide();
499
+
500
+ var data = {
501
+ action: 'yasr_hide_ask_rating_metabox',
502
+ choose: 'hide',
503
+ nonce: nonceHideAskRating
504
+
505
+ };
506
+
507
+ jQuery.post(ajaxurl, data);
508
+
509
+ });
510
+
511
+
512
+ //This will close the ask rating metabox forever
513
+ jQuery('#yasr-ask-five-close').on("click", function(){
514
+
515
+ jQuery('#yasr-ask-five-stars').hide();
516
+
517
+ var data = {
518
+ action: 'yasr_hide_ask_rating_metabox',
519
+ choose: 'close',
520
+ nonce: nonceHideAskRating
521
+ };
522
+
523
+ jQuery.post(ajaxurl, data);
524
+
525
+ });
526
+
527
+
528
+ }
529
+
530
/****** End Yasr Settings Page ******/
531
532
lib/yasr-ajax-functions.php CHANGED
@@ -205,7 +205,7 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
205
//Get Set fields name
206
$set_name=$wpdb->get_results($wpdb->prepare("SELECT field_name AS name, field_id AS id
207
FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
208
- WHERE parent_set_id=%d
209
ORDER BY field_id ASC",
210
$set_type));
211
@@ -367,7 +367,7 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
367
array (
368
'id'=>$id
369
),
370
- array ("%d", "%d", "%d", "%s", "%d"),
371
array ("%d")
372
);
373
@@ -399,7 +399,7 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
399
'votes'=>$vote,
400
'set_type'=>$set_type
401
),
402
- array ("%d", "%d", "%s", "%d")
403
);
404
405
if($result) {
@@ -730,8 +730,7 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
730
731
732
733
- /******
734
- Display recent votes on dashboard, called from function yasr_display_dashboard_log_wiget,
735
declared on yasr-db-function ******/
736
737
@@ -894,10 +893,56 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
894
}
895
896
897
- /**************** END Admin ajax functions ****************/
898
899
900
- /**************** NON Admin ajax functions ****************/
901
902
/****** Yasr insert visitor votes, called from yasr-shortcode-function ******/
903
205
//Get Set fields name
206
$set_name=$wpdb->get_results($wpdb->prepare("SELECT field_name AS name, field_id AS id
207
FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
208
+ WHERE parent_set_id=%f
209
ORDER BY field_id ASC",
210
$set_type));
211
367
array (
368
'id'=>$id
369
),
370
+ array ("%d", "%d", "%d", "%f", "%d"),
371
array ("%d")
372
);
373
399
'votes'=>$vote,
400
'set_type'=>$set_type
401
),
402
+ array ("%d", "%d", "%d", "%f", "%d")
403
);
404
405
if($result) {
730
731
732
733
+ /****** Display recent votes on dashboard, called from function yasr_display_dashboard_log_wiget,
734
declared on yasr-db-function ******/
735
736
893
}
894
895
896
897
+ /****** Ajax function called to hide the ask rating mateabox ******/
898
899
+ add_action( 'wp_ajax_yasr_hide_ask_rating_metabox', 'yasr_hide_ask_rating_metabox' );
900
+
901
+ function yasr_hide_ask_rating_metabox () {
902
+
903
+ if (isset($_POST['nonce']) && isset($_POST['choose']) ) {
904
+
905
+ $choose = $_POST['choose'];
906
+ $nonce = $_POST['nonce'];
907
+
908
+ }
909
+
910
+ else {
911
+
912
+ exit();
913
+
914
+ }
915
+
916
+ if ( ! wp_verify_nonce($nonce, 'yasr_nonce_hide_ask_rating')) {
917
+
918
+ die( 'Security check' );
919
+
920
+ }
921
+
922
+ if ($choose == 'hide') {
923
+
924
+ //set transient for a week
925
+ set_site_transient( 'yasr_hide_ask_rating', 'hide', DAY_IN_SECONDS * 7 );
926
+
927
+ }
928
+
929
+ elseif ($choose == 'close') {
930
+
931
+ //it will not close forever, but for 1 year
932
+ set_site_transient( 'yasr_hide_ask_rating', 'close', YEAR_IN_SECONDS );
933
+
934
+ }
935
+
936
+ die();
937
+
938
+ }
939
+
940
+
941
+
942
+ /********************* END Admin ajax functions ****************/
943
+
944
+
945
+ /********************* NON Admin ajax functions ****************/
946
947
/****** Yasr insert visitor votes, called from yasr-shortcode-function ******/
948
lib/yasr-db-functions.php CHANGED
@@ -479,6 +479,7 @@ add_action ('admin_init', 'admin_init_delete_data_on_post_callback');
479
/****** Check if a logged in user has already rated. Return user vote for a post if exists ******/
480
481
function yasr_check_if_user_already_voted() {
482
global $wpdb;
483
484
global $current_user;
@@ -517,4 +518,28 @@ function yasr_check_if_user_already_voted() {
517
518
}
519
520
?>
479
/****** Check if a logged in user has already rated. Return user vote for a post if exists ******/
480
481
function yasr_check_if_user_already_voted() {
482
+
483
global $wpdb;
484
485
global $current_user;
518
519
}
520
521
+
522
+ /****** Function to get always the last id in the log table ******/
523
+
524
+ function yasr_count_logged_vote () {
525
+
526
+ global $wpdb;
527
+
528
+ $result = $wpdb->get_var("SELECT COUNT(id) FROM " . YASR_LOG_TABLE );
529
+
530
+ if ($result) {
531
+
532
+ return $result;
533
+
534
+ }
535
+
536
+ else {
537
+
538
+ return '0';
539
+
540
+ }
541
+
542
+ }
543
+
544
+
545
?>
lib/yasr-settings-functions.php CHANGED
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
20
21
if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // Exit if accessed directly
22
23
- /****** Add yasr general options ******/
24
25
add_action( 'admin_init', 'yasr_general_options_init' ); //This is for general options
26
@@ -411,77 +411,77 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
411
}
412
413
414
- /****** End Yasr General Settings ******/
415
416
417
418
- /****** Add yasr multiset options and settings******/
419
420
- add_action( 'admin_init', 'yasr_multiset_options_init' ); //This is for general options
421
422
- function yasr_multiset_options_init() {
423
- register_setting(
424
- 'yasr_multiset_options_group', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
425
- 'yasr_multiset_options' //The name of an option to sanitize and save.
426
- );
427
428
- $option_multiset = get_option( 'yasr_multiset_options' );
429
430
- add_settings_section( 'yasr_multiset_options_section_id', '', 'yasr_multiset_section_callback', 'yasr_multiset_tab' );
431
- add_settings_field( 'yasr_color_scheme', __('Which color scheme do you want to use?', 'yasr') , 'yasr_color_scheme_callback', 'yasr_multiset_tab', 'yasr_multiset_options_section_id', $option_multiset);
432
-
433
- }
434
435
- function yasr_multiset_section_callback () {
436
437
- //Silence
438
439
- }
440
441
- function yasr_color_scheme_callback($option_multiset) {
442
443
- if (!$option_multiset['scheme_color']) {
444
445
- $option_multiset['scheme_color'] = 'light';
446
447
- }
448
449
- ?>
450
451
- <input type='radio' name='yasr_multiset_options[scheme_color]' value='light' class='yasr-general-options-scheme-color' <?php if ($option_multiset['scheme_color']==='light') echo " checked=\"checked\" "; ?> />
452
- <?php _e('Light', 'yasr')?>
453
-
454
- &nbsp;&nbsp;&nbsp;
455
456
- <input type='radio' name='yasr_multiset_options[scheme_color]' value='dark' class='yasr-general-options-scheme-color' <?php if ($option_multiset['scheme_color']==='dark') echo " checked=\"checked\" "; ?> />
457
- <?php _e('Dark', 'yasr')?>
458
- <br />
459
460
- <br />
461
462
- <a href="#" id="yasr-color-scheme-preview-link"><?php _e("Preview", "yasr") ?></a>
463
464
- <div id="yasr-color-scheme-preview" style="display:none">
465
- <?php
466
467
- _e("Light theme", "yasr");
468
- echo "<br /><br /><img src=" . YASR_IMG_DIR . "yasr-multi-set.png>";
469
470
- echo "<br /> <br />";
471
472
- _e("Dark theme", "yasr");
473
- echo "<br /><br /><img src=" . YASR_IMG_DIR . "dark-multi-set.png>";
474
- ?>
475
- </div>
476
477
- <p>
478
479
- <?php
480
- }
481
482
483
/****** Create a form for settings page to create new multi set ******/
484
- function yasr_display_multi_set_form() {
485
?>
486
487
<h4 class="yasr-multi-set-form-headers"><?php _e("Add New Multiple Set", "yasr"); ?></h4>
@@ -511,21 +511,21 @@ function yasr_display_multi_set_form() {
511
<input type="submit" value="<?php _e("Create New Set", 'yasr') ?>" class="button-primary"/>
512
</form>
513
514
- <?php
515
- } //End function
516
517
518
519
- function yasr_edit_multi_form() {
520
521
- $multi_set=yasr_get_multi_set();
522
523
- global $wpdb;
524
525
- $n_multi_set = $wpdb->num_rows; //wpdb->num_rows always store the last of the last query
526
527
- if ($n_multi_set > 1) {
528
- ?>
529
530
<div class="yasr-manage-multiset">
531
@@ -545,116 +545,117 @@ function yasr_edit_multi_form() {
545
</div>
546
547
<?php
548
- } //End if n_multi_set >1
549
550
- elseif ($n_multi_set == 1) {
551
552
- $set_name=$wpdb->get_results("SELECT field_name AS name, field_id AS id, parent_set_id AS set_id
553
- FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
554
- ORDER BY field_id ASC");
555
556
- foreach ($multi_set as $find_set_id) {
557
- $set_type = $find_set_id->set_id;
558
- }
559
560
- ?>
561
-
562
- <div class="yasr-manage-multiset-single">
563
564
- <h4 class="yasr-multi-set-form-headers"><?php _e("Manage Multiple Set", "yasr"); ?></h4>
565
566
- <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>" id="form_edit_multi_set" method="post">
567
568
- <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />
569
570
- <table id="yasr-table-form-edit-multi-set">
571
- <tr>
572
573
- <td id="yasr-table-form-edit-multi-set-header">
574
- <?php _e('Field name', 'yasr') ?>
575
- </td>
576
577
- <td id="yasr-table-form-edit-multi-set-remove">
578
- <?php _e('Remove', 'yasr') ?>
579
- </td>
580
581
- </tr>
582
583
- <?php
584
585
- $i=1;
586
587
- foreach ($set_name as $name) {
588
589
- echo "
590
- <tr>
591
-
592
- <td width=\"80%\">
593
- Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$i\">
594
- <input type=\"hidden\" value=\"$name->id\" name=\"db-id-for-element-$i\">
595
- </td>
596
597
- <td width=\"20%\" style=\"text-align:center\">
598
- <input type=\"checkbox\" value=\"$name->id\" name=\"remove-element-$i\">
599
- </td>
600
601
- </tr>
602
- ";
603
-
604
- $i++;
605
606
- }
607
608
609
- $i = $i-1; //This is the number of the fields
610
611
- echo "
612
613
- <input type=\"hidden\" name=\"yasr-edit-form-number-elements\" id=\"yasr-edit-form-number-elements\" value=\"$i\">
614
615
- </table>
616
617
- <table width=\"100%\" class=\"yasr-edit-form-remove-entire-set\">
618
- <tr>
619
620
- <td width=\"80%\">" . __("Remove whole set?", "yasr") . "</td>
621
622
- <td width=\"20%\" style=\"text-align:center\">
623
- <input type=\"checkbox\" name=\"yasr-remove-multi-set\" value=\"$set_type\">
624
- </td>
625
626
- </tr>
627
628
- </table>
629
630
- ";
631
632
- echo "<p>";
633
- _e("If you remove something you will remove all the votes for that set or field. This operation CAN'T BE undone." , "yasr");
634
- echo "</p>";
635
636
- wp_nonce_field( 'edit-multi-set', 'add-nonce-edit-multi-set' )
637
638
- ?>
639
640
- <div id="yasr-element-limit" style="display:none; color:red"><?php _e("You can use up to 9 elements" , "yasr") ?></div>
641
642
- <input type="button" class="button-delete" id="yasr-add-field-edit-multiset" value="<?php _e('Add element', 'yasr'); ?>">
643
644
- <input type="submit" value="<?php _e('Save changes', 'yasr') ?>" class="button-primary" >
645
646
- </form>
647
648
- </div>
649
650
- <?php
651
- }
652
653
- else {
654
- _e("No Multiple Set were found", "yasr");
655
- }
656
657
- }//End function
658
659
660
@@ -773,411 +774,412 @@ function yasr_edit_multi_form() {
773
774
775
/****** Validate new multi set form ******/
776
- function yasr_process_new_multi_set_form()
777
- {
778
779
- if ( isset( $_POST['multi-set-name'])) {
780
-
781
- global $wpdb;
782
-
783
- if ( !current_user_can( 'manage_options' ) ) {
784
- wp_die( 'You are not allowed to be on this page.' );
785
- }
786
787
- // Check nonce field
788
- check_admin_referer( 'add-multi-set', 'add-nonce-new-multi-set' );
789
-
790
- $array_errors = array();
791
- $error = FALSE;
792
793
- //IF thes fields are not empty go ahed
794
- if ($_POST['multi-set-name']!='' && $_POST['multi-set-name-element-1']!='' && $_POST['multi-set-name-element-2']!='' ) {
795
-
796
- $multi_set_name = ucfirst(strtolower($_POST['multi-set-name']));
797
798
- $multi_set_name_element_=array();
799
800
- $multi_set_name_element_[1]=$_POST['multi-set-name-element-1'];
801
- $multi_set_name_element_[2]=$_POST['multi-set-name-element-2'];
802
803
- //If multi set name is shorter than 3 characher come back
804
- if (mb_strlen($multi_set_name) < 3 || mb_strlen($multi_set_name_element_[1]) <3 || mb_strlen($multi_set_name_element_[2]) < 3 ) {
805
- $array_errors[] = "Content field must be longer than 3 chars";
806
- $error=TRUE;
807
- }
808
809
810
- if (mb_strlen($multi_set_name) > 23 || mb_strlen($multi_set_name_element_[1]) > 23 || mb_strlen($multi_set_name_element_[2]) > 23 ) {
811
- $array_errors[] = "Content field must be shorter than 23 chars";
812
- $error=TRUE;
813
- }
814
815
- //Check if a set with that name already exists
816
- $check_name_exists=$wpdb->get_results("SELECT set_name FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id ASC");
817
818
- foreach ($check_name_exists as $set_name) {
819
820
- if ($multi_set_name==$set_name->set_name) {
821
- $array_errors[] = "You already have a set with this name";
822
- $error=TRUE;
823
- }
824
825
- }
826
827
- $element_filled=2;
828
829
- //If filled get the element from 3 to 9
830
- for($i=3; $i<=9; $i++) {
831
832
- if (isset($_POST["multi-set-name-element-$i"]) && $_POST["multi-set-name-element-$i"]!='') {
833
834
- $multi_set_name_element_[$i]=$_POST["multi-set-name-element-$i"];
835
836
- if (mb_strlen($multi_set_name_element_[$i]) < 3) {
837
- $array_errors[] = "Field # $i must be at least 3 characters";
838
- $error=TRUE;
839
- }
840
841
- if (mb_strlen($multi_set_name_element_[$i]) > 23) {
842
- $array_errors[] = "Field # $i must be shorter than 23 characters";
843
- $error=TRUE;
844
- }
845
846
- $element_filled++;
847
- }
848
-
849
- }
850
851
- //If there isnt any error write in the table
852
- if (!$error) {
853
854
- //get the highest id in table
855
- $highest_id=$wpdb->get_results("SELECT set_id FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id DESC LIMIT 1 ");
856
-
857
- if (!$highest_id) {
858
- $name_table_new_id=0;
859
- }
860
-
861
- foreach ($highest_id as $id) {
862
- $name_table_new_id=$id->set_id + 1;
863
- }
864
-
865
- $insert_multi_name_success = $wpdb->replace(
866
- YASR_MULTI_SET_NAME_TABLE,
867
- array(
868
- 'set_id' =>$name_table_new_id,
869
- 'set_name' =>$multi_set_name
870
- ),
871
- array ('%d', '%s')
872
- );
873
-
874
- //If multi set name hase been inserted, now we're going to insert elements
875
- if ($insert_multi_name_success) {
876
-
877
- //get the highest id in table
878
- $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
879
-
880
- if (!$highest_id) {
881
- $field_table_new_id=0;
882
- }
883
-
884
- foreach ($highest_id as $id) {
885
- $field_table_new_id=$id->id + 1;
886
- }
887
-
888
- for ($i=1; $i<=$element_filled; $i++) {
889
- $insert_set_value=$wpdb->replace(
890
- YASR_MULTI_SET_FIELDS_TABLE,
891
- array(
892
- 'id' => $field_table_new_id,
893
- 'parent_set_id' =>$name_table_new_id,
894
- 'field_name' =>$multi_set_name_element_[$i],
895
- 'field_id' =>$i
896
- ),
897
- array ('%d', '%d', '%s', '%d')
898
- );
899
- $field_table_new_id++; //Avoid overwrite
900
- } //End for
901
-
902
- if ($insert_set_value) {
903
- echo "<div class=\"updated\"><p><strong>";
904
- _e("Settings Saved", 'yasr');
905
- echo "</strong></p></div> ";
906
- }
907
-
908
- else {
909
- _e("Something goes wrong trying insert set field name. Please report it", "yasr");
910
- }
911
-
912
- } //End if $insert_multi_name_success
913
-
914
- else {
915
- _e("Something goes wrong trying insert Multi Set name. Please report it", "yasr");
916
- }
917
-
918
- } //End if !$error
919
-
920
- } //End if $_POST['multi-set-name']!=''
921
-
922
- //Else multi set's name and first 2 elements are empty
923
- else {
924
- $array_errors[] = "Multi Set's name and first 2 elements can't be empty";
925
- $error=TRUE;
926
- }
927
-
928
- if ($error) {
929
- return $array_errors;
930
- }
931
932
- } //End if ( isset( $_POST['multi-set-name']) ) {
933
934
- } //End yasr_process_new_multi_set_form() function
935
936
937
938
- function yasr_process_edit_multi_set_form() {
939
940
- $error = FALSE;
941
942
- if ( isset( $_POST['yasr_edit_multi_set_form']) ) {
943
944
- $set_id = $_POST['yasr_edit_multi_set_form'];
945
946
- $number_of_stored_elements = $_POST['yasr-edit-form-number-elements'];
947
948
- global $wpdb;
949
950
- $array_errors = array();
951
-
952
- if ( !current_user_can( 'manage_options' ) ) {
953
- wp_die( 'You are not allowed to be on this page.' );
954
- }
955
-
956
- // Check nonce field
957
- check_admin_referer( 'edit-multi-set', 'add-nonce-edit-multi-set' );
958
-
959
-
960
- //Check if user want to delete entire set
961
-
962
- if (isset($_POST["yasr-remove-multi-set"])) {
963
-
964
- $remove_set = $wpdb->delete (
965
- YASR_MULTI_SET_NAME_TABLE,
966
- array(
967
- 'set_id' => $set_id,
968
- ),
969
- array ('%d')
970
- );
971
-
972
- $remove_set_values = $wpdb->delete (
973
- YASR_MULTI_SET_FIELDS_TABLE,
974
- array(
975
- 'parent_set_id' => $set_id,
976
- ),
977
- array ('%d')
978
- );
979
-
980
- $remove_set_votes = $wpdb->delete (
981
- YASR_MULTI_SET_VALUES_TABLE,
982
- array(
983
- 'set_type' => $set_id,
984
- ),
985
- array ('%d')
986
- );
987
-
988
- if ($remove_set==FALSE) {
989
- $error = TRUE;
990
- $array_errors[] .= __("Something goes wrong trying to delete a Multi Set . Please report it", 'yasr');
991
- }
992
-
993
-
994
- //Comment this out, if try to delete an empty set print error
995
- /*if ($remove_set_values==FALSE) {
996
- $error = TRUE;
997
- $array_errors[] .= __("Something goes wrong trying to delete data fields for a set. Please report it", 'yasr');
998
- }
999
- */
1000
1001
- //Comment this out, will echo error even if the value for that field it's just empty
1002
- /*if ($remove_set_votes==FALSE) {
1003
- $error = TRUE;
1004
- $array_errors[] .= __("Something goes wrong trying to delete data values for a set. Please report it", 'yasr');
1005
- }*/
1006
1007
- }
1008
1009
- for ($i = 0; $i <= 9; $i++) {
1010
1011
- //Than, check if the user want to remove some field
1012
- if (isset($_POST["remove-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) ) {
1013
1014
- $field_to_remove = $_POST["remove-element-$i"];
1015
1016
- $remove_field = $wpdb->delete (
1017
- YASR_MULTI_SET_FIELDS_TABLE,
1018
- array(
1019
- 'parent_set_id' => $set_id,
1020
- 'field_id' =>$field_to_remove
1021
- ),
1022
- array ('%d', '%d')
1023
- );
1024
1025
- $remove_values = $wpdb->delete (
1026
- YASR_MULTI_SET_VALUES_TABLE,
1027
- array(
1028
- 'set_type' => $set_id,
1029
- 'field_id' =>$field_to_remove
1030
- ),
1031
- array ('%d', '%d')
1032
- );
1033
1034
- if ($remove_field == FALSE) {
1035
- $error = TRUE;
1036
- $array_errors[] = __("Something goes wrong trying to delete a Multi Set's element. Please report it", 'yasr');
1037
- }
1038
1039
1040
- //Comment this out, will echo error even if the value for that field it's just empty
1041
- /*if ($remove_values == FALSE) {
1042
- $error = TRUE;
1043
- $array_errors[] = __("Something goes wrong trying to delete data value for an element. Please report it", 'yasr');
1044
- }*/
1045
1046
-
1047
- } //End if isset $_POST['remove-element-$i']
1048
-
1049
-
1050
- //update the stored elements with the new ones
1051
- if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i <= $number_of_stored_elements ) {
1052
1053
- $field_name = $_POST["edit-multi-set-element-$i"];
1054
1055
- $field_id = $_POST["db-id-for-element-$i"];
1056
1057
- //if elements name is shorter than 3 chars
1058
- if (mb_strlen($field_name) <3) {
1059
- $array_errors[] = __("Field # $i must be at least 3 characters", "yasr");
1060
- $error=TRUE;
1061
}
1062
1063
- if(mb_strlen($field_name) > 23) {
1064
- $array_errors[] = __("Field # $i must be shorter than 23 characters", "yasr");
1065
- $error=TRUE;
1066
- }
1067
1068
- else {
1069
1070
- //Check if field name is changed
1071
- $field_name_in_db = $wpdb->get_results("SELECT field_name FROM " . YASR_MULTI_SET_FIELDS_TABLE . " WHERE field_id=$field_id AND parent_set_id=$set_id");
1072
1073
- foreach ($field_name_in_db as $field_in_db) {
1074
- $field_name_in_database = $field_in_db->field_name;
1075
- }
1076
1077
- //if field name in db is different from field name in form update it
1078
- if ($field_name_in_database != $field_name) {
1079
1080
- $insert_field_name=$wpdb->update(
1081
- YASR_MULTI_SET_FIELDS_TABLE,
1082
1083
array(
1084
- 'field_name' =>$field_name,
1085
),
1086
1087
array(
1088
- 'parent_set_id' =>$set_id,
1089
- 'field_id' =>$field_id
1090
),
1091
-
1092
- array ('%s'),
1093
-
1094
array ('%d', '%d')
1095
-
1096
);
1097
1098
- if ($insert_field_name == FALSE) {
1099
- $error = TRUE;
1100
- $array_errors[] = __("Something goes wrong trying to update a Multi Set's element. Please report it", 'yasr');
1101
}
1102
1103
- } //End if ($field_name_in_database != $field_name) {
1104
1105
- }
1106
1107
- } //End if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["remove-element-$i"]) && $i<=$number_of_stored_elements )
1108
-
1109
1110
- //If $i > number of stored elements, user is adding new elements, so we're going to insert the new ones
1111
- if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i > $number_of_stored_elements ) {
1112
1113
- $field_name = $_POST["edit-multi-set-element-$i"];
1114
1115
- //if elements name is shorter than 3 chars return error. I use mb_strlen($field_name) > 1
1116
- //because I don't wont return error if an user add an empty field. An empty field will be
1117
- //just ignored
1118
- if (mb_strlen($field_name) > 1 && mb_strlen($field_name) < 3) {
1119
- $array_errors[] = __("Field # $i must be at least 3 characters", "yasr");
1120
- $error=TRUE;
1121
- }
1122
1123
- if(mb_strlen($field_name) > 23) {
1124
- $array_errors[] = __("Field # $i must be shorter than 23 characters", "yasr");
1125
- $error=TRUE;
1126
- }
1127
1128
- //if field is not empty
1129
- elseif ($field_name != '') {
1130
1131
- $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
1132
1133
- $highest_field_id = $wpdb->get_results("SELECT field_id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY field_id DESC LIMIT 1 ");
1134
1135
- foreach ($highest_id as $id) {
1136
- $field_table_new_id=$id->id + 1;
1137
- }
1138
1139
- foreach ($highest_field_id as $id) {
1140
- $new_field_id = $id->field_id+1;
1141
- }
1142
1143
- $insert_set_value=$wpdb->replace(
1144
- YASR_MULTI_SET_FIELDS_TABLE,
1145
- array(
1146
- 'id' => $field_table_new_id,
1147
- 'parent_set_id' =>$set_id,
1148
- 'field_name' =>$field_name,
1149
- 'field_id' =>$new_field_id
1150
- ),
1151
- array ('%d', '%d', '%s', '%d')
1152
- );
1153
- $field_table_new_id++; //Avoid overwrite
1154
1155
- if ($insert_set_value == FALSE) {
1156
- $error = TRUE;
1157
- $array_errors[] = __("Something goes wrong trying to insert set field name in edit form. Please report it", 'yasr');
1158
- }
1159
1160
- } //end else
1161
- }
1162
1163
1164
- } //End for
1165
1166
1167
- if ($error) {
1168
- return $array_errors;
1169
- }
1170
- else {
1171
- echo "<div class=\"updated\"><p><strong>";
1172
- _e("Settings Saved", 'yasr');
1173
- echo "</strong></p></div> ";
1174
- }
1175
1176
1177
- } //End if isset( $_POST['yasr_edit_multi_set_form']
1178
1179
-
1180
- } //End yasr_process_edit_multi_set_form() function
1181
1182
1183
add_action( 'admin_init', 'yasr_style_options_init' ); //This is for auto insert options
@@ -1315,59 +1317,7 @@ function yasr_go_pro () {
1315
1316
}
1317
1318
- /****** Donation box dx ******/
1319
-
1320
- function yasr_donate_dx () {
1321
-
1322
- ?>
1323
-
1324
- <div class="yasr-donatedivdx" style="display:none">
1325
- <h3><?php _e('Donations', 'yasr'); ?></h3>
1326
-
1327
- <?php _e('If you have found this plugin useful, please consider making a donation to help support future development. Your support will be much appreciated. ', 'yasr'); ?>
1328
- <br />
1329
- <?php _e('Thank you!', 'yasr'); ?>
1330
- <br />
1331
- <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=AXE284FYMNWDC">
1332
- <?php echo("<img src=" . YASR_IMG_DIR . "/paypal.png>"); ?>
1333
- </a>
1334
-
1335
- <hr>
1336
-
1337
- <h3><a href="https://yetanotherstarsrating.com"><?php _e('Follow YASR official site!', 'yasr') ?></a></h3>
1338
-
1339
- </div>
1340
-
1341
- <?php
1342
-
1343
- }
1344
-
1345
-
1346
- function yasr_donate_bottom () {
1347
-
1348
- ?>
1349
-
1350
- <div class="yasr-donatedivbottom" style="display:none">
1351
- <h3><?php _e('Donations', 'yasr'); ?></h3>
1352
-
1353
- <?php _e('If you have found this plugin useful, please consider making a donation to help support future development. Your support will be much appreciated. ', 'yasr'); ?>
1354
- <br />
1355
- <?php _e('Thank you!', 'yasr'); ?>
1356
- <br />
1357
-
1358
- <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=AXE284FYMNWDC">
1359
- <?php echo("<img src=" . YASR_IMG_DIR . "/paypal.png>"); ?>
1360
- </a>
1361
-
1362
- <hr>
1363
-
1364
- <h3><a href="https://yetanotherstarsrating.com"><?php _e('Follow YASR official site!', 'yasr') ?></a></h3>
1365
-
1366
- </div>
1367
-
1368
- <?php
1369
-
1370
- }
1371
1372
function yasr_include_fb_sdk () {
1373
@@ -1394,6 +1344,8 @@ function yasr_include_fb_sdk () {
1394
1395
}
1396
1397
function yasr_fb_box ($position=FALSE) {
1398
1399
if ($position && $position == "bottom") {
@@ -1425,6 +1377,105 @@ function yasr_fb_box ($position=FALSE) {
1425
1426
}
1427
1428
1429
1430
/*************************BEGIN IMPORT FUNCTIONS*******************************/
20
21
if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // Exit if accessed directly
22
23
+ /************ Add yasr general options ***********/
24
25
add_action( 'admin_init', 'yasr_general_options_init' ); //This is for general options
26
411
}
412
413
414
+ /************ End Yasr General Settings ************/
415
416
417
418
+ /**************** Add yasr multiset options and settings ************/
419
420
+ add_action( 'admin_init', 'yasr_multiset_options_init' ); //This is for general options
421
422
+ function yasr_multiset_options_init() {
423
+ register_setting(
424
+ 'yasr_multiset_options_group', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
425
+ 'yasr_multiset_options' //The name of an option to sanitize and save.
426
+ );
427
428
+ $option_multiset = get_option( 'yasr_multiset_options' );
429
430
+ add_settings_section( 'yasr_multiset_options_section_id', '', 'yasr_multiset_section_callback', 'yasr_multiset_tab' );
431
+ add_settings_field( 'yasr_color_scheme', __('Which color scheme do you want to use?', 'yasr') , 'yasr_color_scheme_callback', 'yasr_multiset_tab', 'yasr_multiset_options_section_id', $option_multiset);
432
+
433
+ }
434
435
+ function yasr_multiset_section_callback () {
436
437
+ //Silence
438
439
+ }
440
441
+ function yasr_color_scheme_callback($option_multiset) {
442
443
+ if (!$option_multiset['scheme_color']) {
444
445
+ $option_multiset['scheme_color'] = 'light';
446
447
+ }
448
449
+ ?>
450
451
+ <input type='radio' name='yasr_multiset_options[scheme_color]' value='light' class='yasr-general-options-scheme-color' <?php if ($option_multiset['scheme_color']==='light') echo " checked=\"checked\" "; ?> />
452
+ <?php _e('Light', 'yasr')?>
453
+
454
+ &nbsp;&nbsp;&nbsp;
455
456
+ <input type='radio' name='yasr_multiset_options[scheme_color]' value='dark' class='yasr-general-options-scheme-color' <?php if ($option_multiset['scheme_color']==='dark') echo " checked=\"checked\" "; ?> />
457
+ <?php _e('Dark', 'yasr')?>
458
+ <br />
459
460
+ <br />
461
462
+ <a href="#" id="yasr-color-scheme-preview-link"><?php _e("Preview", "yasr") ?></a>
463
464
+ <div id="yasr-color-scheme-preview" style="display:none">
465
+ <?php
466
467
+ _e("Light theme", "yasr");
468
+ echo "<br /><br /><img src=" . YASR_IMG_DIR . "yasr-multi-set.png>";
469
470
+ echo "<br /> <br />";
471
472
+ _e("Dark theme", "yasr");
473
+ echo "<br /><br /><img src=" . YASR_IMG_DIR . "dark-multi-set.png>";
474
+ ?>
475
+ </div>
476
477
+ <p>
478
479
+ <?php
480
+ }
481
482
483
/****** Create a form for settings page to create new multi set ******/
484
+ function yasr_display_multi_set_form() {
485
?>
486
487
<h4 class="yasr-multi-set-form-headers"><?php _e("Add New Multiple Set", "yasr"); ?></h4>
511
<input type="submit" value="<?php _e("Create New Set", 'yasr') ?>" class="button-primary"/>
512
</form>
513
514
+ <?php
515
+ } //End function
516
517
518
519
+ function yasr_edit_multi_form() {
520
521
+ $multi_set=yasr_get_multi_set();
522
523
+ global $wpdb;
524
525
+ $n_multi_set = $wpdb->num_rows; //wpdb->num_rows always store the last of the last query
526
527
+ if ($n_multi_set > 1) {
528
+ ?>
529
530
<div class="yasr-manage-multiset">
531
545
</div>
546
547
<?php
548
549
+ } //End if n_multi_set >1
550
551
+ elseif ($n_multi_set == 1) {
552
553
+ $set_name=$wpdb->get_results("SELECT field_name AS name, field_id AS id, parent_set_id AS set_id
554
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
555
+ ORDER BY field_id ASC");
556
557
+ foreach ($multi_set as $find_set_id) {
558
+ $set_type = $find_set_id->set_id;
559
+ }
560
561
+ ?>
562
+
563
+ <div class="yasr-manage-multiset-single">
564
565
+ <h4 class="yasr-multi-set-form-headers"><?php _e("Manage Multiple Set", "yasr"); ?></h4>
566
567
+ <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi') ?>" id="form_edit_multi_set" method="post">
568
569
+ <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />
570
571
+ <table id="yasr-table-form-edit-multi-set">
572
+ <tr>
573
574
+ <td id="yasr-table-form-edit-multi-set-header">
575
+ <?php _e('Field name', 'yasr') ?>
576
+ </td>
577
578
+ <td id="yasr-table-form-edit-multi-set-remove">
579
+ <?php _e('Remove', 'yasr') ?>
580
+ </td>
581
582
+ </tr>
583
584
+ <?php
585
586
+ $i=1;
587
588
+ foreach ($set_name as $name) {
589
590
+ echo "
591
+ <tr>
592
+
593
+ <td width=\"80%\">
594
+ Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$i\">
595
+ <input type=\"hidden\" value=\"$name->id\" name=\"db-id-for-element-$i\">
596
+ </td>
597
598
+ <td width=\"20%\" style=\"text-align:center\">
599
+ <input type=\"checkbox\" value=\"$name->id\" name=\"remove-element-$i\">
600
+ </td>
601
602
+ </tr>
603
+ ";
604
+
605
+ $i++;
606
607
+ }
608
609
610
+ $i = $i-1; //This is the number of the fields
611
612
+ echo "
613
614
+ <input type=\"hidden\" name=\"yasr-edit-form-number-elements\" id=\"yasr-edit-form-number-elements\" value=\"$i\">
615
616
+ </table>
617
618
+ <table width=\"100%\" class=\"yasr-edit-form-remove-entire-set\">
619
+ <tr>
620
621
+ <td width=\"80%\">" . __("Remove whole set?", "yasr") . "</td>
622
623
+ <td width=\"20%\" style=\"text-align:center\">
624
+ <input type=\"checkbox\" name=\"yasr-remove-multi-set\" value=\"$set_type\">
625
+ </td>
626
627
+ </tr>
628
629
+ </table>
630
631
+ ";
632
633
+ echo "<p>";
634
+ _e("If you remove something you will remove all the votes for that set or field. This operation CAN'T BE undone." , "yasr");
635
+ echo "</p>";
636
637
+ wp_nonce_field( 'edit-multi-set', 'add-nonce-edit-multi-set' )
638
639
+ ?>
640
641
+ <div id="yasr-element-limit" style="display:none; color:red"><?php _e("You can use up to 9 elements" , "yasr") ?></div>
642
643
+ <input type="button" class="button-delete" id="yasr-add-field-edit-multiset" value="<?php _e('Add element', 'yasr'); ?>">
644
645
+ <input type="submit" value="<?php _e('Save changes', 'yasr') ?>" class="button-primary" >
646
647
+ </form>
648
649
+ </div>
650
651
+ <?php
652
+ }
653
654
+ else {
655
+ _e("No Multiple Set were found", "yasr");
656
+ }
657
+
658
+ }//End function
659
660
661
774
775
776
/****** Validate new multi set form ******/
777
+ function yasr_process_new_multi_set_form() {
778
779
+ if ( isset( $_POST['multi-set-name'])) {
780
781
+ global $wpdb;
782
+
783
+ if ( !current_user_can( 'manage_options' ) ) {
784
+ wp_die( 'You are not allowed to be on this page.' );
785
+ }
786
787
+ // Check nonce field
788
+ check_admin_referer( 'add-multi-set', 'add-nonce-new-multi-set' );
789
790
+ $array_errors = array();
791
+ $error = FALSE;
792
793
+ //IF thes fields are not empty go ahed
794
+ if ($_POST['multi-set-name']!='' && $_POST['multi-set-name-element-1']!='' && $_POST['multi-set-name-element-2']!='' ) {
795
+
796
+ $multi_set_name = ucfirst(strtolower($_POST['multi-set-name']));
797
798
+ $multi_set_name_element_=array();
799
800
+ $multi_set_name_element_[1]=$_POST['multi-set-name-element-1'];
801
+ $multi_set_name_element_[2]=$_POST['multi-set-name-element-2'];
802
803
+ //If multi set name is shorter than 3 characher come back
804
+ if (mb_strlen($multi_set_name) < 3 || mb_strlen($multi_set_name_element_[1]) <3 || mb_strlen($multi_set_name_element_[2]) < 3 ) {
805
+ $array_errors[] = "Content field must be longer than 3 chars";
806
+ $error=TRUE;
807
+ }
808
809
810
+ if (mb_strlen($multi_set_name) > 23 || mb_strlen($multi_set_name_element_[1]) > 23 || mb_strlen($multi_set_name_element_[2]) > 23 ) {
811
+ $array_errors[] = "Content field must be shorter than 23 chars";
812
+ $error=TRUE;
813
+ }
814
815
+ //Check if a set with that name already exists
816
+ $check_name_exists=$wpdb->get_results("SELECT set_name FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id ASC");
817
818
+ foreach ($check_name_exists as $set_name) {
819
820
+ if ($multi_set_name==$set_name->set_name) {
821
+ $array_errors[] = "You already have a set with this name";
822
+ $error=TRUE;
823
+ }
824
825
+ }
826
827
+ $element_filled=2;
828
829
+ //If filled get the element from 3 to 9
830
+ for($i=3; $i<=9; $i++) {
831
832
+ if (isset($_POST["multi-set-name-element-$i"]) && $_POST["multi-set-name-element-$i"]!='') {
833
834
+ $multi_set_name_element_[$i]=$_POST["multi-set-name-element-$i"];
835
836
+ if (mb_strlen($multi_set_name_element_[$i]) < 3) {
837
+ $array_errors[] = "Field # $i must be at least 3 characters";
838
+ $error=TRUE;
839
+ }
840
841
+ if (mb_strlen($multi_set_name_element_[$i]) > 23) {
842
+ $array_errors[] = "Field # $i must be shorter than 23 characters";
843
+ $error=TRUE;
844
+ }
845
846
+ $element_filled++;
847
+ }
848
+
849
+ }
850
+
851
+ //If there isnt any error write in the table
852
+ if (!$error) {
853
+
854
+ //get the highest id in table
855
+ $highest_id=$wpdb->get_results("SELECT set_id FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id DESC LIMIT 1 ");
856
+
857
+ if (!$highest_id) {
858
+ $name_table_new_id=0;
859
+ }
860
+
861
+ foreach ($highest_id as $id) {
862
+ $name_table_new_id=$id->set_id + 1;
863
+ }
864
+
865
+ $insert_multi_name_success = $wpdb->replace(
866
+ YASR_MULTI_SET_NAME_TABLE,
867
+ array(
868
+ 'set_id' =>$name_table_new_id,
869
+ 'set_name' =>$multi_set_name
870
+ ),
871
+ array ('%d', '%s')
872
+ );
873
+
874
+ //If multi set name hase been inserted, now we're going to insert elements
875
+ if ($insert_multi_name_success) {
876
+
877
+ //get the highest id in table
878
+ $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
879
+
880
+ if (!$highest_id) {
881
+ $field_table_new_id=0;
882
+ }
883
+
884
+ foreach ($highest_id as $id) {
885
+ $field_table_new_id=$id->id + 1;
886
+ }
887
+
888
+ for ($i=1; $i<=$element_filled; $i++) {
889
+ $insert_set_value=$wpdb->replace(
890
+ YASR_MULTI_SET_FIELDS_TABLE,
891
+ array(
892
+ 'id' => $field_table_new_id,
893
+ 'parent_set_id' =>$name_table_new_id,
894
+ 'field_name' =>$multi_set_name_element_[$i],
895
+ 'field_id' =>$i
896
+ ),
897
+ array ('%d', '%d', '%s', '%d')
898
+ );
899
+ $field_table_new_id++; //Avoid overwrite
900
+ } //End for
901
902
+ if ($insert_set_value) {
903
+ echo "<div class=\"updated\"><p><strong>";
904
+ _e("Settings Saved", 'yasr');
905
+ echo "</strong></p></div> ";
906
+ }
907
908
+ else {
909
+ _e("Something goes wrong trying insert set field name. Please report it", "yasr");
910
+ }
911
912
+ } //End if $insert_multi_name_success
913
914
+ else {
915
+ _e("Something goes wrong trying insert Multi Set name. Please report it", "yasr");
916
+ }
917
918
+ } //End if !$error
919
920
+ } //End if $_POST['multi-set-name']!=''
921
+
922
+ //Else multi set's name and first 2 elements are empty
923
+ else {
924
+ $array_errors[] = "Multi Set's name and first 2 elements can't be empty";
925
+ $error=TRUE;
926
+ }
927
928
+ if ($error) {
929
+ return $array_errors;
930
+ }
931
932
+ } //End if ( isset( $_POST['multi-set-name']) ) {
933
934
+ } //End yasr_process_new_multi_set_form() function
935
936
937
938
+ function yasr_process_edit_multi_set_form() {
939
940
+ $error = FALSE;
941
942
+ if ( isset( $_POST['yasr_edit_multi_set_form']) ) {
943
944
+ $set_id = $_POST['yasr_edit_multi_set_form'];
945
946
+ $number_of_stored_elements = $_POST['yasr-edit-form-number-elements'];
947
948
+ global $wpdb;
949
950
+ $array_errors = array();
951
+
952
+ if ( !current_user_can( 'manage_options' ) ) {
953
+ wp_die( 'You are not allowed to be on this page.' );
954
+ }
955
956
+ // Check nonce field
957
+ check_admin_referer( 'edit-multi-set', 'add-nonce-edit-multi-set' );
958
959
960
+ //Check if user want to delete entire set
961
962
+ if (isset($_POST["yasr-remove-multi-set"])) {
963
+
964
+ $remove_set = $wpdb->delete (
965
+ YASR_MULTI_SET_NAME_TABLE,
966
+ array(
967
+ 'set_id' => $set_id,
968
+ ),
969
+ array ('%d')
970
+ );
971
972
+ $remove_set_values = $wpdb->delete (
973
+ YASR_MULTI_SET_FIELDS_TABLE,
974
+ array(
975
+ 'parent_set_id' => $set_id,
976
+ ),
977
+ array ('%d')
978
+ );
979
980
+ $remove_set_votes = $wpdb->delete (
981
+ YASR_MULTI_SET_VALUES_TABLE,
982
+ array(
983
+ 'set_type' => $set_id,
984
+ ),
985
+ array ('%d')
986
+ );
987
988
+ if ($remove_set==FALSE) {
989
+ $error = TRUE;
990
+ $array_errors[] .= __("Something goes wrong trying to delete a Multi Set . Please report it", 'yasr');
991
}
992
993
994
+ //Comment this out, if try to delete an empty set print error
995
+ /*if ($remove_set_values==FALSE) {
996
+ $error = TRUE;
997
+ $array_errors[] .= __("Something goes wrong trying to delete data fields for a set. Please report it", 'yasr');
998
+ }
999
+ */
1000
1001
+ //Comment this out, will echo error even if the value for that field it's just empty
1002
+ /*if ($remove_set_votes==FALSE) {
1003
+ $error = TRUE;
1004
+ $array_errors[] .= __("Something goes wrong trying to delete data values for a set. Please report it", 'yasr');
1005
+ }*/
1006
1007
+ }
1008
1009
+ for ($i = 0; $i <= 9; $i++) {
1010
1011
+ //Than, check if the user want to remove some field
1012
+ if (isset($_POST["remove-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) ) {
1013
1014
+ $field_to_remove = $_POST["remove-element-$i"];
1015
+
1016
+ $remove_field = $wpdb->delete (
1017
+ YASR_MULTI_SET_FIELDS_TABLE,
1018
array(
1019
+ 'parent_set_id' => $set_id,
1020
+ 'field_id' =>$field_to_remove
1021
),
1022
+ array ('%d', '%d')
1023
+ );
1024
1025
+ $remove_values = $wpdb->delete (
1026
+ YASR_MULTI_SET_VALUES_TABLE,
1027
array(
1028
+ 'set_type' => $set_id,
1029
+ 'field_id' =>$field_to_remove
1030
),
1031
array ('%d', '%d')
1032
);
1033
1034
+ if ($remove_field == FALSE) {
1035
+ $error = TRUE;
1036
+ $array_errors[] = __("Something goes wrong trying to delete a Multi Set's element. Please report it", 'yasr');
1037
+ }
1038
+
1039
+
1040
+ //Comment this out, will echo error even if the value for that field it's just empty
1041
+ /*if ($remove_values == FALSE) {
1042
+ $error = TRUE;
1043
+ $array_errors[] = __("Something goes wrong trying to delete data value for an element. Please report it", 'yasr');
1044
+ }*/
1045
+
1046
+
1047
+ } //End if isset $_POST['remove-element-$i']
1048
+
1049
+
1050
+ //update the stored elements with the new ones
1051
+ if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i <= $number_of_stored_elements ) {
1052
+
1053
+ $field_name = $_POST["edit-multi-set-element-$i"];
1054
+
1055
+ $field_id = $_POST["db-id-for-element-$i"];
1056
+
1057
+ //if elements name is shorter than 3 chars
1058
+ if (mb_strlen($field_name) <3) {
1059
+ $array_errors[] = __("Field # $i must be at least 3 characters", "yasr");
1060
+ $error=TRUE;
1061
+ }
1062
+
1063
+ if(mb_strlen($field_name) > 23) {
1064
+ $array_errors[] = __("Field # $i must be shorter than 23 characters", "yasr");
1065
+ $error=TRUE;
1066
+ }
1067
+
1068
+ else {
1069
+
1070
+ //Check if field name is changed
1071
+ $field_name_in_db = $wpdb->get_results("SELECT field_name FROM " . YASR_MULTI_SET_FIELDS_TABLE . " WHERE field_id=$field_id AND parent_set_id=$set_id");
1072
+
1073
+ foreach ($field_name_in_db as $field_in_db) {
1074
+ $field_name_in_database = $field_in_db->field_name;
1075
}
1076
1077
+ //if field name in db is different from field name in form update it
1078
+ if ($field_name_in_database != $field_name) {
1079
1080
+ $insert_field_name=$wpdb->update(
1081
+ YASR_MULTI_SET_FIELDS_TABLE,
1082
1083
+ array(
1084
+ 'field_name' =>$field_name,
1085
+ ),
1086
1087
+ array(
1088
+ 'parent_set_id' =>$set_id,
1089
+ 'field_id' =>$field_id
1090
+ ),
1091
1092
+ array ('%s'),
1093
1094
+ array ('%d', '%d')
1095
+
1096
+ );
1097
1098
+ if ($insert_field_name == FALSE) {
1099
+ $error = TRUE;
1100
+ $array_errors[] = __("Something goes wrong trying to update a Multi Set's element. Please report it", 'yasr');
1101
+ }
1102
1103
+ } //End if ($field_name_in_database != $field_name) {
1104
1105
+ }
1106
1107
+ } //End if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["remove-element-$i"]) && $i<=$number_of_stored_elements )
1108
+
1109
1110
+ //If $i > number of stored elements, user is adding new elements, so we're going to insert the new ones
1111
+ if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i > $number_of_stored_elements ) {
1112
1113
+ $field_name = $_POST["edit-multi-set-element-$i"];
1114
1115
+ //if elements name is shorter than 3 chars return error. I use mb_strlen($field_name) > 1
1116
+ //because I don't wont return error if an user add an empty field. An empty field will be
1117
+ //just ignored
1118
+ if (mb_strlen($field_name) > 1 && mb_strlen($field_name) < 3) {
1119
+ $array_errors[] = __("Field # $i must be at least 3 characters", "yasr");
1120
+ $error=TRUE;
1121
+ }
1122
1123
+ if(mb_strlen($field_name) > 23) {
1124
+ $array_errors[] = __("Field # $i must be shorter than 23 characters", "yasr");
1125
+ $error=TRUE;
1126
+ }
1127
1128
+ //if field is not empty
1129
+ elseif ($field_name != '') {
1130
1131
+ $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
1132
1133
+ $highest_field_id = $wpdb->get_results("SELECT field_id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY field_id DESC LIMIT 1 ");
1134
1135
+ foreach ($highest_id as $id) {
1136
+ $field_table_new_id=$id->id + 1;
1137
+ }
1138
1139
+ foreach ($highest_field_id as $id) {
1140
+ $new_field_id = $id->field_id+1;
1141
+ }
1142
1143
+ $insert_set_value=$wpdb->replace(
1144
+ YASR_MULTI_SET_FIELDS_TABLE,
1145
+ array(
1146
+ 'id' => $field_table_new_id,
1147
+ 'parent_set_id' =>$set_id,
1148
+ 'field_name' =>$field_name,
1149
+ 'field_id' =>$new_field_id
1150
+ ),
1151
+ array ('%d', '%d', '%s', '%d')
1152
+ );
1153
+ $field_table_new_id++; //Avoid overwrite
1154
+
1155
+ if ($insert_set_value == FALSE) {
1156
+ $error = TRUE;
1157
+ $array_errors[] = __("Something goes wrong trying to insert set field name in edit form. Please report it", 'yasr');
1158
+ }
1159
+
1160
+ } //end else
1161
+ }
1162
+
1163
+
1164
+ } //End for
1165
+
1166
+
1167
+ if ($error) {
1168
+ return $array_errors;
1169
+ }
1170
+ else {
1171
+ echo "<div class=\"updated\"><p><strong>";
1172
+ _e("Settings Saved", 'yasr');
1173
+ echo "</strong></p></div> ";
1174
+ }
1175
+
1176
+
1177
+ } //End if isset( $_POST['yasr_edit_multi_set_form']
1178
+
1179
+
1180
+ } //End yasr_process_edit_multi_set_form() function
1181
1182
1183
1184
1185
add_action( 'admin_init', 'yasr_style_options_init' ); //This is for auto insert options
1317
1318
}
1319
1320
+ /*** Facebook sdk, since version 0.8.8 ***/
1321
1322
function yasr_include_fb_sdk () {
1323
1344
1345
}
1346
1347
+ /****** Facebook box, since version 0.8.8 ******/
1348
+
1349
function yasr_fb_box ($position=FALSE) {
1350
1351
if ($position && $position == "bottom") {
1377
1378
}
1379
1380
+ /** Add a box on the right for asking to rate 5 stars on Wordpress.org
1381
+ * It must be appear after 10 logged rating, after 100 and after 1000
1382
+ * Since version 0.9.0
1383
+ */
1384
+
1385
+ function yasr_ask_rating ($position=FALSE) {
1386
+
1387
+ $transient = get_site_transient ('yasr_hide_ask_rating');
1388
+
1389
+ if (!$transient) {
1390
+
1391
+ if ($position && $position == "bottom") {
1392
+
1393
+ $yasr_metabox_class = "yasr-donatedivbottom";
1394
+
1395
+ }
1396
+
1397
+ else {
1398
+
1399
+ $yasr_metabox_class = "yasr-donatedivdx";
1400
+
1401
+ }
1402
+
1403
+ $n_stored_ratings = yasr_count_logged_vote ();
1404
+
1405
+ $div = "<div class=\"$yasr_metabox_class\" id=\"yasr-ask-five-stars\" style=\" display:none; border-left: 3px solid #7AD03A; font-size: 14px;\">";
1406
+
1407
+ if($n_stored_ratings > 20) {
1408
+
1409
+ $text = sprintf( __('Hey, seems like you reached %s votes on your site throught YASR! That\'s cool!', 'yasr'),'<strong>'.$n_stored_ratings.'</strong>');
1410
+ $text .= "<br />";
1411
+ $text .= __('Can I ask a favor?', 'yasr');
1412
+ $text .= "<br />";
1413
+ $text .= __('Can you please rate YASR 5 stars on', 'yasr');
1414
+ $text .= ' <a href="https://wordpress.org/support/view/plugin-reviews/yet-another-stars-rating?filter=5">wordpress.org?</a>';
1415
+ $text .= __(' It will require just 1 min but it\'s a HUGE help for me. Thank you.' , 'yasr');
1416
+ $text .= "<br /><br />";
1417
+ $text .= "<em>> Dario Curvino</em>";
1418
+
1419
+ $text .= "<ul>
1420
+
1421
+ <li><a href=\"https://wordpress.org/support/view/plugin-reviews/yet-another-stars-rating?filter=5\">" . __("Ok, I'm glad to help!" , "yasr") ."</a></li>
1422
+ <li><a href=\"#\" id=\"yasr-ask-five-star-later\">" . __("Remind me later!" , "yasr") ."</a></li>
1423
+ <li><a href=\"#\" id=\"yasr-ask-five-close\">" . __("Don't need to ask, I already did it!" , "yasr") ."</a></li>
1424
+
1425
+ </ul>";
1426
+
1427
+
1428
+ $div_and_text = $div . $text . '</div>';
1429
+
1430
+ echo $div_and_text;
1431
+
1432
+ }
1433
+
1434
+ } //End if (!transient)
1435
+
1436
+
1437
+ }
1438
+
1439
+
1440
+
1441
+ /** Change default admin footer on yasr settings pages
1442
+ * $text is the default wordpress text
1443
+ * Since 0.8.9
1444
+ */
1445
+
1446
+ add_filter( 'admin_footer_text', 'yasr_custom_admin_footer' );
1447
+
1448
+ function yasr_custom_admin_footer ($text) {
1449
+
1450
+ if (isset($_GET['page'])) {
1451
+ $yasr_page = $_GET[ 'page' ];
1452
+
1453
+ if ($yasr_page == 'yasr_settings_page') {
1454
+
1455
+ $custom_text = ' | <i>';
1456
+ $custom_text .= sprintf( __( 'Thank you for using <a href="%s" target="_blank">Yet Another Stars Rating</a>. Please <a href="%s" target="_blank">rate it</a> 5 stars on <a href="%s" target="_blank">WordPress.org</a>', 'yasr' ), 'https://yetanotherstarsrating.com', 'https://wordpress.org/support/view/plugin-reviews/yet-another-stars-rating?filter=5', 'https://wordpress.org/support/view/plugin-reviews/yet-another-stars-rating?filter=5' );
1457
+ $custom_text .= '</i>';
1458
+
1459
+ return $text . $custom_text;
1460
+
1461
+ }
1462
+
1463
+ else {
1464
+
1465
+ return $text;
1466
+
1467
+ }
1468
+
1469
+ }
1470
+
1471
+ else {
1472
+
1473
+ return $text;
1474
+
1475
+ }
1476
+
1477
+ }
1478
+
1479
1480
1481
/*************************BEGIN IMPORT FUNCTIONS*******************************/
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: 5 star, admin, administrator, AJAX, five-star, javascript, jquery, post r
4
Requires at least: 3.5
5
Contributors: Dudo
6
Tested up to: 4.2.2
7
- Stable tag: 0.8.9
8
License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
10
Yet Another Stars Rating is a simple plugin which allows you and / or your visitor to rate a post or element. Ideal for review's website
@@ -44,7 +44,7 @@ If with gd-star-rating you're using a different number of stars from the default
44
* Polish (thanks to Hoek i Tutu Team)
45
* Dutch (thanks to [Marcel Pol](http://zenoweb.nl ) )
46
* French (Thanks to Sébastien Gracia)
47
- * Norwegian (Thanks to [Line](http://www.spilleautomatercasinobonuser.com) )
48
* Persian (Thanks to Babak Mehri )
49
* Brazilian Portuguese (Thanks to [Iuri](http://assistirfilmesonline.info) )
50
* Russian (Thanks to Ron)
@@ -123,6 +123,10 @@ Of course not: you can easily add it on the visual editor just by clicking on th
123
124
== Changelog ==
125
126
= 0.8.9 =
127
* FIXED: Minor bugfixes for multisets and visitor multisets
128
4
Requires at least: 3.5
5
Contributors: Dudo
6
Tested up to: 4.2.2
7
+ Stable tag: 0.9.0
8
License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
10
Yet Another Stars Rating is a simple plugin which allows you and / or your visitor to rate a post or element. Ideal for review's website
44
* Polish (thanks to Hoek i Tutu Team)
45
* Dutch (thanks to [Marcel Pol](http://zenoweb.nl ) )
46
* French (Thanks to Sébastien Gracia)
47
+ * Norwegian (Thanks to [Line Holm Anderssen, Anderssen Language Services](http://www.alanguageservices.com/) )
48
* Persian (Thanks to Babak Mehri )
49
* Brazilian Portuguese (Thanks to [Iuri](http://assistirfilmesonline.info) )
50
* Russian (Thanks to Ron)
123
124
== Changelog ==
125
126
+ = 0.9.0 =
127
+ * FIXED: Fixed bug in multisets (here https://wordpress.org/support/topic/half-stars-not-saving more info)
128
+ * TWEAKED: Minor changes
129
+
130
= 0.8.9 =
131
* FIXED: Minor bugfixes for multisets and visitor multisets
132
yasr-settings-page.php CHANGED
@@ -26,6 +26,8 @@ if ( !current_user_can( 'manage_options' ) ) {
26
27
$n_multi_set = NULL; //Evoid undefined variable when printed outside multiset tab
28
29
yasr_include_fb_sdk ();
30
31
?>
@@ -102,9 +104,8 @@ yasr_include_fb_sdk ();
102
103
<?php
104
105
- yasr_donate_dx ();
106
-
107
- yasr_fb_box ();
108
109
?>
110
@@ -269,11 +270,10 @@ yasr_include_fb_sdk ();
269
</div>
270
271
272
- <?php
273
-
274
- yasr_donate_dx ();
275
276
- yasr_fb_box ();
277
278
?>
279
@@ -300,11 +300,10 @@ yasr_include_fb_sdk ();
300
</div>
301
302
303
- <?php
304
-
305
- yasr_donate_dx ();
306
307
- yasr_fb_box ();
308
309
?>
310
@@ -319,11 +318,12 @@ yasr_include_fb_sdk ();
319
320
if ($active_tab == 'go_pro') {
321
322
- yasr_go_pro();
323
324
- yasr_donate_dx ();
325
326
- yasr_fb_box ();
327
328
}
329
@@ -331,10 +331,10 @@ yasr_include_fb_sdk ();
331
332
<?php
333
334
- yasr_donate_bottom ();
335
-
336
yasr_fb_box("bottom");
337
338
?>
339
340
<!--End div wrap-->
26
27
$n_multi_set = NULL; //Evoid undefined variable when printed outside multiset tab
28
29
+ $ajax_nonce_hide_ask_rating = wp_create_nonce( "yasr_nonce_hide_ask_rating" );
30
+
31
yasr_include_fb_sdk ();
32
33
?>
104
105
<?php
106
107
+ yasr_fb_box ();
108
+ yasr_ask_rating ();
109
110
?>
111
270
</div>
271
272
273
+ <?php
274
275
+ yasr_fb_box ();
276
+ yasr_ask_rating ();
277
278
?>
279
300
</div>
301
302
303
+ <?php
304
305
+ yasr_fb_box ();
306
+ yasr_ask_rating ();
307
308
?>
309
318
319
if ($active_tab == 'go_pro') {
320
321
+ yasr_go_pro();
322
+
323
+ yasr_fb_box ();
324
325
+ yasr_ask_rating ();
326
327
328
}
329
331
332
<?php
333
334
yasr_fb_box("bottom");
335
336
+ yasr_ask_rating("bottom");
337
+
338
?>
339
340
<!--End div wrap-->
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.8.9
7
* Author: Dario Curvino
8
* Author URI: https://yetanotherstarsrating.com/
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.8.9');
32
33
//Plugin relative path
34
define( "YASR_RELATIVE_PATH", dirname(__FILE__) );
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.9.0
7
* Author: Dario Curvino
8
* Author URI: https://yetanotherstarsrating.com/
9
* License: GPL2
28
*/
29
30
31
+ define('YASR_VERSION_NUM', '0.9.0');
32
33
//Plugin relative path
34
define( "YASR_RELATIVE_PATH", dirname(__FILE__) );