PluginProbe
ActivityPub / 4.3.0
ActivityPub v4.3.0
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / activitypub.php

activitypub.php in ActivityPub 4.3.0, at activitypub.php

219 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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: 4.3.0
7 * Author: Matthias Pfefferle & Automattic
8 * Author URI: https://automattic.com/
9 * License: MIT
10 * License URI: http://opensource.org/licenses/MIT
11 * Requires PHP: 7.0
12 * Text Domain: activitypub
13 * Domain Path: /languages
14 *
15 * @package Activitypub
16 */
17
18 namespace Activitypub;
19
20 use WP_CLI;
21
22 \define( 'ACTIVITYPUB_PLUGIN_VERSION', '4.3.0' );
23
24 // Plugin related constants.
25 \define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
26 \define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
27 \define( 'ACTIVITYPUB_PLUGIN_FILE', ACTIVITYPUB_PLUGIN_DIR . basename( __FILE__ ) );
28 \define( 'ACTIVITYPUB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
29
30 require_once __DIR__ . '/includes/compat.php';
31 require_once __DIR__ . '/includes/functions.php';
32 require_once __DIR__ . '/includes/constants.php';
33
34 /**
35 * Initialize REST routes.
36 */
37 function rest_init() {
38 Rest\Actors::init();
39 Rest\Outbox::init();
40 Rest\Inbox::init();
41 Rest\Followers::init();
42 Rest\Following::init();
43 Rest\Webfinger::init();
44 Rest\Comment::init();
45 Rest\Server::init();
46 Rest\Collection::init();
47 Rest\Interaction::init();
48
49 // Load NodeInfo endpoints only if blog is public.
50 if ( is_blog_public() ) {
51 Rest\NodeInfo::init();
52 }
53 }
54 \add_action( 'rest_api_init', __NAMESPACE__ . '\rest_init' );
55
56 /**
57 * Initialize plugin.
58 */
59 function plugin_init() {
60 \add_action( 'init', array( __NAMESPACE__ . '\Migration', 'init' ) );
61 \add_action( 'init', array( __NAMESPACE__ . '\Activitypub', 'init' ) );
62 \add_action( 'init', array( __NAMESPACE__ . '\Activity_Dispatcher', 'init' ) );
63 \add_action( 'init', array( __NAMESPACE__ . '\Handler', 'init' ) );
64 \add_action( 'init', array( __NAMESPACE__ . '\Admin', 'init' ) );
65 \add_action( 'init', array( __NAMESPACE__ . '\Hashtag', 'init' ) );
66 \add_action( 'init', array( __NAMESPACE__ . '\Mention', 'init' ) );
67 \add_action( 'init', array( __NAMESPACE__ . '\Health_Check', 'init' ) );
68 \add_action( 'init', array( __NAMESPACE__ . '\Scheduler', 'init' ) );
69 \add_action( 'init', array( __NAMESPACE__ . '\Comment', 'init' ) );
70 \add_action( 'init', array( __NAMESPACE__ . '\Link', 'init' ) );
71
72 if ( site_supports_blocks() ) {
73 \add_action( 'init', array( __NAMESPACE__ . '\Blocks', 'init' ) );
74 }
75
76 $debug_file = __DIR__ . '/includes/debug.php';
77 if ( \WP_DEBUG && file_exists( $debug_file ) && is_readable( $debug_file ) ) {
78 require_once $debug_file;
79 Debug::init();
80 }
81 }
82 \add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );
83
84
85 /**
86 * Class Autoloader.
87 */
88 \spl_autoload_register(
89 function ( $full_class ) {
90 $base_dir = __DIR__ . '/includes/';
91 $base = 'Activitypub\\';
92
93 if ( strncmp( $full_class, $base, strlen( $base ) ) === 0 ) {
94 $maybe_uppercase = str_replace( $base, '', $full_class );
95 $class = strtolower( $maybe_uppercase );
96 // All classes should be capitalized. If this is instead looking for a lowercase method, we ignore that.
97 if ( $maybe_uppercase === $class ) {
98 return;
99 }
100
101 if ( false !== strpos( $class, '\\' ) ) {
102 $parts = explode( '\\', $class );
103 $class = array_pop( $parts );
104 $sub_dir = strtr( implode( '/', $parts ), '_', '-' );
105 $base_dir = $base_dir . $sub_dir . '/';
106 }
107
108 $filename = 'class-' . strtr( $class, '_', '-' );
109 $file = $base_dir . $filename . '.php';
110
111 if ( file_exists( $file ) && is_readable( $file ) ) {
112 require_once $file;
113 } else {
114 // translators: %s is the class name.
115 $message = sprintf( esc_html__( 'Required class not found or not readable: %s', 'activitypub' ), esc_html( $full_class ) );
116 Debug::write_log( $message );
117 \wp_die( $message ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
118 }
119 }
120 }
121 );
122
123 /**
124 * Add plugin settings link.
125 *
126 * @param array $actions The current actions.
127 */
128 function plugin_settings_link( $actions ) {
129 $settings_link = array();
130 $settings_link[] = \sprintf(
131 '<a href="%1s">%2s</a>',
132 \menu_page_url( 'activitypub', false ),
133 \__( 'Settings', 'activitypub' )
134 );
135
136 return \array_merge( $settings_link, $actions );
137 }
138 \add_filter( 'plugin_action_links_' . ACTIVITYPUB_PLUGIN_BASENAME, __NAMESPACE__ . '\plugin_settings_link' );
139
140 \register_activation_hook(
141 __FILE__,
142 array(
143 __NAMESPACE__ . '\Activitypub',
144 'activate',
145 )
146 );
147
148 \register_deactivation_hook(
149 __FILE__,
150 array(
151 __NAMESPACE__ . '\Activitypub',
152 'deactivate',
153 )
154 );
155
156 \register_uninstall_hook(
157 __FILE__,
158 array(
159 __NAMESPACE__ . '\Activitypub',
160 'uninstall',
161 )
162 );
163
164 // Load integrations.
165 require_once __DIR__ . '/integration/load.php';
166
167 /**
168 * `get_plugin_data` wrapper.
169 *
170 * @deprecated 4.2.0 Use `get_plugin_data` instead.
171 *
172 * @param array $default_headers Optional. The default plugin headers. Default empty array.
173 * @return array The plugin metadata array.
174 */
175 function get_plugin_meta( $default_headers = array() ) {
176 _deprecated_function( __FUNCTION__, '4.2.0', 'get_plugin_data' );
177
178 if ( ! $default_headers ) {
179 $default_headers = array(
180 'Name' => 'Plugin Name',
181 'PluginURI' => 'Plugin URI',
182 'Version' => 'Version',
183 'Description' => 'Description',
184 'Author' => 'Author',
185 'AuthorURI' => 'Author URI',
186 'TextDomain' => 'Text Domain',
187 'DomainPath' => 'Domain Path',
188 'Network' => 'Network',
189 'RequiresWP' => 'Requires at least',
190 'RequiresPHP' => 'Requires PHP',
191 'UpdateURI' => 'Update URI',
192 );
193 }
194
195 return \get_file_data( __FILE__, $default_headers, 'plugin' );
196 }
197
198 /**
199 * Plugin Version Number used for caching.
200 *
201 * @deprecated 4.2.0 Use constant ACTIVITYPUB_PLUGIN_VERSION directly.
202 */
203 function get_plugin_version() {
204 _deprecated_function( __FUNCTION__, '4.2.0', 'ACTIVITYPUB_PLUGIN_VERSION' );
205
206 return ACTIVITYPUB_PLUGIN_VERSION;
207 }
208
209 // Check for CLI env, to add the CLI commands.
210 if ( defined( 'WP_CLI' ) && WP_CLI ) {
211 WP_CLI::add_command(
212 'activitypub',
213 '\Activitypub\Cli',
214 array(
215 'shortdesc' => 'ActivityPub related commands to manage plugin functionality and the federation of posts and comments.',
216 )
217 );
218 }
219