Mercurial > hg > rc1
comparison plugins/libcalendaring/lib/Sabre/VObject/Splitter/ICalendar.php @ 4:888e774ee983
libcalendar plugin as distributed
| author | Charlie Root |
|---|---|
| date | Sat, 13 Jan 2018 08:57:56 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 3:f6fe4b6ae66a | 4:888e774ee983 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Sabre\VObject\Splitter; | |
| 4 | |
| 5 use Sabre\VObject; | |
| 6 | |
| 7 /** | |
| 8 * Splitter | |
| 9 * | |
| 10 * This class is responsible for splitting up iCalendar objects. | |
| 11 * | |
| 12 * This class expects a single VCALENDAR object with one or more | |
| 13 * calendar-objects inside. Objects with identical UID's will be combined into | |
| 14 * a single object. | |
| 15 * | |
| 16 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/). | |
| 17 * @author Dominik Tobschall | |
| 18 * @author Armin Hackmann | |
| 19 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License | |
| 20 */ | |
| 21 class ICalendar implements SplitterInterface { | |
| 22 | |
| 23 /** | |
| 24 * Timezones | |
| 25 * | |
| 26 * @var array | |
| 27 */ | |
| 28 protected $vtimezones = array(); | |
| 29 | |
| 30 /** | |
| 31 * iCalendar objects | |
| 32 * | |
| 33 * @var array | |
| 34 */ | |
| 35 protected $objects = array(); | |
| 36 | |
| 37 /** | |
| 38 * Constructor | |
| 39 * | |
| 40 * The splitter should receive an readable file stream as it's input. | |
| 41 * | |
| 42 * @param resource $input | |
| 43 */ | |
| 44 public function __construct($input) { | |
| 45 | |
| 46 $data = VObject\Reader::read(stream_get_contents($input)); | |
| 47 $vtimezones = array(); | |
| 48 $components = array(); | |
| 49 | |
| 50 foreach($data->children as $component) { | |
| 51 if (!$component instanceof VObject\Component) { | |
| 52 continue; | |
| 53 } | |
| 54 | |
| 55 // Get all timezones | |
| 56 if ($component->name === 'VTIMEZONE') { | |
| 57 $this->vtimezones[(string)$component->TZID] = $component; | |
| 58 continue; | |
| 59 } | |
| 60 | |
| 61 // Get component UID for recurring Events search | |
| 62 if($component->UID) { | |
| 63 $uid = (string)$component->UID; | |
| 64 } else { | |
| 65 // Generating a random UID | |
| 66 $uid = sha1(microtime()) . '-vobjectimport'; | |
| 67 } | |
| 68 | |
| 69 // Take care of recurring events | |
| 70 if (!array_key_exists($uid, $this->objects)) { | |
| 71 $this->objects[$uid] = VObject\Component::create('VCALENDAR'); | |
| 72 } | |
| 73 | |
| 74 $this->objects[$uid]->add(clone $component); | |
| 75 } | |
| 76 | |
| 77 } | |
| 78 | |
| 79 /** | |
| 80 * Every time getNext() is called, a new object will be parsed, until we | |
| 81 * hit the end of the stream. | |
| 82 * | |
| 83 * When the end is reached, null will be returned. | |
| 84 * | |
| 85 * @return Sabre\VObject\Component|null | |
| 86 */ | |
| 87 public function getNext() { | |
| 88 | |
| 89 if($object=array_shift($this->objects)) { | |
| 90 | |
| 91 // create our baseobject | |
| 92 $object->version = '2.0'; | |
| 93 $object->prodid = '-//Sabre//Sabre VObject ' . VObject\Version::VERSION . '//EN'; | |
| 94 $object->calscale = 'GREGORIAN'; | |
| 95 | |
| 96 // add vtimezone information to obj (if we have it) | |
| 97 foreach ($this->vtimezones as $vtimezone) { | |
| 98 $object->add($vtimezone); | |
| 99 } | |
| 100 | |
| 101 return $object; | |
| 102 | |
| 103 } else { | |
| 104 | |
| 105 return null; | |
| 106 | |
| 107 } | |
| 108 | |
| 109 } | |
| 110 | |
| 111 } |
