4 $uri = parse_url($a->get_baseurl());
6 if (strlen($uri["path"]) > 1) {
7 $path = $uri["path"] . "/";
10 define("CALDAV_SQL_DB", "");
11 define("CALDAV_SQL_PREFIX", "dav_");
12 define("CALDAV_URL_PREFIX", $path . "dav/");
14 define("CALDAV_NAMESPACE_PRIVATE", 1);
15 define("CALDAV_NAMESPACE_FRIENDICA_NATIVE", 2);
17 define("CALDAV_FRIENDICA_MINE", 1);
18 define("CALDAV_FRIENDICA_CONTACTS", 2);
20 define("CARDDAV_NAMESPACE_COMMUNITYCONTACTS", 1);
21 define("CARDDAV_NAMESPACE_PHONECONTACTS", 2);
23 define("CALDAV_DB_VERSION", 1);
25 function getCurMicrotime () {
26 list($usec, $sec) = explode(" ", microtime());
27 return sprintf("%14.0f", $sec * 10000 + $usec * 10000);
28 } // function getCurMicrotime
30 function debug_time() {
31 $cur = getCurMicrotime();
32 if ($GLOBALS["debug_time_last"] > 0) {
33 echo "Zeit: " . ($cur - $GLOBALS["debug_time_last"]) . "<br>\n";
35 $GLOBALS["debug_time_last"] = $cur;
40 * @param string $username
43 function dav_compat_username2id($username = "")
45 $x = q("SELECT `uid` FROM user WHERE nickname='%s' AND account_removed = 0 AND account_expired = 0", dbesc($username));
46 if (count($x) == 1) return $x[0]["uid"];
54 function dav_compat_id2username($id = 0)
56 $x = q("SELECT `nickname` FROM user WHERE uid = %i AND account_removed = 0 AND account_expired = 0", IntVal($id));
57 if (count($x) == 1) return $x[0]["nickname"];
64 function dav_compat_get_curr_user_id() {
66 return IntVal($a->user["uid"]);
71 * @param string $principalUri
74 function dav_compat_principal2uid($principalUri = "")
76 if (strlen($principalUri) == 0) return null;
77 if ($principalUri[0] == "/") $principalUri = substr($principalUri, 1);
78 if (strpos($principalUri, "principals/users/") !== 0) return null;
79 $username = substr($principalUri, strlen("principals/users/"));
80 return dav_compat_username2id($username);
87 function wdcal_parse_text_serverside($text)
94 * @param int $namespace
95 * @param int $namespace_id
96 * @return AnimexxCalSource
99 function wdcal_calendar_factory($user_id, $namespace, $namespace_id)
101 switch ($namespace) {
102 case CALDAV_NAMESPACE_PRIVATE:
103 return new AnimexxCalSourcePrivate($user_id, $namespace_id);
104 case CALDAV_NAMESPACE_FRIENDICA_NATIVE:
105 return new FriendicaCalSourceEvents($user_id, $namespace_id);
107 throw new Exception("Calendar Namespace not found");
113 function wdcal_create_std_calendars()
116 if (!local_user()) return;
118 $cals = q("SELECT * FROM %s%scalendars WHERE `uid` = %d AND `namespace` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $a->user["uid"], CALDAV_NAMESPACE_PRIVATE);
119 if (count($cals) == 0) {
120 $maxid = q("SELECT MAX(`namespace_id`) maxid FROM %s%scalendars WHERE `namespace` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CALDAV_NAMESPACE_PRIVATE);
122 notification("Something went wrong when trying to create your calendar.");
126 $nextid = IntVal($maxid[0]["maxid"]) + 1;
127 q("INSERT INTO %s%scalendars (`namespace`, `namespace_id`, `uid`, `displayname`, `timezone`, `ctag`) VALUES (%d, %d, %d, '%s', '%s', 1)",
128 CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CALDAV_NAMESPACE_PRIVATE, $nextid, $a->user["uid"], dbesc(t("Private Calendar")), dbesc($a->timezone)
132 $cals = q("SELECT * FROM %s%scalendars WHERE `uid` = %d AND `namespace` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $a->user["uid"], CALDAV_NAMESPACE_FRIENDICA_NATIVE);
133 if (count($cals) < 2) {
134 q("INSERT INTO %s%scalendars (`namespace`, `namespace_id`, `uid`, `displayname`, `timezone`, `ctag`) VALUES (%d, %d, %d, '%s', '%s', 1)",
135 CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CALDAV_NAMESPACE_FRIENDICA_NATIVE, CALDAV_FRIENDICA_MINE, $a->user["uid"], dbesc(t("Friendica Events: Mine")), dbesc($a->timezone)
137 q("INSERT INTO %s%scalendars (`namespace`, `namespace_id`, `uid`, `displayname`, `timezone`, `ctag`) VALUES (%d, %d, %d, '%s', '%s', 1)",
138 CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CALDAV_NAMESPACE_FRIENDICA_NATIVE, CALDAV_FRIENDICA_CONTACTS, $a->user["uid"], dbesc(t("Friendica Events: Contacts")), dbesc($a->timezone)