Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/13/2010 03:31:07 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Fix anonymous user links. Fix single reply template. Abstract out user profile/website links. Fixes #1408. Props GautamGupta via Google Code-in

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-topic-template.php

    r2715 r2720  
    2121    $default = array (
    2222        // Narrow query down to bbPress topics
    23         'post_type'        => $bbp->topic_id,
     23        'post_type'      => $bbp->topic_id,
    2424
    2525        // Forum ID
    26         'post_parent'      => isset( $_REQUEST['forum_id'] ) ? $_REQUEST['forum_id'] : bbp_get_forum_id(),
     26        'post_parent'    => isset( $_REQUEST['forum_id'] ) ? $_REQUEST['forum_id'] : bbp_get_forum_id(),
    2727
    2828        // Make sure topic has some last activity time
    29         'meta_key'         => '_bbp_topic_last_active',
     29        'meta_key'       => '_bbp_topic_last_active',
    3030
    3131        //'author', 'date', 'title', 'modified', 'parent', rand',
    32         'orderby'          => isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : 'meta_value',
     32        'orderby'        => isset( $_REQUEST['orderby']  ) ? $_REQUEST['orderby'] : 'meta_value',
    3333
    3434        // 'ASC', 'DESC'
    35         'order'            => isset( $_REQUEST['order'] ) ? $_REQUEST['order'] : 'DESC',
     35        'order'          => isset( $_REQUEST['order']    ) ? $_REQUEST['order']    : 'DESC',
    3636
    3737        // @todo replace 15 with setting
    38         'posts_per_page'   => isset( $_REQUEST['posts'] ) ? $_REQUEST['posts'] : 15,
     38        'posts_per_page' => isset( $_REQUEST['posts']    ) ? $_REQUEST['posts']    : 15,
     39
     40        // Topic Search
     41        's'              => !empty( $_REQUEST['ts']      ) ? $_REQUEST['ts']       : '',
    3942
    4043        // Page Number
    41         'paged'            => bbp_get_paged(),
    42 
    43         // Topic Search
    44         's'                => empty( $_REQUEST['ts'] ) ? '' : $_REQUEST['ts'],
     44        'paged'          => bbp_get_paged(),
    4545    );
    4646
     
    428428 * @param int $topic_id optional
    429429 *
    430  * @uses bbp_get_topic_author()
     430 * @uses bbp_get_topic_author_avatar()
    431431 */
    432432function bbp_topic_author_avatar ( $topic_id = 0, $size = 40 ) {
     
    442442     * @since bbPress (r2590)
    443443     *
    444      * @uses apply_filters
     444     * @uses get_avatar()
     445     * @uses get_post_meta()
     446     *
    445447     * @param int $topic_id optional
    446      *
    447      * @return string Author of topic
     448     * @return string Avatar of the author of the topic
    448449     */
    449450    function bbp_get_topic_author_avatar ( $topic_id = 0, $size = 40 ) {
    450         $topic_id = bbp_get_topic_id( $topic_id );
    451 
    452         return apply_filters( 'bbp_get_topic_author_avatar', get_avatar( get_post_field( 'post_author', $topic_id ), $size ) );
    453     }
    454 
    455 /**
    456  * bbp_topic_author_avatar ()
    457  *
    458  * Output the author avatar of the topic in the loop
    459  *
    460  * @package bbPress
    461  * @subpackage Template Tags
    462  * @since bbPress (r2590)
    463  * @param int $topic_id optional
    464  *
    465  * @uses bbp_get_topic_author()
    466  */
    467 function bbp_topic_author_url ( $topic_id = 0 ) {
    468     echo bbp_get_topic_author_url( $topic_id );
    469 }
    470     /**
    471      * bbp_get_topic_author_url ()
    472      *
    473      * Return the author url of the topic in the loop
    474      *
    475      * @package bbPress
    476      * @subpackage Template Tags
    477      * @since bbPress (r2590)
    478      *
    479      * @uses apply_filters
    480      * @param int $topic_id optional
    481      *
    482      * @return string Author URL of topic
    483      */
    484     function bbp_get_topic_author_url ( $topic_id = 0 ) {
    485451        $topic_id = bbp_get_topic_id( $topic_id );
    486452
    487453        // Check for anonymous user
    488454        if ( $author_id = get_post_field( 'post_author', $topic_id ) )
    489             $author_url = bbp_get_user_profile_url( $author_id );
     455            $author_avatar = get_avatar( $author_id );
    490456        else
    491             $author_url = get_post_meta( $topic_id, '_bbp_anonymous_website', true );
    492 
    493         return apply_filters( 'bbp_get_topic_author_url', $author_url );
    494     }
     457            $author_avatar = get_avatar( get_post_meta( $topic_id, '_bbp_anonymous_email', true ) );
     458
     459        return apply_filters( 'bbp_get_topic_author_avatar', $author_avatar, $topic_id, $size );
     460    }
     461
     462/**
     463 * bbp_topic_author_link ()
     464 *
     465 * Output the author link of the topic in the loop
     466 *
     467 * @package bbPress
     468 * @subpackage Template Tags
     469 * @since bbPress (r2717)
     470 *
     471 * @param mixed|int $args If it is an integer, it is used as topic_id. Optional.
     472 * @uses bbp_get_topic_author_link()
     473 */
     474function bbp_topic_author_link ( $args = '' ) {
     475    echo bbp_get_topic_author_link( $args );
     476}
     477    /**
     478     * bbp_get_topic_author_link ()
     479     *
     480     * Return the author link of the topic in the loop
     481     *
     482     * @package bbPress
     483     * @subpackage Template Tags
     484     * @since bbPress (r2717)
     485     *
     486     * @uses bbp_get_topic_author_url()
     487     * @uses bbp_get_topic_author()
     488     *
     489     * @param mixed|int $args If it is an integer, it is used as topic_id. Optional.
     490     * @return string Author link of topic
     491     */
     492    function bbp_get_topic_author_link ( $args = '' ) {
     493        // Used as topic_id
     494        if ( is_int( $args ) ) {
     495            $topic_id = bbp_get_topic_id( $args );
     496        } else {
     497            $defaults = array (
     498                'topic_id'   => 0,
     499                'link_title' => '',
     500                'link_text'  => ''
     501            );
     502
     503            $r = wp_parse_args( $args, $defaults );
     504            extract( $r );
     505        }
     506
     507        if ( empty( $topic_id ) )
     508            $topic_id = bbp_get_topic_id( $topic_id );
     509
     510        if ( empty( $link_title ) && ( bbp_is_topic() || bbp_is_topic() ) )
     511            $link_title = sprintf( get_the_author_meta( 'ID' ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), bbp_get_topic_author( $topic_id ) );
     512
     513        if ( empty( $link_text ) && ( bbp_is_topic() || bbp_is_topic() ) )
     514            $link_text = bbp_get_topic_author_avatar( $topic_id, 80 );
     515        else
     516            $link_text = bbp_get_topic_author( $topic_id );
     517
     518        $link_title = !empty( $link_title ) ? ' title="' . $link_title . '"' : '';
     519
     520        // Check for anonymous user
     521        if ( $author_url = bbp_get_topic_author_url( $topic_id ) )
     522            $author_link = sprintf( '<a href="%1$s"%2$s>%3$s</a>', $author_url, $link_title, $link_text );
     523        else
     524            $author_link = $link_text;
     525
     526        return apply_filters( 'bbp_get_topic_author_link', $author_link, $topic_id );
     527    }
     528
     529        /**
     530         * bbp_topic_author_url ()
     531         *
     532         * Output the author url of the topic in the loop
     533         *
     534         * @package bbPress
     535         * @subpackage Template Tags
     536         * @since bbPress (r2590)
     537         * @param int $topic_id optional
     538         *
     539         * @uses bbp_get_topic_author_url()
     540         */
     541        function bbp_topic_author_url ( $topic_id = 0 ) {
     542            echo bbp_get_topic_author_url( $topic_id );
     543        }
     544            /**
     545             * bbp_get_topic_author_url ()
     546             *
     547             * Return the author url of the topic in the loop
     548             *
     549             * @package bbPress
     550             * @subpackage Template Tags
     551             * @since bbPress (r2590)
     552             *
     553             * @uses bbp_get_user_profile_url()
     554             * @uses get_post_meta()
     555             *
     556             * @param int $topic_id optional
     557             * @return string Author URL of topic
     558             */
     559            function bbp_get_topic_author_url ( $topic_id = 0 ) {
     560                $topic_id = bbp_get_topic_id( $topic_id );
     561
     562                // Check for anonymous user
     563                if ( $author_id = get_post_field( 'post_author', $topic_id ) )
     564                    $author_url = bbp_get_user_profile_url( $author_id );
     565                else
     566                    if ( !$author_url = get_post_meta( $topic_id, '_bbp_anonymous_website', true ) )
     567                        $author_url = '';
     568
     569                return apply_filters( 'bbp_get_topic_author_url', $author_url, $topic_id );
     570            }
    495571
    496572/**
     
    859935
    860936        // Look for existing count, and populate if does not exist
    861         if ( !$voices = get_post_meta( $topic_id, '_bbp_topic_voice_count', true ) )
     937        if ( !$voices   = get_post_meta( $topic_id, '_bbp_topic_voice_count', true ) )
    862938            $voices = bbp_update_topic_voice_count( $topic_id );
    863939
Note: See TracChangeset for help on using the changeset viewer.