Skip to:
Content

bbPress.org

Changeset 6591


Ignore:
Timestamp:
06/19/2017 09:46:29 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Authors: Rejig author link functions.

  • Allow for easier filtering of link sections
  • Update default arguments to remove no-break space and <br>, and rely on styling instead
  • Surrounding code clean-up
  • Add escaping to display names in links
Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/replies/template.php

    r6583 r6591  
    11321132                        'type'       => 'both',
    11331133                        'size'       => 80,
    1134                         'sep'        => '&nbsp;',
     1134                        'sep'        => '',
    11351135                        'show_role'  => false
    11361136                ), 'get_reply_author_link' );
    11371137
     1138                // Default return value
     1139                $author_link = '';
     1140
    11381141                // Used as reply_id
    1139                 if ( is_numeric( $args ) ) {
    1140                         $reply_id = bbp_get_reply_id( $args );
    1141                 } else {
    1142                         $reply_id = bbp_get_reply_id( $r['post_id'] );
    1143                 }
     1142                $reply_id = is_numeric( $args )
     1143                        ? bbp_get_reply_id( $args )
     1144                        : bbp_get_reply_id( $r['post_id'] );
    11441145
    11451146                // Reply ID is good
     
    11521153                        // Tweak link title if empty
    11531154                        if ( empty( $r['link_title'] ) ) {
    1154                                 $link_title = sprintf( empty( $anonymous ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), bbp_get_reply_author_display_name( $reply_id ) );
     1155                                $author     = bbp_get_reply_author_display_name( $reply_id );
     1156                                $title      = empty( $anonymous )
     1157                                        ? __( 'View %s\'s profile',  'bbpress' )
     1158                                        : __( 'Visit %s\'s website', 'bbpress' );
     1159                                $link_title = sprintf( $title, $author );
    11551160
    11561161                        // Use what was passed if not
     
    11601165
    11611166                        // Setup title and author_links array
    1162                         $link_title   = ! empty( $link_title ) ? ' title="' . esc_attr( $link_title ) . '"' : '';
    11631167                        $author_links = array();
    1164 
    1165                         // Get avatar
    1166                         if ( 'avatar' === $r['type'] || 'both' === $r['type'] ) {
     1168                        $link_title   = ! empty( $link_title )
     1169                                ? ' title="' . esc_attr( $link_title ) . '"'
     1170                                : '';
     1171
     1172                        // Get avatar (unescaped, because HTML)
     1173                        if ( ( 'avatar' === $r['type'] ) || ( 'both' === $r['type'] ) ) {
    11671174                                $author_links['avatar'] = bbp_get_reply_author_avatar( $reply_id, $r['size'] );
    11681175                        }
    11691176
    1170                         // Get display name
    1171                         if ( 'name' === $r['type']   || 'both' === $r['type'] ) {
    1172                                 $author_links['name'] = bbp_get_reply_author_display_name( $reply_id );
     1177                        // Get display name (escaped, because never HTML)
     1178                        if ( ( 'name' === $r['type'] ) || ( 'both' === $r['type'] ) ) {
     1179                                $author_links['name'] = esc_html( bbp_get_reply_author_display_name( $reply_id ) );
    11731180                        }
    11741181
     
    11791186                        if ( empty( $anonymous ) && bbp_user_has_profile( bbp_get_reply_author_id( $reply_id ) ) ) {
    11801187
     1188                                // Empty array
     1189                                $links = array();
     1190
    11811191                                // Assemble the links
    11821192                                foreach ( $author_links as $link => $link_text ) {
    1183                                         $link_class = ' class="bbp-author-' . $link . '"';
    1184                                         $author_link[] = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, $link_class, $link_text );
     1193                                        $link_class = ' class="bbp-author-' . esc_attr( $link ) . '"';
     1194                                        $links[]    = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, $link_class, $link_text );
    11851195                                }
    11861196
     1197                                // Role is not linked
    11871198                                if ( true === $r['show_role'] ) {
    1188                                         $author_link[] = bbp_get_reply_author_role( array( 'reply_id' => $reply_id ) );
     1199                                        $links[] = bbp_get_reply_author_role( array( 'reply_id' => $reply_id ) );
    11891200                                }
    11901201
    1191                                 $author_link = implode( $r['sep'], $author_link );
    1192 
    1193                         // No links if anonymous
    1194                         } else {
    1195                                 $author_link = implode( $r['sep'], $author_links );
     1202                                // Juggle
     1203                                $author_links = $links;
     1204                                unset( $links );
    11961205                        }
    11971206
    1198                 // No replies so link is empty
    1199                 } else {
    1200                         $author_link = '';
     1207                        // Filter sections
     1208                        $sections    = apply_filters( 'bbp_get_reply_author_links', $author_links, $r, $args );
     1209
     1210                        // Assemble sections into author link
     1211                        $author_link = implode( $r['sep'], $sections );
    12011212                }
    12021213
  • trunk/src/includes/topics/template.php

    r6583 r6591  
    13971397                        'type'       => 'both',
    13981398                        'size'       => 80,
    1399                         'sep'        => '&nbsp;',
     1399                        'sep'        => '',
    14001400                        'show_role'  => false
    14011401                ), 'get_topic_author_link' );
    14021402
     1403                // Default return value
     1404                $author_link = '';
     1405
    14031406                // Used as topic_id
    1404                 if ( is_numeric( $args ) ) {
    1405                         $topic_id = bbp_get_topic_id( $args );
    1406                 } else {
    1407                         $topic_id = bbp_get_topic_id( $r['post_id'] );
    1408                 }
     1407                $topic_id = is_numeric( $args )
     1408                        ? bbp_get_topic_id( $args )
     1409                        : bbp_get_topic_id( $r['post_id'] );
    14091410
    14101411                // Topic ID is good
     
    14171418                        // Tweak link title if empty
    14181419                        if ( empty( $r['link_title'] ) ) {
    1419                                 $title      = empty( $anonymous ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' );
    14201420                                $author     = bbp_get_topic_author_display_name( $topic_id );
     1421                                $title      = empty( $anonymous )
     1422                                        ? __( 'View %s\'s profile',  'bbpress' )
     1423                                        : __( 'Visit %s\'s website', 'bbpress' );
    14211424                                $link_title = sprintf( $title, $author );
    14221425
     
    14271430
    14281431                        // Setup title and author_links array
    1429                         $link_title   = ! empty( $link_title ) ? ' title="' . esc_attr( $link_title ) . '"' : '';
    14301432                        $author_links = array();
    1431 
    1432                         // Get avatar
    1433                         if ( 'avatar' === $r['type'] || 'both' === $r['type'] ) {
     1433                        $link_title   = ! empty( $link_title )
     1434                                ? ' title="' . esc_attr( $link_title ) . '"'
     1435                                : '';
     1436
     1437                        // Get avatar (unescaped, because HTML)
     1438                        if ( ( 'avatar' === $r['type'] ) || ( 'both' === $r['type'] ) ) {
    14341439                                $author_links['avatar'] = bbp_get_topic_author_avatar( $topic_id, $r['size'] );
    14351440                        }
    14361441
    1437                         // Get display name
    1438                         if ( 'name' === $r['type'] || 'both' === $r['type'] ) {
    1439                                 $author_links['name'] = bbp_get_topic_author_display_name( $topic_id );
     1442                        // Get display name (escaped, because never HTML)
     1443                        if ( ( 'name' === $r['type'] ) || ( 'both' === $r['type'] ) ) {
     1444                                $author_links['name'] = esc_html( bbp_get_topic_author_display_name( $topic_id ) );
    14401445                        }
    14411446
     
    14451450                        // Add links if not anonymous
    14461451                        if ( empty( $anonymous ) && bbp_user_has_profile( bbp_get_topic_author_id( $topic_id ) ) ) {
     1452
     1453                                // Empty array
     1454                                $links = array();
    14471455
    14481456                                // Assemble the links
    14491457                                foreach ( $author_links as $link => $link_text ) {
    14501458                                        $link_class = ' class="bbp-author-' . esc_attr( $link ) . '"';
    1451                                         $author_link[] = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, $link_class, $link_text );
     1459                                        $links[]    = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, $link_class, $link_text );
    14521460                                }
    14531461
     1462                                // Role is not linked
    14541463                                if ( true === $r['show_role'] ) {
    1455                                         $author_link[] = bbp_get_topic_author_role( array( 'topic_id' => $topic_id ) );
     1464                                        $links[] = bbp_get_topic_author_role( array( 'topic_id' => $topic_id ) );
    14561465                                }
    14571466
    1458                                 $author_link = implode( $r['sep'], $author_link );
    1459 
    1460                         // No links if anonymous
    1461                         } else {
    1462                                 $author_link = implode( $r['sep'], $author_links );
     1467                                // Juggle
     1468                                $author_links = $links;
     1469                                unset( $links );
    14631470                        }
    14641471
    1465                 } else {
    1466                         $author_link = '';
    1467                 }
    1468 
    1469                 // Filter & return
    1470                 return apply_filters( 'bbp_get_topic_author_link', $author_link, $args );
     1472                        // Filter sections
     1473                        $sections    = apply_filters( 'bbp_get_topic_author_links', $author_links, $r, $args );
     1474
     1475                        // Assemble sections into author link
     1476                        $author_link = implode( $r['sep'], $sections );
     1477                }
     1478
     1479                // Filter & return
     1480                return apply_filters( 'bbp_get_topic_author_link', $author_link, $r, $args );
    14711481        }
    14721482
  • trunk/src/templates/default/bbpress/content-single-topic-lead.php

    r6258 r6591  
    5353                                <?php do_action( 'bbp_theme_before_topic_author_details' ); ?>
    5454
    55                                 <?php bbp_topic_author_link( array( 'sep' => '<br />', 'show_role' => true ) ); ?>
     55                                <?php bbp_topic_author_link( array( 'show_role' => true ) ); ?>
    5656
    5757                                <?php if ( current_user_can( 'moderate', bbp_get_reply_id() ) ) : ?>
  • trunk/src/templates/default/bbpress/loop-search-reply.php

    r6258 r6591  
    3030                <?php do_action( 'bbp_theme_before_reply_author_details' ); ?>
    3131
    32                 <?php bbp_reply_author_link( array( 'sep' => '<br />', 'show_role' => true ) ); ?>
     32                <?php bbp_reply_author_link( array( 'show_role' => true ) ); ?>
    3333
    3434                <?php if ( bbp_is_user_keymaster() ) : ?>
  • trunk/src/templates/default/bbpress/loop-search-topic.php

    r6258 r6591  
    5353                <?php do_action( 'bbp_theme_before_topic_author_details' ); ?>
    5454
    55                 <?php bbp_topic_author_link( array( 'sep' => '<br />', 'show_role' => true ) ); ?>
     55                <?php bbp_topic_author_link( array( 'show_role' => true ) ); ?>
    5656
    5757                <?php if ( bbp_is_user_keymaster() ) : ?>
  • trunk/src/templates/default/bbpress/loop-single-reply.php

    r6258 r6591  
    4242                <?php do_action( 'bbp_theme_before_reply_author_details' ); ?>
    4343
    44                 <?php bbp_reply_author_link( array( 'sep' => '<br />', 'show_role' => true ) ); ?>
     44                <?php bbp_reply_author_link( array( 'show_role' => true ) ); ?>
    4545
    4646                <?php if ( current_user_can( 'moderate', bbp_get_reply_id() ) ) : ?>
Note: See TracChangeset for help on using the changeset viewer.