tra('Events'),
'documentation' => 'PluginEvents',
'description' => tra('Display events from calendars'),
'prefs' => [ 'feature_calendar', 'wikiplugin_events' ],
'iconname' => 'calendar',
'tags' => [ 'basic' ],
'introduced' => 2,
'params' => [
'calendarid' => [
'required' => true,
'name' => tra('Calendar IDs'),
'description' => tr('ID numbers for the site calendars whose events are to be displayed, separated by
vertical bars (%0)', '|'),
'since' => '2.0',
'default' => '',
'filter' => 'text',
'profile_reference' => 'calendar',
],
'maxdays' => [
'required' => false,
'name' => tra('Maximum Days'),
'description' => tr('Events occurring within this number of days in the future from today will be
included in the list (unless limited by other parameter settings). Default is %0.', '365'),
'since' => '2.0',
'filter' => 'digits',
'default' => 365,
],
'max' => [
'required' => false,
'name' => tra('Maximum Events'),
'description' => tr('Maximum number of events to display. Default is %0. Set to %1 to display all
(unless limited by other parameter settings)', '10', '0'),
'since' => '2.0',
'default' => 10,
'filter' => 'digits',
],
'datetime' => [
'required' => false,
'name' => tra('Show Time'),
'description' => tra('Show the time along with the date (shown by default)'),
'since' => '2.0',
'default' => 1,
'filter' => 'digits',
'options' => [
['text' => '', 'value' => ''],
['text' => tra('Yes'), 'value' => 1],
['text' => tra('No'), 'value' => 0]
],
],
'desc' => [
'required' => false,
'name' => tra('Show Description'),
'description' => tra('Show the description of the event (shown by default)'),
'since' => '2.0',
'default' => 1,
'filter' => 'digits',
'options' => [
['text' => '', 'value' => ''],
['text' => tra('Yes'), 'value' => 1],
['text' => tra('No'), 'value' => 0]
],
],
// Pagination
'timespan' => [
'required' => false,
'name' => tra('Time Span'),
'description' => tra('Specify the time span.'),
'since' => '10.0',
'default' => 'future',
'filter' => 'word',
'options' => [
['text' => '', 'value' => ''],
['text' => tra('All'), 'value' => 'all'],
['text' => tra('Past'), 'value' => 'past'],
['text' => tra('Future'), 'value' => 'future']
],
],
'usePagination' => [
'required' => false,
'name' => tra('Use Pagination'),
'description' => tr('Activate pagination when Events listing are long. Default is %0.', 'n'),
'since' => '10.0',
'filter' => 'alpha',
'default' => 'n',
'options' => [
['text' => '', 'value' => ''],
['text' => tra('Yes'), 'value' => 'y'],
['text' => tra('No'), 'value' => 'n']
],
],
],
];
}
function wikiplugin_events($data, $params)
{
global $tiki_p_admin, $tiki_p_view_calendar, $user;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
$smarty = TikiLib::lib('smarty');
$calendarlib = TikiLib::lib('calendar');
$invalideid = false;
extract($params, EXTR_SKIP);
if (! isset($maxdays)) {
$maxdays = 365;
}
if (! isset($max)) {
$max = 10;
}
if (! isset($datetime)) {
$datetime = 1;
}
if (! isset($desc)) {
$desc = 1;
}
// Pagination
if (! isset($timespan)) {
$timespan = "future";
}
if ($usePagination == 'y') {
if (! isset($_REQUEST["offset"])) {
$start = 0;
} else {
$start = $_REQUEST["offset"];
}
}
$rawcals = $calendarlib->list_calendars();
$calIds = [];
$viewable = [];
foreach ($rawcals["data"] as $cal_id => $cal_data) {
$calIds[] = $cal_id;
if ($tiki_p_admin == 'y') {
$canView = 'y';
} elseif ($cal_data["personal"] == "y") {
if ($user) {
$canView = 'y';
} else {
$canView = 'n';
}
} else {
if ($userlib->object_has_one_permission($cal_id, 'calendar')) {
if ($userlib->object_has_permission($user, $cal_id, 'calendar', 'tiki_p_view_calendar')) {
$canView = 'y';
} else {
$canView = 'n';
}
if ($userlib->object_has_permission($user, $cal_id, 'calendar', 'tiki_p_admin_calendar')) {
$canView = 'y';
}
} else {
$canView = $tiki_p_view_calendar;
}
}
if ($canView == 'y') {
$viewable[] = $cal_id;
}
}
// Pagination
if ($timespan == 'future') {
$events = $calendarlib->upcoming_events(
$max,
array_intersect($calIds, $viewable) ? array_intersect($calIds, $viewable) : array(),
$maxdays,
'start_asc',
1,
0,
$start
);
}
if ($timespan == 'all') {
$events = $calendarlib->all_events(
$max,
array_intersect($calIds, $viewable),
$maxdays,
'start_asc',
1,
0,
$start
);
}
if ($timespan == 'past') {
$events = $calendarlib->past_events(
$max,
array_intersect($calIds, $viewable),
$maxdays,
'start_desc',
0,
-1,
$start
);
}
if (isset($calendarid)) {
$calParamIds = explode('|', $calendarid);
if (array_diff($calParamIds, $calIds)) {
$invalideid = true;
$calParamIds = array();
}
}
$events = $calendarlib->upcoming_events($max, array_intersect($calParamIds, $viewable) ? array_intersect($calParamIds, $viewable) : array(), $maxdays);
$smarty->assign_by_ref('datetime', $datetime);
$smarty->assign_by_ref('desc', $desc);
$smarty->assign_by_ref('events', $events);
$smarty->assign_by_ref('invalideid', $invalideid);
// Pagination
if ($usePagination == 'y') {
$smarty->assign('maxEvents', $max);
$smarty->assign_by_ref('offset', $start);
$smarty->assign_by_ref('cant', $events['cant']);
}
$smarty->assign('usePagination', $usePagination);
$smarty->assign_by_ref('events', $events['data']);
$smarty->assign_by_ref('actions', $actions);
return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_events.tpl') . '~/np~';
$repl = "";
if (count($events) < $max) {
$max = count($events);
}
$repl .= '
| ' . tra("Upcoming Events") . ' | |
| ~np~' . $eventStart . ' ' . $eventEnd . '~/np~ | ';
$repl .= '' . $events[$j]["name"] . '';
if ($desc == 1) {
$repl .= ' ' . nl2br($events[$j]["description"]); } $repl .= ' |