support print stylesheets
This commit is contained in:
parent
cc4e4ecf0f
commit
99b9ec41c1
|
@ -15,7 +15,10 @@
|
||||||
<link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path('', 'favicon-touch.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="#1d2d44">
|
<link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path('', 'favicon-mask.svg')); ?>" color="#1d2d44">
|
||||||
<?php foreach ($_['cssfiles'] as $cssfile): ?>
|
<?php foreach ($_['cssfiles'] as $cssfile): ?>
|
||||||
<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="screen">
|
<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 endforeach; ?>
|
||||||
<?php foreach ($_['jsfiles'] as $jsfile): ?>
|
<?php foreach ($_['jsfiles'] as $jsfile): ?>
|
||||||
<script src="<?php print_unescaped($jsfile); ?>"></script>
|
<script src="<?php print_unescaped($jsfile); ?>"></script>
|
||||||
|
|
|
@ -16,7 +16,10 @@
|
||||||
<link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path('', 'favicon-touch.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="#1d2d44">
|
<link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path('', 'favicon-mask.svg')); ?>" color="#1d2d44">
|
||||||
<?php foreach($_['cssfiles'] as $cssfile): ?>
|
<?php foreach($_['cssfiles'] as $cssfile): ?>
|
||||||
<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="screen">
|
<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 endforeach; ?>
|
||||||
<?php foreach($_['jsfiles'] as $jsfile): ?>
|
<?php foreach($_['jsfiles'] as $jsfile): ?>
|
||||||
<script src="<?php print_unescaped($jsfile); ?>"></script>
|
<script src="<?php print_unescaped($jsfile); ?>"></script>
|
||||||
|
|
|
@ -27,7 +27,10 @@
|
||||||
<link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path($_['appid'], 'favicon-touch.png')); ?>">
|
<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="#1d2d44">
|
<link rel="mask-icon" sizes="any" href="<?php print_unescaped(image_path($_['appid'], 'favicon-mask.svg')); ?>" color="#1d2d44">
|
||||||
<?php foreach($_['cssfiles'] as $cssfile): ?>
|
<?php foreach($_['cssfiles'] as $cssfile): ?>
|
||||||
<link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="screen">
|
<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 endforeach; ?>
|
||||||
<?php foreach($_['jsfiles'] as $jsfile): ?>
|
<?php foreach($_['jsfiles'] as $jsfile): ?>
|
||||||
<script src="<?php print_unescaped($jsfile); ?>"></script>
|
<script src="<?php print_unescaped($jsfile); ?>"></script>
|
||||||
|
|
|
@ -182,7 +182,11 @@ class TemplateLayout extends \OC_Template {
|
||||||
$web = $info[1];
|
$web = $info[1];
|
||||||
$file = $info[2];
|
$file = $info[2];
|
||||||
|
|
||||||
$this->append( 'cssfiles', $web.'/'.$file . '?v=' . self::$versionHash);
|
if (substr($file, -strlen('print.css')) === 'print.css') {
|
||||||
|
$this->append( 'printcssfiles', $web.'/'.$file . '?v=' . self::$versionHash);
|
||||||
|
} else {
|
||||||
|
$this->append( 'cssfiles', $web.'/'.$file . '?v=' . self::$versionHash);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,10 +253,35 @@ class TemplateLayout extends \OC_Template {
|
||||||
}
|
}
|
||||||
|
|
||||||
$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
|
$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
|
||||||
$cssHash = self::hashFileNames($cssFiles);
|
|
||||||
|
|
||||||
if (!file_exists("$assetDir/assets/$cssHash.css")) {
|
// differentiate between screen stylesheets and printer stylesheets
|
||||||
$cssFiles = array_map(function ($item) {
|
$screenCssFiles = array_filter($cssFiles, function($cssFile) {
|
||||||
|
return substr_compare($cssFile[2], 'print.css', -strlen('print.css')) !== 0;
|
||||||
|
});
|
||||||
|
$screenCssAsset = $this->generateCssAsset($screenCssFiles);
|
||||||
|
|
||||||
|
$printCssFiles = array_filter($cssFiles, function($cssFile) {
|
||||||
|
return substr_compare($cssFile[2], 'print.css', -strlen('print.css')) === 0;
|
||||||
|
});
|
||||||
|
$printCssAsset = $this->generateCssAsset($printCssFiles);
|
||||||
|
|
||||||
|
$this->append('jsfiles', \OC::$server->getURLGenerator()->linkTo('assets', "$jsHash.js"));
|
||||||
|
$this->append('cssfiles', $screenCssAsset);
|
||||||
|
$this->append('printcssfiles', $printCssAsset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generates a single css asset file from an array of css files if at least one of them has changed
|
||||||
|
* otherwise it just returns the path to the old asset file
|
||||||
|
* @param $files
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function generateCssAsset($files) {
|
||||||
|
$assetDir = \OC::$server->getConfig()->getSystemValue('assetdirectory', \OC::$SERVERROOT);
|
||||||
|
$hash = self::hashFileNames($files);
|
||||||
|
|
||||||
|
if (!file_exists("$assetDir/assets/$hash.css")) {
|
||||||
|
$files = array_map(function ($item) {
|
||||||
$root = $item[0];
|
$root = $item[0];
|
||||||
$file = $item[2];
|
$file = $item[2];
|
||||||
$assetPath = $root . '/' . $file;
|
$assetPath = $root . '/' . $file;
|
||||||
|
@ -268,16 +297,17 @@ class TemplateLayout extends \OC_Template {
|
||||||
$sourceRoot,
|
$sourceRoot,
|
||||||
$sourcePath
|
$sourcePath
|
||||||
);
|
);
|
||||||
}, $cssFiles);
|
}, $files);
|
||||||
$cssCollection = new AssetCollection($cssFiles);
|
|
||||||
$cssCollection->setTargetPath("assets/$cssHash.css");
|
$cssCollection = new AssetCollection($files);
|
||||||
|
$cssCollection->setTargetPath("assets/$hash.css");
|
||||||
|
|
||||||
$writer = new AssetWriter($assetDir);
|
$writer = new AssetWriter($assetDir);
|
||||||
$writer->writeAsset($cssCollection);
|
$writer->writeAsset($cssCollection);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->append('jsfiles', \OC::$server->getURLGenerator()->linkTo('assets', "$jsHash.js"));
|
return \OC::$server->getURLGenerator()->linkTo('assets', "$hash.css");
|
||||||
$this->append('cssfiles', \OC::$server->getURLGenerator()->linkTo('assets', "$cssHash.css"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue