Changeset 2471 for trunk/bp-activity/bp-activity-classes.php
- Timestamp:
- 01/28/2010 06:01:42 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r2416 r2471 71 71 /* Static Functions */ 72 72 73 function delete( $item_id, $component, $type, $user_id = false, $secondary_item_id = false ) {74 global $wpdb, $bp;75 76 if ( $secondary_item_id )77 $secondary_sql = $wpdb->prepare( "AND secondary_item_id = %s", $secondary_item_id );78 79 if ( $type )80 $type_sql = $wpdb->prepare( "AND type = %s", $type );81 82 if ( $user_id )83 $user_sql = $wpdb->prepare( "AND user_id = %d", $user_id );84 85 /* Fetch the activity IDs so we can delete any comments for this activity item */86 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component = %s {$type_sql} {$user_sql}", $item_id, $component ) );87 88 error_log( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component = %s {$type_sql} {$user_sql}", $item_id, $component ) );89 90 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component = %s {$type_sql} {$user_sql}", $item_id, $component ) ) )91 return false;92 93 if ( $activity_ids ) {94 BP_Activity_Activity::delete_activity_item_comments( $activity_ids );95 BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );96 97 return $activity_ids;98 }99 100 return true;101 }102 103 function delete_by_item_id( $item_id, $component, $type, $user_id = false, $secondary_item_id = false ) {104 return BP_Activity_Activity::delete( $item_id, $component, $type, $user_id, $secondary_item_id );105 }106 107 function delete_by_activity_id( $activity_id ) {108 global $bp, $wpdb;109 110 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE id = %d", $activity_id ) ) )111 return false;112 113 /* Delete the comments for this activity ID */114 BP_Activity_Activity::delete_activity_item_comments( $activity_id );115 BP_Activity_Activity::delete_activity_meta_entries( $activity_id );116 117 return true;118 }119 120 function delete_by_content( $user_id, $content, $component, $type ) {121 global $bp, $wpdb;122 123 /* Fetch the activity ID so we can delete any comments for this activity item */124 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component = %s AND type = %s", $user_id, $content, $component, $type ) );125 126 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component = %s AND type = %s", $user_id, $content, $component, $type ) ) )127 return false;128 129 if ( $activity_ids ) {130 BP_Activity_Activity::delete_activity_item_comments( $activity_ids );131 BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );132 133 return $activity_ids;134 }135 136 return true;137 }138 139 function delete_for_user_by_component( $user_id, $component ) {140 global $bp, $wpdb;141 142 /* Fetch the activity IDs so we can delete any comments for this activity item */143 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND component = %s", $user_id, $component ) );144 145 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component = %s", $user_id, $component ) ) )146 return false;147 148 if ( $activity_ids ) {149 BP_Activity_Activity::delete_activity_item_comments( $activity_ids );150 BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );151 152 return $activity_ids;153 }154 155 return true;156 }157 158 function delete_for_user( $user_id ) {159 global $wpdb, $bp;160 161 /* Fetch the activity IDs so we can delete any comments for this activity item */162 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d", $user_id ) );163 164 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d", $user_id ) ) )165 return false;166 167 if ( $activity_ids ) {168 BP_Activity_Activity::delete_activity_item_comments( $activity_ids );169 BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );170 171 return $activity_ids;172 }173 }174 175 function delete_activity_item_comments( $activity_ids ) {176 global $bp, $wpdb;177 178 if ( is_array($activity_ids) )179 $activity_ids = implode( ',', $activity_ids );180 181 $activity_ids = $wpdb->escape( $activity_ids );182 183 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" ) );184 }185 186 function delete_activity_meta_entries( $activity_ids ) {187 global $bp, $wpdb;188 189 if ( is_array($activity_ids) )190 $activity_ids = implode( ',', $activity_ids );191 192 $activity_ids = $wpdb->escape( $activity_ids );193 194 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id IN ({$activity_ids})" ) );195 }196 197 73 function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) { 198 74 global $wpdb, $bp; … … 201 77 $select_sql = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name"; 202 78 203 if ( function_exists( 'xprofile_install' ) ) 204 $select_sql .= ", pd.value as user_fullname"; 205 206 $from_sql = " FROM {$bp->activity->table_name} a, {$wpdb->users} u"; 207 208 if ( function_exists( 'xprofile_install' ) ) 209 $from_sql .= ", {$bp->profile->table_name_data} pd"; 79 $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID"; 210 80 211 81 /* Where conditions */ 212 82 $where_conditions = array(); 213 $where_conditions['user_join'] = "a.user_id = u.ID";214 215 if ( function_exists( 'xprofile_install' ) ) {216 $where_conditions['xprofile_join'] = "a.user_id = pd.user_id";217 $where_conditions['xprofile_filter'] = "pd.field_id = 1";218 }219 83 220 84 if ( $per_page && $page ) … … 253 117 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(a.id) {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ) ); 254 118 119 /* Get the fullnames of users so we don't have to query in the loop */ 120 if ( function_exists( 'xprofile_install' ) && $activities ) { 121 foreach ( (array)$activities as $activity ) { 122 if ( (int)$activity->user_id ) 123 $activity_user_ids[] = $activity->user_id; 124 } 125 126 $activity_user_ids = implode( ',', (array)$activity_user_ids ); 127 if ( !empty( $activity_user_ids ) ) { 128 if ( $names = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value AS user_fullname FROM {$bp->profile->table_name_data} WHERE field_id = 1 AND user_id IN ({$activity_user_ids})" ) ) ) { 129 foreach ( (array)$names as $name ) 130 $tmp_names[$name->user_id] = $name->user_fullname; 131 132 foreach ( (array)$activities as $i => $activity ) { 133 if ( !empty( $tmp_names[$activity->user_id] ) ) 134 $activities[$i]->user_fullname = $tmp_names[$activity->user_id]; 135 } 136 137 unset( $names ); 138 unset( $tmp_names ); 139 } 140 } 141 } 142 255 143 if ( $activities && $display_comments ) 256 144 $activities = BP_Activity_Activity::append_comments( &$activities ); … … 295 183 } 296 184 297 function get_id( $user_id, $component, $type, $item_id, $secondary_item_id ) {185 function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content ) { 298 186 global $bp, $wpdb; 299 187 … … 314 202 if ( !empty( $secondary_item_id ) ) 315 203 $where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id ); 204 205 if ( !empty( $action ) ) 206 $where_args[] = $wpdb->prepare( "action = %s", bp_activity_add_timesince_placeholder( $action ) ); 207 208 if ( !empty( $content ) ) 209 $where_args[] = $wpdb->prepare( "content = %s", $content ); 316 210 317 211 if ( !empty( $where_args ) ) … … 321 215 322 216 return $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ); 217 } 218 219 function delete( $args ) { 220 global $wpdb, $bp; 221 222 extract( $args ); 223 224 $defaults = array( 225 'id' => false, 226 'action' => false, 227 'content' => false, 228 'component' => false, 229 'type' => false, 230 'primary_link' => false, 231 'user_id' => false, 232 'item_id' => false, 233 'secondary_item_id' => false, 234 'recorded_time' => false, 235 'hide_sitewide' => false 236 ); 237 238 $where_args = false; 239 240 if ( !empty( $id ) ) 241 $where_args[] = $wpdb->prepare( "id = %d", $id ); 242 243 if ( !empty( $user_id ) ) 244 $where_args[] = $wpdb->prepare( "user_id = %d", $user_id ); 245 246 if ( !empty( $action ) ) 247 $where_args[] = $wpdb->prepare( "action = %s", bp_activity_add_timesince_placeholder( $action ) ); 248 249 if ( !empty( $content ) ) 250 $where_args[] = $wpdb->prepare( "content = %s", $content ); 251 252 if ( !empty( $component ) ) 253 $where_args[] = $wpdb->prepare( "component = %s", $component ); 254 255 if ( !empty( $type ) ) 256 $where_args[] = $wpdb->prepare( "type = %s", $type ); 257 258 if ( !empty( $primary_link ) ) 259 $where_args[] = $wpdb->prepare( "primary_link = %s", $primary_link ); 260 261 if ( !empty( $item_id ) ) 262 $where_args[] = $wpdb->prepare( "item_id = %s", $item_id ); 263 264 if ( !empty( $secondary_item_id ) ) 265 $where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id ); 266 267 if ( !empty( $recorded_time ) ) 268 $where_args[] = $wpdb->prepare( "recorded_time = %s", $recorded_time ); 269 270 if ( !empty( $hide_sitewide ) ) 271 $where_args[] = $wpdb->prepare( "recorded_time = %d", $hide_sitewide ); 272 273 if ( !empty( $where_args ) ) 274 $where_sql = 'WHERE ' . join( ' AND ', $where_args ); 275 else 276 return false; 277 278 /* Fetch the activity IDs so we can delete any comments for this activity item */ 279 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ) ); 280 281 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) ) ) 282 return false; 283 284 if ( $activity_ids ) { 285 BP_Activity_Activity::delete_activity_item_comments( $activity_ids ); 286 BP_Activity_Activity::delete_activity_meta_entries( $activity_ids ); 287 288 return $activity_ids; 289 } 290 291 return $activity_ids; 292 } 293 294 function delete_activity_item_comments( $activity_ids ) { 295 global $bp, $wpdb; 296 297 if ( is_array($activity_ids) ) 298 $activity_ids = implode( ',', $activity_ids ); 299 300 $activity_ids = $wpdb->escape( $activity_ids ); 301 302 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" ) ); 303 } 304 305 function delete_activity_meta_entries( $activity_ids ) { 306 global $bp, $wpdb; 307 308 if ( is_array($activity_ids) ) 309 $activity_ids = implode( ',', $activity_ids ); 310 311 $activity_ids = $wpdb->escape( $activity_ids ); 312 313 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id IN ({$activity_ids})" ) ); 323 314 } 324 315
Note: See TracChangeset
for help on using the changeset viewer.