Skip to:
Content

BuddyPress.org


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs.php

    r2114 r2618  
    11<?php
    22
    3 define ( 'BP_BLOGS_DB_VERSION', '1800' );
     3define ( 'BP_BLOGS_DB_VERSION', '2000' );
    44
    55/* Define the slug for the component */
     
    1010require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-templatetags.php' );
    1111require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-widgets.php' );
    12 
    13 /* Include deprecated functions if settings allow */
    14 if ( !defined( 'BP_IGNORE_DEPRECATED' ) )
    15     require ( BP_PLUGIN_DIR . '/bp-blogs/deprecated/bp-blogs-deprecated.php' );
    1612
    1713function bp_blogs_install() {
     
    6864
    6965    // On first installation - record all existing blogs in the system.
    70     if ( !(int)get_site_option( 'bp-blogs-first-install') ) {
    71 
     66    if ( !(int)get_site_option( 'bp-blogs-first-install') && bp_core_is_multisite() ) {
    7267        bp_blogs_record_existing_blogs();
    7368        add_site_option( 'bp-blogs-first-install', 1 );
    74 
    75     } else {
    76 
    77         // Import blog titles and descriptions into the blogmeta table
    78         if ( get_site_option( 'bp-blogs-version' ) <= '0.1.5' ) {
    79             $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM " . $bp->blogs->table_name ) );
    80 
    81             for ( $i = 0; $i < count($blog_ids); $i++ ) {
    82                 $name = get_blog_option( $blog_ids[$i], 'blogname' );
    83                 $desc = get_blog_option( $blog_ids[$i], 'blogdescription' );
    84 
    85                 bp_blogs_update_blogmeta( $blog_ids[$i], 'name', $name );
    86                 bp_blogs_update_blogmeta( $blog_ids[$i], 'description', $desc );
    87                 bp_blogs_update_blogmeta( $blog_ids[$i], 'last_activity', time() );
    88             }
    89         }
    90 
    9169    }
    9270
     
    9775    global $wpdb, $bp, $userdata;
    9876
    99     if ( is_site_admin() ) {
     77    if ( is_site_admin() && bp_core_is_multisite() ) {
    10078        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
    10179        if ( get_site_option('bp-blogs-db-version') < BP_BLOGS_DB_VERSION )
     
    139117 * @package BuddyPress Blogs
    140118 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    141  * @uses bp_is_home() Checks to see if the current user being viewed is the logged in user
     119 * @uses bp_is_my_profile() Checks to see if the current user being viewed is the logged in user
    142120 */
    143121function bp_blogs_setup_nav() {
    144122    global $bp;
    145123
     124    /* Blog/post/comment menus should not appear on single WordPress setups. Although comments
     125       and posts made by users will still show on their activity stream .*/
     126    if ( !bp_core_is_multisite() )
     127        return false;
     128
    146129    /* Add 'Blogs' to the main navigation */
    147     bp_core_new_nav_item( array( 'name' => __( 'Blogs', 'buddypress' ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );
     130    bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs <span>(%d)</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );
    148131
    149132    $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/';
     
    153136    bp_core_new_subnav_item( array( 'name' => __( 'Recent Posts', 'buddypress' ), 'slug' => 'recent-posts', 'parent_url' => $blogs_link, 'parent_slug' => $bp->blogs->slug, 'screen_function' => 'bp_blogs_screen_recent_posts', 'position' => 20 ) );
    154137    bp_core_new_subnav_item( array( 'name' => __( 'Recent Comments', 'buddypress' ), 'slug' => 'recent-comments', 'parent_url' => $blogs_link, 'parent_slug' => $bp->blogs->slug, 'screen_function' => 'bp_blogs_screen_recent_comments', 'position' => 30 ) );
    155     bp_core_new_subnav_item( array( 'name' => __( 'Create a Blog', 'buddypress' ), 'slug' => 'create-a-blog', 'parent_url' => $blogs_link, 'parent_slug' => $bp->blogs->slug, 'screen_function' => 'bp_blogs_screen_create_a_blog', 'position' => 40 ) );
    156138
    157139    /* Set up the component options navigation for Blog */
    158140    if ( 'blogs' == $bp->current_component ) {
    159         if ( bp_is_home() ) {
     141        if ( bp_is_my_profile() ) {
    160142            if ( function_exists('xprofile_setup_nav') ) {
    161143                $bp->bp_options_title = __('My Blogs', 'buddypress');
     
    176158    global $bp;
    177159
    178     if ( $bp->current_component == $bp->blogs->slug && empty( $bp->current_action ) ) {
     160    if ( bp_core_is_multisite() && $bp->current_component == $bp->blogs->slug && empty( $bp->current_action ) ) {
    179161        $bp->is_directory = true;
    180162
    181163        do_action( 'bp_blogs_directory_blogs_setup' );
    182         bp_core_load_template( apply_filters( 'bp_blogs_template_directory_blogs_setup', 'directories/blogs/index' ) );
     164        bp_core_load_template( apply_filters( 'bp_blogs_template_directory_blogs_setup', 'blogs/index' ) );
    183165    }
    184166}
     
    195177
    196178function bp_blogs_screen_my_blogs() {
     179    global $bp;
     180
     181    if ( !bp_core_is_multisite() )
     182        return false;
     183
    197184    do_action( 'bp_blogs_screen_my_blogs' );
    198     bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'blogs/my-blogs' ) );
     185    bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
    199186}
    200187
    201188function bp_blogs_screen_recent_posts() {
    202189    do_action( 'bp_blogs_screen_recent_posts' );
    203     bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'blogs/recent-posts' ) );
     190    bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'members/single/home' ) );
    204191}
    205192
    206193function bp_blogs_screen_recent_comments() {
    207194    do_action( 'bp_blogs_screen_recent_comments' );
    208     bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'blogs/recent-comments' ) );
     195    bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'members/single/home' ) );
    209196}
    210197
    211198function bp_blogs_screen_create_a_blog() {
     199    global $bp;
     200
     201    if ( !bp_core_is_multisite() || $bp->current_component != $bp->blogs->slug || 'create' != $bp->current_action )
     202        return false;
     203
     204    if ( !is_user_logged_in() || !bp_blog_signup_enabled() )
     205        return false;
     206
    212207    do_action( 'bp_blogs_screen_create_a_blog' );
    213208    bp_core_load_template( apply_filters( 'bp_blogs_template_create_a_blog', 'blogs/create' ) );
    214209}
     210/* The create screen is not attached to a nav item, so we need to attach it to an action */
     211add_action( 'wp', 'bp_blogs_screen_create_a_blog', 3 );
    215212
    216213
     
    249246    $defaults = array(
    250247        'user_id' => $bp->loggedin_user->id,
    251         'content' => false,
    252         'primary_link' => false,
    253         'component_name' => $bp->blogs->id,
    254         'component_action' => false,
     248        'action' => '',
     249        'content' => '',
     250        'primary_link' => '',
     251        'component' => $bp->blogs->id,
     252        'type' => false,
    255253        'item_id' => false,
    256254        'secondary_item_id' => false,
    257         'recorded_time' => time(),
     255        'recorded_time' => gmdate( "Y-m-d H:i:s" ),
    258256        'hide_sitewide' => false
    259257    );
     
    262260    extract( $r, EXTR_SKIP );
    263261
    264     return bp_activity_add( array( 'user_id' => $user_id, 'content' => $content, 'primary_link' => $primary_link, 'component_name' => $component_name, 'component_action' => $component_action, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
     262    /* Remove large images and replace them with just one image thumbnail */
     263    if ( function_exists( 'bp_activity_thumbnail_content_images' ) && !empty( $content ) )
     264        $content = bp_activity_thumbnail_content_images( $content );
     265
     266    if ( !empty( $action ) )
     267        $action = apply_filters( 'bp_blogs_record_activity_action', $action );
     268
     269    if ( !empty( $content ) )
     270        $content = apply_filters( 'bp_blogs_record_activity_content', "<blockquote>" . bp_create_excerpt( $content ) . "</blockquote>" );
     271
     272    /* Check for an existing entry and update if one exists. */
     273    $id = bp_activity_get_activity_id( array(
     274        'user_id' => $user_id,
     275        'component' => $component,
     276        'type' => $type,
     277        'item_id' => $item_id,
     278        'secondary_item_id' => $secondary_item_id
     279    ) );
     280
     281    return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
    265282}
    266283
    267284function bp_blogs_delete_activity( $args = true ) {
     285    global $bp;
     286
    268287    if ( function_exists('bp_activity_delete_by_item_id') ) {
    269         extract($args);
     288        $defaults = array(
     289            'item_id' => false,
     290            'component' => $bp->blogs->id,
     291            'type' => false,
     292            'user_id' => false,
     293            'secondary_item_id' => false
     294        );
     295
     296        $params = wp_parse_args( $args, $defaults );
     297        extract( $params, EXTR_SKIP );
    270298
    271299        bp_activity_delete_by_item_id( array(
    272300            'item_id' => $item_id,
    273             'component_name' => $component_name,
    274             'component_action' => $component_action,
     301            'component' => $component,
     302            'type' => $type,
    275303            'user_id' => $user_id,
    276304            'secondary_item_id' => $secondary_item_id
     
    294322
    295323    if ( $blog_ids ) {
    296         foreach( $blog_ids as $blog_id ) {
     324        foreach( (array)$blog_ids as $blog_id ) {
    297325            $users = get_users_of_blog( $blog_id );
    298326
    299327            if ( $users ) {
    300                 foreach ( $users as $user ) {
     328                foreach ( (array)$users as $user ) {
    301329                    $role = unserialize( $user->meta_value );
    302330
    303331                    if ( !isset( $role['subscriber'] ) )
    304                         bp_blogs_record_blog( $blog_id, $user->user_id );
     332                        bp_blogs_record_blog( $blog_id, $user->user_id, true );
    305333                }
    306334            }
     
    309337}
    310338
    311 function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = true ) {
     339function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
    312340    global $bp;
    313341
     
    326354    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
    327355    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
    328     bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', time() );
     356    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
    329357
    330358    /* Only record this activity if the blog is public */
    331     if ( (int)$_POST['blog_public'] || !$no_activity ) {
     359    if ( (int)$_POST['blog_public'] && !$no_activity ) {
    332360        /* Record this in activity streams */
    333361        bp_blogs_record_activity( array(
    334362            'user_id' => $recorded_blog->user_id,
    335             'content' => apply_filters( 'bp_blogs_activity_created_blog', sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ), &$recorded_blog, $name, $description ),
     363            'action' => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ), &$recorded_blog, $name, $description ),
    336364            'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_blog_option( $recorded_blog->blog_id, 'siteurl' ), $recorded_blog->blog_id ),
    337             'component_action' => 'new_blog',
     365            'type' => 'new_blog',
    338366            'item_id' => $recorded_blog->blog_id
    339367        ) );
     
    364392        if ( 'publish' == $post->post_status && '' == $post->post_password ) {
    365393
    366             $recorded_post = new BP_Blogs_Post;
    367             $recorded_post->user_id = $user_id;
    368             $recorded_post->blog_id = $blog_id;
    369             $recorded_post->post_id = $post_id;
    370             $recorded_post->date_created = strtotime( $post->post_date );
    371 
    372             $recorded_post_id = $recorded_post->save();
    373 
    374             bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', time() );
    375 
    376             if ( (int)get_blog_option( $blog_id, 'blog_public' ) ) {
     394            /* If we're on a multiblog install, record this post */
     395            if ( bp_core_is_multisite() ) {
     396                $recorded_post = new BP_Blogs_Post;
     397                $recorded_post->user_id = $user_id;
     398                $recorded_post->blog_id = $blog_id;
     399                $recorded_post->post_id = $post_id;
     400                $recorded_post->date_created = strtotime( $post->post_date );
     401
     402                $recorded_post_id = $recorded_post->save();
     403
     404                bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     405            }
     406
     407            if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    377408                /* Record this in activity streams */
    378409                $post_permalink = bp_post_get_permalink( $post, $blog_id );
    379410
    380                 $activity_content = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
    381                 $activity_content .= "<blockquote>" . bp_create_excerpt( $post->post_content ) . "</blockquote>";
     411                $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
     412                $activity_content = $post->post_content;
    382413
    383414                bp_blogs_record_activity( array(
    384415                    'user_id' => (int)$post->post_author,
    385                     'content' => apply_filters( 'bp_blogs_activity_new_post', $activity_content, &$post, $post_permalink ),
     416                    'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
     417                    'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
    386418                    'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
    387                     'component_action' => 'new_blog_post',
    388                     'item_id' => $recorded_post_id,
    389                     'recorded_time' => strtotime( $post->post_date )
     419                    'type' => 'new_blog_post',
     420                    'item_id' => $blog_id,
     421                    'secondary_item_id' => $post_id,
     422                    'recorded_time' => $post->post_date_gmt
    390423                ));
    391424            }
     
    394427        $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
    395428
    396         /* Delete and the activity stream item as we are probably going to re-add it later with new info. */
    397         bp_blogs_delete_activity( array( 'item_id' => $existing_post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post' ) );
    398 
    399429        /* Delete the recorded post if the status is not published or it is password protected */
    400430        if ( 'publish' != $post->post_status || '' != $post->post_password ) {
     
    410440        }
    411441
    412         if ( (int)get_blog_option( $blog_id, 'blog_public' ) ) {
     442        if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    413443            /* Now re-record the post in the activity streams */
    414444            $post_permalink = bp_post_get_permalink( $post, $blog_id );
    415445
    416             $activity_content = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
    417             $activity_content .= "<blockquote>" . bp_create_excerpt( $post->post_content ) . "</blockquote>";
    418 
    419             /* Record this in activity streams */
     446            $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
     447            $activity_content = $post->post_content;
     448
    420449            bp_blogs_record_activity( array(
    421450                'user_id' => (int)$post->post_author,
    422                 'content' => apply_filters( 'bp_blogs_activity_new_post', $activity_content, &$post, $post_permalink ),
     451                'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
     452                'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
    423453                'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
    424                 'component_action' => 'new_blog_post',
    425                 'item_id' => $existing_post->id,
    426                 'recorded_time' => strtotime( $post->post_date )
     454                'type' => 'new_blog_post',
     455                'item_id' => $blog_id,
     456                'secondary_item_id' => $post_id,
     457                'recorded_time' => $post->post_date_gmt
    427458            ) );
    428459        }
     
    449480        return false;
    450481
    451     $recorded_comment = new BP_Blogs_Comment;
    452     $recorded_comment->user_id = $user_id;
    453     $recorded_comment->blog_id = $wpdb->blogid;
    454     $recorded_comment->comment_id = $comment_id;
    455     $recorded_comment->comment_post_id = $comment->comment_post_ID;
    456     $recorded_comment->date_created = strtotime( $comment->comment_date );
    457 
    458     $recorded_commment_id = $recorded_comment->save();
    459 
    460     bp_blogs_update_blogmeta( $recorded_comment->blog_id, 'last_activity', time() );
    461 
    462     if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) ) {
     482    /* If this is a password protected post, don't record the comment */
     483    if ( !empty( $post->post_password ) )
     484        return false;
     485
     486    /* If we're on a multiblog install, record this post */
     487    if ( bp_core_is_multisite() ) {
     488        $recorded_comment = new BP_Blogs_Comment;
     489        $recorded_comment->user_id = $user_id;
     490        $recorded_comment->blog_id = $wpdb->blogid;
     491        $recorded_comment->comment_id = $comment_id;
     492        $recorded_comment->comment_post_id = $comment->comment_post_ID;
     493        $recorded_comment->date_created = strtotime( $comment->comment_date_gmt );
     494
     495        $recorded_commment_id = $recorded_comment->save();
     496
     497        bp_blogs_update_blogmeta( $recorded_comment->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     498    }
     499
     500    if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
    463501        /* Record in activity streams */
    464         $comment_link = bp_post_get_permalink( $comment->post, $recorded_comment->blog_id );
    465         $activity_content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' );
    466         $activity_content .= '<blockquote>' . bp_create_excerpt( $comment->comment_content ) . '</blockquote>';
     502        $comment_link = bp_post_get_permalink( $comment->post, $wpdb->blogid ) . '#comment-' . $comment_id;
     503        $activity_action = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' );
     504        $activity_content = $comment->comment_content;
    467505
    468506        /* Record this in activity streams */
    469507        bp_blogs_record_activity( array(
    470             'user_id' => $recorded_comment->user_id,
    471             'content' => apply_filters( 'bp_blogs_activity_new_comment', $activity_content, &$comment, &$recorded_comment, $comment_link ),
     508            'user_id' => $user_id,
     509            'action' => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$comment, &$recorded_comment, $comment_link ),
     510            'content' => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$comment, &$recorded_comment, $comment_link ),
    472511            'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$comment, &$recorded_comment ),
    473             'component_action' => 'new_blog_comment',
    474             'item_id' => $comment_id,
    475             'secondary_item_id' => $recorded_comment->blog_id,
    476             'recorded_time' =>  $recorded_comment->date_created
     512            'type' => 'new_blog_comment',
     513            'item_id' => $wpdb->blogid,
     514            'secondary_item_id' => $comment_id,
     515            'recorded_time' => $comment->comment_date_gmt
    477516        ) );
    478517    }
     
    482521add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
    483522
    484 function bp_blogs_approve_comment( $comment_id, $comment_status ) {
    485     global $bp, $wpdb;
    486 
    487     if ( 'approve' != $comment_status )
    488         return false;
    489 
    490     $recorded_comment = bp_blogs_record_comment( $comment_id, true );
    491     $comment = get_comment($comment_id);
    492     $comment->post = get_post( $comment->comment_post_ID );
    493 
    494     bp_blogs_delete_activity( array( 'item_id' => $comment_id, 'secondary_item_id' => $recorded_comment->blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_comment' ) );
    495 
    496     if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) ) {
    497         /* Record in activity streams */
    498         $comment_link = bp_post_get_permalink( $comment->post, $recorded_comment->blog_id );
    499         $activity_content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $recorded_comment->user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' );
    500         $activity_content .= '<blockquote>' . bp_create_excerpt( $comment->comment_content ) . '</blockquote>';
    501 
    502         /* Record this in activity streams */
    503         bp_blogs_record_activity( array(
    504             'user_id' => $recorded_comment->user_id,
    505             'content' => apply_filters( 'bp_blogs_activity_new_comment', $activity_content, &$comment, &$recorded_comment, $comment_link ),
    506             'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$comment, &$recorded_comment ),
    507             'component_action' => 'new_blog_comment',
    508             'item_id' => $comment_id,
    509             'secondary_item_id' => $recorded_comment->blog_id,
    510             'recorded_time' =>  $recorded_comment->date_created
    511         ) );
    512     }
    513 }
    514 add_action( 'wp_set_comment_status', 'bp_blogs_approve_comment', 10, 2 );
    515 
    516 function bp_blogs_unapprove_comment( $comment_id, $comment_status ) {
    517     if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status )
    518         bp_blogs_remove_comment( $comment_id );
    519 }
    520 add_action( 'wp_set_comment_status', 'bp_blogs_unapprove_comment', 10, 2 );
     523function bp_blogs_manage_comment( $comment_id, $comment_status ) {
     524    if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status )
     525        return bp_blogs_remove_comment( $comment_id );
     526
     527    return bp_blogs_record_comment( $comment_id, true );
     528}
     529add_action( 'wp_set_comment_status', 'bp_blogs_manage_comment', 10, 2 );
    521530
    522531function bp_blogs_add_user_to_blog( $user_id, $role, $blog_id ) {
    523532    if ( $role != 'subscriber' ) {
    524         bp_blogs_record_blog( $blog_id, $user_id );
     533        bp_blogs_record_blog( $blog_id, $user_id, true );
    525534    }
    526535}
     
    540549
    541550    // Delete activity stream item
    542     bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog' ) );
     551    bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog' ) );
    543552
    544553    do_action( 'bp_blogs_remove_blog', $blog_id );
     
    555564
    556565    // Delete activity stream item
    557     bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog' ) );
     566    bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog' ) );
    558567
    559568    do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id );
     
    576585
    577586    // Delete activity stream item
    578     bp_blogs_delete_activity( array( 'item_id' => $existing_post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post' ) );
     587    bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid, 'component' => $existing_post->id, 'type' => 'new_blog_post' ) );
    579588
    580589    do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $post->user_id );
     
    589598
    590599    // Delete activity stream item
    591     bp_blogs_delete_activity( array( 'item_id' => $comment_id, 'secondary_item_id' => $recorded_comment->blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_comment' ) );
     600    bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid, 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
    592601
    593602    do_action( 'bp_blogs_remove_comment', $blog_id, $comment_id, $bp->loggedin_user->id );
    594603}
    595604add_action( 'delete_comment', 'bp_blogs_remove_comment' );
     605
     606function bp_blogs_total_blogs() {
     607    if ( !$count = wp_cache_get( 'bp_total_blogs', 'bp' ) ) {
     608        $blogs = BP_Blogs_Blog::get_all();
     609        $count = $blogs['total'];
     610        wp_cache_set( 'bp_total_blogs', $count, 'bp' );
     611    }
     612    return $count;
     613}
     614
     615function bp_blogs_total_blogs_for_user( $user_id = false ) {
     616    global $bp;
     617
     618    if ( !$user_id )
     619        $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
     620
     621    if ( !$count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) {
     622        $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
     623        wp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' );
     624    }
     625
     626    return $count;
     627}
    596628
    597629function bp_blogs_remove_data_for_blog( $blog_id ) {
     
    604636
    605637    // Delete activity stream item
    606     bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => false ) );
     638    bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => false ) );
    607639
    608640    do_action( 'bp_blogs_remove_data_for_blog', $blog_id );
     
    610642add_action( 'delete_blog', 'bp_blogs_remove_data_for_blog', 1 );
    611643
    612 function bp_blogs_get_blogs_for_user( $user_id ) {
    613     return BP_Blogs_Blog::get_blogs_for_user( $user_id );
     644function bp_blogs_get_blogs_for_user( $user_id, $show_hidden = false ) {
     645    return BP_Blogs_Blog::get_blogs_for_user( $user_id, $show_hidden );
    614646}
    615647
     
    635667}
    636668
    637 function bp_blogs_get_random_blog( $limit = null, $page = null ) {
    638     return BP_Blogs_Blog::get_random( $limit, $page );
     669function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
     670    return BP_Blogs_Blog::get( 'random', $limit, $page );
    639671}
    640672
     
    659691
    660692    if ( $bp->current_component == $bp->blogs->slug && isset( $_GET['random-blog'] ) ) {
    661         $blog = bp_blogs_get_random_blog();
     693        $blog = bp_blogs_get_random_blogs( 1, 1 );
    662694
    663695        bp_core_redirect( get_blog_option( $blog['blogs'][0]->blog_id, 'siteurl') );
     
    695727    }
    696728
    697     // TODO need to look into using this.
    698     // wp_cache_delete($group_id, 'groups');
     729    wp_cache_delete( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' );
    699730
    700731    return true;
     
    712743        $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
    713744
    714         // TODO need to look into using this.
    715         //$user = wp_cache_get($user_id, 'users');
    716 
    717         // Check the cached user object
    718         //if ( false !== $user && isset($user->$meta_key) )
    719         //  $metas = array($user->$meta_key);
    720         //else
    721         $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key) );
     745        if ( !$metas = wp_cache_get( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' ) ) {
     746            $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
     747            wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $metas, 'bp' );
     748        }
    722749    } else {
    723750        $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id) );
     
    766793    }
    767794
    768     // TODO need to look into using this.
    769     // wp_cache_delete($user_id, 'users');
     795    wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $metas, 'bp' );
    770796
    771797    return true;
    772798}
     799
     800/**
     801 * bp_blogs_filter_template_paths()
     802 *
     803 * Add fallback for the bp-sn-parent theme template locations used in BuddyPress versions
     804 * older than 1.2.
     805 *
     806 * @package BuddyPress Core
     807 */
     808function bp_blogs_filter_template_paths() {
     809    if ( 'bp-sn-parent' != basename( TEMPLATEPATH ) && !defined( 'BP_CLASSIC_TEMPLATE_STRUCTURE' ) )
     810        return false;
     811
     812    add_filter( 'bp_blogs_template_directory_blogs_setup', create_function( '', 'return "directories/blogs/index";' ) );
     813    add_filter( 'bp_blogs_template_my_blogs', create_function( '', 'return "blogs/my-blogs";' ) );
     814    add_filter( 'bp_blogs_template_recent_posts', create_function( '', 'return "blogs/recent-posts";' ) );
     815    add_filter( 'bp_blogs_template_recent_comments', create_function( '', 'return "blogs/recent-comments";' ) );
     816    add_filter( 'bp_blogs_template_create_a_blog', create_function( '', 'return "blogs/create";' ) );
     817}
     818add_action( 'init', 'bp_blogs_filter_template_paths' );
    773819
    774820function bp_blogs_remove_data( $user_id ) {
     
    786832    wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' );
    787833    wp_cache_delete( 'bp_blogs_for_user_' . $user_id, 'bp' );
     834    wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
    788835
    789836    /* Clear the sitewide activity cache */
     
    796843    /* Clear the sitewide activity cache */
    797844    wp_cache_delete( 'sitewide_activity', 'bp' );
     845    wp_cache_delete( 'bp_total_blogs', 'bp' );
    798846}
    799847
Note: See TracChangeset for help on using the changeset viewer.