MyBB Community Forums

Full Version: [F] Notifications in wrong language
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
myBB version: 1.4(1400)

When receiving notifications on new posts, the emails contains the wrong language.
To explain, we are 2 administrators, the other one has set his language to dutch, mine is english standard. The boards default language is set to english.
But the received mail is in dutch.
PHP mail is used, no other parameters.
Is this a bug?
Can anyone confirm this?
The code and db confirm this.

If a user doesn't select a language when s/he registers, but leaves the dropdown at 'Default language', no language is set in the db (empty field). This means the if-statement in lines 870-881 of inc/datahandlers/post.php will fall back to $mybb->settings['bblanguage'], which is the language of the user creating the post.

Rob
(2008-08-07, 11:38 AM)OhReally Wrote: [ -> ]If a user doesn't select a language when s/he registers, but leaves the dropdown at 'Default language', no language is set in the db (empty field). This means the if-statement in lines 870-881 of inc/datahandlers/post.php will fall back to $mybb->settings['bblanguage'], which is the language of the user creating the post.

// Fetch any users subscribed to this thread receiving instant notification and queue up their subscription notices
			$query = $db->query("
				SELECT u.username, u.email, u.uid, u.language, s.subscriptionkey
				FROM ".TABLE_PREFIX."threadsubscriptions s
				LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=s.uid)
				WHERE s.notification='1' AND s.tid='{$post['tid']}'
				AND s.uid != '{$post['uid']}'
				AND u.lastactive>'{$thread['lastpost']}'
			");
			while($subscribedmember = $db->fetch_array($query))
			{
				if($done_users[$subscribedmember['uid']])
				{
					continue;
				}
				$done_users[$subscribedmember['uid']] = 1;
				if($subscribedmember['language'] != '' && $lang->language_exists($subscribedmember['language']))
				{
					$uselang = $subscribedmember['language'];
				}
				elseif($mybb->settings['bblanguage'])
				{
					$uselang = $mybb->settings['bblanguage'];
				}
				else
				{
					$uselang = "english";
				}

				if($uselang == $mybb->settings['bblanguage'])
				{
					$emailsubject = $lang->emailsubject_subscription;
					$emailmessage = $lang->email_subscription;
				}
				else
				{
					if(!isset($langcache[$uselang]['emailsubject_subscription']))
					{
						$userlang = new MyLanguage;
						$userlang->set_path(MYBB_ROOT."inc/languages");
						$userlang->set_language($uselang);
						$userlang->load("messages");
						$langcache[$uselang]['emailsubject_subscription'] = $userlang->emailsubject_subscription;
						$langcache[$uselang]['email_subscription'] = $userlang->email_subscription;
						unset($userlang);
					}
					$emailsubject = $langcache[$uselang]['emailsubject_subscription'];
					$emailmessage = $langcache[$uselang]['email_subscription'];
				}
				$emailsubject = $lang->sprintf($emailsubject, $subject);
				$emailmessage = $lang->sprintf($emailmessage, $subscribedmember['username'], $post['username'], $mybb->settings['bbname'], $subject, $excerpt, $mybb->settings['bburl'], get_thread_link($thread['tid'], 0, "newpost"), $thread['tid'], $subscribedmember['subscriptionkey']);
				$new_email = array(
					"mailto" => $db->escape_string($subscribedmember['email']),
					"mailfrom" => '',
					"subject" => $db->escape_string($emailsubject),
					"message" => $db->escape_string($emailmessage),
					"headers" => ''
				);
				$db->insert_query("mailqueue", $new_email);
				unset($userlang);
				$queued_email = 1;
			}

It loops through each individual user and checks their language, not just the language of the user creating the post.

I don't see what's wrong yet
If a user registers, but does not change the language settings, the 'language' field in th user record in the db will have a value of '' (empty string).

Pseudo code of the code in inc/datahandlers/post.php:
if ((subscribedmember's language is not the empty string) and (the language file exists)) {
    # will not get here, because subscribedmember's language IS the empty string
    use subscribedmember's language;
}
else if (the person who creates the post has set a language) {
    # we use this, because the poster has a prefered language
    use that language;
}
else {
    # will never get here
    use english;
}
Like I said, there's nothing wrong with that. It loops through each subscribed user and sends to their OWN language. The variable is refreshed every loop.
But if the subscribed member has not set a language, the poster's language is used...
No it doesn't. It uses the board's default language. Which would be english

elseif($mybb->settings['bblanguage'])
{
	$uselang = $mybb->settings['bblanguage']; // MyBB's Default language in the global settings
}
Okay, I may be wrong here, but to me it looks like $mybb->settings['bblanguage'] is set to $mybb->input['language'] in global.php.
(2008-08-07, 03:45 PM)OhReally Wrote: [ -> ]Okay, I may be wrong here, but to me it looks like $mybb->settings['bblanguage'] is set to $mybb->input['language'] in global.php.

That's for the "quick language select" feature; the more relevant code is in /inc/class_session.php...

if($mybb->user['language'] && $lang->language_exists($mybb->user['language']))
{
	$mybb->settings['bblanguage'] = $mybb->user['language'];
}

So to reiterate, $mybb->settings['bblanguage'] is not necessarily the board's default language.
Pages: 1 2