From 5200eb24636238657ce6177ebdd09b637577e849 Mon Sep 17 00:00:00 2001 From: Edward Ficklin Date: Tue, 14 Mar 2023 13:34:50 -0400 Subject: [PATCH 1/8] define const for fedi bio meta key --- activitypub.php | 1 + 1 file changed, 1 insertion(+) diff --git a/activitypub.php b/activitypub.php index b72901b..1a23d8d 100644 --- a/activitypub.php +++ b/activitypub.php @@ -25,6 +25,7 @@ function init() { \defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' ); \defined( 'ACTIVITYPUB_ALLOWED_HTML' ) || \define( 'ACTIVITYPUB_ALLOWED_HTML', '

    1. ' );
       	\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "

      [ap_title]

      \n\n[ap_content]\n\n

      [ap_hashtags]

      \n\n

      [ap_shortlink]

      " ); + \defined( 'ACTIVITYPUB_USER_DESCRIPTION_KEY' ) || \define( 'ACTIVITYPUB_USER_DESCRIPTION_KEY', 'activitypub_user_description' ); \define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); \define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); \define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) ); From 3ed96471de419114eb5606cd38d0bca34ddaff6e Mon Sep 17 00:00:00 2001 From: Edward Ficklin Date: Tue, 14 Mar 2023 13:36:12 -0400 Subject: [PATCH 2/8] add profile field and save handling for fediverse specific bio --- includes/class-admin.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/class-admin.php b/includes/class-admin.php index e98d547..4acef35 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -14,6 +14,7 @@ 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( 'personal_options_update', array( '\Activitypub\Admin', 'save_user_description' ) ); \add_action( 'admin_enqueue_scripts', array( '\Activitypub\Admin', 'enqueue_scripts' ) ); } @@ -153,10 +154,27 @@ class Admin { } public static function add_fediverse_profile( $user ) { + $ap_description = get_user_meta( $user->ID, ACTIVITYPUB_USER_DESCRIPTION_KEY, true ); ?>

      ID ); + ?> + + + + + + + Date: Tue, 14 Mar 2023 13:36:47 -0400 Subject: [PATCH 3/8] template helper function for displaying fedi bio, if set --- includes/functions.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/includes/functions.php b/includes/functions.php index 8f2e5d9..9b00e8f 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -320,3 +320,17 @@ function url_to_authorid( $url ) { return 0; } + +/** + * Return the custom Activity Pub description, if set, or default author description. + * + * @param int $user_id The user ID. + * @return string + */ +function get_author_description( $user_id ) { + $description = get_user_meta( $user_id, ACTIVITYPUB_USER_DESCRIPTION_KEY, true ); + if ( empty( $description ) ) { + $description = get_user_meta( $user_id, 'description', true ); + } + return $description; +} From 277c7ba10f4a83610f058b04e29da9f46121b377 Mon Sep 17 00:00:00 2001 From: Edward Ficklin Date: Tue, 14 Mar 2023 13:37:20 -0400 Subject: [PATCH 4/8] output fedi bio if set, default if not --- templates/author-json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/author-json.php b/templates/author-json.php index 1003989..3b355b9 100644 --- a/templates/author-json.php +++ b/templates/author-json.php @@ -8,7 +8,7 @@ $json->id = \get_author_posts_url( $author_id ); $json->type = 'Person'; $json->name = \get_the_author_meta( 'display_name', $author_id ); $json->summary = \html_entity_decode( - \get_the_author_meta( 'description', $author_id ), + \Activitypub\get_author_description( $author_id ), \ENT_QUOTES, 'UTF-8' ); From 8b92e9d47e8485189713ba0338127100fb479205 Mon Sep 17 00:00:00 2001 From: Edward Ficklin Date: Tue, 14 Mar 2023 20:35:14 -0400 Subject: [PATCH 5/8] escape output --- includes/class-admin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-admin.php b/includes/class-admin.php index 4acef35..c677246 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -162,9 +162,9 @@ class Admin { ?> - - + + Date: Tue, 14 Mar 2023 20:47:30 -0400 Subject: [PATCH 6/8] nonce verification --- includes/class-admin.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/class-admin.php b/includes/class-admin.php index c677246..8287259 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -165,12 +165,16 @@ class Admin {

      + Date: Fri, 28 Apr 2023 14:39:33 +0200 Subject: [PATCH 7/8] fix indents --- includes/class-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-admin.php b/includes/class-admin.php index f1f7df8..2b7ee2a 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -14,7 +14,7 @@ class Admin { \add_action( 'admin_menu', array( self::class, 'admin_menu' ) ); \add_action( 'admin_init', array( self::class, 'register_settings' ) ); \add_action( 'show_user_profile', array( self::class, 'add_fediverse_profile' ) ); - \add_action( 'personal_options_update', array( self::class, 'save_user_description' ) ); + \add_action( 'personal_options_update', array( self::class, 'save_user_description' ) ); \add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_scripts' ) ); } From 7c47f9a07c3640d06af0559a0a07ed159e88ab9c Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Fri, 28 Apr 2023 15:12:30 +0200 Subject: [PATCH 8/8] clean up admin settings --- includes/class-admin.php | 38 +++++++++++++++++-------------------- includes/functions.php | 19 ------------------- templates/user-settings.php | 29 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 40 deletions(-) create mode 100644 templates/user-settings.php diff --git a/includes/class-admin.php b/includes/class-admin.php index 2b7ee2a..66966f9 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -1,6 +1,8 @@ ID, ACTIVITYPUB_USER_DESCRIPTION_KEY, true ); - ?> -

      - ID ); - ?> - - - - - - - - ID, ACTIVITYPUB_USER_DESCRIPTION_KEY, true ); + + \load_template( + ACTIVITYPUB_PLUGIN_DIR . 'templates/user-settings.php', + true, + array( + 'description' => $description, + ) + ); } public static function save_user_description( $user_id ) { - if ( ! wp_verify_nonce( $_REQUEST['_apnonce'], 'activitypub-user-description' ) ) { + if ( isset( $_REQUEST['_apnonce'] ) && ! wp_verify_nonce( $_REQUEST['_apnonce'], 'activitypub-user-description' ) ) { return false; } if ( ! current_user_can( 'edit_user', $user_id ) ) { diff --git a/includes/functions.php b/includes/functions.php index a436496..4d44853 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -241,25 +241,6 @@ function get_follower_inboxes( $user_id, $cc = array() ) { return $inboxes; } -function get_identifier_settings( $user_id ) { - ?> - - - - - - - -
      - - -

      or

      - -

      -
      - + + + + + + + + + + + + + +
      + + +

      + or + +

      + +

      +
      + + + +

      +