diff --git a/README.md b/README.md index 65361e1..05c7fc8 100644 --- a/README.md +++ b/README.md @@ -26,15 +26,15 @@ Implemented: * profile pages (JSON representation) * custom links * functional inbox/outbox -* follow (accept follows) -* share posts +* follow (accept follows) +* share posts * receive comments/reactions To implement: -* signature verification -* better WordPress integration -* better configuration possibilities +* signature verification +* better WordPress integration +* better configuration possibilities * threaded comments support ### Why does the plugin not support ...? ### @@ -59,12 +59,16 @@ To implement: Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). +### 0.1.1 ### + +* fixed "excerpt" in AS JSON + ### 0.1.0 ### * added basic WebFinger support * added basic NodeInfo support -* fully functional "follow" activity -* send new posts to your followers +* fully functional "follow" activity +* send new posts to your followers * receive comments from your followers ### 0.0.2 ### diff --git a/includes/class-activitypub-post.php b/includes/class-activitypub-post.php index 09f545a..cd4c181 100644 --- a/includes/class-activitypub-post.php +++ b/includes/class-activitypub-post.php @@ -22,14 +22,12 @@ class Activitypub_Post { public function to_array() { $post = $this->post; - setup_postdata( $post ); - $array = array( 'id' => get_permalink( $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' => apply_filters( 'the_excerpt', get_post_field( 'post_excerpt', $post->ID ) ), + 'summary' => apply_filters( 'the_excerpt', activitypub_get_the_excerpt( $post->ID, 400 ) ), 'inReplyTo' => null, 'content' => apply_filters( 'the_content', get_post_field( 'post_content', $post->ID ) ), 'contentMap' => array( @@ -41,8 +39,6 @@ class Activitypub_Post { 'tag' => $this->get_tags(), ); - wp_reset_postdata(); - return apply_filters( 'activitypub_post', $array ); } diff --git a/includes/functions.php b/includes/functions.php index cf95860..20e4964 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -183,3 +183,40 @@ function activitypub_get_follower_inboxes( $user_id, $followers ) { return array_unique( $inboxes ); } + +/** + * Get the excerpt for a post for use outside of the loop. + * + * @param int|WP_Post $post ID or WP_Post object. + * @param int Optional excerpt length. + * + * @return string The excerpt. + */ +function activitypub_get_the_excerpt( $post, $excerpt_length = 55 ) { + + $excerpt = get_post_field( 'post_excerpt', $post ); + + if ( '' === $excerpt ) { + + $content = get_post_field( 'post_content', $post ); + + // An empty string will make wp_trim_excerpt do stuff we do not want. + if ( '' !== $content ) { + + $excerpt = strip_shortcodes( $content ); + + /** This filter is documented in wp-includes/post-template.php */ + $excerpt = apply_filters( 'the_content', $excerpt ); + $excerpt = str_replace( ']]>', ']]>', $excerpt ); + + $excerpt_length = apply_filters( 'excerpt_length', $excerpt_length ); + + /** This filter is documented in wp-includes/formatting.php */ + $excerpt_more = apply_filters( 'excerpt_more', ' […]' ); + + $excerpt = wp_trim_words( $excerpt, $excerpt_length, $excerpt_more ); + } + } + + return apply_filters( 'the_excerpt', $excerpt ); +} diff --git a/languages/activitypub.pot b/languages/activitypub.pot index c027d48..7e4c8bb 100644 --- a/languages/activitypub.pot +++ b/languages/activitypub.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: ActivityPub 0.1.0\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n" -"POT-Creation-Date: 2018-12-20 10:32:52+00:00\n" +"POT-Creation-Date: 2018-12-20 18:09:57+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" diff --git a/readme.txt b/readme.txt index 755a8ef..e59b174 100644 --- a/readme.txt +++ b/readme.txt @@ -26,15 +26,15 @@ Implemented: * profile pages (JSON representation) * custom links * functional inbox/outbox -* follow (accept follows) -* share posts +* follow (accept follows) +* share posts * receive comments/reactions To implement: -* signature verification -* better WordPress integration -* better configuration possibilities +* signature verification +* better WordPress integration +* better configuration possibilities * threaded comments support = Why does the plugin not support ...? = @@ -59,12 +59,16 @@ To implement: Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). += 0.1.1 = + +* fixed "excerpt" in AS JSON + = 0.1.0 = * added basic WebFinger support * added basic NodeInfo support -* fully functional "follow" activity -* send new posts to your followers +* fully functional "follow" activity +* send new posts to your followers * receive comments from your followers = 0.0.2 =