4 * This addon provides support for RFC4709: Mounting WebDAV servers
6 * Simply append ?mount to any collection to generate the davmount response.
10 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
11 * @author Evert Pot (http://www.rooftopsolutions.nl/)
13 class Sabre_DAV_Mount_Plugin extends Sabre_DAV_ServerPlugin {
16 * Reference to Server class
18 * @var Sabre_DAV_Server
23 * Initializes the addon and registers event handles
25 * @param Sabre_DAV_Server $server
28 public function initialize(Sabre_DAV_Server $server) {
30 $this->server = $server;
31 $this->server->subscribeEvent('beforeMethod',array($this,'beforeMethod'), 90);
36 * 'beforeMethod' event handles. This event handles intercepts GET requests ending
39 * @param string $method
43 public function beforeMethod($method, $uri) {
45 if ($method!='GET') return;
46 if ($this->server->httpRequest->getQueryString()!='mount') return;
48 $currentUri = $this->server->httpRequest->getAbsoluteUri();
50 // Stripping off everything after the ?
51 list($currentUri) = explode('?',$currentUri);
53 $this->davMount($currentUri);
55 // Returning false to break the event chain
61 * Generates the davmount response
63 * @param string $uri absolute uri
66 public function davMount($uri) {
68 $this->server->httpResponse->sendStatus(200);
69 $this->server->httpResponse->setHeader('Content-Type','application/davmount+xml');
71 echo '<?xml version="1.0"?>', "\n";
72 echo "<dm:mount xmlns:dm=\"http://purl.org/NET/webdav/mount\">\n";
73 echo " <dm:url>", htmlspecialchars($uri, ENT_NOQUOTES, 'UTF-8'), "</dm:url>\n";
75 $this->server->httpResponse->sendBody(ob_get_clean());