| @@ -1,45 +1,33 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Load the ActivityPub integrations. |
| 4 | - * | |
| 5 | - * @package Activitypub | |
| 6 | 4 | */ |
| 7 | 5 | |
| 8 | 6 | namespace Activitypub\Integration; |
| 9 | 7 | |
| 10 | -use Activitypub\Autoloader; | |
| 11 | - | |
| 12 | -use function Activitypub\site_supports_blocks; | |
| 13 | - | |
| 14 | -Autoloader::register_path( __NAMESPACE__, __DIR__ ); | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * Initialize the ActivityPub integrations. | |
| 18 | - */ | |
| 19 | 8 | function plugin_init() { |
| 20 | 9 | /** |
| 21 | - * Adds Akismet support. | |
| 10 | + * Adds WebFinger (plugin) support. | |
| 22 | 11 | * |
| 23 | - * This class handles the compatibility with the Akismet plugin. | |
| 12 | + * This class handles the compatibility with the WebFinger plugin | |
| 13 | + * and coordinates the internal WebFinger implementation. | |
| 24 | 14 | * |
| 25 | - * @see https://wordpress.org/plugins/akismet/ | |
| 15 | + * @see https://wordpress.org/plugins/webfinger/ | |
| 26 | 16 | */ |
| 27 | - if ( \defined( 'AKISMET_VERSION' ) ) { | |
| 28 | - Akismet::init(); | |
| 29 | - } | |
| 17 | + require_once __DIR__ . '/class-webfinger.php'; | |
| 18 | + Webfinger::init(); | |
| 30 | 19 | |
| 31 | 20 | /** |
| 32 | - * Adds Classic Editor support. | |
| 21 | + * Adds NodeInfo (plugin) support. | |
| 33 | 22 | * |
| 34 | - * This class handles the compatibility with the Classic Editor plugin | |
| 35 | - * and sites without block editor support. | |
| 23 | + * This class handles the compatibility with the NodeInfo plugin | |
| 24 | + * and coordinates the internal NodeInfo implementation. | |
| 36 | 25 | * |
| 37 | - * @see https://wordpress.org/plugins/classic-editor/ | |
| 26 | + * @see https://wordpress.org/plugins/nodeinfo/ | |
| 38 | 27 | */ |
| 39 | - if ( \class_exists( '\Classic_Editor' ) || \function_exists( 'classicpress_version' ) || ! site_supports_blocks() ) { | |
| 40 | - Classic_Editor::init(); | |
| 41 | - } | |
| 28 | + require_once __DIR__ . '/class-nodeinfo.php'; | |
| 29 | + Nodeinfo::init(); | |
| 42 | 30 | |
| 43 | 31 | /** |
| 44 | 32 | * Adds Enable Mastodon Apps support. |
| 45 | 33 | * |
| @@ -46,54 +34,12 @@ | ||
| 46 | 34 | * This class handles the compatibility with the Enable Mastodon Apps plugin. |
| 47 | 35 | * |
| 48 | 36 | * @see https://wordpress.org/plugins/enable-mastodon-apps/ |
| 49 | 37 | */ |
| 50 | - if ( \defined( 'ENABLE_MASTODON_APPS_VERSION' ) ) { | |
| 51 | - Enable_Mastodon_Apps::init(); | |
| 52 | - } | |
| 38 | + require_once __DIR__ . '/class-enable-mastodon-apps.php'; | |
| 39 | + Enable_Mastodon_Apps::init(); | |
| 53 | 40 | |
| 54 | 41 | /** |
| 55 | - * Adds Jetpack support. | |
| 56 | - * | |
| 57 | - * This class handles the compatibility with Jetpack. | |
| 58 | - * | |
| 59 | - * @see https://jetpack.com/ | |
| 60 | - */ | |
| 61 | - if ( \defined( 'JETPACK__VERSION' ) ) { | |
| 62 | - Jetpack::init(); | |
| 63 | - } | |
| 64 | - | |
| 65 | - /** | |
| 66 | - * Adds LiteSpeed Cache support. | |
| 67 | - * | |
| 68 | - * The check for whether LiteSpeed Cache is loaded and initialized happens inside Litespeed_Cache::init(). | |
| 69 | - * | |
| 70 | - * @see https://wordpress.org/plugins/litespeed-cache/ | |
| 71 | - */ | |
| 72 | - Litespeed_Cache::init(); | |
| 73 | - | |
| 74 | - /** | |
| 75 | - * Adds Multisite Language Switcher support. | |
| 76 | - * | |
| 77 | - * This class handles the compatibility with the Multisite Language Switcher plugin. | |
| 78 | - * | |
| 79 | - * @see https://wordpress.org/plugins/multisite-language-switcher/ | |
| 80 | - */ | |
| 81 | - if ( \defined( 'MSLS_PLUGIN_VERSION' ) ) { | |
| 82 | - Multisite_Language_Switcher::init(); | |
| 83 | - } | |
| 84 | - | |
| 85 | - /** | |
| 86 | - * Adds NodeInfo (plugin) support. | |
| 87 | - * | |
| 88 | - * This class handles the compatibility with the NodeInfo plugin | |
| 89 | - * and coordinates the internal NodeInfo implementation. | |
| 90 | - * | |
| 91 | - * @see https://wordpress.org/plugins/nodeinfo/ | |
| 92 | - */ | |
| 93 | - Nodeinfo::init(); | |
| 94 | - | |
| 95 | - /** | |
| 96 | 42 | * Adds OpenGraph support. |
| 97 | 43 | * |
| 98 | 44 | * This class handles the compatibility with the OpenGraph plugin. |
| 99 | 45 | * |
| @@ -99,37 +45,22 @@ | ||
| 99 | 45 | * |
| 100 | 46 | * @see https://wordpress.org/plugins/opengraph/ |
| 101 | 47 | */ |
| 102 | 48 | if ( '1' === \get_option( 'activitypub_use_opengraph', '1' ) ) { |
| 49 | + require_once __DIR__ . '/class-opengraph.php'; | |
| 103 | 50 | Opengraph::init(); |
| 104 | 51 | } |
| 105 | 52 | |
| 106 | 53 | /** |
| 107 | - * Adds Podlove Podcast Publisher support. | |
| 54 | + * Adds Jetpack support. | |
| 108 | 55 | * |
| 109 | - * This class handles the compatibility with Podlove Podcast Publisher. | |
| 56 | + * This class handles the compatibility with Jetpack. | |
| 110 | 57 | * |
| 111 | - * @see https://wordpress.org/plugins/podlove-podcasting-plugin-for-wordpress/ | |
| 58 | + * @see https://jetpack.com/ | |
| 112 | 59 | */ |
| 113 | - if ( \defined( 'Podlove\PLUGIN_FILE' ) ) { | |
| 114 | - // Enable ActivityPub support for the podcast post type. | |
| 115 | - \add_post_type_support( 'podcast', 'activitypub' ); | |
| 116 | - | |
| 117 | - \add_filter( | |
| 118 | - 'activitypub_transformer', | |
| 119 | - static function ( $transformer, $data, $object_class ) { | |
| 120 | - if ( | |
| 121 | - 'WP_Post' === $object_class && | |
| 122 | - 'podcast' === $data->post_type && | |
| 123 | - \Podlove\Model\Episode::find_one_by_post_id( $data->ID ) | |
| 124 | - ) { | |
| 125 | - return new Podlove_Podcast_Publisher( $data ); | |
| 126 | - } | |
| 127 | - return $transformer; | |
| 128 | - }, | |
| 129 | - 10, | |
| 130 | - 3 | |
| 131 | - ); | |
| 60 | + if ( \defined( 'JETPACK__VERSION' ) && ! \defined( 'IS_WPCOM' ) ) { | |
| 61 | + require_once __DIR__ . '/class-jetpack.php'; | |
| 62 | + Jetpack::init(); | |
| 132 | 63 | } |
| 133 | 64 | |
| 134 | 65 | /** |
| 135 | 66 | * Adds Seriously Simple Podcasting support. |
| @@ -138,16 +69,18 @@ | ||
| 138 | 69 | * |
| 139 | 70 | * @see https://wordpress.org/plugins/seriously-simple-podcasting/ |
| 140 | 71 | */ |
| 141 | 72 | if ( \defined( 'SSP_VERSION' ) ) { |
| 142 | - \add_filter( | |
| 73 | + add_filter( | |
| 143 | 74 | 'activitypub_transformer', |
| 144 | - static function ( $transformer, $data, $object_class ) { | |
| 75 | + // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound | |
| 76 | + function( $transformer, $object, $object_class ) { | |
| 145 | 77 | if ( |
| 146 | 78 | 'WP_Post' === $object_class && |
| 147 | - \get_post_meta( $data->ID, 'audio_file', true ) | |
| 79 | + \get_post_meta( $object->ID, 'audio_file', true ) | |
| 148 | 80 | ) { |
| 149 | - return new Seriously_Simple_Podcasting( $data ); | |
| 81 | + require_once __DIR__ . '/class-seriously-simple-podcasting.php'; | |
| 82 | + return new Seriously_Simple_Podcasting( $object ); | |
| 150 | 83 | } |
| 151 | 84 | return $transformer; |
| 152 | 85 | }, |
| 153 | 86 | 10, |
| @@ -153,69 +86,53 @@ | ||
| 153 | 86 | 10, |
| 154 | 87 | 3 |
| 155 | 88 | ); |
| 156 | 89 | } |
| 90 | +} | |
| 91 | +\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' ); | |
| 157 | 92 | |
| 158 | - /** | |
| 159 | - * Adds Stream support. | |
| 160 | - * | |
| 161 | - * This class handles the compatibility with the Stream plugin. | |
| 162 | - * | |
| 163 | - * @see https://wordpress.org/plugins/stream/ | |
| 164 | - */ | |
| 165 | - Stream\Stream::init(); | |
| 93 | +/** | |
| 94 | + * Register the Stream Connector for ActivityPub. | |
| 95 | + * | |
| 96 | + * @param array $classes The Stream connectors. | |
| 97 | + * | |
| 98 | + * @return array The Stream connectors with the ActivityPub connector. | |
| 99 | + */ | |
| 100 | +function register_stream_connector( $classes ) { | |
| 101 | + require plugin_dir_path( __FILE__ ) . '/class-stream-connector.php'; | |
| 166 | 102 | |
| 167 | - /** | |
| 168 | - * Adds Surge support. | |
| 169 | - * | |
| 170 | - * Only load code that needs Surge to run once Surge is loaded and initialized. | |
| 171 | - * | |
| 172 | - * @see https://wordpress.org/plugins/surge/ | |
| 173 | - */ | |
| 174 | - Surge::init(); | |
| 103 | + $class_name = '\Activitypub\Integration\Stream_Connector'; | |
| 175 | 104 | |
| 176 | - /** | |
| 177 | - * Adds WebFinger (plugin) support. | |
| 178 | - * | |
| 179 | - * This class handles the compatibility with the WebFinger plugin | |
| 180 | - * and coordinates the internal WebFinger implementation. | |
| 181 | - * | |
| 182 | - * @see https://wordpress.org/plugins/webfinger/ | |
| 183 | - */ | |
| 184 | - Webfinger::init(); | |
| 105 | + if ( ! class_exists( $class_name ) ) { | |
| 106 | + return; | |
| 107 | + } | |
| 185 | 108 | |
| 186 | - /** | |
| 187 | - * Adds WPML Multilingual CMS (plugin) support. | |
| 188 | - * | |
| 189 | - * This class handles the compatibility with the WPML plugin. | |
| 190 | - * | |
| 191 | - * @see https://wpml.org/ | |
| 192 | - */ | |
| 193 | - if ( \defined( 'ICL_SITEPRESS_VERSION' ) ) { | |
| 194 | - WPML::init(); | |
| 109 | + wp_stream_get_instance(); | |
| 110 | + $class = new $class_name(); | |
| 111 | + | |
| 112 | + if ( ! method_exists( $class, 'is_dependency_satisfied' ) ) { | |
| 113 | + return; | |
| 195 | 114 | } |
| 196 | 115 | |
| 197 | - /** | |
| 198 | - * Adds Yoast SEO support. | |
| 199 | - * | |
| 200 | - * This class handles the compatibility with Yoast SEO. | |
| 201 | - * | |
| 202 | - * @see https://wordpress.org/plugins/wordpress-seo/ | |
| 203 | - */ | |
| 204 | - if ( \defined( 'WPSEO_VERSION' ) ) { | |
| 205 | - Yoast_Seo::init(); | |
| 116 | + if ( $class->is_dependency_satisfied() ) { | |
| 117 | + $classes[] = $class; | |
| 206 | 118 | } |
| 119 | + | |
| 120 | + return $classes; | |
| 207 | 121 | } |
| 208 | -\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' ); | |
| 122 | +add_filter( 'wp_stream_connectors', __NAMESPACE__ . '\register_stream_connector' ); | |
| 209 | 123 | |
| 210 | -// Register activation and deactivation hooks for Surge integration. | |
| 211 | -\register_activation_hook( ACTIVITYPUB_PLUGIN_FILE, array( __NAMESPACE__ . '\Surge', 'add_cache_config' ) ); | |
| 212 | -\register_deactivation_hook( ACTIVITYPUB_PLUGIN_FILE, array( __NAMESPACE__ . '\Surge', 'remove_cache_config' ) ); | |
| 124 | +// Excluded ActivityPub post types from the Stream. | |
| 125 | +add_filter( | |
| 126 | + 'wp_stream_posts_exclude_post_types', | |
| 127 | + function( $post_types ) { | |
| 128 | + $post_types[] = 'ap_follower'; | |
| 129 | + $post_types[] = 'ap_extrafield'; | |
| 130 | + $post_types[] = 'ap_extrafield_blog'; | |
| 131 | + return $post_types; | |
| 132 | + } | |
| 133 | +); | |
| 213 | 134 | |
| 214 | -// Register activation and deactivation hooks for LiteSpeed Cache integration. | |
| 215 | -\register_activation_hook( ACTIVITYPUB_PLUGIN_FILE, array( __NAMESPACE__ . '\LiteSpeed_Cache', 'add_htaccess_rules' ) ); | |
| 216 | -\register_deactivation_hook( ACTIVITYPUB_PLUGIN_FILE, array( __NAMESPACE__ . '\LiteSpeed_Cache', 'remove_htaccess_rules' ) ); | |
| 217 | - | |
| 218 | 135 | /** |
| 219 | 136 | * Load the BuddyPress integration. |
| 220 | 137 | * |
| 221 | 138 | * Only load code that needs BuddyPress to run once BP is loaded and initialized. |
| @@ -221,5 +138,12 @@ | ||
| 221 | 138 | * Only load code that needs BuddyPress to run once BP is loaded and initialized. |
| 222 | 139 | * |
| 223 | 140 | * @see https://buddypress.org/ |
| 224 | 141 | */ |
| 225 | -\add_action( 'bp_include', array( __NAMESPACE__ . '\Buddypress', 'init' ), 0 ); | |
| 142 | +add_action( | |
| 143 | + 'bp_include', | |
| 144 | + function () { | |
| 145 | + require_once __DIR__ . '/class-buddypress.php'; | |
| 146 | + Buddypress::init(); | |
| 147 | + }, | |
| 148 | + 0 | |
| 149 | +); | |