| @@ -1,13 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Activitypub\Rest; |
| 3 | 3 | |
| 4 | -use WP_Error; | |
| 5 | 4 | use WP_REST_Server; |
| 6 | 5 | use WP_REST_Response; |
| 7 | -use Activitypub\Transformer\Post; | |
| 8 | -use Activitypub\Activity\Activity; | |
| 6 | +use Activitypub\Activity\Actor; | |
| 7 | +use Activitypub\Activity\Base_Object; | |
| 9 | 8 | use Activitypub\Collection\Users as User_Collection; |
| 9 | +use Activitypub\Transformer\Factory; | |
| 10 | 10 | |
| 11 | 11 | use function Activitypub\esc_hashtag; |
| 12 | 12 | use function Activitypub\is_single_user; |
| 13 | 13 | use function Activitypub\get_rest_url_by_path; |
| @@ -33,9 +33,9 @@ | ||
| 33 | 33 | */ |
| 34 | 34 | public static function register_routes() { |
| 35 | 35 | \register_rest_route( |
| 36 | 36 | ACTIVITYPUB_REST_NAMESPACE, |
| 37 | - '/users/(?P<user_id>[\w\-\.]+)/collections/tags', | |
| 37 | + '/(users|actors)/(?P<user_id>[\w\-\.]+)/collections/tags', | |
| 38 | 38 | array( |
| 39 | 39 | array( |
| 40 | 40 | 'methods' => WP_REST_Server::READABLE, |
| 41 | 41 | 'callback' => array( self::class, 'tags_get' ), |
| @@ -46,9 +46,9 @@ | ||
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | 48 | \register_rest_route( |
| 49 | 49 | ACTIVITYPUB_REST_NAMESPACE, |
| 50 | - '/users/(?P<user_id>[\w\-\.]+)/collections/featured', | |
| 50 | + '/(users|actors)/(?P<user_id>[\w\-\.]+)/collections/featured', | |
| 51 | 51 | array( |
| 52 | 52 | array( |
| 53 | 53 | 'methods' => WP_REST_Server::READABLE, |
| 54 | 54 | 'callback' => array( self::class, 'featured_get' ), |
| @@ -101,10 +101,10 @@ | ||
| 101 | 101 | $tags = array(); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $response = array( |
| 105 | - '@context' => Activity::CONTEXT, | |
| 106 | - 'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/tags', $user->get__id() ) ), | |
| 105 | + '@context' => Base_Object::JSON_LD_CONTEXT, | |
| 106 | + 'id' => get_rest_url_by_path( sprintf( 'actors/%d/collections/tags', $user->get__id() ) ), | |
| 107 | 107 | 'type' => 'Collection', |
| 108 | 108 | 'totalItems' => is_countable( $tags ) ? count( $tags ) : 0, |
| 109 | 109 | 'items' => array(), |
| 110 | 110 | ); |
| @@ -159,10 +159,10 @@ | ||
| 159 | 159 | $posts = array(); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | $response = array( |
| 163 | - '@context' => Activity::CONTEXT, | |
| 164 | - 'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/featured', $user_id ) ), | |
| 163 | + '@context' => Base_Object::JSON_LD_CONTEXT, | |
| 164 | + 'id' => get_rest_url_by_path( sprintf( 'actors/%d/collections/featured', $user_id ) ), | |
| 165 | 165 | 'type' => 'OrderedCollection', |
| 166 | 166 | 'totalItems' => is_countable( $posts ) ? count( $posts ) : 0, |
| 167 | 167 | 'orderedItems' => array(), |
| 168 | 168 | ); |
| @@ -167,9 +167,15 @@ | ||
| 167 | 167 | 'orderedItems' => array(), |
| 168 | 168 | ); |
| 169 | 169 | |
| 170 | 170 | foreach ( $posts as $post ) { |
| 171 | - $response['orderedItems'][] = Post::transform( $post )->to_object()->to_array(); | |
| 171 | + $transformer = Factory::get_transformer( $post ); | |
| 172 | + | |
| 173 | + if ( \is_wp_error( $transformer ) ) { | |
| 174 | + continue; | |
| 175 | + } | |
| 176 | + | |
| 177 | + $response['orderedItems'][] = $transformer->to_object()->to_array( false ); | |
| 172 | 178 | } |
| 173 | 179 | |
| 174 | 180 | $rest_response = new WP_REST_Response( $response, 200 ); |
| 175 | 181 | $rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) ); |
| @@ -185,9 +191,9 @@ | ||
| 185 | 191 | * @return WP_REST_Response The response object. |
| 186 | 192 | */ |
| 187 | 193 | public static function moderators_get( $request ) { |
| 188 | 194 | $response = array( |
| 189 | - '@context' => Activity::CONTEXT, | |
| 195 | + '@context' => Actor::JSON_LD_CONTEXT, | |
| 190 | 196 | 'id' => get_rest_url_by_path( 'collections/moderators' ), |
| 191 | 197 | 'type' => 'OrderedCollection', |
| 192 | 198 | 'orderedItems' => array(), |
| 193 | 199 | ); |