update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -8,7 +8,6 @@
|
|||
*/
|
||||
namespace Piwik\DataTable\Renderer;
|
||||
|
||||
use Piwik\DataTable\Manager;
|
||||
use Piwik\DataTable;
|
||||
use Piwik\DataTable\Renderer;
|
||||
|
||||
|
|
@ -31,22 +30,9 @@ class Console extends Renderer
|
|||
*/
|
||||
public function render()
|
||||
{
|
||||
$this->renderHeader();
|
||||
return $this->renderTable($this->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the exception output and returns the string/binary
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function renderException()
|
||||
{
|
||||
$this->renderHeader();
|
||||
$exceptionMessage = $this->getExceptionMessage();
|
||||
return 'Error: ' . $exceptionMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the prefix to be used
|
||||
*
|
||||
|
|
@ -85,8 +71,9 @@ class Console extends Renderer
|
|||
*/
|
||||
protected function renderTable($table, $prefix = "")
|
||||
{
|
||||
if (is_array($table)) // convert array to DataTable
|
||||
{
|
||||
if (is_array($table)) {
|
||||
// convert array to DataTable
|
||||
|
||||
$table = DataTable::makeFromSimpleArray($table);
|
||||
}
|
||||
|
||||
|
|
@ -110,8 +97,11 @@ class Console extends Renderer
|
|||
$dataTableMapBreak = true;
|
||||
break;
|
||||
}
|
||||
if (is_string($value)) $value = "'$value'";
|
||||
elseif (is_array($value)) $value = var_export($value, true);
|
||||
if (is_string($value)) {
|
||||
$value = "'$value'";
|
||||
} elseif (is_array($value)) {
|
||||
$value = var_export($value, true);
|
||||
}
|
||||
|
||||
$columns[] = "'$column' => $value";
|
||||
}
|
||||
|
|
@ -122,8 +112,11 @@ class Console extends Renderer
|
|||
|
||||
$metadata = array();
|
||||
foreach ($row->getMetadata() as $name => $value) {
|
||||
if (is_string($value)) $value = "'$value'";
|
||||
elseif (is_array($value)) $value = var_export($value, true);
|
||||
if (is_string($value)) {
|
||||
$value = "'$value'";
|
||||
} elseif (is_array($value)) {
|
||||
$value = var_export($value, true);
|
||||
}
|
||||
$metadata[] = "'$name' => $value";
|
||||
}
|
||||
$metadata = implode(", ", $metadata);
|
||||
|
|
@ -133,14 +126,10 @@ class Console extends Renderer
|
|||
. $row->getIdSubDataTable() . "]<br />\n";
|
||||
|
||||
if (!is_null($row->getIdSubDataTable())) {
|
||||
if ($row->isSubtableLoaded()) {
|
||||
$subTable = $row->getSubtable();
|
||||
if ($subTable) {
|
||||
$depth++;
|
||||
$output .= $this->renderTable(
|
||||
Manager::getInstance()->getTable(
|
||||
$row->getIdSubDataTable()
|
||||
),
|
||||
$prefix . ' '
|
||||
);
|
||||
$output .= $this->renderTable($subTable, $prefix . ' ');
|
||||
$depth--;
|
||||
} else {
|
||||
$output .= "-- Sub DataTable not loaded<br />\n";
|
||||
|
|
@ -155,7 +144,7 @@ class Console extends Renderer
|
|||
foreach ($metadata as $id => $metadataIn) {
|
||||
$output .= "<br />";
|
||||
$output .= $prefix . " <b>$id</b><br />";
|
||||
if(is_array($metadataIn)) {
|
||||
if (is_array($metadataIn)) {
|
||||
foreach ($metadataIn as $name => $value) {
|
||||
$output .= $prefix . $prefix . "$name => $value";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -70,6 +70,8 @@ class Csv extends Renderer
|
|||
*/
|
||||
const NO_DATA_AVAILABLE = 'No data available';
|
||||
|
||||
private $unsupportedColumns = array();
|
||||
|
||||
/**
|
||||
* Computes the dataTable output and returns the string/binary
|
||||
*
|
||||
|
|
@ -84,26 +86,10 @@ class Csv extends Renderer
|
|||
|
||||
$this->renderHeader();
|
||||
|
||||
if ($this->convertToUnicode
|
||||
&& function_exists('mb_convert_encoding')
|
||||
) {
|
||||
$str = chr(255) . chr(254) . mb_convert_encoding($str, 'UTF-16LE', 'UTF-8');
|
||||
}
|
||||
$str = $this->convertToUnicode($str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the exception output and returns the string/binary
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function renderException()
|
||||
{
|
||||
@header('Content-Type: text/html; charset=utf-8');
|
||||
$exceptionMessage = $this->getExceptionMessage();
|
||||
return 'Error: ' . $exceptionMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables / Disables unicode converting
|
||||
*
|
||||
|
|
@ -133,8 +119,9 @@ class Csv extends Renderer
|
|||
*/
|
||||
protected function renderTable($table, &$allColumns = array())
|
||||
{
|
||||
if (is_array($table)) // convert array to DataTable
|
||||
{
|
||||
if (is_array($table)) {
|
||||
// convert array to DataTable
|
||||
|
||||
$table = DataTable::makeFromSimpleArray($table);
|
||||
}
|
||||
|
||||
|
|
@ -205,42 +192,7 @@ class Csv extends Renderer
|
|||
}
|
||||
}
|
||||
|
||||
$csv = array();
|
||||
foreach ($table->getRows() as $row) {
|
||||
$csvRow = $this->flattenColumnArray($row->getColumns());
|
||||
|
||||
if ($this->exportMetadata) {
|
||||
$metadata = $row->getMetadata();
|
||||
foreach ($metadata as $name => $value) {
|
||||
if ($name == 'idsubdatatable_in_db') {
|
||||
continue;
|
||||
}
|
||||
//if a metadata and a column have the same name make sure they dont overwrite
|
||||
if ($this->translateColumnNames) {
|
||||
$name = Piwik::translate('General_Metadata') . ': ' . $name;
|
||||
} else {
|
||||
$name = 'metadata_' . $name;
|
||||
}
|
||||
|
||||
$csvRow[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($csvRow as $name => $value) {
|
||||
$allColumns[$name] = true;
|
||||
}
|
||||
|
||||
if ($this->exportIdSubtable) {
|
||||
$idsubdatatable = $row->getIdSubDataTable();
|
||||
if ($idsubdatatable !== false
|
||||
&& $this->hideIdSubDatatable === false
|
||||
) {
|
||||
$csvRow['idsubdatatable'] = $idsubdatatable;
|
||||
}
|
||||
}
|
||||
|
||||
$csv[] = $csvRow;
|
||||
}
|
||||
$csv = $this->makeArrayFromDataTable($table, $allColumns);
|
||||
|
||||
// now we make sure that all the rows in the CSV array have all the columns
|
||||
foreach ($csv as &$row) {
|
||||
|
|
@ -251,31 +203,7 @@ class Csv extends Renderer
|
|||
}
|
||||
}
|
||||
|
||||
$str = '';
|
||||
|
||||
// specific case, we have only one column and this column wasn't named properly (indexed by a number)
|
||||
// we don't print anything in the CSV file => an empty line
|
||||
if (sizeof($allColumns) == 1
|
||||
&& reset($allColumns)
|
||||
&& !is_string(key($allColumns))
|
||||
) {
|
||||
$str .= '';
|
||||
} else {
|
||||
// render row names
|
||||
$str .= $this->getHeaderLine(array_keys($allColumns)) . $this->lineEnd;
|
||||
}
|
||||
|
||||
// we render the CSV
|
||||
foreach ($csv as $theRow) {
|
||||
$rowStr = '';
|
||||
foreach ($allColumns as $columnName => $true) {
|
||||
$rowStr .= $this->formatValue($theRow[$columnName]) . $this->separator;
|
||||
}
|
||||
// remove the last separator
|
||||
$rowStr = substr_replace($rowStr, "", -strlen($this->separator));
|
||||
$str .= $rowStr . $this->lineEnd;
|
||||
}
|
||||
$str = substr($str, 0, -strlen($this->lineEnd));
|
||||
$str = $this->buildCsvString($allColumns, $csv);
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
|
@ -287,9 +215,20 @@ class Csv extends Renderer
|
|||
*/
|
||||
private function getHeaderLine($columnMetrics)
|
||||
{
|
||||
foreach ($columnMetrics as $index => $value) {
|
||||
if (in_array($value, $this->unsupportedColumns)) {
|
||||
unset($columnMetrics[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->translateColumnNames) {
|
||||
$columnMetrics = $this->translateColumnNames($columnMetrics);
|
||||
}
|
||||
|
||||
foreach ($columnMetrics as &$value) {
|
||||
$value = $this->formatValue($value);
|
||||
}
|
||||
|
||||
return implode($this->separator, $columnMetrics);
|
||||
}
|
||||
|
||||
|
|
@ -334,14 +273,15 @@ class Csv extends Renderer
|
|||
|
||||
$period = Common::getRequestVar('period', false);
|
||||
$date = Common::getRequestVar('date', false);
|
||||
if ($period || $date) // in test cases, there are no request params set
|
||||
{
|
||||
if ($period || $date) {
|
||||
// in test cases, there are no request params set
|
||||
|
||||
if ($period == 'range') {
|
||||
$period = new Range($period, $date);
|
||||
} else if (strpos($date, ',') !== false) {
|
||||
} elseif (strpos($date, ',') !== false) {
|
||||
$period = new Range('range', $date);
|
||||
} else {
|
||||
$period = Period::factory($period, Date::factory($date));
|
||||
$period = Period\Factory::build($period, Date::factory($date));
|
||||
}
|
||||
|
||||
$prettyDate = $period->getLocalizedLongString();
|
||||
|
|
@ -353,8 +293,7 @@ class Csv extends Renderer
|
|||
}
|
||||
|
||||
// silent fail otherwise unit tests fail
|
||||
@header('Content-Type: application/vnd.ms-excel');
|
||||
@header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
||||
Common::sendHeader('Content-Disposition: attachment; filename="' . $fileName . '"', true);
|
||||
ProxyHttp::overrideCacheControlHeaders();
|
||||
}
|
||||
|
||||
|
|
@ -400,4 +339,119 @@ class Csv extends Renderer
|
|||
return $name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $allColumns
|
||||
* @param $csv
|
||||
* @return array
|
||||
*/
|
||||
private function buildCsvString($allColumns, $csv)
|
||||
{
|
||||
$str = '';
|
||||
|
||||
// specific case, we have only one column and this column wasn't named properly (indexed by a number)
|
||||
// we don't print anything in the CSV file => an empty line
|
||||
if (sizeof($allColumns) == 1
|
||||
&& reset($allColumns)
|
||||
&& !is_string(key($allColumns))
|
||||
) {
|
||||
$str .= '';
|
||||
} else {
|
||||
// render row names
|
||||
$str .= $this->getHeaderLine(array_keys($allColumns)) . $this->lineEnd;
|
||||
}
|
||||
|
||||
// we render the CSV
|
||||
foreach ($csv as $theRow) {
|
||||
$rowStr = '';
|
||||
foreach ($allColumns as $columnName => $true) {
|
||||
$rowStr .= $this->formatValue($theRow[$columnName]) . $this->separator;
|
||||
}
|
||||
// remove the last separator
|
||||
$rowStr = substr_replace($rowStr, "", -strlen($this->separator));
|
||||
$str .= $rowStr . $this->lineEnd;
|
||||
}
|
||||
$str = substr($str, 0, -strlen($this->lineEnd));
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $table
|
||||
* @param $allColumns
|
||||
* @return array of csv data
|
||||
*/
|
||||
private function makeArrayFromDataTable($table, &$allColumns)
|
||||
{
|
||||
$csv = array();
|
||||
foreach ($table->getRows() as $row) {
|
||||
$csvRow = $this->flattenColumnArray($row->getColumns());
|
||||
|
||||
if ($this->exportMetadata) {
|
||||
$metadata = $row->getMetadata();
|
||||
foreach ($metadata as $name => $value) {
|
||||
if ($name == 'idsubdatatable_in_db') {
|
||||
continue;
|
||||
}
|
||||
//if a metadata and a column have the same name make sure they dont overwrite
|
||||
if ($this->translateColumnNames) {
|
||||
$name = Piwik::translate('General_Metadata') . ': ' . $name;
|
||||
} else {
|
||||
$name = 'metadata_' . $name;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
if (!in_array($name, $this->unsupportedColumns)) {
|
||||
$this->unsupportedColumns[] = $name;
|
||||
}
|
||||
} else {
|
||||
$csvRow[$name] = $value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($csvRow as $name => $value) {
|
||||
if (in_array($name, $this->unsupportedColumns)) {
|
||||
unset($allColumns[$name]);
|
||||
} else {
|
||||
$allColumns[$name] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->exportIdSubtable) {
|
||||
$idsubdatatable = $row->getIdSubDataTable();
|
||||
if ($idsubdatatable !== false
|
||||
&& $this->hideIdSubDatatable === false
|
||||
) {
|
||||
$csvRow['idsubdatatable'] = $idsubdatatable;
|
||||
}
|
||||
}
|
||||
|
||||
$csv[] = $csvRow;
|
||||
}
|
||||
|
||||
if (!empty($this->unsupportedColumns)) {
|
||||
foreach ($this->unsupportedColumns as $unsupportedColumn) {
|
||||
foreach ($csv as $index => $row) {
|
||||
unset($row[$index][$unsupportedColumn]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $csv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @return string
|
||||
*/
|
||||
private function convertToUnicode($str)
|
||||
{
|
||||
if ($this->convertToUnicode
|
||||
&& function_exists('mb_convert_encoding')
|
||||
) {
|
||||
$str = chr(255) . chr(254) . mb_convert_encoding($str, 'UTF-16LE', 'UTF-8');
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -29,27 +29,18 @@ class Html extends Renderer
|
|||
*
|
||||
* @param string $id
|
||||
*/
|
||||
function setTableId($id)
|
||||
public function setTableId($id)
|
||||
{
|
||||
$this->tableId = str_replace('.', '_', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output HTTP Content-Type header
|
||||
*/
|
||||
protected function renderHeader()
|
||||
{
|
||||
@header('Content-Type: text/html; charset=utf-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the dataTable output and returns the string/binary
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function render()
|
||||
public function render()
|
||||
{
|
||||
$this->renderHeader();
|
||||
$this->tableStructure = array();
|
||||
$this->allColumns = array();
|
||||
$this->i = 0;
|
||||
|
|
@ -57,18 +48,6 @@ class Html extends Renderer
|
|||
return $this->renderTable($this->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the exception output and returns the string/binary
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function renderException()
|
||||
{
|
||||
$this->renderHeader();
|
||||
$exceptionMessage = $this->getExceptionMessage();
|
||||
return nl2br($exceptionMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the output for the given data table
|
||||
*
|
||||
|
|
@ -77,8 +56,9 @@ class Html extends Renderer
|
|||
*/
|
||||
protected function renderTable($table)
|
||||
{
|
||||
if (is_array($table)) // convert array to DataTable
|
||||
{
|
||||
if (is_array($table)) {
|
||||
// convert array to DataTable
|
||||
|
||||
$table = DataTable::makeFromSimpleArray($table);
|
||||
}
|
||||
|
||||
|
|
@ -88,8 +68,9 @@ class Html extends Renderer
|
|||
$this->buildTableStructure($subtable, '_' . $table->getKeyName(), $date);
|
||||
}
|
||||
}
|
||||
} else // Simple
|
||||
{
|
||||
} else {
|
||||
// Simple
|
||||
|
||||
if ($table->getRowsCount()) {
|
||||
$this->buildTableStructure($table);
|
||||
}
|
||||
|
|
@ -134,7 +115,9 @@ class Html extends Renderer
|
|||
|
||||
$metadata = array();
|
||||
foreach ($row->getMetadata() as $name => $value) {
|
||||
if (is_string($value)) $value = "'$value'";
|
||||
if (is_string($value)) {
|
||||
$value = "'$value'";
|
||||
}
|
||||
$metadata[] = "'$name' => $value";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -11,7 +11,6 @@ namespace Piwik\DataTable\Renderer;
|
|||
use Piwik\Common;
|
||||
use Piwik\DataTable\Renderer;
|
||||
use Piwik\DataTable;
|
||||
use Piwik\ProxyHttp;
|
||||
|
||||
/**
|
||||
* JSON export.
|
||||
|
|
@ -27,27 +26,9 @@ class Json extends Renderer
|
|||
*/
|
||||
public function render()
|
||||
{
|
||||
$this->renderHeader();
|
||||
return $this->renderTable($this->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the exception output and returns the string/binary
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function renderException()
|
||||
{
|
||||
$this->renderHeader();
|
||||
|
||||
$exceptionMessage = $this->getExceptionMessage();
|
||||
$exceptionMessage = str_replace(array("\r\n", "\n"), "", $exceptionMessage);
|
||||
|
||||
$result = json_encode(array('result' => 'error', 'message' => $exceptionMessage));
|
||||
|
||||
return $this->jsonpWrap($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the output for the given data table
|
||||
*
|
||||
|
|
@ -73,7 +54,6 @@ class Json extends Renderer
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$array = $this->convertDataTableToArray($table);
|
||||
}
|
||||
|
|
@ -90,40 +70,15 @@ class Json extends Renderer
|
|||
};
|
||||
array_walk_recursive($array, $callback);
|
||||
|
||||
$str = json_encode($array);
|
||||
|
||||
return $this->jsonpWrap($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @return string
|
||||
*/
|
||||
protected function jsonpWrap($str)
|
||||
{
|
||||
if (($jsonCallback = Common::getRequestVar('callback', false)) === false)
|
||||
$jsonCallback = Common::getRequestVar('jsoncallback', false);
|
||||
if ($jsonCallback !== false) {
|
||||
if (preg_match('/^[0-9a-zA-Z_.]*$/D', $jsonCallback) > 0) {
|
||||
$str = $jsonCallback . "(" . $str . ")";
|
||||
}
|
||||
}
|
||||
// silence "Warning: json_encode(): Invalid UTF-8 sequence in argument"
|
||||
$str = @json_encode($array);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the http header for json file
|
||||
*/
|
||||
protected function renderHeader()
|
||||
{
|
||||
self::sendHeaderJSON();
|
||||
ProxyHttp::overrideCacheControlHeaders();
|
||||
}
|
||||
|
||||
public static function sendHeaderJSON()
|
||||
{
|
||||
@header('Content-Type: application/json; charset=utf-8');
|
||||
Common::sendHeader('Content-Type: application/json; charset=utf-8');
|
||||
}
|
||||
|
||||
private function convertDataTableToArray($table)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -9,7 +9,6 @@
|
|||
namespace Piwik\DataTable\Renderer;
|
||||
|
||||
use Exception;
|
||||
use Piwik\DataTable\Manager;
|
||||
use Piwik\DataTable\Renderer;
|
||||
use Piwik\DataTable\Simple;
|
||||
use Piwik\DataTable;
|
||||
|
|
@ -71,8 +70,6 @@ class Php extends Renderer
|
|||
*/
|
||||
public function render($dataTable = null)
|
||||
{
|
||||
$this->renderHeader();
|
||||
|
||||
if (is_null($dataTable)) {
|
||||
$dataTable = $this->table;
|
||||
}
|
||||
|
|
@ -87,26 +84,6 @@ class Php extends Renderer
|
|||
return $toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the exception output and returns the string/binary
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function renderException()
|
||||
{
|
||||
$this->renderHeader();
|
||||
|
||||
$exceptionMessage = $this->getExceptionMessage();
|
||||
|
||||
$return = array('result' => 'error', 'message' => $exceptionMessage);
|
||||
|
||||
if ($this->serialize) {
|
||||
$return = serialize($return);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a flat php array from the DataTable, putting "columns" and "metadata" on the same level.
|
||||
*
|
||||
|
|
@ -133,7 +110,7 @@ class Php extends Renderer
|
|||
if (self::shouldWrapArrayBeforeRendering($flatArray)) {
|
||||
$flatArray = array($flatArray);
|
||||
}
|
||||
} else if ($dataTable instanceof DataTable\Map) {
|
||||
} elseif ($dataTable instanceof DataTable\Map) {
|
||||
$flatArray = array();
|
||||
foreach ($dataTable->getDataTables() as $keyName => $table) {
|
||||
$serializeSave = $this->serialize;
|
||||
|
|
@ -141,7 +118,7 @@ class Php extends Renderer
|
|||
$flatArray[$keyName] = $this->flatRender($table);
|
||||
$this->serialize = $serializeSave;
|
||||
}
|
||||
} else if ($dataTable instanceof Simple) {
|
||||
} elseif ($dataTable instanceof Simple) {
|
||||
$flatArray = $this->renderSimpleTable($dataTable);
|
||||
|
||||
// if we return only one numeric value then we print out the result in a simple <result> tag
|
||||
|
|
@ -228,10 +205,11 @@ class Php extends Renderer
|
|||
$newRow['issummaryrow'] = true;
|
||||
}
|
||||
|
||||
$subTable = $row->getSubtable();
|
||||
if ($this->isRenderSubtables()
|
||||
&& $row->isSubtableLoaded()
|
||||
&& $subTable
|
||||
) {
|
||||
$subTable = $this->renderTable(Manager::getInstance()->getTable($row->getIdSubDataTable()));
|
||||
$subTable = $this->renderTable($subTable);
|
||||
$newRow['subtable'] = $subTable;
|
||||
if ($this->hideIdSubDatatable === false
|
||||
&& isset($newRow['metadata']['idsubdatatable_in_db'])
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -15,7 +15,6 @@ use Piwik\DataTable\Renderer;
|
|||
use Piwik\DataTable;
|
||||
use Piwik\Date;
|
||||
use Piwik\SettingsPiwik;
|
||||
use Piwik\Url;
|
||||
|
||||
/**
|
||||
* RSS Feed.
|
||||
|
|
@ -30,24 +29,11 @@ class Rss extends Renderer
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
function render()
|
||||
public function render()
|
||||
{
|
||||
$this->renderHeader();
|
||||
return $this->renderTable($this->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the exception output and returns the string/binary
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function renderException()
|
||||
{
|
||||
header('Content-type: text/plain');
|
||||
$exceptionMessage = $this->getExceptionMessage();
|
||||
return 'Error: ' . $exceptionMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the output for the given data table
|
||||
*
|
||||
|
|
@ -101,14 +87,6 @@ class Rss extends Renderer
|
|||
return $header . $out . $footer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the xml file http header
|
||||
*/
|
||||
protected function renderHeader()
|
||||
{
|
||||
@header('Content-Type: text/xml; charset=utf-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the RSS file footer
|
||||
*
|
||||
|
|
@ -185,7 +163,6 @@ class Rss extends Renderer
|
|||
}
|
||||
}
|
||||
$html .= "\n</tr>";
|
||||
$colspan = count($allColumns);
|
||||
|
||||
foreach ($tableStructure as $row) {
|
||||
$html .= "\n\n<tr>";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -8,7 +8,6 @@
|
|||
*/
|
||||
namespace Piwik\DataTable\Renderer;
|
||||
|
||||
|
||||
/**
|
||||
* TSV export
|
||||
*
|
||||
|
|
@ -21,7 +20,7 @@ class Tsv extends Csv
|
|||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function __construct()
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setSeparator("\t");
|
||||
|
|
@ -32,7 +31,7 @@ class Tsv extends Csv
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
function render()
|
||||
public function render()
|
||||
{
|
||||
return parent::render();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -30,31 +30,11 @@ class Xml extends Renderer
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
function render()
|
||||
public function render()
|
||||
{
|
||||
$this->renderHeader();
|
||||
return '<?xml version="1.0" encoding="utf-8" ?>' . "\n" . $this->renderTable($this->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the exception output and returns the string/binary
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function renderException()
|
||||
{
|
||||
$this->renderHeader();
|
||||
|
||||
$exceptionMessage = $this->getExceptionMessage();
|
||||
|
||||
$return = '<?xml version="1.0" encoding="utf-8" ?>' . "\n" .
|
||||
"<result>\n" .
|
||||
"\t<error message=\"" . $exceptionMessage . "\" />\n" .
|
||||
"</result>";
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given data table to an array
|
||||
*
|
||||
|
|
@ -174,17 +154,16 @@ class Xml extends Renderer
|
|||
foreach ($array as $key => $value) {
|
||||
// based on the type of array & the key, determine how this node will look
|
||||
if ($isAssociativeArray) {
|
||||
$keyIsInvalidXmlElement = is_numeric($key) || is_numeric($key[0]);
|
||||
if ($keyIsInvalidXmlElement) {
|
||||
$prefix = "<row key=\"$key\">";
|
||||
$suffix = "</row>";
|
||||
$emptyNode = "<row key=\"$key\"/>";
|
||||
} else if (strpos($key, '=') !== false) {
|
||||
if (strpos($key, '=') !== false) {
|
||||
list($keyAttributeName, $key) = explode('=', $key, 2);
|
||||
|
||||
$prefix = "<row $keyAttributeName=\"$key\">";
|
||||
$suffix = "</row>";
|
||||
$emptyNode = "<row $keyAttributeName=\"$key\">";
|
||||
} elseif (!self::isValidXmlTagName($key)) {
|
||||
$prefix = "<row key=\"$key\">";
|
||||
$suffix = "</row>";
|
||||
$emptyNode = "<row key=\"$key\"/>";
|
||||
} else {
|
||||
$prefix = "<$key>";
|
||||
$suffix = "</$key>";
|
||||
|
|
@ -201,7 +180,7 @@ class Xml extends Renderer
|
|||
$result .= $prefixLines . $prefix . "\n";
|
||||
$result .= $this->renderArray($value, $prefixLines . "\t");
|
||||
$result .= $prefixLines . $suffix . "\n";
|
||||
} else if ($value instanceof DataTable
|
||||
} elseif ($value instanceof DataTable
|
||||
|| $value instanceof Map
|
||||
) {
|
||||
if ($value->getRowsCount() == 0) {
|
||||
|
|
@ -210,7 +189,7 @@ class Xml extends Renderer
|
|||
$result .= $prefixLines . $prefix . "\n";
|
||||
if ($value instanceof Map) {
|
||||
$result .= $this->renderDataTableMap($value, $this->getArrayFromDataTable($value), $prefixLines);
|
||||
} else if ($value instanceof Simple) {
|
||||
} elseif ($value instanceof Simple) {
|
||||
$result .= $this->renderDataTableSimple($this->getArrayFromDataTable($value), $prefixLines);
|
||||
} else {
|
||||
$result .= $this->renderDataTable($this->getArrayFromDataTable($value), $prefixLines);
|
||||
|
|
@ -358,6 +337,8 @@ class Xml extends Renderer
|
|||
*/
|
||||
protected function renderDataTable($array, $prefixLine = "")
|
||||
{
|
||||
$columnsHaveInvalidChars = $this->areTableLabelsInvalidXmlTagNames(reset($array));
|
||||
|
||||
$out = '';
|
||||
foreach ($array as $rowId => $row) {
|
||||
if (!is_array($row)) {
|
||||
|
|
@ -370,10 +351,9 @@ class Xml extends Renderer
|
|||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Handing case idgoal=7, creating a new array for that one
|
||||
$rowAttribute = '';
|
||||
if (($equalFound = strstr($rowId, '=')) !== false) {
|
||||
if (strstr($rowId, '=') !== false) {
|
||||
$rowAttribute = explode('=', $rowId);
|
||||
$rowAttribute = " " . $rowAttribute[0] . "='" . $rowAttribute[1] . "'";
|
||||
}
|
||||
|
|
@ -394,10 +374,13 @@ class Xml extends Renderer
|
|||
} else {
|
||||
$value = self::formatValueXml($value);
|
||||
}
|
||||
|
||||
list($tagStart, $tagEnd) = $this->getTagStartAndEndFor($name, $columnsHaveInvalidChars);
|
||||
|
||||
if (strlen($value) == 0) {
|
||||
$out .= $prefixLine . "\t\t<$name />\n";
|
||||
$out .= $prefixLine . "\t\t<$tagStart />\n";
|
||||
} else {
|
||||
$out .= $prefixLine . "\t\t<$name>" . $value . "</$name>\n";
|
||||
$out .= $prefixLine . "\t\t<$tagStart>" . $value . "</$tagEnd>\n";
|
||||
}
|
||||
}
|
||||
$out .= "\t";
|
||||
|
|
@ -420,24 +403,62 @@ class Xml extends Renderer
|
|||
$array = array('value' => $array);
|
||||
}
|
||||
|
||||
$columnsHaveInvalidChars = $this->areTableLabelsInvalidXmlTagNames($array);
|
||||
|
||||
$out = '';
|
||||
foreach ($array as $keyName => $value) {
|
||||
$xmlValue = self::formatValueXml($value);
|
||||
list($tagStart, $tagEnd) = $this->getTagStartAndEndFor($keyName, $columnsHaveInvalidChars);
|
||||
if (strlen($xmlValue) == 0) {
|
||||
$out .= $prefixLine . "\t<$keyName />\n";
|
||||
$out .= $prefixLine . "\t<$tagStart />\n";
|
||||
} else {
|
||||
$out .= $prefixLine . "\t<$keyName>" . $xmlValue . "</$keyName>\n";
|
||||
$out .= $prefixLine . "\t<$tagStart>" . $xmlValue . "</$tagEnd>\n";
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the XML headers
|
||||
* Returns true if a string is a valid XML tag name, false if otherwise.
|
||||
*
|
||||
* @param string $str
|
||||
* @return bool
|
||||
*/
|
||||
protected function renderHeader()
|
||||
private static function isValidXmlTagName($str)
|
||||
{
|
||||
// silent fail because otherwise it throws an exception in the unit tests
|
||||
@header('Content-Type: text/xml; charset=utf-8');
|
||||
static $validTagRegex = null;
|
||||
|
||||
if ($validTagRegex === null) {
|
||||
$invalidTagChars = "!\"#$%&'()*+,\\/;<=>?@[\\]\\\\^`{|}~";
|
||||
$invalidTagStartChars = $invalidTagChars . "\\-.0123456789";
|
||||
$validTagRegex = "/^[^" . $invalidTagStartChars . "][^" . $invalidTagChars . "]*$/";
|
||||
}
|
||||
|
||||
$result = preg_match($validTagRegex, $str);
|
||||
return !empty($result);
|
||||
}
|
||||
|
||||
private function areTableLabelsInvalidXmlTagNames($rowArray)
|
||||
{
|
||||
if (!empty($rowArray)) {
|
||||
foreach ($rowArray as $name => $value) {
|
||||
if (!self::isValidXmlTagName($name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getTagStartAndEndFor($keyName, $columnsHaveInvalidChars)
|
||||
{
|
||||
if ($columnsHaveInvalidChars) {
|
||||
$tagStart = "col name=\"" . self::formatValueXml($keyName) . "\"";
|
||||
$tagEnd = "col";
|
||||
} else {
|
||||
$tagStart = $tagEnd = $keyName;
|
||||
}
|
||||
|
||||
return array($tagStart, $tagEnd);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue