Skip to content

Commit

Permalink
0.1.0
Browse files Browse the repository at this point in the history
* added basic WebFinger support
* added basic NodeInfo support
* fully functional "follow" activity
* send new posts to your followers
* receive comments from your followers
  • Loading branch information
pfefferle committed Dec 20, 2018
1 parent b063220 commit 4e653f5
Show file tree
Hide file tree
Showing 18 changed files with 822 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
- WP_TRAVISCI=travis:phpunit
- SVN_REPO: https://plugins.svn.wordpress.org/activitypub/
- GH_REF: https://github.com/pfefferle/wordpress-activitypub.git
- 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=
- secure: "WaeBLo0MDuK4X7NQvk5Ie5BVnexHtyDfHAV8v7dB8B67d8GCWy9K5I54jTECNRUC+CecMakLq5DOfn+ThtWdkJmoJKnGNFp8ZrWkMsfVJRi3CDED2HkccOrxkmXBj8Z6A8jZjcfVNrEmq/6697xVNRGeaS08l9rokh7pyb8INWY="
matrix:
include:
- php: 7.2
Expand Down
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**Donate link:** https://notiz.blog/donate/
**Tags:** OStatus, fediverse, activitypub, activitystream
**Requires at least:** 4.7
**Tested up to:** 5.0
**Tested up to:** 5.0.2
**Stable tag:** 0.1.0
**Requires PHP:** 5.6
**License:** MIT
Expand All @@ -13,9 +13,9 @@ The ActivityPub protocol is a decentralized social networking protocol based upo

## Description ##

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

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

## Frequently Asked Questions ##

Expand All @@ -26,30 +26,34 @@ Implemented:
* profile pages (JSON representation)
* custom links
* functional inbox/outbox
* follow (accept follows)
* follow (accept follows)
* share posts
* receive comments/reactions

To implement:

* share posts
* share comments
* signature verification
* better WordPress integration
* better configuration possibilities
* threaded comments support

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

*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/).

### What are the differences to Pterotype? ###
### What are the differences between this plugin and Pterotype? ###

**PHP Version**

*ActivityPub* needs PHP 5.6, *Pterotype* requires 7.2.x
*This plugin* needs PHP 5.6, *Pterotype* requires 7.2.x

**Compatibility**

*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/).
*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/).

**Custom tables**

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

## Changelog ##

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

* added basic WebFinger support
* added basic NodeInfo support
* fully functional "follow" activity
* fully functional "follow" activity
* send new posts to your followers
* receive comments from your followers

### 0.0.2 ###

Expand Down
24 changes: 19 additions & 5 deletions activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
function activitypub_init() {
require_once dirname( __FILE__ ) . '/includes/class-activitypub-signature.php';
require_once dirname( __FILE__ ) . '/includes/class-activitypub-post.php';
require_once dirname( __FILE__ ) . '/includes/class-activitypub-activity.php';
require_once dirname( __FILE__ ) . '/includes/class-db-activitypub-followers.php';
require_once dirname( __FILE__ ) . '/includes/functions.php';

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

require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-inbox.php';
add_action( 'rest_api_init', array( 'Rest_Activitypub_Inbox', 'register_routes' ) );
//add_filter( 'rest_pre_serve_request', array( 'Rest_Activitypub_Inbox', 'serve_request' ), 11, 4 );
add_action( 'activitypub_inbox_follow', array( 'Rest_Activitypub_Inbox', 'handle_follow' ), 10, 2 );
add_action( 'activitypub_inbox_unfollow', array( 'Rest_Activitypub_Inbox', 'handle_unfollow' ), 10, 2 );
add_action( 'activitypub_inbox_like', array( 'Rest_Activitypub_Inbox', 'handle_reaction' ), 10, 2 );
add_action( 'activitypub_inbox_announce', array( 'Rest_Activitypub_Inbox', 'handle_reaction' ), 10, 2 );
add_action( 'activitypub_inbox_create', array( 'Rest_Activitypub_Inbox', 'handle_create' ), 10, 2 );

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

// Configure activities
require_once dirname( __FILE__ ) . '/includes/class-activitypub-activities.php';
add_action( 'activitypub_inbox_follow', array( 'Activitypub_Activities', 'accept' ), 10, 2 );
add_action( 'activitypub_inbox_follow', array( 'Activitypub_Activities', 'follow' ), 10, 2 );
add_action( 'activitypub_inbox_unfollow', array( 'Activitypub_Activities', 'unfollow' ), 10, 2 );
add_post_type_support( 'post', 'activitypub' );
add_post_type_support( 'page', 'activitypub' );

$post_types = get_post_types_by_support( 'activitypub' );
foreach ( $post_types as $post_type ) {
add_action( 'publish_' . $post_type, array( 'Activitypub', 'schedule_post_activity' ) );
}

require_once dirname( __FILE__ ) . '/includes/class-activitypub-admin.php';
add_action( 'admin_menu', array( 'Activitypub_Admin', 'admin_menu' ) );
add_action( 'admin_init', array( 'Activitypub_Admin', 'register_settings' ) );
}
add_action( 'plugins_loaded', 'activitypub_init' );

Expand Down
64 changes: 0 additions & 64 deletions includes/class-activitypub-activities.php

This file was deleted.

84 changes: 84 additions & 0 deletions includes/class-activitypub-activity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* ActivityPub Post Class
*
* @author Matthias Pfefferle
*/
class Activitypub_Activity {
private $context = array( 'https://www.w3.org/ns/activitystreams' );
private $published = '';
private $id = '';
private $type = 'Create';
private $actor = '';
private $to = array( 'https://www.w3.org/ns/activitystreams#Public' );
private $cc = array( 'https://www.w3.org/ns/activitystreams#Public' );
private $object = null;

const TYPE_SIMPLE = 'simple';
const TYPE_FULL = 'full';
const TYPE_NONE = 'none';

public function __construct( $type = 'Create', $context = self::TYPE_SIMPLE ) {
if ( 'none' === $context ) {
$this->context = null;
} elseif ( 'full' === $context ) {
$this->context = get_activitypub_context();
}

$this->type = ucfirst( $type );
$this->published = date( 'Y-m-d\TH:i:s\Z', strtotime( 'now' ) );
}

public function __call( $method, $params ) {
$var = strtolower( substr( $method, 4 ) );

if ( strncasecmp( $method, 'get', 3 ) === 0 ) {
return $this->$var;
}

if ( strncasecmp( $method, 'set', 3 ) === 0 ) {
$this->$var = $params[0];
}
}

public function from_post( $object ) {
$this->object = $object;
$this->published = $object['published'];
$this->actor = $object['attributedTo'];
$this->id = $object['id'];
}

public function from_comment( $object ) {

}

public function to_array() {
$array = get_object_vars( $this );

if ( $this->context ) {
$array = array( '@context' => $this->context ) + $array;
}

unset( $array['context'] );

return $array;
}

public function to_json() {
return wp_json_encode( $this->to_array() );
}

public function to_simple_array() {
return array(
'@context' => $this->context,
'type' => $this->type,
'actor' => $this->actor,
'object' => $this->object,
'to' => $this->to,
);
}

public function to_simple_json() {
return wp_json_encode( $this->to_simple_array() );
}
}
54 changes: 54 additions & 0 deletions includes/class-activitypub-admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* ActivityPub Admin Class
*/
class Activitypub_Admin {
/**
* Add admin menu entry
*/
public static function admin_menu() {
$settings_page = add_options_page(
'ActivityPub',
'ActivityPub',
'manage_options',
'activitypub',
array( 'Activitypub_Admin', 'settings_page' )
);

add_action( 'load-' . $settings_page, array( 'Activitypub_Admin', 'add_help_tab' ) );
}

/**
* Load settings page
*/
public static function settings_page() {
load_template( dirname( __FILE__ ) . '/../templates/settings-page.php' );
}

/**
* Register PubSubHubbub settings
*/
public static function register_settings() {
register_setting( 'activitypub', 'activitypub_feed_use_excerpt' );
}

public static function add_help_tab() {
get_current_screen()->add_help_tab(
array(
'id' => 'overview',
'title' => __( 'Overview', 'activitypub' ),
'content' =>
'<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>',
)
);

get_current_screen()->set_help_sidebar(
'<p><strong>' . __( 'For more information:', 'activitypub' ) . '</strong></p>' .
'<p>' . __( '<a href="https://activitypub.rocks/">Test Suite</a>', 'activitypub' ) . '</p>' .
'<p>' . __( '<a href="https://www.w3.org/TR/activitypub/">W3C Spec</a>', 'activitypub' ) . '</p>' .
'<p>' . __( '<a href="https://github.com/pfefferle/wordpress-activitypub/issues">Give us feedback</a>', 'activitypub' ) . '</p>' .
'<hr />' .
'<p>' . __( '<a href="https://notiz.blog/donate">Donate</a>', 'activitypub' ) . '</p>'
);
}
}
Loading

0 comments on commit 4e653f5

Please sign in to comment.