|
1
|
|
|
<?php |
|
2
|
|
|
use \OCA\Files_External\Lib\Backend\Backend; |
|
3
|
|
|
use \OCA\Files_External\Lib\DefinitionParameter; |
|
4
|
|
|
use \OCA\Files_External\Service\BackendService; |
|
5
|
|
|
|
|
6
|
|
|
function writeParameterInput($parameter, $options, $classes = []) { |
|
7
|
|
|
$value = ''; |
|
8
|
|
|
if (isset($options[$parameter->getName()])) { |
|
9
|
|
|
$value = $options[$parameter->getName()]; |
|
10
|
|
|
} |
|
11
|
|
|
$placeholder = $parameter->getText(); |
|
12
|
|
|
$is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
|
13
|
|
|
|
|
14
|
|
|
switch ($parameter->getType()) { |
|
15
|
|
View Code Duplication |
case DefinitionParameter::VALUE_PASSWORD: ?> |
|
|
|
|
|
|
16
|
|
|
<?php if ($is_optional) { $classes[] = 'optional'; } ?> |
|
17
|
|
|
<input type="password" |
|
18
|
|
|
<?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
|
19
|
|
|
data-parameter="<?php p($parameter->getName()); ?>" |
|
20
|
|
|
value="<?php p($value); ?>" |
|
21
|
|
|
placeholder="<?php p($placeholder); ?>" |
|
22
|
|
|
/> |
|
23
|
|
|
<?php |
|
24
|
|
|
break; |
|
25
|
|
|
case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
26
|
|
|
<?php $checkboxId = uniqid("checkbox_"); ?> |
|
27
|
|
|
<input type="checkbox" |
|
28
|
|
|
id="<?php p($checkboxId); ?>" |
|
29
|
|
|
<?php if (!empty($classes)): ?> class="checkbox <?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
|
30
|
|
|
data-parameter="<?php p($parameter->getName()); ?>" |
|
31
|
|
|
<?php if ($value === true): ?> checked="checked"<?php endif; ?> |
|
32
|
|
|
/> |
|
33
|
|
|
<label for="<?php p($checkboxId); ?>"><?php p($placeholder); ?></label> |
|
34
|
|
|
<?php |
|
35
|
|
|
break; |
|
36
|
|
|
case DefinitionParameter::VALUE_HIDDEN: ?> |
|
37
|
|
|
<input type="hidden" |
|
38
|
|
|
<?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
|
39
|
|
|
data-parameter="<?php p($parameter->getName()); ?>" |
|
40
|
|
|
value="<?php p($value); ?>" |
|
41
|
|
|
/> |
|
42
|
|
|
<?php |
|
43
|
|
|
break; |
|
44
|
|
View Code Duplication |
default: ?> |
|
|
|
|
|
|
45
|
|
|
<?php if ($is_optional) { $classes[] = 'optional'; } ?> |
|
46
|
|
|
<input type="text" |
|
47
|
|
|
<?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
|
48
|
|
|
data-parameter="<?php p($parameter->getName()); ?>" |
|
49
|
|
|
value="<?php p($value); ?>" |
|
50
|
|
|
placeholder="<?php p($placeholder); ?>" |
|
51
|
|
|
/> |
|
52
|
|
|
<?php |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
?> |
|
56
|
|
|
<form id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>"> |
|
57
|
|
|
<h2><?php p($l->t('External Storage')); ?></h2> |
|
58
|
|
|
<?php if (isset($_['dependencies']) and ($_['dependencies']<>'')) print_unescaped(''.$_['dependencies'].''); ?> |
|
59
|
|
|
<table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['isAdminPage'])); ?>'> |
|
60
|
|
|
<thead> |
|
61
|
|
|
<tr> |
|
62
|
|
|
<th></th> |
|
63
|
|
|
<th><?php p($l->t('Folder name')); ?></th> |
|
64
|
|
|
<th><?php p($l->t('External storage')); ?></th> |
|
65
|
|
|
<th><?php p($l->t('Authentication')); ?></th> |
|
66
|
|
|
<th><?php p($l->t('Configuration')); ?></th> |
|
67
|
|
|
<?php if ($_['isAdminPage']) print_unescaped('<th>'.$l->t('Available for').'</th>'); ?> |
|
68
|
|
|
<th> </th> |
|
69
|
|
|
<th> </th> |
|
70
|
|
|
</tr> |
|
71
|
|
|
</thead> |
|
72
|
|
|
<tbody> |
|
73
|
|
|
<?php foreach ($_['storages'] as $storage): ?> |
|
74
|
|
|
<tr class="<?php p($storage->getBackend()->getIdentifier()); ?>" data-id="<?php p($storage->getId()); ?>"> |
|
75
|
|
|
<td class="status"> |
|
76
|
|
|
<span></span> |
|
77
|
|
|
</td> |
|
78
|
|
|
<td class="mountPoint"><input type="text" name="mountPoint" |
|
79
|
|
|
value="<?php p(ltrim($storage->getMountPoint(), '/')); ?>" |
|
80
|
|
|
data-mountpoint="<?php p(ltrim($storage->getMountPoint(), '/')); ?>" |
|
81
|
|
|
placeholder="<?php p($l->t('Folder name')); ?>" /> |
|
82
|
|
|
</td> |
|
83
|
|
|
<td class="backend" data-class="<?php p($storage->getBackend()->getIdentifier()); ?>"><?php p($storage->getBackend()->getText()); ?> |
|
84
|
|
|
</td> |
|
85
|
|
|
<td class="authentication"> |
|
86
|
|
|
<select class="selectAuthMechanism"> |
|
87
|
|
|
<?php |
|
88
|
|
|
$authSchemes = $storage->getBackend()->getAuthSchemes(); |
|
89
|
|
|
$authMechanisms = array_filter($_['authMechanisms'], function($mech) use ($authSchemes) { |
|
90
|
|
|
return isset($authSchemes[$mech->getScheme()]); |
|
91
|
|
|
}); |
|
92
|
|
|
?> |
|
93
|
|
|
<?php foreach ($authMechanisms as $mech): ?> |
|
94
|
|
|
<option value="<?php p($mech->getIdentifier()); ?>" data-scheme="<?php p($mech->getScheme());?>" |
|
95
|
|
|
<?php if ($mech->getIdentifier() === $storage->getAuthMechanism()->getIdentifier()): ?>selected<?php endif; ?> |
|
96
|
|
|
><?php p($mech->getText()); ?></option> |
|
97
|
|
|
<?php endforeach; ?> |
|
98
|
|
|
</select> |
|
99
|
|
|
</td> |
|
100
|
|
|
<td class="configuration"> |
|
101
|
|
|
<?php |
|
102
|
|
|
$options = $storage->getBackendOptions(); |
|
103
|
|
|
foreach ($storage->getBackend()->getParameters() as $parameter) { |
|
104
|
|
|
writeParameterInput($parameter, $options); |
|
105
|
|
|
} |
|
106
|
|
|
foreach ($storage->getAuthMechanism()->getParameters() as $parameter) { |
|
107
|
|
|
writeParameterInput($parameter, $options, ['auth-param']); |
|
108
|
|
|
} |
|
109
|
|
|
?> |
|
110
|
|
|
</td> |
|
111
|
|
|
<?php if ($_['isAdminPage']): ?> |
|
112
|
|
|
<td class="applicable" |
|
113
|
|
|
align="right" |
|
114
|
|
|
data-applicable-groups='<?php print_unescaped(json_encode($storage->getApplicableGroups())); ?>' |
|
115
|
|
|
data-applicable-users='<?php print_unescaped(json_encode($storage->getApplicableUsers())); ?>'> |
|
116
|
|
|
<input type="hidden" class="applicableUsers" style="width:20em;" value=""/> |
|
117
|
|
|
</td> |
|
118
|
|
|
<?php endif; ?> |
|
119
|
|
|
<td class="mountOptionsToggle"> |
|
120
|
|
|
<img |
|
121
|
|
|
class="svg action" |
|
122
|
|
|
title="<?php p($l->t('Advanced settings')); ?>" |
|
123
|
|
|
alt="<?php p($l->t('Advanced settings')); ?>" |
|
124
|
|
|
src="<?php print_unescaped(image_path('core', 'actions/settings.svg')); ?>" |
|
125
|
|
|
/> |
|
126
|
|
|
<input type="hidden" class="mountOptions" value="<?php p(json_encode($storage->getMountOptions())); ?>" /> |
|
127
|
|
|
<?php if ($_['isAdminPage']): ?> |
|
128
|
|
|
<input type="hidden" class="priority" value="<?php p($storage->getPriority()); ?>" /> |
|
129
|
|
|
<?php endif; ?> |
|
130
|
|
|
</td> |
|
131
|
|
|
<td class="remove"> |
|
132
|
|
|
<img alt="<?php p($l->t('Delete')); ?>" |
|
133
|
|
|
title="<?php p($l->t('Delete')); ?>" |
|
134
|
|
|
class="svg action" |
|
135
|
|
|
src="<?php print_unescaped(image_path('core', 'actions/delete.svg')); ?>" |
|
136
|
|
|
/> |
|
137
|
|
|
</td> |
|
138
|
|
|
</tr> |
|
139
|
|
|
<?php endforeach; ?> |
|
140
|
|
|
<tr id="addMountPoint"> |
|
141
|
|
|
<td class="status"> |
|
142
|
|
|
<span></span> |
|
143
|
|
|
</td> |
|
144
|
|
|
<td class="mountPoint"><input type="text" name="mountPoint" value="" |
|
145
|
|
|
placeholder="<?php p($l->t('Folder name')); ?>"> |
|
146
|
|
|
</td> |
|
147
|
|
|
<td class="backend"> |
|
148
|
|
|
<select id="selectBackend" class="selectBackend" data-configurations='<?php p(json_encode($_['backends'])); ?>'> |
|
149
|
|
|
<option value="" disabled selected |
|
150
|
|
|
style="display:none;"> |
|
151
|
|
|
<?php p($l->t('Add storage')); ?> |
|
152
|
|
|
</option> |
|
153
|
|
|
<?php |
|
154
|
|
|
$sortedBackends = $_['backends']; |
|
155
|
|
|
uasort($sortedBackends, function($a, $b) { |
|
156
|
|
|
return strcasecmp($a->getText(), $b->getText()); |
|
157
|
|
|
}); |
|
158
|
|
|
?> |
|
159
|
|
|
<?php foreach ($sortedBackends as $backend): ?> |
|
160
|
|
|
<?php if ($backend->getDeprecateTo()) continue; // ignore deprecated backends ?> |
|
161
|
|
|
<option value="<?php p($backend->getIdentifier()); ?>"><?php p($backend->getText()); ?></option> |
|
162
|
|
|
<?php endforeach; ?> |
|
163
|
|
|
</select> |
|
164
|
|
|
</td> |
|
165
|
|
|
<td class="authentication" data-mechanisms='<?php p(json_encode($_['authMechanisms'])); ?>'></td> |
|
166
|
|
|
<td class="configuration"></td> |
|
167
|
|
|
<?php if ($_['isAdminPage']): ?> |
|
168
|
|
|
<td class="applicable" align="right"> |
|
169
|
|
|
<input type="hidden" class="applicableUsers" style="width:20em;" value="" /> |
|
170
|
|
|
</td> |
|
171
|
|
|
<?php endif; ?> |
|
172
|
|
|
<td class="mountOptionsToggle hidden"> |
|
173
|
|
|
<img class="svg action" |
|
174
|
|
|
title="<?php p($l->t('Advanced settings')); ?>" |
|
175
|
|
|
alt="<?php p($l->t('Advanced settings')); ?>" |
|
176
|
|
|
src="<?php print_unescaped(image_path('core', 'actions/settings.svg')); ?>" |
|
177
|
|
|
/> |
|
178
|
|
|
<input type="hidden" class="mountOptions" value="" /> |
|
179
|
|
|
</td> |
|
180
|
|
|
<td class="hidden"> |
|
181
|
|
|
<img class="svg action" |
|
182
|
|
|
alt="<?php p($l->t('Delete')); ?>" |
|
183
|
|
|
title="<?php p($l->t('Delete')); ?>" |
|
184
|
|
|
src="<?php print_unescaped(image_path('core', 'actions/delete.svg')); ?>" |
|
185
|
|
|
/> |
|
186
|
|
|
</td> |
|
187
|
|
|
</tr> |
|
188
|
|
|
</tbody> |
|
189
|
|
|
</table> |
|
190
|
|
|
<br /> |
|
191
|
|
|
|
|
192
|
|
|
<?php if ($_['isAdminPage']): ?> |
|
193
|
|
|
<br /> |
|
194
|
|
|
<input type="checkbox" name="allowUserMounting" id="allowUserMounting" class="checkbox" |
|
195
|
|
|
value="1" <?php if ($_['allowUserMounting'] == 'yes') print_unescaped(' checked="checked"'); ?> /> |
|
196
|
|
|
<label for="allowUserMounting"><?php p($l->t('Enable User External Storage')); ?></label> <span id="userMountingMsg" class="msg"></span> |
|
197
|
|
|
|
|
198
|
|
|
<p id="userMountingBackends"<?php if ($_['allowUserMounting'] != 'yes'): ?> class="hidden"<?php endif; ?>> |
|
199
|
|
|
<?php p($l->t('Allow users to mount the following external storage')); ?><br /> |
|
200
|
|
|
<?php $i = 0; foreach ($_['userBackends'] as $backend): ?> |
|
201
|
|
|
<?php if ($deprecateTo = $backend->getDeprecateTo()): ?> |
|
202
|
|
|
<input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" /> |
|
203
|
|
|
<?php else: ?> |
|
204
|
|
|
<input type="checkbox" id="allowUserMountingBackends<?php p($i); ?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) print_unescaped(' checked="checked"'); ?> /> |
|
205
|
|
|
<label for="allowUserMountingBackends<?php p($i); ?>"><?php p($backend->getText()); ?></label> <br /> |
|
206
|
|
|
<?php endif; ?> |
|
207
|
|
|
<?php $i++; ?> |
|
208
|
|
|
<?php endforeach; ?> |
|
209
|
|
|
</p> |
|
210
|
|
|
<?php endif; ?> |
|
211
|
|
|
</form> |
|
212
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.