update Piwik to version 2.16 (fixes #91)

This commit is contained in:
oliver 2016-04-10 18:55:57 +02:00
commit d885a4baa9
5833 changed files with 418860 additions and 226988 deletions

View file

@ -0,0 +1,141 @@
<?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\Http;
use DI\FactoryInterface;
use Exception;
use Piwik\Plugin\Controller;
use Piwik\Plugin\Report;
use Piwik\Plugin\Widgets;
/**
* Resolves the controller that will handle the request.
*
* A controller is a PHP callable.
*/
class ControllerResolver
{
/**
* @var FactoryInterface
*/
private $abstractFactory;
public function __construct(FactoryInterface $abstractFactory)
{
$this->abstractFactory = $abstractFactory;
}
/**
* @param string $module
* @param string|null $action
* @param array $parameters
* @throws Exception Controller not found.
* @return callable The controller is a PHP callable.
*/
public function getController($module, $action, array &$parameters)
{
$controller = $this->createPluginController($module, $action);
if ($controller) {
return $controller;
}
$controller = $this->createWidgetController($module, $action, $parameters);
if ($controller) {
return $controller;
}
$controller = $this->createReportController($module, $action, $parameters);
if ($controller) {
return $controller;
}
$controller = $this->createReportMenuController($module, $action, $parameters);
if ($controller) {
return $controller;
}
throw new Exception(sprintf("Action '%s' not found in the module '%s'", $action, $module));
}
private function createPluginController($module, $action)
{
$controllerClass = "Piwik\\Plugins\\$module\\Controller";
if (!class_exists($controllerClass)) {
return null;
}
/** @var $controller Controller */
$controller = $this->abstractFactory->make($controllerClass);
$action = $action ?: $controller->getDefaultAction();
if (!is_callable(array($controller, $action))) {
return null;
}
return array($controller, $action);
}
private function createWidgetController($module, $action, array &$parameters)
{
$widget = Widgets::factory($module, $action);
if (!$widget) {
return null;
}
$parameters['widget'] = $widget;
$parameters['method'] = $action;
return array($this->createCoreHomeController(), 'renderWidget');
}
private function createReportController($module, $action, array &$parameters)
{
$report = Report::factory($module, $action);
if (!$report) {
return null;
}
$parameters['report'] = $report;
return array($this->createCoreHomeController(), 'renderReportWidget');
}
private function createReportMenuController($module, $action, array &$parameters)
{
if (!$this->isReportMenuAction($action)) {
return null;
}
$action = lcfirst(substr($action, 4)); // menuGetPageUrls => getPageUrls
$report = Report::factory($module, $action);
if (!$report) {
return null;
}
$parameters['report'] = $report;
return array($this->createCoreHomeController(), 'renderReportMenu');
}
private function isReportMenuAction($action)
{
$startsWithMenu = (Report::PREFIX_ACTION_IN_MENU === substr($action, 0, strlen(Report::PREFIX_ACTION_IN_MENU)));
return !empty($action) && $startsWithMenu;
}
private function createCoreHomeController()
{
return $this->abstractFactory->make('Piwik\Plugins\CoreHome\Controller');
}
}

View file

@ -0,0 +1,39 @@
<?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\Http;
use Piwik\Url;
/**
* Router
*/
class Router
{
/**
* Filters some malformed URL by suggesting to redirect them.
*
* E.g. /index.php/.html?... can be interpreted as HTML by old browsers
* even though the Content-Type says JSON.
* @link https://github.com/piwik/piwik/issues/6156
*
* @param string $url The URL to filter.
*
* @return string|null If not null, then the application should redirect to that URL.
*/
public function filterUrl($url)
{
$path = parse_url($url, PHP_URL_PATH);
if (strpos($path, 'index.php/') !== false) {
return preg_replace('#index\.php/([^\?]*)#', 'index.php', $url, 1);
}
return null;
}
}