@@ -42,173 +42,173 @@ |
||
42 | 42 | // Legacy routes above |
43 | 43 | /** @var $this \OC\Route\Router */ |
44 | 44 | $this->create('files_ajax_download', 'apps/files/ajax/download.php') |
45 | - ->actionInclude('files/ajax/download.php'); |
|
45 | + ->actionInclude('files/ajax/download.php'); |
|
46 | 46 | |
47 | 47 | /** @var Application $application */ |
48 | 48 | $application = \OC::$server->query(Application::class); |
49 | 49 | $application->registerRoutes( |
50 | - $this, |
|
51 | - [ |
|
52 | - 'routes' => [ |
|
53 | - [ |
|
54 | - 'name' => 'view#index', |
|
55 | - 'url' => '/', |
|
56 | - 'verb' => 'GET', |
|
57 | - ], |
|
58 | - [ |
|
59 | - 'name' => 'View#showFile', |
|
60 | - 'url' => '/f/{fileid}', |
|
61 | - 'verb' => 'GET', |
|
62 | - 'root' => '', |
|
63 | - ], |
|
64 | - [ |
|
65 | - 'name' => 'API#getThumbnail', |
|
66 | - 'url' => '/api/v1/thumbnail/{x}/{y}/{file}', |
|
67 | - 'verb' => 'GET', |
|
68 | - 'requirements' => ['file' => '.+'] |
|
69 | - ], |
|
70 | - [ |
|
71 | - 'name' => 'API#updateFileTags', |
|
72 | - 'url' => '/api/v1/files/{path}', |
|
73 | - 'verb' => 'POST', |
|
74 | - 'requirements' => ['path' => '.+'], |
|
75 | - ], |
|
76 | - [ |
|
77 | - 'name' => 'API#getRecentFiles', |
|
78 | - 'url' => '/api/v1/recent/', |
|
79 | - 'verb' => 'GET' |
|
80 | - ], |
|
81 | - [ |
|
82 | - 'name' => 'API#getStorageStats', |
|
83 | - 'url' => '/api/v1/stats', |
|
84 | - 'verb' => 'GET' |
|
85 | - ], |
|
86 | - [ |
|
87 | - 'name' => 'API#setConfig', |
|
88 | - 'url' => '/api/v1/config/{key}', |
|
89 | - 'verb' => 'POST' |
|
90 | - ], |
|
91 | - [ |
|
92 | - 'name' => 'API#getConfigs', |
|
93 | - 'url' => '/api/v1/configs', |
|
94 | - 'verb' => 'GET' |
|
95 | - ], |
|
96 | - [ |
|
97 | - 'name' => 'API#updateFileSorting', |
|
98 | - 'url' => '/api/v1/sorting', |
|
99 | - 'verb' => 'POST' |
|
100 | - ], |
|
101 | - [ |
|
102 | - 'name' => 'API#showHiddenFiles', |
|
103 | - 'url' => '/api/v1/showhidden', |
|
104 | - 'verb' => 'POST' |
|
105 | - ], |
|
106 | - [ |
|
107 | - 'name' => 'API#cropImagePreviews', |
|
108 | - 'url' => '/api/v1/cropimagepreviews', |
|
109 | - 'verb' => 'POST' |
|
110 | - ], |
|
111 | - [ |
|
112 | - 'name' => 'API#showGridView', |
|
113 | - 'url' => '/api/v1/showgridview', |
|
114 | - 'verb' => 'POST' |
|
115 | - ], |
|
116 | - [ |
|
117 | - 'name' => 'API#getGridView', |
|
118 | - 'url' => '/api/v1/showgridview', |
|
119 | - 'verb' => 'GET' |
|
120 | - ], |
|
121 | - [ |
|
122 | - 'name' => 'API#toggleShowFolder', |
|
123 | - 'url' => '/api/v1/toggleShowFolder/{key}', |
|
124 | - 'verb' => 'POST' |
|
125 | - ], |
|
126 | - [ |
|
127 | - 'name' => 'API#getNodeType', |
|
128 | - 'url' => '/api/v1/quickaccess/get/NodeType', |
|
129 | - 'verb' => 'GET', |
|
130 | - ], |
|
131 | - [ |
|
132 | - 'name' => 'DirectEditingView#edit', |
|
133 | - 'url' => '/directEditing/{token}', |
|
134 | - 'verb' => 'GET' |
|
135 | - ], |
|
136 | - [ |
|
137 | - 'name' => 'view#index', |
|
138 | - 'url' => '/{view}', |
|
139 | - 'verb' => 'GET', |
|
140 | - 'postfix' => 'view', |
|
141 | - ], |
|
142 | - [ |
|
143 | - 'name' => 'view#index', |
|
144 | - 'url' => '/{view}/{fileid}', |
|
145 | - 'verb' => 'GET', |
|
146 | - 'postfix' => 'fileid', |
|
147 | - ], |
|
148 | - ], |
|
149 | - 'ocs' => [ |
|
150 | - [ |
|
151 | - 'name' => 'DirectEditing#info', |
|
152 | - 'url' => '/api/v1/directEditing', |
|
153 | - 'verb' => 'GET' |
|
154 | - ], |
|
155 | - [ |
|
156 | - 'name' => 'DirectEditing#templates', |
|
157 | - 'url' => '/api/v1/directEditing/templates/{editorId}/{creatorId}', |
|
158 | - 'verb' => 'GET' |
|
159 | - ], |
|
160 | - [ |
|
161 | - 'name' => 'DirectEditing#open', |
|
162 | - 'url' => '/api/v1/directEditing/open', |
|
163 | - 'verb' => 'POST' |
|
164 | - ], |
|
165 | - [ |
|
166 | - 'name' => 'DirectEditing#create', |
|
167 | - 'url' => '/api/v1/directEditing/create', |
|
168 | - 'verb' => 'POST' |
|
169 | - ], |
|
170 | - [ |
|
171 | - 'name' => 'Template#list', |
|
172 | - 'url' => '/api/v1/templates', |
|
173 | - 'verb' => 'GET' |
|
174 | - ], |
|
175 | - [ |
|
176 | - 'name' => 'Template#create', |
|
177 | - 'url' => '/api/v1/templates/create', |
|
178 | - 'verb' => 'POST' |
|
179 | - ], |
|
180 | - [ |
|
181 | - 'name' => 'Template#path', |
|
182 | - 'url' => '/api/v1/templates/path', |
|
183 | - 'verb' => 'POST' |
|
184 | - ], |
|
185 | - [ |
|
186 | - 'name' => 'TransferOwnership#transfer', |
|
187 | - 'url' => '/api/v1/transferownership', |
|
188 | - 'verb' => 'POST', |
|
189 | - ], |
|
190 | - [ |
|
191 | - 'name' => 'TransferOwnership#accept', |
|
192 | - 'url' => '/api/v1/transferownership/{id}', |
|
193 | - 'verb' => 'POST', |
|
194 | - ], |
|
195 | - [ |
|
196 | - 'name' => 'TransferOwnership#reject', |
|
197 | - 'url' => '/api/v1/transferownership/{id}', |
|
198 | - 'verb' => 'DELETE', |
|
199 | - ], |
|
200 | - [ |
|
201 | - /** @see OpenLocalEditorController::create() */ |
|
202 | - 'name' => 'OpenLocalEditor#create', |
|
203 | - 'url' => '/api/v1/openlocaleditor', |
|
204 | - 'verb' => 'POST', |
|
205 | - ], |
|
206 | - [ |
|
207 | - /** @see OpenLocalEditorController::validate() */ |
|
208 | - 'name' => 'OpenLocalEditor#validate', |
|
209 | - 'url' => '/api/v1/openlocaleditor/{token}', |
|
210 | - 'verb' => 'POST', |
|
211 | - ], |
|
212 | - ], |
|
213 | - ] |
|
50 | + $this, |
|
51 | + [ |
|
52 | + 'routes' => [ |
|
53 | + [ |
|
54 | + 'name' => 'view#index', |
|
55 | + 'url' => '/', |
|
56 | + 'verb' => 'GET', |
|
57 | + ], |
|
58 | + [ |
|
59 | + 'name' => 'View#showFile', |
|
60 | + 'url' => '/f/{fileid}', |
|
61 | + 'verb' => 'GET', |
|
62 | + 'root' => '', |
|
63 | + ], |
|
64 | + [ |
|
65 | + 'name' => 'API#getThumbnail', |
|
66 | + 'url' => '/api/v1/thumbnail/{x}/{y}/{file}', |
|
67 | + 'verb' => 'GET', |
|
68 | + 'requirements' => ['file' => '.+'] |
|
69 | + ], |
|
70 | + [ |
|
71 | + 'name' => 'API#updateFileTags', |
|
72 | + 'url' => '/api/v1/files/{path}', |
|
73 | + 'verb' => 'POST', |
|
74 | + 'requirements' => ['path' => '.+'], |
|
75 | + ], |
|
76 | + [ |
|
77 | + 'name' => 'API#getRecentFiles', |
|
78 | + 'url' => '/api/v1/recent/', |
|
79 | + 'verb' => 'GET' |
|
80 | + ], |
|
81 | + [ |
|
82 | + 'name' => 'API#getStorageStats', |
|
83 | + 'url' => '/api/v1/stats', |
|
84 | + 'verb' => 'GET' |
|
85 | + ], |
|
86 | + [ |
|
87 | + 'name' => 'API#setConfig', |
|
88 | + 'url' => '/api/v1/config/{key}', |
|
89 | + 'verb' => 'POST' |
|
90 | + ], |
|
91 | + [ |
|
92 | + 'name' => 'API#getConfigs', |
|
93 | + 'url' => '/api/v1/configs', |
|
94 | + 'verb' => 'GET' |
|
95 | + ], |
|
96 | + [ |
|
97 | + 'name' => 'API#updateFileSorting', |
|
98 | + 'url' => '/api/v1/sorting', |
|
99 | + 'verb' => 'POST' |
|
100 | + ], |
|
101 | + [ |
|
102 | + 'name' => 'API#showHiddenFiles', |
|
103 | + 'url' => '/api/v1/showhidden', |
|
104 | + 'verb' => 'POST' |
|
105 | + ], |
|
106 | + [ |
|
107 | + 'name' => 'API#cropImagePreviews', |
|
108 | + 'url' => '/api/v1/cropimagepreviews', |
|
109 | + 'verb' => 'POST' |
|
110 | + ], |
|
111 | + [ |
|
112 | + 'name' => 'API#showGridView', |
|
113 | + 'url' => '/api/v1/showgridview', |
|
114 | + 'verb' => 'POST' |
|
115 | + ], |
|
116 | + [ |
|
117 | + 'name' => 'API#getGridView', |
|
118 | + 'url' => '/api/v1/showgridview', |
|
119 | + 'verb' => 'GET' |
|
120 | + ], |
|
121 | + [ |
|
122 | + 'name' => 'API#toggleShowFolder', |
|
123 | + 'url' => '/api/v1/toggleShowFolder/{key}', |
|
124 | + 'verb' => 'POST' |
|
125 | + ], |
|
126 | + [ |
|
127 | + 'name' => 'API#getNodeType', |
|
128 | + 'url' => '/api/v1/quickaccess/get/NodeType', |
|
129 | + 'verb' => 'GET', |
|
130 | + ], |
|
131 | + [ |
|
132 | + 'name' => 'DirectEditingView#edit', |
|
133 | + 'url' => '/directEditing/{token}', |
|
134 | + 'verb' => 'GET' |
|
135 | + ], |
|
136 | + [ |
|
137 | + 'name' => 'view#index', |
|
138 | + 'url' => '/{view}', |
|
139 | + 'verb' => 'GET', |
|
140 | + 'postfix' => 'view', |
|
141 | + ], |
|
142 | + [ |
|
143 | + 'name' => 'view#index', |
|
144 | + 'url' => '/{view}/{fileid}', |
|
145 | + 'verb' => 'GET', |
|
146 | + 'postfix' => 'fileid', |
|
147 | + ], |
|
148 | + ], |
|
149 | + 'ocs' => [ |
|
150 | + [ |
|
151 | + 'name' => 'DirectEditing#info', |
|
152 | + 'url' => '/api/v1/directEditing', |
|
153 | + 'verb' => 'GET' |
|
154 | + ], |
|
155 | + [ |
|
156 | + 'name' => 'DirectEditing#templates', |
|
157 | + 'url' => '/api/v1/directEditing/templates/{editorId}/{creatorId}', |
|
158 | + 'verb' => 'GET' |
|
159 | + ], |
|
160 | + [ |
|
161 | + 'name' => 'DirectEditing#open', |
|
162 | + 'url' => '/api/v1/directEditing/open', |
|
163 | + 'verb' => 'POST' |
|
164 | + ], |
|
165 | + [ |
|
166 | + 'name' => 'DirectEditing#create', |
|
167 | + 'url' => '/api/v1/directEditing/create', |
|
168 | + 'verb' => 'POST' |
|
169 | + ], |
|
170 | + [ |
|
171 | + 'name' => 'Template#list', |
|
172 | + 'url' => '/api/v1/templates', |
|
173 | + 'verb' => 'GET' |
|
174 | + ], |
|
175 | + [ |
|
176 | + 'name' => 'Template#create', |
|
177 | + 'url' => '/api/v1/templates/create', |
|
178 | + 'verb' => 'POST' |
|
179 | + ], |
|
180 | + [ |
|
181 | + 'name' => 'Template#path', |
|
182 | + 'url' => '/api/v1/templates/path', |
|
183 | + 'verb' => 'POST' |
|
184 | + ], |
|
185 | + [ |
|
186 | + 'name' => 'TransferOwnership#transfer', |
|
187 | + 'url' => '/api/v1/transferownership', |
|
188 | + 'verb' => 'POST', |
|
189 | + ], |
|
190 | + [ |
|
191 | + 'name' => 'TransferOwnership#accept', |
|
192 | + 'url' => '/api/v1/transferownership/{id}', |
|
193 | + 'verb' => 'POST', |
|
194 | + ], |
|
195 | + [ |
|
196 | + 'name' => 'TransferOwnership#reject', |
|
197 | + 'url' => '/api/v1/transferownership/{id}', |
|
198 | + 'verb' => 'DELETE', |
|
199 | + ], |
|
200 | + [ |
|
201 | + /** @see OpenLocalEditorController::create() */ |
|
202 | + 'name' => 'OpenLocalEditor#create', |
|
203 | + 'url' => '/api/v1/openlocaleditor', |
|
204 | + 'verb' => 'POST', |
|
205 | + ], |
|
206 | + [ |
|
207 | + /** @see OpenLocalEditorController::validate() */ |
|
208 | + 'name' => 'OpenLocalEditor#validate', |
|
209 | + 'url' => '/api/v1/openlocaleditor/{token}', |
|
210 | + 'verb' => 'POST', |
|
211 | + ], |
|
212 | + ], |
|
213 | + ] |
|
214 | 214 | ); |
@@ -4,11 +4,11 @@ discard block |
||
4 | 4 | |
5 | 5 | <?php |
6 | 6 | |
7 | - $pinned = 0; |
|
8 | - foreach ($_['navigationItems'] as $item) { |
|
9 | - $pinned = NavigationListElements($item, $l, $pinned); |
|
10 | - } |
|
11 | - ?> |
|
7 | + $pinned = 0; |
|
8 | + foreach ($_['navigationItems'] as $item) { |
|
9 | + $pinned = NavigationListElements($item, $l, $pinned); |
|
10 | + } |
|
11 | + ?> |
|
12 | 12 | </ul> |
13 | 13 | </div> |
14 | 14 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @return int Returns the pinned value |
26 | 26 | */ |
27 | 27 | function NavigationListElements($item, $l, $pinned) { |
28 | - strpos($item['classes'] ?? '', 'pinned') !== false ? $pinned++ : ''; ?> |
|
28 | + strpos($item['classes'] ?? '', 'pinned') !== false ? $pinned++ : ''; ?> |
|
29 | 29 | <li |
30 | 30 | data-id="<?php p($item['id']) ?>" |
31 | 31 | <?php if (isset($item['dir'])) { ?> data-dir="<?php p($item['dir']); ?>" <?php } ?> |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | <?php if (isset($item['expandedState'])) { ?> data-expandedstate="<?php p($item['expandedState']); ?>" <?php } ?> |
34 | 34 | class="nav-<?php p($item['id']) ?> |
35 | 35 | <?php if (isset($item['classes'])) { |
36 | - p($item['classes']); |
|
37 | - } ?> |
|
36 | + p($item['classes']); |
|
37 | + } ?> |
|
38 | 38 | <?php p($pinned === 1 ? 'first-pinned' : '') ?> |
39 | 39 | <?php if (isset($item['defaultExpandedState']) && $item['defaultExpandedState']) { ?> open<?php } ?>" |
40 | 40 | <?php if (isset($item['folderPosition'])) { ?> folderposition="<?php p($item['folderPosition']); ?>" <?php } ?>> |
@@ -44,26 +44,26 @@ discard block |
||
44 | 44 | |
45 | 45 | |
46 | 46 | <?php |
47 | - NavigationElementMenu($item); |
|
48 | - if (isset($item['sublist'])) { |
|
49 | - ?> |
|
47 | + NavigationElementMenu($item); |
|
48 | + if (isset($item['sublist'])) { |
|
49 | + ?> |
|
50 | 50 | <button class="collapse app-navigation-noclose" aria-expanded="<?= !empty($item['defaultExpandedState']) ? 'true' : 'false' ?>" |
51 | 51 | aria-label="<?php p($l->t('Toggle %1$s sublist', $item['name'])) ?>" |
52 | 52 | <?php if (sizeof($item['sublist']) == 0) { ?> style="display: none" <?php } ?>> |
53 | 53 | </button> |
54 | 54 | <ul id="sublist-<?php p($item['id']); ?>"> |
55 | 55 | <?php |
56 | - foreach ($item['sublist'] as $item) { |
|
57 | - $pinned = NavigationListElements($item, $l, $pinned); |
|
58 | - } ?> |
|
56 | + foreach ($item['sublist'] as $item) { |
|
57 | + $pinned = NavigationListElements($item, $l, $pinned); |
|
58 | + } ?> |
|
59 | 59 | </ul> |
60 | 60 | <?php |
61 | - } ?> |
|
61 | + } ?> |
|
62 | 62 | </li> |
63 | 63 | |
64 | 64 | |
65 | 65 | <?php |
66 | - return $pinned; |
|
66 | + return $pinned; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | * @return void |
75 | 75 | */ |
76 | 76 | function NavigationElementMenu($item) { |
77 | - if (isset($item['menubuttons']) && $item['menubuttons'] === 'true') { |
|
78 | - ?> |
|
77 | + if (isset($item['menubuttons']) && $item['menubuttons'] === 'true') { |
|
78 | + ?> |
|
79 | 79 | <div id="dotmenu-<?php p($item['id']); ?>" |
80 | 80 | class="app-navigation-entry-utils" <?php if (isset($item['enableMenuButton']) && $item['enableMenuButton'] === 0) { ?> style="display: none"<?php } ?>> |
81 | 81 | <ul> |
@@ -91,5 +91,5 @@ discard block |
||
91 | 91 | </ul> |
92 | 92 | </div> |
93 | 93 | <?php |
94 | - } |
|
94 | + } |
|
95 | 95 | } |
@@ -62,358 +62,358 @@ |
||
62 | 62 | * @package OCA\Files\Controller |
63 | 63 | */ |
64 | 64 | class ApiController extends Controller { |
65 | - private TagService $tagService; |
|
66 | - private IManager $shareManager; |
|
67 | - private IPreview $previewManager; |
|
68 | - private IUserSession $userSession; |
|
69 | - private IConfig $config; |
|
70 | - private Folder $userFolder; |
|
71 | - private UserConfig $userConfig; |
|
65 | + private TagService $tagService; |
|
66 | + private IManager $shareManager; |
|
67 | + private IPreview $previewManager; |
|
68 | + private IUserSession $userSession; |
|
69 | + private IConfig $config; |
|
70 | + private Folder $userFolder; |
|
71 | + private UserConfig $userConfig; |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param string $appName |
|
75 | - * @param IRequest $request |
|
76 | - * @param IUserSession $userSession |
|
77 | - * @param TagService $tagService |
|
78 | - * @param IPreview $previewManager |
|
79 | - * @param IManager $shareManager |
|
80 | - * @param IConfig $config |
|
81 | - * @param Folder $userFolder |
|
82 | - */ |
|
83 | - public function __construct($appName, |
|
84 | - IRequest $request, |
|
85 | - IUserSession $userSession, |
|
86 | - TagService $tagService, |
|
87 | - IPreview $previewManager, |
|
88 | - IManager $shareManager, |
|
89 | - IConfig $config, |
|
90 | - Folder $userFolder, |
|
91 | - UserConfig $userConfig) { |
|
92 | - parent::__construct($appName, $request); |
|
93 | - $this->userSession = $userSession; |
|
94 | - $this->tagService = $tagService; |
|
95 | - $this->previewManager = $previewManager; |
|
96 | - $this->shareManager = $shareManager; |
|
97 | - $this->config = $config; |
|
98 | - $this->userFolder = $userFolder; |
|
99 | - $this->userConfig = $userConfig; |
|
100 | - } |
|
73 | + /** |
|
74 | + * @param string $appName |
|
75 | + * @param IRequest $request |
|
76 | + * @param IUserSession $userSession |
|
77 | + * @param TagService $tagService |
|
78 | + * @param IPreview $previewManager |
|
79 | + * @param IManager $shareManager |
|
80 | + * @param IConfig $config |
|
81 | + * @param Folder $userFolder |
|
82 | + */ |
|
83 | + public function __construct($appName, |
|
84 | + IRequest $request, |
|
85 | + IUserSession $userSession, |
|
86 | + TagService $tagService, |
|
87 | + IPreview $previewManager, |
|
88 | + IManager $shareManager, |
|
89 | + IConfig $config, |
|
90 | + Folder $userFolder, |
|
91 | + UserConfig $userConfig) { |
|
92 | + parent::__construct($appName, $request); |
|
93 | + $this->userSession = $userSession; |
|
94 | + $this->tagService = $tagService; |
|
95 | + $this->previewManager = $previewManager; |
|
96 | + $this->shareManager = $shareManager; |
|
97 | + $this->config = $config; |
|
98 | + $this->userFolder = $userFolder; |
|
99 | + $this->userConfig = $userConfig; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Gets a thumbnail of the specified file |
|
104 | - * |
|
105 | - * @since API version 1.0 |
|
106 | - * |
|
107 | - * @NoAdminRequired |
|
108 | - * @NoCSRFRequired |
|
109 | - * @StrictCookieRequired |
|
110 | - * |
|
111 | - * @param int $x |
|
112 | - * @param int $y |
|
113 | - * @param string $file URL-encoded filename |
|
114 | - * @return DataResponse|FileDisplayResponse |
|
115 | - */ |
|
116 | - public function getThumbnail($x, $y, $file) { |
|
117 | - if ($x < 1 || $y < 1) { |
|
118 | - return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
119 | - } |
|
102 | + /** |
|
103 | + * Gets a thumbnail of the specified file |
|
104 | + * |
|
105 | + * @since API version 1.0 |
|
106 | + * |
|
107 | + * @NoAdminRequired |
|
108 | + * @NoCSRFRequired |
|
109 | + * @StrictCookieRequired |
|
110 | + * |
|
111 | + * @param int $x |
|
112 | + * @param int $y |
|
113 | + * @param string $file URL-encoded filename |
|
114 | + * @return DataResponse|FileDisplayResponse |
|
115 | + */ |
|
116 | + public function getThumbnail($x, $y, $file) { |
|
117 | + if ($x < 1 || $y < 1) { |
|
118 | + return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
119 | + } |
|
120 | 120 | |
121 | - try { |
|
122 | - $file = $this->userFolder->get($file); |
|
123 | - if ($file instanceof Folder) { |
|
124 | - throw new NotFoundException(); |
|
125 | - } |
|
121 | + try { |
|
122 | + $file = $this->userFolder->get($file); |
|
123 | + if ($file instanceof Folder) { |
|
124 | + throw new NotFoundException(); |
|
125 | + } |
|
126 | 126 | |
127 | - /** @var File $file */ |
|
128 | - $preview = $this->previewManager->getPreview($file, $x, $y, true); |
|
127 | + /** @var File $file */ |
|
128 | + $preview = $this->previewManager->getPreview($file, $x, $y, true); |
|
129 | 129 | |
130 | - return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]); |
|
131 | - } catch (NotFoundException $e) { |
|
132 | - return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
133 | - } catch (\Exception $e) { |
|
134 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
135 | - } |
|
136 | - } |
|
130 | + return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]); |
|
131 | + } catch (NotFoundException $e) { |
|
132 | + return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
133 | + } catch (\Exception $e) { |
|
134 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
135 | + } |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * Updates the info of the specified file path |
|
140 | - * The passed tags are absolute, which means they will |
|
141 | - * replace the actual tag selection. |
|
142 | - * |
|
143 | - * @NoAdminRequired |
|
144 | - * |
|
145 | - * @param string $path path |
|
146 | - * @param array|string $tags array of tags |
|
147 | - * @return DataResponse |
|
148 | - */ |
|
149 | - public function updateFileTags($path, $tags = null) { |
|
150 | - $result = []; |
|
151 | - // if tags specified or empty array, update tags |
|
152 | - if (!is_null($tags)) { |
|
153 | - try { |
|
154 | - $this->tagService->updateFileTags($path, $tags); |
|
155 | - } catch (\OCP\Files\NotFoundException $e) { |
|
156 | - return new DataResponse([ |
|
157 | - 'message' => $e->getMessage() |
|
158 | - ], Http::STATUS_NOT_FOUND); |
|
159 | - } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
160 | - return new DataResponse([ |
|
161 | - 'message' => $e->getMessage() |
|
162 | - ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
163 | - } catch (\Exception $e) { |
|
164 | - return new DataResponse([ |
|
165 | - 'message' => $e->getMessage() |
|
166 | - ], Http::STATUS_NOT_FOUND); |
|
167 | - } |
|
168 | - $result['tags'] = $tags; |
|
169 | - } |
|
170 | - return new DataResponse($result); |
|
171 | - } |
|
138 | + /** |
|
139 | + * Updates the info of the specified file path |
|
140 | + * The passed tags are absolute, which means they will |
|
141 | + * replace the actual tag selection. |
|
142 | + * |
|
143 | + * @NoAdminRequired |
|
144 | + * |
|
145 | + * @param string $path path |
|
146 | + * @param array|string $tags array of tags |
|
147 | + * @return DataResponse |
|
148 | + */ |
|
149 | + public function updateFileTags($path, $tags = null) { |
|
150 | + $result = []; |
|
151 | + // if tags specified or empty array, update tags |
|
152 | + if (!is_null($tags)) { |
|
153 | + try { |
|
154 | + $this->tagService->updateFileTags($path, $tags); |
|
155 | + } catch (\OCP\Files\NotFoundException $e) { |
|
156 | + return new DataResponse([ |
|
157 | + 'message' => $e->getMessage() |
|
158 | + ], Http::STATUS_NOT_FOUND); |
|
159 | + } catch (\OCP\Files\StorageNotAvailableException $e) { |
|
160 | + return new DataResponse([ |
|
161 | + 'message' => $e->getMessage() |
|
162 | + ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
163 | + } catch (\Exception $e) { |
|
164 | + return new DataResponse([ |
|
165 | + 'message' => $e->getMessage() |
|
166 | + ], Http::STATUS_NOT_FOUND); |
|
167 | + } |
|
168 | + $result['tags'] = $tags; |
|
169 | + } |
|
170 | + return new DataResponse($result); |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * @param \OCP\Files\Node[] $nodes |
|
175 | - * @return array |
|
176 | - */ |
|
177 | - private function formatNodes(array $nodes) { |
|
178 | - $shareTypesForNodes = $this->getShareTypesForNodes($nodes); |
|
179 | - return array_values(array_map(function (Node $node) use ($shareTypesForNodes) { |
|
180 | - $shareTypes = $shareTypesForNodes[$node->getId()] ?? []; |
|
181 | - $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); |
|
182 | - $file['hasPreview'] = $this->previewManager->isAvailable($node); |
|
183 | - $parts = explode('/', dirname($node->getPath()), 4); |
|
184 | - if (isset($parts[3])) { |
|
185 | - $file['path'] = '/' . $parts[3]; |
|
186 | - } else { |
|
187 | - $file['path'] = '/'; |
|
188 | - } |
|
189 | - if (!empty($shareTypes)) { |
|
190 | - $file['shareTypes'] = $shareTypes; |
|
191 | - } |
|
192 | - return $file; |
|
193 | - }, $nodes)); |
|
194 | - } |
|
173 | + /** |
|
174 | + * @param \OCP\Files\Node[] $nodes |
|
175 | + * @return array |
|
176 | + */ |
|
177 | + private function formatNodes(array $nodes) { |
|
178 | + $shareTypesForNodes = $this->getShareTypesForNodes($nodes); |
|
179 | + return array_values(array_map(function (Node $node) use ($shareTypesForNodes) { |
|
180 | + $shareTypes = $shareTypesForNodes[$node->getId()] ?? []; |
|
181 | + $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); |
|
182 | + $file['hasPreview'] = $this->previewManager->isAvailable($node); |
|
183 | + $parts = explode('/', dirname($node->getPath()), 4); |
|
184 | + if (isset($parts[3])) { |
|
185 | + $file['path'] = '/' . $parts[3]; |
|
186 | + } else { |
|
187 | + $file['path'] = '/'; |
|
188 | + } |
|
189 | + if (!empty($shareTypes)) { |
|
190 | + $file['shareTypes'] = $shareTypes; |
|
191 | + } |
|
192 | + return $file; |
|
193 | + }, $nodes)); |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Get the share types for each node |
|
198 | - * |
|
199 | - * @param \OCP\Files\Node[] $nodes |
|
200 | - * @return array<int, int[]> list of share types for each fileid |
|
201 | - */ |
|
202 | - private function getShareTypesForNodes(array $nodes): array { |
|
203 | - $userId = $this->userSession->getUser()->getUID(); |
|
204 | - $requestedShareTypes = [ |
|
205 | - IShare::TYPE_USER, |
|
206 | - IShare::TYPE_GROUP, |
|
207 | - IShare::TYPE_LINK, |
|
208 | - IShare::TYPE_REMOTE, |
|
209 | - IShare::TYPE_EMAIL, |
|
210 | - IShare::TYPE_ROOM, |
|
211 | - IShare::TYPE_DECK, |
|
212 | - ]; |
|
213 | - $shareTypes = []; |
|
196 | + /** |
|
197 | + * Get the share types for each node |
|
198 | + * |
|
199 | + * @param \OCP\Files\Node[] $nodes |
|
200 | + * @return array<int, int[]> list of share types for each fileid |
|
201 | + */ |
|
202 | + private function getShareTypesForNodes(array $nodes): array { |
|
203 | + $userId = $this->userSession->getUser()->getUID(); |
|
204 | + $requestedShareTypes = [ |
|
205 | + IShare::TYPE_USER, |
|
206 | + IShare::TYPE_GROUP, |
|
207 | + IShare::TYPE_LINK, |
|
208 | + IShare::TYPE_REMOTE, |
|
209 | + IShare::TYPE_EMAIL, |
|
210 | + IShare::TYPE_ROOM, |
|
211 | + IShare::TYPE_DECK, |
|
212 | + ]; |
|
213 | + $shareTypes = []; |
|
214 | 214 | |
215 | - $nodeIds = array_map(function (Node $node) { |
|
216 | - return $node->getId(); |
|
217 | - }, $nodes); |
|
215 | + $nodeIds = array_map(function (Node $node) { |
|
216 | + return $node->getId(); |
|
217 | + }, $nodes); |
|
218 | 218 | |
219 | - foreach ($requestedShareTypes as $shareType) { |
|
220 | - $nodesLeft = array_combine($nodeIds, array_fill(0, count($nodeIds), true)); |
|
221 | - $offset = 0; |
|
219 | + foreach ($requestedShareTypes as $shareType) { |
|
220 | + $nodesLeft = array_combine($nodeIds, array_fill(0, count($nodeIds), true)); |
|
221 | + $offset = 0; |
|
222 | 222 | |
223 | - // fetch shares until we've either found shares for all nodes or there are no more shares left |
|
224 | - while (count($nodesLeft) > 0) { |
|
225 | - $shares = $this->shareManager->getSharesBy($userId, $shareType, null, false, 100, $offset); |
|
226 | - foreach ($shares as $share) { |
|
227 | - $fileId = $share->getNodeId(); |
|
228 | - if (isset($nodesLeft[$fileId])) { |
|
229 | - if (!isset($shareTypes[$fileId])) { |
|
230 | - $shareTypes[$fileId] = []; |
|
231 | - } |
|
232 | - $shareTypes[$fileId][] = $shareType; |
|
233 | - unset($nodesLeft[$fileId]); |
|
234 | - } |
|
235 | - } |
|
223 | + // fetch shares until we've either found shares for all nodes or there are no more shares left |
|
224 | + while (count($nodesLeft) > 0) { |
|
225 | + $shares = $this->shareManager->getSharesBy($userId, $shareType, null, false, 100, $offset); |
|
226 | + foreach ($shares as $share) { |
|
227 | + $fileId = $share->getNodeId(); |
|
228 | + if (isset($nodesLeft[$fileId])) { |
|
229 | + if (!isset($shareTypes[$fileId])) { |
|
230 | + $shareTypes[$fileId] = []; |
|
231 | + } |
|
232 | + $shareTypes[$fileId][] = $shareType; |
|
233 | + unset($nodesLeft[$fileId]); |
|
234 | + } |
|
235 | + } |
|
236 | 236 | |
237 | - if (count($shares) < 100) { |
|
238 | - break; |
|
239 | - } else { |
|
240 | - $offset += count($shares); |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - return $shareTypes; |
|
245 | - } |
|
237 | + if (count($shares) < 100) { |
|
238 | + break; |
|
239 | + } else { |
|
240 | + $offset += count($shares); |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | + return $shareTypes; |
|
245 | + } |
|
246 | 246 | |
247 | - /** |
|
248 | - * Returns a list of recently modified files. |
|
249 | - * |
|
250 | - * @NoAdminRequired |
|
251 | - * |
|
252 | - * @return DataResponse |
|
253 | - */ |
|
254 | - public function getRecentFiles() { |
|
255 | - $nodes = $this->userFolder->getRecent(100); |
|
256 | - $files = $this->formatNodes($nodes); |
|
257 | - return new DataResponse(['files' => $files]); |
|
258 | - } |
|
247 | + /** |
|
248 | + * Returns a list of recently modified files. |
|
249 | + * |
|
250 | + * @NoAdminRequired |
|
251 | + * |
|
252 | + * @return DataResponse |
|
253 | + */ |
|
254 | + public function getRecentFiles() { |
|
255 | + $nodes = $this->userFolder->getRecent(100); |
|
256 | + $files = $this->formatNodes($nodes); |
|
257 | + return new DataResponse(['files' => $files]); |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | - /** |
|
262 | - * Returns the current logged-in user's storage stats. |
|
263 | - * |
|
264 | - * @NoAdminRequired |
|
265 | - * |
|
266 | - * @param ?string $dir the directory to get the storage stats from |
|
267 | - * @return JSONResponse |
|
268 | - */ |
|
269 | - public function getStorageStats($dir = '/'): JSONResponse { |
|
270 | - $storageInfo = \OC_Helper::getStorageInfo($dir ?: '/'); |
|
271 | - return new JSONResponse(['message' => 'ok', 'data' => $storageInfo]); |
|
272 | - } |
|
261 | + /** |
|
262 | + * Returns the current logged-in user's storage stats. |
|
263 | + * |
|
264 | + * @NoAdminRequired |
|
265 | + * |
|
266 | + * @param ?string $dir the directory to get the storage stats from |
|
267 | + * @return JSONResponse |
|
268 | + */ |
|
269 | + public function getStorageStats($dir = '/'): JSONResponse { |
|
270 | + $storageInfo = \OC_Helper::getStorageInfo($dir ?: '/'); |
|
271 | + return new JSONResponse(['message' => 'ok', 'data' => $storageInfo]); |
|
272 | + } |
|
273 | 273 | |
274 | - /** |
|
275 | - * Change the default sort mode |
|
276 | - * |
|
277 | - * @NoAdminRequired |
|
278 | - * |
|
279 | - * @param string $mode |
|
280 | - * @param string $direction |
|
281 | - * @return Response |
|
282 | - * @throws \OCP\PreConditionNotMetException |
|
283 | - */ |
|
284 | - public function updateFileSorting($mode, $direction) { |
|
285 | - $allowedMode = ['name', 'size', 'mtime']; |
|
286 | - $allowedDirection = ['asc', 'desc']; |
|
287 | - if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) { |
|
288 | - $response = new Response(); |
|
289 | - $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); |
|
290 | - return $response; |
|
291 | - } |
|
292 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode); |
|
293 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction); |
|
294 | - return new Response(); |
|
295 | - } |
|
274 | + /** |
|
275 | + * Change the default sort mode |
|
276 | + * |
|
277 | + * @NoAdminRequired |
|
278 | + * |
|
279 | + * @param string $mode |
|
280 | + * @param string $direction |
|
281 | + * @return Response |
|
282 | + * @throws \OCP\PreConditionNotMetException |
|
283 | + */ |
|
284 | + public function updateFileSorting($mode, $direction) { |
|
285 | + $allowedMode = ['name', 'size', 'mtime']; |
|
286 | + $allowedDirection = ['asc', 'desc']; |
|
287 | + if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) { |
|
288 | + $response = new Response(); |
|
289 | + $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); |
|
290 | + return $response; |
|
291 | + } |
|
292 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode); |
|
293 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction); |
|
294 | + return new Response(); |
|
295 | + } |
|
296 | 296 | |
297 | - /** |
|
298 | - * Toggle default files user config |
|
299 | - * |
|
300 | - * @NoAdminRequired |
|
301 | - * |
|
302 | - * @param string $key |
|
303 | - * @param string|bool $value |
|
304 | - * @return JSONResponse |
|
305 | - */ |
|
306 | - public function setConfig(string $key, $value): JSONResponse { |
|
307 | - try { |
|
308 | - $this->userConfig->setConfig($key, (string)$value); |
|
309 | - } catch (\InvalidArgumentException $e) { |
|
310 | - return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
311 | - } |
|
297 | + /** |
|
298 | + * Toggle default files user config |
|
299 | + * |
|
300 | + * @NoAdminRequired |
|
301 | + * |
|
302 | + * @param string $key |
|
303 | + * @param string|bool $value |
|
304 | + * @return JSONResponse |
|
305 | + */ |
|
306 | + public function setConfig(string $key, $value): JSONResponse { |
|
307 | + try { |
|
308 | + $this->userConfig->setConfig($key, (string)$value); |
|
309 | + } catch (\InvalidArgumentException $e) { |
|
310 | + return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
311 | + } |
|
312 | 312 | |
313 | - return new JSONResponse(['message' => 'ok', 'data' => ['key' => $key, 'value' => $value]]); |
|
314 | - } |
|
313 | + return new JSONResponse(['message' => 'ok', 'data' => ['key' => $key, 'value' => $value]]); |
|
314 | + } |
|
315 | 315 | |
316 | 316 | |
317 | - /** |
|
318 | - * Get the user config |
|
319 | - * |
|
320 | - * @NoAdminRequired |
|
321 | - * |
|
322 | - * @return JSONResponse |
|
323 | - */ |
|
324 | - public function getConfigs(): JSONResponse { |
|
325 | - return new JSONResponse(['message' => 'ok', 'data' => $this->userConfig->getConfigs()]); |
|
326 | - } |
|
317 | + /** |
|
318 | + * Get the user config |
|
319 | + * |
|
320 | + * @NoAdminRequired |
|
321 | + * |
|
322 | + * @return JSONResponse |
|
323 | + */ |
|
324 | + public function getConfigs(): JSONResponse { |
|
325 | + return new JSONResponse(['message' => 'ok', 'data' => $this->userConfig->getConfigs()]); |
|
326 | + } |
|
327 | 327 | |
328 | - /** |
|
329 | - * Toggle default for showing/hiding hidden files |
|
330 | - * |
|
331 | - * @NoAdminRequired |
|
332 | - * |
|
333 | - * @param bool $value |
|
334 | - * @return Response |
|
335 | - * @throws \OCP\PreConditionNotMetException |
|
336 | - */ |
|
337 | - public function showHiddenFiles(bool $value): Response { |
|
338 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', $value ? '1' : '0'); |
|
339 | - return new Response(); |
|
340 | - } |
|
328 | + /** |
|
329 | + * Toggle default for showing/hiding hidden files |
|
330 | + * |
|
331 | + * @NoAdminRequired |
|
332 | + * |
|
333 | + * @param bool $value |
|
334 | + * @return Response |
|
335 | + * @throws \OCP\PreConditionNotMetException |
|
336 | + */ |
|
337 | + public function showHiddenFiles(bool $value): Response { |
|
338 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', $value ? '1' : '0'); |
|
339 | + return new Response(); |
|
340 | + } |
|
341 | 341 | |
342 | - /** |
|
343 | - * Toggle default for cropping preview images |
|
344 | - * |
|
345 | - * @NoAdminRequired |
|
346 | - * |
|
347 | - * @param bool $value |
|
348 | - * @return Response |
|
349 | - * @throws \OCP\PreConditionNotMetException |
|
350 | - */ |
|
351 | - public function cropImagePreviews(bool $value): Response { |
|
352 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', $value ? '1' : '0'); |
|
353 | - return new Response(); |
|
354 | - } |
|
342 | + /** |
|
343 | + * Toggle default for cropping preview images |
|
344 | + * |
|
345 | + * @NoAdminRequired |
|
346 | + * |
|
347 | + * @param bool $value |
|
348 | + * @return Response |
|
349 | + * @throws \OCP\PreConditionNotMetException |
|
350 | + */ |
|
351 | + public function cropImagePreviews(bool $value): Response { |
|
352 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', $value ? '1' : '0'); |
|
353 | + return new Response(); |
|
354 | + } |
|
355 | 355 | |
356 | - /** |
|
357 | - * Toggle default for files grid view |
|
358 | - * |
|
359 | - * @NoAdminRequired |
|
360 | - * |
|
361 | - * @param bool $show |
|
362 | - * @return Response |
|
363 | - * @throws \OCP\PreConditionNotMetException |
|
364 | - */ |
|
365 | - public function showGridView(bool $show): Response { |
|
366 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', $show ? '1' : '0'); |
|
367 | - return new Response(); |
|
368 | - } |
|
356 | + /** |
|
357 | + * Toggle default for files grid view |
|
358 | + * |
|
359 | + * @NoAdminRequired |
|
360 | + * |
|
361 | + * @param bool $show |
|
362 | + * @return Response |
|
363 | + * @throws \OCP\PreConditionNotMetException |
|
364 | + */ |
|
365 | + public function showGridView(bool $show): Response { |
|
366 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', $show ? '1' : '0'); |
|
367 | + return new Response(); |
|
368 | + } |
|
369 | 369 | |
370 | - /** |
|
371 | - * Get default settings for the grid view |
|
372 | - * |
|
373 | - * @NoAdminRequired |
|
374 | - */ |
|
375 | - public function getGridView() { |
|
376 | - $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1'; |
|
377 | - return new JSONResponse(['gridview' => $status]); |
|
378 | - } |
|
370 | + /** |
|
371 | + * Get default settings for the grid view |
|
372 | + * |
|
373 | + * @NoAdminRequired |
|
374 | + */ |
|
375 | + public function getGridView() { |
|
376 | + $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1'; |
|
377 | + return new JSONResponse(['gridview' => $status]); |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * Toggle default for showing/hiding xxx folder |
|
382 | - * |
|
383 | - * @NoAdminRequired |
|
384 | - * |
|
385 | - * @param int $show |
|
386 | - * @param string $key the key of the folder |
|
387 | - * |
|
388 | - * @return Response |
|
389 | - * @throws \OCP\PreConditionNotMetException |
|
390 | - */ |
|
391 | - public function toggleShowFolder(int $show, string $key): Response { |
|
392 | - if ($show !== 0 && $show !== 1) { |
|
393 | - return new DataResponse([ |
|
394 | - 'message' => 'Invalid show value. Only 0 and 1 are allowed.' |
|
395 | - ], Http::STATUS_BAD_REQUEST); |
|
396 | - } |
|
380 | + /** |
|
381 | + * Toggle default for showing/hiding xxx folder |
|
382 | + * |
|
383 | + * @NoAdminRequired |
|
384 | + * |
|
385 | + * @param int $show |
|
386 | + * @param string $key the key of the folder |
|
387 | + * |
|
388 | + * @return Response |
|
389 | + * @throws \OCP\PreConditionNotMetException |
|
390 | + */ |
|
391 | + public function toggleShowFolder(int $show, string $key): Response { |
|
392 | + if ($show !== 0 && $show !== 1) { |
|
393 | + return new DataResponse([ |
|
394 | + 'message' => 'Invalid show value. Only 0 and 1 are allowed.' |
|
395 | + ], Http::STATUS_BAD_REQUEST); |
|
396 | + } |
|
397 | 397 | |
398 | - $userId = $this->userSession->getUser()->getUID(); |
|
398 | + $userId = $this->userSession->getUser()->getUID(); |
|
399 | 399 | |
400 | - // Set the new value and return it |
|
401 | - // Using a prefix prevents the user from setting arbitrary keys |
|
402 | - $this->config->setUserValue($userId, 'files', 'show_' . $key, (string)$show); |
|
403 | - return new JSONResponse([$key => $show]); |
|
404 | - } |
|
400 | + // Set the new value and return it |
|
401 | + // Using a prefix prevents the user from setting arbitrary keys |
|
402 | + $this->config->setUserValue($userId, 'files', 'show_' . $key, (string)$show); |
|
403 | + return new JSONResponse([$key => $show]); |
|
404 | + } |
|
405 | 405 | |
406 | - /** |
|
407 | - * Get sorting-order for custom sorting |
|
408 | - * |
|
409 | - * @NoAdminRequired |
|
410 | - * |
|
411 | - * @param string $folderpath |
|
412 | - * @return string |
|
413 | - * @throws \OCP\Files\NotFoundException |
|
414 | - */ |
|
415 | - public function getNodeType($folderpath) { |
|
416 | - $node = $this->userFolder->get($folderpath); |
|
417 | - return $node->getType(); |
|
418 | - } |
|
406 | + /** |
|
407 | + * Get sorting-order for custom sorting |
|
408 | + * |
|
409 | + * @NoAdminRequired |
|
410 | + * |
|
411 | + * @param string $folderpath |
|
412 | + * @return string |
|
413 | + * @throws \OCP\Files\NotFoundException |
|
414 | + */ |
|
415 | + public function getNodeType($folderpath) { |
|
416 | + $node = $this->userFolder->get($folderpath); |
|
417 | + return $node->getType(); |
|
418 | + } |
|
419 | 419 | } |
@@ -67,351 +67,351 @@ |
||
67 | 67 | * @package OCA\Files\Controller |
68 | 68 | */ |
69 | 69 | class ViewController extends Controller { |
70 | - private IURLGenerator $urlGenerator; |
|
71 | - private IL10N $l10n; |
|
72 | - private IConfig $config; |
|
73 | - private IEventDispatcher $eventDispatcher; |
|
74 | - private IUserSession $userSession; |
|
75 | - private IAppManager $appManager; |
|
76 | - private IRootFolder $rootFolder; |
|
77 | - private Helper $activityHelper; |
|
78 | - private IInitialState $initialState; |
|
79 | - private ITemplateManager $templateManager; |
|
80 | - private IManager $shareManager; |
|
81 | - private UserConfig $userConfig; |
|
82 | - |
|
83 | - public function __construct(string $appName, |
|
84 | - IRequest $request, |
|
85 | - IURLGenerator $urlGenerator, |
|
86 | - IL10N $l10n, |
|
87 | - IConfig $config, |
|
88 | - IEventDispatcher $eventDispatcher, |
|
89 | - IUserSession $userSession, |
|
90 | - IAppManager $appManager, |
|
91 | - IRootFolder $rootFolder, |
|
92 | - Helper $activityHelper, |
|
93 | - IInitialState $initialState, |
|
94 | - ITemplateManager $templateManager, |
|
95 | - IManager $shareManager, |
|
96 | - UserConfig $userConfig |
|
97 | - ) { |
|
98 | - parent::__construct($appName, $request); |
|
99 | - $this->urlGenerator = $urlGenerator; |
|
100 | - $this->l10n = $l10n; |
|
101 | - $this->config = $config; |
|
102 | - $this->eventDispatcher = $eventDispatcher; |
|
103 | - $this->userSession = $userSession; |
|
104 | - $this->appManager = $appManager; |
|
105 | - $this->rootFolder = $rootFolder; |
|
106 | - $this->activityHelper = $activityHelper; |
|
107 | - $this->initialState = $initialState; |
|
108 | - $this->templateManager = $templateManager; |
|
109 | - $this->shareManager = $shareManager; |
|
110 | - $this->userConfig = $userConfig; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @param string $appName |
|
115 | - * @param string $scriptName |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - protected function renderScript($appName, $scriptName) { |
|
119 | - $content = ''; |
|
120 | - $appPath = \OC_App::getAppPath($appName); |
|
121 | - $scriptPath = $appPath . '/' . $scriptName; |
|
122 | - if (file_exists($scriptPath)) { |
|
123 | - // TODO: sanitize path / script name ? |
|
124 | - ob_start(); |
|
125 | - include $scriptPath; |
|
126 | - $content = ob_get_contents(); |
|
127 | - @ob_end_clean(); |
|
128 | - } |
|
129 | - |
|
130 | - return $content; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * FIXME: Replace with non static code |
|
135 | - * |
|
136 | - * @return array |
|
137 | - * @throws \OCP\Files\NotFoundException |
|
138 | - */ |
|
139 | - protected function getStorageInfo(string $dir = '/') { |
|
140 | - \OC_Util::setupFS(); |
|
141 | - $rootInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
142 | - |
|
143 | - return \OC_Helper::getStorageInfo($dir, $rootInfo ?: null); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @NoCSRFRequired |
|
148 | - * @NoAdminRequired |
|
149 | - * |
|
150 | - * @param string $fileid |
|
151 | - * @return TemplateResponse|RedirectResponse |
|
152 | - * @throws NotFoundException |
|
153 | - */ |
|
154 | - public function showFile(string $fileid = null, int $openfile = 1): Response { |
|
155 | - // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server. |
|
156 | - try { |
|
157 | - return $this->redirectToFile($fileid, $openfile !== 0); |
|
158 | - } catch (NotFoundException $e) { |
|
159 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @NoCSRFRequired |
|
165 | - * @NoAdminRequired |
|
166 | - * @UseSession |
|
167 | - * |
|
168 | - * @param string $dir |
|
169 | - * @param string $view |
|
170 | - * @param string $fileid |
|
171 | - * @param bool $fileNotFound |
|
172 | - * @param string $openfile - the openfile URL parameter if it was present in the initial request |
|
173 | - * @return TemplateResponse|RedirectResponse |
|
174 | - * @throws NotFoundException |
|
175 | - */ |
|
176 | - public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false, $openfile = null) { |
|
177 | - |
|
178 | - if ($fileid !== null && $dir === '') { |
|
179 | - try { |
|
180 | - return $this->redirectToFile($fileid); |
|
181 | - } catch (NotFoundException $e) { |
|
182 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
187 | - |
|
188 | - // Load the files we need |
|
189 | - \OCP\Util::addStyle('files', 'merged'); |
|
190 | - \OCP\Util::addScript('files', 'merged-index', 'files'); |
|
191 | - \OCP\Util::addScript('files', 'main'); |
|
192 | - |
|
193 | - // mostly for the home storage's free space |
|
194 | - // FIXME: Make non static |
|
195 | - $storageInfo = $this->getStorageInfo(); |
|
196 | - |
|
197 | - $userId = $this->userSession->getUser()->getUID(); |
|
198 | - |
|
199 | - // Get all the user favorites to create a submenu |
|
200 | - try { |
|
201 | - $favElements = $this->activityHelper->getFavoriteFilePaths($userId); |
|
202 | - } catch (\RuntimeException $e) { |
|
203 | - $favElements['folders'] = []; |
|
204 | - } |
|
205 | - |
|
206 | - $collapseClasses = ''; |
|
207 | - if (count($favElements['folders']) > 0) { |
|
208 | - $collapseClasses = 'collapsible'; |
|
209 | - } |
|
210 | - |
|
211 | - $favoritesSublistArray = []; |
|
212 | - |
|
213 | - $navBarPositionPosition = 6; |
|
214 | - foreach ($favElements['folders'] as $favElement) { |
|
215 | - $element = [ |
|
216 | - 'id' => str_replace('/', '-', $favElement), |
|
217 | - 'dir' => $favElement, |
|
218 | - 'order' => $navBarPositionPosition, |
|
219 | - 'name' => basename($favElement), |
|
220 | - 'icon' => 'folder', |
|
221 | - 'params' => [ |
|
222 | - 'view' => 'files', |
|
223 | - 'dir' => $favElement, |
|
224 | - ], |
|
225 | - ]; |
|
226 | - |
|
227 | - array_push($favoritesSublistArray, $element); |
|
228 | - $navBarPositionPosition++; |
|
229 | - } |
|
230 | - |
|
231 | - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
232 | - |
|
233 | - // add the favorites entry in menu |
|
234 | - $navItems['favorites']['sublist'] = $favoritesSublistArray; |
|
235 | - $navItems['favorites']['classes'] = $collapseClasses; |
|
236 | - |
|
237 | - // parse every menu and add the expanded user value |
|
238 | - foreach ($navItems as $key => $item) { |
|
239 | - $navItems[$key]['expanded'] = $this->config->getUserValue($userId, 'files', 'show_' . $item['id'], '0') === '1'; |
|
240 | - } |
|
241 | - |
|
242 | - $nav->assign('navigationItems', $navItems); |
|
243 | - |
|
244 | - $contentItems = []; |
|
245 | - |
|
246 | - try { |
|
247 | - // If view is files, we use the directory, otherwise we use the root storage |
|
248 | - $storageInfo = $this->getStorageInfo(($view === 'files' && $dir) ? $dir : '/'); |
|
249 | - } catch(\Exception $e) { |
|
250 | - $storageInfo = $this->getStorageInfo(); |
|
251 | - } |
|
252 | - |
|
253 | - $this->initialState->provideInitialState('storageStats', $storageInfo); |
|
254 | - $this->initialState->provideInitialState('navigation', $navItems); |
|
255 | - $this->initialState->provideInitialState('config', $this->userConfig->getConfigs()); |
|
256 | - |
|
257 | - // render the container content for every navigation item |
|
258 | - foreach ($navItems as $item) { |
|
259 | - $content = ''; |
|
260 | - if (isset($item['script'])) { |
|
261 | - $content = $this->renderScript($item['appname'], $item['script']); |
|
262 | - } |
|
263 | - // parse submenus |
|
264 | - if (isset($item['sublist'])) { |
|
265 | - foreach ($item['sublist'] as $subitem) { |
|
266 | - $subcontent = ''; |
|
267 | - if (isset($subitem['script'])) { |
|
268 | - $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); |
|
269 | - } |
|
270 | - $contentItems[$subitem['id']] = [ |
|
271 | - 'id' => $subitem['id'], |
|
272 | - 'content' => $subcontent |
|
273 | - ]; |
|
274 | - } |
|
275 | - } |
|
276 | - $contentItems[$item['id']] = [ |
|
277 | - 'id' => $item['id'], |
|
278 | - 'content' => $content |
|
279 | - ]; |
|
280 | - } |
|
281 | - |
|
282 | - $this->eventDispatcher->dispatchTyped(new ResourcesLoadAdditionalScriptsEvent()); |
|
283 | - $event = new LoadAdditionalScriptsEvent(); |
|
284 | - $this->eventDispatcher->dispatchTyped($event); |
|
285 | - $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
|
286 | - // Load Viewer scripts |
|
287 | - if (class_exists(LoadViewer::class)) { |
|
288 | - $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
|
289 | - } |
|
290 | - |
|
291 | - $this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false); |
|
292 | - $this->initialState->provideInitialState('templates', $this->templateManager->listCreators()); |
|
293 | - |
|
294 | - $params = []; |
|
295 | - $params['usedSpacePercent'] = (int) $storageInfo['relative']; |
|
296 | - $params['owner'] = $storageInfo['owner'] ?? ''; |
|
297 | - $params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? ''; |
|
298 | - $params['isPublic'] = false; |
|
299 | - $params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no'; |
|
300 | - $params['defaultFileSorting'] = $this->config->getUserValue($userId, 'files', 'file_sorting', 'name'); |
|
301 | - $params['defaultFileSortingDirection'] = $this->config->getUserValue($userId, 'files', 'file_sorting_direction', 'asc'); |
|
302 | - $params['showgridview'] = $this->config->getUserValue($userId, 'files', 'show_grid', false); |
|
303 | - $showHidden = (bool) $this->config->getUserValue($userId, 'files', 'show_hidden', false); |
|
304 | - $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
305 | - $cropImagePreviews = (bool) $this->config->getUserValue($userId, 'files', 'crop_image_previews', true); |
|
306 | - $params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0; |
|
307 | - $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
308 | - $params['appNavigation'] = $nav; |
|
309 | - $params['appContents'] = $contentItems; |
|
310 | - $params['hiddenFields'] = $event->getHiddenFields(); |
|
311 | - |
|
312 | - $response = new TemplateResponse( |
|
313 | - Application::APP_ID, |
|
314 | - 'index', |
|
315 | - $params |
|
316 | - ); |
|
317 | - $policy = new ContentSecurityPolicy(); |
|
318 | - $policy->addAllowedFrameDomain('\'self\''); |
|
319 | - $response->setContentSecurityPolicy($policy); |
|
320 | - |
|
321 | - $this->provideInitialState($dir, $openfile); |
|
322 | - |
|
323 | - return $response; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Add openFileInfo in initialState if $openfile is set. |
|
328 | - * @param string $dir - the ?dir= URL param |
|
329 | - * @param string $openfile - the ?openfile= URL param |
|
330 | - * @return void |
|
331 | - */ |
|
332 | - private function provideInitialState(string $dir, ?string $openfile): void { |
|
333 | - if ($openfile === null) { |
|
334 | - return; |
|
335 | - } |
|
336 | - |
|
337 | - $user = $this->userSession->getUser(); |
|
338 | - |
|
339 | - if ($user === null) { |
|
340 | - return; |
|
341 | - } |
|
342 | - |
|
343 | - $uid = $user->getUID(); |
|
344 | - $userFolder = $this->rootFolder->getUserFolder($uid); |
|
345 | - $nodes = $userFolder->getById((int) $openfile); |
|
346 | - $node = array_shift($nodes); |
|
347 | - |
|
348 | - if ($node === null) { |
|
349 | - return; |
|
350 | - } |
|
351 | - |
|
352 | - // properly format full path and make sure |
|
353 | - // we're relative to the user home folder |
|
354 | - $isRoot = $node === $userFolder; |
|
355 | - $path = $userFolder->getRelativePath($node->getPath()); |
|
356 | - $directory = $userFolder->getRelativePath($node->getParent()->getPath()); |
|
357 | - |
|
358 | - // Prevent opening a file from another folder. |
|
359 | - if ($dir !== $directory) { |
|
360 | - return; |
|
361 | - } |
|
362 | - |
|
363 | - $this->initialState->provideInitialState( |
|
364 | - 'openFileInfo', [ |
|
365 | - 'id' => $node->getId(), |
|
366 | - 'name' => $isRoot ? '' : $node->getName(), |
|
367 | - 'path' => $path, |
|
368 | - 'directory' => $directory, |
|
369 | - 'mime' => $node->getMimetype(), |
|
370 | - 'type' => $node->getType(), |
|
371 | - 'permissions' => $node->getPermissions(), |
|
372 | - ] |
|
373 | - ); |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Redirects to the file list and highlight the given file id |
|
378 | - * |
|
379 | - * @param string $fileId file id to show |
|
380 | - * @param bool $setOpenfile - whether or not to set the openfile URL parameter |
|
381 | - * @return RedirectResponse redirect response or not found response |
|
382 | - * @throws \OCP\Files\NotFoundException |
|
383 | - */ |
|
384 | - private function redirectToFile($fileId, bool $setOpenfile = false) { |
|
385 | - $uid = $this->userSession->getUser()->getUID(); |
|
386 | - $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
387 | - $files = $baseFolder->getById($fileId); |
|
388 | - $params = []; |
|
389 | - |
|
390 | - if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
391 | - $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
392 | - $files = $baseFolder->getById($fileId); |
|
393 | - $params['view'] = 'trashbin'; |
|
394 | - } |
|
395 | - |
|
396 | - if (!empty($files)) { |
|
397 | - $file = current($files); |
|
398 | - if ($file instanceof Folder) { |
|
399 | - // set the full path to enter the folder |
|
400 | - $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
401 | - } else { |
|
402 | - // set parent path as dir |
|
403 | - $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
404 | - // and scroll to the entry |
|
405 | - $params['scrollto'] = $file->getName(); |
|
406 | - |
|
407 | - if ($setOpenfile) { |
|
408 | - // forward the openfile URL parameter. |
|
409 | - $params['openfile'] = $fileId; |
|
410 | - } |
|
411 | - } |
|
412 | - |
|
413 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
414 | - } |
|
415 | - throw new \OCP\Files\NotFoundException(); |
|
416 | - } |
|
70 | + private IURLGenerator $urlGenerator; |
|
71 | + private IL10N $l10n; |
|
72 | + private IConfig $config; |
|
73 | + private IEventDispatcher $eventDispatcher; |
|
74 | + private IUserSession $userSession; |
|
75 | + private IAppManager $appManager; |
|
76 | + private IRootFolder $rootFolder; |
|
77 | + private Helper $activityHelper; |
|
78 | + private IInitialState $initialState; |
|
79 | + private ITemplateManager $templateManager; |
|
80 | + private IManager $shareManager; |
|
81 | + private UserConfig $userConfig; |
|
82 | + |
|
83 | + public function __construct(string $appName, |
|
84 | + IRequest $request, |
|
85 | + IURLGenerator $urlGenerator, |
|
86 | + IL10N $l10n, |
|
87 | + IConfig $config, |
|
88 | + IEventDispatcher $eventDispatcher, |
|
89 | + IUserSession $userSession, |
|
90 | + IAppManager $appManager, |
|
91 | + IRootFolder $rootFolder, |
|
92 | + Helper $activityHelper, |
|
93 | + IInitialState $initialState, |
|
94 | + ITemplateManager $templateManager, |
|
95 | + IManager $shareManager, |
|
96 | + UserConfig $userConfig |
|
97 | + ) { |
|
98 | + parent::__construct($appName, $request); |
|
99 | + $this->urlGenerator = $urlGenerator; |
|
100 | + $this->l10n = $l10n; |
|
101 | + $this->config = $config; |
|
102 | + $this->eventDispatcher = $eventDispatcher; |
|
103 | + $this->userSession = $userSession; |
|
104 | + $this->appManager = $appManager; |
|
105 | + $this->rootFolder = $rootFolder; |
|
106 | + $this->activityHelper = $activityHelper; |
|
107 | + $this->initialState = $initialState; |
|
108 | + $this->templateManager = $templateManager; |
|
109 | + $this->shareManager = $shareManager; |
|
110 | + $this->userConfig = $userConfig; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @param string $appName |
|
115 | + * @param string $scriptName |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + protected function renderScript($appName, $scriptName) { |
|
119 | + $content = ''; |
|
120 | + $appPath = \OC_App::getAppPath($appName); |
|
121 | + $scriptPath = $appPath . '/' . $scriptName; |
|
122 | + if (file_exists($scriptPath)) { |
|
123 | + // TODO: sanitize path / script name ? |
|
124 | + ob_start(); |
|
125 | + include $scriptPath; |
|
126 | + $content = ob_get_contents(); |
|
127 | + @ob_end_clean(); |
|
128 | + } |
|
129 | + |
|
130 | + return $content; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * FIXME: Replace with non static code |
|
135 | + * |
|
136 | + * @return array |
|
137 | + * @throws \OCP\Files\NotFoundException |
|
138 | + */ |
|
139 | + protected function getStorageInfo(string $dir = '/') { |
|
140 | + \OC_Util::setupFS(); |
|
141 | + $rootInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
142 | + |
|
143 | + return \OC_Helper::getStorageInfo($dir, $rootInfo ?: null); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @NoCSRFRequired |
|
148 | + * @NoAdminRequired |
|
149 | + * |
|
150 | + * @param string $fileid |
|
151 | + * @return TemplateResponse|RedirectResponse |
|
152 | + * @throws NotFoundException |
|
153 | + */ |
|
154 | + public function showFile(string $fileid = null, int $openfile = 1): Response { |
|
155 | + // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server. |
|
156 | + try { |
|
157 | + return $this->redirectToFile($fileid, $openfile !== 0); |
|
158 | + } catch (NotFoundException $e) { |
|
159 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @NoCSRFRequired |
|
165 | + * @NoAdminRequired |
|
166 | + * @UseSession |
|
167 | + * |
|
168 | + * @param string $dir |
|
169 | + * @param string $view |
|
170 | + * @param string $fileid |
|
171 | + * @param bool $fileNotFound |
|
172 | + * @param string $openfile - the openfile URL parameter if it was present in the initial request |
|
173 | + * @return TemplateResponse|RedirectResponse |
|
174 | + * @throws NotFoundException |
|
175 | + */ |
|
176 | + public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false, $openfile = null) { |
|
177 | + |
|
178 | + if ($fileid !== null && $dir === '') { |
|
179 | + try { |
|
180 | + return $this->redirectToFile($fileid); |
|
181 | + } catch (NotFoundException $e) { |
|
182 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
187 | + |
|
188 | + // Load the files we need |
|
189 | + \OCP\Util::addStyle('files', 'merged'); |
|
190 | + \OCP\Util::addScript('files', 'merged-index', 'files'); |
|
191 | + \OCP\Util::addScript('files', 'main'); |
|
192 | + |
|
193 | + // mostly for the home storage's free space |
|
194 | + // FIXME: Make non static |
|
195 | + $storageInfo = $this->getStorageInfo(); |
|
196 | + |
|
197 | + $userId = $this->userSession->getUser()->getUID(); |
|
198 | + |
|
199 | + // Get all the user favorites to create a submenu |
|
200 | + try { |
|
201 | + $favElements = $this->activityHelper->getFavoriteFilePaths($userId); |
|
202 | + } catch (\RuntimeException $e) { |
|
203 | + $favElements['folders'] = []; |
|
204 | + } |
|
205 | + |
|
206 | + $collapseClasses = ''; |
|
207 | + if (count($favElements['folders']) > 0) { |
|
208 | + $collapseClasses = 'collapsible'; |
|
209 | + } |
|
210 | + |
|
211 | + $favoritesSublistArray = []; |
|
212 | + |
|
213 | + $navBarPositionPosition = 6; |
|
214 | + foreach ($favElements['folders'] as $favElement) { |
|
215 | + $element = [ |
|
216 | + 'id' => str_replace('/', '-', $favElement), |
|
217 | + 'dir' => $favElement, |
|
218 | + 'order' => $navBarPositionPosition, |
|
219 | + 'name' => basename($favElement), |
|
220 | + 'icon' => 'folder', |
|
221 | + 'params' => [ |
|
222 | + 'view' => 'files', |
|
223 | + 'dir' => $favElement, |
|
224 | + ], |
|
225 | + ]; |
|
226 | + |
|
227 | + array_push($favoritesSublistArray, $element); |
|
228 | + $navBarPositionPosition++; |
|
229 | + } |
|
230 | + |
|
231 | + $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
232 | + |
|
233 | + // add the favorites entry in menu |
|
234 | + $navItems['favorites']['sublist'] = $favoritesSublistArray; |
|
235 | + $navItems['favorites']['classes'] = $collapseClasses; |
|
236 | + |
|
237 | + // parse every menu and add the expanded user value |
|
238 | + foreach ($navItems as $key => $item) { |
|
239 | + $navItems[$key]['expanded'] = $this->config->getUserValue($userId, 'files', 'show_' . $item['id'], '0') === '1'; |
|
240 | + } |
|
241 | + |
|
242 | + $nav->assign('navigationItems', $navItems); |
|
243 | + |
|
244 | + $contentItems = []; |
|
245 | + |
|
246 | + try { |
|
247 | + // If view is files, we use the directory, otherwise we use the root storage |
|
248 | + $storageInfo = $this->getStorageInfo(($view === 'files' && $dir) ? $dir : '/'); |
|
249 | + } catch(\Exception $e) { |
|
250 | + $storageInfo = $this->getStorageInfo(); |
|
251 | + } |
|
252 | + |
|
253 | + $this->initialState->provideInitialState('storageStats', $storageInfo); |
|
254 | + $this->initialState->provideInitialState('navigation', $navItems); |
|
255 | + $this->initialState->provideInitialState('config', $this->userConfig->getConfigs()); |
|
256 | + |
|
257 | + // render the container content for every navigation item |
|
258 | + foreach ($navItems as $item) { |
|
259 | + $content = ''; |
|
260 | + if (isset($item['script'])) { |
|
261 | + $content = $this->renderScript($item['appname'], $item['script']); |
|
262 | + } |
|
263 | + // parse submenus |
|
264 | + if (isset($item['sublist'])) { |
|
265 | + foreach ($item['sublist'] as $subitem) { |
|
266 | + $subcontent = ''; |
|
267 | + if (isset($subitem['script'])) { |
|
268 | + $subcontent = $this->renderScript($subitem['appname'], $subitem['script']); |
|
269 | + } |
|
270 | + $contentItems[$subitem['id']] = [ |
|
271 | + 'id' => $subitem['id'], |
|
272 | + 'content' => $subcontent |
|
273 | + ]; |
|
274 | + } |
|
275 | + } |
|
276 | + $contentItems[$item['id']] = [ |
|
277 | + 'id' => $item['id'], |
|
278 | + 'content' => $content |
|
279 | + ]; |
|
280 | + } |
|
281 | + |
|
282 | + $this->eventDispatcher->dispatchTyped(new ResourcesLoadAdditionalScriptsEvent()); |
|
283 | + $event = new LoadAdditionalScriptsEvent(); |
|
284 | + $this->eventDispatcher->dispatchTyped($event); |
|
285 | + $this->eventDispatcher->dispatchTyped(new LoadSidebar()); |
|
286 | + // Load Viewer scripts |
|
287 | + if (class_exists(LoadViewer::class)) { |
|
288 | + $this->eventDispatcher->dispatchTyped(new LoadViewer()); |
|
289 | + } |
|
290 | + |
|
291 | + $this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false); |
|
292 | + $this->initialState->provideInitialState('templates', $this->templateManager->listCreators()); |
|
293 | + |
|
294 | + $params = []; |
|
295 | + $params['usedSpacePercent'] = (int) $storageInfo['relative']; |
|
296 | + $params['owner'] = $storageInfo['owner'] ?? ''; |
|
297 | + $params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? ''; |
|
298 | + $params['isPublic'] = false; |
|
299 | + $params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no'; |
|
300 | + $params['defaultFileSorting'] = $this->config->getUserValue($userId, 'files', 'file_sorting', 'name'); |
|
301 | + $params['defaultFileSortingDirection'] = $this->config->getUserValue($userId, 'files', 'file_sorting_direction', 'asc'); |
|
302 | + $params['showgridview'] = $this->config->getUserValue($userId, 'files', 'show_grid', false); |
|
303 | + $showHidden = (bool) $this->config->getUserValue($userId, 'files', 'show_hidden', false); |
|
304 | + $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
305 | + $cropImagePreviews = (bool) $this->config->getUserValue($userId, 'files', 'crop_image_previews', true); |
|
306 | + $params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0; |
|
307 | + $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
308 | + $params['appNavigation'] = $nav; |
|
309 | + $params['appContents'] = $contentItems; |
|
310 | + $params['hiddenFields'] = $event->getHiddenFields(); |
|
311 | + |
|
312 | + $response = new TemplateResponse( |
|
313 | + Application::APP_ID, |
|
314 | + 'index', |
|
315 | + $params |
|
316 | + ); |
|
317 | + $policy = new ContentSecurityPolicy(); |
|
318 | + $policy->addAllowedFrameDomain('\'self\''); |
|
319 | + $response->setContentSecurityPolicy($policy); |
|
320 | + |
|
321 | + $this->provideInitialState($dir, $openfile); |
|
322 | + |
|
323 | + return $response; |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Add openFileInfo in initialState if $openfile is set. |
|
328 | + * @param string $dir - the ?dir= URL param |
|
329 | + * @param string $openfile - the ?openfile= URL param |
|
330 | + * @return void |
|
331 | + */ |
|
332 | + private function provideInitialState(string $dir, ?string $openfile): void { |
|
333 | + if ($openfile === null) { |
|
334 | + return; |
|
335 | + } |
|
336 | + |
|
337 | + $user = $this->userSession->getUser(); |
|
338 | + |
|
339 | + if ($user === null) { |
|
340 | + return; |
|
341 | + } |
|
342 | + |
|
343 | + $uid = $user->getUID(); |
|
344 | + $userFolder = $this->rootFolder->getUserFolder($uid); |
|
345 | + $nodes = $userFolder->getById((int) $openfile); |
|
346 | + $node = array_shift($nodes); |
|
347 | + |
|
348 | + if ($node === null) { |
|
349 | + return; |
|
350 | + } |
|
351 | + |
|
352 | + // properly format full path and make sure |
|
353 | + // we're relative to the user home folder |
|
354 | + $isRoot = $node === $userFolder; |
|
355 | + $path = $userFolder->getRelativePath($node->getPath()); |
|
356 | + $directory = $userFolder->getRelativePath($node->getParent()->getPath()); |
|
357 | + |
|
358 | + // Prevent opening a file from another folder. |
|
359 | + if ($dir !== $directory) { |
|
360 | + return; |
|
361 | + } |
|
362 | + |
|
363 | + $this->initialState->provideInitialState( |
|
364 | + 'openFileInfo', [ |
|
365 | + 'id' => $node->getId(), |
|
366 | + 'name' => $isRoot ? '' : $node->getName(), |
|
367 | + 'path' => $path, |
|
368 | + 'directory' => $directory, |
|
369 | + 'mime' => $node->getMimetype(), |
|
370 | + 'type' => $node->getType(), |
|
371 | + 'permissions' => $node->getPermissions(), |
|
372 | + ] |
|
373 | + ); |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Redirects to the file list and highlight the given file id |
|
378 | + * |
|
379 | + * @param string $fileId file id to show |
|
380 | + * @param bool $setOpenfile - whether or not to set the openfile URL parameter |
|
381 | + * @return RedirectResponse redirect response or not found response |
|
382 | + * @throws \OCP\Files\NotFoundException |
|
383 | + */ |
|
384 | + private function redirectToFile($fileId, bool $setOpenfile = false) { |
|
385 | + $uid = $this->userSession->getUser()->getUID(); |
|
386 | + $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
387 | + $files = $baseFolder->getById($fileId); |
|
388 | + $params = []; |
|
389 | + |
|
390 | + if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
391 | + $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
392 | + $files = $baseFolder->getById($fileId); |
|
393 | + $params['view'] = 'trashbin'; |
|
394 | + } |
|
395 | + |
|
396 | + if (!empty($files)) { |
|
397 | + $file = current($files); |
|
398 | + if ($file instanceof Folder) { |
|
399 | + // set the full path to enter the folder |
|
400 | + $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
401 | + } else { |
|
402 | + // set parent path as dir |
|
403 | + $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
404 | + // and scroll to the entry |
|
405 | + $params['scrollto'] = $file->getName(); |
|
406 | + |
|
407 | + if ($setOpenfile) { |
|
408 | + // forward the openfile URL parameter. |
|
409 | + $params['openfile'] = $fileId; |
|
410 | + } |
|
411 | + } |
|
412 | + |
|
413 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
414 | + } |
|
415 | + throw new \OCP\Files\NotFoundException(); |
|
416 | + } |
|
417 | 417 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | protected function renderScript($appName, $scriptName) { |
119 | 119 | $content = ''; |
120 | 120 | $appPath = \OC_App::getAppPath($appName); |
121 | - $scriptPath = $appPath . '/' . $scriptName; |
|
121 | + $scriptPath = $appPath.'/'.$scriptName; |
|
122 | 122 | if (file_exists($scriptPath)) { |
123 | 123 | // TODO: sanitize path / script name ? |
124 | 124 | ob_start(); |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | |
237 | 237 | // parse every menu and add the expanded user value |
238 | 238 | foreach ($navItems as $key => $item) { |
239 | - $navItems[$key]['expanded'] = $this->config->getUserValue($userId, 'files', 'show_' . $item['id'], '0') === '1'; |
|
239 | + $navItems[$key]['expanded'] = $this->config->getUserValue($userId, 'files', 'show_'.$item['id'], '0') === '1'; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | $nav->assign('navigationItems', $navItems); |
@@ -245,8 +245,8 @@ discard block |
||
245 | 245 | |
246 | 246 | try { |
247 | 247 | // If view is files, we use the directory, otherwise we use the root storage |
248 | - $storageInfo = $this->getStorageInfo(($view === 'files' && $dir) ? $dir : '/'); |
|
249 | - } catch(\Exception $e) { |
|
248 | + $storageInfo = $this->getStorageInfo(($view === 'files' && $dir) ? $dir : '/'); |
|
249 | + } catch (\Exception $e) { |
|
250 | 250 | $storageInfo = $this->getStorageInfo(); |
251 | 251 | } |
252 | 252 | |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | $params = []; |
389 | 389 | |
390 | 390 | if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
391 | - $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
391 | + $baseFolder = $this->rootFolder->get($uid.'/files_trashbin/files/'); |
|
392 | 392 | $files = $baseFolder->getById($fileId); |
393 | 393 | $params['view'] = 'trashbin'; |
394 | 394 | } |
@@ -6,57 +6,57 @@ |
||
6 | 6 | $baseDir = $vendorDir; |
7 | 7 | |
8 | 8 | return array( |
9 | - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', |
|
10 | - 'OCA\\Files\\Activity\\FavoriteProvider' => $baseDir . '/../lib/Activity/FavoriteProvider.php', |
|
11 | - 'OCA\\Files\\Activity\\Filter\\Favorites' => $baseDir . '/../lib/Activity/Filter/Favorites.php', |
|
12 | - 'OCA\\Files\\Activity\\Filter\\FileChanges' => $baseDir . '/../lib/Activity/Filter/FileChanges.php', |
|
13 | - 'OCA\\Files\\Activity\\Helper' => $baseDir . '/../lib/Activity/Helper.php', |
|
14 | - 'OCA\\Files\\Activity\\Provider' => $baseDir . '/../lib/Activity/Provider.php', |
|
15 | - 'OCA\\Files\\Activity\\Settings\\FavoriteAction' => $baseDir . '/../lib/Activity/Settings/FavoriteAction.php', |
|
16 | - 'OCA\\Files\\Activity\\Settings\\FileActivitySettings' => $baseDir . '/../lib/Activity/Settings/FileActivitySettings.php', |
|
17 | - 'OCA\\Files\\Activity\\Settings\\FileChanged' => $baseDir . '/../lib/Activity/Settings/FileChanged.php', |
|
18 | - 'OCA\\Files\\Activity\\Settings\\FileFavoriteChanged' => $baseDir . '/../lib/Activity/Settings/FileFavoriteChanged.php', |
|
19 | - 'OCA\\Files\\App' => $baseDir . '/../lib/App.php', |
|
20 | - 'OCA\\Files\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
21 | - 'OCA\\Files\\BackgroundJob\\CleanupDirectEditingTokens' => $baseDir . '/../lib/BackgroundJob/CleanupDirectEditingTokens.php', |
|
22 | - 'OCA\\Files\\BackgroundJob\\CleanupFileLocks' => $baseDir . '/../lib/BackgroundJob/CleanupFileLocks.php', |
|
23 | - 'OCA\\Files\\BackgroundJob\\DeleteExpiredOpenLocalEditor' => $baseDir . '/../lib/BackgroundJob/DeleteExpiredOpenLocalEditor.php', |
|
24 | - 'OCA\\Files\\BackgroundJob\\DeleteOrphanedItems' => $baseDir . '/../lib/BackgroundJob/DeleteOrphanedItems.php', |
|
25 | - 'OCA\\Files\\BackgroundJob\\ScanFiles' => $baseDir . '/../lib/BackgroundJob/ScanFiles.php', |
|
26 | - 'OCA\\Files\\BackgroundJob\\TransferOwnership' => $baseDir . '/../lib/BackgroundJob/TransferOwnership.php', |
|
27 | - 'OCA\\Files\\Capabilities' => $baseDir . '/../lib/Capabilities.php', |
|
28 | - 'OCA\\Files\\Collaboration\\Resources\\Listener' => $baseDir . '/../lib/Collaboration/Resources/Listener.php', |
|
29 | - 'OCA\\Files\\Collaboration\\Resources\\ResourceProvider' => $baseDir . '/../lib/Collaboration/Resources/ResourceProvider.php', |
|
30 | - 'OCA\\Files\\Command\\DeleteOrphanedFiles' => $baseDir . '/../lib/Command/DeleteOrphanedFiles.php', |
|
31 | - 'OCA\\Files\\Command\\RepairTree' => $baseDir . '/../lib/Command/RepairTree.php', |
|
32 | - 'OCA\\Files\\Command\\Scan' => $baseDir . '/../lib/Command/Scan.php', |
|
33 | - 'OCA\\Files\\Command\\ScanAppData' => $baseDir . '/../lib/Command/ScanAppData.php', |
|
34 | - 'OCA\\Files\\Command\\TransferOwnership' => $baseDir . '/../lib/Command/TransferOwnership.php', |
|
35 | - 'OCA\\Files\\Controller\\ApiController' => $baseDir . '/../lib/Controller/ApiController.php', |
|
36 | - 'OCA\\Files\\Controller\\DirectEditingController' => $baseDir . '/../lib/Controller/DirectEditingController.php', |
|
37 | - 'OCA\\Files\\Controller\\DirectEditingViewController' => $baseDir . '/../lib/Controller/DirectEditingViewController.php', |
|
38 | - 'OCA\\Files\\Controller\\OpenLocalEditorController' => $baseDir . '/../lib/Controller/OpenLocalEditorController.php', |
|
39 | - 'OCA\\Files\\Controller\\TemplateController' => $baseDir . '/../lib/Controller/TemplateController.php', |
|
40 | - 'OCA\\Files\\Controller\\TransferOwnershipController' => $baseDir . '/../lib/Controller/TransferOwnershipController.php', |
|
41 | - 'OCA\\Files\\Controller\\ViewController' => $baseDir . '/../lib/Controller/ViewController.php', |
|
42 | - 'OCA\\Files\\Db\\OpenLocalEditor' => $baseDir . '/../lib/Db/OpenLocalEditor.php', |
|
43 | - 'OCA\\Files\\Db\\OpenLocalEditorMapper' => $baseDir . '/../lib/Db/OpenLocalEditorMapper.php', |
|
44 | - 'OCA\\Files\\Db\\TransferOwnership' => $baseDir . '/../lib/Db/TransferOwnership.php', |
|
45 | - 'OCA\\Files\\Db\\TransferOwnershipMapper' => $baseDir . '/../lib/Db/TransferOwnershipMapper.php', |
|
46 | - 'OCA\\Files\\DirectEditingCapabilities' => $baseDir . '/../lib/DirectEditingCapabilities.php', |
|
47 | - 'OCA\\Files\\Event\\LoadAdditionalScriptsEvent' => $baseDir . '/../lib/Event/LoadAdditionalScriptsEvent.php', |
|
48 | - 'OCA\\Files\\Event\\LoadSidebar' => $baseDir . '/../lib/Event/LoadSidebar.php', |
|
49 | - 'OCA\\Files\\Exception\\TransferOwnershipException' => $baseDir . '/../lib/Exception/TransferOwnershipException.php', |
|
50 | - 'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php', |
|
51 | - 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php', |
|
52 | - 'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php', |
|
53 | - 'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php', |
|
54 | - 'OCA\\Files\\Migration\\Version12101Date20221011153334' => $baseDir . '/../lib/Migration/Version12101Date20221011153334.php', |
|
55 | - 'OCA\\Files\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php', |
|
56 | - 'OCA\\Files\\Search\\FilesSearchProvider' => $baseDir . '/../lib/Search/FilesSearchProvider.php', |
|
57 | - 'OCA\\Files\\Service\\DirectEditingService' => $baseDir . '/../lib/Service/DirectEditingService.php', |
|
58 | - 'OCA\\Files\\Service\\OwnershipTransferService' => $baseDir . '/../lib/Service/OwnershipTransferService.php', |
|
59 | - 'OCA\\Files\\Service\\TagService' => $baseDir . '/../lib/Service/TagService.php', |
|
60 | - 'OCA\\Files\\Service\\UserConfig' => $baseDir . '/../lib/Service/UserConfig.php', |
|
61 | - 'OCA\\Files\\Settings\\PersonalSettings' => $baseDir . '/../lib/Settings/PersonalSettings.php', |
|
9 | + 'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php', |
|
10 | + 'OCA\\Files\\Activity\\FavoriteProvider' => $baseDir.'/../lib/Activity/FavoriteProvider.php', |
|
11 | + 'OCA\\Files\\Activity\\Filter\\Favorites' => $baseDir.'/../lib/Activity/Filter/Favorites.php', |
|
12 | + 'OCA\\Files\\Activity\\Filter\\FileChanges' => $baseDir.'/../lib/Activity/Filter/FileChanges.php', |
|
13 | + 'OCA\\Files\\Activity\\Helper' => $baseDir.'/../lib/Activity/Helper.php', |
|
14 | + 'OCA\\Files\\Activity\\Provider' => $baseDir.'/../lib/Activity/Provider.php', |
|
15 | + 'OCA\\Files\\Activity\\Settings\\FavoriteAction' => $baseDir.'/../lib/Activity/Settings/FavoriteAction.php', |
|
16 | + 'OCA\\Files\\Activity\\Settings\\FileActivitySettings' => $baseDir.'/../lib/Activity/Settings/FileActivitySettings.php', |
|
17 | + 'OCA\\Files\\Activity\\Settings\\FileChanged' => $baseDir.'/../lib/Activity/Settings/FileChanged.php', |
|
18 | + 'OCA\\Files\\Activity\\Settings\\FileFavoriteChanged' => $baseDir.'/../lib/Activity/Settings/FileFavoriteChanged.php', |
|
19 | + 'OCA\\Files\\App' => $baseDir.'/../lib/App.php', |
|
20 | + 'OCA\\Files\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
21 | + 'OCA\\Files\\BackgroundJob\\CleanupDirectEditingTokens' => $baseDir.'/../lib/BackgroundJob/CleanupDirectEditingTokens.php', |
|
22 | + 'OCA\\Files\\BackgroundJob\\CleanupFileLocks' => $baseDir.'/../lib/BackgroundJob/CleanupFileLocks.php', |
|
23 | + 'OCA\\Files\\BackgroundJob\\DeleteExpiredOpenLocalEditor' => $baseDir.'/../lib/BackgroundJob/DeleteExpiredOpenLocalEditor.php', |
|
24 | + 'OCA\\Files\\BackgroundJob\\DeleteOrphanedItems' => $baseDir.'/../lib/BackgroundJob/DeleteOrphanedItems.php', |
|
25 | + 'OCA\\Files\\BackgroundJob\\ScanFiles' => $baseDir.'/../lib/BackgroundJob/ScanFiles.php', |
|
26 | + 'OCA\\Files\\BackgroundJob\\TransferOwnership' => $baseDir.'/../lib/BackgroundJob/TransferOwnership.php', |
|
27 | + 'OCA\\Files\\Capabilities' => $baseDir.'/../lib/Capabilities.php', |
|
28 | + 'OCA\\Files\\Collaboration\\Resources\\Listener' => $baseDir.'/../lib/Collaboration/Resources/Listener.php', |
|
29 | + 'OCA\\Files\\Collaboration\\Resources\\ResourceProvider' => $baseDir.'/../lib/Collaboration/Resources/ResourceProvider.php', |
|
30 | + 'OCA\\Files\\Command\\DeleteOrphanedFiles' => $baseDir.'/../lib/Command/DeleteOrphanedFiles.php', |
|
31 | + 'OCA\\Files\\Command\\RepairTree' => $baseDir.'/../lib/Command/RepairTree.php', |
|
32 | + 'OCA\\Files\\Command\\Scan' => $baseDir.'/../lib/Command/Scan.php', |
|
33 | + 'OCA\\Files\\Command\\ScanAppData' => $baseDir.'/../lib/Command/ScanAppData.php', |
|
34 | + 'OCA\\Files\\Command\\TransferOwnership' => $baseDir.'/../lib/Command/TransferOwnership.php', |
|
35 | + 'OCA\\Files\\Controller\\ApiController' => $baseDir.'/../lib/Controller/ApiController.php', |
|
36 | + 'OCA\\Files\\Controller\\DirectEditingController' => $baseDir.'/../lib/Controller/DirectEditingController.php', |
|
37 | + 'OCA\\Files\\Controller\\DirectEditingViewController' => $baseDir.'/../lib/Controller/DirectEditingViewController.php', |
|
38 | + 'OCA\\Files\\Controller\\OpenLocalEditorController' => $baseDir.'/../lib/Controller/OpenLocalEditorController.php', |
|
39 | + 'OCA\\Files\\Controller\\TemplateController' => $baseDir.'/../lib/Controller/TemplateController.php', |
|
40 | + 'OCA\\Files\\Controller\\TransferOwnershipController' => $baseDir.'/../lib/Controller/TransferOwnershipController.php', |
|
41 | + 'OCA\\Files\\Controller\\ViewController' => $baseDir.'/../lib/Controller/ViewController.php', |
|
42 | + 'OCA\\Files\\Db\\OpenLocalEditor' => $baseDir.'/../lib/Db/OpenLocalEditor.php', |
|
43 | + 'OCA\\Files\\Db\\OpenLocalEditorMapper' => $baseDir.'/../lib/Db/OpenLocalEditorMapper.php', |
|
44 | + 'OCA\\Files\\Db\\TransferOwnership' => $baseDir.'/../lib/Db/TransferOwnership.php', |
|
45 | + 'OCA\\Files\\Db\\TransferOwnershipMapper' => $baseDir.'/../lib/Db/TransferOwnershipMapper.php', |
|
46 | + 'OCA\\Files\\DirectEditingCapabilities' => $baseDir.'/../lib/DirectEditingCapabilities.php', |
|
47 | + 'OCA\\Files\\Event\\LoadAdditionalScriptsEvent' => $baseDir.'/../lib/Event/LoadAdditionalScriptsEvent.php', |
|
48 | + 'OCA\\Files\\Event\\LoadSidebar' => $baseDir.'/../lib/Event/LoadSidebar.php', |
|
49 | + 'OCA\\Files\\Exception\\TransferOwnershipException' => $baseDir.'/../lib/Exception/TransferOwnershipException.php', |
|
50 | + 'OCA\\Files\\Helper' => $baseDir.'/../lib/Helper.php', |
|
51 | + 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir.'/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php', |
|
52 | + 'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir.'/../lib/Listener/LoadSidebarListener.php', |
|
53 | + 'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir.'/../lib/Migration/Version11301Date20191205150729.php', |
|
54 | + 'OCA\\Files\\Migration\\Version12101Date20221011153334' => $baseDir.'/../lib/Migration/Version12101Date20221011153334.php', |
|
55 | + 'OCA\\Files\\Notification\\Notifier' => $baseDir.'/../lib/Notification/Notifier.php', |
|
56 | + 'OCA\\Files\\Search\\FilesSearchProvider' => $baseDir.'/../lib/Search/FilesSearchProvider.php', |
|
57 | + 'OCA\\Files\\Service\\DirectEditingService' => $baseDir.'/../lib/Service/DirectEditingService.php', |
|
58 | + 'OCA\\Files\\Service\\OwnershipTransferService' => $baseDir.'/../lib/Service/OwnershipTransferService.php', |
|
59 | + 'OCA\\Files\\Service\\TagService' => $baseDir.'/../lib/Service/TagService.php', |
|
60 | + 'OCA\\Files\\Service\\UserConfig' => $baseDir.'/../lib/Service/UserConfig.php', |
|
61 | + 'OCA\\Files\\Settings\\PersonalSettings' => $baseDir.'/../lib/Settings/PersonalSettings.php', |
|
62 | 62 | ); |
@@ -6,79 +6,79 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInitFiles |
8 | 8 | { |
9 | - public static $prefixLengthsPsr4 = array ( |
|
9 | + public static $prefixLengthsPsr4 = array( |
|
10 | 10 | 'O' => |
11 | - array ( |
|
11 | + array( |
|
12 | 12 | 'OCA\\Files\\' => 10, |
13 | 13 | ), |
14 | 14 | ); |
15 | 15 | |
16 | - public static $prefixDirsPsr4 = array ( |
|
16 | + public static $prefixDirsPsr4 = array( |
|
17 | 17 | 'OCA\\Files\\' => |
18 | - array ( |
|
19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
18 | + array( |
|
19 | + 0 => __DIR__.'/..'.'/../lib', |
|
20 | 20 | ), |
21 | 21 | ); |
22 | 22 | |
23 | - public static $classMap = array ( |
|
24 | - 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', |
|
25 | - 'OCA\\Files\\Activity\\FavoriteProvider' => __DIR__ . '/..' . '/../lib/Activity/FavoriteProvider.php', |
|
26 | - 'OCA\\Files\\Activity\\Filter\\Favorites' => __DIR__ . '/..' . '/../lib/Activity/Filter/Favorites.php', |
|
27 | - 'OCA\\Files\\Activity\\Filter\\FileChanges' => __DIR__ . '/..' . '/../lib/Activity/Filter/FileChanges.php', |
|
28 | - 'OCA\\Files\\Activity\\Helper' => __DIR__ . '/..' . '/../lib/Activity/Helper.php', |
|
29 | - 'OCA\\Files\\Activity\\Provider' => __DIR__ . '/..' . '/../lib/Activity/Provider.php', |
|
30 | - 'OCA\\Files\\Activity\\Settings\\FavoriteAction' => __DIR__ . '/..' . '/../lib/Activity/Settings/FavoriteAction.php', |
|
31 | - 'OCA\\Files\\Activity\\Settings\\FileActivitySettings' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileActivitySettings.php', |
|
32 | - 'OCA\\Files\\Activity\\Settings\\FileChanged' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileChanged.php', |
|
33 | - 'OCA\\Files\\Activity\\Settings\\FileFavoriteChanged' => __DIR__ . '/..' . '/../lib/Activity/Settings/FileFavoriteChanged.php', |
|
34 | - 'OCA\\Files\\App' => __DIR__ . '/..' . '/../lib/App.php', |
|
35 | - 'OCA\\Files\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
36 | - 'OCA\\Files\\BackgroundJob\\CleanupDirectEditingTokens' => __DIR__ . '/..' . '/../lib/BackgroundJob/CleanupDirectEditingTokens.php', |
|
37 | - 'OCA\\Files\\BackgroundJob\\CleanupFileLocks' => __DIR__ . '/..' . '/../lib/BackgroundJob/CleanupFileLocks.php', |
|
38 | - 'OCA\\Files\\BackgroundJob\\DeleteExpiredOpenLocalEditor' => __DIR__ . '/..' . '/../lib/BackgroundJob/DeleteExpiredOpenLocalEditor.php', |
|
39 | - 'OCA\\Files\\BackgroundJob\\DeleteOrphanedItems' => __DIR__ . '/..' . '/../lib/BackgroundJob/DeleteOrphanedItems.php', |
|
40 | - 'OCA\\Files\\BackgroundJob\\ScanFiles' => __DIR__ . '/..' . '/../lib/BackgroundJob/ScanFiles.php', |
|
41 | - 'OCA\\Files\\BackgroundJob\\TransferOwnership' => __DIR__ . '/..' . '/../lib/BackgroundJob/TransferOwnership.php', |
|
42 | - 'OCA\\Files\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php', |
|
43 | - 'OCA\\Files\\Collaboration\\Resources\\Listener' => __DIR__ . '/..' . '/../lib/Collaboration/Resources/Listener.php', |
|
44 | - 'OCA\\Files\\Collaboration\\Resources\\ResourceProvider' => __DIR__ . '/..' . '/../lib/Collaboration/Resources/ResourceProvider.php', |
|
45 | - 'OCA\\Files\\Command\\DeleteOrphanedFiles' => __DIR__ . '/..' . '/../lib/Command/DeleteOrphanedFiles.php', |
|
46 | - 'OCA\\Files\\Command\\RepairTree' => __DIR__ . '/..' . '/../lib/Command/RepairTree.php', |
|
47 | - 'OCA\\Files\\Command\\Scan' => __DIR__ . '/..' . '/../lib/Command/Scan.php', |
|
48 | - 'OCA\\Files\\Command\\ScanAppData' => __DIR__ . '/..' . '/../lib/Command/ScanAppData.php', |
|
49 | - 'OCA\\Files\\Command\\TransferOwnership' => __DIR__ . '/..' . '/../lib/Command/TransferOwnership.php', |
|
50 | - 'OCA\\Files\\Controller\\ApiController' => __DIR__ . '/..' . '/../lib/Controller/ApiController.php', |
|
51 | - 'OCA\\Files\\Controller\\DirectEditingController' => __DIR__ . '/..' . '/../lib/Controller/DirectEditingController.php', |
|
52 | - 'OCA\\Files\\Controller\\DirectEditingViewController' => __DIR__ . '/..' . '/../lib/Controller/DirectEditingViewController.php', |
|
53 | - 'OCA\\Files\\Controller\\OpenLocalEditorController' => __DIR__ . '/..' . '/../lib/Controller/OpenLocalEditorController.php', |
|
54 | - 'OCA\\Files\\Controller\\TemplateController' => __DIR__ . '/..' . '/../lib/Controller/TemplateController.php', |
|
55 | - 'OCA\\Files\\Controller\\TransferOwnershipController' => __DIR__ . '/..' . '/../lib/Controller/TransferOwnershipController.php', |
|
56 | - 'OCA\\Files\\Controller\\ViewController' => __DIR__ . '/..' . '/../lib/Controller/ViewController.php', |
|
57 | - 'OCA\\Files\\Db\\OpenLocalEditor' => __DIR__ . '/..' . '/../lib/Db/OpenLocalEditor.php', |
|
58 | - 'OCA\\Files\\Db\\OpenLocalEditorMapper' => __DIR__ . '/..' . '/../lib/Db/OpenLocalEditorMapper.php', |
|
59 | - 'OCA\\Files\\Db\\TransferOwnership' => __DIR__ . '/..' . '/../lib/Db/TransferOwnership.php', |
|
60 | - 'OCA\\Files\\Db\\TransferOwnershipMapper' => __DIR__ . '/..' . '/../lib/Db/TransferOwnershipMapper.php', |
|
61 | - 'OCA\\Files\\DirectEditingCapabilities' => __DIR__ . '/..' . '/../lib/DirectEditingCapabilities.php', |
|
62 | - 'OCA\\Files\\Event\\LoadAdditionalScriptsEvent' => __DIR__ . '/..' . '/../lib/Event/LoadAdditionalScriptsEvent.php', |
|
63 | - 'OCA\\Files\\Event\\LoadSidebar' => __DIR__ . '/..' . '/../lib/Event/LoadSidebar.php', |
|
64 | - 'OCA\\Files\\Exception\\TransferOwnershipException' => __DIR__ . '/..' . '/../lib/Exception/TransferOwnershipException.php', |
|
65 | - 'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php', |
|
66 | - 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__ . '/..' . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php', |
|
67 | - 'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php', |
|
68 | - 'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php', |
|
69 | - 'OCA\\Files\\Migration\\Version12101Date20221011153334' => __DIR__ . '/..' . '/../lib/Migration/Version12101Date20221011153334.php', |
|
70 | - 'OCA\\Files\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php', |
|
71 | - 'OCA\\Files\\Search\\FilesSearchProvider' => __DIR__ . '/..' . '/../lib/Search/FilesSearchProvider.php', |
|
72 | - 'OCA\\Files\\Service\\DirectEditingService' => __DIR__ . '/..' . '/../lib/Service/DirectEditingService.php', |
|
73 | - 'OCA\\Files\\Service\\OwnershipTransferService' => __DIR__ . '/..' . '/../lib/Service/OwnershipTransferService.php', |
|
74 | - 'OCA\\Files\\Service\\TagService' => __DIR__ . '/..' . '/../lib/Service/TagService.php', |
|
75 | - 'OCA\\Files\\Service\\UserConfig' => __DIR__ . '/..' . '/../lib/Service/UserConfig.php', |
|
76 | - 'OCA\\Files\\Settings\\PersonalSettings' => __DIR__ . '/..' . '/../lib/Settings/PersonalSettings.php', |
|
23 | + public static $classMap = array( |
|
24 | + 'Composer\\InstalledVersions' => __DIR__.'/..'.'/composer/InstalledVersions.php', |
|
25 | + 'OCA\\Files\\Activity\\FavoriteProvider' => __DIR__.'/..'.'/../lib/Activity/FavoriteProvider.php', |
|
26 | + 'OCA\\Files\\Activity\\Filter\\Favorites' => __DIR__.'/..'.'/../lib/Activity/Filter/Favorites.php', |
|
27 | + 'OCA\\Files\\Activity\\Filter\\FileChanges' => __DIR__.'/..'.'/../lib/Activity/Filter/FileChanges.php', |
|
28 | + 'OCA\\Files\\Activity\\Helper' => __DIR__.'/..'.'/../lib/Activity/Helper.php', |
|
29 | + 'OCA\\Files\\Activity\\Provider' => __DIR__.'/..'.'/../lib/Activity/Provider.php', |
|
30 | + 'OCA\\Files\\Activity\\Settings\\FavoriteAction' => __DIR__.'/..'.'/../lib/Activity/Settings/FavoriteAction.php', |
|
31 | + 'OCA\\Files\\Activity\\Settings\\FileActivitySettings' => __DIR__.'/..'.'/../lib/Activity/Settings/FileActivitySettings.php', |
|
32 | + 'OCA\\Files\\Activity\\Settings\\FileChanged' => __DIR__.'/..'.'/../lib/Activity/Settings/FileChanged.php', |
|
33 | + 'OCA\\Files\\Activity\\Settings\\FileFavoriteChanged' => __DIR__.'/..'.'/../lib/Activity/Settings/FileFavoriteChanged.php', |
|
34 | + 'OCA\\Files\\App' => __DIR__.'/..'.'/../lib/App.php', |
|
35 | + 'OCA\\Files\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
36 | + 'OCA\\Files\\BackgroundJob\\CleanupDirectEditingTokens' => __DIR__.'/..'.'/../lib/BackgroundJob/CleanupDirectEditingTokens.php', |
|
37 | + 'OCA\\Files\\BackgroundJob\\CleanupFileLocks' => __DIR__.'/..'.'/../lib/BackgroundJob/CleanupFileLocks.php', |
|
38 | + 'OCA\\Files\\BackgroundJob\\DeleteExpiredOpenLocalEditor' => __DIR__.'/..'.'/../lib/BackgroundJob/DeleteExpiredOpenLocalEditor.php', |
|
39 | + 'OCA\\Files\\BackgroundJob\\DeleteOrphanedItems' => __DIR__.'/..'.'/../lib/BackgroundJob/DeleteOrphanedItems.php', |
|
40 | + 'OCA\\Files\\BackgroundJob\\ScanFiles' => __DIR__.'/..'.'/../lib/BackgroundJob/ScanFiles.php', |
|
41 | + 'OCA\\Files\\BackgroundJob\\TransferOwnership' => __DIR__.'/..'.'/../lib/BackgroundJob/TransferOwnership.php', |
|
42 | + 'OCA\\Files\\Capabilities' => __DIR__.'/..'.'/../lib/Capabilities.php', |
|
43 | + 'OCA\\Files\\Collaboration\\Resources\\Listener' => __DIR__.'/..'.'/../lib/Collaboration/Resources/Listener.php', |
|
44 | + 'OCA\\Files\\Collaboration\\Resources\\ResourceProvider' => __DIR__.'/..'.'/../lib/Collaboration/Resources/ResourceProvider.php', |
|
45 | + 'OCA\\Files\\Command\\DeleteOrphanedFiles' => __DIR__.'/..'.'/../lib/Command/DeleteOrphanedFiles.php', |
|
46 | + 'OCA\\Files\\Command\\RepairTree' => __DIR__.'/..'.'/../lib/Command/RepairTree.php', |
|
47 | + 'OCA\\Files\\Command\\Scan' => __DIR__.'/..'.'/../lib/Command/Scan.php', |
|
48 | + 'OCA\\Files\\Command\\ScanAppData' => __DIR__.'/..'.'/../lib/Command/ScanAppData.php', |
|
49 | + 'OCA\\Files\\Command\\TransferOwnership' => __DIR__.'/..'.'/../lib/Command/TransferOwnership.php', |
|
50 | + 'OCA\\Files\\Controller\\ApiController' => __DIR__.'/..'.'/../lib/Controller/ApiController.php', |
|
51 | + 'OCA\\Files\\Controller\\DirectEditingController' => __DIR__.'/..'.'/../lib/Controller/DirectEditingController.php', |
|
52 | + 'OCA\\Files\\Controller\\DirectEditingViewController' => __DIR__.'/..'.'/../lib/Controller/DirectEditingViewController.php', |
|
53 | + 'OCA\\Files\\Controller\\OpenLocalEditorController' => __DIR__.'/..'.'/../lib/Controller/OpenLocalEditorController.php', |
|
54 | + 'OCA\\Files\\Controller\\TemplateController' => __DIR__.'/..'.'/../lib/Controller/TemplateController.php', |
|
55 | + 'OCA\\Files\\Controller\\TransferOwnershipController' => __DIR__.'/..'.'/../lib/Controller/TransferOwnershipController.php', |
|
56 | + 'OCA\\Files\\Controller\\ViewController' => __DIR__.'/..'.'/../lib/Controller/ViewController.php', |
|
57 | + 'OCA\\Files\\Db\\OpenLocalEditor' => __DIR__.'/..'.'/../lib/Db/OpenLocalEditor.php', |
|
58 | + 'OCA\\Files\\Db\\OpenLocalEditorMapper' => __DIR__.'/..'.'/../lib/Db/OpenLocalEditorMapper.php', |
|
59 | + 'OCA\\Files\\Db\\TransferOwnership' => __DIR__.'/..'.'/../lib/Db/TransferOwnership.php', |
|
60 | + 'OCA\\Files\\Db\\TransferOwnershipMapper' => __DIR__.'/..'.'/../lib/Db/TransferOwnershipMapper.php', |
|
61 | + 'OCA\\Files\\DirectEditingCapabilities' => __DIR__.'/..'.'/../lib/DirectEditingCapabilities.php', |
|
62 | + 'OCA\\Files\\Event\\LoadAdditionalScriptsEvent' => __DIR__.'/..'.'/../lib/Event/LoadAdditionalScriptsEvent.php', |
|
63 | + 'OCA\\Files\\Event\\LoadSidebar' => __DIR__.'/..'.'/../lib/Event/LoadSidebar.php', |
|
64 | + 'OCA\\Files\\Exception\\TransferOwnershipException' => __DIR__.'/..'.'/../lib/Exception/TransferOwnershipException.php', |
|
65 | + 'OCA\\Files\\Helper' => __DIR__.'/..'.'/../lib/Helper.php', |
|
66 | + 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__.'/..'.'/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php', |
|
67 | + 'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__.'/..'.'/../lib/Listener/LoadSidebarListener.php', |
|
68 | + 'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__.'/..'.'/../lib/Migration/Version11301Date20191205150729.php', |
|
69 | + 'OCA\\Files\\Migration\\Version12101Date20221011153334' => __DIR__.'/..'.'/../lib/Migration/Version12101Date20221011153334.php', |
|
70 | + 'OCA\\Files\\Notification\\Notifier' => __DIR__.'/..'.'/../lib/Notification/Notifier.php', |
|
71 | + 'OCA\\Files\\Search\\FilesSearchProvider' => __DIR__.'/..'.'/../lib/Search/FilesSearchProvider.php', |
|
72 | + 'OCA\\Files\\Service\\DirectEditingService' => __DIR__.'/..'.'/../lib/Service/DirectEditingService.php', |
|
73 | + 'OCA\\Files\\Service\\OwnershipTransferService' => __DIR__.'/..'.'/../lib/Service/OwnershipTransferService.php', |
|
74 | + 'OCA\\Files\\Service\\TagService' => __DIR__.'/..'.'/../lib/Service/TagService.php', |
|
75 | + 'OCA\\Files\\Service\\UserConfig' => __DIR__.'/..'.'/../lib/Service/UserConfig.php', |
|
76 | + 'OCA\\Files\\Settings\\PersonalSettings' => __DIR__.'/..'.'/../lib/Settings/PersonalSettings.php', |
|
77 | 77 | ); |
78 | 78 | |
79 | 79 | public static function getInitializer(ClassLoader $loader) |
80 | 80 | { |
81 | - return \Closure::bind(function () use ($loader) { |
|
81 | + return \Closure::bind(function() use ($loader) { |
|
82 | 82 | $loader->prefixLengthsPsr4 = ComposerStaticInitFiles::$prefixLengthsPsr4; |
83 | 83 | $loader->prefixDirsPsr4 = ComposerStaticInitFiles::$prefixDirsPsr4; |
84 | 84 | $loader->classMap = ComposerStaticInitFiles::$classMap; |
@@ -55,577 +55,577 @@ |
||
55 | 55 | * Collection of useful functions |
56 | 56 | */ |
57 | 57 | class OC_Helper { |
58 | - private static $templateManager; |
|
59 | - |
|
60 | - /** |
|
61 | - * Make a human file size |
|
62 | - * @param int $bytes file size in bytes |
|
63 | - * @return string a human readable file size |
|
64 | - * |
|
65 | - * Makes 2048 to 2 kB. |
|
66 | - */ |
|
67 | - public static function humanFileSize($bytes) { |
|
68 | - if ($bytes < 0) { |
|
69 | - return "?"; |
|
70 | - } |
|
71 | - if ($bytes < 1024) { |
|
72 | - return "$bytes B"; |
|
73 | - } |
|
74 | - $bytes = round($bytes / 1024, 0); |
|
75 | - if ($bytes < 1024) { |
|
76 | - return "$bytes KB"; |
|
77 | - } |
|
78 | - $bytes = round($bytes / 1024, 1); |
|
79 | - if ($bytes < 1024) { |
|
80 | - return "$bytes MB"; |
|
81 | - } |
|
82 | - $bytes = round($bytes / 1024, 1); |
|
83 | - if ($bytes < 1024) { |
|
84 | - return "$bytes GB"; |
|
85 | - } |
|
86 | - $bytes = round($bytes / 1024, 1); |
|
87 | - if ($bytes < 1024) { |
|
88 | - return "$bytes TB"; |
|
89 | - } |
|
90 | - |
|
91 | - $bytes = round($bytes / 1024, 1); |
|
92 | - return "$bytes PB"; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Make a computer file size |
|
97 | - * @param string $str file size in human readable format |
|
98 | - * @return int|false a file size in bytes |
|
99 | - * |
|
100 | - * Makes 2kB to 2048. |
|
101 | - * |
|
102 | - * Inspired by: https://www.php.net/manual/en/function.filesize.php#92418 |
|
103 | - */ |
|
104 | - public static function computerFileSize($str) { |
|
105 | - $str = strtolower($str); |
|
106 | - if (is_numeric($str)) { |
|
107 | - return (int)$str; |
|
108 | - } |
|
109 | - |
|
110 | - $bytes_array = [ |
|
111 | - 'b' => 1, |
|
112 | - 'k' => 1024, |
|
113 | - 'kb' => 1024, |
|
114 | - 'mb' => 1024 * 1024, |
|
115 | - 'm' => 1024 * 1024, |
|
116 | - 'gb' => 1024 * 1024 * 1024, |
|
117 | - 'g' => 1024 * 1024 * 1024, |
|
118 | - 'tb' => 1024 * 1024 * 1024 * 1024, |
|
119 | - 't' => 1024 * 1024 * 1024 * 1024, |
|
120 | - 'pb' => 1024 * 1024 * 1024 * 1024 * 1024, |
|
121 | - 'p' => 1024 * 1024 * 1024 * 1024 * 1024, |
|
122 | - ]; |
|
123 | - |
|
124 | - $bytes = (float)$str; |
|
125 | - |
|
126 | - if (preg_match('#([kmgtp]?b?)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) { |
|
127 | - $bytes *= $bytes_array[$matches[1]]; |
|
128 | - } else { |
|
129 | - return false; |
|
130 | - } |
|
131 | - |
|
132 | - $bytes = round($bytes); |
|
133 | - |
|
134 | - return (int)$bytes; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Recursive copying of folders |
|
139 | - * @param string $src source folder |
|
140 | - * @param string $dest target folder |
|
141 | - * |
|
142 | - */ |
|
143 | - public static function copyr($src, $dest) { |
|
144 | - if (is_dir($src)) { |
|
145 | - if (!is_dir($dest)) { |
|
146 | - mkdir($dest); |
|
147 | - } |
|
148 | - $files = scandir($src); |
|
149 | - foreach ($files as $file) { |
|
150 | - if ($file != "." && $file != "..") { |
|
151 | - self::copyr("$src/$file", "$dest/$file"); |
|
152 | - } |
|
153 | - } |
|
154 | - } elseif (file_exists($src) && !\OC\Files\Filesystem::isFileBlacklisted($src)) { |
|
155 | - copy($src, $dest); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Recursive deletion of folders |
|
161 | - * @param string $dir path to the folder |
|
162 | - * @param bool $deleteSelf if set to false only the content of the folder will be deleted |
|
163 | - * @return bool |
|
164 | - */ |
|
165 | - public static function rmdirr($dir, $deleteSelf = true) { |
|
166 | - if (is_dir($dir)) { |
|
167 | - $files = new RecursiveIteratorIterator( |
|
168 | - new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), |
|
169 | - RecursiveIteratorIterator::CHILD_FIRST |
|
170 | - ); |
|
171 | - |
|
172 | - foreach ($files as $fileInfo) { |
|
173 | - /** @var SplFileInfo $fileInfo */ |
|
174 | - if ($fileInfo->isLink()) { |
|
175 | - unlink($fileInfo->getPathname()); |
|
176 | - } elseif ($fileInfo->isDir()) { |
|
177 | - rmdir($fileInfo->getRealPath()); |
|
178 | - } else { |
|
179 | - unlink($fileInfo->getRealPath()); |
|
180 | - } |
|
181 | - } |
|
182 | - if ($deleteSelf) { |
|
183 | - rmdir($dir); |
|
184 | - } |
|
185 | - } elseif (file_exists($dir)) { |
|
186 | - if ($deleteSelf) { |
|
187 | - unlink($dir); |
|
188 | - } |
|
189 | - } |
|
190 | - if (!$deleteSelf) { |
|
191 | - return true; |
|
192 | - } |
|
193 | - |
|
194 | - return !file_exists($dir); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @deprecated 18.0.0 |
|
199 | - * @return \OC\Files\Type\TemplateManager |
|
200 | - */ |
|
201 | - public static function getFileTemplateManager() { |
|
202 | - if (!self::$templateManager) { |
|
203 | - self::$templateManager = new \OC\Files\Type\TemplateManager(); |
|
204 | - } |
|
205 | - return self::$templateManager; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * detect if a given program is found in the search PATH |
|
210 | - * |
|
211 | - * @param string $name |
|
212 | - * @param bool $path |
|
213 | - * @internal param string $program name |
|
214 | - * @internal param string $optional search path, defaults to $PATH |
|
215 | - * @return bool true if executable program found in path |
|
216 | - */ |
|
217 | - public static function canExecute($name, $path = false) { |
|
218 | - // path defaults to PATH from environment if not set |
|
219 | - if ($path === false) { |
|
220 | - $path = getenv("PATH"); |
|
221 | - } |
|
222 | - // we look for an executable file of that name |
|
223 | - $exts = [""]; |
|
224 | - $check_fn = "is_executable"; |
|
225 | - // Default check will be done with $path directories : |
|
226 | - $dirs = explode(PATH_SEPARATOR, $path); |
|
227 | - // WARNING : We have to check if open_basedir is enabled : |
|
228 | - $obd = OC::$server->get(IniGetWrapper::class)->getString('open_basedir'); |
|
229 | - if ($obd != "none") { |
|
230 | - $obd_values = explode(PATH_SEPARATOR, $obd); |
|
231 | - if (count($obd_values) > 0 and $obd_values[0]) { |
|
232 | - // open_basedir is in effect ! |
|
233 | - // We need to check if the program is in one of these dirs : |
|
234 | - $dirs = $obd_values; |
|
235 | - } |
|
236 | - } |
|
237 | - foreach ($dirs as $dir) { |
|
238 | - foreach ($exts as $ext) { |
|
239 | - if ($check_fn("$dir/$name" . $ext)) { |
|
240 | - return true; |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - return false; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * copy the contents of one stream to another |
|
249 | - * |
|
250 | - * @param resource $source |
|
251 | - * @param resource $target |
|
252 | - * @return array the number of bytes copied and result |
|
253 | - */ |
|
254 | - public static function streamCopy($source, $target) { |
|
255 | - if (!$source or !$target) { |
|
256 | - return [0, false]; |
|
257 | - } |
|
258 | - $bufSize = 8192; |
|
259 | - $result = true; |
|
260 | - $count = 0; |
|
261 | - while (!feof($source)) { |
|
262 | - $buf = fread($source, $bufSize); |
|
263 | - $bytesWritten = fwrite($target, $buf); |
|
264 | - if ($bytesWritten !== false) { |
|
265 | - $count += $bytesWritten; |
|
266 | - } |
|
267 | - // note: strlen is expensive so only use it when necessary, |
|
268 | - // on the last block |
|
269 | - if ($bytesWritten === false |
|
270 | - || ($bytesWritten < $bufSize && $bytesWritten < strlen($buf)) |
|
271 | - ) { |
|
272 | - // write error, could be disk full ? |
|
273 | - $result = false; |
|
274 | - break; |
|
275 | - } |
|
276 | - } |
|
277 | - return [$count, $result]; |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Adds a suffix to the name in case the file exists |
|
282 | - * |
|
283 | - * @param string $path |
|
284 | - * @param string $filename |
|
285 | - * @return string |
|
286 | - */ |
|
287 | - public static function buildNotExistingFileName($path, $filename) { |
|
288 | - $view = \OC\Files\Filesystem::getView(); |
|
289 | - return self::buildNotExistingFileNameForView($path, $filename, $view); |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Adds a suffix to the name in case the file exists |
|
294 | - * |
|
295 | - * @param string $path |
|
296 | - * @param string $filename |
|
297 | - * @return string |
|
298 | - */ |
|
299 | - public static function buildNotExistingFileNameForView($path, $filename, \OC\Files\View $view) { |
|
300 | - if ($path === '/') { |
|
301 | - $path = ''; |
|
302 | - } |
|
303 | - if ($pos = strrpos($filename, '.')) { |
|
304 | - $name = substr($filename, 0, $pos); |
|
305 | - $ext = substr($filename, $pos); |
|
306 | - } else { |
|
307 | - $name = $filename; |
|
308 | - $ext = ''; |
|
309 | - } |
|
310 | - |
|
311 | - $newpath = $path . '/' . $filename; |
|
312 | - if ($view->file_exists($newpath)) { |
|
313 | - if (preg_match_all('/\((\d+)\)/', $name, $matches, PREG_OFFSET_CAPTURE)) { |
|
314 | - //Replace the last "(number)" with "(number+1)" |
|
315 | - $last_match = count($matches[0]) - 1; |
|
316 | - $counter = $matches[1][$last_match][0] + 1; |
|
317 | - $offset = $matches[0][$last_match][1]; |
|
318 | - $match_length = strlen($matches[0][$last_match][0]); |
|
319 | - } else { |
|
320 | - $counter = 2; |
|
321 | - $match_length = 0; |
|
322 | - $offset = false; |
|
323 | - } |
|
324 | - do { |
|
325 | - if ($offset) { |
|
326 | - //Replace the last "(number)" with "(number+1)" |
|
327 | - $newname = substr_replace($name, '(' . $counter . ')', $offset, $match_length); |
|
328 | - } else { |
|
329 | - $newname = $name . ' (' . $counter . ')'; |
|
330 | - } |
|
331 | - $newpath = $path . '/' . $newname . $ext; |
|
332 | - $counter++; |
|
333 | - } while ($view->file_exists($newpath)); |
|
334 | - } |
|
335 | - |
|
336 | - return $newpath; |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. |
|
341 | - * |
|
342 | - * @param array $input The array to work on |
|
343 | - * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) |
|
344 | - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
345 | - * @return array |
|
346 | - * |
|
347 | - * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. |
|
348 | - * based on https://www.php.net/manual/en/function.array-change-key-case.php#107715 |
|
349 | - * |
|
350 | - */ |
|
351 | - public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { |
|
352 | - $case = ($case != MB_CASE_UPPER) ? MB_CASE_LOWER : MB_CASE_UPPER; |
|
353 | - $ret = []; |
|
354 | - foreach ($input as $k => $v) { |
|
355 | - $ret[mb_convert_case($k, $case, $encoding)] = $v; |
|
356 | - } |
|
357 | - return $ret; |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * performs a search in a nested array |
|
362 | - * @param array $haystack the array to be searched |
|
363 | - * @param string $needle the search string |
|
364 | - * @param mixed $index optional, only search this key name |
|
365 | - * @return mixed the key of the matching field, otherwise false |
|
366 | - * |
|
367 | - * performs a search in a nested array |
|
368 | - * |
|
369 | - * taken from https://www.php.net/manual/en/function.array-search.php#97645 |
|
370 | - */ |
|
371 | - public static function recursiveArraySearch($haystack, $needle, $index = null) { |
|
372 | - $aIt = new RecursiveArrayIterator($haystack); |
|
373 | - $it = new RecursiveIteratorIterator($aIt); |
|
374 | - |
|
375 | - while ($it->valid()) { |
|
376 | - if (((isset($index) and ($it->key() == $index)) or !isset($index)) and ($it->current() == $needle)) { |
|
377 | - return $aIt->key(); |
|
378 | - } |
|
379 | - |
|
380 | - $it->next(); |
|
381 | - } |
|
382 | - |
|
383 | - return false; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * calculates the maximum upload size respecting system settings, free space and user quota |
|
388 | - * |
|
389 | - * @param string $dir the current folder where the user currently operates |
|
390 | - * @param int $freeSpace the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly |
|
391 | - * @return int number of bytes representing |
|
392 | - */ |
|
393 | - public static function maxUploadFilesize($dir, $freeSpace = null) { |
|
394 | - if (is_null($freeSpace) || $freeSpace < 0) { |
|
395 | - $freeSpace = self::freeSpace($dir); |
|
396 | - } |
|
397 | - return min($freeSpace, self::uploadLimit()); |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * Calculate free space left within user quota |
|
402 | - * |
|
403 | - * @param string $dir the current folder where the user currently operates |
|
404 | - * @return int number of bytes representing |
|
405 | - */ |
|
406 | - public static function freeSpace($dir) { |
|
407 | - $freeSpace = \OC\Files\Filesystem::free_space($dir); |
|
408 | - if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
409 | - $freeSpace = max($freeSpace, 0); |
|
410 | - return $freeSpace; |
|
411 | - } else { |
|
412 | - return (INF > 0)? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188 |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Calculate PHP upload limit |
|
418 | - * |
|
419 | - * @return int PHP upload file size limit |
|
420 | - */ |
|
421 | - public static function uploadLimit() { |
|
422 | - $ini = \OC::$server->get(IniGetWrapper::class); |
|
423 | - $upload_max_filesize = (int)OCP\Util::computerFileSize($ini->get('upload_max_filesize')); |
|
424 | - $post_max_size = (int)OCP\Util::computerFileSize($ini->get('post_max_size')); |
|
425 | - if ($upload_max_filesize === 0 && $post_max_size === 0) { |
|
426 | - return INF; |
|
427 | - } elseif ($upload_max_filesize === 0 || $post_max_size === 0) { |
|
428 | - return max($upload_max_filesize, $post_max_size); //only the non 0 value counts |
|
429 | - } else { |
|
430 | - return min($upload_max_filesize, $post_max_size); |
|
431 | - } |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Checks if a function is available |
|
436 | - * |
|
437 | - * @deprecated Since 25.0.0 use \OCP\Util::isFunctionEnabled instead |
|
438 | - */ |
|
439 | - public static function is_function_enabled(string $function_name): bool { |
|
440 | - return \OCP\Util::isFunctionEnabled($function_name); |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Try to find a program |
|
445 | - * @deprecated Since 25.0.0 Use \OC\BinaryFinder directly |
|
446 | - */ |
|
447 | - public static function findBinaryPath(string $program): ?string { |
|
448 | - $result = \OCP\Server::get(IBinaryFinder::class)->findBinaryPath($program); |
|
449 | - return $result !== false ? $result : null; |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * Calculate the disc space for the given path |
|
454 | - * |
|
455 | - * BEWARE: this requires that Util::setupFS() was called |
|
456 | - * already ! |
|
457 | - * |
|
458 | - * @param string $path |
|
459 | - * @param \OCP\Files\FileInfo $rootInfo (optional) |
|
460 | - * @param bool $includeMountPoints whether to include mount points in the size calculation |
|
461 | - * @param bool $useCache whether to use the cached quota values |
|
462 | - * @return array |
|
463 | - * @throws \OCP\Files\NotFoundException |
|
464 | - */ |
|
465 | - public static function getStorageInfo($path, $rootInfo = null, $includeMountPoints = true, $useCache = true) { |
|
466 | - /** @var ICacheFactory $cacheFactory */ |
|
467 | - $cacheFactory = \OC::$server->get(ICacheFactory::class); |
|
468 | - $memcache = $cacheFactory->createLocal('storage_info'); |
|
469 | - |
|
470 | - // return storage info without adding mount points |
|
471 | - $includeExtStorage = \OC::$server->getSystemConfig()->getValue('quota_include_external_storage', false); |
|
472 | - |
|
473 | - $view = Filesystem::getView(); |
|
474 | - if (!$view) { |
|
475 | - throw new \OCP\Files\NotFoundException(); |
|
476 | - } |
|
477 | - $fullPath = $view->getAbsolutePath($path); |
|
478 | - |
|
479 | - $cacheKey = $fullPath. '::' . ($includeMountPoints ? 'include' : 'exclude'); |
|
480 | - if ($useCache) { |
|
481 | - $cached = $memcache->get($cacheKey); |
|
482 | - if ($cached) { |
|
483 | - return $cached; |
|
484 | - } |
|
485 | - } |
|
486 | - |
|
487 | - if (!$rootInfo) { |
|
488 | - $rootInfo = \OC\Files\Filesystem::getFileInfo($path, $includeExtStorage ? 'ext' : false); |
|
489 | - } |
|
490 | - if (!$rootInfo instanceof \OCP\Files\FileInfo) { |
|
491 | - throw new \OCP\Files\NotFoundException(); |
|
492 | - } |
|
493 | - $used = $rootInfo->getSize($includeMountPoints); |
|
494 | - if ($used < 0) { |
|
495 | - $used = 0; |
|
496 | - } |
|
497 | - $quota = \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
498 | - $mount = $rootInfo->getMountPoint(); |
|
499 | - $storage = $mount->getStorage(); |
|
500 | - $sourceStorage = $storage; |
|
501 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
502 | - $includeExtStorage = false; |
|
503 | - } |
|
504 | - if ($includeExtStorage) { |
|
505 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
506 | - || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
507 | - ) { |
|
508 | - /** @var \OC\Files\Storage\Home $storage */ |
|
509 | - $user = $storage->getUser(); |
|
510 | - } else { |
|
511 | - $user = \OC::$server->getUserSession()->getUser(); |
|
512 | - } |
|
513 | - $quota = OC_Util::getUserQuota($user); |
|
514 | - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
515 | - // always get free space / total space from root + mount points |
|
516 | - return self::getGlobalStorageInfo($quota, $user, $mount); |
|
517 | - } |
|
518 | - } |
|
519 | - |
|
520 | - // TODO: need a better way to get total space from storage |
|
521 | - if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) { |
|
522 | - /** @var \OC\Files\Storage\Wrapper\Quota $storage */ |
|
523 | - $quota = $sourceStorage->getQuota(); |
|
524 | - } |
|
525 | - try { |
|
526 | - $free = $sourceStorage->free_space($rootInfo->getInternalPath()); |
|
527 | - } catch (\Exception $e) { |
|
528 | - if ($path === "") { |
|
529 | - throw $e; |
|
530 | - } |
|
531 | - /** @var LoggerInterface $logger */ |
|
532 | - $logger = \OC::$server->get(LoggerInterface::class); |
|
533 | - $logger->warning("Error while getting quota info, using root quota", ['exception' => $e]); |
|
534 | - $rootInfo = self::getStorageInfo(""); |
|
535 | - $memcache->set($cacheKey, $rootInfo, 5 * 60); |
|
536 | - return $rootInfo; |
|
537 | - } |
|
538 | - if ($free >= 0) { |
|
539 | - $total = $free + $used; |
|
540 | - } else { |
|
541 | - $total = $free; //either unknown or unlimited |
|
542 | - } |
|
543 | - if ($total > 0) { |
|
544 | - if ($quota > 0 && $total > $quota) { |
|
545 | - $total = $quota; |
|
546 | - } |
|
547 | - // prevent division by zero or error codes (negative values) |
|
548 | - $relative = round(($used / $total) * 10000) / 100; |
|
549 | - } else { |
|
550 | - $relative = 0; |
|
551 | - } |
|
552 | - |
|
553 | - $ownerId = $storage->getOwner($path); |
|
554 | - $ownerDisplayName = ''; |
|
555 | - if ($ownerId) { |
|
556 | - $ownerDisplayName = \OC::$server->getUserManager()->getDisplayName($ownerId) ?? ''; |
|
557 | - } |
|
558 | - |
|
559 | - if (substr_count($mount->getMountPoint(), '/') < 3) { |
|
560 | - $mountPoint = ''; |
|
561 | - } else { |
|
562 | - [,,,$mountPoint] = explode('/', $mount->getMountPoint(), 4); |
|
563 | - } |
|
564 | - |
|
565 | - $info = [ |
|
566 | - 'free' => $free, |
|
567 | - 'used' => $used, |
|
568 | - 'quota' => $quota, |
|
569 | - 'total' => $total, |
|
570 | - 'relative' => $relative, |
|
571 | - 'owner' => $ownerId, |
|
572 | - 'ownerDisplayName' => $ownerDisplayName, |
|
573 | - 'mountType' => $mount->getMountType(), |
|
574 | - 'mountPoint' => trim($mountPoint, '/'), |
|
575 | - ]; |
|
576 | - |
|
577 | - $memcache->set($cacheKey, $info, 5 * 60); |
|
578 | - |
|
579 | - return $info; |
|
580 | - } |
|
581 | - |
|
582 | - /** |
|
583 | - * Get storage info including all mount points and quota |
|
584 | - */ |
|
585 | - private static function getGlobalStorageInfo(int $quota, IUser $user, IMountPoint $mount): array { |
|
586 | - $rootInfo = \OC\Files\Filesystem::getFileInfo('', 'ext'); |
|
587 | - $used = $rootInfo['size']; |
|
588 | - if ($used < 0) { |
|
589 | - $used = 0; |
|
590 | - } |
|
591 | - |
|
592 | - $total = $quota; |
|
593 | - $free = $quota - $used; |
|
594 | - |
|
595 | - if ($total > 0) { |
|
596 | - if ($quota > 0 && $total > $quota) { |
|
597 | - $total = $quota; |
|
598 | - } |
|
599 | - // prevent division by zero or error codes (negative values) |
|
600 | - $relative = round(($used / $total) * 10000) / 100; |
|
601 | - } else { |
|
602 | - $relative = 0; |
|
603 | - } |
|
604 | - |
|
605 | - if (substr_count($mount->getMountPoint(), '/') < 3) { |
|
606 | - $mountPoint = ''; |
|
607 | - } else { |
|
608 | - [,,,$mountPoint] = explode('/', $mount->getMountPoint(), 4); |
|
609 | - } |
|
610 | - |
|
611 | - return [ |
|
612 | - 'free' => $free, |
|
613 | - 'used' => $used, |
|
614 | - 'total' => $total, |
|
615 | - 'relative' => $relative, |
|
616 | - 'quota' => $quota, |
|
617 | - 'owner' => $user->getUID(), |
|
618 | - 'ownerDisplayName' => $user->getDisplayName(), |
|
619 | - 'mountType' => $mount->getMountType(), |
|
620 | - 'mountPoint' => trim($mountPoint, '/'), |
|
621 | - ]; |
|
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * Returns whether the config file is set manually to read-only |
|
626 | - * @return bool |
|
627 | - */ |
|
628 | - public static function isReadOnlyConfigEnabled() { |
|
629 | - return \OC::$server->getConfig()->getSystemValue('config_is_read_only', false); |
|
630 | - } |
|
58 | + private static $templateManager; |
|
59 | + |
|
60 | + /** |
|
61 | + * Make a human file size |
|
62 | + * @param int $bytes file size in bytes |
|
63 | + * @return string a human readable file size |
|
64 | + * |
|
65 | + * Makes 2048 to 2 kB. |
|
66 | + */ |
|
67 | + public static function humanFileSize($bytes) { |
|
68 | + if ($bytes < 0) { |
|
69 | + return "?"; |
|
70 | + } |
|
71 | + if ($bytes < 1024) { |
|
72 | + return "$bytes B"; |
|
73 | + } |
|
74 | + $bytes = round($bytes / 1024, 0); |
|
75 | + if ($bytes < 1024) { |
|
76 | + return "$bytes KB"; |
|
77 | + } |
|
78 | + $bytes = round($bytes / 1024, 1); |
|
79 | + if ($bytes < 1024) { |
|
80 | + return "$bytes MB"; |
|
81 | + } |
|
82 | + $bytes = round($bytes / 1024, 1); |
|
83 | + if ($bytes < 1024) { |
|
84 | + return "$bytes GB"; |
|
85 | + } |
|
86 | + $bytes = round($bytes / 1024, 1); |
|
87 | + if ($bytes < 1024) { |
|
88 | + return "$bytes TB"; |
|
89 | + } |
|
90 | + |
|
91 | + $bytes = round($bytes / 1024, 1); |
|
92 | + return "$bytes PB"; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Make a computer file size |
|
97 | + * @param string $str file size in human readable format |
|
98 | + * @return int|false a file size in bytes |
|
99 | + * |
|
100 | + * Makes 2kB to 2048. |
|
101 | + * |
|
102 | + * Inspired by: https://www.php.net/manual/en/function.filesize.php#92418 |
|
103 | + */ |
|
104 | + public static function computerFileSize($str) { |
|
105 | + $str = strtolower($str); |
|
106 | + if (is_numeric($str)) { |
|
107 | + return (int)$str; |
|
108 | + } |
|
109 | + |
|
110 | + $bytes_array = [ |
|
111 | + 'b' => 1, |
|
112 | + 'k' => 1024, |
|
113 | + 'kb' => 1024, |
|
114 | + 'mb' => 1024 * 1024, |
|
115 | + 'm' => 1024 * 1024, |
|
116 | + 'gb' => 1024 * 1024 * 1024, |
|
117 | + 'g' => 1024 * 1024 * 1024, |
|
118 | + 'tb' => 1024 * 1024 * 1024 * 1024, |
|
119 | + 't' => 1024 * 1024 * 1024 * 1024, |
|
120 | + 'pb' => 1024 * 1024 * 1024 * 1024 * 1024, |
|
121 | + 'p' => 1024 * 1024 * 1024 * 1024 * 1024, |
|
122 | + ]; |
|
123 | + |
|
124 | + $bytes = (float)$str; |
|
125 | + |
|
126 | + if (preg_match('#([kmgtp]?b?)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) { |
|
127 | + $bytes *= $bytes_array[$matches[1]]; |
|
128 | + } else { |
|
129 | + return false; |
|
130 | + } |
|
131 | + |
|
132 | + $bytes = round($bytes); |
|
133 | + |
|
134 | + return (int)$bytes; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Recursive copying of folders |
|
139 | + * @param string $src source folder |
|
140 | + * @param string $dest target folder |
|
141 | + * |
|
142 | + */ |
|
143 | + public static function copyr($src, $dest) { |
|
144 | + if (is_dir($src)) { |
|
145 | + if (!is_dir($dest)) { |
|
146 | + mkdir($dest); |
|
147 | + } |
|
148 | + $files = scandir($src); |
|
149 | + foreach ($files as $file) { |
|
150 | + if ($file != "." && $file != "..") { |
|
151 | + self::copyr("$src/$file", "$dest/$file"); |
|
152 | + } |
|
153 | + } |
|
154 | + } elseif (file_exists($src) && !\OC\Files\Filesystem::isFileBlacklisted($src)) { |
|
155 | + copy($src, $dest); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Recursive deletion of folders |
|
161 | + * @param string $dir path to the folder |
|
162 | + * @param bool $deleteSelf if set to false only the content of the folder will be deleted |
|
163 | + * @return bool |
|
164 | + */ |
|
165 | + public static function rmdirr($dir, $deleteSelf = true) { |
|
166 | + if (is_dir($dir)) { |
|
167 | + $files = new RecursiveIteratorIterator( |
|
168 | + new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), |
|
169 | + RecursiveIteratorIterator::CHILD_FIRST |
|
170 | + ); |
|
171 | + |
|
172 | + foreach ($files as $fileInfo) { |
|
173 | + /** @var SplFileInfo $fileInfo */ |
|
174 | + if ($fileInfo->isLink()) { |
|
175 | + unlink($fileInfo->getPathname()); |
|
176 | + } elseif ($fileInfo->isDir()) { |
|
177 | + rmdir($fileInfo->getRealPath()); |
|
178 | + } else { |
|
179 | + unlink($fileInfo->getRealPath()); |
|
180 | + } |
|
181 | + } |
|
182 | + if ($deleteSelf) { |
|
183 | + rmdir($dir); |
|
184 | + } |
|
185 | + } elseif (file_exists($dir)) { |
|
186 | + if ($deleteSelf) { |
|
187 | + unlink($dir); |
|
188 | + } |
|
189 | + } |
|
190 | + if (!$deleteSelf) { |
|
191 | + return true; |
|
192 | + } |
|
193 | + |
|
194 | + return !file_exists($dir); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @deprecated 18.0.0 |
|
199 | + * @return \OC\Files\Type\TemplateManager |
|
200 | + */ |
|
201 | + public static function getFileTemplateManager() { |
|
202 | + if (!self::$templateManager) { |
|
203 | + self::$templateManager = new \OC\Files\Type\TemplateManager(); |
|
204 | + } |
|
205 | + return self::$templateManager; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * detect if a given program is found in the search PATH |
|
210 | + * |
|
211 | + * @param string $name |
|
212 | + * @param bool $path |
|
213 | + * @internal param string $program name |
|
214 | + * @internal param string $optional search path, defaults to $PATH |
|
215 | + * @return bool true if executable program found in path |
|
216 | + */ |
|
217 | + public static function canExecute($name, $path = false) { |
|
218 | + // path defaults to PATH from environment if not set |
|
219 | + if ($path === false) { |
|
220 | + $path = getenv("PATH"); |
|
221 | + } |
|
222 | + // we look for an executable file of that name |
|
223 | + $exts = [""]; |
|
224 | + $check_fn = "is_executable"; |
|
225 | + // Default check will be done with $path directories : |
|
226 | + $dirs = explode(PATH_SEPARATOR, $path); |
|
227 | + // WARNING : We have to check if open_basedir is enabled : |
|
228 | + $obd = OC::$server->get(IniGetWrapper::class)->getString('open_basedir'); |
|
229 | + if ($obd != "none") { |
|
230 | + $obd_values = explode(PATH_SEPARATOR, $obd); |
|
231 | + if (count($obd_values) > 0 and $obd_values[0]) { |
|
232 | + // open_basedir is in effect ! |
|
233 | + // We need to check if the program is in one of these dirs : |
|
234 | + $dirs = $obd_values; |
|
235 | + } |
|
236 | + } |
|
237 | + foreach ($dirs as $dir) { |
|
238 | + foreach ($exts as $ext) { |
|
239 | + if ($check_fn("$dir/$name" . $ext)) { |
|
240 | + return true; |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | + return false; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * copy the contents of one stream to another |
|
249 | + * |
|
250 | + * @param resource $source |
|
251 | + * @param resource $target |
|
252 | + * @return array the number of bytes copied and result |
|
253 | + */ |
|
254 | + public static function streamCopy($source, $target) { |
|
255 | + if (!$source or !$target) { |
|
256 | + return [0, false]; |
|
257 | + } |
|
258 | + $bufSize = 8192; |
|
259 | + $result = true; |
|
260 | + $count = 0; |
|
261 | + while (!feof($source)) { |
|
262 | + $buf = fread($source, $bufSize); |
|
263 | + $bytesWritten = fwrite($target, $buf); |
|
264 | + if ($bytesWritten !== false) { |
|
265 | + $count += $bytesWritten; |
|
266 | + } |
|
267 | + // note: strlen is expensive so only use it when necessary, |
|
268 | + // on the last block |
|
269 | + if ($bytesWritten === false |
|
270 | + || ($bytesWritten < $bufSize && $bytesWritten < strlen($buf)) |
|
271 | + ) { |
|
272 | + // write error, could be disk full ? |
|
273 | + $result = false; |
|
274 | + break; |
|
275 | + } |
|
276 | + } |
|
277 | + return [$count, $result]; |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Adds a suffix to the name in case the file exists |
|
282 | + * |
|
283 | + * @param string $path |
|
284 | + * @param string $filename |
|
285 | + * @return string |
|
286 | + */ |
|
287 | + public static function buildNotExistingFileName($path, $filename) { |
|
288 | + $view = \OC\Files\Filesystem::getView(); |
|
289 | + return self::buildNotExistingFileNameForView($path, $filename, $view); |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Adds a suffix to the name in case the file exists |
|
294 | + * |
|
295 | + * @param string $path |
|
296 | + * @param string $filename |
|
297 | + * @return string |
|
298 | + */ |
|
299 | + public static function buildNotExistingFileNameForView($path, $filename, \OC\Files\View $view) { |
|
300 | + if ($path === '/') { |
|
301 | + $path = ''; |
|
302 | + } |
|
303 | + if ($pos = strrpos($filename, '.')) { |
|
304 | + $name = substr($filename, 0, $pos); |
|
305 | + $ext = substr($filename, $pos); |
|
306 | + } else { |
|
307 | + $name = $filename; |
|
308 | + $ext = ''; |
|
309 | + } |
|
310 | + |
|
311 | + $newpath = $path . '/' . $filename; |
|
312 | + if ($view->file_exists($newpath)) { |
|
313 | + if (preg_match_all('/\((\d+)\)/', $name, $matches, PREG_OFFSET_CAPTURE)) { |
|
314 | + //Replace the last "(number)" with "(number+1)" |
|
315 | + $last_match = count($matches[0]) - 1; |
|
316 | + $counter = $matches[1][$last_match][0] + 1; |
|
317 | + $offset = $matches[0][$last_match][1]; |
|
318 | + $match_length = strlen($matches[0][$last_match][0]); |
|
319 | + } else { |
|
320 | + $counter = 2; |
|
321 | + $match_length = 0; |
|
322 | + $offset = false; |
|
323 | + } |
|
324 | + do { |
|
325 | + if ($offset) { |
|
326 | + //Replace the last "(number)" with "(number+1)" |
|
327 | + $newname = substr_replace($name, '(' . $counter . ')', $offset, $match_length); |
|
328 | + } else { |
|
329 | + $newname = $name . ' (' . $counter . ')'; |
|
330 | + } |
|
331 | + $newpath = $path . '/' . $newname . $ext; |
|
332 | + $counter++; |
|
333 | + } while ($view->file_exists($newpath)); |
|
334 | + } |
|
335 | + |
|
336 | + return $newpath; |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. |
|
341 | + * |
|
342 | + * @param array $input The array to work on |
|
343 | + * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) |
|
344 | + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
345 | + * @return array |
|
346 | + * |
|
347 | + * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. |
|
348 | + * based on https://www.php.net/manual/en/function.array-change-key-case.php#107715 |
|
349 | + * |
|
350 | + */ |
|
351 | + public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { |
|
352 | + $case = ($case != MB_CASE_UPPER) ? MB_CASE_LOWER : MB_CASE_UPPER; |
|
353 | + $ret = []; |
|
354 | + foreach ($input as $k => $v) { |
|
355 | + $ret[mb_convert_case($k, $case, $encoding)] = $v; |
|
356 | + } |
|
357 | + return $ret; |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * performs a search in a nested array |
|
362 | + * @param array $haystack the array to be searched |
|
363 | + * @param string $needle the search string |
|
364 | + * @param mixed $index optional, only search this key name |
|
365 | + * @return mixed the key of the matching field, otherwise false |
|
366 | + * |
|
367 | + * performs a search in a nested array |
|
368 | + * |
|
369 | + * taken from https://www.php.net/manual/en/function.array-search.php#97645 |
|
370 | + */ |
|
371 | + public static function recursiveArraySearch($haystack, $needle, $index = null) { |
|
372 | + $aIt = new RecursiveArrayIterator($haystack); |
|
373 | + $it = new RecursiveIteratorIterator($aIt); |
|
374 | + |
|
375 | + while ($it->valid()) { |
|
376 | + if (((isset($index) and ($it->key() == $index)) or !isset($index)) and ($it->current() == $needle)) { |
|
377 | + return $aIt->key(); |
|
378 | + } |
|
379 | + |
|
380 | + $it->next(); |
|
381 | + } |
|
382 | + |
|
383 | + return false; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * calculates the maximum upload size respecting system settings, free space and user quota |
|
388 | + * |
|
389 | + * @param string $dir the current folder where the user currently operates |
|
390 | + * @param int $freeSpace the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly |
|
391 | + * @return int number of bytes representing |
|
392 | + */ |
|
393 | + public static function maxUploadFilesize($dir, $freeSpace = null) { |
|
394 | + if (is_null($freeSpace) || $freeSpace < 0) { |
|
395 | + $freeSpace = self::freeSpace($dir); |
|
396 | + } |
|
397 | + return min($freeSpace, self::uploadLimit()); |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * Calculate free space left within user quota |
|
402 | + * |
|
403 | + * @param string $dir the current folder where the user currently operates |
|
404 | + * @return int number of bytes representing |
|
405 | + */ |
|
406 | + public static function freeSpace($dir) { |
|
407 | + $freeSpace = \OC\Files\Filesystem::free_space($dir); |
|
408 | + if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
409 | + $freeSpace = max($freeSpace, 0); |
|
410 | + return $freeSpace; |
|
411 | + } else { |
|
412 | + return (INF > 0)? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188 |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Calculate PHP upload limit |
|
418 | + * |
|
419 | + * @return int PHP upload file size limit |
|
420 | + */ |
|
421 | + public static function uploadLimit() { |
|
422 | + $ini = \OC::$server->get(IniGetWrapper::class); |
|
423 | + $upload_max_filesize = (int)OCP\Util::computerFileSize($ini->get('upload_max_filesize')); |
|
424 | + $post_max_size = (int)OCP\Util::computerFileSize($ini->get('post_max_size')); |
|
425 | + if ($upload_max_filesize === 0 && $post_max_size === 0) { |
|
426 | + return INF; |
|
427 | + } elseif ($upload_max_filesize === 0 || $post_max_size === 0) { |
|
428 | + return max($upload_max_filesize, $post_max_size); //only the non 0 value counts |
|
429 | + } else { |
|
430 | + return min($upload_max_filesize, $post_max_size); |
|
431 | + } |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Checks if a function is available |
|
436 | + * |
|
437 | + * @deprecated Since 25.0.0 use \OCP\Util::isFunctionEnabled instead |
|
438 | + */ |
|
439 | + public static function is_function_enabled(string $function_name): bool { |
|
440 | + return \OCP\Util::isFunctionEnabled($function_name); |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Try to find a program |
|
445 | + * @deprecated Since 25.0.0 Use \OC\BinaryFinder directly |
|
446 | + */ |
|
447 | + public static function findBinaryPath(string $program): ?string { |
|
448 | + $result = \OCP\Server::get(IBinaryFinder::class)->findBinaryPath($program); |
|
449 | + return $result !== false ? $result : null; |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * Calculate the disc space for the given path |
|
454 | + * |
|
455 | + * BEWARE: this requires that Util::setupFS() was called |
|
456 | + * already ! |
|
457 | + * |
|
458 | + * @param string $path |
|
459 | + * @param \OCP\Files\FileInfo $rootInfo (optional) |
|
460 | + * @param bool $includeMountPoints whether to include mount points in the size calculation |
|
461 | + * @param bool $useCache whether to use the cached quota values |
|
462 | + * @return array |
|
463 | + * @throws \OCP\Files\NotFoundException |
|
464 | + */ |
|
465 | + public static function getStorageInfo($path, $rootInfo = null, $includeMountPoints = true, $useCache = true) { |
|
466 | + /** @var ICacheFactory $cacheFactory */ |
|
467 | + $cacheFactory = \OC::$server->get(ICacheFactory::class); |
|
468 | + $memcache = $cacheFactory->createLocal('storage_info'); |
|
469 | + |
|
470 | + // return storage info without adding mount points |
|
471 | + $includeExtStorage = \OC::$server->getSystemConfig()->getValue('quota_include_external_storage', false); |
|
472 | + |
|
473 | + $view = Filesystem::getView(); |
|
474 | + if (!$view) { |
|
475 | + throw new \OCP\Files\NotFoundException(); |
|
476 | + } |
|
477 | + $fullPath = $view->getAbsolutePath($path); |
|
478 | + |
|
479 | + $cacheKey = $fullPath. '::' . ($includeMountPoints ? 'include' : 'exclude'); |
|
480 | + if ($useCache) { |
|
481 | + $cached = $memcache->get($cacheKey); |
|
482 | + if ($cached) { |
|
483 | + return $cached; |
|
484 | + } |
|
485 | + } |
|
486 | + |
|
487 | + if (!$rootInfo) { |
|
488 | + $rootInfo = \OC\Files\Filesystem::getFileInfo($path, $includeExtStorage ? 'ext' : false); |
|
489 | + } |
|
490 | + if (!$rootInfo instanceof \OCP\Files\FileInfo) { |
|
491 | + throw new \OCP\Files\NotFoundException(); |
|
492 | + } |
|
493 | + $used = $rootInfo->getSize($includeMountPoints); |
|
494 | + if ($used < 0) { |
|
495 | + $used = 0; |
|
496 | + } |
|
497 | + $quota = \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
498 | + $mount = $rootInfo->getMountPoint(); |
|
499 | + $storage = $mount->getStorage(); |
|
500 | + $sourceStorage = $storage; |
|
501 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
502 | + $includeExtStorage = false; |
|
503 | + } |
|
504 | + if ($includeExtStorage) { |
|
505 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
506 | + || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
507 | + ) { |
|
508 | + /** @var \OC\Files\Storage\Home $storage */ |
|
509 | + $user = $storage->getUser(); |
|
510 | + } else { |
|
511 | + $user = \OC::$server->getUserSession()->getUser(); |
|
512 | + } |
|
513 | + $quota = OC_Util::getUserQuota($user); |
|
514 | + if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
515 | + // always get free space / total space from root + mount points |
|
516 | + return self::getGlobalStorageInfo($quota, $user, $mount); |
|
517 | + } |
|
518 | + } |
|
519 | + |
|
520 | + // TODO: need a better way to get total space from storage |
|
521 | + if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) { |
|
522 | + /** @var \OC\Files\Storage\Wrapper\Quota $storage */ |
|
523 | + $quota = $sourceStorage->getQuota(); |
|
524 | + } |
|
525 | + try { |
|
526 | + $free = $sourceStorage->free_space($rootInfo->getInternalPath()); |
|
527 | + } catch (\Exception $e) { |
|
528 | + if ($path === "") { |
|
529 | + throw $e; |
|
530 | + } |
|
531 | + /** @var LoggerInterface $logger */ |
|
532 | + $logger = \OC::$server->get(LoggerInterface::class); |
|
533 | + $logger->warning("Error while getting quota info, using root quota", ['exception' => $e]); |
|
534 | + $rootInfo = self::getStorageInfo(""); |
|
535 | + $memcache->set($cacheKey, $rootInfo, 5 * 60); |
|
536 | + return $rootInfo; |
|
537 | + } |
|
538 | + if ($free >= 0) { |
|
539 | + $total = $free + $used; |
|
540 | + } else { |
|
541 | + $total = $free; //either unknown or unlimited |
|
542 | + } |
|
543 | + if ($total > 0) { |
|
544 | + if ($quota > 0 && $total > $quota) { |
|
545 | + $total = $quota; |
|
546 | + } |
|
547 | + // prevent division by zero or error codes (negative values) |
|
548 | + $relative = round(($used / $total) * 10000) / 100; |
|
549 | + } else { |
|
550 | + $relative = 0; |
|
551 | + } |
|
552 | + |
|
553 | + $ownerId = $storage->getOwner($path); |
|
554 | + $ownerDisplayName = ''; |
|
555 | + if ($ownerId) { |
|
556 | + $ownerDisplayName = \OC::$server->getUserManager()->getDisplayName($ownerId) ?? ''; |
|
557 | + } |
|
558 | + |
|
559 | + if (substr_count($mount->getMountPoint(), '/') < 3) { |
|
560 | + $mountPoint = ''; |
|
561 | + } else { |
|
562 | + [,,,$mountPoint] = explode('/', $mount->getMountPoint(), 4); |
|
563 | + } |
|
564 | + |
|
565 | + $info = [ |
|
566 | + 'free' => $free, |
|
567 | + 'used' => $used, |
|
568 | + 'quota' => $quota, |
|
569 | + 'total' => $total, |
|
570 | + 'relative' => $relative, |
|
571 | + 'owner' => $ownerId, |
|
572 | + 'ownerDisplayName' => $ownerDisplayName, |
|
573 | + 'mountType' => $mount->getMountType(), |
|
574 | + 'mountPoint' => trim($mountPoint, '/'), |
|
575 | + ]; |
|
576 | + |
|
577 | + $memcache->set($cacheKey, $info, 5 * 60); |
|
578 | + |
|
579 | + return $info; |
|
580 | + } |
|
581 | + |
|
582 | + /** |
|
583 | + * Get storage info including all mount points and quota |
|
584 | + */ |
|
585 | + private static function getGlobalStorageInfo(int $quota, IUser $user, IMountPoint $mount): array { |
|
586 | + $rootInfo = \OC\Files\Filesystem::getFileInfo('', 'ext'); |
|
587 | + $used = $rootInfo['size']; |
|
588 | + if ($used < 0) { |
|
589 | + $used = 0; |
|
590 | + } |
|
591 | + |
|
592 | + $total = $quota; |
|
593 | + $free = $quota - $used; |
|
594 | + |
|
595 | + if ($total > 0) { |
|
596 | + if ($quota > 0 && $total > $quota) { |
|
597 | + $total = $quota; |
|
598 | + } |
|
599 | + // prevent division by zero or error codes (negative values) |
|
600 | + $relative = round(($used / $total) * 10000) / 100; |
|
601 | + } else { |
|
602 | + $relative = 0; |
|
603 | + } |
|
604 | + |
|
605 | + if (substr_count($mount->getMountPoint(), '/') < 3) { |
|
606 | + $mountPoint = ''; |
|
607 | + } else { |
|
608 | + [,,,$mountPoint] = explode('/', $mount->getMountPoint(), 4); |
|
609 | + } |
|
610 | + |
|
611 | + return [ |
|
612 | + 'free' => $free, |
|
613 | + 'used' => $used, |
|
614 | + 'total' => $total, |
|
615 | + 'relative' => $relative, |
|
616 | + 'quota' => $quota, |
|
617 | + 'owner' => $user->getUID(), |
|
618 | + 'ownerDisplayName' => $user->getDisplayName(), |
|
619 | + 'mountType' => $mount->getMountType(), |
|
620 | + 'mountPoint' => trim($mountPoint, '/'), |
|
621 | + ]; |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * Returns whether the config file is set manually to read-only |
|
626 | + * @return bool |
|
627 | + */ |
|
628 | + public static function isReadOnlyConfigEnabled() { |
|
629 | + return \OC::$server->getConfig()->getSystemValue('config_is_read_only', false); |
|
630 | + } |
|
631 | 631 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | public static function computerFileSize($str) { |
105 | 105 | $str = strtolower($str); |
106 | 106 | if (is_numeric($str)) { |
107 | - return (int)$str; |
|
107 | + return (int) $str; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | $bytes_array = [ |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | 'p' => 1024 * 1024 * 1024 * 1024 * 1024, |
122 | 122 | ]; |
123 | 123 | |
124 | - $bytes = (float)$str; |
|
124 | + $bytes = (float) $str; |
|
125 | 125 | |
126 | 126 | if (preg_match('#([kmgtp]?b?)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) { |
127 | 127 | $bytes *= $bytes_array[$matches[1]]; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | |
132 | 132 | $bytes = round($bytes); |
133 | 133 | |
134 | - return (int)$bytes; |
|
134 | + return (int) $bytes; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | } |
237 | 237 | foreach ($dirs as $dir) { |
238 | 238 | foreach ($exts as $ext) { |
239 | - if ($check_fn("$dir/$name" . $ext)) { |
|
239 | + if ($check_fn("$dir/$name".$ext)) { |
|
240 | 240 | return true; |
241 | 241 | } |
242 | 242 | } |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | $ext = ''; |
309 | 309 | } |
310 | 310 | |
311 | - $newpath = $path . '/' . $filename; |
|
311 | + $newpath = $path.'/'.$filename; |
|
312 | 312 | if ($view->file_exists($newpath)) { |
313 | 313 | if (preg_match_all('/\((\d+)\)/', $name, $matches, PREG_OFFSET_CAPTURE)) { |
314 | 314 | //Replace the last "(number)" with "(number+1)" |
@@ -324,11 +324,11 @@ discard block |
||
324 | 324 | do { |
325 | 325 | if ($offset) { |
326 | 326 | //Replace the last "(number)" with "(number+1)" |
327 | - $newname = substr_replace($name, '(' . $counter . ')', $offset, $match_length); |
|
327 | + $newname = substr_replace($name, '('.$counter.')', $offset, $match_length); |
|
328 | 328 | } else { |
329 | - $newname = $name . ' (' . $counter . ')'; |
|
329 | + $newname = $name.' ('.$counter.')'; |
|
330 | 330 | } |
331 | - $newpath = $path . '/' . $newname . $ext; |
|
331 | + $newpath = $path.'/'.$newname.$ext; |
|
332 | 332 | $counter++; |
333 | 333 | } while ($view->file_exists($newpath)); |
334 | 334 | } |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | $freeSpace = max($freeSpace, 0); |
410 | 410 | return $freeSpace; |
411 | 411 | } else { |
412 | - return (INF > 0)? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188 |
|
412 | + return (INF > 0) ? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188 |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | */ |
421 | 421 | public static function uploadLimit() { |
422 | 422 | $ini = \OC::$server->get(IniGetWrapper::class); |
423 | - $upload_max_filesize = (int)OCP\Util::computerFileSize($ini->get('upload_max_filesize')); |
|
424 | - $post_max_size = (int)OCP\Util::computerFileSize($ini->get('post_max_size')); |
|
423 | + $upload_max_filesize = (int) OCP\Util::computerFileSize($ini->get('upload_max_filesize')); |
|
424 | + $post_max_size = (int) OCP\Util::computerFileSize($ini->get('post_max_size')); |
|
425 | 425 | if ($upload_max_filesize === 0 && $post_max_size === 0) { |
426 | 426 | return INF; |
427 | 427 | } elseif ($upload_max_filesize === 0 || $post_max_size === 0) { |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | } |
477 | 477 | $fullPath = $view->getAbsolutePath($path); |
478 | 478 | |
479 | - $cacheKey = $fullPath. '::' . ($includeMountPoints ? 'include' : 'exclude'); |
|
479 | + $cacheKey = $fullPath.'::'.($includeMountPoints ? 'include' : 'exclude'); |
|
480 | 480 | if ($useCache) { |
481 | 481 | $cached = $memcache->get($cacheKey); |
482 | 482 | if ($cached) { |