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));
 }
Exemplo n.º 2
0
/**
 *
 */
function wdcal_print_feed($base_path = "")
{
    $user_id = dav_compat_get_curr_user_id();
    $cals = array();
    if (isset($_REQUEST["cal"])) {
        foreach ($_REQUEST["cal"] as $c) {
            $x = explode("-", $c);
            $calendarSource = wdcal_calendar_factory($user_id, $x[0], $x[1]);
            $calp = $calendarSource->getPermissionsCalendar($user_id);
            if ($calp["read"]) {
                $cals[] = $calendarSource;
            }
        }
    }
    $ret = null;
    /** @var $cals array|AnimexxCalSource[] */
    $method = $_GET["method"];
    switch ($method) {
        case "add":
            $cs = null;
            foreach ($cals as $c) {
                if ($cs == null) {
                    $x = $c->getPermissionsCalendar($user_id);
                    if ($x["read"]) {
                        $cs = $c;
                    }
                }
            }
            if ($cs == null) {
                echo wdcal_jsonp_encode(array('IsSuccess' => false, 'Msg' => t('No access')));
                killme();
            }
            try {
                $start = wdcal_mySql2icalTime(wdcal_php2MySqlTime($_REQUEST["CalendarStartTime"]));
                $end = wdcal_mySql2icalTime(wdcal_php2MySqlTime($_REQUEST["CalendarEndTime"]));
                $newuri = $cs->addItem($start, $end, $_REQUEST["CalendarTitle"], $_REQUEST["IsAllDayEvent"]);
                $ret = array('IsSuccess' => true, 'Msg' => 'add success', 'Data' => $newuri);
            } 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;
            foreach ($cals as $c) {
                $events = $c->listItemsByRange($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":
            $found = false;
            $start = wdcal_mySql2icalTime(wdcal_php2MySqlTime($_REQUEST["CalendarStartTime"]));
            $end = wdcal_mySql2icalTime(wdcal_php2MySqlTime($_REQUEST["CalendarEndTime"]));
            foreach ($cals as $c) {
                try {
                    $permissions_item = $c->getPermissionsItem($user_id, $_REQUEST["calendarId"], "");
                    if ($permissions_item["write"]) {
                        $c->updateItem($_REQUEST["calendarId"], $start, $end);
                        $found = true;
                    }
                } catch (Exception $e) {
                }
            }
            if ($found) {
                $ret = array('IsSuccess' => true, 'Msg' => 'Succefully');
            } else {
                echo wdcal_jsonp_encode(array('IsSuccess' => false, 'Msg' => t('No access')));
                killme();
            }
            try {
            } catch (Exception $e) {
                $ret = array('IsSuccess' => false, 'Msg' => $e->__toString());
            }
            break;
        case "remove":
            $found = false;
            foreach ($cals as $c) {
                try {
                    $permissions_item = $c->getPermissionsItem($user_id, $_REQUEST["calendarId"], "");
                    if ($permissions_item["write"]) {
                        $c->removeItem($_REQUEST["calendarId"]);
                    }
                } catch (Exception $e) {
                }
            }
            if ($found) {
                $ret = array('IsSuccess' => true, 'Msg' => 'Succefully');
            } else {
                echo wdcal_jsonp_encode(array('IsSuccess' => false, 'Msg' => t('No access')));
                killme();
            }
            break;
    }
    echo wdcal_jsonp_encode($ret);
    killme();
}