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
|
||||
|
|
@ -14,6 +14,7 @@ use Piwik\Piwik;
|
|||
use Piwik\Session\SessionNamespace;
|
||||
use Piwik\View;
|
||||
use Piwik\WidgetsList;
|
||||
use Piwik\FrontController;
|
||||
|
||||
/**
|
||||
* Dashboard Controller
|
||||
|
|
@ -38,11 +39,14 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
$view = new View($template);
|
||||
$this->setGeneralVariablesView($view);
|
||||
|
||||
$view->availableWidgets = Common::json_encode(WidgetsList::get());
|
||||
$view->availableWidgets = json_encode(WidgetsList::get());
|
||||
$view->availableLayouts = $this->getAvailableLayouts();
|
||||
|
||||
$view->dashboardId = Common::getRequestVar('idDashboard', 1, 'int');
|
||||
$view->dashboardLayout = $this->getLayout($view->dashboardId);
|
||||
|
||||
// get the layout via FrontController so controller events are posted
|
||||
$view->dashboardLayout = FrontController::getInstance()->dispatch('Dashboard', 'getDashboardLayout',
|
||||
array($checkToken = false));
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
|
@ -66,35 +70,25 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
return $view->render();
|
||||
}
|
||||
|
||||
public function getDashboardSettingsControl()
|
||||
{
|
||||
$view = new DashboardManagerControl();
|
||||
$result = $view->render();
|
||||
|
||||
if (Common::getRequestVar('includeWidgetFactory', false)) {
|
||||
$factoryTemplateView = new View("@Dashboard/_widgetFactoryTemplate");
|
||||
$result .= $factoryTemplateView->render();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getAvailableWidgets()
|
||||
{
|
||||
$this->checkTokenInUrl();
|
||||
|
||||
Json::sendHeaderJSON();
|
||||
return Common::json_encode(WidgetsList::get());
|
||||
return json_encode(WidgetsList::get());
|
||||
}
|
||||
|
||||
public function getDashboardLayout()
|
||||
public function getDashboardLayout($checkToken = true)
|
||||
{
|
||||
$this->checkTokenInUrl();
|
||||
if ($checkToken) {
|
||||
$this->checkTokenInUrl();
|
||||
}
|
||||
|
||||
$idDashboard = Common::getRequestVar('idDashboard', 1, 'int');
|
||||
|
||||
$layout = $this->getLayout($idDashboard);
|
||||
|
||||
Json::sendHeaderJSON();
|
||||
return $layout;
|
||||
}
|
||||
|
||||
|
|
@ -111,38 +105,13 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
$session->dashboardLayout = $layout;
|
||||
$session->setExpirationSeconds(1800);
|
||||
} else {
|
||||
$this->saveLayoutForUser(Piwik::getCurrentUserLogin(), $idDashboard, $layout);
|
||||
$this->getModel()->updateLayoutForUser(Piwik::getCurrentUserLogin(), $idDashboard, $layout);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Records the layout in the DB for the given user.
|
||||
*
|
||||
* @param string $login
|
||||
* @param int $idDashboard
|
||||
* @param string $layout
|
||||
*/
|
||||
protected function saveLayoutForUser($login, $idDashboard, $layout)
|
||||
private function getModel()
|
||||
{
|
||||
$paramsBind = array($login, $idDashboard, $layout, $layout);
|
||||
$query = sprintf('INSERT INTO %s (login, iddashboard, layout) VALUES (?,?,?) ON DUPLICATE KEY UPDATE layout=?',
|
||||
Common::prefixTable('user_dashboard'));
|
||||
Db::query($query, $paramsBind);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the name of a dashboard
|
||||
*
|
||||
* @param string $login
|
||||
* @param int $idDashboard
|
||||
* @param string $name
|
||||
*/
|
||||
protected function updateDashboardName($login, $idDashboard, $name)
|
||||
{
|
||||
$paramsBind = array($name, $login, $idDashboard);
|
||||
$query = sprintf('UPDATE %s SET name = ? WHERE login = ? AND iddashboard = ?',
|
||||
Common::prefixTable('user_dashboard'));
|
||||
Db::query($query, $paramsBind);
|
||||
return new Model();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -160,9 +129,7 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
|
||||
// first layout can't be removed
|
||||
if ($idDashboard != 1) {
|
||||
$query = sprintf('DELETE FROM %s WHERE iddashboard = ? AND login = ?',
|
||||
Common::prefixTable('user_dashboard'));
|
||||
Db::query($query, array($idDashboard, Piwik::getCurrentUserLogin()));
|
||||
$this->getModel()->deleteDashboardForUser($idDashboard, Piwik::getCurrentUserLogin());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -178,11 +145,11 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
return '[]';
|
||||
}
|
||||
|
||||
$login = Piwik::getCurrentUserLogin();
|
||||
$login = Piwik::getCurrentUserLogin();
|
||||
$dashboards = $this->dashboard->getAllDashboards($login);
|
||||
|
||||
Json::sendHeaderJSON();
|
||||
return Common::json_encode($dashboards);
|
||||
return json_encode($dashboards);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -196,36 +163,20 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
if (Piwik::isUserIsAnonymous()) {
|
||||
return '0';
|
||||
}
|
||||
$user = Piwik::getCurrentUserLogin();
|
||||
$nextId = $this->getNextIdDashboard($user);
|
||||
|
||||
$name = urldecode(Common::getRequestVar('name', '', 'string'));
|
||||
$type = urldecode(Common::getRequestVar('type', 'default', 'string'));
|
||||
$name = urldecode(Common::getRequestVar('name', '', 'string'));
|
||||
$type = urldecode(Common::getRequestVar('type', 'default', 'string'));
|
||||
$layout = '{}';
|
||||
$login = Piwik::getCurrentUserLogin();
|
||||
|
||||
if ($type == 'default') {
|
||||
$layout = $this->dashboard->getDefaultLayout();
|
||||
}
|
||||
|
||||
$query = sprintf('INSERT INTO %s (login, iddashboard, name, layout) VALUES (?, ?, ?, ?)',
|
||||
Common::prefixTable('user_dashboard'));
|
||||
Db::query($query, array($user, $nextId, $name, $layout));
|
||||
$nextId = $this->getModel()->createNewDashboardForUser($login, $name, $layout);
|
||||
|
||||
Json::sendHeaderJSON();
|
||||
return Common::json_encode($nextId);
|
||||
}
|
||||
|
||||
private function getNextIdDashboard($login)
|
||||
{
|
||||
$nextIdQuery = sprintf('SELECT MAX(iddashboard)+1 FROM %s WHERE login = ?',
|
||||
Common::prefixTable('user_dashboard'));
|
||||
$nextId = Db::fetchOne($nextIdQuery, array($login));
|
||||
|
||||
if (empty($nextId)) {
|
||||
$nextId = 1;
|
||||
return $nextId;
|
||||
}
|
||||
return $nextId;
|
||||
return json_encode($nextId);
|
||||
}
|
||||
|
||||
public function copyDashboardToUser()
|
||||
|
|
@ -235,21 +186,19 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
if (!Piwik::hasUserSuperUserAccess()) {
|
||||
return '0';
|
||||
}
|
||||
|
||||
$login = Piwik::getCurrentUserLogin();
|
||||
$name = urldecode(Common::getRequestVar('name', '', 'string'));
|
||||
$user = urldecode(Common::getRequestVar('user', '', 'string'));
|
||||
$name = urldecode(Common::getRequestVar('name', '', 'string'));
|
||||
$user = urldecode(Common::getRequestVar('user', '', 'string'));
|
||||
$idDashboard = Common::getRequestVar('dashboardId', 0, 'int');
|
||||
|
||||
$layout = $this->dashboard->getLayoutForUser($login, $idDashboard);
|
||||
|
||||
if ($layout !== false) {
|
||||
$nextId = $this->getNextIdDashboard($user);
|
||||
|
||||
$query = sprintf('INSERT INTO %s (login, iddashboard, name, layout) VALUES (?, ?, ?, ?)',
|
||||
Common::prefixTable('user_dashboard'));
|
||||
Db::query($query, array($user, $nextId, $name, $layout));
|
||||
$nextId = $this->getModel()->createNewDashboardForUser($user, $name, $layout);
|
||||
|
||||
Json::sendHeaderJSON();
|
||||
return Common::json_encode($nextId);
|
||||
return json_encode($nextId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -262,17 +211,19 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
{
|
||||
$this->checkTokenInUrl();
|
||||
|
||||
$layout = Common::unsanitizeInputValue(Common::getRequestVar('layout'));
|
||||
$layout = Common::unsanitizeInputValue(Common::getRequestVar('layout'));
|
||||
$layout = strip_tags($layout);
|
||||
$idDashboard = Common::getRequestVar('idDashboard', 1, 'int');
|
||||
$name = Common::getRequestVar('name', '', 'string');
|
||||
$name = Common::getRequestVar('name', '', 'string');
|
||||
|
||||
if (Piwik::isUserIsAnonymous()) {
|
||||
$session = new SessionNamespace("Dashboard");
|
||||
$session->dashboardLayout = $layout;
|
||||
$session->setExpirationSeconds(1800);
|
||||
} else {
|
||||
$this->saveLayoutForUser(Piwik::getCurrentUserLogin(), $idDashboard, $layout);
|
||||
$this->getModel()->updateLayoutForUser(Piwik::getCurrentUserLogin(), $idDashboard, $layout);
|
||||
if (!empty($name)) {
|
||||
$this->updateDashboardName(Piwik::getCurrentUserLogin(), $idDashboard, $name);
|
||||
$this->getModel()->updateDashboardName(Piwik::getCurrentUserLogin(), $idDashboard, $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -286,10 +237,8 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
|
||||
if (Piwik::hasUserSuperUserAccess()) {
|
||||
$layout = Common::unsanitizeInputValue(Common::getRequestVar('layout'));
|
||||
$paramsBind = array('', '1', $layout, $layout);
|
||||
$query = sprintf('INSERT INTO %s (login, iddashboard, layout) VALUES (?,?,?) ON DUPLICATE KEY UPDATE layout=?',
|
||||
Common::prefixTable('user_dashboard'));
|
||||
Db::query($query, $paramsBind);
|
||||
$layout = strip_tags($layout);
|
||||
$this->getModel()->createOrUpdateDashboard('', '1', $layout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -342,4 +291,3 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue