Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/27/2012 06:21:46 AM (14 years ago)
Author:
johnjamesjacoby
Message:

First pass at making admin Components screen work like list-tables without actually being list-tables.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/admin/bp-core-components.php

    r5800 r5850  
    5757                require( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php' );
    5858
    59         $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
    60 
    61         // An array of strings looped over to create component setup markup
     59        // Declare local variables
     60        $deactivated_components = array();
     61        $required_components    = array();
     62        $active_components      = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
     63
     64        // Optional core components
    6265        $optional_components = array(
    6366                'xprofile' => array(
     
    9598        );
    9699
    97         if ( is_multisite() )
     100        // Add blogs tracking if multisite
     101        if ( is_multisite() ) {
    98102                $optional_components['blogs']['description'] = __( 'Make BuddyPress aware of new sites, new posts and new comments from across your entire network.', 'buddypress' );
    99 
    100         // If this is an upgrade from before BuddyPress 1.5, we'll have to convert deactivated
    101         // components into activated ones
    102         if ( empty( $active_components ) ) {
    103                 $deactivated_components = bp_get_option( 'bp-deactivated-components' );
    104 
    105                 // Trim off namespace and filename
    106                 $trimmed = array();
    107                 foreach ( (array) $deactivated_components as $component => $value ) {
    108                         $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) );
    109                 }
    110 
    111                 // Loop through the optional components to create an active component array
    112                 foreach ( (array) $optional_components as $ocomponent => $ovalue ) {
    113                         if ( !in_array( $ocomponent, $trimmed ) ) {
    114                                 $active_components[$ocomponent] = 1;
    115                         }
    116                 }
    117103        }
    118104
     
    129115        );
    130116
     117        // Merge optional and required together
     118        $all_components = $optional_components + $required_components;
     119
     120        // If this is an upgrade from before BuddyPress 1.5, we'll have to convert
     121        // deactivated components into activated ones.
     122        if ( empty( $active_components ) ) {
     123                $deactivated_components = bp_get_option( 'bp-deactivated-components' );
     124                if ( !empty( $deactivated_components ) ) {
     125
     126                        // Trim off namespace and filename
     127                        $trimmed = array();
     128                        foreach ( (array) $deactivated_components as $component => $value ) {
     129                                $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) );
     130                        }
     131
     132                        // Loop through the optional components to create an active component array
     133                        foreach ( (array) $optional_components as $ocomponent => $ovalue ) {
     134                                if ( !in_array( $ocomponent, $trimmed ) ) {
     135                                        $active_components[$ocomponent] = 1;
     136                                }
     137                        }
     138                }
     139        }
     140
    131141        // On new install, set all components to be active by default
    132         if ( empty( $active_components ) && ( bp_get_maintenance_mode() == 'install' ) )
     142        if ( empty( $active_components ) && ( bp_get_maintenance_mode() == 'install' ) ) {
    133143                $active_components = $optional_components;
    134 
     144        }
     145
     146        // Core component is always active
     147        $active_components['core'] = $all_components['core'];
     148        $inactive_components       = array_diff( array_keys( $all_components ) , array_keys( $active_components ) );
     149
     150        /** Display ***************************************************************/
     151
     152        // Get the total count of all plugins
     153        $all_count = count( $all_components );
     154        $page      = bp_core_do_network_admin()  ? 'settings.php' : 'options-general.php';
     155        $action    = !empty( $_GET['action'] ) ? $_GET['action'] : 'all';
     156       
     157        switch( $action ) {
     158                case 'all' :
     159                        $current_components = $all_components;
     160                        break;
     161                case 'active' :
     162                        foreach ( array_keys( $active_components ) as $component ) {
     163                                $current_components[$component] = $all_components[$component];
     164                        }
     165                        break;
     166                case 'inactive' :
     167                        foreach ( $inactive_components as $component ) {
     168                                $current_components[$component] = $all_components[$component];
     169                        }
     170                        break;
     171                case 'mustuse' :
     172                        $current_components = $required_components;
     173                        break;
     174        }
     175       
    135176        // The setup wizard uses different, more descriptive text
    136177        if ( bp_get_maintenance_mode() ) : ?>
     
    141182
    142183        <?php endif ?>
    143 
    144         <table class="form-table">
    145                 <tbody>
    146 
    147                         <?php foreach ( $optional_components as $name => $labels ) : ?>
    148 
    149                                 <tr valign="top">
    150                                         <th scope="row"><?php echo esc_html( $labels['title'] ); ?></th>
    151 
    152                                         <td>
    153                                                 <label for="bp_components[<?php echo esc_attr( $name ); ?>]">
    154                                                         <input type="checkbox" id="bp_components[<?php echo esc_attr( $name ); ?>]" name="bp_components[<?php echo esc_attr( $name ); ?>]" value="1"<?php checked( isset( $active_components[esc_attr( $name )] ) ); ?> />
    155 
    156                                                         <?php echo $labels['description']; ?>
    157 
    158                                                 </label>
    159 
    160                                         </td>
     184               
     185                <ul class="subsubsub">
     186                        <li><a href="<?php echo add_query_arg( array( 'page' => 'bp-components', 'action' => 'all'      ), bp_get_admin_url( $page ) ); ?>" <?php if ( $action === 'all'      ) : ?>class="current"<?php endif; ?>><?php printf( _nx( 'All <span class="count">(%s)</span>',     'All <span class="count">(%s)</span>',       $all_count,         'plugins' ), number_format_i18n( $all_count                    ) ); ?></a> | </li>
     187                        <li><a href="<?php echo add_query_arg( array( 'page' => 'bp-components', 'action' => 'active'   ), bp_get_admin_url( $page ) ); ?>" <?php if ( $action === 'active'   ) : ?>class="current"<?php endif; ?>><?php printf( _n(  'Active <span class="count">(%s)</span>',   'Active <span class="count">(%s)</span>',   count( $active_components   ) ), number_format_i18n( count( $active_components   ) ) ); ?></a> | </li>
     188                        <li><a href="<?php echo add_query_arg( array( 'page' => 'bp-components', 'action' => 'inactive' ), bp_get_admin_url( $page ) ); ?>" <?php if ( $action === 'inactive' ) : ?>class="current"<?php endif; ?>><?php printf( _n(  'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', count( $inactive_components ) ), number_format_i18n( count( $inactive_components ) ) ); ?></a> | </li>
     189                        <li><a href="<?php echo add_query_arg( array( 'page' => 'bp-components', 'action' => 'mustuse'  ), bp_get_admin_url( $page ) ); ?>" <?php if ( $action === 'mustuse'  ) : ?>class="current"<?php endif; ?>><?php printf( _n(  'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', count( $required_components ) ), number_format_i18n( count( $required_components ) ) ); ?></a></li>
     190                </ul>
     191
     192                <table class="widefat fixed plugins" cellspacing="0">
     193                        <thead>
     194                                <tr>
     195                                        <th scope="col" id="cb" class="manage-column column-cb check-column">&nbsp;</th>
     196                                        <th scope="col" id="name" class="manage-column column-name" style="width: 190px;"><?php _e( 'Component', 'buddypress' ); ?></th>
     197                                        <th scope="col" id="description" class="manage-column column-description"><?php _e( 'Description', 'buddypress' ); ?></th>
    161198                                </tr>
    162 
    163                         <?php endforeach ?>
    164 
    165                 </tbody>
    166         </table>
    167 
    168         <?php if ( bp_get_maintenance_mode() ) : ?>
    169 
    170                 <h3><?php _e( 'Required Components', 'buddypress' ); ?></h3>
    171 
    172                 <p><?php _e( 'The following components are required by BuddyPress and cannot be turned off.', 'buddypress' ); ?></p>
    173 
    174         <?php endif ?>
    175 
    176         <table class="form-table">
    177                 <tbody>
    178 
    179                         <?php foreach ( $required_components as $name => $labels ) : ?>
    180 
    181                                 <tr valign="top">
    182                                         <th scope="row"><?php echo esc_html( $labels['title'] ); ?></th>
    183 
    184                                         <td>
    185                                                 <label for="bp_components[<?php echo esc_attr( $name ); ?>]">
    186                                                         <input type="checkbox" id="bp_components[<?php echo esc_attr( $name ); ?>]" name="" disabled="disabled" value="1"<?php checked( true ); ?> />
    187 
    188                                                         <?php echo $labels['description']; ?>
    189 
    190                                                 </label>
    191 
    192                                         </td>
     199                        </thead>
     200
     201                        <tfoot>
     202                                <tr>
     203                                        <th scope="col" class="manage-column column-cb check-column">&nbsp;</th>
     204                                        <th scope="col" class="manage-column column-name" style="width: 190px;"><?php _e( 'Component', 'buddypress' ); ?></th>
     205                                        <th scope="col" class="manage-column column-description"><?php _e( 'Description', 'buddypress' ); ?></th>
    193206                                </tr>
    194 
    195                         <?php endforeach ?>
    196 
    197                 </tbody>
    198         </table>
     207                        </tfoot>
     208
     209                        <tbody id="the-list">
     210                               
     211                                <?php if ( !empty( $current_components ) ) : ?>
     212
     213                                        <?php foreach ( $current_components as $name => $labels ) : ?>
     214
     215                                                <?php if ( !in_array( $name, array( 'core', 'members' ) ) ) :
     216                                                        $class = isset( $active_components[esc_attr( $name )] ) ? 'active' : 'inactive';
     217                                                else :
     218                                                        $class = 'active';
     219                                                endif; ?>
     220
     221                                                <tr id="<?php echo $name; ?>" class="<?php echo $class; ?>">
     222                                                        <th scope="row">
     223
     224                                                                <?php if ( !in_array( $name, array( 'core', 'members' ) ) ) : ?>
     225
     226                                                                        <input type="checkbox" id="bp_components[<?php echo esc_attr( $name ); ?>]" name="bp_components[<?php echo esc_attr( $name ); ?>]" value="1"<?php checked( isset( $active_components[esc_attr( $name )] ) ); ?> />
     227
     228                                                                <?php endif; ?>
     229
     230                                                                <label class="screen-reader-text" for="bp_components[<?php echo esc_attr( $name ); ?>]"><?php sprintf( __( 'Select %s', 'bbpress' ), esc_html( $labels['title'] ) );  ?></label>
     231                                                        </th>
     232                                                        <td class="plugin-title" style="width: 190px;">
     233                                                                <strong><?php echo esc_html( $labels['title'] ); ?></strong>
     234                                                                <div class="row-actions-visible">
     235                                                                       
     236                                                                </div>
     237                                                        </td>
     238
     239                                                        <td class="column-description desc">
     240                                                                <div class="plugin-description">
     241                                                                        <p><?php echo $labels['description']; ?></p>
     242                                                                </div>
     243                                                                <div class="active second plugin-version-author-uri">
     244                                                                       
     245                                                                </div>
     246                                                        </td>
     247                                                </tr>
     248
     249                                        <?php endforeach ?>
     250
     251                                <?php else : ?>
     252                                               
     253                                        <tr class="no-items">
     254                                                <td class="colspanchange" colspan="3"><?php _e( 'No components found.', 'buddypress' ); ?></td>
     255                                        </tr>
     256
     257                                <?php endif; ?>
     258
     259                        </tbody>
     260                </table>
    199261
    200262        <input type="hidden" name="bp_components[members]" value="1" />
Note: See TracChangeset for help on using the changeset viewer.