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

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-08-11 21:28:30 +0400
committermattab <matthieu.aubry@gmail.com>2013-08-11 21:28:30 +0400
commitd293408450bc8b0c0f79934da6a43914626935ae (patch)
treee50c0df2f698b6033e13f963b9a16a01ef5bf020 /plugins/API
parent3b74ae5cdac37e16315c3a24ecf2591f742ca3c7 (diff)
parent2340530c1109a37527f3b8ad0b82e54e7a6eb137 (diff)
Merge branch 'plugin_namespaces'
Conflicts: plugins/UserCountryMap/Controller.php
Diffstat (limited to 'plugins/API')
-rw-r--r--plugins/API/API.php137
-rw-r--r--plugins/API/Controller.php9
-rw-r--r--plugins/API/ProcessedReport.php29
-rw-r--r--plugins/API/RowEvolution.php17
4 files changed, 98 insertions, 94 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.