Completed
Pull Request — master (#5985)
by Joas
18:13
created
lib/public/Template.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
  * @suppress PhanDeprecatedFunction
52 52
  */
53 53
 function image_path($app, $image) {
54
-	return \image_path($app, $image);
54
+    return \image_path($app, $image);
55 55
 }
56 56
 
57 57
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
  * @suppress PhanDeprecatedFunction
64 64
  */
65 65
 function mimetype_icon($mimetype) {
66
-	return \mimetype_icon($mimetype);
66
+    return \mimetype_icon($mimetype);
67 67
 }
68 68
 
69 69
 /**
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
  * @suppress PhanDeprecatedFunction
75 75
  */
76 76
 function preview_icon($path) {
77
-	return \preview_icon($path);
77
+    return \preview_icon($path);
78 78
 }
79 79
 
80 80
 /**
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
  * @suppress PhanDeprecatedFunction
88 88
  */
89 89
 function publicPreview_icon($path, $token) {
90
-	return \publicPreview_icon($path, $token);
90
+    return \publicPreview_icon($path, $token);
91 91
 }
92 92
 
93 93
 /**
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
  * @suppress PhanDeprecatedFunction
100 100
  */
101 101
 function human_file_size($bytes) {
102
-	return \human_file_size($bytes);
102
+    return \human_file_size($bytes);
103 103
 }
104 104
 
105 105
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
  * @suppress PhanTypeMismatchArgument
115 115
  */
116 116
 function relative_modified_date($timestamp, $dateOnly = false) {
117
-	return \relative_modified_date($timestamp, null, $dateOnly);
117
+    return \relative_modified_date($timestamp, null, $dateOnly);
118 118
 }
119 119
 
120 120
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
  * @suppress PhanDeprecatedFunction
127 127
  */
128 128
 function simple_file_size($bytes) {
129
-	return \human_file_size($bytes);
129
+    return \human_file_size($bytes);
130 130
 }
131 131
 
132 132
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
  * @suppress PhanDeprecatedFunction
141 141
  */
142 142
 function html_select_options($options, $selected, $params=array()) {
143
-	return \html_select_options($options, $selected, $params);
143
+    return \html_select_options($options, $selected, $params);
144 144
 }
145 145
 
146 146
 
@@ -151,109 +151,109 @@  discard block
 block discarded – undo
151 151
  * @since 8.0.0
152 152
  */
153 153
 class Template extends \OC_Template {
154
-	/**
155
-	 * Make OC_Helper::imagePath available as a simple function
156
-	 *
157
-	 * @see \OCP\IURLGenerator::imagePath
158
-	 *
159
-	 * @param string $app
160
-	 * @param string $image
161
-	 * @return string to the image
162
-	 * @since 8.0.0
163
-	 * @suppress PhanDeprecatedFunction
164
-	 */
165
-	public static function image_path($app, $image) {
166
-		return \image_path($app, $image);
167
-	}
154
+    /**
155
+     * Make OC_Helper::imagePath available as a simple function
156
+     *
157
+     * @see \OCP\IURLGenerator::imagePath
158
+     *
159
+     * @param string $app
160
+     * @param string $image
161
+     * @return string to the image
162
+     * @since 8.0.0
163
+     * @suppress PhanDeprecatedFunction
164
+     */
165
+    public static function image_path($app, $image) {
166
+        return \image_path($app, $image);
167
+    }
168 168
 
169
-	/**
170
-	 * @param string $app
171
-	 * @param string $image
172
-	 * @return string content of the image
173
-	 * @since 13.0.0
174
-	 * @suppress PhanDeprecatedFunction
175
-	 */
176
-	public static function inline_image($app, $image) {
177
-		inline_image($app, $image);
178
-	}
169
+    /**
170
+     * @param string $app
171
+     * @param string $image
172
+     * @return string content of the image
173
+     * @since 13.0.0
174
+     * @suppress PhanDeprecatedFunction
175
+     */
176
+    public static function inline_image($app, $image) {
177
+        inline_image($app, $image);
178
+    }
179 179
 
180 180
 
181
-	/**
182
-	 * Make OC_Helper::mimetypeIcon available as a simple function
183
-	 *
184
-	 * @param string $mimetype
185
-	 * @return string to the image of this file type.
186
-	 * @since 8.0.0
187
-	 * @suppress PhanDeprecatedFunction
188
-	 */
189
-	public static function mimetype_icon($mimetype) {
190
-		return \mimetype_icon($mimetype);
191
-	}
181
+    /**
182
+     * Make OC_Helper::mimetypeIcon available as a simple function
183
+     *
184
+     * @param string $mimetype
185
+     * @return string to the image of this file type.
186
+     * @since 8.0.0
187
+     * @suppress PhanDeprecatedFunction
188
+     */
189
+    public static function mimetype_icon($mimetype) {
190
+        return \mimetype_icon($mimetype);
191
+    }
192 192
 
193
-	/**
194
-	 * Make preview_icon available as a simple function
195
-	 *
196
-	 * @param string $path path to file
197
-	 * @return string to the preview of the image
198
-	 * @since 8.0.0
199
-	 * @suppress PhanDeprecatedFunction
200
-	 */
201
-	public static function preview_icon($path) {
202
-		return \preview_icon($path);
203
-	}
193
+    /**
194
+     * Make preview_icon available as a simple function
195
+     *
196
+     * @param string $path path to file
197
+     * @return string to the preview of the image
198
+     * @since 8.0.0
199
+     * @suppress PhanDeprecatedFunction
200
+     */
201
+    public static function preview_icon($path) {
202
+        return \preview_icon($path);
203
+    }
204 204
 
205
-	/**
206
-	 * Make publicpreview_icon available as a simple function
207
-	 * Returns the path to the preview of the image.
208
-	 *
209
-	 * @param string $path of file
210
-	 * @param string $token
211
-	 * @return string link to the preview
212
-	 * @since 8.0.0
213
-	 * @suppress PhanDeprecatedFunction
214
-	 */
215
-	public static function publicPreview_icon($path, $token) {
216
-		return \publicPreview_icon($path, $token);
217
-	}
205
+    /**
206
+     * Make publicpreview_icon available as a simple function
207
+     * Returns the path to the preview of the image.
208
+     *
209
+     * @param string $path of file
210
+     * @param string $token
211
+     * @return string link to the preview
212
+     * @since 8.0.0
213
+     * @suppress PhanDeprecatedFunction
214
+     */
215
+    public static function publicPreview_icon($path, $token) {
216
+        return \publicPreview_icon($path, $token);
217
+    }
218 218
 
219
-	/**
220
-	 * Make OC_Helper::humanFileSize available as a simple function
221
-	 * Example: 2048 to 2 kB.
222
-	 *
223
-	 * @param int $bytes in bytes
224
-	 * @return string size as string
225
-	 * @since 8.0.0
226
-	 * @suppress PhanDeprecatedFunction
227
-	 */
228
-	public static function human_file_size($bytes) {
229
-		return \human_file_size($bytes);
230
-	}
219
+    /**
220
+     * Make OC_Helper::humanFileSize available as a simple function
221
+     * Example: 2048 to 2 kB.
222
+     *
223
+     * @param int $bytes in bytes
224
+     * @return string size as string
225
+     * @since 8.0.0
226
+     * @suppress PhanDeprecatedFunction
227
+     */
228
+    public static function human_file_size($bytes) {
229
+        return \human_file_size($bytes);
230
+    }
231 231
 
232
-	/**
233
-	 * Return the relative date in relation to today. Returns something like "last hour" or "two month ago"
234
-	 *
235
-	 * @param int $timestamp unix timestamp
236
-	 * @param boolean $dateOnly
237
-	 * @return string human readable interpretation of the timestamp
238
-	 * @since 8.0.0
239
-	 * @suppress PhanDeprecatedFunction
240
-	 * @suppress PhanTypeMismatchArgument
241
-	 */
242
-	public static function relative_modified_date($timestamp, $dateOnly = false) {
243
-		return \relative_modified_date($timestamp, null, $dateOnly);
244
-	}
232
+    /**
233
+     * Return the relative date in relation to today. Returns something like "last hour" or "two month ago"
234
+     *
235
+     * @param int $timestamp unix timestamp
236
+     * @param boolean $dateOnly
237
+     * @return string human readable interpretation of the timestamp
238
+     * @since 8.0.0
239
+     * @suppress PhanDeprecatedFunction
240
+     * @suppress PhanTypeMismatchArgument
241
+     */
242
+    public static function relative_modified_date($timestamp, $dateOnly = false) {
243
+        return \relative_modified_date($timestamp, null, $dateOnly);
244
+    }
245 245
 
246
-	/**
247
-	 * Generate html code for an options block.
248
-	 *
249
-	 * @param array $options the options
250
-	 * @param mixed $selected which one is selected?
251
-	 * @param array $params the parameters
252
-	 * @return string html options
253
-	 * @since 8.0.0
254
-	 * @suppress PhanDeprecatedFunction
255
-	 */
256
-	public static function html_select_options($options, $selected, $params=array()) {
257
-		return \html_select_options($options, $selected, $params);
258
-	}
246
+    /**
247
+     * Generate html code for an options block.
248
+     *
249
+     * @param array $options the options
250
+     * @param mixed $selected which one is selected?
251
+     * @param array $params the parameters
252
+     * @return string html options
253
+     * @since 8.0.0
254
+     * @suppress PhanDeprecatedFunction
255
+     */
256
+    public static function html_select_options($options, $selected, $params=array()) {
257
+        return \html_select_options($options, $selected, $params);
258
+    }
259 259
 }
Please login to merge, or discard this patch.
lib/private/legacy/template/functions.php 2 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
  * @param string $string the string which will be escaped and printed
36 36
  */
37 37
 function p($string) {
38
-	print(\OCP\Util::sanitizeHTML($string));
38
+    print(\OCP\Util::sanitizeHTML($string));
39 39
 }
40 40
 
41 41
 
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
  * @param string $opts, additional optional options
46 46
 */
47 47
 function emit_css_tag($href, $opts = '') {
48
-	$s='<link rel="stylesheet"';
49
-	if (!empty($href)) {
50
-		$s.=' href="' . $href .'"';
51
-	}
52
-	if (!empty($opts)) {
53
-		$s.=' '.$opts;
54
-	}
55
-	print_unescaped($s.">\n");
48
+    $s='<link rel="stylesheet"';
49
+    if (!empty($href)) {
50
+        $s.=' href="' . $href .'"';
51
+    }
52
+    if (!empty($opts)) {
53
+        $s.=' '.$opts;
54
+    }
55
+    print_unescaped($s.">\n");
56 56
 }
57 57
 
58 58
 /**
@@ -60,12 +60,12 @@  discard block
 block discarded – undo
60 60
  * @param array $obj all the script information from template
61 61
 */
62 62
 function emit_css_loading_tags($obj) {
63
-	foreach($obj['cssfiles'] as $css) {
64
-		emit_css_tag($css);
65
-	}
66
-	foreach($obj['printcssfiles'] as $css) {
67
-		emit_css_tag($css, 'media="print"');
68
-	}
63
+    foreach($obj['cssfiles'] as $css) {
64
+        emit_css_tag($css);
65
+    }
66
+    foreach($obj['printcssfiles'] as $css) {
67
+        emit_css_tag($css, 'media="print"');
68
+    }
69 69
 }
70 70
 
71 71
 /**
@@ -74,20 +74,20 @@  discard block
 block discarded – undo
74 74
  * @param string $script_content the inline script content, ignored when empty
75 75
 */
76 76
 function emit_script_tag($src, $script_content='') {
77
-	$defer_str=' defer';
78
-	$s='<script nonce="' . \OC::$server->getContentSecurityPolicyNonceManager()->getNonce() . '"';
79
-	if (!empty($src)) {
80
-		 // emit script tag for deferred loading from $src
81
-		$s.=$defer_str.' src="' . $src .'">';
82
-	} else if (!empty($script_content)) {
83
-		// emit script tag for inline script from $script_content without defer (see MDN)
84
-		$s.=">\n".$script_content."\n";
85
-	} else {
86
-		// no $src nor $src_content, really useless empty tag
87
-		$s.='>';
88
-	}
89
-	$s.='</script>';
90
-	print_unescaped($s."\n");
77
+    $defer_str=' defer';
78
+    $s='<script nonce="' . \OC::$server->getContentSecurityPolicyNonceManager()->getNonce() . '"';
79
+    if (!empty($src)) {
80
+            // emit script tag for deferred loading from $src
81
+        $s.=$defer_str.' src="' . $src .'">';
82
+    } else if (!empty($script_content)) {
83
+        // emit script tag for inline script from $script_content without defer (see MDN)
84
+        $s.=">\n".$script_content."\n";
85
+    } else {
86
+        // no $src nor $src_content, really useless empty tag
87
+        $s.='>';
88
+    }
89
+    $s.='</script>';
90
+    print_unescaped($s."\n");
91 91
 }
92 92
 
93 93
 /**
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
  * @param array $obj all the script information from template
96 96
 */
97 97
 function emit_script_loading_tags($obj) {
98
-	foreach($obj['jsfiles'] as $jsfile) {
99
-		emit_script_tag($jsfile, '');
100
-	}
101
-	if (!empty($obj['inline_ocjs'])) {
102
-		emit_script_tag('', $obj['inline_ocjs']);
103
-	}
98
+    foreach($obj['jsfiles'] as $jsfile) {
99
+        emit_script_tag($jsfile, '');
100
+    }
101
+    if (!empty($obj['inline_ocjs'])) {
102
+        emit_script_tag('', $obj['inline_ocjs']);
103
+    }
104 104
 }
105 105
 
106 106
 /**
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
  * @param string|array $string the string which will be printed as it is
110 110
  */
111 111
 function print_unescaped($string) {
112
-	print($string);
112
+    print($string);
113 113
 }
114 114
 
115 115
 /**
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
  * if an array is given it will add all scripts
120 120
  */
121 121
 function script($app, $file = null) {
122
-	if(is_array($file)) {
123
-		foreach($file as $f) {
124
-			OC_Util::addScript($app, $f);
125
-		}
126
-	} else {
127
-		OC_Util::addScript($app, $file);
128
-	}
122
+    if(is_array($file)) {
123
+        foreach($file as $f) {
124
+            OC_Util::addScript($app, $f);
125
+        }
126
+    } else {
127
+        OC_Util::addScript($app, $file);
128
+    }
129 129
 }
130 130
 
131 131
 /**
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
  * if an array is given it will add all scripts
136 136
  */
137 137
 function vendor_script($app, $file = null) {
138
-	if(is_array($file)) {
139
-		foreach($file as $f) {
140
-			OC_Util::addVendorScript($app, $f);
141
-		}
142
-	} else {
143
-		OC_Util::addVendorScript($app, $file);
144
-	}
138
+    if(is_array($file)) {
139
+        foreach($file as $f) {
140
+            OC_Util::addVendorScript($app, $f);
141
+        }
142
+    } else {
143
+        OC_Util::addVendorScript($app, $file);
144
+    }
145 145
 }
146 146
 
147 147
 /**
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
  * if an array is given it will add all styles
152 152
  */
153 153
 function style($app, $file = null) {
154
-	if(is_array($file)) {
155
-		foreach($file as $f) {
156
-			OC_Util::addStyle($app, $f);
157
-		}
158
-	} else {
159
-		OC_Util::addStyle($app, $file);
160
-	}
154
+    if(is_array($file)) {
155
+        foreach($file as $f) {
156
+            OC_Util::addStyle($app, $f);
157
+        }
158
+    } else {
159
+        OC_Util::addStyle($app, $file);
160
+    }
161 161
 }
162 162
 
163 163
 /**
@@ -167,13 +167,13 @@  discard block
 block discarded – undo
167 167
  * if an array is given it will add all styles
168 168
  */
169 169
 function vendor_style($app, $file = null) {
170
-	if(is_array($file)) {
171
-		foreach($file as $f) {
172
-			OC_Util::addVendorStyle($app, $f);
173
-		}
174
-	} else {
175
-		OC_Util::addVendorStyle($app, $file);
176
-	}
170
+    if(is_array($file)) {
171
+        foreach($file as $f) {
172
+            OC_Util::addVendorStyle($app, $f);
173
+        }
174
+    } else {
175
+        OC_Util::addVendorStyle($app, $file);
176
+    }
177 177
 }
178 178
 
179 179
 /**
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
  * if an array is given it will add all styles
183 183
  */
184 184
 function translation($app) {
185
-	OC_Util::addTranslations($app);
185
+    OC_Util::addTranslations($app);
186 186
 }
187 187
 
188 188
 /**
@@ -192,15 +192,15 @@  discard block
 block discarded – undo
192 192
  * if an array is given it will add all components
193 193
  */
194 194
 function component($app, $file) {
195
-	if(is_array($file)) {
196
-		foreach($file as $f) {
197
-			$url = link_to($app, 'component/' . $f . '.html');
198
-			OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
199
-		}
200
-	} else {
201
-		$url = link_to($app, 'component/' . $file . '.html');
202
-		OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
203
-	}
195
+    if(is_array($file)) {
196
+        foreach($file as $f) {
197
+            $url = link_to($app, 'component/' . $f . '.html');
198
+            OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
199
+        }
200
+    } else {
201
+        $url = link_to($app, 'component/' . $file . '.html');
202
+        OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
203
+    }
204 204
 }
205 205
 
206 206
 /**
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
  * For further information have a look at \OCP\IURLGenerator::linkTo
214 214
  */
215 215
 function link_to( $app, $file, $args = array() ) {
216
-	return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
216
+    return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
217 217
 }
218 218
 
219 219
 /**
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
  * @return string url to the online documentation
222 222
  */
223 223
 function link_to_docs($key) {
224
-	return \OC::$server->getURLGenerator()->linkToDocs($key);
224
+    return \OC::$server->getURLGenerator()->linkToDocs($key);
225 225
 }
226 226
 
227 227
 /**
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
  * For further information have a look at \OCP\IURLGenerator::imagePath
234 234
  */
235 235
 function image_path( $app, $image ) {
236
-	return \OC::$server->getURLGenerator()->imagePath( $app, $image );
236
+    return \OC::$server->getURLGenerator()->imagePath( $app, $image );
237 237
 }
238 238
 
239 239
 /**
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
  * @return string content of the image
243 243
  */
244 244
 function inline_image($app, $image) {
245
-	echo file_get_contents(\OC::$SERVERROOT . image_path($app, $image));
245
+    echo file_get_contents(\OC::$SERVERROOT . image_path($app, $image));
246 246
 }
247 247
 
248 248
 /**
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
  * @return string link to the image
252 252
  */
253 253
 function mimetype_icon( $mimetype ) {
254
-	return \OC::$server->getMimeTypeDetector()->mimeTypeIcon( $mimetype );
254
+    return \OC::$server->getMimeTypeDetector()->mimeTypeIcon( $mimetype );
255 255
 }
256 256
 
257 257
 /**
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
  * @return string link to the preview
262 262
  */
263 263
 function preview_icon( $path ) {
264
-	return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]);
264
+    return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]);
265 265
 }
266 266
 
267 267
 /**
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
  * @return string
271 271
  */
272 272
 function publicPreview_icon ( $path, $token ) {
273
-	return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 't' => $token]);
273
+    return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 't' => $token]);
274 274
 }
275 275
 
276 276
 /**
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
  * For further information have a look at OC_Helper::humanFileSize
282 282
  */
283 283
 function human_file_size( $bytes ) {
284
-	return OC_Helper::humanFileSize( $bytes );
284
+    return OC_Helper::humanFileSize( $bytes );
285 285
 }
286 286
 
287 287
 /**
@@ -290,9 +290,9 @@  discard block
 block discarded – undo
290 290
  * @return $timestamp without time value
291 291
  */
292 292
 function strip_time($timestamp){
293
-	$date = new \DateTime("@{$timestamp}");
294
-	$date->setTime(0, 0, 0);
295
-	return intval($date->format('U'));
293
+    $date = new \DateTime("@{$timestamp}");
294
+    $date->setTime(0, 0, 0);
295
+    return intval($date->format('U'));
296 296
 }
297 297
 
298 298
 /**
@@ -304,39 +304,39 @@  discard block
 block discarded – undo
304 304
  * @return string timestamp
305 305
  */
306 306
 function relative_modified_date($timestamp, $fromTime = null, $dateOnly = false) {
307
-	/** @var \OC\DateTimeFormatter $formatter */
308
-	$formatter = \OC::$server->query('DateTimeFormatter');
307
+    /** @var \OC\DateTimeFormatter $formatter */
308
+    $formatter = \OC::$server->query('DateTimeFormatter');
309 309
 
310
-	if ($dateOnly){
311
-		return $formatter->formatDateSpan($timestamp, $fromTime);
312
-	}
313
-	return $formatter->formatTimeSpan($timestamp, $fromTime);
310
+    if ($dateOnly){
311
+        return $formatter->formatDateSpan($timestamp, $fromTime);
312
+    }
313
+    return $formatter->formatTimeSpan($timestamp, $fromTime);
314 314
 }
315 315
 
316 316
 function html_select_options($options, $selected, $params=array()) {
317
-	if (!is_array($selected)) {
318
-		$selected=array($selected);
319
-	}
320
-	if (isset($params['combine']) && $params['combine']) {
321
-		$options = array_combine($options, $options);
322
-	}
323
-	$value_name = $label_name = false;
324
-	if (isset($params['value'])) {
325
-		$value_name = $params['value'];
326
-	}
327
-	if (isset($params['label'])) {
328
-		$label_name = $params['label'];
329
-	}
330
-	$html = '';
331
-	foreach($options as $value => $label) {
332
-		if ($value_name && is_array($label)) {
333
-			$value = $label[$value_name];
334
-		}
335
-		if ($label_name && is_array($label)) {
336
-			$label = $label[$label_name];
337
-		}
338
-		$select = in_array($value, $selected) ? ' selected="selected"' : '';
339
-		$html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n";
340
-	}
341
-	return $html;
317
+    if (!is_array($selected)) {
318
+        $selected=array($selected);
319
+    }
320
+    if (isset($params['combine']) && $params['combine']) {
321
+        $options = array_combine($options, $options);
322
+    }
323
+    $value_name = $label_name = false;
324
+    if (isset($params['value'])) {
325
+        $value_name = $params['value'];
326
+    }
327
+    if (isset($params['label'])) {
328
+        $label_name = $params['label'];
329
+    }
330
+    $html = '';
331
+    foreach($options as $value => $label) {
332
+        if ($value_name && is_array($label)) {
333
+            $value = $label[$value_name];
334
+        }
335
+        if ($label_name && is_array($label)) {
336
+            $label = $label[$label_name];
337
+        }
338
+        $select = in_array($value, $selected) ? ' selected="selected"' : '';
339
+        $html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n";
340
+    }
341
+    return $html;
342 342
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -45,12 +45,12 @@  discard block
 block discarded – undo
45 45
  * @param string $opts, additional optional options
46 46
 */
47 47
 function emit_css_tag($href, $opts = '') {
48
-	$s='<link rel="stylesheet"';
48
+	$s = '<link rel="stylesheet"';
49 49
 	if (!empty($href)) {
50
-		$s.=' href="' . $href .'"';
50
+		$s .= ' href="'.$href.'"';
51 51
 	}
52 52
 	if (!empty($opts)) {
53
-		$s.=' '.$opts;
53
+		$s .= ' '.$opts;
54 54
 	}
55 55
 	print_unescaped($s.">\n");
56 56
 }
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
  * @param array $obj all the script information from template
61 61
 */
62 62
 function emit_css_loading_tags($obj) {
63
-	foreach($obj['cssfiles'] as $css) {
63
+	foreach ($obj['cssfiles'] as $css) {
64 64
 		emit_css_tag($css);
65 65
 	}
66
-	foreach($obj['printcssfiles'] as $css) {
66
+	foreach ($obj['printcssfiles'] as $css) {
67 67
 		emit_css_tag($css, 'media="print"');
68 68
 	}
69 69
 }
@@ -73,20 +73,20 @@  discard block
 block discarded – undo
73 73
  * @param string $src the source URL, ignored when empty
74 74
  * @param string $script_content the inline script content, ignored when empty
75 75
 */
76
-function emit_script_tag($src, $script_content='') {
77
-	$defer_str=' defer';
78
-	$s='<script nonce="' . \OC::$server->getContentSecurityPolicyNonceManager()->getNonce() . '"';
76
+function emit_script_tag($src, $script_content = '') {
77
+	$defer_str = ' defer';
78
+	$s = '<script nonce="'.\OC::$server->getContentSecurityPolicyNonceManager()->getNonce().'"';
79 79
 	if (!empty($src)) {
80 80
 		 // emit script tag for deferred loading from $src
81
-		$s.=$defer_str.' src="' . $src .'">';
81
+		$s .= $defer_str.' src="'.$src.'">';
82 82
 	} else if (!empty($script_content)) {
83 83
 		// emit script tag for inline script from $script_content without defer (see MDN)
84
-		$s.=">\n".$script_content."\n";
84
+		$s .= ">\n".$script_content."\n";
85 85
 	} else {
86 86
 		// no $src nor $src_content, really useless empty tag
87
-		$s.='>';
87
+		$s .= '>';
88 88
 	}
89
-	$s.='</script>';
89
+	$s .= '</script>';
90 90
 	print_unescaped($s."\n");
91 91
 }
92 92
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
  * @param array $obj all the script information from template
96 96
 */
97 97
 function emit_script_loading_tags($obj) {
98
-	foreach($obj['jsfiles'] as $jsfile) {
98
+	foreach ($obj['jsfiles'] as $jsfile) {
99 99
 		emit_script_tag($jsfile, '');
100 100
 	}
101 101
 	if (!empty($obj['inline_ocjs'])) {
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
  * if an array is given it will add all scripts
120 120
  */
121 121
 function script($app, $file = null) {
122
-	if(is_array($file)) {
123
-		foreach($file as $f) {
122
+	if (is_array($file)) {
123
+		foreach ($file as $f) {
124 124
 			OC_Util::addScript($app, $f);
125 125
 		}
126 126
 	} else {
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
  * if an array is given it will add all scripts
136 136
  */
137 137
 function vendor_script($app, $file = null) {
138
-	if(is_array($file)) {
139
-		foreach($file as $f) {
138
+	if (is_array($file)) {
139
+		foreach ($file as $f) {
140 140
 			OC_Util::addVendorScript($app, $f);
141 141
 		}
142 142
 	} else {
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
  * if an array is given it will add all styles
152 152
  */
153 153
 function style($app, $file = null) {
154
-	if(is_array($file)) {
155
-		foreach($file as $f) {
154
+	if (is_array($file)) {
155
+		foreach ($file as $f) {
156 156
 			OC_Util::addStyle($app, $f);
157 157
 		}
158 158
 	} else {
@@ -167,8 +167,8 @@  discard block
 block discarded – undo
167 167
  * if an array is given it will add all styles
168 168
  */
169 169
 function vendor_style($app, $file = null) {
170
-	if(is_array($file)) {
171
-		foreach($file as $f) {
170
+	if (is_array($file)) {
171
+		foreach ($file as $f) {
172 172
 			OC_Util::addVendorStyle($app, $f);
173 173
 		}
174 174
 	} else {
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
  * if an array is given it will add all components
193 193
  */
194 194
 function component($app, $file) {
195
-	if(is_array($file)) {
196
-		foreach($file as $f) {
197
-			$url = link_to($app, 'component/' . $f . '.html');
195
+	if (is_array($file)) {
196
+		foreach ($file as $f) {
197
+			$url = link_to($app, 'component/'.$f.'.html');
198 198
 			OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
199 199
 		}
200 200
 	} else {
201
-		$url = link_to($app, 'component/' . $file . '.html');
201
+		$url = link_to($app, 'component/'.$file.'.html');
202 202
 		OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
203 203
 	}
204 204
 }
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
  *
213 213
  * For further information have a look at \OCP\IURLGenerator::linkTo
214 214
  */
215
-function link_to( $app, $file, $args = array() ) {
215
+function link_to($app, $file, $args = array()) {
216 216
 	return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
217 217
 }
218 218
 
@@ -232,8 +232,8 @@  discard block
 block discarded – undo
232 232
  *
233 233
  * For further information have a look at \OCP\IURLGenerator::imagePath
234 234
  */
235
-function image_path( $app, $image ) {
236
-	return \OC::$server->getURLGenerator()->imagePath( $app, $image );
235
+function image_path($app, $image) {
236
+	return \OC::$server->getURLGenerator()->imagePath($app, $image);
237 237
 }
238 238
 
239 239
 /**
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
  * @return string content of the image
243 243
  */
244 244
 function inline_image($app, $image) {
245
-	echo file_get_contents(\OC::$SERVERROOT . image_path($app, $image));
245
+	echo file_get_contents(\OC::$SERVERROOT.image_path($app, $image));
246 246
 }
247 247
 
248 248
 /**
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
  * @param string $mimetype mimetype
251 251
  * @return string link to the image
252 252
  */
253
-function mimetype_icon( $mimetype ) {
254
-	return \OC::$server->getMimeTypeDetector()->mimeTypeIcon( $mimetype );
253
+function mimetype_icon($mimetype) {
254
+	return \OC::$server->getMimeTypeDetector()->mimeTypeIcon($mimetype);
255 255
 }
256 256
 
257 257
 /**
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
  * @param string $path path of file
261 261
  * @return string link to the preview
262 262
  */
263
-function preview_icon( $path ) {
263
+function preview_icon($path) {
264 264
 	return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]);
265 265
 }
266 266
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
  * @param string $token
270 270
  * @return string
271 271
  */
272
-function publicPreview_icon ( $path, $token ) {
272
+function publicPreview_icon($path, $token) {
273 273
 	return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 't' => $token]);
274 274
 }
275 275
 
@@ -280,8 +280,8 @@  discard block
 block discarded – undo
280 280
  *
281 281
  * For further information have a look at OC_Helper::humanFileSize
282 282
  */
283
-function human_file_size( $bytes ) {
284
-	return OC_Helper::humanFileSize( $bytes );
283
+function human_file_size($bytes) {
284
+	return OC_Helper::humanFileSize($bytes);
285 285
 }
286 286
 
287 287
 /**
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
  * @param int $timestamp UNIX timestamp to strip
290 290
  * @return $timestamp without time value
291 291
  */
292
-function strip_time($timestamp){
292
+function strip_time($timestamp) {
293 293
 	$date = new \DateTime("@{$timestamp}");
294 294
 	$date->setTime(0, 0, 0);
295 295
 	return intval($date->format('U'));
@@ -307,15 +307,15 @@  discard block
 block discarded – undo
307 307
 	/** @var \OC\DateTimeFormatter $formatter */
308 308
 	$formatter = \OC::$server->query('DateTimeFormatter');
309 309
 
310
-	if ($dateOnly){
310
+	if ($dateOnly) {
311 311
 		return $formatter->formatDateSpan($timestamp, $fromTime);
312 312
 	}
313 313
 	return $formatter->formatTimeSpan($timestamp, $fromTime);
314 314
 }
315 315
 
316
-function html_select_options($options, $selected, $params=array()) {
316
+function html_select_options($options, $selected, $params = array()) {
317 317
 	if (!is_array($selected)) {
318
-		$selected=array($selected);
318
+		$selected = array($selected);
319 319
 	}
320 320
 	if (isset($params['combine']) && $params['combine']) {
321 321
 		$options = array_combine($options, $options);
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 		$label_name = $params['label'];
329 329
 	}
330 330
 	$html = '';
331
-	foreach($options as $value => $label) {
331
+	foreach ($options as $value => $label) {
332 332
 		if ($value_name && is_array($label)) {
333 333
 			$value = $label[$value_name];
334 334
 		}
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 			$label = $label[$label_name];
337 337
 		}
338 338
 		$select = in_array($value, $selected) ? ' selected="selected"' : '';
339
-		$html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n";
339
+		$html .= '<option value="'.\OCP\Util::sanitizeHTML($value).'"'.$select.'>'.\OCP\Util::sanitizeHTML($label).'</option>'."\n";
340 340
 	}
341 341
 	return $html;
342 342
 }
Please login to merge, or discard this patch.