Skip to content

Commit

Permalink
Refs #4059 Work in progress: Conversion to use Namespaces of dozen mo…
Browse files Browse the repository at this point in the history
…re classes

Removed many Piwik_ functions, in Piwik 2 it is best practise to use the methods calls instead

Todo: finish converting core/ classes + convert plugins/ classes to use \Piwik\Plugin namespace + fix build + Merge master
  • Loading branch information
mattab committed Jul 23, 2013
1 parent ae4b1f4 commit 5104d94
Show file tree
Hide file tree
Showing 358 changed files with 3,091 additions and 2,621 deletions.
5 changes: 4 additions & 1 deletion core/API/DataTableGenericFilter.php
Expand Up @@ -8,6 +8,9 @@
* @category Piwik
* @package Piwik
*/
namespace Piwik\API;

use Exception;
use Piwik\Common;
use Piwik\DataTable;
use Piwik\DataTable\Filter\AddColumnsProcessedMetricsGoal;
Expand All @@ -16,7 +19,7 @@
* @package Piwik
* @subpackage Piwik_API
*/
class Piwik_API_DataTableGenericFilter
class DataTableGenericFilter
{
private static $genericFiltersInfo = null;

Expand Down
21 changes: 13 additions & 8 deletions core/API/DataTableManipulator.php
Expand Up @@ -8,15 +8,21 @@
* @category Piwik
* @package Piwik
*/
namespace Piwik\API;

use Exception;
use Piwik\DataTable\Row;
use Piwik\Period\Range;
use Piwik\DataTable;
use Piwik_API_API;
use Piwik\API\Proxy;
use Piwik\API\ResponseBuilder;

/**
* Base class for manipulating data tables.
* It provides generic mechanisms like iteration and loading subtables.
*
* The manipulators are used in Piwik_API_ResponseBuilder and are triggered by
* The manipulators are used in ResponseBuilder and are triggered by
* API parameters. They are not filters because they don't work on the pre-
* fetched nested data tables. Instead, they load subtables using this base
* class. This way, they can only load the tables they really need instead
Expand All @@ -27,7 +33,7 @@
* @package Piwik
* @subpackage Piwik_API
*/
abstract class Piwik_API_DataTableManipulator
abstract class DataTableManipulator
{
protected $apiModule;
protected $apiMethod;
Expand Down Expand Up @@ -92,7 +98,7 @@ protected abstract function manipulateDataTable($dataTable);
* Load the subtable for a row.
* Returns null if none is found.
*
* @param DataTable $dataTable
* @param DataTable $dataTable
* @param Row $row
*
* @return DataTable
Expand All @@ -114,7 +120,7 @@ protected function loadSubtable($dataTable, $row)
if ($dataTable) {
$period = $dataTable->metadata['period'];
if ($period instanceof Range) {
$request['date'] = $period->getDateStart().','.$period->getDateEnd();
$request['date'] = $period->getDateStart() . ',' . $period->getDateEnd();
} else {
$request['date'] = $period->getDateStart()->toString();
}
Expand All @@ -132,8 +138,8 @@ protected function loadSubtable($dataTable, $row)
// run it on the flattened table.
unset($request['filter_pattern_recursive']);

$dataTable = Piwik_API_Proxy::getInstance()->call($class, $method, $request);
$response = new Piwik_API_ResponseBuilder($format = 'original', $request);
$dataTable = Proxy::getInstance()->call($class, $method, $request);
$response = new ResponseBuilder($format = 'original', $request);
$dataTable = $response->getResponse($dataTable);
if (method_exists($dataTable, 'applyQueuedFilters')) {
$dataTable->applyQueuedFilters();
Expand All @@ -144,7 +150,7 @@ protected function loadSubtable($dataTable, $row)

/**
* In this method, subclasses can clean up the request array for loading subtables
* in order to make Piwik_API_ResponseBuilder behave correctly (e.g. not trigger the
* in order to make ResponseBuilder behave correctly (e.g. not trigger the
* manipulator again).
*
* @param $request
Expand All @@ -169,5 +175,4 @@ private function getApiMethodForSubtable()
}
return $this->apiMethodForSubtable;
}

}
7 changes: 5 additions & 2 deletions core/API/DataTableManipulator/Flattener.php
Expand Up @@ -8,8 +8,11 @@
* @category Piwik
* @package Piwik
*/
namespace Piwik\API\DataTableManipulator;

use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\API\DataTableManipulator;

/**
* This class is responsible for flattening data tables.
Expand All @@ -20,7 +23,7 @@
* @package Piwik
* @subpackage Piwik_API
*/
class Piwik_API_DataTableManipulator_Flattener extends Piwik_API_DataTableManipulator
class Flattener extends DataTableManipulator
{

private $includeAggregateRows = false;
Expand Down Expand Up @@ -66,7 +69,7 @@ protected function manipulateDataTable($dataTable)
if ($this->includeAggregateRows) {
$dataTable->applyQueuedFilters();
}

$newDataTable = $dataTable->getEmptyClone($keepFilters = false);
foreach ($dataTable->getRows() as $row) {
$this->flattenRow($row, $newDataTable);
Expand Down
16 changes: 10 additions & 6 deletions core/API/DataTableManipulator/LabelFilter.php
Expand Up @@ -8,9 +8,13 @@
* @category Piwik
* @package Piwik
*/
namespace Piwik\API\DataTableManipulator;

use Piwik\Common;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\API\DataTableManipulator;
use false;

/**
* This class is responsible for handling the label parameter that can be
Expand All @@ -23,7 +27,7 @@
* @package Piwik
* @subpackage Piwik_API
*/
class Piwik_API_DataTableManipulator_LabelFilter extends Piwik_API_DataTableManipulator
class LabelFilter extends DataTableManipulator
{
const SEPARATOR_RECURSIVE_LABEL = '>';

Expand Down Expand Up @@ -96,7 +100,7 @@ private function doFilterRecursiveDescend($labelParts, $dataTable)
}

/**
* Clean up request for Piwik_API_ResponseBuilder to behave correctly
* Clean up request for ResponseBuilder to behave correctly
*
* @param $request
*/
Expand All @@ -108,7 +112,7 @@ protected function manipulateSubtableRequest(&$request)
/**
* Use variations of the label to make it easier to specify the desired label
*
* Note: The HTML Encoded version must be tried first, since in Piwik_API_ResponseBuilder the $label is unsanitized
* Note: The HTML Encoded version must be tried first, since in ResponseBuilder the $label is unsanitized
* via Common::unsanitizeLabelParameter.
*
* @param string $label
Expand All @@ -117,19 +121,19 @@ protected function manipulateSubtableRequest(&$request)
private function getLabelVariations($label)
{
static $pageTitleReports = array('getPageTitles', 'getEntryPageTitles', 'getExitPageTitles');

$variations = array();
$label = urldecode($label);
$label = trim($label);

$sanitizedLabel = Common::sanitizeInputValue( $label );
$sanitizedLabel = Common::sanitizeInputValue($label);
$variations[] = $sanitizedLabel;

if ($this->apiModule == 'Actions'
&& in_array($this->apiMethod, $pageTitleReports)
) {
// special case: the Actions.getPageTitles report prefixes some labels with a blank.
// the blank might be passed by the user but is removed in Piwik_API_Request::getRequestArrayFromString.
// the blank might be passed by the user but is removed in Request::getRequestArrayFromString.
$variations[] = ' ' . $sanitizedLabel;
$variations[] = ' ' . $label;
}
Expand Down
32 changes: 18 additions & 14 deletions core/API/DocumentationGenerator.php
Expand Up @@ -8,14 +8,20 @@
* @category Piwik
* @package Piwik
*/
namespace Piwik\API;

use Exception;
use Piwik\Piwik;
use Piwik\Common;
use Piwik\API\Proxy;
use Piwik_API_Proxy_NoDefaultValue;
use Piwik_Url;

/**
* @package Piwik
* @subpackage Piwik_API
*/
class Piwik_API_DocumentationGenerator
class DocumentationGenerator
{
protected $modulesToHide = array('CoreAdminHome', 'DBStats');
protected $countPluginsLoaded = 0;
Expand All @@ -29,7 +35,7 @@ public function __construct()
foreach ($plugins as $plugin) {
$plugin = Common::unprefixClass($plugin);
try {
Piwik_API_Proxy::getInstance()->registerClass('Piwik_' . $plugin . '_API');
Proxy::getInstance()->registerClass('Piwik_' . $plugin . '_API');
} catch (Exception $e) {
}
}
Expand Down Expand Up @@ -57,8 +63,8 @@ public function getAllInterfaceString($outputExampleUrls = true, $prefixUrls = '
'date' => Common::getRequestVar('date', 'today', 'string')
);

foreach (Piwik_API_Proxy::getInstance()->getMetadata() as $class => $info) {
$moduleName = Piwik_API_Proxy::getInstance()->getModuleNameFromClassName($class);
foreach (Proxy::getInstance()->getMetadata() as $class => $info) {
$moduleName = Proxy::getInstance()->getModuleNameFromClassName($class);
if (in_array($moduleName, $this->modulesToHide)) {
continue;
}
Expand Down Expand Up @@ -87,9 +93,9 @@ public function getAllInterfaceString($outputExampleUrls = true, $prefixUrls = '
}
$exampleUrl = $prefixUrls . $exampleUrl;
$str .= " [ Example in
<a target=_blank href='$exampleUrl&format=xml$token_auth'>XML</a>,
<a target=_blank href='$exampleUrl&format=JSON$token_auth'>Json</a>,
<a target=_blank href='$exampleUrl&format=Tsv$token_auth&translateColumnNames=1'>Tsv (Excel)</a>
<a target=_blank href='$exampleUrl&format=xml$token_auth'>XML</a>,
<a target=_blank href='$exampleUrl&format=JSON$token_auth'>Json</a>,
<a target=_blank href='$exampleUrl&format=Tsv$token_auth&translateColumnNames=1'>Tsv (Excel)</a>
$lastNUrls
]";
} else {
Expand All @@ -104,7 +110,7 @@ public function getAllInterfaceString($outputExampleUrls = true, $prefixUrls = '
}

$str = "<h2 id='topApiRef' name='topApiRef'>Quick access to APIs</h2>
$toc
$toc
$str";
return $str;
}
Expand All @@ -129,7 +135,7 @@ public function getExampleUrl($class, $methodName, $parametersToSet = array())

'languageCode' => 'fr',
'url' => 'http://forum.piwik.org/',
'pageUrl' => 'http://forum.piwik.org/',
'pageUrl' => 'http://forum.piwik.org/',
'apiModule' => 'UserCountry',
'apiAction' => 'getCountry',
'lastMinutes' => '30',
Expand Down Expand Up @@ -165,7 +171,7 @@ public function getExampleUrl($class, $methodName, $parametersToSet = array())
}

// we try to give an URL example to call the API
$aParameters = Piwik_API_Proxy::getInstance()->getParametersList($class, $methodName);
$aParameters = Proxy::getInstance()->getParametersList($class, $methodName);
// Kindly force some known generic parameters to appear in the final list
// the parameter 'format' can be set to all API methods (used in tests)
// the parameter 'hideIdSubDatable' is used for integration tests only
Expand All @@ -189,7 +195,7 @@ public function getExampleUrl($class, $methodName, $parametersToSet = array())
$aParameters['showColumns'] = false;
$aParameters['filter_pattern_recursive'] = false;

$moduleName = Piwik_API_Proxy::getInstance()->getModuleNameFromClassName($class);
$moduleName = Proxy::getInstance()->getModuleNameFromClassName($class);
$aParameters = array_merge(array('module' => 'API', 'method' => $moduleName . '.' . $methodName), $aParameters);

foreach ($aParameters as $nameVariable => &$defaultValue) {
Expand All @@ -204,7 +210,6 @@ public function getExampleUrl($class, $methodName, $parametersToSet = array())
return '?' . Piwik_Url::getQueryStringFromParameters($aParameters);
}


/**
* Returns the methods $class.$name parameters (and default value if provided) as a string.
*
Expand All @@ -214,7 +219,7 @@ public function getExampleUrl($class, $methodName, $parametersToSet = array())
*/
public function getParametersString($class, $name)
{
$aParameters = Piwik_API_Proxy::getInstance()->getParametersList($class, $name);
$aParameters = Proxy::getInstance()->getParametersList($class, $name);
$asParameters = array();
foreach ($aParameters as $nameVariable => $defaultValue) {
// Do not show API parameters starting with _
Expand All @@ -235,5 +240,4 @@ public function getParametersString($class, $name)
$sParameters = implode(", ", $asParameters);
return "($sParameters)";
}

}

0 comments on commit 5104d94

Please sign in to comment.