connector-wordpress/source/includes/EventsListShortcut.php

54 lines
1.6 KiB
PHP
Raw Normal View History

2021-01-08 14:08:40 +01:00
<?php
namespace MobilizonConnector;
// Exit if this file is called directly.
if (!defined('ABSPATH')) {
exit;
}
class EventsListShortcut {
public static function init() {
add_shortcode(NAME . '-events-list', 'MobilizonConnector\EventsListShortcut::inflate');
}
public static function inflate($atts = [], $content = null) {
// Normalize attribute keys, lowercase.
$atts = array_change_key_case((array) $atts, CASE_LOWER);
// Override default attributes with user attributes.
$atts_with_overriden_defaults = shortcode_atts(
array(
'events-count' => DEFAULT_EVENTS_COUNT,
'group-name' => '',
2021-01-08 14:08:40 +01:00
), $atts
);
2023-05-07 19:53:24 +02:00
$url = Settings::getUrl();
2021-01-08 14:08:40 +01:00
$eventsCount = $atts_with_overriden_defaults['events-count'];
$groupName = $atts_with_overriden_defaults['group-name'];
2021-01-08 14:08:40 +01:00
2023-05-07 21:48:33 +02:00
ob_start();
try {
if ($groupName) {
2023-05-07 22:12:36 +02:00
$events = GraphQlClient::get_upcoming_events_by_group_name($url, (int) $eventsCount, $groupName);
2023-05-07 21:48:33 +02:00
} else {
2023-05-07 22:12:36 +02:00
$events = GraphQlClient::get_upcoming_events($url, (int) $eventsCount);
2023-05-07 21:48:33 +02:00
}
2023-05-07 19:53:24 +02:00
2023-05-07 21:48:33 +02:00
$classNamePrefix = NAME;
$locale = get_locale();
$isShortOffsetNameShown = Settings::isShortOffsetNameShown();
$timeZone = wp_timezone_string();
2023-05-07 19:53:24 +02:00
2023-05-07 21:48:33 +02:00
require dirname(__DIR__) . '/view/events-list.php';
} catch (GeneralException $e) {
require dirname(__DIR__) . '/view/events-list-not-loaded.php';
} catch (GroupNotFoundException $e) {
require dirname(__DIR__) . '/view/events-list-group-not-found.php';
}
2021-01-08 14:08:40 +01:00
$output = ob_get_clean();
return $output;
}
}