BP_Activity_Activity:: get_activity_comments (intactivity_id美元,int剩余美元,int美元对吧,字符串美元的垃圾邮件=“ham_only”,int$top\u level\u parent\u id)
获取与特定活动ID相关联的活动注释。
描述
参数
- activity_id美元
-
(int)(必需)获取注释的活动ID。
- 剩余美元
-
(int)(必需)最左侧的节点边界。
- 美元对吧
-
(int)(必需)最右节点边界。
- 美元的垃圾邮件
-
(字符串)(可选)'ham_only'(默认),'spam_only'或'all'。
默认值:“ham_only”
- $top\u level\u parent\u id
-
(int)(可选)根级父活动项的id。
返回
(数组)带有嵌套注释的更新活动。
源
文件:bp-activity /类/ class-bp-activity-activity.php
Public static function get_activity_comments($activity_id, $left, $right, $spam = 'ham_only', $top_level_parent_id = 0){全局$wpdb;If(空($top_level_parent_id)) {$top_level_parent_id = $activity_id;} $comments = wp_cache_get($activity_id, 'bp_activity_comments');//我们存储字符串'none'来缓存//活动项没有注释的事实。If ('none' === $comments) {$comments = false;} elseif (empty($comments)) {$bp = buddypress();//使用查询选择用户的全名。If (bp_is_active('xprofile')) {$fullname_select = ", pd. log . log . log . log . log . log . log . log . log。值作为user_fullname”;$bp = ", {$bp->profile->table_name_data} pd ";$fullname_where = "AND pd. "user_id = a.user_id AND pd.field_id = 1"; // Prevent debug errors. } else { $fullname_select = $fullname_from = $fullname_where = ''; } // Don't retrieve activity comments marked as spam. if ( 'ham_only' == $spam ) { $spam_sql = 'AND a.is_spam = 0'; } elseif ( 'spam_only' == $spam ) { $spam_sql = 'AND a.is_spam = 1'; } else { $spam_sql = ''; } // Legacy query - not recommended. /** * Filters if BuddyPress should use the legacy activity query. * * @since BuddyPress 2.0.0 * * @param bool $value Whether or not to use the legacy query. * @param BP_Activity_Activity $value Magic method referring to currently called method. * @param array $func_args Array of the method's argument list. */ if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, func_get_args() ) ) { /** * Filters the MySQL prepared statement for the legacy activity query. * * @since BuddyPress 1.5.0 * * @param string $value Prepared statement for the activity query. * @param int $activity_id Activity ID to fetch comments for. * @param int $left Left-most node boundary. * @param int $right Right-most node boundary. * @param string $spam_sql SQL Statement portion to differentiate between ham or spam. */ $sql = apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' {$spam_sql} AND a.item_id = %d AND a.mptt_left > %d AND a.mptt_left < %d ORDER BY a.date_recorded ASC", $top_level_parent_id, $left, $right ), $activity_id, $left, $right, $spam_sql ); $descendants = $wpdb->get_results( $sql ); // We use the mptt BETWEEN clause to limit returned // descendants to the correct part of the tree. } else { $sql = $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} a WHERE a.type = 'activity_comment' {$spam_sql} AND a.item_id = %d and a.mptt_left > %d AND a.mptt_left < %d ORDER BY a.date_recorded ASC", $top_level_parent_id, $left, $right ); $descendant_ids = $wpdb->get_col( $sql ); $descendants = self::get_activity_data( $descendant_ids ); $descendants = self::append_user_fullnames( $descendants ); } $ref = array(); // Loop descendants and build an assoc array. foreach ( (array) $descendants as $d ) { $d->children = array(); // If we have a reference on the parent. if ( isset( $ref[ $d->secondary_item_id ] ) ) { $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d; $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ]; // If we don't have a reference on the parent, put in the root level. } else { $comments[ $d->id ] = $d; $ref[ $d->id ] =& $comments[ $d->id ]; } } // Calculate depth for each item. foreach ( $ref as &$r ) { $depth = 1; $parent_id = $r->secondary_item_id; while ( $parent_id !== $r->item_id ) { $depth++; // When display_comments=stream, the parent comment may not be part of the // returned results, so we manually fetch it. if ( empty( $ref[ $parent_id ] ) ) { $direct_parent = new BP_Activity_Activity( $parent_id ); if ( isset( $direct_parent->secondary_item_id ) ) { // If the direct parent is not an activity update, that means we've reached // the parent activity item (eg. new_blog_post). if ( 'activity_update' !== $direct_parent->type ) { $parent_id = $r->item_id; } else { $parent_id = $direct_parent->secondary_item_id; } } else { // Something went wrong. Short-circuit the depth calculation. $parent_id = $r->item_id; } } else { $parent_id = $ref[ $parent_id ]->secondary_item_id; } } $r->depth = $depth; } // If we cache a value of false, it'll count as a cache // miss the next time the activity comments are fetched. // Storing the string 'none' is a hack workaround to // avoid unnecessary queries. if ( false === $comments ) { $cache_value = 'none'; } else { $cache_value = $comments; } wp_cache_set( $activity_id, $cache_value, 'bp_activity_comments' ); } return $comments; }
更新日志
版本 | 描述 |
---|---|
BuddyPress 1.2.0 | 介绍了。 |