Passed
Push — master ( 26d767...2e2600 )
by Pauli
01:48
created

HtmlUtil::printSvgPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
3
/**
4
 * ownCloud - Music app
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Pauli Järvinen <[email protected]>
10
 * @copyright Pauli Järvinen 2020
11
 */
12
13
namespace OCA\Music\Utility;
14
15
/**
16
 * Utility functions to be used from the front-end templates
17
 */
18
class HtmlUtil {
19
20
	/**
21
	 * Sanitized printing
22
	 * @param string $string
23
	 */
24
	public static function p($string) {
25
		print(/** @scrutinizer ignore-type */ \OCP\Util::sanitizeHTML($string));
26
	}
27
28
	/**
29
	 * Print path to a icon of the Music app
30
	 * @param string $iconName Name of the icon without path or the '.svg' suffix
31
	 */
32
	public static function printSvgPath($iconName) {
33
		print(\OCP\Template::image_path('music', $iconName.'.svg'));
34
	}
35
36
	/**
37
	 * Print AngularJS template whose contents can be found under templates/partials
38
	 * @param string $templateName
39
	 */
40
	public static function printNgTemplate($templateName) {
41
		print(
42
			'<script type="text/ng-template" id="'.$templateName.'.html">' .
43
				self::partialContent($templateName) .
44
			'</script>'
45
		);
46
	}
47
48
	/**
49
	 * Print a partial template
50
	 * @param string $partialName Name of the file under templates/partials without the '.php' suffix
51
	 */
52
	public static function printPartial($partialName) {
53
		print(self::partialContent($partialName));
54
	}
55
56
	/**
57
	 * @param string $partialName
58
	 */
59
	private static function partialContent($partialName) {
60
		$fileName = \join(DIRECTORY_SEPARATOR, [\dirname(__DIR__), 'templates', 'partials', $partialName.'.php']);
61
62
		\ob_start();
63
		try {
64
			include $fileName;
65
			$data = \ob_get_contents();
66
		} catch (\Exception $e) {
67
			\ob_end_clean();
68
			throw $e;
69
		}
70
		\ob_end_clean();
71
72
		return $data;
73
	}
74
}
75