2008-02-23 10:49:16 +00:00
|
|
|
<?php
|
|
|
|
|
2010-10-29 04:52:19 +00:00
|
|
|
define('SG_ICALREADER_VERSION', '0.5.1-tpruvot');
|
2008-02-29 13:30:33 +00:00
|
|
|
|
2008-02-23 10:49:16 +00:00
|
|
|
/**
|
2009-01-10 11:10:45 +00:00
|
|
|
* A simple iCal parser. Should take care of most stuff for ya
|
2010-10-29 04:52:19 +00:00
|
|
|
* http://github.com/tpruvot/PHP-iCal
|
2008-02-23 10:49:16 +00:00
|
|
|
*
|
|
|
|
* Roadmap:
|
2008-03-01 08:53:15 +00:00
|
|
|
* * Finish FREQUENCY-parsing.
|
|
|
|
* * Add API for recurring events
|
2008-02-23 10:49:16 +00:00
|
|
|
*
|
|
|
|
* A simple example:
|
|
|
|
* <?php
|
2010-10-29 04:52:19 +00:00
|
|
|
* $ical = new SG_iCalReader("http://example.com/calendar.ics");
|
2008-02-23 10:49:16 +00:00
|
|
|
* foreach( $ical->getEvents() As $event ) {
|
|
|
|
* // Do stuff with the event $event
|
|
|
|
* }
|
|
|
|
* ?>
|
|
|
|
*
|
|
|
|
* @package SG_iCalReader
|
|
|
|
* @author Morten Fangel (C) 2008
|
2008-02-24 11:05:01 +00:00
|
|
|
* @license http://creativecommons.org/licenses/by-sa/2.5/dk/deed.en_GB CC-BY-SA-DK
|
2008-02-23 10:49:16 +00:00
|
|
|
*/
|
2009-01-10 11:10:45 +00:00
|
|
|
class SG_iCal {
|
2010-10-29 03:17:55 +00:00
|
|
|
protected $information;
|
|
|
|
protected $events;
|
|
|
|
protected $timezones;
|
2008-02-23 10:49:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a new iCalReader. You can supply the url now, or later using setUrl
|
|
|
|
* @param $url string
|
|
|
|
*/
|
2009-01-10 11:10:45 +00:00
|
|
|
public function __construct($url = false) {
|
2008-02-23 10:49:16 +00:00
|
|
|
require_once dirname(__FILE__) . '/helpers/SG_iCal_Factory.php'; // BUILD: Remove line
|
|
|
|
require_once dirname(__FILE__) . '/helpers/SG_iCal_Line.php'; // BUILD: Remove line
|
2008-03-25 18:26:52 +00:00
|
|
|
require_once dirname(__FILE__) . '/helpers/SG_iCal_Query.php'; // BUILD: Remove line
|
2010-10-29 01:03:19 +00:00
|
|
|
require_once dirname(__FILE__) . '/helpers/SG_iCal_Recurrence.php'; // BUILD: Remove line
|
|
|
|
require_once dirname(__FILE__) . '/helpers/SG_iCal_Freq.php'; // BUILD: Remove line
|
|
|
|
require_once dirname(__FILE__) . '/helpers/SG_iCal_Duration.php'; // BUILD: Remove line
|
2009-01-10 11:10:45 +00:00
|
|
|
require_once dirname(__FILE__) . '/helpers/SG_iCal_Parser.php'; // BUILD: Remove line
|
|
|
|
|
|
|
|
if( $url !== false ) {
|
|
|
|
SG_iCal_Parser::Parse($url, $this);
|
|
|
|
}
|
2008-02-23 10:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-10 11:10:45 +00:00
|
|
|
* Sets (or resets) the url this reader reads from.
|
2008-02-23 10:49:16 +00:00
|
|
|
* @param $url string
|
|
|
|
*/
|
2009-01-10 11:10:45 +00:00
|
|
|
public function setUrl( $url = false ) {
|
|
|
|
if( $url !== false ) {
|
|
|
|
SG_iCal_Parser::Parse($url, $this);
|
2008-02-23 10:49:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the main calendar info. You can then query the returned
|
|
|
|
* object with ie getTitle().
|
|
|
|
* @return SG_iCal_VCalendar
|
|
|
|
*/
|
|
|
|
public function getCalendarInfo() {
|
2009-01-10 11:10:45 +00:00
|
|
|
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;
|
2008-02-23 10:49:16 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 11:10:45 +00:00
|
|
|
|
2008-02-23 10:49:16 +00:00
|
|
|
/**
|
|
|
|
* 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 ) {
|
2009-01-10 11:10:45 +00:00
|
|
|
return $this->timezones;
|
2008-02-23 10:49:16 +00:00
|
|
|
} else {
|
2009-10-27 13:44:01 +00:00
|
|
|
if ( !isset($this->timezones)) {
|
|
|
|
return null;
|
|
|
|
}
|
2009-01-10 11:10:45 +00:00
|
|
|
foreach( $this->timezones AS $tz ) {
|
2008-02-23 10:49:16 +00:00
|
|
|
if( $tz->getTimeZoneId() == $tzid ) {
|
|
|
|
return $tz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-10 11:10:45 +00:00
|
|
|
* Adds a new timezone to this calendar
|
|
|
|
* @param SG_iCal_VTimeZone $tz
|
2008-02-23 10:49:16 +00:00
|
|
|
*/
|
2009-01-10 11:10:45 +00:00
|
|
|
public function addTimeZone( SG_iCal_VTimeZone $tz ) {
|
|
|
|
$this->timezones[] = $tz;
|
2008-02-23 10:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-10 11:10:45 +00:00
|
|
|
* Returns the events found
|
|
|
|
* @return array
|
2008-02-23 10:49:16 +00:00
|
|
|
*/
|
2009-01-10 11:10:45 +00:00
|
|
|
public function getEvents() {
|
|
|
|
return $this->events;
|
2008-02-23 10:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-10 11:10:45 +00:00
|
|
|
* Adds a event to this calendar
|
|
|
|
* @param SG_iCal_VEvent $event
|
2008-02-23 10:49:16 +00:00
|
|
|
*/
|
2009-01-10 11:10:45 +00:00
|
|
|
public function addEvent( SG_iCal_VEvent $event ) {
|
|
|
|
$this->events[] = $event;
|
2008-02-23 10:49:16 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-10 11:10:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For legacy reasons, we keep the name SG_iCalReader..
|
|
|
|
*/
|
|
|
|
class SG_iCalReader extends SG_iCal {}
|