Skip to:
Content

BuddyPress.org

Changeset 13305


Ignore:
Timestamp:
07/26/2022 02:08:37 PM (4 years ago)
Author:
imath
Message:

Improve the new_blog_post activity type layout

These type of activities are generated when a blog post is published. If [13298] already brought some improvements making the included post featured image clickable, this changeset complement the first one:

  • by adding the post title into the activity content and linking it as well as the "read more" ellipsis to the post permalink. This "read more" link is generated using the WordPress the_content_more_link filter which means if your theme is using this filter to adapt the "read more" link, these adaptations will also be applied to the activity "read more" link.
  • by changing the markup used into these activities and by adding some CSS rules to make them looks more like WordPress embeds.

Props teeboy4real

Fixes #8052

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-functions.php

    r13298 r13305  
    34613461        );
    34623462
    3463         $post_url = '';
     3463        $post_url        = '';
     3464        $post_title      = '';
     3465        $bp_excerpt_args = array(
     3466                'html'              => false,
     3467                'filter_shortcodes' => true,
     3468                'strip_tags'        => true,
     3469                'remove_links'      => true,
     3470        );
    34643471        // Get the WP_Post object if this activity type is a blog post.
    34653472        if ( $activity['type'] === 'new_blog_post' ) {
    3466                 $content  = get_post( $activity['secondary_item_id'] );
    3467                 $post_url = $content->guid;
     3473                $content    = get_post( $activity['secondary_item_id'] );
     3474                $post_url   = $content->guid;
     3475                $post_title = sprintf(
     3476                        '<strong><a href="%1$s">%2$s</a></strong>',
     3477                        esc_url( $post_url ),
     3478                        esc_html( $content->post_title )
     3479                );
     3480
     3481                $more_text  = sprintf(
     3482                        '<span>%s</span>',
     3483                        trim( __( ' [&hellip;]', 'buddypress' ) )
     3484                );
     3485
     3486                /** This filter is documented in wp-admin/includes/post-template.php */
     3487                $bp_excerpt_args['ending'] = apply_filters(
     3488                        'the_content_more_link',
     3489                        sprintf(
     3490                                ' <a href="%1$s">%2$s</a>',
     3491                                esc_url( $post_url ),
     3492                                $more_text
     3493                        ),
     3494                        $more_text
     3495                );
    34683496        }
    34693497
     
    35803608
    35813609        // Generate a text excerpt for this activity item (and remove any oEmbeds URLs).
    3582         $summary = bp_create_excerpt( html_entity_decode( $content ), 225, array(
    3583                 'html' => false,
    3584                 'filter_shortcodes' => true,
    3585                 'strip_tags'        => true,
    3586                 'remove_links'      => true
    3587         ) );
     3610        $summary_parts = array(
     3611                str_replace(
     3612                        array( "\n", "\r" ),
     3613                        ' ',
     3614                        trim( bp_create_excerpt( html_entity_decode( $content ), 225, $bp_excerpt_args ) )
     3615                ),
     3616        );
    35883617
    35893618        if ( $use_media_type === 'embeds' ) {
    3590                 $summary .= PHP_EOL . PHP_EOL . $extracted_media['url'];
     3619                $summary_parts[] = PHP_EOL . PHP_EOL . $extracted_media['url'];
    35913620        } elseif ( $use_media_type === 'images' ) {
    35923621                $extracted_media_url = isset( $extracted_media['url'] ) ? $extracted_media['url'] : '';
     3622                $image_tag           = sprintf( '<img src="%s"> ', esc_url( $extracted_media_url ) );
    35933623
    35943624                if ( $post_url ) {
    3595                         $summary .= sprintf( '<a href="%1$s" class="activity-post-featured-image"><img src="%2$s"></a>', esc_url( $post_url ), esc_url( $extracted_media_url ) );
    3596                 } else {
    3597                         $summary .= sprintf( ' <img src="%s">', esc_url( $extracted_media_url ) );
     3625                        $image_tag = sprintf( '<a href="%1$s" class="activity-post-featured-image">%2$s</a> ', esc_url( $post_url ), trim( $image_tag ) );
     3626                        array_unshift( $summary_parts, $image_tag );
    35983627                }
    35993628        } elseif ( in_array( $use_media_type, array( 'audio', 'videos' ), true ) ) {
    3600                 $summary .= PHP_EOL . PHP_EOL . $extracted_media['original'];  // Full shortcode.
    3601         }
     3629                $summary_parts[] = PHP_EOL . PHP_EOL . $extracted_media['original'];  // Full shortcode.
     3630        }
     3631
     3632        if ( $post_title ) {
     3633                array_unshift( $summary_parts, $post_title );
     3634        }
     3635
     3636        // Join summary parts.
     3637        $summary = implode( '', $summary_parts );
    36023638
    36033639        /**
  • trunk/src/bp-templates/bp-legacy/css/buddypress-rtl.css

    r13183 r13305  
    325325        margin-right: 5px;
    326326        padding-right: 10px;
     327}
     328
     329#buddypress .activity-list li.new_blog_post .activity-content .activity-inner strong {
     330        display: block;
     331        margin-bottom: 0.8em;
     332}
     333
     334#buddypress .activity-list li.new_blog_post .activity-content .activity-inner img {
     335        float: right;
     336        margin-left: 0.8em;
    327337}
    328338
  • trunk/src/bp-templates/bp-legacy/css/buddypress.css

    r13183 r13305  
    325325        margin-left: 5px;
    326326        padding-left: 10px;
     327}
     328
     329#buddypress .activity-list li.new_blog_post .activity-content .activity-inner strong {
     330        display: block;
     331        margin-bottom: 0.8em;
     332}
     333
     334#buddypress .activity-list li.new_blog_post .activity-content .activity-inner img {
     335        float: left;
     336        margin-right: 0.8em;
    327337}
    328338
  • trunk/src/bp-templates/bp-nouveau/common-styles/_bp_activity_entries.scss

    r13182 r13305  
    9090                        }
    9191                } // close li forum elements
     92
     93                &.new_blog_post {
     94
     95                        .activity-inner {
     96
     97                                strong {
     98                                        display: block;
     99                                        margin-bottom: 0.8em;
     100                                }
     101
     102                                img {
     103                                        float: left;
     104                                        margin-right: 0.8em;
     105                                }
     106                        }
     107                } // close li blog post elements
    92108
    93109
  • trunk/src/bp-templates/bp-nouveau/css/buddypress-rtl.css

    r13289 r13305  
    13051305        margin-right: 10px;
    13061306        padding-right: 1em;
     1307}
     1308
     1309.activity-list .activity-item.new_blog_post .activity-inner strong {
     1310        display: block;
     1311        margin-bottom: 0.8em;
     1312}
     1313
     1314.activity-list .activity-item.new_blog_post .activity-inner img {
     1315        float: right;
     1316        margin-left: 0.8em;
    13071317}
    13081318
  • trunk/src/bp-templates/bp-nouveau/css/buddypress.css

    r13289 r13305  
    13051305        margin-left: 10px;
    13061306        padding-left: 1em;
     1307}
     1308
     1309.activity-list .activity-item.new_blog_post .activity-inner strong {
     1310        display: block;
     1311        margin-bottom: 0.8em;
     1312}
     1313
     1314.activity-list .activity-item.new_blog_post .activity-inner img {
     1315        float: left;
     1316        margin-right: 0.8em;
    13071317}
    13081318
  • trunk/tests/phpunit/testcases/activity/actions.php

    r13135 r13305  
    242242                $a = $this->activity_exists_for_post( $post_id, 'new_post', true );
    243243
    244                 $this->assertSame( $post->post_content, $a->content, 'The Activity about a published post type should be updated when the post content has changed.' );
     244                $this->assertSame( bp_activity_create_summary( $post->post_content, (array) $a ), $a->content, 'The Activity about a published post type should be updated when the post content has changed.' );
    245245        }
    246246
Note: See TracChangeset for help on using the changeset viewer.