Skip to content

Commit 1580b3d

Browse files
committed
fixed "excerpt" in AS JSON
1 parent 4e653f5 commit 1580b3d

File tree

5 files changed

+61
-20
lines changed

5 files changed

+61
-20
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ Implemented:
2626
* profile pages (JSON representation)
2727
* custom links
2828
* functional inbox/outbox
29-
* follow (accept follows)
30-
* share posts
29+
* follow (accept follows)
30+
* share posts
3131
* receive comments/reactions
3232

3333
To implement:
3434

35-
* signature verification
36-
* better WordPress integration
37-
* better configuration possibilities
35+
* signature verification
36+
* better WordPress integration
37+
* better configuration possibilities
3838
* threaded comments support
3939

4040
### Why does the plugin not support ...? ###
@@ -59,12 +59,16 @@ To implement:
5959

6060
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
6161

62+
### 0.1.1 ###
63+
64+
* fixed "excerpt" in AS JSON
65+
6266
### 0.1.0 ###
6367

6468
* added basic WebFinger support
6569
* added basic NodeInfo support
66-
* fully functional "follow" activity
67-
* send new posts to your followers
70+
* fully functional "follow" activity
71+
* send new posts to your followers
6872
* receive comments from your followers
6973

7074
### 0.0.2 ###

includes/class-activitypub-post.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ public function get_post_author() {
2222
public function to_array() {
2323
$post = $this->post;
2424

25-
setup_postdata( $post );
26-
2725
$array = array(
2826
'id' => get_permalink( $post ),
2927
'type' => $this->get_object_type(),
3028
'published' => date( 'Y-m-d\TH:i:s\Z', strtotime( $post->post_date ) ),
3129
'attributedTo' => get_author_posts_url( $post->post_author ),
32-
'summary' => apply_filters( 'the_excerpt', get_post_field( 'post_excerpt', $post->ID ) ),
30+
'summary' => apply_filters( 'the_excerpt', activitypub_get_the_excerpt( $post->ID, 400 ) ),
3331
'inReplyTo' => null,
3432
'content' => apply_filters( 'the_content', get_post_field( 'post_content', $post->ID ) ),
3533
'contentMap' => array(
@@ -41,8 +39,6 @@ public function to_array() {
4139
'tag' => $this->get_tags(),
4240
);
4341

44-
wp_reset_postdata();
45-
4642
return apply_filters( 'activitypub_post', $array );
4743
}
4844

includes/functions.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,40 @@ function activitypub_get_follower_inboxes( $user_id, $followers ) {
183183

184184
return array_unique( $inboxes );
185185
}
186+
187+
/**
188+
* Get the excerpt for a post for use outside of the loop.
189+
*
190+
* @param int|WP_Post $post ID or WP_Post object.
191+
* @param int Optional excerpt length.
192+
*
193+
* @return string The excerpt.
194+
*/
195+
function activitypub_get_the_excerpt( $post, $excerpt_length = 55 ) {
196+
197+
$excerpt = get_post_field( 'post_excerpt', $post );
198+
199+
if ( '' === $excerpt ) {
200+
201+
$content = get_post_field( 'post_content', $post );
202+
203+
// An empty string will make wp_trim_excerpt do stuff we do not want.
204+
if ( '' !== $content ) {
205+
206+
$excerpt = strip_shortcodes( $content );
207+
208+
/** This filter is documented in wp-includes/post-template.php */
209+
$excerpt = apply_filters( 'the_content', $excerpt );
210+
$excerpt = str_replace( ']]>', ']]>', $excerpt );
211+
212+
$excerpt_length = apply_filters( 'excerpt_length', $excerpt_length );
213+
214+
/** This filter is documented in wp-includes/formatting.php */
215+
$excerpt_more = apply_filters( 'excerpt_more', ' […]' );
216+
217+
$excerpt = wp_trim_words( $excerpt, $excerpt_length, $excerpt_more );
218+
}
219+
}
220+
221+
return apply_filters( 'the_excerpt', $excerpt );
222+
}

languages/activitypub.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ msgid ""
44
msgstr ""
55
"Project-Id-Version: ActivityPub 0.1.0\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
7-
"POT-Creation-Date: 2018-12-20 10:32:52+00:00\n"
7+
"POT-Creation-Date: 2018-12-20 18:09:57+00:00\n"
88
"MIME-Version: 1.0\n"
99
"Content-Type: text/plain; charset=utf-8\n"
1010
"Content-Transfer-Encoding: 8bit\n"

readme.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ Implemented:
2626
* profile pages (JSON representation)
2727
* custom links
2828
* functional inbox/outbox
29-
* follow (accept follows)
30-
* share posts
29+
* follow (accept follows)
30+
* share posts
3131
* receive comments/reactions
3232

3333
To implement:
3434

35-
* signature verification
36-
* better WordPress integration
37-
* better configuration possibilities
35+
* signature verification
36+
* better WordPress integration
37+
* better configuration possibilities
3838
* threaded comments support
3939

4040
= Why does the plugin not support ...? =
@@ -59,12 +59,16 @@ To implement:
5959

6060
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
6161

62+
= 0.1.1 =
63+
64+
* fixed "excerpt" in AS JSON
65+
6266
= 0.1.0 =
6367

6468
* added basic WebFinger support
6569
* added basic NodeInfo support
66-
* fully functional "follow" activity
67-
* send new posts to your followers
70+
* fully functional "follow" activity
71+
* send new posts to your followers
6872
* receive comments from your followers
6973

7074
= 0.0.2 =

0 commit comments

Comments
 (0)