Example #1
0
 public function configureTopMenu(MenuTop $menu)
 {
     $userPreferences = new UserPreferences();
     $idSite = $userPreferences->getDefaultWebsiteId();
     $tooltip = Piwik::translate('Dashboard_TopLinkTooltip', Site::getNameFor($idSite));
     $urlParams = array('module' => 'CoreHome', 'action' => 'index', 'idSite' => $idSite);
     $menu->add('Dashboard_Dashboard', null, $urlParams, true, 1, $tooltip);
 }
Example #2
0
 public function configureTopMenu(MenuTop $menu)
 {
     $userPreferences = new UserPreferences();
     $idSite = $userPreferences->getDefaultWebsiteId();
     $tooltip = Piwik::translate('Dashboard_TopLinkTooltip', Site::getNameFor($idSite));
     $urlParams = $this->urlForModuleActionWithDefaultUserParams('CoreHome', 'index');
     $menu->addItem('Dashboard_Dashboard', null, $urlParams, 1, $tooltip);
 }
Example #3
0
File: Menu.php Project: piwik/piwik
 public function configureAdminMenu(MenuAdmin $menu)
 {
     $userPreferences = new UserPreferences();
     $idSite = $this->getIdSite($userPreferences->getDefaultWebsiteId());
     if (Piwik::isUserHasAdminAccess($idSite)) {
         $menu->addMeasurableItem('Goals_Goals', $this->urlForAction('manage', array('idSite' => $idSite)), 40);
     }
 }
Example #4
0
File: Menu.php Project: piwik/piwik
 public function configureAdminMenu(MenuAdmin $menu)
 {
     $userPreferences = new UserPreferences();
     $default = $userPreferences->getDefaultWebsiteId();
     $idSite = Common::getRequestVar('idSite', $default, 'int');
     if (Piwik::isUserHasAdminAccess($idSite)) {
         $menu->addDiagnosticItem('Custom Variables', $this->urlForAction('manage'), $orderId = 20);
     }
 }
Example #5
0
 public function configureUserMenu(MenuUser $menu)
 {
     $userPreferences = new UserPreferences();
     $default = $userPreferences->getDefaultWebsiteId();
     $idSite = Common::getRequestVar('idSite', $default, 'int');
     if (Piwik::isUserHasAdminAccess($idSite)) {
         $menu->addManageItem('CustomDimensions_CustomDimensions', $this->urlForAction('manage'), $orderId = 16);
     }
 }
 public function test_getDefaultDate_ShouldOnlyReturnDateInAllowedPeriods()
 {
     // Only allow for week period
     Config::getInstance()->General['enabled_periods_UI'] = 'day';
     Config::getInstance()->General['default_period'] = 'day';
     $this->setDefaultDate('last7');
     $this->assertEquals('yesterday', $this->userPreferences->getDefaultDate());
 }
Example #7
0
 /**
  * @return array
  */
 private function loadCustomDateRangeToPreProcess()
 {
     $customDateRangesToProcessForSites = array();
     // For all users who have selected this website to load by default,
     // we load the default period/date that will be loaded for this user
     // and make sure it's pre-archived
     $allUsersPreferences = APIUsersManager::getInstance()->getAllUsersPreferences(array(APIUsersManager::PREFERENCE_DEFAULT_REPORT_DATE, APIUsersManager::PREFERENCE_DEFAULT_REPORT));
     foreach ($allUsersPreferences as $userLogin => $userPreferences) {
         if (!isset($userPreferences[APIUsersManager::PREFERENCE_DEFAULT_REPORT_DATE])) {
             continue;
         }
         $defaultDate = $userPreferences[APIUsersManager::PREFERENCE_DEFAULT_REPORT_DATE];
         $preference = new UserPreferences();
         $period = $preference->getDefaultPeriod($defaultDate);
         if ($period != 'range') {
             continue;
         }
         if (isset($userPreferences[APIUsersManager::PREFERENCE_DEFAULT_REPORT]) && is_numeric($userPreferences[APIUsersManager::PREFERENCE_DEFAULT_REPORT])) {
             // If user selected one particular website ID
             $idSites = array($userPreferences[APIUsersManager::PREFERENCE_DEFAULT_REPORT]);
         } else {
             // If user selected "All websites"  or some other random value, we pre-process all websites that he has access to
             $idSites = APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess($userLogin);
         }
         foreach ($idSites as $idSite) {
             $customDateRangesToProcessForSites[$idSite][] = $defaultDate;
         }
     }
     return $customDateRangesToProcessForSites;
 }
Example #8
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 #9
0
 /**
  * The "User Settings" admin UI screen view
  */
 public function userSettings()
 {
     Piwik::checkUserIsNotAnonymous();
     $view = new View('@UsersManager/userSettings');
     $userLogin = Piwik::getCurrentUserLogin();
     $user = APIUsersManager::getInstance()->getUser($userLogin);
     $view->userAlias = $user['alias'];
     $view->userEmail = $user['email'];
     $view->ignoreSalt = $this->getIgnoreCookieSalt();
     $userPreferences = new UserPreferences();
     $defaultReport = $userPreferences->getDefaultReport();
     if ($defaultReport === false) {
         $defaultReport = $userPreferences->getDefaultWebsiteId();
     }
     $view->defaultReport = $defaultReport;
     if ($defaultReport == 'MultiSites') {
         $defaultSiteId = $userPreferences->getDefaultWebsiteId();
         $view->defaultReportIdSite = $defaultSiteId;
         $view->defaultReportSiteName = Site::getNameFor($defaultSiteId);
     } else {
         $view->defaultReportIdSite = $defaultReport;
         $view->defaultReportSiteName = Site::getNameFor($defaultReport);
     }
     $view->defaultDate = $this->getDefaultDateForUser($userLogin);
     $view->availableDefaultDates = $this->getDefaultDates();
     $view->languages = APILanguagesManager::getInstance()->getAvailableLanguageNames();
     $view->currentLanguageCode = LanguagesManager::getLanguageCodeForCurrentUser();
     $view->ignoreCookieSet = IgnoreCookie::isIgnoreCookieFound();
     $view->piwikHost = Url::getCurrentHost();
     $this->setBasicVariablesView($view);
     return $view->render();
 }
Example #10
0
 public function test_getDefaultWebsiteId_ShouldReturnASiteEvenIfMultiSitesIsDefaultReport()
 {
     $this->setDefaultReport('MultiSites');
     $this->createSite();
     $this->assertEquals(1, $this->userPreferences->getDefaultWebsiteId());
 }
Example #11
0
 /**
  * The "User Settings" admin UI screen view
  */
 public function userSettings()
 {
     Piwik::checkUserIsNotAnonymous();
     $view = new View('@UsersManager/userSettings');
     $userLogin = Piwik::getCurrentUserLogin();
     $user = Request::processRequest('UsersManager.getUser', array('userLogin' => $userLogin));
     $view->userAlias = $user['alias'];
     $view->userEmail = $user['email'];
     $view->userTokenAuth = Piwik::getCurrentUserTokenAuth();
     $view->ignoreSalt = $this->getIgnoreCookieSalt();
     $userPreferences = new UserPreferences();
     $defaultReport = $userPreferences->getDefaultReport();
     if ($defaultReport === false) {
         $defaultReport = $userPreferences->getDefaultWebsiteId();
     }
     $view->defaultReport = $defaultReport;
     if ($defaultReport == 'MultiSites') {
         $defaultSiteId = $userPreferences->getDefaultWebsiteId();
         $reportOptionsValue = $defaultSiteId;
         $view->defaultReportIdSite = $defaultSiteId;
         $view->defaultReportSiteName = Site::getNameFor($defaultSiteId);
     } else {
         $reportOptionsValue = $defaultReport;
         $view->defaultReportIdSite = $defaultReport;
         $view->defaultReportSiteName = Site::getNameFor($defaultReport);
     }
     $view->defaultReportOptions = array(array('key' => 'MultiSites', 'value' => Piwik::translate('General_AllWebsitesDashboard')), array('key' => $reportOptionsValue, 'value' => Piwik::translate('General_DashboardForASpecificWebsite')));
     $view->defaultDate = $this->getDefaultDateForUser($userLogin);
     $view->availableDefaultDates = $this->getDefaultDates();
     $languages = APILanguagesManager::getInstance()->getAvailableLanguageNames();
     $languageOptions = array();
     foreach ($languages as $language) {
         $languageOptions[] = array('key' => $language['code'], 'value' => $language['name']);
     }
     $view->languageOptions = $languageOptions;
     $view->currentLanguageCode = LanguagesManager::getLanguageCodeForCurrentUser();
     $view->currentTimeformat = (int) LanguagesManager::uses12HourClockForCurrentUser();
     $view->ignoreCookieSet = IgnoreCookie::isIgnoreCookieFound();
     $view->piwikHost = Url::getCurrentHost();
     $this->setBasicVariablesView($view);
     $view->timeFormats = array('1' => Piwik::translate('General_12HourClock'), '0' => Piwik::translate('General_24HourClock'));
     return $view->render();
 }
Example #12
0
File: Menu.php Project: piwik/piwik
 /**
  * Returns the &idSite=X&period=Y&date=Z query string fragment,
  * fetched from current logged-in user's preferences.
  *
  * @param bool $websiteId
  * @param bool $defaultPeriod
  * @param bool $defaultDate
  * @return string eg '&idSite=1&period=week&date=today'
  * @throws \Exception in case a website was not specified and a default website id could not be found
  */
 public function urlForDefaultUserParams($websiteId = false, $defaultPeriod = false, $defaultDate = false)
 {
     $userPreferences = new UserPreferences();
     if (empty($websiteId)) {
         $websiteId = $userPreferences->getDefaultWebsiteId();
     }
     if (empty($websiteId)) {
         throw new \Exception("A website ID was not specified and a website to default to could not be found.");
     }
     if (empty($defaultDate)) {
         $defaultDate = $userPreferences->getDefaultDate();
     }
     if (empty($defaultPeriod)) {
         $defaultPeriod = $userPreferences->getDefaultPeriod(false);
     }
     return array('idSite' => $websiteId, 'period' => $defaultPeriod, 'date' => $defaultDate);
 }