Completed
Push — master ( eba447...1a7516 )
by Blizzz
18:31
created
lib/private/Archive/TAR.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -370,6 +370,7 @@
 block discarded – undo
370 370
 
371 371
 	/**
372 372
 	 * write back temporary files
373
+	 * @param string $path
373 374
 	 */
374 375
 	public function writeBack($tmpFile, $path) {
375 376
 		$this->addFile($path, $tmpFile);
Please login to merge, or discard this patch.
Indentation   +326 added lines, -326 removed lines patch added patch discarded remove patch
@@ -35,350 +35,350 @@
 block discarded – undo
35 35
 use Icewind\Streams\CallbackWrapper;
36 36
 
37 37
 class TAR extends Archive {
38
-	const PLAIN = 0;
39
-	const GZIP = 1;
40
-	const BZIP = 2;
38
+    const PLAIN = 0;
39
+    const GZIP = 1;
40
+    const BZIP = 2;
41 41
 
42
-	private $fileList;
43
-	private $cachedHeaders;
42
+    private $fileList;
43
+    private $cachedHeaders;
44 44
 
45
-	/**
46
-	 * @var \Archive_Tar tar
47
-	 */
48
-	private $tar = null;
49
-	private $path;
45
+    /**
46
+     * @var \Archive_Tar tar
47
+     */
48
+    private $tar = null;
49
+    private $path;
50 50
 
51
-	/**
52
-	 * @param string $source
53
-	 */
54
-	public function __construct($source) {
55
-		$types = array(null, 'gz', 'bz2');
56
-		$this->path = $source;
57
-		$this->tar = new \Archive_Tar($source, $types[self::getTarType($source)]);
58
-	}
51
+    /**
52
+     * @param string $source
53
+     */
54
+    public function __construct($source) {
55
+        $types = array(null, 'gz', 'bz2');
56
+        $this->path = $source;
57
+        $this->tar = new \Archive_Tar($source, $types[self::getTarType($source)]);
58
+    }
59 59
 
60
-	/**
61
-	 * try to detect the type of tar compression
62
-	 *
63
-	 * @param string $file
64
-	 * @return integer
65
-	 */
66
-	static public function getTarType($file) {
67
-		if (strpos($file, '.')) {
68
-			$extension = substr($file, strrpos($file, '.'));
69
-			switch ($extension) {
70
-				case '.gz':
71
-				case '.tgz':
72
-					return self::GZIP;
73
-				case '.bz':
74
-				case '.bz2':
75
-					return self::BZIP;
76
-				case '.tar':
77
-					return self::PLAIN;
78
-				default:
79
-					return self::PLAIN;
80
-			}
81
-		} else {
82
-			return self::PLAIN;
83
-		}
84
-	}
60
+    /**
61
+     * try to detect the type of tar compression
62
+     *
63
+     * @param string $file
64
+     * @return integer
65
+     */
66
+    static public function getTarType($file) {
67
+        if (strpos($file, '.')) {
68
+            $extension = substr($file, strrpos($file, '.'));
69
+            switch ($extension) {
70
+                case '.gz':
71
+                case '.tgz':
72
+                    return self::GZIP;
73
+                case '.bz':
74
+                case '.bz2':
75
+                    return self::BZIP;
76
+                case '.tar':
77
+                    return self::PLAIN;
78
+                default:
79
+                    return self::PLAIN;
80
+            }
81
+        } else {
82
+            return self::PLAIN;
83
+        }
84
+    }
85 85
 
86
-	/**
87
-	 * add an empty folder to the archive
88
-	 *
89
-	 * @param string $path
90
-	 * @return bool
91
-	 */
92
-	public function addFolder($path) {
93
-		$tmpBase = \OC::$server->getTempManager()->getTemporaryFolder();
94
-		$path = rtrim($path, '/') . '/';
95
-		if ($this->fileExists($path)) {
96
-			return false;
97
-		}
98
-		$parts = explode('/', $path);
99
-		$folder = $tmpBase;
100
-		foreach ($parts as $part) {
101
-			$folder .= '/' . $part;
102
-			if (!is_dir($folder)) {
103
-				mkdir($folder);
104
-			}
105
-		}
106
-		$result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase);
107
-		rmdir($tmpBase . $path);
108
-		$this->fileList = false;
109
-		$this->cachedHeaders = false;
110
-		return $result;
111
-	}
86
+    /**
87
+     * add an empty folder to the archive
88
+     *
89
+     * @param string $path
90
+     * @return bool
91
+     */
92
+    public function addFolder($path) {
93
+        $tmpBase = \OC::$server->getTempManager()->getTemporaryFolder();
94
+        $path = rtrim($path, '/') . '/';
95
+        if ($this->fileExists($path)) {
96
+            return false;
97
+        }
98
+        $parts = explode('/', $path);
99
+        $folder = $tmpBase;
100
+        foreach ($parts as $part) {
101
+            $folder .= '/' . $part;
102
+            if (!is_dir($folder)) {
103
+                mkdir($folder);
104
+            }
105
+        }
106
+        $result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase);
107
+        rmdir($tmpBase . $path);
108
+        $this->fileList = false;
109
+        $this->cachedHeaders = false;
110
+        return $result;
111
+    }
112 112
 
113
-	/**
114
-	 * add a file to the archive
115
-	 *
116
-	 * @param string $path
117
-	 * @param string $source either a local file or string data
118
-	 * @return bool
119
-	 */
120
-	public function addFile($path, $source = '') {
121
-		if ($this->fileExists($path)) {
122
-			$this->remove($path);
123
-		}
124
-		if ($source and $source[0] == '/' and file_exists($source)) {
125
-			$source = file_get_contents($source);
126
-		}
127
-		$result = $this->tar->addString($path, $source);
128
-		$this->fileList = false;
129
-		$this->cachedHeaders = false;
130
-		return $result;
131
-	}
113
+    /**
114
+     * add a file to the archive
115
+     *
116
+     * @param string $path
117
+     * @param string $source either a local file or string data
118
+     * @return bool
119
+     */
120
+    public function addFile($path, $source = '') {
121
+        if ($this->fileExists($path)) {
122
+            $this->remove($path);
123
+        }
124
+        if ($source and $source[0] == '/' and file_exists($source)) {
125
+            $source = file_get_contents($source);
126
+        }
127
+        $result = $this->tar->addString($path, $source);
128
+        $this->fileList = false;
129
+        $this->cachedHeaders = false;
130
+        return $result;
131
+    }
132 132
 
133
-	/**
134
-	 * rename a file or folder in the archive
135
-	 *
136
-	 * @param string $source
137
-	 * @param string $dest
138
-	 * @return bool
139
-	 */
140
-	public function rename($source, $dest) {
141
-		//no proper way to delete, rename entire archive, rename file and remake archive
142
-		$tmp = \OC::$server->getTempManager()->getTemporaryFolder();
143
-		$this->tar->extract($tmp);
144
-		rename($tmp . $source, $tmp . $dest);
145
-		$this->tar = null;
146
-		unlink($this->path);
147
-		$types = array(null, 'gz', 'bz');
148
-		$this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
149
-		$this->tar->createModify(array($tmp), '', $tmp . '/');
150
-		$this->fileList = false;
151
-		$this->cachedHeaders = false;
152
-		return true;
153
-	}
133
+    /**
134
+     * rename a file or folder in the archive
135
+     *
136
+     * @param string $source
137
+     * @param string $dest
138
+     * @return bool
139
+     */
140
+    public function rename($source, $dest) {
141
+        //no proper way to delete, rename entire archive, rename file and remake archive
142
+        $tmp = \OC::$server->getTempManager()->getTemporaryFolder();
143
+        $this->tar->extract($tmp);
144
+        rename($tmp . $source, $tmp . $dest);
145
+        $this->tar = null;
146
+        unlink($this->path);
147
+        $types = array(null, 'gz', 'bz');
148
+        $this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
149
+        $this->tar->createModify(array($tmp), '', $tmp . '/');
150
+        $this->fileList = false;
151
+        $this->cachedHeaders = false;
152
+        return true;
153
+    }
154 154
 
155
-	/**
156
-	 * @param string $file
157
-	 */
158
-	private function getHeader($file) {
159
-		if (!$this->cachedHeaders) {
160
-			$this->cachedHeaders = $this->tar->listContent();
161
-		}
162
-		foreach ($this->cachedHeaders as $header) {
163
-			if ($file == $header['filename']
164
-				or $file . '/' == $header['filename']
165
-				or '/' . $file . '/' == $header['filename']
166
-				or '/' . $file == $header['filename']
167
-			) {
168
-				return $header;
169
-			}
170
-		}
171
-		return null;
172
-	}
155
+    /**
156
+     * @param string $file
157
+     */
158
+    private function getHeader($file) {
159
+        if (!$this->cachedHeaders) {
160
+            $this->cachedHeaders = $this->tar->listContent();
161
+        }
162
+        foreach ($this->cachedHeaders as $header) {
163
+            if ($file == $header['filename']
164
+                or $file . '/' == $header['filename']
165
+                or '/' . $file . '/' == $header['filename']
166
+                or '/' . $file == $header['filename']
167
+            ) {
168
+                return $header;
169
+            }
170
+        }
171
+        return null;
172
+    }
173 173
 
174
-	/**
175
-	 * get the uncompressed size of a file in the archive
176
-	 *
177
-	 * @param string $path
178
-	 * @return int
179
-	 */
180
-	public function filesize($path) {
181
-		$stat = $this->getHeader($path);
182
-		return $stat['size'];
183
-	}
174
+    /**
175
+     * get the uncompressed size of a file in the archive
176
+     *
177
+     * @param string $path
178
+     * @return int
179
+     */
180
+    public function filesize($path) {
181
+        $stat = $this->getHeader($path);
182
+        return $stat['size'];
183
+    }
184 184
 
185
-	/**
186
-	 * get the last modified time of a file in the archive
187
-	 *
188
-	 * @param string $path
189
-	 * @return int
190
-	 */
191
-	public function mtime($path) {
192
-		$stat = $this->getHeader($path);
193
-		return $stat['mtime'];
194
-	}
185
+    /**
186
+     * get the last modified time of a file in the archive
187
+     *
188
+     * @param string $path
189
+     * @return int
190
+     */
191
+    public function mtime($path) {
192
+        $stat = $this->getHeader($path);
193
+        return $stat['mtime'];
194
+    }
195 195
 
196
-	/**
197
-	 * get the files in a folder
198
-	 *
199
-	 * @param string $path
200
-	 * @return array
201
-	 */
202
-	public function getFolder($path) {
203
-		$files = $this->getFiles();
204
-		$folderContent = array();
205
-		$pathLength = strlen($path);
206
-		foreach ($files as $file) {
207
-			if ($file[0] == '/') {
208
-				$file = substr($file, 1);
209
-			}
210
-			if (substr($file, 0, $pathLength) == $path and $file != $path) {
211
-				$result = substr($file, $pathLength);
212
-				if ($pos = strpos($result, '/')) {
213
-					$result = substr($result, 0, $pos + 1);
214
-				}
215
-				if (array_search($result, $folderContent) === false) {
216
-					$folderContent[] = $result;
217
-				}
218
-			}
219
-		}
220
-		return $folderContent;
221
-	}
196
+    /**
197
+     * get the files in a folder
198
+     *
199
+     * @param string $path
200
+     * @return array
201
+     */
202
+    public function getFolder($path) {
203
+        $files = $this->getFiles();
204
+        $folderContent = array();
205
+        $pathLength = strlen($path);
206
+        foreach ($files as $file) {
207
+            if ($file[0] == '/') {
208
+                $file = substr($file, 1);
209
+            }
210
+            if (substr($file, 0, $pathLength) == $path and $file != $path) {
211
+                $result = substr($file, $pathLength);
212
+                if ($pos = strpos($result, '/')) {
213
+                    $result = substr($result, 0, $pos + 1);
214
+                }
215
+                if (array_search($result, $folderContent) === false) {
216
+                    $folderContent[] = $result;
217
+                }
218
+            }
219
+        }
220
+        return $folderContent;
221
+    }
222 222
 
223
-	/**
224
-	 * get all files in the archive
225
-	 *
226
-	 * @return array
227
-	 */
228
-	public function getFiles() {
229
-		if ($this->fileList) {
230
-			return $this->fileList;
231
-		}
232
-		if (!$this->cachedHeaders) {
233
-			$this->cachedHeaders = $this->tar->listContent();
234
-		}
235
-		$files = array();
236
-		foreach ($this->cachedHeaders as $header) {
237
-			$files[] = $header['filename'];
238
-		}
239
-		$this->fileList = $files;
240
-		return $files;
241
-	}
223
+    /**
224
+     * get all files in the archive
225
+     *
226
+     * @return array
227
+     */
228
+    public function getFiles() {
229
+        if ($this->fileList) {
230
+            return $this->fileList;
231
+        }
232
+        if (!$this->cachedHeaders) {
233
+            $this->cachedHeaders = $this->tar->listContent();
234
+        }
235
+        $files = array();
236
+        foreach ($this->cachedHeaders as $header) {
237
+            $files[] = $header['filename'];
238
+        }
239
+        $this->fileList = $files;
240
+        return $files;
241
+    }
242 242
 
243
-	/**
244
-	 * get the content of a file
245
-	 *
246
-	 * @param string $path
247
-	 * @return string
248
-	 */
249
-	public function getFile($path) {
250
-		return $this->tar->extractInString($path);
251
-	}
243
+    /**
244
+     * get the content of a file
245
+     *
246
+     * @param string $path
247
+     * @return string
248
+     */
249
+    public function getFile($path) {
250
+        return $this->tar->extractInString($path);
251
+    }
252 252
 
253
-	/**
254
-	 * extract a single file from the archive
255
-	 *
256
-	 * @param string $path
257
-	 * @param string $dest
258
-	 * @return bool
259
-	 */
260
-	public function extractFile($path, $dest) {
261
-		$tmp = \OC::$server->getTempManager()->getTemporaryFolder();
262
-		if (!$this->fileExists($path)) {
263
-			return false;
264
-		}
265
-		if ($this->fileExists('/' . $path)) {
266
-			$success = $this->tar->extractList(array('/' . $path), $tmp);
267
-		} else {
268
-			$success = $this->tar->extractList(array($path), $tmp);
269
-		}
270
-		if ($success) {
271
-			rename($tmp . $path, $dest);
272
-		}
273
-		\OCP\Files::rmdirr($tmp);
274
-		return $success;
275
-	}
253
+    /**
254
+     * extract a single file from the archive
255
+     *
256
+     * @param string $path
257
+     * @param string $dest
258
+     * @return bool
259
+     */
260
+    public function extractFile($path, $dest) {
261
+        $tmp = \OC::$server->getTempManager()->getTemporaryFolder();
262
+        if (!$this->fileExists($path)) {
263
+            return false;
264
+        }
265
+        if ($this->fileExists('/' . $path)) {
266
+            $success = $this->tar->extractList(array('/' . $path), $tmp);
267
+        } else {
268
+            $success = $this->tar->extractList(array($path), $tmp);
269
+        }
270
+        if ($success) {
271
+            rename($tmp . $path, $dest);
272
+        }
273
+        \OCP\Files::rmdirr($tmp);
274
+        return $success;
275
+    }
276 276
 
277
-	/**
278
-	 * extract the archive
279
-	 *
280
-	 * @param string $dest
281
-	 * @return bool
282
-	 */
283
-	public function extract($dest) {
284
-		return $this->tar->extract($dest);
285
-	}
277
+    /**
278
+     * extract the archive
279
+     *
280
+     * @param string $dest
281
+     * @return bool
282
+     */
283
+    public function extract($dest) {
284
+        return $this->tar->extract($dest);
285
+    }
286 286
 
287
-	/**
288
-	 * check if a file or folder exists in the archive
289
-	 *
290
-	 * @param string $path
291
-	 * @return bool
292
-	 */
293
-	public function fileExists($path) {
294
-		$files = $this->getFiles();
295
-		if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) {
296
-			return true;
297
-		} else {
298
-			$folderPath = rtrim($path, '/') . '/';
299
-			$pathLength = strlen($folderPath);
300
-			foreach ($files as $file) {
301
-				if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) {
302
-					return true;
303
-				}
304
-			}
305
-		}
306
-		if ($path[0] != '/') { //not all programs agree on the use of a leading /
307
-			return $this->fileExists('/' . $path);
308
-		} else {
309
-			return false;
310
-		}
311
-	}
287
+    /**
288
+     * check if a file or folder exists in the archive
289
+     *
290
+     * @param string $path
291
+     * @return bool
292
+     */
293
+    public function fileExists($path) {
294
+        $files = $this->getFiles();
295
+        if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) {
296
+            return true;
297
+        } else {
298
+            $folderPath = rtrim($path, '/') . '/';
299
+            $pathLength = strlen($folderPath);
300
+            foreach ($files as $file) {
301
+                if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) {
302
+                    return true;
303
+                }
304
+            }
305
+        }
306
+        if ($path[0] != '/') { //not all programs agree on the use of a leading /
307
+            return $this->fileExists('/' . $path);
308
+        } else {
309
+            return false;
310
+        }
311
+    }
312 312
 
313
-	/**
314
-	 * remove a file or folder from the archive
315
-	 *
316
-	 * @param string $path
317
-	 * @return bool
318
-	 */
319
-	public function remove($path) {
320
-		if (!$this->fileExists($path)) {
321
-			return false;
322
-		}
323
-		$this->fileList = false;
324
-		$this->cachedHeaders = false;
325
-		//no proper way to delete, extract entire archive, delete file and remake archive
326
-		$tmp = \OC::$server->getTempManager()->getTemporaryFolder();
327
-		$this->tar->extract($tmp);
328
-		\OCP\Files::rmdirr($tmp . $path);
329
-		$this->tar = null;
330
-		unlink($this->path);
331
-		$this->reopen();
332
-		$this->tar->createModify(array($tmp), '', $tmp);
333
-		return true;
334
-	}
313
+    /**
314
+     * remove a file or folder from the archive
315
+     *
316
+     * @param string $path
317
+     * @return bool
318
+     */
319
+    public function remove($path) {
320
+        if (!$this->fileExists($path)) {
321
+            return false;
322
+        }
323
+        $this->fileList = false;
324
+        $this->cachedHeaders = false;
325
+        //no proper way to delete, extract entire archive, delete file and remake archive
326
+        $tmp = \OC::$server->getTempManager()->getTemporaryFolder();
327
+        $this->tar->extract($tmp);
328
+        \OCP\Files::rmdirr($tmp . $path);
329
+        $this->tar = null;
330
+        unlink($this->path);
331
+        $this->reopen();
332
+        $this->tar->createModify(array($tmp), '', $tmp);
333
+        return true;
334
+    }
335 335
 
336
-	/**
337
-	 * get a file handler
338
-	 *
339
-	 * @param string $path
340
-	 * @param string $mode
341
-	 * @return resource
342
-	 */
343
-	public function getStream($path, $mode) {
344
-		if (strrpos($path, '.') !== false) {
345
-			$ext = substr($path, strrpos($path, '.'));
346
-		} else {
347
-			$ext = '';
348
-		}
349
-		$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
350
-		if ($this->fileExists($path)) {
351
-			$this->extractFile($path, $tmpFile);
352
-		} elseif ($mode == 'r' or $mode == 'rb') {
353
-			return false;
354
-		}
355
-		if ($mode == 'r' or $mode == 'rb') {
356
-			return fopen($tmpFile, $mode);
357
-		} else {
358
-			$handle = fopen($tmpFile, $mode);
359
-			return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
360
-				$this->writeBack($tmpFile, $path);
361
-			});
362
-		}
363
-	}
336
+    /**
337
+     * get a file handler
338
+     *
339
+     * @param string $path
340
+     * @param string $mode
341
+     * @return resource
342
+     */
343
+    public function getStream($path, $mode) {
344
+        if (strrpos($path, '.') !== false) {
345
+            $ext = substr($path, strrpos($path, '.'));
346
+        } else {
347
+            $ext = '';
348
+        }
349
+        $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
350
+        if ($this->fileExists($path)) {
351
+            $this->extractFile($path, $tmpFile);
352
+        } elseif ($mode == 'r' or $mode == 'rb') {
353
+            return false;
354
+        }
355
+        if ($mode == 'r' or $mode == 'rb') {
356
+            return fopen($tmpFile, $mode);
357
+        } else {
358
+            $handle = fopen($tmpFile, $mode);
359
+            return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
360
+                $this->writeBack($tmpFile, $path);
361
+            });
362
+        }
363
+    }
364 364
 
365
-	/**
366
-	 * write back temporary files
367
-	 */
368
-	public function writeBack($tmpFile, $path) {
369
-		$this->addFile($path, $tmpFile);
370
-		unlink($tmpFile);
371
-	}
365
+    /**
366
+     * write back temporary files
367
+     */
368
+    public function writeBack($tmpFile, $path) {
369
+        $this->addFile($path, $tmpFile);
370
+        unlink($tmpFile);
371
+    }
372 372
 
373
-	/**
374
-	 * reopen the archive to ensure everything is written
375
-	 */
376
-	private function reopen() {
377
-		if ($this->tar) {
378
-			$this->tar->_close();
379
-			$this->tar = null;
380
-		}
381
-		$types = array(null, 'gz', 'bz');
382
-		$this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
383
-	}
373
+    /**
374
+     * reopen the archive to ensure everything is written
375
+     */
376
+    private function reopen() {
377
+        if ($this->tar) {
378
+            $this->tar->_close();
379
+            $this->tar = null;
380
+        }
381
+        $types = array(null, 'gz', 'bz');
382
+        $this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
383
+    }
384 384
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -91,20 +91,20 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public function addFolder($path) {
93 93
 		$tmpBase = \OC::$server->getTempManager()->getTemporaryFolder();
94
-		$path = rtrim($path, '/') . '/';
94
+		$path = rtrim($path, '/').'/';
95 95
 		if ($this->fileExists($path)) {
96 96
 			return false;
97 97
 		}
98 98
 		$parts = explode('/', $path);
99 99
 		$folder = $tmpBase;
100 100
 		foreach ($parts as $part) {
101
-			$folder .= '/' . $part;
101
+			$folder .= '/'.$part;
102 102
 			if (!is_dir($folder)) {
103 103
 				mkdir($folder);
104 104
 			}
105 105
 		}
106
-		$result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase);
107
-		rmdir($tmpBase . $path);
106
+		$result = $this->tar->addModify(array($tmpBase.$path), '', $tmpBase);
107
+		rmdir($tmpBase.$path);
108 108
 		$this->fileList = false;
109 109
 		$this->cachedHeaders = false;
110 110
 		return $result;
@@ -141,12 +141,12 @@  discard block
 block discarded – undo
141 141
 		//no proper way to delete, rename entire archive, rename file and remake archive
142 142
 		$tmp = \OC::$server->getTempManager()->getTemporaryFolder();
143 143
 		$this->tar->extract($tmp);
144
-		rename($tmp . $source, $tmp . $dest);
144
+		rename($tmp.$source, $tmp.$dest);
145 145
 		$this->tar = null;
146 146
 		unlink($this->path);
147 147
 		$types = array(null, 'gz', 'bz');
148 148
 		$this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
149
-		$this->tar->createModify(array($tmp), '', $tmp . '/');
149
+		$this->tar->createModify(array($tmp), '', $tmp.'/');
150 150
 		$this->fileList = false;
151 151
 		$this->cachedHeaders = false;
152 152
 		return true;
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 		}
162 162
 		foreach ($this->cachedHeaders as $header) {
163 163
 			if ($file == $header['filename']
164
-				or $file . '/' == $header['filename']
165
-				or '/' . $file . '/' == $header['filename']
166
-				or '/' . $file == $header['filename']
164
+				or $file.'/' == $header['filename']
165
+				or '/'.$file.'/' == $header['filename']
166
+				or '/'.$file == $header['filename']
167 167
 			) {
168 168
 				return $header;
169 169
 			}
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
 		if (!$this->fileExists($path)) {
263 263
 			return false;
264 264
 		}
265
-		if ($this->fileExists('/' . $path)) {
266
-			$success = $this->tar->extractList(array('/' . $path), $tmp);
265
+		if ($this->fileExists('/'.$path)) {
266
+			$success = $this->tar->extractList(array('/'.$path), $tmp);
267 267
 		} else {
268 268
 			$success = $this->tar->extractList(array($path), $tmp);
269 269
 		}
270 270
 		if ($success) {
271
-			rename($tmp . $path, $dest);
271
+			rename($tmp.$path, $dest);
272 272
 		}
273 273
 		\OCP\Files::rmdirr($tmp);
274 274
 		return $success;
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
 	 */
293 293
 	public function fileExists($path) {
294 294
 		$files = $this->getFiles();
295
-		if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) {
295
+		if ((array_search($path, $files) !== false) or (array_search($path.'/', $files) !== false)) {
296 296
 			return true;
297 297
 		} else {
298
-			$folderPath = rtrim($path, '/') . '/';
298
+			$folderPath = rtrim($path, '/').'/';
299 299
 			$pathLength = strlen($folderPath);
300 300
 			foreach ($files as $file) {
301 301
 				if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) {
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 			}
305 305
 		}
306 306
 		if ($path[0] != '/') { //not all programs agree on the use of a leading /
307
-			return $this->fileExists('/' . $path);
307
+			return $this->fileExists('/'.$path);
308 308
 		} else {
309 309
 			return false;
310 310
 		}
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 		//no proper way to delete, extract entire archive, delete file and remake archive
326 326
 		$tmp = \OC::$server->getTempManager()->getTemporaryFolder();
327 327
 		$this->tar->extract($tmp);
328
-		\OCP\Files::rmdirr($tmp . $path);
328
+		\OCP\Files::rmdirr($tmp.$path);
329 329
 		$this->tar = null;
330 330
 		unlink($this->path);
331 331
 		$this->reopen();
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 			return fopen($tmpFile, $mode);
357 357
 		} else {
358 358
 			$handle = fopen($tmpFile, $mode);
359
-			return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
359
+			return CallbackWrapper::wrap($handle, null, null, function() use ($path, $tmpFile) {
360 360
 				$this->writeBack($tmpFile, $path);
361 361
 			});
362 362
 		}
Please login to merge, or discard this patch.
lib/private/Security/TrustedDomainHelper.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -32,68 +32,68 @@
 block discarded – undo
32 32
  * @package OC\Security
33 33
  */
34 34
 class TrustedDomainHelper {
35
-	/** @var IConfig */
36
-	private $config;
35
+    /** @var IConfig */
36
+    private $config;
37 37
 
38
-	/**
39
-	 * @param IConfig $config
40
-	 */
41
-	public function __construct(IConfig $config) {
42
-		$this->config = $config;
43
-	}
38
+    /**
39
+     * @param IConfig $config
40
+     */
41
+    public function __construct(IConfig $config) {
42
+        $this->config = $config;
43
+    }
44 44
 
45
-	/**
46
-	 * Strips a potential port from a domain (in format domain:port)
47
-	 * @param string $host
48
-	 * @return string $host without appended port
49
-	 */
50
-	private function getDomainWithoutPort($host) {
51
-		$pos = strrpos($host, ':');
52
-		if ($pos !== false) {
53
-			$port = substr($host, $pos + 1);
54
-			if (is_numeric($port)) {
55
-				$host = substr($host, 0, $pos);
56
-			}
57
-		}
58
-		return $host;
59
-	}
45
+    /**
46
+     * Strips a potential port from a domain (in format domain:port)
47
+     * @param string $host
48
+     * @return string $host without appended port
49
+     */
50
+    private function getDomainWithoutPort($host) {
51
+        $pos = strrpos($host, ':');
52
+        if ($pos !== false) {
53
+            $port = substr($host, $pos + 1);
54
+            if (is_numeric($port)) {
55
+                $host = substr($host, 0, $pos);
56
+            }
57
+        }
58
+        return $host;
59
+    }
60 60
 
61
-	/**
62
-	 * Checks whether a domain is considered as trusted from the list
63
-	 * of trusted domains. If no trusted domains have been configured, returns
64
-	 * true.
65
-	 * This is used to prevent Host Header Poisoning.
66
-	 * @param string $domainWithPort
67
-	 * @return bool true if the given domain is trusted or if no trusted domains
68
-	 * have been configured
69
-	 */
70
-	public function isTrustedDomain($domainWithPort) {
71
-		$domain = $this->getDomainWithoutPort($domainWithPort);
61
+    /**
62
+     * Checks whether a domain is considered as trusted from the list
63
+     * of trusted domains. If no trusted domains have been configured, returns
64
+     * true.
65
+     * This is used to prevent Host Header Poisoning.
66
+     * @param string $domainWithPort
67
+     * @return bool true if the given domain is trusted or if no trusted domains
68
+     * have been configured
69
+     */
70
+    public function isTrustedDomain($domainWithPort) {
71
+        $domain = $this->getDomainWithoutPort($domainWithPort);
72 72
 
73
-		// Read trusted domains from config
74
-		$trustedList = $this->config->getSystemValue('trusted_domains', []);
75
-		if (!is_array($trustedList)) {
76
-			return false;
77
-		}
73
+        // Read trusted domains from config
74
+        $trustedList = $this->config->getSystemValue('trusted_domains', []);
75
+        if (!is_array($trustedList)) {
76
+            return false;
77
+        }
78 78
 
79
-		// Always allow access from localhost
80
-		if (preg_match(Request::REGEX_LOCALHOST, $domain) === 1) {
81
-			return true;
82
-		}
83
-		// Reject misformed domains in any case
84
-		if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) {
85
-			return false;
86
-		}
87
-		// Match, allowing for * wildcards
88
-		foreach ($trustedList as $trusted) {
89
-			if (gettype($trusted) !== 'string') {
90
-				break;
91
-			}
92
-			$regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/';
93
-			if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) {
94
- 				return true;
95
- 			}
96
- 		}
97
- 		return false;
98
-	}
79
+        // Always allow access from localhost
80
+        if (preg_match(Request::REGEX_LOCALHOST, $domain) === 1) {
81
+            return true;
82
+        }
83
+        // Reject misformed domains in any case
84
+        if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) {
85
+            return false;
86
+        }
87
+        // Match, allowing for * wildcards
88
+        foreach ($trustedList as $trusted) {
89
+            if (gettype($trusted) !== 'string') {
90
+                break;
91
+            }
92
+            $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/';
93
+            if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) {
94
+                    return true;
95
+                }
96
+            }
97
+            return false;
98
+    }
99 99
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 			return true;
82 82
 		}
83 83
 		// Reject misformed domains in any case
84
-		if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) {
84
+		if (strpos($domain, '-') === 0 || strpos($domain, '..') !== false) {
85 85
 			return false;
86 86
 		}
87 87
 		// Match, allowing for * wildcards
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 			if (gettype($trusted) !== 'string') {
90 90
 				break;
91 91
 			}
92
-			$regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/';
92
+			$regex = '/^'.implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))).'$/';
93 93
 			if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) {
94 94
  				return true;
95 95
  			}
Please login to merge, or discard this patch.
apps/files_sharing/lib/Command/CleanupRemoteStorages.php 2 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -34,147 +34,147 @@
 block discarded – undo
34 34
  */
35 35
 class CleanupRemoteStorages extends Command {
36 36
 
37
-	/**
38
-	 * @var IDBConnection
39
-	 */
40
-	protected $connection;
41
-
42
-	public function __construct(IDBConnection $connection) {
43
-		$this->connection = $connection;
44
-		parent::__construct();
45
-	}
46
-
47
-	protected function configure() {
48
-		$this
49
-			->setName('sharing:cleanup-remote-storages')
50
-			->setDescription('Cleanup shared storage entries that have no matching entry in the shares_external table')
51
-			->addOption(
52
-				'dry-run',
53
-				null,
54
-				InputOption::VALUE_NONE,
55
-				'only show which storages would be deleted'
56
-			);
57
-	}
58
-
59
-	public function execute(InputInterface $input, OutputInterface $output) {
60
-
61
-		$remoteStorages = $this->getRemoteStorages();
62
-
63
-		$output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked');
64
-
65
-		$remoteShareIds = $this->getRemoteShareIds();
66
-
67
-		$output->writeln(count($remoteShareIds) . ' remote share(s) exist');
68
-
69
-		foreach ($remoteShareIds as $id => $remoteShareId) {
70
-			if (isset($remoteStorages[$remoteShareId])) {
71
-				if ($input->getOption('dry-run') || $output->isVerbose()) {
72
-					$output->writeln("<info>$remoteShareId belongs to remote share $id</info>");
73
-				}
74
-
75
-				unset($remoteStorages[$remoteShareId]);
76
-			} else {
77
-				$output->writeln("<comment>$remoteShareId for share $id has no matching storage, yet</comment>");
78
-			}
79
-		}
80
-
81
-		if (empty($remoteStorages)) {
82
-			$output->writeln('<info>no storages deleted</info>');
83
-		} else {
84
-			$dryRun = $input->getOption('dry-run');
85
-			foreach ($remoteStorages as $id => $numericId) {
86
-				if ($dryRun) {
87
-					$output->writeln("<error>$id [$numericId] can be deleted</error>");
88
-					$this->countFiles($numericId, $output);
89
-				} else {
90
-					$this->deleteStorage($id, $numericId, $output);
91
-				}
92
-			}
93
-		}
94
-	}
95
-
96
-	public function countFiles($numericId, OutputInterface $output) {
97
-		$queryBuilder = $this->connection->getQueryBuilder();
98
-		$queryBuilder->select($queryBuilder->createFunction('count(fileid)'))
99
-			->from('filecache')
100
-			->where($queryBuilder->expr()->eq(
101
-				'storage',
102
-				$queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR),
103
-				IQueryBuilder::PARAM_STR)
104
-			);
105
-		$result = $queryBuilder->execute();
106
-		$count = $result->fetchColumn();
107
-		$output->writeln("$count files can be deleted for storage $numericId");
108
-	}
109
-
110
-	public function deleteStorage($id, $numericId, OutputInterface $output) {
111
-		$queryBuilder = $this->connection->getQueryBuilder();
112
-		$queryBuilder->delete('storages')
113
-			->where($queryBuilder->expr()->eq(
114
-				'id',
115
-				$queryBuilder->createNamedParameter($id, IQueryBuilder::PARAM_STR),
116
-				IQueryBuilder::PARAM_STR)
117
-			);
118
-		$output->write("deleting $id [$numericId] ... ");
119
-		$count = $queryBuilder->execute();
120
-		$output->writeln("deleted $count storage");
121
-		$this->deleteFiles($numericId, $output);
122
-	}
123
-
124
-	public function deleteFiles($numericId, OutputInterface $output) {
125
-		$queryBuilder = $this->connection->getQueryBuilder();
126
-		$queryBuilder->delete('filecache')
127
-			->where($queryBuilder->expr()->eq(
128
-				'storage',
129
-				$queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR),
130
-				IQueryBuilder::PARAM_STR)
131
-			);
132
-		$output->write("deleting files for storage $numericId ... ");
133
-		$count = $queryBuilder->execute();
134
-		$output->writeln("deleted $count files");
135
-	}
136
-
137
-	public function getRemoteStorages() {
138
-
139
-		$queryBuilder = $this->connection->getQueryBuilder();
140
-		$queryBuilder->select(['id', 'numeric_id'])
141
-			->from('storages')
142
-			->where($queryBuilder->expr()->like(
143
-				'id',
144
-				// match all 'shared::' + 32 characters storages
145
-				$queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)),
146
-				IQueryBuilder::PARAM_STR)
147
-			)
148
-			->andWhere($queryBuilder->expr()->notLike(
149
-				'id',
150
-				// but not the ones starting with a '/', they are for normal shares
151
-				$queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'),
152
-				IQueryBuilder::PARAM_STR)
153
-			)->orderBy('numeric_id');
154
-		$query = $queryBuilder->execute();
155
-
156
-		$remoteStorages = [];
157
-
158
-		while ($row = $query->fetch()) {
159
-			$remoteStorages[$row['id']] = $row['numeric_id'];
160
-		}
161
-
162
-		return $remoteStorages;
163
-	}
164
-
165
-	public function getRemoteShareIds() {
166
-
167
-		$queryBuilder = $this->connection->getQueryBuilder();
168
-		$queryBuilder->select(['id', 'share_token', 'remote'])
169
-			->from('share_external');
170
-		$query = $queryBuilder->execute();
171
-
172
-		$remoteShareIds = [];
173
-
174
-		while ($row = $query->fetch()) {
175
-			$remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']);
176
-		}
177
-
178
-		return $remoteShareIds;
179
-	}
37
+    /**
38
+     * @var IDBConnection
39
+     */
40
+    protected $connection;
41
+
42
+    public function __construct(IDBConnection $connection) {
43
+        $this->connection = $connection;
44
+        parent::__construct();
45
+    }
46
+
47
+    protected function configure() {
48
+        $this
49
+            ->setName('sharing:cleanup-remote-storages')
50
+            ->setDescription('Cleanup shared storage entries that have no matching entry in the shares_external table')
51
+            ->addOption(
52
+                'dry-run',
53
+                null,
54
+                InputOption::VALUE_NONE,
55
+                'only show which storages would be deleted'
56
+            );
57
+    }
58
+
59
+    public function execute(InputInterface $input, OutputInterface $output) {
60
+
61
+        $remoteStorages = $this->getRemoteStorages();
62
+
63
+        $output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked');
64
+
65
+        $remoteShareIds = $this->getRemoteShareIds();
66
+
67
+        $output->writeln(count($remoteShareIds) . ' remote share(s) exist');
68
+
69
+        foreach ($remoteShareIds as $id => $remoteShareId) {
70
+            if (isset($remoteStorages[$remoteShareId])) {
71
+                if ($input->getOption('dry-run') || $output->isVerbose()) {
72
+                    $output->writeln("<info>$remoteShareId belongs to remote share $id</info>");
73
+                }
74
+
75
+                unset($remoteStorages[$remoteShareId]);
76
+            } else {
77
+                $output->writeln("<comment>$remoteShareId for share $id has no matching storage, yet</comment>");
78
+            }
79
+        }
80
+
81
+        if (empty($remoteStorages)) {
82
+            $output->writeln('<info>no storages deleted</info>');
83
+        } else {
84
+            $dryRun = $input->getOption('dry-run');
85
+            foreach ($remoteStorages as $id => $numericId) {
86
+                if ($dryRun) {
87
+                    $output->writeln("<error>$id [$numericId] can be deleted</error>");
88
+                    $this->countFiles($numericId, $output);
89
+                } else {
90
+                    $this->deleteStorage($id, $numericId, $output);
91
+                }
92
+            }
93
+        }
94
+    }
95
+
96
+    public function countFiles($numericId, OutputInterface $output) {
97
+        $queryBuilder = $this->connection->getQueryBuilder();
98
+        $queryBuilder->select($queryBuilder->createFunction('count(fileid)'))
99
+            ->from('filecache')
100
+            ->where($queryBuilder->expr()->eq(
101
+                'storage',
102
+                $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR),
103
+                IQueryBuilder::PARAM_STR)
104
+            );
105
+        $result = $queryBuilder->execute();
106
+        $count = $result->fetchColumn();
107
+        $output->writeln("$count files can be deleted for storage $numericId");
108
+    }
109
+
110
+    public function deleteStorage($id, $numericId, OutputInterface $output) {
111
+        $queryBuilder = $this->connection->getQueryBuilder();
112
+        $queryBuilder->delete('storages')
113
+            ->where($queryBuilder->expr()->eq(
114
+                'id',
115
+                $queryBuilder->createNamedParameter($id, IQueryBuilder::PARAM_STR),
116
+                IQueryBuilder::PARAM_STR)
117
+            );
118
+        $output->write("deleting $id [$numericId] ... ");
119
+        $count = $queryBuilder->execute();
120
+        $output->writeln("deleted $count storage");
121
+        $this->deleteFiles($numericId, $output);
122
+    }
123
+
124
+    public function deleteFiles($numericId, OutputInterface $output) {
125
+        $queryBuilder = $this->connection->getQueryBuilder();
126
+        $queryBuilder->delete('filecache')
127
+            ->where($queryBuilder->expr()->eq(
128
+                'storage',
129
+                $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR),
130
+                IQueryBuilder::PARAM_STR)
131
+            );
132
+        $output->write("deleting files for storage $numericId ... ");
133
+        $count = $queryBuilder->execute();
134
+        $output->writeln("deleted $count files");
135
+    }
136
+
137
+    public function getRemoteStorages() {
138
+
139
+        $queryBuilder = $this->connection->getQueryBuilder();
140
+        $queryBuilder->select(['id', 'numeric_id'])
141
+            ->from('storages')
142
+            ->where($queryBuilder->expr()->like(
143
+                'id',
144
+                // match all 'shared::' + 32 characters storages
145
+                $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)),
146
+                IQueryBuilder::PARAM_STR)
147
+            )
148
+            ->andWhere($queryBuilder->expr()->notLike(
149
+                'id',
150
+                // but not the ones starting with a '/', they are for normal shares
151
+                $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'),
152
+                IQueryBuilder::PARAM_STR)
153
+            )->orderBy('numeric_id');
154
+        $query = $queryBuilder->execute();
155
+
156
+        $remoteStorages = [];
157
+
158
+        while ($row = $query->fetch()) {
159
+            $remoteStorages[$row['id']] = $row['numeric_id'];
160
+        }
161
+
162
+        return $remoteStorages;
163
+    }
164
+
165
+    public function getRemoteShareIds() {
166
+
167
+        $queryBuilder = $this->connection->getQueryBuilder();
168
+        $queryBuilder->select(['id', 'share_token', 'remote'])
169
+            ->from('share_external');
170
+        $query = $queryBuilder->execute();
171
+
172
+        $remoteShareIds = [];
173
+
174
+        while ($row = $query->fetch()) {
175
+            $remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']);
176
+        }
177
+
178
+        return $remoteShareIds;
179
+    }
180 180
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 
61 61
 		$remoteStorages = $this->getRemoteStorages();
62 62
 
63
-		$output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked');
63
+		$output->writeln(count($remoteStorages).' remote storage(s) need(s) to be checked');
64 64
 
65 65
 		$remoteShareIds = $this->getRemoteShareIds();
66 66
 
67
-		$output->writeln(count($remoteShareIds) . ' remote share(s) exist');
67
+		$output->writeln(count($remoteShareIds).' remote share(s) exist');
68 68
 
69 69
 		foreach ($remoteShareIds as $id => $remoteShareId) {
70 70
 			if (isset($remoteStorages[$remoteShareId])) {
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
 			->where($queryBuilder->expr()->like(
143 143
 				'id',
144 144
 				// match all 'shared::' + 32 characters storages
145
-				$queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)),
145
+				$queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::').str_repeat('_', 32)),
146 146
 				IQueryBuilder::PARAM_STR)
147 147
 			)
148 148
 			->andWhere($queryBuilder->expr()->notLike(
149 149
 				'id',
150 150
 				// but not the ones starting with a '/', they are for normal shares
151
-				$queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'),
151
+				$queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/').'%'),
152 152
 				IQueryBuilder::PARAM_STR)
153 153
 			)->orderBy('numeric_id');
154 154
 		$query = $queryBuilder->execute();
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 		$remoteShareIds = [];
173 173
 
174 174
 		while ($row = $query->fetch()) {
175
-			$remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']);
175
+			$remoteShareIds[$row['id']] = 'shared::'.md5($row['share_token'].'@'.$row['remote']);
176 176
 		}
177 177
 
178 178
 		return $remoteShareIds;
Please login to merge, or discard this patch.
lib/private/legacy/template/functions.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@
 block discarded – undo
106 106
 /**
107 107
  * Prints an unsanitized string - usage of this function may result into XSS.
108 108
  * Consider using p() instead.
109
- * @param string|array $string the string which will be printed as it is
109
+ * @param string $string the string which will be printed as it is
110 110
  */
111 111
 function print_unescaped($string) {
112 112
 	print($string);
Please login to merge, or discard this patch.
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
  * @param string $string the string which will be escaped and printed
37 37
  */
38 38
 function p($string) {
39
-	print(\OCP\Util::sanitizeHTML($string));
39
+    print(\OCP\Util::sanitizeHTML($string));
40 40
 }
41 41
 
42 42
 
@@ -46,14 +46,14 @@  discard block
 block discarded – undo
46 46
  * @param string $opts, additional optional options
47 47
 */
48 48
 function emit_css_tag($href, $opts = '') {
49
-	$s='<link rel="stylesheet"';
50
-	if (!empty($href)) {
51
-		$s.=' href="' . $href .'"';
52
-	}
53
-	if (!empty($opts)) {
54
-		$s.=' '.$opts;
55
-	}
56
-	print_unescaped($s.">\n");
49
+    $s='<link rel="stylesheet"';
50
+    if (!empty($href)) {
51
+        $s.=' href="' . $href .'"';
52
+    }
53
+    if (!empty($opts)) {
54
+        $s.=' '.$opts;
55
+    }
56
+    print_unescaped($s.">\n");
57 57
 }
58 58
 
59 59
 /**
@@ -61,12 +61,12 @@  discard block
 block discarded – undo
61 61
  * @param array $obj all the script information from template
62 62
 */
63 63
 function emit_css_loading_tags($obj) {
64
-	foreach($obj['cssfiles'] as $css) {
65
-		emit_css_tag($css);
66
-	}
67
-	foreach($obj['printcssfiles'] as $css) {
68
-		emit_css_tag($css, 'media="print"');
69
-	}
64
+    foreach($obj['cssfiles'] as $css) {
65
+        emit_css_tag($css);
66
+    }
67
+    foreach($obj['printcssfiles'] as $css) {
68
+        emit_css_tag($css, 'media="print"');
69
+    }
70 70
 }
71 71
 
72 72
 /**
@@ -75,20 +75,20 @@  discard block
 block discarded – undo
75 75
  * @param string $script_content the inline script content, ignored when empty
76 76
 */
77 77
 function emit_script_tag($src, $script_content='') {
78
-	$defer_str=' defer';
79
-	$s='<script nonce="' . \OC::$server->getContentSecurityPolicyNonceManager()->getNonce() . '"';
80
-	if (!empty($src)) {
81
-		 // emit script tag for deferred loading from $src
82
-		$s.=$defer_str.' src="' . $src .'">';
83
-	} else if (!empty($script_content)) {
84
-		// emit script tag for inline script from $script_content without defer (see MDN)
85
-		$s.=">\n".$script_content."\n";
86
-	} else {
87
-		// no $src nor $src_content, really useless empty tag
88
-		$s.='>';
89
-	}
90
-	$s.='</script>';
91
-	print_unescaped($s."\n");
78
+    $defer_str=' defer';
79
+    $s='<script nonce="' . \OC::$server->getContentSecurityPolicyNonceManager()->getNonce() . '"';
80
+    if (!empty($src)) {
81
+            // emit script tag for deferred loading from $src
82
+        $s.=$defer_str.' src="' . $src .'">';
83
+    } else if (!empty($script_content)) {
84
+        // emit script tag for inline script from $script_content without defer (see MDN)
85
+        $s.=">\n".$script_content."\n";
86
+    } else {
87
+        // no $src nor $src_content, really useless empty tag
88
+        $s.='>';
89
+    }
90
+    $s.='</script>';
91
+    print_unescaped($s."\n");
92 92
 }
93 93
 
94 94
 /**
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
  * @param array $obj all the script information from template
97 97
 */
98 98
 function emit_script_loading_tags($obj) {
99
-	foreach($obj['jsfiles'] as $jsfile) {
100
-		emit_script_tag($jsfile, '');
101
-	}
102
-	if (!empty($obj['inline_ocjs'])) {
103
-		emit_script_tag('', $obj['inline_ocjs']);
104
-	}
99
+    foreach($obj['jsfiles'] as $jsfile) {
100
+        emit_script_tag($jsfile, '');
101
+    }
102
+    if (!empty($obj['inline_ocjs'])) {
103
+        emit_script_tag('', $obj['inline_ocjs']);
104
+    }
105 105
 }
106 106
 
107 107
 /**
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
  * @param string|array $string the string which will be printed as it is
111 111
  */
112 112
 function print_unescaped($string) {
113
-	print($string);
113
+    print($string);
114 114
 }
115 115
 
116 116
 /**
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
  * if an array is given it will add all scripts
121 121
  */
122 122
 function script($app, $file = null) {
123
-	if(is_array($file)) {
124
-		foreach($file as $f) {
125
-			OC_Util::addScript($app, $f);
126
-		}
127
-	} else {
128
-		OC_Util::addScript($app, $file);
129
-	}
123
+    if(is_array($file)) {
124
+        foreach($file as $f) {
125
+            OC_Util::addScript($app, $f);
126
+        }
127
+    } else {
128
+        OC_Util::addScript($app, $file);
129
+    }
130 130
 }
131 131
 
132 132
 /**
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
  * if an array is given it will add all scripts
137 137
  */
138 138
 function vendor_script($app, $file = null) {
139
-	if(is_array($file)) {
140
-		foreach($file as $f) {
141
-			OC_Util::addVendorScript($app, $f);
142
-		}
143
-	} else {
144
-		OC_Util::addVendorScript($app, $file);
145
-	}
139
+    if(is_array($file)) {
140
+        foreach($file as $f) {
141
+            OC_Util::addVendorScript($app, $f);
142
+        }
143
+    } else {
144
+        OC_Util::addVendorScript($app, $file);
145
+    }
146 146
 }
147 147
 
148 148
 /**
@@ -152,13 +152,13 @@  discard block
 block discarded – undo
152 152
  * if an array is given it will add all styles
153 153
  */
154 154
 function style($app, $file = null) {
155
-	if(is_array($file)) {
156
-		foreach($file as $f) {
157
-			OC_Util::addStyle($app, $f);
158
-		}
159
-	} else {
160
-		OC_Util::addStyle($app, $file);
161
-	}
155
+    if(is_array($file)) {
156
+        foreach($file as $f) {
157
+            OC_Util::addStyle($app, $f);
158
+        }
159
+    } else {
160
+        OC_Util::addStyle($app, $file);
161
+    }
162 162
 }
163 163
 
164 164
 /**
@@ -168,13 +168,13 @@  discard block
 block discarded – undo
168 168
  * if an array is given it will add all styles
169 169
  */
170 170
 function vendor_style($app, $file = null) {
171
-	if(is_array($file)) {
172
-		foreach($file as $f) {
173
-			OC_Util::addVendorStyle($app, $f);
174
-		}
175
-	} else {
176
-		OC_Util::addVendorStyle($app, $file);
177
-	}
171
+    if(is_array($file)) {
172
+        foreach($file as $f) {
173
+            OC_Util::addVendorStyle($app, $f);
174
+        }
175
+    } else {
176
+        OC_Util::addVendorStyle($app, $file);
177
+    }
178 178
 }
179 179
 
180 180
 /**
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
  * if an array is given it will add all styles
184 184
  */
185 185
 function translation($app) {
186
-	OC_Util::addTranslations($app);
186
+    OC_Util::addTranslations($app);
187 187
 }
188 188
 
189 189
 /**
@@ -193,15 +193,15 @@  discard block
 block discarded – undo
193 193
  * if an array is given it will add all components
194 194
  */
195 195
 function component($app, $file) {
196
-	if(is_array($file)) {
197
-		foreach($file as $f) {
198
-			$url = link_to($app, 'component/' . $f . '.html');
199
-			OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
200
-		}
201
-	} else {
202
-		$url = link_to($app, 'component/' . $file . '.html');
203
-		OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
204
-	}
196
+    if(is_array($file)) {
197
+        foreach($file as $f) {
198
+            $url = link_to($app, 'component/' . $f . '.html');
199
+            OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
200
+        }
201
+    } else {
202
+        $url = link_to($app, 'component/' . $file . '.html');
203
+        OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
204
+    }
205 205
 }
206 206
 
207 207
 /**
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
  * For further information have a look at \OCP\IURLGenerator::linkTo
215 215
  */
216 216
 function link_to( $app, $file, $args = array() ) {
217
-	return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
217
+    return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
218 218
 }
219 219
 
220 220
 /**
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
  * @return string url to the online documentation
223 223
  */
224 224
 function link_to_docs($key) {
225
-	return \OC::$server->getURLGenerator()->linkToDocs($key);
225
+    return \OC::$server->getURLGenerator()->linkToDocs($key);
226 226
 }
227 227
 
228 228
 /**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
  * For further information have a look at \OCP\IURLGenerator::imagePath
235 235
  */
236 236
 function image_path( $app, $image ) {
237
-	return \OC::$server->getURLGenerator()->imagePath( $app, $image );
237
+    return \OC::$server->getURLGenerator()->imagePath( $app, $image );
238 238
 }
239 239
 
240 240
 /**
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
  * @return string link to the image
244 244
  */
245 245
 function mimetype_icon( $mimetype ) {
246
-	return \OC::$server->getMimeTypeDetector()->mimeTypeIcon( $mimetype );
246
+    return \OC::$server->getMimeTypeDetector()->mimeTypeIcon( $mimetype );
247 247
 }
248 248
 
249 249
 /**
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
  * @return string link to the preview
254 254
  */
255 255
 function preview_icon( $path ) {
256
-	return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]);
256
+    return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]);
257 257
 }
258 258
 
259 259
 /**
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
  * @return string
263 263
  */
264 264
 function publicPreview_icon ( $path, $token ) {
265
-	return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 'token' => $token]);
265
+    return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 'token' => $token]);
266 266
 }
267 267
 
268 268
 /**
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
  * For further information have a look at OC_Helper::humanFileSize
274 274
  */
275 275
 function human_file_size( $bytes ) {
276
-	return OC_Helper::humanFileSize( $bytes );
276
+    return OC_Helper::humanFileSize( $bytes );
277 277
 }
278 278
 
279 279
 /**
@@ -282,9 +282,9 @@  discard block
 block discarded – undo
282 282
  * @return int timestamp without time value
283 283
  */
284 284
 function strip_time($timestamp){
285
-	$date = new \DateTime("@{$timestamp}");
286
-	$date->setTime(0, 0, 0);
287
-	return (int)$date->format('U');
285
+    $date = new \DateTime("@{$timestamp}");
286
+    $date->setTime(0, 0, 0);
287
+    return (int)$date->format('U');
288 288
 }
289 289
 
290 290
 /**
@@ -296,39 +296,39 @@  discard block
 block discarded – undo
296 296
  * @return string timestamp
297 297
  */
298 298
 function relative_modified_date($timestamp, $fromTime = null, $dateOnly = false) {
299
-	/** @var \OC\DateTimeFormatter $formatter */
300
-	$formatter = \OC::$server->query('DateTimeFormatter');
299
+    /** @var \OC\DateTimeFormatter $formatter */
300
+    $formatter = \OC::$server->query('DateTimeFormatter');
301 301
 
302
-	if ($dateOnly){
303
-		return $formatter->formatDateSpan($timestamp, $fromTime);
304
-	}
305
-	return $formatter->formatTimeSpan($timestamp, $fromTime);
302
+    if ($dateOnly){
303
+        return $formatter->formatDateSpan($timestamp, $fromTime);
304
+    }
305
+    return $formatter->formatTimeSpan($timestamp, $fromTime);
306 306
 }
307 307
 
308 308
 function html_select_options($options, $selected, $params=array()) {
309
-	if (!is_array($selected)) {
310
-		$selected=array($selected);
311
-	}
312
-	if (isset($params['combine']) && $params['combine']) {
313
-		$options = array_combine($options, $options);
314
-	}
315
-	$value_name = $label_name = false;
316
-	if (isset($params['value'])) {
317
-		$value_name = $params['value'];
318
-	}
319
-	if (isset($params['label'])) {
320
-		$label_name = $params['label'];
321
-	}
322
-	$html = '';
323
-	foreach($options as $value => $label) {
324
-		if ($value_name && is_array($label)) {
325
-			$value = $label[$value_name];
326
-		}
327
-		if ($label_name && is_array($label)) {
328
-			$label = $label[$label_name];
329
-		}
330
-		$select = in_array($value, $selected) ? ' selected="selected"' : '';
331
-		$html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n";
332
-	}
333
-	return $html;
309
+    if (!is_array($selected)) {
310
+        $selected=array($selected);
311
+    }
312
+    if (isset($params['combine']) && $params['combine']) {
313
+        $options = array_combine($options, $options);
314
+    }
315
+    $value_name = $label_name = false;
316
+    if (isset($params['value'])) {
317
+        $value_name = $params['value'];
318
+    }
319
+    if (isset($params['label'])) {
320
+        $label_name = $params['label'];
321
+    }
322
+    $html = '';
323
+    foreach($options as $value => $label) {
324
+        if ($value_name && is_array($label)) {
325
+            $value = $label[$value_name];
326
+        }
327
+        if ($label_name && is_array($label)) {
328
+            $label = $label[$label_name];
329
+        }
330
+        $select = in_array($value, $selected) ? ' selected="selected"' : '';
331
+        $html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n";
332
+    }
333
+    return $html;
334 334
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -46,12 +46,12 @@  discard block
 block discarded – undo
46 46
  * @param string $opts, additional optional options
47 47
 */
48 48
 function emit_css_tag($href, $opts = '') {
49
-	$s='<link rel="stylesheet"';
49
+	$s = '<link rel="stylesheet"';
50 50
 	if (!empty($href)) {
51
-		$s.=' href="' . $href .'"';
51
+		$s .= ' href="'.$href.'"';
52 52
 	}
53 53
 	if (!empty($opts)) {
54
-		$s.=' '.$opts;
54
+		$s .= ' '.$opts;
55 55
 	}
56 56
 	print_unescaped($s.">\n");
57 57
 }
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
  * @param array $obj all the script information from template
62 62
 */
63 63
 function emit_css_loading_tags($obj) {
64
-	foreach($obj['cssfiles'] as $css) {
64
+	foreach ($obj['cssfiles'] as $css) {
65 65
 		emit_css_tag($css);
66 66
 	}
67
-	foreach($obj['printcssfiles'] as $css) {
67
+	foreach ($obj['printcssfiles'] as $css) {
68 68
 		emit_css_tag($css, 'media="print"');
69 69
 	}
70 70
 }
@@ -74,20 +74,20 @@  discard block
 block discarded – undo
74 74
  * @param string $src the source URL, ignored when empty
75 75
  * @param string $script_content the inline script content, ignored when empty
76 76
 */
77
-function emit_script_tag($src, $script_content='') {
78
-	$defer_str=' defer';
79
-	$s='<script nonce="' . \OC::$server->getContentSecurityPolicyNonceManager()->getNonce() . '"';
77
+function emit_script_tag($src, $script_content = '') {
78
+	$defer_str = ' defer';
79
+	$s = '<script nonce="'.\OC::$server->getContentSecurityPolicyNonceManager()->getNonce().'"';
80 80
 	if (!empty($src)) {
81 81
 		 // emit script tag for deferred loading from $src
82
-		$s.=$defer_str.' src="' . $src .'">';
82
+		$s .= $defer_str.' src="'.$src.'">';
83 83
 	} else if (!empty($script_content)) {
84 84
 		// emit script tag for inline script from $script_content without defer (see MDN)
85
-		$s.=">\n".$script_content."\n";
85
+		$s .= ">\n".$script_content."\n";
86 86
 	} else {
87 87
 		// no $src nor $src_content, really useless empty tag
88
-		$s.='>';
88
+		$s .= '>';
89 89
 	}
90
-	$s.='</script>';
90
+	$s .= '</script>';
91 91
 	print_unescaped($s."\n");
92 92
 }
93 93
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
  * @param array $obj all the script information from template
97 97
 */
98 98
 function emit_script_loading_tags($obj) {
99
-	foreach($obj['jsfiles'] as $jsfile) {
99
+	foreach ($obj['jsfiles'] as $jsfile) {
100 100
 		emit_script_tag($jsfile, '');
101 101
 	}
102 102
 	if (!empty($obj['inline_ocjs'])) {
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
  * if an array is given it will add all scripts
121 121
  */
122 122
 function script($app, $file = null) {
123
-	if(is_array($file)) {
124
-		foreach($file as $f) {
123
+	if (is_array($file)) {
124
+		foreach ($file as $f) {
125 125
 			OC_Util::addScript($app, $f);
126 126
 		}
127 127
 	} else {
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
  * if an array is given it will add all scripts
137 137
  */
138 138
 function vendor_script($app, $file = null) {
139
-	if(is_array($file)) {
140
-		foreach($file as $f) {
139
+	if (is_array($file)) {
140
+		foreach ($file as $f) {
141 141
 			OC_Util::addVendorScript($app, $f);
142 142
 		}
143 143
 	} else {
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
  * if an array is given it will add all styles
153 153
  */
154 154
 function style($app, $file = null) {
155
-	if(is_array($file)) {
156
-		foreach($file as $f) {
155
+	if (is_array($file)) {
156
+		foreach ($file as $f) {
157 157
 			OC_Util::addStyle($app, $f);
158 158
 		}
159 159
 	} else {
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
  * if an array is given it will add all styles
169 169
  */
170 170
 function vendor_style($app, $file = null) {
171
-	if(is_array($file)) {
172
-		foreach($file as $f) {
171
+	if (is_array($file)) {
172
+		foreach ($file as $f) {
173 173
 			OC_Util::addVendorStyle($app, $f);
174 174
 		}
175 175
 	} else {
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
  * if an array is given it will add all components
194 194
  */
195 195
 function component($app, $file) {
196
-	if(is_array($file)) {
197
-		foreach($file as $f) {
198
-			$url = link_to($app, 'component/' . $f . '.html');
196
+	if (is_array($file)) {
197
+		foreach ($file as $f) {
198
+			$url = link_to($app, 'component/'.$f.'.html');
199 199
 			OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
200 200
 		}
201 201
 	} else {
202
-		$url = link_to($app, 'component/' . $file . '.html');
202
+		$url = link_to($app, 'component/'.$file.'.html');
203 203
 		OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
204 204
 	}
205 205
 }
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
  *
214 214
  * For further information have a look at \OCP\IURLGenerator::linkTo
215 215
  */
216
-function link_to( $app, $file, $args = array() ) {
216
+function link_to($app, $file, $args = array()) {
217 217
 	return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
218 218
 }
219 219
 
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
  *
234 234
  * For further information have a look at \OCP\IURLGenerator::imagePath
235 235
  */
236
-function image_path( $app, $image ) {
237
-	return \OC::$server->getURLGenerator()->imagePath( $app, $image );
236
+function image_path($app, $image) {
237
+	return \OC::$server->getURLGenerator()->imagePath($app, $image);
238 238
 }
239 239
 
240 240
 /**
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
  * @param string $mimetype mimetype
243 243
  * @return string link to the image
244 244
  */
245
-function mimetype_icon( $mimetype ) {
246
-	return \OC::$server->getMimeTypeDetector()->mimeTypeIcon( $mimetype );
245
+function mimetype_icon($mimetype) {
246
+	return \OC::$server->getMimeTypeDetector()->mimeTypeIcon($mimetype);
247 247
 }
248 248
 
249 249
 /**
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
  * @param string $path path of file
253 253
  * @return string link to the preview
254 254
  */
255
-function preview_icon( $path ) {
255
+function preview_icon($path) {
256 256
 	return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]);
257 257
 }
258 258
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
  * @param string $token
262 262
  * @return string
263 263
  */
264
-function publicPreview_icon ( $path, $token ) {
264
+function publicPreview_icon($path, $token) {
265 265
 	return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 'token' => $token]);
266 266
 }
267 267
 
@@ -272,8 +272,8 @@  discard block
 block discarded – undo
272 272
  *
273 273
  * For further information have a look at OC_Helper::humanFileSize
274 274
  */
275
-function human_file_size( $bytes ) {
276
-	return OC_Helper::humanFileSize( $bytes );
275
+function human_file_size($bytes) {
276
+	return OC_Helper::humanFileSize($bytes);
277 277
 }
278 278
 
279 279
 /**
@@ -281,10 +281,10 @@  discard block
 block discarded – undo
281 281
  * @param int $timestamp UNIX timestamp to strip
282 282
  * @return int timestamp without time value
283 283
  */
284
-function strip_time($timestamp){
284
+function strip_time($timestamp) {
285 285
 	$date = new \DateTime("@{$timestamp}");
286 286
 	$date->setTime(0, 0, 0);
287
-	return (int)$date->format('U');
287
+	return (int) $date->format('U');
288 288
 }
289 289
 
290 290
 /**
@@ -299,15 +299,15 @@  discard block
 block discarded – undo
299 299
 	/** @var \OC\DateTimeFormatter $formatter */
300 300
 	$formatter = \OC::$server->query('DateTimeFormatter');
301 301
 
302
-	if ($dateOnly){
302
+	if ($dateOnly) {
303 303
 		return $formatter->formatDateSpan($timestamp, $fromTime);
304 304
 	}
305 305
 	return $formatter->formatTimeSpan($timestamp, $fromTime);
306 306
 }
307 307
 
308
-function html_select_options($options, $selected, $params=array()) {
308
+function html_select_options($options, $selected, $params = array()) {
309 309
 	if (!is_array($selected)) {
310
-		$selected=array($selected);
310
+		$selected = array($selected);
311 311
 	}
312 312
 	if (isset($params['combine']) && $params['combine']) {
313 313
 		$options = array_combine($options, $options);
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 		$label_name = $params['label'];
321 321
 	}
322 322
 	$html = '';
323
-	foreach($options as $value => $label) {
323
+	foreach ($options as $value => $label) {
324 324
 		if ($value_name && is_array($label)) {
325 325
 			$value = $label[$value_name];
326 326
 		}
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 			$label = $label[$label_name];
329 329
 		}
330 330
 		$select = in_array($value, $selected) ? ' selected="selected"' : '';
331
-		$html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n";
331
+		$html .= '<option value="'.\OCP\Util::sanitizeHTML($value).'"'.$select.'>'.\OCP\Util::sanitizeHTML($label).'</option>'."\n";
332 332
 	}
333 333
 	return $html;
334 334
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/Response.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -261,7 +261,7 @@
 block discarded – undo
261 261
 
262 262
 	/**
263 263
 	 * Get the currently used Content-Security-Policy
264
-	 * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
264
+	 * @return ContentSecurityPolicy|null Used Content-Security-Policy or null if
265 265
 	 *                                    none specified.
266 266
 	 * @since 8.1.0
267 267
 	 */
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
 	 * @since 6.0.0 - return value was added in 7.0.0
97 97
 	 */
98 98
 	public function cacheFor(int $cacheSeconds) {
99
-		if($cacheSeconds > 0) {
100
-			$this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
99
+		if ($cacheSeconds > 0) {
100
+			$this->addHeader('Cache-Control', 'max-age='.$cacheSeconds.', must-revalidate');
101 101
 
102 102
 			// Old scool prama caching
103 103
 			$this->addHeader('Pragma', 'public');
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	 * @since 8.0.0
162 162
 	 */
163 163
 	public function invalidateCookies(array $cookieNames) {
164
-		foreach($cookieNames as $cookieName) {
164
+		foreach ($cookieNames as $cookieName) {
165 165
 			$this->invalidateCookie($cookieName);
166 166
 		}
167 167
 		return $this;
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 	 * @since 6.0.0 - return value was added in 7.0.0
186 186
 	 */
187 187
 	public function addHeader($name, $value) {
188
-		$name = trim($name);  // always remove leading and trailing whitespace
188
+		$name = trim($name); // always remove leading and trailing whitespace
189 189
 		                      // to be able to reliably check for security
190 190
 		                      // headers
191 191
 
192
-		if(is_null($value)) {
192
+		if (is_null($value)) {
193 193
 			unset($this->headers[$name]);
194 194
 		} else {
195 195
 			$this->headers[$name] = $value;
@@ -220,19 +220,19 @@  discard block
 block discarded – undo
220 220
 	public function getHeaders() {
221 221
 		$mergeWith = [];
222 222
 
223
-		if($this->lastModified) {
223
+		if ($this->lastModified) {
224 224
 			$mergeWith['Last-Modified'] =
225 225
 				$this->lastModified->format(\DateTime::RFC2822);
226 226
 		}
227 227
 
228 228
 		// Build Content-Security-Policy and use default if none has been specified
229
-		if(is_null($this->contentSecurityPolicy)) {
229
+		if (is_null($this->contentSecurityPolicy)) {
230 230
 			$this->setContentSecurityPolicy(new ContentSecurityPolicy());
231 231
 		}
232 232
 		$this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
233 233
 
234
-		if($this->ETag) {
235
-			$mergeWith['ETag'] = '"' . $this->ETag . '"';
234
+		if ($this->ETag) {
235
+			$mergeWith['ETag'] = '"'.$this->ETag.'"';
236 236
 		}
237 237
 
238 238
 		return array_merge($mergeWith, $this->headers);
Please login to merge, or discard this patch.
Indentation   +325 added lines, -325 removed lines patch added patch discarded remove patch
@@ -45,329 +45,329 @@
 block discarded – undo
45 45
  */
46 46
 class Response {
47 47
 
48
-	/**
49
-	 * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
50
-	 * @var array
51
-	 */
52
-	private $headers = array(
53
-		'Cache-Control' => 'no-cache, no-store, must-revalidate'
54
-	);
55
-
56
-
57
-	/**
58
-	 * Cookies that will be need to be constructed as header
59
-	 * @var array
60
-	 */
61
-	private $cookies = array();
62
-
63
-
64
-	/**
65
-	 * HTTP status code - defaults to STATUS OK
66
-	 * @var int
67
-	 */
68
-	private $status = Http::STATUS_OK;
69
-
70
-
71
-	/**
72
-	 * Last modified date
73
-	 * @var \DateTime
74
-	 */
75
-	private $lastModified;
76
-
77
-
78
-	/**
79
-	 * ETag
80
-	 * @var string
81
-	 */
82
-	private $ETag;
83
-
84
-	/** @var ContentSecurityPolicy|null Used Content-Security-Policy */
85
-	private $contentSecurityPolicy = null;
86
-
87
-	/** @var bool */
88
-	private $throttled = false;
89
-	/** @var array */
90
-	private $throttleMetadata = [];
91
-
92
-	/**
93
-	 * Caches the response
94
-	 * @param int $cacheSeconds the amount of seconds that should be cached
95
-	 * if 0 then caching will be disabled
96
-	 * @return $this
97
-	 * @since 6.0.0 - return value was added in 7.0.0
98
-	 */
99
-	public function cacheFor(int $cacheSeconds) {
100
-		if($cacheSeconds > 0) {
101
-			$this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
102
-
103
-			// Old scool prama caching
104
-			$this->addHeader('Pragma', 'public');
105
-
106
-			// Set expires header
107
-			$expires = new \DateTime();
108
-			/** @var ITimeFactory $time */
109
-			$time = \OC::$server->query(ITimeFactory::class);
110
-			$expires->setTimestamp($time->getTime());
111
-			$expires->add(new \DateInterval('PT'.$cacheSeconds.'S'));
112
-			$this->addHeader('Expires', $expires->format(\DateTime::RFC2822));
113
-		} else {
114
-			$this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
115
-			unset($this->headers['Expires'], $this->headers['Pragma']);
116
-		}
117
-
118
-		return $this;
119
-	}
120
-
121
-	/**
122
-	 * Adds a new cookie to the response
123
-	 * @param string $name The name of the cookie
124
-	 * @param string $value The value of the cookie
125
-	 * @param \DateTime|null $expireDate Date on that the cookie should expire, if set
126
-	 * 									to null cookie will be considered as session
127
-	 * 									cookie.
128
-	 * @return $this
129
-	 * @since 8.0.0
130
-	 */
131
-	public function addCookie($name, $value, \DateTime $expireDate = null) {
132
-		$this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate);
133
-		return $this;
134
-	}
135
-
136
-
137
-	/**
138
-	 * Set the specified cookies
139
-	 * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null))
140
-	 * @return $this
141
-	 * @since 8.0.0
142
-	 */
143
-	public function setCookies(array $cookies) {
144
-		$this->cookies = $cookies;
145
-		return $this;
146
-	}
147
-
148
-
149
-	/**
150
-	 * Invalidates the specified cookie
151
-	 * @param string $name
152
-	 * @return $this
153
-	 * @since 8.0.0
154
-	 */
155
-	public function invalidateCookie($name) {
156
-		$this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00'));
157
-		return $this;
158
-	}
159
-
160
-	/**
161
-	 * Invalidates the specified cookies
162
-	 * @param array $cookieNames array('foo', 'bar')
163
-	 * @return $this
164
-	 * @since 8.0.0
165
-	 */
166
-	public function invalidateCookies(array $cookieNames) {
167
-		foreach($cookieNames as $cookieName) {
168
-			$this->invalidateCookie($cookieName);
169
-		}
170
-		return $this;
171
-	}
172
-
173
-	/**
174
-	 * Returns the cookies
175
-	 * @return array
176
-	 * @since 8.0.0
177
-	 */
178
-	public function getCookies() {
179
-		return $this->cookies;
180
-	}
181
-
182
-	/**
183
-	 * Adds a new header to the response that will be called before the render
184
-	 * function
185
-	 * @param string $name The name of the HTTP header
186
-	 * @param string $value The value, null will delete it
187
-	 * @return $this
188
-	 * @since 6.0.0 - return value was added in 7.0.0
189
-	 */
190
-	public function addHeader($name, $value) {
191
-		$name = trim($name);  // always remove leading and trailing whitespace
192
-		                      // to be able to reliably check for security
193
-		                      // headers
194
-
195
-		if(is_null($value)) {
196
-			unset($this->headers[$name]);
197
-		} else {
198
-			$this->headers[$name] = $value;
199
-		}
200
-
201
-		return $this;
202
-	}
203
-
204
-
205
-	/**
206
-	 * Set the headers
207
-	 * @param array $headers value header pairs
208
-	 * @return $this
209
-	 * @since 8.0.0
210
-	 */
211
-	public function setHeaders(array $headers) {
212
-		$this->headers = $headers;
213
-
214
-		return $this;
215
-	}
216
-
217
-
218
-	/**
219
-	 * Returns the set headers
220
-	 * @return array the headers
221
-	 * @since 6.0.0
222
-	 */
223
-	public function getHeaders() {
224
-		$mergeWith = [];
225
-
226
-		if($this->lastModified) {
227
-			$mergeWith['Last-Modified'] =
228
-				$this->lastModified->format(\DateTime::RFC2822);
229
-		}
230
-
231
-		// Build Content-Security-Policy and use default if none has been specified
232
-		if(is_null($this->contentSecurityPolicy)) {
233
-			$this->setContentSecurityPolicy(new ContentSecurityPolicy());
234
-		}
235
-		$this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
236
-
237
-		if($this->ETag) {
238
-			$mergeWith['ETag'] = '"' . $this->ETag . '"';
239
-		}
240
-
241
-		return array_merge($mergeWith, $this->headers);
242
-	}
243
-
244
-
245
-	/**
246
-	 * By default renders no output
247
-	 * @return string
248
-	 * @since 6.0.0
249
-	 */
250
-	public function render() {
251
-		return '';
252
-	}
253
-
254
-
255
-	/**
256
-	 * Set response status
257
-	 * @param int $status a HTTP status code, see also the STATUS constants
258
-	 * @return Response Reference to this object
259
-	 * @since 6.0.0 - return value was added in 7.0.0
260
-	 */
261
-	public function setStatus($status) {
262
-		$this->status = $status;
263
-
264
-		return $this;
265
-	}
266
-
267
-	/**
268
-	 * Set a Content-Security-Policy
269
-	 * @param EmptyContentSecurityPolicy $csp Policy to set for the response object
270
-	 * @return $this
271
-	 * @since 8.1.0
272
-	 */
273
-	public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) {
274
-		$this->contentSecurityPolicy = $csp;
275
-		return $this;
276
-	}
277
-
278
-	/**
279
-	 * Get the currently used Content-Security-Policy
280
-	 * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
281
-	 *                                    none specified.
282
-	 * @since 8.1.0
283
-	 */
284
-	public function getContentSecurityPolicy() {
285
-		return $this->contentSecurityPolicy;
286
-	}
287
-
288
-
289
-	/**
290
-	 * Get response status
291
-	 * @since 6.0.0
292
-	 */
293
-	public function getStatus() {
294
-		return $this->status;
295
-	}
296
-
297
-
298
-	/**
299
-	 * Get the ETag
300
-	 * @return string the etag
301
-	 * @since 6.0.0
302
-	 */
303
-	public function getETag() {
304
-		return $this->ETag;
305
-	}
306
-
307
-
308
-	/**
309
-	 * Get "last modified" date
310
-	 * @return \DateTime RFC2822 formatted last modified date
311
-	 * @since 6.0.0
312
-	 */
313
-	public function getLastModified() {
314
-		return $this->lastModified;
315
-	}
316
-
317
-
318
-	/**
319
-	 * Set the ETag
320
-	 * @param string $ETag
321
-	 * @return Response Reference to this object
322
-	 * @since 6.0.0 - return value was added in 7.0.0
323
-	 */
324
-	public function setETag($ETag) {
325
-		$this->ETag = $ETag;
326
-
327
-		return $this;
328
-	}
329
-
330
-
331
-	/**
332
-	 * Set "last modified" date
333
-	 * @param \DateTime $lastModified
334
-	 * @return Response Reference to this object
335
-	 * @since 6.0.0 - return value was added in 7.0.0
336
-	 */
337
-	public function setLastModified($lastModified) {
338
-		$this->lastModified = $lastModified;
339
-
340
-		return $this;
341
-	}
342
-
343
-	/**
344
-	 * Marks the response as to throttle. Will be throttled when the
345
-	 * @BruteForceProtection annotation is added.
346
-	 *
347
-	 * @param array $metadata
348
-	 * @since 12.0.0
349
-	 */
350
-	public function throttle(array $metadata = []) {
351
-		$this->throttled = true;
352
-		$this->throttleMetadata = $metadata;
353
-	}
354
-
355
-	/**
356
-	 * Returns the throttle metadata, defaults to empty array
357
-	 *
358
-	 * @return array
359
-	 * @since 13.0.0
360
-	 */
361
-	public function getThrottleMetadata() {
362
-		return $this->throttleMetadata;
363
-	}
364
-
365
-	/**
366
-	 * Whether the current response is throttled.
367
-	 *
368
-	 * @since 12.0.0
369
-	 */
370
-	public function isThrottled() {
371
-		return $this->throttled;
372
-	}
48
+    /**
49
+     * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
50
+     * @var array
51
+     */
52
+    private $headers = array(
53
+        'Cache-Control' => 'no-cache, no-store, must-revalidate'
54
+    );
55
+
56
+
57
+    /**
58
+     * Cookies that will be need to be constructed as header
59
+     * @var array
60
+     */
61
+    private $cookies = array();
62
+
63
+
64
+    /**
65
+     * HTTP status code - defaults to STATUS OK
66
+     * @var int
67
+     */
68
+    private $status = Http::STATUS_OK;
69
+
70
+
71
+    /**
72
+     * Last modified date
73
+     * @var \DateTime
74
+     */
75
+    private $lastModified;
76
+
77
+
78
+    /**
79
+     * ETag
80
+     * @var string
81
+     */
82
+    private $ETag;
83
+
84
+    /** @var ContentSecurityPolicy|null Used Content-Security-Policy */
85
+    private $contentSecurityPolicy = null;
86
+
87
+    /** @var bool */
88
+    private $throttled = false;
89
+    /** @var array */
90
+    private $throttleMetadata = [];
91
+
92
+    /**
93
+     * Caches the response
94
+     * @param int $cacheSeconds the amount of seconds that should be cached
95
+     * if 0 then caching will be disabled
96
+     * @return $this
97
+     * @since 6.0.0 - return value was added in 7.0.0
98
+     */
99
+    public function cacheFor(int $cacheSeconds) {
100
+        if($cacheSeconds > 0) {
101
+            $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
102
+
103
+            // Old scool prama caching
104
+            $this->addHeader('Pragma', 'public');
105
+
106
+            // Set expires header
107
+            $expires = new \DateTime();
108
+            /** @var ITimeFactory $time */
109
+            $time = \OC::$server->query(ITimeFactory::class);
110
+            $expires->setTimestamp($time->getTime());
111
+            $expires->add(new \DateInterval('PT'.$cacheSeconds.'S'));
112
+            $this->addHeader('Expires', $expires->format(\DateTime::RFC2822));
113
+        } else {
114
+            $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
115
+            unset($this->headers['Expires'], $this->headers['Pragma']);
116
+        }
117
+
118
+        return $this;
119
+    }
120
+
121
+    /**
122
+     * Adds a new cookie to the response
123
+     * @param string $name The name of the cookie
124
+     * @param string $value The value of the cookie
125
+     * @param \DateTime|null $expireDate Date on that the cookie should expire, if set
126
+     * 									to null cookie will be considered as session
127
+     * 									cookie.
128
+     * @return $this
129
+     * @since 8.0.0
130
+     */
131
+    public function addCookie($name, $value, \DateTime $expireDate = null) {
132
+        $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate);
133
+        return $this;
134
+    }
135
+
136
+
137
+    /**
138
+     * Set the specified cookies
139
+     * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null))
140
+     * @return $this
141
+     * @since 8.0.0
142
+     */
143
+    public function setCookies(array $cookies) {
144
+        $this->cookies = $cookies;
145
+        return $this;
146
+    }
147
+
148
+
149
+    /**
150
+     * Invalidates the specified cookie
151
+     * @param string $name
152
+     * @return $this
153
+     * @since 8.0.0
154
+     */
155
+    public function invalidateCookie($name) {
156
+        $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00'));
157
+        return $this;
158
+    }
159
+
160
+    /**
161
+     * Invalidates the specified cookies
162
+     * @param array $cookieNames array('foo', 'bar')
163
+     * @return $this
164
+     * @since 8.0.0
165
+     */
166
+    public function invalidateCookies(array $cookieNames) {
167
+        foreach($cookieNames as $cookieName) {
168
+            $this->invalidateCookie($cookieName);
169
+        }
170
+        return $this;
171
+    }
172
+
173
+    /**
174
+     * Returns the cookies
175
+     * @return array
176
+     * @since 8.0.0
177
+     */
178
+    public function getCookies() {
179
+        return $this->cookies;
180
+    }
181
+
182
+    /**
183
+     * Adds a new header to the response that will be called before the render
184
+     * function
185
+     * @param string $name The name of the HTTP header
186
+     * @param string $value The value, null will delete it
187
+     * @return $this
188
+     * @since 6.0.0 - return value was added in 7.0.0
189
+     */
190
+    public function addHeader($name, $value) {
191
+        $name = trim($name);  // always remove leading and trailing whitespace
192
+                                // to be able to reliably check for security
193
+                                // headers
194
+
195
+        if(is_null($value)) {
196
+            unset($this->headers[$name]);
197
+        } else {
198
+            $this->headers[$name] = $value;
199
+        }
200
+
201
+        return $this;
202
+    }
203
+
204
+
205
+    /**
206
+     * Set the headers
207
+     * @param array $headers value header pairs
208
+     * @return $this
209
+     * @since 8.0.0
210
+     */
211
+    public function setHeaders(array $headers) {
212
+        $this->headers = $headers;
213
+
214
+        return $this;
215
+    }
216
+
217
+
218
+    /**
219
+     * Returns the set headers
220
+     * @return array the headers
221
+     * @since 6.0.0
222
+     */
223
+    public function getHeaders() {
224
+        $mergeWith = [];
225
+
226
+        if($this->lastModified) {
227
+            $mergeWith['Last-Modified'] =
228
+                $this->lastModified->format(\DateTime::RFC2822);
229
+        }
230
+
231
+        // Build Content-Security-Policy and use default if none has been specified
232
+        if(is_null($this->contentSecurityPolicy)) {
233
+            $this->setContentSecurityPolicy(new ContentSecurityPolicy());
234
+        }
235
+        $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
236
+
237
+        if($this->ETag) {
238
+            $mergeWith['ETag'] = '"' . $this->ETag . '"';
239
+        }
240
+
241
+        return array_merge($mergeWith, $this->headers);
242
+    }
243
+
244
+
245
+    /**
246
+     * By default renders no output
247
+     * @return string
248
+     * @since 6.0.0
249
+     */
250
+    public function render() {
251
+        return '';
252
+    }
253
+
254
+
255
+    /**
256
+     * Set response status
257
+     * @param int $status a HTTP status code, see also the STATUS constants
258
+     * @return Response Reference to this object
259
+     * @since 6.0.0 - return value was added in 7.0.0
260
+     */
261
+    public function setStatus($status) {
262
+        $this->status = $status;
263
+
264
+        return $this;
265
+    }
266
+
267
+    /**
268
+     * Set a Content-Security-Policy
269
+     * @param EmptyContentSecurityPolicy $csp Policy to set for the response object
270
+     * @return $this
271
+     * @since 8.1.0
272
+     */
273
+    public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) {
274
+        $this->contentSecurityPolicy = $csp;
275
+        return $this;
276
+    }
277
+
278
+    /**
279
+     * Get the currently used Content-Security-Policy
280
+     * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
281
+     *                                    none specified.
282
+     * @since 8.1.0
283
+     */
284
+    public function getContentSecurityPolicy() {
285
+        return $this->contentSecurityPolicy;
286
+    }
287
+
288
+
289
+    /**
290
+     * Get response status
291
+     * @since 6.0.0
292
+     */
293
+    public function getStatus() {
294
+        return $this->status;
295
+    }
296
+
297
+
298
+    /**
299
+     * Get the ETag
300
+     * @return string the etag
301
+     * @since 6.0.0
302
+     */
303
+    public function getETag() {
304
+        return $this->ETag;
305
+    }
306
+
307
+
308
+    /**
309
+     * Get "last modified" date
310
+     * @return \DateTime RFC2822 formatted last modified date
311
+     * @since 6.0.0
312
+     */
313
+    public function getLastModified() {
314
+        return $this->lastModified;
315
+    }
316
+
317
+
318
+    /**
319
+     * Set the ETag
320
+     * @param string $ETag
321
+     * @return Response Reference to this object
322
+     * @since 6.0.0 - return value was added in 7.0.0
323
+     */
324
+    public function setETag($ETag) {
325
+        $this->ETag = $ETag;
326
+
327
+        return $this;
328
+    }
329
+
330
+
331
+    /**
332
+     * Set "last modified" date
333
+     * @param \DateTime $lastModified
334
+     * @return Response Reference to this object
335
+     * @since 6.0.0 - return value was added in 7.0.0
336
+     */
337
+    public function setLastModified($lastModified) {
338
+        $this->lastModified = $lastModified;
339
+
340
+        return $this;
341
+    }
342
+
343
+    /**
344
+     * Marks the response as to throttle. Will be throttled when the
345
+     * @BruteForceProtection annotation is added.
346
+     *
347
+     * @param array $metadata
348
+     * @since 12.0.0
349
+     */
350
+    public function throttle(array $metadata = []) {
351
+        $this->throttled = true;
352
+        $this->throttleMetadata = $metadata;
353
+    }
354
+
355
+    /**
356
+     * Returns the throttle metadata, defaults to empty array
357
+     *
358
+     * @return array
359
+     * @since 13.0.0
360
+     */
361
+    public function getThrottleMetadata() {
362
+        return $this->throttleMetadata;
363
+    }
364
+
365
+    /**
366
+     * Whether the current response is throttled.
367
+     *
368
+     * @since 12.0.0
369
+     */
370
+    public function isThrottled() {
371
+        return $this->throttled;
372
+    }
373 373
 }
Please login to merge, or discard this patch.
lib/private/legacy/db/statementwrapper.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 	/**
55 55
 	 * pass all other function directly to the \Doctrine\DBAL\Driver\Statement
56 56
 	 */
57
-	public function __call($name,$arguments) {
58
-		return call_user_func_array(array($this->statement,$name), $arguments);
57
+	public function __call($name, $arguments) {
58
+		return call_user_func_array(array($this->statement, $name), $arguments);
59 59
 	}
60 60
 
61 61
 	/**
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @param array $input
65 65
 	 * @return \OC_DB_StatementWrapper|int|bool
66 66
 	 */
67
-	public function execute($input= []) {
67
+	public function execute($input = []) {
68 68
 		$this->lastArguments = $input;
69 69
 		if (count($input) > 0) {
70 70
 			$result = $this->statement->execute($input);
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 * @param integer|null $length max length when using an OUT bind
114 114
 	 * @return boolean
115 115
 	 */
116
-	public function bindParam($column, &$variable, $type = null, $length = null){
116
+	public function bindParam($column, &$variable, $type = null, $length = null) {
117 117
 		return $this->statement->bindParam($column, $variable, $type, $length);
118 118
 	}
119 119
 }
Please login to merge, or discard this patch.
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -37,83 +37,83 @@
 block discarded – undo
37 37
  * @method array fetchAll(integer $fetchMode = null);
38 38
  */
39 39
 class OC_DB_StatementWrapper {
40
-	/**
41
-	 * @var \Doctrine\DBAL\Driver\Statement
42
-	 */
43
-	private $statement = null;
44
-	private $isManipulation = false;
45
-	private $lastArguments = array();
40
+    /**
41
+     * @var \Doctrine\DBAL\Driver\Statement
42
+     */
43
+    private $statement = null;
44
+    private $isManipulation = false;
45
+    private $lastArguments = array();
46 46
 
47
-	/**
48
-	 * @param boolean $isManipulation
49
-	 */
50
-	public function __construct($statement, $isManipulation) {
51
-		$this->statement = $statement;
52
-		$this->isManipulation = $isManipulation;
53
-	}
47
+    /**
48
+     * @param boolean $isManipulation
49
+     */
50
+    public function __construct($statement, $isManipulation) {
51
+        $this->statement = $statement;
52
+        $this->isManipulation = $isManipulation;
53
+    }
54 54
 
55
-	/**
56
-	 * pass all other function directly to the \Doctrine\DBAL\Driver\Statement
57
-	 */
58
-	public function __call($name,$arguments) {
59
-		return call_user_func_array(array($this->statement,$name), $arguments);
60
-	}
55
+    /**
56
+     * pass all other function directly to the \Doctrine\DBAL\Driver\Statement
57
+     */
58
+    public function __call($name,$arguments) {
59
+        return call_user_func_array(array($this->statement,$name), $arguments);
60
+    }
61 61
 
62
-	/**
63
-	 * make execute return the result instead of a bool
64
-	 *
65
-	 * @param array $input
66
-	 * @return \OC_DB_StatementWrapper|int|bool
67
-	 */
68
-	public function execute($input= []) {
69
-		$this->lastArguments = $input;
70
-		if (count($input) > 0) {
71
-			$result = $this->statement->execute($input);
72
-		} else {
73
-			$result = $this->statement->execute();
74
-		}
62
+    /**
63
+     * make execute return the result instead of a bool
64
+     *
65
+     * @param array $input
66
+     * @return \OC_DB_StatementWrapper|int|bool
67
+     */
68
+    public function execute($input= []) {
69
+        $this->lastArguments = $input;
70
+        if (count($input) > 0) {
71
+            $result = $this->statement->execute($input);
72
+        } else {
73
+            $result = $this->statement->execute();
74
+        }
75 75
 
76
-		if ($result === false) {
77
-			return false;
78
-		}
79
-		if ($this->isManipulation) {
80
-			return $this->statement->rowCount();
81
-		} else {
82
-			return $this;
83
-		}
84
-	}
76
+        if ($result === false) {
77
+            return false;
78
+        }
79
+        if ($this->isManipulation) {
80
+            return $this->statement->rowCount();
81
+        } else {
82
+            return $this;
83
+        }
84
+    }
85 85
 
86
-	/**
87
-	 * provide an alias for fetch
88
-	 *
89
-	 * @return mixed
90
-	 */
91
-	public function fetchRow() {
92
-		return $this->statement->fetch();
93
-	}
86
+    /**
87
+     * provide an alias for fetch
88
+     *
89
+     * @return mixed
90
+     */
91
+    public function fetchRow() {
92
+        return $this->statement->fetch();
93
+    }
94 94
 
95
-	/**
96
-	 * Provide a simple fetchOne.
97
-	 *
98
-	 * fetch single column from the next row
99
-	 * @param int $column the column number to fetch
100
-	 * @return string
101
-	 */
102
-	public function fetchOne($column = 0) {
103
-		return $this->statement->fetchColumn($column);
104
-	}
95
+    /**
96
+     * Provide a simple fetchOne.
97
+     *
98
+     * fetch single column from the next row
99
+     * @param int $column the column number to fetch
100
+     * @return string
101
+     */
102
+    public function fetchOne($column = 0) {
103
+        return $this->statement->fetchColumn($column);
104
+    }
105 105
 
106
-	/**
107
-	 * Binds a PHP variable to a corresponding named or question mark placeholder in the
108
-	 * SQL statement that was use to prepare the statement.
109
-	 *
110
-	 * @param mixed $column Either the placeholder name or the 1-indexed placeholder index
111
-	 * @param mixed $variable The variable to bind
112
-	 * @param integer|null $type one of the  PDO::PARAM_* constants
113
-	 * @param integer|null $length max length when using an OUT bind
114
-	 * @return boolean
115
-	 */
116
-	public function bindParam($column, &$variable, $type = null, $length = null){
117
-		return $this->statement->bindParam($column, $variable, $type, $length);
118
-	}
106
+    /**
107
+     * Binds a PHP variable to a corresponding named or question mark placeholder in the
108
+     * SQL statement that was use to prepare the statement.
109
+     *
110
+     * @param mixed $column Either the placeholder name or the 1-indexed placeholder index
111
+     * @param mixed $variable The variable to bind
112
+     * @param integer|null $type one of the  PDO::PARAM_* constants
113
+     * @param integer|null $length max length when using an OUT bind
114
+     * @return boolean
115
+     */
116
+    public function bindParam($column, &$variable, $type = null, $length = null){
117
+        return $this->statement->bindParam($column, $variable, $type, $length);
118
+    }
119 119
 }
Please login to merge, or discard this patch.
lib/private/App/CodeChecker/MigrationSchemaChecker.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -29,179 +29,179 @@
 block discarded – undo
29 29
 
30 30
 class MigrationSchemaChecker extends NodeVisitorAbstract {
31 31
 
32
-	/** @var string */
33
-	protected $schemaVariableName = null;
34
-	/** @var array */
35
-	protected $tableVariableNames = [];
36
-	/** @var array */
37
-	public $errors = [];
32
+    /** @var string */
33
+    protected $schemaVariableName = null;
34
+    /** @var array */
35
+    protected $tableVariableNames = [];
36
+    /** @var array */
37
+    public $errors = [];
38 38
 
39
-	/**
40
-	 * @param Node $node
41
-	 * @return void
42
-	 *
43
-	 * @suppress PhanUndeclaredProperty
44
-	 */
45
-	public function enterNode(Node $node) {
46
-		/**
47
-		 * Check tables
48
-		 */
49
-		if ($this->schemaVariableName !== null &&
50
-			 $node instanceof Node\Expr\Assign &&
51
-			 $node->var instanceof Node\Expr\Variable &&
52
-			 $node->expr instanceof Node\Expr\MethodCall &&
53
-			 $node->expr->var instanceof Node\Expr\Variable &&
54
-			 $node->expr->var->name === $this->schemaVariableName) {
39
+    /**
40
+     * @param Node $node
41
+     * @return void
42
+     *
43
+     * @suppress PhanUndeclaredProperty
44
+     */
45
+    public function enterNode(Node $node) {
46
+        /**
47
+         * Check tables
48
+         */
49
+        if ($this->schemaVariableName !== null &&
50
+             $node instanceof Node\Expr\Assign &&
51
+             $node->var instanceof Node\Expr\Variable &&
52
+             $node->expr instanceof Node\Expr\MethodCall &&
53
+             $node->expr->var instanceof Node\Expr\Variable &&
54
+             $node->expr->var->name === $this->schemaVariableName) {
55 55
 
56
-			if ($node->expr->name === 'createTable') {
57
-				if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) {
58
-					if (!$this->checkNameLength($node->expr->args[0]->value->value)) {
59
-						$this->errors[] = [
60
-							'line' => $node->getLine(),
61
-							'disallowedToken' => $node->expr->args[0]->value->value,
62
-							'reason' => 'Table name is too long (max. 27)',
63
-						];
64
-					} else {
65
-						$this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value;
66
-					}
67
-				}
68
-			} else if ($node->expr->name === 'getTable') {
69
-				if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) {
70
-					$this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value;
71
-				}
72
-			}
73
-		} else if ($this->schemaVariableName !== null &&
74
-			 $node instanceof Node\Expr\MethodCall &&
75
-			 $node->var instanceof Node\Expr\Variable &&
76
-			 $node->var->name === $this->schemaVariableName) {
56
+            if ($node->expr->name === 'createTable') {
57
+                if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) {
58
+                    if (!$this->checkNameLength($node->expr->args[0]->value->value)) {
59
+                        $this->errors[] = [
60
+                            'line' => $node->getLine(),
61
+                            'disallowedToken' => $node->expr->args[0]->value->value,
62
+                            'reason' => 'Table name is too long (max. 27)',
63
+                        ];
64
+                    } else {
65
+                        $this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value;
66
+                    }
67
+                }
68
+            } else if ($node->expr->name === 'getTable') {
69
+                if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) {
70
+                    $this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value;
71
+                }
72
+            }
73
+        } else if ($this->schemaVariableName !== null &&
74
+             $node instanceof Node\Expr\MethodCall &&
75
+             $node->var instanceof Node\Expr\Variable &&
76
+             $node->var->name === $this->schemaVariableName) {
77 77
 
78
-			if ($node->name === 'renameTable') {
79
-				$this->errors[] = [
80
-					'line' => $node->getLine(),
81
-					'disallowedToken' => 'Deprecated method',
82
-					'reason' => sprintf(
83
-						'`$%s->renameTable()` must not be used',
84
-						$node->var->name
85
-					),
86
-				];
87
-			}
78
+            if ($node->name === 'renameTable') {
79
+                $this->errors[] = [
80
+                    'line' => $node->getLine(),
81
+                    'disallowedToken' => 'Deprecated method',
82
+                    'reason' => sprintf(
83
+                        '`$%s->renameTable()` must not be used',
84
+                        $node->var->name
85
+                    ),
86
+                ];
87
+            }
88 88
 
89
-		/**
90
-		 * Check columns and Indexes
91
-		 */
92
-		} else if (!empty($this->tableVariableNames) &&
93
-			 $node instanceof Node\Expr\MethodCall &&
94
-			 $node->var instanceof Node\Expr\Variable &&
95
-			 isset($this->tableVariableNames[$node->var->name])) {
89
+        /**
90
+         * Check columns and Indexes
91
+         */
92
+        } else if (!empty($this->tableVariableNames) &&
93
+             $node instanceof Node\Expr\MethodCall &&
94
+             $node->var instanceof Node\Expr\Variable &&
95
+             isset($this->tableVariableNames[$node->var->name])) {
96 96
 
97
-			if ($node->name === 'addColumn' || $node->name === 'changeColumn') {
98
-				if (isset($node->args[0]) && $node->args[0]->value instanceof Node\Scalar\String_) {
99
-					if (!$this->checkNameLength($node->args[0]->value->value)) {
100
-						$this->errors[] = [
101
-							'line' => $node->getLine(),
102
-							'disallowedToken' => $node->args[0]->value->value,
103
-							'reason' => sprintf(
104
-								'Column name is too long on table `%s` (max. 27)',
105
-								$this->tableVariableNames[$node->var->name]
106
-							),
107
-						];
108
-					}
97
+            if ($node->name === 'addColumn' || $node->name === 'changeColumn') {
98
+                if (isset($node->args[0]) && $node->args[0]->value instanceof Node\Scalar\String_) {
99
+                    if (!$this->checkNameLength($node->args[0]->value->value)) {
100
+                        $this->errors[] = [
101
+                            'line' => $node->getLine(),
102
+                            'disallowedToken' => $node->args[0]->value->value,
103
+                            'reason' => sprintf(
104
+                                'Column name is too long on table `%s` (max. 27)',
105
+                                $this->tableVariableNames[$node->var->name]
106
+                            ),
107
+                        ];
108
+                    }
109 109
 
110
-					// On autoincrement the max length of the table name is 21 instead of 27
111
-					if (isset($node->args[2]) && $node->args[2]->value instanceof Node\Expr\Array_) {
112
-						/** @var Node\Expr\Array_ $options */
113
-						$options = $node->args[2]->value;
114
-						if ($this->checkColumnForAutoincrement($options)) {
115
-							if (!$this->checkNameLength($this->tableVariableNames[$node->var->name], true)) {
116
-								$this->errors[] = [
117
-									'line' => $node->getLine(),
118
-									'disallowedToken' => $this->tableVariableNames[$node->var->name],
119
-									'reason' => 'Table name is too long because of autoincrement (max. 21)',
120
-								];
121
-							}
122
-						}
123
-					}
124
-				}
125
-			} else if ($node->name === 'addIndex' ||
126
-				 $node->name === 'addUniqueIndex' ||
127
-				 $node->name === 'renameIndex' ||
128
-				 $node->name === 'setPrimaryKey') {
129
-				if (isset($node->args[1]) && $node->args[1]->value instanceof Node\Scalar\String_) {
130
-					if (!$this->checkNameLength($node->args[1]->value->value)) {
131
-						$this->errors[] = [
132
-							'line' => $node->getLine(),
133
-							'disallowedToken' => $node->args[1]->value->value,
134
-							'reason' => sprintf(
135
-								'Index name is too long on table `%s` (max. 27)',
136
-								$this->tableVariableNames[$node->var->name]
137
-							),
138
-						];
139
-					}
140
-				}
141
-			} else if ($node->name === 'addForeignKeyConstraint') {
142
-				if (isset($node->args[4]) && $node->args[4]->value instanceof Node\Scalar\String_) {
143
-					if (!$this->checkNameLength($node->args[4]->value->value)) {
144
-						$this->errors[] = [
145
-							'line' => $node->getLine(),
146
-							'disallowedToken' => $node->args[4]->value->value,
147
-							'reason' => sprintf(
148
-								'Constraint name is too long on table `%s` (max. 27)',
149
-								$this->tableVariableNames[$node->var->name]
150
-							),
151
-						];
152
-					}
153
-				}
154
-			} else if ($node->name === 'renameColumn') {
155
-				$this->errors[] = [
156
-					'line' => $node->getLine(),
157
-					'disallowedToken' => 'Deprecated method',
158
-					'reason' => sprintf(
159
-						'`$%s->renameColumn()` must not be used',
160
-						$node->var->name
161
-					),
162
-				];
163
-			}
110
+                    // On autoincrement the max length of the table name is 21 instead of 27
111
+                    if (isset($node->args[2]) && $node->args[2]->value instanceof Node\Expr\Array_) {
112
+                        /** @var Node\Expr\Array_ $options */
113
+                        $options = $node->args[2]->value;
114
+                        if ($this->checkColumnForAutoincrement($options)) {
115
+                            if (!$this->checkNameLength($this->tableVariableNames[$node->var->name], true)) {
116
+                                $this->errors[] = [
117
+                                    'line' => $node->getLine(),
118
+                                    'disallowedToken' => $this->tableVariableNames[$node->var->name],
119
+                                    'reason' => 'Table name is too long because of autoincrement (max. 21)',
120
+                                ];
121
+                            }
122
+                        }
123
+                    }
124
+                }
125
+            } else if ($node->name === 'addIndex' ||
126
+                 $node->name === 'addUniqueIndex' ||
127
+                 $node->name === 'renameIndex' ||
128
+                 $node->name === 'setPrimaryKey') {
129
+                if (isset($node->args[1]) && $node->args[1]->value instanceof Node\Scalar\String_) {
130
+                    if (!$this->checkNameLength($node->args[1]->value->value)) {
131
+                        $this->errors[] = [
132
+                            'line' => $node->getLine(),
133
+                            'disallowedToken' => $node->args[1]->value->value,
134
+                            'reason' => sprintf(
135
+                                'Index name is too long on table `%s` (max. 27)',
136
+                                $this->tableVariableNames[$node->var->name]
137
+                            ),
138
+                        ];
139
+                    }
140
+                }
141
+            } else if ($node->name === 'addForeignKeyConstraint') {
142
+                if (isset($node->args[4]) && $node->args[4]->value instanceof Node\Scalar\String_) {
143
+                    if (!$this->checkNameLength($node->args[4]->value->value)) {
144
+                        $this->errors[] = [
145
+                            'line' => $node->getLine(),
146
+                            'disallowedToken' => $node->args[4]->value->value,
147
+                            'reason' => sprintf(
148
+                                'Constraint name is too long on table `%s` (max. 27)',
149
+                                $this->tableVariableNames[$node->var->name]
150
+                            ),
151
+                        ];
152
+                    }
153
+                }
154
+            } else if ($node->name === 'renameColumn') {
155
+                $this->errors[] = [
156
+                    'line' => $node->getLine(),
157
+                    'disallowedToken' => 'Deprecated method',
158
+                    'reason' => sprintf(
159
+                        '`$%s->renameColumn()` must not be used',
160
+                        $node->var->name
161
+                    ),
162
+                ];
163
+            }
164 164
 
165
-		/**
166
-		 * Find the schema
167
-		 */
168
-		} else if ($node instanceof Node\Expr\Assign &&
169
-			 $node->expr instanceof Node\Expr\FuncCall &&
170
-			 $node->var instanceof Node\Expr\Variable &&
171
-			 $node->expr->name instanceof Node\Expr\Variable &&
172
-			 $node->expr->name->name === 'schemaClosure') {
173
-			// E.g. $schema = $schemaClosure();
174
-			$this->schemaVariableName = $node->var->name;
175
-		}
176
-	}
165
+        /**
166
+         * Find the schema
167
+         */
168
+        } else if ($node instanceof Node\Expr\Assign &&
169
+             $node->expr instanceof Node\Expr\FuncCall &&
170
+             $node->var instanceof Node\Expr\Variable &&
171
+             $node->expr->name instanceof Node\Expr\Variable &&
172
+             $node->expr->name->name === 'schemaClosure') {
173
+            // E.g. $schema = $schemaClosure();
174
+            $this->schemaVariableName = $node->var->name;
175
+        }
176
+    }
177 177
 
178
-	protected function checkNameLength($tableName, $hasAutoincrement = false) {
179
-		if ($hasAutoincrement) {
180
-			return strlen($tableName) <= 21;
181
-		}
182
-		return strlen($tableName) <= 27;
183
-	}
178
+    protected function checkNameLength($tableName, $hasAutoincrement = false) {
179
+        if ($hasAutoincrement) {
180
+            return strlen($tableName) <= 21;
181
+        }
182
+        return strlen($tableName) <= 27;
183
+    }
184 184
 
185
-	/**
186
-	 * @param Node\Expr\Array_ $optionsArray
187
-	 * @return bool Whether the column is an autoincrement column
188
-	 */
189
-	protected function checkColumnForAutoincrement(Node\Expr\Array_ $optionsArray) {
190
-		foreach ($optionsArray->items as $option) {
191
-			if ($option->key instanceof Node\Scalar\String_) {
192
-				if ($option->key->value === 'autoincrement' &&
193
-					 $option->value instanceof Node\Expr\ConstFetch) {
194
-					/** @var Node\Expr\ConstFetch $const */
195
-					$const = $option->value;
185
+    /**
186
+     * @param Node\Expr\Array_ $optionsArray
187
+     * @return bool Whether the column is an autoincrement column
188
+     */
189
+    protected function checkColumnForAutoincrement(Node\Expr\Array_ $optionsArray) {
190
+        foreach ($optionsArray->items as $option) {
191
+            if ($option->key instanceof Node\Scalar\String_) {
192
+                if ($option->key->value === 'autoincrement' &&
193
+                     $option->value instanceof Node\Expr\ConstFetch) {
194
+                    /** @var Node\Expr\ConstFetch $const */
195
+                    $const = $option->value;
196 196
 
197
-					if ($const->name instanceof Name &&
198
-						 $const->name->parts === ['true']) {
199
-						return true;
200
-					}
201
-				}
202
-			}
203
-		}
197
+                    if ($const->name instanceof Name &&
198
+                         $const->name->parts === ['true']) {
199
+                        return true;
200
+                    }
201
+                }
202
+            }
203
+        }
204 204
 
205
-		return false;
206
-	}
205
+        return false;
206
+    }
207 207
 }
Please login to merge, or discard this patch.
lib/private/OCS/Exception.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -25,16 +25,16 @@
 block discarded – undo
25 25
 
26 26
 class Exception extends \Exception {
27 27
 
28
-	/** @var Result */
29
-	private $result;
28
+    /** @var Result */
29
+    private $result;
30 30
 
31
-	public function __construct(Result $result) {
32
-		parent::__construct();
33
-		$this->result = $result;
34
-	}
31
+    public function __construct(Result $result) {
32
+        parent::__construct();
33
+        $this->result = $result;
34
+    }
35 35
 
36
-	public function getResult() {
37
-		return $this->result;
38
-	}
36
+    public function getResult() {
37
+        return $this->result;
38
+    }
39 39
 
40 40
 }
Please login to merge, or discard this patch.
lib/private/BackgroundJob/TimedJob.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -32,26 +32,26 @@
 block discarded – undo
32 32
  * @package OC\BackgroundJob
33 33
  */
34 34
 abstract class TimedJob extends Job {
35
-	protected $interval = 0;
35
+    protected $interval = 0;
36 36
 
37
-	/**
38
-	 * set the interval for the job
39
-	 *
40
-	 * @param int $interval
41
-	 */
42
-	public function setInterval($interval) {
43
-		$this->interval = $interval;
44
-	}
37
+    /**
38
+     * set the interval for the job
39
+     *
40
+     * @param int $interval
41
+     */
42
+    public function setInterval($interval) {
43
+        $this->interval = $interval;
44
+    }
45 45
 
46
-	/**
47
-	 * run the job if
48
-	 *
49
-	 * @param JobList $jobList
50
-	 * @param ILogger|null $logger
51
-	 */
52
-	public function execute($jobList, ILogger $logger = null) {
53
-		if ((time() - $this->lastRun) > $this->interval) {
54
-			parent::execute($jobList, $logger);
55
-		}
56
-	}
46
+    /**
47
+     * run the job if
48
+     *
49
+     * @param JobList $jobList
50
+     * @param ILogger|null $logger
51
+     */
52
+    public function execute($jobList, ILogger $logger = null) {
53
+        if ((time() - $this->lastRun) > $this->interval) {
54
+            parent::execute($jobList, $logger);
55
+        }
56
+    }
57 57
 }
Please login to merge, or discard this patch.