Mit dem angehängten Modul auf der Basis des CalDAV-Moduls von Johannes Willnecker lässt sich ein NextCloud- bzw. OwnCloud-Kalender einbinden.
Dazu ist nötig:
der Servername (http oder https)
Username und Passwort für den Server (falls https mit Anmeldung eingerichtet ist) - <user> / <pass>
Username und Passwort für NextCloud (bei mir identisch mit Serveranmeldung. Unterschiedliche Logins für HTTPS und NextCloud werden derzeit noch nicht unterstützt.
Namen des Kalenders bzw Liste der Kalender (mit Komma getrennt) <calendar>
Da über die Smartvisu-Konfiguration nicht sinnvoll alle Kombinationen abgedeckt werden können, muss die URL im Konfigurationsfeld Kalender die folgenden Elemente enthalten:
Falls eine ältere Version von OwnCloud im Einsatz ist, muss die URL ggf. noch angepasst werden. In der Kalender-App kann der Link für den jeweiligen Kalender abgerufen werden.
Wenn man dann im Beschreibungsfeld des Kalenders die Daten wie folgt eingibt
(hinter das @ gehört kein Leerzeichen!) dann zeigt er das Mülltonnensymbol in der entsprechenden Farbe an.
lib/calendar/service/nextcloud.php:
Danke für die Fehlerbehebungen an offline und gnarrf!
Dazu ist nötig:
der Servername (http oder https)
Username und Passwort für den Server (falls https mit Anmeldung eingerichtet ist) - <user> / <pass>
Username und Passwort für NextCloud (bei mir identisch mit Serveranmeldung. Unterschiedliche Logins für HTTPS und NextCloud werden derzeit noch nicht unterstützt.
Namen des Kalenders bzw Liste der Kalender (mit Komma getrennt) <calendar>
Da über die Smartvisu-Konfiguration nicht sinnvoll alle Kombinationen abgedeckt werden können, muss die URL im Konfigurationsfeld Kalender die folgenden Elemente enthalten:
Code:
http(s)://<user>:<pass>@<server>/remote.php/dav/calendars/<caluser>/
Wenn man dann im Beschreibungsfeld des Kalenders die Daten wie folgt eingibt
Code:
@ icon icons/ws/message_garbage.svg @ color #cccc00
lib/calendar/service/nextcloud.php:
Code:
<?php /** * ----------------------------------------------------------------------------- * @package smartVISU * @author Johannes Willnecker, Sebastian Helms * @copyright 2015 * @license GPL [http://www.gnu.de] * ----------------------------------------------------------------------------- */ require_once '../../../lib/includes.php'; require_once const_path_system.'calendar/calendar.php'; /** * This class reads a caldav calendar */ class calendar_caldav extends calendar { private function startElement($element) { if(strcmp($element,"VEVENT") == 0) { $this->vevent = array( 'start' => date('y-m-d', 0).' '.gmdate('H:i:s', 0), 'end' => date('y-m-d', 0).' '.gmdate('H:i:s', 0), 'title' => (string)(""), 'content' => (string)(""), 'where' => (string)(""), 'link' => (string)("") ); $this->startts = 0; $this->inVEVENT = true; } } private function endElement($element) { if($element == 'VEVENT') { $this->startdatearray[] = $this->startts; $this->data[] = $this->vevent; $this->inVEVENT = false; } } private function Value($name, $value) { if($this->inVEVENT == true) { if($name == 'SUMMARY') { $this->vevent['title'] = (string)($value); } if($name == 'DESCRIPTION') { $this->vevent['content'] = (string)($value); foreach (explode("\\n", $value) as $line) { preg_match_all('/@([^ ]+) +(.*)$/', $line, $items); if ($items[1][0] == "icon" or $items[1][0] == "color") { $this->vevent[$items[1][0]] = (string)$items[2][0]; } } } if($name == 'LOCATION') { $this->vevent['where'] = (string)($value); } if($name == 'DTSTART') { preg_match('/((.*)=(.*):)?(.*)/', $value, $matches); //TODO TZID handling date_default_timezone_set('Europe/Berlin'); $ts = strtotime($matches[4]) + date("Z", strtotime($matches[4])); $this->startts = $ts; $this->vevent['start'] = date('y-m-d', $ts).' '.gmdate('H:i:s', $ts); } if($name == 'DTEND') { preg_match('/((.*)=(.*):)?(.*)/', $value, $matches); //TODO TZID handling date_default_timezone_set('Europe/Berlin'); $ts = strtotime($matches[4]) + date("Z", strtotime($matches[4])); $this->vevent['end'] = date('y-m-d', $ts).' '.gmdate('H:i:s', $ts); } } } private function get_caldav_calendar($url) { $calStart = gmdate("Ymd\THis\Z"); $calEnd = gmdate("Ymd\THis\Z", strtotime("+4 weeks")); $postdata = "<C:calendar-query xmlns:D=\"DAV:\" xmlns:C=\"urn:ietf:params:xml:ns:caldav\"> <D:prop> <C:calendar-data> <C:expand start=\"".$calStart."\" end=\"".$calEnd."\"/> </C:calendar-data> </D:prop> <C:filter> <C:comp-filter name=\"VCALENDAR\"> <C:comp-filter name=\"VEVENT\"> <C:time-range start=\"".$calStart."\" end=\"".$calEnd."\"/> </C:comp-filter> </C:comp-filter> </C:filter> </C:calendar-query>"; $ctxopts = array('http' => array( 'method' => 'REPORT', 'header' => "Depth: 1\r\n", "Content-Type: application/xml\r\n", 'content' => $postdata ) ); $context = stream_context_create($ctxopts); $content = file_get_contents($url, false, $context); return $content; } public function run() { $srcurl = $this->url; if (strpos(config_calendar_name, ",") > 0) { $snippets = explode(",", config_calendar_name); } else { $snippets[] = config_calendar_name; } if (substr($srcurl,-1) !== "/" and $snippets[0] !== "") { $srcurl .= "/"; } foreach ($snippets as $snippet) { $urls[] = $srcurl . $snippet; } foreach ($urls as $url) { $content = $this->get_caldav_calendar($url); $this->debug($content); if ($content !== false) { $xmls[] = simplexml_load_string($content); } } foreach($xmls as $xml) { if ($xml !== false) { $this->i = 1; foreach ($xml->children('d', true) as $entry) { foreach ($entry->propstat->prop->children('cal',true) as $cal) { if($cal->getName() == 'calendar-data') { $cal = str_replace (array("\r\n ", "\n ", "\r "), '', $cal); preg_match_all('/(.[^;|:]*)?(;|:)(.*)/', $cal, $matches, PREG_SET_ORDER); foreach($matches as $values) { if($values[1] == 'BEGIN') { $this->startElement(trim($values[3])); } else if($values[1] == 'END') { $this->endElement(trim($values[3])); } else { $this->Value($values[1], trim($values[3])); } } } } } } else { $this->error('Calendar: caldav', 'caldav: Calendar read request failed!'); } } //order events: array_multisort($this->startdatearray, SORT_ASC, $this->data); $i = 1; foreach($this->data as $key => $value) { $this->data[$key]['pos'] = $i++; } $this->data = array_slice($this->data, 0, $this->count); } } // ----------------------------------------------------------------------------- // call the service // ----------------------------------------------------------------------------- $service = new calendar_caldav(array_merge($_GET, $_POST)); echo $service->json(); ?>
Danke für die Fehlerbehebungen an offline und gnarrf!
Kommentar