content fixes

* added option to switch between content and excerpt
* removed html and duplicateded new-lines

fixes #6
This commit is contained in:
Matthias Pfefferle 2019-01-04 19:57:33 +01:00
parent be3fc9bb8d
commit b9e90829af
8 changed files with 145 additions and 86 deletions

View file

@ -4,7 +4,7 @@
**Tags:** OStatus, fediverse, activitypub, activitystream **Tags:** OStatus, fediverse, activitypub, activitystream
**Requires at least:** 4.7 **Requires at least:** 4.7
**Tested up to:** 5.0.2 **Tested up to:** 5.0.2
**Stable tag:** 0.1.1 **Stable tag:** 0.2.0
**Requires PHP:** 5.6 **Requires PHP:** 5.6
**License:** MIT **License:** MIT
**License URI:** http://opensource.org/licenses/MIT **License URI:** http://opensource.org/licenses/MIT
@ -59,6 +59,11 @@ To implement:
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
### 0.2.0 ###
* added option to switch between content and excerpt
* removed html and duplicateded new-lines
### 0.1.1 ### ### 0.1.1 ###
* fixed "excerpt" in AS JSON * fixed "excerpt" in AS JSON

View file

@ -3,7 +3,7 @@
* Plugin Name: ActivityPub * Plugin Name: ActivityPub
* Plugin URI: https://github.com/pfefferle/wordpress-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. * Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
* Version: 0.1.1 * Version: 0.2.0
* Author: Matthias Pfefferle * Author: Matthias Pfefferle
* Author URI: https://notiz.blog/ * Author URI: https://notiz.blog/
* License: MIT * License: MIT

View file

@ -30,10 +30,14 @@ class Activitypub_Admin {
*/ */
public static function register_settings() { public static function register_settings() {
register_setting( register_setting(
'activitypub', 'activitypub_add_summary', array( 'activitypub', 'activitypub_post_content_type', array(
'type' => 'boolean', 'type' => 'string',
'description' => __( 'Adds a "summary" to the Activity-Objects', 'activitypub' ), 'description' => __( 'Use summary or full content', 'activitypub' ),
'show_in_rest' => true, 'show_in_rest' => array(
'schema' => array(
'enum' => array( 'excerpt', 'content' )
),
),
'default' => 0, 'default' => 0,
) )
); );

View file

@ -27,11 +27,11 @@ class Activitypub_Post {
'type' => $this->get_object_type(), 'type' => $this->get_object_type(),
'published' => date( 'Y-m-d\TH:i:s\Z', strtotime( $post->post_date ) ), 'published' => date( 'Y-m-d\TH:i:s\Z', strtotime( $post->post_date ) ),
'attributedTo' => get_author_posts_url( $post->post_author ), 'attributedTo' => get_author_posts_url( $post->post_author ),
'summary' => get_option( 'activitypub_add_summary', false ) ? apply_filters( 'the_excerpt', activitypub_get_the_excerpt( $post->ID, 400 ) ) : null, 'summary' => null,
'inReplyTo' => null, 'inReplyTo' => null,
'content' => apply_filters( 'the_content', get_post_field( 'post_content', $post->ID ) ), 'content' => $this->get_the_content(),
'contentMap' => array( 'contentMap' => array(
strstr( get_locale(), '_', true ) => apply_filters( 'the_content', get_post_field( 'post_content', $post->ID ) ), strstr( get_locale(), '_', true ) => $this->get_the_content(),
), ),
'to' => array( 'https://www.w3.org/ns/activitystreams#Public' ), 'to' => array( 'https://www.w3.org/ns/activitystreams#Public' ),
'cc' => array( 'https://www.w3.org/ns/activitystreams#Public' ), 'cc' => array( 'https://www.w3.org/ns/activitystreams#Public' ),
@ -138,7 +138,7 @@ class Activitypub_Post {
* @return string the object-type * @return string the object-type
*/ */
public function get_object_type() { public function get_object_type() {
if ( get_option( 'activitypub_object_type', 'note' ) !== "wordpress-post-format" ) { if ( 'wordpress-post-format' !== get_option( 'activitypub_object_type', 'note' ) ) {
return ucfirst( get_option( 'activitypub_object_type', 'note' ) ); return ucfirst( get_option( 'activitypub_object_type', 'note' ) );
} }
@ -193,4 +193,72 @@ class Activitypub_Post {
return $object_type; return $object_type;
} }
public function get_the_content() {
if ( 'excerpt' === get_option( 'activitypub_post_content_type', 'excerpt' ) ) {
return $this->get_the_post_excerpt();
}
return $this->get_the_post_content();
}
/**
* Get the excerpt for a post for use outside of the loop.
*
* @param int Optional excerpt length.
*
* @return string The excerpt.
*/
public function get_the_post_excerpt( $excerpt_length = 400 ) {
$post = $this->post;
$excerpt = get_post_field( 'post_excerpt', $post );
if ( '' === $excerpt ) {
$content = get_post_field( 'post_content', $post );
// An empty string will make wp_trim_excerpt do stuff we do not want.
if ( '' !== $content ) {
$excerpt = strip_shortcodes( $content );
/** This filter is documented in wp-includes/post-template.php */
$excerpt = apply_filters( 'the_content', $excerpt );
$excerpt = str_replace( ']]>', ']]>', $excerpt );
$excerpt_length = apply_filters( 'excerpt_length', $excerpt_length );
/** This filter is documented in wp-includes/formatting.php */
$excerpt_more = apply_filters( 'excerpt_more', ' [...]' );
$excerpt = wp_trim_words( $excerpt, $excerpt_length, $excerpt_more );
}
}
$filtered_excerpt = apply_filters( 'the_excerpt', $excerpt );
$excerpt = $filtered_excerpt . "\n\n" . '<a rel="shortlink" href="' . esc_url( wp_get_shortlink( $this->post->ID ) ) . '">' . wp_get_shortlink( $this->post->ID ) . '</a>';
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a>' );
return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $excerpt, $allowed_html ) ) );
}
/**
* Get the content for a post for use outside of the loop.
*
* @return string The content.
*/
public function get_the_post_content() {
$post = $this->post;
$content = get_post_field( 'post_content', $post );
$filtered_content = apply_filters( 'the_content', $content );
$allowed_html = apply_filters( 'activitypub_allowed_html', '<a>' );
return trim( preg_replace( '/[\r\n]{2,}/', "\n\n", strip_tags( $filtered_content, $allowed_html ) ) );
}
} }

View file

@ -183,40 +183,3 @@ function activitypub_get_follower_inboxes( $user_id, $followers ) {
return array_unique( $inboxes ); return array_unique( $inboxes );
} }
/**
* Get the excerpt for a post for use outside of the loop.
*
* @param int|WP_Post $post ID or WP_Post object.
* @param int Optional excerpt length.
*
* @return string The excerpt.
*/
function activitypub_get_the_excerpt( $post, $excerpt_length = 55 ) {
$excerpt = get_post_field( 'post_excerpt', $post );
if ( '' === $excerpt ) {
$content = get_post_field( 'post_content', $post );
// An empty string will make wp_trim_excerpt do stuff we do not want.
if ( '' !== $content ) {
$excerpt = strip_shortcodes( $content );
/** This filter is documented in wp-includes/post-template.php */
$excerpt = apply_filters( 'the_content', $excerpt );
$excerpt = str_replace( ']]>', ']]>', $excerpt );
$excerpt_length = apply_filters( 'excerpt_length', $excerpt_length );
/** This filter is documented in wp-includes/formatting.php */
$excerpt_more = apply_filters( 'excerpt_more', ' […]' );
$excerpt = wp_trim_words( $excerpt, $excerpt_length, $excerpt_more );
}
}
return apply_filters( 'the_excerpt', $excerpt );
}

View file

@ -1,31 +1,31 @@
# Copyright (C) 2018 Matthias Pfefferle # Copyright (C) 2019 Matthias Pfefferle
# This file is distributed under the MIT. # This file is distributed under the MIT.
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: ActivityPub 0.1.1\n" "Project-Id-Version: ActivityPub 0.2.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
"POT-Creation-Date: 2018-12-30 10:41:44+00:00\n" "POT-Creation-Date: 2019-01-04 18:55:11+00:00\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n" "Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2018-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: 2019-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
"X-Generator: grunt-wp-i18n1.0.2\n" "X-Generator: grunt-wp-i18n1.0.2\n"
#: includes/class-activitypub-admin.php:35 #: includes/class-activitypub-admin.php:35
msgid "Adds a \"summary\" to the Activity-Objects" msgid "Use summary or full content"
msgstr "" msgstr ""
#: includes/class-activitypub-admin.php:43 #: includes/class-activitypub-admin.php:47
msgid "The Activity-Object-Type" msgid "The Activity-Object-Type"
msgstr "" msgstr ""
#: includes/class-activitypub-admin.php:58 #: includes/class-activitypub-admin.php:62
msgid "Overview" msgid "Overview"
msgstr "" msgstr ""
#: includes/class-activitypub-admin.php:60 #: includes/class-activitypub-admin.php:64
msgid "" msgid ""
"ActivityPub is a decentralized social networking protocol based on the " "ActivityPub is a decentralized social networking protocol based on the "
"ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended " "ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended "
@ -35,25 +35,25 @@ msgid ""
"subscribing to content." "subscribing to content."
msgstr "" msgstr ""
#: includes/class-activitypub-admin.php:65 #: includes/class-activitypub-admin.php:69
msgid "For more information:" msgid "For more information:"
msgstr "" msgstr ""
#: includes/class-activitypub-admin.php:66 #: includes/class-activitypub-admin.php:70
msgid "<a href=\"https://activitypub.rocks/\">Test Suite</a>" msgid "<a href=\"https://activitypub.rocks/\">Test Suite</a>"
msgstr "" msgstr ""
#: includes/class-activitypub-admin.php:67 #: includes/class-activitypub-admin.php:71
msgid "<a href=\"https://www.w3.org/TR/activitypub/\">W3C Spec</a>" msgid "<a href=\"https://www.w3.org/TR/activitypub/\">W3C Spec</a>"
msgstr "" msgstr ""
#: includes/class-activitypub-admin.php:68 #: includes/class-activitypub-admin.php:72
msgid "" msgid ""
"<a href=\"https://github.com/pfefferle/wordpress-activitypub/issues\">Give " "<a href=\"https://github.com/pfefferle/wordpress-activitypub/issues\">Give "
"us feedback</a>" "us feedback</a>"
msgstr "" msgstr ""
#: includes/class-activitypub-admin.php:70 #: includes/class-activitypub-admin.php:74
msgid "<a href=\"https://notiz.blog/donate\">Donate</a>" msgid "<a href=\"https://notiz.blog/donate\">Donate</a>"
msgstr "" msgstr ""
@ -108,7 +108,7 @@ msgstr ""
msgid "Blog" msgid "Blog"
msgstr "" msgstr ""
#: templates/json-author.php:58 templates/settings-page.php:45 #: templates/json-author.php:58 templates/settings-page.php:49
msgid "Profile" msgid "Profile"
msgstr "" msgstr ""
@ -136,74 +136,84 @@ msgid "All activity related settings."
msgstr "" msgstr ""
#: templates/settings-page.php:17 #: templates/settings-page.php:17
msgid "Add the Post-Summary" msgid "Post-Content"
msgstr "" msgstr ""
#: templates/settings-page.php:21 #: templates/settings-page.php:21
msgid "" msgid "Excerpt (default)"
"Adds the Post-Summary to the activity. Be aware, that Mastodon seems to use "
"the \"summary\" as the \"content warning\" label."
msgstr "" msgstr ""
#: templates/settings-page.php:26 #: templates/settings-page.php:21
msgid "A content summary, shortened to 400 characters and without markup."
msgstr ""
#: templates/settings-page.php:24
msgid "Content"
msgstr ""
#: templates/settings-page.php:24
msgid "The full content."
msgstr ""
#: templates/settings-page.php:30
msgid "Activtity-Object-Type" msgid "Activtity-Object-Type"
msgstr "" msgstr ""
#: templates/settings-page.php:30 #: templates/settings-page.php:34
msgid "Note (default)" msgid "Note (default)"
msgstr "" msgstr ""
#: templates/settings-page.php:30 #: templates/settings-page.php:34
msgid "Should work with most plattforms." msgid "Should work with most plattforms."
msgstr "" msgstr ""
#: templates/settings-page.php:33 #: templates/settings-page.php:37
msgid "Article" msgid "Article"
msgstr "" msgstr ""
#: templates/settings-page.php:33 #: templates/settings-page.php:37
msgid "" msgid ""
"The presentation of the \"Article\" might change on different plattforms. " "The presentation of the \"Article\" might change on different plattforms. "
"Mastodon for example shows the \"Article\" type as a simple link." "Mastodon for example shows the \"Article\" type as a simple link."
msgstr "" msgstr ""
#: templates/settings-page.php:36 #: templates/settings-page.php:40
msgid "WordPress Post-Format" msgid "WordPress Post-Format"
msgstr "" msgstr ""
#: templates/settings-page.php:36 #: templates/settings-page.php:40
msgid "Maps the WordPress Post-Format to the ActivityPub Object Type." msgid "Maps the WordPress Post-Format to the ActivityPub Object Type."
msgstr "" msgstr ""
#: templates/settings-page.php:47 #: templates/settings-page.php:51
msgid "All profile related settings." msgid "All profile related settings."
msgstr "" msgstr ""
#: templates/settings-page.php:53 #: templates/settings-page.php:57
msgid "Profile identifier" msgid "Profile identifier"
msgstr "" msgstr ""
#: templates/settings-page.php:57 #: templates/settings-page.php:61
msgid "Try to follow \"@%s\" in the mastodon/friendi.ca search field." msgid "Try to follow \"@%s\" in the mastodon/friendi.ca search field."
msgstr "" msgstr ""
#: templates/settings-page.php:65 #: templates/settings-page.php:69
msgid "Followers" msgid "Followers"
msgstr "" msgstr ""
#: templates/settings-page.php:67 #: templates/settings-page.php:71
msgid "All follower related settings." msgid "All follower related settings."
msgstr "" msgstr ""
#: templates/settings-page.php:73 #: templates/settings-page.php:77
msgid "List of followers" msgid "List of followers"
msgstr "" msgstr ""
#: templates/settings-page.php:83 #: templates/settings-page.php:87
msgid "No followers yet" msgid "No followers yet"
msgstr "" msgstr ""
#: templates/settings-page.php:98 #: templates/settings-page.php:102
msgid "" msgid ""
"If you like this plugin, what about a small <a " "If you like this plugin, what about a small <a "
"href=\"https://notiz.blog/donate\">donation</a>?" "href=\"https://notiz.blog/donate\">donation</a>?"

View file

@ -4,7 +4,7 @@ Donate link: https://notiz.blog/donate/
Tags: OStatus, fediverse, activitypub, activitystream Tags: OStatus, fediverse, activitypub, activitystream
Requires at least: 4.7 Requires at least: 4.7
Tested up to: 5.0.2 Tested up to: 5.0.2
Stable tag: 0.1.1 Stable tag: 0.2.0
Requires PHP: 5.6 Requires PHP: 5.6
License: MIT License: MIT
License URI: http://opensource.org/licenses/MIT License URI: http://opensource.org/licenses/MIT
@ -59,6 +59,11 @@ To implement:
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
= 0.2.0 =
* added option to switch between content and excerpt
* removed html and duplicateded new-lines
= 0.1.1 = = 0.1.1 =
* fixed "excerpt" in AS JSON * fixed "excerpt" in AS JSON

View file

@ -14,11 +14,15 @@
<tbody> <tbody>
<tr> <tr>
<th scope="row"> <th scope="row">
<label for="activitypub_add_summary"><?php esc_html_e( 'Add the Post-Summary', 'activitypub' ); ?></label> <?php esc_html_e( 'Post-Content', 'activitypub' ); ?>
</th> </th>
<td> <td>
<input type="checkbox" name="activitypub_add_summary" id="activitypub_add_summary" value="1" <?php echo checked( true, get_option( 'activitypub_add_summary', false ) ); ?> /> <p>
<?php printf( __( 'Adds the Post-Summary to the activity. Be aware, that Mastodon seems to use the "summary" as the "content warning" label.', 'activitypub' ) ); ?> <label><input type="radio" name="activitypub_post_content_type" id="activitypub_post_content_type_excerpt" value="excerpt" <?php echo checked( 'excerpt', get_option( 'activitypub_post_content_type', 'excerpt' ) ); ?> /> <?php esc_html_e( 'Excerpt (default)', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'A content summary, shortened to 400 characters and without markup.', 'activitypub' ); ?></span>
</p>
<p>
<label><input type="radio" name="activitypub_post_content_type" id="activitypub_post_content_type_content" value="content" <?php echo checked( 'content', get_option( 'activitypub_post_content_type', 'excerpt' ) ); ?> /> <?php esc_html_e( 'Content', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'The full content.', 'activitypub' ); ?></span>
</p>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -27,10 +31,10 @@
</th> </th>
<td> <td>
<p> <p>
<label><input type="radio" name="activitypub_object_type" id="activitypub_object_type" value="note" <?php echo checked( 'note', get_option( 'activitypub_object_type', 'note' ) ); ?> /> <?php esc_html_e( 'Note (default)', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'Should work with most plattforms.', 'activitypub' ); ?></span> <label><input type="radio" name="activitypub_object_type" id="activitypub_object_type_note" value="note" <?php echo checked( 'note', get_option( 'activitypub_object_type', 'note' ) ); ?> /> <?php esc_html_e( 'Note (default)', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'Should work with most plattforms.', 'activitypub' ); ?></span>
</p> </p>
<p> <p>
<label><input type="radio" name="activitypub_object_type" id="activitypub_object_type" value="article" <?php echo checked( 'article', get_option( 'activitypub_object_type', 'note' ) ); ?> /> <?php esc_html_e( 'Article', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'The presentation of the "Article" might change on different plattforms. Mastodon for example shows the "Article" type as a simple link.', 'activitypub' ); ?></span> <label><input type="radio" name="activitypub_object_type" id="activitypub_object_type_article" value="article" <?php echo checked( 'article', get_option( 'activitypub_object_type', 'note' ) ); ?> /> <?php esc_html_e( 'Article', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'The presentation of the "Article" might change on different plattforms. Mastodon for example shows the "Article" type as a simple link.', 'activitypub' ); ?></span>
</p> </p>
<p> <p>
<label><input type="radio" name="activitypub_object_type" id="activitypub_object_type" value="wordpress-post-format" <?php echo checked( 'wordpress-post-format', get_option( 'activitypub_object_type', 'note' ) ); ?> /> <?php esc_html_e( 'WordPress Post-Format', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'Maps the WordPress Post-Format to the ActivityPub Object Type.', 'activitypub' ); ?></span> <label><input type="radio" name="activitypub_object_type" id="activitypub_object_type" value="wordpress-post-format" <?php echo checked( 'wordpress-post-format', get_option( 'activitypub_object_type', 'note' ) ); ?> /> <?php esc_html_e( 'WordPress Post-Format', 'activitypub' ); ?> - <span class="description"><?php esc_html_e( 'Maps the WordPress Post-Format to the ActivityPub Object Type.', 'activitypub' ); ?></span>