66 * SPDX-License-Identifier: AGPL-3.0-only
77 */
88
9+ use OC \Security \CSP \ContentSecurityPolicyNonceManager ;
10+ use OCP \Files \IMimeTypeDetector ;
911use OCP \IDateTimeFormatter ;
12+ use OCP \IURLGenerator ;
13+ use OCP \Server ;
1014use OCP \Util ;
1115
12- function p ($ string ) {
13- print (\ OCP \ Util::sanitizeHTML ($ string ));
16+ function p (string $ string ): void {
17+ print (Util::sanitizeHTML ($ string ));
1418}
1519
16-
1720/**
1821 * Prints a <link> tag for loading css
1922 * @param string $href the source URL, ignored when empty
2023 * @param string $opts, additional optional options
2124 */
22- function emit_css_tag ($ href , $ opts = '' ) {
25+ function emit_css_tag ($ href , $ opts = '' ): void {
2326 $ s = '<link rel="stylesheet" ' ;
2427 if (!empty ($ href )) {
2528 $ s .= ' href=" ' . $ href . '" ' ;
@@ -34,7 +37,7 @@ function emit_css_tag($href, $opts = '') {
3437 * Prints all tags for CSS loading
3538 * @param array $obj all the script information from template
3639 */
37- function emit_css_loading_tags ($ obj ) {
40+ function emit_css_loading_tags ($ obj ): void {
3841 foreach ($ obj ['cssfiles ' ] as $ css ) {
3942 emit_css_tag ($ css );
4043 }
@@ -49,8 +52,8 @@ function emit_css_loading_tags($obj) {
4952 * @param string $script_content the inline script content, ignored when empty
5053 * @param string $content_type the type of the source (e.g. 'module')
5154 */
52- function emit_script_tag (string $ src , string $ script_content = '' , string $ content_type = '' ) {
53- $ nonceManager = \ OC :: $ server -> get (\ OC \ Security \ CSP \ ContentSecurityPolicyNonceManager::class);
55+ function emit_script_tag (string $ src , string $ script_content = '' , string $ content_type = '' ): void {
56+ $ nonceManager = Server:: get (ContentSecurityPolicyNonceManager::class);
5457
5558 $ defer_str = ' defer ' ;
5659 $ type = $ content_type !== '' ? ' type=" ' . $ content_type . '" ' : '' ;
@@ -74,7 +77,7 @@ function emit_script_tag(string $src, string $script_content = '', string $conte
7477 * Print all <script> tags for loading JS
7578 * @param array $obj all the script information from template
7679 */
77- function emit_script_loading_tags ($ obj ) {
80+ function emit_script_loading_tags ($ obj ): void {
7881 foreach ($ obj ['jsfiles ' ] as $ jsfile ) {
7982 $ fileName = explode ('? ' , $ jsfile , 2 )[0 ];
8083 $ type = str_ends_with ($ fileName , '.mjs ' ) ? 'module ' : '' ;
@@ -88,9 +91,9 @@ function emit_script_loading_tags($obj) {
8891/**
8992 * Prints an unsanitized string - usage of this function may result into XSS.
9093 * Consider using p() instead.
91- * @param string|array $string the string which will be printed as it is
94+ * @param string $string the string which will be printed as it is
9295 */
93- function print_unescaped ($ string ) {
96+ function print_unescaped ($ string ): void {
9497 print ($ string );
9598}
9699
@@ -106,7 +109,7 @@ function print_unescaped($string) {
106109 * @param string|string[] $file the filename,
107110 * if an array is given it will add all scripts
108111 */
109- function script ($ app , $ file = null ) {
112+ function script ($ app , $ file = null ): void {
110113 if (is_array ($ file )) {
111114 foreach ($ file as $ script ) {
112115 Util::addScript ($ app , $ script , 'core ' );
@@ -122,7 +125,7 @@ function script($app, $file = null) {
122125 * @param string|string[] $file the filename,
123126 * if an array is given it will add all scripts
124127 */
125- function vendor_script ($ app , $ file = null ) {
128+ function vendor_script ($ app , $ file = null ): void {
126129 if (is_array ($ file )) {
127130 foreach ($ file as $ f ) {
128131 OC_Util::addVendorScript ($ app , $ f );
@@ -138,7 +141,7 @@ function vendor_script($app, $file = null) {
138141 * @param string|string[] $file the filename,
139142 * if an array is given it will add all styles
140143 */
141- function style ($ app , $ file = null ) {
144+ function style ($ app , $ file = null ): void {
142145 if (is_array ($ file )) {
143146 foreach ($ file as $ f ) {
144147 OC_Util::addStyle ($ app , $ f );
@@ -154,7 +157,7 @@ function style($app, $file = null) {
154157 * @param string|string[] $file the filename,
155158 * if an array is given it will add all styles
156159 */
157- function vendor_style ($ app , $ file = null ) {
160+ function vendor_style ($ app , $ file = null ): void {
158161 if (is_array ($ file )) {
159162 foreach ($ file as $ f ) {
160163 OC_Util::addVendorStyle ($ app , $ f );
@@ -169,28 +172,10 @@ function vendor_style($app, $file = null) {
169172 * @param string $app the appname
170173 * if an array is given it will add all styles
171174 */
172- function translation ($ app ) {
175+ function translation ($ app ): void {
173176 OC_Util::addTranslations ($ app );
174177}
175178
176- /**
177- * Shortcut for HTML imports
178- * @param string $app the appname
179- * @param string|string[] $file the path relative to the app's component folder,
180- * if an array is given it will add all components
181- */
182- function component ($ app , $ file ) {
183- if (is_array ($ file )) {
184- foreach ($ file as $ f ) {
185- $ url = link_to ($ app , 'component/ ' . $ f . '.html ' );
186- OC_Util::addHeader ('link ' , ['rel ' => 'import ' , 'href ' => $ url ]);
187- }
188- } else {
189- $ url = link_to ($ app , 'component/ ' . $ file . '.html ' );
190- OC_Util::addHeader ('link ' , ['rel ' => 'import ' , 'href ' => $ url ]);
191- }
192- }
193-
194179/**
195180 * make \OCP\IURLGenerator::linkTo available as a simple function
196181 * @param string $app app
@@ -201,15 +186,15 @@ function component($app, $file) {
201186 * For further information have a look at \OCP\IURLGenerator::linkTo
202187 */
203188function link_to ($ app , $ file , $ args = []) {
204- return \ OC :: $ server -> getURLGenerator ( )->linkTo ($ app , $ file , $ args );
189+ return Server:: get (IURLGenerator::class )->linkTo ($ app , $ file , $ args );
205190}
206191
207192/**
208- * @param $key
193+ * @param string $key
209194 * @return string url to the online documentation
210195 */
211196function link_to_docs ($ key ) {
212- return \ OC :: $ server -> getURLGenerator ( )->linkToDocs ($ key );
197+ return Server:: get (IURLGenerator::class )->linkToDocs ($ key );
213198}
214199
215200/**
@@ -221,16 +206,16 @@ function link_to_docs($key) {
221206 * For further information have a look at \OCP\IURLGenerator::imagePath
222207 */
223208function image_path ($ app , $ image ) {
224- return \ OC :: $ server -> getURLGenerator ( )->imagePath ($ app , $ image );
209+ return Server:: get (IURLGenerator::class )->imagePath ($ app , $ image );
225210}
226211
227212/**
228- * make OC_Helper:: mimetypeIcon available as a simple function
213+ * make mimetypeIcon available as a simple function
229214 * @param string $mimetype mimetype
230215 * @return string link to the image
231216 */
232217function mimetype_icon ($ mimetype ) {
233- return \ OC :: $ server -> getMimeTypeDetector ( )->mimeTypeIcon ($ mimetype );
218+ return Server:: get (IMimeTypeDetector::class )->mimeTypeIcon ($ mimetype );
234219}
235220
236221/**
@@ -240,7 +225,7 @@ function mimetype_icon($mimetype) {
240225 * @return string link to the preview
241226 */
242227function preview_icon ($ path ) {
243- return \ OC :: $ server -> getURLGenerator ( )->linkToRoute ('core.Preview.getPreview ' , ['x ' => 32 , 'y ' => 32 , 'file ' => $ path ]);
228+ return Server:: get (IURLGenerator::class )->linkToRoute ('core.Preview.getPreview ' , ['x ' => 32 , 'y ' => 32 , 'file ' => $ path ]);
244229}
245230
246231/**
@@ -249,18 +234,19 @@ function preview_icon($path) {
249234 * @return string
250235 */
251236function publicPreview_icon ($ path , $ token ) {
252- return \ OC :: $ server -> getURLGenerator ( )->linkToRoute ('files_sharing.PublicPreview.getPreview ' , ['x ' => 32 , 'y ' => 32 , 'file ' => $ path , 'token ' => $ token ]);
237+ return Server:: get (IURLGenerator::class )->linkToRoute ('files_sharing.PublicPreview.getPreview ' , ['x ' => 32 , 'y ' => 32 , 'file ' => $ path , 'token ' => $ token ]);
253238}
254239
255240/**
256- * make OC_Helper ::humanFileSize available as a simple function
241+ * make Util ::humanFileSize available as a simple function
257242 * @param int $bytes size in bytes
258243 * @return string size as string
244+ * @deprecated use Util::humanFileSize instead
259245 *
260- * For further information have a look at OC_Helper ::humanFileSize
246+ * For further information have a look at Util ::humanFileSize
261247 */
262248function human_file_size ($ bytes ) {
263- return OC_Helper ::humanFileSize ($ bytes );
249+ return Util ::humanFileSize ($ bytes );
264250}
265251
266252/**
@@ -283,15 +269,20 @@ function strip_time($timestamp) {
283269 * @return string timestamp
284270 */
285271function relative_modified_date ($ timestamp , $ fromTime = null , $ dateOnly = false ): string {
286- $ formatter = \ OCP \ Server::get (IDateTimeFormatter::class);
272+ $ formatter = Server::get (IDateTimeFormatter::class);
287273
288274 if ($ dateOnly ) {
289275 return $ formatter ->formatDateSpan ($ timestamp , $ fromTime );
290276 }
291277 return $ formatter ->formatTimeSpan ($ timestamp , $ fromTime );
292278}
293279
294- function html_select_options ($ options , $ selected , $ params = []) {
280+ /**
281+ * @param array $options
282+ * @param string[]|string $selected
283+ * @param array $params
284+ */
285+ function html_select_options ($ options , $ selected , $ params = []): string {
295286 if (!is_array ($ selected )) {
296287 $ selected = [$ selected ];
297288 }
@@ -314,7 +305,7 @@ function html_select_options($options, $selected, $params = []) {
314305 $ label = $ label [$ label_name ];
315306 }
316307 $ select = in_array ($ value , $ selected ) ? ' selected="selected" ' : '' ;
317- $ html .= '<option value=" ' . \ OCP \ Util::sanitizeHTML ($ value ) . '" ' . $ select . '> ' . \ OCP \ Util::sanitizeHTML ($ label ) . '</option> ' . "\n" ;
308+ $ html .= '<option value=" ' . Util::sanitizeHTML ($ value ) . '" ' . $ select . '> ' . Util::sanitizeHTML ($ label ) . '</option> ' . "\n" ;
318309 }
319310 return $ html ;
320311}
0 commit comments