From e8d2508f5d97f847c94be612260278c2576448e9 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 16 Jan 2019 21:50:45 +0100 Subject: [PATCH] nicer profile and customizable backlink * customizable backlink URL #18 * fixes #12 --- activitypub.php | 1 + includes/class-activitypub-admin.php | 30 +++++++++++++++++------- includes/class-activitypub-post.php | 32 +++++++++++++++++++++---- includes/functions.php | 18 ++++++++++++++ templates/settings-page.php | 35 ++++++++++++++-------------- 5 files changed, 85 insertions(+), 31 deletions(-) diff --git a/activitypub.php b/activitypub.php index 5ecf1fe..abc84cc 100644 --- a/activitypub.php +++ b/activitypub.php @@ -64,6 +64,7 @@ function activitypub_init() { require_once dirname( __FILE__ ) . '/includes/class-activitypub-admin.php'; 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( 'plugins_loaded', 'activitypub_init' ); diff --git a/includes/class-activitypub-admin.php b/includes/class-activitypub-admin.php index 2702ffc..8af226d 100644 --- a/includes/class-activitypub-admin.php +++ b/includes/class-activitypub-admin.php @@ -31,26 +31,33 @@ class Activitypub_Admin { public static function register_settings() { register_setting( 'activitypub', 'activitypub_post_content_type', array( - 'type' => 'string', - 'description' => __( 'Use summary or full content', 'activitypub' ), + 'type' => 'string', + 'description' => __( 'Use summary or full content', 'activitypub' ), 'show_in_rest' => array( 'schema' => array( - 'enum' => array( 'excerpt', 'content' ) + 'enum' => array( 'excerpt', 'content' ), ), ), - 'default' => 0, + 'default' => 'excerpt', ) ); register_setting( 'activitypub', 'activitypub_object_type', array( - 'type' => 'string', - 'description' => __( 'The Activity-Object-Type', 'activitypub' ), + 'type' => 'string', + 'description' => __( 'The Activity-Object-Type', 'activitypub' ), 'show_in_rest' => array( 'schema' => array( - 'enum' => array( 'note', 'article', 'wordpress-post-format' ) + 'enum' => array( 'note', 'article', 'wordpress-post-format' ), ), ), - 'default' => 'note', + 'default' => 'note', + ) + ); + register_setting( + 'activitypub', 'activitypub_use_shortlink', array( + 'type' => 'boolean', + 'description' => __( 'Use the Shortlink instead of the permalink', 'activitypub' ), + 'default' => 0, ) ); } @@ -74,4 +81,11 @@ class Activitypub_Admin { '

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

' ); } + + public static function add_fediverse_profile( $user ) { + ?> +

+ ID ); + } } diff --git a/includes/class-activitypub-post.php b/includes/class-activitypub-post.php index e4e6dc7..02d06df 100644 --- a/includes/class-activitypub-post.php +++ b/includes/class-activitypub-post.php @@ -27,7 +27,7 @@ class Activitypub_Post { 'type' => $this->get_object_type(), 'published' => date( 'Y-m-d\TH:i:s\Z', strtotime( $post->post_date ) ), 'attributedTo' => get_author_posts_url( $post->post_author ), - 'summary' => null, + 'summary' => ( $this->get_object_type() == 'Article' ) ? $this->get_the_post_excerpt( 400, false ) : null, 'inReplyTo' => null, 'content' => $this->get_the_content(), 'contentMap' => array( @@ -209,7 +209,7 @@ class Activitypub_Post { * * @return string The excerpt. */ - public function get_the_post_excerpt( $excerpt_length = 400 ) { + public function get_the_post_excerpt( $excerpt_length = 400, $with_link = true ) { $post = $this->post; $excerpt = get_post_field( 'post_excerpt', $post ); @@ -238,11 +238,21 @@ class Activitypub_Post { $filtered_excerpt = apply_filters( 'the_excerpt', $excerpt ); - $excerpt = $filtered_excerpt . "\n\n" . '' . wp_get_shortlink( $this->post->ID ) . ''; + if ( $with_link ) { + $link = ''; + + if ( get_option( 'activitypub_use_shortlink', 0 ) ) { + $link = esc_url( wp_get_shortlink( $this->post->ID ) ); + } else { + $link = esc_url( get_permalink( $this->post->ID ) ); + } + + $filtered_excerpt = $filtered_excerpt . "\n\n" . '' . $link . ''; + } $allowed_html = apply_filters( 'activitypub_allowed_html', '' ); - return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $excerpt, $allowed_html ) ) ); + return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $filtered_excerpt, $allowed_html ) ) ); } /** @@ -250,13 +260,25 @@ class Activitypub_Post { * * @return string The content. */ - public function get_the_post_content() { + public function get_the_post_content( $with_link = true ) { $post = $this->post; $content = get_post_field( 'post_content', $post ); $filtered_content = apply_filters( 'the_content', $content ); + if ( $with_link ) { + $link = ''; + + if ( get_option( 'activitypub_use_shortlink', 0 ) ) { + $link = esc_url( wp_get_shortlink( $this->post->ID ) ); + } else { + $link = esc_url( get_permalink( $this->post->ID ) ); + } + + $filtered_content = $filtered_content . "\n\n" . '' . $link . ''; + } + $allowed_html = apply_filters( 'activitypub_allowed_html', '' ); return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $filtered_content, $allowed_html ) ) ); diff --git a/includes/functions.php b/includes/functions.php index cf95860..76984cc 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -183,3 +183,21 @@ function activitypub_get_follower_inboxes( $user_id, $followers ) { return array_unique( $inboxes ); } + +function activitypub_get_identifier_settings( $user_id ) { + ?> + + + + + + + +
+ + +

or

+

+
+

-

-

+ + + + + + + +

+ +

', '' ); ?>

@@ -31,13 +42,13 @@

-

-

-

@@ -50,19 +61,7 @@

- - - - - - - -
- - -

or

-

-
+