Skip to:
Content

BuddyPress.org

Changeset 4239


Ignore:
Timestamp:
04/22/2011 08:30:22 PM (13 years ago)
Author:
boonebgorges
Message:

Adds Read More functionality to activity comments. Adds AJAX functionality to activity Read More. Fixes #2635. Fixes bugs with the way that activity comment content and meta links are displayed. Fixes #3168.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-filters.php

    r4229 r4239  
    157157 */
    158158function bp_activity_truncate_entry( $text ) {
     159    global $activities_template;
     160   
    159161    // The full text of the activity update should always show on the single activity screen
    160162    if ( bp_is_single_activity() )
     
    164166    $excerpt_length = apply_filters( 'bp_activity_excerpt_length', 358 );
    165167    $excerpt        = $text;
    166 
     168   
     169    $id     = !empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id();
     170   
    167171    if ( strlen( $excerpt ) > $excerpt_length )
    168         $excerpt = sprintf( '%1$s<span class="activity-read-more"><a href="%2$s" rel="nofollow">%3$s</a></span>', bp_create_excerpt( $excerpt, $excerpt_length, true, '&hellip;' ), bp_get_activity_thread_permalink(), $append_text );
     172        $excerpt = sprintf( '%1$s<span class="activity-read-more" id="%2$s"><a href="%3$s" rel="nofollow">%4$s</a></span>', bp_create_excerpt( $excerpt, $excerpt_length, true, '&hellip;' ), $id, bp_get_activity_thread_permalink(), $append_text );
    169173   
    170174    return apply_filters( 'bp_activity_truncate_entry', $excerpt, $text, $append_text );
    171175}
    172176add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
     177add_filter( 'bp_get_activity_content', 'bp_activity_truncate_entry', 5 );
    173178?>
  • trunk/bp-activity/bp-activity-template.php

    r4216 r4239  
    800800            $content = '<ul>';
    801801            foreach ( (array)$comment->children as $comment_child ) {
     802                // Put the comment into the global so it's available to filters
     803                $activities_template->activity->current_comment = $comment_child;
     804               
    802805                if ( empty( $comment_child->user_fullname ) )
    803806                    $comment_child->user_fullname = $comment_child->display_name;
     
    837840                // hidden when JS is off.
    838841                if ( is_user_logged_in() && bp_activity_can_comment_reply( $comment ) )
    839                     $content .= apply_filters( 'bp_activity_comment_reply_link', '<span class="acomment-replylink"> &middot; <a href="#acomment-' . $comment->id . '" class="acomment-reply" id="acomment-reply-' . $activities_template->activity->id . '">' . __( 'Reply', 'buddypress' ) . '</a></span>', $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-' . $comment->id . '">' . __( 'Reply', 'buddypress' ) . '</a></span>', $comment_child );
    840843
    841844                // Delete link
    842845                if ( $bp->loggedin_user->is_super_admin || $bp->loggedin_user->id == $comment->user_id ) {
    843                     $delete_url = wp_nonce_url( bp_get_root_domain() . '/' . $bp->activity->slug . '/delete/?cid=' . $comment->id, 'bp_activity_delete_link' );
    844                     $content .= apply_filters( 'bp_activity_comment_delete_link', ' &middot; <a href="' . $delete_url . '" class="delete acomment-delete" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>', $comment, $delete_url );
     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" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>', $comment_child, $delete_url );
    845848                }
    846849
    847850                $content .= '</div>';
    848                 $content .= '<div class="acomment-content">' . apply_filters( 'bp_get_activity_content', $comment->content ) . '</div>';
     851                $content .= '<div class="acomment-content">' . apply_filters( 'bp_get_activity_content', $comment_child->content ) . '</div>';
    849852
    850853                $content .= bp_activity_recurse_comments( $comment_child );
    851854                $content .= '</li>';
     855               
     856                // Unset in the global in case of the last iteration
     857                unset( $activities_template->activity->current_comment );
    852858            }
    853859            $content .= '</ul>';
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r4230 r4239  
    320320add_action( 'wp_ajax_activity_mark_unfav', 'bp_dtheme_unmark_activity_favorite' );
    321321
     322/**
     323 * AJAX handler for Read More link on long activity items
     324 *
     325 * @package BuddyPress
     326 * @since 1.3
     327 */
     328function bp_dtheme_get_single_activity_content() {
     329    $activity_array = bp_activity_get_specific( array(
     330        'activity_ids'      => $_POST['activity_id'],
     331        'display_comments'  => 'stream'
     332    ) );
     333   
     334    $activity = !empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
     335   
     336    if ( !$activity )
     337        exit(); // todo: error?
     338   
     339    // Activity content retrieved through AJAX should run through normal filters, but not be
     340    // truncated
     341    remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
     342    $content = apply_filters( 'bp_get_activity_content_body', $activity->content );
     343   
     344    echo $content;
     345   
     346    exit();
     347}
     348add_action( 'wp_ajax_get_single_activity_content', 'bp_dtheme_get_single_activity_content' );
     349
    322350/* AJAX invite a friend to a group functionality */
    323351function bp_dtheme_ajax_invite_user() {
  • trunk/bp-themes/bp-default/_inc/global.js

    r4232 r4239  
    265265            return false;
    266266        }
     267    });
     268
     269    /* Activity "Read More" links */
     270    jq('.activity-read-more a').click(function(event) {
     271        var target = jq(event.target);
     272        var link_id = target.parent().attr('id').split('-');
     273        var a_id = link_id[3];
     274        var type = link_id[0]; /* activity or acomment */
     275       
     276        var inner_class = type == 'acomment' ? 'acomment-content' : 'activity-inner';
     277        var a_inner = jq('li#' + type + '-' + a_id + ' .' + inner_class );
     278       
     279        jq.post( ajaxurl, {
     280            action: 'get_single_activity_content',
     281            'activity_id': a_id
     282        },
     283        function(response) {
     284            jq(a_inner).slideUp(200,function(){
     285                jq(a_inner).html(response);
     286                jq(a_inner).slideDown(200);
     287            });
     288        });
     289       
     290       
     291        return false;
    267292    });
    268293
Note: See TracChangeset for help on using the changeset viewer.