Changeset 7048
- Timestamp:
- 05/09/2013 02:11:57 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r6948 r7048 174 174 if ( $search_terms ) { 175 175 $search_terms = $wpdb->escape( $search_terms ); 176 $where_conditions['search_sql'] = "a.content LIKE '%%" . like_escape( $search_terms) . "%%'";176 $where_conditions['search_sql'] = "a.content LIKE '%%" . esc_sql( like_escape( $search_terms ) ) . "%%'"; 177 177 } 178 178 … … 253 253 254 254 // Get the fullnames of users so we don't have to query in the loop 255 $activity_user_ids = array(); 256 if ( bp_is_active( 'xprofile' ) && $activities ) { 257 foreach ( (array) $activities as $activity ) { 258 if ( (int) $activity->user_id ) 259 $activity_user_ids[] = $activity->user_id; 260 } 261 262 $activity_user_ids = implode( ',', array_unique( (array) $activity_user_ids ) ); 263 if ( !empty( $activity_user_ids ) ) { 255 if ( bp_is_active( 'xprofile' ) && !empty( $activities ) ) { 256 $activity_user_ids = wp_list_pluck( $activities, 'user_id' ); 257 $activity_user_ids = implode( ',', wp_parse_id_list( $activity_user_ids ) ); 258 259 if ( !empty( $activity_user_ids ) ) { 264 260 if ( $names = $wpdb->get_results( "SELECT user_id, value AS user_fullname FROM {$bp->profile->table_name_data} WHERE field_id = 1 AND user_id IN ({$activity_user_ids})" ) ) { 265 261 foreach ( (array) $names as $name ) … … 374 370 375 371 if ( !empty( $item_id ) ) 376 $where_args[] = $wpdb->prepare( "item_id = % s", $item_id );372 $where_args[] = $wpdb->prepare( "item_id = %d", $item_id ); 377 373 378 374 if ( !empty( $secondary_item_id ) ) 379 $where_args[] = $wpdb->prepare( "secondary_item_id = % s", $secondary_item_id );375 $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $secondary_item_id ); 380 376 381 377 if ( !empty( $action ) ) … … 439 435 440 436 if ( !empty( $item_id ) ) 441 $where_args[] = $wpdb->prepare( "item_id = % s", $item_id );437 $where_args[] = $wpdb->prepare( "item_id = %d", $item_id ); 442 438 443 439 if ( !empty( $secondary_item_id ) ) 444 $where_args[] = $wpdb->prepare( "secondary_item_id = % s", $secondary_item_id );440 $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $secondary_item_id ); 445 441 446 442 if ( !empty( $date_recorded ) ) … … 471 467 } 472 468 473 function delete_activity_item_comments( $activity_ids ) {469 function delete_activity_item_comments( $activity_ids = array() ) { 474 470 global $bp, $wpdb; 475 471 476 if ( is_array( $activity_ids ) ) 477 $activity_ids = implode ( ',', array_map( 'absint', $activity_ids ) ); 478 else 479 $activity_ids = implode ( ',', array_map( 'absint', explode ( ',', $activity_ids ) ) ); 472 $activity_ids = implode( ',', wp_parse_id_list( $activity_ids ) ); 480 473 481 474 return $wpdb->query( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" ); 482 475 } 483 476 484 function delete_activity_meta_entries( $activity_ids ) {477 function delete_activity_meta_entries( $activity_ids = array() ) { 485 478 global $bp, $wpdb; 486 479 487 if ( is_array( $activity_ids ) ) 488 $activity_ids = implode ( ',', array_map( 'absint', $activity_ids ) ); 489 else 490 $activity_ids = implode ( ',', array_map( 'absint', explode ( ',', $activity_ids ) ) ); 480 $activity_ids = implode( ',', wp_parse_id_list( $activity_ids ) ); 491 481 492 482 return $wpdb->query( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id IN ({$activity_ids})" ); -
trunk/tests/testcases/activity/class.BP_Activity_Activity.php
r7047 r7048 74 74 } 75 75 76 public function test_get_ meta_query() {76 public function test_get_with_meta_query() { 77 77 $a1 = $this->factory->activity->create(); 78 78 $a2 = $this->factory->activity->create(); … … 90 90 $this->assertEquals( $ids, array( $a1 ) ); 91 91 } 92 93 public function test_get_with_search_terms() { 94 $a1 = $this->factory->activity->create( array( 95 'content' => 'Boone is a cool guy', 96 ) ); 97 $a2 = $this->factory->activity->create( array( 98 'content' => 'No he isn\'t', 99 ) ); 100 101 $activity = BP_Activity_Activity::get( array( 102 'search_terms' => 'cool', 103 ) ); 104 $ids = wp_list_pluck( $activity['activities'], 'id' ); 105 $this->assertEquals( $ids, array( $a1 ) ); 106 } 107 108 public function test_get_id_with_item_id() { 109 $a1 = $this->factory->activity->create( array( 110 'item_id' => 523, 111 ) ); 112 $a2 = $this->factory->activity->create( array( 113 'item_id' => 1888, 114 ) ); 115 116 $activity = BP_Activity_Activity::get_id( false, false, false, 523, false, false, false, false ); 117 $this->assertEquals( $a1, $activity ); 118 } 119 120 public function test_get_id_with_secondary_item_id() { 121 $a1 = $this->factory->activity->create( array( 122 'secondary_item_id' => 523, 123 ) ); 124 $a2 = $this->factory->activity->create( array( 125 'secondary_content' => 1888, 126 ) ); 127 128 $activity = BP_Activity_Activity::get_id( false, false, false, false, 523, false, false, false ); 129 $this->assertEquals( $a1, $activity ); 130 } 131 132 public function test_delete_with_item_id() { 133 $a1 = $this->factory->activity->create( array( 134 'item_id' => 523, 135 ) ); 136 $a2 = $this->factory->activity->create( array( 137 'item_id' => 1888, 138 ) ); 139 140 $activity = BP_Activity_Activity::delete( array( 141 'item_id' => 523, 142 ) ); 143 $this->assertEquals( array( $a1 ), $activity ); 144 } 145 146 public function test_delete_with_secondary_item_id() { 147 $a1 = $this->factory->activity->create( array( 148 'secondary_item_id' => 523, 149 ) ); 150 $a2 = $this->factory->activity->create( array( 151 'secondary_item_id' => 1888, 152 ) ); 153 154 $activity = BP_Activity_Activity::delete( array( 155 'secondary_item_id' => 523, 156 ) ); 157 $this->assertEquals( array( $a1 ), $activity ); 158 } 92 159 }
Note: See TracChangeset
for help on using the changeset viewer.