| @@ -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 | |
| @@ -65,16 +62,11 @@ | ||
| 65 | 62 | * @var string<url> |
| 66 | 63 | */ |
| 67 | 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' ) ); |
| @@ -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,9 +224,9 @@ | ||
| 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 | |
| 229 | 231 | public function get_endpoints() { |
| 230 | 232 | $endpoints = null; |
| @@ -243,43 +245,10 @@ | ||
| 243 | 245 | * |
| 244 | 246 | * @return array The extended User-Output. |
| 245 | 247 | */ |
| 246 | 248 | public function get_attachment() { |
| 247 | - $array = array(); | |
| 248 | - | |
| 249 | - $array[] = array( | |
| 250 | - 'type' => 'PropertyValue', | |
| 251 | - 'name' => \__( 'Blog', 'activitypub' ), | |
| 252 | - 'value' => \html_entity_decode( | |
| 253 | - '<a rel="me" title="' . \esc_attr( \home_url( '/' ) ) . '" target="_blank" href="' . \home_url( '/' ) . '">' . \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) . '</a>', | |
| 254 | - \ENT_QUOTES, | |
| 255 | - 'UTF-8' | |
| 256 | - ), | |
| 257 | - ); | |
| 258 | - | |
| 259 | - $array[] = array( | |
| 260 | - 'type' => 'PropertyValue', | |
| 261 | - 'name' => \__( 'Profile', 'activitypub' ), | |
| 262 | - 'value' => \html_entity_decode( | |
| 263 | - '<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>', | |
| 264 | - \ENT_QUOTES, | |
| 265 | - 'UTF-8' | |
| 266 | - ), | |
| 267 | - ); | |
| 268 | - | |
| 269 | - if ( \get_the_author_meta( 'user_url', $this->get__id() ) ) { | |
| 270 | - $array[] = array( | |
| 271 | - 'type' => 'PropertyValue', | |
| 272 | - 'name' => \__( 'Website', 'activitypub' ), | |
| 273 | - 'value' => \html_entity_decode( | |
| 274 | - '<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>', | |
| 275 | - \ENT_QUOTES, | |
| 276 | - 'UTF-8' | |
| 277 | - ), | |
| 278 | - ); | |
| 279 | - } | |
| 280 | - | |
| 281 | - return $array; | |
| 249 | + $extra_fields = Extra_Fields::get_actor_fields( $this->_id ); | |
| 250 | + return Extra_Fields::fields_to_attachments( $extra_fields ); | |
| 282 | 251 | } |
| 283 | 252 | |
| 284 | 253 | /** |
| 285 | 254 | * Returns a user@domain type of identifier for the user. |
| @@ -289,12 +258,8 @@ | ||
| 289 | 258 | public function get_webfinger() { |
| 290 | 259 | return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST ); |
| 291 | 260 | } |
| 292 | 261 | |
| 293 | - public function get_resource() { | |
| 294 | - return $this->get_webfinger(); | |
| 295 | - } | |
| 296 | - | |
| 297 | 262 | public function get_canonical_url() { |
| 298 | 263 | return $this->get_url(); |
| 299 | 264 | } |
| 300 | 265 | |
| @@ -306,9 +271,9 @@ | ||
| 306 | 271 | return array(); |
| 307 | 272 | } |
| 308 | 273 | |
| 309 | 274 | public function get_indexable() { |
| 310 | - if ( \get_option( 'blog_public', 1 ) ) { | |
| 275 | + if ( is_blog_public() ) { | |
| 311 | 276 | return true; |
| 312 | 277 | } else { |
| 313 | 278 | return false; |
| 314 | 279 | } |