Changeset 8700
- Timestamp:
- 07/27/2014 04:20:42 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-template.php
r8698 r8700 24 24 * to determine whether or not to highlight a particular sub nav item. 25 25 * 26 * @global BuddyPress $bp The one true BuddyPress instance.27 26 * @uses bp_get_user_nav() Renders the navigation for a profile of a currently 28 27 * viewed user. … … 104 103 105 104 // If none is found, concatenate 106 } else 105 } elseif ( isset( buddypress()->{$component}->name ) ) { 107 106 $title = sprintf( __( '%s Directory', 'buddypress' ), buddypress()->{$component}->name ); 108 107 } … … 540 539 $filter_shortcodes_default = is_bool( $options ) ? $options : true; 541 540 542 $r = wp_parse_args( $options, array(541 $r = bp_parse_args( $options, array( 543 542 'ending' => __( ' […]', 'buddypress' ), 544 543 'exact' => false, 545 544 'html' => true, 546 545 'filter_shortcodes' => $filter_shortcodes_default 547 ) ); 548 extract( $r ); 546 ), 'create_excerpt' ); 549 547 550 548 // Save the original text, to be passed along to the filter … … 552 550 553 551 // 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'] ); 556 554 557 555 // Remove shortcodes if necessary 558 if ( ! empty( $ filter_shortcodes) ) {556 if ( ! empty( $r['filter_shortcodes'] ) ) { 559 557 $text = strip_shortcodes( $text ); 560 558 } … … 562 560 // When $html is true, the excerpt should be created without including HTML tags in the 563 561 // excerpt length 564 if ( ! empty( $html ) ) { 562 if ( ! empty( $r['html'] ) ) { 563 565 564 // The text is short enough. No need to truncate 566 565 if ( mb_strlen( preg_replace( '/<.*?>/', '', $text ) ) <= $length ) { … … 575 574 preg_match_all( '/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER ); 576 575 foreach ( $tags as $tag ) { 576 577 577 // Process tags that need to be closed 578 578 if ( !preg_match( '/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2] ) ) { 579 579 if ( preg_match( '/<[\w]+[^>]*>/s', $tag[0] ) ) { 580 580 array_unshift( $openTags, $tag[2] ); 581 } else 581 } elseif ( preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag ) ) { 582 582 $pos = array_search( $closeTag[1], $openTags ); 583 583 if ( $pos !== false ) { … … 586 586 } 587 587 } 588 $truncate .= $tag[1]; 589 588 589 $truncate .= $tag[1]; 590 590 $contentLength = mb_strlen( preg_replace( '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $tag[3] ) ); 591 591 592 if ( $contentLength + $totalLength > $length ) { 592 593 $left = $length - $totalLength; … … 622 623 623 624 // If $exact is false, we can't break on words 624 if ( empty( $ exact) ) {625 if ( empty( $r['exact'] ) ) { 625 626 $spacepos = mb_strrpos( $truncate, ' ' ); 626 627 if ( isset( $spacepos ) ) { 627 if ( $ html) {628 if ( $r['html'] ) { 628 629 $bits = mb_substr( $truncate, $spacepos ); 629 630 preg_match_all( '/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER ); … … 641 642 $truncate .= $ending; 642 643 643 if ( $html) {644 if ( !empty( $r['html'] ) ) { 644 645 foreach ( $openTags as $tag ) { 645 646 $truncate .= '</' . $tag . '>'; … … 648 649 649 650 return apply_filters( 'bp_create_excerpt', $truncate, $original_text, $length, $options ); 650 651 } 652 add_filter( 'bp_create_excerpt', 'stripslashes_deep' ); 651 } 652 add_filter( 'bp_create_excerpt', 'stripslashes_deep' ); 653 653 add_filter( 'bp_create_excerpt', 'force_balance_tags' ); 654 654 … … 805 805 function bp_current_component() { 806 806 $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 808 811 return apply_filters( 'bp_current_component', $current_component ); 809 812 } … … 815 818 */ 816 819 function 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 819 825 return apply_filters( 'bp_current_action', $current_action ); 820 826 } … … 827 833 function bp_current_item() { 828 834 $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 830 839 return apply_filters( 'bp_current_item', $current_item ); 831 840 } … … 839 848 function bp_action_variables() { 840 849 $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 842 854 return apply_filters( 'bp_action_variables', $action_variables ); 843 855 } … … 854 866 function bp_action_variable( $position = 0 ) { 855 867 $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; 857 871 858 872 return apply_filters( 'bp_action_variable', $action_variable, $position ); … … 873 887 $bp = buddypress(); 874 888 875 if ( isset( $bp->root_domain ) && !empty( $bp->root_domain ) ) {889 if ( ! empty( $bp->root_domain ) ) { 876 890 $domain = $bp->root_domain; 877 891 } else { … … 920 934 * @since BuddyPress (1.5.0) 921 935 * 922 * @global BuddyPress $bp The one true BuddyPress instance.923 *924 936 * @param string $component Optional. Defaults to the current component. 925 937 * @return string $root_slug The root slug. … … 935 947 936 948 // Component is active 937 if ( !empty( $bp->active_components[$component] ) ) { 949 if ( ! empty( $bp->active_components[ $component ] ) ) { 950 938 951 // Backward compatibility: in legacy plugins, the canonical component id 939 952 // 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]; 941 956 942 957 // Component has specific root slug 943 if ( ! empty( $bp->{$component_name}->root_slug ) ) {958 if ( ! empty( $bp->{$component_name}->root_slug ) ) { 944 959 $root_slug = $bp->{$component_name}->root_slug; 945 960 } … … 959 974 * @since BuddyPress (1.5.0) 960 975 * 961 * @global BuddyPress $bp The one true BuddyPress instance.962 *963 976 * @param string $root_slug Needle to our active component haystack. 964 977 * @return mixed False if none found, component name if found. … … 979 992 // Loop through active components and look for a match 980 993 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 ) ) ) { 982 995 return $bp->{$component}->name; 983 996 } … … 988 1001 989 1002 function 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 ); 993 1008 } 994 1009 … … 1023 1038 function bp_displayed_user_id() { 1024 1039 $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; 1026 1043 1027 1044 return (int) apply_filters( 'bp_displayed_user_id', $id ); … … 1037 1054 function bp_loggedin_user_id() { 1038 1055 $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; 1040 1059 1041 1060 return (int) apply_filters( 'bp_loggedin_user_id', $id ); … … 1059 1078 */ 1060 1079 function bp_is_current_component( $component ) { 1061 global $ bp, $wp_query;1080 global $wp_query; 1062 1081 1063 1082 $is_current_component = false; … … 1072 1091 $component = 'profile'; 1073 1092 } 1093 1094 $bp = buddypress(); 1074 1095 1075 1096 if ( ! empty( $bp->current_component ) ) { … … 1092 1113 // non-translatable component name. If so, we can return its 1093 1114 // corresponding slug from $bp->active_components. 1094 } else 1115 } elseif ( $key = array_search( $component, $bp->active_components ) ) { 1095 1116 if ( strstr( $bp->current_component, $key ) ) { 1096 1117 $is_current_component = true; … … 1151 1172 */ 1152 1173 function 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() ); 1158 1175 } 1159 1176 … … 1449 1466 */ 1450 1467 function 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' ) ); 1455 1469 } 1456 1470
Note: See TracChangeset
for help on using the changeset viewer.