/** * @param string $uri * @param int $uid * @param string $timezone * @param string $goaway_url * @return array */ function wdcal_postEditPage($uri, $uid = 0, $timezone = "", $goaway_url = "") { $uid = IntVal($uid); $localization = wdcal_local::getInstanceByUser($uid); $server = dav_create_server(true, true, false); if ($uri > 0) { $calendar = dav_get_current_user_calendar_by_id($server, $_REQUEST["calendar"], DAV_ACL_READ); $obj_uri = Sabre_CalDAV_Backend_Common::loadCalendarobjectById($uri); $obj_uri = $obj_uri["uri"]; $vObject = dav_get_current_user_calendarobject($server, $calendar, $obj_uri, DAV_ACL_WRITE); $component = dav_get_eventComponent($vObject); if ($component == null) { return array("ok" => false, "msg" => t('Could not open component for editing')); } } else { $calendar = dav_get_current_user_calendar_by_id($server, $_REQUEST["calendar"], DAV_ACL_WRITE); $vObject = dav_create_empty_vevent(); $component = dav_get_eventComponent($vObject); $obj_uri = $component->__get("UID"); } $ts_start = wdcal_set_component_date($component, $localization); wdcal_set_component_recurrence($component, $localization); wdcal_set_component_alerts($component, $localization, icalendar_sanitize_string(dav_compat_parse_text_serverside("summary")), $ts_start); $component->__unset("LOCATION"); $component->__unset("SUMMARY"); $component->__unset("DESCRIPTION"); $component->__unset("X-ANIMEXX-COLOR"); $component->add("SUMMARY", icalendar_sanitize_string(dav_compat_parse_text_serverside("summary"))); $component->add("LOCATION", icalendar_sanitize_string(dav_compat_parse_text_serverside("location"))); $component->add("DESCRIPTION", icalendar_sanitize_string(dav_compat_parse_text_serverside("wdcal_desc"))); if (isset($_REQUEST["color_override"])) { $component->add("X-ANIMEXX-COLOR", $_REQUEST["color"]); } $data = $vObject->serialize(); if ($uri == 0) { $calendar->createFile($obj_uri . ".ics", $data); } else { $obj = $calendar->getChild($obj_uri); $obj->put($data); } return array("ok" => false, "msg" => t("Saved")); }
/** * @return string */ function dav_content() { $a = get_app(); if (!isset($a->user["uid"]) || $a->user["uid"] == 0) { return login(); } $x = ""; try { if ($a->argv[1] == "settings") { return wdcal_getSettingsPage($a); } elseif ($a->argv[1] == "wdcal") { if (isset($a->argv[2]) && strlen($a->argv[2]) > 0) { if ($a->argv[2] == "new") { $o = ""; if (isset($_REQUEST["save"])) { check_form_security_token_redirectOnErr("/dav/wdcal/", "caledit"); $ret = wdcal_postEditPage("new", "", $a->user["uid"], $a->timezone, $a->get_baseurl() . "/dav/wdcal/"); if ($ret["ok"]) { notice($ret["msg"]); } else { info($ret["msg"]); } goaway($a->get_baseurl() . "/dav/wdcal/"); } $o .= wdcal_getNewPage(); return $o; } else { $calendar_id = IntVal($a->argv[2]); if (isset($a->argv[3]) && $a->argv[3] == "ics-export") { wdcal_print_user_ics($calendar_id); } elseif (isset($a->argv[3]) && $a->argv[3] == "ics-import") { return wdcal_import_user_ics($calendar_id); } elseif (isset($a->argv[3]) && $a->argv[3] > 0) { if (isset($a->argv[4]) && $a->argv[4] == "edit") { $o = ""; if (isset($_REQUEST["save"])) { check_form_security_token_redirectOnErr("/dav/wdcal/", "caledit"); $ret = wdcal_postEditPage($a->argv[3], $a->user["uid"], $a->timezone, $a->get_baseurl() . "/dav/wdcal/"); if ($ret["ok"]) { notice($ret["msg"]); } else { info($ret["msg"]); } goaway($a->get_baseurl() . "/dav/wdcal/"); } $o .= wdcal_getEditPage($calendar_id, $a->argv[3]); return $o; } else { return wdcal_getDetailPage($calendar_id, $a->argv[3]); } } else { // @TODO Edit Calendar } } } else { $server = dav_create_server(true, true, false); $cals = dav_get_current_user_calendars($server, DAV_ACL_READ); $x = wdcal_printCalendar($cals, array(), $a->get_baseurl() . "/dav/wdcal/feed/", "week", 0, 200); } } } catch (DAVVersionMismatchException $e) { $x = t("The current version of this plugin has not been set up correctly. Please contact the system administrator of your installation of friendica to fix this."); } return $x; }
/** * */ function wdcal_print_feed($base_path = "") { $server = dav_create_server(true, true, false); $ret = null; $method = $_GET["method"]; switch ($method) { case "add": $cs = wdcal_print_feed_getCal($server, DAV_ACL_WRITE); if ($cs == null) { echo wdcal_jsonp_encode(array('IsSuccess' => false, 'Msg' => t('No access'))); killme(); } try { $item = dav_create_empty_vevent(); $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; } $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->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarEndTime"]))), $type); $component->add($datetime_start); $component->add($datetime_end); $uid = $component->__get("UID"); $data = $item->serialize(); $cs->createFile($uid . ".ics", $data); $ret = array('IsSuccess' => true, 'Msg' => 'add success', 'Data' => $uid . ".ics"); } catch (Exception $e) { $ret = array('IsSuccess' => false, 'Msg' => $e->__toString()); } break; case "list": $weekstartday = isset($_REQUEST["weekstartday"]) ? IntVal($_REQUEST["weekstartday"]) : 1; // 1 = Monday $num_days = isset($_REQUEST["num_days"]) ? IntVal($_REQUEST["num_days"]) : 7; $ret = null; $date = wdcal_get_list_range_params($_REQUEST["showdate"], $weekstartday, $num_days, $_REQUEST["viewtype"]); $ret = array(); $ret['events'] = array(); $ret["issort"] = true; $ret["start"] = $date[0]; $ret["end"] = $date[1]; $ret['error'] = null; $cals = dav_get_current_user_calendars($server, DAV_ACL_READ); foreach ($cals as $cal) { $prop = $cal->getProperties(array("id")); if (isset($prop["id"]) && (!isset($_REQUEST["cal"]) || in_array($prop["id"], $_REQUEST["cal"]))) { $backend = wdcal_calendar_factory_by_id($prop["id"]); $events = $backend->listItemsByRange($prop["id"], $date[0], $date[1], $base_path); $ret["events"] = array_merge($ret["events"], $events); } } $tmpev = array(); foreach ($ret["events"] as $e) { if (!isset($tmpev[$e["start"]])) { $tmpev[$e["start"]] = array(); } $tmpev[$e["start"]][] = $e; } ksort($tmpev); $ret["events"] = array(); foreach ($tmpev as $e) { foreach ($e as $f) { $ret["events"][] = $f; } } break; case "update": $r = q("SELECT `calendarobject_id`, `calendar_id` FROM %s%sjqcalendar WHERE `id`=%d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($_REQUEST["jq_id"])); if (count($r) != 1) { echo wdcal_jsonp_encode(array('IsSuccess' => false, 'Msg' => t('No access'))); killme(); } try { $cs = dav_get_current_user_calendar_by_id($server, $r[0]["calendar_id"], DAV_ACL_READ); $obj_uri = Sabre_CalDAV_Backend_Common::loadCalendarobjectById($r[0]["calendarobject_id"]); $vObject = dav_get_current_user_calendarobject($server, $cs, $obj_uri["uri"], DAV_ACL_WRITE); $component = dav_get_eventComponent($vObject); if (!$component) { echo wdcal_jsonp_encode(array('IsSuccess' => false, 'Msg' => t('No access'))); killme(); } 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->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarStartTime"]))), $type); $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"); $component->__unset("DTEND"); $component->add($datetime_start); $component->add($datetime_end); $data = $vObject->serialize(); /** @var Sabre_CalDAV_CalendarObject $child */ $child = $cs->getChild($obj_uri["uri"]); $child->put($data); $ret = array('IsSuccess' => true, 'Msg' => 'Succefully'); } catch (Exception $e) { echo wdcal_jsonp_encode(array('IsSuccess' => false, 'Msg' => t('No access'))); killme(); } break; case "remove": $r = q("SELECT `calendarobject_id`, `calendar_id` FROM %s%sjqcalendar WHERE `id`=%d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($_REQUEST["jq_id"])); if (count($r) != 1) { echo wdcal_jsonp_encode(array('IsSuccess' => false, 'Msg' => t('No access'))); killme(); } try { $cs = dav_get_current_user_calendar_by_id($server, $r[0]["calendar_id"], DAV_ACL_WRITE); $obj_uri = Sabre_CalDAV_Backend_Common::loadCalendarobjectById($r[0]["calendarobject_id"]); $child = $cs->getChild($obj_uri["uri"]); $child->delete(); $ret = array('IsSuccess' => true, 'Msg' => 'Succefully'); } catch (Exception $e) { echo wdcal_jsonp_encode(array('IsSuccess' => false, 'Msg' => t('No access'))); killme(); } break; } echo wdcal_jsonp_encode($ret); killme(); }
/** * @param int $calendar_id * @param int $calendarobject_id * @return string */ function wdcal_getDetailPage($calendar_id, $calendarobject_id) { $a = get_app(); 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); } $details = $obj; } catch (Exception $e) { info(t("Error") . ": " . $e); goaway($a->get_baseurl() . "/dav/wdcal/"); } return print_r($details, true); }