Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/06/2009 03:07:48 AM (17 years ago)
Author:
apeatling
Message:

Converted $bp as an array to $bp as an object. See this post for more info: http://buddypress.org/forums/topic.php?id=1125

File:
1 edited

Legend:

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

    r909 r1021  
    3131                global $wpdb, $bp;
    3232               
    33                 $activity = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $this->table_name . " WHERE id = %d", $this->id ) );
     33                $activity = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE id = %d", $this->id ) );
    3434
    3535                $this->item_id = $activity->item_id;
     
    5555                if ( !$this->exists() ) {
    5656                        // Insert the new activity into the activity table.
    57                         $activity = $wpdb->query( $wpdb->prepare( "INSERT INTO " . $this->table_name . " ( item_id, secondary_item_id, user_id, component_name, component_action, date_recorded, is_private, no_sitewide_cache ) VALUES ( %d, %d, %d, %s, %s, FROM_UNIXTIME(%d), %d, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_recorded, $this->is_private, $this->no_sitewide_cache ) );
     57                        $activity = $wpdb->query( $wpdb->prepare( "INSERT INTO {$this->table_name} ( item_id, secondary_item_id, user_id, component_name, component_action, date_recorded, is_private, no_sitewide_cache ) VALUES ( %d, %d, %d, %s, %s, FROM_UNIXTIME(%d), %d, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_recorded, $this->is_private, $this->no_sitewide_cache ) );
    5858
    5959                        // Fetch the formatted activity content so we can add it to the cache.
    60                         if ( function_exists( $bp[$this->component_name]['format_activity_function'] ) ) {
    61                                 if ( !$activity_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 ) )
     60                        if ( function_exists( $bp->{$this->component_name}->format_activity_function ) ) {
     61                                if ( !$activity_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 ) )
    6262                                        return false;
    6363                        }
    6464                       
    6565                        // Add the cached version of the activity to the cached activity table.
    66                         $activity_cached = $wpdb->query( $wpdb->prepare( "INSERT INTO " . $this->table_name_cached . " ( item_id, secondary_item_id, content, primary_link, component_name, component_action, date_cached, date_recorded, is_private ) VALUES ( %d, %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d), %d )", $this->item_id, $this->secondary_item_id, $activity_content['content'], $activity_content['primary_link'], $this->component_name, $this->component_action, time(), $this->date_recorded, $this->is_private ) );
     66                        $activity_cached = $wpdb->query( $wpdb->prepare( "INSERT INTO {$this->table_name_cached} ( item_id, secondary_item_id, content, primary_link, component_name, component_action, date_cached, date_recorded, is_private ) VALUES ( %d, %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d), %d )", $this->item_id, $this->secondary_item_id, $activity_content['content'], $activity_content['primary_link'], $this->component_name, $this->component_action, time(), $this->date_recorded, $this->is_private ) );
    6767                       
    6868                        // Add the cached version of the activity to the sitewide activity table.
    6969                        if ( !$this->no_sitewide_cache )
    70                                 $sitewide_cached = $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp['activity']['table_name_sitewide'] . " ( user_id, item_id, secondary_item_id, content, primary_link, component_name, component_action, date_cached, date_recorded ) VALUES ( %d, %d, %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d) )", $this->user_id, $this->item_id, $this->secondary_item_id, $activity_content['content'], $activity_content['primary_link'], $this->component_name, $this->component_action, time(), $this->date_recorded ) );
     70                                $sitewide_cached = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->activity->table_name_sitewide} ( user_id, item_id, secondary_item_id, content, primary_link, component_name, component_action, date_cached, date_recorded ) VALUES ( %d, %d, %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d) )", $this->user_id, $this->item_id, $this->secondary_item_id, $activity_content['content'], $activity_content['primary_link'], $this->component_name, $this->component_action, time(), $this->date_recorded ) );
    7171                       
    7272                        if ( $activity && $activity_cached )
     
    7979        function exists() {
    8080                global $wpdb, $bp;
    81                 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM " . $this->table_name . " WHERE item_id = %d AND secondary_item_id = %d AND user_id = %d AND component_name = %s AND component_action = %s", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action ) );               
     81                return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$this->table_name} WHERE item_id = %d AND secondary_item_id = %d AND user_id = %d AND component_name = %s AND component_action = %s", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action ) );             
    8282        }
    8383       
     
    9090                        return false;
    9191               
    92                 if ( !$bp['activity'] )
     92                if ( !$bp->activity )
    9393                        bp_activity_setup_globals();
    9494               
     
    9898                //error_log($wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) );
    9999                //error_log($wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity_cached WHERE item_id = %d{$secondary_sql} AND component_name = %s AND component_action = %s", $item_id, $component_name, $component_action ) );
    100                 //error_log($wpdb->prepare( "DELETE FROM " . $bp['activity']['table_name_sitewide'] . " WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) );
     100                //error_log($wpdb->prepare( "DELETE FROM " . $bp->activity->table_name_sitewide . " WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) );
    101101               
    102102                $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) );
     
    104104                // Delete this entry from the users' cache table and the sitewide cache table
    105105                $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}user_{$user_id}_activity_cached WHERE item_id = %d{$secondary_sql} AND component_name = %s AND component_action = %s", $item_id, $component_name, $component_action ) );
    106                 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['activity']['table_name_sitewide'] . " WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) );
     106                $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_sitewide} WHERE item_id = %d{$secondary_sql} AND user_id = %d AND component_name = %s AND component_action = %s", $item_id, $user_id, $component_name, $component_action ) );
    107107               
    108108                return true;
     
    113113               
    114114                if ( !$user_id )
    115                         $user_id = $bp['current_userid'];
     115                        $user_id = $bp->displayed_user->id;
    116116               
    117117                if ( !$user_id )
     
    127127               
    128128                /* Determine whether or not to use the cached activity stream, or re-select and cache a new stream */
    129                 $last_cached = get_usermeta( $bp['current_userid'], 'bp_activity_last_cached' );
     129                $last_cached = get_usermeta( $bp->displayed_user->id, 'bp_activity_last_cached' );
    130130               
    131131                if ( strtotime( BP_ACTIVITY_CACHE_LENGTH, (int)$last_cached ) >= time() ) {
     
    134134                       
    135135                        // Use the cached activity stream.
    136                         $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp['activity']['table_name_current_user_cached'] . " WHERE date_recorded >= FROM_UNIXTIME(%d) $privacy_sql ORDER BY date_recorded DESC $limit_sql", $since ) );
     136                        $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name_current_user_cached} WHERE date_recorded >= FROM_UNIXTIME(%d) $privacy_sql ORDER BY date_recorded DESC $limit_sql", $since ) );
    137137       
    138138                        for ( $i = 0; $i < count( $activities ); $i++ ) {
     
    152152                       
    153153                        // Reselect, format and cache a new activity stream. Override the limit otherwise we might only cache 5 items when viewing a profile page.
    154                         $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp['activity']['table_name_current_user'] . " WHERE date_recorded >= FROM_UNIXTIME(%d) $privacy_sql ORDER BY date_recorded DESC LIMIT 30", $since ) );
     154                        $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name_current_user} WHERE date_recorded >= FROM_UNIXTIME(%d) $privacy_sql ORDER BY date_recorded DESC LIMIT 30", $since ) );
    155155
    156156                        for ( $i = 0; $i < count( $activities ); $i++ ) {                       
    157                                 if ( function_exists( $bp[$activities[$i]->component_name]['format_activity_function'] ) ) {   
    158                                         if ( !$content = call_user_func($bp[$activities[$i]->component_name]['format_activity_function'], $activities[$i]->item_id, $activities[$i]->user_id, $activities[$i]->component_action, $activities[$i]->secondary_item_id ) )
     157                                if ( function_exists( $bp->{$activities[$i]->component_name}->format_activity_function ) ) {   
     158                                        if ( !$content = call_user_func( $bp->{$activities[$i]->component_name}->format_activity_function, $activities[$i]->item_id, $activities[$i]->user_id, $activities[$i]->component_action, $activities[$i]->secondary_item_id ) )
    159159                                                continue;
    160160                                       
     
    199199               
    200200                /* Determine whether or not to use the cached friends activity stream, or re-select and cache a new stream */
    201                 $last_cached = get_usermeta( $bp['loggedin_userid'], 'bp_activity_friends_last_cached' );
     201                $last_cached = get_usermeta( $bp->loggedin_user->id, 'bp_activity_friends_last_cached' );
    202202               
    203203                if ( strtotime( BP_ACTIVITY_CACHE_LENGTH, (int)$last_cached ) >= time() ) {
     
    206206                       
    207207                        // Use the cached activity stream.
    208                         $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp['activity']['table_name_loggedin_user_friends_cached'] . " ORDER BY date_recorded DESC $limit_sql" ) );
     208                        $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name_loggedin_user_friends_cached} ORDER BY date_recorded DESC $limit_sql" ) );
    209209               
    210210                        for ( $i = 0; $i < count( $activities ); $i++ ) {
     
    231231                                $table_name = $wpdb->base_prefix . 'user_' . $friend_ids[$i] . '_activity_cached';
    232232
    233                                 $activities[$i]['activity'] = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $table_name . " WHERE is_private = 0 ORDER BY date_recorded $limit_sql" ) );
     233                                $activities[$i]['activity'] = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_name} WHERE is_private = 0 ORDER BY date_recorded $limit_sql" ) );
    234234                                $activities[$i]['full_name'] = bp_fetch_user_fullname( $friend_ids[$i], false );
    235235                        }
     
    265265               
    266266                /* Remove entries that are older than 6 months */
    267                 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['activity']['table_name_sitewide'] . " WHERE DATE_ADD(date_recorded, INTERVAL 6 MONTH) <= NOW()" ) );
    268                
    269                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp['activity']['table_name_sitewide'] . " ORDER BY date_recorded DESC $limit_sql" ) );
     267                $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->activity->table_name_sitewide . " WHERE DATE_ADD(date_recorded, INTERVAL 6 MONTH) <= NOW()" ) );
     268               
     269                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp->activity->table_name_sitewide . " ORDER BY date_recorded DESC $limit_sql" ) );
    270270               
    271271                for ( $i = 0; $i < count( $activities ); $i++ ) {
     
    289289                                $activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) );
    290290                                $activity_feed[$i]['link'] = $activities[$i]['primary_link'];
    291                                 $activity_feed[$i]['description'] = sprintf ( $activities[$i]['content'], '' );
     291                                $activity_feed[$i]['description'] = sprintf( $activities[$i]['content'], '' );
    292292                                $activity_feed[$i]['pubdate'] = $activities[$i]['date_recorded'];
    293293                }
     
    300300               
    301301                /* Empty the cache */
    302                 $wpdb->query( "TRUNCATE TABLE " . $bp['activity']['table_name_loggedin_user_friends_cached'] );
     302                $wpdb->query( "TRUNCATE TABLE {$bp->activity->table_name_loggedin_user_friends_cached}" );
    303303               
    304304                for ( $i = 0; $i < count($activity_array); $i++ ) {
    305305                        // Cache that sucka...
    306                         $cached = $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp['activity']['table_name_loggedin_user_friends_cached'] . " ( user_id, content, primary_link, component_name, component_action, date_cached, date_recorded ) VALUES ( %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), %s )", $activity_array[$i]['user_id'], $activity_array[$i]['content'], $activity_array[$i]['primary_link'], $activity_array[$i]['component_name'], $activity_array[$i]['component_action'], time(), $activity_array[$i]['date_recorded'] ) );
    307                 }
    308                
    309                 update_usermeta( $bp['loggedin_userid'], 'bp_activity_friends_last_cached', time() );
     306                        $cached = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->activity->table_name_loggedin_user_friends_cached} ( user_id, content, primary_link, component_name, component_action, date_cached, date_recorded ) VALUES ( %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), %s )", $activity_array[$i]['user_id'], $activity_array[$i]['content'], $activity_array[$i]['primary_link'], $activity_array[$i]['component_name'], $activity_array[$i]['component_action'], time(), $activity_array[$i]['date_recorded'] ) );
     307                }
     308               
     309                update_usermeta( $bp->loggedin_user->id, 'bp_activity_friends_last_cached', time() );
    310310        }
    311311       
     
    314314
    315315                /* Empty the cache */
    316                 $wpdb->query( "TRUNCATE TABLE " . $bp['activity']['table_name_current_user_cached'] );
     316                $wpdb->query( "TRUNCATE TABLE {$bp->activity->table_name_current_user_cached}" );
    317317               
    318318                /* Empty user's activities from the sitewide stream */
    319                 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['activity']['table_name_sitewide'] . " WHERE user_id = %d", $user_id ) );
     319                $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->activity->table_name_sitewide . " WHERE user_id = %d", $user_id ) );
    320320               
    321321                for ( $i = 0; $i < count($activity_array); $i++ ) {
     
    323323                       
    324324                        // Cache that sucka...
    325                         $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp['activity']['table_name_current_user_cached'] . " ( content, item_id, secondary_item_id, primary_link, component_name, component_action, date_cached, date_recorded, is_private ) VALUES ( %s, %d, %d, %s, %s, %s, FROM_UNIXTIME(%d), %s, %d )", $activity_array[$i]['content'], $activity_array[$i]['item_id'], $activity_array[$i]['secondary_item_id'], $activity_array[$i]['primary_link'], $activity_array[$i]['component_name'], $activity_array[$i]['component_action'], time(), $activity_array[$i]['date_recorded'], $activity_array[$i]['is_private'] ) );
     325                        $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp->activity->table_name_current_user_cached . " ( content, item_id, secondary_item_id, primary_link, component_name, component_action, date_cached, date_recorded, is_private ) VALUES ( %s, %d, %d, %s, %s, %s, FROM_UNIXTIME(%d), %s, %d )", $activity_array[$i]['content'], $activity_array[$i]['item_id'], $activity_array[$i]['secondary_item_id'], $activity_array[$i]['primary_link'], $activity_array[$i]['component_name'], $activity_array[$i]['component_action'], time(), $activity_array[$i]['date_recorded'], $activity_array[$i]['is_private'] ) );
    326326                       
    327327                        // Add to the sitewide activity stream
    328328                        if ( !$activity_array[$i]['is_private'] && !$activity_array[$i]['no_sitewide_cache'] )
    329                                 $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp['activity']['table_name_sitewide'] . " ( user_id, content, item_id, secondary_item_id, primary_link, component_name, component_action, date_cached, date_recorded ) VALUES ( %d, %s, %d, %d, %s, %s, %s, FROM_UNIXTIME(%d), %s )", $user_id, $activity_array[$i]['content'], $activity_array[$i]['item_id'], $activity_array[$i]['secondary_item_id'], $activity_array[$i]['primary_link'], $activity_array[$i]['component_name'], $activity_array[$i]['component_action'], time(), $activity_array[$i]['date_recorded'] ) );
    330                 }
    331                
    332                 update_usermeta( $bp['current_userid'], 'bp_activity_last_cached', time() );
     329                                $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp->activity->table_name_sitewide . " ( user_id, content, item_id, secondary_item_id, primary_link, component_name, component_action, date_cached, date_recorded ) VALUES ( %d, %s, %d, %d, %s, %s, %s, FROM_UNIXTIME(%d), %s )", $user_id, $activity_array[$i]['content'], $activity_array[$i]['item_id'], $activity_array[$i]['secondary_item_id'], $activity_array[$i]['primary_link'], $activity_array[$i]['component_name'], $activity_array[$i]['component_action'], time(), $activity_array[$i]['date_recorded'] ) );
     330                }
     331               
     332                update_usermeta( $bp->displayed_user->id, 'bp_activity_last_cached', time() );
    333333        }
    334334       
     
    337337
    338338                /* Empty user's activities from the sitewide stream */
    339                 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['activity']['table_name_sitewide'] . " WHERE user_id = %d", $user_id ) );
     339                $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->activity->table_name_sitewide . " WHERE user_id = %d", $user_id ) );
    340340
    341341                /* Empty the user's activity items and cached activity items */
     
    349349                global $bp, $wpdb;
    350350               
    351                 return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM " . $bp['activity']['table_name_sitewide'] . " ORDER BY date_recorded ASC LIMIT 1" ) );
     351                return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM " . $bp->activity->table_name_sitewide . " ORDER BY date_recorded ASC LIMIT 1" ) );
    352352        }
    353353       
Note: See TracChangeset for help on using the changeset viewer.