Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-09-14 07:23:23 +0400
committermattab <matthieu.aubry@gmail.com>2013-09-14 07:23:23 +0400
commite3bd0c0b9e8bd34efd27d31fe310602fcfc3a894 (patch)
tree9e8873a2410dedb65b3e725bf537d4781047b7b7
parent8d11a25fa7f41212584a58998c59884a4b9836d4 (diff)
Moving piwik settings specific getters to SettingsPiwik class
Adding MetricsFormatter class which knows how to format/display metrics (time, money, size, etc)
-rw-r--r--core/ArchiveProcessor/Period.php9
-rw-r--r--core/ArchiveProcessor/Rules.php3
-rw-r--r--core/AssetManager.php2
-rw-r--r--core/Common.php14
-rw-r--r--core/Controller.php15
-rw-r--r--core/Cookie.php6
-rw-r--r--core/DataAccess/ArchiveWriter.php3
-rw-r--r--core/Filesystem.php12
-rw-r--r--core/FrontController.php4
-rw-r--r--core/Mail.php5
-rw-r--r--core/Metrics.php3
-rw-r--r--core/MetricsFormatter.php217
-rw-r--r--core/Nonce.php4
-rw-r--r--core/Piwik.php372
-rw-r--r--core/PluginsManager.php4
-rw-r--r--core/ReportRenderer/Html.php8
-rw-r--r--core/Segment.php5
-rw-r--r--core/SettingsPiwik.php180
-rw-r--r--core/Timer.php4
-rw-r--r--core/Twig.php10
-rw-r--r--core/View.php2
-rw-r--r--core/ViewDataTable.php16
-rw-r--r--misc/cron/archive.php10
-rw-r--r--plugins/API/API.php7
-rw-r--r--plugins/API/ProcessedReport.php15
-rw-r--r--plugins/Actions/Actions.php16
-rw-r--r--plugins/CoreAdminHome/API.php3
-rw-r--r--plugins/CoreAdminHome/Controller.php16
-rw-r--r--plugins/CoreUpdater/Controller.php4
-rw-r--r--plugins/CoreUpdater/CoreUpdater.php7
-rw-r--r--plugins/CoreVisualizations/Visualizations/HtmlTable.php17
-rw-r--r--plugins/DBStats/Controller.php10
-rw-r--r--plugins/DBStats/DBStats.php4
-rw-r--r--plugins/Goals/Goals.php2
-rw-r--r--plugins/ImageGraph/Controller.php7
-rw-r--r--plugins/Installation/Controller.php2
-rw-r--r--plugins/Live/API.php19
-rw-r--r--plugins/Live/Controller.php19
-rw-r--r--plugins/Live/Visitor.php7
-rw-r--r--plugins/Login/Controller.php3
-rw-r--r--plugins/MultiSites/Controller.php11
-rw-r--r--plugins/Overlay/Controller.php3
-rw-r--r--plugins/PrivacyManager/Controller.php9
-rw-r--r--plugins/Referers/Referers.php5
-rw-r--r--plugins/SEO/RankChecker.php6
-rw-r--r--plugins/SitesManager/API.php8
-rw-r--r--plugins/UsersManager/UsersManager.php6
-rw-r--r--plugins/VisitsSummary/API.php8
-rw-r--r--tests/PHPUnit/Core/PiwikTest.php7
-rwxr-xr-xtests/PHPUnit/IntegrationTestCase.php4
50 files changed, 568 insertions, 565 deletions
diff --git a/core/ArchiveProcessor/Period.php b/core/ArchiveProcessor/Period.php
index 778b41f075..02d1af72db 100644
--- a/core/ArchiveProcessor/Period.php
+++ b/core/ArchiveProcessor/Period.php
@@ -13,13 +13,12 @@ namespace Piwik\ArchiveProcessor;
use Exception;
use Piwik\Archive;
-use Piwik\Metrics;
-use Piwik\Piwik;
-use Piwik\Common;
use Piwik\ArchiveProcessor;
+use Piwik\Common;
use Piwik\DataTable;
-use Piwik\DataTable\Map;
use Piwik\DataTable\Manager;
+use Piwik\Metrics;
+use Piwik\SettingsPiwik;
/**
* This class provides generic methods to archive data for a period (week / month / year).
@@ -266,7 +265,7 @@ class Period extends ArchiveProcessor
protected function enrichWithUniqueVisitorsMetric(&$results)
{
if (array_key_exists('nb_uniq_visitors', $results)) {
- if (Piwik::isUniqueVisitorsEnabled($this->getPeriod()->getLabel())) {
+ if (SettingsPiwik::isUniqueVisitorsEnabled($this->getPeriod()->getLabel())) {
$results['nb_uniq_visitors'] = (float)$this->computeNbUniqVisitors();
} else {
unset($results['nb_uniq_visitors']);
diff --git a/core/ArchiveProcessor/Rules.php b/core/ArchiveProcessor/Rules.php
index eadb6ad244..9b40be42bc 100644
--- a/core/ArchiveProcessor/Rules.php
+++ b/core/ArchiveProcessor/Rules.php
@@ -15,6 +15,7 @@ use Piwik\Config;
use Piwik\Date;
use Piwik\Piwik;
use Piwik\Segment;
+use Piwik\SettingsPiwik;
use Piwik\SettingsServer;
use Piwik\Site;
use Piwik\Tracker\Cache;
@@ -59,7 +60,7 @@ class Rules
return true;
}
- $segmentsToProcess = Piwik::getKnownSegmentsToArchive();
+ $segmentsToProcess = SettingsPiwik::getKnownSegmentsToArchive();
if (!empty($segmentsToProcess)) {
// If the requested segment is one of the segments to pre-process
// we ensure that any call to the API will trigger archiving of all reports for this segment
diff --git a/core/AssetManager.php b/core/AssetManager.php
index 1f4a190475..b5ae6a6a5f 100644
--- a/core/AssetManager.php
+++ b/core/AssetManager.php
@@ -86,7 +86,7 @@ class AssetManager
public static function generateAssetsCacheBuster()
{
$pluginList = md5(implode(",", PluginsManager::getInstance()->getLoadedPluginsName()));
- $cacheBuster = md5(Common::getSalt() . $pluginList . PHP_VERSION . Version::VERSION);
+ $cacheBuster = md5(SettingsPiwik::getSalt() . $pluginList . PHP_VERSION . Version::VERSION);
return $cacheBuster;
}
diff --git a/core/Common.php b/core/Common.php
index d115cc53ed..36ff82061e 100644
--- a/core/Common.php
+++ b/core/Common.php
@@ -587,20 +587,6 @@ class Common
}
/**
- * Get salt from [superuser] section
- *
- * @return string
- */
- public static function getSalt()
- {
- static $salt = null;
- if (is_null($salt)) {
- $salt = @Config::getInstance()->superuser['salt'];
- }
- return $salt;
- }
-
- /**
* Configureable hash() algorithm (defaults to md5)
*
* @param string $str String to be hashed
diff --git a/core/Controller.php b/core/Controller.php
index b1d394430d..c241085848 100644
--- a/core/Controller.php
+++ b/core/Controller.php
@@ -11,23 +11,14 @@
namespace Piwik;
use Exception;
-use Piwik\Config;
+use Piwik\API\Request;
use Piwik\DataTable\Filter\CalculateEvolutionFilter;
-use Piwik\Period;
use Piwik\Period\Month;
+use Piwik\Period;
use Piwik\Period\Range;
-use Piwik\Piwik;
-use Piwik\Common;
-use Piwik\Access;
-use Piwik\NoAccessException;
-use Piwik\Date;
-use Piwik\Site;
use Piwik\Plugins\API\API;
-use Piwik\API\Request;
-use Piwik\FrontController;
use Piwik\Plugins\LanguagesManager\LanguagesManager;
use Piwik\Plugins\SitesManager\API as SitesManagerAPI;
-use Piwik\Url;
use Piwik\Plugins\UsersManager\API as UsersManagerAPI;
use Piwik\View;
use Piwik\ViewDataTable;
@@ -549,7 +540,7 @@ abstract class Controller
}
$currentPeriod = Common::getRequestVar('period');
- $view->displayUniqueVisitors = Piwik::isUniqueVisitorsEnabled($currentPeriod);
+ $view->displayUniqueVisitors = SettingsPiwik::isUniqueVisitorsEnabled($currentPeriod);
$availablePeriods = array('day', 'week', 'month', 'year', 'range');
if (!in_array($currentPeriod, $availablePeriods)) {
throw new Exception("Period must be one of: " . implode(",", $availablePeriods));
diff --git a/core/Cookie.php b/core/Cookie.php
index 84246569af..4492fffb72 100644
--- a/core/Cookie.php
+++ b/core/Cookie.php
@@ -10,8 +10,6 @@
*/
namespace Piwik;
-use Piwik\Common;
-
/**
* Simple class to handle the cookies:
* - read a cookie values
@@ -206,7 +204,7 @@ class Cookie
{
$signature = substr($content, -40);
if (substr($content, -43, 3) == self::VALUE_SEPARATOR . '_=' &&
- $signature == sha1(substr($content, 0, -40) . Common::getSalt())
+ $signature == sha1(substr($content, 0, -40) . SettingsPiwik::getSalt())
) {
// strip trailing: VALUE_SEPARATOR '_=' signature"
return substr($content, 0, -43);
@@ -272,7 +270,7 @@ class Cookie
$cookieStr .= '_=';
// sign cookie
- $signature = sha1($cookieStr . Common::getSalt());
+ $signature = sha1($cookieStr . SettingsPiwik::getSalt());
return $cookieStr . $signature;
}
diff --git a/core/DataAccess/ArchiveWriter.php b/core/DataAccess/ArchiveWriter.php
index 18bc227d74..45027c5bd3 100644
--- a/core/DataAccess/ArchiveWriter.php
+++ b/core/DataAccess/ArchiveWriter.php
@@ -20,6 +20,7 @@ use Piwik\Db\BatchInsert;
use Piwik\Period;
use Piwik\Piwik;
use Piwik\Segment;
+use Piwik\SettingsPiwik;
/**
* This class is used to create a new Archive.
@@ -134,7 +135,7 @@ class ArchiveWriter
. $period->getId() . '/'
. $period->getDateStart()->toString('Y-m-d') . ','
. $period->getDateEnd()->toString('Y-m-d');
- return $lockName . '/' . md5($lockName . Common::getSalt());
+ return $lockName . '/' . md5($lockName . SettingsPiwik::getSalt());
}
public function finalizeArchive()
diff --git a/core/Filesystem.php b/core/Filesystem.php
index 45877e6763..34b66ed777 100644
--- a/core/Filesystem.php
+++ b/core/Filesystem.php
@@ -11,10 +11,22 @@
namespace Piwik;
use Exception;
+use Piwik\Tracker\Cache;
class Filesystem
{
/**
+ * Called on Core install, update, plugin enable/disable
+ * Will clear all cache that could be affected by the change in configuration being made
+ */
+ public static function deleteAllCacheOnUpdate()
+ {
+ AssetManager::removeMergedAssets();
+ View::clearCompiledTemplates();
+ Cache::deleteTrackerCache();
+ }
+
+ /**
* ending WITHOUT slash
*
* @return string
diff --git a/core/FrontController.php b/core/FrontController.php
index 693d5bd5ae..e3db4927d8 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -276,8 +276,8 @@ class FrontController
PluginsManager::getInstance()->installLoadedPlugins();
// ensure the current Piwik URL is known for later use
- if (method_exists('Piwik\Piwik', 'getPiwikUrl')) {
- $host = Piwik::getPiwikUrl();
+ if (method_exists('Piwik\SettingsPiwik', 'getPiwikUrl')) {
+ $host = SettingsPiwik::getPiwikUrl();
}
Piwik_PostEvent('FrontController.initAuthenticationObject');
diff --git a/core/Mail.php b/core/Mail.php
index 1ffbc5d2e4..27ccf629ef 100644
--- a/core/Mail.php
+++ b/core/Mail.php
@@ -10,9 +10,6 @@
*/
namespace Piwik;
-use Piwik\Config;
-use Piwik\Piwik;
-use Piwik\Url;
use Zend_Mail;
/**
@@ -48,7 +45,7 @@ class Mail extends Zend_Mail
$piwikHost = Url::getCurrentHost($hostname);
// If known Piwik URL, use it instead of "localhost"
- $piwikUrl = Piwik::getPiwikUrl();
+ $piwikUrl = SettingsPiwik::getPiwikUrl();
$url = parse_url($piwikUrl);
if (isset($url['host'])
&& $url['host'] != 'localhost'
diff --git a/core/Metrics.php b/core/Metrics.php
index 3d6bc17c48..ada20a7646 100644
--- a/core/Metrics.php
+++ b/core/Metrics.php
@@ -9,7 +9,6 @@
* @package Piwik
*/
namespace Piwik;
-use Piwik\Piwik;
/**
* This class holds the various mappings we use to internally store and manipulate metrics.
@@ -194,7 +193,7 @@ class Metrics
{
$nameToUnit = array(
'_rate' => '%',
- 'revenue' => Piwik::getCurrency($idSite),
+ 'revenue' => MetricsFormatter::getCurrencySymbol($idSite),
'_time_' => 's'
);
diff --git a/core/MetricsFormatter.php b/core/MetricsFormatter.php
new file mode 100644
index 0000000000..63794f3c81
--- /dev/null
+++ b/core/MetricsFormatter.php
@@ -0,0 +1,217 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ * @category Piwik
+ * @package Piwik
+ */
+namespace Piwik;
+
+use Piwik\Tracker\GoalManager;
+
+class MetricsFormatter
+{
+ /**
+ * Gets a prettified string representation of a number. The result will have
+ * thousands separators and a decimal point specific to the current locale.
+ *
+ * @param number $value
+ * @return string
+ */
+ public static function getPrettyNumber($value)
+ {
+ $locale = localeconv();
+
+ $decimalPoint = $locale['decimal_point'];
+ $thousandsSeparator = $locale['thousands_sep'];
+
+ return number_format($value, 0, $decimalPoint, $thousandsSeparator);
+ }
+
+ /**
+ * Pretty format a time
+ *
+ * @param int $numberOfSeconds
+ * @param bool $displayTimeAsSentence If set to true, will output "5min 17s", if false "00:05:17"
+ * @param bool $isHtml
+ * @param bool $round to the full seconds
+ * @return string
+ */
+ public static function getPrettyTimeFromSeconds($numberOfSeconds, $displayTimeAsSentence = true, $isHtml = true, $round = false)
+ {
+ $numberOfSeconds = $round ? (int)$numberOfSeconds : (float)$numberOfSeconds;
+
+ // Display 01:45:17 time format
+ if ($displayTimeAsSentence === false) {
+ $hours = floor($numberOfSeconds / 3600);
+ $minutes = floor(($reminder = ($numberOfSeconds - $hours * 3600)) / 60);
+ $seconds = floor($reminder - $minutes * 60);
+ $time = sprintf("%02s", $hours) . ':' . sprintf("%02s", $minutes) . ':' . sprintf("%02s", $seconds);
+ $centiSeconds = ($numberOfSeconds * 100) % 100;
+ if ($centiSeconds) {
+ $time .= '.' . sprintf("%02s", $centiSeconds);
+ }
+ return $time;
+ }
+ $secondsInYear = 86400 * 365.25;
+ $years = floor($numberOfSeconds / $secondsInYear);
+ $minusYears = $numberOfSeconds - $years * $secondsInYear;
+ $days = floor($minusYears / 86400);
+
+ $minusDays = $numberOfSeconds - $days * 86400;
+ $hours = floor($minusDays / 3600);
+
+ $minusDaysAndHours = $minusDays - $hours * 3600;
+ $minutes = floor($minusDaysAndHours / 60);
+
+ $seconds = $minusDaysAndHours - $minutes * 60;
+ $precision = ($seconds > 0 && $seconds < 0.01 ? 3 : 2);
+ $seconds = round($seconds, $precision);
+
+ if ($years > 0) {
+ $return = sprintf(Piwik_Translate('General_YearsDays'), $years, $days);
+ } elseif ($days > 0) {
+ $return = sprintf(Piwik_Translate('General_DaysHours'), $days, $hours);
+ } elseif ($hours > 0) {
+ $return = sprintf(Piwik_Translate('General_HoursMinutes'), $hours, $minutes);
+ } elseif ($minutes > 0) {
+ $return = sprintf(Piwik_Translate('General_MinutesSeconds'), $minutes, $seconds);
+ } else {
+ $return = sprintf(Piwik_Translate('General_Seconds'), $seconds);
+ }
+ if ($isHtml) {
+ return str_replace(' ', '&nbsp;', $return);
+ }
+ return $return;
+ }
+
+ /**
+ * Pretty format a memory size value
+ *
+ * @param number $size size in bytes
+ * @param string $unit The specific unit to use, if any. If null, the unit is determined by $size.
+ * @param int $precision The precision to use when rounding.
+ * @return string
+ */
+ public static function getPrettySizeFromBytes($size, $unit = null, $precision = 1)
+ {
+ if ($size == 0) {
+ return '0 M';
+ }
+
+ $units = array('B', 'K', 'M', 'G', 'T');
+ foreach ($units as $currentUnit) {
+ if ($size >= 1024 && $unit != $currentUnit) {
+ $size = $size / 1024;
+ } else {
+ break;
+ }
+ }
+ return round($size, $precision) . " " . $currentUnit;
+ }
+
+ /**
+ * Pretty format monetary value for a site
+ *
+ * @param int|string $value
+ * @param int $idSite
+ * @param bool $htmlAllowed
+ * @return string
+ */
+ public static function getPrettyMoney($value, $idSite, $htmlAllowed = true)
+ {
+ $currencyBefore = MetricsFormatter::getCurrencySymbol($idSite);
+
+ $space = ' ';
+ if ($htmlAllowed) {
+ $space = '&nbsp;';
+ }
+
+ $currencyAfter = '';
+ // manually put the currency symbol after the amount for euro
+ // (maybe more currencies prefer this notation?)
+ if (in_array($currencyBefore, array('€', 'kr'))) {
+ $currencyAfter = $space . $currencyBefore;
+ $currencyBefore = '';
+ }
+
+ // if the input is a number (it could be a string or INPUT form),
+ // and if this number is not an int, we round to precision 2
+ if (is_numeric($value)) {
+ if ($value == round($value)) {
+ // 0.0 => 0
+ $value = round($value);
+ } else {
+ $precision = GoalManager::REVENUE_PRECISION;
+ $value = sprintf("%01." . $precision . "f", $value);
+ }
+ }
+ $prettyMoney = $currencyBefore . $space . $value . $currencyAfter;
+ return $prettyMoney;
+ }
+
+ /**
+ * For the given value, based on the column name, will apply: pretty time, pretty money
+ * @param int $idSite
+ * @param string $columnName
+ * @param mixed $value
+ * @param bool $htmlAllowed
+ * @return string
+ */
+ public static function getPrettyValue($idSite, $columnName, $value, $htmlAllowed)
+ {
+ // Display time in human readable
+ if (strpos($columnName, 'time') !== false) {
+ // Little hack: Display 15s rather than 00:00:15, only for "(avg|min|max)_generation_time"
+ $timeAsSentence = (substr($columnName, -16) == '_time_generation');
+ return self::getPrettyTimeFromSeconds($value, $timeAsSentence);
+ }
+ // Add revenue symbol to revenues
+ if (strpos($columnName, 'revenue') !== false && strpos($columnName, 'evolution') === false) {
+ return self::getPrettyMoney($value, $idSite, $htmlAllowed);
+ }
+ // Add % symbol to rates
+ if (strpos($columnName, '_rate') !== false) {
+ if (strpos($value, "%") === false) {
+ return $value . "%";
+ }
+ }
+ return $value;
+ }
+
+ /**
+ * Get currency symbol for a site
+ *
+ * @param int $idSite
+ * @return string
+ */
+ public static function getCurrencySymbol($idSite)
+ {
+ $symbols = MetricsFormatter::getCurrencyList();
+ $site = new Site($idSite);
+ $currency = $site->getCurrency();
+ if (isset($symbols[$currency])) {
+ return $symbols[$currency][0];
+ }
+
+ return '';
+ }
+
+ /**
+ * Returns a list of currency symbols
+ *
+ * @return array array( currencyCode => symbol, ... )
+ */
+ public static function getCurrencyList()
+ {
+ static $currenciesList = null;
+ if (is_null($currenciesList)) {
+ require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Currencies.php';
+ $currenciesList = $GLOBALS['Piwik_CurrencyList'];
+ }
+ return $currenciesList;
+ }
+} \ No newline at end of file
diff --git a/core/Nonce.php b/core/Nonce.php
index d7606854f9..136db339af 100644
--- a/core/Nonce.php
+++ b/core/Nonce.php
@@ -10,9 +10,7 @@
*/
namespace Piwik;
-use Piwik\Common;
use Piwik\Session\SessionNamespace;
-use Piwik\Url;
/**
* Nonce class.
@@ -46,7 +44,7 @@ class Nonce
// to handle browser pre-fetch or double fetch caused by some browser add-ons/extensions
if (empty($nonce)) {
// generate a new nonce
- $nonce = md5(Common::getSalt() . time() . Common::generateUniqId());
+ $nonce = md5(SettingsPiwik::getSalt() . time() . Common::generateUniqId());
$ns->nonce = $nonce;
$ns->setExpirationSeconds($ttl, 'nonce');
}
diff --git a/core/Piwik.php b/core/Piwik.php
index 926393a531..75f37139b9 100644
--- a/core/Piwik.php
+++ b/core/Piwik.php
@@ -18,9 +18,7 @@ use Piwik\Log\ScreenFormatter;
use Piwik\Plugin;
use Piwik\Plugins\UsersManager\API;
use Piwik\Session;
-use Piwik\Tracker\Cache;
use Piwik\Tracker;
-use Piwik\Tracker\GoalManager;
use Piwik\View;
use Zend_Registry;
@@ -62,42 +60,6 @@ class Piwik
const LABEL_ID_GOAL_IS_ECOMMERCE_ORDER = 'ecommerceOrder';
/**
- * Should we process and display Unique Visitors?
- * -> Always process for day/week/month periods
- * For Year and Range, only process if it was enabled in the config file,
- *
- * @param string $periodLabel Period label (e.g., 'day')
- * @return bool
- */
- static public function isUniqueVisitorsEnabled($periodLabel)
- {
- $generalSettings = Config::getInstance()->General;
-
- $settingName = "enable_processing_unique_visitors_$periodLabel";
- $result = !empty($generalSettings[$settingName]) && $generalSettings[$settingName] == 1;
-
- // check enable_processing_unique_visitors_year_and_range for backwards compatibility
- if (($periodLabel == 'year' || $periodLabel == 'range')
- && isset($generalSettings['enable_processing_unique_visitors_year_and_range'])
- ) {
- $result |= $generalSettings['enable_processing_unique_visitors_year_and_range'] == 1;
- }
-
- return $result;
- }
-
- /**
- * Returns true if Segmentation is allowed for this user
- *
- * @return bool
- */
- public static function isSegmentationEnabled()
- {
- return !Piwik::isUserIsAnonymous()
- || Config::getInstance()->General['anonymous_user_enable_use_segments_API'];
- }
-
- /**
* Uninstallation helper
*/
static public function uninstall()
@@ -122,69 +84,6 @@ class Piwik
}
/**
- * Called on Core install, update, plugin enable/disable
- * Will clear all cache that could be affected by the change in configuration being made
- */
- static public function deleteAllCacheOnUpdate()
- {
- AssetManager::removeMergedAssets();
- View::clearCompiledTemplates();
- Cache::deleteTrackerCache();
- }
-
- /**
- * Cache for result of getPiwikUrl.
- * Can be overwritten for testing purposes only.
- *
- * @var string
- */
- static public $piwikUrlCache = null;
-
- /**
- * Returns the cached the Piwik URL, eg. http://demo.piwik.org/ or http://example.org/piwik/
- * If not found, then tries to cache it and returns the value.
- *
- * If the Piwik URL changes (eg. Piwik moved to new server), the value will automatically be refreshed in the cache.
- *
- * @return string
- */
- static public function getPiwikUrl()
- {
- // Only set in tests
- if (self::$piwikUrlCache !== null) {
- return self::$piwikUrlCache;
- }
-
- $key = 'piwikUrl';
- $url = Piwik_GetOption($key);
- if (SettingsServer::isPhpCliMode()
- // in case archive.php is triggered with domain localhost
- || SettingsServer::isArchivePhpTriggered()
- || defined('PIWIK_MODE_ARCHIVE')
- ) {
- return $url;
- }
-
- $currentUrl = Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName());
-
- if (empty($url)
- // if URL changes, always update the cache
- || $currentUrl != $url
- ) {
- if (strlen($currentUrl) >= strlen('http://a/')) {
- Piwik_SetOption($key, $currentUrl, $autoLoad = true);
- }
- $url = $currentUrl;
- }
- return $url;
- }
-
-
- /*
- * PHP environment settings
- */
-
- /**
* Logging and error handling
*
* @var bool|null
@@ -199,7 +98,7 @@ class Piwik
static public function log($message = '')
{
if (is_null(self::$shouldLog)) {
- self::$shouldLog = self::shouldLoggerLog();
+ self::$shouldLog = SettingsPiwik::shouldLoggerLog();
// It is possible that the logger is not setup:
// - Tracker request, and debug disabled,
// - and some scheduled tasks call code that tries and log something
@@ -215,24 +114,6 @@ class Piwik
}
/**
- * Returns if logging should work
- * @return bool
- */
- static public function shouldLoggerLog()
- {
- try {
- $shouldLog = (SettingsServer::isPhpCliMode()
- || Config::getInstance()->log['log_only_when_cli'] == 0)
- &&
- (Config::getInstance()->log['log_only_when_debug_parameter'] == 0
- || isset($_REQUEST['debug']));
- } catch (Exception $e) {
- $shouldLog = false;
- }
- return $shouldLog;
- }
-
- /**
* Trigger E_USER_ERROR with optional message
*
* @param string $message
@@ -264,21 +145,6 @@ class Piwik
*/
/**
- * Returns a list of currency symbols
- *
- * @return array array( currencyCode => symbol, ... )
- */
- static public function getCurrencyList()
- {
- static $currenciesList = null;
- if (is_null($currenciesList)) {
- require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Currencies.php';
- $currenciesList = $GLOBALS['Piwik_CurrencyList'];
- }
- return $currenciesList;
- }
-
- /**
* Computes the division of i1 by i2. If either i1 or i2 are not number, or if i2 has a value of zero
* we return 0 to avoid the division by zero.
*
@@ -311,192 +177,6 @@ class Piwik
}
/**
- * Get currency symbol for a site
- *
- * @param int $idSite
- * @return string
- */
- static public function getCurrency($idSite)
- {
- $symbols = self::getCurrencyList();
- $site = new Site($idSite);
- $currency = $site->getCurrency();
- if (isset($symbols[$currency])) {
- return $symbols[$currency][0];
- }
-
- return '';
- }
-
- /**
- * For the given value, based on the column name, will apply: pretty time, pretty money
- * @param int $idSite
- * @param string $columnName
- * @param mixed $value
- * @param bool $htmlAllowed
- * @return string
- */
- static public function getPrettyValue($idSite, $columnName, $value, $htmlAllowed)
- {
- // Display time in human readable
- if (strpos($columnName, 'time') !== false) {
- // Little hack: Display 15s rather than 00:00:15, only for "(avg|min|max)_generation_time"
- $timeAsSentence = (substr($columnName, -16) == '_time_generation');
- return Piwik::getPrettyTimeFromSeconds($value, $timeAsSentence);
- }
- // Add revenue symbol to revenues
- if (strpos($columnName, 'revenue') !== false && strpos($columnName, 'evolution') === false) {
- return Piwik::getPrettyMoney($value, $idSite, $htmlAllowed);
- }
- // Add % symbol to rates
- if (strpos($columnName, '_rate') !== false) {
- if (strpos($value, "%") === false) {
- return $value . "%";
- }
- }
- return $value;
- }
-
- /**
- * Pretty format monetary value for a site
- *
- * @param int|string $value
- * @param int $idSite
- * @param bool $htmlAllowed
- * @return string
- */
- static public function getPrettyMoney($value, $idSite, $htmlAllowed = true)
- {
- $currencyBefore = self::getCurrency($idSite);
-
- $space = ' ';
- if ($htmlAllowed) {
- $space = '&nbsp;';
- }
-
- $currencyAfter = '';
- // manually put the currency symbol after the amount for euro
- // (maybe more currencies prefer this notation?)
- if (in_array($currencyBefore, array('€', 'kr'))) {
- $currencyAfter = $space . $currencyBefore;
- $currencyBefore = '';
- }
-
- // if the input is a number (it could be a string or INPUT form),
- // and if this number is not an int, we round to precision 2
- if (is_numeric($value)) {
- if ($value == round($value)) {
- // 0.0 => 0
- $value = round($value);
- } else {
- $precision = GoalManager::REVENUE_PRECISION;
- $value = sprintf("%01." . $precision . "f", $value);
- }
- }
- $prettyMoney = $currencyBefore . $space . $value . $currencyAfter;
- return $prettyMoney;
- }
-
- /**
- * Pretty format a memory size value
- *
- * @param number $size size in bytes
- * @param string $unit The specific unit to use, if any. If null, the unit is determined by $size.
- * @param int $precision The precision to use when rounding.
- * @return string
- */
- static public function getPrettySizeFromBytes($size, $unit = null, $precision = 1)
- {
- if ($size == 0) {
- return '0 M';
- }
-
- $units = array('B', 'K', 'M', 'G', 'T');
- foreach ($units as $currentUnit) {
- if ($size >= 1024 && $unit != $currentUnit) {
- $size = $size / 1024;
- } else {
- break;
- }
- }
- return round($size, $precision) . " " . $currentUnit;
- }
-
- /**
- * Pretty format a time
- *
- * @param int $numberOfSeconds
- * @param bool $displayTimeAsSentence If set to true, will output "5min 17s", if false "00:05:17"
- * @param bool $isHtml
- * @param bool $round to the full seconds
- * @return string
- */
- static public function getPrettyTimeFromSeconds($numberOfSeconds, $displayTimeAsSentence = true, $isHtml = true, $round = false)
- {
- $numberOfSeconds = $round ? (int)$numberOfSeconds : (float)$numberOfSeconds;
-
- // Display 01:45:17 time format
- if ($displayTimeAsSentence === false) {
- $hours = floor($numberOfSeconds / 3600);
- $minutes = floor(($reminder = ($numberOfSeconds - $hours * 3600)) / 60);
- $seconds = floor($reminder - $minutes * 60);
- $time = sprintf("%02s", $hours) . ':' . sprintf("%02s", $minutes) . ':' . sprintf("%02s", $seconds);
- $centiSeconds = ($numberOfSeconds * 100) % 100;
- if ($centiSeconds) {
- $time .= '.' . sprintf("%02s", $centiSeconds);
- }
- return $time;
- }
- $secondsInYear = 86400 * 365.25;
- $years = floor($numberOfSeconds / $secondsInYear);
- $minusYears = $numberOfSeconds - $years * $secondsInYear;
- $days = floor($minusYears / 86400);
-
- $minusDays = $numberOfSeconds - $days * 86400;
- $hours = floor($minusDays / 3600);
-
- $minusDaysAndHours = $minusDays - $hours * 3600;
- $minutes = floor($minusDaysAndHours / 60);
-
- $seconds = $minusDaysAndHours - $minutes * 60;
- $precision = ($seconds > 0 && $seconds < 0.01 ? 3 : 2);
- $seconds = round($seconds, $precision);
-
- if ($years > 0) {
- $return = sprintf(Piwik_Translate('General_YearsDays'), $years, $days);
- } elseif ($days > 0) {
- $return = sprintf(Piwik_Translate('General_DaysHours'), $days, $hours);
- } elseif ($hours > 0) {
- $return = sprintf(Piwik_Translate('General_HoursMinutes'), $hours, $minutes);
- } elseif ($minutes > 0) {
- $return = sprintf(Piwik_Translate('General_MinutesSeconds'), $minutes, $seconds);
- } else {
- $return = sprintf(Piwik_Translate('General_Seconds'), $seconds);
- }
- if ($isHtml) {
- return str_replace(' ', '&nbsp;', $return);
- }
- return $return;
- }
-
- /**
- * Gets a prettified string representation of a number. The result will have
- * thousands separators and a decimal point specific to the current locale.
- *
- * @param number $value
- * @return string
- */
- static public function getPrettyNumber($value)
- {
- $locale = localeconv();
-
- $decimalPoint = $locale['decimal_point'];
- $thousandsSeparator = $locale['thousands_sep'];
-
- return number_format($value, 0, $decimalPoint, $thousandsSeparator);
- }
-
- /**
* Returns the Javascript code to be inserted on every page to track
*
* @param int $idSite
@@ -538,44 +218,6 @@ class Piwik
return $title;
}
- /**
- * Number of websites to show in the Website selector
- *
- * @return int
- */
- static public function getWebsitesCountToDisplay()
- {
- $count = max(Config::getInstance()->General['site_selector_max_sites'],
- Config::getInstance()->General['autocomplete_min_sites']);
- return (int)$count;
- }
-
- /**
- * Segments to pre-process
- *
- * @return string
- */
- static public function getKnownSegmentsToArchive()
- {
- if (self::$cachedKnownSegmentsToArchive === null) {
- $segments = Config::getInstance()->Segments;
- $cachedResult = isset($segments['Segments']) ? $segments['Segments'] : array();
-
- Piwik_PostEvent('Piwik.getKnownSegmentsToArchiveAllSites', array(&$cachedResult));
-
- self::$cachedKnownSegmentsToArchive = array_unique($cachedResult);
- }
-
- return self::$cachedKnownSegmentsToArchive;
- }
-
- static public function getKnownSegmentsToArchiveForSite($idSite)
- {
- $segments = array();
- Piwik_PostEvent('Piwik.getKnownSegmentsToArchiveForSite', array(&$segments, $idSite));
- return $segments;
- }
-
/*
* Access
*/
@@ -1006,7 +648,7 @@ class Piwik
*/
static public function checkValidLoginString($userLogin)
{
- if (!self::isChecksEnabled()
+ if (!SettingsPiwik::isUserCredentialsSanityCheckEnabled()
&& !empty($userLogin)
) {
return;
@@ -1022,16 +664,6 @@ class Piwik
}
}
- /**
- * Should Piwik check that the login & password have minimum length and valid characters?
- *
- * @return bool True if checks enabled; false otherwise
- */
- static public function isChecksEnabled()
- {
- return Config::getInstance()->General['disable_checks_usernames_attributes'] == 0;
- }
-
/*
* Database and table definition methods
*/
diff --git a/core/PluginsManager.php b/core/PluginsManager.php
index 2df4707994..b56f4a4e43 100644
--- a/core/PluginsManager.php
+++ b/core/PluginsManager.php
@@ -243,7 +243,7 @@ class PluginsManager
}
Config::getInstance()->forceSave();
- Piwik::deleteAllCacheOnUpdate();
+ Filesystem::deleteAllCacheOnUpdate();
return $plugins;
}
@@ -310,7 +310,7 @@ class PluginsManager
$this->updatePluginsConfig($plugins);
Config::getInstance()->forceSave();
- Piwik::deleteAllCacheOnUpdate();
+ Filesystem::deleteAllCacheOnUpdate();
}
protected function isPluginInFilesystem($pluginName)
diff --git a/core/ReportRenderer/Html.php b/core/ReportRenderer/Html.php
index 40055bbaa6..4e8a2c53cf 100644
--- a/core/ReportRenderer/Html.php
+++ b/core/ReportRenderer/Html.php
@@ -10,10 +10,10 @@
*/
namespace Piwik\ReportRenderer;
-use Piwik\Piwik;
-use Piwik\View;
-use Piwik\ReportRenderer;
use Piwik\Plugins\API\API;
+use Piwik\ReportRenderer;
+use Piwik\SettingsPiwik;
+use Piwik\View;
/**
*
@@ -119,7 +119,7 @@ class Html extends ReportRenderer
$view->assign("reportTableHeaderTextSize", self::REPORT_TABLE_HEADER_TEXT_SIZE);
$view->assign("reportTableRowTextSize", self::REPORT_TABLE_ROW_TEXT_SIZE);
$view->assign("reportBackToTopTextSize", self::REPORT_BACK_TO_TOP_TEXT_SIZE);
- $view->assign("currentPath", Piwik::getPiwikUrl());
+ $view->assign("currentPath", SettingsPiwik::getPiwikUrl());
$view->assign("logoHeader", API::getInstance()->getHeaderLogoUrl());
}
diff --git a/core/Segment.php b/core/Segment.php
index 8687362a56..508afbdd11 100644
--- a/core/Segment.php
+++ b/core/Segment.php
@@ -10,10 +10,7 @@
*/
namespace Piwik;
use Exception;
-use Piwik\Piwik;
-use Piwik\Common;
use Piwik\Plugins\API\API;
-use Piwik\SegmentExpression;
/**
*
@@ -34,7 +31,7 @@ class Segment
public function __construct($string, $idSites)
{
$string = trim($string);
- if (!Piwik::isSegmentationEnabled()
+ if (!SettingsPiwik::isSegmentationEnabled()
&& !empty($string)
) {
throw new Exception("The Super User has disabled the Segmentation feature.");
diff --git a/core/SettingsPiwik.php b/core/SettingsPiwik.php
new file mode 100644
index 0000000000..8067c8a215
--- /dev/null
+++ b/core/SettingsPiwik.php
@@ -0,0 +1,180 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ * @category Piwik
+ * @package Piwik
+ */
+namespace Piwik;
+
+use Exception;
+
+class SettingsPiwik
+{
+ /**
+ * Get salt from [superuser] section
+ *
+ * @return string
+ */
+ public static function getSalt()
+ {
+ static $salt = null;
+ if (is_null($salt)) {
+ $salt = @Config::getInstance()->superuser['salt'];
+ }
+ return $salt;
+ }
+
+ /**
+ * Should Piwik check that the login & password have minimum length and valid characters?
+ *
+ * @return bool True if checks enabled; false otherwise
+ */
+ public static function isUserCredentialsSanityCheckEnabled()
+ {
+ return Config::getInstance()->General['disable_checks_usernames_attributes'] == 0;
+ }
+
+ /**
+ * Segments to pre-process
+ *
+ * @return string
+ */
+ static public function getKnownSegmentsToArchive()
+ {
+ if (self::$cachedKnownSegmentsToArchive === null) {
+ $segments = Config::getInstance()->Segments;
+ $cachedResult = isset($segments['Segments']) ? $segments['Segments'] : array();
+
+ Piwik_PostEvent('Piwik.getKnownSegmentsToArchiveAllSites', array(&$cachedResult));
+
+ self::$cachedKnownSegmentsToArchive = array_unique($cachedResult);
+ }
+
+ return self::$cachedKnownSegmentsToArchive;
+ }
+
+
+ public static function getKnownSegmentsToArchiveForSite($idSite)
+ {
+ $segments = array();
+ Piwik_PostEvent('Piwik.getKnownSegmentsToArchiveForSite', array(&$segments, $idSite));
+ return $segments;
+ }
+
+ /**
+ * Number of websites to show in the Website selector
+ *
+ * @return int
+ */
+ public static function getWebsitesCountToDisplay()
+ {
+ $count = max(Config::getInstance()->General['site_selector_max_sites'],
+ Config::getInstance()->General['autocomplete_min_sites']);
+ return (int)$count;
+ }
+
+ /**
+ * Returns if logging should work
+ * @return bool
+ */
+ public static function shouldLoggerLog()
+ {
+ try {
+ $shouldLog = (SettingsServer::isPhpCliMode()
+ || Config::getInstance()->log['log_only_when_cli'] == 0)
+ &&
+ (Config::getInstance()->log['log_only_when_debug_parameter'] == 0
+ || isset($_REQUEST['debug']));
+ } catch (Exception $e) {
+ $shouldLog = false;
+ }
+ return $shouldLog;
+ }
+
+ /**
+ * Cache for result of getPiwikUrl.
+ * Can be overwritten for testing purposes only.
+ *
+ * @var string
+ */
+ static public $piwikUrlCache = null;
+
+ /**
+ * Returns the cached the Piwik URL, eg. http://demo.piwik.org/ or http://example.org/piwik/
+ * If not found, then tries to cache it and returns the value.
+ *
+ * If the Piwik URL changes (eg. Piwik moved to new server), the value will automatically be refreshed in the cache.
+ *
+ * @return string
+ */
+ public static function getPiwikUrl()
+ {
+ // Only set in tests
+ if (Piwik::$piwikUrlCache !== null) {
+ return Piwik::$piwikUrlCache;
+ }
+
+ $key = 'piwikUrl';
+ $url = Piwik_GetOption($key);
+ if (SettingsServer::isPhpCliMode()
+ // in case archive.php is triggered with domain localhost
+ || SettingsServer::isArchivePhpTriggered()
+ || defined('PIWIK_MODE_ARCHIVE')
+ ) {
+ return $url;
+ }
+
+ $currentUrl = Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName());
+
+ if (empty($url)
+ // if URL changes, always update the cache
+ || $currentUrl != $url
+ ) {
+ if (strlen($currentUrl) >= strlen('http://a/')) {
+ Piwik_SetOption($key, $currentUrl, $autoLoad = true);
+ }
+ $url = $currentUrl;
+ }
+ return $url;
+ }
+
+ /**
+ * Returns true if Segmentation is allowed for this user
+ *
+ * @return bool
+ */
+ public static function isSegmentationEnabled()
+ {
+ return !Piwik::isUserIsAnonymous()
+ || Config::getInstance()->General['anonymous_user_enable_use_segments_API'];
+ }
+
+ /**
+ * Should we process and display Unique Visitors?
+ * -> Always process for day/week/month periods
+ * For Year and Range, only process if it was enabled in the config file,
+ *
+ * @param string $periodLabel Period label (e.g., 'day')
+ * @return bool
+ */
+ public static function isUniqueVisitorsEnabled($periodLabel)
+ {
+ $generalSettings = Config::getInstance()->General;
+
+ $settingName = "enable_processing_unique_visitors_$periodLabel";
+ $result = !empty($generalSettings[$settingName]) && $generalSettings[$settingName] == 1;
+
+ // check enable_processing_unique_visitors_year_and_range for backwards compatibility
+ if (($periodLabel == 'year' || $periodLabel == 'range')
+ && isset($generalSettings['enable_processing_unique_visitors_year_and_range'])
+ ) {
+ $result |= $generalSettings['enable_processing_unique_visitors_year_and_range'] == 1;
+ }
+
+ return $result;
+ }
+}
diff --git a/core/Timer.php b/core/Timer.php
index c1d17a8020..cddb7cb93f 100644
--- a/core/Timer.php
+++ b/core/Timer.php
@@ -10,8 +10,6 @@
*/
namespace Piwik;
-use Piwik\Piwik;
-
/**
*
* @package Piwik
@@ -61,7 +59,7 @@ class Timer
*/
public function getMemoryLeak()
{
- return "Memory delta: " . Piwik::getPrettySizeFromBytes($this->getMemoryUsage() - $this->memoryStart);
+ return "Memory delta: " . MetricsFormatter::getPrettySizeFromBytes($this->getMemoryUsage() - $this->memoryStart);
}
/**
diff --git a/core/Twig.php b/core/Twig.php
index 09dbe27940..59fabb8a2e 100644
--- a/core/Twig.php
+++ b/core/Twig.php
@@ -11,13 +11,7 @@
namespace Piwik;
use Exception;
-use Piwik\API\Request;
-use Piwik\Piwik;
-use Piwik\Common;
-use Piwik\AssetManager;
use Piwik\Translate;
-use Piwik\Url;
-use Piwik\PluginsManager;
use Piwik\Visualization\Sparkline;
use Twig_Environment;
use Twig_Extension_Debug;
@@ -170,7 +164,7 @@ class Twig
}
$idSite = func_get_args();
$idSite = $idSite[1];
- return Piwik::getPrettyMoney($amount, $idSite);
+ return MetricsFormatter::getPrettyMoney($amount, $idSite);
});
$this->twig->addFilter($moneyFilter);
}
@@ -178,7 +172,7 @@ class Twig
protected function addFilter_sumTime()
{
$sumtimeFilter = new Twig_SimpleFilter('sumtime', function ($numberOfSeconds) {
- return Piwik::getPrettyTimeFromSeconds($numberOfSeconds);
+ return MetricsFormatter::getPrettyTimeFromSeconds($numberOfSeconds);
});
$this->twig->addFilter($sumtimeFilter);
}
diff --git a/core/View.php b/core/View.php
index 910e5b1397..98406e30cc 100644
--- a/core/View.php
+++ b/core/View.php
@@ -99,7 +99,7 @@ class View implements ViewInterface
$userLogin = Piwik::getCurrentUserLogin();
$this->userLogin = $userLogin;
- $count = Piwik::getWebsitesCountToDisplay();
+ $count = SettingsPiwik::getWebsitesCountToDisplay();
$sites = SitesManagerAPI::getInstance()->getSitesWithAtLeastViewAccess($count);
usort($sites, function($site1, $site2) {
diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php
index fd4d171615..5fdd36c32a 100644
--- a/core/ViewDataTable.php
+++ b/core/ViewDataTable.php
@@ -10,21 +10,13 @@
*/
namespace Piwik;
-use Piwik\Config;
-use Piwik\Metrics;
-use Piwik\Period;
use Piwik\API\Request;
-use Piwik\Period\Range;
-use Piwik\Piwik;
-use Piwik\NoAccessException;
-use Piwik\Common;
-use Piwik\Date;
use Piwik\DataTable;
-use Piwik\Url;
-use Piwik\Site;
+use Piwik\Period;
+use Piwik\Period\Range;
+use Piwik\Plugins\API\API;
use Piwik\ViewDataTable\Properties;
use Piwik\ViewDataTable\VisualizationPropertiesProxy;
-use Piwik\Plugins\API\API;
/**
* This class is used to load (from the API) and customize the output of a given DataTable.
@@ -645,7 +637,7 @@ class ViewDataTable
$today = mktime(0, 0, 0);
if ($date->getTimestamp() > $today) {
$elapsedSeconds = time() - $date->getTimestamp();
- $timeAgo = Piwik::getPrettyTimeFromSeconds($elapsedSeconds);
+ $timeAgo = MetricsFormatter::getPrettyTimeFromSeconds($elapsedSeconds);
return Piwik_Translate('CoreHome_ReportGeneratedXAgo', $timeAgo);
}
diff --git a/misc/cron/archive.php b/misc/cron/archive.php
index c8ff067b1c..7b8580dcea 100644
--- a/misc/cron/archive.php
+++ b/misc/cron/archive.php
@@ -153,7 +153,7 @@ class Archiving
// Try and not request older data we know is already archived
if ($this->timeLastCompleted !== false) {
$dateLast = time() - $this->timeLastCompleted;
- $this->log("- Archiving was last executed without error " . Piwik::getPrettyTimeFromSeconds($dateLast, true, $isHtml = false) . " ago");
+ $this->log("- Archiving was last executed without error " . \Piwik\MetricsFormatter::getPrettyTimeFromSeconds($dateLast, true, $isHtml = false) . " ago");
}
$this->initWebsitesToProcess();
@@ -251,7 +251,7 @@ class Archiving
&& $elapsedSinceLastArchiving < $this->todayArchiveTimeToLive
) {
$this->log("Skipped website id $idsite, already processed today's report in recent run, "
- . Piwik::getPrettyTimeFromSeconds($elapsedSinceLastArchiving, true, $isHtml = false)
+ . \Piwik\MetricsFormatter::getPrettyTimeFromSeconds($elapsedSinceLastArchiving, true, $isHtml = false)
. " ago, " . $timerWebsite->__toString());
$skippedDayArchivesWebsites++;
$skipped++;
@@ -405,7 +405,7 @@ class Archiving
private function getSegmentsForSite($idsite)
{
$segmentsAllSites = $this->segments;
- $segmentsThisSite = Piwik::getKnownSegmentsToArchiveForSite($idsite);
+ $segmentsThisSite = \Piwik\SettingsPiwik::getKnownSegmentsToArchiveForSite($idsite);
if (!empty($segmentsThisSite)) {
$this->log("Will pre-process the following " . count($segmentsThisSite) . " Segments for this website (id = $idsite): " . implode(", ", $segmentsThisSite));
}
@@ -731,12 +731,12 @@ class Archiving
if (empty($timestampActiveTraffic)) {
$timestampActiveTraffic = time() - $this->firstRunActiveWebsitesWithTraffic;
$this->log("--force-all-periods was detected: we will process websites with visits in the last "
- . Piwik::getPrettyTimeFromSeconds($this->firstRunActiveWebsitesWithTraffic, true, false)
+ . \Piwik\MetricsFormatter::getPrettyTimeFromSeconds($this->firstRunActiveWebsitesWithTraffic, true, false)
);
}
$this->websites = SitesManagerAPI::getInstance()->getSitesIdWithVisits($timestampActiveTraffic);
$websiteIds = !empty($this->websites) ? ", IDs: " . implode(", ", $this->websites) : "";
- $prettySeconds = Piwik::getPrettyTimeFromSeconds(empty($this->timeLastCompleted)
+ $prettySeconds = \Piwik\MetricsFormatter::getPrettyTimeFromSeconds(empty($this->timeLastCompleted)
? $this->firstRunActiveWebsitesWithTraffic
: (time() - $this->timeLastCompleted),
true, false);
diff --git a/plugins/API/API.php b/plugins/API/API.php
index 19cade72f1..d95ba716fb 100644
--- a/plugins/API/API.php
+++ b/plugins/API/API.php
@@ -20,6 +20,7 @@ use Piwik\Date;
use Piwik\Filesystem;
use Piwik\Metrics;
use Piwik\Piwik;
+use Piwik\SettingsPiwik;
use Piwik\Tracker\GoalManager;
use Piwik\Translate;
use Piwik\Version;
@@ -289,7 +290,7 @@ class API
$logo = 'misc/user/logo.png';
}
if (!$pathOnly) {
- return Piwik::getPiwikUrl() . $logo;
+ return SettingsPiwik::getPiwikUrl() . $logo;
}
return Filesystem::getPathToPiwikRoot() . '/' . $logo;
}
@@ -309,7 +310,7 @@ class API
$logo = 'misc/user/logo-header.png';
}
if (!$pathOnly) {
- return Piwik::getPiwikUrl() . $logo;
+ return SettingsPiwik::getPiwikUrl() . $logo;
}
return Filesystem::getPathToPiwikRoot() . '/' . $logo;
}
@@ -330,7 +331,7 @@ class API
$logo = 'misc/user/logo.svg';
}
if (!$pathOnly) {
- return Piwik::getPiwikUrl() . $logo;
+ return SettingsPiwik::getPiwikUrl() . $logo;
}
return Filesystem::getPathToPiwikRoot() . '/' . $logo;
}
diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php
index 92e82aa275..6926595b6f 100644
--- a/plugins/API/ProcessedReport.php
+++ b/plugins/API/ProcessedReport.php
@@ -12,17 +12,18 @@ namespace Piwik\Plugins\API;
use Exception;
use Piwik\API\Request;
-use Piwik\DataTable\Simple;
+use Piwik\Common;
use Piwik\DataTable\Row;
+use Piwik\DataTable\Simple;
+use Piwik\DataTable;
+use Piwik\Date;
use Piwik\Metrics;
+use Piwik\MetricsFormatter;
use Piwik\Period;
use Piwik\Piwik;
-use Piwik\Common;
-use Piwik\Date;
-use Piwik\DataTable;
-use Piwik\Url;
-use Piwik\Timer;
use Piwik\Site;
+use Piwik\Timer;
+use Piwik\Url;
class ProcessedReport
{
@@ -518,7 +519,7 @@ class ProcessedReport
// filter metrics according to metadata definition
if (isset($metadataColumns[$columnName])) {
// generate 'human readable' metric values
- $prettyValue = Piwik::getPrettyValue($idSite, $columnName, $columnValue, $htmlAllowed = false);
+ $prettyValue = MetricsFormatter::getPrettyValue($idSite, $columnName, $columnValue, $htmlAllowed = false);
$enhancedRow->addColumn($columnName, $prettyValue);
} // For example the Maps Widget requires the raw metrics to do advanced datavis
elseif ($returnRawMetrics) {
diff --git a/plugins/Actions/Actions.php b/plugins/Actions/Actions.php
index bed8cb94a6..4e936bab2f 100644
--- a/plugins/Actions/Actions.php
+++ b/plugins/Actions/Actions.php
@@ -12,14 +12,14 @@ namespace Piwik\Plugins\Actions;
use Piwik\API\Request;
use Piwik\ArchiveProcessor;
-use Piwik\Piwik;
use Piwik\Common;
+use Piwik\Db;
+use Piwik\MetricsFormatter;
+use Piwik\SegmentExpression;
+use Piwik\Site;
use Piwik\Tracker\Action;
use Piwik\ViewDataTable;
use Piwik\WidgetsList;
-use Piwik\SegmentExpression;
-use Piwik\Db;
-use Piwik\Site;
/**
* Actions plugin
@@ -735,12 +735,12 @@ class Actions extends \Piwik\Plugin
);
// prettify avg_time_on_page column
- $getPrettyTimeFromSeconds = '\Piwik\Piwik::getPrettyTimeFromSeconds';
+ $getPrettyTimeFromSeconds = '\Piwik\MetricsFormatter::getPrettyTimeFromSeconds';
$result['filters'][] = array('ColumnCallbackReplace', array('avg_time_on_page', $getPrettyTimeFromSeconds));
// prettify avg_time_generation column
$avgTimeCallback = function ($time) {
- return $time ? Piwik::getPrettyTimeFromSeconds($time, true, true, false) : "-";
+ return $time ? MetricsFormatter::getPrettyTimeFromSeconds($time, true, true, false) : "-";
};
$result['filters'][] = array('ColumnCallbackReplace', array('avg_time_generation', $avgTimeCallback));
@@ -753,8 +753,8 @@ class Actions extends \Piwik\Plugin
return Piwik_Translate("Actions_AvgGenerationTimeTooltip", array(
$hits,
"<br />",
- Piwik::getPrettyTimeFromSeconds($min),
- Piwik::getPrettyTimeFromSeconds($max)
+ MetricsFormatter::getPrettyTimeFromSeconds($min),
+ MetricsFormatter::getPrettyTimeFromSeconds($max)
));
};
$result['filters'][] = array('ColumnCallbackAddMetadata',
diff --git a/plugins/CoreAdminHome/API.php b/plugins/CoreAdminHome/API.php
index 71444288e3..13aff44da3 100644
--- a/plugins/CoreAdminHome/API.php
+++ b/plugins/CoreAdminHome/API.php
@@ -18,6 +18,7 @@ use Piwik\Piwik;
use Piwik\Config;
use Piwik\Common;
use Piwik\Date;
+use Piwik\SettingsPiwik;
use Piwik\TaskScheduler;
use Piwik\Site;
use Piwik\Db;
@@ -54,7 +55,7 @@ class API
public function getKnownSegmentsToArchive()
{
Piwik::checkUserIsSuperUser();
- return Piwik::getKnownSegmentsToArchive();
+ return SettingsPiwik::getKnownSegmentsToArchive();
}
/*
diff --git a/plugins/CoreAdminHome/Controller.php b/plugins/CoreAdminHome/Controller.php
index f8a23c8dc2..e49d412744 100644
--- a/plugins/CoreAdminHome/Controller.php
+++ b/plugins/CoreAdminHome/Controller.php
@@ -13,17 +13,17 @@ namespace Piwik\Plugins\CoreAdminHome;
use Exception;
use Piwik\API\ResponseBuilder;
use Piwik\ArchiveProcessor\Rules;
-use Piwik\Config;
-use Piwik\Piwik;
use Piwik\Common;
+use Piwik\Config;
use Piwik\Nonce;
-use Piwik\Tracker\IgnoreCookie;
-use Piwik\View;
-use Piwik\Url;
-use Piwik\Site;
-use Piwik\Plugins\LanguagesManager\LanguagesManager;
+use Piwik\Piwik;
use Piwik\Plugins\LanguagesManager\API as LanguagesManagerAPI;
+use Piwik\Plugins\LanguagesManager\LanguagesManager;
use Piwik\Plugins\SitesManager\API;
+use Piwik\Site;
+use Piwik\Tracker\IgnoreCookie;
+use Piwik\Url;
+use Piwik\View;
/**
*
@@ -153,7 +153,7 @@ class Controller extends \Piwik\Controller\Admin
$view->idSite = Common::getRequestVar('idSite', $defaultIdSite, 'int');
$view->defaultReportSiteName = Site::getNameFor($view->idSite);
- $view->defaultSiteRevenue = Piwik::getCurrency($view->idSite);
+ $view->defaultSiteRevenue = \Piwik\MetricsFormatter::getCurrencySymbol($view->idSite);
$allUrls = API::getInstance()->getSiteUrlsFromId($view->idSite);
if (isset($allUrls[1])) {
diff --git a/plugins/CoreUpdater/Controller.php b/plugins/CoreUpdater/Controller.php
index 41a94678c4..1112421591 100644
--- a/plugins/CoreUpdater/Controller.php
+++ b/plugins/CoreUpdater/Controller.php
@@ -325,7 +325,7 @@ class Controller extends \Piwik\Controller
}
$this->warningMessages = array_merge($this->warningMessages, array_slice($integrityInfo, 1));
}
- Piwik::deleteAllCacheOnUpdate();
+ Filesystem::deleteAllCacheOnUpdate();
$view->coreError = $this->coreError;
$view->warningMessages = $this->warningMessages;
@@ -339,7 +339,7 @@ class Controller extends \Piwik\Controller
{
$this->loadAndExecuteUpdateFiles($updater, $componentsWithUpdateFile);
- Piwik::deleteAllCacheOnUpdate();
+ Filesystem::deleteAllCacheOnUpdate();
$view->coreError = $this->coreError;
$view->warningMessages = $this->warningMessages;
diff --git a/plugins/CoreUpdater/CoreUpdater.php b/plugins/CoreUpdater/CoreUpdater.php
index 20f3f5c0ae..cb4f2edd1e 100644
--- a/plugins/CoreUpdater/CoreUpdater.php
+++ b/plugins/CoreUpdater/CoreUpdater.php
@@ -11,12 +11,13 @@
namespace Piwik\Plugins\CoreUpdater;
use Exception;
-use Piwik\Piwik;
use Piwik\Common;
+use Piwik\Filesystem;
use Piwik\FrontController;
+use Piwik\Piwik;
+use Piwik\UpdateCheck;
use Piwik\Updater;
use Piwik\Version;
-use Piwik\UpdateCheck;
/**
*
@@ -61,7 +62,7 @@ class CoreUpdater extends \Piwik\Plugin
$updater->addComponentToCheck('core', Version::VERSION);
$updates = $updater->getComponentsWithNewVersion();
if (!empty($updates)) {
- Piwik::deleteAllCacheOnUpdate();
+ Filesystem::deleteAllCacheOnUpdate();
}
if (self::getComponentUpdates($updater) !== null
&& $module != 'CoreUpdater'
diff --git a/plugins/CoreVisualizations/Visualizations/HtmlTable.php b/plugins/CoreVisualizations/Visualizations/HtmlTable.php
index 9ffc3393eb..d5e1f32775 100644
--- a/plugins/CoreVisualizations/Visualizations/HtmlTable.php
+++ b/plugins/CoreVisualizations/Visualizations/HtmlTable.php
@@ -10,15 +10,16 @@
*/
namespace Piwik\Plugins\CoreVisualizations\Visualizations;
-use Piwik\Piwik;
-use Piwik\DataTable;
-use Piwik\View;
-use Piwik\Config;
use Piwik\Common;
-use Piwik\Site;
-use Piwik\DataTableVisualization;
+use Piwik\Config;
+use Piwik\DataTable;
use Piwik\DataTable\Filter\AddColumnsProcessedMetricsGoal;
+use Piwik\DataTableVisualization;
+use Piwik\MetricsFormatter;
+use Piwik\Piwik;
use Piwik\Plugins\Goals\API as Goals_API;
+use Piwik\Site;
+use Piwik\View;
require_once PIWIK_INCLUDE_PATH . '/plugins/CoreVisualizations/Visualizations/HtmlTable/AllColumns.php';
require_once PIWIK_INCLUDE_PATH . '/plugins/CoreVisualizations/Visualizations/HtmlTable/Goals.php';
@@ -188,7 +189,7 @@ class HtmlTable extends DataTableVisualization
$view->columns_to_display = $columnsToDisplay;
};
- $prettifyTime = array('\Piwik\Piwik', 'getPrettyTimeFromSeconds');
+ $prettifyTime = array('\Piwik\MetricsFormatter', 'getPrettyTimeFromSeconds');
$view->filters[] = array('ColumnCallbackReplace', array('avg_time_on_site', $prettifyTime));
$view->show_exclude_low_population = true;
@@ -244,7 +245,7 @@ class HtmlTable extends DataTableVisualization
}
$formatPercent = function ($value) use($idSite) {
- return Piwik::getPrettyMoney(sprintf("%.1f", $value), $idSite);
+ return MetricsFormatter::getPrettyMoney(sprintf("%.1f", $value), $idSite);
};
foreach ($view->columns_to_display as $columnName) {
diff --git a/plugins/DBStats/Controller.php b/plugins/DBStats/Controller.php
index 941b095f81..890fd1d71c 100644
--- a/plugins/DBStats/Controller.php
+++ b/plugins/DBStats/Controller.php
@@ -10,10 +10,10 @@
*/
namespace Piwik\Plugins\DBStats;
+use Piwik\MetricsFormatter;
use Piwik\Piwik;
-use Piwik\Plugins\DBStats\API;
-use Piwik\ViewDataTable;
use Piwik\View;
+use Piwik\ViewDataTable;
/**
* @package DBStats
@@ -40,9 +40,9 @@ class Controller extends \Piwik\Controller\Admin
$view->adminDataSummary = $this->getAdminDataSummary(true);
list($siteCount, $userCount, $totalSpaceUsed) = API::getInstance()->getGeneralInformation();
- $view->siteCount = Piwik::getPrettyNumber($siteCount);
- $view->userCount = Piwik::getPrettyNumber($userCount);
- $view->totalSpaceUsed = Piwik::getPrettySizeFromBytes($totalSpaceUsed);
+ $view->siteCount = MetricsFormatter::getPrettyNumber($siteCount);
+ $view->userCount = MetricsFormatter::getPrettyNumber($userCount);
+ $view->totalSpaceUsed = MetricsFormatter::getPrettySizeFromBytes($totalSpaceUsed);
echo $view->render();
}
diff --git a/plugins/DBStats/DBStats.php b/plugins/DBStats/DBStats.php
index 22e767f360..ba1dca5fbe 100644
--- a/plugins/DBStats/DBStats.php
+++ b/plugins/DBStats/DBStats.php
@@ -332,7 +332,7 @@ class DBStats extends \Piwik\Plugin
}
}
- $getPrettySize = array('\Piwik\Piwik', 'getPrettySizeFromBytes');
+ $getPrettySize = array('\Piwik\MetricsFormatter', 'getPrettySizeFromBytes');
$params = !isset($fixedMemoryUnit) ? array() : array($fixedMemoryUnit);
$properties['filters'][] = array(
'ColumnCallbackReplace', array($sizeColumns, $getPrettySize, $params), $runPrettySizeFilterBeforeGeneric);
@@ -346,7 +346,7 @@ class DBStats extends \Piwik\Plugin
$properties['filters'][] = array('ColumnCallbackReplace', array($sizeColumns, $replaceSpaces));
}
- $getPrettyNumber = array('\Piwik\Piwik', 'getPrettyNumber');
+ $getPrettyNumber = array('\Piwik\MetricsFormatter', 'getPrettyNumber');
$properties['filters'][] = array('ColumnCallbackReplace', array('row_count', $getPrettyNumber));
return $viewDataTable;
diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php
index c0fb1d6c6f..43ef4b1717 100644
--- a/plugins/Goals/Goals.php
+++ b/plugins/Goals/Goals.php
@@ -577,7 +577,7 @@ class Goals extends \Piwik\Plugin
$moneyColumns = array('revenue', 'avg_price');
$prettifyMoneyColumns = array(
- 'ColumnCallbackReplace', array($moneyColumns, '\Piwik\Piwik::getPrettyMoney', array($idSite)));
+ 'ColumnCallbackReplace', array($moneyColumns, '\Piwik\MetricsFormatter::getPrettyMoney', array($idSite)));
$result = array(
'show_ecommerce' => true,
diff --git a/plugins/ImageGraph/Controller.php b/plugins/ImageGraph/Controller.php
index 19925fdc41..ae217dc768 100644
--- a/plugins/ImageGraph/Controller.php
+++ b/plugins/ImageGraph/Controller.php
@@ -10,10 +10,11 @@
*/
namespace Piwik\Plugins\ImageGraph;
-use Piwik\Piwik;
use Piwik\Common;
-use Piwik\View;
+use Piwik\Piwik;
use Piwik\Plugins\API\API;
+use Piwik\SettingsPiwik;
+use Piwik\View;
class Controller extends \Piwik\Controller
{
@@ -33,7 +34,7 @@ class Controller extends \Piwik\Controller
// Title
$report['category'] . ' › ' . $report['name'],
//URL
- Piwik::getPiwikUrl() . $report['imageGraphUrl']
+ SettingsPiwik::getPiwikUrl() . $report['imageGraphUrl']
);
}
}
diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php
index ea1ce67b70..81540f913f 100644
--- a/plugins/Installation/Controller.php
+++ b/plugins/Installation/Controller.php
@@ -103,7 +103,7 @@ class Controller extends \Piwik\Controller\Admin
function welcome($message = false)
{
// Delete merged js/css files to force regenerations based on updated activated plugin list
- Piwik::deleteAllCacheOnUpdate();
+ Filesystem::deleteAllCacheOnUpdate();
$view = new View(
'@Installation/welcome',
diff --git a/plugins/Live/API.php b/plugins/Live/API.php
index 6b2c19aa7f..008c4abc43 100644
--- a/plugins/Live/API.php
+++ b/plugins/Live/API.php
@@ -11,24 +11,23 @@
namespace Piwik\Plugins\Live;
use Exception;
+use Piwik\Common;
use Piwik\Config;
use Piwik\DataAccess\LogAggregator;
use Piwik\DataTable\Filter\ColumnDelete;
use Piwik\DataTable\Row;
+use Piwik\DataTable;
+use Piwik\Date;
+use Piwik\Db;
use Piwik\Period;
use Piwik\Period\Range;
use Piwik\Piwik;
-use Piwik\Common;
-use Piwik\Date;
-use Piwik\DataTable;
-use Piwik\Tracker;
+use Piwik\Plugins\SitesManager\API as SitesManagerAPI;
use Piwik\Segment;
use Piwik\Site;
-use Piwik\Db;
use Piwik\Tracker\Action;
+use Piwik\Tracker;
use Piwik\Tracker\GoalManager;
-use Piwik\Plugins\Live\Visitor;
-use Piwik\Plugins\SitesManager\API as SitesManagerAPI;
/**
* @see plugins/Live/Visitor.php
@@ -283,7 +282,7 @@ class API
'prettyName' => \Piwik\Plugins\UserCountry\continentTranslate($continentCode));
}
- $result['totalVisitDurationPretty'] = Piwik::getPrettyTimeFromSeconds($result['totalVisitDuration']);
+ $result['totalVisitDurationPretty'] = \Piwik\MetricsFormatter::getPrettyTimeFromSeconds($result['totalVisitDuration']);
// use requested visits for first/last visit info
$rows = $visits->getRows();
@@ -813,13 +812,13 @@ class API
// Set the time spent for this action (which is the timeSpentRef of the next action)
if (isset($actionDetails[$actionIdx + 1])) {
$actionDetail['timeSpent'] = $actionDetails[$actionIdx + 1]['timeSpentRef'];
- $actionDetail['timeSpentPretty'] = Piwik::getPrettyTimeFromSeconds($actionDetail['timeSpent']);
+ $actionDetail['timeSpentPretty'] = \Piwik\MetricsFormatter::getPrettyTimeFromSeconds($actionDetail['timeSpent']);
}
unset($actionDetails[$actionIdx]['timeSpentRef']); // not needed after timeSpent is added
// Handle generation time
if ($actionDetail['custom_float'] > 0) {
- $actionDetail['generationTime'] = Piwik::getPrettyTimeFromSeconds($actionDetail['custom_float'] / 1000);
+ $actionDetail['generationTime'] = \Piwik\MetricsFormatter::getPrettyTimeFromSeconds($actionDetail['custom_float'] / 1000);
}
unset($actionDetail['custom_float']);
diff --git a/plugins/Live/Controller.php b/plugins/Live/Controller.php
index dfbb0720c1..ca546b45c8 100644
--- a/plugins/Live/Controller.php
+++ b/plugins/Live/Controller.php
@@ -10,17 +10,16 @@
*/
namespace Piwik\Plugins\Live;
-use Piwik\Url;
use Piwik\API\Request;
use Piwik\Common;
-use Piwik\Piwik;
use Piwik\Config;
-use Piwik\Plugins\Live\API;
-use Piwik\ViewDataTable;
-use Piwik\View;
-use Piwik\FrontController;
-use Piwik\PluginsManager;
+use Piwik\MetricsFormatter;
+use Piwik\Piwik;
use Piwik\Plugins\Goals\API as Goals_API;
+use Piwik\PluginsManager;
+use Piwik\Url;
+use Piwik\View;
+use Piwik\ViewDataTable;
/**
* @package Live
@@ -53,9 +52,9 @@ class Controller extends \Piwik\Controller
$view = new View('@Live/getSimpleLastVisitCount');
$view->lastMinutes = $lastMinutes;
- $view->visitors = Piwik::getPrettyNumber($lastNData[0]['visitors']);
- $view->visits = Piwik::getPrettyNumber($lastNData[0]['visits']);
- $view->actions = Piwik::getPrettyNumber($lastNData[0]['actions']);
+ $view->visitors = MetricsFormatter::getPrettyNumber($lastNData[0]['visitors']);
+ $view->visits = MetricsFormatter::getPrettyNumber($lastNData[0]['visits']);
+ $view->actions = MetricsFormatter::getPrettyNumber($lastNData[0]['actions']);
$view->refreshAfterXSecs = Config::getInstance()->General['live_widget_refresh_after_seconds'];
$view->translations = array(
'one_visitor' => Piwik_Translate('Live_NbVisitor'),
diff --git a/plugins/Live/Visitor.php b/plugins/Live/Visitor.php
index 849521ba3d..70076fd1c3 100644
--- a/plugins/Live/Visitor.php
+++ b/plugins/Live/Visitor.php
@@ -10,14 +10,13 @@
*/
namespace Piwik\Plugins\Live;
-use Piwik\Piwik;
use Piwik\Common;
use Piwik\IP;
-use Piwik\Tracker;
-use Piwik\Tracker\Visit;
use Piwik\Plugins\API\API as MetaAPI;
use Piwik\Plugins\Referers\API as ReferersAPI;
use Piwik\Plugins\UserCountry\LocationProvider\GeoIp;
+use Piwik\Tracker;
+use Piwik\Tracker\Visit;
/**
* @see plugins/Referers/functions.php
@@ -207,7 +206,7 @@ class Visitor
function getVisitLengthPretty()
{
- return Piwik::getPrettyTimeFromSeconds($this->details['visit_total_time']);
+ return \Piwik\MetricsFormatter::getPrettyTimeFromSeconds($this->details['visit_total_time']);
}
function getVisitorReturning()
diff --git a/plugins/Login/Controller.php b/plugins/Login/Controller.php
index ad4e91c1d1..bb6b3fbe6a 100644
--- a/plugins/Login/Controller.php
+++ b/plugins/Login/Controller.php
@@ -23,6 +23,7 @@ use Piwik\Plugins\UsersManager\UsersManager;
use Piwik\ProxyHttp;
use Piwik\QuickForm2;
use Piwik\Session;
+use Piwik\SettingsPiwik;
use Piwik\Url;
use Piwik\View;
@@ -48,7 +49,7 @@ class Controller extends \Piwik\Controller
$passwordLen = strlen($password) / 2;
$hash = Common::hash(
$userInfo . substr($password, 0, $passwordLen)
- . Common::getSalt() . substr($password, $passwordLen)
+ . SettingsPiwik::getSalt() . substr($password, $passwordLen)
);
return $hash;
}
diff --git a/plugins/MultiSites/Controller.php b/plugins/MultiSites/Controller.php
index 56ed2351d4..91ba38bfba 100644
--- a/plugins/MultiSites/Controller.php
+++ b/plugins/MultiSites/Controller.php
@@ -10,15 +10,16 @@
*/
namespace Piwik\Plugins\MultiSites;
-use Piwik\Period;
-use Piwik\Piwik;
use Piwik\Common;
use Piwik\Config;
use Piwik\Date;
+use Piwik\MetricsFormatter;
+use Piwik\Period;
+use Piwik\Piwik;
use Piwik\Plugins\MultiSites\API as MultiSitesAPI;
-use Piwik\View;
-use Piwik\Site;
use Piwik\Plugins\SitesManager\API as SitesManagerAPI;
+use Piwik\Site;
+use Piwik\View;
/**
*
@@ -208,7 +209,7 @@ class Controller extends \Piwik\Controller
foreach ($sites as $idsite => &$site) {
$revenue = "-";
if (!empty($site['revenue'])) {
- $revenue = Piwik::getPrettyMoney($site['revenue'], $site['idsite'], $htmlAllowed = false);
+ $revenue = MetricsFormatter::getPrettyMoney($site['revenue'], $site['idsite'], $htmlAllowed = false);
}
$site['revenue'] = '"' . $revenue . '"';
}
diff --git a/plugins/Overlay/Controller.php b/plugins/Overlay/Controller.php
index 128ba12e6b..86a7fd266d 100644
--- a/plugins/Overlay/Controller.php
+++ b/plugins/Overlay/Controller.php
@@ -14,6 +14,7 @@ use Piwik\API\Request;
use Piwik\Common;
use Piwik\Config;
use Piwik\Metrics;
+use Piwik\MetricsFormatter;
use Piwik\Piwik;
use Piwik\Plugins\Actions\ArchivingHelper;
use Piwik\Plugins\SitesManager\API;
@@ -89,7 +90,7 @@ class Controller extends \Piwik\Controller
continue;
}
if ($metric == 'avg_time_on_page') {
- $value = Piwik::getPrettyTimeFromSeconds($value);
+ $value = MetricsFormatter::getPrettyTimeFromSeconds($value);
}
$data[] = array(
'name' => $translations[$metric],
diff --git a/plugins/PrivacyManager/Controller.php b/plugins/PrivacyManager/Controller.php
index 2be20e059a..ef37f7c969 100644
--- a/plugins/PrivacyManager/Controller.php
+++ b/plugins/PrivacyManager/Controller.php
@@ -14,6 +14,7 @@ use Piwik\Common;
use Piwik\Config;
use Piwik\Date;
use Piwik\Db;
+use Piwik\MetricsFormatter;
use Piwik\Piwik;
use Piwik\Plugins\DBStats\MySQLMetadataProvider;
use Piwik\Plugins\LanguagesManager\LanguagesManager;
@@ -185,7 +186,7 @@ class Controller extends \Piwik\Controller\Admin
}
$result = array(
- 'currentSize' => Piwik::getPrettySizeFromBytes($totalBytes)
+ 'currentSize' => MetricsFormatter::getPrettySizeFromBytes($totalBytes)
);
// if the db size estimate feature is enabled, get the estimate
@@ -212,8 +213,8 @@ class Controller extends \Piwik\Controller\Admin
}
}
- $result['sizeAfterPurge'] = Piwik::getPrettySizeFromBytes($totalAfterPurge);
- $result['spaceSaved'] = Piwik::getPrettySizeFromBytes($totalBytes - $totalAfterPurge);
+ $result['sizeAfterPurge'] = MetricsFormatter::getPrettySizeFromBytes($totalAfterPurge);
+ $result['spaceSaved'] = MetricsFormatter::getPrettySizeFromBytes($totalBytes - $totalAfterPurge);
}
return $result;
@@ -277,7 +278,7 @@ class Controller extends \Piwik\Controller\Admin
}
}
- $deleteDataInfos["nextRunPretty"] = Piwik::getPrettyTimeFromSeconds($deleteDataInfos["nextScheduleTime"] - time());
+ $deleteDataInfos["nextRunPretty"] = MetricsFormatter::getPrettyTimeFromSeconds($deleteDataInfos["nextScheduleTime"] - time());
return $deleteDataInfos;
}
diff --git a/plugins/Referers/Referers.php b/plugins/Referers/Referers.php
index 66a7b853d5..63c4c29160 100644
--- a/plugins/Referers/Referers.php
+++ b/plugins/Referers/Referers.php
@@ -11,9 +11,8 @@
namespace Piwik\Plugins\Referers;
use Piwik\ArchiveProcessor;
-use Piwik\Piwik;
use Piwik\Common;
-use Piwik\Plugins\Referers\Archiver;
+use Piwik\SettingsPiwik;
use Piwik\WidgetsList;
/**
@@ -220,7 +219,7 @@ class Referers extends \Piwik\Plugin
WidgetsList::add('Referers_Referers', 'Referers_WidgetCampaigns', 'Referers', 'getCampaigns');
WidgetsList::add('Referers_Referers', 'Referers_WidgetOverview', 'Referers', 'getRefererType');
WidgetsList::add('Referers_Referers', 'Referers_WidgetGetAll', 'Referers', 'getAll');
- if (Piwik::isSegmentationEnabled()) {
+ if (SettingsPiwik::isSegmentationEnabled()) {
WidgetsList::add('SEO', 'Referers_WidgetTopKeywordsForPages', 'Referers', 'getKeywordsForPage');
}
}
diff --git a/plugins/SEO/RankChecker.php b/plugins/SEO/RankChecker.php
index 74d8afda3b..9584d4bc2a 100644
--- a/plugins/SEO/RankChecker.php
+++ b/plugins/SEO/RankChecker.php
@@ -11,9 +11,9 @@
namespace Piwik\Plugins\SEO;
use Exception;
-use Piwik\Piwik;
use Piwik\Http;
-use Piwik\Plugins\SEO\MajesticClient;
+use Piwik\MetricsFormatter;
+use Piwik\Piwik;
/**
* The functions below are derived/adapted from GetRank.org's
@@ -174,7 +174,7 @@ class RankChecker
}
if ($maxAge) {
- return Piwik::getPrettyTimeFromSeconds(time() - $maxAge);
+ return MetricsFormatter::getPrettyTimeFromSeconds(time() - $maxAge);
}
return false;
}
diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php
index 2dcc54efed..9017a70af2 100644
--- a/plugins/SitesManager/API.php
+++ b/plugins/SitesManager/API.php
@@ -16,7 +16,9 @@ use Piwik\Common;
use Piwik\Date;
use Piwik\Db;
use Piwik\IP;
+use Piwik\MetricsFormatter;
use Piwik\Piwik;
+use Piwik\SettingsPiwik;
use Piwik\SettingsServer;
use Piwik\Site;
use Piwik\TaskScheduler;
@@ -1079,7 +1081,7 @@ class API
*/
public function getCurrencyList()
{
- $currencies = Piwik::getCurrencyList();
+ $currencies = MetricsFormatter::getCurrencyList();
return array_map(function($a) { return $a[1]." (".$a[0].")"; }, $currencies);
}
@@ -1090,7 +1092,7 @@ class API
*/
public function getCurrencySymbols()
{
- $currencies = Piwik::getCurrencyList();
+ $currencies = MetricsFormatter::getCurrencyList();
return array_map(function($a) { return $a[0]; }, $currencies);
}
@@ -1353,7 +1355,7 @@ class API
OR s.main_url like ?
$where )
AND idsite in ($ids_str)
- LIMIT " . Piwik::getWebsitesCountToDisplay(),
+ LIMIT " . SettingsPiwik::getWebsitesCountToDisplay(),
$bind);
return $sites;
}
diff --git a/plugins/UsersManager/UsersManager.php b/plugins/UsersManager/UsersManager.php
index 427f0e4b7e..1b58ee3626 100644
--- a/plugins/UsersManager/UsersManager.php
+++ b/plugins/UsersManager/UsersManager.php
@@ -11,9 +11,9 @@
namespace Piwik\Plugins\UsersManager;
use Exception;
-use Piwik\Piwik;
use Piwik\Option;
-use Piwik\Plugins\UsersManager\API;
+use Piwik\Piwik;
+use Piwik\SettingsPiwik;
/**
* Manage Piwik users
@@ -110,7 +110,7 @@ class UsersManager extends \Piwik\Plugin
*/
public static function isValidPasswordString($input)
{
- if (!Piwik::isChecksEnabled()
+ if (!SettingsPiwik::isUserCredentialsSanityCheckEnabled()
&& !empty($input)
) {
return true;
diff --git a/plugins/VisitsSummary/API.php b/plugins/VisitsSummary/API.php
index 831828b775..a0685029e3 100644
--- a/plugins/VisitsSummary/API.php
+++ b/plugins/VisitsSummary/API.php
@@ -11,7 +11,9 @@
namespace Piwik\Plugins\VisitsSummary;
use Piwik\Archive;
+use Piwik\MetricsFormatter;
use Piwik\Piwik;
+use Piwik\SettingsPiwik;
/**
* VisitsSummary API lets you access the core web analytics metrics (visits, unique visitors,
@@ -108,7 +110,7 @@ class API
'sum_visit_length',
'max_actions'
);
- if (Piwik::isUniqueVisitorsEnabled($period)) {
+ if (SettingsPiwik::isUniqueVisitorsEnabled($period)) {
$columns = array_merge(array('nb_uniq_visitors'), $columns);
}
$columns = array_values($columns);
@@ -163,9 +165,9 @@ class API
$table = $this->getSumVisitsLength($idSite, $period, $date, $segment);
if (is_object($table)) {
$table->filter('ColumnCallbackReplace',
- array('sum_visit_length', '\Piwik\Piwik::getPrettyTimeFromSeconds'));
+ array('sum_visit_length', '\Piwik\MetricsFormatter::getPrettyTimeFromSeconds'));
} else {
- $table = Piwik::getPrettyTimeFromSeconds($table);
+ $table = MetricsFormatter::getPrettyTimeFromSeconds($table);
}
return $table;
}
diff --git a/tests/PHPUnit/Core/PiwikTest.php b/tests/PHPUnit/Core/PiwikTest.php
index 0da18e4fbf..56930f6123 100644
--- a/tests/PHPUnit/Core/PiwikTest.php
+++ b/tests/PHPUnit/Core/PiwikTest.php
@@ -7,6 +7,7 @@
*/
use Piwik\Access;
use Piwik\Filesystem;
+use Piwik\MetricsFormatter;
use Piwik\Piwik;
use Piwik\Plugins\SitesManager\API;
use Piwik\Translate;
@@ -120,8 +121,8 @@ class PiwikTest extends DatabaseTestCase
$sentenceExpected = str_replace(' ', '&nbsp;', $expected[0]);
$numericExpected = $expected[1];
- $this->assertEquals($sentenceExpected, Piwik::getPrettyTimeFromSeconds($seconds, $sentence = true));
- $this->assertEquals($numericExpected, Piwik::getPrettyTimeFromSeconds($seconds, $sentence = false));
+ $this->assertEquals($sentenceExpected, MetricsFormatter::getPrettyTimeFromSeconds($seconds, $sentence = true));
+ $this->assertEquals($numericExpected, MetricsFormatter::getPrettyTimeFromSeconds($seconds, $sentence = false));
Translate::getInstance()->unloadEnglishTranslation();
}
@@ -223,7 +224,7 @@ class PiwikTest extends DatabaseTestCase
$this->assertEquals(
$expected,
- Piwik::getPrettyValue($idsite, $columnName, $value, false, false)
+ MetricsFormatter::getPrettyValue($idsite, $columnName, $value, false, false)
);
Translate::getInstance()->unloadEnglishTranslation();
diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php
index 1e97462fce..c1d7e9e76f 100755
--- a/tests/PHPUnit/IntegrationTestCase.php
+++ b/tests/PHPUnit/IntegrationTestCase.php
@@ -144,7 +144,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
public static function _setUpBeforeClass($dbName = false, $createEmptyDatabase = true, $createConfig = true, $installPlugins = null)
{
try {
- Piwik::$piwikUrlCache = '';
+ \Piwik\SettingsPiwik::$piwikUrlCache = '';
if ($createConfig) {
static::createTestConfig();
@@ -215,7 +215,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
public static function _tearDownAfterClass($dropDatabase = true)
{
- Piwik::$piwikUrlCache = null;
+ \Piwik\SettingsPiwik::$piwikUrlCache = null;
IntegrationTestCase::unloadAllPlugins();
/*
$plugins = \Piwik\PluginsManager::getInstance()->getLoadedPlugins();