From d7a30ef317dd8289da2cacbe53edb8a3d43de9c2 Mon Sep 17 00:00:00 2001 From: Partydragen Date: Sat, 4 Jun 2022 13:58:49 +0200 Subject: [PATCH] Fix default language for webhooks --- core/classes/Integrations/IntegrationUser.php | 9 ++++++--- core/init.php | 2 ++ modules/Core/pages/complete_signup.php | 5 +++-- modules/Core/pages/register.php | 5 +++-- modules/Core/pages/validate.php | 5 +++-- modules/Forum/pages/forum/new_topic.php | 3 ++- modules/Forum/pages/forum/view_topic.php | 3 ++- 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/core/classes/Integrations/IntegrationUser.php b/core/classes/Integrations/IntegrationUser.php index 8ca029d8ea..c0d920d63c 100644 --- a/core/classes/Integrations/IntegrationUser.php +++ b/core/classes/Integrations/IntegrationUser.php @@ -112,11 +112,12 @@ public function linkIntegration(User $user, ?string $identifier, ?string $userna ] ); + $default_language = new Language('core', DEFAULT_LANGUAGE); EventHandler::executeEvent('linkIntegrationUser', [ 'integration' => $this->_integration->getName(), 'user_id' => $user->data()->id, 'username' => $user->getDisplayname(), - 'content' => $this->_integration->getLanguage()->get('user', 'user_has_linked_integration', [ + 'content' => $default_language->get('user', 'user_has_linked_integration', [ 'user' => $user->getDisplayname(), 'integration' => $this->_integration->getName(), ]), @@ -142,11 +143,12 @@ public function verifyIntegration(): void { $this->_integration->onSuccessfulVerification($this); $user = $this->getUser(); + $default_language = new Language('core', DEFAULT_LANGUAGE); EventHandler::executeEvent('verifyIntegrationUser', [ 'integration' => $this->_integration->getName(), 'user_id' => $user->data()->id, 'username' => $user->getDisplayname(), - 'content' => $this->_integration->getLanguage()->get('user', 'user_has_verified_integration', [ + 'content' => $default_language->get('user', 'user_has_verified_integration', [ 'user' => $user->getDisplayname(), 'integration' => $this->_integration->getName(), ]), @@ -172,11 +174,12 @@ public function unlinkIntegration(): void { ); $user = $this->getUser(); + $default_language = new Language('core', DEFAULT_LANGUAGE); EventHandler::executeEvent('unlinkIntegrationUser', [ 'integration' => $this->_integration->getName(), 'user_id' => $user->data()->id, 'username' => $user->getDisplayname(), - 'content' => $this->_integration->getLanguage()->get('user', 'user_has_unlinked_integration', [ + 'content' => $default_language->get('user', 'user_has_unlinked_integration', [ 'user' => $user->getDisplayname(), 'integration' => $this->_integration->getName(), ]), diff --git a/core/init.php b/core/init.php index b0fbfbf44d..fdab433ad6 100644 --- a/core/init.php +++ b/core/init.php @@ -185,6 +185,8 @@ } } + define('DEFAULT_LANGUAGE', $default_language); + if (!$user->isLoggedIn() || !($user->data()->language_id)) { // Attempt to get the requested language from the browser if it exists // and if the user has enabled auto language detection diff --git a/modules/Core/pages/complete_signup.php b/modules/Core/pages/complete_signup.php index f828cd0122..8893cfa9fa 100644 --- a/modules/Core/pages/complete_signup.php +++ b/modules/Core/pages/complete_signup.php @@ -71,13 +71,14 @@ 'active' => true, ]); + $default_language = new Language('core', DEFAULT_LANGUAGE); EventHandler::executeEvent('validateUser', [ 'user_id' => $target_user->data()->id, 'username' => $target_user->getDisplayname(), - 'content' => $language->get('user', 'user_x_has_validated', ['user' => $target_user->getDisplayname()]), + 'content' => $default_language->get('user', 'user_x_has_validated', ['user' => $target_user->getDisplayname()]), 'avatar_url' => $target_user->getAvatar(128, true), 'url' => Util::getSelfURL() . ltrim($target_user->getProfileURL(), '/'), - 'language' => $language + 'language' => $default_language ]); Session::flash('home', $language->get('user', 'validation_complete')); diff --git a/modules/Core/pages/register.php b/modules/Core/pages/register.php index 73e770c962..eaf40226d5 100644 --- a/modules/Core/pages/register.php +++ b/modules/Core/pages/register.php @@ -357,15 +357,16 @@ Log::getInstance()->log(Log::Action('user/register'), '', $user_id, Util::getRemoteAddress()); + $default_language = new Language('core', DEFAULT_LANGUAGE); EventHandler::executeEvent('registerUser', [ 'user_id' => $user_id, 'username' => Input::get('username'), - 'content' => $language->get('user', 'user_x_has_registered', [ + 'content' => $default_language->get('user', 'user_x_has_registered', [ 'user' => Input::get('username'), ]), 'avatar_url' => $user->getAvatar(128, true), 'url' => Util::getSelfURL() . ltrim(URL::build('/profile/' . urlencode(Input::get('username'))), '/'), - 'language' => $language, + 'language' => $default_language, ]); if (Util::getSetting('email_verification') === '1') { diff --git a/modules/Core/pages/validate.php b/modules/Core/pages/validate.php index 0564e1e029..706e68003b 100644 --- a/modules/Core/pages/validate.php +++ b/modules/Core/pages/validate.php @@ -25,13 +25,14 @@ 'active' => true, ]); + $default_language = new Language('core', DEFAULT_LANGUAGE); EventHandler::executeEvent('validateUser', [ 'user_id' => $user->data()->id, 'username' => $user->getDisplayname(), - 'content' => $language->get('user', 'user_x_has_validated', ['user' => $user->getDisplayname()]), + 'content' => $default_language->get('user', 'user_x_has_validated', ['user' => $user->getDisplayname()]), 'avatar_url' => $user->getAvatar(128, true), 'url' => Util::getSelfURL() . ltrim($user->getProfileURL(), '/'), - 'language' => $language + 'language' => $default_language ]); GroupSyncManager::getInstance()->broadcastChange( diff --git a/modules/Forum/pages/forum/new_topic.php b/modules/Forum/pages/forum/new_topic.php index 12bfdcb644..ed246b219f 100644 --- a/modules/Forum/pages/forum/new_topic.php +++ b/modules/Forum/pages/forum/new_topic.php @@ -199,13 +199,14 @@ Log::getInstance()->log(Log::Action('forums/topic/create'), Output::getClean(Input::get('title'))); // Execute hooks and pass $available_hooks + $default_forum_language = new Language(ROOT_PATH . '/modules/Forum/language', DEFAULT_LANGUAGE); $available_hooks = DB::getInstance()->get('forums', ['id', $fid])->results(); $available_hooks = json_decode($available_hooks[0]->hooks); EventHandler::executeEvent('newTopic', [ 'user_id' => Output::getClean($user->data()->id), 'username' => $user->getDisplayname(true), 'nickname' => $user->getDisplayname(), - 'content' => $forum_language->get('forum', 'new_topic_text', [ + 'content' => $default_forum_language->get('forum', 'new_topic_text', [ 'forum' => $forum_title, 'author' => $user->getDisplayname(), ]), diff --git a/modules/Forum/pages/forum/view_topic.php b/modules/Forum/pages/forum/view_topic.php index e275894dc7..808e2e86fd 100644 --- a/modules/Forum/pages/forum/view_topic.php +++ b/modules/Forum/pages/forum/view_topic.php @@ -295,13 +295,14 @@ // Execute hooks and pass $available_hooks // TODO: This gets hooks only for this specific forum, not any of its parents... + $default_forum_language = new Language(ROOT_PATH . '/modules/Forum/language', DEFAULT_LANGUAGE); $available_hooks = DB::getInstance()->get('forums', ['id', $topic->forum_id])->results(); $available_hooks = json_decode($available_hooks[0]->hooks); EventHandler::executeEvent('topicReply', [ 'user_id' => $user->data()->id, 'username' => $user->data()->username, 'nickname' => $user->data()->nickname, - 'content' => $forum_language->get('forum', 'new_topic_reply_text', [ + 'content' => $default_forum_language->get('forum', 'new_topic_reply_text', [ 'forum' => $forum_parent[0]->forum_title, 'author' => $user->getDisplayname(), ]),