1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2019 Julius Härtl <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Julius Härtl <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
namespace OCA\Richdocuments\Controller; |
24
|
|
|
|
25
|
|
|
use OCP\AppFramework\Db\DoesNotExistException; |
26
|
|
|
use \OCP\AppFramework\OCSController; |
|
|
|
|
27
|
|
|
use OCA\Richdocuments\Db\WopiMapper; |
28
|
|
|
use OCP\AppFramework\Http\DataResponse; |
29
|
|
|
use OCP\AppFramework\OCS\OCSNotFoundException; |
30
|
|
|
use OCP\Files\NotFoundException; |
31
|
|
|
use OCP\IConfig; |
32
|
|
|
use OCP\IRequest; |
33
|
|
|
use OCP\Share\Exceptions\ShareNotFound; |
34
|
|
|
use OCP\Share\IManager; |
35
|
|
|
|
36
|
|
|
class FederationController extends OCSController { |
37
|
|
|
|
38
|
|
|
/** @var IConfig */ |
39
|
|
|
private $config; |
40
|
|
|
|
41
|
|
|
/** @var WopiMapper */ |
42
|
|
|
private $wopiMapper; |
43
|
|
|
|
44
|
|
|
/** @var IManager */ |
45
|
|
|
private $shareManager; |
46
|
|
|
|
47
|
|
|
public function __construct( |
48
|
|
|
string $appName, |
49
|
|
|
IRequest $request, |
50
|
|
|
IConfig $config, |
51
|
|
|
WopiMapper $wopiMapper, |
52
|
|
|
IManager $shareManager |
53
|
|
|
) { |
54
|
|
|
parent::__construct($appName, $request); |
55
|
|
|
$this->config = $config; |
56
|
|
|
$this->wopiMapper = $wopiMapper; |
57
|
|
|
$this->shareManager = $shareManager; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @PublicPage |
62
|
|
|
* @NoCSRFRequired |
63
|
|
|
*/ |
64
|
|
|
public function index() { |
65
|
|
|
$response = new DataResponse([ |
66
|
|
|
'wopi_url' => $this->config->getAppValue('richdocuments', 'wopi_url') |
67
|
|
|
]); |
68
|
|
|
$response->setHeaders(['X-Frame-Options' => 'ALLOW']); |
69
|
|
|
return $response; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @PublicPage |
74
|
|
|
* @NoCSRFRequired |
75
|
|
|
* |
76
|
|
|
* Check the file info of a remote accessing a file |
77
|
|
|
* |
78
|
|
|
* this is used to make sure we respect reshares of federated shares with the |
79
|
|
|
* applied permissions and also have information about the actual editor |
80
|
|
|
* |
81
|
|
|
* @param $token |
82
|
|
|
* @return DataResponse |
83
|
|
|
* @throws DoesNotExistException |
84
|
|
|
*/ |
85
|
|
|
public function remoteWopiToken($token) { |
86
|
|
|
$wopi = $this->wopiMapper->getWopiForToken($token); |
87
|
|
|
return new DataResponse([ |
88
|
|
|
'ownerUid' => $wopi->getOwnerUid(), |
89
|
|
|
'editorUid' => $wopi->getEditorUid(), |
90
|
|
|
'canwrite' => $wopi->getCanwrite(), |
91
|
|
|
'hideDownload' => $wopi->getHideDownload(), |
92
|
|
|
'direct' => $wopi->getDirect(), |
93
|
|
|
'serverHost' => $wopi->getServerHost(), |
94
|
|
|
'guestDisplayname' => $wopi->getGuestDisplayname() |
95
|
|
|
]); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: