<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][5850] trunk/bp-core/admin/bp-core-components.php: First pass at making admin Components screen work like list-tables without actually being list-tables.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/5850">5850</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2012-02-27 06:21:46 +0000 (Mon, 27 Feb 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>First pass at making admin Components screen work like list-tables without actually being list-tables.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcoreadminbpcorecomponentsphp">trunk/bp-core/admin/bp-core-components.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcoreadminbpcorecomponentsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/admin/bp-core-components.php (5849 => 5850)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/admin/bp-core-components.php        2012-02-27 03:36:10 UTC (rev 5849)
+++ trunk/bp-core/admin/bp-core-components.php        2012-02-27 06:21:46 UTC (rev 5850)
</span><span class="lines">@@ -56,9 +56,12 @@
</span><span class="cx">         if ( !function_exists( 'bp_get_option' ) )
</span><span class="cx">                 require( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php' );
</span><span class="cx">
</span><del>-        $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
</del><ins>+        // Declare local variables
+        $deactivated_components = array();
+        $required_components = array();
+        $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
</ins><span class="cx">
</span><del>-        // An array of strings looped over to create component setup markup
</del><ins>+        // Optional core components
</ins><span class="cx">         $optional_components = array(
</span><span class="cx">                 'xprofile' => array(
</span><span class="cx">                         'title' => __( 'Extended Profiles', 'buddypress' ),
</span><span class="lines">@@ -94,26 +97,9 @@
</span><span class="cx">                 )
</span><span class="cx">         );
</span><span class="cx">
</span><del>-        if ( is_multisite() )
</del><ins>+        // Add blogs tracking if multisite
+        if ( is_multisite() ) {
</ins><span class="cx">                 $optional_components['blogs']['description'] = __( 'Make BuddyPress aware of new sites, new posts and new comments from across your entire network.', 'buddypress' );
</span><del>-
-        // If this is an upgrade from before BuddyPress 1.5, we'll have to convert deactivated
-        // components into activated ones
-        if ( empty( $active_components ) ) {
-                $deactivated_components = bp_get_option( 'bp-deactivated-components' );
-
-                // Trim off namespace and filename
-                $trimmed = array();
-                foreach ( (array) $deactivated_components as $component => $value ) {
-                        $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) );
-                }
-
-                // Loop through the optional components to create an active component array
-                foreach ( (array) $optional_components as $ocomponent => $ovalue ) {
-                        if ( !in_array( $ocomponent, $trimmed ) ) {
-                                $active_components[$ocomponent] = 1;
-                        }
-                }
</del><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         // Required components
</span><span class="lines">@@ -128,10 +114,65 @@
</span><span class="cx">                 ),
</span><span class="cx">         );
</span><span class="cx">
</span><ins>+        // Merge optional and required together
+        $all_components = $optional_components + $required_components;
+
+        // If this is an upgrade from before BuddyPress 1.5, we'll have to convert
+        // deactivated components into activated ones.
+        if ( empty( $active_components ) ) {
+                $deactivated_components = bp_get_option( 'bp-deactivated-components' );
+                if ( !empty( $deactivated_components ) ) {
+
+                        // Trim off namespace and filename
+                        $trimmed = array();
+                        foreach ( (array) $deactivated_components as $component => $value ) {
+                                $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) );
+                        }
+
+                        // Loop through the optional components to create an active component array
+                        foreach ( (array) $optional_components as $ocomponent => $ovalue ) {
+                                if ( !in_array( $ocomponent, $trimmed ) ) {
+                                        $active_components[$ocomponent] = 1;
+                                }
+                        }
+                }
+        }
+
</ins><span class="cx">         // On new install, set all components to be active by default
</span><del>-        if ( empty( $active_components ) && ( bp_get_maintenance_mode() == 'install' ) )
</del><ins>+        if ( empty( $active_components ) && ( bp_get_maintenance_mode() == 'install' ) ) {
</ins><span class="cx">                 $active_components = $optional_components;
</span><ins>+        }
</ins><span class="cx">
</span><ins>+        // Core component is always active
+        $active_components['core'] = $all_components['core'];
+        $inactive_components = array_diff( array_keys( $all_components ) , array_keys( $active_components ) );
+
+        /** Display ***************************************************************/
+
+        // Get the total count of all plugins
+        $all_count = count( $all_components );
+        $page = bp_core_do_network_admin() ? 'settings.php' : 'options-general.php';
+        $action = !empty( $_GET['action'] ) ? $_GET['action'] : 'all';
+        
+        switch( $action ) {
+                case 'all' :
+                        $current_components = $all_components;
+                        break;
+                case 'active' :
+                        foreach ( array_keys( $active_components ) as $component ) {
+                                $current_components[$component] = $all_components[$component];
+                        }
+                        break;
+                case 'inactive' :
+                        foreach ( $inactive_components as $component ) {
+                                $current_components[$component] = $all_components[$component];
+                        }
+                        break;
+                case 'mustuse' :
+                        $current_components = $required_components;
+                        break;
+        }
+        
</ins><span class="cx">         // The setup wizard uses different, more descriptive text
</span><span class="cx">         if ( bp_get_maintenance_mode() ) : ?>
</span><span class="cx">
</span><span class="lines">@@ -140,63 +181,84 @@
</span><span class="cx">                 <p><?php _e( 'Each component has a unique purpose, and your community may not need each one.', 'buddypress' ); ?></p>
</span><span class="cx">
</span><span class="cx">         <?php endif ?>
</span><ins>+                
+                <ul class="subsubsub">
+                        <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>
+                        <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>
+                        <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>
+                        <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>
+                </ul>
</ins><span class="cx">
</span><del>-        <table class="form-table">
-                <tbody>
</del><ins>+                <table class="widefat fixed plugins" cellspacing="0">
+                        <thead>
+                                <tr>
+                                        <th scope="col" id="cb" class="manage-column column-cb check-column">&nbsp;</th>
+                                        <th scope="col" id="name" class="manage-column column-name" style="width: 190px;"><?php _e( 'Component', 'buddypress' ); ?></th>
+                                        <th scope="col" id="description" class="manage-column column-description"><?php _e( 'Description', 'buddypress' ); ?></th>
+                                </tr>
+                        </thead>
</ins><span class="cx">
</span><del>-                        <?php foreach ( $optional_components as $name => $labels ) : ?>
-
-                                <tr valign="top">
-                                        <th scope="row"><?php echo esc_html( $labels['title'] ); ?></th>
-
-                                        <td>
-                                                <label for="bp_components[<?php echo esc_attr( $name ); ?>]">
-                                                        <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 )] ) ); ?> />
-
-                                                        <?php echo $labels['description']; ?>
-
-                                                </label>
-
-                                        </td>
</del><ins>+                        <tfoot>
+                                <tr>
+                                        <th scope="col" class="manage-column column-cb check-column">&nbsp;</th>
+                                        <th scope="col" class="manage-column column-name" style="width: 190px;"><?php _e( 'Component', 'buddypress' ); ?></th>
+                                        <th scope="col" class="manage-column column-description"><?php _e( 'Description', 'buddypress' ); ?></th>
</ins><span class="cx">                                 </tr>
</span><ins>+                        </tfoot>
</ins><span class="cx">
</span><del>-                        <?php endforeach ?>
</del><ins>+                        <tbody id="the-list">
+                                
+                                <?php if ( !empty( $current_components ) ) : ?>
</ins><span class="cx">
</span><del>-                </tbody>
-        </table>
</del><ins>+                                        <?php foreach ( $current_components as $name => $labels ) : ?>
</ins><span class="cx">
</span><del>-        <?php if ( bp_get_maintenance_mode() ) : ?>
</del><ins>+                                                <?php if ( !in_array( $name, array( 'core', 'members' ) ) ) :
+                                                        $class = isset( $active_components[esc_attr( $name )] ) ? 'active' : 'inactive';
+                                                else :
+                                                        $class = 'active';
+                                                endif; ?>
</ins><span class="cx">
</span><del>-                <h3><?php _e( 'Required Components', 'buddypress' ); ?></h3>
</del><ins>+                                                <tr id="<?php echo $name; ?>" class="<?php echo $class; ?>">
+                                                        <th scope="row">
</ins><span class="cx">
</span><del>-                <p><?php _e( 'The following components are required by BuddyPress and cannot be turned off.', 'buddypress' ); ?></p>
</del><ins>+                                                                <?php if ( !in_array( $name, array( 'core', 'members' ) ) ) : ?>
</ins><span class="cx">
</span><del>-        <?php endif ?>
</del><ins>+                                                                        <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 )] ) ); ?> />
</ins><span class="cx">
</span><del>-        <table class="form-table">
-                <tbody>
</del><ins>+                                                                <?php endif; ?>
</ins><span class="cx">
</span><del>-                        <?php foreach ( $required_components as $name => $labels ) : ?>
</del><ins>+                                                                <label class="screen-reader-text" for="bp_components[<?php echo esc_attr( $name ); ?>]"><?php sprintf( __( 'Select %s', 'bbpress' ), esc_html( $labels['title'] ) ); ?></label>
+                                                        </th>
+                                                        <td class="plugin-title" style="width: 190px;">
+                                                                <strong><?php echo esc_html( $labels['title'] ); ?></strong>
+                                                                <div class="row-actions-visible">
+                                                                        
+                                                                </div>
+                                                        </td>
</ins><span class="cx">
</span><del>-                                <tr valign="top">
-                                        <th scope="row"><?php echo esc_html( $labels['title'] ); ?></th>
</del><ins>+                                                        <td class="column-description desc">
+                                                                <div class="plugin-description">
+                                                                        <p><?php echo $labels['description']; ?></p>
+                                                                </div>
+                                                                <div class="active second plugin-version-author-uri">
+                                                                        
+                                                                </div>
+                                                        </td>
+                                                </tr>
</ins><span class="cx">
</span><del>-                                        <td>
-                                                <label for="bp_components[<?php echo esc_attr( $name ); ?>]">
-                                                        <input type="checkbox" id="bp_components[<?php echo esc_attr( $name ); ?>]" name="" disabled="disabled" value="1"<?php checked( true ); ?> />
</del><ins>+                                        <?php endforeach ?>
</ins><span class="cx">
</span><del>-                                                        <?php echo $labels['description']; ?>
</del><ins>+                                <?php else : ?>
+                                                
+                                        <tr class="no-items">
+                                                <td class="colspanchange" colspan="3"><?php _e( 'No components found.', 'buddypress' ); ?></td>
+                                        </tr>
</ins><span class="cx">
</span><del>-                                                </label>
</del><ins>+                                <?php endif; ?>
</ins><span class="cx">
</span><del>-                                        </td>
-                                </tr>
</del><ins>+                        </tbody>
+                </table>
</ins><span class="cx">
</span><del>-                        <?php endforeach ?>
-
-                </tbody>
-        </table>
-
</del><span class="cx">         <input type="hidden" name="bp_components[members]" value="1" />
</span><span class="cx">
</span><span class="cx">         <?php
</span></span></pre>
</div>
</div>
</body>
</html>