PluginProbe
ActivityPub / 1.0.2
ActivityPub v1.0.2
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 1.0.2, at activitypub.php

201 lines 5.6 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: 1.0.2
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: 5.6
12 * Text Domain: activitypub
13 * Domain Path: /languages
14 */
15
16 namespace Activitypub;
17
18 use function Activitypub\site_supports_blocks;
19
20 \defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
21
22 /**
23 * Initialize plugin
24 */
25 function init() {
26 \defined( 'ACTIVITYPUB_EXCERPT_LENGTH' ) || \define( 'ACTIVITYPUB_EXCERPT_LENGTH', 400 );
27 \defined( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS' ) || \define( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS', true );
28 \defined( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS' ) || \define( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS', 3 );
29 \defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|(?<=<p>)|(?<=<br>)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))' );
30 \defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' );
31 \defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<strong>[ap_title]</strong>\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" );
32 \defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) || \define( 'ACTIVITYPUB_AUTHORIZED_FETCH', false );
33
34 \define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
35 \define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
36 \define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) );
37 \define( 'ACTIVITYPUB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
38
39 Migration::init();
40 Activitypub::init();
41 Activity_Dispatcher::init();
42 Collection\Followers::init();
43
44 // Configure the REST API route
45 Rest\Users::init();
46 Rest\Outbox::init();
47 Rest\Inbox::init();
48 Rest\Followers::init();
49 Rest\Following::init();
50 Rest\Webfinger::init();
51 Rest\Server::init();
52 Rest\Collection::init();
53
54 Admin::init();
55 Hashtag::init();
56 Shortcodes::init();
57 Mention::init();
58 Health_Check::init();
59 Scheduler::init();
60
61 if ( site_supports_blocks() ) {
62 Blocks::init();
63 }
64 }
65 \add_action( 'init', __NAMESPACE__ . '\init' );
66
67 /**
68 * Class Autoloader
69 */
70 spl_autoload_register(
71 function ( $full_class ) {
72 $base_dir = __DIR__ . '/includes/';
73 $base = 'Activitypub\\';
74
75 if ( strncmp( $full_class, $base, strlen( $base ) ) === 0 ) {
76 $maybe_uppercase = str_replace( $base, '', $full_class );
77 $class = strtolower( $maybe_uppercase );
78 // All classes should be capitalized. If this is instead looking for a lowercase method, we ignore that.
79 if ( $maybe_uppercase === $class ) {
80 return;
81 }
82
83 if ( false !== strpos( $class, '\\' ) ) {
84 $parts = explode( '\\', $class );
85 $class = array_pop( $parts );
86 $sub_dir = implode( '/', $parts );
87 $base_dir = $base_dir . $sub_dir . '/';
88 }
89
90 $filename = 'class-' . strtr( $class, '_', '-' );
91 $file = $base_dir . $filename . '.php';
92
93 if ( file_exists( $file ) && is_readable( $file ) ) {
94 require_once $file;
95 } else {
96 // translators: %s is the class name
97 \wp_die( sprintf( esc_html__( 'Required class not found or not readable: %s', 'activitypub' ), esc_html( $full_class ) ) );
98 }
99 }
100 }
101 );
102
103 require_once __DIR__ . '/includes/functions.php';
104
105 // load NodeInfo endpoints only if blog is public
106 if ( \get_option( 'blog_public', 1 ) ) {
107 Rest\NodeInfo::init();
108 }
109
110 $debug_file = __DIR__ . '/includes/debug.php';
111 if ( \WP_DEBUG && file_exists( $debug_file ) && is_readable( $debug_file ) ) {
112 require_once $debug_file;
113 Debug::init();
114 }
115
116 /**
117 * Add plugin settings link
118 */
119 function plugin_settings_link( $actions ) {
120 $settings_link = array();
121 $settings_link[] = \sprintf(
122 '<a href="%1s">%2s</a>',
123 \menu_page_url( 'activitypub', false ),
124 \__( 'Settings', 'activitypub' )
125 );
126
127 return \array_merge( $settings_link, $actions );
128 }
129 \add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), __NAMESPACE__ . '\plugin_settings_link' );
130
131 \register_activation_hook(
132 __FILE__,
133 array(
134 __NAMESPACE__ . '\Activitypub',
135 'activate',
136 )
137 );
138
139 \register_deactivation_hook(
140 __FILE__,
141 array(
142 __NAMESPACE__ . '\Activitypub',
143 'deactivate',
144 )
145 );
146
147 \register_uninstall_hook(
148 __FILE__,
149 array(
150 __NAMESPACE__ . '\Activitypub',
151 'uninstall',
152 )
153 );
154
155 /**
156 * Only load code that needs BuddyPress to run once BP is loaded and initialized.
157 */
158 add_action(
159 'bp_include',
160 function() {
161 require_once __DIR__ . '/integration/class-buddypress.php';
162 Integration\Buddypress::init();
163 },
164 0
165 );
166
167 /**
168 * `get_plugin_data` wrapper
169 *
170 * @return array The plugin metadata array
171 */
172 function get_plugin_meta( $default_headers = array() ) {
173 if ( ! $default_headers ) {
174 $default_headers = array(
175 'Name' => 'Plugin Name',
176 'PluginURI' => 'Plugin URI',
177 'Version' => 'Version',
178 'Description' => 'Description',
179 'Author' => 'Author',
180 'AuthorURI' => 'Author URI',
181 'TextDomain' => 'Text Domain',
182 'DomainPath' => 'Domain Path',
183 'Network' => 'Network',
184 'RequiresWP' => 'Requires at least',
185 'RequiresPHP' => 'Requires PHP',
186 'UpdateURI' => 'Update URI',
187 );
188 }
189
190 return \get_file_data( __FILE__, $default_headers, 'plugin' );
191 }
192
193 /**
194 * Plugin Version Number used for caching.
195 */
196 function get_plugin_version() {
197 $meta = get_plugin_meta( array( 'Version' => 'Version' ) );
198
199 return $meta['Version'];
200 }
201