Skip to:
Content

BuddyPress.org

Changeset 8700


Ignore:
Timestamp:
07/27/2014 04:20:42 PM (10 years ago)
Author:
johnjamesjacoby
Message:

More nit-picky code clean-up to bp-core-template.php.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-template.php

    r8698 r8700  
    2424 * to determine whether or not to highlight a particular sub nav item.
    2525 *
    26  * @global BuddyPress $bp The one true BuddyPress instance.
    2726 * @uses bp_get_user_nav() Renders the navigation for a profile of a currently
    2827 *       viewed user.
     
    104103
    105104    // If none is found, concatenate
    106     } else if ( isset( buddypress()->{$component}->name ) ) {
     105    } elseif ( isset( buddypress()->{$component}->name ) ) {
    107106        $title = sprintf( __( '%s Directory', 'buddypress' ), buddypress()->{$component}->name );
    108107    }
     
    540539    $filter_shortcodes_default = is_bool( $options ) ? $options : true;
    541540
    542     $r = wp_parse_args( $options, array(
     541    $r = bp_parse_args( $options, array(
    543542        'ending'            => __( ' […]', 'buddypress' ),
    544543        'exact'             => false,
    545544        'html'              => true,
    546545        'filter_shortcodes' => $filter_shortcodes_default
    547     ) );
    548     extract( $r );
     546    ), 'create_excerpt' );
    549547
    550548    // Save the original text, to be passed along to the filter
     
    552550
    553551    // Allow plugins to modify these values globally
    554     $length = apply_filters( 'bp_excerpt_length', $length );
    555     $ending = apply_filters( 'bp_excerpt_append_text', $ending );
     552    $length = apply_filters( 'bp_excerpt_length',      $length      );
     553    $ending = apply_filters( 'bp_excerpt_append_text', $r['ending'] );
    556554
    557555    // Remove shortcodes if necessary
    558     if ( ! empty( $filter_shortcodes ) ) {
     556    if ( ! empty( $r['filter_shortcodes'] ) ) {
    559557        $text = strip_shortcodes( $text );
    560558    }
     
    562560    // When $html is true, the excerpt should be created without including HTML tags in the
    563561    // excerpt length
    564     if ( ! empty( $html ) ) {
     562    if ( ! empty( $r['html'] ) ) {
     563
    565564        // The text is short enough. No need to truncate
    566565        if ( mb_strlen( preg_replace( '/<.*?>/', '', $text ) ) <= $length ) {
     
    575574        preg_match_all( '/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER );
    576575        foreach ( $tags as $tag ) {
     576
    577577            // Process tags that need to be closed
    578578            if ( !preg_match( '/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s',  $tag[2] ) ) {
    579579                if ( preg_match( '/<[\w]+[^>]*>/s', $tag[0] ) ) {
    580580                    array_unshift( $openTags, $tag[2] );
    581                 } else if ( preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag ) ) {
     581                } elseif ( preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag ) ) {
    582582                    $pos = array_search( $closeTag[1], $openTags );
    583583                    if ( $pos !== false ) {
     
    586586                }
    587587            }
    588             $truncate .= $tag[1];
    589 
     588
     589            $truncate     .= $tag[1];
    590590            $contentLength = mb_strlen( preg_replace( '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $tag[3] ) );
     591
    591592            if ( $contentLength + $totalLength > $length ) {
    592593                $left = $length - $totalLength;
     
    622623
    623624    // If $exact is false, we can't break on words
    624     if ( empty( $exact ) ) {
     625    if ( empty( $r['exact'] ) ) {
    625626        $spacepos = mb_strrpos( $truncate, ' ' );
    626627        if ( isset( $spacepos ) ) {
    627             if ( $html ) {
     628            if ( $r['html'] ) {
    628629                $bits = mb_substr( $truncate, $spacepos );
    629630                preg_match_all( '/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER );
     
    641642    $truncate .= $ending;
    642643
    643     if ( $html ) {
     644    if ( !empty( $r['html'] ) ) {
    644645        foreach ( $openTags as $tag ) {
    645646            $truncate .= '</' . $tag . '>';
     
    648649
    649650    return apply_filters( 'bp_create_excerpt', $truncate, $original_text, $length, $options );
    650 
    651 }
    652 add_filter( 'bp_create_excerpt', 'stripslashes_deep' );
     651}
     652add_filter( 'bp_create_excerpt', 'stripslashes_deep'  );
    653653add_filter( 'bp_create_excerpt', 'force_balance_tags' );
    654654
     
    805805function bp_current_component() {
    806806    $bp                = buddypress();
    807     $current_component = !empty( $bp->current_component ) ? $bp->current_component : false;
     807    $current_component = !empty( $bp->current_component )
     808        ? $bp->current_component
     809        : false;
     810
    808811    return apply_filters( 'bp_current_component', $current_component );
    809812}
     
    815818 */
    816819function bp_current_action() {
    817     $bp            = buddypress();
    818     $current_action = !empty( $bp->current_action ) ? $bp->current_action : '';
     820    $bp             = buddypress();
     821    $current_action = !empty( $bp->current_action )
     822        ? $bp->current_action
     823        : '';
     824
    819825    return apply_filters( 'bp_current_action', $current_action );
    820826}
     
    827833function bp_current_item() {
    828834    $bp           = buddypress();
    829     $current_item = !empty( $bp->current_item ) ? $bp->current_item : false;
     835    $current_item = !empty( $bp->current_item )
     836        ? $bp->current_item
     837        : false;
     838
    830839    return apply_filters( 'bp_current_item', $current_item );
    831840}
     
    839848function bp_action_variables() {
    840849    $bp               = buddypress();
    841     $action_variables = !empty( $bp->action_variables ) ? $bp->action_variables : false;
     850    $action_variables = !empty( $bp->action_variables )
     851        ? $bp->action_variables
     852        : false;
     853
    842854    return apply_filters( 'bp_action_variables', $action_variables );
    843855}
     
    854866function bp_action_variable( $position = 0 ) {
    855867    $action_variables = bp_action_variables();
    856     $action_variable  = isset( $action_variables[$position] ) ? $action_variables[$position] : false;
     868    $action_variable  = isset( $action_variables[ $position ] )
     869        ? $action_variables[ $position ]
     870        : false;
    857871
    858872    return apply_filters( 'bp_action_variable', $action_variable, $position );
     
    873887        $bp = buddypress();
    874888
    875         if ( isset( $bp->root_domain ) && !empty( $bp->root_domain ) ) {
     889        if ( ! empty( $bp->root_domain ) ) {
    876890            $domain = $bp->root_domain;
    877891        } else {
     
    920934     * @since BuddyPress (1.5.0)
    921935     *
    922      * @global BuddyPress $bp The one true BuddyPress instance.
    923      *
    924936     * @param string $component Optional. Defaults to the current component.
    925937     * @return string $root_slug The root slug.
     
    935947
    936948        // Component is active
    937         if ( !empty( $bp->active_components[$component] ) ) {
     949        if ( ! empty( $bp->active_components[ $component ] ) ) {
     950
    938951            // Backward compatibility: in legacy plugins, the canonical component id
    939952            // was stored as an array value in $bp->active_components
    940             $component_name = '1' == $bp->active_components[$component] ? $component : $bp->active_components[$component];
     953            $component_name = ( '1' == $bp->active_components[ $component ] )
     954                ? $component
     955                : $bp->active_components[$component];
    941956
    942957            // Component has specific root slug
    943             if ( !empty( $bp->{$component_name}->root_slug ) ) {
     958            if ( ! empty( $bp->{$component_name}->root_slug ) ) {
    944959                $root_slug = $bp->{$component_name}->root_slug;
    945960            }
     
    959974 * @since BuddyPress (1.5.0)
    960975 *
    961  * @global BuddyPress $bp The one true BuddyPress instance.
    962  *
    963976 * @param string $root_slug Needle to our active component haystack.
    964977 * @return mixed False if none found, component name if found.
     
    979992    // Loop through active components and look for a match
    980993    foreach ( array_keys( $bp->active_components ) as $component ) {
    981         if ( ( !empty( $bp->{$component}->slug ) && ( $bp->{$component}->slug == $root_slug ) ) || ( !empty( $bp->{$component}->root_slug ) && ( $bp->{$component}->root_slug == $root_slug ) ) ) {
     994        if ( ( ! empty( $bp->{$component}->slug ) && ( $bp->{$component}->slug == $root_slug ) ) || ( ! empty( $bp->{$component}->root_slug ) && ( $bp->{$component}->root_slug === $root_slug ) ) ) {
    982995            return $bp->{$component}->name;
    983996        }
     
    9881001
    9891002function bp_user_has_access() {
    990     $has_access = ( bp_current_user_can( 'bp_moderate' ) || bp_is_my_profile() ) ? true : false;
    991 
    992     return apply_filters( 'bp_user_has_access', $has_access );
     1003    $has_access = ( bp_current_user_can( 'bp_moderate' ) || bp_is_my_profile() )
     1004        ? true
     1005        : false;
     1006
     1007    return (bool) apply_filters( 'bp_user_has_access', $has_access );
    9931008}
    9941009
     
    10231038function bp_displayed_user_id() {
    10241039    $bp = buddypress();
    1025     $id = !empty( $bp->displayed_user->id ) ? $bp->displayed_user->id : 0;
     1040    $id = !empty( $bp->displayed_user->id )
     1041        ? $bp->displayed_user->id
     1042        : 0;
    10261043
    10271044    return (int) apply_filters( 'bp_displayed_user_id', $id );
     
    10371054function bp_loggedin_user_id() {
    10381055    $bp = buddypress();
    1039     $id = !empty( $bp->loggedin_user->id ) ? $bp->loggedin_user->id : 0;
     1056    $id = !empty( $bp->loggedin_user->id )
     1057        ? $bp->loggedin_user->id
     1058        : 0;
    10401059
    10411060    return (int) apply_filters( 'bp_loggedin_user_id', $id );
     
    10591078 */
    10601079function bp_is_current_component( $component ) {
    1061     global $bp, $wp_query;
     1080    global $wp_query;
    10621081
    10631082    $is_current_component = false;
     
    10721091        $component = 'profile';
    10731092    }
     1093
     1094    $bp = buddypress();
    10741095
    10751096    if ( ! empty( $bp->current_component ) ) {
     
    10921113        // non-translatable component name. If so, we can return its
    10931114        // corresponding slug from $bp->active_components.
    1094         } else if ( $key = array_search( $component, $bp->active_components ) ) {
     1115        } elseif ( $key = array_search( $component, $bp->active_components ) ) {
    10951116            if ( strstr( $bp->current_component, $key ) ) {
    10961117                $is_current_component = true;
     
    11511172 */
    11521173function bp_is_current_action( $action = '' ) {
    1153     if ( $action === bp_current_action() ) {
    1154         return true;
    1155     }
    1156 
    1157     return false;
     1174    return (bool) ( $action === bp_current_action() );
    11581175}
    11591176
     
    14491466 */
    14501467function bp_is_blogs_component() {
    1451     if ( is_multisite() && bp_is_current_component( 'blogs' ) )
    1452         return true;
    1453 
    1454     return false;
     1468    return (bool) ( is_multisite() && bp_is_current_component( 'blogs' ) );
    14551469}
    14561470
Note: See TracChangeset for help on using the changeset viewer.