Merge branch 'master' into Comments
This commit is contained in:
commit
7e6c112679
11 changed files with 80 additions and 96 deletions
|
@ -22,6 +22,8 @@ bin
|
|||
composer.json
|
||||
composer.lock
|
||||
docker-compose.yml
|
||||
docker-compose-test.yml
|
||||
Dockerfile
|
||||
gulpfile.js
|
||||
package.json
|
||||
node_modules
|
||||
|
|
19
README.md
19
README.md
|
@ -4,7 +4,7 @@
|
|||
**Tags:** OStatus, fediverse, activitypub, activitystream
|
||||
**Requires at least:** 4.7
|
||||
**Tested up to:** 6.1
|
||||
**Stable tag:** 0.15.0
|
||||
**Stable tag:** 0.16.2
|
||||
**Requires PHP:** 5.6
|
||||
**License:** MIT
|
||||
**License URI:** http://opensource.org/licenses/MIT
|
||||
|
@ -88,9 +88,22 @@ Where 'blog' is the path to the subdirectory at which your blog resides.
|
|||
|
||||
Project maintained on GitHub at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
|
||||
|
||||
### v.next ###
|
||||
### 0.16.2 ###
|
||||
|
||||
* Add configuration item for number of images to attach. props [@mexon](https://github.com/mexon)
|
||||
* Fix fatal error in outbox
|
||||
|
||||
### 0.16.1 ###
|
||||
|
||||
* Fix "update and create, posts appear blank on Mastodon" issue
|
||||
|
||||
### 0.16.0 ###
|
||||
|
||||
* Add "Outgoing Mentions" ([#213](https://github.com/pfefferle/wordpress-activitypub/pull/213)) props [@akirk](https://github.com/akirk)
|
||||
* Add configuration item for number of images to attach ([#248](https://github.com/pfefferle/wordpress-activitypub/pull/248)) props [@mexon](https://github.com/mexon)
|
||||
* Use shortcodes instead of custom templates, to setup the Activity Post-Content ([#250](https://github.com/pfefferle/wordpress-activitypub/pull/250)) props [@toolstack](https://github.com/toolstack)
|
||||
* Remove custom REST Server, because the needed changes are now merged into Core.
|
||||
* Fix hashtags ([#261](https://github.com/pfefferle/wordpress-activitypub/pull/261)) props [@akirk](https://github.com/akirk)
|
||||
* Change priorites, to maybe fix the hashtag issue
|
||||
|
||||
### 0.15.0 ###
|
||||
|
||||
|
|
|
@ -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.15.0
|
||||
* Version: 0.16.2
|
||||
* Author: Matthias Pfefferle
|
||||
* Author URI: https://notiz.blog/
|
||||
* License: MIT
|
||||
|
@ -90,14 +90,6 @@ function init() {
|
|||
require_once \dirname( __FILE__ ) . '/includes/class-health-check.php';
|
||||
\Activitypub\Health_Check::init();
|
||||
|
||||
require_once \dirname( __FILE__ ) . '/includes/rest/class-server.php';
|
||||
\add_filter(
|
||||
'wp_rest_server_class',
|
||||
function() {
|
||||
return '\Activitypub\Rest\Server';
|
||||
}
|
||||
);
|
||||
|
||||
if ( \WP_DEBUG ) {
|
||||
require_once \dirname( __FILE__ ) . '/includes/debug.php';
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ class Activity_Dispatcher {
|
|||
$updated = \wp_date( 'Y-m-d\TH:i:s\Z', \strtotime( $activitypub_post->get_updated() ) );
|
||||
|
||||
$activitypub_activity = new \Activitypub\Model\Activity( 'Update', \Activitypub\Model\Activity::TYPE_FULL );
|
||||
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
||||
$activitypub_activity->from_post( $activitypub_post );
|
||||
|
||||
foreach ( \Activitypub\get_follower_inboxes( $user_id ) as $inbox => $to ) {
|
||||
$activitypub_activity->set_to( $to );
|
||||
|
@ -125,12 +125,9 @@ class Activity_Dispatcher {
|
|||
public static function send_delete_activity( $activitypub_post ) {
|
||||
// get latest version of post
|
||||
$user_id = $activitypub_post->get_post_author();
|
||||
$deleted = \current_time( 'Y-m-d\TH:i:s\Z', true );
|
||||
$activitypub_post->set_deleted( $deleted );
|
||||
|
||||
$activitypub_activity = new \Activitypub\Model\Activity( 'Delete', \Activitypub\Model\Activity::TYPE_FULL );
|
||||
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
||||
$activitypub_activity->set_deleted( $deleted );
|
||||
$activitypub_activity->from_post( $activitypub_post );
|
||||
|
||||
foreach ( \Activitypub\get_follower_inboxes( $user_id ) as $inbox => $to ) {
|
||||
$activitypub_activity->set_to( $to );
|
||||
|
|
|
@ -191,9 +191,23 @@ class Shortcodes {
|
|||
return '';
|
||||
}
|
||||
|
||||
$atts = shortcode_atts(
|
||||
array( 'apply_filters' => 'yes' ),
|
||||
$atts,
|
||||
$tag
|
||||
);
|
||||
|
||||
$content = \get_post_field( 'post_content', $post );
|
||||
|
||||
return \apply_filters( 'the_content', $content );
|
||||
if ( 'yes' === $atts['apply_filters'] ) {
|
||||
$content = \apply_filters( 'the_content', $content );
|
||||
} else {
|
||||
$content = do_blocks( $content );
|
||||
$content = wptexturize( $content );
|
||||
$content = wp_filter_content_tags( $content );
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
'<dl>' .
|
||||
'<dt><code>[ap_title]</code></dt>' .
|
||||
'<dd>' . \wp_kses( __( 'The post\'s title.', 'activitypub' ), 'default' ) . '</dd>' .
|
||||
'<dt><code>[ap_content]</code></dt>' .
|
||||
'<dd>' . \wp_kses( __( 'The post\'s content.', 'activitypub' ), 'default' ) . '</dd>' .
|
||||
'<dt><code>[ap_content apply_filters="yes"]</code></dt>' .
|
||||
'<dd>' . \wp_kses( __( 'The post\'s content. With <code>apply_filters</code> you can decide if filters should be applied or not (default is <code>yes</code>). The values can be <code>yes</code> or <code>no</code>. <code>apply_filters</code> attribute is optional.', 'activitypub' ), 'default' ) . '</dd>' .
|
||||
'<dt><code>[ap_excerpt lenght="400"]</code></dt>' .
|
||||
'<dd>' . \wp_kses( __( 'The post\'s excerpt (default 400 chars). <code>length</code> attribute is optional.', 'activitypub' ), 'default' ) . '</dd>' .
|
||||
'<dt><code>[ap_permalink type="url"]</code></dt>' .
|
||||
'<dd>' . \wp_kses( __( 'The post\'s permalink. Type can be either: <code>url</code> or <code>html</code> (an <a /> tag). <code>type</code> attribute is optional.', 'activitypub' ), 'default' ) . '</dd>' .
|
||||
'<dd>' . \wp_kses( __( 'The post\'s permalink. <code>type</code> can be either: <code>url</code> or <code>html</code> (an <a /> tag). <code>type</code> attribute is optional.', 'activitypub' ), 'default' ) . '</dd>' .
|
||||
'<dt><code>[ap_shortlink type="url"]</code></dt>' .
|
||||
'<dd>' . \wp_kses( __( 'The post\'s shortlink. Type can be either <code>url</code> or <code>html</code> (an <a /> tag). I can recommend <a href="https://wordpress.org/plugins/hum/" target="_blank">Hum</a>, to prettify the Shortlinks. <code>type</code> attribute is optional.', 'activitypub' ), 'default' ) . '</dd>' .
|
||||
'<dd>' . \wp_kses( __( 'The post\'s shortlink. <code>type</code> can be either <code>url</code> or <code>html</code> (an <a /> tag). I can recommend <a href="https://wordpress.org/plugins/hum/" target="_blank">Hum</a>, to prettify the Shortlinks. <code>type</code> attribute is optional.', 'activitypub' ), 'default' ) . '</dd>' .
|
||||
'<dt><code>[ap_hashtags]</code></dt>' .
|
||||
'<dd>' . \wp_kses( __( 'The post\'s tags as hashtags.', 'activitypub' ), 'default' ) . '</dd>' .
|
||||
'<dt><code>[ap_hashcats]</code></dt>' .
|
||||
|
|
|
@ -148,17 +148,17 @@ class Post {
|
|||
'attachment' => $this->get_attachments(),
|
||||
'tag' => $this->get_tags(),
|
||||
);
|
||||
if ( $this->replies ) {
|
||||
$array['replies'] = $this->replies;
|
||||
if ( $this->replies ) { //has comments
|
||||
$array['replies'] = $this->get_replies();
|
||||
}
|
||||
if ( $this->deleted ) {
|
||||
if ( $this->deleted ) { //is trash
|
||||
$array['deleted'] = \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_modified_gmt ) );
|
||||
$deleted_post_slug = \get_post_meta( $post->ID, 'activitypub_canonical_url', true );
|
||||
if ( $deleted_post_slug ) {
|
||||
$array['id'] = $deleted_post_slug;
|
||||
}
|
||||
}
|
||||
if ( $this->updated ) {
|
||||
if ( $this->updated ) { //post_modified
|
||||
$array['updated'] = \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_modified_gmt ) );
|
||||
}
|
||||
return \apply_filters( 'activitypub_post', $array );
|
||||
|
@ -188,7 +188,7 @@ class Post {
|
|||
if ( 'trash' === get_post_status( $post ) && \get_post_meta( $post->ID, 'activitypub_canonical_url', true ) ) {
|
||||
$object_id = \get_post_meta( $post->ID, 'activitypub_canonical_url', true );
|
||||
} else {
|
||||
$object_id = \add_query_arg( //
|
||||
$object_id = \add_query_arg(
|
||||
array(
|
||||
'p' => $post->ID,
|
||||
),
|
||||
|
@ -317,7 +317,11 @@ class Post {
|
|||
return $tags;
|
||||
}
|
||||
|
||||
public function generate_replies() {
|
||||
public function get_replies() {
|
||||
if ( $this->replies ) {
|
||||
return $this->replies;
|
||||
}
|
||||
|
||||
$replies = null;
|
||||
if ( $this->post->comment_count > 0 ) {
|
||||
$args = array(
|
||||
|
@ -358,6 +362,9 @@ class Post {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
$this->replies = $replies;
|
||||
|
||||
return $replies;
|
||||
}
|
||||
|
||||
|
@ -435,11 +442,14 @@ class Post {
|
|||
* @return string the content
|
||||
*/
|
||||
public function get_content() {
|
||||
global $post;
|
||||
|
||||
if ( $this->content ) {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
$post = $this->post;
|
||||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
$post = $this->post;
|
||||
$content = $this->get_post_content_template();
|
||||
|
||||
// Fill in the shortcodes.
|
||||
|
@ -452,7 +462,7 @@ class Post {
|
|||
$filtered_content = \apply_filters( 'activitypub_the_content', $content, $post );
|
||||
$decoded_content = \html_entity_decode( $filtered_content, \ENT_QUOTES, 'UTF-8' );
|
||||
|
||||
$content = \trim( \preg_replace( '/[\n\r]/', '', $content ) );
|
||||
$content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) );
|
||||
|
||||
$this->content = $content;
|
||||
|
||||
|
@ -522,31 +532,6 @@ class Post {
|
|||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all tags as hashtags to the post/summary content
|
||||
*
|
||||
* @param string $content
|
||||
* @param WP_Post $post
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_the_mentions() {
|
||||
$post = $this->post;
|
||||
$tags = \get_the_tags( $post->ID );
|
||||
|
||||
if ( ! $tags ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$hash_tags = array();
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
$hash_tags[] = \sprintf( '<a rel="tag" class="u-tag u-category" href="%s">#%s</a>', \get_tag_link( $tag ), $tag->slug );
|
||||
}
|
||||
|
||||
return \implode( ' ', $hash_tags );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get deleted datetime
|
||||
*/
|
||||
|
@ -554,7 +539,7 @@ class Post {
|
|||
$post = $this->post;
|
||||
$deleted = null;
|
||||
if ( 'trash' === $post->post_status ) {
|
||||
$deleted = \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_modified_gmt ) );
|
||||
$this->deleted = \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_modified_gmt ) );
|
||||
}
|
||||
return $deleted;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ class Outbox {
|
|||
foreach ( $posts as $post ) {
|
||||
$activitypub_post = new \Activitypub\Model\Post( $post );
|
||||
$activitypub_activity = new \Activitypub\Model\Activity( 'Create', \Activitypub\Model\Activity::TYPE_NONE );
|
||||
$activitypub_activity->from_post( $activitypub_post->to_array() );
|
||||
$activitypub_activity->from_post( $activitypub_post );
|
||||
$json->orderedItems[] = $activitypub_activity->to_array(); // phpcs:ignore
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
namespace Activitypub\Rest;
|
||||
|
||||
/**
|
||||
* Custom (hopefully temporary) ActivityPub Rest Server
|
||||
*
|
||||
* @author Matthias Pfefferle
|
||||
*/
|
||||
class Server extends \WP_REST_Server {
|
||||
/**
|
||||
* Overwrite dispatch function to quick fix missing subtype featur
|
||||
*
|
||||
* @see https://core.trac.wordpress.org/ticket/49404
|
||||
*
|
||||
* @param WP_REST_Request $request Request to attempt dispatching.
|
||||
* @return WP_REST_Response Response returned by the callback.
|
||||
*/
|
||||
public function dispatch( $request ) {
|
||||
$content_type = $request->get_content_type();
|
||||
|
||||
if ( ! $content_type ) {
|
||||
return parent::dispatch( $request );
|
||||
}
|
||||
|
||||
// check for content-sub-types like 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
|
||||
if ( \preg_match( '/application\/([a-zA-Z+_-]+\+)json/', $content_type['value'] ) ) {
|
||||
$request->set_header( 'Content-Type', 'application/json' );
|
||||
}
|
||||
|
||||
// make request filterable
|
||||
$request = \apply_filters( 'activitypub_pre_dispatch_request', $request );
|
||||
|
||||
return parent::dispatch( $request );
|
||||
}
|
||||
}
|
20
readme.txt
20
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: 6.1
|
||||
Stable tag: 0.15.0
|
||||
Stable tag: 0.16.2
|
||||
Requires PHP: 5.6
|
||||
License: MIT
|
||||
License URI: http://opensource.org/licenses/MIT
|
||||
|
@ -88,10 +88,22 @@ Where 'blog' is the path to the subdirectory at which your blog resides.
|
|||
|
||||
Project maintained on GitHub at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
|
||||
|
||||
= v.next =
|
||||
= 0.16.2 =
|
||||
|
||||
* Add configuration item for number of images to attach. props [@mexon](https://github.com/mexon)
|
||||
* Use shortcodes instead of custom templates, to setup the Activity Post-Content. props [@toolstack](https://github.com/toolstack)
|
||||
* Fix fatal error in outbox
|
||||
|
||||
= 0.16.1 =
|
||||
|
||||
* Fix "update and create, posts appear blank on Mastodon" issue
|
||||
|
||||
= 0.16.0 =
|
||||
|
||||
* Add "Outgoing Mentions" ([#213](https://github.com/pfefferle/wordpress-activitypub/pull/213)) props [@akirk](https://github.com/akirk)
|
||||
* Add configuration item for number of images to attach ([#248](https://github.com/pfefferle/wordpress-activitypub/pull/248)) props [@mexon](https://github.com/mexon)
|
||||
* Use shortcodes instead of custom templates, to setup the Activity Post-Content ([#250](https://github.com/pfefferle/wordpress-activitypub/pull/250)) props [@toolstack](https://github.com/toolstack)
|
||||
* Remove custom REST Server, because the needed changes are now merged into Core.
|
||||
* Fix hashtags ([#261](https://github.com/pfefferle/wordpress-activitypub/pull/261)) props [@akirk](https://github.com/akirk)
|
||||
* Change priorites, to maybe fix the hashtag issue
|
||||
|
||||
= 0.15.0 =
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HT
|
|||
$activitypub_post = new \Activitypub\Model\Post( $post );
|
||||
\Activitypub\Activity_Dispatcher::send_post_activity( $activitypub_post );
|
||||
|
||||
$this->assertNotEmpty( $activitypub_post->get_content() );
|
||||
|
||||
$this->assertSame( 2, $pre_http_request->get_call_count() );
|
||||
$all_args = $pre_http_request->get_args();
|
||||
$first_call_args = array_shift( $all_args );
|
||||
|
@ -69,6 +71,8 @@ class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HT
|
|||
$activitypub_post = new \Activitypub\Model\Post( $post );
|
||||
\Activitypub\Activity_Dispatcher::send_post_activity( $activitypub_post );
|
||||
|
||||
$this->assertNotEmpty( $activitypub_post->get_content() );
|
||||
|
||||
$this->assertSame( 1, $pre_http_request->get_call_count() );
|
||||
$all_args = $pre_http_request->get_args();
|
||||
$first_call_args = $all_args[0];
|
||||
|
|
Loading…
Reference in a new issue