Skip to content

Commit

Permalink
better json encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle committed Feb 2, 2019
1 parent fdad48e commit ebe2d43
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 21 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
**Tags:** OStatus, fediverse, activitypub, activitystream
**Requires at least:** 4.7
**Tested up to:** 5.1.0
**Stable tag:** 0.3.0
**Stable tag:** 0.3.1
**Requires PHP:** 5.6
**License:** MIT
**License URI:** http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -55,11 +55,15 @@ To implement:

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

### 0.3.1 ###

* better json encoding

### 0.3.0 ###

* basic hashtag support
* temporarily deactived likes and boosts
* added support for actor objects
* basic hashtag support
* temporarily deactived likes and boosts
* added support for actor objects
* fixed encoding issue

### 0.2.1 ###
Expand Down
2 changes: 1 addition & 1 deletion activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: ActivityPub
* Plugin URI: https://github.com/pfefferle/wordpress-activitypub/
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
* Version: 0.3.0
* Version: 0.3.1
* Author: Matthias Pfefferle
* Author URI: https://notiz.blog/
* License: MIT
Expand Down
4 changes: 2 additions & 2 deletions includes/class-activitypub-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function to_array() {
}

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

public function to_simple_array() {
Expand All @@ -79,6 +79,6 @@ public function to_simple_array() {
}

public function to_simple_json() {
return wp_json_encode( $this->to_simple_array(), JSON_UNESCAPED_UNICODE );
return wp_json_encode( $this->to_simple_array(), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT );
}
}
12 changes: 6 additions & 6 deletions includes/class-activitypub-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function to_array() {
}

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

public function get_attachments() {
Expand Down Expand Up @@ -262,9 +262,9 @@ public function get_the_post_content( $with_link = true ) {

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

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

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

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

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

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

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

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

return $content . "\n\n" . '<a href="' . $link . '">' . $link . '</a>';
return $content . '<p><a href="' . $link . '">' . $link . '</a></p>';
}
}
4 changes: 2 additions & 2 deletions languages/activitypub.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# This file is distributed under the MIT.
msgid ""
msgstr ""
"Project-Id-Version: ActivityPub 0.3.0\n"
"Project-Id-Version: ActivityPub 0.3.1\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
"POT-Creation-Date: 2019-02-02 22:55:56+00:00\n"
"POT-Creation-Date: 2019-02-02 23:38:20+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
12 changes: 8 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://notiz.blog/donate/
Tags: OStatus, fediverse, activitypub, activitystream
Requires at least: 4.7
Tested up to: 5.1.0
Stable tag: 0.3.0
Stable tag: 0.3.1
Requires PHP: 5.6
License: MIT
License URI: http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -55,11 +55,15 @@ To implement:

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

= 0.3.1 =

* better json encoding

= 0.3.0 =

* basic hashtag support
* temporarily deactived likes and boosts
* added support for actor objects
* basic hashtag support
* temporarily deactived likes and boosts
* added support for actor objects
* fixed encoding issue

= 0.2.1 =
Expand Down
2 changes: 1 addition & 1 deletion templates/json-author.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
$options |= JSON_PRETTY_PRINT; // phpcs:ignore
}

$options |= JSON_UNESCAPED_UNICODE;
$options |= JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT;

/*
* Options to be passed to json_encode()
Expand Down
2 changes: 1 addition & 1 deletion templates/json-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$options |= JSON_PRETTY_PRINT; // phpcs:ignore
}

$options |= JSON_UNESCAPED_UNICODE;
$options |= JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT;

/*
* Options to be passed to json_encode()
Expand Down

0 comments on commit ebe2d43

Please sign in to comment.