| 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.16.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_EXCERPT_LENGTH' ) || \define( 'ACTIVITYPUB_EXCERPT_LENGTH', 400 ); |
| 23 |
\defined( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS' ) || \define( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS', 3 ); |
| 24 |
\defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|(?<=<p>)|(?<=<br>)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))' ); |
| 25 |
\defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' ); |
| 26 |
\defined( 'ACTIVITYPUB_ALLOWED_HTML' ) || \define( 'ACTIVITYPUB_ALLOWED_HTML', '<strong><a><p><ul><ol><li><code><blockquote><pre><img>' ); |
| 27 |
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<p><strong>[ap_title]</strong></p>\n\n[ap_content]\n\n<p>[ap_hashtags]</p>\n\n<p>[ap_shortlink]</p>" ); |
| 28 |
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 29 |
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 30 |
\define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) ); |
| 31 |
|
| 32 |
require_once \dirname( __FILE__ ) . '/includes/table/followers-list.php'; |
| 33 |
require_once \dirname( __FILE__ ) . '/includes/class-signature.php'; |
| 34 |
require_once \dirname( __FILE__ ) . '/includes/class-webfinger.php'; |
| 35 |
require_once \dirname( __FILE__ ) . '/includes/peer/class-followers.php'; |
| 36 |
require_once \dirname( __FILE__ ) . '/includes/functions.php'; |
| 37 |
|
| 38 |
require_once \dirname( __FILE__ ) . '/includes/model/class-activity.php'; |
| 39 |
require_once \dirname( __FILE__ ) . '/includes/model/class-post.php'; |
| 40 |
|
| 41 |
require_once \dirname( __FILE__ ) . '/includes/class-activity-dispatcher.php'; |
| 42 |
\Activitypub\Activity_Dispatcher::init(); |
| 43 |
|
| 44 |
require_once \dirname( __FILE__ ) . '/includes/class-activitypub.php'; |
| 45 |
\Activitypub\Activitypub::init(); |
| 46 |
|
| 47 |
// Configure the REST API route |
| 48 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-outbox.php'; |
| 49 |
\Activitypub\Rest\Outbox::init(); |
| 50 |
|
| 51 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-inbox.php'; |
| 52 |
\Activitypub\Rest\Inbox::init(); |
| 53 |
|
| 54 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-followers.php'; |
| 55 |
\Activitypub\Rest\Followers::init(); |
| 56 |
|
| 57 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-following.php'; |
| 58 |
\Activitypub\Rest\Following::init(); |
| 59 |
|
| 60 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-webfinger.php'; |
| 61 |
\Activitypub\Rest\Webfinger::init(); |
| 62 |
|
| 63 |
// load NodeInfo endpoints only if blog is public |
| 64 |
if ( true === (bool) \get_option( 'blog_public', 1 ) ) { |
| 65 |
require_once \dirname( __FILE__ ) . '/includes/rest/class-nodeinfo.php'; |
| 66 |
\Activitypub\Rest\NodeInfo::init(); |
| 67 |
} |
| 68 |
|
| 69 |
require_once \dirname( __FILE__ ) . '/includes/class-admin.php'; |
| 70 |
\Activitypub\Admin::init(); |
| 71 |
|
| 72 |
require_once \dirname( __FILE__ ) . '/includes/class-hashtag.php'; |
| 73 |
\Activitypub\Hashtag::init(); |
| 74 |
|
| 75 |
require_once \dirname( __FILE__ ) . '/includes/class-shortcodes.php'; |
| 76 |
\Activitypub\Shortcodes::init(); |
| 77 |
|
| 78 |
require_once \dirname( __FILE__ ) . '/includes/class-mention.php'; |
| 79 |
\Activitypub\Mention::init(); |
| 80 |
|
| 81 |
require_once \dirname( __FILE__ ) . '/includes/class-debug.php'; |
| 82 |
\Activitypub\Debug::init(); |
| 83 |
|
| 84 |
require_once \dirname( __FILE__ ) . '/includes/class-health-check.php'; |
| 85 |
\Activitypub\Health_Check::init(); |
| 86 |
|
| 87 |
if ( \WP_DEBUG ) { |
| 88 |
require_once \dirname( __FILE__ ) . '/includes/debug.php'; |
| 89 |
} |
| 90 |
} |
| 91 |
\add_action( 'plugins_loaded', '\Activitypub\init' ); |
| 92 |
|
| 93 |
/** |
| 94 |
* Add plugin settings link |
| 95 |
*/ |
| 96 |
function plugin_settings_link( $actions ) { |
| 97 |
$settings_link[] = \sprintf( |
| 98 |
'<a href="%1s">%2s</a>', |
| 99 |
\menu_page_url( 'activitypub', false ), |
| 100 |
\__( 'Settings', 'activitypub' ) |
| 101 |
); |
| 102 |
|
| 103 |
return \array_merge( $settings_link, $actions ); |
| 104 |
} |
| 105 |
\add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), '\Activitypub\plugin_settings_link' ); |
| 106 |
|
| 107 |
/** |
| 108 |
* Add rewrite rules |
| 109 |
*/ |
| 110 |
function add_rewrite_rules() { |
| 111 |
if ( ! \class_exists( 'Webfinger' ) ) { |
| 112 |
\add_rewrite_rule( '^.well-known/webfinger', 'index.php?rest_route=/activitypub/1.0/webfinger', 'top' ); |
| 113 |
} |
| 114 |
|
| 115 |
if ( ! \class_exists( 'Nodeinfo' ) || ! (bool) \get_option( 'blog_public', 1 ) ) { |
| 116 |
\add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/activitypub/1.0/nodeinfo/discovery', 'top' ); |
| 117 |
\add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/activitypub/1.0/nodeinfo2', 'top' ); |
| 118 |
} |
| 119 |
|
| 120 |
\add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES ); |
| 121 |
} |
| 122 |
\add_action( 'init', '\Activitypub\add_rewrite_rules', 1 ); |
| 123 |
|
| 124 |
/** |
| 125 |
* Flush rewrite rules; |
| 126 |
*/ |
| 127 |
function flush_rewrite_rules() { |
| 128 |
\Activitypub\add_rewrite_rules(); |
| 129 |
\flush_rewrite_rules(); |
| 130 |
} |
| 131 |
\register_activation_hook( __FILE__, '\Activitypub\flush_rewrite_rules' ); |
| 132 |
\register_deactivation_hook( __FILE__, '\flush_rewrite_rules' ); |
| 133 |
|
| 134 |
/** |
| 135 |
* Only load code that needs BuddyPress to run once BP is loaded and initialized. |
| 136 |
*/ |
| 137 |
function enable_buddypress_features() { |
| 138 |
require_once \dirname( __FILE__ ) . '/integration/class-buddypress.php'; |
| 139 |
\Activitypub\Integration\Buddypress::init(); |
| 140 |
} |
| 141 |
add_action( 'bp_include', '\Activitypub\enable_buddypress_features' ); |
| 142 |
|