279 | | if ( $this->type == "radio" ) { |
280 | | $options = $_POST['radio_option']; |
281 | | } else { |
282 | | $options = $_POST['select_option']; |
283 | | } |
| 279 | if ( !empty( $_POST['field_file'] ) ) { |
| 280 | // Add a prebuilt field from a csv file |
| 281 | $field_file = $_POST['field_file']; |
| 282 | if ( $fp = fopen($field_file, 'r') ) { |
| 283 | $start_reading = false; |
| 284 | while ( ! feof($fp) && !$start_reading) { |
| 285 | if ( $s = fgets ($fp, 1024) ) { |
| 286 | if ( preg_match ( '/\*\//', $s ) ) { |
| 287 | $start_reading = true; |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | while ( ( $data = fgetcsv( $fp ) ) ) { |
| 293 | $num = count($data); |
| 294 | $name = ''; |
| 295 | $description = ''; |
| 296 | if ( $num >= 1 ) { $name = $data[0]; } |
| 297 | if ( $num >= 2 ) { $description = $data[1]; } |
| 298 | if ( $num > 0 ) { |
| 299 | $sql = $wpdb->prepare("INSERT INTO $this->table_name_fields (group_id, parent_id, type, name, description, is_required) VALUES (%d, %d, 'option', %s, %s, 0)", $this->group_id, $parent_id, $name, $description); |
| 300 | $wpdb->query($sql); |
| 301 | } |
| 302 | } |
| 303 | fclose($fp); |
| 304 | } |
| 305 | } else { |
| 306 | if ( $this->type == "radio" ) { |
| 307 | $options = $_POST['radio_option']; |
| 308 | } else { |
| 309 | $options = $_POST['select_option']; |
| 310 | } |
288 | | if ( $option_value != "" ) { |
289 | | // don't insert an empty option. |
290 | | $sql = $wpdb->prepare("INSERT INTO $this->table_name_fields (group_id, parent_id, type, name, description, is_required) VALUES (%d, %d, 'option', %s, '', 0)", $this->group_id, $parent_id, $option_value); |
| 315 | if ( $option_value != "" ) { |
| 316 | // don't insert an empty option. |
| 317 | $sql = $wpdb->prepare("INSERT INTO $this->table_name_fields (group_id, parent_id, type, name, description, is_required) VALUES (%d, %d, 'option', %s, '', 0)", $this->group_id, $parent_id, $option_value); |
| 620 | function render_prebuilt_fields() { |
| 621 | $action = "admin.php?page=xprofile_settings&group_id=" . $this->group_id . "&mode=add_field"; |
| 622 | |
| 623 | // Files in wp-content/themes directory and one subdir down |
| 624 | $prebuilt_fields_path = ABSPATH . MUPLUGINDIR . '/bp-xprofile/prebuilt-fields'; |
| 625 | if( !empty( $prebuilt_fields_path ) ){ |
| 626 | $prebuilt_fields_dir = @opendir($prebuilt_fields_path); |
| 627 | if ( $prebuilt_fields_dir ){ |
| 628 | ?><table class="form-table"><?php |
| 629 | $counter = 0; |
| 630 | while ( ($field_file = readdir( $prebuilt_fields_dir )) !== false ) { |
| 631 | |
| 632 | if ( $field_file{0} == '.' || $field_file == '..' || $field_file == 'CVS' || $field_file == '.svn' ) |
| 633 | continue; |
| 634 | |
| 635 | $field_file_path = $prebuilt_fields_path . '/' . $field_file; |
| 636 | |
| 637 | if ( is_readable( $field_file_path ) ) { |
| 638 | $field_data = $this->get_prebuilt_field_data( $field_file_path ); ?> |
| 639 | <tr> |
| 640 | <td style="vertical-align:top;"> |
| 641 | <h3> |
| 642 | <?php echo $field_data['Name'] . $field_data['Version']; ?> by <a href="<?php echo $field_data['URI'];?>"> |
| 643 | <?php echo $field_data['Author'];?></a> |
| 644 | </h3> |
| 645 | </td> |
| 646 | <td> |
| 647 | <form action="<?php echo $action ?>" method="post"> |
| 648 | |
| 649 | <label for="title">* <?php _e("Field Title") ?></label> |
| 650 | <div> |
| 651 | <input type="text" name="title" id="title" value="<?php echo $field_data['Name']; ?>" style="width:50%" /> |
| 652 | </div> |
| 653 | <p></p> |
| 654 | <label for="description"><?php _e("Field Description") ?></label> |
| 655 | <div> |
| 656 | <textarea name="description" id="description" rows="5" cols="60"><?php echo $field_data['Description']; ?></textarea> |
| 657 | </div> |
| 658 | <p></p> |
| 659 | <label for="required">* <?php _e("Is This Field Required?") ?></label> |
| 660 | <div> |
| 661 | <select name="required" id="required"> |
| 662 | <option value="0"<?php if ( $this->is_required == '0' ) { ?> selected="selected"<?php } ?>>Not Required</option> |
| 663 | <option value="1"<?php if ( $this->is_required == '1' ) { ?> selected="selected"<?php } ?>>Required</option> |
| 664 | </select> |
| 665 | </div> |
| 666 | <p></p> |
| 667 | <label for="fieldtype">* <?php _e("Field Type") ?></label> |
| 668 | <div> |
| 669 | <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)"> |
| 670 | <?php if (in_array('textbox', $field_data['Types'])) { ?> |
| 671 | <option value="textbox"<?php if ( $this->type == 'textbox' ) {?> selected="selected"<?php } ?>>Text Box</option> |
| 672 | <?php } if (in_array('textarea', $field_data['Types'])) { ?> |
| 673 | <option value="textarea"<?php if ( $this->type == 'textarea' ) {?> selected="selected"<?php } ?>>Multi-line Text Box</option> |
| 674 | <?php } if (in_array('datebox', $field_data['Types'])) { ?> |
| 675 | <option value="datebox"<?php if ( $this->type == 'datebox' ) {?> selected="selected"<?php } ?>>Date Selector</option> |
| 676 | <?php } if (in_array('radio', $field_data['Types'])) { ?> |
| 677 | <option value="radio"<?php if ( $this->type == 'radio' ) {?> selected="selected"<?php } ?>>Radio Buttons</option> |
| 678 | <?php } if (in_array('selectbox', $field_data['Types'])) { ?> |
| 679 | <option value="selectbox"<?php if ( $this->type == 'selectbox' ) {?> selected="selected"<?php } ?>>Drop-down Select Box</option> |
| 680 | <?php } ?> |
| 681 | </select> |
| 682 | </div> |
| 683 | |
| 684 | <p class="submit"> |
| 685 | <input type="submit" value="<?php _e("Add") ?> »" name="saveField" id="saveField<?php echo $counter;?>" class="button" /> |
| 686 | <input type="hidden" name="field_file" value="<?php echo $field_file_path; ?>"> |
| 687 | </p> |
| 688 | </form> |
| 689 | </td> |
| 690 | </tr> |
| 691 | <?php |
| 692 | } |
| 693 | $counter++; |
| 694 | } |
| 695 | ?></table><?php |
| 696 | } |
| 697 | @closedir( $prebuilt_fields_dir ); |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | function get_prebuilt_field_data( $field_file ) { |
| 702 | $allowed_tags = array( |
| 703 | 'a' => array( |
| 704 | 'href' => array(),'title' => array() |
| 705 | ), |
| 706 | 'abbr' => array( |
| 707 | 'title' => array() |
| 708 | ), |
| 709 | 'acronym' => array( |
| 710 | 'title' => array() |
| 711 | ), |
| 712 | 'code' => array(), |
| 713 | 'em' => array(), |
| 714 | 'strong' => array() |
| 715 | ); |
| 716 | |
| 717 | $field_data = implode( '', file( $field_file ) ); |
| 718 | $field_data = str_replace ( '\r', '\n', $field_data ); |
| 719 | preg_match( '|Field Name:(.*)$|mi', $field_data, $field_name ); |
| 720 | preg_match( '|URI:(.*)$|mi', $field_data, $uri ); |
| 721 | preg_match( '|Description:(.*)$|mi', $field_data, $description ); |
| 722 | preg_match( '|Types:(.*)$|mi', $field_data, $types ); |
| 724 | if ( preg_match( '|Version:(.*)|i', $field_data, $version ) ) |
| 725 | $version = wp_kses( trim( $version[1] ), $allowed_tags ); |
| 726 | else |
| 727 | $version = ''; |
| 728 | |
| 729 | $name = wp_kses( trim( $field_name[1] ), $allowed_tags ); |
| 730 | $description = wptexturize( wp_kses( trim( $description[1] ), $allowed_tags ) ); |
| 731 | $types = split( ",", wptexturize( wp_kses( trim( $types[1] ), $allowed_tags ) ) ); |
| 732 | |
| 733 | if ( preg_match( '|Author:(.*)$|mi', $field_data, $author_name ) ) { |
| 734 | if ( empty( $author_uri ) ) { |
| 735 | $author = wp_kses( trim( $author_name[1] ), $allowed_tags ); |
| 736 | } else { |
| 737 | $author = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $author_uri, __( 'Visit author homepage' ), |
| 738 | wp_kses( trim( $author_name[1] ), $allowed_tags ) ); |
| 739 | } |
| 740 | } else { |
| 741 | $author = __('Anonymous'); |
| 742 | } |
| 743 | |
| 744 | return array( 'Name' => $name, 'URI' => $uri, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Types' => $types); |
| 745 | } |
| 746 | |