Skip to content

Commit 4e653f5

Browse files
committed
0.1.0
* added basic WebFinger support * added basic NodeInfo support * fully functional "follow" activity * send new posts to your followers * receive comments from your followers
1 parent b063220 commit 4e653f5

18 files changed

+822
-260
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ env:
1717
- WP_TRAVISCI=travis:phpunit
1818
- SVN_REPO: https://plugins.svn.wordpress.org/activitypub/
1919
- GH_REF: https://github.com/pfefferle/wordpress-activitypub.git
20-
- secure: k6uZL/zVYvuSsG4tUMvVC6+DTYKSueOYj6j9csKSa08EzPl0JLPoNN/5MPihi+zZkBPLL+KjBgUUYfBtdcOh/xwPb+lilg5UnvM7TKQEG583RtBbohADvahQHN4mxZb6yBvrmvbB5jNtf+3L4RcOgdONEb2CpGo5n8RRM3MXxF4WSn9s+F+P0fvWCpcZnM9yqgbTJNUaZHw4tRWQ7eYZ5kFxSxKSnZd5+149UAh2YcKjA+ix3rrK0ClOlGaMVZz+SV4/qoNwamxMTMAQ6Be1wIelXz0n92FIonw6euDfBSgNLg+WLiAYoqaM+tEluLV1DRcx5TLUfmAOGli6pEfqL6XZxf8iZheMtn5Ir0nR4vLbOUKEojqEpLwmlUjiTN6RSZbPMquBNz/lOEQd9S/EzPLrtvlBRYAq0EmI62KtXVG+vHta2TTF+LS0caXjVZaHcpF4SYmuG5WyR6d0KpnVw6czvXu7hyq2sNz6lj1hUt15pPZO8tFkJFTs87pOBfEj/GnjIE4Iab2HA/HgdWqFpB+5ZAWH9QDIa9c3+QUQQf2qA7Z1yS0c5SBn/TE+0O3yomyBTD63Zc7gNG2qqw+THql5fzG3iGV5M6db+yTY0INfsJYuRjQXpn9Q35ZTxgXEEvu7naHh162wa14K18zzXoVEjhywOoW3X1Qiz6VFK8s=
20+
- secure: "WaeBLo0MDuK4X7NQvk5Ie5BVnexHtyDfHAV8v7dB8B67d8GCWy9K5I54jTECNRUC+CecMakLq5DOfn+ThtWdkJmoJKnGNFp8ZrWkMsfVJRi3CDED2HkccOrxkmXBj8Z6A8jZjcfVNrEmq/6697xVNRGeaS08l9rokh7pyb8INWY="
2121
matrix:
2222
include:
2323
- php: 7.2

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
**Donate link:** https://notiz.blog/donate/
44
**Tags:** OStatus, fediverse, activitypub, activitystream
55
**Requires at least:** 4.7
6-
**Tested up to:** 5.0
6+
**Tested up to:** 5.0.2
77
**Stable tag:** 0.1.0
88
**Requires PHP:** 5.6
99
**License:** MIT
@@ -13,9 +13,9 @@ The ActivityPub protocol is a decentralized social networking protocol based upo
1313

1414
## Description ##
1515

16-
This is **BETA** software, see the FAQ to see what works and what still needs to be implemented or is in planning.
16+
This is **BETA** software, see the FAQ to see the current feature set or rather what is still planned.
1717

18-
This plugin enables ActivityPub for your Blog. Your readers will be able to follow your Blogposts on Mastodon and other Federated Plattforms that support ActivityPub.
18+
This plugin implements the ActivityPub for your Blog. Your readers will be able to follow your Blogposts on Mastodon and other Federated Plattforms that support ActivityPub.
1919

2020
## Frequently Asked Questions ##
2121

@@ -26,30 +26,34 @@ Implemented:
2626
* profile pages (JSON representation)
2727
* custom links
2828
* functional inbox/outbox
29-
* follow (accept follows)
29+
* follow (accept follows)
30+
* share posts
31+
* receive comments/reactions
3032

3133
To implement:
3234

33-
* share posts
34-
* share comments
35+
* signature verification
36+
* better WordPress integration
37+
* better configuration possibilities
38+
* threaded comments support
3539

3640
### Why does the plugin not support ...? ###
3741

3842
*ActivityPub* extends WordPress with some fediverse features, but it does not compete with plattforms like Friendi.ca or Mastodon. If you want to have a **decentralized social network**, please use [Mastodon](https://joinmastodon.org/) or [GNU.social](https://gnu.io/social/).
3943

40-
### What are the differences to Pterotype? ###
44+
### What are the differences between this plugin and Pterotype? ###
4145

4246
**PHP Version**
4347

44-
*ActivityPub* needs PHP 5.6, *Pterotype* requires 7.2.x
48+
*This plugin* needs PHP 5.6, *Pterotype* requires 7.2.x
4549

4650
**Compatibility**
4751

48-
*ActivityPub* is compatible with OStatus and the IndieWeb movement. *Pterotype* implements its own WebFinger endpoint, that is not compatible with the [WebFinger plugin](https://wordpress.org/plugins/webfinger/).
52+
*This plugin* is compatible with OStatus and the IndieWeb movement. *Pterotype* implements for example its own WebFinger endpoint, which is not compatible with the [WebFinger plugin](https://wordpress.org/plugins/webfinger/).
4953

5054
**Custom tables**
5155

52-
*Pterotype* creates/uses a bunch of custom tables, *ActivityPub* only uses the native tables and adds as few meta data as possible.
56+
*Pterotype* creates/uses a bunch of custom tables, *this plugin* only uses the native tables and adds as few meta data as possible.
5357

5458
## Changelog ##
5559

@@ -59,7 +63,9 @@ Project maintained on github at [pfefferle/wordpress-activitypub](https://github
5963

6064
* added basic WebFinger support
6165
* added basic NodeInfo support
62-
* fully functional "follow" activity
66+
* fully functional "follow" activity
67+
* send new posts to your followers
68+
* receive comments from your followers
6369

6470
### 0.0.2 ###
6571

activitypub.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
function activitypub_init() {
1919
require_once dirname( __FILE__ ) . '/includes/class-activitypub-signature.php';
2020
require_once dirname( __FILE__ ) . '/includes/class-activitypub-post.php';
21+
require_once dirname( __FILE__ ) . '/includes/class-activitypub-activity.php';
2122
require_once dirname( __FILE__ ) . '/includes/class-db-activitypub-followers.php';
2223
require_once dirname( __FILE__ ) . '/includes/functions.php';
2324

@@ -29,9 +30,16 @@ function activitypub_init() {
2930
// Configure the REST API route
3031
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-outbox.php';
3132
add_action( 'rest_api_init', array( 'Rest_Activitypub_Outbox', 'register_routes' ) );
33+
add_action( 'activitypub_send_post_activity', array( 'Rest_Activitypub_Outbox', 'send_post_activity' ) );
3234

3335
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-inbox.php';
3436
add_action( 'rest_api_init', array( 'Rest_Activitypub_Inbox', 'register_routes' ) );
37+
//add_filter( 'rest_pre_serve_request', array( 'Rest_Activitypub_Inbox', 'serve_request' ), 11, 4 );
38+
add_action( 'activitypub_inbox_follow', array( 'Rest_Activitypub_Inbox', 'handle_follow' ), 10, 2 );
39+
add_action( 'activitypub_inbox_unfollow', array( 'Rest_Activitypub_Inbox', 'handle_unfollow' ), 10, 2 );
40+
add_action( 'activitypub_inbox_like', array( 'Rest_Activitypub_Inbox', 'handle_reaction' ), 10, 2 );
41+
add_action( 'activitypub_inbox_announce', array( 'Rest_Activitypub_Inbox', 'handle_reaction' ), 10, 2 );
42+
add_action( 'activitypub_inbox_create', array( 'Rest_Activitypub_Inbox', 'handle_create' ), 10, 2 );
3543

3644
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-followers.php';
3745
add_action( 'rest_api_init', array( 'Rest_Activitypub_Followers', 'register_routes' ) );
@@ -45,11 +53,17 @@ function activitypub_init() {
4553
add_filter( 'nodeinfo_data', array( 'Rest_Activitypub_Nodeinfo', 'add_nodeinfo_discovery' ), 10, 2 );
4654
add_filter( 'nodeinfo2_data', array( 'Rest_Activitypub_Nodeinfo', 'add_nodeinfo2_discovery' ), 10 );
4755

48-
// Configure activities
49-
require_once dirname( __FILE__ ) . '/includes/class-activitypub-activities.php';
50-
add_action( 'activitypub_inbox_follow', array( 'Activitypub_Activities', 'accept' ), 10, 2 );
51-
add_action( 'activitypub_inbox_follow', array( 'Activitypub_Activities', 'follow' ), 10, 2 );
52-
add_action( 'activitypub_inbox_unfollow', array( 'Activitypub_Activities', 'unfollow' ), 10, 2 );
56+
add_post_type_support( 'post', 'activitypub' );
57+
add_post_type_support( 'page', 'activitypub' );
58+
59+
$post_types = get_post_types_by_support( 'activitypub' );
60+
foreach ( $post_types as $post_type ) {
61+
add_action( 'publish_' . $post_type, array( 'Activitypub', 'schedule_post_activity' ) );
62+
}
63+
64+
require_once dirname( __FILE__ ) . '/includes/class-activitypub-admin.php';
65+
add_action( 'admin_menu', array( 'Activitypub_Admin', 'admin_menu' ) );
66+
add_action( 'admin_init', array( 'Activitypub_Admin', 'register_settings' ) );
5367
}
5468
add_action( 'plugins_loaded', 'activitypub_init' );
5569

includes/class-activitypub-activities.php

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* ActivityPub Post Class
4+
*
5+
* @author Matthias Pfefferle
6+
*/
7+
class Activitypub_Activity {
8+
private $context = array( 'https://www.w3.org/ns/activitystreams' );
9+
private $published = '';
10+
private $id = '';
11+
private $type = 'Create';
12+
private $actor = '';
13+
private $to = array( 'https://www.w3.org/ns/activitystreams#Public' );
14+
private $cc = array( 'https://www.w3.org/ns/activitystreams#Public' );
15+
private $object = null;
16+
17+
const TYPE_SIMPLE = 'simple';
18+
const TYPE_FULL = 'full';
19+
const TYPE_NONE = 'none';
20+
21+
public function __construct( $type = 'Create', $context = self::TYPE_SIMPLE ) {
22+
if ( 'none' === $context ) {
23+
$this->context = null;
24+
} elseif ( 'full' === $context ) {
25+
$this->context = get_activitypub_context();
26+
}
27+
28+
$this->type = ucfirst( $type );
29+
$this->published = date( 'Y-m-d\TH:i:s\Z', strtotime( 'now' ) );
30+
}
31+
32+
public function __call( $method, $params ) {
33+
$var = strtolower( substr( $method, 4 ) );
34+
35+
if ( strncasecmp( $method, 'get', 3 ) === 0 ) {
36+
return $this->$var;
37+
}
38+
39+
if ( strncasecmp( $method, 'set', 3 ) === 0 ) {
40+
$this->$var = $params[0];
41+
}
42+
}
43+
44+
public function from_post( $object ) {
45+
$this->object = $object;
46+
$this->published = $object['published'];
47+
$this->actor = $object['attributedTo'];
48+
$this->id = $object['id'];
49+
}
50+
51+
public function from_comment( $object ) {
52+
53+
}
54+
55+
public function to_array() {
56+
$array = get_object_vars( $this );
57+
58+
if ( $this->context ) {
59+
$array = array( '@context' => $this->context ) + $array;
60+
}
61+
62+
unset( $array['context'] );
63+
64+
return $array;
65+
}
66+
67+
public function to_json() {
68+
return wp_json_encode( $this->to_array() );
69+
}
70+
71+
public function to_simple_array() {
72+
return array(
73+
'@context' => $this->context,
74+
'type' => $this->type,
75+
'actor' => $this->actor,
76+
'object' => $this->object,
77+
'to' => $this->to,
78+
);
79+
}
80+
81+
public function to_simple_json() {
82+
return wp_json_encode( $this->to_simple_array() );
83+
}
84+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* ActivityPub Admin Class
4+
*/
5+
class Activitypub_Admin {
6+
/**
7+
* Add admin menu entry
8+
*/
9+
public static function admin_menu() {
10+
$settings_page = add_options_page(
11+
'ActivityPub',
12+
'ActivityPub',
13+
'manage_options',
14+
'activitypub',
15+
array( 'Activitypub_Admin', 'settings_page' )
16+
);
17+
18+
add_action( 'load-' . $settings_page, array( 'Activitypub_Admin', 'add_help_tab' ) );
19+
}
20+
21+
/**
22+
* Load settings page
23+
*/
24+
public static function settings_page() {
25+
load_template( dirname( __FILE__ ) . '/../templates/settings-page.php' );
26+
}
27+
28+
/**
29+
* Register PubSubHubbub settings
30+
*/
31+
public static function register_settings() {
32+
register_setting( 'activitypub', 'activitypub_feed_use_excerpt' );
33+
}
34+
35+
public static function add_help_tab() {
36+
get_current_screen()->add_help_tab(
37+
array(
38+
'id' => 'overview',
39+
'title' => __( 'Overview', 'activitypub' ),
40+
'content' =>
41+
'<p>' . __( 'ActivityPub is a decentralized social networking protocol based on the ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended standard published by the W3C Social Web Working Group. It provides a client to server API for creating, updating and deleting content, as well as a federated server to server API for delivering notifications and subscribing to content.', 'activitypub' ) . '</p>',
42+
)
43+
);
44+
45+
get_current_screen()->set_help_sidebar(
46+
'<p><strong>' . __( 'For more information:', 'activitypub' ) . '</strong></p>' .
47+
'<p>' . __( '<a href="https://activitypub.rocks/">Test Suite</a>', 'activitypub' ) . '</p>' .
48+
'<p>' . __( '<a href="https://www.w3.org/TR/activitypub/">W3C Spec</a>', 'activitypub' ) . '</p>' .
49+
'<p>' . __( '<a href="https://github.com/pfefferle/wordpress-activitypub/issues">Give us feedback</a>', 'activitypub' ) . '</p>' .
50+
'<hr />' .
51+
'<p>' . __( '<a href="https://notiz.blog/donate">Donate</a>', 'activitypub' ) . '</p>'
52+
);
53+
}
54+
}

0 commit comments

Comments
 (0)