<!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][8700] trunk/src/bp-core/bp-core-template.php: More nit-picky code clean-up to `bp-core-template.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 { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { 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/8700">8700</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2014-07-27 16:20:42 +0000 (Sun, 27 Jul 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>More nit-picky code clean-up to `bp-core-template.php`.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpcorebpcoretemplatephp">trunk/src/bp-core/bp-core-template.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpcorebpcoretemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/src/bp-core/bp-core-template.php (8699 => 8700)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/bp-core/bp-core-template.php   2014-07-27 16:19:40 UTC (rev 8699)
+++ trunk/src/bp-core/bp-core-template.php      2014-07-27 16:20:42 UTC (rev 8700)
</span><span class="lines">@@ -23,7 +23,6 @@
</span><span class="cx">  * The function will also analyze the current action for the current component
</span><span class="cx">  * to determine whether or not to highlight a particular sub nav item.
</span><span class="cx">  *
</span><del>- * @global BuddyPress $bp The one true BuddyPress instance.
</del><span class="cx">  * @uses bp_get_user_nav() Renders the navigation for a profile of a currently
</span><span class="cx">  *       viewed user.
</span><span class="cx">  */
</span><span class="lines">@@ -103,7 +102,7 @@
</span><span class="cx">          $title = buddypress()->{$component}->directory_title;
</span><span class="cx"> 
</span><span class="cx">  // If none is found, concatenate
</span><del>-       } else if ( isset( buddypress()->{$component}->name ) ) {
</del><ins>+        } elseif ( isset( buddypress()->{$component}->name ) ) {
</ins><span class="cx">           $title = sprintf( __( '%s Directory', 'buddypress' ), buddypress()->{$component}->name );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="lines">@@ -539,29 +538,29 @@
</span><span class="cx">  // Backward compatibility. The third argument used to be a boolean $filter_shortcodes
</span><span class="cx">  $filter_shortcodes_default = is_bool( $options ) ? $options : true;
</span><span class="cx"> 
</span><del>-       $r = wp_parse_args( $options, array(
</del><ins>+        $r = bp_parse_args( $options, array(
</ins><span class="cx">           'ending'            => __( ' [&hellip;]', 'buddypress' ),
</span><span class="cx">          'exact'             => false,
</span><span class="cx">          'html'              => true,
</span><span class="cx">          'filter_shortcodes' => $filter_shortcodes_default
</span><del>-       ) );
-       extract( $r );
</del><ins>+        ), 'create_excerpt' );
</ins><span class="cx"> 
</span><span class="cx">  // Save the original text, to be passed along to the filter
</span><span class="cx">  $original_text = $text;
</span><span class="cx"> 
</span><span class="cx">  // Allow plugins to modify these values globally
</span><del>-       $length = apply_filters( 'bp_excerpt_length', $length );
-       $ending = apply_filters( 'bp_excerpt_append_text', $ending );
</del><ins>+        $length = apply_filters( 'bp_excerpt_length',      $length      );
+       $ending = apply_filters( 'bp_excerpt_append_text', $r['ending'] );
</ins><span class="cx"> 
</span><span class="cx">  // Remove shortcodes if necessary
</span><del>-       if ( ! empty( $filter_shortcodes ) ) {
</del><ins>+        if ( ! empty( $r['filter_shortcodes'] ) ) {
</ins><span class="cx">           $text = strip_shortcodes( $text );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  // When $html is true, the excerpt should be created without including HTML tags in the
</span><span class="cx">  // excerpt length
</span><del>-       if ( ! empty( $html ) ) {
</del><ins>+        if ( ! empty( $r['html'] ) ) {
+
</ins><span class="cx">           // The text is short enough. No need to truncate
</span><span class="cx">          if ( mb_strlen( preg_replace( '/<.*?>/', '', $text ) ) <= $length ) {
</span><span class="cx">                  return $text;
</span><span class="lines">@@ -574,20 +573,22 @@
</span><span class="cx">          // Find all the tags and put them in a stack for later use
</span><span class="cx">          preg_match_all( '/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER );
</span><span class="cx">          foreach ( $tags as $tag ) {
</span><ins>+
</ins><span class="cx">                   // Process tags that need to be closed
</span><span class="cx">                  if ( !preg_match( '/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s',  $tag[2] ) ) {
</span><span class="cx">                          if ( preg_match( '/<[\w]+[^>]*>/s', $tag[0] ) ) {
</span><span class="cx">                                  array_unshift( $openTags, $tag[2] );
</span><del>-                               } else if ( preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag ) ) {
</del><ins>+                                } elseif ( preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag ) ) {
</ins><span class="cx">                                   $pos = array_search( $closeTag[1], $openTags );
</span><span class="cx">                                  if ( $pos !== false ) {
</span><span class="cx">                                          array_splice( $openTags, $pos, 1 );
</span><span class="cx">                                  }
</span><span class="cx">                          }
</span><span class="cx">                  }
</span><del>-                       $truncate .= $tag[1];
</del><span class="cx"> 
</span><ins>+                       $truncate     .= $tag[1];
</ins><span class="cx">                   $contentLength = mb_strlen( preg_replace( '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $tag[3] ) );
</span><ins>+
</ins><span class="cx">                   if ( $contentLength + $totalLength > $length ) {
</span><span class="cx">                          $left = $length - $totalLength;
</span><span class="cx">                          $entitiesLength = 0;
</span><span class="lines">@@ -621,10 +622,10 @@
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  // If $exact is false, we can't break on words
</span><del>-       if ( empty( $exact ) ) {
</del><ins>+        if ( empty( $r['exact'] ) ) {
</ins><span class="cx">           $spacepos = mb_strrpos( $truncate, ' ' );
</span><span class="cx">          if ( isset( $spacepos ) ) {
</span><del>-                       if ( $html ) {
</del><ins>+                        if ( $r['html'] ) {
</ins><span class="cx">                           $bits = mb_substr( $truncate, $spacepos );
</span><span class="cx">                          preg_match_all( '/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER );
</span><span class="cx">                          if ( !empty( $droppedTags ) ) {
</span><span class="lines">@@ -640,16 +641,15 @@
</span><span class="cx">  }
</span><span class="cx">  $truncate .= $ending;
</span><span class="cx"> 
</span><del>-       if ( $html ) {
</del><ins>+        if ( !empty( $r['html'] ) ) {
</ins><span class="cx">           foreach ( $openTags as $tag ) {
</span><span class="cx">                  $truncate .= '</' . $tag . '>';
</span><span class="cx">          }
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  return apply_filters( 'bp_create_excerpt', $truncate, $original_text, $length, $options );
</span><del>-
</del><span class="cx"> }
</span><del>-add_filter( 'bp_create_excerpt', 'stripslashes_deep' );
</del><ins>+add_filter( 'bp_create_excerpt', 'stripslashes_deep'  );
</ins><span class="cx"> add_filter( 'bp_create_excerpt', 'force_balance_tags' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -804,7 +804,10 @@
</span><span class="cx">  */
</span><span class="cx"> function bp_current_component() {
</span><span class="cx">  $bp                = buddypress();
</span><del>-       $current_component = !empty( $bp->current_component ) ? $bp->current_component : false;
</del><ins>+        $current_component = !empty( $bp->current_component )
+               ? $bp->current_component
+               : false;
+
</ins><span class="cx">   return apply_filters( 'bp_current_component', $current_component );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -814,8 +817,11 @@
</span><span class="cx">  * @return string Action name.
</span><span class="cx">  */
</span><span class="cx"> function bp_current_action() {
</span><del>-       $bp            = buddypress();
-       $current_action = !empty( $bp->current_action ) ? $bp->current_action : '';
</del><ins>+        $bp             = buddypress();
+       $current_action = !empty( $bp->current_action )
+               ? $bp->current_action
+               : '';
+
</ins><span class="cx">   return apply_filters( 'bp_current_action', $current_action );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -826,7 +832,10 @@
</span><span class="cx">  */
</span><span class="cx"> function bp_current_item() {
</span><span class="cx">  $bp           = buddypress();
</span><del>-       $current_item = !empty( $bp->current_item ) ? $bp->current_item : false;
</del><ins>+        $current_item = !empty( $bp->current_item )
+               ? $bp->current_item
+               : false;
+
</ins><span class="cx">   return apply_filters( 'bp_current_item', $current_item );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -838,7 +847,10 @@
</span><span class="cx">  */
</span><span class="cx"> function bp_action_variables() {
</span><span class="cx">  $bp               = buddypress();
</span><del>-       $action_variables = !empty( $bp->action_variables ) ? $bp->action_variables : false;
</del><ins>+        $action_variables = !empty( $bp->action_variables )
+               ? $bp->action_variables
+               : false;
+
</ins><span class="cx">   return apply_filters( 'bp_action_variables', $action_variables );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -853,7 +865,9 @@
</span><span class="cx">  */
</span><span class="cx"> function bp_action_variable( $position = 0 ) {
</span><span class="cx">  $action_variables = bp_action_variables();
</span><del>-       $action_variable  = isset( $action_variables[$position] ) ? $action_variables[$position] : false;
</del><ins>+        $action_variable  = isset( $action_variables[ $position ] )
+               ? $action_variables[ $position ]
+               : false;
</ins><span class="cx"> 
</span><span class="cx">  return apply_filters( 'bp_action_variable', $action_variable, $position );
</span><span class="cx"> }
</span><span class="lines">@@ -872,7 +886,7 @@
</span><span class="cx">  function bp_get_root_domain() {
</span><span class="cx">          $bp = buddypress();
</span><span class="cx"> 
</span><del>-               if ( isset( $bp->root_domain ) && !empty( $bp->root_domain ) ) {
</del><ins>+                if ( ! empty( $bp->root_domain ) ) {
</ins><span class="cx">                   $domain = $bp->root_domain;
</span><span class="cx">          } else {
</span><span class="cx">                  $domain          = bp_core_get_root_domain();
</span><span class="lines">@@ -919,8 +933,6 @@
</span><span class="cx">   *
</span><span class="cx">   * @since BuddyPress (1.5.0)
</span><span class="cx">   *
</span><del>-        * @global BuddyPress $bp The one true BuddyPress instance.
-        *
</del><span class="cx">    * @param string $component Optional. Defaults to the current component.
</span><span class="cx">   * @return string $root_slug The root slug.
</span><span class="cx">   */
</span><span class="lines">@@ -934,13 +946,16 @@
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="cx">          // Component is active
</span><del>-               if ( !empty( $bp->active_components[$component] ) ) {
</del><ins>+                if ( ! empty( $bp->active_components[ $component ] ) ) {
+
</ins><span class="cx">                   // Backward compatibility: in legacy plugins, the canonical component id
</span><span class="cx">                  // was stored as an array value in $bp->active_components
</span><del>-                       $component_name = '1' == $bp->active_components[$component] ? $component : $bp->active_components[$component];
</del><ins>+                        $component_name = ( '1' == $bp->active_components[ $component ] )
+                               ? $component
+                               : $bp->active_components[$component];
</ins><span class="cx"> 
</span><span class="cx">                  // Component has specific root slug
</span><del>-                       if ( !empty( $bp->{$component_name}->root_slug ) ) {
</del><ins>+                        if ( ! empty( $bp->{$component_name}->root_slug ) ) {
</ins><span class="cx">                           $root_slug = $bp->{$component_name}->root_slug;
</span><span class="cx">                  }
</span><span class="cx">          }
</span><span class="lines">@@ -958,8 +973,6 @@
</span><span class="cx">  *
</span><span class="cx">  * @since BuddyPress (1.5.0)
</span><span class="cx">  *
</span><del>- * @global BuddyPress $bp The one true BuddyPress instance.
- *
</del><span class="cx">  * @param string $root_slug Needle to our active component haystack.
</span><span class="cx">  * @return mixed False if none found, component name if found.
</span><span class="cx">  */
</span><span class="lines">@@ -978,7 +991,7 @@
</span><span class="cx"> 
</span><span class="cx">  // Loop through active components and look for a match
</span><span class="cx">  foreach ( array_keys( $bp->active_components ) as $component ) {
</span><del>-               if ( ( !empty( $bp->{$component}->slug ) && ( $bp->{$component}->slug == $root_slug ) ) || ( !empty( $bp->{$component}->root_slug ) && ( $bp->{$component}->root_slug == $root_slug ) ) ) {
</del><ins>+                if ( ( ! empty( $bp->{$component}->slug ) && ( $bp->{$component}->slug == $root_slug ) ) || ( ! empty( $bp->{$component}->root_slug ) && ( $bp->{$component}->root_slug === $root_slug ) ) ) {
</ins><span class="cx">                   return $bp->{$component}->name;
</span><span class="cx">          }
</span><span class="cx">  }
</span><span class="lines">@@ -987,9 +1000,11 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function bp_user_has_access() {
</span><del>-       $has_access = ( bp_current_user_can( 'bp_moderate' ) || bp_is_my_profile() ) ? true : false;
</del><ins>+        $has_access = ( bp_current_user_can( 'bp_moderate' ) || bp_is_my_profile() )
+               ? true
+               : false;
</ins><span class="cx"> 
</span><del>-       return apply_filters( 'bp_user_has_access', $has_access );
</del><ins>+        return (bool) apply_filters( 'bp_user_has_access', $has_access );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -1022,7 +1037,9 @@
</span><span class="cx">  */
</span><span class="cx"> function bp_displayed_user_id() {
</span><span class="cx">  $bp = buddypress();
</span><del>-       $id = !empty( $bp->displayed_user->id ) ? $bp->displayed_user->id : 0;
</del><ins>+        $id = !empty( $bp->displayed_user->id )
+               ? $bp->displayed_user->id
+               : 0;
</ins><span class="cx"> 
</span><span class="cx">  return (int) apply_filters( 'bp_displayed_user_id', $id );
</span><span class="cx"> }
</span><span class="lines">@@ -1036,7 +1053,9 @@
</span><span class="cx">  */
</span><span class="cx"> function bp_loggedin_user_id() {
</span><span class="cx">  $bp = buddypress();
</span><del>-       $id = !empty( $bp->loggedin_user->id ) ? $bp->loggedin_user->id : 0;
</del><ins>+        $id = !empty( $bp->loggedin_user->id )
+               ? $bp->loggedin_user->id
+               : 0;
</ins><span class="cx"> 
</span><span class="cx">  return (int) apply_filters( 'bp_loggedin_user_id', $id );
</span><span class="cx"> }
</span><span class="lines">@@ -1058,7 +1077,7 @@
</span><span class="cx">  * @return bool Returns true if the component matches, or else false.
</span><span class="cx">  */
</span><span class="cx"> function bp_is_current_component( $component ) {
</span><del>-       global $bp, $wp_query;
</del><ins>+        global $wp_query;
</ins><span class="cx"> 
</span><span class="cx">  $is_current_component = false;
</span><span class="cx"> 
</span><span class="lines">@@ -1072,6 +1091,8 @@
</span><span class="cx">          $component = 'profile';
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       $bp = buddypress();
+
</ins><span class="cx">   if ( ! empty( $bp->current_component ) ) {
</span><span class="cx"> 
</span><span class="cx">          // First, check to see whether $component_name and the current
</span><span class="lines">@@ -1091,7 +1112,7 @@
</span><span class="cx">          // Next, check to see whether $component is a canonical,
</span><span class="cx">          // non-translatable component name. If so, we can return its
</span><span class="cx">          // corresponding slug from $bp->active_components.
</span><del>-               } else if ( $key = array_search( $component, $bp->active_components ) ) {
</del><ins>+                } elseif ( $key = array_search( $component, $bp->active_components ) ) {
</ins><span class="cx">                   if ( strstr( $bp->current_component, $key ) ) {
</span><span class="cx">                          $is_current_component = true;
</span><span class="cx">                  }
</span><span class="lines">@@ -1150,11 +1171,7 @@
</span><span class="cx">  * @return bool True if the current action matches $action.
</span><span class="cx">  */
</span><span class="cx"> function bp_is_current_action( $action = '' ) {
</span><del>-       if ( $action === bp_current_action() ) {
-               return true;
-       }
-
-       return false;
</del><ins>+        return (bool) ( $action === bp_current_action() );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -1448,10 +1465,7 @@
</span><span class="cx">  * @return bool True if the current page is part of the Blogs component.
</span><span class="cx">  */
</span><span class="cx"> function bp_is_blogs_component() {
</span><del>-       if ( is_multisite() && bp_is_current_component( 'blogs' ) )
-               return true;
-
-       return false;
</del><ins>+        return (bool) ( is_multisite() && bp_is_current_component( 'blogs' ) );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>

</body>
</html>