|
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 \OCP\AppFramework\Controller; |
|
15
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
|
16
|
|
|
use \OCP\IRequest; |
|
17
|
|
|
use \OCP\IL10N; |
|
18
|
|
|
|
|
19
|
|
|
use OCA\Richdocuments\AppConfig; |
|
20
|
|
|
use OCA\Richdocuments\Filter; |
|
21
|
|
|
|
|
22
|
|
|
class SettingsController extends Controller{ |
|
23
|
|
|
/** @var IL10N */ |
|
24
|
|
|
private $l10n; |
|
25
|
|
|
/** @var AppConfig */ |
|
26
|
|
|
private $appConfig; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param string $appName |
|
30
|
|
|
* @param IRequest $request |
|
31
|
|
|
* @param IL10N $l10n |
|
32
|
|
|
* @param AppConfig $appConfig |
|
33
|
|
|
* @param string $userId |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct($appName, |
|
36
|
|
|
IRequest $request, |
|
37
|
|
|
IL10N $l10n, |
|
38
|
|
|
AppConfig $appConfig, |
|
39
|
|
|
$userId) { |
|
40
|
|
|
parent::__construct($appName, $request); |
|
41
|
|
|
$this->l10n = $l10n; |
|
42
|
|
|
$this->appConfig = $appConfig; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @NoAdminRequired |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getSupportedMimes(){ |
|
49
|
|
|
return array( |
|
50
|
|
|
'status' => 'success', |
|
51
|
|
|
'mimes' => Filter::getAll() |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @NoAdminRequired |
|
57
|
|
|
* |
|
58
|
|
|
* @return JSONResponse |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getSettings() { |
|
61
|
|
|
return new JSONResponse([ |
|
62
|
|
|
'doc_format' => $this->appConfig->getAppValue('doc_format'), |
|
63
|
|
|
'wopi_url' => $this->appConfig->getAppValue('wopi_url'), |
|
64
|
|
|
]); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param string $wopi_url |
|
69
|
|
|
* @param string $doc_format |
|
70
|
|
|
* @return JSONResponse |
|
71
|
|
|
*/ |
|
72
|
|
|
public function setSettings($wopi_url, |
|
73
|
|
|
$doc_format){ |
|
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 (\OC::$server->getRequest()->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 ($doc_format !== null) { |
|
86
|
|
|
$this->appConfig->setAppValue('doc_format', $doc_format); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$richMemCache = \OC::$server->getMemCacheFactory()->create('richdocuments'); |
|
90
|
|
|
$richMemCache->clear('discovery.xml'); |
|
91
|
|
|
|
|
92
|
|
|
$response = array( |
|
93
|
|
|
'status' => 'success', |
|
94
|
|
|
'data' => array('message' => (string) $message) |
|
95
|
|
|
); |
|
96
|
|
|
|
|
97
|
|
|
return new JSONResponse($response); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|