<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [2383] trunk:
  Auto thumbnail the first image in a blog post and display it on the activity stream
 .</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>2383</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2010-01-20 17:43:49 +0000 (Wed, 20 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>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</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivitytemplatetagsphp">trunk/bp-activity/bp-activity-templatetags.php</a></li>
<li><a href="#trunkbpactivityphp">trunk/bp-activity.php</a></li>
<li><a href="#trunkbpblogsphp">trunk/bp-blogs.php</a></li>
<li><a href="#trunkbpcorebpcoretemplatetagsphp">trunk/bp-core/bp-core-templatetags.php</a></li>
<li><a href="#trunkbpthemesbpdefault_inccssdefaultcss">trunk/bp-themes/bp-default/_inc/css/default.css</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivitytemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-templatetags.php (2382 => 2383)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-templatetags.php        2010-01-20 16:43:39 UTC (rev 2382)
+++ trunk/bp-activity/bp-activity-templatetags.php        2010-01-20 17:43:49 UTC (rev 2383)
</span><span class="lines">@@ -558,7 +558,7 @@
</span><span class="cx">         function bp_get_activity_css_class() {
</span><span class="cx">                 global $activities_template;
</span><span class="cx"> 
</span><del>-                $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_actions', array(
</del><ins>+                $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array(
</ins><span class="cx">                         'friendship_accepted',
</span><span class="cx">                         'friendship_created',
</span><span class="cx">                         'new_blog',
</span><span class="lines">@@ -568,7 +568,7 @@
</span><span class="cx">                 ) );
</span><span class="cx"> 
</span><span class="cx">                 $class = '';
</span><del>-                if ( in_array( $activities_template-&gt;activity-&gt;type, (array)$mini_activity_actions ) )
</del><ins>+                if ( in_array( $activities_template-&gt;activity-&gt;type, (array)$mini_activity_actions ) || empty( $activities_template-&gt;activity-&gt;content ) )
</ins><span class="cx">                         $class = ' mini';
</span><span class="cx"> 
</span><span class="cx">                 if ( bp_activity_get_comment_count() &amp;&amp; bp_activity_can_comment() )
</span></span></pre></div>
<a id="trunkbpactivityphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity.php (2382 => 2383)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity.php        2010-01-20 16:43:39 UTC (rev 2382)
+++ trunk/bp-activity.php        2010-01-20 17:43:49 UTC (rev 2383)
</span><span class="lines">@@ -486,9 +486,6 @@
</span><span class="cx">         else if ( empty( $action ) &amp;&amp; !empty( $content ) )
</span><span class="cx">                 $content = bp_activity_add_timesince_placeholder( $content );
</span><span class="cx"> 
</span><del>-        /* Remove any images and replace the first image with a thumbnail */
-        //$content = bp_activity_thumbnail_images( $content );
-
</del><span class="cx">         $activity = new BP_Activity_Activity( $id );
</span><span class="cx"> 
</span><span class="cx">         $activity-&gt;user_id = $user_id;
</span><span class="lines">@@ -709,7 +706,7 @@
</span><span class="cx">         return apply_filters( 'bp_activity_add_timesince_placeholder', $content );
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function bp_activity_thumbnail_images( $content ) {
</del><ins>+function bp_activity_thumnail_content_images( $content ) {
</ins><span class="cx">         preg_match_all( '/&lt;img[^&gt;]*&gt;/Ui', $content, $matches );
</span><span class="cx">         $content = preg_replace('/&lt;img[^&gt;]*&gt;/Ui', '', $content );
</span><span class="cx"> 
</span><span class="lines">@@ -717,13 +714,25 @@
</span><span class="cx">                 /* Get the SRC value */
</span><span class="cx">                 preg_match( '/&lt;img.*?(src\=[\'|&quot;]{0,1}.*?[\'|&quot;]{0,1})[\s|&gt;]{1}/i', $matches[0][0], $src );
</span><span class="cx"> 
</span><ins>+                /* Get the width and height */
+                preg_match( '/&lt;img.*?(height\=[\'|&quot;]{0,1}.*?[\'|&quot;]{0,1})[\s|&gt;]{1}/i', $matches[0][0], $height );
+                preg_match( '/&lt;img.*?(width\=[\'|&quot;]{0,1}.*?[\'|&quot;]{0,1})[\s|&gt;]{1}/i', $matches[0][0], $width );
+
</ins><span class="cx">                 if ( !empty( $src ) ) {
</span><span class="cx">                         $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
</span><del>-                        $pos = strpos( $content, '&lt;blockquote&gt;' );
-                        $before = substr( $content, 0, (int) $pos );
-                        $after = substr( $content, (int) $pos, strlen( $content ) );
</del><ins>+                        $height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
+                        $width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
</ins><span class="cx"> 
</span><del>-                        $content = $before . '&lt;img src=&quot;' . esc_attr( $src) . '&quot; width=&quot;100&quot; height=&quot;100&quot; alt=&quot;thumb&quot; class=&quot;align-left thumbnail&quot; /&gt;' . $after;
</del><ins>+                        if ( empty( $width ) || empty( $height ) ) {
+                                $width = 100;
+                                $height = 100;
+                        }
+
+                        $ratio = (int)$width / (int)$height;
+                        $new_height = 100;
+                        $new_width = $new_height * $ratio;
+
+                        $content = '&lt;img src=&quot;' . esc_attr( $src) . '&quot; width=&quot;' . $new_width . '&quot; height=&quot;' . $new_height . '&quot; alt=&quot;' . __( 'Thumbnail', 'buddypress' ) . '&quot; class=&quot;align-left thumbnail&quot; /&gt;' . $content;
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkbpblogsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-blogs.php (2382 => 2383)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-blogs.php        2010-01-20 16:43:39 UTC (rev 2382)
+++ trunk/bp-blogs.php        2010-01-20 17:43:49 UTC (rev 2383)
</span><span class="lines">@@ -259,6 +259,13 @@
</span><span class="cx">         $r = wp_parse_args( $args, $defaults );
</span><span class="cx">         extract( $r, EXTR_SKIP );
</span><span class="cx"> 
</span><ins>+        /* Remove large images and replace them with just one image thumbnail */
+         if ( function_exists( 'bp_activity_thumnail_content_images' ) &amp;&amp; !empty( $content ) )
+                $content = bp_activity_thumnail_content_images( $content );
+
+        $action = apply_filters( 'bp_blogs_record_activity_action', $action );
+        $content = apply_filters( 'bp_blogs_record_activity_content', &quot;&lt;blockquote&gt;&quot; . bp_create_excerpt( $content ) . &quot;&lt;/blockquote&gt;&quot; );
+
</ins><span class="cx">         return bp_activity_add( array( 'user_id' =&gt; $user_id, 'action' =&gt; $action, 'content' =&gt; $content, 'primary_link' =&gt; $primary_link, 'component' =&gt; $component, 'type' =&gt; $type, 'item_id' =&gt; $item_id, 'secondary_item_id' =&gt; $secondary_item_id, 'recorded_time' =&gt; $recorded_time, 'hide_sitewide' =&gt; $hide_sitewide ) );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -390,7 +397,7 @@
</span><span class="cx">                                 $post_permalink = bp_post_get_permalink( $post, $blog_id );
</span><span class="cx"> 
</span><span class="cx">                                 $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post-&gt;post_author ), '&lt;a href=&quot;' . $post_permalink . '&quot;&gt;' . $post-&gt;post_title . '&lt;/a&gt;' );
</span><del>-                                $activity_content = &quot;&lt;blockquote&gt;&quot; . bp_create_excerpt( $post-&gt;post_content ) . &quot;&lt;/blockquote&gt;&quot;;
</del><ins>+                                $activity_content = $post-&gt;post_content;
</ins><span class="cx"> 
</span><span class="cx">                                 bp_blogs_record_activity( array(
</span><span class="cx">                                         'user_id' =&gt; (int)$post-&gt;post_author,
</span><span class="lines">@@ -428,7 +435,7 @@
</span><span class="cx">                         $post_permalink = bp_post_get_permalink( $post, $blog_id );
</span><span class="cx"> 
</span><span class="cx">                         $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post-&gt;post_author ), '&lt;a href=&quot;' . $post_permalink . '&quot;&gt;' . $post-&gt;post_title . '&lt;/a&gt;' );
</span><del>-                        $activity_content = &quot;&lt;blockquote&gt;&quot; . bp_create_excerpt( $post-&gt;post_content ) . &quot;&lt;/blockquote&gt;&quot;;
</del><ins>+                        $activity_content = $post-&gt;post_content;
</ins><span class="cx"> 
</span><span class="cx">                         /* Record this in activity streams */
</span><span class="cx">                         bp_blogs_record_activity( array(
</span><span class="lines">@@ -486,7 +493,7 @@
</span><span class="cx">                 /* Record in activity streams */
</span><span class="cx">                 $comment_link = bp_post_get_permalink( $comment-&gt;post, $wpdb-&gt;blogid ) . '#comment-' . $comment_id;
</span><span class="cx">                 $activity_action = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '&lt;a href=&quot;' . $comment_link . '#comment-' . $comment-&gt;comment_ID . '&quot;&gt;' . $comment-&gt;post-&gt;post_title . '&lt;/a&gt;' );
</span><del>-                $activity_content = '&lt;blockquote&gt;' . bp_create_excerpt( $comment-&gt;comment_content ) . '&lt;/blockquote&gt;';
</del><ins>+                $activity_content = $comment-&gt;comment_content;
</ins><span class="cx"> 
</span><span class="cx">                 /* Record this in activity streams */
</span><span class="cx">                 bp_blogs_record_activity( array(
</span></span></pre></div>
<a id="trunkbpcorebpcoretemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-templatetags.php (2382 => 2383)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-templatetags.php        2010-01-20 16:43:39 UTC (rev 2382)
+++ trunk/bp-core/bp-core-templatetags.php        2010-01-20 17:43:49 UTC (rev 2383)
</span><span class="lines">@@ -1095,10 +1095,6 @@
</span><span class="cx"> 
</span><span class="cx">         return apply_filters( 'bp_create_excerpt', $text );
</span><span class="cx"> }
</span><del>-add_filter( 'bp_create_excerpt', 'wptexturize' );
-add_filter( 'bp_create_excerpt', 'convert_smilies' );
-add_filter( 'bp_create_excerpt', 'convert_chars' );
-add_filter( 'bp_create_excerpt', 'wpautop' );
</del><span class="cx"> add_filter( 'bp_create_excerpt', 'wp_trim_excerpt' );
</span><span class="cx"> add_filter( 'bp_create_excerpt', 'stripslashes_deep' );
</span><span class="cx"> add_filter( 'bp_create_excerpt', 'force_balance_tags' );
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_inccssdefaultcss"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/css/default.css (2382 => 2383)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/css/default.css        2010-01-20 16:43:39 UTC (rev 2382)
+++ trunk/bp-themes/bp-default/_inc/css/default.css        2010-01-20 17:43:49 UTC (rev 2383)
</span><span class="lines">@@ -1058,6 +1058,7 @@
</span><span class="cx">                 display: inline;
</span><span class="cx">                 padding: 0;
</span><span class="cx">                 margin: 0;
</span><ins>+                overflow: auto;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx"> .activity-list .activity-avatar img {
</span><span class="lines">@@ -1140,12 +1141,19 @@
</span><span class="cx">         .activity-list .activity-content .activity-inner,
</span><span class="cx">         .activity-list .activity-content blockquote {
</span><span class="cx">                 margin: 15px 0 15px 5px;
</span><ins>+                overflow: auto;
</ins><span class="cx">         }
</span><span class="cx">                 body.activity-permalink .activity-content .activity-inner,
</span><span class="cx">                 body.activity-permalink .activity-content blockquote {
</span><span class="cx">                         margin-top: 5px;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><ins>+        .activity-list .activity-content img.thumbnail {
+                float: left;
+                margin: 0 10px 5px 0;
+                border: 2px solid #eee;
+        }
+
</ins><span class="cx"> .activity-list li.load-more {
</span><span class="cx">         margin: 15px  0 !important;
</span><span class="cx">         padding: 10px 15px !important;
</span><span class="lines">@@ -1167,6 +1175,7 @@
</span><span class="cx"> 
</span><span class="cx"> div.activity-meta {
</span><span class="cx">         margin: 0 0 20px 3px;
</span><ins>+        clear: left;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> .activity-list div.activity-meta a {
</span></span></pre>
</div>
</div>

</body>
</html>