| @@ -2,14 +2,17 @@ | ||
| 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; | |
| 9 | 11 | |
| 10 | 12 | use function Activitypub\is_user_disabled; |
| 11 | 13 | use function Activitypub\get_rest_url_by_path; |
| 14 | +use function Activitypub\get_actor_extra_fields; | |
| 12 | 15 | |
| 13 | 16 | class User extends Actor { |
| 14 | 17 | /** |
| 15 | 18 | * The local User-ID (WP_User). |
| @@ -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( |
| @@ -192,9 +177,9 @@ | ||
| 192 | 177 | * |
| 193 | 178 | * @return string The Inbox-Endpoint. |
| 194 | 179 | */ |
| 195 | 180 | public function get_inbox() { |
| 196 | - return get_rest_url_by_path( sprintf( 'users/%d/inbox', $this->get__id() ) ); | |
| 181 | + return get_rest_url_by_path( sprintf( 'actors/%d/inbox', $this->get__id() ) ); | |
| 197 | 182 | } |
| 198 | 183 | |
| 199 | 184 | /** |
| 200 | 185 | * Returns the Outbox-API-Endpoint. |
| @@ -201,9 +186,9 @@ | ||
| 201 | 186 | * |
| 202 | 187 | * @return string The Outbox-Endpoint. |
| 203 | 188 | */ |
| 204 | 189 | public function get_outbox() { |
| 205 | - return get_rest_url_by_path( sprintf( 'users/%d/outbox', $this->get__id() ) ); | |
| 190 | + return get_rest_url_by_path( sprintf( 'actors/%d/outbox', $this->get__id() ) ); | |
| 206 | 191 | } |
| 207 | 192 | |
| 208 | 193 | /** |
| 209 | 194 | * Returns the Followers-API-Endpoint. |
| @@ -210,9 +195,9 @@ | ||
| 210 | 195 | * |
| 211 | 196 | * @return string The Followers-Endpoint. |
| 212 | 197 | */ |
| 213 | 198 | public function get_followers() { |
| 214 | - return get_rest_url_by_path( sprintf( 'users/%d/followers', $this->get__id() ) ); | |
| 199 | + return get_rest_url_by_path( sprintf( 'actors/%d/followers', $this->get__id() ) ); | |
| 215 | 200 | } |
| 216 | 201 | |
| 217 | 202 | /** |
| 218 | 203 | * Returns the Following-API-Endpoint. |
| @@ -219,9 +204,9 @@ | ||
| 219 | 204 | * |
| 220 | 205 | * @return string The Following-Endpoint. |
| 221 | 206 | */ |
| 222 | 207 | public function get_following() { |
| 223 | - return get_rest_url_by_path( sprintf( 'users/%d/following', $this->get__id() ) ); | |
| 208 | + return get_rest_url_by_path( sprintf( 'actors/%d/following', $this->get__id() ) ); | |
| 224 | 209 | } |
| 225 | 210 | |
| 226 | 211 | /** |
| 227 | 212 | * Returns the Featured-API-Endpoint. |
| @@ -228,9 +213,9 @@ | ||
| 228 | 213 | * |
| 229 | 214 | * @return string The Featured-Endpoint. |
| 230 | 215 | */ |
| 231 | 216 | public function get_featured() { |
| 232 | - return get_rest_url_by_path( sprintf( 'users/%d/collections/featured', $this->get__id() ) ); | |
| 217 | + return get_rest_url_by_path( sprintf( 'actors/%d/collections/featured', $this->get__id() ) ); | |
| 233 | 218 | } |
| 234 | 219 | |
| 235 | 220 | public function get_endpoints() { |
| 236 | 221 | $endpoints = null; |
| @@ -249,43 +234,76 @@ | ||
| 249 | 234 | * |
| 250 | 235 | * @return array The extended User-Output. |
| 251 | 236 | */ |
| 252 | 237 | public function get_attachment() { |
| 253 | - $array = array(); | |
| 238 | + $extra_fields = get_actor_extra_fields( \get_current_user_id() ); | |
| 254 | 239 | |
| 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 | - ); | |
| 240 | + $attachments = array(); | |
| 264 | 241 | |
| 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 | - ); | |
| 242 | + foreach ( $extra_fields as $post ) { | |
| 243 | + $content = \get_the_content( null, false, $post ); | |
| 244 | + $content = \make_clickable( $content ); | |
| 245 | + $content = \do_blocks( $content ); | |
| 246 | + $content = \wptexturize( $content ); | |
| 247 | + $content = \wp_filter_content_tags( $content ); | |
| 248 | + // replace script and style elements | |
| 249 | + $content = \preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $content ); | |
| 250 | + $content = \strip_shortcodes( $content ); | |
| 251 | + $content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) ); | |
| 274 | 252 | |
| 275 | - if ( \get_the_author_meta( 'user_url', $this->get__id() ) ) { | |
| 276 | - $array[] = array( | |
| 253 | + $attachments[] = array( | |
| 277 | 254 | 'type' => 'PropertyValue', |
| 278 | - 'name' => \__( 'Website', 'activitypub' ), | |
| 255 | + 'name' => \get_the_title( $post ), | |
| 279 | 256 | '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>', | |
| 257 | + $content, | |
| 281 | 258 | \ENT_QUOTES, |
| 282 | 259 | 'UTF-8' |
| 283 | 260 | ), |
| 284 | 261 | ); |
| 262 | + | |
| 263 | + $link_added = false; | |
| 264 | + | |
| 265 | + // Add support for FEP-fb2a, for more information see FEDERATION.md | |
| 266 | + if ( \class_exists( '\WP_HTML_Tag_Processor' ) ) { | |
| 267 | + $tags = new \WP_HTML_Tag_Processor( $content ); | |
| 268 | + $tags->next_tag(); | |
| 269 | + | |
| 270 | + if ( 'P' === $tags->get_tag() ) { | |
| 271 | + $tags->next_tag(); | |
| 272 | + } | |
| 273 | + | |
| 274 | + if ( 'A' === $tags->get_tag() ) { | |
| 275 | + $tags->set_bookmark( 'link' ); | |
| 276 | + if ( ! $tags->next_tag() ) { | |
| 277 | + $tags->seek( 'link' ); | |
| 278 | + $attachment = array( | |
| 279 | + 'type' => 'Link', | |
| 280 | + 'name' => \get_the_title( $post ), | |
| 281 | + 'href' => \esc_url( $tags->get_attribute( 'href' ) ), | |
| 282 | + 'rel' => explode( ' ', $tags->get_attribute( 'rel' ) ), | |
| 283 | + ); | |
| 284 | + | |
| 285 | + $link_added = true; | |
| 286 | + } | |
| 287 | + } | |
| 288 | + } | |
| 289 | + | |
| 290 | + if ( ! $link_added ) { | |
| 291 | + $attachment = array( | |
| 292 | + 'type' => 'Note', | |
| 293 | + 'name' => \get_the_title( $post ), | |
| 294 | + 'content' => \html_entity_decode( | |
| 295 | + $content, | |
| 296 | + \ENT_QUOTES, | |
| 297 | + 'UTF-8' | |
| 298 | + ), | |
| 299 | + ); | |
| 300 | + } | |
| 301 | + | |
| 302 | + $attachments[] = $attachment; | |
| 285 | 303 | } |
| 286 | 304 | |
| 287 | - return $array; | |
| 305 | + return $attachments; | |
| 288 | 306 | } |
| 289 | 307 | |
| 290 | 308 | /** |
| 291 | 309 | * Returns a user@domain type of identifier for the user. |
| @@ -293,12 +311,8 @@ | ||
| 293 | 311 | * @return string The Webfinger-Identifier. |
| 294 | 312 | */ |
| 295 | 313 | public function get_webfinger() { |
| 296 | 314 | 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 | 315 | } |
| 302 | 316 | |
| 303 | 317 | public function get_canonical_url() { |
| 304 | 318 | return $this->get_url(); |