Passed
Push — master ( 795881...c80e00 )
by Julius
12:34 queued 10s
created
apps/files/appinfo/routes.php 1 patch
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -39,127 +39,127 @@
 block discarded – undo
39 39
 /** @var Application $application */
40 40
 $application = \OC::$server->query(Application::class);
41 41
 $application->registerRoutes(
42
-	$this,
43
-	[
44
-		'routes' => [
45
-			[
46
-				'name' => 'View#showFile',
47
-				'url' => '/f/{fileid}',
48
-				'verb' => 'GET',
49
-				'root' => '',
50
-			],
42
+    $this,
43
+    [
44
+        'routes' => [
45
+            [
46
+                'name' => 'View#showFile',
47
+                'url' => '/f/{fileid}',
48
+                'verb' => 'GET',
49
+                'root' => '',
50
+            ],
51 51
 
52
-			[
53
-				'name' => 'API#getThumbnail',
54
-				'url' => '/api/v1/thumbnail/{x}/{y}/{file}',
55
-				'verb' => 'GET',
56
-				'requirements' => ['file' => '.+']
57
-			],
58
-			[
59
-				'name' => 'API#updateFileTags',
60
-				'url' => '/api/v1/files/{path}',
61
-				'verb' => 'POST',
62
-				'requirements' => ['path' => '.+'],
63
-			],
64
-			[
65
-				'name' => 'API#getRecentFiles',
66
-				'url' => '/api/v1/recent/',
67
-				'verb' => 'GET'
68
-			],
69
-			[
70
-				'name' => 'API#updateFileSorting',
71
-				'url' => '/api/v1/sorting',
72
-				'verb' => 'POST'
73
-			],
74
-			[
75
-				'name' => 'API#showHiddenFiles',
76
-				'url' => '/api/v1/showhidden',
77
-				'verb' => 'POST'
78
-			],
79
-			[
80
-				'name' => 'API#cropImagePreviews',
81
-				'url' => '/api/v1/cropimagepreviews',
82
-				'verb' => 'POST'
83
-			],
84
-			[
85
-				'name' => 'API#showGridView',
86
-				'url' => '/api/v1/showgridview',
87
-				'verb' => 'POST'
88
-			],
89
-			[
90
-				'name' => 'API#getGridView',
91
-				'url' => '/api/v1/showgridview',
92
-				'verb' => 'GET'
93
-			],
94
-			[
95
-				'name' => 'view#index',
96
-				'url' => '/',
97
-				'verb' => 'GET',
98
-			],
99
-			[
100
-				'name' => 'ajax#getStorageStats',
101
-				'url' => '/ajax/getstoragestats.php',
102
-				'verb' => 'GET',
103
-			],
104
-			[
105
-				'name' => 'API#toggleShowFolder',
106
-				'url' => '/api/v1/toggleShowFolder/{key}',
107
-				'verb' => 'POST'
108
-			],
109
-			[
110
-				'name' => 'API#getNodeType',
111
-				'url' => '/api/v1/quickaccess/get/NodeType',
112
-				'verb' => 'GET',
113
-			],
114
-			[
115
-				'name' => 'DirectEditingView#edit',
116
-				'url' => '/directEditing/{token}',
117
-				'verb' => 'GET'
118
-			],
119
-		],
120
-		'ocs' => [
121
-			[
122
-				'name' => 'DirectEditing#info',
123
-				'url' => '/api/v1/directEditing',
124
-				'verb' => 'GET'
125
-			],
126
-			[
127
-				'name' => 'DirectEditing#templates',
128
-				'url' => '/api/v1/directEditing/templates/{editorId}/{creatorId}',
129
-				'verb' => 'GET'
130
-			],
131
-			[
132
-				'name' => 'DirectEditing#open',
133
-				'url' => '/api/v1/directEditing/open',
134
-				'verb' => 'POST'
135
-			],
136
-			[
137
-				'name' => 'DirectEditing#create',
138
-				'url' => '/api/v1/directEditing/create',
139
-				'verb' => 'POST'
140
-			],
141
-			[
142
-				'name' => 'TransferOwnership#transfer',
143
-				'url' => '/api/v1/transferownership',
144
-				'verb' => 'POST',
145
-			],
146
-			[
147
-				'name' => 'TransferOwnership#accept',
148
-				'url' => '/api/v1/transferownership/{id}',
149
-				'verb' => 'POST',
150
-			],
151
-			[
152
-				'name' => 'TransferOwnership#reject',
153
-				'url' => '/api/v1/transferownership/{id}',
154
-				'verb' => 'DELETE',
155
-			],
156
-		],
157
-	]
52
+            [
53
+                'name' => 'API#getThumbnail',
54
+                'url' => '/api/v1/thumbnail/{x}/{y}/{file}',
55
+                'verb' => 'GET',
56
+                'requirements' => ['file' => '.+']
57
+            ],
58
+            [
59
+                'name' => 'API#updateFileTags',
60
+                'url' => '/api/v1/files/{path}',
61
+                'verb' => 'POST',
62
+                'requirements' => ['path' => '.+'],
63
+            ],
64
+            [
65
+                'name' => 'API#getRecentFiles',
66
+                'url' => '/api/v1/recent/',
67
+                'verb' => 'GET'
68
+            ],
69
+            [
70
+                'name' => 'API#updateFileSorting',
71
+                'url' => '/api/v1/sorting',
72
+                'verb' => 'POST'
73
+            ],
74
+            [
75
+                'name' => 'API#showHiddenFiles',
76
+                'url' => '/api/v1/showhidden',
77
+                'verb' => 'POST'
78
+            ],
79
+            [
80
+                'name' => 'API#cropImagePreviews',
81
+                'url' => '/api/v1/cropimagepreviews',
82
+                'verb' => 'POST'
83
+            ],
84
+            [
85
+                'name' => 'API#showGridView',
86
+                'url' => '/api/v1/showgridview',
87
+                'verb' => 'POST'
88
+            ],
89
+            [
90
+                'name' => 'API#getGridView',
91
+                'url' => '/api/v1/showgridview',
92
+                'verb' => 'GET'
93
+            ],
94
+            [
95
+                'name' => 'view#index',
96
+                'url' => '/',
97
+                'verb' => 'GET',
98
+            ],
99
+            [
100
+                'name' => 'ajax#getStorageStats',
101
+                'url' => '/ajax/getstoragestats.php',
102
+                'verb' => 'GET',
103
+            ],
104
+            [
105
+                'name' => 'API#toggleShowFolder',
106
+                'url' => '/api/v1/toggleShowFolder/{key}',
107
+                'verb' => 'POST'
108
+            ],
109
+            [
110
+                'name' => 'API#getNodeType',
111
+                'url' => '/api/v1/quickaccess/get/NodeType',
112
+                'verb' => 'GET',
113
+            ],
114
+            [
115
+                'name' => 'DirectEditingView#edit',
116
+                'url' => '/directEditing/{token}',
117
+                'verb' => 'GET'
118
+            ],
119
+        ],
120
+        'ocs' => [
121
+            [
122
+                'name' => 'DirectEditing#info',
123
+                'url' => '/api/v1/directEditing',
124
+                'verb' => 'GET'
125
+            ],
126
+            [
127
+                'name' => 'DirectEditing#templates',
128
+                'url' => '/api/v1/directEditing/templates/{editorId}/{creatorId}',
129
+                'verb' => 'GET'
130
+            ],
131
+            [
132
+                'name' => 'DirectEditing#open',
133
+                'url' => '/api/v1/directEditing/open',
134
+                'verb' => 'POST'
135
+            ],
136
+            [
137
+                'name' => 'DirectEditing#create',
138
+                'url' => '/api/v1/directEditing/create',
139
+                'verb' => 'POST'
140
+            ],
141
+            [
142
+                'name' => 'TransferOwnership#transfer',
143
+                'url' => '/api/v1/transferownership',
144
+                'verb' => 'POST',
145
+            ],
146
+            [
147
+                'name' => 'TransferOwnership#accept',
148
+                'url' => '/api/v1/transferownership/{id}',
149
+                'verb' => 'POST',
150
+            ],
151
+            [
152
+                'name' => 'TransferOwnership#reject',
153
+                'url' => '/api/v1/transferownership/{id}',
154
+                'verb' => 'DELETE',
155
+            ],
156
+        ],
157
+    ]
158 158
 );
159 159
 
160 160
 /** @var $this \OC\Route\Router */
161 161
 
162 162
 $this->create('files_ajax_download', 'apps/files/ajax/download.php')
163
-	->actionInclude('files/ajax/download.php');
163
+    ->actionInclude('files/ajax/download.php');
164 164
 $this->create('files_ajax_list', 'apps/files/ajax/list.php')
165
-	->actionInclude('files/ajax/list.php');
165
+    ->actionInclude('files/ajax/list.php');
Please login to merge, or discard this patch.
apps/files/lib/Controller/ApiController.php 2 patches
Indentation   +280 added lines, -280 removed lines patch added patch discarded remove patch
@@ -61,300 +61,300 @@
 block discarded – undo
61 61
  * @package OCA\Files\Controller
62 62
  */
63 63
 class ApiController extends Controller {
64
-	/** @var TagService */
65
-	private $tagService;
66
-	/** @var IManager * */
67
-	private $shareManager;
68
-	/** @var IPreview */
69
-	private $previewManager;
70
-	/** IUserSession */
71
-	private $userSession;
72
-	/** IConfig */
73
-	private $config;
74
-	/** @var Folder */
75
-	private $userFolder;
64
+    /** @var TagService */
65
+    private $tagService;
66
+    /** @var IManager * */
67
+    private $shareManager;
68
+    /** @var IPreview */
69
+    private $previewManager;
70
+    /** IUserSession */
71
+    private $userSession;
72
+    /** IConfig */
73
+    private $config;
74
+    /** @var Folder */
75
+    private $userFolder;
76 76
 
77
-	/**
78
-	 * @param string $appName
79
-	 * @param IRequest $request
80
-	 * @param IUserSession $userSession
81
-	 * @param TagService $tagService
82
-	 * @param IPreview $previewManager
83
-	 * @param IManager $shareManager
84
-	 * @param IConfig $config
85
-	 * @param Folder $userFolder
86
-	 */
87
-	public function __construct($appName,
88
-								IRequest $request,
89
-								IUserSession $userSession,
90
-								TagService $tagService,
91
-								IPreview $previewManager,
92
-								IManager $shareManager,
93
-								IConfig $config,
94
-								Folder $userFolder) {
95
-		parent::__construct($appName, $request);
96
-		$this->userSession = $userSession;
97
-		$this->tagService = $tagService;
98
-		$this->previewManager = $previewManager;
99
-		$this->shareManager = $shareManager;
100
-		$this->config = $config;
101
-		$this->userFolder = $userFolder;
102
-	}
77
+    /**
78
+     * @param string $appName
79
+     * @param IRequest $request
80
+     * @param IUserSession $userSession
81
+     * @param TagService $tagService
82
+     * @param IPreview $previewManager
83
+     * @param IManager $shareManager
84
+     * @param IConfig $config
85
+     * @param Folder $userFolder
86
+     */
87
+    public function __construct($appName,
88
+                                IRequest $request,
89
+                                IUserSession $userSession,
90
+                                TagService $tagService,
91
+                                IPreview $previewManager,
92
+                                IManager $shareManager,
93
+                                IConfig $config,
94
+                                Folder $userFolder) {
95
+        parent::__construct($appName, $request);
96
+        $this->userSession = $userSession;
97
+        $this->tagService = $tagService;
98
+        $this->previewManager = $previewManager;
99
+        $this->shareManager = $shareManager;
100
+        $this->config = $config;
101
+        $this->userFolder = $userFolder;
102
+    }
103 103
 
104
-	/**
105
-	 * Gets a thumbnail of the specified file
106
-	 *
107
-	 * @since API version 1.0
108
-	 *
109
-	 * @NoAdminRequired
110
-	 * @NoCSRFRequired
111
-	 * @StrictCookieRequired
112
-	 *
113
-	 * @param int $x
114
-	 * @param int $y
115
-	 * @param string $file URL-encoded filename
116
-	 * @return DataResponse|FileDisplayResponse
117
-	 */
118
-	public function getThumbnail($x, $y, $file) {
119
-		if ($x < 1 || $y < 1) {
120
-			return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
121
-		}
104
+    /**
105
+     * Gets a thumbnail of the specified file
106
+     *
107
+     * @since API version 1.0
108
+     *
109
+     * @NoAdminRequired
110
+     * @NoCSRFRequired
111
+     * @StrictCookieRequired
112
+     *
113
+     * @param int $x
114
+     * @param int $y
115
+     * @param string $file URL-encoded filename
116
+     * @return DataResponse|FileDisplayResponse
117
+     */
118
+    public function getThumbnail($x, $y, $file) {
119
+        if ($x < 1 || $y < 1) {
120
+            return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
121
+        }
122 122
 
123
-		try {
124
-			$file = $this->userFolder->get($file);
125
-			if ($file instanceof Folder) {
126
-				throw new NotFoundException();
127
-			}
123
+        try {
124
+            $file = $this->userFolder->get($file);
125
+            if ($file instanceof Folder) {
126
+                throw new NotFoundException();
127
+            }
128 128
 
129
-			/** @var File $file */
130
-			$preview = $this->previewManager->getPreview($file, $x, $y, true);
129
+            /** @var File $file */
130
+            $preview = $this->previewManager->getPreview($file, $x, $y, true);
131 131
 
132
-			return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
133
-		} catch (NotFoundException $e) {
134
-			return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
135
-		} catch (\Exception $e) {
136
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
137
-		}
138
-	}
132
+            return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
133
+        } catch (NotFoundException $e) {
134
+            return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
135
+        } catch (\Exception $e) {
136
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
137
+        }
138
+    }
139 139
 
140
-	/**
141
-	 * Updates the info of the specified file path
142
-	 * The passed tags are absolute, which means they will
143
-	 * replace the actual tag selection.
144
-	 *
145
-	 * @NoAdminRequired
146
-	 *
147
-	 * @param string $path path
148
-	 * @param array|string $tags array of tags
149
-	 * @return DataResponse
150
-	 */
151
-	public function updateFileTags($path, $tags = null) {
152
-		$result = [];
153
-		// if tags specified or empty array, update tags
154
-		if (!is_null($tags)) {
155
-			try {
156
-				$this->tagService->updateFileTags($path, $tags);
157
-			} catch (\OCP\Files\NotFoundException $e) {
158
-				return new DataResponse([
159
-					'message' => $e->getMessage()
160
-				], Http::STATUS_NOT_FOUND);
161
-			} catch (\OCP\Files\StorageNotAvailableException $e) {
162
-				return new DataResponse([
163
-					'message' => $e->getMessage()
164
-				], Http::STATUS_SERVICE_UNAVAILABLE);
165
-			} catch (\Exception $e) {
166
-				return new DataResponse([
167
-					'message' => $e->getMessage()
168
-				], Http::STATUS_NOT_FOUND);
169
-			}
170
-			$result['tags'] = $tags;
171
-		}
172
-		return new DataResponse($result);
173
-	}
140
+    /**
141
+     * Updates the info of the specified file path
142
+     * The passed tags are absolute, which means they will
143
+     * replace the actual tag selection.
144
+     *
145
+     * @NoAdminRequired
146
+     *
147
+     * @param string $path path
148
+     * @param array|string $tags array of tags
149
+     * @return DataResponse
150
+     */
151
+    public function updateFileTags($path, $tags = null) {
152
+        $result = [];
153
+        // if tags specified or empty array, update tags
154
+        if (!is_null($tags)) {
155
+            try {
156
+                $this->tagService->updateFileTags($path, $tags);
157
+            } catch (\OCP\Files\NotFoundException $e) {
158
+                return new DataResponse([
159
+                    'message' => $e->getMessage()
160
+                ], Http::STATUS_NOT_FOUND);
161
+            } catch (\OCP\Files\StorageNotAvailableException $e) {
162
+                return new DataResponse([
163
+                    'message' => $e->getMessage()
164
+                ], Http::STATUS_SERVICE_UNAVAILABLE);
165
+            } catch (\Exception $e) {
166
+                return new DataResponse([
167
+                    'message' => $e->getMessage()
168
+                ], Http::STATUS_NOT_FOUND);
169
+            }
170
+            $result['tags'] = $tags;
171
+        }
172
+        return new DataResponse($result);
173
+    }
174 174
 
175
-	/**
176
-	 * @param \OCP\Files\Node[] $nodes
177
-	 * @return array
178
-	 */
179
-	private function formatNodes(array $nodes) {
180
-		return array_values(array_map(function (Node $node) {
181
-			/** @var \OC\Files\Node\Node $shareTypes */
182
-			$shareTypes = $this->getShareTypes($node);
183
-			$file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
184
-			$file['hasPreview'] = $this->previewManager->isAvailable($node);
185
-			$parts = explode('/', dirname($node->getPath()), 4);
186
-			if (isset($parts[3])) {
187
-				$file['path'] = '/' . $parts[3];
188
-			} else {
189
-				$file['path'] = '/';
190
-			}
191
-			if (!empty($shareTypes)) {
192
-				$file['shareTypes'] = $shareTypes;
193
-			}
194
-			return $file;
195
-		}, $nodes));
196
-	}
175
+    /**
176
+     * @param \OCP\Files\Node[] $nodes
177
+     * @return array
178
+     */
179
+    private function formatNodes(array $nodes) {
180
+        return array_values(array_map(function (Node $node) {
181
+            /** @var \OC\Files\Node\Node $shareTypes */
182
+            $shareTypes = $this->getShareTypes($node);
183
+            $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
184
+            $file['hasPreview'] = $this->previewManager->isAvailable($node);
185
+            $parts = explode('/', dirname($node->getPath()), 4);
186
+            if (isset($parts[3])) {
187
+                $file['path'] = '/' . $parts[3];
188
+            } else {
189
+                $file['path'] = '/';
190
+            }
191
+            if (!empty($shareTypes)) {
192
+                $file['shareTypes'] = $shareTypes;
193
+            }
194
+            return $file;
195
+        }, $nodes));
196
+    }
197 197
 
198
-	/**
199
-	 * Returns a list of recently modifed files.
200
-	 *
201
-	 * @NoAdminRequired
202
-	 *
203
-	 * @return DataResponse
204
-	 */
205
-	public function getRecentFiles() {
206
-		$nodes = $this->userFolder->getRecent(100);
207
-		$files = $this->formatNodes($nodes);
208
-		return new DataResponse(['files' => $files]);
209
-	}
198
+    /**
199
+     * Returns a list of recently modifed files.
200
+     *
201
+     * @NoAdminRequired
202
+     *
203
+     * @return DataResponse
204
+     */
205
+    public function getRecentFiles() {
206
+        $nodes = $this->userFolder->getRecent(100);
207
+        $files = $this->formatNodes($nodes);
208
+        return new DataResponse(['files' => $files]);
209
+    }
210 210
 
211
-	/**
212
-	 * Return a list of share types for outgoing shares
213
-	 *
214
-	 * @param Node $node file node
215
-	 *
216
-	 * @return int[] array of share types
217
-	 */
218
-	private function getShareTypes(Node $node) {
219
-		$userId = $this->userSession->getUser()->getUID();
220
-		$shareTypes = [];
221
-		$requestedShareTypes = [
222
-			IShare::TYPE_USER,
223
-			IShare::TYPE_GROUP,
224
-			IShare::TYPE_LINK,
225
-			IShare::TYPE_REMOTE,
226
-			IShare::TYPE_EMAIL,
227
-			IShare::TYPE_ROOM,
228
-			IShare::TYPE_DECK,
229
-		];
230
-		foreach ($requestedShareTypes as $requestedShareType) {
231
-			// one of each type is enough to find out about the types
232
-			$shares = $this->shareManager->getSharesBy(
233
-				$userId,
234
-				$requestedShareType,
235
-				$node,
236
-				false,
237
-				1
238
-			);
239
-			if (!empty($shares)) {
240
-				$shareTypes[] = $requestedShareType;
241
-			}
242
-		}
243
-		return $shareTypes;
244
-	}
211
+    /**
212
+     * Return a list of share types for outgoing shares
213
+     *
214
+     * @param Node $node file node
215
+     *
216
+     * @return int[] array of share types
217
+     */
218
+    private function getShareTypes(Node $node) {
219
+        $userId = $this->userSession->getUser()->getUID();
220
+        $shareTypes = [];
221
+        $requestedShareTypes = [
222
+            IShare::TYPE_USER,
223
+            IShare::TYPE_GROUP,
224
+            IShare::TYPE_LINK,
225
+            IShare::TYPE_REMOTE,
226
+            IShare::TYPE_EMAIL,
227
+            IShare::TYPE_ROOM,
228
+            IShare::TYPE_DECK,
229
+        ];
230
+        foreach ($requestedShareTypes as $requestedShareType) {
231
+            // one of each type is enough to find out about the types
232
+            $shares = $this->shareManager->getSharesBy(
233
+                $userId,
234
+                $requestedShareType,
235
+                $node,
236
+                false,
237
+                1
238
+            );
239
+            if (!empty($shares)) {
240
+                $shareTypes[] = $requestedShareType;
241
+            }
242
+        }
243
+        return $shareTypes;
244
+    }
245 245
 
246
-	/**
247
-	 * Change the default sort mode
248
-	 *
249
-	 * @NoAdminRequired
250
-	 *
251
-	 * @param string $mode
252
-	 * @param string $direction
253
-	 * @return Response
254
-	 * @throws \OCP\PreConditionNotMetException
255
-	 */
256
-	public function updateFileSorting($mode, $direction) {
257
-		$allowedMode = ['name', 'size', 'mtime'];
258
-		$allowedDirection = ['asc', 'desc'];
259
-		if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
260
-			$response = new Response();
261
-			$response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
262
-			return $response;
263
-		}
264
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode);
265
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
266
-		return new Response();
267
-	}
246
+    /**
247
+     * Change the default sort mode
248
+     *
249
+     * @NoAdminRequired
250
+     *
251
+     * @param string $mode
252
+     * @param string $direction
253
+     * @return Response
254
+     * @throws \OCP\PreConditionNotMetException
255
+     */
256
+    public function updateFileSorting($mode, $direction) {
257
+        $allowedMode = ['name', 'size', 'mtime'];
258
+        $allowedDirection = ['asc', 'desc'];
259
+        if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
260
+            $response = new Response();
261
+            $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
262
+            return $response;
263
+        }
264
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode);
265
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
266
+        return new Response();
267
+    }
268 268
 
269
-	/**
270
-	 * Toggle default for showing/hiding hidden files
271
-	 *
272
-	 * @NoAdminRequired
273
-	 *
274
-	 * @param bool $show
275
-	 * @return Response
276
-	 * @throws \OCP\PreConditionNotMetException
277
-	 */
278
-	public function showHiddenFiles($show) {
279
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
280
-		return new Response();
281
-	}
269
+    /**
270
+     * Toggle default for showing/hiding hidden files
271
+     *
272
+     * @NoAdminRequired
273
+     *
274
+     * @param bool $show
275
+     * @return Response
276
+     * @throws \OCP\PreConditionNotMetException
277
+     */
278
+    public function showHiddenFiles($show) {
279
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
280
+        return new Response();
281
+    }
282 282
 
283
-	/**
284
-	 * Toggle default for cropping preview images
285
-	 *
286
-	 * @NoAdminRequired
287
-	 *
288
-	 * @param bool $crop
289
-	 * @return Response
290
-	 * @throws \OCP\PreConditionNotMetException
291
-	 */
292
-	public function cropImagePreviews($crop) {
293
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', (int)$crop);
294
-		return new Response();
295
-	}
283
+    /**
284
+     * Toggle default for cropping preview images
285
+     *
286
+     * @NoAdminRequired
287
+     *
288
+     * @param bool $crop
289
+     * @return Response
290
+     * @throws \OCP\PreConditionNotMetException
291
+     */
292
+    public function cropImagePreviews($crop) {
293
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', (int)$crop);
294
+        return new Response();
295
+    }
296 296
 
297
-	/**
298
-	 * Toggle default for files grid view
299
-	 *
300
-	 * @NoAdminRequired
301
-	 *
302
-	 * @param bool $show
303
-	 * @return Response
304
-	 * @throws \OCP\PreConditionNotMetException
305
-	 */
306
-	public function showGridView($show) {
307
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show);
308
-		return new Response();
309
-	}
297
+    /**
298
+     * Toggle default for files grid view
299
+     *
300
+     * @NoAdminRequired
301
+     *
302
+     * @param bool $show
303
+     * @return Response
304
+     * @throws \OCP\PreConditionNotMetException
305
+     */
306
+    public function showGridView($show) {
307
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show);
308
+        return new Response();
309
+    }
310 310
 
311
-	/**
312
-	 * Get default settings for the grid view
313
-	 *
314
-	 * @NoAdminRequired
315
-	 */
316
-	public function getGridView() {
317
-		$status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1';
318
-		return new JSONResponse(['gridview' => $status]);
319
-	}
311
+    /**
312
+     * Get default settings for the grid view
313
+     *
314
+     * @NoAdminRequired
315
+     */
316
+    public function getGridView() {
317
+        $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1';
318
+        return new JSONResponse(['gridview' => $status]);
319
+    }
320 320
 
321
-	/**
322
-	 * Toggle default for showing/hiding xxx folder
323
-	 *
324
-	 * @NoAdminRequired
325
-	 *
326
-	 * @param int $show
327
-	 * @param string $key the key of the folder
328
-	 *
329
-	 * @return Response
330
-	 * @throws \OCP\PreConditionNotMetException
331
-	 */
332
-	public function toggleShowFolder(int $show, string $key) {
333
-		// ensure the edited key exists
334
-		$navItems = \OCA\Files\App::getNavigationManager()->getAll();
335
-		foreach ($navItems as $item) {
336
-			// check if data is valid
337
-			if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
338
-				$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, $show);
339
-				return new Response();
340
-			}
341
-		}
342
-		$response = new Response();
343
-		$response->setStatus(Http::STATUS_FORBIDDEN);
344
-		return $response;
345
-	}
321
+    /**
322
+     * Toggle default for showing/hiding xxx folder
323
+     *
324
+     * @NoAdminRequired
325
+     *
326
+     * @param int $show
327
+     * @param string $key the key of the folder
328
+     *
329
+     * @return Response
330
+     * @throws \OCP\PreConditionNotMetException
331
+     */
332
+    public function toggleShowFolder(int $show, string $key) {
333
+        // ensure the edited key exists
334
+        $navItems = \OCA\Files\App::getNavigationManager()->getAll();
335
+        foreach ($navItems as $item) {
336
+            // check if data is valid
337
+            if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
338
+                $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, $show);
339
+                return new Response();
340
+            }
341
+        }
342
+        $response = new Response();
343
+        $response->setStatus(Http::STATUS_FORBIDDEN);
344
+        return $response;
345
+    }
346 346
 
347
-	/**
348
-	 * Get sorting-order for custom sorting
349
-	 *
350
-	 * @NoAdminRequired
351
-	 *
352
-	 * @param string $folderpath
353
-	 * @return string
354
-	 * @throws \OCP\Files\NotFoundException
355
-	 */
356
-	public function getNodeType($folderpath) {
357
-		$node = $this->userFolder->get($folderpath);
358
-		return $node->getType();
359
-	}
347
+    /**
348
+     * Get sorting-order for custom sorting
349
+     *
350
+     * @NoAdminRequired
351
+     *
352
+     * @param string $folderpath
353
+     * @return string
354
+     * @throws \OCP\Files\NotFoundException
355
+     */
356
+    public function getNodeType($folderpath) {
357
+        $node = $this->userFolder->get($folderpath);
358
+        return $node->getType();
359
+    }
360 360
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -177,14 +177,14 @@  discard block
 block discarded – undo
177 177
 	 * @return array
178 178
 	 */
179 179
 	private function formatNodes(array $nodes) {
180
-		return array_values(array_map(function (Node $node) {
180
+		return array_values(array_map(function(Node $node) {
181 181
 			/** @var \OC\Files\Node\Node $shareTypes */
182 182
 			$shareTypes = $this->getShareTypes($node);
183 183
 			$file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
184 184
 			$file['hasPreview'] = $this->previewManager->isAvailable($node);
185 185
 			$parts = explode('/', dirname($node->getPath()), 4);
186 186
 			if (isset($parts[3])) {
187
-				$file['path'] = '/' . $parts[3];
187
+				$file['path'] = '/'.$parts[3];
188 188
 			} else {
189 189
 				$file['path'] = '/';
190 190
 			}
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 	 * @throws \OCP\PreConditionNotMetException
277 277
 	 */
278 278
 	public function showHiddenFiles($show) {
279
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
279
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int) $show);
280 280
 		return new Response();
281 281
 	}
282 282
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	 * @throws \OCP\PreConditionNotMetException
291 291
 	 */
292 292
 	public function cropImagePreviews($crop) {
293
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', (int)$crop);
293
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', (int) $crop);
294 294
 		return new Response();
295 295
 	}
296 296
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 	 * @throws \OCP\PreConditionNotMetException
305 305
 	 */
306 306
 	public function showGridView($show) {
307
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show);
307
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int) $show);
308 308
 		return new Response();
309 309
 	}
310 310
 
Please login to merge, or discard this patch.
apps/files/lib/Controller/ViewController.php 1 patch
Indentation   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -60,294 +60,294 @@
 block discarded – undo
60 60
  * @package OCA\Files\Controller
61 61
  */
62 62
 class ViewController extends Controller {
63
-	/** @var string */
64
-	protected $appName;
65
-	/** @var IRequest */
66
-	protected $request;
67
-	/** @var IURLGenerator */
68
-	protected $urlGenerator;
69
-	/** @var IL10N */
70
-	protected $l10n;
71
-	/** @var IConfig */
72
-	protected $config;
73
-	/** @var IEventDispatcher */
74
-	protected $eventDispatcher;
75
-	/** @var IUserSession */
76
-	protected $userSession;
77
-	/** @var IAppManager */
78
-	protected $appManager;
79
-	/** @var IRootFolder */
80
-	protected $rootFolder;
81
-	/** @var Helper */
82
-	protected $activityHelper;
83
-
84
-	public function __construct(string $appName,
85
-		IRequest $request,
86
-		IURLGenerator $urlGenerator,
87
-		IL10N $l10n,
88
-		IConfig $config,
89
-		IEventDispatcher $eventDispatcher,
90
-		IUserSession $userSession,
91
-		IAppManager $appManager,
92
-		IRootFolder $rootFolder,
93
-		Helper $activityHelper
94
-	) {
95
-		parent::__construct($appName, $request);
96
-		$this->appName = $appName;
97
-		$this->request = $request;
98
-		$this->urlGenerator = $urlGenerator;
99
-		$this->l10n = $l10n;
100
-		$this->config = $config;
101
-		$this->eventDispatcher = $eventDispatcher;
102
-		$this->userSession = $userSession;
103
-		$this->appManager = $appManager;
104
-		$this->rootFolder = $rootFolder;
105
-		$this->activityHelper = $activityHelper;
106
-	}
107
-
108
-	/**
109
-	 * @param string $appName
110
-	 * @param string $scriptName
111
-	 * @return string
112
-	 */
113
-	protected function renderScript($appName, $scriptName) {
114
-		$content = '';
115
-		$appPath = \OC_App::getAppPath($appName);
116
-		$scriptPath = $appPath . '/' . $scriptName;
117
-		if (file_exists($scriptPath)) {
118
-			// TODO: sanitize path / script name ?
119
-			ob_start();
120
-			include $scriptPath;
121
-			$content = ob_get_contents();
122
-			@ob_end_clean();
123
-		}
124
-
125
-		return $content;
126
-	}
127
-
128
-	/**
129
-	 * FIXME: Replace with non static code
130
-	 *
131
-	 * @return array
132
-	 * @throws \OCP\Files\NotFoundException
133
-	 */
134
-	protected function getStorageInfo() {
135
-		\OC_Util::setupFS();
136
-		$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
137
-
138
-		return \OC_Helper::getStorageInfo('/', $dirInfo);
139
-	}
140
-
141
-	/**
142
-	 * @NoCSRFRequired
143
-	 * @NoAdminRequired
144
-	 *
145
-	 * @param string $fileid
146
-	 * @return TemplateResponse|RedirectResponse
147
-	 * @throws NotFoundException
148
-	 */
149
-	public function showFile(string $fileid = null): Response {
150
-		// This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server.
151
-		try {
152
-			return $this->redirectToFile($fileid);
153
-		} catch (NotFoundException $e) {
154
-			return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
155
-		}
156
-	}
157
-
158
-	/**
159
-	 * @NoCSRFRequired
160
-	 * @NoAdminRequired
161
-	 *
162
-	 * @param string $dir
163
-	 * @param string $view
164
-	 * @param string $fileid
165
-	 * @param bool $fileNotFound
166
-	 * @return TemplateResponse|RedirectResponse
167
-	 * @throws NotFoundException
168
-	 */
169
-	public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
170
-		if ($fileid !== null) {
171
-			try {
172
-				return $this->redirectToFile($fileid);
173
-			} catch (NotFoundException $e) {
174
-				return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
175
-			}
176
-		}
177
-
178
-		$nav = new \OCP\Template('files', 'appnavigation', '');
179
-
180
-		// Load the files we need
181
-		\OCP\Util::addStyle('files', 'merged');
182
-		\OCP\Util::addScript('files', 'merged-index');
183
-
184
-		// mostly for the home storage's free space
185
-		// FIXME: Make non static
186
-		$storageInfo = $this->getStorageInfo();
187
-
188
-		$user = $this->userSession->getUser()->getUID();
189
-
190
-		// Get all the user favorites to create a submenu
191
-		try {
192
-			$favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID());
193
-		} catch (\RuntimeException $e) {
194
-			$favElements['folders'] = [];
195
-		}
196
-
197
-		$collapseClasses = '';
198
-		if (count($favElements['folders']) > 0) {
199
-			$collapseClasses = 'collapsible';
200
-		}
201
-
202
-		$favoritesSublistArray = [];
203
-
204
-		$navBarPositionPosition = 6;
205
-		$currentCount = 0;
206
-		foreach ($favElements['folders'] as $dir) {
207
-			$link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']);
208
-			$sortingValue = ++$currentCount;
209
-			$element = [
210
-				'id' => str_replace('/', '-', $dir),
211
-				'view' => 'files',
212
-				'href' => $link,
213
-				'dir' => $dir,
214
-				'order' => $navBarPositionPosition,
215
-				'folderPosition' => $sortingValue,
216
-				'name' => basename($dir),
217
-				'icon' => 'files',
218
-				'quickaccesselement' => 'true'
219
-			];
220
-
221
-			array_push($favoritesSublistArray, $element);
222
-			$navBarPositionPosition++;
223
-		}
224
-
225
-		$navItems = \OCA\Files\App::getNavigationManager()->getAll();
226
-
227
-		// add the favorites entry in menu
228
-		$navItems['favorites']['sublist'] = $favoritesSublistArray;
229
-		$navItems['favorites']['classes'] = $collapseClasses;
230
-
231
-		// parse every menu and add the expandedState user value
232
-		foreach ($navItems as $key => $item) {
233
-			if (isset($item['expandedState'])) {
234
-				$navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
235
-			}
236
-		}
237
-
238
-		$nav->assign('navigationItems', $navItems);
239
-
240
-		$nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used']));
241
-		if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
242
-			$totalSpace = $this->l10n->t('Unlimited');
243
-		} else {
244
-			$totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
245
-		}
246
-		$nav->assign('total_space', $totalSpace);
247
-		$nav->assign('quota', $storageInfo['quota']);
248
-		$nav->assign('usage_relative', $storageInfo['relative']);
249
-
250
-		$nav->assign('webdav_url', \OCP\Util::linkToRemote('dav/files/' . $user));
251
-
252
-		$contentItems = [];
253
-
254
-		// render the container content for every navigation item
255
-		foreach ($navItems as $item) {
256
-			$content = '';
257
-			if (isset($item['script'])) {
258
-				$content = $this->renderScript($item['appname'], $item['script']);
259
-			}
260
-			// parse submenus
261
-			if (isset($item['sublist'])) {
262
-				foreach ($item['sublist'] as $subitem) {
263
-					$subcontent = '';
264
-					if (isset($subitem['script'])) {
265
-						$subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
266
-					}
267
-					$contentItems[$subitem['id']] = [
268
-						'id' => $subitem['id'],
269
-						'content' => $subcontent
270
-					];
271
-				}
272
-			}
273
-			$contentItems[$item['id']] = [
274
-				'id' => $item['id'],
275
-				'content' => $content
276
-			];
277
-		}
278
-
279
-		$event = new LoadAdditionalScriptsEvent();
280
-		$this->eventDispatcher->dispatchTyped($event);
281
-		$this->eventDispatcher->dispatchTyped(new LoadSidebar());
282
-		// Load Viewer scripts
283
-		if (class_exists(LoadViewer::class)) {
284
-			$this->eventDispatcher->dispatchTyped(new LoadViewer());
285
-		}
286
-
287
-		$params = [];
288
-		$params['usedSpacePercent'] = (int) $storageInfo['relative'];
289
-		$params['owner'] = $storageInfo['owner'] ?? '';
290
-		$params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? '';
291
-		$params['isPublic'] = false;
292
-		$params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
293
-		$params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
294
-		$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
295
-		$params['showgridview'] = $this->config->getUserValue($user, 'files', 'show_grid', false);
296
-		$params['isIE'] = \OCP\Util::isIE();
297
-		$showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
298
-		$params['showHiddenFiles'] = $showHidden ? 1 : 0;
299
-		$cropImagePreviews = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', true);
300
-		$params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0;
301
-		$params['fileNotFound'] = $fileNotFound ? 1 : 0;
302
-		$params['appNavigation'] = $nav;
303
-		$params['appContents'] = $contentItems;
304
-		$params['hiddenFields'] = $event->getHiddenFields();
305
-
306
-		$response = new TemplateResponse(
307
-			$this->appName,
308
-			'index',
309
-			$params
310
-		);
311
-		$policy = new ContentSecurityPolicy();
312
-		$policy->addAllowedFrameDomain('\'self\'');
313
-		$response->setContentSecurityPolicy($policy);
314
-
315
-		return $response;
316
-	}
317
-
318
-	/**
319
-	 * Redirects to the file list and highlight the given file id
320
-	 *
321
-	 * @param string $fileId file id to show
322
-	 * @return RedirectResponse redirect response or not found response
323
-	 * @throws \OCP\Files\NotFoundException
324
-	 */
325
-	private function redirectToFile($fileId) {
326
-		$uid = $this->userSession->getUser()->getUID();
327
-		$baseFolder = $this->rootFolder->getUserFolder($uid);
328
-		$files = $baseFolder->getById($fileId);
329
-		$params = [];
330
-
331
-		if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
332
-			$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
333
-			$files = $baseFolder->getById($fileId);
334
-			$params['view'] = 'trashbin';
335
-		}
336
-
337
-		if (!empty($files)) {
338
-			$file = current($files);
339
-			if ($file instanceof Folder) {
340
-				// set the full path to enter the folder
341
-				$params['dir'] = $baseFolder->getRelativePath($file->getPath());
342
-			} else {
343
-				// set parent path as dir
344
-				$params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath());
345
-				// and scroll to the entry
346
-				$params['scrollto'] = $file->getName();
347
-			}
348
-
349
-			return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
350
-		}
351
-		throw new \OCP\Files\NotFoundException();
352
-	}
63
+    /** @var string */
64
+    protected $appName;
65
+    /** @var IRequest */
66
+    protected $request;
67
+    /** @var IURLGenerator */
68
+    protected $urlGenerator;
69
+    /** @var IL10N */
70
+    protected $l10n;
71
+    /** @var IConfig */
72
+    protected $config;
73
+    /** @var IEventDispatcher */
74
+    protected $eventDispatcher;
75
+    /** @var IUserSession */
76
+    protected $userSession;
77
+    /** @var IAppManager */
78
+    protected $appManager;
79
+    /** @var IRootFolder */
80
+    protected $rootFolder;
81
+    /** @var Helper */
82
+    protected $activityHelper;
83
+
84
+    public function __construct(string $appName,
85
+        IRequest $request,
86
+        IURLGenerator $urlGenerator,
87
+        IL10N $l10n,
88
+        IConfig $config,
89
+        IEventDispatcher $eventDispatcher,
90
+        IUserSession $userSession,
91
+        IAppManager $appManager,
92
+        IRootFolder $rootFolder,
93
+        Helper $activityHelper
94
+    ) {
95
+        parent::__construct($appName, $request);
96
+        $this->appName = $appName;
97
+        $this->request = $request;
98
+        $this->urlGenerator = $urlGenerator;
99
+        $this->l10n = $l10n;
100
+        $this->config = $config;
101
+        $this->eventDispatcher = $eventDispatcher;
102
+        $this->userSession = $userSession;
103
+        $this->appManager = $appManager;
104
+        $this->rootFolder = $rootFolder;
105
+        $this->activityHelper = $activityHelper;
106
+    }
107
+
108
+    /**
109
+     * @param string $appName
110
+     * @param string $scriptName
111
+     * @return string
112
+     */
113
+    protected function renderScript($appName, $scriptName) {
114
+        $content = '';
115
+        $appPath = \OC_App::getAppPath($appName);
116
+        $scriptPath = $appPath . '/' . $scriptName;
117
+        if (file_exists($scriptPath)) {
118
+            // TODO: sanitize path / script name ?
119
+            ob_start();
120
+            include $scriptPath;
121
+            $content = ob_get_contents();
122
+            @ob_end_clean();
123
+        }
124
+
125
+        return $content;
126
+    }
127
+
128
+    /**
129
+     * FIXME: Replace with non static code
130
+     *
131
+     * @return array
132
+     * @throws \OCP\Files\NotFoundException
133
+     */
134
+    protected function getStorageInfo() {
135
+        \OC_Util::setupFS();
136
+        $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
137
+
138
+        return \OC_Helper::getStorageInfo('/', $dirInfo);
139
+    }
140
+
141
+    /**
142
+     * @NoCSRFRequired
143
+     * @NoAdminRequired
144
+     *
145
+     * @param string $fileid
146
+     * @return TemplateResponse|RedirectResponse
147
+     * @throws NotFoundException
148
+     */
149
+    public function showFile(string $fileid = null): Response {
150
+        // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server.
151
+        try {
152
+            return $this->redirectToFile($fileid);
153
+        } catch (NotFoundException $e) {
154
+            return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
155
+        }
156
+    }
157
+
158
+    /**
159
+     * @NoCSRFRequired
160
+     * @NoAdminRequired
161
+     *
162
+     * @param string $dir
163
+     * @param string $view
164
+     * @param string $fileid
165
+     * @param bool $fileNotFound
166
+     * @return TemplateResponse|RedirectResponse
167
+     * @throws NotFoundException
168
+     */
169
+    public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) {
170
+        if ($fileid !== null) {
171
+            try {
172
+                return $this->redirectToFile($fileid);
173
+            } catch (NotFoundException $e) {
174
+                return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
175
+            }
176
+        }
177
+
178
+        $nav = new \OCP\Template('files', 'appnavigation', '');
179
+
180
+        // Load the files we need
181
+        \OCP\Util::addStyle('files', 'merged');
182
+        \OCP\Util::addScript('files', 'merged-index');
183
+
184
+        // mostly for the home storage's free space
185
+        // FIXME: Make non static
186
+        $storageInfo = $this->getStorageInfo();
187
+
188
+        $user = $this->userSession->getUser()->getUID();
189
+
190
+        // Get all the user favorites to create a submenu
191
+        try {
192
+            $favElements = $this->activityHelper->getFavoriteFilePaths($this->userSession->getUser()->getUID());
193
+        } catch (\RuntimeException $e) {
194
+            $favElements['folders'] = [];
195
+        }
196
+
197
+        $collapseClasses = '';
198
+        if (count($favElements['folders']) > 0) {
199
+            $collapseClasses = 'collapsible';
200
+        }
201
+
202
+        $favoritesSublistArray = [];
203
+
204
+        $navBarPositionPosition = 6;
205
+        $currentCount = 0;
206
+        foreach ($favElements['folders'] as $dir) {
207
+            $link = $this->urlGenerator->linkToRoute('files.view.index', ['dir' => $dir, 'view' => 'files']);
208
+            $sortingValue = ++$currentCount;
209
+            $element = [
210
+                'id' => str_replace('/', '-', $dir),
211
+                'view' => 'files',
212
+                'href' => $link,
213
+                'dir' => $dir,
214
+                'order' => $navBarPositionPosition,
215
+                'folderPosition' => $sortingValue,
216
+                'name' => basename($dir),
217
+                'icon' => 'files',
218
+                'quickaccesselement' => 'true'
219
+            ];
220
+
221
+            array_push($favoritesSublistArray, $element);
222
+            $navBarPositionPosition++;
223
+        }
224
+
225
+        $navItems = \OCA\Files\App::getNavigationManager()->getAll();
226
+
227
+        // add the favorites entry in menu
228
+        $navItems['favorites']['sublist'] = $favoritesSublistArray;
229
+        $navItems['favorites']['classes'] = $collapseClasses;
230
+
231
+        // parse every menu and add the expandedState user value
232
+        foreach ($navItems as $key => $item) {
233
+            if (isset($item['expandedState'])) {
234
+                $navItems[$key]['defaultExpandedState'] = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', $item['expandedState'], '0') === '1';
235
+            }
236
+        }
237
+
238
+        $nav->assign('navigationItems', $navItems);
239
+
240
+        $nav->assign('usage', \OC_Helper::humanFileSize($storageInfo['used']));
241
+        if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
242
+            $totalSpace = $this->l10n->t('Unlimited');
243
+        } else {
244
+            $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
245
+        }
246
+        $nav->assign('total_space', $totalSpace);
247
+        $nav->assign('quota', $storageInfo['quota']);
248
+        $nav->assign('usage_relative', $storageInfo['relative']);
249
+
250
+        $nav->assign('webdav_url', \OCP\Util::linkToRemote('dav/files/' . $user));
251
+
252
+        $contentItems = [];
253
+
254
+        // render the container content for every navigation item
255
+        foreach ($navItems as $item) {
256
+            $content = '';
257
+            if (isset($item['script'])) {
258
+                $content = $this->renderScript($item['appname'], $item['script']);
259
+            }
260
+            // parse submenus
261
+            if (isset($item['sublist'])) {
262
+                foreach ($item['sublist'] as $subitem) {
263
+                    $subcontent = '';
264
+                    if (isset($subitem['script'])) {
265
+                        $subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
266
+                    }
267
+                    $contentItems[$subitem['id']] = [
268
+                        'id' => $subitem['id'],
269
+                        'content' => $subcontent
270
+                    ];
271
+                }
272
+            }
273
+            $contentItems[$item['id']] = [
274
+                'id' => $item['id'],
275
+                'content' => $content
276
+            ];
277
+        }
278
+
279
+        $event = new LoadAdditionalScriptsEvent();
280
+        $this->eventDispatcher->dispatchTyped($event);
281
+        $this->eventDispatcher->dispatchTyped(new LoadSidebar());
282
+        // Load Viewer scripts
283
+        if (class_exists(LoadViewer::class)) {
284
+            $this->eventDispatcher->dispatchTyped(new LoadViewer());
285
+        }
286
+
287
+        $params = [];
288
+        $params['usedSpacePercent'] = (int) $storageInfo['relative'];
289
+        $params['owner'] = $storageInfo['owner'] ?? '';
290
+        $params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? '';
291
+        $params['isPublic'] = false;
292
+        $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
293
+        $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
294
+        $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
295
+        $params['showgridview'] = $this->config->getUserValue($user, 'files', 'show_grid', false);
296
+        $params['isIE'] = \OCP\Util::isIE();
297
+        $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
298
+        $params['showHiddenFiles'] = $showHidden ? 1 : 0;
299
+        $cropImagePreviews = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', true);
300
+        $params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0;
301
+        $params['fileNotFound'] = $fileNotFound ? 1 : 0;
302
+        $params['appNavigation'] = $nav;
303
+        $params['appContents'] = $contentItems;
304
+        $params['hiddenFields'] = $event->getHiddenFields();
305
+
306
+        $response = new TemplateResponse(
307
+            $this->appName,
308
+            'index',
309
+            $params
310
+        );
311
+        $policy = new ContentSecurityPolicy();
312
+        $policy->addAllowedFrameDomain('\'self\'');
313
+        $response->setContentSecurityPolicy($policy);
314
+
315
+        return $response;
316
+    }
317
+
318
+    /**
319
+     * Redirects to the file list and highlight the given file id
320
+     *
321
+     * @param string $fileId file id to show
322
+     * @return RedirectResponse redirect response or not found response
323
+     * @throws \OCP\Files\NotFoundException
324
+     */
325
+    private function redirectToFile($fileId) {
326
+        $uid = $this->userSession->getUser()->getUID();
327
+        $baseFolder = $this->rootFolder->getUserFolder($uid);
328
+        $files = $baseFolder->getById($fileId);
329
+        $params = [];
330
+
331
+        if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
332
+            $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
333
+            $files = $baseFolder->getById($fileId);
334
+            $params['view'] = 'trashbin';
335
+        }
336
+
337
+        if (!empty($files)) {
338
+            $file = current($files);
339
+            if ($file instanceof Folder) {
340
+                // set the full path to enter the folder
341
+                $params['dir'] = $baseFolder->getRelativePath($file->getPath());
342
+            } else {
343
+                // set parent path as dir
344
+                $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath());
345
+                // and scroll to the entry
346
+                $params['scrollto'] = $file->getName();
347
+            }
348
+
349
+            return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
350
+        }
351
+        throw new \OCP\Files\NotFoundException();
352
+    }
353 353
 }
Please login to merge, or discard this patch.