Compare commits

...

56 commits

Author SHA1 Message Date
0fba291706 fix readme
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 37s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m8s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 1m1s
2024-10-03 20:38:28 +02:00
8168df2965 remove duplicated definition of event category strings (#51)
Some checks failed
PHPUnit / PHPUnit – PHP 8.3 (push) Waiting to run
PHP Code Checker / PHP Code Checker (push) Successful in 39s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.2 (push) Has been cancelled
Reviewed-on: #51
2024-10-03 20:35:46 +02:00
8e56eb66c0 remove duplicated definition of event category strings
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 55s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m10s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m9s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m4s
2024-10-03 19:59:31 +02:00
4cc992d79b Remove actions needed for local https development
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 47s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m12s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 1m0s
moved to external plugin: https://code.event-federation.eu/Event-Federation/wordpress-localhost-https-development
2024-10-03 15:30:00 +02:00
17648dc664 improve documentation how to add new event plugin and write a new transformer
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 38s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 1m0s
2024-10-02 22:40:41 +02:00
a8627cdb02 set default status in the transformer 2024-10-02 22:40:12 +02:00
4aad867d1f Rename plugin to ActivityPub Event Bridge (#47)
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 40s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m12s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 1m0s
See the results of the poll: https://graz.social/@linos/113214893071983918

Reviewed-on: #47
Co-authored-by: André Menrath <andre.menrath@posteo.de>
Co-committed-by: André Menrath <andre.menrath@posteo.de>
2024-10-02 21:54:03 +02:00
2124b1f612 Set timezone and status for The Events Calendar (#46)
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 42s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m8s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 1m2s
Reviewed-on: Event-Federation/wordpress-activitypub-event-extensions#46
2024-10-02 19:53:13 +02:00
ced5ee90b1 set timezone and status for tribe
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 43s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m8s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m5s
2024-10-02 19:50:41 +02:00
972fcbb2db Improve the design of the Base Event Transformer (#44)
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 44s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 1m2s
Co-authored-by: André Menrath <andre.menrath@posteo.de>
Reviewed-on: Event-Federation/wordpress-activitypub-event-extensions#44
Reviewed-by: André Menrath <andre.menrath@event-federation.eu>
Co-authored-by: ruru4143 <ruru@event-federation.eu>
Co-committed-by: ruru4143 <ruru@event-federation.eu>
2024-10-02 19:15:28 +02:00
2257e86f0f Merge branch 'format_summary'
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 35s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 59s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 56s
2024-09-28 16:38:29 +02:00
11bf3a2048 add node_modules to gitignore
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 36s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m5s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 59s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 1m0s
2024-09-28 16:18:00 +02:00
6f744b9e14 Cleanup top of PHP files (#40)
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 32s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 57s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 58s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 1m5s
- sorting use statements
- always check for `ABSPATH` after namespace

Reviewed-on: Event-Federation/wordpress-activitypub-event-extensions#40
Co-authored-by: André Menrath <andre.menrath@posteo.de>
Co-committed-by: André Menrath <andre.menrath@posteo.de>
2024-09-28 13:14:10 +02:00
c599384006 improve readme text
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 33s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 58s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 54s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 57s
2024-09-28 11:51:43 +02:00
f92c5853ad First draft of a proper Readme (targeting WordPress.org) (#39)
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 33s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 56s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m0s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 56s
Reviewed-on: Event-Federation/wordpress-activitypub-event-extensions#39
Co-authored-by: André Menrath <andre.menrath@posteo.de>
Co-committed-by: André Menrath <andre.menrath@posteo.de>
2024-09-28 11:45:47 +02:00
19457a9f19 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>
2024-09-27 23:20:30 +02:00
7ab51b104e Fix location for tribe (#36)
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 35s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 59s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m0s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 57s
Updates did not work. Always use the tribe_event instead of the wp_object where ever possible!

Reviewed-on: Event-Federation/wordpress-activitypub-event-extensions#36
Co-authored-by: André Menrath <andre.menrath@posteo.de>
Co-committed-by: André Menrath <andre.menrath@posteo.de>
2024-09-27 18:04:29 +02:00
3dbd3e21ee phpdocs, phpcs
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 39s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m10s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m9s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m4s
2024-09-26 15:51:23 +02:00
20f0ea2823 add filter to never include permalink in summary
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 48s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m10s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m17s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m4s
2024-09-26 15:44:22 +02:00
c13230ac6f fix more function return types in transformers
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 33s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 57s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 52s
2024-09-25 14:30:37 +02:00
4d4328f3fd add missing phpdoc
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Successful in 34s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Failing after 57s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Failing after 58s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Failing after 50s
2024-09-25 14:25:27 +02:00
35bd198f47 fix return types of transformer functions
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 36s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Has been cancelled
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Has been cancelled
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Has been cancelled
2024-09-25 14:24:30 +02:00
ac99300949 wip draft of composed human readable summary using vs events list
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 36s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Failing after 55s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Failing after 53s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Failing after 50s
2024-09-25 13:59:31 +02:00
e8574d26ac Run integration tests and improve transformers for all integrations (#32)
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 33s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 56s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m0s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 57s
Reviewed-on: Event-Federation/wordpress-activitypub-event-extensions#32
Co-authored-by: André Menrath <andre.menrath@posteo.de>
Co-committed-by: André Menrath <andre.menrath@posteo.de>
2024-09-25 11:27:17 +02:00
1764a7b03f add tests for venue and join mode is always external
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 43s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m10s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 58s
2024-09-24 17:16:52 +02:00
893f1d3b7c Add integration tests for The Events Calendar (#31)
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 40s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m1s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 52s
Reviewed-on: Event-Federation/wordpress-activitypub-event-extensions#31
Co-authored-by: André Menrath <andre.menrath@posteo.de>
Co-committed-by: André Menrath <andre.menrath@posteo.de>
2024-09-24 16:24:31 +02:00
68b7963fe6 fix composer phpunit to make it work with autoloader
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 47s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 1m8s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 59s
2024-09-23 16:21:12 +02:00
2b22013e08 Enhance docs
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 34s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 56s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 59s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 51s
2024-09-21 15:04:06 +02:00
6edc402581 fix docker compose file for running unit tests locally
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 33s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m1s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 56s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 56s
2024-09-21 14:59:26 +02:00
c495e65105 cleanup repo
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 40s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 1m0s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 58s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 55s
2024-09-21 14:15:16 +02:00
712e56c87e Improve Actions (#27)
All checks were successful
PHP Code Checker / PHP Code Checker (push) Successful in 34s
PHPUnit / PHPUnit – PHP 8.1 (push) Successful in 58s
PHPUnit / PHPUnit – PHP 8.2 (push) Successful in 57s
PHPUnit / PHPUnit – PHP 8.3 (push) Successful in 54s
Try to make caching in Forgejo Actions work.

Reviewed-on: Event-Federation/wordpress-activitypub-event-extensions#27
Co-authored-by: André Menrath <andre.menrath@posteo.de>
Co-committed-by: André Menrath <andre.menrath@posteo.de>
2024-09-21 14:06:11 +02:00
575aff68b0 some cleanup
All checks were successful
PHP Code Checker / Run PHP Code Checker (push) Successful in 40s
Unit Testing / Run phpunit tests (push) Successful in 3m53s
2024-09-21 11:17:11 +02:00
f77f4bc017 add forgejo actions for phpunit and phpcs
All checks were successful
PHP Code Checker / Run PHP Code Checker (push) Successful in 42s
Unit Testing / Run phpunit tests (push) Successful in 3m55s
2024-09-21 11:00:33 +02:00
fb544206f9 test
Some checks failed
/ test (push) Successful in 1s
Unit Testing / phpunit (push) Failing after 0s
2024-09-20 19:18:11 +02:00
640304ba23 add phpunit test
Some checks failed
/ test (push) Successful in 1s
Unit Testing / phpunit (push) Failing after 9s
2024-09-20 19:15:55 +02:00
1445964e03 test action
All checks were successful
/ test (push) Successful in 1s
2024-09-20 19:10:01 +02:00
639a64f464 add demo action
Some checks failed
/ test (push) Has been cancelled
2024-09-20 18:55:11 +02:00
c8fc78ccdd small function name improvements 2024-09-18 21:26:53 +02:00
4e2c1fb23a add checks for minimum version of the activitypub plugin 2024-09-11 13:55:37 +02:00
0b3974b255 fix base event transformer for activitypub 3.2+ 2024-09-11 13:50:57 +02:00
1f2bf14860 code beautify and some better docs 2024-09-11 08:00:38 +02:00
126327288f Merge pull request 'Refactoring: each event plugin is now represented by the implementation of a Event_Plugin base class.' (#24) from class_plugin_adapter into main
Reviewed-on: Event-Federation/wordpress-activitypub-event-extensions#24
2024-09-11 00:42:43 +02:00
ea7570d362 improve plugin-file meta 2024-09-11 00:41:37 +02:00
457f433ed9 refactoring: each event plugin now is represented as a class with static functions 2024-09-11 00:38:21 +02:00
b2076951b5 wip 2024-09-10 18:48:54 +02:00
df04913ba1 fix event category mapping when so categories are present 2024-09-10 18:48:02 +02:00
ef858c91e0 refactoring setup class 2024-09-10 18:44:07 +02:00
69d2458ea8 only add css with our domain prefix 2024-09-02 14:39:47 +02:00
871959c8c9 cleanup unused code 2024-09-02 14:39:37 +02:00
04dad65bfa refactoring the settings sanitation 2024-09-02 14:32:02 +02:00
812cbca546 remove experiment with chaining in the generic setter from the VSEL transformer 2024-09-02 14:02:18 +02:00
ebc8bd4b37 small fixes 2024-08-28 21:15:26 +02:00
16aa012be0 Merge branch 'setting_mapping' 2024-08-28 20:01:43 +02:00
bdd4c616ea fix readme 2024-08-27 21:14:25 +02:00
6191dafe5b some cleanup and code linting 2024-08-27 21:13:37 +02:00
0999db945b linting 2024-08-01 20:08:35 +02:00
42 changed files with 3128 additions and 1083 deletions

50
.forgejo/workflows/phpcs.yml Executable file
View file

@ -0,0 +1,50 @@
name: PHP Code Checker
on:
push:
branches:
- main
pull_request:
jobs:
phpcs:
runs-on: ubuntu-latest
services:
mysql:
image: mariadb
env:
MYSQL_ROOT_PASSWORD: root
strategy:
matrix:
php-versions: ['8.1']
name: PHP Code Checker
env:
extensions: mysql
key: cache-v1
steps:
- name: Checkout
uses: https://code.forgejo.org/actions/checkout@v4
- name: Cache Composer
id: cache-composer
uses: https://code.forgejo.org/actions/cache@v4
with:
path: |
./vendor/
key: cache-composer-phpcs-1
- name: Setup PHP
uses: https://github.com/shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none
tools: composer
env:
runner: self-hosted
- name: Install Composer dependencies for PHP
if: steps.cache-composer.outputs.cache-hit != 'true'
uses: ramsey/composer-install@v3
- name: Run PHP_CodeSniffer
run: ./vendor/bin/phpcs

View file

@ -0,0 +1,95 @@
name: PHPUnit
on:
push:
branches:
- main
- improve_tests
pull_request:
env:
WP_TESTS_DIR: /workspace/wordpress-test-lib
WP_CORE_DIR: /workspace/wordpress
jobs:
phpunit:
runs-on: ubuntu-latest
services:
mysql:
image: mariadb
env:
MYSQL_ROOT_PASSWORD: root
strategy:
matrix:
php-version: ['8.1', '8.2', '8.3']
name: PHPUnit PHP ${{ matrix.php-version }}
env:
extensions: mysql
key: cache-v1
steps:
- name: Checkout
uses: https://code.forgejo.org/actions/checkout@v4
- name: Cache WordPress Setup
id: cache-wordpress
uses: https://code.forgejo.org/actions/cache@v4
with:
path: |
${{ env.WP_CORE_DIR }}
${{ env.WP_TESTS_DIR }}
key: cache-wordpress-4
- name: Cache Composer
id: cache-composer-phpunit
uses: https://code.forgejo.org/actions/cache@v4
with:
path: |
./vendor/
key: cache-composer-phpunit-1
- name: Setup PHP
uses: https://github.com/shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: none
tools: composer
env:
runner: self-hosted
- name: Install PHPUnit and PHPUnit-Polyfills
if: steps.cache-composer-phpunit.outputs.cache-hit != 'true'
run: composer require --dev yoast/phpunit-polyfills:"^3.0"
- name: Install and cache mysqladmin needed to initialize the test database
uses: https://github.com/awalsh128/cache-apt-pkgs-action@latest
with:
packages: mysql-client
version: 1.0
- name: Setup Test Environment
if: steps.cache-wordpress.outputs.cache-hit != 'true'
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 6.6 false false false false
- name: Initialize WordPress test database
if: steps.cache-wordpress.outputs.cache-hit != 'false'
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 6.6 false true true true
- name: Run Integration tests for The Events Calendar
run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=the_events_calendar
env:
PHP_VERSION: ${{ matrix.php-version }}
- name: Run Integration tests for VS Event List
run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=vs_event_list
env:
PHP_VERSION: ${{ matrix.php-version }}
- name: Run Integration tests for GatherPress
run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=gatherpress
env:
PHP_VERSION: ${{ matrix.php-version }}
- name: Run Integration tests for Events Manager
run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=events_manager
env:
PHP_VERSION: ${{ matrix.php-version }}

4
.gitignore vendored
View file

@ -1,2 +1,4 @@
vendor
vendor/
composer.lock
.phpunit.result.cache
node_modules/

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

43
Dockerfile Normal file
View file

@ -0,0 +1,43 @@
FROM php:8.1.29-alpine
RUN mkdir /app
WORKDIR /app
# Install Git, NPM & needed libraries
RUN apk update \
&& apk add bash git nodejs npm gettext subversion mysql mysql-client zip \
&& rm -f /var/cache/apk/*
RUN docker-php-ext-install mysqli
# Install Xdebug
RUN apk add --no-cache $PHPIZE_DEPS \
&& apk add --update linux-headers \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& apk del --purge $PHPIZE_DEPS \
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.idekey=VSCODE" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# Install Composer
RUN EXPECTED_CHECKSUM=$(curl -s https://composer.github.io/installer.sig) \
&& curl https://getcomposer.org/installer -o composer-setup.php \
&& ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" \
&& if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then >&2 echo 'ERROR: Invalid installer checksum'; rm composer-setup.php; exit 1; fi \
&& php composer-setup.php --quiet \
&& php -r "unlink('composer-setup.php');" \
&& mv composer.phar /usr/local/bin/composer
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \
chmod +x wp-cli.phar && \
mv wp-cli.phar /usr/local/bin/wp
COPY composer.json composer.lock /app/
RUN composer install --no-scripts --no-autoloader
RUN composer global require yoast/phpunit-polyfills:"^3.0" --dev
ENV PATH="/root/.composer/vendor/bin:${PATH}"
RUN chmod +x -R ./

View file

@ -1,26 +1,92 @@
This is a WordPress plugin improves the Fediverse integration of Events via the [WordPress ActivityPub plugin](https://wordpress.org/plugins/activitypub/).
# ActivityPub Event Bridge
> **_NOTE:_** This is still pre-alpha. It is not more than a skeleton/playground. Things change rapidly. Please contact us, instead of trying it out yourself at this time.
Contributors: andremenrath
Tags: events, fediverse, activitypub, calendar
Requires at least: 6.5
Tested up to: 6.6
Stable tag: 0.1.0
Requires PHP: 8.1
License: AGPL-3.0-or-later
License URI: https://www.gnu.org/licenses/agpl-3.0.html
For more information checkout our website https://event-federation.eu/. You can follow updates via [RSS](https://event-federation.eu/feed/) or ActivityPub: [@blog@event-federation.eu](https://event-federation.eu/blog/).
Integrating popular event plugins with the ActivityPub plugin.
## Goals
* Proper ActivityPub (JSON-LD) representation of events within WordPress
* Improving the setup and configuration workflow of ActivityPub
* Researching/Implementing federated RSVP/attendee management
![](.wordpress-org/banner-1544x500.jpg)
## Supported Event Plugins
## Description
### Events plugin that will be supported at first:
Make your events more discoverable, expand your reach effortlessly while being independent of other (commercial) platforms, and be a part of the growing decentralized web (the Fediverse).
With the ActivityPub Event Bridge plugin for WordPress, your events can be automatically followed, aggregated and displayed across decentralized platforms like [Mastodon](https://joinmastodon.org) or [Gancio](https://gancio.org), without any extra work.
Forget the hassle of managing multiple social media accounts just to keep your audience informed.
This plugin is not an event managing plugin but an add-on to popular event plugins. It extends their functionality to fully support the [ActivityPub plugin](https://wordpress.org/plugins/activitypub/).
With the ActivityPub plugin people can follow your website directly and engage with your events just as they would on social media: liking, boosting and even commenting if you enable it.
You retain full ownership of your content. By integrating into your existing setup, it ensures no extra work is needed while enhancing your events' visibility across the web.
### How It Works
With the ActivityPub Event Bridge WordPress plugin, sharing your events is effortless and automatic!
Once you create an event on your WordPress site, it is seamlessly shared across the decentralized web using the ActivityPub protocol.
<p align="center">
<img src="./.wordpress-org/event-activitypub-publishing.gif" alt="Logo" width="250" />
</p>
Your events can be automatically delivered to platforms that fully support events, such as [Mobilizon](https://joinmobilizon.org/), [Gancio](https://gancio.org), [Friendica](https://friendi.ca), [Hubzilla](https://hubzilla.org), and [Pleroma](https://pleroma.social/).
These platforms create public event calendars by pulling in events from various sources, including your website. Any updates you make to your events are synced across these platforms—so you only need to manage your events on your own site, with no extra work required.
<p align="center">
<img src="./.wordpress-org/decentralized-event-calenders.gif" alt="Logo" width="250" />
</p>
Even platforms that dont yet fully support events, like [Mastodon](https://joinmastodon.org), will still receive a detailed, well-composed summary of your event.
The Event Federation plugin ensures that users from those platforms are provided with all important information about an event.
## Installation
This plugin depends on the [ActivityPub plugin](https://wordpress.org/plugins/activitypub/). Additionally, you need to use one of the supported event plugins. See below.
### Supported Event plugins
* [The Events Calendar](https://de.wordpress.org/plugins/the-events-calendar/)
* [VS Event List](https://de.wordpress.org/plugins/very-simple-event-list/)
* [Events Manager](https://de.wordpress.org/plugins/events-manager/)
* [GatherPress](https://github.com/GatherPress/gatherpress)
### Later:
- [All in One Events Calendar](https://de.wordpress.org/plugins/all-in-one-event-calendar/)
- TBA
## Configuration
### Your event plugin:
- [**Contact us**](https://event-federation.eu/contact/), if you want to see your event plugin on the list.
If youre new to the [ActivityPub plugin](https://wordpress.org/plugins/activitypub/), its recommended to spend a few minutes reading through its documentation to familiarize yourself with its setup and functionality.
## Frequently Asked Questions
### Do I need to install another event plugin to use the Event Federation plugin?
Yes, this plugin works as an add-on and requires both the ActivityPub plugin and a supported event plugin such as The Events Calendar, VS Event List, or Events Manager to manage your events. It just fills the missing gap between event plugins and the [ActivityPub plugin](https://wordpress.org/plugins/activitypub/).
### What platforms can follow my events?
Your events can be followed on platforms that support ActivityPub like [Mobilizon](https://joinmobilizon.org/), [Gancio](https://gancio.org), [Friendica](https://friendi.ca), [Hubzilla](https://hubzilla.org), and [Pleroma](https://pleroma.social/). Even other applications like [Mastodon](https://joinmastodon.org), which dont fully support events yet, will display all important information about the events.
### How much extra work is required to maintain my events across the decentralized Web?
None! Once the plugin is set up, your events are automatically sent to all connected platforms or account that follow you (your Website). Any updates you make to your events are synced without additional effort.
### Can I still use social media to promote my events?
Yes, you can still use traditional social media if you wish. However, this plugin helps reduce reliance on commercial platforms by connecting your events to the decentralized Fediverse.
### Will this plugin work if I don't use the ActivityPub plugin?
No, the Event Federation plugin depends on the ActivityPub plugin to deliver your events across decentralized platforms, so it's essential to have it installed and configured.
### My event plugin is not supported, what can I do?
If you know about coding have a look at the documentation of how to add your plugin or open an [issue](https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-bridge/issues), if we can spare some free hours we might add it.
### What if I experience problems?
We're always interested in your feedback. Feel free to reach out to us via [E-Mail](https://event-federation.eu/contact/) or create an [issue](https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-bridge/issues).
## Changelog
### [0.1.0] 2024-10-01
* Initial alpha release on WordPress.org

View file

@ -0,0 +1,36 @@
<?php
/**
* Plugin Name: ActivityPub Event Bridge
* Description: Integrating popular event plugins with the ActivityPub plugin.
* Plugin URI: https://event-federation.eu/
* Version: 0.1.0
* Author: André Menrath
* Author URI: https://graz.social/@linos
* Text Domain: activitypub-event-bridge
* License: AGPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/agpl-3.0.de.html
* Requires PHP: 8.1
*
* Requires at least ActivityPub plugin with version >= 3.2.2. ActivityPub plugin tested up to: 3.2.2.
*
* @package ActivityPub_Event_Bridge
* @license AGPL-3.0-or-later
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
define( 'ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
define( 'ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) );
define( 'ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_VERSION', current( get_file_data( __FILE__, array( 'Version' ), 'plugin' ) ) );
define( 'ACTIVITYPUB_EVENT_BRIDGE_DOMAIN', 'activitypub-event-bridge' );
define( 'ACTIVITYPUB_EVENT_BRIDGE_ACTIVITYPUB_PLUGIN_MIN_VERSION', '3.2.2' );
// Include and register the autoloader class for automatic loading of plugin classes.
require_once ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . '/includes/class-autoloader.php';
ActivityPub_Event_Bridge\Autoloader::register();
// Initialize the plugin.
ActivityPub_Event_Bridge\Setup::get_instance();

View file

@ -1,74 +0,0 @@
<?php
/**
* Plugin Name: ActivityPub Event Extensions
* Description: Custom ActivityPub Transformers and Integrations for common Event Plugins.
* Plugin URI: https://event-federation.eu/
* Version: 0.1.0
* Author: André Menrath
* Author URI: https://graz.social/@linos
* Text Domain: activitypub-event-extensions
* License: AGPL-3.0-or-later
*
* ActivityPub tested up to: 2.4.0
*
* @package activitypub-event-extensions
* @license AGPL-3.0-or-later
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
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';
Activitypub_Event_Extensions\Autoloader::register();
// Initialize the plugin.
Activitypub_Event_Extensions\Setup::get_instance();
// For local development purposes: TODO. Remove everything after here.
/**
* Add a filter for http_request_host_is_external
*
* TODO: Remove this for release.
*
* @todo This filter is temporary code needed to do local testing.
*/
add_filter( 'http_request_host_is_external', 'custom_http_request_host_is_external', 10, 3 );
/**
* Add a filter for http_request_host_is_external
*
* TODO: Remove this for release.
*
* @todo This filter is temporary code needed to do local testing.
*/
function custom_http_request_host_is_external( $is_external, $host, $url ) {
$is_external = true;
return $is_external;
}
/**
* Don't verify ssl certs for testing.
*
* TODO: Remove this for release.
*
* @todo This filter is temporary code needed to do local testing.
*/
add_filter( 'https_ssl_verify', 'dont_verify_local_dev_https', 10, 3 );
function dont_verify_local_dev_https( $url ) {
return false;
}

View file

@ -1,4 +1,4 @@
.activitypub-settings-page .box {
.activitypub-event-bridge-settings-page .box {
border: 1px solid #c3c4c7;
background-color: #fff;
padding: 1em 1.5em;

246
bin/install-wp-tests.sh Executable file
View file

@ -0,0 +1,246 @@
#!/usr/bin/env bash
if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation] [skip-wp-install] [skip-plugins] [skip-test-suite]"
exit 1
fi
DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
SKIP_DB_CREATE=${6-false}
SKIP_WP_INSTALL=${7-false}
SKIP_PLUGINS_INSTALL=${8-false}
SKIP_TEST_SUITE_INSTALL=${9-false}
# Initialize the plugin list
PLUGINS=""
# Parse optional --plugins argument
while [[ "$#" -gt 0 ]]; do
case $1 in
--plugins) PLUGINS="$2"; shift ;;
esac
shift
done
TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress}
download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}
if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
WP_BRANCH=${WP_VERSION%\-*}
WP_TESTS_TAG="branches/$WP_BRANCH"
elif [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
WP_TESTS_TAG="branches/$WP_VERSION"
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
WP_TESTS_TAG="tags/${WP_VERSION%??}"
else
WP_TESTS_TAG="tags/$WP_VERSION"
fi
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
WP_TESTS_TAG="trunk"
else
# http serves a single offer, whereas https serves multiple. we only want one
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
if [[ -z "$LATEST_VERSION" ]]; then
echo "Latest WordPress version could not be found"
exit 1
fi
WP_TESTS_TAG="tags/$LATEST_VERSION"
fi
set -ex
install_wp() {
if [ "$SKIP_WP_INSTALL" = "true" ]; then
echo "Skipping WordPress installation."
return 0
fi
if [ -d $WP_CORE_DIR ]; then
return;
fi
mkdir -p $WP_CORE_DIR
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p $TMPDIR/wordpress-trunk
rm -rf $TMPDIR/wordpress-trunk/*
svn export --quiet https://core.svn.wordpress.org/trunk $TMPDIR/wordpress-trunk/wordpress
mv $TMPDIR/wordpress-trunk/wordpress/* $WP_CORE_DIR
else
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then
# https serves multiple offers, whereas http serves single.
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
LATEST_VERSION=${WP_VERSION%??}
else
# otherwise, scan the releases and get the most up to date minor version of the major release
local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
fi
if [[ -z "$LATEST_VERSION" ]]; then
local ARCHIVE_NAME="wordpress-$WP_VERSION"
else
local ARCHIVE_NAME="wordpress-$LATEST_VERSION"
fi
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
fi
download https://raw.githubusercontent.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}
install_test_suite() {
if [ "$SKIP_TEST_SUITE_INSTALL" = "true" ]; then
echo "Skipping test suite installation."
return 0
fi
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i.bak'
else
local ioption='-i'
fi
# set up testing suite if it doesn't yet exist
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
rm -rf $WP_TESTS_DIR/{includes,data}
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
fi
if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s:__DIR__ . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
fi
}
recreate_db() {
shopt -s nocasematch
if [[ $1 =~ ^(y|yes)$ ]]
then
mysqladmin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA
create_db
echo "Recreated the database ($DB_NAME)."
else
echo "Leaving the existing database ($DB_NAME) in place."
fi
shopt -u nocasematch
}
create_db() {
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}
install_db() {
if [ ${SKIP_DB_CREATE} = "true" ]; then
return 0
fi
# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""
if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi
# create database
if [ $(mysql --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ]
then
echo "Reinstalling will delete the existing test database ($DB_NAME)"
recreate_db yes
else
create_db
fi
}
install_wp_plugin() {
PLUGIN_NAME=$1
mkdir -p "$WP_CORE_DIR/wp-content/plugins/"
if [ -d "$WP_CORE_DIR/wp-content/plugins/$PLUGIN_NAME" ]; then
return;
fi
# Get the latest tag.
LATEST_TAG=$(svn log https://plugins.svn.wordpress.org/$PLUGIN_NAME/tags --limit 1 | awk 'NR == 4 { print $4 }')
if [ -n "$LATEST_TAG" ]; then
PLUGIN_FILE="$PLUGIN_NAME.$LATEST_TAG.zip"
else
PLUGIN_FILE="$PLUGIN_NAME.zip"
fi
URL="https://downloads.wordpress.org/plugin/$PLUGIN_FILE"
# Check if the plugin file already exists
if ! test -f "$TMPDIR/$PLUGIN_FILE"; then
download $URL "$TMPDIR/$PLUGIN_FILE"
fi
# Unzip the plugin into the WordPress must-use plugins directory
unzip -q -o "$TMPDIR/$PLUGIN_FILE" -d "$WP_CORE_DIR/wp-content/plugins/"
}
install_wp_plugins() {
if [ "$SKIP_PLUGINS_INSTALL" = "true" ]; then
echo "Skipping WordPress plugin installation."
return 0
fi
# Install the one and only ActivityPub plugin (greetings @pfefferle).
install_wp_plugin activitypub
# Install (not-activate) all supported event plugins.
install_wp_plugin the-events-calendar
install_wp_plugin very-simple-event-list
install_wp_plugin gatherpress
install_wp_plugin events-manager
}
install_wp
install_wp_plugins
install_test_suite
install_db

View file

@ -1,18 +1,22 @@
{
"name": "menrath/wordpress-activitypub-event-extensions",
"description": "The ActivityPub Event Extensions help for event custom post types to federate properly.",
"name": "menrath/wordpress-activitypub-event-bridge",
"description": "The ActivityPub Event Bridge help for event custom post types to federate properly.",
"type": "wordpress-plugin",
"require": {
"php": ">=5.6.0",
"composer/installers": "^1.0 || ^2.0"
"php": ">=8.1.0",
"composer/installers": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^8",
"phpcompatibility/php-compatibility": "*",
"phpcompatibility/phpcompatibility-wp": "*",
"squizlabs/php_codesniffer": "3.*",
"wp-coding-standards/wpcs": "dev-develop",
"yoast/phpunit-polyfills": "^3.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"sirbrillig/phpcs-variable-analysis": "^2.11"
"sirbrillig/phpcs-variable-analysis": "^2.11",
"phpcsstandards/phpcsextra": "^1.1.0",
"dms/phpunit-arraysubset-asserts": "^0.5.0"
},
"config": {
"allow-plugins": true
@ -28,14 +32,33 @@
}
],
"extra": {
"installer-name": "activitypub-event-extensions"
"installer-name": "activitypub-event-bridge"
},
"scripts": {
"lint": [
"vendor/bin/phpcs -n -q"
"vendor/bin/phpcs"
],
"lint:fix": [
"vendor/bin/phpcbf"
]
],
"prepare-test": [
"composer install",
"bin/install-wp-tests.sh wordpress-test root wordpress-test test-db latest true"
],
"test": [
"@prepare-test",
"@test-vs-event-list",
"@test-the-events-calendar",
"@test-gatherpress",
"@test-events-manager"
],
"test-debug": [
"@prepare-test",
"@test-gatherpress"
],
"test-vs-event-list": "phpunit --filter=vs_event_list",
"test-the-events-calendar": "phpunit --filter=the_events_calendar",
"test-gatherpress": "phpunit --filter=gatherpress",
"test-events-manager": "phpunit --filter=events_manager"
}
}

47
docker-compose.yml Normal file
View file

@ -0,0 +1,47 @@
version: '3'
# This files purpose is to run the PHPunit tests locally.
# Install docker and docker compose and than just run:
# docker compose up
# To live debug in VSCode add this launch configuration to your .vscode/launch.json.
# It assumes that the WordPress root-dir is your workspace root.
#
# {
# "name": "Listen for PHPUnit",
# "type": "php",
# "request": "launch",
# "port": 9003,
# "pathMappings": {
# "/app/": "${workspaceRoot}/wp-content/plugins/activitypub-event-bridge/",
# "/tmp/wordpress/": "${workspaceRoot}/"
# },
# },
services:
test-db:
image: mariadb
environment:
MARIADB_DATABASE: wordpress-test
MARIADB_ROOT_PASSWORD: wordpress-test
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
start_period: 2s
interval: 1s
timeout: 5s
retries: 10
test-php:
build:
context: .
dockerfile: Dockerfile
depends_on:
test-db:
condition: service_healthy
links:
- test-db
volumes:
- .:/app
command: ["composer", "run-script", "test-debug"]
extra_hosts:
- "host.docker.internal:host-gateway"

View file

@ -10,34 +10,48 @@ To make the WordPress ActivityPub plugin use a custom transformer simply add a f
## Add your event plugin
First you need to add some basic information about your event plugin in the constant `SUPPORTED_EVENT_PLUGIN` in the file `includes/class-setup.php`:
First you need to add some basic information about your event plugin. Just create a new file in `./includes/plugins/my-event-plugin.php`. Implement at least all abstract functions of the `Event_Plugin` class.
```php
// Example from the Events Manager plugin.
'events_manager' => array( // Choose any key you like.
'plugin_file' => 'events-manager/events-manager.php',
'post_type' => 'event',
'settings_page' => 'options-general.php?page=vsel',
'transformer_class' => 'Events_Manager', // Points to the class in the file `includes/activitypub/transformer/class-events-manager.php`.
),
namespace ActivityPub_Event_Bridge\Plugins;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
/**
* Integration information for My Event Plugin
*
* This class defines necessary meta information is for the integration of My Event Plugin with the ActivityPub plugin.
*
* @since 1.0.0
*/
final class My_Event_Plugin extends Event_Plugin {
```
The Plugin takes care of applying the transformer, so you can jump right into implementing it.
The ActivityPub Event Bridge then takes care of applying the transformer, so you can jump right into implementing it.
## Writing an event transformer class
If you are writing a transformer for a custom post type it is recommended to start by extending the provided [event transformer](./includes/activitypub/transformer/class-event.php). It is an extension of the default generic post transformer and inherits useful default implementations for generating the [attachments](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment), rendering a proper [content](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content) in HTML from either blocks or the classic editor, extracting [tags](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag) and more.
Within WordPress most content types are stored as a custom post type in the posts table. The ActivityPub plugin offers a basic support for all post types out of the box. So-called transformers take care of converting WordPress WP_Post objects to ActivityStreams JSON. The ActivityPub plugin offers a generic transformer for all post types. Additionally, custom transformers can be implemented to better fit a custom post type, and they can be easily registered with the ActivityPub plugin.
If you are writing a transformer for your event post type we recommend to start by extending the provided [event transformer](./includes/activitypub/transformer/class-event.php). It is an extension of the default generic post transformer and inherits useful default implementations for generating the [attachments](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment), rendering a proper [content](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content) in HTML from either blocks or the classic editor, extracting [tags](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag) and more. Furthermore, it offers functions which are likely to be shared by multiple event plugins, so you do not need to reimplement those, or you can fork and extend them to your needs.
So create a new file at `./includes/activitypub/transformer/my-event-plugin.php`.
```php
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
/**
* ActivityPub Transformer for my_event_post_type.
* ActivityPub Transformer for My Event Plugin' event post type.
*/
class My_Event_Post_Type_Transformer extends Event; {
class My_Event_Plugin extends Event_Transformer; {
```
The main function which controls the transformation is `to_object`. This one is called by the ActivityPub plugin to get the resulting ActivityPub representation as an PHP-array. The conversion to JSON-LD takes place later, and you don't need to cover that. You might just want to start by applying the parent function, but the chances are high, you don't even need to extend this functions functionality.
The main function which controls the transformation is `to_object`. This one is called by the ActivityPub plugin to get the resulting ActivityStreams represented by a PHP-object (`\Activitypub\Activity\Object\Extended_Object\Event`). The conversion to the actual JSON-LD takes place later, and you don't need to cover that (> `to_array` > associative array > `to_json` > JSON).
The chances are good that you will not need to override that function.
```php
/**
@ -52,7 +66,16 @@ public function to_object() {
}
```
The ActivityPub object classes contain dynamic getter and setter functions: `set_<property-name>` and `get_<property-name>`. Of course, the property with `property-name` must exist for these to work. The function `transform_object_properties` tries to set all properties known to the ActivityPub object where a function called `get_<property-name>` exists in the current transformer class.
We also recommend extending the constructor of the transformer class and set a specialized API object of the event, if it is available. For instance:
```php
public function __construct( $wp_object, $wp_taxonomy ) {
parent::__construct( $wp_object, $wp_taxonomy );
$this->event_api = new My_Event_Object_API( $wp_object );
}
```
The ActivityPub object classes contain dynamic getter and setter functions: `set_<property>()` and `get_<property>()`. The function `transform_object_properties()` usually called by `to_object()` tries to set all properties known to the target ActivityPub object where a function called `get_<property>` exists in the current transformer class.
### How to add new properties
@ -65,7 +88,7 @@ Adding new properties is not encouraged to do at the transformer level. It's rec
You can find all available event related properties in the [event class](https://github.com/Automattic/wordpress-activitypub/blob/master/includes/activity/extended-object/class-event.php) along documentation and with links to the specifications.
#### Mandatory Properties for an Event
#### Mandatory fields
In order to ensure your events are compatible with other ActivityPub Event implementations there are several required properties that must be set by your transformer.
@ -75,8 +98,12 @@ In order to ensure your events are compatible with other ActivityPub Event imple
* **[`name`](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name)**: the title of the event
#### Recommended properties for an Event in order to achieve good interoperability with other ActivityPub platforms
#### Checklist for properties you SHOULD at least consider writing a getter functions for
* **[summary](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary)**: Other ActivityPub platforms that don't natively support event should use the summary (and the `name`) to display it as a converted object type. For example Mastodon converts an `Event` object to a `Note`. It is recommended to write the summary as text-centered with minimal HTML markup and that it contains the most important event details like place, time, etc.
* **`isOnline`**:
* **`endTime`**
* **`location`** Note: the `address` within can be both a `string` or a `PostalAddress`.
* **`isOnline`**
* **`status`**
* **`get_tag`**
* **`timezone`**
* **`commentsEnabled`**

View file

@ -2,25 +2,32 @@
/**
* Replace the default ActivityPub Transformer
*
* @package activity-event-transformers
* @package ActivityPub_Event_Bridge
* @license AGPL-3.0-or-later
*/
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Activitypub\Activity\Extended_Object\Event as Event_Object;
use Activitypub\Model\Blog;
use Activitypub\Activity\Extended_Object\Place;
use Activitypub\Transformer\Post;
use function Activitypub\get_rest_url_by_path;
use DateTime;
/**
* Base transformer for WordPress event post types to ActivityPub events.
*
* Everything that transforming several WordPress post types that represent events
* have in common, as well as sane defaults for events should be defined here.
*
* BeforeFirstRelease:
* [ ] remove link at the end of the content.
* [ ] add organizer.
* [ ] do add Cancelled reason in the content.
*/
class Event extends Post {
abstract class Event extends Post {
/**
* The WordPress event taxonomy.
@ -29,18 +36,6 @@ class Event extends Post {
*/
protected $wp_taxonomy;
/**
* Returns the User-URL of the Author of the Post.
*
* If `single_user` mode is enabled, the URL of the Blog-User is returned.
*
* @return string The User-URL.
*/
protected function get_attributed_to() {
$blog = new Blog();
return $blog->get_id();
}
/**
* Returns the ActivityStreams 2.0 Object-Type for an Event.
*
@ -48,26 +43,82 @@ class Event extends Post {
*
* @return string The Event Object-Type.
*/
protected function get_object_type() {
protected function get_type(): string {
return 'Event';
}
/**
* Get a sane default for whether comments are enabled.
*/
protected function get_comments_enabled(): ?bool {
return comments_open( $this->wp_object );
}
/**
* Set a hardcoded template for the content.
*
* This actually disabled templates for the content.
* Maybe this independent templates for events will be added later.
*/
protected function get_post_content_template(): string {
return '[ap_content]';
}
/**
* Returns the title of the event.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name
*
* @return string The name.
*/
protected function get_name(): string {
return $this->wp_object->post_title;
}
/**
* 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 ) {
public function __construct( $wp_object, $wp_taxonomy = 'category' ) {
parent::__construct( $wp_object );
$this->wp_taxonomy = $wp_taxonomy;
}
/**
* Set the event category, via the mapping setting.
* Extract the join mode.
*
* Currently we don't handle joins, we always mark events as external.
*
* @return string
*/
public function get_category() {
$current_category_mapping = \get_option( 'activitypub_event_extensions_event_category_mappings', array() );
public function get_join_mode(): ?string {
return 'external';
}
/**
* Extract the external participation url.
*
* Currently we don't handle joins, we always mark events as external.
* We just link back to the events HTML representation on our WordPress site.
*
* @return ?string The external participation URL.
*/
public function get_external_participation_url(): ?string {
return 'external' === $this->get_join_mode() ? $this->get_url() : null;
}
/**
* Set the event category, via the mapping setting.
*
* @return ?string
*/
public function get_category(): ?string {
if ( is_null( $this->wp_taxonomy ) ) {
return null;
}
$current_category_mapping = \get_option( 'activitypub_event_bridge_event_category_mappings', array() );
$terms = \get_the_terms( $this->wp_object, $this->wp_taxonomy );
// Check if the event has a category set and if that category has a specific mapping return that one.
@ -75,19 +126,231 @@ class Event extends Post {
return sanitize_text_field( $current_category_mapping[ $terms[0]->slug ] );
} else {
// Return the default event category.
return sanitize_text_field( \get_option( 'activitypub_event_extensions_default_event_category', 'MEETING' ) );
return sanitize_text_field( \get_option( 'activitypub_event_bridge_default_event_category', 'MEETING' ) );
}
}
/**
* Retrieves the excerpt text (may be HTML). Used for constructing the summary.
*
* @return ?string
*/
protected function retrieve_excerpt(): ?string {
if ( $this->wp_object->post_excerpt ) {
return $this->wp_object->post_excerpt;
} else {
return null;
}
}
/**
* Get the start time.
*
* This is mandatory and must be implemented in the final event transformer class.
*/
abstract protected function get_start_time(): string;
/**
* Get the end time.
*
* This is not mandatory and therefore just return null by default.
*/
protected function get_end_time(): ?string {
return null;
}
/**
* Get a default for the location.
*
* This should be overridden in the actual event transformer.
*/
protected function get_location(): ?Place {
return null;
}
/**
* Default value for the event status.
*/
protected function get_status(): ?string {
return 'CONFIRMED';
}
/**
* Compose a human readable formatted start time.
*/
protected function format_start_time(): string {
return $this->format_time( $this->get_start_time() );
}
/**
* Compose a human readable formatted end time.
*/
protected function format_end_time(): string {
return $this->format_time( $this->get_end_time() );
}
/**
* Compose a human readable formatted time.
*
* @param ?string $time The time which needs to be formatted.
*/
private static function format_time( $time ) {
if ( is_null( $time ) ) {
return '';
}
$start_datetime = new DateTime( $time );
$start_timestamp = $start_datetime->getTimestamp();
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
return wp_date( $datetime_format, $start_timestamp );
}
/**
* Format a human readable address.
*/
protected function format_address(): string {
$location = $this->get_location();
if ( is_null( $location ) ) {
return '';
}
$address = $location->get_address();
if ( ! $address ) {
return $location->get_name();
}
if ( is_string( $address ) ) {
return $address;
}
if ( ! is_array( $address ) ) {
return '';
}
return isset( $address['locality'] ) ? $address['locality'] : '';
}
/**
* Format the category using the translation.
*/
protected function format_categories(): string {
if ( is_null( $this->wp_taxonomy ) ) {
return '';
}
$categories = array();
// Add the federated category string.
require_once ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . '/includes/event-categories.php';
$federated_category = $this->get_category();
if ( array_key_exists( $federated_category, ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES ) ) {
$categories[] = ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES[ $federated_category ];
}
// Add all category terms.
$terms = \get_the_terms( $this->wp_object, $this->wp_taxonomy );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$categories[] = $term->name;
}
}
if ( ! empty( $categories ) ) {
return implode( ' · ', array_unique( $categories ) );
}
return '';
}
/**
* Create a custom summary.
*
* It contains also the most important meta-information. The summary is often used when the
* ActivityPub object type 'Event' is not supported, e.g. in Mastodon.
*
* @return string $summary The custom event summary.
*/
public function get_summary(): ?string {
add_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ), 2, 2 );
$excerpt = $this->retrieve_excerpt();
// BeforeFirstRelease: decide whether this should be a admin setting.
$fallback_to_content = true;
if ( is_null( $excerpt ) && $fallback_to_content ) {
$excerpt = parent::get_content();
}
remove_filter( 'activitypub_object_content_template', array( self::class, 'remove_ap_permalink_from_template' ) );
$category = $this->format_categories();
$start_time = $this->format_start_time();
$end_time = $this->format_end_time();
$address = $this->format_address();
$formatted_items = array();
if ( ! empty( $category ) ) {
$formatted_items[] = '🏷️ ' . __( 'Category', 'activitypub-event-bridge' ) . ': ' . $category;
}
if ( ! empty( $start_time ) ) {
$formatted_items[] = '🗓️ ' . __( 'Start', 'activitypub-event-bridge' ) . ': ' . $start_time;
}
if ( ! empty( $end_time ) ) {
$formatted_items[] = '⏳ ' . __( 'End', 'activitypub-event-bridge' ) . ': ' . $end_time;
}
if ( ! empty( $address ) ) {
$formatted_items[] = '📍 ' . __( 'Address', 'activitypub-event-bridge' ) . ': ' . $address;
}
// Compose the summary based on the number of meta items.
if ( count( $formatted_items ) > 1 ) {
$summary = '<ul><li>' . implode( '</li><li>', $formatted_items ) . '</li></ul>';
} elseif ( 1 === count( $formatted_items ) ) {
$summary = $formatted_items[0]; // Just the one item without <ul><li>.
} else {
$summary = ''; // No items, so no output.
}
$summary .= $excerpt;
return $summary;
}
/**
* By default set the timezone of the WordPress site.
*
* This is likely to be overwritten by the actual transformer.
*
* @return string The timezone string of the site.
*/
public function get_timezone(): string {
return wp_timezone_string();
}
/**
* Remove the permalink shortcode from a WordPress template.
*
* This used for the summary template, because the summary usually gets,
* used when converting a object, where the URL is usually appended anyway.
*
* @param string $template The template string.
* @param WP_Post|WP_Comment $wp_object The wp_object which was used to select the template.
*/
public static function remove_ap_permalink_from_template( $template, $wp_object ) {
// we could override the template here, to get out custom template from an option.
if ( 'event' === $wp_object->post_type ) {
$template = str_replace( '[ap_permalink]', '', $template );
$template = str_replace( '[ap_permalink type="html"]', '', $template );
}
return $template;
}
/**
* Generic function that converts an WP-Event object to an ActivityPub-Event object.
*
* @return Event_Object
*/
public function to_object() {
public function to_object(): Event_Object {
$activitypub_object = new Event_Object();
$activitypub_object = $this->transform_object_properties( $activitypub_object );
// maybe move the following logic (till end of the function) into getter functions.
$published = \strtotime( $this->wp_object->post_date_gmt );
$activitypub_object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) );
@ -103,12 +366,11 @@ class Event extends Post {
$this->get_locale() => $this->get_content(),
)
);
$path = sprintf( 'actors/%d/followers', intval( $this->wp_object->post_author ) );
$activitypub_object->set_to(
array(
'https://www.w3.org/ns/activitystreams#Public',
get_rest_url_by_path( $path ),
$this->get_actor_object()->get_followers(), // this fails on my machine.
)
);

View file

@ -1,21 +1,24 @@
<?php
/**
* ActivityPub Transformer for the plugin Very Simple Event List.
*
* @package activity-event-transformers
* @package ActivityPub_Event_Bridge
* @license AGPL-3.0-or-later
*/
use Activitypub_Event_Extensions\Activitypub\Transformer\Event as Event_Transformer;
use EM_Event;
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Activitypub\Activity\Extended_Object\Event;
use Activitypub\Activity\Extended_Object\Place;
use function Activitypub\esc_hashtag;
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
use DateTime;
use DateTimeZone;
use EM_Event;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
use function Activitypub\esc_hashtag;
/**
* ActivityPub Transformer for events from the WordPress plugin 'Events Manager'
@ -24,7 +27,7 @@ if ( ! defined( 'ABSPATH' ) ) {
*
* @since 1.0.0
*/
class Events_Manager extends Event_Transformer {
final class Events_Manager extends Event_Transformer {
/**
* Holds the EM_Event object.
@ -34,55 +37,24 @@ class Events_Manager extends Event_Transformer {
protected $em_event;
/**
* Get transformer name.
* Extend the constructor, to also set the Eventsmanager objects.
*
* Retrieve the transformers name.
* This is a special class object form The Events Calendar which
* has a lot of useful functions, we make use of our getter functions.
*
* @since 1.0.0
* @access public
* @return string Widget name.
* @param WP_Post $wp_object The WordPress object.
* @param string $wp_taxonomy The taxonomy slug of the event post type.
*/
public function get_transformer_name() {
return 'activitypub-event-transformers/events-manager';
public function __construct( $wp_object, $wp_taxonomy ) {
parent::__construct( $wp_object, $wp_taxonomy );
$this->em_event = new EM_Event( $this->wp_object->ID, 'post_id' );
}
/**
* Get transformer title.
* Returns whether the even is online
*
* Retrieve the transformers label.
*
* @since 1.0.0
* @access public
* @return string Widget title.
* @return bool
*/
public function get_transformer_label() {
return 'Events Manager';
}
/**
* Get supported post types.
*
* Retrieve the list of supported WordPress post types this transformer widget can handle.
*
* @since 1.0.0
* @access public
* @return array Widget categories.
*/
public static function get_supported_post_types() {
return array();
}
/**
* Returns the ActivityStreams 2.0 Object-Type for an Event.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
* @since 1.0.0
* @return string The Event Object-Type.
*/
protected function get_type() {
return 'Event';
}
protected function get_is_online() {
return 'url' === $this->em_event->event_location_type;
}
@ -92,29 +64,31 @@ class Events_Manager extends Event_Transformer {
*
* @return array The Place.
*/
public function get_location() {
public function get_location(): ?Place {
if ( 'url' === $this->em_event->event_location_type ) {
return null;
}
$location = new Place();
$em_location = $this->em_event->get_location();
if ( '' === $em_location->location_id ) {
return null;
}
$location = new Place();
$location->set_name( $em_location->location_name );
$address = array(
'type' => 'PostalAddress',
'addressCountry' => $em_location->location_country,
'addressLocality' => $em_location->location_town,
'streetAddress' => $em_location->location_address,
'postalAddress' => $em_location->location_address,
'postalCode' => $em_location->location_postcode,
'name' => $em_location->location_name,
);
if ( $em_location->location_state ) {
$address['addressRegion'] = $em_location->location_state;
}
if ( $em_location->location_postcode ) {
$address['postalCode'] = $em_location->location_postcode;
}
$location->set_address( $address );
return $location;
@ -123,76 +97,70 @@ class Events_Manager extends Event_Transformer {
/**
* Get the end time from the events metadata.
*/
protected function get_end_time() {
public function get_end_time(): ?string {
return null;
}
/**
* Get the end time from the events metadata.
*/
protected function get_start_time() {
public function get_start_time(): string {
$date_string = $this->em_event->event_start_date;
$time_string = $this->em_event->event_start_time;
$timezone_string = $this->em_event->event_timezone;
// Create a DateTime object with the given date, time, and timezone
// Create a DateTime object with the given date, time, and timezone.
$datetime = new DateTime( $date_string . ' ' . $time_string, new DateTimeZone( $timezone_string ) );
// Set the timezone for proper formatting
// Set the timezone for proper formatting.
$datetime->setTimezone( new DateTimeZone( 'UTC' ) );
// Format the DateTime object as 'Y-m-d\TH:i:s\Z'
// Format the DateTime object as 'Y-m-d\TH:i:s\Z'.
$formatted_date = $datetime->format( 'Y-m-d\TH:i:s\Z' );
return $formatted_date;
}
protected function get_maximum_attendee_capacity() {
/**
* Returns the maximum attendee capacity.
*
* @return int
*/
public function get_maximum_attendee_capacity() {
return $this->em_event->event_spaces;
}
/**
* @todo decide whether to include pending bookings or not!
* Return the remaining attendee capacity
*
* @return int
*/
protected function get_remaining_attendee_capacity() {
$em_bookings = $this->em_event->get_bookings()->get_bookings();
$remaining_attendee_capacity = $this->em_event->event_spaces - count( $em_bookings->bookings );
public function get_remaining_attendee_capacity() {
$em_bookings_count = $this->get_participant_count();
$remaining_attendee_capacity = $this->em_event->event_spaces - $em_bookings_count;
return $remaining_attendee_capacity;
}
protected function get_participant_count() {
/**
* Returns the current participant count.
*
* @return int
*/
public function get_participant_count(): int {
$em_bookings = $this->em_event->get_bookings()->get_bookings();
return count( $em_bookings->bookings );
}
protected function get_content() {
return $this->wp_object->post_content;
}
protected function get_summary() {
if ( $this->em_event->post_excerpt ) {
$excerpt = $this->em_event->post_excerpt;
} else {
$excerpt = $this->get_content();
}
$address = $this->em_event->get_location()->location_name;
$start_time = strtotime( $this->get_start_time() );
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
$start_time_string = wp_date( $datetime_format, $start_time );
$summary = "📍 {$address}\n📅 {$start_time_string}\n\n{$excerpt}";
return $summary;
}
// protected function get_join_mode() {
// return 'free';
// }
private function get_event_link_attachment() {
/**
* Get the event link as an ActivityPub Link object, but as an associative array.
*
* @return array
*/
private function get_event_link_attachment(): array {
$event_link_url = $this->em_event->event_location->data['url'];
$event_link_text = $this->em_event->event_location->data['text'];
return array(
'type' => 'Link',
'name' => 'Website',
// 'name' => $event_link_text,
'name' => $event_link_text ? $event_link_text : 'Website',
'href' => \esc_url( $event_link_url ),
'mediaType' => 'text/html',
);
@ -218,55 +186,9 @@ class Events_Manager extends Event_Transformer {
}
/**
* This function tries to map VS-Event categories to Mobilizon event categories.
*
* @return string $category
* Compose the events tags.
*/
protected function get_category() {
$categories = $this->em_event->get_categories()->terms;
if ( empty( $categories ) ) {
return 'MEETING';
}
// Prepare an array to store all category information for comparison.
$category_info = array();
// Extract relevant category information (name, slug, description) from the categories array.
foreach ( $categories as $category ) {
$category_info[] = strtolower( $category->name );
$category_info[] = strtolower( $category->slug );
$category_info[] = strtolower( $category->description );
}
// Convert mobilizon categories to lowercase for case-insensitive comparison.
$mobilizon_categories = array_map( 'strtolower', Event::DEFAULT_EVENT_CATEGORIES );
// Initialize variables to track the best match.
$best_mobilizon_category_match = '';
$best_match_length = 0;
// Check for the best match.
foreach ( $mobilizon_categories as $mobilizon_category ) {
foreach ( $category_info as $category ) {
foreach ( explode( '_', $mobilizon_category ) as $mobilizon_category_slice ) {
if ( stripos( $category, $mobilizon_category_slice ) !== false ) {
// Check if the current match is longer than the previous best match.
$current_match_legnth = strlen( $mobilizon_category_slice );
if ( $current_match_legnth > $best_match_length ) {
$best_mobilizon_category_match = $mobilizon_category;
$best_match_length = $current_match_legnth;
}
}
}
}
}
return ( '' != $best_mobilizon_category_match ) ? strtoupper( $best_mobilizon_category_match ) : 'MEETING';
}
protected function get_tag() {
public function get_tag() {
// The parent tag function also fetches the mentions.
$tags = parent::get_tag();
@ -285,25 +207,12 @@ class Events_Manager extends Event_Transformer {
return $tags;
}
protected function get_name() {
/**
* Get the events title/name.
*
* @return string
*/
protected function get_name(): string {
return $this->em_event->event_name;
}
/**
* Transform the WordPress Object into an ActivityPub Object.
*
* @return Activitypub\Activity\Event
*/
public function to_object() {
$this->em_event = new EM_Event( $this->wp_object->ID, 'post_id' );
$activitypub_object = new Event();
$activitypub_object = $this->transform_object_properties( $activitypub_object );
$activitypub_object->set_external_participation_url( $this->get_url() );
return $activitypub_object;
}
}

View file

@ -2,40 +2,32 @@
/**
* ActivityPub Transformer for the plugin Very Simple Event List.
*
* @package activity-event-transformers
* @package ActivityPub_Event_Bridge
* @license AGPL-3.0-or-later
*/
use Activitypub\Transformer\Post;
use Activitypub\Model\Blog_user;
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Activitypub\Activity\Extended_Object\Event as Event_Object;
use Activitypub\Activity\Extended_Object\Place;
use Activitypub\Model\Blog;
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
use GatherPress\Core\Event as GatherPress_Event;
use function Activitypub\get_rest_url_by_path;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* ActivityPub Transformer for VS Event
*
* @since 1.0.0
*/
class GatherPress extends Post {
/**
* The target ActivityPub Event object of the transformer.
*
* @var Event
*/
protected $ap_object;
final class GatherPress extends Event {
/**
* The current GatherPress Event object.
*
* @var Event
* @var GatherPress_Event
*/
protected $gp_event;
@ -47,87 +39,49 @@ class GatherPress extends Post {
protected $gp_venue;
/**
* Get transformer name.
* Extend the constructor, to also set the GatherPress objects.
*
* Retrieve the transformers name.
* This is a special class object form The Events Calendar which
* has a lot of useful functions, we make use of our getter functions.
*
* @since 1.0.0
* @access public
* @return string Widget name.
* @param WP_Post $wp_object The WordPress object.
* @param string $wp_taxonomy The taxonomy slug of the event post type.
*/
public function get_transformer_name() {
return 'gatherpress/gp-event';
}
/**
* Get transformer title.
*
* Retrieve the transformers label.
*
* @since 1.0.0
* @access public
* @return string Widget title.
*/
public function get_transformer_label() {
return 'GatherPress Event';
}
/**
* Get supported post types.
*
* Retrieve the list of supported WordPress post types this transformer widget can handle.
*
* @since 1.0.0
* @access public
* @return array Widget categories.
*/
public static function get_supported_post_types() {
return array( GatherPress_Event::POST_TYPE );
}
/**
* Returns the ActivityStreams 2.0 Object-Type for an Event.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
* @since 1.0.0
* @return string The Event Object-Type.
*/
protected function get_type() {
return 'Event';
public function __construct( $wp_object, $wp_taxonomy ) {
parent::__construct( $wp_object, $wp_taxonomy );
$this->gp_event = new GatherPress_Event( $this->wp_object->ID );
$this->gp_venue = $this->gp_event->get_venue_information();
}
/**
* Get the event location.
*
* @return array The Place.
* @return Place|null The place objector null if not place set.
*/
public function get_location() {
public function get_location(): ?Place {
$address = $this->gp_venue['full_address'];
$place = new Place();
$place->set_type( 'Place' );
$place->set_name( $address );
$place->set_address( $address );
return $place;
if ( $address ) {
$place = new Place();
$place->set_type( 'Place' );
$place->set_name( $address );
$place->set_address( $address );
return $place;
} else {
return null;
}
}
/**
* Get the end time from the event object.
*/
protected function get_end_time() {
protected function get_end_time(): ?string {
return $this->gp_event->get_datetime_end( 'Y-m-d\TH:i:s\Z' );
}
/**
* Get the end time from the event object.
*/
protected function get_start_time() {
protected function get_start_time(): string {
return $this->gp_event->get_datetime_start( 'Y-m-d\TH:i:s\Z' );
}
@ -150,8 +104,7 @@ class GatherPress extends Post {
/**
* Overrides/extends the get_attachments function to also add the event Link.
*/
protected function get_attachment() {
protected function get_attachment(): array {
$attachments = parent::get_attachment();
if ( count( $attachments ) ) {
$attachments[0]['type'] = 'Document';
@ -165,87 +118,38 @@ class GatherPress extends Post {
}
/**
* TODO:
* Prevents gatherpress blocks from being rendered for the content.
*
* @return string $category
* @param mixed $block_content The blocks content.
* @param mixed $block The block.
*/
protected function get_category() {
return 'MEETING';
}
/**
* Returns the User-URL of the Author of the Post.
*
* If `single_user` mode is enabled, the URL of the Blog-User is returned.
*
* @return string The User-URL.
*/
protected function get_attributed_to() {
$user = new Blog_User();
return $user->get_url();
}
/**
* Create a custom summary.
*
* It contains also the most important meta-information. The summary is often used when the
* ActivityPub object type 'Event' is not supported, e.g. in Mastodon.
*
* @return string $summary The custom event summary.
*/
public function get_summary() {
if ( $this->wp_object->excerpt ) {
$excerpt = $this->wp_object->post_excerpt;
} elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) {
$excerpt = get_post_meta( $this->wp_object->ID, 'event-summary', true );
} else {
$excerpt = $this->get_content();
public static function filter_gatherpress_blocks( $block_content, $block ) {
// Check if the block name starts with 'gatherpress'.
if ( strpos( $block['blockName'], 'gatherpress/' ) === 0 ) {
return ''; // Skip rendering this block.
}
$address = get_post_meta( $this->wp_object->ID, 'event-location', true );
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
$start_time_string = wp_date( $datetime_format, $start_time );
$summary = "📍 {$address}\n📅 {$start_time_string}\n\n{$excerpt}";
return $summary;
return $block_content; // Return the content for other blocks.
}
/**
* Transform the WordPress Object into an ActivityPub Object.
* Apply the filter for preventing the rendering off gatherpress blocks just in time.
*
* @return Activitypub\Activity\Event
* @return Event_Object
*/
public function to_object() {
public function to_object(): Event_Object {
add_filter( 'render_block', array( self::class, 'filter_gatherpress_blocks' ), 10, 2 );
$activitypub_object = parent::to_object();
remove_filter( 'render_block', array( self::class, 'filter_gatherpress_blocks' ) );
return $activitypub_object;
}
$this->ap_object = new Event();
$this->gp_event = new GatherPress_Event( $this->wp_object->ID );
$this->gp_venue = $this->gp_event->get_venue_information();
$this->ap_object = parent::to_object();
$this->ap_object->set_comments_enabled( 'open' === $this->wp_object->comment_status ? true : false );
$this->ap_object->set_external_participation_url( $this->get_url() );
$online_event_link = $this->gp_event->maybe_get_online_event_link();
if ( $online_event_link ) {
$this->ap_object->set_is_online( true );
} else {
$this->ap_object->set_is_online( false );
}
$this->ap_object->set_status( 'CONFIRMED' );
$this->ap_object->set_name( get_the_title( $this->wp_object->ID ) );
$this->ap_object->set_actor( get_rest_url_by_path( 'application' ) );
$this->ap_object->set_to( array( 'https://www.w3.org/ns/activitystreams#Public' ) );
$this->ap_object->set_location();
return $this->ap_object;
/**
* Determine whether the event is online.
*
* @return bool
*/
public function get_is_online(): bool {
return $this->gp_event->maybe_get_online_event_link() ? true : false;
}
}

View file

@ -0,0 +1,191 @@
<?php
/**
* ActivityPub Tribe Transformer
*
* @package ActivityPub_Event_Bridge
* @license AGPL-3.0-or-later
*/
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Activitypub\Activity\Extended_Object\Event as Event_Object;
use Activitypub\Activity\Extended_Object\Place;
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
use WP_Post;
use function Activitypub\esc_hashtag;
/**
* ActivityPub Tribe Transformer
*
* @since 1.0.0
*/
final class The_Events_Calendar extends Event {
/**
* The Tribe Event object.
*
* @var array|WP_Post|null
*/
protected $tribe_event;
/**
* Extend the constructor, to also set the tribe object.
*
* This is a special class object form The Events Calendar which
* has a lot of useful functions, we make use of our getter functions.
*
* @param WP_Post $wp_object The WordPress object.
* @param string $wp_taxonomy The taxonomy slug of the event post type.
*/
public function __construct( $wp_object, $wp_taxonomy ) {
parent::__construct( $wp_object, $wp_taxonomy );
$this->tribe_event = \tribe_get_event( $wp_object );
}
/**
* Get the tags, including also the set categories from The Events Calendar.
*
* @return ?array The array if tags,
*/
public function get_tag(): ?array {
$tags = array();
$category_ids = tribe_get_event_cat_ids();
if ( $category_ids ) {
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 = array_merge( $tags, parent::get_tag() );
return $tags;
}
/**
* Get the end time from the event object.
*/
protected function get_end_time(): ?string {
if ( empty( $this->tribe_event->end_date ) ) {
return null;
}
$date = date_create( $this->tribe_event->end_date, wp_timezone() );
return \gmdate( 'Y-m-d\TH:i:s\Z', $date->getTimestamp() );
}
/**
* Get the end time from the event object.
*/
protected function get_start_time(): string {
$date = date_create( $this->tribe_event->start_date, wp_timezone() );
return \gmdate( 'Y-m-d\TH:i:s\Z', $date->getTimestamp() );
}
/**
* Get status of the tribe event
*
* @return string status of the event
*/
public function get_status(): ?string {
if ( 'canceled' === $this->tribe_event->event_status ) {
return 'CANCELLED';
}
if ( 'postponed' === $this->tribe_event->event_status ) {
return 'CANCELLED'; // This will be reflected in the cancelled reason.
}
return 'CONFIRMED';
}
/**
* Check if the comments are enabled for the current event.
*/
public function get_comments_enabled(): bool {
return ( 'open' === $this->tribe_event->comment_status ) ? true : false;
}
/**
* Check if the event is an online event.
*/
public function get_is_online(): bool {
return false;
}
/**
* Get the event location.
*
* @return Place|array The place/venue if one is set.
*/
public function get_location(): Place|null {
// Get short handle for the venues.
$venues = $this->tribe_event->venues;
// Get first venue. We currently only support a single venue.
if ( $venues instanceof \Tribe\Events\Collections\Lazy_Post_Collection ) {
$venue = $venues->first();
} elseif ( empty( $this->wp_object->venues ) || ! empty( $this->wp_object->venues[0] ) ) {
return null;
} else {
$venue = $venues[0];
}
if ( ! $venue ) {
return null;
}
// Set the address.
$address = array();
if ( ! empty( $venue->country ) ) {
$address['addressCountry'] = $venue->country;
}
if ( ! empty( $venue->city ) ) {
$address['addressLocality'] = $venue->city;
}
if ( ! empty( $venue->province ) ) {
$address['addressRegion'] = $venue->province;
}
if ( ! empty( $venue->zip ) ) {
$address['postalCode'] = $venue->zip;
}
if ( ! empty( $venue->address ) ) {
$address['streetAddress'] = $venue->address;
}
if ( ! empty( $venue->post_title ) ) {
$address['name'] = $venue->post_title;
}
$address['type'] = 'PostalAddress';
$location = new Place();
if ( count( $address ) > 1 ) {
$location->set_address( $address );
} else {
$location->set_address( $venue->post_title );
}
$location->set_id( $venue->permalink );
$location->set_name( $venue->post_title );
return $location;
}
/**
* Get the timezone of the event.
*
* @return string The timezone string of the site.
*/
public function get_timezone(): string {
return $this->tribe_event->timezone;
}
}

View file

@ -1,136 +0,0 @@
<?php
/**
* ActivityPub Tribe Transformer
*
* @package activity-event-transformers
* @license AGPL-3.0-or-later
*/
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
use Activitypub_Event_Extensions\Activitypub\Transformer\Event;
use Activitypub\Activity\Extended_Object\Place;
use WP_Error;
/**
* ActivityPub Tribe Transformer
*
* @since 1.0.0
*/
class Tribe extends Event {
/**
* The Tribe Event object.
*
* @var WP_Post
*/
protected $tribe_event;
// /**
// * resolve the tribe metadata in the setter of wp_post.
// *
// * @param WP_Post $wp_post The WP_Post object.
// * @return void
// */
// public function set_wp_post( WP_Post $wp_post ) {
// parent::set_wp_post( $wp_post );
// $this->tribe_event = tribe_get_event( $wp_post->ID );
// }
/**
* Get tribe category of wp_post
*
* @return string|null tribe category if it exists
*/
public function get_tribe_category() {
// TODO: make it possible that one event can have multiple categories?
// Using cat_slugs isn't the best way to do this, don't know if it's a good idea.
$categories = tribe_get_event_cat_slugs( $this->wp_object->ID );
if ( count( $categories ) === 0 ) {
return null;
}
return $categories[0];
}
/**
* Get status of the tribe event
*
* @return string status of the event
*/
public function get_tribe_status() {
if ( 'canceled' === $this->tribe_event->event_status ) {
return 'CANCELLED';
}
if ( 'postponed' === $this->tribe_event->event_status ) {
return 'CANCELLED'; // This will be reflected in the cancelled reason.
}
if ( '' === $this->tribe_event->event_status ) {
return 'CONFIRMED';
}
return new WP_Error( 'invalid event_status value', __( 'invalid event_status', 'activitypub' ), array( 'status' => 404 ) );
}
/**
* Returns the content for the ActivityPub Item with
*
* The content will be generated based on the user settings.
*
* @return string The content.
*/
protected function get_content() {
$content = parent::get_content();
// TODO: remove link at the end of the content.
// TODO: add organizer
// $this->tribe_event->organizers[0].
// TODO: do add Cancelled reason in the content (maybe at the end).
return $content;
}
/**
* Get the event location.
*
* @returns array The Place.
*/
public function get_event_location() {
/*
This is how the Tribe event looks like:
TODO: Remove this comment.
'post_title' => 'testvenue',
'post_name' => 'testvenue',
'guid' => 'http://localhost/venue/testvenue/',
'post_type' => 'tribe_venue',
'address' => 'testaddr',
'country' => 'Austria',
'city' => 'testcity',
'state_province' => 'testprovince',
'state' => '',
'province' => 'testprovince',
'zip' => '8000',
'phone' => '+4312343',
'permalink' => 'http://localhost/venue/testvenue/',
'directions_link' => 'https://maps.google.com/maps?f=q&#038;source=s_q&#038;hl=en&#038;geocode=&#038;q=testaddr+testcity+testprovince+8000+Austria',
'website' => 'https://test.at',
*/
$venue = $this->tribe_event->venues[0];
return ( new Place() )
->set_type( 'Place' )
->set_name( $venue->post_name )
->set_address(
$venue->address . "\n" .
$venue->zip . ', ' . $venue->city . "\n" .
$venue->country
); // TODO: add checks that everything exists here.
}
}

View file

@ -0,0 +1,114 @@
<?php
/**
* ActivityPub Transformer for the plugin Very Simple Event List.
*
* @package ActivityPub_Event_Bridge
* @license AGPL-3.0-or-later
*/
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Activitypub\Activity\Extended_Object\Event;
use Activitypub\Activity\Extended_Object\Place;
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
/**
* ActivityPub Transformer for VS Event.
*
* This transformer tries a different principle: The setters are chainable.
*
* @since 1.0.0
*/
final class VS_Event_List extends Event_Transformer {
/**
* Get the event location.
*
* @return Place The Place.
*/
public function get_location(): ?Place {
$address = get_post_meta( $this->wp_object->ID, 'event-location', true );
if ( $address ) {
$place = new Place();
$place->set_type( 'Place' );
$place->set_name( $address );
$place->set_address( $address );
return $place;
} else {
return null;
}
}
/**
* Get the end time from the events metadata.
*/
protected function get_end_time(): ?string {
if ( 'yes' === get_post_meta( $this->wp_object->ID, 'event-hide-end-time', true ) ) {
return null;
}
$end_time = get_post_meta( $this->wp_object->ID, 'event-date', true );
if ( is_null( $end_time ) || empty( $end_time ) || 'no' === $end_time ) {
return null;
}
return $end_time ? \gmdate( 'Y-m-d\TH:i:s\Z', $end_time ) : null;
}
/**
* Get the end time from the events metadata.
*/
protected function get_start_time(): string {
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
return \gmdate( 'Y-m-d\TH:i:s\Z', $start_time );
}
/**
* Get the event link from the events metadata.
*
* @return ?array Associated array of an ActivityStreams Link object with the events URL.
*/
private function get_event_link(): ?array {
$event_link = get_post_meta( $this->wp_object->ID, 'event-link', true );
$event_link_label = get_post_meta( $this->wp_object->ID, 'event-link-label', true ) ?? 'Event Link';
if ( $event_link ) {
return array(
'type' => 'Link',
'name' => $event_link_label,
'href' => \esc_url( $event_link ),
'mediaType' => 'text/html',
);
}
return null;
}
/**
* Overrides/extends the get_attachments function to also add the event Link.
*/
protected function get_attachment(): ?array {
$attachments = parent::get_attachment();
if ( count( $attachments ) ) {
$attachments[0]['type'] = 'Document';
$attachments[0]['name'] = 'Banner';
}
$event_link = $this->get_event_link();
if ( $event_link ) {
$attachments[] = $event_link;
}
return $attachments;
}
/**
* Retrieves the excerpt text (may be HTML). Used for constructing the summary.
*
* @return ?string
*/
protected function retrieve_excerpt(): ?string {
if ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) {
return get_post_meta( $this->wp_object->ID, 'event-summary', true );
} else {
return parent::retrieve_excerpt();
}
}
}

View file

@ -1,251 +0,0 @@
<?php
/**
* ActivityPub Transformer for the plugin Very Simple Event List.
*
* @package activity-event-transformers
* @license AGPL-3.0-or-later
*/
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
use Activitypub_Event_Extensions\Activitypub\Transformer\Event as Event_Transformer;
use Activitypub\Model\Blog;
use Activitypub\Activity\Extended_Object\Event;
use Activitypub\Activity\Extended_Object\Place;
use WP_Error;
use function Activitypub\get_rest_url_by_path;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* ActivityPub Transformer for VS Event
*
* @since 1.0.0
*/
class VS_Event extends Event_Transformer {
/**
* The target transformer ActivityPub Event object.
*
* @var Event
*/
protected $ap_object;
/**
* Get transformer name.
*
* Retrieve the transformers name.
*
* @since 1.0.0
* @access public
* @return string Widget name.
*/
public function get_transformer_name() {
return 'activitypub-event-transformers/vs-event';
}
/**
* Get transformer title.
*
* Retrieve the transformers label.
*
* @since 1.0.0
* @access public
* @return string Widget title.
*/
public function get_transformer_label() {
return 'VS Event';
}
/**
* Get supported post types.
*
* Retrieve the list of supported WordPress post types this transformer widget can handle.
*
* @since 1.0.0
* @access public
* @return array Widget categories.
*/
public static function get_supported_post_types() {
return array( 'event' );
}
/**
* Returns the ActivityStreams 2.0 Object-Type for an Event.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
* @since 1.0.0
* @return string The Event Object-Type.
*/
protected function get_type() {
return 'Event';
}
/**
* Get the event location.
*
* @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' );
$place->set_name( $address );
$place->set_address( $address );
return $place;
}
/**
* 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 );
}
/**
* 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 );
}
/**
* 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(
'type' => 'Link',
'name' => 'Website',
'href' => \esc_url( $event_link ),
'mediaType' => 'text/html',
);
}
}
/**
* 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';
$attachments[0]['name'] = 'Banner';
}
$event_link = $this->get_event_link();
if ( $event_link ) {
$attachments[] = $event_link;
}
return $attachments;
}
/**
* Create a custom summary.
*
* It contains also the most important meta-information. The summary is often used when the
* ActivityPub object type 'Event' is not supported, e.g. in Mastodon.
*
* @return string $summary The custom event summary.
*/
public function get_summary() {
if ( $this->wp_object->excerpt ) {
$excerpt = $this->wp_object->post_excerpt;
} elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) {
$excerpt = get_post_meta( $this->wp_object->ID, 'event-summary', true );
} else {
$excerpt = $this->get_content();
}
$address = get_post_meta( $this->wp_object->ID, 'event-location', true );
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
$start_time_string = wp_date( $datetime_format, $start_time );
$summary = "📍 {$address}\n📅 {$start_time_string}\n\n{$excerpt}";
return $summary;
}
/**
* Generic setter.
*
* @param string $key The key to set.
* @param string $value The value to set.
*
* @return mixed The value.
*/
public function set( $key, $value ) {
if ( ! $this->ap_object->has( $key ) ) {
return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
}
$setter_function = 'set_' . $key;
$getter_function = 'get_' . $key;
if ( in_array( $getter_function, get_class_methods( $this ) ) ) {
$this->ap_object->$setter_function( $this->$getter_function() );
} else {
$this->ap_object->$setter_function( $value );
}
return $this;
}
/**
* Magic function to implement setter
*
* @param string $method The method name.
* @param string $params The method params.
*
* @return void
*/
public function __call( $method, $params ) {
$var = \strtolower( \substr( $method, 4 ) );
if ( \strncasecmp( $method, 'set', 3 ) === 0 ) {
return $this->set( $var, $params[0] );
}
// when do we need: call_user_func( array( $activitypub_object, $setter ), $value );
return $this;
}
/**
* Transform the WordPress Object into an ActivityPub Object.
*
* @return Activitypub\Activity\Event
*/
public function to_object() {
$this->ap_object = new Event();
$this
->set_content()
->set_content_map()
->set_attributed_to()
->set_published()
->set_start_time()
->set_end_time()
->set_type()
->set_category()
->set_attachment()
->set_comments_enabled( true )
->set_external_participation_url( $this->get_url() )
->set_status( 'CONFIRMED' )
->set_name( get_the_title( $this->wp_object->ID ) )
->set_is_online( false )
->set_in_language( $this->get_locale() )
->set_actor( get_rest_url_by_path( 'application' ) )
->set_to( array( 'https://www.w3.org/ns/activitystreams#Public' ) )
->set_location()
->set_id();
return $this->ap_object;
}
}

View file

@ -4,11 +4,17 @@
*
* Notices for guiding to proper configuration of ActivityPub with event plugins.
*
* @package Activitypub_Event_Extensions
* @package ActivityPub_Event_Bridge
* @since 1.0.0
* @license AGPL-3.0-or-later
*/
namespace Activitypub_Event_Extensions\Admin;
namespace ActivityPub_Event_Bridge\Admin;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use ActivityPub_Event_Bridge\Plugins\Event_Plugin;
/**
* Class responsible for Event Plugin related admin notices.
@ -21,14 +27,14 @@ class Event_Plugin_Admin_Notices {
/**
* Information about the event plugin.
*
* @var array
* @var Event_Plugin
*/
protected $event_plugin;
/**
* Adds admin notices to an active supported event plugin.
*
* @param array $event_plugin Information about the activate event plugin.
* @param Event_Plugin $event_plugin Class that has implements functions to handle a certain supported activate event plugin.
*/
public function __construct( $event_plugin ) {
$this->event_plugin = $event_plugin;
@ -42,39 +48,35 @@ class Event_Plugin_Admin_Notices {
*
* @return bool
*/
private function event_post_type_is_not_activitypub_enabled() {
return ! in_array( $this->event_plugin['post_type'], get_option( 'activitypub_support_post_types', array() ), true );
private function event_post_type_is_not_activitypub_enabled(): bool {
return ! in_array( $this->event_plugin::get_post_type(), get_option( 'activitypub_support_post_types', array() ), true );
}
/**
* Display the admin notices for the plugins.
*
* @return void
*/
public function admin_notice_activitypub_not_enabled_for_post_type() {
// Get the current page.
$screen = get_current_screen();
// Check if we are on a edit page for the event, or on the settings page of the event plugin.
$is_event_plugins_edit_page = 'edit' === $screen->base && $this->event_plugin['post_type'] === $screen->post_type;
$is_event_plugins_settings_page = $this->event_plugin['settings_page_id'] === $screen->id;
if ( $is_event_plugins_edit_page || $is_event_plugins_settings_page ) {
$this->do_admin_notice_post_type_not_activitypub_enabled( $this->event_plugin['plugin_file'] );
public function admin_notice_activitypub_not_enabled_for_post_type(): void {
if ( $this->event_plugin::is_plugin_page() ) {
$this->do_admin_notice_post_type_not_activitypub_enabled();
}
}
/**
* Print admin notice that the current post type is not enabled in the ActivityPub plugin.
*
* @param string $event_plugin_file The event plugin file path.
* @return void
*/
private function do_admin_notice_post_type_not_activitypub_enabled( $event_plugin_file ) {
$event_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $event_plugin_file );
private function do_admin_notice_post_type_not_activitypub_enabled(): void {
$event_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $this->event_plugin::get_plugin_file() );
$activitypub_plugin_data = get_plugin_data( ACTIVITYPUB_PLUGIN_FILE );
$notice = sprintf(
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */
_x(
'You have installed the <i>%1$s</i> plugin, but the event post type of the plugin <i>%2$s</i> is <b>not enabled</b> in the <a href="%3$s">%1$s settings</a>.',
'admin notice',
'activitypub-event-extensions'
'activitypub-event-bridge'
),
esc_html( $activitypub_plugin_data['Name'] ),
esc_html( $event_plugin_data['Name'] ),

View file

@ -4,11 +4,15 @@
*
* Notices for guiding to proper configuration of this plugin.
*
* @package Activitypub_Event_Extensions
* @package ActivityPub_Event_Bridge
* @since 1.0.0
* @license AGPL-3.0-or-later
*/
namespace Activitypub_Event_Extensions\Admin;
namespace ActivityPub_Event_Bridge\Admin;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
/**
* Class responsible for general admin notices.
@ -25,7 +29,7 @@ class General_Admin_Notices {
*/
const ACTIVITYPUB_PLUGIN_URL = 'https://wordpress.org/plugins/activitypub';
const ACTIVITYPUB_EVENT_EXTENSIONS_SUPPORTED_EVENT_PLUGINS_URL = 'https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-extensions#events-plugin-that-will-be-supported-at-first';
const ACTIVITYPUB_EVENT_BRIDGE_SUPPORTED_EVENT_PLUGINS_URL = 'https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-bridge#events-plugin-that-will-be-supported-at-first';
/**
* Allowed HTML for admin notices.
@ -48,14 +52,31 @@ class General_Admin_Notices {
*/
public static function get_admin_notice_activitypub_plugin_not_enabled(): string {
return sprintf(
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */
/* translators: 1: An URL that points to the ActivityPub plugin. */
_x(
'For the ActivityPub Event Extensions to work, you will need to install and activate the <a href="%1$s">ActivityPub</a> plugin.',
'For the ActivityPub Event Bridge to work, you will need to install and activate the <a href="%1$s">ActivityPub</a> plugin.',
'admin notice',
'activitypub-event-extensions'
'activitypub-event-bridge'
),
esc_html( self::ACTIVITYPUB_PLUGIN_URL )
);
}
/**
* Admin notice when the ActivityPub plugin version is too old.
*
* @return string
*/
public static function get_admin_notice_activitypub_plugin_version_too_old(): string {
return sprintf(
/* translators: 1: The name of the ActivityPub plugin. 2: The minimum required version number of the ActivityPub plugin. */
_x(
'Please upgrade your <a href="%1$s">ActivityPub</a> plugin. At least version %2$s is required for the ActivityPub Event Bridge to work.',
'admin notice',
'activitypub-event-bridge'
),
esc_html( self::ACTIVITYPUB_PLUGIN_URL ),
admin_url( 'options-general.php?page=activitypub&tab=settings' )
esc_html( ACTIVITYPUB_EVENT_BRIDGE_ACTIVITYPUB_PLUGIN_MIN_VERSION )
);
}
@ -66,15 +87,14 @@ class General_Admin_Notices {
*/
public static function get_admin_notice_no_supported_event_plugin_active(): string {
return sprintf(
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */
/* translators: 1: An URL to the list of supported event plugins. */
_x(
'The Plugin <i>ActivityPub Event Extensions</i> is of no use, because you do not have installed and activated a supported Event Plugin.
'The Plugin <i>ActivityPub Event Bridge</i> is of no use, because you do not have installed and activated a supported Event Plugin.
<br> For a list of supported Event Plugins see <a href="%1$s">here</a>.',
'admin notice',
'activitypub-event-extensions'
'activitypub-event-bridge'
),
esc_html( self::ACTIVITYPUB_EVENT_EXTENSIONS_SUPPORTED_EVENT_PLUGINS_URL ),
admin_url( 'options-general.php?page=activitypub&tab=settings' )
esc_html( self::ACTIVITYPUB_EVENT_BRIDGE_SUPPORTED_EVENT_PLUGINS_URL )
);
}
@ -83,17 +103,27 @@ class General_Admin_Notices {
*
* @return void
*/
public static function activitypub_plugin_not_enabled() {
public static function activitypub_plugin_not_enabled(): void {
$notice = self::get_admin_notice_activitypub_plugin_not_enabled();
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, self::ALLOWED_HTML ) . '</p></div>';
}
/**
* Warning if the plugin is Active and the ActivityPub plugins version is too old.
*
* @return void
*/
public static function activitypub_plugin_version_too_old(): void {
$notice = self::get_admin_notice_activitypub_plugin_version_too_old();
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, self::ALLOWED_HTML ) . '</p></div>';
}
/**
* Warning when no supported Even Plugin is installed and active.
*
* @return void
*/
public static function no_supported_event_plugin_active() {
public static function no_supported_event_plugin_active(): void {
$notice = self::get_admin_notice_no_supported_event_plugin_active();
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, self::ALLOWED_HTML ) . '</p></div>';
}

View file

@ -5,35 +5,39 @@
* This file contains the General class definition, which handles the "General" settings
* page for the ActivityPub Event Extension Plugin, providing options for configuring various general settings.
*
* @package Activitypub_Event_Extensions
* @package ActivityPub_Event_Bridge
* @since 1.0.0
*/
namespace Activitypub_Event_Extensions\Admin;
use Activitypub_Event_Extensions\Setup;
namespace ActivityPub_Event_Bridge\Admin;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use ActivityPub_Event_Bridge\Plugins\Event_Plugin;
use ActivityPub_Event_Bridge\Setup;
/**
* Class responsible for the ActivityPui Event Extension related Settings.
* Class responsible for the ActivityPub Event Extension related Settings.
*
* Class responsible for the ActivityPui Event Extension related Settings.
* Class which handles the "General" settings page for the ActivityPub Event Extension Plugin,
* providing options for configuring various general settings.
*
* @since 1.0.0
*/
class Settings_Page {
const STATIC = 'Activitypub_Event_Extensions\Admin\Settings_Page';
const STATIC = 'ActivityPub_Event_Bridge\Admin\Settings_Page';
const SETTINGS_SLUG = 'activitypub-event-extensions';
const SETTINGS_SLUG = 'activitypub-event-bridge';
/**
* Warning if the plugin is Active and the ActivityPub plugin is not.
*
* @return void
*/
public static function admin_menu() {
public static function admin_menu(): void {
\add_options_page(
'Activitypub Event Extension',
__( 'ActivityPub Events', 'activitypub_event_extensions' ),
__( 'ActivityPub Events', 'activitypub-event-bridge' ),
'manage_options',
self::SETTINGS_SLUG,
array( self::STATIC, 'settings_page' )
@ -45,9 +49,10 @@ class Settings_Page {
* It's called via apply_filter('plugin_action_links_' . PLUGIN_NAME).
*
* @param array $links Already added links.
*
* @return array Original links but with link to setting page added.
*/
public static function settings_link( $links ) {
public static function settings_link( $links ): array {
return array_merge(
$links,
array(
@ -59,36 +64,39 @@ class Settings_Page {
/**
* Receive the event categories (terms) used by the event plugin.
*
* @param array $event_plugin Contains info about a certain event plugin.
* @param Event_Plugin $event_plugin Contains info about a certain event plugin.
*
* @return array An array of Terms.
*/
private static function get_event_terms( $event_plugin ) {
if ( isset( $event_plugin['taxonomy'] ) ) {
private static function get_event_terms( $event_plugin ): array {
$taxonomy = $event_plugin::get_event_category_taxonomy();
if ( $taxonomy ) {
$event_terms = get_terms(
array(
'taxonomy' => $event_plugin['taxonomy'],
'taxonomy' => $taxonomy,
'hide_empty' => true,
)
);
return $event_terms;
return ! is_wp_error( $event_terms ) ? $event_terms : array();
} else {
return array();
}
}
/**
* Settings page.
* Preparing the data and loading the template for the settings page.
*
* @return void
*/
public static function settings_page() {
public static function settings_page(): void {
$plugin_setup = Setup::get_instance();
$event_plugins = $plugin_setup->get_active_event_plugins();
$event_terms = array();
foreach ( $event_plugins as $event_plugin_name => $events_plugin_info ) {
$event_terms = array_merge( $event_terms, self::get_event_terms( $events_plugin_info ) );
foreach ( $event_plugins as $event_plugin ) {
$event_terms = array_merge( $event_terms, self::get_event_terms( $event_plugin ) );
}
$args = array(
@ -96,6 +104,6 @@ class Settings_Page {
'event_terms' => $event_terms,
);
\load_template( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . 'templates/settings.php', true, $args );
\load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/settings.php', true, $args );
}
}

View file

@ -1,16 +1,17 @@
<?php
/**
* Class responsible for autoloading ActivityPub Event Extensions class files.
* Class responsible for autoloading ActivityPub Event Bridge class files.
*
* The Autoloader class is responsible for automatically loading class files as needed
* to ensure a clean and organized codebase. It maps class names to their corresponding
* file locations within the GatherPress plugin.
*
* @package Activitypub_Event_Extensions
* @package ActivityPub_Event_Bridge
* @since 1.0.0
* @license AGPL-3.0-or-later
*/
namespace Activitypub_Event_Extensions;
namespace ActivityPub_Event_Bridge;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
@ -33,8 +34,8 @@ class Autoloader {
public static function register(): void {
spl_autoload_register(
function ( $full_class ) {
$base_dir = ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . '/includes/';
$base = 'Activitypub_Event_Extensions\\';
$base_dir = ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . '/includes/';
$base = 'ActivityPub_Event_Bridge\\';
if ( strncmp( $full_class, $base, strlen( $base ) ) === 0 ) {
$maybe_uppercase = str_replace( $base, '', $full_class );

View file

@ -5,17 +5,17 @@
* This file contains the General class definition, which handles the "General" settings
* page for the ActivityPub Event Extension Plugin, providing options for configuring various general settings.
*
* @package Activitypub_Event_Extensions
* @package ActivityPub_Event_Bridge
* @since 1.0.0
*/
namespace Activitypub_Event_Extensions;
use Activitypub\Activity\Extended_Object\Event;
namespace ActivityPub_Event_Bridge;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Activitypub\Activity\Extended_Object\Event;
/**
* Class responsible for the ActivityPui Event Extension related Settings.
*
@ -24,42 +24,84 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
* @since 1.0.0
*/
class Settings {
const STATIC = 'Activitypub_Event_Extensions\Admin\Settings_Page';
const SETTINGS_SLUG = 'activitypub-event-extensions';
const SETTINGS_SLUG = 'activitypub-event-bridge';
/**
* Register the settings for the ActivityPub Event Extensions plugin.
* The default ActivityPub event category.
*
* @var string
*/
public static function register_settings() {
const DEFAULT_EVENT_CATEGORY = 'MEETING';
/**
* Register the settings for the ActivityPub Event Bridge plugin.
*
* @return void
*/
public static function register_settings(): void {
\register_setting(
'activitypub-event-extensions',
'activitypub_event_extensions_default_event_category',
'activitypub-event-bridge',
'activitypub_event_bridge_default_event_category',
array(
'type' => 'string',
'description' => \__( 'Define your own custom post template', 'activitypub' ),
'show_in_rest' => true,
'default' => 'MEETING',
'type' => 'string',
'description' => \__( 'Define your own custom post template', 'activitypub' ),
'show_in_rest' => true,
'default' => self::DEFAULT_EVENT_CATEGORY,
'sanitize_callback' => array( self::class, 'sanitize_mapped_event_category' ),
)
);
\register_setting(
'activitypub-event-extensions',
'activitypub_event_extensions_event_category_mappings',
'activitypub-event-bridge',
'activitypub_event_bridge_event_category_mappings',
array(
'type' => 'array',
'description' => \__( 'Define your own custom post template', 'activitypub' ),
'default' => array(),
'sanitize_callback' => function ( $event_category_mappings ) {
$allowed_mappings = Event::DEFAULT_EVENT_CATEGORIES;
foreach ( $event_category_mappings as $key => $value ) {
if ( ! in_array( $value, $allowed_mappings, true ) ) {
unset( $event_category_mappings[ $key ] );
}
}
return $event_category_mappings;
},
'sanitize_callback' => array( self::class, 'sanitize_event_category_mappings' ),
)
);
}
/**
* Sanitize the target ActivityPub Event category.
*
* @param string $event_category The ActivityPUb event category.
*/
public static function sanitize_mapped_event_category( $event_category ): string {
return self::is_allowed_event_category( $event_category ) ? $event_category : self::DEFAULT_EVENT_CATEGORY;
}
/**
* Sanitization function for the event category mapping setting.
*
* Currently only the default event categories are allowed to be target of a mapping.
*
* @param array $event_category_mappings The settings value.
*
* @return array An array that contains only valid mapping pairs.
*/
public static function sanitize_event_category_mappings( $event_category_mappings ): array {
if ( empty( $event_category_mappings ) ) {
return array();
}
foreach ( $event_category_mappings as $taxonomy_slug => $event_category ) {
if ( ! self::is_allowed_event_category( $event_category ) ) {
unset( $event_category_mappings[ $taxonomy_slug ] );
}
}
return $event_category_mappings;
}
/**
* Checks if the given event category is allowed to be target of a mapping.
*
* @param string $event_category The event category to check.
*
* @return bool True if allowed, false otherwise.
*/
private static function is_allowed_event_category( $event_category ): bool {
$allowed_event_categories = Event::DEFAULT_EVENT_CATEGORIES;
return in_array( $event_category, $allowed_event_categories, true );
}
}

View file

@ -1,61 +1,35 @@
<?php
/**
* Class responsible for initializing ActivityPub Event Extensions.
* Class responsible for initializing ActivityPub Event Bridge.
*
* The setup class provides function for checking if this plugin should be activated.
* It detects supported event plugins and provides all setup hooks and filters.
*
* @package Activitypub_Event_Extensions
* @package ActivityPub_Event_Bridge
* @since 1.0.0
* @license AGPL-3.0-or-later
*/
namespace Activitypub_Event_Extensions;
use Activitypub_Event_Extensions\Admin\Event_Plugin_Admin_Notices;
use Activitypub_Event_Extensions\Admin\General_Admin_Notices;
use Activitypub_Event_Extensions\Admin\Settings_Page;
namespace ActivityPub_Event_Bridge;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use ActivityPub_Event_Bridge\Admin\Event_Plugin_Admin_Notices;
use ActivityPub_Event_Bridge\Admin\General_Admin_Notices;
use ActivityPub_Event_Bridge\Admin\Settings_Page;
use ActivityPub_Event_Bridge\Plugins\Event_Plugin;
require_once ABSPATH . 'wp-admin/includes/plugin.php';
/**
* Class Setup.
*
* This class is responsible for initializing ActivityPub Event Extensions.
* This class is responsible for initializing ActivityPub Event Bridge.
*
* @since 1.0.0
*/
class Setup {
const SUPPORTED_EVENT_PLUGINS = array(
'events_manager' => array(
'plugin_file' => 'events-manager/events-manager.php',
'post_type' => 'event',
'settings_page' => 'options-general.php?page=vsel',
'transformer_class' => 'Events_Manager',
),
'gatherpress' => array(
'plugin_file' => 'gatherpress/gatherpress.php',
'post_type' => 'gatherpress_event',
'transformer_class' => 'GatherPress',
'settings_page_id' => 'gatherpress_general',
),
'the_events_calendar' => array(
'plugin_file' => 'the-events-calendar/the-events-calendar.php',
'post_type' => 'tribe_events',
'transformer_class' => 'Tribe',
'settings_page_id' => 'tribe_general',
),
'vsel' => array(
'plugin_file' => 'very-simple-event-list/vsel.php',
'post_type' => 'event',
'settings_page_id' => 'settings_page_vsel',
'transformer_class' => 'VS_Event',
'taxonomy' => 'event_cat',
),
);
/**
* Keep the information whether the ActivityPub plugin is active.
*
@ -63,10 +37,17 @@ class Setup {
*/
protected $activitypub_plugin_is_active = false;
/**
* Keep the current version of the current ActivityPub plugin.
*
* @var string
*/
protected $activitypub_plugin_version = '';
/**
* Holds an array of the currently activated supported event plugins.
*
* @var array
* @var Event_Plugin[]
*/
protected $active_event_plugins = array();
@ -78,8 +59,15 @@ class Setup {
* @since 1.0.0
*/
protected function __construct() {
$this->activitypub_plugin_is_active = is_plugin_active( 'activitypub/activitypub.php' );
$this->active_event_plugins = self::detect_supported_event_plugins();
$this->activitypub_plugin_is_active = defined( 'ACTIVITYPUB_PLUGIN_VERSION' ) ||
is_plugin_active( 'activitypub/activitypub.php' );
// BeforeFirstRelease: decide whether we want to do anything at all when ActivityPub plugin is note active.
// if ( ! $this->activitypub_plugin_is_active ) {
// deactivate_plugins( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE );
// return;
// }.
$this->active_event_plugins = self::detect_active_event_plugins();
$this->activitypub_plugin_version = self::get_activitypub_plugin_version();
$this->setup_hooks();
}
@ -109,27 +97,58 @@ class Setup {
}
/**
* Function that checks for supported activated event plugins.
* LooksUp the current version of the ActivityPub.
*
* @return array List of supported event plugins as keys from the SUPPORTED_EVENT_PLUGINS const.
* @return string The semantic Version.
*/
public static function detect_supported_event_plugins(): array {
$active_event_plugins = array();
foreach ( self::SUPPORTED_EVENT_PLUGINS as $event_plugin_key => $event_plugin ) {
if ( \is_plugin_active( $event_plugin['plugin_file'] ) ) {
$active_event_plugins[ $event_plugin_key ] = $event_plugin;
}
private static function get_activitypub_plugin_version(): string {
if ( defined( 'ACTIVITYPUB_PLUGIN_VERSION' ) ) {
return constant( 'ACTIVITYPUB_PLUGIN_VERSION' );
}
return $active_event_plugins;
$version = get_file_data( WP_PLUGIN_DIR . '/activitypub/activitypub.php', array( 'Version' ) )[0];
return $version ?? '0.0.0';
}
/**
* Getter function for the active event plugins.
*
* @return Event_Plugin[]
*/
public function get_active_event_plugins() {
return $this->active_event_plugins;
}
/**
* Holds all the classes for the supported event plugins.
*
* @var array
*/
private const EVENT_PLUGIN_CLASSES = array(
'\ActivityPub_Event_Bridge\Plugins\Events_Manager',
'\ActivityPub_Event_Bridge\Plugins\GatherPress',
'\ActivityPub_Event_Bridge\Plugins\The_Events_Calendar',
'\ActivityPub_Event_Bridge\Plugins\VS_Event_List',
);
/**
* Function that checks for supported activated event plugins.
*
* @return array List of supported event plugins as keys from the SUPPORTED_EVENT_PLUGINS const.
*/
public static function detect_active_event_plugins(): array {
$active_event_plugins = array();
foreach ( self::EVENT_PLUGIN_CLASSES as $event_plugin_class ) {
if ( ! class_exists( $event_plugin_class ) || ! method_exists( $event_plugin_class, 'get_plugin_file' ) ) {
continue;
}
$event_plugin_file = call_user_func( array( $event_plugin_class, 'get_plugin_file' ) );
if ( \is_plugin_active( $event_plugin_file ) ) {
$active_event_plugins[] = new $event_plugin_class();
}
}
return $active_event_plugins;
}
/**
* Set up hooks for various purposes.
@ -141,7 +160,7 @@ class Setup {
* @return void
*/
protected function setup_hooks(): void {
register_activation_hook( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE, array( $this, 'activate' ) );
register_activation_hook( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE, array( $this, 'activate' ) );
add_action( 'admin_init', array( $this, 'do_admin_notices' ) );
add_action( 'admin_init', array( Settings::class, 'register_settings' ) );
@ -156,9 +175,15 @@ class Setup {
add_action( 'admin_menu', array( Settings_Page::class, 'admin_menu' ) );
add_filter(
'plugin_action_links_' . ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_BASENAME,
'plugin_action_links_' . ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_BASENAME,
array( Settings_Page::class, 'settings_link' )
);
// Check if the minimum required version of the ActivityPub plugin is installed.
if ( ! version_compare( $this->activitypub_plugin_version, ACTIVITYPUB_EVENT_BRIDGE_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) {
return;
}
add_filter( 'activitypub_transformer', array( $this, 'register_activitypub_event_transformer' ), 10, 3 );
}
@ -166,17 +191,19 @@ class Setup {
* Add the CSS for the admin pages.
*
* @param string $hook_suffix The suffix of the hook.
*
* @return void
*/
public static function enqueue_styles( $hook_suffix ) {
if ( false !== strpos( $hook_suffix, 'activitypub-event-extensions' ) ) {
public static function enqueue_styles( $hook_suffix ): void {
if ( false !== strpos( $hook_suffix, 'activitypub-event-bridge' ) ) {
wp_enqueue_style(
'activitypub-event-extensions-admin-styles',
'activitypub-event-bridge-admin-styles',
plugins_url(
'assets/css/activitypub-event-extensions-admin.css',
ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE
'assets/css/activitypub-event-bridge-admin.css',
ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE
),
array(),
ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_VERSION
ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_VERSION
);
}
}
@ -189,14 +216,17 @@ class Setup {
new Event_Plugin_Admin_Notices( $event_plugin );
}
// Check if any general admin notices are needed and add actions to insert the needed admin notices.
if ( ! $this->activitypub_plugin_is_active ) {
// The ActivityPub plugin is not active.
add_action( 'admin_notices', array( 'Activitypub_Event_Extensions\Admin\General_Admin_Notices', 'activitypub_plugin_not_enabled' ), 10, 1 );
add_action( 'admin_notices', array( 'ActivityPub_Event_Bridge\Admin\General_Admin_Notices', 'activitypub_plugin_not_enabled' ), 10, 1 );
}
if ( ! version_compare( $this->activitypub_plugin_version, ACTIVITYPUB_EVENT_BRIDGE_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) {
// The ActivityPub plugin is too old.
add_action( 'admin_notices', array( 'ActivityPub_Event_Bridge\Admin\General_Admin_Notices', 'activitypub_plugin_version_too_old' ), 10, 1 );
}
if ( empty( $this->active_event_plugins ) ) {
// No supported Event Plugin is active.
add_action( 'admin_notices', array( 'Activitypub_Event_Extensions\Admin\General_Admin_Notices', 'no_supported_event_plugin_active' ), 10, 1 );
add_action( 'admin_notices', array( 'ActivityPub_Event_Bridge\Admin\General_Admin_Notices', 'no_supported_event_plugin_active' ), 10, 1 );
}
}
@ -217,9 +247,11 @@ class Setup {
// Get the transformer for a specific event plugins event-post type.
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, $event_plugin['taxonomy'] );
if ( $wp_object->post_type === $event_plugin->get_post_type() ) {
$transformer_class = $event_plugin::get_activitypub_event_transformer_class();
if ( class_exists( $transformer_class ) ) {
return new $transformer_class( $wp_object, $event_plugin::get_event_category_taxonomy() );
}
}
}
@ -228,18 +260,37 @@ class Setup {
}
/**
* Activates the ActivityPub Event Extensions plugin.
*
* This method handles the activation of the ActivityPub Event Extensions plugin.
* Activates ActivityPub support for all active event plugins event post-types.
*
* @since 1.0.0
*
* @return void
*/
public function activate() {
public function activate_activitypub_support_for_active_event_plugins(): void {
// If someone installs this plugin, we simply enable ActivityPub support for all currently active event post types.
$activitypub_supported_post_types = get_option( 'activitypub_support_post_types', array() );
foreach ( $this->active_event_plugins as $event_plugin ) {
if ( ! in_array( $event_plugin->get_post_type(), $activitypub_supported_post_types, true ) ) {
$activitypub_supported_post_types[] = $event_plugin->get_post_type();
add_post_type_support( $event_plugin->get_post_type(), 'activitypub' );
}
}
update_option( 'activitypub_support_post_types', $activitypub_supported_post_types );
}
/**
* Activates the ActivityPub Event Bridge plugin.
*
* This method handles the activation of the ActivityPub Event Bridge plugin.
*
* @since 1.0.0
*
* @return void
*/
public function activate(): void {
// Don't allow plugin activation, when the ActivityPub plugin is not activated yet.
if ( ! $this->activitypub_plugin_is_active ) {
deactivate_plugins( plugin_basename( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE ) );
deactivate_plugins( plugin_basename( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE ) );
$notice = General_Admin_Notices::get_admin_notice_activitypub_plugin_not_enabled();
wp_die(
wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ),
@ -249,7 +300,7 @@ class Setup {
}
if ( empty( $this->active_event_plugins ) ) {
deactivate_plugins( plugin_basename( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE ) );
deactivate_plugins( plugin_basename( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE ) );
$notice = General_Admin_Notices::get_admin_notice_no_supported_event_plugin_active();
wp_die(
wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ),
@ -257,13 +308,7 @@ class Setup {
array( 'back_link' => true ),
);
}
// If someone installs this plugin, we simply enable ActivityPub support for all currently active event post types.
$activitypub_supported_post_types = get_option( 'activitypub_support_post_types', array() );
foreach ( $this->active_event_plugins as $event_plugin ) {
if ( ! in_array( $event_plugin['post_type'], $activitypub_supported_post_types, true ) ) {
$activitypub_supported_post_types[] = $event_plugin['post_type'];
}
}
update_option( 'activitypub_support_post_types', $activitypub_supported_post_types );
self::activate_activitypub_support_for_active_event_plugins();
}
}

View file

@ -0,0 +1,47 @@
<?php
/**
* File responsible for defining the event category strings.
*
* @package ActivityPub_Event_Bridge
* @since 1.0.0
* @license AGPL-3.0-or-later
*/
namespace ActivityPub_Event_Bridge;
define(
'ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES',
array(
'ARTS' => __( 'Arts', 'activitypub-event-bridge' ),
'BOOK_CLUBS' => __( 'Book clubs', 'activitypub-event-bridge' ),
'BUSINESS' => __( 'Business', 'activitypub-event-bridge' ),
'CAUSES' => __( 'Causes', 'activitypub-event-bridge' ),
'COMEDY' => __( 'Comedy', 'activitypub-event-bridge' ),
'CRAFTS' => __( 'Crafts', 'activitypub-event-bridge' ),
'FOOD_DRINK' => __( 'Food & Drink', 'activitypub-event-bridge' ),
'HEALTH' => __( 'Health', 'activitypub-event-bridge' ),
'MUSIC' => __( 'Music', 'activitypub-event-bridge' ),
'AUTO_BOAT_AIR' => __( 'Auto, boat and air', 'activitypub-event-bridge' ),
'COMMUNITY' => __( 'Community', 'activitypub-event-bridge' ),
'FAMILY_EDUCATION' => __( 'Family & Education', 'activitypub-event-bridge' ),
'FASHION_BEAUTY' => __( 'Fashion & Beauty', 'activitypub-event-bridge' ),
'FILM_MEDIA' => __( 'Film & Media', 'activitypub-event-bridge' ),
'GAMES' => __( 'Games', 'activitypub-event-bridge' ),
'LANGUAGE_CULTURE' => __( 'Language & Culture', 'activitypub-event-bridge' ),
'LEARNING' => __( 'Learning', 'activitypub-event-bridge' ),
'LGBTQ' => __( 'LGBTQ', 'activitypub-event-bridge' ),
'MOVEMENTS_POLITICS' => __( 'Movements and politics', 'activitypub-event-bridge' ),
'NETWORKING' => __( 'Networking', 'activitypub-event-bridge' ),
'PARTY' => __( 'Party', 'activitypub-event-bridge' ),
'PERFORMING_VISUAL_ARTS' => __( 'Performing & Visual Arts', 'activitypub-event-bridge' ),
'PETS' => __( 'Pets', 'activitypub-event-bridge' ),
'PHOTOGRAPHY' => __( 'Photography', 'activitypub-event-bridge' ),
'OUTDOORS_ADVENTURE' => __( 'Outdoors & Adventure', 'activitypub-event-bridge' ),
'SPIRITUALITY_RELIGION_BELIEFS' => __( 'Spirituality, Religion & Beliefs', 'activitypub-event-bridge' ),
'SCIENCE_TECH' => __( 'Science & Tech', 'activitypub-event-bridge' ),
'SPORTS' => __( 'Sports', 'activitypub-event-bridge' ),
'THEATRE' => __( 'Theatre', 'activitypub-event-bridge' ),
'MEETING' => __( 'Meeting', 'activitypub-event-bridge' ), // Default value in federation.
'DEFAULT' => __( 'Default', 'activitypub-event-bridge' ), // Internal default for overrides.
),
);

View file

@ -0,0 +1,76 @@
<?php
/**
* Interface for defining supported Event Plugins.
*
* Basic information that each supported event needs for this plugin to work.
*
* @package ActivityPub_Event_Bridge
* @since 1.0.0
*/
namespace ActivityPub_Event_Bridge\Plugins;
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
/**
* Interface for a supported event plugin.
*
* This interface defines which information is necessary for a supported event plugin.
*
* @since 1.0.0
*/
abstract class Event_Plugin {
/**
* Returns the full plugin file.
*
* @return string
*/
abstract public static function get_plugin_file(): string;
/**
* Returns the event post type of the plugin.
*
* @return string
*/
abstract public static function get_post_type(): string;
/**
* Returns the taxonomy used for the plugin's event categories.
*
* @return string
*/
abstract public static function get_event_category_taxonomy(): string;
/**
* Returns the ID of the main settings page of the plugin.
*
* @return string The settings page url.
*/
public static function get_settings_page(): string {
return '';
}
/**
* Detects whether the current screen is a admin page of the event plugin.
*/
public static function is_plugin_page(): bool {
// Get the current page.
$screen = get_current_screen();
// Check if we are on a edit page for the event, or on the settings page of the event plugin.
$is_event_plugins_edit_page = 'edit' === $screen->base && static::get_post_type() === $screen->post_type;
$is_event_plugins_settings_page = static::get_settings_page() === $screen->id;
return $is_event_plugins_edit_page || $is_event_plugins_settings_page;
}
/**
* Returns the Activitypub transformer for the event plugins event post type.
*/
public static function get_activitypub_event_transformer_class(): string {
return str_replace( 'Plugins', 'Activitypub\Transformer', static::class );
}
}

View file

@ -0,0 +1,60 @@
<?php
/**
* Events Manager.
*
* Defines all the necessary meta information for the Events Manager WordPress Plugin.
*
* @link https://wordpress.org/plugins/events-manager/
* @package ActivityPub_Event_Bridge
* @since 1.0.0
*/
namespace ActivityPub_Event_Bridge\Plugins;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
/**
* Interface for a supported event plugin.
*
* This interface defines which information is necessary for a supported event plugin.
*
* @since 1.0.0
*/
final class Events_Manager extends Event_Plugin {
/**
* Returns the full plugin file.
*
* @return string
*/
public static function get_plugin_file(): string {
return 'events-manager/events-manager.php';
}
/**
* Returns the event post type of the plugin.
*
* @return string
*/
public static function get_post_type(): string {
return defined( 'EM_POST_TYPE_EVENT' ) ? constant( 'EM_POST_TYPE_EVENT' ) : 'event';
}
/**
* Returns the ID of the main settings page of the plugin.
*
* @return string The settings page url.
*/
public static function get_settings_page(): string {
return 'wp-admin/edit.php?post_type=event&page=events-manager-options#general';
}
/**
* Returns the taxonomy used for the plugin's event categories.
*
* @return string
*/
public static function get_event_category_taxonomy(): string {
return defined( 'EM_TAXONOMY_CATEGORY' ) ? constant( 'EM_TAXONOMY_CATEGORY' ) : 'event-categories';
}
}

View file

@ -0,0 +1,69 @@
<?php
/**
* GatherPress.
*
* Defines all the necessary meta information for the GatherPress plugin.
*
* @link https://wordpress.org/plugins/gatherpress/
* @package ActivityPub_Event_Bridge
* @since 1.0.0
*/
namespace ActivityPub_Event_Bridge\Plugins;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
/**
* Interface for a supported event plugin.
*
* This interface defines which information is necessary for a supported event plugin.
*
* @since 1.0.0
*/
final class GatherPress extends Event_Plugin {
/**
* Returns the full plugin file.
*
* @return string
*/
public static function get_plugin_file(): string {
return 'gatherpress/gatherpress.php';
}
/**
* Returns the event post type of the plugin.
*
* @return string
*/
public static function get_post_type(): string {
return class_exists( '\GatherPress\Core\Event' ) ? \GatherPress\Core\Event::POST_TYPE : 'gatherpress_event';
}
/**
* Returns the ID of the main settings page of the plugin.
*
* @return string The settings page url.
*/
public static function get_settings_page(): string {
return class_exists( '\GatherPress\Core\Utility' ) ? \GatherPress\Core\Utility::prefix_key( 'general' ) : 'gatherpress_general';
}
/**
* Returns the ActivityPub transformer class.
*
* @return string
*/
public static function get_activitypub_transformer_class_name(): string {
return 'GatherPress';
}
/**
* Returns the taxonomy used for the plugin's event categories.
*
* @return string
*/
public static function get_event_category_taxonomy(): string {
return class_exists( '\GatherPress\Core\Topic' ) ? \GatherPress\Core\Topic::TAXONOMY : 'gatherpress_topic';
}
}

View file

@ -0,0 +1,65 @@
<?php
/**
* The Events Calendar.
*
* Defines all the necessary meta information for the events calendar.
*
* @link https://wordpress.org/plugins/the-events-calendar/
* @package ActivityPub_Event_Bridge
* @since 1.0.0
*/
namespace ActivityPub_Event_Bridge\Plugins;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
/**
* Interface for a supported event plugin.
*
* This interface defines which information is necessary for a supported event plugin.
*
* @since 1.0.0
*/
final class The_Events_Calendar extends Event_plugin {
/**
* Returns the full plugin file.
*
* @return string
*/
public static function get_plugin_file(): string {
return 'the-events-calendar/the-events-calendar.php';
}
/**
* Returns the event post type of the plugin.
*
* @return string
*/
public static function get_post_type(): string {
return class_exists( '\Tribe__Events__Main' ) ? \Tribe__Events__Main::POSTTYPE : 'tribe_event';
}
/**
* Returns the ID of the main settings page of the plugin.
*
* @return string The settings page url.
*/
public static function get_settings_page(): string {
if ( class_exists( '\Tribe\Events\Admin\Settings' ) ) {
$page = \Tribe\Events\Admin\Settings::$settings_page_id;
} else {
$page = 'tec-events-settings';
}
return sprintf( 'edit.php?post_type=tribe_events&page=%s', $page );
}
/**
* Returns the taxonomy used for the plugin's event categories.
*
* @return string
*/
public static function get_event_category_taxonomy(): string {
return class_exists( '\Tribe__Events__Main' ) ? \Tribe__Events__Main::TAXONOMY : 'tribe_events_cat';
}
}

View file

@ -0,0 +1,72 @@
<?php
/**
* VS Events LIst.
*
* Defines all the necessary meta information for the WordPress event plugin
* "Very Simple Events List".
*
* @link https://de.wordpress.org/plugins/very-simple-event-list/
* @package ActivityPub_Event_Bridge
* @since 1.0.0
*/
namespace ActivityPub_Event_Bridge\Plugins;
use ActivityPub_Event_Bridge\Event_Plugins;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
/**
* Interface for a supported event plugin.
*
* This interface defines which information is necessary for a supported event plugin.
*
* @since 1.0.0
*/
final class VS_Event_List extends Event_Plugin {
/**
* Returns the full plugin file.
*
* @return string
*/
public static function get_plugin_file(): string {
return 'very-simple-event-list/vsel.php';
}
/**
* Returns the event post type of the plugin.
*
* @return string
*/
public static function get_post_type(): string {
return 'event';
}
/**
* Returns the ID of the main settings page of the plugin.
*
* @return string The settings page url.
*/
public static function get_settings_page(): string {
return 'settings_page_vsel';
}
/**
* Returns the ActivityPub transformer class.
*
* @return string
*/
public static function get_activitypub_transformer_class_name(): string {
return 'VS_Event';
}
/**
* Returns the taxonomy used for the plugin's event categories.
*
* @return string
*/
public static function get_event_category_taxonomy(): string {
return 'event_cat';
}
}

157
phpcs.xml Normal file
View file

@ -0,0 +1,157 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Example Project" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
<description>A custom set of rules to check for a WPized WordPress project</description>
<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset
#############################################################################
-->
<file>.</file>
<!-- Exclude WP Core folders and files from being checked. -->
<exclude-pattern>/docroot/wp-admin/*</exclude-pattern>
<exclude-pattern>/docroot/wp-includes/*</exclude-pattern>
<exclude-pattern>/docroot/wp-*.php</exclude-pattern>
<exclude-pattern>/docroot/index.php</exclude-pattern>
<exclude-pattern>/docroot/xmlrpc.php</exclude-pattern>
<exclude-pattern>/docroot/wp-content/plugins/*</exclude-pattern>
<!-- Exclude the Composer Vendor directory. -->
<exclude-pattern>/vendor/*</exclude-pattern>
<!-- Exclude the Node Modules directory. -->
<exclude-pattern>/node_modules/*</exclude-pattern>
<!-- Exclude minified Javascript files. -->
<exclude-pattern>*.min.js</exclude-pattern>
<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="."/>
<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>
<!--
#############################################################################
SET UP THE RULESETS
#############################################################################
-->
<!-- Include the WordPress-Extra standard. -->
<rule ref="WordPress-Extra">
<!--
We may want a middle ground though. The best way to do this is add the
entire ruleset, then rule by rule, remove ones that don't suit a project.
We can do this by running `phpcs` with the '-s' flag, which allows us to
see the names of the sniffs reporting errors.
Once we know the sniff names, we can opt to exclude sniffs which don't
suit our project like so.
The below two examples just show how you can exclude rules/error codes.
They are not intended as advice about which sniffs to exclude.
-->
<!--
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing"/>
<exclude name="Modernize.FunctionCalls.Dirname.Nested"/>
-->
</rule>
<!-- Let's also check that everything is properly documented. -->
<rule ref="WordPress-Docs"/>
<!-- Add in some extra rules from other standards. -->
<rule ref="Generic.Commenting.Todo"/>
<!-- Check for PHP cross-version compatibility. -->
<!--
To enable this, the PHPCompatibilityWP standard needs
to be installed.
See the readme for installation instructions:
https://github.com/PHPCompatibility/PHPCompatibilityWP
For more information, also see:
https://github.com/PHPCompatibility/PHPCompatibility
-->
<!--
<config name="testVersion" value="5.6-"/>
<rule ref="PHPCompatibilityWP">
<include-pattern>*\.php</include-pattern>
</rule>
-->
<!--
#############################################################################
SNIFF SPECIFIC CONFIGURATION
#############################################################################
-->
<!--
To get the optimal benefits of using WordPressCS, we should add a couple of
custom properties.
Adjust the values of these properties to fit our needs.
For information on additional custom properties available, check out
the wiki:
https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties
-->
<config name="minimum_wp_version" value="6.6"/>
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="activitypub-event-bridge"/>
<element value="activitypub"/>
</property>
</properties>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="prefixes" type="array">
<element value="ACTIVITYPUB_EVENT_BRIDGE"/>
</property>
</properties>
</rule>
<!--
#############################################################################
SELECTIVE EXCLUSIONS
Exclude specific files for specific sniffs and/or exclude sub-groups in sniffs.
#############################################################################
-->
<!--
Sometimes, you may want to exclude a certain directory, like your tests,
for select sniffs.
The below examples demonstrate how to do this.
In the example, the `GlobalVariablesOverride` rule is excluded for test files
as it is sometimes necessary to overwrite WP globals in test situations (just
don't forget to restore them after the test!).
Along the same lines, PHPUnit is getting stricter about using PSR-4 file names,
so excluding test files from the `WordPress.Files.Filename` sniff can be a
legitimate exclusion.
For more information on ruleset configuration options, check out the PHPCS wiki:
https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset
-->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<exclude-pattern>tests/*.php</exclude-pattern>
<exclude-pattern>templates/*.php</exclude-pattern>
</rule>
<rule ref="WordPress.WP.GlobalVariablesOverride">
<exclude-pattern>tests/*.php</exclude-pattern>
</rule>
<rule ref="WordPress.Files.FileName">
<exclude-pattern>tests/*.php</exclude-pattern>
</rule>
</ruleset>

15
phpunit.xml Normal file
View file

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="testing">
<directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>

View file

@ -1,53 +1,83 @@
=== ActivityPub Event Extensions ===
Contributors: menrath
Tags: events, fediverse, activitypub, activitystreams
Requires at least: 5.5
Tested up to: 6.4
Stable tag: 1.0.0
Requires PHP: 7.4
=== ActivityPub Event Bridge ===
Contributors: andremenrath
Tags: events, fediverse, activitypub, calendar
Requires at least: 6.5
Tested up to: 6.6
Stable tag: 0.1.0
Requires PHP: 8.1
License: AGPL-3.0-or-later
License URI: https://www.gnu.org/licenses/agpl-3.0.html
The ActivityPub Event Extensions
Integrating popular event plugins with the ActivityPub plugin.
== Description ==
With this event others can automatically aggregate and display events published on your website!
Additionally, people who do not want to miss on of your events will not have to follow a social-media account of yours that you maintain on the website of another party (and thereby you push the people to use these platforms), but could just follow your website directly.
Following like in social media, including all features you know like boosting, liking or commenting.
And the best: as you already publish events on your website, this means no extra work for you.
In the long term it actually might lead to less work and you help to provide a momentum to become independent of commercial platforms like Facebook and co.
For more details read our detailed project description.
Make your events more discoverable, expand your reach effortlessly while being independent of other (commercial) platforms, and be a part of the growing decentralized web (the Fediverse).
With the ActivityPub Event Bridge Plugin for WordPress, your events can be automatically followed, aggregated and displayed across decentralized platforms like [Mastodon](https://joinmastodon.org) or [Gancio](https://gancio.org), without any extra work.
Forget the hassle of managing multiple social media accounts just to keep your audience informed.
This plugin is not an event managing plugin but an add-on to popular event plugins. It extends their functionality to fully support the [ActivityPub plugin](https://wordpress.org/plugins/activitypub/).
With the ActivityPub plugin people can follow your website directly and engage with your events just as they would on social media: liking, boosting and even commenting if you enable it.
You retain full ownership of your content. By integrating into your existing setup, it ensures no extra work is needed while enhancing your events' visibility across the web.
= How It Works =
With the ActivityPub Event Bridge WordPress plugin, sharing your events is effortless and automatic!
Once you create an event on your WordPress site, it is seamlessly shared across the decentralized web using the ActivityPub protocol.
![](./.wordpress-org/event-activitypub-publishing.gif)
Your events can be automatically delivered to platforms that fully support events, such as [Mobilizon](https://joinmobilizon.org/), [Gancio](https://gancio.org), [Friendica](https://friendi.ca), [Hubzilla](https://hubzilla.org), and [Pleroma](https://pleroma.social/).
These platforms create public event calendars by pulling in events from various sources, including your website. Any updates you make to your events are synced across these platforms—so you only need to manage your events on your own site, with no extra work required.
![](./.wordpress-org/decentralized-event-calenders.gif)
== Installation ==
This plugin depends on the ActivityPub plugin. Furthermore you need to use one of the supported Event Plugins. See below.
This plugin depends on the [ActivityPub plugin](https://wordpress.org/plugins/activitypub/). Additionally, you need to use one of the supported event Plugins.
== Supported Event Plugins ==
= Supported Event Plugins =
* [The Events Calendar](https://de.wordpress.org/plugins/the-events-calendar/)
* [VS Event List](https://de.wordpress.org/plugins/very-simple-event-list/)
* [Events Manager](https://de.wordpress.org/plugins/events-manager/)
* [GatherPress](https://github.com/GatherPress/gatherpress)
== Configuration ==
At first be sure to spend some minutes reading the Documentation of the ActivityPub plugin](https://wordpress.org/plugins/activitypub/), in case you have not used it before.
TODO
If youre new to the [ActivityPub plugin](https://wordpress.org/plugins/activitypub/), its recommended to spend a few minutes reading through its documentation to familiarize yourself with its setup and functionality.
== Frequently Asked Questions ==
= Do I need to install another event plugin to use the Event Federation Plugin? =
Yes, this plugin works as an add-on and requires both the ActivityPub plugin and a supported event plugin such as The Events Calendar, VS Event List, or Events Manager to manage your events.
= What platforms can follow my events? =
Your events can be followed on platforms that support ActivityPub like [Mobilizon](https://joinmobilizon.org/), [Gancio](https://gancio.org), [Friendica](https://friendi.ca), [Hubzilla](https://hubzilla.org), and [Pleroma](https://pleroma.social/). Even other applications like [Mastodon](https://joinmastodon.org), which dont fully support events yet, will display all important information about the events.
= How much extra work is required to maintain my events across the decentralized Web? =
None! Once the plugin is set up, your events are automatically sent to all connected platforms or account that follow you (your Website). Any updates you make to your events are synced without additional effort.
= Can I still use social media to promote my events? =
Yes, you can still use traditional social media if you wish. However, this plugin helps reduce reliance on commercial platforms by connecting your events to the decentralized Fediverse.
= Will this plugin work if I don't use the ActivityPub plugin? =
No, the Event Federation Plugin depends on the [ActivityPub plugin](https://wordpress.org/plugins/activitypub/) to deliver your events across decentralized platforms, so it's essential to have it installed and configured.
= My event plugin is not supported, what can I do? =
If you know about coding have a look at the documentation of how to add your plugin or open an [issue](https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-extensions/issues), if we can spare some free hours we might add it.
If you know about coding have a look at the documentation of how to add your plugin or open an [issue](https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-bridge/issues), if we can spare some free hours we might add it.
= What if I experience problems? =
We're always interested in your feedback. Feel free to reach out to us via E-Mail or create an [issue](https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-extensions/issues).
We're always interested in your feedback. Feel free to reach out to us via [E-Mail](https://event-federation.eu/contact/) or create an [issue](https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-bridge/issues).
== Changelog ==
= [1.0.0] 2024-09-01 =
= [0.1.0] 2024-09-01 =
* Initial release
* Initial alpha release on WordPress.org

View file

@ -1,10 +1,10 @@
<?php
/**
* Template for ActivityPub Event Extensions settings page.
* Template for ActivityPub Event Bridge settings page.
*
* This template is used to display and manage settings for the ActivityPub Event Extensions plugin.
* This template is used to display and manage settings for the ActivityPub Event Bridge plugin.
*
* @package ActivityPub_Event_Extensions
* @package ActivityPub_Event_Bridge
* @since 1.0.0
*
* @param array $args An array of arguments for the settings page.
@ -25,65 +25,33 @@ if ( ! current_user_can( 'manage_options' ) ) {
$event_terms = $args['event_terms'];
$default_event_category_strings = array(
'ARTS' => __( 'Arts', 'activitypub-event-extensions' ),
'BOOK_CLUBS' => __( 'Book clubs', 'activitypub-event-extensions' ),
'BUSINESS' => __( 'Business', 'activitypub-event-extensions' ),
'CAUSES' => __( 'Causes', 'activitypub-event-extensions' ),
'COMEDY' => __( 'Comedy', 'activitypub-event-extensions' ),
'CRAFTS' => __( 'Crafts', 'activitypub-event-extensions' ),
'FOOD_DRINK' => __( 'Food & Drink', 'activitypub-event-extensions' ),
'HEALTH' => __( 'Health', 'activitypub-event-extensions' ),
'MUSIC' => __( 'Music', 'activitypub-event-extensions' ),
'AUTO_BOAT_AIR' => __( 'Auto, boat and air', 'activitypub-event-extensions' ),
'COMMUNITY' => __( 'Community', 'activitypub-event-extensions' ),
'FAMILY_EDUCATION' => __( 'Family & Education', 'activitypub-event-extensions' ),
'FASHION_BEAUTY' => __( 'Fashion & Beauty', 'activitypub-event-extensions' ),
'FILM_MEDIA' => __( 'Film & Media', 'activitypub-event-extensions' ),
'GAMES' => __( 'Games', 'activitypub-event-extensions' ),
'LANGUAGE_CULTURE' => __( 'Language & Culture', 'activitypub-event-extensions' ),
'LEARNING' => __( 'Learning', 'activitypub-event-extensions' ),
'LGBTQ' => __( 'LGBTQ', 'activitypub-event-extensions' ),
'MOVEMENTS_POLITICS' => __( 'Movements and politics', 'activitypub-event-extensions' ),
'NETWORKING' => __( 'Networking', 'activitypub-event-extensions' ),
'PARTY' => __( 'Party', 'activitypub-event-extensions' ),
'PERFORMING_VISUAL_ARTS' => __( 'Performing & Visual Arts', 'activitypub-event-extensions' ),
'PETS' => __( 'Pets', 'activitypub-event-extensions' ),
'PHOTOGRAPHY' => __( 'Photography', 'activitypub-event-extensions' ),
'OUTDOORS_ADVENTURE' => __( 'Outdoors & Adventure', 'activitypub-event-extensions' ),
'SPIRITUALITY_RELIGION_BELIEFS' => __( 'Spirituality, Religion & Beliefs', 'activitypub-event-extensions' ),
'SCIENCE_TECH' => __( 'Science & Tech', 'activitypub-event-extensions' ),
'SPORTS' => __( 'Sports', 'activitypub-event-extensions' ),
'THEATRE' => __( 'Theatre', 'activitypub-event-extensions' ),
'MEETING' => __( 'Meeting', 'activitypub-event-extensions' ), // Default value in federation.
'DEFAULT' => __( 'Default', 'activitypub-event-extensions' ), // Internal default for overrides.
);
require_once ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . '/includes/event-categories.php';
$selected_default_event_category = \get_option( 'activitypub_event_extensions_default_event_category', 'MEETING' );
$current_category_mapping = \get_option( 'activitypub_event_extensions_event_category_mappings', array() );
$selected_default_event_category = \get_option( 'activitypub_event_bridge_default_event_category', 'MEETING' );
$current_category_mapping = \get_option( 'activitypub_event_bridge_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>
<h1><?php \esc_html_e( 'ActivityPub Event Bridge', 'activitypub-event-bridge' ); ?></h1>
</div>
</div>
<hr class="wp-header-end">
<div class="activitypub-settings activitypub-settings-page hide-if-no-js">
<div class="activitypub-settings activitypub-settings-page activitypub-event-bridge-settings-page hide-if-no-js">
<form method="post" action="options.php">
<?php \settings_fields( 'activitypub-event-extensions' ); ?>
<?php \settings_fields( 'activitypub-event-bridge' ); ?>
<div class="box">
<h2> <?php esc_html_e( 'Default ActivityPub Event Category', 'activitypub-event-extensions' ); ?> </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.' ); ?> </p>
<h2> <?php esc_html_e( 'Default ActivityPub Event Category', 'activitypub-event-bridge' ); ?> </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.', 'activitypub-event-bridge' ); ?> </p>
<table class="form-table">
<tr>
<th scope="row"> <?php esc_html_e( 'Default Category', 'activitypub-event-extensions' ); ?> </th>
<th scope="row"> <?php esc_html_e( 'Default Category', 'activitypub-event-bridge' ); ?> </th>
<td>
<select id="activitypub_event_extensions_default_event_category" name="activitypub_event_extensions_default_event_category">';
<select id="activitypub_event_bridge_default_event_category" name="activitypub_event_bridge_default_event_category">';
<?php
foreach ( $default_event_category_strings as $value => $label ) {
foreach ( ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES as $value => $label ) {
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $selected_default_event_category, $value, false ) . '>' . esc_html( $label ) . '</option>';
}
?>
@ -93,15 +61,16 @@ $current_category_mapping = \get_option( 'activitypub_event_extensions_ev
</table>
</div>
<?php if ( ! empty( $event_terms ) ) : ?>
<div class="box">
<h2> <?php esc_html_e( 'Advanced Event Category Settings', 'activitypub-event-extensions' ); ?> </h2>
<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.' ); ?> </p>
<h2> <?php esc_html_e( 'Advanced Event Category Settings', 'activitypub-event-bridge' ); ?> </h2>
<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.', 'activitypub-event-bridge' ); ?> </p>
<table class="form-table">
<?php foreach ( $event_terms as $event_term ) { ?>
<tr>
<th scope="row"> <?php echo esc_html( $event_term->name ); ?> </th>
<td>
<select name="activitypub_event_extensions_event_category_mappings[<?php echo esc_attr( $event_term->slug ); ?>]">
<select name="activitypub_event_bridge_event_category_mappings[<?php echo esc_attr( $event_term->slug ); ?>]">
<?php
$current_mapping_is_set = false;
if ( ! empty( $current_category_mapping ) ) {
@ -113,13 +82,13 @@ $current_category_mapping = \get_option( 'activitypub_event_extensions_ev
$mapping = 'DEFAULT';
}
if ( 'DEFAULT' === $mapping ) {
echo '<option value="' . esc_attr( $mapping ) . '"> -- ' . esc_html( $default_event_category_strings[ $mapping ] ) . ' -- </option>';
echo '<option value="' . esc_attr( $mapping ) . '"> -- ' . esc_html( ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES[ $mapping ] ) . ' -- </option>';
} else {
echo '<option value="' . esc_attr( $mapping ) . '">' . esc_html( $default_event_category_strings[ $mapping ] ) . '</option>';
echo '<option value="' . esc_attr( $mapping ) . '">' . esc_html( ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES[ $mapping ] ) . '</option>';
}
echo '<option value="DEFAULT" ' . selected( $selected_default_event_category, 'DEFAULT', false ) . '> -- ' . esc_html__( 'Default', 'activitypub-event-extensions' ) . ' -- </option>';
echo '<option value="DEFAULT" ' . selected( $selected_default_event_category, 'DEFAULT', false ) . '> -- ' . esc_html__( 'Default', 'activitypub-event-bridge' ) . ' -- </option>';
foreach ( Event::DEFAULT_EVENT_CATEGORIES as $event_category ) {
echo '<option value="' . esc_attr( $event_category ) . '" ' . selected( $mappings[ $event_term->slug ] ?? '', $event_category, false ) . '>' . esc_html( $default_event_category_strings[ $event_category ] ) . '</option>';
echo '<option value="' . esc_attr( $event_category ) . '" ' . selected( $mappings[ $event_term->slug ] ?? '', $event_category, false ) . '>' . esc_html( ACTIVITYPUB_EVENT_BRIDGE_EVENT_CATEGORIES[ $event_category ] ) . '</option>';
}
?>
</select>
@ -128,6 +97,7 @@ $current_category_mapping = \get_option( 'activitypub_event_extensions_ev
<?php } ?>
</table>
</div>
<?php endif; ?>
<?php \submit_button(); ?>
</form>
</div>

87
tests/bootstrap.php Executable file
View file

@ -0,0 +1,87 @@
<?php
/**
* PHPUnit bootstrap file.
*
* @package ActivityPub_Event_Bridge
*/
$_tests_dir = getenv( 'WP_TESTS_DIR' );
if ( ! $_tests_dir ) {
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
}
// Forward custom PHPUnit Polyfills configuration to PHPUnit bootstrap file.
$_phpunit_polyfills_path = getenv( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' );
if ( false !== $_phpunit_polyfills_path ) {
define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', $_phpunit_polyfills_path );
}
if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) {
echo "Could not find {$_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
exit( 1 );
}
// Give access to tests_add_filter() function.
require_once "{$_tests_dir}/includes/functions.php";
/**
* Manually load the plugin being tested and its integrations.
*/
function _manually_load_plugin() {
$plugin_dir = ABSPATH . '/wp-content/plugins/';
// Always manually load the ActivityPub plugin.
require_once $plugin_dir . 'activitypub/activitypub.php';
// Capture the --filter argument.
$activitypub_event_extension_integration_filter = null;
foreach ( $_SERVER['argv'] as $arg ) {
if ( strpos( $arg, '--filter=' ) === 0 ) {
$activitypub_event_extension_integration_filter = substr( $arg, strlen( '--filter=' ) );
break;
}
}
$plugin_file = null;
// See if we want to run integration tests for a specific event-plugin.
switch ( $activitypub_event_extension_integration_filter ) {
case 'the_events_calendar':
$plugin_file = 'the-events-calendar/the-events-calendar.php';
break;
case 'vs_event_list':
$plugin_file = 'very-simple-event-list/vsel.php';
break;
case 'events_manager':
$plugin_file = 'events-manager/events-manager.php';
break;
case 'gatherpress':
$plugin_file = 'gatherpress/gatherpress.php';
break;
}
if ( $plugin_file ) {
// Manually load the event plugin.
require_once $plugin_dir . $plugin_file;
$current = get_option( 'active_plugins', array() );
$current[] = $plugin_file;
sort( $current );
update_option( 'active_plugins', $current );
}
// Hot fix that allows using Events Manager within unit tests, because the em_init() is later not run as admin.
if ( 'events_manager' === $activitypub_event_extension_integration_filter ) {
require_once $plugin_dir . 'events-manager/em-install.php';
em_create_events_table();
em_create_events_meta_table();
em_create_locations_table();
}
// At last manually load our WordPress plugin.
require dirname( __DIR__ ) . '/activitypub-event-bridge.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
// Start up the WP testing environment.
require "{$_tests_dir}/includes/bootstrap.php";

View file

@ -0,0 +1,184 @@
<?php
/**
* Class SampleTest
*
* @package ActivityPub_Event_Bridge
*/
/**
* Sample test case.
*/
class Test_Events_Manager extends WP_UnitTestCase {
/**
* Override the setup function, so that tests don't run if the Events Calendar is not active.
*/
public function set_up() {
parent::set_up();
if ( ! class_exists( 'EM_Events' ) ) {
self::markTestSkipped( 'VS Event List plugin is not active.' );
}
// For tests allow every user to create new events.
update_option( 'dbem_events_anonymous_submissions', true );
// Make sure that ActivityPub support is enabled for Events Manager.
$aec = \ActivityPub_Event_Bridge\Setup::get_instance();
$aec->activate_activitypub_support_for_active_event_plugins();
// Delete all posts afterwards.
_delete_all_posts();
}
/**
* Test that the right transformer gets applied.
*/
public function test_transformer_class() {
// We only test for one event plugin being active at the same time,
// even though we support multiple onces in theory.
// But testing all combinations is beyond scope.
$active_event_plugins = \ActivityPub_Event_Bridge\Setup::get_instance()->get_active_event_plugins();
$this->assertEquals( 1, count( $active_event_plugins ) );
// Enable ActivityPub support for the event plugin.
$this->assertContains( EM_POST_TYPE_EVENT, get_option( 'activitypub_support_post_types' ) );
// Insert a new Event.
$wp_post_id = wp_insert_post(
array(
'post_title' => 'Events Manager Test event',
'post_status' => 'publish',
'post_type' => EM_POST_TYPE_EVENT,
'meta_input' => array(
'event_start_time' => strtotime( '+10 days 15:00:00' ),
),
)
);
$wp_object = get_post( $wp_post_id );
// Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
// Check that we got the right transformer.
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Events_Manager::class, $transformer );
}
/**
* Test the transformation of a minimal event.
*/
public function test_transform_of_minimal_event() {
// Create mockup event.
$event = new EM_Event();
$event->event_name = 'Events Manager Test event';
$event->post_content = 'Event description';
$event->event_start_date = gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) );
$event->event_start_time = '15:00:00';
$event->start = strtotime( $event->event_start_date . ' ' . $event->event_start_time );
$event->force_status = 'publish';
$event->event_rsvp = false;
$this->assertTrue( $event->save() );
// Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->post_id ) )->to_object()->to_array();
// Check that we got the right transformer.
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Events Manager Test event', $event_array['name'] );
$this->assertEquals( 'Event description', wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( comments_open( $event->post_id ), $event_array['commentsEnabled'] );
$this->assertEquals( comments_open( $event->post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertArrayNotHasKey( 'location', $event_array );
$this->assertArrayNotHasKey( 'endTime', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] );
}
/**
* Test the transformation of a event with full location.
*/
public function test_transform_of__full_event_with_location() {
// Create a mockup location.
$location = new EM_Location();
$location->location_name = 'Test location';
$location->location_address = 'Test Address';
$location->location_town = 'Test Town';
$location->location_state = 'Test state';
$location->location_postcode = '1337';
$location->location_region = 'Test region';
$location->location_country = 'AT'; // Must be a two char country code.
$this->assertTrue( $location->save() );
// Create mockup event.
$event = new EM_Event();
$event->event_name = 'Events Manager Test event';
$event->post_content = 'Event description';
$event->location_id = $location->location_id;
$event->event_start_date = gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) );
$event->event_end_date = gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) );
$event->event_start_time = '15:00:00';
$event->event_end_time = '16:00:00';
$event->start = strtotime( $event->event_start_date . ' ' . $event->event_start_time );
$event->end = strtotime( $event->event_end_date . ' ' . $event->event_end_time );
$event->force_status = 'publish';
$event->event_rsvp = false;
$this->assertTrue( $event->save() );
// Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->post_id ) )->to_object()->to_array();
// Check that we got the right transformer.
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Events Manager Test event', $event_array['name'] );
$this->assertEquals( 'Event description', wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertEquals( 'MEETING', $event_array['category'] );
$this->assertArrayHasKey( 'location', $event_array );
$this->assertEquals( 'Test location', $event_array['location']['name'] );
$this->assertEquals( 'Test Address', $event_array['location']['address']['postalAddress'] );
$this->assertEquals( 'Test Town', $event_array['location']['address']['addressLocality'] );
$this->assertEquals( 'Test state', $event_array['location']['address']['addressRegion'] );
$this->assertEquals( '1337', $event_array['location']['address']['postalCode'] );
$this->assertEquals( 'AT', $event_array['location']['address']['addressCountry'] );
}
/**
* Test the transformation of a minimal event.
*/
public function test_transform_of_event_with_name_only_location() {
// Create a mockup location.
$location = new EM_Location();
$location->location_name = 'Name only location';
$this->assertTrue( $location->save() );
// Create mockup event.
$event = new EM_Event();
$event->event_name = 'Events Manager Test event';
$event->post_content = 'Event description';
$event->location_id = $location->location_id;
$event->event_start_date = gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) );
$event->event_end_date = gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) );
$event->event_start_time = '15:00:00';
$event->event_end_time = '16:00:00';
$event->start = strtotime( $event->event_start_date . ' ' . $event->event_start_time );
$event->end = strtotime( $event->event_end_date . ' ' . $event->event_end_time );
$event->force_status = 'publish';
$event->event_rsvp = false;
$this->assertTrue( $event->save() );
// Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->post_id ) )->to_object()->to_array();
// Check that we got the right transformer.
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Events Manager Test event', $event_array['name'] );
$this->assertEquals( 'Event description', wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertEquals( 'MEETING', $event_array['category'] );
$this->assertArrayHasKey( 'location', $event_array );
$this->assertEquals( 'Name only location', $event_array['location']['name'] );
}
}

View file

@ -0,0 +1,104 @@
<?php
/**
* Class SampleTest
*
* @package ActivityPub_Event_Bridge
*/
/**
* Sample test case.
*/
class Test_GatherPress extends WP_UnitTestCase {
/**
* Override the setup function, so that tests don't run if the Events Calendar is not active.
*/
public function set_up() {
parent::set_up();
if ( ! defined( 'GATHERPRESS_CORE_FILE' ) ) {
self::markTestSkipped( 'GatherPress plugin is not active.' );
}
// Mock the plugin activation.
GatherPress\Core\Setup::get_instance()->activate_gatherpress_plugin( false );
// Make sure that ActivityPub support is enabled for The Events Calendar.
$aec = \ActivityPub_Event_Bridge\Setup::get_instance();
$aec->activate_activitypub_support_for_active_event_plugins();
// Delete all posts afterwards.
_delete_all_posts();
}
/**
* Test that the right transformer gets applied.
*/
public function test_transformer_class() {
// We only test for one event plugin being active at the same time,
// even though we support multiple onces in theory.
// But testing all combinations is beyond scope.
$active_event_plugins = \ActivityPub_Event_Bridge\Setup::get_instance()->get_active_event_plugins();
$this->assertEquals( 1, count( $active_event_plugins ) );
// Enable ActivityPub support for the event plugin.
$this->assertContains( 'gatherpress_event', get_option( 'activitypub_support_post_types' ) );
// Mock GatherPress Event.
$post_id = wp_insert_post(
array(
'post_title' => 'Unit Test Event',
'post_type' => 'gatherpress_event',
'post_content' => 'Unit Test description.',
'post_status' => 'publish',
)
);
$event = new \GatherPress\Core\Event( $post_id );
$params = array(
'datetime_start' => '+10 days 15:00:00',
'datetime_end' => '+10 days 16:00:00',
'timezone' => 'America/New_York',
);
$event->save_datetimes( $params );
// Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( $event->event );
// Check that we got the right transformer.
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\GatherPress::class, $transformer );
}
/**
* Test transformation to ActivityPUb for basic event.
*/
public function test_transform_of_basic_event() {
// Mock GatherPress Event.
$post_id = wp_insert_post(
array(
'post_title' => 'Unit Test Event',
'post_type' => 'gatherpress_event',
'post_content' => 'Unit Test description.',
'post_status' => 'publish',
)
);
$event = new \GatherPress\Core\Event( $post_id );
$params = array(
'datetime_start' => '+10 days 15:00:00',
'datetime_end' => '+10 days 16:00:00',
'timezone' => 'America/New_York',
);
$event->save_datetimes( $params );
// Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $event->event )->to_object()->to_array();
// Check that the event ActivityStreams representation contains everything as expected.
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Unit Test Event', $event_array['name'] );
$this->assertEquals( 'Unit Test description.', wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
$this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertArrayNotHasKey( 'location', $event_array );
}
}

View file

@ -0,0 +1,216 @@
<?php
/**
* Class SampleTest
*
* @package ActivityPub_Event_Bridge
*/
/**
* Sample test case.
*/
class Test_The_Events_Calendar extends WP_UnitTestCase {
/**
* Mockup events of certain complexity.
*/
public const MOCKUP_VENUS = array(
'minimal_venue' => array(
'venue' => 'Minimal Venue',
'status' => 'publish',
),
'complex_venue' => array(
'venue' => 'Complex Venue',
'status' => 'publish',
'show_map' => false,
'show_map_link' => false,
'address' => 'Venue address',
'city' => 'Venue city',
'country' => 'Venue country',
'province' => 'Venue province',
'state' => 'Venue state',
'stateprovince' => 'Venue stateprovince',
'zip' => 'Venue zip',
'phone' => 'Venue phone',
'website' => 'http://venue.com',
),
);
public const MOCKUP_EVENTS = array(
'minimal_event' => array(
'title' => 'My Event',
'content' => 'Come to my event!',
'start_date' => '+10 days 15:00:00',
'duration' => HOUR_IN_SECONDS,
'status' => 'publish',
),
'complex_event' => array(
'title' => 'My Event',
'content' => 'Come to my event!',
'start_date' => '+10 days 15:00:00',
'duration' => HOUR_IN_SECONDS,
'status' => 'publish',
),
);
/**
* Override the setup function, so that tests don't run if the Events Calendar is not active.
*/
public function set_up() {
parent::set_up();
if ( ! class_exists( '\Tribe__Events__Main' ) ) {
self::markTestSkipped( 'The Events Calendar plugin is not active.' );
}
// Make sure that ActivityPub support is enabled for The Events Calendar.
$aec = \ActivityPub_Event_Bridge\Setup::get_instance();
$aec->activate_activitypub_support_for_active_event_plugins();
// Delete all posts afterwards.
_delete_all_posts();
}
/**
* Test that the right transformer gets applied.
*/
public function test_the_events_calendar_transformer_class() {
// We only test for one event plugin being active at the same time,
// even though we support multiple onces in theory.
// But testing all combinations is beyond scope.
$active_event_plugins = \ActivityPub_Event_Bridge\Setup::get_instance()->get_active_event_plugins();
$this->assertEquals( 1, count( $active_event_plugins ) );
// Enable ActivityPub support for the event plugin.
$this->assertContains( 'tribe_events', get_option( 'activitypub_support_post_types' ) );
// Create a The Events Calendar Event without content.
$wp_object = tribe_events()
->set_args( self::MOCKUP_EVENTS['minimal_event'] )
->create();
// Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
// Check that we got the right transformer.
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\The_Events_Calendar::class, $transformer );
}
/**
* Test transformation of minimal event without venue.
*/
public function test_transform_of_minimal_event_without_venue() {
// Create a The Events Calendar Event.
$wp_object = tribe_events()
->set_args( self::MOCKUP_EVENTS['minimal_event'] )
->create();
// Call the transformer.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
// Check that the event ActivityStreams representation contains everything as expected.
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'My Event', $event_array['name'] );
$this->assertEquals( 'Come to my event!', wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
$this->assertTrue( $event_array['commentsEnabled'] );
$this->assertEquals( 'allow_all', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertArrayNotHasKey( 'location', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] );
}
/**
* Test transformation of event with mapped category.
*/
public function test_transform_event_with_mapped_categories() {
// Create category.
$category_id_music = wp_insert_term( 'Music', Tribe__Events__Main::TAXONOMY, array( 'slug' => 'music' ) );
$category_id_theatre = wp_insert_term( 'Theatre', Tribe__Events__Main::TAXONOMY, array( 'slug' => 'theatre' ) );
// Set default mapping for event categories.
update_option( 'activitypub_event_bridge_default_event_category', 'MUSIC' );
// Set an override for the category with the slug theatre.
update_option( 'activitypub_event_bridge_event_category_mappings', array( 'theatre' => 'THEATRE' ) );
// Create a The Events Calendar event with the music category.
$wp_object = tribe_events()
->set_args( self::MOCKUP_EVENTS['minimal_event'] )
->create();
// Set the post term music to the event.
wp_set_post_terms( $wp_object->ID, $category_id_music['term_id'], Tribe__Events__Main::TAXONOMY );
// Call the transformer.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
// See if the default category mapping is applied.
$this->assertEquals( 'MUSIC', $event_array['category'] );
// Set the post term theatre to the event.
wp_set_post_terms( $wp_object->ID, $category_id_theatre['term_id'], Tribe__Events__Main::TAXONOMY, false );
// Call the transformer.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
// See if the default category mapping is applied.
$this->assertEquals( 'THEATRE', $event_array['category'] );
}
/**
* Test transformation of minimal event with minimal venue.
*/
public function test_transform_of_minimal_event_with_venue() {
// Create Venue.
$venue = tribe_venues()->set_args( self::MOCKUP_VENUS['minimal_venue'] )->create();
// Create a The Events Calendar Event.
$wp_object = tribe_events()
->set_args( self::MOCKUP_EVENTS['complex_event'] )
->set( 'venue', $venue->ID )
->create();
// Call the transformer.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
// Check that the event ActivityStreams representation contains everything as expected.
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'My Event', $event_array['name'] );
$this->assertEquals( 'Come to my event!', wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['commentsEnabled'] );
$this->assertArrayHasKey( 'location', $event_array );
$this->assertEquals( 'Place', $event_array['location']['type'] );
$this->assertEquals( self::MOCKUP_VENUS['minimal_venue']['venue'], $event_array['location']['name'] );
}
/**
* Test transformation of minimal event with fully filled venue.
*/
public function test_transform_of_minimal_event_with_address_venue() {
// Create Venue.
$venue = tribe_venues()->set_args( self::MOCKUP_VENUS['complex_venue'] )->create();
// Create a The Events Calendar Event.
$wp_object = tribe_events()
->set_args( self::MOCKUP_EVENTS['minimal_event'] )
->set( 'venue', $venue->ID )
->create();
// Call the transformer.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
// Check that the event ActivityStreams representation contains everything as expected.
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'My Event', $event_array['name'] );
$this->assertEquals( 'Come to my event!', wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['commentsEnabled'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
$this->assertArrayHasKey( 'location', $event_array );
$this->assertEquals( 'Place', $event_array['location']['type'] );
$this->assertEquals( 'PostalAddress', $event_array['location']['address']['type'] );
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['venue'], $event_array['location']['name'] );
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['venue'], $event_array['location']['address']['name'] );
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['province'], $event_array['location']['address']['addressRegion'] );
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['address'], $event_array['location']['address']['streetAddress'] );
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['city'], $event_array['location']['address']['addressLocality'] );
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['country'], $event_array['location']['address']['addressCountry'] );
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['zip'], $event_array['location']['address']['postalCode'] );
}
}

View file

@ -0,0 +1,211 @@
<?php
/**
* Class SampleTest
*
* @package ActivityPub_Event_Bridge
*/
/**
* Sample test case.
*/
class Test_VS_Event_List extends WP_UnitTestCase {
/**
* Override the setup function, so that tests don't run if the Events Calendar is not active.
*/
public function set_up() {
parent::set_up();
if ( ! function_exists( 'vsel_custom_post_type' ) ) {
self::markTestSkipped( 'VS Event List plugin is not active.' );
}
// Make sure that ActivityPub support is enabled for The Events Calendar.
$aec = \ActivityPub_Event_Bridge\Setup::get_instance();
$aec->activate_activitypub_support_for_active_event_plugins();
// Delete all posts afterwards.
_delete_all_posts();
}
/**
* Test that the right transformer gets applied.
*/
public function test_transformer_class() {
// We only test for one event plugin being active at the same time,
// even though we support multiple onces in theory.
// But testing all combinations is beyond scope.
$active_event_plugins = \ActivityPub_Event_Bridge\Setup::get_instance()->get_active_event_plugins();
$this->assertEquals( 1, count( $active_event_plugins ) );
// Enable ActivityPub support for the event plugin.
$this->assertContains( 'event', get_option( 'activitypub_support_post_types' ) );
// Insert a new Event.
$wp_post_id = wp_insert_post(
array(
'post_title' => 'VSEL Test Event',
'post_status' => 'published',
'post_type' => 'event',
'meta_input' => array(
'event-start-date' => strtotime( '+10 days 15:00:00' ),
),
)
);
$wp_object = get_post( $wp_post_id );
// Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
// Check that we got the right transformer.
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\VS_Event_List::class, $transformer );
}
/**
* Test the transformation to ActivityStreams of minimal event.
*/
public function test_transform_of_minimal_event() {
// Insert a new Event.
$wp_post_id = wp_insert_post(
array(
'post_title' => 'VSEL Test Event',
'post_status' => 'published',
'post_type' => 'event',
'meta_input' => array(
'event-start-date' => strtotime( '+10 days 15:00:00' ),
),
)
);
// Transform the event to ActivityStreams.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array();
// Check that the event ActivityStreams representation contains everything as expected.
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'VSEL Test Event', $event_array['name'] );
$this->assertEquals( '', $event_array['content'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertArrayNotHasKey( 'endTime', $event_array );
$this->assertEquals( comments_open( $wp_post_id ), $event_array['commentsEnabled'] );
$this->assertEquals( comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertEquals( esc_url( get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] );
$this->assertArrayNotHasKey( 'location', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] );
}
/**
* Test the transformation to ActivityStreams of minimal event.
*/
public function test_transform_of_full_event() {
// Insert a new Event.
$wp_post_id = wp_insert_post(
array(
'post_title' => 'VSEL Test Event',
'post_status' => 'published',
'post_type' => 'event',
'meta_input' => array(
'event-start-date' => strtotime( '+10 days 15:00:00' ),
'event-date' => strtotime( '+10 days 16:00:00' ),
'event-link' => 'https://event-federation.eu/vsel-test-event',
'event-link-label' => 'Website',
),
)
);
// Transform the event to ActivityStreams.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array();
// Check that the event ActivityStreams representation contains everything as expected.
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'VSEL Test Event', $event_array['name'] );
$this->assertEquals( '', $event_array['content'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
$this->assertEquals( comments_open( $wp_post_id ), $event_array['commentsEnabled'] );
$this->assertEquals( comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertEquals( esc_url( get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] );
$this->assertArrayNotHasKey( 'location', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] );
$this->assertContains(
array(
'type' => 'Link',
'name' => 'Website',
'href' => 'https://event-federation.eu/vsel-test-event',
'mediaType' => 'text/html',
),
$event_array['attachment']
);
}
/**
* Test the transformation to ActivityStreams of event with hidden end time.
*/
public function test_transform_of_event_with_hidden_end_time() {
// Insert a new Event.
$wp_post_id = wp_insert_post(
array(
'post_title' => 'VSEL Test Event',
'post_status' => 'published',
'post_type' => 'event',
'meta_input' => array(
'event-start-date' => strtotime( '+10 days 15:00:00' ),
'event-date' => strtotime( '+10 days 16:00:00' ),
'event-hide-end-time' => 'yes',
),
)
);
// Transform the event to ActivityStreams.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array();
// Check that the event ActivityStreams representation contains everything as expected.
$this->assertArrayNotHasKey( 'endTime', $event_array );
}
/**
* Test transformation of event with mapped category.
*/
public function test_transform_event_with_mapped_categories() {
// Create category.
$category_id_music = wp_insert_term( 'Music', 'event_cat', array( 'slug' => 'music' ) );
$category_id_theatre = wp_insert_term( 'Theatre', 'event_cat', array( 'slug' => 'theatre' ) );
// Set default mapping for event categories.
update_option( 'activitypub_event_bridge_default_event_category', 'MUSIC' );
// Set an override for the category with the slug theatre.
update_option( 'activitypub_event_bridge_event_category_mappings', array( 'theatre' => 'THEATRE' ) );
// Create a VS Event List event with the music category.
$wp_post_id = wp_insert_post(
array(
'post_title' => 'VSEL Test Event',
'post_status' => 'published',
'post_type' => 'event',
'meta_input' => array(
'event-start-date' => strtotime( '+10 days 15:00:00' ),
'event-date' => strtotime( '+10 days 16:00:00' ),
'event-hide-end-time' => 'yes',
),
)
);
wp_set_post_terms( $wp_post_id, $category_id_music['term_id'], 'event_cat' );
// Call the transformer.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array();
// See if the default category mapping is applied.
$this->assertEquals( 'MUSIC', $event_array['category'] );
// Change the event category to theatre.
wp_set_post_terms( $wp_post_id, $category_id_theatre['term_id'], 'event_cat', false );
// Call the transformer.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array();
// See if the default category mapping is applied.
$this->assertEquals( 'THEATRE', $event_array['category'] );
}
}