summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorC. Montero Luque <cmonteroluque@users.noreply.github.com>2016-03-31 22:13:44 +0200
committerC. Montero Luque <cmonteroluque@users.noreply.github.com>2016-03-31 22:13:44 +0200
commit0393e80c7c8203c5524e3250f99f598e42720ca0 (patch)
tree7cd2e6f44be987e769662fe0b1210434873dedd7
parent6d40e69e2916792b8a0aa6ee5747dc919f758e89 (diff)
parent99b9ec41c1af6489f7da4b37f249a8ccbcf7b99d (diff)
downloadnextcloud-server-0393e80c7c8203c5524e3250f99f598e42720ca0.tar.gz
nextcloud-server-0393e80c7c8203c5524e3250f99f598e42720ca0.zip
Merge pull request #16857 from owncloud/printStylesheets
Support for print stylesheets
-rw-r--r--core/templates/layout.base.php5
-rw-r--r--core/templates/layout.guest.php5
-rw-r--r--core/templates/layout.user.php5
-rw-r--r--lib/private/templatelayout.php48
4 files changed, 51 insertions, 12 deletions
diff --git a/core/templates/layout.base.php b/core/templates/layout.base.php
index 3a974b00c2c..29c2ca6696d 100644
--- a/core/templates/layout.base.php
+++ b/core/templates/layout.base.php
@@ -15,7 +15,10 @@
<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">
<?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 foreach ($_['jsfiles'] as $jsfile): ?>
<script src="<?php print_unescaped($jsfile); ?>"></script>
diff --git a/core/templates/layout.guest.php b/core/templates/layout.guest.php
index 7ee282faf0f..3f9c47f9aa6 100644
--- a/core/templates/layout.guest.php
+++ b/core/templates/layout.guest.php
@@ -16,7 +16,10 @@
<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">
<?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 foreach($_['jsfiles'] as $jsfile): ?>
<script src="<?php print_unescaped($jsfile); ?>"></script>
diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php
index dd4864ea73f..601af6077f4 100644
--- a/core/templates/layout.user.php
+++ b/core/templates/layout.user.php
@@ -23,7 +23,10 @@
<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">
<?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 foreach($_['jsfiles'] as $jsfile): ?>
<script src="<?php print_unescaped($jsfile); ?>"></script>
diff --git a/lib/private/templatelayout.php b/lib/private/templatelayout.php
index 5afbd4495c4..a1b75a34213 100644
--- a/lib/private/templatelayout.php
+++ b/lib/private/templatelayout.php
@@ -160,7 +160,11 @@ class TemplateLayout extends \OC_Template {
$web = $info[1];
$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);
+ }
}
}
}
@@ -227,10 +231,35 @@ class TemplateLayout extends \OC_Template {
}
$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
- $cssHash = self::hashFileNames($cssFiles);
- if (!file_exists("$assetDir/assets/$cssHash.css")) {
- $cssFiles = array_map(function ($item) {
+ // differentiate between screen stylesheets and printer stylesheets
+ $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];
$file = $item[2];
$assetPath = $root . '/' . $file;
@@ -246,16 +275,17 @@ class TemplateLayout extends \OC_Template {
$sourceRoot,
$sourcePath
);
- }, $cssFiles);
- $cssCollection = new AssetCollection($cssFiles);
- $cssCollection->setTargetPath("assets/$cssHash.css");
+ }, $files);
+
+ $cssCollection = new AssetCollection($files);
+ $cssCollection->setTargetPath("assets/$hash.css");
$writer = new AssetWriter($assetDir);
$writer->writeAsset($cssCollection);
+
}
- $this->append('jsfiles', \OC::$server->getURLGenerator()->linkTo('assets', "$jsHash.js"));
- $this->append('cssfiles', \OC::$server->getURLGenerator()->linkTo('assets', "$cssHash.css"));
+ return \OC::$server->getURLGenerator()->linkTo('assets', "$hash.css");
}
/**