From a359553eeed3ec2fadb080a3720be8a20e6ee69d Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 28 Apr 2010 14:08:14 +1200 Subject: [PATCH] When a timezone is supplied, but not used in the event, pretend it was. This gets around some buggy software which expects this kind of thing to work. --- inc/caldav-PUT-functions.php | 84 ++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/inc/caldav-PUT-functions.php b/inc/caldav-PUT-functions.php index 1e4ff522..4846e77a 100644 --- a/inc/caldav-PUT-functions.php +++ b/inc/caldav-PUT-functions.php @@ -846,50 +846,48 @@ function write_resource( $user_no, $path, $caldav_data, $collection_id, $author, $last_tz_locn = 'Turkmenikikamukau'; // I really hope this location doesn't exist! $tzid = $first->GetPParamValue('DTSTART','TZID'); if ( !isset($tzid) || $tzid == '' ) $tzid = $first->GetPParamValue('DUE','TZID'); - if ( isset($tzid) && $tzid != '' ) { - $timezones = $ic->GetComponents('VTIMEZONE'); - foreach( $timezones AS $k => $tz ) { - if ( $tz->GetPValue('TZID') != $tzid ) { - /** - * We'll pretend they didn't forget to give us a TZID and that they - * really hope the server is running in the timezone they supplied... but be noisy about it. - */ - dbg_error_log( 'ERROR', ' Event includes TZID[%s] but uses TZID[%s]!', $tz->GetPValue('TZID'), $tzid ); - $tzid = $tz->GetPValue('TZID'); - } - // This is the one - $tz_locn = $tz->GetPValue('X-LIC-LOCATION'); - if ( ! isset($tz_locn) ) { - if ( preg_match( '#([^/]+/[^/]+)$#', $tzid, $matches ) ) - $tz_locn = $matches[1]; - else { - dbg_error_log( 'ERROR', ' Couldn\'t guess Olsen TZ from TZID[%s]. This may end in tears...', $tzid ); - } - } - else { - if ( ! preg_match( $tz_regex, $tz_locn ) ) { - if ( preg_match( '#([^/]+/[^/]+)$#', $tzid, $matches ) ) $tz_locn = $matches[1]; - } - } - - dbg_error_log( 'PUT', ' Using TZID[%s] and location of [%s]', $tzid, (isset($tz_locn) ? $tz_locn : '') ); - if ( isset($tz_locn) && ($tz_locn != $last_tz_locn) && preg_match( $tz_regex, $tz_locn ) ) { - dbg_error_log( 'PUT', ' Setting timezone to %s', $tz_locn ); - if ( $tz_locn != '' ) { - $qry->QDo('SET TIMEZONE TO \''.$tz_locn."'" ); - } - $last_tz_locn = $tz_locn; - } - $params = array( ':tzid' => $tzid); - $qry = new AwlQuery('SELECT tz_locn FROM time_zone WHERE tz_id = :tzid', $params ); - if ( $qry->Exec('PUT',__LINE__,__FILE__) && $qry->rows() == 0 ) { - $params[':tzlocn'] = $tz_locn; - $params[':tzspec'] = (isset($tz) ? $tz->Render() : null ); - $qry->QDo('INSERT INTO time_zone (tz_id, tz_locn, tz_spec) VALUES(:tzid,:tzlocn,:tzspec)', $params ); - } - if ( !isset($tz_locn) || $tz_locn == '' ) $tz_locn = $tzid; - + $timezones = $ic->GetComponents('VTIMEZONE'); + foreach( $timezones AS $k => $tz ) { + if ( $tz->GetPValue('TZID') != $tzid ) { + /** + * We'll pretend they didn't forget to give us a TZID and that they + * really hope the server is running in the timezone they supplied... but be noisy about it. + */ + dbg_error_log( 'ERROR', ' Event includes TZID[%s] but uses TZID[%s]!', $tz->GetPValue('TZID'), $tzid ); + $tzid = $tz->GetPValue('TZID'); } + // This is the one + $tz_locn = $tz->GetPValue('X-LIC-LOCATION'); + if ( ! isset($tz_locn) ) { + if ( preg_match( '#([^/]+/[^/]+)$#', $tzid, $matches ) ) + $tz_locn = $matches[1]; + else if ( isset($tzid) && $tzid != '' ) { + dbg_error_log( 'ERROR', ' Couldn\'t guess Olsen TZ from TZID[%s]. This may end in tears...', $tzid ); + } + } + else { + if ( ! preg_match( $tz_regex, $tz_locn ) ) { + if ( preg_match( '#([^/]+/[^/]+)$#', $tzid, $matches ) ) $tz_locn = $matches[1]; + } + } + + dbg_error_log( 'PUT', ' Using TZID[%s] and location of [%s]', $tzid, (isset($tz_locn) ? $tz_locn : '') ); + if ( isset($tz_locn) && ($tz_locn != $last_tz_locn) && preg_match( $tz_regex, $tz_locn ) ) { + dbg_error_log( 'PUT', ' Setting timezone to %s', $tz_locn ); + if ( $tz_locn != '' ) { + $qry->QDo('SET TIMEZONE TO \''.$tz_locn."'" ); + } + $last_tz_locn = $tz_locn; + } + $params = array( ':tzid' => $tzid); + $qry = new AwlQuery('SELECT tz_locn FROM time_zone WHERE tz_id = :tzid', $params ); + if ( $qry->Exec('PUT',__LINE__,__FILE__) && $qry->rows() == 0 ) { + $params[':tzlocn'] = $tz_locn; + $params[':tzspec'] = (isset($tz) ? $tz->Render() : null ); + $qry->QDo('INSERT INTO time_zone (tz_id, tz_locn, tz_spec) VALUES(:tzid,:tzlocn,:tzspec)', $params ); + } + if ( !isset($tz_locn) || $tz_locn == '' ) $tz_locn = $tzid; + } $created = $first->GetPValue('CREATED');