diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-06-23 07:45:36 +0400 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-06-23 07:45:36 +0400 |
commit | 7e1b5d6b762340cbff1bb928d15815980c7649a7 (patch) | |
tree | e07da179b9e1372866d2349777bd1cc6b4c9e8cf /plugins/Dashboard/Controller.php | |
parent | 999f46479294713104c962bfe7469e9b6e7a4bbf (diff) | |
parent | c98ea06f2cccec81c6ccce49162a583494e44d91 (diff) |
Diffstat (limited to 'plugins/Dashboard/Controller.php')
-rw-r--r-- | plugins/Dashboard/Controller.php | 96 |
1 files changed, 80 insertions, 16 deletions
diff --git a/plugins/Dashboard/Controller.php b/plugins/Dashboard/Controller.php index 863883f6be..bdfe1acf2e 100644 --- a/plugins/Dashboard/Controller.php +++ b/plugins/Dashboard/Controller.php @@ -21,16 +21,12 @@ class Piwik_Dashboard_Controller extends Piwik_Controller $view = Piwik_View::factory($template); $this->setGeneralVariablesView($view); - // layout was JSON.stringified - $layout = html_entity_decode($this->getLayout()); - $layout = str_replace("\\\"", "\"", $layout); - - if(!empty($layout) - && strstr($layout, '[[') == false) { - $layout = "'$layout'"; + $view->availableWidgets = json_encode(Piwik_GetWidgetsList()); + $layout = $this->getLayout(); + if(empty($layout)) { + $layout = $this->getDefaultLayout(); } $view->layout = $layout; - $view->availableWidgets = json_encode(Piwik_GetWidgetsList()); return $view; } @@ -56,7 +52,7 @@ class Piwik_Dashboard_Controller extends Piwik_Controller protected function saveLayoutForUser( $login, $idDashboard, $layout) { $paramsBind = array($login, $idDashboard, $layout, $layout); - Piwik_Query('INSERT INTO '.Piwik::prefixTable('user_dashboard') . + Piwik_Query('INSERT INTO '.Piwik_Common::prefixTable('user_dashboard') . ' (login, iddashboard, layout) VALUES (?,?,?) ON DUPLICATE KEY UPDATE layout=?', @@ -74,7 +70,7 @@ class Piwik_Dashboard_Controller extends Piwik_Controller protected function getLayoutForUser( $login, $idDashboard) { $paramsBind = array($login, $idDashboard); - $return = Piwik_FetchAll('SELECT layout FROM '.Piwik::prefixTable('user_dashboard') . + $return = Piwik_FetchAll('SELECT layout FROM '.Piwik_Common::prefixTable('user_dashboard') . ' WHERE login = ? AND iddashboard = ?', $paramsBind); if(count($return) == 0) { @@ -90,14 +86,14 @@ class Piwik_Dashboard_Controller extends Piwik_Controller */ public function saveLayout() { + $this->checkTokenInUrl(); $layout = Piwik_Common::getRequestVar('layout'); $idDashboard = Piwik_Common::getRequestVar('idDashboard', 1, 'int' ); $currentUser = Piwik::getCurrentUserLogin(); - if($currentUser == 'anonymous') { $session = new Zend_Session_Namespace("Piwik_Dashboard"); - $session->idDashboard = $layout; + $session->dashboardLayout = $layout; } else { @@ -119,16 +115,84 @@ class Piwik_Dashboard_Controller extends Piwik_Controller { $session = new Zend_Session_Namespace("Piwik_Dashboard"); - if(!isset($session->idDashboard)) + if(!isset($session->dashboardLayout)) { return false; } - return $session->idDashboard; + $layout = $session->dashboardLayout; } else { - return $this->getLayoutForUser($currentUser,$idDashboard); - } + $layout = $this->getLayoutForUser($currentUser,$idDashboard); + } + + // layout was JSON.stringified + $layout = html_entity_decode($layout); + $layout = str_replace("\\\"", "\"", $layout); + + // compatibility with the old layout format + if(!empty($layout) + && strstr($layout, '[[') == false) { + $layout = "'$layout'"; + } + $layout = $this->removeDisabledPluginFromLayout($layout); + return $layout; + } + + protected function removeDisabledPluginFromLayout($layout) + { + $layout = str_replace("\n", "", $layout); + // if the json decoding works (ie. new Json format) + // we will only return the widgets that are from enabled plugins + if($layoutObject = json_decode($layout, $assoc = false)) + { + foreach($layoutObject as &$row) + { + if(!is_array($row)) + { + $row = array(); + continue; + } + + foreach($row as $widgetId => $widget) + { + if(isset($widget->parameters->module)) { + $controllerName = $widget->parameters->module; + $controllerAction = $widget->parameters->action; + if(!Piwik_IsWidgetDefined($controllerName, $controllerAction)) + { + unset($row[$widgetId]); + } + } + } + } + $layout = json_encode($layoutObject); + } + return $layout; + } + + protected function getDefaultLayout() + { + $defaultLayout = '[ + [ + {"uniqueId":"widgetVisitsSummarygetEvolutionGraphcolumnsArray","parameters":{"module":"VisitsSummary","action":"getEvolutionGraph","columns":["nb_visits"]}}, + {"uniqueId":"widgetVisitorInterestgetNumberOfVisitsPerVisitDuration","parameters":{"module":"VisitorInterest","action":"getNumberOfVisitsPerVisitDuration"}}, + {"uniqueId":"widgetUserSettingsgetBrowser","parameters":{"module":"UserSettings","action":"getBrowser"}}, + {"uniqueId":"widgetUserCountrygetCountry","parameters":{"module":"UserCountry","action":"getCountry"}}, + {"uniqueId":"widgetExampleFeedburnerfeedburner","parameters":{"module":"ExampleFeedburner","action":"feedburner"}} + ], + [ + {"uniqueId":"widgetReferersgetKeywords","parameters":{"module":"Referers","action":"getKeywords"}}, + {"uniqueId":"widgetReferersgetWebsites","parameters":{"module":"Referers","action":"getWebsites"}} + ], + [ + {"uniqueId":"widgetReferersgetSearchEngines","parameters":{"module":"Referers","action":"getSearchEngines"}}, + {"uniqueId":"widgetVisitTimegetVisitInformationPerServerTime","parameters":{"module":"VisitTime","action":"getVisitInformationPerServerTime"}}, + {"uniqueId":"widgetExampleRssWidgetrssPiwik","parameters":{"module":"ExampleRssWidget","action":"rssPiwik"}} + ] + ]'; + $defaultLayout = $this->removeDisabledPluginFromLayout($defaultLayout); + return $defaultLayout; } } |