forked from fangel/SG-iCalendar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SG_iCal.php
127 lines (114 loc) · 2.89 KB
/
SG_iCal.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
define('SG_ICALREADER_VERSION', '0.5');
/**
* A simple iCal parser. Should take care of most stuff for ya
*
* Roadmap:
* * Finish FREQUENCY-parsing.
* * Add API for recurring events
*
* A simple example:
* <?php
* $ical = new SG_iCal("http://example.com/calendar.ics");
* foreach( $ical->getEvents() As $event ) {
* // Do stuff with the event $event
* }
* ?>
*
* @package SG_iCalReader
* @author Morten Fangel (C) 2008
* @license http://creativecommons.org/licenses/by-sa/2.5/dk/deed.en_GB CC-BY-SA-DK
*/
class SG_iCal {
private $information;
private $events;
private $timezones;
/**
* Constructs a new iCalReader. You can supply the url now, or later using setUrl
* @param $url string
*/
public function __construct($url = false) {
require_once dirname(__FILE__) . '/helpers/SG_iCal_Factory.php'; // BUILD: Remove line
require_once dirname(__FILE__) . '/helpers/SG_iCal_Line.php'; // BUILD: Remove line
require_once dirname(__FILE__) . '/helpers/SG_iCal_Query.php'; // BUILD: Remove line
require_once dirname(__FILE__) . '/helpers/SG_iCal_Parser.php'; // BUILD: Remove line
if( $url !== false ) {
SG_iCal_Parser::Parse($url, $this);
}
}
/**
* Sets (or resets) the url this reader reads from.
* @param $url string
*/
public function setUrl( $url = false ) {
if( $url !== false ) {
SG_iCal_Parser::Parse($url, $this);
}
}
/**
* Returns the main calendar info. You can then query the returned
* object with ie getTitle().
* @return SG_iCal_VCalendar
*/
public function getCalendarInfo() {
return $this->information;
}
/**
* Sets the calendar info for this calendar
* @param SG_iCal_VCalendar $info
*/
public function setCalendarInfo( SG_iCal_VCalendar $info ) {
$this->information = $info;
}
/**
* Returns a given timezone for the calendar. This is mainly used
* by VEvents to adjust their date-times if they have specified a
* timezone.
*
* If no timezone is given, all timezones in the calendar is
* returned.
*
* @param $tzid string
* @return SG_iCal_VTimeZone
*/
public function getTimeZoneInfo( $tzid = null ) {
if( $tzid == null ) {
return $this->timezones;
} else {
if ( !isset($this->timezones)) {
return null;
}
foreach( $this->timezones AS $tz ) {
if( $tz->getTimeZoneId() == $tzid ) {
return $tz;
}
}
return null;
}
}
/**
* Adds a new timezone to this calendar
* @param SG_iCal_VTimeZone $tz
*/
public function addTimeZone( SG_iCal_VTimeZone $tz ) {
$this->timezones[] = $tz;
}
/**
* Returns the events found
* @return array
*/
public function getEvents() {
return $this->events;
}
/**
* Adds a event to this calendar
* @param SG_iCal_VEvent $event
*/
public function addEvent( SG_iCal_VEvent $event ) {
$this->events[] = $event;
}
}
/**
* For legacy reasons, we keep the name SG_iCalReader..
*/
class SG_iCalReader extends SG_iCal {}