|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file contains several functions for retrieving and manipulating calendar events, birthdays and holidays. |
|
5
|
|
|
* |
|
6
|
|
|
* @package ElkArte Forum |
|
7
|
|
|
* @copyright ElkArte Forum contributors |
|
8
|
|
|
* @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
|
9
|
|
|
* |
|
10
|
|
|
* This file contains code covered by: |
|
11
|
|
|
* copyright: 2011 Simple Machines (http://www.simplemachines.org) |
|
12
|
|
|
* |
|
13
|
|
|
* @version 2.0 dev |
|
14
|
|
|
* |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace ElkArte\Modules\Calendar; |
|
18
|
|
|
|
|
19
|
|
|
use ElkArte\Cache\Cache; |
|
20
|
|
|
use ElkArte\EventManager; |
|
21
|
|
|
use ElkArte\Modules\AbstractModule; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* This class's task is to show the upcoming events in the BoardIndex. |
|
25
|
|
|
*/ |
|
26
|
|
|
class BoardIndex extends AbstractModule |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritDoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function hooks(EventManager $eventsManager) |
|
32
|
|
|
{ |
|
33
|
|
|
// Load the calendar? |
|
34
|
|
|
if (allowedTo('calendar_view')) |
|
35
|
|
|
{ |
|
36
|
|
|
return [ |
|
37
|
|
|
['pre_load', [BoardIndex::class, 'pre_load'], []], |
|
38
|
|
|
['post_load', [BoardIndex::class, 'post_load'], []], |
|
39
|
|
|
]; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return false; |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Pre-load hooks as part of board index |
|
47
|
|
|
*/ |
|
48
|
|
|
public function pre_load(): void |
|
49
|
|
|
{ |
|
50
|
|
|
global $modSettings, $context; |
|
51
|
|
|
|
|
52
|
|
|
// Retrieve the calendar data (events, birthdays, holidays). |
|
53
|
|
|
$eventOptions = [ |
|
54
|
|
|
'include_holidays' => $modSettings['cal_showholidays'] > 1, |
|
55
|
|
|
'include_birthdays' => $modSettings['cal_showbdays'] > 1, |
|
56
|
|
|
'include_events' => $modSettings['cal_showevents'] > 1, |
|
57
|
|
|
'num_days_shown' => empty($modSettings['cal_days_for_index']) || $modSettings['cal_days_for_index'] < 1 ? 1 : $modSettings['cal_days_for_index'], |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
$context += Cache::instance()->quick_get('calendar_index_offset_' . ($this->user->time_offset + $modSettings['time_offset']), 'subs/Calendar.subs.php', 'cache_getRecentEvents', [$eventOptions]); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
// Whether one or multiple days are shown on the board index. |
|
63
|
|
|
$context['calendar_only_today'] = (int) $modSettings['cal_days_for_index'] === 1; |
|
64
|
|
|
|
|
65
|
|
|
// This is used to show the "how-do-I-edit" help. |
|
66
|
|
|
$context['calendar_can_edit'] = allowedTo('calendar_edit_any'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* post load functions, load calendar events for the board index as part of BoardIndex |
|
71
|
|
|
* |
|
72
|
|
|
* @param array $callbacks |
|
73
|
|
|
*/ |
|
74
|
|
|
public function post_load(&$callbacks): void |
|
75
|
|
|
{ |
|
76
|
|
|
global $context; |
|
77
|
|
|
|
|
78
|
|
|
if (empty($context['calendar_holidays']) && empty($context['calendar_birthdays']) && empty($context['calendar_events'])) |
|
79
|
|
|
{ |
|
80
|
|
|
return; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$callbacks = elk_array_insert($callbacks, 'recent_posts', ['show_events'], 'after', false); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: