| @@ -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 | |
| @@ -32,21 +35,8 @@ | ||
| 32 | 35 | */ |
| 33 | 36 | protected $featured; |
| 34 | 37 | |
| 35 | 38 | /** |
| 36 | - * Moderators endpoint. | |
| 37 | - * | |
| 38 | - * @see https://join-lemmy.org/docs/contributors/05-federation.html | |
| 39 | - * | |
| 40 | - * @var string | |
| 41 | - */ | |
| 42 | - protected $moderators; | |
| 43 | - | |
| 44 | - public function get_type() { | |
| 45 | - return 'Person'; | |
| 46 | - } | |
| 47 | - | |
| 48 | - /** | |
| 49 | 39 | * If the User is discoverable. |
| 50 | 40 | * |
| 51 | 41 | * @see https://docs.joinmastodon.org/spec/activitypub/#discoverable |
| 52 | 42 | * |
| @@ -71,16 +61,11 @@ | ||
| 71 | 61 | * @var string<url> |
| 72 | 62 | */ |
| 73 | 63 | protected $webfinger; |
| 74 | 64 | |
| 75 | - /** | |
| 76 | - * Restrict posting to mods | |
| 77 | - * | |
| 78 | - * @see https://join-lemmy.org/docs/contributors/05-federation.html | |
| 79 | - * | |
| 80 | - * @var boolean | |
| 81 | - */ | |
| 82 | - protected $posting_restricted_to_mods = null; | |
| 65 | + public function get_type() { | |
| 66 | + return 'Person'; | |
| 67 | + } | |
| 83 | 68 | |
| 84 | 69 | public static function from_wp_user( $user_id ) { |
| 85 | 70 | if ( is_user_disabled( $user_id ) ) { |
| 86 | 71 | return new WP_Error( |
| @@ -119,9 +104,9 @@ | ||
| 119 | 104 | * |
| 120 | 105 | * @return string The User-Description. |
| 121 | 106 | */ |
| 122 | 107 | public function get_summary() { |
| 123 | - $description = get_user_meta( $this->_id, 'activitypub_user_description', true ); | |
| 108 | + $description = get_user_option( 'activitypub_description', $this->_id ); | |
| 124 | 109 | if ( empty( $description ) ) { |
| 125 | 110 | $description = get_user_meta( $this->_id, 'description', true ); |
| 126 | 111 | } |
| 127 | 112 | return \wpautop( \wp_kses( $description, 'default' ) ); |
| @@ -163,13 +148,23 @@ | ||
| 163 | 148 | ); |
| 164 | 149 | } |
| 165 | 150 | |
| 166 | 151 | public function get_image() { |
| 167 | - if ( \has_header_image() ) { | |
| 168 | - $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 ) { | |
| 169 | 164 | return array( |
| 170 | 165 | 'type' => 'Image', |
| 171 | - 'url' => $image, | |
| 166 | + 'url' => esc_url( $image_url ), | |
| 172 | 167 | ); |
| 173 | 168 | } |
| 174 | 169 | |
| 175 | 170 | return null; |
| @@ -192,9 +187,9 @@ | ||
| 192 | 187 | * |
| 193 | 188 | * @return string The Inbox-Endpoint. |
| 194 | 189 | */ |
| 195 | 190 | public function get_inbox() { |
| 196 | - 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() ) ); | |
| 197 | 192 | } |
| 198 | 193 | |
| 199 | 194 | /** |
| 200 | 195 | * Returns the Outbox-API-Endpoint. |
| @@ -201,9 +196,9 @@ | ||
| 201 | 196 | * |
| 202 | 197 | * @return string The Outbox-Endpoint. |
| 203 | 198 | */ |
| 204 | 199 | public function get_outbox() { |
| 205 | - 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() ) ); | |
| 206 | 201 | } |
| 207 | 202 | |
| 208 | 203 | /** |
| 209 | 204 | * Returns the Followers-API-Endpoint. |
| @@ -210,9 +205,9 @@ | ||
| 210 | 205 | * |
| 211 | 206 | * @return string The Followers-Endpoint. |
| 212 | 207 | */ |
| 213 | 208 | public function get_followers() { |
| 214 | - 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() ) ); | |
| 215 | 210 | } |
| 216 | 211 | |
| 217 | 212 | /** |
| 218 | 213 | * Returns the Following-API-Endpoint. |
| @@ -219,9 +214,9 @@ | ||
| 219 | 214 | * |
| 220 | 215 | * @return string The Following-Endpoint. |
| 221 | 216 | */ |
| 222 | 217 | public function get_following() { |
| 223 | - 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() ) ); | |
| 224 | 219 | } |
| 225 | 220 | |
| 226 | 221 | /** |
| 227 | 222 | * Returns the Featured-API-Endpoint. |
| @@ -228,9 +223,9 @@ | ||
| 228 | 223 | * |
| 229 | 224 | * @return string The Featured-Endpoint. |
| 230 | 225 | */ |
| 231 | 226 | public function get_featured() { |
| 232 | - 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() ) ); | |
| 233 | 228 | } |
| 234 | 229 | |
| 235 | 230 | public function get_endpoints() { |
| 236 | 231 | $endpoints = null; |
| @@ -249,43 +244,10 @@ | ||
| 249 | 244 | * |
| 250 | 245 | * @return array The extended User-Output. |
| 251 | 246 | */ |
| 252 | 247 | 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; | |
| 248 | + $extra_fields = Extra_Fields::get_actor_fields( $this->_id ); | |
| 249 | + return Extra_Fields::fields_to_attachments( $extra_fields ); | |
| 288 | 250 | } |
| 289 | 251 | |
| 290 | 252 | /** |
| 291 | 253 | * Returns a user@domain type of identifier for the user. |
| @@ -293,12 +255,8 @@ | ||
| 293 | 255 | * @return string The Webfinger-Identifier. |
| 294 | 256 | */ |
| 295 | 257 | public function get_webfinger() { |
| 296 | 258 | return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST ); |
| 297 | - } | |
| 298 | - | |
| 299 | - public function get_resource() { | |
| 300 | - return $this->get_webfinger(); | |
| 301 | 259 | } |
| 302 | 260 | |
| 303 | 261 | public function get_canonical_url() { |
| 304 | 262 | return $this->get_url(); |