aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHendrik Leppelsack <hendrik@leppelsack.de>2015-06-10 12:16:45 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-13 15:12:11 +0100
commit99b9ec41c1af6489f7da4b37f249a8ccbcf7b99d (patch)
treed570120eeb6690962c63b57b14cf691d7f323c8a /lib
parentcc4e4ecf0f2f1e2644ff66da537515ddaddc716c (diff)
downloadnextcloud-server-99b9ec41c1af6489f7da4b37f249a8ccbcf7b99d.tar.gz
nextcloud-server-99b9ec41c1af6489f7da4b37f249a8ccbcf7b99d.zip
support print stylesheets
Diffstat (limited to 'lib')
-rw-r--r--lib/private/templatelayout.php48
1 files changed, 39 insertions, 9 deletions
diff --git a/lib/private/templatelayout.php b/lib/private/templatelayout.php
index e14b070a7b4..f986aee4695 100644
--- a/lib/private/templatelayout.php
+++ b/lib/private/templatelayout.php
@@ -182,7 +182,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);
+ }
}
}
}
@@ -249,10 +253,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;
@@ -268,16 +297,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");
}
/**