From 2fd7df57d9255e9a8b2fa57c7e9fd435f2b44f98 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 18 Jun 2012 15:35:22 +0200 Subject: [PATCH 1/6] don't add the "Shared"-directory size to users quota --- settings/personal.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/settings/personal.php b/settings/personal.php index 64e08be89e..26a9f601d9 100644 --- a/settings/personal.php +++ b/settings/personal.php @@ -17,7 +17,8 @@ OC_App::setActiveNavigationEntry( 'personal' ); // calculate the disc space $rootInfo=OC_FileCache::get(''); -$used=$rootInfo['size']; +$sharedInfo=OC_FileCache::get('/Shared'); +$used=$rootInfo['size']-$sharedInfo['size']; $free=OC_Filesystem::free_space(); $total=$free+$used; if($total==0) $total=1; // prevent division by zero From 79f9d61ec84041c61a8d00042dfeb28afd8219a6 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 18 Jun 2012 12:44:06 +0200 Subject: [PATCH 2/6] Allow apps to load before login, needed for user_openid --- apps/user_openid/appinfo/info.xml | 1 + index.php | 1 + 2 files changed, 2 insertions(+) diff --git a/apps/user_openid/appinfo/info.xml b/apps/user_openid/appinfo/info.xml index 268af23973..7aae4271fa 100644 --- a/apps/user_openid/appinfo/info.xml +++ b/apps/user_openid/appinfo/info.xml @@ -8,6 +8,7 @@ 4 true + diff --git a/index.php b/index.php index 32b3c88df1..1171c0fe0c 100755 --- a/index.php +++ b/index.php @@ -69,6 +69,7 @@ elseif(OC_User::isLoggedIn()) { // For all others cases, we display the guest page : } else { + OC_App::loadApps(array('prelogin')); $error = false; // remember was checked after last login if(isset($_COOKIE["oc_remember_login"]) && isset($_COOKIE["oc_token"]) && isset($_COOKIE["oc_username"]) && $_COOKIE["oc_remember_login"]) { From 332603a2637ec46984f0622ee9a930a84a1c367d Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 18 Jun 2012 12:57:11 +0200 Subject: [PATCH 3/6] Move formfactor code to OC_Template --- lib/base.php | 34 ---------------------------------- lib/template.php | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/lib/base.php b/lib/base.php index 94ae26c4d1..db55504117 100644 --- a/lib/base.php +++ b/lib/base.php @@ -95,31 +95,6 @@ class OC{ } } - /** - * autodetects the formfactor of the used device - * default -> the normal desktop browser interface - * mobile -> interface for smartphones - * tablet -> interface for tablets - * standalone -> the default interface but without header, footer and sidebar. just the application. useful to ue just a specific app on the desktop in a standalone window. - */ - public static function detectFormfactor(){ - // please add more useragent strings for other devices - if(isset($_SERVER['HTTP_USER_AGENT'])){ - if(stripos($_SERVER['HTTP_USER_AGENT'],'ipad')>0) { - $mode='tablet'; - }elseif(stripos($_SERVER['HTTP_USER_AGENT'],'iphone')>0){ - $mode='mobile'; - }elseif((stripos($_SERVER['HTTP_USER_AGENT'],'N9')>0) and (stripos($_SERVER['HTTP_USER_AGENT'],'nokia')>0)){ - $mode='mobile'; - }else{ - $mode='default'; - } - }else{ - $mode='default'; - } - return($mode); - } - public static function initPaths(){ // calculate the root directories OC::$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13)); @@ -237,15 +212,6 @@ class OC{ } public static function initTemplateEngine() { - // if the formfactor is not yet autodetected do the autodetection now. For possible forfactors check the detectFormfactor documentation - if(!isset($_SESSION['formfactor'])){ - $_SESSION['formfactor']=OC::detectFormfactor(); - } - // allow manual override via GET parameter - if(isset($_GET['formfactor'])){ - $_SESSION['formfactor']=$_GET['formfactor']; - } - // Add the stuff we need always OC_Util::addScript( "jquery-1.7.2.min" ); OC_Util::addScript( "jquery-ui-1.8.16.custom.min" ); diff --git a/lib/template.php b/lib/template.php index a3700e133e..7e2e1d4d52 100644 --- a/lib/template.php +++ b/lib/template.php @@ -166,11 +166,48 @@ class OC_Template{ $this->findTemplate($name); } + /** + * autodetects the formfactor of the used device + * default -> the normal desktop browser interface + * mobile -> interface for smartphones + * tablet -> interface for tablets + * standalone -> the default interface but without header, footer and + * sidebar, just the application. Useful to use just a specific + * app on the desktop in a standalone window. + */ + public static function detectFormfactor(){ + // please add more useragent strings for other devices + if(isset($_SERVER['HTTP_USER_AGENT'])){ + if(stripos($_SERVER['HTTP_USER_AGENT'],'ipad')>0) { + $mode='tablet'; + }elseif(stripos($_SERVER['HTTP_USER_AGENT'],'iphone')>0){ + $mode='mobile'; + }elseif((stripos($_SERVER['HTTP_USER_AGENT'],'N9')>0) and (stripos($_SERVER['HTTP_USER_AGENT'],'nokia')>0)){ + $mode='mobile'; + }else{ + $mode='default'; + } + }else{ + $mode='default'; + } + return($mode); + } + /** * @brief Returns the formfactor extension for current formfactor */ static public function getFormFactorExtension() { + // if the formfactor is not yet autodetected do the + // autodetection now. For possible formfactors check the + // detectFormfactor documentation + if(!isset($_SESSION['formfactor'])){ + $_SESSION['formfactor'] = self::detectFormfactor(); + } + // allow manual override via GET parameter + if(isset($_GET['formfactor'])){ + $_SESSION['formfactor']=$_GET['formfactor']; + } $formfactor=$_SESSION['formfactor']; if($formfactor=='default') { $fext=''; From 180243d92a6e1261092c6262f02b20b2f3785ba7 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 18 Jun 2012 15:04:35 +0200 Subject: [PATCH 4/6] Move page layout handling to its own class --- lib/template.php | 130 +------------------------------ lib/templatelayout.php | 170 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+), 127 deletions(-) create mode 100644 lib/templatelayout.php diff --git a/lib/template.php b/lib/template.php index 7e2e1d4d52..a5d10c45d2 100644 --- a/lib/template.php +++ b/lib/template.php @@ -307,7 +307,7 @@ class OC_Template{ * * If the key existed before, it will be overwritten */ - public function assign( $key, $value, $sanitizeHTML=true ){ + public function assign( $key, $value, $sanitizeHTML=true ){ if($sanitizeHTML == true) { if(is_array($value)) { array_walk_recursive($value,'OC_Template::sanitizeHTML'); @@ -376,29 +376,6 @@ class OC_Template{ } } - /* - * @brief append the $file-url if exist at $root - * @param $type of collection to use when appending - * @param $root path to check - * @param $web base for path - * @param $file the filename - */ - public function appendIfExist($type, $root, $web, $file) { - if (is_file($root.'/'.$file)) { - $pathes = explode('/', $file); - if($type == 'cssfiles' && $root == OC::$APPSROOT && $pathes[0] == 'apps'){ - $app = $pathes[1]; - unset($pathes[0]); - unset($pathes[1]); - $path = implode('/', $pathes); - $this->append( $type, OC_Helper::linkTo($app, $path)); - }else{ - $this->append( $type, $web.'/'.$file); - } - return true; - } - return false; - } /** * @brief Proceeds the template * @returns content @@ -410,109 +387,9 @@ class OC_Template{ $data = $this->_fetch(); if( $this->renderas ){ - // Decide which page we show - if( $this->renderas == "user" ){ - $page = new OC_Template( "core", "layout.user" ); - $page->assign('searchurl',OC_Helper::linkTo( 'search', 'index.php' ), false); + $page = new OC_TemplateLayout($this->renderas); + if($this->renderas == 'user') { $page->assign('requesttoken', $this->vars['requesttoken']); - if(array_search(OC_APP::getCurrentApp(),array('settings','admin','help'))!==false){ - $page->assign('bodyid','body-settings', false); - }else{ - $page->assign('bodyid','body-user', false); - } - - // Add navigation entry - $navigation = OC_App::getNavigation(); - $page->assign( "navigation", $navigation, false); - $page->assign( "settingsnavigation", OC_App::getSettingsNavigation(), false); - foreach($navigation as $entry) { - if ($entry['active']) { - $page->assign( 'application', $entry['name'], false ); - break; - } - } - }else{ - $page = new OC_Template( "core", "layout.guest" ); - } - - // Read the selected theme from the config file - $theme=OC_Config::getValue( "theme" ); - - // Read the detected formfactor and use the right file name. - $fext = self::getFormFactorExtension(); - - $page->assign('jsfiles', array(), false); - // 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? - if($page->appendIfExist('jsfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) { - - // Is it in apps and overwritten by the theme? - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) { - - // Is it part of an app? - }elseif($page->appendIfExist('jsfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) { - - // Is it in the owncloud root but overwritten by the theme? - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) { - - // Is it in the owncloud root ? - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) { - - // Is in core but overwritten by a theme? - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) { - - // Is it in core? - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) { - - }else{ - echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); - die(); - - } - } - // 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')) { - - // or in apps? - }elseif($page->appendIfExist('cssfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) { - - // or in the owncloud root? - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) { - - // or in core ? - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', 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(OC_Util::$styles as $style){ - if($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) { - - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) { - - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) { - } - } } // Add custom headers @@ -521,7 +398,6 @@ class OC_Template{ $page->append('headers',$header); } - // Add css files and js files $page->assign( "content", $data, false ); return $page->fetchPage(); } diff --git a/lib/templatelayout.php b/lib/templatelayout.php new file mode 100644 index 0000000000..e387309ad7 --- /dev/null +++ b/lib/templatelayout.php @@ -0,0 +1,170 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class OC_TemplateLayout extends OC_Template { + public function __construct( $renderas ){ + // Decide which page we show + if( $renderas == 'user' ){ + parent::__construct( 'core', 'layout.user' ); + $this->assign('searchurl',OC_Helper::linkTo( 'search', 'index.php' ), false); + if(array_search(OC_APP::getCurrentApp(),array('settings','admin','help'))!==false){ + $this->assign('bodyid','body-settings', false); + }else{ + $this->assign('bodyid','body-user', false); + } + + // Add navigation entry + $navigation = OC_App::getNavigation(); + $this->assign( 'navigation', $navigation, false); + $this->assign( 'settingsnavigation', OC_App::getSettingsNavigation(), false); + foreach($navigation as $entry) { + if ($entry['active']) { + $this->assign( 'application', $entry['name'], false ); + break; + } + } + }else{ + parent::__construct( 'core', 'layout.guest' ); + } + + // Add the core js files or the js files provided by the selected theme + $jsfiles = $this->findScripts(OC_Util::$scripts); + $this->assign('jsfiles', array(), false); + foreach($jsfiles as $info) { + $root = $info[0]; + $web = $info[1]; + $file = $info[2]; + $this->append( 'jsfiles', $web.'/'.$file); + } + + // Add the css files + $cssfiles = $this->findStyles(OC_Util::$styles); + $this->assign('cssfiles', array()); + foreach($cssfiles as $info) { + $root = $info[0]; + $web = $info[1]; + $file = $info[2]; + $paths = explode('/', $file); + if($root == OC::$APPSROOT && $paths[0] == 'apps'){ + $app = $paths[1]; + unset($paths[0]); + unset($paths[1]); + $path = implode('/', $paths); + $this->append( 'cssfiles', OC_Helper::linkTo($app, $path)); + }else{ + $this->append( 'cssfiles', $web.'/'.$file); + } + } + } + + /* + * @brief append the $file-url if exist at $root + * @param $files array to append file info to + * @param $root path to check + * @param $web base for path + * @param $file the filename + */ + public function appendIfExist(&$files, $root, $webroot, $file) { + if (is_file($root.'/'.$file)) { + $files[] = array($root, $webroot, $file); + return true; + } + return false; + } + + public function findStyles($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 = self::getFormFactorExtension(); + + $files = array(); + foreach($styles as $style){ + // is it in 3rdparty? + if($this->appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) { + + // or in apps? + }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) { + }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) { + + // or in the owncloud root? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) { + + // or in core ? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) { + }elseif($this->appendIfExist($files, 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($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) { + + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) { + + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) { + } + } + } + return $files; + } + + public function findScripts($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 = self::getFormFactorExtension(); + + $files = array(); + foreach($scripts as $script){ + // Is it in 3rd party? + if($this->appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) { + + // Is it in apps and overwritten by the theme? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) { + + // Is it part of an app? + }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) { + }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) { + + // Is it in the owncloud root but overwritten by the theme? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) { + + // Is it in the owncloud root ? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) { + + // Is in core but overwritten by a theme? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) { + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) { + + // Is it in core? + }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) { + }elseif($this->appendIfExist($files, 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 $files; + } +} From 3000e8f9d508088abe7bb9c2cbc8f3490fa36c9a Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 18 Jun 2012 15:35:04 +0200 Subject: [PATCH 5/6] Prepare template js and css functions for use in the js and css minimizers --- lib/templatelayout.php | 64 +++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/templatelayout.php b/lib/templatelayout.php index e387309ad7..1f82e82be7 100644 --- a/lib/templatelayout.php +++ b/lib/templatelayout.php @@ -32,8 +32,8 @@ class OC_TemplateLayout extends OC_Template { parent::__construct( 'core', 'layout.guest' ); } - // Add the core js files or the js files provided by the selected theme - $jsfiles = $this->findScripts(OC_Util::$scripts); + // Add the js files + $jsfiles = self::findJavascriptFiles(OC_Util::$scripts); $this->assign('jsfiles', array(), false); foreach($jsfiles as $info) { $root = $info[0]; @@ -43,7 +43,7 @@ class OC_TemplateLayout extends OC_Template { } // Add the css files - $cssfiles = $this->findStyles(OC_Util::$styles); + $cssfiles = self::findStylesheetFiles(OC_Util::$styles); $this->assign('cssfiles', array()); foreach($cssfiles as $info) { $root = $info[0]; @@ -69,7 +69,7 @@ class OC_TemplateLayout extends OC_Template { * @param $web base for path * @param $file the filename */ - public function appendIfExist(&$files, $root, $webroot, $file) { + static public function appendIfExist(&$files, $root, $webroot, $file) { if (is_file($root.'/'.$file)) { $files[] = array($root, $webroot, $file); return true; @@ -77,7 +77,7 @@ class OC_TemplateLayout extends OC_Template { return false; } - public function findStyles($styles){ + static public function findStylesheetFiles($styles){ // Read the selected theme from the config file $theme=OC_Config::getValue( 'theme' ); @@ -87,19 +87,19 @@ class OC_TemplateLayout extends OC_Template { $files = array(); foreach($styles as $style){ // is it in 3rdparty? - if($this->appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) { + if(self::appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) { // or in apps? - }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) { - }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) { + }elseif(self::appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) { + }elseif(self::appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) { // or in the owncloud root? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) { // or in core ? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) { }else{ echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); @@ -109,21 +109,21 @@ class OC_TemplateLayout extends OC_Template { // Add the theme css files. you can override the default values here if(!empty($theme)) { foreach($styles as $style){ - if($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) { + if(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) { } } } return $files; } - public function findScripts($scripts){ + static public function findJavascriptFiles($scripts){ // Read the selected theme from the config file $theme=OC_Config::getValue( 'theme' ); @@ -133,31 +133,31 @@ class OC_TemplateLayout extends OC_Template { $files = array(); foreach($scripts as $script){ // Is it in 3rd party? - if($this->appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) { + if(self::appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) { // Is it in apps and overwritten by the theme? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) { // Is it part of an app? - }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) { - }elseif($this->appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) { + }elseif(self::appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) { + }elseif(self::appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) { // Is it in the owncloud root but overwritten by the theme? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) { // Is it in the owncloud root ? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) { // Is in core but overwritten by a theme? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) { // Is it in core? - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) { - }elseif($this->appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) { + }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) { }else{ echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); From 2f00384b5124ec0b3f3703d73a11a129aff93a62 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 18 Jun 2012 15:40:43 +0200 Subject: [PATCH 6/6] Use TemplateLayout functions for finding js and css files in minimizer --- core/minimizer.php | 4 ++-- lib/minimizer.php | 13 +------------ lib/minimizer/css.php | 44 ------------------------------------------- lib/minimizer/js.php | 43 ------------------------------------------ 4 files changed, 3 insertions(+), 101 deletions(-) diff --git a/core/minimizer.php b/core/minimizer.php index 47e3d855e7..0abbca7502 100644 --- a/core/minimizer.php +++ b/core/minimizer.php @@ -5,11 +5,11 @@ OC_App::loadApps(); if ($service == 'core.css'){ $minimizer = new OC_Minimizer_CSS(); - $files = $minimizer->findFiles(OC_Util::$core_styles); + $files = OC_TemplateLayout::findStylesheetFiles(OC_Util::$core_styles); $minimizer->output($files, $service); } else if ($service == 'core.js'){ $minimizer = new OC_Minimizer_JS(); - $files = $minimizer->findFiles(OC_Util::$core_scripts); + $files = OC_TemplateLayout::findJavascriptFiles(OC_Util::$core_scripts); $minimizer->output($files, $service); } diff --git a/lib/minimizer.php b/lib/minimizer.php index 428fa477f7..e17c114f06 100644 --- a/lib/minimizer.php +++ b/lib/minimizer.php @@ -1,17 +1,6 @@ files[] = array($root, $webroot, $file); - return true; - } - return false; - } - +abstract class OC_Minimizer { public function getLastModified($files) { $last_modified = 0; foreach($files as $file_info) { diff --git a/lib/minimizer/css.php b/lib/minimizer/css.php index 09a0efdc3a..da502bfa9e 100644 --- a/lib/minimizer/css.php +++ b/lib/minimizer/css.php @@ -6,50 +6,6 @@ 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; diff --git a/lib/minimizer/js.php b/lib/minimizer/js.php index b9a023e068..0f5cb7e557 100644 --- a/lib/minimizer/js.php +++ b/lib/minimizer/js.php @@ -6,49 +6,6 @@ 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) {