diff options
author | Michael Letzgus <www@chronos.michael-letzgus.de> | 2017-05-20 12:16:44 +0200 |
---|---|---|
committer | Michael Letzgus <www@chronos.michael-letzgus.de> | 2017-05-25 11:13:43 +0200 |
commit | 0d320fba4b2ff940975fc9fa415e2d20c6da961f (patch) | |
tree | c61698238afe6370672b07468ca0a9007232d1c4 /lib/private/legacy/template/functions.php | |
parent | a46d2f1d39c99b2e237b3b642099f02a3fb8c841 (diff) | |
download | nextcloud-server-0d320fba4b2ff940975fc9fa415e2d20c6da961f.tar.gz nextcloud-server-0d320fba4b2ff940975fc9fa415e2d20c6da961f.zip |
Streamline templates, more DRY
Use Unified function to emit <link> tags for css loading, obey "Don't Repeat Yourself" ;-)
(Next step might by to combine this with the emit <script> function (even more DRY?) AND move all this to a better place?)
Signed-off-by: Michael Letzgus <michaelletzgus@users.noreply.github.com>
Diffstat (limited to 'lib/private/legacy/template/functions.php')
-rw-r--r-- | lib/private/legacy/template/functions.php | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/private/legacy/template/functions.php b/lib/private/legacy/template/functions.php index 06eb512b54f..208d9fb3f9f 100644 --- a/lib/private/legacy/template/functions.php +++ b/lib/private/legacy/template/functions.php @@ -38,13 +38,43 @@ function p($string) { print(\OCP\Util::sanitizeHTML($string)); } + +/** + * Prints a <link> tag for loading css + * @param string $href the source URL, ignored when empty + * @param string $opts, additional optional options +*/ +function emit_css_tag($href, $opts = '') { + $s='<link rel="stylesheet"'; + if (!empty($href)) { + $s.=' href="' . $href .'"'; + } + if (!empty($opts)) { + $s.=' '.$opts; + } + print_unescaped($s.">\n"); +} + +/** + * Prints all tags for CSS loading + * @param hash $obj all the script information from template +*/ +function emit_css_loading_tags($obj) { + foreach($obj['cssfiles'] as $css) { + emit_css_tag($css); + } + foreach($obj['printcssfiles'] as $css) { + emit_css_tag($css, 'media="print"'); + } +} + /** * Prints a <script> tag with nonce and defer depending on config * @param string $src the source URL, ignored when empty * @param string $script_content the inline script content, ignored when empty * @param bool $defer_flag deferred loading or not */ -function emit_script_tag($src, $script_content) { +function emit_script_tag($src, $script_content='') { $defer_str=' defer'; $s='<script nonce="' . \OC::$server->getContentSecurityPolicyNonceManager()->getNonce() . '"'; if (!empty($src)) { |