several improvements and fixes

- plugin version handling
- category mapping
- settings page css
This commit is contained in:
André Menrath 2024-08-28 17:48:15 +02:00
parent efcdf00ae3
commit be9733c55b
6 changed files with 58 additions and 29 deletions

View file

@ -3,7 +3,7 @@
* Plugin Name: ActivityPub Event Extensions
* Description: Custom ActivityPub Transformers and Integrations for common Event Plugins.
* Plugin URI: https://event-federation.eu/
* Version: 1.0.0
* Version: 0.1.0
* Author: André Menrath
* Author URI: https://graz.social/@linos
* Text Domain: activitypub-event-extensions
@ -18,12 +18,11 @@
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_VERSION', '1.0.0' );
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) );
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_VERSION', current( get_file_data( __FILE__, array( 'Version' ), 'plugin' ) ) );
// Include and register the autoloader class for automatic loading of plugin classes.
require_once ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . '/includes/class-autoloader.php';

View file

@ -0,0 +1,6 @@
.activitypub-settings-page .box {
border: 1px solid #c3c4c7;
background-color: #fff;
padding: 1em 1.5em;
margin-bottom: 1.5em;
}

View file

@ -52,16 +52,30 @@ class Event extends Post {
return 'Event';
}
/**
* Extend the construction of the Post Transformer to also set the according taxonomy of the event post type.
*
* @param WP_Post $wp_object The WordPress post object (event).
* @param string $wp_taxonomy The taxonomy slug of the event post type.
*/
public function __construct( $wp_object, $wp_taxonomy ) {
parent::__construct( $wp_object );
$this->wp_taxonomy = $wp_taxonomy;
}
/**
* Set the event category, via the mapping setting.
*/
public function get_category() {
$current_category_mapping = \get_option( 'activitypub_event_extensions_event_category_mappings', array() );
$terms = \get_the_terms( $this->wp_object, $this->wp_taxonomy );
if ( ! is_wp_error( $terms ) && $terms ) {
return $current_category_mapping[ $terms[0]->slug ];
// Check if the event has a category set and if that category has a specific mapping return that one.
if ( ! is_wp_error( $terms ) && $terms && array_key_exists( $terms[0]->slug, $current_category_mapping ) ) {
return sanitize_text_field( $current_category_mapping[ $terms[0]->slug ] );
} else {
return \get_option( 'activitypub_event_extensions_default_event_category', 'MEETING' );
// Return the default event category.
return sanitize_text_field( \get_option( 'activitypub_event_extensions_default_event_category', 'MEETING' ) );
}
}

View file

@ -28,7 +28,7 @@ if ( ! defined( 'ABSPATH' ) ) {
class VS_Event extends Event_Transformer {
/**
* The target transformet ActivityPub Event object.
* The target transformer ActivityPub Event object.
*
* @var Event
*/
@ -44,7 +44,6 @@ class VS_Event extends Event_Transformer {
* @return string Widget name.
*/
public function get_transformer_name() {
return 'activitypub-event-transformers/vs-event';
}
@ -58,7 +57,6 @@ class VS_Event extends Event_Transformer {
* @return string Widget title.
*/
public function get_transformer_label() {
return 'VS Event';
}
@ -72,7 +70,6 @@ class VS_Event extends Event_Transformer {
* @return array Widget categories.
*/
public static function get_supported_post_types() {
return array( 'event' );
}
@ -84,7 +81,6 @@ class VS_Event extends Event_Transformer {
* @return string The Event Object-Type.
*/
protected function get_type() {
return 'Event';
}
@ -94,7 +90,6 @@ class VS_Event extends Event_Transformer {
* @return array The Place.
*/
public function get_location() {
$address = get_post_meta( $this->wp_object->ID, 'event-location', true );
$place = new Place();
$place->set_type( 'Place' );
@ -107,7 +102,6 @@ class VS_Event extends Event_Transformer {
* Get the end time from the events metadata.
*/
protected function get_end_time() {
$end_time = get_post_meta( $this->wp_object->ID, 'event-date', true );
return \gmdate( 'Y-m-d\TH:i:s\Z', $end_time );
}
@ -116,7 +110,6 @@ class VS_Event extends Event_Transformer {
* Get the end time from the events metadata.
*/
protected function get_start_time() {
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
return \gmdate( 'Y-m-d\TH:i:s\Z', $start_time );
}
@ -125,7 +118,6 @@ class VS_Event extends Event_Transformer {
* Get the event link from the events metadata.
*/
private function get_event_link() {
$event_link = get_post_meta( $this->wp_object->ID, 'event-link', true );
if ( $event_link ) {
return array(
@ -141,7 +133,6 @@ class VS_Event extends Event_Transformer {
* Overrides/extends the get_attachments function to also add the event Link.
*/
protected function get_attachment() {
$attachments = parent::get_attachment();
if ( count( $attachments ) ) {
$attachments[0]['type'] = 'Document';
@ -154,15 +145,6 @@ class VS_Event extends Event_Transformer {
return $attachments;
}
/**
* This function tries to map VS-Event categories to Mobilizon event categories.
*
* @return string $category
*/
protected function get_category() {
return 'MEETING';
}
/**
* Create a custom summary.
*

View file

@ -151,6 +151,8 @@ class Setup {
return;
}
add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_styles' ) );
add_action( 'admin_menu', array( Settings_Page::class, 'admin_menu' ) );
add_filter(
@ -160,6 +162,25 @@ class Setup {
add_filter( 'activitypub_transformer', array( $this, 'register_activitypub_event_transformer' ), 10, 3 );
}
/**
* Add the CSS for the admin pages.
*
* @param string $hook_suffix The suffix of the hook.
*/
public static function enqueue_styles( $hook_suffix ) {
if ( false !== strpos( $hook_suffix, 'activitypub-event-extensions' ) ) {
wp_enqueue_style(
'activitypub-event-extensions-admin-styles',
plugins_url(
'assets/css/activitypub-event-extensions-admin.css',
ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE
),
array(),
ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_VERSION
);
}
}
/**
* Fires the initialization of admin notices.
*/
@ -198,7 +219,7 @@ class Setup {
foreach ( $this->active_event_plugins as $event_plugin ) {
if ( $wp_object->post_type === $event_plugin['post_type'] ) {
$transformer_class = 'Activitypub_Event_Extensions\Activitypub\Transformer\\' . $event_plugin['transformer_class'];
return new $transformer_class( $wp_object );
return new $transformer_class( $wp_object, $event_plugin['taxonomy'] );
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* Template for ActivityPub Event Extensions settings pages.
* Template for ActivityPub Event Extensions settings page.
*
* This template is used to display and manage settings for the ActivityPub Event Extensions plugin.
*
@ -15,7 +15,7 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Activitypub\Activity\Extended_Object\Event;
if ( ! isset( $args ) ) {
if ( ! isset( $args ) || ! array_key_exists( 'event_terms', $args ) ) {
return;
}
@ -63,6 +63,13 @@ $selected_default_event_category = \get_option( 'activitypub_event_extensions_de
$current_category_mapping = \get_option( 'activitypub_event_extensions_event_category_mappings', array() );
?>
<div class="activitypub-settings-header">
<div class="activitypub-settings-title-section">
<h1><?php \esc_html_e( 'ActivityPub Event Extensions', 'activitypub-event-extensions' ); ?></h1>
</div>
</div>
<hr class="wp-header-end">
<div class="activitypub-settings activitypub-settings-page hide-if-no-js">
<form method="post" action="options.php">
<?php \settings_fields( 'activitypub-event-extensions' ); ?>