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>
This commit is contained in:
parent
a46d2f1d39
commit
0d320fba4b
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in New Issue