SG-iCalendar/SG_iCal.php

132 wiersze
3.2 KiB
PHP
Czysty Zwykły widok Historia

2008-02-23 10:49:16 +00:00
<?php
define('SG_ICALREADER_VERSION', '0.5.1-tpruvot');
2008-02-23 10:49:16 +00:00
/**
* A simple iCal parser. Should take care of most stuff for ya
* http://github.com/tpruvot/PHP-iCal
2008-02-23 10:49:16 +00:00
*
* Roadmap:
* * Finish FREQUENCY-parsing.
* * Add API for recurring events
2008-02-23 10:49:16 +00:00
*
* A simple example:
* <?php
* $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
* @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
*/
class SG_iCal {
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
*/
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
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
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
}
/**
* Sets (or resets) the url this reader reads from.
2008-02-23 10:49:16 +00:00
* @param $url string
*/
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() {
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
}
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 ) {
return $this->timezones;
2008-02-23 10:49:16 +00:00
} else {
if ( !isset($this->timezones)) {
return null;
}
foreach( $this->timezones AS $tz ) {
2008-02-23 10:49:16 +00:00
if( $tz->getTimeZoneId() == $tzid ) {
return $tz;
}
}
return null;
}
}
/**
* Adds a new timezone to this calendar
* @param SG_iCal_VTimeZone $tz
2008-02-23 10:49:16 +00:00
*/
public function addTimeZone( SG_iCal_VTimeZone $tz ) {
$this->timezones[] = $tz;
2008-02-23 10:49:16 +00:00
}
/**
* Returns the events found
* @return array
2008-02-23 10:49:16 +00:00
*/
public function getEvents() {
return $this->events;
2008-02-23 10:49:16 +00:00
}
/**
* Adds a event to this calendar
* @param SG_iCal_VEvent $event
2008-02-23 10:49:16 +00:00
*/
public function addEvent( SG_iCal_VEvent $event ) {
$this->events[] = $event;
2008-02-23 10:49:16 +00:00
}
}
/**
* For legacy reasons, we keep the name SG_iCalReader..
*/
class SG_iCalReader extends SG_iCal {}