Skip to content

Commit

Permalink
content fixes
Browse files Browse the repository at this point in the history
* added option to switch between content and excerpt
* removed html and duplicateded new-lines

fixes #6
  • Loading branch information
pfefferle committed Jan 4, 2019
1 parent be3fc9b commit b9e9082
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 86 deletions.
7 changes: 6 additions & 1 deletion 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.0.2
**Stable tag:** 0.1.1
**Stable tag:** 0.2.0
**Requires PHP:** 5.6
**License:** MIT
**License URI:** http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -59,6 +59,11 @@ To implement:

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 ###

* fixed "excerpt" in AS JSON
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.1.1
* Version: 0.2.0
* Author: Matthias Pfefferle
* Author URI: https://notiz.blog/
* License: MIT
Expand Down
12 changes: 8 additions & 4 deletions includes/class-activitypub-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ public static function settings_page() {
*/
public static function register_settings() {
register_setting(
'activitypub', 'activitypub_add_summary', array(
'type' => 'boolean',
'description' => __( 'Adds a "summary" to the Activity-Objects', 'activitypub' ),
'show_in_rest' => true,
'activitypub', 'activitypub_post_content_type', array(
'type' => 'string',
'description' => __( 'Use summary or full content', 'activitypub' ),
'show_in_rest' => array(
'schema' => array(
'enum' => array( 'excerpt', 'content' )
),
),
'default' => 0,
)
);
Expand Down
76 changes: 72 additions & 4 deletions includes/class-activitypub-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function to_array() {
'type' => $this->get_object_type(),
'published' => date( 'Y-m-d\TH:i:s\Z', strtotime( $post->post_date ) ),
'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,
'content' => apply_filters( 'the_content', get_post_field( 'post_content', $post->ID ) ),
'content' => $this->get_the_content(),
'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' ),
'cc' => array( 'https://www.w3.org/ns/activitystreams#Public' ),
Expand Down Expand Up @@ -138,7 +138,7 @@ public function get_tags() {
* @return string the 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' ) );
}

Expand Down Expand Up @@ -193,4 +193,72 @@ public function get_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 ) ) );
}
}
37 changes: 0 additions & 37 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,40 +183,3 @@ function activitypub_get_follower_inboxes( $user_id, $followers ) {

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 );
}
76 changes: 43 additions & 33 deletions languages/activitypub.pot
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# Copyright (C) 2018 Matthias Pfefferle
# Copyright (C) 2019 Matthias Pfefferle
# This file is distributed under the MIT.
msgid ""
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"
"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"
"Content-Type: text/plain; charset=utf-8\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"
"Language-Team: LANGUAGE <LL@li.org>\n"
"X-Generator: grunt-wp-i18n1.0.2\n"

#: includes/class-activitypub-admin.php:35
msgid "Adds a \"summary\" to the Activity-Objects"
msgid "Use summary or full content"
msgstr ""

#: includes/class-activitypub-admin.php:43
#: includes/class-activitypub-admin.php:47
msgid "The Activity-Object-Type"
msgstr ""

#: includes/class-activitypub-admin.php:58
#: includes/class-activitypub-admin.php:62
msgid "Overview"
msgstr ""

#: includes/class-activitypub-admin.php:60
#: includes/class-activitypub-admin.php:64
msgid ""
"ActivityPub is a decentralized social networking protocol based on the "
"ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended "
Expand All @@ -35,25 +35,25 @@ msgid ""
"subscribing to content."
msgstr ""

#: includes/class-activitypub-admin.php:65
#: includes/class-activitypub-admin.php:69
msgid "For more information:"
msgstr ""

#: includes/class-activitypub-admin.php:66
#: includes/class-activitypub-admin.php:70
msgid "<a href=\"https://activitypub.rocks/\">Test Suite</a>"
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>"
msgstr ""

#: includes/class-activitypub-admin.php:68
#: includes/class-activitypub-admin.php:72
msgid ""
"<a href=\"https://github.com/pfefferle/wordpress-activitypub/issues\">Give "
"us feedback</a>"
msgstr ""

#: includes/class-activitypub-admin.php:70
#: includes/class-activitypub-admin.php:74
msgid "<a href=\"https://notiz.blog/donate\">Donate</a>"
msgstr ""

Expand Down Expand Up @@ -108,7 +108,7 @@ msgstr ""
msgid "Blog"
msgstr ""

#: templates/json-author.php:58 templates/settings-page.php:45
#: templates/json-author.php:58 templates/settings-page.php:49
msgid "Profile"
msgstr ""

Expand Down Expand Up @@ -136,74 +136,84 @@ msgid "All activity related settings."
msgstr ""

#: templates/settings-page.php:17
msgid "Add the Post-Summary"
msgid "Post-Content"
msgstr ""

#: templates/settings-page.php:21
msgid ""
"Adds the Post-Summary to the activity. Be aware, that Mastodon seems to use "
"the \"summary\" as the \"content warning\" label."
msgid "Excerpt (default)"
msgstr ""

#: templates/settings-page.php:26
msgid "Activtity-Object-Type"
#: 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"
msgstr ""

#: templates/settings-page.php:34
msgid "Note (default)"
msgstr ""

#: templates/settings-page.php:30
#: templates/settings-page.php:34
msgid "Should work with most plattforms."
msgstr ""

#: templates/settings-page.php:33
#: templates/settings-page.php:37
msgid "Article"
msgstr ""

#: templates/settings-page.php:33
#: templates/settings-page.php:37
msgid ""
"The presentation of the \"Article\" might change on different plattforms. "
"Mastodon for example shows the \"Article\" type as a simple link."
msgstr ""

#: templates/settings-page.php:36
#: templates/settings-page.php:40
msgid "WordPress Post-Format"
msgstr ""

#: templates/settings-page.php:36
#: templates/settings-page.php:40
msgid "Maps the WordPress Post-Format to the ActivityPub Object Type."
msgstr ""

#: templates/settings-page.php:47
#: templates/settings-page.php:51
msgid "All profile related settings."
msgstr ""

#: templates/settings-page.php:53
#: templates/settings-page.php:57
msgid "Profile identifier"
msgstr ""

#: templates/settings-page.php:57
#: templates/settings-page.php:61
msgid "Try to follow \"@%s\" in the mastodon/friendi.ca search field."
msgstr ""

#: templates/settings-page.php:65
#: templates/settings-page.php:69
msgid "Followers"
msgstr ""

#: templates/settings-page.php:67
#: templates/settings-page.php:71
msgid "All follower related settings."
msgstr ""

#: templates/settings-page.php:73
#: templates/settings-page.php:77
msgid "List of followers"
msgstr ""

#: templates/settings-page.php:83
#: templates/settings-page.php:87
msgid "No followers yet"
msgstr ""

#: templates/settings-page.php:98
#: templates/settings-page.php:102
msgid ""
"If you like this plugin, what about a small <a "
"href=\"https://notiz.blog/donate\">donation</a>?"
Expand Down
7 changes: 6 additions & 1 deletion 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.0.2
Stable tag: 0.1.1
Stable tag: 0.2.0
Requires PHP: 5.6
License: MIT
License URI: http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -59,6 +59,11 @@ To implement:

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 =

* fixed "excerpt" in AS JSON
Expand Down
Loading

0 comments on commit b9e9082

Please sign in to comment.