5
5
* @package Activitypub
6
6
*/
7
7
8
- namespace Activitypub ;
8
+ namespace Activitypub \ WP_Admin ;
9
9
10
+ use Activitypub \Comment ;
10
11
use WP_User_Query ;
11
12
use Activitypub \Model \Blog ;
12
13
use Activitypub \Collection \Actors ;
13
14
use Activitypub \Collection \Extra_Fields ;
15
+ use function Activitypub \count_followers ;
16
+ use function Activitypub \get_content_visibility ;
17
+ use function Activitypub \is_user_disabled ;
18
+ use function Activitypub \is_user_type_disabled ;
19
+ use function Activitypub \site_supports_blocks ;
20
+ use function Activitypub \was_comment_received ;
14
21
15
22
/**
16
23
* ActivityPub Admin Class.
@@ -22,8 +29,6 @@ class Admin {
22
29
* Initialize the class, registering WordPress hooks,
23
30
*/
24
31
public static function init () {
25
- \add_action ( 'admin_menu ' , array ( self ::class, 'admin_menu ' ) );
26
- \add_action ( 'admin_init ' , array ( self ::class, 'register_settings ' ) );
27
32
\add_action ( 'load-comment.php ' , array ( self ::class, 'edit_comment ' ) );
28
33
\add_action ( 'load-post.php ' , array ( self ::class, 'edit_post ' ) );
29
34
\add_action ( 'load-edit.php ' , array ( self ::class, 'list_posts ' ) );
@@ -54,50 +59,6 @@ public static function init() {
54
59
\add_filter ( 'plugin_action_links_ ' . ACTIVITYPUB_PLUGIN_BASENAME , array ( self ::class, 'add_plugin_settings_link ' ) );
55
60
}
56
61
57
- /**
58
- * Add admin menu entry.
59
- */
60
- public static function admin_menu () {
61
- $ settings_page = \add_options_page (
62
- 'Welcome ' ,
63
- 'ActivityPub ' ,
64
- 'manage_options ' ,
65
- 'activitypub ' ,
66
- array ( self ::class, 'settings_page ' )
67
- );
68
-
69
- \add_action (
70
- 'load- ' . $ settings_page ,
71
- array ( self ::class, 'add_settings_help_tab ' )
72
- );
73
-
74
- // User has to be able to publish posts.
75
- if ( ! is_user_disabled ( get_current_user_id () ) ) {
76
- $ followers_list_page = \add_users_page (
77
- \__ ( 'Followers ⁂ ' , 'activitypub ' ),
78
- \__ ( 'Followers ⁂ ' , 'activitypub ' ),
79
- 'activitypub ' ,
80
- 'activitypub-followers-list ' ,
81
- array (
82
- self ::class,
83
- 'followers_list_page ' ,
84
- )
85
- );
86
-
87
- \add_action (
88
- 'load- ' . $ followers_list_page ,
89
- array ( self ::class, 'add_followers_list_help_tab ' )
90
- );
91
-
92
- \add_users_page (
93
- \__ ( 'Extra Fields ⁂ ' , 'activitypub ' ),
94
- \__ ( 'Extra Fields ⁂ ' , 'activitypub ' ),
95
- 'activitypub ' ,
96
- \esc_url ( \admin_url ( '/edit.php?post_type=ap_extrafield ' ) )
97
- );
98
- }
99
- }
100
-
101
62
/**
102
63
* Display admin menu notices about configuration problems or conflicts.
103
64
*/
@@ -143,63 +104,6 @@ private static function show_admin_notice( $admin_notice, $level ) {
143
104
<?php
144
105
}
145
106
146
- /**
147
- * Load settings page.
148
- */
149
- public static function settings_page () {
150
- // phpcs:ignore WordPress.Security.NonceVerification.Recommended
151
- $ tab = isset ( $ _GET ['tab ' ] ) ? sanitize_key ( $ _GET ['tab ' ] ) : 'welcome ' ;
152
-
153
- $ settings_tabs = array (
154
- 'welcome ' => array (
155
- 'label ' => __ ( 'Welcome ' , 'activitypub ' ),
156
- 'template ' => ACTIVITYPUB_PLUGIN_DIR . 'templates/welcome.php ' ,
157
- ),
158
- 'settings ' => array (
159
- 'label ' => __ ( 'Settings ' , 'activitypub ' ),
160
- 'template ' => ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php ' ,
161
- ),
162
- );
163
- if ( ! is_user_disabled ( Actors::BLOG_USER_ID ) ) {
164
- $ settings_tabs ['blog-profile ' ] = array (
165
- 'label ' => __ ( 'Blog Profile ' , 'activitypub ' ),
166
- 'template ' => ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-settings.php ' ,
167
- );
168
- $ settings_tabs ['followers ' ] = array (
169
- 'label ' => __ ( 'Followers ' , 'activitypub ' ),
170
- 'template ' => ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-followers-list.php ' ,
171
- );
172
- }
173
-
174
- /**
175
- * Filters the tabs displayed in the ActivityPub settings.
176
- *
177
- * @param array $settings_tabs The tabs to display.
178
- */
179
- $ custom_tabs = \apply_filters ( 'activitypub_admin_settings_tabs ' , array () );
180
- $ settings_tabs = \array_merge ( $ settings_tabs , $ custom_tabs );
181
-
182
- switch ( $ tab ) {
183
- case 'blog-profile ' :
184
- wp_enqueue_media ();
185
- wp_enqueue_script ( 'activitypub-header-image ' );
186
- break ;
187
- case 'welcome ' :
188
- wp_enqueue_script ( 'plugin-install ' );
189
- add_thickbox ();
190
- wp_enqueue_script ( 'updates ' );
191
- break ;
192
- }
193
-
194
- $ labels = wp_list_pluck ( $ settings_tabs , 'label ' );
195
- $ args = array_fill_keys ( array_keys ( $ labels ), '' );
196
- $ args [ $ tab ] = 'active ' ;
197
- $ args ['tabs ' ] = $ labels ;
198
-
199
- \load_template ( ACTIVITYPUB_PLUGIN_DIR . 'templates/admin-header.php ' , true , $ args );
200
- \load_template ( $ settings_tabs [ $ tab ]['template ' ] );
201
- }
202
-
203
107
/**
204
108
* Load user settings page
205
109
*/
@@ -210,223 +114,6 @@ public static function followers_list_page() {
210
114
}
211
115
}
212
116
213
- /**
214
- * Register ActivityPub settings
215
- */
216
- public static function register_settings () {
217
- \register_setting (
218
- 'activitypub ' ,
219
- 'activitypub_post_content_type ' ,
220
- array (
221
- 'type ' => 'string ' ,
222
- 'description ' => \__ ( 'Use title and link, summary, full or custom content ' , 'activitypub ' ),
223
- 'show_in_rest ' => array (
224
- 'schema ' => array (
225
- 'enum ' => array (
226
- 'title ' ,
227
- 'excerpt ' ,
228
- 'content ' ,
229
- ),
230
- ),
231
- ),
232
- 'default ' => 'content ' ,
233
- )
234
- );
235
- \register_setting (
236
- 'activitypub ' ,
237
- 'activitypub_custom_post_content ' ,
238
- array (
239
- 'type ' => 'string ' ,
240
- 'description ' => \__ ( 'Define your own custom post template ' , 'activitypub ' ),
241
- 'show_in_rest ' => true ,
242
- 'default ' => ACTIVITYPUB_CUSTOM_POST_CONTENT ,
243
- )
244
- );
245
- \register_setting (
246
- 'activitypub ' ,
247
- 'activitypub_max_image_attachments ' ,
248
- array (
249
- 'type ' => 'integer ' ,
250
- 'description ' => \__ ( 'Number of images to attach to posts. ' , 'activitypub ' ),
251
- 'default ' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ,
252
- )
253
- );
254
- \register_setting (
255
- 'activitypub ' ,
256
- 'activitypub_object_type ' ,
257
- array (
258
- 'type ' => 'string ' ,
259
- 'description ' => \__ ( 'The Activity-Object-Type ' , 'activitypub ' ),
260
- 'show_in_rest ' => array (
261
- 'schema ' => array (
262
- 'enum ' => array (
263
- 'note ' ,
264
- 'wordpress-post-format ' ,
265
- ),
266
- ),
267
- ),
268
- 'default ' => ACTIVITYPUB_DEFAULT_OBJECT_TYPE ,
269
- )
270
- );
271
- \register_setting (
272
- 'activitypub ' ,
273
- 'activitypub_use_hashtags ' ,
274
- array (
275
- 'type ' => 'boolean ' ,
276
- 'description ' => \__ ( 'Add hashtags in the content as native tags and replace the #tag with the tag-link ' , 'activitypub ' ),
277
- 'default ' => '0 ' ,
278
- )
279
- );
280
- \register_setting (
281
- 'activitypub ' ,
282
- 'activitypub_use_opengraph ' ,
283
- array (
284
- 'type ' => 'boolean ' ,
285
- 'description ' => \__ ( 'Automatically add "fediverse:creator" OpenGraph tags for Authors and the Blog-User. ' , 'activitypub ' ),
286
- 'default ' => '1 ' ,
287
- )
288
- );
289
- \register_setting (
290
- 'activitypub ' ,
291
- 'activitypub_support_post_types ' ,
292
- array (
293
- 'type ' => 'string ' ,
294
- 'description ' => \esc_html__ ( 'Enable ActivityPub support for post types ' , 'activitypub ' ),
295
- 'show_in_rest ' => true ,
296
- 'default ' => array ( 'post ' ),
297
- )
298
- );
299
- \register_setting (
300
- 'activitypub ' ,
301
- 'activitypub_actor_mode ' ,
302
- array (
303
- 'type ' => 'integer ' ,
304
- 'description ' => \__ ( 'Choose your preferred Actor-Mode. ' , 'activitypub ' ),
305
- 'default ' => ACTIVITYPUB_ACTOR_MODE ,
306
- )
307
- );
308
-
309
- \register_setting (
310
- 'activitypub ' ,
311
- 'activitypub_attribution_domains ' ,
312
- array (
313
- 'type ' => 'string ' ,
314
- 'description ' => \__ ( 'Websites allowed to credit you. ' , 'activitypub ' ),
315
- 'default ' => home_host (),
316
- 'sanitize_callback ' => function ( $ value ) {
317
- $ value = explode ( PHP_EOL , $ value );
318
- $ value = array_filter ( array_map ( 'trim ' , $ value ) );
319
- $ value = array_filter ( array_map ( 'esc_attr ' , $ value ) );
320
- $ value = implode ( PHP_EOL , $ value );
321
-
322
- return $ value ;
323
- },
324
- )
325
- );
326
-
327
- \register_setting (
328
- 'activitypub ' ,
329
- 'activitypub_authorized_fetch ' ,
330
- array (
331
- 'type ' => 'boolean ' ,
332
- 'description ' => \__ ( 'Require HTTP signature authentication. ' , 'activitypub ' ),
333
- 'default ' => false ,
334
- )
335
- );
336
-
337
- \register_setting (
338
- 'activitypub ' ,
339
- 'activitypub_mailer_new_follower ' ,
340
- array (
341
- 'type ' => 'boolean ' ,
342
- 'description ' => \__ ( 'Send notifications via e-mail when a new follower is added. ' , 'activitypub ' ),
343
- 'default ' => '0 ' ,
344
- )
345
- );
346
- \register_setting (
347
- 'activitypub ' ,
348
- 'activitypub_mailer_new_dm ' ,
349
- array (
350
- 'type ' => 'boolean ' ,
351
- 'description ' => \__ ( 'Send notifications via e-mail when a direct message is received. ' , 'activitypub ' ),
352
- 'default ' => '0 ' ,
353
- )
354
- );
355
-
356
- // Blog-User Settings.
357
- \register_setting (
358
- 'activitypub_blog ' ,
359
- 'activitypub_blog_description ' ,
360
- array (
361
- 'type ' => 'string ' ,
362
- 'description ' => \esc_html__ ( 'The Description of the Blog-User ' , 'activitypub ' ),
363
- 'show_in_rest ' => true ,
364
- 'default ' => '' ,
365
- )
366
- );
367
- \register_setting (
368
- 'activitypub_blog ' ,
369
- 'activitypub_blog_identifier ' ,
370
- array (
371
- 'type ' => 'string ' ,
372
- 'description ' => \esc_html__ ( 'The Identifier of the Blog-User ' , 'activitypub ' ),
373
- 'show_in_rest ' => true ,
374
- 'default ' => Blog::get_default_username (),
375
- 'sanitize_callback ' => function ( $ value ) {
376
- // Hack to allow dots in the username.
377
- $ parts = explode ( '. ' , $ value );
378
- $ sanitized = array ();
379
-
380
- foreach ( $ parts as $ part ) {
381
- $ sanitized [] = \sanitize_title ( $ part );
382
- }
383
-
384
- $ sanitized = implode ( '. ' , $ sanitized );
385
-
386
- // Check for login or nicename.
387
- $ user = new WP_User_Query (
388
- array (
389
- 'search ' => $ sanitized ,
390
- 'search_columns ' => array ( 'user_login ' , 'user_nicename ' ),
391
- 'number ' => 1 ,
392
- 'hide_empty ' => true ,
393
- 'fields ' => 'ID ' ,
394
- )
395
- );
396
-
397
- if ( $ user ->results ) {
398
- add_settings_error (
399
- 'activitypub_blog_identifier ' ,
400
- 'activitypub_blog_identifier ' ,
401
- \esc_html__ ( 'You cannot use an existing author \'s name for the blog profile ID. ' , 'activitypub ' ),
402
- 'error '
403
- );
404
-
405
- return Blog::get_default_username ();
406
- }
407
-
408
- return $ sanitized ;
409
- },
410
- )
411
- );
412
- \register_setting (
413
- 'activitypub_blog ' ,
414
- 'activitypub_header_image ' ,
415
- array (
416
- 'type ' => 'integer ' ,
417
- 'description ' => \__ ( 'The Attachment-ID of the Sites Header-Image ' , 'activitypub ' ),
418
- 'default ' => null ,
419
- )
420
- );
421
- }
422
-
423
- /**
424
- * Adds the ActivityPub settings to the Help tab.
425
- */
426
- public static function add_settings_help_tab () {
427
- require_once ACTIVITYPUB_PLUGIN_DIR . 'includes/help.php ' ;
428
- }
429
-
430
117
/**
431
118
* Adds the follower list to the Help tab.
432
119
*/
0 commit comments