PluginProbe
ActivityPub / 3.2.5
ActivityPub v3.2.5
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 -90 1.0.53.2.5 View file →
@@ -2,12 +2,16 @@
2 2 namespace Activitypub\Model;
3 3
4 4 use WP_Query;
5 5 use WP_Error;
6 +use Activitypub\Migration;
6 7 use Activitypub\Signature;
8 +use Activitypub\Model\Blog;
9 +use Activitypub\Activity\Actor;
7 10 use Activitypub\Collection\Users;
8 -use Activitypub\Activity\Actor;
11 +use Activitypub\Collection\Extra_Fields;
9 12
13 +use function Activitypub\is_blog_public;
10 14 use function Activitypub\is_user_disabled;
11 15 use function Activitypub\get_rest_url_by_path;
12 16
13 17 class User extends Actor {
@@ -18,46 +22,28 @@
18 22 */
19 23 protected $_id; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
20 24
21 25 /**
22 - * The Featured-Tags.
23 - *
24 - * @see https://docs.joinmastodon.org/spec/activitypub/#featuredTags
25 - *
26 - * @var string
27 - */
28 - protected $featured_tags;
29 -
30 - /**
31 26 * The Featured-Posts.
32 27 *
33 28 * @see https://docs.joinmastodon.org/spec/activitypub/#featured
34 29 *
30 + * @context {
31 + * "@id": "http://joinmastodon.org/ns#featured",
32 + * "@type": "@id"
33 + * }
34 + *
35 35 * @var string
36 36 */
37 37 protected $featured;
38 38
39 39 /**
40 - * Moderators endpoint.
41 - *
42 - * @see https://join-lemmy.org/docs/contributors/05-federation.html
43 - *
44 - * @var string
45 - */
46 - protected $moderators;
47 -
48 - /**
49 - * The User-Type
50 - *
51 - * @var string
52 - */
53 - protected $type = 'Person';
54 -
55 - /**
56 40 * If the User is discoverable.
57 41 *
58 42 * @see https://docs.joinmastodon.org/spec/activitypub/#discoverable
59 43 *
44 + * @context http://joinmastodon.org/ns#discoverable
45 + *
60 46 * @var boolean
61 47 */
62 48 protected $discoverable = true;
63 49
@@ -63,8 +49,10 @@
63 49
64 50 /**
65 51 * If the User is indexable.
66 52 *
53 + * @context http://joinmastodon.org/ns#indexable
54 + *
67 55 * @var boolean
68 56 */
69 57 protected $indexable;
70 58
@@ -72,18 +60,13 @@
72 60 * The WebFinger Resource.
73 61 *
74 62 * @var string<url>
75 63 */
76 - protected $resource;
64 + protected $webfinger;
77 65
78 - /**
79 - * Restrict posting to mods
80 - *
81 - * @see https://join-lemmy.org/docs/contributors/05-federation.html
82 - *
83 - * @var boolean
84 - */
85 - protected $posting_restricted_to_mods = null;
66 + public function get_type() {
67 + return 'Person';
68 + }
86 69
87 70 public static function from_wp_user( $user_id ) {
88 71 if ( is_user_disabled( $user_id ) ) {
89 72 return new WP_Error(
@@ -122,9 +105,9 @@
122 105 *
123 106 * @return string The User-Description.
124 107 */
125 108 public function get_summary() {
126 - $description = get_user_meta( $this->_id, 'activitypub_user_description', true );
109 + $description = get_user_option( 'activitypub_description', $this->_id );
127 110 if ( empty( $description ) ) {
128 111 $description = get_user_meta( $this->_id, 'description', true );
129 112 }
130 113 return \wpautop( \wp_kses( $description, 'default' ) );
@@ -143,10 +126,10 @@
143 126 * Returns the User-URL with @-Prefix for the username.
144 127 *
145 128 * @return string The User-URL with @-Prefix for the username.
146 129 */
147 - public function get_at_url() {
148 - return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_username() );
130 + public function get_alternate_url() {
131 + return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() );
149 132 }
150 133
151 134 public function get_preferred_username() {
152 135 return \esc_attr( \get_the_author_meta( 'login', $this->_id ) );
@@ -166,13 +149,23 @@
166 149 );
167 150 }
168 151
169 152 public function get_image() {
170 - if ( \has_header_image() ) {
171 - $image = \esc_url( \get_header_image() );
153 + $header_image = get_user_option( 'activitypub_header_image', $this->_id );
154 + $image_url = null;
155 +
156 + if ( $header_image ) {
157 + $image_url = \wp_get_attachment_url( $header_image );
158 + }
159 +
160 + if ( ! $image_url && \has_header_image() ) {
161 + $image_url = \get_header_image();
162 + }
163 +
164 + if ( $image_url ) {
172 165 return array(
173 166 'type' => 'Image',
174 - 'url' => $image,
167 + 'url' => esc_url( $image_url ),
175 168 );
176 169 }
177 170
178 171 return null;
@@ -195,9 +188,9 @@
195 188 *
196 189 * @return string The Inbox-Endpoint.
197 190 */
198 191 public function get_inbox() {
199 - return get_rest_url_by_path( sprintf( 'users/%d/inbox', $this->get__id() ) );
192 + return get_rest_url_by_path( sprintf( 'actors/%d/inbox', $this->get__id() ) );
200 193 }
201 194
202 195 /**
203 196 * Returns the Outbox-API-Endpoint.
@@ -204,9 +197,9 @@
204 197 *
205 198 * @return string The Outbox-Endpoint.
206 199 */
207 200 public function get_outbox() {
208 - return get_rest_url_by_path( sprintf( 'users/%d/outbox', $this->get__id() ) );
201 + return get_rest_url_by_path( sprintf( 'actors/%d/outbox', $this->get__id() ) );
209 202 }
210 203
211 204 /**
212 205 * Returns the Followers-API-Endpoint.
@@ -213,9 +206,9 @@
213 206 *
214 207 * @return string The Followers-Endpoint.
215 208 */
216 209 public function get_followers() {
217 - return get_rest_url_by_path( sprintf( 'users/%d/followers', $this->get__id() ) );
210 + return get_rest_url_by_path( sprintf( 'actors/%d/followers', $this->get__id() ) );
218 211 }
219 212
220 213 /**
221 214 * Returns the Following-API-Endpoint.
@@ -222,9 +215,9 @@
222 215 *
223 216 * @return string The Following-Endpoint.
224 217 */
225 218 public function get_following() {
226 - return get_rest_url_by_path( sprintf( 'users/%d/following', $this->get__id() ) );
219 + return get_rest_url_by_path( sprintf( 'actors/%d/following', $this->get__id() ) );
227 220 }
228 221
229 222 /**
230 223 * Returns the Featured-API-Endpoint.
@@ -231,18 +224,21 @@
231 224 *
232 225 * @return string The Featured-Endpoint.
233 226 */
234 227 public function get_featured() {
235 - return get_rest_url_by_path( sprintf( 'users/%d/collections/featured', $this->get__id() ) );
228 + return get_rest_url_by_path( sprintf( 'actors/%d/collections/featured', $this->get__id() ) );
236 229 }
237 230
238 - /**
239 - * Returns the Featured-Tags-API-Endpoint.
240 - *
241 - * @return string The Featured-Tags-Endpoint.
242 - */
243 - public function get_featured_tags() {
244 - return get_rest_url_by_path( sprintf( 'users/%d/collections/tags', $this->get__id() ) );
231 + public function get_endpoints() {
232 + $endpoints = null;
233 +
234 + if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) {
235 + $endpoints = array(
236 + 'sharedInbox' => get_rest_url_by_path( 'inbox' ),
237 + );
238 + }
239 +
240 + return $endpoints;
245 241 }
246 242
247 243 /**
248 244 * Extend the User-Output with Attachments.
@@ -249,43 +245,10 @@
249 245 *
250 246 * @return array The extended User-Output.
251 247 */
252 248 public function get_attachment() {
253 - $array = array();
254 -
255 - $array[] = array(
256 - 'type' => 'PropertyValue',
257 - 'name' => \__( 'Blog', 'activitypub' ),
258 - 'value' => \html_entity_decode(
259 - '<a rel="me" title="' . \esc_attr( \home_url( '/' ) ) . '" target="_blank" href="' . \home_url( '/' ) . '">' . \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) . '</a>',
260 - \ENT_QUOTES,
261 - 'UTF-8'
262 - ),
263 - );
264 -
265 - $array[] = array(
266 - 'type' => 'PropertyValue',
267 - 'name' => \__( 'Profile', 'activitypub' ),
268 - 'value' => \html_entity_decode(
269 - '<a rel="me" title="' . \esc_attr( \get_author_posts_url( $this->get__id() ) ) . '" target="_blank" href="' . \get_author_posts_url( $this->get__id() ) . '">' . \wp_parse_url( \get_author_posts_url( $this->get__id() ), \PHP_URL_HOST ) . '</a>',
270 - \ENT_QUOTES,
271 - 'UTF-8'
272 - ),
273 - );
274 -
275 - if ( \get_the_author_meta( 'user_url', $this->get__id() ) ) {
276 - $array[] = array(
277 - 'type' => 'PropertyValue',
278 - 'name' => \__( 'Website', 'activitypub' ),
279 - 'value' => \html_entity_decode(
280 - '<a rel="me" title="' . \esc_attr( \get_the_author_meta( 'user_url', $this->get__id() ) ) . '" target="_blank" href="' . \get_the_author_meta( 'user_url', $this->get__id() ) . '">' . \wp_parse_url( \get_the_author_meta( 'user_url', $this->get__id() ), \PHP_URL_HOST ) . '</a>',
281 - \ENT_QUOTES,
282 - 'UTF-8'
283 - ),
284 - );
285 - }
286 -
287 - return $array;
249 + $extra_fields = Extra_Fields::get_actor_fields( $this->_id );
250 + return Extra_Fields::fields_to_attachments( $extra_fields );
288 251 }
289 252
290 253 /**
291 254 * Returns a user@domain type of identifier for the user.
@@ -291,9 +254,9 @@
291 254 * Returns a user@domain type of identifier for the user.
292 255 *
293 256 * @return string The Webfinger-Identifier.
294 257 */
295 - public function get_resource() {
258 + public function get_webfinger() {
296 259 return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST );
297 260 }
298 261
299 262 public function get_canonical_url() {
@@ -308,9 +271,9 @@
308 271 return array();
309 272 }
310 273
311 274 public function get_indexable() {
312 - if ( \get_option( 'blog_public', 1 ) ) {
275 + if ( is_blog_public() ) {
313 276 return true;
314 277 } else {
315 278 return false;
316 279 }