diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2016-03-17 03:13:08 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2016-03-29 02:12:09 +0300 |
commit | 2884da2b668cd0844e090982643dc4b0f1ef4517 (patch) | |
tree | 4263c4db2a1909c210c819b486d0aa6ea967be88 /core | |
parent | a4c0f65f0ca93ee3c1ac6633a8bead7965998bc3 (diff) |
fix #9896 Keep Page URL fragments when tracking Page URLs" not persistent
Diffstat (limited to 'core')
-rw-r--r-- | core/Access.php | 13 | ||||
-rw-r--r-- | core/AssetManager.php | 13 | ||||
-rw-r--r-- | core/BaseFactory.php | 7 | ||||
-rwxr-xr-x | core/Twig.php | 117 | ||||
-rw-r--r-- | core/Unzip.php | 4 | ||||
-rw-r--r-- | core/UpdateCheck.php | 3 | ||||
-rw-r--r-- | core/WidgetsList.php | 8 |
7 files changed, 133 insertions, 32 deletions
diff --git a/core/Access.php b/core/Access.php index 881810bfca..c8b9bafea0 100644 --- a/core/Access.php +++ b/core/Access.php @@ -10,6 +10,7 @@ namespace Piwik; use Exception; use Piwik\Container\StaticContainer; +use Piwik\Plugins\SitesManager\API as SitesManagerApi; /** * Singleton that manages user access to Piwik resources. @@ -145,7 +146,7 @@ class Access $this->login = null; // if the Auth wasn't set, we may be in the special case of setSuperUser(), otherwise we fail TODO: docs + review - if ($this->auth === null) { + if (!isset($this->auth)) { return false; } @@ -207,7 +208,8 @@ class Access if ($this->hasSuperUserAccess) { if (empty($this->idsitesByAccess['superuser'])) { try { - $allSitesId = Plugins\SitesManager\API::getInstance()->getAllSitesId(); + $api = SitesManagerApi::getInstance(); + $allSitesId = $api->getAllSitesId(); } catch (\Exception $e) { $allSitesId = array(); } @@ -460,17 +462,18 @@ class Access { $isSuperUser = self::getInstance()->hasSuperUserAccess(); - self::getInstance()->setSuperUserAccess(true); + $access = self::getInstance(); + $access->setSuperUserAccess(true); try { $result = $function(); } catch (Exception $ex) { - self::getInstance()->setSuperUserAccess($isSuperUser); + $access->setSuperUserAccess($isSuperUser); throw $ex; } - self::getInstance()->setSuperUserAccess($isSuperUser); + $access->setSuperUserAccess($isSuperUser); return $result; } diff --git a/core/AssetManager.php b/core/AssetManager.php index 407a2058c0..54c09515f5 100644 --- a/core/AssetManager.php +++ b/core/AssetManager.php @@ -123,7 +123,7 @@ class AssetManager extends Singleton $this->getMergedCoreJSAsset()->delete(); $this->getMergedNonCoreJSAsset()->delete(); - $result .= $this->getIndividualJsIncludes(); + $result .= $this->getIndividualCoreAndNonCoreJsIncludes(); } else { $result .= sprintf(self::JS_IMPORT_DIRECTIVE, self::GET_CORE_JS_MODULE_ACTION); $result .= sprintf(self::JS_IMPORT_DIRECTIVE, self::GET_NON_CORE_JS_MODULE_ACTION); @@ -290,7 +290,7 @@ class AssetManager extends Singleton * * @return string */ - private function getIndividualJsIncludes() + private function getIndividualCoreAndNonCoreJsIncludes() { return $this->getIndividualJsIncludesFromAssetFetcher($this->getCoreJScriptFetcher()) . @@ -305,7 +305,9 @@ class AssetManager extends Singleton { $jsIncludeString = ''; - foreach ($assetFetcher->getCatalog()->getAssets() as $jsFile) { + $assets = $assetFetcher->getCatalog()->getAssets(); + + foreach ($assets as $jsFile) { $jsFile->validateFile(); $jsIncludeString = $jsIncludeString . sprintf(self::JS_IMPORT_DIRECTIVE, $jsFile->getRelativeLocation()); } @@ -339,10 +341,11 @@ class AssetManager extends Singleton return false; } - $plugin = Manager::getInstance()->getLoadedPlugin($pluginName); + $pluginManager = Manager::getInstance(); + $plugin = $pluginManager->getLoadedPlugin($pluginName); if ($plugin->isTheme()) { - $theme = Manager::getInstance()->getTheme($pluginName); + $theme = $pluginManager->getTheme($pluginName); $javaScriptFiles = $theme->getJavaScriptFiles(); diff --git a/core/BaseFactory.php b/core/BaseFactory.php index 24425c8fee..32b4090bc2 100644 --- a/core/BaseFactory.php +++ b/core/BaseFactory.php @@ -34,13 +34,18 @@ abstract class BaseFactory $className = static::getClassNameFromClassId($classId); if (!class_exists($className)) { - Common::sendHeader('Content-Type: text/plain; charset=utf-8'); + self::sendPlainHeader(); throw new Exception(static::getInvalidClassIdExceptionMessage($classId)); } return new $className; } + private static function sendPlainHeader() + { + Common::sendHeader('Content-Type: text/plain; charset=utf-8'); + } + /** * Should return a class name based on the class's associated string ID. */ diff --git a/core/Twig.php b/core/Twig.php index c3b6ba7414..9f17e0b218 100755 --- a/core/Twig.php +++ b/core/Twig.php @@ -23,6 +23,85 @@ use Twig_SimpleFilter; use Twig_SimpleFunction; use Twig_SimpleTest; +function piwik_filter_truncate($string, $size) +{ + if (strlen($string) < $size) { + return $string; + } else { + $array = str_split($string, $size); + return array_shift($array) . "..."; + } +} + +function piwik_format_number($string, $minFractionDigits, $maxFractionDigits) +{ + $formatter = NumberFormatter::getInstance(); + return $formatter->format($string, $minFractionDigits, $maxFractionDigits); +} + +function piwik_fix_lbrace($string) +{ + $chars = array('{', '{', '{', '{', '{', '{'); + + static $search; + static $replace; + + if (!isset($search)) { + $search = array_map(function ($val) { return $val . $val; }, $chars); + } + if (!isset($replace)) { + $replace = array_map(function ($val) { return $val . '⁣' . $val; }, $chars); + } + + return str_replace($search, $replace, $string); +} + +function piwik_escape_filter(Twig_Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false) { + + $string = twig_escape_filter($env, $string, $strategy, $charset, $autoescape); + + switch ($strategy) { + case 'html': + case 'html_attr': + return piwik_fix_lbrace($string); + case 'url': + $encoded = rawurlencode('{'); + return str_replace('{{', $encoded . $encoded, $string); + case 'css': + case 'js': + default: + return $string; + } +} + +function piwik_format_money($amount, $idSite) +{ + $currencySymbol = Site::getCurrencySymbolFor($idSite); + $numberFormatter = NumberFormatter::getInstance(); + return $numberFormatter->formatCurrency($amount, $currencySymbol, GoalManager::REVENUE_PRECISION); +} + +class PiwikTwigFilterExtension extends \Twig_Extension +{ + public function getFilters() + { + return array( + new Twig_SimpleFilter('e', '\Piwik\piwik_escape_filter', array('needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe')), + new Twig_SimpleFilter('escape', '\Piwik\piwik_escape_filter', array('needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe')) + ); + } + + /** + * Returns the name of the extension. + * + * @return string The extension name + */ + public function getName() + { + return 'escaper2'; + } +} + /** * Twig class * @@ -84,8 +163,8 @@ class Twig $this->addFilter_money(); $this->addFilter_truncate(); $this->addFilter_notification(); - $this->addFilter_percentage(); $this->addFilter_percent(); + $this->addFilter_percentage(); $this->addFilter_percentEvolution(); $this->addFilter_piwikProAdLink(); $this->addFilter_piwikProOnPremisesAdLink(); @@ -109,6 +188,8 @@ class Twig $this->addTest_false(); $this->addTest_true(); $this->addTest_emptyString(); + + $this->twig->addExtension(new PiwikTwigFilterExtension()); } private function addTest_false() @@ -287,7 +368,9 @@ class Twig $string = str_replace('+', '%2B', $string); $string = str_replace(' ', html_entity_decode(' '), $string); - return SafeDecodeLabel::decodeLabelSafe($string); + $string = SafeDecodeLabel::decodeLabelSafe($string); + + return piwik_fix_lbrace($string); }, array('is_safe' => array('all'))); $this->twig->addFilter($rawSafeDecoded); @@ -304,7 +387,8 @@ class Twig protected function addFilter_percentage() { $percentage = new Twig_SimpleFilter('percentage', function ($string, $totalValue, $precision = 1) { - return NumberFormatter::getInstance()->formatPercent(Piwik::getPercentageSafe($string, $totalValue, $precision), $precision); + $formatter = NumberFormatter::getInstance(); + return $formatter->formatPercent(Piwik::getPercentageSafe($string, $totalValue, $precision), $precision); }); $this->twig->addFilter($percentage); } @@ -312,7 +396,8 @@ class Twig protected function addFilter_percent() { $percentage = new Twig_SimpleFilter('percent', function ($string, $precision = 1) { - return NumberFormatter::getInstance()->formatPercent($string, $precision); + $formatter = NumberFormatter::getInstance(); + return $formatter->formatPercent($string, $precision); }); $this->twig->addFilter($percentage); } @@ -320,7 +405,8 @@ class Twig protected function addFilter_percentEvolution() { $percentage = new Twig_SimpleFilter('percentEvolution', function ($string) { - return NumberFormatter::getInstance()->formatPercentEvolution($string); + $formatter = NumberFormatter::getInstance(); + return $formatter->formatPercentEvolution($string); }); $this->twig->addFilter($percentage); } @@ -371,7 +457,7 @@ class Twig protected function addFilter_number() { $formatter = new Twig_SimpleFilter('number', function ($string, $minFractionDigits = 0, $maxFractionDigits = 0) { - return NumberFormatter::getInstance()->format($string, $minFractionDigits, $maxFractionDigits); + return piwik_format_number($string, $minFractionDigits, $maxFractionDigits); }); $this->twig->addFilter($formatter); } @@ -379,27 +465,20 @@ class Twig protected function addFilter_truncate() { $truncateFilter = new Twig_SimpleFilter('truncate', function ($string, $size) { - if (strlen($string) < $size) { - return $string; - } else { - $array = str_split($string, $size); - return array_shift($array) . "..."; - } + return piwik_filter_truncate($string, $size); }); $this->twig->addFilter($truncateFilter); } protected function addFilter_money() { - $formatter = $this->formatter; - $moneyFilter = new Twig_SimpleFilter('money', function ($amount) use ($formatter) { + $moneyFilter = new Twig_SimpleFilter('money', function ($amount) { if (func_num_args() != 2) { throw new Exception('the money modifier expects one parameter: the idSite.'); } $idSite = func_get_args(); $idSite = $idSite[1]; - $currencySymbol = Site::getCurrencySymbolFor($idSite); - return NumberFormatter::getInstance()->formatCurrency($amount, $currencySymbol, GoalManager::REVENUE_PRECISION); + return piwik_format_money($amount, $idSite); }); $this->twig->addFilter($moneyFilter); } @@ -445,7 +524,8 @@ class Twig private function addPluginNamespaces(Twig_Loader_Filesystem $loader) { - $plugins = \Piwik\Plugin\Manager::getInstance()->getAllPluginsNames(); + $pluginManager = \Piwik\Plugin\Manager::getInstance(); + $plugins = $pluginManager->getAllPluginsNames(); foreach ($plugins as $name) { $path = sprintf("%s/plugins/%s/templates/", PIWIK_INCLUDE_PATH, $name); if (is_dir($path)) { @@ -461,7 +541,8 @@ class Twig */ private function addCustomPluginNamespaces(Twig_Loader_Filesystem $loader, $pluginName) { - $plugins = \Piwik\Plugin\Manager::getInstance()->getAllPluginsNames(); + $pluginManager = \Piwik\Plugin\Manager::getInstance(); + $plugins = $pluginManager->getAllPluginsNames(); foreach ($plugins as $name) { $path = sprintf("%s/plugins/%s/templates/plugins/%s/", PIWIK_INCLUDE_PATH, $pluginName, $name); if (is_dir($path)) { diff --git a/core/Unzip.php b/core/Unzip.php index ffef2add15..af1c14a815 100644 --- a/core/Unzip.php +++ b/core/Unzip.php @@ -33,15 +33,19 @@ class Unzip return new ZipArchive($filename); } break; + case 'tar.gz': return new Tar($filename, 'gz'); + case 'tar.bz2': return new Tar($filename, 'bz2'); + case 'gz': if (function_exists('gzopen')) { return new Gzip($filename); } break; + case 'PclZip': default: return new PclZip($filename); diff --git a/core/UpdateCheck.php b/core/UpdateCheck.php index b176ed87c3..e2ce130c4a 100644 --- a/core/UpdateCheck.php +++ b/core/UpdateCheck.php @@ -68,7 +68,8 @@ class UpdateCheck */ private static function getLatestAvailableVersionNumber() { - $channel = StaticContainer::get('\Piwik\Plugin\ReleaseChannels')->getActiveReleaseChannel(); + $releaseChannels = StaticContainer::get('\Piwik\Plugin\ReleaseChannels'); + $channel = $releaseChannels->getActiveReleaseChannel(); $url = $channel->getUrlToCheckForLatestAvailableVersion(); try { diff --git a/core/WidgetsList.php b/core/WidgetsList.php index 8380d7a1ee..bafc94323d 100644 --- a/core/WidgetsList.php +++ b/core/WidgetsList.php @@ -71,8 +71,7 @@ class WidgetsList extends Singleton } self::addWidgets(); - - uksort(self::$widgets, array('Piwik\WidgetsList', '_sortWidgetCategories')); + self::sortWidgets(); $widgets = array(); foreach (self::$widgets as $key => $v) { @@ -91,6 +90,11 @@ class WidgetsList extends Singleton return $widgets; } + private static function sortWidgets() + { + uksort(self::$widgets, array('Piwik\WidgetsList', '_sortWidgetCategories')); + } + private static function addWidgets() { if (!self::$hookCalled) { |