Skip to:
Content

bbPress.org


Ignore:
Timestamp:
05/26/2017 09:50:36 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Forms: Introduce bbp_tab_index_attribute() helpers to handle tabindex attribute output.

Note that these functions are used but normally their output is suppressed, because overriding the browser's natural tabindex order is impolite, and may introduce more issues than it actually fixes.

(Also includes some surrounding code clean-up.)

File:
1 edited

Legend:

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

    r6415 r6433  
    27692769        ), 'get_topic_trash_link' );
    27702770
     2771        // Get topic
    27712772        $topic = bbp_get_topic( $r['id'] );
    27722773
     2774        // Bail if no topic or current user cannot delete
    27732775        if ( empty( $topic ) || ! current_user_can( 'delete_topic', $topic->ID ) ) {
    27742776            return;
    27752777        }
    27762778
    2777         $actions = array();
     2779        $actions    = array();
     2780        $trash_days = bbp_get_trash_days( bbp_get_topic_post_type() );
    27782781
    27792782        if ( bbp_is_topic_trash( $topic->ID ) ) {
    27802783            $actions['untrash'] = '<a title="' . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_topic_trash', 'sub_action' => 'untrash', 'topic_id' => $topic->ID ) ), 'untrash-' . $topic->post_type . '_' . $topic->ID ) ) . '" class="bbp-topic-restore-link">' . $r['restore_text'] . '</a>';
    2781         } elseif ( EMPTY_TRASH_DAYS ) {
     2784        } elseif ( ! empty( $trash_days ) ) {
    27822785            $actions['trash']   = '<a title="' . esc_attr__( 'Move this item to the Trash',      'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_topic_trash', 'sub_action' => 'trash',   'topic_id' => $topic->ID ) ), 'trash-'   . $topic->post_type . '_' . $topic->ID ) ) . '" class="bbp-topic-trash-link">'   . $r['trash_text']   . '</a>';
    27832786        }
    27842787
    2785         if ( bbp_is_topic_trash( $topic->ID ) || ! EMPTY_TRASH_DAYS ) {
     2788        if ( bbp_is_topic_trash( $topic->ID ) || empty( $trash_days ) ) {
    27862789            $actions['delete']  = '<a title="' . esc_attr__( 'Delete this item permanently',     'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_topic_trash', 'sub_action' => 'delete',  'topic_id' => $topic->ID ) ), 'delete-'  . $topic->post_type . '_' . $topic->ID ) ) . '" onclick="return confirm(\'' . esc_js( __( 'Are you sure you want to delete that permanently?', 'bbpress' ) ) . '\' );" class="bbp-topic-delete-link">' . $r['delete_text'] . '</a>';
    27872790        }
     
    28392842        ), 'get_topic_close_link' );
    28402843
     2844        // Get topic
    28412845        $topic = bbp_get_topic( $r['id'] );
    28422846
     2847        // Bail if no topic or current user cannot moderate
    28432848        if ( empty( $topic ) || ! current_user_can( 'moderate', $topic->ID ) ) {
    28442849            return;
     
    29002905        ), 'get_topic_approve_link' );
    29012906
     2907        // Get topic
    29022908        $topic = bbp_get_topic( $r['id'] );
    29032909
     2910        // Bail if no topic or current user cannot moderate
    29042911        if ( empty( $topic ) || ! current_user_can( 'moderate', $topic->ID ) ) {
    29052912            return;
     
    29622969        ), 'get_topic_stick_link' );
    29632970
     2971        // Get topic
    29642972        $topic = bbp_get_topic( $r['id'] );
    29652973
     2974        // Bail if no topic or current user cannot moderate
    29662975        if ( empty( $topic ) || ! current_user_can( 'moderate', $topic->ID ) ) {
    29672976            return;
     
    30323041        ), 'get_topic_merge_link' );
    30333042
     3043        // Get topic
    30343044        $topic = bbp_get_topic( $r['id'] );
    30353045
     3046        // Bail if no topic or current user cannot moderate
    30363047        if ( empty( $topic ) || ! current_user_can( 'moderate', $topic->ID ) ) {
    30373048            return;
     
    31333144        // Parse arguments against default values
    31343145        $r = bbp_parse_args( $args, array(
    3135             'id'           => 0,
    3136             'link_before'  => '',
    3137             'link_after'   => '',
    3138             'reply_text'   => esc_html_x( 'Reply', 'verb', 'bbpress' ),
     3146            'id'          => 0,
     3147            'link_before' => '',
     3148            'link_after'  => '',
     3149            'reply_text'  => esc_html_x( 'Reply', 'verb', 'bbpress' ),
    31393150        ), 'get_topic_reply_link' );
    31403151
    3141         // Get the reply to use it's ID and post_parent
     3152        // Get the topic to use it's ID and post_parent
    31423153        $topic = bbp_get_topic( $r['id'] );
    31433154
    3144         // Bail if no reply or user cannot reply
    3145         if ( empty( $topic ) || ! bbp_current_user_can_access_create_reply_form() ) {
     3155        // Bail if no topic or user cannot reply
     3156        if ( empty( $topic ) || bbp_is_single_reply() || ! bbp_current_user_can_access_create_reply_form() ) {
    31463157            return;
    31473158        }
     
    31493160        // Add $uri to the array, to be passed through the filter
    31503161        $r['uri'] = '#new-post';
    3151         $retval   = $r['link_before'] . '<a role="button" href="' . esc_url( $r['uri'] ) . '" class="bbp-topic-reply-link">' . esc_html( $r['reply_text'] ) . '</a>' . $r['link_after'];
     3162        $retval   = $r['link_before'] . '<a role="button" href="' . esc_url( $r['uri'] ) . '" class="bbp-topic-reply-link">' . $r['reply_text'] . '</a>' . $r['link_after'];
    31523163
    31533164        return apply_filters( 'bbp_get_topic_reply_link', $retval, $r, $args );
     
    34383449        }
    34393450
    3440         // Used variables
    3441         $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
    3442 
    34433451        // Start an output buffer, we'll finish it after the select loop
    34443452        ob_start(); ?>
    34453453
    3446         <select name="<?php echo esc_attr( $r['select_id'] ); ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php echo $tab; ?>>
     3454        <select name="<?php echo esc_attr( $r['select_id'] ); ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
    34473455
    34483456            <?php foreach ( bbp_get_topic_types( $r['topic_id'] ) as $key => $label ) : ?>
     
    35223530        }
    35233531
    3524         // Used variables
    3525         $tab = ! empty( $r['tab'] ) ? ' tabindex="' . (int) $r['tab'] . '"' : '';
    3526 
    35273532        // Start an output buffer, we'll finish it after the select loop
    35283533        ob_start(); ?>
    35293534
    3530         <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php echo $tab; ?>>
     3535        <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
    35313536
    35323537            <?php foreach ( bbp_get_topic_statuses( $r['topic_id'] ) as $key => $label ) : ?>
     
    37253730        }
    37263731
    3727         // Add before and after if description exists
    3728         if ( ! empty( $term->term_id ) ) {
    3729             $retval = $term->term_id;
    3730 
    3731         // No id
    3732         } else {
    3733             $retval = '';
    3734         }
     3732        // Get the term ID
     3733        $retval = ! empty( $term->term_id )
     3734            ? $term->term_id
     3735            : 0;
    37353736
    37363737        return (int) apply_filters( 'bbp_get_topic_tag_id', (int) $retval, $tag, $term );
     
    37693770        }
    37703771
    3771         // Add before and after if description exists
    3772         if ( ! empty( $term->name ) ) {
    3773             $retval = $term->name;
    3774 
    3775         // No name
    3776         } else {
    3777             $retval = '';
    3778         }
     3772        // Get the term name
     3773        $retval = ! empty( $term->name )
     3774            ? $term->name
     3775            : '';
    37793776
    37803777        return apply_filters( 'bbp_get_topic_tag_name', $retval, $tag, $term );
     
    38133810        }
    38143811
    3815         // Add before and after if description exists
    3816         if ( ! empty( $term->slug ) ) {
    3817             $retval = $term->slug;
    3818 
    3819         // No slug
    3820         } else {
    3821             $retval = '';
    3822         }
     3812        // Get the term slug
     3813        $retval = ! empty( $term->slug )
     3814            ? $term->slug
     3815            : '';
    38233816
    38243817        return apply_filters( 'bbp_get_topic_tag_slug', $retval, $tag, $term );
     
    38573850        }
    38583851
    3859         // Add before and after if description exists
    3860         if ( ! empty( $term->term_id ) ) {
    3861             $retval = get_term_link( $term, bbp_get_topic_tag_tax_id() );
    3862 
    3863         // No link
    3864         } else {
    3865             $retval = '';
    3866         }
     3852        // Get the term link
     3853        $retval = ! empty( $term->term_id )
     3854            ? get_term_link( $term, bbp_get_topic_tag_tax_id() )
     3855            : '';
    38673856
    38683857        return apply_filters( 'bbp_get_topic_tag_link', $retval, $tag, $term );
     
    39013890        }
    39023891
    3903         // Add before and after if description exists
     3892        // Get the term's edit link
    39043893        if ( ! empty( $term->term_id ) ) {
    39053894
    3906             // Pretty
    3907             if ( bbp_use_pretty_urls() ) {
    3908                 $retval = user_trailingslashit( trailingslashit( bbp_get_topic_tag_link() ) . bbp_get_edit_rewrite_id() );
    3909 
    3910             // Ugly
    3911             } else {
    3912                 $retval = add_query_arg( array( bbp_get_edit_rewrite_id() => '1' ), bbp_get_topic_tag_link() );
    3913             }
     3895            // Pretty or ugly URL
     3896            $retval = bbp_use_pretty_urls()
     3897                ? user_trailingslashit( trailingslashit( bbp_get_topic_tag_link() ) . bbp_get_edit_rewrite_id() )
     3898                : add_query_arg( array( bbp_get_edit_rewrite_id() => '1' ), bbp_get_topic_tag_link() );
    39143899
    39153900        // No link
     
    39573942            $term = get_term_by( 'slug', $r['tag'], bbp_get_topic_tag_tax_id() );
    39583943        } else {
    3959             $tag      = get_query_var( 'term' );
    3960             $r['tag'] = $tag;
    3961             $term     = get_queried_object();
    3962         }
    3963 
    3964         // Add before and after if description exists
    3965         if ( ! empty( $term->description ) ) {
    3966             $retval = $r['before'] . $term->description . $r['after'];
    3967 
    3968         // No description, no HTML
    3969         } else {
    3970             $retval = '';
    3971         }
     3944            $tag  = $r['tag'] = get_query_var( 'term' );
     3945            $term = get_queried_object();
     3946        }
     3947
     3948        // Add before & after if description exists
     3949        $retval = ! empty( $term->description )
     3950            ? $r['before'] . $term->description . $r['after']
     3951            : '';
    39723952
    39733953        return apply_filters( 'bbp_get_topic_tag_description', $retval, $r, $args, $tag, $term );
Note: See TracChangeset for help on using the changeset viewer.