예제 #1
0
파일: Menu.php 프로젝트: brienomatty/elmsln
 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);
 }
예제 #2
0
파일: Menu.php 프로젝트: normimuc/piwik
 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);
 }
예제 #3
0
파일: Menu.php 프로젝트: 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);
     }
 }
예제 #4
0
파일: Menu.php 프로젝트: 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);
     }
 }
예제 #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());
 }
예제 #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;
 }
예제 #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;
 }
예제 #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();
 }
예제 #10
0
 public function test_getDefaultWebsiteId_ShouldReturnASiteEvenIfMultiSitesIsDefaultReport()
 {
     $this->setDefaultReport('MultiSites');
     $this->createSite();
     $this->assertEquals(1, $this->userPreferences->getDefaultWebsiteId());
 }
예제 #11
0
파일: Controller.php 프로젝트: piwik/piwik
 /**
  * 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();
 }
예제 #12
0
파일: Menu.php 프로젝트: 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);
 }