From a27f28d7bfcd2efa0fe24f34e17339a77d0535d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6=C3=9Fl?= Date: Mon, 30 Jul 2012 19:07:20 +0000 Subject: [PATCH 01/84] Refactoring to make common/ more independent of the framework --- dav/Changelog.txt | 3 +++ dav/calendar.friendica.fnk.php | 11 +++++++++++ dav/common/calendar.fnk.php | 27 ++++++++------------------- dav/main.php | 6 ++++++ 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/dav/Changelog.txt b/dav/Changelog.txt index 90117b718..2a8304c8a 100644 --- a/dav/Changelog.txt +++ b/dav/Changelog.txt @@ -1,3 +1,6 @@ +v0.2.1 +[REFACTOR] Remove some Friendica-specific code out of the "common"-folder + v0.2.0 ====== [FEATURE] Multiple private Calendars can be created. Each calendar can have its own default color; single events of a calendar can override this setting. diff --git a/dav/calendar.friendica.fnk.php b/dav/calendar.friendica.fnk.php index fff3447e4..7019cb500 100644 --- a/dav/calendar.friendica.fnk.php +++ b/dav/calendar.friendica.fnk.php @@ -10,6 +10,7 @@ if (isset($uri["path"]) && strlen($uri["path"]) > 1) { define("CALDAV_SQL_DB", ""); define("CALDAV_SQL_PREFIX", "dav_"); define("CALDAV_URL_PREFIX", $path . "dav/"); +define("DAV_APPNAME", "Friendica"); define("CALDAV_NAMESPACE_PRIVATE", 1); @@ -17,9 +18,11 @@ define("CALDAV_FRIENDICA_MINE", "friendica-mine"); define("CALDAV_FRIENDICA_CONTACTS", "friendica-contacts"); $GLOBALS["CALDAV_PRIVATE_SYSTEM_CALENDARS"] = array(CALDAV_FRIENDICA_MINE, CALDAV_FRIENDICA_CONTACTS); +$GLOBALS["CALDAV_PRIVATE_SYSTEM_BACKENDS"] = array("Sabre_CalDAV_Backend_Friendica"); define("CARDDAV_NAMESPACE_COMMUNITYCONTACTS", 1); define("CARDDAV_NAMESPACE_PHONECONTACTS", 2); +$GLOBALS["CARDDAV_PRIVATE_SYSTEM_BACKENDS"] = array("Sabre_CardDAV_Backend_FriendicaCommunity"); define("CALDAV_MAX_YEAR", date("Y") + 5); @@ -151,6 +154,14 @@ function dav_compat_get_max_private_calendars() return null; } +/** + * @return string + */ +function dav_compat_get_hostname() { + $a = get_app(); + return $a->get_hostname(); +} + /** * @param int $namespace * @param int $namespace_id diff --git a/dav/common/calendar.fnk.php b/dav/common/calendar.fnk.php index 1bfe97e2f..ea04bdae0 100644 --- a/dav/common/calendar.fnk.php +++ b/dav/common/calendar.fnk.php @@ -108,7 +108,7 @@ class vcard_source_data */ function vcard_source_compile($vcardsource) { - $str = "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Friendica//DAV-Plugin//EN\r\n"; + $str = "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//" . DAV_APPNAME . "//DAV-Plugin//EN\r\n"; $str .= "N:" . str_replace(";", ",", $vcardsource->name_last) . ";" . str_replace(";", ",", $vcardsource->name_first) . ";" . str_replace(";", ",", $vcardsource->name_middle) . ";;\r\n"; $str .= "FN:" . str_replace(";", ",", $vcardsource->name_first) . " " . str_replace(";", ",", $vcardsource->name_middle) . " " . str_replace(";", ",", $vcardsource->name_last) . "\r\n"; $str .= "REV:" . str_replace(" ", "T", $vcardsource->last_update) . "Z\r\n"; @@ -196,13 +196,9 @@ function icalendar_sanitize_string($str = "") */ function dav_createRootCalendarNode() { - $caldavBackend_std = Sabre_CalDAV_Backend_Private::getInstance(); - $caldavBackend_community = Sabre_CalDAV_Backend_Friendica::getInstance(); - - return new Sabre_CalDAV_AnimexxCalendarRootNode(Sabre_DAVACL_PrincipalBackend_Std::getInstance(), array( - $caldavBackend_std, - $caldavBackend_community, - )); + $backends = array(Sabre_CalDAV_Backend_Private::getInstance()); + foreach ($GLOBALS["CALDAV_PRIVATE_SYSTEM_BACKENDS"] as $backendclass) $backends[] = $backendclass::getInstance(); + return new Sabre_CalDAV_AnimexxCalendarRootNode(Sabre_DAVACL_PrincipalBackend_Std::getInstance(), $backends); } /** @@ -210,13 +206,10 @@ function dav_createRootCalendarNode() */ function dav_createRootContactsNode() { - $carddavBackend_std = Sabre_CardDAV_Backend_Std::getInstance(); - $carddavBackend_community = Sabre_CardDAV_Backend_FriendicaCommunity::getInstance(); + $backends = array(Sabre_CardDAV_Backend_Std::getInstance()); + foreach ($GLOBALS["CARDDAV_PRIVATE_SYSTEM_BACKENDS"] as $backendclass) $backends[] = $backendclass::getInstance(); - return new Sabre_CardDAV_AddressBookRootFriendica(Sabre_DAVACL_PrincipalBackend_Std::getInstance(), array( - $carddavBackend_std, - $carddavBackend_community, - )); + return new Sabre_CardDAV_AddressBookRootFriendica(Sabre_DAVACL_PrincipalBackend_Std::getInstance(), $backends); } @@ -247,10 +240,6 @@ function dav_create_server($force_authentication = false, $needs_caldav = true, $authPlugin = new Sabre_DAV_Auth_Plugin(Sabre_DAV_Auth_Backend_Std::getInstance(), 'SabreDAV'); $server->addPlugin($authPlugin); - $aclPlugin = new Sabre_DAVACL_Plugin_Friendica(); - $aclPlugin->defaultUsernamePath = "principals/users"; - $server->addPlugin($aclPlugin); - if ($needs_caldav) { $caldavPlugin = new Sabre_CalDAV_Plugin(); $server->addPlugin($caldavPlugin); @@ -353,7 +342,7 @@ function dav_create_empty_vevent($uid = "") { $a = get_app(); if ($uid == "") $uid = uniqid(); - return Sabre_VObject_Reader::read("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Friendica//DAV-Plugin//EN\r\nBEGIN:VEVENT\r\nUID:" . $uid . "@" . $a->get_hostname() . + return Sabre_VObject_Reader::read("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//" . DAV_APPNAME . "//DAV-Plugin//EN\r\nBEGIN:VEVENT\r\nUID:" . $uid . "@" . dav_compat_get_hostname() . "\r\nDTSTAMP:" . date("Ymd") . "T" . date("His") . "Z\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"); } diff --git a/dav/main.php b/dav/main.php index 03f342bd2..a56862aec 100644 --- a/dav/main.php +++ b/dav/main.php @@ -100,8 +100,14 @@ function dav_init(&$a) $server = dav_create_server(); + $browser = new Sabre_DAV_Browser_Plugin(); $server->addPlugin($browser); + + $aclPlugin = new Sabre_DAVACL_Plugin_Friendica(); + $aclPlugin->defaultUsernamePath = "principals/users"; + $server->addPlugin($aclPlugin); + $server->exec(); killme(); From a9924ea4430c1990d5b6795610d12f8c4f4f015b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6=C3=9Fl?= Date: Mon, 30 Jul 2012 19:18:10 +0000 Subject: [PATCH 02/84] Prevent a notice --- dav/common/calendar.fnk.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dav/common/calendar.fnk.php b/dav/common/calendar.fnk.php index ea04bdae0..10d88833d 100644 --- a/dav/common/calendar.fnk.php +++ b/dav/common/calendar.fnk.php @@ -235,7 +235,7 @@ function dav_create_server($force_authentication = false, $needs_caldav = true, // The object tree needs in turn to be passed to the server class $server = new Sabre_DAV_Server($tree); - $server->setBaseUri(CALDAV_URL_PREFIX); + if (CALDAV_URL_PREFIX != "") $server->setBaseUri(CALDAV_URL_PREFIX); $authPlugin = new Sabre_DAV_Auth_Plugin(Sabre_DAV_Auth_Backend_Std::getInstance(), 'SabreDAV'); $server->addPlugin($authPlugin); From f039582421bddce3f9f68e62962ad5818cf71f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6=C3=9Fl?= Date: Thu, 2 Aug 2012 20:26:52 +0000 Subject: [PATCH 03/84] More refactoring, mainly of the addressbook/VCARD-part --- dav/calendar.friendica.fnk.php | 51 ++++- dav/common/calendar.fnk.php | 7 +- dav/common/dav_caldav_backend_private.inc.php | 2 +- .../dav_caldav_calendar_private.inc.php | 50 +++++ dav/common/dav_carddav_backend_common.inc.php | 116 ++++++++++ ...hp => dav_carddav_backend_private.inc.php} | 143 ++++-------- .../dav_carddav_backend_virtual.inc.php | 151 +++++++++++++ dav/common/dav_user_calendars.inc.php | 1 - dav/database-init.inc.php | 106 +++++---- ...v_caldav_backend_virtual_friendica.inc.php | 2 +- ..._carddav_backend_virtual_friendica.inc.php | 203 ++++-------------- dav/main.php | 20 +- 12 files changed, 531 insertions(+), 321 deletions(-) create mode 100644 dav/common/dav_caldav_calendar_private.inc.php create mode 100644 dav/common/dav_carddav_backend_common.inc.php rename dav/common/{dav_carddav_backend_std.inc.php => dav_carddav_backend_private.inc.php} (57%) create mode 100644 dav/common/dav_carddav_backend_virtual.inc.php diff --git a/dav/calendar.friendica.fnk.php b/dav/calendar.friendica.fnk.php index 7019cb500..60dd9c6bd 100644 --- a/dav/calendar.friendica.fnk.php +++ b/dav/calendar.friendica.fnk.php @@ -13,16 +13,18 @@ define("CALDAV_URL_PREFIX", $path . "dav/"); define("DAV_APPNAME", "Friendica"); define("CALDAV_NAMESPACE_PRIVATE", 1); - define("CALDAV_FRIENDICA_MINE", "friendica-mine"); define("CALDAV_FRIENDICA_CONTACTS", "friendica-contacts"); $GLOBALS["CALDAV_PRIVATE_SYSTEM_CALENDARS"] = array(CALDAV_FRIENDICA_MINE, CALDAV_FRIENDICA_CONTACTS); $GLOBALS["CALDAV_PRIVATE_SYSTEM_BACKENDS"] = array("Sabre_CalDAV_Backend_Friendica"); -define("CARDDAV_NAMESPACE_COMMUNITYCONTACTS", 1); -define("CARDDAV_NAMESPACE_PHONECONTACTS", 2); -$GLOBALS["CARDDAV_PRIVATE_SYSTEM_BACKENDS"] = array("Sabre_CardDAV_Backend_FriendicaCommunity"); +define("CARDDAV_NAMESPACE_PRIVATE", 1); +define("CARDDAV_FRIENDICA_CONTACT", "friendica"); +$GLOBALS["CARDDAV_PRIVATE_SYSTEM_ADDRESSBOOKS"] = array(CARDDAV_FRIENDICA_CONTACT); +$GLOBALS["CARDDAV_PRIVATE_SYSTEM_BACKENDS"] = array("Sabre_CardDAV_Backend_Friendica"); + +$GLOBALS["CALDAV_ACL_PLUGIN_CLASS"] = "Sabre_DAVACL_Plugin_Friendica"; define("CALDAV_MAX_YEAR", date("Y") + 5); @@ -229,3 +231,44 @@ function wdcal_create_std_calendars() $stms = wdcal_create_std_calendars_get_statements($a->user["uid"]); foreach ($stms as $stmt) q($stmt); } + + + + +/** + * @param int $user_id + * @param bool $withcheck + * @return array + */ +function wdcal_create_std_addressbooks_get_statements($user_id, $withcheck = true) +{ + $stms = array(); + $a = get_app(); + $uris = array( + 'private' => t("Private Addresses"), + CARDDAV_FRIENDICA_CONTACT => t("Friendica Contacts"), + ); + foreach ($uris as $uri => $name) { + $cals = q("SELECT * FROM %s%saddressbooks WHERE `namespace` = %d AND `namespace_id` = %d AND `uri` = '%s'", + CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CALDAV_NAMESPACE_PRIVATE, IntVal($user_id), dbesc($uri)); + if (count($cals) == 0 || !$withcheck) $stms[] = + sprintf("INSERT INTO %s%saddressbooks (`namespace`, `namespace_id`, `displayname`, `ctag`, `uri`) + VALUES (%d, %d, '%s', 1, '%s')", + CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CARDDAV_NAMESPACE_PRIVATE, IntVal($user_id), dbesc($name), dbesc($uri)); + } + return $stms; +} + +/** + */ +function wdcal_create_std_addressbooks() +{ + $a = get_app(); + if (!local_user()) return; + + $privates = q("SELECT COUNT(*) num FROM %s%addressbooks WHERE `namespace` = %d AND `namespace_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CARDDAV_NAMESPACE_PRIVATE, IntVal($a->user["uid"])); + if ($privates[0]["num"] > 0) return; + + $stms = wdcal_create_std_addressbooks_get_statements($a->user["uid"]); + foreach ($stms as $stmt) q($stmt); +} diff --git a/dav/common/calendar.fnk.php b/dav/common/calendar.fnk.php index 10d88833d..149511191 100644 --- a/dav/common/calendar.fnk.php +++ b/dav/common/calendar.fnk.php @@ -249,6 +249,11 @@ function dav_create_server($force_authentication = false, $needs_caldav = true, $server->addPlugin($carddavPlugin); } + $aclPlugin = new $GLOBALS["CALDAV_ACL_PLUGIN_CLASS"](); + $aclPlugin->defaultUsernamePath = "principals/users"; + $server->addPlugin($aclPlugin); + + if ($force_authentication) $server->broadcastEvent('beforeMethod', array("GET", "/")); // Make it authenticate return $server; @@ -275,7 +280,7 @@ function dav_get_current_user_calendars(&$server, $with_privilege = "") $calendars = array(); /** @var Sabre_DAVACL_Plugin $aclplugin */ $aclplugin = $server->getPlugin("acl"); - foreach ($children as $child) if (is_a($child, "Sabre_CalDAV_Calendar")) { + foreach ($children as $child) if (is_a($child, "Sabre_CalDAV_Calendar") || is_subclass_of($child, "Sabre_CalDAV_Calendar")) { if ($with_privilege != "") { $caluri = $calendar_path . $child->getName(); if ($aclplugin->checkPrivileges($caluri, $with_privilege, Sabre_DAVACL_Plugin::R_PARENT, false)) $calendars[] = $child; diff --git a/dav/common/dav_caldav_backend_private.inc.php b/dav/common/dav_caldav_backend_private.inc.php index 5356280a4..1eb3b3656 100644 --- a/dav/common/dav_caldav_backend_private.inc.php +++ b/dav/common/dav_caldav_backend_private.inc.php @@ -177,7 +177,7 @@ class Sabre_CalDAV_Backend_Private extends Sabre_CalDAV_Backend_Common "principaluri" => $principalUri, '{' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '}getctag' => $cal['ctag'] ? $cal['ctag'] : '0', '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}supported-calendar-component-set' => new Sabre_CalDAV_Property_SupportedCalendarComponentSet($components), - "calendar_class" => "Sabre_CalDAV_Calendar", + "calendar_class" => "Sabre_CalDAV_Calendar_Private", ); foreach ($this->propertyMap as $key=> $field) $dat[$key] = $cal[$field]; diff --git a/dav/common/dav_caldav_calendar_private.inc.php b/dav/common/dav_caldav_calendar_private.inc.php new file mode 100644 index 000000000..65f7c2b03 --- /dev/null +++ b/dav/common/dav_caldav_calendar_private.inc.php @@ -0,0 +1,50 @@ + '{DAV:}read', + 'principal' => $this->calendarInfo['principaluri'], + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}write', + 'principal' => $this->calendarInfo['principaluri'], + 'protected' => true, + ), + /* + array( + 'privilege' => '{DAV:}read', + 'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-write', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}write', + 'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-write', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}read', + 'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-read', + 'protected' => true, + ), + array( + 'privilege' => '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}read-free-busy', + 'principal' => '{DAV:}authenticated', + 'protected' => true, + ), + */ + + ); + + } + + + +} \ No newline at end of file diff --git a/dav/common/dav_carddav_backend_common.inc.php b/dav/common/dav_carddav_backend_common.inc.php new file mode 100644 index 000000000..4279f8a1c --- /dev/null +++ b/dav/common/dav_carddav_backend_common.inc.php @@ -0,0 +1,116 @@ + $newValue) { + + switch ($property) { + case '{DAV:}displayname' : + $updates['displayname'] = $newValue; + break; + case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' : + $updates['description'] = $newValue; + break; + default : + // If any unsupported values were being updated, we must + // let the entire request fail. + return false; + } + + } + + // No values are being updated? + if (!$updates) { + return false; + } + + $query = 'UPDATE ' . CALDAV_SQL_DB . CALDAV_SQL_PREFIX . 'addressbooks SET ctag = ctag + 1 '; + foreach ($updates as $key=> $value) { + $query .= ', `' . dbesc($key) . '` = ' . dbesc($key) . ' '; + } + $query .= ' WHERE id = ' . IntVal($addressBookId); + q($query); + + return true; + + } + + /** + * @param int $addressbookId + */ + protected function increaseAddressbookCtag($addressbookId) + { + q("UPDATE %s%saddressbooks SET `ctag` = `ctag` + 1 WHERE `id` = '%d'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId)); + self::$addressbookCache = array(); + } +} \ No newline at end of file diff --git a/dav/common/dav_carddav_backend_std.inc.php b/dav/common/dav_carddav_backend_private.inc.php similarity index 57% rename from dav/common/dav_carddav_backend_std.inc.php rename to dav/common/dav_carddav_backend_private.inc.php index e257d156b..71923b998 100644 --- a/dav/common/dav_carddav_backend_std.inc.php +++ b/dav/common/dav_carddav_backend_private.inc.php @@ -1,17 +1,6 @@ getNamespace()) return array(); $addressBooks = array(); - $books = q("SELECT id, uri, displayname, principaluri, description, ctag FROM %s%saddressbooks_phone WHERE principaluri = '%s'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($principalUri)); - if (count($books) == 0) { - q("INSERT INTO %s%saddressbooks_phone (uid, principaluri, displayname, uri, description, ctag) VALUES (%d, '%s', '%s', '%s', '%s', 1)", - CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $uid, dbesc($principalUri), 'Other', 'phone', 'Manually added contacts' - ); - $books = q("SELECT id, uri, displayname, principaluri, description, ctag FROM %s%saddressbooks_phone WHERE principaluri = '%s'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($principalUri)); - } + $books = q("SELECT * FROM %s%saddressbooks WHERE `namespace` = %d AND `namespace_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($n["namespace"]), IntVal($n["namespace_id"])); foreach ($books as $row) { + if (in_array($row["uri"], $GLOBALS["CARDDAV_PRIVATE_SYSTEM_ADDRESSBOOKS"])) continue; + $addressBooks[] = array( - 'id' => CARDDAV_NAMESPACE_PHONECONTACTS . "-" . $row['id'], + 'id' => $row['id'], 'uri' => $row['uri'], - 'principaluri' => $row['principaluri'], + 'principaluri' => $principalUri, '{DAV:}displayname' => $row['displayname'], '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], '{http://calendarserver.org/ns/}getctag' => $row['ctag'], @@ -76,57 +80,6 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract } - /** - * Updates an addressbook's properties - * - * See Sabre_DAV_IProperties for a description of the mutations array, as - * well as the return value. - * - * @param mixed $addressBookId - * @param array $mutations - * @throws Sabre_DAV_Exception_Forbidden - * @see Sabre_DAV_IProperties::updateProperties - * @return bool|array - */ - public function updateAddressBook($addressBookId, array $mutations) - { - $x = explode("-", $addressBookId); - - $updates = array(); - - foreach ($mutations as $property=> $newValue) { - - switch ($property) { - case '{DAV:}displayname' : - $updates['displayname'] = $newValue; - break; - case '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' : - $updates['description'] = $newValue; - break; - default : - // If any unsupported values were being updated, we must - // let the entire request fail. - return false; - } - - } - - // No values are being updated? - if (!$updates) { - return false; - } - - $query = 'UPDATE ' . CALDAV_SQL_DB . CALDAV_SQL_PREFIX . 'addressbooks_phone SET ctag = ctag + 1 '; - foreach ($updates as $key=> $value) { - $query .= ', `' . dbesc($key) . '` = ' . dbesc($key) . ' '; - } - $query .= ' WHERE id = ' . IntVal($x[1]); - q($query); - - return true; - - } - /** * Creates a new address book * @@ -138,6 +91,8 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract */ public function createAddressBook($principalUri, $url, array $properties) { + $uid = dav_compat_principal2uid($principalUri); + $values = array( 'displayname' => null, 'description' => null, @@ -160,8 +115,8 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract } - q("INSERT INTO %s%saddressbooks_phone (uri, displayname, description, principaluri, ctag) VALUES ('%s', '%s', '%s', '%s', 1)", - CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($values["uri"]), dbesc($values["displayname"]), dbesc($values["description"]), dbesc($values["principaluri"]) + q("INSERT INTO %s%saddressbooks (`uri`, `displayname`, `description`, `namespace`, `namespace_id`, `ctag`) VALUES ('%s', '%s', '%s', %d, %d, 1)", + CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($values["uri"]), dbesc($values["displayname"]), dbesc($values["description"]), CARDDAV_NAMESPACE_PRIVATE, IntVal($uid) ); } @@ -174,9 +129,8 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract */ public function deleteAddressBook($addressBookId) { - $x = explode("-", $addressBookId); - q("DELETE FROM %s%scards WHERE namespace = %d AND namespace_id = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1])); - q("DELETE FROM %s%saddressbooks_phone WHERE id = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1])); + q("DELETE FROM %s%saddressbookobjects WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId)); + q("DELETE FROM %s%saddressbooks WHERE `addressbook_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId)); } /** @@ -200,10 +154,8 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract */ public function getCards($addressbookId) { - $x = explode("-", $addressbookId); - - $r = q('SELECT id, carddata, uri, lastmodified, etag, size, contact FROM %s%scards WHERE namespace = %d AND namespace_id = %d AND manually_deleted = 0', - CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]) + $r = q('SELECT `id`, `carddata`, `uri`, `lastmodified`, `etag`, `size`, `contact` FROM %s%saddressbookobjects WHERE `addressbook_id` = %d AND `manually_deleted` = 0', + CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId) ); if ($r) return $r; return array(); @@ -222,9 +174,8 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract */ public function getCard($addressBookId, $cardUri) { - $x = explode("-", $addressBookId); - $x = q("SELECT id, carddata, uri, lastmodified, etag, size FROM %s%scards WHERE namespace = %d AND namespace_id = %d AND uri = '%s'", - CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]), dbesc($cardUri)); + $x = q("SELECT `id`, `carddata`, `uri`, `lastmodified`, `etag`, `size` FROM %s%saddressbookobjects WHERE `addressbook_id` = %d AND `uri` = '%s'", + CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId), dbesc($cardUri)); if (count($x) == 0) throw new Sabre_DAV_Exception_NotFound(); return $x[0]; } @@ -257,14 +208,12 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract */ public function createCard($addressBookId, $cardUri, $cardData) { - $x = explode("-", $addressBookId); - $etag = md5($cardData); - q("INSERT INTO %s%scards (carddata, uri, lastmodified, namespace, namespace_id, etag, size) VALUES ('%s', '%s', %d, %d, '%s', %d)", - CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($cardData), dbesc($cardUri), time(), IntVal($x[0]), IntVal($x[1]), $etag, strlen($cardData) + q("INSERT INTO %s%saddressbookobjects (`carddata`, `uri`, `lastmodified`, `addressbook_id`, `etag`, `size`) VALUES ('%s', '%s', NOW(), %d, '%s', %d)", + CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($cardData), dbesc($cardUri), IntVal($addressBookId), dbesc($etag), strlen($cardData) ); - q('UPDATE %s%saddressbooks_phone SET ctag = ctag + 1 WHERE id = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1])); + q('UPDATE %s%saddressbooks SET `ctag` = `ctag` + 1 WHERE `id` = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId)); return '"' . $etag . '"'; @@ -298,14 +247,12 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract */ public function updateCard($addressBookId, $cardUri, $cardData) { - $x = explode("-", $addressBookId); - $etag = md5($cardData); - q("UPDATE %s%scards SET carddata = '%s', lastmodified = %d, etag = '%s', size = %d, manually_edited = 1 WHERE uri = '%s' AND namespace = %d AND namespace_id =%d", - CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($cardData), time(), $etag, strlen($cardData), dbesc($cardUri), IntVal($x[10]), IntVal($x[1]) + q("UPDATE %s%saddressbookobjects SET `carddata` = '%s', `lastmodified` = NOW(), `etag` = '%s', `size` = %d, `manually_edited` = 1 WHERE `uri` = '%s' AND `addressbook_id` = %d", + CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($cardData), dbesc($etag), strlen($cardData), dbesc($cardUri), IntVal($addressBookId) ); - q('UPDATE %s%saddressbooks_phone SET ctag = ctag + 1 WHERE id = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1])); + q('UPDATE %s%saddressbooks SET `ctag` = `ctag` + 1 WHERE `id` = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId)); return '"' . $etag . '"'; } @@ -320,10 +267,8 @@ class Sabre_CardDAV_Backend_Std extends Sabre_CardDAV_Backend_Abstract */ public function deleteCard($addressBookId, $cardUri) { - $x = explode("-", $addressBookId); - - q("DELETE FROM %s%scards WHERE namespace = %d AND namespace_id = %d AND uri = '%s'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]), dbesc($cardUri)); - q('UPDATE %s%saddressbooks_phone SET ctag = ctag + 1 WHERE id = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1])); + q("DELETE FROM %s%saddressbookobjects WHERE `addressbook_id` = %d AND `uri` = '%s'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId), dbesc($cardUri)); + q('UPDATE %s%saddressbooks SET `ctag` = `ctag` + 1 WHERE `id` = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId)); return true; } diff --git a/dav/common/dav_carddav_backend_virtual.inc.php b/dav/common/dav_carddav_backend_virtual.inc.php new file mode 100644 index 000000000..98597c694 --- /dev/null +++ b/dav/common/dav_carddav_backend_virtual.inc.php @@ -0,0 +1,151 @@ + IntVal($obj["uri"]), + "carddata" => $obj["carddata"], + "uri" => $obj["uri"], + "lastmodified" => $obj["lastmodified"], + "addressbookid" => $addressbookId, + "etag" => $obj["etag"], + "size" => IntVal($obj["size"]), + ); + return $ret; + } + + + + /** + * @param string $principalUri + * @param string $addressbookUri + * @param array $properties + * @throws Sabre_DAV_Exception_Forbidden + * @return void + */ + public function createAddressBook($principalUri, $addressbookUri, array $properties) + { + throw new Sabre_DAV_Exception_Forbidden(); + } + + /** + * @param string $addressbookId + * @throws Sabre_DAV_Exception_Forbidden + * @return void + */ + public function deleteAddressBook($addressbookId) + { + throw new Sabre_DAV_Exception_Forbidden(); + } + + + /** + * @param string $addressbookId + * @param string $objectUri + * @param string $cardData + * @throws Sabre_DAV_Exception_Forbidden + * @return null|string|void + */ + function createCard($addressbookId, $objectUri, $cardData) + { + throw new Sabre_DAV_Exception_Forbidden(); + } + + /** + * @param string $addressbookId + * @param string $objectUri + * @param string $cardData + * @throws Sabre_DAV_Exception_Forbidden + * @return null|string|void + */ + function updateCard($addressbookId, $objectUri, $cardData) + { + throw new Sabre_DAV_Exception_Forbidden(); + } + + /** + * @param string $addressbookId + * @param string $objectUri + * @throws Sabre_DAV_Exception_Forbidden + * @return void + */ + function deleteCard($addressbookId, $objectUri) + { + throw new Sabre_DAV_Exception_Forbidden(); + } + + +} \ No newline at end of file diff --git a/dav/common/dav_user_calendars.inc.php b/dav/common/dav_user_calendars.inc.php index 62837dc54..b292074d6 100644 --- a/dav/common/dav_user_calendars.inc.php +++ b/dav/common/dav_user_calendars.inc.php @@ -169,7 +169,6 @@ class Sabre_CalDAV_AnimexxUserCalendars implements Sabre_DAV_IExtendedCollection $objs[] = new $calendar["calendar_class"]($this->principalBackend, $backend, $calendar); } } - //$objs[] = new Sabre_CalDAV_AnimexxUserZirkelCalendars($this->principalBackend, $this->caldavBackend, $this->username); return $objs; } diff --git a/dav/database-init.inc.php b/dav/database-init.inc.php index 8cdd9b9b1..7c0d23a3a 100644 --- a/dav/database-init.inc.php +++ b/dav/database-init.inc.php @@ -43,6 +43,39 @@ function dav_get_update_statements($from_version) } + if (in_array($from_version, array(1, 2))) { + $stms[] = "DROP TABLE `dav_addressbooks_phone`"; + $stms[] = "DROP TABLE `dav_addressbooks_community`"; + $stms[] = "DROP TABLE `dav_cards`"; + + $stms[] = "CREATE TABLE IF NOT EXISTS `dav_addressbooks` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `namespace` mediumint(9) NOT NULL, + `namespace_id` int(11) unsigned NOT NULL, + `displayname` varchar(200) NOT NULL, + `description` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, + `uri` varchar(50) NOT NULL, + `ctag` int(11) unsigned NOT NULL DEFAULT '1', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; + + $stms[] = "CREATE TABLE IF NOT EXISTS `dav_addressbookobjects` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `addressbook_id` int(11) unsigned NOT NULL, + `contact` int(11) DEFAULT NULL, + `carddata` mediumtext CHARACTER SET utf8 COLLATE utf8_unicode_ci, + `uri` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, + `lastmodified` timestamp NULL DEFAULT NULL, + `manually_edited` tinyint(4) NOT NULL DEFAULT '0', + `manually_deleted` tinyint(4) NOT NULL DEFAULT '0', + `etag` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, + `size` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `namespace` (`addressbook_id`,`contact`), + KEY `contact` (`contact`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; + } + return $stms; } @@ -54,24 +87,6 @@ function dav_get_create_statements($except = array()) { $arr = array(); - if (!in_array("dav_addressbooks_community", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_addressbooks_community` ( - `uid` int(11) NOT NULL, - `ctag` int(11) unsigned NOT NULL DEFAULT '1', - PRIMARY KEY (`uid`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8"; - - if (!in_array("dav_addressbooks_phone", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_addressbooks_phone` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `uid` int(11) NOT NULL, - `principaluri` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `displayname` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `uri` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `description` text CHARACTER SET utf8 COLLATE utf8_unicode_ci, - `ctag` int(11) unsigned NOT NULL DEFAULT '1', - PRIMARY KEY (`id`), - UNIQUE KEY `principaluri` (`principaluri`,`uri`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8"; - if (!in_array("dav_caldav_log", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_caldav_log` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `uid` mediumint(9) NOT NULL, @@ -82,7 +97,7 @@ function dav_get_create_statements($except = array()) `url` varchar(100) NOT NULL, PRIMARY KEY (`id`), KEY `mitglied` (`uid`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8"; +) ENGINE=InnoDB DEFAULT CHARSET=utf8"; if (!in_array("dav_calendarobjects", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_calendarobjects` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, @@ -98,7 +113,7 @@ function dav_get_create_statements($except = array()) PRIMARY KEY (`id`), UNIQUE KEY `uri` (`uri`), KEY `calendar_id` (`calendar_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8"; +) ENGINE=InnoDB DEFAULT CHARSET=utf8"; if (!in_array("dav_calendars", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_calendars` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -116,7 +131,7 @@ function dav_get_create_statements($except = array()) PRIMARY KEY (`id`), UNIQUE KEY (`namespace` , `namespace_id` , `uri`), KEY `uri` (`uri`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8"; +) ENGINE=InnoDB DEFAULT CHARSET=utf8"; if (!in_array("dav_cal_virtual_object_cache", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_cal_virtual_object_cache` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, @@ -135,7 +150,7 @@ function dav_get_create_statements($except = array()) PRIMARY KEY (`id`), KEY `data_uri` (`data_uri`), KEY `ref_type` (`calendar_id`,`data_end`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8"; +) ENGINE=InnoDB DEFAULT CHARSET=utf8"; if (!in_array("dav_cal_virtual_object_sync", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_cal_virtual_object_sync` ( `calendar_id` int(10) unsigned NOT NULL, @@ -143,23 +158,6 @@ function dav_get_create_statements($except = array()) PRIMARY KEY (`calendar_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8"; - if (!in_array("dav_cards", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_cards` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `namespace` tinyint(3) unsigned NOT NULL, - `namespace_id` int(11) unsigned NOT NULL, - `contact` int(11) DEFAULT NULL, - `carddata` mediumtext CHARACTER SET utf8 COLLATE utf8_unicode_ci, - `uri` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `lastmodified` int(11) unsigned DEFAULT NULL, - `manually_edited` tinyint(4) NOT NULL DEFAULT '0', - `manually_deleted` tinyint(4) NOT NULL DEFAULT '0', - `etag` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `size` int(10) unsigned NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `namespace` (`namespace`,`namespace_id`,`contact`), - KEY `contact` (`contact`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8"; - if (!in_array("dav_jqcalendar", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_jqcalendar` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `ical_recurr_uri` varchar(100) DEFAULT NULL, @@ -190,6 +188,33 @@ function dav_get_create_statements($except = array()) KEY `calendar_id` (`calendar_id`,`calendarobject_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8"; + if (!in_array("dav_addressbooks", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_addressbooks` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `namespace` mediumint(9) NOT NULL, + `namespace_id` int(11) unsigned NOT NULL, + `displayname` varchar(200) NOT NULL, + `description` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, + `uri` varchar(50) NOT NULL, + `ctag` int(11) unsigned NOT NULL DEFAULT '1', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; + + if (!in_array("dav_addressbookobjects", $except)) $arr[] = "CREATE TABLE IF NOT EXISTS `dav_addressbookobjects` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `addressbook_id` int(11) unsigned NOT NULL, + `contact` int(11) DEFAULT NULL, + `carddata` mediumtext CHARACTER SET utf8 COLLATE utf8_unicode_ci, + `uri` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, + `lastmodified` timestamp NULL DEFAULT NULL, + `manually_edited` tinyint(4) NOT NULL DEFAULT '0', + `manually_deleted` tinyint(4) NOT NULL DEFAULT '0', + `etag` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, + `size` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `namespace` (`addressbook_id`,`contact`), + KEY `contact` (`contact`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; + return $arr; } @@ -201,6 +226,7 @@ function dav_check_tables() $x = q("DESCRIBE %s%scalendars", CALDAV_SQL_DB, CALDAV_SQL_PREFIX); if (!$x) return -1; if (count($x) == 9) return 1; // Version 0.1 + // @TODO Detect Version 0.2 if (count($x) == 12) return 0; // Correct return -2; // Unknown version } @@ -229,7 +255,7 @@ function dav_create_tables() function dav_upgrade_tables() { $ver = dav_check_tables(); - if (!in_array($ver, array(1) )) return array("Unknown error"); + if (!in_array($ver, array(1))) return array("Unknown error"); $stms = dav_get_update_statements($ver); $errors = array(); diff --git a/dav/dav_caldav_backend_virtual_friendica.inc.php b/dav/dav_caldav_backend_virtual_friendica.inc.php index 9178aaabb..d2810b4f8 100644 --- a/dav/dav_caldav_backend_virtual_friendica.inc.php +++ b/dav/dav_caldav_backend_virtual_friendica.inc.php @@ -33,7 +33,7 @@ class Sabre_CalDAV_Backend_Friendica extends Sabre_CalDAV_Backend_Virtual * @return string */ public static function getBackendTypeName() { - return t("Friendicy-Native events"); + return t("Friendica-Native events"); } /** diff --git a/dav/dav_carddav_backend_virtual_friendica.inc.php b/dav/dav_carddav_backend_virtual_friendica.inc.php index 8d8a156ca..3d7e09745 100644 --- a/dav/dav_carddav_backend_virtual_friendica.inc.php +++ b/dav/dav_carddav_backend_virtual_friendica.inc.php @@ -1,30 +1,39 @@ CARDDAV_NAMESPACE_COMMUNITYCONTACTS . "-" . $uid, + 'id' => $books[0]["id"], 'uri' => "friendica", 'principaluri' => $principalUri, '{DAV:}displayname' => t("Friendica-Contacts"), @@ -61,56 +67,12 @@ class Sabre_CardDAV_Backend_FriendicaCommunity extends Sabre_CardDAV_Backend_Abs } - - /** - * Updates an addressbook's properties - * - * See Sabre_DAV_IProperties for a description of the mutations array, as - * well as the return value. - * - * @param string $addressBookId - * @param array $mutations - * @throws Sabre_DAV_Exception_Forbidden - * @see Sabre_DAV_IProperties::updateProperties - * @return bool|array - */ - public function updateAddressBook($addressBookId, array $mutations) - { - throw new Sabre_DAV_Exception_Forbidden(); - } - - /** - * Creates a new address book - * - * @param string $principalUri - * @param string $url Just the 'basename' of the url. - * @param array $properties - * @throws Sabre_DAV_Exception_Forbidden - * @return void - */ - public function createAddressBook($principalUri, $url, array $properties) - { - throw new Sabre_DAV_Exception_Forbidden(); - } - - /** - * Deletes an entire addressbook and all its contents - * - * @param int $addressBookId - * @throws Sabre_DAV_Exception_Forbidden - * @return void - */ - public function deleteAddressBook($addressBookId) - { - throw new Sabre_DAV_Exception_Forbidden(); - } - - /** + * @static * @param array $contact * @return array */ - private function dav_contactarr2vcardsource($contact) + private static function dav_contactarr2vcardsource($contact) { $name = explode(" ", $contact["name"]); $first_name = $last_name = ""; @@ -164,118 +126,25 @@ class Sabre_CardDAV_Backend_FriendicaCommunity extends Sabre_CardDAV_Backend_Abs } /** - * @param int $uid - * @param array|int[] $exclude_ids - * @return array + * @static + * @param int $addressbookId + * @throws Sabre_DAV_Exception_NotFound */ - private function dav_getCommunityContactsVCards($uid = 0, $exclude_ids = array()) - { - $notin = (count($exclude_ids) > 0 ? " AND id NOT IN (" . implode(", ", $exclude_ids) . ") " : ""); - $uid = IntVal($uid); - $contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 $notin ORDER BY `name` ASC", $uid); + static protected function createCache_internal($addressbookId) { + //$notin = (count($exclude_ids) > 0 ? " AND id NOT IN (" . implode(", ", $exclude_ids) . ") " : ""); + $addressbook = q("SELECT * FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId)); + if (count($addressbook) != 1 || $addressbook[0]["namespace"] != CARDDAV_NAMESPACE_PRIVATE) throw new Sabre_DAV_Exception_NotFound(); + $contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ORDER BY `name` ASC", $addressbook[0]["namespace_id"]); $retdata = array(); foreach ($contacts as $contact) { - $x = $this->dav_contactarr2vcardsource($contact); - $x["contact"] = $contact["id"]; - $retdata[] = $x; - } - return $retdata; - } - - - /** - * Returns all cards for a specific addressbook id. - * - * This method should return the following properties for each card: - * * carddata - raw vcard data - * * uri - Some unique url - * * lastmodified - A unix timestamp - * - * It's recommended to also return the following properties: - * * etag - A unique etag. This must change every time the card changes. - * * size - The size of the card in bytes. - * - * If these last two properties are provided, less time will be spent - * calculating them. If they are specified, you can also ommit carddata. - * This may speed up certain requests, especially with large cards. - * - * @param string $addressbookId - * @return array - */ - public function getCards($addressbookId) - { - $add = explode("-", $addressbookId); - - $indb = q('SELECT id, carddata, uri, lastmodified, etag, size, contact, manually_deleted FROM %s%scards WHERE namespace = %d AND namespace_id = %d', - CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($add[0]), IntVal($add[1]) - ); - $found_contacts = array(); - $contacts = array(); - foreach ($indb as $x) { - if ($x["manually_deleted"] == 0) $contacts[] = $x; - $found_contacts[] = IntVal($x["contact"]); - } - $new_found = $this->dav_getCommunityContactsVCards($add[1], $found_contacts); - foreach ($new_found as $new) { - q("INSERT INTO %s%scards (namespace, namespace_id, contact, carddata, uri, lastmodified, manually_edited, manually_deleted, etag, size) - VALUES (%d, %d, %d, '%s', '%s', %d, 0, 0, '%s', %d)", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, - IntVal($add[0]), IntVal($add[1]), IntVal($new["contact"]), dbesc($new["carddata"]), dbesc($new["uri"]), time(), md5($new["carddata"]), strlen($new["carddata"]) + $x = static::dav_contactarr2vcardsource($contact); + q("INSERT INTO %s%saddressbookobjects (`addressbook_id`, `contact`, `carddata`, `uri`, `lastmodified`, `etag`, `size`) VALUES (%d, %d, '%s', '%s', NOW(), '%s', %d)", + CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId, $contact["id"], dbesc($x["carddata"]), dbesc($x["uri"]), dbesc($x["etag"]), $x["size"] ); } - return array_merge($contacts, $new_found); } - /** - * Returns a specfic card. - * - * The same set of properties must be returned as with getCards. The only - * exception is that 'carddata' is absolutely required. - * - * @param mixed $addressBookId - * @param string $cardUri - * @throws Sabre_DAV_Exception_NotFound - * @return array - */ - public function getCard($addressBookId, $cardUri) - { - $x = explode("-", $addressBookId); - $x = q("SELECT id, carddata, uri, lastmodified, etag, size FROM %s%scards WHERE namespace = %d AND namespace_id = %d AND uri = '%s'", - CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]), dbesc($cardUri)); - if (count($x) == 0) throw new Sabre_DAV_Exception_NotFound(); - return $x[0]; - } - - /** - * Creates a new card. - * - * The addressbook id will be passed as the first argument. This is the - * same id as it is returned from the getAddressbooksForUser method. - * - * The cardUri is a base uri, and doesn't include the full path. The - * cardData argument is the vcard body, and is passed as a string. - * - * It is possible to return an ETag from this method. This ETag is for the - * newly created resource, and must be enclosed with double quotes (that - * is, the string itself must contain the double quotes). - * - * You should only return the ETag if you store the carddata as-is. If a - * subsequent GET request on the same card does not have the same body, - * byte-by-byte and you did return an ETag here, clients tend to get - * confused. - * - * If you don't return an ETag, you can just return null. - * - * @param string $addressBookId - * @param string $cardUri - * @param string $cardData - * @throws Sabre_DAV_Exception_Forbidden - * @return string - */ - public function createCard($addressBookId, $cardUri, $cardData) - { - throw new Sabre_DAV_Exception_Forbidden(); - } /** * Updates a card. diff --git a/dav/main.php b/dav/main.php index a56862aec..c36d00840 100644 --- a/dav/main.php +++ b/dav/main.php @@ -30,15 +30,21 @@ function dav_include_files() require_once (__DIR__ . "/common/calendar.fnk.php"); require_once (__DIR__ . "/common/calendar_rendering.fnk.php"); + require_once (__DIR__ . "/common/dav_caldav_backend_common.inc.php"); require_once (__DIR__ . "/common/dav_caldav_backend_private.inc.php"); require_once (__DIR__ . "/common/dav_caldav_backend_virtual.inc.php"); require_once (__DIR__ . "/common/dav_caldav_root.inc.php"); require_once (__DIR__ . "/common/dav_user_calendars.inc.php"); - require_once (__DIR__ . "/common/dav_carddav_root.inc.php"); - require_once (__DIR__ . "/common/dav_carddav_backend_std.inc.php"); - require_once (__DIR__ . "/common/dav_user_addressbooks.inc.php"); require_once (__DIR__ . "/common/dav_caldav_calendar_virtual.inc.php"); + require_once (__DIR__ . "/common/dav_caldav_calendar_private.inc.php"); + + require_once (__DIR__ . "/common/dav_carddav_root.inc.php"); + require_once (__DIR__ . "/common/dav_carddav_backend_common.inc.php"); + require_once (__DIR__ . "/common/dav_carddav_backend_virtual.inc.php"); + require_once (__DIR__ . "/common/dav_carddav_backend_private.inc.php"); + require_once (__DIR__ . "/common/dav_user_addressbooks.inc.php"); + require_once (__DIR__ . "/common/wdcal_configuration.php"); require_once (__DIR__ . "/common/wdcal_backend.inc.php"); @@ -65,6 +71,9 @@ function dav_init(&$a) * ALTER TABLE `photo` ADD INDEX ( `contact-id` ) */ + ini_set("display_errors", 1); + error_reporting(E_ALL); + dav_include_files(); if (false) { @@ -74,6 +83,7 @@ function dav_init(&$a) } wdcal_create_std_calendars(); + wdcal_create_std_addressbooks(); wdcal_addRequiredHeaders(); if ($a->argc >= 2 && $a->argv[1] == "wdcal") { @@ -104,10 +114,6 @@ function dav_init(&$a) $browser = new Sabre_DAV_Browser_Plugin(); $server->addPlugin($browser); - $aclPlugin = new Sabre_DAVACL_Plugin_Friendica(); - $aclPlugin->defaultUsernamePath = "principals/users"; - $server->addPlugin($aclPlugin); - $server->exec(); killme(); From 8f5a88aa10a33a3872bcc70d80e887a65a2b0333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6=C3=9Fl?= Date: Thu, 2 Aug 2012 22:39:19 +0200 Subject: [PATCH 04/84] Fix some edge cases --- dav/common/calendar.fnk.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dav/common/calendar.fnk.php b/dav/common/calendar.fnk.php index 149511191..cd5efa57f 100644 --- a/dav/common/calendar.fnk.php +++ b/dav/common/calendar.fnk.php @@ -249,10 +249,11 @@ function dav_create_server($force_authentication = false, $needs_caldav = true, $server->addPlugin($carddavPlugin); } - $aclPlugin = new $GLOBALS["CALDAV_ACL_PLUGIN_CLASS"](); - $aclPlugin->defaultUsernamePath = "principals/users"; - $server->addPlugin($aclPlugin); - + if ($GLOBALS["CALDAV_ACL_PLUGIN_CLASS"] != "") { + $aclPlugin = new $GLOBALS["CALDAV_ACL_PLUGIN_CLASS"](); + $aclPlugin->defaultUsernamePath = "principals/users"; + $server->addPlugin($aclPlugin); + } if ($force_authentication) $server->broadcastEvent('beforeMethod', array("GET", "/")); // Make it authenticate From b8234a1cb8d6603bf527fa12f6be9062b35efa8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6=C3=9Fl?= Date: Sat, 4 Aug 2012 08:46:11 +0000 Subject: [PATCH 05/84] Move friendica-specific parts into an own subdirectory --- dav/dav.php | 2 +- .../FriendicaACLPlugin.inc.php | 0 .../calendar.friendica.fnk.php | 0 dav/{ => friendica}/database-init.inc.php | 0 ...v_caldav_backend_virtual_friendica.inc.php | 0 ..._carddav_backend_virtual_friendica.inc.php | 0 .../dav_friendica_auth.inc.php | 0 .../dav_friendica_principal.inc.php | 0 dav/{ => friendica}/layout.fnk.php | 2 +- dav/{ => friendica}/main.php | 36 +++++++++---------- dav/{ => friendica}/wdcal.css | 0 11 files changed, 20 insertions(+), 20 deletions(-) rename dav/{ => friendica}/FriendicaACLPlugin.inc.php (100%) rename dav/{ => friendica}/calendar.friendica.fnk.php (100%) rename dav/{ => friendica}/database-init.inc.php (100%) rename dav/{ => friendica}/dav_caldav_backend_virtual_friendica.inc.php (100%) rename dav/{ => friendica}/dav_carddav_backend_virtual_friendica.inc.php (100%) rename dav/{ => friendica}/dav_friendica_auth.inc.php (100%) rename dav/{ => friendica}/dav_friendica_principal.inc.php (100%) rename dav/{ => friendica}/layout.fnk.php (99%) rename dav/{ => friendica}/main.php (89%) rename dav/{ => friendica}/wdcal.css (100%) diff --git a/dav/dav.php b/dav/dav.php index 05916d01f..40040dfe2 100644 --- a/dav/dav.php +++ b/dav/dav.php @@ -8,5 +8,5 @@ $_v = explode(".", phpversion()); if ($_v[0] > 5 || ($_v[0] == 5 && $_v[1] >= 3)) { - require(__DIR__ . "/main.php"); + require(__DIR__ . "/friendica/main.php"); } \ No newline at end of file diff --git a/dav/FriendicaACLPlugin.inc.php b/dav/friendica/FriendicaACLPlugin.inc.php similarity index 100% rename from dav/FriendicaACLPlugin.inc.php rename to dav/friendica/FriendicaACLPlugin.inc.php diff --git a/dav/calendar.friendica.fnk.php b/dav/friendica/calendar.friendica.fnk.php similarity index 100% rename from dav/calendar.friendica.fnk.php rename to dav/friendica/calendar.friendica.fnk.php diff --git a/dav/database-init.inc.php b/dav/friendica/database-init.inc.php similarity index 100% rename from dav/database-init.inc.php rename to dav/friendica/database-init.inc.php diff --git a/dav/dav_caldav_backend_virtual_friendica.inc.php b/dav/friendica/dav_caldav_backend_virtual_friendica.inc.php similarity index 100% rename from dav/dav_caldav_backend_virtual_friendica.inc.php rename to dav/friendica/dav_caldav_backend_virtual_friendica.inc.php diff --git a/dav/dav_carddav_backend_virtual_friendica.inc.php b/dav/friendica/dav_carddav_backend_virtual_friendica.inc.php similarity index 100% rename from dav/dav_carddav_backend_virtual_friendica.inc.php rename to dav/friendica/dav_carddav_backend_virtual_friendica.inc.php diff --git a/dav/dav_friendica_auth.inc.php b/dav/friendica/dav_friendica_auth.inc.php similarity index 100% rename from dav/dav_friendica_auth.inc.php rename to dav/friendica/dav_friendica_auth.inc.php diff --git a/dav/dav_friendica_principal.inc.php b/dav/friendica/dav_friendica_principal.inc.php similarity index 100% rename from dav/dav_friendica_principal.inc.php rename to dav/friendica/dav_friendica_principal.inc.php diff --git a/dav/layout.fnk.php b/dav/friendica/layout.fnk.php similarity index 99% rename from dav/layout.fnk.php rename to dav/friendica/layout.fnk.php index 597e773d2..5b65ec244 100644 --- a/dav/layout.fnk.php +++ b/dav/friendica/layout.fnk.php @@ -17,7 +17,7 @@ function wdcal_addRequiredHeaders() $a->page['htmlhead'] .= '' . "\r\n"; $a->page['htmlhead'] .= '' . "\r\n"; - $a->page['htmlhead'] .= '' . "\r\n"; + $a->page['htmlhead'] .= '' . "\r\n"; $a->page['htmlhead'] .= '' . "\r\n"; $a->page['htmlhead'] .= '' . "\r\n"; diff --git a/dav/main.php b/dav/friendica/main.php similarity index 89% rename from dav/main.php rename to dav/friendica/main.php index c36d00840..602bda6d7 100644 --- a/dav/main.php +++ b/dav/friendica/main.php @@ -26,27 +26,27 @@ function dav_module() function dav_include_files() { - require_once (__DIR__ . "/SabreDAV/lib/Sabre/autoload.php"); + require_once (__DIR__ . "/../SabreDAV/lib/Sabre/autoload.php"); - require_once (__DIR__ . "/common/calendar.fnk.php"); - require_once (__DIR__ . "/common/calendar_rendering.fnk.php"); + require_once (__DIR__ . "/../common/calendar.fnk.php"); + require_once (__DIR__ . "/../common/calendar_rendering.fnk.php"); - require_once (__DIR__ . "/common/dav_caldav_backend_common.inc.php"); - require_once (__DIR__ . "/common/dav_caldav_backend_private.inc.php"); - require_once (__DIR__ . "/common/dav_caldav_backend_virtual.inc.php"); - require_once (__DIR__ . "/common/dav_caldav_root.inc.php"); - require_once (__DIR__ . "/common/dav_user_calendars.inc.php"); - require_once (__DIR__ . "/common/dav_caldav_calendar_virtual.inc.php"); - require_once (__DIR__ . "/common/dav_caldav_calendar_private.inc.php"); + require_once (__DIR__ . "/../common/dav_caldav_backend_common.inc.php"); + require_once (__DIR__ . "/../common/dav_caldav_backend_private.inc.php"); + require_once (__DIR__ . "/../common/dav_caldav_backend_virtual.inc.php"); + require_once (__DIR__ . "/../common/dav_caldav_root.inc.php"); + require_once (__DIR__ . "/../common/dav_user_calendars.inc.php"); + require_once (__DIR__ . "/../common/dav_caldav_calendar_virtual.inc.php"); + require_once (__DIR__ . "/../common/dav_caldav_calendar_private.inc.php"); - require_once (__DIR__ . "/common/dav_carddav_root.inc.php"); - require_once (__DIR__ . "/common/dav_carddav_backend_common.inc.php"); - require_once (__DIR__ . "/common/dav_carddav_backend_virtual.inc.php"); - require_once (__DIR__ . "/common/dav_carddav_backend_private.inc.php"); - require_once (__DIR__ . "/common/dav_user_addressbooks.inc.php"); + require_once (__DIR__ . "/../common/dav_carddav_root.inc.php"); + require_once (__DIR__ . "/../common/dav_carddav_backend_common.inc.php"); + require_once (__DIR__ . "/../common/dav_carddav_backend_virtual.inc.php"); + require_once (__DIR__ . "/../common/dav_carddav_backend_private.inc.php"); + require_once (__DIR__ . "/../common/dav_user_addressbooks.inc.php"); - require_once (__DIR__ . "/common/wdcal_configuration.php"); - require_once (__DIR__ . "/common/wdcal_backend.inc.php"); + require_once (__DIR__ . "/../common/wdcal_configuration.php"); + require_once (__DIR__ . "/../common/wdcal_backend.inc.php"); require_once (__DIR__ . "/dav_friendica_principal.inc.php"); require_once (__DIR__ . "/dav_friendica_auth.inc.php"); @@ -54,7 +54,7 @@ function dav_include_files() require_once (__DIR__ . "/dav_caldav_backend_virtual_friendica.inc.php"); require_once (__DIR__ . "/FriendicaACLPlugin.inc.php"); - require_once (__DIR__ . "/common/wdcal_edit.inc.php"); + require_once (__DIR__ . "/../common/wdcal_edit.inc.php"); require_once (__DIR__ . "/calendar.friendica.fnk.php"); require_once (__DIR__ . "/layout.fnk.php"); } diff --git a/dav/wdcal.css b/dav/friendica/wdcal.css similarity index 100% rename from dav/wdcal.css rename to dav/friendica/wdcal.css From 9b1de8593f006ca8a021b8bdf3e625b0696c2190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6=C3=9Fl?= Date: Sat, 4 Aug 2012 10:48:25 +0200 Subject: [PATCH 06/84] Change in database scheme --- dav/database-init.inc.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dav/database-init.inc.php b/dav/database-init.inc.php index 7c0d23a3a..527b76714 100644 --- a/dav/database-init.inc.php +++ b/dav/database-init.inc.php @@ -66,7 +66,7 @@ function dav_get_update_statements($from_version) `carddata` mediumtext CHARACTER SET utf8 COLLATE utf8_unicode_ci, `uri` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `lastmodified` timestamp NULL DEFAULT NULL, - `manually_edited` tinyint(4) NOT NULL DEFAULT '0', + `needs_rebuild` tinyint(4) NOT NULL DEFAULT '0', `manually_deleted` tinyint(4) NOT NULL DEFAULT '0', `etag` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `size` int(10) unsigned NOT NULL, @@ -206,7 +206,7 @@ function dav_get_create_statements($except = array()) `carddata` mediumtext CHARACTER SET utf8 COLLATE utf8_unicode_ci, `uri` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `lastmodified` timestamp NULL DEFAULT NULL, - `manually_edited` tinyint(4) NOT NULL DEFAULT '0', + `needs_rebuild` tinyint(4) NOT NULL DEFAULT '0', `manually_deleted` tinyint(4) NOT NULL DEFAULT '0', `etag` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `size` int(10) unsigned NOT NULL, @@ -241,7 +241,7 @@ function dav_create_tables() $errors = array(); global $db; - foreach ($stms as $st) { + foreach ($stms as $st) { // @TODO Friendica-dependent $db->q($st); if ($db->error) $errors[] = $db->error; } @@ -261,7 +261,7 @@ function dav_upgrade_tables() $errors = array(); global $db; - foreach ($stms as $st) { + foreach ($stms as $st) { // @TODO Friendica-dependent $db->q($st); if ($db->error) $errors[] = $db->error; } From 87d314170bf0e89c8f16ec0d723744b3b09c454a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6=C3=9Fl?= Date: Fri, 10 Aug 2012 21:41:17 +0200 Subject: [PATCH 07/84] First part of Refactoring to stay compatible with v2.0 of the VObject library --- dav/common/calendar.fnk.php | 64 ++---- dav/common/calendar_rendering.fnk.php | 28 +-- dav/common/dav_caldav_backend_common.inc.php | 20 +- .../dav_carddav_backend_virtual.inc.php | 186 ++++++++++++++---- dav/common/wdcal_backend.inc.php | 16 +- dav/common/wdcal_edit.inc.php | 50 ++--- dav/friendica/database-init.inc.php | 4 +- 7 files changed, 223 insertions(+), 145 deletions(-) diff --git a/dav/common/calendar.fnk.php b/dav/common/calendar.fnk.php index cd5efa57f..10177b347 100644 --- a/dav/common/calendar.fnk.php +++ b/dav/common/calendar.fnk.php @@ -99,51 +99,6 @@ class vcard_source_data public $photo; } -; - - -/** - * @param vcard_source_data $vcardsource - * @return string - */ -function vcard_source_compile($vcardsource) -{ - $str = "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//" . DAV_APPNAME . "//DAV-Plugin//EN\r\n"; - $str .= "N:" . str_replace(";", ",", $vcardsource->name_last) . ";" . str_replace(";", ",", $vcardsource->name_first) . ";" . str_replace(";", ",", $vcardsource->name_middle) . ";;\r\n"; - $str .= "FN:" . str_replace(";", ",", $vcardsource->name_first) . " " . str_replace(";", ",", $vcardsource->name_middle) . " " . str_replace(";", ",", $vcardsource->name_last) . "\r\n"; - $str .= "REV:" . str_replace(" ", "T", $vcardsource->last_update) . "Z\r\n"; - - $item_count = 0; - for ($i = 0; $i < count($vcardsource->homepages); $i++) { - if ($i == 0) $str .= "URL;type=" . $vcardsource->homepages[0]->type . ":" . $vcardsource->homepages[0]->homepage . "\r\n"; - else { - $c = ++$item_count; - $str .= "item$c.URL;type=" . $vcardsource->homepages[0]->type . ":" . $vcardsource->homepages[0]->homepage . "\r\n"; - $str .= "item$c.X-ABLabel:_\$!!\$_\r\n"; - } - } - - if (is_object($vcardsource->photo)) { - $data = base64_encode($vcardsource->photo->binarydata); - $str .= "PHOTO;ENCODING=BASE64;TYPE=" . $vcardsource->photo->type . ":" . $data . "\r\n"; - } - - if (isset($vcardsource->socialnetworks) && is_array($vcardsource->socialnetworks)) foreach ($vcardsource->socialnetworks as $netw) switch ($netw->type) { - case "dfrn": - $str .= "X-SOCIALPROFILE;type=dfrn;x-user=" . $netw->nick . ":" . $netw->url . "\r\n"; - break; - case "facebook": - $str .= "X-SOCIALPROFILE;type=facebook;x-user=" . $netw->nick . ":" . $netw->url . "\r\n"; - break; - case "twitter": - $str .= "X-SOCIALPROFILE;type=twitter;x-user=" . $netw->nick . ":" . $netw->url . "\r\n"; - break; - } - - $str .= "END:VCARD\r\n"; - return $str; -} - /** * @param int $phpDate (UTC) @@ -237,7 +192,7 @@ function dav_create_server($force_authentication = false, $needs_caldav = true, if (CALDAV_URL_PREFIX != "") $server->setBaseUri(CALDAV_URL_PREFIX); - $authPlugin = new Sabre_DAV_Auth_Plugin(Sabre_DAV_Auth_Backend_Std::getInstance(), 'SabreDAV'); + $authPlugin = new Sabre_DAV_Auth_Plugin(Sabre_DAV_Auth_Backend_Std::getInstance(), DAV_APPNAME); $server->addPlugin($authPlugin); if ($needs_caldav) { @@ -253,6 +208,10 @@ function dav_create_server($force_authentication = false, $needs_caldav = true, $aclPlugin = new $GLOBALS["CALDAV_ACL_PLUGIN_CLASS"](); $aclPlugin->defaultUsernamePath = "principals/users"; $server->addPlugin($aclPlugin); + } else { + $aclPlugin = new Sabre_DAVACL_Plugin(); + $aclPlugin->defaultUsernamePath = "principals/users"; + $server->addPlugin($aclPlugin); } if ($force_authentication) $server->broadcastEvent('beforeMethod', array("GET", "/")); // Make it authenticate @@ -298,7 +257,7 @@ function dav_get_current_user_calendars(&$server, $with_privilege = "") * @param Sabre_CalDAV_Calendar $calendar * @param string $calendarobject_uri * @param string $with_privilege - * @return null|Sabre_VObject_Component_VCalendar + * @return null|Sabre\VObject\Component\VCalendar */ function dav_get_current_user_calendarobject(&$server, &$calendar, $calendarobject_uri, $with_privilege = "") { @@ -314,7 +273,7 @@ function dav_get_current_user_calendarobject(&$server, &$calendar, $calendarobje if (!$aclplugin->checkPrivileges($uri, $with_privilege, Sabre_DAVACL_Plugin::R_PARENT, false)) return null; $data = $obj->get(); - $vObject = Sabre_VObject_Reader::read($data); + $vObject = Sabre\VObject\Reader::read($data); return $vObject; } @@ -342,20 +301,19 @@ function dav_get_current_user_calendar_by_id(&$server, $id, $with_privilege = "" /** * @param string $uid - * @return Sabre_VObject_Component_VCalendar $vObject + * @return Sabre\VObject\Component\VCalendar $vObject */ function dav_create_empty_vevent($uid = "") { - $a = get_app(); if ($uid == "") $uid = uniqid(); - return Sabre_VObject_Reader::read("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//" . DAV_APPNAME . "//DAV-Plugin//EN\r\nBEGIN:VEVENT\r\nUID:" . $uid . "@" . dav_compat_get_hostname() . + return Sabre\VObject\Reader::read("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//" . DAV_APPNAME . "//DAV-Plugin//EN\r\nBEGIN:VEVENT\r\nUID:" . $uid . "@" . dav_compat_get_hostname() . "\r\nDTSTAMP:" . date("Ymd") . "T" . date("His") . "Z\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"); } /** - * @param Sabre_VObject_Component_VCalendar $vObject - * @return Sabre_VObject_Component_VEvent|null + * @param Sabre\VObject\Component\VCalendar $vObject + * @return Sabre\VObject\Component\VEvent|null */ function dav_get_eventComponent(&$vObject) { diff --git a/dav/common/calendar_rendering.fnk.php b/dav/common/calendar_rendering.fnk.php index f82247957..6481c1019 100644 --- a/dav/common/calendar_rendering.fnk.php +++ b/dav/common/calendar_rendering.fnk.php @@ -3,8 +3,8 @@ /** - * @param Sabre_VObject_Component_VAlarm $alarm - * @param Sabre_VObject_Component_VEvent|Sabre_VObject_Component_VTodo $parent + * @param Sabre\VObject\Component\VAlarm $alarm + * @param Sabre\VObject\Component\VEvent|Sabre\VObject\Component\VTodo $parent * @return DateTime|null * @throws Sabre_DAV_Exception */ @@ -12,12 +12,12 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent) { $trigger = $alarm->__get("TRIGGER"); if (!isset($trigger['VALUE']) || strtoupper($trigger['VALUE']) === 'DURATION') { - $triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($trigger->value); + $triggerDuration = Sabre\VObject\DateTimeParser::parseDuration($trigger->value); $related = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'END' : 'START'; if ($related === 'START') { - /** @var Sabre_VObject_Property_DateTime $dtstart */ + /** @var Sabre\VObject\Property\DateTime $dtstart */ $dtstart = $parent->__get("DTSTART"); $effectiveTrigger = $dtstart->getDateTime(); $effectiveTrigger->add($triggerDuration); @@ -28,14 +28,14 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent) $endProp = 'DTEND'; } - /** @var Sabre_VObject_Property_DateTime $dtstart */ + /** @var Sabre\VObject\Property\DateTime $dtstart */ $dtstart = $parent->__get("DTSTART"); if (isset($parent->$endProp)) { $effectiveTrigger = clone $parent->$endProp->getDateTime(); $effectiveTrigger->add($triggerDuration); } elseif ($parent->__get("DURATION") != "") { $effectiveTrigger = clone $dtstart->getDateTime(); - $duration = Sabre_VObject_DateTimeParser::parseDuration($parent->__get("DURATION")); + $duration = Sabre\VObject\DateTimeParser::parseDuration($parent->__get("DURATION")); $effectiveTrigger->add($duration); $effectiveTrigger->add($triggerDuration); } else { @@ -58,10 +58,10 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent) */ function renderCalDavEntry_data(&$calendar, &$calendarobject) { - /** @var Sabre_VObject_Component_VCalendar $vObject */ - $vObject = Sabre_VObject_Reader::read($calendarobject["calendardata"]); + /** @var Sabre\VObject\Component\VCalendar $vObject */ + $vObject = Sabre\VObject\Reader::read($calendarobject["calendardata"]); $componentType = null; - /** @var Sabre_VObject_Component_VEvent $component */ + /** @var Sabre\VObject\Component\VEvent $component */ $component = null; foreach ($vObject->getComponents() as $component) { if ($component->name !== 'VTIMEZONE') { @@ -86,18 +86,18 @@ function renderCalDavEntry_data(&$calendar, &$calendarobject) ); $recurring = ($component->__get("RRULE") ? 1 : 0); - /** @var Sabre_VObject_Property_DateTime $dtstart */ + /** @var Sabre\VObject\Property\DateTime $dtstart */ $dtstart = $component->__get("DTSTART"); - $allday = ($dtstart->getDateType() == Sabre_VObject_Property_DateTime::DATE ? 1 : 0); + $allday = ($dtstart->getDateType() == Sabre\VObject\Property\DateTime::DATE ? 1 : 0); - /** @var array|Sabre_VObject_Component_VAlarm[] $alarms */ + /** @var array|Sabre\VObject\Component\VAlarm[] $alarms */ $alarms = array(); foreach ($component->getComponents() as $a_component) if ($a_component->name == "VALARM") { - /** var Sabre_VObject_Component_VAlarm $component */ + /** var Sabre\VObject\Component_VAlarm $component */ $alarms[] = $a_component; } - $it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID")); + $it = new Sabre\VObject\RecurrenceIterator($vObject, (string)$component->__get("UID")); $last_end = 0; $max_ts = mktime(0, 0, 0, 1, 1, CALDAV_MAX_YEAR * 1); $first = true; diff --git a/dav/common/dav_caldav_backend_common.inc.php b/dav/common/dav_caldav_backend_common.inc.php index 99fcb6c10..97d5722a9 100644 --- a/dav/common/dav_caldav_backend_common.inc.php +++ b/dav/common/dav_caldav_backend_common.inc.php @@ -81,22 +81,22 @@ abstract class Sabre_CalDAV_Backend_Common extends Sabre_CalDAV_Backend_Abstract /** * @static - * @param Sabre_VObject_Component_VEvent $component + * @param Sabre\VObject\Component\VEvent $component * @return int */ public static function getDtEndTimeStamp(&$component) { - /** @var Sabre_VObject_Property_DateTime $dtstart */ + /** @var Sabre\VObject\Property\DateTime $dtstart */ $dtstart = $component->__get("DTSTART"); if ($component->__get("DTEND")) { - /** @var Sabre_VObject_Property_DateTime $dtend */ + /** @var Sabre\VObject\Property\DateTime $dtend */ $dtend = $component->__get("DTEND"); return $dtend->getDateTime()->getTimeStamp(); } elseif ($component->__get("DURATION")) { $endDate = clone $dtstart->getDateTime(); - $endDate->add(Sabre_VObject_DateTimeParser::parse($component->__get("DURATION")->value)); + $endDate->add(Sabre\VObject\DateTimeParser::parse($component->__get("DURATION")->value)); return $endDate->getTimeStamp(); - } elseif ($dtstart->getDateType() === Sabre_VObject_Property_DateTime::DATE) { + } elseif ($dtstart->getDateType() === Sabre\VObject\Property\DateTime::DATE) { $endDate = clone $dtstart->getDateTime(); $endDate->modify('+1 day'); return $endDate->getTimeStamp(); @@ -124,8 +124,8 @@ abstract class Sabre_CalDAV_Backend_Common extends Sabre_CalDAV_Backend_Abstract */ protected function getDenormalizedData($calendarData) { - /** @var Sabre_VObject_Component_VEvent $vObject */ - $vObject = Sabre_VObject_Reader::read($calendarData); + /** @var Sabre\VObject\Component\VEvent $vObject */ + $vObject = Sabre\VObject\Reader::read($calendarData); $componentType = null; $component = null; $firstOccurence = null; @@ -141,15 +141,15 @@ abstract class Sabre_CalDAV_Backend_Common extends Sabre_CalDAV_Backend_Abstract throw new Sabre_DAV_Exception_BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); } if ($componentType === 'VEVENT') { - /** @var Sabre_VObject_Component_VEvent $component */ - /** @var Sabre_VObject_Property_DateTime $dtstart */ + /** @var Sabre\VObject\Component\VEvent $component */ + /** @var Sabre\VObject\Property\DateTime $dtstart */ $dtstart = $component->__get("DTSTART"); $firstOccurence = $dtstart->getDateTime()->getTimeStamp(); // Finding the last occurence is a bit harder if (!$component->__get("RRULE")) { $lastOccurence = self::getDtEndTimeStamp($component); } else { - $it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID")); + $it = new Sabre\VObject\RecurrenceIterator($vObject, (string)$component->__get("UID")); $maxDate = new DateTime(CALDAV_MAX_YEAR . "-01-01"); if ($it->isInfinite()) { $lastOccurence = $maxDate->getTimeStamp(); diff --git a/dav/common/dav_carddav_backend_virtual.inc.php b/dav/common/dav_carddav_backend_virtual.inc.php index 98597c694..f81a0a48c 100644 --- a/dav/common/dav_carddav_backend_virtual.inc.php +++ b/dav/common/dav_carddav_backend_virtual.inc.php @@ -16,65 +16,147 @@ abstract class Sabre_CardDAV_Backend_Virtual extends Sabre_CardDAV_Backend_Commo /** * @static - * @param int $uid - * @param int $namespace + * @param int $addressbookId */ - static public function invalidateCache($uid = 0, $namespace = 0) { - q("DELETE FROM %s%sadd_virtual_object_sync WHERE `uid` = %d AND `namespace` = %d", - CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($uid), IntVal($namespace)); + static public function invalidateCache($addressbookId) { + q("UPDATE %s%saddressbooks SET `needs_rebuild` = 1 WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId)); } /** * @static * @abstract * @param int $addressbookId + * @param bool $force */ - static abstract protected function createCache_internal($addressbookId); + static abstract protected function createCache_internal($addressbookId, $force = false); + + /** + * @param int $addressbookId + * @param null|array $addressbook + * @param bool $force + */ + public function createCache($addressbookId, $addressbook = null, $force = false) { + $addressbookId = IntVal($addressbookId); + + if (!$addressbook) { + $add = q("SELECT `needs_rebuild`, `uri` FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId); + $addressbook = $add[0]; + } + if ($addressbook["needs_rebuild"] == 1 || $force) { + static::createCache_internal($addressbookId, $force); + q("UPDATE %s%saddressbooks SET `needs_rebuild` = 0, `ctag` = `ctag` + 1 WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId); + } + } /** * @static + * @abstract * @param int $addressbookId + * @param int $contactId + * @param bool $force */ - static protected function createCache($addressbookId) { - $addressbookId = IntVal($addressbookId); - q("DELETE FROM %s%saddressbookobjects WHERE `addressbook_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId); - static::createCache_internal($addressbookId); - q("REPLACE INTO %s%sadd_virtual_object_sync (`addressbook_id`, `date`) VALUES (%d, NOW())", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId); - } - + static abstract protected function createCardCache($addressbookId, $contactId, $force = false); /** - * @param string $addressbookId + * @param int $addressbookId * @return array */ public function getCards($addressbookId) { $addressbookId = IntVal($addressbookId); - $r = q("SELECT COUNT(*) n FROM %s%sadd_virtual_object_sync WHERE `addressbook_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId); + $add = q("SELECT * FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId); + if ($add[0]["needs_rebuild"]) { + static::createCache_internal($addressbookId); + q("UPDATE %s%saddressbooks SET `needs_rebuild` = 0, `ctag` = `ctag` + 1 WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId); + $add[0]["needs_rebuild"] = 0; + $add[0]["ctag"]++; + } - if ($r[0]["n"] == 0) static::createCache($addressbookId); + $ret = array(); + $x = q("SELECT * FROM %s%saddressbookobjects WHERE `addressbook_id` = %d AND `manually_deleted` = 0", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId); + foreach ($x as $y) $ret[] = self::getCard($addressbookId, $add[0]["uri"], $add[0], $y); - return q("SELECT * FROM %s%saddressbookobjects WHERE `addressbook_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId); + return $ret; + } + + /** + * Replaces the x-prop_name value. Replaces the prop_name value IF the old value is the same as the old value of x-prop_name (meaning: the user has not manually changed it) + * + * @param Sabre\VObject\Component $component + * @param string $prop_name + * @param string $prop_value + * @param array $parameters + * @return void + */ + static public function card_set_automatic_value(&$component, $prop_name, $prop_value, $parameters = array()) { + $automatic = $component->select("X-" . $prop_name); + $curr = $component->select($prop_name); + + if (count($automatic) == 0) { + $prop = new Sabre\VObject\Property('X-' . $prop_name, $prop_value); + foreach ($parameters as $key=>$val) $prop->add($key, $val); + $component->children[] = $prop; + + if (count($curr) == 0) { + $prop = new Sabre\VObject\Property($prop_name, $prop_value); + foreach ($parameters as $key=>$val) $prop->add($key, $val); + $component->children[] = $prop; + } + + } else foreach ($automatic as $auto_prop) { + /** @var Sabre\VObject\Property $auto_prop */ + /** @var Sabre\VObject\Property $actual_prop */ + foreach ($curr as $actual_prop) { + if ($auto_prop->value == $actual_prop->value) $actual_prop->setValue($prop_value); + } + $auto_prop->setValue($prop_value); + } + } + + + + /** + * Deletes the x-prop_name value. Deletes the prop_name value IF the old value is the same as the old value of x-prop_name (meaning: the user has not manually changed it) + * + * @param Sabre\VObject\Component $component + * @param string $prop_name + * @param array $parameters + */ + static public function card_del_automatic_value(&$component, $prop_name, $parameters = array()) { + // @TODO } /** - * @param string $addressbookId + * @param int $addressbookId * @param string $objectUri + * @param array $book + * @param array $obj * @throws Sabre_DAV_Exception_NotFound * @return array */ - public function getCard($addressbookId, $objectUri) + public function getCard($addressbookId, $objectUri, $book = null, $obj = null) { $addressbookId = IntVal($addressbookId); - $r = q("SELECT COUNT(*) n FROM %s%sadd_virtual_object_sync WHERE `addressbook_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId)); - if ($r[0]["n"] == 0) static::createCache($addressbookId); + if ($book == null) { + $add = q("SELECT `needs_rebuild`, `uri` FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId); + $book = $add[0]; + } + if ($book["needs_rebuild"] == 1) { + static::createCache_internal($addressbookId); + q("UPDATE %s%saddressbooks SET `needs_rebuild` = 0, `ctag` = `ctag` + 1 WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId); + $add[0]["needs_rebuild"] = 0; + } - $r = q("SELECT * FROM %s%saddressbookobjects WHERE `uri` = '%s' AND `addressbook_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($objectUri), IntVal($addressbookId)); - if (count($r) == 0) throw new Sabre_DAV_Exception_NotFound(); + if ($obj == null) { + $r = q("SELECT * FROM %s%saddressbookobjects WHERE `uri` = '%s' AND `addressbook_id` = %d AND `manually_deleted` = 0", + CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($objectUri), IntVal($addressbookId)); + if (count($r) == 0) throw new Sabre_DAV_Exception_NotFound(); + $obj = $r[0]; + if ($obj["needs_rebuild"] == 1) $obj = static::createCardCache($addressbookId, $obj["contact"]); + } - $obj = $r[0]; $ret = array( "id" => IntVal($obj["uri"]), "carddata" => $obj["carddata"], @@ -125,26 +207,62 @@ abstract class Sabre_CardDAV_Backend_Virtual extends Sabre_CardDAV_Backend_Commo } /** - * @param string $addressbookId - * @param string $objectUri + * Updates a card. + * + * The addressbook id will be passed as the first argument. This is the + * same id as it is returned from the getAddressbooksForUser method. + * + * The cardUri is a base uri, and doesn't include the full path. The + * cardData argument is the vcard body, and is passed as a string. + * + * It is possible to return an ETag from this method. This ETag should + * match that of the updated resource, and must be enclosed with double + * quotes (that is: the string itself must contain the actual quotes). + * + * You should only return the ETag if you store the carddata as-is. If a + * subsequent GET request on the same card does not have the same body, + * byte-by-byte and you did return an ETag here, clients tend to get + * confused. + * + * If you don't return an ETag, you can just return null. + * + * @param string $addressBookId + * @param string $cardUri * @param string $cardData * @throws Sabre_DAV_Exception_Forbidden - * @return null|string|void + * @return string|null */ - function updateCard($addressbookId, $objectUri, $cardData) + public function updateCard($addressBookId, $cardUri, $cardData) { - throw new Sabre_DAV_Exception_Forbidden(); + echo "Die!"; die(); // @TODO + $x = explode("-", $addressBookId); + + $etag = md5($cardData); + q("UPDATE %s%scards SET carddata = '%s', lastmodified = %d, etag = '%s', size = %d, manually_edited = 1 WHERE uri = '%s' AND namespace = %d AND namespace_id =%d", + CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($cardData), time(), $etag, strlen($cardData), dbesc($cardUri), IntVal($x[10]), IntVal($x[1]) + ); + q('UPDATE %s%saddressbooks_community SET ctag = ctag + 1 WHERE uid = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[1])); + + return '"' . $etag . '"'; } + + + /** - * @param string $addressbookId - * @param string $objectUri + * Deletes a card + * + * @param string $addressBookId + * @param string $cardUri * @throws Sabre_DAV_Exception_Forbidden - * @return void + * @return bool */ - function deleteCard($addressbookId, $objectUri) + public function deleteCard($addressBookId, $cardUri) { - throw new Sabre_DAV_Exception_Forbidden(); + q("UPDATE %s%scards SET `manually_deleted` = 1 WHERE `addressbook_id` = %d AND `uri` = '%s'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId), dbesc($cardUri)); + q('UPDATE %s%saddressbooks SET ctag = ctag + 1 WHERE `id` = %d', CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressBookId)); + + return true; } diff --git a/dav/common/wdcal_backend.inc.php b/dav/common/wdcal_backend.inc.php index 9233da6e2..330f29889 100644 --- a/dav/common/wdcal_backend.inc.php +++ b/dav/common/wdcal_backend.inc.php @@ -97,12 +97,12 @@ function wdcal_print_feed($base_path = "") $component = dav_get_eventComponent($item); $component->add("SUMMARY", icalendar_sanitize_string(dav_compat_parse_text_serverside("CalendarTitle"))); - if (isset($_REQUEST["allday"])) $type = Sabre_VObject_Property_DateTime::DATE; - else $type = Sabre_VObject_Property_DateTime::LOCALTZ; + if (isset($_REQUEST["allday"])) $type = Sabre\VObject\Property\DateTime::DATE; + else $type = Sabre\VObject\Property\DateTime::LOCALTZ; - $datetime_start = new Sabre_VObject_Property_DateTime("DTSTART"); + $datetime_start = new Sabre\VObject\Property\DateTime("DTSTART"); $datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarStartTime"]))), $type); - $datetime_end = new Sabre_VObject_Property_DateTime("DTEND"); + $datetime_end = new Sabre\VObject\Property\DateTime("DTEND"); $datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarEndTime"]))), $type); $component->add($datetime_start); @@ -179,12 +179,12 @@ function wdcal_print_feed($base_path = "") killme(); } - if (isset($_REQUEST["allday"])) $type = Sabre_VObject_Property_DateTime::DATE; - else $type = Sabre_VObject_Property_DateTime::LOCALTZ; + if (isset($_REQUEST["allday"])) $type = Sabre\VObject\Property\DateTime::DATE; + else $type = Sabre\VObject\Property\DateTime::LOCALTZ; - $datetime_start = new Sabre_VObject_Property_DateTime("DTSTART"); + $datetime_start = new Sabre\VObject\Property\DateTime("DTSTART"); $datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarStartTime"]))), $type); - $datetime_end = new Sabre_VObject_Property_DateTime("DTEND"); + $datetime_end = new Sabre\VObject\Property\DateTime("DTEND"); $datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarEndTime"]))), $type); $component->__unset("DTSTART"); diff --git a/dav/common/wdcal_edit.inc.php b/dav/common/wdcal_edit.inc.php index dac493683..d507a9000 100644 --- a/dav/common/wdcal_edit.inc.php +++ b/dav/common/wdcal_edit.inc.php @@ -29,7 +29,7 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $calendar_id, $uri) if ($component == null) return t('Could not open component for editing'); - /** @var Sabre_VObject_Property_DateTime $dtstart */ + /** @var Sabre\VObject\Property\DateTime $dtstart */ $dtstart = $component->__get("DTSTART"); $event = array( "id" => IntVal($uri), @@ -44,7 +44,7 @@ function wdcal_getEditPage_str(&$localization, $baseurl, $calendar_id, $uri) $exdates = $component->select("EXDATE"); $recurrentce_exdates = array(); - /** @var Sabre_VObject_Property_MultiDateTime $x */ + /** @var Sabre\VObject\Property\MultiDateTime $x */ foreach ($exdates as $x) { /** @var DateTime $y */ $z = $x->getDateTimes(); @@ -511,15 +511,15 @@ function wdcal_set_component_date(&$component, &$localization) if (isset($_REQUEST["allday"])) { $ts_start = $localization->date_local2timestamp($_REQUEST["start_date"] . " 00:00"); $ts_end = $localization->date_local2timestamp($_REQUEST["end_date"] . " 00:00"); - $type = Sabre_VObject_Property_DateTime::DATE; + $type = Sabre\VObject\Property\DateTime::DATE; } else { $ts_start = $localization->date_local2timestamp($_REQUEST["start_date"] . " " . $_REQUEST["start_time"]); $ts_end = $localization->date_local2timestamp($_REQUEST["end_date"] . " " . $_REQUEST["end_time"]); - $type = Sabre_VObject_Property_DateTime::LOCALTZ; + $type = Sabre\VObject\Property\DateTime::LOCALTZ; } - $datetime_start = new Sabre_VObject_Property_DateTime("DTSTART"); + $datetime_start = new Sabre\VObject\Property\DateTime("DTSTART"); $datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_start)), $type); - $datetime_end = new Sabre_VObject_Property_DateTime("DTEND"); + $datetime_end = new Sabre\VObject\Property\DateTime("DTEND"); $datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_end)), $type); $component->__unset("DTSTART"); @@ -539,7 +539,7 @@ function wdcal_set_component_date(&$component, &$localization) function wdcal_set_component_recurrence_special(&$component, $str) { $ret = ""; - /** @var Sabre_VObject_Property_DateTime $start */ + /** @var Sabre\VObject\Property\DateTime $start */ $start = $component->__get("DTSTART"); $dayMap = array( 0 => 'SU', @@ -595,8 +595,8 @@ function wdcal_set_component_recurrence(&$component, &$localization) case "date": $date = $localization->date_local2timestamp($_REQUEST["rec_until_date"]); $part_until = ";UNTIL=" . date("Ymd", $date); - $datetime_until = new Sabre_VObject_Property_DateTime("UNTIL"); - $datetime_until->setDateTime(new DateTime(date("Y-m-d H:i:s", $date)), Sabre_VObject_Property_DateTime::DATE); + $datetime_until = new Sabre\VObject\Property\DateTime("UNTIL"); + $datetime_until->setDateTime(new DateTime(date("Y-m-d H:i:s", $date)), Sabre\VObject\Property\DateTime::DATE); break; case "count": $part_until = ";COUNT=" . IntVal($_REQUEST["rec_until_count"]); @@ -626,7 +626,7 @@ function wdcal_set_component_recurrence(&$component, &$localization) $part_freq .= wdcal_set_component_recurrence_special($component, $_REQUEST["rec_monthly_day"]); break; case "yearly": - /** @var Sabre_VObject_Property_DateTime $start */ + /** @var Sabre\VObject\Property\DateTime $start */ $start = $component->__get("DTSTART"); $part_freq = "FREQ=YEARLY"; $part_freq .= ";BYMONTH=" . $start->getDateTime()->format("n"); @@ -645,20 +645,20 @@ function wdcal_set_component_recurrence(&$component, &$localization) foreach ($_REQUEST["rec_exceptions"] as $except) { $arr[] = new DateTime(date("Y-m-d H:i:s", $except)); } - /** @var Sabre_VObject_Property_MultiDateTime $prop */ - $prop = Sabre_VObject_Property::create("EXDATE"); + /** @var Sabre\VObject\Property\MultiDateTime $prop */ + $prop = Sabre\VObject\Property::create("EXDATE"); $prop->setDateTimes($arr); $component->add($prop); } $rrule = $part_freq . $part_until; - $component->add(new Sabre_VObject_Property("RRULE", $rrule)); + $component->add(new Sabre\VObject\Property("RRULE", $rrule)); } /** - * @param Sabre_VObject_Component_VEvent $component + * @param Sabre\VObject\Component\VEvent $component * @param wdcal_local $localization * @param string $summary * @param int $dtstart @@ -671,12 +671,12 @@ function wdcal_set_component_alerts(&$component, &$localization, $summary, $dtst $component->__unset("VALARM"); foreach ($prev_alarms as $al) { - /** @var Sabre_VObject_Component_VAlarm $al */ + /** @var Sabre\VObject\Component\VAlarm $al */ // @TODO Parse notifications that have been there before; e.g. from Lightning } foreach (array_keys($_REQUEST["noti_type"]) as $key) if (is_numeric($key) || ($key == "new" && $_REQUEST["new_alarm"] == 1)) { - $alarm = new Sabre_VObject_Component_VAlarm("VALARM"); + $alarm = new Sabre\VObject\Component\VAlarm("VALARM"); switch ($_REQUEST["noti_type"][$key]) { case "email": @@ -686,15 +686,15 @@ function wdcal_set_component_alerts(&$component, &$localization, $summary, $dtst $localization->date_timestamp2local($dtstart), $summary, ), t("The event #name# will start at #date")); - $alarm->add(new Sabre_VObject_Property("ACTION", "EMAIL")); - $alarm->add(new Sabre_VObject_Property("SUMMARY", $summary)); - $alarm->add(new Sabre_VObject_Property("DESCRIPTION", $mailtext)); - $alarm->add(new Sabre_VObject_Property("ATTENDEE", "MAILTO:" . $a->user["email"])); + $alarm->add(new Sabre\VObject\Property("ACTION", "EMAIL")); + $alarm->add(new Sabre\VObject\Property("SUMMARY", $summary)); + $alarm->add(new Sabre\VObject\Property("DESCRIPTION", $mailtext)); + $alarm->add(new Sabre\VObject\Property("ATTENDEE", "MAILTO:" . $a->user["email"])); break; case "display": - $alarm->add(new Sabre_VObject_Property("ACTION", "DISPLAY")); + $alarm->add(new Sabre\VObject\Property("ACTION", "DISPLAY")); $text = str_replace("#name#", $summary, t("#name# is about to begin.")); - $alarm->add(new Sabre_VObject_Property("DESCRIPTION", $text)); + $alarm->add(new Sabre\VObject\Property("DESCRIPTION", $text)); break; default: continue; @@ -706,7 +706,7 @@ function wdcal_set_component_alerts(&$component, &$localization, $summary, $dtst $trigger_val .= "-P"; if (in_array($_REQUEST["noti_unit"][$key], array("H", "M", "S"))) $trigger_val .= "T"; $trigger_val .= IntVal($_REQUEST["noti_value"][$key]) . $_REQUEST["noti_unit"][$key]; - $alarm->add(new Sabre_VObject_Property($trigger_name, $trigger_val)); + $alarm->add(new Sabre\VObject\Property($trigger_name, $trigger_val)); $component->add($alarm); } @@ -785,12 +785,12 @@ function wdcal_getEditPage_exception_selector() foreach ($vObject->getComponents() as $component) { if ($component->name !== 'VTIMEZONE') break; } - /** @var Sabre_VObject_Component_VEvent $component */ + /** @var Sabre\VObject\Component\VEvent $component */ wdcal_set_component_date($component, $localization); wdcal_set_component_recurrence($component, $localization); - $it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID")); + $it = new Sabre\VObject\RecurrenceIterator($vObject, (string)$component->__get("UID")); $max_ts = mktime(0, 0, 0, 1, 1, CALDAV_MAX_YEAR + 1); $last_start = 0; diff --git a/dav/friendica/database-init.inc.php b/dav/friendica/database-init.inc.php index 527b76714..5978fd01e 100644 --- a/dav/friendica/database-init.inc.php +++ b/dav/friendica/database-init.inc.php @@ -54,6 +54,7 @@ function dav_get_update_statements($from_version) `namespace_id` int(11) unsigned NOT NULL, `displayname` varchar(200) NOT NULL, `description` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, + `needs_rebuild` TINYINT NOT NULL DEFAULT '1', `uri` varchar(50) NOT NULL, `ctag` int(11) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`) @@ -194,6 +195,7 @@ function dav_get_create_statements($except = array()) `namespace_id` int(11) unsigned NOT NULL, `displayname` varchar(200) NOT NULL, `description` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, + `needs_rebuild` TINYINT NOT NULL DEFAULT '1', `uri` varchar(50) NOT NULL, `ctag` int(11) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`) @@ -267,4 +269,4 @@ function dav_upgrade_tables() } return $errors; -} \ No newline at end of file +} From 6186153f689e4863a75bf574f97cc75ada7954c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6=C3=9Fl?= Date: Sat, 11 Aug 2012 08:07:19 +0000 Subject: [PATCH 08/84] Second part of refactoring; should be runnable again, yet not thoroughly tested --- dav/SabreDAV/ChangeLog | 10 +- dav/SabreDAV/composer.json | 17 +- .../lib/Sabre/CalDAV/Backend/Abstract.php | 4 +- dav/SabreDAV/lib/Sabre/CalDAV/Backend/PDO.php | 10 +- .../lib/Sabre/CalDAV/CalendarQueryParser.php | 10 +- .../Sabre/CalDAV/CalendarQueryValidator.php | 28 +- .../lib/Sabre/CalDAV/ICSExportPlugin.php | 6 +- dav/SabreDAV/lib/Sabre/CalDAV/Plugin.php | 30 +- .../lib/Sabre/CalDAV/Schedule/IMip.php | 6 +- dav/SabreDAV/lib/Sabre/CardDAV/Plugin.php | 8 +- dav/SabreDAV/lib/Sabre/VObject/includes.php | 39 -- .../Sabre/CalDAV/CalendarQueryVAlarmTest.php | 20 +- .../CalDAV/CalendarQueryValidatorTest.php | 6 +- .../ExpandEventsDTSTARTandDTENDTest.php | 8 +- .../ExpandEventsDTSTARTandDTENDbyDayTest.php | 8 +- .../CalDAV/ExpandEventsDoubleEventsTest.php | 4 +- .../Sabre/CalDAV/GetEventsByTimerangeTest.php | 4 +- .../Sabre/CalDAV/ICSExportPluginTest.php | 8 +- .../tests/Sabre/CalDAV/Issue166Test.php | 4 +- .../tests/Sabre/CalDAV/Issue172Test.php | 8 +- .../tests/Sabre/CalDAV/Issue203Test.php | 8 +- .../tests/Sabre/CalDAV/Issue205Test.php | 4 +- .../tests/Sabre/CalDAV/Issue228Test.php | 75 ++++ .../Sabre/VObject/Component/VEventTest.php | 69 ---- .../Sabre/VObject/Component/VJournalTest.php | 37 -- .../Sabre/VObject/Component/VTodoTest.php | 63 --- .../Sabre/VObject/DateTimeParserTest.php | 117 ------ .../tests/Sabre/VObject/Issue153Test.php | 12 - dav/SabreDAV/tests/bootstrap.php | 4 +- dav/common/calendar.fnk.php | 12 +- dav/common/calendar_rendering.fnk.php | 28 +- dav/common/dav_caldav_backend_common.inc.php | 20 +- dav/common/wdcal_backend.inc.php | 16 +- ...v_caldav_backend_virtual_friendica.inc.php | 6 +- dav/friendica/layout.fnk.php | 6 +- dav/friendica/main.php | 26 +- dav/sabre-vobject/.travis.yml | 8 + dav/sabre-vobject/ChangeLog | 7 + dav/sabre-vobject/LICENSE | 27 ++ dav/sabre-vobject/README.md | 388 ++++++++++++++++++ dav/sabre-vobject/composer.json | 27 ++ .../lib/Sabre/VObject/Component.php | 82 ++-- .../lib/Sabre/VObject/Component/VAlarm.php | 23 +- .../lib/Sabre/VObject/Component/VCalendar.php | 28 +- .../lib/Sabre/VObject/Component/VCard.php | 105 +++++ .../lib/Sabre/VObject/Component/VEvent.php | 34 +- .../lib/Sabre/VObject/Component/VJournal.php | 12 +- .../lib/Sabre/VObject/Component/VTodo.php | 12 +- .../lib/Sabre/VObject/DateTimeParser.php | 24 +- .../lib/Sabre/VObject/Element.php | 6 +- .../lib/Sabre/VObject/ElementList.php | 12 +- .../lib/Sabre/VObject/FreeBusyGenerator.php | 97 +++-- .../lib/Sabre/VObject/Node.php | 18 +- .../lib/Sabre/VObject/Parameter.php | 6 +- .../lib/Sabre/VObject/ParseException.php | 8 +- .../lib/Sabre/VObject/Property.php | 91 ++-- .../lib/Sabre/VObject/Property/DateTime.php | 43 +- .../Sabre/VObject/Property/MultiDateTime.php | 32 +- .../lib/Sabre/VObject/Reader.php | 24 +- .../lib/Sabre/VObject/RecurrenceIterator.php | 34 +- .../lib/Sabre/VObject/TimeZoneUtil.php | 20 +- .../lib/Sabre/VObject/Version.php | 8 +- .../Sabre/VObject/Component/VAlarmTest.php | 45 +- .../Sabre/VObject/Component/VCalendarTest.php | 20 +- .../Sabre/VObject/Component/VCardTest.php | 100 +++++ .../Sabre/VObject/Component/VEventTest.php | 74 ++++ .../Sabre/VObject/Component/VJournalTest.php | 41 ++ .../Sabre/VObject/Component/VTodoTest.php | 67 +++ .../tests/Sabre/VObject/ComponentTest.php | 149 ++++--- .../Sabre/VObject/DateTimeParserTest.php | 121 ++++++ .../tests/Sabre/VObject/ElementListTest.php | 10 +- .../tests/Sabre/VObject/EmClientTest.php | 8 +- .../Sabre/VObject/FreeBusyGeneratorTest.php | 40 +- .../tests/Sabre/VObject/Issue153Test.php | 14 + .../tests/Sabre/VObject/Issue154Test.php | 6 +- .../tests/Sabre/VObject/ParameterTest.php | 8 +- .../Sabre/VObject/Property/DateTimeTest.php | 95 ++--- .../VObject/Property/MultiDateTimeTest.php | 90 ++-- .../tests/Sabre/VObject/PropertyTest.php | 113 ++--- .../tests/Sabre/VObject/ReaderTest.php | 86 ++-- ...urrenceIteratorFifthTuesdayProblemTest.php | 8 +- ...urrenceIteratorInfiniteLoopProblemTest.php | 15 +- .../Sabre/VObject/RecurrenceIteratorTest.php | 241 +++++------ .../tests/Sabre/VObject/TimeZoneUtilTest.php | 24 +- .../tests/Sabre/VObject/VersionTest.php | 8 +- .../tests/Sabre/VObject/issue153.vcf | 0 dav/sabre-vobject/tests/bootstrap.php | 4 + dav/sabre-vobject/tests/phpunit.xml | 17 + 88 files changed, 2135 insertions(+), 1186 deletions(-) delete mode 100644 dav/SabreDAV/lib/Sabre/VObject/includes.php create mode 100644 dav/SabreDAV/tests/Sabre/CalDAV/Issue228Test.php delete mode 100644 dav/SabreDAV/tests/Sabre/VObject/Component/VEventTest.php delete mode 100644 dav/SabreDAV/tests/Sabre/VObject/Component/VJournalTest.php delete mode 100644 dav/SabreDAV/tests/Sabre/VObject/Component/VTodoTest.php delete mode 100644 dav/SabreDAV/tests/Sabre/VObject/DateTimeParserTest.php delete mode 100644 dav/SabreDAV/tests/Sabre/VObject/Issue153Test.php create mode 100644 dav/sabre-vobject/.travis.yml create mode 100644 dav/sabre-vobject/ChangeLog create mode 100644 dav/sabre-vobject/LICENSE create mode 100644 dav/sabre-vobject/README.md create mode 100644 dav/sabre-vobject/composer.json rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Component.php (79%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Component/VAlarm.php (79%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Component/VCalendar.php (90%) create mode 100644 dav/sabre-vobject/lib/Sabre/VObject/Component/VCard.php rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Component/VEvent.php (64%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Component/VJournal.php (79%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Component/VTodo.php (87%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/DateTimeParser.php (83%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Element.php (73%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/ElementList.php (89%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/FreeBusyGenerator.php (74%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Node.php (87%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Parameter.php (93%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/ParseException.php (54%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Property.php (69%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Property/DateTime.php (79%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Property/MultiDateTime.php (80%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Reader.php (83%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/RecurrenceIterator.php (96%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/TimeZoneUtil.php (96%) rename dav/{SabreDAV => sabre-vobject}/lib/Sabre/VObject/Version.php (81%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/Component/VAlarmTest.php (77%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/Component/VCalendarTest.php (90%) create mode 100644 dav/sabre-vobject/tests/Sabre/VObject/Component/VCardTest.php create mode 100644 dav/sabre-vobject/tests/Sabre/VObject/Component/VEventTest.php create mode 100644 dav/sabre-vobject/tests/Sabre/VObject/Component/VJournalTest.php create mode 100644 dav/sabre-vobject/tests/Sabre/VObject/Component/VTodoTest.php rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/ComponentTest.php (65%) create mode 100644 dav/sabre-vobject/tests/Sabre/VObject/DateTimeParserTest.php rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/ElementListTest.php (55%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/EmClientTest.php (81%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/FreeBusyGeneratorTest.php (81%) create mode 100644 dav/sabre-vobject/tests/Sabre/VObject/Issue153Test.php rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/Issue154Test.php (81%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/ParameterTest.php (60%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/Property/DateTimeTest.php (58%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/Property/MultiDateTimeTest.php (55%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/PropertyTest.php (57%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/ReaderTest.php (70%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/RecurrenceIteratorFifthTuesdayProblemTest.php (75%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/RecurrenceIteratorInfiniteLoopProblemTest.php (83%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/RecurrenceIteratorTest.php (75%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/TimeZoneUtilTest.php (76%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/VersionTest.php (53%) rename dav/{SabreDAV => sabre-vobject}/tests/Sabre/VObject/issue153.vcf (100%) create mode 100644 dav/sabre-vobject/tests/bootstrap.php create mode 100644 dav/sabre-vobject/tests/phpunit.xml diff --git a/dav/SabreDAV/ChangeLog b/dav/SabreDAV/ChangeLog index 1199ae766..3f424d953 100644 --- a/dav/SabreDAV/ChangeLog +++ b/dav/SabreDAV/ChangeLog @@ -14,6 +14,7 @@ only used for informational purposes. * BC Break: The DAV: namespace is no longer converted to urn:DAV. This was a workaround for a bug in older PHP versions (pre-5.3). + * Changed: The Sabre_VObject library now spawned into it's own project! * New feature: Support for caldav notifications! * Changed: Responsibility for dealing with the calendar-query is now moved from the CalDAV plugin to the CalDAV backends. This allows for @@ -33,13 +34,14 @@ * Fixed: Uploaded VCards without a UID are now rejected. (thanks Dominik!) * Fixed: Rejecting calendar objects if they are not in the supported-calendar-component list. (thanks Armin!) - * Fixed: Workaround for 10.8 Mountain Lion vCards, as it needs \r line - endings to parse them correctly. * Fixed: Issue 219: serialize() now reorders correctly. * Fixed: Sabre_DAV_XMLUtil no longer returns empty $dom->childNodes if there is whitespace in $dom. -1.6.4-stable (2012-??-??) +1.6.5-stable (2012-??-??) + * Fixed: Workaround for line-ending bug OS X 10.8 addressbook has. + +1.6.4-stable (2012-08-02) * Fixed: Issue 220: Calendar-query filters may fail when filtering on alarms, if an overridden event has it's alarm removed. * Fixed: Compatibility for OS/X 10.8 iCal in the IMipHandler. @@ -56,6 +58,8 @@ exactly on the start of a time-range. * Fixed: HTTP basic auth did not correctly deal with passwords containing colons on some servers. + * Fixed: Issue 228: DTEND is now non-inclusive for all-day events in the + calendar-query REPORT and free-busy calculations. 1.6.3-stable (2012-06-12) * Added: It's now possible to specify in Sabre_DAV_Client which type of diff --git a/dav/SabreDAV/composer.json b/dav/SabreDAV/composer.json index 8875829ec..1a427e762 100644 --- a/dav/SabreDAV/composer.json +++ b/dav/SabreDAV/composer.json @@ -1,21 +1,30 @@ { - "name": "evert/sabredav", + "name": "sabre/dav", "type": "library", "description": "WebDAV Framework for PHP", "keywords": ["Framework", "WebDAV", "CalDAV", "CardDAV", "iCalendar"], "homepage": "http://code.google.com/p/sabredav/", - "license": "New BSD License", + "license" : "BSD-3-Clause", "authors": [ { "name": "Evert Pot", "email": "evert@rooftopsolutions.nl", - "homepage" : "http://www.rooftopsolutions.nl/" + "homepage" : "http://www.rooftopsolutions.nl/", + "role" : "Developer" } ], "require": { - "php": ">=5.3.1" + "php": ">=5.3.1", + "sabre/vobject" : "master-dev" + }, + "provide" : { + "evert/sabredav" : "2.0.0" }, "autoload": { "psr-0": { "Sabre": "lib/" } + }, + "support" : { + "forum" : "https://groups.google.com/group/sabredav-discuss", + "source" : "https://github.com/evert/sabredav" } } diff --git a/dav/SabreDAV/lib/Sabre/CalDAV/Backend/Abstract.php b/dav/SabreDAV/lib/Sabre/CalDAV/Backend/Abstract.php index 480e6329f..8adf10e1b 100644 --- a/dav/SabreDAV/lib/Sabre/CalDAV/Backend/Abstract.php +++ b/dav/SabreDAV/lib/Sabre/CalDAV/Backend/Abstract.php @@ -1,5 +1,7 @@ getCalendarObject($object['calendarid'], $object['uri']); } - $vObject = Sabre_VObject_Reader::read($object['calendardata']); + $vObject = VObject\Reader::read($object['calendardata']); $validator = new Sabre_CalDAV_CalendarQueryValidator(); return $validator->validate($vObject, $filters); diff --git a/dav/SabreDAV/lib/Sabre/CalDAV/Backend/PDO.php b/dav/SabreDAV/lib/Sabre/CalDAV/Backend/PDO.php index 105ebd338..74b34267f 100644 --- a/dav/SabreDAV/lib/Sabre/CalDAV/Backend/PDO.php +++ b/dav/SabreDAV/lib/Sabre/CalDAV/Backend/PDO.php @@ -1,5 +1,7 @@ DTEND->getDateTime()->getTimeStamp(); } elseif (isset($component->DURATION)) { $endDate = clone $component->DTSTART->getDateTime(); - $endDate->add(Sabre_VObject_DateTimeParser::parse($component->DURATION->value)); + $endDate->add(VObject\DateTimeParser::parse($component->DURATION->value)); $lastOccurence = $endDate->getTimeStamp(); - } elseif ($component->DTSTART->getDateType()===Sabre_VObject_Property_DateTime::DATE) { + } elseif ($component->DTSTART->getDateType()===VObject\Property\DateTime::DATE) { $endDate = clone $component->DTSTART->getDateTime(); $endDate->modify('+1 day'); $lastOccurence = $endDate->getTimeStamp(); @@ -494,7 +496,7 @@ class Sabre_CalDAV_Backend_PDO extends Sabre_CalDAV_Backend_Abstract { $lastOccurence = $firstOccurence; } } else { - $it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->UID); + $it = new VObject\RecurrenceIterator($vObject, (string)$component->UID); $maxDate = new DateTime(self::MAX_DATE); if ($it->isInfinite()) { $lastOccurence = $maxDate->getTimeStamp(); diff --git a/dav/SabreDAV/lib/Sabre/CalDAV/CalendarQueryParser.php b/dav/SabreDAV/lib/Sabre/CalDAV/CalendarQueryParser.php index 098edccca..b95095f96 100644 --- a/dav/SabreDAV/lib/Sabre/CalDAV/CalendarQueryParser.php +++ b/dav/SabreDAV/lib/Sabre/CalDAV/CalendarQueryParser.php @@ -1,5 +1,7 @@ item(0); if ($start = $timeRangeNode->getAttribute('start')) { - $start = Sabre_VObject_DateTimeParser::parseDateTime($start); + $start = VObject\DateTimeParser::parseDateTime($start); } else { $start = null; } if ($end = $timeRangeNode->getAttribute('end')) { - $end = Sabre_VObject_DateTimeParser::parseDateTime($end); + $end = VObject\DateTimeParser::parseDateTime($end); } else { $end = null; } @@ -274,13 +276,13 @@ class Sabre_CalDAV_CalendarQueryParser { if(!$start) { throw new Sabre_DAV_Exception_BadRequest('The "start" attribute is required for the CALDAV:expand element'); } - $start = Sabre_VObject_DateTimeParser::parseDateTime($start); + $start = VObject\DateTimeParser::parseDateTime($start); $end = $parentNode->getAttribute('end'); if(!$end) { throw new Sabre_DAV_Exception_BadRequest('The "end" attribute is required for the CALDAV:expand element'); } - $end = Sabre_VObject_DateTimeParser::parseDateTime($end); + $end = VObject\DateTimeParser::parseDateTime($end); if ($end <= $start) { throw new Sabre_DAV_Exception_BadRequest('The end-date must be larger than the start-date in the expand element.'); diff --git a/dav/SabreDAV/lib/Sabre/CalDAV/CalendarQueryValidator.php b/dav/SabreDAV/lib/Sabre/CalDAV/CalendarQueryValidator.php index 8f674840e..53e86fc50 100644 --- a/dav/SabreDAV/lib/Sabre/CalDAV/CalendarQueryValidator.php +++ b/dav/SabreDAV/lib/Sabre/CalDAV/CalendarQueryValidator.php @@ -1,5 +1,7 @@ parent->name === 'VEVENT' && $component->parent->RRULE) { // Fire up the iterator! - $it = new Sabre_VObject_RecurrenceIterator($component->parent->parent, (string)$component->parent->UID); + $it = new VObject\RecurrenceIterator($component->parent->parent, (string)$component->parent->UID); while($it->valid()) { $expandedEvent = $it->getEventObject(); diff --git a/dav/SabreDAV/lib/Sabre/CalDAV/ICSExportPlugin.php b/dav/SabreDAV/lib/Sabre/CalDAV/ICSExportPlugin.php index ec42b406b..d3e4e7b72 100644 --- a/dav/SabreDAV/lib/Sabre/CalDAV/ICSExportPlugin.php +++ b/dav/SabreDAV/lib/Sabre/CalDAV/ICSExportPlugin.php @@ -1,5 +1,7 @@ version = '2.0'; if (Sabre_DAV_Server::$exposeVersion) { $calendar->prodid = '-//SabreDAV//SabreDAV ' . Sabre_DAV_Version::VERSION . '//EN'; @@ -103,7 +105,7 @@ class Sabre_CalDAV_ICSExportPlugin extends Sabre_DAV_ServerPlugin { } $nodeData = $node[200]['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}calendar-data']; - $nodeComp = Sabre_VObject_Reader::read($nodeData); + $nodeComp = VObject\Reader::read($nodeData); foreach($nodeComp->children() as $child) { diff --git a/dav/SabreDAV/lib/Sabre/CalDAV/Plugin.php b/dav/SabreDAV/lib/Sabre/CalDAV/Plugin.php index 0b0978f14..c0e4a206d 100644 --- a/dav/SabreDAV/lib/Sabre/CalDAV/Plugin.php +++ b/dav/SabreDAV/lib/Sabre/CalDAV/Plugin.php @@ -1,5 +1,7 @@ server->getPropertiesForPath($uri,$properties); if ($expand && isset($objProps[200]['{' . self::NS_CALDAV . '}calendar-data'])) { - $vObject = Sabre_VObject_Reader::read($objProps[200]['{' . self::NS_CALDAV . '}calendar-data']); + $vObject = VObject\Reader::read($objProps[200]['{' . self::NS_CALDAV . '}calendar-data']); $vObject->expand($start, $end); $objProps[200]['{' . self::NS_CALDAV . '}calendar-data'] = $vObject->serialize(); } @@ -543,7 +545,7 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin { if (isset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) { $validator = new Sabre_CalDAV_CalendarQueryValidator(); - $vObject = Sabre_VObject_Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']); + $vObject = VObject\Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']); if ($validator->validate($vObject,$parser->filters)) { // If the client didn't require the calendar-data property, @@ -577,7 +579,7 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin { if ($parser->expand) { // We need to do some post-processing - $vObject = Sabre_VObject_Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']); + $vObject = VObject\Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']); $vObject->expand($parser->expand['start'], $parser->expand['end']); $properties[200]['{' . self::NS_CALDAV . '}calendar-data'] = $vObject->serialize(); } @@ -617,10 +619,10 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin { } if ($start) { - $start = Sabre_VObject_DateTimeParser::parseDateTime($start); + $start = VObject\DateTimeParser::parseDateTime($start); } if ($end) { - $end = Sabre_VObject_DateTimeParser::parseDateTime($end); + $end = VObject\DateTimeParser::parseDateTime($end); } if (!$start && !$end) { @@ -647,7 +649,7 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin { return $obj; }, $calendar->getChildren()); - $generator = new Sabre_VObject_FreeBusyGenerator(); + $generator = new VObject\FreeBusyGenerator(); $generator->setObjects($objects); $generator->setTimeRange($start, $end); $result = $generator->getResult(); @@ -763,9 +765,9 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin { try { - $vobj = Sabre_VObject_Reader::read($data); + $vobj = VObject\Reader::read($data); - } catch (Sabre_VObject_ParseException $e) { + } catch (VObject\ParseException $e) { throw new Sabre_DAV_Exception_UnsupportedMediaType('This resource only supports valid iCalendar 2.0 data. Parse error: ' . $e->getMessage()); @@ -868,8 +870,8 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin { } try { - $vObject = Sabre_VObject_Reader::read($this->server->httpRequest->getBody(true)); - } catch (Sabre_VObject_ParseException $e) { + $vObject = VObject\Reader::read($this->server->httpRequest->getBody(true)); + } catch (VObject\ParseException $e) { throw new Sabre_DAV_Exception_BadRequest('The request body must be a valid iCalendar object. Parse error: ' . $e->getMessage()); } @@ -920,10 +922,10 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin { * * @param string $originator * @param array $recipients - * @param Sabre_VObject_Component $vObject + * @param Sabre\VObject\Component $vObject * @return array */ - protected function iMIPMessage($originator, array $recipients, Sabre_VObject_Component $vObject, $principal) { + protected function iMIPMessage($originator, array $recipients, VObject\Component $vObject, $principal) { if (!$this->imipHandler) { $resultStatus = '5.2;This server does not support this operation'; diff --git a/dav/SabreDAV/lib/Sabre/CalDAV/Schedule/IMip.php b/dav/SabreDAV/lib/Sabre/CalDAV/Schedule/IMip.php index 1be63a06b..f62f94af3 100644 --- a/dav/SabreDAV/lib/Sabre/CalDAV/Schedule/IMip.php +++ b/dav/SabreDAV/lib/Sabre/CalDAV/Schedule/IMip.php @@ -1,5 +1,7 @@ getMessage()); @@ -441,7 +443,7 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin { */ public function validateFilters($vcardData, array $filters, $test) { - $vcard = Sabre_VObject_Reader::read($vcardData); + $vcard = VObject\Reader::read($vcardData); if (!$filters) return true; diff --git a/dav/SabreDAV/lib/Sabre/VObject/includes.php b/dav/SabreDAV/lib/Sabre/VObject/includes.php deleted file mode 100644 index 76497d6ff..000000000 --- a/dav/SabreDAV/lib/Sabre/VObject/includes.php +++ /dev/null @@ -1,39 +0,0 @@ -RRULE = 'FREQ=MONTHLY'; $vevent->DTSTART = '20120101T120000Z'; $vevent->UID = 'bla'; - $valarm = Sabre_VObject_Component::create('VALARM'); + $valarm = VObject\Component::create('VALARM'); $valarm->TRIGGER = '-P15D'; $vevent->add($valarm); - $vcalendar = Sabre_VObject_Component::create('VCALENDAR'); + $vcalendar = VObject\Component::create('VCALENDAR'); $vcalendar->add($vevent); $filter = array( @@ -52,16 +54,16 @@ class Sabre_CalDAV_CalendarQueryVAlarmTest extends PHPUnit_Framework_TestCase { // A limited recurrence rule, should return false - $vevent = Sabre_VObject_Component::create('VEVENT'); + $vevent = VObject\Component::create('VEVENT'); $vevent->RRULE = 'FREQ=MONTHLY;COUNT=1'; $vevent->DTSTART = '20120101T120000Z'; $vevent->UID = 'bla'; - $valarm = Sabre_VObject_Component::create('VALARM'); + $valarm = VObject\Component::create('VALARM'); $valarm->TRIGGER = '-P15D'; $vevent->add($valarm); - $vcalendar = Sabre_VObject_Component::create('VCALENDAR'); + $vcalendar = VObject\Component::create('VCALENDAR'); $vcalendar->add($vevent); $this->assertFalse($validator->validate($vcalendar, $filter)); @@ -69,15 +71,15 @@ class Sabre_CalDAV_CalendarQueryVAlarmTest extends PHPUnit_Framework_TestCase { function testAlarmWayBefore() { - $vevent = Sabre_VObject_Component::create('VEVENT'); + $vevent = VObject\Component::create('VEVENT'); $vevent->DTSTART = '20120101T120000Z'; $vevent->UID = 'bla'; - $valarm = Sabre_VObject_Component::create('VALARM'); + $valarm = VObject\Component::create('VALARM'); $valarm->TRIGGER = '-P2W1D'; $vevent->add($valarm); - $vcalendar = Sabre_VObject_Component::create('VCALENDAR'); + $vcalendar = VObject\Component::create('VCALENDAR'); $vcalendar->add($vevent); $filter = array( diff --git a/dav/SabreDAV/tests/Sabre/CalDAV/CalendarQueryValidatorTest.php b/dav/SabreDAV/tests/Sabre/CalDAV/CalendarQueryValidatorTest.php index 18c8330db..dede4764b 100644 --- a/dav/SabreDAV/tests/Sabre/CalDAV/CalendarQueryValidatorTest.php +++ b/dav/SabreDAV/tests/Sabre/CalDAV/CalendarQueryValidatorTest.php @@ -1,5 +1,7 @@ null, ); - $vObject = Sabre_VObject_Reader::read($icalObject); + $vObject = VObject\Reader::read($icalObject); switch($outcome) { case 0 : @@ -31,7 +33,7 @@ class Sabre_CalDAV_CalendarQueryValidatorTest extends PHPUnit_Framework_TestCase case -1 : try { $validator->validate($vObject, $filters); - } catch (Sabre_DAV_Exception $e) { + } catch (Exception $e) { // Success } break; diff --git a/dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php b/dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php index 984212aa2..444dc496b 100644 --- a/dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php +++ b/dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php @@ -1,5 +1,7 @@ VEVENT as $vevent) { - /** @var $vevent Sabre_VObject_Component_VEvent */ + /** @var $vevent Sabre\VObject\Component_VEvent */ foreach ($vevent->children as $child) { - /** @var $child Sabre_VObject_Property */ + /** @var $child Sabre\VObject\Property */ if ($child->name == 'DTSTART') { // DTSTART has to be one of three valid values diff --git a/dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php b/dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php index a2c2fc275..a183082b5 100644 --- a/dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php +++ b/dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php @@ -1,5 +1,7 @@ assertEquals(2, count($vObject->VEVENT)); // check if DTSTARTs and DTENDs are correct foreach ($vObject->VEVENT as $vevent) { - /** @var $vevent Sabre_VObject_Component_VEvent */ + /** @var $vevent Sabre\VObject\Component\VEvent */ foreach ($vevent->children as $child) { - /** @var $child Sabre_VObject_Property */ + /** @var $child Sabre\VObject\Property */ if ($child->name == 'DTSTART') { // DTSTART has to be one of two valid values diff --git a/dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php b/dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php index 55d06b231..087c384fa 100644 --- a/dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php +++ b/dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php @@ -1,5 +1,7 @@ assertEquals(3, count($vObject->VEVENT),'We got 6 events instead of 3. Output: ' . $body); diff --git a/dav/SabreDAV/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php b/dav/SabreDAV/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php index b8a97ca1d..d9a6d586b 100644 --- a/dav/SabreDAV/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php +++ b/dav/SabreDAV/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php @@ -1,5 +1,7 @@ assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body); diff --git a/dav/SabreDAV/tests/Sabre/CalDAV/ICSExportPluginTest.php b/dav/SabreDAV/tests/Sabre/CalDAV/ICSExportPluginTest.php index d23b81231..c569da8f7 100644 --- a/dav/SabreDAV/tests/Sabre/CalDAV/ICSExportPluginTest.php +++ b/dav/SabreDAV/tests/Sabre/CalDAV/ICSExportPluginTest.php @@ -1,5 +1,7 @@ 'text/calendar', ), $s->httpResponse->headers); - $obj = Sabre_VObject_Reader::read($s->httpResponse->body); + $obj = VObject\Reader::read($s->httpResponse->body); $this->assertEquals(5,count($obj->children())); $this->assertEquals(1,count($obj->VERSION)); @@ -98,7 +100,7 @@ class Sabre_CalDAV_ICSExportPluginTest extends PHPUnit_Framework_TestCase { 'Content-Type' => 'text/calendar', ), $s->httpResponse->headers); - $obj = Sabre_VObject_Reader::read($s->httpResponse->body); + $obj = VObject\Reader::read($s->httpResponse->body); $this->assertEquals(5,count($obj->children())); $this->assertEquals(1,count($obj->VERSION)); @@ -211,7 +213,7 @@ class Sabre_CalDAV_ICSExportPluginTest extends PHPUnit_Framework_TestCase { 'Content-Type' => 'text/calendar', ), $s->httpResponse->headers); - $obj = Sabre_VObject_Reader::read($s->httpResponse->body); + $obj = VObject\Reader::read($s->httpResponse->body); $this->assertEquals(5,count($obj->children())); $this->assertEquals(1,count($obj->VERSION)); diff --git a/dav/SabreDAV/tests/Sabre/CalDAV/Issue166Test.php b/dav/SabreDAV/tests/Sabre/CalDAV/Issue166Test.php index 3a61663ec..11d2f21ce 100644 --- a/dav/SabreDAV/tests/Sabre/CalDAV/Issue166Test.php +++ b/dav/SabreDAV/tests/Sabre/CalDAV/Issue166Test.php @@ -1,5 +1,7 @@ false, 'time-range' => null, ); - $input = Sabre_VObject_Reader::read($input); + $input = VObject\Reader::read($input); $this->assertTrue($validator->validate($input,$filters)); } diff --git a/dav/SabreDAV/tests/Sabre/CalDAV/Issue172Test.php b/dav/SabreDAV/tests/Sabre/CalDAV/Issue172Test.php index 024b25579..90e13fd84 100644 --- a/dav/SabreDAV/tests/Sabre/CalDAV/Issue172Test.php +++ b/dav/SabreDAV/tests/Sabre/CalDAV/Issue172Test.php @@ -1,5 +1,7 @@ array(), ); - $input = Sabre_VObject_Reader::read($input); + $input = VObject\Reader::read($input); $this->assertTrue($validator->validate($input,$filters)); } @@ -77,7 +79,7 @@ HI; ), 'prop-filters' => array(), ); - $input = Sabre_VObject_Reader::read($input); + $input = VObject\Reader::read($input); $this->assertTrue($validator->validate($input,$filters)); } @@ -125,7 +127,7 @@ HI; ), 'prop-filters' => array(), ); - $input = Sabre_VObject_Reader::read($input); + $input = VObject\Reader::read($input); $this->assertTrue($validator->validate($input,$filters)); } } diff --git a/dav/SabreDAV/tests/Sabre/CalDAV/Issue203Test.php b/dav/SabreDAV/tests/Sabre/CalDAV/Issue203Test.php index e9eaecab8..4cb8eec9a 100644 --- a/dav/SabreDAV/tests/Sabre/CalDAV/Issue203Test.php +++ b/dav/SabreDAV/tests/Sabre/CalDAV/Issue203Test.php @@ -1,5 +1,7 @@ assertEquals(2, count($vObject->VEVENT)); @@ -113,10 +115,10 @@ END:VCALENDAR $matching = false; foreach ($vObject->VEVENT as $vevent) { - /** @var $vevent Sabre_VObject_Component_VEvent */ + /** @var $vevent Sabre\VObject\Component\VEvent */ foreach ($vevent->children as $child) { - /** @var $child Sabre_VObject_Property */ + /** @var $child Sabre\VObject\Property */ if (isset($expectedEvent[$child->name])) { if ($expectedEvent[$child->name] != $child->value) { diff --git a/dav/SabreDAV/tests/Sabre/CalDAV/Issue205Test.php b/dav/SabreDAV/tests/Sabre/CalDAV/Issue205Test.php index 20098252e..6e9e497ca 100644 --- a/dav/SabreDAV/tests/Sabre/CalDAV/Issue205Test.php +++ b/dav/SabreDAV/tests/Sabre/CalDAV/Issue205Test.php @@ -1,5 +1,7 @@ assertEquals(1, count($vObject->VEVENT)); diff --git a/dav/SabreDAV/tests/Sabre/CalDAV/Issue228Test.php b/dav/SabreDAV/tests/Sabre/CalDAV/Issue228Test.php new file mode 100644 index 000000000..f251ab13e --- /dev/null +++ b/dav/SabreDAV/tests/Sabre/CalDAV/Issue228Test.php @@ -0,0 +1,75 @@ + 1, + 'name' => 'Calendar', + 'principaluri' => 'principals/user1', + 'uri' => 'calendar1', + ) + ); + + protected $caldavCalendarObjects = array( + 1 => array( + 'event.ics' => array( + 'calendardata' => 'BEGIN:VCALENDAR +VERSION:2.0 +BEGIN:VEVENT +UID:20120730T113415CEST-6804EGphkd@xxxxxx.de +DTSTAMP:20120730T093415Z +DTSTART;VALUE=DATE:20120729 +DTEND;VALUE=DATE:20120730 +SUMMARY:sunday event +TRANSP:TRANSPARENT +END:VEVENT +END:VCALENDAR +', + ), + ), + ); + + function testIssue228() { + + $request = new Sabre_HTTP_Request(array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_CONTENT_TYPE' => 'application/xml', + 'REQUEST_URI' => '/calendars/user1/calendar1', + 'HTTP_DEPTH' => '1', + )); + + $request->setBody(' + + + + + + + + + + + + + + +'); + + $response = $this->request($request); + + // We must check if absolutely nothing was returned from this query. + $this->assertFalse(strpos($response->body, 'BEGIN:VCALENDAR')); + + } +} diff --git a/dav/SabreDAV/tests/Sabre/VObject/Component/VEventTest.php b/dav/SabreDAV/tests/Sabre/VObject/Component/VEventTest.php deleted file mode 100644 index 90579cb41..000000000 --- a/dav/SabreDAV/tests/Sabre/VObject/Component/VEventTest.php +++ /dev/null @@ -1,69 +0,0 @@ -assertEquals($outcome, $vevent->isInTimeRange($start, $end)); - - } - - public function timeRangeTestData() { - - $tests = array(); - - $vevent = new Sabre_VObject_Component_VEvent('VEVENT'); - $vevent->DTSTART = '20111223T120000Z'; - $tests[] = array($vevent, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vevent, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - $vevent2 = clone $vevent; - $vevent2->DTEND = '20111225T120000Z'; - $tests[] = array($vevent2, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vevent2, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - $vevent3 = clone $vevent; - $vevent3->DURATION = 'P1D'; - $tests[] = array($vevent3, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vevent3, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - $vevent4 = clone $vevent; - $vevent4->DTSTART = '20111225'; - $vevent4->DTSTART['VALUE'] = 'DATE'; - $tests[] = array($vevent4, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vevent4, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - // Event with no end date should be treated as lasting the entire day. - $tests[] = array($vevent4, new DateTime('2011-12-25 16:00:00'), new DateTime('2011-12-25 17:00:00'), true); - - - $vevent5 = clone $vevent; - $vevent5->DURATION = 'P1D'; - $vevent5->RRULE = 'FREQ=YEARLY'; - $tests[] = array($vevent5, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vevent5, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - $tests[] = array($vevent5, new DateTime('2013-12-01'), new DateTime('2013-12-31'), true); - - $vevent6 = clone $vevent; - $vevent6->DTSTART = '20111225'; - $vevent6->DTSTART['VALUE'] = 'DATE'; - $vevent6->DTEND = '20111225'; - $vevent6->DTEND['VALUE'] = 'DATE'; - $tests[] = array($vevent6, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vevent6, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - // Added this test to ensure that recurrence rules with no DTEND also - // get checked for the entire day. - $vevent7 = clone $vevent; - $vevent7->DTSTART = '20120101'; - $vevent7->DTSTART['VALUE'] = 'DATE'; - $vevent7->RRULE = 'FREQ=MONTHLY'; - $tests[] = array($vevent7, new DateTime('2012-02-01 15:00:00'), new DateTime('2012-02-02'), true); - return $tests; - - } - -} - diff --git a/dav/SabreDAV/tests/Sabre/VObject/Component/VJournalTest.php b/dav/SabreDAV/tests/Sabre/VObject/Component/VJournalTest.php deleted file mode 100644 index 04fcc9dba..000000000 --- a/dav/SabreDAV/tests/Sabre/VObject/Component/VJournalTest.php +++ /dev/null @@ -1,37 +0,0 @@ -assertEquals($outcome, $vtodo->isInTimeRange($start, $end)); - - } - - public function timeRangeTestData() { - - $tests = array(); - - $vjournal = Sabre_VObject_Component::create('VJOURNAL'); - $vjournal->DTSTART = '20111223T120000Z'; - $tests[] = array($vjournal, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vjournal, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - $vjournal2 = Sabre_VObject_Component::create('VJOURNAL'); - $vjournal2->DTSTART = '20111223'; - $vjournal2->DTSTART['VALUE'] = 'DATE'; - $tests[] = array($vjournal2, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vjournal2, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - $vjournal3 = Sabre_VObject_Component::create('VJOURNAL'); - $tests[] = array($vjournal3, new DateTime('2011-01-01'), new DateTime('2012-01-01'), false); - $tests[] = array($vjournal3, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - return $tests; - } - -} - diff --git a/dav/SabreDAV/tests/Sabre/VObject/Component/VTodoTest.php b/dav/SabreDAV/tests/Sabre/VObject/Component/VTodoTest.php deleted file mode 100644 index a8bd619af..000000000 --- a/dav/SabreDAV/tests/Sabre/VObject/Component/VTodoTest.php +++ /dev/null @@ -1,63 +0,0 @@ -assertEquals($outcome, $vtodo->isInTimeRange($start, $end)); - - } - - public function timeRangeTestData() { - - $tests = array(); - - $vtodo = Sabre_VObject_Component::create('VTODO'); - $vtodo->DTSTART = '20111223T120000Z'; - $tests[] = array($vtodo, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vtodo, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - $vtodo2 = clone $vtodo; - $vtodo2->DURATION = 'P1D'; - $tests[] = array($vtodo2, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vtodo2, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - $vtodo3 = clone $vtodo; - $vtodo3->DUE = '20111225'; - $tests[] = array($vtodo3, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vtodo3, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - $vtodo4 = Sabre_VObject_Component::create('VTODO'); - $vtodo4->DUE = '20111225'; - $tests[] = array($vtodo4, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vtodo4, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - $vtodo5 = Sabre_VObject_Component::create('VTODO'); - $vtodo5->COMPLETED = '20111225'; - $tests[] = array($vtodo5, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vtodo5, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - $vtodo6 = Sabre_VObject_Component::create('VTODO'); - $vtodo6->CREATED = '20111225'; - $tests[] = array($vtodo6, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vtodo6, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - $vtodo7 = Sabre_VObject_Component::create('VTODO'); - $vtodo7->CREATED = '20111225'; - $vtodo7->COMPLETED = '20111226'; - $tests[] = array($vtodo7, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vtodo7, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false); - - $vtodo7 = Sabre_VObject_Component::create('VTODO'); - $tests[] = array($vtodo7, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true); - $tests[] = array($vtodo7, new DateTime('2011-01-01'), new DateTime('2011-11-01'), true); - - return $tests; - - } - -} - diff --git a/dav/SabreDAV/tests/Sabre/VObject/DateTimeParserTest.php b/dav/SabreDAV/tests/Sabre/VObject/DateTimeParserTest.php deleted file mode 100644 index 83e4c4299..000000000 --- a/dav/SabreDAV/tests/Sabre/VObject/DateTimeParserTest.php +++ /dev/null @@ -1,117 +0,0 @@ -assertEquals('+1 weeks', Sabre_VObject_DateTimeParser::parseDuration('P1W',true)); - $this->assertEquals('+5 days', Sabre_VObject_DateTimeParser::parseDuration('P5D',true)); - $this->assertEquals('+5 days 3 hours 50 minutes 12 seconds', Sabre_VObject_DateTimeParser::parseDuration('P5DT3H50M12S',true)); - $this->assertEquals('-1 weeks 50 minutes', Sabre_VObject_DateTimeParser::parseDuration('-P1WT50M',true)); - $this->assertEquals('+50 days 3 hours 2 seconds', Sabre_VObject_DateTimeParser::parseDuration('+P50DT3H2S',true)); - $this->assertEquals(new DateInterval('PT0S'), Sabre_VObject_DateTimeParser::parseDuration('PT0S')); - - } - - function testParseICalendarDurationDateInterval() { - - $expected = new DateInterval('P7D'); - $this->assertEquals($expected, Sabre_VObject_DateTimeParser::parseDuration('P1W')); - $this->assertEquals($expected, Sabre_VObject_DateTimeParser::parse('P1W')); - - $expected = new DateInterval('PT3M'); - $expected->invert = true; - $this->assertEquals($expected, Sabre_VObject_DateTimeParser::parseDuration('-PT3M')); - - } - - /** - * @expectedException Sabre_DAV_Exception_BadRequest - */ - function testParseICalendarDurationFail() { - - Sabre_VObject_DateTimeParser::parseDuration('P1X',true); - - } - - function testParseICalendarDateTime() { - - $dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20100316T141405'); - - $compare = new DateTime('2010-03-16 14:14:05',new DateTimeZone('UTC')); - - $this->assertEquals($compare, $dateTime); - - } - - /** - * @depends testParseICalendarDateTime - * @expectedException Sabre_DAV_Exception_BadRequest - */ - function testParseICalendarDateTimeBadFormat() { - - $dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20100316T141405 '); - - } - - /** - * @depends testParseICalendarDateTime - */ - function testParseICalendarDateTimeUTC() { - - $dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20100316T141405Z'); - - $compare = new DateTime('2010-03-16 14:14:05',new DateTimeZone('UTC')); - $this->assertEquals($compare, $dateTime); - - } - - /** - * @depends testParseICalendarDateTime - */ - function testParseICalendarDateTimeUTC2() { - - $dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20101211T160000Z'); - - $compare = new DateTime('2010-12-11 16:00:00',new DateTimeZone('UTC')); - $this->assertEquals($compare, $dateTime); - - } - - /** - * @depends testParseICalendarDateTime - */ - function testParseICalendarDateTimeCustomTimeZone() { - - $dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20100316T141405', new DateTimeZone('Europe/Amsterdam')); - - $compare = new DateTime('2010-03-16 13:14:05',new DateTimeZone('UTC')); - $this->assertEquals($compare, $dateTime); - - } - - function testParseICalendarDate() { - - $dateTime = Sabre_VObject_DateTimeParser::parseDate('20100316'); - - $expected = new DateTime('2010-03-16 00:00:00',new DateTimeZone('UTC')); - - $this->assertEquals($expected, $dateTime); - - $dateTime = Sabre_VObject_DateTimeParser::parse('20100316'); - $this->assertEquals($expected, $dateTime); - - } - - /** - * @depends testParseICalendarDate - * @expectedException Sabre_DAV_Exception_BadRequest - */ - function testParseICalendarDateBadFormat() { - - $dateTime = Sabre_VObject_DateTimeParser::parseDate('20100316T141405'); - - } -} diff --git a/dav/SabreDAV/tests/Sabre/VObject/Issue153Test.php b/dav/SabreDAV/tests/Sabre/VObject/Issue153Test.php deleted file mode 100644 index 16557c525..000000000 --- a/dav/SabreDAV/tests/Sabre/VObject/Issue153Test.php +++ /dev/null @@ -1,12 +0,0 @@ -assertEquals('Test Benutzer', (string)$obj->fn); - - } - -} diff --git a/dav/SabreDAV/tests/bootstrap.php b/dav/SabreDAV/tests/bootstrap.php index 8dcae248b..c3be7366c 100644 --- a/dav/SabreDAV/tests/bootstrap.php +++ b/dav/SabreDAV/tests/bootstrap.php @@ -4,9 +4,9 @@ define('SABRE_MYSQLDSN','mysql:host=127.0.0.1;dbname=sabredav'); define('SABRE_MYSQLUSER','root'); define('SABRE_MYSQLPASS',''); -set_include_path(dirname(__FILE__) . PATH_SEPARATOR . dirname(__FILE__) . '/../lib/' . PATH_SEPARATOR . get_include_path()); +set_include_path(__DIR__ . '/../lib/' . PATH_SEPARATOR . __DIR__ . PATH_SEPARATOR . get_include_path()); -include 'Sabre/autoload.php'; +include __DIR__ . '/../vendor/autoload.php'; include 'Sabre/DAVServerTest.php'; date_default_timezone_set('GMT'); diff --git a/dav/common/calendar.fnk.php b/dav/common/calendar.fnk.php index cd5efa57f..13d2cdbb8 100644 --- a/dav/common/calendar.fnk.php +++ b/dav/common/calendar.fnk.php @@ -298,7 +298,7 @@ function dav_get_current_user_calendars(&$server, $with_privilege = "") * @param Sabre_CalDAV_Calendar $calendar * @param string $calendarobject_uri * @param string $with_privilege - * @return null|Sabre_VObject_Component_VCalendar + * @return null|Sabre\VObject\Component\VCalendar */ function dav_get_current_user_calendarobject(&$server, &$calendar, $calendarobject_uri, $with_privilege = "") { @@ -314,7 +314,7 @@ function dav_get_current_user_calendarobject(&$server, &$calendar, $calendarobje if (!$aclplugin->checkPrivileges($uri, $with_privilege, Sabre_DAVACL_Plugin::R_PARENT, false)) return null; $data = $obj->get(); - $vObject = Sabre_VObject_Reader::read($data); + $vObject = Sabre\VObject\Reader::read($data); return $vObject; } @@ -342,20 +342,20 @@ function dav_get_current_user_calendar_by_id(&$server, $id, $with_privilege = "" /** * @param string $uid - * @return Sabre_VObject_Component_VCalendar $vObject + * @return Sabre\VObject\Component\VCalendar $vObject */ function dav_create_empty_vevent($uid = "") { $a = get_app(); if ($uid == "") $uid = uniqid(); - return Sabre_VObject_Reader::read("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//" . DAV_APPNAME . "//DAV-Plugin//EN\r\nBEGIN:VEVENT\r\nUID:" . $uid . "@" . dav_compat_get_hostname() . + return Sabre\VObject\Reader::read("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//" . DAV_APPNAME . "//DAV-Plugin//EN\r\nBEGIN:VEVENT\r\nUID:" . $uid . "@" . dav_compat_get_hostname() . "\r\nDTSTAMP:" . date("Ymd") . "T" . date("His") . "Z\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"); } /** - * @param Sabre_VObject_Component_VCalendar $vObject - * @return Sabre_VObject_Component_VEvent|null + * @param Sabre\VObject\Component\VCalendar $vObject + * @return Sabre\VObject\Component\VEvent|null */ function dav_get_eventComponent(&$vObject) { diff --git a/dav/common/calendar_rendering.fnk.php b/dav/common/calendar_rendering.fnk.php index f82247957..d80892f7c 100644 --- a/dav/common/calendar_rendering.fnk.php +++ b/dav/common/calendar_rendering.fnk.php @@ -3,8 +3,8 @@ /** - * @param Sabre_VObject_Component_VAlarm $alarm - * @param Sabre_VObject_Component_VEvent|Sabre_VObject_Component_VTodo $parent + * @param Sabre\VObject\Component\VAlarm $alarm + * @param Sabre\VObject\Component\VEvent|Sabre\VObject\Component\VTodo $parent * @return DateTime|null * @throws Sabre_DAV_Exception */ @@ -12,12 +12,12 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent) { $trigger = $alarm->__get("TRIGGER"); if (!isset($trigger['VALUE']) || strtoupper($trigger['VALUE']) === 'DURATION') { - $triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($trigger->value); + $triggerDuration = Sabre\VObject\DateTimeParser::parseDuration($trigger->value); $related = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'END' : 'START'; if ($related === 'START') { - /** @var Sabre_VObject_Property_DateTime $dtstart */ + /** @var Sabre\VObject\Property\DateTime $dtstart */ $dtstart = $parent->__get("DTSTART"); $effectiveTrigger = $dtstart->getDateTime(); $effectiveTrigger->add($triggerDuration); @@ -28,14 +28,14 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent) $endProp = 'DTEND'; } - /** @var Sabre_VObject_Property_DateTime $dtstart */ + /** @var Sabre\VObject\Property\DateTime $dtstart */ $dtstart = $parent->__get("DTSTART"); if (isset($parent->$endProp)) { $effectiveTrigger = clone $parent->$endProp->getDateTime(); $effectiveTrigger->add($triggerDuration); } elseif ($parent->__get("DURATION") != "") { $effectiveTrigger = clone $dtstart->getDateTime(); - $duration = Sabre_VObject_DateTimeParser::parseDuration($parent->__get("DURATION")); + $duration = Sabre\VObject\DateTimeParser::parseDuration($parent->__get("DURATION")); $effectiveTrigger->add($duration); $effectiveTrigger->add($triggerDuration); } else { @@ -58,10 +58,10 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent) */ function renderCalDavEntry_data(&$calendar, &$calendarobject) { - /** @var Sabre_VObject_Component_VCalendar $vObject */ - $vObject = Sabre_VObject_Reader::read($calendarobject["calendardata"]); + /** @var Sabre\VObject\Component\VCalendar $vObject */ + $vObject = Sabre\VObject\Reader::read($calendarobject["calendardata"]); $componentType = null; - /** @var Sabre_VObject_Component_VEvent $component */ + /** @var Sabre\VObject\Component\VEvent $component */ $component = null; foreach ($vObject->getComponents() as $component) { if ($component->name !== 'VTIMEZONE') { @@ -86,18 +86,18 @@ function renderCalDavEntry_data(&$calendar, &$calendarobject) ); $recurring = ($component->__get("RRULE") ? 1 : 0); - /** @var Sabre_VObject_Property_DateTime $dtstart */ + /** @var Sabre\VObject\Property\DateTime $dtstart */ $dtstart = $component->__get("DTSTART"); - $allday = ($dtstart->getDateType() == Sabre_VObject_Property_DateTime::DATE ? 1 : 0); + $allday = ($dtstart->getDateType() == Sabre\VObject\Property\DateTime::DATE ? 1 : 0); - /** @var array|Sabre_VObject_Component_VAlarm[] $alarms */ + /** @var array|Sabre\VObject\Component\VAlarm[] $alarms */ $alarms = array(); foreach ($component->getComponents() as $a_component) if ($a_component->name == "VALARM") { - /** var Sabre_VObject_Component_VAlarm $component */ + /** var Sabre\VObject\Component\VAlarm $component */ $alarms[] = $a_component; } - $it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID")); + $it = new Sabre\VObject\RecurrenceIterator($vObject, (string)$component->__get("UID")); $last_end = 0; $max_ts = mktime(0, 0, 0, 1, 1, CALDAV_MAX_YEAR * 1); $first = true; diff --git a/dav/common/dav_caldav_backend_common.inc.php b/dav/common/dav_caldav_backend_common.inc.php index 99fcb6c10..97d5722a9 100644 --- a/dav/common/dav_caldav_backend_common.inc.php +++ b/dav/common/dav_caldav_backend_common.inc.php @@ -81,22 +81,22 @@ abstract class Sabre_CalDAV_Backend_Common extends Sabre_CalDAV_Backend_Abstract /** * @static - * @param Sabre_VObject_Component_VEvent $component + * @param Sabre\VObject\Component\VEvent $component * @return int */ public static function getDtEndTimeStamp(&$component) { - /** @var Sabre_VObject_Property_DateTime $dtstart */ + /** @var Sabre\VObject\Property\DateTime $dtstart */ $dtstart = $component->__get("DTSTART"); if ($component->__get("DTEND")) { - /** @var Sabre_VObject_Property_DateTime $dtend */ + /** @var Sabre\VObject\Property\DateTime $dtend */ $dtend = $component->__get("DTEND"); return $dtend->getDateTime()->getTimeStamp(); } elseif ($component->__get("DURATION")) { $endDate = clone $dtstart->getDateTime(); - $endDate->add(Sabre_VObject_DateTimeParser::parse($component->__get("DURATION")->value)); + $endDate->add(Sabre\VObject\DateTimeParser::parse($component->__get("DURATION")->value)); return $endDate->getTimeStamp(); - } elseif ($dtstart->getDateType() === Sabre_VObject_Property_DateTime::DATE) { + } elseif ($dtstart->getDateType() === Sabre\VObject\Property\DateTime::DATE) { $endDate = clone $dtstart->getDateTime(); $endDate->modify('+1 day'); return $endDate->getTimeStamp(); @@ -124,8 +124,8 @@ abstract class Sabre_CalDAV_Backend_Common extends Sabre_CalDAV_Backend_Abstract */ protected function getDenormalizedData($calendarData) { - /** @var Sabre_VObject_Component_VEvent $vObject */ - $vObject = Sabre_VObject_Reader::read($calendarData); + /** @var Sabre\VObject\Component\VEvent $vObject */ + $vObject = Sabre\VObject\Reader::read($calendarData); $componentType = null; $component = null; $firstOccurence = null; @@ -141,15 +141,15 @@ abstract class Sabre_CalDAV_Backend_Common extends Sabre_CalDAV_Backend_Abstract throw new Sabre_DAV_Exception_BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); } if ($componentType === 'VEVENT') { - /** @var Sabre_VObject_Component_VEvent $component */ - /** @var Sabre_VObject_Property_DateTime $dtstart */ + /** @var Sabre\VObject\Component\VEvent $component */ + /** @var Sabre\VObject\Property\DateTime $dtstart */ $dtstart = $component->__get("DTSTART"); $firstOccurence = $dtstart->getDateTime()->getTimeStamp(); // Finding the last occurence is a bit harder if (!$component->__get("RRULE")) { $lastOccurence = self::getDtEndTimeStamp($component); } else { - $it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID")); + $it = new Sabre\VObject\RecurrenceIterator($vObject, (string)$component->__get("UID")); $maxDate = new DateTime(CALDAV_MAX_YEAR . "-01-01"); if ($it->isInfinite()) { $lastOccurence = $maxDate->getTimeStamp(); diff --git a/dav/common/wdcal_backend.inc.php b/dav/common/wdcal_backend.inc.php index 9233da6e2..330f29889 100644 --- a/dav/common/wdcal_backend.inc.php +++ b/dav/common/wdcal_backend.inc.php @@ -97,12 +97,12 @@ function wdcal_print_feed($base_path = "") $component = dav_get_eventComponent($item); $component->add("SUMMARY", icalendar_sanitize_string(dav_compat_parse_text_serverside("CalendarTitle"))); - if (isset($_REQUEST["allday"])) $type = Sabre_VObject_Property_DateTime::DATE; - else $type = Sabre_VObject_Property_DateTime::LOCALTZ; + if (isset($_REQUEST["allday"])) $type = Sabre\VObject\Property\DateTime::DATE; + else $type = Sabre\VObject\Property\DateTime::LOCALTZ; - $datetime_start = new Sabre_VObject_Property_DateTime("DTSTART"); + $datetime_start = new Sabre\VObject\Property\DateTime("DTSTART"); $datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarStartTime"]))), $type); - $datetime_end = new Sabre_VObject_Property_DateTime("DTEND"); + $datetime_end = new Sabre\VObject\Property\DateTime("DTEND"); $datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarEndTime"]))), $type); $component->add($datetime_start); @@ -179,12 +179,12 @@ function wdcal_print_feed($base_path = "") killme(); } - if (isset($_REQUEST["allday"])) $type = Sabre_VObject_Property_DateTime::DATE; - else $type = Sabre_VObject_Property_DateTime::LOCALTZ; + if (isset($_REQUEST["allday"])) $type = Sabre\VObject\Property\DateTime::DATE; + else $type = Sabre\VObject\Property\DateTime::LOCALTZ; - $datetime_start = new Sabre_VObject_Property_DateTime("DTSTART"); + $datetime_start = new Sabre\VObject\Property\DateTime("DTSTART"); $datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarStartTime"]))), $type); - $datetime_end = new Sabre_VObject_Property_DateTime("DTEND"); + $datetime_end = new Sabre\VObject\Property\DateTime("DTEND"); $datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarEndTime"]))), $type); $component->__unset("DTSTART"); diff --git a/dav/friendica/dav_caldav_backend_virtual_friendica.inc.php b/dav/friendica/dav_caldav_backend_virtual_friendica.inc.php index d2810b4f8..0afc03bd7 100644 --- a/dav/friendica/dav_caldav_backend_virtual_friendica.inc.php +++ b/dav/friendica/dav_caldav_backend_virtual_friendica.inc.php @@ -82,11 +82,11 @@ class Sabre_CalDAV_Backend_Friendica extends Sabre_CalDAV_Backend_Virtual $ts_end = wdcal_mySql2PhpTime($start); $allday = (strpos($start, "00:00:00") !== false && strpos($finish, "00:00:00") !== false); - $type = ($allday ? Sabre_VObject_Property_DateTime::DATE : Sabre_VObject_Property_DateTime::LOCALTZ); + $type = ($allday ? Sabre\VObject\Property\DateTime::DATE : Sabre\VObject\Property\DateTime::LOCALTZ); - $datetime_start = new Sabre_VObject_Property_DateTime("DTSTART"); + $datetime_start = new Sabre\VObject\Property\DateTime("DTSTART"); $datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_start)), $type); - $datetime_end = new Sabre_VObject_Property_DateTime("DTEND"); + $datetime_end = new Sabre\VObject\Property\DateTime("DTEND"); $datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_end)), $type); $component->add($datetime_start); diff --git a/dav/friendica/layout.fnk.php b/dav/friendica/layout.fnk.php index 5b65ec244..80a9ae2d0 100644 --- a/dav/friendica/layout.fnk.php +++ b/dav/friendica/layout.fnk.php @@ -86,12 +86,12 @@ function wdcal_import_user_ics($calendar_id) { if ($_FILES["ics_file"]["tmp_name"] != "" && is_uploaded_file($_FILES["ics_file"]["tmp_name"])) try { $text = file_get_contents($_FILES["ics_file"]["tmp_name"]); - /** @var Sabre_VObject_Component_VCalendar $vObject */ - $vObject = Sabre_VObject_Reader::read($text); + /** @var Sabre\VObject\Component\VCalendar $vObject */ + $vObject = Sabre\VObject\Reader::read($text); $comp = $vObject->getComponents(); $imported = array(); foreach ($comp as $c) try { - /** @var Sabre_VObject_Component_VEvent $c */ + /** @var Sabre\VObject\Component\VEvent $c */ $uid = $c->__get("UID")->value; if (!isset($imported[$uid])) $imported[$uid] = ""; $imported[$uid] .= $c->serialize(); diff --git a/dav/friendica/main.php b/dav/friendica/main.php index 602bda6d7..712b6c7b8 100644 --- a/dav/friendica/main.php +++ b/dav/friendica/main.php @@ -28,6 +28,27 @@ function dav_include_files() { require_once (__DIR__ . "/../SabreDAV/lib/Sabre/autoload.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Node.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Element.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/DateTimeParser.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/ElementList.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/FreeBusyGenerator.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Parameter.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/ParseException.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Property.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Reader.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/RecurrenceIterator.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/TimeZoneUtil.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Version.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Property/DateTime.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Property/MultiDateTime.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VAlarm.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VCalendar.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VEvent.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VJournal.php"); + require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VTodo.php"); + require_once (__DIR__ . "/../common/calendar.fnk.php"); require_once (__DIR__ . "/../common/calendar_rendering.fnk.php"); @@ -109,7 +130,7 @@ function dav_init(&$a) } - $server = dav_create_server(); + $server = dav_create_server(); $browser = new Sabre_DAV_Browser_Plugin(); $server->addPlugin($browser); @@ -293,8 +314,7 @@ function dav_plugin_admin_post(&$a = null, &$o = null) if (count($errs) == 0) { renderAllCalDavEntries(); info(t('The database tables have been updated.') . EOL); - } - else notice(t("An error occurred during the update.") . EOL); + } else notice(t("An error occurred during the update.") . EOL); } } diff --git a/dav/sabre-vobject/.travis.yml b/dav/sabre-vobject/.travis.yml new file mode 100644 index 000000000..aca128bc8 --- /dev/null +++ b/dav/sabre-vobject/.travis.yml @@ -0,0 +1,8 @@ +language: php +php: + - 5.3 + - 5.4 + +script: phpunit --configuration tests/phpunit.xml + +before_script: composer install diff --git a/dav/sabre-vobject/ChangeLog b/dav/sabre-vobject/ChangeLog new file mode 100644 index 000000000..0f26abbbc --- /dev/null +++ b/dav/sabre-vobject/ChangeLog @@ -0,0 +1,7 @@ +2.0.0-stable (2012-08-08) + * VObject is now a separate project from SabreDAV. See the SabreDAV + changelog for version information before 2.0. + * New: VObject library now uses PHP 5.3 namespaces. + * New: It's possible to specify lists of parameters when constructing + properties. + * New: made it easier to construct the FreeBusyGenerator. diff --git a/dav/sabre-vobject/LICENSE b/dav/sabre-vobject/LICENSE new file mode 100644 index 000000000..8e09aec68 --- /dev/null +++ b/dav/sabre-vobject/LICENSE @@ -0,0 +1,27 @@ +Copyright (C) 2007-2012 Rooftop Solutions. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the Sabre nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. diff --git a/dav/sabre-vobject/README.md b/dav/sabre-vobject/README.md new file mode 100644 index 000000000..13107039f --- /dev/null +++ b/dav/sabre-vobject/README.md @@ -0,0 +1,388 @@ +# SabreTooth VObject library + +[![Build Status](https://secure.travis-ci.org/evert/sabre-vobject.png?branch=master)](http://travis-ci.org/evert/sabre-vobject) + +The VObject library allows you to easily parse and manipulate [iCalendar](https://tools.ietf.org/html/rfc5545) +and [vCard](https://tools.ietf.org/html/rfc6350) objects using PHP. +The goal of the VObject library is to create a very complete library, with an easy to use API. + +This project is a spin-off from [SabreDAV](http://code.google.com/p/sabredav/), where it has +been used for several years. The VObject library has 100% unittest coverage. + +# Installation + +VObject requires PHP 5.3, and should be installed using composer. +The general composer instructions can be found on the [composer website](http://getcomposer.org/doc/00-intro.md composer website). + +After that, just declare the vobject dependency as follows: + +``` +"require" : { + "sabre/vobject" : "dev-master" +} +``` + +Then, run `composer.phar update` and you should be good. As soon as the first release is out, you should switch `dev-master` to `2.0.*` though. + +# Usage + +## Parsing + +For our example, we will be using the following vcard: + +``` +BEGIN:VCARD +VERSION:3.0 +PRODID:-//Sabre//Sabre VObject 2.0//EN +N:Planck;Max;;; +FN:Max Planck +EMAIL;TYPE=WORK:mplanck@example.org +item1.TEL;TYPE=CELL:(+49)3144435678 +item1.X-ABLabel:Private cell +item2.TEL;TYPE=WORK:(+49)5554564744 +item2.X-ABLabel:Work +END:VCARD +``` + + +If we want to just print out Max' full name, you can just use property access: + + +```php + +use Sabre\VObject; + +$card = VObject\Reader::read($data); +echo $card->FN; + +``` + +## Changing properties + +Creating properties is pretty similar. If we like to add his birthday, we just +set the property: + +```php + +$card->BDAY = '1858-04-23'; + +``` + +Note that in the previous example, we're actually updating any existing BDAY that +may already exist. If we want to add a new property, without overwriting the previous +we can do this with the `add` method. + +```php + +$card->add('EMAIL','max@example.org'); + +``` + +## Parameters + +If we want to also specify that this is max' home email addresses, we can do this with +a third parameter: + +``` + +$card->add('EMAIL', 'max@example'org', array('type' => 'HOME')); + +``` + +If we want to read out all the email addresses and their type, this would look something +like this: + +``` +foreach($card->EMAIL as $email) { + + echo $email['TYPE'], ' - ', $email; + +} +``` + +## Groups + +In our example, you can see that the TEL properties are prefixed. These are 'groups' and +allow you to group multiple related properties together. The group can be any user-defined +name. + +This particular example as generated by the OS X addressbook, which uses the `X-ABLabel` +to allow the user to specify custom labels for properties. OS X addressbook uses groups +to tie the label to the property. + +The VObject library simply ignores the group if you don't specify it, so this will work: + +```php + +foreach($card->TEL as $tel) { + echo $tel, "\n"; +} +``` + +But if you would like to target a specific group + property, this is possible too: + +```php + +echo $card->{'ITEM1.TEL'}; + +``` + +So if you would like to show all the phone numbers, along with their custom label, the +following syntax is used: + +``` +foreach($card->TEL as $tel) { + + echo $card->{$tel->group . '.X-ABLABEL'}, ": "; + echo $tel, "\n"; + +} +``` + +## Serializing / Saving + +If you want to generate your updated VObject, you can simply call the serialize() method. + +``` + +echo $card->serialize(); + +``` + +## Components + +iCalendar, unlike vCards always have sub-components. Where vCards are often just a flat +list, iCalendar objects tend to have a tree-like structure. For the following paragraphs, +we will use the following object as the example: + +``` +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//Sabre//Sabre VObject 2.0//EN +BEGIN:VEVENT +SUMMARY:Curiosity landing +DTSTART:20120806T051439Z +LOCATION:Mars +END:VEVENT +END:VCALENDAR +``` + +Since events, tasks and journals are always in a sub component, this is also how we +access them. + +```php + +use Sabre\VObject; + +$calendar = VObject\Reader::read($data); +echo $calendar->VEVENT->SUMMARY; + +``` + +Adding components to a calendar is done with a factory method: + +```php + +$event = VObject\Component::create('VEVENT'); +$calendar->add($event); + +$event->SUMMARY = 'Curiosity launch'; +$event->DTSTART = '20111126T150202Z'; +$event->LOCATION = 'Cape Carnival'; + +``` + +By the way.. cloning also works as expected, as the entire structure is cloned along with it: + +```php + +$clonedEvent = clone $calendar->VEVENT[0]; +$calendar->add($clonedEvent); + +``` + +## Date and time handling + +If you ever had to deal with iCalendar timezones, you know it can be complicated. +The way timezones are specified is flawed, which is something I may write an essay about some +day. VObject does its best to determine the correct timezone. Many standard formats +have been tested and verified, and special code has been implemented for special-casing +microsoft generated timezone information, and others. + +To get a real php `DateTime` object, you can request this as follows: + +``` +$event = $calendar->VEVENT; +$start = $event->DTSTART->getDateTime(); +echo $start->format(\DateTime::W3C); +``` + +To set the property with a DateTime object, you can use the following syntax: + +``` +$dateTime = new \DateTime('2012-08-07 23:53:00', new DateTimeZone('Europe/Amsterdam')); +$event->DTSTART->setDateTime($dateTime, VObject\Property\DateTime::DATE); +``` + +The second argument specifies the type of date you're setting. The following three +options exist: + +1. `LOCAL` This is a floating time, with no timezone information. This basically specifies that the event happens in whatever the timezone's currently in. This would be encoded as `DTSTART;VALUE=DATE-TIME:20120807235300` +2. `UTC` This specifies that the time should be encoded as a UTC time. This is encoded as `DTSTART;VALUE=DATE-TIME:20120807205300Z`. Note the extra Z and the fact that it's two hours 'earlier'. +3. `LOCALTZ` specifies that it's supposed to be encoded in its local timezone. For example `DTSTART;VALUE=DATE-TIME;TZID=Europe/Amsterdam:20120807235300`. +4. `DATE` This is a date-only, and does not contain the time. In this case this would be encoded as `DTSTART;VALUE=DATE:20120807`. + +A few important notes: + +* When a `TZID` is specified, there should also be a matching `VTIMEZONE` object with all the timezone information. VObject cannot currently automatically embed this. However, in reality other clients seem to do fine without this information. Yet, for completeness, this will be added in the future. +* As mentioned, the timezone-determination process may sometimes fail. Report any issues you find, and I'll be quick to add workarounds! + +## Recurrence rules + +Recurrence rules allow events to recur, for example for a weekly meeting, or an anniversary. +This is done with the `RRULE` property. The `RRULE` property allows for a LOT of different +rules. VObject only implements the ones that actually appear in calendar software. + +To read more about `RRULE` and all the options, check out [RFC5545](https://tools.ietf.org/html/rfc5545#section-3.8.5). +VObject supports the following options: + +1. `UNTIL` for an end date. +2. `INTERVAL` for for example "every 2 days". +3. `COUNT` to stop recurring after x items. +4. `FREQ=DAILY` to recur every day, and `BYDAY` to limit it to certain days. +5. `FREQ=WEEKLY` to recur every week, `BYDAY` to expand this to multiple weekdays in every week and `WKST` to specify on which day the week starts. +6. `FREQ=MONTHLY` to recur every month, `BYMONTHDAY` to expand this to certain days in a month, `BYDAY` to expand it to certain weekdays occuring in a month, and `BYSETPOS` to limit the last two expansions. +7. `FREQ=YEARLY` to recur every year, `BYMONTH` to expand that to certain months in a year, and `BYDAY` and `BYWEEKDAY` to expand the `BYMONTH` rule even further. + +VObject supports the `EXDATE` property for exclusions, but not yet the `RDATE` and `EXRULE` +properties. If you're interested in this, please file a github issue, as this will put it +on my radar. + +This is a bit of a complex subject to go in excruciating detail. The +[RFC](https://tools.ietf.org/html/rfc5545#section-3.8.5) has a lot of examples though. + +The hard part is not to write the RRULE, it is to expand them. The most complex and +hard-to-read code is hidden in this component. Dragons be here. + +So, if we have a meeting every 2nd monday of the month, this would be specified as such: + +``` +BEGIN:VCALENDAR + VERSION:2.0 + BEGIN:VEVENT + UID:1102c450-e0d7-11e1-9b23-0800200c9a66 + DTSTART:20120109T140000Z + RRULE:FREQ=MONTHLY;BYDAY=MO;BYSETPOS=2 + END:VEVENT +END:VCALENDAR +``` + +Note that normally it's not allowed to indent the object like this, but it does make +it easier to read. This is also the first time I added in a UID, which is required +for all VEVENT, VTODO and VJOURNAL objects! + +To figure out all the meetings for this year, we can use the following syntax: + +```php +use Sabre\VObject; + +$calendar = VObject\Reader::read($data); +$calendar->expand(new DateTime('2012-01-01'), new DateTime('2012-12-31')); +``` + +What the expand method does, is look at its inner events, and expand the recurring +rule. Our calendar now contains 12 events. The first will have its RRULE stripped, +and every subsequent VEVENT has the correct meeting date and a `RECURRENCE-ID` set. + +This results in something like this: + +``` +BEGIN:VCALENDAR + VERSION:2.0 + BEGIN:VEVENT + UID:1102c450-e0d7-11e1-9b23-0800200c9a66 + DTSTART:20120109T140000Z + END:VEVENT + BEGIN:VEVENT + UID:1102c450-e0d7-11e1-9b23-0800200c9a66 + RECURRENCE-ID:20120213T140000Z + DTSTART:20120213T140000Z + END:VEVENT + BEGIN:VEVENT + UID:1102c450-e0d7-11e1-9b23-0800200c9a66 + RECURRENCE-ID:20120312T140000Z + DTSTART:20120312T140000Z + END:VEVENT + ..etc.. +END:VCALENDAR +``` + +To show the list of dates, we would do this as such: + +``` +foreach($calendar->VEVENT as $event) { + echo $event->DTSTART->getDateTime()->format(\DateTime::ATOM); +} +``` + +In a recurring event, single instances can also be overriden. VObject also takes these +into consideration. The reason we needed to specify a start and end-date, is because +some recurrence rules can be 'never ending'. + +You should make sure you pick a sane date-range. Because if you pick a 50 year +time-range, for a daily recurring event; this would result in over 18K objects. + +# Free-busy report generation + +Some calendaring software can make use of FREEBUSY reports to show when people are +available. + +You can automatically generate these reports from calendars using the `FreeBusyGenerator`. + +Example based on our last event: + +``` + +// We're giving it the calendar object. It's also possible to specify multiple objects, +// by setting them as an array. +// +// We must also specify a start and end date, because recurring events are expanded. +$fbGenerator = new VObject\FreeBusyGenerator( + new DateTime('2012-01-01'), + new DateTime('2012-12-31'), + $calendar +); + +// Grabbing the report +$freebusy = $fbGenerator->result(); + +// The freebusy report is another VCALENDAR object, so we can serialize it as usual: +echo $freebusy->serialize(); +``` + +The output of this script will look like this: + +``` +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//Sabre//Sabre VObject 2.0//EN +CALSCALE:GREGORIAN +BEGIN:VFREEBUSY +DTSTART;VALUE=DATE-TIME:20111231T230000Z +DTEND;VALUE=DATE-TIME:20111231T230000Z +DTSTAMP;VALUE=DATE-TIME:20120808T131628Z +FREEBUSY;FBTYPE=BUSY:20120109T140000Z/20120109T140000Z +FREEBUSY;FBTYPE=BUSY:20120213T140000Z/20120213T140000Z +FREEBUSY;FBTYPE=BUSY:20120312T140000Z/20120312T140000Z +FREEBUSY;FBTYPE=BUSY:20120409T140000Z/20120409T140000Z +FREEBUSY;FBTYPE=BUSY:20120514T140000Z/20120514T140000Z +FREEBUSY;FBTYPE=BUSY:20120611T140000Z/20120611T140000Z +FREEBUSY;FBTYPE=BUSY:20120709T140000Z/20120709T140000Z +FREEBUSY;FBTYPE=BUSY:20120813T140000Z/20120813T140000Z +FREEBUSY;FBTYPE=BUSY:20120910T140000Z/20120910T140000Z +FREEBUSY;FBTYPE=BUSY:20121008T140000Z/20121008T140000Z +FREEBUSY;FBTYPE=BUSY:20121112T140000Z/20121112T140000Z +FREEBUSY;FBTYPE=BUSY:20121210T140000Z/20121210T140000Z +END:VFREEBUSY +END:VCALENDAR +``` diff --git a/dav/sabre-vobject/composer.json b/dav/sabre-vobject/composer.json new file mode 100644 index 000000000..9ecdf4558 --- /dev/null +++ b/dav/sabre-vobject/composer.json @@ -0,0 +1,27 @@ +{ + "name": "sabre/vobject", + "description" : "The VObject library for PHP allows you to easily parse and manipulate iCalendar and vCard objects", + "keywords" : [ "VObject", "iCalendar", "vCard" ], + "homepage" : "https://github.com/evert/sabre-vobject", + "license" : "BSD-3-Clause", + "require" : { + "php" : ">=5.3.1" + }, + "authors" : [ + { + "name" : "Evert Pot", + "email" : "evert@rooftopsolutions.nl", + "homepage" : "http://www.rooftopsolutions.nl/", + "role" : "Developer" + } + ], + "support" : { + "forum" : "https://groups.google.com/group/sabredav-discuss", + "source" : "https://github.com/evert/sabre-vobject" + }, + "autoload" : { + "psr-0" : { + "Sabre\\VObject" : "lib/" + } + } +} diff --git a/dav/SabreDAV/lib/Sabre/VObject/Component.php b/dav/sabre-vobject/lib/Sabre/VObject/Component.php similarity index 79% rename from dav/SabreDAV/lib/Sabre/VObject/Component.php rename to dav/sabre-vobject/lib/Sabre/VObject/Component.php index ced593848..d17cb895e 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Component.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Component.php @@ -1,5 +1,7 @@ 'Sabre_VObject_Component_VCalendar', - 'VEVENT' => 'Sabre_VObject_Component_VEvent', - 'VTODO' => 'Sabre_VObject_Component_VTodo', - 'VJOURNAL' => 'Sabre_VObject_Component_VJournal', - 'VALARM' => 'Sabre_VObject_Component_VAlarm', + 'VALARM' => 'Sabre\\VObject\\Component\\VAlarm', + 'VCALENDAR' => 'Sabre\\VObject\\Component\\VCalendar', + 'VCARD' => 'Sabre\\VObject\\Component\\VCard', + 'VEVENT' => 'Sabre\\VObject\\Component\\VEvent', + 'VJOURNAL' => 'Sabre\\VObject\\Component\\VJournal', + 'VTODO' => 'Sabre\\VObject\\Component\\VTodo', ); /** @@ -50,7 +56,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { * * @param string $name * @param string $value - * @return Sabre_VObject_Component + * @return Component */ static public function create($name, $value = null) { @@ -71,9 +77,9 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { * be overridden with the iterator argument * * @param string $name - * @param Sabre_VObject_ElementList $iterator + * @param ElementList $iterator */ - public function __construct($name, Sabre_VObject_ElementList $iterator = null) { + public function __construct($name, ElementList $iterator = null) { $this->name = strtoupper($name); if (!is_null($iterator)) $this->iterator = $iterator; @@ -100,12 +106,13 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { * preserve the original relative order of elements. * * @param int $key - * @param Sabre_VObject $array + * @param array $array * @return int */ $sortScore = function($key, $array) { - if ($array[$key] instanceof Sabre_VObject_Component) { + if ($array[$key] instanceof Component) { + // We want to encode VTIMEZONE first, this is a personal // preference. if ($array[$key]->name === 'VTIMEZONE') { @@ -118,7 +125,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { } else { // Properties get encoded first // VCARD version 4.0 wants the VERSION property to appear first - if ($array[$key] instanceof Sabre_VObject_Property) { + if ($array[$key] instanceof Property) { if ($array[$key]->name === 'VERSION') { $score=100000000; return $score+$key; @@ -129,7 +136,6 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { } } } - next($children); }; @@ -157,8 +163,8 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { * * You can call this method with the following syntaxes: * - * add(Sabre_VObject_Element $element) - * add(string $name, $value) + * add(Element $element) + * add(string $name, $value, array $parameters = array()) * * The first version adds an Element * The second adds a property as a string. @@ -167,26 +173,26 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { * @param mixed $itemValue * @return void */ - public function add($item, $itemValue = null) { + public function add($item, $itemValue = null, array $parameters = array()) { - if ($item instanceof Sabre_VObject_Element) { + if ($item instanceof Element) { if (!is_null($itemValue)) { - throw new InvalidArgumentException('The second argument must not be specified, when passing a VObject'); + throw new \InvalidArgumentException('The second argument must not be specified, when passing a VObject'); } $item->parent = $this; $this->children[] = $item; } elseif(is_string($item)) { if (!is_scalar($itemValue)) { - throw new InvalidArgumentException('The second argument must be scalar'); + throw new \InvalidArgumentException('The second argument must be scalar'); } - $item = Sabre_VObject_Property::create($item,$itemValue); + $item = Property::create($item,$itemValue, $parameters); $item->parent = $this; $this->children[] = $item; } else { - throw new InvalidArgumentException('The first argument must either be a Sabre_VObject_Element or a string'); + throw new \InvalidArgumentException('The first argument must either be a \\Sabre\\VObject\\Element or a string'); } @@ -195,11 +201,11 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { /** * Returns an iterable list of children * - * @return Sabre_VObject_ElementList + * @return ElementList */ public function children() { - return new Sabre_VObject_ElementList($this->children); + return new ElementList($this->children); } @@ -232,7 +238,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { if ( strtoupper($child->name) === $name && - (is_null($group) || ( $child instanceof Sabre_VObject_Property && strtoupper($child->group) === $group)) + (is_null($group) || ( $child instanceof Property && strtoupper($child->group) === $group)) ) { $result[$key] = $child; @@ -255,7 +261,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { $result = array(); foreach($this->children as $child) { - if ($child instanceof Sabre_VObject_Component) { + if ($child instanceof Component) { $result[] = $child; } } @@ -266,6 +272,11 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { /** * Validates the node for correctness. + * + * The following options are supported: + * - Component::REPAIR - If something is broken, and automatic repair may + * be attempted. + * * An array is returned with warnings. * * Every item in the array has the following properties: @@ -273,9 +284,10 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { * * message - (human readable message) * * node - (reference to the offending node) * + * @param int $options * @return array */ - public function validate() { + public function validate($options = 0) { $result = array(); foreach($this->children as $child) { @@ -294,7 +306,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { * null is returned. * * @param string $name - * @return Sabre_VObject_Property + * @return Property */ public function __get($name) { @@ -303,8 +315,8 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { return null; } else { $firstMatch = current($matches); - /** @var $firstMatch Sabre_VObject_Property */ - $firstMatch->setIterator(new Sabre_VObject_ElementList(array_values($matches))); + /** @var $firstMatch Property */ + $firstMatch->setIterator(new ElementList(array_values($matches))); return $firstMatch; } @@ -326,7 +338,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { /** * Using the setter method you can add properties or subcomponents * - * You can either pass a Sabre_VObject_Component, Sabre_VObject_Property + * You can either pass a Component, Property * object, or a string to automatically create a Property. * * If the item already exists, it will be removed. If you want to add @@ -341,7 +353,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { $matches = $this->select($name); $overWrite = count($matches)?key($matches):null; - if ($value instanceof Sabre_VObject_Component || $value instanceof Sabre_VObject_Property) { + if ($value instanceof Component || $value instanceof Property) { $value->parent = $this; if (!is_null($overWrite)) { $this->children[$overWrite] = $value; @@ -349,7 +361,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { $this->children[] = $value; } } elseif (is_scalar($value)) { - $property = Sabre_VObject_Property::create($name,$value); + $property = Property::create($name,$value); $property->parent = $this; if (!is_null($overWrite)) { $this->children[$overWrite] = $property; @@ -357,7 +369,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element { $this->children[] = $property; } } else { - throw new InvalidArgumentException('You must pass a Sabre_VObject_Component, Sabre_VObject_Property or scalar type'); + throw new \InvalidArgumentException('You must pass a \\Sabre\\VObject\\Component, \\Sabre\\VObject\\Property or scalar type'); } } diff --git a/dav/SabreDAV/lib/Sabre/VObject/Component/VAlarm.php b/dav/sabre-vobject/lib/Sabre/VObject/Component/VAlarm.php similarity index 79% rename from dav/SabreDAV/lib/Sabre/VObject/Component/VAlarm.php rename to dav/sabre-vobject/lib/Sabre/VObject/Component/VAlarm.php index 1d1dd69d5..6bf7f5a2e 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Component/VAlarm.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Component/VAlarm.php @@ -1,17 +1,18 @@ TRIGGER; if(!isset($trigger['VALUE']) || strtoupper($trigger['VALUE']) === 'DURATION') { - $triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($this->TRIGGER); + $triggerDuration = VObject\DateTimeParser::parseDuration($this->TRIGGER); $related = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'END' : 'START'; $parentComponent = $this->parent; @@ -37,7 +38,7 @@ class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component { } elseif ($parentComponent->name === 'VEVENT') { $endProp = 'DTEND'; } else { - throw new Sabre_DAV_Exception('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT'); + throw new \LogicException('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT'); } if (isset($parentComponent->$endProp)) { @@ -45,7 +46,7 @@ class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component { $effectiveTrigger->add($triggerDuration); } elseif (isset($parentComponent->DURATION)) { $effectiveTrigger = clone $parentComponent->DTSTART->getDateTime(); - $duration = Sabre_VObject_DateTimeParser::parseDuration($parentComponent->DURATION); + $duration = VObject\DateTimeParser::parseDuration($parentComponent->DURATION); $effectiveTrigger->add($duration); $effectiveTrigger->add($triggerDuration); } else { @@ -67,22 +68,22 @@ class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component { * The rules used to determine if an event falls within the specified * time-range is based on the CalDAV specification. * - * @param DateTime $start - * @param DateTime $end + * @param \DateTime $start + * @param \DateTime $end * @return bool */ - public function isInTimeRange(DateTime $start, DateTime $end) { + public function isInTimeRange(\DateTime $start, \DateTime $end) { $effectiveTrigger = $this->getEffectiveTriggerTime(); if (isset($this->DURATION)) { - $duration = Sabre_VObject_DateTimeParser::parseDuration($this->DURATION); + $duration = VObject\DateTimeParser::parseDuration($this->DURATION); $repeat = (string)$this->repeat; if (!$repeat) { $repeat = 1; } - $period = new DatePeriod($effectiveTrigger, $duration, (int)$repeat); + $period = new \DatePeriod($effectiveTrigger, $duration, (int)$repeat); foreach($period as $occurrence) { diff --git a/dav/SabreDAV/lib/Sabre/VObject/Component/VCalendar.php b/dav/sabre-vobject/lib/Sabre/VObject/Component/VCalendar.php similarity index 90% rename from dav/SabreDAV/lib/Sabre/VObject/Component/VCalendar.php rename to dav/sabre-vobject/lib/Sabre/VObject/Component/VCalendar.php index 35dd90f23..73f2f6d34 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Component/VCalendar.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Component/VCalendar.php @@ -1,17 +1,19 @@ children as $component) { - if (!$component instanceof Sabre_VObject_Component) + if (!$component instanceof VObject\Component) continue; if (isset($component->{'RECURRENCE-ID'})) @@ -69,7 +71,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component { * @param DateTime $end * @return void */ - public function expand(DateTime $start, DateTime $end) { + public function expand(\DateTime $start, \DateTime $end) { $newEvents = array(); @@ -91,10 +93,10 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component { $uid = (string)$vevent->uid; if (!$uid) { - throw new LogicException('Event did not have a UID!'); + throw new \LogicException('Event did not have a UID!'); } - $it = new Sabre_VObject_RecurrenceIterator($this, $vevent->uid); + $it = new VObject\RecurrenceIterator($this, $vevent->uid); $it->fastForward($start); while($it->valid() && $it->getDTStart() < $end) { @@ -114,9 +116,9 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component { foreach($newEvents as $newEvent) { foreach($newEvent->children as $child) { - if ($child instanceof Sabre_VObject_Property_DateTime && - $child->getDateType() == Sabre_VObject_Property_DateTime::LOCALTZ) { - $child->setDateTime($child->getDateTime(),Sabre_VObject_Property_DateTime::UTC); + if ($child instanceof VObject\Property\DateTime && + $child->getDateType() == VObject\Property\DateTime::LOCALTZ) { + $child->setDateTime($child->getDateTime(),VObject\Property\DateTime::UTC); } } @@ -140,6 +142,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component { * * @return array */ + /* public function validate() { $warnings = array(); @@ -198,7 +201,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component { ); $componentsFound = 0; foreach($this->children as $child) { - if($child instanceof Sabre_VObject_Component) { + if($child instanceof Component) { $componentsFound++; if (!in_array($child->name, $allowedComponents)) { $warnings[] = array( @@ -208,7 +211,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component { ); } } - if ($child instanceof Sabre_VObject_Property) { + if ($child instanceof Property) { if (!in_array($child->name, $allowedProperties)) { $warnings[] = array( 'level' => 2, @@ -233,6 +236,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component { ); } + */ } diff --git a/dav/sabre-vobject/lib/Sabre/VObject/Component/VCard.php b/dav/sabre-vobject/lib/Sabre/VObject/Component/VCard.php new file mode 100644 index 000000000..002c4db2b --- /dev/null +++ b/dav/sabre-vobject/lib/Sabre/VObject/Component/VCard.php @@ -0,0 +1,105 @@ +select('VERSION'); + if (count($version)!==1) { + $warnings[] = array( + 'level' => 1, + 'message' => 'The VERSION property must appear in the VCARD component exactly 1 time', + 'node' => $this, + ); + if ($options & self::REPAIR) { + $this->VERSION = self::DEFAULT_VERSION; + } + } else { + $version = (string)$this->VERSION; + if ($version!=='2.1' && $version!=='3.0' && $version!=='4.0') { + $warnings[] = array( + 'level' => 1, + 'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.', + 'node' => $this, + ); + if ($options & self::REPAIR) { + $this->VERSION = '4.0'; + } + } + + } + $version = $this->select('FN'); + if (count($version)!==1) { + $warnings[] = array( + 'level' => 1, + 'message' => 'The FN property must appear in the VCARD component exactly 1 time', + 'node' => $this, + ); + if (($options & self::REPAIR) && count($version) === 0) { + // We're going to try to see if we can use the contents of the + // N property. + if (isset($this->N)) { + $value = explode(';', (string)$this->N); + if (isset($value[1]) && $value[1]) { + $this->FN = $value[1] . ' ' . $value[0]; + } else { + $this->FN = $value[0]; + } + + // Otherwise, the ORG property may work + } elseif (isset($this->ORG)) { + $this->FN = (string)$this->ORG; + } + + } + } + + return array_merge( + parent::validate($options), + $warnings + ); + + } + +} + diff --git a/dav/SabreDAV/lib/Sabre/VObject/Component/VEvent.php b/dav/sabre-vobject/lib/Sabre/VObject/Component/VEvent.php similarity index 64% rename from dav/SabreDAV/lib/Sabre/VObject/Component/VEvent.php rename to dav/sabre-vobject/lib/Sabre/VObject/Component/VEvent.php index 684f5f5a7..9d10966e2 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Component/VEvent.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Component/VEvent.php @@ -1,17 +1,18 @@ RRULE) { - $it = new Sabre_VObject_RecurrenceIterator($this); + $it = new VObject\RecurrenceIterator($this); $it->fastForward($start); // We fast-forwarded to a spot where the end-time of the @@ -42,18 +43,19 @@ class Sabre_VObject_Component_VEvent extends Sabre_VObject_Component { $effectiveStart = $this->DTSTART->getDateTime(); if (isset($this->DTEND)) { + + // The DTEND property is considered non inclusive. So for a 3 day + // event in july, dtstart and dtend would have to be July 1st and + // July 4th respectively. + // + // See: + // http://tools.ietf.org/html/rfc5545#page-54 $effectiveEnd = $this->DTEND->getDateTime(); - // If this was an all-day event, we should just increase the - // end-date by 1. Otherwise the event will last until the second - // the date changed, by increasing this by 1 day the event lasts - // all of the last day as well. - if ($this->DTSTART->getDateType() == Sabre_VObject_Property_DateTime::DATE) { - $effectiveEnd->modify('+1 day'); - } + } elseif (isset($this->DURATION)) { $effectiveEnd = clone $effectiveStart; - $effectiveEnd->add( Sabre_VObject_DateTimeParser::parseDuration($this->DURATION) ); - } elseif ($this->DTSTART->getDateType() == Sabre_VObject_Property_DateTime::DATE) { + $effectiveEnd->add( VObject\DateTimeParser::parseDuration($this->DURATION) ); + } elseif ($this->DTSTART->getDateType() == VObject\Property\DateTime::DATE) { $effectiveEnd = clone $effectiveStart; $effectiveEnd->modify('+1 day'); } else { diff --git a/dav/SabreDAV/lib/Sabre/VObject/Component/VJournal.php b/dav/sabre-vobject/lib/Sabre/VObject/Component/VJournal.php similarity index 79% rename from dav/SabreDAV/lib/Sabre/VObject/Component/VJournal.php rename to dav/sabre-vobject/lib/Sabre/VObject/Component/VJournal.php index 6d3949289..f104a1f66 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Component/VJournal.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Component/VJournal.php @@ -1,17 +1,19 @@ DTSTART)?$this->DTSTART->getDateTime():null; if ($dtstart) { $effectiveEnd = clone $dtstart; - if ($this->DTSTART->getDateType() == Sabre_VObject_Property_DateTime::DATE) { + if ($this->DTSTART->getDateType() == VObject\Property\DateTime::DATE) { $effectiveEnd->modify('+1 day'); } diff --git a/dav/SabreDAV/lib/Sabre/VObject/Component/VTodo.php b/dav/sabre-vobject/lib/Sabre/VObject/Component/VTodo.php similarity index 87% rename from dav/SabreDAV/lib/Sabre/VObject/Component/VTodo.php rename to dav/sabre-vobject/lib/Sabre/VObject/Component/VTodo.php index 2fb6654ed..5f879aea4 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Component/VTodo.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Component/VTodo.php @@ -1,17 +1,19 @@ DTSTART)?$this->DTSTART->getDateTime():null; - $duration = isset($this->DURATION)?Sabre_VObject_DateTimeParser::parseDuration($this->DURATION):null; + $duration = isset($this->DURATION)?VObject\DateTimeParser::parseDuration($this->DURATION):null; $due = isset($this->DUE)?$this->DUE->getDateTime():null; $completed = isset($this->COMPLETED)?$this->COMPLETED->getDateTime():null; $created = isset($this->CREATED)?$this->CREATED->getDateTime():null; diff --git a/dav/SabreDAV/lib/Sabre/VObject/DateTimeParser.php b/dav/sabre-vobject/lib/Sabre/VObject/DateTimeParser.php similarity index 83% rename from dav/SabreDAV/lib/Sabre/VObject/DateTimeParser.php rename to dav/sabre-vobject/lib/Sabre/VObject/DateTimeParser.php index 23a4bb699..0ef8460dd 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/DateTimeParser.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/DateTimeParser.php @@ -1,18 +1,18 @@ setTimeZone(new DateTimeZone('UTC')); + $date->setTimeZone(new \DateTimeZone('UTC')); return $date; } @@ -57,10 +57,10 @@ class Sabre_VObject_DateTimeParser { $result = preg_match('/^([1-3][0-9]{3})([0-1][0-9])([0-3][0-9])$/',$date,$matches); if (!$result) { - throw new Sabre_DAV_Exception_BadRequest('The supplied iCalendar date value is incorrect: ' . $date); + throw new \LogicException('The supplied iCalendar date value is incorrect: ' . $date); } - $date = new DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3], new DateTimeZone('UTC')); + $date = new \DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3], new \DateTimeZone('UTC')); return $date; } @@ -79,7 +79,7 @@ class Sabre_VObject_DateTimeParser { $result = preg_match('/^(?P\+|-)?P((?P\d+)W)?((?P\d+)D)?(T((?P\d+)H)?((?P\d+)M)?((?P\d+)S)?)?$/', $duration, $matches); if (!$result) { - throw new Sabre_DAV_Exception_BadRequest('The supplied iCalendar duration value is incorrect: ' . $duration); + throw new \LogicException('The supplied iCalendar duration value is incorrect: ' . $duration); } if (!$asString) { @@ -128,7 +128,7 @@ class Sabre_VObject_DateTimeParser { if ($duration==='P') { $duration = 'PT0S'; } - $iv = new DateInterval($duration); + $iv = new \DateInterval($duration); if ($invert) $iv->invert = true; return $iv; diff --git a/dav/SabreDAV/lib/Sabre/VObject/Element.php b/dav/sabre-vobject/lib/Sabre/VObject/Element.php similarity index 73% rename from dav/SabreDAV/lib/Sabre/VObject/Element.php rename to dav/sabre-vobject/lib/Sabre/VObject/Element.php index e20ff0b35..151ae76ad 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Element.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Element.php @@ -1,15 +1,15 @@ vevent where there's multiple VEVENT objects. * - * @package Sabre - * @subpackage VObject * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. * @author Evert Pot (http://www.rooftopsolutions.nl/) * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License */ -class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess { +class ElementList implements \Iterator, \Countable, \ArrayAccess { /** * Inner elements @@ -44,7 +44,7 @@ class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess { /** * Returns current item in iteration * - * @return Sabre_VObject_Element + * @return Element */ public function current() { @@ -149,7 +149,7 @@ class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess { */ public function offsetSet($offset,$value) { - throw new LogicException('You can not add new objects to an ElementList'); + throw new \LogicException('You can not add new objects to an ElementList'); } @@ -163,7 +163,7 @@ class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess { */ public function offsetUnset($offset) { - throw new LogicException('You can not remove objects from an ElementList'); + throw new \LogicException('You can not remove objects from an ElementList'); } diff --git a/dav/SabreDAV/lib/Sabre/VObject/FreeBusyGenerator.php b/dav/sabre-vobject/lib/Sabre/VObject/FreeBusyGenerator.php similarity index 74% rename from dav/SabreDAV/lib/Sabre/VObject/FreeBusyGenerator.php rename to dav/sabre-vobject/lib/Sabre/VObject/FreeBusyGenerator.php index 1c96a64a0..bfb89b018 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/FreeBusyGenerator.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/FreeBusyGenerator.php @@ -1,5 +1,7 @@ setTimeRange($start, $end); + } + + if ($objects) { + $this->setObjects($objects); + } + + } + /** * Sets the VCALENDAR object. * @@ -54,10 +77,10 @@ class Sabre_VObject_FreeBusyGenerator { * * The VFREEBUSY object will be automatically added though. * - * @param Sabre_VObject_Component $vcalendar + * @param Component $vcalendar * @return void */ - public function setBaseObject(Sabre_VObject_Component $vcalendar) { + public function setBaseObject(Component $vcalendar) { $this->baseObject = $vcalendar; @@ -66,22 +89,28 @@ class Sabre_VObject_FreeBusyGenerator { /** * Sets the input objects * - * Every object must either be a string or a Sabre_VObject_Component. + * You must either specify a valendar object as a strong, or as the parse + * Component. + * It's also possible to specify multiple objects as an array. * - * @param array $objects + * @param mixed $objects * @return void */ - public function setObjects(array $objects) { + public function setObjects($objects) { + + if (!is_array($objects)) { + $objects = array($objects); + } $this->objects = array(); foreach($objects as $object) { if (is_string($object)) { - $this->objects[] = Sabre_VObject_Reader::read($object); - } elseif ($object instanceof Sabre_VObject_Component) { + $this->objects[] = Reader::read($object); + } elseif ($object instanceof Component) { $this->objects[] = $object; } else { - throw new InvalidArgumentException('You can only pass strings or Sabre_VObject_Component arguments to setObjects'); + throw new \InvalidArgumentException('You can only pass strings or \\Sabre\\VObject\\Component arguments to setObjects'); } } @@ -97,7 +126,7 @@ class Sabre_VObject_FreeBusyGenerator { * @param DateTime $end * @return void */ - public function setTimeRange(DateTime $start = null, DateTime $end = null) { + public function setTimeRange(\DateTime $start = null, \DateTime $end = null) { $this->start = $start; $this->end = $end; @@ -108,7 +137,7 @@ class Sabre_VObject_FreeBusyGenerator { * Parses the input data and returns a correct VFREEBUSY object, wrapped in * a VCALENDAR. * - * @return Sabre_VObject_Component + * @return Component */ public function getResult() { @@ -140,7 +169,7 @@ class Sabre_VObject_FreeBusyGenerator { if ($component->RRULE) { - $iterator = new Sabre_VObject_RecurrenceIterator($object, (string)$component->uid); + $iterator = new RecurrenceIterator($object, (string)$component->uid); if ($this->start) { $iterator->fastForward($this->start); } @@ -172,10 +201,10 @@ class Sabre_VObject_FreeBusyGenerator { if (isset($component->DTEND)) { $endTime = $component->DTEND->getDateTime(); } elseif (isset($component->DURATION)) { - $duration = Sabre_VObject_DateTimeParser::parseDuration((string)$component->DURATION); + $duration = DateTimeParser::parseDuration((string)$component->DURATION); $endTime = clone $startTime; $endTime->add($duration); - } elseif ($component->DTSTART->getDateType() === Sabre_VObject_Property_DateTime::DATE) { + } elseif ($component->DTSTART->getDateType() === Property\DateTime::DATE) { $endTime = clone $startTime; $endTime->modify('+1 day'); } else { @@ -212,14 +241,14 @@ class Sabre_VObject_FreeBusyGenerator { $values = explode(',', $freebusy); foreach($values as $value) { list($startTime, $endTime) = explode('/', $value); - $startTime = Sabre_VObject_DateTimeParser::parseDateTime($startTime); + $startTime = DateTimeParser::parseDateTime($startTime); if (substr($endTime,0,1)==='P' || substr($endTime,0,2)==='-P') { - $duration = Sabre_VObject_DateTimeParser::parseDuration($endTime); + $duration = DateTimeParser::parseDuration($endTime); $endTime = clone $startTime; $endTime->add($duration); } else { - $endTime = Sabre_VObject_DateTimeParser::parseDateTime($endTime); + $endTime = DateTimeParser::parseDateTime($endTime); } if($this->start && $this->start > $endTime) continue; @@ -248,39 +277,35 @@ class Sabre_VObject_FreeBusyGenerator { if ($this->baseObject) { $calendar = $this->baseObject; } else { - $calendar = new Sabre_VObject_Component('VCALENDAR'); + $calendar = new Component('VCALENDAR'); $calendar->version = '2.0'; - if (Sabre_DAV_Server::$exposeVersion) { - $calendar->prodid = '-//SabreDAV//Sabre VObject ' . Sabre_VObject_Version::VERSION . '//EN'; - } else { - $calendar->prodid = '-//SabreDAV//Sabre VObject//EN'; - } + $calendar->prodid = '-//Sabre//Sabre VObject ' . Version::VERSION . '//EN'; $calendar->calscale = 'GREGORIAN'; } - $vfreebusy = new Sabre_VObject_Component('VFREEBUSY'); + $vfreebusy = new Component('VFREEBUSY'); $calendar->add($vfreebusy); if ($this->start) { - $dtstart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtstart->setDateTime($this->start,Sabre_VObject_Property_DateTime::UTC); + $dtstart = new Property\DateTime('DTSTART'); + $dtstart->setDateTime($this->start,Property\DateTime::UTC); $vfreebusy->add($dtstart); } if ($this->end) { - $dtend = new Sabre_VObject_Property_DateTime('DTEND'); - $dtend->setDateTime($this->start,Sabre_VObject_Property_DateTime::UTC); + $dtend = new Property\DateTime('DTEND'); + $dtend->setDateTime($this->start,Property\DateTime::UTC); $vfreebusy->add($dtend); } - $dtstamp = new Sabre_VObject_Property_DateTime('DTSTAMP'); - $dtstamp->setDateTime(new DateTime('now'), Sabre_VObject_Property_DateTime::UTC); + $dtstamp = new Property\DateTime('DTSTAMP'); + $dtstamp->setDateTime(new \DateTime('now'), Property\DateTime::UTC); $vfreebusy->add($dtstamp); foreach($busyTimes as $busyTime) { - $busyTime[0]->setTimeZone(new DateTimeZone('UTC')); - $busyTime[1]->setTimeZone(new DateTimeZone('UTC')); + $busyTime[0]->setTimeZone(new \DateTimeZone('UTC')); + $busyTime[1]->setTimeZone(new \DateTimeZone('UTC')); - $prop = new Sabre_VObject_Property( + $prop = new Property( 'FREEBUSY', $busyTime[0]->format('Ymd\\THis\\Z') . '/' . $busyTime[1]->format('Ymd\\THis\\Z') ); diff --git a/dav/SabreDAV/lib/Sabre/VObject/Node.php b/dav/sabre-vobject/lib/Sabre/VObject/Node.php similarity index 87% rename from dav/SabreDAV/lib/Sabre/VObject/Node.php rename to dav/sabre-vobject/lib/Sabre/VObject/Node.php index 6c8319f76..88d1d8c35 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Node.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Node.php @@ -1,15 +1,15 @@ iterator)) return $this->iterator; - return new Sabre_VObject_ElementList(array($this)); + return new ElementList(array($this)); } @@ -70,10 +70,10 @@ abstract class Sabre_VObject_Node implements IteratorAggregate, ArrayAccess, Cou * * Note that this is not actually part of the iterator interface * - * @param Sabre_VObject_ElementList $iterator + * @param ElementList $iterator * @return void */ - public function setIterator(Sabre_VObject_ElementList $iterator) { + public function setIterator(ElementList $iterator) { $this->iterator = $iterator; diff --git a/dav/SabreDAV/lib/Sabre/VObject/Parameter.php b/dav/sabre-vobject/lib/Sabre/VObject/Parameter.php similarity index 93% rename from dav/SabreDAV/lib/Sabre/VObject/Parameter.php rename to dav/sabre-vobject/lib/Sabre/VObject/Parameter.php index 2e39af5f7..0355b0a0f 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Parameter.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Parameter.php @@ -1,5 +1,7 @@ 'Sabre_VObject_Property_DateTime', - 'CREATED' => 'Sabre_VObject_Property_DateTime', - 'DTEND' => 'Sabre_VObject_Property_DateTime', - 'DTSTAMP' => 'Sabre_VObject_Property_DateTime', - 'DTSTART' => 'Sabre_VObject_Property_DateTime', - 'DUE' => 'Sabre_VObject_Property_DateTime', - 'EXDATE' => 'Sabre_VObject_Property_MultiDateTime', - 'LAST-MODIFIED' => 'Sabre_VObject_Property_DateTime', - 'RECURRENCE-ID' => 'Sabre_VObject_Property_DateTime', - 'TRIGGER' => 'Sabre_VObject_Property_DateTime', + 'COMPLETED' => 'Sabre\\VObject\\Property\\DateTime', + 'CREATED' => 'Sabre\\VObject\\Property\\DateTime', + 'DTEND' => 'Sabre\\VObject\\Property\\DateTime', + 'DTSTAMP' => 'Sabre\\VObject\\Property\\DateTime', + 'DTSTART' => 'Sabre\\VObject\\Property\\DateTime', + 'DUE' => 'Sabre\\VObject\\Property\\DateTime', + 'EXDATE' => 'Sabre\\VObject\\Property\\MultiDateTime', + 'LAST-MODIFIED' => 'Sabre\\VObject\\Property\\DateTime', + 'RECURRENCE-ID' => 'Sabre\\VObject\\Property\\DateTime', + 'TRIGGER' => 'Sabre\\VObject\\Property\\DateTime', ); /** * Creates the new property by name, but in addition will also see if * there's a class mapped to the property name. * + * Parameters can be specified with the optional third argument. Parameters + * must be a key->value map of the parameter name, and value. If the value + * is specified as an array, it is assumed that multiple parameters with + * the same name should be added. + * * @param string $name * @param string $value - * @return Sabre_VObject_Property + * @param array $parameters + * @return Property */ - static public function create($name, $value = null) { + static public function create($name, $value = null, array $parameters = array()) { $name = strtoupper($name); $shortName = $name; @@ -87,9 +93,9 @@ class Sabre_VObject_Property extends Sabre_VObject_Element { } if (isset(self::$classMap[$shortName])) { - return new self::$classMap[$shortName]($name, $value); + return new self::$classMap[$shortName]($name, $value, $parameters); } else { - return new self($name, $value); + return new self($name, $value, $parameters); } } @@ -97,14 +103,16 @@ class Sabre_VObject_Property extends Sabre_VObject_Element { /** * Creates a new property object * - * By default this object will iterate over its own children, but this can - * be overridden with the iterator argument + * Parameters can be specified with the optional third argument. Parameters + * must be a key->value map of the parameter name, and value. If the value + * is specified as an array, it is assumed that multiple parameters with + * the same name should be added. * * @param string $name * @param string $value - * @param Sabre_VObject_ElementList $iterator + * @param array $parameters */ - public function __construct($name, $value = null, $iterator = null) { + public function __construct($name, $value = null, array $parameters = array()) { $name = strtoupper($name); $group = null; @@ -113,13 +121,22 @@ class Sabre_VObject_Property extends Sabre_VObject_Element { } $this->name = $name; $this->group = $group; - if (!is_null($iterator)) $this->iterator = $iterator; $this->setValue($value); + foreach($parameters as $paramName => $paramValues) { + + if (!is_array($paramValues)) { + $paramValues = array($paramValues); + } + + foreach($paramValues as $paramValue) { + $this->add($paramName, $paramValue); + } + + } + } - - /** * Updates the internal value * @@ -180,7 +197,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element { * * You can call this method with the following syntaxes: * - * add(Sabre_VObject_Parameter $element) + * add(Parameter $element) * add(string $name, $value) * * The first version adds an Parameter @@ -192,24 +209,24 @@ class Sabre_VObject_Property extends Sabre_VObject_Element { */ public function add($item, $itemValue = null) { - if ($item instanceof Sabre_VObject_Parameter) { + if ($item instanceof Parameter) { if (!is_null($itemValue)) { - throw new InvalidArgumentException('The second argument must not be specified, when passing a VObject'); + throw new \InvalidArgumentException('The second argument must not be specified, when passing a VObject'); } $item->parent = $this; $this->parameters[] = $item; } elseif(is_string($item)) { if (!is_scalar($itemValue) && !is_null($itemValue)) { - throw new InvalidArgumentException('The second argument must be scalar'); + throw new \InvalidArgumentException('The second argument must be scalar'); } - $parameter = new Sabre_VObject_Parameter($item,$itemValue); + $parameter = new Parameter($item,$itemValue); $parameter->parent = $this; $this->parameters[] = $parameter; } else { - throw new InvalidArgumentException('The first argument must either be a Sabre_VObject_Element or a string'); + throw new \InvalidArgumentException('The first argument must either be a Element or a string'); } @@ -240,7 +257,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element { * Returns a parameter, or parameter list. * * @param string $name - * @return Sabre_VObject_Element + * @return Element */ public function offsetGet($name) { @@ -258,7 +275,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element { } elseif (count($result)===1) { return $result[0]; } else { - $result[0]->setIterator(new Sabre_VObject_ElementList($result)); + $result[0]->setIterator(new ElementList($result)); return $result[0]; } @@ -277,21 +294,21 @@ class Sabre_VObject_Property extends Sabre_VObject_Element { if (is_scalar($value)) { if (!is_string($name)) - throw new InvalidArgumentException('A parameter name must be specified. This means you cannot use the $array[]="string" to add parameters.'); + throw new \InvalidArgumentException('A parameter name must be specified. This means you cannot use the $array[]="string" to add parameters.'); $this->offsetUnset($name); - $parameter = new Sabre_VObject_Parameter($name, $value); + $parameter = new Parameter($name, $value); $parameter->parent = $this; $this->parameters[] = $parameter; - } elseif ($value instanceof Sabre_VObject_Parameter) { + } elseif ($value instanceof Parameter) { if (!is_null($name)) - throw new InvalidArgumentException('Don\'t specify a parameter name if you\'re passing a Sabre_VObject_Parameter. Add using $array[]=$parameterObject.'); + throw new \InvalidArgumentException('Don\'t specify a parameter name if you\'re passing a \\Sabre\\VObject\\Parameter. Add using $array[]=$parameterObject.'); $value->parent = $this; $this->parameters[] = $value; } else { - throw new InvalidArgumentException('You can only add parameters to the property object'); + throw new \InvalidArgumentException('You can only add parameters to the property object'); } } diff --git a/dav/SabreDAV/lib/Sabre/VObject/Property/DateTime.php b/dav/sabre-vobject/lib/Sabre/VObject/Property/DateTime.php similarity index 79% rename from dav/SabreDAV/lib/Sabre/VObject/Property/DateTime.php rename to dav/sabre-vobject/lib/Sabre/VObject/Property/DateTime.php index ff2c867a3..556cd441d 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Property/DateTime.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Property/DateTime.php @@ -1,5 +1,9 @@ offsetSet('VALUE','DATE-TIME'); break; case self::UTC : - $dt->setTimeZone(new DateTimeZone('UTC')); + $dt->setTimeZone(new \DateTimeZone('UTC')); $this->setValue($dt->format('Ymd\\THis\\Z')); $this->offsetUnset('VALUE'); $this->offsetUnset('TZID'); @@ -93,7 +95,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { $this->offsetSet('VALUE','DATE'); break; default : - throw new InvalidArgumentException('You must pass a valid dateType constant'); + throw new \InvalidArgumentException('You must pass a valid dateType constant'); } $this->dateTime = $dt; @@ -106,7 +108,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { * * If no value was set, this method returns null. * - * @return DateTime|null + * @return \DateTime|null */ public function getDateTime() { @@ -152,11 +154,11 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { * * @param string|null $propertyValue The string to parse (yymmdd or * ymmddThhmmss, etc..) - * @param Sabre_VObject_Property|null $property The instance of the + * @param \Sabre\VObject\Property|null $property The instance of the * property we're parsing. * @return array */ - static public function parseData($propertyValue, Sabre_VObject_Property $property = null) { + static public function parseData($propertyValue, VObject\Property $property = null) { if (is_null($propertyValue)) { return array(null, null); @@ -167,14 +169,14 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { $regex = "/^$date(T$time(?PZ)?)?$/"; if (!preg_match($regex, $propertyValue, $matches)) { - throw new InvalidArgumentException($propertyValue . ' is not a valid DateTime or Date string'); + throw new \InvalidArgumentException($propertyValue . ' is not a valid \DateTime or Date string'); } if (!isset($matches['hour'])) { // Date-only return array( self::DATE, - new DateTime($matches['year'] . '-' . $matches['month'] . '-' . $matches['date'] . ' 00:00:00'), + new \DateTime($matches['year'] . '-' . $matches['month'] . '-' . $matches['date'] . ' 00:00:00', new \DateTimeZone('UTC')), ); } @@ -187,8 +189,8 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { $matches['second']; if (isset($matches['isutc'])) { - $dt = new DateTime($dateStr,new DateTimeZone('UTC')); - $dt->setTimeZone(new DateTimeZone('UTC')); + $dt = new \DateTime($dateStr,new \DateTimeZone('UTC')); + $dt->setTimeZone(new \DateTimeZone('UTC')); return array( self::UTC, $dt @@ -198,9 +200,12 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { // Finding the timezone. $tzid = $property['TZID']; if (!$tzid) { + // This was a floating time string. This implies we use the + // timezone from date_default_timezone_set / date.timezone ini + // setting. return array( self::LOCAL, - new DateTime($dateStr) + new \DateTime($dateStr) ); } @@ -210,12 +215,12 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property { $root = $root->parent; } if ($root->name === 'VCALENDAR') { - $tz = Sabre_VObject_TimeZoneUtil::getTimeZone((string)$tzid, $root); + $tz = VObject\TimeZoneUtil::getTimeZone((string)$tzid, $root); } else { - $tz = Sabre_VObject_TimeZoneUtil::getTimeZone((string)$tzid); + $tz = VObject\TimeZoneUtil::getTimeZone((string)$tzid); } - $dt = new DateTime($dateStr, $tz); + $dt = new \DateTime($dateStr, $tz); $dt->setTimeZone($tz); return array( diff --git a/dav/SabreDAV/lib/Sabre/VObject/Property/MultiDateTime.php b/dav/sabre-vobject/lib/Sabre/VObject/Property/MultiDateTime.php similarity index 80% rename from dav/SabreDAV/lib/Sabre/VObject/Property/MultiDateTime.php rename to dav/sabre-vobject/lib/Sabre/VObject/Property/MultiDateTime.php index ae53ab6a6..629ef4a13 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Property/MultiDateTime.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Property/MultiDateTime.php @@ -1,5 +1,9 @@ offsetUnset('VALUE'); $this->offsetUnset('TZID'); switch($dateType) { - case Sabre_VObject_Property_DateTime::LOCAL : + case DateTime::LOCAL : $val = array(); foreach($dt as $i) { $val[] = $i->format('Ymd\\THis'); @@ -62,16 +64,16 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { $this->setValue(implode(',',$val)); $this->offsetSet('VALUE','DATE-TIME'); break; - case Sabre_VObject_Property_DateTime::UTC : + case DateTime::UTC : $val = array(); foreach($dt as $i) { - $i->setTimeZone(new DateTimeZone('UTC')); + $i->setTimeZone(new \DateTimeZone('UTC')); $val[] = $i->format('Ymd\\THis\\Z'); } $this->setValue(implode(',',$val)); $this->offsetSet('VALUE','DATE-TIME'); break; - case Sabre_VObject_Property_DateTime::LOCALTZ : + case DateTime::LOCALTZ : $val = array(); foreach($dt as $i) { $val[] = $i->format('Ymd\\THis'); @@ -80,7 +82,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { $this->offsetSet('VALUE','DATE-TIME'); $this->offsetSet('TZID', $dt[0]->getTimeZone()->getName()); break; - case Sabre_VObject_Property_DateTime::DATE : + case DateTime::DATE : $val = array(); foreach($dt as $i) { $val[] = $i->format('Ymd'); @@ -89,7 +91,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { $this->offsetSet('VALUE','DATE'); break; default : - throw new InvalidArgumentException('You must pass a valid dateType constant'); + throw new \InvalidArgumentException('You must pass a valid dateType constant'); } $this->dateTimes = $dt; @@ -121,7 +123,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { list( $type, $dt - ) = Sabre_VObject_Property_DateTime::parseData($val, $this); + ) = DateTime::parseData($val, $this); $dts[] = $dt; $this->dateType = $type; } @@ -154,7 +156,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property { list( $type, $dt - ) = Sabre_VObject_Property_DateTime::parseData($val, $this); + ) = DateTime::parseData($val, $this); $dts[] = $dt; $this->dateType = $type; } diff --git a/dav/SabreDAV/lib/Sabre/VObject/Reader.php b/dav/sabre-vobject/lib/Sabre/VObject/Reader.php similarity index 83% rename from dav/SabreDAV/lib/Sabre/VObject/Reader.php rename to dav/sabre-vobject/lib/Sabre/VObject/Reader.php index eea73fa3d..8fed7e275 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Reader.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Reader.php @@ -1,5 +1,7 @@ name) { - throw new Sabre_VObject_ParseException('Invalid VObject, expected: "END:' . $obj->name . '" got: "' . $nextLine . '"'); + throw new ParseException('Invalid VObject, expected: "END:' . $obj->name . '" got: "' . $nextLine . '"'); } next($lines); @@ -107,7 +107,7 @@ class Sabre_VObject_Reader { $result = preg_match($regex,$line,$matches); if (!$result) { - throw new Sabre_VObject_ParseException('Invalid VObject, line ' . ($lineNr+1) . ' did not follow the icalendar/vcard format'); + throw new ParseException('Invalid VObject, line ' . ($lineNr+1) . ' did not follow the icalendar/vcard format'); } $propertyName = strtoupper($matches['name']); @@ -119,7 +119,7 @@ class Sabre_VObject_Reader { } }, $matches['value']); - $obj = Sabre_VObject_Property::create($propertyName, $propertyValue); + $obj = Property::create($propertyName, $propertyValue); if ($matches['parameters']) { @@ -137,7 +137,7 @@ class Sabre_VObject_Reader { /** * Reads a parameter list from a property * - * This method returns an array of Sabre_VObject_Parameter + * This method returns an array of Parameter * * @param string $parameters * @return array @@ -171,7 +171,7 @@ class Sabre_VObject_Reader { } }, $value); - $params[] = new Sabre_VObject_Parameter($match['paramName'], $value); + $params[] = new Parameter($match['paramName'], $value); } diff --git a/dav/SabreDAV/lib/Sabre/VObject/RecurrenceIterator.php b/dav/sabre-vobject/lib/Sabre/VObject/RecurrenceIterator.php similarity index 96% rename from dav/SabreDAV/lib/Sabre/VObject/RecurrenceIterator.php rename to dav/sabre-vobject/lib/Sabre/VObject/RecurrenceIterator.php index 7ccd2049b..374b16e83 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/RecurrenceIterator.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/RecurrenceIterator.php @@ -1,5 +1,7 @@ name === 'VCALENDAR') { - throw new InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well'); + throw new \InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well'); } $components = array($vcal); $uid = (string)$vcal->uid; @@ -325,7 +325,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator { } } if (!$this->baseEvent) { - throw new InvalidArgumentException('Could not find a base event with uid: ' . $uid); + throw new \InvalidArgumentException('Could not find a base event with uid: ' . $uid); } $this->startDate = clone $this->baseEvent->DTSTART->getDateTime(); @@ -336,8 +336,8 @@ class Sabre_VObject_RecurrenceIterator implements Iterator { } else { $this->endDate = clone $this->startDate; if (isset($this->baseEvent->DURATION)) { - $this->endDate->add(Sabre_VObject_DateTimeParser::parse($this->baseEvent->DURATION->value)); - } elseif ($this->baseEvent->DTSTART->getDateType()===Sabre_VObject_Property_DateTime::DATE) { + $this->endDate->add(DateTimeParser::parse($this->baseEvent->DURATION->value)); + } elseif ($this->baseEvent->DTSTART->getDateType()===Property\DateTime::DATE) { $this->endDate->modify('+1 day'); } } @@ -362,14 +362,14 @@ class Sabre_VObject_RecurrenceIterator implements Iterator { strtolower($value), array('secondly','minutely','hourly','daily','weekly','monthly','yearly') )) { - throw new InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value)); + throw new \InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value)); } $this->frequency = strtolower($value); break; case 'UNTIL' : - $this->until = Sabre_VObject_DateTimeParser::parse($value); + $this->until = DateTimeParser::parse($value); break; case 'COUNT' : @@ -431,7 +431,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator { foreach(explode(',', (string)$exDate) as $exceptionDate) { $this->exceptionDates[] = - Sabre_VObject_DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone()); + DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone()); } @@ -489,7 +489,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator { * * This method always returns a cloned instance. * - * @return Sabre_VObject_Component_VEvent + * @return Component\VEvent */ public function getEventObject() { @@ -565,7 +565,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator { * @param DateTime $dt * @return void */ - public function fastForward(DateTime $dt) { + public function fastForward(\DateTime $dt) { while($this->valid() && $this->getDTEnd() <= $dt) { $this->next(); diff --git a/dav/SabreDAV/lib/Sabre/VObject/TimeZoneUtil.php b/dav/sabre-vobject/lib/Sabre/VObject/TimeZoneUtil.php similarity index 96% rename from dav/SabreDAV/lib/Sabre/VObject/TimeZoneUtil.php rename to dav/sabre-vobject/lib/Sabre/VObject/TimeZoneUtil.php index 276288aaa..8e01210b0 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/TimeZoneUtil.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/TimeZoneUtil.php @@ -1,18 +1,18 @@ {'X-LIC-LOCATION'})) { try { - return new DateTimeZone($vtimezone->{'X-LIC-LOCATION'}); + return new \DateTimeZone($vtimezone->{'X-LIC-LOCATION'}); } catch (\Exception $e) { } @@ -332,7 +332,7 @@ class Sabre_VObject_TimeZoneUtil { // answer for. if (isset($vtimezone->{'X-MICROSOFT-CDO-TZID'})) { if (isset(self::$microsoftExchangeMap[(int)$vtimezone->{'X-MICROSOFT-CDO-TZID'}->value])) { - return new DateTimeZone(self::$microsoftExchangeMap[(int)$vtimezone->{'X-MICROSOFT-CDO-TZID'}->value]); + return new \DateTimeZone(self::$microsoftExchangeMap[(int)$vtimezone->{'X-MICROSOFT-CDO-TZID'}->value]); } } } @@ -342,7 +342,7 @@ class Sabre_VObject_TimeZoneUtil { } // If we got all the way here, we default to UTC. - return new DateTimeZone(date_default_timezone_get()); + return new \DateTimeZone(date_default_timezone_get()); } diff --git a/dav/SabreDAV/lib/Sabre/VObject/Version.php b/dav/sabre-vobject/lib/Sabre/VObject/Version.php similarity index 81% rename from dav/SabreDAV/lib/Sabre/VObject/Version.php rename to dav/sabre-vobject/lib/Sabre/VObject/Version.php index 9ee03d871..a35c852e1 100644 --- a/dav/SabreDAV/lib/Sabre/VObject/Version.php +++ b/dav/sabre-vobject/lib/Sabre/VObject/Version.php @@ -1,20 +1,20 @@ assertEquals($outcome, $valarm->isInTimeRange($start, $end)); @@ -16,7 +21,7 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase { $tests = array(); // Hard date and time - $valarm1 = Sabre_VObject_Component::create('VALARM'); + $valarm1 = Component::create('VALARM'); $valarm1->TRIGGER = '20120312T130000Z'; $valarm1->TRIGGER['VALUE'] = 'DATE-TIME'; @@ -24,11 +29,11 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase { $tests[] = array($valarm1, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-03-10 01:00:00'), false); // Relation to start time of event - $valarm2 = Sabre_VObject_Component::create('VALARM'); + $valarm2 = Component::create('VALARM'); $valarm2->TRIGGER = '-P1D'; $valarm2->TRIGGER['VALUE'] = 'DURATION'; - $vevent2 = Sabre_VObject_Component::create('VEVENT'); + $vevent2 = Component::create('VEVENT'); $vevent2->DTSTART = '20120313T130000Z'; $vevent2->add($valarm2); @@ -36,12 +41,12 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase { $tests[] = array($valarm2, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-03-10 01:00:00'), false); // Relation to end time of event - $valarm3 = Sabre_VObject_Component::create('VALARM'); + $valarm3 = Component::create('VALARM'); $valarm3->TRIGGER = '-P1D'; $valarm3->TRIGGER['VALUE'] = 'DURATION'; $valarm3->TRIGGER['RELATED']= 'END'; - $vevent3 = Sabre_VObject_Component::create('VEVENT'); + $vevent3 = Component::create('VEVENT'); $vevent3->DTSTART = '20120301T130000Z'; $vevent3->DTEND = '20120401T130000Z'; $vevent3->add($valarm3); @@ -50,12 +55,12 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase { $tests[] = array($valarm3, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), true); // Relation to end time of todo - $valarm4 = Sabre_VObject_Component::create('VALARM'); + $valarm4 = Component::create('VALARM'); $valarm4->TRIGGER = '-P1D'; $valarm4->TRIGGER['VALUE'] = 'DURATION'; $valarm4->TRIGGER['RELATED']= 'END'; - $vtodo4 = Sabre_VObject_Component::create('VTODO'); + $vtodo4 = Component::create('VTODO'); $vtodo4->DTSTART = '20120301T130000Z'; $vtodo4->DUE = '20120401T130000Z'; $vtodo4->add($valarm4); @@ -64,25 +69,25 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase { $tests[] = array($valarm4, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), true); // Relation to start time of event + repeat - $valarm5 = Sabre_VObject_Component::create('VALARM'); + $valarm5 = Component::create('VALARM'); $valarm5->TRIGGER = '-P1D'; $valarm5->TRIGGER['VALUE'] = 'DURATION'; $valarm5->REPEAT = 10; $valarm5->DURATION = 'P1D'; - $vevent5 = Sabre_VObject_Component::create('VEVENT'); + $vevent5 = Component::create('VEVENT'); $vevent5->DTSTART = '20120301T130000Z'; $vevent5->add($valarm5); $tests[] = array($valarm5, new DateTime('2012-03-09 01:00:00'), new DateTime('2012-03-10 01:00:00'), true); // Relation to start time of event + duration, but no repeat - $valarm6 = Sabre_VObject_Component::create('VALARM'); + $valarm6 = Component::create('VALARM'); $valarm6->TRIGGER = '-P1D'; $valarm6->TRIGGER['VALUE'] = 'DURATION'; $valarm6->DURATION = 'P1D'; - $vevent6 = Sabre_VObject_Component::create('VEVENT'); + $vevent6 = Component::create('VEVENT'); $vevent6->DTSTART = '20120313T130000Z'; $vevent6->add($valarm6); @@ -91,12 +96,12 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase { // Relation to end time of event (DURATION instead of DTEND) - $valarm7 = Sabre_VObject_Component::create('VALARM'); + $valarm7 = Component::create('VALARM'); $valarm7->TRIGGER = '-P1D'; $valarm7->TRIGGER['VALUE'] = 'DURATION'; $valarm7->TRIGGER['RELATED']= 'END'; - $vevent7 = Sabre_VObject_Component::create('VEVENT'); + $vevent7 = Component::create('VEVENT'); $vevent7->DTSTART = '20120301T130000Z'; $vevent7->DURATION = 'P30D'; $vevent7->add($valarm7); @@ -105,12 +110,12 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase { $tests[] = array($valarm7, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), true); // Relation to end time of event (No DTEND or DURATION) - $valarm7 = Sabre_VObject_Component::create('VALARM'); + $valarm7 = Component::create('VALARM'); $valarm7->TRIGGER = '-P1D'; $valarm7->TRIGGER['VALUE'] = 'DURATION'; $valarm7->TRIGGER['RELATED']= 'END'; - $vevent7 = Sabre_VObject_Component::create('VEVENT'); + $vevent7 = Component::create('VEVENT'); $vevent7->DTSTART = '20120301T130000Z'; $vevent7->add($valarm7); @@ -122,15 +127,15 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase { } /** - * @expectedException Sabre_DAV_Exception + * @expectedException LogicException */ public function testInTimeRangeInvalidComponent() { - $valarm = Sabre_VObject_Component::create('VALARM'); + $valarm = Component::create('VALARM'); $valarm->TRIGGER = '-P1D'; $valarm->TRIGGER['RELATED'] = 'END'; - $vjournal = Sabre_VObject_Component::create('VJOURNAL'); + $vjournal = Component::create('VJOURNAL'); $vjournal->add($valarm); $valarm->isInTimeRange(new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00')); diff --git a/dav/SabreDAV/tests/Sabre/VObject/Component/VCalendarTest.php b/dav/sabre-vobject/tests/Sabre/VObject/Component/VCalendarTest.php similarity index 90% rename from dav/SabreDAV/tests/Sabre/VObject/Component/VCalendarTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/Component/VCalendarTest.php index b1b503b4d..1d7e0c603 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/Component/VCalendarTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/Component/VCalendarTest.php @@ -1,20 +1,24 @@ expand( - new DateTime('2011-12-01'), - new DateTime('2011-12-31') + new \DateTime('2011-12-01'), + new \DateTime('2011-12-31') ); // This will normalize the output - $output = Sabre_VObject_Reader::read($output)->serialize(); + $output = VObject\Reader::read($output)->serialize(); $this->assertEquals($output, $vcal->serialize()); @@ -229,10 +233,10 @@ DTSTART;VALUE=DATE:20111202 END:VEVENT END:VCALENDAR '; - $vcal = Sabre_VObject_Reader::read($input); + $vcal = VObject\Reader::read($input); $vcal->expand( - new DateTime('2011-12-01'), - new DateTime('2011-12-31') + new \DateTime('2011-12-01'), + new \DateTime('2011-12-31') ); } diff --git a/dav/sabre-vobject/tests/Sabre/VObject/Component/VCardTest.php b/dav/sabre-vobject/tests/Sabre/VObject/Component/VCardTest.php new file mode 100644 index 000000000..584a007d9 --- /dev/null +++ b/dav/sabre-vobject/tests/Sabre/VObject/Component/VCardTest.php @@ -0,0 +1,100 @@ +validate(); + + $warnMsg = array(); + foreach($warnings as $warning) { + $warnMsg[] = $warning['message']; + } + + $this->assertEquals($expectedWarnings, $warnMsg); + + $vcard->validate(VObject\Component::REPAIR); + + $this->assertEquals( + $expectedRepairedOutput, + $vcard->serialize() + ); + + } + + public function validateData() { + + $tests = array(); + + // Correct + $tests[] = array( + "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n", + array(), + "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n", + ); + + // No VERSION + $tests[] = array( + "BEGIN:VCARD\r\nFN:John Doe\r\nEND:VCARD\r\n", + array( + 'The VERSION property must appear in the VCARD component exactly 1 time', + ), + "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n", + ); + + // Unknown version + $tests[] = array( + "BEGIN:VCARD\r\nVERSION:2.2\r\nFN:John Doe\r\nEND:VCARD\r\n", + array( + 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.', + ), + "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n", + ); + + // No FN + $tests[] = array( + "BEGIN:VCARD\r\nVERSION:4.0\r\nEND:VCARD\r\n", + array( + 'The FN property must appear in the VCARD component exactly 1 time', + ), + "BEGIN:VCARD\r\nVERSION:4.0\r\nEND:VCARD\r\n", + ); + // No FN, N fallback + $tests[] = array( + "BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;John;;;;;\r\nEND:VCARD\r\n", + array( + 'The FN property must appear in the VCARD component exactly 1 time', + ), + "BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;John;;;;;\r\nFN:John Doe\r\nEND:VCARD\r\n", + ); + // No FN, N fallback, no first name + $tests[] = array( + "BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;;;;;;\r\nEND:VCARD\r\n", + array( + 'The FN property must appear in the VCARD component exactly 1 time', + ), + "BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;;;;;;\r\nFN:Doe\r\nEND:VCARD\r\n", + ); + + // No FN, ORG fallback + $tests[] = array( + "BEGIN:VCARD\r\nVERSION:4.0\r\nORG:Acme Co.\r\nEND:VCARD\r\n", + array( + 'The FN property must appear in the VCARD component exactly 1 time', + ), + "BEGIN:VCARD\r\nVERSION:4.0\r\nORG:Acme Co.\r\nFN:Acme Co.\r\nEND:VCARD\r\n", + ); + return $tests; + + } + +} diff --git a/dav/sabre-vobject/tests/Sabre/VObject/Component/VEventTest.php b/dav/sabre-vobject/tests/Sabre/VObject/Component/VEventTest.php new file mode 100644 index 000000000..616da4ac7 --- /dev/null +++ b/dav/sabre-vobject/tests/Sabre/VObject/Component/VEventTest.php @@ -0,0 +1,74 @@ +assertEquals($outcome, $vevent->isInTimeRange($start, $end)); + + } + + public function timeRangeTestData() { + + $tests = array(); + + $vevent = new VEvent('VEVENT'); + $vevent->DTSTART = '20111223T120000Z'; + $tests[] = array($vevent, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vevent, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + $vevent2 = clone $vevent; + $vevent2->DTEND = '20111225T120000Z'; + $tests[] = array($vevent2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vevent2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + $vevent3 = clone $vevent; + $vevent3->DURATION = 'P1D'; + $tests[] = array($vevent3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vevent3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + $vevent4 = clone $vevent; + $vevent4->DTSTART = '20111225'; + $vevent4->DTSTART['VALUE'] = 'DATE'; + $tests[] = array($vevent4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vevent4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + // Event with no end date should be treated as lasting the entire day. + $tests[] = array($vevent4, new \DateTime('2011-12-25 16:00:00'), new \DateTime('2011-12-25 17:00:00'), true); + + + $vevent5 = clone $vevent; + $vevent5->DURATION = 'P1D'; + $vevent5->RRULE = 'FREQ=YEARLY'; + $tests[] = array($vevent5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vevent5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + $tests[] = array($vevent5, new \DateTime('2013-12-01'), new \DateTime('2013-12-31'), true); + + $vevent6 = clone $vevent; + $vevent6->DTSTART = '20111225'; + $vevent6->DTSTART['VALUE'] = 'DATE'; + $vevent6->DTEND = '20111225'; + $vevent6->DTEND['VALUE'] = 'DATE'; + + $tests[] = array($vevent6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vevent6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + // Added this test to ensure that recurrence rules with no DTEND also + // get checked for the entire day. + $vevent7 = clone $vevent; + $vevent7->DTSTART = '20120101'; + $vevent7->DTSTART['VALUE'] = 'DATE'; + $vevent7->RRULE = 'FREQ=MONTHLY'; + $tests[] = array($vevent7, new \DateTime('2012-02-01 15:00:00'), new \DateTime('2012-02-02'), true); + return $tests; + + } + +} + diff --git a/dav/sabre-vobject/tests/Sabre/VObject/Component/VJournalTest.php b/dav/sabre-vobject/tests/Sabre/VObject/Component/VJournalTest.php new file mode 100644 index 000000000..46ecb992b --- /dev/null +++ b/dav/sabre-vobject/tests/Sabre/VObject/Component/VJournalTest.php @@ -0,0 +1,41 @@ +assertEquals($outcome, $vtodo->isInTimeRange($start, $end)); + + } + + public function timeRangeTestData() { + + $tests = array(); + + $vjournal = Component::create('VJOURNAL'); + $vjournal->DTSTART = '20111223T120000Z'; + $tests[] = array($vjournal, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vjournal, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + $vjournal2 = Component::create('VJOURNAL'); + $vjournal2->DTSTART = '20111223'; + $vjournal2->DTSTART['VALUE'] = 'DATE'; + $tests[] = array($vjournal2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vjournal2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + $vjournal3 = Component::create('VJOURNAL'); + $tests[] = array($vjournal3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), false); + $tests[] = array($vjournal3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + return $tests; + } + +} + diff --git a/dav/sabre-vobject/tests/Sabre/VObject/Component/VTodoTest.php b/dav/sabre-vobject/tests/Sabre/VObject/Component/VTodoTest.php new file mode 100644 index 000000000..a84da5cdf --- /dev/null +++ b/dav/sabre-vobject/tests/Sabre/VObject/Component/VTodoTest.php @@ -0,0 +1,67 @@ +assertEquals($outcome, $vtodo->isInTimeRange($start, $end)); + + } + + public function timeRangeTestData() { + + $tests = array(); + + $vtodo = Component::create('VTODO'); + $vtodo->DTSTART = '20111223T120000Z'; + $tests[] = array($vtodo, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vtodo, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + $vtodo2 = clone $vtodo; + $vtodo2->DURATION = 'P1D'; + $tests[] = array($vtodo2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vtodo2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + $vtodo3 = clone $vtodo; + $vtodo3->DUE = '20111225'; + $tests[] = array($vtodo3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vtodo3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + $vtodo4 = Component::create('VTODO'); + $vtodo4->DUE = '20111225'; + $tests[] = array($vtodo4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vtodo4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + $vtodo5 = Component::create('VTODO'); + $vtodo5->COMPLETED = '20111225'; + $tests[] = array($vtodo5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vtodo5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + $vtodo6 = Component::create('VTODO'); + $vtodo6->CREATED = '20111225'; + $tests[] = array($vtodo6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vtodo6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + $vtodo7 = Component::create('VTODO'); + $vtodo7->CREATED = '20111225'; + $vtodo7->COMPLETED = '20111226'; + $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); + + $vtodo7 = Component::create('VTODO'); + $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); + $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), true); + + return $tests; + + } + +} + diff --git a/dav/SabreDAV/tests/Sabre/VObject/ComponentTest.php b/dav/sabre-vobject/tests/Sabre/VObject/ComponentTest.php similarity index 65% rename from dav/SabreDAV/tests/Sabre/VObject/ComponentTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/ComponentTest.php index 42f836dbd..07000bda0 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/ComponentTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/ComponentTest.php @@ -1,22 +1,24 @@ children[] = $sub; - $sub = new Sabre_VObject_Component('VTODO'); + $sub = new Component('VTODO'); $comp->children[] = $sub; $count = 0; foreach($comp->children() as $key=>$subcomponent) { $count++; - $this->assertInstanceOf('Sabre_VObject_Component',$subcomponent); + $this->assertInstanceOf('Sabre\\VObject\\Component',$subcomponent); } $this->assertEquals(2,$count); @@ -26,16 +28,16 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { function testMagicGet() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); - $sub = new Sabre_VObject_Component('VEVENT'); + $sub = new Component('VEVENT'); $comp->children[] = $sub; - $sub = new Sabre_VObject_Component('VTODO'); + $sub = new Component('VTODO'); $comp->children[] = $sub; $event = $comp->vevent; - $this->assertInstanceOf('Sabre_VObject_Component', $event); + $this->assertInstanceOf('Sabre\\VObject\\Component', $event); $this->assertEquals('VEVENT', $event->name); $this->assertInternalType('null', $comp->vjournal); @@ -44,15 +46,15 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { function testMagicGetGroups() { - $comp = new Sabre_VObject_Component('VCARD'); + $comp = new Component('VCARD'); - $sub = new Sabre_VObject_Property('GROUP1.EMAIL','1@1.com'); + $sub = new Property('GROUP1.EMAIL','1@1.com'); $comp->children[] = $sub; - $sub = new Sabre_VObject_Property('GROUP2.EMAIL','2@2.com'); + $sub = new Property('GROUP2.EMAIL','2@2.com'); $comp->children[] = $sub; - $sub = new Sabre_VObject_Property('EMAIL','3@3.com'); + $sub = new Property('EMAIL','3@3.com'); $comp->children[] = $sub; $emails = $comp->email; @@ -70,12 +72,12 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { function testMagicIsset() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); - $sub = new Sabre_VObject_Component('VEVENT'); + $sub = new Component('VEVENT'); $comp->children[] = $sub; - $sub = new Sabre_VObject_Component('VTODO'); + $sub = new Component('VTODO'); $comp->children[] = $sub; $this->assertTrue(isset($comp->vevent)); @@ -86,10 +88,10 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { function testMagicSetScalar() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); $comp->myProp = 'myValue'; - $this->assertInstanceOf('Sabre_VObject_Property',$comp->MYPROP); + $this->assertInstanceOf('Sabre\\VObject\\Property',$comp->MYPROP); $this->assertEquals('myValue',$comp->MYPROP->value); @@ -97,22 +99,22 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { function testMagicSetScalarTwice() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); $comp->myProp = 'myValue'; $comp->myProp = 'myValue'; $this->assertEquals(1,count($comp->children)); - $this->assertInstanceOf('Sabre_VObject_Property',$comp->MYPROP); + $this->assertInstanceOf('Sabre\\VObject\\Property',$comp->MYPROP); $this->assertEquals('myValue',$comp->MYPROP->value); } function testMagicSetComponent() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); // Note that 'myProp' is ignored here. - $comp->myProp = new Sabre_VObject_Component('VEVENT'); + $comp->myProp = new Component('VEVENT'); $this->assertEquals(1, count($comp->children)); @@ -122,10 +124,10 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { function testMagicSetTwice() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); - $comp->VEVENT = new Sabre_VObject_Component('VEVENT'); - $comp->VEVENT = new Sabre_VObject_Component('VEVENT'); + $comp->VEVENT = new Component('VEVENT'); + $comp->VEVENT = new Component('VEVENT'); $this->assertEquals(1, count($comp->children)); @@ -135,9 +137,9 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { function testArrayAccessGet() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); - $event = new Sabre_VObject_Component('VEVENT'); + $event = new Component('VEVENT'); $event->summary = 'Event 1'; $comp->add($event); @@ -148,16 +150,16 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { $comp->add($event2); $this->assertEquals(2,count($comp->children())); - $this->assertTrue($comp->vevent[1] instanceof Sabre_VObject_Component); + $this->assertTrue($comp->vevent[1] instanceof Component); $this->assertEquals('Event 2', (string)$comp->vevent[1]->summary); } function testArrayAccessExists() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); - $event = new Sabre_VObject_Component('VEVENT'); + $event = new Component('VEVENT'); $event->summary = 'Event 1'; $comp->add($event); @@ -177,7 +179,7 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { */ function testArrayAccessSet() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); $comp['hey'] = 'hi there'; } @@ -186,30 +188,51 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { */ function testArrayAccessUnset() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); unset($comp[0]); } function testAddScalar() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); $comp->add('myprop','value'); $this->assertEquals(1, count($comp->children)); - $this->assertTrue($comp->children[0] instanceof Sabre_VObject_Property); + $this->assertTrue($comp->children[0] instanceof Property); $this->assertEquals('MYPROP',$comp->children[0]->name); $this->assertEquals('value',$comp->children[0]->value); } + function testAddScalarParams() { + + $comp = Component::create('VCALENDAR'); + + $comp->add('myprop','value',array('param1'=>'value1')); + + $this->assertEquals(1, count($comp->children)); + + $this->assertTrue($comp->children[0] instanceof Property); + $this->assertEquals('MYPROP',$comp->children[0]->name); + $this->assertEquals('value',$comp->children[0]->value); + + $this->assertEquals(1, count($comp->children[0]->parameters)); + + $this->assertTrue($comp->children[0]->parameters[0] instanceof Parameter); + $this->assertEquals('PARAM1',$comp->children[0]->parameters[0]->name); + $this->assertEquals('value1',$comp->children[0]->parameters[0]->value); + + } + + function testAddComponent() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); - $comp->add(new Sabre_VObject_Component('VEVENT')); + $comp->add(new Component('VEVENT')); $this->assertEquals(1, count($comp->children)); @@ -219,10 +242,10 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { function testAddComponentTwice() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); - $comp->add(new Sabre_VObject_Component('VEVENT')); - $comp->add(new Sabre_VObject_Component('VEVENT')); + $comp->add(new Component('VEVENT')); + $comp->add(new Component('VEVENT')); $this->assertEquals(2, count($comp->children)); @@ -235,8 +258,8 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { */ function testAddArgFail() { - $comp = new Sabre_VObject_Component('VCALENDAR'); - $comp->add(new Sabre_VObject_Component('VEVENT'),'hello'); + $comp = new Component('VCALENDAR'); + $comp->add(new Component('VEVENT'),'hello'); } @@ -245,7 +268,7 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { */ function testAddArgFail2() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); $comp->add(array()); } @@ -255,7 +278,7 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { */ function testAddArgFail3() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); $comp->add('hello',array()); } @@ -265,10 +288,10 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { */ function testMagicSetInvalid() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); // Note that 'myProp' is ignored here. - $comp->myProp = new StdClass(); + $comp->myProp = new \StdClass(); $this->assertEquals(1, count($comp->children)); @@ -278,8 +301,8 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { function testMagicUnset() { - $comp = new Sabre_VObject_Component('VCALENDAR'); - $comp->add(new Sabre_VObject_Component('VEVENT')); + $comp = new Component('VCALENDAR'); + $comp->add(new Component('VEVENT')); unset($comp->vevent); @@ -290,34 +313,34 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { function testCount() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); $this->assertEquals(1,$comp->count()); } function testChildren() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); // Note that 'myProp' is ignored here. $comp->children = array( - new Sabre_VObject_Component('VEVENT'), - new Sabre_VObject_Component('VTODO') + new Component('VEVENT'), + new Component('VTODO') ); $r = $comp->children(); - $this->assertTrue($r instanceof Sabre_VObject_ElementList); + $this->assertTrue($r instanceof ElementList); $this->assertEquals(2,count($r)); } function testGetComponents() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); // Note that 'myProp' is ignored here. $comp->children = array( - new Sabre_VObject_Property('FOO','BAR'), - new Sabre_VObject_Component('VTODO') + new Property('FOO','BAR'), + new Component('VTODO') ); $r = $comp->getComponents(); @@ -328,17 +351,17 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { function testSerialize() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); $this->assertEquals("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n", $comp->serialize()); } function testSerializeChildren() { - $comp = new Sabre_VObject_Component('VCALENDAR'); + $comp = new Component('VCALENDAR'); $comp->children = array( - new Sabre_VObject_Component('VEVENT'), - new Sabre_VObject_Component('VTODO') + new Component('VEVENT'), + new Component('VTODO') ); $str = $comp->serialize(); @@ -349,11 +372,11 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { function testSerializeOrderCompAndProp() { - $comp = new Sabre_VObject_Component('VCALENDAR'); - $comp->add(new Sabre_VObject_Component('VEVENT')); + $comp = new Component('VCALENDAR'); + $comp->add(new Component('VEVENT')); $comp->add('PROP1','BLABLA'); $comp->add('VERSION','2.0'); - $comp->add(new Sabre_VObject_Component('VTIMEZONE')); + $comp->add(new Component('VTIMEZONE')); $str = $comp->serialize(); @@ -365,7 +388,7 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase { $prop4s=array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10'); - $comp = new Sabre_VObject_Component('VCARD'); + $comp = new Component('VCARD'); $comp->__set('SOMEPROP','FOO'); $comp->__set('ANOTHERPROP','FOO'); $comp->__set('THIRDPROP','FOO'); diff --git a/dav/sabre-vobject/tests/Sabre/VObject/DateTimeParserTest.php b/dav/sabre-vobject/tests/Sabre/VObject/DateTimeParserTest.php new file mode 100644 index 000000000..463e7bcc2 --- /dev/null +++ b/dav/sabre-vobject/tests/Sabre/VObject/DateTimeParserTest.php @@ -0,0 +1,121 @@ +assertEquals('+1 weeks', DateTimeParser::parseDuration('P1W',true)); + $this->assertEquals('+5 days', DateTimeParser::parseDuration('P5D',true)); + $this->assertEquals('+5 days 3 hours 50 minutes 12 seconds', DateTimeParser::parseDuration('P5DT3H50M12S',true)); + $this->assertEquals('-1 weeks 50 minutes', DateTimeParser::parseDuration('-P1WT50M',true)); + $this->assertEquals('+50 days 3 hours 2 seconds', DateTimeParser::parseDuration('+P50DT3H2S',true)); + $this->assertEquals(new DateInterval('PT0S'), DateTimeParser::parseDuration('PT0S')); + + } + + function testParseICalendarDurationDateInterval() { + + $expected = new DateInterval('P7D'); + $this->assertEquals($expected, DateTimeParser::parseDuration('P1W')); + $this->assertEquals($expected, DateTimeParser::parse('P1W')); + + $expected = new DateInterval('PT3M'); + $expected->invert = true; + $this->assertEquals($expected, DateTimeParser::parseDuration('-PT3M')); + + } + + /** + * @expectedException LogicException + */ + function testParseICalendarDurationFail() { + + DateTimeParser::parseDuration('P1X',true); + + } + + function testParseICalendarDateTime() { + + $dateTime = DateTimeParser::parseDateTime('20100316T141405'); + + $compare = new DateTime('2010-03-16 14:14:05',new DateTimeZone('UTC')); + + $this->assertEquals($compare, $dateTime); + + } + + /** + * @depends testParseICalendarDateTime + * @expectedException LogicException + */ + function testParseICalendarDateTimeBadFormat() { + + $dateTime = DateTimeParser::parseDateTime('20100316T141405 '); + + } + + /** + * @depends testParseICalendarDateTime + */ + function testParseICalendarDateTimeUTC() { + + $dateTime = DateTimeParser::parseDateTime('20100316T141405Z'); + + $compare = new DateTime('2010-03-16 14:14:05',new DateTimeZone('UTC')); + $this->assertEquals($compare, $dateTime); + + } + + /** + * @depends testParseICalendarDateTime + */ + function testParseICalendarDateTimeUTC2() { + + $dateTime = DateTimeParser::parseDateTime('20101211T160000Z'); + + $compare = new DateTime('2010-12-11 16:00:00',new DateTimeZone('UTC')); + $this->assertEquals($compare, $dateTime); + + } + + /** + * @depends testParseICalendarDateTime + */ + function testParseICalendarDateTimeCustomTimeZone() { + + $dateTime = DateTimeParser::parseDateTime('20100316T141405', new DateTimeZone('Europe/Amsterdam')); + + $compare = new DateTime('2010-03-16 13:14:05',new DateTimeZone('UTC')); + $this->assertEquals($compare, $dateTime); + + } + + function testParseICalendarDate() { + + $dateTime = DateTimeParser::parseDate('20100316'); + + $expected = new DateTime('2010-03-16 00:00:00',new DateTimeZone('UTC')); + + $this->assertEquals($expected, $dateTime); + + $dateTime = DateTimeParser::parse('20100316'); + $this->assertEquals($expected, $dateTime); + + } + + /** + * @depends testParseICalendarDate + * @expectedException LogicException + */ + function testParseICalendarDateBadFormat() { + + $dateTime = DateTimeParser::parseDate('20100316T141405'); + + } +} diff --git a/dav/SabreDAV/tests/Sabre/VObject/ElementListTest.php b/dav/sabre-vobject/tests/Sabre/VObject/ElementListTest.php similarity index 55% rename from dav/SabreDAV/tests/Sabre/VObject/ElementListTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/ElementListTest.php index 5bc8b43c5..84e1bcbe9 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/ElementListTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/ElementListTest.php @@ -1,10 +1,12 @@ $subcomponent) { $count++; - $this->assertInstanceOf('Sabre_VObject_Component',$subcomponent); + $this->assertInstanceOf('Sabre\\VObject\\Component',$subcomponent); } $this->assertEquals(3,$count); diff --git a/dav/SabreDAV/tests/Sabre/VObject/EmClientTest.php b/dav/sabre-vobject/tests/Sabre/VObject/EmClientTest.php similarity index 81% rename from dav/SabreDAV/tests/Sabre/VObject/EmClientTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/EmClientTest.php index 69330230f..69d410fe7 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/EmClientTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/EmClientTest.php @@ -1,6 +1,8 @@ VEVENT->DTSTART->getDateTime(); - $this->assertEquals(new DateTime('2011-10-08 19:30:00', new DateTimeZone('America/Chicago')), $dt); + $this->assertEquals(new \DateTime('2011-10-08 19:30:00', new \DateTimeZone('America/Chicago')), $dt); } diff --git a/dav/SabreDAV/tests/Sabre/VObject/FreeBusyGeneratorTest.php b/dav/sabre-vobject/tests/Sabre/VObject/FreeBusyGeneratorTest.php similarity index 81% rename from dav/SabreDAV/tests/Sabre/VObject/FreeBusyGeneratorTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/FreeBusyGeneratorTest.php index d84f5a489..1f79e0a47 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/FreeBusyGeneratorTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/FreeBusyGeneratorTest.php @@ -1,6 +1,8 @@ setObjects($this->getInput()); - $gen->setTimeRange( - new DateTime('20110101T110000Z'), - new DateTime('20110103T110000Z') + $gen = new FreeBusyGenerator( + new \DateTime('20110101T110000Z', new \DateTimeZone('UTC')), + new \DateTime('20110103T110000Z', new \DateTimeZone('UTC')), + $this->getInput() ); $result = $gen->getResult(); @@ -216,10 +217,10 @@ ICS; function testGeneratorBaseObject() { - $obj = new Sabre_VObject_Component('VCALENDAR'); + $obj = new Component('VCALENDAR'); $obj->METHOD = 'PUBLISH'; - $gen = new Sabre_VObject_FreeBusyGenerator(); + $gen = new FreeBusyGenerator(); $gen->setObjects(array()); $gen->setBaseObject($obj); @@ -227,20 +228,6 @@ ICS; $this->assertEquals('PUBLISH', $result->METHOD->value); - } - function testGeneratorNoVersion() { - - $v = Sabre_DAV_Server::$exposeVersion; - Sabre_DAV_Server::$exposeVersion = false; - - $gen = new Sabre_VObject_FreeBusyGenerator(); - $gen->setObjects(array()); - - $result = $gen->getResult(); - Sabre_DAV_Server::$exposeVersion = $v; - - $this->assertFalse(strpos($result->PRODID->value, Sabre_VObject_Version::VERSION)); - } /** @@ -248,8 +235,11 @@ ICS; */ function testInvalidArg() { - $gen = new Sabre_VObject_FreeBusyGenerator(); - $gen->setObjects(array(new StdClass())); + $gen = new FreeBusyGenerator( + new \DateTime('2012-01-01'), + new \DateTime('2012-12-31'), + new \StdClass() + ); } diff --git a/dav/sabre-vobject/tests/Sabre/VObject/Issue153Test.php b/dav/sabre-vobject/tests/Sabre/VObject/Issue153Test.php new file mode 100644 index 000000000..1cc14c161 --- /dev/null +++ b/dav/sabre-vobject/tests/Sabre/VObject/Issue153Test.php @@ -0,0 +1,14 @@ +assertEquals('Test Benutzer', (string)$obj->fn); + + } + +} diff --git a/dav/SabreDAV/tests/Sabre/VObject/Issue154Test.php b/dav/sabre-vobject/tests/Sabre/VObject/Issue154Test.php similarity index 81% rename from dav/SabreDAV/tests/Sabre/VObject/Issue154Test.php rename to dav/sabre-vobject/tests/Sabre/VObject/Issue154Test.php index f5136be12..ed9c7c3f4 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/Issue154Test.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/Issue154Test.php @@ -1,10 +1,12 @@ VERSION = '3.0'; $vcard->PHOTO = base64_encode('random_stuff'); $vcard->PHOTO->add('BASE64',null); diff --git a/dav/SabreDAV/tests/Sabre/VObject/ParameterTest.php b/dav/sabre-vobject/tests/Sabre/VObject/ParameterTest.php similarity index 60% rename from dav/SabreDAV/tests/Sabre/VObject/ParameterTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/ParameterTest.php index ea3099718..150830459 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/ParameterTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/ParameterTest.php @@ -1,10 +1,12 @@ assertEquals('NAME',$param->name); $this->assertEquals('value',$param->value); @@ -12,7 +14,7 @@ class Sabre_VObject_ParameterTest extends PHPUnit_Framework_TestCase { function testCastToString() { - $param = new Sabre_VObject_Parameter('name','value'); + $param = new Parameter('name','value'); $this->assertEquals('value',$param->__toString()); $this->assertEquals('value',(string)$param); diff --git a/dav/SabreDAV/tests/Sabre/VObject/Property/DateTimeTest.php b/dav/sabre-vobject/tests/Sabre/VObject/Property/DateTimeTest.php similarity index 58% rename from dav/SabreDAV/tests/Sabre/VObject/Property/DateTimeTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/Property/DateTimeTest.php index d6a9830d3..9dc7e8610 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/Property/DateTimeTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/Property/DateTimeTest.php @@ -1,14 +1,17 @@ setTimeZone($tz); - $elem = new Sabre_VObject_Property_DateTime('DTSTART'); + $elem = new DateTime('DTSTART'); $elem->setDateTime($dt); $this->assertEquals('19850704T013000', $elem->value); @@ -19,12 +22,12 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase { function testSetDateTimeLOCAL() { - $tz = new DateTimeZone('Europe/Amsterdam'); - $dt = new DateTime('1985-07-04 01:30:00', $tz); + $tz = new \DateTimeZone('Europe/Amsterdam'); + $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); - $elem = new Sabre_VObject_Property_DateTime('DTSTART'); - $elem->setDateTime($dt, Sabre_VObject_Property_DateTime::LOCAL); + $elem = new DateTime('DTSTART'); + $elem->setDateTime($dt, DateTime::LOCAL); $this->assertEquals('19850704T013000', $elem->value); $this->assertNull($elem['TZID']); @@ -34,12 +37,12 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase { function testSetDateTimeUTC() { - $tz = new DateTimeZone('GMT'); - $dt = new DateTime('1985-07-04 01:30:00', $tz); + $tz = new \DateTimeZone('GMT'); + $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); - $elem = new Sabre_VObject_Property_DateTime('DTSTART'); - $elem->setDateTime($dt, Sabre_VObject_Property_DateTime::UTC); + $elem = new DateTime('DTSTART'); + $elem->setDateTime($dt, DateTime::UTC); $this->assertEquals('19850704T013000Z', $elem->value); $this->assertNull($elem['TZID']); @@ -49,12 +52,12 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase { function testSetDateTimeLOCALTZ() { - $tz = new DateTimeZone('Europe/Amsterdam'); - $dt = new DateTime('1985-07-04 01:30:00', $tz); + $tz = new \DateTimeZone('Europe/Amsterdam'); + $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); - $elem = new Sabre_VObject_Property_DateTime('DTSTART'); - $elem->setDateTime($dt, Sabre_VObject_Property_DateTime::LOCALTZ); + $elem = new DateTime('DTSTART'); + $elem->setDateTime($dt, DateTime::LOCALTZ); $this->assertEquals('19850704T013000', $elem->value); $this->assertEquals('Europe/Amsterdam', (string)$elem['TZID']); @@ -64,12 +67,12 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase { function testSetDateTimeDATE() { - $tz = new DateTimeZone('Europe/Amsterdam'); - $dt = new DateTime('1985-07-04 01:30:00', $tz); + $tz = new \DateTimeZone('Europe/Amsterdam'); + $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); - $elem = new Sabre_VObject_Property_DateTime('DTSTART'); - $elem->setDateTime($dt, Sabre_VObject_Property_DateTime::DATE); + $elem = new DateTime('DTSTART'); + $elem->setDateTime($dt, DateTime::DATE); $this->assertEquals('19850704', $elem->value); $this->assertNull($elem['TZID']); @@ -82,22 +85,22 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase { */ function testSetDateTimeInvalid() { - $tz = new DateTimeZone('Europe/Amsterdam'); - $dt = new DateTime('1985-07-04 01:30:00', $tz); + $tz = new \DateTimeZone('Europe/Amsterdam'); + $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); - $elem = new Sabre_VObject_Property_DateTime('DTSTART'); + $elem = new DateTime('DTSTART'); $elem->setDateTime($dt, 7); } function testGetDateTimeCached() { - $tz = new DateTimeZone('Europe/Amsterdam'); - $dt = new DateTime('1985-07-04 01:30:00', $tz); + $tz = new \DateTimeZone('Europe/Amsterdam'); + $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); - $elem = new Sabre_VObject_Property_DateTime('DTSTART'); + $elem = new DateTime('DTSTART'); $elem->setDateTime($dt); $this->assertEquals($elem->getDateTime(), $dt); @@ -106,7 +109,7 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase { function testGetDateTimeDateNULL() { - $elem = new Sabre_VObject_Property_DateTime('DTSTART'); + $elem = new DateTime('DTSTART'); $dt = $elem->getDateTime(); $this->assertNull($dt); @@ -116,42 +119,42 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase { function testGetDateTimeDateDATE() { - $elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704'); + $elem = new DateTime('DTSTART','19850704'); $dt = $elem->getDateTime(); $this->assertInstanceOf('DateTime', $dt); $this->assertEquals('1985-07-04 00:00:00', $dt->format('Y-m-d H:i:s')); - $this->assertEquals(Sabre_VObject_Property_DateTime::DATE, $elem->getDateType()); + $this->assertEquals(DateTime::DATE, $elem->getDateType()); } function testGetDateTimeDateLOCAL() { - $elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000'); + $elem = new DateTime('DTSTART','19850704T013000'); $dt = $elem->getDateTime(); $this->assertInstanceOf('DateTime', $dt); $this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); - $this->assertEquals(Sabre_VObject_Property_DateTime::LOCAL, $elem->getDateType()); + $this->assertEquals(DateTime::LOCAL, $elem->getDateType()); } function testGetDateTimeDateUTC() { - $elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000Z'); + $elem = new DateTime('DTSTART','19850704T013000Z'); $dt = $elem->getDateTime(); $this->assertInstanceOf('DateTime', $dt); $this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); $this->assertEquals('UTC', $dt->getTimeZone()->getName()); - $this->assertEquals(Sabre_VObject_Property_DateTime::UTC, $elem->getDateType()); + $this->assertEquals(DateTime::UTC, $elem->getDateType()); } function testGetDateTimeDateLOCALTZ() { - $elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000'); + $elem = new DateTime('DTSTART','19850704T013000'); $elem['TZID'] = 'Europe/Amsterdam'; $dt = $elem->getDateTime(); @@ -159,7 +162,7 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase { $this->assertInstanceOf('DateTime', $dt); $this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); $this->assertEquals('Europe/Amsterdam', $dt->getTimeZone()->getName()); - $this->assertEquals(Sabre_VObject_Property_DateTime::LOCALTZ, $elem->getDateType()); + $this->assertEquals(DateTime::LOCALTZ, $elem->getDateType()); } @@ -168,25 +171,25 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase { */ function testGetDateTimeDateInvalid() { - $elem = new Sabre_VObject_Property_DateTime('DTSTART','bla'); + $elem = new DateTime('DTSTART','bla'); $dt = $elem->getDateTime(); } function testGetDateTimeWeirdTZ() { - $elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000'); + $elem = new DateTime('DTSTART','19850704T013000'); $elem['TZID'] = '/freeassociation.sourceforge.net/Tzfile/Europe/Amsterdam'; - $event = new Sabre_VObject_Component('VEVENT'); + $event = new Component('VEVENT'); $event->add($elem); - $timezone = new Sabre_VObject_Component('VTIMEZONE'); + $timezone = new Component('VTIMEZONE'); $timezone->TZID = '/freeassociation.sourceforge.net/Tzfile/Europe/Amsterdam'; $timezone->{'X-LIC-LOCATION'} = 'Europe/Amsterdam'; - $calendar = new Sabre_VObject_Component('VCALENDAR'); + $calendar = new Component('VCALENDAR'); $calendar->add($event); $calendar->add($timezone); @@ -195,7 +198,7 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase { $this->assertInstanceOf('DateTime', $dt); $this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); $this->assertEquals('Europe/Amsterdam', $dt->getTimeZone()->getName()); - $this->assertEquals(Sabre_VObject_Property_DateTime::LOCALTZ, $elem->getDateType()); + $this->assertEquals(DateTime::LOCALTZ, $elem->getDateType()); } @@ -204,18 +207,18 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase { $default = date_default_timezone_get(); date_default_timezone_set('Canada/Eastern'); - $elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000'); + $elem = new DateTime('DTSTART','19850704T013000'); $elem['TZID'] = 'Moon'; - $event = new Sabre_VObject_Component('VEVENT'); + $event = new Component('VEVENT'); $event->add($elem); - $timezone = new Sabre_VObject_Component('VTIMEZONE'); + $timezone = new Component('VTIMEZONE'); $timezone->TZID = 'Moon'; $timezone->{'X-LIC-LOCATION'} = 'Moon'; - $calendar = new Sabre_VObject_Component('VCALENDAR'); + $calendar = new Component('VCALENDAR'); $calendar->add($event); $calendar->add($timezone); @@ -224,7 +227,7 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase { $this->assertInstanceOf('DateTime', $dt); $this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); $this->assertEquals('Canada/Eastern', $dt->getTimeZone()->getName()); - $this->assertEquals(Sabre_VObject_Property_DateTime::LOCALTZ, $elem->getDateType()); + $this->assertEquals(DateTime::LOCALTZ, $elem->getDateType()); date_default_timezone_set($default); } diff --git a/dav/SabreDAV/tests/Sabre/VObject/Property/MultiDateTimeTest.php b/dav/sabre-vobject/tests/Sabre/VObject/Property/MultiDateTimeTest.php similarity index 55% rename from dav/SabreDAV/tests/Sabre/VObject/Property/MultiDateTimeTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/Property/MultiDateTimeTest.php index 4d70ed3d7..eae3e2bb2 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/Property/MultiDateTimeTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/Property/MultiDateTimeTest.php @@ -1,16 +1,18 @@ setTimeZone($tz); $dt2->setTimeZone($tz); - $elem = new Sabre_VObject_Property_MultiDateTime('DTSTART'); + $elem = new MultiDateTime('DTSTART'); $elem->setDateTimes(array($dt1,$dt2)); $this->assertEquals('19850704T013000,19860704T013000', $elem->value); @@ -21,14 +23,14 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas function testSetDateTimeLOCAL() { - $tz = new DateTimeZone('Europe/Amsterdam'); - $dt1 = new DateTime('1985-07-04 01:30:00', $tz); - $dt2 = new DateTime('1986-07-04 01:30:00', $tz); + $tz = new \DateTimeZone('Europe/Amsterdam'); + $dt1 = new \DateTime('1985-07-04 01:30:00', $tz); + $dt2 = new \DateTime('1986-07-04 01:30:00', $tz); $dt1->setTimeZone($tz); $dt2->setTimeZone($tz); - $elem = new Sabre_VObject_Property_MultiDateTime('DTSTART'); - $elem->setDateTimes(array($dt1,$dt2), Sabre_VObject_Property_DateTime::LOCAL); + $elem = new MultiDateTime('DTSTART'); + $elem->setDateTimes(array($dt1,$dt2), DateTime::LOCAL); $this->assertEquals('19850704T013000,19860704T013000', $elem->value); $this->assertNull($elem['TZID']); @@ -38,14 +40,14 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas function testSetDateTimeUTC() { - $tz = new DateTimeZone('GMT'); - $dt1 = new DateTime('1985-07-04 01:30:00', $tz); - $dt2 = new DateTime('1986-07-04 01:30:00', $tz); + $tz = new \DateTimeZone('GMT'); + $dt1 = new \DateTime('1985-07-04 01:30:00', $tz); + $dt2 = new \DateTime('1986-07-04 01:30:00', $tz); $dt1->setTimeZone($tz); $dt2->setTimeZone($tz); - $elem = new Sabre_VObject_Property_MultiDateTime('DTSTART'); - $elem->setDateTimes(array($dt1,$dt2), Sabre_VObject_Property_DateTime::UTC); + $elem = new MultiDateTime('DTSTART'); + $elem->setDateTimes(array($dt1,$dt2), DateTime::UTC); $this->assertEquals('19850704T013000Z,19860704T013000Z', $elem->value); $this->assertNull($elem['TZID']); @@ -55,14 +57,14 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas function testSetDateTimeLOCALTZ() { - $tz = new DateTimeZone('Europe/Amsterdam'); - $dt1 = new DateTime('1985-07-04 01:30:00', $tz); - $dt2 = new DateTime('1986-07-04 01:30:00', $tz); + $tz = new \DateTimeZone('Europe/Amsterdam'); + $dt1 = new \DateTime('1985-07-04 01:30:00', $tz); + $dt2 = new \DateTime('1986-07-04 01:30:00', $tz); $dt1->setTimeZone($tz); $dt2->setTimeZone($tz); - $elem = new Sabre_VObject_Property_MultiDateTime('DTSTART'); - $elem->setDateTimes(array($dt1,$dt2), Sabre_VObject_Property_DateTime::LOCALTZ); + $elem = new MultiDateTime('DTSTART'); + $elem->setDateTimes(array($dt1,$dt2), DateTime::LOCALTZ); $this->assertEquals('19850704T013000,19860704T013000', $elem->value); $this->assertEquals('Europe/Amsterdam', (string)$elem['TZID']); @@ -72,14 +74,14 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas function testSetDateTimeDATE() { - $tz = new DateTimeZone('Europe/Amsterdam'); - $dt1 = new datetime('1985-07-04 01:30:00', $tz); - $dt2 = new datetime('1986-07-04 01:30:00', $tz); + $tz = new \DateTimeZone('Europe/Amsterdam'); + $dt1 = new \DateTime('1985-07-04 01:30:00', $tz); + $dt2 = new \DateTime('1986-07-04 01:30:00', $tz); $dt1->settimezone($tz); $dt2->settimezone($tz); - $elem = new Sabre_VObject_Property_MultiDateTime('DTSTART'); - $elem->setDateTimes(array($dt1,$dt2), Sabre_VObject_Property_DateTime::DATE); + $elem = new MultiDateTime('DTSTART'); + $elem->setDateTimes(array($dt1,$dt2), DateTime::DATE); $this->assertEquals('19850704,19860704', $elem->value); $this->assertNull($elem['TZID']); @@ -92,24 +94,24 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas */ function testSetDateTimeInvalid() { - $tz = new DateTimeZone('Europe/Amsterdam'); - $dt = new DateTime('1985-07-04 01:30:00', $tz); + $tz = new \DateTimeZone('Europe/Amsterdam'); + $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); - $elem = new Sabre_VObject_Property_MultiDateTime('DTSTART'); + $elem = new MultiDateTime('DTSTART'); $elem->setDateTimes(array($dt), 7); } function testGetDateTimeCached() { - $tz = new DateTimeZone('Europe/Amsterdam'); - $dt1 = new datetime('1985-07-04 01:30:00', $tz); - $dt2 = new datetime('1986-07-04 01:30:00', $tz); + $tz = new \DateTimeZone('Europe/Amsterdam'); + $dt1 = new \DateTime('1985-07-04 01:30:00', $tz); + $dt2 = new \DateTime('1986-07-04 01:30:00', $tz); $dt1->settimezone($tz); $dt2->settimezone($tz); - $elem = new Sabre_VObject_Property_MultiDateTime('DTSTART'); + $elem = new MultiDateTime('DTSTART'); $elem->setDateTimes(array($dt1,$dt2)); $this->assertEquals($elem->getDateTimes(), array($dt1,$dt2)); @@ -118,7 +120,7 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas function testGetDateTimeDateNULL() { - $elem = new Sabre_VObject_Property_MultiDateTime('DTSTART'); + $elem = new MultiDateTime('DTSTART'); $dt = $elem->getDateTimes(); $this->assertNull($dt); @@ -128,20 +130,20 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas function testGetDateTimeDateDATE() { - $elem = new Sabre_VObject_Property_MultiDateTime('DTSTART','19850704,19860704'); + $elem = new MultiDateTime('DTSTART','19850704,19860704'); $dt = $elem->getDateTimes(); $this->assertEquals('1985-07-04 00:00:00', $dt[0]->format('Y-m-d H:i:s')); $this->assertEquals('1986-07-04 00:00:00', $dt[1]->format('Y-m-d H:i:s')); - $this->assertEquals(Sabre_VObject_Property_DateTime::DATE, $elem->getDateType()); + $this->assertEquals(DateTime::DATE, $elem->getDateType()); } function testGetDateTimeDateDATEReverse() { - $elem = new Sabre_VObject_Property_MultiDateTime('DTSTART','19850704,19860704'); + $elem = new MultiDateTime('DTSTART','19850704,19860704'); - $this->assertEquals(Sabre_VObject_Property_DateTime::DATE, $elem->getDateType()); + $this->assertEquals(DateTime::DATE, $elem->getDateType()); $dt = $elem->getDateTimes(); $this->assertEquals('1985-07-04 00:00:00', $dt[0]->format('Y-m-d H:i:s')); @@ -152,30 +154,30 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas function testGetDateTimeDateLOCAL() { - $elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000'); + $elem = new DateTime('DTSTART','19850704T013000'); $dt = $elem->getDateTime(); $this->assertInstanceOf('DateTime', $dt); $this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); - $this->assertEquals(Sabre_VObject_Property_DateTime::LOCAL, $elem->getDateType()); + $this->assertEquals(DateTime::LOCAL, $elem->getDateType()); } function testGetDateTimeDateUTC() { - $elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000Z'); + $elem = new DateTime('DTSTART','19850704T013000Z'); $dt = $elem->getDateTime(); $this->assertInstanceOf('DateTime', $dt); $this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); $this->assertEquals('UTC', $dt->getTimeZone()->getName()); - $this->assertEquals(Sabre_VObject_Property_DateTime::UTC, $elem->getDateType()); + $this->assertEquals(DateTime::UTC, $elem->getDateType()); } function testGetDateTimeDateLOCALTZ() { - $elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000'); + $elem = new DateTime('DTSTART','19850704T013000'); $elem['TZID'] = 'Europe/Amsterdam'; $dt = $elem->getDateTime(); @@ -183,7 +185,7 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas $this->assertInstanceOf('DateTime', $dt); $this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); $this->assertEquals('Europe/Amsterdam', $dt->getTimeZone()->getName()); - $this->assertEquals(Sabre_VObject_Property_DateTime::LOCALTZ, $elem->getDateType()); + $this->assertEquals(DateTime::LOCALTZ, $elem->getDateType()); } @@ -192,7 +194,7 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas */ function testGetDateTimeDateInvalid() { - $elem = new Sabre_VObject_Property_DateTime('DTSTART','bla'); + $elem = new DateTime('DTSTART','bla'); $dt = $elem->getDateTime(); } diff --git a/dav/SabreDAV/tests/Sabre/VObject/PropertyTest.php b/dav/sabre-vobject/tests/Sabre/VObject/PropertyTest.php similarity index 57% rename from dav/SabreDAV/tests/Sabre/VObject/PropertyTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/PropertyTest.php index 40fb1468a..201646bb9 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/PropertyTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/PropertyTest.php @@ -1,10 +1,12 @@ assertEquals('PROPNAME', $property->name); $this->assertEquals('propvalue', $property->value); $this->assertEquals('propvalue', $property->__toString()); @@ -14,8 +16,8 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { public function testParameterExists() { - $property = new Sabre_VObject_Property('propname','propvalue'); - $property->parameters[] = new Sabre_VObject_Parameter('paramname','paramvalue'); + $property = new Property('propname','propvalue'); + $property->parameters[] = new Parameter('paramname','paramvalue'); $this->assertTrue(isset($property['PARAMNAME'])); $this->assertTrue(isset($property['paramname'])); @@ -25,17 +27,17 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { public function testParameterGet() { - $property = new Sabre_VObject_Property('propname','propvalue'); - $property->parameters[] = new Sabre_VObject_Parameter('paramname','paramvalue'); + $property = new Property('propname','propvalue'); + $property->parameters[] = new Parameter('paramname','paramvalue'); - $this->assertInstanceOf('Sabre_VObject_Parameter',$property['paramname']); + $this->assertInstanceOf('Sabre\\VObject\\Parameter',$property['paramname']); } public function testParameterNotExists() { - $property = new Sabre_VObject_Property('propname','propvalue'); - $property->parameters[] = new Sabre_VObject_Parameter('paramname','paramvalue'); + $property = new Property('propname','propvalue'); + $property->parameters[] = new Parameter('paramname','paramvalue'); $this->assertInternalType('null',$property['foo']); @@ -43,22 +45,22 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { public function testParameterMultiple() { - $property = new Sabre_VObject_Property('propname','propvalue'); - $property->parameters[] = new Sabre_VObject_Parameter('paramname','paramvalue'); - $property->parameters[] = new Sabre_VObject_Parameter('paramname','paramvalue'); + $property = new Property('propname','propvalue'); + $property->parameters[] = new Parameter('paramname','paramvalue'); + $property->parameters[] = new Parameter('paramname','paramvalue'); - $this->assertInstanceOf('Sabre_VObject_Parameter',$property['paramname']); + $this->assertInstanceOf('Sabre\\VObject\\Parameter',$property['paramname']); $this->assertEquals(2,count($property['paramname'])); } public function testSetParameterAsString() { - $property = new Sabre_VObject_Property('propname','propvalue'); + $property = new Property('propname','propvalue'); $property['paramname'] = 'paramvalue'; $this->assertEquals(1,count($property->parameters)); - $this->assertInstanceOf('Sabre_VObject_Parameter', $property->parameters[0]); + $this->assertInstanceOf('Sabre\\VObject\\Parameter', $property->parameters[0]); $this->assertEquals('PARAMNAME',$property->parameters[0]->name); $this->assertEquals('paramvalue',$property->parameters[0]->value); @@ -69,15 +71,15 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { */ public function testSetParameterAsStringNoKey() { - $property = new Sabre_VObject_Property('propname','propvalue'); + $property = new Property('propname','propvalue'); $property[] = 'paramvalue'; } public function testSetParameterObject() { - $property = new Sabre_VObject_Property('propname','propvalue'); - $param = new Sabre_VObject_Parameter('paramname','paramvalue'); + $property = new Property('propname','propvalue'); + $param = new Parameter('paramname','paramvalue'); $property[] = $param; @@ -91,8 +93,8 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { */ public function testSetParameterObjectWithKey() { - $property = new Sabre_VObject_Property('propname','propvalue'); - $param = new Sabre_VObject_Parameter('paramname','paramvalue'); + $property = new Property('propname','propvalue'); + $param = new Parameter('paramname','paramvalue'); $property['key'] = $param; @@ -104,15 +106,15 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { */ public function testSetParameterObjectRandomObject() { - $property = new Sabre_VObject_Property('propname','propvalue'); - $property[] = new StdClass(); + $property = new Property('propname','propvalue'); + $property[] = new \StdClass(); } public function testUnsetParameter() { - $property = new Sabre_VObject_Property('propname','propvalue'); - $param = new Sabre_VObject_Parameter('paramname','paramvalue'); + $property = new Property('propname','propvalue'); + $param = new Parameter('paramname','paramvalue'); $property->parameters[] = $param; unset($property['PARAMNAME']); @@ -122,8 +124,8 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { public function testParamCount() { - $property = new Sabre_VObject_Property('propname','propvalue'); - $param = new Sabre_VObject_Parameter('paramname','paramvalue'); + $property = new Property('propname','propvalue'); + $param = new Parameter('paramname','paramvalue'); $property->parameters[] = $param; $property->parameters[] = clone $param; @@ -133,7 +135,7 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { public function testSerialize() { - $property = new Sabre_VObject_Property('propname','propvalue'); + $property = new Property('propname','propvalue'); $this->assertEquals("PROPNAME:propvalue\r\n",$property->serialize()); @@ -141,9 +143,9 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { public function testSerializeParam() { - $property = new Sabre_VObject_Property('propname','propvalue'); - $property->parameters[] = new Sabre_VObject_Parameter('paramname','paramvalue'); - $property->parameters[] = new Sabre_VObject_Parameter('paramname2','paramvalue2'); + $property = new Property('propname','propvalue'); + $property->parameters[] = new Parameter('paramname','paramvalue'); + $property->parameters[] = new Parameter('paramname2','paramvalue2'); $this->assertEquals("PROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propvalue\r\n",$property->serialize()); @@ -151,7 +153,7 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { public function testSerializeNewLine() { - $property = new Sabre_VObject_Property('propname',"line1\nline2"); + $property = new Property('propname',"line1\nline2"); $this->assertEquals("PROPNAME:line1\\nline2\r\n",$property->serialize()); @@ -160,7 +162,7 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { public function testSerializeLongLine() { $value = str_repeat('!',200); - $property = new Sabre_VObject_Property('propname',$value); + $property = new Property('propname',$value); $expected = "PROPNAME:" . str_repeat('!',66) . "\r\n " . str_repeat('!',74) . "\r\n " . str_repeat('!',60) . "\r\n"; @@ -171,7 +173,7 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { public function testSerializeUTF8LineFold() { $value = str_repeat('!',65) . "\xc3\xa4bla"; // inserted umlaut-a - $property = new Sabre_VObject_Property('propname', $value); + $property = new Property('propname', $value); $expected = "PROPNAME:" . str_repeat('!',65) . "\r\n \xc3\xa4bla\r\n"; $this->assertEquals($expected, $property->serialize()); @@ -179,8 +181,9 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { public function testGetIterator() { - $it = new Sabre_VObject_ElementList(array()); - $property = new Sabre_VObject_Property('propname','propvalue', $it); + $it = new ElementList(array()); + $property = new Property('propname','propvalue'); + $property->setIterator($it); $this->assertEquals($it,$property->getIterator()); } @@ -188,22 +191,22 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { public function testGetIteratorDefault() { - $property = new Sabre_VObject_Property('propname','propvalue'); + $property = new Property('propname','propvalue'); $it = $property->getIterator(); - $this->assertTrue($it instanceof Sabre_VObject_ElementList); + $this->assertTrue($it instanceof ElementList); $this->assertEquals(1,count($it)); } function testAddScalar() { - $property = new Sabre_VObject_Property('EMAIL'); + $property = new Property('EMAIL'); $property->add('myparam','value'); $this->assertEquals(1, count($property->parameters)); - $this->assertTrue($property->parameters[0] instanceof Sabre_VObject_Parameter); + $this->assertTrue($property->parameters[0] instanceof Parameter); $this->assertEquals('MYPARAM',$property->parameters[0]->name); $this->assertEquals('value',$property->parameters[0]->value); @@ -211,9 +214,9 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { function testAddParameter() { - $prop = new Sabre_VObject_Property('EMAIL'); + $prop = new Property('EMAIL'); - $prop->add(new Sabre_VObject_Parameter('MYPARAM','value')); + $prop->add(new Parameter('MYPARAM','value')); $this->assertEquals(1, count($prop->parameters)); $this->assertEquals('MYPARAM',$prop['myparam']->name); @@ -222,10 +225,10 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { function testAddParameterTwice() { - $prop = new Sabre_VObject_Property('EMAIL'); + $prop = new Property('EMAIL'); - $prop->add(new Sabre_VObject_Parameter('MYPARAM', 'value1')); - $prop->add(new Sabre_VObject_Parameter('MYPARAM', 'value2')); + $prop->add(new Parameter('MYPARAM', 'value1')); + $prop->add(new Parameter('MYPARAM', 'value2')); $this->assertEquals(2, count($prop->parameters)); @@ -238,8 +241,8 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { */ function testAddArgFail() { - $prop = new Sabre_VObject_Property('EMAIL'); - $prop->add(new Sabre_VObject_Parameter('MPARAM'),'hello'); + $prop = new Property('EMAIL'); + $prop->add(new Parameter('MPARAM'),'hello'); } @@ -248,7 +251,7 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { */ function testAddArgFail2() { - $property = new Sabre_VObject_Property('EMAIL','value'); + $property = new Property('EMAIL','value'); $property->add(array()); } @@ -258,14 +261,14 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { */ function testAddArgFail3() { - $property = new Sabre_VObject_Property('EMAIL','value'); + $property = new Property('EMAIL','value'); $property->add('hello',array()); } function testClone() { - $property = new Sabre_VObject_Property('EMAIL','value'); + $property = new Property('EMAIL','value'); $property['FOO'] = 'BAR'; $property2 = clone $property; @@ -275,4 +278,16 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase { } + function testCreateParams() { + + $property = Property::create('X-PROP', 'value', array( + 'param1' => 'value1', + 'param2' => array('value2', 'value3') + )); + + $this->assertEquals(1, count($property['PARAM1'])); + $this->assertEquals(2, count($property['PARAM2'])); + + } + } diff --git a/dav/SabreDAV/tests/Sabre/VObject/ReaderTest.php b/dav/sabre-vobject/tests/Sabre/VObject/ReaderTest.php similarity index 70% rename from dav/SabreDAV/tests/Sabre/VObject/ReaderTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/ReaderTest.php index a87651cdc..998ff6204 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/ReaderTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/ReaderTest.php @@ -1,14 +1,16 @@ assertInstanceOf('Sabre_VObject_Component', $result); + $this->assertInstanceOf('Sabre\\VObject\\Component', $result); $this->assertEquals('VCALENDAR', $result->name); $this->assertEquals(0, count($result->children)); @@ -18,9 +20,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { $data = "BEGIN:VCALENDAR\nEND:VCALENDAR"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Component', $result); + $this->assertInstanceOf('Sabre\\VObject\\Component', $result); $this->assertEquals('VCALENDAR', $result->name); $this->assertEquals(0, count($result->children)); @@ -30,9 +32,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { $data = "BEGIN:VCALENDAR\rEND:VCALENDAR"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Component', $result); + $this->assertInstanceOf('Sabre\\VObject\\Component', $result); $this->assertEquals('VCALENDAR', $result->name); $this->assertEquals(0, count($result->children)); @@ -42,31 +44,31 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { $data = "BEGIN:\r\n\tVCALENDAR\r\nE\r\n ND:VCALENDAR"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Component', $result); + $this->assertInstanceOf('Sabre\\VObject\\Component', $result); $this->assertEquals('VCALENDAR', $result->name); $this->assertEquals(0, count($result->children)); } /** - * @expectedException Sabre_VObject_ParseException + * @expectedException Sabre\VObject\ParseException */ function testReadCorruptComponent() { $data = "BEGIN:VCALENDAR\r\nEND:FOO"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); } function testReadProperty() { $data = "PROPNAME:propValue"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Property', $result); + $this->assertInstanceOf('Sabre\\VObject\\Property', $result); $this->assertEquals('PROPNAME', $result->name); $this->assertEquals('propValue', $result->value); @@ -75,9 +77,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { function testReadPropertyWithNewLine() { $data = 'PROPNAME:Line1\\nLine2\\NLine3\\\\Not the 4th line!'; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Property', $result); + $this->assertInstanceOf('Sabre\\VObject\\Property', $result); $this->assertEquals('PROPNAME', $result->name); $this->assertEquals("Line1\nLine2\nLine3\\Not the 4th line!", $result->value); @@ -86,9 +88,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { function testReadMappedProperty() { $data = "DTSTART:20110529"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Property_DateTime', $result); + $this->assertInstanceOf('Sabre\\VObject\\Property\\DateTime', $result); $this->assertEquals('DTSTART', $result->name); $this->assertEquals('20110529', $result->value); @@ -97,9 +99,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { function testReadMappedPropertyGrouped() { $data = "foo.DTSTART:20110529"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Property_DateTime', $result); + $this->assertInstanceOf('Sabre\\VObject\\Property\\DateTime', $result); $this->assertEquals('DTSTART', $result->name); $this->assertEquals('20110529', $result->value); @@ -107,12 +109,12 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { /** - * @expectedException Sabre_VObject_ParseException + * @expectedException Sabre\VObject\ParseException */ function testReadBrokenLine() { $data = "PROPNAME;propValue"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); } @@ -124,12 +126,12 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { "END:VCALENDAR" ); - $result = Sabre_VObject_Reader::read(implode("\r\n",$data)); + $result = Reader::read(implode("\r\n",$data)); - $this->assertInstanceOf('Sabre_VObject_Component', $result); + $this->assertInstanceOf('Sabre\\VObject\\Component', $result); $this->assertEquals('VCALENDAR', $result->name); $this->assertEquals(1, count($result->children)); - $this->assertInstanceOf('Sabre_VObject_Property', $result->children[0]); + $this->assertInstanceOf('Sabre\\VObject\\Property', $result->children[0]); $this->assertEquals('PROPNAME', $result->children[0]->name); $this->assertEquals('propValue', $result->children[0]->value); @@ -146,15 +148,15 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { "END:VCALENDAR" ); - $result = Sabre_VObject_Reader::read(implode("\r\n",$data)); + $result = Reader::read(implode("\r\n",$data)); - $this->assertInstanceOf('Sabre_VObject_Component', $result); + $this->assertInstanceOf('Sabre\\VObject\\Component', $result); $this->assertEquals('VCALENDAR', $result->name); $this->assertEquals(1, count($result->children)); - $this->assertInstanceOf('Sabre_VObject_Component', $result->children[0]); + $this->assertInstanceOf('Sabre\\VObject\\Component', $result->children[0]); $this->assertEquals('VTIMEZONE', $result->children[0]->name); $this->assertEquals(1, count($result->children[0]->children)); - $this->assertInstanceOf('Sabre_VObject_Component', $result->children[0]->children[0]); + $this->assertInstanceOf('Sabre\\VObject\\Component', $result->children[0]->children[0]); $this->assertEquals('DAYLIGHT', $result->children[0]->children[0]->name); @@ -163,9 +165,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { function testReadPropertyParameter() { $data = "PROPNAME;PARAMNAME=paramvalue:propValue"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Property', $result); + $this->assertInstanceOf('Sabre\\VObject\\Property', $result); $this->assertEquals('PROPNAME', $result->name); $this->assertEquals('propValue', $result->value); $this->assertEquals(1, count($result->parameters)); @@ -177,9 +179,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { function testReadPropertyNoValue() { $data = "PROPNAME;PARAMNAME:propValue"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Property', $result); + $this->assertInstanceOf('Sabre\\VObject\\Property', $result); $this->assertEquals('PROPNAME', $result->name); $this->assertEquals('propValue', $result->value); $this->assertEquals(1, count($result->parameters)); @@ -191,9 +193,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { function testReadPropertyParameterExtraColon() { $data = "PROPNAME;PARAMNAME=paramvalue:propValue:anotherrandomstring"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Property', $result); + $this->assertInstanceOf('Sabre\\VObject\\Property', $result); $this->assertEquals('PROPNAME', $result->name); $this->assertEquals('propValue:anotherrandomstring', $result->value); $this->assertEquals(1, count($result->parameters)); @@ -205,9 +207,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { function testReadProperty2Parameters() { $data = "PROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propValue"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Property', $result); + $this->assertInstanceOf('Sabre\\VObject\\Property', $result); $this->assertEquals('PROPNAME', $result->name); $this->assertEquals('propValue', $result->value); $this->assertEquals(2, count($result->parameters)); @@ -221,9 +223,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { function testReadPropertyParameterQuoted() { $data = "PROPNAME;PARAMNAME=\"paramvalue\":propValue"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Property', $result); + $this->assertInstanceOf('Sabre\\VObject\\Property', $result); $this->assertEquals('PROPNAME', $result->name); $this->assertEquals('propValue', $result->value); $this->assertEquals(1, count($result->parameters)); @@ -234,9 +236,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { function testReadPropertyParameterNewLines() { $data = "PROPNAME;PARAMNAME=paramvalue1\\nvalue2\\\\nvalue3:propValue"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Property', $result); + $this->assertInstanceOf('Sabre\\VObject\\Property', $result); $this->assertEquals('PROPNAME', $result->name); $this->assertEquals('propValue', $result->value); @@ -249,9 +251,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase { function testReadPropertyParameterQuotedColon() { $data = "PROPNAME;PARAMNAME=\"param:value\":propValue"; - $result = Sabre_VObject_Reader::read($data); + $result = Reader::read($data); - $this->assertInstanceOf('Sabre_VObject_Property', $result); + $this->assertInstanceOf('Sabre\\VObject\\Property', $result); $this->assertEquals('PROPNAME', $result->name); $this->assertEquals('propValue', $result->value); $this->assertEquals(1, count($result->parameters)); diff --git a/dav/SabreDAV/tests/Sabre/VObject/RecurrenceIteratorFifthTuesdayProblemTest.php b/dav/sabre-vobject/tests/Sabre/VObject/RecurrenceIteratorFifthTuesdayProblemTest.php similarity index 75% rename from dav/SabreDAV/tests/Sabre/VObject/RecurrenceIteratorFifthTuesdayProblemTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/RecurrenceIteratorFifthTuesdayProblemTest.php index 75972c2a0..ffcb6ee71 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/RecurrenceIteratorFifthTuesdayProblemTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/RecurrenceIteratorFifthTuesdayProblemTest.php @@ -1,6 +1,8 @@ VEVENT->UID); + $vObject = Reader::read($ics); + $it = new RecurrenceIterator($vObject, (string)$vObject->VEVENT->UID); while($it->valid()) { $it->next(); diff --git a/dav/SabreDAV/tests/Sabre/VObject/RecurrenceIteratorInfiniteLoopProblemTest.php b/dav/sabre-vobject/tests/Sabre/VObject/RecurrenceIteratorInfiniteLoopProblemTest.php similarity index 83% rename from dav/SabreDAV/tests/Sabre/VObject/RecurrenceIteratorInfiniteLoopProblemTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/RecurrenceIteratorInfiniteLoopProblemTest.php index 150625095..3976388be 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/RecurrenceIteratorInfiniteLoopProblemTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/RecurrenceIteratorInfiniteLoopProblemTest.php @@ -1,6 +1,11 @@ DTSTART = '20090420T180000Z'; $ev->RRULE = 'FREQ=WEEKLY;BYDAY=MO;UNTIL=20090704T205959Z;INTERVAL=1'; @@ -21,7 +26,7 @@ class Sabre_VObject_RecurrenceIteratorInfiniteLoopProblemTest extends PHPUnit_Fr */ function testYearlyByMonthLoop() { - $ev = Sabre_VObject_Component::create('VEVENT'); + $ev = Component::create('VEVENT'); $ev->UID = 'uuid'; $ev->DTSTART = '20120101T154500'; $ev->DTSTART['TZID'] = 'Europe/Berlin'; @@ -35,10 +40,10 @@ class Sabre_VObject_RecurrenceIteratorInfiniteLoopProblemTest extends PHPUnit_Fr // The BYDAY part expands this to every day of the month, but the // BYSETPOS limits this to only the 1st day of the month. Very crazy // way to specify this, and could have certainly been a lot easier. - $cal = Sabre_VObject_Component::create('VCALENDAR'); + $cal = Component::create('VCALENDAR'); $cal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($cal,'uuid'); + $it = new RecurrenceIterator($cal,'uuid'); $it->fastForward(new DateTime('2012-01-29 23:00:00', new DateTimeZone('UTC'))); $collect = array(); diff --git a/dav/SabreDAV/tests/Sabre/VObject/RecurrenceIteratorTest.php b/dav/sabre-vobject/tests/Sabre/VObject/RecurrenceIteratorTest.php similarity index 75% rename from dav/SabreDAV/tests/Sabre/VObject/RecurrenceIteratorTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/RecurrenceIteratorTest.php index 0bb42bb87..c79ac689c 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/RecurrenceIteratorTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/RecurrenceIteratorTest.php @@ -1,21 +1,26 @@ UID = 'bla'; $ev->RRULE = 'FREQ=DAILY;BYHOUR=10;BYMINUTE=5;BYSECOND=16;BYWEEKNO=32;BYYEARDAY=100,200'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-10-07'),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals(array(10), $it->byHour); $this->assertEquals(array(5), $it->byMinute); @@ -31,17 +36,17 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testInvalidFreq() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->RRULE = 'FREQ=SMONTHLY;INTERVAL=3;UNTIL=20111025T000000Z'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-10-07'),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); } @@ -50,8 +55,8 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testVCalendarNoUID() { - $vcal = new Sabre_VObject_Component('VCALENDAR'); - $it = new Sabre_VObject_RecurrenceIterator($vcal); + $vcal = new Component('VCALENDAR'); + $it = new RecurrenceIterator($vcal); } @@ -60,8 +65,8 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testVCalendarInvalidUID() { - $vcal = new Sabre_VObject_Component('VCALENDAR'); - $it = new Sabre_VObject_RecurrenceIterator($vcal,'foo'); + $vcal = new Component('VCALENDAR'); + $it = new RecurrenceIterator($vcal,'foo'); } @@ -70,18 +75,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testDaily() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=DAILY;INTERVAL=3;UNTIL=20111025T000000Z'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,$ev->uid); + $it = new RecurrenceIterator($vcal,$ev->uid); $this->assertEquals('daily', $it->frequency); $this->assertEquals(3, $it->interval); @@ -121,17 +126,17 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testNoRRULE() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,$ev->uid); + $it = new RecurrenceIterator($vcal,$ev->uid); $this->assertEquals('daily', $it->frequency); $this->assertEquals(1, $it->interval); @@ -164,18 +169,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testDailyByDay() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=DAILY;INTERVAL=2;BYDAY=TU,WE,FR'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('daily', $it->frequency); $this->assertEquals(2, $it->interval); @@ -220,18 +225,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testWeekly() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;COUNT=10'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('weekly', $it->frequency); $this->assertEquals(2, $it->interval); @@ -274,18 +279,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testWeeklyByDay() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('weekly', $it->frequency); $this->assertEquals(2, $it->interval); @@ -331,18 +336,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testMonthly() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=3;COUNT=5'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-12-05'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-12-05', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('monthly', $it->frequency); $this->assertEquals(3, $it->interval); @@ -380,18 +385,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testMonthlyEndOfMonth() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=12'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-12-31'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-12-31', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('monthly', $it->frequency); $this->assertEquals(2, $it->interval); @@ -436,18 +441,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testMonthlyByMonthDay() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=5;COUNT=9;BYMONTHDAY=1,31,-7'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-01-01'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-01-01', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('monthly', $it->frequency); $this->assertEquals(5, $it->interval); @@ -489,18 +494,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testMonthlyByDay() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=16;BYDAY=MO,-2TU,+1WE,3TH'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-01-03'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-01-03', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('monthly', $it->frequency); $this->assertEquals(2, $it->interval); @@ -549,18 +554,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testMonthlyByDayByMonthDay() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO;BYMONTHDAY=1'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-08-01'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-08-01', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('monthly', $it->frequency); $this->assertEquals(1, $it->interval); @@ -604,18 +609,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testMonthlyByDayBySetPos() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-01-03'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-01-03', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('monthly', $it->frequency); $this->assertEquals(1, $it->interval); @@ -659,18 +664,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testYearly() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=10;INTERVAL=3'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-01-01'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-01-01', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('yearly', $it->frequency); $this->assertEquals(3, $it->interval); @@ -712,18 +717,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testYearlyLeapYear() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=3'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2012-02-29'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2012-02-29', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('yearly', $it->frequency); $this->assertEquals(3, $it->count); @@ -757,18 +762,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testYearlyByMonth() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYMONTH=4,10'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-04-07'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-04-07', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('yearly', $it->frequency); $this->assertEquals(4, $it->interval); @@ -809,18 +814,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testYearlyByMonthByDay() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-04-04'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-04-04', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('yearly', $it->frequency); $this->assertEquals(5, $it->interval); @@ -862,22 +867,22 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testFastForward() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); - $dtStart->setDateTime(new DateTime('2011-04-04'),Sabre_VObject_Property_DateTime::UTC); + $dtStart = new Property\DateTime('DTSTART'); + $dtStart->setDateTime(new DateTime('2011-04-04', new DateTimeZone('UTC')),Property\DateTime::UTC); $ev->add($dtStart); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); // The idea is that we're fast-forwarding too far in the future, so // there will be no results left. - $it->fastForward(new DateTime('2020-05-05')); + $it->fastForward(new DateTime('2020-05-05', new DateTimeZone('UTC'))); $max = 20; $result = array(); @@ -901,27 +906,27 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testComplexExclusions() { - $ev = new Sabre_VObject_Component('VEVENT'); + $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=10'; - $dtStart = new Sabre_VObject_Property_DateTime('DTSTART'); + $dtStart = new Property\DateTime('DTSTART'); $tz = new DateTimeZone('Canada/Eastern'); - $dtStart->setDateTime(new DateTime('2011-01-01 13:50:20', $tz),Sabre_VObject_Property_DateTime::LOCALTZ); + $dtStart->setDateTime(new DateTime('2011-01-01 13:50:20', $tz),Property\DateTime::LOCALTZ); - $exDate1 = new Sabre_VObject_Property_MultiDateTime('EXDATE'); - $exDate1->setDateTimes(array(new DateTime('2012-01-01 13:50:20', $tz), new DateTime('2014-01-01 13:50:20', $tz)), Sabre_VObject_Property_DateTime::LOCALTZ); - $exDate2 = new Sabre_VObject_Property_MultiDateTime('EXDATE'); - $exDate2->setDateTimes(array(new DateTime('2016-01-01 13:50:20', $tz)), Sabre_VObject_Property_DateTime::LOCALTZ); + $exDate1 = new Property\MultiDateTime('EXDATE'); + $exDate1->setDateTimes(array(new DateTime('2012-01-01 13:50:20', $tz), new DateTime('2014-01-01 13:50:20', $tz)), Property\DateTime::LOCALTZ); + $exDate2 = new Property\MultiDateTime('EXDATE'); + $exDate2->setDateTimes(array(new DateTime('2016-01-01 13:50:20', $tz)), Property\DateTime::LOCALTZ); $ev->add($dtStart); $ev->add($exDate1); $ev->add($exDate2); - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); $vcal->add($ev); - $it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid); + $it = new RecurrenceIterator($vcal,(string)$ev->uid); $this->assertEquals('yearly', $it->frequency); $this->assertEquals(1, $it->interval); @@ -958,9 +963,9 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testOverridenEvent() { - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); - $ev1 = Sabre_VObject_Component::create('VEVENT'); + $ev1 = Component::create('VEVENT'); $ev1->UID = 'overridden'; $ev1->RRULE = 'FREQ=DAILY;COUNT=10'; $ev1->DTSTART = '20120107T120000Z'; @@ -969,7 +974,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { $vcal->add($ev1); // ev2 overrides an event, and puts it on 2pm instead. - $ev2 = Sabre_VObject_Component::create('VEVENT'); + $ev2 = Component::create('VEVENT'); $ev2->UID = 'overridden'; $ev2->{'RECURRENCE-ID'} = '20120110T120000Z'; $ev2->DTSTART = '20120110T140000Z'; @@ -978,7 +983,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { $vcal->add($ev2); // ev3 overrides an event, and puts it 2 days and 2 hours later - $ev3 = Sabre_VObject_Component::create('VEVENT'); + $ev3 = Component::create('VEVENT'); $ev3->UID = 'overridden'; $ev3->{'RECURRENCE-ID'} = '20120113T120000Z'; $ev3->DTSTART = '20120115T140000Z'; @@ -986,7 +991,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { $vcal->add($ev3); - $it = new Sabre_VObject_RecurrenceIterator($vcal,'overridden'); + $it = new RecurrenceIterator($vcal,'overridden'); $dates = array(); $summaries = array(); @@ -1032,9 +1037,9 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testOverridenEvent2() { - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); - $ev1 = Sabre_VObject_Component::create('VEVENT'); + $ev1 = Component::create('VEVENT'); $ev1->UID = 'overridden'; $ev1->RRULE = 'FREQ=WEEKLY;COUNT=3'; $ev1->DTSTART = '20120112T120000Z'; @@ -1043,7 +1048,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { $vcal->add($ev1); // ev2 overrides an event, and puts it 6 days earlier instead. - $ev2 = Sabre_VObject_Component::create('VEVENT'); + $ev2 = Component::create('VEVENT'); $ev2->UID = 'overridden'; $ev2->{'RECURRENCE-ID'} = '20120119T120000Z'; $ev2->DTSTART = '20120113T120000Z'; @@ -1051,7 +1056,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { $vcal->add($ev2); - $it = new Sabre_VObject_RecurrenceIterator($vcal,'overridden'); + $it = new RecurrenceIterator($vcal,'overridden'); $dates = array(); $summaries = array(); @@ -1084,9 +1089,9 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { */ function testOverridenEventNoValuesExpected() { - $vcal = Sabre_VObject_Component::create('VCALENDAR'); + $vcal = Component::create('VCALENDAR'); - $ev1 = Sabre_VObject_Component::create('VEVENT'); + $ev1 = Component::create('VEVENT'); $ev1->UID = 'overridden'; $ev1->RRULE = 'FREQ=WEEKLY;COUNT=3'; $ev1->DTSTART = '20120124T120000Z'; @@ -1095,7 +1100,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { $vcal->add($ev1); // ev2 overrides an event, and puts it 6 days earlier instead. - $ev2 = Sabre_VObject_Component::create('VEVENT'); + $ev2 = Component::create('VEVENT'); $ev2->UID = 'overridden'; $ev2->{'RECURRENCE-ID'} = '20120131T120000Z'; $ev2->DTSTART = '20120125T120000Z'; @@ -1103,7 +1108,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase { $vcal->add($ev2); - $it = new Sabre_VObject_RecurrenceIterator($vcal,'overridden'); + $it = new RecurrenceIterator($vcal,'overridden'); $dates = array(); $summaries = array(); diff --git a/dav/SabreDAV/tests/Sabre/VObject/TimeZoneUtilTest.php b/dav/sabre-vobject/tests/Sabre/VObject/TimeZoneUtilTest.php similarity index 76% rename from dav/SabreDAV/tests/Sabre/VObject/TimeZoneUtilTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/TimeZoneUtilTest.php index be8cd49c3..1f13ccbc3 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/TimeZoneUtilTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/TimeZoneUtilTest.php @@ -1,13 +1,15 @@ assertEquals(new DateTimeZone('Europe/Sarajevo'), $tz); + $this->assertEquals(new \DateTimeZone('Europe/Sarajevo'), $tz); } @@ -99,16 +101,16 @@ END:VEVENT END:VCALENDAR HI; - $tz = Sabre_VObject_TimeZoneUtil::getTimeZone('foo', Sabre_VObject_Reader::read($vobj)); + $tz = TimeZoneUtil::getTimeZone('foo', Reader::read($vobj)); - $this->assertEquals(new DateTimeZone(date_default_timezone_get()), $tz); + $this->assertEquals(new \DateTimeZone(date_default_timezone_get()), $tz); } function testWindowsTimeZone() { - $tz = Sabre_VObject_TimeZoneUtil::getTimeZone('Eastern Standard Time'); - $this->assertEquals(new DateTimeZone('America/New_York'), $tz); + $tz = TimeZoneUtil::getTimeZone('Eastern Standard Time'); + $this->assertEquals(new \DateTimeZone('America/New_York'), $tz); } @@ -144,9 +146,9 @@ UID:040000008200E00074C5B7101A82E0080000000010DA091DC31BCD01000000000000000 END:VEVENT END:VCALENDAR HI; - $tz = Sabre_VObject_TimeZoneUtil::getTimeZone('foo', Sabre_VObject_Reader::read($vobj)); + $tz = TimeZoneUtil::getTimeZone('foo', Reader::read($vobj)); - $this->assertEquals(new DateTimeZone(date_default_timezone_get()), $tz); + $this->assertEquals(new \DateTimeZone(date_default_timezone_get()), $tz); } diff --git a/dav/SabreDAV/tests/Sabre/VObject/VersionTest.php b/dav/sabre-vobject/tests/Sabre/VObject/VersionTest.php similarity index 53% rename from dav/SabreDAV/tests/Sabre/VObject/VersionTest.php rename to dav/sabre-vobject/tests/Sabre/VObject/VersionTest.php index ea2a4b284..ae6855e85 100644 --- a/dav/SabreDAV/tests/Sabre/VObject/VersionTest.php +++ b/dav/sabre-vobject/tests/Sabre/VObject/VersionTest.php @@ -1,13 +1,15 @@ assertEquals(-1, version_compare('0.9.0',$v)); - $s = Sabre_VObject_Version::STABILITY; + $s = Version::STABILITY; $this->assertTrue($s == 'alpha' || $s == 'beta' || $s =='stable'); } diff --git a/dav/SabreDAV/tests/Sabre/VObject/issue153.vcf b/dav/sabre-vobject/tests/Sabre/VObject/issue153.vcf similarity index 100% rename from dav/SabreDAV/tests/Sabre/VObject/issue153.vcf rename to dav/sabre-vobject/tests/Sabre/VObject/issue153.vcf diff --git a/dav/sabre-vobject/tests/bootstrap.php b/dav/sabre-vobject/tests/bootstrap.php new file mode 100644 index 000000000..ee071ea75 --- /dev/null +++ b/dav/sabre-vobject/tests/bootstrap.php @@ -0,0 +1,4 @@ + + + Sabre/ + + + + + ../lib/ + + + From d233ccbcc71e7f0f0f060ca0d2b1c51004b9fdda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6=C3=9Fl?= Date: Sun, 12 Aug 2012 08:27:05 +0000 Subject: [PATCH 09/84] An additional check to prevent PHP-notices that might corrupt the image data --- privacy_image_cache/privacy_image_cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index 8c68ef9a4..f4ada61e1 100644 --- a/privacy_image_cache/privacy_image_cache.php +++ b/privacy_image_cache/privacy_image_cache.php @@ -137,7 +137,7 @@ function privacy_image_cache_init() { } // Writing in cachefile - if (isset($cachefile) && ($cachefile != '') and (exif_imagetype($cachefile) > 0)) + if (isset($cachefile) && ($cachefile != '') and (file_exists($cachefile)) and (exif_imagetype($cachefile) > 0)) file_put_contents($cachefile, $img_str); header("Content-type: $mime"); From 5aa4e7d9671e20f6a3daab1b83e8f0ca78a62195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B6=C3=9Fl?= Date: Sun, 12 Aug 2012 09:31:34 +0000 Subject: [PATCH 10/84] v0.3 - Only refactoring, no new features; please note that this is still alpha-software --- dav/Changelog.txt | 4 +- dav/common/calendar.fnk.php | 48 ++++++++++++++++++- dav/dav.php | 2 +- dav/friendica/database-init.inc.php | 15 +++--- ..._carddav_backend_virtual_friendica.inc.php | 26 +++++++++- dav/friendica/main.php | 5 +- 6 files changed, 84 insertions(+), 16 deletions(-) diff --git a/dav/Changelog.txt b/dav/Changelog.txt index 2a8304c8a..c336baa93 100644 --- a/dav/Changelog.txt +++ b/dav/Changelog.txt @@ -1,4 +1,6 @@ -v0.2.1 +v0.3 +[REFACTOR] The new version of the VObject Library is used +[REFACTOR] The addressbook part has beed heavily refactored [REFACTOR] Remove some Friendica-specific code out of the "common"-folder v0.2.0 diff --git a/dav/common/calendar.fnk.php b/dav/common/calendar.fnk.php index 10177b347..11f31f7de 100644 --- a/dav/common/calendar.fnk.php +++ b/dav/common/calendar.fnk.php @@ -7,7 +7,9 @@ define("DAV_DISPLAYNAME", "{DAV:}displayname"); define("DAV_CALENDARCOLOR", "{http://apple.com/ns/ical/}calendar-color"); -class DAVVersionMismatchException extends Exception {} +class DAVVersionMismatchException extends Exception +{ +} class vcard_source_data_email @@ -99,6 +101,48 @@ class vcard_source_data public $photo; } +/** + * @param vcard_source_data $vcardsource + * @return string + */ +function vcard_source_compile($vcardsource) +{ + $str = "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Friendica//DAV-Plugin//EN\r\n"; + $str .= "N:" . str_replace(";", ",", $vcardsource->name_last) . ";" . str_replace(";", ",", $vcardsource->name_first) . ";" . str_replace(";", ",", $vcardsource->name_middle) . ";;\r\n"; + $str .= "FN:" . str_replace(";", ",", $vcardsource->name_first) . " " . str_replace(";", ",", $vcardsource->name_middle) . " " . str_replace(";", ",", $vcardsource->name_last) . "\r\n"; + $str .= "REV:" . str_replace(" ", "T", $vcardsource->last_update) . "Z\r\n"; + + $item_count = 0; + for ($i = 0; $i < count($vcardsource->homepages); $i++) { + if ($i == 0) $str .= "URL;type=" . $vcardsource->homepages[0]->type . ":" . $vcardsource->homepages[0]->homepage . "\r\n"; + else { + $c = ++$item_count; + $str .= "item$c.URL;type=" . $vcardsource->homepages[0]->type . ":" . $vcardsource->homepages[0]->homepage . "\r\n"; + $str .= "item$c.X-ABLabel:_\$!!\$_\r\n"; + } + } + + if (is_object($vcardsource->photo)) { + $data = base64_encode($vcardsource->photo->binarydata); + $str .= "PHOTO;ENCODING=BASE64;TYPE=" . $vcardsource->photo->type . ":" . $data . "\r\n"; + } + + if (isset($vcardsource->socialnetworks) && is_array($vcardsource->socialnetworks)) foreach ($vcardsource->socialnetworks as $netw) switch ($netw->type) { + case "dfrn": + $str .= "X-SOCIALPROFILE;type=dfrn;x-user=" . $netw->nick . ":" . $netw->url . "\r\n"; + break; + case "facebook": + $str .= "X-SOCIALPROFILE;type=facebook;x-user=" . $netw->nick . ":" . $netw->url . "\r\n"; + break; + case "twitter": + $str .= "X-SOCIALPROFILE;type=twitter;x-user=" . $netw->nick . ":" . $netw->url . "\r\n"; + break; + } + + $str .= "END:VCARD\r\n"; + return $str; +} + /** * @param int $phpDate (UTC) @@ -209,7 +253,7 @@ function dav_create_server($force_authentication = false, $needs_caldav = true, $aclPlugin->defaultUsernamePath = "principals/users"; $server->addPlugin($aclPlugin); } else { - $aclPlugin = new Sabre_DAVACL_Plugin(); + $aclPlugin = new Sabre_DAVACL_Plugin(); $aclPlugin->defaultUsernamePath = "principals/users"; $server->addPlugin($aclPlugin); } diff --git a/dav/dav.php b/dav/dav.php index 40040dfe2..f4d08f028 100644 --- a/dav/dav.php +++ b/dav/dav.php @@ -2,7 +2,7 @@ /** * Name: Calendar with CalDAV Support * Description: A web-based calendar system with CalDAV-support. Also brings your Friendica-Contacts to your CardDAV-capable mobile phone. Requires PHP >= 5.3. - * Version: 0.2.0 + * Version: 0.3.0 * Author: Tobias Hößl */ diff --git a/dav/friendica/database-init.inc.php b/dav/friendica/database-init.inc.php index 5978fd01e..f91ddb259 100644 --- a/dav/friendica/database-init.inc.php +++ b/dav/friendica/database-init.inc.php @@ -44,10 +44,6 @@ function dav_get_update_statements($from_version) } if (in_array($from_version, array(1, 2))) { - $stms[] = "DROP TABLE `dav_addressbooks_phone`"; - $stms[] = "DROP TABLE `dav_addressbooks_community`"; - $stms[] = "DROP TABLE `dav_cards`"; - $stms[] = "CREATE TABLE IF NOT EXISTS `dav_addressbooks` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `namespace` mediumint(9) NOT NULL, @@ -228,8 +224,12 @@ function dav_check_tables() $x = q("DESCRIBE %s%scalendars", CALDAV_SQL_DB, CALDAV_SQL_PREFIX); if (!$x) return -1; if (count($x) == 9) return 1; // Version 0.1 - // @TODO Detect Version 0.2 + + $x2 = q("show tables like '%s%saddressbooks'", CALDAV_SQL_DB, CALDAV_SQL_PREFIX); + if (!$x2 || count($x2) == 0) return 2; // Version 0.2 + if (count($x) == 12) return 0; // Correct + return -2; // Unknown version } @@ -257,11 +257,10 @@ function dav_create_tables() function dav_upgrade_tables() { $ver = dav_check_tables(); - if (!in_array($ver, array(1))) return array("Unknown error"); - + if (!in_array($ver, array(1, 2))) return array("Unknown error"); $stms = dav_get_update_statements($ver); - $errors = array(); + $errors = array(); global $db; foreach ($stms as $st) { // @TODO Friendica-dependent $db->q($st); diff --git a/dav/friendica/dav_carddav_backend_virtual_friendica.inc.php b/dav/friendica/dav_carddav_backend_virtual_friendica.inc.php index 3d7e09745..3a06d042b 100644 --- a/dav/friendica/dav_carddav_backend_virtual_friendica.inc.php +++ b/dav/friendica/dav_carddav_backend_virtual_friendica.inc.php @@ -128,15 +128,15 @@ class Sabre_CardDAV_Backend_Friendica extends Sabre_CardDAV_Backend_Virtual /** * @static * @param int $addressbookId + * @param bool $force * @throws Sabre_DAV_Exception_NotFound */ - static protected function createCache_internal($addressbookId) { + static protected function createCache_internal($addressbookId, $force = false) { //$notin = (count($exclude_ids) > 0 ? " AND id NOT IN (" . implode(", ", $exclude_ids) . ") " : ""); $addressbook = q("SELECT * FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId)); if (count($addressbook) != 1 || $addressbook[0]["namespace"] != CARDDAV_NAMESPACE_PRIVATE) throw new Sabre_DAV_Exception_NotFound(); $contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ORDER BY `name` ASC", $addressbook[0]["namespace_id"]); - $retdata = array(); foreach ($contacts as $contact) { $x = static::dav_contactarr2vcardsource($contact); q("INSERT INTO %s%saddressbookobjects (`addressbook_id`, `contact`, `carddata`, `uri`, `lastmodified`, `etag`, `size`) VALUES (%d, %d, '%s', '%s', NOW(), '%s', %d)", @@ -146,6 +146,27 @@ class Sabre_CardDAV_Backend_Friendica extends Sabre_CardDAV_Backend_Virtual } + /** + * @static + * @param int $addressbookId + * @param int $contactId + * @param bool $force + * @throws Sabre_DAV_Exception_NotFound + */ + static protected function createCardCache($addressbookId, $contactId, $force = false) + { + $addressbook = q("SELECT * FROM %s%saddressbooks WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($addressbookId)); + if (count($addressbook) != 1 || $addressbook[0]["namespace"] != CARDDAV_NAMESPACE_PRIVATE) throw new Sabre_DAV_Exception_NotFound(); + + $contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 AND `id` = %d ORDER BY `name` ASC", + $addressbook[0]["namespace_id"], IntVal($contactId)); + $contact = $contacts[0]; + + $x = static::dav_contactarr2vcardsource($contact); + q("INSERT INTO %s%saddressbookobjects (`addressbook_id`, `contact`, `carddata`, `uri`, `lastmodified`, `etag`, `size`) VALUES (%d, %d, '%s', '%s', NOW(), '%s', %d)", + CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $addressbookId, $contact["id"], dbesc($x["carddata"]), dbesc($x["uri"]), dbesc($x["etag"]), $x["size"] + ); + } /** * Updates a card. * @@ -202,4 +223,5 @@ class Sabre_CardDAV_Backend_Friendica extends Sabre_CardDAV_Backend_Virtual return true; } + } diff --git a/dav/friendica/main.php b/dav/friendica/main.php index 712b6c7b8..0fe939ebb 100644 --- a/dav/friendica/main.php +++ b/dav/friendica/main.php @@ -339,6 +339,7 @@ function dav_plugin_admin(&$a, &$o) $o .= t('Installed'); break; case 1: + case 2: $o .= "" . t('Upgrade needed') . "
" . t("Please back up all calendar data (the tables beginning with dav_*) before proceeding. While all calendar events should be converted to the new database structure, it's always safe to have a backup. Below, you can have a look at the database-queries that will be made when pressing the 'update'-button.") . "

"; break; case -1: @@ -355,8 +356,8 @@ function dav_plugin_admin(&$a, &$o) $o .= "

" . t("Manual creation of the database tables:") . "

"; $o .= "" . t("Show SQL-statements") . "