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'); } } }
public function getSparklines() { $idGoal = Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER; $view = new View('@Ecommerce/getSparklines'); $view->onlyConversionOverview = false; $view->conversionsOverViewEnabled = true; if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) { $goalDefinition['name'] = $this->translator->translate('Goals_Ecommerce'); $goalDefinition['allow_multiple'] = true; } else { $goals = GoalsApi::getInstance()->getGoals($this->idSite); if (!isset($goals[$idGoal])) { Piwik::redirectToModule('Goals', 'index', array('idGoal' => null)); } $goalDefinition = $goals[$idGoal]; } $this->setGeneralVariablesView($view); $goal = $this->getMetricsForGoal($idGoal); foreach ($goal as $name => $value) { $view->{$name} = $value; } if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) { $goal = $this->getMetricsForGoal(Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART); foreach ($goal as $name => $value) { $name = 'cart_' . $name; $view->{$name} = $value; } } $view->idGoal = $idGoal; $view->goalAllowMultipleConversionsPerVisit = $goalDefinition['allow_multiple']; return $view->render(); }
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'); } } }
protected function getGoalReportView($idGoal = false) { $view = new View('@Goals/getGoalReportView'); if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) { $goalDefinition['name'] = $this->translator->translate('Goals_Ecommerce'); $goalDefinition['allow_multiple'] = true; $ecommerce = $view->ecommerce = true; } else { if (!isset($this->goals[$idGoal])) { Piwik::redirectToModule('Goals', 'index', array('idGoal' => null)); } $goalDefinition = $this->goals[$idGoal]; } $this->setGeneralVariablesView($view); $goal = $this->getMetricsForGoal($idGoal); foreach ($goal as $name => $value) { $view->{$name} = $value; } if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) { $goal = $this->getMetricsForGoal(Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART); foreach ($goal as $name => $value) { $name = 'cart_' . $name; $view->{$name} = $value; } } $view->showHeadline = false; $view->idGoal = $idGoal; $view->goalName = $goalDefinition['name']; $view->goalAllowMultipleConversionsPerVisit = $goalDefinition['allow_multiple']; $view->graphEvolution = $this->getEvolutionGraph(array(), $idGoal, array('nb_conversions')); $view->nameGraphEvolution = 'Goals.getEvolutionGraph' . $idGoal; $view->topDimensions = $this->getTopDimensions($idGoal); $goalMetrics = Request::processRequest('Goals.get', array('idGoal' => $idGoal)); // conversion rate for new and returning visitors $view->conversion_rate_returning = $this->formatConversionRate($goalMetrics, 'conversion_rate_returning_visit'); $view->conversion_rate_new = $this->formatConversionRate($goalMetrics, 'conversion_rate_new_visit'); $view->goalReportsByDimension = $this->getGoalReportsByDimensionTable($view->nb_conversions, isset($ecommerce), !empty($view->cart_nb_conversions)); return $view; }
/** * Logout current user * * @param none * @return void */ public function logout() { self::clearSession(); $logoutUrl = @Config::getInstance()->General['login_logout_url']; if (empty($logoutUrl)) { Piwik::redirectToModule('CoreHome'); } else { Url::redirectToUrl($logoutUrl); } }
public function index() { $language = Common::getRequestVar('language', ''); if (!empty($language)) { LanguagesManager::setLanguageForSession($language); } try { return $this->runUpdaterAndExit(); } catch (NoUpdatesFoundException $e) { Piwik::redirectToModule('CoreHome'); } }
/** * Redirect to next step * * @param string $currentStep Current step * @return void */ private function redirectToNextStep($currentStep, $parameters = array()) { $steps = array_keys($this->steps); $nextStep = $steps[1 + array_search($currentStep, $steps)]; Piwik::redirectToModule('Installation', $nextStep, $parameters); }
public function setIgnoreCookie() { Piwik::checkUserHasSomeViewAccess(); Piwik::checkUserIsNotAnonymous(); $salt = Common::getRequestVar('ignoreSalt', false, 'string'); if ($salt !== $this->getIgnoreCookieSalt()) { throw new Exception("Not authorized"); } IgnoreCookie::setIgnoreCookie(); Piwik::redirectToModule('UsersManager', 'userSettings', array('token_auth' => false)); }
protected function getGoalReportView($idGoal = false) { $view = new View('@Goals/getGoalReportView'); if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) { $goalDefinition['name'] = Piwik::translate('Goals_Ecommerce'); $goalDefinition['allow_multiple'] = true; $ecommerce = $view->ecommerce = true; } else { if (!isset($this->goals[$idGoal])) { Piwik::redirectToModule('Goals', 'index', array('idGoal' => null)); } $goalDefinition = $this->goals[$idGoal]; } $this->setGeneralVariablesView($view); $goal = $this->getMetricsForGoal($idGoal); foreach ($goal as $name => $value) { $view->{$name} = $value; } if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) { $goal = $this->getMetricsForGoal(Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART); foreach ($goal as $name => $value) { $name = 'cart_' . $name; $view->{$name} = $value; } } $view->idGoal = $idGoal; $view->goalName = $goalDefinition['name']; $view->goalAllowMultipleConversionsPerVisit = $goalDefinition['allow_multiple']; $view->graphEvolution = $this->getEvolutionGraph(true, array('nb_conversions'), $idGoal); $view->nameGraphEvolution = 'Goals.getEvolutionGraph' . $idGoal; $view->topDimensions = $this->getTopDimensions($idGoal); // conversion rate for new and returning visitors $segment = \Piwik\Plugins\VisitFrequency\API::RETURNING_VISITOR_SEGMENT; $conversionRateReturning = API::getInstance()->getConversionRate($this->idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), $segment, $idGoal); $view->conversion_rate_returning = $this->formatConversionRate($conversionRateReturning); $segment = 'visitorType==new'; $conversionRateNew = API::getInstance()->getConversionRate($this->idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), $segment, $idGoal); $view->conversion_rate_new = $this->formatConversionRate($conversionRateNew); $view->goalReportsByDimension = $this->getGoalReportsByDimensionTable($view->nb_conversions, isset($ecommerce), !empty($view->cart_nb_conversions)); return $view; }
protected function runUpdaterAndExit() { $updater = new Updater(); $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater); if (empty($componentsWithUpdateFile)) { Piwik::redirectToModule('CoreHome'); } SettingsServer::setMaxExecutionTime(0); $cli = Common::isPhpCliMode() ? '_cli' : ''; $welcomeTemplate = '@CoreUpdater/runUpdaterAndExit_welcome' . $cli; $doneTemplate = '@CoreUpdater/runUpdaterAndExit_done' . $cli; $viewWelcome = new View($welcomeTemplate); $viewDone = new View($doneTemplate); if (Common::isPhpCliMode()) { $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile); $output = $viewWelcome->render(); if (!$this->coreError && Piwik::getModule() == 'CoreUpdater') { $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile); $output .= $viewDone->render(); } return $output; } else { if (Common::getRequestVar('updateCorePlugins', 0, 'integer') == 1) { $this->warningMessages = array(); $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile); $this->redirectToDashboardWhenNoError($updater); return $viewDone->render(); } else { $viewWelcome->queries = $updater->getSqlQueriesToExecute(); $viewWelcome->isMajor = $updater->hasMajorDbUpdate(); $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile); return $viewWelcome->render(); } } exit; }
protected function setDateTodayIfWebsiteCreatedToday() { $date = Common::getRequestVar('date', false); if ($date == 'today' || Common::getRequestVar('period', false) == 'range') { return; } $websiteId = Common::getRequestVar('idSite', false, 'int'); if ($websiteId) { $website = new Site($websiteId); $datetimeCreationDate = $website->getCreationDate()->getDatetime(); $creationDateLocalTimezone = Date::factory($datetimeCreationDate, $website->getTimezone())->toString('Y-m-d'); $todayLocalTimezone = Date::factory('now', $website->getTimezone())->toString('Y-m-d'); if ($creationDateLocalTimezone == $todayLocalTimezone) { Piwik::redirectToModule('CoreHome', 'index', array('date' => 'today', 'idSite' => $websiteId, 'period' => Common::getRequestVar('period'))); } } }
public function setIgnoreCookie() { Piwik::checkUserHasSomeViewAccess(); Piwik::checkUserIsNotAnonymous(); $this->checkTokenInUrl(); IgnoreCookie::setIgnoreCookie(); Piwik::redirectToModule('UsersManager', 'userSettings', array('token_auth' => false)); }
/** * Redirect to next step * * @param string $currentStep Current step * @return void */ protected function redirectToNextStep($currentStep) { $steps = array_keys($this->steps); $this->session->currentStepDone = $currentStep; $nextStep = $steps[1 + array_search($currentStep, $steps)]; Piwik::redirectToModule('Installation', $nextStep); }
/** * Logout current user * * @param none * @return void */ public function logout() { Piwik::postEvent('Login.logout', array(Piwik::getCurrentUserLogin())); self::clearSession(); $logoutUrl = @Config::getInstance()->General['login_logout_url']; if (empty($logoutUrl)) { Piwik::redirectToModule('CoreHome'); } else { Url::redirectToUrl($logoutUrl); } }