8
8
namespace Activitypub ;
9
9
10
10
use Exception ;
11
+ use Activitypub \Collection \Actors ;
11
12
use Activitypub \Collection \Outbox ;
12
13
use Activitypub \Collection \Followers ;
13
14
use Activitypub \Collection \Extra_Fields ;
@@ -43,22 +44,17 @@ public static function init() {
43
44
44
45
\add_action ( 'user_register ' , array ( self ::class, 'user_register ' ) );
45
46
46
- \add_action ( 'in_plugin_update_message- ' . ACTIVITYPUB_PLUGIN_BASENAME , array ( self ::class, 'plugin_update_message ' ) );
47
-
48
- if ( site_supports_blocks () ) {
49
- \add_action ( 'tool_box ' , array ( self ::class, 'tool_box ' ) );
50
- Embed::init ();
51
- }
52
-
53
47
\add_filter ( 'activitypub_get_actor_extra_fields ' , array ( Extra_Fields::class, 'default_actor_extra_fields ' ), 10 , 2 );
54
48
55
49
\add_action ( 'updated_postmeta ' , array ( self ::class, 'updated_postmeta ' ), 10 , 4 );
56
50
\add_action ( 'added_post_meta ' , array ( self ::class, 'updated_postmeta ' ), 10 , 4 );
51
+ \add_action ( 'init ' , array ( self ::class, 'register_user_meta ' ), 11 );
57
52
58
53
// Register several post_types.
59
54
self ::register_post_types ();
60
55
61
56
self ::register_oembed_providers ();
57
+ Embed::init ();
62
58
}
63
59
64
60
/**
@@ -97,6 +93,8 @@ public static function uninstall() {
97
93
delete_option ( 'activitypub_authorized_fetch ' );
98
94
delete_option ( 'activitypub_application_user_private_key ' );
99
95
delete_option ( 'activitypub_application_user_public_key ' );
96
+ delete_option ( 'activitypub_blog_user_also_known_as ' );
97
+ delete_option ( 'activitypub_blog_user_moved_to ' );
100
98
delete_option ( 'activitypub_blog_user_private_key ' );
101
99
delete_option ( 'activitypub_blog_user_public_key ' );
102
100
delete_option ( 'activitypub_blog_description ' );
@@ -257,29 +255,50 @@ public static function redirect_canonical( $redirect_url, $requested_url ) {
257
255
* @return void
258
256
*/
259
257
public static function template_redirect () {
258
+ global $ wp_query ;
259
+
260
260
$ comment_id = get_query_var ( 'c ' , null );
261
261
262
262
// Check if it seems to be a comment.
263
- if ( ! $ comment_id ) {
264
- return ;
265
- }
263
+ if ( $ comment_id ) {
264
+ $ comment = get_comment ( $ comment_id );
266
265
267
- $ comment = get_comment ( $ comment_id );
266
+ // Load a 404-page if `c` is set but not valid.
267
+ if ( ! $ comment ) {
268
+ $ wp_query ->set_404 ();
269
+ return ;
270
+ }
268
271
269
- // Load a 404-page if `c` is set but not valid.
270
- if ( ! $ comment ) {
271
- global $ wp_query ;
272
- $ wp_query ->set_404 ();
273
- return ;
274
- }
272
+ // Stop if it's not an ActivityPub comment.
273
+ if ( is_activitypub_request () && ! is_local_comment ( $ comment ) ) {
274
+ return ;
275
+ }
275
276
276
- // Stop if it's not an ActivityPub comment.
277
- if ( is_activitypub_request () && ! is_local_comment ( $ comment ) ) {
278
- return ;
277
+ wp_safe_redirect ( get_comment_link ( $ comment ) );
278
+ exit ;
279
279
}
280
280
281
- wp_safe_redirect ( get_comment_link ( $ comment ) );
282
- exit ;
281
+ $ actor = get_query_var ( 'actor ' , null );
282
+ if ( $ actor ) {
283
+ $ actor = Actors::get_by_username ( $ actor );
284
+ if ( ! $ actor || \is_wp_error ( $ actor ) ) {
285
+ $ wp_query ->set_404 ();
286
+ return ;
287
+ }
288
+
289
+ if ( is_activitypub_request () ) {
290
+ return ;
291
+ }
292
+
293
+ if ( $ actor ->get__id () > 0 ) {
294
+ $ redirect_url = $ actor ->get_url ();
295
+ } else {
296
+ $ redirect_url = get_bloginfo ( 'url ' );
297
+ }
298
+
299
+ wp_safe_redirect ( $ redirect_url , 301 );
300
+ exit ;
301
+ }
283
302
}
284
303
285
304
/**
@@ -293,6 +312,7 @@ public static function add_query_vars( $vars ) {
293
312
$ vars [] = 'activitypub ' ;
294
313
$ vars [] = 'preview ' ;
295
314
$ vars [] = 'author ' ;
315
+ $ vars [] = 'actor ' ;
296
316
$ vars [] = 'c ' ;
297
317
$ vars [] = 'p ' ;
298
318
@@ -414,12 +434,7 @@ public static function add_rewrite_rules() {
414
434
);
415
435
}
416
436
417
- \add_rewrite_rule (
418
- '^@([\w\-\.]+)$ ' ,
419
- 'index.php?rest_route=/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/$matches[1] ' ,
420
- 'top '
421
- );
422
-
437
+ \add_rewrite_rule ( '^@([\w\-\.]+)\/?$ ' , 'index.php?actor=$matches[1] ' , 'top ' );
423
438
\add_rewrite_endpoint ( 'activitypub ' , EP_AUTHORS | EP_PERMALINK | EP_PAGES );
424
439
}
425
440
@@ -431,15 +446,6 @@ public static function flush_rewrite_rules() {
431
446
\flush_rewrite_rules ();
432
447
}
433
448
434
- /**
435
- * Adds metabox on wp-admin/tools.php.
436
- */
437
- public static function tool_box () {
438
- if ( \current_user_can ( 'edit_posts ' ) ) {
439
- \load_template ( ACTIVITYPUB_PLUGIN_DIR . 'templates/toolbox.php ' );
440
- }
441
- }
442
-
443
449
/**
444
450
* Theme compatibility stuff.
445
451
*/
@@ -462,30 +468,6 @@ public static function theme_compat() {
462
468
}
463
469
}
464
470
465
- /**
466
- * Display plugin upgrade notice to users.
467
- *
468
- * @param array $data The plugin data.
469
- */
470
- public static function plugin_update_message ( $ data ) {
471
- if ( ! isset ( $ data ['upgrade_notice ' ] ) ) {
472
- return ;
473
- }
474
-
475
- printf (
476
- '<div class="update-message">%s</div> ' ,
477
- wp_kses (
478
- wpautop ( $ data ['upgrade_notice ' ] ),
479
- array (
480
- 'p ' => array (),
481
- 'a ' => array ( 'href ' , 'title ' ),
482
- 'strong ' => array (),
483
- 'em ' => array (),
484
- )
485
- )
486
- );
487
- }
488
-
489
471
/**
490
472
* Register Custom Post Types.
491
473
*/
@@ -753,4 +735,61 @@ public static function register_oembed_providers() {
753
735
\wp_oembed_add_provider ( '#https?://mastodon\.world/(@.+)/([0-9]+)#i ' , 'https://mastodon.world/api/oembed ' , true );
754
736
\wp_oembed_add_provider ( '#https?://mas\.to/(@.+)/([0-9]+)#i ' , 'https://mas.to/api/oembed ' , true );
755
737
}
738
+
739
+ /**
740
+ * Register user meta.
741
+ */
742
+ public static function register_user_meta () {
743
+ $ blog_prefix = $ GLOBALS ['wpdb ' ]->get_blog_prefix ();
744
+
745
+ \register_meta (
746
+ 'user ' ,
747
+ $ blog_prefix . 'activitypub_also_known_as ' ,
748
+ array (
749
+ 'type ' => 'array ' ,
750
+ 'description ' => 'An array of URLs that the user is known by. ' ,
751
+ 'single ' => true ,
752
+ 'default ' => array (),
753
+ 'sanitize_callback ' => array ( Sanitize::class, 'url_list ' ),
754
+ )
755
+ );
756
+
757
+ \register_meta (
758
+ 'user ' ,
759
+ $ blog_prefix . 'activitypub_description ' ,
760
+ array (
761
+ 'type ' => 'string ' ,
762
+ 'description ' => 'The user’s description. ' ,
763
+ 'single ' => true ,
764
+ 'default ' => '' ,
765
+ 'sanitize_callback ' => function ( $ value ) {
766
+ return wp_kses ( $ value , 'user_description ' );
767
+ },
768
+ )
769
+ );
770
+
771
+ \register_meta (
772
+ 'user ' ,
773
+ $ blog_prefix . 'activitypub_icon ' ,
774
+ array (
775
+ 'type ' => 'integer ' ,
776
+ 'description ' => 'The attachment ID for user’s profile image. ' ,
777
+ 'single ' => true ,
778
+ 'default ' => 0 ,
779
+ 'sanitize_callback ' => 'absint ' ,
780
+ )
781
+ );
782
+
783
+ \register_meta (
784
+ 'user ' ,
785
+ $ blog_prefix . 'activitypub_header_image ' ,
786
+ array (
787
+ 'type ' => 'integer ' ,
788
+ 'description ' => 'The attachment ID for the user’s header image. ' ,
789
+ 'single ' => true ,
790
+ 'default ' => 0 ,
791
+ 'sanitize_callback ' => 'absint ' ,
792
+ )
793
+ );
794
+ }
756
795
}
0 commit comments