summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Letzgus <www@chronos.michael-letzgus.de>2017-05-20 12:16:44 +0200
committerMichael Letzgus <www@chronos.michael-letzgus.de>2017-05-25 11:13:43 +0200
commit0d320fba4b2ff940975fc9fa415e2d20c6da961f (patch)
treec61698238afe6370672b07468ca0a9007232d1c4
parenta46d2f1d39c99b2e237b3b642099f02a3fb8c841 (diff)
downloadnextcloud-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>
-rw-r--r--core/templates/layout.base.php7
-rw-r--r--core/templates/layout.guest.php7
-rw-r--r--core/templates/layout.user.php7
-rw-r--r--lib/private/legacy/template/functions.php32
4 files changed, 34 insertions, 19 deletions
diff --git a/core/templates/layout.base.php b/core/templates/layout.base.php
index 7eb1cf5ffa4..7c1fe79e79d 100644
--- a/core/templates/layout.base.php
+++ b/core/templates/layout.base.php
@@ -12,12 +12,7 @@
<link rel="icon" href="<?php print_unescaped(image_path('', 'favicon.ico')); /* IE11+ supports png */ ?>">
<link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path('', 'favicon-touch.png')); ?>">
<link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path('', 'favicon-mask.svg')); ?>" color="<?php p($theme->getColorPrimary()); ?>">
- <?php foreach ($_['cssfiles'] as $cssfile): ?>
- <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>">
- <?php endforeach; ?>
- <?php foreach($_['printcssfiles'] as $cssfile): ?>
- <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print">
- <?php endforeach; ?>
+ <?php emit_css_loading_tags($_); ?>
<?php emit_script_loading_tags($_); ?>
<?php print_unescaped($_['headers']); ?>
</head>
diff --git a/core/templates/layout.guest.php b/core/templates/layout.guest.php
index dc56edb0061..d97da109842 100644
--- a/core/templates/layout.guest.php
+++ b/core/templates/layout.guest.php
@@ -13,12 +13,7 @@
<link rel="icon" href="<?php print_unescaped(image_path('', 'favicon.ico')); /* IE11+ supports png */ ?>">
<link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path('', 'favicon-touch.png')); ?>">
<link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path('', 'favicon-mask.svg')); ?>" color="<?php p($theme->getColorPrimary()); ?>">
- <?php foreach($_['cssfiles'] as $cssfile): ?>
- <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>">
- <?php endforeach; ?>
- <?php foreach($_['printcssfiles'] as $cssfile): ?>
- <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print">
- <?php endforeach; ?>
+ <?php emit_css_loading_tags($_); ?>
<?php emit_script_loading_tags($_); ?>
<?php print_unescaped($_['headers']); ?>
</head>
diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php
index aad9875f375..7d54d9b21f7 100644
--- a/core/templates/layout.user.php
+++ b/core/templates/layout.user.php
@@ -21,12 +21,7 @@
<link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path($_['appid'], 'favicon-touch.png')); ?>">
<link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path($_['appid'], 'favicon-mask.svg')); ?>" color="<?php p($theme->getColorPrimary()); ?>">
<link rel="manifest" href="<?php print_unescaped(image_path($_['appid'], 'manifest.json')); ?>">
- <?php foreach($_['cssfiles'] as $cssfile): ?>
- <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>">
- <?php endforeach; ?>
- <?php foreach($_['printcssfiles'] as $cssfile): ?>
- <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print">
- <?php endforeach; ?>
+ <?php emit_css_loading_tags($_); ?>
<?php emit_script_loading_tags($_); ?>
<?php print_unescaped($_['headers']); ?>
</head>
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)) {