1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016 Lukas Reschke <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @license GNU AGPL version 3 or any later version |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as |
9
|
|
|
* published by the Free Software Foundation, either version 3 of the |
10
|
|
|
* License, or (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace OCA\Richdocuments\WOPI; |
23
|
|
|
|
24
|
|
|
use OCP\AppFramework\Utility\ITimeFactory; |
25
|
|
|
use OCP\Files\IAppData; |
26
|
|
|
use OCP\Files\NotFoundException; |
27
|
|
|
use OCP\Files\SimpleFS\ISimpleFolder; |
28
|
|
|
use OCP\Http\Client\IClientService; |
29
|
|
|
use OCP\IConfig; |
30
|
|
|
use OCP\IL10N; |
31
|
|
|
use OCP\Notification\IApp; |
32
|
|
|
|
33
|
|
|
class DiscoveryManager { |
34
|
|
|
/** @var IClientService */ |
35
|
|
|
private $clientService; |
36
|
|
|
/** @var ISimpleFolder */ |
37
|
|
|
private $appData; |
38
|
|
|
/** @var IConfig */ |
39
|
|
|
private $config; |
40
|
|
|
/** @var IL10N */ |
41
|
|
|
private $l10n; |
42
|
|
|
/** @var ITimeFactory */ |
43
|
|
|
private $timeFactory; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param IClientService $clientService |
47
|
|
|
* @param IAppData $appData |
48
|
|
|
* @param IConfig $config |
49
|
|
|
* @param IL10N $l10n |
50
|
|
|
* @param ITimeFactory $timeFactory |
51
|
|
|
*/ |
52
|
|
|
public function __construct(IClientService $clientService, |
53
|
|
|
IAppData $appData, |
54
|
|
|
IConfig $config, |
55
|
|
|
IL10N $l10n, |
56
|
|
|
ITimeFactory $timeFactory) { |
57
|
|
|
$this->clientService = $clientService; |
58
|
|
|
try { |
59
|
|
|
$this->appData = $appData->getFolder('richdocuments'); |
60
|
|
|
} catch (NotFoundException $e) { |
|
|
|
|
61
|
|
|
$this->appData = $appData->newFolder('richdocuments'); |
62
|
|
|
} |
63
|
|
|
$this->config = $config; |
64
|
|
|
$this->l10n = $l10n; |
65
|
|
|
$this->timeFactory = $timeFactory; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function get() { |
69
|
|
|
// First check if there is a local valid discovery file |
70
|
|
|
try { |
71
|
|
|
$file = $this->appData->getFile('discovery.xml'); |
72
|
|
|
$decodedFile = json_decode($file->getContent(), true); |
73
|
|
|
if($decodedFile['timestamp'] + 3600 > $this->timeFactory->getTime()) { |
74
|
|
|
return $decodedFile['data']; |
75
|
|
|
} |
76
|
|
|
} catch (NotFoundException $e) { |
|
|
|
|
77
|
|
|
$file = $this->appData->newFile('discovery.xml'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url'); |
81
|
|
|
$wopiDiscovery = $remoteHost . '/hosting/discovery'; |
82
|
|
|
|
83
|
|
|
$client = $this->clientService->newClient(); |
84
|
|
|
try { |
85
|
|
|
$response = $client->get($wopiDiscovery); |
86
|
|
|
} catch (\Exception $e) { |
87
|
|
|
throw $e; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$responseBody = $response->getBody(); |
91
|
|
|
$file->putContent( |
92
|
|
|
json_encode([ |
93
|
|
|
'data' => $responseBody, |
94
|
|
|
'timestamp' => $this->timeFactory->getTime(), |
95
|
|
|
]) |
96
|
|
|
); |
97
|
|
|
return $responseBody; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.