Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/03/2012 02:28:05 AM (14 years ago)
Author:
johnjamesjacoby
Message:

XProfile:

  • Allow options to be sorted.
  • Escape all the things.
  • Props humanshell.
  • Fixes #3778.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r6259 r6294  
    381381
    382382                        <div id="poststuff">
    383                                 <form action="<?php echo esc_attr( $action ); ?>" method="post">
     383                                <form action="<?php echo esc_erl( $action ); ?>" method="post">
    384384                                        <div id="titlediv">
    385385                                                <h3><label for="group_name"><?php _e( "Field Group Title", 'buddypress') ?> *</label></h3>
     
    737737                        ?>
    738738
    739                         <div id="<?php echo $type; ?>" class="options-box" style="<?php echo $class; ?> margin-left: 15px;">
     739                        <div id="<?php echo esc_attr( $type ); ?>" class="options-box" style="<?php echo esc_attr( $class ); ?> margin-left: 15px;">
    740740                                <h4><?php _e( 'Please enter options for this Field:', 'buddypress' ); ?></h4>
    741                                 <p><label for="sort_order_<?php echo $type; ?>"><?php _e( 'Order By:', 'buddypress' ); ?></label>
    742                                         <select name="sort_order_<?php echo $type; ?>" id="sort_order_<?php echo $type; ?>" >
    743                                                 <option value="default" <?php if ( 'default' == $this->order_by ) {?> selected="selected"<?php } ?> ><?php _e( 'Order Entered', 'buddypress' ); ?></option>
    744                                                 <option value="asc" <?php if ( 'asc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Ascending', 'buddypress' ); ?></option>
    745                                                 <option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Descending', 'buddypress' ); ?></option>
     741                                <p>
     742                                        <label for="sort_order_<?php echo esc_attr( $type ); ?>"><?php _e( 'Sort Order:', 'buddypress' ); ?></label>
     743                                        <select name="sort_order_<?php echo esc_attr( $type ); ?>" id="sort_order_<?php echo esc_attr( $type ); ?>" >
     744                                                <option value="custom" <?php selected( 'custom', $this->order_by ); ?>><?php _e( 'Custom',     'buddypress' ); ?></option>
     745                                                <option value="asc"    <?php selected( 'asc',    $this->order_by ); ?>><?php _e( 'Ascending',  'buddypress' ); ?></option>
     746                                                <option value="desc"   <?php selected( 'desc',   $this->order_by ); ?>><?php _e( 'Descending', 'buddypress' ); ?></option>
    746747                                        </select>
    747748
     
    767768                                                        $default_name = '[' . $j . ']'; ?>
    768769
    769                                                 <p><?php _e( 'Option', 'buddypress' ); ?> <?php echo $j; ?>:
    770                                                    <input type="text" name="<?php echo $type; ?>_option[<?php echo $j; ?>]" id="<?php echo $type; ?>_option<?php echo $j; ?>" value="<?php echo stripslashes( esc_attr( $options[$i]->name ) ); ?>" />
    771                                                    <input type="<?php echo $default_input; ?>" name="isDefault_<?php echo $type; ?>_option<?php echo $default_name; ?>" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?> " value="<?php echo $j; ?>" /> <?php _e( 'Default Value', 'buddypress' ); ?>
    772 
    773                                                         <?php if ( $j != 1 && $options[$i]->id != -1 ) : ?>
    774 
    775                                                                 <a href="admin.php?page=bp-profile-setup&amp;mode=delete_option&amp;option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id; ?>">[x]</a>
    776 
    777                                                         <?php endif; ?>
    778 
     770                                                <p class="sortable">
     771                                                        <span>&nbsp;&Xi;&nbsp;</span>
     772                                                        <input type="text" name="<?php echo esc_attr( $type ); ?>_option[<?php echo esc_attr( $j ); ?>]" id="<?php echo esc_attr( $type ); ?>_option<?php echo esc_attr( $j ); ?>" value="<?php echo stripslashes( esc_attr( $options[$i]->name ) ); ?>" />
     773                                                        <input type="<?php echo $default_input; ?>" name="isDefault_<?php echo esc_attr( $type ); ?>_option<?php echo esc_attr( $default_name ); ?>" <?php checked( (int) $options[$i]->is_default_option, true ); ?> value="<?php echo esc_attr( $j ); ?>" />
     774                                                        <span><?php _e( 'Default Value', 'buddypress' ); ?></span>
     775                                                        <a href="<?php echo esc_url( 'admin.php?page=bp-profile-setup&amp;mode=delete_option&amp;option_id=' . $options[$i]->id ); ?>" class="ajax-option-delete" id="delete-<?php echo esc_attr( $options[$i]->id ); ?>">[x]</a>
    779776                                                </p>
    780777
    781778                                        <?php } /* end for */ ?>
    782779
    783                                         <input type="hidden" name="<?php echo $type; ?>_option_number" id="<?php echo $type; ?>_option_number" value="<?php echo $j + 1; ?>" />
     780                                        <input type="hidden" name="<?php echo esc_attr( $type ); ?>_option_number" id="<?php echo esc_attr( $type ); ?>_option_number" value="<?php echo esc_attr( (int) $j + 1 ); ?>" />
    784781
    785782                                <?php } else {
     
    788785                                                $default_name = '[1]'; ?>
    789786
    790                                         <p><?php _e( 'Option', 'buddypress' ); ?> 1: <input type="text" name="<?php echo $type; ?>_option[1]" id="<?php echo $type; ?>_option1" />
    791                                         <input type="<?php echo $default_input; ?>" name="isDefault_<?php echo $type; ?>_option<?php echo $default_name; ?>" id="isDefault_<?php echo $type; ?>_option" value="1" /> <?php _e( 'Default Value', 'buddypress' ); ?>
    792                                         <input type="hidden" name="<?php echo $type; ?>_option_number" id="<?php echo $type; ?>_option_number" value="2" />
     787                                        <p class="sortable">
     788                                                <span>&nbsp;&Xi;&nbsp;</span>
     789                                                <input type="text" name="<?php echo esc_attr( $type ); ?>_option[1]" id="<?php echo esc_attr( $type ); ?>_option1" />
     790                                                <input type="<?php echo esc_attr( $default_input ); ?>" name="isDefault_<?php echo esc_attr( $type ); ?>_option<?php echo esc_attr( $default_name ); ?>" id="isDefault_<?php echo esc_attr( $type ); ?>_option" value="1" />
     791                                                <span><?php _e( 'Default Value', 'buddypress' ); ?></span>
     792                                                <input type="hidden" name="<?php echo esc_attr( $type ); ?>_option_number" id="<?php echo esc_attr( $type ); ?>_option_number" value="2" />
     793                                        </p>
    793794
    794795                                <?php } /* end if */ ?>
    795796
    796                                 <div id="<?php echo $type; ?>_more"></div>
    797                                 <p><a href="javascript:add_option('<?php echo $type; ?>')"><?php _e('Add Another Option', 'buddypress'); ?></a></p>
     797                                <div id="<?php echo esc_attr( $type ); ?>_more"></div>
     798                                <p><a href="javascript:add_option('<?php echo esc_attr( $type ); ?>')"><?php _e( 'Add Another Option', 'buddypress' ); ?></a></p>
    798799                        </div>
    799800
     
    803804        function render_admin_form( $message = '' ) {
    804805                if ( empty( $this->id ) ) {
    805                         $title                          = __( 'Add Field', 'buddypress' );
    806                         $action                         = "admin.php?page=bp-profile-setup&amp;group_id=" . $this->group_id . "&amp;mode=add_field#tabs-" . $this->group_id;
     806                        $title  = __( 'Add Field', 'buddypress' );
     807                        $action = "admin.php?page=bp-profile-setup&amp;group_id=" . $this->group_id . "&amp;mode=add_field#tabs-" . $this->group_id;
    807808
    808809                        if ( !empty( $_POST['saveField'] ) ) {
    809                                 $this->name        = $_POST['title'];
     810                                $this->name        = $_POST['title'];
    810811                                $this->description = $_POST['description'];
    811812                                $this->is_required = $_POST['required'];
     
    821822                <div class="wrap">
    822823                        <div id="icon-users" class="icon32"><br /></div>
    823                         <h2><?php echo $title; ?></h2>
     824                        <h2><?php echo esc_html( $title ); ?></h2>
    824825                        <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p>
    825826
     
    827828
    828829                                <div id="message" class="error fade">
    829                                         <p><?php echo $message; ?></p>
     830                                        <p><?php echo esc_html( $message ); ?></p>
    830831                                </div>
    831832
    832833                        <?php endif; ?>
    833834
    834                         <form action="<?php echo $action; ?>" method="post">
     835                        <form action="<?php echo esc_url( $action ); ?>" method="post">
    835836                                <div id="poststuff">
    836837                                        <div id="titlediv">
     
    844845                                                <h3><label for="description"><?php _e("Field Description", 'buddypress'); ?></label></h3>
    845846                                                <div id="titlewrap">
    846                                                         <textarea name="description" id="description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea>
     847                                                        <textarea name="description" id="description" rows="8" cols="60"><?php echo esc_textarea( $this->description ); ?></textarea>
    847848                                                </div>
    848849                                        </div>
    849850
    850                                         <?php if ( '0' != $this->can_delete ) { ?>
     851                                        <?php if ( '0' != $this->can_delete ) : ?>
    851852
    852853                                                <div id="titlediv">
    853854                                                        <h3><label for="required"><?php _e( "Is This Field Required?", 'buddypress' ); ?> *</label></h3>
    854855                                                        <select name="required" id="required" style="width: 30%">
    855                                                                 <option value="0"<?php if ( $this->is_required == '0' ) { ?> selected="selected"<?php } ?>><?php _e( 'Not Required', 'buddypress' ); ?></option>
    856                                                                 <option value="1"<?php if ( $this->is_required == '1' ) { ?> selected="selected"<?php } ?>><?php _e( 'Required', 'buddypress' ); ?></option>
     856                                                                <option value="0"<?php selected( $this->is_required, '0' ); ?>><?php _e( 'Not Required', 'buddypress' ); ?></option>
     857                                                                <option value="1"<?php selected( $this->is_required, '1' ); ?>><?php _e( 'Required',    'buddypress' ); ?></option>
    857858                                                        </select>
    858859                                                </div>
    859860
    860861                                                <div id="titlediv">
    861                                                         <h3><label for="fieldtype"><?php _e("Field Type", 'buddypress'); ?> *</label></h3>
     862                                                        <h3><label for="fieldtype"><?php _e( 'Field Type', 'buddypress'); ?> *</label></h3>
    862863                                                        <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)" style="width: 30%">
    863                                                                 <option value="textbox"<?php if ( $this->type == 'textbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Text Box', 'buddypress' ); ?></option>
    864                                                                 <option value="textarea"<?php if ( $this->type == 'textarea' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi-line Text Box', 'buddypress' ); ?></option>
    865                                                                 <option value="datebox"<?php if ( $this->type == 'datebox' ) {?> selected="selected"<?php } ?>><?php _e( 'Date Selector', 'buddypress' ); ?></option>
    866                                                                 <option value="radio"<?php if ( $this->type == 'radio' ) {?> selected="selected"<?php } ?>><?php _e( 'Radio Buttons', 'buddypress' ); ?></option>
    867                                                                 <option value="selectbox"<?php if ( $this->type == 'selectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Drop Down Select Box', 'buddypress' ); ?></option>
    868                                                                 <option value="multiselectbox"<?php if ( $this->type == 'multiselectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi Select Box', 'buddypress' ); ?></option>
    869                                                                 <option value="checkbox"<?php if ( $this->type == 'checkbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Checkboxes', 'buddypress' ); ?></option>
     864                                                                <option value="textbox"        <?php selected( $this->type, 'textbox'        ); ?>><?php _e( 'Text Box',            'buddypress' ); ?></option>
     865                                                                <option value="textarea"       <?php selected( $this->type, 'textarea'       ); ?>><?php _e( 'Multi-line Text Box', 'buddypress' ); ?></option>
     866                                                                <option value="datebox"        <?php selected( $this->type, 'datebox'        ); ?>><?php _e( 'Date Selector',        'buddypress' ); ?></option>
     867                                                                <option value="radio"          <?php selected( $this->type, 'radio'          ); ?>><?php _e( 'Radio Buttons',        'buddypress' ); ?></option>
     868                                                                <option value="selectbox"      <?php selected( $this->type, 'selectbox'      ); ?>><?php _e( 'Drop Down Select Box', 'buddypress' ); ?></option>
     869                                                                <option value="multiselectbox" <?php selected( $this->type, 'multiselectbox' ); ?>><?php _e( 'Multi Select Box',    'buddypress' ); ?></option>
     870                                                                <option value="checkbox"       <?php selected( $this->type, 'checkbox'       ); ?>><?php _e( 'Checkboxes',          'buddypress' ); ?></option>
    870871                                                        </select>
    871872                                                </div>
     
    875876                                                <?php $this->render_admin_form_children(); ?>
    876877
    877                                         <?php } else { ?>
    878 
    879                                                 <input type="hidden" name="required" id="required" value="1" />
     878                                        <?php else : ?>
     879
     880                                                <input type="hidden" name="required"  id="required"  value="1"      />
    880881                                                <input type="hidden" name="fieldtype" id="fieldtype" value="textbox" />
    881882
    882                                         <?php } ?>
    883 
    884                                         <?php /* The fullname field cannot be hidden */ ?>
    885                                         <?php if ( 1 != $this->id ) : ?>
     883                                        <?php endif;
     884
     885                                        /* The fullname field cannot be hidden */
     886                                        if ( 1 != $this->id ) : ?>
    886887
    887888                                                <div id="titlediv">
    888 
    889889                                                        <div id="titlewrap">
    890                                                                 <h3><label for="default-visibility"><?php _e( "Default Visibility", 'buddypress' ); ?></label></h3>
     890                                                                <h3><label for="default-visibility"><?php _e( 'Default Visibility', 'buddypress' ); ?></label></h3>
    891891                                                                <ul>
    892                                                                 <?php foreach( bp_xprofile_get_visibility_levels() as $level ) : ?>
    893                                                                         <li><input type="radio" name="default-visibility" value="<?php echo esc_attr( $level['id'] ) ?>" <?php checked( $this->default_visibility, $level['id'] ) ?>> <?php echo esc_html( $level['label'] ) ?></li>
    894                                                                 <?php endforeach ?>
     892
     893                                                                        <?php foreach( bp_xprofile_get_visibility_levels() as $level ) : ?>
     894
     895                                                                                <li><input type="radio" name="default-visibility" value="<?php echo esc_attr( $level['id'] ) ?>" <?php checked( $this->default_visibility, $level['id'] ); ?>> <?php echo esc_html( $level['label'] ) ?></li>
     896
     897                                                                        <?php endforeach ?>
     898
    895899                                                                </ul>
    896900                                                        </div>
    897901
    898902                                                        <div id="titlewrap">
    899                                                                 <h3><label for="allow-custom-visibility"><?php _e( "Per-Member Visibility", 'buddypress' ); ?></label></h3>
     903                                                                <h3><label for="allow-custom-visibility"><?php _e( 'Per-Member Visibility', 'buddypress' ); ?></label></h3>
    900904                                                                <ul>
    901                                                                         <li><input type="radio" name="allow-custom-visibility" value="allowed" <?php checked( $this->allow_custom_visibility, 'allowed' ) ?>> <?php _e( "Let members change the this field's visibility", 'buddypress' ) ?></li>
    902 
    903                                                                         <li><input type="radio" name="allow-custom-visibility" value="disabled" <?php checked( $this->allow_custom_visibility, 'disabled' ) ?>> <?php _e( 'Enforce the default visibility for all members', 'buddypress' ) ?></li>
     905                                                                        <li><input type="radio" name="allow-custom-visibility" value="allowed"  <?php checked( $this->allow_custom_visibility, 'allowed'  ); ?>> <?php _e( "Let members change the this field's visibility", 'buddypress' ); ?></li>
     906                                                                        <li><input type="radio" name="allow-custom-visibility" value="disabled" <?php checked( $this->allow_custom_visibility, 'disabled' ); ?>> <?php _e( 'Enforce the default visibility for all members', 'buddypress' ); ?></li>
    904907                                                                </ul>
    905908                                                        </div>
     
    958961
    959962        function __construct( $field_id = null, $user_id = null ) {
    960                 if ( !empty( $field_id ) )
     963                if ( !empty( $field_id ) ) {
    961964                        $this->populate( $field_id, $user_id );
     965                }
    962966        }
    963967
     
    10711075
    10721076                if ( !empty( $results ) ) {
    1073                         $profile_data['user_login']             = $results[0]->user_login;
    1074                         $profile_data['user_nicename']  = $results[0]->user_nicename;
    1075                         $profile_data['user_email']             = $results[0]->user_email;
     1077                        $profile_data['user_login']    = $results[0]->user_login;
     1078                        $profile_data['user_nicename'] = $results[0]->user_nicename;
     1079                        $profile_data['user_email']    = $results[0]->user_email;
    10761080
    10771081                        foreach( (array) $results as $field ) {
     
    11371141                if ( is_array( $fields ) ) {
    11381142                        for ( $i = 0, $count = count( $fields ); $i < $count; ++$i ) {
    1139                                 if ( $i == 0 )
     1143                                if ( $i == 0 ) {
    11401144                                        $field_sql .= $wpdb->prepare( "AND ( f.name = %s ", $fields[$i] );
    1141                                 else
     1145                                } else {
    11421146                                        $field_sql .= $wpdb->prepare( "OR f.name = %s ", $fields[$i] );
     1147                                }
    11431148                        }
    11441149
     
    11581163                        for ( $i = 0, $count = count( $values ); $i < $count; ++$i ) {
    11591164                                for ( $j = 0; $j < count( $fields ); $j++ ) {
    1160                                         if ( $values[$i]->name == $fields[$j] )
     1165                                        if ( $values[$i]->name == $fields[$j] ) {
    11611166                                                $new_values[$fields[$j]] = $values[$i]->value;
    1162                                         else if ( !array_key_exists( $fields[$j], $new_values ) )
     1167                                        } else if ( !array_key_exists( $fields[$j], $new_values ) ) {
    11631168                                                $new_values[$fields[$j]] = NULL;
     1169                                        }
    11641170                                }
    11651171                        }
     
    12091215
    12101216                $field_name = bp_xprofile_fullname_field_name();
    1211 
    1212                 $data = xprofile_get_field_data( $field_name, $user_id );
     1217                $data       = xprofile_get_field_data( $field_name, $user_id );
    12131218
    12141219                return $data[$field_name];
    12151220        }
    12161221}
    1217 
    1218 ?>
Note: See TracChangeset for help on using the changeset viewer.