Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/14/2009 03:24:05 PM (14 years ago)
Author:
apeatling
Message:

Committing core code support for new default theme.

Removed all deprecated code since it will be released as a separate plugin for backwards compatibility if people need it.

Removed the wire and status updates components since there is no support in the theme for these. If people still want this functionality then I'm sure there is someone in the community that could spend a bit of time and release them as plugins. I'm happy to guide.

Removed a lot of template loop duplication. There are no longer site loops and user loops (e.g. bp_has_site_groups() / bp_has_groups() ). There are now bp_has_members(), bp_has_groups(), bp_has_blogs() and you can pass a "user_id" parameter into these loops to limit results to only that user or users.

Merged activity stream functions. There are no longer functions for bp_activity_get_sitewide() / bp_activity_get_for_user() / bp_activity_get_friends_activity() instead there is simply one function: bp_activity_get() and you can pass in parameters to filter on just friends, for a single user, or anything your heart desires. Actually, filtering is extremely fine grained, so I encourage devs to check out the filter functions.

Lots of other code cleanup.

The new default theme will be committed straight after this. The original default folder will be renamed to bp-classic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-friends/bp-friends-templatetags.php

    r2128 r2168  
    11<?php
    22
    3 class BP_Friendship_Template {
    4     var $current_friendship = -1;
    5     var $friendship_count;
    6     var $friendships;
    7     var $friendship;
    8 
    9     var $in_the_loop;
    10 
    11     var $pag_page;
    12     var $pag_num;
    13     var $pag_links;
    14     var $total_friend_count;
    15 
    16     function bp_friendship_template( $user_id, $type, $per_page, $max, $filter ) {
    17         global $bp;
    18 
    19         if ( !$user_id )
    20             $user_id = $bp->displayed_user->id;
    21 
    22         $this->pag_page = isset( $_REQUEST['frpage'] ) ? intval( $_REQUEST['frpage'] ) : 1;
    23         $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
    24         $this->type = $type;
    25 
    26         switch ( $type ) {
    27             case 'newest':
    28                 $this->friendships = friends_get_newest( $user_id, $this->pag_num, $this->pag_page, $filter );
    29                 break;
    30 
    31             case 'alphabetical':
    32                 $this->friendships = friends_get_alphabetically( $user_id, $this->pag_num, $this->pag_page, $filter );
    33                 break;
    34 
    35             case 'requests':
    36                 $this->friendships = friends_get_friendship_requests( $user_id );
    37                 break;
    38 
    39             case 'active': default:
    40                 $this->friendships = friends_get_recently_active( $user_id, $this->pag_num, $this->pag_page, $filter );
    41                 break;
    42         }
    43 
    44         if ( 'requests' == $type ) {
    45             $this->total_friend_count = $this->friendships['total'];
    46             $this->friendships = $this->friendships['requests'];
    47             $this->friendship_count = count($this->friendships);
    48         } else {
    49             if ( !$max || $max >= (int)$this->friendships['total'] )
    50                 $this->total_friend_count = (int)$this->friendships['total'];
    51             else
    52                 $this->total_friend_count = (int)$max;
    53 
    54             $this->friendships = $this->friendships['friends'];
    55 
    56             if ( $max ) {
    57                 if ( $max >= count($this->friendships) )
    58                     $this->friendship_count = count($this->friendships);
    59                 else
    60                     $this->friendship_count = (int)$max;
    61             } else {
    62                 $this->friendship_count = count($this->friendships);
    63             }
    64         }
    65 
    66         $this->pag_links = paginate_links( array(
    67             'base' => add_query_arg( 'frpage', '%#%' ),
    68             'format' => '',
    69             'total' => ceil($this->total_friend_count / $this->pag_num),
    70             'current' => $this->pag_page,
    71             'prev_text' => '&laquo;',
    72             'next_text' => '&raquo;',
    73             'mid_size' => 1
    74         ));
    75     }
    76 
    77     function has_friendships() {
    78         if ( $this->friendship_count )
    79             return true;
    80 
    81         return false;
    82     }
    83 
    84     function next_friendship() {
    85         $this->current_friendship++;
    86         $this->friendship = $this->friendships[$this->current_friendship];
    87 
    88         return $this->friendship;
    89     }
    90 
    91     function rewind_friendships() {
    92         $this->current_friendship = -1;
    93         if ( $this->friendship_count > 0 ) {
    94             $this->friendship = $this->friendships[0];
    95         }
    96     }
    97 
    98     function user_friendships() {
    99         if ( $this->current_friendship + 1 < $this->friendship_count ) {
    100             return true;
    101         } elseif ( $this->current_friendship + 1 == $this->friendship_count ) {
    102             do_action('loop_end');
    103             // Do some cleaning up after the loop
    104             $this->rewind_friendships();
    105         }
    106 
    107         $this->in_the_loop = false;
    108         return false;
    109     }
    110 
    111     function the_friendship() {
    112         global $friendship, $bp;
    113 
    114         $this->in_the_loop = true;
    115         $this->friendship = $this->next_friendship();
    116 
    117         if ( 'requests' == $this->type ) {
    118             $this->friendship = new BP_Friends_Friendship( $this->friendship );
    119             $this->friendship->user_id = ( $this->friendship->friend_user_id == $bp->loggedin_user->id ) ?  $this->friendship->initiator_user_id : $this->friendship->friend_user_id;
    120         } else {
    121             if ( 'newest' == $this->type )
    122                 $user_id = $this->friendship;
    123             else
    124                 $user_id = $this->friendship->user_id;
    125 
    126             $this->friendship = new stdClass;
    127 
    128             if ( !$this->friendship->friend = wp_cache_get( 'bp_user_' . $user_id, 'bp' ) ) {
    129                 $this->friendship->friend = new BP_Core_User( $user_id );
    130                 wp_cache_set( 'bp_user_' . $user_id, $this->friendship->friend, 'bp' );
    131             }
    132 
    133             /* Make sure the user_id is available in the friend object. */
    134             $this->friendship->friend->user_id = $user_id;
    135         }
    136 
    137         if ( 0 == $this->current_friendship ) // loop has just started
    138             do_action('loop_start');
    139     }
    140 }
    141 
    142 function bp_has_friendships( $args = '' ) {
    143     global $bp, $friends_template;
    144 
    145     $defaults = array(
    146         'type' => 'active',
    147         'user_id' => false,
    148         'per_page' => 10,
    149         'max' => false,
    150         'filter' => false
    151     );
    152 
    153     $r = wp_parse_args( $args, $defaults );
    154     extract( $r, EXTR_SKIP );
    155 
    156     /* The following code will auto set parameters based on the page being viewed.
    157      * for example on example.com/members/andy/friends/my-friends/newest/
    158      * $type = 'newest'
    159      */
    160     if ( 'my-friends' == $bp->current_action ) {
    161         $order = $bp->action_variables[0];
    162         if ( 'newest' == $order )
    163             $type = 'newest';
    164         else if ( 'alphabetically' == $order )
    165             $type = 'alphabetical';
    166     } else if ( 'requests' == $bp->current_action ) {
    167         $type = 'requests';
    168     }
    169 
    170     if ( isset( $_REQUEST['friend-search-box'] ) )
    171         $filter = $_REQUEST['friend-search-box'];
    172 
    173     $friends_template = new BP_Friendship_Template( $user_id, $type, $per_page, $max, $filter );
    174     return apply_filters( 'bp_has_friendships', $friends_template->has_friendships(), &$friends_template );
    175 }
    176 
    177 function bp_the_friendship() {
    178     global $friends_template;
    179     return $friends_template->the_friendship();
    180 }
    181 
    182 function bp_user_friendships() {
    183     global $friends_template;
    184     return $friends_template->user_friendships();
    185 }
    186 
    187 function bp_friend_id() {
    188     echo bp_get_friend_id();
    189 }
    190     function bp_get_friend_id() {
    191         global $friends_template;
    192 
    193         return apply_filters( 'bp_get_friend_id', $friends_template->friendship->friend->user_id );
    194     }
    195 
    196 function bp_friend_avatar_thumb( $args = '' ) {
    197     echo bp_get_friend_avatar_thumb( $args );
    198 }
    199     function bp_get_friend_avatar_thumb( $args = '' ) {
    200         global $bp, $friends_template;
    201 
    202         $defaults = array(
    203             'type' => 'thumb',
    204             'width' => false,
    205             'height' => false,
    206             'class' => 'avatar',
    207             'id' => false,
    208             'alt' => __( 'Group avatar', 'buddypress' )
    209         );
    210 
    211         $r = wp_parse_args( $args, $defaults );
    212         extract( $r, EXTR_SKIP );
    213 
    214         return apply_filters( 'bp_get_friend_avatar_thumb', bp_core_fetch_avatar( array( 'item_id' => $friends_template->friendship->friend->id, 'type' => $type, 'alt' => $alt, 'width' => $width, 'height' => $height, 'class' => $class ) ) );
    215     }
    216 
    217 function bp_friend_name() {
    218     echo bp_get_friend_name();
    219 }
    220     function bp_get_friend_name() {
    221         global $friends_template;
    222 
    223         return apply_filters( 'bp_get_friend_name', strip_tags( $friends_template->friendship->friend->user_link ) );
    224     }
    225 
    226 function bp_friend_link() {
    227     echo bp_get_friend_link();
    228 }
    229     function bp_get_friend_link() {
    230         global $friends_template;
    231 
    232         return apply_filters( 'bp_get_friend_link', $friends_template->friendship->friend->user_link );
    233     }
    234 
    235 function bp_friend_url() {
    236     echo bp_get_friend_url();
    237 }
    238     function bp_get_friend_url() {
    239         global $friends_template;
    240 
    241         return apply_filters( 'bp_get_friend_url', $friends_template->friendship->friend->user_url );
    242     }
    243 
    244 function bp_friend_last_active() {
    245     echo bp_get_friend_last_active();
    246 }
    247     function bp_get_friend_last_active() {
    248         global $friends_template;
    249 
    250         return apply_filters( 'bp_get_friend_last_active', $friends_template->friendship->friend->last_active );
    251     }
    252 
    253 function bp_friend_time_since_requested() {
    254     echo bp_get_friend_time_since_requested();
    255 }
    256     function bp_get_friend_time_since_requested() {
    257         global $friends_template;
    258 
    259         if ( $friends_template->friendship->date_created != "0000-00-00 00:00:00" ) {
    260             return apply_filters( 'bp_friend_time_since_requested', sprintf( __( 'requested %s ago', 'buddypress' ), bp_core_time_since( strtotime( $friends_template->friendship->date_created ) ) ) );
    261         }
    262 
    263         return false;
    264     }
    265 
    266 function bp_friend_accept_request_link() {
    267     echo bp_get_friend_accept_request_link();
    268 }
    269     function bp_get_friend_accept_request_link() {
    270         global $friends_template, $bp;
    271 
    272         return apply_filters( 'bp_get_friend_accept_request_link', wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/requests/accept/' . $friends_template->friendship->id, 'friends_accept_friendship' ) );
    273     }
    274 
    275 function bp_friend_reject_request_link() {
    276     echo bp_get_friend_reject_request_link();
    277 }
    278     function bp_get_friend_reject_request_link() {
    279         global $friends_template, $bp;
    280 
    281         return apply_filters( 'bp_get_friend_reject_request_link', wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/requests/reject/' . $friends_template->friendship->id, 'friends_reject_friendship' ) );
    282     }
    283 
    284 function bp_friend_pagination() {
    285     echo bp_get_friend_pagination();
    286 }
    287     function bp_get_friend_pagination() {
    288         global $friends_template;
    289 
    290         return apply_filters( 'bp_friend_pagination', $friends_template->pag_links );
    291     }
    292 
    293 function bp_friend_pagination_count() {
    294     global $bp, $friends_template;
    295 
    296     $from_num = intval( ( $friends_template->pag_page - 1 ) * $friends_template->pag_num ) + 1;
    297     $to_num = ( $from_num + ( $friends_template->pag_num - 1 ) > $friends_template->total_friend_count ) ? $friends_template->total_friend_count : $from_num + ( $friends_template->pag_num - 1) ;
    298 
    299     echo sprintf( __( 'Viewing friend %d to %d (of %d friends)', 'buddypress' ), $from_num, $to_num, $friends_template->total_friend_count ); ?> &nbsp;
    300     <span class="ajax-loader"></span><?php
    301 }
    302 
    303 function bp_friend_total_for_member() {
    304     echo bp_get_friend_total_for_member();
    305 }
    306     function bp_get_friend_total_for_member() {
    307         return apply_filters( 'bp_get_friend_total_for_member', BP_Friends_Friendship::total_friend_count() );
    308     }
    309 
    310 function bp_friend_search_form() {
    311     global $friends_template, $bp;
    312 
    313     $action = $bp->displayed_user->domain . $bp->friends->slug . '/my-friends/search/';
    314     $label = __( 'Filter Friends', 'buddypress' );
    315 ?>
    316     <form action="<?php echo $action ?>" id="friend-search-form" method="post">
    317 
    318         <label for="friend-search-box" id="friend-search-label"><?php echo $label ?></label>
    319         <input type="search" name="friend-search-box" id="friend-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> />
    320 
    321         <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?>
    322         <input type="hidden" name="initiator" id="initiator" value="<?php echo attribute_escape( $bp->displayed_user->id ) ?>" />
    323 
    324     </form>
    325 <?php
    326 }
    327 
    328 function bp_friends_is_filtered() {
    329     if ( isset( $_POST['friend-search-box'] ) )
    330         return true;
    331 
    332     return false;
    333 }
    334 
    335 function bp_friend_all_friends_link() {
     3function bp_friends_header_tabs() {
    3364    global $bp;
    337     echo apply_filters( 'bp_friend_all_friends_link', $bp->displayed_user->domain . 'my-friends/all-friends' );
    338 }
    339 
    340 function bp_friend_latest_update_link() {
    341     global $bp;
    342     echo apply_filters( 'bp_friend_latest_update_link', $bp->displayed_user->domain . 'my-friends/last-updated' );
    343 }
    344 
    345 function bp_friend_recent_activity_link() {
    346     global $bp;
    347     echo apply_filters( 'bp_friend_recent_activity_link', $bp->displayed_user->domain . 'my-friends/recently-active' );
    348 }
    349 
    350 function bp_friend_recent_status_link() {
    351     global $bp;
    352     echo apply_filters( 'bp_friend_recent_status_link', $bp->displayed_user->domain . 'my-friends/status-updates' );
    353 }
    354 
    355 function bp_add_friend_button( $potential_friend_id = false ) {
    356     echo bp_get_add_friend_button( $potential_friend_id );
    357 }
    358     function bp_get_add_friend_button( $potential_friend_id = false ) {
    359         global $bp, $friends_template;
    360 
    361         $button = false;
    362 
    363         if ( is_user_logged_in() ) {
    364 
    365             if ( !$potential_friend_id && $friends_template->friendship->friend )
    366                 $potential_friend_id = $friends_template->friendship->friend->id;
    367             else if ( !$potential_friend_id && !$friends_template->friendship->friend )
    368                 $potential_friend_id = $bp->displayed_user->id;
    369 
    370             if ( $bp->loggedin_user->id == $potential_friend_id )
    371                 return false;
    372 
    373             $friend_status = BP_Friends_Friendship::check_is_friend( $bp->loggedin_user->id, $potential_friend_id );
    374 
    375             $button = '<div class="generic-button friendship-button ' . $friend_status . '" id="friendship-button-' . $potential_friend_id . '">';
    376             if ( 'pending' == $friend_status ) {
    377                 $button .= '<a class="requested" href="' . $bp->loggedin_user->domain . $bp->friends->slug . '">' . __( 'Friendship Requested', 'buddypress' ) . '</a>';
    378             } else if ( 'is_friend' == $friend_status ) {
    379                 $button .= '<a href="' . wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/remove-friend/' . $potential_friend_id, 'friends_remove_friend' ) . '" title="' . __('Cancel Friendship', 'buddypress') . '" id="friend-' . $potential_friend_id . '" rel="remove" class="remove">' . __('Cancel Friendship', 'buddypress') . '</a>';
    380             } else {
    381                 $button .= '<a href="' . wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/add-friend/' . $potential_friend_id, 'friends_add_friend' ) . '" title="' . __('Add Friend', 'buddypress') . '" id="friend-' . $potential_friend_id . '" rel="add" class="add">' . __('Add Friend', 'buddypress') . '</a>';
    382             }
    383             $button .= '</div>';
    384         }
    385 
    386         return apply_filters( 'bp_get_add_friend_button', $button );
    387     }
    388 
    389 function bp_friends_header_tabs() {
    390     global $bp, $create_group_step, $completed_to_step;
    3915?>
    3926    <li<?php if ( !isset($bp->action_variables[0]) || 'recently-active' == $bp->action_variables[0] ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->friends->slug ?>/my-friends/recently-active"><?php _e( 'Recently Active', 'buddypress' ) ?></a></li>
     
    48397}
    48498
     99function bp_friend_search_form() {
     100    global $friends_template, $bp;
     101
     102    $action = $bp->displayed_user->domain . $bp->friends->slug . '/my-friends/search/';
     103    $label = __( 'Filter Friends', 'buddypress' );
     104    ?>
     105        <form action="<?php echo $action ?>" id="friend-search-form" method="post">
     106
     107        <label for="friend-search-box" id="friend-search-label"><?php echo $label ?></label>
     108        <input type="search" name="friend-search-box" id="friend-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> />
     109
     110        <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?>
     111        <input type="hidden" name="initiator" id="initiator" value="<?php echo attribute_escape( $bp->displayed_user->id ) ?>" />
     112
     113        </form>
     114    <?php
     115}
     116
     117function bp_add_friend_button( $potential_friend_id = false ) {
     118    echo bp_get_add_friend_button( $potential_friend_id );
     119}
     120    function bp_get_add_friend_button( $potential_friend_id = false ) {
     121        global $bp, $friends_template;
     122
     123        $button = false;
     124
     125        if ( is_user_logged_in() ) {
     126
     127            if ( !$potential_friend_id && $friends_template->friendship->friend )
     128                $potential_friend_id = $friends_template->friendship->friend->id;
     129            else if ( !$potential_friend_id && !$friends_template->friendship->friend )
     130                $potential_friend_id = $bp->displayed_user->id;
     131
     132            if ( $bp->loggedin_user->id == $potential_friend_id )
     133                return false;
     134
     135            $friend_status = BP_Friends_Friendship::check_is_friend( $bp->loggedin_user->id, $potential_friend_id );
     136
     137            $button = '<div class="generic-button friendship-button ' . $friend_status . '" id="friendship-button-' . $potential_friend_id . '">';
     138            if ( 'pending' == $friend_status ) {
     139                $button .= '<a class="requested" href="' . $bp->loggedin_user->domain . $bp->friends->slug . '">' . __( 'Friendship Requested', 'buddypress' ) . '</a>';
     140            } else if ( 'is_friend' == $friend_status ) {
     141                $button .= '<a href="' . wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/remove-friend/' . $potential_friend_id, 'friends_remove_friend' ) . '" title="' . __('Cancel Friendship', 'buddypress') . '" id="friend-' . $potential_friend_id . '" rel="remove" class="remove">' . __('Cancel Friendship', 'buddypress') . '</a>';
     142            } else {
     143                $button .= '<a href="' . wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/add-friend/' . $potential_friend_id, 'friends_add_friend' ) . '" title="' . __('Add Friend', 'buddypress') . '" id="friend-' . $potential_friend_id . '" rel="add" class="add">' . __('Add Friend', 'buddypress') . '</a>';
     144            }
     145            $button .= '</div>';
     146        }
     147
     148        return apply_filters( 'bp_get_add_friend_button', $button );
     149    }
     150
     151function bp_get_friend_ids( $user_id = false ) {
     152    global $bp;
     153
     154    if ( !$user_id )
     155        $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
     156
     157    return implode( ',', friends_get_friend_user_ids( $user_id ) );
     158}
     159function bp_get_friendship_requests() {
     160    global $bp;
     161
     162    return apply_filters( 'bp_get_friendship_requests', implode( ',', (array) friends_get_friendship_request_user_ids( $bp->loggedin_user->id ) ) );
     163}
     164
     165function bp_friend_accept_request_link() {
     166    echo bp_get_friend_accept_request_link();
     167}
     168    // You only have the user ID but you need the friendship ID !!
     169
     170    function bp_get_friend_accept_request_link() {
     171        global $members_template, $bp;
     172
     173        if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id ) ) {
     174            $friendship_id = friends_get_friendship_id( $members_template->member->id, $bp->loggedin_user->id );
     175            wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id, $friendship_id, 'bp' );
     176        }
     177
     178        return apply_filters( 'bp_get_friend_accept_request_link', wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/requests/accept/' . $friendship_id, 'friends_accept_friendship' ) );
     179    }
     180
     181function bp_friend_reject_request_link() {
     182    echo bp_get_friend_reject_request_link();
     183}
     184    function bp_get_friend_reject_request_link() {
     185        global $members_template, $bp;
     186
     187        if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id ) ) {
     188            $friendship_id = friends_get_friendship_id( $members_template->member->id, $bp->loggedin_user->id );
     189            wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id, $friendship_id, 'bp' );
     190        }
     191
     192        return apply_filters( 'bp_get_friend_reject_request_link', wp_nonce_url( $bp->loggedin_user->domain . $bp->friends->slug . '/requests/reject/' . $friendship_id, 'friends_reject_friendship' ) );
     193    }
     194
    485195?>
Note: See TracChangeset for help on using the changeset viewer.