@@ -32,61 +32,61 @@ |
||
32 | 32 | * This property contains multiple "share-type" elements, each containing a share type. |
33 | 33 | */ |
34 | 34 | class ShareTypeList implements Element { |
35 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
35 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Share types |
|
39 | - * |
|
40 | - * @var int[] |
|
41 | - */ |
|
42 | - private $shareTypes; |
|
37 | + /** |
|
38 | + * Share types |
|
39 | + * |
|
40 | + * @var int[] |
|
41 | + */ |
|
42 | + private $shareTypes; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param int[] $shareTypes |
|
46 | - */ |
|
47 | - public function __construct($shareTypes) { |
|
48 | - $this->shareTypes = $shareTypes; |
|
49 | - } |
|
44 | + /** |
|
45 | + * @param int[] $shareTypes |
|
46 | + */ |
|
47 | + public function __construct($shareTypes) { |
|
48 | + $this->shareTypes = $shareTypes; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns the share types |
|
53 | - * |
|
54 | - * @return int[] |
|
55 | - */ |
|
56 | - public function getShareTypes() { |
|
57 | - return $this->shareTypes; |
|
58 | - } |
|
51 | + /** |
|
52 | + * Returns the share types |
|
53 | + * |
|
54 | + * @return int[] |
|
55 | + */ |
|
56 | + public function getShareTypes() { |
|
57 | + return $this->shareTypes; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * The deserialize method is called during xml parsing. |
|
62 | - * |
|
63 | - * @param Reader $reader |
|
64 | - * @return mixed |
|
65 | - */ |
|
66 | - static function xmlDeserialize(Reader $reader) { |
|
67 | - $shareTypes = []; |
|
60 | + /** |
|
61 | + * The deserialize method is called during xml parsing. |
|
62 | + * |
|
63 | + * @param Reader $reader |
|
64 | + * @return mixed |
|
65 | + */ |
|
66 | + static function xmlDeserialize(Reader $reader) { |
|
67 | + $shareTypes = []; |
|
68 | 68 | |
69 | - $tree = $reader->parseInnerTree(); |
|
70 | - if ($tree === null) { |
|
71 | - return null; |
|
72 | - } |
|
73 | - foreach ($tree as $elem) { |
|
74 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | - $shareTypes[] = (int)$elem['value']; |
|
76 | - } |
|
77 | - } |
|
78 | - return new self($shareTypes); |
|
79 | - } |
|
69 | + $tree = $reader->parseInnerTree(); |
|
70 | + if ($tree === null) { |
|
71 | + return null; |
|
72 | + } |
|
73 | + foreach ($tree as $elem) { |
|
74 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | + $shareTypes[] = (int)$elem['value']; |
|
76 | + } |
|
77 | + } |
|
78 | + return new self($shareTypes); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * The xmlSerialize metod is called during xml writing. |
|
83 | - * |
|
84 | - * @param Writer $writer |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - function xmlSerialize(Writer $writer) { |
|
88 | - foreach ($this->shareTypes as $shareType) { |
|
89 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
90 | - } |
|
91 | - } |
|
81 | + /** |
|
82 | + * The xmlSerialize metod is called during xml writing. |
|
83 | + * |
|
84 | + * @param Writer $writer |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + function xmlSerialize(Writer $writer) { |
|
88 | + foreach ($this->shareTypes as $shareType) { |
|
89 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | } |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | return null; |
72 | 72 | } |
73 | 73 | foreach ($tree as $elem) { |
74 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | - $shareTypes[] = (int)$elem['value']; |
|
74 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}share-type') { |
|
75 | + $shareTypes[] = (int) $elem['value']; |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | return new self($shareTypes); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | function xmlSerialize(Writer $writer) { |
88 | 88 | foreach ($this->shareTypes as $shareType) { |
89 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
89 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}share-type', $shareType); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
@@ -24,42 +24,42 @@ |
||
24 | 24 | |
25 | 25 | class Forbidden extends \Sabre\DAV\Exception\Forbidden { |
26 | 26 | |
27 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
27 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var bool |
|
31 | - */ |
|
32 | - private $retry; |
|
29 | + /** |
|
30 | + * @var bool |
|
31 | + */ |
|
32 | + private $retry; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param string $message |
|
36 | - * @param bool $retry |
|
37 | - * @param \Exception $previous |
|
38 | - */ |
|
39 | - public function __construct($message, $retry = false, \Exception $previous = null) { |
|
40 | - parent::__construct($message, 0, $previous); |
|
41 | - $this->retry = $retry; |
|
42 | - } |
|
34 | + /** |
|
35 | + * @param string $message |
|
36 | + * @param bool $retry |
|
37 | + * @param \Exception $previous |
|
38 | + */ |
|
39 | + public function __construct($message, $retry = false, \Exception $previous = null) { |
|
40 | + parent::__construct($message, 0, $previous); |
|
41 | + $this->retry = $retry; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * This method allows the exception to include additional information |
|
46 | - * into the WebDAV error response |
|
47 | - * |
|
48 | - * @param \Sabre\DAV\Server $server |
|
49 | - * @param \DOMElement $errorNode |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
44 | + /** |
|
45 | + * This method allows the exception to include additional information |
|
46 | + * into the WebDAV error response |
|
47 | + * |
|
48 | + * @param \Sabre\DAV\Server $server |
|
49 | + * @param \DOMElement $errorNode |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
53 | 53 | |
54 | - // set ownCloud namespace |
|
55 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
54 | + // set ownCloud namespace |
|
55 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
56 | 56 | |
57 | - // adding the retry node |
|
58 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
59 | - $errorNode->appendChild($error); |
|
57 | + // adding the retry node |
|
58 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
59 | + $errorNode->appendChild($error); |
|
60 | 60 | |
61 | - // adding the message node |
|
62 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
63 | - $errorNode->appendChild($error); |
|
64 | - } |
|
61 | + // adding the message node |
|
62 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
63 | + $errorNode->appendChild($error); |
|
64 | + } |
|
65 | 65 | } |
@@ -49,17 +49,17 @@ |
||
49 | 49 | * @param \DOMElement $errorNode |
50 | 50 | * @return void |
51 | 51 | */ |
52 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
52 | + public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) { |
|
53 | 53 | |
54 | 54 | // set ownCloud namespace |
55 | 55 | $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
56 | 56 | |
57 | 57 | // adding the retry node |
58 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
58 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true)); |
|
59 | 59 | $errorNode->appendChild($error); |
60 | 60 | |
61 | 61 | // adding the message node |
62 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
62 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage()); |
|
63 | 63 | $errorNode->appendChild($error); |
64 | 64 | } |
65 | 65 | } |
@@ -61,17 +61,17 @@ |
||
61 | 61 | * @param \DOMElement $errorNode |
62 | 62 | * @return void |
63 | 63 | */ |
64 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
64 | + public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) { |
|
65 | 65 | |
66 | 66 | // set ownCloud namespace |
67 | 67 | $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
68 | 68 | |
69 | 69 | // adding the retry node |
70 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
70 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true)); |
|
71 | 71 | $errorNode->appendChild($error); |
72 | 72 | |
73 | 73 | // adding the message node |
74 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
74 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage()); |
|
75 | 75 | $errorNode->appendChild($error); |
76 | 76 | } |
77 | 77 |
@@ -26,54 +26,54 @@ |
||
26 | 26 | |
27 | 27 | class InvalidPath extends Exception { |
28 | 28 | |
29 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
29 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var bool |
|
33 | - */ |
|
34 | - private $retry; |
|
31 | + /** |
|
32 | + * @var bool |
|
33 | + */ |
|
34 | + private $retry; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $message |
|
38 | - * @param bool $retry |
|
39 | - * @param \Exception|null $previous |
|
40 | - */ |
|
41 | - public function __construct($message, $retry = false, \Exception $previous = null) { |
|
42 | - parent::__construct($message, 0, $previous); |
|
43 | - $this->retry = $retry; |
|
44 | - } |
|
36 | + /** |
|
37 | + * @param string $message |
|
38 | + * @param bool $retry |
|
39 | + * @param \Exception|null $previous |
|
40 | + */ |
|
41 | + public function __construct($message, $retry = false, \Exception $previous = null) { |
|
42 | + parent::__construct($message, 0, $previous); |
|
43 | + $this->retry = $retry; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Returns the HTTP status code for this exception |
|
48 | - * |
|
49 | - * @return int |
|
50 | - */ |
|
51 | - public function getHTTPCode() { |
|
46 | + /** |
|
47 | + * Returns the HTTP status code for this exception |
|
48 | + * |
|
49 | + * @return int |
|
50 | + */ |
|
51 | + public function getHTTPCode() { |
|
52 | 52 | |
53 | - return 400; |
|
53 | + return 400; |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * This method allows the exception to include additional information |
|
59 | - * into the WebDAV error response |
|
60 | - * |
|
61 | - * @param \Sabre\DAV\Server $server |
|
62 | - * @param \DOMElement $errorNode |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
57 | + /** |
|
58 | + * This method allows the exception to include additional information |
|
59 | + * into the WebDAV error response |
|
60 | + * |
|
61 | + * @param \Sabre\DAV\Server $server |
|
62 | + * @param \DOMElement $errorNode |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
66 | 66 | |
67 | - // set ownCloud namespace |
|
68 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
67 | + // set ownCloud namespace |
|
68 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
69 | 69 | |
70 | - // adding the retry node |
|
71 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
72 | - $errorNode->appendChild($error); |
|
70 | + // adding the retry node |
|
71 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
72 | + $errorNode->appendChild($error); |
|
73 | 73 | |
74 | - // adding the message node |
|
75 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
76 | - $errorNode->appendChild($error); |
|
77 | - } |
|
74 | + // adding the message node |
|
75 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
76 | + $errorNode->appendChild($error); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | } |
@@ -29,27 +29,27 @@ |
||
29 | 29 | |
30 | 30 | class PasswordLoginForbidden extends NotAuthenticated { |
31 | 31 | |
32 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
33 | - |
|
34 | - public function getHTTPCode() { |
|
35 | - return 401; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * This method allows the exception to include additional information |
|
40 | - * into the WebDAV error response |
|
41 | - * |
|
42 | - * @param Server $server |
|
43 | - * @param DOMElement $errorNode |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public function serialize(Server $server, DOMElement $errorNode) { |
|
47 | - |
|
48 | - // set ownCloud namespace |
|
49 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
50 | - |
|
51 | - $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden'); |
|
52 | - $errorNode->appendChild($error); |
|
53 | - } |
|
32 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
33 | + |
|
34 | + public function getHTTPCode() { |
|
35 | + return 401; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * This method allows the exception to include additional information |
|
40 | + * into the WebDAV error response |
|
41 | + * |
|
42 | + * @param Server $server |
|
43 | + * @param DOMElement $errorNode |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public function serialize(Server $server, DOMElement $errorNode) { |
|
47 | + |
|
48 | + // set ownCloud namespace |
|
49 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
50 | + |
|
51 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden'); |
|
52 | + $errorNode->appendChild($error); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | } |
@@ -30,20 +30,20 @@ |
||
30 | 30 | |
31 | 31 | class FileLocked extends \Sabre\DAV\Exception { |
32 | 32 | |
33 | - public function __construct($message = "", $code = 0, Exception $previous = null) { |
|
34 | - if($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
35 | - $message = sprintf('Target file %s is locked by another process.', $previous->path); |
|
36 | - } |
|
37 | - parent::__construct($message, $code, $previous); |
|
38 | - } |
|
33 | + public function __construct($message = "", $code = 0, Exception $previous = null) { |
|
34 | + if($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
35 | + $message = sprintf('Target file %s is locked by another process.', $previous->path); |
|
36 | + } |
|
37 | + parent::__construct($message, $code, $previous); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Returns the HTTP status code for this exception |
|
42 | - * |
|
43 | - * @return int |
|
44 | - */ |
|
45 | - public function getHTTPCode() { |
|
40 | + /** |
|
41 | + * Returns the HTTP status code for this exception |
|
42 | + * |
|
43 | + * @return int |
|
44 | + */ |
|
45 | + public function getHTTPCode() { |
|
46 | 46 | |
47 | - return 423; |
|
48 | - } |
|
47 | + return 423; |
|
48 | + } |
|
49 | 49 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | class FileLocked extends \Sabre\DAV\Exception { |
32 | 32 | |
33 | 33 | public function __construct($message = "", $code = 0, Exception $previous = null) { |
34 | - if($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
34 | + if ($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
35 | 35 | $message = sprintf('Target file %s is locked by another process.', $previous->path); |
36 | 36 | } |
37 | 37 | parent::__construct($message, $code, $previous); |
@@ -31,15 +31,15 @@ |
||
31 | 31 | */ |
32 | 32 | class UnsupportedMediaType extends \Sabre\DAV\Exception { |
33 | 33 | |
34 | - /** |
|
35 | - * Returns the HTTP status code for this exception |
|
36 | - * |
|
37 | - * @return int |
|
38 | - */ |
|
39 | - public function getHTTPCode() { |
|
34 | + /** |
|
35 | + * Returns the HTTP status code for this exception |
|
36 | + * |
|
37 | + * @return int |
|
38 | + */ |
|
39 | + public function getHTTPCode() { |
|
40 | 40 | |
41 | - return 415; |
|
41 | + return 415; |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | } |
@@ -31,15 +31,15 @@ |
||
31 | 31 | */ |
32 | 32 | class EntityTooLarge extends \Sabre\DAV\Exception { |
33 | 33 | |
34 | - /** |
|
35 | - * Returns the HTTP status code for this exception |
|
36 | - * |
|
37 | - * @return int |
|
38 | - */ |
|
39 | - public function getHTTPCode() { |
|
34 | + /** |
|
35 | + * Returns the HTTP status code for this exception |
|
36 | + * |
|
37 | + * @return int |
|
38 | + */ |
|
39 | + public function getHTTPCode() { |
|
40 | 40 | |
41 | - return 413; |
|
41 | + return 413; |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | } |
@@ -34,92 +34,92 @@ |
||
34 | 34 | * This property contains multiple "tag" elements, each containing a tag name. |
35 | 35 | */ |
36 | 36 | class TagList implements Element { |
37 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
37 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * tags |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - private $tags; |
|
39 | + /** |
|
40 | + * tags |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + private $tags; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param array $tags |
|
48 | - */ |
|
49 | - public function __construct(array $tags) { |
|
50 | - $this->tags = $tags; |
|
51 | - } |
|
46 | + /** |
|
47 | + * @param array $tags |
|
48 | + */ |
|
49 | + public function __construct(array $tags) { |
|
50 | + $this->tags = $tags; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Returns the tags |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getTags() { |
|
53 | + /** |
|
54 | + * Returns the tags |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getTags() { |
|
59 | 59 | |
60 | - return $this->tags; |
|
60 | + return $this->tags; |
|
61 | 61 | |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * The deserialize method is called during xml parsing. |
|
66 | - * |
|
67 | - * This method is called statictly, this is because in theory this method |
|
68 | - * may be used as a type of constructor, or factory method. |
|
69 | - * |
|
70 | - * Often you want to return an instance of the current class, but you are |
|
71 | - * free to return other data as well. |
|
72 | - * |
|
73 | - * You are responsible for advancing the reader to the next element. Not |
|
74 | - * doing anything will result in a never-ending loop. |
|
75 | - * |
|
76 | - * If you just want to skip parsing for this element altogether, you can |
|
77 | - * just call $reader->next(); |
|
78 | - * |
|
79 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | - * the next element. |
|
81 | - * |
|
82 | - * @param Reader $reader |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - static function xmlDeserialize(Reader $reader) { |
|
86 | - $tags = []; |
|
64 | + /** |
|
65 | + * The deserialize method is called during xml parsing. |
|
66 | + * |
|
67 | + * This method is called statictly, this is because in theory this method |
|
68 | + * may be used as a type of constructor, or factory method. |
|
69 | + * |
|
70 | + * Often you want to return an instance of the current class, but you are |
|
71 | + * free to return other data as well. |
|
72 | + * |
|
73 | + * You are responsible for advancing the reader to the next element. Not |
|
74 | + * doing anything will result in a never-ending loop. |
|
75 | + * |
|
76 | + * If you just want to skip parsing for this element altogether, you can |
|
77 | + * just call $reader->next(); |
|
78 | + * |
|
79 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | + * the next element. |
|
81 | + * |
|
82 | + * @param Reader $reader |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + static function xmlDeserialize(Reader $reader) { |
|
86 | + $tags = []; |
|
87 | 87 | |
88 | - $tree = $reader->parseInnerTree(); |
|
89 | - if ($tree === null) { |
|
90 | - return null; |
|
91 | - } |
|
92 | - foreach ($tree as $elem) { |
|
93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
94 | - $tags[] = $elem['value']; |
|
95 | - } |
|
96 | - } |
|
97 | - return new self($tags); |
|
98 | - } |
|
88 | + $tree = $reader->parseInnerTree(); |
|
89 | + if ($tree === null) { |
|
90 | + return null; |
|
91 | + } |
|
92 | + foreach ($tree as $elem) { |
|
93 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
94 | + $tags[] = $elem['value']; |
|
95 | + } |
|
96 | + } |
|
97 | + return new self($tags); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * The xmlSerialize metod is called during xml writing. |
|
102 | - * |
|
103 | - * Use the $writer argument to write its own xml serialization. |
|
104 | - * |
|
105 | - * An important note: do _not_ create a parent element. Any element |
|
106 | - * implementing XmlSerializble should only ever write what's considered |
|
107 | - * its 'inner xml'. |
|
108 | - * |
|
109 | - * The parent of the current element is responsible for writing a |
|
110 | - * containing element. |
|
111 | - * |
|
112 | - * This allows serializers to be re-used for different element names. |
|
113 | - * |
|
114 | - * If you are opening new elements, you must also close them again. |
|
115 | - * |
|
116 | - * @param Writer $writer |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - function xmlSerialize(Writer $writer) { |
|
100 | + /** |
|
101 | + * The xmlSerialize metod is called during xml writing. |
|
102 | + * |
|
103 | + * Use the $writer argument to write its own xml serialization. |
|
104 | + * |
|
105 | + * An important note: do _not_ create a parent element. Any element |
|
106 | + * implementing XmlSerializble should only ever write what's considered |
|
107 | + * its 'inner xml'. |
|
108 | + * |
|
109 | + * The parent of the current element is responsible for writing a |
|
110 | + * containing element. |
|
111 | + * |
|
112 | + * This allows serializers to be re-used for different element names. |
|
113 | + * |
|
114 | + * If you are opening new elements, you must also close them again. |
|
115 | + * |
|
116 | + * @param Writer $writer |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + function xmlSerialize(Writer $writer) { |
|
120 | 120 | |
121 | - foreach ($this->tags as $tag) { |
|
122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
123 | - } |
|
124 | - } |
|
121 | + foreach ($this->tags as $tag) { |
|
122 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
123 | + } |
|
124 | + } |
|
125 | 125 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | return null; |
91 | 91 | } |
92 | 92 | foreach ($tree as $elem) { |
93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
93 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}tag') { |
|
94 | 94 | $tags[] = $elem['value']; |
95 | 95 | } |
96 | 96 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | function xmlSerialize(Writer $writer) { |
120 | 120 | |
121 | 121 | foreach ($this->tags as $tag) { |
122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
122 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}tag', $tag); |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | } |
@@ -245,7 +245,9 @@ |
||
245 | 245 | function httpGet(RequestInterface $request, ResponseInterface $response) { |
246 | 246 | // Only handle valid files |
247 | 247 | $node = $this->tree->getNodeForPath($request->getPath()); |
248 | - if (!($node instanceof IFile)) return; |
|
248 | + if (!($node instanceof IFile)) { |
|
249 | + return; |
|
250 | + } |
|
249 | 251 | |
250 | 252 | // adds a 'Content-Disposition: attachment' header in case no disposition |
251 | 253 | // header has been set before |
@@ -53,470 +53,470 @@ |
||
53 | 53 | |
54 | 54 | class FilesPlugin extends ServerPlugin { |
55 | 55 | |
56 | - // namespace |
|
57 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
58 | - const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; |
|
59 | - const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
60 | - const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid'; |
|
61 | - const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions'; |
|
62 | - const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions'; |
|
63 | - const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions'; |
|
64 | - const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL'; |
|
65 | - const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size'; |
|
66 | - const GETETAG_PROPERTYNAME = '{DAV:}getetag'; |
|
67 | - const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; |
|
68 | - const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id'; |
|
69 | - const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; |
|
70 | - const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; |
|
71 | - const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; |
|
72 | - const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; |
|
73 | - const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; |
|
74 | - const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; |
|
75 | - const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag'; |
|
76 | - const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time'; |
|
77 | - const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time'; |
|
78 | - const SHARE_NOTE = '{http://nextcloud.org/ns}note'; |
|
79 | - |
|
80 | - /** |
|
81 | - * Reference to main server object |
|
82 | - * |
|
83 | - * @var \Sabre\DAV\Server |
|
84 | - */ |
|
85 | - private $server; |
|
86 | - |
|
87 | - /** |
|
88 | - * @var Tree |
|
89 | - */ |
|
90 | - private $tree; |
|
91 | - |
|
92 | - /** |
|
93 | - * Whether this is public webdav. |
|
94 | - * If true, some returned information will be stripped off. |
|
95 | - * |
|
96 | - * @var bool |
|
97 | - */ |
|
98 | - private $isPublic; |
|
99 | - |
|
100 | - /** |
|
101 | - * @var bool |
|
102 | - */ |
|
103 | - private $downloadAttachment; |
|
104 | - |
|
105 | - /** |
|
106 | - * @var IConfig |
|
107 | - */ |
|
108 | - private $config; |
|
109 | - |
|
110 | - /** |
|
111 | - * @var IRequest |
|
112 | - */ |
|
113 | - private $request; |
|
114 | - |
|
115 | - /** |
|
116 | - * @var IPreview |
|
117 | - */ |
|
118 | - private $previewManager; |
|
119 | - |
|
120 | - /** |
|
121 | - * @param Tree $tree |
|
122 | - * @param IConfig $config |
|
123 | - * @param IRequest $request |
|
124 | - * @param IPreview $previewManager |
|
125 | - * @param bool $isPublic |
|
126 | - * @param bool $downloadAttachment |
|
127 | - */ |
|
128 | - public function __construct(Tree $tree, |
|
129 | - IConfig $config, |
|
130 | - IRequest $request, |
|
131 | - IPreview $previewManager, |
|
132 | - $isPublic = false, |
|
133 | - $downloadAttachment = true) { |
|
134 | - $this->tree = $tree; |
|
135 | - $this->config = $config; |
|
136 | - $this->request = $request; |
|
137 | - $this->isPublic = $isPublic; |
|
138 | - $this->downloadAttachment = $downloadAttachment; |
|
139 | - $this->previewManager = $previewManager; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * This initializes the plugin. |
|
144 | - * |
|
145 | - * This function is called by \Sabre\DAV\Server, after |
|
146 | - * addPlugin is called. |
|
147 | - * |
|
148 | - * This method should set up the required event subscriptions. |
|
149 | - * |
|
150 | - * @param \Sabre\DAV\Server $server |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - public function initialize(\Sabre\DAV\Server $server) { |
|
154 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
155 | - $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
156 | - $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
157 | - $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
158 | - $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
159 | - $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
160 | - $server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME; |
|
161 | - $server->protectedProperties[] = self::SIZE_PROPERTYNAME; |
|
162 | - $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME; |
|
163 | - $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME; |
|
164 | - $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; |
|
165 | - $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; |
|
166 | - $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; |
|
167 | - $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; |
|
168 | - $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; |
|
169 | - $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME; |
|
170 | - $server->protectedProperties[] = self::SHARE_NOTE; |
|
171 | - |
|
172 | - // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
173 | - $allowedProperties = ['{DAV:}getetag']; |
|
174 | - $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
175 | - |
|
176 | - $this->server = $server; |
|
177 | - $this->server->on('propFind', [$this, 'handleGetProperties']); |
|
178 | - $this->server->on('propPatch', [$this, 'handleUpdateProperties']); |
|
179 | - $this->server->on('afterBind', [$this, 'sendFileIdHeader']); |
|
180 | - $this->server->on('afterWriteContent', [$this, 'sendFileIdHeader']); |
|
181 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
182 | - $this->server->on('afterMethod:GET', [$this, 'handleDownloadToken']); |
|
183 | - $this->server->on('afterResponse', function ($request, ResponseInterface $response) { |
|
184 | - $body = $response->getBody(); |
|
185 | - if (is_resource($body)) { |
|
186 | - fclose($body); |
|
187 | - } |
|
188 | - }); |
|
189 | - $this->server->on('beforeMove', [$this, 'checkMove']); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Plugin that checks if a move can actually be performed. |
|
194 | - * |
|
195 | - * @param string $source source path |
|
196 | - * @param string $destination destination path |
|
197 | - * @throws Forbidden |
|
198 | - * @throws NotFound |
|
199 | - */ |
|
200 | - function checkMove($source, $destination) { |
|
201 | - $sourceNode = $this->tree->getNodeForPath($source); |
|
202 | - if (!$sourceNode instanceof Node) { |
|
203 | - return; |
|
204 | - } |
|
205 | - list($sourceDir,) = \Sabre\Uri\split($source); |
|
206 | - list($destinationDir,) = \Sabre\Uri\split($destination); |
|
207 | - |
|
208 | - if ($sourceDir !== $destinationDir) { |
|
209 | - $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
|
210 | - if ($sourceNodeFileInfo === null) { |
|
211 | - throw new NotFound($source . ' does not exist'); |
|
212 | - } |
|
213 | - |
|
214 | - if (!$sourceNodeFileInfo->isDeletable()) { |
|
215 | - throw new Forbidden($source . " cannot be deleted"); |
|
216 | - } |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * This sets a cookie to be able to recognize the start of the download |
|
222 | - * the content must not be longer than 32 characters and must only contain |
|
223 | - * alphanumeric characters |
|
224 | - * |
|
225 | - * @param RequestInterface $request |
|
226 | - * @param ResponseInterface $response |
|
227 | - */ |
|
228 | - function handleDownloadToken(RequestInterface $request, ResponseInterface $response) { |
|
229 | - $queryParams = $request->getQueryParameters(); |
|
230 | - |
|
231 | - /** |
|
232 | - * this sets a cookie to be able to recognize the start of the download |
|
233 | - * the content must not be longer than 32 characters and must only contain |
|
234 | - * alphanumeric characters |
|
235 | - */ |
|
236 | - if (isset($queryParams['downloadStartSecret'])) { |
|
237 | - $token = $queryParams['downloadStartSecret']; |
|
238 | - if (!isset($token[32]) |
|
239 | - && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) { |
|
240 | - // FIXME: use $response->setHeader() instead |
|
241 | - setcookie('ocDownloadStarted', $token, time() + 20, '/'); |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Add headers to file download |
|
248 | - * |
|
249 | - * @param RequestInterface $request |
|
250 | - * @param ResponseInterface $response |
|
251 | - */ |
|
252 | - function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
253 | - // Only handle valid files |
|
254 | - $node = $this->tree->getNodeForPath($request->getPath()); |
|
255 | - if (!($node instanceof IFile)) return; |
|
256 | - |
|
257 | - // adds a 'Content-Disposition: attachment' header in case no disposition |
|
258 | - // header has been set before |
|
259 | - if ($this->downloadAttachment && |
|
260 | - $response->getHeader('Content-Disposition') === null) { |
|
261 | - $filename = $node->getName(); |
|
262 | - if ($this->request->isUserAgent( |
|
263 | - [ |
|
264 | - Request::USER_AGENT_IE, |
|
265 | - Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
266 | - Request::USER_AGENT_FREEBOX, |
|
267 | - ])) { |
|
268 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
269 | - } else { |
|
270 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
271 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
276 | - //Add OC-Checksum header |
|
277 | - /** @var $node File */ |
|
278 | - $checksum = $node->getChecksum(); |
|
279 | - if ($checksum !== null && $checksum !== '') { |
|
280 | - $response->addHeader('OC-Checksum', $checksum); |
|
281 | - } |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Adds all ownCloud-specific properties |
|
287 | - * |
|
288 | - * @param PropFind $propFind |
|
289 | - * @param \Sabre\DAV\INode $node |
|
290 | - * @return void |
|
291 | - */ |
|
292 | - public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { |
|
293 | - |
|
294 | - $httpRequest = $this->server->httpRequest; |
|
295 | - |
|
296 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
297 | - /** |
|
298 | - * This was disabled, because it made dir listing throw an exception, |
|
299 | - * so users were unable to navigate into folders where one subitem |
|
300 | - * is blocked by the files_accesscontrol app, see: |
|
301 | - * https://github.com/nextcloud/files_accesscontrol/issues/65 |
|
302 | - * if (!$node->getFileInfo()->isReadable()) { |
|
303 | - * // avoid detecting files through this means |
|
304 | - * throw new NotFound(); |
|
305 | - * } |
|
306 | - */ |
|
307 | - |
|
308 | - $propFind->handle(self::FILEID_PROPERTYNAME, function () use ($node) { |
|
309 | - return $node->getFileId(); |
|
310 | - }); |
|
311 | - |
|
312 | - $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) { |
|
313 | - return $node->getInternalFileId(); |
|
314 | - }); |
|
315 | - |
|
316 | - $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function () use ($node) { |
|
317 | - $perms = $node->getDavPermissions(); |
|
318 | - if ($this->isPublic) { |
|
319 | - // remove mount information |
|
320 | - $perms = str_replace(['S', 'M'], '', $perms); |
|
321 | - } |
|
322 | - return $perms; |
|
323 | - }); |
|
324 | - |
|
325 | - $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) { |
|
326 | - return $node->getSharePermissions( |
|
327 | - $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
328 | - ); |
|
329 | - }); |
|
330 | - |
|
331 | - $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) { |
|
332 | - $ncPermissions = $node->getSharePermissions( |
|
333 | - $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
334 | - ); |
|
335 | - $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions); |
|
336 | - return json_encode($ocmPermissions); |
|
337 | - }); |
|
338 | - |
|
339 | - $propFind->handle(self::GETETAG_PROPERTYNAME, function () use ($node) { |
|
340 | - return $node->getETag(); |
|
341 | - }); |
|
342 | - |
|
343 | - $propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use ($node) { |
|
344 | - $owner = $node->getOwner(); |
|
345 | - if (!$owner) { |
|
346 | - return null; |
|
347 | - } else { |
|
348 | - return $owner->getUID(); |
|
349 | - } |
|
350 | - }); |
|
351 | - $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use ($node) { |
|
352 | - $owner = $node->getOwner(); |
|
353 | - if (!$owner) { |
|
354 | - return null; |
|
355 | - } else { |
|
356 | - return $owner->getDisplayName(); |
|
357 | - } |
|
358 | - }); |
|
359 | - |
|
360 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
361 | - return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
|
362 | - }); |
|
363 | - $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) { |
|
364 | - return $node->getSize(); |
|
365 | - }); |
|
366 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
367 | - return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
368 | - }); |
|
369 | - |
|
370 | - $propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest) { |
|
371 | - return $node->getNoteFromShare( |
|
372 | - $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
373 | - ); |
|
374 | - }); |
|
375 | - } |
|
376 | - |
|
377 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
378 | - $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () use ($node) { |
|
379 | - return $this->config->getSystemValue('data-fingerprint', ''); |
|
380 | - }); |
|
381 | - } |
|
382 | - |
|
383 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
384 | - $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function () use ($node) { |
|
385 | - /** @var $node \OCA\DAV\Connector\Sabre\File */ |
|
386 | - try { |
|
387 | - $directDownloadUrl = $node->getDirectDownload(); |
|
388 | - if (isset($directDownloadUrl['url'])) { |
|
389 | - return $directDownloadUrl['url']; |
|
390 | - } |
|
391 | - } catch (StorageNotAvailableException $e) { |
|
392 | - return false; |
|
393 | - } catch (ForbiddenException $e) { |
|
394 | - return false; |
|
395 | - } |
|
396 | - return false; |
|
397 | - }); |
|
398 | - |
|
399 | - $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function () use ($node) { |
|
400 | - $checksum = $node->getChecksum(); |
|
401 | - if ($checksum === null || $checksum === '') { |
|
402 | - return null; |
|
403 | - } |
|
404 | - |
|
405 | - return new ChecksumList($checksum); |
|
406 | - }); |
|
407 | - |
|
408 | - $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function () use ($node) { |
|
409 | - return $node->getFileInfo()->getCreationTime(); |
|
410 | - }); |
|
411 | - |
|
412 | - $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function () use ($node) { |
|
413 | - return $node->getFileInfo()->getUploadTime(); |
|
414 | - }); |
|
415 | - |
|
416 | - } |
|
417 | - |
|
418 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
|
419 | - $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) { |
|
420 | - return $node->getSize(); |
|
421 | - }); |
|
422 | - |
|
423 | - $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) { |
|
424 | - return $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
|
425 | - }); |
|
426 | - } |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * translate Nextcloud permissions to OCM Permissions |
|
431 | - * |
|
432 | - * @param $ncPermissions |
|
433 | - * @return array |
|
434 | - */ |
|
435 | - protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
436 | - |
|
437 | - $ocmPermissions = []; |
|
438 | - |
|
439 | - if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
440 | - $ocmPermissions[] = 'share'; |
|
441 | - } |
|
442 | - |
|
443 | - if ($ncPermissions & Constants::PERMISSION_READ) { |
|
444 | - $ocmPermissions[] = 'read'; |
|
445 | - } |
|
446 | - |
|
447 | - if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
448 | - ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
449 | - $ocmPermissions[] = 'write'; |
|
450 | - } |
|
451 | - |
|
452 | - return $ocmPermissions; |
|
453 | - |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Update ownCloud-specific properties |
|
458 | - * |
|
459 | - * @param string $path |
|
460 | - * @param PropPatch $propPatch |
|
461 | - * |
|
462 | - * @return void |
|
463 | - */ |
|
464 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
465 | - $node = $this->tree->getNodeForPath($path); |
|
466 | - if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
467 | - return; |
|
468 | - } |
|
469 | - |
|
470 | - $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function ($time) use ($node) { |
|
471 | - if (empty($time)) { |
|
472 | - return false; |
|
473 | - } |
|
474 | - $node->touch($time); |
|
475 | - return true; |
|
476 | - }); |
|
477 | - $propPatch->handle(self::GETETAG_PROPERTYNAME, function ($etag) use ($node) { |
|
478 | - if (empty($etag)) { |
|
479 | - return false; |
|
480 | - } |
|
481 | - if ($node->setEtag($etag) !== -1) { |
|
482 | - return true; |
|
483 | - } |
|
484 | - return false; |
|
485 | - }); |
|
486 | - $propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function ($time) use ($node) { |
|
487 | - if (empty($time)) { |
|
488 | - return false; |
|
489 | - } |
|
490 | - $node->setCreationTime((int) $time); |
|
491 | - return true; |
|
492 | - }); |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * @param string $filePath |
|
497 | - * @param \Sabre\DAV\INode $node |
|
498 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
499 | - */ |
|
500 | - public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
501 | - // chunked upload handling |
|
502 | - if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
503 | - list($path, $name) = \Sabre\Uri\split($filePath); |
|
504 | - $info = \OC_FileChunking::decodeName($name); |
|
505 | - if (!empty($info)) { |
|
506 | - $filePath = $path . '/' . $info['name']; |
|
507 | - } |
|
508 | - } |
|
509 | - |
|
510 | - // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
511 | - if (!$this->server->tree->nodeExists($filePath)) { |
|
512 | - return; |
|
513 | - } |
|
514 | - $node = $this->server->tree->getNodeForPath($filePath); |
|
515 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
516 | - $fileId = $node->getFileId(); |
|
517 | - if (!is_null($fileId)) { |
|
518 | - $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
519 | - } |
|
520 | - } |
|
521 | - } |
|
56 | + // namespace |
|
57 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
58 | + const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; |
|
59 | + const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
60 | + const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid'; |
|
61 | + const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions'; |
|
62 | + const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions'; |
|
63 | + const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions'; |
|
64 | + const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL'; |
|
65 | + const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size'; |
|
66 | + const GETETAG_PROPERTYNAME = '{DAV:}getetag'; |
|
67 | + const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; |
|
68 | + const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id'; |
|
69 | + const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; |
|
70 | + const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; |
|
71 | + const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; |
|
72 | + const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; |
|
73 | + const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; |
|
74 | + const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; |
|
75 | + const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag'; |
|
76 | + const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time'; |
|
77 | + const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time'; |
|
78 | + const SHARE_NOTE = '{http://nextcloud.org/ns}note'; |
|
79 | + |
|
80 | + /** |
|
81 | + * Reference to main server object |
|
82 | + * |
|
83 | + * @var \Sabre\DAV\Server |
|
84 | + */ |
|
85 | + private $server; |
|
86 | + |
|
87 | + /** |
|
88 | + * @var Tree |
|
89 | + */ |
|
90 | + private $tree; |
|
91 | + |
|
92 | + /** |
|
93 | + * Whether this is public webdav. |
|
94 | + * If true, some returned information will be stripped off. |
|
95 | + * |
|
96 | + * @var bool |
|
97 | + */ |
|
98 | + private $isPublic; |
|
99 | + |
|
100 | + /** |
|
101 | + * @var bool |
|
102 | + */ |
|
103 | + private $downloadAttachment; |
|
104 | + |
|
105 | + /** |
|
106 | + * @var IConfig |
|
107 | + */ |
|
108 | + private $config; |
|
109 | + |
|
110 | + /** |
|
111 | + * @var IRequest |
|
112 | + */ |
|
113 | + private $request; |
|
114 | + |
|
115 | + /** |
|
116 | + * @var IPreview |
|
117 | + */ |
|
118 | + private $previewManager; |
|
119 | + |
|
120 | + /** |
|
121 | + * @param Tree $tree |
|
122 | + * @param IConfig $config |
|
123 | + * @param IRequest $request |
|
124 | + * @param IPreview $previewManager |
|
125 | + * @param bool $isPublic |
|
126 | + * @param bool $downloadAttachment |
|
127 | + */ |
|
128 | + public function __construct(Tree $tree, |
|
129 | + IConfig $config, |
|
130 | + IRequest $request, |
|
131 | + IPreview $previewManager, |
|
132 | + $isPublic = false, |
|
133 | + $downloadAttachment = true) { |
|
134 | + $this->tree = $tree; |
|
135 | + $this->config = $config; |
|
136 | + $this->request = $request; |
|
137 | + $this->isPublic = $isPublic; |
|
138 | + $this->downloadAttachment = $downloadAttachment; |
|
139 | + $this->previewManager = $previewManager; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * This initializes the plugin. |
|
144 | + * |
|
145 | + * This function is called by \Sabre\DAV\Server, after |
|
146 | + * addPlugin is called. |
|
147 | + * |
|
148 | + * This method should set up the required event subscriptions. |
|
149 | + * |
|
150 | + * @param \Sabre\DAV\Server $server |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + public function initialize(\Sabre\DAV\Server $server) { |
|
154 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
155 | + $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
156 | + $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
157 | + $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
158 | + $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
159 | + $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
160 | + $server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME; |
|
161 | + $server->protectedProperties[] = self::SIZE_PROPERTYNAME; |
|
162 | + $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME; |
|
163 | + $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME; |
|
164 | + $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; |
|
165 | + $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; |
|
166 | + $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; |
|
167 | + $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; |
|
168 | + $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; |
|
169 | + $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME; |
|
170 | + $server->protectedProperties[] = self::SHARE_NOTE; |
|
171 | + |
|
172 | + // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
173 | + $allowedProperties = ['{DAV:}getetag']; |
|
174 | + $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
175 | + |
|
176 | + $this->server = $server; |
|
177 | + $this->server->on('propFind', [$this, 'handleGetProperties']); |
|
178 | + $this->server->on('propPatch', [$this, 'handleUpdateProperties']); |
|
179 | + $this->server->on('afterBind', [$this, 'sendFileIdHeader']); |
|
180 | + $this->server->on('afterWriteContent', [$this, 'sendFileIdHeader']); |
|
181 | + $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
182 | + $this->server->on('afterMethod:GET', [$this, 'handleDownloadToken']); |
|
183 | + $this->server->on('afterResponse', function ($request, ResponseInterface $response) { |
|
184 | + $body = $response->getBody(); |
|
185 | + if (is_resource($body)) { |
|
186 | + fclose($body); |
|
187 | + } |
|
188 | + }); |
|
189 | + $this->server->on('beforeMove', [$this, 'checkMove']); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Plugin that checks if a move can actually be performed. |
|
194 | + * |
|
195 | + * @param string $source source path |
|
196 | + * @param string $destination destination path |
|
197 | + * @throws Forbidden |
|
198 | + * @throws NotFound |
|
199 | + */ |
|
200 | + function checkMove($source, $destination) { |
|
201 | + $sourceNode = $this->tree->getNodeForPath($source); |
|
202 | + if (!$sourceNode instanceof Node) { |
|
203 | + return; |
|
204 | + } |
|
205 | + list($sourceDir,) = \Sabre\Uri\split($source); |
|
206 | + list($destinationDir,) = \Sabre\Uri\split($destination); |
|
207 | + |
|
208 | + if ($sourceDir !== $destinationDir) { |
|
209 | + $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
|
210 | + if ($sourceNodeFileInfo === null) { |
|
211 | + throw new NotFound($source . ' does not exist'); |
|
212 | + } |
|
213 | + |
|
214 | + if (!$sourceNodeFileInfo->isDeletable()) { |
|
215 | + throw new Forbidden($source . " cannot be deleted"); |
|
216 | + } |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * This sets a cookie to be able to recognize the start of the download |
|
222 | + * the content must not be longer than 32 characters and must only contain |
|
223 | + * alphanumeric characters |
|
224 | + * |
|
225 | + * @param RequestInterface $request |
|
226 | + * @param ResponseInterface $response |
|
227 | + */ |
|
228 | + function handleDownloadToken(RequestInterface $request, ResponseInterface $response) { |
|
229 | + $queryParams = $request->getQueryParameters(); |
|
230 | + |
|
231 | + /** |
|
232 | + * this sets a cookie to be able to recognize the start of the download |
|
233 | + * the content must not be longer than 32 characters and must only contain |
|
234 | + * alphanumeric characters |
|
235 | + */ |
|
236 | + if (isset($queryParams['downloadStartSecret'])) { |
|
237 | + $token = $queryParams['downloadStartSecret']; |
|
238 | + if (!isset($token[32]) |
|
239 | + && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) { |
|
240 | + // FIXME: use $response->setHeader() instead |
|
241 | + setcookie('ocDownloadStarted', $token, time() + 20, '/'); |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Add headers to file download |
|
248 | + * |
|
249 | + * @param RequestInterface $request |
|
250 | + * @param ResponseInterface $response |
|
251 | + */ |
|
252 | + function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
253 | + // Only handle valid files |
|
254 | + $node = $this->tree->getNodeForPath($request->getPath()); |
|
255 | + if (!($node instanceof IFile)) return; |
|
256 | + |
|
257 | + // adds a 'Content-Disposition: attachment' header in case no disposition |
|
258 | + // header has been set before |
|
259 | + if ($this->downloadAttachment && |
|
260 | + $response->getHeader('Content-Disposition') === null) { |
|
261 | + $filename = $node->getName(); |
|
262 | + if ($this->request->isUserAgent( |
|
263 | + [ |
|
264 | + Request::USER_AGENT_IE, |
|
265 | + Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
266 | + Request::USER_AGENT_FREEBOX, |
|
267 | + ])) { |
|
268 | + $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
269 | + } else { |
|
270 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
271 | + . '; filename="' . rawurlencode($filename) . '"'); |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
276 | + //Add OC-Checksum header |
|
277 | + /** @var $node File */ |
|
278 | + $checksum = $node->getChecksum(); |
|
279 | + if ($checksum !== null && $checksum !== '') { |
|
280 | + $response->addHeader('OC-Checksum', $checksum); |
|
281 | + } |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Adds all ownCloud-specific properties |
|
287 | + * |
|
288 | + * @param PropFind $propFind |
|
289 | + * @param \Sabre\DAV\INode $node |
|
290 | + * @return void |
|
291 | + */ |
|
292 | + public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { |
|
293 | + |
|
294 | + $httpRequest = $this->server->httpRequest; |
|
295 | + |
|
296 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
297 | + /** |
|
298 | + * This was disabled, because it made dir listing throw an exception, |
|
299 | + * so users were unable to navigate into folders where one subitem |
|
300 | + * is blocked by the files_accesscontrol app, see: |
|
301 | + * https://github.com/nextcloud/files_accesscontrol/issues/65 |
|
302 | + * if (!$node->getFileInfo()->isReadable()) { |
|
303 | + * // avoid detecting files through this means |
|
304 | + * throw new NotFound(); |
|
305 | + * } |
|
306 | + */ |
|
307 | + |
|
308 | + $propFind->handle(self::FILEID_PROPERTYNAME, function () use ($node) { |
|
309 | + return $node->getFileId(); |
|
310 | + }); |
|
311 | + |
|
312 | + $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) { |
|
313 | + return $node->getInternalFileId(); |
|
314 | + }); |
|
315 | + |
|
316 | + $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function () use ($node) { |
|
317 | + $perms = $node->getDavPermissions(); |
|
318 | + if ($this->isPublic) { |
|
319 | + // remove mount information |
|
320 | + $perms = str_replace(['S', 'M'], '', $perms); |
|
321 | + } |
|
322 | + return $perms; |
|
323 | + }); |
|
324 | + |
|
325 | + $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) { |
|
326 | + return $node->getSharePermissions( |
|
327 | + $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
328 | + ); |
|
329 | + }); |
|
330 | + |
|
331 | + $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) { |
|
332 | + $ncPermissions = $node->getSharePermissions( |
|
333 | + $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
334 | + ); |
|
335 | + $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions); |
|
336 | + return json_encode($ocmPermissions); |
|
337 | + }); |
|
338 | + |
|
339 | + $propFind->handle(self::GETETAG_PROPERTYNAME, function () use ($node) { |
|
340 | + return $node->getETag(); |
|
341 | + }); |
|
342 | + |
|
343 | + $propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use ($node) { |
|
344 | + $owner = $node->getOwner(); |
|
345 | + if (!$owner) { |
|
346 | + return null; |
|
347 | + } else { |
|
348 | + return $owner->getUID(); |
|
349 | + } |
|
350 | + }); |
|
351 | + $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use ($node) { |
|
352 | + $owner = $node->getOwner(); |
|
353 | + if (!$owner) { |
|
354 | + return null; |
|
355 | + } else { |
|
356 | + return $owner->getDisplayName(); |
|
357 | + } |
|
358 | + }); |
|
359 | + |
|
360 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
361 | + return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
|
362 | + }); |
|
363 | + $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) { |
|
364 | + return $node->getSize(); |
|
365 | + }); |
|
366 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
367 | + return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
368 | + }); |
|
369 | + |
|
370 | + $propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest) { |
|
371 | + return $node->getNoteFromShare( |
|
372 | + $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
373 | + ); |
|
374 | + }); |
|
375 | + } |
|
376 | + |
|
377 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
378 | + $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () use ($node) { |
|
379 | + return $this->config->getSystemValue('data-fingerprint', ''); |
|
380 | + }); |
|
381 | + } |
|
382 | + |
|
383 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
384 | + $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function () use ($node) { |
|
385 | + /** @var $node \OCA\DAV\Connector\Sabre\File */ |
|
386 | + try { |
|
387 | + $directDownloadUrl = $node->getDirectDownload(); |
|
388 | + if (isset($directDownloadUrl['url'])) { |
|
389 | + return $directDownloadUrl['url']; |
|
390 | + } |
|
391 | + } catch (StorageNotAvailableException $e) { |
|
392 | + return false; |
|
393 | + } catch (ForbiddenException $e) { |
|
394 | + return false; |
|
395 | + } |
|
396 | + return false; |
|
397 | + }); |
|
398 | + |
|
399 | + $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function () use ($node) { |
|
400 | + $checksum = $node->getChecksum(); |
|
401 | + if ($checksum === null || $checksum === '') { |
|
402 | + return null; |
|
403 | + } |
|
404 | + |
|
405 | + return new ChecksumList($checksum); |
|
406 | + }); |
|
407 | + |
|
408 | + $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function () use ($node) { |
|
409 | + return $node->getFileInfo()->getCreationTime(); |
|
410 | + }); |
|
411 | + |
|
412 | + $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function () use ($node) { |
|
413 | + return $node->getFileInfo()->getUploadTime(); |
|
414 | + }); |
|
415 | + |
|
416 | + } |
|
417 | + |
|
418 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
|
419 | + $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) { |
|
420 | + return $node->getSize(); |
|
421 | + }); |
|
422 | + |
|
423 | + $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) { |
|
424 | + return $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
|
425 | + }); |
|
426 | + } |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * translate Nextcloud permissions to OCM Permissions |
|
431 | + * |
|
432 | + * @param $ncPermissions |
|
433 | + * @return array |
|
434 | + */ |
|
435 | + protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
436 | + |
|
437 | + $ocmPermissions = []; |
|
438 | + |
|
439 | + if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
440 | + $ocmPermissions[] = 'share'; |
|
441 | + } |
|
442 | + |
|
443 | + if ($ncPermissions & Constants::PERMISSION_READ) { |
|
444 | + $ocmPermissions[] = 'read'; |
|
445 | + } |
|
446 | + |
|
447 | + if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
448 | + ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
449 | + $ocmPermissions[] = 'write'; |
|
450 | + } |
|
451 | + |
|
452 | + return $ocmPermissions; |
|
453 | + |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Update ownCloud-specific properties |
|
458 | + * |
|
459 | + * @param string $path |
|
460 | + * @param PropPatch $propPatch |
|
461 | + * |
|
462 | + * @return void |
|
463 | + */ |
|
464 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
465 | + $node = $this->tree->getNodeForPath($path); |
|
466 | + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
467 | + return; |
|
468 | + } |
|
469 | + |
|
470 | + $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function ($time) use ($node) { |
|
471 | + if (empty($time)) { |
|
472 | + return false; |
|
473 | + } |
|
474 | + $node->touch($time); |
|
475 | + return true; |
|
476 | + }); |
|
477 | + $propPatch->handle(self::GETETAG_PROPERTYNAME, function ($etag) use ($node) { |
|
478 | + if (empty($etag)) { |
|
479 | + return false; |
|
480 | + } |
|
481 | + if ($node->setEtag($etag) !== -1) { |
|
482 | + return true; |
|
483 | + } |
|
484 | + return false; |
|
485 | + }); |
|
486 | + $propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function ($time) use ($node) { |
|
487 | + if (empty($time)) { |
|
488 | + return false; |
|
489 | + } |
|
490 | + $node->setCreationTime((int) $time); |
|
491 | + return true; |
|
492 | + }); |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * @param string $filePath |
|
497 | + * @param \Sabre\DAV\INode $node |
|
498 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
499 | + */ |
|
500 | + public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
501 | + // chunked upload handling |
|
502 | + if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
503 | + list($path, $name) = \Sabre\Uri\split($filePath); |
|
504 | + $info = \OC_FileChunking::decodeName($name); |
|
505 | + if (!empty($info)) { |
|
506 | + $filePath = $path . '/' . $info['name']; |
|
507 | + } |
|
508 | + } |
|
509 | + |
|
510 | + // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
511 | + if (!$this->server->tree->nodeExists($filePath)) { |
|
512 | + return; |
|
513 | + } |
|
514 | + $node = $this->server->tree->getNodeForPath($filePath); |
|
515 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
516 | + $fileId = $node->getFileId(); |
|
517 | + if (!is_null($fileId)) { |
|
518 | + $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
519 | + } |
|
520 | + } |
|
521 | + } |
|
522 | 522 | } |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | $this->server->on('propPatch', [$this, 'handleUpdateProperties']); |
179 | 179 | $this->server->on('afterBind', [$this, 'sendFileIdHeader']); |
180 | 180 | $this->server->on('afterWriteContent', [$this, 'sendFileIdHeader']); |
181 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
181 | + $this->server->on('afterMethod:GET', [$this, 'httpGet']); |
|
182 | 182 | $this->server->on('afterMethod:GET', [$this, 'handleDownloadToken']); |
183 | - $this->server->on('afterResponse', function ($request, ResponseInterface $response) { |
|
183 | + $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
|
184 | 184 | $body = $response->getBody(); |
185 | 185 | if (is_resource($body)) { |
186 | 186 | fclose($body); |
@@ -208,11 +208,11 @@ discard block |
||
208 | 208 | if ($sourceDir !== $destinationDir) { |
209 | 209 | $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
210 | 210 | if ($sourceNodeFileInfo === null) { |
211 | - throw new NotFound($source . ' does not exist'); |
|
211 | + throw new NotFound($source.' does not exist'); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | if (!$sourceNodeFileInfo->isDeletable()) { |
215 | - throw new Forbidden($source . " cannot be deleted"); |
|
215 | + throw new Forbidden($source." cannot be deleted"); |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | } |
@@ -265,10 +265,10 @@ discard block |
||
265 | 265 | Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
266 | 266 | Request::USER_AGENT_FREEBOX, |
267 | 267 | ])) { |
268 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
268 | + $response->addHeader('Content-Disposition', 'attachment; filename="'.rawurlencode($filename).'"'); |
|
269 | 269 | } else { |
270 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
271 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
270 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\''.rawurlencode($filename) |
|
271 | + . '; filename="'.rawurlencode($filename).'"'); |
|
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
@@ -305,15 +305,15 @@ discard block |
||
305 | 305 | * } |
306 | 306 | */ |
307 | 307 | |
308 | - $propFind->handle(self::FILEID_PROPERTYNAME, function () use ($node) { |
|
308 | + $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) { |
|
309 | 309 | return $node->getFileId(); |
310 | 310 | }); |
311 | 311 | |
312 | - $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function () use ($node) { |
|
312 | + $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) { |
|
313 | 313 | return $node->getInternalFileId(); |
314 | 314 | }); |
315 | 315 | |
316 | - $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function () use ($node) { |
|
316 | + $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) { |
|
317 | 317 | $perms = $node->getDavPermissions(); |
318 | 318 | if ($this->isPublic) { |
319 | 319 | // remove mount information |
@@ -322,13 +322,13 @@ discard block |
||
322 | 322 | return $perms; |
323 | 323 | }); |
324 | 324 | |
325 | - $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) { |
|
325 | + $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
326 | 326 | return $node->getSharePermissions( |
327 | 327 | $httpRequest->getRawServerValue('PHP_AUTH_USER') |
328 | 328 | ); |
329 | 329 | }); |
330 | 330 | |
331 | - $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) { |
|
331 | + $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
332 | 332 | $ncPermissions = $node->getSharePermissions( |
333 | 333 | $httpRequest->getRawServerValue('PHP_AUTH_USER') |
334 | 334 | ); |
@@ -336,11 +336,11 @@ discard block |
||
336 | 336 | return json_encode($ocmPermissions); |
337 | 337 | }); |
338 | 338 | |
339 | - $propFind->handle(self::GETETAG_PROPERTYNAME, function () use ($node) { |
|
339 | + $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) { |
|
340 | 340 | return $node->getETag(); |
341 | 341 | }); |
342 | 342 | |
343 | - $propFind->handle(self::OWNER_ID_PROPERTYNAME, function () use ($node) { |
|
343 | + $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) { |
|
344 | 344 | $owner = $node->getOwner(); |
345 | 345 | if (!$owner) { |
346 | 346 | return null; |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | return $owner->getUID(); |
349 | 349 | } |
350 | 350 | }); |
351 | - $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function () use ($node) { |
|
351 | + $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) { |
|
352 | 352 | $owner = $node->getOwner(); |
353 | 353 | if (!$owner) { |
354 | 354 | return null; |
@@ -357,17 +357,17 @@ discard block |
||
357 | 357 | } |
358 | 358 | }); |
359 | 359 | |
360 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
360 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function() use ($node) { |
|
361 | 361 | return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
362 | 362 | }); |
363 | - $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) { |
|
363 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
364 | 364 | return $node->getSize(); |
365 | 365 | }); |
366 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
366 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function() use ($node) { |
|
367 | 367 | return $node->getFileInfo()->getMountPoint()->getMountType(); |
368 | 368 | }); |
369 | 369 | |
370 | - $propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest) { |
|
370 | + $propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) { |
|
371 | 371 | return $node->getNoteFromShare( |
372 | 372 | $httpRequest->getRawServerValue('PHP_AUTH_USER') |
373 | 373 | ); |
@@ -375,13 +375,13 @@ discard block |
||
375 | 375 | } |
376 | 376 | |
377 | 377 | if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
378 | - $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () use ($node) { |
|
378 | + $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) { |
|
379 | 379 | return $this->config->getSystemValue('data-fingerprint', ''); |
380 | 380 | }); |
381 | 381 | } |
382 | 382 | |
383 | 383 | if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
384 | - $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function () use ($node) { |
|
384 | + $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) { |
|
385 | 385 | /** @var $node \OCA\DAV\Connector\Sabre\File */ |
386 | 386 | try { |
387 | 387 | $directDownloadUrl = $node->getDirectDownload(); |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | return false; |
397 | 397 | }); |
398 | 398 | |
399 | - $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function () use ($node) { |
|
399 | + $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { |
|
400 | 400 | $checksum = $node->getChecksum(); |
401 | 401 | if ($checksum === null || $checksum === '') { |
402 | 402 | return null; |
@@ -405,22 +405,22 @@ discard block |
||
405 | 405 | return new ChecksumList($checksum); |
406 | 406 | }); |
407 | 407 | |
408 | - $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function () use ($node) { |
|
408 | + $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function() use ($node) { |
|
409 | 409 | return $node->getFileInfo()->getCreationTime(); |
410 | 410 | }); |
411 | 411 | |
412 | - $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function () use ($node) { |
|
412 | + $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function() use ($node) { |
|
413 | 413 | return $node->getFileInfo()->getUploadTime(); |
414 | 414 | }); |
415 | 415 | |
416 | 416 | } |
417 | 417 | |
418 | 418 | if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
419 | - $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) { |
|
419 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
420 | 420 | return $node->getSize(); |
421 | 421 | }); |
422 | 422 | |
423 | - $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) { |
|
423 | + $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) { |
|
424 | 424 | return $node->getFileInfo()->isEncrypted() ? '1' : '0'; |
425 | 425 | }); |
426 | 426 | } |
@@ -467,14 +467,14 @@ discard block |
||
467 | 467 | return; |
468 | 468 | } |
469 | 469 | |
470 | - $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function ($time) use ($node) { |
|
470 | + $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) { |
|
471 | 471 | if (empty($time)) { |
472 | 472 | return false; |
473 | 473 | } |
474 | 474 | $node->touch($time); |
475 | 475 | return true; |
476 | 476 | }); |
477 | - $propPatch->handle(self::GETETAG_PROPERTYNAME, function ($etag) use ($node) { |
|
477 | + $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) { |
|
478 | 478 | if (empty($etag)) { |
479 | 479 | return false; |
480 | 480 | } |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | } |
484 | 484 | return false; |
485 | 485 | }); |
486 | - $propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function ($time) use ($node) { |
|
486 | + $propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function($time) use ($node) { |
|
487 | 487 | if (empty($time)) { |
488 | 488 | return false; |
489 | 489 | } |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | list($path, $name) = \Sabre\Uri\split($filePath); |
504 | 504 | $info = \OC_FileChunking::decodeName($name); |
505 | 505 | if (!empty($info)) { |
506 | - $filePath = $path . '/' . $info['name']; |
|
506 | + $filePath = $path.'/'.$info['name']; |
|
507 | 507 | } |
508 | 508 | } |
509 | 509 |