The Events Calendar: add categories to ActivityStreams tag (#37)
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 36s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 56s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 55s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 54s

Reviewed-on: Event-Federation/wordpress-activitypub-event-extensions#37
Co-authored-by: André Menrath <andre.menrath@posteo.de>
Co-committed-by: André Menrath <andre.menrath@posteo.de>
This commit is contained in:
André Menrath 2024-09-27 23:20:30 +02:00 committed by André Menrath
parent 7ab51b104e
commit 19457a9f19
2 changed files with 27 additions and 21 deletions

View file

@ -13,7 +13,7 @@
* *
* Requires at least ActivityPub plugin with version >= 3.2.2. ActivityPub plugin tested up to: 3.2.2. * Requires at least ActivityPub plugin with version >= 3.2.2. ActivityPub plugin tested up to: 3.2.2.
* *
* @package activitypub-event-extensions * @package Activitypub_Event_Extensions
* @license AGPL-3.0-or-later * @license AGPL-3.0-or-later
*/ */

View file

@ -12,12 +12,14 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly. exit; // Exit if accessed directly.
} }
use Activitypub_Event_Extensions\Activitypub\Transformer\Event;
use Activitypub\Activity\Extended_Object\Place;
use Activitypub\Activity\Extended_Object\Event as Event_Object;
use WP_Error;
use WP_Post; use WP_Post;
use Activitypub\Activity\Extended_Object\Event as Event_Object;
use Activitypub\Activity\Extended_Object\Place;
use Activitypub_Event_Extensions\Activitypub\Transformer\Event;
use function Activitypub\esc_hashtag;
/** /**
* ActivityPub Tribe Transformer * ActivityPub Tribe Transformer
* *
@ -47,24 +49,33 @@ final class The_Events_Calendar extends Event {
} }
/** /**
* Get tribe category of wp_post * Get the tags, including also the set categories from The Events Calendar.
* *
* @return string|null tribe category if it exists * @return ?array The array if tags,
*/ */
public function get_tribe_category() { public function get_tag(): ?array {
$categories = tribe_get_event_cat_slugs( $this->wp_object->ID ); $tags = array();
$category_ids = tribe_get_event_cat_ids();
if ( count( $categories ) === 0 ) { if ( $category_ids ) {
return null; foreach ( $category_ids as $category_id ) {
$term = \get_term( $category_id );
$tag = array(
'type' => 'Hashtag',
'href' => \esc_url( \get_term_link( $term ) ),
'name' => esc_hashtag( $term->name ),
);
$tags[] = $tag;
}
} }
$tags[] = parent::get_tag();
return $categories[0]; return $tags;
} }
/** /**
* Get the end time from the event object. * Get the end time from the event object.
*/ */
protected function get_end_time() { protected function get_end_time(): string {
$date = date_create( $this->tribe_event->end_date, wp_timezone() ); $date = date_create( $this->tribe_event->end_date, wp_timezone() );
return \gmdate( 'Y-m-d\TH:i:s\Z', $date->getTimestamp() ); return \gmdate( 'Y-m-d\TH:i:s\Z', $date->getTimestamp() );
} }
@ -83,20 +94,16 @@ final class The_Events_Calendar extends Event {
* @return string status of the event * @return string status of the event
*/ */
public function get_tribe_status() { public function get_tribe_status() {
if ( 'canceled' === $this->tribe_event->event_status ) { if ( 'canceled' === $this->tribe_event->event_status ) {
return 'CANCELLED'; return 'CANCELLED';
} }
if ( 'postponed' === $this->tribe_event->event_status ) { if ( 'postponed' === $this->tribe_event->event_status ) {
return 'CANCELLED'; // This will be reflected in the cancelled reason. return 'CANCELLED'; // This will be reflected in the cancelled reason.
} }
if ( '' === $this->tribe_event->event_status ) { return 'CONFIRMED';
return 'CONFIRMED';
}
return new WP_Error( 'invalid event_status value', __( 'invalid event_status', 'activitypub' ), array( 'status' => 404 ) );
} }
/** /**
* Check if the comments are enabled for the current event. * Check if the comments are enabled for the current event.
*/ */
@ -119,7 +126,6 @@ final class The_Events_Calendar extends Event {
* @return string The content. * @return string The content.
*/ */
protected function get_content() { protected function get_content() {
$content = parent::get_content(); $content = parent::get_content();
// /BeforeFirstRelease: // /BeforeFirstRelease:
// * remove link at the end of the content. // * remove link at the end of the content.