| 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_use_hashtags', |
| 118 |
__( 'Hashtags', 'activitypub' ), |
| 119 |
array( self::class, 'render_use_hashtags_field' ), |
| 120 |
'activitypub_settings', |
| 121 |
'activitypub_activities', |
| 122 |
array( 'label_for' => 'activitypub_use_hashtags' ) |
| 123 |
); |
| 124 |
|
| 125 |
add_settings_field( |
| 126 |
'activitypub_use_opengraph', |
| 127 |
__( 'OpenGraph', 'activitypub' ), |
| 128 |
array( self::class, 'render_use_opengraph_field' ), |
| 129 |
'activitypub_settings', |
| 130 |
'activitypub_general', |
| 131 |
array( 'label_for' => 'activitypub_use_opengraph' ) |
| 132 |
); |
| 133 |
|
| 134 |
add_settings_field( |
| 135 |
'activitypub_attribution_domains', |
| 136 |
__( 'Attribution Domains', 'activitypub' ), |
| 137 |
array( self::class, 'render_attribution_domains_field' ), |
| 138 |
'activitypub_settings', |
| 139 |
'activitypub_general', |
| 140 |
array( 'label_for' => 'activitypub_attribution_domains' ) |
| 141 |
); |
| 142 |
|
| 143 |
add_settings_field( |
| 144 |
'activitypub_relays', |
| 145 |
__( 'Relays', 'activitypub' ), |
| 146 |
array( self::class, 'render_relays_field' ), |
| 147 |
'activitypub_settings', |
| 148 |
'activitypub_server', |
| 149 |
array( 'label_for' => 'activitypub_relays' ) |
| 150 |
); |
| 151 |
|
| 152 |
add_settings_field( |
| 153 |
'activitypub_site_blocked_domains', |
| 154 |
\esc_html__( 'Blocked Domains', 'activitypub' ), |
| 155 |
array( self::class, 'render_site_blocked_domains_field' ), |
| 156 |
'activitypub_settings', |
| 157 |
'activitypub_moderation' |
| 158 |
); |
| 159 |
|
| 160 |
add_settings_field( |
| 161 |
'activitypub_site_blocked_keywords', |
| 162 |
\esc_html__( 'Blocked Keywords', 'activitypub' ), |
| 163 |
array( self::class, 'render_site_blocked_keywords_field' ), |
| 164 |
'activitypub_settings', |
| 165 |
'activitypub_moderation' |
| 166 |
); |
| 167 |
|
| 168 |
add_settings_field( |
| 169 |
'activitypub_blocklist_subscriptions', |
| 170 |
\esc_html__( 'Blocklist Subscriptions', 'activitypub' ), |
| 171 |
array( self::class, 'render_blocklist_subscriptions_field' ), |
| 172 |
'activitypub_settings', |
| 173 |
'activitypub_moderation' |
| 174 |
); |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Render actor mode field. |
| 179 |
*/ |
| 180 |
public static function render_actor_mode_field() { |
| 181 |
$disabled = ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) && ACTIVITYPUB_SINGLE_USER_MODE ) || |
| 182 |
( \defined( 'ACTIVITYPUB_DISABLE_USER' ) && ACTIVITYPUB_DISABLE_USER ) || |
| 183 |
( \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) && ACTIVITYPUB_DISABLE_BLOG_USER ); |
| 184 |
|
| 185 |
if ( $disabled ) : |
| 186 |
?> |
| 187 |
<p class="description"> |
| 188 |
<?php esc_html_e( 'âš This setting is defined through server configuration by your blog’s administrator.', 'activitypub' ); ?> |
| 189 |
</p> |
| 190 |
<?php |
| 191 |
return; |
| 192 |
endif; |
| 193 |
|
| 194 |
$value = get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ); |
| 195 |
?> |
| 196 |
<fieldset class="actor-mode-selection"> |
| 197 |
<div class="row"> |
| 198 |
<input type="radio" id="actor-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_MODE, $value ); ?> /> |
| 199 |
<div> |
| 200 |
<label for="actor-mode"><strong><?php esc_html_e( 'Author Profiles Only', 'activitypub' ); ?></strong></label> |
| 201 |
<p class="description"> |
| 202 |
<?php echo wp_kses( __( 'Every author on this blog (with the <code>activitypub</code> capability) gets their own ActivityPub profile.', 'activitypub' ), array( 'code' => array() ) ); ?> |
| 203 |
<strong> |
| 204 |
<?php |
| 205 |
echo wp_kses( |
| 206 |
sprintf( |
| 207 |
// translators: %s is a URL. |
| 208 |
__( 'You can add/remove the capability in the <a href="%s">user settings.</a>', 'activitypub' ), |
| 209 |
admin_url( '/users.php' ) |
| 210 |
), |
| 211 |
array( 'a' => array( 'href' => array() ) ) |
| 212 |
); |
| 213 |
?> |
| 214 |
</strong> |
| 215 |
<?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() ) ); ?> |
| 216 |
</p> |
| 217 |
</div> |
| 218 |
</div> |
| 219 |
<div class="row"> |
| 220 |
<input type="radio" id="blog-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_BLOG_MODE, $value ); ?> /> |
| 221 |
<div> |
| 222 |
<label for="blog-mode"><strong><?php esc_html_e( 'Blog profile only', 'activitypub' ); ?></strong></label> |
| 223 |
<p class="description"> |
| 224 |
<?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' ); ?> |
| 225 |
</p> |
| 226 |
</div> |
| 227 |
</div> |
| 228 |
<div class="row"> |
| 229 |
<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 ); ?> /> |
| 230 |
<div> |
| 231 |
<label for="actor-blog-mode"><strong><?php esc_html_e( 'Both author and blog profiles', 'activitypub' ); ?></strong></label> |
| 232 |
<p class="description"> |
| 233 |
<?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' ); ?> |
| 234 |
</p> |
| 235 |
</div> |
| 236 |
</div> |
| 237 |
</fieldset> |
| 238 |
<?php |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* Render custom post content field. |
| 243 |
*/ |
| 244 |
public static function render_custom_post_content_field() { |
| 245 |
$value = get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT ); |
| 246 |
?> |
| 247 |
<p> |
| 248 |
<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> |
| 249 |
<details> |
| 250 |
<summary><?php esc_html_e( 'See a list of ActivityPub Template Tags.', 'activitypub' ); ?></summary> |
| 251 |
<div class="description"> |
| 252 |
<ul> |
| 253 |
<li><code>[ap_title]</code> - <?php esc_html_e( 'The post’s title.', 'activitypub' ); ?></li> |
| 254 |
<li><code>[ap_content]</code> - <?php esc_html_e( 'The post’s content.', 'activitypub' ); ?></li> |
| 255 |
<li><code>[ap_excerpt]</code> - <?php esc_html_e( 'The post’s excerpt (may be truncated).', 'activitypub' ); ?></li> |
| 256 |
<li><code>[ap_permalink]</code> - <?php esc_html_e( 'The post’s permalink.', 'activitypub' ); ?></li> |
| 257 |
<li><code>[ap_shortlink]</code> - <?php echo wp_kses( __( 'The post’s shortlink. I can recommend <a href="https://wordpress.org/plugins/hum/" target="_blank">Hum</a>.', 'activitypub' ), 'default' ); ?></li> |
| 258 |
<li><code>[ap_hashtags]</code> - <?php esc_html_e( 'The post’s tags as hashtags.', 'activitypub' ); ?></li> |
| 259 |
</ul> |
| 260 |
<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> |
| 261 |
</div> |
| 262 |
</details> |
| 263 |
</p> |
| 264 |
<?php |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* Render max image attachments field. |
| 269 |
*/ |
| 270 |
public static function render_max_image_attachments_field() { |
| 271 |
$value = get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ); |
| 272 |
?> |
| 273 |
<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" /> |
| 274 |
<p class="description"> |
| 275 |
<?php |
| 276 |
echo wp_kses( |
| 277 |
sprintf( |
| 278 |
// translators: %s is a number. |
| 279 |
__( 'The number of media (images, audio, video) to attach to posts. Default: <code>%s</code>', 'activitypub' ), |
| 280 |
esc_html( ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ) |
| 281 |
), |
| 282 |
'default' |
| 283 |
); |
| 284 |
?> |
| 285 |
</p> |
| 286 |
<p class="description"> |
| 287 |
<em> |
| 288 |
<?php esc_html_e( 'Note: audio and video attachments are only supported from Block Editor.', 'activitypub' ); ?> |
| 289 |
</em> |
| 290 |
</p> |
| 291 |
<?php |
| 292 |
} |
| 293 |
|
| 294 |
/** |
| 295 |
* Render support post types field. |
| 296 |
*/ |
| 297 |
public static function render_support_post_types_field() { |
| 298 |
$post_types = \get_post_types( array( 'public' => true ), 'objects' ); |
| 299 |
$supported_post_types = \get_option( 'activitypub_support_post_types', array( 'post' ) ); |
| 300 |
?> |
| 301 |
<fieldset> |
| 302 |
<?php esc_html_e( 'Automatically publish items of the selected post types to the fediverse:', 'activitypub' ); ?> |
| 303 |
<ul> |
| 304 |
<?php foreach ( $post_types as $post_type ) : ?> |
| 305 |
<li> |
| 306 |
<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 ) ); ?> /> |
| 307 |
<label for="activitypub_support_post_type_<?php echo esc_attr( $post_type->name ); ?>"><?php echo esc_html( $post_type->label ); ?></label> |
| 308 |
<span class="description"> |
| 309 |
<?php echo esc_html( \Activitypub\get_post_type_description( $post_type ) ); ?> |
| 310 |
</span> |
| 311 |
</li> |
| 312 |
<?php endforeach; ?> |
| 313 |
</ul> |
| 314 |
</fieldset> |
| 315 |
<?php |
| 316 |
} |
| 317 |
|
| 318 |
/** |
| 319 |
* Render allow interactions field. |
| 320 |
*/ |
| 321 |
public static function render_allow_interactions_field() { |
| 322 |
if ( defined( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS' ) && ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) { |
| 323 |
echo '<p class="description">' . \esc_html__( 'âš This setting is defined through server configuration by your blog’s administrator.', 'activitypub' ) . '</p>'; |
| 324 |
return; |
| 325 |
} |
| 326 |
|
| 327 |
$allow_likes = get_option( 'activitypub_allow_likes', '1' ); |
| 328 |
$allow_reposts = get_option( 'activitypub_allow_reposts', '1' ); |
| 329 |
$auto_approve = get_option( 'activitypub_auto_approve_reactions', '0' ); |
| 330 |
?> |
| 331 |
<fieldset> |
| 332 |
<p> |
| 333 |
<label> |
| 334 |
<input type="checkbox" name="activitypub_allow_likes" value="1" <?php checked( '1', $allow_likes ); ?> /> |
| 335 |
<?php esc_html_e( 'Receive likes', 'activitypub' ); ?> |
| 336 |
</label> |
| 337 |
</p> |
| 338 |
<p> |
| 339 |
<label> |
| 340 |
<input type="checkbox" name="activitypub_allow_reposts" value="1" <?php checked( '1', $allow_reposts ); ?> /> |
| 341 |
<?php esc_html_e( 'Receive reblogs (boosts)', 'activitypub' ); ?> |
| 342 |
</label> |
| 343 |
</p> |
| 344 |
<p class="interactions description"><?php esc_html_e( 'Types of interactions from the Fediverse your blog should accept.', 'activitypub' ); ?></p> |
| 345 |
<p> |
| 346 |
<label> |
| 347 |
<input type="checkbox" name="activitypub_auto_approve_reactions" value="1" <?php checked( '1', $auto_approve ); ?> /> |
| 348 |
<?php esc_html_e( 'Auto approve reactions', 'activitypub' ); ?> |
| 349 |
</label> |
| 350 |
</p> |
| 351 |
</fieldset> |
| 352 |
<?php |
| 353 |
} |
| 354 |
|
| 355 |
/** |
| 356 |
* Render use hashtags field. |
| 357 |
*/ |
| 358 |
public static function render_use_hashtags_field() { |
| 359 |
$value = get_option( 'activitypub_use_hashtags', '1' ); |
| 360 |
?> |
| 361 |
<p> |
| 362 |
<label> |
| 363 |
<input type="checkbox" id="activitypub_use_hashtags" name="activitypub_use_hashtags" value="1" <?php checked( '1', $value ); ?> /> |
| 364 |
<?php echo wp_kses( __( 'Add hashtags in the content as native tags and replace the <code>#tag</code> with the tag link.', 'activitypub' ), 'default' ); ?> |
| 365 |
</label> |
| 366 |
</p> |
| 367 |
<?php |
| 368 |
} |
| 369 |
|
| 370 |
/** |
| 371 |
* Render use OpenGraph field. |
| 372 |
*/ |
| 373 |
public static function render_use_opengraph_field() { |
| 374 |
$value = get_option( 'activitypub_use_opengraph', '1' ); |
| 375 |
?> |
| 376 |
<p> |
| 377 |
<label> |
| 378 |
<input type="checkbox" id="activitypub_use_opengraph" name="activitypub_use_opengraph" value="1" <?php checked( '1', $value ); ?> /> |
| 379 |
<?php echo wp_kses( __( 'Automatically add <code><meta name="fediverse:creator" /></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' ); ?> |
| 380 |
</label> |
| 381 |
</p> |
| 382 |
<?php |
| 383 |
} |
| 384 |
|
| 385 |
/** |
| 386 |
* Render attribution domains field. |
| 387 |
*/ |
| 388 |
public static function render_attribution_domains_field() { |
| 389 |
$value = get_option( 'activitypub_attribution_domains', home_host() ); |
| 390 |
?> |
| 391 |
<textarea |
| 392 |
id="activitypub_attribution_domains" |
| 393 |
name="activitypub_attribution_domains" |
| 394 |
class="large-text" |
| 395 |
cols="50" rows="5" |
| 396 |
placeholder="<?php echo esc_attr( home_host() ); ?>" |
| 397 |
><?php echo esc_textarea( $value ); ?></textarea> |
| 398 |
<p class="description"><?php esc_html_e( 'Websites allowed to credit you, one per line. Protects from false attributions.', 'activitypub' ); ?></p> |
| 399 |
<?php |
| 400 |
} |
| 401 |
|
| 402 |
/** |
| 403 |
* Render relays field. |
| 404 |
*/ |
| 405 |
public static function render_relays_field() { |
| 406 |
$value = \get_option( 'activitypub_relays', array() ); |
| 407 |
?> |
| 408 |
<textarea |
| 409 |
id="activitypub_relays" |
| 410 |
name="activitypub_relays" |
| 411 |
class="large-text" |
| 412 |
cols="50" |
| 413 |
rows="5" |
| 414 |
><?php echo \esc_textarea( implode( PHP_EOL, $value ) ); ?></textarea> |
| 415 |
<p class="description"> |
| 416 |
<?php echo \wp_kses( \__( 'A <strong>Fediverse-Relay</strong> distributes content across instances, expanding reach, engagement, and discoverability, especially for smaller instances.', 'activitypub' ), 'default' ); ?> |
| 417 |
</p> |
| 418 |
<p class="description"> |
| 419 |
<?php |
| 420 |
echo \wp_kses( |
| 421 |
\__( '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' ), |
| 422 |
array( |
| 423 |
'strong' => array(), |
| 424 |
'code' => array(), |
| 425 |
) |
| 426 |
); |
| 427 |
?> |
| 428 |
<?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' ); ?> |
| 429 |
</p> |
| 430 |
<?php |
| 431 |
} |
| 432 |
|
| 433 |
/** |
| 434 |
* Render moderation section description. |
| 435 |
*/ |
| 436 |
public static function render_moderation_section_description() { |
| 437 |
echo '<p>' . \esc_html__( 'Configure site-wide moderation settings. These blocks will affect all users and ActivityPub content on your site.', 'activitypub' ) . '</p>'; |
| 438 |
} |
| 439 |
|
| 440 |
/** |
| 441 |
* Render site blocked domains field. |
| 442 |
*/ |
| 443 |
public static function render_site_blocked_domains_field() { |
| 444 |
$blocked_domains = Moderation::get_site_blocks()['domains']; |
| 445 |
$count = \count( $blocked_domains ); |
| 446 |
?> |
| 447 |
<p class="description"><?php \esc_html_e( 'Block entire ActivityPub instances by domain name.', 'activitypub' ); ?></p> |
| 448 |
|
| 449 |
<div class="activitypub-site-block-list"> |
| 450 |
<details class="activitypub-site-block-details" data-type="domain"<?php echo empty( $blocked_domains ) ? ' open' : ''; ?>> |
| 451 |
<summary> |
| 452 |
<?php if ( $count > 0 ) : ?> |
| 453 |
<?php |
| 454 |
echo \esc_html( |
| 455 |
\sprintf( |
| 456 |
/* translators: %s: Number of blocked domains */ |
| 457 |
\_n( '%s blocked domain', '%s blocked domains', $count, 'activitypub' ), |
| 458 |
\number_format_i18n( $count ) |
| 459 |
) |
| 460 |
); |
| 461 |
?> |
| 462 |
<?php else : ?> |
| 463 |
<?php \esc_html_e( 'No blocked domains', 'activitypub' ); ?> |
| 464 |
<?php endif; ?> |
| 465 |
</summary> |
| 466 |
<?php if ( ! empty( $blocked_domains ) ) : ?> |
| 467 |
<table class="widefat striped activitypub-site-blocked-domain" role="presentation"> |
| 468 |
<tbody> |
| 469 |
<?php foreach ( $blocked_domains as $domain ) : ?> |
| 470 |
<tr> |
| 471 |
<td><?php echo \esc_html( $domain ); ?></td> |
| 472 |
<td> |
| 473 |
<button type="button" class="button button-small remove-site-block-btn" data-type="domain" data-value="<?php echo \esc_attr( $domain ); ?>"> |
| 474 |
<?php \esc_html_e( 'Remove', 'activitypub' ); ?> |
| 475 |
</button> |
| 476 |
</td> |
| 477 |
</tr> |
| 478 |
<?php endforeach; ?> |
| 479 |
</tbody> |
| 480 |
</table> |
| 481 |
<?php endif; ?> |
| 482 |
</details> |
| 483 |
|
| 484 |
<div class="add-site-block-form" style="display: flex; max-width: 500px; gap: 8px;"> |
| 485 |
<input type="text" class="regular-text" id="new_site_domain" placeholder="<?php \esc_attr_e( 'example.com', 'activitypub' ); ?>" style="flex: 1; min-width: 0;" /> |
| 486 |
<button type="button" class="button add-site-block-btn" data-type="domain" style="flex-shrink: 0; white-space: nowrap;"> |
| 487 |
<?php \esc_html_e( 'Add Block', 'activitypub' ); ?> |
| 488 |
</button> |
| 489 |
</div> |
| 490 |
</div> |
| 491 |
<?php |
| 492 |
} |
| 493 |
|
| 494 |
/** |
| 495 |
* Render site blocked keywords field. |
| 496 |
*/ |
| 497 |
public static function render_site_blocked_keywords_field() { |
| 498 |
$blocked_keywords = Moderation::get_site_blocks()['keywords']; |
| 499 |
$count = \count( $blocked_keywords ); |
| 500 |
?> |
| 501 |
<p class="description"><?php \esc_html_e( 'Block ActivityPub content containing specific keywords.', 'activitypub' ); ?></p> |
| 502 |
|
| 503 |
<div class="activitypub-site-block-list"> |
| 504 |
<details class="activitypub-site-block-details" data-type="keyword"<?php echo empty( $blocked_keywords ) ? ' open' : ''; ?>> |
| 505 |
<summary> |
| 506 |
<?php if ( $count > 0 ) : ?> |
| 507 |
<?php |
| 508 |
echo \esc_html( |
| 509 |
\sprintf( |
| 510 |
/* translators: %s: Number of blocked keywords */ |
| 511 |
\_n( '%s blocked keyword', '%s blocked keywords', $count, 'activitypub' ), |
| 512 |
\number_format_i18n( $count ) |
| 513 |
) |
| 514 |
); |
| 515 |
?> |
| 516 |
<?php else : ?> |
| 517 |
<?php \esc_html_e( 'No blocked keywords', 'activitypub' ); ?> |
| 518 |
<?php endif; ?> |
| 519 |
</summary> |
| 520 |
<?php if ( ! empty( $blocked_keywords ) ) : ?> |
| 521 |
<table class="widefat striped activitypub-site-blocked-keyword" role="presentation"> |
| 522 |
<tbody> |
| 523 |
<?php foreach ( $blocked_keywords as $keyword ) : ?> |
| 524 |
<tr> |
| 525 |
<td><?php echo \esc_html( $keyword ); ?></td> |
| 526 |
<td> |
| 527 |
<button type="button" class="button button-small remove-site-block-btn" data-type="keyword" data-value="<?php echo \esc_attr( $keyword ); ?>"> |
| 528 |
<?php \esc_html_e( 'Remove', 'activitypub' ); ?> |
| 529 |
</button> |
| 530 |
</td> |
| 531 |
</tr> |
| 532 |
<?php endforeach; ?> |
| 533 |
</tbody> |
| 534 |
</table> |
| 535 |
<?php endif; ?> |
| 536 |
</details> |
| 537 |
|
| 538 |
<div class="add-site-block-form" style="display: flex; max-width: 500px; gap: 8px;"> |
| 539 |
<input type="text" class="regular-text" id="new_site_keyword" placeholder="<?php \esc_attr_e( 'spam keyword', 'activitypub' ); ?>" style="flex: 1; min-width: 0;" /> |
| 540 |
<button type="button" class="button add-site-block-btn" data-type="keyword" style="flex-shrink: 0; white-space: nowrap;"> |
| 541 |
<?php \esc_html_e( 'Add Block', 'activitypub' ); ?> |
| 542 |
</button> |
| 543 |
</div> |
| 544 |
</div> |
| 545 |
<?php |
| 546 |
} |
| 547 |
|
| 548 |
/** |
| 549 |
* Render blocklist subscriptions field. |
| 550 |
*/ |
| 551 |
public static function render_blocklist_subscriptions_field() { |
| 552 |
$subscriptions = Blocklist_Subscriptions::get_all(); |
| 553 |
?> |
| 554 |
<p class="description"><?php \esc_html_e( 'Subscribe to remote blocklists that sync automatically every week.', 'activitypub' ); ?></p> |
| 555 |
|
| 556 |
<div class="activitypub-blocklist-subscriptions"> |
| 557 |
<?php if ( ! empty( $subscriptions ) ) : ?> |
| 558 |
<table class="widefat striped" role="presentation" style="max-width: 500px; margin: 15px 0;"> |
| 559 |
<thead> |
| 560 |
<tr> |
| 561 |
<th style="padding: 10px;"><?php \esc_html_e( 'URL', 'activitypub' ); ?></th> |
| 562 |
<th style="padding: 10px;"><?php \esc_html_e( 'Last Synced', 'activitypub' ); ?></th> |
| 563 |
<th style="width: 80px;"></th> |
| 564 |
</tr> |
| 565 |
</thead> |
| 566 |
<tbody> |
| 567 |
<?php foreach ( $subscriptions as $url => $timestamp ) : ?> |
| 568 |
<tr> |
| 569 |
<td> |
| 570 |
<abbr title="<?php echo \esc_attr( $url ); ?>"><?php echo \esc_html( \wp_parse_url( $url, PHP_URL_HOST ) ); ?></abbr> |
| 571 |
</td> |
| 572 |
<td> |
| 573 |
<?php if ( $timestamp > 0 ) : ?> |
| 574 |
<?php echo \esc_html( \human_time_diff( $timestamp, \time() ) . ' ' . \__( 'ago', 'activitypub' ) ); ?> |
| 575 |
<?php else : ?> |
| 576 |
<em><?php \esc_html_e( 'Never', 'activitypub' ); ?></em> |
| 577 |
<?php endif; ?> |
| 578 |
</td> |
| 579 |
<td> |
| 580 |
<button type="button" class="button button-small remove-blocklist-subscription-btn" data-url="<?php echo \esc_attr( $url ); ?>"> |
| 581 |
<?php \esc_html_e( 'Remove', 'activitypub' ); ?> |
| 582 |
</button> |
| 583 |
</td> |
| 584 |
</tr> |
| 585 |
<?php endforeach; ?> |
| 586 |
</tbody> |
| 587 |
</table> |
| 588 |
<?php endif; ?> |
| 589 |
|
| 590 |
<div class="add-blocklist-subscription-form" style="display: flex; max-width: 500px; gap: 8px;"> |
| 591 |
<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;" /> |
| 592 |
<button type="button" class="button add-blocklist-subscription-btn" style="flex-shrink: 0; white-space: nowrap;"> |
| 593 |
<?php \esc_html_e( 'Subscribe', 'activitypub' ); ?> |
| 594 |
</button> |
| 595 |
</div> |
| 596 |
|
| 597 |
<?php if ( ! isset( $subscriptions[ Blocklist_Subscriptions::IFTAS_DNI_URL ] ) ) : ?> |
| 598 |
<p class="description" style="margin-top: 10px;"> |
| 599 |
<button type="button" class="button add-blocklist-subscription-btn" data-url="<?php echo \esc_attr( Blocklist_Subscriptions::IFTAS_DNI_URL ); ?>"> |
| 600 |
<?php \esc_html_e( 'Subscribe to IFTAS DNI List', 'activitypub' ); ?> |
| 601 |
</button> |
| 602 |
<?php echo \wp_kses_post( \__( 'Domains <a href="https://about.iftas.org/" target="_blank" rel="noopener">IFTAS</a> recommends not federating with.', 'activitypub' ) ); ?> |
| 603 |
</p> |
| 604 |
<?php endif; ?> |
| 605 |
</div> |
| 606 |
<?php |
| 607 |
} |
| 608 |
} |
| 609 |
|