Lines Matching +full:- +full:- +full:strip +full:- +full:components
26 $this->syncChangeLogFile = $conf['metadir'].'/.webdavclient/synclog';
28 $this->client = new DokuHTTPClient();
29 $client_headers = $this->client->headers;
37 if($this->sqlite === null)
39 $this->sqlite = plugin_load('helper', 'sqlite');
40 if(!$this->sqlite)
43 msg('This plugin requires the sqlite plugin. Please install it.', -1);
46 if(!$this->sqlite->init('webdavclient', DOKU_PLUGIN.'webdavclient/db/'))
48 $this->sqlite = null;
53 return $this->sqlite;
63 return $this->lastErr;
77 $conn = $this->getConnection($connectionId);
80 $conn = array_merge($conn, $this->getCredentials($connectionId));
81 $this->setupClient($conn, strlen($data), null, 'text/calendar; charset=utf-8');
82 $path = $conn['uri'].'/'.uniqid('dokuwiki-').'.ics';
83 $resp = $this->client->sendRequest($path, $data, 'PUT');
84 if($this->client->status == 201)
86 $this->syncConnection($conn['id'], true);
89 $this->lastErr = 'Error adding calendar entry, server reported status '.$this->client->status;
104 $conn = $this->getConnection($connectionId);
107 $conn = array_merge($conn, $this->getCredentials($connectionId));
108 $entry = $this->getCalendarEntryByUid($uid);
110 …$this->setupClient($conn, strlen($data), null, 'text/calendar; charset=utf-8', array('If-Match' =>…
112 $resp = $this->client->sendRequest($path, $data, 'PUT');
113 if($this->client->status == 204)
115 $this->syncConnection($conn['id'], true);
118 … $this->lastErr = 'Error editing calendar entry, server reported status '.$this->client->status;
133 $conn = $this->getConnection($connectionId);
136 $conn = array_merge($conn, $this->getCredentials($connectionId));
137 $entry = $this->getCalendarEntryByUid($uid);
139 …$this->setupClient($conn, strlen($data), null, 'text/calendar; charset=utf-8', array('If-Match' =>…
141 $resp = $this->client->sendRequest($path, '', 'DELETE');
142 if($this->client->status == 204)
144 $this->syncConnection($conn['id'], true);
147 … $this->lastErr = 'Error deleting calendar entry, server reported status '.$this->client->status;
160 $sqlite = $this->getDB();
164 $res = $sqlite->query($query, $uid);
165 return $sqlite->res2row($res);
178 $sqlite = $this->getDB();
182 $res = $sqlite->query($query, $connectionId, $uri);
183 return $sqlite->res2row($res);
196 $sqlite = $this->getDB();
200 $res = $sqlite->query($query, $connectionId, $uri);
201 return $sqlite->res2row($res);
213 $sqlite = $this->getDB();
216 $conn = $this->getConnection($connectionId);
222 $sqlite->query($query, $connectionId);
227 $sqlite->query($query, $connectionId);
230 $res = $sqlite->query($query, $connectionId);
233 $this->lastErr = "Error deleting connection.";
251 $sqlite = $this->getDB();
260 $query .= " AND lastoccurence > ".$sqlite->quote_string($startTs->getTimestamp());
265 $query .= " AND firstoccurence < ".$sqlite->quote_string($endTs->getTimestamp());
267 $res = $sqlite->query($query, $connectionId);
268 return $sqlite->res2arr($res);
282 $conn = $this->getConnection($connectionId);
285 $conn = array_merge($conn, $this->getCredentials($connectionId));
286 $this->setupClient($conn, strlen($data), null, 'text/vcard; charset=utf-8');
287 $path = $conn['uri'].'/'.uniqid('dokuwiki-').'.vcf';
288 $resp = $this->client->sendRequest($path, $data, 'PUT');
289 if($this->client->status == 201)
291 $this->syncConnection($conn['id'], true);
294 … $this->lastErr = 'Error adding addressbook entry, server reported status '.$this->client->status;
310 $conn = $this->getConnection($connectionId);
313 $conn = array_merge($conn, $this->getCredentials($connectionId));
314 $entry = $this->getAddressbookEntryByUri($connectionId, $uri);
316 …$this->setupClient($conn, strlen($data), null, 'text/vcard; charset=utf-8', array('If-Match' => $e…
318 $resp = $this->client->sendRequest($path, $data, 'PUT');
319 if($this->client->status == 204)
321 $this->syncConnection($conn['id'], true);
324 … $this->lastErr = 'Error editing addressbook entry, server reported status '.$this->client->status;
339 $conn = $this->getConnection($connectionId);
342 $conn = array_merge($conn, $this->getCredentials($connectionId));
343 $entry = $this->getAddressbookEntryByUri($connectionId, $uri);
345 …$this->setupClient($conn, strlen($data), null, 'text/vcard; charset=utf-8', array('If-Match' => $e…
347 $resp = $this->client->sendRequest($path, '', 'DELETE');
348 if($this->client->status == 204)
350 $this->syncConnection($conn['id'], true);
353 …$this->lastErr = 'Error deleting addressbook entry, server reported status '.$this->client->status;
367 $sqlite = $this->getDB();
371 $res = $sqlite->query($query, $connectionId);
372 return $sqlite->res2arr($res);
375 /** Delete all entries from a WebDAV resource - be careful!
381 $conn = $this->getConnection($connectionId);
385 $entries = $this->getAddressbookEntries($connectionId);
388 $this->deleteAddressbookEntry($connectionId, $entry['uri']);
392 $entries = $this->getCalendarEntries($connectionId);
395 $this->deleteCalendarEntry($connectionId, $entry['uid']);
419 $sqlite = $this->getDB();
424 …$res = $sqlite->query($query, $uri, $displayname, $description, $username, $password, $dwuser, $ty…
427 $this->lastErr = "Error inserting values into SQLite DB";
433 …$res = $sqlite->query($query, $uri, $displayname, $description, $username, $password, $dwuser, $ty…
434 $row = $sqlite->res2row($res);
439 $this->lastErr = "Error retrieving new connection ID from SQLite DB";
457 $sqlite = $this->getDB();
461 … $res = $sqlite->query($query, $permission, $displayname, $syncinterval, $write, $active, $connId);
465 $this->lastErr = "Error modifying connection information";
476 $sqlite = $this->getDB();
480 $res = $sqlite->query($query);
481 return $sqlite->res2arr($res);
493 $sqlite = $this->getDB();
497 $res = $sqlite->query($query, $connectionId);
498 return $sqlite->res2row($res);
510 $sqlite = $this->getDB();
514 $res = $sqlite->query($query, $connectionId);
515 return $sqlite->res2row($res);
521 * 1) Do a PROPFIND on / and try to follow .well-known URLs
550 // as well as the .well-known URLs
552 'https://'.$uri.'/.well-known/caldav',
553 'http://'.$uri.'/.well-known/caldav',
554 'https://'.$uri.'/.well-known/carddav',
555 'http://'.$uri.'/.well-known/carddav');
560 $data = $this->buildPropfind(array('D:current-user-principal'));
565 $this->setupClient($conn, strlen($data), ' 0',
566 'application/xml; charset=utf-8', array(),
574 $this->client->sendRequest($uri, $data, 'PROPFIND');
575 switch($this->client->status)
586 array_unshift($urilist, $this->client->resp_headers['location']);
594 $response = $this->parseResponse();
597 $components = parse_url($uri);
598 if(isset($params['current-user-principal']['href']))
599 $discoveredUris[] = $components['scheme'].'://'.
600 $components['host'].
601 $params['current-user-principal']['href'];
611 $discoveredUris = $this->postprocessUris($discoveredUris);
615 // Go through all discovered URLs and do a PROPFIND for calendar-home-set
616 // and for addressbook-home-set
619 $data = $this->buildPropfind(array('C:calendar-home-set'),
621 $this->setupClient($conn, strlen($data), ' 0');
622 $this->client->sendRequest($uri, $data, 'PROPFIND');
623 if($this->client->status == 207)
625 $response = $this->parseResponse();
628 if(isset($params['calendar-home-set']['href']))
630 $components = parse_url($uri);
631 $calendarhomes[] = $components['scheme'].'://'.
632 $components['host'].
633 $params['calendar-home-set']['href'];
638 $data = $this->buildPropfind(array('C:addressbook-home-set'),
640 $this->setupClient($conn, strlen($data), ' 0');
641 $this->client->sendRequest($uri, $data, 'PROPFIND');
642 if($this->client->status == 207)
644 $response = $this->parseResponse();
647 if(isset($params['addressbook-home-set']['href']))
649 $components = parse_url($uri);
650 $addressbookhomes[] = $components['scheme'].'://'.
651 $components['host'].
652 $params['addressbook-home-set']['href'];
663 $data = $this->buildPropfind(array('D:resourcetype', 'D:displayname',
664 'CS:getctag', 'C:supported-calendar-component-set'),
667 $this->setupClient($conn, strlen($data), '1');
668 $this->client->sendRequest($uri, $data, 'PROPFIND');
669 $response = $this->parseResponse();
670 … $webdavobjects['calendars'] = $this->getSupportedCalendarsFromDavResponse($uri, $response);
675 $data = $this->buildPropfind(array('D:resourcetype', 'D:displayname', 'CS:getctag'),
677 $this->setupClient($conn, strlen($data), '1');
678 $this->client->sendRequest($uri, $data, 'PROPFIND');
679 $response = $this->parseResponse();
680 … $webdavobjects['addressbooks'] = $this->getSupportedAddressbooksFromDavResponse($uri, $response);
702 if(!isset($data['supported-calendar-component-set']['comp']['name']))
704 if((is_array($data['supported-calendar-component-set']['comp']['name']) &&
705 !in_array('VEVENT', $data['supported-calendar-component-set']['comp']['name'])) ||
706 (!is_array($data['supported-calendar-component-set']['comp']['name']) &&
707 $data['supported-calendar-component-set']['comp']['name'] != 'VEVENT'))
710 $components = parse_url($uri);
711 $href = $components['scheme'].'://'.$components['host'].$href;
732 $components = parse_url($uri);
733 $href = $components['scheme'].'://'.$components['host'].$href;
785 $conn = $this->getConnection($connectionId);
788 $this->lastErr = "Error retrieving connection information from SQLite DB";
791 $conn = array_merge($conn, $this->getCredentials($connectionId));
799 $this->lastErr = "Sync not required (time)";
807 $this->lastErr = "Connection not active";
816 $this->lastErr = "Unsupported connection type found: ".$conn['type'];
824 return $this->syncConnectionFeed($conn, $force);
829 return $this->syncConnectionDAV($conn, $force, $deleteBeforeSync);
842 $this->setupClient($conn, null, null, null);
843 $resp = $this->client->sendRequest($conn['uri']);
844 if(($this->client->status >= 400) || ($this->client->status < 200))
846 dbglog('Error: Status reported was ' . $this->client->status);
847 $this->lastErr = "Error: Server reported status ".$this->client->status;
850 $caldata = $this->client->resp_body;
856 $sqlite = $this->getDB();
860 $sqlite->query("BEGIN TRANSACTION");
863 $sqlite->query($query, $conn['id']);
865 foreach ($vObject->getComponents() as $component)
867 $componentType = $component->name;
872 $calendarObject->add($component);
873 $calendarData['calendar-data'] = $calendarObject->serialize();
875 $calendarData['getetag'] = md5($calendarData['calendar-data']);
876 $this->object2calendar($conn['id'], $calendarData);
879 $sqlite->query("COMMIT TRANSACTION");
881 $this->updateConnection($conn['id'], time());
895 $syncResponse = $this->getCollectionStatusForConnection($conn);
904 $this->updateConnection($conn['id'], time(), $conn['ctag']);
905 $this->lastErr = "CTags match, there is no need to sync";
913 $remoteEtags = $this->getRemoteETagsForConnection($conn);
917 $this->lastErr = "Fetching ETags from remote server failed.";
921 $sqlite = $this->getDB();
931 $sqlite->query($query, $conn['id']);
936 $sqlite->query($query, $conn['id']);
940 $localEtags = $this->getLocalETagsForConnection($conn);
944 $this->lastErr = "Fetching ETags from local database failed.";
948 $worklist = $this->compareETags($remoteEtags, $localEtags);
951 $sqlite->query("BEGIN TRANSACTION");
956 $objects = $this->getRemoteObjectsByEtag($conn, $worklist['fetch']);
959 $this->lastErr = "Fetching remote objects by ETag failed.";
960 $sqlite->query("ROLLBACK TRANSACTION");
964 $this->insertObjects($conn, $objects);
970 $this->deleteEntriesByETag($conn, $worklist['del']);
973 $sqlite->query("COMMIT TRANSACTION");
975 $this->updateConnection($conn['id'], time(), $syncResponse['getctag']);
995 $this->object2calendar($conn['id'], $data);
999 $this->object2addressbook($conn['id'], $data);
1003 $this->lastErr = "Unsupported type.";
1032 $this->lastErr = "Unsupported type.";
1035 $sqlite = $this->getDB();
1041 $sqlite->query($query, $etag, $conn['id']);
1058 …$data = $this->buildReport('C:addressbook-multiget', array('C' => 'urn:ietf:params:xml:ns:carddav'…
1060 'C:address-data'), array(),
1065 … $data = $this->buildReport('C:calendar-multiget', array('C' => 'urn:ietf:params:xml:ns:caldav'),
1067 'C:calendar-data'),
1071 $this->setupClient($conn, strlen($data), '1');
1072 $resp = $this->client->sendRequest($conn['uri'], $data, 'REPORT');
1073 $response = $this->parseResponse();
1111 * @param string $cl (Optional) The Content-Length parameter
1113 * @param string $ct (Optional) The Content-Type
1118 $ct = 'application/xml; charset=utf-8', $headers = array(),
1121 $this->client->user = $conn['username'];
1122 $this->client->pass = $conn['password'];
1123 $this->client->http = '1.1';
1124 $this->client->max_redirect = $redirect;
1126 $this->client->keep_alive = false;
1129 $this->client->headers = $this->client_headers;
1131 $this->client->headers[$header] = $content;
1133 $this->client->headers['Content-Type'] = $ct;
1135 $this->client->headers['Depth'] = $depth;
1137 $this->client->headers['Content-Length'] = $cl;
1162 $this->lastErr = "Unsupported type.";
1165 $sqlite = $this->getDB();
1169 $res = $sqlite->query($query, $conn['id']);
1170 $data = $sqlite->res2arr($res);
1186 … $data = $this->buildReport('C:addressbook-query', array('C' => 'urn:ietf:params:xml:ns:carddav'),
1191 … $data = $this->buildReport('C:calendar-query', array('C' => 'urn:ietf:params:xml:ns:caldav'),
1193 array('C:comp-filter' => array('VCALENDAR' => 'VEVENT')));
1197 $this->lastErr = "Unsupported type.";
1200 $this->setupClient($conn, strlen($data), '1');
1201 $resp = $this->client->sendRequest($conn['uri'], $data, 'REPORT');
1202 $etags = $this->parseResponse();
1214 if(($this->client->status >= 400) || ($this->client->status < 200))
1216 dbglog('Error: Status reported was ' . $this->client->status);
1217 $this->lastErr = "Error: Server reported status ".$this->client->status;
1221 dbglog($this->client->status);
1222 dbglog($this->client->error);
1224 $response = $this->clean_response($this->client->resp_body);
1231 dbglog('Exception occured: '.$e->getMessage());
1232 $this->lastErr = "Exception occured while parsing response: ".$e->getMessage();
1238 if(!empty($xml->response))
1240 foreach($xml->response as $response)
1242 $href = (string)$response->href;
1243 $status = $this->parseHttpStatus((string)$response->propstat->status);
1248 $data[$href] = $this->recursiveXmlToArray($response->propstat->prop->children());
1269 if($object->count() > 0)
1271 $ret[$object->getName()] = $this->recursiveXmlToArray($object->children());
1274 elseif(!is_null($object->attributes()) && (count($object->attributes()) > 0))
1278 if(!is_array($ret[$object->getName()]))
1279 $ret[$object->getName()] = array();
1280 foreach($object->attributes() as $key => $val)
1284 if(isset($ret[$object->getName()][(string)$key]) &&
1285 !is_array($ret[$object->getName()][(string)$key]))
1287 $ret[$object->getName()][(string)$key] =
1288 array($ret[$object->getName()][(string)$key], trim((string)$val, '"'));
1291 elseif(isset($ret[$object->getName()][(string)$key]) &&
1292 is_array($ret[$object->getName()][(string)$key]))
1294 $ret[$object->getName()][(string)$key][] = trim((string)$val, '"');
1300 $ret[$object->getName()][(string)$key] = trim((string)$val, '"');
1307 $ret[$object->getName()] = trim((string)$object, '"');
1322 …$data = $this->buildPropfind(array('D:displayname', 'CS:getctag', 'D:sync-token'), array('CS' => '…
1323 $this->setupClient($conn, strlen($data), ' 0');
1325 $resp = $this->client->sendRequest($conn['uri'], $data, 'PROPFIND');
1327 $response = $this->parseResponse();
1330 $this->lastErr = "Error: Unexpected response from server";
1353 io_saveFile($this->syncChangeLogFile.$connectionId, serialize($lastSynced));
1355 $sqlite = $this->getDB();
1359 $res = $sqlite->query($query, $lastSynced, $ctag, $connectionId);
1362 $this->lastErr = "Error updating connection";
1377 $extradata = $this->getDenormalizedCalendarData($calendarobject['calendar-data']);
1381 $this->lastErr = "Couldn't parse calendar data";
1385 $sqlite = $this->getDB();
1390 …$res = $sqlite->query($query, $calendarobject['calendar-data'], $calendarobject['href'], $connecti…
1393 $this->lastErr = "Error inserting object";
1408 $extradata = $this->getDenormalizedContactData($addressobject['address-data']);
1412 $this->lastErr = "Couldn't parse contact data";
1416 $sqlite = $this->getDB();
1423 $res = $sqlite->query($query,
1424 $addressobject['address-data'],
1427 $lastmod->getTimestamp(),
1435 $this->lastErr = "Error inserting object";
1466 // Strip the namespace prefixes on all XML tags
1483 $xml->openMemory();
1484 $xml->setIndent(4);
1485 $xml->startDocument('1.0', 'utf-8');
1486 $xml->startElement('D:propfind');
1487 $xml->writeAttribute('xmlns:D', 'DAV:');
1489 $xml->writeAttribute('xmlns:'.$key, $val);
1490 $xml->startElement('D:prop');
1492 $xml->writeElement($prop);
1493 $xml->endElement();
1494 $xml->endElement();
1495 $xml->endDocument();
1496 return $xml->outputMemory()."\r\n";
1512 $xml->openMemory();
1513 $xml->setIndent(4);
1514 $xml->startDocument('1.0', 'utf-8');
1515 $xml->startElement($op);
1516 $xml->writeAttribute('xmlns:D', 'DAV:');
1518 $xml->writeAttribute('xmlns:'.$key, $val);
1519 $xml->startElement('D:prop');
1522 $xml->writeElement($prop);
1524 $xml->endElement();
1527 $xml->startElement('C:filter');
1532 $xml->startElement($filter);
1533 $xml->writeAttribute('name', $key);
1536 $xml->startElement($filter);
1537 $xml->writeAttribute('name', $val);
1538 $xml->endElement();
1540 $xml->endElement();
1543 $xml->endElement();
1547 $xml->writeElement('D:href', $href);
1549 $xml->endElement();
1550 $xml->endDocument();
1551 return $xml->outputMemory()."\r\n";
1559 $connections = $this->getConnections();
1562 $this->syncConnection($connection['id']);
1577 $connections = $this->getConnections();
1580 if($this->syncConnection($connection['id']) === true)
1595 return $this->getConf($key);
1600 * for optimized addressbook-queries.
1614 if(isset($vObject->FN))
1615 $formattedname = (string)$vObject->FN;
1617 if(isset($vObject->N))
1618 $structuredname = join(';', $vObject->N->getParts());
1629 * calendar-queries.
1632 * * etag - An md5 checksum of the object without the quotes.
1633 * * size - Size of the object in bytes
1634 * * componentType - VEVENT, VTODO or VJOURNAL
1637 * * uid - value of the UID property
1652 foreach ($vObject->getComponents() as $component)
1654 if ($component->name !== 'VTIMEZONE')
1656 $componentType = $component->name;
1657 $uid = (string)$component->UID;
1667 $firstOccurence = $component->DTSTART->getDateTime()->getTimeStamp();
1669 if (!isset($component->RRULE))
1671 if (isset($component->DTEND))
1673 $lastOccurence = $component->DTEND->getDateTime()->getTimeStamp();
1675 elseif (isset($component->DURATION))
1677 $endDate = clone $component->DTSTART->getDateTime();
1678 … $endDate->add(\Sabre\VObject\DateTimeParser::parse($component->DURATION->getValue()));
1679 $lastOccurence = $endDate->getTimeStamp();
1681 elseif (!$component->DTSTART->hasTime())
1683 $endDate = clone $component->DTSTART->getDateTime();
1684 $endDate->modify('+1 day');
1685 $lastOccurence = $endDate->getTimeStamp();
1694 $it = new \Sabre\VObject\Recur\EventIterator($vObject, (string)$component->UID);
1695 $maxDate = new \DateTime('2038-01-01');
1696 if ($it->isInfinite())
1698 $lastOccurence = $maxDate->getTimeStamp();
1702 $end = $it->getDtEnd();
1703 while ($it->valid() && $end < $maxDate)
1705 $end = $it->getDtEnd();
1706 $it->next();
1708 $lastOccurence = $end->getTimeStamp();
1733 return $this->syncChangeLogFile.$connectionId;