Skip to:
Content

BuddyPress.org

Ticket #6772: 6772.05.suggestions.patch

File 6772.05.suggestions.patch, 16.6 KB (added by imath, 9 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 31a4e02..f55ab4c 100644
    defined( 'ABSPATH' ) || exit; 
    1919 * @since 2.5.0
    2020 */
    2121function bp_activity_setup_oembed() {
    22         if ( bp_get_major_wp_version() >= 4.4 && bp_is_active( 'activity', 'embeds' ) ) {
     22        if ( function_exists( 'wp_oembed_register_route' ) && bp_is_active( 'activity', 'embeds' ) ) {
    2323                buddypress()->activity->oembed = new BP_Activity_oEmbed_Component;
    2424        }
    2525}
    function bp_activity_embed_excerpt( $content = '' ) { 
    5050                 * bp_activity_truncate_entry() includes the 'Read More' link, which is why
    5151                 * we're using this instead of bp_create_excerpt().
    5252                 */
    53                 $content = html_entity_decode( $content );
    54                 $content = bp_activity_truncate_entry( $content, array(
    55                         'html' => false,
     53                $excerpt = bp_activity_truncate_entry( html_entity_decode( $content ), array(
     54                        'html'              => false,
    5655                        'filter_shortcodes' => true,
    5756                        'strip_tags'        => true,
    58                         'force_truncate'    => true
     57                        'force_truncate'    => true,
     58                        'remove_links'      => true,
    5959                ) );
    6060
    61                 // Remove links from content.
    62                 $content = preg_replace( '#^\s*(https?://[^\s"]+)\s*$#im', '', $content );
     61                // Temporarly remove this filter as we already truncated the entry.
     62                remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry' );
    6363
    64                 return $content;
    65         }
    66 
    67 /**
    68  * Outputs the first embedded item in the activity oEmbed template.
    69  *
    70  * @since 2.5.0
    71  */
    72 function bp_activity_embed_response_display_media() {
    73         // Bail if oEmbed request explicitly hides media.
    74         if ( isset( $_REQUEST['hide_media'] ) && true == wp_validate_boolean( $_REQUEST['hide_media'] ) ) {
    75                 return;
    76         }
    77 
    78         // Find all embeds for the activity item.
    79         $embeds = bp_core_extract_media_from_content( $GLOBALS['activities_template']->activity->content, 'embeds' );
    80 
    81         /**
    82          * Should we display media in the oEmbed template?
    83          *
    84          * @since 2.5.0
    85          *
    86          * @param bool $retval Defaults to true.
    87          */
    88         $allow_embeds = apply_filters( 'bp_activity_embed_display_media', true );
    89 
    90         // Only embed the first embedded item.
    91         if ( $embeds && $allow_embeds ) {
    92                 $content = apply_filters( 'bp_get_activity_content_body', $embeds['embeds'][0]['url'] );
    93                 echo $content;
     64                // Apply all the other filters to the content.
     65                $excerpt = apply_filters( 'bp_get_activity_content_body', $excerpt );
    9466
    95                 if ( false !== strpos( $content, '<iframe' ) ) {
    96         ?>
     67                // Restore the filter.
     68                add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry' );
    9769
    98 <script>
    99 /*! fluidvids.js v1.2.0 | (c) 2013 @toddmotto | https://github.com/toddmotto/fluidvids */
    100 window.fluidvids=function(a,b){"use strict";var c=function(a){this.elem=a};c.prototype={init:function(){var a=100*(this.elem.height/this.elem.width);this.elem.style.position="absolute",this.elem.style.top="0",this.elem.style.left="0",this.elem.width="100%",this.elem.height="100%";var c=b.createElement("div");c.className="fluidvids",c.style.width="100%",c.style.position="relative",c.style.paddingTop=a+"%";var d=this.elem.parentNode;d.insertBefore(c,this.elem),c.appendChild(this.elem)}};for(var d=b.getElementsByTagName("iframe"),e=0;e<d.length;e++){d[e].src&&new c(d[e]).init()}}(window,document);
    101 </script>
    102 
    103         <?php
    104                 }
     70                /**
     71                 * Filter here to edit the embed excerpt.
     72                 *
     73                 * @since  2.5.0
     74                 *
     75                 * @param  string $excerpt The embed excerpt
     76                 * @param  string $content The full content of the activity
     77                 */
     78                return apply_filters( 'bp_activity_get_embed_excerpt', $excerpt, $content );
    10579        }
    106 }
    107 add_action( 'bp_activity_embed_after_content', 'bp_activity_embed_response_display_media' );
  • src/bp-activity/bp-activity-loader.php

    diff --git src/bp-activity/bp-activity-loader.php src/bp-activity/bp-activity-loader.php
    index f41630e..f8180e3 100644
    class BP_Activity_Component extends BP_Component { 
    6969                }
    7070
    7171                // Embeds - only applicable for WP 4.4+
    72                 if ( bp_get_major_wp_version() >= 4.4 && bp_is_active( $this->id, 'embeds' ) ) {
     72                if ( function_exists( 'wp_oembed_register_route' ) && bp_is_active( $this->id, 'embeds' ) ) {
    7373                        $includes[] = 'classes/class-bp-activity-oembed-component';
    7474                        $includes[] = 'embeds';
    7575                }
  • src/bp-activity/classes/class-bp-activity-oembed-component.php

    diff --git src/bp-activity/classes/class-bp-activity-oembed-component.php src/bp-activity/classes/class-bp-activity-oembed-component.php
    index 8deaa8b..f61823d 100644
     
    99// Exit if accessed directly.
    1010defined( 'ABSPATH' ) || exit;
    1111
    12 require_once( buddypress()->plugin_dir . '/bp-core/classes/class-bp-oembed-component.php' );
     12if ( class_exists( 'BP_oEmbed_Component' ) ) :
    1313
    1414/**
    1515 * oEmbed handler to respond and render single activity items.
    class BP_Activity_oEmbed_Component extends BP_oEmbed_Component { 
    3636        }
    3737
    3838        /**
    39          * Add custom endpoint arguments.
    40          *
    41          * Currently, includes 'hide_media'.
    42          *
    43          * @since 2.5.0
    44          *
    45          * @return array
    46          */
    47         protected function set_route_args() {
    48                 return array(
    49                         'hide_media' => array(
    50                                 'default' => false,
    51                                 'sanitize_callback' => 'wp_validate_boolean'
    52                         )
    53                 );
    54         }
    55 
    56         /**
    5739         * Output our custom embed template part.
    5840         *
    5941         * @since 2.5.0
    class BP_Activity_oEmbed_Component extends BP_oEmbed_Component { 
    158140
    159141                // 'wp-embedded-content' CSS class is necessary due to how the embed JS works.
    160142                $blockquote = sprintf( '<blockquote class="wp-embedded-content bp-activity-item">%1$s%2$s %3$s</blockquote>',
    161                         '<p>' . bp_activity_get_embed_excerpt( $activity->content ) . '</p>',
     143                        bp_activity_get_embed_excerpt( $activity->content ),
    162144                        '- ' . bp_core_get_user_displayname( $activity->user_id ) . $mentionname,
    163145                        '<a href="' . esc_url( bp_activity_get_permalink( $item_id ) ) . '">' . $date . '</a>'
    164146                );
    class BP_Activity_oEmbed_Component extends BP_oEmbed_Component { 
    217199                                        _n(
    218200                                                '%s <span class="screen-reader-text">Comment</span>',
    219201                                                '%s <span class="screen-reader-text">Comments</span>',
    220                                                 $count
     202                                                $count,
     203                                                'buddypress'
    221204                                        ),
    222205                                        number_format_i18n( $count )
    223206                                );
    class BP_Activity_oEmbed_Component extends BP_oEmbed_Component { 
    228211        <?php
    229212        }
    230213}
     214
     215endif;
  • src/bp-core/bp-core-actions.php

    diff --git src/bp-core/bp-core-actions.php src/bp-core/bp-core-actions.php
    index aea4467..09f7b6a 100644
    add_action( 'set_current_user', 'bp_setup_current_user', 10 ); 
    3737add_action( 'setup_theme',             'bp_setup_theme',            10    );
    3838add_action( 'after_setup_theme',       'bp_after_setup_theme',      100   ); // After WP themes.
    3939add_action( 'wp_enqueue_scripts',      'bp_enqueue_scripts',        10    );
     40add_action( 'enqueue_embed_scripts',   'bp_enqueue_embed_scripts',  10    );
    4041add_action( 'admin_bar_menu',          'bp_setup_admin_bar',        20    ); // After WP core.
    4142add_action( 'template_redirect',       'bp_template_redirect',      10    );
    4243add_action( 'widgets_init',            'bp_widgets_init',           10    );
  • src/bp-core/bp-core-classes.php

    diff --git src/bp-core/bp-core-classes.php src/bp-core/bp-core-classes.php
    index 0da6fbb..608eac6 100644
    require dirname( __FILE__ ) . '/classes/class-bp-media-extractor.php'; 
    2424require dirname( __FILE__ ) . '/classes/class-bp-attachment.php';
    2525require dirname( __FILE__ ) . '/classes/class-bp-attachment-avatar.php';
    2626require dirname( __FILE__ ) . '/classes/class-bp-attachment-cover-image.php';
     27
     28if ( function_exists( 'wp_oembed_register_route' ) ) {
     29        require dirname( __FILE__ ) . '/classes/class-bp-oembed-component.php';
     30}
  • src/bp-core/bp-core-dependency.php

    diff --git src/bp-core/bp-core-dependency.php src/bp-core/bp-core-dependency.php
    index 6982924..9ab8314 100644
    function bp_enqueue_scripts() { 
    400400}
    401401
    402402/**
     403 * Fire the 'bp_enqueue_embed_scripts' action, where BP enqueues its CSS and JS
     404 * for BuddyPress embeds.
     405 *
     406 * @since 2.5.0
     407 *
     408 * @uses do_action() Calls 'bp_enqueue_embed_scripts'.
     409 */
     410function bp_enqueue_embed_scripts() {
     411        if ( ! is_buddypress() ) {
     412                return;
     413        }
     414
     415        /**
     416         * Fires inside the 'bp_enqueue_embed_scripts' function, where BP enqueues its CSS and JS
     417         * for BuddyPress embeds.
     418         *
     419         * @since 2.5.0
     420         */
     421        do_action ( 'bp_enqueue_embed_scripts' );
     422}
     423
     424/**
    403425 * Fire the 'bp_add_rewrite_tag' action, where BP adds its custom rewrite tags.
    404426 *
    405427 * @since 1.8.0
  • src/bp-core/bp-core-template-loader.php

    diff --git src/bp-core/bp-core-template-loader.php src/bp-core/bp-core-template-loader.php
    index 8f4b03c..c76133f 100644
    function bp_locate_template( $template_names, $load = false, $require_once = tru 
    147147}
    148148
    149149/**
     150 * Locate the URL for a requested asset
     151 *
     152 * @since  2.5.0
     153 *
     154 * @param  string $filename The requested asset (eg: css/buddypress.css)
     155 * @return string           The located uri for the asset.
     156 */
     157function bp_locate_template_asset_uri( $filename ) {
     158        $asset = bp_locate_template( $filename );
     159
     160        if ( ! $asset ) {
     161                return false;
     162        }
     163
     164        // Should be the majority of cases.
     165        if ( preg_match( '/' . addcslashes( WP_CONTENT_DIR, '/' ) . '/' , $asset ) ) {
     166                $uri = str_replace( WP_CONTENT_DIR, content_url(), $asset );
     167
     168        // Otherwise there's a good chance it's a symlinked plugin.
     169        } else {
     170                $uri = plugins_url( wp_basename( $filename ), $asset );
     171        }
     172
     173        /**
     174         * Filter here to edit the located url for the asset.
     175         *
     176         * @since  2.5.0
     177         *
     178         * @param  string $uri      The located uri for the asset.
     179         * @param  string $filename The requested asset
     180         */
     181        return apply_filters( 'bp_locate_template_asset_uri', $uri, $filename );
     182}
     183
     184/**
    150185 * Register a new template stack location.
    151186 *
    152187 * This allows for templates to live in places beyond just the parent/child
  • 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 4e0b9f9..99f571a 100644
    abstract class BP_oEmbed_Component { 
    176176         * @since 2.5.0
    177177         */
    178178        protected function setup_hooks() {
    179                 add_action( 'rest_api_init',  array( $this, 'register_route' ) );
    180                 add_action( 'embed_content', array( $this, 'inject_content' ) );
     179                add_action( 'rest_api_init',    array( $this, 'register_route' ) );
     180                add_action( 'bp_embed_content', array( $this, 'inject_content' ) );
    181181
    182182                add_filter( 'embed_template', array( $this, 'filter_template' ) );
    183183                add_filter( 'post_embed_url', array( $this, 'filter_embed_url' ) );
    abstract class BP_oEmbed_Component { 
    439439
    440440                $this->content();
    441441        }
    442 }
    443  No newline at end of file
     442}
  • src/bp-templates/bp-legacy/buddypress-functions.php

    diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php
    index c5974e2..803b6da 100644
    class BP_Legacy extends BP_Theme_Compat { 
    8383
    8484                /** Scripts ***********************************************************/
    8585
    86                 add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_styles'   ) ); // Enqueue theme CSS
    87                 add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts'  ) ); // Enqueue theme JS
    88                 add_filter( 'bp_enqueue_scripts', array( $this, 'localize_scripts' ) ); // Enqueue theme script localization
    89                 add_action( 'bp_head',            array( $this, 'head_scripts'     ) ); // Output some extra JS in the <head>.
     86                add_action( 'bp_enqueue_scripts',       array( $this, 'enqueue_styles'       ) ); // Enqueue theme CSS
     87                add_action( 'bp_enqueue_embed_scripts', array( $this, 'embed_enqueue_styles' ) ); // Enqueue theme Embed CSS
     88                add_action( 'bp_enqueue_scripts',       array( $this, 'enqueue_scripts'      ) ); // Enqueue theme JS
     89                add_filter( 'bp_enqueue_scripts',       array( $this, 'localize_scripts'     ) ); // Enqueue theme script localization
     90                add_action( 'bp_head',                  array( $this, 'head_scripts'         ) ); // Output some extra JS in the <head>.
    9091
    9192                /** Body no-js Class **************************************************/
    9293
    class BP_Legacy extends BP_Theme_Compat { 
    270271        }
    271272
    272273        /**
     274         * Load the theme Embed CSS
     275         *
     276         * @since 2.5.0
     277         */
     278        public function embed_enqueue_styles() {
     279                $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
     280
     281                wp_enqueue_style( 'bp-embeds-css', bp_locate_template_asset_uri( "assets/embeds/css/style{$min}.css" ), array(), $this->version, 'screen' );
     282
     283                if ( $min ) {
     284                        wp_style_add_data( 'bp-embeds-css', 'suffix', $min );
     285                }
     286        }
     287
     288        /**
    273289         * Enqueue the required JavaScript files
    274290         *
    275291         * @since 1.7.0
  • 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 1fdae1a..8fa909f 100644
     
    22                <?php if ( bp_has_activities( 'display_comments=threaded&show_hidden=true&include=' . bp_current_action() ) ) : ?>
    33
    44                        <?php while ( bp_activities() ) : bp_the_activity(); ?>
    5                                 <div class="wp-embed-excerpt"><p><?php bp_activity_embed_excerpt(); ?></p></div>
     5
     6                                <?php do_action( 'bp_activity_embed_before_content' ); ?>
     7
     8                                <div class="wp-embed-excerpt"><?php bp_activity_embed_excerpt(); ?></div>
    69
    710                                <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>
    811
  • deleted file src/bp-templates/bp-legacy/buddypress/assets/embeds/css.php

    diff --git src/bp-templates/bp-legacy/buddypress/assets/embeds/css.php src/bp-templates/bp-legacy/buddypress/assets/embeds/css.php
    deleted file mode 100644
    index beaa782..0000000
    + -  
    1 <style type="text/css">
    2 #wp-embed-header:after {
    3         clear: both;
    4         content: "";
    5         display: table;
    6         margin-bottom: 1em;
    7 }
    8 
    9 .wp-embed-avatar {
    10         float: left;
    11         margin: 0 .75em 0 0;
    12 }
    13 
    14 p.wp-embed-heading {
    15         font-size: 16px;
    16         margin-bottom: 0;
    17 }
    18 
    19 .wp-embed-excerpt, p.wp-embed-timestamp {
    20         margin-bottom: .5em;
    21 }
    22 
    23 .activity-read-more {
    24         margin-left: .5em;
    25 }
    26 
    27 .activity-read-more a {
    28         color: #b4b9be;
    29 }
    30 
    31 .wp-embed-footer {
    32         margin-top: 20px;
    33 }
    34 </style>
    35  No newline at end of file
  • src/bp-templates/bp-legacy/buddypress/assets/embeds/css/style.css

    diff --git src/bp-templates/bp-legacy/buddypress/assets/embeds/css/style.css src/bp-templates/bp-legacy/buddypress/assets/embeds/css/style.css
    index e69de29..7737744 100644
     
     1#wp-embed-header:after {
     2        clear: both;
     3        content: "";
     4        display: table;
     5        margin-bottom: 1em;
     6}
     7
     8.wp-embed-avatar {
     9        float: left;
     10        margin: 0 .75em 0 0;
     11}
     12
     13p.wp-embed-heading {
     14        font-size: 16px;
     15        margin-bottom: 0;
     16}
     17
     18.wp-embed-excerpt, p.wp-embed-timestamp {
     19        margin-bottom: .5em;
     20}
     21
     22.activity-read-more {
     23        margin-left: .5em;
     24}
     25
     26.activity-read-more a {
     27        color: #b4b9be;
     28}
     29
     30.wp-embed-footer {
     31        margin-top: 20px;
     32}
  • src/bp-templates/bp-legacy/buddypress/assets/embeds/template.php

    diff --git src/bp-templates/bp-legacy/buddypress/assets/embeds/template.php src/bp-templates/bp-legacy/buddypress/assets/embeds/template.php
    index 599c283..eb488e7 100644
    if ( ! headers_sent() ) { 
    2525        <title><?php echo wp_get_document_title(); ?></title>
    2626        <meta http-equiv="X-UA-Compatible" content="IE=edge">
    2727        <base target="_top" />
     28
    2829        <?php
    2930        /** This action is documented in wp-includes/embed-template.php */
    30         do_action( 'embed_head' );
     31        do_action( 'embed_head' ); ?>
    3132
    32         // This is used by r-a-y for testing purposes at the moment.
    33         bp_get_asset_template_part( 'embeds/css' );
    34         ?>
    3533</head>
    3634<body <?php body_class(); ?>>
    3735<div <?php post_class( 'wp-embed' ); ?>>
     36
    3837<?php
    3938bp_get_asset_template_part( 'embeds/header', bp_current_component() );
    4039
    41 /** This action is documented in wp-includes/embed-template.php */
    42 do_action( 'embed_content' );
     40/**
     41 * Print the content for the BuddyPress Embed object.
     42 *
     43 * @since 2.5.0
     44 */
     45do_action( 'bp_embed_content' );
    4346
    4447bp_get_asset_template_part( 'embeds/footer', bp_current_component() );
    4548?>
    bp_get_asset_template_part( 'embeds/footer', bp_current_component() ); 
    5154do_action( 'embed_footer' );
    5255?>
    5356</body>
    54 </html>
    55  No newline at end of file
     57</html>