Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/14/2009 03:24:05 PM (17 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-activity/bp-activity-classes.php

    r2158 r2168  
    163163    }
    164164
    165     function get_activity_for_user( $user_id, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
    166         global $wpdb, $bp;
    167 
    168         if ( $limit && $page )
    169             $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    170 
    171         if ( $max )
    172             $max_sql = $wpdb->prepare( "LIMIT %d", $max );
    173 
    174         /* Searching */
    175         if ( $search_terms ) {
    176             $search_terms = $wpdb->escape( $search_terms );
    177             $search_sql = "AND content LIKE '%%" . like_escape( $search_terms ) . "%%'";
    178         }
    179 
    180         /* Filtering */
    181         if ( $filter ) {
    182             unset($filter['user_id']); // Unset duplicate user_id filter - TODO: merge all to sitewide.
    183             $filter_sql = BP_Activity_Activity::get_filter_sql( $filter );
    184         }
    185 
    186         /* Sorting */
    187         if ( $sort != 'ASC' && $sort != 'DESC' )
    188             $sort = 'DESC';
    189 
    190         /* Hide Hidden Items? */
    191         if ( !$show_hidden )
    192             $hidden_sql = "AND hide_sitewide = 0";
    193 
    194         /* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
    195         if ( !$display_comments || 'threaded' == $display_comments ) {
    196             if ( $per_page && $page && $max )
    197                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql}", $user_id ) );
    198             else
    199                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}", $user_id ) );
    200 
    201             $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$max_sql}", $user_id ) );
    202 
    203             if ( $activities && $display_comments )
    204                 $activities = BP_Activity_Activity::append_comments( &$activities );
    205         } else {
    206             if ( $per_page && $page && $max )
    207                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} ORDER BY date_recorded {$sort} {$pag_sql}", $user_id ) );
    208             else
    209                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}", $user_id ) );
    210 
    211             $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d {$search_sql} {$filter_sql} {$hidden_sql} ORDER BY date_recorded {$sort} {$max_sql}", $user_id ) );
    212 
    213             if ( $activities )
    214                 $activities = BP_Activity_Activity::append_comments( &$activities );
    215         }
    216 
    217         return array( 'activities' => $activities, 'total' => (int)$total_activities );
    218     }
    219 
    220     function get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $limit, $page, $filter ) {
    221         global $wpdb, $bp;
    222 
    223         // TODO: Max items per friend not yet implemented.
    224 
    225         if ( !function_exists('friends_get_friend_user_ids') )
    226             return false;
    227 
    228         if ( $limit && $page )
    229             $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    230 
    231         if ( $max_items )
    232             $max_sql = $wpdb->prepare( "LIMIT %d", $max_items );
    233 
    234         /* Sort out filtering */
    235         if ( $filter )
    236             $filter_sql = BP_Activity_Activity::get_filter_sql( $filter );
    237 
    238         $friend_ids = friends_get_friend_user_ids( $user_id );
    239 
    240         if ( !$friend_ids )
    241             return false;
    242 
    243         $friend_ids = $wpdb->escape( implode( ',', $friend_ids ) );
    244 
    245         if ( $limit && $page && $max_items )
    246             $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql"  ) );
    247         else
    248             $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql" ) );
    249 
    250         $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT user_id) FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $max_sql" ) );
    251 
    252         return array( 'activities' => $activities, 'total' => (int)$total_activities );
    253     }
    254 
    255     function get_sitewide_activity( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
     165    function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
    256166        global $wpdb, $bp;
    257167
     
    285195        if ( !$display_comments || 'threaded' == $display_comments ) {
    286196            $where_conditions[] = "component_action != 'activity_comment'";
    287             $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
    288 
    289             if ( $per_page && $page && $max )
    290                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$pag_sql}" ) );
    291             else
    292                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}" ) );
    293 
    294             $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$max_sql}" ) );
    295 
    296             if ( $activities && $display_comments )
    297                 $activities = BP_Activity_Activity::append_comments( &$activities );
    298         } else {
    299             /***
    300              * If we are filtering, this is going to stop activity comments showing in the stream,
    301              * we will need to do things slightly differently.
    302              */
    303             if ( !empty( $where_conditions ) )
    304                 $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
    305 
    306              if ( !empty( $filter_sql ) ) {
    307                 $all_activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY id {$sort}" ) );
    308 
    309                 foreach ( (array)$all_activities as $activity ) {
    310                     $tmp_activities[$activity->id] = $activity;
    311                     $a_ids[] = $activity->id;
    312                 }
    313                 $activity_ids = $wpdb->escape( implode( ',', $a_ids ) );
    314 
    315                 /* Fetch the comments for the activity items */
    316                 $search_sql = $where_conditions['search_sql'];
    317                 $all_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE item_id IN ({$activity_ids}) {$search_sql} ORDER BY id {$sort}" ) );
    318 
    319                 foreach ( (array)$all_comments as $comment ) {
    320                     $tmp_comments[$comment->id] = $comment;
    321                 }
    322 
    323                 /* Merge, sort and splice the activities and comments */
    324                 $activities = $tmp_comments + $tmp_activities;
    325                 ksort( $activities );
    326                 $activities = array_reverse( array_merge( array(), (array)$activities ) );
    327                 $activities = array_slice( (array)$activities, intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
    328 
    329                 /* Fetch the totals */
    330                 $total_activities = count($all_activities) + count($all_comments);
    331 
    332              } else {
    333                 if ( $per_page && $page && $max )
    334                     $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY id {$sort} {$pag_sql}" ) );
    335                 else
    336                     $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY id {$sort} {$pag_sql} {$max_sql}" ) );
    337 
    338                 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$max_sql}" ) );
    339              }
    340 
    341             /* Append threaded comments to those activites that have them */
    342             if ( $activities )
    343                 $activities = BP_Activity_Activity::append_comments( &$activities );
    344         }
     197        }
     198
     199        $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
     200
     201        if ( $per_page && $page && $max )
     202            $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$pag_sql}" ) );
     203        else
     204            $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}" ) );
     205
     206        $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$max_sql}" ) );
     207
     208        if ( $activities && $display_comments )
     209            $activities = BP_Activity_Activity::append_comments( &$activities );
    345210
    346211        return array( 'activities' => $activities, 'total' => (int)$total_activities );
Note: See TracChangeset for help on using the changeset viewer.