Changeset 1839
- Timestamp:
- 09/10/2009 01:24:01 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity.php
r1819 r1839 352 352 } 353 353 354 function bp_activity_get_user_activity( $user_id, $max_items = 30, $ since = '-4 weeks', $pag_num = false, $pag_page = false, $filter = false ) {355 return BP_Activity_Activity::get_activity_for_user( $user_id, $max_items, $ since, $pag_num, $pag_page, $filter );356 } 357 358 function bp_activity_get_friends_activity( $user_id, $max_items = 30, $ since = '-4 weeks', $max_items_per_friend = false, $pag_num = false, $pag_page = false, $filter = false ) {359 return BP_Activity_Activity::get_activity_for_friends( $user_id, $max_items, $ since, $max_items_per_friend, $pag_num, $pag_page, $filter );354 function bp_activity_get_user_activity( $user_id, $max_items = 30, $pag_num = false, $pag_page = false, $filter = false ) { 355 return BP_Activity_Activity::get_activity_for_user( $user_id, $max_items, $pag_num, $pag_page, $filter ); 356 } 357 358 function bp_activity_get_friends_activity( $user_id, $max_items = 30, $max_items_per_friend = false, $pag_num = false, $pag_page = false, $filter = false ) { 359 return BP_Activity_Activity::get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $pag_num, $pag_page, $filter ); 360 360 } 361 361 -
trunk/bp-activity/bp-activity-classes.php
r1819 r1839 144 144 } 145 145 146 function get_activity_for_user( $user_id, $max_items, $ since, $limit, $page, $filter ) {146 function get_activity_for_user( $user_id, $max_items, $limit, $page, $filter ) { 147 147 global $wpdb, $bp; 148 148 … … 155 155 $max_sql = $wpdb->prepare( "LIMIT %d", $max_items ); 156 156 157 /* Sort out filtering */ 157 158 if ( $filter ) 158 $filter_sql = $wpdb->prepare( "AND component_name = %s",$filter );159 $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ); 159 160 160 161 if ( $limit && $page && $max_items ) 161 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d AND date_recorded >= FROM_UNIXTIME(%d) $privacy_sql $filter_sql ORDER BY date_recorded DESC $pag_sql", $user_id, $since) );162 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d $privacy_sql $filter_sql ORDER BY date_recorded DESC $pag_sql", $user_id ) ); 162 163 else 163 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d AND date_recorded >= FROM_UNIXTIME(%d) $privacy_sql $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql", $user_id, $since) );164 165 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d AND date_recorded >= FROM_UNIXTIME(%d) $privacy_sql $filter_sql ORDER BY date_recorded DESC $max_sql", $user_id, $since) );164 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d $privacy_sql $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql", $user_id ) ); 165 166 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d $privacy_sql $filter_sql ORDER BY date_recorded DESC $max_sql", $user_id ) ); 166 167 167 168 return array( 'activities' => $activities, 'total' => (int)$total_activities ); 168 169 } 169 170 170 function get_activity_for_friends( $user_id, $max_items, $ since, $max_items_per_friend, $limit, $page, $filter ) {171 function get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $limit, $page, $filter ) { 171 172 global $wpdb, $bp; 172 173 … … 182 183 $max_sql = $wpdb->prepare( "LIMIT %d", $max_items ); 183 184 185 /* Sort out filtering */ 184 186 if ( $filter ) 185 $filter_sql = $wpdb->prepare( "AND component_name = %s", $filter ); 186 187 $since = strtotime($since); 187 $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ); 188 188 189 189 $friend_ids = friends_get_friend_user_ids( $user_id ); … … 195 195 196 196 if ( $limit && $page && $max_items ) 197 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) AND date_recorded >= FROM_UNIXTIME(%d) $filter_sql ORDER BY date_recorded DESC $pag_sql", $since) );197 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT 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" ) ); 198 198 else 199 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) AND date_recorded >= FROM_UNIXTIME(%d) $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql", $since) );200 201 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(user_id) FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) AND date_recorded >= FROM_UNIXTIME(%d) $filter_sql ORDER BY date_recorded DESC $max_sql", $since) );199 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT 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" ) ); 200 201 $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" ) ); 202 202 203 203 return array( 'activities' => $activities, 'total' => (int)$total_activities ); … … 212 212 if ( $max ) 213 213 $max_sql = $wpdb->prepare( "LIMIT %d", $max ); 214 214 215 /* Sort out filtering */ 215 216 if ( $filter ) 216 $filter_sql = $wpdb->prepare( "AND component_name = %s",$filter );217 217 $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ); 218 218 219 if ( $limit && $page && $max ) 219 220 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 $filter_sql ORDER BY date_recorded DESC $pag_sql" ) ); … … 248 249 } 249 250 251 function get_filter_sql( $filter_array ) { 252 global $wpdb; 253 254 if ( !empty( $filter_array['object'] ) ) { 255 $object_filter = explode( ',', $filter_array['object'] ); 256 $object_sql = ' AND ( '; 257 258 $counter = 1; 259 foreach( (array) $object_filter as $object ) { 260 $object_sql .= $wpdb->prepare( "component_name = %s", trim( $object ) ); 261 262 if ( $counter != count( $object_filter ) ) 263 $object_sql .= ' || '; 264 265 $counter++; 266 } 267 268 $object_sql .= ' )'; 269 } 270 271 if ( !empty( $filter_array['action'] ) ) { 272 $action_filter = explode( ',', $filter_array['action'] ); 273 $action_sql = ' AND ( '; 274 275 $counter = 1; 276 foreach( (array) $action_filter as $action ) { 277 $action_sql .= $wpdb->prepare( "component_action = %s", trim( $action ) ); 278 279 if ( $counter != count( $action_filter ) ) 280 $action_sql .= ' || '; 281 282 $counter++; 283 } 284 285 $action_sql .= ' )'; 286 } 287 288 if ( !empty( $filter_array['primary_id'] ) ) { 289 $pid_filter = explode( ',', $filter_array['action'] ); 290 $pid_sql = ' AND ( '; 291 292 $counter = 1; 293 foreach( (array) $pid_filter as $pid ) { 294 $pid_sql .= $wpdb->prepare( "item_id = %s", trim( $pid ) ); 295 296 if ( $counter != count( $pid_filter ) ) 297 $pid_sql .= ' || '; 298 299 $counter++; 300 } 301 302 $pid_sql .= ' )'; 303 } 304 305 if ( !empty( $filter_array['secondary_id'] ) ) { 306 $sid_filter = explode( ',', $filter_array['action'] ); 307 $sid_sql = ' AND ( '; 308 309 $counter = 1; 310 foreach( (array) $sid_filter as $sid ) { 311 $sid_sql .= $wpdb->prepare( "secondary_item_id = %s", trim( $sid ) ); 312 313 if ( $counter != count( $sid_filter ) ) 314 $sid_sql .= ' || '; 315 316 $counter++; 317 } 318 319 $sid_sql .= ' )'; 320 } 321 322 return $object_sql . $action_sql . $pid_sql . $sid_sql; 323 } 324 250 325 function get_last_updated() { 251 326 global $bp, $wpdb; -
trunk/bp-activity/bp-activity-templatetags.php
r1834 r1839 17 17 var $full_name; 18 18 19 function bp_activity_template( $type, $user_id, $per_page, $max, $ timeframe, $filter ) {19 function bp_activity_template( $type, $user_id, $per_page, $max, $filter ) { 20 20 global $bp; 21 21 … … 28 28 29 29 if ( $type == 'personal' ) 30 $this->activities = bp_activity_get_user_activity( $user_id, $max, $t imeframe, $this->pag_num, $this->pag_page, $filter );30 $this->activities = bp_activity_get_user_activity( $user_id, $max, $this->pag_num, $this->pag_page, $filter ); 31 31 32 32 if ( $type == 'friends' && ( bp_is_home() || is_site_admin() || $bp->loggedin_user->id == $user_id ) ) 33 $this->activities = bp_activity_get_friends_activity( $user_id, $max, $timeframe,false, $this->pag_num, $this->pag_page, $filter );33 $this->activities = bp_activity_get_friends_activity( $user_id, $max, false, $this->pag_num, $this->pag_page, $filter ); 34 34 35 35 if ( !$max || $max >= (int)$this->activities['total'] ) … … 89 89 return true; 90 90 } elseif ( $this->current_activity + 1 == $this->activity_count ) { 91 do_action(' loop_end');91 do_action('activity_loop_end'); 92 92 // Do some cleaning up after the loop 93 93 $this->rewind_activities(); … … 108 108 109 109 if ( $this->current_activity == 0 ) // loop has just started 110 do_action(' loop_start');110 do_action('activity_loop_start'); 111 111 } 112 112 } … … 125 125 function bp_has_activities( $args = '' ) { 126 126 global $bp, $activities_template, $bp_activity_user_id, $bp_activity_limit; 127 127 128 /* Note: any params used for filtering can be a single value, or multiple values comma seperated. */ 129 128 130 $defaults = array( 129 131 'type' => 'sitewide', 130 'user_id' => false,131 132 'per_page' => 25, 132 133 'max' => false, 133 'timeframe' => '-4 weeks', 134 'filter' => false 134 'user_id' => false, // user_id to filter on 135 'object' => false, // object to filter on e.g. groups, profile, status, friends 136 'action' => false, // action to filter on e.g. new_wire_post, new_forum_post, profile_updated 137 'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc. 138 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id 135 139 ); 136 140 … … 162 166 163 167 if ( isset( $_GET['afilter'] ) ) 164 $filter = $_GET['afilter']; 165 166 $activities_template = new BP_Activity_Template( $type, $user_id, $per_page, $max, $timeframe, $filter ); 168 $filter = array( 'object' => $_GET['afilter'] ); 169 else 170 $filter = array( 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id ); 171 172 $activities_template = new BP_Activity_Template( $type, $user_id, $per_page, $max, $filter ); 167 173 return $activities_template->has_activities(); 168 174 }
Note: See TracChangeset
for help on using the changeset viewer.