Completed
Push — master ( f78db1...a155f8 )
by Morris
34:10 queued 10s
created
apps/files/lib/Controller/ApiController.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -295,8 +295,8 @@
 block discarded – undo
295 295
 	 *
296 296
 	 * @NoAdminRequired
297 297
 	 *
298
-	 * @param bool $show 
299
-	 * @param bool $key the key of the folder
298
+	 * @param integer $show 
299
+	 * @param string|boolean $key the key of the folder
300 300
 	 *
301 301
 	 * @return Response
302 302
 	 */
Please login to merge, or discard this patch.
Indentation   +351 added lines, -351 removed lines patch added patch discarded remove patch
@@ -53,382 +53,382 @@
 block discarded – undo
53 53
  * @package OCA\Files\Controller
54 54
  */
55 55
 class ApiController extends Controller {
56
-	/** @var TagService */
57
-	private $tagService;
58
-	/** @var IManager * */
59
-	private $shareManager;
60
-	/** @var IPreview */
61
-	private $previewManager;
62
-	/** IUserSession */
63
-	private $userSession;
64
-	/** IConfig */
65
-	private $config;
66
-	/** @var Folder */
67
-	private $userFolder;
56
+    /** @var TagService */
57
+    private $tagService;
58
+    /** @var IManager * */
59
+    private $shareManager;
60
+    /** @var IPreview */
61
+    private $previewManager;
62
+    /** IUserSession */
63
+    private $userSession;
64
+    /** IConfig */
65
+    private $config;
66
+    /** @var Folder */
67
+    private $userFolder;
68 68
 
69
-	/**
70
-	 * @param string $appName
71
-	 * @param IRequest $request
72
-	 * @param IUserSession $userSession
73
-	 * @param TagService $tagService
74
-	 * @param IPreview $previewManager
75
-	 * @param IManager $shareManager
76
-	 * @param IConfig $config
77
-	 * @param Folder $userFolder
78
-	 */
79
-	public function __construct($appName,
80
-								IRequest $request,
81
-								IUserSession $userSession,
82
-								TagService $tagService,
83
-								IPreview $previewManager,
84
-								IManager $shareManager,
85
-								IConfig $config,
86
-								Folder $userFolder) {
87
-		parent::__construct($appName, $request);
88
-		$this->userSession = $userSession;
89
-		$this->tagService = $tagService;
90
-		$this->previewManager = $previewManager;
91
-		$this->shareManager = $shareManager;
92
-		$this->config = $config;
93
-		$this->userFolder = $userFolder;
94
-	}
69
+    /**
70
+     * @param string $appName
71
+     * @param IRequest $request
72
+     * @param IUserSession $userSession
73
+     * @param TagService $tagService
74
+     * @param IPreview $previewManager
75
+     * @param IManager $shareManager
76
+     * @param IConfig $config
77
+     * @param Folder $userFolder
78
+     */
79
+    public function __construct($appName,
80
+                                IRequest $request,
81
+                                IUserSession $userSession,
82
+                                TagService $tagService,
83
+                                IPreview $previewManager,
84
+                                IManager $shareManager,
85
+                                IConfig $config,
86
+                                Folder $userFolder) {
87
+        parent::__construct($appName, $request);
88
+        $this->userSession = $userSession;
89
+        $this->tagService = $tagService;
90
+        $this->previewManager = $previewManager;
91
+        $this->shareManager = $shareManager;
92
+        $this->config = $config;
93
+        $this->userFolder = $userFolder;
94
+    }
95 95
 
96
-	/**
97
-	 * Gets a thumbnail of the specified file
98
-	 *
99
-	 * @since API version 1.0
100
-	 *
101
-	 * @NoAdminRequired
102
-	 * @NoCSRFRequired
103
-	 * @StrictCookieRequired
104
-	 *
105
-	 * @param int $x
106
-	 * @param int $y
107
-	 * @param string $file URL-encoded filename
108
-	 * @return DataResponse|FileDisplayResponse
109
-	 */
110
-	public function getThumbnail($x, $y, $file) {
111
-		if ($x < 1 || $y < 1) {
112
-			return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
113
-		}
96
+    /**
97
+     * Gets a thumbnail of the specified file
98
+     *
99
+     * @since API version 1.0
100
+     *
101
+     * @NoAdminRequired
102
+     * @NoCSRFRequired
103
+     * @StrictCookieRequired
104
+     *
105
+     * @param int $x
106
+     * @param int $y
107
+     * @param string $file URL-encoded filename
108
+     * @return DataResponse|FileDisplayResponse
109
+     */
110
+    public function getThumbnail($x, $y, $file) {
111
+        if ($x < 1 || $y < 1) {
112
+            return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
113
+        }
114 114
 
115
-		try {
116
-			$file = $this->userFolder->get($file);
117
-			if ($file instanceof Folder) {
118
-				throw new NotFoundException();
119
-			}
115
+        try {
116
+            $file = $this->userFolder->get($file);
117
+            if ($file instanceof Folder) {
118
+                throw new NotFoundException();
119
+            }
120 120
 
121
-			/** @var File $file */
122
-			$preview = $this->previewManager->getPreview($file, $x, $y, true);
121
+            /** @var File $file */
122
+            $preview = $this->previewManager->getPreview($file, $x, $y, true);
123 123
 
124
-			return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
125
-		} catch (NotFoundException $e) {
126
-			return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
127
-		} catch (\Exception $e) {
128
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
129
-		}
130
-	}
124
+            return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
125
+        } catch (NotFoundException $e) {
126
+            return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
127
+        } catch (\Exception $e) {
128
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
129
+        }
130
+    }
131 131
 
132
-	/**
133
-	 * Updates the info of the specified file path
134
-	 * The passed tags are absolute, which means they will
135
-	 * replace the actual tag selection.
136
-	 *
137
-	 * @NoAdminRequired
138
-	 *
139
-	 * @param string $path path
140
-	 * @param array|string $tags array of tags
141
-	 * @return DataResponse
142
-	 */
143
-	public function updateFileTags($path, $tags = null) {
144
-		$result = [];
145
-		// if tags specified or empty array, update tags
146
-		if (!is_null($tags)) {
147
-			try {
148
-				$this->tagService->updateFileTags($path, $tags);
149
-			} catch (\OCP\Files\NotFoundException $e) {
150
-				return new DataResponse([
151
-					'message' => $e->getMessage()
152
-				], Http::STATUS_NOT_FOUND);
153
-			} catch (\OCP\Files\StorageNotAvailableException $e) {
154
-				return new DataResponse([
155
-					'message' => $e->getMessage()
156
-				], Http::STATUS_SERVICE_UNAVAILABLE);
157
-			} catch (\Exception $e) {
158
-				return new DataResponse([
159
-					'message' => $e->getMessage()
160
-				], Http::STATUS_NOT_FOUND);
161
-			}
162
-			$result['tags'] = $tags;
163
-		}
164
-		return new DataResponse($result);
165
-	}
132
+    /**
133
+     * Updates the info of the specified file path
134
+     * The passed tags are absolute, which means they will
135
+     * replace the actual tag selection.
136
+     *
137
+     * @NoAdminRequired
138
+     *
139
+     * @param string $path path
140
+     * @param array|string $tags array of tags
141
+     * @return DataResponse
142
+     */
143
+    public function updateFileTags($path, $tags = null) {
144
+        $result = [];
145
+        // if tags specified or empty array, update tags
146
+        if (!is_null($tags)) {
147
+            try {
148
+                $this->tagService->updateFileTags($path, $tags);
149
+            } catch (\OCP\Files\NotFoundException $e) {
150
+                return new DataResponse([
151
+                    'message' => $e->getMessage()
152
+                ], Http::STATUS_NOT_FOUND);
153
+            } catch (\OCP\Files\StorageNotAvailableException $e) {
154
+                return new DataResponse([
155
+                    'message' => $e->getMessage()
156
+                ], Http::STATUS_SERVICE_UNAVAILABLE);
157
+            } catch (\Exception $e) {
158
+                return new DataResponse([
159
+                    'message' => $e->getMessage()
160
+                ], Http::STATUS_NOT_FOUND);
161
+            }
162
+            $result['tags'] = $tags;
163
+        }
164
+        return new DataResponse($result);
165
+    }
166 166
 
167
-	/**
168
-	 * @param \OCP\Files\Node[] $nodes
169
-	 * @return array
170
-	 */
171
-	private function formatNodes(array $nodes) {
172
-		return array_values(array_map(function (Node $node) {
173
-			/** @var \OC\Files\Node\Node $shareTypes */
174
-			$shareTypes = $this->getShareTypes($node);
175
-			$file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
176
-			$parts = explode('/', dirname($node->getPath()), 4);
177
-			if (isset($parts[3])) {
178
-				$file['path'] = '/' . $parts[3];
179
-			} else {
180
-				$file['path'] = '/';
181
-			}
182
-			if (!empty($shareTypes)) {
183
-				$file['shareTypes'] = $shareTypes;
184
-			}
185
-			return $file;
186
-		}, $nodes));
187
-	}
167
+    /**
168
+     * @param \OCP\Files\Node[] $nodes
169
+     * @return array
170
+     */
171
+    private function formatNodes(array $nodes) {
172
+        return array_values(array_map(function (Node $node) {
173
+            /** @var \OC\Files\Node\Node $shareTypes */
174
+            $shareTypes = $this->getShareTypes($node);
175
+            $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
176
+            $parts = explode('/', dirname($node->getPath()), 4);
177
+            if (isset($parts[3])) {
178
+                $file['path'] = '/' . $parts[3];
179
+            } else {
180
+                $file['path'] = '/';
181
+            }
182
+            if (!empty($shareTypes)) {
183
+                $file['shareTypes'] = $shareTypes;
184
+            }
185
+            return $file;
186
+        }, $nodes));
187
+    }
188 188
 
189
-	/**
190
-	 * Returns a list of recently modifed files.
191
-	 *
192
-	 * @NoAdminRequired
193
-	 *
194
-	 * @return DataResponse
195
-	 */
196
-	public function getRecentFiles() {
197
-		$nodes = $this->userFolder->getRecent(100);
198
-		$files = $this->formatNodes($nodes);
199
-		return new DataResponse(['files' => $files]);
200
-	}
189
+    /**
190
+     * Returns a list of recently modifed files.
191
+     *
192
+     * @NoAdminRequired
193
+     *
194
+     * @return DataResponse
195
+     */
196
+    public function getRecentFiles() {
197
+        $nodes = $this->userFolder->getRecent(100);
198
+        $files = $this->formatNodes($nodes);
199
+        return new DataResponse(['files' => $files]);
200
+    }
201 201
 
202
-	/**
203
-	 * Returns a list of favorites modifed folder.
204
-	 *
205
-	 * @NoAdminRequired
206
-	 *
207
-	 * @return DataResponse
208
-	 */
209
-	public function getFavoritesFolder() {
210
-		$nodes = $this->userFolder->searchByTag('_$!<Favorite>!$_', $this->userSession->getUser()->getUID());
202
+    /**
203
+     * Returns a list of favorites modifed folder.
204
+     *
205
+     * @NoAdminRequired
206
+     *
207
+     * @return DataResponse
208
+     */
209
+    public function getFavoritesFolder() {
210
+        $nodes = $this->userFolder->searchByTag('_$!<Favorite>!$_', $this->userSession->getUser()->getUID());
211 211
 
212
-		$favorites = [];
213
-		$i = 0;
214
-		foreach ($nodes as &$node) {
212
+        $favorites = [];
213
+        $i = 0;
214
+        foreach ($nodes as &$node) {
215 215
 
216
-			$favorites[$i]['id'] = $node->getId();
217
-			$favorites[$i]['name'] = $node->getName();
218
-			$favorites[$i]['path'] = $node->getInternalPath();
219
-			$favorites[$i]['mtime'] = $node->getMTime();
220
-			$i++;
221
-		}
216
+            $favorites[$i]['id'] = $node->getId();
217
+            $favorites[$i]['name'] = $node->getName();
218
+            $favorites[$i]['path'] = $node->getInternalPath();
219
+            $favorites[$i]['mtime'] = $node->getMTime();
220
+            $i++;
221
+        }
222 222
 
223
-		return new DataResponse(['favoriteFolders' => $favorites]);
224
-	}
223
+        return new DataResponse(['favoriteFolders' => $favorites]);
224
+    }
225 225
 
226
-	/**
227
-	 * Return a list of share types for outgoing shares
228
-	 *
229
-	 * @param Node $node file node
230
-	 *
231
-	 * @return int[] array of share types
232
-	 */
233
-	private function getShareTypes(Node $node) {
234
-		$userId = $this->userSession->getUser()->getUID();
235
-		$shareTypes = [];
236
-		$requestedShareTypes = [
237
-			\OCP\Share::SHARE_TYPE_USER,
238
-			\OCP\Share::SHARE_TYPE_GROUP,
239
-			\OCP\Share::SHARE_TYPE_LINK,
240
-			\OCP\Share::SHARE_TYPE_REMOTE,
241
-			\OCP\Share::SHARE_TYPE_EMAIL
242
-		];
243
-		foreach ($requestedShareTypes as $requestedShareType) {
244
-			// one of each type is enough to find out about the types
245
-			$shares = $this->shareManager->getSharesBy(
246
-				$userId,
247
-				$requestedShareType,
248
-				$node,
249
-				false,
250
-				1
251
-			);
252
-			if (!empty($shares)) {
253
-				$shareTypes[] = $requestedShareType;
254
-			}
255
-		}
256
-		return $shareTypes;
257
-	}
226
+    /**
227
+     * Return a list of share types for outgoing shares
228
+     *
229
+     * @param Node $node file node
230
+     *
231
+     * @return int[] array of share types
232
+     */
233
+    private function getShareTypes(Node $node) {
234
+        $userId = $this->userSession->getUser()->getUID();
235
+        $shareTypes = [];
236
+        $requestedShareTypes = [
237
+            \OCP\Share::SHARE_TYPE_USER,
238
+            \OCP\Share::SHARE_TYPE_GROUP,
239
+            \OCP\Share::SHARE_TYPE_LINK,
240
+            \OCP\Share::SHARE_TYPE_REMOTE,
241
+            \OCP\Share::SHARE_TYPE_EMAIL
242
+        ];
243
+        foreach ($requestedShareTypes as $requestedShareType) {
244
+            // one of each type is enough to find out about the types
245
+            $shares = $this->shareManager->getSharesBy(
246
+                $userId,
247
+                $requestedShareType,
248
+                $node,
249
+                false,
250
+                1
251
+            );
252
+            if (!empty($shares)) {
253
+                $shareTypes[] = $requestedShareType;
254
+            }
255
+        }
256
+        return $shareTypes;
257
+    }
258 258
 
259
-	/**
260
-	 * Change the default sort mode
261
-	 *
262
-	 * @NoAdminRequired
263
-	 *
264
-	 * @param string $mode
265
-	 * @param string $direction
266
-	 * @return Response
267
-	 */
268
-	public function updateFileSorting($mode, $direction) {
269
-		$allowedMode = ['name', 'size', 'mtime'];
270
-		$allowedDirection = ['asc', 'desc'];
271
-		if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
272
-			$response = new Response();
273
-			$response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
274
-			return $response;
275
-		}
276
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode);
277
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
278
-		return new Response();
279
-	}
259
+    /**
260
+     * Change the default sort mode
261
+     *
262
+     * @NoAdminRequired
263
+     *
264
+     * @param string $mode
265
+     * @param string $direction
266
+     * @return Response
267
+     */
268
+    public function updateFileSorting($mode, $direction) {
269
+        $allowedMode = ['name', 'size', 'mtime'];
270
+        $allowedDirection = ['asc', 'desc'];
271
+        if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
272
+            $response = new Response();
273
+            $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
274
+            return $response;
275
+        }
276
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode);
277
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
278
+        return new Response();
279
+    }
280 280
 
281
-	/**
282
-	 * Toggle default for showing/hiding hidden files
283
-	 *
284
-	 * @NoAdminRequired
285
-	 *
286
-	 * @param bool $show
287
-	 */
288
-	public function showHiddenFiles($show) {
289
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
290
-		return new Response();
291
-	}
281
+    /**
282
+     * Toggle default for showing/hiding hidden files
283
+     *
284
+     * @NoAdminRequired
285
+     *
286
+     * @param bool $show
287
+     */
288
+    public function showHiddenFiles($show) {
289
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
290
+        return new Response();
291
+    }
292 292
 
293
-	/**
294
-	 * Toggle default for showing/hiding xxx folder
295
-	 *
296
-	 * @NoAdminRequired
297
-	 *
298
-	 * @param bool $show 
299
-	 * @param bool $key the key of the folder
300
-	 *
301
-	 * @return Response
302
-	 */
303
-	public function toggleShowFolder(int $show, string $key) {
304
-		// ensure the edited key exists
305
-		$navItems = \OCA\Files\App::getNavigationManager()->getAll();
306
-		foreach ($navItems as $item) {
307
-			// check if data is valid
308
-			if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
309
-				$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show);
310
-				return new Response();
311
-			}
312
-		}
313
-		$response = new Response();
314
-		$response->setStatus(Http::STATUS_FORBIDDEN);
315
-		return $response;
316
-	}
293
+    /**
294
+     * Toggle default for showing/hiding xxx folder
295
+     *
296
+     * @NoAdminRequired
297
+     *
298
+     * @param bool $show 
299
+     * @param bool $key the key of the folder
300
+     *
301
+     * @return Response
302
+     */
303
+    public function toggleShowFolder(int $show, string $key) {
304
+        // ensure the edited key exists
305
+        $navItems = \OCA\Files\App::getNavigationManager()->getAll();
306
+        foreach ($navItems as $item) {
307
+            // check if data is valid
308
+            if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
309
+                $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show);
310
+                return new Response();
311
+            }
312
+        }
313
+        $response = new Response();
314
+        $response->setStatus(Http::STATUS_FORBIDDEN);
315
+        return $response;
316
+    }
317 317
 
318
-	/**
319
-	 * quickaccess-sorting-strategy
320
-	 *
321
-	 * @NoAdminRequired
322
-	 *
323
-	 * @param string $strategy
324
-	 * @return Response
325
-	 */
326
-	public function setSortingStrategy($strategy) {
327
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', (String)$strategy);
328
-		return new Response();
329
-	}
318
+    /**
319
+     * quickaccess-sorting-strategy
320
+     *
321
+     * @NoAdminRequired
322
+     *
323
+     * @param string $strategy
324
+     * @return Response
325
+     */
326
+    public function setSortingStrategy($strategy) {
327
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', (String)$strategy);
328
+        return new Response();
329
+    }
330 330
 
331
-	/**
332
-	 * Get reverse-state for quickaccess-list
333
-	 *
334
-	 * @NoAdminRequired
335
-	 *
336
-	 * @return String
337
-	 */
338
-	public function getSortingStrategy() {
339
-		return $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', 'alphabet');
340
-	}
331
+    /**
332
+     * Get reverse-state for quickaccess-list
333
+     *
334
+     * @NoAdminRequired
335
+     *
336
+     * @return String
337
+     */
338
+    public function getSortingStrategy() {
339
+        return $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', 'alphabet');
340
+    }
341 341
 
342
-	/**
343
-	 * Toggle for reverse quickaccess-list
344
-	 *
345
-	 * @NoAdminRequired
346
-	 *
347
-	 * @param bool $reverse
348
-	 * @return Response
349
-	 */
350
-	public function setReverseQuickaccess($reverse) {
351
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', (int)$reverse);
352
-		return new Response();
353
-	}
342
+    /**
343
+     * Toggle for reverse quickaccess-list
344
+     *
345
+     * @NoAdminRequired
346
+     *
347
+     * @param bool $reverse
348
+     * @return Response
349
+     */
350
+    public function setReverseQuickaccess($reverse) {
351
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', (int)$reverse);
352
+        return new Response();
353
+    }
354 354
 
355
-	/**
356
-	 * Get reverse-state for quickaccess-list
357
-	 *
358
-	 * @NoAdminRequired
359
-	 *
360
-	 * @return bool
361
-	 */
362
-	public function getReverseQuickaccess() {
363
-		if ($this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', false)) {
364
-			return true;
365
-		}
366
-		return false;
367
-	}
355
+    /**
356
+     * Get reverse-state for quickaccess-list
357
+     *
358
+     * @NoAdminRequired
359
+     *
360
+     * @return bool
361
+     */
362
+    public function getReverseQuickaccess() {
363
+        if ($this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', false)) {
364
+            return true;
365
+        }
366
+        return false;
367
+    }
368 368
 
369
-	/**
370
-	 * Set state for show sorting menu
371
-	 *
372
-	 * @NoAdminRequired
373
-	 *
374
-	 * @param bool $show
375
-	 * @return Response
376
-	 */
377
-	public function setShowQuickaccessSettings($show) {
378
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_show_settings', (int)$show);
379
-		return new Response();
380
-	}
369
+    /**
370
+     * Set state for show sorting menu
371
+     *
372
+     * @NoAdminRequired
373
+     *
374
+     * @param bool $show
375
+     * @return Response
376
+     */
377
+    public function setShowQuickaccessSettings($show) {
378
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_show_settings', (int)$show);
379
+        return new Response();
380
+    }
381 381
 
382
-	/**
383
-	 * Get state for show sorting menu
384
-	 *
385
-	 * @NoAdminRequired
386
-	 *
387
-	 * @return bool
388
-	 */
389
-	public function getShowQuickaccessSettings() {
390
-		if ($this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_show_settings', false)) {
391
-			return true;
392
-		}
393
-		return false;
394
-	}
382
+    /**
383
+     * Get state for show sorting menu
384
+     *
385
+     * @NoAdminRequired
386
+     *
387
+     * @return bool
388
+     */
389
+    public function getShowQuickaccessSettings() {
390
+        if ($this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_show_settings', false)) {
391
+            return true;
392
+        }
393
+        return false;
394
+    }
395 395
 
396
-	/**
397
-	 * Set sorting-order for custom sorting
398
-	 *
399
-	 * @NoAdminRequired
400
-	 *
401
-	 * @param String $order
402
-	 * @return Response
403
-	 */
404
-	public function setSortingOrder($order) {
405
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_custom_sorting_order', (String)$order);
406
-		return new Response();
407
-	}
396
+    /**
397
+     * Set sorting-order for custom sorting
398
+     *
399
+     * @NoAdminRequired
400
+     *
401
+     * @param String $order
402
+     * @return Response
403
+     */
404
+    public function setSortingOrder($order) {
405
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_custom_sorting_order', (String)$order);
406
+        return new Response();
407
+    }
408 408
 
409
-	/**
410
-	 * Get sorting-order for custom sorting
411
-	 *
412
-	 * @NoAdminRequired
413
-	 *
414
-	 * @return String
415
-	 */
416
-	public function getSortingOrder() {
417
-		return $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_custom_sorting_order', "");
418
-	}
409
+    /**
410
+     * Get sorting-order for custom sorting
411
+     *
412
+     * @NoAdminRequired
413
+     *
414
+     * @return String
415
+     */
416
+    public function getSortingOrder() {
417
+        return $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_custom_sorting_order', "");
418
+    }
419 419
 
420
-	/**
421
-	 * Get sorting-order for custom sorting
422
-	 *
423
-	 * @NoAdminRequired
424
-	 *
425
-	 * @param String
426
-	 * @return String
427
-	 */
428
-	public function getNodeType($folderpath) {
429
-		$node = $this->userFolder->get($folderpath);
430
-		return $node->getType();
431
-	}
420
+    /**
421
+     * Get sorting-order for custom sorting
422
+     *
423
+     * @NoAdminRequired
424
+     *
425
+     * @param String
426
+     * @return String
427
+     */
428
+    public function getNodeType($folderpath) {
429
+        $node = $this->userFolder->get($folderpath);
430
+        return $node->getType();
431
+    }
432 432
 
433 433
 
434 434
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -169,13 +169,13 @@  discard block
 block discarded – undo
169 169
 	 * @return array
170 170
 	 */
171 171
 	private function formatNodes(array $nodes) {
172
-		return array_values(array_map(function (Node $node) {
172
+		return array_values(array_map(function(Node $node) {
173 173
 			/** @var \OC\Files\Node\Node $shareTypes */
174 174
 			$shareTypes = $this->getShareTypes($node);
175 175
 			$file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
176 176
 			$parts = explode('/', dirname($node->getPath()), 4);
177 177
 			if (isset($parts[3])) {
178
-				$file['path'] = '/' . $parts[3];
178
+				$file['path'] = '/'.$parts[3];
179 179
 			} else {
180 180
 				$file['path'] = '/';
181 181
 			}
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 * @param bool $show
287 287
 	 */
288 288
 	public function showHiddenFiles($show) {
289
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
289
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int) $show);
290 290
 		return new Response();
291 291
 	}
292 292
 
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 		foreach ($navItems as $item) {
307 307
 			// check if data is valid
308 308
 			if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
309
-				$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int)$show);
309
+				$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, (int) $show);
310 310
 				return new Response();
311 311
 			}
312 312
 		}
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 	 * @return Response
325 325
 	 */
326 326
 	public function setSortingStrategy($strategy) {
327
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', (String)$strategy);
327
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_sorting_strategy', (String) $strategy);
328 328
 		return new Response();
329 329
 	}
330 330
 
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 	 * @return Response
349 349
 	 */
350 350
 	public function setReverseQuickaccess($reverse) {
351
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', (int)$reverse);
351
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_reverse_list', (int) $reverse);
352 352
 		return new Response();
353 353
 	}
354 354
 
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 	 * @return Response
376 376
 	 */
377 377
 	public function setShowQuickaccessSettings($show) {
378
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_show_settings', (int)$show);
378
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_show_settings', (int) $show);
379 379
 		return new Response();
380 380
 	}
381 381
 
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 	 * @return Response
403 403
 	 */
404 404
 	public function setSortingOrder($order) {
405
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_custom_sorting_order', (String)$order);
405
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'quickaccess_custom_sorting_order', (String) $order);
406 406
 		return new Response();
407 407
 	}
408 408
 
Please login to merge, or discard this patch.
lib/private/NavigationManager.php 2 patches
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -44,290 +44,290 @@
 block discarded – undo
44 44
  */
45 45
 
46 46
 class NavigationManager implements INavigationManager {
47
-	protected $entries = [];
48
-	protected $closureEntries = [];
49
-	protected $activeEntry;
50
-	/** @var bool */
51
-	protected $init = false;
52
-	/** @var IAppManager|AppManager */
53
-	protected $appManager;
54
-	/** @var IURLGenerator */
55
-	private $urlGenerator;
56
-	/** @var IFactory */
57
-	private $l10nFac;
58
-	/** @var IUserSession */
59
-	private $userSession;
60
-	/** @var IGroupManager|Manager */
61
-	private $groupManager;
62
-	/** @var IConfig */
63
-	private $config;
47
+    protected $entries = [];
48
+    protected $closureEntries = [];
49
+    protected $activeEntry;
50
+    /** @var bool */
51
+    protected $init = false;
52
+    /** @var IAppManager|AppManager */
53
+    protected $appManager;
54
+    /** @var IURLGenerator */
55
+    private $urlGenerator;
56
+    /** @var IFactory */
57
+    private $l10nFac;
58
+    /** @var IUserSession */
59
+    private $userSession;
60
+    /** @var IGroupManager|Manager */
61
+    private $groupManager;
62
+    /** @var IConfig */
63
+    private $config;
64 64
 
65
-	public function __construct(IAppManager $appManager,
66
-						 IURLGenerator $urlGenerator,
67
-						 IFactory $l10nFac,
68
-						 IUserSession $userSession,
69
-						 IGroupManager $groupManager,
70
-						 IConfig $config) {
71
-		$this->appManager = $appManager;
72
-		$this->urlGenerator = $urlGenerator;
73
-		$this->l10nFac = $l10nFac;
74
-		$this->userSession = $userSession;
75
-		$this->groupManager = $groupManager;
76
-		$this->config = $config;
77
-	}
65
+    public function __construct(IAppManager $appManager,
66
+                            IURLGenerator $urlGenerator,
67
+                            IFactory $l10nFac,
68
+                            IUserSession $userSession,
69
+                            IGroupManager $groupManager,
70
+                            IConfig $config) {
71
+        $this->appManager = $appManager;
72
+        $this->urlGenerator = $urlGenerator;
73
+        $this->l10nFac = $l10nFac;
74
+        $this->userSession = $userSession;
75
+        $this->groupManager = $groupManager;
76
+        $this->config = $config;
77
+    }
78 78
 
79
-	/**
80
-	 * Creates a new navigation entry
81
-	 *
82
-	 * @param array|\Closure $entry Array containing: id, name, order, icon and href key
83
-	 *					The use of a closure is preferred, because it will avoid
84
-	 * 					loading the routing of your app, unless required.
85
-	 * @return void
86
-	 */
87
-	public function add($entry) {
88
-		if ($entry instanceof \Closure) {
89
-			$this->closureEntries[] = $entry;
90
-			return;
91
-		}
79
+    /**
80
+     * Creates a new navigation entry
81
+     *
82
+     * @param array|\Closure $entry Array containing: id, name, order, icon and href key
83
+     *					The use of a closure is preferred, because it will avoid
84
+     * 					loading the routing of your app, unless required.
85
+     * @return void
86
+     */
87
+    public function add($entry) {
88
+        if ($entry instanceof \Closure) {
89
+            $this->closureEntries[] = $entry;
90
+            return;
91
+        }
92 92
 
93
-		$entry['active'] = false;
94
-		if(!isset($entry['icon'])) {
95
-			$entry['icon'] = '';
96
-		}
97
-		if(!isset($entry['classes'])) {
98
-			$entry['classes'] = '';
99
-		}
100
-		if(!isset($entry['type'])) {
101
-			$entry['type'] = 'link';
102
-		}
103
-		$this->entries[$entry['id']] = $entry;
104
-	}
93
+        $entry['active'] = false;
94
+        if(!isset($entry['icon'])) {
95
+            $entry['icon'] = '';
96
+        }
97
+        if(!isset($entry['classes'])) {
98
+            $entry['classes'] = '';
99
+        }
100
+        if(!isset($entry['type'])) {
101
+            $entry['type'] = 'link';
102
+        }
103
+        $this->entries[$entry['id']] = $entry;
104
+    }
105 105
 
106
-	/**
107
-	 * Get a list of navigation entries
108
-	 *
109
-	 * @param string $type type of the navigation entries
110
-	 * @return array
111
-	 */
112
-	public function getAll(string $type = 'link'): array {
113
-		$this->init();
114
-		foreach ($this->closureEntries as $c) {
115
-			$this->add($c());
116
-		}
117
-		$this->closureEntries = array();
106
+    /**
107
+     * Get a list of navigation entries
108
+     *
109
+     * @param string $type type of the navigation entries
110
+     * @return array
111
+     */
112
+    public function getAll(string $type = 'link'): array {
113
+        $this->init();
114
+        foreach ($this->closureEntries as $c) {
115
+            $this->add($c());
116
+        }
117
+        $this->closureEntries = array();
118 118
 
119
-		$result = $this->entries;
120
-		if ($type !== 'all') {
121
-			$result = array_filter($this->entries, function($entry) use ($type) {
122
-				return $entry['type'] === $type;
123
-			});
124
-		}
119
+        $result = $this->entries;
120
+        if ($type !== 'all') {
121
+            $result = array_filter($this->entries, function($entry) use ($type) {
122
+                return $entry['type'] === $type;
123
+            });
124
+        }
125 125
 
126
-		return $this->proceedNavigation($result);
127
-	}
126
+        return $this->proceedNavigation($result);
127
+    }
128 128
 
129
-	/**
130
-	 * Sort navigation entries by order, name and set active flag
131
-	 *
132
-	 * @param array $list
133
-	 * @return array
134
-	 */
135
-	private function proceedNavigation(array $list): array {
136
-		uasort($list, function($a, $b) {
137
-			if (isset($a['order']) && isset($b['order'])) {
138
-				return ($a['order'] < $b['order']) ? -1 : 1;
139
-			} else if (isset($a['order']) || isset($b['order'])) {
140
-				return isset($a['order']) ? -1 : 1;
141
-			} else {
142
-				return ($a['name'] < $b['name']) ? -1 : 1;
143
-			}
144
-		});
129
+    /**
130
+     * Sort navigation entries by order, name and set active flag
131
+     *
132
+     * @param array $list
133
+     * @return array
134
+     */
135
+    private function proceedNavigation(array $list): array {
136
+        uasort($list, function($a, $b) {
137
+            if (isset($a['order']) && isset($b['order'])) {
138
+                return ($a['order'] < $b['order']) ? -1 : 1;
139
+            } else if (isset($a['order']) || isset($b['order'])) {
140
+                return isset($a['order']) ? -1 : 1;
141
+            } else {
142
+                return ($a['name'] < $b['name']) ? -1 : 1;
143
+            }
144
+        });
145 145
 
146
-		$activeApp = $this->getActiveEntry();
147
-		if ($activeApp !== null) {
148
-			foreach ($list as $index => &$navEntry) {
149
-				if ($navEntry['id'] == $activeApp) {
150
-					$navEntry['active'] = true;
151
-				} else {
152
-					$navEntry['active'] = false;
153
-				}
154
-			}
155
-			unset($navEntry);
156
-		}
146
+        $activeApp = $this->getActiveEntry();
147
+        if ($activeApp !== null) {
148
+            foreach ($list as $index => &$navEntry) {
149
+                if ($navEntry['id'] == $activeApp) {
150
+                    $navEntry['active'] = true;
151
+                } else {
152
+                    $navEntry['active'] = false;
153
+                }
154
+            }
155
+            unset($navEntry);
156
+        }
157 157
 
158
-		return $list;
159
-	}
158
+        return $list;
159
+    }
160 160
 
161 161
 
162
-	/**
163
-	 * removes all the entries
164
-	 */
165
-	public function clear($loadDefaultLinks = true) {
166
-		$this->entries = [];
167
-		$this->closureEntries = [];
168
-		$this->init = !$loadDefaultLinks;
169
-	}
162
+    /**
163
+     * removes all the entries
164
+     */
165
+    public function clear($loadDefaultLinks = true) {
166
+        $this->entries = [];
167
+        $this->closureEntries = [];
168
+        $this->init = !$loadDefaultLinks;
169
+    }
170 170
 
171
-	/**
172
-	 * Sets the current navigation entry of the currently running app
173
-	 * @param string $id of the app entry to activate (from added $entry)
174
-	 */
175
-	public function setActiveEntry($id) {
176
-		$this->activeEntry = $id;
177
-	}
171
+    /**
172
+     * Sets the current navigation entry of the currently running app
173
+     * @param string $id of the app entry to activate (from added $entry)
174
+     */
175
+    public function setActiveEntry($id) {
176
+        $this->activeEntry = $id;
177
+    }
178 178
 
179
-	/**
180
-	 * gets the active Menu entry
181
-	 * @return string id or empty string
182
-	 *
183
-	 * This function returns the id of the active navigation entry (set by
184
-	 * setActiveEntry
185
-	 */
186
-	public function getActiveEntry() {
187
-		return $this->activeEntry;
188
-	}
179
+    /**
180
+     * gets the active Menu entry
181
+     * @return string id or empty string
182
+     *
183
+     * This function returns the id of the active navigation entry (set by
184
+     * setActiveEntry
185
+     */
186
+    public function getActiveEntry() {
187
+        return $this->activeEntry;
188
+    }
189 189
 
190
-	private function init() {
191
-		if ($this->init) {
192
-			return;
193
-		}
194
-		$this->init = true;
190
+    private function init() {
191
+        if ($this->init) {
192
+            return;
193
+        }
194
+        $this->init = true;
195 195
 
196
-		$l = $this->l10nFac->get('lib');
197
-		if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
198
-			$this->add([
199
-				'type' => 'settings',
200
-				'id' => 'help',
201
-				'order' => 5,
202
-				'href' => $this->urlGenerator->linkToRoute('settings_help'),
203
-				'name' => $l->t('Help'),
204
-				'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
205
-			]);
206
-		}
196
+        $l = $this->l10nFac->get('lib');
197
+        if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
198
+            $this->add([
199
+                'type' => 'settings',
200
+                'id' => 'help',
201
+                'order' => 5,
202
+                'href' => $this->urlGenerator->linkToRoute('settings_help'),
203
+                'name' => $l->t('Help'),
204
+                'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
205
+            ]);
206
+        }
207 207
 
208
-		if ($this->userSession->isLoggedIn()) {
209
-			if ($this->isAdmin()) {
210
-				// App management
211
-				$this->add([
212
-					'type' => 'settings',
213
-					'id' => 'core_apps',
214
-					'order' => 3,
215
-					'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
216
-					'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
217
-					'name' => $l->t('Apps'),
218
-				]);
219
-			}
208
+        if ($this->userSession->isLoggedIn()) {
209
+            if ($this->isAdmin()) {
210
+                // App management
211
+                $this->add([
212
+                    'type' => 'settings',
213
+                    'id' => 'core_apps',
214
+                    'order' => 3,
215
+                    'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
216
+                    'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
217
+                    'name' => $l->t('Apps'),
218
+                ]);
219
+            }
220 220
 
221
-			// Personal and (if applicable) admin settings
222
-			$this->add([
223
-				'type' => 'settings',
224
-				'id' => 'settings',
225
-				'order' => 1,
226
-				'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
227
-				'name' => $l->t('Settings'),
228
-				'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
229
-			]);
221
+            // Personal and (if applicable) admin settings
222
+            $this->add([
223
+                'type' => 'settings',
224
+                'id' => 'settings',
225
+                'order' => 1,
226
+                'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
227
+                'name' => $l->t('Settings'),
228
+                'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
229
+            ]);
230 230
 
231
-			$logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
232
-			if($logoutUrl !== '') {
233
-				// Logout
234
-				$this->add([
235
-					'type' => 'settings',
236
-					'id' => 'logout',
237
-					'order' => 99999,
238
-					'href' => $logoutUrl,
239
-					'name' => $l->t('Log out'),
240
-					'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
241
-				]);
242
-			}
231
+            $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
232
+            if($logoutUrl !== '') {
233
+                // Logout
234
+                $this->add([
235
+                    'type' => 'settings',
236
+                    'id' => 'logout',
237
+                    'order' => 99999,
238
+                    'href' => $logoutUrl,
239
+                    'name' => $l->t('Log out'),
240
+                    'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
241
+                ]);
242
+            }
243 243
 
244
-			if ($this->isSubadmin()) {
245
-				// User management
246
-				$this->add([
247
-					'type' => 'settings',
248
-					'id' => 'core_users',
249
-					'order' => 4,
250
-					'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'),
251
-					'name' => $l->t('Users'),
252
-					'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
253
-				]);
254
-			}
255
-		}
244
+            if ($this->isSubadmin()) {
245
+                // User management
246
+                $this->add([
247
+                    'type' => 'settings',
248
+                    'id' => 'core_users',
249
+                    'order' => 4,
250
+                    'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'),
251
+                    'name' => $l->t('Users'),
252
+                    'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
253
+                ]);
254
+            }
255
+        }
256 256
 
257
-		if ($this->appManager === 'null') {
258
-			return;
259
-		}
257
+        if ($this->appManager === 'null') {
258
+            return;
259
+        }
260 260
 
261
-		if ($this->userSession->isLoggedIn()) {
262
-			$apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
263
-		} else {
264
-			$apps = $this->appManager->getInstalledApps();
265
-		}
261
+        if ($this->userSession->isLoggedIn()) {
262
+            $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
263
+        } else {
264
+            $apps = $this->appManager->getInstalledApps();
265
+        }
266 266
 
267
-		foreach ($apps as $app) {
268
-			if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
269
-				continue;
270
-			}
267
+        foreach ($apps as $app) {
268
+            if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
269
+                continue;
270
+            }
271 271
 
272
-			// load plugins and collections from info.xml
273
-			$info = $this->appManager->getAppInfo($app);
274
-			if (empty($info['navigations'])) {
275
-				continue;
276
-			}
277
-			foreach ($info['navigations'] as $nav) {
278
-				if (!isset($nav['name'])) {
279
-					continue;
280
-				}
281
-				if (!isset($nav['route'])) {
282
-					continue;
283
-				}
284
-				$role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
285
-				if ($role === 'admin' && !$this->isAdmin()) {
286
-					continue;
287
-				}
288
-				$l = $this->l10nFac->get($app);
289
-				$id = isset($nav['id']) ? $nav['id'] : $app;
290
-				$order = isset($nav['order']) ? $nav['order'] : 100;
291
-				$type = isset($nav['type']) ? $nav['type'] : 'link';
292
-				$route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : '';
293
-				$icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
294
-				foreach ([$icon, "$app.svg"] as $i) {
295
-					try {
296
-						$icon = $this->urlGenerator->imagePath($app, $i);
297
-						break;
298
-					} catch (\RuntimeException $ex) {
299
-						// no icon? - ignore it then
300
-					}
301
-				}
302
-				if ($icon === null) {
303
-					$icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
304
-				}
272
+            // load plugins and collections from info.xml
273
+            $info = $this->appManager->getAppInfo($app);
274
+            if (empty($info['navigations'])) {
275
+                continue;
276
+            }
277
+            foreach ($info['navigations'] as $nav) {
278
+                if (!isset($nav['name'])) {
279
+                    continue;
280
+                }
281
+                if (!isset($nav['route'])) {
282
+                    continue;
283
+                }
284
+                $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
285
+                if ($role === 'admin' && !$this->isAdmin()) {
286
+                    continue;
287
+                }
288
+                $l = $this->l10nFac->get($app);
289
+                $id = isset($nav['id']) ? $nav['id'] : $app;
290
+                $order = isset($nav['order']) ? $nav['order'] : 100;
291
+                $type = isset($nav['type']) ? $nav['type'] : 'link';
292
+                $route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : '';
293
+                $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
294
+                foreach ([$icon, "$app.svg"] as $i) {
295
+                    try {
296
+                        $icon = $this->urlGenerator->imagePath($app, $i);
297
+                        break;
298
+                    } catch (\RuntimeException $ex) {
299
+                        // no icon? - ignore it then
300
+                    }
301
+                }
302
+                if ($icon === null) {
303
+                    $icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
304
+                }
305 305
 
306
-				$this->add([
307
-					'id' => $id,
308
-					'order' => $order,
309
-					'href' => $route,
310
-					'icon' => $icon,
311
-					'type' => $type,
312
-					'name' => $l->t($nav['name']),
313
-				]);
314
-			}
315
-		}
316
-	}
306
+                $this->add([
307
+                    'id' => $id,
308
+                    'order' => $order,
309
+                    'href' => $route,
310
+                    'icon' => $icon,
311
+                    'type' => $type,
312
+                    'name' => $l->t($nav['name']),
313
+                ]);
314
+            }
315
+        }
316
+    }
317 317
 
318
-	private function isAdmin() {
319
-		$user = $this->userSession->getUser();
320
-		if ($user !== null) {
321
-			return $this->groupManager->isAdmin($user->getUID());
322
-		}
323
-		return false;
324
-	}
318
+    private function isAdmin() {
319
+        $user = $this->userSession->getUser();
320
+        if ($user !== null) {
321
+            return $this->groupManager->isAdmin($user->getUID());
322
+        }
323
+        return false;
324
+    }
325 325
 
326
-	private function isSubadmin() {
327
-		$user = $this->userSession->getUser();
328
-		if ($user !== null) {
329
-			return $this->groupManager->getSubAdmin()->isSubAdmin($user);
330
-		}
331
-		return false;
332
-	}
326
+    private function isSubadmin() {
327
+        $user = $this->userSession->getUser();
328
+        if ($user !== null) {
329
+            return $this->groupManager->getSubAdmin()->isSubAdmin($user);
330
+        }
331
+        return false;
332
+    }
333 333
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
 		}
92 92
 
93 93
 		$entry['active'] = false;
94
-		if(!isset($entry['icon'])) {
94
+		if (!isset($entry['icon'])) {
95 95
 			$entry['icon'] = '';
96 96
 		}
97
-		if(!isset($entry['classes'])) {
97
+		if (!isset($entry['classes'])) {
98 98
 			$entry['classes'] = '';
99 99
 		}
100
-		if(!isset($entry['type'])) {
100
+		if (!isset($entry['type'])) {
101 101
 			$entry['type'] = 'link';
102 102
 		}
103 103
 		$this->entries[$entry['id']] = $entry;
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 			]);
230 230
 
231 231
 			$logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
232
-			if($logoutUrl !== '') {
232
+			if ($logoutUrl !== '') {
233 233
 				// Logout
234 234
 				$this->add([
235 235
 					'type' => 'settings',
Please login to merge, or discard this patch.
apps/files_sharing/appinfo/app.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
 
41 41
 $eventDispatcher = \OC::$server->getEventDispatcher();
42 42
 $eventDispatcher->addListener(
43
-	'OCA\Files::loadAdditionalScripts',
44
-	function() {
45
-		\OCP\Util::addStyle('files_sharing', 'mergedAdditionalStyles');
46
-		\OCP\Util::addScript('files_sharing', 'additionalScripts');
47
-	}
43
+    'OCA\Files::loadAdditionalScripts',
44
+    function() {
45
+        \OCP\Util::addStyle('files_sharing', 'mergedAdditionalStyles');
46
+        \OCP\Util::addScript('files_sharing', 'additionalScripts');
47
+    }
48 48
 );
49 49
 
50 50
 $config = \OC::$server->getConfig();
@@ -54,58 +54,58 @@  discard block
 block discarded – undo
54 54
 
55 55
 if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') {
56 56
 
57
-	$sharingSublistArray = [];
57
+    $sharingSublistArray = [];
58 58
 
59
-	if (\OCP\Util::isSharingDisabledForUser() === false) {
60
-		array_push($sharingSublistArray, [
61
-			'id' => 'sharingout',
62
-			'appname' => 'files_sharing',
63
-			'script' => 'list.php',
64
-			'order' => 16,
65
-			'name' => $l->t('Shared with others'),
66
-		]);
67
-	}
59
+    if (\OCP\Util::isSharingDisabledForUser() === false) {
60
+        array_push($sharingSublistArray, [
61
+            'id' => 'sharingout',
62
+            'appname' => 'files_sharing',
63
+            'script' => 'list.php',
64
+            'order' => 16,
65
+            'name' => $l->t('Shared with others'),
66
+        ]);
67
+    }
68 68
 
69
-	array_push($sharingSublistArray, [
70
-		'id' => 'sharingin',
71
-		'appname' => 'files_sharing',
72
-		'script' => 'list.php',
73
-		'order' => 15,
74
-		'name' => $l->t('Shared with you'),
75
-	]);
69
+    array_push($sharingSublistArray, [
70
+        'id' => 'sharingin',
71
+        'appname' => 'files_sharing',
72
+        'script' => 'list.php',
73
+        'order' => 15,
74
+        'name' => $l->t('Shared with you'),
75
+    ]);
76 76
 
77
-	if (\OCP\Util::isSharingDisabledForUser() === false) {
78
-		// Check if sharing by link is enabled
79
-		if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') {
80
-			array_push($sharingSublistArray, [
81
-				'id' => 'sharinglinks',
82
-				'appname' => 'files_sharing',
83
-				'script' => 'list.php',
84
-				'order' => 17,
85
-				'name' => $l->t('Shared by link'),
86
-			]);
87
-		}
88
-	}
77
+    if (\OCP\Util::isSharingDisabledForUser() === false) {
78
+        // Check if sharing by link is enabled
79
+        if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') {
80
+            array_push($sharingSublistArray, [
81
+                'id' => 'sharinglinks',
82
+                'appname' => 'files_sharing',
83
+                'script' => 'list.php',
84
+                'order' => 17,
85
+                'name' => $l->t('Shared by link'),
86
+            ]);
87
+        }
88
+    }
89 89
 
90
-	array_push($sharingSublistArray, [
91
-		'id' => 'deletedshares',
92
-		'appname' => 'files_sharing',
93
-		'script' => 'list.php',
94
-		'order' => 19,
95
-		'name' => $l->t('Deleted shares'),
96
-	]);
90
+    array_push($sharingSublistArray, [
91
+        'id' => 'deletedshares',
92
+        'appname' => 'files_sharing',
93
+        'script' => 'list.php',
94
+        'order' => 19,
95
+        'name' => $l->t('Deleted shares'),
96
+    ]);
97 97
 
98
-	// show_Quick_Access stored as string
99
-	$defaultExpandedState = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_sharing_menu', '0') === '1';
98
+    // show_Quick_Access stored as string
99
+    $defaultExpandedState = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_sharing_menu', '0') === '1';
100 100
 
101
-	\OCA\Files\App::getNavigationManager()->add([
102
-		'id' => 'shareoverview',
103
-		'appname' => 'files_sharing',
104
-		'script' => 'list.php',
105
-		'order' => 18,
106
-		'name' => $l->t('Shares'),
107
-		'classes' => 'collapsible',
108
-		'sublist' => $sharingSublistArray,
109
-		'expandedState' => 'show_sharing_menu'
110
-	]);
101
+    \OCA\Files\App::getNavigationManager()->add([
102
+        'id' => 'shareoverview',
103
+        'appname' => 'files_sharing',
104
+        'script' => 'list.php',
105
+        'order' => 18,
106
+        'name' => $l->t('Shares'),
107
+        'classes' => 'collapsible',
108
+        'sublist' => $sharingSublistArray,
109
+        'expandedState' => 'show_sharing_menu'
110
+    ]);
111 111
 }
Please login to merge, or discard this patch.
apps/files/appinfo/app.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -40,28 +40,28 @@
 block discarded – undo
40 40
 $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
41 41
 
42 42
 \OCA\Files\App::getNavigationManager()->add([
43
-	'id'      => 'files',
44
-	'appname' => 'files',
45
-	'script'  => 'list.php',
46
-	'order'   => 0,
47
-	'name'    => $l->t('All files')
43
+    'id'      => 'files',
44
+    'appname' => 'files',
45
+    'script'  => 'list.php',
46
+    'order'   => 0,
47
+    'name'    => $l->t('All files')
48 48
 ]);
49 49
 
50 50
 \OCA\Files\App::getNavigationManager()->add([
51
-	'id'      => 'recent',
52
-	'appname' => 'files',
53
-	'script'  => 'recentlist.php',
54
-	'order'   => 2,
55
-	'name'    => $l->t('Recent')
51
+    'id'      => 'recent',
52
+    'appname' => 'files',
53
+    'script'  => 'recentlist.php',
54
+    'order'   => 2,
55
+    'name'    => $l->t('Recent')
56 56
 ]);
57 57
 
58 58
 \OCA\Files\App::getNavigationManager()->add([
59
-	'id'            => 'favorites',
60
-	'appname'       => 'files',
61
-	'script'        => 'simplelist.php',
62
-	'order'         => 5,
63
-	'name'          => $l->t('Favorites'),
64
-	'expandedState' => 'show_Quick_Access'
59
+    'id'            => 'favorites',
60
+    'appname'       => 'files',
61
+    'script'        => 'simplelist.php',
62
+    'order'         => 5,
63
+    'name'          => $l->t('Favorites'),
64
+    'expandedState' => 'show_Quick_Access'
65 65
 ]);
66 66
 
67 67
 \OCP\Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig');
Please login to merge, or discard this patch.
apps/files/appinfo/routes.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -31,113 +31,113 @@
 block discarded – undo
31 31
 
32 32
 $application = new Application();
33 33
 $application->registerRoutes(
34
-	$this,
35
-	[
36
-		'routes' => [
37
-			[
38
-				'name' => 'API#getThumbnail',
39
-				'url' => '/api/v1/thumbnail/{x}/{y}/{file}',
40
-				'verb' => 'GET',
41
-				'requirements' => ['file' => '.+']
42
-			],
43
-			[
44
-				'name' => 'API#updateFileTags',
45
-				'url' => '/api/v1/files/{path}',
46
-				'verb' => 'POST',
47
-				'requirements' => ['path' => '.+'],
48
-			],
49
-			[
50
-				'name' => 'API#getRecentFiles',
51
-				'url' => '/api/v1/recent/',
52
-				'verb' => 'GET'
53
-			],
54
-			[
55
-				'name' => 'API#updateFileSorting',
56
-				'url' => '/api/v1/sorting',
57
-				'verb' => 'POST'
58
-			],
59
-			[
60
-				'name' => 'API#showHiddenFiles',
61
-				'url' => '/api/v1/showhidden',
62
-				'verb' => 'POST'
63
-			],
64
-			[
65
-				'name' => 'view#index',
66
-				'url' => '/',
67
-				'verb' => 'GET',
68
-			],
69
-			[
70
-				'name' => 'settings#setMaxUploadSize',
71
-				'url' => '/settings/maxUpload',
72
-				'verb' => 'POST',
73
-			],
74
-			[
75
-				'name' => 'ajax#getStorageStats',
76
-				'url' => '/ajax/getstoragestats.php',
77
-				'verb' => 'GET',
78
-			],
79
-			[
80
-				'name' => 'API#toggleShowFolder',
81
-				'url' => '/api/v1/toggleShowFolder/{key}',
82
-				'verb' => 'POST'
83
-			],
84
-			[
85
-				'name' => 'API#getShowQuickaccessSettings',
86
-				'url' => '/api/v1/quickaccess/showsettings',
87
-				'verb' => 'GET',
88
-			],
89
-			[
90
-				'name' => 'API#setShowQuickaccessSettings',
91
-				'url' => '/api/v1/quickaccess/set/showsettings',
92
-				'verb' => 'GET',
93
-			],
94
-			[
95
-				'name' => 'API#setSortingStrategy',
96
-				'url' => '/api/v1/quickaccess/set/SortingStrategy',
97
-				'verb' => 'GET',
98
-			],
99
-			[
100
-				'name' => 'API#setReverseQuickaccess',
101
-				'url' => '/api/v1/quickaccess/set/ReverseList',
102
-				'verb' => 'GET',
103
-			],
104
-			[
105
-				'name' => 'API#getSortingStrategy',
106
-				'url' => '/api/v1/quickaccess/get/SortingStrategy',
107
-				'verb' => 'GET',
108
-			],
109
-			[
110
-				'name' => 'API#getReverseQuickaccess',
111
-				'url' => '/api/v1/quickaccess/get/ReverseList',
112
-				'verb' => 'GET',
113
-			],
114
-			[
115
-				'name' => 'API#getFavoritesFolder',
116
-				'url' => '/api/v1/quickaccess/get/FavoriteFolders/',
117
-				'verb' => 'GET'
118
-			],
119
-			[
120
-				'name' => 'API#setSortingOrder',
121
-				'url' => '/api/v1/quickaccess/set/CustomSortingOrder',
122
-				'verb' => 'GET',
123
-			],
124
-			[
125
-				'name' => 'API#getSortingOrder',
126
-				'url' => '/api/v1/quickaccess/get/CustomSortingOrder',
127
-				'verb' => 'GET',
128
-			],
129
-			[
130
-				'name' => 'API#getNodeType',
131
-				'url' => '/api/v1/quickaccess/get/NodeType',
132
-				'verb' => 'GET',
133
-			],
134
-		]
135
-	]
34
+    $this,
35
+    [
36
+        'routes' => [
37
+            [
38
+                'name' => 'API#getThumbnail',
39
+                'url' => '/api/v1/thumbnail/{x}/{y}/{file}',
40
+                'verb' => 'GET',
41
+                'requirements' => ['file' => '.+']
42
+            ],
43
+            [
44
+                'name' => 'API#updateFileTags',
45
+                'url' => '/api/v1/files/{path}',
46
+                'verb' => 'POST',
47
+                'requirements' => ['path' => '.+'],
48
+            ],
49
+            [
50
+                'name' => 'API#getRecentFiles',
51
+                'url' => '/api/v1/recent/',
52
+                'verb' => 'GET'
53
+            ],
54
+            [
55
+                'name' => 'API#updateFileSorting',
56
+                'url' => '/api/v1/sorting',
57
+                'verb' => 'POST'
58
+            ],
59
+            [
60
+                'name' => 'API#showHiddenFiles',
61
+                'url' => '/api/v1/showhidden',
62
+                'verb' => 'POST'
63
+            ],
64
+            [
65
+                'name' => 'view#index',
66
+                'url' => '/',
67
+                'verb' => 'GET',
68
+            ],
69
+            [
70
+                'name' => 'settings#setMaxUploadSize',
71
+                'url' => '/settings/maxUpload',
72
+                'verb' => 'POST',
73
+            ],
74
+            [
75
+                'name' => 'ajax#getStorageStats',
76
+                'url' => '/ajax/getstoragestats.php',
77
+                'verb' => 'GET',
78
+            ],
79
+            [
80
+                'name' => 'API#toggleShowFolder',
81
+                'url' => '/api/v1/toggleShowFolder/{key}',
82
+                'verb' => 'POST'
83
+            ],
84
+            [
85
+                'name' => 'API#getShowQuickaccessSettings',
86
+                'url' => '/api/v1/quickaccess/showsettings',
87
+                'verb' => 'GET',
88
+            ],
89
+            [
90
+                'name' => 'API#setShowQuickaccessSettings',
91
+                'url' => '/api/v1/quickaccess/set/showsettings',
92
+                'verb' => 'GET',
93
+            ],
94
+            [
95
+                'name' => 'API#setSortingStrategy',
96
+                'url' => '/api/v1/quickaccess/set/SortingStrategy',
97
+                'verb' => 'GET',
98
+            ],
99
+            [
100
+                'name' => 'API#setReverseQuickaccess',
101
+                'url' => '/api/v1/quickaccess/set/ReverseList',
102
+                'verb' => 'GET',
103
+            ],
104
+            [
105
+                'name' => 'API#getSortingStrategy',
106
+                'url' => '/api/v1/quickaccess/get/SortingStrategy',
107
+                'verb' => 'GET',
108
+            ],
109
+            [
110
+                'name' => 'API#getReverseQuickaccess',
111
+                'url' => '/api/v1/quickaccess/get/ReverseList',
112
+                'verb' => 'GET',
113
+            ],
114
+            [
115
+                'name' => 'API#getFavoritesFolder',
116
+                'url' => '/api/v1/quickaccess/get/FavoriteFolders/',
117
+                'verb' => 'GET'
118
+            ],
119
+            [
120
+                'name' => 'API#setSortingOrder',
121
+                'url' => '/api/v1/quickaccess/set/CustomSortingOrder',
122
+                'verb' => 'GET',
123
+            ],
124
+            [
125
+                'name' => 'API#getSortingOrder',
126
+                'url' => '/api/v1/quickaccess/get/CustomSortingOrder',
127
+                'verb' => 'GET',
128
+            ],
129
+            [
130
+                'name' => 'API#getNodeType',
131
+                'url' => '/api/v1/quickaccess/get/NodeType',
132
+                'verb' => 'GET',
133
+            ],
134
+        ]
135
+    ]
136 136
 );
137 137
 
138 138
 /** @var $this \OC\Route\Router */
139 139
 
140 140
 $this->create('files_ajax_download', 'ajax/download.php')
141
-	->actionInclude('files/ajax/download.php');
141
+    ->actionInclude('files/ajax/download.php');
142 142
 $this->create('files_ajax_list', 'ajax/list.php')
143
-	->actionInclude('files/ajax/list.php');
143
+    ->actionInclude('files/ajax/list.php');
Please login to merge, or discard this patch.
apps/files/lib/Controller/ViewController.php 2 patches
Indentation   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -51,265 +51,265 @@
 block discarded – undo
51 51
  * @package OCA\Files\Controller
52 52
  */
53 53
 class ViewController extends Controller {
54
-	/** @var string */
55
-	protected $appName;
56
-	/** @var IRequest */
57
-	protected $request;
58
-	/** @var IURLGenerator */
59
-	protected $urlGenerator;
60
-	/** @var IL10N */
61
-	protected $l10n;
62
-	/** @var IConfig */
63
-	protected $config;
64
-	/** @var EventDispatcherInterface */
65
-	protected $eventDispatcher;
66
-	/** @var IUserSession */
67
-	protected $userSession;
68
-	/** @var IAppManager */
69
-	protected $appManager;
70
-	/** @var IRootFolder */
71
-	protected $rootFolder;
72
-	/** @var Helper */
73
-	protected $activityHelper;
74
-
75
-	public function __construct(string $appName,
76
-		IRequest $request,
77
-		IURLGenerator $urlGenerator,
78
-		IL10N $l10n,
79
-		IConfig $config,
80
-		EventDispatcherInterface $eventDispatcherInterface,
81
-		IUserSession $userSession,
82
-		IAppManager $appManager,
83
-		IRootFolder $rootFolder,
84
-		Helper $activityHelper
85
-	) {
86
-		parent::__construct($appName, $request);
87
-		$this->appName         = $appName;
88
-		$this->request         = $request;
89
-		$this->urlGenerator    = $urlGenerator;
90
-		$this->l10n            = $l10n;
91
-		$this->config          = $config;
92
-		$this->eventDispatcher = $eventDispatcherInterface;
93
-		$this->userSession     = $userSession;
94
-		$this->appManager      = $appManager;
95
-		$this->rootFolder      = $rootFolder;
96
-		$this->activityHelper  = $activityHelper;
97
-	}
98
-
99
-	/**
100
-	 * @param string $appName
101
-	 * @param string $scriptName
102
-	 * @return string
103
-	 */
104
-	protected function renderScript($appName, $scriptName) {
105
-		$content    = '';
106
-		$appPath    = \OC_App::getAppPath($appName);
107
-		$scriptPath = $appPath . '/' . $scriptName;
108
-		if (file_exists($scriptPath)) {
109
-			// TODO: sanitize path / script name ?
110
-			ob_start();
111
-			include $scriptPath;
112
-			$content = ob_get_contents();
113
-			@ob_end_clean();
114
-		}
115
-
116
-		return $content;
117
-	}
118
-
119
-	/**
120
-	 * FIXME: Replace with non static code
121
-	 *
122
-	 * @return array
123
-	 * @throws \OCP\Files\NotFoundException
124
-	 */
125
-	protected function getStorageInfo() {
126
-		$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
127
-
128
-		return \OC_Helper::getStorageInfo('/', $dirInfo);
129
-	}
130
-
131
-	/**
132
-	 * @NoCSRFRequired
133
-	 * @NoAdminRequired
134
-	 *
135
-	 * @param string $dir
136
-	 * @param string $view
137
-	 * @param string $fileid
138
-	 * @return TemplateResponse|RedirectResponse
139
-	 */
140
-	public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
141
-		if ($fileid !== null) {
142
-			try {
143
-				return $this->showFile($fileid);
144
-			} catch (NotFoundException $e) {
145
-				return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
146
-			}
147
-		}
148
-
149
-		$nav = new \OCP\Template('files', 'appnavigation', '');
150
-
151
-		// Load the files we need
152
-		\OCP\Util::addStyle('files', 'merged');
153
-		\OCP\Util::addScript('files', 'merged-index');
154
-
155
-		// mostly for the home storage's free space
156
-		// FIXME: Make non static
157
-		$storageInfo = $this->getStorageInfo();
158
-
159
-		$user = $this->userSession->getUser()->getUID();
160
-
161
-		// Get all the user favorites to create a submenu
162
-		try {
163
-			$favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID());
164
-		} catch (\RuntimeException $e) {
165
-			$favElements['folders'] = null;
166
-		}
167
-
168
-		$collapseClasses = '';
169
-		if (count($favElements['folders']) > 0) {
170
-			$collapseClasses = 'collapsible';
171
-		}
172
-
173
-		$favoritesSublistArray = Array();
174
-
175
-		$navBarPositionPosition = 6;
176
-		$currentCount           = 0;
177
-		foreach ($favElements['folders'] as $dir) {
178
-
179
-			$id           = substr($dir, strrpos($dir, '/') + 1, strlen($dir));
180
-			$link         = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']);
181
-			$sortingValue = ++$currentCount;
182
-			$element      = [
183
-				'id'                 => str_replace('/', '-', $dir),
184
-				'view'               => 'files',
185
-				'href'               => $link,
186
-				'dir'                => $dir,
187
-				'order'              => $navBarPositionPosition,
188
-				'folderPosition'     => $sortingValue,
189
-				'name'               => $id,
190
-				'icon'               => 'files',
191
-				'quickaccesselement' => 'true'
192
-			];
193
-
194
-			array_push($favoritesSublistArray, $element);
195
-			$navBarPositionPosition++;
196
-		}
197
-
198
-		$navItems = \OCA\Files\App::getNavigationManager()->getAll();
199
-
200
-		// add the favorites entry in menu
201
-		$navItems['favorites']['sublist'] = $favoritesSublistArray;
202
-		$navItems['favorites']['classes'] = $collapseClasses;
203
-
204
-		// parse every menu and add the expandedState user value
205
-		foreach ($navItems as $key => $item) {
206
-			if (isset($item['expandedState'])) {
207
-				$navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
208
-			}
209
-		}
210
-
211
-		$nav->assign('navigationItems', $navItems);
212
-
213
-		$nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used']));
214
-		if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
215
-			$totalSpace = $this->l10n->t('Unlimited');
216
-		} else {
217
-			$totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
218
-		}
219
-		$nav->assign('total_space', $totalSpace);
220
-		$nav->assign('quota', $storageInfo['quota']);
221
-		$nav->assign('usage_relative', $storageInfo['relative']);
222
-
223
-		$contentItems = [];
224
-
225
-		// render the container content for every navigation item
226
-		foreach ($navItems as $item) {
227
-			$content = '';
228
-			if (isset($item['script'])) {
229
-				$content = $this->renderScript($item['appname'], $item['script']);
230
-			}
231
-			// parse submenus
232
-			if (isset($item['sublist'])) {
233
-				foreach ($item['sublist'] as $subitem) {
234
-					$subcontent = '';
235
-					if (isset($subitem['script'])) {
236
-						$subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
237
-					}
238
-					$contentItems[$subitem['id']] = [
239
-						'id'      => $subitem['id'],
240
-						'content' => $subcontent
241
-					];
242
-				}
243
-			}
244
-			$contentItems[$item['id']] = [
245
-				'id'      => $item['id'],
246
-				'content' => $content
247
-			];
248
-		}
249
-
250
-		$event = new GenericEvent(null, ['hiddenFields' => []]);
251
-		$this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event);
252
-
253
-		$params                                = [];
254
-		$params['usedSpacePercent']            = (int) $storageInfo['relative'];
255
-		$params['owner']                       = $storageInfo['owner'];
256
-		$params['ownerDisplayName']            = $storageInfo['ownerDisplayName'];
257
-		$params['isPublic']                    = false;
258
-		$params['allowShareWithLink']          = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
259
-		$params['defaultFileSorting']          = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
260
-		$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
261
-		$showHidden                            = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
262
-		$params['showHiddenFiles']             = $showHidden ? 1 : 0;
263
-		$params['fileNotFound']                = $fileNotFound ? 1 : 0;
264
-		$params['appNavigation']               = $nav;
265
-		$params['appContents']                 = $contentItems;
266
-		$params['hiddenFields']                = $event->getArgument('hiddenFields');
267
-
268
-		$response = new TemplateResponse(
269
-			$this->appName,
270
-			'index',
271
-			$params
272
-		);
273
-		$policy = new ContentSecurityPolicy();
274
-		$policy->addAllowedFrameDomain('\'self\'');
275
-		$response->setContentSecurityPolicy($policy);
276
-
277
-		return $response;
278
-	}
279
-
280
-	/**
281
-	 * Redirects to the file list and highlight the given file id
282
-	 *
283
-	 * @param string $fileId file id to show
284
-	 * @return RedirectResponse redirect response or not found response
285
-	 * @throws \OCP\Files\NotFoundException
286
-	 */
287
-	private function showFile($fileId) {
288
-		$uid        = $this->userSession->getUser()->getUID();
289
-		$baseFolder = $this->rootFolder->getUserFolder($uid);
290
-		$files      = $baseFolder->getById($fileId);
291
-		$params     = [];
292
-
293
-		if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
294
-			$baseFolder     = $this->rootFolder->get($uid . '/files_trashbin/files/');
295
-			$files          = $baseFolder->getById($fileId);
296
-			$params['view'] = 'trashbin';
297
-		}
298
-
299
-		if (!empty($files)) {
300
-			$file = current($files);
301
-			if ($file instanceof Folder) {
302
-				// set the full path to enter the folder
303
-				$params['dir'] = $baseFolder->getRelativePath($file->getPath());
304
-			} else {
305
-				// set parent path as dir
306
-				$params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath());
307
-				// and scroll to the entry
308
-				$params['scrollto'] = $file->getName();
309
-			}
310
-
311
-			return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
312
-		}
313
-		throw new \OCP\Files\NotFoundException();
314
-	}
54
+    /** @var string */
55
+    protected $appName;
56
+    /** @var IRequest */
57
+    protected $request;
58
+    /** @var IURLGenerator */
59
+    protected $urlGenerator;
60
+    /** @var IL10N */
61
+    protected $l10n;
62
+    /** @var IConfig */
63
+    protected $config;
64
+    /** @var EventDispatcherInterface */
65
+    protected $eventDispatcher;
66
+    /** @var IUserSession */
67
+    protected $userSession;
68
+    /** @var IAppManager */
69
+    protected $appManager;
70
+    /** @var IRootFolder */
71
+    protected $rootFolder;
72
+    /** @var Helper */
73
+    protected $activityHelper;
74
+
75
+    public function __construct(string $appName,
76
+        IRequest $request,
77
+        IURLGenerator $urlGenerator,
78
+        IL10N $l10n,
79
+        IConfig $config,
80
+        EventDispatcherInterface $eventDispatcherInterface,
81
+        IUserSession $userSession,
82
+        IAppManager $appManager,
83
+        IRootFolder $rootFolder,
84
+        Helper $activityHelper
85
+    ) {
86
+        parent::__construct($appName, $request);
87
+        $this->appName         = $appName;
88
+        $this->request         = $request;
89
+        $this->urlGenerator    = $urlGenerator;
90
+        $this->l10n            = $l10n;
91
+        $this->config          = $config;
92
+        $this->eventDispatcher = $eventDispatcherInterface;
93
+        $this->userSession     = $userSession;
94
+        $this->appManager      = $appManager;
95
+        $this->rootFolder      = $rootFolder;
96
+        $this->activityHelper  = $activityHelper;
97
+    }
98
+
99
+    /**
100
+     * @param string $appName
101
+     * @param string $scriptName
102
+     * @return string
103
+     */
104
+    protected function renderScript($appName, $scriptName) {
105
+        $content    = '';
106
+        $appPath    = \OC_App::getAppPath($appName);
107
+        $scriptPath = $appPath . '/' . $scriptName;
108
+        if (file_exists($scriptPath)) {
109
+            // TODO: sanitize path / script name ?
110
+            ob_start();
111
+            include $scriptPath;
112
+            $content = ob_get_contents();
113
+            @ob_end_clean();
114
+        }
115
+
116
+        return $content;
117
+    }
118
+
119
+    /**
120
+     * FIXME: Replace with non static code
121
+     *
122
+     * @return array
123
+     * @throws \OCP\Files\NotFoundException
124
+     */
125
+    protected function getStorageInfo() {
126
+        $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
127
+
128
+        return \OC_Helper::getStorageInfo('/', $dirInfo);
129
+    }
130
+
131
+    /**
132
+     * @NoCSRFRequired
133
+     * @NoAdminRequired
134
+     *
135
+     * @param string $dir
136
+     * @param string $view
137
+     * @param string $fileid
138
+     * @return TemplateResponse|RedirectResponse
139
+     */
140
+    public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
141
+        if ($fileid !== null) {
142
+            try {
143
+                return $this->showFile($fileid);
144
+            } catch (NotFoundException $e) {
145
+                return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
146
+            }
147
+        }
148
+
149
+        $nav = new \OCP\Template('files', 'appnavigation', '');
150
+
151
+        // Load the files we need
152
+        \OCP\Util::addStyle('files', 'merged');
153
+        \OCP\Util::addScript('files', 'merged-index');
154
+
155
+        // mostly for the home storage's free space
156
+        // FIXME: Make non static
157
+        $storageInfo = $this->getStorageInfo();
158
+
159
+        $user = $this->userSession->getUser()->getUID();
160
+
161
+        // Get all the user favorites to create a submenu
162
+        try {
163
+            $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID());
164
+        } catch (\RuntimeException $e) {
165
+            $favElements['folders'] = null;
166
+        }
167
+
168
+        $collapseClasses = '';
169
+        if (count($favElements['folders']) > 0) {
170
+            $collapseClasses = 'collapsible';
171
+        }
172
+
173
+        $favoritesSublistArray = Array();
174
+
175
+        $navBarPositionPosition = 6;
176
+        $currentCount           = 0;
177
+        foreach ($favElements['folders'] as $dir) {
178
+
179
+            $id           = substr($dir, strrpos($dir, '/') + 1, strlen($dir));
180
+            $link         = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']);
181
+            $sortingValue = ++$currentCount;
182
+            $element      = [
183
+                'id'                 => str_replace('/', '-', $dir),
184
+                'view'               => 'files',
185
+                'href'               => $link,
186
+                'dir'                => $dir,
187
+                'order'              => $navBarPositionPosition,
188
+                'folderPosition'     => $sortingValue,
189
+                'name'               => $id,
190
+                'icon'               => 'files',
191
+                'quickaccesselement' => 'true'
192
+            ];
193
+
194
+            array_push($favoritesSublistArray, $element);
195
+            $navBarPositionPosition++;
196
+        }
197
+
198
+        $navItems = \OCA\Files\App::getNavigationManager()->getAll();
199
+
200
+        // add the favorites entry in menu
201
+        $navItems['favorites']['sublist'] = $favoritesSublistArray;
202
+        $navItems['favorites']['classes'] = $collapseClasses;
203
+
204
+        // parse every menu and add the expandedState user value
205
+        foreach ($navItems as $key => $item) {
206
+            if (isset($item['expandedState'])) {
207
+                $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
208
+            }
209
+        }
210
+
211
+        $nav->assign('navigationItems', $navItems);
212
+
213
+        $nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used']));
214
+        if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
215
+            $totalSpace = $this->l10n->t('Unlimited');
216
+        } else {
217
+            $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
218
+        }
219
+        $nav->assign('total_space', $totalSpace);
220
+        $nav->assign('quota', $storageInfo['quota']);
221
+        $nav->assign('usage_relative', $storageInfo['relative']);
222
+
223
+        $contentItems = [];
224
+
225
+        // render the container content for every navigation item
226
+        foreach ($navItems as $item) {
227
+            $content = '';
228
+            if (isset($item['script'])) {
229
+                $content = $this->renderScript($item['appname'], $item['script']);
230
+            }
231
+            // parse submenus
232
+            if (isset($item['sublist'])) {
233
+                foreach ($item['sublist'] as $subitem) {
234
+                    $subcontent = '';
235
+                    if (isset($subitem['script'])) {
236
+                        $subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
237
+                    }
238
+                    $contentItems[$subitem['id']] = [
239
+                        'id'      => $subitem['id'],
240
+                        'content' => $subcontent
241
+                    ];
242
+                }
243
+            }
244
+            $contentItems[$item['id']] = [
245
+                'id'      => $item['id'],
246
+                'content' => $content
247
+            ];
248
+        }
249
+
250
+        $event = new GenericEvent(null, ['hiddenFields' => []]);
251
+        $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event);
252
+
253
+        $params                                = [];
254
+        $params['usedSpacePercent']            = (int) $storageInfo['relative'];
255
+        $params['owner']                       = $storageInfo['owner'];
256
+        $params['ownerDisplayName']            = $storageInfo['ownerDisplayName'];
257
+        $params['isPublic']                    = false;
258
+        $params['allowShareWithLink']          = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
259
+        $params['defaultFileSorting']          = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
260
+        $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
261
+        $showHidden                            = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
262
+        $params['showHiddenFiles']             = $showHidden ? 1 : 0;
263
+        $params['fileNotFound']                = $fileNotFound ? 1 : 0;
264
+        $params['appNavigation']               = $nav;
265
+        $params['appContents']                 = $contentItems;
266
+        $params['hiddenFields']                = $event->getArgument('hiddenFields');
267
+
268
+        $response = new TemplateResponse(
269
+            $this->appName,
270
+            'index',
271
+            $params
272
+        );
273
+        $policy = new ContentSecurityPolicy();
274
+        $policy->addAllowedFrameDomain('\'self\'');
275
+        $response->setContentSecurityPolicy($policy);
276
+
277
+        return $response;
278
+    }
279
+
280
+    /**
281
+     * Redirects to the file list and highlight the given file id
282
+     *
283
+     * @param string $fileId file id to show
284
+     * @return RedirectResponse redirect response or not found response
285
+     * @throws \OCP\Files\NotFoundException
286
+     */
287
+    private function showFile($fileId) {
288
+        $uid        = $this->userSession->getUser()->getUID();
289
+        $baseFolder = $this->rootFolder->getUserFolder($uid);
290
+        $files      = $baseFolder->getById($fileId);
291
+        $params     = [];
292
+
293
+        if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
294
+            $baseFolder     = $this->rootFolder->get($uid . '/files_trashbin/files/');
295
+            $files          = $baseFolder->getById($fileId);
296
+            $params['view'] = 'trashbin';
297
+        }
298
+
299
+        if (!empty($files)) {
300
+            $file = current($files);
301
+            if ($file instanceof Folder) {
302
+                // set the full path to enter the folder
303
+                $params['dir'] = $baseFolder->getRelativePath($file->getPath());
304
+            } else {
305
+                // set parent path as dir
306
+                $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath());
307
+                // and scroll to the entry
308
+                $params['scrollto'] = $file->getName();
309
+            }
310
+
311
+            return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
312
+        }
313
+        throw new \OCP\Files\NotFoundException();
314
+    }
315 315
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	protected function renderScript($appName, $scriptName) {
105 105
 		$content    = '';
106 106
 		$appPath    = \OC_App::getAppPath($appName);
107
-		$scriptPath = $appPath . '/' . $scriptName;
107
+		$scriptPath = $appPath.'/'.$scriptName;
108 108
 		if (file_exists($scriptPath)) {
109 109
 			// TODO: sanitize path / script name ?
110 110
 			ob_start();
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 		$params     = [];
292 292
 
293 293
 		if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
294
-			$baseFolder     = $this->rootFolder->get($uid . '/files_trashbin/files/');
294
+			$baseFolder     = $this->rootFolder->get($uid.'/files_trashbin/files/');
295 295
 			$files          = $baseFolder->getById($fileId);
296 296
 			$params['view'] = 'trashbin';
297 297
 		}
Please login to merge, or discard this patch.
apps/files/templates/appnavigation.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -3,24 +3,24 @@  discard block
 block discarded – undo
3 3
 
4 4
 		<?php
5 5
 
6
-		$pinned = 0;
7
-		foreach ($_['navigationItems'] as $item) {
8
-			$pinned = NavigationListElements($item, $l, $pinned);
9
-		}
10
-		?>
6
+        $pinned = 0;
7
+        foreach ($_['navigationItems'] as $item) {
8
+            $pinned = NavigationListElements($item, $l, $pinned);
9
+        }
10
+        ?>
11 11
 
12 12
 		<li id="quota"
13 13
 			class="pinned <?php p($pinned === 0 ? 'first-pinned ' : '') ?><?php
14
-			if ($_['quota'] !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
15
-			?>has-tooltip" title="<?php p($_['usage_relative'] . '%');
16
-		} ?>">
14
+            if ($_['quota'] !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
15
+            ?>has-tooltip" title="<?php p($_['usage_relative'] . '%');
16
+        } ?>">
17 17
 			<a href="#" class="icon-quota svg">
18 18
 				<p id="quotatext"><?php
19
-					if ($_['quota'] !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
20
-						p($l->t('%s of %s used', [$_['usage'], $_['total_space']]));
21
-					} else {
22
-						p($l->t('%s used', [$_['usage']]));
23
-					} ?></p>
19
+                    if ($_['quota'] !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
20
+                        p($l->t('%s of %s used', [$_['usage'], $_['total_space']]));
21
+                    } else {
22
+                        p($l->t('%s used', [$_['usage']]));
23
+                    } ?></p>
24 24
 				<div class="quota-container">
25 25
 					<progress value="<?php p($_['usage_relative']); ?>"
26 26
 							  max="100"
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
  * @return int Returns the pinned value
65 65
  */
66 66
 function NavigationListElements($item, $l, $pinned) {
67
-	strpos($item['classes'], 'pinned') !== false ? $pinned++ : '';
68
-	?>
67
+    strpos($item['classes'], 'pinned') !== false ? $pinned++ : '';
68
+    ?>
69 69
 	<li
70 70
 		data-id="<?php p($item['id']) ?>"
71 71
 		<?php if (isset($item['dir'])) { ?> data-dir="<?php p($item['dir']); ?>" <?php } ?>
@@ -82,23 +82,23 @@  discard block
 block discarded – undo
82 82
 
83 83
 
84 84
 		<?php
85
-		NavigationElementMenu($item);
86
-		if (isset($item['sublist'])) {
87
-			?>
85
+        NavigationElementMenu($item);
86
+        if (isset($item['sublist'])) {
87
+            ?>
88 88
 			<button class="collapse app-navigation-noclose" <?php if (sizeof($item['sublist']) == 0) { ?> style="display: none" <?php } ?>></button>
89 89
 			<ul id="sublist-<?php p($item['id']); ?>">
90 90
 				<?php
91
-				foreach ($item['sublist'] as $item) {
92
-					$pinned = NavigationListElements($item, $l, $pinned);
93
-				}
94
-				?>
91
+                foreach ($item['sublist'] as $item) {
92
+                    $pinned = NavigationListElements($item, $l, $pinned);
93
+                }
94
+                ?>
95 95
 			</ul>
96 96
 		<?php } ?>
97 97
 	</li>
98 98
 
99 99
 
100 100
 	<?php
101
-	return $pinned;
101
+    return $pinned;
102 102
 }
103 103
 
104 104
 /**
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
  * @return void
110 110
  */
111 111
 function NavigationElementMenu($item) {
112
-	if (isset($item['menubuttons']) && $item['menubuttons'] === 'true') {
113
-		?>
112
+    if (isset($item['menubuttons']) && $item['menubuttons'] === 'true') {
113
+        ?>
114 114
 		<div id="dotmenu-<?php p($item['id']); ?>"
115 115
 			 class="app-navigation-entry-utils" <?php if (isset($item['enableMenuButton']) && $item['enableMenuButton'] === 0) { ?> style="display: none"<?php } ?>>
116 116
 			<ul>
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 		<li id="quota"
13 13
 			class="pinned <?php p($pinned === 0 ? 'first-pinned ' : '') ?><?php
14 14
 			if ($_['quota'] !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
15
-			?>has-tooltip" title="<?php p($_['usage_relative'] . '%');
15
+			?>has-tooltip" title="<?php p($_['usage_relative'].'%');
16 16
 		} ?>">
17 17
 			<a href="#" class="icon-quota svg">
18 18
 				<p id="quotatext"><?php
Please login to merge, or discard this patch.