argc >= 2 && $a->argv[1] == "wdcal") {
if ($a->argc >= 3 && $a->argv[2] == "feed") {
wdcal_print_feed($a->get_baseurl() . "/dav/wdcal/");
killme();
} elseif ($a->argc >= 3 && strlen($a->argv[2]) > 0) {
wdcal_addRequiredHeadersEdit();
} else {
wdcal_addRequiredHeaders();
}
return;
}
if ($a->argc >= 2 && $a->argv[1] == "settings") {
return;
}
$authBackend = new Sabre_DAV_Auth_Backend_Friendica();
$principalBackend = new Sabre_DAVACL_PrincipalBackend_Friendica($authBackend);
$caldavBackend_std = new Sabre_CalDAV_Backend_Std();
$caldavBackend_community = new Sabre_CalDAV_Backend_Friendica();
$carddavBackend_std = new Sabre_CardDAV_Backend_Std();
$carddavBackend_community = new Sabre_CardDAV_Backend_FriendicaCommunity();
if (isset($_SERVER["PHP_AUTH_USER"])) {
$tree = new Sabre_DAV_SimpleCollection('root', array(
new Sabre_DAV_SimpleCollection('principals', array(
new Sabre_CalDAV_Principal_Collection($principalBackend, "principals/users"),
)),
new Sabre_CalDAV_AnimexxCalendarRootNode($principalBackend, array(
$caldavBackend_std,
$caldavBackend_community,
)),
new Sabre_CardDAV_AddressBookRootFriendica($principalBackend, array(
$carddavBackend_std,
$carddavBackend_community,
)),
));
} else {
$tree = new Sabre_DAV_SimpleCollection('root', array());
}
// The object tree needs in turn to be passed to the server class
$server = new Sabre_DAV_Server($tree);
$url = parse_url($a->get_baseurl());
$server->setBaseUri(CALDAV_URL_PREFIX);
$authPlugin = new Sabre_DAV_Auth_Plugin($authBackend, 'SabreDAV');
$server->addPlugin($authPlugin);
$aclPlugin = new Sabre_DAVACL_Plugin_Friendica();
$aclPlugin->defaultUsernamePath = "principals/users";
$server->addPlugin($aclPlugin);
$caldavPlugin = new Sabre_CalDAV_Plugin();
$server->addPlugin($caldavPlugin);
$carddavPlugin = new Sabre_CardDAV_Plugin();
$server->addPlugin($carddavPlugin);
$browser = new Sabre_DAV_Browser_Plugin();
$server->addPlugin($browser);
$server->exec();
killme();
}
/**
* @return string
*/
function dav_content()
{
$a = get_app();
if (!isset($a->user["uid"]) || $a->user["uid"] == 0) {
return login();
}
$x = "";
if ($a->argv[1] == "settings") {
return wdcal_getSettingsPage($a);
} elseif ($a->argv[1] == "wdcal") {
if ($a->argc >= 3 && strlen($a->argv[2]) > 0) {
$uri = $a->argv[2];
$recurr_uri = ""; // @TODO
if (isset($a->argv[3]) && $a->argv[3] == "edit") {
$o = "";
if (isset($_REQUEST["save"])) $o .= wdcal_postEditPage($uri, $recurr_uri);
$o .= wdcal_getEditPage($uri, $recurr_uri);
return $o;
} else {
return wdcal_getDetailPage($uri, $recurr_uri);
}
} else {
$cals = dav_getMyCals($a->user["uid"]);
$cals_show = array();
foreach ($cals as $e) $cals_show[] = array("ns" => $e->namespace, "id" => $e->namespace_id, "displayname" => $e->displayname);
$x = wdcal_printCalendar($cals, $cals_show, $a->get_baseurl() . "/dav/wdcal/feed/", "week", 0, 200);
}
}
return $x;
}
/**
* @param App $a
* @param object $b
*/
function dav_event_created_hook(&$a, &$b)
{
dav_include_files();
// @TODO Updating the cache instead of completely invalidating and rebuilding it
FriendicaVirtualCalSourceBackend::invalidateCache($a->user["uid"], CALDAV_FRIENDICA_CONTACTS);
FriendicaVirtualCalSourceBackend::invalidateCache($a->user["uid"], CALDAV_FRIENDICA_MINE);
}
/**
* @param App $a
* @param object $b
*/
function dav_event_updated_hook(&$a, &$b)
{
dav_include_files();
// @TODO Updating the cache instead of completely invalidating and rebuilding it
FriendicaVirtualCalSourceBackend::invalidateCache($a->user["uid"], CALDAV_FRIENDICA_CONTACTS);
FriendicaVirtualCalSourceBackend::invalidateCache($a->user["uid"], CALDAV_FRIENDICA_MINE);
}
/**
* @param App $a
* @param object $b
*/
function dav_profile_tabs_hook(&$a, &$b)
{
$b["tabs"][] = array(
"label" => t('Calendar'),
"url" => $a->get_baseurl() . "/dav/wdcal/",
"sel" => "",
"title" => t('Extended calendar with CalDAV-support'),
);
}
/**
* @param App $a
* @param null|object $o
*/
function dav_plugin_admin_post(&$a = null, &$o = null)
{
check_form_security_token_redirectOnErr('/admin/plugins/dav', 'dav_admin_save');
require_once(__DIR__ . "/database-init.inc.php");
if (isset($_REQUEST["install"])) {
$errs = dav_create_tables();
if (count($errs) == 0) info(t('The database tables have been installed.') . EOL);
else notice(t("An error occurred during the installation.") . EOL);
}
}
/**
* @param App $a
* @param null|object $o
*/
function dav_plugin_admin(&$a, &$o)
{
require_once(__DIR__ . "/database-init.inc.php");
$dbstatus = dav_check_tables();
$o = '';
$o .= '' . t("No system-wide settings yet.") . '
';
$o .= '