Batch34: The Events Calendar tools (guarded, net-new)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8t9GEyyLZbUQu26na1JQg
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch 34 — The Events Calendar tools. Net-new, GPL-2.0-or-later. See NOTICE.md.
|
||||
* Inert unless TEC (class Tribe__Events__Main) is active. Events = 'tribe_events', venues = 'tribe_venue'.
|
||||
*/
|
||||
|
||||
namespace AskTamMCP\Extensions;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class Batch34 {
|
||||
|
||||
public static function register($registry): void {
|
||||
if (!class_exists('Tribe__Events__Main')) return;
|
||||
|
||||
$def = function (string $name, string $desc, array $props, array $required, string $scope, string $method) {
|
||||
$schema = ['type' => 'object', 'properties' => $props ?: new \stdClass()];
|
||||
if ($required) $schema['required'] = $required;
|
||||
return ['name' => $name, 'description' => $desc, 'scope' => $scope,
|
||||
'handler' => 'AskTamMCP\\Extensions\\Batch34::' . $method, 'inputSchema' => $schema];
|
||||
};
|
||||
|
||||
$registry->register($def('tec_detect', 'Report whether The Events Calendar is active and its version.', [], [], 'read', 'detect'));
|
||||
$registry->register($def('tec_list_events', 'List events (id, title, start, end) ordered by start date.',
|
||||
['per_page' => ['type' => 'integer', 'default' => 30], 'upcoming_only' => ['type' => 'boolean', 'default' => false]], [], 'read', 'listEvents'));
|
||||
$registry->register($def('tec_get_event', 'Get one event: title, start, end, all-day flag, and venue id.',
|
||||
['event_id' => ['type' => 'integer']], ['event_id'], 'read', 'getEvent'));
|
||||
$registry->register($def('tec_list_venues', 'List event venues (id, title).',
|
||||
['per_page' => ['type' => 'integer', 'default' => 50]], [], 'read', 'listVenues'));
|
||||
}
|
||||
|
||||
public static function detect(array $args): array {
|
||||
$v = (class_exists('Tribe__Events__Main') && defined('Tribe__Events__Main::VERSION')) ? \Tribe__Events__Main::VERSION : null;
|
||||
return ['active' => class_exists('Tribe__Events__Main'), 'version' => $v];
|
||||
}
|
||||
|
||||
public static function listEvents(array $args): array {
|
||||
$per = (int) ($args['per_page'] ?? 30);
|
||||
$q = ['post_type' => 'tribe_events', 'post_status' => 'publish', 'numberposts' => $per,
|
||||
'orderby' => 'meta_value', 'meta_key' => '_EventStartDate', 'order' => 'ASC'];
|
||||
if (!empty($args['upcoming_only'])) {
|
||||
$q['meta_query'] = [['key' => '_EventEndDate', 'value' => current_time('mysql'), 'compare' => '>=', 'type' => 'DATETIME']];
|
||||
}
|
||||
$posts = get_posts($q);
|
||||
$out = [];
|
||||
foreach ($posts as $p) $out[] = ['id' => $p->ID, 'title' => $p->post_title,
|
||||
'start' => get_post_meta($p->ID, '_EventStartDate', true), 'end' => get_post_meta($p->ID, '_EventEndDate', true)];
|
||||
return ['count' => count($out), 'events' => $out];
|
||||
}
|
||||
|
||||
public static function getEvent(array $args): array {
|
||||
$id = (int) ($args['event_id'] ?? 0);
|
||||
$p = get_post($id);
|
||||
if (!$p || $p->post_type !== 'tribe_events') throw new \RuntimeException("Event not found: {$id}");
|
||||
return ['id' => $id, 'title' => $p->post_title,
|
||||
'start' => get_post_meta($id, '_EventStartDate', true), 'end' => get_post_meta($id, '_EventEndDate', true),
|
||||
'all_day' => get_post_meta($id, '_EventAllDay', true) === 'yes', 'venue_id' => (int) get_post_meta($id, '_EventVenueID', true)];
|
||||
}
|
||||
|
||||
public static function listVenues(array $args): array {
|
||||
$posts = get_posts(['post_type' => 'tribe_venue', 'post_status' => 'publish',
|
||||
'numberposts' => (int) ($args['per_page'] ?? 50), 'orderby' => 'title', 'order' => 'ASC']);
|
||||
$out = [];
|
||||
foreach ($posts as $p) $out[] = ['id' => $p->ID, 'title' => $p->post_title];
|
||||
return ['count' => count($out), 'venues' => $out];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user