Skip to:
Content

bbPress.org

Ticket #1393: anon-user-link.2.diff

File anon-user-link.2.diff, 17.9 KB (added by GautamGupta, 12 years ago)
  • bbp-includes/bbp-reply-template.php

     
    2020
    2121        $default = array(
    2222                // Narrow query down to bbPress topics
    23                 'post_type'        => $bbp->reply_id,
     23                'post_type'      => $bbp->reply_id,
    2424
    2525                // Forum ID
    26                 'post_parent'      => isset( $_REQUEST['topic_id'] ) ? $_REQUEST['topic_id'] : bbp_get_topic_id(),
     26                'post_parent'    => isset( $_REQUEST['topic_id'] ) ? $_REQUEST['topic_id'] : bbp_get_topic_id(),
    2727
    2828                //'author', 'date', 'title', 'modified', 'parent', rand',
    29                 'orderby'          => isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : 'date',
     29                'orderby'        => isset( $_REQUEST['orderby']  ) ? $_REQUEST['orderby'] : 'date',
    3030
    3131                // 'ASC', 'DESC'
    32                 'order'            => isset( $_REQUEST['order'] ) ? $_REQUEST['order'] : 'ASC',
     32                'order'          => isset( $_REQUEST['order']    ) ? $_REQUEST['order']    : 'ASC',
    3333
    3434                // @todo replace 15 with setting
    35                 'posts_per_page'   => isset( $_REQUEST['posts'] ) ? $_REQUEST['posts'] : 15,
     35                'posts_per_page' => isset( $_REQUEST['posts']    ) ? $_REQUEST['posts']    : 15,
    3636
    3737                // Page Number
    38                 'paged'            => bbp_get_paged(),
     38                'paged'          => bbp_get_paged(),
    3939
    4040                // Reply Search
    41                 's'                => empty( $_REQUEST['rs'] ) ? '' : $_REQUEST['rs'],
     41                's'              => empty( $_REQUEST['rs']       ) ? ''                    : $_REQUEST['rs'],
    4242        );
    4343
    4444        // Set up topic variables
     
    5050
    5151        // Add pagination values to query object
    5252        $bbp->reply_query->posts_per_page = $posts_per_page;
    53         $bbp->reply_query->paged = $paged;
     53        $bbp->reply_query->paged          = $paged;
    5454
    5555        // Only add pagination if query returned results
    56         if ( (int)$bbp->reply_query->found_posts && (int)$bbp->reply_query->posts_per_page ) {
     56        if ( (int)$bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page ) {
    5757
    5858                // If pretty permalinks are enabled, make our pagination pretty
    5959                if ( $wp_rewrite->using_permalinks() )
     
    6565                $bbp_replies_pagination = apply_filters( 'bbp_replies_pagination', array(
    6666                        'base'      => $base,
    6767                        'format'    => '',
    68                         'total'     => ceil( (int)$bbp->reply_query->found_posts / (int)$posts_per_page ),
     68                        'total'     => ceil( (int)$bbp->reply_query->found_posts / (int) $posts_per_page ),
    6969                        'current'   => (int)$bbp->reply_query->paged,
    7070                        'prev_text' => '←',
    7171                        'next_text' => '→',
     
    395395                if ( get_post_field( 'post_author', $reply_id ) )
    396396                        $author = get_the_author();
    397397                else
    398                         $author = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
     398                        $author = get_post_meta( $reply_id, '_bbp_anonymous_name', true );
    399399
    400400                return apply_filters( 'bbp_get_reply_author', $author );
    401401        }
     
    473473                else
    474474                        $author_name = get_post_meta( $reply_id, '_bbp_anonymous_name', true );
    475475
    476                 return apply_filters( 'bbp_get_reply_author_id', esc_attr( $author_name ) );
     476                return apply_filters( 'bbp_get_reply_author_display_name', esc_attr( $author_name ) );
    477477        }
    478478
    479479/**
     
    486486 * @since bbPress (r2667)
    487487 * @param int $reply_id optional
    488488 *
    489  * @uses bbp_get_reply_author()
     489 * @uses bbp_get_reply_author_avatar()
    490490 */
    491491function bbp_reply_author_avatar ( $reply_id = 0, $size = 40 ) {
    492492        echo bbp_get_reply_author_avatar( $reply_id, $size );
     
    503503         * @uses apply_filters
    504504         * @param int $reply_id optional
    505505         *
    506          * @return string Author of reply
     506         * @return string Avatar of author of the reply
    507507         */
    508508        function bbp_get_reply_author_avatar ( $reply_id = 0, $size = 40 ) {
    509509                $reply_id = bbp_get_reply_id( $reply_id );
    510510
    511                 return apply_filters( 'bbp_get_reply_author_avatar', get_avatar( get_post_field( 'post_author', $reply_id ), $size ) );
     511                // Check for anonymous user
     512                if ( $author_id = get_post_field( 'post_author', $reply_id ) )
     513                        $author_avatar = get_avatar( $author_id );
     514                else
     515                        $author_avatar = get_avatar( get_post_meta( $reply_id, '_bbp_anonymous_email', true ) );
     516
     517                return apply_filters( 'bbp_get_reply_author_avatar', $author_avatar, $reply_id, $size );
    512518        }
    513519
    514520/**
    515  * bbp_reply_author_url ()
     521 * bbp_reply_author_link ()
    516522 *
    517  * Output the author url of the reply in the loop
     523 * Output the author link of the reply in the loop
    518524 *
    519525 * @package bbPress
    520526 * @subpackage Template Tags
    521  * @since bbPress (r2667)
    522  * @param int $reply_id optional
     527 * @since bbPress (r2717)
    523528 *
    524  * @uses bbp_get_reply_author_url()
     529 * @param mixed|int $args If it is an integer, it is used as reply_id. Optional.
     530 * @uses bbp_get_reply_author_link()
    525531 */
    526 function bbp_reply_author_url ( $reply_id = 0 ) {
    527         echo bbp_get_reply_author_url( $reply_id );
     532function bbp_reply_author_link ( $args = '' ) {
     533        echo bbp_get_reply_author_link( $args );
    528534}
    529535        /**
    530          * bbp_get_reply_author_url ()
     536         * bbp_get_reply_author_link ()
    531537         *
    532          * Return the author url of the reply in the loop
     538         * Return the author link of the reply in the loop
    533539         *
    534540         * @package bbPress
    535541         * @subpackage Template Tags
    536          * @since bbPress (r2667)
     542         * @since bbPress (r2717)
    537543         *
    538          * @uses apply_filters
    539          * @param int $reply_id optional
     544         * @uses bbp_get_reply_author_url()
     545         * @uses bbp_get_reply_author()
    540546         *
    541          * @return string Author URL of reply
     547         * @param mixed|int $args If it is an integer, it is used as reply_id. Optional.
     548         * @return string Author link of reply
    542549         */
    543         function bbp_get_reply_author_url ( $reply_id = 0 ) {
    544                 $reply_id = bbp_get_reply_id( $reply_id );
     550        function bbp_get_reply_author_link ( $args = '' ) {
     551                if ( is_int( $args ) ) { // Used as reply_id
     552                        $reply_id = bbp_get_reply_id( $args );
     553                } else {
     554                        $defaults = array (
     555                                'reply_id'   => 0,
     556                                'link_title' => '',
     557                                'link_text'  => ''
     558                        );
    545559
     560                        $r = wp_parse_args( $args, $defaults );
     561                        extract( $r );
     562                }
     563
     564                if ( empty( $reply_id ) )
     565                        $reply_id = bbp_get_reply_id( $reply_id );
     566
     567                if ( empty( $link_title ) && ( bbp_is_topic() || bbp_is_reply() ) )
     568                        $link_title = sprintf( get_the_author_meta( 'ID' ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), bbp_get_reply_author( $reply_id ) );
     569
     570                if ( empty( $link_text ) && ( bbp_is_topic() || bbp_is_reply() ) )
     571                        $link_text = bbp_get_reply_author_avatar( $reply_id, 80 );
     572                else
     573                        $link_text = bbp_get_reply_author( $reply_id );
     574
     575                $link_title = !empty( $link_title ) ? ' title="' . $link_title . '"' : '';
     576
    546577                // Check for anonymous user
    547                 if ( $author_id = get_post_field( 'post_author', $reply_id ) )
    548                         $author_url = bbp_get_user_profile_url( $author_id );
     578                if ( $author_url = bbp_get_reply_author_url( $reply_id ) )
     579                        $author_link = sprintf( '<a href="%1$s"%2$s>%3$s</a>', $author_url, $link_title, $link_text );
    549580                else
    550                         $author_url = get_post_meta( $reply_id, '_bbp_anonymous_website', true );
     581                        $author_link = $link_text; // Still return $link_text
    551582
    552                 return apply_filters( 'bbp_get_reply_author_url', $author_url );
     583                return apply_filters( 'bbp_get_reply_author_link', $author_link, $args );
    553584        }
    554585
     586                /**
     587                 * bbp_reply_author_url ()
     588                 *
     589                 * Output the author url of the reply in the loop
     590                 *
     591                 * @package bbPress
     592                 * @subpackage Template Tags
     593                 * @since bbPress (r2667)
     594                 * @param int $reply_id optional
     595                 *
     596                 * @uses bbp_get_reply_author_url()
     597                 */
     598                function bbp_reply_author_url ( $reply_id = 0 ) {
     599                        echo bbp_get_reply_author_url( $reply_id );
     600                }
     601                        /**
     602                         * bbp_get_reply_author_url ()
     603                         *
     604                         * Return the author url of the reply in the loop
     605                         *
     606                         * @package bbPress
     607                         * @subpackage Template Tags
     608                         * @since bbPress (r22667)
     609                         *
     610                         * @uses bbp_get_user_profile_url()
     611                         * @uses get_post_meta()
     612                         *
     613                         * @param int $reply_id optional
     614                         * @return string Author URL of reply
     615                         */
     616                        function bbp_get_reply_author_url ( $reply_id = 0 ) {
     617                                $reply_id = bbp_get_reply_id( $reply_id );
     618
     619                                // Check for anonymous user
     620                                if ( $author_id = get_post_field( 'post_author', $reply_id ) )
     621                                        $author_url = bbp_get_user_profile_url( $author_id );
     622                                else
     623                                        if ( !$author_url = get_post_meta( $reply_id, '_bbp_anonymous_website', true ) )
     624                                                $author_url = '';
     625
     626                                return apply_filters( 'bbp_get_reply_author_url', $author_url, $reply_id );
     627                        }
     628
    555629/**
    556630 * bbp_reply_topic_title ()
    557631 *
  • bbp-includes/bbp-topic-template.php

     
    2020
    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,
    3939
    4040                // Page Number
    41                 'paged'            => bbp_get_paged(),
     41                'paged'          => bbp_get_paged(),
    4242
    4343                // Topic Search
    44                 's'                => empty( $_REQUEST['ts'] ) ? '' : $_REQUEST['ts'],
     44                's'              => empty( $_REQUEST['ts']       ) ? ''                    : $_REQUEST['ts'],
    4545        );
    4646
    4747        // Don't pass post_parent if forum_id is empty or 0
     
    427427 * @since bbPress (r2590)
    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 ) {
    433433        echo bbp_get_topic_author_avatar( $topic_id, $size );
     
    441441         * @subpackage Template Tags
    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 ) {
    450451                $topic_id = bbp_get_topic_id( $topic_id );
    451452
    452                 return apply_filters( 'bbp_get_topic_author_avatar', get_avatar( get_post_field( 'post_author', $topic_id ), $size ) );
     453                // Check for anonymous user
     454                if ( $author_id = get_post_field( 'post_author', $topic_id ) )
     455                        $author_avatar = get_avatar( $author_id );
     456                else
     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 );
    453460        }
    454461
    455462/**
    456  * bbp_topic_author_avatar ()
     463 * bbp_topic_author_link ()
    457464 *
    458  * Output the author avatar of the topic in the loop
     465 * Output the author link of the topic in the loop
    459466 *
    460467 * @package bbPress
    461468 * @subpackage Template Tags
    462  * @since bbPress (r2590)
    463  * @param int $topic_id optional
     469 * @since bbPress (r2717)
    464470 *
    465  * @uses bbp_get_topic_author()
     471 * @param mixed|int $args If it is an integer, it is used as topic_id. Optional.
     472 * @uses bbp_get_topic_author_link()
    466473 */
    467 function bbp_topic_author_url ( $topic_id = 0 ) {
    468         echo bbp_get_topic_author_url( $topic_id );
     474function bbp_topic_author_link ( $args = '' ) {
     475        echo bbp_get_topic_author_link( $args );
    469476}
    470477        /**
    471          * bbp_get_topic_author_url ()
     478         * bbp_get_topic_author_link ()
    472479         *
    473          * Return the author url of the topic in the loop
     480         * Return the author link of the topic in the loop
    474481         *
    475482         * @package bbPress
    476483         * @subpackage Template Tags
    477          * @since bbPress (r2590)
     484         * @since bbPress (r2717)
    478485         *
    479          * @uses apply_filters
    480          * @param int $topic_id optional
     486         * @uses bbp_get_topic_author_url()
     487         * @uses bbp_get_topic_author()
    481488         *
    482          * @return string Author URL of topic
     489         * @param mixed|int $args If it is an integer, it is used as topic_id. Optional.
     490         * @return string Author link of topic
    483491         */
    484         function bbp_get_topic_author_url ( $topic_id = 0 ) {
    485                 $topic_id = bbp_get_topic_id( $topic_id );
     492        function bbp_get_topic_author_link ( $args = '' ) {
     493                if ( is_int( $args ) ) { // Used as topic_id
     494                        $topic_id = bbp_get_topic_id( $args );
     495                } else {
     496                        $defaults = array (
     497                                'topic_id'   => 0,
     498                                'link_title' => '',
     499                                'link_text'  => ''
     500                        );
    486501
     502                        $r = wp_parse_args( $args, $defaults );
     503                        extract( $r );
     504                }
     505
     506                if ( empty( $topic_id ) )
     507                        $topic_id = bbp_get_topic_id( $topic_id );
     508
     509                if ( empty( $link_title ) && ( bbp_is_topic() || bbp_is_topic() ) )
     510                        $link_title = sprintf( get_the_author_meta( 'ID' ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), bbp_get_topic_author( $topic_id ) );
     511
     512                if ( empty( $link_text ) && ( bbp_is_topic() || bbp_is_topic() ) )
     513                        $link_text = bbp_get_topic_author_avatar( $topic_id, 80 );
     514                else
     515                        $link_text = bbp_get_topic_author( $topic_id );
     516
     517                $link_title = !empty( $link_title ) ? ' title="' . $link_title . '"' : '';
     518
    487519                // Check for anonymous user
    488                 if ( $author_id = get_post_field( 'post_author', $topic_id ) )
    489                         $author_url = bbp_get_user_profile_url( $author_id );
     520                if ( $author_url = bbp_get_topic_author_url( $topic_id ) )
     521                        $author_link = sprintf( '<a href="%1$s"%2$s>%3$s</a>', $author_url, $link_title, $link_text );
    490522                else
    491                         $author_url = get_post_meta( $topic_id, '_bbp_anonymous_website', true );
     523                        $author_link = $link_text;
    492524
    493                 return apply_filters( 'bbp_get_topic_author_url', $author_url );
     525                return apply_filters( 'bbp_get_topic_author_link', $author_link, $topic_id );
    494526        }
    495527
     528                /**
     529                 * bbp_topic_author_url ()
     530                 *
     531                 * Output the author url of the topic in the loop
     532                 *
     533                 * @package bbPress
     534                 * @subpackage Template Tags
     535                 * @since bbPress (r2590)
     536                 * @param int $topic_id optional
     537                 *
     538                 * @uses bbp_get_topic_author_url()
     539                 */
     540                function bbp_topic_author_url ( $topic_id = 0 ) {
     541                        echo bbp_get_topic_author_url( $topic_id );
     542                }
     543                        /**
     544                         * bbp_get_topic_author_url ()
     545                         *
     546                         * Return the author url of the topic in the loop
     547                         *
     548                         * @package bbPress
     549                         * @subpackage Template Tags
     550                         * @since bbPress (r2590)
     551                         *
     552                         * @uses bbp_get_user_profile_url()
     553                         * @uses get_post_meta()
     554                         *
     555                         * @param int $topic_id optional
     556                         * @return string Author URL of topic
     557                         */
     558                        function bbp_get_topic_author_url ( $topic_id = 0 ) {
     559                                $topic_id = bbp_get_topic_id( $topic_id );
     560
     561                                // Check for anonymous user
     562                                if ( $author_id = get_post_field( 'post_author', $topic_id ) )
     563                                        $author_url = bbp_get_user_profile_url( $author_id );
     564                                else
     565                                        if ( !$author_url = get_post_meta( $topic_id, '_bbp_anonymous_website', true ) )
     566                                                $author_url = '';
     567
     568                                return apply_filters( 'bbp_get_topic_author_url', $author_url, $topic_id );
     569                        }
     570
    496571/**
    497572 * bbp_topic_forum_title ()
    498573 *
     
    858933                $topic_id = bbp_get_topic_id( $topic_id );
    859934
    860935                // Look for existing count, and populate if does not exist
    861                 if ( !$voices = get_post_meta( $topic_id, '_bbp_topic_voice_count', true ) )
     936                if ( !$voices   = get_post_meta( $topic_id, '_bbp_topic_voice_count', true ) )
    862937                        $voices = bbp_update_topic_voice_count( $topic_id );
    863938
    864939                return apply_filters( 'bbp_get_topic_voice_count', (int)$voices, $topic_id );
  • bbp-themes/bbp-twentyten/loop-bbp_replies.php

     
    5858                                        <td class="bbp-reply-author">
    5959                                                <?php
    6060                                                        // @todo - abstract
    61                                                         printf (
    62                                                                 '<a href="%1$s" title="%2$s">%3$s</a>',
    63                                                                 bbp_get_reply_author_url(),
    64                                                                 sprintf( get_the_author_meta( 'ID' ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s Website' ), bbp_get_reply_author_display_name() ),
    65                                                                 bbp_get_reply_author_avatar( 0, 80 )
    66                                                         );
     61                                                        bbp_reply_author_link();
    6762                                                ?>
    6863                                        </td>
    6964
  • bbp-themes/bbp-twentyten/loop-bbp_topics.php

     
    3636
    3737                                                <p class="bbp-topic-meta">
    3838
    39                                                         <?php printf( 'Started by: <a href="%1$s">%2$s</a>', bbp_get_topic_author_url(), bbp_get_topic_author() ); ?>
     39                                                        <?php printf( __( 'Started by: %1$s', 'bbpress' ), bbp_get_topic_author_link() ); ?>
    4040
    41                                                         <?php if ( !bbp_is_forum() ) printf( 'in: <a href="%1$s">%2$s</a>', bbp_get_forum_permalink( bbp_get_topic_forum_id() ), bbp_get_forum_title( bbp_get_topic_forum_id() ) ); ?>
     41                                                        <?php if ( !bbp_is_forum() ) printf( __( 'in: <a href="%1$s">%2$s</a>', 'bbpress' ), bbp_get_forum_permalink( bbp_get_topic_forum_id() ), bbp_get_forum_title( bbp_get_topic_forum_id() ) ); ?>
    4242
    4343                                                </p>
    4444
  • bbp-themes/bbp-twentyten/single-bbp_topic.php

     
    6969
    7070                                                                                        <?php
    7171                                                                                                // @todo - abstract
    72                                                                                                 printf (
    73                                                                                                         '<a href="%1$s" title="%2$s">%3$s</a>',
    74                                                                                                         bbp_get_topic_author_url(),
    75                                                                                                         sprintf( get_the_author_meta( 'ID' ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s Website' ), bbp_get_topic_author_display_name() ),
    76                                                                                                         bbp_get_topic_author_avatar( 0, 100 )
    77                                                                                                 );
     72                                                                                                bbp_topic_author_link();
    7873                                                                                        ?>
    7974
    8075                                                                                </td>