]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAV/Mount/Plugin.php
Update strings
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAV / Mount / Plugin.php
1 <?php
2
3 /**
4  * This addon provides support for RFC4709: Mounting WebDAV servers
5  *
6  * Simply append ?mount to any collection to generate the davmount response.
7  *
8  * @package Sabre
9  * @subpackage DAV
10  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
11  * @author Evert Pot (http://www.rooftopsolutions.nl/)
12  */
13 class Sabre_DAV_Mount_Plugin extends Sabre_DAV_ServerPlugin {
14
15     /**
16      * Reference to Server class
17      *
18      * @var Sabre_DAV_Server
19      */
20     private $server;
21
22     /**
23      * Initializes the addon and registers event handles
24      *
25      * @param Sabre_DAV_Server $server
26      * @return void
27      */
28     public function initialize(Sabre_DAV_Server $server) {
29
30         $this->server = $server;
31         $this->server->subscribeEvent('beforeMethod',array($this,'beforeMethod'), 90);
32
33     }
34
35     /**
36      * 'beforeMethod' event handles. This event handles intercepts GET requests ending
37      * with ?mount
38      *
39      * @param string $method
40      * @param string $uri
41      * @return bool
42      */
43     public function beforeMethod($method, $uri) {
44
45         if ($method!='GET') return;
46         if ($this->server->httpRequest->getQueryString()!='mount') return;
47
48         $currentUri = $this->server->httpRequest->getAbsoluteUri();
49
50         // Stripping off everything after the ?
51         list($currentUri) = explode('?',$currentUri);
52
53         $this->davMount($currentUri);
54
55         // Returning false to break the event chain
56         return false;
57
58     }
59
60     /**
61      * Generates the davmount response
62      *
63      * @param string $uri absolute uri
64      * @return void
65      */
66     public function davMount($uri) {
67
68         $this->server->httpResponse->sendStatus(200);
69         $this->server->httpResponse->setHeader('Content-Type','application/davmount+xml');
70         ob_start();
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";
74         echo "</dm:mount>";
75         $this->server->httpResponse->sendBody(ob_get_clean());
76
77     }
78
79
80 }