Merge pull request #189 from blueset/blueset/outbox_posttype

This commit is contained in:
Matthias Pfefferle 2022-11-20 12:51:01 +01:00 committed by GitHub
commit 010ccc7e22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,6 +43,7 @@ class Outbox {
public static function user_outbox_get( $request ) { public static function user_outbox_get( $request ) {
$user_id = $request->get_param( 'user_id' ); $user_id = $request->get_param( 'user_id' );
$author = \get_user_by( 'ID', $user_id ); $author = \get_user_by( 'ID', $user_id );
$post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) );
if ( ! $author ) { if ( ! $author ) {
return new \WP_Error( return new \WP_Error(
@ -73,8 +74,11 @@ class Outbox {
$json->type = 'OrderedCollectionPage'; $json->type = 'OrderedCollectionPage';
$json->partOf = \get_rest_url( null, "/activitypub/1.0/users/$user_id/outbox" ); // phpcs:ignore $json->partOf = \get_rest_url( null, "/activitypub/1.0/users/$user_id/outbox" ); // phpcs:ignore
$count_posts = \wp_count_posts(); $json->totalItems = 0;
$json->totalItems = \intval( $count_posts->publish ); // phpcs:ignore foreach ( $post_types as $post_type ) {
$count_posts = \wp_count_posts( $post_type );
$json->totalItems += \intval( $count_posts->publish ); // phpcs:ignore
}
$json->first = \add_query_arg( 'page', 1, $json->partOf ); // phpcs:ignore $json->first = \add_query_arg( 'page', 1, $json->partOf ); // phpcs:ignore
$json->last = \add_query_arg( 'page', \ceil ( $json->totalItems / 10 ), $json->partOf ); // phpcs:ignore $json->last = \add_query_arg( 'page', \ceil ( $json->totalItems / 10 ), $json->partOf ); // phpcs:ignore
@ -89,7 +93,7 @@ class Outbox {
'posts_per_page' => 10, 'posts_per_page' => 10,
'author' => $user_id, 'author' => $user_id,
'offset' => ( $page - 1 ) * 10, 'offset' => ( $page - 1 ) * 10,
'post_type' => 'post', 'post_type' => $post_types,
) )
); );