Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2527957
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/Kolab/FreeBusy/FormatExchange2010.php b/lib/Kolab/FreeBusy/FormatExchange2010.php
index 8aec7e4..8534df2 100644
--- a/lib/Kolab/FreeBusy/FormatExchange2010.php
+++ b/lib/Kolab/FreeBusy/FormatExchange2010.php
@@ -1,135 +1,137 @@
<?php
namespace Kolab\FreeBusy;
use Sabre\VObject\Reader as VCalReader;
use Sabre\VObject\FreeBusyGenerator;
use Sabre\VObject\ParseException;
use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\File as FileCache;
use \SimpleXMLElement;
/**
* Implementation of a data converter reading Exchange 2010 Internet Calendar Publishing files
*/
class FormatExchange2010 extends Format
{
private $tzmap;
/**
* @see Format::toVCalendar()
*/
public function toVCalendar($input)
{
// convert Microsoft timezone identifiers to Olson standard
// do this before parsing to create correct DateTime values
$input = preg_replace_callback('/(TZID[=:])([-\w ]+)\b/i', array($this, 'convertTZID'), $input);
try {
// parse vcalendar data
$calendar = VCalReader::read($input);
// map X-MICROSOFT-CDO-* attributes into iCal equivalents
foreach ($calendar->VEVENT as $vevent) {
if ($busystatus = reset($vevent->select('X-MICROSOFT-CDO-BUSYSTATUS'))) {
$vevent->STATUS->value = $busystatus->value;
}
}
// feed the calendar object into the free/busy generator
// we must specify a start and end date, because recurring events are expanded. nice!
+ $utc = new \DateTimezone('UTC');
$fbgen = new FreeBusyGenerator(
- new \DateTime('now - 8 weeks'),
- new \DateTime('now + 16 weeks'),
+ new \DateTime('now - 8 weeks 00:00:00', $utc),
+ new \DateTime('now + 16 weeks 00:00:00', $utc),
$calendar
);
// get the freebusy report
$freebusy = $fbgen->getResult();
- $freebusy->PRODID->value = '-//kolab.org//NONSGML Kolab Server 3//EN';
+ $freebusy->PRODID = '-//kolab.org//NONSGML Kolab Server 3//EN';
+ $freebusy->METHOD = 'PUBLISH';
// serialize to VCALENDAR format
return $freebusy->serialize();
}
catch (ParseException $e) {
Logger::get('format.Exchange2010')->addError("iCal parse error: " . $e->getMessage());
}
return false;
}
/**
* preg_replace callback function to map Timezone identifiers
*/
private function convertTZID($m)
{
if (!isset($this->tzmap)) {
$this->getTZMAP();
}
$key = strtolower($m[2]);
if ($this->tzmap[$key]) {
$m[2] = $this->tzmap[$key];
}
return $m[1] . $m[2] . $m[3];
}
/**
* Generate a Microsoft => Olson Timezone mapping table from an official source
*/
private function getTZMAP()
{
if (!isset($this->tzmap)) {
$log = Logger::get('format.Exchange2010');
$cache = new Cache(new FileCache(sys_get_temp_dir()));
// read from cache
$this->tzmap = $cache->get('windows-timezones');
// fetch timezones map from source
if (empty($this->tzmap)) {
$this->tzmap = array();
$zones_url = 'http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml';
if ($xml = @file_get_contents($zones_url)) {
try {
$zonedata = new SimpleXMLElement($xml, LIBXML_NOWARNING | LIBXML_NOERROR);
foreach ($zonedata->windowsZones[0]->mapTimezones[0]->mapZone as $map) {
$other = strtolower(strval($map['other']));
$region = strval($map['territory']);
$words = explode(' ', $other);
$olson = explode(' ', strval($map['type']));
// skip invalid entries
if (empty($other) || empty($olson))
continue;
// create an entry for all substrings
for ($i = 1; $i <= count($words); $i++) {
$last = $i == count($words);
$key = join(' ', array_slice($words, 0, $i));
if ($region == '001' || ($last && empty($this->tzmap[$key]))) {
$this->tzmap[$key] = $olson[0];
}
}
}
// cache the mapping for one week
$cache->set('windows-timezones', $this->tzmap, 7 * 86400);
$log->addInfo("Updated Windows Timezones Map from source", array($zones_url));
}
catch (\Exception $e) {
$log->addError("Failed parse Windows Timezones Map: " . $e->getMessage());
}
}
else {
$log->addError("Failed to load Windows Timezones Map from source", array($zones_url));
}
}
}
return $this->tzmap;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Jan 31, 8:15 PM (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
426466
Default Alt Text
(4 KB)
Attached To
Mode
R28 freebusy
Attached
Detach File
Event Timeline
Log In to Comment