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] 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();