Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/12/2015 05:45:14 AM (9 years ago)
Author:
tw2113
Message:

Further documentation cleanup for Activity Component.

See #6396.

File:
1 edited

Legend:

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

    r10077 r10253  
    99 */
    1010
    11 // Exit if accessed directly
     11// Exit if accessed directly.
    1212defined( 'ABSPATH' ) || exit;
    1313
     
    5151function bp_activity_action_permalink_router() {
    5252
    53     // Not viewing activity
     53    // Not viewing activity.
    5454    if ( ! bp_is_activity_component() || ! bp_is_current_action( 'p' ) )
    5555        return false;
    5656
    57     // No activity to display
     57    // No activity to display.
    5858    if ( ! bp_action_variable( 0 ) || ! is_numeric( bp_action_variable( 0 ) ) )
    5959        return false;
    6060
    61     // Get the activity details
     61    // Get the activity details.
    6262    $activity = bp_activity_get_specific( array( 'activity_ids' => bp_action_variable( 0 ), 'show_hidden' => true ) );
    6363
     
    7070    }
    7171
    72     // Do not redirect at default
     72    // Do not redirect at default.
    7373    $redirect = false;
    7474
    75     // Redirect based on the type of activity
     75    // Redirect based on the type of activity.
    7676    if ( bp_is_active( 'groups' ) && $activity->component == buddypress()->groups->id ) {
    7777
    78         // Activity is a user update
     78        // Activity is a user update.
    7979        if ( ! empty( $activity->user_id ) ) {
    8080            $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';
    8181
    82         // Activity is something else
     82        // Activity is something else.
    8383        } else {
    8484
    85             // Set redirect to group activity stream
     85            // Set redirect to group activity stream.
    8686            if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
    8787                $redirect = bp_get_group_permalink( $group ) . bp_get_activity_slug() . '/' . $activity->id . '/';
     
    8989        }
    9090
    91     // Set redirect to users' activity stream
     91    // Set redirect to users' activity stream.
    9292    } elseif ( ! empty( $activity->user_id ) ) {
    9393        $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';
    9494    }
    9595
    96     // If set, add the original query string back onto the redirect URL
     96    // If set, add the original query string back onto the redirect URL.
    9797    if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
    9898        $query_frags = array();
     
    112112    }
    113113
    114     // Redirect to the actual activity permalink page
     114    // Redirect to the actual activity permalink page.
    115115    bp_core_redirect( $redirect );
    116116}
     
    121121 *
    122122 * @since 1.1.0
    123  *
    124  * @param int $activity_id Activity id to be deleted. Defaults to 0.
    125123 *
    126124 * @uses bp_is_activity_component()
     
    135133 * @uses bp_core_redirect()
    136134 *
     135 * @param int $activity_id Activity id to be deleted. Defaults to 0.
    137136 * @return bool False on failure.
    138137 */
    139138function bp_activity_action_delete_activity( $activity_id = 0 ) {
    140139
    141     // Not viewing activity or action is not delete
     140    // Not viewing activity or action is not delete.
    142141    if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) )
    143142        return false;
     
    146145        $activity_id = (int) bp_action_variable( 0 );
    147146
    148     // Not viewing a specific activity item
     147    // Not viewing a specific activity item.
    149148    if ( empty( $activity_id ) )
    150149        return false;
    151150
    152     // Check the nonce
     151    // Check the nonce.
    153152    check_admin_referer( 'bp_activity_delete_link' );
    154153
    155     // Load up the activity item
     154    // Load up the activity item.
    156155    $activity = new BP_Activity_Activity( $activity_id );
    157156
    158     // Check access
     157    // Check access.
    159158    if ( ! bp_activity_user_can_delete( $activity ) )
    160159        return false;
     
    170169    do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id );
    171170
    172     // Delete the activity item and provide user feedback
     171    // Delete the activity item and provide user feedback.
    173172    if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
    174173        bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) );
     
    186185    do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
    187186
    188     // Check for the redirect query arg, otherwise let WP handle things
     187    // Check for the redirect query arg, otherwise let WP handle things.
    189188    if ( !empty( $_GET['redirect_to'] ) )
    190189        bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
     
    200199 *
    201200 * @param int $activity_id Activity id to be deleted. Defaults to 0.
    202  *
    203201 * @return bool False on failure.
    204202 */
     
    206204    $bp = buddypress();
    207205
    208     // Not viewing activity, or action is not spam, or Akismet isn't present
     206    // Not viewing activity, or action is not spam, or Akismet isn't present.
    209207    if ( !bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) )
    210208        return false;
     
    213211        $activity_id = (int) bp_action_variable( 0 );
    214212
    215     // Not viewing a specific activity item
     213    // Not viewing a specific activity item.
    216214    if ( empty( $activity_id ) )
    217215        return false;
     
    221219        return false;
    222220
    223     // Load up the activity item
     221    // Load up the activity item.
    224222    $activity = new BP_Activity_Activity( $activity_id );
    225223    if ( empty( $activity->id ) )
    226224        return false;
    227225
    228     // Check nonce
     226    // Check nonce.
    229227    check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id );
    230228
     
    239237    do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
    240238
    241     // Mark as spam
     239    // Mark as spam.
    242240    bp_activity_mark_as_spam( $activity );
    243241    $activity->save();
    244242
    245     // Tell the user the spamming has been successful
     243    // Tell the user the spamming has been successful.
    246244    bp_core_add_message( __( 'The activity item has been marked as spam and is no longer visible.', 'buddypress' ) );
    247245
     
    256254    do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id );
    257255
    258     // Check for the redirect query arg, otherwise let WP handle things
     256    // Check for the redirect query arg, otherwise let WP handle things.
    259257    if ( !empty( $_GET['redirect_to'] ) )
    260258        bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
     
    287285function bp_activity_action_post_update() {
    288286
    289     // Do not proceed if user is not logged in, not viewing activity, or not posting
     287    // Do not proceed if user is not logged in, not viewing activity, or not posting.
    290288    if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'post' ) )
    291289        return false;
    292290
    293     // Check the nonce
     291    // Check the nonce.
    294292    check_admin_referer( 'post_update', '_wpnonce_post_update' );
    295293
     
    327325    }
    328326
    329     // No activity content so provide feedback and redirect
     327    // No activity content so provide feedback and redirect.
    330328    if ( empty( $content ) ) {
    331329        bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
     
    333331    }
    334332
    335     // No existing item_id
     333    // No existing item_id.
    336334    if ( empty( $item_id ) ) {
    337335        $activity_id = bp_activity_post_update( array( 'content' => $content ) );
    338336
    339     // Post to groups object
     337    // Post to groups object.
    340338    } elseif ( 'groups' == $object && bp_is_active( 'groups' ) ) {
    341339        if ( (int) $item_id ) {
     
    357355    }
    358356
    359     // Provide user feedback
     357    // Provide user feedback.
    360358    if ( !empty( $activity_id ) )
    361359        bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
     
    363361        bp_core_add_message( __( 'There was an error when posting your update. Please try again.', 'buddypress' ), 'error' );
    364362
    365     // Redirect
     363    // Redirect.
    366364    bp_core_redirect( wp_get_referer() );
    367365}
     
    391389        return false;
    392390
    393     // Check the nonce
     391    // Check the nonce.
    394392    check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
    395393
     
    454452        return false;
    455453
    456     // Check the nonce
     454    // Check the nonce.
    457455    check_admin_referer( 'mark_favorite' );
    458456
     
    488486        return false;
    489487
    490     // Check the nonce
     488    // Check the nonce.
    491489    check_admin_referer( 'unmark_favorite' );
    492490
     
    518516        return false;
    519517
    520     // setup the feed
     518    // Setup the feed.
    521519    buddypress()->activity->feed = new BP_Activity_Feed( array(
    522520        'id'            => 'sitewide',
     
    548546    }
    549547
    550     // setup the feed
     548    // Setup the feed.
    551549    buddypress()->activity->feed = new BP_Activity_Feed( array(
    552550        'id'            => 'personal',
     
    581579    }
    582580
    583     // setup the feed
     581    // Setup the feed.
    584582    buddypress()->activity->feed = new BP_Activity_Feed( array(
    585583        'id'            => 'friends',
     
    614612    }
    615613
    616     // get displayed user's group IDs
     614    // Get displayed user's group IDs.
    617615    $groups    = groups_get_user_groups();
    618616    $group_ids = implode( ',', $groups['groups'] );
    619617
    620     // setup the feed
     618    // Setup the feed.
    621619    buddypress()->activity->feed = new BP_Activity_Feed( array(
    622620        'id'            => 'mygroups',
     
    657655    }
    658656
    659     // setup the feed
     657    // Setup the feed.
    660658    buddypress()->activity->feed = new BP_Activity_Feed( array(
    661659        'id'            => 'mentions',
     
    690688    }
    691689
    692     // get displayed user's favorite activity IDs
     690    // Get displayed user's favorite activity IDs.
    693691    $favs = bp_activity_get_user_favorites( bp_displayed_user_id() );
    694692    $fav_ids = implode( ',', (array) $favs );
    695693
    696     // setup the feed
     694    // Setup the feed.
    697695    buddypress()->activity->feed = new BP_Activity_Feed( array(
    698696        'id'            => 'favorites',
     
    717715    $bp = buddypress();
    718716
    719     // Bail if Akismet is not active
     717    // Bail if Akismet is not active.
    720718    if ( ! defined( 'AKISMET_VERSION' ) ) {
    721719        return;
    722720    }
    723721
    724     // Bail if older version of Akismet
     722    // Bail if older version of Akismet.
    725723    if ( ! class_exists( 'Akismet' ) ) {
    726724        return;
    727725    }
    728726
    729     // Bail if no Akismet key is set
     727    // Bail if no Akismet key is set.
    730728    if ( ! bp_get_option( 'wordpress_api_key' ) && ! defined( 'WPCOM_API_KEY' ) ) {
    731729        return;
     
    743741    }
    744742
    745     // Instantiate Akismet for BuddyPress
     743    // Instantiate Akismet for BuddyPress.
    746744    $bp->activity->akismet = new BP_Akismet();
    747745}
     
    828826    // Unpublishing a previously published post.
    829827    } elseif ( 'publish' === $old_status ) {
    830         // Some form of pending status - only remove the activity entry
     828        // Some form of pending status - only remove the activity entry.
    831829        bp_activity_post_type_unpublish( $post->ID, $post );
    832830    }
Note: See TracChangeset for help on using the changeset viewer.