Skip to:
Content

BuddyPress.org

Ticket #2707: 2707.006.patch

File 2707.006.patch, 17.5 KB (added by r-a-y, 14 years ago)
  • buddypress/bp-core/bp-core-classes.php

     
    10801080        }
    10811081}
    10821082
     1083/**
     1084 * BP_Embed
     1085 *
     1086 * Extends WP_Embed class for use with BuddyPress.
     1087 *
     1088 * @package BuddyPress Core
     1089 * @since 1.3
     1090 * @see WP_Embed
     1091 */
     1092class BP_Embed extends WP_Embed {
     1093
     1094        /**
     1095         * PHP4 constructor
     1096         */
     1097        function BP_Embed() {
     1098                return $this->__construct();
     1099        }
     1100
     1101        /**
     1102         * Class constructor
     1103         */
     1104        function __construct() {
     1105                global $wp_embed;
     1106
     1107                // Make sure we populate the WP_Embed handlers array.
     1108                // These are providers that use a regex callback on the URL in question.
     1109                // Do not confuse with oEmbed providers, which require an external ping.
     1110                // Used in WP_Embed::shortcode()
     1111                $this->handlers = $wp_embed->handlers;
     1112
     1113                if( !defined( 'BP_EMBED_DISABLE_ACTIVITY' ) ) {
     1114                        add_filter( 'bp_get_activity_content_body',     array( &$this, 'autoembed' ), 8 );
     1115                        add_filter( 'bp_get_activity_content_body',     array( &$this, 'run_shortcode' ), 7 );
     1116                }
     1117
     1118                if( !defined( 'BP_EMBED_DISABLE_ACTIVITY_REPLIES' ) ) {
     1119                        add_filter( 'bp_get_activity_content',          array( &$this, 'autoembed' ), 8 );
     1120                        add_filter( 'bp_get_activity_content',          array( &$this, 'run_shortcode' ), 7 );
     1121                }
     1122
     1123                if( !defined( 'BP_EMBED_DISABLE_FORUM_POSTS' ) ) {
     1124                        add_filter( 'bp_get_the_topic_post_content',    array( &$this, 'autoembed' ), 8 );
     1125                        add_filter( 'bp_get_the_topic_post_content',    array( &$this, 'run_shortcode' ), 7 );
     1126                }
     1127        }
     1128
     1129        /**
     1130         * The {@link do_shortcode()} callback function.
     1131         *
     1132         * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of the registered embed handlers.
     1133         * Next, checks the URL against the regex of registered {@link WP_oEmbed} providers if oEmbed discovery is false.
     1134         * 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.
     1135         *
     1136         * @uses wp_parse_args()
     1137         * @uses wp_embed_defaults()
     1138         * @uses author_can()
     1139         * @uses _wp_oembed_get_object()
     1140         * @uses WP_Embed::maybe_make_link()
     1141         *
     1142         * @param array $attr Shortcode attributes.
     1143         * @param string $url The URL attempting to be embeded.
     1144         * @return string The embed HTML on success, otherwise the original URL.
     1145         */
     1146        function shortcode( $attr, $url = '' ) {
     1147
     1148                if ( empty( $url ) )
     1149                        return '';
     1150
     1151                $rawattr = $attr;
     1152                $attr = wp_parse_args( $attr, wp_embed_defaults() );
     1153
     1154                // kses converts & into & and we need to undo this
     1155                // See http://core.trac.wordpress.org/ticket/11311
     1156                $url = str_replace( '&', '&', $url );
     1157
     1158                // Look for known internal handlers
     1159                ksort( $this->handlers );
     1160                foreach ( $this->handlers as $priority => $handlers ) {
     1161                        foreach ( $handlers as $id => $handler ) {
     1162                                if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
     1163                                        if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
     1164                                                return apply_filters( 'embed_handler_html', $return, $url, $attr );
     1165                                }
     1166                        }
     1167                }
     1168
     1169                // Get object ID
     1170                $id = apply_filters( 'embed_post_id', $id );
     1171
     1172                // Is oEmbed discovery on?
     1173                $attr['discover'] = ( apply_filters( 'bp_embed_oembed_discover', false ) && author_can( $id, 'unfiltered_html' ) );
     1174
     1175                // Set up a new WP oEmbed object to check URL with registered oEmbed providers
     1176                require_once( ABSPATH . WPINC . '/class-oembed.php' );
     1177                $oembed_obj = _wp_oembed_get_object();
     1178
     1179                // If oEmbed discovery is true, skip oEmbed provider check
     1180                $is_oembed_link = false;
     1181                if ( !$attr['discover'] ) {
     1182                        foreach ( (array)$oembed_obj->providers as $provider_matchmask => $provider ) {
     1183                                $regex = ( $is_regex = $provider[1] ) ? $provider_matchmask : '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $provider_matchmask ), '#' ) ) . '#i';
     1184
     1185                                if ( preg_match( $regex, $url ) )
     1186                                        $is_oembed_link = true;
     1187                        }
     1188
     1189                        // If url doesn't match a WP oEmbed provider, stop parsing
     1190                        if ( !$is_oembed_link )
     1191                                return $this->maybe_make_link( $url );
     1192                }
     1193
     1194                return $this->parse_oembed( $id, $url, $attr, $rawattr );
     1195        }
     1196
     1197        /**
     1198         * Base function so BP components / plugins can parse links to be embedded.
     1199         * View an example to add support in {@link bp_activity_embed()}.
     1200         *
     1201         * @uses apply_filters() Filters cache.
     1202         * @uses do_action() To save cache.
     1203         * @uses wp_oembed_get() Connects to oEmbed provider and returns HTML on success.
     1204         * @uses WP_Embed::maybe_make_link() Process URL for hyperlinking on oEmbed failure.
     1205         * @param int $id ID to do the caching for.
     1206         * @param string $url The URL attempting to be embedded.
     1207         * @param array $attr Shortcode attributes from {@link WP_Embed::shortcode()}.
     1208         * @param array $rawattr Untouched shortcode attributes from {@link WP_Embed::shortcode()}.
     1209         * @return string The embed HTML on success, otherwise the original URL.
     1210         */
     1211        function parse_oembed( $id, $url, $attr, $rawattr ) {
     1212
     1213                if ( $id ) {
     1214
     1215                        // Setup the cachekey
     1216                        $cachekey = '_oembed_' . md5( $url . serialize( $attr ) );
     1217
     1218                        // Let components / plugins grab their cache
     1219                        $cache = apply_filters( 'bp_embed_get_cache', $cache, $id, $cachekey, $url, $attr, $rawattr );
     1220
     1221                        // Grab cache and return it if available
     1222                        if ( !empty( $cache ) ) {
     1223                                return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $rawattr );
     1224                        }
     1225                        // If no cache, ping the oEmbed provider and cache the result
     1226                        else {
     1227                                $html = wp_oembed_get( $url, $attr );
     1228                                $cache = ( $html ) ? $html : $url;
     1229
     1230                                // Let components / plugins save their cache
     1231                                do_action( 'bp_embed_update_cache', $cache, $cachekey, $id );
     1232
     1233                                // If there was a result, return it
     1234                                if ( $html )
     1235                                        return apply_filters( 'embed_oembed_html', $html, $url, $attr, $rawattr );
     1236                        }
     1237                }
     1238
     1239                // Still unknown
     1240                return $this->maybe_make_link( $url );
     1241        }
     1242}
     1243
    10831244?>
  • buddypress/bp-core/bp-core-functions.php

     
    1818 */
    1919function bp_get_option( $option_name, $default = false ) {
    2020        $value = get_blog_option( bp_get_option_blog_id( $option_name ), $option_name, $default );
    21        
     21
    2222        return apply_filters( 'bp_get_option', $value );
    2323}
    2424
     
    8383        $blog_specific_options = apply_filters( 'bp_blog_specific_options', array(
    8484                'bp-pages'
    8585        ) );
    86        
     86
    8787        if ( in_array( $option_name, $blog_specific_options ) ) {
    8888                if ( defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ) {
    8989                        $blog_id = get_current_blog_id();
     
    120120 */
    121121function bp_core_get_page_meta() {
    122122        $page_ids = bp_get_option( 'bp-pages' );
    123  
     123
    124124        // Upgrading from an earlier version of BP pre-1.3
    125125        if ( !isset( $page_ids['members'] ) && $ms_page_ids = get_site_option( 'bp-pages' ) ) {
    126126                $is_enable_multiblog = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? true : false;
    127  
     127
    128128                $page_blog_id = $is_enable_multiblog ? get_current_blog_id() : BP_ROOT_BLOG;
    129129
    130130                if ( isset( $ms_page_ids[$page_blog_id] ) ) {
     
    133133                        bp_update_option( 'bp-pages', $page_ids );
    134134                }
    135135        }
    136        
     136
    137137        return apply_filters( 'bp_core_get_page_meta', $page_ids );
    138138}
    139139
     
    503503add_action( 'admin_init', 'bp_core_activation_notice' );
    504504
    505505/**
     506 * Starts {@link BP_Embed} when BP is initialized.
     507 *
     508 * @package BuddyPress Core
     509 * @since 1.3
     510 */
     511function bp_embed_init() {
     512        $bp_embed = new BP_Embed();
     513}
     514add_action( 'bp_init', 'bp_embed_init' );
     515
     516/**
    506517 * Returns the domain for the root blog.
    507518 * eg: http://domain.com/ OR https://domain.com
    508519 *
     
    10071018        $meta_keys = "'" . implode( "','", (array)$site_options ) ."'";
    10081019
    10091020        $site_meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
    1010        
     1021
    10111022        // Backward compatibility - moves sitemeta to the blog
    10121023        if ( empty( $site_meta ) || ( count( $site_meta ) < count( $site_options ) ) ) {
    10131024                if ( is_multisite() ) {
     
    10151026                } else {
    10161027                        $ms_site_meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
    10171028                }
    1018                
     1029
    10191030                $settings_to_move = array(
    10201031                        'bp-deactivated-components',
    10211032                        'bp-blogs-first-install',
     
    10301041                        'bb-config-location',
    10311042                        'hide-loggedout-adminbar',
    10321043                );
    1033                
    1034                 foreach( (array)$ms_site_meta as $meta ) {     
     1044
     1045                foreach( (array)$ms_site_meta as $meta ) {
    10351046                        if ( isset( $meta->name ) && in_array( $meta->name, $settings_to_move ) ) {
    10361047                                bp_update_option( $meta->name, $meta->value );
    1037                                                
     1048
    10381049                                if ( empty( $site_meta[$meta->name] ) ) {
    10391050                                        $site_meta[$meta->name] = $meta->value;
    10401051                                }
     
    12701281
    12711282        do_action( 'bp_do_404', $redirect );
    12721283
    1273         $wp_query->set_404(); 
    1274         status_header( 404 ); 
     1284        $wp_query->set_404();
     1285        status_header( 404 );
    12751286        nocache_headers();
    12761287
    12771288        if ( 'remove_canonical_direct' == $redirect )
  • buddypress/bp-activity/bp-activity-functions.php

     
    962962        return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches );
    963963}
    964964
     965/** Embeds *******************************************************************/
     966
     967/**
     968 * Grabs the activity ID and attempts to retrieve the oEmbed cache (if it exists)
     969 * during the activity loop.  If no cache and link is embeddable, cache it.
     970 *
     971 * @see BP_Embed
     972 * @see bp_embed_activity_cache()
     973 * @see bp_embed_activity_save_cache()
     974 * @package BuddyPress Activity
     975 * @since 1.3
     976 */
     977function bp_activity_embed() {
     978        add_filter( 'embed_post_id',            'bp_get_activity_id' );
     979        add_filter( 'bp_embed_get_cache',       'bp_embed_activity_cache', 10, 3 );
     980        add_action( 'bp_embed_update_cache',    'bp_embed_activity_save_cache', 10, 3 );
     981}
     982add_action( 'activity_loop_start', 'bp_activity_embed' );
     983
     984        /**
     985         * Wrapper function for {@link bp_activity_get_meta()}.
     986         * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
     987         *
     988         * @package BuddyPress Activity
     989         * @since 1.3
     990         */
     991        function bp_embed_activity_cache( $cache, $id, $cachekey ) {
     992                return bp_activity_get_meta( $id, $cachekey );
     993        }
     994
     995        /**
     996         * Wrapper function for {@link bp_activity_update_meta()}.
     997         * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
     998         *
     999         * @package BuddyPress Activity
     1000         * @since 1.3
     1001         */
     1002        function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
     1003                bp_activity_update_meta( $id, $cachekey, $cache );
     1004        }
     1005
    9651006?>
  • buddypress/bp-forums/bp-forums-filters.php

     
    11<?php
    22
    33/* Apply WordPress defined filters */
    4 add_filter( 'bp_forums_bbconfig_location', 'wp_filter_kses', 1 );
    5 add_filter( 'bp_forums_bbconfig_location', 'esc_attr', 1 );
     4add_filter( 'bp_forums_bbconfig_location',              'wp_filter_kses', 1 );
     5add_filter( 'bp_forums_bbconfig_location',              'esc_attr', 1 );
    66
    7 add_filter( 'bp_get_the_topic_title', 'wp_filter_kses', 1 );
    8 add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_filter_kses', 1 );
    9 add_filter( 'bp_get_the_topic_post_content', 'bp_forums_filter_kses', 1 );
    10 
    11 add_filter( 'bp_get_the_topic_title', 'force_balance_tags' );
    12 add_filter( 'bp_get_the_topic_latest_post_excerpt', 'force_balance_tags' );
    13 add_filter( 'bp_get_the_topic_post_content', 'force_balance_tags' );
    14 
    15 add_filter( 'bp_get_the_topic_title', 'wptexturize' );
    16 add_filter( 'bp_get_the_topic_poster_name', 'wptexturize' );
    17 add_filter( 'bp_get_the_topic_last_poster_name', 'wptexturize' );
    18 add_filter( 'bp_get_the_topic_post_content', 'wptexturize' );
    19 add_filter( 'bp_get_the_topic_post_poster_name', 'wptexturize' );
    20 
    21 add_filter( 'bp_get_the_topic_title', 'convert_smilies' );
    22 add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_smilies' );
    23 add_filter( 'bp_get_the_topic_post_content', 'convert_smilies' );
    24 
    25 add_filter( 'bp_get_the_topic_title', 'convert_chars' );
    26 add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_chars' );
    27 add_filter( 'bp_get_the_topic_post_content', 'convert_chars' );
    28 
    29 add_filter( 'bp_get_the_topic_post_content', 'wpautop' );
    30 add_filter( 'bp_get_the_topic_latest_post_excerpt', 'wpautop' );
    31 
    32 add_filter( 'bp_get_the_topic_post_content', 'stripslashes_deep' );
    33 add_filter( 'bp_get_the_topic_title', 'stripslashes_deep' );
    34 add_filter( 'bp_get_the_topic_latest_post_excerpt', 'stripslashes_deep' );
    35 add_filter( 'bp_get_the_topic_poster_name', 'stripslashes_deep' );
    36 add_filter( 'bp_get_the_topic_last_poster_name', 'stripslashes_deep' );
    37 add_filter( 'bp_get_the_topic_object_name', 'stripslashes_deep' );
    38 
    39 add_filter( 'bp_get_the_topic_post_content', 'make_clickable', 9 );
    40 
    41 add_filter( 'bp_get_forum_topic_count_for_user', 'bp_core_number_format' );
    42 add_filter( 'bp_get_forum_topic_count', 'bp_core_number_format' );
    43 
    44 add_filter( 'bp_get_the_topic_title', 'bp_forums_make_nofollow_filter' );
    45 add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_make_nofollow_filter' );
    46 add_filter( 'bp_get_the_topic_post_content', 'bp_forums_make_nofollow_filter' );
     7add_filter( 'bp_get_the_topic_title',                   'wp_filter_kses', 1 );
     8add_filter( 'bp_get_the_topic_latest_post_excerpt',     'bp_forums_filter_kses', 1 );
     9add_filter( 'bp_get_the_topic_post_content',            'bp_forums_filter_kses', 1 );
     10
     11add_filter( 'bp_get_the_topic_title',                   'force_balance_tags' );
     12add_filter( 'bp_get_the_topic_latest_post_excerpt',     'force_balance_tags' );
     13add_filter( 'bp_get_the_topic_post_content',            'force_balance_tags' );
     14
     15add_filter( 'bp_get_the_topic_title',                   'wptexturize' );
     16add_filter( 'bp_get_the_topic_poster_name',             'wptexturize' );
     17add_filter( 'bp_get_the_topic_last_poster_name',        'wptexturize' );
     18add_filter( 'bp_get_the_topic_post_content',            'wptexturize' );
     19add_filter( 'bp_get_the_topic_post_poster_name',        'wptexturize' );
     20
     21add_filter( 'bp_get_the_topic_title',                   'convert_smilies' );
     22add_filter( 'bp_get_the_topic_latest_post_excerpt',     'convert_smilies' );
     23add_filter( 'bp_get_the_topic_post_content',            'convert_smilies' );
     24
     25add_filter( 'bp_get_the_topic_title',                   'convert_chars' );
     26add_filter( 'bp_get_the_topic_latest_post_excerpt',     'convert_chars' );
     27add_filter( 'bp_get_the_topic_post_content',            'convert_chars' );
     28
     29add_filter( 'bp_get_the_topic_post_content',            'wpautop' );
     30add_filter( 'bp_get_the_topic_latest_post_excerpt',     'wpautop' );
     31
     32add_filter( 'bp_get_the_topic_post_content',            'stripslashes_deep' );
     33add_filter( 'bp_get_the_topic_title',                   'stripslashes_deep' );
     34add_filter( 'bp_get_the_topic_latest_post_excerpt',     'stripslashes_deep' );
     35add_filter( 'bp_get_the_topic_poster_name',             'stripslashes_deep' );
     36add_filter( 'bp_get_the_topic_last_poster_name',        'stripslashes_deep' );
     37add_filter( 'bp_get_the_topic_object_name',             'stripslashes_deep' );
     38
     39add_filter( 'bp_get_the_topic_post_content',            'make_clickable', 9 );
     40
     41add_filter( 'bp_get_forum_topic_count_for_user',        'bp_core_number_format' );
     42add_filter( 'bp_get_forum_topic_count',                 'bp_core_number_format' );
     43
     44add_filter( 'bp_get_the_topic_title',                   'bp_forums_make_nofollow_filter' );
     45add_filter( 'bp_get_the_topic_latest_post_excerpt',     'bp_forums_make_nofollow_filter' );
     46add_filter( 'bp_get_the_topic_post_content',            'bp_forums_make_nofollow_filter' );
     47
     48// Allow shortcodes in activity posts
     49add_filter( 'bp_get_the_topic_post_content',            'do_shortcode' );
    4750
    4851function bp_forums_filter_kses( $content ) {
    4952        global $allowedtags;
  • buddypress/bp-forums/bp-forums-functions.php

     
    502502add_action( 'bp_forums_new_topic', 'bp_core_clear_cache' );
    503503add_action( 'bp_forums_new_post',  'bp_core_clear_cache' );
    504504
     505/** Embeds *******************************************************************/
     506
     507/**
     508 * Grabs the topic post ID and attempts to retrieve the oEmbed cache (if it exists)
     509 * during the forum topic loop.  If no cache and link is embeddable, cache it.
     510 *
     511 * @see BP_Embed
     512 * @see bp_embed_forum_cache()
     513 * @see bp_embed_forum_save_cache()
     514 * @package BuddyPress_Forums
     515 * @since 1.3
     516 */
     517function bp_forums_embed() {
     518        add_filter( 'embed_post_id',            'bp_get_the_topic_post_id' );
     519        add_filter( 'bp_embed_get_cache',       'bp_embed_forum_cache', 10, 3 );
     520        add_action( 'bp_embed_update_cache',    'bp_embed_forum_save_cache', 10, 3 );
     521}
     522add_action( 'topic_loop_start', 'bp_forums_embed' );
     523
     524        /**
     525         * Wrapper function for {@link bb_get_postmeta()}.
     526         * Used during {@link BP_Embed::parse_oembed()} via {@link bp_forums_embed()}.
     527         *
     528         * @package BuddyPress_Forums
     529         * @since 1.3
     530         */
     531        function bp_embed_forum_cache( $cache, $id, $cachekey ) {
     532                return bb_get_postmeta( $id, $cachekey );
     533        }
     534
     535        /**
     536         * Wrapper function for {@link bb_update_postmeta()}.
     537         * Used during {@link BP_Embed::parse_oembed()} via {@link bp_forums_embed()}.
     538         *
     539         * @package BuddyPress_Forums
     540         * @since 1.3
     541         */
     542        function bp_embed_forum_save_cache( $cache, $cachekey, $id ) {
     543                bb_update_postmeta( $id, $cachekey, $cache );
     544        }
     545
    505546?>