diff --git a/core/AssetManager.php b/core/AssetManager.php index a87db2a3f078da2d5841c33070028801e48e7143..307ad4a99a9dfd91455ea6f1194e1a5c38dea9f2 100644 --- a/core/AssetManager.php +++ b/core/AssetManager.php @@ -62,7 +62,7 @@ class Piwik_AssetManager */ public static function getJsAssets() { - if (self::getDisableMergedAssets()) { + if (self::isMergedAssetsDisabled()) { // Individual includes mode self::removeMergedAsset(self::MERGED_JS_FILE); return self::getIndividualJsIncludes(); @@ -88,54 +88,110 @@ class Piwik_AssetManager * * @throws Exception if a file can not be opened in write mode */ - private static function generateMergedCssFile() + private static function prepareMergedCssFile() { - $mergedContent = ""; + $mergedCssAlreadyGenerated = self::isGenerated(self::MERGED_CSS_FILE); + $isDevelopingPiwik = self::isMergedAssetsDisabled(); - // absolute path to doc root - $rootDirectory = realpath(PIWIK_DOCUMENT_ROOT); - if ($rootDirectory != '/' && substr_compare($rootDirectory, '/', -1)) { - $rootDirectory .= '/'; + if ($mergedCssAlreadyGenerated + && !$isDevelopingPiwik + ) { + return; } - $rootDirectoryLen = strlen($rootDirectory); - if(!class_exists("lessc")) { - throw new Exception("Less was added to composer during 2.0. ==> Execute this command to update composer packages: \$ php composer.phar update"); - } - $less = new lessc; + $less = self::makeLess(); // Loop through each css file $files = self::getCssFiles(); + $mergedContent = ""; foreach ($files as $file) { self::validateCssFile($file); $fileLocation = self::getAbsoluteLocation($file); $less->addImportDir(dirname($fileLocation)); + $content = file_get_contents($fileLocation); - // Rewrite css url directives - // - assumes these are all relative paths - // - rewrite windows directory separator \\ to / - $baseDirectory = dirname($file); - $content = preg_replace_callback( - "/(url\(['\"]?)([^'\")]*)/", - create_function( - '$matches', - "return \$matches[1] . str_replace('\\\\', '/', substr(realpath(PIWIK_DOCUMENT_ROOT . '/$baseDirectory/' . \$matches[2]), $rootDirectoryLen));" - ), - $content - ); + $content = self::rewriteCssPathsDirectives($file, $content); + $mergedContent = $mergedContent . $content; } + $fileHash = md5($mergedContent); + $firstLineCompileHash = "/* compile_me_once=$fileHash */"; + + // Disable Merged Assets ==> Check on each request if file needs re-compiling + if ($mergedCssAlreadyGenerated + && $isDevelopingPiwik + ) { + $pathMerged = self::getAbsoluteMergedFileLocation(self::MERGED_CSS_FILE); + $f = fopen($pathMerged, 'r'); + $firstLine = fgets($f); + fclose($f); + if (!empty($firstLine) + && trim($firstLine) == trim($firstLineCompileHash)) { + return; + } + // Some CSS file in the merge, has changed since last merged asset was generated + // Note: we do not detect changes in @import'ed LESS files + } + $mergedContent = $less->compile($mergedContent); Piwik_PostEvent('AssetManager.filterMergedCss', array(&$mergedContent)); + $mergedContent = + $firstLineCompileHash . "\n" + . "/* Piwik CSS file is compiled with Less. You may be interested in writing a custom Theme for Piwik! */\n" + . $mergedContent; + self::writeAssetToFile($mergedContent, self::MERGED_CSS_FILE); } + protected static function makeLess() + { + if (!class_exists("lessc")) { + throw new Exception("Less was added to composer during 2.0. ==> Execute this command to update composer packages: \$ php composer.phar update"); + } + $less = new lessc; + return $less; + } + + /* + * Rewrite css url directives + * - assumes these are all relative paths + * - rewrite windows directory separator \\ to / + */ + protected static function rewriteCssPathsDirectives($relativePath, $content) + { + static $rootDirectoryLength = null; + if (is_null($rootDirectoryLength)) { + $rootDirectoryLength = self::countDirectoriesInPathToRoot(); + } + + $baseDirectory = dirname($relativePath); + $content = preg_replace_callback( + "/(url\(['\"]?)([^'\")]*)/", + create_function( + '$matches', + "return \$matches[1] . str_replace('\\\\', '/', substr(realpath(PIWIK_DOCUMENT_ROOT . '/$baseDirectory/' . \$matches[2]), $rootDirectoryLength));" + ), + $content + ); + return $content; + } + + protected static function countDirectoriesInPathToRoot() + { + $rootDirectory = realpath(PIWIK_DOCUMENT_ROOT); + if ($rootDirectory != '/' && substr_compare($rootDirectory, '/', -1)) { + $rootDirectory .= '/'; + } + $rootDirectoryLen = strlen($rootDirectory); + return $rootDirectoryLen; + } + private static function writeAssetToFile($mergedContent, $name) { // Remove the previous file @@ -320,9 +376,9 @@ class Piwik_AssetManager * * @return string */ - private static function getDisableMergedAssets() + private static function isMergedAssetsDisabled() { - return Piwik_Config::getInstance()->Debug['disable_merged_assets']; + return (bool)Piwik_Config::getInstance()->Debug['disable_merged_assets']; } /** @@ -333,12 +389,7 @@ class Piwik_AssetManager */ public static function getMergedCssFileLocation() { - $isGenerated = self::isGenerated(self::MERGED_CSS_FILE); - - if (!$isGenerated) { - self::generateMergedCssFile(); - } - + self::prepareMergedCssFile(); return self::getAbsoluteMergedFileLocation(self::MERGED_CSS_FILE); } diff --git a/core/testMinimumPhpVersion.php b/core/testMinimumPhpVersion.php index 0f9b8b0529e61fcb4ea3e48d462c203c445277cf..e44c39ea1ea45501e34696af7ceb1cb893365eb8 100644 --- a/core/testMinimumPhpVersion.php +++ b/core/testMinimumPhpVersion.php @@ -58,9 +58,11 @@ if ($minimumPhpInvalid) { if(!file_exists($autoloader)) { $piwik_errorMessage .= "<p>It appears the <a href='https://getcomposer.org/' target='_blank'>composer</a> tool is not yet installed. You can install Composer in a few easy steps. In the piwik directory, run in the command line the following (eg. via ssh): - <pre>curl -sS https://getcomposer.org/installer | php". - "\nphp composer.phar install</pre> </p><p>This will download and install composer, and initialize composer for Piwik (eg. download the twig library in vendor/twig). - <br/>Then reload this page to access your analytics reports.</p>"; + <pre> curl -sS https://getcomposer.org/installer | php". + "\n php composer.phar install</pre> </p><p>This will download and install composer, and initialize composer for Piwik (eg. download the twig library in vendor/twig). + <br/>Then reload this page to access your analytics reports. + <br/><br/>Note: if for some reasons you cannot execute this command, install the latest Piwik release from <a + href='http://builds.piwik.org/latest.zip'>builds.piwik.org</a>.</p>"; } } diff --git a/plugins/Zeitgeist/stylesheets/base.css b/plugins/Zeitgeist/stylesheets/base.css index 4d178e86adcb495d1790c22480a1b0b247dbe3ad..a4cd523faecdbdc3ee5fea641df89b3cc5f125f4 100644 --- a/plugins/Zeitgeist/stylesheets/base.css +++ b/plugins/Zeitgeist/stylesheets/base.css @@ -503,7 +503,6 @@ body .ui-tooltip.small { } /* Component styles */ #header { - padding: 5px 0 0; min-height: 60px; } /* Clear fix */ @@ -514,6 +513,7 @@ body .ui-tooltip.small { } #logo { float: left; + padding-top:5px; } #logo > a { text-decoration: none; diff --git a/plugins/Zeitgeist/stylesheets/ui/_header.less b/plugins/Zeitgeist/stylesheets/ui/_header.less index 66e199c34ecf100259f996785ae703425b9cf5d4..f9f2c4dca83d307000e5fd83e5bea95ce67c535c 100644 --- a/plugins/Zeitgeist/stylesheets/ui/_header.less +++ b/plugins/Zeitgeist/stylesheets/ui/_header.less @@ -1,5 +1,4 @@ #header { - padding: 5px 0 0; min-height: 60px; } @@ -11,6 +10,7 @@ } #logo { + padding: 5px 0 0; float: left; }