| 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: 0.11.2 |
| 7 |
* Author: Matthias Pfefferle |
| 8 |
* Author URI: https://notiz.blog/ |
| 9 |
* License: MIT |
| 10 |
* License URI: http://opensource.org/licenses/MIT |
| 11 |
* Requires PHP: 5.6 |
| 12 |
* Text Domain: activitypub |
| 13 |
* Domain Path: /languages |
| 14 |
*/ |
| 15 |
|
| 16 |
namespace Activitypub; |
| 17 |
|
| 18 |
/** |
| 19 |
* Initialize plugin |
| 20 |
*/ |
| 21 |
function init() { |
| 22 |
\defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|^)#(\w*[A-Za-z_]+\w*)' ); |
| 23 |
\defined( 'ACTIVITYPUB_ALLOWED_HTML' ) || \define( 'ACTIVITYPUB_ALLOWED_HTML', '<strong><a><p><ul><ol><li><code><blockquote><pre><img>' ); |
| 24 |
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<p><strong>%title%</strong></p>\n\n%content%\n\n<p>%hashtags%</p>\n\n<p>%shortlink%</p>" ); |
| 25 |
|
| 26 |
require_once \dirname( __FILE__ ) . '/includes/table/followers-list.php'; |
| 27 |
require_once \dirname( __FILE__ ) . '/includes/class-signature.php'; |
| 28 |
require_once \dirname( __FILE__ ) . '/includes/peer/class-followers.php'; |
| 29 |
require_once \dirname( __FILE__ ) . '/includes/functions.php'; |
| 30 |
|
| 31 |
require_once \dirname( __FILE__ ) . '/includes/model/class-activity.php'; |
| 32 |
require_once \dirname( __FILE__ ) . '/includes/model/class-post.php'; |
| 33 |
|
| 34 |
require_once \dirname( __FILE__ ) . '/includes/class-activity-dispatcher.php'; |
| 35 |
\Activitypub\Activity_Dispatcher::init(); |
| 36 |
|
| 37 |
require_once \dirname( __FILE__ ) . '/includes/class-activitypub.php'; |
| 38 |
\Activitypub\Activitypub::init(); |
| 39 |
|
| 40 |
// Configure the REST API route |
| 41 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-outbox.php'; |
| 42 |
\Activitypub\Rest\Outbox::init(); |
| 43 |
|
| 44 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-inbox.php'; |
| 45 |
\Activitypub\Rest\Inbox::init(); |
| 46 |
|
| 47 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-followers.php'; |
| 48 |
\Activitypub\Rest\Followers::init(); |
| 49 |
|
| 50 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-following.php'; |
| 51 |
\Activitypub\Rest\Following::init(); |
| 52 |
|
| 53 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-webfinger.php'; |
| 54 |
\Activitypub\Rest\Webfinger::init(); |
| 55 |
|
| 56 |
// load NodeInfo endpoints only if blog is public |
| 57 |
if ( 1 === \get_option( 'blog_public', 1 ) ) { |
| 58 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-nodeinfo.php'; |
| 59 |
\Activitypub\Rest\NodeInfo::init(); |
| 60 |
} |
| 61 |
|
| 62 |
require_once \dirname( __FILE__ ) . '/includes/class-admin.php'; |
| 63 |
\Activitypub\Admin::init(); |
| 64 |
|
| 65 |
require_once \dirname( __FILE__ ) . '/includes/class-hashtag.php'; |
| 66 |
\Activitypub\Hashtag::init(); |
| 67 |
|
| 68 |
require_once \dirname( __FILE__ ) . '/includes/class-debug.php'; |
| 69 |
\Activitypub\Debug::init(); |
| 70 |
|
| 71 |
require_once \dirname( __FILE__ ) . '/includes/class-health-check.php'; |
| 72 |
\Activitypub\Health_Check::init(); |
| 73 |
|
| 74 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-server.php'; |
| 75 |
\add_filter( 'wp_rest_server_class', function() { |
| 76 |
return '\Activitypub\Rest\Server'; |
| 77 |
} ); |
| 78 |
} |
| 79 |
\add_action( 'plugins_loaded', '\Activitypub\init' ); |
| 80 |
|
| 81 |
/** |
| 82 |
* Add rewrite rules |
| 83 |
*/ |
| 84 |
function add_rewrite_rules() { |
| 85 |
if ( ! \class_exists( 'Webfinger' ) ) { |
| 86 |
\add_rewrite_rule( '^.well-known/webfinger', 'index.php?rest_route=/activitypub/1.0/webfinger', 'top' ); |
| 87 |
} |
| 88 |
|
| 89 |
if ( ! \class_exists( 'Nodeinfo' ) ) { |
| 90 |
\add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/activitypub/1.0/nodeinfo/discovery', 'top' ); |
| 91 |
\add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/activitypub/1.0/nodeinfo2', 'top' ); |
| 92 |
} |
| 93 |
} |
| 94 |
\add_action( 'init', '\Activitypub\add_rewrite_rules', 1 ); |
| 95 |
|
| 96 |
/** |
| 97 |
* Flush rewrite rules; |
| 98 |
*/ |
| 99 |
function flush_rewrite_rules() { |
| 100 |
\Activitypub\add_rewrite_rules(); |
| 101 |
\flush_rewrite_rules(); |
| 102 |
} |
| 103 |
\register_activation_hook( __FILE__, '\Activitypub\flush_rewrite_rules' ); |
| 104 |
\register_deactivation_hook( __FILE__, '\flush_rewrite_rules' ); |
| 105 |
|