Yasr – Yet Another Stars Rating - Version 0.2.7

Version Description

  • Many bug fixes on the settings page
  • Minor change and code cleanup
Download this release

Release Info

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

Code changes from version 0.2.5 to 0.2.7

lib/yasr-ajax-functions.php CHANGED
@@ -411,116 +411,6 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
411
412
413
414
-
415
- /****** Get multiple set, used in settings page ******/
416
-
417
- add_action( 'wp_ajax_yasr_get_multi_set', 'yasr_get_multi_set_callback' );
418
-
419
- function yasr_get_multi_set_callback() {
420
- if (isset($_POST['set_id'])) {
421
- $set_type = $_POST['set_id'];
422
- }
423
- else {
424
- exit ();
425
- }
426
-
427
- global $wpdb;
428
-
429
- $set_name=$wpdb->get_results("SELECT field_name AS name, field_id AS id
430
- FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
431
- WHERE parent_set_id=$set_type
432
- ORDER BY field_id ASC");
433
-
434
- $i=1;
435
-
436
- ?>
437
-
438
- <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page') ?>" id="form_edit_multi_set" method="post">
439
- <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />
440
-
441
-
442
- <table id="yasr-table-form-edit-multi-set">
443
- <tr>
444
-
445
- <td id="yasr-table-form-edit-multi-set-header">
446
- <?php _e('Field name', 'yasr') ?>
447
- </td>
448
-
449
- <td id="yasr-table-form-edit-multi-set-remove">
450
- <?php _e('Remove', 'yasr') ?>
451
- </td>
452
-
453
- </tr>
454
-
455
- <?php
456
- foreach ($set_name as $name) {
457
- echo "
458
- <tr>
459
-
460
- <td width=\"80%\">
461
- Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$name->id\">
462
- </td>
463
-
464
- <td width=\"20%\" style=\"text-align:center\">
465
- <input type=\"checkbox\" name=\"remove-element-$name->id\">
466
- </td>
467
-
468
- </tr>
469
- ";
470
- $i++;
471
- }
472
-
473
-
474
- $i = $i-1; //This is the number of the fields
475
-
476
- echo "
477
-
478
- <input type=\"hidden\" name=\"yasr-edit-form-number-elements\" id=\"yasr-edit-form-number-elements\" value=\"$i\">
479
-
480
- </table>
481
-
482
- <table width=\"100%\" class=\"yasr-edit-form-remove-entire-set\">
483
- <tr>
484
-
485
- <td width=\"80%\">Remove whole set?</td>
486
-
487
- <td width=\"20%\" style=\"text-align:center\">
488
- <input type=\"checkbox\" name=\"yasr-remove-multi-set\" value=\"$set_type\">
489
- </td>
490
-
491
- </tr>
492
-
493
- </table>
494
-
495
- ";
496
-
497
- echo "<p>";
498
- _e("If you remove something you will remove all the votes for that set or field. This operation CAN'T BE undone." , "yasr");
499
- echo "</p>";
500
-
501
- wp_nonce_field( 'edit-multi-set', 'add-nonce-edit-multi-set' )
502
-
503
- ?>
504
-
505
- <div id="yasr-element-limit" style="display:none; color:red"><?php _e("You can use up to 9 elements" , "yasr") ?></div>
506
-
507
- <input type="button" class="button-delete" id="yasr-add-field-edit-multiset" value="<?php _e('Add element', 'yasr'); ?>">
508
-
509
- <input type="submit" value="<?php _e('Save changes', 'yasr') ?>" class="button-primary" >
510
-
511
- </form>
512
-
513
- <?php
514
-
515
- die();
516
-
517
- } //End function
518
-
519
-
520
-
521
-
522
-
523
-
524
/********* IMPORT FUNCTIONS *********/
525
526
add_action( 'plugins_loaded', 'add_action_import_gdstar_1' );
411
412
413
414
/********* IMPORT FUNCTIONS *********/
415
416
add_action( 'plugins_loaded', 'add_action_import_gdstar_1' );
lib/yasr-db-functions.php CHANGED
@@ -73,261 +73,6 @@ function yasr_install() {
73
74
}
75
76
- /*************************BEGIN IMPORT FUNCTIONS*******************************/
77
-
78
- /****** Check for previous GD STAR INSTALLATION *******/
79
- function yasr_search_gd_star_rating () {
80
- $gd_star_rating_found=FALSE;
81
-
82
- if ( is_plugin_active( 'gd-star-rating/gd-star-rating.php' ) ) {
83
- $gd_star_rating_found=TRUE;
84
- }
85
-
86
- else {
87
- global $wpdb;
88
-
89
- $gdstar_table=$wpdb->prefix . 'gdsr_data_article';
90
-
91
- if ($wpdb->get_var("SHOW TABLES LIKE '$gdstar_table'") == $gdstar_table) {
92
- $gd_star_rating_found=TRUE;
93
- }
94
-
95
- else {
96
- __( 'No previous Gd Star Ratings installation was found', 'yasr' );
97
- }
98
- }
99
-
100
- return $gd_star_rating_found;
101
-
102
- }
103
-
104
- /****** Import the following Gd Star Rating columns FROM gdsr_data_article
105
- post_id
106
- user_voters
107
- user_votes
108
- visitor_voters
109
- visitor_votes
110
- review
111
- ******/
112
-
113
- function yasr_import_gdstar_data(){
114
-
115
- $gd_stars_option=get_option("gd-star-rating");
116
-
117
- if ($gd_stars_option) {
118
-
119
- $n_visitors_stars=$gd_stars_option['stars'];
120
- $n_review_stars=$gd_stars_option['review_stars'];
121
- }
122
-
123
- else {
124
-
125
- $n_visitors_stars=5;
126
- $n_review_stars=5;
127
-
128
- }
129
-
130
- global $wpdb;
131
-
132
- $gdsr_data_article=$wpdb->prefix . 'gdsr_data_article';
133
-
134
- $data=$wpdb->get_results(" SELECT gd.post_id, (gd.user_voters + gd.visitor_voters) AS voters,
135
- (gd.user_votes + gd.visitor_votes) AS sum_votes,
136
- gd.review,
137
- p.ID, p.post_author
138
- FROM $gdsr_data_article AS gd, $wpdb->posts AS p
139
- WHERE gd.post_id = p.id" );
140
-
141
- //If in gd star rating user didn't use 5 rating system convert it
142
-
143
- //Review Convertion
144
- if($n_review_stars != 5) {
145
-
146
- foreach ($data as $data_row) {
147
- $data_row->review=($data_row->review/$n_review_stars)*5; //Review vote convertion
148
- }
149
-
150
- }
151
-
152
-
153
- if ($n_visitors_stars != 5) {
154
-
155
- foreach ($data as $data_row) {
156
- $data_row->sum_votes=($data_row->sum_votes/$n_visitors_stars)*5; //Visitor Vote conversion
157
- }
158
-
159
- }
160
-
161
- return $data;
162
-
163
- }
164
-
165
-
166
- /****** Import the following GDSR columns FROM wp_gdsr_multis ******/
167
- function yasr_import_gdstar_multi_set(){
168
- global $wpdb;
169
-
170
- $table_name = $wpdb->prefix . 'gdsr_multis';
171
-
172
- $multi_set = $wpdb->get_results (" SELECT multi_id, name, stars, object FROM $table_name");
173
-
174
- return $multi_set;
175
- }
176
-
177
-
178
- /****** Import the following Gd Star Rating columns:
179
- 'id' and 'post_id': FROM gdsr_multis_data
180
- 'user_votes' and 'item_id' FROM gdsr_multis_values
181
- 'multi_id' from gdsr_multis_values
182
-
183
- Then check if some multi set has star's number !=5 and convert every vote
184
- that use that set
185
-
186
- Thanks to Alessandro Carlo Chirico for his helps in this query!
187
- ******/
188
- function yasr_import_gdstar_multi_value(){
189
- global $wpdb;
190
-
191
- $table_gdsr_multis_values=$wpdb->prefix . 'gdsr_multis_values';
192
- $table_gdsr_multis_data=$wpdb->prefix . 'gdsr_multis_data';
193
- $table_gdsr_multis=$wpdb->prefix . 'gdsr_multis';
194
-
195
- $multi_set_data=$wpdb->get_results (" SELECT d.post_id,
196
- v.user_votes, v.item_id,
197
- m.multi_id
198
- FROM $table_gdsr_multis_values AS v, $table_gdsr_multis_data AS d, $wpdb->posts AS p, $table_gdsr_multis AS m
199
- WHERE v.id = d.id
200
- AND 0 <> (
201
- SELECT SUM( user_votes )
202
- FROM wp_gdsr_multis_values AS tabin
203
- WHERE tabin.id = v.id )
204
- AND p.ID = d.post_id
205
- AND d.multi_id = m.multi_id
206
- AND p.post_status = 'publish'
207
- AND v.source = 'rvw'
208
- ORDER BY d.post_id, m.multi_id, v.item_id ASC ");
209
-
210
-
211
- //Import multi set name: if a multiset use != 5 stars,
212
- //then i search wich vote has that set and convert
213
- //the vote to fit 5 stars vote
214
- $old_multi_set = yasr_import_gdstar_multi_set();
215
-
216
- foreach ($old_multi_set AS $multi_set) { //Search wich set not use 5 stars
217
- if ($multi_set->stars != 5) {
218
- //Search in the $multi_set_data if some vote use a set with !=5 stars
219
- foreach ($multi_set_data as $data_row) {
220
- if ($data_row->multi_id == $multi_set->multi_id) {
221
- $data_row->user_votes=($data_row->user_votes/$multi_set->stars)*5; //Vote convertion
222
- }
223
- } //End foreach $multi_set_data
224
- } //End if $multi_set->stars != 5
225
- }
226
-
227
- return ($multi_set_data);
228
- }
229
-
230
- /****** Insert Gd Star Rating review in overall rating ******/
231
- function yasr_insert_gdstar_data($votes){
232
- global $wpdb;
233
-
234
- foreach ( $votes as $column ) {
235
- $result=$wpdb->replace(
236
- YASR_VOTES_TABLE,
237
- array (
238
- 'reviewer_id' => $column->post_author,
239
- 'post_id' => $column->post_id,
240
- 'overall_rating' => $column->review,
241
- 'number_of_votes' => $column->voters,
242
- 'sum_votes' =>$column->sum_votes
243
- ),
244
- array( '%d', '%d', '%s', '%d', '%d')
245
- );
246
- }
247
- return $result;
248
- }
249
-
250
- /****** Insert gd star rating multi set name
251
-
252
- Thanks to Alessandro Carlo Chirico for his help in regex!
253
- ******/
254
- function yasr_insert_gdstar_multi_set($multi_set_names) {
255
-
256
- global $wpdb;
257
-
258
- $i=0;
259
- foreach ($multi_set_names as $value) {
260
-
261
- $result = $wpdb->replace(
262
- YASR_MULTI_SET_NAME_TABLE,
263
- array(
264
- 'set_id' =>$value->multi_id,
265
- 'set_name' =>$value->name
266
- ),
267
- array ('%d', '%s')
268
- );
269
-
270
- if ($result) {
271
-
272
- if(preg_match_all('#".+?"#', $value->object, $matches)) {
273
- $fields = $matches[0];
274
- }
275
-
276
- $fields = str_replace('"', '', $fields);
277
-
278
- foreach ($fields as $id => $field_name) {
279
- $result2=$wpdb->replace(
280
- YASR_MULTI_SET_FIELDS_TABLE,
281
- array(
282
- 'id' => $i,
283
- 'parent_set_id' =>$value->multi_id,
284
- 'field_name' =>$field_name,
285
- 'field_id' =>$id
286
- ),
287
- array ('%d', '%d', '%s', '%d')
288
- );
289
- $i++;
290
- } //End Foreach ($fields as $id => $field_name)
291
-
292
- } //End if $result
293
- }
294
-
295
- if ($result && $result2) {
296
- return "OK";
297
- }
298
-
299
- }
300
-
301
- /******
302
- Check how many stars the existing set use, than convert the vote
303
- into 5 stars. Last insert GD Star Rating multi values
304
- ******/
305
- function yasr_insert_gdstar_multi_value($multi_datas) {
306
- global $wpdb;
307
-
308
- $i=1;
309
- foreach ($multi_datas as $value) {
310
- $result=$wpdb->replace(
311
- YASR_MULTI_SET_VALUES_TABLE,
312
- array(
313
- 'id' =>$i,
314
- 'post_id' => $value->post_id,
315
- 'votes' => $value->user_votes,
316
- 'field_id' => $value->item_id,
317
- 'set_type' => $value->multi_id
318
- ),
319
- array('%d', '%d', '%s', '%d','%d')
320
- );
321
- $i++;
322
- }
323
-
324
- return $result;
325
- }
326
-
327
-
328
- /****************************END IMPORT FUNCTIONS******************************/
329
-
330
-
331
332
/****** Get overall rating from yasr_votes table
333
used in yasr_add_filter_for_schema() and yasr_get_id_value_callback() ******/
@@ -410,365 +155,6 @@ function yasr_get_visitor_votes () {
410
}
411
412
413
- /****** Validate new multi set form ******/
414
- function yasr_process_new_multi_set_form()
415
- {
416
-
417
- if ( isset( $_POST['multi-set-name']) ) {
418
-
419
- global $wpdb;
420
-
421
- if ( !current_user_can( 'manage_options' ) ) {
422
- wp_die( 'You are not allowed to be on this page.' );
423
- }
424
-
425
- // Check nonce field
426
- check_admin_referer( 'add-multi-set', 'add-nonce-new-multi-set' );
427
-
428
- $array_errors = array();
429
- $error = FALSE;
430
-
431
- //IF thes fields are not empty go ahed
432
- if ($_POST['multi-set-name']!='' && $_POST['multi-set-name-element-1']!='' && $_POST['multi-set-name-element-2']!='' ) {
433
-
434
- $multi_set_name = ucfirst(strtolower($_POST['multi-set-name']));
435
-
436
- $multi_set_name_element_=array();
437
-
438
- $multi_set_name_element_[1]=$_POST['multi-set-name-element-1'];
439
- $multi_set_name_element_[2]=$_POST['multi-set-name-element-2'];
440
-
441
- //If multi set name is shorter than 3 characher come back
442
- if (mb_strlen($multi_set_name) < 3 || mb_strlen($multi_set_name_element_[1]) <3 || mb_strlen($multi_set_name_element_[2]) <3 ) {
443
- $array_errors[] = "Content field must be longer then 3 chars";
444
- $error=TRUE;
445
- }
446
-
447
- //Check if a set with that name already exists
448
- $check_name_exists=$wpdb->get_results("SELECT set_name FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id ASC");
449
-
450
- foreach ($check_name_exists as $set_name) {
451
-
452
- if ($multi_set_name==$set_name->set_name) {
453
- $array_errors[] = "You already have a set with this name";
454
- $error=TRUE;
455
- }
456
-
457
- }
458
-
459
- $element_filled=2;
460
-
461
- //If filled get the element from 3 to 9
462
- for($i=3; $i<=9; $i++) {
463
-
464
- if (isset($_POST["multi-set-name-element-$i"]) && $_POST["multi-set-name-element-$i"]!='') {
465
-
466
- $multi_set_name_element_[$i]=$_POST["multi-set-name-element-$i"];
467
-
468
- if (mb_strlen($multi_set_name_element_[$i]) < 3) {
469
- $array_errors[] = "Field # $i must be at least 3 characters";
470
- $error=TRUE;
471
- }
472
-
473
- $element_filled++;
474
- }
475
-
476
- }
477
-
478
- //If there isnt any error write in the table
479
- if (!$error) {
480
-
481
- //get the highest id in table
482
- $highest_id=$wpdb->get_results("SELECT set_id FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id DESC LIMIT 1 ");
483
-
484
- if (!$highest_id) {
485
- $name_table_new_id=0;
486
- }
487
-
488
- foreach ($highest_id as $id) {
489
- $name_table_new_id=$id->set_id + 1;
490
- }
491
-
492
- $insert_multi_name_success = $wpdb->replace(
493
- YASR_MULTI_SET_NAME_TABLE,
494
- array(
495
- 'set_id' =>$name_table_new_id,
496
- 'set_name' =>$multi_set_name
497
- ),
498
- array ('%d', '%s')
499
- );
500
-
501
- //If multi set name hase been inserted, now we're going to insert elements
502
- if ($insert_multi_name_success) {
503
-
504
- //get the highest id in table
505
- $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
506
-
507
- if (!$highest_id) {
508
- $field_table_new_id=0;
509
- }
510
-
511
- foreach ($highest_id as $id) {
512
- $field_table_new_id=$id->id + 1;
513
- }
514
-
515
- for ($i=1; $i<=$element_filled; $i++) {
516
- $insert_set_value=$wpdb->replace(
517
- YASR_MULTI_SET_FIELDS_TABLE,
518
- array(
519
- 'id' => $field_table_new_id,
520
- 'parent_set_id' =>$name_table_new_id,
521
- 'field_name' =>$multi_set_name_element_[$i],
522
- 'field_id' =>$i
523
- ),
524
- array ('%d', '%d', '%s', '%d')
525
- );
526
- $field_table_new_id++; //Avoid overwrite
527
- } //End for
528
-
529
- if ($insert_set_value) {
530
- echo "<div class=\"updated\"><p><strong>";
531
- _e("Settings Saved", 'yasr');
532
- echo "</strong></p></div> ";
533
- }
534
-
535
- else {
536
- _e("Something goes wrong trying insert set field name. Please report it", 'yasr');
537
- }
538
-
539
- } //End if $insert_multi_name_success
540
-
541
- else {
542
- _e("Something goes wrong trying insert multi set name. Please report it", 'yasr');
543
- }
544
-
545
- } //End if !$error
546
-
547
- } //End if $_POST['multi-set-name']!=''
548
-
549
- //Else multi set's name and first 2 elements are empty
550
- else {
551
- $array_errors[] = "Multi set's name and first 2 elements can't be empty";
552
- $error=TRUE;
553
- }
554
-
555
- if ($error) {
556
- return $array_errors;
557
- }
558
-
559
- } //End if ( isset( $_POST['multi-set-name']) ) {
560
-
561
- } //End yasr_process_new_multi_set_form() function
562
-
563
-
564
- /****** Process Edit multi set form ******/
565
- function yasr_process_edit_multi_set_form() {
566
-
567
- $error = FALSE;
568
-
569
- if ( isset( $_POST['yasr_edit_multi_set_form']) ) {
570
-
571
- $set_id = $_POST['yasr_edit_multi_set_form'];
572
-
573
- $number_of_stored_elements = $_POST['yasr-edit-form-number-elements'];
574
-
575
- global $wpdb;
576
-
577
- $array_errors = array();
578
-
579
- if ( !current_user_can( 'manage_options' ) ) {
580
- wp_die( 'You are not allowed to be on this page.' );
581
- }
582
-
583
- // Check nonce field
584
- check_admin_referer( 'edit-multi-set', 'add-nonce-edit-multi-set' );
585
-
586
-
587
- //Check if user want to delete entire set
588
-
589
- if (isset($_POST["yasr-remove-multi-set"])) {
590
-
591
- $remove_set = $wpdb->delete (
592
- YASR_MULTI_SET_NAME_TABLE,
593
- array(
594
- 'set_id' => $set_id,
595
- ),
596
- array ('%d')
597
- );
598
-
599
- $remove_set_values = $wpdb->delete (
600
- YASR_MULTI_SET_FIELDS_TABLE,
601
- array(
602
- 'parent_set_id' => $set_id,
603
- ),
604
- array ('%d')
605
- );
606
-
607
- $remove_set_votes = $wpdb->delete (
608
- YASR_MULTI_SET_VALUES_TABLE,
609
- array(
610
- 'set_type' => $set_id,
611
- ),
612
- array ('%d')
613
- );
614
-
615
- if ($remove_set===FALSE) {
616
- $error = TRUE;
617
- $array_errors[] = __("Something goes wrong trying to delete a multi-set . Please report it", 'yasr');
618
- }
619
-
620
- if ($remove_set_values===FALSE) {
621
- $error = TRUE;
622
- $array_errors[] = __("Something goes wrong trying to delete data fields for a set. Please report it", 'yasr');
623
- }
624
-
625
- if ($remove_set_votes===FALSE) {
626
- $error = TRUE;
627
- $array_errors[] = __("Something goes wrong trying to delete data values for a set. Please report it", 'yasr');
628
- }
629
-
630
- }
631
-
632
-
633
- for ($i = 0; $i <= 9; $i++) {
634
-
635
- //Than, check if the user want to remove some field
636
- if (isset($_POST["remove-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) ) {
637
-
638
- $remove_field = $wpdb->delete (
639
- YASR_MULTI_SET_FIELDS_TABLE,
640
- array(
641
- 'parent_set_id' => $set_id,
642
- 'field_id' =>$i
643
- ),
644
- array ('%d', '%d')
645
- );
646
-
647
- $remove_values = $wpdb->delete (
648
- YASR_MULTI_SET_VALUES_TABLE,
649
- array(
650
- 'set_type' => $set_id,
651
- 'field_id' =>$i
652
- ),
653
- array ('%d', '%d')
654
- );
655
-
656
- if ($remove_field === FALSE) {
657
- $error = TRUE;
658
- $array_errors[] = __("Something goes wrong trying to delete a multi-set element. Please report it", 'yasr');
659
- }
660
-
661
- if ($remove_values === FALSE) {
662
- $error = TRUE;
663
- $array_errors[] = __("Something goes wrong trying to delete data value for an element. Please report it", 'yasr');
664
- }
665
-
666
-
667
- } //End if isset $_POST['remove-element-$i']
668
-
669
-
670
- //update the stored elements with the new ones
671
- if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i <= $number_of_stored_elements ) {
672
-
673
- $field_name = $_POST["edit-multi-set-element-$i"];
674
-
675
- //if elements name is shorter than 3 chars
676
- if (mb_strlen($field_name) <3 ) {
677
- $array_errors[] = __("Field # $i must be at least 3 characters", "yasr");
678
- $error=TRUE;
679
- }
680
-
681
- else {
682
-
683
- $insert_field_name=$wpdb->update(
684
- YASR_MULTI_SET_FIELDS_TABLE,
685
-
686
- array(
687
- 'field_name' =>$field_name,
688
- ),
689
-
690
- array(
691
- 'parent_set_id' =>$set_id,
692
- 'field_id' =>$i
693
- ),
694
-
695
- array ('%s'),
696
-
697
- array ('%d', '%s', '%d')
698
-
699
- );
700
-
701
- if ($insert_field_name === FALSE) {
702
- $error = TRUE;
703
- $array_errors[] = __("Something goes wrong trying to update a multi set element. Please report it", 'yasr');
704
- }
705
-
706
- }
707
-
708
- } //End if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["remove-element-$i"]) && $i<=$number_of_stored_elements )
709
-
710
-
711
- //If $i > number of stored elements, user is adding new elements, so we're going to insert the new ones
712
- if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["remove-element-$i"]) && $i > $number_of_stored_elements ) {
713
-
714
- $field_name = $_POST["edit-multi-set-element-$i"];
715
-
716
- //if elements name is shorter than 3 chars return error. I use mb_strlen($field_name) > 1
717
- //because I don't wont return error if an user add an empty field. An empty field will be
718
- //just ignored
719
- if (mb_strlen($field_name) > 1 && mb_strlen($field_name) < 3) {
720
- $array_errors[] = __("Field # $i must be at least 3 characters", "yasr");
721
- $error=TRUE;
722
- }
723
-
724
- //if field is not empty
725
- elseif ($field_name != '') {
726
-
727
- $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
728
-
729
- foreach ($highest_id as $id) {
730
- $field_table_new_id=$id->id + 1;
731
- }
732
-
733
- $insert_set_value=$wpdb->replace(
734
- YASR_MULTI_SET_FIELDS_TABLE,
735
- array(
736
- 'id' => $field_table_new_id,
737
- 'parent_set_id' =>$set_id,
738
- 'field_name' =>$field_name,
739
- 'field_id' =>$i
740
- ),
741
- array ('%d', '%d', '%s', '%d')
742
- );
743
- $field_table_new_id++; //Avoid overwrite
744
-
745
- if ($insert_set_value === FALSE) {
746
- $error = TRUE;
747
- $array_errors[] = __("Something goes wrong trying to insert set field name in edit form. Please report it", 'yasr');
748
- }
749
-
750
- } //end else
751
- }
752
-
753
-
754
- } //End for
755
-
756
-
757
- if ($error) {
758
- return $array_errors;
759
- }
760
- else {
761
- echo "<div class=\"updated\"><p><strong>";
762
- _e("Settings Saved", 'yasr');
763
- echo "</strong></p></div> ";
764
- }
765
-
766
-
767
- } //End if isset( $_POST['yasr_edit_multi_set_form']
768
-
769
-
770
- } //End yasr_process_edit_multi_set_form() function
771
-
772
773
/****** Adding log's widget to the dashboard ******/
774
73
74
}
75
76
77
/****** Get overall rating from yasr_votes table
78
used in yasr_add_filter_for_schema() and yasr_get_id_value_callback() ******/
155
}
156
157
158
159
/****** Adding log's widget to the dashboard ******/
160
lib/yasr-functions.php CHANGED
@@ -85,12 +85,11 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
85
}
86
?>
87
88
-
89
<div class="yasr-settingsdiv">
90
<form action="options.php" method="post" id="yasr_settings_form">
91
<?php
92
settings_fields( 'yasr_auto_insert_options_group' );
93
- settings_fields( 'yasr_choose_snippet_group' );
94
do_settings_sections('yasr_settings_page' );
95
submit_button( __('Save') );
96
?>
@@ -106,174 +105,6 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
106
} //End yasr_settings_page_content
107
108
109
- /****** Create a form for settings page to create new multi set ******/
110
- function yasr_display_multi_set_form() {
111
- ?>
112
-
113
- <h4 align="center">Add New Multiple Set</h4>
114
- <em><?php _e('Field Name, Element#1 and Element#2 MUST be filled and must be long at least 3 characters', 'yasr') ?></em>
115
- <p>
116
- <form action="<?php echo admin_url('options-general.php?page=yasr_settings_page') ?>" id="form_add_multi_set" method="post">
117
- <strong><?php _e("Name", 'yasr')?></strong>
118
- <input type="text" name="multi-set-name" id="new-multi-set-name" class="input-text-multi-set">
119
- <input type="hidden" name="action" value="yasr_new_multi_set_form" />
120
-
121
- <p></p>
122
- <?php _e("You can insert up to nine element") ?>
123
- <br />
124
-
125
- <?php for($i=1; $i<=9; $i++) {
126
-
127
- echo "<strong>" . __("Element ", 'yasr') . "#$i" . "</strong>";
128
- ?>
129
- <input type="text" name="multi-set-name-element-<?php echo $i ?>" id="multi-set-name-element-<?php echo $i ?>" class="input-text-multi-set">
130
- <br />
131
-
132
- <?php } //End foreach
133
-
134
- wp_nonce_field( 'add-multi-set', 'add-nonce-new-multi-set' ) ?><!-- a little security to process on submission -->
135
-
136
- <br />
137
- <input type="submit" value="<?php _e("Create New Set", 'yasr') ?>" class="button-primary"/>
138
- </form>
139
-
140
- <?php
141
- } //End function
142
-
143
-
144
- /****** This function print the form to edit multi-set ******/
145
- function yasr_edit_multi_form() {
146
-
147
- $multi_set=yasr_get_multi_set();
148
-
149
- global $wpdb;
150
-
151
- $n_multi_set = $wpdb->num_rows; //wpdb->num_rows always store the last of the last query
152
-
153
- if ($n_multi_set > 1) {
154
- ?>
155
-
156
- <button href="#" class="button-delete" id="yasr-manage-multi-set"> <?php _e("Manage existing multi-set", 'yasr'); ?> </button>
157
-
158
- <div class="yasr-manage-multiset">
159
-
160
- <?php _e('Wich set do you want to edit or remove?', 'yasr')?>
161
-
162
- <select id ="yasr_select_edit_set">
163
- <?php foreach ($multi_set as $name) { ?>
164
- <option value="<?php echo $name->set_id ?>"><?php echo $name->set_name ?></option>
165
- <?php } //End foreach ?>
166
- </select>
167
-
168
- </div>
169
-
170
- <?php
171
- } //End if n_multi_set >1
172
-
173
- elseif ($n_multi_set == 1) {
174
-
175
- $set_name=$wpdb->get_results("SELECT field_name AS name, field_id AS id, parent_set_id AS set_id
176
- FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
177
- ORDER BY field_id ASC");
178
-
179
- foreach ($multi_set as $find_set_id) {
180
- $set_type = $find_set_id->set_id;
181
- }
182
-
183
- ?>
184
-
185
- <button href="#" class="button-delete" id="yasr-manage-multi-set-single"> <?php _e("Manage existing multi-set", 'yasr'); ?> </button>
186
-
187
- <div class="yasr-manage-multiset-single">
188
-
189
- <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page') ?>" id="form_edit_multi_set" method="post">
190
-
191
- <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />
192
-
193
- <table id="yasr-table-form-edit-multi-set">
194
- <tr>
195
-
196
- <td id="yasr-table-form-edit-multi-set-header">
197
- <?php _e('Field name', 'yasr') ?>
198
- </td>
199
-
200
- <td id="yasr-table-form-edit-multi-set-remove">
201
- <?php _e('Remove', 'yasr') ?>
202
- </td>
203
-
204
- </tr>
205
-
206
- <?php
207
-
208
- $i=1;
209
- foreach ($set_name as $name) {
210
- echo "
211
- <tr>
212
-
213
- <td width=\"80%\">
214
- Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$name->id\">
215
- </td>
216
-
217
- <td width=\"20%\" style=\"text-align:center\">
218
- <input type=\"checkbox\" name=\"remove-element-$name->id\">
219
- </td>
220
-
221
- </tr>
222
- ";
223
- $i++;
224
- }
225
-
226
-
227
- $i = $i-1; //This is the number of the fields
228
-
229
- echo "
230
-
231
- <input type=\"hidden\" name=\"yasr-edit-form-number-elements\" id=\"yasr-edit-form-number-elements\" value=\"$i\">
232
-
233
- </table>
234
-
235
- <table width=\"100%\" class=\"yasr-edit-form-remove-entire-set\">
236
- <tr>
237
-
238
- <td width=\"80%\">Remove whole set?</td>
239
-
240
- <td width=\"20%\" style=\"text-align:center\">
241
- <input type=\"checkbox\" name=\"yasr-remove-multi-set\" value=\"$set_type\">
242
- </td>
243
-
244
- </tr>
245
-
246
- </table>
247
-
248
- ";
249
-
250
- echo "<p>";
251
- _e("If you remove something you will remove all the votes for that set or field. This operation CAN'T BE undone." , "yasr");
252
- echo "</p>";
253
-
254
- wp_nonce_field( 'edit-multi-set', 'add-nonce-edit-multi-set' )
255
-
256
- ?>
257
-
258
- <div id="yasr-element-limit" style="display:none; color:red"><?php _e("You can use up to 9 elements" , "yasr") ?></div>
259
-
260
- <input type="button" class="button-delete" id="yasr-add-field-edit-multiset" value="<?php _e('Add element', 'yasr'); ?>">
261
-
262
- <input type="submit" value="<?php _e('Save changes', 'yasr') ?>" class="button-primary" >
263
-
264
- </form>
265
-
266
- </div>
267
-
268
- <?php
269
- }
270
-
271
- else {
272
- _e("No multiple set were found");
273
- }
274
-
275
- }//End function
276
-
277
278
/****** Create 2 metaboxes in post and pages ******/
279
@@ -322,9 +153,14 @@ function yasr_edit_multi_form() {
322
323
$schema=NULL; //To avoid undefined variable notice outside the loop
324
325
- $choosen_snippet = get_option( 'yasr_snippet_option' );
326
327
- if ($choosen_snippet['what'] == 'overall_rating') {
328
329
$overall_rating=yasr_get_overall_rating();
330
@@ -355,7 +191,7 @@ function yasr_edit_multi_form() {
355
356
}
357
358
- if ($choosen_snippet['what'] == 'visitor_rating') {
359
360
$visitor_rating = yasr_get_vistor_rating();
361
@@ -368,7 +204,7 @@ function yasr_edit_multi_form() {
368
$div_1 = "<div itemscope itemtype=\"http://schema.org/Product\">";
369
$title = "<span itemprop=\"name\">". get_the_title() ."</span>";
370
$span_1 = "<span itemprop=\"aggregateRating\" itemscope itemtype=\"http://schema.org/AggregateRating\">";
371
- $rating = __( ' rated ' , 'yasr' ) . "<span itemprop=\"ratingValue\">" . $average_rating . "</span>" . __(' out of' ,'yasr') . "<span itemprop=\"bestRating\">5</span>";
372
$n_ratings = __(' based on ', 'yasr') . "<span itemprop=\"ratingCount\">" . $visitor_rating['votes_number'] . "</span>" . __(' user ratings', 'yasr');
373
$end_span_1 = "</span>";
374
$end_div_1 = "</div>";
85
}
86
?>
87
88
<div class="yasr-settingsdiv">
89
<form action="options.php" method="post" id="yasr_settings_form">
90
<?php
91
settings_fields( 'yasr_auto_insert_options_group' );
92
+ //settings_fields( 'yasr_choose_snippet_group' );
93
do_settings_sections('yasr_settings_page' );
94
submit_button( __('Save') );
95
?>
105
} //End yasr_settings_page_content
106
107
108
109
/****** Create 2 metaboxes in post and pages ******/
110
153
154
$schema=NULL; //To avoid undefined variable notice outside the loop
155
156
+ $choosen_snippet = get_option( 'yasr_auto_insert_options' );
157
+
158
+ if(!$choosen_snippet) {
159
+ $choosen_snippet = array();
160
+ $choosen_snippet['snippet'] = 'overall_rating';
161
+ }
162
163
+ if ($choosen_snippet['snippet'] == 'overall_rating') {
164
165
$overall_rating=yasr_get_overall_rating();
166
191
192
}
193
194
+ if ($choosen_snippet['snippet'] == 'visitor_rating') {
195
196
$visitor_rating = yasr_get_vistor_rating();
197
204
$div_1 = "<div itemscope itemtype=\"http://schema.org/Product\">";
205
$title = "<span itemprop=\"name\">". get_the_title() ."</span>";
206
$span_1 = "<span itemprop=\"aggregateRating\" itemscope itemtype=\"http://schema.org/AggregateRating\">";
207
+ $rating = __( ' rated ' , 'yasr' ) . "<span itemprop=\"ratingValue\">" . $average_rating . "</span>" . __(' out of ' ,'yasr') . "<span itemprop=\"bestRating\">5</span>";
208
$n_ratings = __(' based on ', 'yasr') . "<span itemprop=\"ratingCount\">" . $visitor_rating['votes_number'] . "</span>" . __(' user ratings', 'yasr');
209
$end_span_1 = "</span>";
210
$end_div_1 = "</div>";
lib/yasr-settings-functions.php CHANGED
@@ -14,16 +14,29 @@
14
$option = get_option( 'yasr_auto_insert_options' );
15
16
//To avoid undifined index, i put here the default value
17
- if (!$option || !$option['enabled'] || !$option['what'] || !$option['where']) {
18
$option['enabled']=0;
19
$option['what']='overall_rating';
20
$option['where']='top';
21
}
22
23
add_settings_section( 'yasr_auto_insert_section_id', __('Auto insert Settings', 'yasr'), 'yasr_section_callback', 'yasr_settings_page' );
24
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 );
25
add_settings_field( 'yasr_what_auto_insert', __('What?', 'yasr'), 'yasr_what_auto_insert_callback', 'yasr_settings_page', 'yasr_auto_insert_section_id', $option);
26
add_settings_field( 'yasr_where_auto_insert', __('Where?', 'yasr'), 'yasr_where_auto_insert_callback', 'yasr_settings_page', 'yasr_auto_insert_section_id', $option);
27
28
}
29
@@ -37,6 +50,7 @@
37
?>
38
39
<?php _e('Yes', 'yasr') ?>
40
<input type='radio' name='yasr_auto_insert_options[enabled]' value='1' id='yasr_auto_insert_radio_on' <?php if ($option['enabled']==1) echo " checked=\"checked\" "; ?> />
41
&nbsp;&nbsp;&nbsp;
42
@@ -87,48 +101,22 @@
87
88
<p>&nbsp;</p>
89
90
91
- <?php
92
- } //End function yasr_where_auto_insert_callback
93
-
94
-
95
96
- /****** Add choose snippet option ******/
97
98
- add_action( 'admin_init', 'yasr_choose_snippet_init' );
99
-
100
- function yasr_choose_snippet_init() {
101
-
102
- register_setting(
103
- 'yasr_choose_snippet_group', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
104
- 'yasr_snippet_option' //The name of an option to sanitize and save.
105
- );
106
-
107
- $choosen_snippet = get_option( 'yasr_snippet_option' );
108
-
109
- if (!$choosen_snippet || !$choosen_snippet['what']) {
110
- $choosen_snippet['what']='overall_rating';
111
- }
112
-
113
- add_settings_section('yasr_choose_snippet_section_id', __('What rich snippets do you want to use?', 'yasr'), 'yasr_snippet_section_callback', 'yasr_settings_page');
114
- add_settings_field( 'yasr_choose_snippet_id', __('Choose one', 'yasr'), 'yasr_choose_snippet_callback', 'yasr_settings_page', 'yasr_choose_snippet_section_id', $choosen_snippet );
115
-
116
- }
117
118
-
119
- function yasr_snippet_section_callback() {
120
- }
121
-
122
-
123
- function yasr_choose_snippet_callback($choosen_snippet) {
124
125
?>
126
127
- <input type="radio" name="yasr_snippet_option[what]" value="overall_rating" class="yasr_choose_snippet" <?php if ($choosen_snippet['what']==='overall_rating') echo " checked=\"checked\" "; ?> >
128
<?php _e('Review Rating', 'yasr') ?>
129
<br />
130
131
- <input type="radio" name="yasr_snippet_option[what]" value="visitor_rating" class="yasr_choose_snippet" <?php if ($choosen_snippet['what']==='visitor_rating') echo " checked=\"checked\" "; ?> >
132
<?php _e('Aggregate Rating', 'yasr')?>
133
<br />
134
@@ -152,4 +140,898 @@
152
153
}
154
155
?>
14
$option = get_option( 'yasr_auto_insert_options' );
15
16
//To avoid undifined index, i put here the default value
17
+ if (!$option) {
18
+ $option = array();
19
$option['enabled']=0;
20
$option['what']='overall_rating';
21
$option['where']='top';
22
+ $option['snippet']='overall_rating';
23
+ }
24
+
25
+ if ($option && $option['enabled']==0) {
26
+ $option['what']='overall_rating';
27
+ $option['where']='top';
28
+ }
29
+
30
+ if ($option && !$option['snippet']) {
31
+ $option['snippet']='overall_rating';
32
}
33
34
+
35
add_settings_section( 'yasr_auto_insert_section_id', __('Auto insert Settings', 'yasr'), 'yasr_section_callback', 'yasr_settings_page' );
36
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 );
37
add_settings_field( 'yasr_what_auto_insert', __('What?', 'yasr'), 'yasr_what_auto_insert_callback', 'yasr_settings_page', 'yasr_auto_insert_section_id', $option);
38
add_settings_field( 'yasr_where_auto_insert', __('Where?', 'yasr'), 'yasr_where_auto_insert_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
50
?>
51
52
<?php _e('Yes', 'yasr') ?>
53
+
54
<input type='radio' name='yasr_auto_insert_options[enabled]' value='1' id='yasr_auto_insert_radio_on' <?php if ($option['enabled']==1) echo " checked=\"checked\" "; ?> />
55
&nbsp;&nbsp;&nbsp;
56
101
102
<p>&nbsp;</p>
103
104
+ <hr>
105
106
+ <?php
107
108
+ }
109
110
111
+ function yasr_choose_snippet_callback($option) {
112
113
?>
114
115
+ <input type="radio" name="yasr_auto_insert_options[snippet]" value="overall_rating" class="yasr_choose_snippet" <?php if ($option['snippet']==='overall_rating') echo " checked=\"checked\" "; ?> >
116
<?php _e('Review Rating', 'yasr') ?>
117
<br />
118
119
+ <input type="radio" name="yasr_auto_insert_options[snippet]" value="visitor_rating" class="yasr_choose_snippet" <?php if ($option['snippet']==='visitor_rating') echo " checked=\"checked\" "; ?> >
120
<?php _e('Aggregate Rating', 'yasr')?>
121
<br />
122
140
141
}
142
143
+
144
+ /****** Create a form for settings page to create new multi set ******/
145
+ function yasr_display_multi_set_form() {
146
+ ?>
147
+
148
+ <h4 align="center">Add New Multiple Set</h4>
149
+ <em><?php _e('Field Name, Element#1 and Element#2 MUST be filled and must be long at least 3 characters', 'yasr') ?></em>
150
+ <p>
151
+ <form action="<?php echo admin_url('options-general.php?page=yasr_settings_page') ?>" id="form_add_multi_set" method="post">
152
+ <strong><?php _e("Name", 'yasr')?></strong>
153
+ <input type="text" name="multi-set-name" id="new-multi-set-name" class="input-text-multi-set">
154
+ <input type="hidden" name="action" value="yasr_new_multi_set_form" />
155
+
156
+ <p></p>
157
+ <?php _e("You can insert up to nine element") ?>
158
+ <br />
159
+
160
+ <?php for($i=1; $i<=9; $i++) {
161
+
162
+ echo "<strong>" . __("Element ", 'yasr') . "#$i" . "</strong>";
163
+ ?>
164
+ <input type="text" name="multi-set-name-element-<?php echo $i ?>" id="multi-set-name-element-<?php echo $i ?>" class="input-text-multi-set">
165
+ <br />
166
+
167
+ <?php } //End foreach
168
+
169
+ wp_nonce_field( 'add-multi-set', 'add-nonce-new-multi-set' ) ?><!-- a little security to process on submission -->
170
+
171
+ <br />
172
+ <input type="submit" value="<?php _e("Create New Set", 'yasr') ?>" class="button-primary"/>
173
+ </form>
174
+
175
+ <?php
176
+ } //End function
177
+
178
+
179
+
180
+ /****** This function print the form to edit multi-set ******/
181
+ function yasr_edit_multi_form() {
182
+
183
+ $multi_set=yasr_get_multi_set();
184
+
185
+ global $wpdb;
186
+
187
+ $n_multi_set = $wpdb->num_rows; //wpdb->num_rows always store the last of the last query
188
+
189
+ if ($n_multi_set > 1) {
190
+ ?>
191
+
192
+ <button href="#" class="button-delete" id="yasr-manage-multi-set"> <?php _e("Manage existing multi-set", 'yasr'); ?> </button>
193
+
194
+ <div class="yasr-manage-multiset">
195
+
196
+ <?php _e('Wich set do you want to edit or remove?', 'yasr')?>
197
+
198
+ <select id ="yasr_select_edit_set">
199
+ <?php foreach ($multi_set as $name) { ?>
200
+ <option value="<?php echo $name->set_id ?>"><?php echo $name->set_name ?></option>
201
+ <?php } //End foreach ?>
202
+ </select>
203
+
204
+ </div>
205
+
206
+ <?php
207
+ } //End if n_multi_set >1
208
+
209
+ elseif ($n_multi_set == 1) {
210
+
211
+ $set_name=$wpdb->get_results("SELECT field_name AS name, field_id AS id, parent_set_id AS set_id
212
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
213
+ ORDER BY field_id ASC");
214
+
215
+ foreach ($multi_set as $find_set_id) {
216
+ $set_type = $find_set_id->set_id;
217
+ }
218
+
219
+ ?>
220
+
221
+ <button href="#" class="button-delete" id="yasr-manage-multi-set-single"> <?php _e("Manage existing multi-set", 'yasr'); ?> </button>
222
+
223
+ <div class="yasr-manage-multiset-single">
224
+
225
+ <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page') ?>" id="form_edit_multi_set" method="post">
226
+
227
+ <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />
228
+
229
+ <table id="yasr-table-form-edit-multi-set">
230
+ <tr>
231
+
232
+ <td id="yasr-table-form-edit-multi-set-header">
233
+ <?php _e('Field name', 'yasr') ?>
234
+ </td>
235
+
236
+ <td id="yasr-table-form-edit-multi-set-remove">
237
+ <?php _e('Remove', 'yasr') ?>
238
+ </td>
239
+
240
+ </tr>
241
+
242
+ <?php
243
+
244
+ $i=1;
245
+ foreach ($set_name as $name) {
246
+ echo "
247
+ <tr>
248
+
249
+ <td width=\"80%\">
250
+ Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$name->id\">
251
+ </td>
252
+
253
+ <td width=\"20%\" style=\"text-align:center\">
254
+ <input type=\"checkbox\" name=\"remove-element-$name->id\">
255
+ </td>
256
+
257
+ </tr>
258
+ ";
259
+ $i++;
260
+ }
261
+
262
+
263
+ $i = $i-1; //This is the number of the fields
264
+
265
+ echo "
266
+
267
+ <input type=\"hidden\" name=\"yasr-edit-form-number-elements\" id=\"yasr-edit-form-number-elements\" value=\"$i\">
268
+
269
+ </table>
270
+
271
+ <table width=\"100%\" class=\"yasr-edit-form-remove-entire-set\">
272
+ <tr>
273
+
274
+ <td width=\"80%\">Remove whole set?</td>
275
+
276
+ <td width=\"20%\" style=\"text-align:center\">
277
+ <input type=\"checkbox\" name=\"yasr-remove-multi-set\" value=\"$set_type\">
278
+ </td>
279
+
280
+ </tr>
281
+
282
+ </table>
283
+
284
+ ";
285
+
286
+ echo "<p>";
287
+ _e("If you remove something you will remove all the votes for that set or field. This operation CAN'T BE undone." , "yasr");
288
+ echo "</p>";
289
+
290
+ wp_nonce_field( 'edit-multi-set', 'add-nonce-edit-multi-set' )
291
+
292
+ ?>
293
+
294
+ <div id="yasr-element-limit" style="display:none; color:red"><?php _e("You can use up to 9 elements" , "yasr") ?></div>
295
+
296
+ <input type="button" class="button-delete" id="yasr-add-field-edit-multiset" value="<?php _e('Add element', 'yasr'); ?>">
297
+
298
+ <input type="submit" value="<?php _e('Save changes', 'yasr') ?>" class="button-primary" >
299
+
300
+ </form>
301
+
302
+ </div>
303
+
304
+ <?php
305
+ }
306
+
307
+ else {
308
+ _e("No multiple set were found");
309
+ }
310
+
311
+ }//End function
312
+
313
+
314
+
315
+ /****** Get and output multiple set in a form and table, used in settings page ******/
316
+
317
+ add_action( 'wp_ajax_yasr_get_multi_set', 'yasr_get_multi_set_callback' );
318
+
319
+ function yasr_get_multi_set_callback() {
320
+ if (isset($_POST['set_id'])) {
321
+ $set_type = $_POST['set_id'];
322
+ }
323
+ else {
324
+ exit ();
325
+ }
326
+
327
+ global $wpdb;
328
+
329
+ $set_name=$wpdb->get_results("SELECT field_name AS name, field_id AS id
330
+ FROM " . YASR_MULTI_SET_FIELDS_TABLE . "
331
+ WHERE parent_set_id=$set_type
332
+ ORDER BY field_id ASC");
333
+
334
+ $i=1;
335
+
336
+ ?>
337
+
338
+ <form action=" <?php echo admin_url('options-general.php?page=yasr_settings_page') ?>" id="form_edit_multi_set" method="post">
339
+ <input type="hidden" name="yasr_edit_multi_set_form" value="<?php echo $set_type ?>" />
340
+
341
+
342
+ <table id="yasr-table-form-edit-multi-set">
343
+ <tr>
344
+
345
+ <td id="yasr-table-form-edit-multi-set-header">
346
+ <?php _e('Field name', 'yasr') ?>
347
+ </td>
348
+
349
+ <td id="yasr-table-form-edit-multi-set-remove">
350
+ <?php _e('Remove', 'yasr') ?>
351
+ </td>
352
+
353
+ </tr>
354
+
355
+ <?php
356
+ foreach ($set_name as $name) {
357
+ echo "
358
+ <tr>
359
+
360
+ <td width=\"80%\">
361
+ Element #$i <input type=\"text\" value=\"$name->name\" name=\"edit-multi-set-element-$name->id\">
362
+ </td>
363
+
364
+ <td width=\"20%\" style=\"text-align:center\">
365
+ <input type=\"checkbox\" name=\"remove-element-$name->id\">
366
+ </td>
367
+
368
+ </tr>
369
+ ";
370
+ $i++;
371
+ }
372
+
373
+
374
+ $i = $i-1; //This is the number of the fields
375
+
376
+ echo "
377
+
378
+ <input type=\"hidden\" name=\"yasr-edit-form-number-elements\" id=\"yasr-edit-form-number-elements\" value=\"$i\">
379
+
380
+ </table>
381
+
382
+ <table width=\"100%\" class=\"yasr-edit-form-remove-entire-set\">
383
+ <tr>
384
+
385
+ <td width=\"80%\">Remove whole set?</td>
386
+
387
+ <td width=\"20%\" style=\"text-align:center\">
388
+ <input type=\"checkbox\" name=\"yasr-remove-multi-set\" value=\"$set_type\">
389
+ </td>
390
+
391
+ </tr>
392
+
393
+ </table>
394
+
395
+ ";
396
+
397
+ echo "<p>";
398
+ _e("If you remove something you will remove all the votes for that set or field. This operation CAN'T BE undone." , "yasr");
399
+ echo "</p>";
400
+
401
+ wp_nonce_field( 'edit-multi-set', 'add-nonce-edit-multi-set' )
402
+
403
+ ?>
404
+
405
+ <div id="yasr-element-limit" style="display:none; color:red"><?php _e("You can use up to 9 elements" , "yasr") ?></div>
406
+
407
+ <input type="button" class="button-delete" id="yasr-add-field-edit-multiset" value="<?php _e('Add element', 'yasr'); ?>">
408
+
409
+ <input type="submit" value="<?php _e('Save changes', 'yasr') ?>" class="button-primary" >
410
+
411
+ </form>
412
+
413
+ <?php
414
+
415
+ die();
416
+
417
+ } //End function
418
+
419
+
420
+
421
+ /****** Validate new multi set form ******/
422
+ function yasr_process_new_multi_set_form()
423
+ {
424
+
425
+ if ( isset( $_POST['multi-set-name']) ) {
426
+
427
+ global $wpdb;
428
+
429
+ if ( !current_user_can( 'manage_options' ) ) {
430
+ wp_die( 'You are not allowed to be on this page.' );
431
+ }
432
+
433
+ // Check nonce field
434
+ check_admin_referer( 'add-multi-set', 'add-nonce-new-multi-set' );
435
+
436
+ $array_errors = array();
437
+ $error = FALSE;
438
+
439
+ //IF thes fields are not empty go ahed
440
+ if ($_POST['multi-set-name']!='' && $_POST['multi-set-name-element-1']!='' && $_POST['multi-set-name-element-2']!='' ) {
441
+
442
+ $multi_set_name = ucfirst(strtolower($_POST['multi-set-name']));
443
+
444
+ $multi_set_name_element_=array();
445
+
446
+ $multi_set_name_element_[1]=$_POST['multi-set-name-element-1'];
447
+ $multi_set_name_element_[2]=$_POST['multi-set-name-element-2'];
448
+
449
+ //If multi set name is shorter than 3 characher come back
450
+ if (mb_strlen($multi_set_name) < 3 || mb_strlen($multi_set_name_element_[1]) <3 || mb_strlen($multi_set_name_element_[2]) <3 ) {
451
+ $array_errors[] = "Content field must be longer then 3 chars";
452
+ $error=TRUE;
453
+ }
454
+
455
+ //Check if a set with that name already exists
456
+ $check_name_exists=$wpdb->get_results("SELECT set_name FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id ASC");
457
+
458
+ foreach ($check_name_exists as $set_name) {
459
+
460
+ if ($multi_set_name==$set_name->set_name) {
461
+ $array_errors[] = "You already have a set with this name";
462
+ $error=TRUE;
463
+ }
464
+
465
+ }
466
+
467
+ $element_filled=2;
468
+
469
+ //If filled get the element from 3 to 9
470
+ for($i=3; $i<=9; $i++) {
471
+
472
+ if (isset($_POST["multi-set-name-element-$i"]) && $_POST["multi-set-name-element-$i"]!='') {
473
+
474
+ $multi_set_name_element_[$i]=$_POST["multi-set-name-element-$i"];
475
+
476
+ if (mb_strlen($multi_set_name_element_[$i]) < 3) {
477
+ $array_errors[] = "Field # $i must be at least 3 characters";
478
+ $error=TRUE;
479
+ }
480
+
481
+ $element_filled++;
482
+ }
483
+
484
+ }
485
+
486
+ //If there isnt any error write in the table
487
+ if (!$error) {
488
+
489
+ //get the highest id in table
490
+ $highest_id=$wpdb->get_results("SELECT set_id FROM " . YASR_MULTI_SET_NAME_TABLE . " ORDER BY set_id DESC LIMIT 1 ");
491
+
492
+ if (!$highest_id) {
493
+ $name_table_new_id=0;
494
+ }
495
+
496
+ foreach ($highest_id as $id) {
497
+ $name_table_new_id=$id->set_id + 1;
498
+ }
499
+
500
+ $insert_multi_name_success = $wpdb->replace(
501
+ YASR_MULTI_SET_NAME_TABLE,
502
+ array(
503
+ 'set_id' =>$name_table_new_id,
504
+ 'set_name' =>$multi_set_name
505
+ ),
506
+ array ('%d', '%s')
507
+ );
508
+
509
+ //If multi set name hase been inserted, now we're going to insert elements
510
+ if ($insert_multi_name_success) {
511
+
512
+ //get the highest id in table
513
+ $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
514
+
515
+ if (!$highest_id) {
516
+ $field_table_new_id=0;
517
+ }
518
+
519
+ foreach ($highest_id as $id) {
520
+ $field_table_new_id=$id->id + 1;
521
+ }
522
+
523
+ for ($i=1; $i<=$element_filled; $i++) {
524
+ $insert_set_value=$wpdb->replace(
525
+ YASR_MULTI_SET_FIELDS_TABLE,
526
+ array(
527
+ 'id' => $field_table_new_id,
528
+ 'parent_set_id' =>$name_table_new_id,
529
+ 'field_name' =>$multi_set_name_element_[$i],
530
+ 'field_id' =>$i
531
+ ),
532
+ array ('%d', '%d', '%s', '%d')
533
+ );
534
+ $field_table_new_id++; //Avoid overwrite
535
+ } //End for
536
+
537
+ if ($insert_set_value) {
538
+ echo "<div class=\"updated\"><p><strong>";
539
+ _e("Settings Saved", 'yasr');
540
+ echo "</strong></p></div> ";
541
+ }
542
+
543
+ else {
544
+ _e("Something goes wrong trying insert set field name. Please report it", 'yasr');
545
+ }
546
+
547
+ } //End if $insert_multi_name_success
548
+
549
+ else {
550
+ _e("Something goes wrong trying insert multi set name. Please report it", 'yasr');
551
+ }
552
+
553
+ } //End if !$error
554
+
555
+ } //End if $_POST['multi-set-name']!=''
556
+
557
+ //Else multi set's name and first 2 elements are empty
558
+ else {
559
+ $array_errors[] = "Multi set's name and first 2 elements can't be empty";
560
+ $error=TRUE;
561
+ }
562
+
563
+ if ($error) {
564
+ return $array_errors;
565
+ }
566
+
567
+ } //End if ( isset( $_POST['multi-set-name']) ) {
568
+
569
+ } //End yasr_process_new_multi_set_form() function
570
+
571
+
572
+
573
+ /****** Process Edit multi set form ******/
574
+ function yasr_process_edit_multi_set_form() {
575
+
576
+ $error = FALSE;
577
+
578
+ if ( isset( $_POST['yasr_edit_multi_set_form']) ) {
579
+
580
+ $set_id = $_POST['yasr_edit_multi_set_form'];
581
+
582
+ $number_of_stored_elements = $_POST['yasr-edit-form-number-elements'];
583
+
584
+ global $wpdb;
585
+
586
+ $array_errors = array();
587
+
588
+ if ( !current_user_can( 'manage_options' ) ) {
589
+ wp_die( 'You are not allowed to be on this page.' );
590
+ }
591
+
592
+ // Check nonce field
593
+ check_admin_referer( 'edit-multi-set', 'add-nonce-edit-multi-set' );
594
+
595
+
596
+ //Check if user want to delete entire set
597
+
598
+ if (isset($_POST["yasr-remove-multi-set"])) {
599
+
600
+ $remove_set = $wpdb->delete (
601
+ YASR_MULTI_SET_NAME_TABLE,
602
+ array(
603
+ 'set_id' => $set_id,
604
+ ),
605
+ array ('%d')
606
+ );
607
+
608
+ $remove_set_values = $wpdb->delete (
609
+ YASR_MULTI_SET_FIELDS_TABLE,
610
+ array(
611
+ 'parent_set_id' => $set_id,
612
+ ),
613
+ array ('%d')
614
+ );
615
+
616
+ $remove_set_votes = $wpdb->delete (
617
+ YASR_MULTI_SET_VALUES_TABLE,
618
+ array(
619
+ 'set_type' => $set_id,
620
+ ),
621
+ array ('%d')
622
+ );
623
+
624
+ if ($remove_set===FALSE) {
625
+ $error = TRUE;
626
+ $array_errors[] = __("Something goes wrong trying to delete a multi-set . Please report it", 'yasr');
627
+ }
628
+
629
+ if ($remove_set_values===FALSE) {
630
+ $error = TRUE;
631
+ $array_errors[] = __("Something goes wrong trying to delete data fields for a set. Please report it", 'yasr');
632
+ }
633
+
634
+ if ($remove_set_votes===FALSE) {
635
+ $error = TRUE;
636
+ $array_errors[] = __("Something goes wrong trying to delete data values for a set. Please report it", 'yasr');
637
+ }
638
+
639
+ }
640
+
641
+
642
+ for ($i = 0; $i <= 9; $i++) {
643
+
644
+ //Than, check if the user want to remove some field
645
+ if (isset($_POST["remove-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) ) {
646
+
647
+ $remove_field = $wpdb->delete (
648
+ YASR_MULTI_SET_FIELDS_TABLE,
649
+ array(
650
+ 'parent_set_id' => $set_id,
651
+ 'field_id' =>$i
652
+ ),
653
+ array ('%d', '%d')
654
+ );
655
+
656
+ $remove_values = $wpdb->delete (
657
+ YASR_MULTI_SET_VALUES_TABLE,
658
+ array(
659
+ 'set_type' => $set_id,
660
+ 'field_id' =>$i
661
+ ),
662
+ array ('%d', '%d')
663
+ );
664
+
665
+ if ($remove_field === FALSE) {
666
+ $error = TRUE;
667
+ $array_errors[] = __("Something goes wrong trying to delete a multi-set element. Please report it", 'yasr');
668
+ }
669
+
670
+ if ($remove_values === FALSE) {
671
+ $error = TRUE;
672
+ $array_errors[] = __("Something goes wrong trying to delete data value for an element. Please report it", 'yasr');
673
+ }
674
+
675
+
676
+ } //End if isset $_POST['remove-element-$i']
677
+
678
+
679
+ //update the stored elements with the new ones
680
+ if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["yasr-remove-multi-set"]) && !isset($_POST["remove-element-$i"]) && $i <= $number_of_stored_elements ) {
681
+
682
+ $field_name = $_POST["edit-multi-set-element-$i"];
683
+
684
+ //if elements name is shorter than 3 chars
685
+ if (mb_strlen($field_name) <3 ) {
686
+ $array_errors[] = __("Field # $i must be at least 3 characters", "yasr");
687
+ $error=TRUE;
688
+ }
689
+
690
+ else {
691
+
692
+ $insert_field_name=$wpdb->update(
693
+ YASR_MULTI_SET_FIELDS_TABLE,
694
+
695
+ array(
696
+ 'field_name' =>$field_name,
697
+ ),
698
+
699
+ array(
700
+ 'parent_set_id' =>$set_id,
701
+ 'field_id' =>$i
702
+ ),
703
+
704
+ array ('%s'),
705
+
706
+ array ('%d', '%s', '%d')
707
+
708
+ );
709
+
710
+ if ($insert_field_name === FALSE) {
711
+ $error = TRUE;
712
+ $array_errors[] = __("Something goes wrong trying to update a multi set element. Please report it", 'yasr');
713
+ }
714
+
715
+ }
716
+
717
+ } //End if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["remove-element-$i"]) && $i<=$number_of_stored_elements )
718
+
719
+
720
+ //If $i > number of stored elements, user is adding new elements, so we're going to insert the new ones
721
+ if (isset($_POST["edit-multi-set-element-$i"]) && !isset($_POST["remove-element-$i"]) && $i > $number_of_stored_elements ) {
722
+
723
+ $field_name = $_POST["edit-multi-set-element-$i"];
724
+
725
+ //if elements name is shorter than 3 chars return error. I use mb_strlen($field_name) > 1
726
+ //because I don't wont return error if an user add an empty field. An empty field will be
727
+ //just ignored
728
+ if (mb_strlen($field_name) > 1 && mb_strlen($field_name) < 3) {
729
+ $array_errors[] = __("Field # $i must be at least 3 characters", "yasr");
730
+ $error=TRUE;
731
+ }
732
+
733
+ //if field is not empty
734
+ elseif ($field_name != '') {
735
+
736
+ $highest_id=$wpdb->get_results("SELECT id FROM " . YASR_MULTI_SET_FIELDS_TABLE . " ORDER BY id DESC LIMIT 1 ");
737
+
738
+ foreach ($highest_id as $id) {
739
+ $field_table_new_id=$id->id + 1;
740
+ }
741
+
742
+ $insert_set_value=$wpdb->replace(
743
+ YASR_MULTI_SET_FIELDS_TABLE,
744
+ array(
745
+ 'id' => $field_table_new_id,
746
+ 'parent_set_id' =>$set_id,
747
+ 'field_name' =>$field_name,
748
+ 'field_id' =>$i
749
+ ),
750
+ array ('%d', '%d', '%s', '%d')
751
+ );
752
+ $field_table_new_id++; //Avoid overwrite
753
+
754
+ if ($insert_set_value === FALSE) {
755
+ $error = TRUE;
756
+ $array_errors[] = __("Something goes wrong trying to insert set field name in edit form. Please report it", 'yasr');
757
+ }
758
+
759
+ } //end else
760
+ }
761
+
762
+
763
+ } //End for
764
+
765
+
766
+ if ($error) {
767
+ return $array_errors;
768
+ }
769
+ else {
770
+ echo "<div class=\"updated\"><p><strong>";
771
+ _e("Settings Saved", 'yasr');
772
+ echo "</strong></p></div> ";
773
+ }
774
+
775
+
776
+ } //End if isset( $_POST['yasr_edit_multi_set_form']
777
+
778
+
779
+ } //End yasr_process_edit_multi_set_form() function
780
+
781
+
782
+ /*************************BEGIN IMPORT FUNCTIONS*******************************/
783
+
784
+ /****** Check for previous GD STAR INSTALLATION *******/
785
+ function yasr_search_gd_star_rating () {
786
+ $gd_star_rating_found=FALSE;
787
+
788
+ if ( is_plugin_active( 'gd-star-rating/gd-star-rating.php' ) ) {
789
+ $gd_star_rating_found=TRUE;
790
+ }
791
+
792
+ else {
793
+ global $wpdb;
794
+
795
+ $gdstar_table=$wpdb->prefix . 'gdsr_data_article';
796
+
797
+ if ($wpdb->get_var("SHOW TABLES LIKE '$gdstar_table'") == $gdstar_table) {
798
+ $gd_star_rating_found=TRUE;
799
+ }
800
+
801
+ else {
802
+ __( 'No previous Gd Star Ratings installation was found', 'yasr' );
803
+ }
804
+ }
805
+
806
+ return $gd_star_rating_found;
807
+
808
+ }
809
+
810
+ /****** Import the following Gd Star Rating columns FROM gdsr_data_article
811
+ post_id
812
+ user_voters
813
+ user_votes
814
+ visitor_voters
815
+ visitor_votes
816
+ review
817
+ ******/
818
+
819
+ function yasr_import_gdstar_data(){
820
+
821
+ $gd_stars_option=get_option("gd-star-rating");
822
+
823
+ if ($gd_stars_option) {
824
+
825
+ $n_visitors_stars=$gd_stars_option['stars'];
826
+ $n_review_stars=$gd_stars_option['review_stars'];
827
+ }
828
+
829
+ else {
830
+
831
+ $n_visitors_stars=5;
832
+ $n_review_stars=5;
833
+
834
+ }
835
+
836
+ global $wpdb;
837
+
838
+ $gdsr_data_article=$wpdb->prefix . 'gdsr_data_article';
839
+
840
+ $data=$wpdb->get_results(" SELECT gd.post_id, (gd.user_voters + gd.visitor_voters) AS voters,
841
+ (gd.user_votes + gd.visitor_votes) AS sum_votes,
842
+ gd.review,
843
+ p.ID, p.post_author
844
+ FROM $gdsr_data_article AS gd, $wpdb->posts AS p
845
+ WHERE gd.post_id = p.id" );
846
+
847
+ //If in gd star rating user didn't use 5 rating system convert it
848
+
849
+ //Review Convertion
850
+ if($n_review_stars != 5) {
851
+
852
+ foreach ($data as $data_row) {
853
+ $data_row->review=($data_row->review/$n_review_stars)*5; //Review vote convertion
854
+ }
855
+
856
+ }
857
+
858
+
859
+ if ($n_visitors_stars != 5) {
860
+
861
+ foreach ($data as $data_row) {
862
+ $data_row->sum_votes=($data_row->sum_votes/$n_visitors_stars)*5; //Visitor Vote conversion
863
+ }
864
+
865
+ }
866
+
867
+ return $data;
868
+
869
+ }
870
+
871
+
872
+ /****** Import the following GDSR columns FROM wp_gdsr_multis ******/
873
+ function yasr_import_gdstar_multi_set(){
874
+ global $wpdb;
875
+
876
+ $table_name = $wpdb->prefix . 'gdsr_multis';
877
+
878
+ $multi_set = $wpdb->get_results (" SELECT multi_id, name, stars, object FROM $table_name");
879
+
880
+ return $multi_set;
881
+ }
882
+
883
+
884
+ /****** Import the following Gd Star Rating columns:
885
+ 'id' and 'post_id': FROM gdsr_multis_data
886
+ 'user_votes' and 'item_id' FROM gdsr_multis_values
887
+ 'multi_id' from gdsr_multis_values
888
+
889
+ Then check if some multi set has star's number !=5 and convert every vote
890
+ that use that set
891
+
892
+ Thanks to Alessandro Carlo Chirico for his helps in this query!
893
+ ******/
894
+ function yasr_import_gdstar_multi_value(){
895
+ global $wpdb;
896
+
897
+ $table_gdsr_multis_values=$wpdb->prefix . 'gdsr_multis_values';
898
+ $table_gdsr_multis_data=$wpdb->prefix . 'gdsr_multis_data';
899
+ $table_gdsr_multis=$wpdb->prefix . 'gdsr_multis';
900
+
901
+ $multi_set_data=$wpdb->get_results (" SELECT d.post_id,
902
+ v.user_votes, v.item_id,
903
+ m.multi_id
904
+ FROM $table_gdsr_multis_values AS v, $table_gdsr_multis_data AS d, $wpdb->posts AS p, $table_gdsr_multis AS m
905
+ WHERE v.id = d.id
906
+ AND 0 <> (
907
+ SELECT SUM( user_votes )
908
+ FROM wp_gdsr_multis_values AS tabin
909
+ WHERE tabin.id = v.id )
910
+ AND p.ID = d.post_id
911
+ AND d.multi_id = m.multi_id
912
+ AND p.post_status = 'publish'
913
+ AND v.source = 'rvw'
914
+ ORDER BY d.post_id, m.multi_id, v.item_id ASC ");
915
+
916
+
917
+ //Import multi set name: if a multiset use != 5 stars,
918
+ //then i search wich vote has that set and convert
919
+ //the vote to fit 5 stars vote
920
+ $old_multi_set = yasr_import_gdstar_multi_set();
921
+
922
+ foreach ($old_multi_set AS $multi_set) { //Search wich set not use 5 stars
923
+ if ($multi_set->stars != 5) {
924
+ //Search in the $multi_set_data if some vote use a set with !=5 stars
925
+ foreach ($multi_set_data as $data_row) {
926
+ if ($data_row->multi_id == $multi_set->multi_id) {
927
+ $data_row->user_votes=($data_row->user_votes/$multi_set->stars)*5; //Vote convertion
928
+ }
929
+ } //End foreach $multi_set_data
930
+ } //End if $multi_set->stars != 5
931
+ }
932
+
933
+ return ($multi_set_data);
934
+ }
935
+
936
+ /****** Insert Gd Star Rating review in overall rating ******/
937
+ function yasr_insert_gdstar_data($votes){
938
+ global $wpdb;
939
+
940
+ foreach ( $votes as $column ) {
941
+ $result=$wpdb->replace(
942
+ YASR_VOTES_TABLE,
943
+ array (
944
+ 'reviewer_id' => $column->post_author,
945
+ 'post_id' => $column->post_id,
946
+ 'overall_rating' => $column->review,
947
+ 'number_of_votes' => $column->voters,
948
+ 'sum_votes' =>$column->sum_votes
949
+ ),
950
+ array( '%d', '%d', '%s', '%d', '%d')
951
+ );
952
+ }
953
+ return $result;
954
+ }
955
+
956
+ /****** Insert gd star rating multi set name
957
+
958
+ Thanks to Alessandro Carlo Chirico for his help in regex!
959
+ ******/
960
+ function yasr_insert_gdstar_multi_set($multi_set_names) {
961
+
962
+ global $wpdb;
963
+
964
+ $i=0;
965
+ foreach ($multi_set_names as $value) {
966
+
967
+ $result = $wpdb->replace(
968
+ YASR_MULTI_SET_NAME_TABLE,
969
+ array(
970
+ 'set_id' =>$value->multi_id,
971
+ 'set_name' =>$value->name
972
+ ),
973
+ array ('%d', '%s')
974
+ );
975
+
976
+ if ($result) {
977
+
978
+ if(preg_match_all('#".+?"#', $value->object, $matches)) {
979
+ $fields = $matches[0];
980
+ }
981
+
982
+ $fields = str_replace('"', '', $fields);
983
+
984
+ foreach ($fields as $id => $field_name) {
985
+ $result2=$wpdb->replace(
986
+ YASR_MULTI_SET_FIELDS_TABLE,
987
+ array(
988
+ 'id' => $i,
989
+ 'parent_set_id' =>$value->multi_id,
990
+ 'field_name' =>$field_name,
991
+ 'field_id' =>$id
992
+ ),
993
+ array ('%d', '%d', '%s', '%d')
994
+ );
995
+ $i++;
996
+ } //End Foreach ($fields as $id => $field_name)
997
+
998
+ } //End if $result
999
+ }
1000
+
1001
+ if ($result && $result2) {
1002
+ return "OK";
1003
+ }
1004
+
1005
+ }
1006
+
1007
+ /******
1008
+ Check how many stars the existing set use, than convert the vote
1009
+ into 5 stars. Last insert GD Star Rating multi values
1010
+ ******/
1011
+ function yasr_insert_gdstar_multi_value($multi_datas) {
1012
+ global $wpdb;
1013
+
1014
+ $i=1;
1015
+ foreach ($multi_datas as $value) {
1016
+ $result=$wpdb->replace(
1017
+ YASR_MULTI_SET_VALUES_TABLE,
1018
+ array(
1019
+ 'id' =>$i,
1020
+ 'post_id' => $value->post_id,
1021
+ 'votes' => $value->user_votes,
1022
+ 'field_id' => $value->item_id,
1023
+ 'set_type' => $value->multi_id
1024
+ ),
1025
+ array('%d', '%d', '%s', '%d','%d')
1026
+ );
1027
+ $i++;
1028
+ }
1029
+
1030
+ return $result;
1031
+ }
1032
+
1033
+
1034
+ /****************************END IMPORT FUNCTIONS******************************/
1035
+
1036
+
1037
?>
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.2.5
7
License: GPL2
8
License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
@@ -49,6 +49,10 @@ If with gd-star-rating you're using a different number of stars from the default
49
50
== Changelog ==
51
52
= 0.2.5 =
53
* Bug fix on multi set
54
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.2.7
7
License: GPL2
8
License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
49
50
== Changelog ==
51
52
+ = 0.2.7 =
53
+ * Many bug fixes on the settings page
54
+ * Minor change and code cleanup
55
+
56
= 0.2.5 =
57
* Bug fix on multi set
58
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.2.5
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
</