PluginProbe
ActivityPub / 5.7.0
ActivityPub v5.7.0
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/collection/class-replies.php +27 -23 8.2.15.7.0 View file →
@@ -6,16 +6,20 @@
6 6 */
7 7
8 8 namespace Activitypub\Collection;
9 9
10 +use WP_Post;
11 +use WP_Comment;
12 +use WP_Error;
13 +
10 14 use Activitypub\Comment;
11 15 use Activitypub\Model\Blog;
12 -use Activitypub\Transformer\Comment as Comment_Transformer;
13 -use Activitypub\Transformer\Post as Post_Transformer;
16 +use Activitypub\Transformer\Post as PostTransformer;
17 +use Activitypub\Transformer\Comment as CommentTransformer;
14 18
19 +use function Activitypub\is_post_disabled;
20 +use function Activitypub\is_local_comment;
15 21 use function Activitypub\get_rest_url_by_path;
16 -use function Activitypub\is_local_comment;
17 -use function Activitypub\is_post_publicly_queryable;
18 22 use function Activitypub\is_user_type_disabled;
19 23
20 24 /**
21 25 * Class containing code for getting replies Collections and CollectionPages of posts and comments.
@@ -23,9 +27,9 @@
23 27 class Replies {
24 28 /**
25 29 * Build base arguments for fetching the comments of either a WordPress post or comment.
26 30 *
27 - * @param \WP_Post|\WP_Comment|\WP_Error $wp_object The post or comment to fetch replies for on success.
31 + * @param WP_Post|WP_Comment|WP_Error $wp_object The post or comment to fetch replies for on success.
28 32 */
29 33 private static function build_args( $wp_object ) {
30 34 $args = array(
31 35 'status' => 'approve',
@@ -33,15 +37,15 @@
33 37 'order' => 'ASC',
34 38 'type' => 'comment',
35 39 );
36 40
37 - if ( $wp_object instanceof \WP_Post ) {
41 + if ( $wp_object instanceof WP_Post ) {
38 42 $args['parent'] = 0; // TODO: maybe this is unnecessary.
39 43 $args['post_id'] = $wp_object->ID;
40 - } elseif ( $wp_object instanceof \WP_Comment ) {
44 + } elseif ( $wp_object instanceof WP_Comment ) {
41 45 $args['parent'] = $wp_object->comment_ID;
42 46 } else {
43 - return new \WP_Error();
47 + return new WP_Error();
44 48 }
45 49
46 50 return $args;
47 51 }
@@ -48,19 +52,19 @@
48 52
49 53 /**
50 54 * Get the replies collections ID.
51 55 *
52 - * @param \WP_Post|\WP_Comment $wp_object The post or comment to fetch replies for.
56 + * @param WP_Post|WP_Comment $wp_object The post or comment to fetch replies for.
53 57 *
54 - * @return string|\WP_Error The rest URL of the replies collection or WP_Error if the object is not a post or comment.
58 + * @return string|WP_Error The rest URL of the replies collection or WP_Error if the object is not a post or comment.
55 59 */
56 60 private static function get_id( $wp_object ) {
57 - if ( $wp_object instanceof \WP_Post ) {
61 + if ( $wp_object instanceof WP_Post ) {
58 62 return get_rest_url_by_path( sprintf( 'posts/%d/replies', $wp_object->ID ) );
59 - } elseif ( $wp_object instanceof \WP_Comment ) {
63 + } elseif ( $wp_object instanceof WP_Comment ) {
60 64 return get_rest_url_by_path( sprintf( 'comments/%d/replies', $wp_object->comment_ID ) );
61 65 } else {
62 - return new \WP_Error( 'unsupported_object', 'The object is not a post or comment.' );
66 + return new WP_Error( 'unsupported_object', 'The object is not a post or comment.' );
63 67 }
64 68 }
65 69
66 70 /**
@@ -65,9 +69,9 @@
65 69
66 70 /**
67 71 * Get the Replies collection.
68 72 *
69 - * @param \WP_Post|\WP_Comment $wp_object The post or comment to fetch replies for.
73 + * @param WP_Post|WP_Comment $wp_object The post or comment to fetch replies for.
70 74 *
71 75 * @return array|\WP_Error|null An associative array containing the replies collection without JSON-LD context on success.
72 76 */
73 77 public static function get_collection( $wp_object ) {
@@ -91,13 +95,13 @@
91 95 * Returns a replies collection page as an associative array.
92 96 *
93 97 * @link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collectionpage
94 98 *
95 - * @param \WP_Post|\WP_Comment $wp_object The post of comment the replies are for.
96 - * @param int $page The current pagination page.
97 - * @param string $part_of Optional. The collection id/url the returned CollectionPage belongs to. Default null.
99 + * @param WP_Post|WP_Comment $wp_object The post of comment the replies are for.
100 + * @param int $page The current pagination page.
101 + * @param string $part_of Optional. The collection id/url the returned CollectionPage belongs to. Default null.
98 102 *
99 - * @return array|\WP_Error|null A CollectionPage as an associative array on success, WP_Error or null on failure.
103 + * @return array|WP_Error|null A CollectionPage as an associative array on success, WP_Error or null on failure.
100 104 */
101 105 public static function get_collection_page( $wp_object, $page, $part_of = null ) {
102 106 // Build initial arguments for fetching approved comments.
103 107 $args = self::build_args( $wp_object );
@@ -151,9 +155,9 @@
151 155 */
152 156 public static function get_context_collection( $post_id ) {
153 157 $post = \get_post( $post_id );
154 158
155 - if ( ! is_post_publicly_queryable( $post_id ) ) {
159 + if ( ! $post || is_post_disabled( $post_id ) ) {
156 160 return false;
157 161 }
158 162
159 163 $comments = \get_comments(
@@ -165,9 +169,9 @@
165 169 'order' => 'ASC',
166 170 )
167 171 );
168 172 $ids = self::get_reply_ids( $comments, true );
169 - $post_uri = ( new Post_Transformer( $post ) )->to_id();
173 + $post_uri = ( new PostTransformer( $post ) )->to_id();
170 174 \array_unshift( $ids, $post_uri );
171 175
172 176 $author = Actors::get_by_id( $post->post_author );
173 177 if ( is_wp_error( $author ) ) {
@@ -192,10 +196,10 @@
192 196 *
193 197 * It takes only federated/non-local comments into account, others also do not have an
194 198 * ActivityPub ID available.
195 199 *
196 - * @param \WP_Comment[] $comments The comments to retrieve the ActivityPub ids from.
197 - * @param boolean $include_blog_comments Optional. Include blog comments in the returned array. Default false.
200 + * @param WP_Comment[] $comments The comments to retrieve the ActivityPub ids from.
201 + * @param boolean $include_blog_comments Optional. Include blog comments in the returned array. Default false.
198 202 *
199 203 * @return string[] A list of the ActivityPub ID's.
200 204 */
201 205 private static function get_reply_ids( $comments, $include_blog_comments = false ) {
@@ -212,9 +216,9 @@
212 216 continue;
213 217 }
214 218
215 219 if ( $include_blog_comments ) {
216 - $comment_ids[] = ( new Comment_Transformer( $comment ) )->to_id();
220 + $comment_ids[] = ( new CommentTransformer( $comment ) )->to_id();
217 221 }
218 222 }
219 223
220 224 return \array_unique( $comment_ids );