Skip to:
Content

BuddyPress.org

Changeset 2798


Ignore:
Timestamp:
03/03/2010 06:53:59 AM (16 years ago)
Author:
johnjamesjacoby
Message:

Allow xprofile field groups to be reordered. Also swept through xprofile files and cleaned up code formatting.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile.php

    r2797 r2798  
    11<?php
    2 define ( 'BP_XPROFILE_DB_VERSION', '1850' );
     2define ( 'BP_XPROFILE_DB_VERSION', '1950' );
    33
    44/* Define the slug for the component */
     
    3838                          name varchar(150) NOT NULL,
    3939                          description mediumtext NOT NULL,
     40                          group_order bigint(20) NOT NULL DEFAULT '0',
    4041                          can_delete tinyint(1) NOT NULL,
    4142                          KEY can_delete (can_delete)
     
    8687
    8788        require_once( ABSPATH . 'wp-admin/upgrade-functions.php' );
    88         dbDelta($sql);
     89        dbDelta( $sql );
    8990
    9091        do_action( 'xprofile_install' );
     
    153154
    154155        /* Add the administration tab under the "Site Admin" tab for site administrators */
    155         add_submenu_page( 'bp-general-settings', __("Profile Field Setup", 'buddypress'), __("Profile Field Setup", 'buddypress'), 'manage_options', 'bp-profile-setup', "xprofile_admin" );
     156        add_submenu_page( 'bp-general-settings', __( 'Profile Field Setup', 'buddypress' ), __( 'Profile Field Setup', 'buddypress' ), 'manage_options', 'bp-profile-setup', 'xprofile_admin' );
    156157
    157158        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
     
    215216        /* Don't show this menu to non site admins or if you're viewing your own profile */
    216217        if ( !is_site_admin() || bp_is_my_profile() )
    217                 return false;
    218         ?>
     218                return false; ?>
     219
    219220        <li id="bp-adminbar-adminoptions-menu">
    220221                <a href=""><?php _e( 'Admin Options', 'buddypress' ) ?></a>
     
    223224                        <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/edit/"><?php printf( __( "Edit %s's Profile", 'buddypress' ), attribute_escape( $bp->displayed_user->fullname ) ) ?></a></li>
    224225                        <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/change-avatar/"><?php printf( __( "Edit %s's Avatar", 'buddypress' ), attribute_escape( $bp->displayed_user->fullname ) ) ?></a></li>
    225 
    226                         <?php if ( !bp_core_is_user_spammer( $bp->displayed_user->id ) ) : ?>
    227                                 <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/mark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Mark as Spammer", 'buddypress' ) ?></a></li>
    228                         <?php else : ?>
    229                                 <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/unmark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Not a Spammer", 'buddypress' ) ?></a></li>
    230                         <?php endif; ?>
     226<?php if ( !bp_core_is_user_spammer( $bp->displayed_user->id ) ) : ?>
     227
     228                        <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/mark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Mark as Spammer", 'buddypress' ) ?></a></li>
     229<?php else : ?>
     230
     231                        <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/unmark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Not a Spammer", 'buddypress' ) ?></a></li>
     232<?php endif; ?>
    231233
    232234                        <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/delete-user/', 'delete-user' ) ?>" class="confirm"><?php printf( __( "Delete %s", 'buddypress' ), attribute_escape( $bp->displayed_user->fullname ) ) ?></a></li>
    233 
    234                         <?php do_action( 'xprofile_adminbar_menu_items' ) ?>
     235<?php do_action( 'xprofile_adminbar_menu_items' ) ?>
     236
    235237                </ul>
    236238        </li>
    237         <?php
     239<?php
    238240}
    239241add_action( 'bp_adminbar_menus', 'xprofile_setup_adminbar_menu', 20 );
     
    578580        $field_group = new BP_XProfile_Group( $field_group_id );
    579581        return $field_group->delete();
     582}
     583
     584function xprofile_update_field_group_position( $field_group_id, $position ) {
     585        return BP_XProfile_Group::update_position( $field_group_id, $position );
    580586}
    581587
     
    851857
    852858function xprofile_update_field_position( $field_id, $position ) {
    853         return BP_XProfile_Field::update_position( $field_id, $position);
     859        return BP_XProfile_Field::update_position( $field_id, $position );
    854860}
    855861
     
    953959        BP_XProfile_ProfileData::delete_data_for_user( $user_id );
    954960
    955         // delete any avatar files.
     961        /* delete any avatar files. */
    956962        @unlink( get_usermeta( $user_id, 'bp_core_avatar_v1_path' ) );
    957963        @unlink( get_usermeta( $user_id, 'bp_core_avatar_v2_path' ) );
    958964
    959         // unset the usermeta for avatars from the usermeta table.
     965        /* unset the usermeta for avatars from the usermeta table. */
    960966        delete_usermeta( $user_id, 'bp_core_avatar_v1' );
    961967        delete_usermeta( $user_id, 'bp_core_avatar_v1_path' );
     
    9951001}
    9961002
    997 // List actions to clear object caches on
     1003/* List actions to clear object caches on */
    9981004add_action( 'xprofile_groups_deleted_group', 'xprofile_clear_profile_groups_object_cache' );
    9991005add_action( 'xprofile_groups_saved_group', 'xprofile_clear_profile_groups_object_cache' );
    10001006add_action( 'xprofile_updated_profile', 'xprofile_clear_profile_data_object_cache' );
    10011007
    1002 // List actions to clear super cached pages on, if super cache is installed
     1008/* List actions to clear super cached pages on, if super cache is installed */
    10031009add_action( 'xprofile_updated_profile', 'bp_core_clear_cache' );
    10041010
  • trunk/bp-xprofile/admin/css/admin.css

    r1798 r2798  
     1
     2div.sortable {
     3        margin-bottom: 20px;
     4}
     5
     6table.field-group {
     7        margin-bottom: 20px;
     8}
     9table.field-group.ui-sortable-helper {
     10        filter: alpha(opacity=50);
     11        opacity: 0.5;
     12}
     13table.field-group.ui-sortable-placeholder {
     14        border: 2px dashed #ddd;
     15        visibility: visible !important;
     16        margin-bottom: 22px;
     17        background-color: transparent;
     18}
     19
     20table.field-group thead tr.grabber {
     21        cursor: move;
     22}
     23
    124table.field-group tbody {
    225        cursor: move;
  • trunk/bp-xprofile/admin/js/admin.js

    r1977 r2798  
    3737       
    3838        toDeleteText = document.createTextNode('[x]');
     39
    3940        toDelete.setAttribute('href',"javascript:hide('" + forWhat + '_div' + theId + "')");
    40        
    4141        toDelete.setAttribute('class','delete');
    42 
    4342        toDelete.appendChild(toDeleteText);
    4443
     
    5049        newDiv.appendChild(toDelete);   
    5150        holder.appendChild(newDiv);
    52        
    5351       
    5452        theId++
     
    6260        document.getElementById("checkbox").style.display = "none";
    6361       
    64         if(forWhat == "radio") {
     62        if(forWhat == "radio")
    6563                document.getElementById("radio").style.display = "";
    66         }
    6764       
    68         if(forWhat == "selectbox") {
     65        if(forWhat == "selectbox")
    6966                document.getElementById("selectbox").style.display = "";                                               
    70         }
    7167       
    72         if(forWhat == "multiselectbox") {
     68        if(forWhat == "multiselectbox")
    7369                document.getElementById("multiselectbox").style.display = "";                                           
    74         }
    7570       
    76         if(forWhat == "checkbox") {
     71        if(forWhat == "checkbox")
    7772                document.getElementById("checkbox").style.display = "";                                         
    78         }
    7973}
    8074
    8175function hide(id) {
    82         if ( !document.getElementById(id) ) return false;
     76        if ( !document.getElementById(id) ) return;
    8377       
    8478        document.getElementById(id).style.display = "none";
     
    8680}
    8781
    88 // Set up deleting options ajax
     82/* Set up deleting options ajax */
    8983jQuery(document).ready( function() {
    90        
    9184        jQuery("a.ajax-option-delete").click(
    9285                function() {
     
    9891                                'cookie': encodeURIComponent(document.cookie),
    9992                                '_wpnonce': jQuery("input#_wpnonce").val(),
    100                                
    10193                                'option_id': theId
    10294                        },
    103                         function(response)
    104                         {});
     95                        function(response){});
    10596                }
    106         );                             
     97        );
    10798});
    10899
     
    115106
    116107jQuery(document).ready( function() {
     108        jQuery("form#profile-field-form div#field-groups").sortable( {
     109                cursor: 'move',
     110                axis: 'y',
     111                helper: fixHelper,
     112                distance: 1,
     113                cancel: 'table.nodrag',
     114                update: function() {
     115                        jQuery.post( ajaxurl, {
     116                                action: 'xprofile_reorder_groups',
     117                                'cookie': encodeURIComponent(document.cookie),
     118                                '_wpnonce_reorder_groups': jQuery("input#_wpnonce_reorder_groups").val(),
     119                                'group_order': jQuery(this).sortable('serialize')
     120                        },
     121                        function(response){});
     122                }
     123        });
     124
    117125        jQuery("table.field-group tbody").sortable( {
    118126                cursor: 'move',
     
    126134                                'cookie': encodeURIComponent(document.cookie),
    127135                                '_wpnonce_reorder_fields': jQuery("input#_wpnonce_reorder_fields").val(),
    128                                
    129136                                'field_order': jQuery(this).sortable('serialize')
    130137                        },
    131                         function(response)
    132                         {});
    133 
     138                        function(response){});
    134139                }
    135140        });
  • trunk/bp-xprofile/bp-xprofile-admin.php

    r2625 r2798  
    11<?php
    2 
    32
    43/**************************************************************************
     
    1615        $groups = BP_XProfile_Group::get( array(
    1716                'fetch_fields' => true
    18         ) );
    19 
    20         if ( isset($_GET['mode']) && isset($_GET['group_id']) && 'add_field' == $_GET['mode'] ) {
    21                 xprofile_admin_manage_field($_GET['group_id']);
    22         } else if ( isset($_GET['mode']) && isset($_GET['group_id']) && isset($_GET['field_id']) && 'edit_field' == $_GET['mode'] ) {
    23                 xprofile_admin_manage_field($_GET['group_id'], $_GET['field_id']);
    24         } else if ( isset($_GET['mode']) && isset($_GET['field_id']) && 'delete_field' == $_GET['mode'] ) {
     17        ));
     18
     19        if ( isset( $_GET['mode'] ) && isset( $_GET['group_id'] ) && 'add_field' == $_GET['mode'] )
     20                xprofile_admin_manage_field( $_GET['group_id'] );
     21
     22        else if ( isset( $_GET['mode'] ) && isset( $_GET['group_id'] ) && isset( $_GET['field_id'] ) && 'edit_field' == $_GET['mode'] )
     23                xprofile_admin_manage_field($_GET['group_id'], $_GET['field_id'] );
     24
     25        else if ( isset( $_GET['mode'] ) && isset( $_GET['field_id'] ) && 'delete_field' == $_GET['mode'] )
    2526                xprofile_admin_delete_field($_GET['field_id'], 'field');
    26         } else if ( isset($_GET['mode']) && isset($_GET['option_id']) && 'delete_option' == $_GET['mode'] ) {
    27                 xprofile_admin_delete_field($_GET['option_id'], 'option');
    28         } else if ( isset($_GET['mode']) && 'add_group' == $_GET['mode'] ) {
     27
     28        else if ( isset( $_GET['mode'] ) && isset( $_GET['option_id'] ) && 'delete_option' == $_GET['mode'] )
     29                xprofile_admin_delete_field( $_GET['option_id'], 'option' );
     30
     31        else if ( isset( $_GET['mode'] ) && 'add_group' == $_GET['mode'] )
    2932                xprofile_admin_manage_group();
    30         } else if ( isset($_GET['mode']) && isset($_GET['group_id']) && 'delete_group' == $_GET['mode'] ) {
    31                 xprofile_admin_delete_group($_GET['group_id']);
    32         } else if ( isset($_GET['mode']) && isset($_GET['group_id']) && 'edit_group' == $_GET['mode'] ) {
    33                 xprofile_admin_manage_group($_GET['group_id']);
    34         } else {
     33
     34        else if ( isset( $_GET['mode'] ) && isset( $_GET['group_id'] ) && 'delete_group' == $_GET['mode'] )
     35                xprofile_admin_delete_group( $_GET['group_id'] );
     36
     37        else if ( isset( $_GET['mode'] ) && isset( $_GET['group_id'] ) && 'edit_group' == $_GET['mode'] )
     38                xprofile_admin_manage_group( $_GET['group_id'] );
     39
     40        else {
    3541?>
    3642        <div class="wrap">
    37 
    3843                <h2><?php _e( 'Profile Field Setup', 'buddypress') ?></h2>
    39                 <br />
    4044                <p><?php _e( 'Your users will distinguish themselves through their profile page. You must give them profile fields that allow them to describe themselves in a way that is relevant to the theme of your social network.', 'buddypress') ?></p>
    4145                <p><?php _e('NOTE: Any fields in the first group will appear on the signup page.', 'buddypress'); ?></p>
    4246
    4347                <form action="" id="profile-field-form" method="post">
    44 
    4548                        <?php wp_nonce_field( 'bp_reorder_fields', '_wpnonce_reorder_fields' ); ?>
    4649
    47                         <?php
    48                                 if ( $message != '' ) {
    49                                         $type = ( $type == 'error' ) ? 'error' : 'updated';
    50                         ?>
     50                        <?php wp_nonce_field( 'bp_reorder_groups', '_wpnonce_reorder_groups', false );
     51
     52                        if ( $message != '' ) :
     53                                $type = ( $type == 'error' ) ? 'error' : 'updated';
     54?>
     55
    5156                                <div id="message" class="<?php echo $type; ?> fade">
    5257                                        <p><?php echo wp_specialchars( attribute_escape( $message ) ); ?></p>
    5358                                </div>
    54                         <?php }
    55 
    56                         if ( $groups ) { ?>
    57                                 <?php
    58                                 for ( $i = 0; $i < count($groups); $i++ ) { // TODO: foreach
    59                                 ?>
    60                                         <p>
    61                                         <table id="group_<?php echo $groups[$i]->id;?>" class="widefat field-group">
    62                                                 <thead>
    63                                                     <tr>
    64                                                                 <th scope="col" width="10">&nbsp;</th>
    65                                                         <th scope="col" colspan="<?php if ( $groups[$i]->can_delete ) { ?>3<?php } else { ?>5<?php } ?>"><?php echo attribute_escape( $groups[$i]->name ); ?></th>
    66                                                                 <?php if ( $groups[$i]->can_delete ) { ?>
    67                                                                         <th scope="col"><a class="edit" href="admin.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=<?php echo attribute_escape( $groups[$i]->id ); ?>"><?php _e( 'Edit', 'buddypress' ) ?></a></th>
    68                                                                 <th scope="col"><a class="delete" href="admin.php?page=bp-profile-setup&amp;mode=delete_group&amp;group_id=<?php echo attribute_escape( $groups[$i]->id ); ?>"><?php _e( 'Delete', 'buddypress' ) ?></a></th>
    69                                                                 <?php } ?>
    70                                                         </tr>
    71                                                         <tr class="header">
    72                                                                 <td>&nbsp;</td>
    73                                                         <td><?php _e( 'Field Name', 'buddypress' ) ?></td>
    74                                                         <td width="14%"><?php _e( 'Field Type', 'buddypress' ) ?></td>
    75                                                         <td width="6%"><?php _e( 'Required?', 'buddypress' ) ?></td>
    76                                                         <td colspan="2" width="10%" style="text-align:center;"><?php _e( 'Action', 'buddypress' ) ?></td>
    77                                                     </tr>
    78                                                 </thead>
    79                                                 <tbody id="the-list">
    80 
    81                                                   <?php if ( $groups[$i]->fields ) { ?>
    82 
    83                                                         <?php for ( $j = 0; $j < count($groups[$i]->fields); $j++ ) { ?>
    84 
    85                                                                         <?php if ( 0 == $j % 2 ) { $class = ""; } else { $class = "alternate"; } ?>
    86                                                                         <?php $field = new BP_XProfile_Field($groups[$i]->fields[$j]->id); ?>
    87                                                                         <?php if ( !$field->can_delete ) { $class .= ' core'; } ?>
    88 
    89                                                                         <tr id="field_<?php echo attribute_escape( $field->id ); ?>" class="sortable<?php if ( $class ) { echo ' ' . $class; } ?>">
    90                                                                         <td width="10"><img src="<?php echo BP_PLUGIN_URL ?>/bp-xprofile/admin/images/move.gif" alt="<?php _e( 'Drag', 'buddypress' ) ?>" /></td>
    91                                                                                 <td><span title="<?php echo $field->description; ?>"><?php echo attribute_escape( $field->name ); ?> <?php if(!$field->can_delete) { ?> <?php _e( '(Core Field)', 'buddypress' ) ?><?php } ?></span></td>
    92                                                                         <td><?php echo attribute_escape( $field->type ); ?></td>
    93                                                                         <td style="text-align:center;"><?php if ( $field->is_required ) { echo '<img src="' . BP_PLUGIN_URL . '/bp-xprofile/admin/images/tick.gif" alt="' . __( 'Yes', 'buddypress' ) . '" />'; } else { ?>--<?php } ?></td>
    94                                                                         <td style="text-align:center;"><?php if ( !$field->can_delete ) { ?><strike><?php _e( 'Edit', 'buddypress' ) ?></strike><?php } else { ?><a class="edit" href="admin.php?page=bp-profile-setup&amp;group_id=<?php echo attribute_escape( $groups[$i]->id ); ?>&amp;field_id=<?php echo attribute_escape( $field->id ); ?>&amp;mode=edit_field"><?php _e( 'Edit', 'buddypress' ) ?></a><?php } ?></td>
    95                                                                         <td style="text-align:center;"><?php if ( !$field->can_delete ) { ?><strike><?php _e( 'Delete', 'buddypress' ) ?></strike><?php } else { ?><a class="delete" href="admin.php?page=bp-profile-setup&amp;field_id=<?php echo attribute_escape( $field->id ); ?>&amp;mode=delete_field"><?php _e( 'Delete', 'buddypress' ) ?></a><?php } ?></td>
    96                                                                     </tr>
    97 
    98                                                                 <?php } ?>
    99 
    100                                                         <?php } else { ?>
    101 
     59<?php           endif; ?>
     60
     61                        <div id="field-groups">
     62<?php
     63                        if ( $groups ) :
     64                                foreach ( $groups as $group ) { ?>
     65
     66                                                <table id="group_<?php echo $group->id;?>" class="widefat field-group sortable">
     67                                                        <thead>
     68                                                                <tr class="grabber">
     69                                                                        <th scope="col" width="10">&nbsp;</th>
     70                                                                        <th scope="col" colspan="<?php if ( $group->can_delete ) { ?>3<?php } else { ?>5<?php } ?>"><?php echo attribute_escape( $group->name ); ?></th>
     71<?php
     72                                                                        if ( $group->can_delete ) :
     73?>
     74                                                                                <th scope="col"><a class="edit" href="admin.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=<?php echo attribute_escape( $group->id ); ?>"><?php _e( 'Edit', 'buddypress' ) ?></a></th>
     75                                                                        <th scope="col"><a class="delete" href="admin.php?page=bp-profile-setup&amp;mode=delete_group&amp;group_id=<?php echo attribute_escape( $group->id ); ?>"><?php _e( 'Delete', 'buddypress' ) ?></a></th>
     76<?php
     77                                                                        endif;
     78?>
     79
     80                                                                </tr>
     81                                                                <tr class="header">
     82                                                                        <td>&nbsp;</td>
     83                                                                        <td><?php _e( 'Field Name', 'buddypress' ) ?></td>
     84                                                                        <td width="14%"><?php _e( 'Field Type', 'buddypress' ) ?></td>
     85                                                                        <td width="6%"><?php _e( 'Required?', 'buddypress' ) ?></td>
     86                                                                        <td colspan="2" width="10%" style="text-align:center;"><?php _e( 'Action', 'buddypress' ) ?></td>
     87                                                                </tr>
     88                                                        </thead>
     89
     90                                                        <tfoot>
    10291                                                                <tr class="nodrag">
    103                                                                         <td colspan="6"><?php _e( 'There are no fields in this group.', 'buddypress' ) ?></td>
     92                                                                        <td colspan="6"><a href="admin.php?page=bp-profile-setup&amp;group_id=<?php echo attribute_escape( $group->id ); ?>&amp;mode=add_field"><?php _e( 'Add New Field', 'buddypress' ) ?></a></td>
    10493                                                                </tr>
    105 
    106                                                         <?php } ?>
    107 
    108                                                 </tbody>
    109 
    110                                                 <tfoot>
    111 
    112                                                                 <tr class="nodrag">
    113                                                                         <td colspan="6"><a href="admin.php?page=bp-profile-setup&amp;group_id=<?php echo attribute_escape( $groups[$i]->id ); ?>&amp;mode=add_field"><?php _e( 'Add New Field', 'buddypress' ) ?></a></td>
    114                                                                 </tr>
    115 
    116                                                 </tfoot>
    117 
    118                                         </table>
    119                                         </p>
    120 
    121                                 <?php } /* End For */ ?>
    122 
     94                                                        </tfoot>
     95
     96                                                        <tbody id="the-list">
     97 <?php
     98                                                                if ( $group->fields ) :
     99                                                                        foreach ( $group->fields as $field ) {
     100                                                                                if ( 0 == $j % 2 )
     101                                                                                        $class = '';
     102                                                                                else
     103                                                                                        $class = 'alternate';
     104
     105                                                                                $field = new BP_XProfile_Field( $field->id );
     106                                                                                if ( !$field->can_delete )
     107                                                                                        $class .= ' core';
     108?>
     109
     110                                                                                <tr id="field_<?php echo attribute_escape( $field->id ); ?>" class="sortable<?php if ( $class ) { echo ' ' . $class; } ?>">
     111                                                                                        <td width="10"><img src="<?php echo BP_PLUGIN_URL ?>/bp-xprofile/admin/images/move.gif" alt="<?php _e( 'Drag', 'buddypress' ) ?>" /></td>
     112                                                                                        <td><span title="<?php echo $field->description; ?>"><?php echo attribute_escape( $field->name ); ?> <?php if(!$field->can_delete) { ?> <?php _e( '(Core Field)', 'buddypress' ) ?><?php } ?></span></td>
     113                                                                                        <td><?php echo attribute_escape( $field->type ); ?></td>
     114                                                                                        <td style="text-align:center;"><?php if ( $field->is_required ) { echo '<img src="' . BP_PLUGIN_URL . '/bp-xprofile/admin/images/tick.gif" alt="' . __( 'Yes', 'buddypress' ) . '" />'; } else { ?>--<?php } ?></td>
     115                                                                                        <td style="text-align:center;"><?php if ( !$field->can_delete ) { ?><strike><?php _e( 'Edit', 'buddypress' ) ?></strike><?php } else { ?><a class="edit" href="admin.php?page=bp-profile-setup&amp;group_id=<?php echo attribute_escape( $group->id ); ?>&amp;field_id=<?php echo attribute_escape( $field->id ); ?>&amp;mode=edit_field"><?php _e( 'Edit', 'buddypress' ) ?></a><?php } ?></td>
     116                                                                                        <td style="text-align:center;"><?php if ( !$field->can_delete ) { ?><strike><?php _e( 'Delete', 'buddypress' ) ?></strike><?php } else { ?><a class="delete" href="admin.php?page=bp-profile-setup&amp;field_id=<?php echo attribute_escape( $field->id ); ?>&amp;mode=delete_field"><?php _e( 'Delete', 'buddypress' ) ?></a><?php } ?></td>
     117                                                                                </tr>
     118<?php
     119                                                                        } /* end for */
     120
     121                                                                else : /* !$group->fields */
     122?>
     123
     124                                                                        <tr class="nodrag">
     125                                                                                <td colspan="6"><?php _e( 'There are no fields in this group.', 'buddypress' ) ?></td>
     126                                                                        </tr>
     127<?php
     128                                                                endif; /* end $group->fields */
     129?>
     130
     131                                                        </tbody>
     132                                                </table>
     133<?php
     134                                } /* End For */ ?>
     135                                        </div>
    123136                                        <p>
    124137                                                <a class="button" href="admin.php?page=bp-profile-setup&amp;mode=add_group"><?php _e( 'Add New Field Group', 'buddypress' ) ?></a>
    125138                                        </p>
    126 
    127                         <?php } else { ?>
     139<?php
     140                                else :
     141?>
     142
    128143                                <div id="message" class="error"><p><?php _e('You have no groups.', 'buddypress' ); ?></p></div>
    129144                                <p><a href="admin.php?page=bp-profile-setup&amp;mode=add_group"><?php _e( 'Add New Group', 'buddypress' ) ?></a></p>
    130                         <?php } ?>
     145<?php
     146                                endif;
     147?>
    131148
    132149                </form>
    133 
    134150        </div>
    135151<?php
    136152        }
    137153}
    138 
    139154
    140155/**************************************************************************
     
    184199        global $message, $type;
    185200
    186         $group = new BP_XProfile_Group($group_id);
     201        $group = new BP_XProfile_Group( $group_id );
    187202
    188203        if ( !$group->delete() ) {
    189                 $message = __('There was an error deleting the group. Please try again', 'buddypress');
     204                $message = __( 'There was an error deleting the group. Please try again', 'buddypress' );
    190205                $type = 'error';
    191206        } else {
    192                 $message = __('The group was deleted successfully.', 'buddypress');
     207                $message = __( 'The group was deleted successfully.', 'buddypress' );
    193208                $type = 'success';
    194209
     
    196211        }
    197212
    198         unset($_GET['mode']); // TODO: wtf?
     213        unset( $_GET['mode'] ); /* TODO: wtf? */
    199214        xprofile_admin( $message, $type );
    200215}
     
    293308                return false;
    294309
    295         parse_str($_POST['field_order'], $order );
    296 
    297         foreach ( (array) $order['field'] as $position => $field_id ) {
     310        parse_str( $_POST['field_order'], $order );
     311
     312        foreach ( (array) $order['field'] as $position => $field_id )
    298313                xprofile_update_field_position( (int) $field_id, (int) $position );
    299         }
     314
    300315}
    301316add_action( 'wp_ajax_xprofile_reorder_fields', 'xprofile_ajax_reorder_fields' );
     317
     318function xprofile_ajax_reorder_field_groups() {
     319        global $bp;
     320
     321        /* Check the nonce */
     322        check_admin_referer( 'bp_reorder_groups', '_wpnonce_reorder_groups' );
     323
     324        if ( empty( $_POST['group_order'] ) )
     325                return false;
     326
     327        parse_str( $_POST['group_order'], $order );
     328
     329        foreach ( (array) $order['group'] as $position => $field_group_id )
     330                xprofile_update_field_group_position( (int) $field_group_id, (int) $position );
     331
     332}
     333add_action( 'wp_ajax_xprofile_reorder_groups', 'xprofile_ajax_reorder_field_groups' );
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r2654 r2798  
    6161                        return false;
    6262
    63                 $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id );
    64 
    65                 if ( !$wpdb->query($sql) ) {
    66                         return false;
    67                 } else {
    68                         // Now the group is deleted, remove the group's fields.
    69                         if ( BP_XProfile_Field::delete_for_group($this->id) ) {
    70                                 // Now delete all the profile data for the groups fields
    71                                 for ( $i = 0; $i < count($this->fields); $i++ ) {
    72                                         BP_XProfile_ProfileData::delete_for_field($this->fields[$i]->id);
    73                                 }
     63                /* Delete field group */
     64                if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id ) ) ) {
     65                        return false;
     66                } else {
     67                        /* Remove the group's fields. */
     68                        if ( BP_XProfile_Field::delete_for_group( $this->id ) ) {
     69                                /* Remove profile data for the groups fields */
     70                                foreach ( $this->fields as $field )
     71                                        BP_XProfile_ProfileData::delete_for_field( $field->id );
     72
    7473                        }
    7574
     
    9897
    9998                if ( $hide_empty_groups )
    100                         $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$group_id_sql} ORDER BY g.id ASC" ) );
     99                        $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$group_id_sql} ORDER BY g.group_order ASC" ) );
    101100                else
    102                         $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g {$group_id_sql} ORDER BY g.id ASC" ) );
     101                        $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g {$group_id_sql} ORDER BY g.group_order ASC" ) );
    103102
    104103                if ( !$fetch_fields )
     
    154153                global $message;
    155154
    156                 // Validate Form
     155                /* Validate Form */
    157156                if ( empty( $_POST['group_name'] ) ) {
    158157                        $message = __('Please make sure you give the group a name.', 'buddypress');
     
    163162        }
    164163
    165         // ADMIN AREA HTML. TODO: Get this out of here.
     164        function update_position( $field_group_id, $position ) {
     165                global $wpdb, $bp;
     166
     167                if ( !is_numeric( $position ) )
     168                        return false;
     169
     170                return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET group_order = %d WHERE id = %d", $position, $field_group_id ) );
     171        }
     172
     173        /* ADMIN AREA HTML. TODO: Get this out of here. */
    166174
    167175        function render_admin_form() {
     
    175183                        $action = "admin.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=" . $this->id;
    176184                }
    177         ?>
     185?>
    178186                <div class="wrap">
    179187
     
    206214                </div>
    207215
    208                 <?php
     216<?php
    209217        }
    210218}
     
    230238
    231239        function bp_xprofile_field( $id = null, $user_id = null, $get_data = true ) {
    232                 if ( $id ) {
     240                if ( $id )
    233241                        $this->populate( $id, $user_id, $get_data );
    234                 }
    235242        }
    236243
     
    238245                global $wpdb, $userdata, $bp;
    239246
    240                 if ( is_null($user_id) ) {
     247                if ( is_null( $user_id ) )
    241248                        $user_id = $userdata->ID;
    242                 }
    243249
    244250                $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id );
    245251
    246                 if ( $field = $wpdb->get_row($sql) ) {
     252                if ( $field = $wpdb->get_row( $sql ) ) {
    247253                        $this->id = $field->id;
    248254                        $this->group_id = $field->group_id;
     
    258264                        $this->is_default_option = $field->is_default_option;
    259265
    260                         if ( $get_data ) {
     266                        if ( $get_data )
    261267                                $this->data = $this->get_field_data($user_id);
    262                         }
     268
    263269                }
    264270        }
     
    268274
    269275                if ( !$this->id ||
    270                         // Prevent deletion by url when can_delete is false.
     276                        /* Prevent deletion by url when can_delete is false. */
    271277                        !$this->can_delete ||
    272                         // Prevent deletion of option 1 since this invalidates fields with options.
     278                        /* Prevent deletion of option 1 since this invalidates fields with options. */
    273279                        ( $this->parent_id && $this->option_order == 1 ) )
    274280                        return false;
     
    277283                        return false;
    278284
    279                 // delete the data in the DB for this field
    280                 BP_XProfile_ProfileData::delete_for_field($this->id);
     285                /* delete the data in the DB for this field */
     286                BP_XProfile_ProfileData::delete_for_field( $this->id );
    281287
    282288                return true;
     
    300306
    301307                if ( $this->id != null )
    302                         $sql = $wpdb->prepare("UPDATE {$bp->profile->table_name_fields} SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, order_by = %s, field_order = %d WHERE id = %d", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->id);
     308                        $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, order_by = %s, field_order = %d WHERE id = %d", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->id);
    303309                else
    304                         $sql = $wpdb->prepare("INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order ) VALUES (%d, 0, %s, %s, %s, %d, %s, %d )", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order );
    305 
    306                 // Check for null so field options can be changed without changing any other part of the field.
    307                 // The described situation will return 0 here.
    308                 if ( $wpdb->query($sql) !== null ) {
     310                        $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order ) VALUES (%d, 0, %s, %s, %s, %d, %s, %d )", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order );
     311
     312                /*
     313                 * Check for null so field options can be changed without changing any other part of the field.
     314                 * The described situation will return 0 here.
     315                 */
     316                if ( $wpdb->query( $sql ) !== null ) {
    309317
    310318                        if ( $this->id )
     
    313321                                $field_id = $wpdb->insert_id;
    314322
    315                         // Only do this if we are editing an existing field
     323                        /* Only do this if we are editing an existing field */
    316324                        if ( $this->id != null ) {
    317                                 // Remove any radio or dropdown options for this
    318                                 // field. They will be re-added if needed.
    319                                 // This stops orphan options if the user changes a
    320                                 // field from a radio button field to a text box.
     325                                /*
     326                                 * Remove any radio or dropdown options for this
     327                                 * field. They will be re-added if needed.
     328                                 * This stops orphan options if the user changes a
     329                                 * field from a radio button field to a text box.
     330                                 */
    321331                                $this->delete_children();
    322332                        }
    323333
    324                         // Check to see if this is a field with child options.
    325                         // We need to add the options to the db, if it is.
     334                        /*
     335                         * Check to see if this is a field with child options.
     336                         * We need to add the options to the db, if it is.
     337                         */
    326338                        if ( 'radio' == $this->type || 'selectbox' == $this->type || 'checkbox' == $this->type || 'multiselectbox' == $this->type ) {
    327                                 if ( $this->id ) {
     339                                if ( $this->id )
    328340                                        $parent_id = $this->id;
    329                                 } else {
     341                                else
    330342                                        $parent_id = $wpdb->insert_id;
    331                                 }
    332343
    333344                                if ( 'radio' == $this->type ) {
    334 
    335345                                        $options = $_POST['radio_option'];
    336346                                        $defaults = $_POST['isDefault_radio_option'];
    337347
    338348                                } else if ( 'selectbox' == $this->type ) {
    339 
    340349                                        $options = $_POST['selectbox_option'];
    341350                                        $defaults = $_POST['isDefault_selectbox_option'];
    342351
    343352                                } else if ( 'multiselectbox' == $this->type ) {
    344 
    345353                                        $options = $_POST['multiselectbox_option'];
    346354                                        $defaults = $_POST['isDefault_multiselectbox_option'];
    347355
    348356                                } else if ( 'checkbox' == $this->type ) {
    349 
    350357                                        $options = $_POST['checkbox_option'];
    351358                                        $defaults = $_POST['isDefault_checkbox_option'];
     
    358365                                                $is_default = 0;
    359366
    360                                                 if ( is_array($defaults) ) {
    361                                                         if ( isset($defaults[$option_key]) )
     367                                                if ( is_array( $defaults ) ) {
     368                                                        if ( isset( $defaults[$option_key] ) )
    362369                                                                $is_default = 1;
    363370                                                } else {
     
    367374
    368375                                                if ( '' != $option_value ) {
    369                                                         if ( !$wpdb->query( $wpdb->prepare("INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default ) ) )
     376                                                        if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default ) ) )
    370377                                                                return false;
    371378                                                }
     
    387394        }
    388395
    389         function get_field_data($user_id) {
    390                 return new BP_XProfile_ProfileData($this->id, $user_id);
    391         }
    392 
    393          function get_children($for_editing = false) {
    394                 global $wpdb, $bp;
    395 
    396                 // This is done here so we don't have problems with sql injection
    397                 if ( 'asc' == $this->order_by && !$for_editing ) {
     396        function get_field_data( $user_id ) {
     397                return new BP_XProfile_ProfileData( $this->id, $user_id );
     398        }
     399
     400        function get_children( $for_editing = false ) {
     401                global $wpdb, $bp;
     402
     403                /* This is done here so we don't have problems with sql injection */
     404                if ( 'asc' == $this->order_by && !$for_editing )
    398405                        $sort_sql = 'ORDER BY name ASC';
    399                 } else if ( 'desc' == $this->order_by && !$for_editing ) {
     406                else if ( 'desc' == $this->order_by && !$for_editing )
    400407                        $sort_sql = 'ORDER BY name DESC';
    401                 } else {
     408                else
    402409                        $sort_sql = 'ORDER BY option_order ASC';
    403                 }
    404 
    405                 //This eliminates a problem with getting all fields when there is no id for the object
    406                 if ( !$this->id ) {
     410
     411                /* This eliminates a problem with getting all fields when there is no id for the object */
     412                if ( !$this->id )
    407413                        $parent_id = -1;
    408                 } else {
     414                else
    409415                        $parent_id = $this->id;
    410                 }
    411416
    412417                $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d AND group_id = %d $sort_sql", $parent_id, $this->group_id );
     
    426431        }
    427432
    428         // Static Functions
     433        /* Static Functions */
    429434
    430435        function get_type( $field_id ) {
     
    434439                        $sql = $wpdb->prepare( "SELECT type FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id );
    435440
    436                         if ( !$field_type = $wpdb->get_var($sql) )
     441                        if ( !$field_type = $wpdb->get_var( $sql ) )
    437442                                return false;
    438443
     
    449454                        $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id );
    450455
    451                         if ( $wpdb->get_var($sql) === false ) {
     456                        if ( $wpdb->get_var($sql) === false )
    452457                                return false;
    453                         }
    454458
    455459                        return true;
     
    477481        }
    478482
    479         // ADMIN AREA HTML. TODO: Get this out of here.
    480 
     483        /* ADMIN AREA HTML. TODO: Get this out of here. */
     484
     485        /* This function populates the items for radio buttons checkboxes and drop down boxes */
    481486        function render_admin_form_children() {
    482                 //This function populates the items for radio buttons checkboxes and drop down boxes
    483487                $input_types = array( 'checkbox', 'selectbox', 'multiselectbox', 'radio' );
    484488
     
    486490                        $default_name = '';
    487491
    488                         if ( 'multiselectbox' == $type || 'checkbox' == $type ) {
     492                        if ( 'multiselectbox' == $type || 'checkbox' == $type )
    489493                                $default_input = 'checkbox';
    490                         } else {
     494                        else
    491495                                $default_input = 'radio';
    492                         }
    493                 ?>
     496?>
    494497                        <div id="<?php echo $type ?>" class="options-box" style="<?php if ( $this->type != $type ) { ?>display: none;<?php } ?> margin-left: 15px;">
    495498                                <h4><?php _e('Please enter options for this Field:', 'buddypress') ?></h4>
    496499                                <p><?php _e( 'Order By:', 'buddypress' ) ?>
    497 
    498500                                        <select name="sort_order_<?php echo $type ?>" id="sort_order_<?php echo $type ?>" >
    499501                                                <option value="default" <?php if ( 'default' == $this->order_by ) {?> selected="selected"<?php } ?> ><?php _e( 'Order Entered', 'buddypress' ) ?></option>
     
    501503                                                <option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Descending', 'buddypress' ) ?></option>
    502504                                        </select>
    503 
    504                                 <?php
     505<?php
    505506                                if ( !$options = $this->get_children(true) ) {
    506507                                        $i = 1;
     
    520521                                }
    521522
    522                                 if ( !empty($options) ) {
     523                                if ( !empty( $options ) ) {
    523524                                        for ( $i = 0; $i < count($options); $i++ ) {
    524525                                                $j = $i + 1;
     
    526527                                                if ( 'multiselectbox' == $type || 'checkbox' == $type )
    527528                                                        $default_name = '[' . $j . ']';
    528                                         ?>
     529                                                ?>
    529530                                                <p><?php _e('Option', 'buddypress') ?> <?php echo $j ?>:
    530531                                                   <input type="text" name="<?php echo $type ?>_option[<?php echo $j ?>]" id="<?php echo $type ?>_option<?php echo $j ?>" value="<?php echo attribute_escape( $options[$i]->name ) ?>" />
     
    533534                                                                $options[$i]->id != -1 ) : ?><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><?php endif ?></p>
    534535                                                </p>
    535                                         <?php } // end for ?>
     536                                        <?php } /* end for */ ?>
    536537                                        <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="<?php echo $j + 1 ?>" />
    537538
     
    546547                                        <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="2" />
    547548
    548                                 <?php } // end if ?>
     549                                <?php } /* end if */ ?>
    549550                                <div id="<?php echo $type ?>_more"></div>
    550551                                <p><a href="javascript:add_option('<?php echo $type ?>')"><?php _e('Add Another Option', 'buddypress') ?></a></p>
     
    556557        function render_admin_form( $message = '' ) {
    557558                if ( !$this->id ) {
    558                         $title = __('Add Field', 'buddypress');
    559                         $action = "admin.php?page=bp-profile-setup&amp;group_id=" . $this->group_id . "&amp;mode=add_field";
     559                        $title                          = __('Add Field', 'buddypress');
     560                        $action                         = "admin.php?page=bp-profile-setup&amp;group_id=" . $this->group_id . "&amp;mode=add_field";
    560561
    561562                        $this->name                     = $_POST['title'];
     
    565566                        $this->order_by         = $_POST["sort_order_{$this->type}"];
    566567                } else {
    567                         $title = __('Edit Field', 'buddypress');
    568                         $action = "admin.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id;
     568                        $title                          = __('Edit Field', 'buddypress');
     569                        $action                         = "admin.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id;
    569570                }
    570571        ?>
     
    623624
    624625                                <p class="submit">
    625                                                 &nbsp;<input type="submit" value="<?php _e("Save", 'buddypress') ?> &rarr;" name="saveField" id="saveField" style="font-weight: bold" />
    626                                                 <?php _e('or', 'buddypress') ?> <a href="admin.php?page=bp-profile-setup" style="color: red"><?php _e( 'Cancel', 'buddypress' ) ?></a>
     626                                        &nbsp;<input type="submit" value="<?php _e("Save", 'buddypress') ?> &rarr;" name="saveField" id="saveField" style="font-weight: bold" />
     627                                        <?php _e('or', 'buddypress') ?> <a href="admin.php?page=bp-profile-setup" style="color: red"><?php _e( 'Cancel', 'buddypress' ) ?></a>
    627628                                </p>
    628629
     630                        </div>
     631
    629632                        <div class="clear"></div>
    630633
    631                         <?php if ( function_exists('wp_nonce_field') )
    632                                 wp_nonce_field('xprofile_delete_option');
    633                         ?>
     634                        <?php if ( function_exists( 'wp_nonce_field' ) ) wp_nonce_field( 'xprofile_delete_option' ); ?>
    634635
    635636                </form>
    636637        </div>
    637638
    638         <?php
     639<?php
    639640        }
    640641
     
    642643                global $message;
    643644
    644                 // Validate Form
     645                /* Validate Form */
    645646                if ( '' == $_POST['title'] || '' == $_POST['required'] || '' == $_POST['fieldtype'] ) {
    646                         $message = __('Please make sure you fill out all required fields.', 'buddypress');
     647                        $message = __( 'Please make sure you fill out all required fields.', 'buddypress' );
    647648                        return false;
    648649                } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'radio' && empty($_POST['radio_option'][1]) ) {
    649                         $message = __('Radio button field types require at least one option. Please add options below.', 'buddypress');
     650                        $message = __( 'Radio button field types require at least one option. Please add options below.', 'buddypress' );
    650651                        return false;
    651652                } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'selectbox' && empty($_POST['selectbox_option'][1]) ) {
    652                         $message = __('Select box field types require at least one option. Please add options below.', 'buddypress');
     653                        $message = __( 'Select box field types require at least one option. Please add options below.', 'buddypress' );
    653654                        return false;
    654655                } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'multiselectbox' && empty($_POST['multiselectbox_option'][1]) ) {
    655                         $message = __('Select box field types require at least one option. Please add options below.', 'buddypress');
     656                        $message = __( 'Select box field types require at least one option. Please add options below.', 'buddypress' );
    656657                        return false;
    657658                } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'checkbox' && empty($_POST['checkbox_option'][1]) ) {
    658                         $message = __('Checkbox field types require at least one option. Please add options below.', 'buddypress');
     659                        $message = __( 'Checkbox field types require at least one option. Please add options below.', 'buddypress' );
    659660                        return false;
    660661                } else {
     
    673674
    674675        function bp_xprofile_profiledata( $field_id = null, $user_id = null ) {
    675                 if ( $field_id ) {
     676                if ( $field_id )
    676677                        $this->populate( $field_id, $user_id );
    677                 }
    678678        }
    679679
     
    683683                $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id );
    684684
    685                 if ( $profiledata = $wpdb->get_row($sql) ) {
    686 
     685                if ( $profiledata = $wpdb->get_row( $sql ) ) {
    687686                        $this->id = $profiledata->id;
    688687                        $this->user_id = $profiledata->user_id;
     
    696695                global $wpdb, $bp;
    697696
    698                 // check to see if there is data already for the user.
     697                /* Check to see if there is data already for the user. */
    699698                $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = %d", $this->user_id, $this->field_id );
    700699
    701                 if ( !$wpdb->get_row($sql) )
     700                if ( !$wpdb->get_row( $sql ) )
    702701                        return false;
    703702
     
    708707                global $wpdb, $bp;
    709708
    710                 // check to see if this data is actually for a valid field.
    711                 $sql = $wpdb->prepare("SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id );
    712 
    713                 if ( !$wpdb->get_row($sql) )
     709                /* check to see if this data is actually for a valid field. */
     710                $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id );
     711
     712                if ( !$wpdb->get_row( $sql ) )
    714713                        return false;
    715714
     
    728727
    729728                if ( $this->is_valid_field() ) {
    730                         if ( $this->exists() && !empty( $this->value ) && strlen( trim( $this->value ) ) ) {
     729                        if ( $this->exists() && !empty( $this->value ) && strlen( trim( $this->value ) ) )
    731730                                $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_data} SET value = %s, last_updated = %s WHERE user_id = %d AND field_id = %d", $this->value, $this->last_updated, $this->user_id, $this->field_id ) );
    732                         } else if ( $this->exists() && empty( $this->value ) ) {
    733                                 // Data removed, delete the entry.
     731
     732                        /* Data removed, delete the entry. */
     733                        else if ( $this->exists() && empty( $this->value ) )
    734734                                $result = $this->delete();
    735                         } else {
     735
     736                        else
    736737                                $result = $wpdb->query( $wpdb->prepare("INSERT INTO {$bp->profile->table_name_data} (user_id, field_id, value, last_updated) VALUES (%d, %d, %s, %s)", $this->user_id, $this->field_id, $this->value, $this->last_updated ) );
    737                         }
    738738
    739739                        if ( !$result )
     
    800800                        $user_ids = implode( ',', (array)$user_ids );
    801801                        $data = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id IN ({$user_ids})", $field_id ) );
    802                 } else
     802                } else {
    803803                        $data = $wpdb->get_var( $wpdb->prepare( "SELECT value FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_ids ) );
     804                }
    804805
    805806                return $data;
     
    835836                $sql = $wpdb->prepare( "SELECT d.value, f.name FROM {$bp->profile->table_name_data} d, {$bp->profile->table_name_fields} f WHERE d.field_id = f.id AND d.user_id = %d AND f.parent_id = 0 $field_sql", $user_id );
    836837
    837                 if ( !$values = $wpdb->get_results($sql) )
     838                if ( !$values = $wpdb->get_results( $sql ) )
    838839                        return false;
    839840
    840841                $new_values = array();
    841842
    842                 if ( is_array($fields) ) {
    843                         for ( $i = 0; $i < count($values); $i++ ) {
    844                                 for ( $j = 0; $j < count($fields); $j++ ) {
     843                if ( is_array( $fields ) ) {
     844                        for ( $i = 0; $i < count( $values ); $i++ ) {
     845                                for ( $j = 0; $j < count( $fields ); $j++ ) {
    845846                                        if ( $values[$i]->name == $fields[$j] ) {
    846847                                                $new_values[$fields[$j]] = $values[$i]->value;
     
    900901        }
    901902}
     903
    902904?>
  • trunk/bp-xprofile/bp-xprofile-cssjs.php

    r1963 r2798  
    88function xprofile_add_admin_js() {
    99        if ( strpos( $_GET['page'], 'bp-profile-setup' ) !== false ) {
    10                 wp_enqueue_script( array( "jquery-ui-sortable" ) );
    11                 wp_enqueue_script( 'xprofile-admin-js', BP_PLUGIN_URL . '/bp-xprofile/admin/js/admin.js', array( 'jquery' ) );
     10                wp_enqueue_script( 'jquery-ui-sortable' );
     11                wp_enqueue_script( 'xprofile-admin-js', BP_PLUGIN_URL . '/bp-xprofile/admin/js/admin.js', array( 'jquery', 'jquery-ui-sortable' ) );
    1212        }
    1313}
  • trunk/bp-xprofile/bp-xprofile-templatetags.php

    r2695 r2798  
    6161                } elseif ( $this->current_group + 1 == $this->group_count ) {
    6262                        do_action('xprofile_template_loop_end');
    63                         // Do some cleaning up after the loop
     63                        /* Do some cleaning up after the loop */
    6464                        $this->rewind_groups();
    6565                }
     
    7575                $group = $this->next_group();
    7676
    77                 if ( 0 == $this->current_group ) // loop has just started
     77                if ( 0 == $this->current_group ) /* loop has just started */
    7878                        do_action('xprofile_template_loop_start');
    7979        }
     
    116116                        return true;
    117117                } elseif ( $this->current_field + 1 == $this->field_count ) {
    118                         // Do some cleaning up after the loop
     118                        /* Do some cleaning up after the loop */
    119119                        $this->rewind_fields();
    120120                }
     
    547547        function bp_get_profile_field_data( $args = '' ) {
    548548                $defaults = array(
    549                         'field' => false, // Field name or ID.
     549                        'field' => false, /* Field name or ID. */
    550550                        'user_id' => $bp->displayed_user->id
    551                         );
     551                );
    552552
    553553                $r = wp_parse_args( $args, $defaults );
     
    657657                        $profile_group_id = 1;
    658658
    659                 return apply_filters( 'bp_get_current_profile_group_id', $profile_group_id ); // admin/profile/edit/[group-id]
     659                /* admin/profile/edit/[group-id] */
     660                return apply_filters( 'bp_get_current_profile_group_id', $profile_group_id );
    660661        }
    661662
Note: See TracChangeset for help on using the changeset viewer.