-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathCapabilitiesService.php
More file actions
148 lines (119 loc) Β· 3.7 KB
/
CapabilitiesService.php
File metadata and controls
148 lines (119 loc) Β· 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Richdocuments\Service;
use OCA\Richdocuments\AppInfo\Application;
use OCP\App\IAppManager;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IL10N;
use Psr\Log\LoggerInterface;
class CapabilitiesService extends CachedRequestService {
private ?array $capabilities = null;
public function __construct(
private IClientService $clientService,
private ICacheFactory $cacheFactory,
private IAppDataFactory $appDataFactory,
private IAppConfig $appConfig,
private LoggerInterface $logger,
private IConfig $config,
private IAppManager $appManager,
private IL10N $l10n,
) {
parent::__construct(
$this->clientService,
$this->cacheFactory,
$this->appDataFactory,
$this->appConfig,
$this->logger,
'capabilities',
);
}
public function getCapabilities() {
if (!$this->capabilities) {
$this->capabilities = $this->getParsedCapabilities();
}
if (!is_array($this->capabilities)) {
return [];
}
return $this->capabilities;
}
public function getProductVersion(): ?string {
return $this->getCapabilities()['productVersion'] ?? null;
}
public function getProductHash(): ?string {
return $this->getCapabilities()['productVersionHash'] ?? null;
}
public function getServerProductName(): ?string {
return $this->getCapabilities()['productName'] ?? null;
}
public function hasNextcloudBranding(): bool {
return $this->isVersionAtLeast('21.11');
}
public function hasDrawSupport(): bool {
return $this->isVersionAtLeast('6.4.7');
}
public function hasTemplateSource(): bool {
return $this->getCapabilities()['hasTemplateSource'] ?? false;
}
public function hasZoteroSupport(): bool {
return $this->getCapabilities()['hasZoteroSupport'] ?? false;
}
public function hasSettingIframeSupport(): bool {
return $this->getCapabilities()['hasSettingIframeSupport'] ?? false;
}
public function hasWASMSupport(): bool {
return $this->getCapabilities()['hasWASMSupport'] ?? false;
}
public function hasDocumentSigningSupport(): bool {
return $this->getCapabilities()['hasDocumentSigningSupport'] ?? false;
}
public function hasFormFilling(): bool {
return $this->isVersionAtLeast('24.04.5.2');
}
private function isVersionAtLeast(string $version): bool {
$productVersion = $this->getCapabilities()['productVersion'] ?? '0.0.0.0';
return version_compare($productVersion, $version, '>=');
}
public function getProductName(): string {
$theme = $this->config->getAppValue(Application::APPNAME, 'theme', 'nextcloud');
if (isset($this->capabilities['productName']) && $theme !== 'nextcloud') {
return $this->capabilities['productName'];
}
return $this->l10n->t('Nextcloud Office');
}
public function hasOtherOOXMLApps(): bool {
if ($this->appManager->isEnabledForUser('officeonline')) {
return true;
}
if ($this->appManager->isEnabledForUser('onlyoffice')) {
return true;
}
return false;
}
public function getCapabilitiesEndpoint(): ?string {
$remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url');
if ($remoteHost === '') {
return null;
}
return rtrim($remoteHost, '/') . '/hosting/capabilities';
}
#[\Override]
protected function sendRequest(IClient $client): string {
$response = $client->get($this->getCapabilitiesEndpoint(), $this->getDefaultRequestOptions());
return (string)$response->getBody();
}
private function getParsedCapabilities() {
$response = $this->get();
if (!$response) {
return [];
}
return json_decode($response, true);
}
}