PluginProbe
ActivityPub / 5.3.1
ActivityPub v5.3.1
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/model/class-user.php +53 -115 8.2.15.3.1 View file →
@@ -6,16 +6,17 @@
6 6 */
7 7
8 8 namespace Activitypub\Model;
9 9
10 +use WP_Error;
11 +use Activitypub\Signature;
10 12 use Activitypub\Activity\Actor;
11 -use Activitypub\Collection\Actors;
12 13 use Activitypub\Collection\Extra_Fields;
13 14
15 +use function Activitypub\is_blog_public;
16 +use function Activitypub\is_user_disabled;
17 +use function Activitypub\get_rest_url_by_path;
14 18 use function Activitypub\get_attribution_domains;
15 -use function Activitypub\get_rest_url_by_path;
16 -use function Activitypub\is_blog_public;
17 -use function Activitypub\user_can_activitypub;
18 19
19 20 /**
20 21 * User class.
21 22 *
@@ -29,8 +30,22 @@
29 30 */
30 31 protected $_id; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
31 32
32 33 /**
34 + * The Featured-Posts.
35 + *
36 + * @see https://docs.joinmastodon.org/spec/activitypub/#featured
37 + *
38 + * @context {
39 + * "@id": "http://joinmastodon.org/ns#featured",
40 + * "@type": "@id"
41 + * }
42 + *
43 + * @var string
44 + */
45 + protected $featured;
46 +
47 + /**
33 48 * Whether the User is discoverable.
34 49 *
35 50 * @see https://docs.joinmastodon.org/spec/activitypub/#discoverable
36 51 *
@@ -40,43 +55,23 @@
40 55 */
41 56 protected $discoverable = true;
42 57
43 58 /**
44 - * The generator of the object.
59 + * Whether the User is indexable.
45 60 *
46 - * @see https://www.w3.org/TR/activitypub/#generator
47 - * @see https://codeberg.org/fediverse/fep/src/branch/main/fep/844e/fep-844e.md#discovery-through-an-actor
61 + * @context http://joinmastodon.org/ns#indexable
48 62 *
49 - * @var array
63 + * @var boolean
50 64 */
51 - protected $generator = array(
52 - 'type' => 'Application',
53 - 'implements' => array(
54 - array(
55 - 'href' => 'https://datatracker.ietf.org/doc/html/rfc9421',
56 - 'name' => 'RFC-9421: HTTP Message Signatures',
57 - ),
58 - ),
59 - );
65 + protected $indexable;
60 66
61 67 /**
62 - * Constructor.
68 + * The WebFinger Resource.
63 69 *
64 - * @param int $user_id Optional. The WordPress user ID. Default null.
70 + * @var string
65 71 */
66 - public function __construct( $user_id = null ) {
67 - if ( $user_id ) {
68 - $this->_id = $user_id;
72 + protected $webfinger;
69 73
70 - /**
71 - * Fires when a model actor is constructed.
72 - *
73 - * @param User $this The User object.
74 - */
75 - \do_action( 'activitypub_construct_model_actor', $this );
76 - }
77 - }
78 -
79 74 /**
80 75 * The type of the object.
81 76 *
82 77 * @return string The type of the object.
@@ -89,13 +84,13 @@
89 84 * Generate a User object from a WP_User.
90 85 *
91 86 * @param int $user_id The user ID.
92 87 *
93 - * @return \WP_Error|User The User object or \WP_Error if user not found.
88 + * @return WP_Error|User The User object or WP_Error if user not found.
94 89 */
95 90 public static function from_wp_user( $user_id ) {
96 - if ( ! user_can_activitypub( $user_id ) ) {
97 - return new \WP_Error(
91 + if ( is_user_disabled( $user_id ) ) {
92 + return new WP_Error(
98 93 'activitypub_user_not_found',
99 94 \__( 'User not found', 'activitypub' ),
100 95 array( 'status' => 404 )
101 96 );
@@ -100,9 +95,12 @@
100 95 array( 'status' => 404 )
101 96 );
102 97 }
103 98
104 - return new static( $user_id );
99 + $object = new static();
100 + $object->_id = $user_id;
101 +
102 + return $object;
105 103 }
106 104
107 105 /**
108 106 * Get the user ID.
@@ -109,14 +107,8 @@
109 107 *
110 108 * @return string The user ID.
111 109 */
112 110 public function get_id() {
113 - $id = parent::get_id();
114 -
115 - if ( $id ) {
116 - return $id;
117 - }
118 -
119 111 $permalink = \get_user_option( 'activitypub_use_permalink_as_id', $this->_id );
120 112
121 113 if ( '1' === $permalink ) {
122 114 return $this->get_url();
@@ -121,9 +113,9 @@
121 113 if ( '1' === $permalink ) {
122 114 return $this->get_url();
123 115 }
124 116
125 - return \add_query_arg( 'author', $this->_id, \home_url( '/' ) );
117 + return \add_query_arg( 'author', $this->_id, \trailingslashit( \home_url() ) );
126 118 }
127 119
128 120 /**
129 121 * Get the Username.
@@ -170,26 +162,19 @@
170 162 *
171 163 * @return string The preferred username.
172 164 */
173 165 public function get_preferred_username() {
174 - $login = \get_the_author_meta( 'login', $this->_id );
175 -
176 - // Handle cases where login is an email address (e.g., from Site Kit Google login).
177 - if ( \filter_var( $login, FILTER_VALIDATE_EMAIL ) ) {
178 - $login = \get_the_author_meta( 'user_nicename', $this->_id );
179 - }
180 -
181 - return $login;
166 + return \get_the_author_meta( 'login', $this->_id );
182 167 }
183 168
184 169 /**
185 170 * Get the User icon.
186 171 *
187 - * @return string[] The User icon.
172 + * @return array The User icon.
188 173 */
189 174 public function get_icon() {
190 175 $icon = \get_user_option( 'activitypub_icon', $this->_id );
191 - if ( false !== $icon && wp_attachment_is_image( $icon ) ) {
176 + if ( wp_attachment_is_image( $icon ) ) {
192 177 return array(
193 178 'type' => 'Image',
194 179 'url' => esc_url( wp_get_attachment_url( $icon ) ),
195 180 );
@@ -210,9 +195,9 @@
210 195
211 196 /**
212 197 * Returns the header image.
213 198 *
214 - * @return string[]|null The header image.
199 + * @return array|null The header image.
215 200 */
216 201 public function get_image() {
217 202 $header_image = get_user_option( 'activitypub_header_image', $this->_id );
218 203 $image_url = null;
@@ -240,21 +225,21 @@
240 225 *
241 226 * @return false|string The date the user was created.
242 227 */
243 228 public function get_published() {
244 - return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, \strtotime( \get_the_author_meta( 'registered', $this->_id ) ) );
229 + return \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( \get_the_author_meta( 'registered', $this->_id ) ) );
245 230 }
246 231
247 232 /**
248 233 * Returns the public key.
249 234 *
250 - * @return string[] The public key.
235 + * @return array The public key.
251 236 */
252 237 public function get_public_key() {
253 238 return array(
254 239 'id' => $this->get_id() . '#main-key',
255 240 'owner' => $this->get_id(),
256 - 'publicKeyPem' => Actors::get_public_key( $this->get__id() ),
241 + 'publicKeyPem' => Signature::get_public_key_for( $this->get__id() ),
257 242 );
258 243 }
259 244
260 245 /**
@@ -293,19 +278,8 @@
293 278 return get_rest_url_by_path( sprintf( 'actors/%d/following', $this->get__id() ) );
294 279 }
295 280
296 281 /**
297 - * Returns the Liked API endpoint.
298 - *
299 - * @since 8.1.0
300 - *
301 - * @return string The Liked endpoint.
302 - */
303 - public function get_liked() {
304 - return get_rest_url_by_path( sprintf( 'actors/%d/liked', $this->get__id() ) );
305 - }
306 -
307 - /**
308 282 * Returns the Featured-API-Endpoint.
309 283 *
310 284 * @return string The Featured-Endpoint.
311 285 */
@@ -313,30 +287,22 @@
313 287 return get_rest_url_by_path( sprintf( 'actors/%d/collections/featured', $this->get__id() ) );
314 288 }
315 289
316 290 /**
317 - * Returns the Featured-Tags-API-Endpoint.
318 - *
319 - * @return string The Featured-Tags-Endpoint.
320 - */
321 - public function get_featured_tags() {
322 - return get_rest_url_by_path( sprintf( 'actors/%d/collections/tags', $this->get__id() ) );
323 - }
324 -
325 - /**
326 291 * Returns the endpoints.
327 292 *
328 - * @return string[]|null The endpoints.
293 + * @return array|null The endpoints.
329 294 */
330 295 public function get_endpoints() {
331 - return array(
332 - 'sharedInbox' => get_rest_url_by_path( 'inbox' ),
333 - 'oauthAuthorizationEndpoint' => get_rest_url_by_path( 'oauth/authorize' ),
334 - 'oauthTokenEndpoint' => get_rest_url_by_path( 'oauth/token' ),
335 - 'oauthRegistrationEndpoint' => get_rest_url_by_path( 'oauth/clients' ),
336 - 'proxyUrl' => get_rest_url_by_path( 'proxy' ),
337 - 'proxyEventStream' => get_rest_url_by_path( 'proxy/stream' ),
338 - );
296 + $endpoints = null;
297 +
298 + if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) {
299 + $endpoints = array(
300 + 'sharedInbox' => get_rest_url_by_path( 'inbox' ),
301 + );
302 + }
303 +
304 + return $endpoints;
339 305 }
340 306
341 307 /**
342 308 * Extend the User-Output with Attachments.
@@ -400,9 +366,9 @@
400 366 /**
401 367 * Update the username.
402 368 *
403 369 * @param string $value The new value.
404 - * @return int|\WP_Error The updated user ID or \WP_Error on failure.
370 + * @return int|WP_Error The updated user ID or WP_Error on failure.
405 371 */
406 372 public function update_name( $value ) {
407 373 $userdata = array(
408 374 'ID' => $this->_id,
@@ -449,38 +415,10 @@
449 415
450 416 /**
451 417 * Returns the website hosts allowed to credit this blog.
452 418 *
453 - * @return string[]|null The attribution domains or null if not found.
419 + * @return array|null The attribution domains or null if not found.
454 420 */
455 421 public function get_attribution_domains() {
456 422 return get_attribution_domains();
457 - }
458 -
459 - /**
460 - * Returns the alsoKnownAs.
461 - *
462 - * @return string[] The alsoKnownAs.
463 - */
464 - public function get_also_known_as() {
465 - $also_known_as = array(
466 - \add_query_arg( 'author', $this->_id, \home_url( '/' ) ),
467 - $this->get_url(),
468 - $this->get_alternate_url(),
469 - );
470 -
471 - $also_known_as = array_merge( $also_known_as, \get_user_option( 'activitypub_also_known_as', $this->_id ) ?: array() );
472 -
473 - return array_unique( $also_known_as );
474 - }
475 -
476 - /**
477 - * Returns the movedTo.
478 - *
479 - * @return string The movedTo.
480 - */
481 - public function get_moved_to() {
482 - $moved_to = \get_user_option( 'activitypub_moved_to', $this->_id );
483 -
484 - return $moved_to && $moved_to !== $this->get_id() ? $moved_to : null;
485 423 }
486 424 }