From 24106f58252b9919959aa70c12d419828fd01826 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Fri, 7 Feb 2025 17:28:45 +0100 Subject: [PATCH] add settings --- includes/wp-admin/class-admin.php | 217 ++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) diff --git a/includes/wp-admin/class-admin.php b/includes/wp-admin/class-admin.php index 77ddfd942..1a336d96d 100644 --- a/includes/wp-admin/class-admin.php +++ b/includes/wp-admin/class-admin.php @@ -112,6 +112,223 @@ public static function followers_list_page() { } } + /** + * Register ActivityPub settings + */ + public static function register_settings() { + \register_setting( + 'activitypub', + 'activitypub_post_content_type', + array( + 'type' => 'string', + 'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ), + 'show_in_rest' => array( + 'schema' => array( + 'enum' => array( + 'title', + 'excerpt', + 'content', + ), + ), + ), + 'default' => 'content', + ) + ); + \register_setting( + 'activitypub', + 'activitypub_custom_post_content', + array( + 'type' => 'string', + 'description' => \__( 'Define your own custom post template', 'activitypub' ), + 'show_in_rest' => true, + 'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT, + ) + ); + \register_setting( + 'activitypub', + 'activitypub_max_image_attachments', + array( + 'type' => 'integer', + 'description' => \__( 'Number of images to attach to posts.', 'activitypub' ), + 'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS, + ) + ); + \register_setting( + 'activitypub', + 'activitypub_object_type', + array( + 'type' => 'string', + 'description' => \__( 'The Activity-Object-Type', 'activitypub' ), + 'show_in_rest' => array( + 'schema' => array( + 'enum' => array( + 'note', + 'wordpress-post-format', + ), + ), + ), + 'default' => ACTIVITYPUB_DEFAULT_OBJECT_TYPE, + ) + ); + \register_setting( + 'activitypub', + 'activitypub_use_hashtags', + array( + 'type' => 'boolean', + 'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ), + 'default' => '0', + ) + ); + \register_setting( + 'activitypub', + 'activitypub_use_opengraph', + array( + 'type' => 'boolean', + 'description' => \__( 'Automatically add "fediverse:creator" OpenGraph tags for Authors and the Blog-User.', 'activitypub' ), + 'default' => '1', + ) + ); + \register_setting( + 'activitypub', + 'activitypub_support_post_types', + array( + 'type' => 'string', + 'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ), + 'show_in_rest' => true, + 'default' => array( 'post' ), + ) + ); + \register_setting( + 'activitypub', + 'activitypub_actor_mode', + array( + 'type' => 'integer', + 'description' => \__( 'Choose your preferred Actor-Mode.', 'activitypub' ), + 'default' => ACTIVITYPUB_ACTOR_MODE, + ) + ); + + \register_setting( + 'activitypub', + 'activitypub_attribution_domains', + array( + 'type' => 'string', + 'description' => \__( 'Websites allowed to credit you.', 'activitypub' ), + 'default' => home_host(), + 'sanitize_callback' => function ( $value ) { + $value = explode( PHP_EOL, $value ); + $value = array_filter( array_map( 'trim', $value ) ); + $value = array_filter( array_map( 'esc_attr', $value ) ); + $value = implode( PHP_EOL, $value ); + + return $value; + }, + ) + ); + + \register_setting( + 'activitypub', + 'activitypub_authorized_fetch', + array( + 'type' => 'boolean', + 'description' => \__( 'Require HTTP signature authentication.', 'activitypub' ), + 'default' => false, + ) + ); + + \register_setting( + 'activitypub', + 'activitypub_mailer_new_follower', + array( + 'type' => 'boolean', + 'description' => \__( 'Send notifications via e-mail when a new follower is added.', 'activitypub' ), + 'default' => '0', + ) + ); + \register_setting( + 'activitypub', + 'activitypub_mailer_new_dm', + array( + 'type' => 'boolean', + 'description' => \__( 'Send notifications via e-mail when a direct message is received.', 'activitypub' ), + 'default' => '0', + ) + ); + + // Blog-User Settings. + \register_setting( + 'activitypub_blog', + 'activitypub_blog_description', + array( + 'type' => 'string', + 'description' => \esc_html__( 'The Description of the Blog-User', 'activitypub' ), + 'show_in_rest' => true, + 'default' => '', + ) + ); + \register_setting( + 'activitypub_blog', + 'activitypub_blog_identifier', + array( + 'type' => 'string', + 'description' => \esc_html__( 'The Identifier of the Blog-User', 'activitypub' ), + 'show_in_rest' => true, + 'default' => Blog::get_default_username(), + 'sanitize_callback' => function ( $value ) { + // Hack to allow dots in the username. + $parts = explode( '.', $value ); + $sanitized = array(); + + foreach ( $parts as $part ) { + $sanitized[] = \sanitize_title( $part ); + } + + $sanitized = implode( '.', $sanitized ); + + // Check for login or nicename. + $user = new WP_User_Query( + array( + 'search' => $sanitized, + 'search_columns' => array( 'user_login', 'user_nicename' ), + 'number' => 1, + 'hide_empty' => true, + 'fields' => 'ID', + ) + ); + + if ( $user->results ) { + add_settings_error( + 'activitypub_blog_identifier', + 'activitypub_blog_identifier', + \esc_html__( 'You cannot use an existing author\'s name for the blog profile ID.', 'activitypub' ), + 'error' + ); + + return Blog::get_default_username(); + } + + return $sanitized; + }, + ) + ); + \register_setting( + 'activitypub_blog', + 'activitypub_header_image', + array( + 'type' => 'integer', + 'description' => \__( 'The Attachment-ID of the Sites Header-Image', 'activitypub' ), + 'default' => null, + ) + ); + } + + /** + * Adds the ActivityPub settings to the Help tab. + */ + public static function add_settings_help_tab() { + require_once ACTIVITYPUB_PLUGIN_DIR . 'includes/help.php'; + } + /** * Adds the follower list to the Help tab. */