Piwik uses this class for all requests that go through **index.php**. Plugins can use it to call controller actions of other plugins. ### Examples **Forwarding controller requests** public function myConfiguredRealtimeMap() { $_GET['changeVisitAlpha'] = false; $_GET['removeOldVisits'] = false; $_GET['showFooterMessage'] = false; return FrontController::getInstance()->dispatch('UserCountryMap', 'realtimeMap'); } **Using other plugin controller actions** public function myPopupWithRealtimeMap() { $_GET['changeVisitAlpha'] = false; $_GET['removeOldVisits'] = false; $_GET['showFooterMessage'] = false; $realtimeMap = FrontController::getInstance()->dispatch('UserCountryMap', 'realtimeMap'); $view = new View('@MyPlugin/myPopupWithRealtimeMap.twig'); $view->realtimeMap = $realtimeMap; return $realtimeMap->render(); } For a detailed explanation, see the documentation here.
Inheritance: extends piwik\Singleton
Example #1
0
 public function dispatch()
 {
     $module = Common::getRequestVar('module', '', 'string');
     $action = Common::getRequestVar('action', '', 'string');
     if ($module == 'CoreUpdater' || $module == 'Proxy' || $module == 'Installation' || $module == 'LanguagesManager' && $action == 'saveLanguage') {
         return;
     }
     $updater = new PiwikCoreUpdater();
     $updates = $updater->getComponentsWithNewVersion(array('core' => Version::VERSION));
     if (!empty($updates)) {
         Filesystem::deleteAllCacheOnUpdate();
     }
     if ($updater->getComponentUpdates() !== null) {
         if (FrontController::shouldRethrowException()) {
             throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n" . "--> Please run the update process first. See documentation: http://piwik.org/docs/update/ \n");
         } elseif ($module === 'API') {
             $outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $_GET + $_POST));
             $response = new ResponseBuilder($outputFormat);
             $e = new Exception('Database Upgrade Required. Your Piwik database is out-of-date, and must be upgraded before you can continue.');
             echo $response->getResponseException($e);
             Common::sendResponseCode(503);
             exit;
         } else {
             Piwik::redirectToModule('CoreUpdater');
         }
     }
 }
Example #2
0
    public static function footerUserCountry(&$out)
    {
        $out = '<div>
			<h2>' . Piwik::translate('Provider_WidgetProviders') . '</h2>';
        $out .= FrontController::getInstance()->fetchDispatch('Provider', 'getProvider');
        $out .= '</div>';
    }
Example #3
0
 /**
  * Execute command like: ./console core:run-scheduled-tasks
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->forceRunAllTasksIfRequested($input);
     FrontController::getInstance()->init();
     API::getInstance()->runScheduledTasks();
     $this->writeSuccessMessage($output, array('Scheduled Tasks executed'));
 }
Example #4
0
    public static function footerVisitsFrequency(&$out)
    {
        $out = '</div>
			<div id="rightcolumn">
			';
        $out .= FrontController::getInstance()->fetchDispatch('VisitorInterest', 'index');
        $out .= '</div>';
    }
Example #5
0
 public function getEcommerceLog($fetch = false)
 {
     $saveGET = $_GET;
     $_GET['segment'] = urlencode('visitEcommerceStatus!=none');
     $_GET['widget'] = 1;
     $output = FrontController::getInstance()->dispatch('Live', 'getVisitorLog', array($fetch));
     $_GET = $saveGET;
     return $output;
 }
Example #6
0
 /**
  * Redirects to Login form with error message.
  * Listens to User.isNotAuthorized hook.
  */
 public function noAccess(Exception $exception)
 {
     $frontController = FrontController::getInstance();
     if (Common::isXmlHttpRequest()) {
         echo $frontController->dispatch('Login', 'ajaxNoAccess', array($exception->getMessage()));
         return;
     }
     echo $frontController->dispatch('Login', 'login', array($exception->getMessage()));
 }
Example #7
0
 /**
  * Testing that getOne does not error out when format=rss, #10407
  *
  * @group Plugins
  */
 public function testWhenRssFormatGetOneDoesNotError()
 {
     $_GET = array('method' => 'MultiSites.getOne', 'idSite' => $this->idSiteAccess, 'period' => 'month', 'date' => 'last10', 'format' => 'rss');
     $output = FrontController::getInstance()->fetchDispatch('API');
     $this->assertContains('<item>', $output);
     $this->assertContains('</rss>', $output);
     $this->assertNotContains('error', $output);
     $_GET = array();
 }
Example #8
0
 private function requestGetAllWithGroups($params)
 {
     $oldGet = $_GET;
     $params['period'] = 'day';
     $params['date'] = '2013-01-23';
     $_GET = $params;
     $sites = FrontController::getInstance()->dispatch('MultiSites', 'getAllWithGroups');
     $_GET = $oldGet;
     return $sites;
 }
 /**
  * Execute command like: ./console core:run-scheduled-tasks
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->forceRunAllTasksIfRequested($input);
     FrontController::getInstance()->init();
     $scheduledTasksResults = API::getInstance()->runScheduledTasks();
     foreach ($scheduledTasksResults as $scheduledTasksResult) {
         $output->writeln(sprintf('<comment>%s</comment> - %s', $scheduledTasksResult['task'], $scheduledTasksResult['output']));
     }
     $this->writeSuccessMessage($output, array('Scheduled Tasks executed'));
 }
Example #10
0
 private function init()
 {
     $this->handleFatalErrors();
     \Piwik\FrontController::createConfigObject();
     if ($this->isDebugModeEnabled()) {
         ErrorHandler::registerErrorHandler();
         ExceptionHandler::setUp();
         Common::printDebug("Debug enabled - Input parameters: ");
         Common::printDebug(var_export($_GET, true));
     }
 }
Example #11
0
 public function showInContext()
 {
     $controllerName = Common::getRequestVar('moduleToLoad');
     $actionName = Common::getRequestVar('actionToLoad', 'index');
     if ($actionName == 'showInContext') {
         throw new Exception("Preventing infinite recursion...");
     }
     $view = $this->getDefaultIndexView();
     $view->content = FrontController::getInstance()->fetchDispatch($controllerName, $actionName);
     return $view->render();
 }
Example #12
0
 protected function _getDashboardView($template)
 {
     $view = new View($template);
     $this->setGeneralVariablesView($view);
     $view->availableWidgets = Common::json_encode(WidgetsList::get());
     $view->availableLayouts = $this->getAvailableLayouts();
     $view->dashboardId = Common::getRequestVar('idDashboard', 1, 'int');
     // get the layout via FrontController so controller events are posted
     $view->dashboardLayout = FrontController::getInstance()->dispatch('Dashboard', 'getDashboardLayout', array($checkToken = false));
     return $view;
 }
Example #13
0
 /**
  * @param $lastError
  * @return mixed|void
  * @throws AuthenticationFailedException
  * @throws Exception
  */
 private static function generateSafeModeOutput($lastError)
 {
     Common::sendResponseCode(500);
     $controller = FrontController::getInstance();
     try {
         $controller->init();
         $message = $controller->dispatch('CorePluginsAdmin', 'safemode', array($lastError));
     } catch (Exception $e) {
         // may fail in safe mode (eg. global.ini.php not found)
         $message = sprintf("Piwik encoutered an error: %s (which lead to: %s)", $lastError['message'], $e->getMessage());
     }
     return $message;
 }
Example #14
0
 /**
  * @param \Exception|null $exception
  */
 public function dispatch($exception = null)
 {
     if ($exception) {
         $message = $exception->getMessage();
     } else {
         $message = '';
     }
     $action = Common::getRequestVar('action', 'welcome', 'string');
     if ($this->isAllowedAction($action)) {
         echo FrontController::getInstance()->dispatch('Installation', $action, array($message));
     } else {
         Piwik::exitWithErrorMessage(Piwik::translate('Installation_NoConfigFound'));
     }
     exit;
 }
 /**
  * Execute command like: ./console core:run-scheduled-tasks
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->forceRunAllTasksIfRequested($input);
     FrontController::getInstance()->init();
     // TODO use dependency injection
     /** @var Scheduler $scheduler */
     $scheduler = StaticContainer::get('Piwik\\Scheduler\\Scheduler');
     $task = $input->getArgument('task');
     if ($task) {
         $this->runSingleTask($scheduler, $task, $output);
     } else {
         $scheduler->run();
     }
     $this->writeSuccessMessage($output, array('Scheduled Tasks executed'));
 }
Example #16
0
 public function iframe()
 {
     Request::reloadAuthUsingTokenAuth();
     $this->init();
     $controllerName = Common::getRequestVar('moduleToWidgetize');
     $actionName = Common::getRequestVar('actionToWidgetize');
     if ($controllerName == 'Dashboard' && $actionName == 'index') {
         $view = new View('@Widgetize/iframe_empty');
     } else {
         $view = new View('@Widgetize/iframe');
     }
     $this->setGeneralVariablesView($view);
     $view->setXFrameOptions('allow');
     $view->content = FrontController::getInstance()->fetchDispatch($controllerName, $actionName);
     return $view->render();
 }
Example #17
0
 public function dispatch()
 {
     $module = Common::getRequestVar('module', '', 'string');
     $action = Common::getRequestVar('action', '', 'string');
     $updater = new PiwikCoreUpdater();
     $updates = $updater->getComponentsWithNewVersion(array('core' => Version::VERSION));
     if (!empty($updates)) {
         Filesystem::deleteAllCacheOnUpdate();
     }
     if ($updater->getComponentUpdates() !== null && $module != 'CoreUpdater' && $module != 'Proxy' && $module != 'Installation' && !($module == 'LanguagesManager' && $action == 'saveLanguage')) {
         if (FrontController::shouldRethrowException()) {
             throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n" . "--> Please run the update process first. See documentation: http://piwik.org/docs/update/ \n");
         } else {
             Piwik::redirectToModule('CoreUpdater');
         }
     }
 }
 /**
  * @param \Exception|null $exception
  */
 public function dispatch($exception = null)
 {
     if ($exception) {
         $message = $exception->getMessage();
     } else {
         $message = '';
     }
     Translate::loadCoreTranslation();
     $step = Common::getRequestVar('action', 'welcome', 'string');
     $controller = $this->getInstallationController();
     $isActionWhiteListed = in_array($step, array('saveLanguage', 'getBaseCss'));
     if (in_array($step, array_keys($controller->getInstallationSteps())) || $isActionWhiteListed) {
         echo FrontController::getInstance()->dispatch('Installation', $step, array($message));
     } else {
         Piwik::exitWithErrorMessage(Piwik::translate('Installation_NoConfigFound'));
     }
     exit;
 }
Example #19
0
 public function iframe()
 {
     Request::reloadAuthUsingTokenAuth();
     $this->init();
     $controllerName = Common::getRequestVar('moduleToWidgetize');
     $actionName = Common::getRequestVar('actionToWidgetize');
     if ($controllerName == 'API') {
         throw new \Exception("Widgetizing API requests is not supported for security reasons. Please change query parameter 'moduleToWidgetize'.");
     }
     if ($controllerName == 'Dashboard' && $actionName == 'index') {
         $view = new View('@Widgetize/iframe_empty');
     } else {
         $view = new View('@Widgetize/iframe');
     }
     $this->setGeneralVariablesView($view);
     $view->setXFrameOptions('allow');
     $view->content = FrontController::getInstance()->fetchDispatch($controllerName, $actionName);
     return $view->render();
 }
Example #20
0
 private function call($id, $url, $params)
 {
     if (!defined('PIWIK_INCLUDE_PATH')) {
         return false;
     }
     if (PIWIK_INCLUDE_PATH === FALSE) {
         return array('result' => 'error', 'message' => __('Could not resolve', 'wp-piwik') . ' &quot;' . htmlentities(self::$settings->getGlobalOption('piwik_path')) . '&quot;: ' . __('realpath() returns false', 'wp-piwik') . '.');
     }
     if (file_exists(PIWIK_INCLUDE_PATH . "/index.php")) {
         require_once PIWIK_INCLUDE_PATH . "/index.php";
     }
     if (file_exists(PIWIK_INCLUDE_PATH . "/core/API/Request.php")) {
         require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";
     }
     if (class_exists('\\Piwik\\Application\\Environment') && !self::$piwikEnvironment) {
         // Piwik 2.14.* compatibility fix
         self::$piwikEnvironment = new \Piwik\Application\Environment(null);
         self::$piwikEnvironment->init();
     }
     if (class_exists('Piwik\\FrontController')) {
         \Piwik\FrontController::getInstance()->init();
     } else {
         return array('result' => 'error', 'message' => __('Class Piwik\\FrontController does not exists.', 'wp-piwik'));
     }
     if (class_exists('Piwik\\API\\Request')) {
         $request = new \Piwik\API\Request($params . '&token_auth=' . self::$settings->getGlobalOption('piwik_token'));
     } else {
         return array('result' => 'error', 'message' => __('Class Piwik\\API\\Request does not exists.', 'wp-piwik'));
     }
     if (isset($request)) {
         $result = $request->process();
     } else {
         $result = null;
     }
     if (!headers_sent()) {
         header("Content-Type: text/html", true);
     }
     $result = $this->unserialize($result);
     if ($GLOBALS['wp-piwik_debug']) {
         self::$debug[$id] = array($params . '&token_auth=...');
     }
     return $result;
 }
Example #21
0
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 * @package Piwik
 */
use Piwik\Error;
use Piwik\ExceptionHandler;
use Piwik\FrontController;
use Piwik\Plugin\ControllerAdmin as PluginControllerAdmin;
PluginControllerAdmin::disableEacceleratorIfEnabled();
if (!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) {
    require_once PIWIK_INCLUDE_PATH . '/core/Error.php';
    Error::setErrorHandler();
    require_once PIWIK_INCLUDE_PATH . '/core/ExceptionHandler.php';
    ExceptionHandler::setUp();
}
FrontController::setUpSafeMode();
if (!defined('PIWIK_ENABLE_DISPATCH')) {
    define('PIWIK_ENABLE_DISPATCH', true);
}
if (PIWIK_ENABLE_DISPATCH) {
    $controller = FrontController::getInstance();
    $controller->init();
    $response = $controller->dispatch();
    if (is_array($response)) {
        var_export($response);
    } elseif (!is_null($response)) {
        echo $response;
    }
}
 public static function triggerSafeModeWhenError()
 {
     $lastError = error_get_last();
     if (!empty($lastError) && $lastError['type'] == E_ERROR) {
         Common::sendResponseCode(500);
         $controller = FrontController::getInstance();
         $controller->init();
         $message = $controller->dispatch('CorePluginsAdmin', 'safemode', array($lastError));
         echo $message;
     }
 }
Example #23
0
 public static function insertMapInLocationReport(&$out)
 {
     $out = '<h2>' . Piwik::translate('UserCountryMap_VisitorMap') . '</h2>';
     $out .= FrontController::getInstance()->fetchDispatch('UserCountryMap', 'visitorMap');
 }
 public static function footerVisitsFrequency(&$out)
 {
     $out .= FrontController::getInstance()->fetchDispatch('VisitorInterest', 'index');
 }
Example #25
0
 public function getEcommerceLog($fetch = false)
 {
     $saveGET = $_GET;
     $filterEcommerce = Common::getRequestVar('filterEcommerce', self::ECOMMERCE_LOG_SHOW_ORDERS, 'int');
     if ($filterEcommerce == self::ECOMMERCE_LOG_SHOW_ORDERS) {
         $segment = urlencode('visitEcommerceStatus==ordered,visitEcommerceStatus==orderedThenAbandonedCart');
     } else {
         $segment = urlencode('visitEcommerceStatus==abandonedCart,visitEcommerceStatus==orderedThenAbandonedCart');
     }
     $_GET['segment'] = $segment;
     $_GET['filterEcommerce'] = $filterEcommerce;
     $_GET['widget'] = 1;
     $output = FrontController::getInstance()->dispatch('Live', 'getVisitorLog', array($fetch));
     $_GET = $saveGET;
     return $output;
 }
Example #26
0
require_once PIWIK_INCLUDE_PATH . '/core/Filesystem.php';
require_once PIWIK_INCLUDE_PATH . '/core/Cookie.php';
session_cache_limiter('nocache');
@date_default_timezone_set('UTC');
if (!defined('PIWIK_ENABLE_TRACKING') || PIWIK_ENABLE_TRACKING) {
    ob_start();
}
if ($GLOBALS['PIWIK_TRACKER_DEBUG'] === true) {
    require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
    require_once PIWIK_INCLUDE_PATH . '/core/Error.php';
    \Piwik\Error::setErrorHandler();
    require_once PIWIK_INCLUDE_PATH . '/core/ExceptionHandler.php';
    \Piwik\ExceptionHandler::setUp();
    $timer = new Timer();
    Common::printDebug("Debug enabled - Input parameters: <br/>" . var_export($_GET, true));
    \Piwik\Tracker\Db::enableProfiling();
    \Piwik\FrontController::createConfigObject();
}
if (!defined('PIWIK_ENABLE_TRACKING') || PIWIK_ENABLE_TRACKING) {
    $process = new Tracker();
    try {
        $process->main();
    } catch (Exception $e) {
        echo "Error:" . $e->getMessage();
    }
    ob_end_flush();
    if ($GLOBALS['PIWIK_TRACKER_DEBUG'] === true) {
        Common::printDebug($_COOKIE);
        Common::printDebug($timer);
    }
}
Example #27
0
 /**
  * Helper method used to redirect the current HTTP request to another module/action.
  * 
  * This function will exit immediately after executing.
  *
  * @param string $moduleToRedirect The plugin to redirect to, eg. `"MultiSites"`.
  * @param string $actionToRedirect Action, eg. `"index"`.
  * @param int|null $websiteId The new idSite query parameter, eg, `1`.
  * @param string|null $defaultPeriod The new period query parameter, eg, `'day'`.
  * @param string|null $defaultDate The new date query parameter, eg, `'today'`.
  * @param array $parameters Other query parameters to append to the URL.
  * @api
  */
 public function redirectToIndex($moduleToRedirect, $actionToRedirect, $websiteId = null, $defaultPeriod = null, $defaultDate = null, $parameters = array())
 {
     $userPreferences = new UserPreferences();
     if (empty($websiteId)) {
         $websiteId = $userPreferences->getDefaultWebsiteId();
     }
     if (empty($defaultDate)) {
         $defaultDate = $userPreferences->getDefaultDate();
     }
     if (empty($defaultPeriod)) {
         $defaultPeriod = $userPreferences->getDefaultPeriod();
     }
     $parametersString = '';
     if (!empty($parameters)) {
         $parametersString = '&' . Url::getQueryStringFromParameters($parameters);
     }
     if ($websiteId) {
         $url = "index.php?module=" . $moduleToRedirect . "&action=" . $actionToRedirect . "&idSite=" . $websiteId . "&period=" . $defaultPeriod . "&date=" . $defaultDate . $parametersString;
         Url::redirectToUrl($url);
         exit;
     }
     if (Piwik::hasUserSuperUserAccess()) {
         Piwik_ExitWithMessage("Error: no website was found in this Piwik installation.\n\t\t\t<br />Check the table '" . Common::prefixTable('site') . "' in your database, it should contain your Piwik websites.", false, true);
     }
     $currentLogin = Piwik::getCurrentUserLogin();
     if (!empty($currentLogin) && $currentLogin != 'anonymous') {
         $emails = implode(',', Piwik::getAllSuperUserAccessEmailAddresses());
         $errorMessage = sprintf(Piwik::translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:" . $emails . "?subject=Access to Piwik for user {$currentLogin}'>", "</a>");
         $errorMessage .= "<br /><br />&nbsp;&nbsp;&nbsp;<b><a href='index.php?module=" . Registry::get('auth')->getName() . "&amp;action=logout'>&rsaquo; " . Piwik::translate('General_Logout') . "</a></b><br />";
         Piwik_ExitWithMessage($errorMessage, false, true);
     }
     echo FrontController::getInstance()->dispatch(Piwik::getLoginPluginName(), false);
     exit;
 }
Example #28
0
 /**
  * Redirects to Login form with error message.
  * Listens to User.isNotAuthorized hook.
  */
 public function noAccess(Exception $exception)
 {
     $exceptionMessage = $exception->getMessage();
     echo FrontController::getInstance()->dispatch('Login', 'login', array($exceptionMessage));
 }
Example #29
0
 /** Creates two dashboards that split the widgets up into different groups. */
 public function setupDashboards()
 {
     $dashboardColumnCount = 3;
     $dashboardCount = 4;
     $layout = array();
     for ($j = 0; $j != $dashboardColumnCount; ++$j) {
         $layout[] = array();
     }
     $dashboards = array();
     for ($i = 0; $i != $dashboardCount; ++$i) {
         $dashboards[] = $layout;
     }
     $oldGet = $_GET;
     $_GET['idSite'] = 1;
     $_GET['token_auth'] = Fixture::getTokenAuth();
     // collect widgets & sort them so widget order is not important
     $allWidgets = array();
     foreach (WidgetsList::get() as $category => $widgets) {
         $allWidgets = array_merge($allWidgets, $widgets);
     }
     usort($allWidgets, function ($lhs, $rhs) {
         return strcmp($lhs['uniqueId'], $rhs['uniqueId']);
     });
     $widgetsPerDashboard = ceil(count($allWidgets) / $dashboardCount);
     // group widgets so they will be spread out across 3 dashboards
     $groupedWidgets = array();
     $dashboard = 0;
     foreach ($allWidgets as $widget) {
         if ($widget['uniqueId'] == 'widgetSEOgetRank' || $widget['uniqueId'] == 'widgetReferrersgetKeywordsForPage' || $widget['uniqueId'] == 'widgetLivegetVisitorProfilePopup' || $widget['uniqueId'] == 'widgetActionsgetPageTitles' || strpos($widget['uniqueId'], 'widgetExample') === 0) {
             continue;
         }
         $widgetEntry = array('uniqueId' => $widget['uniqueId'], 'parameters' => $widget['parameters']);
         // dashboard images must have height of less than 4000px to avoid odd discoloration of last line of image
         $widgetEntry['parameters']['filter_limit'] = 5;
         $groupedWidgets[$dashboard][] = $widgetEntry;
         if (count($groupedWidgets[$dashboard]) >= $widgetsPerDashboard) {
             $dashboard = $dashboard + 1;
         }
         // sanity check
         if ($dashboard >= $dashboardCount) {
             throw new Exception("Unexpected error: Incorrect dashboard widget placement logic. Something's wrong w/ the code.");
         }
     }
     // distribute widgets in each dashboard
     $column = 0;
     foreach ($groupedWidgets as $dashboardIndex => $dashboardWidgets) {
         foreach ($dashboardWidgets as $widget) {
             $column = ($column + 1) % $dashboardColumnCount;
             $dashboards[$dashboardIndex][$column][] = $widget;
         }
     }
     foreach ($dashboards as $id => $layout) {
         if ($id == 0) {
             $_GET['name'] = self::makeXssContent('dashboard name' . $id);
         } else {
             $_GET['name'] = 'dashboard name' . $id;
         }
         $_GET['layout'] = json_encode($layout);
         $_GET['idDashboard'] = $id + 1;
         FrontController::getInstance()->fetchDispatch('Dashboard', 'saveLayout');
     }
     // create empty dashboard
     $dashboard = array(array(array('uniqueId' => "widgetVisitsSummarygetEvolutionGraphcolumnsArray", 'parameters' => array('module' => 'VisitsSummary', 'action' => 'getEvolutionGraph', 'columns' => 'nb_visits'))), array(), array());
     $_GET['name'] = 'D4';
     $_GET['layout'] = json_encode($dashboard);
     $_GET['idDashboard'] = 5;
     $_GET['idSite'] = 2;
     FrontController::getInstance()->fetchDispatch('Dashboard', 'saveLayout');
     $_GET = $oldGet;
 }
Example #30
0
 /**
  * Helper method used to redirect the current HTTP request to another module/action.
  *
  * This function will exit immediately after executing.
  *
  * @param string $moduleToRedirect The plugin to redirect to, eg. `"MultiSites"`.
  * @param string $actionToRedirect Action, eg. `"index"`.
  * @param int|null $websiteId The new idSite query parameter, eg, `1`.
  * @param string|null $defaultPeriod The new period query parameter, eg, `'day'`.
  * @param string|null $defaultDate The new date query parameter, eg, `'today'`.
  * @param array $parameters Other query parameters to append to the URL.
  * @api
  */
 public function redirectToIndex($moduleToRedirect, $actionToRedirect, $websiteId = null, $defaultPeriod = null, $defaultDate = null, $parameters = array())
 {
     try {
         $this->doRedirectToUrl($moduleToRedirect, $actionToRedirect, $websiteId, $defaultPeriod, $defaultDate, $parameters);
     } catch (Exception $e) {
         // no website ID to default to, so could not redirect
     }
     if (Piwik::hasUserSuperUserAccess()) {
         Piwik_ExitWithMessage("Error: no website was found in this Piwik installation.\n\t\t\t<br />Check the table '" . Common::prefixTable('site') . "' in your database, it should contain your Piwik websites.", false, true);
     }
     if (!Piwik::isUserIsAnonymous()) {
         $emails = implode(',', Piwik::getAllSuperUserAccessEmailAddresses());
         $errorMessage = sprintf(Piwik::translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:" . $emails . "?subject=Access to Piwik for user {$currentLogin}'>", "</a>");
         $errorMessage .= "<br /><br />&nbsp;&nbsp;&nbsp;<b><a href='index.php?module=" . Registry::get('auth')->getName() . "&amp;action=logout'>&rsaquo; " . Piwik::translate('General_Logout') . "</a></b><br />";
         Piwik_ExitWithMessage($errorMessage, false, true);
     }
     echo FrontController::getInstance()->dispatch(Piwik::getLoginPluginName(), false);
     exit;
 }