diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-04-02 05:31:07 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-04-02 05:31:07 +0400 |
commit | 2f7d4c55d4c49c12d4d536c60be7280565d9b786 (patch) | |
tree | cb60db72ce3db0ac0af8fa0a10d29ba76f88af7c /plugins | |
parent | 68d120ce1207aad2e492fd08b4e7cd4578ad8a79 (diff) |
refs #4899 move language selector to user settings for logged in users, still visible for anonymous users + during install
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CoreHome/templates/_topBarTopMenu.twig | 4 | ||||
-rw-r--r-- | plugins/LanguagesManager/Controller.php | 9 | ||||
-rw-r--r-- | plugins/LanguagesManager/LanguagesManager.php | 17 | ||||
-rw-r--r-- | plugins/LanguagesManager/templates/getLanguagesSelector.twig | 4 | ||||
-rw-r--r-- | plugins/UsersManager/Controller.php | 9 | ||||
-rw-r--r-- | plugins/UsersManager/javascripts/usersSettings.js | 1 | ||||
-rw-r--r-- | plugins/UsersManager/templates/userSettings.twig | 15 |
7 files changed, 43 insertions, 16 deletions
diff --git a/plugins/CoreHome/templates/_topBarTopMenu.twig b/plugins/CoreHome/templates/_topBarTopMenu.twig index d403a87ca3..a4dc16b047 100644 --- a/plugins/CoreHome/templates/_topBarTopMenu.twig +++ b/plugins/CoreHome/templates/_topBarTopMenu.twig @@ -3,11 +3,11 @@ {% if menu._html is defined %} {{ menu._html|raw }} {% elseif (menu._url.module == currentModule and (menu._url.action is empty or menu._url.action == currentAction)) %} - <span class="topBarElem topBarElemActive"><strong>{{ label|translate }}</strong></span> | + <span class="topBarElem topBarElemActive"><strong>{{ label|translate }}</strong></span>{% if not loop.last %} |{% endif %} {% else %} <span class="topBarElem" {% if menu._tooltip is defined %}title="{{ menu._tooltip }}"{% endif %}> <a id="topmenu-{{ menu._url.module|lower }}" href="index.php{{ menu._url|urlRewriteWithParameters }}">{{ label|translate }}</a> - </span> | + </span>{% if not loop.last %} | {% endif %} {% endif %} {% endfor %} </div>
\ No newline at end of file diff --git a/plugins/LanguagesManager/Controller.php b/plugins/LanguagesManager/Controller.php index 73cdbddfa6..7240c1fba8 100644 --- a/plugins/LanguagesManager/Controller.php +++ b/plugins/LanguagesManager/Controller.php @@ -20,7 +20,7 @@ class Controller extends \Piwik\Plugin\Controller { /** * anonymous = in the session - * authenticated user = in the session and in DB + * authenticated user = in the session */ public function saveLanguage() { @@ -30,13 +30,8 @@ class Controller extends \Piwik\Plugin\Controller 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(); } } diff --git a/plugins/LanguagesManager/LanguagesManager.php b/plugins/LanguagesManager/LanguagesManager.php index 449d77987d..3815c1942f 100644 --- a/plugins/LanguagesManager/LanguagesManager.php +++ b/plugins/LanguagesManager/LanguagesManager.php @@ -38,6 +38,7 @@ class LanguagesManager extends \Piwik\Plugin 'User.getLanguage' => 'getLanguageToLoad', 'UsersManager.deleteUser' => 'deleteUserLanguage', 'Template.topBar' => 'addLanguagesManagerToOtherTopBar', + 'Template.jsGlobalVariables' => 'jsGlobalVariables', 'Console.addCommands' => 'addConsoleCommands' ); } @@ -65,7 +66,9 @@ class LanguagesManager extends \Piwik\Plugin public function showLanguagesSelector() { - MenuTop::addEntry('LanguageSelector', $this->getLanguagesSelector(), true, $order = 30, true); + if (Piwik::isUserIsAnonymous() || !DbHelper::isInstalled()) { + MenuTop::addEntry('LanguageSelector', $this->getLanguagesSelector(), true, $order = 30, true); + } } /** @@ -82,6 +85,17 @@ class LanguagesManager extends \Piwik\Plugin } /** + * Adds the languages drop-down list to topbars other than the main one rendered + * in CoreHome/templates/top_bar.twig. The 'other' topbars are on the Installation + * and CoreUpdater screens. + */ + public function jsGlobalVariables(&$str) + { + // piwik object & scripts aren't loaded in 'other' topbars + $str .= "piwik.languageName = '" . self::getLanguageNameForCurrentUser() . "';"; + } + + /** * Renders and returns the language selector HTML. * * @return string @@ -91,7 +105,6 @@ class LanguagesManager extends \Piwik\Plugin $view = new View("@LanguagesManager/getLanguagesSelector"); $view->languages = API::getInstance()->getAvailableLanguageNames(); $view->currentLanguageCode = self::getLanguageCodeForCurrentUser(); - $view->currentLanguageName = self::getLanguageNameForCurrentUser(); return $view->render(); } diff --git a/plugins/LanguagesManager/templates/getLanguagesSelector.twig b/plugins/LanguagesManager/templates/getLanguagesSelector.twig index 3533e96f24..0b602d803e 100644 --- a/plugins/LanguagesManager/templates/getLanguagesSelector.twig +++ b/plugins/LanguagesManager/templates/getLanguagesSelector.twig @@ -14,8 +14,4 @@ <input type="submit" value="go"/> </form> </span> - - <script type="text/javascript"> - piwik.languageName = "{{ currentLanguageName }}"; - </script> </span> diff --git a/plugins/UsersManager/Controller.php b/plugins/UsersManager/Controller.php index cd882cfd49..f966fc26c8 100644 --- a/plugins/UsersManager/Controller.php +++ b/plugins/UsersManager/Controller.php @@ -11,10 +11,11 @@ namespace Piwik\Plugins\UsersManager; use Exception; use Piwik\API\ResponseBuilder; use Piwik\Common; -use Piwik\Config; use Piwik\Piwik; +use Piwik\Plugins\LanguagesManager\LanguagesManager; use Piwik\Plugins\SitesManager\API as APISitesManager; use Piwik\Plugins\UsersManager\API as APIUsersManager; +use Piwik\Plugins\LanguagesManager\API as APILanguagesManager; use Piwik\Site; use Piwik\Tracker\IgnoreCookie; use Piwik\Url; @@ -180,6 +181,8 @@ class Controller extends \Piwik\Plugin\ControllerAdmin 'year' => Piwik::translate('General_CurrentYear'), ); + $view->languages = APILanguagesManager::getInstance()->getAvailableLanguageNames(); + $view->currentLanguageCode = LanguagesManager::getLanguageCodeForCurrentUser(); $view->ignoreCookieSet = IgnoreCookie::isIgnoreCookieFound(); $this->initViewAnonymousUserSettings($view); $view->piwikHost = Url::getCurrentHost(); @@ -279,10 +282,14 @@ class Controller extends \Piwik\Plugin\ControllerAdmin $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); diff --git a/plugins/UsersManager/javascripts/usersSettings.js b/plugins/UsersManager/javascripts/usersSettings.js index d50f0321b0..e83e431423 100644 --- a/plugins/UsersManager/javascripts/usersSettings.js +++ b/plugins/UsersManager/javascripts/usersSettings.js @@ -37,6 +37,7 @@ function sendUserSettingsAJAX() { } postParams.defaultReport = defaultReport; postParams.defaultDate = defaultDate; + postParams.language = $('#userSettingsTable #language').val(); var ajaxHandler = new ajaxHelper(); ajaxHandler.addParams({ diff --git a/plugins/UsersManager/templates/userSettings.twig b/plugins/UsersManager/templates/userSettings.twig index 397f31e46e..6053270afa 100644 --- a/plugins/UsersManager/templates/userSettings.twig +++ b/plugins/UsersManager/templates/userSettings.twig @@ -28,6 +28,21 @@ <td><input size="25" value="{{ userEmail }}" id="email"/></td> </tr> <tr> + <td><div style="margin-top: 5px;margin-bottom: 10px;">{{ 'General_Language'|translate }}</div></td> + <td> + <fieldset style="margin-top: 5px;margin-bottom: 10px;"> + <select name="language" id="language" onchange="if (this.value=='') window.open('?module=Proxy&action=redirect&url=http://piwik.org/translations/');"> + <option title="" value="">{{ 'LanguagesManager_AboutPiwikTranslations'|translate }}</option> + {% for language in languages %} + <option value="{{ language.code }}" {% if language.code == currentLanguageCode %}selected="selected"{% endif %} + title="{{ language.name }} ({{ language.english_name }})">{{ language.name }}</option> + {% endfor %} + </select> + <br /> + </fieldset> + </td> + </tr> + <tr> <td>{{ 'UsersManager_ReportToLoadByDefault'|translate }}</td> <td> <fieldset> |