<!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][5319] trunk: Performance improvements and phpdoc to bp-core-catchuri.php.</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/5319">5319</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2011-11-09 06:38:28 +0000 (Wed, 09 Nov 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Performance improvements and phpdoc to bp-core-catchuri.php. Introduce bp_core_enable_root_profiles() function as wrapper for constant.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcorebpcorecatchuriphp">trunk/bp-core/bp-core-catchuri.php</a></li>
<li><a href="#trunkbpmembersbpmembersfunctionsphp">trunk/bp-members/bp-members-functions.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcorebpcorecatchuriphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-catchuri.php (5318 => 5319)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-catchuri.php        2011-11-09 06:31:07 UTC (rev 5318)
+++ trunk/bp-core/bp-core-catchuri.php        2011-11-09 06:38:28 UTC (rev 5319)
</span><span class="lines">@@ -1,19 +1,27 @@
</span><span class="cx"> &lt;?php
</span><ins>+
+/**
+ * BuddyPress URI catcher
+ *
+ * Functions for parsing the URI and determining which BuddyPress template file
+ * to use on-screen.
+ *
+ * Based on contributions from: Chris Taylor - http://www.stillbreathing.co.uk/
+ * Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
+ *
+ * @package BuddyPress
+ * @subpackage Core
+ */
+
</ins><span class="cx"> // Exit if accessed directly
</span><span class="cx"> if ( !defined( 'ABSPATH' ) ) exit;
</span><span class="cx"> 
</span><del>-/*
-Based on contributions from: Chris Taylor - http://www.stillbreathing.co.uk/
-Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
-*/
-
</del><span class="cx"> /**
</span><span class="cx">  * Analyzes the URI structure and breaks it down into parts for use in code.
</span><del>- * The idea is that BuddyPress can use complete custom friendly URI's without the
- * user having to add new re-write rules.
</del><ins>+ * BuddyPress can use complete custom friendly URI's without the user having to
+ * add new re-write rules. Custom components are able to use their own custom
+ * URI structures with very little work.
</ins><span class="cx">  *
</span><del>- * Future custom components would then be able to use their own custom URI structure.
- *
</del><span class="cx">  * @package BuddyPress Core
</span><span class="cx">  * @since BuddyPress (r100)
</span><span class="cx">  *
</span><span class="lines">@@ -35,6 +43,10 @@
</span><span class="cx">         if ( !bp_is_root_blog() &amp;&amp; !bp_is_multiblog_mode() )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><ins>+        // Define local variables
+        $root_profile = $match   = false;
+        $key_slugs    = $matches = $uri_chunks = array();
+
</ins><span class="cx">         // Fetch all the WP page names for each component
</span><span class="cx">         if ( empty( $bp-&gt;pages ) )
</span><span class="cx">                 $bp-&gt;pages = bp_core_get_directory_pages();
</span><span class="lines">@@ -48,30 +60,39 @@
</span><span class="cx">         // Filter the path
</span><span class="cx">         $path = apply_filters( 'bp_uri', $path );
</span><span class="cx"> 
</span><del>-        // Take GET variables off the URL to avoid problems,
-        // they are still registered in the global $_GET variable
-        if ( $noget = substr( $path, 0, strpos( $path, '?' ) ) )
-                $path = $noget;
</del><ins>+        // Take GET variables off the URL to avoid problems
+        $path = strtok( $path, '?' );
</ins><span class="cx"> 
</span><del>-        // Fetch the current URI and explode each part separated by '/' into an array
</del><ins>+        // Fetch current URI and explode each part separated by '/' into an array
</ins><span class="cx">         $bp_uri = explode( '/', $path );
</span><span class="cx"> 
</span><span class="cx">         // Loop and remove empties
</span><del>-        foreach ( (array)$bp_uri as $key =&gt; $uri_chunk )
-                if ( empty( $bp_uri[$key] ) ) unset( $bp_uri[$key] );
</del><ins>+        foreach ( (array)$bp_uri as $key =&gt; $uri_chunk ) {
+                if ( empty( $bp_uri[$key] ) ) {
+                        unset( $bp_uri[$key] );
+                }
+        }
</ins><span class="cx"> 
</span><del>-        // Running off blog other than root
</del><ins>+        // If running off blog other than root, any subdirectory names must be
+        // removed from $bp_uri. This includes two cases:
+        // 
+        //    1. when WP is installed in a subdirectory,
+        //    2. when BP is running on secondary blog of a subdirectory
+        //       multisite installation. Phew!
</ins><span class="cx">         if ( is_multisite() &amp;&amp; !is_subdomain_install() &amp;&amp; ( bp_is_multiblog_mode() || 1 != bp_get_root_blog_id() ) ) {
</span><span class="cx"> 
</span><del>-                // Any subdirectory names must be removed from $bp_uri.
-                // This includes two cases: (1) when WP is installed in a subdirectory,
-                // and (2) when BP is running on secondary blog of a subdirectory
-                // multisite installation. Phew!
-                if ( $chunks = explode( '/', $current_blog-&gt;path ) ) {
</del><ins>+                // Blow chunks
+                $chunks = explode( '/', $current_blog-&gt;path );
+
+                // If chunks exist...
+                if ( !empty( $chunks ) ) {
+
+                        // ...loop through them...
</ins><span class="cx">                         foreach( $chunks as $key =&gt; $chunk ) {
</span><span class="cx">                                 $bkey = array_search( $chunk, $bp_uri );
</span><span class="cx"> 
</span><del>-                                if ( $bkey !== false ) {
</del><ins>+                                // ...and unset offending keys
+                                if ( false !== $bkey ) {
</ins><span class="cx">                                         unset( $bp_uri[$bkey] );
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><span class="lines">@@ -80,10 +101,6 @@
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        // Set the indexes, these are incresed by one if we are not on a VHOST install
-        $component_index = 0;
-        $action_index    = $component_index + 1;
-
</del><span class="cx">         // Get site path items
</span><span class="cx">         $paths = explode( '/', bp_core_get_site_path() );
</span><span class="cx"> 
</span><span class="lines">@@ -177,7 +194,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // URLs with BP_ENABLE_ROOT_PROFILES enabled won't be caught above
</span><del>-        if ( empty( $matches ) &amp;&amp; defined( 'BP_ENABLE_ROOT_PROFILES' ) &amp;&amp; BP_ENABLE_ROOT_PROFILES ) {
</del><ins>+        if ( empty( $matches ) &amp;&amp; bp_core_enable_root_profiles() ) {
</ins><span class="cx"> 
</span><span class="cx">                 // Make sure there's a user corresponding to $bp_uri[0]
</span><span class="cx">                 if ( !empty( $bp-&gt;pages-&gt;members ) &amp;&amp; !empty( $bp_uri[0] ) &amp;&amp; $root_profile = get_user_by( 'login', $bp_uri[0] ) ) {
</span><span class="lines">@@ -295,6 +312,22 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Are root profiles enabled and allowed
+ * 
+ * @since BuddyPress (1.6)
+ * @return bool True if yes, false if no
+ */
+function bp_core_enable_root_profiles() {
+        
+        $retval = false;
+
+        if ( defined( 'BP_ENABLE_ROOT_PROFILES' ) &amp;&amp; ( true == BP_ENABLE_ROOT_PROFILES ) )
+                $retval = true;
+        
+        return apply_filters( 'bp_core_enable_root_profiles', $retval );
+}
+
+/**
</ins><span class="cx">  * bp_core_load_template()
</span><span class="cx">  *
</span><span class="cx">  * Load a specific template file with fallback support.
</span><span class="lines">@@ -309,16 +342,20 @@
</span><span class="cx">  * @return false|int The user ID of the matched user, or false.
</span><span class="cx">  */
</span><span class="cx"> function bp_core_load_template( $templates ) {
</span><del>-        global $post, $bp, $wpdb, $wp_query;
</del><ins>+        global $post, $bp, $wp_query;
</ins><span class="cx"> 
</span><del>-        // Determine if the root object WP page exists for this request (TODO: is there an API function for this?
-        if ( !empty( $bp-&gt;unfiltered_uri_offset ) &amp;&amp; !$page_exists = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT ID FROM {$wpdb-&gt;posts} WHERE post_name = %s&quot;, $bp-&gt;unfiltered_uri[$bp-&gt;unfiltered_uri_offset] ) ) )
</del><ins>+        // Bail if there is no offset
+        if ( empty( $bp-&gt;unfiltered_uri[$bp-&gt;unfiltered_uri_offset] ) )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><ins>+        // Determine if the root object WP page exists for this request
+        if ( !get_page_by_path( $bp-&gt;unfiltered_uri[$bp-&gt;unfiltered_uri_offset] ) )
+                return false;
+
</ins><span class="cx">         // Set the root object as the current wp_query-ied item
</span><span class="cx">         $object_id = 0;
</span><del>-        foreach ( (array)$bp-&gt;pages as $page ) {
-                if ( isset( $bp-&gt;unfiltered_uri[$bp-&gt;unfiltered_uri_offset] ) &amp;&amp; ( $page-&gt;name == $bp-&gt;unfiltered_uri[$bp-&gt;unfiltered_uri_offset] ) ) {
</del><ins>+        foreach ( (array) $bp-&gt;pages as $page ) {
+                if ( $page-&gt;name == $bp-&gt;unfiltered_uri[$bp-&gt;unfiltered_uri_offset] ) {
</ins><span class="cx">                         $object_id = $page-&gt;id;
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="lines">@@ -330,12 +367,18 @@
</span><span class="cx">                 $post                        = $wp_query-&gt;queried_object;
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        // Define local variables
+        $located_template   = false;
+        $filtered_templates = array();
+
</ins><span class="cx">         // Fetch each template and add the php suffix
</span><del>-        foreach ( (array)$templates as $template )
</del><ins>+        foreach ( (array) $templates as $template )
</ins><span class="cx">                 $filtered_templates[] = $template . '.php';
</span><span class="cx"> 
</span><span class="cx">         // Filter the template locations so that plugins can alter where they are located
</span><del>-        if ( $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ) ) {
</del><ins>+        $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates );
+        if ( !empty( $located_template ) ) {
+
</ins><span class="cx">                 // Template was located, lets set this as a valid page and not a 404.
</span><span class="cx">                 status_header( 200 );
</span><span class="cx">                 $wp_query-&gt;is_page = $wp_query-&gt;is_singular = true;
</span><span class="lines">@@ -404,10 +447,11 @@
</span><span class="cx">         extract( $r, EXTR_SKIP );
</span><span class="cx"> 
</span><span class="cx">         // Apply filters to these variables
</span><del>-        $mode                = apply_filters( 'bp_no_access_mode', $mode, $root, $redirect, $message );
-        $redirect        = apply_filters( 'bp_no_access_redirect', $redirect, $root, $message, $mode );
-        $root                = trailingslashit( apply_filters( 'bp_no_access_root', $root, $redirect, $message, $mode ) );
-        $message        = apply_filters( 'bp_no_access_message', $message, $root, $redirect, $mode );
</del><ins>+        $mode                = apply_filters( 'bp_no_access_mode',     $mode,     $root,     $redirect, $message );
+        $redirect        = apply_filters( 'bp_no_access_redirect', $redirect, $root,     $message,  $mode    );
+        $root                = apply_filters( 'bp_no_access_root',     $root,     $redirect, $message,  $mode    );
+        $message        = apply_filters( 'bp_no_access_message',  $message,  $root,     $redirect, $mode    );
+        $root       = trailingslashit( $root );
</ins><span class="cx"> 
</span><span class="cx">         switch ( $mode ) {
</span><span class="cx">                 // Option to redirect to wp-login.php
</span></span></pre></div>
<a id="trunkbpmembersbpmembersfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-members/bp-members-functions.php (5318 => 5319)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-members/bp-members-functions.php        2011-11-09 06:31:07 UTC (rev 5318)
+++ trunk/bp-members/bp-members-functions.php        2011-11-09 06:38:28 UTC (rev 5319)
</span><span class="lines">@@ -109,18 +109,14 @@
</span><span class="cx">                 if ( bp_is_username_compatibility_mode() )
</span><span class="cx">                         $username = rawurlencode( $username );
</span><span class="cx"> 
</span><del>-                // If we are using a members slug, include it.
-                if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
-                        $domain = bp_get_root_domain() . '/' . bp_get_members_root_slug() . '/' . $username;
-                else
-                        $domain = bp_get_root_domain() . '/' . $username;
</del><ins>+                $after_domain = bp_core_enable_root_profiles() ? $username : bp_get_members_root_slug() . '/' . $username;
+                $domain       = trailingslashit( bp_get_root_domain() . '/' . $after_domain );
+                $domain       = apply_filters( 'bp_core_get_user_domain_pre_cache', $domain, $user_id, $user_nicename, $user_login );
</ins><span class="cx"> 
</span><del>-                // Add a slash at the end, and filter before caching
-                $domain = apply_filters( 'bp_core_get_user_domain_pre_cache', trailingslashit( $domain ), $user_id, $user_nicename, $user_login );
-
</del><span class="cx">                 // Cache the link
</span><del>-                if ( !empty( $domain ) )
</del><ins>+                if ( !empty( $domain ) ) {
</ins><span class="cx">                         wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
</span><ins>+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         return apply_filters( 'bp_core_get_user_domain', $domain, $user_id, $user_nicename, $user_login );
</span></span></pre>
</div>
</div>

</body>
</html>