diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-05-14 17:57:43 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-05-16 18:53:46 +0200 |
commit | f71fec8cdcb5d7d24b7dfa30dfaf24c5115e51c1 (patch) | |
tree | 4b510fcd7da78d67fa995c6daa33c3d7cd13842e /lib/minimizer | |
parent | 2faae817f183e82975251d5023417e2f331971d3 (diff) | |
download | nextcloud-server-f71fec8cdcb5d7d24b7dfa30dfaf24c5115e51c1.tar.gz nextcloud-server-f71fec8cdcb5d7d24b7dfa30dfaf24c5115e51c1.zip |
Combine and minimize core and default app css files
Diffstat (limited to 'lib/minimizer')
-rw-r--r-- | lib/minimizer/css.php | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/minimizer/css.php b/lib/minimizer/css.php new file mode 100644 index 00000000000..3d1196390e2 --- /dev/null +++ b/lib/minimizer/css.php @@ -0,0 +1,73 @@ +<?php + +require_once('mediawiki/CSSMin.php'); + +class OC_Minimizer_CSS extends OC_Minimizer +{ + protected $contentType = 'text/css'; + + public function findFiles($styles) { + // Read the selected theme from the config file + $theme=OC_Config::getValue( "theme" ); + + // Read the detected formfactor and use the right file name. + $fext = OC_Template::getFormFactorExtension(); + foreach($styles as $style){ + // is it in 3rdparty? + if($this->appendIfExist(OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) { + + // or in apps? + }elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) { + }elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) { + + // or in the owncloud root? + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) { + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) { + + // or in core ? + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) { + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) { + + }else{ + echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); + die(); + } + } + // Add the theme css files. you can override the default values here + if(!empty($theme)) { + foreach($styles as $style){ + if($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) { + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) { + + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) { + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) { + + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) { + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) { + } + } + } + return $this->files; + } + + public function minimizeFiles($files) { + $css_out = ''; + $appswebroot = (string) OC::$APPSWEBROOT; + $webroot = (string) OC::$WEBROOT; + foreach($files as $file_info) { + $file = $file_info[0] . '/' . $file_info[2]; + $css_out .= '/* ' . $file . ' */' . "\n"; + $css = file_get_contents($file); + if (strpos($file, OC::$APPSROOT) == 0) { + $css = str_replace('%appswebroot%', $appswebroot, $css); + $css = str_replace('%webroot%', $webroot, $css); + } + $remote = $file_info[1]; + $remote .= '../'; + $remote .= dirname($file_info[2]); + $css_out .= CSSMin::remap($css, dirname($file), $remote, true); + } + $css_out = CSSMin::minify($css_out); + return $css_out; + } +} |