public function getInformation() { $suffix = ' Debug: <a href="' . Url::getCurrentQueryStringWithParametersModified(array('module' => 'ImageGraph', 'action' => 'index')) . '">All images</a>'; $info = parent::getInformation(); $info['description'] .= ' ' . $suffix; return $info; }
/** * Adds a report to the list of reports to display. * * @param string $category The report's category. Can be a i18n token. * @param string $title The report's title. Can be a i18n token. * @param string $action The controller action used to load the report, ie, Referrers.getAll * @param array $params The list of query parameters to use when loading the report. * This list overrides query parameters currently in use. For example, * array('idSite' => 2, 'viewDataTable' => 'goalsTable') * would mean the goals report for site w/ ID=2 will always be loaded. */ public function addReport($category, $title, $action, $params = array()) { list($module, $action) = explode('.', $action); $params = array('module' => $module, 'action' => $action) + $params; $categories = $this->dimensionCategories; $categories[$category][] = array('title' => $title, 'params' => $params, 'url' => Url::getCurrentQueryStringWithParametersModified($params)); $this->dimensionCategories = $categories; }
/** * @group Core */ public function testAllMethods() { $this->assertEquals(Url::getCurrentQueryStringWithParametersModified(array()), Url::getCurrentQueryString()); $this->assertEquals(Url::getCurrentUrl(), Url::getCurrentUrlWithoutQueryString()); $this->assertEquals(Url::getCurrentUrl(), Url::getCurrentScheme() . '://' . Url::getCurrentHost() . Url::getCurrentScriptName()); $_SERVER['QUERY_STRING'] = 'q=test'; $parameters = array_keys(Url::getArrayFromCurrentQueryString()); $parametersNameToValue = array(); foreach ($parameters as $name) { $parametersNameToValue[$name] = null; } $this->assertEquals('', Url::getCurrentQueryStringWithParametersModified($parametersNameToValue)); }
private static function notifyAnyInvalidPlugin() { $missingPlugins = \Piwik\Plugin\Manager::getInstance()->getMissingPlugins(); if (empty($missingPlugins)) { return; } if (!Piwik::hasUserSuperUserAccess()) { return; } $pluginsLink = Url::getCurrentQueryStringWithParametersModified(array('module' => 'CorePluginsAdmin', 'action' => 'plugins')); $invalidPluginsWarning = Piwik::translate('CoreAdminHome_InvalidPluginsWarning', array(self::getPiwikVersion(), '<strong>' . implode('</strong>, <strong>', $missingPlugins) . '</strong>')) . "<br/>" . Piwik::translate('CoreAdminHome_InvalidPluginsYouCanUninstall', array('<a href="' . $pluginsLink . '"/>', '</a>')); $notification = new Notification($invalidPluginsWarning); $notification->raw = true; $notification->context = Notification::CONTEXT_WARNING; $notification->title = Piwik::translate('General_Warning'); Notification\Manager::notify('ControllerAdmin_InvalidPluginsWarning', $notification); }
/** * Checks if a datatable for a view is empty and if so, displays a message in the footer * telling users to configure GeoIP. */ protected function checkIfNoDataForGeoIpReport(ViewDataTable $view) { $view->config->filters[] = function ($dataTable) use($view) { // if there's only one row whose label is 'Unknown', display a message saying there's no data if ($dataTable->getRowsCount() == 1 && $dataTable->getFirstRow()->getColumn('label') == Piwik::translate('General_Unknown')) { $footerMessage = Piwik::translate('UserCountry_NoDataForGeoIPReport1'); $userCountry = new UserCountry(); // if GeoIP is working, don't display this part of the message if (!$userCountry->isGeoIPWorking()) { $params = array('module' => 'UserCountry', 'action' => 'adminIndex'); $footerMessage .= ' ' . Piwik::translate('UserCountry_NoDataForGeoIPReport2', array('<a target="_blank" href="' . Url::getCurrentQueryStringWithParametersModified($params) . '">', '</a>', '<a target="_blank" href="http://dev.maxmind.com/geoip/geolite?rId=piwik">', '</a>')); } else { $footerMessage .= ' ' . Piwik::translate('UserCountry_ToGeolocateOldVisits', array('<a target="_blank" href="http://piwik.org/faq/how-to/#faq_167">', '</a>')); } $view->config->show_footer_message = $footerMessage; } }; }
protected function addFilter_urlRewriteWithParameters() { $urlRewriteFilter = new Twig_SimpleFilter('urlRewriteWithParameters', function ($parameters) { $parameters['updated'] = null; $url = Url::getCurrentQueryStringWithParametersModified($parameters); return $url; }); $this->twig->addFilter($urlRewriteFilter); }
/** * @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; }
/** * Returns the current URL without generic filter query parameters. * * @param array $params Query parameter values to override in the new URL. * @return string */ public static function getCurrentUrlWithoutGenericFilters($params) { // unset all filter query params so the related report will show up in its default state, // unless the filter param was in $queryParams $genericFiltersInfo = DataTableGenericFilter::getGenericFiltersInformation(); foreach ($genericFiltersInfo as $filter) { foreach ($filter[1] as $queryParamName => $queryParamInfo) { if (!isset($params[$queryParamName])) { $params[$queryParamName] = null; } } } return Url::getCurrentQueryStringWithParametersModified($params); }
/** * Redirects the current request to a new module and action. * * @param string $newModule The target module, eg, `'UserCountry'`. * @param string $newAction The target controller action, eg, `'index'`. * @param array $parameters The query parameter values to modify before redirecting. * @api */ public static function redirectToModule($newModule, $newAction = '', $parameters = array()) { $newUrl = 'index.php' . Url::getCurrentQueryStringWithParametersModified(array('module' => $newModule, 'action' => $newAction) + $parameters); Url::redirectToUrl($newUrl); }
private function getUserCountryMapUrlForVisitorProfile() { $params = array('module' => 'UserCountryMap', 'action' => 'realtimeMap', 'segment' => self::getSegmentWithVisitorId(), 'visitorId' => false, 'changeVisitAlpha' => 0, 'removeOldVisits' => 0, 'realtimeWindow' => 'false', 'showFooterMessage' => 0, 'showDateTime' => 0, 'doNotRefreshVisits' => 1); return Url::getCurrentQueryStringWithParametersModified($params); }
/** * Returns a URL to a sparkline image for a report served by the current plugin. * * The result of this URL should be used with the [sparkline()](/api-reference/Piwik/View#twig) twig function. * * The current site ID and period will be used. * * @param array $customParameters The array of query parameter name/value pairs that * should be set in result URL. * @return string The generated URL. */ private function getUrlSparkline($customParameters = array()) { $customParameters['viewDataTable'] = 'sparkline'; $params = $this->getGraphParamsModified($customParameters); // convert array values to comma separated foreach ($params as &$value) { if (is_array($value)) { $value = rawurlencode(implode(',', $value)); } } $url = Url::getCurrentQueryStringWithParametersModified($params); return $url; }
public function activate($redirectAfter = true) { $pluginName = $this->initPluginModification(static::ACTIVATE_NONCE); $this->dieIfPluginsAdminIsDisabled(); $this->pluginManager->activatePlugin($pluginName); if ($redirectAfter) { $message = $this->translator->translate('CorePluginsAdmin_SuccessfullyActicated', array($pluginName)); if ($this->settingsProvider->getSystemSettings($pluginName)) { $target = sprintf('<a href="index.php%s#%s">', Url::getCurrentQueryStringWithParametersModified(array('module' => 'CoreAdminHome', 'action' => 'generalSettings')), $pluginName); $message .= ' ' . $this->translator->translate('CorePluginsAdmin_ChangeSettingsPossible', array($target, '</a>')); } $notification = new Notification($message); $notification->raw = true; $notification->title = $this->translator->translate('General_WellDone'); $notification->context = Notification::CONTEXT_SUCCESS; Notification\Manager::notify('CorePluginsAdmin_PluginActivated', $notification); $redirectTo = Common::getRequestVar('redirectTo', '', 'string'); if (!empty($redirectTo) && $redirectTo === 'marketplace') { $this->redirectToIndex('Marketplace', 'overview'); } elseif (!empty($redirectTo) && $redirectTo === 'referrer') { $this->redirectAfterModification($redirectAfter); } else { $plugin = $this->pluginManager->loadPlugin($pluginName); $actionToRedirect = 'plugins'; if ($plugin->isTheme()) { $actionToRedirect = 'themes'; } $this->redirectToIndex('CorePluginsAdmin', $actionToRedirect); } } }
private function getSubscritionSummaryMessage() { $url = Url::getCurrentQueryStringWithParametersModified(array('module' => 'Marketplace', 'action' => 'subscriptionOverview')); $link = '<a href="' . $url . '">'; return "<br/>" . $this->translator->translate('Marketplace_ViewSubscriptionsSummary', array($link, '</a>')); }
public function configureView(ViewDataTable $view) { $idGoal = Common::getRequestVar('idGoal', 0, 'string'); $idSite = $this->getIdSite(); if ($view->isViewDataTableId(Sparklines::ID)) { /** @var Sparklines $view */ $isEcommerceEnabled = $this->isEcommerceEnabled($idSite); $onlySummary = Common::getRequestVar('only_summary', 0, 'int'); if ($onlySummary && !empty($idGoal)) { if (is_numeric($idGoal)) { $view->config->title_attributes = array('piwik-goal-page-link' => $idGoal); } // in Goals overview summary we show proper title for a goal $goal = $this->getGoal($idGoal); if (!empty($goal['name'])) { $view->config->title = Piwik::translate('Goals_GoalX', "'" . $goal['name'] . "'"); } } else { $view->config->title = ''; } $numberFormatter = NumberFormatter::getInstance(); $view->config->filters[] = function (DataTable $table) use($numberFormatter, $idSite) { $firstRow = $table->getFirstRow(); if ($firstRow) { $revenue = $firstRow->getColumn('revenue'); $currencySymbol = Site::getCurrencySymbolFor($idSite); $revenue = $numberFormatter->formatCurrency($revenue, $currencySymbol, GoalManager::REVENUE_PRECISION); $firstRow->setColumn('revenue', $revenue); $conversionRate = $firstRow->getColumn('conversion_rate'); if (false !== $conversionRate) { $firstRow->setColumn('conversion_rate', $numberFormatter->formatPercent($conversionRate, $precision = 1)); } $conversions = $firstRow->getColumn('nb_conversions'); if (false !== $conversions) { $firstRow->setColumn('nb_conversions', $numberFormatter->formatNumber($conversions)); } $visitsConverted = $firstRow->getColumn('nb_visits_converted'); if (false !== $visitsConverted) { $firstRow->setColumn('nb_visits_converted', $numberFormatter->formatNumber($visitsConverted)); } } }; $view->config->addTranslations(array('nb_visits' => Piwik::translate('VisitsSummary_NbVisitsDescription'), 'nb_conversions' => Piwik::translate('Goals_ConversionsDescription'), 'nb_visits_converted' => Piwik::translate('General_NVisits'), 'conversion_rate' => Piwik::translate('Goals_OverallConversionRate'), 'revenue' => Piwik::translate('Goals_OverallRevenue'))); $allowMultiple = Common::getRequestVar('allow_multiple', 0, 'int'); if ($allowMultiple) { $view->config->addSparklineMetric(array('nb_conversions', 'nb_visits_converted'), $order = 10); } else { $view->config->addSparklineMetric(array('nb_conversions'), $order = 10); } $view->config->addSparklineMetric(array('conversion_rate'), $order = 20); if (empty($idGoal)) { // goals overview sparklines below evolution graph if ($isEcommerceEnabled) { // this would be ideally done in Ecommerce plugin but then it is hard to keep same order $view->config->addSparklineMetric(array('revenue'), $order = 30); } } else { if ($onlySummary) { // in Goals Overview we list an overview for each goal.... $view->config->addTranslation('conversion_rate', Piwik::translate('Goals_ConversionRate')); } elseif ($isEcommerceEnabled) { // in Goals detail page... $view->config->addSparklineMetric(array('revenue'), $order = 30); } } } else { if ($view->isViewDataTableId(Evolution::ID)) { if (!empty($idSite) && Piwik::isUserHasAdminAccess($idSite)) { $view->config->title_edit_entity_url = 'index.php' . Url::getCurrentQueryStringWithParametersModified(array('module' => 'Goals', 'action' => 'manage', 'forceView' => null, 'viewDataTable' => null, 'showtitle' => null, 'random' => null)); } $goal = $this->getGoal($idGoal); if (!empty($goal['name'])) { $view->config->title = Piwik::translate('Goals_GoalX', "'" . $goal['name'] . "'"); if (!empty($goal['description'])) { $view->config->description = $goal['description']; } } else { $view->config->title = Piwik::translate('General_EvolutionOverPeriod'); } if (empty($view->config->columns_to_display)) { $view->config->columns_to_display = array('nb_conversions'); } } } }
/** * Checks if the current host is valid and sets variables on the given view, including: * * - **isValidHost** - true if host is valid, false if otherwise * - **invalidHostMessage** - message to display if host is invalid (only set if host is invalid) * - **invalidHost** - the invalid hostname (only set if host is invalid) * - **mailLinkStart** - the open tag of a link to email the Super User of this problem (only set * if host is invalid) * * @param View $view * @api */ public static function setHostValidationVariablesView($view) { // check if host is valid $view->isValidHost = Url::isValidHost(); if (!$view->isValidHost) { // invalid host, so display warning to user $validHosts = Url::getTrustedHostsFromConfig(); $validHost = $validHosts[0]; $invalidHost = Common::sanitizeInputValue($_SERVER['HTTP_HOST']); $emailSubject = rawurlencode(Piwik::translate('CoreHome_InjectedHostEmailSubject', $invalidHost)); $emailBody = rawurlencode(Piwik::translate('CoreHome_InjectedHostEmailBody')); $superUserEmail = implode(',', Piwik::getAllSuperUserAccessEmailAddresses()); $mailToUrl = "mailto:{$superUserEmail}?subject={$emailSubject}&body={$emailBody}"; $mailLinkStart = "<a href=\"{$mailToUrl}\">"; $invalidUrl = Url::getCurrentUrlWithoutQueryString($checkIfTrusted = false); $validUrl = Url::getCurrentScheme() . '://' . $validHost . Url::getCurrentScriptName(); $invalidUrl = Common::sanitizeInputValue($invalidUrl); $validUrl = Common::sanitizeInputValue($validUrl); $changeTrustedHostsUrl = "index.php" . Url::getCurrentQueryStringWithParametersModified(array('module' => 'CoreAdminHome', 'action' => 'generalSettings')) . "#trustedHostsSection"; $warningStart = Piwik::translate('CoreHome_InjectedHostWarningIntro', array('<strong>' . $invalidUrl . '</strong>', '<strong>' . $validUrl . '</strong>')) . ' <br/>'; if (Piwik::hasUserSuperUserAccess()) { $view->invalidHostMessage = $warningStart . ' ' . Piwik::translate('CoreHome_InjectedHostSuperUserWarning', array("<a href=\"{$changeTrustedHostsUrl}\">", $invalidHost, '</a>', "<br/><a href=\"{$validUrl}\">", $validHost, '</a>')); } else { if (Piwik::isUserIsAnonymous()) { $view->invalidHostMessage = $warningStart . ' ' . Piwik::translate('CoreHome_InjectedHostNonSuperUserWarning', array("<br/><a href=\"{$validUrl}\">", '</a>', '<span style="display:none">', '</span>')); } else { $view->invalidHostMessage = $warningStart . ' ' . Piwik::translate('CoreHome_InjectedHostNonSuperUserWarning', array("<br/><a href=\"{$validUrl}\">", '</a>', $mailLinkStart, '</a>')); } } $view->invalidHostMessageHowToFix = '<p><b>How do I fix this problem and how do I login again?</b><br/> The Piwik Super User can manually edit the file piwik/config/config.ini.php and add the following lines: <pre>[General]' . "\n" . 'trusted_hosts[] = "' . $invalidHost . '"</pre>After making the change, you will be able to login again.</p> <p>You may also <i>disable this security feature (not recommended)</i>. To do so edit config/config.ini.php and add: <pre>[General]' . "\n" . 'enable_trusted_host_check=0</pre>'; $view->invalidHost = $invalidHost; // for UserSettings warning $view->invalidHostMailLinkStart = $mailLinkStart; } }
/** * Action to generate a new Google Authenticator secret for the current user * * @return string * @throws \Exception * @throws \Piwik\NoAccessException */ public function regenerate() { Piwik::checkUserIsNotAnonymous(); $view = new View('@GoogleAuthenticator/regenerate'); $this->setGeneralVariablesView($view); $googleAuth = new PHPGangsta\GoogleAuthenticator(); $storage = new Storage(Piwik::getCurrentUserLogin()); $secret = Common::getRequestVar('gasecret', '', 'string'); $authCode = Common::getRequestVar('gaauthcode', '', 'string'); $authCodeNonce = Common::getRequestVar('authCodeNonce', '', 'string'); $title = Common::getRequestVar('gatitle', $storage->getTitle(), 'string'); $description = Common::getRequestVar('gadescription', $storage->getDescription(), 'string'); if (!empty($secret) && !empty($authCode) && Nonce::verifyNonce(self::AUTH_CODE_NONCE, $authCodeNonce) && $googleAuth->verifyCode($secret, $authCode, 2)) { $storage->setSecret($secret); $storage->setDescription($description); $storage->setTitle($title); $this->auth->setAuthCode($authCode); $this->auth->validateAuthCode(); Url::redirectToUrl(Url::getCurrentUrlWithoutQueryString() . Url::getCurrentQueryStringWithParametersModified(array('action' => 'settings', 'activate' => '1'))); } if (empty($secret)) { $secret = $googleAuth->createSecret(32); } $view->title = $title; $view->description = $description; $view->authCodeNonce = Nonce::getNonce(self::AUTH_CODE_NONCE); $view->newSecret = $secret; $view->googleAuthImage = $googleAuth->getQRCodeGoogleUrl($description, $secret, $title); return $view->render(); }
public function activate($redirectAfter = true) { $pluginName = $this->initPluginModification(static::ACTIVATE_NONCE); $this->dieIfPluginsAdminIsDisabled(); \Piwik\Plugin\Manager::getInstance()->activatePlugin($pluginName); if ($redirectAfter) { $plugin = \Piwik\Plugin\Manager::getInstance()->loadPlugin($pluginName); $actionToRedirect = 'plugins'; if ($plugin->isTheme()) { $actionToRedirect = 'themes'; } $message = $this->translator->translate('CorePluginsAdmin_SuccessfullyActicated', array($pluginName)); if (SettingsManager::hasSystemPluginSettingsForCurrentUser($pluginName)) { $target = sprintf('<a href="index.php%s#%s">', Url::getCurrentQueryStringWithParametersModified(array('module' => 'CoreAdminHome', 'action' => 'adminPluginSettings')), $pluginName); $message .= ' ' . $this->translator->translate('CorePluginsAdmin_ChangeSettingsPossible', array($target, '</a>')); } $notification = new Notification($message); $notification->raw = true; $notification->title = $this->translator->translate('General_WellDone'); $notification->context = Notification::CONTEXT_SUCCESS; Notification\Manager::notify('CorePluginsAdmin_PluginActivated', $notification); $this->redirectToIndex('CorePluginsAdmin', $actionToRedirect); } }
/** * 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(); }