Skip to:
Content

BuddyPress.org

Ticket #5130: 5130.04.patch

File 5130.04.patch, 44.1 KB (added by r-a-y, 12 years ago)
  • bp-activity/admin/css/admin.css

     
    7575#bp-activities-primaryid {
    7676        margin-bottom: 1em;
    7777}
     78.column-action {
     79        width: 12%;
     80}
     81 No newline at end of file
  • bp-activity/admin/css/admin.min.css

     
    1 .akismet-status{float:right}.akismet-status a{color:#AAA;font-style:italic}.akismet-history{margin:13px}.akismet-history div{margin-bottom:13px}.akismet-history span{color:#999}#wp-bp-activities-wrap{padding:5px 0}#bp-activities{height:120px}#bp-replyhead{font-size:1em;line-height:1.4em;margin:0}#bp-replysubmit{margin:0;padding:0 0 3px;text-align:center}#bp-replysubmit .error{color:red;line-height:21px;text-align:center;vertical-align:center}#bp-replysubmit img.waiting{float:right;padding:4px 10px 0;vertical-align:top}#bp-activities-form .column-response img{float:left;margin-right:10px;margin-top:1px}.activity-errors{list-style-type:disc;margin-left:2em}#bp_activity_action div.inside,#bp_activity_content div.inside{line-height:0}#bp_activity_action h3,#bp_activity_content h3{cursor:auto}#bp_activity_action td.mceIframeContainer,#bp_activity_content td.mceIframeContainer{background-color:white}#post-body #bp-activities-action_resize,#post-body #bp-activities-content_resize{position:inherit;margin-top:-2px}#bp_activity_link input{width:99%}#bp-activities-primaryid{margin-bottom:1em}
    2  No newline at end of file
     1.akismet-status{float:right}.akismet-status a{color:#AAA;font-style:italic}.akismet-history{margin:13px}.akismet-history div{margin-bottom:13px}.akismet-history span{color:#999}#wp-bp-activities-wrap{padding:5px 0}#bp-activities{height:120px}#bp-replyhead{font-size:1em;line-height:1.4em;margin:0}#bp-replysubmit{margin:0;padding:0 0 3px;text-align:center}#bp-replysubmit .error{color:red;line-height:21px;text-align:center;vertical-align:center}#bp-replysubmit img.waiting{float:right;padding:4px 10px 0;vertical-align:top}#bp-activities-form .column-response img{float:left;margin-right:10px;margin-top:1px}.activity-errors{list-style-type:disc;margin-left:2em}#bp_activity_action div.inside,#bp_activity_content div.inside{line-height:0}#bp_activity_action h3,#bp_activity_content h3{cursor:auto}#bp_activity_action td.mceIframeContainer,#bp_activity_content td.mceIframeContainer{background-color:white}#post-body #bp-activities-action_resize,#post-body #bp-activities-content_resize{position:inherit;margin-top:-2px}#bp_activity_link input{width:99%}#bp-activities-primaryid{margin-bottom:1em}.column-action{width:12%}
     2 No newline at end of file
  • bp-activity/bp-activity-admin.php

     
    458458
    459459                // Activity type
    460460                if ( ! empty( $_POST['bp-activities-type'] ) ) {
    461                         $actions  = array();
    462 
    463                         // Walk through the registered actions, and build an array of actions/values.
    464                         foreach ( $bp->activity->actions as $action ) {
    465                                 $action = array_values( (array) $action );
    466 
    467                                 for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ )
    468                                         $actions[] = $action[$i]['key'];
    469                         }
    470 
    471                         // This was a mis-named activity type from before BP 1.6
    472                         unset( $actions['friends_register_activity_action'] );
     461                        $actions = bp_activity_admin_get_activity_actions();
    473462
    474463                        // Check that the new type is a registered activity type
    475                         if ( in_array( $_POST['bp-activities-type'], $actions ) )
     464                        if ( in_array( $_POST['bp-activities-type'], $actions ) ) {
    476465                                $activity->type = $_POST['bp-activities-type'];
     466                        }
    477467                }
    478468
    479469                // Activity timestamp
     
    736726}
    737727
    738728/**
    739  * Activity type metabox for the Activity admin edit screen
     729 * Get flattened array of all registered activity actions.
    740730 *
    741  * @since BuddyPress (1.6.0)
     731 * Format is [activity_type] => Pretty name for activity type.
    742732 *
    743  * @global object $bp BuddyPress global settings.
     733 * @since BuddyPress (2.0.0)
    744734 *
    745  * @param object $item Activity item.
     735 * @return array
    746736 */
    747 function bp_activity_admin_edit_metabox_type( $item ) {
    748         global $bp;
    749 
     737function bp_activity_admin_get_activity_actions() {
    750738        $actions  = array();
    751         $selected = $item->type;
    752739
    753740        // Walk through the registered actions, and build an array of actions/values.
    754         foreach ( $bp->activity->actions as $action ) {
     741        foreach ( buddypress()->activity->actions as $action ) {
    755742                $action = array_values( (array) $action );
    756743
    757                 for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ )
     744                for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) {
    758745                        $actions[ $action[$i]['key'] ] = $action[$i]['value'];
     746                }
    759747        }
    760748
    761749        // This was a mis-named activity type from before BP 1.6
     
    764752        // Sort array by the human-readable value
    765753        natsort( $actions );
    766754
     755        return $actions;
     756}
     757
     758/**
     759 * Activity type metabox for the Activity admin edit screen
     760 *
     761 * @since BuddyPress (1.6.0)
     762 *
     763 * @global object $bp BuddyPress global settings.
     764 *
     765 * @param object $item Activity item.
     766 */
     767function bp_activity_admin_edit_metabox_type( $item ) {
     768        $actions  = bp_activity_admin_get_activity_actions();
     769        $selected = $item->type;
     770
    767771        // If the activity type is not registered properly (eg, a plugin has
    768772        // not called bp_activity_set_action()), add the raw type to the end
    769773        // of the list
     
    974978         */
    975979        public function __construct() {
    976980
     981                // See if activity commenting is enabled for blog / forum activity items
     982                $this->disable_blogforum_comments = bp_disable_blogforum_comments();
     983
    977984                // Define singular and plural labels, as well as whether we support AJAX.
    978985                parent::__construct( array(
    979986                        'ajax'     => false,
     
    12171224                        'cb'       => '<input name type="checkbox" />',
    12181225                        'author'   => __( 'Author', 'buddypress' ),
    12191226                        'comment'  => __( 'Activity', 'buddypress' ),
     1227                        'action'   => __( 'Action', 'buddypress' ),
    12201228                        'response' => __( 'In Response To', 'buddypress' ),
    12211229                );
    12221230        }
     
    13001308        }
    13011309
    13021310        /**
     1311         * Action column markup.
     1312         *
     1313         * @since BuddyPress (2.0.0)
     1314         *
     1315         * @see WP_List_Table::single_row_columns()
     1316         *
     1317         * @param array $item A singular item (one full row).
     1318         */
     1319        function column_action( $item ) {
     1320                $actions = bp_activity_admin_get_activity_actions();
     1321
     1322                if ( isset( $actions[ $item['type'] ] ) ) {
     1323                        echo $actions[ $item['type'] ];
     1324                } else {
     1325                        printf( __( 'Unregistered action - %s', 'buddypress' ), $item['type'] );
     1326                }
     1327        }
     1328
     1329        /**
    13031330         * Content column, and "quick admin" rollover actions.
    13041331         *
    13051332         * Called "comment" in the CSS so we can re-use some WP core CSS.
     
    13381365
    13391366                // Reply - javascript only; implemented by AJAX.
    13401367                if ( 'spam' != $item_status ) {
    1341                         $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', __( 'Reply', 'buddypress' ) );
     1368                        if ( $this->can_comment( $item ) ) {
     1369                                $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', __( 'Reply', 'buddypress' ) );
     1370                        } else {
     1371                                $actions['reply'] = sprintf( '<span class="form-input-tip" title="%s">%s</span>', __( 'Replies are disabled for this activity item', 'buddypress' ), __( 'Replies disabled', 'buddypress' ) );
     1372                        }
    13421373
    13431374                        // Edit
    13441375                        $actions['edit'] = sprintf( '<a href="%s">%s</a>', $edit_url, __( 'Edit', 'buddypress' ) );
     
    14451476        }
    14461477
    14471478        /**
     1479         * Checks if an activity item can be replied to.
     1480         *
     1481         * This method merges functionality from {@link bp_activity_can_comment()} and
     1482         * {@link bp_blogs_disable_activity_commenting()}.  This is done because the activity
     1483         * list table doesn't use a BuddyPress activity loop, which prevents those
     1484         * functions from working as intended.
     1485         *
     1486         * @since BuddyPress (2.0.0)
     1487         *
     1488         * @param array $item An array version of the BP_Activity_Activity object.
     1489         * @return bool
     1490         */
     1491        protected function can_comment( $item  ) {
     1492                $can_comment = true;
     1493
     1494                if ( $this->disable_blogforum_comments ) {
     1495                        switch ( $item['type'] ) {
     1496                                case 'new_blog_post' :
     1497                                case 'new_blog_comment' :
     1498                                case 'new_forum_topic' :
     1499                                case 'new_forum_post' :
     1500                                        $can_comment = false;
     1501                                        break;
     1502                        }
     1503
     1504                // activity comments require special checking
     1505                } elseif ( 'activity_comment' == $item['type'] ) {
     1506                        // blogs
     1507                        if ( bp_is_active( 'blogs' ) ) {
     1508                                // grab the parent activity entry
     1509                                $parent_activity = new BP_Activity_Activity( $item['item_id'] );
     1510
     1511                                // fetch blog post comment depth and if the blog post's comments are open
     1512                                bp_blogs_setup_activity_loop_globals( $parent_activity );
     1513
     1514                                // check if the activity item can be replied to
     1515                                if ( false === bp_blogs_can_comment_reply( true, $item ) ) {
     1516                                        $can_comment = false;
     1517                                }
     1518                        }
     1519                }
     1520
     1521                return apply_filters( 'bp_activity_list_table_can_comment', $can_comment );
     1522        }
     1523
     1524        /**
    14481525         * Flatten the activity array.
    14491526         *
    14501527         * In some cases, BuddyPress gives us a structured tree of activity
  • bp-activity/bp-activity-functions.php

     
    15221522         * You may want to hook into this filter if you want to override this function and
    15231523         * handle the deletion of child comments differently. Make sure you return false.
    15241524         */
    1525         if ( !apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) )
    1526                 return false;
     1525        if ( ! apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) ) {
     1526                return true;
     1527        }
    15271528
    15281529        // Delete any children of this comment.
    15291530        bp_activity_delete_children( $activity_id, $comment_id );
  • bp-activity/bp-activity-template.php

     
    29722972        }
    29732973
    29742974/**
     2975 * Recurse through all activity comments and return the activity comment IDs.
     2976 *
     2977 * @since BuddyPress (2.0.0)
     2978 *
     2979 * @param array $activity Array of activities generated from {@link bp_activity_get()}.
     2980 * @return array
     2981 */
     2982function bp_activity_recurse_comments_activity_ids( $activity = array(), $activity_ids = array() ) {
     2983        if ( is_array( $activity ) && ! empty( $activity['activities'] ) ) {
     2984                $activity = $activity['activities'][0];
     2985        }
     2986
     2987        if ( ! empty( $activity->children ) ) {
     2988                foreach ($activity->children as $child ) {
     2989                        $activity_ids[] = $child->id;
     2990
     2991                        if( ! empty( $child->children ) ) {
     2992                                $activity_ids = bp_activity_recurse_comments_activity_ids( $child, $activity_ids );
     2993                        }
     2994                }
     2995        }
     2996
     2997        return $activity_ids;
     2998}
     2999
     3000/**
    29753001 * Output the mentionname for the displayed user.
    29763002 *
    29773003 * @since BuddyPress (1.9.0)
  • bp-blogs/bp-blogs-activity.php

     
    345345                'secondary_item_id' => $secondary_item_id
    346346        ) );
    347347}
     348
     349/**
     350 * Check if a blog post's activity item should be closed from commenting.
     351 *
     352 * This mirrors the {@link comments_open()} and {@link _close_comments_for_old_post()}
     353 * functions, but for use with the BuddyPress activity stream to be as
     354 * lightweight as possible.
     355 *
     356 * By lightweight, we actually mirror a few of the blog's commenting settings
     357 * to blogmeta and checks the values in blogmeta instead.  This is to prevent
     358 * multiple {@link switch_to_blog()} calls in the activity stream.
     359 *
     360 * @param object $activity The BP_Activity_Activity object
     361 * @return bool
     362 */
     363function bp_blogs_comments_open( $activity ) {
     364        $open = true;
     365
     366        $blog_id = $activity->item_id;
     367
     368        // see if we've mirrored the close comments option before
     369        $days_old = bp_blogs_get_blogmeta( $blog_id, 'close_comments_days_old' );
     370
     371        // we've never cached these items before, so do it now
     372        if ( '' === $days_old ) {
     373                switch_to_blog( $blog_id );
     374
     375                // use comments_open()
     376                remove_filter( 'comments_open', 'bp_comments_open', 10, 2 );
     377                $open = comments_open( $activity->secondary_item_id );
     378                add_filter( 'comments_open', 'bp_comments_open', 10, 2 );
     379
     380                // might as well mirror values to blogmeta since we're here!
     381                $thread_depth = get_option( 'thread_comments' );
     382                if ( ! empty( $thread_depth ) ) {
     383                        $thread_depth = get_option( 'thread_comments_depth' );
     384                } else {
     385                        // perhaps filter this?
     386                        $thread_depth = 1;
     387                }
     388
     389                bp_blogs_update_blogmeta( $blog_id, 'close_comments_for_old_posts', get_option( 'close_comments_for_old_posts' ) );
     390                bp_blogs_update_blogmeta( $blog_id, 'close_comments_days_old',      get_option( 'close_comments_days_old' ) );
     391                bp_blogs_update_blogmeta( $blog_id, 'thread_comments_depth',        $thread_depth );
     392
     393                restore_current_blog();
     394
     395        // check blogmeta and manually check activity item
     396        // basically a copy of _close_comments_for_old_post()
     397        } else {
     398
     399                if ( ! bp_blogs_get_blogmeta( $blog_id, 'close_comments_for_old_posts' ) ) {
     400                        return $open;
     401                }
     402
     403                $days_old = (int) $days_old;
     404                if ( ! $days_old ) {
     405                        return $open;
     406                }
     407
     408                /* commenting out for now - needs some more thought...
     409                   should we add the post type to activity meta?
     410
     411                $post = get_post($post_id);
     412
     413                // This filter is documented in wp-includes/comment.php
     414                $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
     415                if ( ! in_array( $post->post_type, $post_types ) )
     416                        return $open;
     417                */
     418
     419                if ( time() - strtotime( $activity->date_recorded ) > ( $days_old * DAY_IN_SECONDS ) ) {
     420                        return false;
     421                }
     422
     423                return $open;
     424        }
     425
     426        return $open;
     427}
     428
     429/** POST COMMENT SYNCHRONIZATION ****************************************/
     430
     431/**
     432 * Deletes associated post comments when a blog post is deleted.
     433 *
     434 * Currently, this also occurs if the blog post is *trashed* because
     435 * {@link bp_blogs_transition_activity_status()} doesn't support trash / untrash
     436 * routines.
     437 *
     438 * This function will be removed once bp_blogs_transition_activity_status() is
     439 * modified to work with trash / untrash post statuses.
     440 *
     441 * @since BuddyPress (2.0.0)
     442 *
     443 * @param int $blog_id The blog ID
     444 * @param int $post_id The post ID
     445 * @param int $user_id The user ID
     446 * @param bool $force_delete_comments Whether we should force delete comments or
     447 *        trash them.  If false, comments are trashed rather than deleted.
     448 */
     449function bp_blogs_sync_delete_post_comments_on_post_delete( $blog_id, $post_id, $user_id, $force_delete_comments ) {
     450        if ( ! $force_delete_comments ) {
     451                return;
     452        }
     453
     454        // get the activity ID for the blog post
     455        $post_activity_id = bp_activity_get_activity_id( array(
     456                'component'         => buddypress()->blogs->id,
     457                'item_id'           => $blog_id,
     458                'secondary_item_id' => $post_id,
     459                'type'              => 'new_blog_post',
     460        ) );
     461
     462        // fetch the activity comments for the activity item
     463        $activity_comments = bp_activity_get( array(
     464                'in'               => $post_activity_id,
     465                'display_comments' => 'stream',
     466        ) );
     467
     468        // get all activity comment IDs for the pending deleted item
     469        $activity_ids = bp_activity_recurse_comments_activity_ids( $activity_comments );
     470
     471        if ( empty( $activity_ids ) ) {
     472                return;
     473        }
     474
     475        // handle multisite
     476        // switch to the blog where the comment was made
     477        switch_to_blog( $blog_id );
     478
     479        // remove associated blog comments
     480        bp_blogs_remove_associated_blog_comments( $activity_ids );
     481
     482        // multisite again!
     483        restore_current_blog();
     484}
     485add_action( 'bp_blogs_before_remove_post', 'bp_blogs_sync_delete_post_comments_on_post_delete', 10, 4 );
     486
     487/**
     488 * Syncs activity comments and posts them back as blog comments.
     489 *
     490 * Note: This is only a one-way sync - activity comments -> blog comment.
     491 *
     492 * For blog post -> activity comment, see {@link bp_blogs_record_comment()}.
     493 *
     494 * @since BuddyPress (2.0.0)
     495 *
     496 * @param int $comment_id The activity ID for the posted activity comment.
     497 * @param array $params Parameters for the activity comment.
     498 * @param object Parameters of the parent activity item (in this case, the blog post).
     499 */
     500function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) {
     501        // if parent activity isn't a blog post, stop now!
     502        if ( $parent_activity->type != 'new_blog_post' ) {
     503                return;
     504        }
     505
     506        // if activity comments are disabled for blog posts, stop now!
     507        if ( bp_disable_blogforum_comments() ) {
     508                return;
     509        }
     510
     511        // get userdata
     512        if ( $params['user_id'] == bp_loggedin_user_id() ) {
     513                $user = buddypress()->loggedin_user->userdata;
     514        } else {
     515                $user = bp_core_get_core_userdata( $params['user_id'] );
     516        }
     517
     518        // see if a parent WP comment ID exists
     519        if ( ! empty( $params['parent_id'] ) ) {
     520                $comment_parent = bp_activity_get_meta( $params['parent_id'], 'bp_blogs_post_comment_id' );
     521        } else {
     522                $comment_parent = 0;
     523        }
     524
     525        // comment args
     526        $args = array(
     527                'comment_post_ID'      => $parent_activity->secondary_item_id,
     528                'comment_author'       => bp_core_get_user_displayname( $params['user_id'] ),
     529                'comment_author_email' => $user->user_email,
     530                'comment_author_url'   => bp_core_get_user_domain( $params['user_id'], $user->user_nicename, $user->user_login ),
     531                'comment_content'      => $params['content'],
     532                'comment_type'         => '', // could be interesting to add 'buddypress' here...
     533                'comment_parent'       => (int) $comment_parent,
     534                'user_id'              => $params['user_id'],
     535
     536                // commenting these out for now
     537                //'comment_author_IP'    => '127.0.0.1',
     538                //'comment_agent'        => '',
     539
     540                'comment_approved'     => 1
     541        );
     542
     543        // prevent separate activity entry being made
     544        remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
     545
     546        // handle multisite
     547        switch_to_blog( $parent_activity->item_id );
     548
     549        // handle timestamps for the WP comment after we've switched to the blog
     550        $args['comment_date']     = current_time( 'mysql' );
     551        $args['comment_date_gmt'] = current_time( 'mysql', 1 );
     552
     553        // post the comment
     554        $post_comment_id = wp_insert_comment( $args );
     555
     556        // add meta to comment
     557        add_comment_meta( $post_comment_id, 'bp_activity_comment_id', $comment_id );
     558
     559        // add meta to activity comment
     560        bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id );
     561
     562        // resave activity comment with WP comment permalink
     563        //
     564        // in bp_blogs_activity_comment_permalink(), we change activity comment
     565        // permalinks to use the post comment link
     566        //
     567        // @todo since this is done after AJAX posting, the activity comment permalink
     568        //       doesn't change on the frontend until the next page refresh.
     569        $resave_activity = new BP_Activity_Activity( $comment_id );
     570        $resave_activity->primary_link = get_comment_link( $post_comment_id );
     571        $resave_activity->save();
     572
     573        // multisite again!
     574        restore_current_blog();
     575
     576        // add the comment hook back
     577        add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
     578
     579        do_action( 'bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user );
     580}
     581add_action( 'bp_activity_comment_posted', 'bp_blogs_sync_add_from_activity_comment', 10, 3 );
     582
     583/**
     584 * Deletes the blog comment when the associated activity comment is deleted.
     585 *
     586 * Note: This is hooked on the 'bp_activity_delete_comment_pre' filter instead
     587 * of the 'bp_activity_delete_comment' action because we need to fetch the
     588 * activity comment children before they are deleted.
     589 *
     590 * @since BuddyPress (2.0.0)
     591 *
     592 * @param bool $retval
     593 * @param int $parent_activity_id The parent activity ID for the activity comment.
     594 * @param int $activity_id The activity ID for the pending deleted activity comment.
     595 */
     596function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id ) {
     597        // check if parent activity is a blog post
     598        $parent_activity = new BP_Activity_Activity( $parent_activity_id );
     599        if ( 'new_blog_post' != $parent_activity->type ) {
     600                return $retval;
     601        }
     602
     603        // fetch the activity comments for the activity item
     604        $activity = bp_activity_get( array(
     605                'in'               => $activity_id,
     606                'display_comments' => 'stream',
     607        ) );
     608
     609        // get all activity comment IDs for the pending deleted item
     610        $activity_ids   = bp_activity_recurse_comments_activity_ids( $activity );
     611        $activity_ids[] = $activity_id;
     612
     613        // handle multisite
     614        // switch to the blog where the comment was made
     615        switch_to_blog( $parent_activity->item_id );
     616
     617        // remove associated blog comments
     618        bp_blogs_remove_associated_blog_comments( $activity_ids, current_user_can( 'moderate_comments' ) );
     619
     620        // multisite again!
     621        restore_current_blog();
     622
     623        // rebuild activity comment tree
     624        // emulate bp_activity_delete_comment()
     625        BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id );
     626
     627        // we're overriding the default bp_activity_delete_comment() functionality
     628        // so we need to return false
     629        return false;
     630}
     631add_filter( 'bp_activity_delete_comment_pre', 'bp_blogs_sync_delete_from_activity_comment', 10, 3 );
     632
     633/**
     634 * Updates the blog comment when the associated activity comment is edited.
     635 *
     636 * @since BuddyPress (2.0.0)
     637 *
     638 * @param BP_Activity_Activity $activity The activity object.
     639 */
     640function bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $activity ) {
     641        // not an activity comment? stop now!
     642        if ( 'activity_comment' !== $activity->type ) {
     643                return;
     644        }
     645
     646        // this is an existing entry, so stop!
     647        // we only want edits!
     648        if ( empty( $activity->id ) ) {
     649                return;
     650        }
     651
     652        // prevent recursion
     653        remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
     654
     655        // Try to see if a corresponding blog comment exists
     656        $post_comment_id = bp_activity_get_meta( $activity->id, 'bp_blogs_post_comment_id' );
     657
     658        if ( empty( $post_comment_id ) ) {
     659                return;
     660        }
     661
     662        // fetch parent activity item
     663        $parent_activity = new BP_Activity_Activity( $activity->item_id );
     664
     665        // sanity check
     666        if ( 'new_blog_post' !== $parent_activity->type ) {
     667                return;
     668        }
     669
     670        // handle multisite
     671        switch_to_blog( $parent_activity->item_id );
     672
     673        // update the blog post comment
     674        wp_update_comment( array(
     675                'comment_ID'      => $post_comment_id,
     676                'comment_content' => $activity->content
     677        ) );
     678
     679        restore_current_blog();
     680}
     681add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
     682
     683/**
     684 * Utility function to set up some variables for use in the activity loop.
     685 *
     686 * Grabs the blog's comment depth and the post's open comment status options
     687 * for later use in the activity and activity comment loops.
     688 *
     689 * This is to prevent having to requery these items later on.
     690 *
     691 * @since BuddyPress (2.0.0)
     692 *
     693 * @see bp_blogs_disable_activity_commenting()
     694 * @see bp_blogs_setup_comment_loop_globals_on_ajax()
     695 *
     696 * @param object $activity The BP_Activity_Activity object
     697 */
     698function bp_blogs_setup_activity_loop_globals( $activity ) {
     699        if ( ! is_object( $activity ) ) {
     700                return;
     701        }
     702
     703        // parent not a blog post? stop now!
     704        if ( 'new_blog_post' !== $activity->type ) {
     705                return;
     706        }
     707
     708        if ( empty( $activity->id ) ) {
     709                return;
     710        }
     711
     712        // if we've already done this before, stop now!
     713        if ( isset( buddypress()->blogs->allow_comments[ $activity->id ] ) ) {
     714                return;
     715        }
     716
     717        $allow_comments = bp_blogs_comments_open( $activity );
     718        $thread_depth   = bp_blogs_get_blogmeta( $activity->item_id, 'thread_comments_depth' );
     719
     720        // initialize a local object so we won't have to query this again in the
     721        // comment loop
     722        if ( empty( buddypress()->blogs->allow_comments ) ) {
     723                buddypress()->blogs->allow_comments = array();
     724        }
     725        if ( empty( buddypress()->blogs->thread_depth ) ) {
     726                buddypress()->blogs->thread_depth   = array();
     727        }
     728
     729        // cache comment settings in the buddypress() singleton to reference later in
     730        // the activity comment loop
     731        // @see bp_blogs_disable_activity_replies()
     732        //
     733        // thread_depth is keyed by activity ID instead of blog ID because when we're
     734        // in a comment loop, we don't have access to the blog ID...
     735        // should probably object cache these values instead...
     736        buddypress()->blogs->allow_comments[ $activity->id ] = $allow_comments;
     737        buddypress()->blogs->thread_depth[ $activity->id ]   = $thread_depth;
     738}
     739
     740/**
     741 * Set up some globals used in the activity comment loop when AJAX is used.
     742 *
     743 * @since BuddyPress (2.0.0)
     744 *
     745 * @see bp_blogs_setup_activity_loop_globals()
     746 */
     747function bp_blogs_setup_comment_loop_globals_on_ajax() {
     748        // not AJAX? stop now!
     749        if ( ! defined( 'DOING_AJAX' ) ) {
     750                return;
     751        }
     752        if ( false === (bool) constant( 'DOING_AJAX' ) ) {
     753                return;
     754        }
     755
     756        // get the parent activity item
     757        $comment         = bp_activity_current_comment();
     758        $parent_activity = new BP_Activity_Activity( $comment->item_id );
     759
     760        // setup the globals
     761        bp_blogs_setup_activity_loop_globals( $parent_activity );
     762}
     763add_action( 'bp_before_activity_comment', 'bp_blogs_setup_comment_loop_globals_on_ajax' );
     764
     765/**
     766 * Disable activity commenting for blog posts based on certain criteria.
     767 *
     768 * If activity commenting is enabled for blog posts, we still need to disable
     769 * commenting if:
     770 *  - comments are disabled for the WP blog post from the admin dashboard
     771 *  - the WP blog post is supposed to be automatically closed from comments
     772 *    based on a certain age
     773 *  - the activity entry is a 'new_blog_comment' type
     774 *
     775 * @since BuddyPress (2.0.0)
     776 *
     777 * @param bool $retval Is activity commenting enabled for this activity entry?
     778 * @return bool
     779 */
     780function bp_blogs_disable_activity_commenting( $retval ) {
     781        // if activity commenting is disabled, return current value
     782        if ( bp_disable_blogforum_comments() ) {
     783                return $retval;
     784        }
     785
     786        // activity commenting is enabled for blog posts
     787        switch ( bp_get_activity_action_name() ) {
     788
     789                // we still have to disable activity commenting for 'new_blog_comment' items
     790                // commenting should only be done on the parent 'new_blog_post' item
     791                case 'new_blog_comment' :
     792                        $retval = false;
     793
     794                        break;
     795
     796                // check if commenting is disabled for the WP blog post
     797                // we should extrapolate this and automate this for plugins... or not
     798                case 'new_blog_post' :
     799                        global $activities_template;
     800
     801                        // setup some globals we'll need to reference later
     802                        bp_blogs_setup_activity_loop_globals( $activities_template->activity );
     803
     804                        // if comments are closed for the WP blog post, we should disable
     805                        // activity comments for this activity entry
     806                        if ( empty( buddypress()->blogs->allow_comments[bp_get_activity_id()] ) ) {
     807                                $retval = false;
     808                        }
     809
     810                        break;
     811        }
     812
     813        return $retval;
     814}
     815add_filter( 'bp_activity_can_comment', 'bp_blogs_disable_activity_commenting' );
     816
     817/**
     818 * Check if an activity comment associated with a blog post can be replied to.
     819 *
     820 * By default, disables replying to activity comments if the corresponding WP
     821 * blog post no longer accepts comments.
     822 *
     823 * This check uses a locally-cached value set in {@link bp_blogs_disable_activity_commenting()}
     824 * via {@link bp_blogs_setup_activity_loop_globals()}.
     825 *
     826 * @since BuddyPress (2.0.0)
     827 *
     828 * @param bool $retval Are replies allowed for this activity reply?
     829 * @param object $comment The activity comment object
     830 * @return bool
     831 */
     832function bp_blogs_can_comment_reply( $retval, $comment ) {
     833        if ( is_array( $comment ) ) {
     834                $comment = (object) $comment;
     835        }
     836
     837        // check comment depth and disable if depth is too large
     838        if ( isset( buddypress()->blogs->thread_depth[$comment->item_id] ) ){
     839                if ( $comment->mptt_left > buddypress()->blogs->thread_depth[$comment->item_id] ) {
     840                        $retval = false;
     841                }
     842        }
     843
     844        // check if we should disable activity replies based on the parent activity
     845        if ( isset( buddypress()->blogs->allow_comments[$comment->item_id] ) ){
     846                // the blog post has closed off commenting, so we should disable all activity
     847                // comments under the parent 'new_blog_post' activity entry
     848                if ( empty( buddypress()->blogs->allow_comments[$comment->item_id] ) ) {
     849                        $retval = false;
     850                }
     851        }
     852
     853        return $retval;
     854}
     855add_filter( 'bp_activity_can_comment_reply', 'bp_blogs_can_comment_reply', 10, 2 );
     856
     857/**
     858 * Changes activity comment permalinks to use the blog comment permalink
     859 * instead of the activity permalink.
     860 *
     861 * This is only done if activity commenting is allowed and whether the parent
     862 * activity item is a 'new_blog_post' entry.
     863 *
     864 * @since BuddyPress (2.0.0)
     865 *
     866 * @param string $retval The activity comment permalink
     867 * @return string
     868 */
     869function bp_blogs_activity_comment_permalink( $retval ) {
     870        global $activities_template;
     871
     872        if ( isset( buddypress()->blogs->allow_comments[$activities_template->activity->current_comment->item_id] ) ){
     873                $retval = $activities_template->activity->current_comment->primary_link;
     874        }
     875
     876        return $retval;
     877}
     878add_filter( 'bp_get_activity_comment_permalink', 'bp_blogs_activity_comment_permalink' );
  • bp-blogs/bp-blogs-functions.php

     
    182182        if ( !bp_blogs_is_blog_recordable( $blog_id, $user_id ) )
    183183                return false;
    184184
    185         $url         = get_home_url( $blog_id );
    186         $name        = get_blog_option( $blog_id, 'blogname' );
    187         $description = get_blog_option( $blog_id, 'blogdescription' );
     185        $name = get_blog_option( $blog_id, 'blogname' );
    188186
    189         if ( empty( $name ) )
     187        if ( empty( $name ) ) {
    190188                return false;
     189        }
     190
     191        $url             = get_home_url( $blog_id );
     192        $description     = get_blog_option( $blog_id, 'blogdescription' );
     193        $close_old_posts = get_blog_option( $blog_id, 'close_comments_for_old_posts' );
     194        $close_days_old  = get_blog_option( $blog_id, 'close_comments_days_old' );
     195
     196        $thread_depth = get_blog_option( $blog_id, 'thread_comments' );
     197        if ( ! empty( $thread_depth ) ) {
     198                $thread_depth = get_blog_option( $blog_id, 'thread_comments_depth' );   
     199        } else {
     200                // perhaps filter this?
     201                $thread_depth = 1;
     202        }
    191203
    192204        $recorded_blog          = new BP_Blogs_Blog;
    193205        $recorded_blog->user_id = $user_id;
     
    199211        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
    200212        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
    201213        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() );
     214        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_for_old_posts', $close_old_posts );
     215        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_days_old', $close_days_old );
     216        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'thread_comments_depth', $thread_depth );
    202217
    203218        $is_private = !empty( $_POST['blog_public'] ) && (int) $_POST['blog_public'] ? false : true;
    204219        $is_private = !apply_filters( 'bp_is_new_blog_public', !$is_private );
     
    252267add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescription', 10, 2 );
    253268
    254269/**
     270 * Update "Close comments for old posts" option in BuddyPress blogmeta table.
     271 *
     272 * @since BuddyPress (2.0.0)
     273 *
     274 * @global object $wpdb DB Layer.
     275 *
     276 * @param string $oldvalue Value before save. Passed by do_action() but
     277 *        unused here.
     278 * @param string $newvalue Value to change meta to.
     279 */
     280function bp_blogs_update_option_close_comments_for_old_posts( $oldvalue, $newvalue ) {
     281        global $wpdb;
     282
     283        bp_blogs_update_blogmeta( $wpdb->blogid, 'close_comments_for_old_posts', $newvalue );
     284}
     285add_action( 'update_option_close_comments_for_old_posts', 'bp_blogs_update_option_close_comments_for_old_posts', 10, 2 );
     286
     287/**
     288 * Update "Close comments after days old" option in BuddyPress blogmeta table.
     289 *
     290 * @since BuddyPress (2.0.0)
     291 *
     292 * @global object $wpdb DB Layer.
     293 *
     294 * @param string $oldvalue Value before save. Passed by do_action() but
     295 *        unused here.
     296 * @param string $newvalue Value to change meta to.
     297 */
     298function bp_blogs_update_option_close_close_comments_days_old( $oldvalue, $newvalue ) {
     299        global $wpdb;
     300
     301        bp_blogs_update_blogmeta( $wpdb->blogid, 'close_comments_days_old', $newvalue );
     302}
     303add_action( 'update_option_close_comments_days_old', 'bp_blogs_update_option_close_comments_days_old', 10, 2 );
     304
     305/**
     306 * When toggling threaded comments, update thread depth in blogmeta table.
     307 *
     308 * @since BuddyPress (2.0.0)
     309 *
     310 * @global object $wpdb DB Layer.
     311 *
     312 * @param string $oldvalue Value before save. Passed by do_action() but
     313 *        unused here.
     314 * @param string $newvalue Value to change meta to.
     315 */
     316function bp_blogs_update_option_thread_comments( $oldvalue, $newvalue ) {
     317        global $wpdb;
     318
     319        if ( empty( $newvalue ) ) {
     320                $thread_depth = 1;
     321        } else {
     322                $thread_depth = get_option( 'thread_comments_depth' );
     323        }
     324
     325        bp_blogs_update_blogmeta( $wpdb->blogid, 'thread_comments_depth', $thread_depth );
     326}
     327add_action( 'update_option_thread_comments', 'bp_blogs_update_option_thread_comments', 10, 2 );
     328
     329/**
     330 * When updating comment depth, update thread depth in blogmeta table.
     331 *
     332 * @since BuddyPress (2.0.0)
     333 *
     334 * @global object $wpdb DB Layer.
     335 *
     336 * @param string $oldvalue Value before save. Passed by do_action() but
     337 *        unused here.
     338 * @param string $newvalue Value to change meta to.
     339 */
     340function bp_blogs_update_option_thread_comments_depth( $oldvalue, $newvalue ) {
     341        global $wpdb;
     342
     343        $comments_enabled = get_option( 'thread_comments' );
     344
     345        if (  $comments_enabled ) {
     346                bp_blogs_update_blogmeta( $wpdb->blogid, 'thread_comments_depth', $newvalue );
     347        }
     348}
     349add_action( 'update_option_thread_comments_depth', 'bp_blogs_update_option_thread_comments_depth', 10, 2 );
     350
     351/**
    255352 * Detect a change in post status, and initiate an activity update if necessary.
    256353 *
    257354 * Posts get new activity updates when (a) they are being published, and (b)
     
    262359 *
    263360 * @since BuddyPress (2.0.0)
    264361 *
     362 * @todo Support trashing / untrashing similar to bp_blogs_transition_activity_status()
     363 *       for post comments.
     364 *
    265365 * @param string $new_status New status for the post.
    266366 * @param string $old_status Old status for the post.
    267367 * @param object $post Post data.
     
    441541                $post_permalink = get_permalink( $recorded_comment->comment_post_ID );
    442542                $comment_link   = get_comment_link( $recorded_comment->comment_ID );
    443543
    444                 // Prepare to record in activity streams
    445                 if ( is_multisite() )
    446                         $activity_action = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
    447                 else
    448                         $activity_action = sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
     544                // Setup activity args
     545                $args = array();
     546
     547                $args['user_id']       = $user_id;
     548                $args['content']       = apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $recorded_comment->comment_content, &$recorded_comment, $comment_link ) );
     549                $args['primary_link']  = apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link,     &$recorded_comment ) );
     550                $args['recorded_time'] = $recorded_comment->comment_date_gmt;
     551
     552                // Setup some different activity args depending if activity commenting is
     553                // enabled or not
     554
     555                // if cannot comment, record separate activity entry
     556                // this is the old way of doing things
     557                if ( bp_disable_blogforum_comments() ) {
     558                        $args['type']              = 'new_blog_comment';
     559                        $args['item_id']           = $blog_id;
     560                        $args['secondary_item_id'] = $comment_id;
     561
     562                        // record the activity entry
     563                        bp_blogs_record_activity( $args );
     564
     565                // record comment as BP activity comment under the parent 'new_blog_post'
     566                // activity item
     567                } else {
     568                        // this is a comment edit
     569                        // check to see if corresponding activity entry already exists
     570                        if ( ! empty( $_REQUEST['action'] ) ) {
     571                                $existing_activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true );
     572
     573                                if ( ! empty( $existing_activity_id ) ) {
     574                                        $args['id'] = $existing_activity_id;
     575                                }
     576                        }
    449577
    450                 $activity_content       = $recorded_comment->comment_content;
     578                        // find the parent 'new_blog_post' activity entry
     579                        $parent_activity_id = bp_activity_get_activity_id( array(
     580                                'user_id'           => $user_id,
     581                                'component'         => 'blogs',
     582                                'type'              => 'new_blog_post',
     583                                'item_id'           => $blog_id,
     584                                'secondary_item_id' => $recorded_comment->comment_post_ID
     585                        ) );
     586
     587                        // we found the parent activity entry
     588                        // so let's go ahead and reconfigure some activity args
     589                        if ( ! empty( $parent_activity_id ) ) {
     590                                // set the 'item_id' with the parent activity entry ID
     591                                $args['item_id'] = $parent_activity_id;
     592
     593                                // now see if the WP parent comment has a BP activity ID
     594                                $comment_parent = 0;
     595                                if ( ! empty( $recorded_comment->comment_parent ) ) {
     596                                        $comment_parent = get_comment_meta( $recorded_comment->comment_parent, 'bp_activity_comment_id', true );
     597                                }
    451598
    452                 // Record in activity streams
    453                 bp_blogs_record_activity( array(
    454                         'user_id'           => $user_id,
    455                         'content'           => apply_filters_ref_array( 'bp_blogs_activity_new_comment_content',      array( $activity_content, &$recorded_comment, $comment_link ) ),
    456                         'primary_link'      => apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link,     &$recorded_comment                ) ),
    457                         'type'              => 'new_blog_comment',
    458                         'item_id'           => $blog_id,
    459                         'secondary_item_id' => $comment_id,
    460                         'recorded_time'     => $recorded_comment->comment_date_gmt
    461                 ) );
     599                                // WP parent comment does not have a BP activity ID
     600                                // so set to 'new_blog_post' activity ID
     601                                if ( empty( $comment_parent ) ) {
     602                                        $comment_parent = $parent_activity_id;
     603                                }
     604
     605                                $args['secondary_item_id'] = $comment_parent;
     606                                $args['component']         = 'activity';
     607                                $args['type']              = 'activity_comment';
     608
     609                        // could not find corresponding parent activity entry
     610                        // so wipe out $args array
     611                        } else {
     612                                $args = array();
     613                        }
     614
     615                        // Record in activity streams
     616                        if ( ! empty( $args ) ) {
     617                                // @todo should we use bp_activity_new_comment()? that function will also send
     618                                // an email to people in the activity comment thread
     619                                //
     620                                // what if a site already has some comment email notification plugin setup?
     621                                // this is why I decided to go with bp_activity_add() to avoid any conflict
     622                                // with existing comment email notification plugins
     623                                $comment_activity_id = bp_activity_add( $args );
     624
     625                                if ( empty( $args['id'] ) ) {
     626                                        // add meta to activity comment
     627                                        bp_activity_update_meta( $comment_activity_id, 'bp_blogs_post_comment_id', $comment_id );
     628       
     629                                        // add meta to comment
     630                                        add_comment_meta( $comment_id, 'bp_activity_comment_id', $comment_activity_id );
     631                                }
     632                        }
     633                }
    462634
    463635                // Update the blogs last active date
    464636                bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
     
    632804function bp_blogs_remove_comment( $comment_id ) {
    633805        global $wpdb;
    634806
    635         // Delete activity stream item
    636         bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid, 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
     807        // activity comments are disabled for blog posts
     808        // which means that individual activity items exist for blog comments
     809        if ( bp_disable_blogforum_comments() ) {
     810                // Delete the individual activity stream item
     811                bp_blogs_delete_activity( array(
     812                        'item_id'           => $wpdb->blogid,
     813                        'secondary_item_id' => $comment_id,
     814                        'type'              => 'new_blog_comment'
     815                ) );
     816
     817        // activity comments are enabled for blog posts
     818        // remove the associated activity item
     819        } else {
     820                // get associated activity ID from comment meta
     821                $activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true );
     822
     823                // delete the associated activity comment
     824                //
     825                // also removes child post comments and associated activity comments
     826                if ( ! empty( $activity_id ) && bp_is_active( 'activity' ) ) {
     827                        // fetch the activity comments for the activity item
     828                        $activity = bp_activity_get( array(
     829                                'in'               => $activity_id,
     830                                'display_comments' => 'stream',
     831                        ) );
     832               
     833                        // get all activity comment IDs for the pending deleted item
     834                        if ( ! empty( $activity['activities'] ) ) {
     835                                $activity_ids   = bp_activity_recurse_comments_activity_ids( $activity );
     836                                $activity_ids[] = $activity_id;
     837
     838                                // delete activity items
     839                                foreach ( $activity_ids as $activity_id ) {
     840                                        bp_activity_delete( array(
     841                                                'id' => $activity_id
     842                                        ) );
     843                                }
     844
     845                                // remove associated blog comments
     846                                bp_blogs_remove_associated_blog_comments( $activity_ids );
     847
     848                                // rebuild activity comment tree
     849                                BP_Activity_Activity::rebuild_activity_comment_tree( $activity['activities'][0]->item_id );
     850                        }
     851                }
     852        }
    637853
    638854        do_action( 'bp_blogs_remove_comment', $wpdb->blogid, $comment_id, bp_loggedin_user_id() );
    639855}
    640856add_action( 'delete_comment', 'bp_blogs_remove_comment' );
    641857
    642858/**
     859 * Removes blog comments that are associated with activity comments.
     860 *
     861 * @since BuddyPress (2.0.0)
     862 *
     863 * @see bp_blogs_remove_comment()
     864 * @see bp_blogs_sync_delete_from_activity_comment()
     865 *
     866 * @param array $activity_ids The activity IDs to check association with blog
     867 *              comments.
     868 * @param bool $force_delete Whether to force delete the comments. If false,
     869 *             comments are trashed instead.
     870 */
     871function bp_blogs_remove_associated_blog_comments( $activity_ids = array(), $force_delete = true ) {
     872        // query args
     873        $query_args = array(
     874                'meta_query' => array(
     875                        array(
     876                                'key'     => 'bp_activity_comment_id',
     877                                'value'   => implode( ',', (array) $activity_ids ),
     878                                'compare' => 'IN',
     879                        )
     880                )
     881        );
     882
     883        // get comment
     884        $comment_query = new WP_Comment_Query;
     885        $comments = $comment_query->query( $query_args );
     886
     887        // found the corresponding comments
     888        // let's delete them!
     889        foreach ( $comments as $comment ) {
     890                // we force delete the comment, since activity items are deleted immediately
     891                wp_delete_comment( $comment->comment_ID, $force_delete );
     892        }
     893}
     894
     895/**
    643896 * When a blog comment status transition occurs, update the relevant activity's status.
    644897 *
    645898 * @since BuddyPress (1.6.0)
     
    667920         */
    668921
    669922        // This clause was moved in from bp_blogs_remove_comment() in BuddyPress 1.6. It handles delete/hold.
    670         if ( in_array( $new_status, array( 'delete', 'hold' ) ) )
     923        if ( in_array( $new_status, array( 'delete', 'hold' ) ) ) {
    671924                return bp_blogs_remove_comment( $comment->comment_ID );
    672925
    673926        // These clauses handle trash, spam, and un-spams.
    674         elseif ( in_array( $new_status, array( 'trash', 'spam' ) ) )
     927        } elseif ( in_array( $new_status, array( 'trash', 'spam' ) ) ) {
    675928                $action = 'spam_activity';
    676         elseif ( 'approved' == $new_status )
     929        } elseif ( 'approved' == $new_status ) {
    677930                $action = 'ham_activity';
     931        }
    678932
    679933        // Get the activity
    680         $activity_id = bp_activity_get_activity_id( array( 'component' => $bp->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => 'new_blog_comment', ) );
     934        if ( bp_disable_blogforum_comments() ) {
     935                $activity_id = bp_activity_get_activity_id( array( 'component' => $bp->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => 'new_blog_comment', ) );
     936        } else {
     937                $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true );
     938        }
    681939
    682940        // Check activity item exists
    683         if ( ! $activity_id ) {
    684 
     941        if ( empty( $activity_id ) ) {
    685942                // If no activity exists, but the comment has been approved, record it into the activity table.
    686                 if ( 'approved' == $new_status )
     943                if ( 'approved' == $new_status ) {
    687944                        return bp_blogs_record_comment( $comment->comment_ID, true );
     945                }
    688946
    689947                return;
    690948        }
  • bp-core/bp-core-options.php

     
    226226 * @return mixed The value for the option.
    227227 */
    228228function bp_get_option( $option_name, $default = '' ) {
    229         $value = get_blog_option( bp_get_root_blog_id(), $option_name, $default );
     229        // check buddypress()->site_options array first
     230        if ( isset( buddypress()->site_options[$option_name] ) ) {
     231                $value = buddypress()->site_options[$option_name];
     232
     233        // query for the option if not available
     234        } else {
     235                $value = get_blog_option( bp_get_root_blog_id(), $option_name, $default );
     236        }
    230237
    231238        return apply_filters( 'bp_get_option', $value );
    232239}