diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-08-11 21:28:30 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-08-11 21:28:30 +0400 |
commit | d293408450bc8b0c0f79934da6a43914626935ae (patch) | |
tree | e50c0df2f698b6033e13f963b9a16a01ef5bf020 /plugins | |
parent | 3b74ae5cdac37e16315c3a24ecf2591f742ca3c7 (diff) | |
parent | 2340530c1109a37527f3b8ad0b82e54e7a6eb137 (diff) |
Merge branch 'plugin_namespaces'
Conflicts:
plugins/UserCountryMap/Controller.php
Diffstat (limited to 'plugins')
193 files changed, 2738 insertions, 2312 deletions
diff --git a/plugins/API/API.php b/plugins/API/API.php index d1ea3c6eb8..7058bdb0ce 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -8,6 +8,8 @@ * @category Piwik_Plugins * @package Piwik_API */ +namespace Piwik\Plugins\API; + use Piwik\API\Request; use Piwik\API\Proxy; use Piwik\DataTable\Filter\ColumnDelete; @@ -20,56 +22,11 @@ use Piwik\Date; use Piwik\DataTable; use Piwik\Tracker\GoalManager; use Piwik\Version; -use Piwik\Plugin; use Piwik\Translate; require_once PIWIK_INCLUDE_PATH . '/core/Config.php'; /** - * @package Piwik_API - */ -class Piwik_API extends Plugin -{ - /** - * @see Piwik_Plugin::getListHooksRegistered - */ - public function getListHooksRegistered() - { - return array( - 'AssetManager.getCssFiles' => 'getCssFiles', - 'TopMenu.add' => 'addTopMenu', - ); - } - - public function addTopMenu() - { - $apiUrlParams = array('module' => 'API', 'action' => 'listAllAPI', 'segment' => false); - $tooltip = Piwik_Translate('API_TopLinkTooltip'); - - Piwik_AddTopMenu('General_API', $apiUrlParams, true, 7, $isHTML = false, $tooltip); - - $this->addTopMenuMobileApp(); - } - - protected function addTopMenuMobileApp() - { - if (empty($_SERVER['HTTP_USER_AGENT'])) { - return; - } - require_once PIWIK_INCLUDE_PATH . '/libs/UserAgentParser/UserAgentParser.php'; - $os = UserAgentParser::getOperatingSystem($_SERVER['HTTP_USER_AGENT']); - if ($os && in_array($os['id'], array('AND', 'IPD', 'IPA', 'IPH'))) { - Piwik_AddTopMenu('Piwik Mobile App', array('module' => 'Proxy', 'action' => 'redirect', 'url' => 'http://piwik.org/mobile/'), true, 4); - } - } - - public function getCssFiles(&$cssFiles) - { - $cssFiles[] = "plugins/API/stylesheets/listAllAPI.less"; - } -} - -/** * This API is the <a href='http://piwik.org/docs/analytics-api/metadata/' target='_blank'>Metadata API</a>: it gives information about all other available APIs methods, as well as providing * human readable and more complete outputs than normal API methods. * @@ -87,12 +44,12 @@ class Piwik_API extends Plugin * * @package Piwik_API */ -class Piwik_API_API +class API { static private $instance = null; /** - * @return Piwik_API_API + * @return \Piwik\Plugins\API\API */ static public function getInstance() { @@ -230,7 +187,7 @@ class Piwik_API_API 'acceptedValues' => implode(", ", self::$visitEcommerceStatus) . '. ' . Piwik_Translate('General_EcommerceVisitStatusEg', '"&segment=visitEcommerceStatus==ordered,visitEcommerceStatus==orderedThenAbandonedCart"'), 'sqlSegment' => 'log_visit.visit_goal_buyer', - 'sqlFilter' => array('Piwik_API_API', 'getVisitEcommerceStatus'), + 'sqlFilter' => __NAMESPACE__ . '\API::getVisitEcommerceStatus', ); $segments[] = array( @@ -268,7 +225,7 @@ class Piwik_API_API static public function getVisitEcommerceStatusFromId($id) { if (!isset(self::$visitEcommerceStatus[$id])) { - throw new Exception("Unexpected ECommerce status value "); + throw new \Exception("Unexpected ECommerce status value "); } return self::$visitEcommerceStatus[$id]; } @@ -280,7 +237,7 @@ class Piwik_API_API { $id = array_search($status, self::$visitEcommerceStatus); if ($id === false) { - throw new Exception("Invalid 'visitEcommerceStatus' segment value"); + throw new \Exception("Invalid 'visitEcommerceStatus' segment value"); } return $id; } @@ -396,8 +353,8 @@ class Piwik_API_API $period = false, $date = false, $hideMetricsDoc = false, $showSubtableReports = false) { Translate::getInstance()->reloadLanguage($language); - $reporter = new Piwik_API_ProcessedReport(); - $metadata = $reporter->getMetadata($idSite, $apiModule, $apiAction, $apiParameters, $language, $period, $date, $hideMetricsDoc, $showSubtableReports); + $reporter = new ProcessedReport(); + $metadata = $reporter->getMetadata($idSite, $apiModule, $apiAction, $apiParameters, $language, $period, $date, $hideMetricsDoc, $showSubtableReports); return $metadata; } @@ -415,8 +372,8 @@ class Piwik_API_API public function getReportMetadata($idSites = '', $period = false, $date = false, $hideMetricsDoc = false, $showSubtableReports = false) { - $reporter = new Piwik_API_ProcessedReport(); - $metadata = $reporter->getReportMetadata($idSites, $period, $date, $hideMetricsDoc, $showSubtableReports); + $reporter = new ProcessedReport(); + $metadata = $reporter->getReportMetadata($idSites, $period, $date, $hideMetricsDoc, $showSubtableReports); return $metadata; } @@ -424,8 +381,8 @@ class Piwik_API_API $apiParameters = false, $idGoal = false, $language = false, $showTimer = true, $hideMetricsDoc = false, $idSubtable = false, $showRawMetrics = false) { - $reporter = new Piwik_API_ProcessedReport(); - $processed = $reporter->getProcessedReport( $idSite, $period, $date, $apiModule, $apiAction, $segment, + $reporter = new ProcessedReport(); + $processed = $reporter->getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment, $apiParameters, $idGoal, $language, $showTimer, $hideMetricsDoc, $idSubtable, $showRawMetrics); return $processed; @@ -446,7 +403,7 @@ class Piwik_API_API // find out which columns belong to which plugin $columnsByPlugin = array(); - $meta = Piwik_API_API::getInstance()->getReportMetadata($idSite, $period, $date); + $meta = \Piwik\Plugins\API\API::getInstance()->getReportMetadata($idSite, $period, $date); foreach ($meta as $reportMeta) { // scan all *.get reports if ($reportMeta['action'] == 'get' @@ -472,7 +429,7 @@ class Piwik_API_API $params = compact('idSite', 'period', 'date', 'segment', 'idGoal'); foreach ($columnsByPlugin as $plugin => $columns) { // load the data - $className = 'Piwik_' . $plugin . '_API'; + $className = Request::getClassNameAPI($plugin); $params['columns'] = implode(',', $columns); $dataTable = Proxy::getInstance()->call($className, 'get', $params); // make sure the table has all columns @@ -549,7 +506,7 @@ class Piwik_API_API */ public function getRowEvolution($idSite, $period, $date, $apiModule, $apiAction, $label = false, $segment = false, $column = false, $language = false, $idGoal = false, $legendAppendMetric = true, $labelUseAbsoluteUrl = true) { - $rowEvolution = new Piwik_API_RowEvolution(); + $rowEvolution = new RowEvolution(); return $rowEvolution->getRowEvolution($idSite, $period, $date, $apiModule, $apiAction, $label, $segment, $column, $language, $idGoal, $legendAppendMetric, $labelUseAbsoluteUrl); } @@ -603,12 +560,12 @@ class Piwik_API_API $startDate = Date::now()->subDay(60)->toString(); $requestLastVisits = "method=Live.getLastVisitsDetails - &idSite=$idSite - &period=range - &date=$startDate,today - &format=original - &serialize=0 - &flat=1"; + &idSite=$idSite + &period=range + &date=$startDate,today + &format=original + &serialize=0 + &flat=1"; // Select non empty fields only // Note: this optimization has only a very minor impact @@ -663,3 +620,53 @@ class Piwik_API_API return $doesSegmentNeedActionsInfo; } } + +/** + * @package Piwik_API + */ +class Plugin extends \Piwik\Plugin +{ + public function __construct() + { + // this class is named 'Plugin', manually set the 'API' plugin + parent::__construct($pluginName = 'API'); + } + + /** + * @see Piwik_Plugin::getListHooksRegistered + */ + public function getListHooksRegistered() + { + return array( + 'AssetManager.getCssFiles' => 'getCssFiles', + 'TopMenu.add' => 'addTopMenu', + ); + } + + public function addTopMenu() + { + $apiUrlParams = array('module' => 'API', 'action' => 'listAllAPI', 'segment' => false); + $tooltip = Piwik_Translate('API_TopLinkTooltip'); + + Piwik_AddTopMenu('General_API', $apiUrlParams, true, 7, $isHTML = false, $tooltip); + + $this->addTopMenuMobileApp(); + } + + protected function addTopMenuMobileApp() + { + if (empty($_SERVER['HTTP_USER_AGENT'])) { + return; + } + require_once PIWIK_INCLUDE_PATH . '/libs/UserAgentParser/UserAgentParser.php'; + $os = \UserAgentParser::getOperatingSystem($_SERVER['HTTP_USER_AGENT']); + if ($os && in_array($os['id'], array('AND', 'IPD', 'IPA', 'IPH'))) { + Piwik_AddTopMenu('Piwik Mobile App', array('module' => 'Proxy', 'action' => 'redirect', 'url' => 'http://piwik.org/mobile/'), true, 4); + } + } + + public function getCssFiles(&$cssFiles) + { + $cssFiles[] = "plugins/API/stylesheets/listAllAPI.less"; + } +}
\ No newline at end of file diff --git a/plugins/API/Controller.php b/plugins/API/Controller.php index ed4addae2c..ac8e31ac84 100644 --- a/plugins/API/Controller.php +++ b/plugins/API/Controller.php @@ -8,19 +8,21 @@ * @category Piwik_Plugins * @package Piwik_API */ +namespace Piwik\Plugins\API; + use Piwik\API\DocumentationGenerator; use Piwik\API\Request; use Piwik\API\Proxy; use Piwik\Config; use Piwik\Common; -use Piwik\Controller; +use Piwik\Plugins\API\API; use Piwik\View; /** * * @package Piwik_API */ -class Piwik_API_Controller extends Controller +class Controller extends \Piwik\Controller { function index() { @@ -51,7 +53,7 @@ class Piwik_API_Controller extends Controller public function listSegments() { - $segments = Piwik_API_API::getInstance()->getSegmentsMetadata($this->idSite); + $segments = API::getInstance()->getSegmentsMetadata($this->idSite); $tableDimensions = $tableMetrics = ''; $customVariables = 0; @@ -98,7 +100,6 @@ class Piwik_API_Controller extends Controller } } - if ($segment['type'] == 'dimension') { $tableDimensions .= $output; } else { diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php index 3491372420..92e82aa275 100644 --- a/plugins/API/ProcessedReport.php +++ b/plugins/API/ProcessedReport.php @@ -1,4 +1,16 @@ <?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik_Plugins + * @package Piwik_API + */ +namespace Piwik\Plugins\API; + +use Exception; use Piwik\API\Request; use Piwik\DataTable\Simple; use Piwik\DataTable\Row; @@ -12,18 +24,7 @@ use Piwik\Url; use Piwik\Timer; use Piwik\Site; -/** - * Piwik - Open source web analytics - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - * @category Piwik_Plugins - * @package Piwik_API - */ - - -class Piwik_API_ProcessedReport +class ProcessedReport { /** @@ -175,7 +176,6 @@ class Piwik_API_ProcessedReport return array_values($availableReports); // make sure array has contiguous key values } - /** * API metadata are sorted by category/name, * with a little tweak to replicate the standard Piwik category ordering @@ -240,8 +240,6 @@ class Piwik_API_ProcessedReport $availableReports[] = $metadata; } - - public function getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment = false, $apiParameters = false, $idGoal = false, $language = false, $showTimer = true, $hideMetricsDoc = false, $idSubtable = false, $showRawMetrics = false) @@ -554,5 +552,4 @@ class Piwik_API_ProcessedReport $rowsMetadata ); } - } diff --git a/plugins/API/RowEvolution.php b/plugins/API/RowEvolution.php index cbc50d2e1c..a565424763 100644 --- a/plugins/API/RowEvolution.php +++ b/plugins/API/RowEvolution.php @@ -8,6 +8,9 @@ * @category Piwik_Plugins * @package Piwik_API */ +namespace Piwik\Plugins\API; + +use Exception; use Piwik\API\DataTableManipulator\LabelFilter; use Piwik\API\ResponseBuilder; use Piwik\API\Request; @@ -25,7 +28,7 @@ use Piwik\Url; * * @package Piwik_API */ -class Piwik_API_RowEvolution +class RowEvolution { public function getRowEvolution($idSite, $period, $date, $apiModule, $apiAction, $label = false, $segment = false, $column = false, $language = false, $idGoal = false, $legendAppendMetric = true, $labelUseAbsoluteUrl = true) @@ -43,7 +46,6 @@ class Piwik_API_RowEvolution $label = ResponseBuilder::unsanitizeLabelParameter($label); $labels = Piwik::getArrayFromApiParameter($label); - $dataTable = $this->loadRowEvolutionDataFromAPI($idSite, $period, $date, $apiModule, $apiAction, $labels, $segment, $idGoal); if (empty($labels)) { @@ -290,8 +292,8 @@ class Piwik_API_RowEvolution if (!empty($idGoal) && $idGoal > 0) { $apiParameters = array('idGoal' => $idGoal); } - $reportMetadata = Piwik_API_API::getInstance()->getMetadata($idSite, $apiModule, $apiAction, $apiParameters, $language, - $period, $date, $hideMetricsDoc = false, $showSubtableReports = true); + $reportMetadata = API::getInstance()->getMetadata($idSite, $apiModule, $apiAction, $apiParameters, $language, + $period, $date, $hideMetricsDoc = false, $showSubtableReports = true); if (empty($reportMetadata)) { throw new Exception("Requested report $apiModule.$apiAction for Website id=$idSite " @@ -480,17 +482,14 @@ class Piwik_API_RowEvolution private function getRowEvolutionRowFromLabelIdx($table, $labelIdx) { $labelIdx = (int)$labelIdx; - foreach ($table->getRows() as $row) - { - if ($row->getMetadata(LabelFilter::FLAG_IS_ROW_EVOLUTION) === $labelIdx) - { + foreach ($table->getRows() as $row) { + if ($row->getMetadata(LabelFilter::FLAG_IS_ROW_EVOLUTION) === $labelIdx) { return $row; } } return false; } - /** * Returns a prettier, more comprehensible version of a row evolution label * for display. diff --git a/plugins/Actions/API.php b/plugins/Actions/API.php index 538adccc8b..81402e5f2d 100644 --- a/plugins/Actions/API.php +++ b/plugins/Actions/API.php @@ -6,15 +6,22 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Actions + * @package Actions */ +namespace Piwik\Plugins\Actions; + +use Exception; use Piwik\Archive; use Piwik\Metrics; use Piwik\Piwik; use Piwik\Common; use Piwik\Date; use Piwik\DataTable; +use Piwik\Plugins\Actions\Actions; use Piwik\Tracker\Action; +use Piwik\Plugins\Actions\Archiver; +use Piwik\Plugins\Actions\ArchivingHelper; +use Piwik\Plugins\CustomVariables\API as CustomVariablesAPI; /** * The Actions API lets you request reports for all your Visitor Actions: Page URLs, Page titles (Piwik Events), @@ -28,14 +35,14 @@ use Piwik\Tracker\Action; * and an outlink via "getOutlink". * * Note: pageName, pageUrl, outlinkUrl, downloadUrl parameters must be URL encoded before you call the API. - * @package Piwik_Actions + * @package Actions */ -class Piwik_Actions_API +class API { static private $instance = null; /** - * @return Piwik_Actions_API + * @return \Piwik\Plugins\Actions\API */ static public function getInstance() { @@ -60,7 +67,7 @@ class Piwik_Actions_API Piwik::checkUserHasViewAccess($idSite); $archive = Archive::build($idSite, $period, $date, $segment); - $metrics = Piwik_Actions_Archiver::$actionsAggregateMetrics; + $metrics = Archiver::$actionsAggregateMetrics; $metrics['Actions_avg_time_generation'] = 'avg_time_generation'; // get requested columns @@ -89,13 +96,13 @@ class Piwik_Actions_API } if ($avgGenerationTimeRequested) { - $tempColumns[] = Piwik_Actions_Archiver::METRIC_SUM_TIME_RECORD_NAME; - $tempColumns[] = Piwik_Actions_Archiver::METRIC_HITS_TIMED_RECORD_NAME; + $tempColumns[] = Archiver::METRIC_SUM_TIME_RECORD_NAME; + $tempColumns[] = Archiver::METRIC_HITS_TIMED_RECORD_NAME; $columns = array_merge($columns, $tempColumns); $columns = array_unique($columns); - $nameReplace[Piwik_Actions_Archiver::METRIC_SUM_TIME_RECORD_NAME] = 'sum_time_generation'; - $nameReplace[Piwik_Actions_Archiver::METRIC_HITS_TIMED_RECORD_NAME] = 'nb_hits_with_time_generation'; + $nameReplace[Archiver::METRIC_SUM_TIME_RECORD_NAME] = 'sum_time_generation'; + $nameReplace[Archiver::METRIC_HITS_TIMED_RECORD_NAME] = 'nb_hits_with_time_generation'; } $table = $archive->getDataTableFromNumeric($columns); @@ -334,8 +341,8 @@ class Piwik_Actions_API */ public function getSiteSearchCategories($idSite, $period, $date, $segment = false) { - Piwik_Actions::checkCustomVariablesPluginEnabled(); - $customVariables = Piwik_CustomVariables_API::getInstance()->getCustomVariables($idSite, $period, $date, $segment, $expanded = false, $_leavePiwikCoreVariables = true); + Actions::checkCustomVariablesPluginEnabled(); + $customVariables = CustomVariablesAPI::getInstance()->getCustomVariables($idSite, $period, $date, $segment, $expanded = false, $_leavePiwikCoreVariables = true); $customVarNameToLookFor = Action::CVAR_KEY_SEARCH_CATEGORY; @@ -354,7 +361,7 @@ class Piwik_Actions_API if ($row) { $dateRewrite = $customVariableTableForDate->metadata['period']->getDateStart()->toString(); $idSubtable = $row->getIdSubDataTable(); - $categories = Piwik_CustomVariables_API::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $dateRewrite, $idSubtable, $segment); + $categories = CustomVariablesAPI::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $dateRewrite, $idSubtable, $segment); $dataTable->addTable($categories, $key); } } @@ -363,7 +370,7 @@ class Piwik_Actions_API $row = $customVariables->getRowFromLabel($customVarNameToLookFor); if ($row) { $idSubtable = $row->getIdSubDataTable(); - $dataTable = Piwik_CustomVariables_API::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $date, $idSubtable, $segment); + $dataTable = CustomVariablesAPI::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $date, $idSubtable, $segment); } } $this->filterActionsDataTable($dataTable); @@ -390,8 +397,8 @@ class Piwik_Actions_API $searchedString = $search; } } - Piwik_Actions_ArchivingHelper::reloadConfig(); - $searchTree = Piwik_Actions_ArchivingHelper::getActionExplodedNames($searchedString, $actionType); + ArchivingHelper::reloadConfig(); + $searchTree = ArchivingHelper::getActionExplodedNames($searchedString, $actionType); } if ($table === false) { @@ -412,7 +419,6 @@ class Piwik_Actions_API return $newTableArray; } - } return $this->doFilterPageDatatableSearch($callBackParameters, $table, $searchTree); diff --git a/plugins/Actions/Actions.php b/plugins/Actions/Actions.php index b97895ed7d..1fd74b5efe 100644 --- a/plugins/Actions/Actions.php +++ b/plugins/Actions/Actions.php @@ -6,8 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Actions + * @package Actions */ +namespace Piwik\Plugins\Actions; + use Piwik\API\Request; use Piwik\ArchiveProcessor; use Piwik\Piwik; @@ -15,7 +17,6 @@ use Piwik\Common; use Piwik\Tracker\Action; use Piwik\ViewDataTable; use Piwik\WidgetsList; -use Piwik\Plugin; use Piwik\SegmentExpression; use Piwik\Db; use Piwik\Site; @@ -25,18 +26,18 @@ use Piwik\Site; * * Reports about the page views, the outlinks and downloads. * - * @package Piwik_Actions + * @package Actions */ -class Piwik_Actions extends Plugin +class Actions extends \Piwik\Plugin { const ACTIONS_REPORT_ROWS_DISPLAY = 100; - + private $columnTranslations; - + public function __construct() { parent::__construct(); - + $this->columnTranslations = array( 'nb_hits' => Piwik_Translate('General_ColumnPageviews'), 'nb_visits' => Piwik_Translate('General_ColumnUniquePageviews'), @@ -217,7 +218,7 @@ class Piwik_Actions extends Plugin 'nb_uniq_outlinks' => Piwik_Translate('Actions_ColumnUniqueOutlinks'), 'nb_searches' => Piwik_Translate('Actions_ColumnSearches'), 'nb_keywords' => Piwik_Translate('Actions_ColumnSiteSearchKeywords'), - 'avg_time_generation' => Piwik_Translate('General_ColumnAverageGenerationTime'), + 'avg_time_generation' => Piwik_Translate('General_ColumnAverageGenerationTime'), ), 'metricsDocumentation' => array( 'nb_pageviews' => Piwik_Translate('General_ColumnPageviewsDocumentation'), @@ -227,7 +228,7 @@ class Piwik_Actions extends Plugin 'nb_outlinks' => Piwik_Translate('Actions_ColumnClicksDocumentation'), 'nb_uniq_outlinks' => Piwik_Translate('Actions_ColumnUniqueClicksDocumentation'), 'nb_searches' => Piwik_Translate('Actions_ColumnSearchesDocumentation'), - 'avg_time_generation' => Piwik_Translate('General_ColumnAverageGenerationTimeDocumentation'), + 'avg_time_generation' => Piwik_Translate('General_ColumnAverageGenerationTimeDocumentation'), // 'nb_keywords' => Piwik_Translate('Actions_ColumnSiteSearchKeywords'), ), 'processedMetrics' => false, @@ -587,16 +588,16 @@ class Piwik_Actions extends Plugin */ public function archiveDay(ArchiveProcessor\Day $archiveProcessor) { - $archiving = new Piwik_Actions_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archiveDay(); } } function archivePeriod(ArchiveProcessor\Period $archiveProcessor) { - $archiving = new Piwik_Actions_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archivePeriod(); } } @@ -637,20 +638,20 @@ class Piwik_Actions extends Plugin public function getReportDisplayProperties(&$properties) { $properties['Actions.getPageUrls'] = $this->getDisplayPropertiesForPageUrls(); - $properties['Actions.getEntryPageUrls'] = $this->getDisplayPropertiesForEntryPageUrls(); - $properties['Actions.getExitPageUrls'] = $this->getDisplayPropertiesForExitPageUrls(); - $properties['Actions.getSiteSearchKeywords'] = $this->getDisplayPropertiesForSiteSearchKeywords(); - $properties['Actions.getSiteSearchNoResultKeywords'] = $this->getDisplayPropertiesForSiteSearchNoResultKeywords(); - $properties['Actions.getSiteSearchCategories'] = $this->getDisplayPropertiesForSiteSearchCategories(); - $properties['Actions.getPageUrlsFollowingSiteSearch'] = $this->getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch(false); - $properties['Actions.getPageTitlesFollowingSiteSearch'] = $this->getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch(true); - $properties['Actions.getPageTitles'] = $this->getDisplayPropertiesForGetPageTitles(); - $properties['Actions.getEntryPageTitles'] = $this->getDisplayPropertiesForGetEntryPageTitles(); - $properties['Actions.getExitPageTitles'] = $this->getDisplayPropertiesForGetExitPageTitles(); - $properties['Actions.getDownloads'] = $this->getDisplayPropertiesForGetDownloads(); - $properties['Actions.getOutlinks'] = $this->getDisplayPropertiesForGetOutlinks(); + $properties['Actions.getEntryPageUrls'] = $this->getDisplayPropertiesForEntryPageUrls(); + $properties['Actions.getExitPageUrls'] = $this->getDisplayPropertiesForExitPageUrls(); + $properties['Actions.getSiteSearchKeywords'] = $this->getDisplayPropertiesForSiteSearchKeywords(); + $properties['Actions.getSiteSearchNoResultKeywords'] = $this->getDisplayPropertiesForSiteSearchNoResultKeywords(); + $properties['Actions.getSiteSearchCategories'] = $this->getDisplayPropertiesForSiteSearchCategories(); + $properties['Actions.getPageUrlsFollowingSiteSearch'] = $this->getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch(false); + $properties['Actions.getPageTitlesFollowingSiteSearch'] = $this->getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch(true); + $properties['Actions.getPageTitles'] = $this->getDisplayPropertiesForGetPageTitles(); + $properties['Actions.getEntryPageTitles'] = $this->getDisplayPropertiesForGetEntryPageTitles(); + $properties['Actions.getExitPageTitles'] = $this->getDisplayPropertiesForGetExitPageTitles(); + $properties['Actions.getDownloads'] = $this->getDisplayPropertiesForGetDownloads(); + $properties['Actions.getOutlinks'] = $this->getDisplayPropertiesForGetOutlinks(); } - + private function addBaseDisplayProperties(&$result) { $result['datatable_js_type'] = 'actionDataTable'; @@ -660,16 +661,16 @@ class Piwik_Actions extends Plugin $result['show_all_views_icons'] = false; $result['show_table_all_columns'] = false; $result['filter_limit'] = self::ACTIONS_REPORT_ROWS_DISPLAY; - + // if the flat parameter is not provided, make sure it is set to 0 in the URL, // so users can see that they can set it to 1 (see #3365) $result['custom_parameters'] = array('flat' => 0); - + if (ViewDataTable::shouldLoadExpanded()) { $result['visualization_properties']['table']['show_expanded'] = true; $result['filters'][] = function ($dataTable) { - Piwik_Actions::setDataTableRowLevels($dataTable); + Actions::setDataTableRowLevels($dataTable); }; } @@ -689,15 +690,15 @@ class Piwik_Actions extends Plugin public static function setDataTableRowLevels($dataTable, $level = 0) { foreach ($dataTable->getRows() as $row) { - $row->setMetadata('css_class', 'level'.$level); - + $row->setMetadata('css_class', 'level' . $level); + $subtable = $row->getSubtable(); if ($subtable) { self::setDataTableRowLevels($subtable, $level + 1); } } } - + private function addExcludeLowPopDisplayProperties(&$result) { if (Common::getRequestVar('enable_filter_excludelowpop', '0', 'string') != '0') { @@ -707,60 +708,60 @@ class Piwik_Actions extends Plugin $visitsInfo = Piwik_VisitsSummary_Controller::getVisitsSummary()->getFirstRow(); $nbActions = $visitsInfo->getColumn('nb_actions'); $nbActionsLowPopulationThreshold = floor(0.02 * $nbActions); - + // we remove 1 to make sure some actions/downloads are displayed in the case we have a very few of them // and each of them has 1 or 2 hits... return min($visitsInfo->getColumn('max_actions') - 1, $nbActionsLowPopulationThreshold - 1); }; } } - + private function addPageDisplayProperties(&$result) { // add common translations $result['translations'] += array( - 'nb_hits' => Piwik_Translate('General_ColumnPageviews'), - 'nb_visits' => Piwik_Translate('General_ColumnUniquePageviews'), - 'avg_time_on_page' => Piwik_Translate('General_ColumnAverageTimeOnPage'), - 'bounce_rate' => Piwik_Translate('General_ColumnBounceRate'), - 'exit_rate' => Piwik_Translate('General_ColumnExitRate'), + 'nb_hits' => Piwik_Translate('General_ColumnPageviews'), + 'nb_visits' => Piwik_Translate('General_ColumnUniquePageviews'), + 'avg_time_on_page' => Piwik_Translate('General_ColumnAverageTimeOnPage'), + 'bounce_rate' => Piwik_Translate('General_ColumnBounceRate'), + 'exit_rate' => Piwik_Translate('General_ColumnExitRate'), 'avg_time_generation' => Piwik_Translate('General_ColumnAverageGenerationTime'), ); - + // prettify avg_time_on_page column $getPrettyTimeFromSeconds = '\Piwik\Piwik::getPrettyTimeFromSeconds'; $result['filters'][] = array('ColumnCallbackReplace', array('avg_time_on_page', $getPrettyTimeFromSeconds)); - + // prettify avg_time_generation column $avgTimeCallback = function ($time) { return $time ? Piwik::getPrettyTimeFromSeconds($time, true, true, false) : "-"; }; $result['filters'][] = array('ColumnCallbackReplace', array('avg_time_generation', $avgTimeCallback)); - + // add avg_generation_time tooltip $tooltipCallback = function ($hits, $min, $max) { if (!$hits) { return false; } - + return Piwik_Translate("Actions_AvgGenerationTimeTooltip", array( - $hits, - "<br />", - Piwik::getPrettyTimeFromSeconds($min), - Piwik::getPrettyTimeFromSeconds($max) - )); + $hits, + "<br />", + Piwik::getPrettyTimeFromSeconds($min), + Piwik::getPrettyTimeFromSeconds($max) + )); }; $result['filters'][] = array('ColumnCallbackAddMetadata', - array( - array('nb_hits_with_time_generation', 'min_time_generation', 'max_time_generation'), - 'avg_time_generation_tooltip', - $tooltipCallback - ) + array( + array('nb_hits_with_time_generation', 'min_time_generation', 'max_time_generation'), + 'avg_time_generation_tooltip', + $tooltipCallback + ) ); - + $this->addExcludeLowPopDisplayProperties($result); } - + public function getDisplayPropertiesForPageUrls() { $result = array( @@ -768,26 +769,26 @@ class Piwik_Actions extends Plugin 'columns_to_display' => array('label', 'nb_hits', 'nb_visits', 'bounce_rate', 'avg_time_on_page', 'exit_rate', 'avg_time_generation'), ); - + $this->addPageDisplayProperties($result); $this->addBaseDisplayProperties($result); - + return $result; } - + public function getDisplayPropertiesForEntryPageUrls() { // link to the page, not just the report, but only if not a widget $widget = Common::getRequestVar('widget', false); $reportUrl = Request::getCurrentUrlWithoutGenericFilters(array( - 'module' => 'Actions', - 'action' => $widget === false ? 'indexEntryPageUrls' : 'getEntryPageUrls' - )); - + 'module' => 'Actions', + 'action' => $widget === false ? 'indexEntryPageUrls' : 'getEntryPageUrls' + )); + $result = array( - 'translations' => array('label' => Piwik_Translate('Actions_ColumnEntryPageURL'), + 'translations' => array('label' => Piwik_Translate('Actions_ColumnEntryPageURL'), 'entry_bounce_count' => Piwik_Translate('General_ColumnBounces'), - 'entry_nb_visits' => Piwik_Translate('General_ColumnEntrances')), + 'entry_nb_visits' => Piwik_Translate('General_ColumnEntrances')), 'columns_to_display' => array('label', 'entry_nb_visits', 'entry_bounce_count', 'bounce_rate'), 'filter_sort_column' => 'entry_nb_visits', 'filter_sort_order' => 'desc', @@ -797,24 +798,24 @@ class Piwik_Actions extends Plugin ), 'self_url' => $reportUrl ); - + $this->addPageDisplayProperties($result); $this->addBaseDisplayProperties($result); - + return $result; } - + public function getDisplayPropertiesForExitPageUrls() { // link to the page, not just the report, but only if not a widget $widget = Common::getRequestVar('widget', false); $reportUrl = Request::getCurrentUrlWithoutGenericFilters(array( - 'module' => 'Actions', - 'action' => $widget === false ? 'indexExitPageUrls' : 'getExitPageUrls' - )); - + 'module' => 'Actions', + 'action' => $widget === false ? 'indexExitPageUrls' : 'getExitPageUrls' + )); + $result = array( - 'translations' => array('label' => Piwik_Translate('Actions_ColumnExitPageURL'), + 'translations' => array('label' => Piwik_Translate('Actions_ColumnExitPageURL'), 'exit_nb_visits' => Piwik_Translate('General_ColumnExits')), 'columns_to_display' => array('label', 'exit_nb_visits', 'nb_visits', 'exit_rate'), 'filter_sort_column' => 'exit_nb_visits', @@ -825,13 +826,13 @@ class Piwik_Actions extends Plugin ), 'self_url' => $reportUrl, ); - + $this->addPageDisplayProperties($result); $this->addBaseDisplayProperties($result); - + return $result; } - + private function addSiteSearchDisplayProperties(&$result) { $result['translations'] += array( @@ -842,16 +843,16 @@ class Piwik_Actions extends Plugin $result['show_bar_chart'] = false; $result['show_table_all_columns'] = false; } - + public function getDisplayPropertiesForSiteSearchKeywords() { $result = array( 'translations' => array('label' => Piwik_Translate('Actions_ColumnSearchKeyword')), 'columns_to_display' => array('label', 'nb_visits', 'nb_pages_per_search', 'exit_rate'), ); - + $this->addSiteSearchDisplayProperties($result); - + return $result; } @@ -861,9 +862,9 @@ class Piwik_Actions extends Plugin 'translations' => array('label', Piwik_Translate('Actions_ColumnNoResultKeyword')), 'columns_to_display' => array('label', 'nb_visits', 'exit_rate') ); - + $this->addSiteSearchDisplayProperties($result); - + return $result; } @@ -890,12 +891,12 @@ class Piwik_Actions extends Plugin { $title = $isTitle ? Piwik_Translate('Actions_WidgetPageTitlesFollowingSearch') : Piwik_Translate('Actions_WidgetPageUrlsFollowingSearch'); - + $relatedReports = array( 'Actions.getPageTitlesFollowingSiteSearch' => Piwik_Translate('Actions_WidgetPageTitlesFollowingSearch'), - 'Actions.getPageUrlsFollowingSiteSearch' => Piwik_Translate('Actions_WidgetPageUrlsFollowingSearch'), + 'Actions.getPageUrlsFollowingSiteSearch' => Piwik_Translate('Actions_WidgetPageUrlsFollowingSearch'), ); - + $result = array( 'translations' => array( 'label' => Piwik_Translate('General_ColumnDestinationPage'), @@ -909,10 +910,10 @@ class Piwik_Actions extends Plugin 'title' => $title, 'related_reports' => $relatedReports ); - + $this->addExcludeLowPopDisplayProperties($result); $this->addBaseDisplayProperties($result); - + return $result; } @@ -921,10 +922,10 @@ class Piwik_Actions extends Plugin // link to the page, not just the report, but only if not a widget $widget = Common::getRequestVar('widget', false); $reportUrl = Request::getCurrentUrlWithoutGenericFilters(array( - 'module' => 'Actions', - 'action' => $widget === false ? 'indexPageTitles' : 'getPageTitles' - )); - + 'module' => 'Actions', + 'action' => $widget === false ? 'indexPageTitles' : 'getPageTitles' + )); + $result = array( 'translations' => array('label' => Piwik_Translate('Actions_ColumnPageName')), 'columns_to_display' => array('label', 'nb_hits', 'nb_visits', 'bounce_rate', @@ -936,10 +937,10 @@ class Piwik_Actions extends Plugin ), 'self_url' => $reportUrl ); - + $this->addPageDisplayProperties($result); $this->addBaseDisplayProperties($result); - + return $result; } @@ -947,7 +948,7 @@ class Piwik_Actions extends Plugin { $entryPageUrlAction = Common::getRequestVar('widget', false) === false ? 'indexEntryPageUrls' : 'getEntryPageUrls'; - + $result = array( 'translations' => array( 'label' => Piwik_Translate('Actions_ColumnEntryPageTitle'), @@ -961,10 +962,10 @@ class Piwik_Actions extends Plugin "Actions.$entryPageUrlAction" => Piwik_Translate('Actions_SubmenuPagesEntry') ), ); - + $this->addPageDisplayProperties($result); $this->addBaseDisplayProperties($result); - + return $result; } @@ -972,7 +973,7 @@ class Piwik_Actions extends Plugin { $exitPageUrlAction = Common::getRequestVar('widget', false) === false ? 'indexExitPageUrls' : 'getExitPageUrls'; - + $result = array( 'translations' => array( 'label' => Piwik_Translate('Actions_ColumnExitPageTitle'), @@ -985,10 +986,10 @@ class Piwik_Actions extends Plugin "Actions.$exitPageUrlAction" => Piwik_Translate('Actions_SubmenuPagesExit'), ), ); - + $this->addPageDisplayProperties($result); $this->addBaseDisplayProperties($result); - + return $result; } @@ -1003,9 +1004,9 @@ class Piwik_Actions extends Plugin 'columns_to_display' => array('label', 'nb_visits', 'nb_hits'), 'show_exclude_low_population' => false ); - + $this->addBaseDisplayProperties($result); - + return $result; } @@ -1020,9 +1021,9 @@ class Piwik_Actions extends Plugin 'columns_to_display' => array('label', 'nb_visits', 'nb_hits'), 'show_exclude_low_population' => false ); - + $this->addBaseDisplayProperties($result); - + return $result; } } diff --git a/plugins/Actions/Archiver.php b/plugins/Actions/Archiver.php index f3dfa31138..c177a73ffe 100644 --- a/plugins/Actions/Archiver.php +++ b/plugins/Actions/Archiver.php @@ -6,8 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Actions + * @package Actions */ +namespace Piwik\Plugins\Actions; + use Piwik\Config; use Piwik\DataTable\Manager; use Piwik\DataTable\Row\DataTableSummaryRow; @@ -16,13 +18,14 @@ use Piwik\DataTable; use Piwik\RankingQuery; use Piwik\PluginsArchiver; use Piwik\Tracker\Action; +use Piwik\Plugins\Actions\ArchivingHelper; /** * Class encapsulating logic to process Day/Period Archiving for the Actions reports * - * @package Piwik_Actions + * @package Actions */ -class Piwik_Actions_Archiver extends PluginsArchiver +class Archiver extends PluginsArchiver { const DOWNLOADS_RECORD_NAME = 'Actions_downloads'; const OUTLINKS_RECORD_NAME = 'Actions_outlink'; @@ -42,15 +45,15 @@ class Piwik_Actions_Archiver extends PluginsArchiver const METRIC_KEYWORDS_RECORD_NAME = 'Actions_nb_keywords'; /* Metrics in use by the API Actions.get */ - public static $actionsAggregateMetrics = array( - self::METRIC_PAGEVIEWS_RECORD_NAME => 'nb_pageviews', - self::METRIC_UNIQ_PAGEVIEWS_RECORD_NAME => 'nb_uniq_pageviews', - self::METRIC_DOWNLOADS_RECORD_NAME => 'nb_downloads', - self::METRIC_UNIQ_DOWNLOADS_RECORD_NAME => 'nb_uniq_downloads', - self::METRIC_OUTLINKS_RECORD_NAME => 'nb_outlinks', - self::METRIC_UNIQ_OUTLINKS_RECORD_NAME => 'nb_uniq_outlinks', - self::METRIC_SEARCHES_RECORD_NAME => 'nb_searches', - self::METRIC_KEYWORDS_RECORD_NAME => 'nb_keywords', + public static $actionsAggregateMetrics = array( + self::METRIC_PAGEVIEWS_RECORD_NAME => 'nb_pageviews', + self::METRIC_UNIQ_PAGEVIEWS_RECORD_NAME => 'nb_uniq_pageviews', + self::METRIC_DOWNLOADS_RECORD_NAME => 'nb_downloads', + self::METRIC_UNIQ_DOWNLOADS_RECORD_NAME => 'nb_uniq_downloads', + self::METRIC_OUTLINKS_RECORD_NAME => 'nb_outlinks', + self::METRIC_UNIQ_OUTLINKS_RECORD_NAME => 'nb_uniq_outlinks', + self::METRIC_SEARCHES_RECORD_NAME => 'nb_searches', + self::METRIC_KEYWORDS_RECORD_NAME => 'nb_keywords', ); public static $actionTypes = array( @@ -93,24 +96,24 @@ class Piwik_Actions_Archiver extends PluginsArchiver $rankingQueryLimit = self::getRankingQueryLimit(); // FIXME: This is a quick fix for #3482. The actual cause of the bug is that - // the site search & performance metrics additions to - // Piwik_Actions_ArchivingHelper::updateActionsTableWithRowQuery expect every + // the site search & performance metrics additions to + // ArchivingHelper::updateActionsTableWithRowQuery expect every // row to have 'type' data, but not all of the SQL queries that are run w/o // ranking query join on the log_action table and thus do not select the // log_action.type column. - // + // // NOTES: Archiving logic can be generalized as follows: // 0) Do SQL query over log_link_visit_action & join on log_action to select // some metrics (like visits, hits, etc.) // 1) For each row, cache the action row & metrics. (This is done by - // updateActionsTableWithRowQuery for result set rows that have + // updateActionsTableWithRowQuery for result set rows that have // name & type columns.) // 2) Do other SQL queries for metrics we can't put in the first query (like // entry visits, exit vists, etc.) w/o joining log_action. // 3) For each row, find the cached row by idaction & add the new metrics to // it. (This is done by updateActionsTableWithRowQuery for result set rows // that DO NOT have name & type columns.) - // + // // The site search & performance metrics additions expect a 'type' all the time // which breaks the original pre-rankingquery logic. Ranking query requires a // join, so the bug is only seen when ranking query is disabled. @@ -118,7 +121,7 @@ class Piwik_Actions_Archiver extends PluginsArchiver $rankingQueryLimit = 100000; } - Piwik_Actions_ArchivingHelper::reloadConfig(); + ArchivingHelper::reloadConfig(); $this->initActionsTables(); $this->archiveDayActions($rankingQueryLimit); @@ -159,7 +162,7 @@ class Piwik_Actions_Archiver extends PluginsArchiver $this->actionsTablesByType = array(); foreach (self::$actionTypes as $type) { $dataTable = new DataTable(); - $dataTable->setMaximumAllowedRows(Piwik_Actions_ArchivingHelper::$maximumRowsInDataTableLevelZero); + $dataTable->setMaximumAllowedRows(ArchivingHelper::$maximumRowsInDataTableLevelZero); if ($type == Action::TYPE_ACTION_URL || $type == Action::TYPE_ACTION_NAME @@ -271,7 +274,6 @@ class Piwik_Actions_Archiver extends PluginsArchiver // to the outer select. therefore, $segment needs to know about it. $select = sprintf($select, $sprintfField); - // get query with segmentation $query = $this->getLogAggregator()->generateQuery($select, $from, $where, $groupBy, $orderBy); @@ -285,7 +287,7 @@ class Piwik_Actions_Archiver extends PluginsArchiver // get result $resultSet = $this->getLogAggregator()->getDb()->query($querySql, $query['bind']); - $modified = Piwik_Actions_ArchivingHelper::updateActionsTableWithRowQuery($resultSet, $sprintfField, $this->actionsTablesByType); + $modified = ArchivingHelper::updateActionsTableWithRowQuery($resultSet, $sprintfField, $this->actionsTablesByType); return $modified; } @@ -435,7 +437,7 @@ class Piwik_Actions_Archiver extends PluginsArchiver */ protected function recordDayReports() { - Piwik_Actions_ArchivingHelper::clearActionsCache(); + ArchivingHelper::clearActionsCache(); $this->recordPageUrlsReports(); $this->recordDownloadsReports(); @@ -450,12 +452,12 @@ class Piwik_Actions_Archiver extends PluginsArchiver $this->recordDataTable($dataTable, self::PAGE_URLS_RECORD_NAME); $records = array( - self::METRIC_PAGEVIEWS_RECORD_NAME => array_sum($dataTable->getColumn(Metrics::INDEX_PAGE_NB_HITS)), + self::METRIC_PAGEVIEWS_RECORD_NAME => array_sum($dataTable->getColumn(Metrics::INDEX_PAGE_NB_HITS)), self::METRIC_UNIQ_PAGEVIEWS_RECORD_NAME => array_sum($dataTable->getColumn(Metrics::INDEX_NB_VISITS)), - self::METRIC_SUM_TIME_RECORD_NAME => array_sum($dataTable->getColumn(Metrics::INDEX_PAGE_SUM_TIME_GENERATION)), - self::METRIC_HITS_TIMED_RECORD_NAME => array_sum($dataTable->getColumn(Metrics::INDEX_PAGE_NB_HITS_WITH_TIME_GENERATION)) + self::METRIC_SUM_TIME_RECORD_NAME => array_sum($dataTable->getColumn(Metrics::INDEX_PAGE_SUM_TIME_GENERATION)), + self::METRIC_HITS_TIMED_RECORD_NAME => array_sum($dataTable->getColumn(Metrics::INDEX_PAGE_NB_HITS_WITH_TIME_GENERATION)) ); - $this->getProcessor()->insertNumericRecords( $records ); + $this->getProcessor()->insertNumericRecords($records); } /** @@ -470,7 +472,7 @@ class Piwik_Actions_Archiver extends PluginsArchiver protected function recordDataTable($dataTable, $recordName) { self::deleteInvalidSummedColumnsFromDataTable($dataTable); - $s = $dataTable->getSerialized(Piwik_Actions_ArchivingHelper::$maximumRowsInDataTableLevelZero, Piwik_Actions_ArchivingHelper::$maximumRowsInSubDataTable, Piwik_Actions_ArchivingHelper::$columnToSortByBeforeTruncation); + $s = $dataTable->getSerialized(ArchivingHelper::$maximumRowsInDataTableLevelZero, ArchivingHelper::$maximumRowsInSubDataTable, ArchivingHelper::$columnToSortByBeforeTruncation); $this->getProcessor()->insertBlobRecord($recordName, $s); } @@ -566,15 +568,15 @@ class Piwik_Actions_Archiver extends PluginsArchiver public function archivePeriod() { - Piwik_Actions_ArchivingHelper::reloadConfig(); + ArchivingHelper::reloadConfig(); $dataTableToSum = array( self::PAGE_TITLES_RECORD_NAME, self::PAGE_URLS_RECORD_NAME, ); $this->getProcessor()->aggregateDataTableReports($dataTableToSum, - Piwik_Actions_ArchivingHelper::$maximumRowsInDataTableLevelZero, - Piwik_Actions_ArchivingHelper::$maximumRowsInSubDataTable, - Piwik_Actions_ArchivingHelper::$columnToSortByBeforeTruncation, + ArchivingHelper::$maximumRowsInDataTableLevelZero, + ArchivingHelper::$maximumRowsInSubDataTable, + ArchivingHelper::$columnToSortByBeforeTruncation, self::$actionColumnAggregationOperations, self::$invalidSummedColumnNameToRenamedNameFromPeriodArchive ); @@ -586,9 +588,9 @@ class Piwik_Actions_Archiver extends PluginsArchiver ); $aggregation = null; $nameToCount = $this->getProcessor()->aggregateDataTableReports($dataTableToSum, - Piwik_Actions_ArchivingHelper::$maximumRowsInDataTableLevelZero, - Piwik_Actions_ArchivingHelper::$maximumRowsInSubDataTable, - Piwik_Actions_ArchivingHelper::$columnToSortByBeforeTruncation, + ArchivingHelper::$maximumRowsInDataTableLevelZero, + ArchivingHelper::$maximumRowsInSubDataTable, + ArchivingHelper::$columnToSortByBeforeTruncation, $aggregation, self::$invalidSummedColumnNameToRenamedNameFromPeriodArchive ); diff --git a/plugins/Actions/ArchivingHelper.php b/plugins/Actions/ArchivingHelper.php index 8c95ae629f..e66cf73a97 100644 --- a/plugins/Actions/ArchivingHelper.php +++ b/plugins/Actions/ArchivingHelper.php @@ -6,29 +6,33 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Actions + * @package Actions */ +namespace Piwik\Plugins\Actions; + +use PDOStatement; use Piwik\Config; use Piwik\DataTable\Row; use Piwik\Metrics; use Piwik\DataTable; use Piwik\Tracker\Action; +use Zend_Db_Statement; /** * This static class provides: * - logic to parse/cleanup Action names, * - logic to efficiently process aggregate the array data during Archiving * - * @package Piwik_Actions + * @package Actions */ -class Piwik_Actions_ArchivingHelper +class ArchivingHelper { const OTHERS_ROW_KEY = ''; /** - * FIXME See FIXME related to this function at Piwik_Actions_Archiver::archiveDay. - * + * FIXME See FIXME related to this function at Archiver::archiveDay. + * * @param Zend_Db_Statement|PDOStatement $query * @param string|bool $fieldQueried * @param array $actionsTablesByType @@ -91,7 +95,6 @@ class Piwik_Actions_ArchivingHelper } } - if (is_null($actionRow)) { continue; } @@ -226,7 +229,6 @@ class Piwik_Actions_ArchivingHelper DataTable::setMaximumDepthLevelAllowedAtLeast(self::getSubCategoryLevelLimit() + 1); } - /** * The default row is used when archiving, if data is inconsistent in the DB, * there could be pages that have exit/entry hits, but don't yet @@ -242,11 +244,11 @@ class Piwik_Actions_ArchivingHelper // but this action was not properly recorded when it was hit in the first place // so we add this fake row information to make sure there is a nb_hits, etc. column for every action $row = new Row(array( - Row::COLUMNS => array( - Metrics::INDEX_NB_VISITS => 1, - Metrics::INDEX_NB_UNIQ_VISITORS => 1, - Metrics::INDEX_PAGE_NB_HITS => 1, - ))); + Row::COLUMNS => array( + Metrics::INDEX_NB_VISITS => 1, + Metrics::INDEX_NB_UNIQ_VISITORS => 1, + Metrics::INDEX_PAGE_NB_HITS => 1, + ))); } return $row; } @@ -287,7 +289,7 @@ class Piwik_Actions_ArchivingHelper /** * Explodes action name into an array of elements. * - * NOTE: before calling this function make sure Piwik_Actions_ArchivingHelper::reloadConfig(); is called + * NOTE: before calling this function make sure ArchivingHelper::reloadConfig(); is called * * for downloads: * we explode link http://piwik.org/some/path/piwik.zip into an array( 'piwik.org', '/some/path/piwik.zip' ); @@ -357,7 +359,6 @@ class Piwik_Actions_ArchivingHelper $categoryDelimiter = self::$actionUrlCategoryDelimiter; } - if ($isUrl) { $urlFragment = Action::processUrlFragment($urlFragment); if (!empty($urlFragment)) { @@ -504,8 +505,8 @@ class Piwik_Actions_ArchivingHelper private static function createSummaryRow() { return new Row(array( - Row::COLUMNS => - array('label' => DataTable::LABEL_SUMMARY_ROW) + self::getDefaultRowColumns() - )); + Row::COLUMNS => + array('label' => DataTable::LABEL_SUMMARY_ROW) + self::getDefaultRowColumns() + )); } } diff --git a/plugins/Actions/Controller.php b/plugins/Actions/Controller.php index 9ce7800197..e6342352f6 100644 --- a/plugins/Actions/Controller.php +++ b/plugins/Actions/Controller.php @@ -6,23 +6,24 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Actions + * @package Actions */ -use Piwik\Controller; +namespace Piwik\Plugins\Actions; + use Piwik\ViewDataTable; use Piwik\View; /** * Actions controller * - * @package Piwik_Actions + * @package Actions */ -class Piwik_Actions_Controller extends Controller +class Controller extends \Piwik\Controller { - // + // // Actions that render whole pages - // - + // + public function indexPageUrls($fetch = false) { return View::singleReport( @@ -80,16 +81,16 @@ class Piwik_Actions_Controller extends Controller Piwik_Translate('Actions_SubmenuOutlinks'), $this->getOutlinks(true), $fetch); } - - // + + // // Actions that render individual reports - // - + // + public function getPageUrls($fetch = false) { return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - + public function getEntryPageUrls($fetch = false) { return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); diff --git a/plugins/Alerts/README.md b/plugins/Alerts/README.md deleted file mode 100644 index 292963a701..0000000000 --- a/plugins/Alerts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Alerts - - diff --git a/plugins/Annotations/API.php b/plugins/Annotations/API.php index ec34c1f127..0e946b7302 100755 --- a/plugins/Annotations/API.php +++ b/plugins/Annotations/API.php @@ -6,12 +6,16 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Annotations + * @package Annotations */ +namespace Piwik\Plugins\Annotations; + +use Exception; use Piwik\Period; use Piwik\Period\Range; use Piwik\Piwik; use Piwik\Date; +use Piwik\Plugins\Annotations\AnnotationList; use Piwik\ViewDataTable; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution as EvolutionViz; @@ -24,16 +28,16 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Annotations/AnnotationList.php'; * API for annotations plugin. Provides methods to create, modify, delete & query * annotations. * - * @package Piwik_Annotations + * @package Annotations */ -class Piwik_Annotations_API +class API { static private $instance = null; /** * Returns this API's singleton instance. * - * @return Piwik_Annotations_API + * @return \Piwik\Plugins\Annotations\API */ static public function getInstance() { @@ -49,7 +53,7 @@ class Piwik_Annotations_API * @param string $idSite The site ID to add the annotation to. * @param string $date The date the annotation is attached to. * @param string $note The text of the annotation. - * @param int $starred Either 0 or 1. Whether the annotation should be starred. + * @param int $starred Either 0 or 1. Whether the annotation should be starred. * @return array Returns an array of two elements. The first element (indexed by * 'annotation') is the new annotation. The second element (indexed * by 'idNote' is the new note's ID). @@ -61,7 +65,7 @@ class Piwik_Annotations_API $this->checkUserCanAddNotesFor($idSite); // add, save & return a new annotation - $annotations = new Piwik_Annotations_AnnotationList($idSite); + $annotations = new AnnotationList($idSite); $newAnnotation = $annotations->add($idSite, $date, $note, $starred); $annotations->save($idSite); @@ -97,7 +101,7 @@ class Piwik_Annotations_API $this->checkDateIsValid($date, $canBeNull = true); // get the annotations for the site - $annotations = new Piwik_Annotations_AnnotationList($idSite); + $annotations = new AnnotationList($idSite); // check permissions $this->checkUserCanModifyOrDelete($idSite, $annotations->get($idSite, $idNote)); @@ -125,7 +129,7 @@ class Piwik_Annotations_API { $this->checkSingleIdSite($idSite, $extraMessage = "Note: Cannot delete multiple notes."); - $annotations = new Piwik_Annotations_AnnotationList($idSite); + $annotations = new AnnotationList($idSite); // check permissions $this->checkUserCanModifyOrDelete($idSite, $annotations->get($idSite, $idNote)); @@ -154,7 +158,7 @@ class Piwik_Annotations_API Piwik::checkUserHasViewAccess($idSite); // get single annotation - $annotations = new Piwik_Annotations_AnnotationList($idSite); + $annotations = new AnnotationList($idSite); return $annotations->get($idSite, $idNote); } @@ -182,7 +186,7 @@ class Piwik_Annotations_API { Piwik::checkUserHasViewAccess($idSite); - $annotations = new Piwik_Annotations_AnnotationList($idSite); + $annotations = new AnnotationList($idSite); // if date/period are supplied, determine start/end date for search list($startDate, $endDate) = self::getDateRangeForPeriod($date, $period, $lastN); @@ -234,7 +238,7 @@ class Piwik_Annotations_API $dates[] = $startDate; // get annotations for the site - $annotations = new Piwik_Annotations_AnnotationList($idSite); + $annotations = new AnnotationList($idSite); // create result w/ 0-counts $result = array(); @@ -292,7 +296,7 @@ class Piwik_Annotations_API */ private static function checkUserCanAddNotesFor($idSite) { - if (!Piwik_Annotations_AnnotationList::canUserAddNotesFor($idSite)) { + if (!AnnotationList::canUserAddNotesFor($idSite)) { throw new Exception("The current user is not allowed to add notes for site #$idSite."); } } @@ -303,7 +307,7 @@ class Piwik_Annotations_API * * @param string|bool $date The start date of the period (or the date range of a range * period). - * @param string $period The period type ('day', 'week', 'month', 'year' or 'range'). + * @param string $period The period type ('day', 'week', 'month', 'year' or 'range'). * @param bool|int $lastN Whether to include the last N periods in the range or not. * Ignored if period == range. * diff --git a/plugins/Annotations/AnnotationList.php b/plugins/Annotations/AnnotationList.php index 0f5ba42ae9..75b4d95df1 100755 --- a/plugins/Annotations/AnnotationList.php +++ b/plugins/Annotations/AnnotationList.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Annotations + * @package Annotations */ +namespace Piwik\Plugins\Annotations; + +use Exception; use Piwik\Piwik; use Piwik\Date; use Piwik\Site; @@ -17,7 +20,7 @@ use Piwik\Site; * at once. * * Example use: - * $annotations = new Piwik_Annotations_AnnotationList($idSites = "1,2,5"); + * $annotations = new AnnotationList($idSites = "1,2,5"); * $annotation = $annotations->get($idSite = 1, $idNote = 4); * // do stuff w/ annotation * $annotations->update($idSite = 2, $idNote = 4, $note = "This is the new text."); @@ -27,9 +30,9 @@ use Piwik\Site; * an annotation for the same site, it's possible one of their changes will * never get made (as it will be overwritten by the other's). * - * @package Piwik_Annotations + * @package Annotations */ -class Piwik_Annotations_AnnotationList +class AnnotationList { const ANNOTATION_COLLECTION_OPTION_SUFFIX = '_annotations'; diff --git a/plugins/Annotations/Annotations.php b/plugins/Annotations/Annotations.php index 5b29ec48b5..3b756314c9 100755 --- a/plugins/Annotations/Annotations.php +++ b/plugins/Annotations/Annotations.php @@ -6,17 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Annotations + * @package Annotations */ -use Piwik\Plugin; +namespace Piwik\Plugins\Annotations; /** * Annotations plugins. Provides the ability to attach text notes to * dates for each sites. Notes can be viewed, modified, deleted or starred. * - * @package Piwik_Annotations + * @package Annotations */ -class Piwik_Annotations extends Plugin +class Annotations extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/Annotations/Controller.php b/plugins/Annotations/Controller.php index 739ec5deeb..00a927fe6d 100755 --- a/plugins/Annotations/Controller.php +++ b/plugins/Annotations/Controller.php @@ -6,19 +6,22 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Annotations + * @package Annotations */ +namespace Piwik\Plugins\Annotations; + use Piwik\API\Request; use Piwik\Common; -use Piwik\Controller; +use Piwik\Plugins\Annotations\AnnotationList; +use Piwik\Plugins\Annotations\API; use Piwik\View; /** * Controller for the Annotations plugin. * - * @package Piwik_Annotations + * @package Annotations */ -class Piwik_Annotations_Controller extends Controller +class Controller extends \Piwik\Controller { /** * Controller action that returns HTML displaying annotations for a site and @@ -68,7 +71,7 @@ class Piwik_Annotations_Controller extends Controller $view->period = $period; $view->lastN = $lastN; - list($startDate, $endDate) = Piwik_Annotations_API::getDateRangeForPeriod($date, $period, $lastN); + list($startDate, $endDate) = API::getDateRangeForPeriod($date, $period, $lastN); $view->startDate = $startDate->toString(); $view->endDate = $endDate->toString(); @@ -76,7 +79,7 @@ class Piwik_Annotations_Controller extends Controller $view->startDatePretty = $startDate->getLocalized($dateFormat); $view->endDatePretty = $endDate->getLocalized($dateFormat); - $view->canUserAddNotes = Piwik_Annotations_AnnotationList::canUserAddNotesFor($idSite); + $view->canUserAddNotes = AnnotationList::canUserAddNotesFor($idSite); if ($fetch) { return $view->render(); diff --git a/plugins/AnonymizeIP/AnonymizeIP.php b/plugins/AnonymizeIP/AnonymizeIP.php index 79af7308a5..ba0e2c2230 100644 --- a/plugins/AnonymizeIP/AnonymizeIP.php +++ b/plugins/AnonymizeIP/AnonymizeIP.php @@ -6,19 +6,20 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_AnonymizeIP + * @package AnonymizeIP */ +namespace Piwik\Plugins\AnonymizeIP; + use Piwik\Config; use Piwik\Common; use Piwik\Version; -use Piwik\Plugin; /** * Anonymize visitor IP addresses to comply with the privacy laws/guidelines in countries, such as Germany. * - * @package Piwik_AnonymizeIP + * @package AnonymizeIP */ -class Piwik_AnonymizeIP extends Plugin +class AnonymizeIP extends \Piwik\Plugin { /** * @see Piwik_Plugin::getInformation diff --git a/plugins/CoreAdminHome/API.php b/plugins/CoreAdminHome/API.php index 2768708ef5..71444288e3 100644 --- a/plugins/CoreAdminHome/API.php +++ b/plugins/CoreAdminHome/API.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CoreAdminHome + * @package CoreAdminHome */ +namespace Piwik\Plugins\CoreAdminHome; + +use Exception; use Piwik\DataAccess\ArchiveTableCreator; use Piwik\Period; use Piwik\Period\Week; @@ -20,14 +23,14 @@ use Piwik\Site; use Piwik\Db; /** - * @package Piwik_CoreAdminHome + * @package CoreAdminHome */ -class Piwik_CoreAdminHome_API +class API { static private $instance = null; /** - * @return Piwik_CoreAdminHome_API + * @return \Piwik\Plugins\CoreAdminHome\API */ static public function getInstance() { @@ -103,7 +106,6 @@ class Piwik_CoreAdminHome_API } } - // If using the feature "Delete logs older than N days"... $logsAreDeletedBeforeThisDate = Config::getInstance()->Deletelogs['delete_logs_schedule_lowest_interval']; $logsDeleteEnabled = Config::getInstance()->Deletelogs['delete_logs_enable']; @@ -188,7 +190,7 @@ class Piwik_CoreAdminHome_API Db::query($query, $bind); // Force to re-process data for these websites in the next archive.php cron run - $invalidatedIdSites = Piwik_CoreAdminHome_API::getWebsiteIdsToInvalidate(); + $invalidatedIdSites = self::getWebsiteIdsToInvalidate(); $invalidatedIdSites = array_merge($invalidatedIdSites, $idSites); $invalidatedIdSites = array_unique($invalidatedIdSites); $invalidatedIdSites = array_values($invalidatedIdSites); diff --git a/plugins/CoreAdminHome/Controller.php b/plugins/CoreAdminHome/Controller.php index 64d62ed158..f8a23c8dc2 100644 --- a/plugins/CoreAdminHome/Controller.php +++ b/plugins/CoreAdminHome/Controller.php @@ -6,12 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CoreAdminHome + * @package CoreAdminHome */ +namespace Piwik\Plugins\CoreAdminHome; + +use Exception; use Piwik\API\ResponseBuilder; use Piwik\ArchiveProcessor\Rules; use Piwik\Config; -use Piwik\Controller\Admin; use Piwik\Piwik; use Piwik\Common; use Piwik\Nonce; @@ -19,12 +21,15 @@ use Piwik\Tracker\IgnoreCookie; use Piwik\View; use Piwik\Url; use Piwik\Site; +use Piwik\Plugins\LanguagesManager\LanguagesManager; +use Piwik\Plugins\LanguagesManager\API as LanguagesManagerAPI; +use Piwik\Plugins\SitesManager\API; /** * - * @package Piwik_CoreAdminHome + * @package CoreAdminHome */ -class Piwik_CoreAdminHome_Controller extends Admin +class Controller extends \Piwik\Controller\Admin { const LOGO_HEIGHT = 300; const LOGO_SMALL_HEIGHT = 100; @@ -67,7 +72,8 @@ class Piwik_CoreAdminHome_Controller extends Admin $directoryWritable = is_writable(PIWIK_DOCUMENT_ROOT . '/misc/user/'); $logoFilesWriteable = is_writeable(PIWIK_DOCUMENT_ROOT . '/misc/user/logo.png') && is_writeable(PIWIK_DOCUMENT_ROOT . '/misc/user/logo.svg') - && is_writeable(PIWIK_DOCUMENT_ROOT . '/misc/user/logo-header.png');; + && is_writeable(PIWIK_DOCUMENT_ROOT . '/misc/user/logo-header.png'); + ; $view->logosWriteable = ($logoFilesWriteable || $directoryWritable) && ini_get('file_uploads') == 1; $trustedHosts = array(); @@ -77,7 +83,7 @@ class Piwik_CoreAdminHome_Controller extends Admin $view->trustedHosts = $trustedHosts; } - $view->language = Piwik_LanguagesManager::getLanguageCodeForCurrentUser(); + $view->language = LanguagesManager::getLanguageCodeForCurrentUser(); $this->setBasicVariablesView($view); echo $view->render(); } @@ -141,7 +147,7 @@ class Piwik_CoreAdminHome_Controller extends Admin $this->setBasicVariablesView($view); $view->topMenu = Piwik_GetTopMenu(); - $viewableIdSites = Piwik_SitesManager_API::getInstance()->getSitesIdWithAtLeastViewAccess(); + $viewableIdSites = API::getInstance()->getSitesIdWithAtLeastViewAccess(); $defaultIdSite = reset($viewableIdSites); $view->idSite = Common::getRequestVar('idSite', $defaultIdSite, 'int'); @@ -149,7 +155,7 @@ class Piwik_CoreAdminHome_Controller extends Admin $view->defaultReportSiteName = Site::getNameFor($view->idSite); $view->defaultSiteRevenue = Piwik::getCurrency($view->idSite); - $allUrls = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($view->idSite); + $allUrls = API::getInstance()->getSiteUrlsFromId($view->idSite); if (isset($allUrls[1])) { $aliasUrl = $allUrls[1]; } else { @@ -161,9 +167,9 @@ class Piwik_CoreAdminHome_Controller extends Admin $view->defaultReportSiteDomain = @parse_url($mainUrl, PHP_URL_HOST); // get currencies for each viewable site - $view->currencySymbols = Piwik_SitesManager_API::getInstance()->getCurrencySymbols(); + $view->currencySymbols = API::getInstance()->getCurrencySymbols(); - $view->serverSideDoNotTrackEnabled = \Piwik_PrivacyManager_Controller::isDntSupported(); + $view->serverSideDoNotTrackEnabled = \Piwik\Plugins\PrivacyManager\Controller::isDntSupported(); echo $view->render(); } @@ -186,9 +192,9 @@ class Piwik_CoreAdminHome_Controller extends Admin $view = new View('@CoreAdminHome/optOut'); $view->trackVisits = $trackVisits; $view->nonce = Nonce::getNonce('Piwik_OptOut', 3600); - $view->language = Piwik_LanguagesManager_API::getInstance()->isLanguageAvailable($language) + $view->language = LanguagesManagerAPI::getInstance()->isLanguageAvailable($language) ? $language - : Piwik_LanguagesManager::getLanguageCodeForCurrentUser(); + : LanguagesManager::getLanguageCodeForCurrentUser(); echo $view->render(); } diff --git a/plugins/CoreAdminHome/CoreAdminHome.php b/plugins/CoreAdminHome/CoreAdminHome.php index c3517d8870..607df94246 100644 --- a/plugins/CoreAdminHome/CoreAdminHome.php +++ b/plugins/CoreAdminHome/CoreAdminHome.php @@ -6,22 +6,23 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CoreAdminHome + * @package CoreAdminHome */ +namespace Piwik\Plugins\CoreAdminHome; + use Piwik\DataAccess\ArchiveSelector; use Piwik\DataAccess\ArchiveTableCreator; use Piwik\Piwik; use Piwik\Date; use Piwik\ScheduledTask; -use Piwik\Plugin; use Piwik\Db; use Piwik\ScheduledTime\Daily; /** * - * @package Piwik_CoreAdminHome + * @package CoreAdminHome */ -class Piwik_CoreAdminHome extends Plugin +class CoreAdminHome extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered @@ -91,7 +92,6 @@ class Piwik_CoreAdminHome extends Plugin array('module' => 'CoreAdminHome', 'action' => 'trackingCodeGenerator'), Piwik::isUserHasSomeAdminAccess(), $order = 4); - } function purgeOutdatedArchives() diff --git a/plugins/CoreHome/Controller.php b/plugins/CoreHome/Controller.php index f89727fb51..7a70f1ac94 100644 --- a/plugins/CoreHome/Controller.php +++ b/plugins/CoreHome/Controller.php @@ -6,26 +6,30 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CoreHome + * @package CoreHome */ +namespace Piwik\Plugins\CoreHome; + +use Exception; use Piwik\API\Request; use Piwik\Piwik; use Piwik\Common; use Piwik\Date; use Piwik\AssetManager; -use Piwik\Controller; use Piwik\FrontController; use Piwik\View; use Piwik\Url; use Piwik\UpdateCheck; use Piwik\Site; - +use Piwik\Plugins\CoreHome\DataTableRowAction\MultiRowEvolution; +use Piwik\Plugins\CoreHome\DataTableRowAction\RowEvolution; +use Piwik\Plugins\UsersManager\API; /** * - * @package Piwik_CoreHome + * @package CoreHome */ -class Piwik_CoreHome_Controller extends Controller +class Controller extends \Piwik\Controller { function getDefaultAction() { @@ -34,7 +38,7 @@ class Piwik_CoreHome_Controller extends Controller function redirectToCoreHomeIndex() { - $defaultReport = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT); + $defaultReport = API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), API::PREFERENCE_DEFAULT_REPORT); $module = 'CoreHome'; $action = 'index'; @@ -128,7 +132,6 @@ class Piwik_CoreHome_Controller extends Controller Piwik::serveStaticFile($jsMergedFile, "application/javascript; charset=UTF-8"); } - // -------------------------------------------------------- // ROW EVOLUTION // The following methods render the popover that shows the @@ -170,9 +173,9 @@ class Piwik_CoreHome_Controller extends Controller private function makeRowEvolution($isMultiRowEvolution, $graphType = null) { if ($isMultiRowEvolution) { - return new Piwik_CoreHome_DataTableRowAction_MultiRowEvolution($this->idSite, $this->date, $graphType); + return new MultiRowEvolution($this->idSite, $this->date, $graphType); } else { - return new Piwik_CoreHome_DataTableRowAction_RowEvolution($this->idSite, $this->date, $graphType); + return new RowEvolution($this->idSite, $this->date, $graphType); } } @@ -219,7 +222,7 @@ class Piwik_CoreHome_Controller extends Controller $view->promoVideoUrl = 'http://www.youtube.com/watch?v=OslfF_EH81g'; echo $view->render(); } - + /** * Redirects the user to a paypal so they can donate to Piwik. */ @@ -234,9 +237,9 @@ class Piwik_CoreHome_Controller extends Controller unset($parameters[$name]); } } - - $url = "https://www.paypal.com/cgi-bin/webscr?".Url::getQueryStringFromParameters($parameters); - + + $url = "https://www.paypal.com/cgi-bin/webscr?" . Url::getQueryStringFromParameters($parameters); + header("Location: $url"); exit; } diff --git a/plugins/CoreHome/CoreHome.php b/plugins/CoreHome/CoreHome.php index c7b6e01a5f..e2e32b1a6b 100644 --- a/plugins/CoreHome/CoreHome.php +++ b/plugins/CoreHome/CoreHome.php @@ -6,16 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CoreHome + * @package CoreHome */ -use Piwik\Plugin; +namespace Piwik\Plugins\CoreHome; + use Piwik\WidgetsList; /** * - * @package Piwik_CoreHome + * @package CoreHome */ -class Piwik_CoreHome extends Plugin +class CoreHome extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/CoreHome/DataTableRowAction/MultiRowEvolution.php b/plugins/CoreHome/DataTableRowAction/MultiRowEvolution.php index 11b2d25ef2..3594675f41 100644 --- a/plugins/CoreHome/DataTableRowAction/MultiRowEvolution.php +++ b/plugins/CoreHome/DataTableRowAction/MultiRowEvolution.php @@ -6,18 +6,20 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CoreHome + * @package CoreHome */ +namespace Piwik\Plugins\CoreHome\DataTableRowAction; + use Piwik\Common; use Piwik\ViewDataTable; +use Piwik\Plugins\CoreHome\DataTableRowAction\RowEvolution; /** * MULTI ROW EVOLUTION * The class handles the popover that shows the evolution of a multiple rows in a data table - * @package Piwik_CoreHome + * @package CoreHome */ -class Piwik_CoreHome_DataTableRowAction_MultiRowEvolution - extends Piwik_CoreHome_DataTableRowAction_RowEvolution +class MultiRowEvolution extends RowEvolution { /** The requested metric */ protected $metric; @@ -70,4 +72,4 @@ class Piwik_CoreHome_DataTableRowAction_MultiRowEvolution return parent::renderPopover($controller, $view); } -}
\ No newline at end of file +} diff --git a/plugins/CoreHome/DataTableRowAction/RowEvolution.php b/plugins/CoreHome/DataTableRowAction/RowEvolution.php index 46654c531e..081b9ad374 100644 --- a/plugins/CoreHome/DataTableRowAction/RowEvolution.php +++ b/plugins/CoreHome/DataTableRowAction/RowEvolution.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CoreHome + * @package CoreHome */ +namespace Piwik\Plugins\CoreHome\DataTableRowAction; + +use Exception; use Piwik\API\ResponseBuilder; use Piwik\API\Request; use Piwik\Common; @@ -21,9 +24,9 @@ use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution as Evo /** * ROW EVOLUTION * The class handles the popover that shows the evolution of a singe row in a data table - * @package Piwik_CoreHome + * @package CoreHome */ -class Piwik_CoreHome_DataTableRowAction_RowEvolution +class RowEvolution { /** The current site id */ @@ -52,7 +55,7 @@ class Piwik_CoreHome_DataTableRowAction_RowEvolution /** * The data - * @var Piwik\DataTable + * @var \Piwik\DataTable */ protected $dataTable; @@ -186,12 +189,12 @@ class Piwik_CoreHome_DataTableRowAction_RowEvolution public function getRowEvolutionGraph($graphType = false, $metrics = false) { // set up the view data table - $view = ViewDataTable::factory($graphType ?: $this->graphType, $this->apiMethod, + $view = ViewDataTable::factory($graphType ? : $this->graphType, $this->apiMethod, $controllerAction = 'CoreHome.getRowEvolutionGraph', $forceDefault = true); $view->setDataTable($this->dataTable); if (!empty($this->graphMetrics)) { // In row Evolution popover, this is empty - $view->columns_to_display = array_keys($metrics ?: $this->graphMetrics); + $view->columns_to_display = array_keys($metrics ? : $this->graphMetrics); } $view->show_goals = false; @@ -217,7 +220,7 @@ class Piwik_CoreHome_DataTableRowAction_RowEvolution protected function getMetricsToggles() { $chart = new Evolution; - + $i = 0; $metrics = array(); foreach ($this->availableMetrics as $metric => $metricData) { diff --git a/plugins/CorePluginsAdmin/Controller.php b/plugins/CorePluginsAdmin/Controller.php index c1156cce99..0237c26a81 100644 --- a/plugins/CorePluginsAdmin/Controller.php +++ b/plugins/CorePluginsAdmin/Controller.php @@ -6,9 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CorePluginsAdmin + * @package CorePluginsAdmin */ -use Piwik\Controller\Admin; +namespace Piwik\Plugins\CorePluginsAdmin; + use Piwik\Piwik; use Piwik\Common; use Piwik\Config; @@ -17,9 +18,9 @@ use Piwik\Url; /** * - * @package Piwik_CorePluginsAdmin + * @package CorePluginsAdmin */ -class Piwik_CorePluginsAdmin_Controller extends Admin +class Controller extends \Piwik\Controller\Admin { function extend() { @@ -141,7 +142,7 @@ class Piwik_CorePluginsAdmin_Controller extends Admin { $pluginName = $this->initPluginModification(); $uninstalled = \Piwik\PluginsManager::getInstance()->uninstallPlugin($pluginName); - if(!$uninstalled) { + if (!$uninstalled) { $path = Common::getPathToPiwikRoot() . '/plugins/' . $pluginName . '/'; $messagePermissions = Piwik::getErrorMessageMissingPermissions($path); diff --git a/plugins/CorePluginsAdmin/CorePluginsAdmin.php b/plugins/CorePluginsAdmin/CorePluginsAdmin.php index fe4e9d8780..6116300ce2 100644 --- a/plugins/CorePluginsAdmin/CorePluginsAdmin.php +++ b/plugins/CorePluginsAdmin/CorePluginsAdmin.php @@ -6,16 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CorePluginsAdmin + * @package CorePluginsAdmin */ +namespace Piwik\Plugins\CorePluginsAdmin; + use Piwik\Piwik; -use Piwik\Plugin; /** * - * @package Piwik_CorePluginsAdmin + * @package CorePluginsAdmin */ -class Piwik_CorePluginsAdmin extends Plugin +class CorePluginsAdmin extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/CoreUpdater/Controller.php b/plugins/CoreUpdater/Controller.php index 82e24475fa..d829734ae3 100644 --- a/plugins/CoreUpdater/Controller.php +++ b/plugins/CoreUpdater/Controller.php @@ -6,14 +6,16 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CoreUpdater + * @package CoreUpdater */ +namespace Piwik\Plugins\CoreUpdater; + +use Exception; use Piwik\API\Request; use Piwik\ArchiveProcessor\Rules; use Piwik\Config; use Piwik\Piwik; use Piwik\Common; -use Piwik\Controller; use Piwik\Http; use Piwik\Updater; use Piwik\View; @@ -21,12 +23,15 @@ use Piwik\Version; use Piwik\UpdateCheck; use Piwik\Unzip; use Piwik\View\OneClickDone; +use Piwik\Plugins\CoreUpdater\CoreUpdater; +use Piwik\Plugins\LanguagesManager\LanguagesManager; +use Updater_UpdateErrorException; /** * - * @package Piwik_CoreUpdater + * @package CoreUpdater */ -class Piwik_CoreUpdater_Controller extends Controller +class Controller extends \Piwik\Controller { const CONFIG_FILE_BACKUP = '/config/global.ini.auto-backup-before-update.php'; const PATH_TO_EXTRACT_LATEST_VERSION = '/tmp/latest/'; @@ -232,7 +237,7 @@ class Piwik_CoreUpdater_Controller extends Controller { $language = Common::getRequestVar('language', ''); if (!empty($language)) { - Piwik_LanguagesManager::setLanguageForSession($language); + LanguagesManager::setLanguageForSession($language); } $this->runUpdaterAndExit(); } @@ -240,7 +245,7 @@ class Piwik_CoreUpdater_Controller extends Controller protected function runUpdaterAndExit() { $updater = new Updater(); - $componentsWithUpdateFile = Piwik_CoreUpdater::getComponentUpdates($updater); + $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater); if (empty($componentsWithUpdateFile)) { Piwik::redirectToModule('CoreHome'); } diff --git a/plugins/CoreUpdater/CoreUpdater.php b/plugins/CoreUpdater/CoreUpdater.php index 7e4d2497a5..20f3f5c0ae 100644 --- a/plugins/CoreUpdater/CoreUpdater.php +++ b/plugins/CoreUpdater/CoreUpdater.php @@ -6,21 +6,23 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CoreUpdater + * @package CoreUpdater */ +namespace Piwik\Plugins\CoreUpdater; + +use Exception; use Piwik\Piwik; use Piwik\Common; use Piwik\FrontController; use Piwik\Updater; use Piwik\Version; use Piwik\UpdateCheck; -use Piwik\Plugin; /** * - * @package Piwik_CoreUpdater + * @package CoreUpdater */ -class Piwik_CoreUpdater extends Plugin +class CoreUpdater extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered @@ -69,7 +71,7 @@ class Piwik_CoreUpdater extends Plugin && $action == 'saveLanguage') ) { if (FrontController::shouldRethrowException()) { - throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n". + throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n" . "--> Please run the update process first. See documentation: http://piwik.org/docs/update/ \n"); } else { Piwik::redirectToModule('CoreUpdater'); diff --git a/plugins/CoreVisualizations/CoreVisualizations.php b/plugins/CoreVisualizations/CoreVisualizations.php index 00330377a2..a1b970459e 100644 --- a/plugins/CoreVisualizations/CoreVisualizations.php +++ b/plugins/CoreVisualizations/CoreVisualizations.php @@ -6,10 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CoreVisualizations + * @package CoreVisualizations */ -use Piwik\Plugin; +namespace Piwik\Plugins\CoreVisualizations; require_once PIWIK_INCLUDE_PATH . '/plugins/CoreVisualizations/JqplotDataGenerator.php'; require_once PIWIK_INCLUDE_PATH . '/plugins/CoreVisualizations/Visualizations/Cloud.php'; @@ -20,7 +20,7 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/CoreVisualizations/Visualizations/Jq * This plugin contains all core visualizations, such as the normal HTML table and * jqPlot graphs. */ -class Piwik_CoreVisualizations extends Plugin +class CoreVisualizations extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered @@ -28,9 +28,9 @@ class Piwik_CoreVisualizations extends Plugin public function getListHooksRegistered() { return array( - 'AssetManager.getCssFiles' => 'getCssFiles', - 'AssetManager.getJsFiles' => 'getJsFiles', - 'DataTableVisualization.getAvailable' => 'getAvailableDataTableVisualizations', + 'AssetManager.getCssFiles' => 'getCssFiles', + 'AssetManager.getJsFiles' => 'getJsFiles', + 'DataTableVisualization.getAvailable' => 'getAvailableDataTableVisualizations', ); } diff --git a/plugins/CustomVariables/API.php b/plugins/CustomVariables/API.php index fb3e88456e..21bdca1f55 100644 --- a/plugins/CustomVariables/API.php +++ b/plugins/CustomVariables/API.php @@ -6,25 +6,28 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CustomVariables + * @package CustomVariables */ +namespace Piwik\Plugins\CustomVariables; + use Piwik\Archive; use Piwik\Metrics; use Piwik\Date; use Piwik\DataTable; use Piwik\Tracker\Action; +use Piwik\Plugins\CustomVariables\Archiver; /** * The Custom Variables API lets you access reports for your <a href='http://piwik.org/docs/custom-variables/' target='_blank'>Custom Variables</a> names and values. * - * @package Piwik_CustomVariables + * @package CustomVariables */ -class Piwik_CustomVariables_API +class API { static private $instance = null; /** - * @return Piwik_CustomVariables_API + * @return \Piwik\Plugins\CustomVariables\API */ static public function getInstance() { @@ -46,7 +49,7 @@ class Piwik_CustomVariables_API */ protected function getDataTable($idSite, $period, $date, $segment, $expanded, $idSubtable) { - $dataTable = Archive::getDataTableFromArchive(Piwik_CustomVariables_Archiver::CUSTOM_VARIABLE_RECORD_NAME, $idSite, $period, $date, $segment, $expanded, $idSubtable); + $dataTable = Archive::getDataTableFromArchive(Archiver::CUSTOM_VARIABLE_RECORD_NAME, $idSite, $period, $date, $segment, $expanded, $idSubtable); $dataTable->filter('Sort', array(Metrics::INDEX_NB_ACTIONS, 'desc', $naturalSort = false, $expanded)); $dataTable->queueFilter('ReplaceColumnNames'); $dataTable->queueFilter('ColumnDelete', 'nb_uniq_visitors'); @@ -111,7 +114,7 @@ class Piwik_CustomVariables_API $dataTable->renameColumn('price_viewed', 'price'); } $dataTable->queueFilter('ColumnCallbackReplace', array('label', create_function('$label', ' - return $label == Piwik_CustomVariables_Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED + return $label == \\Piwik\\Plugins\\CustomVariables\\Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED ? "' . Piwik_Translate('General_NotDefined', Piwik_Translate('CustomVariables_ColumnCustomVariableValue')) . '" : $label;'))); return $dataTable; diff --git a/plugins/CustomVariables/Archiver.php b/plugins/CustomVariables/Archiver.php index e26bb0a254..d4d3cb7884 100644 --- a/plugins/CustomVariables/Archiver.php +++ b/plugins/CustomVariables/Archiver.php @@ -1,24 +1,27 @@ <?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik_Plugins + * @package CustomVariables + */ +namespace Piwik\Plugins\CustomVariables; + use Piwik\Common; use Piwik\Config; use Piwik\DataAccess\LogAggregator; use Piwik\Metrics; use Piwik\DataArray; +use Piwik\Plugins\CustomVariables\API; use Piwik\Tracker; use Piwik\PluginsArchiver; use Piwik\Tracker\GoalManager; -/** - * Piwik - Open source web analytics - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - * @category Piwik_Plugins - * @package Piwik_CustomVariables - */ -class Piwik_CustomVariables_Archiver extends PluginsArchiver +class Archiver extends PluginsArchiver { const LABEL_CUSTOM_VALUE_NOT_DEFINED = "Value not defined"; const CUSTOM_VARIABLE_RECORD_NAME = 'CustomVariables_valueByName'; @@ -71,8 +74,8 @@ class Piwik_CustomVariables_Archiver extends PluginsArchiver // then we also query the "Product page view" price which was possibly recorded. $additionalSelects = false; // FIXMEA - if (in_array($slot, array(3,4,5))) { - $additionalSelects = array( $this->getSelectAveragePrice() ); + if (in_array($slot, array(3, 4, 5))) { + $additionalSelects = array($this->getSelectAveragePrice()); } $query = $this->getLogAggregator()->queryActionsByDimension($dimensions, $where, $additionalSelects); $this->aggregateFromActions($query, $keyField, $valueField); @@ -106,7 +109,6 @@ class Piwik_CustomVariables_Archiver extends PluginsArchiver return self::LABEL_CUSTOM_VALUE_NOT_DEFINED; } - protected function aggregateFromActions($query, $keyField, $valueField) { while ($row = $query->fetch()) { @@ -171,10 +173,9 @@ class Piwik_CustomVariables_Archiver extends PluginsArchiver protected static function isReservedKey($key) { - return in_array($key, Piwik_CustomVariables_API::getReservedCustomVariableKeys()); + return in_array($key, API::getReservedCustomVariableKeys()); } - protected function aggregateFromConversions($query, $keyField, $valueField) { if ($query === false) { @@ -190,7 +191,7 @@ class Piwik_CustomVariables_Archiver extends PluginsArchiver protected function removeVisitsMetricsFromActionsAggregate() { - $dataArray = &$this->dataArray->getDataArray(); + $dataArray = & $this->dataArray->getDataArray(); foreach ($dataArray as $key => &$row) { if (!self::isReservedKey($key) && DataArray::isRowActions($row) diff --git a/plugins/CustomVariables/Controller.php b/plugins/CustomVariables/Controller.php index 5607e2c630..da88d4e66e 100644 --- a/plugins/CustomVariables/Controller.php +++ b/plugins/CustomVariables/Controller.php @@ -6,16 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CustomVariables + * @package CustomVariables */ -use Piwik\Controller; +namespace Piwik\Plugins\CustomVariables; + use Piwik\ViewDataTable; use Piwik\View; /** - * @package Piwik_CustomVariables + * @package CustomVariables */ -class Piwik_CustomVariables_Controller extends Controller +class Controller extends \Piwik\Controller { public function index($fetch = false) { diff --git a/plugins/CustomVariables/CustomVariables.php b/plugins/CustomVariables/CustomVariables.php index 30ebb6b580..45bc3fa14b 100644 --- a/plugins/CustomVariables/CustomVariables.php +++ b/plugins/CustomVariables/CustomVariables.php @@ -6,17 +6,19 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_CustomVariables + * @package CustomVariables */ +namespace Piwik\Plugins\CustomVariables; + use Piwik\ArchiveProcessor; +use Piwik\Plugins\CustomVariables\Archiver; use Piwik\Tracker; -use Piwik\Plugin; use Piwik\WidgetsList; /** - * @package Piwik_CustomVariables + * @package CustomVariables */ -class Piwik_CustomVariables extends Plugin +class CustomVariables extends \Piwik\Plugin { public function getInformation() { @@ -137,16 +139,16 @@ class Piwik_CustomVariables extends Plugin */ public function archiveDay(ArchiveProcessor\Day $archiveProcessor) { - $archiving = new Piwik_CustomVariables_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archiveDay(); } } public function archivePeriod(ArchiveProcessor\Period $archiveProcessor) { - $archiving = new Piwik_CustomVariables_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archivePeriod(); } } @@ -164,26 +166,26 @@ class Piwik_CustomVariables extends Plugin array('<a target="_blank" href="http://piwik.org/docs/custom-variables/">', '</a>')); return array( - 'columns_to_display' => array('label', 'nb_actions', 'nb_visits'), - 'filter_sort_column' => 'nb_actions', - 'filter_sort_order' => 'desc', - 'show_goals' => true, + 'columns_to_display' => array('label', 'nb_actions', 'nb_visits'), + 'filter_sort_column' => 'nb_actions', + 'filter_sort_order' => 'desc', + 'show_goals' => true, 'subtable_controller_action' => 'getCustomVariablesValuesFromNameId', - 'translations' => array('label' => Piwik_Translate('CustomVariables_ColumnCustomVariableName')), - 'show_footer_message' => $footerMessage + 'translations' => array('label' => Piwik_Translate('CustomVariables_ColumnCustomVariableName')), + 'show_footer_message' => $footerMessage ); } private function getDisplayPropertiesForGetCustomVariablesValuesFromNameId() { return array( - 'columns_to_display' => array('label', 'nb_actions', 'nb_visits'), - 'filter_sort_column' => 'nb_actions', - 'filter_sort_order' => 'desc', - 'show_goals' => true, - 'show_search' => false, + 'columns_to_display' => array('label', 'nb_actions', 'nb_visits'), + 'filter_sort_column' => 'nb_actions', + 'filter_sort_order' => 'desc', + 'show_goals' => true, + 'show_search' => false, 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik_Translate('CustomVariables_ColumnCustomVariableValue')) + 'translations' => array('label' => Piwik_Translate('CustomVariables_ColumnCustomVariableValue')) ); } } diff --git a/plugins/DBStats/API.php b/plugins/DBStats/API.php index 46b3666c02..11788d19a1 100644 --- a/plugins/DBStats/API.php +++ b/plugins/DBStats/API.php @@ -6,11 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_DBStats + * @package DBStats */ +namespace Piwik\Plugins\DBStats; + use Piwik\Piwik; use Piwik\Common; use Piwik\DataTable; +use Piwik\Plugins\DBStats\MySQLMetadataProvider; /** * @see plugins/DBStats/MySQLMetadataProvider.php @@ -20,9 +23,9 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/DBStats/MySQLMetadataProvider.php'; /** * DBStats API is used to request the overall status of the Mysql tables in use by Piwik. * - * @package Piwik_DBStats + * @package DBStats */ -class Piwik_DBStats_API +class API { /** Singleton instance of this class. */ static private $instance = null; @@ -48,7 +51,7 @@ class Piwik_DBStats_API */ public function __construct() { - $this->metadataProvider = new Piwik_DBStats_MySQLMetadataProvider(); + $this->metadataProvider = new MySQLMetadataProvider(); } /** @@ -57,7 +60,7 @@ class Piwik_DBStats_API public function resetTableStatuses() { Piwik::checkUserIsSuperUser(); - self::getInstance()->metadataProvider = new Piwik_DBStats_MySQLMetadataProvider(); + self::getInstance()->metadataProvider = new MySQLMetadataProvider(); } /** @@ -169,8 +172,7 @@ class Piwik_DBStats_API $dataTable = $this->getMetricDataSummary(); - $getTableYear = array('Piwik_DBStats_API', 'getArchiveTableYear'); - $dataTable->filter('GroupBy', array('label', $getTableYear)); + $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\API::getArchiveTableYear')); return $dataTable; } @@ -199,8 +201,7 @@ class Piwik_DBStats_API $dataTable = $this->getReportDataSummary(); - $getTableYear = array('Piwik_DBStats_API', 'getArchiveTableYear'); - $dataTable->filter('GroupBy', array('label', $getTableYear)); + $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\API::getArchiveTableYear')); return $dataTable; } diff --git a/plugins/DBStats/Controller.php b/plugins/DBStats/Controller.php index 51f2a00ae6..941b095f81 100644 --- a/plugins/DBStats/Controller.php +++ b/plugins/DBStats/Controller.php @@ -6,18 +6,19 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_DBStats + * @package DBStats */ -use Piwik\Controller\Admin; +namespace Piwik\Plugins\DBStats; + use Piwik\Piwik; +use Piwik\Plugins\DBStats\API; use Piwik\ViewDataTable; use Piwik\View; /** - * - * @package Piwik_DBStats + * @package DBStats */ -class Piwik_DBStats_Controller extends Admin +class Controller extends \Piwik\Controller\Admin { /** * Returns the index for this plugin. Shows every other report defined by this plugin, @@ -38,7 +39,7 @@ class Piwik_DBStats_Controller extends Admin $view->reportDataSummary = $this->getReportDataSummary(true); $view->adminDataSummary = $this->getAdminDataSummary(true); - list($siteCount, $userCount, $totalSpaceUsed) = Piwik_DBStats_API::getInstance()->getGeneralInformation(); + list($siteCount, $userCount, $totalSpaceUsed) = API::getInstance()->getGeneralInformation(); $view->siteCount = Piwik::getPrettyNumber($siteCount); $view->userCount = Piwik::getPrettyNumber($userCount); $view->totalSpaceUsed = Piwik::getPrettySizeFromBytes($totalSpaceUsed); diff --git a/plugins/DBStats/DBStats.php b/plugins/DBStats/DBStats.php index 630bf4fe57..e3821800cc 100644 --- a/plugins/DBStats/DBStats.php +++ b/plugins/DBStats/DBStats.php @@ -6,20 +6,22 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_DBStats + * @package DBStats */ +namespace Piwik\Plugins\DBStats; + use Piwik\Piwik; use Piwik\Date; use Piwik\Common; +use Piwik\Plugins\DBStats\API; use Piwik\ScheduledTask; -use Piwik\Plugin; use Piwik\ScheduledTime\Weekly; /** * - * @package Piwik_DBStats + * @package DBStats */ -class Piwik_DBStats extends Plugin +class DBStats extends \Piwik\Plugin { const TIME_OF_LAST_TASK_RUN_OPTION = 'dbstats_time_of_last_cache_task_run'; @@ -65,7 +67,7 @@ class Piwik_DBStats extends Plugin */ public function cacheDataByArchiveNameReports() { - $api = Piwik_DBStats_API::getInstance(); + $api = API::getInstance(); $api->getIndividualReportsSummary(true); $api->getIndividualMetricsSummary(true); @@ -202,7 +204,7 @@ class Piwik_DBStats extends Plugin $result = array(); $this->addBaseDisplayProperties($result); $viewDataTable = $this->addPresentationFilters($result, $addTotalSizeColumn = false, $addPercentColumn = false, - $sizeColumns = array('estimated_size')); + $sizeColumns = array('estimated_size')); $result['filter_sort_order'] = 'asc'; $result['translations']['label'] = Piwik_Translate('General_Report'); @@ -222,7 +224,7 @@ class Piwik_DBStats extends Plugin $result = array(); $this->addBaseDisplayProperties($result); $this->addPresentationFilters($result, $addTotalSizeColumn = false, $addPercentColumn = false, - $sizeColumns = array('estimated_size')); + $sizeColumns = array('estimated_size')); $result['filter_sort_order'] = 'asc'; $result['translations']['label'] = Piwik_Translate('General_Metric'); @@ -279,7 +281,7 @@ class Piwik_DBStats extends Plugin }; $properties['filters'][] = array('ColumnCallbackAddColumn', - array(array('data_size', 'index_size'), 'total_size', $getTotalTableSize), $isPriority = true); + array(array('data_size', 'index_size'), 'total_size', $getTotalTableSize), $isPriority = true); $sizeColumns[] = 'total_size'; } @@ -299,9 +301,9 @@ class Piwik_DBStats extends Plugin && $addTotalSizeColumn ) { $properties['filters'][] = array('ColumnCallbackAddColumnPercentage', - array('percent_total', 'total_size', 'total_size', $quotientPrecision = 0, - $shouldSkipRows = false, $getDivisorFromSummaryRow = true), - $isPriority = true + array('percent_total', 'total_size', 'total_size', $quotientPrecision = 0, + $shouldSkipRows = false, $getDivisorFromSummaryRow = true), + $isPriority = true ); $properties['filter_sort_column'] = 'percent_total'; diff --git a/plugins/DBStats/MySQLMetadataProvider.php b/plugins/DBStats/MySQLMetadataProvider.php index d47713cf30..4e39d50887 100755 --- a/plugins/DBStats/MySQLMetadataProvider.php +++ b/plugins/DBStats/MySQLMetadataProvider.php @@ -6,15 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_DBStats + * @package DBStats */ +namespace Piwik\Plugins\DBStats; + +use Exception; use Piwik\Piwik; use Piwik\Common; use Piwik\Config; use Piwik\DataTable; use Piwik\Db; - /** * Utility class that provides general information about databases, including the size of * the entire database, the size and row count of each table and the size and row count @@ -23,7 +25,7 @@ use Piwik\Db; * This class will cache the table information it retrieves from the database. In order to * issue a new query instead of using this cache, you must create a new instance of this type. */ -class Piwik_DBStats_MySQLMetadataProvider +class MySQLMetadataProvider { /** * Cached MySQL table statuses. So we won't needlessly re-issue SHOW TABLE STATUS queries. diff --git a/plugins/Dashboard/API.php b/plugins/Dashboard/API.php index dd87979739..1330eacef6 100644 --- a/plugins/Dashboard/API.php +++ b/plugins/Dashboard/API.php @@ -5,21 +5,22 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @category Piwik_Plugins - * @package Piwik_Dashboard + * @package Dashboard */ +namespace Piwik\Plugins\Dashboard; + use Piwik\Piwik; use Piwik\WidgetsList; - /** * This API is the <a href='http://piwik.org/docs/analytics-api/reference/' target='_blank'>Dashboard API</a>: it gives information about dashboards. * * @package Piwik_API */ -class Piwik_Dashboard_API +class API { /** - * @var Piwik_Dashboard_API + * @var \Piwik\Plugins\Dashboard\API */ static private $instance = null; @@ -27,11 +28,11 @@ class Piwik_Dashboard_API public function __construct() { - $this->dashboard = new Piwik_Dashboard(); + $this->dashboard = new Dashboard(); } /** - * @return Piwik_Dashboard_API + * @return \Piwik\Plugins\Dashboard\API */ static public function getInstance() { @@ -83,7 +84,7 @@ class Piwik_Dashboard_API */ private function getUserDashboards() { - $userLogin = Piwik::getCurrentUserLogin(); + $userLogin = Piwik::getCurrentUserLogin(); $userDashboards = $this->dashboard->getAllDashboards($userLogin); $dashboards = array(); @@ -91,10 +92,9 @@ class Piwik_Dashboard_API foreach ($userDashboards as $userDashboard) { if ($this->hasDashboardColumns($userDashboard)) { - $widgets = $this->getExistingWidgetsWithinDashboard($userDashboard); + $widgets = $this->getExistingWidgetsWithinDashboard($userDashboard); $dashboards[] = $this->buildDashboard($userDashboard, $widgets); } - } return $dashboards; @@ -111,8 +111,8 @@ class Piwik_Dashboard_API foreach ($column as $widget) { if ($this->widgetIsNotHidden($widget) && $this->widgetExists($widget)) { - $module = $widget->parameters->module; - $action = $widget->parameters->action; + $module = $widget->parameters->module; + $action = $widget->parameters->action; $widgets[] = array('module' => $module, 'action' => $action); } diff --git a/plugins/Dashboard/Controller.php b/plugins/Dashboard/Controller.php index 7ffe0dc79e..bded95b33e 100644 --- a/plugins/Dashboard/Controller.php +++ b/plugins/Dashboard/Controller.php @@ -5,12 +5,14 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @category Piwik_Plugins - * @package Piwik_Dashboard + * @package Dashboard */ +namespace Piwik\Plugins\Dashboard; + use Piwik\DataTable\Renderer\Json; use Piwik\Piwik; use Piwik\Common; -use Piwik\Controller; +use Piwik\Plugins\Dashboard\Dashboard; use Piwik\Session\SessionNamespace; use Piwik\View; use Piwik\Db; @@ -19,12 +21,12 @@ use Piwik\WidgetsList; /** * Dashboard Controller * - * @package Piwik_Dashboard + * @package Dashboard */ -class Piwik_Dashboard_Controller extends Controller +class Controller extends \Piwik\Controller { /** - * @var Piwik_Dashboard + * @var Dashboard */ private $dashboard; @@ -32,7 +34,7 @@ class Piwik_Dashboard_Controller extends Controller { parent::init(); - $this->dashboard = new Piwik_Dashboard(); + $this->dashboard = new Dashboard(); } protected function _getDashboardView($template) @@ -96,7 +98,7 @@ class Piwik_Dashboard_Controller extends Controller $layout = $this->dashboard->getDefaultLayout(); $idDashboard = Common::getRequestVar('idDashboard', 1, 'int'); if (Piwik::isUserIsAnonymous()) { - $session = new SessionNamespace("Piwik_Dashboard"); + $session = new SessionNamespace("Dashboard"); $session->dashboardLayout = $layout; $session->setExpirationSeconds(1800); } else { @@ -161,15 +163,15 @@ class Piwik_Dashboard_Controller extends Controller public function getAllDashboards() { $this->checkTokenInUrl(); - + if (Piwik::isUserIsAnonymous()) { Json::sendHeaderJSON(); echo '[]'; - + return; } - $login = Piwik::getCurrentUserLogin(); + $login = Piwik::getCurrentUserLogin(); $dashboards = $this->dashboard->getAllDashboards($login); Json::sendHeaderJSON(); @@ -260,7 +262,7 @@ class Piwik_Dashboard_Controller extends Controller $idDashboard = Common::getRequestVar('idDashboard', 1, 'int'); $name = Common::getRequestVar('name', '', 'string'); if (Piwik::isUserIsAnonymous()) { - $session = new SessionNamespace("Piwik_Dashboard"); + $session = new SessionNamespace("Dashboard"); $session->dashboardLayout = $layout; $session->setExpirationSeconds(1800); } else { @@ -298,14 +300,13 @@ class Piwik_Dashboard_Controller extends Controller { if (Piwik::isUserIsAnonymous()) { - $session = new SessionNamespace("Piwik_Dashboard"); + $session = new SessionNamespace("Dashboard"); if (!isset($session->dashboardLayout)) { return $this->dashboard->getDefaultLayout(); } $layout = $session->dashboardLayout; - } else { $layout = $this->dashboard->getLayoutForUser(Piwik::getCurrentUserLogin(), $idDashboard); } @@ -335,7 +336,6 @@ class Piwik_Dashboard_Controller extends Controller array(25, 25, 25, 25) ); } - } diff --git a/plugins/Dashboard/Dashboard.php b/plugins/Dashboard/Dashboard.php index 13d25ee9cb..58618e05b4 100644 --- a/plugins/Dashboard/Dashboard.php +++ b/plugins/Dashboard/Dashboard.php @@ -6,19 +6,22 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Dashboard + * @package Dashboard */ +namespace Piwik\Plugins\Dashboard; + +use Exception; use Piwik\Piwik; use Piwik\Common; -use Piwik\Plugin; use Piwik\Site; use Piwik\Db; use Piwik\WidgetsList; +use Zend_Registry; /** - * @package Piwik_Dashboard + * @package Dashboard */ -class Piwik_Dashboard extends Plugin +class Dashboard extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/DevicesDetection/API.php b/plugins/DevicesDetection/API.php index 1800849fcf..250919c565 100644 --- a/plugins/DevicesDetection/API.php +++ b/plugins/DevicesDetection/API.php @@ -1,5 +1,4 @@ <?php - /** * Piwik - Open source web analytics * @@ -7,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_DevicesDetection + * @package DevicesDetection */ + +namespace Piwik\Plugins\DevicesDetection; + use Piwik\Archive; use Piwik\Metrics; use Piwik\Piwik; @@ -17,14 +19,14 @@ use Piwik\DataTable; /** * The DevicesDetection API lets you access reports on your visitors devices, brands, models, Operating system, Browsers. */ -class Piwik_DevicesDetection_API +class API { static private $instance = null; /** - * - * @return Piwik_DevicesDetection_API + * + * @return \Piwik\Plugins\DevicesDetection\API */ static public function getInstance() { @@ -64,9 +66,9 @@ class Piwik_DevicesDetection_API public function getType($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable('DevicesDetection_types', $idSite, $period, $date, $segment); - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_getDeviceTypeLabel')); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getDeviceTypeLabel')); $dataTable->filter('ColumnCallbackReplace', array('label', 'ucfirst')); - $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getDeviceTypeLogo')); + $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getDeviceTypeLogo')); return $dataTable; } @@ -81,8 +83,8 @@ class Piwik_DevicesDetection_API public function getBrand($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable('DevicesDetection_brands', $idSite, $period, $date, $segment); - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_getDeviceBrandLabel')); - $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_GetBrandLogo')); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getDeviceBrandLabel')); + $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getBrandLogo')); return $dataTable; } @@ -97,7 +99,7 @@ class Piwik_DevicesDetection_API public function getModel($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable('DevicesDetection_models', $idSite, $period, $date, $segment); - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_getModelName')); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getModelName')); return $dataTable; } @@ -112,8 +114,8 @@ class Piwik_DevicesDetection_API public function getOsFamilies($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable('DevicesDetection_os', $idSite, $period, $date, $segment); - $dataTable->filter('GroupBy', array('label', 'Piwik_getOSFamilyFullNameExtended')); - $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getOsFamilyLogoExtended')); + $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getOSFamilyFullNameExtended')); + $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getOsFamilyLogoExtended')); return $dataTable; } @@ -128,15 +130,15 @@ class Piwik_DevicesDetection_API public function getOsVersions($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable('DevicesDetection_osVersions', $idSite, $period, $date, $segment); - $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getOsLogoExtended')); - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_getOsFullNameExtended')); + $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getOsLogoExtended')); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getOsFullNameExtended')); return $dataTable; } /** * Gets datatable displaying number of visits by Browser family (eg. Firefox, InternetExplorer) - * @param int $idSite + * @param int $idSite * @param string $period * @param string $date * @param bool|string $segment @@ -145,8 +147,8 @@ class Piwik_DevicesDetection_API public function getBrowserFamilies($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable('DevicesDetection_browsers', $idSite, $period, $date, $segment); - $dataTable->filter('GroupBy', array('label', 'Piwik_getBrowserFamilyFullNameExtended')); - $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getBrowserFamilyLogoExtended')); + $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getBrowserFamilyFullNameExtended')); + $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getBrowserFamilyLogoExtended')); return $dataTable; } @@ -161,9 +163,8 @@ class Piwik_DevicesDetection_API public function getBrowserVersions($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable('DevicesDetection_browserVersions', $idSite, $period, $date, $segment); - $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getBrowserLogoExtended')); - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_getBrowserNameExtended')); + $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getBrowserLogoExtended')); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getBrowserNameExtended')); return $dataTable; } - }
\ No newline at end of file diff --git a/plugins/DevicesDetection/Archiver.php b/plugins/DevicesDetection/Archiver.php index 73a66fb67d..58b1df2cca 100644 --- a/plugins/DevicesDetection/Archiver.php +++ b/plugins/DevicesDetection/Archiver.php @@ -6,13 +6,15 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_DevicesDetection + * @package DevicesDetection */ +namespace Piwik\Plugins\DevicesDetection; + use Piwik\Metrics; use Piwik\PluginsArchiver; -class Piwik_DevicesDetection_Archiver extends PluginsArchiver +class Archiver extends PluginsArchiver { const DEVICE_TYPE_RECORD_NAME = 'DevicesDetection_types'; const DEVICE_BRAND_RECORD_NAME = 'DevicesDetection_brands'; @@ -32,16 +34,16 @@ class Piwik_DevicesDetection_Archiver extends PluginsArchiver public function archiveDay() { - $this->aggregateByLabel( self::DEVICE_TYPE_FIELD, self::DEVICE_TYPE_RECORD_NAME); - $this->aggregateByLabel( self::DEVICE_BRAND_FIELD, self::DEVICE_BRAND_RECORD_NAME); - $this->aggregateByLabel( self::DEVICE_MODEL_FIELD, self::DEVICE_MODEL_RECORD_NAME); - $this->aggregateByLabel( self::OS_FIELD, self::OS_RECORD_NAME); - $this->aggregateByLabel( self::OS_VERSION_FIELD, self::OS_VERSION_RECORD_NAME); - $this->aggregateByLabel( self::BROWSER_FIELD, self::BROWSER_RECORD_NAME); - $this->aggregateByLabel( self::BROWSER_VERSION_DIMENSION, self::BROWSER_VERSION_RECORD_NAME); + $this->aggregateByLabel(self::DEVICE_TYPE_FIELD, self::DEVICE_TYPE_RECORD_NAME); + $this->aggregateByLabel(self::DEVICE_BRAND_FIELD, self::DEVICE_BRAND_RECORD_NAME); + $this->aggregateByLabel(self::DEVICE_MODEL_FIELD, self::DEVICE_MODEL_RECORD_NAME); + $this->aggregateByLabel(self::OS_FIELD, self::OS_RECORD_NAME); + $this->aggregateByLabel(self::OS_VERSION_FIELD, self::OS_VERSION_RECORD_NAME); + $this->aggregateByLabel(self::BROWSER_FIELD, self::BROWSER_RECORD_NAME); + $this->aggregateByLabel(self::BROWSER_VERSION_DIMENSION, self::BROWSER_VERSION_RECORD_NAME); } - private function aggregateByLabel( $labelSQL, $recordName) + private function aggregateByLabel($labelSQL, $recordName) { $metrics = $this->getProcessor()->getMetricsForDimension($labelSQL); $table = $this->getProcessor()->getDataTableFromDataArray($metrics); diff --git a/plugins/DevicesDetection/Controller.php b/plugins/DevicesDetection/Controller.php index 189729e81e..ac0beb50d4 100644 --- a/plugins/DevicesDetection/Controller.php +++ b/plugins/DevicesDetection/Controller.php @@ -1,12 +1,4 @@ <?php -use Piwik\Piwik; -use Piwik\Common; -use Piwik\Controller; -use Piwik\ViewDataTable; -use Piwik\View; -use Piwik\Db; - - /** * Piwik - Open source web analytics * @@ -14,9 +6,18 @@ use Piwik\Db; * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_DevicesDetection + * @package DevicesDetection */ -class Piwik_DevicesDetection_Controller extends Controller +namespace Piwik\Plugins\DevicesDetection; + +use Piwik\Piwik; +use Piwik\Common; +use Piwik\ViewDataTable; +use Piwik\View; +use Piwik\Db; +use UserAgentParserEnhanced; + +class Controller extends \Piwik\Controller { public function index($fetch = false) { diff --git a/plugins/DevicesDetection/DevicesDetection.php b/plugins/DevicesDetection/DevicesDetection.php index 35fb148866..d207cdc285 100644 --- a/plugins/DevicesDetection/DevicesDetection.php +++ b/plugins/DevicesDetection/DevicesDetection.php @@ -1,5 +1,4 @@ <?php - /** * Piwik - Open source web analytics * @@ -7,20 +6,25 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_DevicesDetection + * @package DevicesDetection */ + +namespace Piwik\Plugins\DevicesDetection; + +use Exception; use Piwik\ArchiveProcessor; use Piwik\Config; use Piwik\Common; -use Piwik\Plugin; +use Piwik\Plugins\DevicesDetection\Archiver; use Piwik\WidgetsList; use Piwik\Db; - +use UserAgentParserEnhanced; +use Zend_Registry; require_once PIWIK_INCLUDE_PATH . "/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php"; require_once PIWIK_INCLUDE_PATH . '/plugins/DevicesDetection/functions.php'; -class Piwik_DevicesDetection extends Plugin +class DevicesDetection extends \Piwik\Plugin { /** The set of related reports displayed under the 'Operating Systems' header. */ private $osRelatedReports = null; @@ -45,27 +49,26 @@ class Piwik_DevicesDetection extends Plugin public function getInformation() { return array( - 'description' => "[Beta Plugin] " . Piwik_Translate("DevicesDetection_description"), - 'author' => 'Piwik and Clearcode.cc', + 'description' => "[Beta Plugin] " . Piwik_Translate("DevicesDetection_description"), + 'author' => 'Piwik and Clearcode.cc', 'author_homepage' => 'http://clearcode.cc', - 'version' => '1.12-b6', + 'version' => '1.12-b6', ); } - /** * @see Piwik_Plugin::getListHooksRegistered */ public function getListHooksRegistered() { return array( - 'ArchiveProcessing_Day.compute' => "archiveDay", - 'ArchiveProcessing_Period.compute' => 'archivePeriod', - 'Menu.add' => 'addMenu', - 'Tracker.newVisitorInformation' => 'parseMobileVisitData', - 'WidgetsList.add' => 'addWidgets', - 'API.getReportMetadata' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ArchiveProcessing_Day.compute' => "archiveDay", + 'ArchiveProcessing_Period.compute' => 'archivePeriod', + 'Menu.add' => 'addMenu', + 'Tracker.newVisitorInformation' => 'parseMobileVisitData', + 'WidgetsList.add' => 'addWidgets', + 'API.getReportMetadata' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); } @@ -155,7 +158,6 @@ class Piwik_DevicesDetection extends Plugin } } - /** * Get segments meta data */ @@ -187,12 +189,12 @@ class Piwik_DevicesDetection extends Plugin continue; $report = array( - 'category' => Piwik_Translate($category), - 'name' => Piwik_Translate($name), - 'module' => $apiModule, - 'action' => $apiAction, + 'category' => Piwik_Translate($category), + 'name' => Piwik_Translate($name), + 'module' => $apiModule, + 'action' => $apiAction, 'dimension' => Piwik_Translate($columnName), - 'order' => $i++ + 'order' => $i++ ); $translation = $name . 'Documentation'; @@ -201,7 +203,6 @@ class Piwik_DevicesDetection extends Plugin $report['documentation'] = $translated; } - $reports[] = $report; } } @@ -223,7 +224,7 @@ class Piwik_DevicesDetection extends Plugin Db::exec($q2); } } catch (Exception $e) { - if (!Zend_Registry::get('db')->isErrNo($e, '1060')) { + if (!Zend_Registry::get('db')->isErrNo($e, '1060')) { throw $e; } } @@ -254,16 +255,16 @@ class Piwik_DevicesDetection extends Plugin public function archiveDay(ArchiveProcessor\Day $archiveProcessor) { - $archiving = new Piwik_DevicesDetection_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archiveDay(); } } public function archivePeriod(ArchiveProcessor\Period $archiveProcessor) { - $archiving = new Piwik_DevicesDetection_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archivePeriod(); } } @@ -287,34 +288,34 @@ class Piwik_DevicesDetection extends Plugin private function getDisplayPropertiesForGetType() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelTypes")) + 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelTypes")) ); } private function getDisplayPropertiesForGetBrand() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelBrands")) + 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelBrands")) ); } private function getDisplayPropertiesForGetModel() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelModels")) + 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelModels")) ); } private function getDisplayPropertiesForGetOsFamilies() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelSystemFamily")), 'title' => Piwik_Translate('DeviceDetection_OperatingSystemFamilies'), @@ -325,7 +326,7 @@ class Piwik_DevicesDetection extends Plugin private function getDisplayPropertiesForGetOsVersions() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelSystemVersion")), 'title' => Piwik_Translate('DeviceDetection_OperatingSystemVersions'), @@ -336,7 +337,7 @@ class Piwik_DevicesDetection extends Plugin private function getDisplayPropertiesForGetBrowserFamilies() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelBrowserFamily")), 'title' => Piwik_Translate('DevicesDetection_BrowsersFamily'), @@ -347,7 +348,7 @@ class Piwik_DevicesDetection extends Plugin private function getDisplayPropertiesForGetBrowserVersions() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelBrowserVersion")), 'related_reports' => $this->getBrowserRelatedReports() diff --git a/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php b/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php index d078305d97..a8ec8e2204 100644 --- a/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php +++ b/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php @@ -7,7 +7,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_DevicesDetection + * @package DevicesDetection */ //yml parser require_once(PIWIK_INCLUDE_PATH.'/libs/spyc.php'); diff --git a/plugins/DevicesDetection/UserAgentParserEnhanced/regexes/browsers.yml b/plugins/DevicesDetection/UserAgentParserEnhanced/regexes/browsers.yml index 9ab3bc4c1c..351aa7f268 100644 --- a/plugins/DevicesDetection/UserAgentParserEnhanced/regexes/browsers.yml +++ b/plugins/DevicesDetection/UserAgentParserEnhanced/regexes/browsers.yml @@ -5,7 +5,7 @@ # @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later # # @category Piwik_Plugins -# @package Piwik_DevicesDetection +# @package DevicesDetection ############### # SeaMonkey diff --git a/plugins/DevicesDetection/UserAgentParserEnhanced/regexes/mobiles.yml b/plugins/DevicesDetection/UserAgentParserEnhanced/regexes/mobiles.yml index d9a2a22f88..46ae6b9c97 100644 --- a/plugins/DevicesDetection/UserAgentParserEnhanced/regexes/mobiles.yml +++ b/plugins/DevicesDetection/UserAgentParserEnhanced/regexes/mobiles.yml @@ -5,7 +5,7 @@ # @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later # # @category Piwik_Plugins -# @package Piwik_DevicesDetection +# @package DevicesDetection ############### # HTC diff --git a/plugins/DevicesDetection/UserAgentParserEnhanced/regexes/oss.yml b/plugins/DevicesDetection/UserAgentParserEnhanced/regexes/oss.yml index 71b85f987f..918a00487d 100644 --- a/plugins/DevicesDetection/UserAgentParserEnhanced/regexes/oss.yml +++ b/plugins/DevicesDetection/UserAgentParserEnhanced/regexes/oss.yml @@ -5,7 +5,7 @@ # @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later # # @category Piwik_Plugins -# @package Piwik_DevicesDetection +# @package DevicesDetection ############### ########## diff --git a/plugins/DevicesDetection/functions.php b/plugins/DevicesDetection/functions.php index 4819cd6974..92a4b3e84e 100644 --- a/plugins/DevicesDetection/functions.php +++ b/plugins/DevicesDetection/functions.php @@ -1,5 +1,4 @@ <?php - /** * Piwik - Open source web analytics * @@ -7,9 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_DevicesDetection + * @package DevicesDetection */ -function Piwik_GetBrandLogo($label) + +namespace Piwik\Plugins\DevicesDetection; + +use UserAgentParserEnhanced; + +function getBrandLogo($label) { $path = dirname(__FILE__) . '/images/brand/' . $label . '.ico'; if (file_exists($path)) { @@ -19,7 +23,7 @@ function Piwik_GetBrandLogo($label) } } -function Piwik_getBrowserFamilyFullNameExtended($label) +function getBrowserFamilyFullNameExtended($label) { foreach (UserAgentParserEnhanced::$browserFamilies as $name => $family) { if (in_array($label, $family)) { @@ -29,7 +33,7 @@ function Piwik_getBrowserFamilyFullNameExtended($label) return Piwik_Translate('General_Unknown'); } -function Piwik_getBrowserFamilyLogoExtended($label) +function getBrowserFamilyLogoExtended($label) { if (array_key_exists($label, UserAgentParserEnhanced::$browserFamilies)) { $path = 'plugins/UserSettings/images/browsers/' . UserAgentParserEnhanced::$browserFamilies[$label][0] . '.gif'; @@ -39,7 +43,7 @@ function Piwik_getBrowserFamilyLogoExtended($label) return $path; } -function Piwik_getBrowserNameExtended($label) +function getBrowserNameExtended($label) { $short = substr($label, 0, 2); $ver = substr($label, 3, 10); @@ -50,17 +54,17 @@ function Piwik_getBrowserNameExtended($label) } } -function Piwik_getBrowserLogoExtended($label) +function getBrowserLogoExtended($label) { $short = substr($label, 0, 2); - $familyName = Piwik_getBrowserFamilyFullNameExtended($short); - $path = Piwik_getBrowserFamilyLogoExtended($familyName); + $familyName = getBrowserFamilyFullNameExtended($short); + $path = getBrowserFamilyLogoExtended($familyName); return $path; } -function Piwik_getDeviceBrandLabel($label) +function getDeviceBrandLabel($label) { if (array_key_exists($label, UserAgentParserEnhanced::$deviceBrands)) { return ucfirst(UserAgentParserEnhanced::$deviceBrands[$label]); @@ -69,7 +73,7 @@ function Piwik_getDeviceBrandLabel($label) } } -function Piwik_getDeviceTypeLabel($label) +function getDeviceTypeLabel($label) { if (isset(UserAgentParserEnhanced::$deviceTypes[$label])) { return UserAgentParserEnhanced::$deviceTypes[$label]; @@ -78,7 +82,7 @@ function Piwik_getDeviceTypeLabel($label) } } -function Piwik_getDeviceTypeLogo($label) +function getDeviceTypeLogo($label) { $deviceTypeLogos = Array( "Desktop" => "normal.gif", @@ -97,7 +101,7 @@ function Piwik_getDeviceTypeLogo($label) return $path; } -function Piwik_getModelName($label) +function getModelName($label) { if (!$label) { return Piwik_Translate('General_Unknown'); @@ -105,7 +109,7 @@ function Piwik_getModelName($label) return $label; } -function Piwik_getOSFamilyFullNameExtended($label) +function getOSFamilyFullNameExtended($label) { foreach (UserAgentParserEnhanced::$osFamilies as $name => $family) { if (in_array($label, $family)) { @@ -115,7 +119,7 @@ function Piwik_getOSFamilyFullNameExtended($label) return Piwik_Translate('General_Unknown'); } -function Piwik_getOsFamilyLogoExtended($label) +function getOsFamilyLogoExtended($label) { if (array_key_exists($label, UserAgentParserEnhanced::$osFamilies)) { $path = 'plugins/UserSettings/images/os/' . UserAgentParserEnhanced::$osFamilies[$label][0] . ".gif"; @@ -125,7 +129,7 @@ function Piwik_getOsFamilyLogoExtended($label) return $path; } -function Piwik_getOsFullNameExtended($label) +function getOsFullNameExtended($label) { if (!empty($label) && $label != ";") { $os = substr($label, 0, 3); @@ -140,10 +144,10 @@ function Piwik_getOsFullNameExtended($label) -function Piwik_getOsLogoExtended($label) +function getOsLogoExtended($label) { $short = substr($label, 0, 3); - $familyName = Piwik_getOsFamilyFullNameExtended($short); - $path = Piwik_getOsFamilyLogoExtended($familyName); + $familyName = getOsFamilyFullNameExtended($short); + $path = getOsFamilyLogoExtended($familyName); return $path; }
\ No newline at end of file diff --git a/plugins/DoNotTrack/DoNotTrack.php b/plugins/DoNotTrack/DoNotTrack.php index 8d9a3cf700..1a02788a27 100644 --- a/plugins/DoNotTrack/DoNotTrack.php +++ b/plugins/DoNotTrack/DoNotTrack.php @@ -6,9 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_DoNotTrack + * @package DoNotTrack */ -use Piwik\Plugin; +namespace Piwik\Plugins\DoNotTrack; + use Piwik\Common; use Piwik\Tracker\IgnoreCookie; use Piwik\Tracker\Request; @@ -18,9 +19,9 @@ use Piwik\Tracker\Request; * - X-Do-Not-Track header (used by AdBlockPlus and NoScript) * - DNT header (used by Mozilla) * - * @package Piwik_DoNotTrack + * @package DoNotTrack */ -class Piwik_DoNotTrack extends Plugin +class DoNotTrack extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/ExampleAPI/API.php b/plugins/ExampleAPI/API.php index 214d73eac5..a6c012a644 100644 --- a/plugins/ExampleAPI/API.php +++ b/plugins/ExampleAPI/API.php @@ -8,9 +8,11 @@ * @category Piwik_Plugins * @package Piwik_ExampleAPI */ +namespace Piwik\Plugins\ExampleAPI; + +use Piwik\DataTable; use Piwik\DataTable\Row; use Piwik\Piwik; -use Piwik\DataTable; use Piwik\Version; /** @@ -19,7 +21,7 @@ use Piwik\Version; * Please see the <a href='http://dev.piwik.org/trac/browser/trunk/plugins/ExampleAPI/API.php#L1' target='_blank'>source code in in the file plugins/ExampleAPI/API.php</a> for more documentation. * @package Piwik_ExampleAPI */ -class Piwik_ExampleAPI_API +class API { /** * * This is an example of a basic API file. Each plugin can have one public API. @@ -38,14 +40,14 @@ class Piwik_ExampleAPI_API * * It is highly recommended that all the plugin logic is done inside API implementations, and the * Controller and other objects would all call the API internally using, eg. - * Piwik_ExampleAPI_API::getInstance()->getSum(1, 2); + * API::getInstance()->getSum(1, 2); * */ static private $instance = null; /** * Singleton - * @return Piwik_ExampleAPI_API + * @return \Piwik\Plugins\ExampleAPI\API */ static public function getInstance() { @@ -80,11 +82,11 @@ class Piwik_ExampleAPI_API * If used internally, the data structure can be returned untouched by using * the API parameter 'format=original' * - * @return Piwik_MagicObject Will return a standard Piwik error when called from the Web APIs + * @return MagicObject Will return a standard Piwik error when called from the Web APIs */ public function getObject() { - return new Piwik_MagicObject(); + return new MagicObject(); } /** @@ -180,9 +182,9 @@ class Piwik_ExampleAPI_API /** * Magic Object * - * @package Piwik_ExamplePlugin + * @package ExamplePlugin */ -class Piwik_MagicObject +class MagicObject { function Incredible() { @@ -191,4 +193,4 @@ class Piwik_MagicObject protected $wonderful = 'magnifique'; public $great = 'formidable'; -} +}
\ No newline at end of file diff --git a/plugins/ExampleAPI/ExampleAPI.php b/plugins/ExampleAPI/ExampleAPI.php deleted file mode 100644 index da1c3f4c52..0000000000 --- a/plugins/ExampleAPI/ExampleAPI.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php -/** - * Piwik - Open source web analytics - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - * @category Piwik_Plugins - * @package Piwik_ExampleAPI - */ -use Piwik\Plugin; - -/** - * ExampleAPI plugin - * - * @package Piwik_ExampleAPI - */ -class Piwik_ExampleAPI extends Plugin -{ -} diff --git a/plugins/ExamplePlugin/Controller.php b/plugins/ExamplePlugin/Controller.php index dfb4c18eb5..c13df5baa9 100644 --- a/plugins/ExamplePlugin/Controller.php +++ b/plugins/ExamplePlugin/Controller.php @@ -6,21 +6,22 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ExamplePlugin + * @package ExamplePlugin */ +namespace Piwik\Plugins\ExamplePlugin; + use Piwik\Piwik; use Piwik\Common; -use Piwik\Controller; use Piwik\View; use Piwik\Db; use Piwik\WidgetsList; - +use Piwik\Plugins\SitesManager\API; /** * - * @package Piwik_ExamplePlugin + * @package ExamplePlugin */ -class Piwik_ExamplePlugin_Controller extends Controller +class Controller extends \Piwik\Controller { /** * Go to /piwik/?module=ExamplePlugin&action=helloWorld to execute this method @@ -89,7 +90,6 @@ class Piwik_ExamplePlugin_Controller extends Controller $out .= '<code>WidgetsList::add( $widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array());</code> - Adds a widget that users can add in the dashboard, or export using the Widgets link at the top of the screen. See the example in the <a href="https://github.com/piwik/piwik/blob/1.0/plugins/UserCountry/UserCountry.php#L70">UserCountry Plugin file</a> or any other plugin)<br />'; $out .= '<code>Common::prefixTable("site")</code> = <b>' . Common::prefixTable("site") . '</b><br />'; - $out .= '<h2>User access</h2>'; $out .= '<code>Piwik::getCurrentUserLogin()</code> = <b>' . Piwik::getCurrentUserLogin() . '</b><br />'; $out .= '<code>Piwik::isUserHasSomeAdminAccess()</code> = <b>' . self::boolToString(Piwik::isUserHasSomeAdminAccess()) . '</b><br />'; @@ -112,19 +112,19 @@ class Piwik_ExamplePlugin_Controller extends Controller $out .= 'At this point, we have: <code>$fetched[\'token_auth\'] == <b>' . var_export($token_auth, true) . '</b></code><br />'; $out .= '<h2>Example Sites information API</h2>'; - $out .= '<code>Piwik_SitesManager_API::getInstance()->getSitesWithViewAccess()</code> = <b><pre>' . var_export(Piwik_SitesManager_API::getInstance()->getSitesWithViewAccess(), true) . '</pre></b><br />'; - $out .= '<code>Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess()</code> = <b><pre>' . var_export(Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess(), true) . '</pre></b><br />'; + $out .= '<code>API::getInstance()->getSitesWithViewAccess()</code> = <b><pre>' . var_export(API::getInstance()->getSitesWithViewAccess(), true) . '</pre></b><br />'; + $out .= '<code>API::getInstance()->getSitesWithAdminAccess()</code> = <b><pre>' . var_export(API::getInstance()->getSitesWithAdminAccess(), true) . '</pre></b><br />'; $out .= '<h2>Example API Users information</h2>'; $out .= 'View the list of API methods you can call on <a href="http://piwik.org/docs/analytics-api/reference">API reference</a><br />'; - $out .= 'For example you can try <code>Piwik_UsersManager_API::getInstance()->getUsersSitesFromAccess("view");</code> or <code>Piwik_UsersManager_API::getInstance()->deleteUser("userToDelete");</code><br />'; + $out .= 'For example you can try <code>API::getInstance()->getUsersSitesFromAccess("view");</code> or <code>API::getInstance()->deleteUser("userToDelete");</code><br />'; $out .= '<h2>Javascript in Piwik</h2>'; $out .= '<h3>i18n internationalization</h3>'; $out .= 'In order to translate strings within Javascript code, you can use the javascript function _pk_translate( token );. <ul><li>The "token" parameter is the string unique key found in the translation file. For this token string to be available in Javascript, you must suffix your token by "_js" in the language file. For example, you can add <code>\'Goals_AddGoal_js\' => \'Add Goal\',</code> in the lang/en.php file</li> - <li>You then need to instruct Piwik to load your Javascript translations for your plugin; by default, all translation strings are not loaded in Javascript for performance reasons. This can be done by calling a custom-made Twig modifier before the Javascript code requiring translations, eg. + <li>You then need to instruct Piwik to load your Javascript translations for your plugin; by default, all translation strings are not loaded in Javascript for performance reasons. This can be done by calling a custom-made Twig modifier before the Javascript code requiring translations, eg. <code>{loadJavascriptTranslations plugins=\'$YOUR_PLUGIN_NAME\'}</code>. In our previous example, the $YOUR_PLUGIN_NAME being Goals, we would write <code>{loadJavascriptTranslations plugins=\'Goals\'}</code> </li><li>You can then print this string from your JS code by doing <code>_pk_translate(\'Goals_AddGoal_js\');</code>. </li></ul>'; diff --git a/plugins/ExamplePlugin/ExamplePlugin.php b/plugins/ExamplePlugin/ExamplePlugin.php index 481c324b5d..812898291d 100644 --- a/plugins/ExamplePlugin/ExamplePlugin.php +++ b/plugins/ExamplePlugin/ExamplePlugin.php @@ -6,16 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ExamplePlugin + * @package ExamplePlugin */ -use Piwik\Plugin; +namespace Piwik\Plugins\ExamplePlugin; + use Piwik\WidgetsList; /** * - * @package Piwik_ExamplePlugin + * @package ExamplePlugin */ -class Piwik_ExamplePlugin extends Plugin +class ExamplePlugin extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/ExamplePlugin/lang/en.php b/plugins/ExamplePlugin/lang/en.php index 9be43dddea..eaec0c9940 100644 --- a/plugins/ExamplePlugin/lang/en.php +++ b/plugins/ExamplePlugin/lang/en.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ExamplePlugin + * @package ExamplePlugin */ $translations = array( diff --git a/plugins/ExampleRssWidget/Controller.php b/plugins/ExampleRssWidget/Controller.php index ce1806b632..a8a5eb7247 100644 --- a/plugins/ExampleRssWidget/Controller.php +++ b/plugins/ExampleRssWidget/Controller.php @@ -6,20 +6,24 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ExampleRssWidget + * @package ExampleRssWidget */ -use Piwik\Controller; + +namespace Piwik\Plugins\ExampleRssWidget; + +use Exception; +use Piwik\Plugins\ExampleRssWidget\RssRenderer; /** * - * @package Piwik_ExampleRssWidget + * @package ExampleRssWidget */ -class Piwik_ExampleRssWidget_Controller extends Controller +class Controller extends \Piwik\Controller { public function rssPiwik() { try { - $rss = new Piwik_ExampleRssWidget_Rss('http://feeds.feedburner.com/Piwik'); + $rss = new RssRenderer('http://feeds.feedburner.com/Piwik'); $rss->showDescription(true); echo $rss->get(); } catch (Exception $e) { @@ -30,7 +34,7 @@ class Piwik_ExampleRssWidget_Controller extends Controller public function rssChangelog() { try { - $rss = new Piwik_ExampleRssWidget_Rss('http://feeds.feedburner.com/PiwikReleases'); + $rss = new RssRenderer('http://feeds.feedburner.com/PiwikReleases'); $rss->setCountPosts(1); $rss->showDescription(false); $rss->showContent(true); diff --git a/plugins/ExampleRssWidget/ExampleRssWidget.php b/plugins/ExampleRssWidget/ExampleRssWidget.php index a23daf88ee..868913959e 100644 --- a/plugins/ExampleRssWidget/ExampleRssWidget.php +++ b/plugins/ExampleRssWidget/ExampleRssWidget.php @@ -6,16 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ExampleRssWidget + * @package ExampleRssWidget */ -use Piwik\Plugin; +namespace Piwik\Plugins\ExampleRssWidget; + use Piwik\WidgetsList; /** * - * @package Piwik_ExampleRssWidget + * @package ExampleRssWidget */ -class Piwik_ExampleRssWidget extends Plugin +class ExampleRssWidget extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/ExampleRssWidget/Rss.php b/plugins/ExampleRssWidget/RssRenderer.php index ee95a8a56d..1b7baa1ba2 100644 --- a/plugins/ExampleRssWidget/Rss.php +++ b/plugins/ExampleRssWidget/RssRenderer.php @@ -6,14 +6,19 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ExampleRssWidget + * @package ExampleRssWidget */ +namespace Piwik\Plugins\ExampleRssWidget; + +use Zend_Feed; +use Zend_Feed_Exception; + /** * - * @package Piwik_ExampleRssWidget + * @package ExampleRssWidget */ -class Piwik_ExampleRssWidget_Rss +class RssRenderer { protected $url = null; protected $count = 3; diff --git a/plugins/ExampleUI/API.php b/plugins/ExampleUI/API.php index 4fc0c513f8..d2128fa296 100644 --- a/plugins/ExampleUI/API.php +++ b/plugins/ExampleUI/API.php @@ -6,8 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ExampleUI + * @package ExampleUI */ +namespace Piwik\Plugins\ExampleUI; + use Piwik\Period\Range; use Piwik\DataTable; @@ -17,14 +19,14 @@ use Piwik\DataTable; * The functions listed in this API are returning the data used in the Controller to draw graphs and * display tables. See also the ExampleAPI plugin for an introduction to Piwik APIs. * - * @package Piwik_ExampleUI + * @package ExampleUI */ -class Piwik_ExampleUI_API +class API { static private $instance = null; /** - * @return Piwik_ExampleUI_API + * @return \Piwik\Plugins\ExampleUI\API */ static public function getInstance() { diff --git a/plugins/ExampleUI/Controller.php b/plugins/ExampleUI/Controller.php index 5c6f27254c..dc1415b411 100644 --- a/plugins/ExampleUI/Controller.php +++ b/plugins/ExampleUI/Controller.php @@ -6,17 +6,18 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ExampleUI + * @package ExampleUI */ +namespace Piwik\Plugins\ExampleUI; + use Piwik\Common; -use Piwik\Controller; use Piwik\ViewDataTable; use Piwik\View; /** - * @package Piwik_ExampleUI + * @package ExampleUI */ -class Piwik_ExampleUI_Controller extends Controller +class Controller extends \Piwik\Controller { public function dataTables() { @@ -130,7 +131,7 @@ class Piwik_ExampleUI_Controller extends Controller if ($serverRequested !== false) { $view->columns_to_display = array($serverRequested); } - + echo $view->render(); } diff --git a/plugins/ExampleUI/ExampleUI.php b/plugins/ExampleUI/ExampleUI.php index 4e1210cf14..fcd6120cca 100644 --- a/plugins/ExampleUI/ExampleUI.php +++ b/plugins/ExampleUI/ExampleUI.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ExampleUI + * @package ExampleUI */ /* @@ -18,13 +18,14 @@ - without all columns icon + update http://piwik.org/participate/user-interface */ -use Piwik\Plugin; +namespace Piwik\Plugins\ExampleUI; + /** * - * @package Piwik_ExampleUI + * @package ExampleUI */ -class Piwik_ExampleUI extends Plugin +class ExampleUI extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/Feedback/Controller.php b/plugins/Feedback/Controller.php index 3a43559d6f..2b80b18ad2 100644 --- a/plugins/Feedback/Controller.php +++ b/plugins/Feedback/Controller.php @@ -6,12 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Feedback + * @package Feedback */ +namespace Piwik\Plugins\Feedback; + +use Exception; use Piwik\Config; use Piwik\Piwik; use Piwik\Common; -use Piwik\Controller; use Piwik\IP; use Piwik\Mail; use Piwik\Nonce; @@ -21,14 +23,14 @@ use Piwik\Url; /** * - * @package Piwik_Feedback + * @package Feedback */ -class Piwik_Feedback_Controller extends Controller +class Controller extends \Piwik\Controller { function index() { $view = new View('@Feedback/index'); - $view->nonce = Nonce::getNonce('Piwik_Feedback.sendFeedback', 3600); + $view->nonce = Nonce::getNonce('Feedback.sendFeedback', 3600); echo $view->render(); } @@ -60,10 +62,10 @@ class Piwik_Feedback_Controller extends Controller if (preg_match('/https?:/i', $body)) { throw new Exception(Piwik_TranslateException('Feedback_ExceptionNoUrls')); } - if (!Nonce::verifyNonce('Piwik_Feedback.sendFeedback', $nonce)) { + if (!Nonce::verifyNonce('Feedback.sendFeedback', $nonce)) { throw new Exception(Piwik_TranslateException('General_ExceptionNonceMismatch')); } - Nonce::discardNonce('Piwik_Feedback.sendFeedback'); + Nonce::discardNonce('Feedback.sendFeedback'); $mail = new Mail(); $mail->setFrom(Common::unsanitizeInputValue($email)); diff --git a/plugins/Feedback/Feedback.php b/plugins/Feedback/Feedback.php index 522c09fe96..48f8d297f4 100644 --- a/plugins/Feedback/Feedback.php +++ b/plugins/Feedback/Feedback.php @@ -6,15 +6,16 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Feedback + * @package Feedback */ -use Piwik\Plugin; +namespace Piwik\Plugins\Feedback; + /** * - * @package Piwik_Feedback + * @package Feedback */ -class Piwik_Feedback extends Plugin +class Feedback extends \Piwik\Plugin { /** diff --git a/plugins/Goals/API.php b/plugins/Goals/API.php index 3eb1a62e28..c80ade9ac3 100644 --- a/plugins/Goals/API.php +++ b/plugins/Goals/API.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Goals + * @package Goals */ +namespace Piwik\Plugins\Goals; + +use Exception; use Piwik\Archive; use Piwik\Metrics; use Piwik\Piwik; @@ -17,6 +20,8 @@ use Piwik\Site; use Piwik\Db; use Piwik\Tracker\Cache; use Piwik\Tracker\GoalManager; +use Piwik\Plugins\Goals\Goals; +use Piwik\Plugins\Goals\Archiver; /** * Goals API lets you Manage existing goals, via "updateGoal" and "deleteGoal", create new Goals via "addGoal", @@ -36,14 +41,14 @@ use Piwik\Tracker\GoalManager; * * See also the documentation about <a href='http://piwik.org/docs/tracking-goals-web-analytics/' target='_blank'>Tracking Goals</a> in Piwik. * - * @package Piwik_Goals + * @package Goals */ -class Piwik_Goals_API +class API { static private $instance = null; /** - * @return Piwik_Goals_API + * @return \Piwik\Plugins\Goals\API */ static public function getInstance() { @@ -199,7 +204,7 @@ class Piwik_Goals_API Piwik::checkUserHasAdminAccess($idSite); Db::query("UPDATE " . Common::prefixTable('goal') . " SET deleted = 1 - WHERE idsite = ? + WHERE idsite = ? AND idgoal = ?", array($idSite, $idGoal)); Db::deleteAllRows(Common::prefixTable("log_conversion"), "WHERE idgoal = ?", 100000, array($idGoal)); @@ -215,11 +220,11 @@ class Piwik_Goals_API Piwik::checkUserHasViewAccess($idSite); $recordNameFinal = $recordName; if ($abandonedCarts) { - $recordNameFinal = Piwik_Goals_Archiver::getItemRecordNameAbandonedCart($recordName); + $recordNameFinal = Archiver::getItemRecordNameAbandonedCart($recordName); } $archive = Archive::build($idSite, $period, $date); $dataTable = $archive->getDataTable($recordNameFinal); - + $dataTable->filter('Sort', array(Metrics::INDEX_ECOMMERCE_ITEM_REVENUE)); $dataTable->queueFilter('ReplaceColumnNames'); $dataTable->queueFilter('ReplaceSummaryRowLabel'); @@ -238,7 +243,8 @@ class Piwik_Goals_API $dataTable->queueFilter('ColumnDelete', array('price')); // Enrich the datatable with Product/Categories views, and conversion rates - $customVariables = Piwik_CustomVariables_API::getInstance()->getCustomVariables($idSite, $period, $date, $segment = false, $expanded = false, $_leavePiwikCoreVariables = true); + $customVariables = \Piwik\Plugins\CustomVariables\API::getInstance()->getCustomVariables($idSite, $period, $date, $segment = false, $expanded = false, + $_leavePiwikCoreVariables = true); $mapping = array( 'Goals_ItemsSku' => '_pks', 'Goals_ItemsName' => '_pkn', @@ -295,16 +301,15 @@ class Piwik_Goals_API } return; } - $rowNotDefined = $dataTable->getRowFromLabel(Piwik_CustomVariables_Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED); + $rowNotDefined = $dataTable->getRowFromLabel(\Piwik\Plugins\CustomVariables\Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED); if ($rowNotDefined) { $rowNotDefined->setColumn('label', $notDefinedStringPretty); } } - protected function enrichItemsDataTableWithItemsViewMetrics($dataTable, $idSite, $period, $date, $idSubtable) { - $ecommerceViews = Piwik_CustomVariables_API::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $date, $idSubtable, $segment = false, $_leavePriceViewedColumn = true); + $ecommerceViews = \Piwik\Plugins\CustomVariables\API::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $date, $idSubtable, $segment = false, $_leavePriceViewedColumn = true); // For Product names and SKU reports, and for Category report // Use the Price (tracked on page views) @@ -385,7 +390,7 @@ class Piwik_Goals_API $idGoal = self::convertSpecialGoalIds($idGoal); if (empty($columns)) { - $columns = Piwik_Goals::getGoalColumns($idGoal); + $columns = Goals::getGoalColumns($idGoal); if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) { $columns[] = 'avg_order_revenue'; } @@ -399,7 +404,7 @@ class Piwik_Goals_API } $columnsToSelect = array(); foreach ($columns as &$columnName) { - $columnsToSelect[] = Piwik_Goals_Archiver::getRecordName($columnName, $idGoal); + $columnsToSelect[] = Archiver::getRecordName($columnName, $idGoal); } $dataTable = $archive->getDataTableFromNumeric($columnsToSelect); @@ -447,7 +452,7 @@ class Piwik_Goals_API */ public function getConversions($idSite, $period, $date, $segment = false, $idGoal = false) { - return $this->getNumeric($idSite, $period, $date, $segment, Piwik_Goals_Archiver::getRecordName('nb_conversions', $idGoal)); + return $this->getNumeric($idSite, $period, $date, $segment, Archiver::getRecordName('nb_conversions', $idGoal)); } /** @@ -455,7 +460,7 @@ class Piwik_Goals_API */ public function getNbVisitsConverted($idSite, $period, $date, $segment = false, $idGoal = false) { - return $this->getNumeric($idSite, $period, $date, $segment, Piwik_Goals_Archiver::getRecordName('nb_visits_converted', $idGoal)); + return $this->getNumeric($idSite, $period, $date, $segment, Archiver::getRecordName('nb_visits_converted', $idGoal)); } /** @@ -463,7 +468,7 @@ class Piwik_Goals_API */ public function getConversionRate($idSite, $period, $date, $segment = false, $idGoal = false) { - return $this->getNumeric($idSite, $period, $date, $segment, Piwik_Goals_Archiver::getRecordName('conversion_rate', $idGoal)); + return $this->getNumeric($idSite, $period, $date, $segment, Archiver::getRecordName('conversion_rate', $idGoal)); } /** @@ -471,7 +476,7 @@ class Piwik_Goals_API */ public function getRevenue($idSite, $period, $date, $segment = false, $idGoal = false) { - return $this->getNumeric($idSite, $period, $date, $segment, Piwik_Goals_Archiver::getRecordName('revenue', $idGoal)); + return $this->getNumeric($idSite, $period, $date, $segment, Archiver::getRecordName('revenue', $idGoal)); } /** @@ -498,7 +503,7 @@ class Piwik_Goals_API $realGoalId = $idGoal != true ? false : self::convertSpecialGoalIds($idGoal); // get the data table - $dataTable = $archive->getDataTable(Piwik_Goals_Archiver::getRecordName($recordName, $realGoalId), $idSubtable = null); + $dataTable = $archive->getDataTable(Archiver::getRecordName($recordName, $realGoalId), $idSubtable = null); $dataTable->queueFilter('ReplaceColumnNames'); return $dataTable; @@ -519,7 +524,7 @@ class Piwik_Goals_API public function getDaysToConversion($idSite, $period, $date, $segment = false, $idGoal = false) { $dataTable = $this->getGoalSpecificDataTable( - Piwik_Goals_Archiver::DAYS_UNTIL_CONV_RECORD_NAME, $idSite, $period, $date, $segment, $idGoal); + Archiver::DAYS_UNTIL_CONV_RECORD_NAME, $idSite, $period, $date, $segment, $idGoal); $dataTable->queueFilter('Sort', array('label', 'asc', true)); $dataTable->queueFilter( @@ -543,7 +548,7 @@ class Piwik_Goals_API public function getVisitsUntilConversion($idSite, $period, $date, $segment = false, $idGoal = false) { $dataTable = $this->getGoalSpecificDataTable( - Piwik_Goals_Archiver::VISITS_UNTIL_RECORD_NAME, $idSite, $period, $date, $segment, $idGoal); + Archiver::VISITS_UNTIL_RECORD_NAME, $idSite, $period, $date, $segment, $idGoal); $dataTable->queueFilter('Sort', array('label', 'asc', true)); $dataTable->queueFilter( diff --git a/plugins/Goals/Archiver.php b/plugins/Goals/Archiver.php index cad582453a..efb26854bc 100644 --- a/plugins/Goals/Archiver.php +++ b/plugins/Goals/Archiver.php @@ -6,17 +6,21 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Goals + * @package Goals */ +namespace Piwik\Plugins\Goals; + use Piwik\DataAccess\LogAggregator; use Piwik\Metrics; use Piwik\DataTable; use Piwik\DataArray; use Piwik\PluginsArchiver; +use Piwik\PluginsManager; use Piwik\Tracker\GoalManager; +use Piwik\Plugins\Goals\Goals; -class Piwik_Goals_Archiver extends PluginsArchiver +class Archiver extends PluginsArchiver { const VISITS_UNTIL_RECORD_NAME = 'visits_until_conv'; const DAYS_UNTIL_CONV_RECORD_NAME = 'days_until_conv'; @@ -120,7 +124,7 @@ class Piwik_Goals_Archiver extends PluginsArchiver unset($row['label']); $values = array(); - foreach($conversionMetrics as $field => $statement) { + foreach ($conversionMetrics as $field => $statement) { $values[$field] = $row[$field]; } $goals->sumMetrics($idGoal, $values); @@ -173,7 +177,7 @@ class Piwik_Goals_Archiver extends PluginsArchiver $recordName = self::getRecordName($metricName, $idGoal); $numericRecords[$recordName] = $value; } - if(!empty($array[Metrics::INDEX_GOAL_NB_VISITS_CONVERTED])) { + if (!empty($array[Metrics::INDEX_GOAL_NB_VISITS_CONVERTED])) { $conversion_rate = $this->getConversionRate($array[Metrics::INDEX_GOAL_NB_VISITS_CONVERTED]); $recordName = self::getRecordName('conversion_rate', $idGoal); $numericRecords[$recordName] = $conversion_rate; @@ -330,8 +334,8 @@ class Piwik_Goals_Archiver extends PluginsArchiver } $label = "Value not defined"; // Product Name/Category not defined" - if (class_exists('Piwik_CustomVariables')) { - $label = Piwik_CustomVariables_Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED; + if (PluginsManager::getInstance()->isPluginActivated('CustomVariables')) { + $label = \Piwik\Plugins\CustomVariables\Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED; } } @@ -403,7 +407,7 @@ class Piwik_Goals_Archiver extends PluginsArchiver $fieldsToSum = array(); foreach ($goalIdsToSum as $goalId) { - $metricsToSum = Piwik_Goals::getGoalColumns($goalId); + $metricsToSum = Goals::getGoalColumns($goalId); unset($metricsToSum[array_search('conversion_rate', $metricsToSum)]); foreach ($metricsToSum as $metricName) { $fieldsToSum[] = self::getRecordName($metricName, $goalId); @@ -419,13 +423,13 @@ class Piwik_Goals_Archiver extends PluginsArchiver // sum up the visits to conversion data table & the days to conversion data table $this->getProcessor()->aggregateDataTableReports(array( - self::getRecordName(self::VISITS_UNTIL_RECORD_NAME, $goalId), - self::getRecordName(self::DAYS_UNTIL_CONV_RECORD_NAME, $goalId))); + self::getRecordName(self::VISITS_UNTIL_RECORD_NAME, $goalId), + self::getRecordName(self::DAYS_UNTIL_CONV_RECORD_NAME, $goalId))); } // sum up goal overview reports $this->getProcessor()->aggregateDataTableReports(array( - self::getRecordName(self::VISITS_UNTIL_RECORD_NAME), - self::getRecordName(self::DAYS_UNTIL_CONV_RECORD_NAME))); + self::getRecordName(self::VISITS_UNTIL_RECORD_NAME), + self::getRecordName(self::DAYS_UNTIL_CONV_RECORD_NAME))); } }
\ No newline at end of file diff --git a/plugins/Goals/Controller.php b/plugins/Goals/Controller.php index 0bca7f1403..7cb2353a0b 100644 --- a/plugins/Goals/Controller.php +++ b/plugins/Goals/Controller.php @@ -6,24 +6,28 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Goals + * @package Goals */ +namespace Piwik\Plugins\Goals; + +use Exception; use Piwik\API\Request; use Piwik\DataTable\Filter\AddColumnsProcessedMetricsGoal; use Piwik\Piwik; use Piwik\Common; use Piwik\DataTable; -use Piwik\Controller; use Piwik\FrontController; use Piwik\View\ReportsByDimension; use Piwik\ViewDataTable; use Piwik\View; +use Piwik\Plugins\Goals\Goals; +use Piwik\Plugins\Referers\API as ReferersAPI; /** * - * @package Piwik_Goals + * @package Goals */ -class Piwik_Goals_Controller extends Controller +class Controller extends \Piwik\Controller { const CONVERSION_RATE_PRECISION = 1; @@ -58,7 +62,7 @@ class Piwik_Goals_Controller extends Controller { parent::__construct(); $this->idSite = Common::getRequestVar('idSite', null, 'int'); - $this->goals = Piwik_Goals_API::getInstance()->getGoals($this->idSite); + $this->goals = API::getInstance()->getGoals($this->idSite); foreach ($this->goals as &$goal) { $goal['name'] = Common::sanitizeInputValue($goal['name']); if (isset($goal['pattern'])) { @@ -137,10 +141,10 @@ class Piwik_Goals_Controller extends Controller // conversion rate for new and returning visitors $segment = 'visitorType==returning,visitorType==returningCustomer'; - $conversionRateReturning = Piwik_Goals_API::getInstance()->getConversionRate($this->idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), $segment, $idGoal); + $conversionRateReturning = API::getInstance()->getConversionRate($this->idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), $segment, $idGoal); $view->conversion_rate_returning = $this->formatConversionRate($conversionRateReturning); $segment = 'visitorType==new'; - $conversionRateNew = Piwik_Goals_API::getInstance()->getConversionRate($this->idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), $segment, $idGoal); + $conversionRateNew = API::getInstance()->getConversionRate($this->idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), $segment, $idGoal); $view->conversion_rate_new = $this->formatConversionRate($conversionRateNew); $view->goalReportsByDimension = $this->getGoalReportsByDimensionTable( $view->nb_conversions, isset($ecommerce), !empty($view->cart_nb_conversions)); @@ -150,7 +154,7 @@ class Piwik_Goals_Controller extends Controller public function index() { $view = $this->getOverviewView(); - + // unsanitize goal names and other text data (not done in API so as not to break // any other code/cause security issues) $goals = $this->goals; @@ -161,7 +165,7 @@ class Piwik_Goals_Controller extends Controller } } $view->goalsJSON = Common::json_encode($goals); - + $view->userCanEditGoals = Piwik::isUserHasAdminAccess($this->idSite); $view->ecommerceEnabled = $this->site->isEcommerceEnabled(); $view->displayFullReport = true; @@ -294,7 +298,6 @@ class Piwik_Goals_Controller extends Controller return $this->renderView($view, $fetch); } - protected function getTopDimensions($idGoal) { $columnNbConversions = 'goal_' . $idGoal . '_nb_conversions'; @@ -310,7 +313,7 @@ class Piwik_Goals_Controller extends Controller $keywordNotDefinedString = ''; if (\Piwik\PluginsManager::getInstance()->isPluginActivated('Referers')) { - $keywordNotDefinedString = Piwik_Referers_API::getKeywordNotDefinedString(); + $keywordNotDefinedString = ReferersAPI::getKeywordNotDefinedString(); $topDimensionsToLoad += array( 'keyword' => 'Referers.getKeywords', 'website' => 'Referers.getWebsites', @@ -436,12 +439,12 @@ class Piwik_Goals_Controller extends Controller $customParams['idGoal'] = '0'; // NOTE: Must be string! Otherwise Piwik_View_HtmlTable_Goals fails. } - $allReports = Piwik_Goals::getReportsWithGoalMetrics(); + $allReports = Goals::getReportsWithGoalMetrics(); foreach ($allReports as $category => $reports) { $categoryText = Piwik_Translate('Goals_ViewGoalsBy', $category); foreach ($reports as $report) { $customParams['viewDataTable'] = 'tableGoals'; - if(in_array($report['action'], array('getVisitsUntilConversion', 'getDaysToConversion'))) { + if (in_array($report['action'], array('getVisitsUntilConversion', 'getDaysToConversion'))) { $customParams['viewDataTable'] = 'table'; } @@ -453,16 +456,16 @@ class Piwik_Goals_Controller extends Controller return $goalReportsByDimension->render(); } - - // + + // // Report rendering actions - // + // public function getItemsSku($fetch = false) { return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - + public function getItemsName($fetch = false) { return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php index 010f1a6623..f15569affb 100644 --- a/plugins/Goals/Goals.php +++ b/plugins/Goals/Goals.php @@ -6,23 +6,26 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Goals + * @package Goals */ +namespace Piwik\Plugins\Goals; + use Piwik\ArchiveProcessor; use Piwik\Piwik; use Piwik\Common; +use Piwik\Plugins\Goals\API; +use Piwik\Plugins\Goals\Archiver; use Piwik\Tracker\GoalManager; use Piwik\TranslationWriter; -use Piwik\Plugin; use Piwik\Site; use Piwik\WidgetsList; use Piwik\Db; /** * - * @package Piwik_Goals + * @package Goals */ -class Piwik_Goals extends Plugin +class Goals extends \Piwik\Plugin { protected $ecommerceReports = array( array('Goals_ProductSKU', 'Goals', 'getItemsSku'), @@ -153,7 +156,7 @@ class Piwik_Goals extends Plugin // If only one website is selected, we add the Goal metrics if (count($idSites) == 1) { $idSite = reset($idSites); - $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); + $goals = API::getInstance()->getGoals($idSite); // Add overall visits to conversion report $reports[] = array( @@ -350,7 +353,6 @@ class Piwik_Goals extends Plugin } } } - } static public function getProductReportColumns() @@ -412,7 +414,7 @@ class Piwik_Goals extends Plugin public function fetchGoalsFromDb(&$array, $idSite) { // add the 'goal' entry in the website array - $array['goals'] = Piwik_Goals_API::getInstance()->getGoals($idSite); + $array['goals'] = API::getInstance()->getGoals($idSite); } public function addWidgets() @@ -431,7 +433,7 @@ class Piwik_Goals extends Plugin // Goals widgets WidgetsList::add('Goals_Goals', 'Goals_GoalsOverview', 'Goals', 'widgetGoalsOverview'); - $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); + $goals = API::getInstance()->getGoals($idSite); if (count($goals) > 0) { foreach ($goals as $goal) { WidgetsList::add('Goals_Goals', Common::sanitizeInputValue($goal['name']), 'Goals', 'widgetGoalReport', array('idGoal' => $goal['idgoal'])); @@ -442,7 +444,7 @@ class Piwik_Goals extends Plugin function addMenus() { $idSite = Common::getRequestVar('idSite', null, 'int'); - $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); + $goals = API::getInstance()->getGoals($idSite); $mainGoalMenu = $this->getGoalCategoryName($idSite); $site = new Site($idSite); if (count($goals) == 0) { @@ -487,8 +489,8 @@ class Piwik_Goals extends Plugin */ public function archiveDay(ArchiveProcessor\Day $archiveProcessor) { - $archiving = new Piwik_Goals_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archiveDay(); } } @@ -499,12 +501,12 @@ class Piwik_Goals extends Plugin */ public function archivePeriod(ArchiveProcessor\Period $archiveProcessor) { - $archiving = new Piwik_Goals_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archivePeriod(); } } - + public function getReportDisplayProperties(&$properties) { $properties['Goals.getItemsSku'] = $this->getDisplayPropertiesForGetItemsSku(); @@ -513,86 +515,86 @@ class Piwik_Goals extends Plugin $properties['Goals.getVisitsUntilConversion'] = $this->getDisplayPropertiesForGetVisitsUntilConversion(); $properties['Goals.getDaysToConversion'] = $this->getDisplayPropertiesForGetDaysToConversion(); } - + private function getDisplayPropertiesForGetItemsSku() { return $this->getDisplayPropertiesForItemsReport(Piwik_Translate('Goals_ProductSKU')); } - + private function getDisplayPropertiesForGetItemsName() { return $this->getDisplayPropertiesForItemsReport(Piwik_Translate('Goals_ProductName')); } - + private function getDisplayPropertiesForGetItemsCategory() { return $this->getDisplayPropertiesForItemsReport(Piwik_Translate('Goals_ProductCategory')); } - + private function getDisplayPropertiesForGetVisitsUntilConversion() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, - 'show_table_all_columns' => false, - 'columns_to_display' => array('label', 'nb_conversions'), - 'filter_sort_column' => 'label', - 'filter_sort_order' => 'asc', - 'translations' => array( - 'label' => Piwik_Translate('Goals_VisitsUntilConv'), + 'show_table_all_columns' => false, + 'columns_to_display' => array('label', 'nb_conversions'), + 'filter_sort_column' => 'label', + 'filter_sort_order' => 'asc', + 'translations' => array( + 'label' => Piwik_Translate('Goals_VisitsUntilConv'), 'nb_conversions' => Piwik_Translate('Goals_ColumnConversions'), ), - 'filter_limit' => count(Piwik_Goals_Archiver::$visitCountRanges), - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_all_views_icons' => false + 'filter_limit' => count(Archiver::$visitCountRanges), + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'show_all_views_icons' => false ); } - + private function getDisplayPropertiesForGetDaysToConversion() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, - 'show_table_all_columns' => false, - 'columns_to_display' => array('label', 'nb_conversions'), - 'filter_sort_column' => 'label', - 'filter_sort_order' => 'asc', - 'translations' => array( - 'label' => Piwik_Translate('Goals_DaysToConv'), + 'show_table_all_columns' => false, + 'columns_to_display' => array('label', 'nb_conversions'), + 'filter_sort_column' => 'label', + 'filter_sort_order' => 'asc', + 'translations' => array( + 'label' => Piwik_Translate('Goals_DaysToConv'), 'nb_conversions' => Piwik_Translate('Goals_ColumnConversions'), ), - 'filter_limit' => count(Piwik_Goals_Archiver::$daysToConvRanges), - 'show_all_views_icons' => false, - 'show_offset_information' => false, - 'show_pagination_control' => false, + 'filter_limit' => count(Archiver::$daysToConvRanges), + 'show_all_views_icons' => false, + 'show_offset_information' => false, + 'show_pagination_control' => false, ); } - + private function getDisplayPropertiesForItemsReport($label) { $idSite = Common::getRequestVar('idSite'); - + $moneyColumns = array('revenue', 'avg_price'); $prettifyMoneyColumns = array( 'ColumnCallbackReplace', array($moneyColumns, '\Piwik\Piwik::getPrettyMoney', array($idSite))); - + $result = array( - 'show_ecommerce' => true, - 'show_all_views_icons' => false, - 'show_table' => false, + 'show_ecommerce' => true, + 'show_all_views_icons' => false, + 'show_table' => false, 'show_exclude_low_population' => false, - 'show_table_all_columns' => false, - 'filter_limit' => 10, - 'translations' => array('label' => $label), - 'filter_sort_column' => 'revenue', - 'filter_sort_order' => 'desc', - 'filters' => array($prettifyMoneyColumns) + 'show_table_all_columns' => false, + 'filter_limit' => 10, + 'translations' => array('label' => $label), + 'filter_sort_column' => 'revenue', + 'filter_sort_order' => 'desc', + 'filters' => array($prettifyMoneyColumns) ); - + // set columns/translations which differ based on viewDataTable TODO: shouldn't have to do this check... amount of reports should be dynamic, but metadata should be static - $columns = Piwik_Goals::getProductReportColumns(); - + $columns = Goals::getProductReportColumns(); + $abandonedCart = Common::getRequestVar('viewDataTable', 'ecommerceOrder', 'string') == 'ecommerceAbandonedCart'; if ($abandonedCart) { $columns['abandoned_carts'] = Piwik_Translate('General_AbandonedCarts'); @@ -601,13 +603,13 @@ class Piwik_Goals extends Plugin $columns['avg_quantity'] = Piwik_Translate('Goals_LeftInCart', Piwik_Translate('General_AverageQuantity')); unset($columns['orders']); unset($columns['conversion_rate']); - + $result['request_parameters_to_modify'] = array('abandonedCarts' => '1'); } - + $result['translations'] = array_merge(array('label' => $label), $columns); $result['columns_to_display'] = array_keys($result['translations']); - + // set metrics documentation in normal ecommerce report if (!$abandonedCart) { $result['metrics_documentation'] = array( @@ -621,10 +623,10 @@ class Piwik_Goals extends Plugin 'conversion_rate' => Piwik_Translate('Goals_ColumnConversionRateProductDocumentation', $label), ); } - + $result['custom_parameters']['viewDataTable'] = $abandonedCart ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART : Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER; - + return $result; } } diff --git a/plugins/ImageGraph/API.php b/plugins/ImageGraph/API.php index 942a4042bd..64e4fb311f 100644 --- a/plugins/ImageGraph/API.php +++ b/plugins/ImageGraph/API.php @@ -6,12 +6,16 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ImageGraph + * @package ImageGraph */ +namespace Piwik\Plugins\ImageGraph; + use Piwik\Period; use Piwik\Piwik; use Piwik\Common; use Piwik\Translate; +use Piwik\Plugins\API\API as MetaAPI; +use Piwik\Plugins\ImageGraph\StaticGraph; /** * The ImageGraph.get API call lets you generate beautiful static PNG Graphs for any existing Piwik report. @@ -24,9 +28,9 @@ use Piwik\Translate; * * See also <a href='http://piwik.org/docs/analytics-api/metadata/#toc-static-image-graphs'>How to embed static Image Graphs?</a> for more information. * - * @package Piwik_ImageGraph + * @package ImageGraph */ -class Piwik_ImageGraph_API +class API { const FILENAME_KEY = 'filename'; const TRUNCATE_KEY = 'truncate'; @@ -36,31 +40,31 @@ class Piwik_ImageGraph_API const MAX_HEIGHT = 2048; static private $DEFAULT_PARAMETERS = array( - Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_BASIC_LINE => array( + StaticGraph::GRAPH_TYPE_BASIC_LINE => array( self::FILENAME_KEY => 'BasicLine', self::TRUNCATE_KEY => 6, self::WIDTH_KEY => 1044, self::HEIGHT_KEY => 290, ), - Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_VERTICAL_BAR => array( + StaticGraph::GRAPH_TYPE_VERTICAL_BAR => array( self::FILENAME_KEY => 'BasicBar', self::TRUNCATE_KEY => 6, self::WIDTH_KEY => 1044, self::HEIGHT_KEY => 290, ), - Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_HORIZONTAL_BAR => array( + StaticGraph::GRAPH_TYPE_HORIZONTAL_BAR => array( self::FILENAME_KEY => 'HorizontalBar', self::TRUNCATE_KEY => null, // horizontal bar graphs are dynamically truncated self::WIDTH_KEY => 800, self::HEIGHT_KEY => 290, ), - Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_3D_PIE => array( + StaticGraph::GRAPH_TYPE_3D_PIE => array( self::FILENAME_KEY => '3DPie', self::TRUNCATE_KEY => 5, self::WIDTH_KEY => 1044, self::HEIGHT_KEY => 290, ), - Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_BASIC_PIE => array( + StaticGraph::GRAPH_TYPE_BASIC_PIE => array( self::FILENAME_KEY => 'BasicPie', self::TRUNCATE_KEY => 5, self::WIDTH_KEY => 1044, @@ -71,11 +75,11 @@ class Piwik_ImageGraph_API static private $DEFAULT_GRAPH_TYPE_OVERRIDE = array( 'UserSettings_getPlugin' => array( false // override if !$isMultiplePeriod - => Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_HORIZONTAL_BAR, + => StaticGraph::GRAPH_TYPE_HORIZONTAL_BAR, ), 'Referers_getRefererType' => array( false // override if !$isMultiplePeriod - => Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_HORIZONTAL_BAR, + => StaticGraph::GRAPH_TYPE_HORIZONTAL_BAR, ), ); @@ -100,7 +104,7 @@ class Piwik_ImageGraph_API static private $instance = null; /** - * @return Piwik_ImageGraph_API + * @return \Piwik\Plugins\ImageGraph\API */ static public function getInstance() { @@ -118,29 +122,31 @@ class Piwik_ImageGraph_API $apiModule, $apiAction, $graphType = false, - $outputType = Piwik_ImageGraph_API::GRAPH_OUTPUT_INLINE, + $outputType = API::GRAPH_OUTPUT_INLINE, $columns = false, $labels = false, $showLegend = true, $width = false, $height = false, - $fontSize = Piwik_ImageGraph_API::DEFAULT_FONT_SIZE, + $fontSize = API::DEFAULT_FONT_SIZE, $legendFontSize = false, $aliasedGraph = true, $idGoal = false, $colors = false, - $textColor = Piwik_ImageGraph_API::DEFAULT_TEXT_COLOR, - $backgroundColor = Piwik_ImageGraph_API::DEFAULT_BACKGROUND_COLOR, - $gridColor = Piwik_ImageGraph_API::DEFAULT_GRID_COLOR, + $textColor = API::DEFAULT_TEXT_COLOR, + $backgroundColor = API::DEFAULT_BACKGROUND_COLOR, + $gridColor = API::DEFAULT_GRID_COLOR, $idSubtable = false, $legendAppendMetric = true, $segment = false - ) { + ) + { Piwik::checkUserHasViewAccess($idSite); // Health check - should we also test for GD2 only? if (!Piwik::isGdExtensionEnabled()) { - throw new Exception('Error: To create graphs in Piwik, please enable GD php extension (with Freetype support) in php.ini, and restart your web server.'); + throw new \Exception('Error: To create graphs in Piwik, please enable GD php extension (with Freetype support) in php.ini, + and restart your web server.'); } $useUnicodeFont = array( @@ -162,7 +168,7 @@ class Piwik_ImageGraph_API $apiParameters = array('idGoal' => $idGoal); } // Fetch the metadata for given api-action - $metadata = Piwik_API_API::getInstance()->getMetadata( + $metadata = MetaAPI::getInstance()->getMetadata( $idSite, $apiModule, $apiAction, $apiParameters, $languageLoaded, $period, $date, $hideMetricsDoc = false, $showSubtableReports = true); if (!$metadata) { @@ -184,12 +190,12 @@ class Piwik_ImageGraph_API if (empty($graphType)) { if ($isMultiplePeriod) { - $graphType = Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_BASIC_LINE; + $graphType = StaticGraph::GRAPH_TYPE_BASIC_LINE; } else { if ($constantRowsCount) { - $graphType = Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_VERTICAL_BAR; + $graphType = StaticGraph::GRAPH_TYPE_VERTICAL_BAR; } else { - $graphType = Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_HORIZONTAL_BAR; + $graphType = StaticGraph::GRAPH_TYPE_HORIZONTAL_BAR; } } @@ -198,7 +204,7 @@ class Piwik_ImageGraph_API $graphType = self::$DEFAULT_GRAPH_TYPE_OVERRIDE[$reportUniqueId][$isMultiplePeriod]; } } else { - $availableGraphTypes = Piwik_ImageGraph_StaticGraph::getAvailableStaticGraphTypes(); + $availableGraphTypes = StaticGraph::getAvailableStaticGraphTypes(); if (!in_array($graphType, $availableGraphTypes)) { throw new Exception( Piwik_TranslateException( @@ -255,8 +261,8 @@ class Piwik_ImageGraph_API // sort and truncate filters $defaultFilterTruncate = self::$DEFAULT_PARAMETERS[$graphType][self::TRUNCATE_KEY]; switch ($graphType) { - case Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_3D_PIE: - case Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_BASIC_PIE: + case StaticGraph::GRAPH_TYPE_3D_PIE: + case StaticGraph::GRAPH_TYPE_BASIC_PIE: if (count($ordinateColumns) > 1) { // pChart doesn't support multiple series on pie charts @@ -267,8 +273,8 @@ class Piwik_ImageGraph_API $this->setFilterTruncate($defaultFilterTruncate); break; - case Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_VERTICAL_BAR: - case Piwik_ImageGraph_StaticGraph::GRAPH_TYPE_BASIC_LINE: + case StaticGraph::GRAPH_TYPE_VERTICAL_BAR: + case StaticGraph::GRAPH_TYPE_BASIC_LINE: if (!$isMultiplePeriod && !$constantRowsCount) { $this->setFilterTruncate($defaultFilterTruncate); @@ -294,7 +300,7 @@ class Piwik_ImageGraph_API } } - $processedReport = Piwik_API_API::getInstance()->getRowEvolution( + $processedReport = MetaAPI::getInstance()->getRowEvolution( $idSite, $period, $date, @@ -311,7 +317,7 @@ class Piwik_ImageGraph_API //@review this test will need to be updated after evaluating the @review comment in API/API.php if (!$processedReport) { - throw new Exception(Piwik_Translate('General_NoDataForGraph_js')); + throw new \Exception(Piwik_Translate('General_NoDataForGraph_js')); } // restoring generic filter parameters @@ -351,7 +357,7 @@ class Piwik_ImageGraph_API $ordinateLabels[$plottedMetric] = $processedReport['label'] . ' (' . $metrics[$plottedMetric]['name'] . ')'; } } else { - $processedReport = Piwik_API_API::getInstance()->getProcessedReport( + $processedReport = MetaAPI::getInstance()->getProcessedReport( $idSite, $period, $date, @@ -437,7 +443,6 @@ class Piwik_ImageGraph_API $ordinateSeries[$column][] = $parsedOrdinateValue; } - } else { foreach ($ordinateColumns as $column) { $ordinateSeries[$column][] = 0; @@ -450,11 +455,11 @@ class Piwik_ImageGraph_API } if (!$hasData || !$hasNonZeroValue) { - throw new Exception(Piwik_Translate('General_NoDataForGraph_js')); + throw new \Exception(Piwik_Translate('General_NoDataForGraph_js')); } //Setup the graph - $graph = Piwik_ImageGraph_StaticGraph::factory($graphType); + $graph = StaticGraph::factory($graphType); $graph->setWidth($width); $graph->setHeight($height); $graph->setFont($font); @@ -480,10 +485,9 @@ class Piwik_ImageGraph_API // render graph $graph->renderGraph(); + } catch (\Exception $e) { - } catch (Exception $e) { - - $graph = new Piwik_ImageGraph_StaticGraph_Exception(); + $graph = new \Piwik\Plugins\ImageGraph\StaticGraph\Exception(); $graph->setWidth($width); $graph->setHeight($height); $graph->setFont($font); diff --git a/plugins/ImageGraph/Controller.php b/plugins/ImageGraph/Controller.php index a36d520b8e..19925fdc41 100644 --- a/plugins/ImageGraph/Controller.php +++ b/plugins/ImageGraph/Controller.php @@ -1,9 +1,4 @@ <?php -use Piwik\Piwik; -use Piwik\Common; -use Piwik\Controller; -use Piwik\View; - /** * Piwik - Open source web analytics * @@ -11,10 +6,16 @@ use Piwik\View; * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ImageGraph + * @package ImageGraph */ +namespace Piwik\Plugins\ImageGraph; -class Piwik_ImageGraph_Controller extends Controller +use Piwik\Piwik; +use Piwik\Common; +use Piwik\View; +use Piwik\Plugins\API\API; + +class Controller extends \Piwik\Controller { // Call metadata reports, and draw the default graph for each report. public function index() @@ -24,7 +25,7 @@ class Piwik_ImageGraph_Controller extends Controller $period = Common::getRequestVar('period', 'day', 'string'); $date = Common::getRequestVar('date', 'today', 'string'); $_GET['token_auth'] = Piwik::getCurrentUserTokenAuth(); - $reports = Piwik_API_API::getInstance()->getReportMetadata($idSite, $period, $date); + $reports = API::getInstance()->getReportMetadata($idSite, $period, $date); $plot = array(); foreach ($reports as $report) { if (!empty($report['imageGraphUrl'])) { @@ -53,7 +54,7 @@ class Piwik_ImageGraph_Controller extends Controller $date = Common::getRequestVar('date', 'today', 'string'); $_GET['token_auth'] = Piwik::getCurrentUserTokenAuth(); - $availableReports = Piwik_API_API::getInstance()->getReportMetadata($this->idSite, $period, $date); + $availableReports = API::getInstance()->getReportMetadata($this->idSite, $period, $date); $view->availableReports = $availableReports; $view->graphTypes = array( '', // default graph type @@ -73,5 +74,4 @@ class Piwik_ImageGraph_Controller extends Controller ); echo $view->render(); } - } diff --git a/plugins/ImageGraph/ImageGraph.php b/plugins/ImageGraph/ImageGraph.php index 6181877fb7..fc992a3425 100644 --- a/plugins/ImageGraph/ImageGraph.php +++ b/plugins/ImageGraph/ImageGraph.php @@ -1,12 +1,4 @@ <?php -use Piwik\Common; -use Piwik\Period; -use Piwik\Controller; -use Piwik\Url; -use Piwik\Plugin; -use Piwik\Site; -use Piwik\Config; - /** * Piwik - Open source web analytics * @@ -14,10 +6,17 @@ use Piwik\Config; * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ImageGraph + * @package ImageGraph */ +namespace Piwik\Plugins\ImageGraph; + +use Piwik\Common; +use Piwik\Period; +use Piwik\Url; +use Piwik\Site; +use Piwik\Config; -class Piwik_ImageGraph extends Plugin +class ImageGraph extends \Piwik\Plugin { static private $CONSTANT_ROW_COUNT_REPORT_EXCEPTIONS = array( 'Referers_getRefererType', @@ -92,7 +91,7 @@ class Piwik_ImageGraph extends Plugin $dateForMultiplePeriodGraph = $dateForSinglePeriodGraph; } else { $periodForMultiplePeriodGraph = $periodForSinglePeriodGraph; - $dateForMultiplePeriodGraph = Controller::getDateRangeRelativeToEndDate( + $dateForMultiplePeriodGraph = \Piwik\Controller::getDateRangeRelativeToEndDate( $periodForSinglePeriodGraph, 'last' . self::GRAPH_EVOLUTION_LAST_PERIODS, $dateForSinglePeriodGraph, @@ -146,8 +145,9 @@ class Piwik_ImageGraph extends Plugin $reportSupportsEvolution = !in_array($reportUniqueId, self::$REPORTS_DISABLED_EVOLUTION_GRAPH); - if ( $reportSupportsEvolution - && $reportWithDimensionsSupportsEvolution) { + if ($reportSupportsEvolution + && $reportWithDimensionsSupportsEvolution + ) { $parameters['period'] = $periodForMultiplePeriodGraph; $parameters['date'] = $dateForMultiplePeriodGraph; $report['imageGraphEvolutionUrl'] = $urlPrefix . Url::getQueryStringFromParameters($parameters); diff --git a/plugins/ImageGraph/StaticGraph.php b/plugins/ImageGraph/StaticGraph.php index a3eeee9341..cd4786f090 100644 --- a/plugins/ImageGraph/StaticGraph.php +++ b/plugins/ImageGraph/StaticGraph.php @@ -6,22 +6,28 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ImageGraph + * @package ImageGraph */ +namespace Piwik\Plugins\ImageGraph; + +use Exception; use Piwik\Loader; +use Piwik\Plugins\ImageGraph\API; +use pData; +use pImage; require_once PIWIK_INCLUDE_PATH . "/libs/pChart2.1.3/class/pDraw.class.php"; require_once PIWIK_INCLUDE_PATH . "/libs/pChart2.1.3/class/pImage.class.php"; require_once PIWIK_INCLUDE_PATH . "/libs/pChart2.1.3/class/pData.class.php"; /** - * The Piwik_ImageGraph_StaticGraph abstract class is used as a base class for different types of static graphs. + * The StaticGraph abstract class is used as a base class for different types of static graphs. * - * @package Piwik_ImageGraph - * @subpackage Piwik_ImageGraph_StaticGraph + * @package ImageGraph + * @subpackage StaticGraph */ -abstract class Piwik_ImageGraph_StaticGraph +abstract class StaticGraph { const GRAPH_TYPE_BASIC_LINE = "evolution"; const GRAPH_TYPE_VERTICAL_BAR = "verticalBar"; @@ -30,11 +36,11 @@ abstract class Piwik_ImageGraph_StaticGraph const GRAPH_TYPE_BASIC_PIE = "pie"; static private $availableStaticGraphTypes = array( - self::GRAPH_TYPE_BASIC_LINE => 'Piwik_ImageGraph_StaticGraph_Evolution', - self::GRAPH_TYPE_VERTICAL_BAR => 'Piwik_ImageGraph_StaticGraph_VerticalBar', - self::GRAPH_TYPE_HORIZONTAL_BAR => 'Piwik_ImageGraph_StaticGraph_HorizontalBar', - self::GRAPH_TYPE_BASIC_PIE => 'Piwik_ImageGraph_StaticGraph_Pie', - self::GRAPH_TYPE_3D_PIE => 'Piwik_ImageGraph_StaticGraph_3DPie', + self::GRAPH_TYPE_BASIC_LINE => 'Evolution', + self::GRAPH_TYPE_VERTICAL_BAR => 'VerticalBar', + self::GRAPH_TYPE_HORIZONTAL_BAR => 'HorizontalBar', + self::GRAPH_TYPE_BASIC_PIE => 'Pie', + self::GRAPH_TYPE_3D_PIE => 'Pie3D', ); const ABSCISSA_SERIE_NAME = 'ABSCISSA'; @@ -73,15 +79,16 @@ abstract class Piwik_ImageGraph_StaticGraph /** * Return the StaticGraph according to the static graph type $graphType * - * @throws exception If the static graph type is unknown + * @throws Exception If the static graph type is unknown * @param string $graphType - * @return Piwik_ImageGraph_StaticGraph + * @return \Piwik\Plugins\ImageGraph\StaticGraph */ public static function factory($graphType) { if (isset(self::$availableStaticGraphTypes[$graphType])) { $className = self::$availableStaticGraphTypes[$graphType]; + $className = __NAMESPACE__ . "\\StaticGraph\\" . $className; Loader::loadClass($className); return new $className; } else { @@ -141,7 +148,7 @@ abstract class Piwik_ImageGraph_StaticGraph public function setFontSize($fontSize) { if (!is_numeric($fontSize)) { - $fontSize = Piwik_ImageGraph_API::DEFAULT_FONT_SIZE; + $fontSize = API::DEFAULT_FONT_SIZE; } $this->fontSize = $fontSize; } @@ -266,8 +273,8 @@ abstract class Piwik_ImageGraph_StaticGraph $this->pImage->setFontProperties( array_merge( array( - 'FontName' => $this->font, - 'FontSize' => $this->fontSize, + 'FontName' => $this->font, + 'FontSize' => $this->fontSize, ), $this->textColor ) diff --git a/plugins/ImageGraph/StaticGraph/3DPie.php b/plugins/ImageGraph/StaticGraph/3DPie.php index 62252c0059..4a7ab3ef06 100644 --- a/plugins/ImageGraph/StaticGraph/3DPie.php +++ b/plugins/ImageGraph/StaticGraph/3DPie.php @@ -6,14 +6,16 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ +namespace Piwik\Plugins\ImageGraph\StaticGraph; + /** * - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ -class Piwik_ImageGraph_StaticGraph_3DPie extends Piwik_ImageGraph_StaticGraph_PieGraph +class Pie3D extends PieGraph { public function renderGraph() { diff --git a/plugins/ImageGraph/StaticGraph/Evolution.php b/plugins/ImageGraph/StaticGraph/Evolution.php index a4851afaa4..3bc870b9b6 100644 --- a/plugins/ImageGraph/StaticGraph/Evolution.php +++ b/plugins/ImageGraph/StaticGraph/Evolution.php @@ -6,15 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ +namespace Piwik\Plugins\ImageGraph\StaticGraph; +use Piwik\Plugins\ImageGraph\StaticGraph\GridGraph; /** * - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ -class Piwik_ImageGraph_StaticGraph_Evolution extends Piwik_ImageGraph_StaticGraph_GridGraph +class Evolution extends GridGraph { public function renderGraph() diff --git a/plugins/ImageGraph/StaticGraph/Exception.php b/plugins/ImageGraph/StaticGraph/Exception.php index 5140c73eb6..0772e603cf 100644 --- a/plugins/ImageGraph/StaticGraph/Exception.php +++ b/plugins/ImageGraph/StaticGraph/Exception.php @@ -6,15 +6,18 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ +namespace Piwik\Plugins\ImageGraph\StaticGraph; +use Piwik\Plugins\ImageGraph\StaticGraph; +use pData; /** * - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ -class Piwik_ImageGraph_StaticGraph_Exception extends Piwik_ImageGraph_StaticGraph +class Exception extends StaticGraph { const MESSAGE_RIGHT_MARGIN = 5; @@ -30,7 +33,6 @@ class Piwik_ImageGraph_StaticGraph_Exception extends Piwik_ImageGraph_StaticGrap return array(); } - public function setWidth($width) { if (empty($width)) { diff --git a/plugins/ImageGraph/StaticGraph/GridGraph.php b/plugins/ImageGraph/StaticGraph/GridGraph.php index 3efd36bc1a..026c2952bc 100644 --- a/plugins/ImageGraph/StaticGraph/GridGraph.php +++ b/plugins/ImageGraph/StaticGraph/GridGraph.php @@ -6,15 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ +namespace Piwik\Plugins\ImageGraph\StaticGraph; +use Piwik\Plugins\ImageGraph\StaticGraph; /** * - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ -abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_StaticGraph +abstract class GridGraph extends StaticGraph { const GRAPHIC_COLOR_KEY = 'GRAPHIC_COLOR'; @@ -413,7 +415,6 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S } return $label; } - // display min & max values // can not currently be used because pChart's label design is not flexible enough // e.g: it is not possible to remove the box border & the square icon diff --git a/plugins/ImageGraph/StaticGraph/HorizontalBar.php b/plugins/ImageGraph/StaticGraph/HorizontalBar.php index fe4cf5b3b4..64ebf2d4e5 100644 --- a/plugins/ImageGraph/StaticGraph/HorizontalBar.php +++ b/plugins/ImageGraph/StaticGraph/HorizontalBar.php @@ -6,15 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ +namespace Piwik\Plugins\ImageGraph\StaticGraph; +use Piwik\Plugins\ImageGraph\StaticGraph\GridGraph; /** * - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ -class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_StaticGraph_GridGraph +class HorizontalBar extends GridGraph { const INTERLEAVE = 0.30; const PADDING_CHARS = ' '; @@ -173,7 +175,7 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static - $logoHeight / 2 + 1; - if(method_exists($this->pImage, $drawingFunction)) { + if (method_exists($this->pImage, $drawingFunction)) { $this->pImage->$drawingFunction( $gridLeftMarginBeforePadding, $logoYPosition, diff --git a/plugins/ImageGraph/StaticGraph/Pie.php b/plugins/ImageGraph/StaticGraph/Pie.php index bdfbdef9ab..1626ebd3fc 100644 --- a/plugins/ImageGraph/StaticGraph/Pie.php +++ b/plugins/ImageGraph/StaticGraph/Pie.php @@ -6,14 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ +namespace Piwik\Plugins\ImageGraph\StaticGraph; + +use Piwik\Plugins\ImageGraph\StaticGraph\PieGraph; /** * - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ -class Piwik_ImageGraph_StaticGraph_Pie extends Piwik_ImageGraph_StaticGraph_PieGraph +class Pie extends PieGraph { public function renderGraph() { diff --git a/plugins/ImageGraph/StaticGraph/PieGraph.php b/plugins/ImageGraph/StaticGraph/PieGraph.php index 3f00008f90..86c9852372 100644 --- a/plugins/ImageGraph/StaticGraph/PieGraph.php +++ b/plugins/ImageGraph/StaticGraph/PieGraph.php @@ -6,16 +6,21 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ +namespace Piwik\Plugins\ImageGraph\StaticGraph; + +use Piwik\Plugins\ImageGraph\StaticGraph; +use pPie; + require_once PIWIK_INCLUDE_PATH . "/libs/pChart2.1.3/class/pPie.class.php"; /** * - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ -abstract class Piwik_ImageGraph_StaticGraph_PieGraph extends Piwik_ImageGraph_StaticGraph +abstract class PieGraph extends StaticGraph { const RADIUS_MARGIN = 40; const PIE_RIGHT_MARGIN = 20; diff --git a/plugins/ImageGraph/StaticGraph/VerticalBar.php b/plugins/ImageGraph/StaticGraph/VerticalBar.php index 5bf40df7f8..add00e6423 100644 --- a/plugins/ImageGraph/StaticGraph/VerticalBar.php +++ b/plugins/ImageGraph/StaticGraph/VerticalBar.php @@ -6,15 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ +namespace Piwik\Plugins\ImageGraph\StaticGraph; +use Piwik\Plugins\ImageGraph\StaticGraph\GridGraph; /** * - * @package Piwik_ImageGraph_StaticGraph + * @package StaticGraph */ -class Piwik_ImageGraph_StaticGraph_VerticalBar extends Piwik_ImageGraph_StaticGraph_GridGraph +class VerticalBar extends GridGraph { const INTERLEAVE = 0.10; diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php index edf7805509..23333872be 100644 --- a/plugins/Installation/Controller.php +++ b/plugins/Installation/Controller.php @@ -6,10 +6,12 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Installation + * @package Installation */ +namespace Piwik\Plugins\Installation; + +use Exception; use Piwik\API\Request; -use Piwik\Controller\Admin; use Piwik\DataAccess\ArchiveTableCreator; use Piwik\Db\Adapter; use Piwik\Piwik; @@ -24,32 +26,39 @@ use Piwik\Version; use Piwik\Url; use Piwik\ProxyHeaders; use Piwik\Db; +use Piwik\Plugins\Installation\FormDatabaseSetup; +use Piwik\Plugins\Installation\FormFirstWebsiteSetup; +use Piwik\Plugins\Installation\FormGeneralSetup; +use Piwik\Plugins\LanguagesManager\LanguagesManager; +use Piwik\Plugins\SitesManager\API as SitesManagerAPI; +use Piwik\Plugins\UsersManager\API as UsersManagerAPI; +use Zend_Db_Adapter_Exception; /** * Installation controller * - * @package Piwik_Installation + * @package Installation */ -class Piwik_Installation_Controller extends Admin +class Controller extends \Piwik\Controller\Admin { // public so plugins can add/delete installation steps public $steps = array( - 'welcome' => 'Installation_Welcome', - 'systemCheck' => 'Installation_SystemCheck', - 'databaseSetup' => 'Installation_DatabaseSetup', - 'databaseCheck' => 'Installation_DatabaseCheck', - 'tablesCreation' => 'Installation_Tables', - 'generalSetup' => 'Installation_SuperUser', - 'firstWebsiteSetup' => 'Installation_SetupWebsite', - 'trackingCode' => 'Installation_JsTag', - 'finished' => 'Installation_Congratulations', + 'welcome' => 'Installation_Welcome', + 'systemCheck' => 'Installation_SystemCheck', + 'databaseSetup' => 'Installation_DatabaseSetup', + 'databaseCheck' => 'Installation_DatabaseCheck', + 'tablesCreation' => 'Installation_Tables', + 'generalSetup' => 'Installation_SuperUser', + 'firstWebsiteSetup' => 'Installation_SetupWebsite', + 'trackingCode' => 'Installation_JsTag', + 'finished' => 'Installation_Congratulations', ); protected $session; public function __construct() { - $this->session = new SessionNamespace('Piwik_Installation'); + $this->session = new SessionNamespace('Installation'); if (!isset($this->session->currentStepDone)) { $this->session->currentStepDone = ''; $this->session->skipThisStep = array(); @@ -87,7 +96,7 @@ class Piwik_Installation_Controller extends Admin // Delete merged js/css files to force regenerations based on updated activated plugin list Piwik::deleteAllCacheOnUpdate(); - $view = new Piwik_Installation_View( + $view = new View( '@Installation/welcome', $this->getInstallationSteps(), __FUNCTION__ @@ -107,7 +116,7 @@ class Piwik_Installation_Controller extends Admin { $this->checkPreviousStepIsValid(__FUNCTION__); - $view = new Piwik_Installation_View( + $view = new View( '@Installation/systemCheck', $this->getInstallationSteps(), __FUNCTION__ @@ -147,11 +156,11 @@ class Piwik_Installation_Controller extends Admin // case the user hits the back button $this->session->skipThisStep = array( - 'firstWebsiteSetup' => false, - 'trackingCode' => false, + 'firstWebsiteSetup' => false, + 'trackingCode' => false, ); - $view = new Piwik_Installation_View( + $view = new View( '@Installation/databaseSetup', $this->getInstallationSteps(), __FUNCTION__ @@ -160,7 +169,7 @@ class Piwik_Installation_Controller extends Admin $view->showNextStep = false; - $form = new Piwik_Installation_FormDatabaseSetup(); + $form = new FormDatabaseSetup(); if ($form->validate()) { try { @@ -187,7 +196,7 @@ class Piwik_Installation_Controller extends Admin function databaseCheck() { $this->checkPreviousStepIsValid(__FUNCTION__); - $view = new Piwik_Installation_View( + $view = new View( '@Installation/databaseCheck', $this->getInstallationSteps(), __FUNCTION__ @@ -246,7 +255,7 @@ class Piwik_Installation_Controller extends Admin { $this->checkPreviousStepIsValid(__FUNCTION__); - $view = new Piwik_Installation_View( + $view = new View( '@Installation/tablesCreation', $this->getInstallationSteps(), __FUNCTION__ @@ -281,8 +290,8 @@ class Piwik_Installation_Controller extends Admin Access::getInstance(); Piwik::setUserIsSuperUser(); if ($baseTablesInstalled >= $minimumCountPiwikTables && - count(Piwik_SitesManager_API::getInstance()->getAllSitesId()) > 0 && - count(Piwik_UsersManager_API::getInstance()->getUsers()) > 0 + count(SitesManagerAPI::getInstance()->getAllSitesId()) > 0 && + count(SitesManagerAPI::getInstance()->getUsers()) > 0 ) { $view->showReuseExistingTables = true; // when the user reuses the same tables we skip the website creation step @@ -313,14 +322,14 @@ class Piwik_Installation_Controller extends Admin { $this->checkPreviousStepIsValid(__FUNCTION__); - $view = new Piwik_Installation_View( + $view = new View( '@Installation/generalSetup', $this->getInstallationSteps(), __FUNCTION__ ); $this->skipThisStep(__FUNCTION__); - $form = new Piwik_Installation_FormGeneralSetup(); + $form = new FormGeneralSetup(); if ($form->validate()) { $superUserInfos = array( @@ -370,14 +379,14 @@ class Piwik_Installation_Controller extends Admin { $this->checkPreviousStepIsValid(__FUNCTION__); - $view = new Piwik_Installation_View( + $view = new View( '@Installation/firstWebsiteSetup', $this->getInstallationSteps(), __FUNCTION__ ); $this->skipThisStep(__FUNCTION__); - $form = new Piwik_Installation_FormFirstWebsiteSetup(); + $form = new FormFirstWebsiteSetup(); if (!isset($this->session->generalSetupSuccessMessage)) { $view->displayGeneralSetupSuccess = true; $this->session->generalSetupSuccessMessage = true; @@ -407,7 +416,6 @@ class Piwik_Installation_Controller extends Admin } catch (Exception $e) { $view->errorMessage = $e->getMessage(); } - } $view->addForm($form); echo $view->render(); @@ -420,7 +428,7 @@ class Piwik_Installation_Controller extends Admin { $this->checkPreviousStepIsValid(__FUNCTION__); - $view = new Piwik_Installation_View( + $view = new View( '@Installation/trackingCode', $this->getInstallationSteps(), __FUNCTION__ @@ -458,7 +466,7 @@ class Piwik_Installation_Controller extends Admin { $this->checkPreviousStepIsValid(__FUNCTION__); - $view = new Piwik_Installation_View( + $view = new View( '@Installation/finished', $this->getInstallationSteps(), __FUNCTION__ @@ -562,7 +570,7 @@ class Piwik_Installation_Controller extends Admin public function saveLanguage() { $language = Common::getRequestVar('language'); - Piwik_LanguagesManager::setLanguageForSession($language); + LanguagesManager::setLanguageForSession($language); Url::redirectToReferer(); } @@ -601,7 +609,7 @@ class Piwik_Installation_Controller extends Admin } } if ($error) { - Piwik_Login_Controller::clearSession(); + \Piwik\Plugins\Login\Controller::clearSession(); $message = Piwik_Translate('Installation_ErrorInvalidState', array('<br /><b>', '</b>', @@ -693,20 +701,20 @@ class Piwik_Installation_Controller extends Admin $directoriesToCheck = array(); - if(!Piwik::isInstalled()) { + if (!Piwik::isInstalled()) { // at install, need /config to be writable (so we can create config.ini.php) $directoriesToCheck[] = '/config/'; } $directoriesToCheck = array_merge($directoriesToCheck, array( - '/tmp/', - '/tmp/templates_c/', - '/tmp/cache/', - '/tmp/assets/', - '/tmp/latest/', - '/tmp/tcpdf/', - '/tmp/sessions/', - )); + '/tmp/', + '/tmp/templates_c/', + '/tmp/cache/', + '/tmp/assets/', + '/tmp/latest/', + '/tmp/tcpdf/', + '/tmp/sessions/', + )); $infos['directories'] = Piwik::checkDirectoriesWritable($directoriesToCheck); @@ -905,7 +913,6 @@ class Piwik_Installation_Controller extends Admin $blacklistFunctions = array_map('strtolower', array_map('trim', explode(',', $blacklist))); return $exists && !in_array($functionName, $blacklistFunctions); } - } return $exists; } diff --git a/plugins/Installation/FormDatabaseSetup.php b/plugins/Installation/FormDatabaseSetup.php index fc9f3957ee..c67d8b8470 100644 --- a/plugins/Installation/FormDatabaseSetup.php +++ b/plugins/Installation/FormDatabaseSetup.php @@ -6,18 +6,24 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Installation + * @package Installation */ +namespace Piwik\Plugins\Installation; + use Piwik\Db\Adapter; use Piwik\Piwik; use Piwik\Common; use Piwik\QuickForm2; +use Exception; +use HTML_QuickForm2_DataSource_Array; +use HTML_QuickForm2_Factory; +use Zend_Db_Adapter_Exception; /** * - * @package Piwik_Installation + * @package Installation */ -class Piwik_Installation_FormDatabaseSetup extends QuickForm2 +class FormDatabaseSetup extends QuickForm2 { function __construct($id = 'databasesetupform', $method = 'post', $attributes = null, $trackSubmit = false) { @@ -26,9 +32,9 @@ class Piwik_Installation_FormDatabaseSetup extends QuickForm2 function init() { - HTML_QuickForm2_Factory::registerRule('checkValidFilename', 'Piwik_Installation_FormDatabaseSetup_Rule_checkValidFilename'); + HTML_QuickForm2_Factory::registerRule('checkValidFilename', 'FormDatabaseSetup_Rule_checkValidFilename'); - $checkUserPrivilegesClass = 'Piwik_Installation_FormDatabaseSetup_Rule_checkUserPrivileges'; + $checkUserPrivilegesClass = 'Rule_checkUserPrivileges'; HTML_QuickForm2_Factory::registerRule('checkUserPrivileges', $checkUserPrivilegesClass); $availableAdapters = Adapter::getAdapters(); @@ -44,7 +50,7 @@ class Piwik_Installation_FormDatabaseSetup extends QuickForm2 $user = $this->addElement('text', 'username') ->setLabel(Piwik_Translate('Installation_DatabaseSetupLogin')); $user->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Installation_DatabaseSetupLogin'))); - $requiredPrivileges = Piwik_Installation_FormDatabaseSetup_Rule_checkUserPrivileges::getRequiredPrivilegesPretty(); + $requiredPrivileges = Rule_checkUserPrivileges::getRequiredPrivilegesPretty(); $user->addRule('checkUserPrivileges', Piwik_Translate('Installation_InsufficientPrivilegesMain', $requiredPrivileges . '<br/><br/>') . Piwik_Translate('Installation_InsufficientPrivilegesHelp')); @@ -148,9 +154,9 @@ class Piwik_Installation_FormDatabaseSetup extends QuickForm2 * - DROP * - CREATE TEMPORARY TABLES * - * @package Piwik_Installation + * @package Installation */ -class Piwik_Installation_FormDatabaseSetup_Rule_checkUserPrivileges extends HTML_QuickForm2_Rule +class Rule_checkUserPrivileges extends HTML_QuickForm2_Rule { const TEST_TABLE_NAME = 'piwik_test_table'; const TEST_TEMP_TABLE_NAME = 'piwik_test_table_temp'; @@ -228,22 +234,22 @@ class Piwik_Installation_FormDatabaseSetup_Rule_checkUserPrivileges extends HTML { return array( 'CREATE' => 'CREATE TABLE ' . self::TEST_TABLE_NAME . ' ( - id INT AUTO_INCREMENT, - value INT, - PRIMARY KEY (id), - KEY index_value (value) - )', + id INT AUTO_INCREMENT, + value INT, + PRIMARY KEY (id), + KEY index_value (value) + )', 'ALTER' => 'ALTER TABLE ' . self::TEST_TABLE_NAME . ' - ADD COLUMN other_value INT DEFAULT 0', + ADD COLUMN other_value INT DEFAULT 0', 'SELECT' => 'SELECT * FROM ' . self::TEST_TABLE_NAME, 'INSERT' => 'INSERT INTO ' . self::TEST_TABLE_NAME . ' (value) VALUES (123)', 'UPDATE' => 'UPDATE ' . self::TEST_TABLE_NAME . ' SET value = 456 WHERE id = 1', 'DELETE' => 'DELETE FROM ' . self::TEST_TABLE_NAME . ' WHERE id = 1', 'DROP' => 'DROP TABLE ' . self::TEST_TABLE_NAME, 'CREATE TEMPORARY TABLES' => 'CREATE TEMPORARY TABLE ' . self::TEST_TEMP_TABLE_NAME . ' ( - id INT AUTO_INCREMENT, - PRIMARY KEY (id) - )', + id INT AUTO_INCREMENT, + PRIMARY KEY (id) + )', ); } @@ -294,9 +300,9 @@ class Piwik_Installation_FormDatabaseSetup_Rule_checkUserPrivileges extends HTML /** * Filename check for prefix/DB name * - * @package Piwik_Installation + * @package Installation */ -class Piwik_Installation_FormDatabaseSetup_Rule_checkValidFilename extends HTML_QuickForm2_Rule +class FormDatabaseSetup_Rule_checkValidFilename extends HTML_QuickForm2_Rule { function validateOwner() { diff --git a/plugins/Installation/FormFirstWebsiteSetup.php b/plugins/Installation/FormFirstWebsiteSetup.php index 31c3e4cf4a..2f8a810b1f 100644 --- a/plugins/Installation/FormFirstWebsiteSetup.php +++ b/plugins/Installation/FormFirstWebsiteSetup.php @@ -6,15 +6,20 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Installation + * @package Installation */ + +namespace Piwik\Plugins\Installation; +use HTML_QuickForm2_DataSource_Array; +use HTML_QuickForm2_Factory; use Piwik\QuickForm2; +use Piwik\Plugins\SitesManager\API; /** * - * @package Piwik_Installation + * @package Installation */ -class Piwik_Installation_FormFirstWebsiteSetup extends QuickForm2 +class FormFirstWebsiteSetup extends QuickForm2 { function __construct($id = 'websitesetupform', $method = 'post', $attributes = null, $trackSubmit = false) { @@ -23,12 +28,12 @@ class Piwik_Installation_FormFirstWebsiteSetup extends QuickForm2 function init() { - HTML_QuickForm2_Factory::registerRule('checkTimezone', 'Piwik_Installation_FormFirstWebsiteSetup_Rule_isValidTimezone'); + HTML_QuickForm2_Factory::registerRule('checkTimezone', 'Rule_isValidTimezone'); $urlExample = 'http://example.org'; $javascriptOnClickUrlExample = "javascript:if(this.value=='$urlExample'){this.value='http://';} this.style.color='black';"; - $timezones = Piwik_SitesManager_API::getInstance()->getTimezonesList(); + $timezones = API::getInstance()->getTimezonesList(); $timezones = array_merge(array('No timezone' => Piwik_Translate('SitesManager_SelectACity')), $timezones); $this->addElement('text', 'siteName') @@ -66,20 +71,20 @@ class Piwik_Installation_FormFirstWebsiteSetup extends QuickForm2 /** * Timezone validation rule * - * @package Piwik_Installation + * @package Installation */ -class Piwik_Installation_FormFirstWebsiteSetup_Rule_isValidTimezone extends HTML_QuickForm2_Rule +class Rule_isValidTimezone extends HTML_QuickForm2_Rule { function validateOwner() { try { $timezone = $this->owner->getValue(); if (!empty($timezone)) { - Piwik_SitesManager_API::getInstance()->setDefaultTimezone($timezone); + API::getInstance()->setDefaultTimezone($timezone); } } catch (Exception $e) { return false; } return true; } -} +}
\ No newline at end of file diff --git a/plugins/Installation/FormGeneralSetup.php b/plugins/Installation/FormGeneralSetup.php index bd2504588a..cfa4ce3c8b 100644 --- a/plugins/Installation/FormGeneralSetup.php +++ b/plugins/Installation/FormGeneralSetup.php @@ -6,16 +6,20 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Installation + * @package Installation */ -use Piwik\Piwik; +namespace Piwik\Plugins\Installation; + +use HTML_QuickForm2_DataSource_Array; +use HTML_QuickForm2_Factory; use Piwik\QuickForm2; +use Piwik\Piwik; /** * - * @package Piwik_Installation + * @package Installation */ -class Piwik_Installation_FormGeneralSetup extends QuickForm2 +class FormGeneralSetup extends QuickForm2 { function __construct($id = 'generalsetupform', $method = 'post', $attributes = null, $trackSubmit = false) { @@ -24,8 +28,8 @@ class Piwik_Installation_FormGeneralSetup extends QuickForm2 function init() { - HTML_QuickForm2_Factory::registerRule('checkLogin', 'Piwik_Installation_FormGeneralSetup_Rule_isValidLoginString'); - HTML_QuickForm2_Factory::registerRule('checkEmail', 'Piwik_Installation_FormGeneralSetup_Rule_isValidEmailString'); + HTML_QuickForm2_Factory::registerRule('checkLogin', 'Rule_isValidLoginString'); + HTML_QuickForm2_Factory::registerRule('checkEmail', 'Rule_isValidEmailString'); $login = $this->addElement('text', 'login') ->setLabel(Piwik_Translate('Installation_SuperUserLogin')); @@ -67,9 +71,9 @@ class Piwik_Installation_FormGeneralSetup extends QuickForm2 /** * Login id validation rule * - * @package Piwik_Installation + * @package Installation */ -class Piwik_Installation_FormGeneralSetup_Rule_isValidLoginString extends HTML_QuickForm2_Rule +class Rule_isValidLoginString extends HTML_QuickForm2_Rule { function validateOwner() { @@ -89,12 +93,12 @@ class Piwik_Installation_FormGeneralSetup_Rule_isValidLoginString extends HTML_Q /** * Email address validation rule * - * @package Piwik_Installation + * @package Installation */ -class Piwik_Installation_FormGeneralSetup_Rule_isValidEmailString extends HTML_QuickForm2_Rule +class Rule_isValidEmailString extends HTML_QuickForm2_Rule { function validateOwner() { return Piwik::isValidEmailString($this->owner->getValue()); } -} +}
\ No newline at end of file diff --git a/plugins/Installation/Installation.php b/plugins/Installation/Installation.php index 8017e4e535..1fb9a565f9 100644 --- a/plugins/Installation/Installation.php +++ b/plugins/Installation/Installation.php @@ -6,20 +6,20 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Installation + * @package Installation */ +namespace Piwik\Plugins\Installation; + use Piwik\Piwik; use Piwik\Common; -use Piwik\Plugin; -use Piwik\Translate; /** * - * @package Piwik_Installation + * @package Installation */ -class Piwik_Installation extends Plugin +class Installation extends \Piwik\Plugin { - protected $installationControllerName = 'Piwik_Installation_Controller'; + protected $installationControllerName = 'Controller'; /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/Installation/View.php b/plugins/Installation/View.php index 84a8d631cf..d5599bed53 100644 --- a/plugins/Installation/View.php +++ b/plugins/Installation/View.php @@ -6,15 +6,16 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Installation + * @package Installation */ -use Piwik\View; +namespace Piwik\Plugins\Installation; + /** * - * @package Piwik_Installation + * @package Installation */ -class Piwik_Installation_View extends View +class View extends \Piwik\View { public function __construct($subtemplatePath, $installationSteps, $currentStepName) { diff --git a/plugins/LanguagesManager/API.php b/plugins/LanguagesManager/API.php index ee6dd2aaa9..332b68cc9c 100644 --- a/plugins/LanguagesManager/API.php +++ b/plugins/LanguagesManager/API.php @@ -6,9 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_LanguagesManager + * @package LanguagesManager * */ +namespace Piwik\Plugins\LanguagesManager; + use Piwik\Piwik; use Piwik\Common; use Piwik\Db; @@ -23,14 +25,14 @@ use Piwik\Db; * You can also request the default language to load for a user via "getLanguageForUser", * or update it via "setLanguageForUser". * - * @package Piwik_LanguagesManager + * @package LanguagesManager */ -class Piwik_LanguagesManager_API +class API { static private $instance = null; /** - * @return Piwik_LanguagesManager_API + * @return \Piwik\Plugins\LanguagesManager\API */ static public function getInstance() { diff --git a/plugins/LanguagesManager/Controller.php b/plugins/LanguagesManager/Controller.php index 212293ce79..3eba8c5097 100644 --- a/plugins/LanguagesManager/Controller.php +++ b/plugins/LanguagesManager/Controller.php @@ -6,18 +6,22 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_LanguagesManager + * @package LanguagesManager * */ +namespace Piwik\Plugins\LanguagesManager; + use Piwik\Piwik; use Piwik\Common; -use Piwik\Controller; +use Piwik\Plugins\LanguagesManager\API; use Piwik\Url; +use Piwik\Plugins\LanguagesManager\LanguagesManager; +use Zend_Registry; /** - * @package Piwik_LanguagesManager + * @package LanguagesManager */ -class Piwik_LanguagesManager_Controller extends Controller +class Controller extends \Piwik\Controller { /** * anonymous = in the session @@ -31,11 +35,11 @@ class Piwik_LanguagesManager_Controller extends Controller if (Piwik::isInstalled()) { $this->checkTokenInUrl(); } - Piwik_LanguagesManager::setLanguageForSession($language); + LanguagesManager::setLanguageForSession($language); if (Zend_Registry::isRegistered('access')) { $currentUser = Piwik::getCurrentUserLogin(); if ($currentUser && $currentUser !== 'anonymous') { - Piwik_LanguagesManager_API::getInstance()->setLanguageForUser($currentUser, $language); + API::getInstance()->setLanguageForUser($currentUser, $language); } } Url::redirectToReferer(); diff --git a/plugins/LanguagesManager/LanguagesManager.php b/plugins/LanguagesManager/LanguagesManager.php index 6bd1bf553c..004d82ade6 100644 --- a/plugins/LanguagesManager/LanguagesManager.php +++ b/plugins/LanguagesManager/LanguagesManager.php @@ -6,23 +6,27 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_LanguagesManager + * @package LanguagesManager * */ +namespace Piwik\Plugins\LanguagesManager; + +use Exception; use Piwik\Config; use Piwik\Piwik; use Piwik\Common; use Piwik\Cookie; +use Piwik\Plugins\LanguagesManager\API; use Piwik\View; -use Piwik\Plugin; use Piwik\Db; use Piwik\Translate; +use Zend_Registry; /** * - * @package Piwik_LanguagesManager + * @package LanguagesManager */ -class Piwik_LanguagesManager extends Plugin +class LanguagesManager extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered @@ -75,7 +79,7 @@ class Piwik_LanguagesManager extends Plugin private function getLanguagesSelector() { $view = new View("@LanguagesManager/getLanguagesSelector"); - $view->languages = Piwik_LanguagesManager_API::getInstance()->getAvailableLanguageNames(); + $view->languages = API::getInstance()->getAvailableLanguageNames(); $view->currentLanguageCode = self::getLanguageCodeForCurrentUser(); $view->currentLanguageName = self::getLanguageNameForCurrentUser(); return $view->render(); @@ -86,7 +90,7 @@ class Piwik_LanguagesManager extends Plugin if (empty($language)) { $language = self::getLanguageCodeForCurrentUser(); } - if (!Piwik_LanguagesManager_API::getInstance()->isLanguageAvailable($language)) { + if (!API::getInstance()->isLanguageAvailable($language)) { $language = Translate::getInstance()->getLanguageDefault(); } } @@ -132,10 +136,10 @@ class Piwik_LanguagesManager extends Plugin static public function getLanguageCodeForCurrentUser() { $languageCode = self::getLanguageFromPreferences(); - if (!Piwik_LanguagesManager_API::getInstance()->isLanguageAvailable($languageCode)) { - $languageCode = Common::extractLanguageCodeFromBrowserLanguage(Common::getBrowserLanguage(), Piwik_LanguagesManager_API::getInstance()->getAvailableLanguages()); + if (!API::getInstance()->isLanguageAvailable($languageCode)) { + $languageCode = Common::extractLanguageCodeFromBrowserLanguage(Common::getBrowserLanguage(), API::getInstance()->getAvailableLanguages()); } - if (!Piwik_LanguagesManager_API::getInstance()->isLanguageAvailable($languageCode)) { + if (!API::getInstance()->isLanguageAvailable($languageCode)) { $languageCode = Translate::getInstance()->getLanguageDefault(); } return $languageCode; @@ -147,7 +151,7 @@ class Piwik_LanguagesManager extends Plugin static public function getLanguageNameForCurrentUser() { $languageCode = self::getLanguageCodeForCurrentUser(); - $languages = Piwik_LanguagesManager_API::getInstance()->getAvailableLanguageNames(); + $languages = API::getInstance()->getAvailableLanguageNames(); foreach ($languages as $language) { if ($language['code'] === $languageCode) { return $language['name']; @@ -166,13 +170,12 @@ class Piwik_LanguagesManager extends Plugin try { $currentUser = Piwik::getCurrentUserLogin(); - return Piwik_LanguagesManager_API::getInstance()->getLanguageForUser($currentUser); + return API::getInstance()->getLanguageForUser($currentUser); } catch (Exception $e) { return false; } } - /** * Returns the language for the session * @@ -196,7 +199,7 @@ class Piwik_LanguagesManager extends Plugin */ static public function setLanguageForSession($languageCode) { - if (!Piwik_LanguagesManager_API::getInstance()->isLanguageAvailable($languageCode)) { + if (!API::getInstance()->isLanguageAvailable($languageCode)) { return false; } diff --git a/plugins/Live/API.php b/plugins/Live/API.php index 8f43f26563..3429892a1c 100644 --- a/plugins/Live/API.php +++ b/plugins/Live/API.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Live + * @package Live */ +namespace Piwik\Plugins\Live; + +use Exception; use Piwik\Config; use Piwik\DataAccess\LogAggregator; use Piwik\DataTable\Filter\ColumnDelete; @@ -24,6 +27,8 @@ use Piwik\Site; use Piwik\Db; use Piwik\Tracker\Action; use Piwik\Tracker\GoalManager; +use Piwik\Plugins\Live\Visitor; +use Piwik\Plugins\SitesManager\API as SitesManagerAPI; /** * @see plugins/Referers/functions.php @@ -49,9 +54,9 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Live/Visitor.php'; * The method "getCounters" is used to return a simple counter: visits, number of actions, number of converted visits, in the last N minutes. * * See also the documentation about <a href='http://piwik.org/docs/real-time/' target='_blank'>Real time widget and visitor level reports</a> in Piwik. - * @package Piwik_Live + * @package Live */ -class Piwik_Live_API +class API { const VISITOR_PROFILE_MAX_VISITS_TO_AGGREGATE = 100; const VISITOR_PROFILE_MAX_VISITS_TO_SHOW = 10; @@ -60,7 +65,7 @@ class Piwik_Live_API static private $instance = null; /** - * @return Piwik_Live_API + * @return \Piwik\Plugins\Live\API */ static public function getInstance() { @@ -344,10 +349,10 @@ class Piwik_Live_API $site = new Site($idSite); $timezone = $site->getTimezone(); - $currencies = Piwik_SitesManager_API::getInstance()->getCurrencySymbols(); + $currencies = SitesManagerAPI::getInstance()->getCurrencySymbols(); foreach ($visitorDetails as $visitorDetail) { $this->cleanVisitorDetails($visitorDetail, $idSite); - $visitor = new Piwik_Live_Visitor($visitorDetail); + $visitor = new Visitor($visitorDetail); $visitorDetailsArray = $visitor->getAllVisitorDetails(); $visitorDetailsArray['siteCurrency'] = $site->getCurrency(); @@ -362,11 +367,11 @@ class Piwik_Live_API $visitorDetailsArray['serverTimePrettyFirstAction'] = $dateTimeVisitFirstAction->getLocalized('%time%'); $visitorDetailsArray['actionDetails'] = array(); - if(!$doNotFetchActions) { + if (!$doNotFetchActions) { $visitorDetailsArray = $this->enrichVisitorArrayWithActions($visitorDetailsArray, $actionsLimit, $timezone); } - if($flat) { + if ($flat) { $visitorDetailsArray = $this->flattenVisitorDetailsArray($visitorDetailsArray); } $table->addRowFromArray(array(Row::COLUMNS => $visitorDetailsArray)); @@ -386,7 +391,6 @@ class Piwik_Live_API return $key; } - /** * The &flat=1 feature is used by API.getSuggestedValuesForSegment * @@ -422,8 +426,8 @@ class Piwik_Live_API // Flatten Goals $count = 1; - foreach($visitorDetailsArray['actionDetails'] as $action) { - if(!empty($action['goalId'])) { + foreach ($visitorDetailsArray['actionDetails'] as $action) { + if (!empty($action['goalId'])) { $flattenedKeyName = 'visitConvertedGoalId' . ColumnDelete::APPEND_TO_COLUMN_NAME_TO_KEEP . $count; $visitorDetailsArray[$flattenedKeyName] = $action['goalId']; $count++; @@ -432,18 +436,18 @@ class Piwik_Live_API // Flatten Page Titles/URLs $count = 1; - foreach($visitorDetailsArray['actionDetails'] as $action) { - if(!empty($action['url'])) { + foreach ($visitorDetailsArray['actionDetails'] as $action) { + if (!empty($action['url'])) { $flattenedKeyName = 'pageUrl' . ColumnDelete::APPEND_TO_COLUMN_NAME_TO_KEEP . $count; $visitorDetailsArray[$flattenedKeyName] = $action['url']; } - if(!empty($action['pageTitle'])) { + if (!empty($action['pageTitle'])) { $flattenedKeyName = 'pageTitle' . ColumnDelete::APPEND_TO_COLUMN_NAME_TO_KEEP . $count; $visitorDetailsArray[$flattenedKeyName] = $action['pageTitle']; } - if(!empty($action['siteSearchKeyword'])) { + if (!empty($action['siteSearchKeyword'])) { $flattenedKeyName = 'siteSearchKeyword' . ColumnDelete::APPEND_TO_COLUMN_NAME_TO_KEEP . $count; $visitorDetailsArray[$flattenedKeyName] = $action['siteSearchKeyword']; } @@ -452,25 +456,25 @@ class Piwik_Live_API // Entry/exit pages $firstAction = $lastAction = false; - foreach($visitorDetailsArray['actionDetails'] as $action) { - if($action['type'] == 'action') { - if(empty($firstAction)) { + foreach ($visitorDetailsArray['actionDetails'] as $action) { + if ($action['type'] == 'action') { + if (empty($firstAction)) { $firstAction = $action; } $lastAction = $action; } } - if(!empty($firstAction['pageTitle'])) { + if (!empty($firstAction['pageTitle'])) { $visitorDetailsArray['entryPageTitle'] = $firstAction['pageTitle']; } - if(!empty($firstAction['url'])) { + if (!empty($firstAction['url'])) { $visitorDetailsArray['entryPageUrl'] = $firstAction['url']; } - if(!empty($lastAction['pageTitle'])) { + if (!empty($lastAction['pageTitle'])) { $visitorDetailsArray['exitPageTitle'] = $lastAction['pageTitle']; } - if(!empty($lastAction['url'])) { + if (!empty($lastAction['url'])) { $visitorDetailsArray['exitPageUrl'] = $lastAction['url']; } @@ -574,8 +578,8 @@ class Piwik_Live_API // Group by idvisit so that a visitor converting 2 goals only appears once $sql = " - SELECT sub.* - FROM ( + SELECT sub.* + FROM ( " . $subQuery['sql'] . " $sqlLimit ) AS sub @@ -680,7 +684,6 @@ class Piwik_Live_API if (isset($actionDetails[$actionIdx + 1])) { $actionDetail['timeSpent'] = $actionDetails[$actionIdx + 1]['timeSpentRef']; $actionDetail['timeSpentPretty'] = Piwik::getPrettyTimeFromSeconds($actionDetail['timeSpent']); - } unset($actionDetails[$actionIdx]['timeSpentRef']); // not needed after timeSpent is added @@ -826,7 +829,6 @@ class Piwik_Live_API // Convert datetimes to the site timezone $dateTimeVisit = Date::factory($details['serverTimePretty'], $timezone); $details['serverTimePretty'] = $dateTimeVisit->getLocalized(Piwik_Translate('CoreHome_ShortDateFormat') . ' %time%'); - } $visitorDetailsArray['goalConversions'] = count($goalDetails); return $visitorDetailsArray; diff --git a/plugins/Live/Controller.php b/plugins/Live/Controller.php index 23ae378074..b8fa0a054c 100644 --- a/plugins/Live/Controller.php +++ b/plugins/Live/Controller.php @@ -6,21 +6,23 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Live + * @package Live */ +namespace Piwik\Plugins\Live; + use Piwik\API\Request; use Piwik\Common; use Piwik\Piwik; use Piwik\Config; -use Piwik\Controller; +use Piwik\Plugins\Live\API; use Piwik\ViewDataTable; use Piwik\View; use Piwik\FrontController; /** - * @package Piwik_Live + * @package Live */ -class Piwik_Live_Controller extends Controller +class Controller extends \Piwik\Controller { const SIMPLE_VISIT_COUNT_WIDGET_LAST_MINUTES_CONFIG_KEY = 'live_widget_visitor_count_last_minutes'; @@ -81,7 +83,7 @@ class Piwik_Live_Controller extends Controller } echo $rendered; } - + public function indexVisitorLog() { $view = new View('@Live/indexVisitorLog.twig'); @@ -121,9 +123,9 @@ class Piwik_Live_Controller extends Controller private function setCounters($view) { $segment = Request::getRawSegmentFromRequest(); - $last30min = Piwik_Live_API::getInstance()->getCounters($this->idSite, $lastMinutes = 30, $segment); + $last30min = API::getInstance()->getCounters($this->idSite, $lastMinutes = 30, $segment); $last30min = $last30min[0]; - $today = Piwik_Live_API::getInstance()->getCounters($this->idSite, $lastMinutes = 24 * 60, $segment); + $today = API::getInstance()->getCounters($this->idSite, $lastMinutes = 24 * 60, $segment); $today = $today[0]; $view->visitorsCountHalfHour = $last30min['visits']; $view->visitorsCountToday = $today['visits']; diff --git a/plugins/Live/Live.php b/plugins/Live/Live.php index 54820cd836..bbdd142b43 100644 --- a/plugins/Live/Live.php +++ b/plugins/Live/Live.php @@ -6,17 +6,18 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Live + * @package Live */ -use Piwik\Plugin; +namespace Piwik\Plugins\Live; + use Piwik\Common; use Piwik\WidgetsList; /** * - * @package Piwik_Live + * @package Live */ -class Piwik_Live extends Plugin +class Live extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered @@ -24,10 +25,10 @@ class Piwik_Live extends Plugin public function getListHooksRegistered() { return array( - 'AssetManager.getJsFiles' => 'getJsFiles', - 'AssetManager.getCssFiles' => 'getCssFiles', - 'WidgetsList.add' => 'addWidget', - 'Menu.add' => 'addMenu', + 'AssetManager.getJsFiles' => 'getJsFiles', + 'AssetManager.getCssFiles' => 'getCssFiles', + 'WidgetsList.add' => 'addWidget', + 'Menu.add' => 'addMenu', 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); } @@ -63,14 +64,14 @@ class Piwik_Live extends Plugin private function getDisplayPropertiesForGetLastVisitsDetails() { return array( - 'datatable_template' => "@Live/getVisitorLog.twig", - 'disable_generic_filters' => true, - 'enable_sort' => false, - 'filter_sort_column' => 'idVisit', - 'filter_sort_order' => 'asc', - 'show_search' => false, - 'filter_limit' => 20, - 'show_offset_information' => false, + 'datatable_template' => "@Live/getVisitorLog.twig", + 'disable_generic_filters' => true, + 'enable_sort' => false, + 'filter_sort_column' => 'idVisit', + 'filter_sort_order' => 'asc', + 'show_search' => false, + 'filter_limit' => 20, + 'show_offset_information' => false, 'show_exclude_low_population' => false, 'show_all_views_icons' => false, 'show_table_all_columns' => false, @@ -78,9 +79,9 @@ class Piwik_Live extends Plugin 'documentation' => Piwik_Translate('Live_VisitorLogDocumentation', array('<br />', '<br />')), 'custom_parameters' => array( // set a very high row count so that the next link in the footer of the data table is always shown - 'totalRows' => 10000000, + 'totalRows' => 10000000, - 'filterEcommerce' => Common::getRequestVar('filterEcommerce', 0, 'int'), + 'filterEcommerce' => Common::getRequestVar('filterEcommerce', 0, 'int'), 'pageUrlNotDefined' => Piwik_Translate('General_NotDefined', Piwik_Translate('Actions_ColumnPageURL')) ), 'visualization_properties' => array( diff --git a/plugins/Live/Visitor.php b/plugins/Live/Visitor.php index 5d7441fc38..849521ba3d 100644 --- a/plugins/Live/Visitor.php +++ b/plugins/Live/Visitor.php @@ -6,13 +6,18 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Live + * @package Live */ +namespace Piwik\Plugins\Live; + use Piwik\Piwik; use Piwik\Common; use Piwik\IP; use Piwik\Tracker; use Piwik\Tracker\Visit; +use Piwik\Plugins\API\API as MetaAPI; +use Piwik\Plugins\Referers\API as ReferersAPI; +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; /** * @see plugins/Referers/functions.php @@ -27,10 +32,9 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/UserSettings/functions.php'; require_once PIWIK_INCLUDE_PATH . '/plugins/Provider/functions.php'; /** - * - * @package Piwik_Live + * @package Live */ -class Piwik_Live_Visitor +class Visitor { const DELIMITER_PLUGIN_NAME = ", "; @@ -102,7 +106,7 @@ class Piwik_Live_Visitor 'referrerSearchEngineUrl' => $this->getSearchEngineUrl(), 'referrerSearchEngineIcon' => $this->getSearchEngineIcon(), 'operatingSystem' => $this->getOperatingSystem(), - 'operatingSystemCode' => $this->getOperatingSystemCode(), + 'operatingSystemCode' => $this->getOperatingSystemCode(), 'operatingSystemShortName' => $this->getOperatingSystemShortName(), 'operatingSystemIcon' => $this->getOperatingSystemIcon(), 'browserFamily' => $this->getBrowserFamily(), @@ -244,17 +248,17 @@ class Piwik_Live_Visitor function getCountryName() { - return Piwik_CountryTranslate($this->getCountryCode()); + return \Piwik\Plugins\UserCountry\countryTranslate($this->getCountryCode()); } function getCountryFlag() { - return Piwik_getFlagFromCode($this->getCountryCode()); + return \Piwik\Plugins\UserCountry\getFlagFromCode($this->getCountryCode()); } function getContinent() { - return Piwik_ContinentTranslate($this->getContinentCode()); + return \Piwik\Plugins\UserCountry\continentTranslate($this->getContinentCode()); } function getContinentCode() @@ -274,7 +278,7 @@ class Piwik_Live_Visitor { $region = $this->getRegionCode(); if ($region != '' && $region != Visit::UNKNOWN_CODE) { - return Piwik_UserCountry_LocationProvider_GeoIp::getRegionNameFromCodes( + return GeoIp::getRegionNameFromCodes( $this->details['location_country'], $region); } return null; @@ -335,12 +339,12 @@ class Piwik_Live_Visitor function getRefererType() { - return Piwik_getRefererTypeFromShortName($this->details['referer_type']); + return \Piwik\Plugins\Referers\getRefererTypeFromShortName($this->details['referer_type']); } function getRefererTypeName() { - return Piwik_getRefererTypeLabel($this->details['referer_type']); + return \Piwik\Plugins\Referers\getRefererTypeLabel($this->details['referer_type']); } function getKeyword() @@ -349,7 +353,7 @@ class Piwik_Live_Visitor if (\Piwik\PluginsManager::getInstance()->isPluginActivated('Referers') && $this->getRefererType() == 'search' ) { - $keyword = Piwik_Referers_API::getCleanKeyword($keyword); + $keyword = \Piwik\Plugins\Referers\API::getCleanKeyword($keyword); } return urldecode($keyword); } @@ -358,7 +362,7 @@ class Piwik_Live_Visitor { if ($this->getRefererType() == 'search') { if (\Piwik\PluginsManager::getInstance()->isPluginActivated('Referers') - && $this->details['referer_keyword'] == Piwik_Referers_API::LABEL_KEYWORD_NOT_DEFINED + && $this->details['referer_keyword'] == ReferersAPI::LABEL_KEYWORD_NOT_DEFINED ) { return 'http://piwik.org/faq/general/#faq_144'; } // Case URL is google.XX/url.... then we rewrite to the search result page url @@ -367,7 +371,7 @@ class Piwik_Live_Visitor ) { $refUrl = @parse_url($this->details['referer_url']); if (isset($refUrl['host'])) { - $url = Piwik_getSearchEngineUrlFromUrlAndKeyword('http://google.com', $this->getKeyword()); + $url = \Piwik\Plugins\Referers\getSearchEngineUrlFromUrlAndKeyword('http://google.com', $this->getKeyword()); $url = str_replace('google.com', $refUrl['host'], $url); return $url; } @@ -406,7 +410,7 @@ class Piwik_Live_Visitor if ($this->getRefererType() == 'search' && !empty($this->details['referer_name']) ) { - return Piwik_getSearchEngineUrlFromName($this->details['referer_name']); + return \Piwik\Plugins\Referers\getSearchEngineUrlFromName($this->details['referer_name']); } return null; } @@ -415,7 +419,7 @@ class Piwik_Live_Visitor { $searchEngineUrl = $this->getSearchEngineUrl(); if (!is_null($searchEngineUrl)) { - return Piwik_getSearchEngineLogoFromUrl($searchEngineUrl); + return \Piwik\Plugins\Referers\getSearchEngineLogoFromUrl($searchEngineUrl); } return null; } @@ -451,7 +455,7 @@ class Piwik_Live_Visitor $pluginIcons = array(); foreach ($pluginNames as $plugin) { - $pluginIcons[] = array("pluginIcon" => Piwik_getPluginsLogo($plugin), "pluginName" => $plugin); + $pluginIcons[] = array("pluginIcon" => \Piwik\Plugins\UserSettings\getPluginsLogo($plugin), "pluginName" => $plugin); } return $pluginIcons; } @@ -465,27 +469,27 @@ class Piwik_Live_Visitor function getOperatingSystem() { - return Piwik_getOSLabel($this->details['config_os']); + return \Piwik\Plugins\UserSettings\getOSLabel($this->details['config_os']); } function getOperatingSystemShortName() { - return Piwik_getOSShortLabel($this->details['config_os']); + return \Piwik\Plugins\UserSettings\getOSShortLabel($this->details['config_os']); } function getOperatingSystemIcon() { - return Piwik_getOSLogo($this->details['config_os']); + return \Piwik\Plugins\UserSettings\getOSLogo($this->details['config_os']); } function getBrowserFamilyDescription() { - return Piwik_getBrowserTypeLabel($this->getBrowserFamily()); + return \Piwik\Plugins\UserSettings\getBrowserTypeLabel($this->getBrowserFamily()); } function getBrowserFamily() { - return Piwik_getBrowserFamily($this->details['config_browser_name']); + return \Piwik\Plugins\UserSettings\getBrowserFamily($this->details['config_browser_name']); } function getBrowserCode() @@ -500,23 +504,23 @@ class Piwik_Live_Visitor function getBrowser() { - return Piwik_getBrowserLabel($this->details['config_browser_name'] . ";" . $this->details['config_browser_version']); + return \Piwik\Plugins\UserSettings\getBrowserLabel($this->details['config_browser_name'] . ";" . $this->details['config_browser_version']); } function getBrowserIcon() { - return Piwik_getBrowsersLogo($this->details['config_browser_name'] . ";" . $this->details['config_browser_version']); + return \Piwik\Plugins\UserSettings\getBrowsersLogo($this->details['config_browser_name'] . ";" . $this->details['config_browser_version']); } function getScreenType() { - return Piwik_getScreenTypeFromResolution($this->details['config_resolution']); + return \Piwik\Plugins\UserSettings\getScreenTypeFromResolution($this->details['config_resolution']); } function getDeviceType() { - if(\Piwik\PluginsManager::getInstance()->isPluginActivated('DevicesDetection')) { - return Piwik_getDeviceTypeLabel($this->details['config_device_type']); + if (\Piwik\PluginsManager::getInstance()->isPluginActivated('DevicesDetection')) { + return \Piwik\Plugins\DevicesDetection\getDeviceTypeLabel($this->details['config_device_type']); } return false; } @@ -528,9 +532,9 @@ class Piwik_Live_Visitor function getScreenTypeIcon() { - return Piwik_getScreensLogo($this->getScreenType()); + return \Piwik\Plugins\UserSettings\getScreensLogo($this->getScreenType()); } - + function getProvider() { if (isset($this->details['location_provider'])) { @@ -542,12 +546,12 @@ class Piwik_Live_Visitor function getProviderName() { - return Piwik_Provider_getPrettyProviderName($this->getProvider()); + return \Piwik\Plugins\Provider\getPrettyProviderName($this->getProvider()); } function getProviderUrl() { - return Piwik_getHostnameUrl(@$this->details['location_provider']); + return \Piwik\Plugins\Provider\getHostnameUrl(@$this->details['location_provider']); } function getDateTimeLastAction() @@ -569,7 +573,7 @@ class Piwik_Live_Visitor function getVisitEcommerceStatus() { - return Piwik_API_API::getVisitEcommerceStatusFromId($this->details['visit_goal_buyer']); + return MetaAPI::getVisitEcommerceStatusFromId($this->details['visit_goal_buyer']); } function getVisitorGoalConvertedIcon() diff --git a/plugins/Login/Auth.php b/plugins/Login/Auth.php index 251369e976..10bad0d0ac 100644 --- a/plugins/Login/Auth.php +++ b/plugins/Login/Auth.php @@ -6,19 +6,21 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Login + * @package Login */ +namespace Piwik\Plugins\Login; + use Piwik\Config; use Piwik\Common; -use Piwik\Auth; use Piwik\AuthResult; use Piwik\Db; +use Piwik\Plugins\UsersManager\API; /** * - * @package Piwik_Login + * @package Login */ -class Piwik_Login_Auth implements Auth +class Auth implements \Piwik\Auth { protected $login = null; protected $token_auth = null; @@ -42,7 +44,7 @@ class Piwik_Login_Auth implements Auth { $rootLogin = Config::getInstance()->superuser['login']; $rootPassword = Config::getInstance()->superuser['password']; - $rootToken = Piwik_UsersManager_API::getInstance()->getTokenAuth($rootLogin, $rootPassword); + $rootToken = API::getInstance()->getTokenAuth($rootLogin, $rootPassword); if (is_null($this->login)) { if ($this->token_auth === $rootToken) { diff --git a/plugins/Login/Controller.php b/plugins/Login/Controller.php index 4aebcd3a86..1e440de915 100644 --- a/plugins/Login/Controller.php +++ b/plugins/Login/Controller.php @@ -6,12 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Login + * @package Login */ +namespace Piwik\Plugins\Login; + +use Exception; use Piwik\Config; use Piwik\Piwik; use Piwik\Common; -use Piwik\Controller; use Piwik\Cookie; use Piwik\IP; use Piwik\Mail; @@ -20,15 +22,20 @@ use Piwik\View; use Piwik\Url; use Piwik\QuickForm2; use Piwik\Session; +use Piwik\Plugins\Login\Login; +use Piwik\Plugins\Login\FormLogin; +use Piwik\Plugins\Login\FormResetPassword; +use Piwik\Plugins\UsersManager\UsersManager; +use Piwik\Plugins\UsersManager\API; require_once PIWIK_INCLUDE_PATH . '/core/Config.php'; /** * Login controller * - * @package Piwik_Login + * @package Login */ -class Piwik_Login_Controller extends Controller +class Controller extends \Piwik\Controller { /** * Generate hash on user info and password @@ -71,10 +78,10 @@ class Piwik_Login_Controller extends Controller { self::checkForceSslLogin(); - $form = new Piwik_Login_FormLogin(); + $form = new FormLogin(); if ($form->validate()) { $nonce = $form->getSubmitValue('form_nonce'); - if (Nonce::verifyNonce('Piwik_Login.login', $nonce)) { + if (Nonce::verifyNonce('Login.login', $nonce)) { $login = $form->getSubmitValue('form_login'); $password = $form->getSubmitValue('form_password'); $rememberMe = $form->getSubmitValue('form_rememberme') == '1'; @@ -112,7 +119,7 @@ class Piwik_Login_Controller extends Controller $view->forceSslLogin = Config::getInstance()->General['force_ssl_login']; // crsf token: don't trust the submitted value; generate/fetch it from session data - $view->nonce = Nonce::getNonce('Piwik_Login.login'); + $view->nonce = Nonce::getNonce('Login.login'); } /** @@ -162,7 +169,7 @@ class Piwik_Login_Controller extends Controller 'md5Password' => $md5Password, 'rememberMe' => $rememberMe, ); - Nonce::discardNonce('Piwik_Login.login'); + Nonce::discardNonce('Login.login'); Piwik_PostEvent('Login.initSession', array(&$info)); Url::redirectToUrl($urlToRedirect); } @@ -188,10 +195,10 @@ class Piwik_Login_Controller extends Controller $infoMessage = null; $formErrors = null; - $form = new Piwik_Login_FormResetPassword(); + $form = new FormResetPassword(); if ($form->validate()) { $nonce = $form->getSubmitValue('form_nonce'); - if (Nonce::verifyNonce('Piwik_Login.login', $nonce)) { + if (Nonce::verifyNonce('Login.login', $nonce)) { $formErrors = $this->resetPasswordFirstStep($form); if (empty($formErrors)) { $infoMessage = Piwik_Translate('Login_ConfirmationLinkSent'); @@ -225,7 +232,7 @@ class Piwik_Login_Controller extends Controller // check the password try { - Piwik_UsersManager::checkPassword($password); + UsersManager::checkPassword($password); } catch (Exception $ex) { return array($ex->getMessage()); } @@ -243,14 +250,14 @@ class Piwik_Login_Controller extends Controller $login = $user['login']; // if valid, store password information in options table, then... - Piwik_Login::savePasswordResetInfo($login, $password); + Login::savePasswordResetInfo($login, $password); // ... send email with confirmation link try { $this->sendEmailConfirmationLink($user); } catch (Exception $ex) { // remove password reset info - Piwik_Login::removePasswordResetInfo($login); + Login::removePasswordResetInfo($login); return array($ex->getMessage() . '<br/>' . Piwik_Translate('Login_ContactAdmin')); } @@ -312,7 +319,7 @@ class Piwik_Login_Controller extends Controller } // check that the reset token is valid - $resetPassword = Piwik_Login::getPasswordToResetTo($login); + $resetPassword = Login::getPasswordToResetTo($login); if ($resetPassword === false || !self::isValidToken($resetToken, $user)) { throw new Exception(Piwik_Translate('Login_InvalidOrExpiredToken')); } @@ -356,7 +363,7 @@ class Piwik_Login_Controller extends Controller Config::getInstance()->superuser = $user; Config::getInstance()->forceSave(); } else { - Piwik_UsersManager_API::getInstance()->updateUser( + API::getInstance()->updateUser( $user['login'], $passwordHash, $email = false, $alias = false, $isPasswordHashed = true); } } @@ -390,10 +397,10 @@ class Piwik_Login_Controller extends Controller 'email' => Piwik::getSuperUserEmail(), 'password' => Config::getInstance()->superuser['password'], ); - } else if (Piwik_UsersManager_API::getInstance()->userExists($loginMail)) { - $user = Piwik_UsersManager_API::getInstance()->getUser($loginMail); - } else if (Piwik_UsersManager_API::getInstance()->userEmailExists($loginMail)) { - $user = Piwik_UsersManager_API::getInstance()->getUserByEmail($loginMail); + } else if (API::getInstance()->userExists($loginMail)) { + $user = API::getInstance()->getUser($loginMail); + } else if (API::getInstance()->userEmailExists($loginMail)) { + $user = API::getInstance()->getUserByEmail($loginMail); } return $user; diff --git a/plugins/Login/FormLogin.php b/plugins/Login/FormLogin.php index 229288e713..f0f5596fe5 100644 --- a/plugins/Login/FormLogin.php +++ b/plugins/Login/FormLogin.php @@ -6,15 +6,18 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Login + * @package Login */ +namespace Piwik\Plugins\Login; + +use HTML_QuickForm2_DataSource_Array; use Piwik\QuickForm2; /** * - * @package Piwik_Login + * @package Login */ -class Piwik_Login_FormLogin extends QuickForm2 +class FormLogin extends QuickForm2 { function __construct($id = 'login_form', $method = 'post', $attributes = null, $trackSubmit = false) { diff --git a/plugins/Login/FormResetPassword.php b/plugins/Login/FormResetPassword.php index abbe1bd4a1..0f02aaedcf 100644 --- a/plugins/Login/FormResetPassword.php +++ b/plugins/Login/FormResetPassword.php @@ -6,15 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Login + * @package Login */ +namespace Piwik\Plugins\Login; + use Piwik\QuickForm2; /** * - * @package Piwik_Login + * @package Login */ -class Piwik_Login_FormResetPassword extends QuickForm2 +class FormResetPassword extends QuickForm2 { function __construct($id = 'resetpasswordform', $method = 'post', $attributes = null, $trackSubmit = false) { diff --git a/plugins/Login/Login.php b/plugins/Login/Login.php index b1da0954ad..2e511b0a5b 100644 --- a/plugins/Login/Login.php +++ b/plugins/Login/Login.php @@ -6,20 +6,26 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Login + * @package Login */ +namespace Piwik\Plugins\Login; + +use Exception; use Piwik\Config; use Piwik\Piwik; use Piwik\Cookie; use Piwik\Option; +use Piwik\Plugins\Login\Auth; +use Piwik\Plugins\Login\Controller; use Piwik\Session; -use Piwik\Plugin; +use Piwik\Plugins\UsersManager\UsersManager; +use Piwik\Plugins\UsersManager\API; /** * - * @package Piwik_Login + * @package Login */ -class Piwik_Login extends Plugin +class Login extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered @@ -43,7 +49,7 @@ class Piwik_Login extends Plugin { $exceptionMessage = $exception->getMessage(); - $controller = new Piwik_Login_Controller(); + $controller = new Controller(); $controller->login($exceptionMessage, '' /* $exception->getTraceAsString() */); } @@ -63,7 +69,7 @@ class Piwik_Login extends Plugin */ function initAuthenticationObject($allowCookieAuthentication = false) { - $auth = new Piwik_Login_Auth(); + $auth = new Auth(); \Zend_Registry::set('auth', $auth); $action = Piwik::getAction(); @@ -91,7 +97,7 @@ class Piwik_Login extends Plugin /** * Authenticate user and initializes the session. * Listens to Login.initSession hook. - * + * * @throws Exception */ public function initSession($info) @@ -100,7 +106,7 @@ class Piwik_Login extends Plugin $md5Password = $info['md5Password']; $rememberMe = $info['rememberMe']; - $tokenAuth = Piwik_UsersManager_API::getInstance()->getTokenAuth($login, $md5Password); + $tokenAuth = API::getInstance()->getTokenAuth($login, $md5Password); $auth = \Zend_Registry::get('auth'); $auth->setLogin($login); @@ -137,7 +143,7 @@ class Piwik_Login extends Plugin public static function savePasswordResetInfo($login, $password) { $optionName = self::getPasswordResetInfoOptionName($login); - $optionData = Piwik_UsersManager::getPasswordHash($password); + $optionData = UsersManager::getPasswordHash($password); Piwik_SetOption($optionName, $optionData); } diff --git a/plugins/MobileMessaging/API.php b/plugins/MobileMessaging/API.php index 491bb46f86..bb2664ffff 100644 --- a/plugins/MobileMessaging/API.php +++ b/plugins/MobileMessaging/API.php @@ -6,10 +6,15 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_MobileMessaging + * @package MobileMessaging */ +namespace Piwik\Plugins\MobileMessaging; + use Piwik\Piwik; use Piwik\Common; +use Piwik\Plugins\MobileMessaging\MobileMessaging; +use Piwik\Plugins\MobileMessaging\SMSProvider; +use Piwik\Plugins\PDFReports\API as PDFReportsAPI; /** * The MobileMessaging API lets you manage and access all the MobileMessaging plugin features including : @@ -17,9 +22,9 @@ use Piwik\Common; * - activate phone numbers * - check remaining credits * - send SMS - * @package Piwik_MobileMessaging + * @package MobileMessaging */ -class Piwik_MobileMessaging_API +class API { const VERIFICATION_CODE_LENGTH = 5; const SMS_FROM = 'Piwik'; @@ -27,7 +32,7 @@ class Piwik_MobileMessaging_API static private $instance = null; /** - * @return Piwik_MobileMessaging_API + * @return \Piwik\Plugins\MobileMessaging\API */ static public function getInstance() { @@ -39,11 +44,11 @@ class Piwik_MobileMessaging_API /** * @param string $provider - * @return Piwik_MobileMessaging_SMSProvider + * @return SMSProvider */ static private function getSMSProviderInstance($provider) { - return Piwik_MobileMessaging_SMSProvider::factory($provider); + return SMSProvider::factory($provider); } /** @@ -56,17 +61,17 @@ class Piwik_MobileMessaging_API Piwik::checkUserHasSomeViewAccess(); $credential = $this->getSMSAPICredential(); - return isset($credential[Piwik_MobileMessaging::API_KEY_OPTION]); + return isset($credential[MobileMessaging::API_KEY_OPTION]); } private function getSMSAPICredential() { $settings = $this->getCredentialManagerSettings(); return array( - Piwik_MobileMessaging::PROVIDER_OPTION => - isset($settings[Piwik_MobileMessaging::PROVIDER_OPTION]) ? $settings[Piwik_MobileMessaging::PROVIDER_OPTION] : null, - Piwik_MobileMessaging::API_KEY_OPTION => - isset($settings[Piwik_MobileMessaging::API_KEY_OPTION]) ? $settings[Piwik_MobileMessaging::API_KEY_OPTION] : null, + MobileMessaging::PROVIDER_OPTION => + isset($settings[MobileMessaging::PROVIDER_OPTION]) ? $settings[MobileMessaging::PROVIDER_OPTION] : null, + MobileMessaging::API_KEY_OPTION => + isset($settings[MobileMessaging::API_KEY_OPTION]) ? $settings[MobileMessaging::API_KEY_OPTION] : null, ); } @@ -79,7 +84,7 @@ class Piwik_MobileMessaging_API { $this->checkCredentialManagementRights(); $credential = $this->getSMSAPICredential(); - return $credential[Piwik_MobileMessaging::PROVIDER_OPTION]; + return $credential[MobileMessaging::PROVIDER_OPTION]; } /** @@ -99,8 +104,8 @@ class Piwik_MobileMessaging_API $settings = $this->getCredentialManagerSettings(); - $settings[Piwik_MobileMessaging::PROVIDER_OPTION] = $provider; - $settings[Piwik_MobileMessaging::API_KEY_OPTION] = $apiKey; + $settings[MobileMessaging::PROVIDER_OPTION] = $provider; + $settings[MobileMessaging::API_KEY_OPTION] = $apiKey; $this->setCredentialManagerSettings($settings); @@ -140,7 +145,7 @@ class Piwik_MobileMessaging_API $phoneNumbers[$phoneNumber] = $verificationCode; $this->savePhoneNumbers($phoneNumbers); - $this->increaseCount(Piwik_MobileMessaging::PHONE_NUMBER_VALIDATION_REQUEST_COUNT_OPTION, $phoneNumber); + $this->increaseCount(MobileMessaging::PHONE_NUMBER_VALIDATION_REQUEST_COUNT_OPTION, $phoneNumber); return true; } @@ -171,15 +176,15 @@ class Piwik_MobileMessaging_API Piwik::checkUserIsNotAnonymous(); $credential = $this->getSMSAPICredential(); - $SMSProvider = self::getSMSProviderInstance($credential[Piwik_MobileMessaging::PROVIDER_OPTION]); + $SMSProvider = self::getSMSProviderInstance($credential[MobileMessaging::PROVIDER_OPTION]); $SMSProvider->sendSMS( - $credential[Piwik_MobileMessaging::API_KEY_OPTION], + $credential[MobileMessaging::API_KEY_OPTION], $content, $phoneNumber, $from ); - $this->increaseCount(Piwik_MobileMessaging::SMS_SENT_COUNT_OPTION, $phoneNumber); + $this->increaseCount(MobileMessaging::SMS_SENT_COUNT_OPTION, $phoneNumber); return true; } @@ -194,9 +199,9 @@ class Piwik_MobileMessaging_API $this->checkCredentialManagementRights(); $credential = $this->getSMSAPICredential(); - $SMSProvider = self::getSMSProviderInstance($credential[Piwik_MobileMessaging::PROVIDER_OPTION]); + $SMSProvider = self::getSMSProviderInstance($credential[MobileMessaging::PROVIDER_OPTION]); return $SMSProvider->getCreditLeft( - $credential[Piwik_MobileMessaging::API_KEY_OPTION] + $credential[MobileMessaging::API_KEY_OPTION] ); } @@ -216,7 +221,7 @@ class Piwik_MobileMessaging_API $this->savePhoneNumbers($phoneNumbers); // remove phone number from reports - $pdfReportsAPIInstance = Piwik_PDFReports_API::getInstance(); + $pdfReportsAPIInstance = PDFReportsAPI::getInstance(); $reports = $pdfReportsAPIInstance->getReports( $idSite = false, $period = false, @@ -225,9 +230,9 @@ class Piwik_MobileMessaging_API ); foreach ($reports as $report) { - if ($report['type'] == Piwik_MobileMessaging::MOBILE_TYPE) { + if ($report['type'] == MobileMessaging::MOBILE_TYPE) { $reportParameters = $report['parameters']; - $reportPhoneNumbers = $reportParameters[Piwik_MobileMessaging::PHONE_NUMBERS_PARAMETER]; + $reportPhoneNumbers = $reportParameters[MobileMessaging::PHONE_NUMBERS_PARAMETER]; $updatedPhoneNumbers = array(); foreach ($reportPhoneNumbers as $reportPhoneNumber) { if ($reportPhoneNumber != $phoneNumber) { @@ -236,7 +241,7 @@ class Piwik_MobileMessaging_API } if (count($updatedPhoneNumbers) != count($reportPhoneNumbers)) { - $reportParameters[Piwik_MobileMessaging::PHONE_NUMBERS_PARAMETER] = $updatedPhoneNumbers; + $reportParameters[MobileMessaging::PHONE_NUMBERS_PARAMETER] = $updatedPhoneNumbers; // note: reports can end up without any recipients $pdfReportsAPIInstance->updateReport( @@ -262,8 +267,8 @@ class Piwik_MobileMessaging_API $settings = $this->getCurrentUserSettings(); $phoneNumbers = array(); - if (isset($settings[Piwik_MobileMessaging::PHONE_NUMBERS_OPTION])) { - $phoneNumbers = $settings[Piwik_MobileMessaging::PHONE_NUMBERS_OPTION]; + if (isset($settings[MobileMessaging::PHONE_NUMBERS_OPTION])) { + $phoneNumbers = $settings[MobileMessaging::PHONE_NUMBERS_OPTION]; } return $phoneNumbers; @@ -273,7 +278,7 @@ class Piwik_MobileMessaging_API { $settings = $this->getCurrentUserSettings(); - $settings[Piwik_MobileMessaging::PHONE_NUMBERS_OPTION] = $phoneNumbers; + $settings[MobileMessaging::PHONE_NUMBERS_OPTION] = $phoneNumbers; $this->setCurrentUserSettings($settings); } @@ -383,7 +388,7 @@ class Piwik_MobileMessaging_API $settings = $this->getCredentialManagerSettings(); - $settings[Piwik_MobileMessaging::API_KEY_OPTION] = null; + $settings[MobileMessaging::API_KEY_OPTION] = null; $this->setCredentialManagerSettings($settings); @@ -398,7 +403,7 @@ class Piwik_MobileMessaging_API private function setUserSettings($user, $settings) { Piwik_SetOption( - $user . Piwik_MobileMessaging::USER_SETTINGS_POSTFIX_OPTION, + $user . MobileMessaging::USER_SETTINGS_POSTFIX_OPTION, Common::json_encode($settings) ); } @@ -420,7 +425,7 @@ class Piwik_MobileMessaging_API private function getUserSettings($user) { - $optionIndex = $user . Piwik_MobileMessaging::USER_SETTINGS_POSTFIX_OPTION; + $optionIndex = $user . MobileMessaging::USER_SETTINGS_POSTFIX_OPTION; $userSettings = Piwik_GetOption($optionIndex); if (empty($userSettings)) { @@ -450,7 +455,7 @@ class Piwik_MobileMessaging_API public function setDelegatedManagement($delegatedManagement) { Piwik::checkUserIsSuperUser(); - Piwik_SetOption(Piwik_MobileMessaging::DELEGATED_MANAGEMENT_OPTION, $delegatedManagement); + Piwik_SetOption(MobileMessaging::DELEGATED_MANAGEMENT_OPTION, $delegatedManagement); } /** @@ -461,6 +466,6 @@ class Piwik_MobileMessaging_API public function getDelegatedManagement() { Piwik::checkUserHasSomeViewAccess(); - return Piwik_GetOption(Piwik_MobileMessaging::DELEGATED_MANAGEMENT_OPTION) == 'true'; + return Piwik_GetOption(MobileMessaging::DELEGATED_MANAGEMENT_OPTION) == 'true'; } } diff --git a/plugins/MobileMessaging/APIException.php b/plugins/MobileMessaging/APIException.php index d48bb0520a..515d872bf0 100644 --- a/plugins/MobileMessaging/APIException.php +++ b/plugins/MobileMessaging/APIException.php @@ -6,13 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_MobileMessaging + * @package MobileMessaging */ +namespace Piwik\Plugins\MobileMessaging; + +use Exception; + /** - * @package Piwik_MobileMessaging + * @package MobileMessaging */ -class Piwik_MobileMessaging_APIException extends Exception +class APIException extends Exception { } diff --git a/plugins/MobileMessaging/Controller.php b/plugins/MobileMessaging/Controller.php index 0054d62912..7cbf2d3bf2 100644 --- a/plugins/MobileMessaging/Controller.php +++ b/plugins/MobileMessaging/Controller.php @@ -6,22 +6,27 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_MobileMessaging + * @package MobileMessaging */ -use Piwik\Controller\Admin; +namespace Piwik\Plugins\MobileMessaging; + use Piwik\Piwik; use Piwik\Common; use Piwik\IP; +use Piwik\Plugins\LanguagesManager\LanguagesManager; +use Piwik\Plugins\MobileMessaging\API; use Piwik\View; +use Piwik\Plugins\MobileMessaging\CountryCallingCodes; +use Piwik\Plugins\MobileMessaging\SMSProvider; require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/functions.php'; /** * - * @package Piwik_MobileMessaging + * @package MobileMessaging */ -class Piwik_MobileMessaging_Controller extends Admin +class Controller extends \Piwik\Controller\Admin { /* * Mobile Messaging Settings tab : @@ -38,7 +43,7 @@ class Piwik_MobileMessaging_Controller extends Admin $view->isSuperUser = Piwik::isUserIsSuperUser(); - $mobileMessagingAPI = Piwik_MobileMessaging_API::getInstance(); + $mobileMessagingAPI = API::getInstance(); $view->delegatedManagement = $mobileMessagingAPI->getDelegatedManagement(); $view->credentialSupplied = $mobileMessagingAPI->areSMSAPICredentialProvided(); $view->accountManagedByCurrentUser = $view->isSuperUser || $view->delegatedManagement; @@ -48,23 +53,23 @@ class Piwik_MobileMessaging_Controller extends Admin $view->creditLeft = $mobileMessagingAPI->getCreditLeft(); } - $view->smsProviders = Piwik_MobileMessaging_SMSProvider::$availableSMSProviders; + $view->smsProviders = SMSProvider::$availableSMSProviders; // construct the list of countries from the lang files $countries = array(); foreach (Common::getCountriesList() as $countryCode => $continentCode) { - if (isset(Piwik_MobileMessaging_CountryCallingCodes::$countryCallingCodes[$countryCode])) { + if (isset(CountryCallingCodes::$countryCallingCodes[$countryCode])) { $countries[$countryCode] = array( - 'countryName' => Piwik_CountryTranslate($countryCode), - 'countryCallingCode' => Piwik_MobileMessaging_CountryCallingCodes::$countryCallingCodes[$countryCode], + 'countryName' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode), + 'countryCallingCode' => CountryCallingCodes::$countryCallingCodes[$countryCode], ); } } $view->countries = $countries; $view->defaultCountry = Common::getCountry( - Piwik_LanguagesManager::getLanguageCodeForCurrentUser(), + LanguagesManager::getLanguageCodeForCurrentUser(), true, IP::getIpFromHeader() ); diff --git a/plugins/MobileMessaging/CountryCallingCodes.php b/plugins/MobileMessaging/CountryCallingCodes.php index b1097220f8..b98aa180ad 100644 --- a/plugins/MobileMessaging/CountryCallingCodes.php +++ b/plugins/MobileMessaging/CountryCallingCodes.php @@ -6,14 +6,16 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_MobileMessaging + * @package MobileMessaging */ +namespace Piwik\Plugins\MobileMessaging; + /** * - * @package Piwik_MobileMessaging + * @package MobileMessaging */ -class Piwik_MobileMessaging_CountryCallingCodes +class CountryCallingCodes { // list taken from core/DataFiles/Countries.php public static $countryCallingCodes = array( diff --git a/plugins/MobileMessaging/GSMCharset.php b/plugins/MobileMessaging/GSMCharset.php index 4d58c96580..3a8da08290 100644 --- a/plugins/MobileMessaging/GSMCharset.php +++ b/plugins/MobileMessaging/GSMCharset.php @@ -6,15 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_MobileMessaging + * @package MobileMessaging */ +namespace Piwik\Plugins\MobileMessaging; + /** * GSM 03.38 Charset * - * @package Piwik_MobileMessaging + * @package MobileMessaging */ -class Piwik_MobileMessaging_GSMCharset +class GSMCharset { public static $GSMCharset = array( diff --git a/plugins/MobileMessaging/MobileMessaging.php b/plugins/MobileMessaging/MobileMessaging.php index 532e511d73..fecec9de43 100644 --- a/plugins/MobileMessaging/MobileMessaging.php +++ b/plugins/MobileMessaging/MobileMessaging.php @@ -6,17 +6,23 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_MobileMessaging + * @package MobileMessaging */ +namespace Piwik\Plugins\MobileMessaging; + use Piwik\Piwik; +use Piwik\Plugins\MobileMessaging\API as MobileMessagingAPI; use Piwik\View; -use Piwik\Plugin; +use Piwik\Plugins\API\API; +use Piwik\Plugins\MobileMessaging\ReportRenderer\ReportRendererException; +use Piwik\Plugins\MobileMessaging\ReportRenderer\Sms; +use Piwik\Plugins\PDFReports\API as PDFReportsAPI; /** * - * @package Piwik_MobileMessaging + * @package MobileMessaging */ -class Piwik_MobileMessaging extends Plugin +class MobileMessaging extends \Piwik\Plugin { const DELEGATED_MANAGEMENT_OPTION = 'MobileMessaging_DelegatedManagement'; const PROVIDER_OPTION = 'Provider'; @@ -98,12 +104,12 @@ class Piwik_MobileMessaging extends Plugin { $cssFiles[] = "plugins/MobileMessaging/stylesheets/MobileMessagingSettings.less"; } - + public function validateReportParameters(&$parameters, $info) { if (self::manageEvent($info)) { // phone number validation - $availablePhoneNumbers = Piwik_MobileMessaging_API::getInstance()->getActivatedPhoneNumbers(); + $availablePhoneNumbers = MobileMessagingAPI::getInstance()->getActivatedPhoneNumbers(); $phoneNumbers = $parameters[self::PHONE_NUMBERS_PARAMETER]; foreach ($phoneNumbers as $key => $phoneNumber) { @@ -121,10 +127,10 @@ class Piwik_MobileMessaging extends Plugin public function getReportMetadata(&$availableReportMetadata, $notificationInfo) { if (self::manageEvent($notificationInfo)) { - $idSite = $notificationInfo[Piwik_PDFReports_API::ID_SITE_INFO_KEY]; + $idSite = $notificationInfo[PDFReportsAPI::ID_SITE_INFO_KEY]; foreach (self::$availableReports as $availableReport) { - $reportMetadata = Piwik_API_API::getInstance()->getMetadata( + $reportMetadata = API::getInstance()->getMetadata( $idSite, $availableReport['module'], $availableReport['action'] @@ -161,9 +167,9 @@ class Piwik_MobileMessaging extends Plugin { if (self::manageEvent($info)) { if (\Piwik\PluginsManager::getInstance()->isPluginActivated('MultiSites')) { - $reportRenderer = new Piwik_MobileMessaging_ReportRenderer_Sms(); + $reportRenderer = new Sms(); } else { - $reportRenderer = new Piwik_MobileMessaging_ReportRenderer_Exception( + $reportRenderer = new ReportRendererException( Piwik_Translate('MobileMessaging_MultiSites_Must_Be_Activated') ); } @@ -180,7 +186,7 @@ class Piwik_MobileMessaging extends Plugin public function getReportRecipients(&$recipients, $notificationInfo) { if (self::manageEvent($notificationInfo)) { - $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; + $report = $notificationInfo[PDFReportsAPI::REPORT_KEY]; $recipients = $report['parameters'][self::PHONE_NUMBERS_PARAMETER]; } } @@ -188,9 +194,9 @@ class Piwik_MobileMessaging extends Plugin public function sendReport($notificationInfo) { if (self::manageEvent($notificationInfo)) { - $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; - $contents = $notificationInfo[Piwik_PDFReports_API::REPORT_CONTENT_KEY]; - $reportSubject = $notificationInfo[Piwik_PDFReports_API::REPORT_SUBJECT_KEY]; + $report = $notificationInfo[PDFReportsAPI::REPORT_KEY]; + $contents = $notificationInfo[PDFReportsAPI::REPORT_CONTENT_KEY]; + $reportSubject = $notificationInfo[PDFReportsAPI::REPORT_SUBJECT_KEY]; $parameters = $report['parameters']; $phoneNumbers = $parameters[self::PHONE_NUMBERS_PARAMETER]; @@ -200,7 +206,7 @@ class Piwik_MobileMessaging extends Plugin $reportSubject = Piwik_Translate('General_Reports'); } - $mobileMessagingAPI = Piwik_MobileMessaging_API::getInstance(); + $mobileMessagingAPI = MobileMessagingAPI::getInstance(); foreach ($phoneNumbers as $phoneNumber) { $mobileMessagingAPI->sendSMS( $contents, @@ -219,13 +225,13 @@ class Piwik_MobileMessaging extends Plugin $view = new View('@MobileMessaging/reportParametersPDFReports'); $view->reportType = self::MOBILE_TYPE; - $view->phoneNumbers = Piwik_MobileMessaging_API::getInstance()->getActivatedPhoneNumbers(); + $view->phoneNumbers = MobileMessagingAPI::getInstance()->getActivatedPhoneNumbers(); $out .= $view->render(); } private static function manageEvent($notificationInfo) { - return in_array($notificationInfo[Piwik_PDFReports_API::REPORT_TYPE_INFO_KEY], array_keys(self::$managedReportTypes)); + return in_array($notificationInfo[PDFReportsAPI::REPORT_TYPE_INFO_KEY], array_keys(self::$managedReportTypes)); } function install() @@ -239,11 +245,11 @@ class Piwik_MobileMessaging extends Plugin function deactivate() { // delete all mobile reports - $pdfReportsAPIInstance = Piwik_PDFReports_API::getInstance(); + $pdfReportsAPIInstance = PDFReportsAPI::getInstance(); $reports = $pdfReportsAPIInstance->getReports(); foreach ($reports as $report) { - if ($report['type'] == Piwik_MobileMessaging::MOBILE_TYPE) { + if ($report['type'] == MobileMessaging::MOBILE_TYPE) { $pdfReportsAPIInstance->deleteReport($report['idreport']); } } diff --git a/plugins/MobileMessaging/ReportRenderer/Exception.php b/plugins/MobileMessaging/ReportRenderer/ReportRendererException.php index cc5b137a38..338dce98f6 100644 --- a/plugins/MobileMessaging/ReportRenderer/Exception.php +++ b/plugins/MobileMessaging/ReportRenderer/ReportRendererException.php @@ -8,13 +8,16 @@ * @category Piwik_Plugins * @package Piwik_MobileMessaging_ReportRenderer */ +namespace Piwik\Plugins\MobileMessaging\ReportRenderer; + use Piwik\ReportRenderer; +use Piwik\Plugins\MobileMessaging\ReportRenderer\Sms; /** * * @package Piwik_MobileMessaging_ReportRenderer */ -class Piwik_MobileMessaging_ReportRenderer_Exception extends ReportRenderer +class ReportRendererException extends ReportRenderer { private $rendering = ""; @@ -32,7 +35,7 @@ class Piwik_MobileMessaging_ReportRenderer_Exception extends ReportRenderer { return ReportRenderer::writeFile( $filename, - Piwik_MobileMessaging_ReportRenderer_Sms::SMS_FILE_EXTENSION, + Sms::SMS_FILE_EXTENSION, $this->rendering ); } @@ -41,8 +44,8 @@ class Piwik_MobileMessaging_ReportRenderer_Exception extends ReportRenderer { ReportRenderer::sendToBrowser( $filename, - Piwik_MobileMessaging_ReportRenderer_Sms::SMS_FILE_EXTENSION, - Piwik_MobileMessaging_ReportRenderer_Sms::SMS_CONTENT_TYPE, + Sms::SMS_FILE_EXTENSION, + Sms::SMS_CONTENT_TYPE, $this->rendering ); } @@ -50,7 +53,7 @@ class Piwik_MobileMessaging_ReportRenderer_Exception extends ReportRenderer public function sendToBrowserInline($filename) { ReportRenderer::inlineToBrowser( - Piwik_MobileMessaging_ReportRenderer_Sms::SMS_CONTENT_TYPE, + Sms::SMS_CONTENT_TYPE, $this->rendering ); } diff --git a/plugins/MobileMessaging/ReportRenderer/Sms.php b/plugins/MobileMessaging/ReportRenderer/Sms.php index 5c89166ea2..6d7abbf71c 100644 --- a/plugins/MobileMessaging/ReportRenderer/Sms.php +++ b/plugins/MobileMessaging/ReportRenderer/Sms.php @@ -8,7 +8,10 @@ * @category Piwik_Plugins * @package Piwik_MobileMessaging_ReportRenderer */ +namespace Piwik\Plugins\MobileMessaging\ReportRenderer; + use Piwik\Common; +use Piwik\Plugins\MultiSites\API; use Piwik\View; use Piwik\ReportRenderer; use Piwik\Site; @@ -17,7 +20,7 @@ use Piwik\Site; * * @package Piwik_MobileMessaging_ReportRenderer */ -class Piwik_MobileMessaging_ReportRenderer_Sms extends ReportRenderer +class Sms extends ReportRenderer { const FLOAT_REGEXP = '/[-+]?[0-9]*[\.,]?[0-9]+/'; const SMS_CONTENT_TYPE = 'text/plain'; @@ -62,9 +65,9 @@ class Piwik_MobileMessaging_ReportRenderer_Sms extends ReportRenderer $reportData = $processedReport['reportData']; $evolutionMetrics = array(); - $multiSitesAPIMetrics = Piwik_MultiSites_API::getApiMetrics($enhanced = true); + $multiSitesAPIMetrics = API::getApiMetrics($enhanced = true); foreach ($multiSitesAPIMetrics as $metricSettings) { - $evolutionMetrics[] = $metricSettings[Piwik_MultiSites_API::METRIC_EVOLUTION_COL_NAME_KEY]; + $evolutionMetrics[] = $metricSettings[API::METRIC_EVOLUTION_COL_NAME_KEY]; } // no decimal for all metrics to shorten SMS content (keeps the monetary sign for revenue metrics) diff --git a/plugins/MobileMessaging/SMSProvider.php b/plugins/MobileMessaging/SMSProvider.php index 402c135b48..7a9c36bb77 100644 --- a/plugins/MobileMessaging/SMSProvider.php +++ b/plugins/MobileMessaging/SMSProvider.php @@ -6,17 +6,21 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_MobileMessaging + * @package MobileMessaging */ +namespace Piwik\Plugins\MobileMessaging; + +use Exception; use Piwik\Loader; +use Piwik\Plugins\MobileMessaging\GSMCharset; /** - * The Piwik_MobileMessaging_SMSProvider abstract class is used as a base class for SMS provider implementations. + * The SMSProvider abstract class is used as a base class for SMS provider implementations. * - * @package Piwik_MobileMessaging - * @subpackage Piwik_MobileMessaging_SMSProvider + * @package MobileMessaging + * @subpackage SMSProvider */ -abstract class Piwik_MobileMessaging_SMSProvider +abstract class SMSProvider { const MAX_GSM_CHARS_IN_ONE_UNIQUE_SMS = 160; const MAX_GSM_CHARS_IN_ONE_CONCATENATED_SMS = 153; @@ -26,11 +30,11 @@ abstract class Piwik_MobileMessaging_SMSProvider static public $availableSMSProviders = array( 'Clockwork' => 'You can use <a target="_blank" href="?module=Proxy&action=redirect&url=http://www.clockworksms.com/platforms/piwik/"><img src="plugins/MobileMessaging/images/Clockwork.png"/></a> to send SMS Reports from Piwik.<br/> <ul> - <li> First, <a target="_blank" href="?module=Proxy&action=redirect&url=http://www.clockworksms.com/platforms/piwik/">get an API Key from Clockwork</a> (Signup is free!) + <li> First, <a target="_blank" href="?module=Proxy&action=redirect&url=http://www.clockworksms.com/platforms/piwik/">get an API Key from Clockwork</a> (Signup is free!) </li><li> Enter your Clockwork API Key on this page. </li> </ul> <br/><i>About Clockwork: </i><ul> - <li>Clockwork gives you fast, reliable high quality worldwide SMS delivery, over 450 networks in every corner of the globe. + <li>Clockwork gives you fast, reliable high quality worldwide SMS delivery, over 450 networks in every corner of the globe. </li><li>Cost per SMS message is around ~0.08USD (0.06EUR). </li><li>Most countries and networks are supported but we suggest you check the latest position on their coverage map <a target="_blank" href="?module=Proxy&action=redirect&url=http://www.clockworksms.com/sms-coverage/">here</a>. </li> @@ -41,13 +45,13 @@ abstract class Piwik_MobileMessaging_SMSProvider /** * Return the SMSProvider associated to the provider name $providerName * - * @throws exception If the provider is unknown + * @throws Exception If the provider is unknown * @param string $providerName - * @return Piwik_MobileMessaging_SMSProvider + * @return \Piwik\Plugins\MobileMessaging\SMSProvider */ static public function factory($providerName) { - $className = 'Piwik_MobileMessaging_SMSProvider_' . $providerName; + $className = __NAMESPACE__ . '\\SMSProvider\\' . $providerName; try { Loader::loadClass($className); @@ -70,7 +74,7 @@ abstract class Piwik_MobileMessaging_SMSProvider */ static public function containsUCS2Characters($string) { - $GSMCharsetAsString = implode(array_keys(Piwik_MobileMessaging_GSMCharset::$GSMCharset)); + $GSMCharsetAsString = implode(array_keys(GSMCharset::$GSMCharset)); foreach (self::mb_str_split($string) as $char) { if (mb_strpos($GSMCharsetAsString, $char) === false) { @@ -128,7 +132,7 @@ abstract class Piwik_MobileMessaging_SMSProvider $sizeOfSMSContent = 0; foreach (self::mb_str_split($smsContent) as $char) { - $sizeOfSMSContent += Piwik_MobileMessaging_GSMCharset::$GSMCharset[$char]; + $sizeOfSMSContent += GSMCharset::$GSMCharset[$char]; } return $sizeOfSMSContent; } diff --git a/plugins/MobileMessaging/SMSProvider/Clockwork.php b/plugins/MobileMessaging/SMSProvider/Clockwork.php index 29a153c6da..da0b07ba1e 100644 --- a/plugins/MobileMessaging/SMSProvider/Clockwork.php +++ b/plugins/MobileMessaging/SMSProvider/Clockwork.php @@ -6,17 +6,22 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_MobileMessaging_SMSProvider + * @package SMSProvider */ +namespace Piwik\Plugins\MobileMessaging\SMSProvider; + +use Exception; use Piwik\Http; +use Piwik\Plugins\MobileMessaging\APIException; +use Piwik\Plugins\MobileMessaging\SMSProvider; require_once PIWIK_INCLUDE_PATH . "/plugins/MobileMessaging/APIException.php"; /** * - * @package Piwik_MobileMessaging_SMSProvider + * @package SMSProvider */ -class Piwik_MobileMessaging_SMSProvider_Clockwork extends Piwik_MobileMessaging_SMSProvider +class Clockwork extends SMSProvider { const SOCKET_TIMEOUT = 15; @@ -83,12 +88,12 @@ class Piwik_MobileMessaging_SMSProvider_Clockwork extends Piwik_MobileMessaging_ $acceptLanguage = false, $acceptInvalidSslCertificate = true ); - } catch(Exception $e) { + } catch (Exception $e) { $result = self::ERROR_STRING . " " . $e->getMessage(); } if (strpos($result, self::ERROR_STRING) !== false) { - throw new Piwik_MobileMessaging_APIException( + throw new APIException( 'Clockwork API returned the following error message : ' . $result ); } diff --git a/plugins/MobileMessaging/SMSProvider/StubbedProvider.php b/plugins/MobileMessaging/SMSProvider/StubbedProvider.php index 8402eefc51..33a4339f8b 100644 --- a/plugins/MobileMessaging/SMSProvider/StubbedProvider.php +++ b/plugins/MobileMessaging/SMSProvider/StubbedProvider.php @@ -6,15 +6,18 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_MobileMessaging_SMSProvider + * @package SMSProvider */ +namespace Piwik\Plugins\MobileMessaging\SMSProvider; + +use Piwik\Plugins\MobileMessaging\SMSProvider; /** * Used for testing * - * @package Piwik_MobileMessaging_SMSProvider + * @package SMSProvider */ -class Piwik_MobileMessaging_SMSProvider_StubbedProvider extends Piwik_MobileMessaging_SMSProvider +class StubbedProvider extends SMSProvider { public function verifyCredential($apiKey) diff --git a/plugins/MultiSites/API.php b/plugins/MultiSites/API.php index dbaf64e0a4..6b2381c0d5 100755 --- a/plugins/MultiSites/API.php +++ b/plugins/MultiSites/API.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_MultiSites + * @package MultiSites */ +namespace Piwik\Plugins\MultiSites; + +use Exception; use Piwik\API\Request; use Piwik\Archive; use Piwik\DataTable\Filter\CalculateEvolutionFilter; @@ -15,13 +18,15 @@ use Piwik\Period\Range; use Piwik\Piwik; use Piwik\Common; use Piwik\DataTable; +use Piwik\Plugins\Goals\Archiver; use Piwik\TaskScheduler; use Piwik\Site; +use Piwik\Plugins\SitesManager\API as SitesManagerAPI; /** * The MultiSites API lets you request the key metrics (visits, page views, revenue) for all Websites in Piwik. */ -class Piwik_MultiSites_API +class API { const METRIC_TRANSLATION_KEY = 'translation'; const METRIC_EVOLUTION_COL_NAME_KEY = 'evolution_column_name'; @@ -67,7 +72,7 @@ class Piwik_MultiSites_API * Returns the singleton instance of this class. The instance is created * if it hasn't been already. * - * @return Piwik_MultiSites_API + * @return \Piwik\Plugins\MultiSites\API */ static public function getInstance() { @@ -107,7 +112,7 @@ class Piwik_MultiSites_API $idSites = $this->getSitesIdFromPattern($pattern); - if(empty($idSites)) { + if (empty($idSites)) { return new DataTable(); } return $this->buildDataTable( @@ -130,7 +135,7 @@ class Piwik_MultiSites_API private function getSitesIdFromPattern($pattern) { $idSites = 'all'; - if(empty($pattern)) { + if (empty($pattern)) { return $idSites; } $idSites = array(); @@ -185,11 +190,11 @@ class Piwik_MultiSites_API && !TaskScheduler::isTaskBeingExecuted() ) { Site::setSites( - Piwik_SitesManager_API::getInstance()->getAllSites() + SitesManagerAPI::getInstance()->getAllSites() ); } else { Site::setSitesFromArray( - Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess($limit = false, $_restrictSitesToLogin) + SitesManagerAPI::getInstance()->getSitesWithAtLeastViewAccess($limit = false, $_restrictSitesToLogin) ); } } @@ -207,7 +212,7 @@ class Piwik_MultiSites_API $fieldsToGet = array(); $columnNameRewrites = array(); $apiECommerceMetrics = array(); - $apiMetrics = Piwik_MultiSites_API::getApiMetrics($enhanced); + $apiMetrics = API::getApiMetrics($enhanced); foreach ($apiMetrics as $metricName => $metricSettings) { $fieldsToGet[] = $metricSettings[self::METRIC_RECORD_NAME_KEY]; $columnNameRewrites[$metricSettings[self::METRIC_RECORD_NAME_KEY]] = $metricName; @@ -231,7 +236,7 @@ class Piwik_MultiSites_API && $dataTable->getRowsCount() > 0 ) { $firstSite = is_array($sites) ? reset($sites) : $sites; - + $firstDataTableRow = $dataTable->getFirstRow(); $firstDataTableRow->setColumn('label', $firstSite); } @@ -252,7 +257,7 @@ class Piwik_MultiSites_API } $pastArchive = Archive::build($sites, $period, $strLastDate, $segment, $_restrictSitesToLogin); $pastData = $pastArchive->getDataTableFromNumeric($fieldsToGet); - + if ($pastData instanceof DataTable\Map && $multipleWebsitesRequested ) { @@ -302,8 +307,9 @@ class Piwik_MultiSites_API // note: if only one website is queried and there are no visits, we can not remove the row otherwise // ResponseBuilder throws 'Call to a member function getColumns() on a non-object' if ($multipleWebsitesRequested - // We don't delete the 0 visits row, if "Enhanced" mode is on. - && !$enhanced) { + // We don't delete the 0 visits row, if "Enhanced" mode is on. + && !$enhanced + ) { $dataTable->filter( 'ColumnCallbackDeleteRow', array( @@ -329,10 +335,10 @@ class Piwik_MultiSites_API private function calculateEvolutionPercentages($currentData, $pastData, $apiMetrics) { if (get_class($currentData) != get_class($pastData)) { // sanity check for regressions - throw new Exception("Expected \$pastData to be of type ".get_class($currentData)." - got " - . get_class($pastData)."."); + throw new Exception("Expected \$pastData to be of type " . get_class($currentData) . " - got " + . get_class($pastData) . "."); } - + if ($currentData instanceof DataTable\Map) { $pastArray = $pastData->getArray(); foreach ($currentData->getArray() as $subTable) { @@ -370,7 +376,7 @@ class Piwik_MultiSites_API } else { $revenueMetric = ''; if (Common::isGoalPluginEnabled()) { - $revenueMetric = Piwik_Goals_Archiver::getRecordName(self::GOAL_REVENUE_METRIC); + $revenueMetric = Archiver::getRecordName(self::GOAL_REVENUE_METRIC); } $totals = array(); @@ -442,7 +448,7 @@ class Piwik_MultiSites_API $metrics[self::GOAL_REVENUE_METRIC] = array( self::METRIC_TRANSLATION_KEY => 'Goals_ColumnRevenue', self::METRIC_EVOLUTION_COL_NAME_KEY => self::GOAL_REVENUE_METRIC . '_evolution', - self::METRIC_RECORD_NAME_KEY => Piwik_Goals_Archiver::getRecordName(self::GOAL_REVENUE_METRIC), + self::METRIC_RECORD_NAME_KEY => Archiver::getRecordName(self::GOAL_REVENUE_METRIC), self::METRIC_IS_ECOMMERCE_KEY => false, ); @@ -451,7 +457,7 @@ class Piwik_MultiSites_API $metrics[self::GOAL_CONVERSION_METRIC] = array( self::METRIC_TRANSLATION_KEY => 'Goals_ColumnConversions', self::METRIC_EVOLUTION_COL_NAME_KEY => self::GOAL_CONVERSION_METRIC . '_evolution', - self::METRIC_RECORD_NAME_KEY => Piwik_Goals_Archiver::getRecordName(self::GOAL_CONVERSION_METRIC), + self::METRIC_RECORD_NAME_KEY => Archiver::getRecordName(self::GOAL_CONVERSION_METRIC), self::METRIC_IS_ECOMMERCE_KEY => false, ); @@ -459,7 +465,7 @@ class Piwik_MultiSites_API $metrics[self::ECOMMERCE_ORDERS_METRIC] = array( self::METRIC_TRANSLATION_KEY => 'General_EcommerceOrders', self::METRIC_EVOLUTION_COL_NAME_KEY => self::ECOMMERCE_ORDERS_METRIC . '_evolution', - self::METRIC_RECORD_NAME_KEY => Piwik_Goals_Archiver::getRecordName(self::GOAL_CONVERSION_METRIC, 0), + self::METRIC_RECORD_NAME_KEY => Archiver::getRecordName(self::GOAL_CONVERSION_METRIC, 0), self::METRIC_IS_ECOMMERCE_KEY => true, ); @@ -467,7 +473,7 @@ class Piwik_MultiSites_API $metrics[self::ECOMMERCE_REVENUE_METRIC] = array( self::METRIC_TRANSLATION_KEY => 'General_ProductRevenue', self::METRIC_EVOLUTION_COL_NAME_KEY => self::ECOMMERCE_REVENUE_METRIC . '_evolution', - self::METRIC_RECORD_NAME_KEY => Piwik_Goals_Archiver::getRecordName(self::GOAL_REVENUE_METRIC, 0), + self::METRIC_RECORD_NAME_KEY => Archiver::getRecordName(self::GOAL_REVENUE_METRIC, 0), self::METRIC_IS_ECOMMERCE_KEY => true, ); } diff --git a/plugins/MultiSites/Controller.php b/plugins/MultiSites/Controller.php index b57f90b020..56ed2351d4 100644 --- a/plugins/MultiSites/Controller.php +++ b/plugins/MultiSites/Controller.php @@ -6,22 +6,25 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_MultiSites + * @package MultiSites */ +namespace Piwik\Plugins\MultiSites; + use Piwik\Period; use Piwik\Piwik; use Piwik\Common; use Piwik\Config; use Piwik\Date; -use Piwik\Controller; +use Piwik\Plugins\MultiSites\API as MultiSitesAPI; use Piwik\View; use Piwik\Site; +use Piwik\Plugins\SitesManager\API as SitesManagerAPI; /** * - * @package Piwik_MultiSites + * @package MultiSites */ -class Piwik_MultiSites_Controller extends Controller +class Controller extends \Piwik\Controller { protected $orderBy = 'visits'; protected $order = 'desc'; @@ -48,7 +51,6 @@ class Piwik_MultiSites_Controller extends Controller $this->getSitesInfo($isWidgetized = true); } - public function getSitesInfo($isWidgetized = false) { Piwik::checkUserHasSomeViewAccess(); @@ -56,20 +58,19 @@ class Piwik_MultiSites_Controller extends Controller $date = Common::getRequestVar('date', 'today'); $period = Common::getRequestVar('period', 'day'); - $siteIds = Piwik_SitesManager_API::getInstance()->getSitesIdWithAtLeastViewAccess(); + $siteIds = SitesManagerAPI::getInstance()->getSitesIdWithAtLeastViewAccess(); list($minDate, $maxDate) = $this->getMinMaxDateAcrossWebsites($siteIds); // overwrites the default Date set in the parent controller // Instead of the default current website's local date, // we set "today" or "yesterday" based on the default Piwik timezone - $piwikDefaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone(); + $piwikDefaultTimezone = SitesManagerAPI::getInstance()->getDefaultTimezone(); if ($period != 'range') { $date = $this->getDateParameterInTimezone($date, $piwikDefaultTimezone); $this->setDate($date); $date = $date->toString(); } - $dataTable = Piwik_MultiSites_API::getInstance()->getAll($period, $date, $segment = false); - + $dataTable = MultiSitesAPI::getInstance()->getAll($period, $date, $segment = false); // put data into a form the template will understand better $digestableData = array(); diff --git a/plugins/MultiSites/MultiSites.php b/plugins/MultiSites/MultiSites.php index 96f14fabce..fab4cd498e 100644 --- a/plugins/MultiSites/MultiSites.php +++ b/plugins/MultiSites/MultiSites.php @@ -6,15 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_MultiSites + * @package MultiSites */ -use Piwik\Plugin; +namespace Piwik\Plugins\MultiSites; + +use Piwik\Plugins\MultiSites\API; /** * - * @package Piwik_MultiSites + * @package MultiSites */ -class Piwik_MultiSites extends Plugin +class MultiSites extends \Piwik\Plugin { public function getInformation() { @@ -40,11 +42,11 @@ class Piwik_MultiSites extends Plugin public function getReportMetadata(&$reports) { $metadataMetrics = array(); - foreach (Piwik_MultiSites_API::getApiMetrics($enhanced = true) as $metricName => $metricSettings) { + foreach (API::getApiMetrics($enhanced = true) as $metricName => $metricSettings) { $metadataMetrics[$metricName] = - Piwik_Translate($metricSettings[Piwik_MultiSites_API::METRIC_TRANSLATION_KEY]); - $metadataMetrics[$metricSettings[Piwik_MultiSites_API::METRIC_EVOLUTION_COL_NAME_KEY]] = - Piwik_Translate($metricSettings[Piwik_MultiSites_API::METRIC_TRANSLATION_KEY]) . " " . Piwik_Translate('MultiSites_Evolution'); + Piwik_Translate($metricSettings[API::METRIC_TRANSLATION_KEY]); + $metadataMetrics[$metricSettings[API::METRIC_EVOLUTION_COL_NAME_KEY]] = + Piwik_Translate($metricSettings[API::METRIC_TRANSLATION_KEY]) . " " . Piwik_Translate('MultiSites_Evolution'); } $reports[] = array( diff --git a/plugins/Overlay/API.php b/plugins/Overlay/API.php index 35e7c681e4..d065b92369 100644 --- a/plugins/Overlay/API.php +++ b/plugins/Overlay/API.php @@ -1,10 +1,4 @@ <?php -use Piwik\Config; -use Piwik\Piwik; -use Piwik\Access; -use Piwik\DataTable; -use Piwik\Tracker\Action; - /** * Piwik - Open source web analytics * @@ -12,17 +6,29 @@ use Piwik\Tracker\Action; * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Overlay + * @package Overlay */ +namespace Piwik\Plugins\Overlay; + +use Exception; +use Piwik\Config; +use Piwik\Piwik; +use Piwik\Access; +use Piwik\DataTable; +use Piwik\Tracker\Action; +use Piwik\Plugins\SitesManager\SitesManager; +use Piwik\Plugins\SitesManager\API as SitesManagerAPI; +use Piwik\Plugins\Transitions\API as TransitionsAPI; + -class Piwik_Overlay_API +class API { private static $instance = null; /** * Get Singleton instance - * @return Piwik_Overlay_API + * @return \Piwik\Plugins\Overlay\API */ public static function getInstance() { @@ -57,11 +63,11 @@ class Piwik_Overlay_API { $this->authenticate($idSite); - $sitesManager = Piwik_SitesManager_API::getInstance(); + $sitesManager = SitesManagerAPI::getInstance(); $site = $sitesManager->getSiteFromId($idSite); try { - return Piwik_SitesManager::getTrackerExcludedQueryParameters($site); + return SitesManager::getTrackerExcludedQueryParameters($site); } catch (Exception $e) { // an exception is thrown when the user has no view access. // do not throw the exception to the outside. @@ -87,7 +93,7 @@ class Piwik_Overlay_API try { $limitBeforeGrouping = Config::getInstance()->General['overlay_following_pages_limit']; - $transitionsReport = Piwik_Transitions_API::getInstance()->getTransitionsForAction( + $transitionsReport = TransitionsAPI::getInstance()->getTransitionsForAction( $url, $type = 'url', $idSite, $period, $date, $segment, $limitBeforeGrouping, $part = 'followingActions', $returnNormalizedUrls = true); } catch (Exception $e) { @@ -124,5 +130,4 @@ class Piwik_Overlay_API Piwik::checkUserHasViewAccess($idSite); } - } diff --git a/plugins/Overlay/Controller.php b/plugins/Overlay/Controller.php index 2efcfd7057..3721c9b226 100644 --- a/plugins/Overlay/Controller.php +++ b/plugins/Overlay/Controller.php @@ -1,13 +1,4 @@ <?php -use Piwik\API\Request; -use Piwik\Metrics; -use Piwik\Piwik; -use Piwik\Config; -use Piwik\Common; -use Piwik\Controller; -use Piwik\Tracker\Action; -use Piwik\View; - /** * Piwik - Open source web analytics * @@ -15,10 +6,21 @@ use Piwik\View; * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Overlay + * @package Overlay */ +namespace Piwik\Plugins\Overlay; -class Piwik_Overlay_Controller extends Controller +use Piwik\API\Request; +use Piwik\Metrics; +use Piwik\Piwik; +use Piwik\Config; +use Piwik\Common; +use Piwik\Plugins\Actions\ArchivingHelper; +use Piwik\Tracker\Action; +use Piwik\View; +use Piwik\Plugins\SitesManager\API; + +class Controller extends \Piwik\Controller { /** The index of the plugin */ @@ -57,8 +59,8 @@ class Piwik_Overlay_Controller extends Controller $normalizedCurrentUrl = Common::unsanitizeInputValue($normalizedCurrentUrl); // load the appropriate row of the page urls report using the label filter - Piwik_Actions_ArchivingHelper::reloadConfig(); - $path = Piwik_Actions_ArchivingHelper::getActionExplodedNames($normalizedCurrentUrl, Action::TYPE_ACTION_URL); + ArchivingHelper::reloadConfig(); + $path = ArchivingHelper::getActionExplodedNames($normalizedCurrentUrl, Action::TYPE_ACTION_URL); $path = array_map('urlencode', $path); $label = implode('>', $path); $request = new Request( @@ -79,7 +81,6 @@ class Piwik_Overlay_Controller extends Controller $showMetrics = array('nb_hits', 'nb_visits', 'nb_uniq_visitors', 'bounce_rate', 'exit_rate', 'avg_time_on_page'); - foreach ($showMetrics as $metric) { $value = $row->getColumn($metric); if ($value === false) { @@ -127,7 +128,7 @@ class Piwik_Overlay_Controller extends Controller $idSite = Common::getRequestVar('idsite', 0, 'int'); Piwik::checkUserHasViewAccess($idSite); - $sitesManager = Piwik_SitesManager_API::getInstance(); + $sitesManager = API::getInstance(); $site = $sitesManager->getSiteFromId($idSite); $urls = $sitesManager->getSiteUrlsFromId($idSite); @@ -142,17 +143,17 @@ class Piwik_Overlay_Controller extends Controller return url.replace(/https:\/\//i, "http://"); } } - + function removeUrlPrefix(url) { return url.replace(/http(s)?:\/\/(www\.)?/i, ""); } - + if (window.location.hash) { var match = false; - + var urlToRedirect = window.location.hash.substr(1); var urlToRedirectWithoutPrefix = removeUrlPrefix(urlToRedirect); - + var knownUrls = ' . Common::json_encode($urls) . '; for (var i = 0; i < knownUrls.length; i++) { var testUrl = removeUrlPrefix(knownUrls[i]); @@ -170,12 +171,12 @@ class Piwik_Overlay_Controller extends Controller break; } } - + if (!match) { var idSite = window.location.href.match(/idSite=([0-9]+)/i)[1]; window.location.href = "index.php?module=Overlay&action=showErrorWrongDomain" + "&idSite=" + idSite - + "&url=" + encodeURIComponent(urlToRedirect); + + "&url=" + encodeURIComponent(urlToRedirect); } } else { @@ -231,5 +232,4 @@ class Piwik_Overlay_Controller extends Controller $view = new View('@Overlay/notifyParentIframe'); echo $view->render(); } - } diff --git a/plugins/Overlay/Overlay.php b/plugins/Overlay/Overlay.php index 72a08d5046..b0ba9a2c7b 100644 --- a/plugins/Overlay/Overlay.php +++ b/plugins/Overlay/Overlay.php @@ -6,12 +6,13 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Overlay + * @package Overlay */ -use Piwik\Plugin; +namespace Piwik\Plugins\Overlay; -class Piwik_Overlay extends Plugin + +class Overlay extends \Piwik\Plugin { public function getInformation() { diff --git a/plugins/PDFReports/API.php b/plugins/PDFReports/API.php index 716687866b..708dd64ccb 100644 --- a/plugins/PDFReports/API.php +++ b/plugins/PDFReports/API.php @@ -6,16 +6,22 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_PDFReports + * @package PDFReports */ +namespace Piwik\Plugins\PDFReports; + +use Exception; use Piwik\Piwik; use Piwik\Common; use Piwik\Date; +use Piwik\Plugins\LanguagesManager\LanguagesManager; use Piwik\ReportRenderer; use Piwik\ReportRenderer\Html; use Piwik\Site; use Piwik\Translate; use Piwik\Db; +use Piwik\Plugins\SegmentEditor\API as SegmentEditorAPI; +use Zend_Mime; /** * The PDFReports API lets you manage Scheduled Email reports, as well as generate, download or email any existing report. @@ -27,9 +33,9 @@ use Piwik\Db; * or manage existing reports with "updateReport" and "deleteReport". * See also the documentation about <a href='http://piwik.org/docs/email-reports/' target='_blank'>Scheduled Email reports</a> in Piwik. * - * @package Piwik_PDFReports + * @package PDFReports */ -class Piwik_PDFReports_API +class API { const VALIDATE_PARAMETERS_EVENT = 'PDFReports.validateReportParameters'; const GET_REPORT_PARAMETERS_EVENT = 'PDFReports.getReportParameters'; @@ -63,7 +69,7 @@ class Piwik_PDFReports_API static private $instance = null; /** - * @return Piwik_PDFReports_API + * @return \Piwik\Plugins\PDFReports\API */ static public function getInstance() { @@ -133,9 +139,9 @@ class Piwik_PDFReports_API private static function ensureLanguageSetForUser($currentUser) { - $lang = Piwik_LanguagesManager_API::getInstance()->getLanguageForUser($currentUser); + $lang = \Piwik\Plugins\LanguagesManager\API::getInstance()->getLanguageForUser($currentUser); if (empty($lang)) { - Piwik_LanguagesManager_API::getInstance()->setLanguageForUser($currentUser, Piwik_LanguagesManager::getLanguageCodeForCurrentUser()); + \Piwik\Plugins\LanguagesManager\API::getInstance()->setLanguageForUser($currentUser, LanguagesManager::getLanguageCodeForCurrentUser()); } } @@ -330,7 +336,7 @@ class Piwik_PDFReports_API ); // available reports - $availableReportMetadata = Piwik_API_API::getInstance()->getReportMetadata($idSite); + $availableReportMetadata = \Piwik\Plugins\API\API::getInstance()->getReportMetadata($idSite); // we need to lookup which reports metadata are registered in this report $reportMetadata = array(); @@ -377,7 +383,7 @@ class Piwik_PDFReports_API } } - $processedReport = Piwik_API_API::getInstance()->getProcessedReport( + $processedReport = \Piwik\Plugins\API\API::getInstance()->getProcessedReport( $idSite, $period, $date, $apiModule, $apiAction, $segment != null ? urlencode($segment['definition']) : false, $apiParameters, $idGoal = false, $language @@ -504,7 +510,7 @@ class Piwik_PDFReports_API $date = Date::now()->subPeriod(1, $report['period'])->toString(); } - $language = Piwik_LanguagesManager_API::getInstance()->getLanguageForUser($report['login']); + $language = \Piwik\Plugins\LanguagesManager\API::getInstance()->getLanguageForUser($report['login']); // generate report list($outputFilename, $prettyDate, $reportSubject, $reportTitle, $additionalFiles) = @@ -528,16 +534,16 @@ class Piwik_PDFReports_API Piwik_PostEvent( self::SEND_REPORT_EVENT, array( - $notificationInfo = array( - self::REPORT_TYPE_INFO_KEY => $report['type'], - self::REPORT_KEY => $report, - self::REPORT_CONTENT_KEY => $contents, - self::FILENAME_KEY => $filename, - self::PRETTY_DATE_KEY => $prettyDate, - self::REPORT_SUBJECT_KEY => $reportSubject, - self::REPORT_TITLE_KEY => $reportTitle, - self::ADDITIONAL_FILES_KEY => $additionalFiles, - ) + $notificationInfo = array( + self::REPORT_TYPE_INFO_KEY => $report['type'], + self::REPORT_KEY => $report, + self::REPORT_CONTENT_KEY => $contents, + self::FILENAME_KEY => $filename, + self::PRETTY_DATE_KEY => $prettyDate, + self::REPORT_SUBJECT_KEY => $reportSubject, + self::REPORT_TITLE_KEY => $reportTitle, + self::ADDITIONAL_FILES_KEY => $additionalFiles, + ) ) ); @@ -659,11 +665,9 @@ class Piwik_PDFReports_API if (empty($idSegment) || (is_numeric($idSegment) && $idSegment == 0)) { $idSegment = null; - } elseif (!is_numeric($idSegment)) { throw new Exception('Invalid segment identifier. Should be an integer.'); - } elseif (self::getSegment($idSegment) == null) { throw new Exception('Segment with id ' . $idSegment . ' does not exist or SegmentEditor is not activated.'); @@ -724,10 +728,10 @@ class Piwik_PDFReports_API Piwik_PostEvent( self::ALLOW_MULTIPLE_REPORTS_EVENT, array( - &$allowMultipleReports, - $notificationInfo = array( - self::REPORT_TYPE_INFO_KEY => $reportType, - ) + &$allowMultipleReports, + $notificationInfo = array( + self::REPORT_TYPE_INFO_KEY => $reportType, + ) ) ); return $allowMultipleReports; @@ -754,10 +758,10 @@ class Piwik_PDFReports_API Piwik_PostEvent( self::GET_REPORT_FORMATS_EVENT, array( - &$reportFormats, - $notificationInfo = array( - self::REPORT_TYPE_INFO_KEY => $reportType - ) + &$reportFormats, + $notificationInfo = array( + self::REPORT_TYPE_INFO_KEY => $reportType + ) ) ); @@ -788,7 +792,7 @@ class Piwik_PDFReports_API { if (self::isSegmentEditorActivated() && !empty($idSegment)) { - $segment = Piwik_SegmentEditor_API::getInstance()->get($idSegment); + $segment = SegmentEditorAPI::getInstance()->get($idSegment); if ($segment) { return $segment; diff --git a/plugins/PDFReports/Controller.php b/plugins/PDFReports/Controller.php index 3eed377084..67c3ce70a3 100644 --- a/plugins/PDFReports/Controller.php +++ b/plugins/PDFReports/Controller.php @@ -6,45 +6,51 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_PDFReports + * @package PDFReports */ +namespace Piwik\Plugins\PDFReports; + use Piwik\Piwik; use Piwik\Common; -use Piwik\Controller; +use Piwik\Plugins\LanguagesManager\LanguagesManager; +use Piwik\Plugins\PDFReports\API; use Piwik\View; +use Piwik\Plugins\PDFReports\PDFReports; +use Piwik\Plugins\SegmentEditor\API as SegmentEditorAPI; +use Piwik\Plugins\SitesManager\API as SitesManagerAPI; /** * - * @package Piwik_PDFReports + * @package PDFReports */ -class Piwik_PDFReports_Controller extends Controller +class Controller extends \Piwik\Controller { - const DEFAULT_REPORT_TYPE = Piwik_PDFReports::EMAIL_TYPE; + const DEFAULT_REPORT_TYPE = PDFReports::EMAIL_TYPE; public function index() { $view = new View('@PDFReports/index'); $this->setGeneralVariablesView($view); - $view->countWebsites = count(Piwik_SitesManager_API::getInstance()->getSitesIdWithAtLeastViewAccess()); + $view->countWebsites = count(SitesManagerAPI::getInstance()->getSitesIdWithAtLeastViewAccess()); // get report types - $reportTypes = Piwik_PDFReports_API::getReportTypes(); + $reportTypes = API::getReportTypes(); $view->reportTypes = $reportTypes; $view->defaultReportType = self::DEFAULT_REPORT_TYPE; - $view->defaultReportFormat = Piwik_PDFReports::DEFAULT_REPORT_FORMAT; + $view->defaultReportFormat = PDFReports::DEFAULT_REPORT_FORMAT; $reportsByCategoryByType = array(); $reportFormatsByReportType = array(); $allowMultipleReportsByReportType = array(); foreach ($reportTypes as $reportType => $reportTypeIcon) { // get report formats - $reportFormatsByReportType[$reportType] = Piwik_PDFReports_API::getReportFormats($reportType); - $allowMultipleReportsByReportType[$reportType] = Piwik_PDFReports_API::allowMultipleReports($reportType); + $reportFormatsByReportType[$reportType] = API::getReportFormats($reportType); + $allowMultipleReportsByReportType[$reportType] = API::allowMultipleReports($reportType); // get report metadata $reportsByCategory = array(); - $availableReportMetadata = Piwik_PDFReports_API::getReportMetadata($this->idSite, $reportType); + $availableReportMetadata = API::getReportMetadata($this->idSite, $reportType); foreach ($availableReportMetadata as $reportMetadata) { $reportsByCategory[$reportMetadata['category']][] = $reportMetadata; } @@ -57,28 +63,28 @@ class Piwik_PDFReports_Controller extends Controller $reports = array(); $reportsById = array(); if (!Piwik::isUserIsAnonymous()) { - $reports = Piwik_PDFReports_API::getInstance()->getReports($this->idSite, $period = false, $idReport = false, $ifSuperUserReturnOnlySuperUserReports = true); + $reports = API::getInstance()->getReports($this->idSite, $period = false, $idReport = false, $ifSuperUserReturnOnlySuperUserReports = true); foreach ($reports as &$report) { - $report['recipients'] = Piwik_PDFReports_API::getReportRecipients($report); + $report['recipients'] = API::getReportRecipients($report); $reportsById[$report['idreport']] = $report; } } $view->reports = $reports; $view->reportsJSON = Common::json_encode($reportsById); - $view->downloadOutputType = Piwik_PDFReports_API::OUTPUT_INLINE; + $view->downloadOutputType = API::OUTPUT_INLINE; - $view->periods = Piwik_PDFReports::getPeriodToFrequency(); - $view->defaultPeriod = Piwik_PDFReports::DEFAULT_PERIOD; - $view->defaultHour = Piwik_PDFReports::DEFAULT_HOUR; + $view->periods = PDFReports::getPeriodToFrequency(); + $view->defaultPeriod = PDFReports::DEFAULT_PERIOD; + $view->defaultHour = PDFReports::DEFAULT_HOUR; - $view->language = Piwik_LanguagesManager::getLanguageCodeForCurrentUser(); + $view->language = LanguagesManager::getLanguageCodeForCurrentUser(); $view->segmentEditorActivated = false; - if (Piwik_PDFReports_API::isSegmentEditorActivated()) { + if (API::isSegmentEditorActivated()) { $savedSegmentsById = array(); - foreach (Piwik_SegmentEditor_API::getInstance()->getAll($this->idSite) as $savedSegment) { + foreach (SegmentEditorAPI::getInstance()->getAll($this->idSite) as $savedSegment) { $savedSegmentsById[$savedSegment['idsegment']] = $savedSegment['name']; } $view->savedSegmentsById = $savedSegmentsById; diff --git a/plugins/PDFReports/PDFReports.php b/plugins/PDFReports/PDFReports.php index 74c5a0110f..edd053cca4 100644 --- a/plugins/PDFReports/PDFReports.php +++ b/plugins/PDFReports/PDFReports.php @@ -6,26 +6,34 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_PDFReports + * @package PDFReports */ +namespace Piwik\Plugins\PDFReports; + +use Exception; use Piwik\Piwik; use Piwik\Common; use Piwik\Config; use Piwik\Date; use Piwik\Mail; +use Piwik\Plugins\MobileMessaging\API as MobileMessagingAPI; +use Piwik\Plugins\MobileMessaging\MobileMessaging; use Piwik\View; use Piwik\ScheduledTime; use Piwik\ScheduledTask; use Piwik\ReportRenderer; -use Piwik\Plugin; use Piwik\Site; use Piwik\Db; +use Piwik\Plugins\SegmentEditor\API as SegmentEditorAPI; +use Piwik\Plugins\UsersManager\API as UsersManagerAPI; +use Zend_Mime; +use Zend_Registry; /** * - * @package Piwik_PDFReports + * @package PDFReports */ -class Piwik_PDFReports extends Plugin +class PDFReports extends \Piwik\Plugin { const MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY = 'MobileMessaging_TopMenu'; const PDF_REPORTS_TOP_MENU_TRANSLATION_KEY = 'PDFReports_EmailReports'; @@ -87,7 +95,7 @@ class Piwik_PDFReports extends Plugin 'template_reportParametersPDFReports' => 'template_reportParametersPDFReports', 'UsersManager.deleteUser' => 'deleteUserReport', 'SitesManager.deleteSite' => 'deleteSiteReport', - Piwik_SegmentEditor_API::DELETE_SEGMENT_EVENT => 'segmentDeletion', + SegmentEditorAPI::DELETE_SEGMENT_EVENT => 'segmentDeletion', ); } @@ -96,11 +104,11 @@ class Piwik_PDFReports extends Plugin */ public function deleteSiteReport(&$idSite) { - $idReports = Piwik_PDFReports_API::getInstance()->getReports($idSite); + $idReports = API::getInstance()->getReports($idSite); foreach ($idReports as $report) { $idReport = $report['idreport']; - Piwik_PDFReports_API::getInstance()->deleteReport($idReport); + API::getInstance()->deleteReport($idReport); } } @@ -154,9 +162,9 @@ class Piwik_PDFReports extends Plugin public function getReportMetadata(&$reportMetadata, $notificationInfo) { if (self::manageEvent($notificationInfo)) { - $idSite = $notificationInfo[Piwik_PDFReports_API::ID_SITE_INFO_KEY]; + $idSite = $notificationInfo[API::ID_SITE_INFO_KEY]; - $availableReportMetadata = Piwik_API_API::getInstance()->getReportMetadata($idSite); + $availableReportMetadata = \Piwik\Plugins\API\API::getInstance()->getReportMetadata($idSite); $filteredReportMetadata = array(); foreach ($availableReportMetadata as $reportMetadata) { @@ -195,7 +203,7 @@ class Piwik_PDFReports extends Plugin public function processReports(&$processedReports, $notificationInfo) { if (self::manageEvent($notificationInfo)) { - $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; + $report = $notificationInfo[API::REPORT_KEY]; $displayFormat = $report['parameters'][self::DISPLAY_FORMAT_PARAMETER]; $evolutionGraph = $report['parameters'][self::EVOLUTION_GRAPH_PARAMETER]; @@ -222,8 +230,8 @@ class Piwik_PDFReports extends Plugin if ($metadata['module'] == 'MultiSites') { $columns = $processedReport['columns']; - foreach (Piwik_MultiSites_API::getApiMetrics($enhanced = true) as $metricSettings) { - unset($columns[$metricSettings[Piwik_MultiSites_API::METRIC_EVOLUTION_COL_NAME_KEY]]); + foreach (\Piwik\Plugins\MultiSites\API::getApiMetrics($enhanced = true) as $metricSettings) { + unset($columns[$metricSettings[\Piwik\Plugins\MultiSites\API::METRIC_EVOLUTION_COL_NAME_KEY]]); } $processedReport['metadata'] = $metadata; @@ -236,13 +244,13 @@ class Piwik_PDFReports extends Plugin public function getRendererInstance(&$reportRenderer, $notificationInfo) { if (self::manageEvent($notificationInfo)) { - $reportFormat = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]['format']; - $outputType = $notificationInfo[Piwik_PDFReports_API::OUTPUT_TYPE_INFO_KEY]; + $reportFormat = $notificationInfo[API::REPORT_KEY]['format']; + $outputType = $notificationInfo[API::OUTPUT_TYPE_INFO_KEY]; $reportRenderer = ReportRenderer::factory($reportFormat); if ($reportFormat == ReportRenderer::HTML_FORMAT) { - $reportRenderer->setRenderImageInline($outputType != Piwik_PDFReports_API::OUTPUT_SAVE_ON_DISK); + $reportRenderer->setRenderImageInline($outputType != API::OUTPUT_SAVE_ON_DISK); } } } @@ -257,12 +265,12 @@ class Piwik_PDFReports extends Plugin public function sendReport($notificationInfo) { if (self::manageEvent($notificationInfo)) { - $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; - $reportTitle = $notificationInfo[Piwik_PDFReports_API::REPORT_TITLE_KEY]; - $prettyDate = $notificationInfo[Piwik_PDFReports_API::PRETTY_DATE_KEY]; - $contents = $notificationInfo[Piwik_PDFReports_API::REPORT_CONTENT_KEY]; - $filename = $notificationInfo[Piwik_PDFReports_API::FILENAME_KEY]; - $additionalFiles = $notificationInfo[Piwik_PDFReports_API::ADDITIONAL_FILES_KEY]; + $report = $notificationInfo[API::REPORT_KEY]; + $reportTitle = $notificationInfo[API::REPORT_TITLE_KEY]; + $prettyDate = $notificationInfo[API::PRETTY_DATE_KEY]; + $contents = $notificationInfo[API::REPORT_CONTENT_KEY]; + $filename = $notificationInfo[API::FILENAME_KEY]; + $additionalFiles = $notificationInfo[API::ADDITIONAL_FILES_KEY]; $periods = self::getPeriodToFrequencyAsAdjective(); $message = Piwik_Translate('PDFReports_EmailHello'); @@ -279,8 +287,8 @@ class Piwik_PDFReports extends Plugin $displaySegmentInfo = false; $segmentInfo = null; - $segment = Piwik_PDFReports_API::getSegment($report['idsegment']); - if($segment != null) { + $segment = API::getSegment($report['idsegment']); + if ($segment != null) { $displaySegmentInfo = true; $segmentInfo = Piwik_Translate('PDFReports_SegmentAppliedToReports', $segment['name']); } @@ -292,7 +300,7 @@ class Piwik_PDFReports extends Plugin $mail->setType(Zend_Mime::MULTIPART_RELATED); $message .= "<br/>" . Piwik_Translate('PDFReports_PleaseFindBelow', array($periods[$report['period']], $reportTitle)); - if($displaySegmentInfo) { + if ($displaySegmentInfo) { $message .= " " . $segmentInfo; } @@ -303,7 +311,7 @@ class Piwik_PDFReports extends Plugin case 'pdf': $message .= "\n" . Piwik_Translate('PDFReports_PleaseFindAttachedFile', array($periods[$report['period']], $reportTitle)); - if($displaySegmentInfo) { + if ($displaySegmentInfo) { $message .= " " . $segmentInfo; } @@ -347,7 +355,7 @@ class Piwik_PDFReports extends Plugin $emails[] = Piwik::getSuperUserEmail(); } else { try { - $user = Piwik_UsersManager_API::getInstance()->getUser($report['login']); + $user = UsersManagerAPI::getInstance()->getUser($report['login']); } catch (Exception $e) { return; } @@ -380,7 +388,7 @@ class Piwik_PDFReports extends Plugin public function getReportRecipients(&$recipients, $notificationInfo) { if (self::manageEvent($notificationInfo)) { - $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; + $report = $notificationInfo[API::REPORT_KEY]; $parameters = $report['parameters']; $eMailMe = $parameters[self::EMAIL_ME_PARAMETER]; @@ -411,7 +419,7 @@ class Piwik_PDFReports extends Plugin private static function manageEvent($info) { return in_array( - $info[Piwik_PDFReports_API::REPORT_TYPE_INFO_KEY], + $info[API::REPORT_TYPE_INFO_KEY], array_keys(self::$managedReportTypes) ); } @@ -419,7 +427,7 @@ class Piwik_PDFReports extends Plugin public function getScheduledTasks(&$tasks) { $arbitraryDateInUTC = Date::factory('2011-01-01'); - foreach (Piwik_PDFReports_API::getInstance()->getReports() as $report) { + foreach (API::getInstance()->getReports() as $report) { if (!$report['deleted'] && $report['period'] != ScheduledTime::PERIOD_NEVER) { $midnightInSiteTimezone = date( @@ -435,7 +443,7 @@ class Piwik_PDFReports extends Plugin $schedule = ScheduledTime::getScheduledTimeForPeriod($report['period']); $schedule->setHour($hourInUTC); $tasks[] = new ScheduledTask ( - Piwik_PDFReports_API::getInstance(), + API::getInstance(), 'sendReport', $report['idreport'], $schedule ); @@ -445,7 +453,7 @@ class Piwik_PDFReports extends Plugin public function segmentDeletion(&$idSegment) { - $reportsUsingSegment = Piwik_PDFReports_API::getInstance()->getReports(false, false, false, true, $idSegment); + $reportsUsingSegment = API::getInstance()->getReports(false, false, false, true, $idSegment); if (count($reportsUsingSegment) > 0) { @@ -486,19 +494,19 @@ class Piwik_PDFReports extends Plugin return self::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY; } - $reports = Piwik_PDFReports_API::getInstance()->getReports(); + $reports = API::getInstance()->getReports(); $reportCount = count($reports); // if there are no reports and the mobile account is // not configured, display 'Email reports' // configured, display 'Email & SMS reports' if ($reportCount == 0) - return Piwik_MobileMessaging_API::getInstance()->areSMSAPICredentialProvided() ? + return MobileMessagingAPI::getInstance()->areSMSAPICredentialProvided() ? self::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY : self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; $anyMobileReport = false; foreach ($reports as $report) { - if ($report['type'] == Piwik_MobileMessaging::MOBILE_TYPE) { + if ($report['type'] == MobileMessaging::MOBILE_TYPE) { $anyMobileReport = true; break; } @@ -600,7 +608,7 @@ class Piwik_PDFReports extends Plugin ScheduledTime::PERIOD_DAY => Piwik_Translate('General_DailyReport'), ScheduledTime::PERIOD_WEEK => Piwik_Translate('General_WeeklyReport'), ScheduledTime::PERIOD_MONTH => Piwik_Translate('General_MonthlyReport'), - ScheduledTime::PERIOD_YEAR => Piwik_Translate('General_YearlyReport'), + ScheduledTime::PERIOD_YEAR => Piwik_Translate('General_YearlyReport'), ScheduledTime::PERIOD_RANGE => Piwik_Translate('General_RangeReports'), ); } diff --git a/plugins/PDFReports/config/tcpdf_config.php b/plugins/PDFReports/config/tcpdf_config.php index 096171d164..f9b2de9a6f 100644 --- a/plugins/PDFReports/config/tcpdf_config.php +++ b/plugins/PDFReports/config/tcpdf_config.php @@ -6,13 +6,13 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_PDFReports + * @package PDFReports */ /** * Override settings in libs/tcpdf_config.php * - * @package Piwik_PDFReports + * @package PDFReports */ define('K_PATH_MAIN', PIWIK_INCLUDE_PATH . '/libs/tcpdf/'); diff --git a/plugins/PleineLune/PleineLune.php b/plugins/PleineLune/PleineLune.php deleted file mode 100644 index b19ed3e288..0000000000 --- a/plugins/PleineLune/PleineLune.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php -/** - * Piwik - Open source web analytics - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - * @category Piwik_Plugins - * @package Piwik_PleineLune - */ -use Piwik\AssetManager; -use Piwik\Plugin; - -/** - * - * @package Piwik_PleineLune - */ -class Piwik_PleineLune extends Plugin -{ - public function getListHooksRegistered() - { - return array( - AssetManager::CSS_IMPORT_EVENT => 'getCssFiles', - ); - } - - public function getCssFiles(&$cssFiles) - { - $cssFiles[] = "plugins/PleineLune/stylesheets/theme.less"; - } -} diff --git a/plugins/PleineLune/plugin.piwik.json b/plugins/PleineLune/plugin.piwik.json index d0718e1737..b3ab4ac732 100644 --- a/plugins/PleineLune/plugin.piwik.json +++ b/plugins/PleineLune/plugin.piwik.json @@ -1,5 +1,6 @@ { "name": "PleineLune", "description": "A dark theme for Piwik, ideal to view your analytics reports before sunrise.", - "theme": true + "theme": true, + "stylesheet": "stylesheets/theme.less" }
\ No newline at end of file diff --git a/plugins/PrivacyManager/Controller.php b/plugins/PrivacyManager/Controller.php index c11fb5d7f0..8bf89fa479 100644 --- a/plugins/PrivacyManager/Controller.php +++ b/plugins/PrivacyManager/Controller.php @@ -6,21 +6,27 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_PrivacyManager + * @package PrivacyManager */ +namespace Piwik\Plugins\PrivacyManager; + use Piwik\Config; -use Piwik\Controller\Admin; use Piwik\Piwik; use Piwik\Common; use Piwik\Date; +use Piwik\Plugins\DBStats\MySQLMetadataProvider; +use Piwik\Plugins\LanguagesManager\LanguagesManager; use Piwik\View; use Piwik\TaskScheduler; +use Piwik\Plugins\PrivacyManager\PrivacyManager; +use Piwik\Plugins\PrivacyManager\LogDataPurger; +use Piwik\Plugins\PrivacyManager\ReportsPurger; /** * - * @package Piwik_PrivacyManager + * @package PrivacyManager */ -class Piwik_PrivacyManager_Controller extends Admin +class Controller extends \Piwik\Controller\Admin { const ANONYMIZE_IP_PLUGIN_NAME = "AnonymizeIP"; @@ -42,7 +48,7 @@ class Piwik_PrivacyManager_Controller extends Admin case("formDeleteSettings"): $settings = $this->getPurgeSettingsFromRequest(); - Piwik_PrivacyManager::savePurgeDataSettings($settings); + PrivacyManager::savePurgeDataSettings($settings); break; default: //do nothing @@ -81,7 +87,7 @@ class Piwik_PrivacyManager_Controller extends Admin $settings['delete_reports_keep_range_reports'] = Common::getRequestVar("deleteReportsKeepRange", 0); $settings['delete_reports_keep_segment_reports'] = Common::getRequestVar("deleteReportsKeepSegments", 0); - $settings['delete_logs_max_rows_per_query'] = Piwik_PrivacyManager::DEFAULT_MAX_ROWS_PER_QUERY; + $settings['delete_logs_max_rows_per_query'] = PrivacyManager::DEFAULT_MAX_ROWS_PER_QUERY; return $settings; } @@ -97,7 +103,7 @@ class Piwik_PrivacyManager_Controller extends Admin $forceEstimate = Common::getRequestVar('forceEstimate', 0); $view->dbStats = $this->getDeleteDBSizeEstimate($getSettingsFromQuery = true, $forceEstimate); - $view->language = Piwik_LanguagesManager::getLanguageCodeForCurrentUser(); + $view->language = LanguagesManager::getLanguageCodeForCurrentUser(); echo $view->render(); } @@ -124,7 +130,7 @@ class Piwik_PrivacyManager_Controller extends Admin $view->canDeleteLogActions = Piwik::isLockPrivilegeGranted(); $view->dbUser = Config::getInstance()->database['username']; } - $view->language = Piwik_LanguagesManager::getLanguageCodeForCurrentUser(); + $view->language = LanguagesManager::getLanguageCodeForCurrentUser(); $this->displayWarningIfConfigFileNotWritable($view); $this->setBasicVariablesView($view); echo $view->render(); @@ -146,14 +152,14 @@ class Piwik_PrivacyManager_Controller extends Admin return $this->redirectToIndex('PrivacyManager', 'privacySettings'); } - $settings = Piwik_PrivacyManager::getPurgeDataSettings(); + $settings = PrivacyManager::getPurgeDataSettings(); if ($settings['delete_logs_enable']) { - $logDataPurger = Piwik_PrivacyManager_LogDataPurger::make($settings); + $logDataPurger = LogDataPurger::make($settings); $logDataPurger->purgeData(); } if ($settings['delete_reports_enable']) { - $reportsPurger = Piwik_PrivacyManager_ReportsPurger::make( - $settings, Piwik_PrivacyManager::getAllMetricsToKeep()); + $reportsPurger = ReportsPurger::make( + $settings, PrivacyManager::getAllMetricsToKeep()); $reportsPurger->purgeData(true); } } @@ -164,13 +170,13 @@ class Piwik_PrivacyManager_Controller extends Admin if ($getSettingsFromQuery) { $settings = $this->getPurgeSettingsFromRequest(); } else { - $settings = Piwik_PrivacyManager::getPurgeDataSettings(); + $settings = PrivacyManager::getPurgeDataSettings(); } $doDatabaseSizeEstimate = Config::getInstance()->Deletelogs['enable_auto_database_size_estimate']; // determine the DB size & purged DB size - $metadataProvider = new Piwik_DBStats_MySQLMetadataProvider(); + $metadataProvider = new MySQLMetadataProvider(); $tableStatuses = $metadataProvider->getAllTablesStatus(); $totalBytes = 0; @@ -186,7 +192,7 @@ class Piwik_PrivacyManager_Controller extends Admin if ($doDatabaseSizeEstimate || $forceEstimate == 1) { // maps tables whose data will be deleted with number of rows that will be deleted // if a value is -1, it means the table will be dropped. - $deletedDataSummary = Piwik_PrivacyManager::getPurgeEstimate($settings); + $deletedDataSummary = PrivacyManager::getPurgeEstimate($settings); $totalAfterPurge = $totalBytes; foreach ($tableStatuses as $status) { @@ -195,7 +201,7 @@ class Piwik_PrivacyManager_Controller extends Admin $tableTotalBytes = $status['Data_length'] + $status['Index_length']; // if dropping the table - if ($deletedDataSummary[$tableName] === Piwik_PrivacyManager_ReportsPurger::DROP_TABLE) { + if ($deletedDataSummary[$tableName] === ReportsPurger::DROP_TABLE) { $totalAfterPurge -= $tableTotalBytes; } else // if just deleting rows { @@ -233,11 +239,11 @@ class Piwik_PrivacyManager_Controller extends Admin Piwik::checkUserIsSuperUser(); $deleteDataInfos = array(); $taskScheduler = new TaskScheduler(); - $deleteDataInfos["config"] = Piwik_PrivacyManager::getPurgeDataSettings(); + $deleteDataInfos["config"] = PrivacyManager::getPurgeDataSettings(); $deleteDataInfos["deleteTables"] = - "<br/>" . implode(", ", Piwik_PrivacyManager_LogDataPurger::getDeleteTableLogTables()); + "<br/>" . implode(", ", LogDataPurger::getDeleteTableLogTables()); - $scheduleTimetable = $taskScheduler->getScheduledTimeForMethod("Piwik_PrivacyManager", "deleteLogTables"); + $scheduleTimetable = $taskScheduler->getScheduledTimeForMethod("PrivacyManager", "deleteLogTables"); $optionTable = Piwik_GetOption(self::OPTION_LAST_DELETE_PIWIK_LOGS); @@ -278,7 +284,7 @@ class Piwik_PrivacyManager_Controller extends Admin protected function handlePluginState($state = 0) { - $pluginController = new Piwik_CorePluginsAdmin_Controller(); + $pluginController = new \Piwik\Plugins\CorePluginsAdmin\Controller(); if ($state == 1 && !\Piwik\PluginsManager::getInstance()->isPluginActivated(self::ANONYMIZE_IP_PLUGIN_NAME)) { $pluginController->activate($redirectAfter = false); diff --git a/plugins/PrivacyManager/LogDataPurger.php b/plugins/PrivacyManager/LogDataPurger.php index d4fa491b43..b08216314f 100755 --- a/plugins/PrivacyManager/LogDataPurger.php +++ b/plugins/PrivacyManager/LogDataPurger.php @@ -6,8 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_PrivacyManager + * @package PrivacyManager */ +namespace Piwik\Plugins\PrivacyManager; + use Piwik\Piwik; use Piwik\Common; use Piwik\Date; @@ -16,7 +18,7 @@ use Piwik\Db; /** * Purges the log_visit, log_conversion and related tables of old visit data. */ -class Piwik_PrivacyManager_LogDataPurger +class LogDataPurger { const TEMP_TABLE_NAME = 'tmp_log_actions_to_keep'; @@ -312,11 +314,11 @@ class Piwik_PrivacyManager_LogDataPurger * * @param array $settings Array of settings * @param bool $useRealTable - * @return Piwik_PrivacyManager_LogDataPurger + * @return \Piwik\Plugins\PrivacyManager\LogDataPurger */ public static function make($settings, $useRealTable = false) { - return new Piwik_PrivacyManager_LogDataPurger( + return new LogDataPurger( $settings['delete_logs_older_than'], $settings['delete_logs_max_rows_per_query'] ); diff --git a/plugins/PrivacyManager/PrivacyManager.php b/plugins/PrivacyManager/PrivacyManager.php index 517b410bfe..2208156584 100644 --- a/plugins/PrivacyManager/PrivacyManager.php +++ b/plugins/PrivacyManager/PrivacyManager.php @@ -6,18 +6,23 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_PrivacyManager + * @package PrivacyManager */ +namespace Piwik\Plugins\PrivacyManager; + +use Exception; use Piwik\Config; use Piwik\Metrics; use Piwik\Piwik; use Piwik\Common; use Piwik\Date; +use Piwik\Plugins\Goals\Archiver; +use Piwik\Plugins\PrivacyManager\LogDataPurger; use Piwik\ScheduledTask; -use Piwik\Plugin; use Piwik\Db; use Piwik\ScheduledTime\Daily; use Piwik\Tracker\GoalManager; +use Piwik\Plugins\PrivacyManager\ReportsPurger; /** * @see plugins/PrivacyManager/LogDataPurger.php @@ -31,9 +36,9 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/PrivacyManager/ReportsPurger.php'; /** * - * @package Piwik_PrivacyManager + * @package PrivacyManager */ -class Piwik_PrivacyManager extends Plugin +class PrivacyManager extends \Piwik\Plugin { const OPTION_LAST_DELETE_PIWIK_LOGS = "lastDelete_piwik_logs"; const OPTION_LAST_DELETE_PIWIK_REPORTS = 'lastDelete_piwik_reports'; @@ -197,7 +202,7 @@ class Piwik_PrivacyManager extends Plugin // set last run time Piwik_SetOption(self::OPTION_LAST_DELETE_PIWIK_REPORTS, Date::factory('today')->getTimestamp()); - Piwik_PrivacyManager_ReportsPurger::make($settings, self::getAllMetricsToKeep())->purgeData(); + ReportsPurger::make($settings, self::getAllMetricsToKeep())->purgeData(); } /** @@ -236,7 +241,7 @@ class Piwik_PrivacyManager extends Plugin Piwik_SetOption(self::OPTION_LAST_DELETE_PIWIK_LOGS, $lastDeleteDate); // execute the purge - Piwik_PrivacyManager_LogDataPurger::make($settings)->purgeData(); + LogDataPurger::make($settings)->purgeData(); } /** @@ -259,12 +264,12 @@ class Piwik_PrivacyManager extends Plugin $result = array(); if ($settings['delete_logs_enable']) { - $logDataPurger = Piwik_PrivacyManager_LogDataPurger::make($settings); + $logDataPurger = LogDataPurger::make($settings); $result = array_merge($result, $logDataPurger->getPurgeEstimate()); } if ($settings['delete_reports_enable']) { - $reportsPurger = Piwik_PrivacyManager_ReportsPurger::make($settings, self::getAllMetricsToKeep()); + $reportsPurger = ReportsPurger::make($settings, self::getAllMetricsToKeep()); $result = array_merge($result, $reportsPurger->getPurgeEstimate()); } @@ -303,7 +308,7 @@ class Piwik_PrivacyManager extends Plugin $reportsOlderThan = Date::factory('today')->subMonth(1 + $reportsOlderThan); } - return Piwik_PrivacyManager_ReportsPurger::shouldReportBePurged( + return ReportsPurger::shouldReportBePurged( $reportDateYear, $reportDateMonth, $reportsOlderThan); } @@ -347,12 +352,12 @@ class Piwik_PrivacyManager extends Plugin foreach ($goalMetricsToKeep as $metric) { for ($i = 1; $i <= $maxGoalId; ++$i) // maxGoalId can be 0 { - $metricsToKeep[] = Piwik_Goals_Archiver::getRecordName($metric, $i); + $metricsToKeep[] = Archiver::getRecordName($metric, $i); } - $metricsToKeep[] = Piwik_Goals_Archiver::getRecordName($metric); - $metricsToKeep[] = Piwik_Goals_Archiver::getRecordName($metric, GoalManager::IDGOAL_ORDER); - $metricsToKeep[] = Piwik_Goals_Archiver::getRecordName($metric, GoalManager::IDGOAL_CART); + $metricsToKeep[] = Archiver::getRecordName($metric); + $metricsToKeep[] = Archiver::getRecordName($metric, GoalManager::IDGOAL_ORDER); + $metricsToKeep[] = Archiver::getRecordName($metric, GoalManager::IDGOAL_CART); } } diff --git a/plugins/PrivacyManager/ReportsPurger.php b/plugins/PrivacyManager/ReportsPurger.php index af527b6142..6b81139830 100755 --- a/plugins/PrivacyManager/ReportsPurger.php +++ b/plugins/PrivacyManager/ReportsPurger.php @@ -6,8 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_PrivacyManager + * @package PrivacyManager */ +namespace Piwik\Plugins\PrivacyManager; + use Piwik\DataAccess\ArchiveTableCreator; use Piwik\Piwik; use Piwik\Date; @@ -16,7 +18,7 @@ use Piwik\Db; /** * Purges archived reports and metrics that are considered old. */ -class Piwik_PrivacyManager_ReportsPurger +class ReportsPurger { // constant used in database purging estimate to signify a table should be dropped const DROP_TABLE = -1; @@ -213,7 +215,7 @@ class Piwik_PrivacyManager_ReportsPurger $oldBlobTables = array(); foreach (Piwik::getTablesInstalled() as $table) { $type = ArchiveTableCreator::getTypeFromTableName($table); - if($type === false) { + if ($type === false) { continue; } $date = ArchiveTableCreator::getDateFromTableName($table); @@ -347,7 +349,7 @@ class Piwik_PrivacyManager_ReportsPurger */ public static function make($settings, $metricsToKeep) { - return new Piwik_PrivacyManager_ReportsPurger( + return new ReportsPurger( $settings['delete_reports_older_than'], $settings['delete_reports_keep_basic_metrics'] == 1, self::getReportPeriodsToKeep($settings), diff --git a/plugins/Provider/API.php b/plugins/Provider/API.php index 63565b5301..88eb4b473b 100644 --- a/plugins/Provider/API.php +++ b/plugins/Provider/API.php @@ -6,11 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Provider + * @package Provider */ +namespace Piwik\Plugins\Provider; + use Piwik\Archive; use Piwik\Metrics; use Piwik\Piwik; +use Piwik\Plugins\Provider\Archiver; /** * @see plugins/Provider/functions.php @@ -20,9 +23,9 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Provider/functions.php'; /** * The Provider API lets you access reports for your visitors Internet Providers. * - * @package Piwik_Provider + * @package Provider */ -class Piwik_Provider_API +class API { static private $instance = null; @@ -38,10 +41,10 @@ class Piwik_Provider_API { Piwik::checkUserHasViewAccess($idSite); $archive = Archive::build($idSite, $period, $date, $segment); - $dataTable = $archive->getDataTable(Piwik_Provider_Archiver::PROVIDER_RECORD_NAME); + $dataTable = $archive->getDataTable(Archiver::PROVIDER_RECORD_NAME); $dataTable->filter('Sort', array(Metrics::INDEX_NB_VISITS)); - $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', 'Piwik_getHostnameUrl')); - $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_Provider_getPrettyProviderName')); + $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', __NAMESPACE__ . '\getHostnameUrl')); + $dataTable->queueFilter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getPrettyProviderName')); $dataTable->queueFilter('ReplaceColumnNames'); $dataTable->queueFilter('ReplaceSummaryRowLabel'); return $dataTable; diff --git a/plugins/Provider/Archiver.php b/plugins/Provider/Archiver.php index bd9a4fa456..a449a9f4e8 100644 --- a/plugins/Provider/Archiver.php +++ b/plugins/Provider/Archiver.php @@ -6,12 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Provider + * @package Provider */ +namespace Piwik\Plugins\Provider; + use Piwik\Metrics; use Piwik\PluginsArchiver; -class Piwik_Provider_Archiver extends PluginsArchiver +class Archiver extends PluginsArchiver { const PROVIDER_RECORD_NAME = 'Provider_hostnameExt'; const PROVIDER_FIELD = "location_provider"; diff --git a/plugins/Provider/Controller.php b/plugins/Provider/Controller.php index c51d7ccf4a..6d79bd3d1a 100644 --- a/plugins/Provider/Controller.php +++ b/plugins/Provider/Controller.php @@ -6,16 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Provider + * @package Provider */ -use Piwik\Controller; +namespace Piwik\Plugins\Provider; + use Piwik\ViewDataTable; /** * - * @package Piwik_Provider + * @package Provider */ -class Piwik_Provider_Controller extends Controller +class Controller extends \Piwik\Controller { /** * Provider diff --git a/plugins/Provider/Provider.php b/plugins/Provider/Provider.php index f20e823b95..f2562e9485 100644 --- a/plugins/Provider/Provider.php +++ b/plugins/Provider/Provider.php @@ -6,21 +6,25 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Provider + * @package Provider */ +namespace Piwik\Plugins\Provider; + +use Exception; use Piwik\Common; use Piwik\FrontController; use Piwik\IP; -use Piwik\Plugin; use Piwik\ArchiveProcessor; use Piwik\Db; +use Piwik\Plugins\Provider\Archiver; use Piwik\WidgetsList; +use Zend_Registry; /** * - * @package Piwik_Provider + * @package Provider */ -class Piwik_Provider extends Plugin +class Provider extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered @@ -28,13 +32,13 @@ class Piwik_Provider extends Plugin public function getListHooksRegistered() { $hooks = array( - 'ArchiveProcessing_Day.compute' => 'archiveDay', - 'ArchiveProcessing_Period.compute' => 'archivePeriod', - 'Tracker.newVisitorInformation' => 'logProviderInfo', - 'WidgetsList.add' => 'addWidget', - 'Menu.add' => 'addMenu', - 'API.getReportMetadata' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ArchiveProcessing_Day.compute' => 'archiveDay', + 'ArchiveProcessing_Period.compute' => 'archivePeriod', + 'Tracker.newVisitorInformation' => 'logProviderInfo', + 'WidgetsList.add' => 'addWidget', + 'Menu.add' => 'addMenu', + 'API.getReportMetadata' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); return $hooks; @@ -78,7 +82,6 @@ class Piwik_Provider extends Plugin throw $e; } } - } public function uninstall() @@ -101,7 +104,7 @@ class Piwik_Provider extends Plugin public function postLoad() { - Piwik_AddAction('template_footerUserCountry', array('Piwik_Provider', 'footerUserCountry')); + Piwik_AddAction('template_footerUserCountry', array('Piwik\Plugins\Provider\Provider', 'footerUserCountry')); } /** @@ -201,16 +204,16 @@ class Piwik_Provider extends Plugin */ public function archiveDay(ArchiveProcessor\Day $archiveProcessor) { - $archiving = new Piwik_Provider_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archiveDay(); } } public function archivePeriod(ArchiveProcessor\Period $archiveProcessor) { - $archiving = new Piwik_Provider_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archivePeriod(); } } diff --git a/plugins/Provider/functions.php b/plugins/Provider/functions.php index 540060db4b..51a85e15d1 100644 --- a/plugins/Provider/functions.php +++ b/plugins/Provider/functions.php @@ -6,8 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Provider + * @package Provider */ +namespace Piwik\Plugins\Provider; + use Piwik\Common; use Piwik\DataTable; @@ -17,7 +19,7 @@ use Piwik\DataTable; * @param string $in * @return string Host name, IP (if IP address didn't resolve), or Unknown */ -function Piwik_getHostnameName($in) +function getHostnameName($in) { if (empty($in)) { return Piwik_Translate('General_Unknown'); @@ -37,7 +39,7 @@ function Piwik_getHostnameName($in) * @param string $in hostname * @return string URL */ -function Piwik_getHostnameUrl($in) +function getHostnameUrl($in) { if ($in == DataTable::LABEL_SUMMARY_ROW) { return false; @@ -63,9 +65,9 @@ function Piwik_getHostnameUrl($in) * @param string $in hostname * @return string Real ISP name, IP (if IP address didn't resolve), or Unknown */ -function Piwik_Provider_getPrettyProviderName( $in ) +function getPrettyProviderName( $in ) { - $providerName = Piwik_getHostnameName($in); + $providerName = getHostnameName($in); $prettyNames = Common::getProviderNames(); diff --git a/plugins/Proxy/Controller.php b/plugins/Proxy/Controller.php index cf1b362c7b..d358908805 100644 --- a/plugins/Proxy/Controller.php +++ b/plugins/Proxy/Controller.php @@ -6,20 +6,21 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Proxy + * @package Proxy */ +namespace Piwik\Plugins\Proxy; + use Piwik\Piwik; use Piwik\Common; use Piwik\AssetManager; -use Piwik\Controller; use Piwik\Url; /** * Controller for proxy services * - * @package Piwik_Proxy + * @package Proxy */ -class Piwik_Proxy_Controller extends Controller +class Controller extends \Piwik\Controller { const TRANSPARENT_PNG_PIXEL = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='; diff --git a/plugins/Proxy/Proxy.php b/plugins/Proxy/Proxy.php index 47d085a70c..7c7959d0e1 100644 --- a/plugins/Proxy/Proxy.php +++ b/plugins/Proxy/Proxy.php @@ -6,17 +6,18 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Proxy + * @package Proxy */ +namespace Piwik\Plugins\Proxy; + use Piwik\Version; -use Piwik\Plugin; /** * Proxy services for the UI * - * @package Piwik_Proxy + * @package Proxy */ -class Piwik_Proxy extends Plugin +class Proxy extends \Piwik\Plugin { /** * Return information about this plugin. diff --git a/plugins/Referers/API.php b/plugins/Referers/API.php index f48d961acd..8e65899d1e 100644 --- a/plugins/Referers/API.php +++ b/plugins/Referers/API.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Referers + * @package Referers */ +namespace Piwik\Plugins\Referers; + +use Exception; use Piwik\API\ResponseBuilder; use Piwik\Archive; use Piwik\DataTable\Row; @@ -16,6 +19,7 @@ use Piwik\Piwik; use Piwik\Common; use Piwik\Date; use Piwik\DataTable; +use Piwik\Plugins\Referers\Archiver; /** * The Referrers API lets you access reports about Websites, Search engines, Keywords, Campaigns used to access your website. @@ -25,9 +29,9 @@ use Piwik\DataTable; * * The methods "getKeywordsForPageUrl" and "getKeywordsForPageTitle" are used to output the top keywords used to find a page. * Check out the widget <a href='http://demo.piwik.org/index.php?module=Widgetize&action=iframe&moduleToWidgetize=Referers&actionToWidgetize=getKeywordsForPage&idSite=7&period=day&date=2011-02-15&disableLink=1' target='_blank'>"Top keywords used to find this page"</a> that you can easily re-use on your website. - * @package Piwik_Referers + * @package Referers */ -class Piwik_Referers_API +class API { static private $instance = null; @@ -78,7 +82,7 @@ class Piwik_Referers_API * @return DataTable */ public function getRefererType($idSite, $period, $date, $segment = false, $typeReferer = false, - $idSubtable = false, $expanded = false) + $idSubtable = false, $expanded = false) { // if idSubtable is supplied, interpret idSubtable as referrer type and return correct report if ($idSubtable !== false) { @@ -103,7 +107,7 @@ class Piwik_Referers_API } // get visits by referrer type - $dataTable = $this->getDataTable(Piwik_Referers_Archiver::REFERER_TYPE_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Archiver::REFERER_TYPE_RECORD_NAME, $idSite, $period, $date, $segment); if ($typeReferer !== false) // filter for a specific referrer type { @@ -117,7 +121,7 @@ class Piwik_Referers_API } // set referrer type column to readable value - $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_getRefererTypeLabel')); + $dataTable->queueFilter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getRefererTypeLabel')); return $dataTable; } @@ -144,14 +148,14 @@ class Piwik_Referers_API public function getKeywords($idSite, $period, $date, $segment = false, $expanded = false) { - $dataTable = $this->getDataTable(Piwik_Referers_Archiver::KEYWORDS_RECORD_NAME, $idSite, $period, $date, $segment, $expanded); + $dataTable = $this->getDataTable(Archiver::KEYWORDS_RECORD_NAME, $idSite, $period, $date, $segment, $expanded); $dataTable = $this->handleKeywordNotDefined($dataTable); return $dataTable; } protected function handleKeywordNotDefined($dataTable) { - $dataTable->queueFilter('ColumnCallbackReplace', array('label', array('Piwik_Referers_API', 'getCleanKeyword'))); + $dataTable->queueFilter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\API::getCleanKeyword')); return $dataTable; } @@ -182,7 +186,6 @@ class Piwik_Referers_API $table = $this->getKeywords($idSite, $period, $date, $segment); $this->filterOutKeywordNotDefined($table); return $this->getLabelsFromTable($table); - } public function getKeywordsForPageTitle($idSite, $period, $date, $title) @@ -227,31 +230,31 @@ class Piwik_Referers_API public function getSearchEnginesFromKeywordId($idSite, $period, $date, $idSubtable, $segment = false) { - $dataTable = $this->getDataTable(Piwik_Referers_Archiver::KEYWORDS_RECORD_NAME, $idSite, $period, $date, $segment, $expanded = false, $idSubtable); - $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', 'Piwik_getSearchEngineUrlFromName')); - $dataTable->queueFilter('MetadataCallbackAddMetadata', array('url', 'logo', 'Piwik_getSearchEngineLogoFromUrl')); + $dataTable = $this->getDataTable(Archiver::KEYWORDS_RECORD_NAME, $idSite, $period, $date, $segment, $expanded = false, $idSubtable); + $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', __NAMESPACE__ . '\getSearchEngineUrlFromName')); + $dataTable->queueFilter('MetadataCallbackAddMetadata', array('url', 'logo', __NAMESPACE__ . '\getSearchEngineLogoFromUrl')); // get the keyword and create the URL to the search result page $keywords = $this->getKeywords($idSite, $period, $date, $segment); $subTable = $keywords->getRowFromIdSubDataTable($idSubtable); if ($subTable) { $keyword = $subTable->getColumn('label'); - $dataTable->queueFilter('MetadataCallbackReplace', array('url', 'Piwik_getSearchEngineUrlFromUrlAndKeyword', array($keyword))); + $dataTable->queueFilter('MetadataCallbackReplace', array('url', __NAMESPACE__ . '\getSearchEngineUrlFromUrlAndKeyword', array($keyword))); } return $dataTable; } public function getSearchEngines($idSite, $period, $date, $segment = false, $expanded = false) { - $dataTable = $this->getDataTable(Piwik_Referers_Archiver::SEARCH_ENGINES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded); - $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', 'Piwik_getSearchEngineUrlFromName')); - $dataTable->queueFilter('MetadataCallbackAddMetadata', array('url', 'logo', 'Piwik_getSearchEngineLogoFromUrl')); + $dataTable = $this->getDataTable(Archiver::SEARCH_ENGINES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded); + $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', __NAMESPACE__ . '\getSearchEngineUrlFromName')); + $dataTable->queueFilter('MetadataCallbackAddMetadata', array('url', 'logo', __NAMESPACE__ . '\getSearchEngineLogoFromUrl')); return $dataTable; } public function getKeywordsFromSearchEngineId($idSite, $period, $date, $idSubtable, $segment = false) { - $dataTable = $this->getDataTable(Piwik_Referers_Archiver::SEARCH_ENGINES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded = false, $idSubtable); + $dataTable = $this->getDataTable(Archiver::SEARCH_ENGINES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded = false, $idSubtable); // get the search engine and create the URL to the search result page $searchEngines = $this->getSearchEngines($idSite, $period, $date, $segment); @@ -274,7 +277,7 @@ class Piwik_Referers_API if (!empty($subTableRow)) { $searchEngineUrl = $subTableRow->getMetadata('url'); - $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', 'Piwik_getSearchEngineUrlFromKeywordAndUrl', array($searchEngineUrl))); + $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', __NAMESPACE__ . '\getSearchEngineUrlFromKeywordAndUrl', array($searchEngineUrl))); } $dataTable = $this->handleKeywordNotDefined($dataTable); return $dataTable; @@ -282,29 +285,29 @@ class Piwik_Referers_API public function getCampaigns($idSite, $period, $date, $segment = false, $expanded = false) { - $dataTable = $this->getDataTable(Piwik_Referers_Archiver::CAMPAIGNS_RECORD_NAME, $idSite, $period, $date, $segment, $expanded); + $dataTable = $this->getDataTable(Archiver::CAMPAIGNS_RECORD_NAME, $idSite, $period, $date, $segment, $expanded); return $dataTable; } public function getKeywordsFromCampaignId($idSite, $period, $date, $idSubtable, $segment = false) { - $dataTable = $this->getDataTable(Piwik_Referers_Archiver::CAMPAIGNS_RECORD_NAME, $idSite, $period, $date, $segment, $expanded = false, $idSubtable); + $dataTable = $this->getDataTable(Archiver::CAMPAIGNS_RECORD_NAME, $idSite, $period, $date, $segment, $expanded = false, $idSubtable); return $dataTable; } public function getWebsites($idSite, $period, $date, $segment = false, $expanded = false) { - $dataTable = $this->getDataTable(Piwik_Referers_Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded); + $dataTable = $this->getDataTable(Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded); return $dataTable; } public function getUrlsFromWebsiteId($idSite, $period, $date, $idSubtable, $segment = false) { - $dataTable = $this->getDataTable(Piwik_Referers_Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded = false, $idSubtable); + $dataTable = $this->getDataTable(Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded = false, $idSubtable); // the htmlspecialchars_decode call is for BC for before 1.1 // as the Referrer URL was previously encoded in the log tables, but is now recorded raw $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', create_function('$label', 'return htmlspecialchars_decode($label);'))); - $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_getPathFromUrl')); + $dataTable->queueFilter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getPathFromUrl')); return $dataTable; } @@ -323,17 +326,17 @@ class Piwik_Referers_API { require PIWIK_INCLUDE_PATH . '/core/DataFiles/Socials.php'; - $dataTable = $this->getDataTable( Piwik_Referers_Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded); + $dataTable = $this->getDataTable(Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded); - $dataTable->filter('ColumnCallbackDeleteRow', array('label', 'Piwik_Referrers_isSocialUrl')); + $dataTable->filter('ColumnCallbackDeleteRow', array('label', __NAMESPACE__ . '\isSocialUrl')); - $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'url', 'Piwik_Referrers_cleanSocialUrl')); - $dataTable->filter('GroupBy', array('label', 'Piwik_Referrers_getSocialNetworkFromDomain')); + $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'url', __NAMESPACE__ . '\cleanSocialUrl')); + $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getSocialNetworkFromDomain')); $this->setSocialIdSubtables($dataTable); $this->removeSubtableMetadata($dataTable); - $dataTable->queueFilter('MetadataCallbackAddMetadata', array('url', 'logo', 'Piwik_getSocialsLogoFromUrl')); + $dataTable->queueFilter('MetadataCallbackAddMetadata', array('url', 'logo', __NAMESPACE__ . '\getSocialsLogoFromUrl')); return $dataTable; } @@ -356,7 +359,7 @@ class Piwik_Referers_API { require PIWIK_INCLUDE_PATH . '/core/DataFiles/Socials.php'; - $dataTable = $this->getDataTable( Piwik_Referers_Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded = true); + $dataTable = $this->getDataTable(Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded = true); // get the social network domain referred to by $idSubtable $social = false; @@ -372,7 +375,7 @@ class Piwik_Referers_API } // filter out everything but social network indicated by $idSubtable - $dataTable->filter('ColumnCallbackDeleteRow', array('label', 'Piwik_Referrers_isSocialUrl', array($social))); + $dataTable->filter('ColumnCallbackDeleteRow', array('label', __NAMESPACE__ . '\isSocialUrl', array($social))); // merge the datatable's subtables which contain the individual URLs $dataTable = $dataTable->mergeSubtables(); @@ -381,7 +384,7 @@ class Piwik_Referers_API $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'url')); // prettify the DataTable - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_Referrers_removeUrlProtocol')); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\removeUrlProtocol')); $dataTable->filter('Sort', array(Metrics::INDEX_NB_VISITS, 'desc', $naturalSort = false, $expanded)); $dataTable->queueFilter('ReplaceColumnNames'); @@ -390,27 +393,27 @@ class Piwik_Referers_API public function getNumberOfDistinctSearchEngines($idSite, $period, $date, $segment = false) { - return $this->getNumeric(Piwik_Referers_Archiver::METRIC_DISTINCT_SEARCH_ENGINE_RECORD_NAME, $idSite, $period, $date, $segment); + return $this->getNumeric(Archiver::METRIC_DISTINCT_SEARCH_ENGINE_RECORD_NAME, $idSite, $period, $date, $segment); } public function getNumberOfDistinctKeywords($idSite, $period, $date, $segment = false) { - return $this->getNumeric(Piwik_Referers_Archiver::METRIC_DISTINCT_KEYWORD_RECORD_NAME, $idSite, $period, $date, $segment); + return $this->getNumeric(Archiver::METRIC_DISTINCT_KEYWORD_RECORD_NAME, $idSite, $period, $date, $segment); } public function getNumberOfDistinctCampaigns($idSite, $period, $date, $segment = false) { - return $this->getNumeric(Piwik_Referers_Archiver::METRIC_DISTINCT_CAMPAIGN_RECORD_NAME, $idSite, $period, $date, $segment); + return $this->getNumeric(Archiver::METRIC_DISTINCT_CAMPAIGN_RECORD_NAME, $idSite, $period, $date, $segment); } public function getNumberOfDistinctWebsites($idSite, $period, $date, $segment = false) { - return $this->getNumeric(Piwik_Referers_Archiver::METRIC_DISTINCT_WEBSITE_RECORD_NAME, $idSite, $period, $date, $segment); + return $this->getNumeric(Archiver::METRIC_DISTINCT_WEBSITE_RECORD_NAME, $idSite, $period, $date, $segment); } public function getNumberOfDistinctWebsitesUrls($idSite, $period, $date, $segment = false) { - return $this->getNumeric(Piwik_Referers_Archiver::METRIC_DISTINCT_URLS_RECORD_NAME, $idSite, $period, $date, $segment); + return $this->getNumeric(Archiver::METRIC_DISTINCT_URLS_RECORD_NAME, $idSite, $period, $date, $segment); } private function getNumeric($name, $idSite, $period, $date, $segment) diff --git a/plugins/Referers/Archiver.php b/plugins/Referers/Archiver.php index 4da6a19d07..5c7d700eea 100644 --- a/plugins/Referers/Archiver.php +++ b/plugins/Referers/Archiver.php @@ -1,10 +1,4 @@ <?php -use Piwik\Common; -use Piwik\Config; -use Piwik\Metrics; -use Piwik\DataArray; -use Piwik\PluginsArchiver; - /** * Piwik - Open source web analytics * @@ -12,10 +6,20 @@ use Piwik\PluginsArchiver; * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Referers + * @package Referers */ +namespace Piwik\Plugins\Referers; + +use Exception; +use Piwik\Common; +use Piwik\Config; +use Piwik\Metrics; +use Piwik\DataArray; +use Piwik\Plugins\Referers\API; +use Piwik\PluginsArchiver; + -class Piwik_Referers_Archiver extends PluginsArchiver +class Archiver extends PluginsArchiver { const SEARCH_ENGINES_RECORD_NAME = 'Referers_keywordBySearchEngine'; const KEYWORDS_RECORD_NAME = 'Referers_searchEngineByKeyword'; @@ -88,7 +92,7 @@ class Piwik_Referers_Archiver extends PluginsArchiver switch ($row['referer_type']) { case Common::REFERER_TYPE_SEARCH_ENGINE: if (empty($row['referer_keyword'])) { - $row['referer_keyword'] = Piwik_Referers_API::LABEL_KEYWORD_NOT_DEFINED; + $row['referer_keyword'] = API::LABEL_KEYWORD_NOT_DEFINED; } $searchEnginesArray = $this->getDataArray(self::SEARCH_ENGINES_RECORD_NAME); $searchEnginesArray->sumMetricsVisits($row['referer_name'], $row); @@ -161,7 +165,7 @@ class Piwik_Referers_Archiver extends PluginsArchiver switch ($row['referer_type']) { case Common::REFERER_TYPE_SEARCH_ENGINE: if (empty($row['referer_keyword'])) { - $row['referer_keyword'] = Piwik_Referers_API::LABEL_KEYWORD_NOT_DEFINED; + $row['referer_keyword'] = API::LABEL_KEYWORD_NOT_DEFINED; } $this->getDataArray(self::SEARCH_ENGINES_RECORD_NAME)->sumMetricsGoals($row['referer_name'], $row); diff --git a/plugins/Referers/Controller.php b/plugins/Referers/Controller.php index 1e31b6dd41..17da96fe90 100644 --- a/plugins/Referers/Controller.php +++ b/plugins/Referers/Controller.php @@ -6,23 +6,24 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Referers + * @package Referers */ +namespace Piwik\Plugins\Referers; + use Piwik\API\Request; use Piwik\Metrics; use Piwik\Period\Range; use Piwik\Piwik; use Piwik\Common; -use Piwik\Controller; use Piwik\ViewDataTable; use Piwik\View; use Piwik\Url; /** * - * @package Piwik_Referers + * @package Referers */ -class Piwik_Referers_Controller extends Controller +class Controller extends \Piwik\Controller { public function index() { @@ -305,7 +306,7 @@ class Piwik_Referers_Controller extends Controller $view->documentation = Piwik_Translate('Referers_EvolutionDocumentation') . '<br />' . Piwik_Translate('General_BrokenDownReportDocumentation') . '<br />' . Piwik_Translate('Referers_EvolutionDocumentationMoreInfo', '"' - . Piwik_Translate('Referers_DetailsByRefererType') . '"'); + . Piwik_Translate('Referers_DetailsByRefererType') . '"'); return $this->renderView($view, $fetch); } @@ -414,7 +415,7 @@ function DisplayTopKeywords($url = "") <p> <b>Example API URL</b> - For example if you would like to get the top 10 keywords, used last week, to land on the page <a target='_blank' href='$topPageUrl'>$topPageUrl</a>, in format JSON: you would dynamically fetch the data using <a target='_blank' href='$jsonRequest&url=" . urlencode($topPageUrl) . "'>this API request URL</a>. Make sure you encode the 'url' parameter in the URL.</p> - + <p><b>PHP Function ready to use!</b> - If you use PHP on your website, we have prepared a small code snippet that you can copy paste in your Website PHP files. You can then simply call the function <code>DisplayTopKeywords();</code> anywhere in your template, at the bottom of the content or in your blog sidebar. If you run this code in your page $topPageUrl, it would output the following:"; @@ -458,7 +459,6 @@ function DisplayTopKeywords($url = "") <br/>On medium to large traffic websites, we recommend to cache this data, as to minimize the performance impact of calling the Piwik API on each page view. </p> "; - } /** @@ -469,7 +469,7 @@ function DisplayTopKeywords($url = "") */ public static function getTranslatedReferrerTypeLabel($typeReferrer) { - $label = Piwik_getRefererTypeLabel($typeReferrer); + $label = getRefererTypeLabel($typeReferrer); return Piwik_Translate($label); } diff --git a/plugins/Referers/Referers.php b/plugins/Referers/Referers.php index cd8ce1844e..5f6451548b 100644 --- a/plugins/Referers/Referers.php +++ b/plugins/Referers/Referers.php @@ -6,12 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Referers + * @package Referers */ +namespace Piwik\Plugins\Referers; + use Piwik\ArchiveProcessor; use Piwik\Piwik; use Piwik\Common; -use Piwik\Plugin; +use Piwik\Plugins\Referers\Archiver; use Piwik\WidgetsList; /** @@ -20,9 +22,9 @@ use Piwik\WidgetsList; require_once PIWIK_INCLUDE_PATH . '/plugins/Referers/functions.php'; /** - * @package Piwik_Referers + * @package Referers */ -class Piwik_Referers extends Plugin +class Referers extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered @@ -30,13 +32,13 @@ class Piwik_Referers extends Plugin public function getListHooksRegistered() { $hooks = array( - 'ArchiveProcessing_Day.compute' => 'archiveDay', - 'ArchiveProcessing_Period.compute' => 'archivePeriod', - 'WidgetsList.add' => 'addWidgets', - 'Menu.add' => 'addMenus', - 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', - 'API.getReportMetadata' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ArchiveProcessing_Day.compute' => 'archiveDay', + 'ArchiveProcessing_Period.compute' => 'archivePeriod', + 'WidgetsList.add' => 'addWidgets', + 'Menu.add' => 'addMenus', + 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', + 'API.getReportMetadata' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); return $hooks; @@ -178,7 +180,7 @@ class Piwik_Referers extends Plugin 'segment' => 'referrerType', 'acceptedValues' => 'direct, search, website, campaign', 'sqlSegment' => 'log_visit.referer_type', - 'sqlFilter' => 'Piwik_getRefererTypeFromShortName', + 'sqlFilter' => __NAMESPACE__ . '\getRefererTypeFromShortName', ); $segments[] = array( 'type' => 'dimension', @@ -274,7 +276,7 @@ class Piwik_Referers extends Plugin */ public function archiveDay(ArchiveProcessor\Day $archiveProcessor) { - $archiving = new Piwik_Referers_Archiver($archiveProcessor); + $archiving = new Archiver($archiveProcessor); if ($archiving->shouldArchive()) { $archiving->archiveDay(); } @@ -286,8 +288,8 @@ class Piwik_Referers extends Plugin */ public function archivePeriod(ArchiveProcessor\Period $archiveProcessor) { - $archiving = new Piwik_Referers_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archivePeriod(); } } @@ -381,9 +383,9 @@ class Piwik_Referers extends Plugin private function getDisplayPropertiesForGetSearchEnginesFromKeywordId() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik_Translate('Referers_ColumnSearchEngine')) + 'translations' => array('label' => Piwik_Translate('Referers_ColumnSearchEngine')) ); } @@ -407,9 +409,9 @@ class Piwik_Referers extends Plugin private function getDisplayPropertiesForGetKeywordsFromSearchEngineId() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik_Translate('Referers_ColumnKeyword')) + 'translations' => array('label' => Piwik_Translate('Referers_ColumnKeyword')) ); } @@ -457,20 +459,20 @@ class Piwik_Referers extends Plugin { return array( 'show_exclude_low_population' => false, - 'filter_limit' => 10, - 'show_goals' => true, - 'translations' => array('label' => Piwik_Translate('Referers_ColumnWebsitePage')) + 'filter_limit' => 10, + 'show_goals' => true, + 'translations' => array('label' => Piwik_Translate('Referers_ColumnWebsitePage')) ); } private function getDisplayPropertiesForGetCampaigns() { $result = array( - 'subtable_controller_action' => 'getKeywordsFromCampaignId', + 'subtable_controller_action' => 'getKeywordsFromCampaignId', 'show_exclude_low_population' => false, - 'show_goals' => true, - 'filter_limit' => 25, - 'translations' => array('label' => Piwik_Translate('Referers_ColumnCampaign')), + 'show_goals' => true, + 'filter_limit' => 25, + 'translations' => array('label' => Piwik_Translate('Referers_ColumnCampaign')), ); if (Common::getRequestVar('viewDataTable', false) != 'graphEvolution') { @@ -487,19 +489,19 @@ class Piwik_Referers extends Plugin private function getDisplayPropertiesForGetKeywordsFromCampaignId() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik_Translate('Referers_ColumnKeyword')) + 'translations' => array('label' => Piwik_Translate('Referers_ColumnKeyword')) ); } private function getDisplayPropertiesForGetUrlsFromWebsiteId() { return array( - 'show_search' => false, + 'show_search' => false, 'show_exclude_low_population' => false, - 'translations' => array('label' => Piwik_Translate('Referers_ColumnWebsitePage')), - 'tooltip_metadata_name' => 'url' + 'translations' => array('label' => Piwik_Translate('Referers_ColumnWebsitePage')), + 'tooltip_metadata_name' => 'url' ); } diff --git a/plugins/Referers/functions.php b/plugins/Referers/functions.php index b7038fb360..0a6a50a72c 100644 --- a/plugins/Referers/functions.php +++ b/plugins/Referers/functions.php @@ -6,9 +6,12 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Referers + * @package Referers */ +namespace Piwik\Plugins\Referers; + use Piwik\Common; +use Piwik\Plugins\Referers\API; /** * Returns path component from a URL @@ -16,7 +19,7 @@ use Piwik\Common; * @param string $url * @return string path */ -function Piwik_getPathFromUrl($url) +function getPathFromUrl($url) { $path = Common::getPathAndQueryFromUrl($url); if (empty($path)) { @@ -31,7 +34,7 @@ function Piwik_getPathFromUrl($url) * @param string $url e.g. http://www.facebook.com/?sdlfk=lksdfj * @return string|false e.g. facebook.com */ -function Piwik_Referrers_cleanSocialUrl($url) +function cleanSocialUrl($url) { $segment = '[^.:\/]+'; preg_match('/(?:https?:\/\/)?(?:' . $segment . '\.)?(' . $segment . '(?:\.' . $segment . ')+)/', $url, $matches); @@ -44,9 +47,9 @@ function Piwik_Referrers_cleanSocialUrl($url) * @param string $url * @return string */ -function Piwik_Referrers_getSocialNetworkFromDomain($url) +function getSocialNetworkFromDomain($url) { - $domain = Piwik_Referrers_cleanSocialUrl($url); + $domain = cleanSocialUrl($url); if (isset($GLOBALS['Piwik_socialUrl'][$domain])) { return $GLOBALS['Piwik_socialUrl'][$domain]; @@ -63,9 +66,9 @@ function Piwik_Referrers_getSocialNetworkFromDomain($url) * for any. * @return bool */ -function Piwik_Referrers_isSocialUrl($url, $socialName = false) +function isSocialUrl($url, $socialName = false) { - $domain = Piwik_Referrers_cleanSocialUrl($url); + $domain = cleanSocialUrl($url); if (isset($GLOBALS['Piwik_socialUrl'][$domain]) && ($socialName === false @@ -83,9 +86,9 @@ function Piwik_Referrers_isSocialUrl($url, $socialName = false) * @return string path * @see plugins/Referers/images/socials/ */ -function Piwik_getSocialsLogoFromUrl($domain) +function getSocialsLogoFromUrl($domain) { - $domain = Piwik_Referrers_cleanSocialUrl($domain); + $domain = cleanSocialUrl($domain); if (isset($GLOBALS['Piwik_socialUrl'][$domain])) { // image names are by first domain in list, so make sure we use the first if $domain isn't it @@ -112,7 +115,7 @@ function Piwik_getSocialsLogoFromUrl($domain) * @param string $name * @return string URL */ -function Piwik_getSearchEngineUrlFromName($name) +function getSearchEngineUrlFromName($name) { $searchEngineNames = Common::getSearchEngineNames(); if (isset($searchEngineNames[$name])) { @@ -129,7 +132,7 @@ function Piwik_getSearchEngineUrlFromName($name) * @param string $url * @return string host */ -function Piwik_getSearchEngineHostFromUrl($url) +function getSearchEngineHostFromUrl($url) { $url = substr($url, strpos($url, '//') + 2); if (($p = strpos($url, '/')) !== false) { @@ -145,10 +148,10 @@ function Piwik_getSearchEngineHostFromUrl($url) * @return string path * @see plugins/Referers/images/searchEnginges/ */ -function Piwik_getSearchEngineLogoFromUrl($url) +function getSearchEngineLogoFromUrl($url) { $pathInPiwik = 'plugins/Referers/images/searchEngines/%s.png'; - $pathWithCode = sprintf($pathInPiwik, Piwik_getSearchEngineHostFromUrl($url)); + $pathWithCode = sprintf($pathInPiwik, getSearchEngineHostFromUrl($url)); $absolutePath = PIWIK_INCLUDE_PATH . '/' . $pathWithCode; if (file_exists($absolutePath)) { return $pathWithCode; @@ -162,7 +165,7 @@ function Piwik_getSearchEngineLogoFromUrl($url) * @param string $url * @return string host */ -function Piwik_getSearchEngineHostPathFromUrl($url) +function getSearchEngineHostPathFromUrl($url) { $url = substr($url, strpos($url, '//') + 2); return $url; @@ -177,15 +180,15 @@ function Piwik_getSearchEngineHostPathFromUrl($url) * @param string $keyword Keyword, e.g., web+analytics * @return string URL, e.g., http://search.piwik.org/q=web+analytics */ -function Piwik_getSearchEngineUrlFromUrlAndKeyword($url, $keyword) +function getSearchEngineUrlFromUrlAndKeyword($url, $keyword) { - if ($keyword === Piwik_Referers_API::LABEL_KEYWORD_NOT_DEFINED) { + if ($keyword === API::LABEL_KEYWORD_NOT_DEFINED) { return 'http://piwik.org/faq/general/#faq_144'; } $searchEngineUrls = Common::getSearchEngineUrls(); $keyword = urlencode($keyword); $keyword = str_replace(urlencode('+'), urlencode(' '), $keyword); - $path = @$searchEngineUrls[Piwik_getSearchEngineHostPathFromUrl($url)][2]; + $path = @$searchEngineUrls[getSearchEngineHostPathFromUrl($url)][2]; if (empty($path)) { return false; } @@ -196,15 +199,15 @@ function Piwik_getSearchEngineUrlFromUrlAndKeyword($url, $keyword) /** * Return search engine URL for keyword and URL * - * @see Piwik_getSearchEngineUrlFromUrlAndKeyword() + * @see Piwik_getSearchEngineUrlFromUrlAndKeyword(getSearchEngineUrlFromUrlAndKeyword * * @param string $keyword Keyword, e.g., web+analytics * @param string $url Domain name, e.g., search.piwik.org * @return string URL, e.g., http://search.piwik.org/q=web+analytics */ -function Piwik_getSearchEngineUrlFromKeywordAndUrl($keyword, $url) +function getSearchEngineUrlFromKeywordAndUrl($keyword, $url) { - return Piwik_getSearchEngineUrlFromUrlAndKeyword($url, $keyword); + return getSearchEngineUrlFromUrlAndKeyword($url, $keyword); } /** @@ -213,7 +216,7 @@ function Piwik_getSearchEngineUrlFromKeywordAndUrl($keyword, $url) * @param string $label * @return string Referrer type */ -function Piwik_getRefererTypeLabel($label) +function getRefererTypeLabel($label) { $indexTranslation = ''; switch ($label) { @@ -243,7 +246,7 @@ function Piwik_getRefererTypeLabel($label) * @throws Exception * @return string */ -function Piwik_getRefererTypeFromShortName($name) +function getRefererTypeFromShortName($name) { $map = array( Common::REFERER_TYPE_SEARCH_ENGINE => 'search', @@ -257,7 +260,7 @@ function Piwik_getRefererTypeFromShortName($name) if ($found = array_search($name, $map)) { return $found; } - throw new Exception("Referrer type '$name' is not valid."); + throw new \Exception("Referrer type '$name' is not valid."); } /** @@ -266,7 +269,7 @@ function Piwik_getRefererTypeFromShortName($name) * @param string $url * @return string */ -function Piwik_Referrers_removeUrlProtocol($url) +function removeUrlProtocol($url) { if (preg_match('/^[a-zA-Z_-]+:\/\//', $url, $matches)) { return substr($url, strlen($matches[0])); diff --git a/plugins/SEO/API.php b/plugins/SEO/API.php index 185561df44..74dd10ac56 100644 --- a/plugins/SEO/API.php +++ b/plugins/SEO/API.php @@ -6,10 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SEO + * @package SEO */ +namespace Piwik\Plugins\SEO; + use Piwik\Piwik; use Piwik\DataTable; +use Piwik\Plugins\SEO\MajesticClient; +use Piwik\Plugins\SEO\RankChecker; /** * @see plugins/Referers/functions.php @@ -20,14 +24,14 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Referers/functions.php'; * The SEO API lets you access a list of SEO metrics for the specified URL: Google Pagerank, Goolge/Bing indexed pages * Alexa Rank, age of the Domain name and count of DMOZ entries. * - * @package Piwik_SEO + * @package SEO */ -class Piwik_SEO_API +class API { static private $instance = null; /** - * @return Piwik_SEO_API + * @return \Piwik\Plugins\SEO\API */ static public function getInstance() { @@ -46,29 +50,29 @@ class Piwik_SEO_API public function getRank($url) { Piwik::checkUserHasSomeViewAccess(); - $rank = new Piwik_SEO_RankChecker($url); + $rank = new RankChecker($url); - $linkToMajestic = Piwik_SEO_MajesticClient::getLinkForUrl($url); + $linkToMajestic = MajesticClient::getLinkForUrl($url); $data = array( 'Google PageRank' => array( 'rank' => $rank->getPageRank(), - 'logo' => Piwik_getSearchEngineLogoFromUrl('http://google.com'), + 'logo' => \Piwik\Plugins\Referers\getSearchEngineLogoFromUrl('http://google.com'), 'id' => 'pagerank' ), Piwik_Translate('SEO_Google_IndexedPages') => array( 'rank' => $rank->getIndexedPagesGoogle(), - 'logo' => Piwik_getSearchEngineLogoFromUrl('http://google.com'), + 'logo' => \Piwik\Plugins\Referers\getSearchEngineLogoFromUrl('http://google.com'), 'id' => 'google-index', ), Piwik_Translate('SEO_Bing_IndexedPages') => array( 'rank' => $rank->getIndexedPagesBing(), - 'logo' => Piwik_getSearchEngineLogoFromUrl('http://bing.com'), + 'logo' => \Piwik\Plugins\Referers\getSearchEngineLogoFromUrl('http://bing.com'), 'id' => 'bing-index', ), Piwik_Translate('SEO_AlexaRank') => array( 'rank' => $rank->getAlexaRank(), - 'logo' => Piwik_getSearchEngineLogoFromUrl('http://alexa.com'), + 'logo' => \Piwik\Plugins\Referers\getSearchEngineLogoFromUrl('http://alexa.com'), 'id' => 'alexa', ), Piwik_Translate('SEO_DomainAge') => array( @@ -95,7 +99,7 @@ class Piwik_SEO_API // Add DMOZ only if > 0 entries found $dmozRank = array( 'rank' => $rank->getDmoz(), - 'logo' => Piwik_getSearchEngineLogoFromUrl('http://dmoz.org'), + 'logo' => \Piwik\Plugins\Referers\getSearchEngineLogoFromUrl('http://dmoz.org'), 'id' => 'dmoz', ); if ($dmozRank['rank'] > 0) { diff --git a/plugins/SEO/Controller.php b/plugins/SEO/Controller.php index fc51c128f9..ee23bde1f4 100644 --- a/plugins/SEO/Controller.php +++ b/plugins/SEO/Controller.php @@ -6,18 +6,21 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SEO + * @package SEO */ +namespace Piwik\Plugins\SEO; + use Piwik\Common; use Piwik\DataTable\Renderer; -use Piwik\Controller; +use Piwik\Plugins\SEO\API; use Piwik\View; use Piwik\Site; +use Piwik\Plugins\SEO\RankChecker; /** - * @package Piwik_SEO + * @package SEO */ -class Piwik_SEO_Controller extends Controller +class Controller extends \Piwik\Controller { function getRank() { @@ -34,10 +37,10 @@ class Piwik_SEO_Controller extends Controller $url = $site->getMainUrl(); } - $dataTable = Piwik_SEO_API::getInstance()->getRank($url); + $dataTable = API::getInstance()->getRank($url); $view = new View('@SEO/getRank'); - $view->urlToRank = Piwik_SEO_RankChecker::extractDomainFromUrl($url); + $view->urlToRank = RankChecker::extractDomainFromUrl($url); /** @var \Piwik\DataTable\Renderer\Php $renderer */ $renderer = Renderer::factory('php'); diff --git a/plugins/SEO/MajesticClient.php b/plugins/SEO/MajesticClient.php index 34f16a038e..1f89009121 100644 --- a/plugins/SEO/MajesticClient.php +++ b/plugins/SEO/MajesticClient.php @@ -6,8 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SEO + * @package SEO */ +namespace Piwik\Plugins\SEO; + use Piwik\Common; use Piwik\Http; @@ -16,7 +18,7 @@ use Piwik\Http; * * Hides the HTTP request sending logic. */ -class Piwik_SEO_MajesticClient +class MajesticClient { const API_BASE = 'http://simpleapi.majesticseo.com/sapi/'; const API_KEY = 'ETHPYY'; // please only use this key within Piwik diff --git a/plugins/SEO/RankChecker.php b/plugins/SEO/RankChecker.php index cdc858176c..74d8afda3b 100644 --- a/plugins/SEO/RankChecker.php +++ b/plugins/SEO/RankChecker.php @@ -6,10 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SEO + * @package SEO */ +namespace Piwik\Plugins\SEO; + +use Exception; use Piwik\Piwik; use Piwik\Http; +use Piwik\Plugins\SEO\MajesticClient; /** * The functions below are derived/adapted from GetRank.org's @@ -18,9 +22,9 @@ use Piwik\Http; * @copyright Copyright (C) 2007 - 2010 GetRank.Org All rights reserved. * @link http://www.getrank.org/free-pagerank-script/ * @license GPL - * @package Piwik_SEO + * @package SEO */ -class Piwik_SEO_RankChecker +class RankChecker { private $url; private $majesticInfo = null; @@ -185,7 +189,7 @@ class Piwik_SEO_RankChecker try { $majesticInfo = $this->getMajesticInfo(); return $majesticInfo['backlink_count']; - } catch(Exception $e) { + } catch (Exception $e) { Piwik::log($e->getMessage()); return 0; } @@ -201,7 +205,7 @@ class Piwik_SEO_RankChecker try { $majesticInfo = $this->getMajesticInfo(); return $majesticInfo['referrer_domains_count']; - } catch(Exception $e) { + } catch (Exception $e) { Piwik::log($e->getMessage()); return 0; } @@ -366,7 +370,7 @@ class Piwik_SEO_RankChecker private function getMajesticInfo() { if ($this->majesticInfo === null) { - $client = new Piwik_SEO_MajesticClient(); + $client = new MajesticClient(); $this->majesticInfo = $client->getBacklinkStats($this->url); } diff --git a/plugins/SEO/SEO.php b/plugins/SEO/SEO.php index 505f8de521..dd488bef97 100644 --- a/plugins/SEO/SEO.php +++ b/plugins/SEO/SEO.php @@ -6,16 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SEO + * @package SEO */ +namespace Piwik\Plugins\SEO; + use Piwik\Version; -use Piwik\Plugin; use Piwik\WidgetsList; /** - * @package Piwik_SEO + * @package SEO */ -class Piwik_SEO extends Plugin +class SEO extends \Piwik\Plugin { /** * @see Piwik_Plugin::getInformation diff --git a/plugins/SecurityInfo/Controller.php b/plugins/SecurityInfo/Controller.php index 7195185fdd..fd7c29c981 100644 --- a/plugins/SecurityInfo/Controller.php +++ b/plugins/SecurityInfo/Controller.php @@ -6,16 +6,18 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SecurityInfo + * @package SecurityInfo */ -use Piwik\Controller\Admin; +namespace Piwik\Plugins\SecurityInfo; + +use PhpSecInfo; use Piwik\Piwik; use Piwik\View; /** - * @package Piwik_SecurityInfo + * @package SecurityInfo */ -class Piwik_SecurityInfo_Controller extends Admin +class Controller extends \Piwik\Controller\Admin { function index() { diff --git a/plugins/SecurityInfo/SecurityInfo.php b/plugins/SecurityInfo/SecurityInfo.php index 785247d2a2..4d5bacf07d 100644 --- a/plugins/SecurityInfo/SecurityInfo.php +++ b/plugins/SecurityInfo/SecurityInfo.php @@ -6,16 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SecurityInfo + * @package SecurityInfo */ +namespace Piwik\Plugins\SecurityInfo; + use Piwik\Piwik; -use Piwik\Plugin; /** * - * @package Piwik_SecurityInfo + * @package SecurityInfo */ -class Piwik_SecurityInfo extends Plugin +class SecurityInfo extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php index c8bb844a09..1dbc8b0811 100644 --- a/plugins/SegmentEditor/API.php +++ b/plugins/SegmentEditor/API.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SegmentEditor + * @package SegmentEditor */ +namespace Piwik\Plugins\SegmentEditor; + +use Exception; use Piwik\Piwik; use Piwik\Common; use Piwik\Date; @@ -16,16 +19,16 @@ use Piwik\Segment; /** * The SegmentEditor API lets you add, update, delete custom Segments, and list saved segments.a * - * @package Piwik_SegmentEditor + * @package SegmentEditor */ -class Piwik_SegmentEditor_API +class API { const DELETE_SEGMENT_EVENT = 'SegmentEditor.delete'; static private $instance = null; /** - * @return Piwik_SegmentEditor_API + * @return \Piwik\Plugins\SegmentEditor\API */ static public function getInstance() { @@ -116,7 +119,7 @@ class Piwik_SegmentEditor_API protected function checkUserIsNotAnonymous() { - if(Piwik::isUserIsAnonymous()) { + if (Piwik::isUserIsAnonymous()) { throw new Exception("To create, edit or delete Custom Segments, please sign in first."); } } @@ -229,8 +232,8 @@ class Piwik_SegmentEditor_API throw new Exception("idSegment should be numeric."); } $segment = \Zend_Registry::get('db')->fetchRow("SELECT * " . - " FROM " . Common::prefixTable("segment") . - " WHERE idsegment = ?", $idSegment); + " FROM " . Common::prefixTable("segment") . + " WHERE idsegment = ?", $idSegment); if (empty($segment)) { return false; @@ -257,7 +260,7 @@ class Piwik_SegmentEditor_API */ public function getAll($idSite = false, $returnOnlyAutoArchived = false) { - if(!empty($idSite) ) { + if (!empty($idSite)) { Piwik::checkUserHasViewAccess($idSite); } else { Piwik::checkUserHasSomeViewAccess(); @@ -266,7 +269,7 @@ class Piwik_SegmentEditor_API // Build basic segment filtering $whereIdSite = ''; - if(!empty($idSite)) { + if (!empty($idSite)) { $whereIdSite = 'enable_only_idsite = ? OR '; $bind[] = $idSite; } @@ -274,14 +277,14 @@ class Piwik_SegmentEditor_API $bind[] = Piwik::getCurrentUserLogin(); $extraWhere = ''; - if($returnOnlyAutoArchived) { + if ($returnOnlyAutoArchived) { $extraWhere = ' AND auto_archive = 1'; } // Query $sql = "SELECT * " . - " FROM " . Common::prefixTable("segment") . - " WHERE ($whereIdSite enable_only_idsite = 0) + " FROM " . Common::prefixTable("segment") . + " WHERE ($whereIdSite enable_only_idsite = 0) AND (enable_all_users = 1 OR login = ?) AND deleted = 0 $extraWhere diff --git a/plugins/SegmentEditor/Controller.php b/plugins/SegmentEditor/Controller.php index 4083369ece..55b406cf53 100644 --- a/plugins/SegmentEditor/Controller.php +++ b/plugins/SegmentEditor/Controller.php @@ -6,17 +6,20 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SegmentEditor + * @package SegmentEditor */ +namespace Piwik\Plugins\SegmentEditor; + use Piwik\Piwik; use Piwik\Common; -use Piwik\Controller; +use Piwik\Plugins\SegmentEditor\API; use Piwik\View; +use Piwik\Plugins\API\API as MetaAPI; /** - * @package Piwik_SegmentEditor + * @package SegmentEditor */ -class Piwik_SegmentEditor_Controller extends Controller +class Controller extends \Piwik\Controller { public function getSelector() @@ -24,12 +27,13 @@ class Piwik_SegmentEditor_Controller extends Controller $view = new View('@SegmentEditor/getSelector'); $idSite = Common::getRequestVar('idSite'); $this->setGeneralVariablesView($view); - $segments = Piwik_API_API::getInstance()->getSegmentsMetadata($idSite); + $segments = MetaAPI::getInstance()->getSegmentsMetadata($idSite); $segmentsByCategory = $customVariablesSegments = array(); - foreach($segments as $segment) { - if($segment['category'] == Piwik_Translate('General_Visit') - && $segment['type'] == 'metric') { + foreach ($segments as $segment) { + if ($segment['category'] == Piwik_Translate('General_Visit') + && $segment['type'] == 'metric' + ) { $metricsLabel = Piwik_Translate('General_Metrics'); $metricsLabel[0] = strtolower($metricsLabel[0]); $segment['category'] .= ' (' . $metricsLabel . ')'; @@ -40,8 +44,8 @@ class Piwik_SegmentEditor_Controller extends Controller $view->segmentsByCategory = $segmentsByCategory; - $savedSegments = Piwik_SegmentEditor_API::getInstance()->getAll($idSite); - foreach($savedSegments as &$savedSegment) { + $savedSegments = API::getInstance()->getAll($idSite); + foreach ($savedSegments as &$savedSegment) { $savedSegment['name'] = Common::sanitizeInputValue($savedSegment['name']); } $view->savedSegmentsJson = Common::json_encode($savedSegments); @@ -55,7 +59,7 @@ class Piwik_SegmentEditor_Controller extends Controller public function sortSegmentCategories($a, $b) { // Custom Variables last - if($a == Piwik_Translate('CustomVariables_CustomVariables')) { + if ($a == Piwik_Translate('CustomVariables_CustomVariables')) { return 1; } return 0; @@ -86,7 +90,7 @@ class Piwik_SegmentEditor_Controller extends Controller '', '', ); - foreach($translationKeys as $key) { + foreach ($translationKeys as $key) { $translations[$key] = Piwik_Translate($key); } return $translations; diff --git a/plugins/SegmentEditor/SegmentEditor.php b/plugins/SegmentEditor/SegmentEditor.php index 48359598a6..1c588a483d 100644 --- a/plugins/SegmentEditor/SegmentEditor.php +++ b/plugins/SegmentEditor/SegmentEditor.php @@ -6,17 +6,22 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SegmentEditor + * @package SegmentEditor */ +namespace Piwik\Plugins\SegmentEditor; + +use Exception; use Piwik\Common; +use Piwik\Plugins\SegmentEditor\API; +use Piwik\Plugins\SegmentEditor\Controller; use Piwik\Version; -use Piwik\Plugin; use Piwik\Db; +use Zend_Registry; /** - * @package Piwik_SegmentEditor + * @package SegmentEditor */ -class Piwik_SegmentEditor extends Plugin +class SegmentEditor extends \Piwik\Plugin { /** * @see Piwik_Plugin::getInformation @@ -47,13 +52,13 @@ class Piwik_SegmentEditor extends Plugin function getSegmentEditorHtml(&$out) { - $controller = new Piwik_SegmentEditor_Controller(); + $controller = new Controller(); $out .= $controller->getSelector(); } public function getKnownSegmentsToArchiveAllSites(&$segments) { - $segmentsToAutoArchive = Piwik_SegmentEditor_API::getInstance()->getAll($idSite = false, $returnAutoArchived = true); + $segmentsToAutoArchive = API::getInstance()->getAll($idSite = false, $returnAutoArchived = true); foreach ($segmentsToAutoArchive as $segment) { $segments[] = $segment['definition']; } @@ -61,7 +66,7 @@ class Piwik_SegmentEditor extends Plugin public function getKnownSegmentsToArchiveForSite(&$segments, $idSite) { - $segmentToAutoArchive = Piwik_SegmentEditor_API::getInstance()->getAll($idSite, $returnAutoArchived = true); + $segmentToAutoArchive = API::getInstance()->getAll($idSite, $returnAutoArchived = true); foreach ($segmentToAutoArchive as $segmentInfo) { $segments[] = $segmentInfo['definition']; diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php index 18f22d8278..5ca3382826 100644 --- a/plugins/SitesManager/API.php +++ b/plugins/SitesManager/API.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SitesManager + * @package SitesManager */ +namespace Piwik\Plugins\SitesManager; + +use Exception; use Piwik\Piwik; use Piwik\Common; use Piwik\Access; @@ -18,6 +21,7 @@ use Piwik\Tracker\Cache; use Piwik\Url; use Piwik\TaskScheduler; use Piwik\Site; +use false; /** * The SitesManager API gives you full control on Websites in Piwik (create, update and delete), and many methods to retrieve websites based on various attributes. @@ -33,15 +37,15 @@ use Piwik\Site; * "setGlobalExcludedQueryParameters" will set the list of URL parameters to remove from URLs for all websites. * The existing values can be fetched via "getExcludedIpsGlobal" and "getExcludedQueryParametersGlobal". * See also the documentation about <a href='http://piwik.org/docs/manage-websites/' target='_blank'>Managing Websites</a> in Piwik. - * @package Piwik_SitesManager + * @package SitesManager */ -class Piwik_SitesManager_API +class API { static private $instance = null; const DEFAULT_SEARCH_KEYWORD_PARAMETERS = 'q,query,s,search,searchword,k,keyword'; /** - * @return Piwik_SitesManager_API + * @return \Piwik\Plugins\SitesManager\API */ static public function getInstance() { @@ -209,8 +213,8 @@ class Piwik_SitesManager_API { Piwik::checkUserIsSuperUser(); try { - return Piwik_SitesManager_API::getInstance()->getSitesId(); - } catch(Exception $e) { + return API::getInstance()->getSitesId(); + } catch (Exception $e) { // can be called before Piwik tables are created so return empty return array(); } @@ -236,7 +240,7 @@ class Piwik_SitesManager_API FROM " . Common::prefixTable('site') . " s WHERE EXISTS ( - SELECT 1 + SELECT 1 FROM " . Common::prefixTable('log_visit') . " v WHERE v.idsite = s.idsite AND visit_last_action_time > ? @@ -250,7 +254,6 @@ class Piwik_SitesManager_API return $idSites; } - /** * Returns the list of websites with the 'admin' access for the current user. * For the superUser it returns all the websites in the database. @@ -344,7 +347,7 @@ class Piwik_SitesManager_API * The user access is not checked in this method so the ID have to be accessible by the user! * * @param array $idSites list of website ID - * @param bool $limit + * @param bool $limit * @return array */ private function getSitesFromIds($idSites, $limit = false) @@ -566,7 +569,7 @@ class Piwik_SitesManager_API { Piwik::checkUserIsSuperUser(); - $idSites = Piwik_SitesManager_API::getInstance()->getSitesId(); + $idSites = API::getInstance()->getSitesId(); if (!in_array($idSite, $idSites)) { throw new Exception("website id = $idSite not found"); } @@ -592,7 +595,6 @@ class Piwik_SitesManager_API Piwik_PostEvent('SitesManager.deleteSite', array($idSite)); } - /** * Checks that the array has at least one element * @@ -659,7 +661,7 @@ class Piwik_SitesManager_API * If some URLs given in parameter are already recorded as alias URLs for this website, * they won't be duplicated. The 'main_url' of the website won't be affected by this method. * - * @param int $idSite + * @param int $idSite * @param array|string $urls * @return int the number of inserted URLs */ @@ -985,7 +987,7 @@ class Piwik_SitesManager_API { Piwik::checkUserHasAdminAccess($idSite); - $idSites = Piwik_SitesManager_API::getInstance()->getSitesId(); + $idSites = API::getInstance()->getSitesId(); if (!in_array($idSite, $idSites)) { throw new Exception("website id = $idSite not found"); } @@ -1187,9 +1189,9 @@ class Piwik_SitesManager_API $db = \Zend_Registry::get('db'); foreach ($urls as $url) { $db->insert(Common::prefixTable("site_url"), array( - 'idsite' => $idSite, - 'url' => $url - ) + 'idsite' => $idSite, + 'url' => $url + ) ); } } @@ -1258,7 +1260,6 @@ class Piwik_SitesManager_API } } - private function checkSiteSearch($siteSearch) { if ($siteSearch === null) { @@ -1348,10 +1349,10 @@ class Piwik_SitesManager_API } $sites = $db->fetchAll("SELECT idsite, name, main_url FROM " . Common::prefixTable('site') . " s - WHERE ( s.name like ? + WHERE ( s.name like ? OR s.main_url like ? - $where ) - AND idsite in ($ids_str) + $where ) + AND idsite in ($ids_str) LIMIT " . Piwik::getWebsitesCountToDisplay(), $bind); return $sites; diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index 3a8f339693..7a03152256 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -6,24 +6,27 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SitesManager + * @package SitesManager */ +namespace Piwik\Plugins\SitesManager; + +use Exception; use Piwik\API\ResponseBuilder; -use Piwik\Controller\Admin; use Piwik\DataTable\Renderer\Json; use Piwik\Piwik; use Piwik\Common; use Piwik\Date; use Piwik\IP; +use Piwik\Plugins\SitesManager\API; use Piwik\View; use Piwik\Url; use Piwik\Site; /** * - * @package Piwik_SitesManager + * @package SitesManager */ -class Piwik_SitesManager_Controller extends Admin +class Controller extends \Piwik\Controller\Admin { /** * Main view showing listing of websites and settings @@ -33,16 +36,16 @@ class Piwik_SitesManager_Controller extends Admin $view = new View('@SitesManager/index'); if (Piwik::isUserIsSuperUser()) { - $sites = Piwik_SitesManager_API::getInstance()->getAllSites(); + $sites = API::getInstance()->getAllSites(); Site::setSites($sites); $sites = array_values($sites); } else { - $sites = Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess(); + $sites = API::getInstance()->getSitesWithAdminAccess(); Site::setSitesFromArray($sites); } foreach ($sites as &$site) { - $site['alias_urls'] = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($site['idsite']); + $site['alias_urls'] = API::getInstance()->getSiteUrlsFromId($site['idsite']); $site['excluded_ips'] = explode(',', $site['excluded_ips']); $site['excluded_parameters'] = explode(',', $site['excluded_parameters']); $site['excluded_user_agents'] = explode(',', $site['excluded_user_agents']); @@ -50,30 +53,30 @@ class Piwik_SitesManager_Controller extends Admin $view->adminSites = $sites; $view->adminSitesCount = count($sites); - $timezones = Piwik_SitesManager_API::getInstance()->getTimezonesList(); + $timezones = API::getInstance()->getTimezonesList(); $view->timezoneSupported = Piwik::isTimezoneSupportEnabled(); $view->timezones = Common::json_encode($timezones); - $view->defaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone(); + $view->defaultTimezone = API::getInstance()->getDefaultTimezone(); - $view->currencies = Common::json_encode(Piwik_SitesManager_API::getInstance()->getCurrencyList()); - $view->defaultCurrency = Piwik_SitesManager_API::getInstance()->getDefaultCurrency(); + $view->currencies = Common::json_encode(API::getInstance()->getCurrencyList()); + $view->defaultCurrency = API::getInstance()->getDefaultCurrency(); $view->utcTime = Date::now()->getDatetime(); - $excludedIpsGlobal = Piwik_SitesManager_API::getInstance()->getExcludedIpsGlobal(); + $excludedIpsGlobal = API::getInstance()->getExcludedIpsGlobal(); $view->globalExcludedIps = str_replace(',', "\n", $excludedIpsGlobal); - $excludedQueryParametersGlobal = Piwik_SitesManager_API::getInstance()->getExcludedQueryParametersGlobal(); + $excludedQueryParametersGlobal = API::getInstance()->getExcludedQueryParametersGlobal(); $view->globalExcludedQueryParameters = str_replace(',', "\n", $excludedQueryParametersGlobal); - $globalExcludedUserAgents = Piwik_SitesManager_API::getInstance()->getExcludedUserAgentsGlobal(); + $globalExcludedUserAgents = API::getInstance()->getExcludedUserAgentsGlobal(); $view->globalExcludedUserAgents = str_replace(',', "\n", $globalExcludedUserAgents); - $view->globalSearchKeywordParameters = Piwik_SitesManager_API::getInstance()->getSearchKeywordParametersGlobal(); - $view->globalSearchCategoryParameters = Piwik_SitesManager_API::getInstance()->getSearchCategoryParametersGlobal(); + $view->globalSearchKeywordParameters = API::getInstance()->getSearchKeywordParametersGlobal(); + $view->globalSearchCategoryParameters = API::getInstance()->getSearchCategoryParametersGlobal(); $view->isSearchCategoryTrackingEnabled = \Piwik\PluginsManager::getInstance()->isPluginActivated('CustomVariables'); $view->allowSiteSpecificUserAgentExclude = - Piwik_SitesManager_API::getInstance()->isSiteSpecificUserAgentExcludeEnabled(); + API::getInstance()->isSiteSpecificUserAgentExcludeEnabled(); - $view->globalKeepURLFragments = Piwik_SitesManager_API::getInstance()->getKeepURLFragmentsGlobal(); + $view->globalKeepURLFragments = API::getInstance()->getKeepURLFragmentsGlobal(); $view->currentIpAddress = IP::getIpFromHeader(); @@ -102,7 +105,7 @@ class Piwik_SitesManager_Controller extends Admin $enableSiteUserAgentExclude = Common::getRequestVar('enableSiteUserAgentExclude', $default = 0); $keepURLFragments = Common::getRequestVar('keepURLFragments', $default = 0); - $api = Piwik_SitesManager_API::getInstance(); + $api = API::getInstance(); $api->setDefaultTimezone($timezone); $api->setDefaultCurrency($currency); $api->setGlobalExcludedQueryParameters($excludedQueryParameters); @@ -170,7 +173,7 @@ class Piwik_SitesManager_Controller extends Admin function getSitesForAutocompleter() { $pattern = Common::getRequestVar('term'); - $sites = Piwik_SitesManager_API::getInstance()->getPatternMatchSites($pattern); + $sites = API::getInstance()->getPatternMatchSites($pattern); $pattern = str_replace('%', '', $pattern); if (!count($sites)) { $results[] = array('label' => Piwik_Translate('SitesManager_NotFound') . " <span class='autocompleteMatched'>$pattern</span>.", 'id' => '#'); diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index 7b21bbafd1..cdc3a92f2b 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -6,16 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_SitesManager + * @package SitesManager */ +namespace Piwik\Plugins\SitesManager; + use Piwik\Piwik; -use Piwik\Plugin; /** * - * @package Piwik_SitesManager + * @package SitesManager */ -class Piwik_SitesManager extends Plugin +class SitesManager extends \Piwik\Plugin { const KEEP_URL_FRAGMENT_USE_DEFAULT = 0; const KEEP_URL_FRAGMENT_YES = 1; @@ -64,17 +65,17 @@ class Piwik_SitesManager extends Plugin * Will record in the tracker config file all data needed for this website in Tracker. * * @param array $array - * @param int $idSite + * @param int $idSite * @return void */ public function recordWebsiteDataInCache(&$array, $idSite) { $idSite = (int)$idSite; - + // add the 'hosts' entry in the website array $array['hosts'] = $this->getTrackerHosts($idSite); - $website = Piwik_SitesManager_API::getInstance()->getSiteFromId($idSite); + $website = API::getInstance()->getSiteFromId($idSite); $array['excluded_ips'] = $this->getTrackerExcludedIps($website); $array['excluded_parameters'] = self::getTrackerExcludedQueryParameters($website); $array['excluded_user_agents'] = self::getExcludedUserAgents($website); @@ -98,14 +99,14 @@ class Piwik_SitesManager extends Plugin return false; } - return Piwik_SitesManager_API::getInstance()->getKeepURLFragmentsGlobal(); + return API::getInstance()->getKeepURLFragmentsGlobal(); } private function getTrackerSearchKeywordParameters($website) { $searchParameters = $website['sitesearch_keyword_parameters']; if (empty($searchParameters)) { - $searchParameters = Piwik_SitesManager_API::getInstance()->getSearchKeywordParametersGlobal(); + $searchParameters = API::getInstance()->getSearchKeywordParametersGlobal(); } return explode(",", $searchParameters); } @@ -114,7 +115,7 @@ class Piwik_SitesManager extends Plugin { $searchParameters = $website['sitesearch_category_parameters']; if (empty($searchParameters)) { - $searchParameters = Piwik_SitesManager_API::getInstance()->getSearchCategoryParametersGlobal(); + $searchParameters = API::getInstance()->getSearchCategoryParametersGlobal(); } return explode(",", $searchParameters); } @@ -128,13 +129,13 @@ class Piwik_SitesManager extends Plugin private function getTrackerExcludedIps($website) { $excludedIps = $website['excluded_ips']; - $globalExcludedIps = Piwik_SitesManager_API::getInstance()->getExcludedIpsGlobal(); + $globalExcludedIps = API::getInstance()->getExcludedIpsGlobal(); $excludedIps .= ',' . $globalExcludedIps; $ipRanges = array(); foreach (explode(',', $excludedIps) as $ip) { - $ipRange = Piwik_SitesManager_API::getInstance()->getIpsForRange($ip); + $ipRange = API::getInstance()->getIpsForRange($ip); if ($ipRange !== false) { $ipRanges[] = $ipRange; } @@ -151,8 +152,8 @@ class Piwik_SitesManager extends Plugin */ private static function getExcludedUserAgents($website) { - $excludedUserAgents = Piwik_SitesManager_API::getInstance()->getExcludedUserAgentsGlobal(); - if (Piwik_SitesManager_API::getInstance()->isSiteSpecificUserAgentExcludeEnabled()) { + $excludedUserAgents = API::getInstance()->getExcludedUserAgentsGlobal(); + if (API::getInstance()->isSiteSpecificUserAgentExcludeEnabled()) { $excludedUserAgents .= ',' . $website['excluded_user_agents']; } return self::filterBlankFromCommaSepList($excludedUserAgents); @@ -167,7 +168,7 @@ class Piwik_SitesManager extends Plugin public static function getTrackerExcludedQueryParameters($website) { $excludedQueryParameters = $website['excluded_parameters']; - $globalExcludedQueryParameters = Piwik_SitesManager_API::getInstance()->getExcludedQueryParametersGlobal(); + $globalExcludedQueryParameters = API::getInstance()->getExcludedQueryParametersGlobal(); $excludedQueryParameters .= ',' . $globalExcludedQueryParameters; return self::filterBlankFromCommaSepList($excludedQueryParameters); @@ -195,7 +196,7 @@ class Piwik_SitesManager extends Plugin */ private function getTrackerHosts($idSite) { - $urls = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idSite); + $urls = API::getInstance()->getSiteUrlsFromId($idSite); $hosts = array(); foreach ($urls as $url) { $url = parse_url($url); diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php index c676e51fe7..e019005aed 100644 --- a/plugins/Transitions/API.php +++ b/plugins/Transitions/API.php @@ -6,9 +6,12 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Transitions + * @package Transitions */ +namespace Piwik\Plugins\Transitions; + +use Exception; use Piwik\ArchiveProcessor; use Piwik\DataAccess\LogAggregator; use Piwik\DataTable\Manager; @@ -20,16 +23,19 @@ use Piwik\Piwik; use Piwik\Common; use Piwik\DataTable; use Piwik\DataArray; +use Piwik\Plugins\Actions\Actions; +use Piwik\Plugins\Actions\ArchivingHelper; use Piwik\RankingQuery; use Piwik\Segment; use Piwik\SegmentExpression; use Piwik\Site; use Piwik\Tracker\Action; +use Piwik\Plugins\Transitions\Controller; /** - * @package Piwik_Transitions + * @package Transitions */ -class Piwik_Transitions_API +class API { static private $instance = null; @@ -139,7 +145,7 @@ class Piwik_Transitions_API */ private function deriveIdAction($actionName, $actionType) { - $actionsPlugin = new Piwik_Actions; + $actionsPlugin = new Actions; switch ($actionType) { case 'url': $originalActionName = $actionName; @@ -158,7 +164,7 @@ class Piwik_Transitions_API $id = $actionsPlugin->getIdActionFromSegment($actionName, 'idaction_name', SegmentExpression::MATCH_EQUAL, 'pageTitle'); if ($id < 0) { - $unknown = Piwik_Actions_ArchivingHelper::getUnknownActionName( + $unknown = ArchivingHelper::getUnknownActionName( Action::TYPE_ACTION_NAME); if (trim($actionName) == trim($unknown)) { @@ -221,14 +227,12 @@ class Piwik_Transitions_API } } - - /** * Get information about the following actions (following pages, site searches, outlinks, downloads) * * @param $idaction * @param $actionType - * @param LogAggregator $logAggregator + * @param LogAggregator $logAggregator * @param $limitBeforeGrouping * @param $includeLoops * @return array(followingPages:DataTable, outlinks:DataTable, downloads:DataTable) @@ -311,11 +315,11 @@ class Piwik_Transitions_API foreach ($data[$type] as &$record) { $actions = intval($record[Metrics::INDEX_NB_ACTIONS]); $dataTable->addRow(new Row(array( - Row::COLUMNS => array( - 'label' => $this->getPageLabel($record, $isTitle), - Metrics::INDEX_NB_ACTIONS => $actions - ) - ))); + Row::COLUMNS => array( + 'label' => $this->getPageLabel($record, $isTitle), + Metrics::INDEX_NB_ACTIONS => $actions + ) + ))); $this->totalTransitionsToFollowingActions += $actions; } } @@ -325,7 +329,6 @@ class Piwik_Transitions_API return $dataTables; } - /** * After calling this method, the query*()-Methods will return urls in their * normalized form (without the prefix reconstructed) @@ -389,7 +392,7 @@ class Piwik_Transitions_API foreach ($subData as &$row) { if ($referrerType == Common::REFERER_TYPE_SEARCH_ENGINE && empty($row['referrer_data'])) { - $row['referrer_data'] = Piwik_Referers_API::LABEL_KEYWORD_NOT_DEFINED; + $row['referrer_data'] = \Piwik\Plugins\Referers\API::LABEL_KEYWORD_NOT_DEFINED; } $referrerData[$referrerType][Metrics::INDEX_NB_VISITS] += $row[Metrics::INDEX_NB_VISITS]; @@ -466,11 +469,11 @@ class Piwik_Transitions_API foreach ($data['result'][1] as &$page) { $nbActions = intval($page[Metrics::INDEX_NB_ACTIONS]); $previousPagesDataTable->addRow(new Row(array( - Row::COLUMNS => array( - 'label' => $this->getPageLabel($page, $isTitle), - Metrics::INDEX_NB_ACTIONS => $nbActions - ) - ))); + Row::COLUMNS => array( + 'label' => $this->getPageLabel($page, $isTitle), + Metrics::INDEX_NB_ACTIONS => $nbActions + ) + ))); $nbPageviews += $nbActions; } } @@ -480,11 +483,11 @@ class Piwik_Transitions_API foreach ($data['result'][2] as &$search) { $nbActions = intval($search[Metrics::INDEX_NB_ACTIONS]); $previousSearchesDataTable->addRow(new Row(array( - Row::COLUMNS => array( - 'label' => $search['name'], - Metrics::INDEX_NB_ACTIONS => $nbActions - ) - ))); + Row::COLUMNS => array( + 'label' => $search['name'], + Metrics::INDEX_NB_ACTIONS => $nbActions + ) + ))); $nbPageviews += $nbActions; } } @@ -513,7 +516,7 @@ class Piwik_Transitions_API if ($isTitle) { $label = $pageRecord['name']; if (empty($label)) { - $label = Piwik_Actions_ArchivingHelper::getUnknownActionName( + $label = ArchivingHelper::getUnknownActionName( Action::TYPE_ACTION_NAME); } return $label; @@ -538,7 +541,6 @@ class Piwik_Transitions_API private $returnNormalizedUrls = false; - /** * Get the sum of all transitions to following actions (pages, outlinks, downloads). * Only works if queryFollowingActions() has been used directly before. @@ -552,7 +554,7 @@ class Piwik_Transitions_API * Add the external referrers to the report: * direct entries, websites, campaigns, search engines * - * @param LogAggregator $logAggregator + * @param LogAggregator $logAggregator * @param $report * @param $idaction * @param string $actionType @@ -583,7 +585,7 @@ class Piwik_Transitions_API } $report['referrers'][] = array( 'label' => $this->getReferrerLabel($referrerId), - 'shortName' => Piwik_getRefererTypeFromShortName($referrerId), + 'shortName' => \Piwik\Plugins\Referers\getRefererTypeFromShortName($referrerId), 'visits' => $visits, 'details' => $details ); @@ -597,7 +599,7 @@ class Piwik_Transitions_API if (count($report['referrers']) == 0) { $report['referrers'][] = array( 'label' => $this->getReferrerLabel(Common::REFERER_TYPE_DIRECT_ENTRY), - 'shortName' => Piwik_getRefererTypeLabel(Common::REFERER_TYPE_DIRECT_ENTRY), + 'shortName' => \Piwik\Plugins\Referers\getRefererTypeLabel(Common::REFERER_TYPE_DIRECT_ENTRY), 'visits' => 0 ); } @@ -607,13 +609,13 @@ class Piwik_Transitions_API { switch ($referrerId) { case Common::REFERER_TYPE_DIRECT_ENTRY: - return Piwik_Transitions_Controller::getTranslation('directEntries'); + return Controller::getTranslation('directEntries'); case Common::REFERER_TYPE_SEARCH_ENGINE: - return Piwik_Transitions_Controller::getTranslation('fromSearchEngines'); + return Controller::getTranslation('fromSearchEngines'); case Common::REFERER_TYPE_WEBSITE: - return Piwik_Transitions_Controller::getTranslation('fromWebsites'); + return Controller::getTranslation('fromWebsites'); case Common::REFERER_TYPE_CAMPAIGN: - return Piwik_Transitions_Controller::getTranslation('fromCampaigns'); + return Controller::getTranslation('fromCampaigns'); default: return Piwik_Translate('General_Others'); } @@ -621,8 +623,7 @@ class Piwik_Transitions_API public function getTranslations() { - $controller = new Piwik_Transitions_Controller(); + $controller = new Controller(); return $controller->getTranslations(); } - }
\ No newline at end of file diff --git a/plugins/Transitions/Controller.php b/plugins/Transitions/Controller.php index 5178b1923f..172f7f1e90 100644 --- a/plugins/Transitions/Controller.php +++ b/plugins/Transitions/Controller.php @@ -6,15 +6,16 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Transitions + * @package Transitions */ -use Piwik\Controller; +namespace Piwik\Plugins\Transitions; + use Piwik\View; /** - * @package Piwik_Transitions + * @package Transitions */ -class Piwik_Transitions_Controller extends Controller +class Controller extends \Piwik\Controller { /** @@ -89,5 +90,4 @@ class Piwik_Transitions_Controller extends Controller } return $translations; } - } diff --git a/plugins/Transitions/Transitions.php b/plugins/Transitions/Transitions.php index b47db2e436..d0ea42d9b7 100644 --- a/plugins/Transitions/Transitions.php +++ b/plugins/Transitions/Transitions.php @@ -6,14 +6,15 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Transitions + * @package Transitions */ -use Piwik\Plugin; + +namespace Piwik\Plugins\Transitions; /** - * @package Piwik_Transitions + * @package Transitions */ -class Piwik_Transitions extends Plugin +class Transitions extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/UserCountry/API.php b/plugins/UserCountry/API.php index 62b472bbaa..a621b9344c 100644 --- a/plugins/UserCountry/API.php +++ b/plugins/UserCountry/API.php @@ -6,12 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountry + * @package UserCountry */ +namespace Piwik\Plugins\UserCountry; + +use Exception; use Piwik\Archive; use Piwik\Metrics; use Piwik\Piwik; use Piwik\DataTable; +use Piwik\Plugins\UserCountry\LocationProvider; +use Piwik\Plugins\UserCountry\Archiver; use Piwik\Tracker\Visit; /** @@ -21,9 +26,9 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/functions.php'; /** * The UserCountry API lets you access reports about your visitors' Countries and Continents. - * @package Piwik_UserCountry + * @package UserCountry */ -class Piwik_UserCountry_API +class API { static private $instance = null; @@ -37,12 +42,12 @@ class Piwik_UserCountry_API public function getCountry($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable(Piwik_UserCountry_Archiver::COUNTRY_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Archiver::COUNTRY_RECORD_NAME, $idSite, $period, $date, $segment); // apply filter on the whole datatable in order the inline search to work (searches are done on "beautiful" label) $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'code')); - $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getFlagFromCode')); - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_CountryTranslate')); + $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getFlagFromCode')); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\countryTranslate')); $dataTable->queueFilter('AddConstantMetadata', array('logoWidth', 16)); $dataTable->queueFilter('AddConstantMetadata', array('logoHeight', 11)); @@ -51,12 +56,12 @@ class Piwik_UserCountry_API public function getContinent($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable(Piwik_UserCountry_Archiver::COUNTRY_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Archiver::COUNTRY_RECORD_NAME, $idSite, $period, $date, $segment); $getContinent = array('Piwik\Common', 'getContinent'); $dataTable->filter('GroupBy', array('label', $getContinent)); - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_ContinentTranslate')); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\continentTranslate')); $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'code')); return $dataTable; @@ -73,31 +78,31 @@ class Piwik_UserCountry_API */ public function getRegion($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable(Piwik_UserCountry_Archiver::REGION_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Archiver::REGION_RECORD_NAME, $idSite, $period, $date, $segment); - $separator = Piwik_UserCountry_Archiver::LOCATION_SEPARATOR; + $separator = Archiver::LOCATION_SEPARATOR; $unk = Visit::UNKNOWN_CODE; // split the label and put the elements into the 'region' and 'country' metadata fields $dataTable->filter('ColumnCallbackAddMetadata', - array('label', 'region', 'Piwik_UserCountry_getElementFromStringArray', array($separator, 0, $unk))); + array('label', 'region', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 0, $unk))); $dataTable->filter('ColumnCallbackAddMetadata', - array('label', 'country', 'Piwik_UserCountry_getElementFromStringArray', array($separator, 1, $unk))); + array('label', 'country', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 1, $unk))); // add country name metadata $dataTable->filter('MetadataCallbackAddMetadata', - array('country', 'country_name', 'Piwik_CountryTranslate', $applyToSummaryRow = false)); + array('country', 'country_name', __NAMESPACE__ . '\CountryTranslate', $applyToSummaryRow = false)); // get the region name of each row and put it into the 'region_name' metadata $dataTable->filter('ColumnCallbackAddMetadata', - array('label', 'region_name', 'Piwik_UserCountry_getRegionName', $params = null, + array('label', 'region_name', __NAMESPACE__ . '\getRegionName', $params = null, $applyToSummaryRow = false)); // add the country flag as a url to the 'logo' metadata field - $dataTable->filter('MetadataCallbackAddMetadata', array('country', 'logo', 'Piwik_getFlagFromCode')); + $dataTable->filter('MetadataCallbackAddMetadata', array('country', 'logo', __NAMESPACE__ . '\getFlagFromCode')); // prettify the region label - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_UserCountry_getPrettyRegionName')); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getPrettyRegionName')); $dataTable->queueFilter('ReplaceSummaryRowLabel'); @@ -115,43 +120,43 @@ class Piwik_UserCountry_API */ public function getCity($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable(Piwik_UserCountry_Archiver::CITY_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Archiver::CITY_RECORD_NAME, $idSite, $period, $date, $segment); - $separator = Piwik_UserCountry_Archiver::LOCATION_SEPARATOR; + $separator = Archiver::LOCATION_SEPARATOR; $unk = Visit::UNKNOWN_CODE; // split the label and put the elements into the 'city_name', 'region', 'country', // 'lat' & 'long' metadata fields $strUnknown = Piwik_Translate('General_Unknown'); $dataTable->filter('ColumnCallbackAddMetadata', - array('label', 'city_name', 'Piwik_UserCountry_getElementFromStringArray', + array('label', 'city_name', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 0, $strUnknown))); $dataTable->filter('MetadataCallbackAddMetadata', array('city_name', 'city', create_function('$city', ' if ($city == "' . $strUnknown . '") { return "xx"; } else { return false; } '))); $dataTable->filter('ColumnCallbackAddMetadata', - array('label', 'region', 'Piwik_UserCountry_getElementFromStringArray', array($separator, 1, $unk))); + array('label', 'region', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 1, $unk))); $dataTable->filter('ColumnCallbackAddMetadata', - array('label', 'country', 'Piwik_UserCountry_getElementFromStringArray', array($separator, 2, $unk))); + array('label', 'country', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 2, $unk))); // backwards compatibility: for reports that have lat|long in label $dataTable->filter('ColumnCallbackAddMetadata', - array('label', 'lat', 'Piwik_UserCountry_getElementFromStringArray', array($separator, 3, false))); + array('label', 'lat', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 3, false))); $dataTable->filter('ColumnCallbackAddMetadata', - array('label', 'long', 'Piwik_UserCountry_getElementFromStringArray', array($separator, 4, false))); + array('label', 'long', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 4, false))); // add country name & region name metadata $dataTable->filter('MetadataCallbackAddMetadata', - array('country', 'country_name', 'Piwik_CountryTranslate', $applyToSummaryRow = false)); + array('country', 'country_name', __NAMESPACE__ . '\countryTranslate', $applyToSummaryRow = false)); - $getRegionName = array('Piwik_UserCountry_LocationProvider_GeoIp', 'getRegionNameFromCodes'); + $getRegionName = '\\Piwik\\Plugins\\UserCountry\\LocationProvider\\GeoIp::getRegionNameFromCodes'; $dataTable->filter('MetadataCallbackAddMetadata', array( array('country', 'region'), 'region_name', $getRegionName, $applyToSummaryRow = false)); // add the country flag as a url to the 'logo' metadata field - $dataTable->filter('MetadataCallbackAddMetadata', array('country', 'logo', 'Piwik_getFlagFromCode')); + $dataTable->filter('MetadataCallbackAddMetadata', array('country', 'logo', __NAMESPACE__ . '\getFlagFromCode')); // prettify the label - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_UserCountry_getPrettyCityName')); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getPrettyCityName')); $dataTable->queueFilter('ReplaceSummaryRowLabel'); @@ -161,7 +166,7 @@ class Piwik_UserCountry_API /** * Uses a location provider to find/guess the location of an IP address. * - * See Piwik_UserCountry_LocationProvider::getLocation to see the details + * See LocationProvider::getLocation to see the details * of the result of this function. * * @param string $ip The IP address. @@ -175,10 +180,10 @@ class Piwik_UserCountry_API Piwik::checkUserHasSomeViewAccess(); if ($provider === false) { - $provider = Piwik_UserCountry_LocationProvider::getCurrentProviderId(); + $provider = LocationProvider::getCurrentProviderId(); } - $oProvider = Piwik_UserCountry_LocationProvider::getProviderById($provider); + $oProvider = LocationProvider::getProviderById($provider); if ($oProvider === false) { throw new Exception("Cannot find the '$provider' provider. It is either an invalid provider " . "ID or the ID of a provider that is not working."); @@ -206,6 +211,6 @@ class Piwik_UserCountry_API { Piwik::checkUserHasViewAccess($idSite); $archive = Archive::build($idSite, $period, $date, $segment); - return $archive->getDataTableFromNumeric(Piwik_UserCountry_Archiver::DISTINCT_COUNTRIES_METRIC); + return $archive->getDataTableFromNumeric(Archiver::DISTINCT_COUNTRIES_METRIC); } } diff --git a/plugins/UserCountry/Archiver.php b/plugins/UserCountry/Archiver.php index 656239ac24..5485d2fe98 100644 --- a/plugins/UserCountry/Archiver.php +++ b/plugins/UserCountry/Archiver.php @@ -6,16 +6,19 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountry + * @package UserCountry */ +namespace Piwik\Plugins\UserCountry; + use Piwik\ArchiveProcessor; use Piwik\Metrics; use Piwik\DataTable; use Piwik\DataArray; +use Piwik\Plugins\UserCountry\LocationProvider; use Piwik\PluginsArchiver; -class Piwik_UserCountry_Archiver extends PluginsArchiver +class Archiver extends PluginsArchiver { const COUNTRY_RECORD_NAME = 'UserCountry_country'; const REGION_RECORD_NAME = 'UserCountry_region'; @@ -35,16 +38,15 @@ class Piwik_UserCountry_Archiver extends PluginsArchiver const CITY_FIELD = 'location_city'; - protected $dimensions = array( self::COUNTRY_FIELD, self::REGION_FIELD, self::CITY_FIELD ); + protected $dimensions = array(self::COUNTRY_FIELD, self::REGION_FIELD, self::CITY_FIELD); protected $arrays; const LATITUDE_FIELD = 'location_latitude'; const LONGITUDE_FIELD = 'location_longitude'; - public function archiveDay() { - foreach($this->dimensions as $dimension) { + foreach ($this->dimensions as $dimension) { $this->arrays[$dimension] = new DataArray(); } $this->aggregateFromVisits(); @@ -95,11 +97,12 @@ class Piwik_UserCountry_Archiver extends PluginsArchiver protected function rememberCityLatLong($row) { - if ( !empty($row[self::CITY_FIELD]) + if (!empty($row[self::CITY_FIELD]) && !empty($row[self::LATITUDE_FIELD]) && !empty($row[self::LONGITUDE_FIELD]) - && empty($this->latLongForCities[$row[self::CITY_FIELD]])) { - $this->latLongForCities[$row[self::CITY_FIELD]] = array($row[self::LATITUDE_FIELD], $row[self::LONGITUDE_FIELD]); + && empty($this->latLongForCities[$row[self::CITY_FIELD]]) + ) { + $this->latLongForCities[$row[self::CITY_FIELD]] = array($row[self::LATITUDE_FIELD], $row[self::LONGITUDE_FIELD]); } } @@ -153,8 +156,8 @@ class Piwik_UserCountry_Archiver extends PluginsArchiver if (isset($this->latLongForCities[$label])) { // get lat/long for city list($lat, $long) = $this->latLongForCities[$label]; - $lat = round($lat, Piwik_UserCountry_LocationProvider::GEOGRAPHIC_COORD_PRECISION); - $long = round($long, Piwik_UserCountry_LocationProvider::GEOGRAPHIC_COORD_PRECISION); + $lat = round($lat, LocationProvider::GEOGRAPHIC_COORD_PRECISION); + $long = round($long, LocationProvider::GEOGRAPHIC_COORD_PRECISION); // set latitude + longitude metadata $row->setMetadata('lat', $lat); @@ -175,5 +178,4 @@ class Piwik_UserCountry_Archiver extends PluginsArchiver $this->getProcessor()->insertNumericRecord(self::DISTINCT_COUNTRIES_METRIC, $nameToCount[self::COUNTRY_RECORD_NAME]['level0']); } - }
\ No newline at end of file diff --git a/plugins/UserCountry/Controller.php b/plugins/UserCountry/Controller.php index 1654885001..8fc88f80b5 100644 --- a/plugins/UserCountry/Controller.php +++ b/plugins/UserCountry/Controller.php @@ -6,23 +6,32 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountry + * @package UserCountry */ -use Piwik\Controller\Admin; +namespace Piwik\Plugins\UserCountry; + +use Admin; +use Exception; use Piwik\DataTable\Renderer\Json; use Piwik\Piwik; use Piwik\Common; use Piwik\Http; use Piwik\IP; +use Piwik\Plugins\UserCountry\LocationProvider; +use Piwik\Plugins\UserCountry\GeoIPAutoUpdater; use Piwik\ViewDataTable; use Piwik\View; use Piwik\Url; +use Piwik\Plugins\UserCountry\LocationProvider\DefaultProvider; +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp\Pecl; +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp\ServerBased; /** * - * @package Piwik_UserCountry + * @package UserCountry */ -class Piwik_UserCountry_Controller extends Admin +class Controller extends \Piwik\Controller\Admin { public function index() { @@ -44,19 +53,19 @@ class Piwik_UserCountry_Controller extends Admin Piwik::checkUserIsSuperUser(); $view = new View('@UserCountry/adminIndex'); - $allProviderInfo = Piwik_UserCountry_LocationProvider::getAllProviderInfo( + $allProviderInfo = LocationProvider::getAllProviderInfo( $newline = '<br/>', $includeExtra = true); $view->locationProviders = $allProviderInfo; - $view->currentProviderId = Piwik_UserCountry_LocationProvider::getCurrentProviderId(); + $view->currentProviderId = LocationProvider::getCurrentProviderId(); $view->thisIP = IP::getIpFromHeader(); - $geoIPDatabasesInstalled = Piwik_UserCountry_LocationProvider_GeoIp::isDatabaseInstalled(); + $geoIPDatabasesInstalled = GeoIp::isDatabaseInstalled(); $view->geoIPDatabasesInstalled = $geoIPDatabasesInstalled; // check if there is a working provider (that isn't the default one) $isThereWorkingProvider = false; foreach ($allProviderInfo as $id => $provider) { - if ($id != Piwik_UserCountry_LocationProvider_Default::ID - && $provider['status'] == Piwik_UserCountry_LocationProvider::INSTALLED + if ($id != DefaultProvider::ID + && $provider['status'] == LocationProvider::INSTALLED ) { $isThereWorkingProvider = true; break; @@ -67,11 +76,11 @@ class Piwik_UserCountry_Controller extends Admin // if using either the Apache or PECL module, they are working and there are no databases // in misc, then the databases are located outside of Piwik, so we cannot update them $view->showGeoIPUpdateSection = true; - $currentProviderId = Piwik_UserCountry_LocationProvider::getCurrentProviderId(); + $currentProviderId = LocationProvider::getCurrentProviderId(); if (!$geoIPDatabasesInstalled - && ($currentProviderId == Piwik_UserCountry_LocationProvider_GeoIp_ServerBased::ID - || $currentProviderId == Piwik_UserCountry_LocationProvider_GeoIp_Pecl::ID) - && $allProviderInfo[$currentProviderId]['status'] == Piwik_UserCountry_LocationProvider::INSTALLED + && ($currentProviderId == ServerBased::ID + || $currentProviderId == Pecl::ID) + && $allProviderInfo[$currentProviderId]['status'] == LocationProvider::INSTALLED ) { $view->showGeoIPUpdateSection = false; } @@ -106,23 +115,23 @@ class Piwik_UserCountry_Controller extends Admin if ($_SERVER["REQUEST_METHOD"] == "POST") { $this->checkTokenInUrl(); Json::sendHeaderJSON(); - $outputPath = Piwik_UserCountry_LocationProvider_GeoIp::getPathForGeoIpDatabase('GeoIPCity.dat') . '.gz'; + $outputPath = GeoIp::getPathForGeoIpDatabase('GeoIPCity.dat') . '.gz'; try { $result = Http::downloadChunk( - $url = Piwik_UserCountry_LocationProvider_GeoIp::GEO_LITE_URL, + $url = GeoIp::GEO_LITE_URL, $outputPath, $continue = Common::getRequestVar('continue', true, 'int') ); // if the file is done if ($result['current_size'] >= $result['expected_file_size']) { - Piwik_UserCountry_GeoIPAutoUpdater::unzipDownloadedFile($outputPath, $unlink = true); + GeoIPAutoUpdater::unzipDownloadedFile($outputPath, $unlink = true); // setup the auto updater - Piwik_UserCountry_GeoIPAutoUpdater::setUpdaterOptions(array( - 'loc_db' => Piwik_UserCountry_LocationProvider_GeoIp::GEO_LITE_URL, - 'period' => Piwik_UserCountry_GeoIPAutoUpdater::SCHEDULE_PERIOD_MONTHLY, - )); + GeoIPAutoUpdater::setUpdaterOptions(array( + 'loc_db' => GeoIp::GEO_LITE_URL, + 'period' => GeoIPAutoUpdater::SCHEDULE_PERIOD_MONTHLY, + )); // make sure to echo out the geoip updater management screen $result['next_screen'] = $this->getGeoIpUpdaterManageScreen(); @@ -155,16 +164,16 @@ class Piwik_UserCountry_Controller extends Admin */ private function setUpdaterManageVars($view) { - $urls = Piwik_UserCountry_GeoIPAutoUpdater::getConfiguredUrls(); + $urls = GeoIPAutoUpdater::getConfiguredUrls(); $view->geoIPLocUrl = $urls['loc']; $view->geoIPIspUrl = $urls['isp']; $view->geoIPOrgUrl = $urls['org']; - $view->geoIPUpdatePeriod = Piwik_UserCountry_GeoIPAutoUpdater::getSchedulePeriod(); + $view->geoIPUpdatePeriod = GeoIPAutoUpdater::getSchedulePeriod(); - $view->geoLiteUrl = Piwik_UserCountry_LocationProvider_GeoIp::GEO_LITE_URL; + $view->geoLiteUrl = GeoIp::GEO_LITE_URL; - $lastRunTime = Piwik_UserCountry_GeoIPAutoUpdater::getLastRunTime(); + $lastRunTime = GeoIPAutoUpdater::getLastRunTime(); if ($lastRunTime !== false) { $view->lastTimeUpdaterRun = '<strong><em>' . $lastRunTime->toString() . '</em></strong>'; } @@ -191,7 +200,7 @@ class Piwik_UserCountry_Controller extends Admin try { $this->checkTokenInUrl(); - Piwik_UserCountry_GeoIPAutoUpdater::setUpdaterOptionsFromUrl(); + GeoIPAutoUpdater::setUpdaterOptionsFromUrl(); // if there is a updater URL for a database, but its missing from the misc dir, tell // the browser so it can download it next @@ -237,15 +246,15 @@ class Piwik_UserCountry_Controller extends Admin // based on the database type (provided by the 'key' query param) determine the // url & output file name $key = Common::getRequestVar('key', null, 'string'); - $url = Piwik_UserCountry_GeoIPAutoUpdater::getConfiguredUrl($key); + $url = GeoIPAutoUpdater::getConfiguredUrl($key); - $ext = Piwik_UserCountry_GeoIPAutoUpdater::getGeoIPUrlExtension($url); - $filename = Piwik_UserCountry_LocationProvider_GeoIp::$dbNames[$key][0] . '.' . $ext; + $ext = GeoIPAutoUpdater::getGeoIPUrlExtension($url); + $filename = GeoIp::$dbNames[$key][0] . '.' . $ext; if (substr($filename, 0, 15) == 'GeoLiteCity.dat') { $filename = 'GeoIPCity.dat' . substr($filename, 15); } - $outputPath = Piwik_UserCountry_LocationProvider_GeoIp::getPathForGeoIpDatabase($filename); + $outputPath = GeoIp::getPathForGeoIpDatabase($filename); // download part of the file $result = Http::downloadChunk( @@ -253,7 +262,7 @@ class Piwik_UserCountry_Controller extends Admin // if the file is done if ($result['current_size'] >= $result['expected_file_size']) { - Piwik_UserCountry_GeoIPAutoUpdater::unzipDownloadedFile($outputPath, $unlink = true); + GeoIPAutoUpdater::unzipDownloadedFile($outputPath, $unlink = true); $info = $this->getNextMissingDbUrlInfo(); if ($info !== false) { @@ -285,7 +294,7 @@ class Piwik_UserCountry_Controller extends Admin $this->checkTokenInUrl(); $providerId = Common::getRequestVar('id'); - $provider = Piwik_UserCountry_LocationProvider::setCurrentProvider($providerId); + $provider = LocationProvider::setCurrentProvider($providerId); if ($provider === false) { throw new Exception("Invalid provider ID: '$providerId'."); } @@ -305,7 +314,7 @@ class Piwik_UserCountry_Controller extends Admin public function getLocationUsingProvider() { $providerId = Common::getRequestVar('id'); - $provider = $provider = Piwik_UserCountry_LocationProvider::getProviderById($providerId); + $provider = $provider = LocationProvider::getProviderById($providerId); if ($provider === false) { throw new Exception("Invalid provider ID: '$providerId'."); } @@ -313,7 +322,7 @@ class Piwik_UserCountry_Controller extends Admin $location = $provider->getLocation(array('ip' => IP::getIpFromHeader(), 'lang' => Common::getBrowserLanguage(), 'disable_fallbacks' => true)); - $location = Piwik_UserCountry_LocationProvider::prettyFormatLocation( + $location = LocationProvider::prettyFormatLocation( $location, $newline = '<br/>', $includeExtra = true); echo $location; @@ -370,11 +379,11 @@ class Piwik_UserCountry_Controller extends Admin */ private function getNextMissingDbUrlInfo() { - $missingDbs = Piwik_UserCountry_GeoIPAutoUpdater::getMissingDatabases(); + $missingDbs = GeoIPAutoUpdater::getMissingDatabases(); if (!empty($missingDbs)) { $missingDbKey = $missingDbs[0]; - $missingDbName = Piwik_UserCountry_LocationProvider_GeoIp::$dbNames[$missingDbKey][0]; - $url = Piwik_UserCountry_GeoIPAutoUpdater::getConfiguredUrl($missingDbKey); + $missingDbName = GeoIp::$dbNames[$missingDbKey][0]; + $url = GeoIPAutoUpdater::getConfiguredUrl($missingDbKey); $link = '<a href="' . $url . '">' . $missingDbName . '</a>'; diff --git a/plugins/UserCountry/GeoIPAutoUpdater.php b/plugins/UserCountry/GeoIPAutoUpdater.php index 66ec7bd343..86383ed4d8 100755 --- a/plugins/UserCountry/GeoIPAutoUpdater.php +++ b/plugins/UserCountry/GeoIPAutoUpdater.php @@ -6,22 +6,28 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountry + * @package UserCountry */ +namespace Piwik\Plugins\UserCountry; + +use Exception; use Piwik\Piwik; use Piwik\Common; use Piwik\Date; use Piwik\Http; +use Piwik\Plugins\UserCountry\LocationProvider; use Piwik\ScheduledTime\Monthly; use Piwik\ScheduledTime\Weekly; use Piwik\Unzip; use Piwik\ScheduledTask; +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp\Php; /** * Used to automatically update installed GeoIP databases, and manages the updater's * scheduled task. */ -class Piwik_UserCountry_GeoIPAutoUpdater +class GeoIPAutoUpdater { const SCHEDULE_PERIOD_MONTHLY = 'month'; const SCHEDULE_PERIOD_WEEKLY = 'week'; @@ -71,7 +77,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater $this->downloadFile('org', $orgUrl); } } catch (Exception $ex) { - // message will already be prefixed w/ 'Piwik_UserCountry_GeoIPAutoUpdater: ' + // message will already be prefixed w/ 'GeoIPAutoUpdater: ' Piwik::log($ex->getMessage()); $this->performRedundantDbChecks(); throw $ex; @@ -94,34 +100,34 @@ class Piwik_UserCountry_GeoIPAutoUpdater */ protected function downloadFile($dbType, $url) { - $ext = Piwik_UserCountry_GeoIPAutoUpdater::getGeoIPUrlExtension($url); - $zippedFilename = Piwik_UserCountry_LocationProvider_GeoIp::$dbNames[$dbType][0] . '.' . $ext; + $ext = GeoIPAutoUpdater::getGeoIPUrlExtension($url); + $zippedFilename = GeoIp::$dbNames[$dbType][0] . '.' . $ext; - $zippedOutputPath = Piwik_UserCountry_LocationProvider_GeoIp::getPathForGeoIpDatabase($zippedFilename); + $zippedOutputPath = GeoIp::getPathForGeoIpDatabase($zippedFilename); // download zipped file to misc dir try { $success = Http::sendHttpRequest($url, $timeout = 3600, $userAgent = null, $zippedOutputPath); } catch (Exception $ex) { - throw new Exception("Piwik_UserCountry_GeoIPAutoUpdater: failed to download '$url' to " + throw new Exception("GeoIPAutoUpdater: failed to download '$url' to " . "'$zippedOutputPath': " . $ex->getMessage()); } if ($success !== true) { - throw new Exception("Piwik_UserCountry_GeoIPAutoUpdater: failed to download '$url' to " + throw new Exception("GeoIPAutoUpdater: failed to download '$url' to " . "'$zippedOutputPath'! (Unknown error)"); } - Piwik::log(sprintf("Piwik_UserCountry_GeoIPAutoUpdater: successfully downloaded '%s'", $url)); + Piwik::log(sprintf("GeoIPAutoUpdater: successfully downloaded '%s'", $url)); try { self::unzipDownloadedFile($zippedOutputPath, $unlink = true); } catch (Exception $ex) { - throw new Exception("Piwik_UserCountry_GeoIPAutoUpdater: failed to unzip '$zippedOutputPath' after " + throw new Exception("GeoIPAutoUpdater: failed to unzip '$zippedOutputPath' after " . "downloading " . "'$url': " . $ex->getMessage()); } - Piwik::log(sprintf("Piwik_UserCountry_GeoIPAutoUpdater: successfully updated GeoIP database '%s'", $url)); + Piwik::log(sprintf("GeoIPAutoUpdater: successfully updated GeoIP database '%s'", $url)); } /** @@ -138,7 +144,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater $dbFilename = $filenameStart . '.dat'; $tempFilename = $filenameStart . '.dat.new'; - $outputPath = Piwik_UserCountry_LocationProvider_GeoIp::getPathForGeoIpDatabase($tempFilename); + $outputPath = GeoIp::getPathForGeoIpDatabase($tempFilename); // extract file if (substr($path, -7, 7) == '.tar.gz') { @@ -191,7 +197,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater try { // test that the new archive is a valid GeoIP database - $dbType = Piwik_UserCountry_LocationProvider_GeoIp::getGeoIPDatabaseTypeFromFilename($dbFilename); + $dbType = GeoIp::getGeoIPDatabaseTypeFromFilename($dbFilename); if ($dbType === false) // sanity check { throw new Exception("Unexpected GeoIP archive file name '$path'."); @@ -204,7 +210,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater ); $customDbNames[$dbType] = array($tempFilename); - $phpProvider = new Piwik_UserCountry_LocationProvider_GeoIp_Php($customDbNames); + $phpProvider = new Php($customDbNames); $location = self::getTestLocationCatchPhpErrors($phpProvider); @@ -213,7 +219,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater ) { if (self::$unzipPhpError !== null) { list($errno, $errstr, $errfile, $errline) = self::$unzipPhpError; - Piwik::log("Piwik_UserCountry_GeoIPAutoUpdater: Encountered PHP error when testing newly downloaded" . + Piwik::log("GeoIPAutoUpdater: Encountered PHP error when testing newly downloaded" . " GeoIP database: $errno: $errstr on line $errline of $errfile."); } @@ -221,12 +227,12 @@ class Piwik_UserCountry_GeoIPAutoUpdater } // delete the existing GeoIP database (if any) and rename the downloaded file - $oldDbFile = Piwik_UserCountry_LocationProvider_GeoIp::getPathForGeoIpDatabase($dbFilename); + $oldDbFile = GeoIp::getPathForGeoIpDatabase($dbFilename); if (file_exists($oldDbFile)) { unlink($oldDbFile); } - $tempFile = Piwik_UserCountry_LocationProvider_GeoIp::getPathForGeoIpDatabase($tempFilename); + $tempFile = GeoIp::getPathForGeoIpDatabase($tempFilename); rename($existing = $tempFile, $newName = $oldDbFile); // delete original archive @@ -251,7 +257,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater */ public static function makeScheduledTask() { - $instance = new Piwik_UserCountry_GeoIPAutoUpdater(); + $instance = new GeoIPAutoUpdater(); $schedulePeriodStr = self::getSchedulePeriod(); @@ -379,7 +385,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater */ public static function performUpdate() { - $instance = new Piwik_UserCountry_GeoIPAutoUpdater(); + $instance = new GeoIPAutoUpdater(); $instance->update(); } @@ -412,8 +418,8 @@ class Piwik_UserCountry_GeoIPAutoUpdater if (!empty($url)) { // if a database of the type does not exist, but there's a url to update, then // a database is missing - $path = Piwik_UserCountry_LocationProvider_GeoIp::getPathToGeoIpDatabase( - Piwik_UserCountry_LocationProvider_GeoIp::$dbNames[$key]); + $path = GeoIp::getPathToGeoIpDatabase( + GeoIp::$dbNames[$key]); if ($path === false) { $result[] = $key; } @@ -465,7 +471,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater * Tests a location provider using a test IP address and catches PHP errors * (ie, notices) if they occur. PHP error information is held in self::$unzipPhpError. * - * @param Piwik_UserCountry_LocationProvider $provider The provider to test. + * @param LocationProvider $provider The provider to test. * @return array|false $location The result of geolocation. False if no location * can be found. */ @@ -475,9 +481,9 @@ class Piwik_UserCountry_GeoIPAutoUpdater // in order to delete the files in such a case (which can be caused by a man-in-the-middle attack) // we need to catch them, so we set a new error handler. self::$unzipPhpError = null; - set_error_handler(array('Piwik_UserCountry_GeoIPAutoUpdater', 'catchGeoIPError')); + set_error_handler(array('Piwik\Plugins\UserCountry\GeoIPAutoUpdater', 'catchGeoIPError')); - $location = $provider->getLocation(array('ip' => Piwik_UserCountry_LocationProvider_GeoIp::TEST_IP)); + $location = $provider->getLocation(array('ip' => GeoIp::TEST_IP)); restore_error_handler(); @@ -496,7 +502,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater */ protected function performRedundantDbChecks() { - $databaseTypes = array_keys(Piwik_UserCountry_LocationProvider_GeoIp::$dbNames); + $databaseTypes = array_keys(GeoIp::$dbNames); foreach ($databaseTypes as $type) { $customNames = array( @@ -504,16 +510,16 @@ class Piwik_UserCountry_GeoIPAutoUpdater 'isp' => array(), 'org' => array() ); - $customNames[$type] = Piwik_UserCountry_LocationProvider_GeoIp::$dbNames[$type]; + $customNames[$type] = GeoIp::$dbNames[$type]; // create provider that only uses the DB type we're testing - $provider = new Piwik_UserCountry_LocationProvider_GeoIp_Php($customNames); + $provider = new Php($customNames); // test the provider. on error, we rename the broken DB. self::getTestLocationCatchPhpErrors($provider); if (self::$unzipPhpError !== null) { list($errno, $errstr, $errfile, $errline) = self::$unzipPhpError; - Piwik::log("Piwik_UserCountry_GeoIPAutoUpdater: Encountered PHP error when performing redundant " . + Piwik::log("GeoIPAutoUpdater: Encountered PHP error when performing redundant " . "tests on GeoIP $type database: $errno: $errstr on line $errline of $errfile."); // get the current filename for the DB and an available new one to rename it to @@ -543,7 +549,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater */ private function getOldAndNewPathsForBrokenDb($possibleDbNames) { - $pathToDb = Piwik_UserCountry_LocationProvider_GeoIp::getPathToGeoIpDatabase($possibleDbNames); + $pathToDb = GeoIp::getPathToGeoIpDatabase($possibleDbNames); $newPath = false; if ($pathToDb !== false) { diff --git a/plugins/UserCountry/LocationProvider.php b/plugins/UserCountry/LocationProvider.php index bb82ebc9f5..946e131f19 100755 --- a/plugins/UserCountry/LocationProvider.php +++ b/plugins/UserCountry/LocationProvider.php @@ -6,11 +6,16 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountry + * @package UserCountry */ +namespace Piwik\Plugins\UserCountry; + +use Exception; use Piwik\Common; use Piwik\IP; use Piwik\Tracker\Cache; +use Piwik\Plugins\UserCountry\LocationProvider\DefaultProvider; +use ReflectionClass; /** * @see plugins/UserCountry/LocationProvider/Default.php @@ -29,7 +34,7 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/LocationProvider/GeoIp.p * visitor info. All LocationProviders require a visitor's IP address, some * require more, such as the browser language. */ -abstract class Piwik_UserCountry_LocationProvider +abstract class LocationProvider { const NOT_INSTALLED = 0; const INSTALLED = 1; @@ -139,7 +144,7 @@ abstract class Piwik_UserCountry_LocationProvider if (is_null(self::$providers)) { self::$providers = array(); foreach (get_declared_classes() as $klass) { - if (is_subclass_of($klass, 'Piwik_UserCountry_LocationProvider')) { + if (is_subclass_of($klass, 'Piwik\Plugins\UserCountry\LocationProvider')) { $klassInfo = new ReflectionClass($klass); if ($klassInfo->isAbstract()) { continue; @@ -188,7 +193,7 @@ abstract class Piwik_UserCountry_LocationProvider * 'geoip_php' => array('id' => 'geoip_php', * 'title' => '...', * 'desc' => '...', - * 'status' => Piwik_UserCountry_LocationProvider_GeoIp::BROKEN, + * 'status' => GeoIp::BROKEN, * 'statusMessage' => '...', * 'location' => '...') * 'geoip_serverbased' => array(...) @@ -259,7 +264,7 @@ abstract class Piwik_UserCountry_LocationProvider public static function getCurrentProviderId() { $optionValue = Piwik_GetOption(self::CURRENT_PROVIDER_OPTION_NAME); - return $optionValue === false ? Piwik_UserCountry_LocationProvider_Default::ID : $optionValue; + return $optionValue === false ? DefaultProvider::ID : $optionValue; } /** @@ -267,7 +272,7 @@ abstract class Piwik_UserCountry_LocationProvider * * This function should not be called by the Tracker. * - * @return Piwik_UserCountry_LocationProvider + * @return \Piwik\Plugins\UserCountry\LocationProvider */ public static function getCurrentProvider() { @@ -278,7 +283,7 @@ abstract class Piwik_UserCountry_LocationProvider * Sets the provider to use when tracking. * * @param string $providerId The ID of the provider to use. - * @return Piwik_UserCountry_LocationProvider The new current provider. + * @return \Piwik\Plugins\UserCountry\LocationProvider The new current provider. * @throws Exception If the provider ID is invalid. */ public static function setCurrentProvider($providerId) @@ -297,7 +302,7 @@ abstract class Piwik_UserCountry_LocationProvider * Returns a provider instance by ID or false if the ID is invalid or unavailable. * * @param string $providerId - * @return Piwik_UserCountry_LocationProvider|false + * @return \Piwik\Plugins\UserCountry\LocationProvider|false */ public static function getProviderById($providerId) { diff --git a/plugins/UserCountry/LocationProvider/Default.php b/plugins/UserCountry/LocationProvider/Default.php index f5956076b6..a8eeb1688d 100755 --- a/plugins/UserCountry/LocationProvider/Default.php +++ b/plugins/UserCountry/LocationProvider/Default.php @@ -6,18 +6,21 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountry + * @package UserCountry */ +namespace Piwik\Plugins\UserCountry\LocationProvider; + use Piwik\Config; use Piwik\Common; +use Piwik\Plugins\UserCountry\LocationProvider; /** * The default LocationProvider, this LocationProvider guesses a visitor's country * using the language they use. This provider is not very accurate. * - * @package Piwik_UserCountry + * @package UserCountry */ -class Piwik_UserCountry_LocationProvider_Default extends Piwik_UserCountry_LocationProvider +class DefaultProvider extends LocationProvider { const ID = 'default'; const TITLE = 'General_Default'; diff --git a/plugins/UserCountry/LocationProvider/GeoIp.php b/plugins/UserCountry/LocationProvider/GeoIp.php index 5cf139ac12..b40783d7c4 100755 --- a/plugins/UserCountry/LocationProvider/GeoIp.php +++ b/plugins/UserCountry/LocationProvider/GeoIp.php @@ -6,15 +6,19 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountry + * @package UserCountry */ +namespace Piwik\Plugins\UserCountry\LocationProvider; + +use Exception; +use Piwik\Plugins\UserCountry\LocationProvider; /** * Base type for all GeoIP LocationProviders. * - * @package Piwik_UserCountry + * @package UserCountry */ -abstract class Piwik_UserCountry_LocationProvider_GeoIp extends Piwik_UserCountry_LocationProvider +abstract class GeoIp extends LocationProvider { /* For testing, use: 'http://piwik-team.s3.amazonaws.com/GeoLiteCity.dat.gz' */ const GEO_LITE_URL = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz'; @@ -255,7 +259,6 @@ abstract class Piwik_UserCountry_LocationProvider_GeoIp extends Piwik_UserCountr } } - /** * @see plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php */ diff --git a/plugins/UserCountry/LocationProvider/GeoIp/Pecl.php b/plugins/UserCountry/LocationProvider/GeoIp/Pecl.php index 9ffc4ffa0a..c4113fd9e8 100755 --- a/plugins/UserCountry/LocationProvider/GeoIp/Pecl.php +++ b/plugins/UserCountry/LocationProvider/GeoIp/Pecl.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountry + * @package UserCountry */ +namespace Piwik\Plugins\UserCountry\LocationProvider\GeoIp; + +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; /** * A LocationProvider that uses the PECL implementation of GeoIP. @@ -15,9 +18,9 @@ * FIXME: For some reason, if the PECL module is loaded & an organization DB is available, the PHP * module won't return organization info. If the PECL module is not loaded, organization info is returned. * - * @package Piwik_UserCountry + * @package UserCountry */ -class Piwik_UserCountry_LocationProvider_GeoIp_Pecl extends Piwik_UserCountry_LocationProvider_GeoIp +class Pecl extends GeoIp { const ID = 'geoip_pecl'; const TITLE = 'GeoIP (PECL)'; diff --git a/plugins/UserCountry/LocationProvider/GeoIp/Php.php b/plugins/UserCountry/LocationProvider/GeoIp/Php.php index 001b7f8c4e..dc54f5b29c 100755 --- a/plugins/UserCountry/LocationProvider/GeoIp/Php.php +++ b/plugins/UserCountry/LocationProvider/GeoIp/Php.php @@ -6,16 +6,19 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountry + * @package UserCountry */ +namespace Piwik\Plugins\UserCountry\LocationProvider\GeoIp; + use Piwik\Piwik; +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; /** * A LocationProvider that uses the PHP implementation of GeoIP. * - * @package Piwik_UserCountry + * @package UserCountry */ -class Piwik_UserCountry_LocationProvider_GeoIp_Php extends Piwik_UserCountry_LocationProvider_GeoIp +class Php extends GeoIp { const ID = 'geoip_php'; const TITLE = 'GeoIP (Php)'; @@ -38,7 +41,7 @@ class Piwik_UserCountry_LocationProvider_GeoIp_Php extends Piwik_UserCountry_Loc * This variable is an array mapping either the 'loc', 'isp' or 'org' strings with * an array of filenames. * - * By default, this will be set to Piwik_UserCountry_LocationProvider_GeoIp_Php::$dbNames. + * By default, this will be set to Php::$dbNames. * * @var array */ diff --git a/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php b/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php index ab3942974f..7d2be065d2 100755 --- a/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php +++ b/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php @@ -6,11 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountry + * @package UserCountry */ +namespace Piwik\Plugins\UserCountry\LocationProvider\GeoIp; + use Piwik\Common; use Piwik\IP; +use Piwik\Plugins\UserCountry\LocationProvider; +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp\Pecl; +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp\Php; /** * A LocationProvider that uses an GeoIP module installed in an HTTP Server. @@ -18,9 +24,9 @@ use Piwik\IP; * To make this provider available, make sure the GEOIP_ADDR server * variable is set. * - * @package Piwik_UserCountry + * @package UserCountry */ -class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCountry_LocationProvider_GeoIp +class ServerBased extends GeoIp { const ID = 'geoip_serverbased'; const TITLE = 'GeoIP (%s)'; @@ -74,11 +80,11 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou ) { Common::printDebug("The request is for IP address: " . $info['ip'] . " but your IP is: $myIP. GeoIP Server Module (apache/nginx) does not support this use case... "); $fallbacks = array( - Piwik_UserCountry_LocationProvider_GeoIp_Pecl::ID, - Piwik_UserCountry_LocationProvider_GeoIp_Php::ID + Pecl::ID, + Php::ID ); foreach ($fallbacks as $fallbackProviderId) { - $otherProvider = Piwik_UserCountry_LocationProvider::getProviderById($fallbackProviderId); + $otherProvider = LocationProvider::getProviderById($fallbackProviderId); if ($otherProvider) { Common::printDebug("Used $fallbackProviderId to detect this visitor IP"); return $otherProvider->getLocation($info); diff --git a/plugins/UserCountry/UserCountry.php b/plugins/UserCountry/UserCountry.php index 282c433563..a2fcc00992 100644 --- a/plugins/UserCountry/UserCountry.php +++ b/plugins/UserCountry/UserCountry.php @@ -6,13 +6,20 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountry + * @package UserCountry */ +namespace Piwik\Plugins\UserCountry; + use Piwik\ArchiveProcessor; use Piwik\Common; use Piwik\Piwik; -use Piwik\Plugin; use Piwik\WidgetsList; +use Piwik_Url; +use Piwik\Plugins\UserCountry\Archiver; +use Piwik\Plugins\UserCountry\GeoIPAutoUpdater; +use Piwik\Plugins\UserCountry\LocationProvider; +use Piwik\Plugins\UserCountry\LocationProvider\DefaultProvider; +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; /** * @see plugins/UserCountry/GeoIPAutoUpdater.php @@ -21,9 +28,9 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/GeoIPAutoUpdater.php'; /** * - * @package Piwik_UserCountry + * @package UserCountry */ -class Piwik_UserCountry extends Plugin +class UserCountry extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered @@ -31,18 +38,18 @@ class Piwik_UserCountry extends Plugin public function getListHooksRegistered() { $hooks = array( - 'ArchiveProcessing_Day.compute' => 'archiveDay', - 'ArchiveProcessing_Period.compute' => 'archivePeriod', - 'WidgetsList.add' => 'addWidgets', - 'Menu.add' => 'addMenu', - 'AdminMenu.add' => 'addAdminMenu', - 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', - 'API.getReportMetadata' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', - 'AssetManager.getCssFiles' => 'getCssFiles', - 'AssetManager.getJsFiles' => 'getJsFiles', - 'Tracker.getVisitorLocation' => 'getVisitorLocation', - 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks', + 'ArchiveProcessing_Day.compute' => 'archiveDay', + 'ArchiveProcessing_Period.compute' => 'archivePeriod', + 'WidgetsList.add' => 'addWidgets', + 'Menu.add' => 'addMenu', + 'AdminMenu.add' => 'addAdminMenu', + 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', + 'API.getReportMetadata' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'AssetManager.getCssFiles' => 'getCssFiles', + 'AssetManager.getJsFiles' => 'getJsFiles', + 'Tracker.getVisitorLocation' => 'getVisitorLocation', + 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks', 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); return $hooks; @@ -51,7 +58,7 @@ class Piwik_UserCountry extends Plugin public function getScheduledTasks(&$tasks) { // add the auto updater task - $tasks[] = Piwik_UserCountry_GeoIPAutoUpdater::makeScheduledTask(); + $tasks[] = GeoIPAutoUpdater::makeScheduledTask(); } public function getCssFiles(&$cssFiles) @@ -69,10 +76,10 @@ class Piwik_UserCountry extends Plugin require_once PIWIK_INCLUDE_PATH . "/plugins/UserCountry/LocationProvider.php"; $id = Common::getCurrentLocationProviderId(); - $provider = Piwik_UserCountry_LocationProvider::getProviderById($id); + $provider = LocationProvider::getProviderById($id); if ($provider === false) { - $id = Piwik_UserCountry_LocationProvider_Default::ID; - $provider = Piwik_UserCountry_LocationProvider::getProviderById($id); + $id = DefaultProvider::ID; + $provider = LocationProvider::getProviderById($id); Common::printDebug("GEO: no current location provider sent, falling back to default '$id' one."); } @@ -80,8 +87,8 @@ class Piwik_UserCountry extends Plugin // if we can't find a location, use default provider if ($location === false) { - $defaultId = Piwik_UserCountry_LocationProvider_Default::ID; - $provider = Piwik_UserCountry_LocationProvider::getProviderById($defaultId); + $defaultId = DefaultProvider::ID; + $provider = LocationProvider::getProviderById($defaultId); $location = $provider->getLocation($visitorInfo); Common::printDebug("GEO: couldn't find a location with Geo Module '$id', using Default '$defaultId' provider as fallback..."); $id = $defaultId; @@ -139,7 +146,7 @@ class Piwik_UserCountry extends Plugin 'segment' => 'continentCode', 'sqlSegment' => 'log_visit.location_country', 'acceptedValues' => 'eur, asi, amc, amn, ams, afr, ant, oce', - 'sqlFilter' => array('Piwik_UserCountry', 'getCountriesForContinent'), + 'sqlFilter' => __NAMESPACE__ . '\UserCountry::getCountriesForContinent', ); $segments[] = array( 'type' => 'dimension', @@ -250,21 +257,20 @@ class Piwik_UserCountry extends Plugin public function archivePeriod(ArchiveProcessor\Period $archiveProcessor) { - $archiving = new Piwik_UserCountry_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archivePeriod(); } } public function archiveDay(ArchiveProcessor\Day $archiveProcessor) { - $archiving = new Piwik_UserCountry_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archiveDay(); } } - /** * Returns a list of country codes for a given continent code. * @@ -296,10 +302,10 @@ class Piwik_UserCountry extends Plugin { return array( 'show_exclude_low_population' => false, - 'show_goals' => true, - 'filter_limit' => 5, - 'translations' => array('label' => Piwik_Translate('UserCountry_Country')), - 'documentation' => Piwik_Translate('UserCountry_getCountryDocumentation') + 'show_goals' => true, + 'filter_limit' => 5, + 'translations' => array('label' => Piwik_Translate('UserCountry_Country')), + 'documentation' => Piwik_Translate('UserCountry_getCountryDocumentation') ); } @@ -307,12 +313,12 @@ class Piwik_UserCountry extends Plugin { return array( 'show_exclude_low_population' => false, - 'show_goals' => true, - 'show_search' => false, - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'translations' => array('label' => Piwik_Translate('UserCountry_Continent')), - 'documentation' => Piwik_Translate('UserCountry_getContinentDocumentation') + 'show_goals' => true, + 'show_search' => false, + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'translations' => array('label' => Piwik_Translate('UserCountry_Continent')), + 'documentation' => Piwik_Translate('UserCountry_getContinentDocumentation') ); } @@ -320,11 +326,11 @@ class Piwik_UserCountry extends Plugin { $result = array( 'show_exclude_low_population' => false, - 'show_goals' => true, - 'filter_limit' => 5, - 'translations' => array('label' => Piwik_Translate('UserCountry_Region')), - 'documentation' => Piwik_Translate('UserCountry_getRegionDocumentation') . '<br/>' - . $this->getGeoIPReportDocSuffix() + 'show_goals' => true, + 'filter_limit' => 5, + 'translations' => array('label' => Piwik_Translate('UserCountry_Region')), + 'documentation' => Piwik_Translate('UserCountry_getRegionDocumentation') . '<br/>' + . $this->getGeoIPReportDocSuffix() ); $this->checkIfNoDataForGeoIpReport($result); return $result; @@ -334,11 +340,11 @@ class Piwik_UserCountry extends Plugin { $result = array( 'show_exclude_low_population' => false, - 'show_goals' => true, - 'filter_limit' => 5, - 'translations' => array('label' => Piwik_Translate('UserCountry_City')), - 'documentation' => Piwik_Translate('UserCountry_getCityDocumentation') . '<br/>' - . $this->getGeoIPReportDocSuffix() + 'show_goals' => true, + 'filter_limit' => 5, + 'translations' => array('label' => Piwik_Translate('UserCountry_City')), + 'documentation' => Piwik_Translate('UserCountry_getCityDocumentation') . '<br/>' + . $this->getGeoIPReportDocSuffix() ); $this->checkIfNoDataForGeoIpReport($result); return $result; @@ -393,8 +399,8 @@ class Piwik_UserCountry extends Plugin */ public function isGeoIPWorking() { - $provider = Piwik_UserCountry_LocationProvider::getCurrentProvider(); - return $provider instanceof Piwik_UserCountry_LocationProvider_GeoIp + $provider = LocationProvider::getCurrentProvider(); + return $provider instanceof GeoIp && $provider->isAvailable() === true && $provider->isWorking() === true; } diff --git a/plugins/UserCountry/functions.php b/plugins/UserCountry/functions.php index cdc408a273..cae545f521 100644 --- a/plugins/UserCountry/functions.php +++ b/plugins/UserCountry/functions.php @@ -6,9 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountry + * @package UserCountry */ + +namespace Piwik\Plugins\UserCountry; + use Piwik\DataTable; +use Piwik\Plugins\UserCountry\Archiver; +use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; use Piwik\Tracker\Visit; /** @@ -17,7 +22,7 @@ use Piwik\Tracker\Visit; * @param string $code ISO country code * @return string Flag image path */ -function Piwik_getFlagFromCode($code) +function getFlagFromCode($code) { $pathInPiwik = 'plugins/UserCountry/images/flags/%s.png'; $pathWithCode = sprintf($pathInPiwik, $code); @@ -34,7 +39,7 @@ function Piwik_getFlagFromCode($code) * @param string $label Continent code * @return string Continent name */ -function Piwik_ContinentTranslate($label) +function continentTranslate($label) { if ($label == 'unk' || $label == '') { return Piwik_Translate('General_Unknown'); @@ -48,7 +53,7 @@ function Piwik_ContinentTranslate($label) * @param string $label country code * @return string Country name */ -function Piwik_CountryTranslate($label) +function countryTranslate($label) { if ($label == Visit::UNKNOWN_CODE || $label == '') { return Piwik_Translate('General_Unknown'); @@ -67,7 +72,7 @@ function Piwik_CountryTranslate($label) * @return string|false Returns false if $label == DataTable::LABEL_SUMMARY_ROW, otherwise * explode($separator, $label)[$index]. */ -function Piwik_UserCountry_getElementFromStringArray($label, $separator, $index, $emptyValue = false) +function getElementFromStringArray($label, $separator, $index, $emptyValue = false) { if ($label == DataTable::LABEL_SUMMARY_ROW) { return false; // so no metadata/column is added @@ -84,7 +89,7 @@ function Piwik_UserCountry_getElementFromStringArray($label, $separator, $index, * 'P3|GB'. * @return string|false The region name or false if $label == DataTable::LABEL_SUMMARY_ROW. */ -function Piwik_UserCountry_getRegionName($label) +function getRegionName($label) { if ($label == DataTable::LABEL_SUMMARY_ROW) { return false; // so no metadata/column is added @@ -94,8 +99,8 @@ function Piwik_UserCountry_getRegionName($label) return Piwik_Translate('General_Unknown'); } - list($regionCode, $countryCode) = explode(Piwik_UserCountry_Archiver::LOCATION_SEPARATOR, $label); - return Piwik_UserCountry_LocationProvider_GeoIp::getRegionNameFromCodes($countryCode, $regionCode); + list($regionCode, $countryCode) = explode(Archiver::LOCATION_SEPARATOR, $label); + return GeoIp::getRegionNameFromCodes($countryCode, $regionCode); } /** @@ -106,7 +111,7 @@ function Piwik_UserCountry_getRegionName($label) * 'P3|GB'. * @return string|false eg. 'Ile de France, France' or false if $label == DataTable::LABEL_SUMMARY_ROW. */ -function Piwik_UserCountry_getPrettyRegionName($label) +function getPrettyRegionName($label) { if ($label == DataTable::LABEL_SUMMARY_ROW) { return $label; @@ -116,11 +121,11 @@ function Piwik_UserCountry_getPrettyRegionName($label) return Piwik_Translate('General_Unknown'); } - list($regionCode, $countryCode) = explode(Piwik_UserCountry_Archiver::LOCATION_SEPARATOR, $label); + list($regionCode, $countryCode) = explode(Archiver::LOCATION_SEPARATOR, $label); - $result = Piwik_UserCountry_LocationProvider_GeoIp::getRegionNameFromCodes($countryCode, $regionCode); + $result = GeoIp::getRegionNameFromCodes($countryCode, $regionCode); if ($countryCode != Visit::UNKNOWN_CODE && $countryCode != '') { - $result .= ', ' . Piwik_CountryTranslate($countryCode); + $result .= ', ' . countryTranslate($countryCode); } return $result; } @@ -134,7 +139,7 @@ function Piwik_UserCountry_getPrettyRegionName($label) * @return string|false eg. 'Paris, Ile de France, France' or false if $label == * DataTable::LABEL_SUMMARY_ROW. */ -function Piwik_UserCountry_getPrettyCityName($label) +function getPrettyCityName($label) { if ($label == DataTable::LABEL_SUMMARY_ROW) { return $label; @@ -145,7 +150,7 @@ function Piwik_UserCountry_getPrettyCityName($label) } // get city name, region code & country code - $parts = explode(Piwik_UserCountry_Archiver::LOCATION_SEPARATOR, $label); + $parts = explode(Archiver::LOCATION_SEPARATOR, $label); $cityName = $parts[0]; $regionCode = $parts[1]; $countryCode = @$parts[2]; @@ -157,10 +162,10 @@ function Piwik_UserCountry_getPrettyCityName($label) $result = $cityName; if ($countryCode != Visit::UNKNOWN_CODE && $countryCode != '') { if ($regionCode != '' && $regionCode != Visit::UNKNOWN_CODE) { - $regionName = Piwik_UserCountry_LocationProvider_GeoIp::getRegionNameFromCodes($countryCode, $regionCode); + $regionName = GeoIp::getRegionNameFromCodes($countryCode, $regionCode); $result .= ', ' . $regionName; } - $result .= ', ' . Piwik_CountryTranslate($countryCode); + $result .= ', ' . countryTranslate($countryCode); } return $result; } diff --git a/plugins/UserCountryMap/Controller.php b/plugins/UserCountryMap/Controller.php index d057c728c7..d81f4003d8 100644 --- a/plugins/UserCountryMap/Controller.php +++ b/plugins/UserCountryMap/Controller.php @@ -6,12 +6,15 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountryMap + * @package UserCountryMap */ +namespace Piwik\Plugins\UserCountryMap; + +use Exception; use Piwik\API\Request; use Piwik\Piwik; use Piwik\Common; -use Piwik\Controller; +use Piwik\Plugins\Goals\API; use Piwik\ViewDataTable; use Piwik\View; use Piwik\Site; @@ -19,9 +22,9 @@ use Piwik\Config; /** * - * @package Piwik_UserCountryMap + * @package UserCountryMap */ -class Piwik_UserCountryMap_Controller extends Controller +class Controller extends \Piwik\Controller { // By default plot up to the last 30 days of visitors on the map, for low traffic sites @@ -65,16 +68,16 @@ class Piwik_UserCountryMap_Controller extends Controller // some translations $view->localeJSON = Common::json_encode(array( - 'nb_visits' => Piwik_Translate('VisitsSummary_NbVisits'), - 'one_visit' => Piwik_Translate('General_OneVisit'), - 'no_visit' => Piwik_Translate('UserCountryMap_NoVisit'), - 'nb_actions' => Piwik_Translate('VisitsSummary_NbActionsDescription'), - 'nb_actions_per_visit' => Piwik_Translate('VisitsSummary_NbActionsPerVisit'), - 'bounce_rate' => Piwik_Translate('VisitsSummary_NbVisitsBounced'), - 'avg_time_on_site' => Piwik_Translate('VisitsSummary_AverageVisitDuration'), - 'and_n_others' => Piwik_Translate('UserCountryMap_AndNOthers'), - 'no_data' => Piwik_Translate('CoreHome_ThereIsNoDataForThisReport') - )); + 'nb_visits' => Piwik_Translate('VisitsSummary_NbVisits'), + 'one_visit' => Piwik_Translate('General_OneVisit'), + 'no_visit' => Piwik_Translate('UserCountryMap_NoVisit'), + 'nb_actions' => Piwik_Translate('VisitsSummary_NbActionsDescription'), + 'nb_actions_per_visit' => Piwik_Translate('VisitsSummary_NbActionsPerVisit'), + 'bounce_rate' => Piwik_Translate('VisitsSummary_NbVisitsBounced'), + 'avg_time_on_site' => Piwik_Translate('VisitsSummary_AverageVisitDuration'), + 'and_n_others' => Piwik_Translate('UserCountryMap_AndNOthers'), + 'no_data' => Piwik_Translate('CoreHome_ThereIsNoDataForThisReport') + )); $view->reqParamsJSON = $this->getEnrichedRequest($params = array( 'period' => $period, @@ -126,7 +129,7 @@ class Piwik_UserCountryMap_Controller extends Controller $view->defaultMetric = 'nb_visits'; $view->liveRefreshAfterMs = (int)Config::getInstance()->General['live_widget_refresh_after_seconds'] * 1000; - $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); + $goals = API::getInstance()->getGoals($idSite); $site = new Site($idSite); $view->hasGoals = !empty($goals) || $site->isEcommerceEnabled() ? 'true' : 'false'; @@ -151,11 +154,11 @@ class Piwik_UserCountryMap_Controller extends Controller )); $view->reqParamsJSON = $this->getEnrichedRequest(array( - 'period' => 'range', - 'idSite' => $idSite, - 'date' => self::REAL_TIME_WINDOW, - 'token_auth' => $token_auth, - )); + 'period' => 'range', + 'idSite' => $idSite, + 'date' => self::REAL_TIME_WINDOW, + 'token_auth' => $token_auth, + )); echo $view->render(); } @@ -165,16 +168,13 @@ class Piwik_UserCountryMap_Controller extends Controller $params['format'] = 'json'; $params['showRawMetrics'] = 1; $segment = \Piwik\API\Request::getRawSegmentFromRequest(); - if (!empty($segment) - && !empty($params['segment']) - ) { + if (!empty($segment)) { $params['segment'] = $segment; } return Common::json_encode($params); } - private function checkUserCountryPluginEnabled() { if (!\Piwik\PluginsManager::getInstance()->isPluginActivated('UserCountry')) { @@ -236,4 +236,4 @@ class Piwik_UserCountryMap_Controller extends Controller return $this->getApiRequestUrl('API', 'getProcessedReport&apiModule=' . $module . '&apiAction=' . $action, $idSite, $period, $date, $token_auth, $filter_by_country, $segmentOverride); } -}
\ No newline at end of file +} diff --git a/plugins/UserCountryMap/UserCountryMap.php b/plugins/UserCountryMap/UserCountryMap.php index 19e0c34590..66da62b137 100644 --- a/plugins/UserCountryMap/UserCountryMap.php +++ b/plugins/UserCountryMap/UserCountryMap.php @@ -6,18 +6,19 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserCountryMap + * @package UserCountryMap */ +namespace Piwik\Plugins\UserCountryMap; + use Piwik\FrontController; use Piwik\Version; use Piwik\WidgetsList; -use Piwik\Plugin; /** * - * @package Piwik_UserCountryMap + * @package UserCountryMap */ -class Piwik_UserCountryMap extends Plugin +class UserCountryMap extends \Piwik\Plugin { /** * @see Piwik_Plugin::getInformation @@ -38,7 +39,7 @@ class Piwik_UserCountryMap extends Plugin WidgetsList::add('General_Visitors', Piwik_Translate('UserCountryMap_VisitorMap'), 'UserCountryMap', 'visitorMap'); WidgetsList::add('Live!', Piwik_Translate('UserCountryMap_RealTimeMap'), 'UserCountryMap', 'realtimeMap'); - Piwik_AddAction('template_leftColumnUserCountry', array('Piwik_UserCountryMap', 'insertMapInLocationReport')); + Piwik_AddAction('template_leftColumnUserCountry', array('Piwik\Plugins\UserCountryMap\UserCountryMap', 'insertMapInLocationReport')); } static public function insertMapInLocationReport(&$out) diff --git a/plugins/UserSettings/API.php b/plugins/UserSettings/API.php index c1c5535c1c..9e0fdf12f3 100644 --- a/plugins/UserSettings/API.php +++ b/plugins/UserSettings/API.php @@ -6,12 +6,15 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserSettings + * @package UserSettings */ +namespace Piwik\Plugins\UserSettings; + use Piwik\Archive; use Piwik\Metrics; use Piwik\Piwik; use Piwik\DataTable; +use Piwik\Plugins\UserSettings\Archiver; /** * @see plugins/UserSettings/functions.php @@ -22,9 +25,9 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/UserSettings/functions.php'; * The UserSettings API lets you access reports about your Visitors technical settings: browsers, browser types (rendering engine), * operating systems, plugins supported in their browser, Screen resolution and Screen types (normal, widescreen, dual screen or mobile). * - * @package Piwik_UserSettings + * @package UserSettings */ -class Piwik_UserSettings_API +class API { static private $instance = null; @@ -49,27 +52,27 @@ class Piwik_UserSettings_API public function getResolution($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable(Piwik_UserSettings_Archiver::RESOLUTION_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Archiver::RESOLUTION_RECORD_NAME, $idSite, $period, $date, $segment); return $dataTable; } public function getConfiguration($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable(Piwik_UserSettings_Archiver::CONFIGURATION_RECORD_NAME, $idSite, $period, $date, $segment); - $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_getConfigurationLabel')); + $dataTable = $this->getDataTable(Archiver::CONFIGURATION_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable->queueFilter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getConfigurationLabel')); return $dataTable; } public function getOS($idSite, $period, $date, $segment = false, $addShortLabel = true) { - $dataTable = $this->getDataTable(Piwik_UserSettings_Archiver::OS_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Archiver::OS_RECORD_NAME, $idSite, $period, $date, $segment); // these filters are applied directly so other API methods can use GroupBy on the result of this method - $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getOSLogo')); + $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getOSLogo')); if ($addShortLabel) { $dataTable->filter( - 'ColumnCallbackAddMetadata', array('label', 'shortLabel', 'Piwik_getOSShortLabel')); + 'ColumnCallbackAddMetadata', array('label', 'shortLabel', __NAMESPACE__ . '\getOSShortLabel')); } - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_getOSLabel')); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getOSLabel')); return $dataTable; } @@ -80,7 +83,7 @@ class Piwik_UserSettings_API public function getOSFamily($idSite, $period, $date, $segment = false) { $dataTable = $this->getOS($idSite, $period, $date, $segment, $addShortLabel = false); - $dataTable->filter('GroupBy', array('label', 'Piwik_UserSettings_getOSFamily')); + $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getOSFamily')); $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_Translate')); return $dataTable; } @@ -91,12 +94,12 @@ class Piwik_UserSettings_API public function getMobileVsDesktop($idSite, $period, $date, $segment = false) { $dataTable = $this->getOS($idSite, $period, $date, $segment, $addShortLabel = false); - $dataTable->filter('GroupBy', array('label', 'Piwik_UserSettings_getDeviceTypeFromOS')); + $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getDeviceTypeFromOS')); $this->ensureDefaultRowsInTable($dataTable); // set the logo metadata $dataTable->queueFilter('MetadataCallbackReplace', - array('logo', 'Piwik_UserSettings_getDeviceTypeImg', null, array('label'))); + array('logo', __NAMESPACE__ . '\getDeviceTypeImg', null, array('label'))); // translate the labels $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_Translate')); @@ -133,15 +136,15 @@ class Piwik_UserSettings_API public function getBrowserVersion($idSite, $period, $date, $segment = false) { $dataTable = $this->getBrowserTable($idSite, $period, $date, $segment); - $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'shortLabel', 'Piwik_getBrowserShortLabel')); + $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'shortLabel', __NAMESPACE__ . '\getBrowserShortLabel')); return $dataTable; } protected function getBrowserTable($idSite, $period, $date, $segment) { - $dataTable = $this->getDataTable(Piwik_UserSettings_Archiver::BROWSER_RECORD_NAME, $idSite, $period, $date, $segment); - $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getBrowsersLogo')); - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_getBrowserLabel')); + $dataTable = $this->getDataTable(Archiver::BROWSER_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getBrowsersLogo')); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getBrowserLabel')); return $dataTable; } @@ -152,22 +155,22 @@ class Piwik_UserSettings_API public function getBrowser($idSite, $period, $date, $segment = false) { $dataTable = $this->getBrowserTable($idSite, $period, $date, $segment); - $dataTable->filter('GroupBy', array('label', 'Piwik_UserSettings_getBrowserFromBrowserVersion')); + $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getBrowserFromBrowserVersion')); return $dataTable; } public function getBrowserType($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable(Piwik_UserSettings_Archiver::BROWSER_TYPE_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Archiver::BROWSER_TYPE_RECORD_NAME, $idSite, $period, $date, $segment); $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'shortLabel', 'ucfirst')); - $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_getBrowserTypeLabel')); + $dataTable->queueFilter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getBrowserTypeLabel')); return $dataTable; } public function getWideScreen($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable(Piwik_UserSettings_Archiver::SCREEN_TYPE_RECORD_NAME, $idSite, $period, $date, $segment); - $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getScreensLogo')); + $dataTable = $this->getDataTable(Archiver::SCREEN_TYPE_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getScreensLogo')); $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'ucfirst')); return $dataTable; } @@ -175,8 +178,8 @@ class Piwik_UserSettings_API public function getPlugin($idSite, $period, $date, $segment = false) { // fetch all archive data required - $dataTable = $this->getDataTable(Piwik_UserSettings_Archiver::PLUGIN_RECORD_NAME, $idSite, $period, $date, $segment); - $browserTypes = $this->getDataTable(Piwik_UserSettings_Archiver::BROWSER_TYPE_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Archiver::PLUGIN_RECORD_NAME, $idSite, $period, $date, $segment); + $browserTypes = $this->getDataTable(Archiver::BROWSER_TYPE_RECORD_NAME, $idSite, $period, $date, $segment); $archive = Archive::build($idSite, $period, $date, $segment); $visitsSums = $archive->getDataTableFromNumeric('nb_visits'); @@ -225,7 +228,6 @@ class Piwik_UserSettings_API $visitsSum = $visitsSumTotal - $ieVisits; - // When Truncate filter is applied, it will call AddSummaryRow which tries to sum all rows. // We tell the object to skip the column nb_visits_percentage when aggregating (since it's not correct to sum % values) $table->setColumnAggregationOperation('nb_visits_percentage', 'skip'); @@ -236,7 +238,7 @@ class Piwik_UserSettings_API $table->filter('RangeCheck', array('nb_visits_percentage')); } - $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'logo', 'Piwik_getPluginsLogo')); + $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getPluginsLogo')); $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'ucfirst')); return $dataTable; @@ -244,8 +246,8 @@ class Piwik_UserSettings_API public function getLanguage($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable(Piwik_UserSettings_Archiver::LANGUAGE_RECORD_NAME, $idSite, $period, $date, $segment); - $dataTable->filter('ColumnCallbackReplace', array('label', 'Piwik_LanguageTranslate')); + $dataTable = $this->getDataTable(Archiver::LANGUAGE_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\languageTranslate')); $dataTable->filter('ReplaceColumnNames'); return $dataTable; } diff --git a/plugins/UserSettings/Archiver.php b/plugins/UserSettings/Archiver.php index d6ff51d459..d25420ec20 100644 --- a/plugins/UserSettings/Archiver.php +++ b/plugins/UserSettings/Archiver.php @@ -6,9 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserSettings + * @package UserSettings */ +namespace Piwik\Plugins\UserSettings; + use Piwik\Common; use Piwik\DataAccess\LogAggregator; use Piwik\Metrics; @@ -23,7 +25,7 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/UserSettings/functions.php'; * * @see PluginsArchiver */ -class Piwik_UserSettings_Archiver extends PluginsArchiver +class Archiver extends PluginsArchiver { const LANGUAGE_RECORD_NAME = 'UserSettings_language'; const PLUGIN_RECORD_NAME = 'UserSettings_plugin'; @@ -80,7 +82,7 @@ class Piwik_UserSettings_Archiver extends PluginsArchiver protected function aggregateByBrowserType(DataTable $tableBrowser) { - $tableBrowser->filter('GroupBy', array('label', 'Piwik_getBrowserFamily')); + $tableBrowser->filter('GroupBy', array('label', __NAMESPACE__ . '\getBrowserFamily')); $this->insertTable(self::BROWSER_TYPE_RECORD_NAME, $tableBrowser); } @@ -94,14 +96,14 @@ class Piwik_UserSettings_Archiver extends PluginsArchiver { $metrics = $this->getProcessor()->getMetricsForDimension(self::RESOLUTION_DIMENSION); $table = $this->getProcessor()->getDataTableFromDataArray($metrics); - $table->filter('ColumnCallbackDeleteRow', array('label', 'Piwik_UserSettings_keepStrlenGreater')); + $table->filter('ColumnCallbackDeleteRow', array('label', __NAMESPACE__ . '\keepStrlenGreater')); $this->insertTable(self::RESOLUTION_RECORD_NAME, $table); return $table; } protected function aggregateByScreenType(DataTable $resolutions) { - $resolutions->filter('GroupBy', array('label', 'Piwik_getScreenTypeFromResolution')); + $resolutions->filter('GroupBy', array('label', __NAMESPACE__ . '\getScreenTypeFromResolution')); $this->insertTable(self::SCREEN_TYPE_RECORD_NAME, $resolutions); } @@ -129,7 +131,7 @@ class Piwik_UserSettings_Archiver extends PluginsArchiver protected function aggregateByLanguage() { - $query = $this->getLogAggregator()->queryVisitsByDimension( array("label" => self::LANGUAGE_DIMENSION) ); + $query = $this->getLogAggregator()->queryVisitsByDimension(array("label" => self::LANGUAGE_DIMENSION)); $languageCodes = array_keys(Common::getLanguagesList()); $metricsByLanguage = new DataArray(); while ($row = $query->fetch()) { diff --git a/plugins/UserSettings/Controller.php b/plugins/UserSettings/Controller.php index b5180359f8..3bdd3e8f5d 100644 --- a/plugins/UserSettings/Controller.php +++ b/plugins/UserSettings/Controller.php @@ -6,17 +6,18 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserSettings + * @package UserSettings */ -use Piwik\Controller; +namespace Piwik\Plugins\UserSettings; + use Piwik\ViewDataTable; use Piwik\View; /** * - * @package Piwik_UserSettings + * @package UserSettings */ -class Piwik_UserSettings_Controller extends Controller +class Controller extends \Piwik\Controller { public function index() { @@ -33,12 +34,12 @@ class Piwik_UserSettings_Controller extends Controller echo $view->render(); } - + public function getResolution($fetch = false) { return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - + public function getConfiguration($fetch = false) { return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); diff --git a/plugins/UserSettings/UserSettings.php b/plugins/UserSettings/UserSettings.php index 46568956f9..ba52b97d0d 100644 --- a/plugins/UserSettings/UserSettings.php +++ b/plugins/UserSettings/UserSettings.php @@ -6,17 +6,19 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserSettings + * @package UserSettings */ +namespace Piwik\Plugins\UserSettings; + use Piwik\ArchiveProcessor; -use Piwik\Plugin; +use Piwik\Plugins\UserSettings\Archiver; use Piwik\WidgetsList; /** * - * @package Piwik_UserSettings + * @package UserSettings */ -class Piwik_UserSettings extends Plugin +class UserSettings extends \Piwik\Plugin { /** * Mapping between the browser family shortcode and the displayed name @@ -433,8 +435,8 @@ class Piwik_UserSettings extends Plugin */ public function archiveDay(ArchiveProcessor\Day $archiveProcessor) { - $archiving = new Piwik_UserSettings_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archiveDay(); } } @@ -444,8 +446,8 @@ class Piwik_UserSettings extends Plugin */ public function archivePeriod(ArchiveProcessor\Period $archiveProcessor) { - $archiving = new Piwik_UserSettings_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archivePeriod(); } } diff --git a/plugins/UserSettings/functions.php b/plugins/UserSettings/functions.php index 41269b773b..28215d2e44 100644 --- a/plugins/UserSettings/functions.php +++ b/plugins/UserSettings/functions.php @@ -6,17 +6,22 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UserSettings + * @package UserSettings */ + +namespace Piwik\Plugins\UserSettings; + use Piwik\Piwik; +use Piwik\Plugins\UserSettings\UserSettings; use Piwik\Tracker\Request; +use UserAgentParser; /** * @see libs/UserAgentParser/UserAgentParser.php */ require_once PIWIK_INCLUDE_PATH . '/libs/UserAgentParser/UserAgentParser.php'; -function Piwik_getPluginsLogo($oldLabel) +function getPluginsLogo($oldLabel) { if($oldLabel == Piwik_Translate('General_Others')) { return false; @@ -24,7 +29,7 @@ function Piwik_getPluginsLogo($oldLabel) return 'plugins/UserSettings/images/plugins/' . $oldLabel . '.gif'; } -function Piwik_getOSLabel($osId) +function getOSLabel($osId) { $osName = UserAgentParser::getOperatingSystemNameFromId($osId); if ($osName !== false) { @@ -36,7 +41,7 @@ function Piwik_getOSLabel($osId) return $osId; } -function Piwik_getOSShortLabel($osId) +function getOSShortLabel($osId) { $osShortName = UserAgentParser::getOperatingSystemShortNameFromId($osId); if ($osShortName !== false) { @@ -49,7 +54,7 @@ function Piwik_getOSShortLabel($osId) } -function Piwik_UserSettings_getOSFamily($osLabel) +function getOSFamily($osLabel) { $osId = UserAgentParser::getOperatingSystemIdFromName($osLabel); $osFamily = UserAgentParser::getOperatingSystemFamilyFromId($osId); @@ -63,7 +68,7 @@ function Piwik_UserSettings_getOSFamily($osLabel) return $osFamily; } -function Piwik_UserSettings_getDeviceTypeFromOS($osLabel) +function getDeviceTypeFromOS($osLabel) { $osId = UserAgentParser::getOperatingSystemIdFromName($osLabel); $osFamily = UserAgentParser::getOperatingSystemFamilyFromId($osId); @@ -88,10 +93,10 @@ function Piwik_UserSettings_getDeviceTypeFromOS($osLabel) } } -function Piwik_getBrowserTypeLabel($oldLabel) +function getBrowserTypeLabel($oldLabel) { - if (isset(Piwik_UserSettings::$browserType_display[$oldLabel])) { - return Piwik_UserSettings::$browserType_display[$oldLabel]; + if (isset(UserSettings::$browserType_display[$oldLabel])) { + return UserSettings::$browserType_display[$oldLabel]; } if ($oldLabel == 'unknown') { return Piwik_Translate('General_Unknown'); @@ -100,14 +105,14 @@ function Piwik_getBrowserTypeLabel($oldLabel) } -function Piwik_getConfigurationLabel($str) +function getConfigurationLabel($str) { if (strpos($str, ';') === false) { return $str; } $values = explode(";", $str); - $os = Piwik_getOSLabel($values[0]); + $os = getOSLabel($values[0]); $name = $values[1]; $browser = UserAgentParser::getBrowserNameFromId($name); if ($browser === false) { @@ -117,10 +122,10 @@ function Piwik_getConfigurationLabel($str) return $os . " / " . $browser . " / " . $resolution; } -function Piwik_getBrowserLabel($oldLabel) +function getBrowserLabel($oldLabel) { - $browserId = Piwik_getBrowserId($oldLabel); - $version = Piwik_getBrowserVersion($oldLabel); + $browserId = getBrowserId($oldLabel); + $version = getBrowserVersion($oldLabel); $browserName = UserAgentParser::getBrowserNameFromId($browserId); if ($browserName !== false) { return $browserName . " " . $version; @@ -131,10 +136,10 @@ function Piwik_getBrowserLabel($oldLabel) return $oldLabel; } -function Piwik_getBrowserShortLabel($oldLabel) +function getBrowserShortLabel($oldLabel) { - $browserId = Piwik_getBrowserId($oldLabel); - $version = Piwik_getBrowserVersion($oldLabel); + $browserId = getBrowserId($oldLabel); + $version = getBrowserVersion($oldLabel); $browserName = UserAgentParser::getBrowserShortNameFromId($browserId); if ($browserName !== false) { return $browserName . " " . $version; @@ -145,17 +150,17 @@ function Piwik_getBrowserShortLabel($oldLabel) return $oldLabel; } -function Piwik_getBrowserId($str) +function getBrowserId($str) { return substr($str, 0, strpos($str, ';')); } -function Piwik_getBrowserVersion($str) +function getBrowserVersion($str) { return substr($str, strpos($str, ';') + 1); } -function Piwik_getLogoImageFromId($dir, $id) +function getLogoImageFromId($dir, $id) { $path = $dir.'/'.$id.'.gif'; if (file_exists(PIWIK_INCLUDE_PATH . '/' . $path)) { @@ -165,31 +170,31 @@ function Piwik_getLogoImageFromId($dir, $id) } } -function Piwik_getBrowsersLogo($label) +function getBrowsersLogo($label) { - $id = Piwik_getBrowserId($label); + $id = getBrowserId($label); // For aggregated row 'Others' if (empty($id)) { $id = 'UNK'; } - return Piwik_getLogoImageFromId('plugins/UserSettings/images/browsers', $id); + return getLogoImageFromId('plugins/UserSettings/images/browsers', $id); } -function Piwik_getOSLogo($label) +function getOSLogo($label) { // For aggregated row 'Others' if (empty($label)) { $label = 'UNK'; } - return Piwik_getLogoImageFromId('plugins/UserSettings/images/os', $label); + return getLogoImageFromId('plugins/UserSettings/images/os', $label); } -function Piwik_getScreensLogo($label) +function getScreensLogo($label) { return 'plugins/UserSettings/images/screens/' . $label . '.gif'; } -function Piwik_UserSettings_getDeviceTypeImg($oldOSImage, $osFamilyLabel) +function getDeviceTypeImg($oldOSImage, $osFamilyLabel) { switch ($osFamilyLabel) { case 'General_Desktop': @@ -202,12 +207,12 @@ function Piwik_UserSettings_getDeviceTypeImg($oldOSImage, $osFamilyLabel) } } -function Piwik_UserSettings_keepStrlenGreater($value) +function keepStrlenGreater($value) { return strlen($value) > 5; } -function Piwik_getScreenTypeFromResolution($resolution) +function getScreenTypeFromResolution($resolution) { if ($resolution === Request::UNKNOWN_RESOLUTION) { return $resolution; @@ -229,7 +234,7 @@ function Piwik_getScreenTypeFromResolution($resolution) return $name; } -function Piwik_getBrowserFamily($browserLabel) +function getBrowserFamily($browserLabel) { $familyNameToUse = UserAgentParser::getBrowserFamilyFromId(substr($browserLabel, 0, 2)); return $familyNameToUse; @@ -238,7 +243,7 @@ function Piwik_getBrowserFamily($browserLabel) /** * Extracts the browser name from a string with the browser name and version. */ -function Piwik_UserSettings_getBrowserFromBrowserVersion($browserWithVersion) +function getBrowserFromBrowserVersion($browserWithVersion) { if (preg_match("/(.+) [0-9]+(?:\.[0-9]+)?$/", $browserWithVersion, $matches) === 0) { return $browserWithVersion; @@ -254,7 +259,7 @@ function Piwik_UserSettings_getBrowserFromBrowserVersion($browserWithVersion) * * @return string */ -function Piwik_LanguageTranslate($label) +function languageTranslate($label) { if ($label == '' || $label == 'xx') { return Piwik_Translate('General_Unknown'); diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 104961c951..1649cdaca7 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UsersManager + * @package UsersManager */ +namespace Piwik\Plugins\UsersManager; + +use Exception; use Piwik\Config; use Piwik\Piwik; use Piwik\Common; @@ -16,6 +19,7 @@ use Piwik\Date; use Piwik\Site; use Piwik\Db; use Piwik\Tracker\Cache; +use Piwik\Plugins\UsersManager\UsersManager; /** * The UsersManager API lets you Manage Users and their permissions to access specific websites. @@ -28,13 +32,13 @@ use Piwik\Tracker\Cache; * or you can list all users and websites for a given permission via "getUsersSitesFromAccess". Permissions are set and updated * via the method "setUserAccess". * See also the documentation about <a href='http://piwik.org/docs/manage-users/' target='_blank'>Managing Users</a> in Piwik. - * @package Piwik_UsersManager + * @package UsersManager */ -class Piwik_UsersManager_API +class API { const PREFERENCE_DEFAULT_REPORT = 'defaultReport'; const PREFERENCE_DEFAULT_REPORT_DATE = 'defaultReportDate'; - + static private $instance = null; /** @@ -45,15 +49,15 @@ class Piwik_UsersManager_API * \Zend_Registry::set('UsersManager_API',Piwik_MyCustomUsersManager_API::getInstance()); * * @throws Exception - * @return Piwik_UsersManager_API + * @return \Piwik\Plugins\UsersManager\API */ static public function getInstance() { try { $instance = \Zend_Registry::get('UsersManager_API'); - if (!($instance instanceof Piwik_UsersManager_API)) { + if (!($instance instanceof API)) { // Exception is caught below and corrected - throw new Exception('UsersManager_API must inherit Piwik_UsersManager_API'); + throw new Exception('UsersManager_API must inherit API'); } self::$instance = $instance; } catch (Exception $e) { @@ -85,7 +89,7 @@ class Piwik_UsersManager_API public function getUserPreference($userLogin, $preferenceName) { Piwik::checkUserIsSuperUserOrTheUser($userLogin); - + $optionValue = Piwik_GetOption($this->getPreferenceId($userLogin, $preferenceName)); if ($optionValue !== false) { return $optionValue; @@ -97,12 +101,12 @@ class Piwik_UsersManager_API { return $login . '_' . $preference; } - + private function getDefaultUserPreference($preferenceName, $login) { switch ($preferenceName) { case self::PREFERENCE_DEFAULT_REPORT: - $viewableSiteIds = Piwik_SitesManager_API::getInstance()->getSitesIdWithAtLeastViewAccess($login); + $viewableSiteIds = \Piwik\Plugins\SitesManager\API::getInstance()->getSitesIdWithAtLeastViewAccess($login); return reset($viewableSiteIds); case self::PREFERENCE_DEFAULT_REPORT_DATE: return Config::getInstance()->General['default_day']; @@ -131,7 +135,7 @@ class Piwik_UsersManager_API $db = \Zend_Registry::get('db'); $users = $db->fetchAll("SELECT * FROM " . Common::prefixTable("user") . " - $where + $where ORDER BY login ASC", $bind); // Non Super user can only access login & alias if (!Piwik::isUserIsSuperUser()) { @@ -193,7 +197,6 @@ class Piwik_UsersManager_API $return[$user['login']][] = $user['idsite']; } return $return; - } /** @@ -373,23 +376,23 @@ class Piwik_UsersManager_API $this->checkEmail($email); $password = Common::unsanitizeInputValue($password); - Piwik_UsersManager::checkPassword($password); + UsersManager::checkPassword($password); $alias = $this->getCleanAlias($alias, $userLogin); - $passwordTransformed = Piwik_UsersManager::getPasswordHash($password); + $passwordTransformed = UsersManager::getPasswordHash($password); $token_auth = $this->getTokenAuth($userLogin, $passwordTransformed); $db = \Zend_Registry::get('db'); $db->insert(Common::prefixTable("user"), array( - 'login' => $userLogin, - 'password' => $passwordTransformed, - 'alias' => $alias, - 'email' => $email, - 'token_auth' => $token_auth, - 'date_registered' => Date::now()->getDatetime() - ) + 'login' => $userLogin, + 'password' => $passwordTransformed, + 'alias' => $alias, + 'email' => $email, + 'token_auth' => $token_auth, + 'date_registered' => Date::now()->getDatetime() + ) ); // we reload the access list which doesn't yet take in consideration this new user @@ -420,8 +423,8 @@ class Piwik_UsersManager_API } else { $password = Common::unsanitizeInputValue($password); if (!$_isPasswordHashed) { - Piwik_UsersManager::checkPassword($password); - $password = Piwik_UsersManager::getPasswordHash($password); + UsersManager::checkPassword($password); + $password = UsersManager::getPasswordHash($password); } } @@ -541,7 +544,7 @@ class Piwik_UsersManager_API // in case idSites is null we grant access to all the websites on which the current connected user // has an 'admin' access if ($idSites === 'all') { - $idSites = Piwik_SitesManager_API::getInstance()->getSitesIdWithAdminAccess(); + $idSites = \Piwik\Plugins\SitesManager\API::getInstance()->getSitesIdWithAdminAccess(); } // in case the idSites is an integer we build an array else { $idSites = Site::getIdSitesFromIdSitesString($idSites); @@ -643,7 +646,6 @@ class Piwik_UsersManager_API Piwik_PostEvent('UsersManager.deleteUser', array($userLogin)); } - /** * Delete the user access for the given websites. * The array of idsite must be either null OR the values must have been checked before for their validity! diff --git a/plugins/UsersManager/Controller.php b/plugins/UsersManager/Controller.php index bedf2bb5fb..1ead3ed8eb 100644 --- a/plugins/UsersManager/Controller.php +++ b/plugins/UsersManager/Controller.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UsersManager + * @package UsersManager */ +namespace Piwik\Plugins\UsersManager; + +use Exception; use Piwik\API\ResponseBuilder; use Piwik\Controller\Admin; use Piwik\Piwik; @@ -17,12 +20,14 @@ use Piwik\Tracker\IgnoreCookie; use Piwik\View; use Piwik\Url; use Piwik\Site; +use Piwik\Plugins\SitesManager\API as SitesManagerAPI; +use Piwik\Plugins\UsersManager\API as UsersManagerAPI; /** * - * @package Piwik_UsersManager + * @package UsersManager */ -class Piwik_UsersManager_Controller extends Admin +class Controller extends Admin { static function orderByName($a, $b) { @@ -38,7 +43,7 @@ class Piwik_UsersManager_Controller extends Admin $view = new View('@UsersManager/index'); - $IdSitesAdmin = Piwik_SitesManager_API::getInstance()->getSitesIdWithAdminAccess(); + $IdSitesAdmin = SitesManagerAPI::getInstance()->getSitesIdWithAdminAccess(); $idSiteSelected = 1; if (count($IdSitesAdmin) > 0) { @@ -50,13 +55,13 @@ class Piwik_UsersManager_Controller extends Admin $usersAccessByWebsite = array(); $defaultReportSiteName = Piwik_Translate('UsersManager_ApplyToAllWebsites'); } else { - $usersAccessByWebsite = Piwik_UsersManager_API::getInstance()->getUsersAccessFromSite($idSiteSelected); + $usersAccessByWebsite = UsersManagerAPI::getInstance()->getUsersAccessFromSite($idSiteSelected); $defaultReportSiteName = Site::getNameFor($idSiteSelected); } // we dont want to display the user currently logged so that the user can't change his settings from admin to view... $currentlyLogged = Piwik::getCurrentUserLogin(); - $usersLogin = Piwik_UsersManager_API::getInstance()->getUsersLogin(); + $usersLogin = UsersManagerAPI::getInstance()->getUsersLogin(); foreach ($usersLogin as $login) { if (!isset($usersAccessByWebsite[$login])) { $usersAccessByWebsite[$login] = 'noaccess'; @@ -64,7 +69,6 @@ class Piwik_UsersManager_Controller extends Admin } unset($usersAccessByWebsite[$currentlyLogged]); - // $usersAccessByWebsite is not supposed to contain unexistant logins, but it does when upgrading from some old Piwik version foreach ($usersAccessByWebsite as $login => $access) { if (!in_array($login, $usersLogin)) { @@ -78,7 +82,7 @@ class Piwik_UsersManager_Controller extends Admin $users = array(); $usersAliasByLogin = array(); if (Piwik::isUserHasSomeAdminAccess()) { - $users = Piwik_UsersManager_API::getInstance()->getUsers(); + $users = UsersManagerAPI::getInstance()->getUsers(); foreach ($users as $user) { $usersAliasByLogin[$user['login']] = $user['alias']; } @@ -90,8 +94,8 @@ class Piwik_UsersManager_Controller extends Admin $view->usersAliasByLogin = $usersAliasByLogin; $view->usersCount = count($users) - 1; $view->usersAccessByWebsite = $usersAccessByWebsite; - $websites = Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess(); - uasort($websites, array('Piwik_UsersManager_Controller', 'orderByName')); + $websites = SitesManagerAPI::getInstance()->getSitesWithAdminAccess(); + uasort($websites, array('Piwik\Plugins\UsersManager\Controller', 'orderByName')); $view->websites = $websites; $this->setBasicVariablesView($view); echo $view->render(); @@ -118,7 +122,7 @@ class Piwik_UsersManager_Controller extends Admin */ protected function getDefaultDateForUser($user) { - return Piwik_UsersManager_API::getInstance()->getUserPreference($user, Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE); + return UsersManagerAPI::getInstance()->getUserPreference($user, UsersManagerAPI::PREFERENCE_DEFAULT_REPORT_DATE); } /** @@ -135,14 +139,13 @@ class Piwik_UsersManager_Controller extends Admin $view->userAlias = $userLogin; $view->userEmail = Piwik::getSuperUserEmail(); $this->displayWarningIfConfigFileNotWritable($view); - } else { - $user = Piwik_UsersManager_API::getInstance()->getUser($userLogin); + $user = UsersManagerAPI::getInstance()->getUser($userLogin); $view->userAlias = $user['alias']; $view->userEmail = $user['email']; } - $defaultReport = Piwik_UsersManager_API::getInstance()->getUserPreference($userLogin, Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT); + $defaultReport = UsersManagerAPI::getInstance()->getUserPreference($userLogin, UsersManagerAPI::PREFERENCE_DEFAULT_REPORT); if ($defaultReport === false) { $defaultReport = $this->getDefaultWebsiteId(); } @@ -196,11 +199,11 @@ class Piwik_UsersManager_Controller extends Admin $userLogin = 'anonymous'; // Which websites are available to the anonymous users? - $anonymousSitesAccess = Piwik_UsersManager_API::getInstance()->getSitesAccessFromUser($userLogin); + $anonymousSitesAccess = UsersManagerAPI::getInstance()->getSitesAccessFromUser($userLogin); $anonymousSites = array(); foreach ($anonymousSitesAccess as $info) { $idSite = $info['site']; - $site = Piwik_SitesManager_API::getInstance()->getSiteFromId($idSite); + $site = SitesManagerAPI::getInstance()->getSiteFromId($idSite); // Work around manual website deletion if (!empty($site)) { $anonymousSites[$idSite] = $site; @@ -209,7 +212,7 @@ class Piwik_UsersManager_Controller extends Admin $view->anonymousSites = $anonymousSites; // Which report is displayed by default to the anonymous user? - $anonymousDefaultReport = Piwik_UsersManager_API::getInstance()->getUserPreference($userLogin, Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT); + $anonymousDefaultReport = UsersManagerAPI::getInstance()->getUserPreference($userLogin, UsersManagerAPI::PREFERENCE_DEFAULT_REPORT); if ($anonymousDefaultReport === false) { if (empty($anonymousSites)) { $anonymousDefaultReport = Piwik::getLoginPluginName(); @@ -239,11 +242,11 @@ class Piwik_UsersManager_Controller extends Admin $anonymousDefaultReport = Common::getRequestVar('anonymousDefaultReport'); $anonymousDefaultDate = Common::getRequestVar('anonymousDefaultDate'); $userLogin = 'anonymous'; - Piwik_UsersManager_API::getInstance()->setUserPreference($userLogin, - Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT, + UsersManagerAPI::getInstance()->setUserPreference($userLogin, + UsersManagerAPI::PREFERENCE_DEFAULT_REPORT, $anonymousDefaultReport); - Piwik_UsersManager_API::getInstance()->setUserPreference($userLogin, - Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE, + UsersManagerAPI::getInstance()->setUserPreference($userLogin, + UsersManagerAPI::PREFERENCE_DEFAULT_REPORT_DATE, $anonymousDefaultDate); $toReturn = $response->getResponse(); } catch (Exception $e) { @@ -306,7 +309,7 @@ class Piwik_UsersManager_Controller extends Admin Config::getInstance()->forceSave(); } } else { - Piwik_UsersManager_API::getInstance()->updateUser($userLogin, $newPassword, $email, $alias); + UsersManagerAPI::getInstance()->updateUser($userLogin, $newPassword, $email, $alias); if ($newPassword !== false) { $newPassword = Common::unsanitizeInputValue($newPassword); } @@ -322,11 +325,11 @@ class Piwik_UsersManager_Controller extends Admin Piwik_PostEvent('Login.initSession', array($info)); } - Piwik_UsersManager_API::getInstance()->setUserPreference($userLogin, - Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT, + UsersManagerAPI::getInstance()->setUserPreference($userLogin, + UsersManagerAPI::PREFERENCE_DEFAULT_REPORT, $defaultReport); - Piwik_UsersManager_API::getInstance()->setUserPreference($userLogin, - Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE, + UsersManagerAPI::getInstance()->setUserPreference($userLogin, + UsersManagerAPI::PREFERENCE_DEFAULT_REPORT_DATE, $defaultDate); $toReturn = $response->getResponse(); } catch (Exception $e) { diff --git a/plugins/UsersManager/UsersManager.php b/plugins/UsersManager/UsersManager.php index a0828d7904..905f23cc2f 100644 --- a/plugins/UsersManager/UsersManager.php +++ b/plugins/UsersManager/UsersManager.php @@ -6,18 +6,21 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_UsersManager + * @package UsersManager */ +namespace Piwik\Plugins\UsersManager; + +use Exception; use Piwik\Piwik; use Piwik\Option; -use Piwik\Plugin; +use Piwik\Plugins\UsersManager\API; /** * Manage Piwik users * - * @package Piwik_UsersManager + * @package UsersManager */ -class Piwik_UsersManager extends Plugin +class UsersManager extends \Piwik\Plugin { const PASSWORD_MIN_LENGTH = 6; const PASSWORD_MAX_LENGTH = 26; @@ -36,7 +39,6 @@ class Piwik_UsersManager extends Plugin ); } - /** * Hooks when a website tracker cache is flushed (website/user updated, cache deleted, or empty cache) * Will record in the tracker config file the list of Admin token_auth for this website. This @@ -49,7 +51,7 @@ class Piwik_UsersManager extends Plugin public function recordAdminUsersInCache(&$array, $idSite) { // add the 'hosts' entry in the website array - $users = Piwik_UsersManager_API::getInstance()->getUsersWithSiteAccess($idSite, 'admin'); + $users = API::getInstance()->getUsersWithSiteAccess($idSite, 'admin'); $tokens = array(); foreach ($users as $user) { @@ -62,7 +64,7 @@ class Piwik_UsersManager extends Plugin */ public function deleteSite(&$idSite) { - Option::getInstance()->deleteLike('%\_' . Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT, $idSite); + Option::getInstance()->deleteLike('%\_' . API::PREFERENCE_DEFAULT_REPORT, $idSite); } /** diff --git a/plugins/VisitFrequency/API.php b/plugins/VisitFrequency/API.php index 141a1acee3..9d10395ba5 100644 --- a/plugins/VisitFrequency/API.php +++ b/plugins/VisitFrequency/API.php @@ -6,22 +6,26 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitFrequency + * @package VisitFrequency */ +namespace Piwik\Plugins\VisitFrequency; + use Piwik\API\Request; use Piwik\Piwik; use Piwik\SegmentExpression; +use Piwik\Plugins\VisitsSummary\API as VisitsSummaryAPI; /** * VisitFrequency API lets you access a list of metrics related to Returning Visitors. - * @package Piwik_VisitFrequency + * @package VisitFrequency */ -class Piwik_VisitFrequency_API +class API { const RETURNING_VISITOR_SEGMENT = "visitorType==returning"; const COLUMN_SUFFIX = "_returning"; static private $instance = null; + static public function getInstance() { if (self::$instance == null) { @@ -79,7 +83,7 @@ class Piwik_VisitFrequency_API protected function prefixColumns($table, $period) { $rename = array(); - foreach (Piwik_VisitsSummary_API::getInstance()->getColumns($period) as $oldColumn) { + foreach (VisitsSummaryAPI::getInstance()->getColumns($period) as $oldColumn) { $rename[$oldColumn] = $oldColumn . self::COLUMN_SUFFIX; } $table->filter('ReplaceColumnNames', array($rename)); diff --git a/plugins/VisitFrequency/Controller.php b/plugins/VisitFrequency/Controller.php index 77baa6b539..b83a117840 100644 --- a/plugins/VisitFrequency/Controller.php +++ b/plugins/VisitFrequency/Controller.php @@ -6,19 +6,20 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitFrequency + * @package VisitFrequency */ +namespace Piwik\Plugins\VisitFrequency; + use Piwik\API\Request; use Piwik\Piwik; use Piwik\Common; -use Piwik\Controller; use Piwik\View; /** * - * @package Piwik_VisitFrequency + * @package VisitFrequency */ -class Piwik_VisitFrequency_Controller extends Controller +class Controller extends \Piwik\Controller { function index() { @@ -96,7 +97,6 @@ class Piwik_VisitFrequency_Controller extends Controller $view->avgVisitDurationReturning = $dataRow->getColumn('avg_time_on_site_returning'); $nbBouncedReturningVisits = $dataRow->getColumn('bounce_count_returning'); $view->bounceRateReturning = Piwik::getPercentageSafe($nbBouncedReturningVisits, $nbVisitsReturning); - } protected function getSummary() diff --git a/plugins/VisitFrequency/VisitFrequency.php b/plugins/VisitFrequency/VisitFrequency.php index 07b1735159..90a5929760 100644 --- a/plugins/VisitFrequency/VisitFrequency.php +++ b/plugins/VisitFrequency/VisitFrequency.php @@ -6,16 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitFrequency + * @package VisitFrequency */ -use Piwik\Plugin; +namespace Piwik\Plugins\VisitFrequency; + use Piwik\WidgetsList; /** * - * @package Piwik_VisitFrequency + * @package VisitFrequency */ -class Piwik_VisitFrequency extends Plugin +class VisitFrequency extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered @@ -23,9 +24,9 @@ class Piwik_VisitFrequency extends Plugin public function getListHooksRegistered() { $hooks = array( - 'WidgetsList.add' => 'addWidgets', - 'Menu.add' => 'addMenu', - 'API.getReportMetadata' => 'getReportMetadata', + 'WidgetsList.add' => 'addWidgets', + 'Menu.add' => 'addMenu', + 'API.getReportMetadata' => 'getReportMetadata', ); return $hooks; } diff --git a/plugins/VisitTime/API.php b/plugins/VisitTime/API.php index 76e9b5652b..25d1ae8a81 100644 --- a/plugins/VisitTime/API.php +++ b/plugins/VisitTime/API.php @@ -6,8 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitTime + * @package VisitTime */ +namespace Piwik\Plugins\VisitTime; + +use Exception; use Piwik\Archive; use Piwik\Metrics; use Piwik\Period; @@ -15,13 +18,16 @@ use Piwik\Piwik; use Piwik\Date; use Piwik\DataTable; use Piwik\Site; +use Piwik\Plugins\VisitTime\Archiver; + +require_once PIWIK_INCLUDE_PATH . '/plugins/VisitTime/functions.php'; /** * VisitTime API lets you access reports by Hour (Server time), and by Hour Local Time of your visitors. * - * @package Piwik_VisitTime + * @package VisitTime */ -class Piwik_VisitTime_API +class API { static private $instance = null; @@ -39,19 +45,19 @@ class Piwik_VisitTime_API $archive = Archive::build($idSite, $period, $date, $segment); $dataTable = $archive->getDataTable($name); $dataTable->filter('Sort', array('label', 'asc', true)); - $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_getTimeLabel')); + $dataTable->queueFilter('ColumnCallbackReplace', array('label', __NAMESPACE__ .'\getTimeLabel')); $dataTable->queueFilter('ReplaceColumnNames'); return $dataTable; } public function getVisitInformationPerLocalTime($idSite, $period, $date, $segment = false) { - return $this->getDataTable(Piwik_VisitTime_Archiver::LOCAL_TIME_RECORD_NAME, $idSite, $period, $date, $segment); + return $this->getDataTable(Archiver::LOCAL_TIME_RECORD_NAME, $idSite, $period, $date, $segment); } public function getVisitInformationPerServerTime($idSite, $period, $date, $segment = false, $hideFutureHoursWhenToday = false) { - $table = $this->getDataTable(Piwik_VisitTime_Archiver::SERVER_TIME_RECORD_NAME, $idSite, $period, $date, $segment); + $table = $this->getDataTable(Archiver::SERVER_TIME_RECORD_NAME, $idSite, $period, $date, $segment); if ($hideFutureHoursWhenToday) { $table = $this->removeHoursInFuture($table, $idSite, $period, $date); } @@ -76,7 +82,7 @@ class Piwik_VisitTime_API // metrics to query $metrics = Metrics::getVisitsMetricNames(); unset($metrics[Metrics::INDEX_MAX_ACTIONS]); - + // disabled for multiple dates if (Period::isMultiplePeriod($date, $period)) { throw new Exception("VisitTime.getByDayOfWeek does not support multiple dates."); @@ -100,7 +106,7 @@ class Piwik_VisitTime_API } // group by the day of the week (see below for dayOfWeekFromDate function) - $dataTable->filter('GroupBy', array('label', 'Piwik_VisitTime_dayOfWeekFromDate')); + $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\dayOfWeekFromDate')); // create new datatable w/ empty rows, then add calculated datatable $rows = array(); @@ -115,7 +121,7 @@ class Piwik_VisitTime_API $result->filter('ColumnCallbackAddMetadata', array('label', 'day_of_week')); // translate labels - $result->filter('ColumnCallbackReplace', array('label', 'Piwik_VisitTime_translateDayOfWeek')); + $result->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\translateDayOfWeek')); // set datatable metadata for period start & finish $result->setMetadata('date_start', $oPeriod->getDateStart()); @@ -161,31 +167,3 @@ class Piwik_VisitTime_API return $table; } } - -function Piwik_getTimeLabel($label) -{ - return sprintf(Piwik_Translate('VisitTime_NHour'), $label); -} - -/** - * Returns the day of the week for a date string, without creating a new - * Date instance. - * - * @param string $dateStr - * @return int The day of the week (1-7) - */ -function Piwik_VisitTime_dayOfWeekFromDate($dateStr) -{ - return date('N', strtotime($dateStr)); -} - -/** - * Returns translated long name of a day of the week. - * - * @param int $dayOfWeek 1-7, for Sunday-Saturday - * @return string - */ -function Piwik_VisitTime_translateDayOfWeek($dayOfWeek) -{ - return Piwik_Translate('General_LongDay_' . $dayOfWeek); -} diff --git a/plugins/VisitTime/Archiver.php b/plugins/VisitTime/Archiver.php index 77b7659d9b..c51c082967 100644 --- a/plugins/VisitTime/Archiver.php +++ b/plugins/VisitTime/Archiver.php @@ -6,14 +6,16 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitTime + * @package VisitTime */ +namespace Piwik\Plugins\VisitTime; + use Piwik\Date; use Piwik\DataArray; use Piwik\PluginsArchiver; -class Piwik_VisitTime_Archiver extends PluginsArchiver +class Archiver extends PluginsArchiver { const SERVER_TIME_RECORD_NAME = 'VisitTime_serverTime'; const LOCAL_TIME_RECORD_NAME = 'VisitTime_localTime'; @@ -26,8 +28,8 @@ class Piwik_VisitTime_Archiver extends PluginsArchiver protected function aggregateByServerTime() { - $array = $this->getProcessor()->getMetricsForDimension( array("label" => "HOUR(log_visit.visit_last_action_time)" )) ; - $query = $this->getLogAggregator()->queryConversionsByDimension( array("label" => "HOUR(log_conversion.server_time)") ); + $array = $this->getProcessor()->getMetricsForDimension(array("label" => "HOUR(log_visit.visit_last_action_time)")); + $query = $this->getLogAggregator()->queryConversionsByDimension(array("label" => "HOUR(log_conversion.server_time)")); if ($query === false) { return; } @@ -62,13 +64,12 @@ class Piwik_VisitTime_Archiver extends PluginsArchiver return new DataArray($converted); } - - private function ensureAllHoursAreSet( DataArray &$array) + private function ensureAllHoursAreSet(DataArray &$array) { $data = $array->getDataArray(); for ($i = 0; $i <= 23; $i++) { if (empty($data[$i])) { - $array->sumMetricsVisits( $i, DataArray::makeEmptyRow()); + $array->sumMetricsVisits($i, DataArray::makeEmptyRow()); } } } diff --git a/plugins/VisitTime/Controller.php b/plugins/VisitTime/Controller.php index 4c4fa760db..dcc89ac9fb 100644 --- a/plugins/VisitTime/Controller.php +++ b/plugins/VisitTime/Controller.php @@ -6,17 +6,18 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitTime + * @package VisitTime */ -use Piwik\Controller; +namespace Piwik\Plugins\VisitTime; + use Piwik\ViewDataTable; use Piwik\View; /** * - * @package Piwik_VisitTime + * @package VisitTime */ -class Piwik_VisitTime_Controller extends Controller +class Controller extends \Piwik\Controller { public function index() { diff --git a/plugins/VisitTime/VisitTime.php b/plugins/VisitTime/VisitTime.php index e9873ae05c..8e047803da 100644 --- a/plugins/VisitTime/VisitTime.php +++ b/plugins/VisitTime/VisitTime.php @@ -6,20 +6,23 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitTime + * @package VisitTime */ +namespace Piwik\Plugins\VisitTime; + +use Exception; use Piwik\ArchiveProcessor; use Piwik\Common; use Piwik\Period; -use Piwik\Plugin; +use Piwik\Plugins\VisitTime\Archiver; use Piwik\Site; use Piwik\WidgetsList; /** * - * @package Piwik_VisitTime + * @package VisitTime */ -class Piwik_VisitTime extends Plugin +class VisitTime extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered @@ -116,7 +119,7 @@ class Piwik_VisitTime extends Plugin 'acceptedValues' => $acceptedValues ); } - + public function getReportDisplayProperties(&$properties) { $commonProperties = array( @@ -128,7 +131,7 @@ class Piwik_VisitTime extends Plugin 'show_pagination_control' => false, 'default_view_type' => 'graphVerticalBar' ); - + $properties['VisitTime.getVisitInformationPerServerTime'] = array_merge($commonProperties, array( 'filter_limit' => 24, 'show_goals' => true, @@ -176,21 +179,20 @@ class Piwik_VisitTime extends Plugin public function archivePeriod(ArchiveProcessor\Period $archiveProcessor) { - $archiving = new Piwik_VisitTime_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archivePeriod(); } } - public function archiveDay(ArchiveProcessor\Day $archiveProcessor) { - $archiving = new Piwik_VisitTime_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archiveDay(); } } - + private static function getDateRangeForFooterMessage() { // get query params diff --git a/plugins/VisitTime/functions.php b/plugins/VisitTime/functions.php new file mode 100644 index 0000000000..f4ccb20d46 --- /dev/null +++ b/plugins/VisitTime/functions.php @@ -0,0 +1,40 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik_Plugins + * @package VisitTime + */ + +namespace Piwik\Plugins\VisitTime; + +function getTimeLabel($label) +{ + return sprintf(Piwik_Translate('VisitTime_NHour'), $label); +} + +/** + * Returns the day of the week for a date string, without creating a new + * Date instance. + * + * @param string $dateStr + * @return int The day of the week (1-7) + */ +function dayOfWeekFromDate($dateStr) +{ + return date('N', strtotime($dateStr)); +} + +/** + * Returns translated long name of a day of the week. + * + * @param int $dayOfWeek 1-7, for Sunday-Saturday + * @return string + */ +function translateDayOfWeek($dayOfWeek) +{ + return Piwik_Translate('General_LongDay_' . $dayOfWeek); +} diff --git a/plugins/VisitorGenerator/Controller.php b/plugins/VisitorGenerator/Controller.php index f0275b3348..bf344be4f3 100644 --- a/plugins/VisitorGenerator/Controller.php +++ b/plugins/VisitorGenerator/Controller.php @@ -6,8 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitorGenerator + * @package VisitorGenerator */ +namespace Piwik\Plugins\VisitorGenerator; + use Piwik\ArchiveProcessor\Rules; use Piwik\Controller\Admin; use Piwik\Piwik; @@ -19,23 +21,25 @@ use Piwik\View; use Piwik\Url; use Piwik\Timer; use Piwik\Site; +use Piwik\Plugins\CoreAdminHome\API as CoreAdminHomeAPI; +use Piwik\Plugins\SitesManager\API as SitesManagerAPI; /** * - * @package Piwik_VisitorGenerator + * @package VisitorGenerator */ -class Piwik_VisitorGenerator_Controller extends Admin +class Controller extends Admin { public function index() { Piwik::checkUserIsSuperUser(); - $sitesList = Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess(); + $sitesList = SitesManagerAPI::getInstance()->getSitesWithAdminAccess(); $view = new View('@VisitorGenerator/index'); $this->setBasicVariablesView($view); $view->assign('sitesList', $sitesList); - $view->nonce = Nonce::getNonce('Piwik_VisitorGenerator.generate'); + $view->nonce = Nonce::getNonce('VisitorGenerator.generate'); $view->countActionsPerRun = count($this->getAccessLog()); $view->accessLogPath = $this->getAccessLogPath(); echo $view->render(); @@ -57,11 +61,11 @@ class Piwik_VisitorGenerator_Controller extends Admin Piwik::checkUserIsSuperUser(); $nonce = Common::getRequestVar('form_nonce', '', 'string', $_POST); if (Common::getRequestVar('choice', 'no') != 'yes' || - !Nonce::verifyNonce('Piwik_VisitorGenerator.generate', $nonce) + !Nonce::verifyNonce('VisitorGenerator.generate', $nonce) ) { Piwik::redirectToModule('VisitorGenerator', 'index'); } - Nonce::discardNonce('Piwik_VisitorGenerator.generate'); + Nonce::discardNonce('VisitorGenerator.generate'); $daysToCompute = Common::getRequestVar('daysToCompute', 1, 'int'); @@ -83,7 +87,7 @@ class Piwik_VisitorGenerator_Controller extends Admin $nbActionsTotal += $nbActionsTotalThisDay; } - $api = Piwik_CoreAdminHome_API::getInstance(); + $api = CoreAdminHomeAPI::getInstance(); $api->invalidateArchivedReports($idSite, implode($dates, ",")); $browserArchiving = Rules::isBrowserTriggerEnabled(); diff --git a/plugins/VisitorGenerator/VisitorGenerator.php b/plugins/VisitorGenerator/VisitorGenerator.php index 9ad4fa3d66..4e3c13e677 100644 --- a/plugins/VisitorGenerator/VisitorGenerator.php +++ b/plugins/VisitorGenerator/VisitorGenerator.php @@ -6,16 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitorGenerator + * @package VisitorGenerator */ +namespace Piwik\Plugins\VisitorGenerator; + use Piwik\Piwik; -use Piwik\Plugin; /** * - * @package Piwik_VisitorGenerator + * @package VisitorGenerator */ -class Piwik_VisitorGenerator extends Plugin +class VisitorGenerator extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/VisitorInterest/API.php b/plugins/VisitorInterest/API.php index 8f34623fec..7a6f925254 100644 --- a/plugins/VisitorInterest/API.php +++ b/plugins/VisitorInterest/API.php @@ -6,20 +6,23 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitorInterest + * @package VisitorInterest */ +namespace Piwik\Plugins\VisitorInterest; + use Piwik\Archive; use Piwik\Metrics; use Piwik\Piwik; use Piwik\DataTable; +use Piwik\Plugins\VisitorInterest\Archiver; /** * VisitorInterest API lets you access two Visitor Engagement reports: number of visits per number of pages, * and number of visits per visit duration. * - * @package Piwik_VisitorInterest + * @package VisitorInterest */ -class Piwik_VisitorInterest_API +class API { static private $instance = null; @@ -42,7 +45,7 @@ class Piwik_VisitorInterest_API public function getNumberOfVisitsPerVisitDuration($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable(Piwik_VisitorInterest_Archiver::TIME_SPENT_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Archiver::TIME_SPENT_RECORD_NAME, $idSite, $period, $date, $segment); $dataTable->queueFilter('Sort', array('label', 'asc', true)); $dataTable->queueFilter('BeautifyTimeRangeLabels', array( Piwik_Translate('VisitorInterest_BetweenXYSeconds'), @@ -53,7 +56,7 @@ class Piwik_VisitorInterest_API public function getNumberOfVisitsPerPage($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable(Piwik_VisitorInterest_Archiver::PAGES_VIEWED_RECORD_NAME, $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Archiver::PAGES_VIEWED_RECORD_NAME, $idSite, $period, $date, $segment); $dataTable->queueFilter('Sort', array('label', 'asc', true)); $dataTable->queueFilter('BeautifyRangeLabels', array( Piwik_Translate('VisitorInterest_OnePage'), @@ -74,7 +77,7 @@ class Piwik_VisitorInterest_API public function getNumberOfVisitsByDaysSinceLast($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable( - Piwik_VisitorInterest_Archiver::DAYS_SINCE_LAST_RECORD_NAME, $idSite, $period, $date, $segment, Metrics::INDEX_NB_VISITS); + Archiver::DAYS_SINCE_LAST_RECORD_NAME, $idSite, $period, $date, $segment, Metrics::INDEX_NB_VISITS); $dataTable->queueFilter('BeautifyRangeLabels', array(Piwik_Translate('General_OneDay'), Piwik_Translate('General_NDays'))); return $dataTable; } @@ -92,7 +95,7 @@ class Piwik_VisitorInterest_API public function getNumberOfVisitsByVisitCount($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable( - Piwik_VisitorInterest_Archiver::VISITS_COUNT_RECORD_NAME, $idSite, $period, $date, $segment, Metrics::INDEX_NB_VISITS); + Archiver::VISITS_COUNT_RECORD_NAME, $idSite, $period, $date, $segment, Metrics::INDEX_NB_VISITS); $dataTable->queueFilter('BeautifyRangeLabels', array( Piwik_Translate('General_OneVisit'), Piwik_Translate('General_NVisits'))); diff --git a/plugins/VisitorInterest/Archiver.php b/plugins/VisitorInterest/Archiver.php index 18449cbf4c..d6aa1a29ba 100644 --- a/plugins/VisitorInterest/Archiver.php +++ b/plugins/VisitorInterest/Archiver.php @@ -6,15 +6,17 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitorInterest + * @package VisitorInterest */ +namespace Piwik\Plugins\VisitorInterest; + use Piwik\DataAccess\LogAggregator; use Piwik\Metrics; use Piwik\DataTable; use Piwik\PluginsArchiver; -class Piwik_VisitorInterest_Archiver extends PluginsArchiver +class Archiver extends PluginsArchiver { // third element is unit (s for seconds, default is munutes) const TIME_SPENT_RECORD_NAME = 'VisitorInterest_timeGap'; @@ -90,9 +92,9 @@ class Piwik_VisitorInterest_Archiver extends PluginsArchiver // these prefixes are prepended to the 'SELECT as' parts of each SELECT expression. detecting // these prefixes allows us to get all the data in one query. $prefixes = array( - self::TIME_SPENT_RECORD_NAME => 'tg', - self::PAGES_VIEWED_RECORD_NAME => 'pg', - self::VISITS_COUNT_RECORD_NAME => 'vbvn', + self::TIME_SPENT_RECORD_NAME => 'tg', + self::PAGES_VIEWED_RECORD_NAME => 'pg', + self::VISITS_COUNT_RECORD_NAME => 'vbvn', self::DAYS_SINCE_LAST_RECORD_NAME => 'dslv', ); @@ -105,13 +107,13 @@ class Piwik_VisitorInterest_Archiver extends PluginsArchiver ), ); $selects = array(); - foreach($aggregatesMetadata as $aggregateMetadata) { + foreach ($aggregatesMetadata as $aggregateMetadata) { $selectsFromRangedColumn = LogAggregator::getSelectsFromRangedColumn($aggregateMetadata); - $selects = array_merge( $selects, $selectsFromRangedColumn); + $selects = array_merge($selects, $selectsFromRangedColumn); } $query = $this->getLogAggregator()->queryVisitsByDimension(array(), $where = false, $selects, array()); $row = $query->fetch(); - foreach($prefixes as $recordName => $selectAsPrefix) { + foreach ($prefixes as $recordName => $selectAsPrefix) { $cleanRow = LogAggregator::makeArrayOneColumn($row, Metrics::INDEX_NB_VISITS, $selectAsPrefix); $dataTable = DataTable::makeFromIndexedArray($cleanRow); $this->getProcessor()->insertBlobRecord($recordName, $dataTable->getSerialized()); diff --git a/plugins/VisitorInterest/Controller.php b/plugins/VisitorInterest/Controller.php index d7a505d6b4..5475d6cba8 100644 --- a/plugins/VisitorInterest/Controller.php +++ b/plugins/VisitorInterest/Controller.php @@ -6,17 +6,18 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitorInterest + * @package VisitorInterest */ +namespace Piwik\Plugins\VisitorInterest; + use Piwik\Metrics; -use Piwik\Controller; use Piwik\ViewDataTable; use Piwik\View; /** - * @package Piwik_VisitorInterest + * @package VisitorInterest */ -class Piwik_VisitorInterest_Controller extends Controller +class Controller extends \Piwik\Controller { public function index() { diff --git a/plugins/VisitorInterest/VisitorInterest.php b/plugins/VisitorInterest/VisitorInterest.php index 569d482480..0692649e33 100644 --- a/plugins/VisitorInterest/VisitorInterest.php +++ b/plugins/VisitorInterest/VisitorInterest.php @@ -6,19 +6,21 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitorInterest + * @package VisitorInterest */ +namespace Piwik\Plugins\VisitorInterest; + use Piwik\ArchiveProcessor; use Piwik\FrontController; -use Piwik\Plugin; use Piwik\Metrics; +use Piwik\Plugins\VisitorInterest\Archiver; use Piwik\WidgetsList; /** * - * @package Piwik_VisitorInterest + * @package VisitorInterest */ -class Piwik_VisitorInterest extends Plugin +class VisitorInterest extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered @@ -26,11 +28,11 @@ class Piwik_VisitorInterest extends Plugin public function getListHooksRegistered() { $hooks = array( - 'ArchiveProcessing_Day.compute' => 'archiveDay', - 'ArchiveProcessing_Period.compute' => 'archivePeriod', - 'WidgetsList.add' => 'addWidgets', - 'Menu.add' => 'addMenu', - 'API.getReportMetadata' => 'getReportMetadata', + 'ArchiveProcessing_Day.compute' => 'archiveDay', + 'ArchiveProcessing_Period.compute' => 'archivePeriod', + 'WidgetsList.add' => 'addWidgets', + 'Menu.add' => 'addMenu', + 'API.getReportMetadata' => 'getReportMetadata', 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); return $hooks; @@ -113,22 +115,22 @@ class Piwik_VisitorInterest extends Plugin function postLoad() { - Piwik_AddAction('template_headerVisitsFrequency', array('Piwik_VisitorInterest', 'headerVisitsFrequency')); - Piwik_AddAction('template_footerVisitsFrequency', array('Piwik_VisitorInterest', 'footerVisitsFrequency')); + Piwik_AddAction('template_headerVisitsFrequency', array('Piwik\Plugins\VisitorInterest\VisitorInterest', 'headerVisitsFrequency')); + Piwik_AddAction('template_footerVisitsFrequency', array('Piwik\Plugins\VisitorInterest\VisitorInterest', 'footerVisitsFrequency')); } public function archivePeriod(ArchiveProcessor\Period $archiveProcessor) { - $archiving = new Piwik_VisitorInterest_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archivePeriod(); } } public function archiveDay(ArchiveProcessor\Day $archiveProcessor) { - $archiving = new Piwik_VisitorInterest_Archiver($archiveProcessor); - if($archiving->shouldArchive()) { + $archiving = new Archiver($archiveProcessor); + if ($archiving->shouldArchive()) { $archiving->archiveDay(); } } @@ -204,36 +206,36 @@ class Piwik_VisitorInterest extends Plugin private function getDisplayPropertiesForGetNumberOfVisitsByVisitCount() { return array( - 'columns_to_display' => array('label', 'nb_visits', 'nb_visits_percentage'), - 'filter_sort_column' => 'label', - 'filter_sort_order' => 'asc', - 'translations' => array('label' => Piwik_Translate('VisitorInterest_VisitNum'), - 'nb_visits_percentage' => Metrics::getPercentVisitColumn()), + 'columns_to_display' => array('label', 'nb_visits', 'nb_visits_percentage'), + 'filter_sort_column' => 'label', + 'filter_sort_order' => 'asc', + 'translations' => array('label' => Piwik_Translate('VisitorInterest_VisitNum'), + 'nb_visits_percentage' => Metrics::getPercentVisitColumn()), 'show_exclude_low_population' => false, - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'filter_limit' => 15, - 'show_search' => false, - 'enable_sort' => false, - 'show_table_all_columns' => false, - 'show_all_views_icons' => false, + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'filter_limit' => 15, + 'show_search' => false, + 'enable_sort' => false, + 'show_table_all_columns' => false, + 'show_all_views_icons' => false, ); } private function getDisplayPropertiesForGetNumberOfVisitsByDaysSinceLast() { return array( - 'filter_sort_column' => 'label', - 'filter_sort_order' => 'asc', - 'translations' => array('label' => Piwik_Translate('General_DaysSinceLastVisit')), + 'filter_sort_column' => 'label', + 'filter_sort_order' => 'asc', + 'translations' => array('label' => Piwik_Translate('General_DaysSinceLastVisit')), 'show_exclude_low_population' => false, - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_all_views_icons' => false, - 'filter_limit' => 15, - 'show_search' => false, - 'enable_sort' => false, - 'show_table_all_columns' => false + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'show_all_views_icons' => false, + 'filter_limit' => 15, + 'show_search' => false, + 'enable_sort' => false, + 'show_table_all_columns' => false ); } } diff --git a/plugins/VisitsSummary/API.php b/plugins/VisitsSummary/API.php index 71b1775e78..831828b775 100644 --- a/plugins/VisitsSummary/API.php +++ b/plugins/VisitsSummary/API.php @@ -6,8 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitsSummary + * @package VisitsSummary */ +namespace Piwik\Plugins\VisitsSummary; + use Piwik\Archive; use Piwik\Piwik; @@ -15,14 +17,14 @@ use Piwik\Piwik; * VisitsSummary API lets you access the core web analytics metrics (visits, unique visitors, * count of actions (page views & downloads & clicks on outlinks), time on site, bounces and converted visits. * - * @package Piwik_VisitsSummary + * @package VisitsSummary */ -class Piwik_VisitsSummary_API +class API { static private $instance = null; /** - * @return Piwik_VisitsSummary_API + * @return \Piwik\Plugins\VisitsSummary\API */ static public function getInstance() { diff --git a/plugins/VisitsSummary/Controller.php b/plugins/VisitsSummary/Controller.php index 4bc553a94d..2594a9689c 100644 --- a/plugins/VisitsSummary/Controller.php +++ b/plugins/VisitsSummary/Controller.php @@ -6,23 +6,25 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitsSummary + * @package VisitsSummary */ +namespace Piwik\Plugins\VisitsSummary; + use Piwik\API\Request; use Piwik\DataTable\Row; use Piwik\Piwik; use Piwik\Common; use Piwik\DataTable; -use Piwik\Controller; +use Piwik\Plugins\Actions\API; use Piwik\ViewDataTable; use Piwik\View; use Piwik\Site; /** * - * @package Piwik_VisitsSummary + * @package VisitsSummary */ -class Piwik_VisitsSummary_Controller extends Controller +class Controller extends \Piwik\Controller { public function index() { @@ -126,7 +128,7 @@ class Piwik_VisitsSummary_Controller extends Controller $view->urlSparklineMaxActions = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('max_actions'))); $view->urlSparklineActionsPerVisit = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_actions_per_visit'))); $view->urlSparklineBounceRate = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('bounce_rate'))); - $view->urlSparklineAvgGenerationTime = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('avg_time_generation'))); + $view->urlSparklineAvgGenerationTime = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('avg_time_generation'))); $idSite = Common::getRequestVar('idSite'); $displaySiteSearch = Site::isSiteSearchEnabledFor($idSite); @@ -138,7 +140,7 @@ class Piwik_VisitsSummary_Controller extends Controller $dataTableVisit = self::getVisitsSummary(); $dataRow = $dataTableVisit->getRowsCount() == 0 ? new Row() : $dataTableVisit->getFirstRow(); - $dataTableActions = Piwik_Actions_API::getInstance()->get($idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), + $dataTableActions = API::getInstance()->get($idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), \Piwik\API\Request::getRawSegmentFromRequest()); $dataActionsRow = $dataTableActions->getRowsCount() == 0 ? new Row() : $dataTableActions->getFirstRow(); @@ -157,7 +159,7 @@ class Piwik_VisitsSummary_Controller extends Controller $view->bounceRate = Piwik::getPercentageSafe($nbBouncedVisits, $nbVisits); $view->maxActions = (int)$dataRow->getColumn('max_actions'); $view->nbActionsPerVisit = $dataRow->getColumn('nb_actions_per_visit'); - $view->averageGenerationTime = $dataActionsRow->getColumn('avg_time_generation'); + $view->averageGenerationTime = $dataActionsRow->getColumn('avg_time_generation'); if ($displaySiteSearch) { $view->nbSearches = (int)$dataActionsRow->getColumn('nb_searches'); diff --git a/plugins/VisitsSummary/VisitsSummary.php b/plugins/VisitsSummary/VisitsSummary.php index 91e4a65661..3ef1a89f0d 100644 --- a/plugins/VisitsSummary/VisitsSummary.php +++ b/plugins/VisitsSummary/VisitsSummary.php @@ -6,9 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_VisitsSummary + * @package VisitsSummary */ -use Piwik\Plugin; +namespace Piwik\Plugins\VisitsSummary; + use Piwik\WidgetsList; /** @@ -17,9 +18,9 @@ use Piwik\WidgetsList; * Day class directly. * These metrics can be used by other Plugins so they need to be processed up front. * - * @package Piwik_VisitsSummary + * @package VisitsSummary */ -class Piwik_VisitsSummary extends Plugin +class VisitsSummary extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/Widgetize/Controller.php b/plugins/Widgetize/Controller.php index c49fa226d3..1dea78feb4 100644 --- a/plugins/Widgetize/Controller.php +++ b/plugins/Widgetize/Controller.php @@ -6,20 +6,21 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Widgetize + * @package Widgetize */ +namespace Piwik\Plugins\Widgetize; + use Piwik\API\Request; use Piwik\Common; -use Piwik\Controller; use Piwik\FrontController; use Piwik\View; use Piwik\WidgetsList; /** * - * @package Piwik_Widgetize + * @package Widgetize */ -class Piwik_Widgetize_Controller extends Controller +class Controller extends \Piwik\Controller { public function index() { diff --git a/plugins/Widgetize/Widgetize.php b/plugins/Widgetize/Widgetize.php index 27a002ccb9..b47fdf9e21 100644 --- a/plugins/Widgetize/Widgetize.php +++ b/plugins/Widgetize/Widgetize.php @@ -7,15 +7,16 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @category Piwik_Plugins - * @package Piwik_Widgetize + * @package Widgetize */ -use Piwik\Plugin; + +namespace Piwik\Plugins\Widgetize; /** * - * @package Piwik_Widgetize + * @package Widgetize */ -class Piwik_Widgetize extends Plugin +class Widgetize extends \Piwik\Plugin { /** * @see Piwik_Plugin::getListHooksRegistered diff --git a/plugins/Zeitgeist/stylesheets/base.css b/plugins/Zeitgeist/stylesheets/base.css index 75a146eb12..3eea5ab03a 100644 --- a/plugins/Zeitgeist/stylesheets/base.css +++ b/plugins/Zeitgeist/stylesheets/base.css @@ -1,3 +1,4 @@ +/* TO GENERATE: lessc plugins/Zeitgeist/stylesheets/base.less plugins/Zeitgeist/stylesheets/base.css */ /* base.less is a standalone Less file */ /* base.css is automatically generated. DO NOT MODIFY */ /* General styles */ diff --git a/plugins/Zeitgeist/stylesheets/base.less b/plugins/Zeitgeist/stylesheets/base.less index 3d8406e360..f4afcc6220 100644 --- a/plugins/Zeitgeist/stylesheets/base.less +++ b/plugins/Zeitgeist/stylesheets/base.less @@ -1,3 +1,4 @@ +/* TO GENERATE: lessc plugins/Zeitgeist/stylesheets/base.less plugins/Zeitgeist/stylesheets/base.css */ /* base.less is a standalone Less file */ /* base.css is automatically generated. DO NOT MODIFY */ |