Caldav-client-v2: Difference between revisions

From Supporting Role Wiki
Jump to navigationJump to search
 
(7 intermediate revisions by the same user not shown)
Line 2: Line 2:


== CalDAVClient ==
== CalDAVClient ==

=== Usage and Examples ===
Connect to the resource.
<code>$cal = new CalDAVClient(server, username, password, calendar);</code>


<pre>
/**
* Usage example
*
* $cal = new CalDAVClient( "http://calendar.example.com/caldav.php/username/calendar/", "username", "password", "calendar" );
* $options = $cal->DoOptionsRequest();
* if ( isset($options["PROPFIND"]) ) {
* // Fetch some information about the events in that calendar
* $cal->SetDepth(1);
* $folder_xml = $cal->DoXMLRequest("PROPFIND", '<?xml version="1.0" encoding="utf-8" ?><propfind xmlns="DAV:"><prop><getcontentleng
th/><getcontenttype/><resourcetype/><getetag/></prop></propfind>' );
* }
* // Fetch all events for February
* $events = $cal->GetEvents("20070101T000000Z","20070201T000000Z");
* foreach ( $events AS $k => $event ) {
* do_something_with_event_data( $event['data'] );
* }
* $acc = array();
* $acc["google"] = array(
* "user"=>"kunsttherapie@gmail.com",
* "pass"=>"xxxxx",
* "server"=>"ssl://www.google.com",
* "port"=>"443",
* "uri"=>"https://www.google.com/calendar/dav/kunsttherapie@gmail.com/events/",
* );
*
* $acc["davical"] = array(
* "user"=>"some_user",
* "pass"=>"big secret",
* "server"=>"calendar.foo.bar",
* "port"=>"80",
* "uri"=>"http://calendar.foo.bar/caldav.php/some_user/home/",
* );
* //*******************************
*
* $account = $acc["davical"];
*
* //*******************************
* $cal = new CalDAVClient( $account["uri"], $account["user"], $account["pass"], "", $account["server"], $account["port"] );
* $options = $cal->DoOptionsRequest();
* 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 />
*
* </D:prop>
* </D:propfind>
* PROPP;
* //if ( isset($options["PROPFIND"]) ) {
* // Fetch some information about the events in that calendar
* // $cal->SetDepth(1);
* // $folder_xml = $cal->DoXMLRequest("PROPFIND", $xmlC);
* // print_r( $folder_xml);
* //}
*
* // Fetch all events for February
* $events = $cal->GetEvents("20090201T000000Z","20090301T000000Z");
* foreach ( $events as $k => $event ) {
* print_r($event['data']);
* print "\n---------------------------------------------\n";
* }
*
* //*******************************
* //*******************************
*/
</pre>


=== Variables ===
=== Variables ===
Line 20: Line 100:


=== Functions ===
=== Functions ===
*<pre>__construct</pre>
*<pre>__construct( $base_url, $user, $pass ) // Constructor, initialises the class</pre>
** @param string $base_url The URL for the calendar server
*:
** @param string $user The name of the user logging in
*<pre>SetMatch</pre>
** @param string $pass The password for that user
*:Info

*<pre>SetDepth</pre>
*<pre>SetMatch( $match, $etag = '*' ) // Adds an If-Match or If-None-Match header</pre>
*:Info
** @param bool $match to Match or Not to Match, that is the question!
*<pre>SetUserAgent</pre>
** @param string $etag The etag to match / not match against.
*<pre>SetContentType</pre>

*<pre>SetCalendar</pre>
*<pre>SetDepth( $depth = '0' ) // Add a Depth: header. Valid values are 0, 1 or infinity</pre>
*<pre>ParseResponse</pre>
** @param int $depth The depth, default to infinity
*<pre>GetHttpRequest</pre>

*<pre>GetResponseHeaders</pre>
*<pre>SetUserAgent( $user_agent = null ) // Sets User Agent</pre>
*<pre>GetResponseBody</pre>
** @param int $user_agent The User Agent String to set. Defaults to predefined class variable if blank
*<pre>GetXmlRequest()</pre>

*<pre>GetXmlResponse()</pre>
*<pre>DoRequest( $url = null )</pre>
*<pre>SetContentType( $type ) // Add a Content-type: header</pre>
** @param string $type The content type
*<pre>Unchunk()</pre>

*<pre>DoOptionsRequest( $url = null )</pre>
*<pre>SetCalendar( $url ) // Set the calendar_url we will be using for a while.</pre>
*<pre>DoXMLRequest( $request_method, $xml, $url = null )</pre>
** @param string $url The calendar_url
*<pre>DoGETRequest( $url )</pre>

*<pre>DoHEADRequest( $url )</pre>
*<pre>ParseResponse( $response ) // Split response into httpResponse and xmlResponse</pre>
** @param string Response from server

*<pre>GetHttpRequest // Output http request headers</pre>
** @return HTTP headers

*<pre>GetResponseHeaders() // Output http response headers</pre>
** @return HTTP headers

*<pre>GetResponseBody() // Output http response body</pre>
** @return HTTP body

*<pre>GetXmlRequest() // Output xml request</pre>
** @return raw xml

*<pre>GetXmlResponse() // Output xml response</pre>
** @return raw xml

*<pre>DoRequest( $url = null ) // Send a request to the server</pre>
** @param string $url The URL to make the request to
** @return string The content of the response from the server

*<pre>Unchunk() // Unchunk a chunked response</pre>

*<pre>DoOptionsRequest( $url = null ) // Send an OPTIONS request to the server</pre>
** @param string $url The URL to make the request to
** @return array The allowed options

*<pre>DoXMLRequest( $request_method, $xml, $url = null ) // Send an XML request to the server (PROPFIND, REPORT, MKCALENDAR)</pre>
** @param string $method The method (PROPFIND, REPORT, etc) to use with the request
** @param string $xml The XML to send along with the request
** @param string $url The URL to make the request to
** @return array An array of the allowed methods

*<pre>DoGETRequest( $url ) // Get a single item from the server.</pre>
** @param string $url The URL to GET

*<pre>DoHEADRequest( $url ) // Get the HEAD of a single item from the server.</pre>
** @param string $url The URL to HEAD

*<pre>DoPUTRequest( $url, $icalendar, $etag = null )</pre>
*<pre>DoPUTRequest( $url, $icalendar, $etag = null )</pre>


*<pre>DoDELETERequest( $url, $etag = null )</pre>
*<pre>DoDELETERequest( $url, $etag = null )</pre>
*<pre>DoPROPFINDRequest( $url, $props, $depth = 0 )</pre>
*<pre>DoPROPFINDRequest( $url, $props, $depth = 0 )</pre>

Latest revision as of 17:22, 18 August 2014

This page holds some basic info on the Davical caldav-client-v2 library that ships with Davical.

CalDAVClient

Usage and Examples

Connect to the resource. $cal = new CalDAVClient(server, username, password, calendar);


/**
* Usage example
*
* $cal = new CalDAVClient( "http://calendar.example.com/caldav.php/username/calendar/", "username", "password", "calendar" );
* $options = $cal->DoOptionsRequest();
* if ( isset($options["PROPFIND"]) ) {
*   // Fetch some information about the events in that calendar
*   $cal->SetDepth(1);
*   $folder_xml = $cal->DoXMLRequest("PROPFIND", '<?xml version="1.0" encoding="utf-8" ?><propfind xmlns="DAV:"><prop><getcontentleng
th/><getcontenttype/><resourcetype/><getetag/></prop></propfind>' );
* }
* // Fetch all events for February
* $events = $cal->GetEvents("20070101T000000Z","20070201T000000Z");
* foreach ( $events AS $k => $event ) {
*   do_something_with_event_data( $event['data'] );
* }
* $acc = array();
* $acc["google"] = array(
* "user"=>"kunsttherapie@gmail.com",
* "pass"=>"xxxxx",
* "server"=>"ssl://www.google.com",
* "port"=>"443",
* "uri"=>"https://www.google.com/calendar/dav/kunsttherapie@gmail.com/events/",
* );
*
* $acc["davical"] = array(
* "user"=>"some_user",
* "pass"=>"big secret",
* "server"=>"calendar.foo.bar",
* "port"=>"80",
* "uri"=>"http://calendar.foo.bar/caldav.php/some_user/home/",
* );
* //*******************************
*
* $account = $acc["davical"];
*
* //*******************************
* $cal = new CalDAVClient( $account["uri"], $account["user"], $account["pass"], "", $account["server"], $account["port"] );
* $options = $cal->DoOptionsRequest();
* 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 />
*
*     </D:prop>
* </D:propfind>
* PROPP;
* //if ( isset($options["PROPFIND"]) ) {
*   // Fetch some information about the events in that calendar
* //  $cal->SetDepth(1);
* //  $folder_xml = $cal->DoXMLRequest("PROPFIND", $xmlC);
* //  print_r( $folder_xml);
* //}
*
* // Fetch all events for February
* $events = $cal->GetEvents("20090201T000000Z","20090301T000000Z");
* foreach ( $events as $k => $event ) {
*     print_r($event['data']);
*     print "\n---------------------------------------------\n";
* }
*
* //*******************************
* //*******************************
*/

Variables

  • protected $base_url, $user, $pass, $entry, $protocol, $server, $port;  // Connection details
  • protected $principal_url;  // The principal-URL we're using
  • protected $calendar_url;  //  The calendar-URL we're using
  • protected $calendar_home_set; // The calendar-home-set we're using
  • protected $calendar_urls;  //  The calendar_urls we have discovered
  • public $user_agent = 'DAViCalClient';  //  The useragent which is send to the caldav server
  • protected $headers = array();
  • protected $body = "";
  • protected $requestMethod = "GET";
  • protected $httpRequest = "";  // for debugging http headers sent
  • protected $xmlRequest = "";   // for debugging xml sent
  • protected $httpResponse = ""; // http headers received
  • protected $xmlResponse = "";  // xml received
  • protected $parser; // our XML parser object

Functions

  • __construct( $base_url, $user, $pass )  //  Constructor, initialises the class
    • @param string $base_url The URL for the calendar server
    • @param string $user The name of the user logging in
    • @param string $pass The password for that user
  • SetMatch( $match, $etag = '*' )  //  Adds an If-Match or If-None-Match header
    • @param bool $match to Match or Not to Match, that is the question!
    • @param string $etag The etag to match / not match against.
  • SetDepth( $depth = '0' )  //  Add a Depth: header.  Valid values are 0, 1 or infinity
    • @param int $depth The depth, default to infinity
  • SetUserAgent( $user_agent = null )  // Sets User Agent
    • @param int $user_agent The User Agent String to set. Defaults to predefined class variable if blank
  • SetContentType( $type )  //  Add a Content-type: header
    • @param string $type The content type
  • SetCalendar( $url )  //  Set the calendar_url we will be using for a while.
    • @param string $url The calendar_url
  • ParseResponse( $response )  //  Split response into httpResponse and xmlResponse
    • @param string Response from server
  • GetHttpRequest  //  Output http request headers
    • @return HTTP headers
  • GetResponseHeaders()  //  Output http response headers
    • @return HTTP headers
  • GetResponseBody()  //  Output http response body
    • @return HTTP body
  • GetXmlRequest()  //  Output xml request
    • @return raw xml
  • GetXmlResponse()  //  Output xml response
    • @return raw xml
  • DoRequest( $url = null )  //  Send a request to the server
    • @param string $url The URL to make the request to
    • @return string The content of the response from the server
  • Unchunk()  //  Unchunk a chunked response
  • DoOptionsRequest( $url = null )  //  Send an OPTIONS request to the server
    • @param string $url The URL to make the request to
    • @return array The allowed options
  • DoXMLRequest( $request_method, $xml, $url = null )  // Send an XML request to the server (PROPFIND, REPORT, MKCALENDAR)
    • @param string $method The method (PROPFIND, REPORT, etc) to use with the request
    • @param string $xml The XML to send along with the request
    • @param string $url The URL to make the request to
    • @return array An array of the allowed methods
  • DoGETRequest( $url )  //  Get a single item from the server.
    • @param string $url The URL to GET
  • DoHEADRequest( $url )  //  Get the HEAD of a single item from the server.
    • @param string $url The URL to HEAD
  • DoPUTRequest( $url, $icalendar, $etag = null )


  • DoDELETERequest( $url, $etag = null )
  • DoPROPFINDRequest( $url, $props, $depth = 0 )
  • PrincipalURL( $url = null )
  • CalendarHomeSet( $urls = null )
  • CalendarUrls( $urls = null )
  • HrefValueInside( $tagname )
  • HrefForProp( $tagname, $i = 0 )
  • HrefForResourcetype( $tagname, $i = 0 )
  • GetOKProps( $nodenum )
  • FindPrincipal( $url )
  • FindCalendarHome( $recursed=false )
  • FindCalendars( $recursed=false )
  • GetCalendarDetails( $url = null )
  • GetCollectionETags( $url = null )
  • CalendarMultiget( $event_hrefs, $url = null )
  • DoCalendarQuery( $filter, $url = '' )
  • GetEvents( $start = null, $finish = null, $relative_url = '' )
  • GetTodos( $start, $finish, $completed = false, $cancelled = false, $relative_url = "" )
  • GetEntryByUid( $uid, $relative_url = '' )
  • GetEntryByHref( $href )