Skip to:
Content

BuddyPress.org


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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' );
Note: See TracChangeset for help on using the changeset viewer.