fixed "excerpt" in AS JSON

This commit is contained in:
Matthias Pfefferle 2018-12-20 19:10:17 +01:00
parent 4e653f5f75
commit 1580b3d4b1
5 changed files with 61 additions and 20 deletions

View file

@ -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 ###

View file

@ -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 );
}

View file

@ -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 );
}

View file

@ -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"

View file

@ -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 =