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
31
www/analytics/plugins/API/Renderer/Console.php
Normal file
31
www/analytics/plugins/API/Renderer/Console.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\API\Renderer;
|
||||
|
||||
use Piwik\API\ApiRenderer;
|
||||
use Piwik\Common;
|
||||
use Piwik\DataTable\Renderer;
|
||||
use Piwik\DataTable;
|
||||
|
||||
class Console extends ApiRenderer
|
||||
{
|
||||
|
||||
public function renderException($message, \Exception $exception)
|
||||
{
|
||||
self::sendHeader();
|
||||
|
||||
return 'Error: ' . $message;
|
||||
}
|
||||
|
||||
public function sendHeader()
|
||||
{
|
||||
Common::sendHeader('Content-Type: text/plain; charset=utf-8');
|
||||
}
|
||||
|
||||
}
|
||||
60
www/analytics/plugins/API/Renderer/Csv.php
Normal file
60
www/analytics/plugins/API/Renderer/Csv.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\API\Renderer;
|
||||
|
||||
use Piwik\API\ApiRenderer;
|
||||
use Piwik\Common;
|
||||
use Piwik\DataTable\Renderer;
|
||||
use Piwik\DataTable;
|
||||
use Piwik\ProxyHttp;
|
||||
|
||||
class Csv extends ApiRenderer
|
||||
{
|
||||
|
||||
public function renderSuccess($message)
|
||||
{
|
||||
Common::sendHeader("Content-Disposition: attachment; filename=piwik-report-export.csv");
|
||||
return "message\n" . $message;
|
||||
}
|
||||
|
||||
public function renderException($message, \Exception $exception)
|
||||
{
|
||||
Common::sendHeader('Content-Type: text/html; charset=utf-8', true);
|
||||
return 'Error: ' . $message;
|
||||
}
|
||||
|
||||
public function renderDataTable($dataTable)
|
||||
{
|
||||
$convertToUnicode = Common::getRequestVar('convertToUnicode', true, 'int', $this->request);
|
||||
$idSite = Common::getRequestVar('idSite', false, 'int', $this->request);
|
||||
|
||||
/** @var \Piwik\DataTable\Renderer\Csv $tableRenderer */
|
||||
$tableRenderer = $this->buildDataTableRenderer($dataTable);
|
||||
$tableRenderer->setConvertToUnicode($convertToUnicode);
|
||||
|
||||
$method = Common::getRequestVar('method', '', 'string', $this->request);
|
||||
|
||||
$tableRenderer->setApiMethod($method);
|
||||
$tableRenderer->setIdSite($idSite);
|
||||
$tableRenderer->setTranslateColumnNames(Common::getRequestVar('translateColumnNames', false, 'int', $this->request));
|
||||
|
||||
return $tableRenderer->render();
|
||||
}
|
||||
|
||||
public function renderArray($array)
|
||||
{
|
||||
return $this->renderDataTable($array);
|
||||
}
|
||||
|
||||
public function sendHeader()
|
||||
{
|
||||
Common::sendHeader("Content-Type: application/vnd.ms-excel", true);
|
||||
ProxyHttp::overrideCacheControlHeaders();
|
||||
}
|
||||
}
|
||||
51
www/analytics/plugins/API/Renderer/Html.php
Normal file
51
www/analytics/plugins/API/Renderer/Html.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\API\Renderer;
|
||||
|
||||
use Piwik\API\ApiRenderer;
|
||||
use Piwik\Common;
|
||||
use Piwik\DataTable\Renderer;
|
||||
use Piwik\DataTable;
|
||||
|
||||
class Html extends ApiRenderer
|
||||
{
|
||||
|
||||
public function renderException($message, \Exception $exception)
|
||||
{
|
||||
Common::sendHeader('Content-Type: text/plain; charset=utf-8', true);
|
||||
|
||||
return nl2br($message);
|
||||
}
|
||||
|
||||
public function renderDataTable($dataTable)
|
||||
{
|
||||
/** @var \Piwik\DataTable\Renderer\Html $tableRenderer */
|
||||
$tableRenderer = $this->buildDataTableRenderer($dataTable);
|
||||
$tableRenderer->setTableId($this->request['method']);
|
||||
|
||||
$method = Common::getRequestVar('method', '', 'string', $this->request);
|
||||
|
||||
$tableRenderer->setApiMethod($method);
|
||||
$tableRenderer->setIdSite(Common::getRequestVar('idSite', false, 'int', $this->request));
|
||||
$tableRenderer->setTranslateColumnNames(Common::getRequestVar('translateColumnNames', false, 'int', $this->request));
|
||||
|
||||
return $tableRenderer->render();
|
||||
}
|
||||
|
||||
public function renderArray($array)
|
||||
{
|
||||
return $this->renderDataTable($array);
|
||||
}
|
||||
|
||||
public function sendHeader()
|
||||
{
|
||||
Common::sendHeader('Content-Type: text/html; charset=utf-8', true);
|
||||
}
|
||||
|
||||
}
|
||||
108
www/analytics/plugins/API/Renderer/Json.php
Normal file
108
www/analytics/plugins/API/Renderer/Json.php
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\API\Renderer;
|
||||
|
||||
use Piwik\API\ApiRenderer;
|
||||
use Piwik\Common;
|
||||
use Piwik\DataTable\Renderer;
|
||||
use Piwik\DataTable;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\ProxyHttp;
|
||||
|
||||
/**
|
||||
* API output renderer for JSON.
|
||||
*
|
||||
* **NOTE: This is the old JSON format. It includes bugs that are fixed in the JSON2 API output
|
||||
* format. Please use that format instead of this.**
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
class Json extends ApiRenderer
|
||||
{
|
||||
public function renderSuccess($message)
|
||||
{
|
||||
$result = json_encode(array('result' => 'success', 'message' => $message));
|
||||
return $this->applyJsonpIfNeeded($result);
|
||||
}
|
||||
|
||||
public function renderException($message, \Exception $exception)
|
||||
{
|
||||
$exceptionMessage = str_replace(array("\r\n", "\n"), "", $message);
|
||||
|
||||
$result = json_encode(array('result' => 'error', 'message' => $exceptionMessage));
|
||||
|
||||
return $this->applyJsonpIfNeeded($result);
|
||||
}
|
||||
|
||||
public function renderDataTable($dataTable)
|
||||
{
|
||||
$result = parent::renderDataTable($dataTable);
|
||||
|
||||
return $this->applyJsonpIfNeeded($result);
|
||||
}
|
||||
|
||||
public function renderArray($array)
|
||||
{
|
||||
if (Piwik::isMultiDimensionalArray($array)) {
|
||||
$jsonRenderer = Renderer::factory('json');
|
||||
$jsonRenderer->setTable($array);
|
||||
$result = $jsonRenderer->render();
|
||||
return $this->applyJsonpIfNeeded($result);
|
||||
}
|
||||
|
||||
return $this->renderDataTable($array);
|
||||
}
|
||||
|
||||
public function sendHeader()
|
||||
{
|
||||
if ($this->isJsonp()) {
|
||||
Common::sendHeader('Content-Type: application/javascript; charset=utf-8');
|
||||
} else {
|
||||
Renderer\Json::sendHeaderJSON();
|
||||
}
|
||||
|
||||
ProxyHttp::overrideCacheControlHeaders();
|
||||
}
|
||||
|
||||
private function isJsonp()
|
||||
{
|
||||
$callback = $this->getJsonpCallback();
|
||||
|
||||
if (false === $callback) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return preg_match('/^[0-9a-zA-Z_.]*$/D', $callback) > 0;
|
||||
}
|
||||
|
||||
private function getJsonpCallback()
|
||||
{
|
||||
$jsonCallback = Common::getRequestVar('callback', false, null, $this->request);
|
||||
|
||||
if ($jsonCallback === false) {
|
||||
$jsonCallback = Common::getRequestVar('jsoncallback', false, null, $this->request);
|
||||
}
|
||||
|
||||
return $jsonCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @return string
|
||||
*/
|
||||
private function applyJsonpIfNeeded($str)
|
||||
{
|
||||
if ($this->isJsonp()) {
|
||||
$jsonCallback = $this->getJsonpCallback();
|
||||
$str = $jsonCallback . "(" . $str . ")";
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
33
www/analytics/plugins/API/Renderer/Json2.php
Normal file
33
www/analytics/plugins/API/Renderer/Json2.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\API\Renderer;
|
||||
|
||||
use Piwik\Piwik;
|
||||
|
||||
/**
|
||||
* Correct API output renderer for JSON. Includes bug fixes for bugs in the old JSON API
|
||||
* format.
|
||||
*/
|
||||
class Json2 extends Json
|
||||
{
|
||||
public function renderArray($array)
|
||||
{
|
||||
$result = parent::renderArray($array);
|
||||
|
||||
// if $array is a simple associative array, remove the JSON root array that is added by renderDataTable
|
||||
if (!empty($array)
|
||||
&& Piwik::isAssociativeArray($array)
|
||||
&& !Piwik::isMultiDimensionalArray($array)
|
||||
) {
|
||||
$result = substr($result, 1, strlen($result) - 2);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
77
www/analytics/plugins/API/Renderer/Original.php
Normal file
77
www/analytics/plugins/API/Renderer/Original.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\API\Renderer;
|
||||
|
||||
use Piwik\API\ApiRenderer;
|
||||
use Piwik\Common;
|
||||
|
||||
class Original extends ApiRenderer
|
||||
{
|
||||
public function renderSuccess($message)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function renderException($message, \Exception $exception)
|
||||
{
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
public function renderDataTable($dataTable)
|
||||
{
|
||||
return $this->serializeIfNeeded($dataTable);
|
||||
}
|
||||
|
||||
public function renderArray($array)
|
||||
{
|
||||
return $this->serializeIfNeeded($array);
|
||||
}
|
||||
|
||||
public function renderScalar($scalar)
|
||||
{
|
||||
return $scalar;
|
||||
}
|
||||
|
||||
public function renderObject($object)
|
||||
{
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function renderResource($resource)
|
||||
{
|
||||
return $resource;
|
||||
}
|
||||
|
||||
public function sendHeader()
|
||||
{
|
||||
if ($this->shouldSerialize()) {
|
||||
Common::sendHeader('Content-Type: text/plain; charset=utf-8');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the user requested to serialize the output data (&serialize=1 in the request)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldSerialize()
|
||||
{
|
||||
$serialize = Common::getRequestVar('serialize', 0, 'int', $this->request);
|
||||
|
||||
return !empty($serialize);
|
||||
}
|
||||
|
||||
private function serializeIfNeeded($response)
|
||||
{
|
||||
if ($this->shouldSerialize()) {
|
||||
return serialize($response);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
82
www/analytics/plugins/API/Renderer/Php.php
Normal file
82
www/analytics/plugins/API/Renderer/Php.php
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\API\Renderer;
|
||||
|
||||
use Piwik\API\ApiRenderer;
|
||||
use Piwik\Common;
|
||||
use Piwik\DataTable\Renderer;
|
||||
use Piwik\DataTable;
|
||||
use Piwik\Piwik;
|
||||
|
||||
class Php extends ApiRenderer
|
||||
{
|
||||
public function renderSuccess($message)
|
||||
{
|
||||
$success = array('result' => 'success', 'message' => $message);
|
||||
|
||||
return $this->serializeIfNeeded($success);
|
||||
}
|
||||
|
||||
public function renderException($message, \Exception $exception)
|
||||
{
|
||||
$message = array('result' => 'error', 'message' => $message);
|
||||
|
||||
return $this->serializeIfNeeded($message);
|
||||
}
|
||||
|
||||
public function renderDataTable($dataTable)
|
||||
{
|
||||
/** @var \Piwik\DataTable\Renderer\Php $tableRenderer */
|
||||
$tableRenderer = $this->buildDataTableRenderer($dataTable);
|
||||
|
||||
$tableRenderer->setSerialize($this->shouldSerialize(1));
|
||||
$tableRenderer->setPrettyDisplay(Common::getRequestVar('prettyDisplay', false, 'int', $this->request));
|
||||
|
||||
return $tableRenderer->render();
|
||||
}
|
||||
|
||||
public function renderArray($array)
|
||||
{
|
||||
if (!Piwik::isMultiDimensionalArray($array)) {
|
||||
return $this->renderDataTable($array);
|
||||
}
|
||||
|
||||
if ($this->shouldSerialize(1)) {
|
||||
return serialize($array);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function sendHeader()
|
||||
{
|
||||
Common::sendHeader('Content-Type: text/plain; charset=utf-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the user requested to serialize the output data (&serialize=1 in the request)
|
||||
*
|
||||
* @param mixed $defaultSerializeValue Default value in case the user hasn't specified a value
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldSerialize($defaultSerializeValue)
|
||||
{
|
||||
$serialize = Common::getRequestVar('serialize', $defaultSerializeValue, 'int', $this->request);
|
||||
|
||||
return !empty($serialize);
|
||||
}
|
||||
|
||||
private function serializeIfNeeded($response)
|
||||
{
|
||||
if ($this->shouldSerialize(1)) {
|
||||
return serialize($response);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
51
www/analytics/plugins/API/Renderer/Rss.php
Normal file
51
www/analytics/plugins/API/Renderer/Rss.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\API\Renderer;
|
||||
|
||||
use Piwik\API\ApiRenderer;
|
||||
use Piwik\Common;
|
||||
use Piwik\DataTable\Renderer;
|
||||
use Piwik\DataTable;
|
||||
|
||||
class Rss extends ApiRenderer
|
||||
{
|
||||
|
||||
public function renderException($message, \Exception $exception)
|
||||
{
|
||||
self::sendHeader('plain');
|
||||
|
||||
return 'Error: ' . $message;
|
||||
}
|
||||
|
||||
public function renderDataTable($dataTable)
|
||||
{
|
||||
/** @var \Piwik\DataTable\Renderer\Rss $tableRenderer */
|
||||
$tableRenderer = $this->buildDataTableRenderer($dataTable);
|
||||
|
||||
$method = Common::getRequestVar('method', '', 'string', $this->request);
|
||||
|
||||
$tableRenderer->setApiMethod($method);
|
||||
$tableRenderer->setIdSite(Common::getRequestVar('idSite', false, 'int', $this->request));
|
||||
$tableRenderer->setTranslateColumnNames(Common::getRequestVar('translateColumnNames', false, 'int', $this->request));
|
||||
|
||||
return $tableRenderer->render();
|
||||
}
|
||||
|
||||
public function renderArray($array)
|
||||
{
|
||||
return $this->renderDataTable($array);
|
||||
}
|
||||
|
||||
public function sendHeader($type = "xml")
|
||||
{
|
||||
Common::sendHeader('Content-Type: text/' . $type . '; charset=utf-8');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
24
www/analytics/plugins/API/Renderer/Tsv.php
Normal file
24
www/analytics/plugins/API/Renderer/Tsv.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\API\Renderer;
|
||||
|
||||
use Piwik\Common;
|
||||
use Piwik\DataTable\Renderer;
|
||||
use Piwik\DataTable;
|
||||
|
||||
class Tsv extends Csv
|
||||
{
|
||||
|
||||
public function renderSuccess($message)
|
||||
{
|
||||
Common::sendHeader("Content-Disposition: attachment; filename=piwik-report-export.csv");
|
||||
return "message\t" . $message;
|
||||
}
|
||||
|
||||
}
|
||||
40
www/analytics/plugins/API/Renderer/Xml.php
Normal file
40
www/analytics/plugins/API/Renderer/Xml.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\API\Renderer;
|
||||
|
||||
use Piwik\API\ApiRenderer;
|
||||
use Piwik\Common;
|
||||
use Piwik\DataTable\Renderer;
|
||||
use Piwik\DataTable;
|
||||
|
||||
class Xml extends ApiRenderer
|
||||
{
|
||||
|
||||
public function renderSuccess($message)
|
||||
{
|
||||
return "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" .
|
||||
"<result>\n" .
|
||||
"\t<success message=\"" . $message . "\" />\n" .
|
||||
"</result>";
|
||||
}
|
||||
|
||||
public function renderException($message, \Exception $exception)
|
||||
{
|
||||
return '<?xml version="1.0" encoding="utf-8" ?>' . "\n" .
|
||||
"<result>\n" .
|
||||
"\t<error message=\"" . $message . "\" />\n" .
|
||||
"</result>";
|
||||
}
|
||||
|
||||
public function sendHeader()
|
||||
{
|
||||
Common::sendHeader('Content-Type: text/xml; charset=utf-8');
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue