Overview

Namespaces

  • intouch
    • ical

Classes

  • Duration
  • Factory
  • Freq
  • iCal
  • Line
  • Parser
  • Query
  • Recurrence
  • VCalendar
  • VEvent
  • VTimeZone
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace intouch\ical;
  4: 
  5: require_once __DIR__ . '/Factory.php';
  6: require_once __DIR__ . '/Duration.php';
  7: require_once __DIR__ . '/Freq.php';
  8: require_once __DIR__ . '/Line.php';
  9: require_once __DIR__ . '/Parser.php';
 10: require_once __DIR__ . '/Query.php';
 11: require_once __DIR__ . '/Recurrence.php';
 12: require_once __DIR__ . '/VCalendar.php';
 13: require_once __DIR__ . '/VEvent.php';
 14: require_once __DIR__ . '/VTimeZone.php';
 15: 
 16: define('SG_ICALREADER_VERSION', '0.8.0');
 17: 
 18: /**
 19:  * A simple iCal parser.
 20:  *
 21:  * http://github.com/mfkahn/intouch-iCalendar based on
 22:  * http://github.com/fangel/SG-iCalendar
 23:  *
 24:  * Roadmap:
 25:  * - Finish FREQUENCY-parsing.
 26:  * - Add API for recurring events
 27:  *
 28:  * A simple example:
 29:  * <code>
 30:  * <?php
 31:  * use intouch\ical\iCal;
 32:  * $ical = new iCal("http://example.com/calendar.ics");
 33:  * foreach( $ical->getEvents() As $event ) {
 34:  *   // Do stuff with the event $event
 35:  * }
 36:  * ?>
 37:  * </code>
 38:  *
 39:  * @author Morten Fangel (C) 2008
 40:  * @author xonev (C) 2010
 41:  * @author Tanguy Pruvot (C) 2010
 42:  * @author Michael Kahn (C) 2013
 43:  * @license http://creativecommons.org/licenses/by-sa/2.5/dk/deed.en_GB CC-BY-SA-DK
 44:  */
 45: class iCal {
 46: 
 47:     //objects
 48:     public $information; //VCalendar
 49:     public $timezones;   //VTimeZone
 50: 
 51:     protected $events; //VEvent[]
 52: 
 53:     /**
 54:      * Constructs a new iCalReader. You can supply the url now, or later using setUrl
 55:      * @param $url string
 56:      */
 57:     public function __construct($url = false) {
 58:         $this->setUrl($url);
 59:     }
 60: 
 61:     /**
 62:      * Sets (or resets) the url this reader reads from.
 63:      * @param $url string
 64:      */
 65:     public function setUrl( $url = false ) {
 66:         if( $url !== false ) {
 67:             Parser::Parse($url, $this);
 68:         }
 69:     }
 70: 
 71:     /**
 72:      * Returns the main calendar info. You can then query the returned
 73:      * object with ie getTitle().
 74:      * @return intouch\ical\VCalendar
 75:      */
 76:     public function getCalendarInfo() {
 77:         return $this->information;
 78:     }
 79: 
 80:     /**
 81:      * Sets the calendar info for this calendar
 82:      * @param intouch\ical\VCalendar $info
 83:      */
 84:     public function setCalendarInfo( VCalendar $info ) {
 85:         $this->information = $info;
 86:     }
 87: 
 88: 
 89:     /**
 90:      * Returns a given timezone for the calendar. This is mainly used
 91:      * by VEvents to adjust their date-times if they have specified a
 92:      * timezone.
 93:      *
 94:      * If no timezone is given, all timezones in the calendar is
 95:      * returned.
 96:      *
 97:      * @param $tzid string
 98:      * @return intouch\ical\VTimeZone
 99:      */
100:     public function getTimeZoneInfo( $tzid = null ) {
101:         if( $tzid == null ) {
102:             return $this->timezones;
103:         } else {
104:             if ( !isset($this->timezones)) {
105:                 return null;
106:             }
107:             foreach( $this->timezones AS $tz ) {
108:                 if( $tz->getTimeZoneId() == $tzid ) {
109:                     return $tz;
110:                 }
111:             }
112:             return null;
113:         }
114:     }
115: 
116:     /**
117:      * Adds a new timezone to this calendar
118:      * @param intouch\ical\VTimeZone $tz
119:      */
120:     public function addTimeZone( VTimeZone $tz ) {
121:         $this->timezones[] = $tz;
122:     }
123: 
124:     /**
125:      * Returns the events found
126:      * @return array
127:      */
128:     public function getEvents() {
129:         return $this->events;
130:     }
131: 
132:     /**
133:      * Adds a event to this calendar
134:      * @param intouch\ical\VEvent $event
135:      */
136:     public function addEvent( VEvent $event ) {
137:         $this->events[] = $event;
138:     }
139: }
140: 
141: /**
142:  * Legacy - empty subclass of iCal
143:  * @internal
144:  */
145: class iCalReader extends iCal {}
146: 
intouch-iCalendar API documentation generated by ApiGen 2.8.0