|
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
|
|
|
return new DataResponse([ |
|
66
|
|
|
'wopi_url' => $this->config->getAppValue('richdocuments', 'wopi_url') |
|
67
|
|
|
]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @PublicPage |
|
72
|
|
|
* @NoCSRFRequired |
|
73
|
|
|
* |
|
74
|
|
|
* Check the file info of a remote accessing a file |
|
75
|
|
|
* |
|
76
|
|
|
* this is used to make sure we respect reshares of federated shares with the |
|
77
|
|
|
* applied permissions and also have information about the actual editor |
|
78
|
|
|
* |
|
79
|
|
|
* @param $token |
|
80
|
|
|
* @return DataResponse |
|
81
|
|
|
* @throws DoesNotExistException |
|
82
|
|
|
*/ |
|
83
|
|
|
public function remoteWopiToken($token) { |
|
84
|
|
|
$wopi = $this->wopiMapper->getWopiForToken($token); |
|
85
|
|
|
return new DataResponse([ |
|
86
|
|
|
'ownerUid' => $wopi->getOwnerUid(), |
|
87
|
|
|
'editorUid' => $wopi->getEditorUid(), |
|
88
|
|
|
'canwrite' => $wopi->getCanwrite(), |
|
89
|
|
|
'hideDownload' => $wopi->getHideDownload(), |
|
|
|
|
|
|
90
|
|
|
'direct' => $wopi->getDirect(), |
|
|
|
|
|
|
91
|
|
|
'serverHost' => $wopi->getServerHost(), |
|
92
|
|
|
'guestDisplayname' => $wopi->getGuestDisplayname() |
|
93
|
|
|
]); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: