--- buddypress/bp-core/bp-core-classes.php	Mon Jul 11 18:48:26 2011
+++ buddypress/bp-core/bp-core-classes.php	Tue Jul 12 01:11:23 2011
@@ -1082,4 +1082,165 @@
 	}
 }
 
-?>
+/**
+ * BP_Embed
+ *
+ * Extends WP_Embed class for use with BuddyPress.
+ *
+ * @package BuddyPress Core
+ * @since 1.3
+ * @see WP_Embed
+ */
+class BP_Embed extends WP_Embed {
+
+	/**
+	 * PHP4 constructor
+	 */
+	function BP_Embed() {
+		return $this->__construct();
+	}
+
+	/**
+	 * PHP5 constructor
+	 */
+	function __construct() {
+		global $wp_embed;
+
+		// Make sure we populate the WP_Embed handlers array.
+		// These are providers that use a regex callback on the URL in question.
+		// Do not confuse with oEmbed providers, which require an external ping.
+		// Used in WP_Embed::shortcode()
+		$this->handlers = $wp_embed->handlers;
+
+		if( !defined( 'BP_EMBED_DISABLE_ACTIVITY' ) ) {
+			add_filter( 'bp_get_activity_content_body', 	array( &$this, 'autoembed' ), 8 );
+			add_filter( 'bp_get_activity_content_body', 	array( &$this, 'run_shortcode' ), 7 );
+		}
+
+		if( !defined( 'BP_EMBED_DISABLE_ACTIVITY_REPLIES' ) ) {
+			add_filter( 'bp_get_activity_content', 		array( &$this, 'autoembed' ), 8 );
+			add_filter( 'bp_get_activity_content', 		array( &$this, 'run_shortcode' ), 7 );
+		}
+
+		if( !defined( 'BP_EMBED_DISABLE_FORUM_POSTS' ) ) {
+			add_filter( 'bp_get_the_topic_post_content', 	array( &$this, 'autoembed' ), 8 );
+			add_filter( 'bp_get_the_topic_post_content', 	array( &$this, 'run_shortcode' ), 7 );
+		}
+	}
+
+	/**
+	 * The {@link do_shortcode()} callback function.
+	 *
+	 * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of the registered embed handlers.
+	 * Next, checks the URL against the regex of registered {@link WP_oEmbed} providers if oEmbed discovery is false.
+	 * If none of the regex matches and it's enabled, then the URL will be passed to {@link BP_Embed::parse_oembed()} for oEmbed parsing.
+	 *
+	 * @uses wp_parse_args()
+	 * @uses wp_embed_defaults()
+	 * @uses author_can()
+	 * @uses _wp_oembed_get_object()
+	 * @uses WP_Embed::maybe_make_link()
+	 *
+	 * @param array $attr Shortcode attributes.
+	 * @param string $url The URL attempting to be embeded.
+	 * @return string The embed HTML on success, otherwise the original URL.
+	 */
+	function shortcode( $attr, $url = '' ) {
+
+		if ( empty( $url ) )
+			return '';
+
+		$rawattr = $attr;
+		$attr = wp_parse_args( $attr, wp_embed_defaults() );
+
+		// kses converts & into &amp; and we need to undo this
+		// See http://core.trac.wordpress.org/ticket/11311
+		$url = str_replace( '&amp;', '&', $url );
+
+		// Look for known internal handlers
+		ksort( $this->handlers );
+		foreach ( $this->handlers as $priority => $handlers ) {
+			foreach ( $handlers as $id => $handler ) {
+				if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
+					if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
+						return apply_filters( 'embed_handler_html', $return, $url, $attr );
+				}
+			}
+		}
+
+		// Get object ID
+		$id = apply_filters( 'embed_post_id', $id );
+
+		// Is oEmbed discovery on?
+		$attr['discover'] = ( apply_filters( 'bp_embed_oembed_discover', false ) && current_user_can( 'unfiltered_html' ) );
+
+		// Set up a new WP oEmbed object to check URL with registered oEmbed providers
+		require_once( ABSPATH . WPINC . '/class-oembed.php' );
+		$oembed_obj = _wp_oembed_get_object();
+
+		// If oEmbed discovery is true, skip oEmbed provider check
+		$is_oembed_link = false;
+		if ( !$attr['discover'] ) {
+			foreach ( (array)$oembed_obj->providers as $provider_matchmask => $provider ) {
+				$regex = ( $is_regex = $provider[1] ) ? $provider_matchmask : '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $provider_matchmask ), '#' ) ) . '#i';
+
+				if ( preg_match( $regex, $url ) )
+					$is_oembed_link = true;
+			}
+
+			// If url doesn't match a WP oEmbed provider, stop parsing
+			if ( !$is_oembed_link )
+				return $this->maybe_make_link( $url );
+		}
+
+		return $this->parse_oembed( $id, $url, $attr, $rawattr );
+	}
+
+	/**
+	 * Base function so BP components / plugins can parse links to be embedded.
+	 * View an example to add support in {@link bp_activity_embed()}.
+	 *
+	 * @uses apply_filters() Filters cache.
+	 * @uses do_action() To save cache.
+	 * @uses wp_oembed_get() Connects to oEmbed provider and returns HTML on success.
+	 * @uses WP_Embed::maybe_make_link() Process URL for hyperlinking on oEmbed failure.
+	 * @param int $id ID to do the caching for.
+	 * @param string $url The URL attempting to be embedded.
+	 * @param array $attr Shortcode attributes from {@link WP_Embed::shortcode()}.
+	 * @param array $rawattr Untouched shortcode attributes from {@link WP_Embed::shortcode()}.
+	 * @return string The embed HTML on success, otherwise the original URL.
+	 */
+	function parse_oembed( $id, $url, $attr, $rawattr ) {
+
+		if ( $id ) {
+
+			// Setup the cachekey
+			$cachekey = '_oembed_' . md5( $url . serialize( $attr ) );
+
+			// Let components / plugins grab their cache
+			$cache = apply_filters( 'bp_embed_get_cache', $cache, $id, $cachekey, $url, $attr, $rawattr );
+
+			// Grab cache and return it if available
+			if ( !empty( $cache ) ) {
+				return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $rawattr );
+			}
+			// If no cache, ping the oEmbed provider and cache the result
+			else {
+				$html = wp_oembed_get( $url, $attr );
+				$cache = ( $html ) ? $html : $url;
+
+				// Let components / plugins save their cache
+				do_action( 'bp_embed_update_cache', $cache, $cachekey, $id );
+
+				// If there was a result, return it
+				if ( $html )
+					return apply_filters( 'bp_embed_oembed_html', $html, $url, $attr, $rawattr );
+			}
+		}
+
+		// Still unknown
+		return $this->maybe_make_link( $url );
+	}
+}
+
+?>
\ No newline at end of file
--- buddypress/bp-core/bp-core-functions.php	Mon Jul 11 18:48:54 2011
+++ buddypress/bp-core/bp-core-functions.php	Tue Jul 12 01:14:10 2011
@@ -18,7 +18,7 @@
  */
 function bp_get_option( $option_name, $default = '' ) {
 	$value = get_blog_option( bp_get_root_blog_id(), $option_name, $default );
-	
+
 	return apply_filters( 'bp_get_option', $value );
 }
 
@@ -78,9 +78,9 @@
  */
 function bp_core_get_page_meta() {
 	$page_ids = bp_get_option( 'bp-pages' );
-  
+
   	// Upgrading from an earlier version of BP pre-1.3
-	if ( !isset( $page_ids['members'] ) && $ms_page_ids = get_site_option( 'bp-pages' ) ) {  
+	if ( !isset( $page_ids['members'] ) && $ms_page_ids = get_site_option( 'bp-pages' ) ) {
 		$page_blog_id = bp_is_multiblog_mode() ? get_current_blog_id() : bp_get_root_blog_id();
 
 		if ( isset( $ms_page_ids[$page_blog_id] ) ) {
@@ -89,7 +89,7 @@
 			bp_update_option( 'bp-pages', $page_ids );
 		}
   	}
-  	
+
 	return apply_filters( 'bp_core_get_page_meta', $page_ids );
 }
 
@@ -681,12 +681,12 @@
  */
 function bp_core_record_activity() {
 	global $bp;
-	
+
 	if ( !is_user_logged_in() )
 		return false;
-	
+
 	$user_id = $bp->loggedin_user->id;
-	
+
 	if ( bp_core_is_user_spammer( $user_id ) || bp_core_is_user_deleted( $user_id ) )
 		return false;
 
@@ -897,6 +897,17 @@
 add_action( 'bp_init', 'bp_core_add_ajax_hook' );
 
 /**
+ * Initializes {@link BP_Embed} after everything is loaded.
+ *
+ * @package BuddyPress Core
+ * @since 1.3
+ */
+function bp_embed_init() {
+        $bp_embed = new BP_Embed();
+}
+add_action( 'bp_init', 'bp_embed_init' );
+
+/**
  * When switching from single to multisite we need to copy blog options to
  * site options.
  *
@@ -1058,7 +1069,7 @@
  * @return bool $is_root_blog Returns true if this is bp_get_root_blog_id().
  */
 function bp_is_root_blog( $blog_id = 0 ) {
-	
+
 	// Assume false
 	$is_root_blog = false;
 
@@ -1102,7 +1113,7 @@
 		}
 
 		define( 'BP_ROOT_BLOG', $root_blog_id );
-		
+
 	// Root blog is defined
 	} else {
 		$root_blog_id = BP_ROOT_BLOG;
@@ -1204,7 +1215,7 @@
  * @since 1.3
  *
  * @uses apply_filters() Filter 'bp_is_username_compatibility_mode' to alter
- * @return bool False when compatibility mode is disabled (default); true when enabled 
+ * @return bool False when compatibility mode is disabled (default); true when enabled
  */
 function bp_is_username_compatibility_mode() {
 	return apply_filters( 'bp_is_username_compatibility_mode', defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) && BP_ENABLE_USERNAME_COMPATIBILITY_MODE );
@@ -1215,7 +1226,7 @@
  *
  * Note that BP_ENABLE_MULTIBLOG is different from (but dependent on) WP Multisite. "Multiblog" is
  * a BP setup that allows BP content to be viewed in the theme, and with the URL, of every blog
- * on the network. Thus, instead of having all 'boonebgorges' links go to 
+ * on the network. Thus, instead of having all 'boonebgorges' links go to
  *   http://example.com/members/boonebgorges
  * on the root blog, each blog will have its own version of the same profile content, eg
  *   http://site2.example.com/members/boonebgorges (for subdomains)
@@ -1228,7 +1239,7 @@
  * @since 1.3
  *
  * @uses apply_filters() Filter 'bp_is_multiblog_mode' to alter
- * @return bool False when multiblog mode is disabled (default); true when enabled 
+ * @return bool False when multiblog mode is disabled (default); true when enabled
  */
 function bp_is_multiblog_mode() {
 	return apply_filters( 'bp_is_multiblog_mode', is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG );
@@ -1247,7 +1258,7 @@
  * @since 1.3
  *
  * @uses apply_filters() Filter 'bp_use_wp_admin_bar' to alter
- * @return bool False when WP Admin Bar support is disabled (default); true when enabled 
+ * @return bool False when WP Admin Bar support is disabled (default); true when enabled
  */
 function bp_use_wp_admin_bar() {
 	return apply_filters( 'bp_use_wp_admin_bar', defined( 'BP_USE_WP_ADMIN_BAR' ) && BP_USE_WP_ADMIN_BAR );
@@ -1316,8 +1327,8 @@
 
 	do_action( 'bp_do_404', $redirect );
 
-	$wp_query->set_404(); 
-	status_header( 404 ); 
+	$wp_query->set_404();
+	status_header( 404 );
 	nocache_headers();
 
 	if ( 'remove_canonical_direct' == $redirect )
--- buddypress/bp-activity/bp-activity-functions.php	Mon Jul 11 18:49:17 2011
+++ buddypress/bp-activity/bp-activity-functions.php	Tue Jul 12 01:17:34 2011
@@ -116,7 +116,7 @@
  * @param int $item_id The activity id
  * @param int $secondary_item_id In the case of at-mentions, this is the mentioner's id
  * @param int $total_items The total number of notifications to format
- * @param str $format 'string' to get a BuddyBar-compatible notification, 'array' otherwise 
+ * @param str $format 'string' to get a BuddyBar-compatible notification, 'array' otherwise
  */
 function bp_activity_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
 	global $bp;
@@ -138,7 +138,7 @@
 			}
 		break;
 	}
-				
+
 	if ( 'string' == $format ) {
 		$return = apply_filters( $filter, '<a href="' . $at_mention_link . '" title="' . $at_mention_title . '">' . $text . '</a>', $at_mention_link, (int)$total_items, $activity_id, $poster_user_id );
 	} else {
@@ -989,4 +989,45 @@
 	return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches );
 }
 
-?>
+/** Embeds *******************************************************************/
+
+/**
+ * Grabs the activity ID and attempts to retrieve the oEmbed cache (if it exists)
+ * during the activity loop.  If no cache and link is embeddable, cache it.
+ *
+ * @see BP_Embed
+ * @see bp_embed_activity_cache()
+ * @see bp_embed_activity_save_cache()
+ * @package BuddyPress Activity
+ * @since 1.3
+ */
+function bp_activity_embed() {
+	add_filter( 'embed_post_id',		'bp_get_activity_id' );
+	add_filter( 'bp_embed_get_cache',	'bp_embed_activity_cache', 10, 3 );
+	add_action( 'bp_embed_update_cache',	'bp_embed_activity_save_cache', 10, 3 );
+}
+add_action( 'activity_loop_start', 'bp_activity_embed' );
+
+	/**
+	 * Wrapper function for {@link bp_activity_get_meta()}.
+	 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
+	 *
+	 * @package BuddyPress Activity
+	 * @since 1.3
+	 */
+	function bp_embed_activity_cache( $cache, $id, $cachekey ) {
+		return bp_activity_get_meta( $id, $cachekey );
+	}
+
+	/**
+	 * Wrapper function for {@link bp_activity_update_meta()}.
+	 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
+	 *
+	 * @package BuddyPress Activity
+	 * @since 1.3
+	 */
+	function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
+		bp_activity_update_meta( $id, $cachekey, $cache );
+	}
+
+?>
\ No newline at end of file
--- buddypress/bp-forums/bp-forums-functions.php	Mon Jul 11 18:49:49 2011
+++ buddypress/bp-forums/bp-forums-functions.php	Tue Jul 12 01:19:04 2011
@@ -514,4 +514,46 @@
 add_action( 'bp_forums_new_topic', 'bp_core_clear_cache' );
 add_action( 'bp_forums_new_post',  'bp_core_clear_cache' );
 
-?>
+
+/** Embeds *******************************************************************/
+
+/**
+ * Grabs the topic post ID and attempts to retrieve the oEmbed cache (if it exists)
+ * during the forum topic loop.  If no cache and link is embeddable, cache it.
+ *
+ * @see BP_Embed
+ * @see bp_embed_forum_cache()
+ * @see bp_embed_forum_save_cache()
+ * @package BuddyPress_Forums
+ * @since 1.3
+ */
+function bp_forums_embed() {
+	add_filter( 'embed_post_id',		'bp_get_the_topic_post_id' );
+	add_filter( 'bp_embed_get_cache',	'bp_embed_forum_cache', 10, 3 );
+	add_action( 'bp_embed_update_cache',	'bp_embed_forum_save_cache', 10, 3 );
+}
+add_action( 'topic_loop_start', 'bp_forums_embed' );
+
+	/**
+	 * Wrapper function for {@link bb_get_postmeta()}.
+	 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_forums_embed()}.
+	 *
+	 * @package BuddyPress_Forums
+	 * @since 1.3
+	 */
+	function bp_embed_forum_cache( $cache, $id, $cachekey ) {
+		return bb_get_postmeta( $id, $cachekey );
+	}
+
+	/**
+	 * Wrapper function for {@link bb_update_postmeta()}.
+	 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_forums_embed()}.
+	 *
+	 * @package BuddyPress_Forums
+	 * @since 1.3
+	 */
+	function bp_embed_forum_save_cache( $cache, $cachekey, $id ) {
+		bb_update_postmeta( $id, $cachekey, $cache );
+	}
+
+?>
\ No newline at end of file
