summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-05-14 17:57:43 +0200
committerBart Visscher <bartv@thisnet.nl>2012-05-16 18:53:46 +0200
commitf71fec8cdcb5d7d24b7dfa30dfaf24c5115e51c1 (patch)
tree4b510fcd7da78d67fa995c6daa33c3d7cd13842e /lib
parent2faae817f183e82975251d5023417e2f331971d3 (diff)
downloadnextcloud-server-f71fec8cdcb5d7d24b7dfa30dfaf24c5115e51c1.tar.gz
nextcloud-server-f71fec8cdcb5d7d24b7dfa30dfaf24c5115e51c1.zip
Combine and minimize core and default app css files
Diffstat (limited to 'lib')
-rw-r--r--lib/app.php6
-rw-r--r--lib/base.php12
-rw-r--r--lib/helper.php4
-rw-r--r--lib/minimizer.php39
-rw-r--r--lib/minimizer/css.php73
-rw-r--r--lib/util.php1
6 files changed, 126 insertions, 9 deletions
diff --git a/lib/app.php b/lib/app.php
index f274194b25c..39e90ada019 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -73,6 +73,12 @@ class OC_App{
self::$init = true;
+ if (!defined('DEBUG') || !DEBUG){
+ if (is_null($types)) {
+ OC_Util::$core_styles = OC_Util::$styles;
+ OC_Util::$styles = array();
+ }
+ }
// return
return true;
}
diff --git a/lib/base.php b/lib/base.php
index f01e1f5be6c..673a47ba450 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -230,6 +230,8 @@ class OC{
OC_Config::setValue('version',implode('.',OC_Util::getVersion()));
}
+ OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php');
+
OC_App::updateApps();
}
}
@@ -278,13 +280,9 @@ class OC{
public static function loadfile(){
if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE)){
if(substr(OC::$REQUESTEDFILE, -3) == 'css'){
- $appswebroot = (string) OC::$APPSWEBROOT;
- $webroot = (string) OC::$WEBROOT;
- $cssfile = file_get_contents(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE);
- $cssfile = str_replace('%appswebroot%', $appswebroot, $cssfile);
- $cssfile = str_replace('%webroot%', $webroot, $cssfile);
- header('Content-Type: text/css');
- echo $cssfile;
+ $file = 'apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE;
+ $minimizer = new OC_Minimizer_CSS();
+ $minimizer->output(array(array(OC::$APPSROOT, OC::$APPSWEBROOT, $file)));
exit;
}elseif(substr(OC::$REQUESTEDFILE, -3) == 'php'){
require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE);
diff --git a/lib/helper.php b/lib/helper.php
index 31819d2e3fc..41ff119ff5f 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -112,8 +112,8 @@ class OC_Helper {
*
* Returns a absolute url to the given service.
*/
- public static function linkToRemote( $service ) {
- return self::linkToAbsolute( '', 'remote.php') . '/' . $service . '/';
+ public static function linkToRemote( $service, $add_slash = true ) {
+ return self::linkToAbsolute( '', 'remote.php') . '/' . $service . ($add_slash?'/':'');
}
/**
diff --git a/lib/minimizer.php b/lib/minimizer.php
new file mode 100644
index 00000000000..2d2708c59e9
--- /dev/null
+++ b/lib/minimizer.php
@@ -0,0 +1,39 @@
+<?php
+
+abstract class OC_Minimizer
+{
+ protected $files = array();
+
+ protected function appendIfExist($root, $webroot, $file) {
+ if (is_file($root.'/'.$file)) {
+ $this->files[] = array($root, $webroot, $file);
+ return true;
+ }
+ return false;
+ }
+
+ public function getLastModified($files) {
+ $last_modified = 0;
+ foreach($files as $file_info) {
+ $file = $file_info[0] . '/' . $file_info[2];
+ $filemtime = filemtime($file);
+ if ($filemtime > $last_modified) {
+ $last_modified = $filemtime;
+ }
+ }
+ return $last_modified;
+ }
+
+ abstract public function minimizeFiles($files);
+
+ public function output($files) {
+ header('Content-Type: '.$this->contentType);
+ OC_Response::enableCaching();
+ $last_modified = $this->getLastModified($files);
+ OC_Response::setLastModifiedHeader($last_modified);
+
+ $out = $this->minimizeFiles($files);
+ header('Content-Length: '.strlen($out));
+ echo $out;
+ }
+}
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;
+ }
+}
diff --git a/lib/util.php b/lib/util.php
index ff117998713..c7a5a9cfd68 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -10,6 +10,7 @@ class OC_Util {
public static $headers=array();
private static $rootMounted=false;
private static $fsSetup=false;
+ public static $core_styles=array();
// Can be set up
public static function setupFS( $user = "", $root = "files" ){// configure the initial filesystem based on the configuration