diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-10-06 12:38:59 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-10-17 12:22:26 +0200 |
commit | 93b0f1a3bff98f3b9aa9f2e0ca2db4bc23ca3746 (patch) | |
tree | 69c18c9a69eec1f74fdf4755886ecb7b95e88cdb /lib/private/templatelayout.php | |
parent | 688a141586dad961b24b364e79cd11c1aa343730 (diff) | |
download | nextcloud-server-93b0f1a3bff98f3b9aa9f2e0ca2db4bc23ca3746.tar.gz nextcloud-server-93b0f1a3bff98f3b9aa9f2e0ca2db4bc23ca3746.zip |
adding cssmin and jssmin(minify)
adding argument deleteSelf to rmdirr() - if false the directory itself will not be deleted only it's content
adding repair step to clean the asset cache after upgrade + coding style adjustments
Diffstat (limited to 'lib/private/templatelayout.php')
-rw-r--r-- | lib/private/templatelayout.php | 119 |
1 files changed, 55 insertions, 64 deletions
diff --git a/lib/private/templatelayout.php b/lib/private/templatelayout.php index 9f996e19f81..10abff6267a 100644 --- a/lib/private/templatelayout.php +++ b/lib/private/templatelayout.php @@ -2,8 +2,10 @@ use Assetic\Asset\AssetCollection; use Assetic\Asset\FileAsset; use Assetic\AssetWriter; -use Assetic\Filter\CssRewriteFilter; use Assetic\Filter\CssImportFilter; +use Assetic\Filter\CssMinFilter; +use Assetic\Filter\CssRewriteFilter; +use Assetic\Filter\JSMinFilter; /** * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl> @@ -17,13 +19,22 @@ class OC_TemplateLayout extends OC_Template { private static $versionHash = ''; /** - * @param string $renderas - * @param string $appid application id + * @var \OCP\IConfig + */ + private $config; + + /** + * @param string $renderAs + * @param string $appId application id */ - public function __construct( $renderas, $appid = '' ) { + public function __construct( $renderAs, $appId = '' ) { + + // yes - should be injected .... + $this->config = \OC::$server->getConfig(); + // Decide which page we show - if( $renderas == 'user' ) { + if( $renderAs == 'user' ) { parent::__construct( 'core', 'layout.user' ); if(in_array(OC_APP::getCurrentApp(), array('settings','admin', 'help'))!==false) { $this->assign('bodyid', 'body-settings'); @@ -32,9 +43,12 @@ class OC_TemplateLayout extends OC_Template { } // Update notification - if(OC_Config::getValue('updatechecker', true) === true) { - $data=OC_Updater::check(); - if(isset($data['version']) && $data['version'] != '' and $data['version'] !== Array() && OC_User::isAdminUser(OC_User::getUser())) { + if($this->config->getSystemValue('updatechecker', true) === true && + OC_User::isAdminUser(OC_User::getUser())) { + $updater = new \OC\Updater(); + $data = $updater->check('http://apps.owncloud.com/updater.php'); + + if(isset($data['version']) && $data['version'] != '' and $data['version'] !== Array()) { $this->assign('updateAvailable', true); $this->assign('updateVersion', $data['versionstring']); $this->assign('updateLink', $data['web']); @@ -47,7 +61,7 @@ class OC_TemplateLayout extends OC_Template { // Add navigation entry $this->assign( 'application', '', false ); - $this->assign( 'appid', $appid ); + $this->assign( 'appid', $appId ); $navigation = OC_App::getNavigation(); $this->assign( 'navigation', $navigation); $this->assign( 'settingsnavigation', OC_App::getSettingsNavigation()); @@ -57,15 +71,15 @@ class OC_TemplateLayout extends OC_Template { break; } } - $user_displayname = OC_User::getDisplayName(); - $this->assign( 'user_displayname', $user_displayname ); + $userDisplayName = OC_User::getDisplayName(); + $this->assign( 'user_displayname', $userDisplayName ); $this->assign( 'user_uid', OC_User::getUser() ); $this->assign( 'appsmanagement_active', strpos(OC_Request::requestUri(), OC_Helper::linkToRoute('settings_apps')) === 0 ); - $this->assign('enableAvatars', \OC_Config::getValue('enable_avatars', true)); - } else if ($renderas == 'error') { + $this->assign('enableAvatars', $this->config->getSystemValue('enable_avatars', true)); + } else if ($renderAs == 'error') { parent::__construct('core', 'layout.guest', '', false); $this->assign('bodyid', 'body-login'); - } else if ($renderas == 'guest') { + } else if ($renderAs == 'guest') { parent::__construct('core', 'layout.guest'); $this->assign('bodyid', 'body-login'); } else { @@ -76,27 +90,27 @@ class OC_TemplateLayout extends OC_Template { self::$versionHash = md5(implode(',', OC_App::getAppVersions())); } - $useAssetPipeline = $this->isAssetPipelineEnabled(); + $useAssetPipeline = self::isAssetPipelineEnabled(); if ($useAssetPipeline) { $this->append( 'jsfiles', OC_Helper::linkToRoute('js_config', array('v' => self::$versionHash))); $this->generateAssets(); } else { // Add the js files - $jsfiles = self::findJavascriptFiles(OC_Util::$scripts); + $jsFiles = self::findJavascriptFiles(OC_Util::$scripts); $this->assign('jsfiles', array(), false); - if (OC_Config::getValue('installed', false) && $renderas!='error') { + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { $this->append( 'jsfiles', OC_Helper::linkToRoute('js_config', array('v' => self::$versionHash))); } - foreach($jsfiles as $info) { + foreach($jsFiles as $info) { $web = $info[1]; $file = $info[2]; $this->append( 'jsfiles', $web.'/'.$file . '?v=' . self::$versionHash); } // Add the css files - $cssfiles = self::findStylesheetFiles(OC_Util::$styles); + $cssFiles = self::findStylesheetFiles(OC_Util::$styles); $this->assign('cssfiles', array()); - foreach($cssfiles as $info) { + foreach($cssFiles as $info) { $web = $info[1]; $file = $info[2]; @@ -113,10 +127,10 @@ class OC_TemplateLayout extends OC_Template { // Read the selected theme from the config file $theme = OC_Util::getTheme(); - // Read the detected formfactor and use the right file name. - $fext = self::getFormFactorExtension(); + // Read the detected form factor and use the right file name. + $formFactorExt = self::getFormFactorExtension(); - $locator = new \OC\Template\CSSResourceLocator( $theme, $fext, + $locator = new \OC\Template\CSSResourceLocator( $theme, $formFactorExt, array( OC::$SERVERROOT => OC::$WEBROOT ), array( OC::$THIRDPARTYROOT => OC::$THIRDPARTYWEBROOT )); $locator->find($styles); @@ -131,18 +145,17 @@ class OC_TemplateLayout extends OC_Template { // Read the selected theme from the config file $theme = OC_Util::getTheme(); - // Read the detected formfactor and use the right file name. - $fext = self::getFormFactorExtension(); + // Read the detected form factor and use the right file name. + $formFactorExt = self::getFormFactorExtension(); - $locator = new \OC\Template\JSResourceLocator( $theme, $fext, + $locator = new \OC\Template\JSResourceLocator( $theme, $formFactorExt, array( OC::$SERVERROOT => OC::$WEBROOT ), array( OC::$THIRDPARTYROOT => OC::$THIRDPARTYWEBROOT )); $locator->find($scripts); return $locator->getResources(); } - public function generateAssets() - { + public function generateAssets() { $jsFiles = self::findJavascriptFiles(OC_Util::$scripts); $jsHash = self::hashScriptNames($jsFiles); @@ -150,7 +163,13 @@ class OC_TemplateLayout extends OC_Template { $jsFiles = array_map(function ($item) { $root = $item[0]; $file = $item[2]; - return new FileAsset($root . '/' . $file, array(), $root, $file); + // no need to minifiy minified files + if (substr($file, -strlen('.min.js')) === '.min.js') { + return new FileAsset($root . '/' . $file, array(), $root, $file); + } + return new FileAsset($root . '/' . $file, array( + new JSMinFilter() + ), $root, $file); }, $jsFiles); $jsCollection = new AssetCollection($jsFiles); $jsCollection->setTargetPath("assets/$jsHash.js"); @@ -170,12 +189,13 @@ class OC_TemplateLayout extends OC_Template { $sourceRoot = \OC::$SERVERROOT; $sourcePath = substr($assetPath, strlen(\OC::$SERVERROOT)); return new FileAsset( - $assetPath, + $assetPath, array( - new CssRewriteFilter(), + new CssRewriteFilter(), + new CssMinFilter(), new CssImportFilter() ), - $sourceRoot, + $sourceRoot, $sourcePath ); }, $cssFiles); @@ -194,8 +214,8 @@ class OC_TemplateLayout extends OC_Template { * @param array $files * @return string */ - private static function hashScriptNames($files) - { + private static function hashScriptNames($files) { + $files = array_map(function ($item) { $root = $item[0]; $file = $item[2]; @@ -204,36 +224,7 @@ class OC_TemplateLayout extends OC_Template { sort($files); // include the apps' versions hash to invalidate the cached assets - $files[]= self::$versionHash; + $files[] = self::$versionHash; return hash('md5', implode('', $files)); } - - /** - * @return bool - */ - private function isAssetPipelineEnabled() { - // asset management enabled? - $useAssetPipeline = OC_Config::getValue('asset-pipeline.enabled', false); - if (!$useAssetPipeline) { - return false; - } - - // assets folder exists? - $assetDir = \OC::$SERVERROOT . '/assets'; - if (!is_dir($assetDir)) { - if (!mkdir($assetDir)) { - \OCP\Util::writeLog('assets', - "Folder <$assetDir> does not exist and/or could not be generated.", \OCP\Util::ERROR); - return false; - } - } - - // assets folder can be accessed? - if (!touch($assetDir."/.oc")) { - \OCP\Util::writeLog('assets', - "Folder <$assetDir> could not be accessed.", \OCP\Util::ERROR); - return false; - } - return $useAssetPipeline; - } } |