Skip to content

Commit

Permalink
Fix default language for webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
partydragen committed Jun 4, 2022
1 parent 957bcd8 commit d7a30ef
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
9 changes: 6 additions & 3 deletions core/classes/Integrations/IntegrationUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]),
Expand All @@ -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(),
]),
Expand All @@ -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(),
]),
Expand Down
2 changes: 2 additions & 0 deletions core/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions modules/Core/pages/complete_signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
5 changes: 3 additions & 2 deletions modules/Core/pages/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
5 changes: 3 additions & 2 deletions modules/Core/pages/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion modules/Forum/pages/forum/new_topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]),
Expand Down
3 changes: 2 additions & 1 deletion modules/Forum/pages/forum/view_topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]),
Expand Down

0 comments on commit d7a30ef

Please sign in to comment.