/** * The actual ChangesSink. * For max. the $timeout value this method should block and if no changes * are available return an empty array. * If changes are available a list of folderids is expected. * * @param int $timeout max. amount of seconds to block * * @access public * @return array */ public function ChangesSink($timeout = 30) { $notifications = array(); $stopat = time() + $timeout - 1; //We can get here and the ChangesSink not be initialized yet if (!$this->changessinkinit) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCalDAV->ChangesSink - Not initialized ChangesSink, sleep and exit")); // We sleep and do nothing else sleep($timeout); return $notifications; } // only check once to reduce pressure in the DAV server foreach ($this->sinkdata as $k => $v) { $changed = false; $url = $this->_caldav_path . substr($k, 1) . "/"; $response = $this->_caldav->GetSync($url, false, CALDAV_SUPPORTS_SYNC); if (CALDAV_SUPPORTS_SYNC) { if (count($response) > 0) { $changed = true; ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCalDAV->ChangesSink - Changes detected")); } } else { // If the numbers of events are different, we know for sure, there are changes if (count($response) != count($v)) { $changed = true; ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCalDAV->ChangesSink - Changes detected")); } else { // If the numbers of events are equals, we compare the biggest date // FIXME: we are comparing strings no dates if (!isset($this->sinkmax[$k])) { $this->sinkmax[$k] = ''; for ($i = 0; $i < count($v); $i++) { if ($v[$i]['getlastmodified'] > $this->sinkmax[$k]) { $this->sinkmax[$k] = $v[$i]['getlastmodified']; } } } for ($i = 0; $i < count($response); $i++) { if ($response[$i]['getlastmodified'] > $this->sinkmax[$k]) { $changed = true; } } if ($changed) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCalDAV->ChangesSink - Changes detected")); } } } if ($changed) { $notifications[] = $k; } } // Wait to timeout if (empty($notifications)) { while ($stopat > time()) { sleep(1); } } return $notifications; }
/** * function connect() * Connects to a CalDAV-Server. * * Arguments: * @param $url URL to the CalDAV-server. E.g. http://exam.pl/baikal/cal.php/username/calendername/ * @param $user Username to login with * @param $pass Password to login with * * Debugging: * @throws CalDAVException * For debugging purposes, just sorround everything with try { ... } catch (Exception $e) { echo $e->__toString(); } */ function connect($url, $user, $pass) { // Connect to CalDAV-Server and log in $client = new CalDAVClient($url, $user, $pass); // Valid CalDAV-Server? Or is it just a WebDAV-Server? if (!$client->isValidCalDAVServer()) { if ($client->GetHttpResultCode() == '401') { throw new CalDAVException('Login failed', $client); } elseif ($client->GetHttpResultCode() == '') { throw new CalDAVException('Can\'t reach server', $client); } else { throw new CalDAVException('Could\'n find a CalDAV-collection under the url', $client); } } // Check for errors if ($client->GetHttpResultCode() != '200') { if ($client->GetHttpResultCode() == '401') { throw new CalDAVException('Login failed', $client); } elseif ($client->GetHttpResultCode() == '') { throw new CalDAVException('Can\'t reach server', $client); } else { throw new CalDAVException('Recieved unknown HTTP status while checking the connection after establishing it', $client); } } $this->client = $client; }
require_once '/home/www/config/dbconfig.inc.php'; require_once '/home/www/cron/functions.inc.php'; require_once '/home/www/cron/CalDAVClient.php'; // Load Settings Data $settings = settings(); date_default_timezone_set($settings['timezone']); if ($settings['oc_ical'] == true) { $url = parse_url($settings['oc_ical_url']); if ($url['scheme'] == "https") { $port = "443"; } else { $port = "80"; } $acc["davical"] = array("user" => $settings['oc_user'], "pass" => $settings['oc_pass'], "server" => $url['host'], "port" => $port, "uri" => $settings['oc_ical_url']); $account = $acc["davical"]; $cal = new CalDAVClient($account["uri"], $account["user"], $account["pass"], "", $account["server"], $account["port"]); $events = $cal->GetEvents($sta, $end); foreach ($events as $k => $event) { $ce = explode("VEVENT", $event['data']); $su = explode("SUMMARY:", $ce[1]); $su1 = explode("\n", $su[1]); preg_match("/DTSTART;(.*):(.*)/", $ce[1], $treffer); $sta = strtotime($treffer[2]); $end = strtotime($treffer[2]) + 60 * 1; $now = time(); if ($now >= $sta && $now <= $end) { $su2 = explode("_", trim($su1[0])); $lampID = trim($su2[0]); $action = trim($su2[1]); $stat = checkLightStatus($lampID); $co = getCodeById($lampID);
static function importCollection($url, $calendar) { ob_start(); require_once ROOTPATH . '/plugins/davicalCliente/caldav-client-v2.php'; $cal = new CalDAVClient(Config::service('CalDAV', 'url') . '/', Config::me('uid'), Config::me('password')); $events = $cal->GetCollectionETags($url); $args = array(); foreach ($events as $ie => $ve) { $cal->DoGETRequest($ie); $sync = Controller::parse(array('service' => 'iCal'), $cal->GetResponseBody(), array('calendar' => $calendar, 'owner' => Config::me('uidNumber'))); if (is_array($sync)) { $args = array_merge($args, $sync); } } include ROOTPATH . '/Sync.php'; ob_end_clean(); }
// Test CalDAV server // This code will do an initial sync and a second sync. require_once 'vendor/autoload.php'; define('LOGLEVEL', LOGLEVEL_DEBUG); define('LOGUSERLEVEL', LOGLEVEL_DEVICEID); // $username = "******"; // $password = "******"; // // define('CALDAV_SERVER', 'http://sogo-demo.inverse.ca'); // define('CALDAV_PORT', '80'); // define('CALDAV_PATH', '/SOGo/dav/%u/Calendar/'); // define('CALDAV_PERSONAL', 'personal'); // define('CALDAV_SUPPORTS_SYNC', true); $caldav_path = str_replace('%u', $username, CALDAV_PATH); $caldav = new CalDAVClient(CALDAV_SERVER . ":" . CALDAV_PORT . $caldav_path, $username, $password); printf("Connected %d\n", $caldav->CheckConnection()); // Show options supported by server $options = $caldav->DoOptionsRequest(); print_r($options); $calendars = $caldav->FindCalendars(); print_r($calendars); $path = $caldav_path . CALDAV_PERSONAL . "/"; $val = $caldav->GetCalendarDetails($path); print_r($val); $begin = gmdate("Ymd\\THis\\Z", time() - 24 * 7 * 60 * 60); $finish = gmdate("Ymd\\THis\\Z", 2147483647); $msgs = $caldav->GetEvents($begin, $finish, $path); print_r($msgs); // Initial sync $results = $caldav->GetSync($path, true, CALDAV_SUPPORTS_SYNC);
$acc = array(); /* * $acc["google"] = array( * "user"=>"*****@*****.**", * "pass"=>"xxxxx", * "server"=>"ssl://www.google.com", * "port"=>"443", * "uri"=>"https://www.google.com/calendar/dav/kunsttherapie@gmail.com/events/", * ); */ $acc["davical"] = array("user" => "rwr26", "pass" => "Warp\$ig7", "server" => "ssl://calendar.cs.drexel.edu", "port" => "443", "uri" => "http://rack19.cs.drexel.edu/davical/caldav.php/rwr26/home/"); //******************************* $account = $acc["davical"]; echo "Got here"; //******************************* $cal = new CalDAVClient($account["uri"], $account["user"], $account["pass"], "", $account["server"], $account["port"]); $options = $cal->DoOptionsRequest(); echo "Printing options below:"; echo print_r($options); /* * * //******************************* * //******************************* * * $xmlC = <<<PROPP * <?xml version="1.0" encoding="utf-8" ?> * <D:propfind xmlns:D="DAV:" xmlns:C="http://calendarserver.org/ns/"> * <D:prop> * <D:displayname /> * <C:getctag /> * <D:resourcetype />
function simpleCalDAVconnect($url, $user, $pass) { // Check for missing arguments if (!(isset($url) && isset($user) && isset($pass))) { return array(1, 'Missing arguments'); } // Connect to CalDAV-Server and log in $client = new CalDAVClient($url, $user, $pass); // Check for errors if (!$client->CheckValidCalDAV()) { if ($client->GetHttpResultCode() == '401') { return array(2, 'Login failed', $client->GetHttpRequest(), $client->GetBody(), $client->GetResponseHeaders(), $client->GetXmlResponse()); } elseif ($client->GetHttpResultCode() == '') { return array(3, 'Can\'t reach server', $client->GetHttpRequest(), $client->GetBody(), $client->GetResponseHeaders(), $client->GetXmlResponse()); } else { return array(4, 'Recieved unknown HTTP status while checking the connection after establishing it', $client->GetHttpRequest(), $client->GetBody(), $client->GetResponseHeaders(), $client->GetXmlResponse()); } } // set url to our calendar (CalDAV-protocol supports multiple calendars) $client->SetCalendar($url); // Is valid calendar? if (count($client->GetCalendarDetailsByURL($url)) == 0) { return array(5, 'Can\'t find the calendar on the CalDAV-server', $client->GetHttpRequest(), $client->GetBody(), $client->GetResponseHeaders(), $client->GetXmlResponse()); } return array(0, $client); }
// Test CalDAV server // This code will do an initial sync and a second sync. require_once 'vendor/autoload.php'; define('LOGLEVEL', LOGLEVEL_DEBUG); define('LOGUSERLEVEL', LOGLEVEL_DEVICEID); // $username = "******"; // $password = "******"; // // define('CALDAV_SERVER', 'http://sogo-demo.inverse.ca'); // define('CALDAV_PORT', '80'); // define('CALDAV_PATH', '/SOGo/dav/%u/Calendar/'); // define('CALDAV_PERSONAL', 'personal'); // define('CALDAV_SUPPORTS_SYNC', true); $caldav_path = str_replace('%u', $username, CALDAV_PATH); $caldav = new CalDAVClient(CALDAV_SERVER . ":" . CALDAV_PORT . $caldav_path, $username, $password); printf("Connected %d\n", $caldav->CheckConnection()); $path = $caldav_path . CALDAV_PERSONAL . "/"; $filter = <<<EOFFILTER <C:filter> <C:comp-filter name="VCALENDAR"> <C:comp-filter name="VEVENT"> <C:prop-filter name="UID"> <C:text-match>040000008200E00074C5B7101A82E00800000000B72BEB1EF3CCD00100000000000000001000000067299FC1A8990B4EB88510710DB15426</C:text-match> </C:prop-filter> </C:comp-filter> </C:comp-filter> </C:filter> EOFFILTER; $val = $caldav->DoCalendarQuery($filter, $path); print_r($val);
if (!isset($args->pass)) { usage(); } if (!isset($args->local_collection_path)) { usage(); } if (!preg_match('{/$}', $args->local_collection_path)) { $args->local_collection_path .= '/'; } if (!preg_match('{^/[^/]+/[^/]+/$}', $args->local_collection_path)) { printf("The local URL of '%s' looks wrong. It should be formed as '/username/collection/'\n", $args->local_collection_path); } if (!preg_match('{/$}', $args->url)) { $args->url .= '/'; } $caldav = new CalDAVClient($args->url, $args->user, $args->pass); // // This will find the 'Principal URL' which we can query for user-related // // properties. // $principal_url = $caldav->FindPrincipal($args->url); // // // This will find the 'Calendar Home URL' which will be the folder(s) which // // contain all of the user's calendars // $calendar_home_set = $caldav->FindCalendarHome(); // // $calendar = null; // // // This will go through the calendar_home_set and find all of the users // // calendars on the remote server. // $calendars = $caldav->FindCalendars(); // if ( count($calendars) < 1 ) { // printf( "No calendars found based on '%s'\n", $args->url );
}*/ $acc = array(); /* * $acc["google"] = array( * "user"=>"*****@*****.**", * "pass"=>"xxxxx", * "server"=>"ssl://www.google.com", * "port"=>"443", * "uri"=>"https://www.google.com/calendar/dav/kunsttherapie@gmail.com/events/", * ); **/ $acc["davical"] = array("user" => "rwr26", "pass" => "password", "server" => "ssl://calendar.cs.drexel.edu", "port" => "443", "uri" => "https://calendar.cs.drexel.edu/davical/caldav.php/rwr26/home/"); //******************************* $account = $acc["davical"]; //******************************* $cal = new CalDAVClient($account["uri"], $account["user"], $account["pass"], "", $account["server"], $account["port"]); $options = $cal->DoOptionsRequest(); echo print_r($options); $events = $cal->GetEvents("20090201T000000Z", "20120301T000000Z"); foreach ($events as $k => $event) { echo print_r("Data" . $event['data']); //echo print "\n---------------------------------------------\n"; } //echo print_r($events); //echo count($events); //echo $events["data"]; /* foreach ( $events as $k => $event ) { echo print_r($event['data']); echo print "\n---------------------------------------------\n"; }