PluginProbe
ActivityPub / 5.3.1
ActivityPub v5.3.1
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 / includes / wp-admin / class-settings.php

class-settings.php in ActivityPub 5.3.1, at includes/wp-admin/class-settings.php

398 lines 17.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Settings file.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\WP_Admin;
9
10 use Activitypub\Collection\Actors;
11 use Activitypub\Model\Blog;
12 use function Activitypub\is_user_disabled;
13
14 /**
15 * ActivityPub Settings Class.
16 */
17 class Settings {
18 /**
19 * Initialize the class, registering WordPress hooks,
20 */
21 public static function init() {
22 \add_action( 'admin_init', array( self::class, 'register_settings' ), 11 );
23 \add_action( 'admin_menu', array( self::class, 'add_settings_page' ) );
24 }
25
26 /**
27 * Register ActivityPub settings
28 */
29 public static function register_settings() {
30 \register_setting(
31 'activitypub',
32 'activitypub_post_content_type',
33 array(
34 'type' => 'string',
35 'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ),
36 'show_in_rest' => array(
37 'schema' => array(
38 'enum' => array( 'title', 'excerpt', 'content' ),
39 ),
40 ),
41 'default' => 'content',
42 )
43 );
44
45 \register_setting(
46 'activitypub',
47 'activitypub_custom_post_content',
48 array(
49 'type' => 'string',
50 'description' => \__( 'Define your own custom post template', 'activitypub' ),
51 'show_in_rest' => true,
52 'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT,
53 )
54 );
55
56 \register_setting(
57 'activitypub',
58 'activitypub_max_image_attachments',
59 array(
60 'type' => 'integer',
61 'description' => \__( 'Number of images to attach to posts.', 'activitypub' ),
62 'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS,
63 )
64 );
65
66 \register_setting(
67 'activitypub',
68 'activitypub_outbox_purge_days',
69 array(
70 'type' => 'integer',
71 'description' => \__( 'Number of days to keep items in the Outbox.', 'activitypub' ),
72 'default' => 180,
73 )
74 );
75
76 \register_setting(
77 'activitypub',
78 'activitypub_object_type',
79 array(
80 'type' => 'string',
81 'description' => \__( 'The Activity-Object-Type', 'activitypub' ),
82 'show_in_rest' => array(
83 'schema' => array(
84 'enum' => array( 'note', 'wordpress-post-format' ),
85 ),
86 ),
87 'default' => ACTIVITYPUB_DEFAULT_OBJECT_TYPE,
88 )
89 );
90
91 \register_setting(
92 'activitypub',
93 'activitypub_use_hashtags',
94 array(
95 'type' => 'boolean',
96 'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ),
97 'default' => '0',
98 )
99 );
100
101 \register_setting(
102 'activitypub',
103 'activitypub_use_opengraph',
104 array(
105 'type' => 'boolean',
106 'description' => \__( 'Automatically add "fediverse:creator" OpenGraph tags for Authors and the Blog-User.', 'activitypub' ),
107 'default' => '1',
108 )
109 );
110
111 \register_setting(
112 'activitypub',
113 'activitypub_support_post_types',
114 array(
115 'type' => 'string',
116 'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ),
117 'show_in_rest' => true,
118 'default' => array( 'post' ),
119 )
120 );
121
122 \register_setting(
123 'activitypub',
124 'activitypub_actor_mode',
125 array(
126 'type' => 'integer',
127 'description' => \__( 'Choose your preferred Actor-Mode.', 'activitypub' ),
128 'default' => ACTIVITYPUB_ACTOR_MODE,
129 )
130 );
131
132 \register_setting(
133 'activitypub',
134 'activitypub_attribution_domains',
135 array(
136 'type' => 'string',
137 'description' => \__( 'Websites allowed to credit you.', 'activitypub' ),
138 'default' => \Activitypub\home_host(),
139 'sanitize_callback' => function ( $value ) {
140 $value = explode( PHP_EOL, $value );
141 $value = array_filter( array_map( 'trim', $value ) );
142 $value = array_filter( array_map( 'esc_attr', $value ) );
143 $value = implode( PHP_EOL, $value );
144
145 return $value;
146 },
147 )
148 );
149
150 \register_setting(
151 'activitypub',
152 'activitypub_authorized_fetch',
153 array(
154 'type' => 'boolean',
155 'description' => \__( 'Require HTTP signature authentication.', 'activitypub' ),
156 'default' => false,
157 )
158 );
159
160 \register_setting(
161 'activitypub',
162 'activitypub_mailer_new_follower',
163 array(
164 'type' => 'boolean',
165 'description' => \__( 'Send notifications via e-mail when a new follower is added.', 'activitypub' ),
166 'default' => '0',
167 )
168 );
169
170 \register_setting(
171 'activitypub',
172 'activitypub_mailer_new_dm',
173 array(
174 'type' => 'boolean',
175 'description' => \__( 'Send notifications via e-mail when a direct message is received.', 'activitypub' ),
176 'default' => '0',
177 )
178 );
179
180 // Blog-User Settings.
181 \register_setting(
182 'activitypub_blog',
183 'activitypub_blog_description',
184 array(
185 'type' => 'string',
186 'description' => \esc_html__( 'The Description of the Blog-User', 'activitypub' ),
187 'show_in_rest' => true,
188 'default' => '',
189 )
190 );
191
192 \register_setting(
193 'activitypub_blog',
194 'activitypub_blog_identifier',
195 array(
196 'type' => 'string',
197 'description' => \esc_html__( 'The Identifier of the Blog-User', 'activitypub' ),
198 'show_in_rest' => true,
199 'default' => Blog::get_default_username(),
200 'sanitize_callback' => function ( $value ) {
201 // Hack to allow dots in the username.
202 $parts = explode( '.', $value );
203 $sanitized = array();
204
205 foreach ( $parts as $part ) {
206 $sanitized[] = \sanitize_title( $part );
207 }
208
209 $sanitized = implode( '.', $sanitized );
210
211 // Check for login or nicename.
212 $user = new \WP_User_Query(
213 array(
214 'search' => $sanitized,
215 'search_columns' => array( 'user_login', 'user_nicename' ),
216 'number' => 1,
217 'hide_empty' => true,
218 'fields' => 'ID',
219 )
220 );
221
222 if ( $user->results ) {
223 add_settings_error(
224 'activitypub_blog_identifier',
225 'activitypub_blog_identifier',
226 \esc_html__( 'You cannot use an existing author\'s name for the blog profile ID.', 'activitypub' ),
227 'error'
228 );
229
230 return Blog::get_default_username();
231 }
232
233 return $sanitized;
234 },
235 )
236 );
237
238 \register_setting(
239 'activitypub_blog',
240 'activitypub_header_image',
241 array(
242 'type' => 'integer',
243 'description' => \__( 'The Attachment-ID of the Sites Header-Image', 'activitypub' ),
244 'default' => null,
245 )
246 );
247 }
248
249 /**
250 * Load settings page.
251 */
252 public static function settings_page() {
253 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
254 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'welcome';
255
256 $settings_tabs = array(
257 'welcome' => array(
258 'label' => __( 'Welcome', 'activitypub' ),
259 'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/welcome.php',
260 ),
261 'settings' => array(
262 'label' => __( 'Settings', 'activitypub' ),
263 'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php',
264 ),
265 );
266 if ( ! is_user_disabled( Actors::BLOG_USER_ID ) ) {
267 $settings_tabs['blog-profile'] = array(
268 'label' => __( 'Blog Profile', 'activitypub' ),
269 'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-settings.php',
270 );
271 $settings_tabs['followers'] = array(
272 'label' => __( 'Followers', 'activitypub' ),
273 'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-followers-list.php',
274 );
275 }
276
277 /**
278 * Filters the tabs displayed in the ActivityPub settings.
279 *
280 * @param array $settings_tabs The tabs to display.
281 */
282 $custom_tabs = \apply_filters( 'activitypub_admin_settings_tabs', array() );
283 $settings_tabs = \array_merge( $settings_tabs, $custom_tabs );
284
285 switch ( $tab ) {
286 case 'blog-profile':
287 wp_enqueue_media();
288 wp_enqueue_script( 'activitypub-header-image' );
289 break;
290 case 'welcome':
291 wp_enqueue_script( 'plugin-install' );
292 add_thickbox();
293 wp_enqueue_script( 'updates' );
294 break;
295 }
296
297 $labels = wp_list_pluck( $settings_tabs, 'label' );
298 $args = array_fill_keys( array_keys( $labels ), '' );
299 $args[ $tab ] = 'active';
300 $args['tabs'] = $labels;
301
302 \load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/admin-header.php', true, $args );
303 \load_template( $settings_tabs[ $tab ]['template'] );
304 }
305
306 /**
307 * Adds the ActivityPub settings to the Help tab.
308 */
309 public static function add_settings_help_tab() {
310 $code_html = array( 'code' => array() );
311 $anchor_html = array(
312 'a' => array(
313 'href' => true,
314 'target' => true,
315 ),
316 );
317
318 \get_current_screen()->add_help_tab(
319 array(
320 'id' => 'template-tags',
321 'title' => \__( 'Template Tags', 'activitypub' ),
322 'content' => '<h2>' . \esc_html__( 'The following Template Tags are available:', 'activitypub' ) . '</h2>' . "\n" .
323 '<dl>' . "\n" .
324 '<dt><code>[ap_title]</code></dt>' . "\n" .
325 '<dd>' . \esc_html__( 'The post&#8217;s title.', 'activitypub' ) . '</dd>' . "\n" .
326 '<dt><code>[ap_content apply_filters="yes"]</code></dt>' . "\n" .
327 '<dd>' . \wp_kses( \__( 'The post&#8217;s content. With <code>apply_filters</code> you can decide if filters (<code>apply_filters( \'the_content\', $content )</code>) should be applied or not (default is <code>yes</code>). The values can be <code>yes</code> or <code>no</code>. <code>apply_filters</code> attribute is optional.', 'activitypub' ), $code_html ) . '</dd>' . "\n" .
328 '<dt><code>[ap_excerpt length="400"]</code></dt>' . "\n" .
329 '<dd>' . \wp_kses( \__( 'The post&#8217;s excerpt (uses <code>the_excerpt</code> if that is set). If no excerpt is provided, will truncate at <code>length</code> (optional, default = 400).', 'activitypub' ), $code_html ) . '</dd>' . "\n" .
330 '<dt><code>[ap_permalink type="url"]</code></dt>' . "\n" .
331 '<dd>' . \wp_kses( \__( 'The post&#8217;s permalink. <code>type</code> can be either: <code>url</code> or <code>html</code> (an &lt;a /&gt; tag). <code>type</code> attribute is optional.', 'activitypub' ), $code_html ) . '</dd>' . "\n" .
332 '<dt><code>[ap_shortlink type="url"]</code></dt>' . "\n" .
333 '<dd>' . \wp_kses( \__( 'The post&#8217;s shortlink. <code>type</code> can be either <code>url</code> or <code>html</code> (an &lt;a /&gt; tag). I can recommend <a href="https://wordpress.org/plugins/hum/" target="_blank">Hum</a>, to prettify the Shortlinks. <code>type</code> attribute is optional.', 'activitypub' ), $code_html ) . '</dd>' . "\n" .
334 '<dt><code>[ap_hashtags]</code></dt>' . "\n" .
335 '<dd>' . \esc_html__( 'The post&#8217;s tags as hashtags.', 'activitypub' ) . '</dd>' . "\n" .
336 '<dt><code>[ap_hashcats]</code></dt>' . "\n" .
337 '<dd>' . \esc_html__( 'The post&#8217;s categories as hashtags.', 'activitypub' ) . '</dd>' . "\n" .
338 '<dt><code>[ap_image type=full]</code></dt>' . "\n" .
339 '<dd>' . \wp_kses( __( 'The URL for the post&#8217;s featured image, defaults to full size. The type attribute can be any of the following: <code>thumbnail</code>, <code>medium</code>, <code>large</code>, <code>full</code>. <code>type</code> attribute is optional.', 'activitypub' ), $code_html ) . '</dd>' . "\n" .
340 '<dt><code>[ap_author]</code></dt>' . "\n" .
341 '<dd>' . \esc_html__( 'The author&#8217;s name.', 'activitypub' ) . '</dd>' . "\n" .
342 '<dt><code>[ap_authorurl]</code></dt>' . "\n" .
343 '<dd>' . \esc_html__( 'The URL to the author&#8217;s profile page.', 'activitypub' ) . '</dd>' . "\n" .
344 '<dt><code>[ap_date]</code></dt>' . "\n" .
345 '<dd>' . \esc_html__( 'The post&#8217;s date.', 'activitypub' ) . '</dd>' . "\n" .
346 '<dt><code>[ap_time]</code></dt>' . "\n" .
347 '<dd>' . \esc_html__( 'The post&#8217;s time.', 'activitypub' ) . '</dd>' . "\n" .
348 '<dt><code>[ap_datetime]</code></dt>' . "\n" .
349 '<dd>' . \esc_html__( 'The post&#8217;s date/time formated as "date @ time".', 'activitypub' ) . '</dd>' . "\n" .
350 '<dt><code>[ap_blogurl]</code></dt>' . "\n" .
351 '<dd>' . \esc_html__( 'The URL to the site.', 'activitypub' ) . '</dd>' . "\n" .
352 '<dt><code>[ap_blogname]</code></dt>' . "\n" .
353 '<dd>' . \esc_html__( 'The name of the site.', 'activitypub' ) . '</dd>' . "\n" .
354 '<dt><code>[ap_blogdesc]</code></dt>' . "\n" .
355 '<dd>' . \esc_html__( 'The description of the site.', 'activitypub' ) . '</dd>' . "\n" .
356 '</dl>' . "\n" .
357 '<p>' . \esc_html__( 'You may also use any Shortcode normally available to you on your site, however be aware that Shortcodes may significantly increase the size of your content depending on what they do.', 'activitypub' ) . '</p>' . "\n" .
358 '<p>' . \esc_html__( 'Note: the old Template Tags are now deprecated and automatically converted to the new ones.', 'activitypub' ) . '</p>' . "\n" .
359 '<p>' . \wp_kses( \__( '<a href="https://github.com/automattic/wordpress-activitypub/issues/new" target="_blank">Let us know</a> if you miss a Template Tag.', 'activitypub' ), $anchor_html ) . '</p>',
360 )
361 );
362
363 /* translators: %s: Link to more information */
364 $info_string = \esc_html__( 'For more information please visit %s.', 'activitypub' );
365
366 \get_current_screen()->add_help_tab(
367 array(
368 'id' => 'glossary',
369 'title' => \__( 'Glossary', 'activitypub' ),
370 'content' =>
371 '<h2>' . \esc_html__( 'Fediverse', 'activitypub' ) . '</h2>' . "\n" .
372 '<p>' . \esc_html__( 'The Fediverse is a new word made of two words: "federation" + "universe"', 'activitypub' ) . '</p>' . "\n" .
373 '<p>' . \esc_html__( 'It is a federated social network running on free open software on a myriad of computers across the globe. Many independent servers are interconnected and allow people to interact with one another. There&#8217;s no one central site: you choose a server to register. This ensures some decentralization and sovereignty of data. Fediverse (also called Fedi) has no built-in advertisements, no tricky algorithms, no one big corporation dictating the rules. Instead we have small cozy communities of like-minded people. Welcome!', 'activitypub' ) . '</p>' . "\n" .
374 '<p>' . \sprintf( $info_string, '<a href="https://fediverse.party/" target="_blank">fediverse.party</a>' ) . '</p>' . "\n" .
375
376 '<h2>' . \esc_html__( 'ActivityPub', 'activitypub' ) . '</h2>' . "\n" .
377 '<p>' . \esc_html__( 'ActivityPub is a decentralized social networking protocol based on the ActivityStreams 2.0 data format. ActivityPub is an official W3C recommended standard published by the W3C Social Web Working Group. It provides a client to server API for creating, updating and deleting content, as well as a federated server to server API for delivering notifications and subscribing to content.', 'activitypub' ) . '</p>' . "\n" .
378
379 '<h2>' . \esc_html__( 'WebFinger', 'activitypub' ) . '</h2>' . "\n" .
380 '<p>' . \esc_html__( 'WebFinger is used to discover information about people or other entities on the Internet that are identified by a URI using standard Hypertext Transfer Protocol (HTTP) methods over a secure transport. A WebFinger resource returns a JavaScript Object Notation (JSON) object describing the entity that is queried. The JSON object is referred to as the JSON Resource Descriptor (JRD).', 'activitypub' ) . '</p>' . "\n" .
381 '<p>' . \esc_html__( 'For a person, the type of information that might be discoverable via WebFinger includes a personal profile address, identity service, telephone number, or preferred avatar. For other entities on the Internet, a WebFinger resource might return JRDs containing link relations that enable a client to discover, for example, that a printer can print in color on A4 paper, the physical location of a server, or other static information.', 'activitypub' ) . '</p>' . "\n" .
382 '<p>' . \wp_kses( \__( 'On Mastodon [and other platforms], user profiles can be hosted either locally on the same website as yours, or remotely on a completely different website. The same username may be used on a different domain. Therefore, a Mastodon user&#8217;s full mention consists of both the username and the domain, in the form <code>@username@domain</code>. In practical terms, <code>@user@example.com</code> is not the same as <code>@user@example.org</code>. If the domain is not included, Mastodon will try to find a local user named <code>@username</code>. However, in order to deliver to someone over ActivityPub, the <code>@username@domain</code> mention is not enough – mentions must be translated to an HTTPS URI first, so that the remote actor&#8217;s inbox and outbox can be found. (This paragraph is copied from the <a href="https://docs.joinmastodon.org/spec/webfinger/" target="_blank">Mastodon Documentation</a>)', 'activitypub' ), array_merge( $code_html, $anchor_html ) ) . '</p>' . "\n" .
383 '<p>' . \sprintf( $info_string, '<a href="https://webfinger.net/" target="_blank">webfinger.net</a>' ) . '</p>' . "\n" .
384
385 '<h2>' . \esc_html__( 'NodeInfo', 'activitypub' ) . '</h2>' . "\n" .
386 '<p>' . \esc_html__( 'NodeInfo is an effort to create a standardized way of exposing metadata about a server running one of the distributed social networks. The two key goals are being able to get better insights into the user base of distributed social networking and the ability to build tools that allow users to choose the best fitting software and server for their needs.', 'activitypub' ) . '</p>' . "\n" .
387 '<p>' . \sprintf( $info_string, '<a href="http://nodeinfo.diaspora.software/" target="_blank">nodeinfo.diaspora.software</a>' ) . '</p>',
388 )
389 );
390
391 \get_current_screen()->set_help_sidebar(
392 '<p><strong>' . \__( 'For more information:', 'activitypub' ) . '</strong></p>' . "\n" .
393 '<p>' . \__( '<a href="https://wordpress.org/support/plugin/activitypub/">Get support</a>', 'activitypub' ) . '</p>' . "\n" .
394 '<p>' . \__( '<a href="https://github.com/automattic/wordpress-activitypub/issues">Report an issue</a>', 'activitypub' ) . '</p>'
395 );
396 }
397 }
398