<!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' =&gt; array(
</span><span class="cx">                         'title'       =&gt; __( '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 =&gt; $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 =&gt; $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 =&gt; $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 =&gt; $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 ) &amp;&amp; ( bp_get_maintenance_mode() == 'install' ) )
</del><ins>+        if ( empty( $active_components ) &amp;&amp; ( 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() ) : ?&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -140,63 +181,84 @@
</span><span class="cx">                 &lt;p&gt;&lt;?php _e( 'Each component has a unique purpose, and your community may not need each one.', 'buddypress' ); ?&gt;&lt;/p&gt;
</span><span class="cx"> 
</span><span class="cx">         &lt;?php endif ?&gt;
</span><ins>+                
+                &lt;ul class=&quot;subsubsub&quot;&gt;
+                        &lt;li&gt;&lt;a href=&quot;&lt;?php echo add_query_arg( array( 'page' =&gt; 'bp-components', 'action' =&gt; 'all'      ), bp_get_admin_url( $page ) ); ?&gt;&quot; &lt;?php if ( $action === 'all'      ) : ?&gt;class=&quot;current&quot;&lt;?php endif; ?&gt;&gt;&lt;?php printf( _nx( 'All &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;',     'All &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;',       $all_count,         'plugins' ), number_format_i18n( $all_count                    ) ); ?&gt;&lt;/a&gt; | &lt;/li&gt;
+                        &lt;li&gt;&lt;a href=&quot;&lt;?php echo add_query_arg( array( 'page' =&gt; 'bp-components', 'action' =&gt; 'active'   ), bp_get_admin_url( $page ) ); ?&gt;&quot; &lt;?php if ( $action === 'active'   ) : ?&gt;class=&quot;current&quot;&lt;?php endif; ?&gt;&gt;&lt;?php printf( _n(  'Active &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;',   'Active &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;',   count( $active_components   ) ), number_format_i18n( count( $active_components   ) ) ); ?&gt;&lt;/a&gt; | &lt;/li&gt;
+                        &lt;li&gt;&lt;a href=&quot;&lt;?php echo add_query_arg( array( 'page' =&gt; 'bp-components', 'action' =&gt; 'inactive' ), bp_get_admin_url( $page ) ); ?&gt;&quot; &lt;?php if ( $action === 'inactive' ) : ?&gt;class=&quot;current&quot;&lt;?php endif; ?&gt;&gt;&lt;?php printf( _n(  'Inactive &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Inactive &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', count( $inactive_components ) ), number_format_i18n( count( $inactive_components ) ) ); ?&gt;&lt;/a&gt; | &lt;/li&gt;
+                        &lt;li&gt;&lt;a href=&quot;&lt;?php echo add_query_arg( array( 'page' =&gt; 'bp-components', 'action' =&gt; 'mustuse'  ), bp_get_admin_url( $page ) ); ?&gt;&quot; &lt;?php if ( $action === 'mustuse'  ) : ?&gt;class=&quot;current&quot;&lt;?php endif; ?&gt;&gt;&lt;?php printf( _n(  'Must-Use &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Must-Use &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', count( $required_components ) ), number_format_i18n( count( $required_components ) ) ); ?&gt;&lt;/a&gt;&lt;/li&gt;
+                &lt;/ul&gt;
</ins><span class="cx"> 
</span><del>-        &lt;table class=&quot;form-table&quot;&gt;
-                &lt;tbody&gt;
</del><ins>+                &lt;table class=&quot;widefat fixed plugins&quot; cellspacing=&quot;0&quot;&gt;
+                        &lt;thead&gt;
+                                &lt;tr&gt;
+                                        &lt;th scope=&quot;col&quot; id=&quot;cb&quot; class=&quot;manage-column column-cb check-column&quot;&gt;&amp;nbsp;&lt;/th&gt;
+                                        &lt;th scope=&quot;col&quot; id=&quot;name&quot; class=&quot;manage-column column-name&quot; style=&quot;width: 190px;&quot;&gt;&lt;?php _e( 'Component', 'buddypress' ); ?&gt;&lt;/th&gt;
+                                        &lt;th scope=&quot;col&quot; id=&quot;description&quot; class=&quot;manage-column column-description&quot;&gt;&lt;?php _e( 'Description', 'buddypress' ); ?&gt;&lt;/th&gt;
+                                &lt;/tr&gt;
+                        &lt;/thead&gt;
</ins><span class="cx"> 
</span><del>-                        &lt;?php foreach ( $optional_components as $name =&gt; $labels ) : ?&gt;
-
-                                &lt;tr valign=&quot;top&quot;&gt;
-                                        &lt;th scope=&quot;row&quot;&gt;&lt;?php echo esc_html( $labels['title'] ); ?&gt;&lt;/th&gt;
-
-                                        &lt;td&gt;
-                                                &lt;label for=&quot;bp_components[&lt;?php echo esc_attr( $name ); ?&gt;]&quot;&gt;
-                                                        &lt;input type=&quot;checkbox&quot; id=&quot;bp_components[&lt;?php echo esc_attr( $name ); ?&gt;]&quot; name=&quot;bp_components[&lt;?php echo esc_attr( $name ); ?&gt;]&quot; value=&quot;1&quot;&lt;?php checked( isset( $active_components[esc_attr( $name )] ) ); ?&gt; /&gt;
-
-                                                        &lt;?php echo $labels['description']; ?&gt;
-
-                                                &lt;/label&gt;
-
-                                        &lt;/td&gt;
</del><ins>+                        &lt;tfoot&gt;
+                                &lt;tr&gt;
+                                        &lt;th scope=&quot;col&quot; class=&quot;manage-column column-cb check-column&quot;&gt;&amp;nbsp;&lt;/th&gt;
+                                        &lt;th scope=&quot;col&quot; class=&quot;manage-column column-name&quot; style=&quot;width: 190px;&quot;&gt;&lt;?php _e( 'Component', 'buddypress' ); ?&gt;&lt;/th&gt;
+                                        &lt;th scope=&quot;col&quot; class=&quot;manage-column column-description&quot;&gt;&lt;?php _e( 'Description', 'buddypress' ); ?&gt;&lt;/th&gt;
</ins><span class="cx">                                 &lt;/tr&gt;
</span><ins>+                        &lt;/tfoot&gt;
</ins><span class="cx"> 
</span><del>-                        &lt;?php endforeach ?&gt;
</del><ins>+                        &lt;tbody id=&quot;the-list&quot;&gt;
+                                
+                                &lt;?php if ( !empty( $current_components ) ) : ?&gt;
</ins><span class="cx"> 
</span><del>-                &lt;/tbody&gt;
-        &lt;/table&gt;
</del><ins>+                                        &lt;?php foreach ( $current_components as $name =&gt; $labels ) : ?&gt;
</ins><span class="cx"> 
</span><del>-        &lt;?php if ( bp_get_maintenance_mode() ) : ?&gt;
</del><ins>+                                                &lt;?php if ( !in_array( $name, array( 'core', 'members' ) ) ) :
+                                                        $class = isset( $active_components[esc_attr( $name )] ) ? 'active' : 'inactive';
+                                                else :
+                                                        $class = 'active';
+                                                endif; ?&gt;
</ins><span class="cx"> 
</span><del>-                &lt;h3&gt;&lt;?php _e( 'Required Components', 'buddypress' ); ?&gt;&lt;/h3&gt;
</del><ins>+                                                &lt;tr id=&quot;&lt;?php echo $name; ?&gt;&quot; class=&quot;&lt;?php echo $class; ?&gt;&quot;&gt;
+                                                        &lt;th scope=&quot;row&quot;&gt;
</ins><span class="cx"> 
</span><del>-                &lt;p&gt;&lt;?php _e( 'The following components are required by BuddyPress and cannot be turned off.', 'buddypress' ); ?&gt;&lt;/p&gt;
</del><ins>+                                                                &lt;?php if ( !in_array( $name, array( 'core', 'members' ) ) ) : ?&gt;
</ins><span class="cx"> 
</span><del>-        &lt;?php endif ?&gt;
</del><ins>+                                                                        &lt;input type=&quot;checkbox&quot; id=&quot;bp_components[&lt;?php echo esc_attr( $name ); ?&gt;]&quot; name=&quot;bp_components[&lt;?php echo esc_attr( $name ); ?&gt;]&quot; value=&quot;1&quot;&lt;?php checked( isset( $active_components[esc_attr( $name )] ) ); ?&gt; /&gt;
</ins><span class="cx"> 
</span><del>-        &lt;table class=&quot;form-table&quot;&gt;
-                &lt;tbody&gt;
</del><ins>+                                                                &lt;?php endif; ?&gt;
</ins><span class="cx"> 
</span><del>-                        &lt;?php foreach ( $required_components as $name =&gt; $labels ) : ?&gt;
</del><ins>+                                                                &lt;label class=&quot;screen-reader-text&quot; for=&quot;bp_components[&lt;?php echo esc_attr( $name ); ?&gt;]&quot;&gt;&lt;?php sprintf( __( 'Select %s', 'bbpress' ), esc_html( $labels['title'] ) );  ?&gt;&lt;/label&gt;
+                                                        &lt;/th&gt;
+                                                        &lt;td class=&quot;plugin-title&quot; style=&quot;width: 190px;&quot;&gt;
+                                                                &lt;strong&gt;&lt;?php echo esc_html( $labels['title'] ); ?&gt;&lt;/strong&gt;
+                                                                &lt;div class=&quot;row-actions-visible&quot;&gt;
+                                                                        
+                                                                &lt;/div&gt;
+                                                        &lt;/td&gt;
</ins><span class="cx"> 
</span><del>-                                &lt;tr valign=&quot;top&quot;&gt;
-                                        &lt;th scope=&quot;row&quot;&gt;&lt;?php echo esc_html( $labels['title'] ); ?&gt;&lt;/th&gt;
</del><ins>+                                                        &lt;td class=&quot;column-description desc&quot;&gt;
+                                                                &lt;div class=&quot;plugin-description&quot;&gt;
+                                                                        &lt;p&gt;&lt;?php echo $labels['description']; ?&gt;&lt;/p&gt;
+                                                                &lt;/div&gt;
+                                                                &lt;div class=&quot;active second plugin-version-author-uri&quot;&gt;
+                                                                        
+                                                                &lt;/div&gt;
+                                                        &lt;/td&gt;
+                                                &lt;/tr&gt;
</ins><span class="cx"> 
</span><del>-                                        &lt;td&gt;
-                                                &lt;label for=&quot;bp_components[&lt;?php echo esc_attr( $name ); ?&gt;]&quot;&gt;
-                                                        &lt;input type=&quot;checkbox&quot; id=&quot;bp_components[&lt;?php echo esc_attr( $name ); ?&gt;]&quot; name=&quot;&quot; disabled=&quot;disabled&quot; value=&quot;1&quot;&lt;?php checked( true ); ?&gt; /&gt;
</del><ins>+                                        &lt;?php endforeach ?&gt;
</ins><span class="cx"> 
</span><del>-                                                        &lt;?php echo $labels['description']; ?&gt;
</del><ins>+                                &lt;?php else : ?&gt;
+                                                
+                                        &lt;tr class=&quot;no-items&quot;&gt;
+                                                &lt;td class=&quot;colspanchange&quot; colspan=&quot;3&quot;&gt;&lt;?php _e( 'No components found.', 'buddypress' ); ?&gt;&lt;/td&gt;
+                                        &lt;/tr&gt;
</ins><span class="cx"> 
</span><del>-                                                &lt;/label&gt;
</del><ins>+                                &lt;?php endif; ?&gt;
</ins><span class="cx"> 
</span><del>-                                        &lt;/td&gt;
-                                &lt;/tr&gt;
</del><ins>+                        &lt;/tbody&gt;
+                &lt;/table&gt;
</ins><span class="cx"> 
</span><del>-                        &lt;?php endforeach ?&gt;
-
-                &lt;/tbody&gt;
-        &lt;/table&gt;
-
</del><span class="cx">         &lt;input type=&quot;hidden&quot; name=&quot;bp_components[members]&quot; value=&quot;1&quot; /&gt;
</span><span class="cx"> 
</span><span class="cx">         &lt;?php
</span></span></pre>
</div>
</div>

</body>
</html>