Skip to content

Commit

Permalink
Merge pull request #15 from SelcalHF/master
Browse files Browse the repository at this point in the history
Small bugfixes and new function implementation
  • Loading branch information
carduz authored Oct 1, 2024
2 parents bdf6ea2 + 3e3ff34 commit ddf97e1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/CalDAVClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class CalDAVClient {
private $httpResponseBody = '';

protected $parser; // our XML parser object
protected $request_url = "";
protected $xmlnodes = array();
protected $xmltags = array();

// Requests timeout
private $timeout;
Expand Down Expand Up @@ -176,11 +179,10 @@ function DoOptionsRequestAndGetDAVHeader( $url = null ) {
$headers = preg_split('/\r?\n/', $headers);

// DAV header(s)
$dav_header = preg_grep('/^DAV:/', $headers);
$dav_header = preg_grep('/^DAV:/i', $headers); // /i for case insensitive as some servers (example Nextcloud) do not send uppercase headers
if (is_array($dav_header)) {
$dav_header = array_values($dav_header);
$dav_header = preg_replace('/^DAV: /', '', $dav_header);

$dav_header = preg_replace('/^DAV: /i', '', $dav_header); // /i for case insensitive
$dav_options = array();

foreach ($dav_header as $d) {
Expand Down
27 changes: 27 additions & 0 deletions src/SimpleCalDAVClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,33 @@ function getEvents ( $start = null, $end = null )
return $report;
}

/**
* function getEventByGuid( $guid )
* Gets an events from the CalDAV-Server with specified UID.
*
* Arguments:
* @param string $guid UID of the iCal requested.
*
* Return value:
* @return array an array of arrays containing ['href'], ['etag'] and the iCal in ['data'] for the found event.
*
*/
function getEventByGuid ( $guid )
{
// Connection and calendar set?
if(!isset($this->client)) throw new CalDAVException('No connection. Try connect().', $this->client);
if(!isset($this->client->calendar_url)) throw new CalDAVException('No calendar selected. Try findCalendars() and setCalendar().', $this->client);

// Get it!
$data = $this->client->GetEntryByUid($guid);
foreach ($data as &$element) {
$element['href'] = $this->client->calendar_url . $element['href'];
unset($element);
}
return $data;

}

/**
* function getTODOs()
* Gets a all TODOs from the CalDAV-Server which lie in a defined time interval and match the
Expand Down

0 comments on commit ddf97e1

Please sign in to comment.