Commit 9eb72b3b authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #122 in ZP/z-push from feature/ZP-685-New-backend-CalDAV to develop

* commit '4c9dd864':
  ZP-685 Move utils functions to TimezoneUtil. Released under the Affero GNU General Public License (AGPL) version 3.
  ZP-685 Fix misspelling. Released under the Affero GNU General Public License (AGPL) version 3.
  ZP-685 Date/Time function changes. Released under the Affero GNU General Public License (AGPL) version 3.
  ZP-685 New backend CalDAV. Released under the Affero GNU General Public License (AGPL) version 3.
parents bc1c1ace 4c9dd864
The Author of this backend is dupondje, I could have modified it.
You can find the original code here:
https://github.com/dupondje/PHP-Push-2
REQUIREMENTS:
php-curl
libawl-php
INSTALL:
Add your awl folder to the include_path variable (/etc/php.ini or similar)
CalDAV server (DAViCal, Sabredav, Sogo, Owncloud...)
This diff is collapsed.
<?php
/***********************************************
* File : config.php
* Project : Z-Push
* Descr : CalDAV backend configuration file
*
* Created : 27.11.2012
*
* Copyright 2012 - 2014 Jean-Louis Dupond
*
* Jean-Louis Dupond released this code as AGPLv3 here: https://github.com/dupondje/PHP-Push-2/issues/93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation with the following additional
* term according to sec. 7:
*
* According to sec. 7 of the GNU Affero General Public License, version 3,
* the terms of the AGPL are supplemented with the following terms:
*
* "Zarafa" is a registered trademark of Zarafa B.V.
* "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
* The licensing of the Program under the AGPL does not imply a trademark license.
* Therefore any rights, title and interest in our trademarks remain entirely with us.
*
* However, if you propagate an unmodified version of the Program you are
* allowed to use the term "Z-Push" to indicate that you distribute the Program.
* Furthermore you may use our trademarks where it is necessary to indicate
* the intended purpose of a product or service provided you use it in accordance
* with honest practices in industrial or commercial matters.
* If you want to propagate modified versions of the Program under the name "Z-Push",
* you may only do so if you have a written permission by Zarafa Deutschland GmbH
* (to acquire a permission please contact Zarafa at trademark@zarafa.com).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Consult LICENSE file for details
************************************************/
// ************************
// BackendCalDAV settings
// ************************
// Server protocol: http or https
define('CALDAV_PROTOCOL', 'https');
// Server name
define('CALDAV_SERVER', 'caldavserver.domain.com');
// Server port
define('CALDAV_PORT', '443');
// Path
define('CALDAV_PATH', '/caldav.php/%u/');
// Default CalDAV folder (calendar folder/principal). This will be marked as the default calendar in the mobile
define('CALDAV_PERSONAL', 'PRINCIPAL');
// If the CalDAV server supports the sync-collection operation
// DAViCal, SOGo and SabreDav support it
// SabreDav version must be at least 1.9.0, otherwise set this to false
// Setting this to false will work with most servers, but it will be slower
define('CALDAV_SUPPORTS_SYNC', false);
// Maximum period to sync.
// Some servers don't support more than 10 years so you will need to change this
define('CALDAV_MAX_SYNC_PERIOD', 2147483647);
\ No newline at end of file
...@@ -74,6 +74,9 @@ class BackendCombinedConfig { ...@@ -74,6 +74,9 @@ class BackendCombinedConfig {
'v' => array( 'v' => array(
'name' => 'BackendVCardDir', 'name' => 'BackendVCardDir',
), ),
'c' => array(
'name' => 'BackendCalDAV',
),
), ),
'delimiter' => '/', 'delimiter' => '/',
//force one type of folder to one backend //force one type of folder to one backend
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -1100,25 +1100,42 @@ class TimezoneUtil { ...@@ -1100,25 +1100,42 @@ class TimezoneUtil {
ZLog::Write(LOGLEVEL_DEBUG, "TimezoneUtil::GetFullTZ() for ". $phptimezone); ZLog::Write(LOGLEVEL_DEBUG, "TimezoneUtil::GetFullTZ() for ". $phptimezone);
$servertzname = self::guessTZNameFromPHPName($phptimezone); $servertzname = self::guessTZNameFromPHPName($phptimezone);
$offset = self::$tzonesoffsets[$servertzname]; return self::GetFullTZFromTZName($servertzname);
}
/**
* Returns a full timezone array
*
* @param string $tzname a TZID value
*
* @access public
* @return array
*/
static public function GetFullTZFromTZName($tzname) {
if (!array_key_exists($tzname, self::$tzonesoffsets)) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("TimezoneUtil::GetFullTZFromTZName('%s'): Is a PHP TimeZone, converting", $tzname));
$tzname = self::guessTZNameFromPHPName($tzname);
}
$offset = self::$tzonesoffsets[$tzname];
$tz = array( $tz = array(
"bias" => $offset[0], "bias" => $offset[0],
"tzname" => self::encodeTZName(self::getMSTZnameFromTZName($servertzname)), "tzname" => self::encodeTZName(self::getMSTZnameFromTZName($tzname)),
"dstendyear" => $offset[3], "dstendyear" => $offset[3],
"dstendmonth" => $offset[4], "dstendmonth" => $offset[4],
"dstendday" => $offset[6], "dstendday" => $offset[5],
"dstendweek" => $offset[5], "dstendweek" => $offset[6],
"dstendhour" => $offset[7], "dstendhour" => $offset[7],
"dstendminute" => $offset[8], "dstendminute" => $offset[8],
"dstendsecond" => $offset[9], "dstendsecond" => $offset[9],
"dstendmillis" => $offset[10], "dstendmillis" => $offset[10],
"stdbias" => $offset[1], "stdbias" => $offset[1],
"tznamedst" => self::encodeTZName(self::getMSTZnameFromTZName($servertzname)), "tznamedst" => self::encodeTZName(self::getMSTZnameFromTZName($tzname)),
"dststartyear" => $offset[11], "dststartyear" => $offset[11],
"dststartmonth" => $offset[12], "dststartmonth" => $offset[12],
"dststartday" => $offset[14], "dststartday" => $offset[13],
"dststartweek" => $offset[13], "dststartweek" => $offset[14],
"dststarthour" => $offset[15], "dststarthour" => $offset[15],
"dststartminute" => $offset[16], "dststartminute" => $offset[16],
"dststartsecond" => $offset[17], "dststartsecond" => $offset[17],
...@@ -1210,7 +1227,7 @@ class TimezoneUtil { ...@@ -1210,7 +1227,7 @@ class TimezoneUtil {
* @access public * @access public
* @return string * @return string
*/ */
static private function getMSTZnameFromTZName($name) { static public function getMSTZnameFromTZName($name) {
foreach (self::$mstzones as $mskey => $msdefs) { foreach (self::$mstzones as $mskey => $msdefs) {
if ($name == $msdefs[0]) if ($name == $msdefs[0])
return $msdefs[1]; return $msdefs[1];
...@@ -1278,4 +1295,60 @@ class TimezoneUtil { ...@@ -1278,4 +1295,60 @@ class TimezoneUtil {
return $packed; return $packed;
} }
/**
* Generate date object from string and timezone.
*
* @param string $value
* @param string $timezone
*
* @access public
* @return int epoch
*/
public static function MakeUTCDate($value, $timezone = null) {
$tz = null;
if ($timezone) {
$tz = timezone_open($timezone);
}
if (!$tz) {
//If there is no timezone set, we use the default timezone
$tz = timezone_open(date_default_timezone_get());
}
//20110930T090000Z
$date = date_create_from_format('Ymd\THis\Z', $value, timezone_open("UTC"));
if (!$date) {
//20110930T090000
$date = date_create_from_format('Ymd\THis', $value, $tz);
}
if (!$date) {
//20110930 (Append T000000Z to the date, so it starts at midnight)
$date = date_create_from_format('Ymd\THis\Z', $value . "T000000Z", $tz);
}
return date_timestamp_get($date);
}
/**
* Generate a tzid from various formats
*
* @param str $timezone
*
* @access public
* @return timezone id
*/
public static function ParseTimezone($timezone) {
//(GMT+01.00) Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
if (preg_match('/GMT(\\+|\\-)0(\d)/', $timezone, $matches)) {
return "Etc/GMT" . $matches[1] . $matches[2];
}
//(GMT+10.00) XXX / XXX / XXX / XXX
if (preg_match('/GMT(\\+|\\-)1(\d)/', $timezone, $matches)) {
return "Etc/GMT" . $matches[1] . "1" . $matches[2];
}
///inverse.ca/20101018_1/Europe/Amsterdam or /inverse.ca/20101018_1/America/Argentina/Buenos_Aires
if (preg_match('/\/[.[:word:]]+\/\w+\/(\w+)\/([\w\/]+)/', $timezone, $matches)) {
return $matches[1] . "/" . $matches[2];
}
return TimezoneUtil::getMSTZnameFromTZName(trim($timezone, '"'));
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment