Skip to:
Content

BuddyPress.org

Changeset 3728 for trunk/bp-friends.php


Ignore:
Timestamp:
01/18/2011 12:53:31 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Code normalization and whitespace clean-up. Introduce bp-core-deprecated.php. Introduce root_slug globals into components with directories, to help with WP page slugs. Fixes #2600. Optimus Props boonebgorges

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-friends.php

    r3633 r3728  
    11<?php
    22
     3// Required Files
     4require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-classes.php' );
     5require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-templatetags.php' );
     6
    37define ( 'BP_FRIENDS_DB_VERSION', '1800' );
    48
    5 /* Define the slug for the component */
     9// Define the slug for the component
    610if ( !defined( 'BP_FRIENDS_SLUG' ) )
    711    define ( 'BP_FRIENDS_SLUG', 'friends' );
    812
    9 require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-classes.php' );
    10 require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-templatetags.php' );
    11 
    1213function friends_setup_globals() {
    1314    global $bp;
    1415
    15     /* For internal identification */
     16    // For internal identification
    1617    $bp->friends->id = 'friends';
    1718
     19    // Slug
    1820    $bp->friends->slug = BP_FRIENDS_SLUG;
    1921
     22    // Table
    2023    $bp->friends->table_name = $bp->table_prefix . 'bp_friends';
    2124
     25    // Notifications
    2226    $bp->friends->format_notification_function = 'friends_format_notifications';
    2327
    24     /* Register this in the active components array */
     28    // Register this in the active components array
    2529    $bp->active_components[$bp->friends->slug] = $bp->friends->id;
    2630
     
    3236    global $bp;
    3337
    34     /* Add 'Friends' to the main navigation */
     38    // Add 'Friends' to the main navigation
    3539    bp_core_new_nav_item( array( 'name' => sprintf( __( 'Friends <span>(%d)</span>', 'buddypress' ), friends_get_total_friend_count() ), 'slug' => $bp->friends->slug, 'position' => 60, 'screen_function' => 'friends_screen_my_friends', 'default_subnav_slug' => 'my-friends', 'item_css_id' => $bp->friends->id ) );
    3640
    3741    $friends_link = $bp->loggedin_user->domain . $bp->friends->slug . '/';
    3842
    39     /* Add the subnav items to the friends nav item */
    40     bp_core_new_subnav_item( array( 'name' => __( 'My Friends', 'buddypress' ), 'slug' => 'my-friends', 'parent_url' => $friends_link, 'parent_slug' => $bp->friends->slug, 'screen_function' => 'friends_screen_my_friends', 'position' => 10, 'item_css_id' => 'friends-my-friends' ) );
    41     bp_core_new_subnav_item( array( 'name' => __( 'Requests', 'buddypress' ), 'slug' => 'requests', 'parent_url' => $friends_link, 'parent_slug' => $bp->friends->slug, 'screen_function' => 'friends_screen_requests', 'position' => 20, 'user_has_access' => bp_is_my_profile() ) );
     43    // Add the subnav items to the friends nav item
     44    bp_core_new_subnav_item( array( 'name' => __( 'My Friends', 'buddypress' ), 'slug' => 'my-friends', 'parent_url' => $friends_link, 'parent_slug' => $bp->friends->slug, 'screen_function' => 'friends_screen_my_friends', 'position' => 10, 'item_css_id'     => 'friends-my-friends' ) );
     45    bp_core_new_subnav_item( array( 'name' => __( 'Requests',   'buddypress' ), 'slug' => 'requests',   'parent_url' => $friends_link, 'parent_slug' => $bp->friends->slug, 'screen_function' => 'friends_screen_requests',   'position' => 20, 'user_has_access' => bp_is_my_profile()  ) );
    4246
    4347    if ( $bp->current_component == $bp->friends->slug ) {
     
    7781
    7882    if ( isset( $bp->action_variables[0] ) && isset( $bp->action_variables[1] ) && 'accept' == $bp->action_variables[0] && is_numeric( $bp->action_variables[1] ) ) {
    79         /* Check the nonce */
     83        // Check the nonce
    8084        check_admin_referer( 'friends_accept_friendship' );
    8185
     
    8892
    8993    } elseif ( isset( $bp->action_variables[0] ) && isset( $bp->action_variables[1] ) && 'reject' == $bp->action_variables[0] && is_numeric( $bp->action_variables[1] ) ) {
    90         /* Check the nonce */
     94        // Check the nonce
    9195        check_admin_referer( 'friends_reject_friendship' );
    9296
     
    110114    global $bp;
    111115
    112     $send_requests = get_user_meta( $bp->displayed_user->id, 'notification_friends_friendship_request', true );
    113     if ( !$send_requests )
    114         $send_requests = 'yes';
    115 
    116     $accept_requests = get_user_meta( $bp->displayed_user->id, 'notification_friends_friendship_accepted', true );
    117     if ( !$accept_requests )
     116   
     117    if ( !$send_requests = get_user_meta( $bp->displayed_user->id, 'notification_friends_friendship_request', true ) )
     118        $send_requests   = 'yes';
     119
     120    if ( !$accept_requests = get_user_meta( $bp->displayed_user->id, 'notification_friends_friendship_accepted', true ) )
    118121        $accept_requests = 'yes';
    119122?>
     123
    120124    <table class="notification-settings zebra" id="friends-notification-settings">
    121125        <thead>
     
    143147
    144148            <?php do_action( 'friends_screen_notification_settings' ); ?>
     149
    145150        </tbody>
    146151    </table>
     152
    147153<?php
    148154}
     
    184190            bp_core_add_message( __( 'Friendship requested', 'buddypress' ) );
    185191        }
     192
    186193    } else if ( 'is_friend' == $friendship_status ) {
    187194        bp_core_add_message( __( 'You are already friends with this user', 'buddypress' ), 'error' );
     
    222229            bp_core_add_message( __( 'Friendship canceled', 'buddypress' ) );
    223230        }
     231
    224232    } else if ( 'is_friends' == $friendship_status ) {
    225233        bp_core_add_message( __( 'You are not yet friends with this user', 'buddypress' ), 'error' );
     
    248256        return false;
    249257
    250     $defaults = array(
    251         'user_id' => $bp->loggedin_user->id,
    252         'action' => '',
    253         'content' => '',
    254         'primary_link' => '',
    255         'component' => $bp->friends->id,
    256         'type' => false,
    257         'item_id' => false,
     258    $defaults = array (
     259        'user_id'           => $bp->loggedin_user->id,
     260        'action'            => '',
     261        'content'           => '',
     262        'primary_link'      => '',
     263        'component'         => $bp->friends->id,
     264        'type'              => false,
     265        'item_id'           => false,
    258266        'secondary_item_id' => false,
    259         'recorded_time' => bp_core_current_time(),
    260         'hide_sitewide' => false
     267        'recorded_time'     => bp_core_current_time(),
     268        'hide_sitewide'     => false
    261269    );
    262270
     
    300308                return apply_filters( 'bp_friends_single_friendship_accepted_notification', '<a href="' . $user_url . '?new" title="' . $user_fullname .'\'s profile">' . sprintf( __( '%s accepted your friendship request', 'buddypress' ), $user_fullname ) . '</a>', $user_fullname );
    301309            }
    302         break;
     310            break;
    303311
    304312        case 'friendship_request':
     
    310318                return apply_filters( 'bp_friends_single_friendship_request_notification', '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/requests/?new" title="' . __( 'Friendship requests', 'buddypress' ) . '">' . sprintf( __('You have a friendship request from %s', 'buddypress' ), $user_fullname ) . '</a>', $user_fullname );
    311319            }
    312         break;
     320            break;
    313321    }
    314322
     
    337345
    338346    $friendship->initiator_user_id = $initiator_userid;
    339     $friendship->friend_user_id = $friend_userid;
    340     $friendship->is_confirmed = 0;
    341     $friendship->is_limited = 0;
    342     $friendship->date_created = bp_core_current_time();
     347    $friendship->friend_user_id    = $friend_userid;
     348    $friendship->is_confirmed      = 0;
     349    $friendship->is_limited        = 0;
     350    $friendship->date_created      = bp_core_current_time();
    343351
    344352    if ( $force_accept )
     
    370378
    371379    $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid );
    372     $friendship = new BP_Friends_Friendship( $friendship_id );
     380    $friendship    = new BP_Friends_Friendship( $friendship_id );
    373381
    374382    // Remove the activity stream item for the user who canceled the friendship
     
    427435
    428436        do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
     437
    429438        return true;
    430439    }
     
    456465}
    457466
     467// Returns - 'is_friend', 'not_friends', 'pending'
    458468function friends_check_friendship_status( $user_id, $possible_friend_id ) {
    459     /* Returns - 'is_friend', 'not_friends', 'pending' */
    460469    return BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id );
    461470}
    462471
    463 function friends_get_total_friend_count( $user_id = false ) {
     472function friends_get_total_friend_count( $user_id = 0 ) {
    464473    global $bp;
    465474
     
    504513}
    505514
    506 function friends_get_recently_active( $user_id, $per_page = false, $page = false, $filter = false ) {
     515function friends_get_recently_active( $user_id, $per_page = 0, $page = 0, $filter = '' ) {
    507516    return apply_filters( 'friends_get_recently_active', BP_Core_User::get_users( 'active', $per_page, $page, $user_id, $filter ) );
    508517}
    509518
    510 function friends_get_alphabetically( $user_id, $per_page = false, $page = false, $filter = false ) {
     519function friends_get_alphabetically( $user_id, $per_page = 0, $page = 0, $filter = '' ) {
    511520    return apply_filters( 'friends_get_alphabetically', BP_Core_User::get_users( 'alphabetical', $per_page, $page, $user_id, $filter ) );
    512521}
    513522
    514 function friends_get_newest( $user_id, $per_page = false, $page = false, $filter = false ) {
     523function friends_get_newest( $user_id, $per_page = 0, $page = 0, $filter = '' ) {
    515524    return apply_filters( 'friends_get_newest', BP_Core_User::get_users( 'newest', $per_page, $page, $user_id, $filter ) );
    516525}
     
    520529}
    521530
    522 function friends_get_friends_invite_list( $user_id = false ) {
     531function friends_get_friends_invite_list( $user_id = 0 ) {
    523532    global $bp;
    524533
     
    549558}
    550559
    551 function friends_search_users( $search_terms, $user_id, $pag_num = false, $pag_page = false ) {
     560function friends_search_users( $search_terms, $user_id, $pag_num = 0, $pag_page = 0 ) {
    552561    global $bp;
    553562
     
    557566        return false;
    558567
    559     for ( $i = 0; $i < count($user_ids); $i++ ) {
     568    for ( $i = 0; $i < count( $user_ids ); $i++  )
    560569        $users[] = new BP_Core_User($user_ids[$i]);
    561     }
    562 
    563     return array( 'users' => $users, 'count' => BP_Friends_Friendship::search_users_count($search_terms) );
     570
     571    return array( 'users' => $users, 'count' => BP_Friends_Friendship::search_users_count( $search_terms ) );
    564572}
    565573
     
    584592    BP_Friends_Friendship::delete_all_for_user($user_id);
    585593
    586     /* Remove usermeta */
     594    // Remove usermeta
    587595    delete_user_meta( $user_id, 'total_friend_count' );
    588596
    589     /* Remove friendship requests FROM user */
     597    // Remove friendship requests FROM user
    590598    bp_core_delete_notifications_from_user( $user_id, $bp->friends->id, 'friendship_request' );
    591599
    592600    do_action( 'friends_remove_data', $user_id );
    593601}
    594 add_action( 'wpmu_delete_user', 'friends_remove_data' );
    595 add_action( 'delete_user', 'friends_remove_data' );
     602add_action( 'wpmu_delete_user',  'friends_remove_data' );
     603add_action( 'delete_user',       'friends_remove_data' );
    596604add_action( 'bp_make_spam_user', 'friends_remove_data' );
    597605
     
    608616        return false;
    609617
    610     wp_cache_delete( 'friends_friend_ids_' . $friendship->initiator_user_id, 'bp' );
    611     wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' );
     618    wp_cache_delete( 'friends_friend_ids_' .    $friendship->initiator_user_id, 'bp' );
     619    wp_cache_delete( 'friends_friend_ids_' .    $friendship->friend_user_id,    'bp' );
    612620    wp_cache_delete( 'bp_total_friend_count_' . $friendship->initiator_user_id, 'bp' );
    613     wp_cache_delete( 'bp_total_friend_count_' . $friendship->friend_user_id, 'bp' );
     621    wp_cache_delete( 'bp_total_friend_count_' . $friendship->friend_user_id,    'bp' );
    614622}
    615623
     
    624632// List actions to clear object caches on
    625633add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' );
    626 add_action( 'friends_friendship_deleted', 'friends_clear_friend_object_cache' );
     634add_action( 'friends_friendship_deleted',  'friends_clear_friend_object_cache' );
    627635
    628636// List actions to clear super cached pages on, if super cache is installed
    629 add_action( 'friends_friendship_rejected', 'bp_core_clear_cache' );
    630 add_action( 'friends_friendship_accepted', 'bp_core_clear_cache' );
    631 add_action( 'friends_friendship_deleted', 'bp_core_clear_cache' );
     637add_action( 'friends_friendship_rejected',  'bp_core_clear_cache' );
     638add_action( 'friends_friendship_accepted',  'bp_core_clear_cache' );
     639add_action( 'friends_friendship_deleted',   'bp_core_clear_cache' );
    632640add_action( 'friends_friendship_requested', 'bp_core_clear_cache' );
    633641
Note: See TracChangeset for help on using the changeset viewer.