Skip to:
Content

BuddyPress.org

Changeset 2383 for trunk/bp-activity.php


Ignore:
Timestamp:
01/20/2010 05:43:49 PM (15 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

File:
1 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    }
Note: See TracChangeset for help on using the changeset viewer.