| 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 Activitypub\Sanitize; |
| 13 |
use function Activitypub\user_can_activitypub; |
| 14 |
|
| 15 |
/** |
| 16 |
* ActivityPub Settings Class. |
| 17 |
*/ |
| 18 |
class Settings { |
| 19 |
/** |
| 20 |
* Initialize the class, registering WordPress hooks, |
| 21 |
*/ |
| 22 |
public static function init() { |
| 23 |
\add_action( 'admin_init', array( self::class, 'register_settings' ), 11 ); |
| 24 |
\add_action( 'admin_menu', array( self::class, 'add_settings_page' ) ); |
| 25 |
|
| 26 |
\add_action( 'load-settings_page_activitypub', array( self::class, 'handle_welcome_query_arg' ) ); |
| 27 |
\add_filter( 'screen_settings', array( self::class, 'add_screen_option' ), 10, 2 ); |
| 28 |
\add_filter( 'screen_options_show_submit', array( self::class, 'screen_options_show_submit' ), 10, 2 ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Register ActivityPub settings |
| 33 |
*/ |
| 34 |
public static function register_settings() { |
| 35 |
\register_setting( |
| 36 |
'activitypub', |
| 37 |
'activitypub_post_content_type', |
| 38 |
array( |
| 39 |
'type' => 'string', |
| 40 |
'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ), |
| 41 |
'show_in_rest' => array( |
| 42 |
'schema' => array( |
| 43 |
'enum' => array( 'title', 'excerpt', 'content' ), |
| 44 |
), |
| 45 |
), |
| 46 |
'default' => 'content', |
| 47 |
) |
| 48 |
); |
| 49 |
|
| 50 |
\register_setting( |
| 51 |
'activitypub', |
| 52 |
'activitypub_custom_post_content', |
| 53 |
array( |
| 54 |
'type' => 'string', |
| 55 |
'description' => \__( 'Define your own custom post template', 'activitypub' ), |
| 56 |
'show_in_rest' => true, |
| 57 |
'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT, |
| 58 |
) |
| 59 |
); |
| 60 |
|
| 61 |
\register_setting( |
| 62 |
'activitypub', |
| 63 |
'activitypub_max_image_attachments', |
| 64 |
array( |
| 65 |
'type' => 'integer', |
| 66 |
'description' => \__( 'Number of images to attach to posts.', 'activitypub' ), |
| 67 |
'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS, |
| 68 |
) |
| 69 |
); |
| 70 |
|
| 71 |
\register_setting( |
| 72 |
'activitypub', |
| 73 |
'activitypub_object_type', |
| 74 |
array( |
| 75 |
'type' => 'string', |
| 76 |
'description' => \__( 'The Activity-Object-Type', 'activitypub' ), |
| 77 |
'show_in_rest' => array( |
| 78 |
'schema' => array( |
| 79 |
'enum' => array( 'note', 'wordpress-post-format' ), |
| 80 |
), |
| 81 |
), |
| 82 |
'default' => ACTIVITYPUB_DEFAULT_OBJECT_TYPE, |
| 83 |
) |
| 84 |
); |
| 85 |
|
| 86 |
\register_setting( |
| 87 |
'activitypub', |
| 88 |
'activitypub_use_hashtags', |
| 89 |
array( |
| 90 |
'type' => 'boolean', |
| 91 |
'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ), |
| 92 |
'default' => '0', |
| 93 |
) |
| 94 |
); |
| 95 |
|
| 96 |
\register_setting( |
| 97 |
'activitypub', |
| 98 |
'activitypub_use_opengraph', |
| 99 |
array( |
| 100 |
'type' => 'boolean', |
| 101 |
'description' => \__( 'Automatically add "fediverse:creator" OpenGraph tags for Authors and the Blog-User.', 'activitypub' ), |
| 102 |
'default' => '1', |
| 103 |
) |
| 104 |
); |
| 105 |
|
| 106 |
\register_setting( |
| 107 |
'activitypub', |
| 108 |
'activitypub_support_post_types', |
| 109 |
array( |
| 110 |
'type' => 'string', |
| 111 |
'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ), |
| 112 |
'show_in_rest' => true, |
| 113 |
'default' => array( 'post' ), |
| 114 |
) |
| 115 |
); |
| 116 |
|
| 117 |
\register_setting( |
| 118 |
'activitypub', |
| 119 |
'activitypub_actor_mode', |
| 120 |
array( |
| 121 |
'type' => 'integer', |
| 122 |
'description' => \__( 'Choose your preferred Actor-Mode.', 'activitypub' ), |
| 123 |
'default' => ACTIVITYPUB_ACTOR_MODE, |
| 124 |
) |
| 125 |
); |
| 126 |
|
| 127 |
\register_setting( |
| 128 |
'activitypub', |
| 129 |
'activitypub_attribution_domains', |
| 130 |
array( |
| 131 |
'type' => 'string', |
| 132 |
'description' => \__( 'Websites allowed to credit you.', 'activitypub' ), |
| 133 |
'default' => \Activitypub\home_host(), |
| 134 |
'sanitize_callback' => array( Sanitize::class, 'host_list' ), |
| 135 |
) |
| 136 |
); |
| 137 |
|
| 138 |
\register_setting( |
| 139 |
'activitypub', |
| 140 |
'activitypub_allow_likes', |
| 141 |
array( |
| 142 |
'type' => 'integer', |
| 143 |
'description' => \__( 'Allow likes.', 'activitypub' ), |
| 144 |
'default' => '1', |
| 145 |
'sanitize_callback' => 'absint', |
| 146 |
) |
| 147 |
); |
| 148 |
|
| 149 |
\register_setting( |
| 150 |
'activitypub', |
| 151 |
'activitypub_allow_reposts', |
| 152 |
array( |
| 153 |
'type' => 'integer', |
| 154 |
'description' => \__( 'Allow reposts.', 'activitypub' ), |
| 155 |
'default' => '1', |
| 156 |
'sanitize_callback' => 'absint', |
| 157 |
) |
| 158 |
); |
| 159 |
|
| 160 |
\register_setting( |
| 161 |
'activitypub', |
| 162 |
'activitypub_mailer_new_dm', |
| 163 |
array( |
| 164 |
'type' => 'boolean', |
| 165 |
'description' => \__( 'Send notifications via e-mail when a direct message is received.', 'activitypub' ), |
| 166 |
'default' => '0', |
| 167 |
) |
| 168 |
); |
| 169 |
|
| 170 |
\register_setting( |
| 171 |
'activitypub_advanced', |
| 172 |
'activitypub_outbox_purge_days', |
| 173 |
array( |
| 174 |
'type' => 'integer', |
| 175 |
'description' => \__( 'Number of days to keep items in the Outbox.', 'activitypub' ), |
| 176 |
'default' => 180, |
| 177 |
) |
| 178 |
); |
| 179 |
|
| 180 |
\register_setting( |
| 181 |
'activitypub_advanced', |
| 182 |
'activitypub_vary_header', |
| 183 |
array( |
| 184 |
'type' => 'boolean', |
| 185 |
'description' => \__( 'Add the Vary header to the ActivityPub response.', 'activitypub' ), |
| 186 |
'default' => false, |
| 187 |
) |
| 188 |
); |
| 189 |
|
| 190 |
\register_setting( |
| 191 |
'activitypub_advanced', |
| 192 |
'activitypub_authorized_fetch', |
| 193 |
array( |
| 194 |
'type' => 'boolean', |
| 195 |
'description' => \__( 'Require HTTP signature authentication.', 'activitypub' ), |
| 196 |
'default' => false, |
| 197 |
) |
| 198 |
); |
| 199 |
|
| 200 |
\register_setting( |
| 201 |
'activitypub_advanced', |
| 202 |
'activitypub_shared_inbox', |
| 203 |
array( |
| 204 |
'type' => 'boolean', |
| 205 |
'description' => \__( 'Enable the shared inbox.', 'activitypub' ), |
| 206 |
'default' => false, |
| 207 |
) |
| 208 |
); |
| 209 |
|
| 210 |
\register_setting( |
| 211 |
'activitypub', |
| 212 |
'activitypub_relays', |
| 213 |
array( |
| 214 |
'type' => 'array', |
| 215 |
'description' => \__( 'Relays', 'activitypub' ), |
| 216 |
'default' => array(), |
| 217 |
'sanitize_callback' => array( Sanitize::class, 'url_list' ), |
| 218 |
) |
| 219 |
); |
| 220 |
|
| 221 |
// Blog-User Settings. |
| 222 |
\register_setting( |
| 223 |
'activitypub_blog', |
| 224 |
'activitypub_blog_description', |
| 225 |
array( |
| 226 |
'type' => 'string', |
| 227 |
'description' => \esc_html__( 'The Description of the Blog-User', 'activitypub' ), |
| 228 |
'show_in_rest' => true, |
| 229 |
'default' => '', |
| 230 |
) |
| 231 |
); |
| 232 |
|
| 233 |
\register_setting( |
| 234 |
'activitypub_blog', |
| 235 |
'activitypub_blog_identifier', |
| 236 |
array( |
| 237 |
'type' => 'string', |
| 238 |
'description' => \esc_html__( 'The Identifier of the Blog-User', 'activitypub' ), |
| 239 |
'show_in_rest' => true, |
| 240 |
'default' => Blog::get_default_username(), |
| 241 |
'sanitize_callback' => array( Sanitize::class, 'blog_identifier' ), |
| 242 |
) |
| 243 |
); |
| 244 |
|
| 245 |
\register_setting( |
| 246 |
'activitypub_blog', |
| 247 |
'activitypub_header_image', |
| 248 |
array( |
| 249 |
'type' => 'integer', |
| 250 |
'description' => \__( 'The Attachment-ID of the Sites Header-Image', 'activitypub' ), |
| 251 |
'default' => null, |
| 252 |
) |
| 253 |
); |
| 254 |
|
| 255 |
\register_setting( |
| 256 |
'activitypub_blog', |
| 257 |
'activitypub_blog_user_also_known_as', |
| 258 |
array( |
| 259 |
'type' => 'array', |
| 260 |
'description' => 'An array of URLs that the blog user is known by.', |
| 261 |
'default' => array(), |
| 262 |
'sanitize_callback' => array( Sanitize::class, 'url_list' ), |
| 263 |
) |
| 264 |
); |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* Load settings page. |
| 269 |
*/ |
| 270 |
public static function settings_page() { |
| 271 |
$show_welcome_tab = \get_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', true ); |
| 272 |
$show_advanced_tab = \get_user_meta( \get_current_user_id(), 'activitypub_show_advanced_tab', true ); |
| 273 |
$default_tab = $show_welcome_tab ? 'welcome' : 'settings'; |
| 274 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 275 |
$tab = isset( $_GET['tab'] ) ? \sanitize_key( $_GET['tab'] ) : $default_tab; |
| 276 |
|
| 277 |
// Redirect welcome tab to settings if skipped. |
| 278 |
if ( 'welcome' === $tab && ! $show_welcome_tab ) { |
| 279 |
$tab = 'settings'; |
| 280 |
} |
| 281 |
|
| 282 |
$settings_tabs = array(); |
| 283 |
|
| 284 |
if ( $show_welcome_tab ) { |
| 285 |
$settings_tabs['welcome'] = array( |
| 286 |
'label' => __( 'Welcome', 'activitypub' ), |
| 287 |
'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/welcome.php', |
| 288 |
); |
| 289 |
} |
| 290 |
|
| 291 |
$settings_tabs['settings'] = array( |
| 292 |
'label' => __( 'Settings', 'activitypub' ), |
| 293 |
'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/settings.php', |
| 294 |
); |
| 295 |
|
| 296 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 297 |
if ( ( isset( $_GET['tab'] ) && 'advanced' === $_GET['tab'] ) || $show_advanced_tab ) { |
| 298 |
$settings_tabs['advanced'] = array( |
| 299 |
'label' => \__( 'Advanced', 'activitypub' ), |
| 300 |
'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/advanced-settings.php', |
| 301 |
); |
| 302 |
} |
| 303 |
|
| 304 |
if ( user_can_activitypub( Actors::BLOG_USER_ID ) ) { |
| 305 |
$settings_tabs['blog-profile'] = array( |
| 306 |
'label' => __( 'Blog Profile', 'activitypub' ), |
| 307 |
'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-settings.php', |
| 308 |
); |
| 309 |
$settings_tabs['followers'] = array( |
| 310 |
'label' => __( 'Followers', 'activitypub' ), |
| 311 |
'template' => ACTIVITYPUB_PLUGIN_DIR . 'templates/blog-followers-list.php', |
| 312 |
); |
| 313 |
} |
| 314 |
|
| 315 |
/** |
| 316 |
* Filters the tabs displayed in the ActivityPub settings. |
| 317 |
* |
| 318 |
* @param array $settings_tabs The tabs to display. |
| 319 |
*/ |
| 320 |
$custom_tabs = \apply_filters( 'activitypub_admin_settings_tabs', array() ); |
| 321 |
$settings_tabs = \array_merge( $settings_tabs, $custom_tabs ); |
| 322 |
|
| 323 |
switch ( $tab ) { |
| 324 |
case 'blog-profile': |
| 325 |
\wp_enqueue_media(); |
| 326 |
\wp_enqueue_script( 'activitypub-header-image' ); |
| 327 |
break; |
| 328 |
case 'welcome': |
| 329 |
\wp_enqueue_script( 'plugin-install' ); |
| 330 |
\add_thickbox(); |
| 331 |
\wp_enqueue_script( 'updates' ); |
| 332 |
break; |
| 333 |
} |
| 334 |
|
| 335 |
if ( ! isset( $settings_tabs[ $tab ] ) ) { |
| 336 |
$tab = $default_tab; |
| 337 |
} |
| 338 |
|
| 339 |
// Only show tabs if there are more than one. |
| 340 |
if ( \count( $settings_tabs ) <= 1 ) { |
| 341 |
$labels = array(); |
| 342 |
} else { |
| 343 |
$labels = \wp_list_pluck( $settings_tabs, 'label' ); |
| 344 |
} |
| 345 |
|
| 346 |
$args = \array_fill_keys( \array_keys( $labels ), '' ); |
| 347 |
$args[ $tab ] = 'active'; |
| 348 |
$args['tabs'] = $labels; |
| 349 |
|
| 350 |
\load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/admin-header.php', true, $args ); |
| 351 |
\load_template( $settings_tabs[ $tab ]['template'] ); |
| 352 |
} |
| 353 |
|
| 354 |
/** |
| 355 |
* Adds the ActivityPub settings to the Help tab. |
| 356 |
*/ |
| 357 |
public static function add_settings_help_tab() { |
| 358 |
$code_html = array( 'code' => array() ); |
| 359 |
$anchor_html = array( |
| 360 |
'a' => array( |
| 361 |
'href' => true, |
| 362 |
'target' => true, |
| 363 |
), |
| 364 |
); |
| 365 |
|
| 366 |
if ( user_can_activitypub( \get_current_user_id() ) ) { |
| 367 |
$webfinger = Actors::get_by_id( \get_current_user_id() )->get_webfinger(); |
| 368 |
} else { |
| 369 |
$webfinger = ( new Blog() )->get_webfinger(); |
| 370 |
} |
| 371 |
|
| 372 |
\get_current_screen()->add_help_tab( |
| 373 |
array( |
| 374 |
'id' => 'template-tags', |
| 375 |
'title' => \__( 'Template Tags', 'activitypub' ), |
| 376 |
'content' => '<h2>' . \esc_html__( 'The following Template Tags are available:', 'activitypub' ) . '</h2>' . "\n" . |
| 377 |
'<dl>' . "\n" . |
| 378 |
'<dt><code>[ap_title]</code></dt>' . "\n" . |
| 379 |
'<dd>' . \esc_html__( 'The post’s title.', 'activitypub' ) . '</dd>' . "\n" . |
| 380 |
'<dt><code>[ap_content apply_filters="yes"]</code></dt>' . "\n" . |
| 381 |
'<dd>' . \wp_kses( \__( 'The post’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" . |
| 382 |
'<dt><code>[ap_excerpt length="400"]</code></dt>' . "\n" . |
| 383 |
'<dd>' . \wp_kses( \__( 'The post’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" . |
| 384 |
'<dt><code>[ap_permalink type="url"]</code></dt>' . "\n" . |
| 385 |
'<dd>' . \wp_kses( \__( 'The post’s permalink. <code>type</code> can be either: <code>url</code> or <code>html</code> (an <a /> tag). <code>type</code> attribute is optional.', 'activitypub' ), $code_html ) . '</dd>' . "\n" . |
| 386 |
'<dt><code>[ap_shortlink type="url"]</code></dt>' . "\n" . |
| 387 |
'<dd>' . \wp_kses( \__( 'The post’s shortlink. <code>type</code> can be either <code>url</code> or <code>html</code> (an <a /> 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" . |
| 388 |
'<dt><code>[ap_hashtags]</code></dt>' . "\n" . |
| 389 |
'<dd>' . \esc_html__( 'The post’s tags as hashtags.', 'activitypub' ) . '</dd>' . "\n" . |
| 390 |
'<dt><code>[ap_hashcats]</code></dt>' . "\n" . |
| 391 |
'<dd>' . \esc_html__( 'The post’s categories as hashtags.', 'activitypub' ) . '</dd>' . "\n" . |
| 392 |
'<dt><code>[ap_image type=full]</code></dt>' . "\n" . |
| 393 |
'<dd>' . \wp_kses( __( 'The URL for the post’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" . |
| 394 |
'<dt><code>[ap_author]</code></dt>' . "\n" . |
| 395 |
'<dd>' . \esc_html__( 'The author’s name.', 'activitypub' ) . '</dd>' . "\n" . |
| 396 |
'<dt><code>[ap_authorurl]</code></dt>' . "\n" . |
| 397 |
'<dd>' . \esc_html__( 'The URL to the author’s profile page.', 'activitypub' ) . '</dd>' . "\n" . |
| 398 |
'<dt><code>[ap_date]</code></dt>' . "\n" . |
| 399 |
'<dd>' . \esc_html__( 'The post’s date.', 'activitypub' ) . '</dd>' . "\n" . |
| 400 |
'<dt><code>[ap_time]</code></dt>' . "\n" . |
| 401 |
'<dd>' . \esc_html__( 'The post’s time.', 'activitypub' ) . '</dd>' . "\n" . |
| 402 |
'<dt><code>[ap_datetime]</code></dt>' . "\n" . |
| 403 |
'<dd>' . \esc_html__( 'The post’s date/time formated as "date @ time".', 'activitypub' ) . '</dd>' . "\n" . |
| 404 |
'<dt><code>[ap_blogurl]</code></dt>' . "\n" . |
| 405 |
'<dd>' . \esc_html__( 'The URL to the site.', 'activitypub' ) . '</dd>' . "\n" . |
| 406 |
'<dt><code>[ap_blogname]</code></dt>' . "\n" . |
| 407 |
'<dd>' . \esc_html__( 'The name of the site.', 'activitypub' ) . '</dd>' . "\n" . |
| 408 |
'<dt><code>[ap_blogdesc]</code></dt>' . "\n" . |
| 409 |
'<dd>' . \esc_html__( 'The description of the site.', 'activitypub' ) . '</dd>' . "\n" . |
| 410 |
'</dl>' . "\n" . |
| 411 |
'<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" . |
| 412 |
'<p>' . \esc_html__( 'Note: the old Template Tags are now deprecated and automatically converted to the new ones.', 'activitypub' ) . '</p>' . "\n" . |
| 413 |
'<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>', |
| 414 |
) |
| 415 |
); |
| 416 |
|
| 417 |
\get_current_screen()->add_help_tab( |
| 418 |
array( |
| 419 |
'id' => 'account-migration', |
| 420 |
'title' => \__( 'Account Migration', 'activitypub' ), |
| 421 |
'content' => |
| 422 |
'<h2>' . \esc_html__( 'Migrating Between Mastodon and WordPress', 'activitypub' ) . '</h2>' . "\n" . |
| 423 |
'<p>' . \esc_html__( 'The ActivityPub plugin allows you to migrate your account between WordPress and Mastodon (or other ActivityPub-compatible platforms) while bringing your followers with you.', 'activitypub' ) . '</p>' . "\n" . |
| 424 |
|
| 425 |
'<h3>' . \esc_html__( 'Migrating from Mastodon to WordPress', 'activitypub' ) . '</h3>' . "\n" . |
| 426 |
'<ol>' . "\n" . |
| 427 |
'<li>' . \wp_kses( |
| 428 |
\sprintf( |
| 429 |
/* translators: %s is the URL to the profile page */ |
| 430 |
\__( 'In your WordPress profile, go to the <a href="%s">Account Aliases</a> section and add your Mastodon profile URL (e.g., <code>https://mastodon.social/@username</code>).', 'activitypub' ), |
| 431 |
\esc_url( \admin_url( 'profile.php#activitypub_blog_user_also_known_as' ) ) |
| 432 |
), |
| 433 |
array_merge( $code_html, $anchor_html ) |
| 434 |
) . '</li>' . "\n" . |
| 435 |
'<li>' . \esc_html__( 'Save your WordPress profile changes.', 'activitypub' ) . '</li>' . "\n" . |
| 436 |
'<li>' . \esc_html__( 'Log in to your Mastodon account.', 'activitypub' ) . '</li>' . "\n" . |
| 437 |
'<li>' . \esc_html__( 'Go to Preferences > Account > Move to a different account.', 'activitypub' ) . '</li>' . "\n" . |
| 438 |
'<li>' . \wp_kses( |
| 439 |
\sprintf( |
| 440 |
/* translators: %s is the user's ActivityPub username */ |
| 441 |
\__( 'Enter your WordPress ActivityPub username (e.g., <code>%s</code>) in the "Handle of the new account" field.', 'activitypub' ), |
| 442 |
\esc_html( $webfinger ) |
| 443 |
), |
| 444 |
$code_html |
| 445 |
) . '</li>' . "\n" . |
| 446 |
'<li>' . \esc_html__( 'Confirm the migration in Mastodon by entering your password.', 'activitypub' ) . '</li>' . "\n" . |
| 447 |
'<li>' . \esc_html__( 'Your followers will be notified and redirected to follow your WordPress account.', 'activitypub' ) . '</li>' . "\n" . |
| 448 |
'</ol>' . "\n", |
| 449 |
) |
| 450 |
); |
| 451 |
|
| 452 |
/* translators: %s: Link to more information */ |
| 453 |
$info_string = \esc_html__( 'For more information please visit %s.', 'activitypub' ); |
| 454 |
|
| 455 |
\get_current_screen()->add_help_tab( |
| 456 |
array( |
| 457 |
'id' => 'glossary', |
| 458 |
'title' => \__( 'Glossary', 'activitypub' ), |
| 459 |
'content' => |
| 460 |
'<h2>' . \esc_html__( 'Fediverse', 'activitypub' ) . '</h2>' . "\n" . |
| 461 |
'<p>' . \esc_html__( 'The Fediverse is a new word made of two words: "federation" + "universe"', 'activitypub' ) . '</p>' . "\n" . |
| 462 |
'<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’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" . |
| 463 |
'<p>' . \sprintf( $info_string, '<a href="https://fediverse.party/" target="_blank">fediverse.party</a>' ) . '</p>' . "\n" . |
| 464 |
|
| 465 |
'<h2>' . \esc_html__( 'ActivityPub', 'activitypub' ) . '</h2>' . "\n" . |
| 466 |
'<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" . |
| 467 |
|
| 468 |
'<h2>' . \esc_html__( 'WebFinger', 'activitypub' ) . '</h2>' . "\n" . |
| 469 |
'<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" . |
| 470 |
'<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" . |
| 471 |
'<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’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’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" . |
| 472 |
'<p>' . \sprintf( $info_string, '<a href="https://webfinger.net/" target="_blank">webfinger.net</a>' ) . '</p>' . "\n" . |
| 473 |
|
| 474 |
'<h2>' . \esc_html__( 'NodeInfo', 'activitypub' ) . '</h2>' . "\n" . |
| 475 |
'<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" . |
| 476 |
'<p>' . \sprintf( $info_string, '<a href="http://nodeinfo.diaspora.software/" target="_blank">nodeinfo.diaspora.software</a>' ) . '</p>', |
| 477 |
) |
| 478 |
); |
| 479 |
|
| 480 |
\get_current_screen()->set_help_sidebar( |
| 481 |
'<p><strong>' . \__( 'For more information:', 'activitypub' ) . '</strong></p>' . "\n" . |
| 482 |
'<p>' . \__( '<a href="https://wordpress.org/support/plugin/activitypub/">Get support</a>', 'activitypub' ) . '</p>' . "\n" . |
| 483 |
'<p>' . \__( '<a href="https://github.com/automattic/wordpress-activitypub/issues">Report an issue</a>', 'activitypub' ) . '</p>' |
| 484 |
); |
| 485 |
} |
| 486 |
|
| 487 |
/** |
| 488 |
* Handle 'welcome' query arg. |
| 489 |
*/ |
| 490 |
public static function handle_welcome_query_arg() { |
| 491 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 492 |
if ( isset( $_GET['welcome'] ) ) { |
| 493 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 494 |
$welcome_checked = empty( \sanitize_text_field( \wp_unslash( $_GET['welcome'] ) ) ) ? 0 : 1; |
| 495 |
\update_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', $welcome_checked ); |
| 496 |
\wp_safe_redirect( \admin_url( 'options-general.php?page=activitypub&tab=settings' ) ); |
| 497 |
exit; |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
/** |
| 502 |
* Add screen option. |
| 503 |
* |
| 504 |
* @param string $screen_settings The screen settings. |
| 505 |
* @param object $screen The screen object. |
| 506 |
* |
| 507 |
* @return string The screen settings. |
| 508 |
*/ |
| 509 |
public static function add_screen_option( $screen_settings, $screen ) { |
| 510 |
if ( 'settings_page_activitypub' !== $screen->id ) { |
| 511 |
return $screen_settings; |
| 512 |
} |
| 513 |
|
| 514 |
// Verify screen options nonce. |
| 515 |
if ( isset( $_POST['screenoptionnonce'] ) ) { |
| 516 |
$nonce = \sanitize_text_field( \wp_unslash( $_POST['screenoptionnonce'] ) ); |
| 517 |
if ( ! \wp_verify_nonce( $nonce, 'screen-options-nonce' ) ) { |
| 518 |
return $screen_settings; |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
if ( isset( $_POST['activitypub_show_welcome_tab'] ) ) { |
| 523 |
$welcome = \sanitize_text_field( \wp_unslash( $_POST['activitypub_show_welcome_tab'] ) ); |
| 524 |
$welcome_checked = empty( $welcome ) ? 0 : 1; |
| 525 |
\update_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', $welcome_checked ); |
| 526 |
} |
| 527 |
|
| 528 |
if ( isset( $_POST['activitypub_show_advanced_tab'] ) ) { |
| 529 |
$advanced_settings = \sanitize_text_field( \wp_unslash( $_POST['activitypub_show_advanced_tab'] ) ); |
| 530 |
$advanced_settings_checked = empty( $advanced_settings ) ? 0 : 1; |
| 531 |
\update_user_meta( \get_current_user_id(), 'activitypub_show_advanced_tab', $advanced_settings_checked ); |
| 532 |
} |
| 533 |
|
| 534 |
$screen_settings = '<fieldset> |
| 535 |
<legend class="screen-layout">' . \esc_html__( 'Settings Pages', 'activitypub' ) . '</legend> |
| 536 |
<p> |
| 537 |
' . \esc_html__( 'Some settings pages can be shown or hidden by using the checkboxes.', 'activitypub' ) . ' |
| 538 |
</p> |
| 539 |
<div class="metabox-prefs-container"> |
| 540 |
<label for="activitypub_show_welcome_tab"> |
| 541 |
<input name="activitypub_show_welcome_tab" type="hidden" value="0" /> |
| 542 |
<input name="activitypub_show_welcome_tab" type="checkbox" id="activitypub_show_welcome_tab" value="1" ' . \checked( 1, \get_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', true ), false ) . ' /> |
| 543 |
' . \esc_html__( 'Welcome Page', 'activitypub' ) . ' |
| 544 |
</label> |
| 545 |
<label for="activitypub_show_advanced_tab"> |
| 546 |
<input name="activitypub_show_advanced_tab" type="hidden" value="0" /> |
| 547 |
<input name="activitypub_show_advanced_tab" type="checkbox" id="activitypub_show_advanced_tab" value="1" ' . \checked( 1, \get_user_meta( \get_current_user_id(), 'activitypub_show_advanced_tab', true ), false ) . ' /> |
| 548 |
' . \esc_html__( 'Advanced Settings', 'activitypub' ) . ' |
| 549 |
</label> |
| 550 |
</div> |
| 551 |
</fieldset>'; |
| 552 |
|
| 553 |
return $screen_settings; |
| 554 |
} |
| 555 |
|
| 556 |
/** |
| 557 |
* Show the submit button on the screen options page. |
| 558 |
* |
| 559 |
* @param bool $show_submit Whether to show the submit button. |
| 560 |
* @param object $screen The screen object. |
| 561 |
* |
| 562 |
* @return bool Whether to show the submit button. |
| 563 |
*/ |
| 564 |
public static function screen_options_show_submit( $show_submit, $screen ) { |
| 565 |
if ( 'settings_page_activitypub' !== $screen->id ) { |
| 566 |
return $show_submit; |
| 567 |
} |
| 568 |
|
| 569 |
return true; |
| 570 |
} |
| 571 |
} |
| 572 |
|