コード例 #1
0
 private static function row2array($row, $timezone, $hostname, $uid, $namespace_id)
 {
     $v = new vcalendar();
     $v->setConfig('unique_id', $hostname);
     $v->setProperty('method', 'PUBLISH');
     $v->setProperty("x-wr-calname", "AnimexxCal");
     $v->setProperty("X-WR-CALDESC", "Animexx Calendar");
     $v->setProperty("X-WR-TIMEZONE", $timezone);
     if ($row["adjust"]) {
         $start = datetime_convert('UTC', date_default_timezone_get(), $row["start"]);
         $finish = datetime_convert('UTC', date_default_timezone_get(), $row["finish"]);
     } else {
         $start = $row["start"];
         $finish = $row["finish"];
     }
     $allday = strpos($start, "00:00:00") !== false && strpos($finish, "00:00:00") !== false;
     /*
     
     if ($allday) {
     	$dat = Datetime::createFromFormat("Y-m-d H:i:s", $finish_tmp);
     	$dat->sub(new DateInterval("P1D"));
     	$finish = datetime_convert("UTC", date_default_timezone_get(), $dat->format("Y-m-d H:i:s"));
     	var_dump($finish);
     }
     */
     $subject = substr(preg_replace("/\\[[^\\]]*\\]/", "", $row["desc"]), 0, 100);
     $description = preg_replace("/\\[[^\\]]*\\]/", "", $row["desc"]);
     $vevent = dav_create_vevent(wdcal_mySql2icalTime($row["start"]), wdcal_mySql2icalTime($row["finish"]), false);
     $vevent->setLocation(icalendar_sanitize_string($row["location"]));
     $vevent->setSummary(icalendar_sanitize_string($subject));
     $vevent->setDescription(icalendar_sanitize_string($description));
     $v->setComponent($vevent);
     $ical = $v->createCalendar();
     return array("uid" => $uid, "namespace" => CALDAV_NAMESPACE_FRIENDICA_NATIVE, "namespace_id" => $namespace_id, "date" => $row["edited"], "data_uri" => "friendica-" . $namespace_id . "-" . $row["id"] . "@" . $hostname, "data_subject" => $subject, "data_location" => $row["location"], "data_description" => $description, "data_start" => $start, "data_end" => $finish, "data_allday" => $allday, "data_type" => $row["type"], "ical" => $ical, "ical_size" => strlen($ical), "ical_etag" => md5($ical));
 }
コード例 #2
0
 /**
  * @param array $start
  * @param array $end
  * @param string $subject
  * @param bool $allday
  * @param string $description
  * @param string $location
  * @param null $color
  * @param string $timezone
  * @param bool $notification
  * @param null $notification_type
  * @param null $notification_value
  * @return array|string
  */
 public function addItem($start, $end, $subject, $allday = false, $description = "", $location = "", $color = null, $timezone = "", $notification = true, $notification_type = null, $notification_value = null)
 {
     $a = get_app();
     $v = new vcalendar();
     $v->setConfig('unique_id', $a->get_hostname());
     $v->setProperty('method', 'PUBLISH');
     $v->setProperty("x-wr-calname", "AnimexxCal");
     $v->setProperty("X-WR-CALDESC", "Animexx Calendar");
     $v->setProperty("X-WR-TIMEZONE", $a->timezone);
     $vevent = dav_create_vevent($start, $end, $allday);
     $vevent->setLocation(icalendar_sanitize_string($location));
     $vevent->setSummary(icalendar_sanitize_string($subject));
     $vevent->setDescription(icalendar_sanitize_string($description));
     if (!is_null($color) && $color >= 0) {
         $vevent->setProperty("X-ANIMEXX-COLOR", $color);
     }
     if ($notification && $notification_type == null) {
         if ($allday) {
             $notification_type = "hour";
             $notification_value = 24;
         } else {
             $notification_type = "minute";
             $notification_value = 60;
         }
     }
     if ($notification) {
         $valarm = new valarm();
         $valarm->setTrigger($notification_type == "year" ? $notification_value : 0, $notification_type == "month" ? $notification_value : 0, $notification_type == "day" ? $notification_value : 0, $notification_type == "week" ? $notification_value : 0, $notification_type == "hour" ? $notification_value : 0, $notification_type == "minute" ? $notification_value : 0, $notification_type == "second" ? $notification_value : 0, true, $notification_value > 0);
         $valarm->setAction("DISPLAY");
         $valarm->setDescription($subject);
         $vevent->setComponent($valarm);
     }
     $v->setComponent($vevent);
     $ical = $v->createCalendar();
     $obj_id = trim($vevent->getProperty("UID"));
     $calendarBackend = new Sabre_CalDAV_Backend_Std();
     $calendarBackend->createCalendarObject($this->getNamespace() . "-" . $this->namespace_id, $obj_id . ".ics", $ical);
     return $obj_id . ".ics";
 }