Skip to:
Content

BuddyPress.org

Changeset 4937


Ignore:
Timestamp:
08/06/2011 04:24:46 PM (9 years ago)
Author:
djpaul
Message:

Tweak BP_Embed implementation; fix caching and PHP warning. Fixes #3429, props r-a-y

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-functions.php

    r4907 r4937  
    924924        $activity_obj = $activity_obj->current_comment;
    925925    }
    926    
     926
    927927    if ( 'new_blog_post' == $activity_obj->type || 'new_blog_comment' == $activity_obj->type || 'new_forum_topic' == $activity_obj->type || 'new_forum_post' == $activity_obj->type )
    928928        $link = $activity_obj->primary_link;
     
    995995
    996996/**
    997  * Grabs the activity ID and attempts to retrieve the oEmbed cache (if it exists)
     997 * Grabs the activity update ID and attempts to retrieve the oEmbed cache (if it exists)
    998998 * during the activity loop.  If no cache and link is embeddable, cache it.
     999 *
     1000 * This does not cover recursive activity comments, as they do not use a real loop.
     1001 * For that, see {@link bp_activity_comment_embed()}.
    9991002 *
    10001003 * @see BP_Embed
     
    10121015
    10131016/**
     1017 * Grabs the activity comment ID and attempts to retrieve the oEmbed cache (if it exists)
     1018 * when BP is recursing through activity comments {@link bp_activity_recurse_comments()}.
     1019 * If no cache and link is embeddable, cache it.
     1020 *
     1021 * @see BP_Embed
     1022 * @see bp_embed_activity_cache()
     1023 * @see bp_embed_activity_save_cache()
     1024 * @package BuddyPress Activity
     1025 * @since 1.5
     1026 */
     1027function bp_activity_comment_embed() {
     1028    add_filter( 'embed_post_id',         'bp_get_activity_comment_id'          );
     1029    add_filter( 'bp_embed_get_cache',    'bp_embed_activity_cache',      10, 3 );
     1030    add_action( 'bp_embed_update_cache', 'bp_embed_activity_save_cache', 10, 3 );
     1031}
     1032add_action( 'bp_before_activity_comment', 'bp_activity_comment_embed' );
     1033
     1034/**
     1035 * When a user clicks on a "Read More" item, make sure embeds are correctly parsed and shown for the expanded content.
     1036 *
     1037 * @global object $bp BuddyPress global settings
     1038 * @param BP_Activity_Activity $activity The activity that is being expanded
     1039 * @see BP_Embed
     1040 * @since 1.5
     1041 */
     1042function bp_dtheme_embed_read_more( $activity ) {
     1043    global $bp;
     1044
     1045    $bp->activity->read_more_id = $activity->id;
     1046
     1047    add_filter( 'embed_post_id',            create_function( '', 'global $bp; return $bp->activity->read_more_id;' ) );
     1048    add_filter( 'bp_embed_get_cache',       'bp_embed_activity_cache',      10, 3 );
     1049    add_action( 'bp_embed_update_cache',    'bp_embed_activity_save_cache', 10, 3 );
     1050}
     1051add_action( 'bp_dtheme_get_single_activity_content', 'bp_dtheme_embed_read_more' );
     1052
     1053/**
     1054 * Removes the 'embed_post_id' filter after {@link bp_activity_recurse_comments()}
     1055 * is rendered to avoid conflict with the 'embed_post_id' filter in
     1056 * {@link bp_activity_embed()} or any other component embeds.
     1057 *
     1058 * @see bp_activity_comment_embed()
     1059 * @package BuddyPress Activity
     1060 * @since 1.5
     1061 */
     1062function bp_activity_comment_embed_after_recurse() {
     1063    remove_filter( 'embed_post_id', 'bp_get_activity_comment_id' );
     1064}
     1065add_action( 'bp_after_activity_comment', 'bp_activity_comment_embed_after_recurse' );
     1066
     1067/**
    10141068 * Wrapper function for {@link bp_activity_get_meta()}.
    10151069 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
  • trunk/bp-core/bp-core-classes.php

    r4934 r4937  
    11691169        ksort( $this->handlers );
    11701170        foreach ( $this->handlers as $priority => $handlers ) {
    1171             foreach ( $handlers as $id => $handler ) {
     1171            foreach ( $handlers as $hid => $handler ) {
    11721172                if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
    11731173                    if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
     
    11781178
    11791179        // Get object ID
    1180         $id = apply_filters( 'embed_post_id', $id );
     1180        $id = apply_filters( 'embed_post_id', 0 );
    11811181
    11821182        // Is oEmbed discovery on?
     
    12201220     */
    12211221    function parse_oembed( $id, $url, $attr, $rawattr ) {
     1222        $id = intval( $id );
     1223
    12221224        if ( $id ) {
    12231225            // Setup the cachekey
     
    12301232            // Grab cache and return it if available
    12311233            if ( !empty( $cache ) ) {
    1232                 return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $rawattr );
     1234                return apply_filters( 'bp_embed_oembed_html', $cache, $url, $attr, $rawattr );
    12331235
    12341236            // If no cache, ping the oEmbed provider and cache the result
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r4920 r4937  
    340340        exit(); // todo: error?
    341341
    342     // Activity content retrieved through AJAX should run through normal filters, but not be
    343     // truncated
     342    do_action_ref_array( 'bp_dtheme_get_single_activity_content', array( &$activity ) );
     343
     344    // Activity content retrieved through AJAX should run through normal filters, but not be truncated
    344345    remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
    345346    $content = apply_filters( 'bp_get_activity_content_body', $activity->content );
    346347
    347348    echo $content;
    348 
    349349    exit();
    350350}
Note: See TracChangeset for help on using the changeset viewer.