@@ -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}
0 commit comments