Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/02/2009 07:54:21 PM (16 years ago)
Author:
apeatling
Message:

Merging 1.1 branch changes and syncing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-classes.php

    r2036 r2077  
    1111    var $date_recorded;
    1212    var $hide_sitewide = false;
    13    
     13
    1414    function bp_activity_activity( $id = false ) {
    1515        global $bp;
    16        
     16
    1717        if ( $id ) {
    1818            $this->id = $id;
     
    2020        }
    2121    }
    22    
     22
    2323    function populate() {
    2424        global $wpdb, $bp;
    25        
     25
    2626        $activity = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) );
    27        
     27
    2828        $this->id = $activity->id;
    2929        $this->item_id = $activity->item_id;
     
    3737        $this->hide_sitewide = $activity->hide_sitewide;
    3838    }
    39    
     39
    4040    function save() {
    4141        global $wpdb, $bp, $current_user;
    42        
     42
    4343        do_action( 'bp_activity_before_save', $this );
    4444
    4545        if ( !$this->component_name || !$this->component_action )
    4646            return false;
    47        
     47
    4848        /***
    4949         * Before v1.1 of BuddyPress, activity content was calculated at a later point. This is no longer the
     
    5454                if ( !$fetched_content = call_user_func( $bp->{$this->component_name}->format_activity_function, $this->item_id, $this->user_id, $this->component_action, $this->secondary_item_id, $this->for_secondary_user ) )
    5555                    return false;
    56                
     56
    5757                $this->content = $fetched_content['content'];
    5858                $this->primary_link = $fetched_content['primary_link'];
    5959            }
    6060        }
    61        
     61
    6262        if ( !$this->primary_link )
    6363            $this->primary_link = $bp->loggedin_user->domain;
    64        
     64
    6565        if ( $existing_activity_id = $this->exists() )
    6666            BP_Activity_Activity::delete_by_activity_id( $existing_activity_id );
    67        
     67
    6868        /* If we have an existing ID, update the activity item, otherwise insert it. */
    6969        if ( $this->id ) {
     
    8181        return false;
    8282    }
    83    
     83
    8484    function exists() {
    8585        global $wpdb, $bp;
    86        
     86
    8787        /* This doesn't seem to be working correctly at the moment, so it is disabled [TODO] */
    8888        return false;
    89        
     89
    9090        /* If we have an item id, try and match on that, if not do a content match */
    9191        if ( $this->item_id ) {
    9292            if ( $this->secondary_item_id )
    9393                $secondary_sql = $wpdb->prepare( " AND secondary_item_id = %s", $secondary_item_id );
    94                
    95             return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND item_id = %s{$secondary_sql} AND component_name = %s AND component_action = %s", $this->user_id, $this->item_id, $this->component_name, $this->component_action ) );     
     94
     95            return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND item_id = %s{$secondary_sql} AND component_name = %s AND component_action = %s", $this->user_id, $this->item_id, $this->component_name, $this->component_action ) );
    9696        } else {
    97             return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $this->user_id, $this->content, $this->component_name, $this->component_action ) );             
    98         }
    99     }
    100    
    101     /* Static Functions */ 
     97            return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $this->user_id, $this->content, $this->component_name, $this->component_action ) );
     98        }
     99    }
     100
     101    /* Static Functions */
    102102
    103103    function delete( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) {
     
    106106        if ( $secondary_item_id )
    107107            $secondary_sql = $wpdb->prepare( "AND secondary_item_id = %s", $secondary_item_id );
    108        
     108
    109109        if ( $component_action )
    110110            $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action );
    111        
     111
    112112        if ( $user_id )
    113113            $user_sql = $wpdb->prepare( "AND user_id = %d", $user_id );
     
    115115        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component_name = %s {$component_action_sql} {$user_sql}", $item_id, $component_name ) );
    116116    }
    117    
     117
    118118    function delete_by_item_id( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) {
    119119        return BP_Activity_Activity::delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
     
    122122    function delete_by_activity_id( $activity_id ) {
    123123        global $bp, $wpdb;
    124        
     124
    125125        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE id = %d", $activity_id ) );
    126126    }
    127    
     127
    128128    function delete_by_content( $user_id, $content, $component_name, $component_action ) {
    129129        global $bp, $wpdb;
    130        
    131         return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $user_id, $content, $component_name, $component_action ) );       
    132     }
    133    
     130
     131        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $user_id, $content, $component_name, $component_action ) );
     132    }
     133
    134134    function delete_for_user_by_component( $user_id, $component_name ) {
    135135        global $bp, $wpdb;
    136        
    137         return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component_name = %s", $user_id, $component_name ) );       
    138     }
    139    
     136
     137        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component_name = %s", $user_id, $component_name ) );
     138    }
     139
    140140    function delete_for_user( $user_id ) {
    141141        global $wpdb, $bp;
     
    143143        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d", $user_id ) );
    144144    }
    145    
     145
    146146    function get_activity_for_user( $user_id, $max_items, $limit, $page, $filter ) {
    147147        global $wpdb, $bp;
    148                
     148
    149149        if ( $limit && $page )
    150150            $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     
    152152        if ( $max_items )
    153153            $max_sql = $wpdb->prepare( "LIMIT %d", $max_items );
    154        
     154
    155155        /* Sort out filtering */
    156156        if ( $filter )
    157157            $filter_sql = BP_Activity_Activity::get_filter_sql( $filter );
    158        
     158
    159159        if ( $limit && $page && $max_items )
    160160            $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $pag_sql", $user_id ) );
    161161        else
    162162            $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql", $user_id ) );
    163        
     163
    164164        $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $max_sql", $user_id ) );
    165        
     165
    166166        return array( 'activities' => $activities, 'total' => (int)$total_activities );
    167167    }
    168    
     168
    169169    function get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $limit, $page, $filter ) {
    170170        global $wpdb, $bp;
    171        
     171
    172172        // TODO: Max items per friend not yet implemented.
    173        
     173
    174174        if ( !function_exists('friends_get_friend_user_ids') )
    175175            return false;
     
    177177        if ( $limit && $page )
    178178            $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    179        
     179
    180180        if ( $max_items )
    181181            $max_sql = $wpdb->prepare( "LIMIT %d", $max_items );
     
    189189        if ( !$friend_ids )
    190190            return false;
    191            
     191
    192192        $friend_ids = implode( ',', $friend_ids );
    193        
     193
    194194        if ( $limit && $page && $max_items )
    195             $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"  ) ); 
     195            $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"  ) );
    196196        else
    197             $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" ) );           
    198 
    199         $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(user_id) FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $max_sql" ) ); 
    200        
     197            $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" ) );
     198
     199        $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(user_id) FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $max_sql" ) );
     200
    201201        return array( 'activities' => $activities, 'total' => (int)$total_activities );
    202202    }
    203    
     203
    204204    function get_sitewide_activity( $max, $limit, $page, $filter ) {
    205205        global $wpdb, $bp;
    206        
     206
    207207        if ( $limit && $page )
    208208            $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    209        
     209
    210210        if ( $max )
    211211            $max_sql = $wpdb->prepare( "LIMIT %d", $max );
    212            
     212
    213213        /* Sort out filtering */
    214214        if ( $filter )
     
    224224        return array( 'activities' => $activities, 'total' => (int)$total_activities );
    225225    }
    226    
     226
    227227    function get_recorded_component_names() {
    228228        global $wpdb, $bp;
    229        
     229
    230230        return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT component_name FROM {$bp->activity->table_name} ORDER BY component_name ASC" ) );
    231231    }
    232    
     232
    233233    function get_sitewide_items_for_feed( $limit = 35 ) {
    234234        global $wpdb, $bp;
    235        
     235
    236236        $activities = bp_activity_get_sitewide_activity( $limit );
    237237        for ( $i = 0; $i < count($activities); $i++ ) {
     
    244244        }
    245245
    246         return $activity_feed; 
    247     }
    248    
     246        return $activity_feed;
     247    }
     248
    249249    function get_filter_sql( $filter_array ) {
    250250        global $wpdb;
    251        
     251
    252252        if ( !empty( $filter_array['object'] ) ) {
    253253            $object_filter = explode( ',', $filter_array['object'] );
    254254            $object_sql = ' AND ( ';
    255            
     255
    256256            $counter = 1;
    257257            foreach( (array) $object_filter as $object ) {
    258258                $object_sql .= $wpdb->prepare( "component_name = %s", trim( $object ) );
    259                
     259
    260260                if ( $counter != count( $object_filter ) )
    261261                    $object_sql .= ' || ';
    262                
     262
    263263                $counter++;
    264264            }
    265            
     265
    266266            $object_sql .= ' )';
    267267        }
     
    270270            $action_filter = explode( ',', $filter_array['action'] );
    271271            $action_sql = ' AND ( ';
    272            
     272
    273273            $counter = 1;
    274274            foreach( (array) $action_filter as $action ) {
    275275                $action_sql .= $wpdb->prepare( "component_action = %s", trim( $action ) );
    276                
     276
    277277                if ( $counter != count( $action_filter ) )
    278278                    $action_sql .= ' || ';
    279                
     279
    280280                $counter++;
    281281            }
    282            
     282
    283283            $action_sql .= ' )';
    284284        }
     
    287287            $pid_filter = explode( ',', $filter_array['primary_id'] );
    288288            $pid_sql = ' AND ( ';
    289            
     289
    290290            $counter = 1;
    291291            foreach( (array) $pid_filter as $pid ) {
    292292                $pid_sql .= $wpdb->prepare( "item_id = %s", trim( $pid ) );
    293                
     293
    294294                if ( $counter != count( $pid_filter ) )
    295295                    $pid_sql .= ' || ';
    296                
     296
    297297                $counter++;
    298298            }
    299            
     299
    300300            $pid_sql .= ' )';
    301301        }
     
    304304            $sid_filter = explode( ',', $filter_array['secondary_id'] );
    305305            $sid_sql = ' AND ( ';
    306            
     306
    307307            $counter = 1;
    308308            foreach( (array) $sid_filter as $sid ) {
    309309                $sid_sql .= $wpdb->prepare( "secondary_item_id = %s", trim( $sid ) );
    310                
     310
    311311                if ( $counter != count( $sid_filter ) )
    312312                    $sid_sql .= ' || ';
    313                
     313
    314314                $counter++;
    315315            }
    316            
     316
    317317            $sid_sql .= ' )';
    318318        }
    319        
     319
    320320        return $object_sql . $action_sql . $pid_sql . $sid_sql;
    321321    }
    322    
     322
    323323    function get_last_updated() {
    324324        global $bp, $wpdb;
    325        
     325
    326326        return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded ASC LIMIT 1" ) );
    327327    }
    328    
     328
    329329    function check_exists_by_content( $content ) {
    330330        global $wpdb, $bp;
Note: See TracChangeset for help on using the changeset viewer.