<!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" />
<title>[BuddyPress][10838] trunk/src: Activity: Add Embeds support to single activity items.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/10838">10838</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/10838","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>r-a-y</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-05-31 07:29:30 +0000 (Tue, 31 May 2016)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Activity: Add Embeds support to single activity items.

Much like the Post Embeds feature introduced in WordPress 4.4, this commit
adds support for single activity URLs to be auto-discovered by oEmbed
consumers.

This allows activity URLs to be rendered into an embeddable format on
third-party websites.

Specifically, this commit:
- Introduces the `BP_Activity_oEmbed_Component` class, which hooks into WordPress' oEmbed provider API via the `BP_oEmbed_Component` class.
- Renders oEmbed requests for single activity items into a template suitable for embedding.
- Introduces embed template parts into bp-legacy - `/bp-templates/bp-legacy/buddypress/assets/embeds/`

See <a href="http://buddypress.trac.wordpress.org/ticket/6772">#6772</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpactivitybpactivityclassesphp">trunk/src/bp-activity/bp-activity-classes.php</a></li>
<li><a href="#trunksrcbpactivityclassesclassbpactivitycomponentphp">trunk/src/bp-activity/classes/class-bp-activity-component.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcbpactivitybpactivityembedsphp">trunk/src/bp-activity/bp-activity-embeds.php</a></li>
<li><a href="#trunksrcbpactivityclassesclassbpactivityoembedcomponentphp">trunk/src/bp-activity/classes/class-bp-activity-oembed-component.php</a></li>
<li>trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/</li>
<li><a href="#trunksrcbptemplatesbplegacybuddypressassetsembedsactivityphp">trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/activity.php</a></li>
<li><a href="#trunksrcbptemplatesbplegacybuddypressassetsembedscssactivityphp">trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/css-activity.php</a></li>
<li><a href="#trunksrcbptemplatesbplegacybuddypressassetsembedsfooterphp">trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/footer.php</a></li>
<li><a href="#trunksrcbptemplatesbplegacybuddypressassetsembedsheaderactivityphp">trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/header-activity.php</a></li>
<li><a href="#trunksrcbptemplatesbplegacybuddypressassetsembedsheaderphp">trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/header.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpactivitybpactivityclassesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/bp-activity-classes.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/bp-activity-classes.php     2016-05-31 07:11:36 UTC (rev 10837)
+++ trunk/src/bp-activity/bp-activity-classes.php       2016-05-31 07:29:30 UTC (rev 10838)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -13,3 +13,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require dirname( __FILE__ ) . '/classes/class-bp-activity-activity.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require dirname( __FILE__ ) . '/classes/class-bp-activity-feed.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require dirname( __FILE__ ) . '/classes/class-bp-activity-query.php';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+// Embeds - only applicable for WP 4.5+
+if ( bp_get_major_wp_version() >= 4.5 && bp_is_active( 'activity', 'embeds' ) ) {
+       require dirname( __FILE__ ) . '/classes/class-bp-activity-oembed-component.php';
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="trunksrcbpactivitybpactivityembedsphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/bp-activity/bp-activity-embeds.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/bp-activity-embeds.php                              (rev 0)
+++ trunk/src/bp-activity/bp-activity-embeds.php        2016-05-31 07:29:30 UTC (rev 10838)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,169 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Functions related to embedding single activity items externally.
+ *
+ * Relies on WordPress 4.5.
+ *
+ * @since 2.6.0
+ *
+ * @package BuddyPress
+ * @subpackage ActivityEmbeds
+ */
+
+// Exit if accessed directly.
+defined( 'ABSPATH' ) || exit;
+
+/**
+ * Loads our activity oEmbed component.
+ *
+ * @since 2.6.0
+ */
+function bp_activity_setup_oembed() {
+       if ( bp_get_major_wp_version() >= 4.5 && bp_is_active( 'activity', 'embeds' ) ) {
+               buddypress()->activity->oembed = new BP_Activity_oEmbed_Component;
+       }
+
+       add_filter( 'bp_activity_get_embed_excerpt', 'wptexturize' );
+       add_filter( 'bp_activity_get_embed_excerpt', 'convert_chars' );
+       add_filter( 'bp_activity_get_embed_excerpt', 'make_clickable', 9 );
+       add_filter( 'bp_activity_get_embed_excerpt', 'bp_activity_embed_excerpt_onclick_location_filter' );
+       add_filter( 'bp_activity_get_embed_excerpt', 'bp_activity_at_name_filter' );
+       add_filter( 'bp_activity_get_embed_excerpt', 'convert_smilies', 20 );
+       add_filter( 'bp_activity_get_embed_excerpt', 'wpautop', 30 );
+}
+add_action( 'bp_loaded', 'bp_activity_setup_oembed' );
+
+/**
+ * Catch links in embed excerpt so top.location.href can be added.
+ *
+ * Due to <iframe sandbox="allow-top-navigation">, links in embeds can only be
+ * clicked if invoked with top.location.href via JS.
+ *
+ * @since 2.6.0
+ *
+ * @param  string $text Embed excerpt
+ * @return string
+ */
+function bp_activity_embed_excerpt_onclick_location_filter( $text ) {
+       return preg_replace_callback( '/<a href=\"([^\"]*)\"/iU', 'bp_activity_embed_excerpt_onclick_location_filter_callback', $text );
+}
+       /**
+        * Add onclick="top.location.href" to a link.
+        *
+        * @since 2.6.0
+        *
+        * @param  array $matches Items matched by bp_activity_embed_excerpt_onclick_location_filter().
+        * @return string
+        */
+       function bp_activity_embed_excerpt_onclick_location_filter_callback( $matches ) {
+               return sprintf( '<a href="%1$s" onclick="top.location.href=\'%1$s\'"', $matches[1] );
+       }
+
+/**
+ * Add inline styles for BP activity embeds.
+ *
+ * This is subject to change or be removed entirely for a different system.
+ * Potentially for BP_Legacy::locate_asset_in_stack().
+ *
+ * @since  2.6.0
+ * @access private
+ */
+function _bp_activity_embed_add_inline_styles() {
+       if ( false === bp_is_single_activity() ) {
+               return;
+       }
+
+       ob_start();
+       if ( is_rtl() ) {
+               bp_get_asset_template_part( 'embeds/css-activity', 'rtl' );
+       } else {
+               bp_get_asset_template_part( 'embeds/css-activity' );
+       }
+       $css = ob_get_clean();
+
+       // Rudimentary CSS protection.
+       $css = wp_kses( $css, array( "\'", '\"' ) );
+
+       printf( '<style type="text/css">%s</style>', $css );
+}
+add_action( 'embed_head', '_bp_activity_embed_add_inline_styles', 20 );
+
+/**
+ * Query for the activity item on the activity embed template.
+ *
+ * Basically a wrapper for {@link bp_has_activities()}, but allows us to
+ * use the activity loop without requerying for it again.
+ *
+ * @since 2.6.0
+ *
+ * @param  int $activity_id The activity ID.
+ * @return bool
+ */
+function bp_activity_embed_has_activity( $activity_id = 0 ) {
+       global $activities_template;
+
+       if ( empty( $activity_id ) ) {
+               return false;
+       }
+
+       if ( ! empty( $activities_template->activities ) ) {
+               $activity = (array) $activities_template->activities;
+               $activity = reset( $activity );
+
+               // No need to requery if we already got the embed activity
+               if ( (int) $activity_id === (int) $activity->id ) {
+                       return $activities_template->has_activities();
+               }
+       }
+
+       return bp_has_activities( array(
+               'display_comments' => 'threaded',
+               'show_hidden'      => true,
+               'include'          => (int) $activity_id,
+       ) );
+}
+
+/**
+ * Outputs excerpt for an activity embed item.
+ *
+ * @since 2.6.0
+ */
+function bp_activity_embed_excerpt( $content = '' ) {
+       echo bp_activity_get_embed_excerpt( $content = '' );
+}
+
+       /**
+        * Generates excerpt for an activity embed item.
+        *
+        * @since 2.6.0
+        *
+        * @param  string $content The content to generate an excerpt for.
+        * @return string
+        */
+       function bp_activity_get_embed_excerpt( $content = '' ) {
+               if ( empty( $content ) && ! empty( $GLOBALS['activities_template']->in_the_loop ) ) {
+                       $content = $GLOBALS['activities_template']->activity->content;
+               }
+
+               /**
+                * bp_activity_truncate_entry() includes the 'Read More' link, which is why
+                * we're using this instead of bp_create_excerpt().
+                */
+               $content = html_entity_decode( $content );
+               $content = bp_activity_truncate_entry( $content, array(
+                       'html' => false,
+                       'filter_shortcodes' => true,
+                       'strip_tags'        => true,
+                       'force_truncate'    => true
+               ) );
+
+               /**
+                * Filter the activity embed excerpt.
+                *
+                * @since 2.6.0
+                *
+                * @var string $content Embed Excerpt.
+                * @var string $unmodified_content Unmodified activity content.
+                */
+               return apply_filters( 'bp_activity_get_embed_excerpt', $content, $GLOBALS['activities_template']->activity->content );
+       }
</ins></span></pre></div>
<a id="trunksrcbpactivityclassesclassbpactivitycomponentphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/classes/class-bp-activity-component.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/classes/class-bp-activity-component.php     2016-05-31 07:11:36 UTC (rev 10837)
+++ trunk/src/bp-activity/classes/class-bp-activity-component.php       2016-05-31 07:29:30 UTC (rev 10838)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -32,6 +32,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'adminbar_myaccount_order' => 10,
</span><span class="cx" style="display: block; padding: 0 10px">                                'search_query_arg' => 'activity_search',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'features' => array( 'embeds' )
</ins><span class="cx" style="display: block; padding: 0 10px">                         )
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -72,6 +73,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $includes[] = 'akismet';
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Embeds - only applicable for WP 4.5+
+               if ( bp_get_major_wp_version() >= 4.5 && bp_is_active( $this->id, 'embeds' ) ) {
+                       $includes[] = 'embeds';
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( is_admin() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $includes[] = 'admin';
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span></span></pre></div>
<a id="trunksrcbpactivityclassesclassbpactivityoembedcomponentphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/bp-activity/classes/class-bp-activity-oembed-component.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/classes/class-bp-activity-oembed-component.php                              (rev 0)
+++ trunk/src/bp-activity/classes/class-bp-activity-oembed-component.php        2016-05-31 07:29:30 UTC (rev 10838)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,329 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * BuddyPress Activity Classes.
+ *
+ * @package BuddyPress
+ * @subpackage Embeds
+ */
+
+// Exit if accessed directly.
+defined( 'ABSPATH' ) || exit;
+
+require_once( buddypress()->plugin_dir . '/bp-core/classes/class-bp-oembed-component.php' );
+
+/**
+ * oEmbed handler to respond and render single activity items.
+ *
+ * @since 2.6.0
+ */
+class BP_Activity_oEmbed_Component extends BP_oEmbed_Component {
+       /**
+        * Custom oEmbed slug endpoint.
+        *
+        * @since 2.6.0
+        *
+        * @var string
+        */
+       public $slug_endpoint = 'activity';
+
+       /**
+        * Custom hooks.
+        *
+        * @since 2.6.0
+        */
+       protected function custom_hooks() {
+               add_action( 'oembed_dataparse',   array( $this, 'use_custom_iframe_sandbox_attribute' ), 20, 3 );
+               add_action( 'embed_content_meta', array( $this, 'embed_comments_button' ), 5 );
+               add_action( 'get_template_part_assets/embeds/header', array( $this, 'on_activity_header' ), 10, 2 );
+
+               add_filter( 'bp_activity_embed_html', array( $this, 'modify_iframe' ) );
+       }
+
+       /**
+        * Add custom endpoint arguments.
+        *
+        * Currently, includes 'hide_media'.
+        *
+        * @since 2.6.0
+        *
+        * @return array
+        */
+       protected function set_route_args() {
+               return array(
+                       'hide_media' => array(
+                               'default' => false,
+                               'sanitize_callback' => 'wp_validate_boolean'
+                       )
+               );
+       }
+
+       /**
+        * Output our custom embed template part.
+        *
+        * @since 2.6.0
+        */
+       protected function content() {
+               bp_get_asset_template_part( 'embeds/activity' );
+       }
+
+       /**
+        * Check if we're on our single activity page.
+        *
+        * @since 2.6.0
+        *
+        * @return bool
+        */
+       protected function is_page() {
+               return bp_is_single_activity();
+       }
+
+       /**
+        * Validates the URL to determine if the activity item is valid.
+        *
+        * @since 2.6.0
+        *
+        * @param  string   $url The URL to check.
+        * @return int|bool Activity ID on success; boolean false on failure.
+        */
+       protected function validate_url_to_item_id( $url ) {
+               if ( bp_core_enable_root_profiles() ) {
+                       $domain = bp_get_root_domain();
+               } else {
+                       $domain = bp_get_members_directory_permalink();
+               }
+
+               // Check the URL to see if this is a single activity URL.
+               if ( 0 !== strpos( $url, $domain ) ) {
+                       return false;
+               }
+
+               // Check for activity slug.
+               if ( false === strpos( $url, '/' . bp_get_activity_slug() . '/' ) ) {
+                       return false;
+               }
+
+               // Do more checks.
+               $url = trim( untrailingslashit( $url ) );
+
+               // Grab the activity ID.
+               $activity_id = (int) substr(
+                       $url,
+                       strrpos( $url, '/' ) + 1
+               );
+
+               if ( ! empty( $activity_id ) ) {
+                       // Check if activity item still exists.
+                       $activity = new BP_Activity_Activity( $activity_id );
+
+                       // Okay, we're good to go!
+                       if ( ! empty( $activity->component ) && 0 === (int) $activity->is_spam ) {
+                               return $activity_id;
+                       }
+               }
+
+               return false;
+       }
+
+       /**
+        * Sets the oEmbed response data for our activity item.
+        *
+        * @since 2.6.0
+        *
+        * @param  int $item_id The activity ID.
+        * @return array
+        */
+       protected function set_oembed_response_data( $item_id ) {
+               $activity = new BP_Activity_Activity( $item_id );
+
+               return array(
+                       'content'      => $activity->content,
+                       'title'        => __( 'Activity', 'buddypress' ),
+                       'author_name'  => bp_core_get_user_displayname( $activity->user_id ),
+                       'author_url'   => bp_core_get_user_domain( $activity->user_id ),
+
+                       // Custom identifier.
+                       'x_buddypress' => 'activity'
+               );
+       }
+
+       /**
+        * Sets a custom <blockquote> for our oEmbed fallback HTML.
+        *
+        * @since 2.6.0
+        *
+        * @param  int $item_id The activity ID.
+        * @return string
+        */
+       protected function set_fallback_html( $item_id ) {
+               $activity    = new BP_Activity_Activity( $item_id );
+               $mentionname = bp_activity_do_mentions() ? ' (@' . bp_activity_get_user_mentionname( $activity->user_id ) . ')' : '';
+               $date        = date_i18n( get_option( 'date_format' ), strtotime( $activity->date_recorded ) );
+
+               // Make sure we can use some activity functions that depend on the loop.
+               $GLOBALS['activities_template'] = new stdClass;
+               $GLOBALS['activities_template']->activity = $activity;
+
+               // 'wp-embedded-content' CSS class is necessary due to how the embed JS works.
+               $blockquote = sprintf( '<blockquote class="wp-embedded-content bp-activity-item">%1$s%2$s %3$s</blockquote>',
+                       bp_activity_get_embed_excerpt( $activity->content ),
+                       '- ' . bp_core_get_user_displayname( $activity->user_id ) . $mentionname,
+                       '<a href="' . esc_url( bp_activity_get_permalink( $item_id ) ) . '">' . $date . '</a>'
+               );
+
+               // Clean up.
+               unset( $GLOBALS['activities_template'] );
+
+               /**
+                * Filters the fallback HTML used when embedding a BP activity item.
+                *
+                * @since 2.6.0
+                *
+                * @param string               $blockquote Current fallback HTML
+                * @param BP_Activity_Activity $activity   Activity object
+                */
+               return apply_filters( 'bp_activity_embed_fallback_html', $blockquote, $activity );
+       }
+
+       /**
+        * Sets a custom <iframe> title for our oEmbed item.
+        *
+        * @since 2.6.0
+        *
+        * @param  int $item_id The activity ID
+        * @return string
+        */
+       protected function set_iframe_title( $item_id ) {
+               return __( 'Embedded Activity Item', 'buddypress' );
+       }
+
+       /**
+        * Use our custom <iframe> sandbox attribute in our oEmbed response.
+        *
+        * WordPress sets the <iframe> sandbox attribute to 'allow-scripts' regardless
+        * of whatever the oEmbed response is in {@link wp_filter_oembed_result()}. We
+        * need to add back our custom sandbox value so links will work.
+        *
+        * @since 2.6.0
+        *
+        * @see BP_Activity_Component::modify_iframe() where our custom sandbox value is set.
+        *
+        * @param string $result The oEmbed HTML result.
+        * @param object $data   A data object result from an oEmbed provider.
+        * @param string $url    The URL of the content to be embedded.
+        * @return string
+        */
+       public function use_custom_iframe_sandbox_attribute( $result, $data, $url ) {
+               // Make sure we are on a BuddyPress activity oEmbed request.
+               if ( false === isset( $data->x_buddypress ) || 'activity' !== $data->x_buddypress ) {
+                       return $result;
+               }
+
+               // Get unfiltered sandbox attribute from our own oEmbed response.
+               $sandbox_pos = strpos( $data->html, 'sandbox=' ) + 9;
+               $sandbox = substr( $data->html, $sandbox_pos, strpos( $data->html, '"', $sandbox_pos ) - $sandbox_pos );
+
+               // Replace only if our sandbox attribute contains 'allow-top-navigation'.
+               if ( false !== strpos( $sandbox, 'allow-top-navigation' ) ) {
+                       $result = str_replace( ' sandbox="allow-scripts"', " sandbox=\"{$sandbox}\"", $result );
+
+                       // Also remove 'security' attribute; this is only used for IE < 10.
+                       $result = str_replace( 'security="restricted"', "", $result );
+               }
+
+               return $result;
+       }
+
+       /**
+        * Modify various IFRAME-related items if embeds are allowed.
+        *
+        * HTML modified:
+        *  - Add sandbox="allow-top-navigation" attribute. This allows links to work
+        *    within the iframe sandbox attribute.
+        *
+        * JS modified:
+        *  - Remove IFRAME height restriction of 1000px. Fixes long embed items being
+        *    truncated.
+        *
+        * @since 2.6.0
+        *
+        * @param  string $retval Current embed HTML.
+        * @return string
+        */
+       public function modify_iframe( $retval ) {
+               // Add 'allow-top-navigation' to allow links to be clicked.
+               $retval = str_replace( 'sandbox="', 'sandbox="allow-top-navigation ', $retval );
+
+               // See /wp-includes/js/wp-embed.js.
+               if ( SCRIPT_DEBUG ) {
+                       // Removes WP's hardcoded IFRAME height restriction.
+                       $retval = str_replace( 'height = 1000;', 'height = height;', $retval );
+
+               // This is for the WP build minified version.
+               } else {
+                       $retval = str_replace( 'g=1e3', 'g=g', $retval );
+               }
+
+               return $retval;
+       }
+
+       /**
+        * Do stuff when our oEmbed activity header template part is loading.
+        *
+        * Currently, removes wpautop() from the bp_activity_action() function.
+        *
+        * @since 2.6.0
+        *
+        * @param string $slug Template part slug requested.
+        * @param string $name Template part name requested.
+        */
+       public function on_activity_header( $slug, $name ) {
+               if ( false === $this->is_page() || 'activity' !== $name ) {
+                       return;
+               }
+
+               remove_filter( 'bp_get_activity_action', 'wpautop' );
+       }
+
+       /**
+        * Prints the markup for the activity embed comments button.
+        *
+        * Basically a copy of {@link print_embed_comments_button()}, but modified for
+        * the BP activity component.
+        *
+        * @since 2.6.0
+        */
+       public function embed_comments_button() {
+               if ( ! did_action( 'bp_embed_content' ) || ! bp_is_single_activity() ) {
+                       return;
+               }
+
+               // Make sure our custom permalink shows up in the 'WordPress Embed' block.
+               add_filter( 'the_permalink', array( $this, 'filter_embed_url' ) );
+
+               // Only show comment bubble if we have some activity comments.
+               $count = bp_activity_get_comment_count();
+               if ( empty( $count ) ) {
+                       return;
+               }
+       ?>
+
+               <div class="wp-embed-comments">
+                       <a href="<?php bp_activity_thread_permalink(); ?>">
+                               <span class="dashicons dashicons-admin-comments"></span>
+                               <?php
+                               printf(
+                                       _n(
+                                               '%s <span class="screen-reader-text">Comment</span>',
+                                               '%s <span class="screen-reader-text">Comments</span>',
+                                               $count,
+                                               'buddypress'
+                                       ),
+                                       number_format_i18n( $count )
+                               );
+                               ?>
+                       </a>
+               </div>
+
+       <?php
+       }
+}
</ins></span></pre></div>
<a id="trunksrcbptemplatesbplegacybuddypressassetsembedsactivityphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/activity.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/activity.php                            (rev 0)
+++ trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/activity.php      2016-05-31 07:29:30 UTC (rev 10838)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,9 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               <?php if ( bp_activity_embed_has_activity( bp_current_action() ) ) : ?>
+
+                       <?php while ( bp_activities() ) : bp_the_activity(); ?>
+                               <div class="bp-embed-excerpt"><?php bp_activity_embed_excerpt(); ?></div>
+                       <?php endwhile; ?>
+
+               <?php endif; ?>
+
</ins></span></pre></div>
<a id="trunksrcbptemplatesbplegacybuddypressassetsembedscssactivityphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/css-activity.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/css-activity.php                                (rev 0)
+++ trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/css-activity.php  2016-05-31 07:29:30 UTC (rev 10838)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,56 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+#bp-embed-header:after {
+       clear: both;
+       content: "";
+       display: table;
+       margin-bottom: 1em;
+}
+
+.bp-embed-avatar {
+       float: left;
+       margin: 0 .75em 0 0;
+}
+
+p.bp-embed-activity-action {
+       font-size: 15px;
+       margin-bottom: 0;
+}
+
+p.bp-embed-activity-action a:first-child {
+       color: #32373c;
+       font-weight: bold;
+}
+
+p.bp-embed-activity-action img.avatar {
+       padding: 0 4px 0 3px;
+       vertical-align: text-bottom;
+}
+
+.bp-embed-excerpt {
+       margin-bottom: 1em;
+}
+
+.bp-embed-excerpt a {
+       color: #21759b;
+       display: inline-block;
+       overflow: hidden;
+       text-overflow: ellipsis;
+       vertical-align: top;
+       white-space: nowrap;
+       max-width: 250px;
+}
+
+.activity-read-more {
+       margin-left: .5em;
+}
+
+.activity-read-more a {
+       color: #b4b9be;
+}
+
+.wp-embed-footer {
+       margin-top: 20px;
+}
+
+span.bp-embed-timestamp {
+       font-size: .9em;
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="trunksrcbptemplatesbplegacybuddypressassetsembedsfooterphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/footer.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/footer.php                              (rev 0)
+++ trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/footer.php        2016-05-31 07:29:30 UTC (rev 10838)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,9 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        <div class="wp-embed-footer">
+                               <?php the_embed_site_title() ?>
+
+                               <div class="wp-embed-meta">
+                                       <?php
+                                       /** This action is documented in wp-includes/theme-compat/embed-content.php */
+                                       do_action( 'embed_content_meta'); ?>
+                               </div>
+                       </div>
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="trunksrcbptemplatesbplegacybuddypressassetsembedsheaderactivityphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/header-activity.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/header-activity.php                             (rev 0)
+++ trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/header-activity.php       2016-05-31 07:29:30 UTC (rev 10838)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,26 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               <div id="bp-embed-header">
+                       <div class="bp-embed-avatar">
+                               <a href="<?php bp_displayed_user_link(); ?>">
+                                       <?php bp_displayed_user_avatar( 'type=thumb&width=45&height=45' ); ?>
+                               </a>
+                       </div>
+
+                       <?php if ( bp_activity_embed_has_activity( bp_current_action() ) ) : ?>
+
+                               <?php while ( bp_activities() ) : bp_the_activity(); ?>
+                                       <p class="bp-embed-activity-action">
+                                               <?php bp_activity_action( array( 'no_timestamp' => true ) ); ?>
+                                       </p>
+                               <?php endwhile; ?>
+
+                       <?php endif; ?>
+
+                       <p class="bp-embed-header-meta">
+                               <?php if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) : ?>
+                                       <span class="bp-embed-mentionname">@<?php bp_displayed_user_mentionname(); ?> &middot; </span>
+                               <?php endif; ?>
+
+                               <span class="bp-embed-timestamp"><a href="<?php bp_activity_thread_permalink(); ?>"><?php echo date_i18n( get_option( 'time_format' ) . ' - ' . get_option( 'date_format' ), strtotime( bp_get_activity_date_recorded() ) ); ?></a></span>
+                       </p>
+               </div>
</ins></span></pre></div>
<a id="trunksrcbptemplatesbplegacybuddypressassetsembedsheaderphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/header.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/header.php                              (rev 0)
+++ trunk/src/bp-templates/bp-legacy/buddypress/assets/embeds/header.php        2016-05-31 07:29:30 UTC (rev 10838)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,18 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               <div id="bp-embed-header">
+                       <div class="bp-embed-avatar">
+                               <a href="<?php bp_displayed_user_link(); ?>">
+                                       <?php bp_displayed_user_avatar( 'type=thumb&width=36&height=36' ); ?>
+                               </a>
+                       </div>
+
+                       <p class="wp-embed-heading">
+                               <a href="<?php bp_displayed_user_link(); ?>">
+                                       <?php bp_displayed_user_fullname(); ?>
+                               </a>
+                       </p>
+
+                       <?php if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) : ?>
+                               <p class="bp-embed-mentionname">@<?php bp_displayed_user_mentionname(); ?></p>
+                       <?php endif; ?>
+               </div>
</ins></span></pre>
</div>
</div>

</body>
</html>