Inheritance: extends Piwik\Plugin
Exemplo n.º 1
0
 public function configureTopMenu(MenuTop $menu)
 {
     if (Piwik::isUserIsAnonymous() || !SettingsPiwik::isPiwikInstalled()) {
         $langManager = new LanguagesManager();
         $menu->addHtml('LanguageSelector', $langManager->getLanguagesSelector(), true, $order = 30, false);
     }
 }
Exemplo n.º 2
0
 public function index()
 {
     Piwik::checkUserIsNotAnonymous();
     $view = new View('@MobileMessaging/index');
     $view->isSuperUser = Piwik::hasUserSuperUserAccess();
     $mobileMessagingAPI = API::getInstance();
     $view->delegatedManagement = $mobileMessagingAPI->getDelegatedManagement();
     $view->credentialSupplied = $mobileMessagingAPI->areSMSAPICredentialProvided();
     $view->accountManagedByCurrentUser = $view->isSuperUser || $view->delegatedManagement;
     $view->strHelpAddPhone = Piwik::translate('MobileMessaging_Settings_PhoneNumbers_HelpAdd', array(Piwik::translate('General_Settings'), Piwik::translate('MobileMessaging_SettingsMenu')));
     if ($view->credentialSupplied && $view->accountManagedByCurrentUser) {
         $view->provider = $mobileMessagingAPI->getSMSProvider();
         $view->creditLeft = $mobileMessagingAPI->getCreditLeft();
     }
     $view->smsProviders = SMSProvider::$availableSMSProviders;
     // construct the list of countries from the lang files
     $countries = array();
     foreach (Common::getCountriesList() as $countryCode => $continentCode) {
         if (isset(CountryCallingCodes::$countryCallingCodes[$countryCode])) {
             $countries[$countryCode] = array('countryName' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode), 'countryCallingCode' => CountryCallingCodes::$countryCallingCodes[$countryCode]);
         }
     }
     $view->countries = $countries;
     $view->defaultCountry = Common::getCountry(LanguagesManager::getLanguageCodeForCurrentUser(), true, IP::getIpFromHeader());
     $view->phoneNumbers = $mobileMessagingAPI->getPhoneNumbers();
     $this->setBasicVariablesView($view);
     return $view->render();
 }
Exemplo n.º 3
0
 public function index()
 {
     $view = new View('@ScheduledReports/index');
     $this->setGeneralVariablesView($view);
     $view->countWebsites = count(APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess());
     // get report types
     $reportTypes = API::getReportTypes();
     $view->reportTypes = $reportTypes;
     $view->defaultReportType = self::DEFAULT_REPORT_TYPE;
     $view->defaultReportFormat = ScheduledReports::DEFAULT_REPORT_FORMAT;
     $view->displayFormats = ScheduledReports::getDisplayFormats();
     $reportsByCategoryByType = array();
     $reportFormatsByReportType = array();
     $allowMultipleReportsByReportType = array();
     foreach ($reportTypes as $reportType => $reportTypeIcon) {
         // get report formats
         $reportFormatsByReportType[$reportType] = API::getReportFormats($reportType);
         $allowMultipleReportsByReportType[$reportType] = API::allowMultipleReports($reportType);
         // get report metadata
         $reportsByCategory = array();
         $availableReportMetadata = API::getReportMetadata($this->idSite, $reportType);
         foreach ($availableReportMetadata as $reportMetadata) {
             $reportsByCategory[$reportMetadata['category']][] = $reportMetadata;
         }
         $reportsByCategoryByType[$reportType] = $reportsByCategory;
     }
     $view->reportsByCategoryByReportType = $reportsByCategoryByType;
     $view->reportFormatsByReportType = $reportFormatsByReportType;
     $view->allowMultipleReportsByReportType = $allowMultipleReportsByReportType;
     $reports = array();
     $reportsById = array();
     if (!Piwik::isUserIsAnonymous()) {
         $reports = API::getInstance()->getReports($this->idSite, $period = false, $idReport = false, $ifSuperUserReturnOnlySuperUserReports = true);
         foreach ($reports as &$report) {
             $report['recipients'] = API::getReportRecipients($report);
             $reportsById[$report['idreport']] = $report;
         }
     }
     $view->reports = $reports;
     $view->reportsJSON = Common::json_encode($reportsById);
     $view->downloadOutputType = API::OUTPUT_INLINE;
     $view->periods = ScheduledReports::getPeriodToFrequency();
     $view->defaultPeriod = ScheduledReports::DEFAULT_PERIOD;
     $view->defaultHour = ScheduledReports::DEFAULT_HOUR;
     $view->language = LanguagesManager::getLanguageCodeForCurrentUser();
     $view->segmentEditorActivated = false;
     if (API::isSegmentEditorActivated()) {
         $savedSegmentsById = array();
         foreach (APISegmentEditor::getInstance()->getAll($this->idSite) as $savedSegment) {
             $savedSegmentsById[$savedSegment['idsegment']] = $savedSegment['name'];
         }
         $view->savedSegmentsById = $savedSegmentsById;
         $view->segmentEditorActivated = true;
     }
     return $view->render();
 }
Exemplo n.º 4
0
 public function index()
 {
     Piwik::checkUserHasSuperUserAccess();
     $view = new View('@IP2Location/index');
     $view->language = LanguagesManager::getLanguageCodeForCurrentUser();
     $this->setBasicVariablesView($view);
     $view->adminMenu = MenuAdmin::getInstance()->getMenu();
     $view->topMenu = MenuTop::getInstance()->getMenu();
     $view->notifications = NotificationManager::getAllNotificationsToDisplay();
     $view->userMenu = MenuUser::getInstance()->getMenu();
     $view->phpVersion = phpversion();
     $view->phpIsNewEnough = version_compare($view->phpVersion, '5.3.0', '>=');
     $view->assign('userMenu', 'IP2Location');
     $view->assign('dbNotFound', false);
     $view->assign('dbOutDated', false);
     $view->assign('showResults', false);
     $view->assign('fileName', '-');
     $view->assign('date', '-');
     $view->assign('country', '');
     $view->assign('regionName', '');
     $view->assign('cityName', '');
     $view->assign('position', '');
     $ipAddress = trim(Common::getRequestVar('ipAddress', $_SERVER['REMOTE_ADDR']));
     $view->assign('ipAddress', $ipAddress);
     $dbPath = PIWIK_INCLUDE_PATH . '/plugins/IP2Location/data/';
     $dbFile = '';
     if ($handle = opendir($dbPath)) {
         while (false !== ($file = readdir($handle))) {
             if (strtoupper(substr($file, -4)) == '.BIN') {
                 $dbFile = $dbPath . $file;
                 break;
             }
         }
         closedir($handle);
     }
     if (!$dbFile) {
         $view->assign('dbNotFound', true);
     }
     if ($dbFile) {
         $view->assign('fileName', $file);
         if (filemtime($dbFile) < strtotime('-2 months')) {
             $view->assign('dbOutDated', true);
         } else {
             $view->assign('date', date('d M, Y', filemtime($dbFile)));
         }
         if (!empty($_POST)) {
             $view->assign('showResults', true);
             $result = IP2LocationAPI::lookup($ipAddress, $dbFile);
             $view->assign('country', $result['countryCode'] != '-' ? $result['countryName'] . ' (' . $result['countryCode'] . ')' : '-');
             $view->assign('regionName', !preg_match('/not supported/', $result['regionName']) ? $result['regionName'] : '-');
             $view->assign('cityName', !preg_match('/not supported/', $result['cityName']) ? $result['cityName'] : '-');
             $view->assign('position', !preg_match('/not supported/', $result['latitude']) && $result['latitude'] != '-' ? $result['latitude'] . ', ' . $result['longitude'] : '-');
         }
     }
     echo $view->render();
 }
Exemplo n.º 5
0
 /**
  * anonymous = in the session
  * authenticated user = in the session
  */
 public function saveLanguage()
 {
     $language = Common::getRequestVar('language');
     // Prevent CSRF only when piwik is not installed yet (During install user can change language)
     if (DbHelper::isInstalled()) {
         $this->checkTokenInUrl();
     }
     LanguagesManager::setLanguageForSession($language);
     Url::redirectToReferrer();
 }
Exemplo n.º 6
0
 /**
  * anonymous = in the session
  * authenticated user = in the session and in DB
  */
 public function saveLanguage()
 {
     $language = Common::getRequestVar('language');
     // Prevent CSRF only when piwik is not installed yet (During install user can change language)
     if (DbHelper::isInstalled()) {
         $this->checkTokenInUrl();
     }
     LanguagesManager::setLanguageForSession($language);
     if (\Piwik\Registry::isRegistered('access')) {
         $currentUser = Piwik::getCurrentUserLogin();
         if ($currentUser && $currentUser !== 'anonymous') {
             API::getInstance()->setLanguageForUser($currentUser, $language);
         }
     }
     Url::redirectToReferrer();
 }
Exemplo n.º 7
0
 /**
  * Main Plugin Index
  *
  * @return mixed
  * @throws \Exception
  */
 public function index()
 {
     Piwik::checkUserHasSomeAdminAccess();
     if (isset($_SERVER['REQUEST_METHOD']) && 'POST' == $_SERVER['REQUEST_METHOD']) {
         // Cannot use Common::getRequestVar, because the function remove whitespaces and newline breaks
         $postedSiteData = isset($_POST['site']) ? $_POST['site'] : null;
         if (is_array($postedSiteData) && count($postedSiteData) > 0) {
             foreach ($postedSiteData as $id => $site) {
                 if (!isset($site['css'], $site['file'])) {
                     continue;
                 }
                 // Check URL
                 if (!UrlHelper::isLookLikeUrl($site['file'])) {
                     $site['file'] = null;
                 }
                 API::getInstance()->saveSite($id, $site['css'], $site['file']);
             }
             // Redirect to, clear POST vars
             $this->redirectToIndex('CustomOptOut', 'index');
             return;
         }
     }
     $view = new View('@CustomOptOut/index.twig');
     Site::clearCache();
     if (Piwik::hasUserSuperUserAccess()) {
         $sitesRaw = APISiteManager::getInstance()->getAllSites();
     } else {
         $sitesRaw = APISiteManager::getInstance()->getSitesWithAdminAccess();
     }
     // Gets sites after Site.setSite hook was called
     $sites = array_values(Site::getSites());
     if (count($sites) != count($sitesRaw)) {
         throw new \Exception("One or more website are missing or invalid.");
     }
     foreach ($sites as &$site) {
         $site['alias_urls'] = APISiteManager::getInstance()->getSiteUrlsFromId($site['idsite']);
     }
     $view->adminSites = $sites;
     $view->adminSitesCount = count($sites);
     $view->language = LanguagesManager::getLanguageCodeForCurrentUser();
     $view->isEditorEnabled = API::getInstance()->isCssEditorEnabled();
     $view->editorTheme = API::getInstance()->getEditorTheme();
     $view->showOldLinks = false;
     $this->setBasicVariablesView($view);
     return $view->render();
 }
Exemplo n.º 8
0
 private function setManageVariables(View $view)
 {
     $view->isSuperUser = Piwik::hasUserSuperUserAccess();
     $mobileMessagingAPI = API::getInstance();
     $view->delegatedManagement = $mobileMessagingAPI->getDelegatedManagement();
     $view->credentialSupplied = $mobileMessagingAPI->areSMSAPICredentialProvided();
     $view->accountManagedByCurrentUser = $view->isSuperUser || $view->delegatedManagement;
     $view->strHelpAddPhone = $this->translator->translate('MobileMessaging_Settings_PhoneNumbers_HelpAdd', array($this->translator->translate('General_Settings'), $this->translator->translate('MobileMessaging_SettingsMenu')));
     $view->creditLeft = 0;
     $currentProvider = '';
     if ($view->credentialSupplied && $view->accountManagedByCurrentUser) {
         $currentProvider = $mobileMessagingAPI->getSMSProvider();
         $view->creditLeft = $mobileMessagingAPI->getCreditLeft();
     }
     $view->delegateManagementOptions = array(array('key' => '0', 'value' => Piwik::translate('General_No'), 'description' => Piwik::translate('General_Default') . '. ' . Piwik::translate('MobileMessaging_Settings_LetUsersManageAPICredential_No_Help')), array('key' => '1', 'value' => Piwik::translate('General_Yes'), 'description' => Piwik::translate('MobileMessaging_Settings_LetUsersManageAPICredential_Yes_Help')));
     $providers = array();
     $providerOptions = array();
     foreach (SMSProvider::findAvailableSmsProviders() as $provider) {
         if (empty($currentProvider)) {
             $currentProvider = $provider->getId();
         }
         $providers[$provider->getId()] = $provider->getDescription();
         $providerOptions[$provider->getId()] = $provider->getId();
     }
     $view->provider = $currentProvider;
     $view->smsProviders = $providers;
     $view->smsProviderOptions = $providerOptions;
     $defaultCountry = Common::getCountry(LanguagesManager::getLanguageCodeForCurrentUser(), true, IP::getIpFromHeader());
     $view->defaultCallingCode = '';
     // construct the list of countries from the lang files
     $countries = array(array('key' => '', 'value' => ''));
     foreach ($this->regionDataProvider->getCountryList() as $countryCode => $continentCode) {
         if (isset(CountryCallingCodes::$countryCallingCodes[$countryCode])) {
             if ($countryCode == $defaultCountry) {
                 $view->defaultCallingCode = CountryCallingCodes::$countryCallingCodes[$countryCode];
             }
             $countries[] = array('key' => CountryCallingCodes::$countryCallingCodes[$countryCode], 'value' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode));
         }
     }
     $view->countries = $countries;
     $view->phoneNumbers = $mobileMessagingAPI->getPhoneNumbers();
     $this->setBasicVariablesView($view);
 }
Exemplo n.º 9
0
 public function generalSettings()
 {
     Piwik::checkUserHasSuperUserAccess();
     $view = new View('@CoreAdminHome/generalSettings');
     $this->handleGeneralSettingsAdmin($view);
     $view->trustedHosts = Url::getTrustedHostsFromConfig();
     $logo = new CustomLogo();
     $view->branding = array('use_custom_logo' => $logo->isEnabled());
     $view->fileUploadEnabled = $logo->isFileUploadEnabled();
     $view->logosWriteable = $logo->isCustomLogoWritable();
     $view->pathUserLogo = CustomLogo::getPathUserLogo();
     $view->pathUserFavicon = CustomLogo::getPathUserFavicon();
     $view->pathUserLogoSmall = CustomLogo::getPathUserLogoSmall();
     $view->pathUserLogoSVG = CustomLogo::getPathUserSvgLogo();
     $view->pathUserLogoDirectory = realpath(dirname($view->pathUserLogo) . '/');
     $view->language = LanguagesManager::getLanguageCodeForCurrentUser();
     $this->setBasicVariablesView($view);
     return $view->render();
 }
Exemplo n.º 10
0
 /**
  * Assigns variables to {@link Piwik\View} instances that display an entire page.
  * 
  * The following variables assigned:
  * 
  * **date** - The value of the **date** query parameter.
  * **idSite** - The value of the **idSite** query parameter.
  * **rawDate** - The value of the **date** query parameter.
  * **prettyDate** - A pretty string description of the current period.
  * **siteName** - The current site's name.
  * **siteMainUrl** - The URL of the current site.
  * **startDate** - The start date of the current period. A {@link Piwik\Date} instance.
  * **endDate** - The end date of the current period. A {@link Piwik\Date} instance.
  * **language** - The current language's language code.
  * **config_action_url_category_delimiter** - The value of the `[General] action_url_category_delimiter`
  *                                            INI config option.
  * **topMenu** - The result of `MenuTop::getInstance()->getMenu()`.
  * 
  * As well as the variables set by {@link setPeriodVariablesView()}.
  * 
  * Will exit on error.
  * 
  * @param View $view
  * @return void
  * @api
  */
 protected function setGeneralVariablesView($view)
 {
     $view->date = $this->strDate;
     try {
         $view->idSite = $this->idSite;
         if (empty($this->site) || empty($this->idSite)) {
             throw new Exception("The requested website idSite is not found in the request, or is invalid.\n\t\t\t\tPlease check that you are logged in Piwik and have permission to access the specified website.");
         }
         $this->setPeriodVariablesView($view);
         $rawDate = Common::getRequestVar('date');
         $periodStr = Common::getRequestVar('period');
         if ($periodStr != 'range') {
             $date = Date::factory($this->strDate);
             $period = Period\Factory::build($periodStr, $date);
         } else {
             $period = new Range($periodStr, $rawDate, $this->site->getTimezone());
         }
         $view->rawDate = $rawDate;
         $view->prettyDate = self::getCalendarPrettyDate($period);
         $view->siteName = $this->site->getName();
         $view->siteMainUrl = $this->site->getMainUrl();
         $datetimeMinDate = $this->site->getCreationDate()->getDatetime();
         $minDate = Date::factory($datetimeMinDate, $this->site->getTimezone());
         $this->setMinDateView($minDate, $view);
         $maxDate = Date::factory('now', $this->site->getTimezone());
         $this->setMaxDateView($maxDate, $view);
         // Setting current period start & end dates, for pre-setting the calendar when "Date Range" is selected
         $dateStart = $period->getDateStart();
         if ($dateStart->isEarlier($minDate)) {
             $dateStart = $minDate;
         }
         $dateEnd = $period->getDateEnd();
         if ($dateEnd->isLater($maxDate)) {
             $dateEnd = $maxDate;
         }
         $view->startDate = $dateStart;
         $view->endDate = $dateEnd;
         $language = LanguagesManager::getLanguageForSession();
         $view->language = !empty($language) ? $language : LanguagesManager::getLanguageCodeForCurrentUser();
         $this->setBasicVariablesView($view);
         $view->topMenu = MenuTop::getInstance()->getMenu();
         $view->userMenu = MenuUser::getInstance()->getMenu();
         $notifications = $view->notifications;
         if (empty($notifications)) {
             $view->notifications = NotificationManager::getAllNotificationsToDisplay();
             NotificationManager::cancelAllNonPersistent();
         }
     } catch (Exception $e) {
         Piwik_ExitWithMessage($e->getMessage(), $e->getTraceAsString());
     }
 }
Exemplo n.º 11
0
 /**
  * Records settings from the "User Settings" page
  * @throws Exception
  */
 public function recordUserSettings()
 {
     $response = new ResponseBuilder(Common::getRequestVar('format'));
     try {
         $this->checkTokenInUrl();
         $defaultReport = Common::getRequestVar('defaultReport');
         $defaultDate = Common::getRequestVar('defaultDate');
         $language = Common::getRequestVar('language');
         $userLogin = Piwik::getCurrentUserLogin();
         $this->processPasswordChange($userLogin);
         LanguagesManager::setLanguageForSession($language);
         APILanguagesManager::getInstance()->setLanguageForUser($userLogin, $language);
         APIUsersManager::getInstance()->setUserPreference($userLogin, APIUsersManager::PREFERENCE_DEFAULT_REPORT, $defaultReport);
         APIUsersManager::getInstance()->setUserPreference($userLogin, APIUsersManager::PREFERENCE_DEFAULT_REPORT_DATE, $defaultDate);
         $toReturn = $response->getResponse();
     } catch (Exception $e) {
         $toReturn = $response->getResponseException($e);
     }
     return $toReturn;
 }
Exemplo n.º 12
0
 private function resetLanguageCookie()
 {
     /** @var Translator $translator */
     $translator = StaticContainer::get('Piwik\\Translation\\Translator');
     LanguagesManager::setLanguageForSession($translator->getCurrentLanguage());
 }
Exemplo n.º 13
0
 /**
  * @return View
  * @throws \Exception
  */
 public function getOptOutView()
 {
     if ($this->view) {
         return $this->view;
     }
     $trackVisits = !IgnoreCookie::isIgnoreCookieFound();
     $dntFound = $this->getDoNotTrackHeaderChecker()->isDoNotTrackFound();
     $setCookieInNewWindow = Common::getRequestVar('setCookieInNewWindow', false, 'int');
     if ($setCookieInNewWindow) {
         $reloadUrl = Url::getCurrentQueryStringWithParametersModified(array('showConfirmOnly' => 1, 'setCookieInNewWindow' => 0));
     } else {
         $reloadUrl = false;
         $nonce = Common::getRequestVar('nonce', false);
         if ($nonce !== false && Nonce::verifyNonce('Piwik_OptOut', $nonce)) {
             Nonce::discardNonce('Piwik_OptOut');
             IgnoreCookie::setIgnoreCookie();
             $trackVisits = !$trackVisits;
         }
     }
     $language = Common::getRequestVar('language', '');
     $lang = APILanguagesManager::getInstance()->isLanguageAvailable($language) ? $language : LanguagesManager::getLanguageCodeForCurrentUser();
     $this->addQueryParameters(array('module' => 'CoreAdminHome', 'action' => 'optOut', 'language' => $lang, 'setCookieInNewWindow' => 1), false);
     $this->view = new View("@CoreAdminHome/optOut");
     $this->view->setXFrameOptions('allow');
     $this->view->dntFound = $dntFound;
     $this->view->trackVisits = $trackVisits;
     $this->view->nonce = Nonce::getNonce('Piwik_OptOut', 3600);
     $this->view->language = $lang;
     $this->view->showConfirmOnly = Common::getRequestVar('showConfirmOnly', false, 'int');
     $this->view->reloadUrl = $reloadUrl;
     $this->view->javascripts = $this->getJavascripts();
     $this->view->stylesheets = $this->getStylesheets();
     $this->view->title = $this->getTitle();
     $this->view->queryParameters = $this->getQueryParameters();
     return $this->view;
 }
Exemplo n.º 14
0
 public function privacySettings()
 {
     Piwik::checkUserHasSomeAdminAccess();
     $view = new View('@PrivacyManager/privacySettings');
     if (Piwik::hasUserSuperUserAccess()) {
         $view->deleteData = $this->getDeleteDataInfo();
         $view->anonymizeIP = $this->getAnonymizeIPInfo();
         $view->dntSupport = DoNotTrackHeaderChecker::isActive();
         $view->canDeleteLogActions = Db::isLockPrivilegeGranted();
         $view->dbUser = PiwikConfig::getInstance()->database['username'];
         $view->deactivateNonce = Nonce::getNonce(self::DEACTIVATE_DNT_NONCE);
         $view->activateNonce = Nonce::getNonce(self::ACTIVATE_DNT_NONCE);
     }
     $view->language = LanguagesManager::getLanguageCodeForCurrentUser();
     $this->setBasicVariablesView($view);
     return $view->render();
 }
Exemplo n.º 15
0
 public function index()
 {
     $language = Common::getRequestVar('language', '');
     if (!empty($language)) {
         LanguagesManager::setLanguageForSession($language);
     }
     return $this->runUpdaterAndExit();
 }
Exemplo n.º 16
0
 /**
  * Shows the "Track Visits" checkbox.
  */
 public function optOut()
 {
     $trackVisits = !IgnoreCookie::isIgnoreCookieFound();
     $nonce = Common::getRequestVar('nonce', false);
     $language = Common::getRequestVar('language', '');
     if ($nonce !== false && Nonce::verifyNonce('Piwik_OptOut', $nonce)) {
         Nonce::discardNonce('Piwik_OptOut');
         IgnoreCookie::setIgnoreCookie();
         $trackVisits = !$trackVisits;
     }
     $view = new View('@CoreAdminHome/optOut');
     $view->trackVisits = $trackVisits;
     $view->nonce = Nonce::getNonce('Piwik_OptOut', 3600);
     $view->language = APILanguagesManager::getInstance()->isLanguageAvailable($language) ? $language : LanguagesManager::getLanguageCodeForCurrentUser();
     return $view->render();
 }
Exemplo n.º 17
0
    /**
     * Shows the "Track Visits" checkbox.
     */
    public function optOut()
    {
        $trackVisits = !IgnoreCookie::isIgnoreCookieFound();

        $dntChecker = new DoNotTrackHeaderChecker();
        $dntFound = $dntChecker->isDoNotTrackFound();

        $setCookieInNewWindow = Common::getRequestVar('setCookieInNewWindow', false, 'int');
        if ($setCookieInNewWindow) {
            $reloadUrl = Url::getCurrentQueryStringWithParametersModified(array(
                'showConfirmOnly' => 1,
                'setCookieInNewWindow' => 0,
            ));
        } else {
            $reloadUrl = false;

            $nonce = Common::getRequestVar('nonce', false);
            if ($nonce !== false && Nonce::verifyNonce('Piwik_OptOut', $nonce)) {
                Nonce::discardNonce('Piwik_OptOut');
                IgnoreCookie::setIgnoreCookie();
                $trackVisits = !$trackVisits;
            }
        }

        $language = Common::getRequestVar('language', '');
        $lang = APILanguagesManager::getInstance()->isLanguageAvailable($language)
            ? $language
            : LanguagesManager::getLanguageCodeForCurrentUser();

        // should not use self::renderTemplate since that uses setBasicVariablesView. this will cause
        // an error when setBasicVariablesAdminView is called, and MenuTop is requested (the idSite query
        // parameter is required)
        $view = new View("@CoreAdminHome/optOut");
        $view->setXFrameOptions('allow');
        $view->dntFound = $dntFound;
        $view->trackVisits = $trackVisits;
        $view->nonce = Nonce::getNonce('Piwik_OptOut', 3600);
        $view->language = $lang;
        $view->isSafari = $this->isUserAgentSafari();
        $view->showConfirmOnly = Common::getRequestVar('showConfirmOnly', false, 'int');
        $view->reloadUrl = $reloadUrl;
        return $view->render();
    }
Exemplo n.º 18
0
 /**
  * Save language selection in session-store
  */
 public function saveLanguage()
 {
     $language = $this->getParam('language');
     LanguagesManager::setLanguageForSession($language);
     Url::redirectToReferrer();
 }
Exemplo n.º 19
0
 /**
  * Assigns variables to {@link Piwik\View} instances that display an entire page.
  *
  * The following variables assigned:
  *
  * **date** - The value of the **date** query parameter.
  * **idSite** - The value of the **idSite** query parameter.
  * **rawDate** - The value of the **date** query parameter.
  * **prettyDate** - A pretty string description of the current period.
  * **siteName** - The current site's name.
  * **siteMainUrl** - The URL of the current site.
  * **startDate** - The start date of the current period. A {@link Piwik\Date} instance.
  * **endDate** - The end date of the current period. A {@link Piwik\Date} instance.
  * **language** - The current language's language code.
  * **config_action_url_category_delimiter** - The value of the `[General] action_url_category_delimiter`
  *                                            INI config option.
  * **topMenu** - The result of `MenuTop::getInstance()->getMenu()`.
  *
  * As well as the variables set by {@link setPeriodVariablesView()}.
  *
  * Will exit on error.
  *
  * @param View $view
  * @return void
  * @api
  */
 protected function setGeneralVariablesView($view)
 {
     $view->idSite = $this->idSite;
     $this->checkSitePermission();
     $this->setPeriodVariablesView($view);
     $view->siteName = $this->site->getName();
     $view->siteMainUrl = $this->site->getMainUrl();
     $siteTimezone = $this->site->getTimezone();
     $datetimeMinDate = $this->site->getCreationDate()->getDatetime();
     $minDate = Date::factory($datetimeMinDate, $siteTimezone);
     $this->setMinDateView($minDate, $view);
     $maxDate = Date::factory('now', $siteTimezone);
     $this->setMaxDateView($maxDate, $view);
     $rawDate = Common::getRequestVar('date');
     Period::checkDateFormat($rawDate);
     $periodStr = Common::getRequestVar('period');
     if ($periodStr != 'range') {
         $date = Date::factory($this->strDate);
         $validDate = $this->getValidDate($date, $minDate, $maxDate);
         $period = Period\Factory::build($periodStr, $validDate);
         if ($date->toString() !== $validDate->toString()) {
             // we to not always change date since it could convert a strDate "today" to "YYYY-MM-DD"
             // only change $this->strDate if it was not valid before
             $this->setDate($validDate);
         }
     } else {
         $period = new Range($periodStr, $rawDate, $siteTimezone);
     }
     // Setting current period start & end dates, for pre-setting the calendar when "Date Range" is selected
     $dateStart = $period->getDateStart();
     $dateStart = $this->getValidDate($dateStart, $minDate, $maxDate);
     $dateEnd = $period->getDateEnd();
     $dateEnd = $this->getValidDate($dateEnd, $minDate, $maxDate);
     if ($periodStr == 'range') {
         // make sure we actually display the correct calendar pretty date
         $newRawDate = $dateStart->toString() . ',' . $dateEnd->toString();
         $period = new Range($periodStr, $newRawDate, $siteTimezone);
     }
     $view->date = $this->strDate;
     $view->prettyDate = self::getCalendarPrettyDate($period);
     $view->prettyDateLong = $period->getLocalizedLongString();
     $view->rawDate = $rawDate;
     $view->startDate = $dateStart;
     $view->endDate = $dateEnd;
     $language = LanguagesManager::getLanguageForSession();
     $view->language = !empty($language) ? $language : LanguagesManager::getLanguageCodeForCurrentUser();
     $this->setBasicVariablesView($view);
     $view->topMenu = MenuTop::getInstance()->getMenu();
     $view->adminMenu = MenuAdmin::getInstance()->getMenu();
     $notifications = $view->notifications;
     if (empty($notifications)) {
         $view->notifications = NotificationManager::getAllNotificationsToDisplay();
         NotificationManager::cancelAllNonPersistent();
     }
 }
Exemplo n.º 20
0
 public function privacySettings()
 {
     Piwik::checkUserHasSomeAdminAccess();
     $view = new View('@PrivacyManager/privacySettings');
     if (Piwik::hasUserSuperUserAccess()) {
         $view->deleteData = $this->getDeleteDataInfo();
         $view->anonymizeIP = $this->getAnonymizeIPInfo();
         $dntChecker = new DoNotTrackHeaderChecker();
         $view->dntSupport = $dntChecker->isActive();
         $view->canDeleteLogActions = Db::isLockPrivilegeGranted();
         $view->dbUser = PiwikConfig::getInstance()->database['username'];
         $view->deactivateNonce = Nonce::getNonce(self::DEACTIVATE_DNT_NONCE);
         $view->activateNonce = Nonce::getNonce(self::ACTIVATE_DNT_NONCE);
         $view->maskLengthOptions = array(array('key' => '1', 'value' => Piwik::translate('PrivacyManager_AnonymizeIpMaskLength', array("1", "192.168.100.xxx")), 'description' => ''), array('key' => '2', 'value' => Piwik::translate('PrivacyManager_AnonymizeIpMaskLength', array("2", "192.168.xxx.xxx")), 'description' => Piwik::translate('General_Recommended')), array('key' => '3', 'value' => Piwik::translate('PrivacyManager_AnonymizeIpMaskLength', array("3", "192.xxx.xxx.xxx")), 'description' => ''));
         $view->useAnonymizedIpForVisitEnrichmentOptions = array(array('key' => '1', 'value' => Piwik::translate('General_Yes'), 'description' => Piwik::translate('PrivacyManager_RecommendedForPrivacy')), array('key' => '0', 'value' => Piwik::translate('General_No'), 'description' => ''));
         $view->scheduleDeletionOptions = array(array('key' => '1', 'value' => Piwik::translate('Intl_PeriodDay')), array('key' => '7', 'value' => Piwik::translate('Intl_PeriodWeek')), array('key' => '30', 'value' => Piwik::translate('Intl_PeriodMonth')));
         $view->doNotTrackOptions = array(array('key' => '1', 'value' => Piwik::translate('PrivacyManager_DoNotTrack_Enable'), 'description' => Piwik::translate('General_Recommended')), array('key' => '0', 'value' => Piwik::translate('PrivacyManager_DoNotTrack_Disable'), 'description' => Piwik::translate('General_NotRecommended')));
     }
     $view->language = LanguagesManager::getLanguageCodeForCurrentUser();
     $this->setBasicVariablesView($view);
     return $view->render();
 }
Exemplo n.º 21
0
 private static function ensureLanguageSetForUser($currentUser)
 {
     $lang = \Piwik\Plugins\LanguagesManager\API::getInstance()->getLanguageForUser($currentUser);
     if (empty($lang)) {
         \Piwik\Plugins\LanguagesManager\API::getInstance()->setLanguageForUser($currentUser, LanguagesManager::getLanguageCodeForCurrentUser());
     }
 }
Exemplo n.º 22
0
 /**
  * Shows the "Track Visits" checkbox.
  */
 public function optOut()
 {
     $trackVisits = !IgnoreCookie::isIgnoreCookieFound();
     $nonce = Common::getRequestVar('nonce', false);
     $language = Common::getRequestVar('language', '');
     if ($nonce !== false && Nonce::verifyNonce('Piwik_OptOut', $nonce)) {
         Nonce::discardNonce('Piwik_OptOut');
         IgnoreCookie::setIgnoreCookie();
         $trackVisits = !$trackVisits;
     }
     $lang = APILanguagesManager::getInstance()->isLanguageAvailable($language) ? $language : LanguagesManager::getLanguageCodeForCurrentUser();
     // should not use self::renderTemplate since that uses setBasicVariablesView. this will cause
     // an error when setBasicVariablesAdminView is called, and MenuTop is requested (the idSite query
     // parameter is required)
     $view = new View("@CoreAdminHome/optOut");
     $view->setXFrameOptions('allow');
     $view->trackVisits = $trackVisits;
     $view->nonce = Nonce::getNonce('Piwik_OptOut', 3600);
     $view->language = $lang;
     return $view->render();
 }
Exemplo n.º 23
0
 public function index()
 {
     $language = Common::getRequestVar('language', '');
     if (!empty($language)) {
         LanguagesManager::setLanguageForSession($language);
     }
     try {
         return $this->runUpdaterAndExit();
     } catch (NoUpdatesFoundException $e) {
         Piwik::redirectToModule('CoreHome');
     }
 }
Exemplo n.º 24
0
 /**
  * Shows the "Track Visits" checkbox.
  */
 public function optOut()
 {
     $trackVisits = !IgnoreCookie::isIgnoreCookieFound();
     $nonce = Common::getRequestVar('nonce', false);
     $language = Common::getRequestVar('language', '');
     if ($nonce !== false && Nonce::verifyNonce('Piwik_OptOut', $nonce)) {
         Nonce::discardNonce('Piwik_OptOut');
         IgnoreCookie::setIgnoreCookie();
         $trackVisits = !$trackVisits;
     }
     $lang = APILanguagesManager::getInstance()->isLanguageAvailable($language) ? $language : LanguagesManager::getLanguageCodeForCurrentUser();
     return $this->renderTemplate('optOut', array('trackVisits' => $trackVisits, 'nonce' => Nonce::getNonce('Piwik_OptOut', 3600), 'language' => $lang));
 }
Exemplo n.º 25
0
 protected function getTimeFormat()
 {
     if (is_null($this->use12HourClock)) {
         $this->use12HourClock = LanguagesManager::uses12HourClockForCurrentUser();
     }
     $timeFormat = 'Intl_Format_Time_24';
     if ($this->use12HourClock) {
         $timeFormat = 'Intl_Format_Time_12';
     }
     $template = $this->translator->translate($timeFormat);
     return $template;
 }
Exemplo n.º 26
0
 /**
  * Save language selection in session-store
  */
 public function saveLanguage()
 {
     $language = Common::getRequestVar('language');
     LanguagesManager::setLanguageForSession($language);
     Url::redirectToReferrer();
 }