Changeset 2381 for trunk/bp-activity.php
- Timestamp:
- 01/20/2010 04:21:20 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/bp-activity.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity.php
r2362 r2381 1 1 <?php 2 2 3 define ( 'BP_ACTIVITY_DB_VERSION', '20 20' );3 define ( 'BP_ACTIVITY_DB_VERSION', '2031' ); 4 4 5 5 /* Define the slug for the component */ … … 18 18 19 19 /* Rename the old user activity cached table if needed. */ 20 $wpdb->query( "RENAME TABLE {$wpdb->base_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" ); 21 20 if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$wpdb->base_prefix}bp_activity_user_activity_cached%'" ) ) { 21 $wpdb->query( "RENAME TABLE {$wpdb->base_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" ); 22 } 23 24 /* Rename fields from pre BP 1.2 */ 25 if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp->activity->table_name}%'" ) ) { 26 $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE type type varchar(75) NOT NULL" ); 27 $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component component varchar(75) NOT NULL" ); 28 } 29 30 /** 31 * Build the tables 32 */ 22 33 $sql[] = "CREATE TABLE {$bp->activity->table_name} ( 23 34 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, 24 35 user_id bigint(20) NOT NULL, 25 component_name varchar(75) NOT NULL, 26 component_action varchar(75) NOT NULL, 36 component varchar(75) NOT NULL, 37 type varchar(75) NOT NULL, 38 action text NOT NULL 27 39 content longtext NOT NULL, 28 40 primary_link varchar(150) NOT NULL, 29 41 item_id varchar(75) NOT NULL, 30 secondary_item_id varchar(75) NOT NULL,42 secondary_item_id varchar(75) DEFAULT NULL, 31 43 date_recorded datetime NOT NULL, 32 44 hide_sitewide bool DEFAULT 0, … … 36 48 KEY user_id (user_id), 37 49 KEY item_id (item_id), 38 KEY component _name (component_name)50 KEY component (component) 39 51 ) {$charset_collate};"; 40 52 … … 167 179 $has_access = true; 168 180 /* Redirect based on the type of activity */ 169 if ( $activity->component _name== $bp->groups->id ) {181 if ( $activity->component == $bp->groups->id ) { 170 182 if ( !function_exists( 'groups_get_group' ) ) 171 183 bp_core_redirect( $bp->root_domain ); … … 248 260 $redirect = false; 249 261 /* Redirect based on the type of activity */ 250 if ( $activity->component _name== $bp->groups->id ) {262 if ( $activity->component == $bp->groups->id ) { 251 263 if ( $activity->user_id ) 252 264 $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id; … … 445 457 'id' => false, // Pass an existing activity ID to update an existing entry. 446 458 447 'content' => false, // The content of the activity item 448 'primary_link' => false, // The primary URL for this item in RSS feeds 449 'component_name' => false, // The name/ID of the component e.g. groups, profile, mycomponent 450 'component_action' => false, // The component action e.g. activity_update, profile_updated 459 'action' => '', // The activity action - e.g. "Jon Doe posted an update" 460 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!" 461 462 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent 463 'type' => false, // The activity type e.g. activity_update, profile_updated 464 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink) 451 465 452 466 'user_id' => $bp->loggedin_user->id, // Optional: The user to record the activity for, can be false if this activity is not for a user. … … 460 474 extract( $params, EXTR_SKIP ); 461 475 462 /* Insert the "time-since" placeholder */ 463 if ( $content ) 476 /* Make sure we are backwards compatible */ 477 if ( empty( $component ) && !empty( $component_name ) ) 478 $component = $component_name; 479 480 if ( empty( $type ) && !empty( $component_action ) ) 481 $type = $component_action; 482 483 /* Insert the "time-since" placeholder (use content if action empty for backwards compat) */ 484 if ( !empty( $action ) ) 485 $action = bp_activity_add_timesince_placeholder( $action ); 486 else if ( empty( $action ) && !empty( $content ) ) 464 487 $content = bp_activity_add_timesince_placeholder( $content ); 465 488 489 /* Remove any images and replace the first image with a thumbnail */ 490 //$content = bp_activity_thumbnail_images( $content ); 491 466 492 $activity = new BP_Activity_Activity( $id ); 467 493 468 494 $activity->user_id = $user_id; 495 $activity->component = $component; 496 $activity->type = $type; 497 $activity->action = $action; 469 498 $activity->content = $content; 470 499 $activity->primary_link = $primary_link; 471 $activity->component_name = $component_name;472 $activity->component_action = $component_action;473 500 $activity->item_id = $item_id; 474 501 $activity->secondary_item_id = $secondary_item_id; … … 480 507 481 508 /* If this is an activity comment, rebuild the tree */ 482 if ( 'activity_comment' == $activity-> component_action)509 if ( 'activity_comment' == $activity->type ) 483 510 BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id ); 484 511 … … 499 526 extract( $r, EXTR_SKIP ); 500 527 501 if ( empty( $content) || empty($content) )528 if ( empty( $content ) ) 502 529 return false; 503 530 504 531 /* Record this on the user's profile */ 505 532 $from_user_link = bp_core_get_userlink( $user_id ); 506 $activity_ content = sprintf( __('%s posted an update:', 'buddypress'), $from_user_link );507 $activity_content .= '<div class="activity-inner">' . $content . '</div>';533 $activity_action = sprintf( __( '%s posted an update:', 'buddypress' ), $from_user_link ); 534 $activity_content = '<div class="activity-inner">' . $content . '</div>'; 508 535 509 536 $primary_link = bp_core_get_userlink( $user_id, false, true ); … … 512 539 $activity_id = bp_activity_add( array( 513 540 'user_id' => $user_id, 541 'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ), 514 542 'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ), 515 543 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ), 516 'component _name' => $bp->activity->id,517 ' component_action' => 'activity_update'544 'component' => $bp->activity->id, 545 'type' => 'activity_update' 518 546 ) ); 519 547 … … 552 580 'content' => apply_filters( 'bp_activity_comment_content', $comment_header . '<div class="activity-inner">' . $content . '</div>' ), 553 581 'primary_link' => '', 554 'component _name' => $bp->activity->id,555 ' component_action' => 'activity_comment',582 'component' => $bp->activity->id, 583 'type' => 'activity_comment', 556 584 'user_id' => $user_id, 557 585 'item_id' => $activity_id, … … 588 616 $defaults = array( 589 617 'item_id' => false, 590 'component _name' => false,591 ' component_action' => false, // optional618 'component' => false, 619 'type' => false, // optional 592 620 'user_id' => false, // optional 593 621 'secondary_item_id' => false // optional … … 597 625 extract( $r, EXTR_SKIP ); 598 626 599 if ( !$activity_ids_deleted = BP_Activity_Activity::delete_by_item_id( $item_id, $component _name, $component_action, $user_id, $secondary_item_id ) )600 return false; 601 602 do_action( 'bp_activity_delete_by_item_id', $item_id, $component _name, $component_action, $user_id, $secondary_item_id );627 if ( !$activity_ids_deleted = BP_Activity_Activity::delete_by_item_id( $item_id, $component, $type, $user_id, $secondary_item_id ) ) 628 return false; 629 630 do_action( 'bp_activity_delete_by_item_id', $item_id, $component, $type, $user_id, $secondary_item_id ); 603 631 do_action( 'bp_activity_deleted_activities', $activity_ids_deleted ); 604 632 … … 616 644 } 617 645 618 function bp_activity_delete_by_content( $user_id, $content, $component _name, $component_action) {646 function bp_activity_delete_by_content( $user_id, $content, $component, $type ) { 619 647 /* Insert the "time-since" placeholder to match the existing content in the DB */ 620 648 $content = bp_activity_add_timesince_placeholder( $content ); 621 649 622 if ( !$activity_ids_deleted = BP_Activity_Activity::delete_by_content( $user_id, $content, $component _name, $component_action) )623 return false; 624 625 do_action( 'bp_activity_delete_by_content', $user_id, $content, $component _name, $component_action);650 if ( !$activity_ids_deleted = BP_Activity_Activity::delete_by_content( $user_id, $content, $component, $type ) ) 651 return false; 652 653 do_action( 'bp_activity_delete_by_content', $user_id, $content, $component, $type ); 626 654 do_action( 'bp_activity_deleted_activities', $activity_ids_deleted ); 627 655 … … 629 657 } 630 658 631 function bp_activity_delete_for_user_by_component( $user_id, $component _name) {632 if ( !$activity_ids_deleted = BP_Activity_Activity::delete_for_user_by_component( $user_id, $component _name) )633 return false; 634 635 do_action( 'bp_activity_delete_for_user_by_component', $user_id, $component _name);659 function bp_activity_delete_for_user_by_component( $user_id, $component ) { 660 if ( !$activity_ids_deleted = BP_Activity_Activity::delete_for_user_by_component( $user_id, $component ) ) 661 return false; 662 663 do_action( 'bp_activity_delete_for_user_by_component', $user_id, $component ); 636 664 do_action( 'bp_activity_deleted_activities', $activity_ids_deleted ); 637 665 … … 645 673 $activity_obj = new BP_Activity_Activity( $activity_id ); 646 674 647 if ( 'new_blog_post' == $activity_obj-> component_action || 'new_blog_comment' == $activity_obj->component_action || 'new_forum_topic' == $activity_obj->component_action || 'new_forum_post' == $activity_obj->component_action)675 if ( 'new_blog_post' == $activity_obj->type || 'new_blog_comment' == $activity_obj->type || 'new_forum_topic' == $activity_obj->type || 'new_forum_post' == $activity_obj->type ) 648 676 $link = $activity_obj->primary_link; 649 677 else { 650 if ( 'activity_comment' == $activity_obj-> component_action)678 if ( 'activity_comment' == $activity_obj->type ) 651 679 $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->item_id . '/'; 652 680 else … … 682 710 } 683 711 712 function bp_activity_thumbnail_images( $content ) { 713 preg_match_all( '/<img[^>]*>/Ui', $content, $matches ); 714 $content = preg_replace('/<img[^>]*>/Ui', '', $content ); 715 716 if ( !empty( $matches ) ) { 717 /* Get the SRC value */ 718 preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src ); 719 720 if ( !empty( $src ) ) { 721 $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 ); 722 $pos = strpos( $content, '<blockquote>' ); 723 $before = substr( $content, 0, (int) $pos ); 724 $after = substr( $content, (int) $pos, strlen( $content ) ); 725 726 $content = $before . '<img src="' . esc_attr( $src) . '" width="100" height="100" alt="thumb" class="align-left thumbnail" />' . $after; 727 } 728 } 729 730 return $content; 731 } 732 684 733 function bp_activity_set_action( $component_id, $key, $value ) { 685 734 global $bp;
Note: See TracChangeset
for help on using the changeset viewer.