| @@ -7,8 +7,10 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace Activitypub\WP_Admin; |
| 9 | 9 | |
| 10 | 10 | use Activitypub\Collection\Actors; |
| 11 | +use Activitypub\Model\Blog; | |
| 12 | +use Activitypub\Sanitize; | |
| 11 | 13 | |
| 12 | 14 | use function Activitypub\user_can_activitypub; |
| 13 | 15 | |
| 14 | 16 | /** |
| @@ -18,15 +20,348 @@ | ||
| 18 | 20 | /** |
| 19 | 21 | * Initialize the class, registering WordPress hooks, |
| 20 | 22 | */ |
| 21 | 23 | public static function init() { |
| 24 | + \add_action( 'admin_init', array( self::class, 'register_settings' ), 11 ); | |
| 22 | 25 | \add_action( 'admin_menu', array( self::class, 'add_settings_page' ) ); |
| 23 | 26 | |
| 24 | 27 | \add_action( 'load-settings_page_activitypub', array( self::class, 'handle_welcome_query_arg' ) ); |
| 25 | - \add_action( 'load-settings_page_activitypub', array( self::class, 'handle_switch_object_type' ) ); | |
| 26 | 28 | } |
| 27 | 29 | |
| 28 | 30 | /** |
| 31 | + * Register ActivityPub settings | |
| 32 | + */ | |
| 33 | + public static function register_settings() { | |
| 34 | + \register_setting( | |
| 35 | + 'activitypub', | |
| 36 | + 'activitypub_post_content_type', | |
| 37 | + array( | |
| 38 | + 'type' => 'string', | |
| 39 | + 'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ), | |
| 40 | + 'show_in_rest' => array( | |
| 41 | + 'schema' => array( | |
| 42 | + 'enum' => array( 'title', 'excerpt', 'content' ), | |
| 43 | + ), | |
| 44 | + ), | |
| 45 | + 'default' => 'content', | |
| 46 | + ) | |
| 47 | + ); | |
| 48 | + | |
| 49 | + \register_setting( | |
| 50 | + 'activitypub', | |
| 51 | + 'activitypub_custom_post_content', | |
| 52 | + array( | |
| 53 | + 'type' => 'string', | |
| 54 | + 'description' => \__( 'Define your own custom post template', 'activitypub' ), | |
| 55 | + 'show_in_rest' => true, | |
| 56 | + 'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT, | |
| 57 | + ) | |
| 58 | + ); | |
| 59 | + | |
| 60 | + \register_setting( | |
| 61 | + 'activitypub', | |
| 62 | + 'activitypub_max_image_attachments', | |
| 63 | + array( | |
| 64 | + 'type' => 'integer', | |
| 65 | + 'description' => \__( 'Number of images to attach to posts.', 'activitypub' ), | |
| 66 | + 'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS, | |
| 67 | + 'sanitize_callback' => function ( $value ) { | |
| 68 | + return \is_numeric( $value ) ? \absint( $value ) : ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS; | |
| 69 | + }, | |
| 70 | + ) | |
| 71 | + ); | |
| 72 | + | |
| 73 | + \register_setting( | |
| 74 | + 'activitypub', | |
| 75 | + 'activitypub_use_hashtags', | |
| 76 | + array( | |
| 77 | + 'type' => 'boolean', | |
| 78 | + 'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ), | |
| 79 | + 'default' => '0', | |
| 80 | + ) | |
| 81 | + ); | |
| 82 | + | |
| 83 | + \register_setting( | |
| 84 | + 'activitypub', | |
| 85 | + 'activitypub_use_opengraph', | |
| 86 | + array( | |
| 87 | + 'type' => 'boolean', | |
| 88 | + 'description' => \__( 'Automatically add "fediverse:creator" OpenGraph tags for Authors and the Blog-User.', 'activitypub' ), | |
| 89 | + 'default' => '1', | |
| 90 | + ) | |
| 91 | + ); | |
| 92 | + | |
| 93 | + \register_setting( | |
| 94 | + 'activitypub', | |
| 95 | + 'activitypub_support_post_types', | |
| 96 | + array( | |
| 97 | + 'type' => 'string', | |
| 98 | + 'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ), | |
| 99 | + 'show_in_rest' => true, | |
| 100 | + 'default' => array( 'post' ), | |
| 101 | + ) | |
| 102 | + ); | |
| 103 | + | |
| 104 | + \register_setting( | |
| 105 | + 'activitypub', | |
| 106 | + 'activitypub_actor_mode', | |
| 107 | + array( | |
| 108 | + 'type' => 'integer', | |
| 109 | + 'description' => \__( 'Choose your preferred Actor-Mode.', 'activitypub' ), | |
| 110 | + 'default' => ACTIVITYPUB_ACTOR_MODE, | |
| 111 | + ) | |
| 112 | + ); | |
| 113 | + | |
| 114 | + \register_setting( | |
| 115 | + 'activitypub', | |
| 116 | + 'activitypub_attribution_domains', | |
| 117 | + array( | |
| 118 | + 'type' => 'string', | |
| 119 | + 'description' => \__( 'Websites allowed to credit you.', 'activitypub' ), | |
| 120 | + 'default' => \Activitypub\home_host(), | |
| 121 | + 'sanitize_callback' => array( Sanitize::class, 'host_list' ), | |
| 122 | + ) | |
| 123 | + ); | |
| 124 | + | |
| 125 | + \register_setting( | |
| 126 | + 'activitypub', | |
| 127 | + 'activitypub_allow_likes', | |
| 128 | + array( | |
| 129 | + 'type' => 'integer', | |
| 130 | + 'description' => \__( 'Allow likes.', 'activitypub' ), | |
| 131 | + 'default' => '1', | |
| 132 | + 'sanitize_callback' => 'absint', | |
| 133 | + ) | |
| 134 | + ); | |
| 135 | + | |
| 136 | + \register_setting( | |
| 137 | + 'activitypub', | |
| 138 | + 'activitypub_allow_reposts', | |
| 139 | + array( | |
| 140 | + 'type' => 'integer', | |
| 141 | + 'description' => \__( 'Allow reposts.', 'activitypub' ), | |
| 142 | + 'default' => '1', | |
| 143 | + 'sanitize_callback' => 'absint', | |
| 144 | + ) | |
| 145 | + ); | |
| 146 | + | |
| 147 | + \register_setting( | |
| 148 | + 'activitypub', | |
| 149 | + 'activitypub_auto_approve_reactions', | |
| 150 | + array( | |
| 151 | + 'type' => 'integer', | |
| 152 | + 'description' => \__( 'Auto approve Reactions.', 'activitypub' ), | |
| 153 | + 'default' => '0', | |
| 154 | + 'sanitize_callback' => 'absint', | |
| 155 | + ) | |
| 156 | + ); | |
| 157 | + | |
| 158 | + \register_setting( | |
| 159 | + 'activitypub', | |
| 160 | + 'activitypub_relays', | |
| 161 | + array( | |
| 162 | + 'type' => 'array', | |
| 163 | + 'description' => \__( 'Relays', 'activitypub' ), | |
| 164 | + 'default' => array(), | |
| 165 | + 'sanitize_callback' => array( Sanitize::class, 'url_list' ), | |
| 166 | + ) | |
| 167 | + ); | |
| 168 | + | |
| 169 | + \register_setting( | |
| 170 | + 'activitypub_advanced', | |
| 171 | + 'activitypub_outbox_purge_days', | |
| 172 | + array( | |
| 173 | + 'type' => 'integer', | |
| 174 | + 'description' => \__( 'Number of days to keep items in the Outbox.', 'activitypub' ), | |
| 175 | + 'default' => 180, | |
| 176 | + ) | |
| 177 | + ); | |
| 178 | + | |
| 179 | + \register_setting( | |
| 180 | + 'activitypub_advanced', | |
| 181 | + 'activitypub_inbox_purge_days', | |
| 182 | + array( | |
| 183 | + 'type' => 'integer', | |
| 184 | + 'description' => \__( 'Number of days to keep items in the Inbox.', 'activitypub' ), | |
| 185 | + 'default' => 180, | |
| 186 | + ) | |
| 187 | + ); | |
| 188 | + | |
| 189 | + \register_setting( | |
| 190 | + 'activitypub_advanced', | |
| 191 | + 'activitypub_vary_header', | |
| 192 | + array( | |
| 193 | + 'type' => 'boolean', | |
| 194 | + 'description' => \__( 'Add the Vary header to the ActivityPub response.', 'activitypub' ), | |
| 195 | + 'default' => true, | |
| 196 | + ) | |
| 197 | + ); | |
| 198 | + | |
| 199 | + \register_setting( | |
| 200 | + 'activitypub_advanced', | |
| 201 | + 'activitypub_content_negotiation', | |
| 202 | + array( | |
| 203 | + 'type' => 'boolean', | |
| 204 | + 'description' => 'Enable content negotiation.', | |
| 205 | + 'default' => true, | |
| 206 | + ) | |
| 207 | + ); | |
| 208 | + | |
| 209 | + \register_setting( | |
| 210 | + 'activitypub_advanced', | |
| 211 | + 'activitypub_authorized_fetch', | |
| 212 | + array( | |
| 213 | + 'type' => 'boolean', | |
| 214 | + 'description' => \__( 'Require HTTP signature authentication.', 'activitypub' ), | |
| 215 | + 'default' => false, | |
| 216 | + ) | |
| 217 | + ); | |
| 218 | + | |
| 219 | + \register_setting( | |
| 220 | + 'activitypub_advanced', | |
| 221 | + 'activitypub_rfc9421_signature', | |
| 222 | + array( | |
| 223 | + 'type' => 'boolean', | |
| 224 | + 'description' => 'Use RFC-9421 signature.', | |
| 225 | + 'default' => false, | |
| 226 | + ) | |
| 227 | + ); | |
| 228 | + | |
| 229 | + \register_setting( | |
| 230 | + 'activitypub_advanced', | |
| 231 | + 'activitypub_following_ui', | |
| 232 | + array( | |
| 233 | + 'type' => 'boolean', | |
| 234 | + 'description' => 'Show Following UI in admin menus and settings.', | |
| 235 | + 'default' => false, | |
| 236 | + ) | |
| 237 | + ); | |
| 238 | + | |
| 239 | + \register_setting( | |
| 240 | + 'activitypub_advanced', | |
| 241 | + 'activitypub_create_posts', | |
| 242 | + array( | |
| 243 | + 'type' => 'boolean', | |
| 244 | + 'description' => 'Allow creating posts via ActivityPub.', | |
| 245 | + 'default' => false, | |
| 246 | + ) | |
| 247 | + ); | |
| 248 | + | |
| 249 | + \register_setting( | |
| 250 | + 'activitypub_advanced', | |
| 251 | + 'activitypub_object_type', | |
| 252 | + array( | |
| 253 | + 'type' => 'string', | |
| 254 | + 'description' => \__( 'The Activity-Object-Type', 'activitypub' ), | |
| 255 | + 'show_in_rest' => array( | |
| 256 | + 'schema' => array( | |
| 257 | + 'enum' => array( 'note', 'wordpress-post-format' ), | |
| 258 | + ), | |
| 259 | + ), | |
| 260 | + 'default' => ACTIVITYPUB_DEFAULT_OBJECT_TYPE, | |
| 261 | + ) | |
| 262 | + ); | |
| 263 | + | |
| 264 | + // Blog-User Settings. | |
| 265 | + \register_setting( | |
| 266 | + 'activitypub_blog', | |
| 267 | + 'activitypub_blog_description', | |
| 268 | + array( | |
| 269 | + 'type' => 'string', | |
| 270 | + 'description' => \esc_html__( 'The Description of the Blog-User', 'activitypub' ), | |
| 271 | + 'show_in_rest' => true, | |
| 272 | + 'default' => '', | |
| 273 | + ) | |
| 274 | + ); | |
| 275 | + | |
| 276 | + \register_setting( | |
| 277 | + 'activitypub_blog', | |
| 278 | + 'activitypub_blog_identifier', | |
| 279 | + array( | |
| 280 | + 'type' => 'string', | |
| 281 | + 'description' => \esc_html__( 'The Identifier of the Blog-User', 'activitypub' ), | |
| 282 | + 'show_in_rest' => true, | |
| 283 | + 'default' => Blog::get_default_username(), | |
| 284 | + 'sanitize_callback' => array( Sanitize::class, 'blog_identifier' ), | |
| 285 | + ) | |
| 286 | + ); | |
| 287 | + | |
| 288 | + \register_setting( | |
| 289 | + 'activitypub_blog', | |
| 290 | + 'activitypub_header_image', | |
| 291 | + array( | |
| 292 | + 'type' => 'integer', | |
| 293 | + 'description' => \__( 'The Attachment-ID of the Sites Header-Image', 'activitypub' ), | |
| 294 | + 'default' => null, | |
| 295 | + ) | |
| 296 | + ); | |
| 297 | + | |
| 298 | + \register_setting( | |
| 299 | + 'activitypub_blog', | |
| 300 | + 'activitypub_blog_user_mailer_new_dm', | |
| 301 | + array( | |
| 302 | + 'type' => 'integer', | |
| 303 | + 'description' => 'Send a notification when someone sends a user of the blog a direct message.', | |
| 304 | + 'default' => 1, | |
| 305 | + ) | |
| 306 | + ); | |
| 307 | + | |
| 308 | + \register_setting( | |
| 309 | + 'activitypub_blog', | |
| 310 | + 'activitypub_blog_user_mailer_new_follower', | |
| 311 | + array( | |
| 312 | + 'type' => 'integer', | |
| 313 | + 'description' => 'Send a notification when someone starts to follow a user of the blog.', | |
| 314 | + 'default' => 1, | |
| 315 | + ) | |
| 316 | + ); | |
| 317 | + | |
| 318 | + \register_setting( | |
| 319 | + 'activitypub_blog', | |
| 320 | + 'activitypub_blog_user_mailer_new_mention', | |
| 321 | + array( | |
| 322 | + 'type' => 'integer', | |
| 323 | + 'description' => 'Send a notification when someone mentions a user of the blog.', | |
| 324 | + 'default' => 1, | |
| 325 | + ) | |
| 326 | + ); | |
| 327 | + | |
| 328 | + \register_setting( | |
| 329 | + 'activitypub_blog', | |
| 330 | + 'activitypub_blog_user_also_known_as', | |
| 331 | + array( | |
| 332 | + 'type' => 'array', | |
| 333 | + 'description' => 'An array of URLs that the blog user is known by.', | |
| 334 | + 'default' => array(), | |
| 335 | + 'sanitize_callback' => array( Sanitize::class, 'identifier_list' ), | |
| 336 | + ) | |
| 337 | + ); | |
| 338 | + | |
| 339 | + \register_setting( | |
| 340 | + 'activitypub_blog', | |
| 341 | + 'activitypub_hide_social_graph', | |
| 342 | + array( | |
| 343 | + 'type' => 'integer', | |
| 344 | + 'description' => 'Hide Followers and Followings on Profile.', | |
| 345 | + 'default' => 0, | |
| 346 | + 'sanitize_callback' => 'absint', | |
| 347 | + ) | |
| 348 | + ); | |
| 349 | + | |
| 350 | + // Moderation settings. | |
| 351 | + \register_setting( | |
| 352 | + 'activitypub', | |
| 353 | + 'activitypub_site_blocked_actors', | |
| 354 | + array( | |
| 355 | + 'type' => 'array', | |
| 356 | + 'description' => 'Site-wide blocked ActivityPub actors.', | |
| 357 | + 'default' => array(), | |
| 358 | + 'sanitize_callback' => array( Sanitize::class, 'identifier_list' ), | |
| 359 | + ) | |
| 360 | + ); | |
| 361 | + } | |
| 362 | + | |
| 363 | + /** | |
| 29 | 364 | * Load settings page. |
| 30 | 365 | */ |
| 31 | 366 | public static function settings_page() { |
| 32 | 367 | $show_welcome_tab = \get_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', true ); |
| @@ -32,15 +367,15 @@ | ||
| 32 | 367 | $show_welcome_tab = \get_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', true ); |
| 33 | 368 | $show_advanced_tab = \get_user_meta( \get_current_user_id(), 'activitypub_show_advanced_tab', true ); |
| 34 | 369 | $settings_tabs = array(); |
| 35 | 370 | $settings_tab = array( |
| 36 | - 'label' => \__( 'Settings', 'activitypub' ), | |
| 371 | + 'label' => __( 'Settings', 'activitypub' ), | |
| 37 | 372 | 'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php', |
| 38 | 373 | ); |
| 39 | 374 | |
| 40 | 375 | if ( $show_welcome_tab ) { |
| 41 | 376 | $settings_tabs['welcome'] = array( |
| 42 | - 'label' => \__( 'Welcome', 'activitypub' ), | |
| 377 | + 'label' => __( 'Welcome', 'activitypub' ), | |
| 43 | 378 | 'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/welcome.php', |
| 44 | 379 | ); |
| 45 | 380 | } |
| 46 | 381 | |
| @@ -61,19 +396,19 @@ | ||
| 61 | 396 | ); |
| 62 | 397 | |
| 63 | 398 | if ( user_can_activitypub( Actors::BLOG_USER_ID ) ) { |
| 64 | 399 | $settings_tabs['blog-profile'] = array( |
| 65 | - 'label' => \__( 'Blog Profile', 'activitypub' ), | |
| 400 | + 'label' => __( 'Blog Profile', 'activitypub' ), | |
| 66 | 401 | 'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-settings.php', |
| 67 | 402 | ); |
| 68 | 403 | $settings_tabs['followers'] = array( |
| 69 | - 'label' => \__( 'Followers', 'activitypub' ), | |
| 404 | + 'label' => __( 'Followers', 'activitypub' ), | |
| 70 | 405 | 'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/followers-list.php', |
| 71 | 406 | ); |
| 72 | 407 | |
| 73 | 408 | if ( '1' === \get_option( 'activitypub_following_ui', '0' ) ) { |
| 74 | 409 | $settings_tabs['following'] = array( |
| 75 | - 'label' => \__( 'Following', 'activitypub' ), | |
| 410 | + 'label' => __( 'Following', 'activitypub' ), | |
| 76 | 411 | 'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/following-list.php', |
| 77 | 412 | ); |
| 78 | 413 | } |
| 79 | 414 | } |
| @@ -85,14 +420,14 @@ | ||
| 85 | 420 | */ |
| 86 | 421 | $settings_tabs = \apply_filters( 'activitypub_admin_settings_tabs', $settings_tabs ); |
| 87 | 422 | |
| 88 | 423 | if ( empty( $settings_tabs ) ) { |
| 89 | - \_doing_it_wrong( __FUNCTION__, 'No settings tabs found. There should be at least one tab to show a settings page.', '7.0.0' ); | |
| 424 | + _doing_it_wrong( __FUNCTION__, 'No settings tabs found. There should be at least one tab to show a settings page.', '7.0.0' ); | |
| 90 | 425 | $settings_tabs['settings'] = $settings_tab; |
| 91 | 426 | } |
| 92 | 427 | |
| 93 | - $tab_keys = \array_keys( $settings_tabs ); | |
| 94 | - $default_tab = \reset( $tab_keys ); | |
| 428 | + $tab_keys = array_keys( $settings_tabs ); | |
| 429 | + $default_tab = reset( $tab_keys ); | |
| 95 | 430 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 96 | 431 | $tab = isset( $_GET['tab'] ) ? \sanitize_key( $_GET['tab'] ) : $default_tab; |
| 97 | 432 | |
| 98 | 433 | if ( ! isset( $settings_tabs[ $tab ] ) ) { |
| @@ -192,12 +527,12 @@ | ||
| 192 | 527 | if ( ! empty( self::get_recommended_plugins() ) ) { |
| 193 | 528 | \get_current_screen()->add_help_tab( |
| 194 | 529 | array( |
| 195 | 530 | 'id' => 'recommended-plugins', |
| 196 | - 'title' => \__( 'Recommended Plugins', 'activitypub' ), | |
| 531 | + 'title' => __( 'Recommended Plugins', 'activitypub' ), | |
| 197 | 532 | 'content' => |
| 198 | - '<h2>' . \esc_html__( 'Supercharge Your Fediverse Experience', 'activitypub' ) . '</h2>' . | |
| 199 | - '<p>' . \esc_html__( 'Enhance your WordPress ActivityPub setup with these hand-picked plugins, each adding unique capabilities for a richer Fediverse experience.', 'activitypub' ) . '</p>' . | |
| 533 | + '<h2>' . esc_html__( 'Supercharge Your Fediverse Experience', 'activitypub' ) . '</h2>' . | |
| 534 | + '<p>' . esc_html__( 'Enhance your WordPress ActivityPub setup with these hand-picked plugins, each adding unique capabilities for a richer Fediverse experience.', 'activitypub' ) . '</p>' . | |
| 200 | 535 | self::render_recommended_plugins_list(), |
| 201 | 536 | ) |
| 202 | 537 | ); |
| 203 | 538 | } |
| @@ -289,31 +624,8 @@ | ||
| 289 | 624 | } |
| 290 | 625 | } |
| 291 | 626 | |
| 292 | 627 | /** |
| 293 | - * Handle switching from legacy template mode to automatic object type. | |
| 294 | - * | |
| 295 | - * @since 8.0.0 | |
| 296 | - */ | |
| 297 | - public static function handle_switch_object_type() { | |
| 298 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 299 | - if ( ! isset( $_GET['activitypub_update_object_type'] ) ) { | |
| 300 | - return; | |
| 301 | - } | |
| 302 | - | |
| 303 | - \check_admin_referer( 'activitypub_switch_object_type' ); | |
| 304 | - | |
| 305 | - if ( ! \current_user_can( 'manage_options' ) ) { | |
| 306 | - return; | |
| 307 | - } | |
| 308 | - | |
| 309 | - \update_option( 'activitypub_object_type', ACTIVITYPUB_DEFAULT_OBJECT_TYPE ); | |
| 310 | - | |
| 311 | - \wp_safe_redirect( \admin_url( 'options-general.php?page=activitypub&tab=settings' ) ); | |
| 312 | - exit; | |
| 313 | - } | |
| 314 | - | |
| 315 | - /** | |
| 316 | 628 | * Returns an array of recommended plugins for ActivityPub. |
| 317 | 629 | */ |
| 318 | 630 | public static function get_recommended_plugins() { |
| 319 | 631 | $plugins = array(); |
| @@ -443,13 +755,13 @@ | ||
| 443 | 755 | * @return string Rendered template output. |
| 444 | 756 | */ |
| 445 | 757 | private static function get_help_tab_template( $template_name ) { |
| 446 | 758 | $template_path = ACTIVITYPUB_PLUGIN_DIR . 'templates/help-tab/' . $template_name . '.php'; |
| 447 | - if ( ! \file_exists( $template_path ) ) { | |
| 759 | + if ( ! file_exists( $template_path ) ) { | |
| 448 | 760 | return ''; |
| 449 | 761 | } |
| 450 | 762 | |
| 451 | - \ob_start(); | |
| 452 | - \load_template( $template_path, false ); | |
| 453 | - return \ob_get_clean(); | |
| 763 | + ob_start(); | |
| 764 | + load_template( $template_path, false ); | |
| 765 | + return ob_get_clean(); | |
| 454 | 766 | } |
| 455 | 767 | } |