Changeset 14148
- Timestamp:
- 12/16/2025 03:59:38 PM (4 months ago)
- Location:
- trunk/src/bp-activity
- Files:
-
- 2 edited
-
bp-activity-template.php (modified) (3 diffs)
-
classes/class-bp-activity-activity.php (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-template.php
r14077 r14148 2597 2597 * 2598 2598 * @since 2.0.0 2599 * @since 2.8.0 Added $commentas a parameter.2599 * @since 2.8.0 Added `$comment` as a parameter. 2600 2600 * 2601 2601 * @param object|int $comment Object of the activity comment or activity comment ID. Usually unnecessary … … 2610 2610 * 2611 2611 * @since 2.0.0 2612 * @since 2.8.0 Added $commentas a parameter.2613 * 2614 * @param object|int $comment Object of the activity comment or activity comment ID. Usually unnecessary2612 * @since 2.8.0 Added `$comment` as a parameter. 2613 * 2614 * @param object|int $comment Object of the activity comment or activity comment ID. Usually unnecessary 2615 2615 * when used in activity comment loop. 2616 2616 * @return int … … 2657 2657 * 2658 2658 * @since 2.0.0 2659 * 2660 * @param int $depth Depth for the current activity comment. 2661 */ 2662 return apply_filters( 'bp_activity_get_comment_depth', $depth ); 2659 * @since 15.0.0 Added `$comment` as a parameter. 2660 * 2661 * @param int $depth Depth for the current activity comment. 2662 * @param object|int $comment Object of the activity comment or activity comment ID. 2663 */ 2664 return apply_filters( 'bp_activity_get_comment_depth', $depth, $comment ); 2663 2665 } 2664 2666 -
trunk/src/bp-activity/classes/class-bp-activity-activity.php
r13988 r14148 162 162 public function __construct( $id = false ) { 163 163 // Instantiate errors object. 164 $this->errors = new WP_Error ;165 166 if ( ! empty( $id ) ) {164 $this->errors = new WP_Error(); 165 166 if ( ! empty( $id ) ) { 167 167 $this->id = (int) $id; 168 168 $this->populate(); … … 239 239 $bp = buddypress(); 240 240 241 $this->id = apply_filters_ref_array( 'bp_activity_id_before_save', array( $this->id,&$this ) );242 $this->item_id = apply_filters_ref_array( 'bp_activity_item_id_before_save', array( $this->item_id,&$this ) );241 $this->id = apply_filters_ref_array( 'bp_activity_id_before_save', array( $this->id, &$this ) ); 242 $this->item_id = apply_filters_ref_array( 'bp_activity_item_id_before_save', array( $this->item_id, &$this ) ); 243 243 $this->secondary_item_id = apply_filters_ref_array( 'bp_activity_secondary_item_id_before_save', array( $this->secondary_item_id, &$this ) ); 244 $this->user_id = apply_filters_ref_array( 'bp_activity_user_id_before_save', array( $this->user_id,&$this ) );245 $this->primary_link = apply_filters_ref_array( 'bp_activity_primary_link_before_save', array( $this->primary_link,&$this ) );246 $this->component = apply_filters_ref_array( 'bp_activity_component_before_save', array( $this->component,&$this ) );247 $this->type = apply_filters_ref_array( 'bp_activity_type_before_save', array( $this->type,&$this ) );248 $this->action = apply_filters_ref_array( 'bp_activity_action_before_save', array( $this->action,&$this ) );249 $this->content = apply_filters_ref_array( 'bp_activity_content_before_save', array( $this->content,&$this ) );250 $this->date_recorded = apply_filters_ref_array( 'bp_activity_date_recorded_before_save', array( $this->date_recorded,&$this ) );251 $this->hide_sitewide = apply_filters_ref_array( 'bp_activity_hide_sitewide_before_save', array( $this->hide_sitewide,&$this ) );252 $this->mptt_left = apply_filters_ref_array( 'bp_activity_mptt_left_before_save', array( $this->mptt_left,&$this ) );253 $this->mptt_right = apply_filters_ref_array( 'bp_activity_mptt_right_before_save', array( $this->mptt_right,&$this ) );254 $this->is_spam = apply_filters_ref_array( 'bp_activity_is_spam_before_save', array( $this->is_spam,&$this ) );244 $this->user_id = apply_filters_ref_array( 'bp_activity_user_id_before_save', array( $this->user_id, &$this ) ); 245 $this->primary_link = apply_filters_ref_array( 'bp_activity_primary_link_before_save', array( $this->primary_link, &$this ) ); 246 $this->component = apply_filters_ref_array( 'bp_activity_component_before_save', array( $this->component, &$this ) ); 247 $this->type = apply_filters_ref_array( 'bp_activity_type_before_save', array( $this->type, &$this ) ); 248 $this->action = apply_filters_ref_array( 'bp_activity_action_before_save', array( $this->action, &$this ) ); 249 $this->content = apply_filters_ref_array( 'bp_activity_content_before_save', array( $this->content, &$this ) ); 250 $this->date_recorded = apply_filters_ref_array( 'bp_activity_date_recorded_before_save', array( $this->date_recorded, &$this ) ); 251 $this->hide_sitewide = apply_filters_ref_array( 'bp_activity_hide_sitewide_before_save', array( $this->hide_sitewide, &$this ) ); 252 $this->mptt_left = apply_filters_ref_array( 'bp_activity_mptt_left_before_save', array( $this->mptt_left, &$this ) ); 253 $this->mptt_right = apply_filters_ref_array( 'bp_activity_mptt_right_before_save', array( $this->mptt_right, &$this ) ); 254 $this->is_spam = apply_filters_ref_array( 'bp_activity_is_spam_before_save', array( $this->is_spam, &$this ) ); 255 255 256 256 /** … … 423 423 8 => 'exclude', 424 424 9 => 'in', 425 10 => 'spam' 425 10 => 'spam', 426 426 ); 427 427 … … 460 460 461 461 // Select conditions. 462 $select_sql = "SELECT DISTINCT a.id";463 464 $from_sql = " FROM {$bp->activity->table_name} a";465 466 $join_sql = '';462 $select_sql = 'SELECT DISTINCT a.id'; 463 464 $from_sql = " FROM {$bp->activity->table_name} a"; 465 466 $join_sql = ''; 467 467 468 468 // Where conditions. … … 553 553 // Searching. 554 554 if ( $r['search_terms'] ) { 555 $search_terms_like = '%' . bp_esc_like( $r['search_terms'] ) . '%';555 $search_terms_like = '%' . bp_esc_like( $r['search_terms'] ) . '%'; 556 556 $where_conditions['search_sql'] = $wpdb->prepare( 'a.content LIKE %s', $search_terms_like ); 557 557 … … 578 578 } 579 579 580 switch ( $r['order_by'] ) {581 case 'id' :582 case 'user_id' :583 case 'component' :584 case 'type' :585 case 'action' :586 case 'content' :587 case 'primary_link' :588 case 'item_id' :589 case 'secondary_item_id' :590 case 'date_recorded' :591 case 'hide_sitewide' :592 case 'mptt_left' :593 case 'mptt_right' :594 case 'is_spam' :580 switch ( $r['order_by'] ) { 581 case 'id': 582 case 'user_id': 583 case 'component': 584 case 'type': 585 case 'action': 586 case 'content': 587 case 'primary_link': 588 case 'item_id': 589 case 'secondary_item_id': 590 case 'date_recorded': 591 case 'hide_sitewide': 592 case 'mptt_left': 593 case 'mptt_right': 594 case 'is_spam': 595 595 break; 596 596 597 default :597 default: 598 598 $r['order_by'] = 'date_recorded'; 599 599 break; … … 603 603 // Hide Hidden Items? 604 604 if ( ! $r['show_hidden'] ) { 605 $where_conditions['hidden_sql'] = "a.hide_sitewide = 0";605 $where_conditions['hidden_sql'] = 'a.hide_sitewide = 0'; 606 606 } 607 607 608 608 // Exclude specified items. 609 609 if ( ! empty( $r['exclude'] ) ) { 610 $exclude = implode( ',', wp_parse_id_list( $r['exclude'] ) );610 $exclude = implode( ',', wp_parse_id_list( $r['exclude'] ) ); 611 611 $where_conditions['exclude'] = "a.id NOT IN ({$exclude})"; 612 612 } … … 614 614 // The specific ids to which you want to limit the query. 615 615 if ( ! empty( $r['in'] ) ) { 616 $in = implode( ',', wp_parse_id_list( $r['in'] ) );616 $in = implode( ',', wp_parse_id_list( $r['in'] ) ); 617 617 $where_conditions['in'] = "a.id IN ({$in})"; 618 618 } … … 651 651 // Build the excluded type sql part. 652 652 if ( ! empty( $excluded_types ) ) { 653 $not_in = "'" . implode( "', '", esc_sql( $excluded_types ) ) . "'";653 $not_in = "'" . implode( "', '", esc_sql( $excluded_types ) ) . "'"; 654 654 $where_conditions['excluded_types'] = "a.type NOT IN ({$not_in})"; 655 655 } … … 685 685 686 686 // Sanitize page and per_page parameters. 687 $page = absint( $r['page'] );687 $page = absint( $r['page'] ); 688 688 $per_page = absint( $r['per_page'] ); 689 689 … … 705 705 * @since 2.0.0 706 706 * 707 * @param bool $valueWhether to use legacy structure or not.708 * @param BP_Activity_Activity $valueCurrent method being called.709 * @param array $r Parsed arguments passed into method.707 * @param bool $use_legacy_activity_query Whether to use legacy structure or not. 708 * @param string $method Current method being called. 709 * @param array $r Parsed arguments passed into method. 710 710 */ 711 711 if ( ! $only_get_count && apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) { 712 712 713 713 // Legacy queries joined against the user table. 714 $select_sql = "SELECT DISTINCT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";714 $select_sql = 'SELECT DISTINCT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name'; 715 715 $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID"; 716 716 717 717 if ( ! empty( $page ) && ! empty( $per_page ) ) { 718 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );718 $pag_sql = $wpdb->prepare( 'LIMIT %d, %d', absint( ( $page - 1 ) * $per_page ), $per_page ); 719 719 720 720 /** This filter is documented in bp-activity/bp-activity-classes.php */ … … 757 757 // We query for $per_page + 1 items in order to 758 758 // populate the has_more_items flag. 759 $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page + 1 );759 $activity_ids_sql .= $wpdb->prepare( ' LIMIT %d, %d', absint( ( $page - 1 ) * $per_page ), $per_page + 1 ); 760 760 } 761 761 … … 1260 1260 ); 1261 1261 1262 return BP_Activity_Activity::get( $max, $page, $per_page, $sort, false, false, $display_comments, false, false, $activity_ids );1262 return self::get( $max, $page, $per_page, $sort, false, false, $display_comments, false, false, $activity_ids ); 1263 1263 } 1264 1264 … … 1426 1426 // ID. 1427 1427 if ( ! empty( $r['id'] ) ) { 1428 $where_args[] = $wpdb->prepare( "id = %d", $r['id'] );1428 $where_args[] = $wpdb->prepare( 'id = %d', $r['id'] ); 1429 1429 } 1430 1430 1431 1431 // User ID. 1432 1432 if ( ! empty( $r['user_id'] ) ) { 1433 $where_args[] = $wpdb->prepare( "user_id = %d", $r['user_id'] );1433 $where_args[] = $wpdb->prepare( 'user_id = %d', $r['user_id'] ); 1434 1434 } 1435 1435 1436 1436 // Action. 1437 1437 if ( ! empty( $r['action'] ) ) { 1438 $where_args[] = $wpdb->prepare( "action = %s", $r['action'] );1438 $where_args[] = $wpdb->prepare( 'action = %s', $r['action'] ); 1439 1439 } 1440 1440 1441 1441 // Content. 1442 1442 if ( ! empty( $r['content'] ) ) { 1443 $where_args[] = $wpdb->prepare( "content = %s", $r['content'] );1443 $where_args[] = $wpdb->prepare( 'content = %s', $r['content'] ); 1444 1444 } 1445 1445 1446 1446 // Component. 1447 1447 if ( ! empty( $r['component'] ) ) { 1448 $where_args[] = $wpdb->prepare( "component = %s", $r['component'] );1448 $where_args[] = $wpdb->prepare( 'component = %s', $r['component'] ); 1449 1449 } 1450 1450 1451 1451 // Type. 1452 1452 if ( ! empty( $r['type'] ) ) { 1453 $where_args[] = $wpdb->prepare( "type = %s", $r['type'] );1453 $where_args[] = $wpdb->prepare( 'type = %s', $r['type'] ); 1454 1454 } 1455 1455 1456 1456 // Primary Link. 1457 1457 if ( ! empty( $r['primary_link'] ) ) { 1458 $where_args[] = $wpdb->prepare( "primary_link = %s", $r['primary_link'] );1458 $where_args[] = $wpdb->prepare( 'primary_link = %s', $r['primary_link'] ); 1459 1459 } 1460 1460 1461 1461 // Item ID. 1462 1462 if ( ! empty( $r['item_id'] ) ) { 1463 $where_args[] = $wpdb->prepare( "item_id = %d", $r['item_id'] );1463 $where_args[] = $wpdb->prepare( 'item_id = %d', $r['item_id'] ); 1464 1464 } 1465 1465 1466 1466 // Secondary item ID. 1467 1467 if ( ! empty( $r['secondary_item_id'] ) ) { 1468 $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $r['secondary_item_id'] );1468 $where_args[] = $wpdb->prepare( 'secondary_item_id = %d', $r['secondary_item_id'] ); 1469 1469 } 1470 1470 1471 1471 // Date Recorded. 1472 1472 if ( ! empty( $r['date_recorded'] ) ) { 1473 $where_args[] = $wpdb->prepare( "date_recorded = %s", $r['date_recorded'] );1473 $where_args[] = $wpdb->prepare( 'date_recorded = %s', $r['date_recorded'] ); 1474 1474 } 1475 1475 1476 1476 // Hidden sitewide. 1477 1477 if ( ! empty( $r['hide_sitewide'] ) ) { 1478 $where_args[] = $wpdb->prepare( "hide_sitewide = %d", $r['hide_sitewide'] );1478 $where_args[] = $wpdb->prepare( 'hide_sitewide = %d', $r['hide_sitewide'] ); 1479 1479 } 1480 1480 … … 1525 1525 1526 1526 // Delete all activity meta entries for activity items. 1527 BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );1527 self::delete_activity_meta_entries( $activity_ids ); 1528 1528 1529 1529 // Setup empty array for comments. … … 1534 1534 1535 1535 // Attempt to delete comments. 1536 $comments = BP_Activity_Activity::delete( array( 1537 'type' => 'activity_comment', 1538 'item_id' => $activity_id 1539 ) ); 1536 $comments = self::delete( 1537 array( 1538 'type' => 'activity_comment', 1539 'item_id' => $activity_id, 1540 ) 1541 ); 1540 1542 1541 1543 // Merge IDs together. … … 1624 1626 // Now fetch the activity comments and parse them into the correct position in the activities array. 1625 1627 foreach ( (array) $activities as $activity ) { 1626 $top_level_parent_id = 'activity_comment' == $activity->type ? $activity->item_id : 0;1627 $activity_comments[ $activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right, $spam, $top_level_parent_id );1628 $top_level_parent_id = 'activity_comment' == $activity->type ? $activity->item_id : 0; 1629 $activity_comments[ $activity->id ] = self::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right, $spam, $top_level_parent_id ); 1628 1630 } 1629 1631 1630 1632 // Merge the comments with the activity items. 1631 1633 foreach ( (array) $activities as $key => $activity ) { 1632 if ( isset( $activity_comments[ $activity->id] ) ) {1633 $activities[ $key]->children = $activity_comments[$activity->id];1634 if ( isset( $activity_comments[ $activity->id ] ) ) { 1635 $activities[ $key ]->children = $activity_comments[ $activity->id ]; 1634 1636 } 1635 1637 } … … 1676 1678 // Select the user's fullname with the query. 1677 1679 if ( bp_is_active( 'xprofile' ) ) { 1678 $fullname_select = ", pd.value as user_fullname";1679 $fullname_from = ", {$bp->profile->table_name_data} pd ";1680 $fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";1680 $fullname_select = ', pd.value as user_fullname'; 1681 $fullname_from = ", {$bp->profile->table_name_data} pd "; 1682 $fullname_where = 'AND pd.user_id = a.user_id AND pd.field_id = 1'; 1681 1683 1682 1684 // Prevent debug errors. … … 1742 1744 if ( isset( $ref[ $d->secondary_item_id ] ) ) { 1743 1745 $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d; 1744 $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];1746 $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ]; 1745 1747 1746 1748 // If we don't have a reference on the parent, put in the root level. 1747 1749 } else { 1748 1750 $comments[ $d->id ] = $d; 1749 $ref[ $d->id ] =& $comments[ $d->id ];1751 $ref[ $d->id ] =& $comments[ $d->id ]; 1750 1752 } 1751 1753 } … … 1753 1755 // Calculate depth for each item. 1754 1756 foreach ( $ref as &$r ) { 1755 $depth = 1;1757 $depth = 1; 1756 1758 $parent_id = $r->secondary_item_id; 1757 1759 1758 1760 while ( $parent_id !== $r->item_id ) { 1759 $depth++;1761 ++$depth; 1760 1762 1761 1763 // When display_comments=stream, the parent comment may not be part of the … … 1772 1774 $parent_id = $direct_parent->secondary_item_id; 1773 1775 } 1774 1775 1776 } else { 1776 1777 // Something went wrong. Short-circuit the depth calculation. … … 1822 1823 1823 1824 // Get all descendants of this node. 1824 $comments = BP_Activity_Activity::get_child_comments( $parent_id );1825 $comments = self::get_child_comments( $parent_id ); 1825 1826 $descendants = wp_list_pluck( $comments, 'id' ); 1826 1827 1827 1828 // Loop the descendants and recalculate the left and right values. 1828 1829 foreach ( (array) $descendants as $descendant_id ) { 1829 $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant_id, $right );1830 $right = self::rebuild_activity_comment_tree( $descendant_id, $right ); 1830 1831 } 1831 1832 … … 1901 1902 1902 1903 for ( $i = 0, $count = count( $activities ); $i < $count; ++$i ) { 1903 $title = explode( '<span', $activities[$i]['content'] );1904 $activity_feed[ $i]['title'] = wp_strip_all_tags( $title[0] );1905 $activity_feed[ $i]['link'] = $activities[$i]['primary_link'];1906 $activity_feed[ $i]['description'] = @sprintf( $activities[$i]['content'], '' );1907 $activity_feed[ $i]['pubdate'] = $activities[$i]['date_recorded'];1904 $title = explode( '<span', $activities[ $i ]['content'] ); 1905 $activity_feed[ $i ]['title'] = wp_strip_all_tags( $title[0] ); 1906 $activity_feed[ $i ]['link'] = $activities[ $i ]['primary_link']; 1907 $activity_feed[ $i ]['description'] = @sprintf( $activities[ $i ]['content'], '' ); 1908 $activity_feed[ $i ]['pubdate'] = $activities[ $i ]['date_recorded']; 1908 1909 } 1909 1910 … … 1944 1945 1945 1946 // Build IN operator sql syntax. 1946 if ( count( $items_prepared ) ) 1947 if ( count( $items_prepared ) ) { 1947 1948 return sprintf( '%s IN ( %s )', trim( $field ), implode( ',', $items_prepared ) ); 1948 else1949 } else { 1949 1950 return false; 1951 } 1950 1952 } 1951 1953 … … 1981 1983 $filter_sql = array(); 1982 1984 1983 if ( ! empty( $filter_array['user_id'] ) ) {1984 $user_sql = BP_Activity_Activity::get_in_operator_sql( 'a.user_id', $filter_array['user_id'] );1985 if ( ! empty( $user_sql ) )1985 if ( ! empty( $filter_array['user_id'] ) ) { 1986 $user_sql = self::get_in_operator_sql( 'a.user_id', $filter_array['user_id'] ); 1987 if ( ! empty( $user_sql ) ) { 1986 1988 $filter_sql[] = $user_sql; 1987 } 1988 1989 if ( !empty( $filter_array['object'] ) ) { 1990 $object_sql = BP_Activity_Activity::get_in_operator_sql( 'a.component', $filter_array['object'] ); 1991 if ( !empty( $object_sql ) ) 1989 } 1990 } 1991 1992 if ( ! empty( $filter_array['object'] ) ) { 1993 $object_sql = self::get_in_operator_sql( 'a.component', $filter_array['object'] ); 1994 if ( ! empty( $object_sql ) ) { 1992 1995 $filter_sql[] = $object_sql; 1993 } 1994 1995 if ( !empty( $filter_array['action'] ) ) { 1996 $action_sql = BP_Activity_Activity::get_in_operator_sql( 'a.type', $filter_array['action'] ); 1997 if ( ! empty( $action_sql ) ) 1996 } 1997 } 1998 1999 if ( ! empty( $filter_array['action'] ) ) { 2000 $action_sql = self::get_in_operator_sql( 'a.type', $filter_array['action'] ); 2001 if ( ! empty( $action_sql ) ) { 1998 2002 $filter_sql[] = $action_sql; 1999 } 2000 2001 if ( !empty( $filter_array['primary_id'] ) ) { 2002 $pid_sql = BP_Activity_Activity::get_in_operator_sql( 'a.item_id', $filter_array['primary_id'] ); 2003 if ( !empty( $pid_sql ) ) 2003 } 2004 } 2005 2006 if ( ! empty( $filter_array['primary_id'] ) ) { 2007 $pid_sql = self::get_in_operator_sql( 'a.item_id', $filter_array['primary_id'] ); 2008 if ( ! empty( $pid_sql ) ) { 2004 2009 $filter_sql[] = $pid_sql; 2005 } 2006 2007 if ( !empty( $filter_array['secondary_id'] ) ) { 2008 $sid_sql = BP_Activity_Activity::get_in_operator_sql( 'a.secondary_item_id', $filter_array['secondary_id'] ); 2009 if ( !empty( $sid_sql ) ) 2010 } 2011 } 2012 2013 if ( ! empty( $filter_array['secondary_id'] ) ) { 2014 $sid_sql = self::get_in_operator_sql( 'a.secondary_item_id', $filter_array['secondary_id'] ); 2015 if ( ! empty( $sid_sql ) ) { 2010 2016 $filter_sql[] = $sid_sql; 2017 } 2011 2018 } 2012 2019 2013 2020 if ( ! empty( $filter_array['offset'] ) ) { 2014 $sid_sql = absint( $filter_array['offset'] );2021 $sid_sql = absint( $filter_array['offset'] ); 2015 2022 $filter_sql[] = "a.id >= {$sid_sql}"; 2016 2023 } 2017 2024 2018 2025 if ( ! empty( $filter_array['offset_lower'] ) ) { 2019 $sid_sql = absint( $filter_array['offset_lower'] );2026 $sid_sql = absint( $filter_array['offset_lower'] ); 2020 2027 $filter_sql[] = "a.id <= {$sid_sql}"; 2021 2028 } … … 2030 2037 } 2031 2038 2032 if ( empty( $filter_sql ) ) 2039 if ( empty( $filter_sql ) ) { 2033 2040 return false; 2041 } 2034 2042 2035 2043 return join( ' AND ', $filter_sql );
Note: See TracChangeset
for help on using the changeset viewer.