-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbehaviour.php
88 lines (72 loc) · 2.59 KB
/
behaviour.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
if (!defined('IN_CMS')) { exit(); }
/**
* A *calendar* behaviour.
*
* This class is **NOT** a part of the public API.
* Its fields and methods can be changed in any version of the plugin.
*/
class Calendar {
private $page;
private $params;
private function beginCapture()
{
ob_start();
}
private function endCapture()
{
$this->page->part->body->content_html = ob_get_contents();
ob_end_clean();
}
private function pageNotFound()
{
pageNotFound();
exit();
}
public function __construct(&$page, $params)
{
$this->page = & $page;
$this->params = $params;
switch (count($params)) {
case 0:
break; // main page of calendar behaviour, don't change anything
case 1: // there's one parameter after slash
$slug = $params[0];
/* We try to find a subpage of the calendar page, so the event's page can be customized */
$page_found = Page::findBySlug($slug, $this->page, true);
/* A subpage is found, so display it */
if (is_a($page_found, "Page"))
$this->page = $page_found;
/* A subpage is not found, so try to parse a date and then create an event's page */
elseif (CalendarPlugin::validateDateString($slug, CALENDAR_SQL_DATE_FORMAT)) {
$date = new DateTime($slug);
$events = CalendarEvent::findEventsByDate($date);
$this->page->title = $date->format(CALENDAR_DISPLAY_DATE_FORMAT);
$this->beginCapture();
CalendarPlugin::showEvents($events);
$this->endCapture();
}
/* Or maybe it's an event Id? */
elseif (is_numeric($slug) && ($event = CalendarEvent::findById((int)$slug))) {
$this->page->title = $event->getTitle();
$this->beginCapture();
CalendarPlugin::showEvent($event);
$this->endCapture();
}
else
$this->pageNotFound();
break;
case 2: // there're two parameters after slash
$year = (int)$params[0];
$month = (int)$params[1];
$date = new DateTime();
$date->setDate($year, $month, 1);
$this->beginCapture();
CalendarPlugin::showCalendar($this->page->slug, $date);
$this->endCapture();
break;
default:
$this->pageNotFound();
}
}
}