From fba834b15df844b196d1ed6b067423c3e9788554 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Tue, 15 Nov 2022 18:22:08 +0100 Subject: [PATCH] add some guidance based on the feedback of users and the suggestion of @akirk --- README.md | 2 +- activitypub.php | 3 +- assets/css/admin.css | 46 ++++++++++++++++++++++++++ includes/class-admin.php | 48 +++++++++++++++------------ includes/class-webfinger.php | 29 +++++++++++++++++ includes/functions.php | 9 +---- includes/help.php | 56 ++++++++++++++++++++++++++++++++ includes/rest/class-nodeinfo.php | 8 ----- templates/admin-header.php | 16 +++++++++ templates/settings.php | 16 ++++----- templates/welcome.php | 23 +++++++++++++ 11 files changed, 208 insertions(+), 48 deletions(-) create mode 100644 assets/css/admin.css create mode 100644 includes/class-webfinger.php create mode 100644 includes/help.php create mode 100644 templates/admin-header.php create mode 100644 templates/welcome.php diff --git a/README.md b/README.md index 6ff1117..56a6576 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ActivityPub # -**Contributors:** [pfefferle](https://profiles.wordpress.org/pfefferle), [mediaformat](https://profiles.wordpress.org/mediaformat) +**Contributors:** [pfefferle](https://profiles.wordpress.org/pfefferle/), [mediaformat](https://profiles.wordpress.org/mediaformat/) **Donate link:** https://notiz.blog/donate/ **Tags:** OStatus, fediverse, activitypub, activitystream **Requires at least:** 4.7 diff --git a/activitypub.php b/activitypub.php index d802cd7..58adc9c 100644 --- a/activitypub.php +++ b/activitypub.php @@ -25,6 +25,7 @@ function init() { require_once \dirname( __FILE__ ) . '/includes/table/followers-list.php'; require_once \dirname( __FILE__ ) . '/includes/class-signature.php'; + require_once \dirname( __FILE__ ) . '/includes/class-webfinger.php'; require_once \dirname( __FILE__ ) . '/includes/peer/class-followers.php'; require_once \dirname( __FILE__ ) . '/includes/functions.php'; @@ -107,7 +108,7 @@ function add_rewrite_rules() { \add_rewrite_rule( '^.well-known/webfinger', 'index.php?rest_route=/activitypub/1.0/webfinger', 'top' ); } - if ( ! \class_exists( 'Nodeinfo' ) ) { + if ( ! \class_exists( 'Nodeinfo' ) || ! get_option( 'blog_public' ) ) { \add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/activitypub/1.0/nodeinfo/discovery', 'top' ); \add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/activitypub/1.0/nodeinfo2', 'top' ); } diff --git a/assets/css/admin.css b/assets/css/admin.css new file mode 100644 index 0000000..7210a02 --- /dev/null +++ b/assets/css/admin.css @@ -0,0 +1,46 @@ +.activitypub-settings-header { + text-align: center; + margin: 0 0 1rem; + background: #fff; + border-bottom: 1px solid #dcdcde; +} + +.activitypub-settings-title-section { + display: flex; + align-items: center; + justify-content: center; + clear: both; + padding-top: 8px; +} + +.settings_page_activitypub #wpcontent, +.settings_page_activitypub-settings #wpcontent { + padding-left: 0; +} + +.activitypub-settings-tabs-wrapper { + display: -ms-inline-grid; + -ms-grid-columns: 1fr 1fr; + vertical-align: top; + display: inline-grid; + grid-template-columns: 1fr 1fr; +} + +.activitypub-settings-tab.active { + box-shadow: inset 0 -3px #3582c4; + font-weight: 600; +} + +.activitypub-settings-tab { + display: block; + text-decoration: none; + color: inherit; + padding: .5rem 1rem 1rem; + margin: 0 1rem; + transition: box-shadow .5s ease-in-out; +} + +.wp-header-end { + visibility: hidden; + margin: -2px 0 0; +} diff --git a/includes/class-admin.php b/includes/class-admin.php index 9e1eedb..dd00350 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -14,21 +14,32 @@ class Admin { \add_action( 'admin_menu', array( '\Activitypub\Admin', 'admin_menu' ) ); \add_action( 'admin_init', array( '\Activitypub\Admin', 'register_settings' ) ); \add_action( 'show_user_profile', array( '\Activitypub\Admin', 'add_fediverse_profile' ) ); + \add_action( 'admin_enqueue_scripts', array( '\Activitypub\Admin', 'admin_style' ) ); } /** * Add admin menu entry */ public static function admin_menu() { - $settings_page = \add_options_page( - 'ActivityPub', + $settings_page = \add_submenu_page( + null, + 'ActivityPub Settings', 'ActivityPub', 'manage_options', - 'activitypub', + 'activitypub-settings', array( '\Activitypub\Admin', 'settings_page' ) ); + $welcome_page = \add_options_page( + 'Welcome', + 'ActivityPub', + 'manage_options', + 'activitypub', + array( '\Activitypub\Admin', 'welcome_page' ) + ); + \add_action( 'load-' . $settings_page, array( '\Activitypub\Admin', 'add_settings_help_tab' ) ); + \add_action( 'load-' . $welcome_page, array( '\Activitypub\Admin', 'add_settings_help_tab' ) ); $followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers (Fediverse)', 'activitypub' ), 'read', 'activitypub-followers-list', array( '\Activitypub\Admin', 'followers_list_page' ) ); @@ -42,6 +53,13 @@ class Admin { \load_template( \dirname( __FILE__ ) . '/../templates/settings.php' ); } + /** + * Load welcome page + */ + public static function welcome_page() { + \load_template( \dirname( __FILE__ ) . '/../templates/welcome.php' ); + } + /** * Load user settings page */ @@ -122,23 +140,7 @@ class Admin { } public static function add_settings_help_tab() { - \get_current_screen()->add_help_tab( - array( - 'id' => 'overview', - 'title' => \__( 'Overview', 'activitypub' ), - 'content' => - '

' . \__( 'ActivityPub is a decentralized social networking protocol based on the ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended standard published by the W3C Social Web Working Group. It provides a client to server API for creating, updating and deleting content, as well as a federated server to server API for delivering notifications and subscribing to content.', 'activitypub' ) . '

', - ) - ); - - \get_current_screen()->set_help_sidebar( - '

' . \__( 'For more information:', 'activitypub' ) . '

' . - '

' . \__( 'Test Suite', 'activitypub' ) . '

' . - '

' . \__( 'W3C Spec', 'activitypub' ) . '

' . - '

' . \__( 'Give us feedback', 'activitypub' ) . '

' . - '
' . - '

' . \__( 'Donate', 'activitypub' ) . '

' - ); + require_once \dirname( __FILE__ ) . '/help.php'; } public static function add_followers_list_help_tab() { @@ -147,8 +149,12 @@ class Admin { public static function add_fediverse_profile( $user ) { ?> -

+

ID ); } + + public static function admin_style() { + wp_enqueue_style( 'admin-styles', plugin_dir_url( __FILE__ ) . '../assets/css/admin.css' ); + } } diff --git a/includes/class-webfinger.php b/includes/class-webfinger.php new file mode 100644 index 0000000..659470e --- /dev/null +++ b/includes/class-webfinger.php @@ -0,0 +1,29 @@ +user_login . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST ); + } +} diff --git a/includes/functions.php b/includes/functions.php index 3c33664..8994256 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -95,14 +95,7 @@ function safe_remote_get( $url, $user_id ) { * @return string The user-resource */ function get_webfinger_resource( $user_id ) { - // use WebFinger plugin if installed - if ( \function_exists( '\get_webfinger_resource' ) ) { - return \get_webfinger_resource( $user_id, false ); - } - - $user = \get_user_by( 'id', $user_id ); - - return $user->user_login . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST ); + return \Activitypub\Webfinger::get_resource( $user_id ); } /** diff --git a/includes/help.php b/includes/help.php new file mode 100644 index 0000000..632b189 --- /dev/null +++ b/includes/help.php @@ -0,0 +1,56 @@ +add_help_tab( + array( + 'id' => 'fediverse', + 'title' => \__( 'Fediverse', 'activitypub' ), + 'content' => + '

' . \__( 'What is the Fediverse?', 'activitypub' ) . '

' . + '

' . \__( 'The Fediverse is a new word made of two words: "federation" + "universe"', 'activitypub' ) . '

' . + '

' . \__( 'It is a federated social network running on free open software on a myriad of computers across the globe. Many independent servers are interconnected and allow people to interact with one another. There\'s no one central site: you choose a server to register. This ensures some decentralization and sovereignty of data. Fediverse (also called Fedi) has no built-in advertisements, no tricky algorithms, no one big corporation dictating the rules. Instead we have small cozy communities of like-minded people. Welcome!', 'activitypub' ) . '

' . + '

' . \__( 'For more informations please visit fediverse.party', 'activitypub' ) . '

', + ) +); + +\get_current_screen()->add_help_tab( + array( + 'id' => 'activitypub', + 'title' => \__( 'ActivityPub', 'activitypub' ), + 'content' => + '

' . \__( 'What is ActivityPub?', 'activitypub' ) . '

' . + '

' . \__( 'ActivityPub is a decentralized social networking protocol based on the ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended standard published by the W3C Social Web Working Group. It provides a client to server API for creating, updating and deleting content, as well as a federated server to server API for delivering notifications and subscribing to content.', 'activitypub' ) . '

', + ) +); + +\get_current_screen()->add_help_tab( + array( + 'id' => 'webfinger', + 'title' => \__( 'WebFinger', 'activitypub' ), + 'content' => + '

' . \__( 'What is WebFinger?', 'activitypub' ) . '

' . + '

' . \__( 'WebFinger is used to discover information about people or other entities on the Internet that are identified by a URI using standard Hypertext Transfer Protocol (HTTP) methods over a secure transport. A WebFinger resource returns a JavaScript Object Notation (JSON) object describing the entity that is queried. The JSON object is referred to as the JSON Resource Descriptor (JRD).', 'activitypub' ) . '

' . + '

' . \__( 'For a person, the type of information that might be discoverable via WebFinger includes a personal profile address, identity service, telephone number, or preferred avatar. For other entities on the Internet, a WebFinger resource might return JRDs containing link relations that enable a client to discover, for example, that a printer can print in color on A4 paper, the physical location of a server, or other static information.', 'activitypub' ) . '

' . + '

' . \__( 'On Mastodon [and other Plattforms], user profiles can be hosted either locally on the same website as yours, or remotely on a completely different website. The same username may be used on a different domain. Therefore, a Mastodon user\'s full mention consists of both the username and the domain, in the form @username@domain. In practical terms, @user@example.com is not the same as @user@example.org. If the domain is not included, Mastodon will try to find a local user named @username. However, in order to deliver to someone over ActivityPub, the @username@domain mention is not enough – mentions must be translated to an HTTPS URI first, so that the remote actor\'s inbox and outbox can be found. (This paragraph is copied from the Mastodon Documentation)', 'activitypub' ) . '

' . + '

' . \__( 'For more informations please visit webfinger.net', 'activitypub' ) . '

', + ) +); + +\get_current_screen()->add_help_tab( + array( + 'id' => 'nodeinfo', + 'title' => \__( 'NodeInfo', 'activitypub' ), + 'content' => + '

' . \__( 'What is NodeInfo?', 'activitypub' ) . '

' . + '

' . \__( 'NodeInfo is an effort to create a standardized way of exposing metadata about a server running one of the distributed social networks. The two key goals are being able to get better insights into the user base of distributed social networking and the ability to build tools that allow users to choose the best fitting software and server for their needs.', 'activitypub' ) . '

' . + '

' . \__( 'For more informations please visit nodeinfo.diaspora.software', 'activitypub' ) . '

', + ) +); + +\get_current_screen()->set_help_sidebar( + '

' . \__( 'For more information:', 'activitypub' ) . '

' . + '

' . \__( 'Test Suite', 'activitypub' ) . '

' . + '

' . \__( 'W3C Spec', 'activitypub' ) . '

' . + '

' . \__( 'Give us feedback', 'activitypub' ) . '

' . + '
' . + '

' . \__( 'Donate', 'activitypub' ) . '

' +); diff --git a/includes/rest/class-nodeinfo.php b/includes/rest/class-nodeinfo.php index d4b394f..e2ae5b4 100644 --- a/includes/rest/class-nodeinfo.php +++ b/includes/rest/class-nodeinfo.php @@ -95,10 +95,6 @@ class Nodeinfo { 'outbound' => array(), ); - $nodeinfo['metadata'] = array( - 'email' => \get_option( 'admin_email' ), - ); - return new \WP_REST_Response( $nodeinfo, 200 ); } @@ -140,10 +136,6 @@ class Nodeinfo { 'outbound' => array(), ); - $nodeinfo['metadata'] = array( - 'email' => \get_option( 'admin_email' ), - ); - return new \WP_REST_Response( $nodeinfo, 200 ); } diff --git a/templates/admin-header.php b/templates/admin-header.php new file mode 100644 index 0000000..68d5e27 --- /dev/null +++ b/templates/admin-header.php @@ -0,0 +1,16 @@ +
+
+

ActivityPub

+
+ + +
+
diff --git a/templates/settings.php b/templates/settings.php index 5a4ba9d..6e8d980 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -1,12 +1,14 @@ -
-

+ 'active', 'welcome' => '' ) ); ?> -

+
+

+ +

-

+

@@ -104,7 +106,7 @@ -

+

@@ -127,8 +129,4 @@
- -

- donation?', 'activitypub' ); ?> -

diff --git a/templates/welcome.php b/templates/welcome.php new file mode 100644 index 0000000..ffff3e2 --- /dev/null +++ b/templates/welcome.php @@ -0,0 +1,23 @@ + '', 'welcome' => 'active' ) ); ?> + +
+

+ +

+

+ %s or the URL %s. Users, that can not access this settings page, will find their username on the Edit Profile page.', + 'activitypub' + ), + \Activitypub\get_webfinger_resource( wp_get_current_user()->ID ), + \get_author_posts_url( wp_get_current_user()->ID ), + \admin_url( 'profile.php#fediverse' ) + ); + ?> +

+

Site Health to ensure that your site is compatible and/or use the "Help" tab (in the top right of the settings pages).', 'activitypub' ), admin_url( '/wp-admin/site-health.php' ) ); ?>

+
+

Friends Plugin for WordPress which uses this plugin to receive posts and display them on your own WordPress, thus making your own WordPress a Mastodon instance of its own.', 'activitypub' ); ?>

+