Skip to content

Commit fdad48e

Browse files
committed
0.3.0
1 parent a5463e1 commit fdad48e

File tree

9 files changed

+89
-43
lines changed

9 files changed

+89
-43
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
**Donate link:** https://notiz.blog/donate/
44
**Tags:** OStatus, fediverse, activitypub, activitystream
55
**Requires at least:** 4.7
6-
**Tested up to:** 5.0.3
7-
**Stable tag:** 0.2.1
6+
**Tested up to:** 5.1.0
7+
**Stable tag:** 0.3.0
88
**Requires PHP:** 5.6
99
**License:** MIT
1010
**License URI:** http://opensource.org/licenses/MIT
@@ -58,7 +58,9 @@ Project maintained on github at [pfefferle/wordpress-activitypub](https://github
5858
### 0.3.0 ###
5959

6060
* basic hashtag support
61-
* temporarily deactived likes and boosts
61+
* temporarily deactived likes and boosts
62+
* added support for actor objects
63+
* fixed encoding issue
6264

6365
### 0.2.1 ###
6466

activitypub.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: ActivityPub
44
* Plugin URI: https://github.com/pfefferle/wordpress-activitypub/
55
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
6-
* Version: 0.2.1
6+
* Version: 0.3.0
77
* Author: Matthias Pfefferle
88
* Author URI: https://notiz.blog/
99
* License: MIT
@@ -19,11 +19,14 @@ function activitypub_init() {
1919
defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(^|\s|>)#([^\s<>]+)\b' );
2020

2121
require_once dirname( __FILE__ ) . '/includes/class-activitypub-signature.php';
22-
require_once dirname( __FILE__ ) . '/includes/class-activitypub-post.php';
2322
require_once dirname( __FILE__ ) . '/includes/class-activitypub-activity.php';
2423
require_once dirname( __FILE__ ) . '/includes/class-db-activitypub-followers.php';
2524
require_once dirname( __FILE__ ) . '/includes/functions.php';
2625

26+
require_once dirname( __FILE__ ) . '/includes/class-activitypub-post.php';
27+
add_filter( 'activitypub_the_excerpt', array( 'Activitypub_Post', 'add_backlink' ), 10, 2 );
28+
add_filter( 'activitypub_the_content', array( 'Activitypub_Post', 'add_backlink' ), 10, 2 );
29+
2730
require_once dirname( __FILE__ ) . '/includes/class-activitypub.php';
2831
add_filter( 'template_include', array( 'Activitypub', 'render_json_template' ), 99 );
2932
add_filter( 'query_vars', array( 'Activitypub', 'add_query_vars' ) );

includes/class-activitypub-activity.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function to_array() {
6565
}
6666

6767
public function to_json() {
68-
return wp_json_encode( $this->to_array() );
68+
return wp_json_encode( $this->to_array(), JSON_UNESCAPED_UNICODE );
6969
}
7070

7171
public function to_simple_array() {
@@ -79,6 +79,6 @@ public function to_simple_array() {
7979
}
8080

8181
public function to_simple_json() {
82-
return wp_json_encode( $this->to_simple_array() );
82+
return wp_json_encode( $this->to_simple_array(), JSON_UNESCAPED_UNICODE );
8383
}
8484
}

includes/class-activitypub-post.php

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function to_array() {
2727
'type' => $this->get_object_type(),
2828
'published' => date( 'Y-m-d\TH:i:s\Z', strtotime( $post->post_date ) ),
2929
'attributedTo' => get_author_posts_url( $post->post_author ),
30-
'summary' => ( $this->get_object_type() == 'Article' ) ? $this->get_the_post_excerpt( 400, false ) : null,
30+
'summary' => $this->get_the_summary(),
3131
'inReplyTo' => null,
3232
'content' => $this->get_the_content(),
3333
'contentMap' => array(
@@ -43,7 +43,7 @@ public function to_array() {
4343
}
4444

4545
public function to_json() {
46-
return wp_json_encode( $this->to_array() );
46+
return wp_json_encode( $this->to_array(), JSON_UNESCAPED_UNICODE );
4747
}
4848

4949
public function get_attachments() {
@@ -196,20 +196,28 @@ public function get_object_type() {
196196

197197
public function get_the_content() {
198198
if ( 'excerpt' === get_option( 'activitypub_post_content_type', 'excerpt' ) ) {
199-
return $this->get_the_post_excerpt();
199+
return $this->get_the_post_summary();
200200
}
201201

202202
return $this->get_the_post_content();
203203
}
204204

205+
public function get_the_summary() {
206+
if ( 'Article' === $this->get_object_type() ) {
207+
return $this->get_the_post_excerpt( 400 );
208+
}
209+
210+
return null;
211+
}
212+
205213
/**
206214
* Get the excerpt for a post for use outside of the loop.
207215
*
208216
* @param int Optional excerpt length.
209217
*
210218
* @return string The excerpt.
211219
*/
212-
public function get_the_post_excerpt( $excerpt_length = 400, $with_link = true ) {
220+
public function get_the_post_excerpt( $excerpt_length = 400 ) {
213221
$post = $this->post;
214222

215223
$excerpt = get_post_field( 'post_excerpt', $post );
@@ -236,23 +244,7 @@ public function get_the_post_excerpt( $excerpt_length = 400, $with_link = true )
236244
}
237245
}
238246

239-
$filtered_excerpt = apply_filters( 'the_excerpt', $excerpt );
240-
241-
if ( $with_link ) {
242-
$link = '';
243-
244-
if ( get_option( 'activitypub_use_shortlink', 0 ) ) {
245-
$link = esc_url( wp_get_shortlink( $this->post->ID ) );
246-
} else {
247-
$link = esc_url( get_permalink( $this->post->ID ) );
248-
}
249-
250-
$filtered_excerpt = $filtered_excerpt . "\n\n" . '<a href="' . $link . '">' . $link . '</a>';
251-
}
252-
253-
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a>' );
254-
255-
return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $filtered_excerpt, $allowed_html ) ) );
247+
return html_entity_decode( $excerpt, ENT_QUOTES, 'UTF-8' );
256248
}
257249

258250
/**
@@ -266,21 +258,44 @@ public function get_the_post_content( $with_link = true ) {
266258
$content = get_post_field( 'post_content', $post );
267259

268260
$filtered_content = apply_filters( 'the_content', $content );
261+
$filtered_content = apply_filters( 'activitypub_the_content', $filtered_content, $this->post );
269262

270-
if ( $with_link ) {
271-
$link = '';
263+
$decoded_content = html_entity_decode( $filtered_content, ENT_QUOTES, 'UTF-8' );
272264

273-
if ( get_option( 'activitypub_use_shortlink', 0 ) ) {
274-
$link = esc_url( wp_get_shortlink( $this->post->ID ) );
275-
} else {
276-
$link = esc_url( get_permalink( $this->post->ID ) );
277-
}
265+
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a>' );
278266

279-
$filtered_content = $filtered_content . "\n\n" . '<a href="' . $link . '">' . $link . '</a>';
280-
}
267+
return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $decoded_content, $allowed_html) ) );
268+
}
269+
270+
/**
271+
* Get the excerpt for a post for use outside of the loop.
272+
*
273+
* @param int Optional excerpt length.
274+
*
275+
* @return string The excerpt.
276+
*/
277+
public function get_the_post_summary( $summary_length = 400 ) {
278+
$summary = $this->get_the_post_excerpt( $summary_length );
279+
280+
$filtered_summary = apply_filters( 'the_excerpt', $summary );
281+
$filtered_summary = apply_filters( 'activitypub_the_summary', $filtered_summary, $this->post );
282+
283+
$decoded_summary = html_entity_decode( $filtered_summary, ENT_QUOTES, 'UTF-8' );
281284

282285
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a>' );
283286

284-
return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $filtered_content, $allowed_html ) ) );
287+
return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $decoded_summary, $allowed_html) ) );
288+
}
289+
290+
public static function add_backlink( $content, $post ) {
291+
$link = '';
292+
293+
if ( get_option( 'activitypub_use_shortlink', 0 ) ) {
294+
$link = esc_url( wp_get_shortlink( $post->ID ) );
295+
} else {
296+
$link = esc_url( get_permalink( $post->ID ) );
297+
}
298+
299+
return $content . "\n\n" . '<a href="' . $link . '">' . $link . '</a>';
285300
}
286301
}

includes/class-db-activitypub-followers.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ public static function get_followers( $author_id ) {
99
public static function add_follower( $actor, $author_id ) {
1010
$followers = get_user_option( 'activitypub_followers', $author_id );
1111

12+
if ( ! is_string( $actor ) ) {
13+
if (
14+
is_array( $actor ) &&
15+
isset( $actor['type'] ) &&
16+
'Person' === $actor['type'] &&
17+
isset( $actor['id'] ) &&
18+
true === filter_var( $actor['id'], FILTER_VALIDATE_URL )
19+
) {
20+
$actor = $actor['id'];
21+
}
22+
23+
return new WP_Error( 'invalid_actor_object', __( 'Unknown Actor schema', 'activitypub' ), array(
24+
'status' => 404
25+
) );
26+
}
27+
1228
if ( ! is_array( $followers ) ) {
1329
$followers = array( $actor );
1430
} else {

languages/activitypub.pot

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# This file is distributed under the MIT.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: ActivityPub 0.2.1\n"
5+
"Project-Id-Version: ActivityPub 0.3.0\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
7-
"POT-Creation-Date: 2019-01-22 20:17:45+00:00\n"
7+
"POT-Creation-Date: 2019-02-02 22:55:56+00:00\n"
88
"MIME-Version: 1.0\n"
99
"Content-Type: text/plain; charset=utf-8\n"
1010
"Content-Transfer-Encoding: 8bit\n"
@@ -65,6 +65,10 @@ msgstr ""
6565
msgid "Fediverse"
6666
msgstr ""
6767

68+
#: includes/class-db-activitypub-followers.php:23
69+
msgid "Unknown Actor schema"
70+
msgstr ""
71+
6872
#: includes/class-rest-activitypub-followers.php:24
6973
#: includes/class-rest-activitypub-followers.php:26
7074
#: includes/class-rest-activitypub-outbox.php:35

readme.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Contributors: pfefferle
33
Donate link: https://notiz.blog/donate/
44
Tags: OStatus, fediverse, activitypub, activitystream
55
Requires at least: 4.7
6-
Tested up to: 5.0.3
7-
Stable tag: 0.2.1
6+
Tested up to: 5.1.0
7+
Stable tag: 0.3.0
88
Requires PHP: 5.6
99
License: MIT
1010
License URI: http://opensource.org/licenses/MIT
@@ -58,7 +58,9 @@ Project maintained on github at [pfefferle/wordpress-activitypub](https://github
5858
= 0.3.0 =
5959

6060
* basic hashtag support
61-
* temporarily deactived likes and boosts
61+
* temporarily deactived likes and boosts
62+
* added support for actor objects
63+
* fixed encoding issue
6264

6365
= 0.2.1 =
6466

templates/json-author.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
$options |= JSON_PRETTY_PRINT; // phpcs:ignore
9494
}
9595

96+
$options |= JSON_UNESCAPED_UNICODE;
97+
9698
/*
9799
* Options to be passed to json_encode()
98100
*

templates/json-post.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
$options |= JSON_PRETTY_PRINT; // phpcs:ignore
2020
}
2121

22+
$options |= JSON_UNESCAPED_UNICODE;
23+
2224
/*
2325
* Options to be passed to json_encode()
2426
*

0 commit comments

Comments
 (0)