Skip to:
Content

BuddyPress.org

Ticket #2707: 2707.002.patch

File 2707.002.patch, 7.6 KB (added by r-a-y, 14 years ago)

Adds missing diff for bp-core.php

  • buddypress/bp-core/bp-core-classes.php

     
    684684        }
    685685}
    686686
     687/**
     688 * BP_Embed
     689 *
     690 * Extends WP_Embed class for use with BuddyPress.
     691 *
     692 * @package BuddyPress Core
     693 * @since 1.3
     694 * @see WP_Embed
     695 */
     696class BP_Embed extends WP_Embed {
     697
     698        /**
     699         * PHP4 constructor
     700         */
     701        function BP_Embed() {
     702                return $this->__construct();
     703        }
     704
     705        /**
     706         * PHP5 constructor
     707         */
     708        function __construct() {
     709                global $wp_embed;
     710
     711                // Make sure we populate the WP_Embed handlers array.
     712                // These are providers that use a regex callback on the URL in question.
     713                // Do not confuse with oEmbed providers, which require an external ping.
     714                // Used in WP_Embed::shortcode()
     715                $this->handlers = $wp_embed->handlers;
     716
     717                if( !defined( 'BP_EMBED_DISABLE_ACTIVITY' ) ) {
     718                        add_filter( 'bp_get_activity_content_body', array(&$this, 'autoembed'), 9 );
     719                        add_filter( 'bp_get_activity_content_body', array(&$this, 'run_shortcode'), 8 );
     720                }
     721
     722                if( !defined( 'BP_EMBED_DISABLE_ACTIVITY_REPLIES' ) ) {
     723                        add_filter( 'bp_get_activity_content', array(&$this, 'autoembed'), 9 );
     724                        add_filter( 'bp_get_activity_content', array(&$this, 'run_shortcode'), 8 );
     725                }
     726
     727                if( !defined( 'BP_EMBED_DISABLE_FORUM_POSTS' ) ) {
     728                        add_filter( 'bp_get_the_topic_post_content', array(&$this, 'autoembed'), 9 );
     729                        add_filter( 'bp_get_the_topic_post_content', array(&$this, 'run_shortcode'), 8 );
     730                }
     731        }
     732
     733        /**
     734         * Base function so BP components / plugins can parse links to be embedded.
     735         * View examples to add support in {@link bp_embed_init()}.
     736         * Overrides {@link WP_Embed::shortcode()}.
     737         *
     738         * @uses wp_parse_args()
     739         * @uses wp_embed_defaults()
     740         * @uses _wp_oembed_get_object()
     741         * @uses wp_oembed_get() Connects to oEmbed provider and returns HTML on success.
     742         * @uses WP_Embed::maybe_make_link() Process URL for hyperlinking on oEmbed failure.
     743         * @param string $url The URL attempting to be embedded.
     744         * @param array $attr Shortcode attributes from {@link WP_Embed::shortcode()}.
     745         * @return string The embed HTML on success, otherwise the original URL.
     746         */
     747        function shortcode( $attr, $url = '' ) {
     748                if ( empty($url) )
     749                        return '';
     750
     751                $rawattr = $attr;
     752                $attr = wp_parse_args( $attr, wp_embed_defaults() );
     753
     754                // Look for known internal handlers
     755                ksort( $this->handlers );
     756                foreach ( $this->handlers as $priority => $handlers ) {
     757                        foreach ( $handlers as $id => $handler ) {
     758                                if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
     759                                        if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
     760                                                return apply_filters( 'embed_handler_html', $return, $url, $attr );
     761                                }
     762                        }
     763                }
     764
     765                // Get object ID
     766                $id = apply_filters( 'bp_embed_object_id', $id );
     767
     768                // Is oEmbed discovery on?
     769                $attr['discover'] = apply_filters( 'bp_embed_oembed_discover', false );
     770
     771                // Set up a new WP oEmbed object to check URL with registered oEmbed providers
     772                require_once( ABSPATH . WPINC . '/class-oembed.php' );
     773                $oembed_obj = _wp_oembed_get_object();
     774
     775                // If oEmbed discovery is true, skip oEmbed provider check
     776                $is_oembed_link = false;
     777                if ( !$attr['discover'] ) {
     778                        foreach ( (array)$oembed_obj->providers as $provider_matchmask => $provider ) {
     779                                $regex = ( $is_regex = $provider[1] ) ? $provider_matchmask : '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $provider_matchmask ), '#' ) ) . '#i';
     780
     781                                if ( preg_match( $regex, $url ) )
     782                                        $is_oembed_link = true;
     783                        }
     784
     785                        // If URL doesn't match a WP oEmbed provider, stop parsing and return link
     786                        if ( !$is_oembed_link )
     787                                return $this->maybe_make_link( $url ); 
     788                }
     789
     790                // Check to see if an object ID was passed
     791                if ( $id ) {
     792                        // Setup the cachekey
     793                        $cachekey = '_oembed_' . md5( $url . serialize( $attr ) );
     794
     795                        // Let components / plugins grab their cache
     796                        $cache = apply_filters( 'bp_embed_get_cache', $cache, $id, $cachekey, $url, $attr, $rawattr );
     797
     798                        // Grab cache and return it if available
     799                        if ( !empty($cache) ) {
     800                                return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $rawattr );
     801                        }
     802                        // If no cache, ping the oEmbed provider and cache the result
     803                        else {
     804                                $html = wp_oembed_get( $url, $attr );
     805                                $cache = ( $html ) ? $html : $url;
     806
     807                                // Let components / plugins save their cache
     808                                do_action( 'bp_embed_update_cache', $cache, $cachekey, $id );
     809
     810                                // If there was a result, return it
     811                                if ( $html )
     812                                        return apply_filters( 'embed_oembed_html', $html, $url, $attr, $rawattr );
     813                        }
     814                }
     815
     816                // Still unknown
     817                return $this->maybe_make_link( $url );
     818        }
     819}
     820
    687821?>
  • buddypress/bp-core/bp-core-embed.php

     
     1<?php
     2/**
     3 * bp_embed_init()
     4 *
     5 * Initializes {@link BP_Embed} after everything is loaded.
     6 * This is to ensure the {@link WP_Embed} handlers array is populated,
     7 * as well as making sure all BP components are loaded before we do any conditional checks,
     8 * and that activity updates created by AJAX get parsed.
     9 *
     10 * @package BuddyPress Core
     11 * @since 1.3
     12 */
     13function bp_embed_init() {
     14        $bp_embed = new BP_Embed();
     15
     16        // Check activity component
     17        if ( bp_is_activity_component() || ( bp_is_group_home() && bp_is_active('activity') ) ) {
     18                add_filter( 'bp_embed_object_id', 'bp_get_activity_id' );
     19                add_filter( 'bp_embed_get_cache', 'bp_embed_activity_cache', 10, 3 );
     20                add_action( 'bp_embed_update_cache', 'bp_embed_activity_save_cache', 10, 3 );           
     21        }
     22
     23        // Check forum component
     24        if ( bp_is_group_forum_topic() ) {
     25                add_filter( 'bp_embed_object_id', 'bp_get_the_topic_post_id' );
     26                add_filter( 'bp_embed_get_cache', 'bp_embed_forum_cache', 10, 3 );
     27                add_action( 'bp_embed_update_cache', 'bp_embed_forum_save_cache', 10, 3 );
     28        }
     29}
     30add_action( 'init', 'bp_embed_init' );
     31
     32/* ACTIVITY COMPONENT */
     33function bp_embed_activity_cache( $cache, $id, $cachekey ) {
     34        return bp_activity_get_meta( $id, $cachekey );
     35}
     36
     37function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
     38        bp_activity_update_meta( $id, $cachekey, $cache );
     39}
     40
     41/* FORUMS COMPONENT */
     42function bp_embed_forum_cache( $cache, $id, $cachekey ) {
     43        return bb_get_postmeta( $id, $cachekey );
     44}
     45
     46function bp_embed_forum_save_cache( $cache, $cachekey, $id ) {
     47        bb_update_postmeta( $id, $cachekey, $cache );
     48}
     49?>
  • buddypress/bp-forums/bp-forums-filters.php

     
    4545add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_make_nofollow_filter' );
    4646add_filter( 'bp_get_the_topic_post_content', 'bp_forums_make_nofollow_filter' );
    4747
     48// Allow shortcodes in forum posts
     49add_filter( 'bp_get_the_topic_post_content', 'do_shortcode' );
     50
    4851function bp_forums_filter_kses( $content ) {
    4952        global $allowedtags;
    5053
  • buddypress/bp-core.php

     
    3737require ( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php' );
    3838require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
    3939require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
     40require ( BP_PLUGIN_DIR . '/bp-core/bp-core-embed.php' );
    4041
    4142/* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
    4243if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )