From 6e38973acc12e9f7fa2d02edee3f8bbbfdbb9694 Mon Sep 17 00:00:00 2001 From: mattab Date: Sat, 20 Jul 2013 16:49:26 +1200 Subject: Removing extra namespace \Core --- core/API/DataTableGenericFilter.php | 2 +- core/API/DataTableManipulator/LabelFilter.php | 2 +- core/API/DocumentationGenerator.php | 4 +- core/API/Proxy.php | 2 +- core/API/Request.php | 4 +- core/API/ResponseBuilder.php | 4 +- core/Access.php | 4 +- core/Archive.php | 2 +- core/ArchiveProcessor.php | 4 +- core/ArchiveProcessor/Period.php | 5 +- core/ArchiveProcessor/Rules.php | 6 +- core/AssetManager.php | 6 +- core/CacheFile.php | 4 +- core/Common.php | 2963 ++++++++++---------- core/Config.php | 4 +- core/Controller.php | 6 +- core/Controller/Admin.php | 4 +- core/Cookie.php | 2 +- core/DataAccess/ArchiveSelector.php | 4 +- core/DataAccess/ArchiveTableCreator.php | 4 +- core/DataAccess/ArchiveWriter.php | 6 +- core/DataAccess/LogAggregator.php | 2 +- core/DataTable.php | 43 +- .../Filter/AddColumnsProcessedMetricsGoal.php | 2 +- .../Filter/ColumnCallbackAddColumnPercentage.php | 2 +- core/DataTable/Filter/ReplaceColumnNames.php | 2 +- core/DataTable/Manager.php | 4 +- core/DataTable/Renderer.php | 2 +- core/DataTable/Renderer/Csv.php | 4 +- core/DataTable/Renderer/Json.php | 4 +- core/DataTable/Renderer/Php.php | 2 +- core/DataTable/Renderer/Rss.php | 2 +- core/DataTable/Renderer/Xml.php | 2 +- core/Db/Adapter/Mysqli.php | 2 +- core/Db/Adapter/Pdo/Mssql.php | 2 +- core/Db/Adapter/Pdo/Mysql.php | 2 +- core/Db/Adapter/Pdo/Pgsql.php | 2 +- core/Db/Schema.php | 2 +- core/Db/Schema/Myisam.php | 6 +- core/ExceptionHandler.php | 2 +- core/FrontController.php | 9 +- core/Http.php | 6 +- core/IP.php | 4 +- core/Log.php | 6 +- core/Log/Exception.php | 2 +- core/Log/Message.php | 4 +- core/Mail.php | 4 +- core/Menu/Abstract.php | 2 +- core/Menu/Admin.php | 2 +- core/Metrics.php | 2 +- core/Nonce.php | 2 +- core/Option.php | 2 +- core/Period.php | 2 +- core/Period/Range.php | 2 +- core/Piwik.php | 11 +- core/Plugin.php | 2 +- core/Plugin/MetadataLoader.php | 2 +- core/PluginsArchiver.php | 4 +- core/PluginsFunctions/Sql.php | 2 +- core/PluginsManager.php | 6 +- core/ProxyHeaders.php | 2 +- core/ReportRenderer.php | 2 +- core/ReportRenderer/Html.php | 2 +- core/ReportRenderer/Pdf.php | 2 +- core/Segment.php | 4 +- core/Session.php | 6 +- core/Session/Namespace.php | 2 +- core/Timer.php | 2 +- core/Tracker.php | 36 +- core/Tracker/Action.php | 36 +- core/Tracker/Cache.php | 4 +- core/Tracker/Config.php | 2 +- core/Tracker/Db.php | 2 +- core/Tracker/GoalManager.php | 48 +- core/Tracker/IgnoreCookie.php | 2 +- core/Tracker/Referer.php | 2 +- core/Tracker/Request.php | 18 +- core/Tracker/Visit.php | 38 +- core/Tracker/VisitExcluded.php | 22 +- core/Translate.php | 4 +- core/TranslationWriter.php | 2 +- core/Twig.php | 4 +- core/UpdateCheck.php | 4 +- core/Updater.php | 2 +- core/Updates.php | 2 +- core/Updates/0.2.10.php | 4 +- core/Updates/0.2.12.php | 2 +- core/Updates/0.2.13.php | 2 +- core/Updates/0.2.24.php | 2 +- core/Updates/0.2.27.php | 4 +- core/Updates/0.2.32.php | 2 +- core/Updates/0.2.33.php | 4 +- core/Updates/0.2.34.php | 2 +- core/Updates/0.2.35.php | 2 +- core/Updates/0.2.37.php | 2 +- core/Updates/0.4.1.php | 2 +- core/Updates/0.4.2.php | 2 +- core/Updates/0.4.php | 2 +- core/Updates/0.5.4.php | 4 +- core/Updates/0.5.5.php | 4 +- core/Updates/0.5.php | 2 +- core/Updates/0.6-rc1.php | 2 +- core/Updates/0.6.2.php | 2 +- core/Updates/0.6.3.php | 4 +- core/Updates/0.7.php | 2 +- core/Updates/0.9.1.php | 4 +- core/Updates/1.1.php | 4 +- core/Updates/1.10.2-b1.php | 2 +- core/Updates/1.10.2-b2.php | 2 +- core/Updates/1.12-b1.php | 2 +- core/Updates/1.12-b16.php | 2 +- core/Updates/1.2-rc1.php | 2 +- core/Updates/1.2.3.php | 4 +- core/Updates/1.2.5-rc1.php | 2 +- core/Updates/1.2.5-rc7.php | 2 +- core/Updates/1.4-rc1.php | 2 +- core/Updates/1.4-rc2.php | 2 +- core/Updates/1.5-b1.php | 2 +- core/Updates/1.5-b2.php | 2 +- core/Updates/1.5-b3.php | 2 +- core/Updates/1.5-b4.php | 2 +- core/Updates/1.5-b5.php | 2 +- core/Updates/1.6-b1.php | 2 +- core/Updates/1.7-b1.php | 2 +- core/Updates/1.7.2-rc5.php | 2 +- core/Updates/1.7.2-rc7.php | 2 +- core/Updates/1.8.3-b1.php | 2 +- core/Updates/1.8.4-b1.php | 2 +- core/Updates/1.9-b16.php | 2 +- core/Updates/1.9-b19.php | 2 +- core/Updates/1.9-b9.php | 2 +- core/Updates/1.9.1-b2.php | 2 +- core/Updates/1.9.3-b8.php | 2 +- core/Url.php | 6 +- core/View.php | 6 +- core/ViewDataTable.php | 6 +- core/ViewDataTable/GenerateGraphData.php | 4 +- .../GenerateGraphData/ChartEvolution.php | 4 +- core/ViewDataTable/GenerateGraphHTML.php | 4 +- .../GenerateGraphHTML/ChartEvolution.php | 2 +- core/ViewDataTable/HtmlTable.php | 6 +- core/ViewDataTable/HtmlTable/Goals.php | 4 +- core/ViewDataTable/Sparkline.php | 2 +- core/Visualization/Chart.php | 4 +- core/Visualization/Cloud.php | 2 +- js/index.php | 2 +- misc/cron/archive.php | 6 +- misc/others/geoipUpdateRows.php | 6 +- misc/others/iframeWidget_localhost.php | 2 +- ...t_cookies_GenerateHundredsWebsitesAndVisits.php | 4 +- misc/others/test_generateLotsVisitsWebsites.php | 6 +- piwik.php | 8 +- plugins/API/API.php | 11 +- plugins/API/Controller.php | 4 +- plugins/API/ProcessedReport.php | 4 +- plugins/API/RowEvolution.php | 4 +- plugins/Actions/API.php | 4 +- plugins/Actions/Actions.php | 4 +- plugins/Actions/Archiver.php | 2 +- plugins/Actions/ArchivingHelper.php | 2 +- plugins/Annotations/API.php | 2 +- plugins/Annotations/AnnotationList.php | 2 +- plugins/Annotations/Controller.php | 2 +- plugins/AnonymizeIP/AnonymizeIP.php | 4 +- plugins/CoreAdminHome/API.php | 4 +- plugins/CoreAdminHome/Controller.php | 6 +- plugins/CoreAdminHome/CoreAdminHome.php | 2 +- plugins/CoreHome/Controller.php | 4 +- .../DataTableRowAction/MultiRowEvolution.php | 2 +- .../CoreHome/DataTableRowAction/RowEvolution.php | 2 +- plugins/CorePluginsAdmin/Controller.php | 4 +- plugins/CorePluginsAdmin/CorePluginsAdmin.php | 2 +- plugins/CoreUpdater/Controller.php | 6 +- plugins/CoreUpdater/CoreUpdater.php | 4 +- plugins/CustomVariables/Archiver.php | 4 +- plugins/DBStats/API.php | 4 +- plugins/DBStats/Controller.php | 2 +- plugins/DBStats/DBStats.php | 2 +- plugins/DBStats/MySQLMetadataProvider.php | 4 +- plugins/Dashboard/API.php | 2 +- plugins/Dashboard/Controller.php | 4 +- plugins/Dashboard/Dashboard.php | 4 +- plugins/DevicesDetection/API.php | 2 +- plugins/DevicesDetection/Controller.php | 4 +- plugins/DevicesDetection/DevicesDetection.php | 8 +- plugins/DoNotTrack/DoNotTrack.php | 4 +- plugins/ExampleAPI/API.php | 2 +- plugins/ExamplePlugin/Controller.php | 4 +- plugins/ExampleUI/Controller.php | 2 +- plugins/Feedback/Controller.php | 6 +- plugins/Goals/API.php | 4 +- plugins/Goals/Controller.php | 4 +- plugins/Goals/Goals.php | 4 +- plugins/ImageGraph/API.php | 4 +- plugins/ImageGraph/Controller.php | 4 +- plugins/ImageGraph/ImageGraph.php | 2 +- plugins/Installation/Controller.php | 4 +- plugins/Installation/FormDatabaseSetup.php | 4 +- plugins/Installation/FormGeneralSetup.php | 2 +- plugins/Installation/Installation.php | 4 +- plugins/LanguagesManager/API.php | 4 +- plugins/LanguagesManager/Controller.php | 4 +- plugins/LanguagesManager/LanguagesManager.php | 6 +- plugins/Live/API.php | 6 +- plugins/Live/Controller.php | 4 +- plugins/Live/Visitor.php | 4 +- plugins/Login/Auth.php | 4 +- plugins/Login/Controller.php | 6 +- plugins/Login/Login.php | 4 +- plugins/MobileMessaging/API.php | 4 +- plugins/MobileMessaging/Controller.php | 4 +- plugins/MobileMessaging/MobileMessaging.php | 2 +- plugins/MobileMessaging/ReportRenderer/Sms.php | 2 +- plugins/MultiSites/API.php | 4 +- plugins/MultiSites/Controller.php | 5 +- plugins/Overlay/API.php | 4 +- plugins/Overlay/Controller.php | 4 +- plugins/PDFReports/API.php | 4 +- plugins/PDFReports/Controller.php | 4 +- plugins/PDFReports/PDFReports.php | 4 +- plugins/PrivacyManager/Controller.php | 6 +- plugins/PrivacyManager/LogDataPurger.php | 4 +- plugins/PrivacyManager/PrivacyManager.php | 6 +- plugins/PrivacyManager/ReportsPurger.php | 2 +- plugins/Provider/API.php | 2 +- plugins/Provider/Provider.php | 4 +- plugins/Provider/functions.php | 2 +- plugins/Proxy/Controller.php | 4 +- plugins/Referers/API.php | 4 +- plugins/Referers/Archiver.php | 3 +- plugins/Referers/Controller.php | 4 +- plugins/Referers/Referers.php | 2 +- plugins/Referers/functions.php | 2 +- plugins/SEO/API.php | 2 +- plugins/SEO/Controller.php | 2 +- plugins/SEO/MajesticClient.php | 2 +- plugins/SEO/RankChecker.php | 2 +- plugins/SecurityInfo/Controller.php | 2 +- plugins/SecurityInfo/SecurityInfo.php | 2 +- plugins/SegmentEditor/API.php | 4 +- plugins/SegmentEditor/Controller.php | 4 +- plugins/SegmentEditor/SegmentEditor.php | 2 +- plugins/SitesManager/API.php | 4 +- plugins/SitesManager/Controller.php | 4 +- plugins/SitesManager/SitesManager.php | 2 +- plugins/Transitions/API.php | 4 +- plugins/UserCountry/API.php | 2 +- plugins/UserCountry/Controller.php | 4 +- plugins/UserCountry/GeoIPAutoUpdater.php | 4 +- plugins/UserCountry/LocationProvider.php | 2 +- plugins/UserCountry/LocationProvider/Default.php | 4 +- plugins/UserCountry/LocationProvider/GeoIp/Php.php | 2 +- .../LocationProvider/GeoIp/ServerBased.php | 6 +- plugins/UserCountry/UserCountry.php | 10 +- plugins/UserCountryMap/Controller.php | 4 +- plugins/UserSettings/API.php | 2 +- plugins/UserSettings/Archiver.php | 2 +- plugins/UserSettings/functions.php | 2 +- plugins/UsersManager/API.php | 6 +- plugins/UsersManager/Controller.php | 4 +- plugins/UsersManager/UsersManager.php | 2 +- plugins/VisitFrequency/API.php | 2 +- plugins/VisitFrequency/Controller.php | 4 +- plugins/VisitTime/API.php | 2 +- plugins/VisitTime/VisitTime.php | 2 +- plugins/VisitorGenerator/Controller.php | 4 +- plugins/VisitorGenerator/VisitorGenerator.php | 2 +- plugins/VisitorInterest/API.php | 2 +- plugins/VisitsSummary/API.php | 2 +- plugins/VisitsSummary/Controller.php | 4 +- plugins/Widgetize/Controller.php | 2 +- 271 files changed, 2039 insertions(+), 2037 deletions(-) diff --git a/core/API/DataTableGenericFilter.php b/core/API/DataTableGenericFilter.php index 9561c26ee5..22f691c505 100644 --- a/core/API/DataTableGenericFilter.php +++ b/core/API/DataTableGenericFilter.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Piwik diff --git a/core/API/DataTableManipulator/LabelFilter.php b/core/API/DataTableManipulator/LabelFilter.php index 43f43ce056..20ba5b273f 100644 --- a/core/API/DataTableManipulator/LabelFilter.php +++ b/core/API/DataTableManipulator/LabelFilter.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * This class is responsible for handling the label parameter that can be diff --git a/core/API/DocumentationGenerator.php b/core/API/DocumentationGenerator.php index 0f40826e22..76c7b2f156 100644 --- a/core/API/DocumentationGenerator.php +++ b/core/API/DocumentationGenerator.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * @package Piwik diff --git a/core/API/Proxy.php b/core/API/Proxy.php index ae07892e3d..723820e1ee 100644 --- a/core/API/Proxy.php +++ b/core/API/Proxy.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * To differentiate between "no value" and default value of null diff --git a/core/API/Request.php b/core/API/Request.php index 184a566d09..503481f185 100644 --- a/core/API/Request.php +++ b/core/API/Request.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * An API request is the object used to make a call to the API and get the result. diff --git a/core/API/ResponseBuilder.php b/core/API/ResponseBuilder.php index f826319fca..3935f267f7 100644 --- a/core/API/ResponseBuilder.php +++ b/core/API/ResponseBuilder.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * @package Piwik diff --git a/core/Access.php b/core/Access.php index 10f798e937..715b96aae0 100644 --- a/core/Access.php +++ b/core/Access.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; /** * Class to handle User Access: diff --git a/core/Archive.php b/core/Archive.php index 9afd5870f1..3e661b7a9e 100644 --- a/core/Archive.php +++ b/core/Archive.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * The archive object is used to query specific data for a day or a period of statistics for a given website. diff --git a/core/ArchiveProcessor.php b/core/ArchiveProcessor.php index bb42ca1b58..bcbfcc1de2 100644 --- a/core/ArchiveProcessor.php +++ b/core/ArchiveProcessor.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; +use Piwik\Config; +use Piwik\Piwik; /** * The ArchiveProcessor class is used by the Archive object to make sure the given Archive is processed and available in the DB. diff --git a/core/ArchiveProcessor/Period.php b/core/ArchiveProcessor/Period.php index 8a25b5d385..a53182a2af 100644 --- a/core/ArchiveProcessor/Period.php +++ b/core/ArchiveProcessor/Period.php @@ -8,7 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; +use Piwik\Common; /** * This class provides generic methods to archive data for a period (week / month / year). @@ -85,7 +86,7 @@ class Piwik_ArchiveProcessor_Period extends Piwik_ArchiveProcessor $nameToCount[$recordName]['recursive'] = $table->getRowsCountRecursive(); $blob = $table->getSerialized($maximumRowsInDataTableLevelZero, $maximumRowsInSubDataTable, $columnToSortByBeforeTruncation); - destroy($table); + Common::destroy($table); $this->insertBlobRecord($recordName, $blob); } Piwik_DataTable_Manager::getInstance()->deleteAll($latestUsedTableId); diff --git a/core/ArchiveProcessor/Rules.php b/core/ArchiveProcessor/Rules.php index 34abbec536..a4ddd03e35 100644 --- a/core/ArchiveProcessor/Rules.php +++ b/core/ArchiveProcessor/Rules.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * This class contains Archiving rules/logic which are used in several places diff --git a/core/AssetManager.php b/core/AssetManager.php index 1c50f69ce6..322ab4ab20 100644 --- a/core/AssetManager.php +++ b/core/AssetManager.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * @see libs/jsmin/jsmin.php diff --git a/core/CacheFile.php b/core/CacheFile.php index 21dafedf65..7458588dc3 100644 --- a/core/CacheFile.php +++ b/core/CacheFile.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * Code originally inspired from OpenX diff --git a/core/Common.php b/core/Common.php index bad3bf28ed..2f12f3e488 100644 --- a/core/Common.php +++ b/core/Common.php @@ -1,1580 +1,1568 @@ database['tables_prefix']; - return $prefix . $table; - } - - /** - * Returns an array containing the prefixed table names of every passed argument. - * - * @param string ... The table names to prefix, ie "log_visit" - * @return array The prefixed names in an array. - */ - public static function prefixTables() - { - $result = array(); - foreach (func_get_args() as $table) { - $result[] = \Piwik\Core\self::prefixTable($table); - } - return $result; +namespace Piwik; + +use Exception; +use Piwik_IP; +use Piwik_PluginsManager; +use Piwik_Tracker; +use Piwik_Tracker_Cache; +use Piwik_UserCountry_LocationProvider_Default; + +/** + * Static class providing functions used by both the CORE of Piwik and the visitor Tracking engine. + * + * This is the only external class loaded by the /piwik.php file. + * This class should contain only the functions that are used in + * both the CORE and the piwik.php statistics logging engine. + * + * @package Piwik + */ +class Common +{ + const CLASSES_PREFIX = 'Piwik_'; + + /** + * Const used to map the referer type to an integer in the log_visit table + */ + const REFERER_TYPE_DIRECT_ENTRY = 1; + const REFERER_TYPE_SEARCH_ENGINE = 2; + const REFERER_TYPE_WEBSITE = 3; + const REFERER_TYPE_CAMPAIGN = 6; + + /** + * Flag used with htmlspecialchar + * See php.net/htmlspecialchars + */ + const HTML_ENCODING_QUOTE_STYLE = ENT_QUOTES; + + /* + * Database + */ + + /** + * Hashes a string into an integer which should be very low collision risks + * @param string $string String to hash + * @return int Resulting int hash + */ + public static function hashStringToInt($string) + { + $stringHash = substr(md5($string), 0, 8); + return base_convert($stringHash, 16, 10); + } + + public static $cachedTablePrefix = null; + + /** + * Returns the table name prefixed by the table prefix. + * Works in both Tracker and UI mode. + * + * @param string $table The table name to prefix, ie "log_visit" + * @return string The table name prefixed, ie "piwik-production_log_visit" + */ + public static function prefixTable($table) + { + $prefix = Config::getInstance()->database['tables_prefix']; + return $prefix . $table; + } + + /** + * Returns an array containing the prefixed table names of every passed argument. + * + * @param string ... The table names to prefix, ie "log_visit" + * @return array The prefixed names in an array. + */ + public static function prefixTables() + { + $result = array(); + foreach (func_get_args() as $table) { + $result[] = self::prefixTable($table); + } + return $result; + } + + /** + * Returns the table name, after removing the table prefix + * + * @param string $table + * @return string + */ + public static function unprefixTable($table) + { + static $prefixTable = null; + if (is_null($prefixTable)) { + $prefixTable = Config::getInstance()->database['tables_prefix']; + } + if (empty($prefixTable) + || strpos($table, $prefixTable) !== 0 + ) { + return $table; + } + $count = 1; + return str_replace($prefixTable, '', $table, $count); + } + + /* + * Tracker + */ + public static function isGoalPluginEnabled() + { + return Piwik_PluginsManager::getInstance()->isPluginActivated('Goals'); + } + + /* + * URLs + */ + + /** + * Returns the path and query part from a URL. + * Eg. http://piwik.org/test/index.php?module=CoreHome will return /test/index.php?module=CoreHome + * + * @param string $url either http://piwik.org/test or / + * @return string + */ + public static function getPathAndQueryFromUrl($url) + { + $parsedUrl = parse_url($url); + $result = ''; + if (isset($parsedUrl['path'])) { + $result .= substr($parsedUrl['path'], 1); } + if (isset($parsedUrl['query'])) { + $result .= '?' . $parsedUrl['query']; + } + return $result; + } - /** - * Returns the table name, after removing the table prefix - * - * @param string $table - * @return string - */ - public static function unprefixTable($table) - { - static $prefixTable = null; - if (is_null($prefixTable)) { - $prefixTable = Config::getInstance()->database['tables_prefix']; + /** + * Returns the value of a GET parameter $parameter in an URL query $urlQuery + * + * @param string $urlQuery result of parse_url()['query'] and htmlentitied (& is &) eg. module=test&action=toto or ?page=test + * @param string $parameter + * @return string|bool Parameter value if found (can be the empty string!), null if not found + */ + public static function getParameterFromQueryString($urlQuery, $parameter) + { + $nameToValue = self::getArrayFromQueryString($urlQuery); + if (isset($nameToValue[$parameter])) { + return $nameToValue[$parameter]; + } + return null; + } + + /** + * Returns an URL query string in an array format + * + * @param string $urlQuery + * @return array array( param1=> value1, param2=>value2) + */ + public static function getArrayFromQueryString($urlQuery) + { + if (strlen($urlQuery) == 0) { + return array(); + } + if ($urlQuery[0] == '?') { + $urlQuery = substr($urlQuery, 1); + } + $separator = '&'; + + $urlQuery = $separator . $urlQuery; + // $urlQuery = str_replace(array('%20'), ' ', $urlQuery); + $refererQuery = trim($urlQuery); + + $values = explode($separator, $refererQuery); + + $nameToValue = array(); + + foreach ($values as $value) { + $pos = strpos($value, '='); + if ($pos !== false) { + $name = substr($value, 0, $pos); + $value = substr($value, $pos + 1); + if ($value === false) { + $value = ''; + } + } else { + $name = $value; + $value = false; } - if (empty($prefixTable) - || strpos($table, $prefixTable) !== 0 - ) { - return $table; + if (!empty($name)) { + $name = self::sanitizeInputValue($name); } - $count = 1; - return str_replace($prefixTable, '', $table, $count); - } - - /* - * Tracker - */ - public static function isGoalPluginEnabled() - { - return Piwik_PluginsManager::getInstance()->isPluginActivated('Goals'); - } - - /* - * URLs - */ - - /** - * Returns the path and query part from a URL. - * Eg. http://piwik.org/test/index.php?module=CoreHome will return /test/index.php?module=CoreHome - * - * @param string $url either http://piwik.org/test or / - * @return string - */ - public static function getPathAndQueryFromUrl($url) - { - $parsedUrl = parse_url($url); - $result = ''; - if (isset($parsedUrl['path'])) { - $result .= substr($parsedUrl['path'], 1); + if (!empty($value)) { + $value = self::sanitizeInputValue($value); } - if (isset($parsedUrl['query'])) { - $result .= '?' . $parsedUrl['query']; + + // if array without indexes + $count = 0; + $tmp = preg_replace('/(\[|%5b)(]|%5d)$/i', '', $name, -1, $count); + if (!empty($tmp) && $count) { + $name = $tmp; + if (isset($nameToValue[$name]) == false || is_array($nameToValue[$name]) == false) { + $nameToValue[$name] = array(); + } + array_push($nameToValue[$name], $value); + } else if (!empty($name)) { + $nameToValue[$name] = $value; } - return $result; } + return $nameToValue; + } - /** - * Returns the value of a GET parameter $parameter in an URL query $urlQuery - * - * @param string $urlQuery result of parse_url()['query'] and htmlentitied (& is &) eg. module=test&action=toto or ?page=test - * @param string $parameter - * @return string|bool Parameter value if found (can be the empty string!), null if not found - */ - public static function getParameterFromQueryString($urlQuery, $parameter) - { - $nameToValue = \Piwik\Core\self::getArrayFromQueryString($urlQuery); - if (isset($nameToValue[$parameter])) { - return $nameToValue[$parameter]; - } - return null; - } - - /** - * Returns an URL query string in an array format - * - * @param string $urlQuery - * @return array array( param1=> value1, param2=>value2) - */ - public static function getArrayFromQueryString($urlQuery) - { - if (strlen($urlQuery) == 0) { - return array(); + /** + * Builds a URL from the result of parse_url function + * Copied from the PHP comments at http://php.net/parse_url + * @param array $parsed + * @return bool|string + */ + public static function getParseUrlReverse($parsed) + { + if (!is_array($parsed)) { + return false; + } + + $uri = !empty($parsed['scheme']) ? $parsed['scheme'] . ':' . (!strcasecmp($parsed['scheme'], 'mailto') ? '' : '//') : ''; + $uri .= !empty($parsed['user']) ? $parsed['user'] . (!empty($parsed['pass']) ? ':' . $parsed['pass'] : '') . '@' : ''; + $uri .= !empty($parsed['host']) ? $parsed['host'] : ''; + $uri .= !empty($parsed['port']) ? ':' . $parsed['port'] : ''; + + if (!empty($parsed['path'])) { + $uri .= (!strncmp($parsed['path'], '/', 1)) + ? $parsed['path'] + : ((!empty($uri) ? '/' : '') . $parsed['path']); + } + + $uri .= !empty($parsed['query']) ? '?' . $parsed['query'] : ''; + $uri .= !empty($parsed['fragment']) ? '#' . $parsed['fragment'] : ''; + return $uri; + } + + /** + * Returns true if the string passed may be a URL. + * We don't need a precise test here because the value comes from the website + * tracked source code and the URLs may look very strange. + * + * @param string $url + * @return bool + */ + public static function isLookLikeUrl($url) + { + return preg_match('~^(ftp|news|http|https)?://(.*)$~D', $url, $matches) !== 0 + && strlen($matches[2]) > 0; + } + + /* + * File operations + */ + + /** + * ending WITHOUT slash + * + * @return string + */ + public static function getPathToPiwikRoot() + { + return realpath(dirname(__FILE__) . "/.."); + } + + /** + * Create directory if permitted + * + * @param string $path + * @param bool $denyAccess + */ + public static function mkdir($path, $denyAccess = true) + { + if (!is_dir($path)) { + // the mode in mkdir is modified by the current umask + @mkdir($path, $mode = 0755, $recursive = true); + } + + // try to overcome restrictive umask (mis-)configuration + if (!is_writable($path)) { + @chmod($path, 0755); + if (!is_writable($path)) { + @chmod($path, 0775); + + // enough! we're not going to make the directory world-writeable } - if ($urlQuery[0] == '?') { - $urlQuery = substr($urlQuery, 1); + } + + if ($denyAccess) { + self::createHtAccess($path, $overwrite = false); + } + } + + /** + * Create .htaccess file in specified directory + * + * Apache-specific; for IIS @see web.config + * + * @param string $path without trailing slash + * @param bool $overwrite whether to overwrite an existing file or not + * @param string $content + */ + public static function createHtAccess($path, $overwrite = true, $content = "\n\nDeny from all\n\n\n\nDeny from all\n\n\n\nDeny from all\n\n\n") + { + if (self::isApache()) { + $file = $path . '/.htaccess'; + if ($overwrite || !file_exists($file)) { + @file_put_contents($file, $content); } - $separator = '&'; + } + } - $urlQuery = $separator . $urlQuery; - // $urlQuery = str_replace(array('%20'), ' ', $urlQuery); - $refererQuery = trim($urlQuery); + /** + * Get canonicalized absolute path + * See http://php.net/realpath + * + * @param string $path + * @return string canonicalized absolute path + */ + public static function realpath($path) + { + if (file_exists($path)) { + return realpath($path); + } + return $path; + } - $values = explode($separator, $refererQuery); + /** + * Returns true if the string is a valid filename + * File names that start with a-Z or 0-9 and contain a-Z, 0-9, underscore(_), dash(-), and dot(.) will be accepted. + * File names beginning with anything but a-Z or 0-9 will be rejected (including .htaccess for example). + * File names containing anything other than above mentioned will also be rejected (file names with spaces won't be accepted). + * + * @param string $filename + * @return bool + * + */ + public static function isValidFilename($filename) + { + return (0 !== preg_match('/(^[a-zA-Z0-9]+([a-zA-Z_0-9.-]*))$/D', $filename)); + } - $nameToValue = array(); + /* + * String operations + */ - foreach ($values as $value) { - $pos = strpos($value, '='); - if ($pos !== false) { - $name = substr($value, 0, $pos); - $value = substr($value, $pos + 1); - if ($value === false) { - $value = ''; - } - } else { - $name = $value; - $value = false; - } - if (!empty($name)) { - $name = \Piwik\Core\Common::sanitizeInputValue($name); - } - if (!empty($value)) { - $value = \Piwik\Core\Common::sanitizeInputValue($value); + /** + * byte-oriented substr() - ASCII + * + * @param string $string + * @param int $start + * @param int ... optional length + * @return string + */ + public static function substr($string, $start) + { + // in case mbstring overloads substr function + $substr = function_exists('mb_orig_substr') ? 'mb_orig_substr' : 'substr'; + + $length = func_num_args() > 2 + ? func_get_arg(2) + : self::strlen($string); + + return $substr($string, $start, $length); + } + + /** + * byte-oriented strlen() - ASCII + * + * @param string $string + * @return int + */ + public static function strlen($string) + { + // in case mbstring overloads strlen function + $strlen = function_exists('mb_orig_strlen') ? 'mb_orig_strlen' : 'strlen'; + return $strlen($string); + } + + /** + * multi-byte substr() - UTF-8 + * + * @param string $string + * @param int $start + * @param int ... optional length + * @return string + */ + public static function mb_substr($string, $start) + { + $length = func_num_args() > 2 + ? func_get_arg(2) + : self::mb_strlen($string); + + if (function_exists('mb_substr')) { + return mb_substr($string, $start, $length, 'UTF-8'); + } + + return substr($string, $start, $length); + } + + /** + * multi-byte strlen() - UTF-8 + * + * @param string $string + * @return int + */ + public static function mb_strlen($string) + { + if (function_exists('mb_strlen')) { + return mb_strlen($string, 'UTF-8'); + } + + return strlen($string); + } + + /** + * multi-byte strtolower() - UTF-8 + * + * @param string $string + * @return string + */ + public static function mb_strtolower($string) + { + if (function_exists('mb_strtolower')) { + return mb_strtolower($string, 'UTF-8'); + } + + return strtolower($string); + } + + /* + * Escaping input + */ + + /** + * Returns the variable after cleaning operations. + * NB: The variable still has to be escaped before going into a SQL Query! + * + * If an array is passed the cleaning is done recursively on all the sub-arrays. + * The array's keys are filtered as well! + * + * How this method works: + * - The variable returned has been htmlspecialchars to avoid the XSS security problem. + * - The single quotes are not protected so "Piwik's amazing" will still be "Piwik's amazing". + * + * - Transformations are: + * - '&' (ampersand) becomes '&' + * - '"'(double quote) becomes '"' + * - '<' (less than) becomes '<' + * - '>' (greater than) becomes '>' + * - It handles the magic_quotes setting. + * - A non string value is returned without modification + * + * @param mixed $value The variable to be cleaned + * @param bool $alreadyStripslashed + * @throws Exception + * @return mixed The variable after cleaning + */ + public static function sanitizeInputValues($value, $alreadyStripslashed = false) + { + if (is_numeric($value)) { + return $value; + } elseif (is_string($value)) { + $value = self::sanitizeInputValue($value); + + if (!$alreadyStripslashed) // a JSON array was already stripslashed, don't do it again for each value + { + $value = self::undoMagicQuotes($value); + } + } elseif (is_array($value)) { + foreach (array_keys($value) as $key) { + $newKey = $key; + $newKey = self::sanitizeInputValues($newKey, $alreadyStripslashed); + if ($key != $newKey) { + $value[$newKey] = $value[$key]; + unset($value[$key]); } - // if array without indexes - $count = 0; - $tmp = preg_replace('/(\[|%5b)(]|%5d)$/i', '', $name, -1, $count); - if (!empty($tmp) && $count) { - $name = $tmp; - if (isset($nameToValue[$name]) == false || is_array($nameToValue[$name]) == false) { - $nameToValue[$name] = array(); - } - array_push($nameToValue[$name], $value); - } else if (!empty($name)) { - $nameToValue[$name] = $value; + $value[$newKey] = self::sanitizeInputValues($value[$newKey], $alreadyStripslashed); + } + } elseif (!is_null($value) + && !is_bool($value) + ) { + throw new Exception("The value to escape has not a supported type. Value = " . var_export($value, true)); + } + return $value; + } + + /** + * Sanitize a single input value + * + * @param string $value + * @return string sanitized input + */ + public static function sanitizeInputValue($value) + { + // $_GET and $_REQUEST already urldecode()'d + // decode + // note: before php 5.2.7, htmlspecialchars() double encodes &#x hex items + $value = html_entity_decode($value, \Piwik\Common::HTML_ENCODING_QUOTE_STYLE, 'UTF-8'); + + // filter + $value = str_replace(array("\n", "\r", "\0"), '', $value); + + // escape + $tmp = @htmlspecialchars($value, self::HTML_ENCODING_QUOTE_STYLE, 'UTF-8'); + + // note: php 5.2.5 and above, htmlspecialchars is destructive if input is not UTF-8 + if ($value != '' && $tmp == '') { + // convert and escape + $value = utf8_encode($value); + $tmp = htmlspecialchars($value, self::HTML_ENCODING_QUOTE_STYLE, 'UTF-8'); + } + return $tmp; + } + + /** + * Unsanitize a single input value + * + * @param string $value + * @return string unsanitized input + */ + public static function unsanitizeInputValue($value) + { + return htmlspecialchars_decode($value, self::HTML_ENCODING_QUOTE_STYLE); + } + + /** + * Unsanitize one or more values. + * + * @param string|array $value + * @return string|array unsanitized input + */ + public static function unsanitizeInputValues($value) + { + if (is_array($value)) { + $result = array(); + foreach ($value as $key => $arrayValue) { + $result[$key] = self::unsanitizeInputValues($arrayValue); + } + return $result; + } else { + return self::unsanitizeInputValue($value); + } + } + + /** + * Undo the damage caused by magic_quotes; deprecated in php 5.3 but not removed until php 5.4 + * + * @param string + * @return string modified or not + */ + public static function undoMagicQuotes($value) + { + return version_compare(PHP_VERSION, '5.4', '<') + && get_magic_quotes_gpc() + ? stripslashes($value) + : $value; + } + + /** + * Returns a sanitized variable value from the $_GET and $_POST superglobal. + * If the variable doesn't have a value or an empty value, returns the defaultValue if specified. + * If the variable doesn't have neither a value nor a default value provided, an exception is raised. + * + * @see sanitizeInputValues() for the applied sanitization + * + * @param string $varName name of the variable + * @param string $varDefault default value. If '', and if the type doesn't match, exit() ! + * @param string $varType Expected type, the value must be one of the following: array, int, integer, string, json + * @param array $requestArrayToUse + * + * @throws Exception if the variable type is not known + * or if the variable we want to read doesn't have neither a value nor a default value specified + * + * @return mixed The variable after cleaning + */ + public static function getRequestVar($varName, $varDefault = null, $varType = null, $requestArrayToUse = null) + { + if (is_null($requestArrayToUse)) { + $requestArrayToUse = $_GET + $_POST; + } + $varDefault = self::sanitizeInputValues($varDefault); + if ($varType === 'int') { + // settype accepts only integer + // 'int' is simply a shortcut for 'integer' + $varType = 'integer'; + } + + // there is no value $varName in the REQUEST so we try to use the default value + if (empty($varName) + || !isset($requestArrayToUse[$varName]) + || (!is_array($requestArrayToUse[$varName]) + && strlen($requestArrayToUse[$varName]) === 0 + ) + ) { + if (is_null($varDefault)) { + throw new Exception("The parameter '$varName' isn't set in the Request, and a default value wasn't provided."); + } else { + if (!is_null($varType) + && in_array($varType, array('string', 'integer', 'array')) + ) { + settype($varDefault, $varType); } + return $varDefault; } - return $nameToValue; - } - - /** - * Builds a URL from the result of parse_url function - * Copied from the PHP comments at http://php.net/parse_url - * @param array $parsed - * @return bool|string - */ - public static function getParseUrlReverse($parsed) - { - if (!is_array($parsed)) { - return false; + } + + // Normal case, there is a value available in REQUEST for the requested varName: + + // we deal w/ json differently + if ($varType == 'json') { + $value = self::undoMagicQuotes($requestArrayToUse[$varName]); + $value = self::json_decode($value, $assoc = true); + return self::sanitizeInputValues($value, $alreadyStripslashed = true); + } + + $value = self::sanitizeInputValues($requestArrayToUse[$varName]); + if (!is_null($varType)) { + $ok = false; + + if ($varType === 'string') { + if (is_string($value)) $ok = true; + } elseif ($varType === 'integer') { + if ($value == (string)(int)$value) $ok = true; + } elseif ($varType === 'float') { + if ($value == (string)(float)$value) $ok = true; + } elseif ($varType === 'array') { + if (is_array($value)) $ok = true; + } else { + throw new Exception("\$varType specified is not known. It should be one of the following: array, int, integer, float, string"); + } + + // The type is not correct + if ($ok === false) { + if ($varDefault === null) { + throw new Exception("The parameter '$varName' doesn't have a correct type, and a default value wasn't provided."); + } // we return the default value with the good type set + else { + settype($varDefault, $varType); + return $varDefault; + } } + settype($value, $varType); + } + return $value; + } + + /* + * Generating unique strings + */ + + /** + * Returns a 32 characters long uniq ID + * + * @return string 32 chars + */ + public static function generateUniqId() + { + return md5(uniqid(rand(), true)); + } + + /** + * 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 + * @param bool $raw_output + * @return string Hash string + */ + public static function hash($str, $raw_output = false) + { + static $hashAlgorithm = null; + if (is_null($hashAlgorithm)) { + $hashAlgorithm = @Config::getInstance()->General['hash_algorithm']; + } + + if ($hashAlgorithm) { + $hash = @hash($hashAlgorithm, $str, $raw_output); + if ($hash !== false) + return $hash; + } + + return md5($str, $raw_output); + } + + /** + * Generate random string + * + * @param int $length string length + * @param string $alphabet characters allowed in random string + * @return string random string with given length + */ + public static function getRandomString($length = 16, $alphabet = "abcdefghijklmnoprstuvwxyz0123456789") + { + $chars = $alphabet; + $str = ''; + + list($usec, $sec) = explode(" ", microtime()); + $seed = ((float)$sec + (float)$usec) * 100000; + mt_srand($seed); + + for ($i = 0; $i < $length; $i++) { + $rand_key = mt_rand(0, strlen($chars) - 1); + $str .= substr($chars, $rand_key, 1); + } + return str_shuffle($str); + } + + /* + * Conversions + */ + + /** + * Convert hexadecimal representation into binary data. + * !! Will emit warning if input string is not hex!! + * + * @see http://php.net/bin2hex + * + * @param string $str Hexadecimal representation + * @return string + */ + public static function hex2bin($str) + { + return pack("H*", $str); + } + + /** + * This function will convert the input string to the binary representation of the ID + * but it will throw an Exception if the specified input ID is not correct + * + * This is used when building segments containing visitorId which could be an invalid string + * therefore throwing Unexpected PHP error [pack(): Type H: illegal hex digit i] severity [E_WARNING] + * + * It would be simply to silent fail the pack() call above but in all other cases, we don't expect an error, + * so better be safe and get the php error when something unexpected is happening + * @param string $id + * @throws Exception + * @return string binary string + */ + public static function convertVisitorIdToBin($id) + { + if (strlen($id) !== Piwik_Tracker::LENGTH_HEX_ID_STRING + || @bin2hex(self::hex2bin($id)) != $id + ) { + throw new Exception("visitorId is expected to be a " . Piwik_Tracker::LENGTH_HEX_ID_STRING . " hex char string"); + } + return self::hex2bin($id); + } + + /** + * Convert IP address (in network address format) to presentation format. + * This is a backward compatibility function for code that only expects + * IPv4 addresses (i.e., doesn't support IPv6). + * + * @see Piwik_IP::N2P() + * + * This function does not support the long (or its string representation) + * returned by the built-in ip2long() function, from Piwik 1.3 and earlier. + * + * @deprecated 1.4 + * + * @param string $ip IP address in network address format + * @return string + */ + public static function long2ip($ip) + { + return Piwik_IP::long2ip($ip); + } + + /** + * Should we use the replacement json_encode/json_decode functions? + * + * @return bool True if broken; false otherwise + */ + private static function useJsonLibrary() + { + static $useLib; + + if (!isset($useLib)) { + /* + * 5.1.x - doesn't have json extension; we use lib/upgradephp instead + * 5.2 to 5.2.4 - broken in various ways, including: + * + * @see https://bugs.php.net/bug.php?id=38680 'json_decode cannot decode basic types' + * @see https://bugs.php.net/bug.php?id=41403 'json_decode cannot decode floats' + * @see https://bugs.php.net/bug.php?id=42785 'json_encode outputs numbers according to locale' + */ + $useLib = false; + if (version_compare(PHP_VERSION, '5.2.1') < 0) { + $useLib = true; + } else if (version_compare(PHP_VERSION, '5.2.5') < 0) { + $info = localeconv(); + $useLib = $info['decimal_point'] != '.'; + } + } + + return $useLib; + } + + /** + * JSON encode wrapper + * - missing or broken in some php 5.x versions + * + * @param mixed $value + * @return string + */ + public static function json_encode($value) + { + if (self::useJsonLibrary()) { + return _json_encode($value); + } + + return @json_encode($value); + } + + /** + * JSON decode wrapper + * - missing or broken in some php 5.x versions + * + * @param string $json + * @param bool $assoc + * @return mixed + */ + public static function json_decode($json, $assoc = false) + { + if (self::useJsonLibrary()) { + return _json_decode($json, $assoc); + } + + return json_decode($json, $assoc); + } + + /* + * DataFiles + */ + + /** + * Returns list of continent codes + * + * @see core/DataFiles/Countries.php + * + * @return array Array of 3 letter continent codes + */ + public static function getContinentsList() + { + require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php'; + + $continentsList = $GLOBALS['Piwik_ContinentList']; + return $continentsList; + } + + /** + * Returns list of valid country codes + * + * @see core/DataFiles/Countries.php + * + * @param bool $includeInternalCodes + * @return array Array of (2 letter ISO codes => 3 letter continent code) + */ + public static function getCountriesList($includeInternalCodes = false) + { + require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php'; + + $countriesList = $GLOBALS['Piwik_CountryList']; + $extras = $GLOBALS['Piwik_CountryList_Extras']; + + if ($includeInternalCodes) { + return array_merge($countriesList, $extras); + } + return $countriesList; + } + + /** + * Returns list of valid language codes + * + * @see core/DataFiles/Languages.php + * + * @return array Array of 2 letter ISO codes => Language name (in English) + */ + public static function getLanguagesList() + { + require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Languages.php'; + + $languagesList = $GLOBALS['Piwik_LanguageList']; + return $languagesList; + } + + /** + * Returns list of language to country mappings + * + * @see core/DataFiles/LanguageToCountry.php + * + * @return array Array of ( 2 letter ISO language codes => 2 letter ISO country codes ) + */ + public static function getLanguageToCountryList() + { + require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/LanguageToCountry.php'; + + $languagesList = $GLOBALS['Piwik_LanguageToCountry']; + return $languagesList; + } + + /** + * Returns list of search engines by URL + * + * @see core/DataFiles/SearchEngines.php + * + * @return array Array of ( URL => array( searchEngineName, keywordParameter, path, charset ) ) + */ + public static function getSearchEngineUrls() + { + require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/SearchEngines.php'; + + $searchEngines = $GLOBALS['Piwik_SearchEngines']; + return $searchEngines; + } + + /** + * Returns list of search engines by name + * + * @see core/DataFiles/SearchEngines.php + * + * @return array Array of ( searchEngineName => URL ) + */ + public static function getSearchEngineNames() + { + require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/SearchEngines.php'; + + $searchEngines = $GLOBALS['Piwik_SearchEngines_NameToUrl']; + return $searchEngines; + } + + /** + * Returns list of provider names + * + * @see core/DataFiles/Providers.php + * + * @return array Array of ( dnsName => providerName ) + */ + public static function getProviderNames() + { + require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Providers.php'; + + $providers = $GLOBALS['Piwik_ProviderNames']; + return $providers; + } + + /* + * Language, country, continent + */ - $uri = !empty($parsed['scheme']) ? $parsed['scheme'] . ':' . (!strcasecmp($parsed['scheme'], 'mailto') ? '' : '//') : ''; - $uri .= !empty($parsed['user']) ? $parsed['user'] . (!empty($parsed['pass']) ? ':' . $parsed['pass'] : '') . '@' : ''; - $uri .= !empty($parsed['host']) ? $parsed['host'] : ''; - $uri .= !empty($parsed['port']) ? ':' . $parsed['port'] : ''; + /** + * Returns the browser language code, eg. "en-gb,en;q=0.5" + * + * @param string|null $browserLang Optional browser language, otherwise taken from the request header + * @return string + */ + public static function getBrowserLanguage($browserLang = NULL) + { + static $replacementPatterns = array( + // extraneous bits of RFC 3282 that we ignore + '/(\\\\.)/', // quoted-pairs + '/(\s+)/', // CFWcS white space + '/(\([^)]*\))/', // CFWS comments + '/(;q=[0-9.]+)/', // quality - if (!empty($parsed['path'])) { - $uri .= (!strncmp($parsed['path'], '/', 1)) - ? $parsed['path'] - : ((!empty($uri) ? '/' : '') . $parsed['path']); - } + // found in the LANG environment variable + '/\.(.*)/', // charset (e.g., en_CA.UTF-8) + '/^C$/', // POSIX 'C' locale + ); - $uri .= !empty($parsed['query']) ? '?' . $parsed['query'] : ''; - $uri .= !empty($parsed['fragment']) ? '#' . $parsed['fragment'] : ''; - return $uri; - } - - /** - * Returns true if the string passed may be a URL. - * We don't need a precise test here because the value comes from the website - * tracked source code and the URLs may look very strange. - * - * @param string $url - * @return bool - */ - public static function isLookLikeUrl($url) - { - return preg_match('~^(ftp|news|http|https)?://(.*)$~D', $url, $matches) !== 0 - && strlen($matches[2]) > 0; - } - - /* - * File operations - */ - - /** - * ending WITHOUT slash - * - * @return string - */ - public static function getPathToPiwikRoot() - { - return realpath(dirname(__FILE__) . "/.."); - } - - /** - * Create directory if permitted - * - * @param string $path - * @param bool $denyAccess - */ - public static function mkdir($path, $denyAccess = true) - { - if (!is_dir($path)) { - // the mode in mkdir is modified by the current umask - @mkdir($path, $mode = 0755, $recursive = true); + if (is_null($browserLang)) { + $browserLang = self::sanitizeInputValues(@$_SERVER['HTTP_ACCEPT_LANGUAGE']); + if (empty($browserLang) && self::isPhpCliMode()) { + $browserLang = @getenv('LANG'); } + } - // try to overcome restrictive umask (mis-)configuration - if (!is_writable($path)) { - @chmod($path, 0755); - if (!is_writable($path)) { - @chmod($path, 0775); + if (is_null($browserLang)) { + // a fallback might be to infer the language in HTTP_USER_AGENT (i.e., localized build) + $browserLang = ""; + } else { + // language tags are case-insensitive per HTTP/1.1 s3.10 but the region may be capitalized per ISO3166-1; + // underscores are not permitted per RFC 4646 or 4647 (which obsolete RFC 1766 and 3066), + // but we guard against a bad user agent which naively uses its locale + $browserLang = strtolower(str_replace('_', '-', $browserLang)); - // enough! we're not going to make the directory world-writeable - } - } + // filters + $browserLang = preg_replace($replacementPatterns, '', $browserLang); - if ($denyAccess) { - \Piwik\Core\self::createHtAccess($path, $overwrite = false); - } - } + $browserLang = preg_replace('/((^|,)chrome:.*)/', '', $browserLang, 1); // Firefox bug + $browserLang = preg_replace('/(,)(?:en-securid,)|(?:(^|,)en-securid(,|$))/', '$1', $browserLang, 1); // unregistered language tag - /** - * Create .htaccess file in specified directory - * - * Apache-specific; for IIS @see web.config - * - * @param string $path without trailing slash - * @param bool $overwrite whether to overwrite an existing file or not - * @param string $content - */ - public static function createHtAccess($path, $overwrite = true, $content = "\n\nDeny from all\n\n\n\nDeny from all\n\n\n\nDeny from all\n\n\n") - { - if (\Piwik\Core\self::isApache()) { - $file = $path . '/.htaccess'; - if ($overwrite || !file_exists($file)) { - @file_put_contents($file, $content); - } - } + $browserLang = str_replace('sr-sp', 'sr-rs', $browserLang); // unofficial (proposed) code in the wild } - /** - * Get canonicalized absolute path - * See http://php.net/realpath - * - * @param string $path - * @return string canonicalized absolute path - */ - public static function realpath($path) - { - if (file_exists($path)) { - return realpath($path); - } - return $path; - } - - /** - * Returns true if the string is a valid filename - * File names that start with a-Z or 0-9 and contain a-Z, 0-9, underscore(_), dash(-), and dot(.) will be accepted. - * File names beginning with anything but a-Z or 0-9 will be rejected (including .htaccess for example). - * File names containing anything other than above mentioned will also be rejected (file names with spaces won't be accepted). - * - * @param string $filename - * @return bool - * - */ - public static function isValidFilename($filename) - { - return (0 !== preg_match('/(^[a-zA-Z0-9]+([a-zA-Z_0-9.-]*))$/D', $filename)); - } - - /* - * String operations - */ - - /** - * byte-oriented substr() - ASCII - * - * @param string $string - * @param int $start - * @param int ... optional length - * @return string - */ - public static function substr($string, $start) - { - // in case mbstring overloads substr function - $substr = function_exists('mb_orig_substr') ? 'mb_orig_substr' : 'substr'; - - $length = func_num_args() > 2 - ? func_get_arg(2) - : \Piwik\Core\self::strlen($string); - - return $substr($string, $start, $length); - } - - /** - * byte-oriented strlen() - ASCII - * - * @param string $string - * @return int - */ - public static function strlen($string) - { - // in case mbstring overloads strlen function - $strlen = function_exists('mb_orig_strlen') ? 'mb_orig_strlen' : 'strlen'; - return $strlen($string); - } - - /** - * multi-byte substr() - UTF-8 - * - * @param string $string - * @param int $start - * @param int ... optional length - * @return string - */ - public static function mb_substr($string, $start) - { - $length = func_num_args() > 2 - ? func_get_arg(2) - : \Piwik\Core\self::mb_strlen($string); - - if (function_exists('mb_substr')) { - return mb_substr($string, $start, $length, 'UTF-8'); - } + return $browserLang; + } - return substr($string, $start, $length); + /** + * Returns the visitor country based on the Browser 'accepted language' + * information, but provides a hook for geolocation via IP address. + * + * @param string $lang browser lang + * @param bool $enableLanguageToCountryGuess If set to true, some assumption will be made and detection guessed more often, but accuracy could be affected + * @param string $ip + * @return string 2 letter ISO code + */ + public static function getCountry($lang, $enableLanguageToCountryGuess, $ip) + { + $country = null; + Piwik_PostEvent('Common.getCountry', array(&$country, $ip)); + if (!empty($country)) { + return strtolower($country); } - /** - * multi-byte strlen() - UTF-8 - * - * @param string $string - * @return int - */ - public static function mb_strlen($string) - { - if (function_exists('mb_strlen')) { - return mb_strlen($string, 'UTF-8'); - } - - return strlen($string); + if (empty($lang) || strlen($lang) < 2 || $lang == 'xx') { + return 'xx'; } - /** - * multi-byte strtolower() - UTF-8 - * - * @param string $string - * @return string - */ - public static function mb_strtolower($string) - { - if (function_exists('mb_strtolower')) { - return mb_strtolower($string, 'UTF-8'); - } + $validCountries = self::getCountriesList(); + return self::extractCountryCodeFromBrowserLanguage($lang, $validCountries, $enableLanguageToCountryGuess); + } - return strtolower($string); - } - - /* - * Escaping input - */ - - /** - * Returns the variable after cleaning operations. - * NB: The variable still has to be escaped before going into a SQL Query! - * - * If an array is passed the cleaning is done recursively on all the sub-arrays. - * The array's keys are filtered as well! - * - * How this method works: - * - The variable returned has been htmlspecialchars to avoid the XSS security problem. - * - The single quotes are not protected so "Piwik's amazing" will still be "Piwik's amazing". - * - * - Transformations are: - * - '&' (ampersand) becomes '&' - * - '"'(double quote) becomes '"' - * - '<' (less than) becomes '<' - * - '>' (greater than) becomes '>' - * - It handles the magic_quotes setting. - * - A non string value is returned without modification - * - * @param mixed $value The variable to be cleaned - * @param bool $alreadyStripslashed - * @throws Exception - * @return mixed The variable after cleaning - */ - public static function sanitizeInputValues($value, $alreadyStripslashed = false) - { - if (is_numeric($value)) { - return $value; - } elseif (is_string($value)) { - $value = \Piwik\Core\self::sanitizeInputValue($value); - - if (!$alreadyStripslashed) // a JSON array was already stripslashed, don't do it again for each value - { - $value = \Piwik\Core\self::undoMagicQuotes($value); - } - } elseif (is_array($value)) { - foreach (array_keys($value) as $key) { - $newKey = $key; - $newKey = \Piwik\Core\self::sanitizeInputValues($newKey, $alreadyStripslashed); - if ($key != $newKey) { - $value[$newKey] = $value[$key]; - unset($value[$key]); - } + /** + * Returns list of valid country codes + * + * @param string $browserLanguage + * @param array $validCountries Array of valid countries + * @param bool $enableLanguageToCountryGuess (if true, will guess country based on language that lacks region information) + * @return array Array of 2 letter ISO codes + */ + public static function extractCountryCodeFromBrowserLanguage($browserLanguage, $validCountries, $enableLanguageToCountryGuess) + { + $langToCountry = self::getLanguageToCountryList(); - $value[$newKey] = \Piwik\Core\self::sanitizeInputValues($value[$newKey], $alreadyStripslashed); + if ($enableLanguageToCountryGuess) { + if (preg_match('/^([a-z]{2,3})(?:,|;|$)/', $browserLanguage, $matches)) { + // match language (without region) to infer the country of origin + if (array_key_exists($matches[1], $langToCountry)) { + return $langToCountry[$matches[1]]; } - } elseif (!is_null($value) - && !is_bool($value) - ) { - throw new Exception("The value to escape has not a supported type. Value = " . var_export($value, true)); } - return $value; } - /** - * Sanitize a single input value - * - * @param string $value - * @return string sanitized input - */ - public static function sanitizeInputValue($value) - { - // $_GET and $_REQUEST already urldecode()'d - // decode - // note: before php 5.2.7, htmlspecialchars() double encodes &#x hex items - $value = html_entity_decode($value, \Piwik\Core\Common::HTML_ENCODING_QUOTE_STYLE, 'UTF-8'); - - // filter - $value = str_replace(array("\n", "\r", "\0"), '', $value); - - // escape - $tmp = @htmlspecialchars($value, \Piwik\Core\self::HTML_ENCODING_QUOTE_STYLE, 'UTF-8'); - - // note: php 5.2.5 and above, htmlspecialchars is destructive if input is not UTF-8 - if ($value != '' && $tmp == '') { - // convert and escape - $value = utf8_encode($value); - $tmp = htmlspecialchars($value, \Piwik\Core\self::HTML_ENCODING_QUOTE_STYLE, 'UTF-8'); - } - return $tmp; - } - - /** - * Unsanitize a single input value - * - * @param string $value - * @return string unsanitized input - */ - public static function unsanitizeInputValue($value) - { - return htmlspecialchars_decode($value, \Piwik\Core\self::HTML_ENCODING_QUOTE_STYLE); - } - - /** - * Unsanitize one or more values. - * - * @param string|array $value - * @return string|array unsanitized input - */ - public static function unsanitizeInputValues($value) - { - if (is_array($value)) { - $result = array(); - foreach ($value as $key => $arrayValue) { - $result[$key] = \Piwik\Core\self::unsanitizeInputValues($arrayValue); + if (!empty($validCountries) && preg_match_all('/[-]([a-z]{2})/', $browserLanguage, $matches, PREG_SET_ORDER)) { + foreach ($matches as $parts) { + // match location; we don't make any inferences from the language + if (array_key_exists($parts[1], $validCountries)) { + return $parts[1]; } - return $result; - } else { - return \Piwik\Core\self::unsanitizeInputValue($value); } } + return 'xx'; + } - /** - * Undo the damage caused by magic_quotes; deprecated in php 5.3 but not removed until php 5.4 - * - * @param string - * @return string modified or not - */ - public static function undoMagicQuotes($value) - { - return version_compare(PHP_VERSION, '5.4', '<') - && get_magic_quotes_gpc() - ? stripslashes($value) - : $value; - } - - /** - * Returns a sanitized variable value from the $_GET and $_POST superglobal. - * If the variable doesn't have a value or an empty value, returns the defaultValue if specified. - * If the variable doesn't have neither a value nor a default value provided, an exception is raised. - * - * @see sanitizeInputValues() for the applied sanitization - * - * @param string $varName name of the variable - * @param string $varDefault default value. If '', and if the type doesn't match, exit() ! - * @param string $varType Expected type, the value must be one of the following: array, int, integer, string, json - * @param array $requestArrayToUse - * - * @throws Exception if the variable type is not known - * or if the variable we want to read doesn't have neither a value nor a default value specified - * - * @return mixed The variable after cleaning - */ - public static function getRequestVar($varName, $varDefault = null, $varType = null, $requestArrayToUse = null) - { - if (is_null($requestArrayToUse)) { - $requestArrayToUse = $_GET + $_POST; - } - $varDefault = \Piwik\Core\self::sanitizeInputValues($varDefault); - if ($varType === 'int') { - // settype accepts only integer - // 'int' is simply a shortcut for 'integer' - $varType = 'integer'; - } - - // there is no value $varName in the REQUEST so we try to use the default value - if (empty($varName) - || !isset($requestArrayToUse[$varName]) - || (!is_array($requestArrayToUse[$varName]) - && strlen($requestArrayToUse[$varName]) === 0 - ) - ) { - if (is_null($varDefault)) { - throw new Exception("The parameter '$varName' isn't set in the Request, and a default value wasn't provided."); - } else { - if (!is_null($varType) - && in_array($varType, array('string', 'integer', 'array')) - ) { - settype($varDefault, $varType); + /** + * Returns the visitor language based only on the Browser 'accepted language' information + * + * @param string $browserLanguage Browser's accepted langauge header + * @param array $validLanguages array of valid language codes + * @return string 2 letter ISO 639 code + */ + public static function extractLanguageCodeFromBrowserLanguage($browserLanguage, $validLanguages) + { + // assumes language preference is sorted; + // does not handle language-script-region tags or language range (*) + if (!empty($validLanguages) && preg_match_all('/(?:^|,)([a-z]{2,3})([-][a-z]{2})?/', $browserLanguage, $matches, PREG_SET_ORDER)) { + foreach ($matches as $parts) { + if (count($parts) == 3) { + // match locale (language and location) + if (in_array($parts[1] . $parts[2], $validLanguages)) { + return $parts[1] . $parts[2]; } - return $varDefault; - } - } - - // Normal case, there is a value available in REQUEST for the requested varName: - - // we deal w/ json differently - if ($varType == 'json') { - $value = \Piwik\Core\self::undoMagicQuotes($requestArrayToUse[$varName]); - $value = \Piwik\Core\Common::json_decode($value, $assoc = true); - return \Piwik\Core\self::sanitizeInputValues($value, $alreadyStripslashed = true); - } - - $value = \Piwik\Core\self::sanitizeInputValues($requestArrayToUse[$varName]); - if (!is_null($varType)) { - $ok = false; - - if ($varType === 'string') { - if (is_string($value)) $ok = true; - } elseif ($varType === 'integer') { - if ($value == (string)(int)$value) $ok = true; - } elseif ($varType === 'float') { - if ($value == (string)(float)$value) $ok = true; - } elseif ($varType === 'array') { - if (is_array($value)) $ok = true; - } else { - throw new Exception("\$varType specified is not known. It should be one of the following: array, int, integer, float, string"); } - - // The type is not correct - if ($ok === false) { - if ($varDefault === null) { - throw new Exception("The parameter '$varName' doesn't have a correct type, and a default value wasn't provided."); - } // we return the default value with the good type set - else { - settype($varDefault, $varType); - return $varDefault; - } + // match language only (where no region provided) + if (in_array($parts[1], $validLanguages)) { + return $parts[1]; } - settype($value, $varType); } - return $value; } + return 'xx'; + } - /* - * Generating unique strings - */ - - /** - * Returns a 32 characters long uniq ID - * - * @return string 32 chars - */ - public static function generateUniqId() - { - return md5(uniqid(rand(), true)); - } - - /** - * 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 - * @param bool $raw_output - * @return string Hash string - */ - public static function hash($str, $raw_output = false) - { - static $hashAlgorithm = null; - if (is_null($hashAlgorithm)) { - $hashAlgorithm = @Config::getInstance()->General['hash_algorithm']; - } - - if ($hashAlgorithm) { - $hash = @hash($hashAlgorithm, $str, $raw_output); - if ($hash !== false) - return $hash; - } - - return md5($str, $raw_output); + /** + * Returns the continent of a given country + * + * @param string $country 2 letters isocode + * + * @return string Continent (3 letters code : afr, asi, eur, amn, ams, oce) + */ + public static function getContinent($country) + { + $countryList = self::getCountriesList(); + if (isset($countryList[$country])) { + return $countryList[$country]; } + return 'unk'; + } - /** - * Generate random string - * - * @param int $length string length - * @param string $alphabet characters allowed in random string - * @return string random string with given length - */ - public static function getRandomString($length = 16, $alphabet = "abcdefghijklmnoprstuvwxyz0123456789") - { - $chars = $alphabet; - $str = ''; - - list($usec, $sec) = explode(" ", microtime()); - $seed = ((float)$sec + (float)$usec) * 100000; - mt_srand($seed); + /* + * Campaign + */ - for ($i = 0; $i < $length; $i++) { - $rand_key = mt_rand(0, strlen($chars) - 1); - $str .= substr($chars, $rand_key, 1); - } - return str_shuffle($str); - } - - /* - * Conversions - */ - - /** - * Convert hexadecimal representation into binary data. - * !! Will emit warning if input string is not hex!! - * - * @see http://php.net/bin2hex - * - * @param string $str Hexadecimal representation - * @return string - */ - public static function hex2bin($str) - { - return pack("H*", $str); - } - - /** - * This function will convert the input string to the binary representation of the ID - * but it will throw an Exception if the specified input ID is not correct - * - * This is used when building segments containing visitorId which could be an invalid string - * therefore throwing Unexpected PHP error [pack(): Type H: illegal hex digit i] severity [E_WARNING] - * - * It would be simply to silent fail the pack() call above but in all other cases, we don't expect an error, - * so better be safe and get the php error when something unexpected is happening - * @param string $id - * @throws Exception - * @return string binary string - */ - public static function convertVisitorIdToBin($id) - { - if (strlen($id) !== Piwik_Tracker::LENGTH_HEX_ID_STRING - || @bin2hex(\Piwik\Core\self::hex2bin($id)) != $id - ) { - throw new Exception("visitorId is expected to be a " . Piwik_Tracker::LENGTH_HEX_ID_STRING . " hex char string"); - } - return \Piwik\Core\self::hex2bin($id); - } - - /** - * Convert IP address (in network address format) to presentation format. - * This is a backward compatibility function for code that only expects - * IPv4 addresses (i.e., doesn't support IPv6). - * - * @see Piwik_IP::N2P() - * - * This function does not support the long (or its string representation) - * returned by the built-in ip2long() function, from Piwik 1.3 and earlier. - * - * @deprecated 1.4 - * - * @param string $ip IP address in network address format - * @return string - */ - public static function long2ip($ip) - { - return Piwik_IP::long2ip($ip); - } - - /** - * Should we use the replacement json_encode/json_decode functions? - * - * @return bool True if broken; false otherwise - */ - private static function useJsonLibrary() - { - static $useLib; - - if (!isset($useLib)) { - /* - * 5.1.x - doesn't have json extension; we use lib/upgradephp instead - * 5.2 to 5.2.4 - broken in various ways, including: - * - * @see https://bugs.php.net/bug.php?id=38680 'json_decode cannot decode basic types' - * @see https://bugs.php.net/bug.php?id=41403 'json_decode cannot decode floats' - * @see https://bugs.php.net/bug.php?id=42785 'json_encode outputs numbers according to locale' - */ - $useLib = false; - if (version_compare(PHP_VERSION, '5.2.1') < 0) { - $useLib = true; - } else if (version_compare(PHP_VERSION, '5.2.5') < 0) { - $info = localeconv(); - $useLib = $info['decimal_point'] != '.'; - } + /** + * Returns the list of Campaign parameter names that will be read to classify + * a visit as coming from a Campaign + * + * @return array array( + * 0 => array( ... ) // campaign names parameters + * 1 => array( ... ) // campaign keyword parameters + * ); + */ + public static function getCampaignParameters() + { + $return = array( + Config::getInstance()->Tracker['campaign_var_name'], + Config::getInstance()->Tracker['campaign_keyword_var_name'], + ); + + foreach ($return as &$list) { + if (strpos($list, ',') !== false) { + $list = explode(',', $list); + } else { + $list = array($list); } - - return $useLib; } - /** - * JSON encode wrapper - * - missing or broken in some php 5.x versions - * - * @param mixed $value - * @return string - */ - public static function json_encode($value) - { - if (\Piwik\Core\self::useJsonLibrary()) { - return _json_encode($value); - } + array_walk_recursive($return, 'trim'); + return $return; + } - return @json_encode($value); - } - - /** - * JSON decode wrapper - * - missing or broken in some php 5.x versions - * - * @param string $json - * @param bool $assoc - * @return mixed - */ - public static function json_decode($json, $assoc = false) - { - if (\Piwik\Core\self::useJsonLibrary()) { - return _json_decode($json, $assoc); - } + /* + * Referrer + */ - return json_decode($json, $assoc); - } - - /* - * DataFiles - */ - - /** - * Returns list of continent codes - * - * @see core/DataFiles/Countries.php - * - * @return array Array of 3 letter continent codes - */ - public static function getContinentsList() - { - require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php'; - - $continentsList = $GLOBALS['Piwik_ContinentList']; - return $continentsList; - } - - /** - * Returns list of valid country codes - * - * @see core/DataFiles/Countries.php - * - * @param bool $includeInternalCodes - * @return array Array of (2 letter ISO codes => 3 letter continent code) - */ - public static function getCountriesList($includeInternalCodes = false) - { - require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php'; - - $countriesList = $GLOBALS['Piwik_CountryList']; - $extras = $GLOBALS['Piwik_CountryList_Extras']; - - if ($includeInternalCodes) { - return array_merge($countriesList, $extras); - } - return $countriesList; - } - - /** - * Returns list of valid language codes - * - * @see core/DataFiles/Languages.php - * - * @return array Array of 2 letter ISO codes => Language name (in English) - */ - public static function getLanguagesList() - { - require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Languages.php'; - - $languagesList = $GLOBALS['Piwik_LanguageList']; - return $languagesList; - } - - /** - * Returns list of language to country mappings - * - * @see core/DataFiles/LanguageToCountry.php - * - * @return array Array of ( 2 letter ISO language codes => 2 letter ISO country codes ) - */ - public static function getLanguageToCountryList() - { - require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/LanguageToCountry.php'; - - $languagesList = $GLOBALS['Piwik_LanguageToCountry']; - return $languagesList; - } - - /** - * Returns list of search engines by URL - * - * @see core/DataFiles/SearchEngines.php - * - * @return array Array of ( URL => array( searchEngineName, keywordParameter, path, charset ) ) - */ - public static function getSearchEngineUrls() - { - require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/SearchEngines.php'; - - $searchEngines = $GLOBALS['Piwik_SearchEngines']; - return $searchEngines; - } - - /** - * Returns list of search engines by name - * - * @see core/DataFiles/SearchEngines.php - * - * @return array Array of ( searchEngineName => URL ) - */ - public static function getSearchEngineNames() - { - require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/SearchEngines.php'; - - $searchEngines = $GLOBALS['Piwik_SearchEngines_NameToUrl']; - return $searchEngines; - } - - /** - * Returns list of provider names - * - * @see core/DataFiles/Providers.php - * - * @return array Array of ( dnsName => providerName ) - */ - public static function getProviderNames() - { - require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Providers.php'; - - $providers = $GLOBALS['Piwik_ProviderNames']; - return $providers; - } - - /* - * Language, country, continent - */ - - /** - * Returns the browser language code, eg. "en-gb,en;q=0.5" - * - * @param string|null $browserLang Optional browser language, otherwise taken from the request header - * @return string - */ - public static function getBrowserLanguage($browserLang = NULL) - { - static $replacementPatterns = array( - // extraneous bits of RFC 3282 that we ignore - '/(\\\\.)/', // quoted-pairs - '/(\s+)/', // CFWcS white space - '/(\([^)]*\))/', // CFWS comments - '/(;q=[0-9.]+)/', // quality - - // found in the LANG environment variable - '/\.(.*)/', // charset (e.g., en_CA.UTF-8) - '/^C$/', // POSIX 'C' locale - ); - - if (is_null($browserLang)) { - $browserLang = \Piwik\Core\self::sanitizeInputValues(@$_SERVER['HTTP_ACCEPT_LANGUAGE']); - if (empty($browserLang) && \Piwik\Core\self::isPhpCliMode()) { - $browserLang = @getenv('LANG'); - } - } + /** + * Reduce URL to more minimal form. 2 letter country codes are + * replaced by '{}', while other parts are simply removed. + * + * Examples: + * www.example.com -> example.com + * search.example.com -> example.com + * m.example.com -> example.com + * de.example.com -> {}.example.com + * example.de -> example.{} + * example.co.uk -> example.{} + * + * @param string $url + * @return string + */ + public static function getLossyUrl($url) + { + static $countries; + if (!isset($countries)) { + $countries = implode('|', array_keys(self::getCountriesList(true))); + } + + return preg_replace( + array( + '/^(w+[0-9]*|search)\./', + '/(^|\.)m\./', + '/(\.(com|org|net|co|it|edu))?\.(' . $countries . ')(\/|$)/', + '/(^|\.)(' . $countries . ')\./', + ), + array( + '', + '$1', + '.{}$4', + '$1{}.', + ), + $url); + } - if (is_null($browserLang)) { - // a fallback might be to infer the language in HTTP_USER_AGENT (i.e., localized build) - $browserLang = ""; + /** + * Extracts a keyword from a raw not encoded URL. + * Will only extract keyword if a known search engine has been detected. + * Returns the keyword: + * - in UTF8: automatically converted from other charsets when applicable + * - strtolowered: "QUErY test!" will return "query test!" + * - trimmed: extra spaces before and after are removed + * + * Lists of supported search engines can be found in /core/DataFiles/SearchEngines.php + * The function returns false when a keyword couldn't be found. + * eg. if the url is "http://www.google.com/partners.html" this will return false, + * as the google keyword parameter couldn't be found. + * + * @see unit tests in /tests/core/Common.test.php + * @param string $referrerUrl URL referer URL, eg. $_SERVER['HTTP_REFERER'] + * @return array|false false if a keyword couldn't be extracted, + * or array( + * 'name' => 'Google', + * 'keywords' => 'my searched keywords') + */ + public static function extractSearchEngineInformationFromUrl($referrerUrl) + { + $refererParsed = @parse_url($referrerUrl); + $refererHost = ''; + if (isset($refererParsed['host'])) { + $refererHost = $refererParsed['host']; + } + if (empty($refererHost)) { + return false; + } + // some search engines (eg. Bing Images) use the same domain + // as an existing search engine (eg. Bing), we must also use the url path + $refererPath = ''; + if (isset($refererParsed['path'])) { + $refererPath = $refererParsed['path']; + } + + // no search query + if (!isset($refererParsed['query'])) { + $refererParsed['query'] = ''; + } + $query = $refererParsed['query']; + + // Google Referrers URLs sometimes have the fragment which contains the keyword + if (!empty($refererParsed['fragment'])) { + $query .= '&' . $refererParsed['fragment']; + } + + $searchEngines = self::getSearchEngineUrls(); + + $hostPattern = self::getLossyUrl($refererHost); + if (array_key_exists($refererHost . $refererPath, $searchEngines)) { + $refererHost = $refererHost . $refererPath; + } elseif (array_key_exists($hostPattern . $refererPath, $searchEngines)) { + $refererHost = $hostPattern . $refererPath; + } elseif (array_key_exists($hostPattern, $searchEngines)) { + $refererHost = $hostPattern; + } elseif (!array_key_exists($refererHost, $searchEngines)) { + if (!strncmp($query, 'cx=partner-pub-', 15)) { + // Google custom search engine + $refererHost = 'google.com/cse'; + } elseif (!strncmp($refererPath, '/pemonitorhosted/ws/results/', 28)) { + // private-label search powered by InfoSpace Metasearch + $refererHost = 'wsdsold.infospace.com'; + } elseif (strpos($refererHost, '.images.search.yahoo.com') != false) { + // Yahoo! Images + $refererHost = 'images.search.yahoo.com'; + } elseif (strpos($refererHost, '.search.yahoo.com') != false) { + // Yahoo! + $refererHost = 'search.yahoo.com'; } else { - // language tags are case-insensitive per HTTP/1.1 s3.10 but the region may be capitalized per ISO3166-1; - // underscores are not permitted per RFC 4646 or 4647 (which obsolete RFC 1766 and 3066), - // but we guard against a bad user agent which naively uses its locale - $browserLang = strtolower(str_replace('_', '-', $browserLang)); - - // filters - $browserLang = preg_replace($replacementPatterns, '', $browserLang); - - $browserLang = preg_replace('/((^|,)chrome:.*)/', '', $browserLang, 1); // Firefox bug - $browserLang = preg_replace('/(,)(?:en-securid,)|(?:(^|,)en-securid(,|$))/', '$1', $browserLang, 1); // unregistered language tag - - $browserLang = str_replace('sr-sp', 'sr-rs', $browserLang); // unofficial (proposed) code in the wild + return false; } + } + $searchEngineName = $searchEngines[$refererHost][0]; + $variableNames = null; + if (isset($searchEngines[$refererHost][1])) { + $variableNames = $searchEngines[$refererHost][1]; + } + if (!$variableNames) { + $searchEngineNames = self::getSearchEngineNames(); + $url = $searchEngineNames[$searchEngineName]; + $variableNames = $searchEngines[$url][1]; + } + if (!is_array($variableNames)) { + $variableNames = array($variableNames); + } - return $browserLang; - } - - /** - * Returns the visitor country based on the Browser 'accepted language' - * information, but provides a hook for geolocation via IP address. - * - * @param string $lang browser lang - * @param bool $enableLanguageToCountryGuess If set to true, some assumption will be made and detection guessed more often, but accuracy could be affected - * @param string $ip - * @return string 2 letter ISO code - */ - public static function getCountry($lang, $enableLanguageToCountryGuess, $ip) - { - $country = null; - Piwik_PostEvent('Common.getCountry', array(&$country, $ip)); - if (!empty($country)) { - return strtolower($country); + $key = null; + if ($searchEngineName === 'Google Images' + || ($searchEngineName === 'Google' && strpos($referrerUrl, '/imgres') !== false) + ) { + if (strpos($query, '&prev') !== false) { + $query = urldecode(trim(self::getParameterFromQueryString($query, 'prev'))); + $query = str_replace('&', '&', strstr($query, '?')); } - - if (empty($lang) || strlen($lang) < 2 || $lang == 'xx') { - return 'xx'; + $searchEngineName = 'Google Images'; + } else if ($searchEngineName === 'Google' + && (strpos($query, '&as_') !== false || strpos($query, 'as_') === 0) + ) { + $keys = array(); + $key = self::getParameterFromQueryString($query, 'as_q'); + if (!empty($key)) { + array_push($keys, $key); } - - $validCountries = \Piwik\Core\self::getCountriesList(); - return \Piwik\Core\self::extractCountryCodeFromBrowserLanguage($lang, $validCountries, $enableLanguageToCountryGuess); - } - - /** - * Returns list of valid country codes - * - * @param string $browserLanguage - * @param array $validCountries Array of valid countries - * @param bool $enableLanguageToCountryGuess (if true, will guess country based on language that lacks region information) - * @return array Array of 2 letter ISO codes - */ - public static function extractCountryCodeFromBrowserLanguage($browserLanguage, $validCountries, $enableLanguageToCountryGuess) - { - $langToCountry = \Piwik\Core\self::getLanguageToCountryList(); - - if ($enableLanguageToCountryGuess) { - if (preg_match('/^([a-z]{2,3})(?:,|;|$)/', $browserLanguage, $matches)) { - // match language (without region) to infer the country of origin - if (array_key_exists($matches[1], $langToCountry)) { - return $langToCountry[$matches[1]]; - } - } + $key = self::getParameterFromQueryString($query, 'as_oq'); + if (!empty($key)) { + array_push($keys, str_replace('+', ' OR ', $key)); + } + $key = self::getParameterFromQueryString($query, 'as_epq'); + if (!empty($key)) { + array_push($keys, "\"$key\""); + } + $key = self::getParameterFromQueryString($query, 'as_eq'); + if (!empty($key)) { + array_push($keys, "-$key"); } + $key = trim(urldecode(implode(' ', $keys))); + } - if (!empty($validCountries) && preg_match_all('/[-]([a-z]{2})/', $browserLanguage, $matches, PREG_SET_ORDER)) { - foreach ($matches as $parts) { - // match location; we don't make any inferences from the language - if (array_key_exists($parts[1], $validCountries)) { - return $parts[1]; - } - } + if ($searchEngineName === 'Google') { + // top bar menu + $tbm = self::getParameterFromQueryString($query, 'tbm'); + switch ($tbm) { + case 'isch': + $searchEngineName = 'Google Images'; + break; + case 'vid': + $searchEngineName = 'Google Video'; + break; + case 'shop': + $searchEngineName = 'Google Shopping'; + break; } - return 'xx'; } - /** - * Returns the visitor language based only on the Browser 'accepted language' information - * - * @param string $browserLanguage Browser's accepted langauge header - * @param array $validLanguages array of valid language codes - * @return string 2 letter ISO 639 code - */ - public static function extractLanguageCodeFromBrowserLanguage($browserLanguage, $validLanguages) - { - // assumes language preference is sorted; - // does not handle language-script-region tags or language range (*) - if (!empty($validLanguages) && preg_match_all('/(?:^|,)([a-z]{2,3})([-][a-z]{2})?/', $browserLanguage, $matches, PREG_SET_ORDER)) { - foreach ($matches as $parts) { - if (count($parts) == 3) { - // match locale (language and location) - if (in_array($parts[1] . $parts[2], $validLanguages)) { - return $parts[1] . $parts[2]; - } + if (empty($key)) { + foreach ($variableNames as $variableName) { + if ($variableName[0] == '/') { + // regular expression match + if (preg_match($variableName, $referrerUrl, $matches)) { + $key = trim(urldecode($matches[1])); + break; + } + } else { + // search for keywords now &vname=keyword + $key = self::getParameterFromQueryString($query, $variableName); + $key = trim(urldecode($key)); + + // Special case: Google & empty q parameter + if (empty($key) + && $variableName == 'q' + + && ( + // Google search with no keyword + ($searchEngineName == 'Google' + && ( // First, they started putting an empty q= parameter + strpos($query, '&q=') !== false + || strpos($query, '?q=') !== false + // then they started sending the full host only (no path/query string) + || (empty($query) && (empty($refererPath) || $refererPath == '/') && empty($refererParsed['fragment'])) + ) + ) + // search engines with no keyword + || $searchEngineName == 'Google Images' + || $searchEngineName == 'DuckDuckGo') + ) { + $key = false; } - // match language only (where no region provided) - if (in_array($parts[1], $validLanguages)) { - return $parts[1]; + if (!empty($key) + || $key === false + ) { + break; } } } - return 'xx'; } - /** - * Returns the continent of a given country - * - * @param string $country 2 letters isocode - * - * @return string Continent (3 letters code : afr, asi, eur, amn, ams, oce) - */ - public static function getContinent($country) - { - $countryList = \Piwik\Core\self::getCountriesList(); - if (isset($countryList[$country])) { - return $countryList[$country]; - } - return 'unk'; - } - - /* - * Campaign - */ - - /** - * Returns the list of Campaign parameter names that will be read to classify - * a visit as coming from a Campaign - * - * @return array array( - * 0 => array( ... ) // campaign names parameters - * 1 => array( ... ) // campaign keyword parameters - * ); - */ - public static function getCampaignParameters() - { - $return = array( - Config::getInstance()->Tracker['campaign_var_name'], - Config::getInstance()->Tracker['campaign_keyword_var_name'], - ); - - foreach ($return as &$list) { - if (strpos($list, ',') !== false) { - $list = explode(',', $list); - } else { - $list = array($list); + // $key === false is the special case "No keyword provided" which is a Search engine match + if ($key === null + || $key === '' + ) { + return false; + } + + if (!empty($key)) { + if (function_exists('iconv') + && isset($searchEngines[$refererHost][3]) + ) { + // accepts string, array, or comma-separated list string in preferred order + $charsets = $searchEngines[$refererHost][3]; + if (!is_array($charsets)) { + $charsets = explode(',', $charsets); } - } - array_walk_recursive($return, 'trim'); - return $return; - } - - /* - * Referrer - */ - - /** - * Reduce URL to more minimal form. 2 letter country codes are - * replaced by '{}', while other parts are simply removed. - * - * Examples: - * www.example.com -> example.com - * search.example.com -> example.com - * m.example.com -> example.com - * de.example.com -> {}.example.com - * example.de -> example.{} - * example.co.uk -> example.{} - * - * @param string $url - * @return string - */ - public static function getLossyUrl($url) - { - static $countries; - if (!isset($countries)) { - $countries = implode('|', array_keys(\Piwik\Core\self::getCountriesList(true))); - } + if (!empty($charsets)) { + $charset = $charsets[0]; + if (count($charsets) > 1 + && function_exists('mb_detect_encoding') + ) { + $charset = mb_detect_encoding($key, $charsets); + if ($charset === false) { + $charset = $charsets[0]; + } + } - return preg_replace( - array( - '/^(w+[0-9]*|search)\./', - '/(^|\.)m\./', - '/(\.(com|org|net|co|it|edu))?\.(' . $countries . ')(\/|$)/', - '/(^|\.)(' . $countries . ')\./', - ), - array( - '', - '$1', - '.{}$4', - '$1{}.', - ), - $url); - } - - /** - * Extracts a keyword from a raw not encoded URL. - * Will only extract keyword if a known search engine has been detected. - * Returns the keyword: - * - in UTF8: automatically converted from other charsets when applicable - * - strtolowered: "QUErY test!" will return "query test!" - * - trimmed: extra spaces before and after are removed - * - * Lists of supported search engines can be found in /core/DataFiles/SearchEngines.php - * The function returns false when a keyword couldn't be found. - * eg. if the url is "http://www.google.com/partners.html" this will return false, - * as the google keyword parameter couldn't be found. - * - * @see unit tests in /tests/core/Common.test.php - * @param string $referrerUrl URL referer URL, eg. $_SERVER['HTTP_REFERER'] - * @return array|false false if a keyword couldn't be extracted, - * or array( - * 'name' => 'Google', - * 'keywords' => 'my searched keywords') - */ - public static function extractSearchEngineInformationFromUrl($referrerUrl) - { - $refererParsed = @parse_url($referrerUrl); - $refererHost = ''; - if (isset($refererParsed['host'])) { - $refererHost = $refererParsed['host']; - } - if (empty($refererHost)) { - return false; - } - // some search engines (eg. Bing Images) use the same domain - // as an existing search engine (eg. Bing), we must also use the url path - $refererPath = ''; - if (isset($refererParsed['path'])) { - $refererPath = $refererParsed['path']; + $newkey = @iconv($charset, 'UTF-8//IGNORE', $key); + if (!empty($newkey)) { + $key = $newkey; + } + } } - // no search query - if (!isset($refererParsed['query'])) { - $refererParsed['query'] = ''; - } - $query = $refererParsed['query']; + $key = self::mb_strtolower($key); + } - // Google Referrers URLs sometimes have the fragment which contains the keyword - if (!empty($refererParsed['fragment'])) { - $query .= '&' . $refererParsed['fragment']; - } + return array( + 'name' => $searchEngineName, + 'keywords' => $key, + ); + } - $searchEngines = \Piwik\Core\self::getSearchEngineUrls(); - - $hostPattern = \Piwik\Core\self::getLossyUrl($refererHost); - if (array_key_exists($refererHost . $refererPath, $searchEngines)) { - $refererHost = $refererHost . $refererPath; - } elseif (array_key_exists($hostPattern . $refererPath, $searchEngines)) { - $refererHost = $hostPattern . $refererPath; - } elseif (array_key_exists($hostPattern, $searchEngines)) { - $refererHost = $hostPattern; - } elseif (!array_key_exists($refererHost, $searchEngines)) { - if (!strncmp($query, 'cx=partner-pub-', 15)) { - // Google custom search engine - $refererHost = 'google.com/cse'; - } elseif (!strncmp($refererPath, '/pemonitorhosted/ws/results/', 28)) { - // private-label search powered by InfoSpace Metasearch - $refererHost = 'wsdsold.infospace.com'; - } elseif (strpos($refererHost, '.images.search.yahoo.com') != false) { - // Yahoo! Images - $refererHost = 'images.search.yahoo.com'; - } elseif (strpos($refererHost, '.search.yahoo.com') != false) { - // Yahoo! - $refererHost = 'search.yahoo.com'; - } else { - return false; - } - } - $searchEngineName = $searchEngines[$refererHost][0]; - $variableNames = null; - if (isset($searchEngines[$refererHost][1])) { - $variableNames = $searchEngines[$refererHost][1]; - } - if (!$variableNames) { - $searchEngineNames = \Piwik\Core\self::getSearchEngineNames(); - $url = $searchEngineNames[$searchEngineName]; - $variableNames = $searchEngines[$url][1]; - } - if (!is_array($variableNames)) { - $variableNames = array($variableNames); - } + /* + * System environment + */ - $key = null; - if ($searchEngineName === 'Google Images' - || ($searchEngineName === 'Google' && strpos($referrerUrl, '/imgres') !== false) - ) { - if (strpos($query, '&prev') !== false) { - $query = urldecode(trim(\Piwik\Core\self::getParameterFromQueryString($query, 'prev'))); - $query = str_replace('&', '&', strstr($query, '?')); - } - $searchEngineName = 'Google Images'; - } else if ($searchEngineName === 'Google' - && (strpos($query, '&as_') !== false || strpos($query, 'as_') === 0) - ) { - $keys = array(); - $key = \Piwik\Core\self::getParameterFromQueryString($query, 'as_q'); - if (!empty($key)) { - array_push($keys, $key); - } - $key = \Piwik\Core\self::getParameterFromQueryString($query, 'as_oq'); - if (!empty($key)) { - array_push($keys, str_replace('+', ' OR ', $key)); - } - $key = \Piwik\Core\self::getParameterFromQueryString($query, 'as_epq'); - if (!empty($key)) { - array_push($keys, "\"$key\""); - } - $key = \Piwik\Core\self::getParameterFromQueryString($query, 'as_eq'); - if (!empty($key)) { - array_push($keys, "-$key"); - } - $key = trim(urldecode(implode(' ', $keys))); - } + /** + * Returns true if PHP was invoked from command-line interface (shell) + * + * @since added in 0.4.4 + * @return bool true if PHP invoked as a CGI or from CLI + */ + public static function isPhpCliMode() + { + $remoteAddr = @$_SERVER['REMOTE_ADDR']; + return PHP_SAPI == 'cli' || + (!strncmp(PHP_SAPI, 'cgi', 3) && empty($remoteAddr)); + } - if ($searchEngineName === 'Google') { - // top bar menu - $tbm = \Piwik\Core\self::getParameterFromQueryString($query, 'tbm'); - switch ($tbm) { - case 'isch': - $searchEngineName = 'Google Images'; - break; - case 'vid': - $searchEngineName = 'Google Video'; - break; - case 'shop': - $searchEngineName = 'Google Shopping'; - break; - } - } + /** + * Is the current script execution triggered by misc/cron/archive.php ? + * + * Helpful for error handling: directly throw error without HTML (eg. when DB is down) + * @return bool + */ + public static function isArchivePhpTriggered() + { + return !empty($_GET['trigger']) + && $_GET['trigger'] == 'archivephp'; + } - if (empty($key)) { - foreach ($variableNames as $variableName) { - if ($variableName[0] == '/') { - // regular expression match - if (preg_match($variableName, $referrerUrl, $matches)) { - $key = trim(urldecode($matches[1])); - break; - } - } else { - // search for keywords now &vname=keyword - $key = \Piwik\Core\self::getParameterFromQueryString($query, $variableName); - $key = trim(urldecode($key)); - - // Special case: Google & empty q parameter - if (empty($key) - && $variableName == 'q' - - && ( - // Google search with no keyword - ($searchEngineName == 'Google' - && ( // First, they started putting an empty q= parameter - strpos($query, '&q=') !== false - || strpos($query, '?q=') !== false - // then they started sending the full host only (no path/query string) - || (empty($query) && (empty($refererPath) || $refererPath == '/') && empty($refererParsed['fragment'])) - ) - ) - // search engines with no keyword - || $searchEngineName == 'Google Images' - || $searchEngineName == 'DuckDuckGo') - ) { - $key = false; - } - if (!empty($key) - || $key === false - ) { - break; - } - } - } + /** + * Assign CLI parameters as if they were REQUEST or GET parameters. + * You can trigger Piwik from the command line by + * # /usr/bin/php5 /path/to/piwik/index.php -- "module=API&method=Actions.getActions&idSite=1&period=day&date=previous8&format=php" + */ + public static function assignCliParametersToRequest() + { + if (isset($_SERVER['argc']) + && $_SERVER['argc'] > 0 + ) { + for ($i = 1; $i < $_SERVER['argc']; $i++) { + parse_str($_SERVER['argv'][$i], $tmp); + $_GET = array_merge($_GET, $tmp); } + } + } - // $key === false is the special case "No keyword provided" which is a Search engine match - if ($key === null - || $key === '' - ) { - return false; - } + /** + * Returns true if running on a Windows operating system + * + * @since 0.6.5 + * @return bool true if PHP detects it is running on Windows; else false + */ + public static function isWindows() + { + return DIRECTORY_SEPARATOR === '\\'; + } - if (!empty($key)) { - if (function_exists('iconv') - && isset($searchEngines[$refererHost][3]) - ) { - // accepts string, array, or comma-separated list string in preferred order - $charsets = $searchEngines[$refererHost][3]; - if (!is_array($charsets)) { - $charsets = explode(',', $charsets); - } + /** + * Returns true if running on MacOS + * + * @return bool true if PHP detects it is running on MacOS; else false + */ + public static function isMacOS() + { + return PHP_OS === 'Darwin'; + } - if (!empty($charsets)) { - $charset = $charsets[0]; - if (count($charsets) > 1 - && function_exists('mb_detect_encoding') - ) { - $charset = mb_detect_encoding($key, $charsets); - if ($charset === false) { - $charset = $charsets[0]; - } - } + /** + * Returns true if running on an Apache web server + * + * @return bool + */ + public static function isApache() + { + $apache = isset($_SERVER['SERVER_SOFTWARE']) && + !strncmp($_SERVER['SERVER_SOFTWARE'], 'Apache', 6); - $newkey = @iconv($charset, 'UTF-8//IGNORE', $key); - if (!empty($newkey)) { - $key = $newkey; - } - } - } + return $apache; + } - $key = \Piwik\Core\self::mb_strtolower($key); - } + /** + * Returns true if running on Microsoft IIS 7 (or above) + * + * @return bool + */ + public static function isIIS() + { + $iis = isset($_SERVER['SERVER_SOFTWARE']) && + preg_match('/^Microsoft-IIS\/(.+)/', $_SERVER['SERVER_SOFTWARE'], $matches) && + version_compare($matches[1], '7') >= 0; - return array( - 'name' => $searchEngineName, - 'keywords' => $key, - ); - } - - /* - * System environment - */ - - /** - * Returns true if PHP was invoked from command-line interface (shell) - * - * @since added in 0.4.4 - * @return bool true if PHP invoked as a CGI or from CLI - */ - public static function isPhpCliMode() - { - $remoteAddr = @$_SERVER['REMOTE_ADDR']; - return PHP_SAPI == 'cli' || - (!strncmp(PHP_SAPI, 'cgi', 3) && empty($remoteAddr)); - } - - /** - * Is the current script execution triggered by misc/cron/archive.php ? - * - * Helpful for error handling: directly throw error without HTML (eg. when DB is down) - * @return bool - */ - public static function isArchivePhpTriggered() - { - return !empty($_GET['trigger']) - && $_GET['trigger'] == 'archivephp'; - } - - /** - * Assign CLI parameters as if they were REQUEST or GET parameters. - * You can trigger Piwik from the command line by - * # /usr/bin/php5 /path/to/piwik/index.php -- "module=API&method=Actions.getActions&idSite=1&period=day&date=previous8&format=php" - */ - public static function assignCliParametersToRequest() - { - if (isset($_SERVER['argc']) - && $_SERVER['argc'] > 0 - ) { - for ($i = 1; $i < $_SERVER['argc']; $i++) { - parse_str($_SERVER['argv'][$i], $tmp); - $_GET = array_merge($_GET, $tmp); - } - } - } + return $iis; + } - /** - * Returns true if running on a Windows operating system - * - * @since 0.6.5 - * @return bool true if PHP detects it is running on Windows; else false - */ - public static function isWindows() - { - return DIRECTORY_SEPARATOR === '\\'; - } - - /** - * Returns true if running on MacOS - * - * @return bool true if PHP detects it is running on MacOS; else false - */ - public static function isMacOS() - { - return PHP_OS === 'Darwin'; - } - - /** - * Returns true if running on an Apache web server - * - * @return bool - */ - public static function isApache() - { - $apache = isset($_SERVER['SERVER_SOFTWARE']) && - !strncmp($_SERVER['SERVER_SOFTWARE'], 'Apache', 6); - - return $apache; - } - - /** - * Returns true if running on Microsoft IIS 7 (or above) - * - * @return bool - */ - public static function isIIS() - { - $iis = isset($_SERVER['SERVER_SOFTWARE']) && - preg_match('/^Microsoft-IIS\/(.+)/', $_SERVER['SERVER_SOFTWARE'], $matches) && - version_compare($matches[1], '7') >= 0; - - return $iis; - } - - /** - * Takes a list of fields defining numeric values and returns the corresponding - * unnamed parameters to be bound to the field names in the where clause of a SQL query - * - * @param array|string $fields array( fieldName1, fieldName2, fieldName3) Names of the mysql table fields to load - * @return string "?, ?, ?" - */ - public static function getSqlStringFieldsArray($fields) - { - if (is_string($fields)) { - $fields = array($fields); - } - $count = count($fields); - if ($count == 0) { - return "''"; - } - return '?' . str_repeat(',?', $count - 1); - } - - /** - * Sets outgoing header. - * - * @param string $header The header. - * @param bool $replace Whether to replace existing or not. - */ - public static function sendHeader($header, $replace = true) - { - if (isset($GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING']) && $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING']) { - @header($header, $replace); - } else { - header($header, $replace); - } + /** + * Takes a list of fields defining numeric values and returns the corresponding + * unnamed parameters to be bound to the field names in the where clause of a SQL query + * + * @param array|string $fields array( fieldName1, fieldName2, fieldName3) Names of the mysql table fields to load + * @return string "?, ?, ?" + */ + public static function getSqlStringFieldsArray($fields) + { + if (is_string($fields)) { + $fields = array($fields); } - - /** - * Returns the ID of the current LocationProvider (see UserCountry plugin code) from - * the Tracker cache. - */ - public static function getCurrentLocationProviderId() - { - $cache = Piwik_Tracker_Cache::getCacheGeneral(); - return empty($cache['currentLocationProviderId']) - ? Piwik_UserCountry_LocationProvider_Default::ID - : $cache['currentLocationProviderId']; - } - - /** - * Unprefix class name (if needed) - * - * @param string $class - * @return string - */ - public static function unprefixClass($class) - { - $lenPrefix = strlen(\Piwik\Core\self::CLASSES_PREFIX); - if (!strncmp($class, \Piwik\Core\self::CLASSES_PREFIX, $lenPrefix)) { - return substr($class, $lenPrefix); - } - return $class; + $count = count($fields); + if ($count == 0) { + return "''"; } + return '?' . str_repeat(',?', $count - 1); } -} -namespace { + /** - * Piwik - Open source web analytics + * Sets outgoing header. * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * @param string $header The header. + * @param bool $replace Whether to replace existing or not. + */ + public static function sendHeader($header, $replace = true) + { + if (isset($GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING']) && $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING']) { + @header($header, $replace); + } else { + header($header, $replace); + } + } + + /** + * Returns the ID of the current LocationProvider (see UserCountry plugin code) from + * the Tracker cache. + */ + public static function getCurrentLocationProviderId() + { + $cache = Piwik_Tracker_Cache::getCacheGeneral(); + return empty($cache['currentLocationProviderId']) + ? Piwik_UserCountry_LocationProvider_Default::ID + : $cache['currentLocationProviderId']; + } + + /** + * Unprefix class name (if needed) * - * @category Piwik - * @package Piwik + * @param string $class + * @return string */ - use Piwik\Core\Config; + public static function unprefixClass($class) + { + $lenPrefix = strlen(self::CLASSES_PREFIX); + if (!strncmp($class, self::CLASSES_PREFIX, $lenPrefix)) { + return substr($class, $lenPrefix); + } + return $class; + } /** @@ -1583,7 +1571,7 @@ namespace { * For more information: @link http://dev.piwik.org/trac/ticket/374 * @param $var */ - function destroy(&$var) + static public function destroy(&$var) { if (is_object($var) && method_exists($var, '__destruct')) { $var->__destruct(); @@ -1592,18 +1580,17 @@ namespace { $var = null; } - if (!function_exists('printDebug')) { - function printDebug($info = '') - { - if (isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) { - if (is_array($info) || is_object($info)) { - print("
");
-                    print(htmlspecialchars(var_export($info, true), ENT_QUOTES));
-                    print("
"); - } else { - print(htmlspecialchars($info, ENT_QUOTES) . "
\n"); - } + static public function printDebug($info = '') + { + if (isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) { + if (is_array($info) || is_object($info)) { + print("
");
+                print(htmlspecialchars(var_export($info, true), ENT_QUOTES));
+                print("
"); + } else { + print(htmlspecialchars($info, ENT_QUOTES) . "
\n"); } } } } + diff --git a/core/Config.php b/core/Config.php index b5c5fb05fd..542b518a6f 100644 --- a/core/Config.php +++ b/core/Config.php @@ -9,7 +9,7 @@ * @package Piwik */ -namespace Piwik\Core; +namespace Piwik; use Exception; /** @@ -48,7 +48,7 @@ class Config /** * Returns the singleton Piwik_Config * - * @return \Piwik\Core\Config + * @return \Piwik\Config */ public static function getInstance() { diff --git a/core/Controller.php b/core/Controller.php index 651351be5f..999e7488b3 100644 --- a/core/Controller.php +++ b/core/Controller.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * Parent class of all plugins Controllers (located in /plugins/PluginName/Controller.php diff --git a/core/Controller/Admin.php b/core/Controller/Admin.php index 91341107f5..7e62499cd1 100644 --- a/core/Controller/Admin.php +++ b/core/Controller/Admin.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; +use Piwik\Config; +use Piwik\Piwik; /** * Parent class of all plugins Controllers with admin functions diff --git a/core/Cookie.php b/core/Cookie.php index d68d97a28e..24bd7c8ba2 100644 --- a/core/Cookie.php +++ b/core/Cookie.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * Simple class to handle the cookies: diff --git a/core/DataAccess/ArchiveSelector.php b/core/DataAccess/ArchiveSelector.php index f0241bd06f..1eac19955c 100644 --- a/core/DataAccess/ArchiveSelector.php +++ b/core/DataAccess/ArchiveSelector.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * Data Access object used to query archives diff --git a/core/DataAccess/ArchiveTableCreator.php b/core/DataAccess/ArchiveTableCreator.php index cbcb25c8ac..d36206d1fe 100644 --- a/core/DataAccess/ArchiveTableCreator.php +++ b/core/DataAccess/ArchiveTableCreator.php @@ -1,6 +1,6 @@ getRows() as $row) { - destroy($row); + Common::destroy($row); } unset($this->rows); Piwik_DataTable_Manager::getInstance()->setTableDeleted($this->getId()); @@ -371,7 +373,7 @@ class Piwik_DataTable $className($this); return; } - + if (!class_exists($className, false)) { $className = "Piwik_DataTable_Filter_" . $className; } @@ -686,19 +688,19 @@ class Piwik_DataTable $columnValues = array(); foreach ($this->getRows() as $row) { $columns = $row->getColumns(); - foreach($columns as $column => $value) { - if(strpos($column, $name) === 0) { + foreach ($columns as $column => $value) { + if (strpos($column, $name) === 0) { $columnValues[] = $row->getColumn($column); } } } return $columnValues; } - + /** * Returns the list of columns the rows in this datatable contain. This will return the * columns of the first row with data and assume they occur in every other row as well. - * + * * @return array */ public function getColumns() @@ -857,7 +859,7 @@ class Piwik_DataTable /** * Deletes the ith row * - * @param int $id + * @param int $id * * @throws Exception if the row $id cannot be found * @return void @@ -1122,7 +1124,6 @@ class Piwik_DataTable "; you will get the original php data structure serialized." . " The data structure looks like this: \n \$data = " . var_export($array, true) . "; "); - // first pass to see if the array has the structure // array(col1_name => val1, col2_name => val2, etc.) // with val* that are never arrays (only strings/numbers/bool/etc.) @@ -1296,12 +1297,12 @@ class Piwik_DataTable * a subtable is encountered w/o the queried label, a new row is created * with the label, and a subtable is added to the row. * - * @param array $path The path to walk. An array of label values. - * @param array|bool $missingRowColumns + * @param array $path The path to walk. An array of label values. + * @param array|bool $missingRowColumns * The default columns to use when creating new arrays. * If this parameter is supplied, new rows will be * created if labels cannot be found. - * @param int $maxSubtableRows The maximum number of allowed rows in new + * @param int $maxSubtableRows The maximum number of allowed rows in new * subtables. * * @return array First element is the found row or false. Second element is @@ -1363,11 +1364,11 @@ class Piwik_DataTable /** * Returns a new DataTable that contains the rows of each of this table's subtables. * - * @param string|bool $labelColumn If supplied the label of the parent row will be + * @param string|bool $labelColumn If supplied the label of the parent row will be * added to a new column in each subtable row. If set to, * 'label' each subtable row's label will be prepended w/ * the parent row's label. - * @param bool $useMetadataColumn If true and if $labelColumn is supplied, the parent row's + * @param bool $useMetadataColumn If true and if $labelColumn is supplied, the parent row's * label will be added as metadata. * * @return Piwik_DataTable @@ -1430,11 +1431,11 @@ class Piwik_DataTable $dataTable->addRowsFromSimpleArray($array); return $dataTable; } - + /** * Set the aggregation operation for a column, e.g. "min". * @see self::addDataTable() and Piwik_DataTable_Row::sumRow() - * + * * @param string $columnName * @param string $operation */ @@ -1442,7 +1443,7 @@ class Piwik_DataTable { $this->columnAggregationOperations[$columnName] = $operation; } - + /** * Set multiple aggregation operations at once. * @param array $operations format: column name => operation @@ -1453,7 +1454,7 @@ class Piwik_DataTable $this->setColumnAggregationOperation($columnName, $operation); } } - + /** * Get the configured column aggregation operations */ @@ -1461,10 +1462,10 @@ class Piwik_DataTable { return $this->columnAggregationOperations; } - + /** * Creates a new DataTable instance from a serialize()'d array of rows. - * + * * @param string $data * @return Piwik_DataTable */ diff --git a/core/DataTable/Filter/AddColumnsProcessedMetricsGoal.php b/core/DataTable/Filter/AddColumnsProcessedMetricsGoal.php index b2fd046254..21468628f6 100644 --- a/core/DataTable/Filter/AddColumnsProcessedMetricsGoal.php +++ b/core/DataTable/Filter/AddColumnsProcessedMetricsGoal.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * @package Piwik diff --git a/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php b/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php index 191f9146b3..5ac99ce678 100644 --- a/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php +++ b/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * Add a new column to the table which is a percentage based on the value resulting diff --git a/core/DataTable/Filter/ReplaceColumnNames.php b/core/DataTable/Filter/ReplaceColumnNames.php index 85fb633194..f0255a8086 100644 --- a/core/DataTable/Filter/ReplaceColumnNames.php +++ b/core/DataTable/Filter/ReplaceColumnNames.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * This filter replaces column names using a mapping table that maps from the old name to the new name. diff --git a/core/DataTable/Manager.php b/core/DataTable/Manager.php index eab94df8f8..21dc600481 100644 --- a/core/DataTable/Manager.php +++ b/core/DataTable/Manager.php @@ -9,6 +9,8 @@ * @package Piwik */ +use Piwik\Common; + /** * The DataTable_Manager registers all the instanciated DataTable and provides an * easy way to access them. This is used to store all the DataTable during the archiving process. @@ -112,7 +114,7 @@ class Piwik_DataTable_Manager public function deleteTable($id) { if (isset($this->tables[$id])) { - destroy($this->tables[$id]); + Common::destroy($this->tables[$id]); $this->setTableDeleted($id); } } diff --git a/core/DataTable/Renderer.php b/core/DataTable/Renderer.php index 74f4785e90..c8f353a64e 100644 --- a/core/DataTable/Renderer.php +++ b/core/DataTable/Renderer.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * A DataTable Renderer can produce an output given a DataTable object. diff --git a/core/DataTable/Renderer/Csv.php b/core/DataTable/Renderer/Csv.php index 38c97fa2fc..0e1a3f39d4 100644 --- a/core/DataTable/Renderer/Csv.php +++ b/core/DataTable/Renderer/Csv.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * CSV export diff --git a/core/DataTable/Renderer/Json.php b/core/DataTable/Renderer/Json.php index 2d408d7fda..92e0830316 100644 --- a/core/DataTable/Renderer/Json.php +++ b/core/DataTable/Renderer/Json.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * JSON export. diff --git a/core/DataTable/Renderer/Php.php b/core/DataTable/Renderer/Php.php index 1dc7ee501b..ec66701cbe 100644 --- a/core/DataTable/Renderer/Php.php +++ b/core/DataTable/Renderer/Php.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * Returns the equivalent PHP array for a given DataTable. diff --git a/core/DataTable/Renderer/Rss.php b/core/DataTable/Renderer/Rss.php index 662ad0ad82..2c1fd05114 100644 --- a/core/DataTable/Renderer/Rss.php +++ b/core/DataTable/Renderer/Rss.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * RSS Feed. diff --git a/core/DataTable/Renderer/Xml.php b/core/DataTable/Renderer/Xml.php index adbe5e7206..ba00e6d39e 100644 --- a/core/DataTable/Renderer/Xml.php +++ b/core/DataTable/Renderer/Xml.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * XML export of a given DataTable. diff --git a/core/Db/Adapter/Mysqli.php b/core/Db/Adapter/Mysqli.php index c20800e2ea..38495a2357 100644 --- a/core/Db/Adapter/Mysqli.php +++ b/core/Db/Adapter/Mysqli.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; +use Piwik\Config; /** * @package Piwik diff --git a/core/Db/Adapter/Pdo/Mssql.php b/core/Db/Adapter/Pdo/Mssql.php index 2e9def1834..458a99fcc5 100644 --- a/core/Db/Adapter/Pdo/Mssql.php +++ b/core/Db/Adapter/Pdo/Mssql.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; +use Piwik\Config; /** * @package Piwik diff --git a/core/Db/Adapter/Pdo/Mysql.php b/core/Db/Adapter/Pdo/Mysql.php index 33f52df232..c2ad0ea2d8 100644 --- a/core/Db/Adapter/Pdo/Mysql.php +++ b/core/Db/Adapter/Pdo/Mysql.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; +use Piwik\Config; /** * @package Piwik diff --git a/core/Db/Adapter/Pdo/Pgsql.php b/core/Db/Adapter/Pdo/Pgsql.php index 1b67103633..f4e68dfde9 100644 --- a/core/Db/Adapter/Pdo/Pgsql.php +++ b/core/Db/Adapter/Pdo/Pgsql.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; +use Piwik\Config; /** * @package Piwik diff --git a/core/Db/Schema.php b/core/Db/Schema.php index ad972e910d..fed20dfe28 100644 --- a/core/Db/Schema.php +++ b/core/Db/Schema.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; +use Piwik\Config; /** * Schema abstraction diff --git a/core/Db/Schema/Myisam.php b/core/Db/Schema/Myisam.php index 1758ee384b..a0eb2a7038 100644 --- a/core/Db/Schema/Myisam.php +++ b/core/Db/Schema/Myisam.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * MySQL schema diff --git a/core/ExceptionHandler.php b/core/ExceptionHandler.php index 105caf9058..c06bc3d5af 100644 --- a/core/ExceptionHandler.php +++ b/core/ExceptionHandler.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * Exception handler used to display nicely exceptions in Piwik diff --git a/core/FrontController.php b/core/FrontController.php index 6836578670..a90f4b8554 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * @see core/PluginsManager.php @@ -20,6 +20,7 @@ use Piwik\Core\Common; require_once PIWIK_INCLUDE_PATH . '/core/PluginsManager.php'; require_once PIWIK_INCLUDE_PATH . '/core/Translate.php'; require_once PIWIK_INCLUDE_PATH . '/core/Option.php'; +require_once PIWIK_INCLUDE_PATH . '/core/Piwik.php'; /** * Front controller. @@ -275,7 +276,7 @@ class Piwik_FrontController Piwik_PluginsManager::getInstance()->installLoadedPlugins(); // ensure the current Piwik URL is known for later use - if (method_exists('Piwik\Core\Piwik', 'getPiwikUrl')) { + if (method_exists('Piwik\Piwik', 'getPiwikUrl')) { $host = Piwik::getPiwikUrl(); } diff --git a/core/Http.php b/core/Http.php index cc536477f2..de30bf3b2f 100644 --- a/core/Http.php +++ b/core/Http.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * Server-side http client to retrieve content from remote servers, and optionally save to a local file. diff --git a/core/IP.php b/core/IP.php index 64ca6072ff..2fa60ca33d 100644 --- a/core/IP.php +++ b/core/IP.php @@ -9,8 +9,8 @@ * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; if (Common::isWindows() || !function_exists('inet_ntop')) { function _inet_ntop($in_addr) diff --git a/core/Log.php b/core/Log.php index 6f0dee2047..2228ec9dae 100644 --- a/core/Log.php +++ b/core/Log.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; /** * @@ -176,7 +176,7 @@ class Piwik_Log_Formatter_ScreenFormatter implements Zend_Log_Formatter_Interfac function formatEvent($event) { // no injection in error messages, backtrace when displayed on screen - return array_map(array('Piwik\Core\Common', 'sanitizeInputValue'), $event); + return array_map(array('Piwik\Common', 'sanitizeInputValue'), $event); } function format($string) diff --git a/core/Log/Exception.php b/core/Log/Exception.php index b86a3dd6c7..b71479e575 100644 --- a/core/Log/Exception.php +++ b/core/Log/Exception.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * Class used to log an exception event. diff --git a/core/Log/Message.php b/core/Log/Message.php index cc425116be..eb200a3b68 100644 --- a/core/Log/Message.php +++ b/core/Log/Message.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * Class used to log a standard message event. diff --git a/core/Mail.php b/core/Mail.php index b907f4c63d..d9f917e464 100644 --- a/core/Mail.php +++ b/core/Mail.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; +use Piwik\Config; +use Piwik\Piwik; /** * Class for sending mails, for more information see: diff --git a/core/Menu/Abstract.php b/core/Menu/Abstract.php index 35e677875d..14574847bf 100644 --- a/core/Menu/Abstract.php +++ b/core/Menu/Abstract.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik_Menu */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Piwik_Menu diff --git a/core/Menu/Admin.php b/core/Menu/Admin.php index 0ee8965a24..7af69b3255 100644 --- a/core/Menu/Admin.php +++ b/core/Menu/Admin.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik_Menu */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * @package Piwik_Menu diff --git a/core/Metrics.php b/core/Metrics.php index 4ba6759582..90560e17d0 100644 --- a/core/Metrics.php +++ b/core/Metrics.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * This class holds the various mappings we use to internally store and manipulate metrics. diff --git a/core/Nonce.php b/core/Nonce.php index 49f52a29b5..23e447f949 100644 --- a/core/Nonce.php +++ b/core/Nonce.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * Nonce class. diff --git a/core/Option.php b/core/Option.php index 424d9e1a05..11f541bd55 100644 --- a/core/Option.php +++ b/core/Option.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * Piwik_Option provides a very simple mechanism to save/retrieve key-values pair diff --git a/core/Period.php b/core/Period.php index a086711e1f..01705ccbe7 100644 --- a/core/Period.php +++ b/core/Period.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * Creating a new Piwik_Period subclass: diff --git a/core/Period/Range.php b/core/Period/Range.php index f23e3dce69..f69a0d304e 100644 --- a/core/Period/Range.php +++ b/core/Period/Range.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * from a starting date to an ending date diff --git a/core/Piwik.php b/core/Piwik.php index 6f9ceb3bce..f788d50f89 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -8,15 +8,14 @@ * @category Piwik * @package Piwik */ -namespace Piwik\Core; +namespace Piwik; + use Exception; -use false; -use Manifest; -use Piwik\Core\Config; +use Piwik\Config; use Piwik_Access; use Piwik_Access_NoAccessException; use Piwik_AssetManager; -use Piwik\Core\Common; +use Piwik\Common; use Piwik_Db_Adapter; use Piwik_Db_Schema; use Piwik_Log_APICall; @@ -41,6 +40,8 @@ use Zend_Registry; * @see core/Translate.php */ require_once PIWIK_INCLUDE_PATH . '/core/Translate.php'; +require_once PIWIK_INCLUDE_PATH . '/core/Common.php'; +require_once PIWIK_INCLUDE_PATH . '/core/Config.php'; /** * Main piwik helper class. diff --git a/core/Plugin.php b/core/Plugin.php index 51a21b6049..bec854cd9e 100644 --- a/core/Plugin.php +++ b/core/Plugin.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * @see core/Plugin/MetadataLoader.php diff --git a/core/Plugin/MetadataLoader.php b/core/Plugin/MetadataLoader.php index 5b514b8610..6e8e16ebb4 100644 --- a/core/Plugin/MetadataLoader.php +++ b/core/Plugin/MetadataLoader.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * @see core/Version.php diff --git a/core/PluginsArchiver.php b/core/PluginsArchiver.php index ad0579e332..aac3b936da 100644 --- a/core/PluginsArchiver.php +++ b/core/PluginsArchiver.php @@ -9,8 +9,8 @@ * @category Piwik * @package Piwik_PluginArchiver */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; /** * Plugins that archive metrics for websites can implement an Archiver that extends this class diff --git a/core/PluginsFunctions/Sql.php b/core/PluginsFunctions/Sql.php index fef08121e1..2a0d3665ba 100644 --- a/core/PluginsFunctions/Sql.php +++ b/core/PluginsFunctions/Sql.php @@ -8,7 +8,7 @@ * @category Piwik * @package PluginsFunctions */ -use Piwik\Core\Config; +use Piwik\Config; /** * SQL wrapper diff --git a/core/PluginsManager.php b/core/PluginsManager.php index ffad1670c2..5147ed2178 100644 --- a/core/PluginsManager.php +++ b/core/PluginsManager.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * @see core/Menu/Abstract.php diff --git a/core/ProxyHeaders.php b/core/ProxyHeaders.php index ae319b986d..5b18bcfbc3 100644 --- a/core/ProxyHeaders.php +++ b/core/ProxyHeaders.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * Proxy headers diff --git a/core/ReportRenderer.php b/core/ReportRenderer.php index da27590652..e4125cf18f 100644 --- a/core/ReportRenderer.php +++ b/core/ReportRenderer.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * A Report Renderer produces user friendly renderings of any given Piwik report. diff --git a/core/ReportRenderer/Html.php b/core/ReportRenderer/Html.php index 0edf422dab..0f72de2aaf 100644 --- a/core/ReportRenderer/Html.php +++ b/core/ReportRenderer/Html.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik_ReportRenderer */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** diff --git a/core/ReportRenderer/Pdf.php b/core/ReportRenderer/Pdf.php index 2b20ecb169..7e7e6069f0 100644 --- a/core/ReportRenderer/Pdf.php +++ b/core/ReportRenderer/Pdf.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik_ReportRenderer */ -use Piwik\Core\Common; +use Piwik\Common; /** * @see libs/tcpdf diff --git a/core/Segment.php b/core/Segment.php index 1e2da61f2d..35ada3d878 100644 --- a/core/Segment.php +++ b/core/Segment.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * diff --git a/core/Session.php b/core/Session.php index 5f2d362b6b..1db8458cb7 100644 --- a/core/Session.php +++ b/core/Session.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * Session initialization. diff --git a/core/Session/Namespace.php b/core/Session/Namespace.php index 22199fdfd6..f2fb04b131 100644 --- a/core/Session/Namespace.php +++ b/core/Session/Namespace.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * Session namespace. diff --git a/core/Timer.php b/core/Timer.php index 43edaa78ec..236787db67 100644 --- a/core/Timer.php +++ b/core/Timer.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * diff --git a/core/Tracker.php b/core/Tracker.php index e82e88f053..d3d9a765b6 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * Class used by the logging script piwik.php called by the javascript tag. @@ -227,10 +227,10 @@ class Piwik_Tracker $visit->handle(); unset($visit); } else { - printDebug("The request is invalid: empty request, or maybe tracking is disabled in the config.ini.php via record_statistics=0"); + Common::printDebug("The request is invalid: empty request, or maybe tracking is disabled in the config.ini.php via record_statistics=0"); } } catch (Piwik_Tracker_Db_Exception $e) { - printDebug("" . $e->getMessage() . ""); + Common::printDebug("" . $e->getMessage() . ""); $this->exitWithException($e, $isAuthenticated); } catch (Piwik_Tracker_Visit_Excluded $e) { } catch (Exception $e) { @@ -290,7 +290,7 @@ class Piwik_Tracker if ($minimumInterval <= 0 || empty($cache['isBrowserTriggerArchivingEnabled']) ) { - printDebug("-> Scheduled tasks not running in Tracker: Browser archiving is disabled."); + Common::printDebug("-> Scheduled tasks not running in Tracker: Browser archiving is disabled."); return; } $nextRunTime = $cache['lastTrackerCronRun'] + $minimumInterval; @@ -302,7 +302,7 @@ class Piwik_Tracker Piwik_Tracker_Cache::setCacheGeneral($cache); self::initCorePiwikInTrackerMode(); Piwik_SetOption('lastTrackerCronRun', $cache['lastTrackerCronRun']); - printDebug('-> Scheduled Tasks: Starting...'); + Common::printDebug('-> Scheduled Tasks: Starting...'); // save current user privilege and temporarily assume super user privilege $isSuperUser = Piwik::isUserIsSuperUser(); @@ -319,12 +319,12 @@ class Piwik_Tracker // restore original user privilege Piwik::setUserIsSuperUser($isSuperUser); - printDebug($resultTasks); - printDebug('Finished Scheduled Tasks.'); + Common::printDebug($resultTasks); + Common::printDebug('Finished Scheduled Tasks.'); } else { - printDebug("-> Scheduled tasks not triggered."); + Common::printDebug("-> Scheduled tasks not triggered."); } - printDebug("Next run will be from: " . date('Y-m-d H:i:s', $nextRunTime) . ' UTC'); + Common::printDebug("Next run will be from: " . date('Y-m-d H:i:s', $nextRunTime) . ' UTC'); } static public $initTrackerMode = false; @@ -417,7 +417,7 @@ class Piwik_Tracker $this->handleDisabledTracker(); $this->handleEmptyRequest($request); - printDebug("Current datetime: " . date("Y-m-d H:i:s", $request->getCurrentTimestamp())); + Common::printDebug("Current datetime: " . date("Y-m-d H:i:s", $request->getCurrentTimestamp())); } /** @@ -428,11 +428,11 @@ class Piwik_Tracker switch ($this->getState()) { case self::STATE_LOGGING_DISABLE: $this->outputTransparentGif(); - printDebug("Logging disabled, display transparent logo"); + Common::printDebug("Logging disabled, display transparent logo"); break; case self::STATE_EMPTY_REQUEST: - printDebug("Empty request => Piwik page"); + Common::printDebug("Empty request => Piwik page"); echo "Piwik is a free open source web analytics that lets you keep control of your data."; break; @@ -440,10 +440,10 @@ class Piwik_Tracker case self::STATE_NOTHING_TO_NOTICE: default: $this->outputTransparentGif(); - printDebug("Nothing to notice => default behaviour"); + Common::printDebug("Nothing to notice => default behaviour"); break; } - printDebug("End of the page."); + Common::printDebug("End of the page."); if ($GLOBALS['PIWIK_TRACKER_DEBUG'] === true) { if (isset(self::$db)) { @@ -606,10 +606,10 @@ class Piwik_Tracker Piwik_PluginsManager::getInstance()->loadPlugins($pluginsTracker); - printDebug("Loading plugins: { " . implode(",", $pluginsTracker) . " }"); + Common::printDebug("Loading plugins: { " . implode(",", $pluginsTracker) . " }"); } } catch (Exception $e) { - printDebug("ERROR: " . $e->getMessage()); + Common::printDebug("ERROR: " . $e->getMessage()); } } diff --git a/core/Tracker/Action.php b/core/Tracker/Action.php index ddba2c0dcc..1fee863928 100644 --- a/core/Tracker/Action.php +++ b/core/Tracker/Action.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; /** * Interface of the Action object. @@ -388,7 +388,7 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface : array(); if (!empty($excludedParameters)) { - printDebug('Excluding parameters "' . implode(',', $excludedParameters) . '" from URL'); + Common::printDebug('Excluding parameters "' . implode(',', $excludedParameters) . '" from URL'); } $parametersToExclude = array_merge($excludedParameters, @@ -446,8 +446,8 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface $info['url'] = self::excludeQueryParametersFromUrl($originalUrl, $this->request->getIdSite()); if ($originalUrl != $info['url']) { - printDebug(' Before was "' . $originalUrl . '"'); - printDebug(' After is "' . $info['url'] . '"'); + Common::printDebug(' Before was "' . $originalUrl . '"'); + Common::printDebug(' After is "' . $info['url'] . '"'); } // Set Final attributes for this Action (Pageview, Search, etc.) @@ -547,7 +547,7 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface Piwik_Tracker::getDatabase()->query($sql, array($name, $name, $type, $urlPrefix)); $actionId = Piwik_Tracker::getDatabase()->lastInsertId(); - printDebug("Recorded a new action (" . self::getActionTypeName($type) . ") in the lookup table: " . $name . " (idaction = " . $actionId . ")"); + Common::printDebug("Recorded a new action (" . self::getActionTypeName($type) . ") in the lookup table: " . $name . " (idaction = " . $actionId . ")"); $actionNamesAndTypes[$actionToInsert][] = $actionId; } @@ -706,7 +706,7 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface 'idRefererActionName' => $idRefererActionName, 'timeSpentRefererAction' => $timeSpentRefererAction, ); - printDebug($insertWithoutNulls); + Common::printDebug($insertWithoutNulls); /* * send the Action object ($this) and the list of ids ($info) as arguments to the event @@ -721,22 +721,22 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface // Enrich Site Search actions with Custom Variables, overwriting existing values if (!empty($this->searchCategory)) { if (!empty($customVariables['custom_var_k' . self::CVAR_INDEX_SEARCH_CATEGORY])) { - printDebug("WARNING: Overwriting existing Custom Variable in slot " . self::CVAR_INDEX_SEARCH_CATEGORY . " for this page view"); + Common::printDebug("WARNING: Overwriting existing Custom Variable in slot " . self::CVAR_INDEX_SEARCH_CATEGORY . " for this page view"); } $customVariables['custom_var_k' . self::CVAR_INDEX_SEARCH_CATEGORY] = self::CVAR_KEY_SEARCH_CATEGORY; $customVariables['custom_var_v' . self::CVAR_INDEX_SEARCH_CATEGORY] = Piwik_Tracker_Request::truncateCustomVariable($this->searchCategory); } if ($this->searchCount !== false) { if (!empty($customVariables['custom_var_k' . self::CVAR_INDEX_SEARCH_COUNT])) { - printDebug("WARNING: Overwriting existing Custom Variable in slot " . self::CVAR_INDEX_SEARCH_COUNT . " for this page view"); + Common::printDebug("WARNING: Overwriting existing Custom Variable in slot " . self::CVAR_INDEX_SEARCH_COUNT . " for this page view"); } $customVariables['custom_var_k' . self::CVAR_INDEX_SEARCH_COUNT] = self::CVAR_KEY_SEARCH_COUNT; $customVariables['custom_var_v' . self::CVAR_INDEX_SEARCH_COUNT] = (int)$this->searchCount; } if (!empty($customVariables)) { - printDebug("Page level Custom Variables: "); - printDebug($customVariables); + Common::printDebug("Page level Custom Variables: "); + Common::printDebug($customVariables); } return $customVariables; } @@ -805,7 +805,7 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface $url = self::cleanupString($url); if (!Common::isLookLikeUrl($url)) { - printDebug("WARNING: URL looks invalid and is discarded"); + Common::printDebug("WARNING: URL looks invalid and is discarded"); $url = ''; } @@ -833,7 +833,7 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface { $website = Piwik_Tracker_Cache::getCacheWebsiteAttributes($this->request->getIdSite()); if (empty($website['sitesearch'])) { - printDebug("Internal 'Site Search' tracking is not enabled for this site. "); + Common::printDebug("Internal 'Site Search' tracking is not enabled for this site. "); return false; } $actionName = $url = $categoryName = $count = false; @@ -873,19 +873,19 @@ class Piwik_Tracker_Action implements Piwik_Tracker_Action_Interface } if (empty($actionName)) { - printDebug("(this is not a Site Search request)"); + Common::printDebug("(this is not a Site Search request)"); return false; } - printDebug("Detected Site Search keyword '$actionName'. "); + Common::printDebug("Detected Site Search keyword '$actionName'. "); if (!empty($categoryName)) { - printDebug("- Detected Site Search Category '$categoryName'. "); + Common::printDebug("- Detected Site Search Category '$categoryName'. "); } if ($count !== false) { - printDebug("- Search Results Count was '$count'. "); + Common::printDebug("- Search Results Count was '$count'. "); } if ($url != $originalUrl) { - printDebug("NOTE: The Page URL was changed / removed, during the Site Search detection, was '$originalUrl', now is '$url'"); + Common::printDebug("NOTE: The Page URL was changed / removed, during the Site Search detection, was '$originalUrl', now is '$url'"); } if (!empty($categoryName) || $count !== false) { diff --git a/core/Tracker/Cache.php b/core/Tracker/Cache.php index eb0b90cd86..4f7e5809f3 100644 --- a/core/Tracker/Cache.php +++ b/core/Tracker/Cache.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; +use Piwik\Config; +use Piwik\Piwik; /** * Simple cache mechanism used in Tracker to avoid requesting settings from mysql on every request diff --git a/core/Tracker/Config.php b/core/Tracker/Config.php index 1ce66aaa55..e3e35fd7e0 100644 --- a/core/Tracker/Config.php +++ b/core/Tracker/Config.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; +use Piwik\Config; /** * Backward compatibility layer diff --git a/core/Tracker/Db.php b/core/Tracker/Db.php index 6d33bc39c5..5b7cbde2cc 100644 --- a/core/Tracker/Db.php +++ b/core/Tracker/Db.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * Simple database wrapper. diff --git a/core/Tracker/GoalManager.php b/core/Tracker/GoalManager.php index fb22e339e7..719639619d 100644 --- a/core/Tracker/GoalManager.php +++ b/core/Tracker/GoalManager.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; /** * @package Piwik @@ -355,7 +355,7 @@ class Piwik_Tracker_GoalManager ); if ($this->isThereExistingCartInVisit) { - printDebug("There is an existing cart for this visit"); + Common::printDebug("There is an existing cart for this visit"); } if ($this->isGoalAnOrder) { $orderIdNumeric = Common::hashStringToInt($this->orderId); @@ -376,7 +376,7 @@ class Piwik_Tracker_GoalManager } $goal['revenue'] = $this->getRevenue($this->request->getGoalRevenue( $defaultRevenue = 0)); - printDebug($debugMessage . ':' . var_export($goal, true)); + Common::printDebug($debugMessage . ':' . var_export($goal, true)); // INSERT or Sync items in the Cart / Order for this visit & order $items = $this->getEcommerceItemsFromRequest(); @@ -409,13 +409,13 @@ class Piwik_Tracker_GoalManager { $items = Common::unsanitizeInputValue($this->request->getParam('ec_items')); if (empty($items)) { - printDebug("There are no Ecommerce items in the request"); + Common::printDebug("There are no Ecommerce items in the request"); // we still record an Ecommerce order without any item in it return array(); } $items = Common::json_decode($items, $assoc = true); if (!is_array($items)) { - printDebug("Error while json_decode the Ecommerce items = " . var_export($items, true)); + Common::printDebug("Error while json_decode the Ecommerce items = " . var_export($items, true)); return false; } @@ -451,8 +451,8 @@ class Piwik_Tracker_GoalManager $itemsInDb = Piwik_Tracker::getDatabase()->fetchAll($sql, $bind); - printDebug("Items found in current cart, for conversion_item (visit,idorder)=" . var_export($bind, true)); - printDebug($itemsInDb); + Common::printDebug("Items found in current cart, for conversion_item (visit,idorder)=" . var_export($bind, true)); + Common::printDebug($itemsInDb); // Look at which items need to be deleted, which need to be added or updated, based on the SKU $skuFoundInDb = $itemsToUpdate = array(); foreach ($itemsInDb as $itemInDb) { @@ -475,8 +475,8 @@ class Piwik_Tracker_GoalManager ); $itemsToUpdate[] = $itemToUpdate; - printDebug("Item found in the previous Cart, but no in the current cart/order"); - printDebug($itemToUpdate); + Common::printDebug("Item found in the previous Cart, but no in the current cart/order"); + Common::printDebug($itemToUpdate); continue; } @@ -484,14 +484,14 @@ class Piwik_Tracker_GoalManager $newItem = $this->getItemRowCast($newItem); if (count($itemInDb) != count($newItem)) { - printDebug("ERROR: Different format in items from cart and DB"); + Common::printDebug("ERROR: Different format in items from cart and DB"); throw new Exception(" Item in DB and Item in cart have a different format, this is not expected... " . var_export($itemInDb, true) . var_export($newItem, true)); } - printDebug("Item has changed since the last cart. Previous item stored in cart in database:"); - printDebug($itemInDb); - printDebug("New item to UPDATE the previous row:"); + Common::printDebug("Item has changed since the last cart. Previous item stored in cart in database:"); + Common::printDebug($itemInDb); + Common::printDebug("New item to UPDATE the previous row:"); $newItem['idorder_original_value'] = $itemInDbOriginal['idorder_original_value']; - printDebug($newItem); + Common::printDebug($newItem); $itemsToUpdate[] = $newItem; } @@ -649,12 +649,12 @@ class Piwik_Tracker_GoalManager if (empty($itemsToUpdate)) { return; } - printDebug("Goal data used to update ecommerce items:"); - printDebug($goal); + Common::printDebug("Goal data used to update ecommerce items:"); + Common::printDebug($goal); foreach ($itemsToUpdate as $item) { $newRow = $this->getItemRowEnriched($goal, $item); - printDebug($newRow); + Common::printDebug($newRow); $updateParts = $sqlBind = array(); foreach ($newRow AS $name => $value) { $updateParts[] = $name . " = ?"; @@ -686,8 +686,8 @@ class Piwik_Tracker_GoalManager if (empty($itemsToInsert)) { return; } - printDebug("Ecommerce items that are added to the cart/order"); - printDebug($itemsToInsert); + Common::printDebug("Ecommerce items that are added to the cart/order"); + Common::printDebug($itemsToInsert); $sql = "INSERT INTO " . Common::prefixTable('log_conversion_item') . " (idaction_sku, idaction_name, idaction_category, idaction_category2, idaction_category3, idaction_category4, idaction_category5, price, quantity, deleted, @@ -705,8 +705,8 @@ class Piwik_Tracker_GoalManager $bind = array_merge($bind, $newRow); } Piwik_Tracker::getDatabase()->query($sql, $bind); - printDebug($sql); - printDebug($bind); + Common::printDebug($sql); + Common::printDebug($bind); } protected function getItemRowEnriched($goal, $item) @@ -741,7 +741,7 @@ class Piwik_Tracker_GoalManager protected function recordStandardGoals($goal, $action, $visitorInformation) { foreach ($this->convertedGoals as $convertedGoal) { - printDebug("- Goal " . $convertedGoal['idgoal'] . " matched. Recording..."); + Common::printDebug("- Goal " . $convertedGoal['idgoal'] . " matched. Recording..."); $newGoal = $goal; $newGoal['idgoal'] = $convertedGoal['idgoal']; $newGoal['url'] = $convertedGoal['url']; @@ -775,7 +775,7 @@ class Piwik_Tracker_GoalManager { $newGoalDebug = $newGoal; $newGoalDebug['idvisitor'] = bin2hex($newGoalDebug['idvisitor']); - printDebug($newGoalDebug); + Common::printDebug($newGoalDebug); $fields = implode(", ", array_keys($newGoal)); $bindFields = Common::getSqlStringFieldsArray($newGoal); diff --git a/core/Tracker/IgnoreCookie.php b/core/Tracker/IgnoreCookie.php index 7fd2cc9fb3..7253c25520 100644 --- a/core/Tracker/IgnoreCookie.php +++ b/core/Tracker/IgnoreCookie.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; +use Piwik\Config; /** * Tracking cookies. diff --git a/core/Tracker/Referer.php b/core/Tracker/Referer.php index 1c8469f3f0..b1389c256b 100644 --- a/core/Tracker/Referer.php +++ b/core/Tracker/Referer.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Piwik diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php index e27e2eaded..c27ebe6b9a 100644 --- a/core/Tracker/Request.php +++ b/core/Tracker/Request.php @@ -1,6 +1,6 @@ isAuthenticated) { return; } - printDebug("token_auth is authenticated!"); + Common::printDebug("token_auth is authenticated!"); } else { $this->isAuthenticated = true; - printDebug("token_auth authentication not required"); + Common::printDebug("token_auth authentication not required"); } } @@ -97,7 +97,7 @@ class Piwik_Tracker_Request return true; } } - printDebug("WARNING! token_auth = $tokenAuth is not valid, Super User / Admin was NOT authenticated"); + Common::printDebug("WARNING! token_auth = $tokenAuth is not valid, Super User / Admin was NOT authenticated"); return false; } @@ -296,7 +296,7 @@ class Piwik_Tracker_Request || count($keyValue) != 2 || (!is_string($keyValue[0]) && !is_numeric($keyValue[0])) ) { - printDebug("Invalid custom variables detected (id=$id)"); + Common::printDebug("Invalid custom variables detected (id=$id)"); continue; } if (strlen($keyValue[1]) == 0) { @@ -332,7 +332,7 @@ class Piwik_Tracker_Request if (!$this->shouldUseThirdPartyCookie()) { return; } - printDebug("We manage the cookie..."); + Common::printDebug("We manage the cookie..."); $cookie = $this->makeThirdPartyCookie(); // idcookie has been generated in handleNewVisit or we simply propagate the old value @@ -346,7 +346,7 @@ class Piwik_Tracker_Request $this->getCookieName(), $this->getCookieExpire(), $this->getCookiePath()); - printDebug($cookie); + Common::printDebug($cookie); return $cookie; } @@ -379,7 +379,7 @@ class Piwik_Tracker_Request if (strlen($idVisitor) != Piwik_Tracker::LENGTH_HEX_ID_STRING) { throw new Exception("Visitor ID (cid) $idVisitor must be " . Piwik_Tracker::LENGTH_HEX_ID_STRING . " characters long"); } - printDebug("Request will be recorded for this idvisitor = " . $idVisitor); + Common::printDebug("Request will be recorded for this idvisitor = " . $idVisitor); $found = true; } diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php index c04d7f5a00..d2d87d121e 100644 --- a/core/Tracker/Visit.php +++ b/core/Tracker/Visit.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; /** * @package Piwik @@ -95,8 +95,8 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface $this->visitorCustomVariables = $this->request->getCustomVariables($scope = 'visit'); if (!empty($this->visitorCustomVariables)) { - printDebug("Visit level Custom Variables: "); - printDebug($this->visitorCustomVariables); + Common::printDebug("Visit level Custom Variables: "); + Common::printDebug($this->visitorCustomVariables); } $this->goalManager = new Piwik_Tracker_GoalManager($this->request); @@ -120,7 +120,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface $visitIsConverted = $someGoalsConverted; // if we find a idgoal in the URL, but then the goal is not valid, this is most likely a fake request if (!$someGoalsConverted) { - printDebug('Invalid goal tracking request for goal id = ' . $this->goalManager->idGoal); + Common::printDebug('Invalid goal tracking request for goal id = ' . $this->goalManager->idGoal); unset($this->goalManager); return; } @@ -129,11 +129,11 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface $action = $this->newAction(); if ($this->detectActionIsOutlinkOnAliasHost($action)) { - printDebug("INFO: The outlink URL host is one of the known host for this website. "); + Common::printDebug("INFO: The outlink URL host is one of the known host for this website. "); } if (isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) { $type = Piwik_Tracker_Action::getActionTypeName($action->getActionType()); - printDebug("Action is a $type, + Common::printDebug("Action is a $type, Action name = " . $action->getActionName() . ", Action URL = " . $action->getActionUrl()); } @@ -155,7 +155,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface $isLastActionInTheSameVisit = $this->isLastActionInTheSameVisit(); if (!$isLastActionInTheSameVisit) { - printDebug("Visitor detected, but last action was more than 30 minutes ago..."); + Common::printDebug("Visitor detected, but last action was more than 30 minutes ago..."); } // Known visit when: // ( - the visitor has the Piwik cookie with the idcookie ID used by Piwik to match the visitor @@ -268,7 +268,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface if ($incrementActions) { $sqlActionUpdate .= "visit_total_actions = visit_total_actions + 1, "; } - printDebug("Visit is known (IP = " . Piwik_IP::N2P($this->getVisitorIp()) . ")"); + Common::printDebug("Visit is known (IP = " . Piwik_IP::N2P($this->getVisitorIp()) . ")"); $datetimeServer = Piwik_Tracker::getDatetimeFromTimestamp($this->request->getCurrentTimestamp()); $valuesToUpdate['visit_last_action_time'] = $datetimeServer; @@ -332,12 +332,12 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface if (isset($valuesToUpdate['idvisitor'])) { $valuesToUpdate['idvisitor'] = bin2hex($valuesToUpdate['idvisitor']); } - printDebug('Updating existing visit: ' . var_export($valuesToUpdate, true)); + Common::printDebug('Updating existing visit: ' . var_export($valuesToUpdate, true)); if (Piwik_Tracker::getDatabase()->rowCount($result) == 0) { - printDebug("Visitor with this idvisit wasn't found in the DB."); - printDebug("$sqlQuery --- "); - printDebug($sqlBind); + Common::printDebug("Visitor with this idvisit wasn't found in the DB."); + Common::printDebug("$sqlQuery --- "); + Common::printDebug($sqlBind); throw new Piwik_Tracker_Visit_VisitorNotFoundInDatabase( "The visitor with idvisitor=" . bin2hex($this->visitorInfo['idvisitor']) . " and idvisit=" . $this->visitorInfo['idvisit'] . " wasn't found in the DB, we fallback to a new visitor"); @@ -373,7 +373,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface */ protected function handleNewVisit($idActionUrl, $idActionName, $actionType, $visitIsConverted) { - printDebug("New Visit (IP = " . Piwik_IP::N2P($this->getVisitorIp()) . ")"); + Common::printDebug("New Visit (IP = " . Piwik_IP::N2P($this->getVisitorIp()) . ")"); $daysSinceFirstVisit = $this->request->getDaysSinceFirstVisit(); $visitCount = $this->request->getVisitCount(); @@ -468,7 +468,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface $debugVisitInfo = $this->visitorInfo; $debugVisitInfo['idvisitor'] = bin2hex($debugVisitInfo['idvisitor']); $debugVisitInfo['config_id'] = bin2hex($debugVisitInfo['config_id']); - printDebug($debugVisitInfo); + Common::printDebug($debugVisitInfo); $this->saveVisitorInformation(); } @@ -643,9 +643,9 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface if ($isVisitorIdToLookup) { $this->visitorInfo['idvisitor'] = $idVisitor; - printDebug("Matching visitors with: visitorId=" . bin2hex($this->visitorInfo['idvisitor']) . " OR configId=" . bin2hex($configId)); + Common::printDebug("Matching visitors with: visitorId=" . bin2hex($this->visitorInfo['idvisitor']) . " OR configId=" . bin2hex($configId)); } else { - printDebug("Visitor doesn't have the piwik cookie..."); + Common::printDebug("Visitor doesn't have the piwik cookie..."); } $selectCustomVariables = ''; @@ -813,14 +813,14 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface } $this->visitorKnown = true; - printDebug("The visitor is known (idvisitor = " . bin2hex($this->visitorInfo['idvisitor']) . ", + Common::printDebug("The visitor is known (idvisitor = " . bin2hex($this->visitorInfo['idvisitor']) . ", config_id = " . bin2hex($configId) . ", idvisit = {$this->visitorInfo['idvisit']}, last action = " . date("r", $this->visitorInfo['visit_last_action_time']) . ", first action = " . date("r", $this->visitorInfo['visit_first_action_time']) . ", visit_goal_buyer' = " . $this->visitorInfo['visit_goal_buyer'] . ")"); } else { - printDebug("The visitor was not matched with an existing visitor..."); + Common::printDebug("The visitor was not matched with an existing visitor..."); } } diff --git a/core/Tracker/VisitExcluded.php b/core/Tracker/VisitExcluded.php index b405d435cf..fc9fbfe52f 100644 --- a/core/Tracker/VisitExcluded.php +++ b/core/Tracker/VisitExcluded.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * This class contains the logic to exclude some visitors from being tracked as per user settings @@ -45,7 +45,7 @@ class Piwik_Tracker_VisitExcluded $excluded = false; if ($this->isNonHumanBot()) { - printDebug('Search bot detected, visit excluded'); + Common::printDebug('Search bot detected, visit excluded'); $excluded = true; } @@ -57,9 +57,9 @@ class Piwik_Tracker_VisitExcluded if (!$excluded) { $toRecord = $this->request->getParam($parameterForceRecord = 'rec'); if (!$toRecord) { - printDebug(@$_SERVER['REQUEST_METHOD'] . ' parameter ' . $parameterForceRecord . ' not found in URL, request excluded'); + Common::printDebug(@$_SERVER['REQUEST_METHOD'] . ' parameter ' . $parameterForceRecord . ' not found in URL, request excluded'); $excluded = true; - printDebug("'$parameterForceRecord' parameter not found."); + Common::printDebug("'$parameterForceRecord' parameter not found."); } } @@ -75,7 +75,7 @@ class Piwik_Tracker_VisitExcluded if (!$excluded) { $excluded = $this->isIgnoreCookieFound(); if ($excluded) { - printDebug("Ignore cookie found."); + Common::printDebug("Ignore cookie found."); } } @@ -83,7 +83,7 @@ class Piwik_Tracker_VisitExcluded if (!$excluded) { $excluded = $this->isVisitorIpExcluded(); if ($excluded) { - printDebug("IP excluded."); + Common::printDebug("IP excluded."); } } @@ -91,19 +91,19 @@ class Piwik_Tracker_VisitExcluded if (!$excluded) { $excluded = $this->isUserAgentExcluded(); if ($excluded) { - printDebug("User agent excluded."); + Common::printDebug("User agent excluded."); } } if (!$excluded) { if ($this->isPrefetchDetected()) { $excluded = true; - printDebug("Prefetch request detected, not a real visit so we Ignore this visit/pageview"); + Common::printDebug("Prefetch request detected, not a real visit so we Ignore this visit/pageview"); } } if ($excluded) { - printDebug("Visitor excluded."); + Common::printDebug("Visitor excluded."); return true; } @@ -167,7 +167,7 @@ class Piwik_Tracker_VisitExcluded protected function isIgnoreCookieFound() { if (Piwik_Tracker_IgnoreCookie::isIgnoreCookieFound()) { - printDebug('Piwik ignore cookie was found, visit not tracked.'); + Common::printDebug('Piwik ignore cookie was found, visit not tracked.'); return true; } return false; @@ -183,7 +183,7 @@ class Piwik_Tracker_VisitExcluded $websiteAttributes = Piwik_Tracker_Cache::getCacheWebsiteAttributes($this->idSite); if (!empty($websiteAttributes['excluded_ips'])) { if (Piwik_IP::isIpInRange($this->ip, $websiteAttributes['excluded_ips'])) { - printDebug('Visitor IP ' . Piwik_IP::N2P($this->ip) . ' is excluded from being tracked'); + Common::printDebug('Visitor IP ' . Piwik_IP::N2P($this->ip) . ' is excluded from being tracked'); return true; } } diff --git a/core/Translate.php b/core/Translate.php index 95a2f58771..ce736265e9 100644 --- a/core/Translate.php +++ b/core/Translate.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; /** * @package Piwik diff --git a/core/TranslationWriter.php b/core/TranslationWriter.php index 5cec03e006..a103799d33 100644 --- a/core/TranslationWriter.php +++ b/core/TranslationWriter.php @@ -9,7 +9,7 @@ * @package Piwik * */ -use Piwik\Core\Common; +use Piwik\Common; /** * Write translations to file diff --git a/core/Twig.php b/core/Twig.php index 57f1b00ee6..57e2c67605 100644 --- a/core/Twig.php +++ b/core/Twig.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** diff --git a/core/UpdateCheck.php b/core/UpdateCheck.php index 0f35a966d9..85d1716f29 100644 --- a/core/UpdateCheck.php +++ b/core/UpdateCheck.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; /** * Class to check if a newer version of Piwik is available diff --git a/core/Updater.php b/core/Updater.php index b048dc6d0a..bc62eca147 100644 --- a/core/Updater.php +++ b/core/Updater.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * @see core/Option.php diff --git a/core/Updates.php b/core/Updates.php index 16e5f0d7e9..e4387d0634 100644 --- a/core/Updates.php +++ b/core/Updates.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; +use Piwik\Config; /** * Abstract class for update scripts diff --git a/core/Updates/0.2.10.php b/core/Updates/0.2.10.php index bb4358e411..a85bcb88a8 100644 --- a/core/Updates/0.2.10.php +++ b/core/Updates/0.2.10.php @@ -8,8 +8,8 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.2.12.php b/core/Updates/0.2.12.php index 5712a132ff..378ad1c724 100644 --- a/core/Updates/0.2.12.php +++ b/core/Updates/0.2.12.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.2.13.php b/core/Updates/0.2.13.php index d548761222..15c510bb25 100644 --- a/core/Updates/0.2.13.php +++ b/core/Updates/0.2.13.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.2.24.php b/core/Updates/0.2.24.php index 4533832d90..e6515309b1 100644 --- a/core/Updates/0.2.24.php +++ b/core/Updates/0.2.24.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.2.27.php b/core/Updates/0.2.27.php index 92a738f903..e88ab68ffb 100644 --- a/core/Updates/0.2.27.php +++ b/core/Updates/0.2.27.php @@ -8,8 +8,8 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.2.32.php b/core/Updates/0.2.32.php index f14b5a5892..b13a40ad18 100644 --- a/core/Updates/0.2.32.php +++ b/core/Updates/0.2.32.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.2.33.php b/core/Updates/0.2.33.php index c203db12d4..50d6a2eea3 100644 --- a/core/Updates/0.2.33.php +++ b/core/Updates/0.2.33.php @@ -8,8 +8,8 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.2.34.php b/core/Updates/0.2.34.php index 4af164a129..bfefb5b501 100644 --- a/core/Updates/0.2.34.php +++ b/core/Updates/0.2.34.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * @package Updates diff --git a/core/Updates/0.2.35.php b/core/Updates/0.2.35.php index 90f1b8fd6d..c5377fb43f 100644 --- a/core/Updates/0.2.35.php +++ b/core/Updates/0.2.35.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.2.37.php b/core/Updates/0.2.37.php index 1b3e9ad28e..a415ebbe58 100644 --- a/core/Updates/0.2.37.php +++ b/core/Updates/0.2.37.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.4.1.php b/core/Updates/0.4.1.php index 17d5b27910..1e06dd7fb3 100644 --- a/core/Updates/0.4.1.php +++ b/core/Updates/0.4.1.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.4.2.php b/core/Updates/0.4.2.php index ac931d6357..f03b443163 100644 --- a/core/Updates/0.4.2.php +++ b/core/Updates/0.4.2.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.4.php b/core/Updates/0.4.php index 2ccecc2c16..9e9e1ee0b0 100644 --- a/core/Updates/0.4.php +++ b/core/Updates/0.4.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.5.4.php b/core/Updates/0.5.4.php index f5fc2fb90a..2a48de630f 100644 --- a/core/Updates/0.5.4.php +++ b/core/Updates/0.5.4.php @@ -8,8 +8,8 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.5.5.php b/core/Updates/0.5.5.php index 1cba67d7a9..8ad736b81d 100644 --- a/core/Updates/0.5.5.php +++ b/core/Updates/0.5.5.php @@ -8,8 +8,8 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.5.php b/core/Updates/0.5.php index d465f9c225..f38c38aa46 100644 --- a/core/Updates/0.5.php +++ b/core/Updates/0.5.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.6-rc1.php b/core/Updates/0.6-rc1.php index bde19cff94..505df64ab2 100644 --- a/core/Updates/0.6-rc1.php +++ b/core/Updates/0.6-rc1.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.6.2.php b/core/Updates/0.6.2.php index d00ed5c91c..a3625a479c 100644 --- a/core/Updates/0.6.2.php +++ b/core/Updates/0.6.2.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * @package Updates diff --git a/core/Updates/0.6.3.php b/core/Updates/0.6.3.php index 7b2c21accc..b20fd75627 100644 --- a/core/Updates/0.6.3.php +++ b/core/Updates/0.6.3.php @@ -8,8 +8,8 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.7.php b/core/Updates/0.7.php index d50796fc20..6e00fc9f7f 100644 --- a/core/Updates/0.7.php +++ b/core/Updates/0.7.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/0.9.1.php b/core/Updates/0.9.1.php index f76928c314..4bc4aab764 100644 --- a/core/Updates/0.9.1.php +++ b/core/Updates/0.9.1.php @@ -8,8 +8,8 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.1.php b/core/Updates/1.1.php index cae7b1f407..de74d8c713 100644 --- a/core/Updates/1.1.php +++ b/core/Updates/1.1.php @@ -8,8 +8,8 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; +use Piwik\Config; +use Piwik\Piwik; /** * @package Updates diff --git a/core/Updates/1.10.2-b1.php b/core/Updates/1.10.2-b1.php index f6c09c6e47..e2d9f2130f 100755 --- a/core/Updates/1.10.2-b1.php +++ b/core/Updates/1.10.2-b1.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.10.2-b2.php b/core/Updates/1.10.2-b2.php index fd0907ab97..8e57c75297 100644 --- a/core/Updates/1.10.2-b2.php +++ b/core/Updates/1.10.2-b2.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.12-b1.php b/core/Updates/1.12-b1.php index 44c9eccd9d..75c69e3839 100644 --- a/core/Updates/1.12-b1.php +++ b/core/Updates/1.12-b1.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.12-b16.php b/core/Updates/1.12-b16.php index 29cfa88489..b3956fc6ce 100644 --- a/core/Updates/1.12-b16.php +++ b/core/Updates/1.12-b16.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.2-rc1.php b/core/Updates/1.2-rc1.php index beb3b97034..02101697e7 100644 --- a/core/Updates/1.2-rc1.php +++ b/core/Updates/1.2-rc1.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.2.3.php b/core/Updates/1.2.3.php index c7cc2ce03c..f479dff100 100644 --- a/core/Updates/1.2.3.php +++ b/core/Updates/1.2.3.php @@ -8,8 +8,8 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.2.5-rc1.php b/core/Updates/1.2.5-rc1.php index 7eafdd9ad9..14d4e29a60 100644 --- a/core/Updates/1.2.5-rc1.php +++ b/core/Updates/1.2.5-rc1.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.2.5-rc7.php b/core/Updates/1.2.5-rc7.php index f1b8805228..dc613a7f83 100644 --- a/core/Updates/1.2.5-rc7.php +++ b/core/Updates/1.2.5-rc7.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.4-rc1.php b/core/Updates/1.4-rc1.php index 794c512e67..6a1029a455 100644 --- a/core/Updates/1.4-rc1.php +++ b/core/Updates/1.4-rc1.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.4-rc2.php b/core/Updates/1.4-rc2.php index a25e69ffc7..c1b52dd079 100644 --- a/core/Updates/1.4-rc2.php +++ b/core/Updates/1.4-rc2.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.5-b1.php b/core/Updates/1.5-b1.php index a8c7b76d31..71670a7c6e 100644 --- a/core/Updates/1.5-b1.php +++ b/core/Updates/1.5-b1.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.5-b2.php b/core/Updates/1.5-b2.php index 9544271bce..26ca5fdd38 100644 --- a/core/Updates/1.5-b2.php +++ b/core/Updates/1.5-b2.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.5-b3.php b/core/Updates/1.5-b3.php index 6f72eb6ac5..48af21fc13 100644 --- a/core/Updates/1.5-b3.php +++ b/core/Updates/1.5-b3.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.5-b4.php b/core/Updates/1.5-b4.php index 5a869301ed..5f0c46dfec 100644 --- a/core/Updates/1.5-b4.php +++ b/core/Updates/1.5-b4.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.5-b5.php b/core/Updates/1.5-b5.php index 76729f4270..bea0539c39 100644 --- a/core/Updates/1.5-b5.php +++ b/core/Updates/1.5-b5.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.6-b1.php b/core/Updates/1.6-b1.php index ef54c76b44..992e5b01ee 100644 --- a/core/Updates/1.6-b1.php +++ b/core/Updates/1.6-b1.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.7-b1.php b/core/Updates/1.7-b1.php index 2b4567e978..04fb74269c 100644 --- a/core/Updates/1.7-b1.php +++ b/core/Updates/1.7-b1.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.7.2-rc5.php b/core/Updates/1.7.2-rc5.php index 648c2c6b04..42af42e7c8 100644 --- a/core/Updates/1.7.2-rc5.php +++ b/core/Updates/1.7.2-rc5.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.7.2-rc7.php b/core/Updates/1.7.2-rc7.php index 51d1bfa887..cb1d96851c 100755 --- a/core/Updates/1.7.2-rc7.php +++ b/core/Updates/1.7.2-rc7.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.8.3-b1.php b/core/Updates/1.8.3-b1.php index ca8c0a1c70..3f3d579e58 100644 --- a/core/Updates/1.8.3-b1.php +++ b/core/Updates/1.8.3-b1.php @@ -8,7 +8,7 @@ * @category Piwik‚ * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.8.4-b1.php b/core/Updates/1.8.4-b1.php index e36349e8d1..f230d13da6 100644 --- a/core/Updates/1.8.4-b1.php +++ b/core/Updates/1.8.4-b1.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.9-b16.php b/core/Updates/1.9-b16.php index 096e7eadf8..380a75a808 100755 --- a/core/Updates/1.9-b16.php +++ b/core/Updates/1.9-b16.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.9-b19.php b/core/Updates/1.9-b19.php index de201fcb8d..bb08141de3 100755 --- a/core/Updates/1.9-b19.php +++ b/core/Updates/1.9-b19.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.9-b9.php b/core/Updates/1.9-b9.php index b67304d93d..737454231e 100755 --- a/core/Updates/1.9-b9.php +++ b/core/Updates/1.9-b9.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.9.1-b2.php b/core/Updates/1.9.1-b2.php index f2bcb81f42..81347c0844 100644 --- a/core/Updates/1.9.1-b2.php +++ b/core/Updates/1.9.1-b2.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Updates/1.9.3-b8.php b/core/Updates/1.9.3-b8.php index 3a0db01948..52938bd166 100755 --- a/core/Updates/1.9.3-b8.php +++ b/core/Updates/1.9.3-b8.php @@ -8,7 +8,7 @@ * @category Piwik * @package Updates */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Updates diff --git a/core/Url.php b/core/Url.php index ab7b7c65e1..7ae67c1c94 100644 --- a/core/Url.php +++ b/core/Url.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * Class to retrieve absolute URL or URI components of the current URL, diff --git a/core/View.php b/core/View.php index c8ee8c3089..6d01d36329 100644 --- a/core/View.php +++ b/core/View.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * Transition for pre-Piwik 0.4.4 diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php index e8026c916a..b8195c5311 100644 --- a/core/ViewDataTable.php +++ b/core/ViewDataTable.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * This class is used to load (from the API) and customize the output of a given DataTable. diff --git a/core/ViewDataTable/GenerateGraphData.php b/core/ViewDataTable/GenerateGraphData.php index 91a1d889b7..af5f9ef132 100644 --- a/core/ViewDataTable/GenerateGraphData.php +++ b/core/ViewDataTable/GenerateGraphData.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * Reads data from the API and prepares data to give to the renderer Piwik_Visualization_Chart. diff --git a/core/ViewDataTable/GenerateGraphData/ChartEvolution.php b/core/ViewDataTable/GenerateGraphData/ChartEvolution.php index 5a51049c8e..3ce1de2d54 100644 --- a/core/ViewDataTable/GenerateGraphData/ChartEvolution.php +++ b/core/ViewDataTable/GenerateGraphData/ChartEvolution.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * Piwik_ViewDataTable_GenerateGraphData for the Evolution graph (eg. Last 30 days visits) using Piwik_Visualization_Chart_Evolution diff --git a/core/ViewDataTable/GenerateGraphHTML.php b/core/ViewDataTable/GenerateGraphHTML.php index 501f7fc558..dc7eacdc04 100644 --- a/core/ViewDataTable/GenerateGraphHTML.php +++ b/core/ViewDataTable/GenerateGraphHTML.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * This class generates the HTML code to embed graphs in the page. diff --git a/core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php b/core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php index 00c5079760..638937dc05 100644 --- a/core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php +++ b/core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * Generates HTML embed for the Evolution graph diff --git a/core/ViewDataTable/HtmlTable.php b/core/ViewDataTable/HtmlTable.php index e1bfe37f10..e7d409b853 100644 --- a/core/ViewDataTable/HtmlTable.php +++ b/core/ViewDataTable/HtmlTable.php @@ -8,9 +8,9 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * Outputs an AJAX Table for a given DataTable. diff --git a/core/ViewDataTable/HtmlTable/Goals.php b/core/ViewDataTable/HtmlTable/Goals.php index 6e1ddb535d..dbe8fc8338 100644 --- a/core/ViewDataTable/HtmlTable/Goals.php +++ b/core/ViewDataTable/HtmlTable/Goals.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * @package Piwik diff --git a/core/ViewDataTable/Sparkline.php b/core/ViewDataTable/Sparkline.php index f20d3bc1ec..ae85101a78 100644 --- a/core/ViewDataTable/Sparkline.php +++ b/core/ViewDataTable/Sparkline.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * Reads the requested DataTable from the API and prepare data for the Sparkline view. diff --git a/core/Visualization/Chart.php b/core/Visualization/Chart.php index 3c6374e852..cee6b08ab7 100644 --- a/core/Visualization/Chart.php +++ b/core/Visualization/Chart.php @@ -8,8 +8,8 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * Generates the data in the Open Flash Chart format, from the given data. diff --git a/core/Visualization/Cloud.php b/core/Visualization/Cloud.php index 9d37bf9423..781973340c 100644 --- a/core/Visualization/Cloud.php +++ b/core/Visualization/Cloud.php @@ -8,7 +8,7 @@ * @category Piwik * @package Piwik */ -use Piwik\Core\Common; +use Piwik\Common; /** * Generates a tag cloud from a given data array. diff --git a/js/index.php b/js/index.php index c0a3a00d0d..6c67ffdc81 100644 --- a/js/index.php +++ b/js/index.php @@ -5,7 +5,7 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * Tracker proxy diff --git a/misc/cron/archive.php b/misc/cron/archive.php index 88dfb56851..280574ac64 100644 --- a/misc/cron/archive.php +++ b/misc/cron/archive.php @@ -1,7 +1,7 @@ " . var_export($_GET, true)); + Common::printDebug("Debug enabled - Input parameters:
" . var_export($_GET, true)); Piwik_Tracker_Db::enableProfiling(); Piwik::createConfigObject(); Piwik::createLogObject(); @@ -81,7 +81,7 @@ if (!defined('PIWIK_ENABLE_TRACKING') || PIWIK_ENABLE_TRACKING) { } ob_end_flush(); if ($GLOBALS['PIWIK_TRACKER_DEBUG'] === true) { - printDebug($_COOKIE); - printDebug($timer); + Common::printDebug($_COOKIE); + Common::printDebug($timer); } } diff --git a/plugins/API/API.php b/plugins/API/API.php index 16cba3ce4e..2dc0ce766d 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -8,8 +8,11 @@ * @category Piwik_Plugins * @package Piwik_API */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; +use Piwik\Config; + +require_once PIWIK_INCLUDE_PATH . '/core/Config.php'; /** * @package Piwik_API @@ -553,7 +556,7 @@ class Piwik_API_API } $urls = array_map('urldecode', $urls); - $urls = array_map(array('Piwik\Core\Common', 'unsanitizeInputValue'), $urls); + $urls = array_map(array('Piwik\Common', 'unsanitizeInputValue'), $urls); $result = array(); foreach ($urls as $url) { @@ -629,7 +632,7 @@ class Piwik_API_API arsort($values); $values = array_keys($values); - $values = array_map(array('Piwik\Core\Common', 'unsanitizeInputValue'), $values); + $values = array_map(array('Piwik\Common', 'unsanitizeInputValue'), $values); $values = array_slice($values, 0, $maxSuggestionsToReturn); return $values; diff --git a/plugins/API/Controller.php b/plugins/API/Controller.php index c18bfc3e85..16d8f9dd1f 100644 --- a/plugins/API/Controller.php +++ b/plugins/API/Controller.php @@ -8,8 +8,8 @@ * @category Piwik_Plugins * @package Piwik_API */ -use Piwik\Core\Config; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Common; /** * diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php index 2417a558ab..70b51f91a5 100644 --- a/plugins/API/ProcessedReport.php +++ b/plugins/API/ProcessedReport.php @@ -1,6 +1,6 @@ getUserAgent(); if (strpos($ua, 'MSIE 10') !== false) { - printDebug("INTERNET EXPLORER 10 Enables DNT by default, so Piwik ignores DNT for all IE10 browsers..."); + Common::printDebug("INTERNET EXPLORER 10 Enables DNT by default, so Piwik ignores DNT for all IE10 browsers..."); return; } $exclude = true; - printDebug("DoNotTrack found."); + Common::printDebug("DoNotTrack found."); $trackingCookie = Piwik_Tracker_IgnoreCookie::getTrackingCookie(); $trackingCookie->delete(); diff --git a/plugins/ExampleAPI/API.php b/plugins/ExampleAPI/API.php index 185aa2174d..163d265c27 100644 --- a/plugins/ExampleAPI/API.php +++ b/plugins/ExampleAPI/API.php @@ -8,7 +8,7 @@ * @category Piwik_Plugins * @package Piwik_ExampleAPI */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * The ExampleAPI is useful to developers building a custom Piwik plugin. diff --git a/plugins/ExamplePlugin/Controller.php b/plugins/ExamplePlugin/Controller.php index 45857cbc0b..1bcb01479b 100644 --- a/plugins/ExamplePlugin/Controller.php +++ b/plugins/ExamplePlugin/Controller.php @@ -8,8 +8,8 @@ * @category Piwik_Plugins * @package Piwik_ExamplePlugin */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * diff --git a/plugins/ExampleUI/Controller.php b/plugins/ExampleUI/Controller.php index 597dea4c0f..5ee8ffddd7 100644 --- a/plugins/ExampleUI/Controller.php +++ b/plugins/ExampleUI/Controller.php @@ -8,7 +8,7 @@ * @category Piwik_Plugins * @package Piwik_ExampleUI */ -use Piwik\Core\Common; +use Piwik\Common; /** * @package Piwik_ExampleUI diff --git a/plugins/Feedback/Controller.php b/plugins/Feedback/Controller.php index 3ba8fa5b5a..243a36bacd 100644 --- a/plugins/Feedback/Controller.php +++ b/plugins/Feedback/Controller.php @@ -8,9 +8,9 @@ * @category Piwik_Plugins * @package Piwik_Feedback */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * diff --git a/plugins/Goals/API.php b/plugins/Goals/API.php index bddaf7b98e..3249a3ac1e 100644 --- a/plugins/Goals/API.php +++ b/plugins/Goals/API.php @@ -8,8 +8,8 @@ * @category Piwik_Plugins * @package Piwik_Goals */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * Goals API lets you Manage existing goals, via "updateGoal" and "deleteGoal", create new Goals via "addGoal", diff --git a/plugins/Goals/Controller.php b/plugins/Goals/Controller.php index ea38907bae..93bdd66b89 100644 --- a/plugins/Goals/Controller.php +++ b/plugins/Goals/Controller.php @@ -8,8 +8,8 @@ * @category Piwik_Plugins * @package Piwik_Goals */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php index 9549dc2fb1..e612295dc1 100644 --- a/plugins/Goals/Goals.php +++ b/plugins/Goals/Goals.php @@ -8,8 +8,8 @@ * @category Piwik_Plugins * @package Piwik_Goals */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * diff --git a/plugins/ImageGraph/API.php b/plugins/ImageGraph/API.php index c240a04ecc..4087b7a18d 100644 --- a/plugins/ImageGraph/API.php +++ b/plugins/ImageGraph/API.php @@ -8,8 +8,8 @@ * @category Piwik_Plugins * @package Piwik_ImageGraph */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * The ImageGraph.get API call lets you generate beautiful static PNG Graphs for any existing Piwik report. diff --git a/plugins/ImageGraph/Controller.php b/plugins/ImageGraph/Controller.php index 4cabcd9633..cd7700ef23 100644 --- a/plugins/ImageGraph/Controller.php +++ b/plugins/ImageGraph/Controller.php @@ -1,6 +1,6 @@ getLocation($info); } } - printDebug("FAILED to lookup the geo location of this IP address, as no fallback location providers is configured. We recommend to configure Geolocation PECL module to fix this error."); + Common::printDebug("FAILED to lookup the geo location of this IP address, as no fallback location providers is configured. We recommend to configure Geolocation PECL module to fix this error."); return false; } diff --git a/plugins/UserCountry/UserCountry.php b/plugins/UserCountry/UserCountry.php index 3171a92e7c..d6e673e697 100644 --- a/plugins/UserCountry/UserCountry.php +++ b/plugins/UserCountry/UserCountry.php @@ -8,8 +8,8 @@ * @category Piwik_Plugins * @package Piwik_UserCountry */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * @see plugins/UserCountry/GeoIPAutoUpdater.php @@ -69,7 +69,7 @@ class Piwik_UserCountry extends Piwik_Plugin if ($provider === false) { $id = Piwik_UserCountry_LocationProvider_Default::ID; $provider = Piwik_UserCountry_LocationProvider::getProviderById($id); - printDebug("GEO: no current location provider sent, falling back to default '$id' one."); + Common::printDebug("GEO: no current location provider sent, falling back to default '$id' one."); } $location = $provider->getLocation($visitorInfo); @@ -79,10 +79,10 @@ class Piwik_UserCountry extends Piwik_Plugin $defaultId = Piwik_UserCountry_LocationProvider_Default::ID; $provider = Piwik_UserCountry_LocationProvider::getProviderById($defaultId); $location = $provider->getLocation($visitorInfo); - printDebug("GEO: couldn't find a location with Geo Module '$id', using Default '$defaultId' provider as fallback..."); + Common::printDebug("GEO: couldn't find a location with Geo Module '$id', using Default '$defaultId' provider as fallback..."); $id = $defaultId; } - printDebug("GEO: Found IP location (provider '" . $id . "'): " . var_export($location, true)); + Common::printDebug("GEO: Found IP location (provider '" . $id . "'): " . var_export($location, true)); } function addWidgets() diff --git a/plugins/UserCountryMap/Controller.php b/plugins/UserCountryMap/Controller.php index 6eee81eed6..08989db237 100644 --- a/plugins/UserCountryMap/Controller.php +++ b/plugins/UserCountryMap/Controller.php @@ -8,8 +8,8 @@ * @category Piwik_Plugins * @package Piwik_UserCountryMap */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * diff --git a/plugins/UserSettings/API.php b/plugins/UserSettings/API.php index 23a538e7f1..2a8c7584de 100644 --- a/plugins/UserSettings/API.php +++ b/plugins/UserSettings/API.php @@ -8,7 +8,7 @@ * @category Piwik_Plugins * @package Piwik_UserSettings */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * @see plugins/UserSettings/functions.php diff --git a/plugins/UserSettings/Archiver.php b/plugins/UserSettings/Archiver.php index 95f7f5f107..cdfd893faf 100644 --- a/plugins/UserSettings/Archiver.php +++ b/plugins/UserSettings/Archiver.php @@ -9,7 +9,7 @@ * @package Piwik_UserSettings */ -use Piwik\Core\Common; +use Piwik\Common; require_once PIWIK_INCLUDE_PATH . '/plugins/UserSettings/functions.php'; diff --git a/plugins/UserSettings/functions.php b/plugins/UserSettings/functions.php index 8adc92b245..86164eb5a1 100644 --- a/plugins/UserSettings/functions.php +++ b/plugins/UserSettings/functions.php @@ -8,7 +8,7 @@ * @category Piwik_Plugins * @package Piwik_UserSettings */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * @see libs/UserAgentParser/UserAgentParser.php diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 0ed1aaf7aa..3a804c70f0 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -8,9 +8,9 @@ * @category Piwik_Plugins * @package Piwik_UsersManager */ -use Piwik\Core\Config; -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Common; /** * The UsersManager API lets you Manage Users and their permissions to access specific websites. diff --git a/plugins/UsersManager/Controller.php b/plugins/UsersManager/Controller.php index ac3aaab360..9c8cae77ca 100644 --- a/plugins/UsersManager/Controller.php +++ b/plugins/UsersManager/Controller.php @@ -8,8 +8,8 @@ * @category Piwik_Plugins * @package Piwik_UsersManager */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * diff --git a/plugins/UsersManager/UsersManager.php b/plugins/UsersManager/UsersManager.php index 82d02f36bf..58f585da67 100644 --- a/plugins/UsersManager/UsersManager.php +++ b/plugins/UsersManager/UsersManager.php @@ -8,7 +8,7 @@ * @category Piwik_Plugins * @package Piwik_UsersManager */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * Manage Piwik users diff --git a/plugins/VisitFrequency/API.php b/plugins/VisitFrequency/API.php index 5b7161b7be..49473b5192 100644 --- a/plugins/VisitFrequency/API.php +++ b/plugins/VisitFrequency/API.php @@ -8,7 +8,7 @@ * @category Piwik_Plugins * @package Piwik_VisitFrequency */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * VisitFrequency API lets you access a list of metrics related to Returning Visitors. diff --git a/plugins/VisitFrequency/Controller.php b/plugins/VisitFrequency/Controller.php index 6cac26d504..c9362959cc 100644 --- a/plugins/VisitFrequency/Controller.php +++ b/plugins/VisitFrequency/Controller.php @@ -8,8 +8,8 @@ * @category Piwik_Plugins * @package Piwik_VisitFrequency */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * diff --git a/plugins/VisitTime/API.php b/plugins/VisitTime/API.php index f473ae6ab3..05dad866b9 100644 --- a/plugins/VisitTime/API.php +++ b/plugins/VisitTime/API.php @@ -8,7 +8,7 @@ * @category Piwik_Plugins * @package Piwik_VisitTime */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * VisitTime API lets you access reports by Hour (Server time), and by Hour Local Time of your visitors. diff --git a/plugins/VisitTime/VisitTime.php b/plugins/VisitTime/VisitTime.php index 990bf350e3..dad9c46fec 100644 --- a/plugins/VisitTime/VisitTime.php +++ b/plugins/VisitTime/VisitTime.php @@ -8,7 +8,7 @@ * @category Piwik_Plugins * @package Piwik_VisitTime */ -use Piwik\Core\Common; +use Piwik\Common; /** * diff --git a/plugins/VisitorGenerator/Controller.php b/plugins/VisitorGenerator/Controller.php index 813984b2ed..606e8784c7 100644 --- a/plugins/VisitorGenerator/Controller.php +++ b/plugins/VisitorGenerator/Controller.php @@ -8,8 +8,8 @@ * @category Piwik_Plugins * @package Piwik_VisitorGenerator */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * diff --git a/plugins/VisitorGenerator/VisitorGenerator.php b/plugins/VisitorGenerator/VisitorGenerator.php index dc23e4f60d..7423f3a900 100644 --- a/plugins/VisitorGenerator/VisitorGenerator.php +++ b/plugins/VisitorGenerator/VisitorGenerator.php @@ -8,7 +8,7 @@ * @category Piwik_Plugins * @package Piwik_VisitorGenerator */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * diff --git a/plugins/VisitorInterest/API.php b/plugins/VisitorInterest/API.php index 35e89c9896..33251a7232 100644 --- a/plugins/VisitorInterest/API.php +++ b/plugins/VisitorInterest/API.php @@ -8,7 +8,7 @@ * @category Piwik_Plugins * @package Piwik_VisitorInterest */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * VisitorInterest API lets you access two Visitor Engagement reports: number of visits per number of pages, diff --git a/plugins/VisitsSummary/API.php b/plugins/VisitsSummary/API.php index a7c0ecda71..6e4399c384 100644 --- a/plugins/VisitsSummary/API.php +++ b/plugins/VisitsSummary/API.php @@ -8,7 +8,7 @@ * @category Piwik_Plugins * @package Piwik_VisitsSummary */ -use Piwik\Core\Piwik; +use Piwik\Piwik; /** * VisitsSummary API lets you access the core web analytics metrics (visits, unique visitors, diff --git a/plugins/VisitsSummary/Controller.php b/plugins/VisitsSummary/Controller.php index 02ab257ac5..8a4552f473 100644 --- a/plugins/VisitsSummary/Controller.php +++ b/plugins/VisitsSummary/Controller.php @@ -8,8 +8,8 @@ * @category Piwik_Plugins * @package Piwik_VisitsSummary */ -use Piwik\Core\Piwik; -use Piwik\Core\Common; +use Piwik\Piwik; +use Piwik\Common; /** * diff --git a/plugins/Widgetize/Controller.php b/plugins/Widgetize/Controller.php index be6b56a37b..dad2506936 100644 --- a/plugins/Widgetize/Controller.php +++ b/plugins/Widgetize/Controller.php @@ -8,7 +8,7 @@ * @category Piwik_Plugins * @package Piwik_Widgetize */ -use Piwik\Core\Common; +use Piwik\Common; /** * -- cgit v1.2.3