PluginProbe
ActivityPub / 8.3.0
ActivityPub v8.3.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 / includes / wp-admin / class-settings-fields.php

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

656 lines 24.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ActivityPub Settings Fields Class.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\WP_Admin;
9
10 use Activitypub\Blocklist_Subscriptions;
11 use Activitypub\Moderation;
12
13 use function Activitypub\home_host;
14
15 /**
16 * Class Settings_Fields.
17 */
18 class Settings_Fields {
19 /**
20 * Initialize the settings fields.
21 */
22 public static function init() {
23 add_action( 'load-settings_page_activitypub', array( self::class, 'register_settings_fields' ) );
24 }
25
26 /**
27 * Register settings fields.
28 */
29 public static function register_settings_fields() {
30 // Add settings sections.
31 add_settings_section(
32 'activitypub_profiles',
33 __( 'Profiles', 'activitypub' ),
34 '__return_empty_string',
35 'activitypub_settings'
36 );
37
38 add_settings_section(
39 'activitypub_activities',
40 __( 'Activities', 'activitypub' ),
41 '__return_empty_string',
42 'activitypub_settings'
43 );
44
45 add_settings_section(
46 'activitypub_general',
47 __( 'General', 'activitypub' ),
48 '__return_empty_string',
49 'activitypub_settings'
50 );
51
52 add_settings_section(
53 'activitypub_server',
54 __( 'Server', 'activitypub' ),
55 '__return_empty_string',
56 'activitypub_settings'
57 );
58
59 add_settings_section(
60 'activitypub_moderation',
61 \esc_html__( 'Moderation', 'activitypub' ),
62 array( self::class, 'render_moderation_section_description' ),
63 'activitypub_settings',
64 array(
65 'before_section' => '<div id="moderation">',
66 'after_section' => '</div>',
67 )
68 );
69
70 // Add settings fields.
71 add_settings_field(
72 'activitypub_actor_mode',
73 __( 'Enable profiles by type', 'activitypub' ),
74 array( self::class, 'render_actor_mode_field' ),
75 'activitypub_settings',
76 'activitypub_profiles'
77 );
78
79 $object_type = \get_option( 'activitypub_object_type', ACTIVITYPUB_DEFAULT_OBJECT_TYPE );
80 if ( 'note' === $object_type ) {
81 add_settings_field(
82 'activitypub_custom_post_content',
83 __( 'Post content', 'activitypub' ),
84 array( self::class, 'render_custom_post_content_field' ),
85 'activitypub_settings',
86 'activitypub_activities',
87 array( 'label_for' => 'activitypub_custom_post_content' )
88 );
89 }
90
91 add_settings_field(
92 'activitypub_max_image_attachments',
93 __( 'Media attachments', 'activitypub' ),
94 array( self::class, 'render_max_image_attachments_field' ),
95 'activitypub_settings',
96 'activitypub_activities',
97 array( 'label_for' => 'activitypub_max_image_attachments' )
98 );
99
100 add_settings_field(
101 'activitypub_support_post_types',
102 __( 'Supported post types', 'activitypub' ),
103 array( self::class, 'render_support_post_types_field' ),
104 'activitypub_settings',
105 'activitypub_activities'
106 );
107
108 add_settings_field(
109 'activitypub_allow_interactions',
110 __( 'Post interactions', 'activitypub' ),
111 array( self::class, 'render_allow_interactions_field' ),
112 'activitypub_settings',
113 'activitypub_activities'
114 );
115
116 add_settings_field(
117 'activitypub_default_quote_policy',
118 __( 'Default quote policy', 'activitypub' ),
119 array( self::class, 'render_default_quote_policy_field' ),
120 'activitypub_settings',
121 'activitypub_activities',
122 array( 'label_for' => 'activitypub_default_quote_policy' )
123 );
124
125 add_settings_field(
126 'activitypub_use_hashtags',
127 __( 'Hashtags', 'activitypub' ),
128 array( self::class, 'render_use_hashtags_field' ),
129 'activitypub_settings',
130 'activitypub_activities',
131 array( 'label_for' => 'activitypub_use_hashtags' )
132 );
133
134 add_settings_field(
135 'activitypub_use_opengraph',
136 __( 'OpenGraph', 'activitypub' ),
137 array( self::class, 'render_use_opengraph_field' ),
138 'activitypub_settings',
139 'activitypub_general',
140 array( 'label_for' => 'activitypub_use_opengraph' )
141 );
142
143 add_settings_field(
144 'activitypub_attribution_domains',
145 __( 'Attribution Domains', 'activitypub' ),
146 array( self::class, 'render_attribution_domains_field' ),
147 'activitypub_settings',
148 'activitypub_general',
149 array( 'label_for' => 'activitypub_attribution_domains' )
150 );
151
152 add_settings_field(
153 'activitypub_relays',
154 __( 'Relays', 'activitypub' ),
155 array( self::class, 'render_relays_field' ),
156 'activitypub_settings',
157 'activitypub_server',
158 array( 'label_for' => 'activitypub_relays' )
159 );
160
161 add_settings_field(
162 'activitypub_site_blocked_domains',
163 \esc_html__( 'Blocked Domains', 'activitypub' ),
164 array( self::class, 'render_site_blocked_domains_field' ),
165 'activitypub_settings',
166 'activitypub_moderation'
167 );
168
169 add_settings_field(
170 'activitypub_site_blocked_keywords',
171 \esc_html__( 'Blocked Keywords', 'activitypub' ),
172 array( self::class, 'render_site_blocked_keywords_field' ),
173 'activitypub_settings',
174 'activitypub_moderation'
175 );
176
177 add_settings_field(
178 'activitypub_blocklist_subscriptions',
179 \esc_html__( 'Blocklist Subscriptions', 'activitypub' ),
180 array( self::class, 'render_blocklist_subscriptions_field' ),
181 'activitypub_settings',
182 'activitypub_moderation'
183 );
184 }
185
186 /**
187 * Render actor mode field.
188 */
189 public static function render_actor_mode_field() {
190 $disabled = ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) && ACTIVITYPUB_SINGLE_USER_MODE ) ||
191 ( \defined( 'ACTIVITYPUB_DISABLE_USER' ) && ACTIVITYPUB_DISABLE_USER ) ||
192 ( \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) && ACTIVITYPUB_DISABLE_BLOG_USER );
193
194 if ( $disabled ) :
195 ?>
196 <p class="description">
197 <?php esc_html_e( 'âš  This setting is defined through server configuration by your blog&#8217;s administrator.', 'activitypub' ); ?>
198 </p>
199 <?php
200 return;
201 endif;
202
203 $value = get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE );
204 ?>
205 <fieldset class="actor-mode-selection">
206 <div class="row">
207 <input type="radio" id="actor-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_MODE, $value ); ?> />
208 <div>
209 <label for="actor-mode"><strong><?php esc_html_e( 'Author Profiles Only', 'activitypub' ); ?></strong></label>
210 <p class="description">
211 <?php echo wp_kses( __( 'Every author on this blog (with the <code>activitypub</code> capability) gets their own ActivityPub profile.', 'activitypub' ), array( 'code' => array() ) ); ?>
212 <strong>
213 <?php
214 echo wp_kses(
215 sprintf(
216 // translators: %s is a URL.
217 __( 'You can add/remove the capability in the <a href="%s">user settings.</a>', 'activitypub' ),
218 admin_url( '/users.php' )
219 ),
220 array( 'a' => array( 'href' => array() ) )
221 );
222 ?>
223 </strong>
224 <?php echo wp_kses( __( 'Select all the users you want to update, choose the method from the drop-down list and click on the "Apply" button.', 'activitypub' ), array( 'code' => array() ) ); ?>
225 </p>
226 </div>
227 </div>
228 <div class="row">
229 <input type="radio" id="blog-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_BLOG_MODE, $value ); ?> />
230 <div>
231 <label for="blog-mode"><strong><?php esc_html_e( 'Blog profile only', 'activitypub' ); ?></strong></label>
232 <p class="description">
233 <?php esc_html_e( 'Your blog becomes a single ActivityPub profile and every post will be published under this profile instead of the individual author profiles.', 'activitypub' ); ?>
234 </p>
235 </div>
236 </div>
237 <div class="row">
238 <input type="radio" id="actor-blog-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_AND_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_AND_BLOG_MODE, $value ); ?> />
239 <div>
240 <label for="actor-blog-mode"><strong><?php esc_html_e( 'Both author and blog profiles', 'activitypub' ); ?></strong></label>
241 <p class="description">
242 <?php esc_html_e( "This combines both modes. Users can be followed individually, while following the blog will show boosts of individual user's posts.", 'activitypub' ); ?>
243 </p>
244 </div>
245 </div>
246 </fieldset>
247 <?php
248 }
249
250 /**
251 * Render custom post content field.
252 */
253 public static function render_custom_post_content_field() {
254 $switch_url = \wp_nonce_url(
255 \add_query_arg(
256 array(
257 'page' => 'activitypub',
258 'tab' => 'settings',
259 'activitypub_update_object_type' => '1',
260 ),
261 \admin_url( 'options-general.php' )
262 ),
263 'activitypub_switch_object_type'
264 );
265 ?>
266 <p class="description">
267 <?php \esc_html_e( 'âš  You are using the legacy template system to format your posts for the fediverse. We recommend switching to automatic mode, which intelligently chooses the best format for each post. Switching will remove this template field from the settings.', 'activitypub' ); ?>
268 </p>
269 <p>
270 <a href="<?php echo \esc_url( $switch_url ); ?>" class="button">
271 <?php \esc_html_e( 'Switch to Automatic Mode', 'activitypub' ); ?>
272 </a>
273 </p>
274 <?php
275 $value = get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
276 ?>
277 <p>
278 <textarea id="activitypub_custom_post_content" name="activitypub_custom_post_content" rows="10" cols="50" class="large-text" placeholder="<?php echo esc_attr( ACTIVITYPUB_CUSTOM_POST_CONTENT ); ?>"><?php echo esc_textarea( wp_kses( $value, 'post' ) ); ?></textarea>
279 <details>
280 <summary><?php esc_html_e( 'See a list of ActivityPub Template Tags.', 'activitypub' ); ?></summary>
281 <div class="description">
282 <ul>
283 <li><code>[ap_title]</code> - <?php esc_html_e( 'The post&#8217;s title.', 'activitypub' ); ?></li>
284 <li><code>[ap_content]</code> - <?php esc_html_e( 'The post&#8217;s content.', 'activitypub' ); ?></li>
285 <li><code>[ap_excerpt]</code> - <?php esc_html_e( 'The post&#8217;s excerpt (may be truncated).', 'activitypub' ); ?></li>
286 <li><code>[ap_permalink]</code> - <?php esc_html_e( 'The post&#8217;s permalink.', 'activitypub' ); ?></li>
287 <li><code>[ap_shortlink]</code> - <?php echo wp_kses( __( 'The post&#8217;s shortlink. I can recommend <a href="https://wordpress.org/plugins/hum/" target="_blank">Hum</a>.', 'activitypub' ), 'default' ); ?></li>
288 <li><code>[ap_hashtags]</code> - <?php esc_html_e( 'The post&#8217;s tags as hashtags.', 'activitypub' ); ?></li>
289 </ul>
290 <p><?php esc_html_e( 'You can find the full list with all possible attributes in the help section on the top-right of the screen.', 'activitypub' ); ?></p>
291 </div>
292 </details>
293 </p>
294 <?php
295 }
296
297 /**
298 * Render max image attachments field.
299 */
300 public static function render_max_image_attachments_field() {
301 $value = get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS );
302 ?>
303 <input id="activitypub_max_image_attachments" value="<?php echo esc_attr( $value ); ?>" name="activitypub_max_image_attachments" type="number" min="0" max="10" class="small-text" />
304 <p class="description">
305 <?php
306 echo wp_kses(
307 sprintf(
308 // translators: %s is a number.
309 __( 'The number of media (images, audio, video) to attach to posts. Default: <code>%s</code>', 'activitypub' ),
310 esc_html( ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS )
311 ),
312 'default'
313 );
314 ?>
315 </p>
316 <p class="description">
317 <em>
318 <?php esc_html_e( 'Note: audio and video attachments are only supported from Block Editor.', 'activitypub' ); ?>
319 </em>
320 </p>
321 <?php
322 }
323
324 /**
325 * Render support post types field.
326 */
327 public static function render_support_post_types_field() {
328 $post_types = \get_post_types( array( 'public' => true ), 'objects' );
329 $supported_post_types = \get_option( 'activitypub_support_post_types', array( 'post' ) );
330 ?>
331 <fieldset>
332 <?php esc_html_e( 'Automatically publish items of the selected post types to the fediverse:', 'activitypub' ); ?>
333 <ul>
334 <?php foreach ( $post_types as $post_type ) : ?>
335 <li>
336 <input type="checkbox" id="activitypub_support_post_type_<?php echo esc_attr( $post_type->name ); ?>" name="activitypub_support_post_types[]" value="<?php echo esc_attr( $post_type->name ); ?>" <?php checked( in_array( $post_type->name, $supported_post_types, true ) ); ?> />
337 <label for="activitypub_support_post_type_<?php echo esc_attr( $post_type->name ); ?>"><?php echo esc_html( $post_type->label ); ?></label>
338 <span class="description">
339 <?php echo esc_html( \Activitypub\get_post_type_description( $post_type ) ); ?>
340 </span>
341 </li>
342 <?php endforeach; ?>
343 </ul>
344 </fieldset>
345 <?php
346 }
347
348 /**
349 * Render allow interactions field.
350 */
351 public static function render_allow_interactions_field() {
352 if ( defined( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS' ) && ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
353 echo '<p class="description">' . \esc_html__( 'âš  This setting is defined through server configuration by your blog&#8217;s administrator.', 'activitypub' ) . '</p>';
354 return;
355 }
356
357 $allow_likes = get_option( 'activitypub_allow_likes', '1' );
358 $allow_reposts = get_option( 'activitypub_allow_reposts', '1' );
359 $auto_approve = get_option( 'activitypub_auto_approve_reactions', '0' );
360 ?>
361 <fieldset>
362 <p>
363 <label>
364 <input type="checkbox" name="activitypub_allow_likes" value="1" <?php checked( '1', $allow_likes ); ?> />
365 <?php esc_html_e( 'Receive likes', 'activitypub' ); ?>
366 </label>
367 </p>
368 <p>
369 <label>
370 <input type="checkbox" name="activitypub_allow_reposts" value="1" <?php checked( '1', $allow_reposts ); ?> />
371 <?php esc_html_e( 'Receive reblogs (boosts)', 'activitypub' ); ?>
372 </label>
373 </p>
374 <p class="interactions description"><?php esc_html_e( 'Types of interactions from the Fediverse your blog should accept.', 'activitypub' ); ?></p>
375 <p>
376 <label>
377 <input type="checkbox" name="activitypub_auto_approve_reactions" value="1" <?php checked( '1', $auto_approve ); ?> />
378 <?php esc_html_e( 'Auto approve reactions', 'activitypub' ); ?>
379 </label>
380 </p>
381 </fieldset>
382 <?php
383 }
384
385 /**
386 * Render default quote policy field.
387 */
388 public static function render_default_quote_policy_field() {
389 $value = get_option( 'activitypub_default_quote_policy', ACTIVITYPUB_INTERACTION_POLICY_ANYONE );
390 ?>
391 <select id="activitypub_default_quote_policy" name="activitypub_default_quote_policy" class="regular-text">
392 <option value="<?php echo esc_attr( ACTIVITYPUB_INTERACTION_POLICY_ANYONE ); ?>" <?php selected( $value, ACTIVITYPUB_INTERACTION_POLICY_ANYONE ); ?>><?php esc_html_e( 'Anyone', 'activitypub' ); ?></option>
393 <option value="<?php echo esc_attr( ACTIVITYPUB_INTERACTION_POLICY_FOLLOWERS ); ?>" <?php selected( $value, ACTIVITYPUB_INTERACTION_POLICY_FOLLOWERS ); ?>><?php esc_html_e( 'Followers only', 'activitypub' ); ?></option>
394 <option value="<?php echo esc_attr( ACTIVITYPUB_INTERACTION_POLICY_ME ); ?>" <?php selected( $value, ACTIVITYPUB_INTERACTION_POLICY_ME ); ?>><?php esc_html_e( 'Just me', 'activitypub' ); ?></option>
395 </select>
396 <p class="description">
397 <?php esc_html_e( 'Default setting for who can quote new posts. This can be overridden per post.', 'activitypub' ); ?>
398 </p>
399 <?php
400 }
401
402 /**
403 * Render use hashtags field.
404 */
405 public static function render_use_hashtags_field() {
406 $value = get_option( 'activitypub_use_hashtags', '0' );
407 ?>
408 <p>
409 <label>
410 <input type="checkbox" id="activitypub_use_hashtags" name="activitypub_use_hashtags" value="1" <?php checked( '1', $value ); ?> />
411 <?php echo wp_kses( __( 'Add hashtags in the content as native tags and replace the <code>#tag</code> with the tag link.', 'activitypub' ), 'default' ); ?>
412 </label>
413 </p>
414 <?php
415 }
416
417 /**
418 * Render use OpenGraph field.
419 */
420 public static function render_use_opengraph_field() {
421 $value = get_option( 'activitypub_use_opengraph', '1' );
422 ?>
423 <p>
424 <label>
425 <input type="checkbox" id="activitypub_use_opengraph" name="activitypub_use_opengraph" value="1" <?php checked( '1', $value ); ?> />
426 <?php echo wp_kses( __( 'Automatically add <code>&lt;meta name="fediverse:creator" /&gt;</code> tags for Authors and the Blog-User. You can read more about the feature on the <a href="https://blog.joinmastodon.org/2024/07/highlighting-journalism-on-mastodon/" target="_blank">Mastodon Blog</a>.', 'activitypub' ), 'post' ); ?>
427 </label>
428 </p>
429 <?php
430 }
431
432 /**
433 * Render attribution domains field.
434 */
435 public static function render_attribution_domains_field() {
436 $value = get_option( 'activitypub_attribution_domains', home_host() );
437 ?>
438 <textarea
439 id="activitypub_attribution_domains"
440 name="activitypub_attribution_domains"
441 class="large-text"
442 cols="50" rows="5"
443 placeholder="<?php echo esc_attr( home_host() ); ?>"
444 ><?php echo esc_textarea( $value ); ?></textarea>
445 <p class="description"><?php esc_html_e( 'Websites allowed to credit you, one per line. Protects from false attributions.', 'activitypub' ); ?></p>
446 <?php
447 }
448
449 /**
450 * Render relays field.
451 */
452 public static function render_relays_field() {
453 $value = \get_option( 'activitypub_relays', array() );
454 ?>
455 <textarea
456 id="activitypub_relays"
457 name="activitypub_relays"
458 class="large-text"
459 cols="50"
460 rows="5"
461 ><?php echo \esc_textarea( implode( PHP_EOL, $value ) ); ?></textarea>
462 <p class="description">
463 <?php echo \wp_kses( \__( 'A <strong>Fediverse-Relay</strong> distributes content across instances, expanding reach, engagement, and discoverability, especially for smaller instances.', 'activitypub' ), 'default' ); ?>
464 </p>
465 <p class="description">
466 <?php
467 echo \wp_kses(
468 \__( 'Enter the <strong>Inbox-URLs</strong> (e.g. <code>https://relay.example.com/inbox</code>) of the relays you want to use, one per line.', 'activitypub' ),
469 array(
470 'strong' => array(),
471 'code' => array(),
472 )
473 );
474 ?>
475 <?php echo \wp_kses( \__( 'You can find a list of public relays on <a href="https://relaylist.com/" target="_blank">relaylist.com</a> or on <a href="https://fedidb.org/software/activity-relay" target="_blank">FediDB</a>.', 'activitypub' ), 'default' ); ?>
476 </p>
477 <?php
478 }
479
480 /**
481 * Render moderation section description.
482 */
483 public static function render_moderation_section_description() {
484 echo '<p>' . \esc_html__( 'Configure site-wide moderation settings. These blocks will affect all users and ActivityPub content on your site.', 'activitypub' ) . '</p>';
485 }
486
487 /**
488 * Render site blocked domains field.
489 */
490 public static function render_site_blocked_domains_field() {
491 $blocked_domains = Moderation::get_site_blocks()['domains'];
492 $count = \count( $blocked_domains );
493 ?>
494 <p class="description"><?php \esc_html_e( 'Block entire ActivityPub instances by domain name.', 'activitypub' ); ?></p>
495
496 <div class="activitypub-site-block-list">
497 <details class="activitypub-site-block-details" data-type="domain"<?php echo empty( $blocked_domains ) ? ' open' : ''; ?>>
498 <summary>
499 <?php if ( $count > 0 ) : ?>
500 <?php
501 echo \esc_html(
502 \sprintf(
503 /* translators: %s: Number of blocked domains */
504 \_n( '%s blocked domain', '%s blocked domains', $count, 'activitypub' ),
505 \number_format_i18n( $count )
506 )
507 );
508 ?>
509 <?php else : ?>
510 <?php \esc_html_e( 'No blocked domains', 'activitypub' ); ?>
511 <?php endif; ?>
512 </summary>
513 <?php if ( ! empty( $blocked_domains ) ) : ?>
514 <table class="widefat striped activitypub-site-blocked-domain" role="presentation">
515 <tbody>
516 <?php foreach ( $blocked_domains as $domain ) : ?>
517 <tr>
518 <td><?php echo \esc_html( $domain ); ?></td>
519 <td>
520 <button type="button" class="button button-small remove-site-block-btn" data-type="domain" data-value="<?php echo \esc_attr( $domain ); ?>">
521 <?php \esc_html_e( 'Remove', 'activitypub' ); ?>
522 </button>
523 </td>
524 </tr>
525 <?php endforeach; ?>
526 </tbody>
527 </table>
528 <?php endif; ?>
529 </details>
530
531 <div class="add-site-block-form" style="display: flex; max-width: 500px; gap: 8px;">
532 <input type="text" class="regular-text" id="new_site_domain" placeholder="<?php \esc_attr_e( 'example.com', 'activitypub' ); ?>" style="flex: 1; min-width: 0;" />
533 <button type="button" class="button add-site-block-btn" data-type="domain" style="flex-shrink: 0; white-space: nowrap;">
534 <?php \esc_html_e( 'Add Block', 'activitypub' ); ?>
535 </button>
536 </div>
537 </div>
538 <?php
539 }
540
541 /**
542 * Render site blocked keywords field.
543 */
544 public static function render_site_blocked_keywords_field() {
545 $blocked_keywords = Moderation::get_site_blocks()['keywords'];
546 $count = \count( $blocked_keywords );
547 ?>
548 <p class="description"><?php \esc_html_e( 'Block ActivityPub content containing specific keywords.', 'activitypub' ); ?></p>
549
550 <div class="activitypub-site-block-list">
551 <details class="activitypub-site-block-details" data-type="keyword"<?php echo empty( $blocked_keywords ) ? ' open' : ''; ?>>
552 <summary>
553 <?php if ( $count > 0 ) : ?>
554 <?php
555 echo \esc_html(
556 \sprintf(
557 /* translators: %s: Number of blocked keywords */
558 \_n( '%s blocked keyword', '%s blocked keywords', $count, 'activitypub' ),
559 \number_format_i18n( $count )
560 )
561 );
562 ?>
563 <?php else : ?>
564 <?php \esc_html_e( 'No blocked keywords', 'activitypub' ); ?>
565 <?php endif; ?>
566 </summary>
567 <?php if ( ! empty( $blocked_keywords ) ) : ?>
568 <table class="widefat striped activitypub-site-blocked-keyword" role="presentation">
569 <tbody>
570 <?php foreach ( $blocked_keywords as $keyword ) : ?>
571 <tr>
572 <td><?php echo \esc_html( $keyword ); ?></td>
573 <td>
574 <button type="button" class="button button-small remove-site-block-btn" data-type="keyword" data-value="<?php echo \esc_attr( $keyword ); ?>">
575 <?php \esc_html_e( 'Remove', 'activitypub' ); ?>
576 </button>
577 </td>
578 </tr>
579 <?php endforeach; ?>
580 </tbody>
581 </table>
582 <?php endif; ?>
583 </details>
584
585 <div class="add-site-block-form" style="display: flex; max-width: 500px; gap: 8px;">
586 <input type="text" class="regular-text" id="new_site_keyword" placeholder="<?php \esc_attr_e( 'spam keyword', 'activitypub' ); ?>" style="flex: 1; min-width: 0;" />
587 <button type="button" class="button add-site-block-btn" data-type="keyword" style="flex-shrink: 0; white-space: nowrap;">
588 <?php \esc_html_e( 'Add Block', 'activitypub' ); ?>
589 </button>
590 </div>
591 </div>
592 <?php
593 }
594
595 /**
596 * Render blocklist subscriptions field.
597 */
598 public static function render_blocklist_subscriptions_field() {
599 $subscriptions = Blocklist_Subscriptions::get_all();
600 ?>
601 <p class="description"><?php \esc_html_e( 'Subscribe to remote blocklists that sync automatically every week.', 'activitypub' ); ?></p>
602
603 <div class="activitypub-blocklist-subscriptions">
604 <?php if ( ! empty( $subscriptions ) ) : ?>
605 <table class="widefat striped" role="presentation" style="max-width: 500px; margin: 15px 0;">
606 <thead>
607 <tr>
608 <th style="padding: 10px;"><?php \esc_html_e( 'URL', 'activitypub' ); ?></th>
609 <th style="padding: 10px;"><?php \esc_html_e( 'Last Synced', 'activitypub' ); ?></th>
610 <th style="width: 80px;"></th>
611 </tr>
612 </thead>
613 <tbody>
614 <?php foreach ( $subscriptions as $url => $timestamp ) : ?>
615 <tr>
616 <td>
617 <abbr title="<?php echo \esc_attr( $url ); ?>"><?php echo \esc_html( \wp_parse_url( $url, PHP_URL_HOST ) ); ?></abbr>
618 </td>
619 <td>
620 <?php if ( $timestamp > 0 ) : ?>
621 <?php echo \esc_html( \human_time_diff( $timestamp, \time() ) . ' ' . \__( 'ago', 'activitypub' ) ); ?>
622 <?php else : ?>
623 <em><?php \esc_html_e( 'Never', 'activitypub' ); ?></em>
624 <?php endif; ?>
625 </td>
626 <td>
627 <button type="button" class="button button-small remove-blocklist-subscription-btn" data-url="<?php echo \esc_attr( $url ); ?>">
628 <?php \esc_html_e( 'Remove', 'activitypub' ); ?>
629 </button>
630 </td>
631 </tr>
632 <?php endforeach; ?>
633 </tbody>
634 </table>
635 <?php endif; ?>
636
637 <div class="add-blocklist-subscription-form" style="display: flex; max-width: 500px; gap: 8px;">
638 <input type="url" class="regular-text" id="new_blocklist_subscription_url" placeholder="<?php \esc_attr_e( 'https://example.com/blocklist.csv', 'activitypub' ); ?>" style="flex: 1; min-width: 0;" />
639 <button type="button" class="button add-blocklist-subscription-btn" style="flex-shrink: 0; white-space: nowrap;">
640 <?php \esc_html_e( 'Subscribe', 'activitypub' ); ?>
641 </button>
642 </div>
643
644 <?php if ( ! isset( $subscriptions[ Blocklist_Subscriptions::IFTAS_DNI_URL ] ) ) : ?>
645 <p class="description" style="margin-top: 10px;">
646 <button type="button" class="button add-blocklist-subscription-btn" data-url="<?php echo \esc_attr( Blocklist_Subscriptions::IFTAS_DNI_URL ); ?>">
647 <?php \esc_html_e( 'Subscribe to IFTAS DNI List', 'activitypub' ); ?>
648 </button>
649 <?php echo \wp_kses_post( \__( 'Domains <a href="https://about.iftas.org/" target="_blank" rel="noopener">IFTAS</a> recommends not federating with.', 'activitypub' ) ); ?>
650 </p>
651 <?php endif; ?>
652 </div>
653 <?php
654 }
655 }
656