Ticket #6772: 6772.07.suggestions.patch
File 6772.07.suggestions.patch, 13.0 KB (added by , 8 years ago) |
---|
-
src/bp-activity/bp-activity-embeds.php
diff --git src/bp-activity/bp-activity-embeds.php src/bp-activity/bp-activity-embeds.php index 220aa28..57396b8 100644
function bp_activity_setup_oembed() { 33 33 add_action( 'bp_loaded', 'bp_activity_setup_oembed' ); 34 34 35 35 /** 36 * Add inline styles for BP activity embeds.36 * Enqueue styles for embeds 37 37 * 38 38 * This is subject to change or be removed entirely for a different system. 39 39 * See PHPDoc for BP_Legacy::locate_asset_in_stack(). … … add_action( 'bp_loaded', 'bp_activity_setup_oembed' ); 41 41 * @since 2.6.0 42 42 * @access private 43 43 */ 44 function _bp_activity_embed_add_inline_styles() { 45 $inline_css = <<<EOD 46 47 #wp-embed-header:after { 48 clear: both; 49 content: ""; 50 display: table; 51 margin-bottom: 1em; 52 } 44 function bp_activity_embed_register_styles() { 45 $min = bp_core_get_minified_asset_suffix(); 46 $url = buddypress()->plugin_url . 'bp-activity/css/'; 53 47 54 .wp-embed-avatar { 55 float: left; 56 margin: 0 .75em 0 0; 57 } 48 /** 49 * Filters the BuddyPress Embed stylesheet files to register. 50 * 51 * @since 2.6.0 52 * 53 * @param array $value Array of stylesheet file information to register. 54 */ 55 $styles = apply_filters( 'bp_activity_embed_register_styles', array( 56 'bp-activity-embed' => array( 57 'file' => "{$url}embed{$min}.css", 58 'dependencies' => array(), 59 'has_rtl' => true, 60 'version' => bp_get_version(), 61 ), 62 ) ); 63 64 foreach ( $styles as $id => $style ) { 65 wp_register_style( $id, $style['file'], $style['dependencies'], $style['version'] ); 66 67 if ( ! empty( $style['has_rtl'] ) ) { 68 wp_style_add_data( $id, 'rtl', true ); 69 } 58 70 59 p.wp-embed-heading { 60 font-size: 16px; 61 margin-bottom: 0; 71 if ( $min ) { 72 wp_style_add_data( $id, 'suffix', $min ); 73 } 74 } 62 75 } 76 add_action( 'bp_enqueue_embed_scripts', 'bp_activity_embed_register_styles', 1 ); 63 77 64 .wp-embed-excerpt, p.wp-embed-timestamp{65 margin-bottom: .5em;78 function bp_activity_embed_enqueue_styles() { 79 wp_enqueue_style( 'bp-activity-embed' ); 66 80 } 81 add_action( 'bp_enqueue_embed_scripts', 'bp_activity_embed_enqueue_styles', 10 ); 67 82 68 .wp-embed-excerpt a { 69 color: #21759b; 70 display: inline-block; 71 overflow: hidden; 72 text-overflow: ellipsis; 73 vertical-align: top; 74 white-space: nowrap; 75 max-width: 250px; 76 } 83 function bp_activity_embed_avatar() { 84 $embed_avatar_args = apply_filters( 'bp_activity_embed_avatar', array( 85 'type' => 'thumb', 86 ) ); 77 87 78 .bp-activity-embed-display-media { 79 height: auto; 80 max-width: 550px; 88 return bp_activity_avatar( $embed_avatar_args ); 81 89 } 82 90 83 .bp-activity-embed-display-media img { 84 height: auto; 85 max-width: 100%; 91 function bp_activity_embed_heading() { 92 echo bp_activity_embed_get_heading(); 86 93 } 87 94 88 .activity-read-more { 89 margin-left: .5em; 90 } 95 function bp_activity_embed_get_heading() { 96 remove_filter( 'bp_get_activity_action', 'wpautop' ); 97 98 $heading = bp_get_activity_action( array( 'no_timestamp' => true ) ); 99 100 add_filter( 'bp_get_activity_action', 'wpautop' ); 101 102 return apply_filters( 'bp_activity_embed_get_heading', $heading ); 103 } 91 104 92 .activity-read-more a { 93 color: #b4b9be; 105 function bp_activity_embed_get_url_data( $url = '', $activity_id = 0 ) { 106 if ( empty( $url ) ) { 107 return false; 108 } 109 110 $meta = bp_activity_get_meta( $activity_id, 'oembed_image' ); 111 if ( ! empty( $meta[ $url ] ) ) { 112 return $meta[ $url ]; 113 } 114 115 if ( ! class_exists( 'WP_Press_This' ) ) { 116 require( ABSPATH . 'wp-admin/includes/class-wp-press-this.php' ); 117 } 118 119 $page = new WP_Press_This; 120 121 $data = $page->source_data_fetch_fallback( $url ); 122 $images = $page->get_images( $data ); 123 124 // Take the first 125 $image = reset( $images ); 126 127 if ( empty( $image ) ) { 128 return false; 129 } 130 131 // Save a meta to avoid requesting the url at each load. 132 bp_activity_update_meta( $activity_id, 'oembed_image', array( $url => $image ) ); 133 return $image; 94 134 } 95 135 96 .wp-embed-footer{97 margin-top: 20px;136 function bp_activity_embed_rich_content() { 137 echo bp_activity_embed_get_rich_content(); 98 138 } 99 139 100 EOD; 140 function bp_activity_embed_get_rich_content() { 141 // Bail if oEmbed request explicitly hides media. 142 if ( isset( $_REQUEST['hide_media'] ) && true == wp_validate_boolean( $_REQUEST['hide_media'] ) ) { 143 return; 144 } 101 145 102 // Piggyback off of 'open-sans' handle so we can use our inline CSS. 103 wp_add_inline_style( 'open-sans', $inline_css ); 104 } 105 add_action( 'bp_enqueue_embed_scripts', '_bp_activity_embed_add_inline_styles' ); 146 $activity = false; 147 148 if ( isset( $GLOBALS['activities_template']->activity ) ) { 149 $activity = $GLOBALS['activities_template']->activity; 150 } 151 152 // Find all embeds for the activity item. 153 $media = (array) bp_core_extract_media_from_content( $activity->content ); 154 $media_key = key( $media ); 155 $media_data = reset( $media[ $media_key ] ); 156 157 if ( ! is_null( $media_key ) ) { 158 if ( 'embeds' === $media_key ) { 159 $image = bp_activity_embed_get_url_data( $media_data['url'], $activity->id ); 160 } elseif ( 'images' === $media_key ) { 161 $image = $media_data['url']; 162 } 163 } 164 165 return apply_filters( 'bp_activity_embed_get_rich_content', sprintf( '<div class="wp-embed-featured-image rectangular"><a href="%1$s"><img src="%2$s"></a></div>', 166 esc_url( bp_activity_get_permalink( $activity->id, $activity ) ), 167 esc_attr( $image ) 168 ), $activity, $media ); 169 } 106 170 107 171 /** 108 172 * Outputs excerpt for an activity embed item. … … function bp_activity_embed_excerpt( $content = '' ) { 124 188 function bp_activity_get_embed_excerpt( $content = '' ) { 125 189 if ( empty( $content ) && ! empty( $GLOBALS['activities_template']->in_the_loop ) ) { 126 190 $content = $GLOBALS['activities_template']->activity->content; 127 128 // No content, so use action value.129 if ( empty( $content ) ) {130 $action = bp_activity_get_action( bp_get_activity_object_name(), bp_get_activity_type() );131 $content = false !== $action ? $action['value'] : '';132 }133 191 } 134 192 135 193 /** … … function bp_activity_embed_excerpt( $content = '' ) { 154 212 */ 155 213 return apply_filters( 'bp_activity_get_embed_excerpt', $content, $GLOBALS['activities_template']->activity->content ); 156 214 } 157 158 /**159 * Outputs the first embedded item in the activity oEmbed template.160 *161 * @since 2.6.0162 */163 function bp_activity_embed_response_display_media() {164 // Bail if oEmbed request explicitly hides media.165 if ( isset( $_REQUEST['hide_media'] ) && true == wp_validate_boolean( $_REQUEST['hide_media'] ) ) {166 return;167 }168 169 // Find all embeds for the activity item.170 $embeds = bp_core_extract_media_from_content( $GLOBALS['activities_template']->activity->content, 'embeds' );171 172 /**173 * Should we display media in the oEmbed template?174 *175 * @since 2.6.0176 *177 * @param bool $retval Defaults to true.178 */179 $allow_embeds = apply_filters( 'bp_activity_embed_display_media', true );180 181 // Only embed the first embedded item.182 if ( $embeds && $allow_embeds ) {183 // Call BP_Embed if it hasn't already loaded.184 bp_embed_init();185 186 // Autoembed first URL.187 $content = buddypress()->embed->autoembed( $embeds['embeds'][0]['url'] );188 189 // Wrap content around a custom DIV.190 echo '<div class="bp-activity-embed-display-media">' . $content . '</div>';191 192 // Add fluidvids.js for responsive IFRAMEs / OBJECTs.193 if ( false !== strpos( $content, '<iframe' ) || false !== strpos( $content, '<object' ) ) {194 ?>195 196 <script>197 /*! fluidvids.js v2.4.1 | (c) 2014 @toddmotto | License: MIT | https://github.com/toddmotto/fluidvids */198 !function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t:e.fluidvids=t()}(this,function(){"use strict";function e(e){return new RegExp("^(https?:)?//(?:"+d.players.join("|")+").*$","i").test(e)}function t(e,t){return parseInt(e,10)/parseInt(t,10)*100+"%"}function i(i){if((e(i.src)||e(i.data))&&!i.getAttribute("data-fluidvids")){var n=document.createElement("div");i.parentNode.insertBefore(n,i),i.className+=(i.className?" ":"")+"fluidvids-item",i.setAttribute("data-fluidvids","loaded"),n.className+="fluidvids",n.style.paddingTop=t(i.height,i.width),n.appendChild(i)}}function n(){var e=document.createElement("div");e.innerHTML="<p>x</p><style>"+o+"</style>",r.appendChild(e.childNodes[1])}var d={selector:["iframe","object"],players:["www.youtube.com","player.vimeo.com"]},o=[".fluidvids {","width: 100%; max-width: 100%; position: relative;","}",".fluidvids-item {","position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;","}"].join(""),r=document.head||document.getElementsByTagName("head")[0];return d.render=function(){for(var e=document.querySelectorAll(d.selector.join()),t=e.length;t--;)i(e[t])},d.init=function(e){for(var t in e)d[t]=e[t];d.render(),n()},d});199 200 // init201 fluidvids.init({202 selector: ['iframe', 'object'],203 players: ['.'] // remove default youtube / vimeo restriction.204 });205 </script>206 207 <?php208 }209 }210 }211 add_action( 'bp_activity_embed_after_content', 'bp_activity_embed_response_display_media' ); -
src/bp-activity/css/embed.css
diff --git src/bp-activity/css/embed.css src/bp-activity/css/embed.css index e69de29..9690c3a 100644
1 #bp-embed-header:after { 2 clear: both; 3 content: ""; 4 display: table; 5 margin-bottom: 1em; 6 } 7 8 .bp-embed-avatar { 9 float: left; 10 margin: 0 .75em 0 0; 11 } 12 13 div.bp-embed-heading { 14 margin: 0 0 15px; 15 font-weight: bold; 16 font-size: 120%; 17 line-height: 1.3; 18 margin-bottom: 0; 19 } 20 21 div.bp-embed-heading a { 22 color: #32373c; 23 } 24 25 div.bp-embed-heading a img.avatar { 26 vertical-align: bottom; 27 margin-right: 2px; 28 } 29 30 .wp-embed-excerpt, p.bp-embed-timestamp { 31 margin-bottom: .5em; 32 } 33 34 .wp-embed-excerpt a { 35 color: #21759b; 36 display: inline-block; 37 overflow: hidden; 38 text-overflow: ellipsis; 39 vertical-align: top; 40 white-space: nowrap; 41 max-width: 250px; 42 } 43 44 .bp-activity-embed-display-media { 45 height: auto; 46 max-width: 550px; 47 } 48 49 .bp-activity-embed-display-media img { 50 height: auto; 51 max-width: 100%; 52 } 53 54 .activity-read-more { 55 margin-left: .5em; 56 } 57 58 .activity-read-more a { 59 color: #b4b9be; 60 } 61 62 .wp-embed-footer { 63 margin-top: 20px; 64 } -
src/bp-core/classes/class-bp-oembed-component.php
diff --git src/bp-core/classes/class-bp-oembed-component.php src/bp-core/classes/class-bp-oembed-component.php index 139b80a..44ed154 100644
abstract class BP_oEmbed_Component { 303 303 post_class( 'wp-embed' ); 304 304 echo '>'; 305 305 306 // Template part for our embed header.307 bp_get_asset_template_part( 'embeds/header', bp_current_component() );308 309 306 /** 310 307 * Inject BuddyPress embed content on this hook. 311 308 * … … abstract class BP_oEmbed_Component { 531 528 532 529 $this->content(); 533 530 } 534 } 535 No newline at end of file 531 } -
src/bp-templates/bp-legacy/buddypress/assets/embeds/activity.php
diff --git src/bp-templates/bp-legacy/buddypress/assets/embeds/activity.php src/bp-templates/bp-legacy/buddypress/assets/embeds/activity.php index 6c88f53..68901ac 100644
2 2 <?php if ( bp_has_activities( 'display_comments=threaded&show_hidden=true&include=' . bp_current_action() ) ) : ?> 3 3 4 4 <?php while ( bp_activities() ) : bp_the_activity(); ?> 5 <div class="wp-embed-excerpt"><?php bp_activity_embed_excerpt(); ?></div> 5 <div id="bp-embed-header"> 6 <div class="bp-embed-avatar"> 7 <a href="<?php bp_activity_user_link(); ?>"> 8 <?php bp_activity_embed_avatar(); ?> 9 </a> 10 </div> 11 <div class="bp-embed-heading"> 12 <?php bp_activity_embed_heading() ;?> 13 </div> 14 15 <p 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></p> 16 </div> 6 17 7 < p class="wp-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></p>18 <?php bp_activity_embed_rich_content(); ?> 8 19 9 < ?php do_action( 'bp_activity_embed_after_content' ); ?>20 <div class="wp-embed-excerpt"><?php bp_activity_embed_excerpt(); ?></div> 10 21 11 22 <?php endwhile; ?> 12 23 -
deleted file src/bp-templates/bp-legacy/buddypress/assets/embeds/header.php
diff --git src/bp-templates/bp-legacy/buddypress/assets/embeds/header.php src/bp-templates/bp-legacy/buddypress/assets/embeds/header.php deleted file mode 100644 index 7a4bc8a..0000000
+ - 1 2 <div id="wp-embed-header">3 <div class="wp-embed-avatar">4 <a href="<?php bp_displayed_user_link(); ?>">5 <?php bp_displayed_user_avatar( 'type=thumb&width=36&height=36' ); ?>6 </a>7 </div>8 9 <p class="wp-embed-heading">10 <a href="<?php bp_displayed_user_link(); ?>">11 <?php bp_displayed_user_fullname(); ?>12 </a>13 </p>14 15 <?php if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) : ?>16 <p class="wp-embed-mentionname">@<?php bp_displayed_user_mentionname(); ?></p>17 <?php endif; ?>18 </div>