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

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