summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSam Tuke <samtuke@owncloud.com>2012-05-16 18:30:35 +0100
committerSam Tuke <samtuke@owncloud.com>2012-05-16 18:30:35 +0100
commit22dd155e4da9e9bce2f9fa22a213b909d850fe9d (patch)
tree489cd50b8ba54fee2a0b94210f34125b5bef415d /lib
parent9acd1065b0b96f5e82444e98273cc613872a8e28 (diff)
parentc645a7d0f86baf2baf9777c9350c8cfd8a907084 (diff)
downloadnextcloud-server-22dd155e4da9e9bce2f9fa22a213b909d850fe9d.tar.gz
nextcloud-server-22dd155e4da9e9bce2f9fa22a213b909d850fe9d.zip
Merge branch 'unstable' of gitorious.org:owncloud/owncloud into unstable
Diffstat (limited to 'lib')
-rw-r--r--lib/app.php8
-rw-r--r--lib/base.php13
-rw-r--r--lib/helper.php4
-rw-r--r--lib/minimizer.php39
-rw-r--r--lib/minimizer/css.php73
-rw-r--r--lib/minimizer/js.php62
-rw-r--r--lib/template.php10
-rw-r--r--lib/util.php2
8 files changed, 198 insertions, 13 deletions
diff --git a/lib/app.php b/lib/app.php
index f274194b25c..8bd095d8c6c 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -73,6 +73,14 @@ class OC_App{
self::$init = true;
+ if (!defined('DEBUG') || !DEBUG){
+ if (is_null($types)) {
+ OC_Util::$core_scripts = OC_Util::$scripts;
+ OC_Util::$scripts = array();
+ 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..1b3554a42a9 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -230,6 +230,9 @@ class OC{
OC_Config::setValue('version',implode('.',OC_Util::getVersion()));
}
+ OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php');
+ OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php');
+
OC_App::updateApps();
}
}
@@ -278,13 +281,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/minimizer/js.php b/lib/minimizer/js.php
new file mode 100644
index 00000000000..4ddaa79d81a
--- /dev/null
+++ b/lib/minimizer/js.php
@@ -0,0 +1,62 @@
+<?php
+
+require_once('mediawiki/JavaScriptMinifier.php');
+
+class OC_Minimizer_JS extends OC_Minimizer
+{
+ protected $contentType = 'application/javascript';
+
+ public function findFiles($scripts) {
+ // 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();
+ // Add the core js files or the js files provided by the selected theme
+ foreach($scripts as $script){
+ // Is it in 3rd party?
+ if($this->appendIfExist(OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) {
+
+ // Is it in apps and overwritten by the theme?
+ }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) {
+ }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) {
+
+ // Is it part of an app?
+ }elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) {
+ }elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) {
+
+ // Is it in the owncloud root but overwritten by the theme?
+ }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) {
+ }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) {
+
+ // Is it in the owncloud root ?
+ }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) {
+ }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) {
+
+ // Is in core but overwritten by a theme?
+ }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) {
+ }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) {
+
+ // Is it in core?
+ }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) {
+ }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) {
+
+ }else{
+ echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
+ die();
+ }
+ }
+ return $this->files;
+ }
+
+ public function minimizeFiles($files) {
+ $js_out = '';
+ foreach($files as $file_info) {
+ $file = $file_info[0] . '/' . $file_info[2];
+ $js_out .= '/* ' . $file . ' */' . "\n";
+ $js_out .= file_get_contents($file);
+ }
+ $js_out = JavaScriptMinifier::minify($js_out);
+ return $js_out;
+ }
+}
diff --git a/lib/template.php b/lib/template.php
index 57e9c15f5e6..b5805f0096c 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -163,7 +163,7 @@ class OC_Template{
/**
* @brief Returns the formfactor extension for current formfactor
*/
- protected function getFormFactorExtension()
+ static public function getFormFactorExtension()
{
$formfactor=$_SESSION['formfactor'];
if($formfactor=='default') {
@@ -193,7 +193,7 @@ class OC_Template{
$theme=OC_Config::getValue( "theme" );
// Read the detected formfactor and use the right file name.
- $fext = $this->getFormFactorExtension();
+ $fext = self::getFormFactorExtension();
$app = $this->application;
// Check if it is a app template or not.
@@ -376,8 +376,9 @@ class OC_Template{
$theme=OC_Config::getValue( "theme" );
// Read the detected formfactor and use the right file name.
- $fext = $this->getFormFactorExtension();
+ $fext = self::getFormFactorExtension();
+ $page->assign('jsfiles', array());
// Add the core js files or the js files provided by the selected theme
foreach(OC_Util::$scripts as $script){
// Is it in 3rd party?
@@ -414,6 +415,7 @@ class OC_Template{
}
}
// Add the css files
+ $page->assign('cssfiles', array());
foreach(OC_Util::$styles as $style){
// is it in 3rdparty?
if($page->appendIfExist('cssfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) {
@@ -431,7 +433,7 @@ class OC_Template{
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) {
}else{
- echo('css file not found: style:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
+ echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
die();
}
}
diff --git a/lib/util.php b/lib/util.php
index ff117998713..95b5f8df3db 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -10,6 +10,8 @@ class OC_Util {
public static $headers=array();
private static $rootMounted=false;
private static $fsSetup=false;
+ public static $core_styles=array();
+ public static $core_scripts=array();
// Can be set up
public static function setupFS( $user = "", $root = "files" ){// configure the initial filesystem based on the configuration