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 +55 -74 1.3.03.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 {
@@ -22,33 +26,24 @@
22 26 * The Featured-Posts.
23 27 *
24 28 * @see https://docs.joinmastodon.org/spec/activitypub/#featured
25 29 *
30 + * @context {
31 + * "@id": "http://joinmastodon.org/ns#featured",
32 + * "@type": "@id"
33 + * }
34 + *
26 35 * @var string
27 36 */
28 37 protected $featured;
29 38
30 39 /**
31 - * Moderators endpoint.
32 - *
33 - * @see https://join-lemmy.org/docs/contributors/05-federation.html
34 - *
35 - * @var string
36 - */
37 - protected $moderators;
38 -
39 - /**
40 - * The User-Type
41 - *
42 - * @var string
43 - */
44 - protected $type = 'Person';
45 -
46 - /**
47 40 * If the User is discoverable.
48 41 *
49 42 * @see https://docs.joinmastodon.org/spec/activitypub/#discoverable
50 43 *
44 + * @context http://joinmastodon.org/ns#discoverable
45 + *
51 46 * @var boolean
52 47 */
53 48 protected $discoverable = true;
54 49
@@ -54,8 +49,10 @@
54 49
55 50 /**
56 51 * If the User is indexable.
57 52 *
53 + * @context http://joinmastodon.org/ns#indexable
54 + *
58 55 * @var boolean
59 56 */
60 57 protected $indexable;
61 58
@@ -63,18 +60,13 @@
63 60 * The WebFinger Resource.
64 61 *
65 62 * @var string<url>
66 63 */
67 - protected $resource;
64 + protected $webfinger;
68 65
69 - /**
70 - * Restrict posting to mods
71 - *
72 - * @see https://join-lemmy.org/docs/contributors/05-federation.html
73 - *
74 - * @var boolean
75 - */
76 - protected $posting_restricted_to_mods = null;
66 + public function get_type() {
67 + return 'Person';
68 + }
77 69
78 70 public static function from_wp_user( $user_id ) {
79 71 if ( is_user_disabled( $user_id ) ) {
80 72 return new WP_Error(
@@ -113,9 +105,9 @@
113 105 *
114 106 * @return string The User-Description.
115 107 */
116 108 public function get_summary() {
117 - $description = get_user_meta( $this->_id, 'activitypub_user_description', true );
109 + $description = get_user_option( 'activitypub_description', $this->_id );
118 110 if ( empty( $description ) ) {
119 111 $description = get_user_meta( $this->_id, 'description', true );
120 112 }
121 113 return \wpautop( \wp_kses( $description, 'default' ) );
@@ -134,10 +126,10 @@
134 126 * Returns the User-URL with @-Prefix for the username.
135 127 *
136 128 * @return string The User-URL with @-Prefix for the username.
137 129 */
138 - public function get_at_url() {
139 - 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() );
140 132 }
141 133
142 134 public function get_preferred_username() {
143 135 return \esc_attr( \get_the_author_meta( 'login', $this->_id ) );
@@ -157,13 +149,23 @@
157 149 );
158 150 }
159 151
160 152 public function get_image() {
161 - if ( \has_header_image() ) {
162 - $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 ) {
163 165 return array(
164 166 'type' => 'Image',
165 - 'url' => $image,
167 + 'url' => esc_url( $image_url ),
166 168 );
167 169 }
168 170
169 171 return null;
@@ -186,9 +188,9 @@
186 188 *
187 189 * @return string The Inbox-Endpoint.
188 190 */
189 191 public function get_inbox() {
190 - 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() ) );
191 193 }
192 194
193 195 /**
194 196 * Returns the Outbox-API-Endpoint.
@@ -195,9 +197,9 @@
195 197 *
196 198 * @return string The Outbox-Endpoint.
197 199 */
198 200 public function get_outbox() {
199 - 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() ) );
200 202 }
201 203
202 204 /**
203 205 * Returns the Followers-API-Endpoint.
@@ -204,9 +206,9 @@
204 206 *
205 207 * @return string The Followers-Endpoint.
206 208 */
207 209 public function get_followers() {
208 - 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() ) );
209 211 }
210 212
211 213 /**
212 214 * Returns the Following-API-Endpoint.
@@ -213,9 +215,9 @@
213 215 *
214 216 * @return string The Following-Endpoint.
215 217 */
216 218 public function get_following() {
217 - 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() ) );
218 220 }
219 221
220 222 /**
221 223 * Returns the Featured-API-Endpoint.
@@ -222,11 +224,23 @@
222 224 *
223 225 * @return string The Featured-Endpoint.
224 226 */
225 227 public function get_featured() {
226 - 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() ) );
227 229 }
228 230
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;
241 + }
242 +
229 243 /**
230 244 * Extend the User-Output with Attachments.
231 245 *
232 246 * @return array The extended User-Output.
@@ -231,43 +245,10 @@
231 245 *
232 246 * @return array The extended User-Output.
233 247 */
234 248 public function get_attachment() {
235 - $array = array();
236 -
237 - $array[] = array(
238 - 'type' => 'PropertyValue',
239 - 'name' => \__( 'Blog', 'activitypub' ),
240 - 'value' => \html_entity_decode(
241 - '<a rel="me" title="' . \esc_attr( \home_url( '/' ) ) . '" target="_blank" href="' . \home_url( '/' ) . '">' . \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) . '</a>',
242 - \ENT_QUOTES,
243 - 'UTF-8'
244 - ),
245 - );
246 -
247 - $array[] = array(
248 - 'type' => 'PropertyValue',
249 - 'name' => \__( 'Profile', 'activitypub' ),
250 - 'value' => \html_entity_decode(
251 - '<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>',
252 - \ENT_QUOTES,
253 - 'UTF-8'
254 - ),
255 - );
256 -
257 - if ( \get_the_author_meta( 'user_url', $this->get__id() ) ) {
258 - $array[] = array(
259 - 'type' => 'PropertyValue',
260 - 'name' => \__( 'Website', 'activitypub' ),
261 - 'value' => \html_entity_decode(
262 - '<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>',
263 - \ENT_QUOTES,
264 - 'UTF-8'
265 - ),
266 - );
267 - }
268 -
269 - return $array;
249 + $extra_fields = Extra_Fields::get_actor_fields( $this->_id );
250 + return Extra_Fields::fields_to_attachments( $extra_fields );
270 251 }
271 252
272 253 /**
273 254 * Returns a user@domain type of identifier for the user.
@@ -273,9 +254,9 @@
273 254 * Returns a user@domain type of identifier for the user.
274 255 *
275 256 * @return string The Webfinger-Identifier.
276 257 */
277 - public function get_resource() {
258 + public function get_webfinger() {
278 259 return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST );
279 260 }
280 261
281 262 public function get_canonical_url() {
@@ -290,9 +271,9 @@
290 271 return array();
291 272 }
292 273
293 274 public function get_indexable() {
294 - if ( \get_option( 'blog_public', 1 ) ) {
275 + if ( is_blog_public() ) {
295 276 return true;
296 277 } else {
297 278 return false;
298 279 }