summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-05-14 23:15:53 +0200
committerBart Visscher <bartv@thisnet.nl>2012-05-16 18:53:46 +0200
commitce1e4425c2fc96f581428207edab040e42387bbc (patch)
treef47242e46ef11b20867f283fa1906c87893c4a55 /lib
parentf71fec8cdcb5d7d24b7dfa30dfaf24c5115e51c1 (diff)
downloadnextcloud-server-ce1e4425c2fc96f581428207edab040e42387bbc.tar.gz
nextcloud-server-ce1e4425c2fc96f581428207edab040e42387bbc.zip
Combine and minimize core and default app js files
Diffstat (limited to 'lib')
-rw-r--r--lib/app.php2
-rw-r--r--lib/base.php1
-rw-r--r--lib/minimizer/js.php62
-rw-r--r--lib/util.php1
4 files changed, 66 insertions, 0 deletions
diff --git a/lib/app.php b/lib/app.php
index 39e90ada019..8bd095d8c6c 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -75,6 +75,8 @@ class OC_App{
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();
}
diff --git a/lib/base.php b/lib/base.php
index 673a47ba450..1b3554a42a9 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -231,6 +231,7 @@ class OC{
}
OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php');
+ OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php');
OC_App::updateApps();
}
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/util.php b/lib/util.php
index c7a5a9cfd68..95b5f8df3db 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -11,6 +11,7 @@ class OC_Util {
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