Skip to content

Commit 52f0d81

Browse files
committed
initial
1 parent 34b7a66 commit 52f0d81

File tree

14 files changed

+411
-1
lines changed

14 files changed

+411
-1
lines changed

.editorconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# WordPress Coding Standards
5+
# https://make.wordpress.org/core/handbook/coding-standards/
6+
7+
root = true
8+
9+
[*]
10+
charset = utf-8
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
indent_style = tab
15+
indent_size = 4
16+
17+
[{.jshintrc,*.json,*.yml}]
18+
indent_style = space
19+
indent_size = 2
20+
21+
[{*.txt,wp-config-sample.php}]
22+
end_of_line = crlf

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules/
2+
/vendor/
3+
package-lock.json
4+
composer.lock

Gruntfile.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
module.exports = function(grunt) {
2+
// Project configuration.
3+
grunt.initConfig({
4+
checktextdomain: {
5+
options:{
6+
text_domain: 'activitypub',
7+
keywords: [
8+
'__:1,2d',
9+
'_e:1,2d',
10+
'_x:1,2c,3d',
11+
'esc_html__:1,2d',
12+
'esc_html_e:1,2d',
13+
'esc_html_x:1,2c,3d',
14+
'esc_attr__:1,2d',
15+
'esc_attr_e:1,2d',
16+
'esc_attr_x:1,2c,3d',
17+
'_ex:1,2c,3d',
18+
'_n:1,2,4d',
19+
'_nx:1,2,4c,5d',
20+
'_n_noop:1,2,3d',
21+
'_nx_noop:1,2,3c,4d'
22+
]
23+
},
24+
files: {
25+
src: [
26+
'**/*.php', // Include all files
27+
'includes/*.php', // Include includes
28+
'!sass/**', // Exclude sass/
29+
'!node_modules/**', // Exclude node_modules/
30+
'!tests/**', // Exclude tests/
31+
'!vendor/**', // Exclude vendor/
32+
'!build/**', // Exclude build/
33+
'!static/**', // Exclude static resources
34+
],
35+
expand: true
36+
}
37+
},
38+
39+
wp_readme_to_markdown: {
40+
target: {
41+
files: {
42+
'README.md': 'readme.txt'
43+
},
44+
},
45+
},
46+
makepot: {
47+
target: {
48+
options: {
49+
mainFile: 'activitypub.php',
50+
domainPath: '/languages',
51+
exclude: ['bin/.*', '.git/.*', 'vendor/.*'],
52+
potFilename: 'activitypub.pot',
53+
type: 'wp-plugin',
54+
updateTimestamp: true
55+
}
56+
}
57+
}
58+
});
59+
60+
grunt.loadNpmTasks('grunt-wp-readme-to-markdown');
61+
grunt.loadNpmTasks('grunt-wp-i18n');
62+
grunt.loadNpmTasks('grunt-checktextdomain');
63+
64+
// Default task(s).
65+
grunt.registerTask('default', ['wp_readme_to_markdown', 'makepot', 'checktextdomain']);
66+
};

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
# wordpress-activitypub
1+
# ActivityPub #
2+
**Contributors:** [pfefferle](https://profiles.wordpress.org/pfefferle)
3+
**Donate link:** https://notiz.blog/donate/
4+
**Tags:** OStatus, fediverse, activitypub, activitystream
5+
**Requires at least:** 4.7
6+
**Tested up to:** 4.9.8
7+
**Stable tag:** 1.0.0
8+
**Requires PHP:** 5.3
9+
**License:** MIT
10+
**License URI:** http://opensource.org/licenses/MIT
11+
12+
The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.

activitypub.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Plugin Name: ActivityPub
4+
* Plugin URI: https://github.com/pfefferle/wordpress-activitypub/
5+
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
6+
* Version: 1.0.0
7+
* Author: Matthias Pfefferle
8+
* Author URI: https://notiz.blog/
9+
* License: MIT
10+
* License URI: http://opensource.org/licenses/MIT
11+
* Text Domain: activitypub
12+
* Domain Path: /languages
13+
*/
14+
15+
/**
16+
* Initialize plugin
17+
*/
18+
function activitypub_init() {
19+
require_once dirname( __FILE__ ) . '/includes/functions.php';
20+
21+
require_once dirname( __FILE__ ) . '/includes/class-activitypub.php';
22+
add_filter( 'template_include', array( 'Activity_Pub', 'render_profile' ), 99 );
23+
add_action( 'webfinger_user_data', array( 'Activity_Pub', 'add_webfinger_discovery' ), 10, 3 );
24+
add_filter( 'query_vars', array( 'Activity_Pub', 'add_query_vars' ) );
25+
add_action( 'init', array( 'Activity_Pub', 'add_rewrite_endpoint' ) );
26+
}
27+
add_action( 'plugins_loaded', 'activitypub_init' );

composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "pfefferle/wordpress-activitypub",
3+
"description": "The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.",
4+
"type": "wordpress-plugin",
5+
"require": {
6+
"php": ">=5.3.0",
7+
"composer/installers": "~1.0"
8+
},
9+
"license": "MIT",
10+
"authors": [
11+
{
12+
"name": "Matthias Pfefferle",
13+
"email": "[email protected]"
14+
}
15+
],
16+
"extra": {
17+
"installer-name": "activitypub"
18+
}
19+
}

docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '2'
2+
services:
3+
db:
4+
image: mysql:5.7
5+
restart: always
6+
environment:
7+
MYSQL_ROOT_PASSWORD: wordpress
8+
MYSQL_DATABASE: wordpress
9+
MYSQL_USER: wordpress
10+
MYSQL_PASSWORD: wordpress
11+
12+
wordpress:
13+
depends_on:
14+
- db
15+
image: wordpress:latest
16+
links:
17+
- db
18+
ports:
19+
- "8076:80"
20+
volumes:
21+
- .:/var/www/html/wp-content/plugins/activitypub
22+
restart: always
23+
environment:
24+
WORDPRESS_DB_HOST: db:3306
25+
WORDPRESS_DB_PASSWORD: wordpress
26+
WORDPRESS_DEBUG: 1

includes/class-activitypub.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
class Activity_Pub {
4+
public static function render_profile( $template ) {
5+
if ( ! is_author() ) {
6+
return $template;
7+
}
8+
9+
$json_template = dirname( __FILE__ ) . '/../templates/author-profile.php';
10+
11+
global $wp_query;
12+
13+
if ( isset( $wp_query->query_vars['activitypub'] ) ) {
14+
return $json_template;
15+
}
16+
17+
if ( ! isset( $_SERVER['HTTP_ACCEPT'] ) ) {
18+
return $template;
19+
}
20+
21+
// interpret accept header
22+
$pos = stripos( $_SERVER['HTTP_ACCEPT'], ';' );
23+
if ( $pos ) {
24+
$accept_header = substr( $_SERVER['HTTP_ACCEPT'], 0, $pos );
25+
} else {
26+
$accept_header = $_SERVER['HTTP_ACCEPT'];
27+
}
28+
// accept header as an array
29+
$accept = explode( ',', trim( $accept_header ) );
30+
31+
if (
32+
! in_array( 'application/activity+json', $accept, true ) &&
33+
! in_array( 'application/ld+json', $accept, true )
34+
) {
35+
return $template;
36+
}
37+
38+
return $json_template;
39+
}
40+
41+
/**
42+
* Add WebFinger discovery links
43+
*
44+
* @param array $array the jrd array
45+
* @param string $resource the WebFinger resource
46+
* @param WP_User $user the WordPress user
47+
*/
48+
public static function add_webfinger_discovery( $array, $resource, $user ) {
49+
$array['links'][] = array(
50+
'rel' => 'self',
51+
'type' => 'aplication/activity+json',
52+
'href' => get_author_posts_url( $user->ID ),
53+
);
54+
55+
return $array;
56+
}
57+
58+
/**
59+
* Add the 'photos' query variable so WordPress
60+
* won't mangle it.
61+
*/
62+
public static function add_query_vars( $vars ) {
63+
$vars[] = 'activitypub';
64+
return $vars;
65+
}
66+
67+
/**
68+
* Add our rewrite endpoint to permalinks and pages.
69+
*/
70+
public static function add_rewrite_endpoint() {
71+
add_rewrite_endpoint( 'activitypub', EP_AUTHORS );
72+
}
73+
}

includes/functions.php

Whitespace-only changes.

languages/activitypub.pot

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (C) 2018 Matthias Pfefferle
2+
# This file is distributed under the MIT.
3+
msgid ""
4+
msgstr ""
5+
"Project-Id-Version: ActivityPub 1.0.0\n"
6+
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
7+
"POT-Creation-Date: 2018-08-18 10:35:26+00:00\n"
8+
"MIME-Version: 1.0\n"
9+
"Content-Type: text/plain; charset=utf-8\n"
10+
"Content-Transfer-Encoding: 8bit\n"
11+
"PO-Revision-Date: 2018-MO-DA HO:MI+ZONE\n"
12+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13+
"Language-Team: LANGUAGE <[email protected]>\n"
14+
"X-Generator: grunt-wp-i18n1.0.2\n"
15+
16+
#. Plugin Name of the plugin/theme
17+
msgid "ActivityPub"
18+
msgstr ""
19+
20+
#. Plugin URI of the plugin/theme
21+
msgid "https://github.com/pfefferle/wordpress-activitypub/"
22+
msgstr ""
23+
24+
#. Description of the plugin/theme
25+
msgid ""
26+
"The ActivityPub protocol is a decentralized social networking protocol "
27+
"based upon the ActivityStreams 2.0 data format."
28+
msgstr ""
29+
30+
#. Author of the plugin/theme
31+
msgid "Matthias Pfefferle"
32+
msgstr ""
33+
34+
#. Author URI of the plugin/theme
35+
msgid "https://notiz.blog/"
36+
msgstr ""

0 commit comments

Comments
 (0)