Skip to:
Content

bbPress.org


Ignore:
Timestamp:
10/19/2018 08:31:07 PM (5 years ago)
Author:
johnjamesjacoby
Message:

Forums: revert part of r6860.

Go back to ul and li to avoid breaking CSS for existing installs, and use a CSS separator instead to address the original invalid markup issues.

This might show an extra separator in circumstances where filters or template-overrides are targeting very specific things, but that's better than breaking mark-up changes.

See #3217.

File:
1 edited

Legend:

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

    r6860 r6872  
    685685 *
    686686 * @param array $args The function supports these args:
    687  *  - before: To put before the output. Defaults to '<div class="bbp-forums-list">'
    688  *  - after: To put after the output. Defaults to '</div>'
    689  *  - link_before: To put before every link. Defaults to '<span class="bbp-forum">'
    690  *  - link_after: To put after every link. Defaults to '</span>'
    691  *  - sep: Separator. Defaults to ', '
     687 *  - before: To put before the output. Defaults to '<ul class="bbp-forums-list">'
     688 *  - after: To put after the output. Defaults to '</ul>'
     689 *  - link_before: To put before every link. Defaults to '<li class="bbp-forum">'
     690 *  - link_after: To put after every link. Defaults to '</li>'
     691 *  - sep: Separator. Defaults to ''. Make sure your markup is valid!
    692692 *  - count_before: String before each count Defaults to ' ('
    693693 *  - count_after: String before each count Defaults to ')'
     
    701701    // Parse arguments against default values
    702702    $r = bbp_parse_args( $args, array(
    703         'before'           => '<div class="bbp-forums-list">',
    704         'after'            => '</div>',
    705         'link_before'      => '<span class="bbp-forum">',
    706         'link_after'       => '</span>',
    707         'sep'              => ', ',
     703        'before'           => '<ul class="bbp-forums-list">',
     704        'after'            => '</ul>',
     705        'link_before'      => '<li class="bbp-forum css-sep">',
     706        'link_after'       => '</li>',
     707        'sep'              => '',
    708708        'count_before'     => ' (',
    709709        'count_after'      => ')',
     
    712712        'show_topic_count' => true,
    713713        'show_reply_count' => true,
     714        'echo'             => true,
    714715
    715716        // Retired, use 'sep' instead
     
    725726    }
    726727
    727     // Define links
    728     $links = array();
     728    // Default values
     729    $links  = array();
     730    $output = '';
    729731
    730732    // Loop through forums and create a list
    731733    $sub_forums = bbp_forum_get_subforums( $r['forum_id'] );
    732     foreach ( $sub_forums as $sub_forum ) {
    733 
    734         // Get forum details
    735         $count     = array();
    736         $permalink = bbp_get_forum_permalink( $sub_forum->ID );
    737         $title     = bbp_get_forum_title( $sub_forum->ID );
    738 
    739         // Show topic count
    740         if ( ! empty( $r['show_topic_count'] ) && ! bbp_is_forum_category( $sub_forum->ID ) ) {
    741             $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
    742         }
    743 
    744         // Show reply count
    745         if ( ! empty( $r['show_reply_count'] ) && ! bbp_is_forum_category( $sub_forum->ID ) ) {
    746             $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
    747         }
    748 
    749         // Counts to show
    750         $counts = ! empty( $count )
    751             ? $r['count_before'] . implode( $r['count_sep'], $count ) . $r['count_after']
     734    if ( ! empty( $sub_forums ) ) {
     735        foreach ( $sub_forums as $sub_forum ) {
     736
     737            // Get forum details
     738            $count     = array();
     739            $permalink = bbp_get_forum_permalink( $sub_forum->ID );
     740            $title     = bbp_get_forum_title( $sub_forum->ID );
     741
     742            // Show topic count
     743            if ( ! empty( $r['show_topic_count'] ) && ! bbp_is_forum_category( $sub_forum->ID ) ) {
     744                $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
     745            }
     746
     747            // Show reply count
     748            if ( ! empty( $r['show_reply_count'] ) && ! bbp_is_forum_category( $sub_forum->ID ) ) {
     749                $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
     750            }
     751
     752            // Counts to show
     753            $counts = ! empty( $count )
     754                ? $r['count_before'] . implode( $r['count_sep'], $count ) . $r['count_after']
     755                : '';
     756
     757            // Subforum classes
     758            $subforum_classes      = array( 'bbp-forum-link' );
     759            $subforum_classes      = apply_filters( 'bbp_list_forums_subforum_classes', $subforum_classes, $sub_forum->ID );
     760
     761            // This could use bbp_get_forum_class() eventually...
     762            $subforum_classes_attr = 'class="' . implode( ' ', array_map( 'sanitize_html_class', $subforum_classes ) ) . '"';
     763
     764            // Build this sub forums link
     765            $links[] = $r['link_before'] . '<a href="' . esc_url( $permalink ) . '" ' . $subforum_classes_attr . '>' . $title . $counts . '</a>' . $r['link_after'];
     766        }
     767
     768        // Maybe wrap output
     769        $output = ! empty( $links )
     770            ? $r['before'] . implode( $r['sep'], $links ) . $r['after']
    752771            : '';
    753 
    754         // Subforum classes
    755         $subforum_classes      = array( 'bbp-forum-link' );
    756         $subforum_classes      = apply_filters( 'bbp_list_forums_subforum_classes', $subforum_classes, $sub_forum->ID );
    757 
    758         // This could use bbp_get_forum_class() eventually...
    759         $subforum_classes_attr = 'class="' . implode( ' ', array_map( 'sanitize_html_class', $subforum_classes ) ) . '"';
    760 
    761         // Build this sub forums link
    762         $links[] = $r['link_before'] . '<a href="' . esc_url( $permalink ) . '" ' . $subforum_classes_attr . '>' . $title . $counts . '</a>' . $r['link_after'];
    763     }
    764 
    765     // Maybe wrap output
    766     $output = ! empty( $links )
    767         ? $r['before'] . implode( $r['sep'], $links ) . $r['after']
    768         : '';
    769 
    770     // Filter & output the forums list
    771     echo apply_filters( 'bbp_list_forums', $output, $r, $args );
     772    }
     773
     774    // Filter output
     775    $the_list = apply_filters( 'bbp_list_forums', $output, $r, $args );
     776
     777    // Echo or return the forums list
     778    if ( true === $r['echo'] ) {
     779        echo $the_list;
     780    } else {
     781        return $the_list;
     782    }
    772783}
    773784
Note: See TracChangeset for help on using the changeset viewer.