diff --git a/classes/admin.php b/classes/admin.php index c0ab1a30..91c9a6c2 100644 --- a/classes/admin.php +++ b/classes/admin.php @@ -68,6 +68,11 @@ class Admin */ public $user; + /** + * @var Lang + */ + protected $lang; + /** * @var Grav\Common\GPM\GPM */ @@ -91,6 +96,7 @@ class Admin $this->uri = $this->grav['uri']; $this->session = $this->grav['session']; $this->user = $this->grav['user']; + $this->lang = $this->grav['user']->language; } /** @@ -156,7 +162,7 @@ class Admin $l = $this->grav['language']; - $this->setMessage($l->translate('PLUGIN_ADMIN.LOGIN_LOGGED_IN'), 'info'); + $this->setMessage($this->translate('PLUGIN_ADMIN.LOGIN_LOGGED_IN'), 'info'); // $redirect_route =$this->getLoginRedirect() ?: $this->uri->route(); $redirect_route = $this->uri->route(); @@ -604,6 +610,11 @@ class Admin } } + /** + * Renders phpinfo + * + * @return string The phpinfo() output + */ function phpinfo() { ob_start(); phpinfo(); @@ -613,4 +624,14 @@ class Admin $pinfo = preg_replace( '%^.*(.*).*$%ms','$1',$pinfo); return $pinfo; } + + /** + * Translate a string to the user-defined language + * + * @param $string the string to translate + */ + public function translate($string) { + return $this->grav['language']->translate($string, [$this->grav['user']->authenticated ? $this->lang : 'en']); + } + } diff --git a/classes/controller.php b/classes/controller.php index fe868f39..75919cd3 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -76,7 +76,6 @@ class AdminController $this->post = $this->getPost($post); $this->route = $route; $this->admin = $this->grav['admin']; - $this->lang = $this->grav['user']->language; } /** @@ -123,15 +122,6 @@ class AdminController $this->grav->redirect($base . '/' . preg_replace('|/+|', '/', $path), $this->redirectCode); } - /** - * Translate a string to the user-defined language - * - * @param $string the string to translate - */ - protected function translate($string) { - return $this->grav['language']->translate('PLUGIN_ADMIN.LOGIN_FAILED', [$this->grav['user']->authenticated ? $this->lang : 'en']); - } - /** * Handle login. * @@ -142,7 +132,7 @@ class AdminController if ($this->admin->authenticate($this->post)) { // should never reach here, redirects first } else { - $this->admin->setMessage($this->translate('PLUGIN_ADMIN.LOGIN_FAILED'), 'error'); + $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.LOGIN_FAILED'), 'error'); } return true; @@ -156,7 +146,7 @@ class AdminController protected function taskLogout() { $this->admin->session()->invalidate()->start(); - $this->admin->setMessage($this->translate('PLUGIN_ADMIN.LOGGED_OUT'), 'info'); + $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.LOGGED_OUT'), 'info'); $this->setRedirect('/logout'); return true; @@ -175,19 +165,19 @@ class AdminController $user = !empty($username) ? User::load($username) : null; if (!isset($this->grav['Email'])) { - $this->admin->setMessage($this->translate('PLUGIN_ADMIN.FORGOT_EMAIL_NOT_CONFIGURED'), 'error'); + $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.FORGOT_EMAIL_NOT_CONFIGURED'), 'error'); $this->setRedirect('/'); return true; } if (!$user || !$user->exists()) { - $this->admin->setMessage($this->translate(['PLUGIN_ADMIN.FORGOT_USERNAME_DOES_NOT_EXIST', $username]), 'error'); + $this->admin->setMessage($this->admin->translate(['PLUGIN_ADMIN.FORGOT_USERNAME_DOES_NOT_EXIST', $username]), 'error'); $this->setRedirect('/forgot'); return true; } if (empty($user->email)) { - $this->admin->setMessage($this->translate(['PLUGIN_ADMIN.FORGOT_CANNOT_RESET_EMAIL_NO_EMAIL', $username]), 'error'); + $this->admin->setMessage($this->admin->translate(['PLUGIN_ADMIN.FORGOT_CANNOT_RESET_EMAIL_NO_EMAIL', $username]), 'error'); $this->setRedirect('/forgot'); return true; } @@ -206,8 +196,8 @@ class AdminController $from = $this->grav['config']->get('plugins.email.from', 'noreply@getgrav.org'); $to = $user->email; - $subject = $this->translate(['PLUGIN_ADMIN.FORGOT_EMAIL_SUBJECT', $sitename]); - $content = $this->translate(['PLUGIN_ADMIN.FORGOT_EMAIL_BODY', $fullname, $reset_link, $author, $sitename]); + $subject = $this->admin->translate(['PLUGIN_ADMIN.FORGOT_EMAIL_SUBJECT', $sitename]); + $content = $this->admin->translate(['PLUGIN_ADMIN.FORGOT_EMAIL_BODY', $fullname, $reset_link, $author, $sitename]); $body = $this->grav['twig']->processTemplate('email/base.html.twig', ['content' => $content]); @@ -218,9 +208,9 @@ class AdminController $sent = $this->grav['Email']->send($message); if ($sent < 1) { - $this->admin->setMessage($this->translate('PLUGIN_ADMIN.FORGOT_FAILED_TO_EMAIL'), 'error'); + $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.FORGOT_FAILED_TO_EMAIL'), 'error'); } else { - $this->admin->setMessage($this->translate(['PLUGIN_ADMIN.FORGOT_INSTRUCTIONS_SENT_VIA_EMAIL', $to]), 'info'); + $this->admin->setMessage($this->admin->translate(['PLUGIN_ADMIN.FORGOT_INSTRUCTIONS_SENT_VIA_EMAIL', $to]), 'info'); } $this->setRedirect('/'); @@ -247,7 +237,7 @@ class AdminController if ($good_token === $token) { if (time() > $expire) { - $this->admin->setMessage($this->translate('PLUGIN_ADMIN.RESET_LINK_EXPIRED'), 'error'); + $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.RESET_LINK_EXPIRED'), 'error'); $this->setRedirect('/forgot'); return true; } @@ -260,13 +250,13 @@ class AdminController $user->filter(); $user->save(); - $this->admin->setMessage($this->translate('PLUGIN_ADMIN.RESET_PASSWORD_RESET'), 'info'); + $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.RESET_PASSWORD_RESET'), 'info'); $this->setRedirect('/'); return true; } } - $this->admin->setMessage($this->translate('PLUGIN_ADMIN.RESET_INVALID_LINK'), 'error'); + $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.RESET_INVALID_LINK'), 'error'); $this->setRedirect('/forgot'); return true; @@ -275,7 +265,7 @@ class AdminController $token = $this->grav['uri']->param('token'); if (empty($user) || empty($token)) { - $this->admin->setMessage($this->translate('PLUGIN_ADMIN.RESET_INVALID_LINK'), 'error'); + $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.RESET_INVALID_LINK'), 'error'); $this->setRedirect('/forgot'); return true; } diff --git a/classes/popularity.php b/classes/popularity.php index c31254f6..d8977037 100644 --- a/classes/popularity.php +++ b/classes/popularity.php @@ -118,7 +118,7 @@ class Popularity $data = array(); foreach ($chart_data as $date => $count) { - $labels[] = self::getGrav()['grav']['language']->translate(['PLUGIN_ADMIN.' . strtoupper(date('D', strtotime($date)))]); + $labels[] = self::getGrav()['grav']['admin']->translate(['PLUGIN_ADMIN.' . strtoupper(date('D', strtotime($date)))]); $data[] = $count; }