2021-01-08 14:08:40 +01:00
|
|
|
<?php
|
|
|
|
namespace MobilizonConnector;
|
|
|
|
|
|
|
|
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,
|
2021-01-15 20:30:05 +01:00
|
|
|
'group-name' => '',
|
2021-01-08 14:08:40 +01:00
|
|
|
), $atts
|
|
|
|
);
|
|
|
|
|
2024-04-05 23:26:11 +02:00
|
|
|
$url = Settings::getUrl();
|
2021-01-08 14:08:40 +01:00
|
|
|
$eventsCount = $atts_with_overriden_defaults['events-count'];
|
2021-01-15 20:30:05 +01:00
|
|
|
$groupName = $atts_with_overriden_defaults['group-name'];
|
2024-05-14 10:28:39 +02:00
|
|
|
$classNamePrefix = NAME;
|
2021-01-08 14:08:40 +01:00
|
|
|
|
|
|
|
ob_start();
|
2024-04-05 23:26:11 +02:00
|
|
|
try {
|
|
|
|
if ($groupName) {
|
|
|
|
$events = GraphQlClient::get_upcoming_events_by_group_name($url, (int) $eventsCount, $groupName);
|
|
|
|
} else {
|
|
|
|
$events = GraphQlClient::get_upcoming_events($url, (int) $eventsCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
$locale = get_locale();
|
|
|
|
$isShortOffsetNameShown = Settings::isShortOffsetNameShown();
|
|
|
|
$timeZone = wp_timezone_string();
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|