Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/23/2015 03:55:00 AM (9 years ago)
Author:
tw2113
Message:

More documentation cleanup for BP-Blogs component.

See #6397.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-activity.php

    r10253 r10374  
    2020    $bp = buddypress();
    2121
    22     // Bail if activity is not active
     22    // Bail if activity is not active.
    2323    if ( ! bp_is_active( 'activity' ) ) {
    2424        return false;
     
    3737    }
    3838
    39     // Only add the comment type if the 'post' post type is trackable
     39    // Only add the comment type if the 'post' post type is trackable.
    4040    if ( post_type_supports( 'post', 'buddypress-activity' ) ) {
    4141        bp_activity_set_action(
     
    6666 * @param string $action   Static activity action.
    6767 * @param object $activity Activity data object.
    68  *
    6968 * @return string
    7069 */
     
    7574    $action = sprintf( __( '%s created the site %s', 'buddypress' ), bp_core_get_userlink( $activity->user_id ), '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );
    7675
    77     // Legacy filter - requires the BP_Blogs_Blog object
     76    // Legacy filter - requires the BP_Blogs_Blog object.
    7877    if ( has_filter( 'bp_blogs_activity_created_blog_action' ) ) {
    7978        $user_blog = BP_Blogs_Blog::get_user_blog( $activity->user_id, $activity->item_id );
     
    105104 * @param string $action   Static activity action.
    106105 * @param object $activity Activity data object.
    107  *
    108106 * @return string Constructed activity action.
    109107 */
     
    141139    }
    142140
    143     // Should be the case when the post has just been published
     141    // Should be the case when the post has just been published.
    144142    if ( isset( $activity->post_title ) ) {
    145143        $post_title = $activity->post_title;
    146144
    147     // If activity already exists try to get the post title from activity meta
     145    // If activity already exists try to get the post title from activity meta.
    148146    } else if ( ! empty( $activity->id ) ) {
    149147        $post_title = bp_activity_get_meta( $activity->id, 'post_title' );
     
    152150    /**
    153151     * In case the post was published without a title
    154      * or the activity meta was not found
     152     * or the activity meta was not found.
    155153     */
    156154    if ( empty( $post_title ) ) {
    157         // Defaults to no title
     155        // Defaults to no title.
    158156        $post_title = esc_html__( '(no title)', 'buddypress' );
    159157
     
    167165            }
    168166
    169             // Make sure the activity exists before saving the post title in activity meta
     167            // Make sure the activity exists before saving the post title in activity meta.
    170168            if ( ! empty( $activity->id ) ) {
    171169                bp_activity_update_meta( $activity->id, 'post_title', $post_title );
     
    176174    }
    177175
    178     // Build the 'post link' part of the activity action string
     176    // Build the 'post link' part of the activity action string.
    179177    $post_link  = '<a href="' . esc_url( $post_url ) . '">' . $post_title . '</a>';
    180178
    181179    $user_link = bp_core_get_userlink( $activity->user_id );
    182180
    183     // Build the complete activity action string
     181    // Build the complete activity action string.
    184182    if ( is_multisite() ) {
    185183        $action  = sprintf( __( '%1$s wrote a new post, %2$s, on the site %3$s', 'buddypress' ), $user_link, $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );
     
    188186    }
    189187
    190     // Legacy filter - requires the post object
     188    // Legacy filter - requires the post object.
    191189    if ( has_filter( 'bp_blogs_activity_new_post_action' ) ) {
    192190        switch_to_blog( $activity->item_id );
     
    217215 * @param string $action   Static activity action.
    218216 * @param object $activity Activity data object.
    219  *
    220217 * @return string Constructed activity action.
    221218 */
     
    235232    $post_title = bp_activity_get_meta( $activity->id, 'post_title' );
    236233
    237     // Should only be empty at the time of post creation
     234    // Should only be empty at the time of post creation.
    238235    if ( empty( $post_url ) || empty( $post_title ) ) {
    239236        switch_to_blog( $activity->item_id );
     
    265262    }
    266263
    267     // Legacy filter - requires the comment object
     264    // Legacy filter - requires the comment object.
    268265    if ( has_filter( 'bp_blogs_activity_new_comment_action' ) ) {
    269266        switch_to_blog( $activity->item_id );
     
    295292 *
    296293 * @param array $activities Array of activity items.
    297  *
    298294 * @return array
    299295 */
     
    338334function bp_blogs_record_activity( $args = '' ) {
    339335
    340     // Bail if activity is not active
     336    // Bail if activity is not active.
    341337    if ( ! bp_is_active( 'activity' ) ) {
    342338        return false;
     
    415411function bp_blogs_delete_activity( $args = '' ) {
    416412
    417     // Bail if activity is not active
     413    // Bail if activity is not active.
    418414    if ( ! bp_is_active( 'activity' ) ) {
    419415        return false;
     
    444440 * @since 2.0.0
    445441 *
    446  * @param object $activity The BP_Activity_Activity object
    447  *
     442 * @param object $activity The BP_Activity_Activity object.
    448443 * @return bool
    449444 */
     
    453448    $blog_id = $activity->item_id;
    454449
    455     // see if we've mirrored the close comments option before
     450    // See if we've mirrored the close comments option before.
    456451    $days_old = bp_blogs_get_blogmeta( $blog_id, 'close_comments_days_old' );
    457452
    458     // we've never cached these items before, so do it now
     453    // We've never cached these items before, so do it now.
    459454    if ( '' === $days_old ) {
    460455        switch_to_blog( $blog_id );
    461456
    462         // use comments_open()
     457        // Use comments_open().
    463458        remove_filter( 'comments_open', 'bp_comments_open', 10, 2 );
    464459        $open = comments_open( $activity->secondary_item_id );
    465460        add_filter( 'comments_open', 'bp_comments_open', 10, 2 );
    466461
    467         // might as well mirror values to blogmeta since we're here!
     462        // Might as well mirror values to blogmeta since we're here!
    468463        $thread_depth = get_option( 'thread_comments' );
    469464        if ( ! empty( $thread_depth ) ) {
    470465            $thread_depth = get_option( 'thread_comments_depth' );
    471466        } else {
    472             // perhaps filter this?
     467            // Perhaps filter this?
    473468            $thread_depth = 1;
    474469        }
     
    480475        restore_current_blog();
    481476
    482     // check blogmeta and manually check activity item
    483     // basically a copy of _close_comments_for_old_post()
     477    // Check blogmeta and manually check activity item.
     478    // Basically a copy of _close_comments_for_old_post().
    484479    } else {
    485480
    486         // comments are closed
     481        // Comments are closed.
    487482        if ( 'closed' == bp_activity_get_meta( $activity->id, 'post_comment_status' ) ) {
    488483            return false;
     
    498493        }
    499494
    500         /* commenting out for now - needs some more thought...
     495        /*
     496           Commenting out for now - needs some more thought...
    501497           should we add the post type to activity meta?
    502498
     
    535531 */
    536532function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) {
    537     // if parent activity isn't a blog post, stop now!
     533    // If parent activity isn't a blog post, stop now!
    538534    if ( $parent_activity->type != 'new_blog_post' ) {
    539535        return;
    540536    }
    541537
    542     // if activity comments are disabled for blog posts, stop now!
     538    // If activity comments are disabled for blog posts, stop now!
    543539    if ( bp_disable_blogforum_comments() ) {
    544540        return;
    545541    }
    546542
    547     // get userdata
     543    // Get userdata.
    548544    if ( $params['user_id'] == bp_loggedin_user_id() ) {
    549545        $user = buddypress()->loggedin_user->userdata;
     
    552548    }
    553549
    554     // see if a parent WP comment ID exists
     550    // See if a parent WP comment ID exists.
    555551    if ( ! empty( $params['parent_id'] ) ) {
    556552        $comment_parent = bp_activity_get_meta( $params['parent_id'], 'bp_blogs_post_comment_id' );
     
    559555    }
    560556
    561     // comment args
     557    // Comment args.
    562558    $args = array(
    563559        'comment_post_ID'      => $parent_activity->secondary_item_id,
     
    566562        'comment_author_url'   => bp_core_get_user_domain( $params['user_id'], $user->user_nicename, $user->user_login ),
    567563        'comment_content'      => $params['content'],
    568         'comment_type'         => '', // could be interesting to add 'buddypress' here...
     564        'comment_type'         => '', // Could be interesting to add 'buddypress' here...
    569565        'comment_parent'       => (int) $comment_parent,
    570566        'user_id'              => $params['user_id'],
    571567
    572         // commenting these out for now
    573         //'comment_author_IP'    => '127.0.0.1',
    574         //'comment_agent'        => '',
    575 
     568        // Commenting these out for now
     569        // 'comment_author_IP'    => '127.0.0.1',
     570        // 'comment_agent'        => '', .
    576571        'comment_approved'     => 1
    577572    );
    578573
    579     // prevent separate activity entry being made
     574    // Prevent separate activity entry being made.
    580575    remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
    581576
    582     // handle multisite
     577    // Handle multisite.
    583578    switch_to_blog( $parent_activity->item_id );
    584579
    585     // handle timestamps for the WP comment after we've switched to the blog
     580    // Handle timestamps for the WP comment after we've switched to the blog.
    586581    $args['comment_date']     = current_time( 'mysql' );
    587582    $args['comment_date_gmt'] = current_time( 'mysql', 1 );
    588583
    589     // post the comment
     584    // Post the comment.
    590585    $post_comment_id = wp_insert_comment( $args );
    591586
    592     // add meta to comment
     587    // Add meta to comment.
    593588    add_comment_meta( $post_comment_id, 'bp_activity_comment_id', $comment_id );
    594589
    595     // add meta to activity comment
     590    // Add meta to activity comment.
    596591    bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id );
    597592
    598     // resave activity comment with WP comment permalink
     593    // Resave activity comment with WP comment permalink.
    599594    //
    600595    // in bp_blogs_activity_comment_permalink(), we change activity comment
     
    602597    //
    603598    // @todo since this is done after AJAX posting, the activity comment permalink
    604     //       doesn't change on the frontend until the next page refresh.
     599    // doesn't change on the frontend until the next page refresh.
    605600    $resave_activity = new BP_Activity_Activity( $comment_id );
    606601    $resave_activity->primary_link = get_comment_link( $post_comment_id );
     
    614609    $resave_activity->save();
    615610
    616     // add the edit activity comment hook back
     611    // Add the edit activity comment hook back.
    617612    add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
    618613
    619     // multisite again!
     614    // Multisite again!
    620615    restore_current_blog();
    621616
    622     // add the comment hook back
     617    // Add the comment hook back.
    623618    add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
    624619
     
    646641 * @since 2.0.0
    647642 *
    648  * @param bool $retval
     643 * @param bool $retval             Whether BuddyPress should continue or not.
    649644 * @param int  $parent_activity_id The parent activity ID for the activity comment.
    650645 * @param int  $activity_id        The activity ID for the pending deleted activity comment.
    651  *
    652646 * @return bool
    653647 */
    654648function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id ) {
    655     // check if parent activity is a blog post
     649    // Check if parent activity is a blog post.
    656650    $parent_activity = new BP_Activity_Activity( $parent_activity_id );
    657651    if ( 'new_blog_post' != $parent_activity->type ) {
     
    659653    }
    660654
    661     // fetch the activity comments for the activity item
     655    // Fetch the activity comments for the activity item.
    662656    $activity = bp_activity_get( array(
    663657        'in'               => $activity_id,
     
    665659    ) );
    666660
    667     // get all activity comment IDs for the pending deleted item
     661    // Get all activity comment IDs for the pending deleted item.
    668662    $activity_ids   = bp_activity_recurse_comments_activity_ids( $activity );
    669663    $activity_ids[] = $activity_id;
    670664
    671     // handle multisite
    672     // switch to the blog where the comment was made
     665    // Handle multisite
     666    // switch to the blog where the comment was made.
    673667    switch_to_blog( $parent_activity->item_id );
    674668
    675     // remove associated blog comments
     669    // Remove associated blog comments.
    676670    bp_blogs_remove_associated_blog_comments( $activity_ids, current_user_can( 'moderate_comments' ) );
    677671
    678     // multisite again!
     672    // Multisite again!
    679673    restore_current_blog();
    680674
    681     // rebuild activity comment tree
    682     // emulate bp_activity_delete_comment()
     675    // Rebuild activity comment tree
     676    // emulate bp_activity_delete_comment().
    683677    BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id );
    684678
    685     // we're overriding the default bp_activity_delete_comment() functionality
    686     // so we need to return false
     679    // We're overriding the default bp_activity_delete_comment() functionality
     680    // so we need to return false.
    687681    return false;
    688682}
     
    697691 */
    698692function bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $activity ) {
    699     // not an activity comment? stop now!
     693    // Not an activity comment? stop now!
    700694    if ( 'activity_comment' !== $activity->type ) {
    701695        return;
    702696    }
    703697
    704     // this is a new entry, so stop!
    705     // we only want edits!
     698    // This is a new entry, so stop!
     699    // We only want edits!
    706700    if ( empty( $activity->id ) ) {
    707701        return;
    708702    }
    709703
    710     // prevent recursion
     704    // Prevent recursion.
    711705    remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
    712706
    713     // Try to see if a corresponding blog comment exists
     707    // Try to see if a corresponding blog comment exists.
    714708    $post_comment_id = bp_activity_get_meta( $activity->id, 'bp_blogs_post_comment_id' );
    715709
     
    718712    }
    719713
    720     // fetch parent activity item
     714    // Fetch parent activity item.
    721715    $parent_activity = new BP_Activity_Activity( $activity->item_id );
    722716
    723     // sanity check
     717    // Sanity check.
    724718    if ( 'new_blog_post' !== $parent_activity->type ) {
    725719        return;
    726720    }
    727721
    728     // handle multisite
     722    // Handle multisite.
    729723    switch_to_blog( $parent_activity->item_id );
    730724
    731     // update the blog post comment
     725    // Update the blog post comment.
    732726    wp_update_comment( array(
    733727        'comment_ID'      => $post_comment_id,
     
    783777 *
    784778 * @param array $args Arguments passed from bp_parse_args() in bp_has_activities().
    785  *
    786779 * @return array $args
    787780 */
     
    790783    $bp = buddypress();
    791784
    792     // Bail if this is not a 'new_blog_comment' query
     785    // Bail if this is not a 'new_blog_comment' query.
    793786    if ( 'new_blog_comment' !== $args['action'] ) {
    794787        return $args;
     
    802795    }
    803796
    804     // Init the filter query
     797    // Init the filter query.
    805798    $filter_query = array();
    806799
     
    833826    $args['filter_query'] = $filter_query;
    834827
    835     // Make sure to have comment in stream mode && avoid duplicate content
     828    // Make sure to have comment in stream mode && avoid duplicate content.
    836829    $args['display_comments'] = 'stream';
    837830
    838     // Finally reset the action
     831    // Finally reset the action.
    839832    $args['action'] = '';
    840833
    841     // Return the original arguments
     834    // Return the original arguments.
    842835    return $args;
    843836}
     
    864857    }
    865858
    866     // parent not a blog post? stop now!
     859    // Parent not a blog post? stop now!
    867860    if ( 'new_blog_post' !== $activity->type ) {
    868861        return;
     
    873866    }
    874867
    875     // if we've already done this before, stop now!
     868    // If we've already done this before, stop now!
    876869    if ( isset( buddypress()->blogs->allow_comments[ $activity->id ] ) ) {
    877870        return;
     
    881874    $thread_depth   = bp_blogs_get_blogmeta( $activity->item_id, 'thread_comments_depth' );
    882875
    883     // initialize a local object so we won't have to query this again in the
    884     // comment loop
     876    // Initialize a local object so we won't have to query this again in the
     877    // comment loop.
    885878    if ( empty( buddypress()->blogs->allow_comments ) ) {
    886879        buddypress()->blogs->allow_comments = array();
     
    890883    }
    891884
    892     // cache comment settings in the buddypress() singleton to reference later in
     885    // Cache comment settings in the buddypress() singleton to reference later in
    893886    // the activity comment loop
    894887    // @see bp_blogs_disable_activity_replies()
     
    909902 */
    910903function bp_blogs_setup_comment_loop_globals_on_ajax() {
    911     // not AJAX? stop now!
     904    // Not AJAX? stop now!
    912905    if ( ! defined( 'DOING_AJAX' ) ) {
    913906        return;
     
    917910    }
    918911
    919     // get the parent activity item
     912    // Get the parent activity item.
    920913    $comment         = bp_activity_current_comment();
    921914    $parent_activity = new BP_Activity_Activity( $comment->item_id );
    922915
    923     // setup the globals
     916    // Setup the globals.
    924917    bp_blogs_setup_activity_loop_globals( $parent_activity );
    925918}
     
    938931 * @since 2.0.0
    939932 *
    940  * @param bool $retval Is activity commenting enabled for this activity entry?
    941  *
     933 * @param bool $retval Is activity commenting enabled for this activity entry.
    942934 * @return bool
    943935 */
    944936function bp_blogs_disable_activity_commenting( $retval ) {
    945     // if activity commenting is disabled, return current value
     937    // If activity commenting is disabled, return current value.
    946938    if ( bp_disable_blogforum_comments() ) {
    947939        return $retval;
    948940    }
    949941
    950     // activity commenting is enabled for blog posts
     942    // Activity commenting is enabled for blog posts.
    951943    switch ( bp_get_activity_action_name() ) {
    952944
    953         // we still have to disable activity commenting for 'new_blog_comment' items
    954         // commenting should only be done on the parent 'new_blog_post' item
     945        // We still have to disable activity commenting for 'new_blog_comment' items
     946        // commenting should only be done on the parent 'new_blog_post' item.
    955947        case 'new_blog_comment' :
    956948            $retval = false;
     
    958950            break;
    959951
    960         // check if commenting is disabled for the WP blog post
    961         // we should extrapolate this and automate this for plugins... or not
     952        // Check if commenting is disabled for the WP blog post
     953        // we should extrapolate this and automate this for plugins... or not.
    962954        case 'new_blog_post' :
    963955            global $activities_template;
    964956
    965             // setup some globals we'll need to reference later
     957            // Setup some globals we'll need to reference later.
    966958            bp_blogs_setup_activity_loop_globals( $activities_template->activity );
    967959
    968             // if comments are closed for the WP blog post, we should disable
    969             // activity comments for this activity entry
     960            // If comments are closed for the WP blog post, we should disable
     961            // activity comments for this activity entry.
    970962            if ( empty( buddypress()->blogs->allow_comments[bp_get_activity_id()] ) ) {
    971963                $retval = false;
     
    990982 * @since 2.0.0
    991983 *
    992  * @param bool         $retval  Are replies allowed for this activity reply?
     984 * @param bool         $retval  Are replies allowed for this activity reply.
    993985 * @param object|array $comment The activity comment object.
    994986 *
     
    1000992    }
    1001993
    1002     // check comment depth and disable if depth is too large
     994    // Check comment depth and disable if depth is too large.
    1003995    if ( isset( buddypress()->blogs->thread_depth[$comment->item_id] ) ){
    1004996        if ( $comment->mptt_left > buddypress()->blogs->thread_depth[$comment->item_id] ) {
     
    1007999    }
    10081000
    1009     // check if we should disable activity replies based on the parent activity
     1001    // Check if we should disable activity replies based on the parent activity.
    10101002    if ( isset( buddypress()->blogs->allow_comments[$comment->item_id] ) ){
    1011         // the blog post has closed off commenting, so we should disable all activity
    1012         // comments under the parent 'new_blog_post' activity entry
     1003        // The blog post has closed off commenting, so we should disable all activity
     1004        // comments under the parent 'new_blog_post' activity entry.
    10131005        if ( empty( buddypress()->blogs->allow_comments[$comment->item_id] ) ) {
    10141006            $retval = false;
     
    10301022 *
    10311023 * @param string $retval The activity comment permalink.
    1032  *
    10331024 * @return string
    10341025 */
     
    10361027    global $activities_template;
    10371028
    1038     // Get the current comment ID
     1029    // Get the current comment ID.
    10391030    $item_id = isset( $activities_template->activity->current_comment->item_id )
    10401031        ? $activities_template->activity->current_comment->item_id
    10411032        : false;
    10421033
    1043     // Maybe adjust the link if item ID exists
     1034    // Maybe adjust the link if item ID exists.
    10441035    if ( ( false !== $item_id ) && isset( buddypress()->blogs->allow_comments[ $item_id ] ) ) {
    10451036        $retval = $activities_template->activity->current_comment->primary_link;
     
    10581049 *
    10591050 * @param string               $retval   The activity permalink.
    1060  * @param BP_Activity_Activity $activity
    1061  *
     1051 * @param BP_Activity_Activity $activity Activity object.
    10621052 * @return string
    10631053 */
     
    10851075 *
    10861076 * @param string               $retval   The activity action.
    1087  * @param BP_Activity_Activity $activity
    1088  *
     1077 * @param BP_Activity_Activity $activity Activity object.
    10891078 * @return string
    10901079 */
     
    10971086
    10981087    if ( ! empty( $blog_comment_id ) ) {
    1099         // fetch the parent blog post activity item
     1088        // Fetch the parent blog post activity item.
    11001089        $parent_blog_post_activity = new BP_Activity_Activity( $activity->item_id );
    11011090
    1102         // fake a 'new_blog_comment' activity object
     1091        // Fake a 'new_blog_comment' activity object.
    11031092        $object = $activity;
    11041093
    1105         // override 'item_id' to use blog ID
     1094        // Override 'item_id' to use blog ID.
    11061095        $object->item_id = $parent_blog_post_activity->item_id;
    11071096
    1108         // override 'secondary_item_id' to use comment ID
     1097        // Override 'secondary_item_id' to use comment ID.
    11091098        $object->secondary_item_id = $blog_comment_id;
    11101099
    1111         // now format the activity action using the 'new_blog_comment' action callback
     1100        // Now format the activity action using the 'new_blog_comment' action callback.
    11121101        $retval = bp_blogs_format_activity_action_new_blog_comment( '', $object );
    11131102    }
Note: See TracChangeset for help on using the changeset viewer.