Skip to:
Content

BuddyPress.org

Ticket #3253: 3253.3.diff

File 3253.3.diff, 15.8 KB (added by boonebgorges, 13 years ago)
  • bp-activity/bp-activity-template.php

    function bp_activity_avatar( $args = '' ) { 
    536536                global $bp, $activities_template;
    537537
    538538                $defaults = array(
    539                         'type'   => 'thumb',
    540                         'width'  => 20,
    541                         'height' => 20,
    542                         'class'  => 'avatar',
    543                         'alt'    => __( 'Profile picture of %s', 'buddypress' ),
    544                         'email'  => false
     539                        'type'    => 'thumb',
     540                        'width'   => 20,
     541                        'height'  => 20,
     542                        'class'   => 'avatar',
     543                        'alt'     => __( 'Profile picture of %s', 'buddypress' ),
     544                        'email'   => false,
     545                        'user_id' => false
    545546                );
    546547
    547548                $r = wp_parse_args( $args, $defaults );
    function bp_activity_avatar( $args = '' ) { 
    552553                $item_id = apply_filters( 'bp_get_activity_avatar_item_id', $activities_template->activity->user_id );
    553554
    554555                // If this is a user object pass the users' email address for Gravatar so we don't have to refetch it.
    555                 if ( 'user' == $object && empty( $email ) && isset( $activities_template->activity->user_email ) )
     556                if ( 'user' == $object && empty( $user_id ) && empty( $email ) && isset( $activities_template->activity->user_email ) )
    556557                        $email = $activities_template->activity->user_email;
    557558
    558559                return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) );
    function bp_activity_is_favorite() { 
    775776                return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array)$activities_template->my_favs ) );
    776777        }
    777778
     779/**
     780 * Echoes the comment markup for an activity item
     781 *
     782 * @package BuddyPress
     783 * @subpackage Activity Template
     784 *
     785 * @param str $args Unused
     786 */
    778787function bp_activity_comments( $args = '' ) {
    779788        echo bp_activity_get_comments( $args );
    780789}
     790        /**
     791         * Gets the comment markup for an activity item
     792         *
     793         * @package BuddyPress
     794         * @subpackage Activity Template
     795         *
     796         * @param str $args Unused. Appears to be left over from an earlier implementation.
     797         * @todo Given that checks for children already happen in bp_activity_recurse_comments(),
     798         *    this function can probably be streamlined or removed.
     799         */
    781800        function bp_activity_get_comments( $args = '' ) {
    782801                global $activities_template, $bp;
    783802
    784803                if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
    785804                        return false;
    786805
    787                 $comments_html = bp_activity_recurse_comments( $activities_template->activity );
    788 
    789                 return apply_filters( 'bp_activity_get_comments', $comments_html );
     806                bp_activity_recurse_comments( $activities_template->activity );
    790807        }
    791                 // TODO: The HTML in this function is temporary and will be moved
    792                 // to the template in a future version
     808       
     809                /**
     810                 * Loops through a level of activity comments and loads the template for each
     811                 *
     812                 * Note: The recursion itself used to happen entirely in this function. Now it is
     813                 * split between here and the comment.php template.
     814                 *
     815                 * @package BuddyPress
     816                 * @subpackage Activity Template
     817                 *
     818                 * @param obj $comment The activity object currently being recursed
     819                 */
    793820                function bp_activity_recurse_comments( $comment ) {
    794                         global $activities_template, $bp;
    795 
     821                        global $activities_template, $bp, $counter;
     822                       
     823                        if ( !$comment )
     824                                return false;
     825                               
    796826                        if ( !$comment->children )
    797827                                return false;
    798828
    799                         $content = '<ul>';
     829                        echo '<ul>';
    800830                        foreach ( (array)$comment->children as $comment_child ) {
    801831                                // Put the comment into the global so it's available to filters
    802832                                $activities_template->activity->current_comment = $comment_child;
    803833
    804                                 if ( empty( $comment_child->user_fullname ) )
    805                                         $comment_child->user_fullname = $comment_child->display_name;
    806 
    807                                 if ( empty( $comment_child->user_nicename ) )
    808                                         $comment_child->user_nicename = '';
    809 
    810                                 if ( empty( $comment_child->user_login ) )
    811                                         $comment_child->user_login = '';
    812 
    813                                 if ( empty( $comment_child->user_email ) )
    814                                         $comment_child->user_email = '';
    815 
    816                                 $content .= '<li id="acomment-' . $comment_child->id . '">';
    817                                 $content .= '<div class="acomment-avatar"><a href="' .
    818                                         bp_core_get_user_domain(
    819                                                 $comment_child->user_id,
    820                                                 $comment_child->user_nicename,
    821                                                 $comment_child->user_login ) . '">' .
    822                                         bp_core_fetch_avatar( array(
    823                                                 'alt'    => __( 'Profile picture of %s', 'buddypress' ),
    824                                                 'item_id' => $comment_child->user_id,
    825                                                 'width'   => 30,
    826                                                 'height'  => 30,
    827                                                 'email'   => $comment_child->user_email
    828                                         ) ) .
    829                                 '</a></div>';
    830 
    831                                 $content .= '<div class="acomment-meta"><a href="' .
    832                                         bp_core_get_user_domain(
    833                                                 $comment_child->user_id,
    834                                                 $comment_child->user_nicename,
    835                                                 $comment_child->user_login ) . '">' .
    836                                         apply_filters( 'bp_acomment_name', $comment_child->user_fullname, $comment_child ) .
    837                                 '</a> &middot; ' . sprintf( __( '%s ago', 'buddypress' ), bp_core_time_since( $comment_child->date_recorded ) );
    838 
    839                                 // Reply link - the span is so that threaded reply links can be
    840                                 // hidden when JS is off.
    841                                 if ( is_user_logged_in() && bp_activity_can_comment_reply( $comment ) )
    842                                         $content .= apply_filters( 'bp_activity_comment_reply_link', '<span class="acomment-replylink"> &middot; <a href="#acomment-' . $comment_child->id . '" class="acomment-reply" id="acomment-reply-' . $activities_template->activity->id . '">' . __( 'Reply', 'buddypress' ) . '</a></span>', $comment_child );
    843 
    844                                 // Delete link
    845                                 if ( $bp->loggedin_user->is_super_admin || $bp->loggedin_user->id == $comment->user_id ) {
    846                                         $delete_url = wp_nonce_url( bp_get_root_domain() . '/' . $bp->activity->slug . '/delete/?cid=' . $comment_child->id, 'bp_activity_delete_link' );
    847                                         $content .= apply_filters( 'bp_activity_comment_delete_link', ' &middot; <a href="' . $delete_url . '" class="delete acomment-delete confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>', $comment_child, $delete_url );
     834                                $template = locate_template( 'activity/comment.php', false, false );
     835                               
     836                                // Backward compatibility. In older versions of BP, the markup was
     837                                // generated in the PHP instead of a template. This ensures that
     838                                // older themes (which are not children of bp-default and won't
     839                                // have the new template) will still work.
     840                                if ( !$template ) {
     841                                        $template = BP_PLUGIN_DIR . '/bp-themes/bp-default/activity/comment.php';
    848842                                }
     843                               
     844                                load_template( $template, false );
     845                               
     846                                unset( $activities_template->activity->current_comment );
     847                        }
     848                        echo '</ul>';
     849                }
    849850
    850                                 $content .= '</div>';
    851                                 $content .= '<div class="acomment-content">' . apply_filters( 'bp_get_activity_content', $comment_child->content ) . '</div>';
     851/**
     852 * Utility function that returns the comment currently being recursed
     853 *
     854 * @package BuddyPress
     855 * @subpackage Activity Template
     856 * @since 1.3
     857 *
     858 * @return obj $current_comment The activity comment currently being displayed
     859 */
     860function bp_activity_current_comment() {
     861        global $activities_template;
     862       
     863        $current_comment = !empty( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : false;
     864       
     865        return apply_filters( 'bp_activity_current_comment', $current_comment );
     866}
    852867
    853                                 $content .= bp_activity_recurse_comments( $comment_child );
    854                                 $content .= '</li>';
    855868
    856                                 // Unset in the global in case of the last iteration
    857                                 unset( $activities_template->activity->current_comment );
    858                         }
    859                         $content .= '</ul>';
     869/**
     870 * Echoes the id of the activity comment currently being displayed
     871 *
     872 * @package BuddyPress
     873 * @subpackage Activity Template
     874 * @since 1.3
     875 */
     876function bp_activity_comment_id() {
     877        echo bp_get_activity_comment_id();
     878}
     879        /**
     880         * Gets the id of the activity comment currently being displayed
     881         *
     882         * @package BuddyPress
     883         * @subpackage Activity Template
     884         * @since 1.3
     885         *
     886         * @return int $comment_id The id of the activity comment currently being displayed
     887         */
     888        function bp_get_activity_comment_id() {
     889                global $activities_template;
     890               
     891                $comment_id = isset( $activities_template->activity->current_comment->id ) ? $activities_template->activity->current_comment->id : false;
     892       
     893                return apply_filters( 'bp_activity_comment_id', $comment_id );
     894        }
    860895
    861                         return apply_filters( 'bp_activity_recurse_comments', $content );
    862                 }
     896/**
     897 * Echoes the user_id of the author of the activity comment currently being displayed
     898 *
     899 * @package BuddyPress
     900 * @subpackage Activity Template
     901 * @since 1.3
     902 */
     903function bp_activity_comment_user_id() {
     904        echo bp_get_activity_comment_user_id();
     905}
     906        /**
     907         * Gets the user_id of the author of the activity comment currently being displayed
     908         *
     909         * @package BuddyPress
     910         * @subpackage Activity Template
     911         * @since 1.3
     912         *
     913         * @return int $user_id The user_id of the author of the displayed activity comment
     914         */
     915        function bp_get_activity_comment_user_id() {
     916                global $activities_template;
     917               
     918                $user_id = isset( $activities_template->activity->current_comment->user_id ) ? $activities_template->activity->current_comment->user_id : false;
     919               
     920                return apply_filters( 'bp_activity_comment_user_id', $user_id );
     921        }
     922
     923/**
     924 * Echoes the author link for the activity comment currently being displayed
     925 *
     926 * @package BuddyPress
     927 * @subpackage Activity Template
     928 * @since 1.3
     929 */
     930function bp_activity_comment_user_link() {
     931        echo bp_get_activity_comment_user_link();
     932}
     933        /**
     934         * Gets the author link for the activity comment currently being displayed
     935         *
     936         * @package BuddyPress
     937         * @subpackage Activity Template
     938         * @since 1.3
     939         *
     940         * @return str $user_link The URL of the activity comment author's profile
     941         */
     942        function bp_get_activity_comment_user_link() {
     943                $user_link = bp_core_get_user_domain( bp_get_activity_comment_user_id() );
     944       
     945                return apply_filters( 'bp_activity_comment_user_link', $user_link );
     946        }
     947
     948/**
     949 * Echoes the author name for the activity comment currently being displayed
     950 *
     951 * @package BuddyPress
     952 * @subpackage Activity Template
     953 * @since 1.3
     954 */
     955function bp_activity_comment_name() {
     956        echo bp_get_activity_comment_name();
     957}
     958        /**
     959         * Gets the author name for the activity comment currently being displayed
     960         *
     961         * The use of the bp_acomment_name filter is deprecated. Please use bp_activity_comment_name
     962         *
     963         * @package BuddyPress
     964         * @subpackage Activity Template
     965         * @since 1.3
     966         *
     967         * @return str $name The full name of the activity comment author
     968         */
     969        function bp_get_activity_comment_name() {
     970                global $activities_template;
     971               
     972                $name = apply_filters( 'bp_acomment_name', $activities_template->activity->current_comment->user_fullname, $activities_template->activity->current_comment ); // backward compatibility
     973               
     974                return apply_filters( 'bp_activity_comment_name', $name );
     975        }
     976
     977/**
     978 * Echoes the date_recorded of the activity comment currently being displayed
     979 *
     980 * @package BuddyPress
     981 * @subpackage Activity Template
     982 * @since 1.3
     983 */
     984function bp_activity_comment_date_recorded() {
     985        echo bp_get_activity_comment_date_recorded();
     986}
     987        /**
     988         * Gets the date_recorded for the activity comment currently being displayed
     989         *
     990         * @package BuddyPress
     991         * @subpackage Activity Template
     992         * @since 1.3
     993         *
     994         * @return str $date_recorded Time since the activity was recorded, of the form "%s ago"
     995         */
     996        function bp_get_activity_comment_date_recorded() {
     997                global $activities_template;
     998               
     999                if ( empty( $activities_template->activity->current_comment->date_recorded ) )
     1000                        return false;
     1001               
     1002                $date_recorded = sprintf( __( '%s ago', 'buddypress' ), bp_core_time_since( $activities_template->activity->current_comment->date_recorded ) );
     1003               
     1004                return apply_filters( 'bp_activity_comment_date_recorded', $date_recorded );
     1005        }
     1006
     1007/**
     1008 * Echoes the 'delete' URL for the activity comment currently being displayed
     1009 *
     1010 * @package BuddyPress
     1011 * @subpackage Activity Template
     1012 * @since 1.3
     1013 */
     1014function bp_activity_comment_delete_link() {
     1015        echo bp_get_activity_comment_delete_link();
     1016}
     1017        /**
     1018         * Gets the 'delete' URL for the activity comment currently being displayed
     1019         *
     1020         * @package BuddyPress
     1021         * @subpackage Activity Template
     1022         * @since 1.3
     1023         *
     1024         * @return str $link The nonced URL for deleting the current activity comment
     1025         */
     1026        function bp_get_activity_comment_delete_link() {
     1027                global $bp;
     1028               
     1029                $link = wp_nonce_url( bp_get_root_domain() . '/' . $bp->activity->slug . '/delete/?cid=' . bp_get_activity_comment_id(), 'bp_activity_delete_link' );
     1030               
     1031                return apply_filters( 'bp_activity_comment_delete_link', $link );
     1032        }
     1033
     1034/**
     1035 * Echoes the content of the activity comment currently being displayed
     1036 *
     1037 * @package BuddyPress
     1038 * @subpackage Activity Template
     1039 * @since 1.3
     1040 */
     1041function bp_activity_comment_content() {
     1042        echo bp_get_activity_comment_content();
     1043}
     1044        /**
     1045         * Gets the content of the activity comment currently being displayed
     1046         *
     1047         * The content is run through two filters. bp_get_activity_content will apply all filters
     1048         * applied to activity items in general. Use bp_activity_comment_content to modify the
     1049         * content of activity comments only.
     1050         *
     1051         * @package BuddyPress
     1052         * @subpackage Activity Template
     1053         * @since 1.3
     1054         *
     1055         * @return str $content The content of the current activity comment
     1056         */
     1057        function bp_get_activity_comment_content() {
     1058                global $activities_template;
     1059               
     1060                $content = apply_filters( 'bp_get_activity_content', $activities_template->activity->current_comment->content );
     1061               
     1062                return apply_filters( 'bp_activity_comment_content', $content );
     1063        }
    8631064
    8641065function bp_activity_comment_count() {
    8651066        echo bp_activity_get_comment_count();
  • bp-themes/bp-default/activity/entry.php

    new file mode 100644
    ---bp-themes/bp-default/activity/comment.php	(revision 0)n+++bp-themes/bp-default/activity/comment.php	(revision 0)
    @@ -0,0 +1,45 @@
    +<?php
    +
    +/**
    + * BuddyPress - Activity Stream Comment
    + *
    + * This template is used by bp_activity_comments() functions to show
    + * each activity.
    + *
    + * @package BuddyPress
    + * @subpackage bp-default
    + */
    + 
    +?>
    +
    +<?php do_action( 'bp_before_activity_comment' ); ?>
    +
    +<li id="acomment-<?php bp_activity_comment_id() ?>">
    +	<div class="acomment-avatar">
    +		<a href="<?php bp_activity_comment_user_link() ?>">
    +			<?php bp_activity_avatar( 'type=full&width=30&height=30&user_id=' . bp_get_activity_comment_user_id() ); ?>
    +		</a>
    +	</div>
    +
    +	<div class="acomment-meta">
    +		<a href="<?php bp_activity_comment_user_link() ?>"><?php bp_activity_comment_name() ?></a> &middot; <?php bp_activity_comment_date_recorded() ?>
    +
    +		<?php if ( is_user_logged_in() && bp_activity_can_comment_reply( bp_activity_current_comment() ) ) : ?>
    +			<span class="acomment-replylink"> &middot; <a href="#acomment-<?php bp_activity_comment_id() ?>" class="acomment-reply" id="acomment-reply-<?php bp_activity_id() ?>"><?php _e( 'Reply', 'buddypress' ) ?></a></span>
    +		<?php endif ?>
    +	
    +		<?php if ( bp_activity_user_can_delete() ) : ?>
    +			&middot; <a href="<?php bp_activity_comment_delete_link() ?>" class="delete acomment-delete confirm" rel="nofollow"><?php _e( 'Delete', 'buddypress' ) ?></a>
    +		<?php endif ?>
    +
    +	</div>
    +	
    +	
    +	<div class="acomment-content">
    +		<?php bp_activity_comment_content() ?>
    +	</div>
    +	
    +	<?php bp_activity_recurse_comments( bp_activity_current_comment() ) ?>
    +</li>
    +
    +<?php do_action( 'bp_after_activity_comment' ); ?>
     
    8080
    8181        <?php if ( bp_activity_can_comment() ) : ?>
    8282                <div class="activity-comments">
    83 
     83                       
    8484                        <?php bp_activity_comments(); ?>
    8585
    8686                        <?php if ( is_user_logged_in() ) : ?>