1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ownCloud - Richdocuments App |
4
|
|
|
* |
5
|
|
|
* @author Victor Dubiniuk |
6
|
|
|
* @copyright 2014 Victor Dubiniuk [email protected] |
7
|
|
|
* |
8
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
9
|
|
|
* later. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\Richdocuments\Controller; |
13
|
|
|
|
14
|
|
|
use OCA\Richdocuments\WOPI\DiscoveryManager; |
15
|
|
|
use \OCP\AppFramework\Controller; |
16
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
17
|
|
|
use OCP\Files\IAppData; |
18
|
|
|
use \OCP\IRequest; |
19
|
|
|
use \OCP\IL10N; |
20
|
|
|
use OCA\Richdocuments\AppConfig; |
21
|
|
|
|
22
|
|
|
class SettingsController extends Controller{ |
23
|
|
|
/** @var IL10N */ |
24
|
|
|
private $l10n; |
25
|
|
|
/** @var AppConfig */ |
26
|
|
|
private $appConfig; |
27
|
|
|
/** @var DiscoveryManager */ |
28
|
|
|
private $discoveryManager; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $appName |
32
|
|
|
* @param IRequest $request |
33
|
|
|
* @param IL10N $l10n |
34
|
|
|
* @param AppConfig $appConfig |
35
|
|
|
* @param DiscoveryManager $discoveryManager |
36
|
|
|
*/ |
37
|
|
|
public function __construct($appName, |
38
|
|
|
IRequest $request, |
39
|
|
|
IL10N $l10n, |
40
|
|
|
AppConfig $appConfig, |
41
|
|
|
DiscoveryManager $discoveryManager) { |
42
|
|
|
parent::__construct($appName, $request); |
43
|
|
|
$this->l10n = $l10n; |
44
|
|
|
$this->appConfig = $appConfig; |
45
|
|
|
$this->discoveryManager = $discoveryManager; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @NoAdminRequired |
50
|
|
|
* |
51
|
|
|
* @return JSONResponse |
52
|
|
|
*/ |
53
|
|
|
public function getSettings() { |
54
|
|
|
return new JSONResponse([ |
55
|
|
|
'wopi_url' => $this->appConfig->getAppValue('wopi_url'), |
56
|
|
|
'use_groups' => $this->appConfig->getAppValue('use_groups'), |
57
|
|
|
'edit_groups' => $this->appConfig->getAppValue('edit_groups'), |
58
|
|
|
'doc_format' => $this->appConfig->getAppValue('doc_format'), |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $wopi_url |
64
|
|
|
* @param string $edit_groups |
65
|
|
|
* @param string $use_groups |
66
|
|
|
* @param string $doc_format |
67
|
|
|
* @return JSONResponse |
68
|
|
|
*/ |
69
|
|
|
public function setSettings($wopi_url, |
70
|
|
|
$edit_groups, |
71
|
|
|
$use_groups, |
72
|
|
|
$doc_format, |
73
|
|
|
$external_apps){ |
74
|
|
|
$message = $this->l10n->t('Saved'); |
75
|
|
|
|
76
|
|
|
if ($wopi_url !== null){ |
77
|
|
|
$this->appConfig->setAppValue('wopi_url', $wopi_url); |
78
|
|
|
|
79
|
|
|
$colon = strpos($wopi_url, ':', 0); |
80
|
|
|
if ($this->request->getServerProtocol() !== substr($wopi_url, 0, $colon)){ |
81
|
|
|
$message = $this->l10n->t('Saved with error: Collabora Online should use the same protocol as the server installation.'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if ($edit_groups !== null){ |
86
|
|
|
$this->appConfig->setAppValue('edit_groups', $edit_groups); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
if ($use_groups !== null){ |
90
|
|
|
$this->appConfig->setAppValue('use_groups', $use_groups); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if ($doc_format !== null) { |
94
|
|
|
$this->appConfig->setAppValue('doc_format', $doc_format); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
if ($external_apps !== null) { |
98
|
|
|
$this->appConfig->setAppValue('external_apps', $external_apps); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$this->discoveryManager->refretch(); |
102
|
|
|
|
103
|
|
|
$response = [ |
104
|
|
|
'status' => 'success', |
105
|
|
|
'data' => array('message' => (string) $message) |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
return new JSONResponse($response); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|