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
|
||||
|
|
@ -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