Skip to:
Content

BuddyPress.org

Changeset 2383


Ignore:
Timestamp:
01/20/2010 05:43:49 PM (14 years ago)
Author:
apeatling
Message:

Auto thumbnail the first image in a blog post and display it on the activity stream. This stops huge images in blogs posts from displaying on the stream and messing with the design. Fixes #1620

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2382 r2383  
    487487        $content = bp_activity_add_timesince_placeholder( $content );
    488488
    489     /* Remove any images and replace the first image with a thumbnail */
    490     //$content = bp_activity_thumbnail_images( $content );
    491 
    492489    $activity = new BP_Activity_Activity( $id );
    493490
     
    710707}
    711708
    712 function bp_activity_thumbnail_images( $content ) {
     709function bp_activity_thumnail_content_images( $content ) {
    713710    preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
    714711    $content = preg_replace('/<img[^>]*>/Ui', '', $content );
     
    718715        preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src );
    719716
     717        /* Get the width and height */
     718        preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
     719        preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width );
     720
    720721        if ( !empty( $src ) ) {
    721722            $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
    722             $pos = strpos( $content, '<blockquote>' );
    723             $before = substr( $content, 0, (int) $pos );
    724             $after = substr( $content, (int) $pos, strlen( $content ) );
    725 
    726             $content = $before . '<img src="' . esc_attr( $src) . '" width="100" height="100" alt="thumb" class="align-left thumbnail" />' . $after;
     723            $height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
     724            $width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
     725
     726            if ( empty( $width ) || empty( $height ) ) {
     727                $width = 100;
     728                $height = 100;
     729            }
     730
     731            $ratio = (int)$width / (int)$height;
     732            $new_height = 100;
     733            $new_width = $new_height * $ratio;
     734
     735            $content = '<img src="' . esc_attr( $src) . '" width="' . $new_width . '" height="' . $new_height . '" alt="' . __( 'Thumbnail', 'buddypress' ) . '" class="align-left thumbnail" />' . $content;
    727736        }
    728737    }
  • trunk/bp-activity/bp-activity-templatetags.php

    r2381 r2383  
    559559        global $activities_template;
    560560
    561         $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_actions', array(
     561        $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array(
    562562            'friendship_accepted',
    563563            'friendship_created',
     
    569569
    570570        $class = '';
    571         if ( in_array( $activities_template->activity->type, (array)$mini_activity_actions ) )
     571        if ( in_array( $activities_template->activity->type, (array)$mini_activity_actions ) || empty( $activities_template->activity->content ) )
    572572            $class = ' mini';
    573573
  • trunk/bp-blogs.php

    r2381 r2383  
    260260    extract( $r, EXTR_SKIP );
    261261
     262    /* Remove large images and replace them with just one image thumbnail */
     263    if ( function_exists( 'bp_activity_thumnail_content_images' ) && !empty( $content ) )
     264        $content = bp_activity_thumnail_content_images( $content );
     265
     266    $action = apply_filters( 'bp_blogs_record_activity_action', $action );
     267    $content = apply_filters( 'bp_blogs_record_activity_content', "<blockquote>" . bp_create_excerpt( $content ) . "</blockquote>" );
     268
    262269    return bp_activity_add( array( 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
    263270}
     
    391398
    392399                $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
    393                 $activity_content = "<blockquote>" . bp_create_excerpt( $post->post_content ) . "</blockquote>";
     400                $activity_content = $post->post_content;
    394401
    395402                bp_blogs_record_activity( array(
     
    429436
    430437            $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
    431             $activity_content = "<blockquote>" . bp_create_excerpt( $post->post_content ) . "</blockquote>";
     438            $activity_content = $post->post_content;
    432439
    433440            /* Record this in activity streams */
     
    487494        $comment_link = bp_post_get_permalink( $comment->post, $wpdb->blogid ) . '#comment-' . $comment_id;
    488495        $activity_action = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' );
    489         $activity_content = '<blockquote>' . bp_create_excerpt( $comment->comment_content ) . '</blockquote>';
     496        $activity_content = $comment->comment_content;
    490497
    491498        /* Record this in activity streams */
  • trunk/bp-core/bp-core-templatetags.php

    r2378 r2383  
    10961096    return apply_filters( 'bp_create_excerpt', $text );
    10971097}
    1098 add_filter( 'bp_create_excerpt', 'wptexturize' );
    1099 add_filter( 'bp_create_excerpt', 'convert_smilies' );
    1100 add_filter( 'bp_create_excerpt', 'convert_chars' );
    1101 add_filter( 'bp_create_excerpt', 'wpautop' );
    11021098add_filter( 'bp_create_excerpt', 'wp_trim_excerpt' );
    11031099add_filter( 'bp_create_excerpt', 'stripslashes_deep' );
  • trunk/bp-themes/bp-default/_inc/css/default.css

    r2381 r2383  
    10591059        padding: 0;
    10601060        margin: 0;
     1061        overflow: auto;
    10611062    }
    10621063
     
    11411142    .activity-list .activity-content blockquote {
    11421143        margin: 15px 0 15px 5px;
     1144        overflow: auto;
    11431145    }
    11441146        body.activity-permalink .activity-content .activity-inner,
     
    11461148            margin-top: 5px;
    11471149        }
     1150
     1151    .activity-list .activity-content img.thumbnail {
     1152        float: left;
     1153        margin: 0 10px 5px 0;
     1154        border: 2px solid #eee;
     1155    }
    11481156
    11491157.activity-list li.load-more {
     
    11681176div.activity-meta {
    11691177    margin: 0 0 20px 3px;
     1178    clear: left;
    11701179}
    11711180
Note: See TracChangeset for help on using the changeset viewer.