Skip to content

Commit ebe2d43

Browse files
committed
better json encoding
1 parent fdad48e commit ebe2d43

File tree

8 files changed

+29
-21
lines changed

8 files changed

+29
-21
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
**Tags:** OStatus, fediverse, activitypub, activitystream
55
**Requires at least:** 4.7
66
**Tested up to:** 5.1.0
7-
**Stable tag:** 0.3.0
7+
**Stable tag:** 0.3.1
88
**Requires PHP:** 5.6
99
**License:** MIT
1010
**License URI:** http://opensource.org/licenses/MIT
@@ -55,11 +55,15 @@ To implement:
5555

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

58+
### 0.3.1 ###
59+
60+
* better json encoding
61+
5862
### 0.3.0 ###
5963

60-
* basic hashtag support
61-
* temporarily deactived likes and boosts
62-
* added support for actor objects
64+
* basic hashtag support
65+
* temporarily deactived likes and boosts
66+
* added support for actor objects
6367
* fixed encoding issue
6468

6569
### 0.2.1 ###

activitypub.php

Lines changed: 1 addition & 1 deletion
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.3.0
6+
* Version: 0.3.1
77
* Author: Matthias Pfefferle
88
* Author URI: https://notiz.blog/
99
* License: MIT

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(), JSON_UNESCAPED_UNICODE );
68+
return wp_json_encode( $this->to_array(), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT );
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(), JSON_UNESCAPED_UNICODE );
82+
return wp_json_encode( $this->to_simple_array(), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT );
8383
}
8484
}

includes/class-activitypub-post.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function to_array() {
4343
}
4444

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

4949
public function get_attachments() {
@@ -262,9 +262,9 @@ public function get_the_post_content( $with_link = true ) {
262262

263263
$decoded_content = html_entity_decode( $filtered_content, ENT_QUOTES, 'UTF-8' );
264264

265-
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a>' );
265+
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a><p>' );
266266

267-
return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $decoded_content, $allowed_html) ) );
267+
return trim( preg_replace( '/[\r\n]{2,}/', '', strip_tags( $decoded_content, $allowed_html) ) );
268268
}
269269

270270
/**
@@ -282,9 +282,9 @@ public function get_the_post_summary( $summary_length = 400 ) {
282282

283283
$decoded_summary = html_entity_decode( $filtered_summary, ENT_QUOTES, 'UTF-8' );
284284

285-
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a>' );
285+
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a><p>' );
286286

287-
return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $decoded_summary, $allowed_html) ) );
287+
return trim( preg_replace( '/[\r\n]{2,}/', '', strip_tags( $decoded_summary, $allowed_html) ) );
288288
}
289289

290290
public static function add_backlink( $content, $post ) {
@@ -296,6 +296,6 @@ public static function add_backlink( $content, $post ) {
296296
$link = esc_url( get_permalink( $post->ID ) );
297297
}
298298

299-
return $content . "\n\n" . '<a href="' . $link . '">' . $link . '</a>';
299+
return $content . '<p><a href="' . $link . '">' . $link . '</a></p>';
300300
}
301301
}

languages/activitypub.pot

Lines changed: 2 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.3.0\n"
5+
"Project-Id-Version: ActivityPub 0.3.1\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
7-
"POT-Creation-Date: 2019-02-02 22:55:56+00:00\n"
7+
"POT-Creation-Date: 2019-02-02 23:38:20+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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://notiz.blog/donate/
44
Tags: OStatus, fediverse, activitypub, activitystream
55
Requires at least: 4.7
66
Tested up to: 5.1.0
7-
Stable tag: 0.3.0
7+
Stable tag: 0.3.1
88
Requires PHP: 5.6
99
License: MIT
1010
License URI: http://opensource.org/licenses/MIT
@@ -55,11 +55,15 @@ To implement:
5555

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

58+
= 0.3.1 =
59+
60+
* better json encoding
61+
5862
= 0.3.0 =
5963

60-
* basic hashtag support
61-
* temporarily deactived likes and boosts
62-
* added support for actor objects
64+
* basic hashtag support
65+
* temporarily deactived likes and boosts
66+
* added support for actor objects
6367
* fixed encoding issue
6468

6569
= 0.2.1 =

templates/json-author.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
$options |= JSON_PRETTY_PRINT; // phpcs:ignore
9494
}
9595

96-
$options |= JSON_UNESCAPED_UNICODE;
96+
$options |= JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT;
9797

9898
/*
9999
* Options to be passed to json_encode()

templates/json-post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
$options |= JSON_PRETTY_PRINT; // phpcs:ignore
2020
}
2121

22-
$options |= JSON_UNESCAPED_UNICODE;
22+
$options |= JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT;
2323

2424
/*
2525
* Options to be passed to json_encode()

0 commit comments

Comments
 (0)