update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -45,7 +45,6 @@ class InMemoryUIAsset extends UIAsset
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function writeContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -10,6 +10,7 @@ namespace Piwik\AssetManager\UIAsset;
|
|||
|
||||
use Exception;
|
||||
use Piwik\AssetManager\UIAsset;
|
||||
use Piwik\Filesystem;
|
||||
|
||||
class OnDiskUIAsset extends UIAsset
|
||||
{
|
||||
|
|
@ -27,7 +28,7 @@ class OnDiskUIAsset extends UIAsset
|
|||
* @param string $baseDirectory
|
||||
* @param string $fileLocation
|
||||
*/
|
||||
function __construct($baseDirectory, $fileLocation)
|
||||
public function __construct($baseDirectory, $fileLocation)
|
||||
{
|
||||
$this->baseDirectory = $baseDirectory;
|
||||
$this->relativeLocation = $fileLocation;
|
||||
|
|
@ -50,20 +51,23 @@ class OnDiskUIAsset extends UIAsset
|
|||
|
||||
public function validateFile()
|
||||
{
|
||||
if (!$this->assetIsReadable())
|
||||
if (!$this->assetIsReadable()) {
|
||||
throw new Exception("The ui asset with 'href' = " . $this->getAbsoluteLocation() . " is not readable");
|
||||
}
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if ($this->exists()) {
|
||||
|
||||
if (!unlink($this->getAbsoluteLocation()))
|
||||
try {
|
||||
Filesystem::remove($this->getAbsoluteLocation());
|
||||
} catch (Exception $e) {
|
||||
throw new Exception("Unable to delete merged file : " . $this->getAbsoluteLocation() . ". Please delete the file and refresh");
|
||||
}
|
||||
|
||||
// try to remove compressed version of the merged file.
|
||||
@unlink($this->getAbsoluteLocation() . ".deflate");
|
||||
@unlink($this->getAbsoluteLocation() . ".gz");
|
||||
Filesystem::remove($this->getAbsoluteLocation() . ".deflate", true);
|
||||
Filesystem::remove($this->getAbsoluteLocation() . ".gz", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,8 +81,9 @@ class OnDiskUIAsset extends UIAsset
|
|||
|
||||
$newFile = @fopen($this->getAbsoluteLocation(), "w");
|
||||
|
||||
if (!$newFile)
|
||||
throw new Exception ("The file : " . $newFile . " can not be opened in write mode.");
|
||||
if (!$newFile) {
|
||||
throw new Exception("The file : " . $newFile . " can not be opened in write mode.");
|
||||
}
|
||||
|
||||
fwrite($newFile, $content);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -20,10 +20,15 @@ class UIAssetCatalog
|
|||
*/
|
||||
private $catalogSorter;
|
||||
|
||||
/**
|
||||
* @var string[] Absolute file locations
|
||||
*/
|
||||
private $existingAssetLocations = array();
|
||||
|
||||
/**
|
||||
* @param UIAssetCatalogSorter $catalogSorter
|
||||
*/
|
||||
function __construct($catalogSorter)
|
||||
public function __construct($catalogSorter)
|
||||
{
|
||||
$this->catalogSorter = $catalogSorter;
|
||||
}
|
||||
|
|
@ -33,8 +38,10 @@ class UIAssetCatalog
|
|||
*/
|
||||
public function addUIAsset($uiAsset)
|
||||
{
|
||||
if(!$this->assetAlreadyInCatalog($uiAsset)) {
|
||||
$location = $uiAsset->getAbsoluteLocation();
|
||||
|
||||
if (!$this->assetAlreadyInCatalog($location)) {
|
||||
$this->existingAssetLocations[] = $location;
|
||||
$this->uiAssets[] = $uiAsset;
|
||||
}
|
||||
}
|
||||
|
|
@ -59,12 +66,8 @@ class UIAssetCatalog
|
|||
* @param UIAsset $uiAsset
|
||||
* @return boolean
|
||||
*/
|
||||
private function assetAlreadyInCatalog($uiAsset)
|
||||
private function assetAlreadyInCatalog($location)
|
||||
{
|
||||
foreach($this->uiAssets as $existingAsset)
|
||||
if($uiAsset->getAbsoluteLocation() == $existingAsset->getAbsoluteLocation())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return in_array($location, $this->existingAssetLocations);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -18,7 +18,7 @@ class UIAssetCatalogSorter
|
|||
/**
|
||||
* @param string[] $priorityOrder
|
||||
*/
|
||||
function __construct($priorityOrder)
|
||||
public function __construct($priorityOrder)
|
||||
{
|
||||
$this->priorityOrder = $priorityOrder;
|
||||
}
|
||||
|
|
@ -31,12 +31,11 @@ class UIAssetCatalogSorter
|
|||
{
|
||||
$sortedCatalog = new UIAssetCatalog($this);
|
||||
foreach ($this->priorityOrder as $filePattern) {
|
||||
|
||||
$assetsMatchingPattern = array_filter($uiAssetCatalog->getAssets(), function($uiAsset) use ($filePattern) {
|
||||
$assetsMatchingPattern = array_filter($uiAssetCatalog->getAssets(), function ($uiAsset) use ($filePattern) {
|
||||
return preg_match('~^' . $filePattern . '~', $uiAsset->getRelativeLocation());
|
||||
});
|
||||
|
||||
foreach($assetsMatchingPattern as $assetMatchingPattern) {
|
||||
foreach ($assetsMatchingPattern as $assetMatchingPattern) {
|
||||
$sortedCatalog->addUIAsset($assetMatchingPattern);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -37,7 +37,7 @@ abstract class UIAssetFetcher
|
|||
* @param string[] $plugins
|
||||
* @param Theme $theme
|
||||
*/
|
||||
function __construct($plugins, $theme)
|
||||
public function __construct($plugins, $theme)
|
||||
{
|
||||
$this->plugins = $plugins;
|
||||
$this->theme = $theme;
|
||||
|
|
@ -56,8 +56,9 @@ abstract class UIAssetFetcher
|
|||
*/
|
||||
public function getCatalog()
|
||||
{
|
||||
if($this->catalog == null)
|
||||
if ($this->catalog == null) {
|
||||
$this->createCatalog();
|
||||
}
|
||||
|
||||
return $this->catalog;
|
||||
}
|
||||
|
|
@ -89,7 +90,6 @@ abstract class UIAssetFetcher
|
|||
private function populateCatalog()
|
||||
{
|
||||
foreach ($this->fileLocations as $fileLocation) {
|
||||
|
||||
$newUIAsset = new OnDiskUIAsset($this->getBaseDirectory(), $fileLocation);
|
||||
$this->catalog->addUIAsset($newUIAsset);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -10,15 +10,13 @@ namespace Piwik\AssetManager\UIAssetFetcher;
|
|||
|
||||
use Piwik\AssetManager\UIAssetFetcher;
|
||||
use Piwik\Piwik;
|
||||
use string;
|
||||
|
||||
class JScriptUIAssetFetcher extends UIAssetFetcher
|
||||
{
|
||||
|
||||
protected function retrieveFileLocations()
|
||||
{
|
||||
|
||||
if(!empty($this->plugins)) {
|
||||
if (!empty($this->plugins)) {
|
||||
|
||||
/**
|
||||
* Triggered when gathering the list of all JavaScript files needed by Piwik
|
||||
|
|
@ -31,7 +29,7 @@ class JScriptUIAssetFetcher extends UIAssetFetcher
|
|||
* plugin's root directory.
|
||||
*
|
||||
* _Note: While you are developing your plugin you should enable the config setting
|
||||
* `[Debug] disable_merged_assets` so JavaScript files will be reloaded immediately
|
||||
* `[Development] disable_merged_assets` so JavaScript files will be reloaded immediately
|
||||
* after every change._
|
||||
*
|
||||
* **Example**
|
||||
|
|
@ -53,17 +51,14 @@ class JScriptUIAssetFetcher extends UIAssetFetcher
|
|||
protected function addThemeFiles()
|
||||
{
|
||||
$theme = $this->getTheme();
|
||||
if(!$theme) {
|
||||
if (!$theme) {
|
||||
return;
|
||||
}
|
||||
if(in_array($theme->getThemeName(), $this->plugins)) {
|
||||
|
||||
if (in_array($theme->getThemeName(), $this->plugins)) {
|
||||
$jsInThemes = $this->getTheme()->getJavaScriptFiles();
|
||||
|
||||
if(!empty($jsInThemes)) {
|
||||
|
||||
foreach($jsInThemes as $jsFile) {
|
||||
|
||||
if (!empty($jsInThemes)) {
|
||||
foreach ($jsInThemes as $jsFile) {
|
||||
$this->fileLocations[] = $jsFile;
|
||||
}
|
||||
}
|
||||
|
|
@ -73,13 +68,17 @@ class JScriptUIAssetFetcher extends UIAssetFetcher
|
|||
protected function getPriorityOrder()
|
||||
{
|
||||
return array(
|
||||
'libs/jquery/jquery.js',
|
||||
'libs/jquery/jquery-ui.js',
|
||||
'libs/bower_components/jquery/dist/jquery.min.js',
|
||||
'libs/bower_components/jquery-ui/ui/minified/jquery-ui.min.js',
|
||||
'libs/jquery/jquery.browser.js',
|
||||
'libs/',
|
||||
'js/',
|
||||
'piwik.js',
|
||||
'plugins/CoreHome/javascripts/require.js',
|
||||
'plugins/Zeitgeist/javascripts/piwikHelper.js',
|
||||
'plugins/Zeitgeist/javascripts/',
|
||||
'plugins/Morpheus/javascripts/piwikHelper.js',
|
||||
'plugins/Morpheus/javascripts/jquery.icheck.min.js',
|
||||
'plugins/Morpheus/javascripts/morpheus.js',
|
||||
'plugins/Morpheus/javascripts/',
|
||||
'plugins/CoreHome/javascripts/uiControl.js',
|
||||
'plugins/CoreHome/javascripts/broadcast.js',
|
||||
'plugins/CoreHome/javascripts/', // load CoreHome JS before other plugins
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -17,7 +17,7 @@ class StaticUIAssetFetcher extends UIAssetFetcher
|
|||
*/
|
||||
private $priorityOrder;
|
||||
|
||||
function __construct($fileLocations, $priorityOrder, $theme)
|
||||
public function __construct($fileLocations, $priorityOrder, $theme)
|
||||
{
|
||||
parent::__construct(array(), $theme);
|
||||
|
||||
|
|
@ -27,7 +27,6 @@ class StaticUIAssetFetcher extends UIAssetFetcher
|
|||
|
||||
protected function retrieveFileLocations()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function getPriorityOrder()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -15,15 +15,30 @@ class StylesheetUIAssetFetcher extends UIAssetFetcher
|
|||
{
|
||||
protected function getPriorityOrder()
|
||||
{
|
||||
return array(
|
||||
$theme = $this->getTheme();
|
||||
$themeName = $theme->getThemeName();
|
||||
|
||||
$order = array(
|
||||
'libs/',
|
||||
'plugins/CoreHome/stylesheets/color_manager.css', // must be before other Piwik stylesheets
|
||||
'plugins/Zeitgeist/stylesheets/base.less',
|
||||
'plugins/Zeitgeist/stylesheets/',
|
||||
'plugins/',
|
||||
'plugins/Dashboard/stylesheets/dashboard.less',
|
||||
'tests/',
|
||||
'plugins/Morpheus/stylesheets/base.less',
|
||||
);
|
||||
|
||||
if ($themeName === 'Morpheus') {
|
||||
$order[] = 'plugins\/((?!Morpheus).)*\/';
|
||||
} else {
|
||||
$order[] = sprintf('plugins\/((?!(Morpheus)|(%s)).)*\/', $themeName);
|
||||
}
|
||||
|
||||
$order = array_merge(
|
||||
$order,
|
||||
array(
|
||||
'plugins/Dashboard/stylesheets/dashboard.less',
|
||||
'tests/',
|
||||
)
|
||||
);
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
protected function retrieveFileLocations()
|
||||
|
|
@ -55,9 +70,13 @@ class StylesheetUIAssetFetcher extends UIAssetFetcher
|
|||
|
||||
protected function addThemeFiles()
|
||||
{
|
||||
$theme = $this->getTheme();
|
||||
if (!$theme) {
|
||||
return;
|
||||
}
|
||||
$themeStylesheet = $this->getTheme()->getStylesheet();
|
||||
|
||||
if($themeStylesheet) {
|
||||
if ($themeStylesheet) {
|
||||
$this->fileLocations[] = $themeStylesheet;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -8,9 +8,6 @@
|
|||
*/
|
||||
namespace Piwik\AssetManager;
|
||||
|
||||
use Piwik\AssetManager\PiwikLessCompiler;
|
||||
use Piwik\AssetManager\UIAsset\StylesheetUIAsset;
|
||||
use Piwik\AssetManager;
|
||||
|
||||
abstract class UIAssetMerger
|
||||
{
|
||||
|
|
@ -39,7 +36,7 @@ abstract class UIAssetMerger
|
|||
* @param UIAssetFetcher $assetFetcher
|
||||
* @param UIAssetCacheBuster $cacheBuster
|
||||
*/
|
||||
function __construct($mergedAsset, $assetFetcher, $cacheBuster)
|
||||
public function __construct($mergedAsset, $assetFetcher, $cacheBuster)
|
||||
{
|
||||
$this->mergedAsset = $mergedAsset;
|
||||
$this->assetFetcher = $assetFetcher;
|
||||
|
|
@ -48,8 +45,9 @@ abstract class UIAssetMerger
|
|||
|
||||
public function generateFile()
|
||||
{
|
||||
if(!$this->shouldGenerate())
|
||||
if (!$this->shouldGenerate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->mergedContent = $this->getMergedAssets();
|
||||
|
||||
|
|
@ -95,8 +93,9 @@ abstract class UIAssetMerger
|
|||
|
||||
protected function getConcatenatedAssets()
|
||||
{
|
||||
if(empty($this->mergedContent))
|
||||
if (empty($this->mergedContent)) {
|
||||
$this->concatenateAssets();
|
||||
}
|
||||
|
||||
return $this->mergedContent;
|
||||
}
|
||||
|
|
@ -106,7 +105,6 @@ abstract class UIAssetMerger
|
|||
$mergedContent = '';
|
||||
|
||||
foreach ($this->getAssetCatalog()->getAssets() as $uiAsset) {
|
||||
|
||||
$uiAsset->validateFile();
|
||||
$content = $this->processFileContent($uiAsset);
|
||||
|
||||
|
|
@ -137,8 +135,9 @@ abstract class UIAssetMerger
|
|||
*/
|
||||
private function shouldGenerate()
|
||||
{
|
||||
if(!$this->mergedAsset->exists())
|
||||
if (!$this->mergedAsset->exists()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !$this->isFileUpToDate();
|
||||
}
|
||||
|
|
@ -161,19 +160,11 @@ abstract class UIAssetMerger
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
private function isMergedAssetsDisabled()
|
||||
{
|
||||
return AssetManager::getInstance()->isMergedAssetsDisabled();
|
||||
}
|
||||
|
||||
private function adjustPaths()
|
||||
{
|
||||
$theme = $this->assetFetcher->getTheme();
|
||||
// During installation theme is not yet ready
|
||||
if($theme) {
|
||||
if ($theme) {
|
||||
$this->mergedContent = $this->assetFetcher->getTheme()->rewriteAssetsPathToTheme($this->mergedContent);
|
||||
}
|
||||
}
|
||||
|
|
@ -188,8 +179,9 @@ abstract class UIAssetMerger
|
|||
*/
|
||||
protected function getCacheBusterValue()
|
||||
{
|
||||
if(empty($this->cacheBusterValue))
|
||||
if (empty($this->cacheBusterValue)) {
|
||||
$this->cacheBusterValue = $this->generateCacheBuster();
|
||||
}
|
||||
|
||||
return $this->cacheBusterValue;
|
||||
}
|
||||
|
|
@ -198,12 +190,4 @@ abstract class UIAssetMerger
|
|||
{
|
||||
$this->mergedContent = $this->getPreamble() . $this->mergedContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
private function shouldCompareExistingVersion()
|
||||
{
|
||||
return $this->isMergedAssetsDisabled();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -28,7 +28,7 @@ class JScriptUIAssetMerger extends UIAssetMerger
|
|||
* @param JScriptUIAssetFetcher $assetFetcher
|
||||
* @param UIAssetCacheBuster $cacheBuster
|
||||
*/
|
||||
function __construct($mergedAsset, $assetFetcher, $cacheBuster)
|
||||
public function __construct($mergedAsset, $assetFetcher, $cacheBuster)
|
||||
{
|
||||
parent::__construct($mergedAsset, $assetFetcher, $cacheBuster);
|
||||
|
||||
|
|
@ -37,15 +37,13 @@ class JScriptUIAssetMerger extends UIAssetMerger
|
|||
|
||||
protected function getMergedAssets()
|
||||
{
|
||||
$concatenatedAssets = $this->getConcatenatedAssets();
|
||||
|
||||
return str_replace("\n", "\r\n", $concatenatedAssets);
|
||||
return $this->getConcatenatedAssets();
|
||||
}
|
||||
|
||||
protected function generateCacheBuster()
|
||||
{
|
||||
$cacheBuster = $this->cacheBuster->piwikVersionBasedCacheBuster($this->getPlugins());
|
||||
return "/* Piwik Javascript - cb=" . $cacheBuster . "*/\r\n";
|
||||
return "/* Piwik Javascript - cb=" . $cacheBuster . "*/\n";
|
||||
}
|
||||
|
||||
protected function getPreamble()
|
||||
|
|
@ -57,7 +55,7 @@ class JScriptUIAssetMerger extends UIAssetMerger
|
|||
{
|
||||
$plugins = $this->getPlugins();
|
||||
|
||||
if(!empty($plugins)) {
|
||||
if (!empty($plugins)) {
|
||||
|
||||
/**
|
||||
* Triggered after all the JavaScript files Piwik uses are minified and merged into a
|
||||
|
|
@ -74,15 +72,16 @@ class JScriptUIAssetMerger extends UIAssetMerger
|
|||
|
||||
public function getFileSeparator()
|
||||
{
|
||||
return PHP_EOL;
|
||||
return "\n";
|
||||
}
|
||||
|
||||
protected function processFileContent($uiAsset)
|
||||
{
|
||||
$content = $uiAsset->getContent();
|
||||
|
||||
if (!$this->assetMinifier->isMinifiedJs($content))
|
||||
if (!$this->assetMinifier->isMinifiedJs($content)) {
|
||||
$content = $this->assetMinifier->minifyJs($content);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -9,10 +9,10 @@
|
|||
namespace Piwik\AssetManager\UIAssetMerger;
|
||||
|
||||
use Exception;
|
||||
use lessc;
|
||||
use Piwik\AssetManager\UIAsset;
|
||||
use Piwik\AssetManager\UIAssetMerger;
|
||||
use Piwik\Piwik;
|
||||
use lessc;
|
||||
|
||||
class StylesheetUIAssetMerger extends UIAssetMerger
|
||||
{
|
||||
|
|
@ -21,7 +21,7 @@ class StylesheetUIAssetMerger extends UIAssetMerger
|
|||
*/
|
||||
private $lessCompiler;
|
||||
|
||||
function __construct($mergedAsset, $assetFetcher, $cacheBuster)
|
||||
public function __construct($mergedAsset, $assetFetcher, $cacheBuster)
|
||||
{
|
||||
parent::__construct($mergedAsset, $assetFetcher, $cacheBuster);
|
||||
|
||||
|
|
@ -30,16 +30,10 @@ class StylesheetUIAssetMerger extends UIAssetMerger
|
|||
|
||||
protected function getMergedAssets()
|
||||
{
|
||||
foreach($this->getAssetCatalog()->getAssets() as $uiAsset) {
|
||||
|
||||
$content = $uiAsset->getContent();
|
||||
if (false !== strpos($content, '@import')) {
|
||||
$this->lessCompiler->addImportDir(dirname($uiAsset->getAbsoluteLocation()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->lessCompiler->compile($this->getConcatenatedAssets());
|
||||
// note: we're using setImportDir on purpose (not addImportDir)
|
||||
$this->lessCompiler->setImportDir(PIWIK_USER_PATH);
|
||||
$concatenatedAssets = $this->getConcatenatedAssets();
|
||||
return $this->lessCompiler->compile($concatenatedAssets);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -87,46 +81,71 @@ class StylesheetUIAssetMerger extends UIAssetMerger
|
|||
|
||||
protected function processFileContent($uiAsset)
|
||||
{
|
||||
return $this->rewriteCssPathsDirectives($uiAsset);
|
||||
$pathsRewriter = $this->getCssPathsRewriter($uiAsset);
|
||||
$content = $uiAsset->getContent();
|
||||
$content = $this->rewriteCssImagePaths($content, $pathsRewriter);
|
||||
$content = $this->rewriteCssImportPaths($content, $pathsRewriter);
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrite css url directives
|
||||
* Rewrite CSS url() directives
|
||||
*
|
||||
* @param string $content
|
||||
* @param callable $pathsRewriter
|
||||
* @return string
|
||||
*/
|
||||
private function rewriteCssImagePaths($content, $pathsRewriter)
|
||||
{
|
||||
$content = preg_replace_callback("/(url\(['\"]?)([^'\")]*)/", $pathsRewriter, $content);
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrite CSS import directives
|
||||
*
|
||||
* @param string $content
|
||||
* @param callable $pathsRewriter
|
||||
* @return string
|
||||
*/
|
||||
private function rewriteCssImportPaths($content, $pathsRewriter)
|
||||
{
|
||||
$content = preg_replace_callback("/(@import \")([^\")]*)/", $pathsRewriter, $content);
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrite CSS url directives
|
||||
* - rewrites paths defined relatively to their css/less definition file
|
||||
* - rewrite windows directory separator \\ to /
|
||||
*
|
||||
* @param UIAsset $uiAsset
|
||||
* @return string
|
||||
* @return \Closure
|
||||
*/
|
||||
private function rewriteCssPathsDirectives($uiAsset)
|
||||
private function getCssPathsRewriter($uiAsset)
|
||||
{
|
||||
static $rootDirectoryLength = null;
|
||||
if (is_null($rootDirectoryLength)) {
|
||||
$rootDirectoryLength = self::countDirectoriesInPathToRoot($uiAsset);
|
||||
}
|
||||
|
||||
$baseDirectory = dirname($uiAsset->getRelativeLocation());
|
||||
$content = preg_replace_callback(
|
||||
"/(url\(['\"]?)([^'\")]*)/",
|
||||
function ($matches) use ($rootDirectoryLength, $baseDirectory) {
|
||||
|
||||
$absolutePath = realpath(PIWIK_USER_PATH . "/$baseDirectory/" . $matches[2]);
|
||||
return function ($matches) use ($baseDirectory) {
|
||||
$absolutePath = PIWIK_USER_PATH . "/$baseDirectory/" . $matches[2];
|
||||
|
||||
if($absolutePath) {
|
||||
// Allow to import extension less file
|
||||
if (strpos($matches[2], '.') === false) {
|
||||
$absolutePath .= '.less';
|
||||
}
|
||||
|
||||
$relativePath = substr($absolutePath, $rootDirectoryLength);
|
||||
// Prevent from rewriting full path
|
||||
$absolutePath = realpath($absolutePath);
|
||||
if ($absolutePath) {
|
||||
$relativePath = $baseDirectory . "/" . $matches[2];
|
||||
$relativePath = str_replace('\\', '/', $relativePath);
|
||||
$publicPath = $matches[1] . $relativePath;
|
||||
} else {
|
||||
$publicPath = $matches[1] . $matches[2];
|
||||
}
|
||||
|
||||
$relativePath = str_replace('\\', '/', $relativePath);
|
||||
|
||||
return $matches[1] . $relativePath;
|
||||
|
||||
} else {
|
||||
return $matches[1] . $matches[2];
|
||||
}
|
||||
},
|
||||
$uiAsset->getContent()
|
||||
);
|
||||
return $content;
|
||||
return $publicPath;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -138,7 +157,7 @@ class StylesheetUIAssetMerger extends UIAssetMerger
|
|||
$rootDirectory = realpath($uiAsset->getBaseDirectory());
|
||||
|
||||
if ($rootDirectory != PATH_SEPARATOR
|
||||
&& substr_compare($rootDirectory, PATH_SEPARATOR, -1)) {
|
||||
&& substr($rootDirectory, -strlen(PATH_SEPARATOR)) !== PATH_SEPARATOR) {
|
||||
$rootDirectory .= PATH_SEPARATOR;
|
||||
}
|
||||
$rootDirectoryLen = strlen($rootDirectory);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -10,8 +10,8 @@
|
|||
namespace Piwik\AssetManager;
|
||||
|
||||
use Exception;
|
||||
use Piwik\Singleton;
|
||||
use JShrink\Minifier;
|
||||
use Piwik\Singleton;
|
||||
|
||||
class UIAssetMinifier extends Singleton
|
||||
{
|
||||
|
|
@ -23,7 +23,6 @@ class UIAssetMinifier extends Singleton
|
|||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indicates if the provided JavaScript content has already been minified or not.
|
||||
* The heuristic is based on a custom ratio : (size of file) / (number of lines).
|
||||
|
|
@ -37,6 +36,7 @@ class UIAssetMinifier extends Singleton
|
|||
public function isMinifiedJs($content)
|
||||
{
|
||||
$lineCount = substr_count($content, "\n");
|
||||
|
||||
if ($lineCount == 0) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -59,8 +59,8 @@ class UIAssetMinifier extends Singleton
|
|||
|
||||
private static function validateDependency()
|
||||
{
|
||||
if (!class_exists("JShrink\\Minifier"))
|
||||
throw new Exception("JShrink could not be found, maybe you are using Piwik from git and need to have update Composer. <br>php composer.phar update");
|
||||
if (!class_exists("JShrink\\Minifier")) {
|
||||
throw new Exception("JShrink could not be found, maybe you are using Piwik from git and need to update Composer. $ php composer.phar update");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue