| @@ -2,11 +2,14 @@ | ||
| 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 | |
| 10 | 13 | use function Activitypub\is_user_disabled; |
| 11 | 14 | use function Activitypub\get_rest_url_by_path; |
| 12 | 15 | |
| @@ -22,33 +25,24 @@ | ||
| 22 | 25 | * The Featured-Posts. |
| 23 | 26 | * |
| 24 | 27 | * @see https://docs.joinmastodon.org/spec/activitypub/#featured |
| 25 | 28 | * |
| 29 | + * @context { | |
| 30 | + * "@id": "http://joinmastodon.org/ns#featured", | |
| 31 | + * "@type": "@id" | |
| 32 | + * } | |
| 33 | + * | |
| 26 | 34 | * @var string |
| 27 | 35 | */ |
| 28 | 36 | protected $featured; |
| 29 | 37 | |
| 30 | 38 | /** |
| 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 | 39 | * If the User is discoverable. |
| 48 | 40 | * |
| 49 | 41 | * @see https://docs.joinmastodon.org/spec/activitypub/#discoverable |
| 50 | 42 | * |
| 43 | + * @context http://joinmastodon.org/ns#discoverable | |
| 44 | + * | |
| 51 | 45 | * @var boolean |
| 52 | 46 | */ |
| 53 | 47 | protected $discoverable = true; |
| 54 | 48 | |
| @@ -54,8 +48,10 @@ | ||
| 54 | 48 | |
| 55 | 49 | /** |
| 56 | 50 | * If the User is indexable. |
| 57 | 51 | * |
| 52 | + * @context http://joinmastodon.org/ns#indexable | |
| 53 | + * | |
| 58 | 54 | * @var boolean |
| 59 | 55 | */ |
| 60 | 56 | protected $indexable; |
| 61 | 57 | |
| @@ -65,16 +61,11 @@ | ||
| 65 | 61 | * @var string<url> |
| 66 | 62 | */ |
| 67 | 63 | protected $webfinger; |
| 68 | 64 | |
| 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; | |
| 65 | + public function get_type() { | |
| 66 | + return 'Person'; | |
| 67 | + } | |
| 77 | 68 | |
| 78 | 69 | public static function from_wp_user( $user_id ) { |
| 79 | 70 | if ( is_user_disabled( $user_id ) ) { |
| 80 | 71 | return new WP_Error( |
| @@ -113,9 +104,9 @@ | ||
| 113 | 104 | * |
| 114 | 105 | * @return string The User-Description. |
| 115 | 106 | */ |
| 116 | 107 | public function get_summary() { |
| 117 | - $description = get_user_meta( $this->_id, 'activitypub_user_description', true ); | |
| 108 | + $description = get_user_option( 'activitypub_description', $this->_id ); | |
| 118 | 109 | if ( empty( $description ) ) { |
| 119 | 110 | $description = get_user_meta( $this->_id, 'description', true ); |
| 120 | 111 | } |
| 121 | 112 | return \wpautop( \wp_kses( $description, 'default' ) ); |
| @@ -157,13 +148,23 @@ | ||
| 157 | 148 | ); |
| 158 | 149 | } |
| 159 | 150 | |
| 160 | 151 | public function get_image() { |
| 161 | - if ( \has_header_image() ) { | |
| 162 | - $image = \esc_url( \get_header_image() ); | |
| 152 | + $header_image = get_user_option( 'activitypub_header_image', $this->_id ); | |
| 153 | + $image_url = null; | |
| 154 | + | |
| 155 | + if ( $header_image ) { | |
| 156 | + $image_url = \wp_get_attachment_url( $header_image ); | |
| 157 | + } | |
| 158 | + | |
| 159 | + if ( ! $image_url && \has_header_image() ) { | |
| 160 | + $image_url = \get_header_image(); | |
| 161 | + } | |
| 162 | + | |
| 163 | + if ( $image_url ) { | |
| 163 | 164 | return array( |
| 164 | 165 | 'type' => 'Image', |
| 165 | - 'url' => $image, | |
| 166 | + 'url' => esc_url( $image_url ), | |
| 166 | 167 | ); |
| 167 | 168 | } |
| 168 | 169 | |
| 169 | 170 | return null; |
| @@ -186,9 +187,9 @@ | ||
| 186 | 187 | * |
| 187 | 188 | * @return string The Inbox-Endpoint. |
| 188 | 189 | */ |
| 189 | 190 | public function get_inbox() { |
| 190 | - return get_rest_url_by_path( sprintf( 'users/%d/inbox', $this->get__id() ) ); | |
| 191 | + return get_rest_url_by_path( sprintf( 'actors/%d/inbox', $this->get__id() ) ); | |
| 191 | 192 | } |
| 192 | 193 | |
| 193 | 194 | /** |
| 194 | 195 | * Returns the Outbox-API-Endpoint. |
| @@ -195,9 +196,9 @@ | ||
| 195 | 196 | * |
| 196 | 197 | * @return string The Outbox-Endpoint. |
| 197 | 198 | */ |
| 198 | 199 | public function get_outbox() { |
| 199 | - return get_rest_url_by_path( sprintf( 'users/%d/outbox', $this->get__id() ) ); | |
| 200 | + return get_rest_url_by_path( sprintf( 'actors/%d/outbox', $this->get__id() ) ); | |
| 200 | 201 | } |
| 201 | 202 | |
| 202 | 203 | /** |
| 203 | 204 | * Returns the Followers-API-Endpoint. |
| @@ -204,9 +205,9 @@ | ||
| 204 | 205 | * |
| 205 | 206 | * @return string The Followers-Endpoint. |
| 206 | 207 | */ |
| 207 | 208 | public function get_followers() { |
| 208 | - return get_rest_url_by_path( sprintf( 'users/%d/followers', $this->get__id() ) ); | |
| 209 | + return get_rest_url_by_path( sprintf( 'actors/%d/followers', $this->get__id() ) ); | |
| 209 | 210 | } |
| 210 | 211 | |
| 211 | 212 | /** |
| 212 | 213 | * Returns the Following-API-Endpoint. |
| @@ -213,9 +214,9 @@ | ||
| 213 | 214 | * |
| 214 | 215 | * @return string The Following-Endpoint. |
| 215 | 216 | */ |
| 216 | 217 | public function get_following() { |
| 217 | - return get_rest_url_by_path( sprintf( 'users/%d/following', $this->get__id() ) ); | |
| 218 | + return get_rest_url_by_path( sprintf( 'actors/%d/following', $this->get__id() ) ); | |
| 218 | 219 | } |
| 219 | 220 | |
| 220 | 221 | /** |
| 221 | 222 | * Returns the Featured-API-Endpoint. |
| @@ -222,9 +223,9 @@ | ||
| 222 | 223 | * |
| 223 | 224 | * @return string The Featured-Endpoint. |
| 224 | 225 | */ |
| 225 | 226 | public function get_featured() { |
| 226 | - return get_rest_url_by_path( sprintf( 'users/%d/collections/featured', $this->get__id() ) ); | |
| 227 | + return get_rest_url_by_path( sprintf( 'actors/%d/collections/featured', $this->get__id() ) ); | |
| 227 | 228 | } |
| 228 | 229 | |
| 229 | 230 | public function get_endpoints() { |
| 230 | 231 | $endpoints = null; |
| @@ -243,43 +244,10 @@ | ||
| 243 | 244 | * |
| 244 | 245 | * @return array The extended User-Output. |
| 245 | 246 | */ |
| 246 | 247 | 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; | |
| 248 | + $extra_fields = Extra_Fields::get_actor_fields( $this->_id ); | |
| 249 | + return Extra_Fields::fields_to_attachments( $extra_fields ); | |
| 282 | 250 | } |
| 283 | 251 | |
| 284 | 252 | /** |
| 285 | 253 | * Returns a user@domain type of identifier for the user. |
| @@ -287,12 +255,8 @@ | ||
| 287 | 255 | * @return string The Webfinger-Identifier. |
| 288 | 256 | */ |
| 289 | 257 | public function get_webfinger() { |
| 290 | 258 | return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST ); |
| 291 | - } | |
| 292 | - | |
| 293 | - public function get_resource() { | |
| 294 | - return $this->get_webfinger(); | |
| 295 | 259 | } |
| 296 | 260 | |
| 297 | 261 | public function get_canonical_url() { |
| 298 | 262 | return $this->get_url(); |