This repository was archived by the owner on Jun 28, 2018. It is now read-only.
forked from owncloud-archive/documents
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsettingscontroller.php
More file actions
169 lines (151 loc) · 3.78 KB
/
settingscontroller.php
File metadata and controls
169 lines (151 loc) · 3.78 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
* ownCloud - Documents App
*
* @author Victor Dubiniuk
* @copyright 2014 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
namespace OCA\Documents\Controller;
use \OCP\AppFramework\Controller;
use \OCP\IRequest;
use \OCP\IL10N;
use \OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCA\Documents\AppConfig;
use OCA\Documents\Converter;
use OCA\Documents\Filter;
class SettingsController extends Controller{
private $userId;
private $l10n;
private $appConfig;
public function __construct($appName, IRequest $request, IL10N $l10n, AppConfig $appConfig, $userId){
parent::__construct($appName, $request);
$this->userId = $userId;
$this->l10n = $l10n;
$this->appConfig = $appConfig;
}
/**
* @NoAdminRequired
*/
public function getSupportedMimes(){
return array(
'status' => 'success',
'mimes' => Filter::getAll()
);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function personalIndex(){
return new TemplateResponse(
$this->appName,
'personal',
[ 'save_path' => $this->appConfig->getUserValue($this->userId, 'save_path') ],
'blank'
);
}
/**
* @NoCSRFRequired
*/
public function settingsIndex(){
return new TemplateResponse(
$this->appName,
'settings',
[ 'unstable' => $this->appConfig->getAppValue('unstable') ],
'blank'
);
}
/**
* @NoCSRFRequired
*/
public function adminIndex(){
return new TemplateResponse(
$this->appName,
'admin',
[
'converter' => $this->appConfig->getAppValue('converter'),
'converter_url' => $this->appConfig->getAppValue('converter_url'),
],
'blank'
);
}
/**
* @NoAdminRequired
*/
public function savePersonal($savePath){
if (is_null($savePath)){
$savePath = '/';
}
$status = true;
if (\OC\Files\Filesystem::file_exists($savePath) === false ){
$status = \OC\Files\Filesystem::mkdir($savePath);
}
if ($status){
$this->appConfig->setUserValue($this->userId, 'save_path', $savePath);
$response = array(
'status' => 'success',
'data' => array('message'=> $this->l10n->t('Directory saved successfully.'))
);
} else {
$response = array(
'status' => 'error',
'data' => array(
'message'=> $this->l10n->t('An error occurred while changing directory.')
)
);
}
return $response;
}
public function setUnstable($unstable){
if (!is_null($unstable)){
$this->appConfig->setAppValue('unstable', $unstable);
}
return array('status' => 'success');
}
public function setConverter($converter, $url){
if (!is_null($converter)){
$this->appConfig->setAppValue('converter', $converter);
}
if (!is_null($url)){
$this->appConfig->setAppValue('converter_url', $url);
}
$response = array(
'status' => 'success',
'data' => array('message' => (string) $this->l10n->t('Saved'))
);
$currentConverter = $this->appConfig->getAppValue('converter');
if ($currentConverter == 'external'){
if (!Converter::checkConnection()){
\OC::$server->getLogger()->warning(
'Bad response from Format Filter Server',
['app' => $this->appName]
);
$response = array(
'status' => 'error',
'data'=>
array('message' => (string) $this->l10n->t('Format filter server is down or misconfigured') )
);
}
} elseif ($currentConverter === 'local') {
try {
if (!Converter::testConversion()){
$response = array(
'status' => 'error',
'data'=>
array('message' => (string) $this->l10n->t('Conversion failed. Check log for details.') )
);
}
} catch (\Exception $e){
$response = array(
'status' => 'error',
'data'=> array('message' => $e->getMessage())
);
}
}
return $response;
}
}