2024-08-27 21:23:33 +02:00
< ? php
/**
2024-12-05 16:16:30 +01:00
* Template for Event Bridge for ActivityPub settings page .
2024-08-27 21:23:33 +02:00
*
2024-12-05 16:16:30 +01:00
* This template is used to display and manage settings for the Event Bridge for ActivityPub plugin .
2024-08-27 21:23:33 +02:00
*
2024-12-05 16:16:30 +01:00
* @ package Event_Bridge_For_ActivityPub
2024-08-27 21:23:33 +02:00
* @ since 1.0 . 0
2024-12-09 18:16:07 +01:00
* @ license AGPL - 3.0 - or - later
2024-08-27 21:23:33 +02:00
*
* @ param array $args An array of arguments for the settings page .
*/
// Exit if accessed directly.
defined ( 'ABSPATH' ) || exit ; // @codeCoverageIgnore
2024-10-19 16:46:50 +02:00
\load_template (
__DIR__ . '/admin-header.php' ,
true ,
array (
'settings' => 'active' ,
)
);
2024-08-27 21:23:33 +02:00
use Activitypub\Activity\Extended_Object\Event ;
2024-08-28 17:48:15 +02:00
if ( ! isset ( $args ) || ! array_key_exists ( 'event_terms' , $args ) ) {
2024-08-27 21:23:33 +02:00
return ;
}
if ( ! current_user_can ( 'manage_options' ) ) {
return ;
}
2024-12-15 09:52:20 +01:00
\get_option ( 'event_bridge_for_activitypub_event_sources_active' , false );
2024-12-10 19:34:15 +01:00
if ( ! isset ( $args ) || ! array_key_exists ( 'supports_event_sources' , $args ) ) {
return ;
}
$event_plugins_supporting_event_sources = $args [ 'supports_event_sources' ];
2024-12-15 23:55:13 +01:00
$selected_plugin = \get_option ( 'event_bridge_for_activitypub_integration_used_for_event_sources_feature' , '' );
2024-12-15 09:52:20 +01:00
$event_sources_active = \get_option ( 'event_bridge_for_activitypub_event_sources_active' , false );
$cache_retention_period = \get_option ( 'event_bridge_for_activitypub_event_source_cache_retention' , DAY_IN_SECONDS );
2024-12-10 19:34:15 +01:00
2024-08-27 21:42:17 +02:00
$event_terms = $args [ 'event_terms' ];
2024-08-27 21:23:33 +02:00
2024-12-05 16:16:30 +01:00
require_once EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . '/includes/event-categories.php' ;
2024-08-27 21:23:33 +02:00
2024-12-05 16:16:30 +01:00
$selected_default_event_category = \get_option ( 'event_bridge_for_activitypub_default_event_category' , 'MEETING' );
$current_category_mapping = \get_option ( 'event_bridge_for_activitypub_event_category_mappings' , array () );
2024-08-27 21:23:33 +02:00
?>
2024-12-05 16:16:30 +01:00
< div class = " event-bridge-for-activitypub-settings event-bridge-for-activitypub-settings-page hide-if-no-js " >
2024-08-27 21:23:33 +02:00
< form method = " post " action = " options.php " >
2024-12-10 19:34:15 +01:00
< ? php \settings_fields ( 'event-bridge-for-activitypub' ); ?>
2024-12-06 18:27:07 +01:00
< div class = " box " >
< h2 > < ? php esc_html_e ( 'Event Summary Text' , 'event-bridge-for-activitypub' ); ?> </h2>
< p >< ? php esc_html_e ( 'Many Fediverse applications (e.g., Mastodon) don\'t fully support events, instead they will show a summary text along with the events title and the URL to your Website.' , 'event-bridge-for-activitypub' ); ?> </p>
< p >
< label for = " event_bridge_for_activitypub_summary_type_preset " >
< input type = " radio " name = " event_bridge_for_activitypub_summary_type " id = " event_bridge_for_activitypub_summary_type_preset " value = " preset " < ? php echo \checked ( 'preset' , \get_option ( 'event_bridge_for_activitypub_summary_type' , EVENT_BRIDGE_FOR_ACTIVITYPUB_DEFAULT_SUMMARY_TYPE ) ); ?> />
2024-12-12 23:24:36 +01:00
< ? php \esc_html_e ( 'Automatic (default)' , 'event-bridge-for-activitypub' ); ?>
2024-12-06 18:27:07 +01:00
-
< span class = " description " >
< ? php \esc_html_e ( 'Let the plugin compose a summary for you. ' , 'event-bridge-for-activitypub' ); ?>
</ span >
</ label >
</ p >
< p >
< label for = " event_bridge_for_activitypub_summary_type_custom " >
< input type = " radio " name = " event_bridge_for_activitypub_summary_type " id = " event_bridge_for_activitypub_summary_type_custom " value = " custom " < ? php echo \checked ( 'custom' , \get_option ( 'event_bridge_for_activitypub_summary_type' , EVENT_BRIDGE_FOR_ACTIVITYPUB_DEFAULT_SUMMARY_TYPE ) ); ?> />
< ? php \esc_html_e ( 'Custom' , 'event-bridge-for-activitypub' ); ?>
-
< span class = " description " >
< ? php \esc_html_e ( 'For advanced users: compose your custom summary via shortcodes.' , 'event-bridge-for-activitypub' ); ?>
</ span >
</ label >
</ p >
< div id = " event_bridge_for_activitypub_summary_type_custom-details " >
< textarea name = " event_bridge_for_activitypub_custom_summary " id = " event_bridge_for_activitypub_custom_summary " rows = " 10 " cols = " 50 " class = " large-text " placeholder = " <?php echo wp_kses( EVENT_BRIDGE_FOR_ACTIVITYPUB_CUSTOM_SUMMARY, 'post' ); ?> " >< ? php echo esc_textarea ( wp_kses ( \get_option ( 'event_bridge_for_activitypub_custom_summary' , EVENT_BRIDGE_FOR_ACTIVITYPUB_CUSTOM_SUMMARY ), 'post' ) ); ?> </textarea>
< details >
2024-12-12 23:24:36 +01:00
< summary >< ? php esc_html_e ( 'See a list Template Tags available for the summary.' , 'event-bridge-for-activitypub' ); ?> </summary>
2024-12-06 18:27:07 +01:00
< div class = " description " >
< dl >
< dt >< code > [ ap_start_time ] </ code >< dt >
< dd >< ? php \esc_html_e ( 'The events title.' , 'event-bridge-for-activitypub' ); ?> </dd>
< dt >< code > [ ap_end_time ] </ code >< dt >
< dd >< ? php \esc_html_e ( 'The events content.' , 'event-bridge-for-activitypub' ); ?> </dd>
< dt >< code > [ ap_location ] </ code >< dt >
< dd >< ? php \esc_html_e ( 'The events location.' , 'event-bridge-for-activitypub' ); ?> </dd>
< dt >< code > [ ap_hashtags ] </ code >< dt >
< dd >< ? php \esc_html_e ( 'The events tags as hashtags.' , 'event-bridge-for-activitypub' ); ?> </dd>
< dt >< code > [ ap_excerpt ] </ code >< dt >
< dd >< ? php \esc_html_e ( 'The events excerpt (may be truncated).' , 'event-bridge-for-activitypub' ); ?> </dd>
< dt >< code > [ ap_content ] </ code >< dt >
< dd >< ? php \esc_html_e ( 'The events description.' , 'event-bridge-for-activitypub' ); ?> </dd>
</ dl >
</ div >
</ details >
</ div >
</ div >
2024-08-27 21:23:33 +02:00
2024-12-10 19:34:15 +01:00
< div class = " box " >
2024-12-14 14:46:00 +01:00
< h2 >< ? php \esc_html_e ( 'Event Sources' , 'event-bridge-for-activitypub' ); ?> </h2>
2024-12-10 19:34:15 +01:00
< ? php
2024-12-15 14:08:16 +01:00
if ( ! \Activitypub\is_user_type_disabled ( 'blog' ) && count ( $event_plugins_supporting_event_sources ) ) {
2024-12-10 19:34:15 +01:00
?>
< table class = " form-table " >
< tbody >
< tr >
< th scope = " row " >
< label for = " event_bridge_for_activitypub_event_sources_active " >< ? php \esc_html_e ( 'Enable External Event Sources' , 'event-bridge-for-activitypub' ); ?> </label>
</ th >
< td >
< input
type = " checkbox "
name = " event_bridge_for_activitypub_event_sources_active "
id = " event_bridge_for_activitypub_event_sources_active "
aria - describedby = " event-sources-description "
value = " 1 "
< ? php echo \checked ( $event_sources_active ); ?>
>
< p id = " event-sources-description " >< ? php esc_html_e ( 'Activate this feature to allow your WordPress site to fetch events from external sources via ActivityPub. Once enabled, you can add any ActivityPub account as a source of events. These events will be cached on your site and seamlessly integrated into your existing event calendar, creating a unified view of events from both internal and external sources.' , 'event-bridge-for-activitypub' ); ?> </p>
</ td >
</ tr >
< ? php
if ( $event_sources_active ) {
?>
< tr >
< th scope = " row " >
2024-12-15 23:55:13 +01:00
< label for = " event_bridge_for_activitypub_integration_used_for_event_sources_feature " >< ? php \esc_html_e ( 'Event Plugin' , 'event-bridge-for-activitypub' ); ?> </label>
2024-12-10 19:34:15 +01:00
</ th >
< td >
< select
2024-12-15 23:55:13 +01:00
name = " event_bridge_for_activitypub_integration_used_for_event_sources_feature "
id = " event_bridge_for_activitypub_integration_used_for_event_sources_feature "
2024-12-10 19:34:15 +01:00
value = " gatherpress "
aria - describedby = " event-sources-used-plugin-description "
>
< ? php
2024-12-15 23:55:13 +01:00
foreach ( $event_plugins_supporting_event_sources as $event_plugin_class_name => $event_plugin_name ) {
echo '<option value="' . esc_attr ( $event_plugin_class_name ) . '" ' . selected ( $event_plugin_class_name , $event_plugin , true ) . '>' . esc_attr ( $event_plugin_name ) . '</option>' ;
2024-12-10 19:34:15 +01:00
}
?>
</ select >
< p id = " event-sources-used-plugin-description " >< ? php esc_html_e ( 'In case you have multiple event plugins installed you might choose which event plugin is utilized.' , 'event-bridge-for-activitypub' ); ?> </p>
</ td >
< tr >
2024-12-15 09:52:20 +01:00
< tr >
< th scope = " row " >
< label for = " event_bridge_for_activitypub_event_source_cache " >< ? php \esc_html_e ( 'Retention Period for External Events' , 'event-bridge-for-activitypub' ); ?> </label>
</ th >
< td >
< select
name = " event_bridge_for_activitypub_event_source_cache_retention "
id = " event_bridge_for_activitypub_event_source_cache_retention "
value = " 0 "
aria - describedby = " event_bridge_for_activitypub_event-sources-cache-clear-time-frame "
>
< ? php
$choices = array (
0 => __ ( 'Immediately' , 'event-bridge-for-activitypub' ),
DAY_IN_SECONDS => __ ( 'One Day' , 'event-bridge-for-activitypub' ),
WEEK_IN_SECONDS => __ ( 'One Week' , 'event-bridge-for-activitypub' ),
MONTH_IN_SECONDS => __ ( 'One Month' , 'event-bridge-for-activitypub' ),
YEAR_IN_SECONDS => __ ( 'One Year' , 'event-bridge-for-activitypub' ),
);
foreach ( $choices as $time => $string ) {
echo '<option value="' . esc_attr ( $time ) . '" ' . selected ( $cache_retention_period , $time , true ) . '>' . esc_attr ( $string ) . '</option>' ;
}
?>
</ select >
< p id = " event_bridge_for_activitypub_event-sources-cache-clear-time-frame " >< ? php esc_html_e ( 'External events from your event sources will be automatically removed from your site after the selected time period has passed since the event ended. Choose a time frame that works best for your needs.' , 'event-bridge-for-activitypub' ); ?> </p>
</ td >
< tr >
2024-12-10 19:34:15 +01:00
< ? php
}
?>
< tbody >
</ table >
< ? php
2024-12-15 14:08:16 +01:00
} elseif ( ! \Activitypub\is_user_type_disabled ( 'blog' ) ) {
2024-12-10 19:34:15 +01:00
?>
< p >< ? php esc_html_e ( 'You do not have an Event Plugin installed that supports this feature' , 'event-bridge-for-activitypub' ); ?> </p>
< p >< ? php esc_html_e ( 'The following Event Plugins are supported:' , 'event-bridge-for-activitypub' ); ?> </p>
< ? php
$plugins_supporting_event_sources = \Event_Bridge_For_ActivityPub\Setup :: detect_event_plugins_supporting_event_sources ();
echo '<ul class="event_bridge_for_activitypub-list">' ;
foreach ( $plugins_supporting_event_sources as $event_plugin ) {
echo '<li>' . esc_attr ( $event_plugin -> get_plugin_name () ) . '</li>' ;
}
echo '</ul>' ;
return ;
2024-12-15 14:08:16 +01:00
} else {
$activitypub_plugin_data = get_plugin_data ( ACTIVITYPUB_PLUGIN_FILE );
$notice = sprintf (
/* translators: 1: The name of the ActivityPub plugin. */
_x (
'In order to use this feature your have to enable the Blog-Actor in the the <a href="%1$s">%2$s settings</a>.' ,
'admin notice' ,
'event-bridge-for-activitypub'
),
admin_url ( 'options-general.php?page=activitypub&tab=settings' ),
esc_html ( $activitypub_plugin_data [ 'Name' ] )
);
$allowed_html = array (
'a' => array (
'href' => true ,
'title' => true ,
),
);
echo '<div class="notice-warning"><p>' . \wp_kses ( $notice , $allowed_html ) . '</p></div>' ;
2024-12-10 19:34:15 +01:00
}
?>
</ div >
2024-08-27 21:23:33 +02:00
< div class = " box " >
2024-12-05 16:16:30 +01:00
< h2 > < ? php esc_html_e ( 'ActivityPub Event Category' , 'event-bridge-for-activitypub' ); ?> </h2>
< p > < ? php esc_html_e ( 'To help visitors find events more easily, the community created a set of basic event categories. Please select the category that best matches the majority of the events you organize.' , 'event-bridge-for-activitypub' ); ?> </p>
2024-08-27 21:23:33 +02:00
< table class = " form-table " >
< tr >
2024-12-05 16:16:30 +01:00
< th scope = " row " > < ? php esc_html_e ( 'Default Category' , 'event-bridge-for-activitypub' ); ?> </th>
2024-08-27 21:23:33 +02:00
< td >
2024-12-05 16:16:30 +01:00
< select id = " event_bridge_for_activitypub_default_event_category " name = " event_bridge_for_activitypub_default_event_category " > ' ;
2024-08-27 21:23:33 +02:00
< ? php
2024-12-05 16:16:30 +01:00
foreach ( EVENT_BRIDGE_FOR_ACTIVITYPUB_EVENT_CATEGORIES as $value => $label ) {
2024-08-27 21:23:33 +02:00
echo '<option value="' . esc_attr ( $value ) . '" ' . selected ( $selected_default_event_category , $value , false ) . '>' . esc_html ( $label ) . '</option>' ;
}
?>
</ select >
</ td >
</ tr >
</ table >
2024-10-19 16:46:50 +02:00
< ? php if ( ! empty ( $event_terms ) ) : ?>
2024-12-05 16:16:30 +01:00
< h3 > < ? php esc_html_e ( 'Advanced Event Category Settings' , 'event-bridge-for-activitypub' ); ?> </h3>
< p > < ? php esc_html_e ( 'Take more control by adjusting how your event categories are mapped to the basic category set used in ActivityPub. This option lets you override the default selection above, ensuring more accurate categorization and better visibility for your events.' , 'event-bridge-for-activitypub' ); ?> </p>
2024-08-27 21:23:33 +02:00
< table class = " form-table " >
< ? php foreach ( $event_terms as $event_term ) { ?>
< tr >
< th scope = " row " > < ? php echo esc_html ( $event_term -> name ); ?> </th>
< td >
2024-12-05 16:16:30 +01:00
< select name = " event_bridge_for_activitypub_event_category_mappings[<?php echo esc_attr( $event_term->slug ); ?>] " >
2024-08-27 21:23:33 +02:00
< ? php
$current_mapping_is_set = false ;
if ( ! empty ( $current_category_mapping ) ) {
$current_mapping_is_set = array_key_exists ( $event_term -> slug , $current_category_mapping );
}
if ( $current_mapping_is_set ) {
$mapping = $current_category_mapping [ $event_term -> slug ];
} else {
$mapping = 'DEFAULT' ;
}
if ( 'DEFAULT' === $mapping ) {
2024-12-05 16:16:30 +01:00
echo '<option value="' . esc_attr ( $mapping ) . '"> -- ' . esc_html ( EVENT_BRIDGE_FOR_ACTIVITYPUB_EVENT_CATEGORIES [ $mapping ] ) . ' -- </option>' ;
2024-08-27 21:23:33 +02:00
} else {
2024-12-05 16:16:30 +01:00
echo '<option value="' . esc_attr ( $mapping ) . '">' . esc_html ( EVENT_BRIDGE_FOR_ACTIVITYPUB_EVENT_CATEGORIES [ $mapping ] ) . '</option>' ;
2024-08-27 21:23:33 +02:00
}
2024-12-05 16:16:30 +01:00
echo '<option value="DEFAULT" ' . selected ( $selected_default_event_category , 'DEFAULT' , false ) . '> -- ' . esc_html__ ( 'Default' , 'event-bridge-for-activitypub' ) . ' -- </option>' ;
2024-08-27 21:23:33 +02:00
foreach ( Event :: DEFAULT_EVENT_CATEGORIES as $event_category ) {
2024-12-05 16:16:30 +01:00
echo '<option value="' . esc_attr ( $event_category ) . '" ' . selected ( $mappings [ $event_term -> slug ] ? ? '' , $event_category , false ) . '>' . esc_html ( EVENT_BRIDGE_FOR_ACTIVITYPUB_EVENT_CATEGORIES [ $event_category ] ) . '</option>' ;
2024-08-27 21:23:33 +02:00
}
?>
</ select >
</ td >
</ tr >
< ? php } ?>
</ table >
2024-10-19 16:46:50 +02:00
< ? php endif ; ?>
</ div >
<!-- This disables the setup wizard . -->
2024-12-08 17:38:05 +01:00
< div class = " hidden " aria - hidden = " true " >
2024-12-05 16:16:30 +01:00
< input type = " checkbox " id = " event_bridge_for_activitypub_initially_activated " name = " event_bridge_for_activitypub_initially_activated " />
2024-08-27 21:23:33 +02:00
</ div >
< ? php \submit_button (); ?>
</ form >
</ div >