X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=dav%2Flayout.fnk.php;fp=dav%2Flayout.fnk.php;h=07eec4215d98901ccd2ac34ddcff0a9c0b77e147;hb=fefee23e903a4d82944dcaf75b8953c5181a6ebf;hp=550f90b6aacf6e04bef2b62c084865f65ffe3fa7;hpb=4a5e30ec845bcb756543f14c4d8e0b5a3138f2fc;p=friendica-addons.git diff --git a/dav/layout.fnk.php b/dav/layout.fnk.php index 550f90b6..07eec421 100644 --- a/dav/layout.fnk.php +++ b/dav/layout.fnk.php @@ -8,8 +8,8 @@ function wdcal_addRequiredHeaders() { $a = get_app(); - $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"; @@ -20,6 +20,7 @@ function wdcal_addRequiredHeaders() switch (get_config("system", "language")) { case "de": $a->page['htmlhead'] .= '' . "\r\n"; + $a->page['htmlhead'] .= '' . "\r\n"; break; default: $a->page['htmlhead'] .= '' . "\r\n"; @@ -34,10 +35,12 @@ function wdcal_addRequiredHeaders() */ function wdcal_addRequiredHeadersEdit() { - $a = get_app(); - $a->page['htmlhead'] .= '' . "\r\n"; - $a->page['htmlhead'] .= '' . "\r\n"; + $a = get_app(); + $localization = wdcal_local::getInstanceByUser($a->user["uid"]); + + $a->page['htmlhead'] .= '' . "\r\n"; + $a->page['htmlhead'] .= '' . "\r\n"; $a->page['htmlhead'] .= '' . "\r\n"; $a->page['htmlhead'] .= '' . "\r\n"; @@ -48,12 +51,56 @@ function wdcal_addRequiredHeadersEdit() $a->page['htmlhead'] .= '' . "\r\n"; $a->page['htmlhead'] .= '' . "\r\n"; + switch ($localization->getLanguageCode()) { + case "de": + $a->page['htmlhead'] .= '' . "\r\n"; + $a->page['htmlhead'] .= '' . "\r\n"; + break; + default: + $a->page['htmlhead'] .= '' . "\r\n"; + } + +} + +/** + * @param array|int[] $calendars + */ +function wdcal_print_user_ics($calendars = array()) +{ + $add = ""; + if (count($calendars) > 0) { + $c = array(); + foreach ($calendars as $i) $c[] = IntVal($i); + $add = " AND `id` IN (" . implode(", ", $c) . ")"; + } + + $a = get_app(); + header("Content-type: text/plain"); + + $str = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Friendica//DAV-Plugin//EN\r\n"; + $cals = q("SELECT * FROM %s%scalendars WHERE `namespace` = %d AND `namespace_id` = %d %s", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, CALDAV_NAMESPACE_PRIVATE, $a->user["uid"], $add); + if (count($cals) > 0) { + $ids = array(); + foreach ($cals as $c) $ids[] = IntVal($c["id"]); + $objs = q("SELECT * FROM %s%scalendarobjects WHERE `calendar_id` IN (" . implode(", ", $ids) . ") ORDER BY `firstOccurence`", CALDAV_SQL_DB, CALDAV_SQL_PREFIX); + + foreach ($objs as $obj) { + preg_match("/BEGIN:VEVENT(.*)END:VEVENT/siu", $obj["calendardata"], $matches); + $str2 = preg_replace("/([^\\r])\\n/siu", "\\1\r\n", $matches[0]); + $str2 = preg_replace("/MAILTO:.*[^:a-z0-9_\+äöüß\\n\\n@-]+.*(:|\\r\\n[^ ])/siU", "\\1", $str2); + $str .= $str2 . "\r\n"; + } + } + $str .= "END:VCALENDAR\r\n"; + + echo $str; + killme(); } /** - * @param array|DBClass_friendica_calendars[] $calendars - * @param array $calendar_preselected + * @param array|Sabre_CalDAV_Calendar[] $calendars + * @param array|int[] $calendars_selected * @param string $data_feed_url * @param string $view * @param int $theme @@ -64,14 +111,17 @@ function wdcal_addRequiredHeadersEdit() * @param bool $show_nav * @return string */ -function wdcal_printCalendar($calendars, $calendar_preselected, $data_feed_url, $view = "week", $theme = 0, $height_diff = 175, $readonly = false, $curr_day = "", $add_params = array(), $show_nav = true) +function wdcal_printCalendar($calendars, $calendars_selected, $data_feed_url, $view = "week", $theme = 0, $height_diff = 175, $readonly = false, $curr_day = "", $add_params = array(), $show_nav = true) { $a = get_app(); $localization = wdcal_local::getInstanceByUser($a->user["uid"]); - $cals_avail = array(); - foreach ($calendars as $c) $cals_avail[] = array("ns" => $c->namespace, "id" => $c->namespace_id, "displayname" => $c->displayname); + if (count($calendars_selected) == 0) foreach ($calendars as $c) { + $prop = $c->getProperties(array("id")); + $calendars_selected[] = $prop["id"]; + } + $opts = array( "view" => $view, "theme" => $theme, @@ -96,12 +146,13 @@ function wdcal_printCalendar($calendars, $calendar_preselected, $data_feed_url,
Available Calendars:'; - foreach ($cals_avail as $cal) { - $x .= '
@@ -179,166 +230,57 @@ function wdcal_printCalendar($calendars, $calendar_preselected, $data_feed_url, /** - * @param string $uri + * @param int $calendar_id + * @param int $calendarobject_id * @param string $recurr_uri * @return string */ -function wdcal_getDetailPage($uri, $recurr_uri) +function wdcal_getDetailPage($calendar_id, $calendarobject_id, $recurr_uri) { $a = get_app(); - $details = null; - $cals = dav_getMyCals($a->user["uid"]); - foreach ($cals as $c) { - $cs = wdcal_calendar_factory($a->user["uid"], $c->namespace, $c->namespace_id); - $p = $cs->getPermissionsItem($a->user["uid"], $uri, $recurr_uri); - if ($p["read"]) try { - $redirect = $cs->getItemDetailRedirect($uri); - if ($redirect !== null) goaway($redirect); - $details = $cs->getItemByUri($uri); - } catch (Exception $e) { - notification(t("Error") . ": " . $e); - goaway($a->get_baseurl() . "/dav/wdcal/"); - } - } + try { + $details = null; + $server = dav_create_server(true, true, false); + $cal = dav_get_current_user_calendar_by_id($server, $calendar_id, DAV_ACL_READ); + $obj = Sabre_CalDAV_Backend_Common::loadCalendarobjectById($calendarobject_id); + dav_get_current_user_calendarobject($server, $cal, $obj["uri"], DAV_ACL_READ); // Check permissions + + $calbackend = wdcal_calendar_factory_by_id($calendar_id); + $redirect = $calbackend->getItemDetailRedirect($calendar_id, $calendarobject_id); + if ($redirect !== null) goaway($a->get_baseurl() . $redirect); - return $uri . " / " . $recurr_uri . "
" . print_r($details, true); + $details = $obj; + } catch (Exception $e) { + info(t("Error") . ": " . $e); + goaway($a->get_baseurl() . "/dav/wdcal/"); + } + + return print_r($details, true); } + /** - * @param string $uri + * @param int $calendar_id + * @param int $uri * @param string $recurr_uri * @return string */ -function wdcal_getEditPage($uri, $recurr_uri = "") +function wdcal_getEditPage($calendar_id, $uri, $recurr_uri = "") { - $a = get_app(); $localization = wdcal_local::getInstanceByUser($a->user["uid"]); - if ($uri != "" && $uri != "new") { - $o = q("SELECT * FROM %s%sjqcalendar WHERE `uid` = %d AND `ical_uri` = '%s' AND `ical_recurr_uri` = '%s'", - CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $a->user["uid"], dbesc($uri), dbesc($recurr_uri) - ); - if (count($o) != 1) return t('Not found'); - $event = $o[0]; - - $calendarSource = wdcal_calendar_factory($a->user["uid"], $event["namespace"], $event["namespace_id"]); - - $permissions = $calendarSource->getPermissionsItem($a->user["uid"], $uri, $recurr_uri, $event); - - if (!$permissions["write"]) return t('No access'); - - $n = q("SELECT * FROM %s%snotifications WHERE `uid` = %d AND `ical_uri` = '%s' AND `ical_recurr_uri` = '%s'", - CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $a->user["uid"], dbesc($uri), dbesc($recurr_uri) - ); - if (count($n) > 0) { - $notification_type = $n[0]["rel_type"]; - $notification_value = -1 * $n[0]["rel_value"]; - $notification = true; - } else { - if ($event["IsAllDayEvent"]) { - $notification_type = "hour"; - $notification_value = 24; - } else { - $notification_type = "minute"; - $notification_value = 60; - } - $notification = false; - } - - - } elseif (isset($_REQUEST["start"]) && $_REQUEST["start"] > 0) { - $event = array( - "id" => 0, - "Subject" => $_REQUEST["title"], - "Location" => "", - "Description" => "", - "StartTime" => wdcal_php2MySqlTime($_REQUEST["start"]), - "EndTime" => wdcal_php2MySqlTime($_REQUEST["end"]), - "IsAllDayEvent" => $_REQUEST["isallday"], - "Color" => null, - "RecurringRule" => null, - ); - if ($_REQUEST["isallday"]) { - $notification_type = "hour"; - $notification_value = 24; - } else { - $notification_type = "hour"; - $notification_value = 1; - } + return wdcal_getEditPage_str($localization, $a->get_baseurl(), $a->user["uid"], $calendar_id, $uri, $recurr_uri); +} - $notification = true; - } else { - $event = array( - "id" => 0, - "Subject" => "", - "Location" => "", - "Description" => "", - "StartTime" => date("Y-m-d H:i:s"), - "EndTime" => date("Y-m-d H:i:s", time() + 3600), - "IsAllDayEvent" => "0", - "Color" => "#5858ff", - "RecurringRule" => null, - ); - $notification_type = "hour"; - $notification_value = 1; - $notification = true; - } +function wdcal_getNewPage() +{ + $a = get_app(); + $localization = wdcal_local::getInstanceByUser($a->user["uid"]); - $postto = $a->get_baseurl() . "/dav/wdcal/" . ($uri == "new" ? "new/" : $uri . "/edit/"); - - $out = "" . t("Go back to the calendar") . "

"; - $out .= "
\n"; - - $out .= " - -
\n"; - $out .= "
\n"; - - $out .= ""; - $out .= ""; - $out .= ""; - $out .= "
\n"; - - $out .= ""; - $out .= ""; - $out .= ""; - $out .= "
\n"; - - $out .= "
\n"; - - $out .= " "; - $out .= "
"; - - $out .= ""; - $out .= ' - ' . t('before') . ' -

'; - - - $out .= ""; - - $out .= "
"; - - return $out; + return wdcal_getEditPage_str($localization, $a->get_baseurl(), $a->user["uid"], 0, 0); }