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/rest/class-interaction-controller.php +13 -79 9.2.05.7.0 View file →
@@ -6,14 +6,10 @@
6 6 */
7 7
8 8 namespace Activitypub\Rest;
9 9
10 -use Activitypub\Activity\Activity;
11 -use Activitypub\Collection\Actors;
12 10 use Activitypub\Http;
13 11
14 -use function Activitypub\user_can_activitypub;
15 -
16 12 /**
17 13 * Interaction Controller.
18 14 */
19 15 class Interaction_Controller extends \WP_REST_Controller {
@@ -43,18 +39,13 @@
43 39 'methods' => \WP_REST_Server::READABLE,
44 40 'callback' => array( $this, 'get_item' ),
45 41 'permission_callback' => '__return_true',
46 42 'args' => array(
47 - 'uri' => array(
48 - 'description' => 'The URI or webfinger ID of the object to interact with.',
49 - 'type' => 'string',
50 - 'required' => true,
51 - 'sanitize_callback' => array( $this, 'sanitize_uri' ),
52 - ),
53 - 'intent' => array(
54 - 'description' => 'The intent of the interaction, e.g., follow, reply, import.',
43 + 'uri' => array(
44 + 'description' => 'The URI of the object to interact with.',
55 45 'type' => 'string',
56 - 'enum' => \array_map( 'Activitypub\camel_to_snake_case', Activity::TYPES ),
46 + 'format' => 'uri',
47 + 'required' => true,
57 48 ),
58 49 ),
59 50 ),
60 51 )
@@ -61,31 +52,8 @@
61 52 );
62 53 }
63 54
64 55 /**
65 - * Sanitize the URI parameter.
66 - *
67 - * @param string $uri The URI or webfinger ID of the object to interact with.
68 - *
69 - * @return string Sanitized URI.
70 - */
71 - public function sanitize_uri( $uri ) {
72 - // Remove "acct:" prefix if present.
73 - if ( \str_starts_with( $uri, 'acct:' ) ) {
74 - $uri = \substr( $uri, 5 );
75 - }
76 -
77 - // Remove "@" prefix if present.
78 - $uri = \ltrim( $uri, '@' );
79 -
80 - if ( \is_email( $uri ) ) {
81 - return \sanitize_text_field( $uri );
82 - }
83 -
84 - return \sanitize_url( $uri );
85 - }
86 -
87 - /**
88 56 * Retrieves the interaction URL for a given URI.
89 57 *
90 58 * @param \WP_REST_Request $request The request object.
91 59 *
@@ -92,9 +60,8 @@
92 60 * @return \WP_REST_Response Response object on success, dies on failure.
93 61 */
94 62 public function get_item( $request ) {
95 63 $uri = $request->get_param( 'uri' );
96 - $intent = $request->get_param( 'intent' );
97 64 $redirect_url = '';
98 65 $object = Http::get_remote_object( $uri );
99 66
100 67 if ( \is_wp_error( $object ) || ! isset( $object['type'] ) ) {
@@ -99,9 +66,9 @@
99 66
100 67 if ( \is_wp_error( $object ) || ! isset( $object['type'] ) ) {
101 68 // Use wp_die as this can be called from the front-end. See https://github.com/Automattic/wordpress-activitypub/pull/1149/files#r1915297109.
102 69 \wp_die(
103 - \esc_html__( 'The URL is not supported!', 'activitypub' ),
70 + esc_html__( 'The URL is not supported!', 'activitypub' ),
104 71 '',
105 72 array(
106 73 'response' => 400,
107 74 'back_link' => true,
@@ -108,15 +75,12 @@
108 75 )
109 76 );
110 77 }
111 78
112 - if ( ! empty( $object['id'] ) ) {
113 - $uri = \esc_url_raw( $object['id'] );
79 + if ( ! empty( $object['url'] ) ) {
80 + $uri = \esc_url( $object['url'] );
114 81 }
115 82
116 - // Prepare URL parameter.
117 - $url_param = \rawurlencode( $uri );
118 -
119 83 switch ( $object['type'] ) {
120 84 case 'Group':
121 85 case 'Person':
122 86 case 'Service':
@@ -121,16 +85,8 @@
121 85 case 'Person':
122 86 case 'Service':
123 87 case 'Application':
124 88 case 'Organization':
125 - if ( \get_option( 'activitypub_following_ui', '0' ) ) {
126 - if ( user_can_activitypub( \get_current_user_id() ) ) {
127 - $redirect_url = \admin_url( 'users.php?page=activitypub-following-list&resource=' . $url_param );
128 - } elseif ( user_can_activitypub( Actors::BLOG_USER_ID ) ) {
129 - $redirect_url = \admin_url( 'options-general.php?page=activitypub&tab=following&resource=' . $url_param );
130 - }
131 - }
132 -
133 89 /**
134 90 * Filters the URL used for following an ActivityPub actor.
135 91 *
136 92 * @param string $redirect_url The URL to redirect to.
@@ -135,33 +91,13 @@
135 91 *
136 92 * @param string $redirect_url The URL to redirect to.
137 93 * @param string $uri The URI of the actor to follow.
138 94 * @param array $object The full actor object data.
139 - * @param string $intent The intent of the interaction.
140 95 */
141 - $redirect_url = \apply_filters( 'activitypub_interactions_follow_url', $redirect_url, $uri, $object, $intent );
96 + $redirect_url = \apply_filters( 'activitypub_interactions_follow_url', $redirect_url, $uri, $object );
142 97 break;
143 - case 'Collection':
144 - case 'CollectionPage':
145 - case 'OrderedCollection':
146 - case 'OrderedCollectionPage':
147 - if ( \get_option( 'activitypub_following_ui', '0' ) ) {
148 - $redirect_url = \admin_url( 'admin.php?import=starter-kit&url=' . $url_param );
149 - }
150 -
151 - /**
152 - * Filters the URL used for importing a Starter Kit collection.
153 - *
154 - * @param string $redirect_url The URL to redirect to.
155 - * @param string $uri The URI of the collection to import.
156 - * @param array $object The full collection object data.
157 - * @param string $intent The intent of the interaction.
158 - */
159 - $redirect_url = \apply_filters( 'activitypub_interactions_starter_kit_url', $redirect_url, $uri, $object, $intent );
160 - break;
161 98 default:
162 - $redirect_url = \admin_url( 'post-new.php?in_reply_to=' . $url_param );
163 -
99 + $redirect_url = \admin_url( 'post-new.php?in_reply_to=' . $uri );
164 100 /**
165 101 * Filters the URL used for replying to an ActivityPub object.
166 102 *
167 103 * By default, this redirects to the WordPress post editor with the in_reply_to parameter set.
@@ -168,11 +104,10 @@
168 104 *
169 105 * @param string $redirect_url The URL to redirect to.
170 106 * @param string $uri The URI of the object to reply to.
171 107 * @param array $object The full object data being replied to.
172 - * @param string $intent The intent of the interaction.
173 108 */
174 - $redirect_url = \apply_filters( 'activitypub_interactions_reply_url', $redirect_url, $uri, $object, $intent );
109 + $redirect_url = \apply_filters( 'activitypub_interactions_reply_url', $redirect_url, $uri, $object );
175 110 }
176 111
177 112 /**
178 113 * Filters the redirect URL.
@@ -182,17 +117,16 @@
182 117 *
183 118 * @param string $redirect_url The URL to redirect to.
184 119 * @param string $uri The URI of the object.
185 120 * @param array $object The object being interacted with.
186 - * @param string $intent The intent of the interaction.
187 121 */
188 - $redirect_url = \apply_filters( 'activitypub_interactions_url', $redirect_url, $uri, $object, $intent );
122 + $redirect_url = \apply_filters( 'activitypub_interactions_url', $redirect_url, $uri, $object );
189 123
190 124 // Check if hook is implemented.
191 125 if ( ! $redirect_url ) {
192 126 // Use wp_die as this can be called from the front-end. See https://github.com/Automattic/wordpress-activitypub/pull/1149/files#r1915297109.
193 127 \wp_die(
194 - \esc_html__( 'This Interaction type is not supported yet!', 'activitypub' ),
128 + esc_html__( 'This Interaction type is not supported yet!', 'activitypub' ),
195 129 '',
196 130 array(
197 131 'response' => 400,
198 132 'back_link' => true,
@@ -199,7 +133,7 @@
199 133 )
200 134 );
201 135 }
202 136
203 - return new \WP_REST_Response( null, 302, array( 'Location' => $redirect_url ) );
137 + return new \WP_REST_Response( null, 302, array( 'Location' => \esc_url( $redirect_url ) ) );
204 138 }
205 139 }