From ebe2d434c687156688b17bd8c215f6e95de0f11c Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Sun, 3 Feb 2019 00:44:01 +0100 Subject: [PATCH] better json encoding --- README.md | 12 ++++++++---- activitypub.php | 2 +- includes/class-activitypub-activity.php | 4 ++-- includes/class-activitypub-post.php | 12 ++++++------ languages/activitypub.pot | 4 ++-- readme.txt | 12 ++++++++---- templates/json-author.php | 2 +- templates/json-post.php | 2 +- 8 files changed, 29 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 9b5f18b..16999e6 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ### diff --git a/activitypub.php b/activitypub.php index c6d85bd..8e7665c 100644 --- a/activitypub.php +++ b/activitypub.php @@ -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 diff --git a/includes/class-activitypub-activity.php b/includes/class-activitypub-activity.php index d6182bc..8fb13c9 100644 --- a/includes/class-activitypub-activity.php +++ b/includes/class-activitypub-activity.php @@ -65,7 +65,7 @@ class Activitypub_Activity { } 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() { @@ -79,6 +79,6 @@ class Activitypub_Activity { } 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 ); } } diff --git a/includes/class-activitypub-post.php b/includes/class-activitypub-post.php index d4da38d..e7d9f7c 100644 --- a/includes/class-activitypub-post.php +++ b/includes/class-activitypub-post.php @@ -43,7 +43,7 @@ class Activitypub_Post { } 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() { @@ -262,9 +262,9 @@ class Activitypub_Post { $decoded_content = html_entity_decode( $filtered_content, ENT_QUOTES, 'UTF-8' ); - $allowed_html = apply_filters( 'activitypub_allowed_html', '' ); + $allowed_html = apply_filters( 'activitypub_allowed_html', '

' ); - 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) ) ); } /** @@ -282,9 +282,9 @@ class Activitypub_Post { $decoded_summary = html_entity_decode( $filtered_summary, ENT_QUOTES, 'UTF-8' ); - $allowed_html = apply_filters( 'activitypub_allowed_html', '' ); + $allowed_html = apply_filters( 'activitypub_allowed_html', '

' ); - 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 ) { @@ -296,6 +296,6 @@ class Activitypub_Post { $link = esc_url( get_permalink( $post->ID ) ); } - return $content . "\n\n" . '' . $link . ''; + return $content . '

' . $link . '

'; } } diff --git a/languages/activitypub.pot b/languages/activitypub.pot index 3dfc702..29f01e7 100644 --- a/languages/activitypub.pot +++ b/languages/activitypub.pot @@ -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" diff --git a/readme.txt b/readme.txt index 5b14f93..fd941ff 100644 --- a/readme.txt +++ b/readme.txt @@ -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 @@ -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 = diff --git a/templates/json-author.php b/templates/json-author.php index 809deb4..fcd6fc6 100644 --- a/templates/json-author.php +++ b/templates/json-author.php @@ -93,7 +93,7 @@ if ( get_query_var( 'pretty' ) ) { $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() diff --git a/templates/json-post.php b/templates/json-post.php index 38a4cdb..e600270 100644 --- a/templates/json-post.php +++ b/templates/json-post.php @@ -19,7 +19,7 @@ if ( get_query_var( 'pretty' ) ) { $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()