]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use urlgenerator to generate an absolute url
authorThomas Citharel <tcit@tcit.fr>
Thu, 7 Jul 2016 08:16:56 +0000 (10:16 +0200)
committerLukas Reschke <lukas@statuscode.ch>
Mon, 26 Sep 2016 09:55:35 +0000 (11:55 +0200)
And pass Config the correct way too

apps/dav/lib/CalDAV/Publishing/PublishPlugin.php
apps/dav/lib/Server.php

index 67e04d7a8b1f54324fb7f9b5f72ae9cbcfc9048d..c12071e367089c115d5a40ccca7900867dfc634e 100644 (file)
@@ -2,8 +2,6 @@
 
 namespace OCA\DAV\CalDAV\Publishing;
 
-//use OCA\DAV\CalDAV\Publishing\Xml;
-
 use Sabre\DAV\PropFind;
 use Sabre\DAV\INode;
 use Sabre\DAV\Server;
@@ -12,10 +10,11 @@ use Sabre\HTTP\RequestInterface;
 use Sabre\HTTP\ResponseInterface;
 use OCA\DAV\CalDAV\Publishing\Xml\Publisher;
 use OCA\DAV\CalDAV\Calendar;
+use OCP\IURLGenerator;
+use OCP\IConfig;
 
 class PublishPlugin extends ServerPlugin
 {
-    const NS_OWNCLOUD = 'http://owncloud.org/ns';
     const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
 
     /**
@@ -25,6 +24,31 @@ class PublishPlugin extends ServerPlugin
      */
     protected $server;
 
+    /**
+     * Config instance to get instance secret.
+     *
+     * @var OCP\IConfig
+     */
+    protected $config;
+
+     /**
+      * URL Generator for absolute URLs.
+      *
+      * @var OCP\IURLGenerator
+      */
+     protected $urlGenerator;
+
+     /**
+      * PublishPlugin constructor.
+      *
+      * @param IURLGenerator $urlGenerator
+      */
+     public function __construct(IConfig $config, IURLGenerator $urlGenerator)
+     {
+         $this->config = $config;
+         $this->urlGenerator = $urlGenerator;
+     }
+
     /**
      * This method should return a list of server-features.
      *
@@ -72,16 +96,17 @@ class PublishPlugin extends ServerPlugin
     public function propFind(PropFind $propFind, INode $node)
     {
         if ($node instanceof Calendar) {
-          $token = md5(\OC::$server->getConfig()->getSystemValue('secret', '').$node->getResourceId());
-          $publishUrl = $this->server->getBaseUri() . 'public-calendars/' . $token;
+            $token = md5($this->config->getSystemValue('secret', '').$node->getResourceId());
+
+            $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token;
 
-          $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node, $publishUrl) {
+            $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node, $publishUrl) {
             if ($node->getPublishStatus()) {
                 return new Publisher($publishUrl, $node->getPublishStatus());
             }
           });
 
-          $propFind->handle('{'.self::NS_CALENDARSERVER.'}pre-publish-url', function () use ($node, $publishUrl) {
+            $propFind->handle('{'.self::NS_CALENDARSERVER.'}pre-publish-url', function () use ($node, $publishUrl) {
                 return new Publisher($publishUrl, false);
           });
         }
index defaddbd6423cc15b74ff9b66fcdbc621e687464..a344885fd298ed881b06e20723d06648b4050fb6 100644 (file)
@@ -114,7 +114,10 @@ class Server {
                $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
                $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
                $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
-               $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin());
+               $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
+                       \OC::$server->getConfig(),
+                       \OC::$server->getUrlGenerator()
+               ));
 
                // addressbook plugins
                $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());