From e43ab077bed858206a2ca84269538ed33d362de0 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 30 Jun 2007 18:22:12 +0000 Subject: [PATCH] r1562: - Moving email templates into the locale/ directory so they can be translated into different languages - Adding FetchEmailPath() so that the email template path doens't have to be given every time (since it is rather long) - Updating all the locations where we send emails to use the new paths --- includes/class_notification.php | 39 ++++++++++++------- includes/functions.php | 15 +++++++ .../en_US/emails}/accountapproved.xml.tpl | 0 .../en_US/emails}/activateaccount.xml.tpl | 0 .../en_US/emails}/bugnotification.xml.tpl | 0 .../en_US/emails}/notice_assigned.part.tpl | 0 .../en_US/emails}/notice_attachment.part.tpl | 0 .../en_US/emails}/notice_comment.part.tpl | 0 .../en_US/emails}/notice_duplicates.part.tpl | 0 .../en_US/emails}/notice_new_bug.part.tpl | 0 .../en_US/emails}/notice_other.part.tpl | 0 .../en_US/emails}/notice_priority.part.tpl | 0 .../en_US/emails}/notice_product.part.tpl | 0 .../en_US/emails}/notice_resolution.part.tpl | 0 .../en_US/emails}/notice_severity.part.tpl | 0 .../en_US/emails}/notice_status.part.tpl | 0 .../en_US/emails}/notice_unassigned.part.tpl | 0 .../en_US/emails}/passwordreset.xml.tpl | 0 .../en_US/emails}/welcome.xml.tpl | 0 login.php | 2 +- register.php | 6 +-- 21 files changed, 45 insertions(+), 17 deletions(-) rename {templates/email => locale/en_US/emails}/accountapproved.xml.tpl (100%) rename {templates/email => locale/en_US/emails}/activateaccount.xml.tpl (100%) rename {templates/email => locale/en_US/emails}/bugnotification.xml.tpl (100%) rename {templates/email => locale/en_US/emails}/notice_assigned.part.tpl (100%) rename {templates/email => locale/en_US/emails}/notice_attachment.part.tpl (100%) rename {templates/email => locale/en_US/emails}/notice_comment.part.tpl (100%) rename {templates/email => locale/en_US/emails}/notice_duplicates.part.tpl (100%) rename {templates/email => locale/en_US/emails}/notice_new_bug.part.tpl (100%) rename {templates/email => locale/en_US/emails}/notice_other.part.tpl (100%) rename {templates/email => locale/en_US/emails}/notice_priority.part.tpl (100%) rename {templates/email => locale/en_US/emails}/notice_product.part.tpl (100%) rename {templates/email => locale/en_US/emails}/notice_resolution.part.tpl (100%) rename {templates/email => locale/en_US/emails}/notice_severity.part.tpl (100%) rename {templates/email => locale/en_US/emails}/notice_status.part.tpl (100%) rename {templates/email => locale/en_US/emails}/notice_unassigned.part.tpl (100%) rename {templates/email => locale/en_US/emails}/passwordreset.xml.tpl (100%) rename {templates/email => locale/en_US/emails}/welcome.xml.tpl (100%) diff --git a/includes/class_notification.php b/includes/class_notification.php index 80969ae..43400cd 100644 --- a/includes/class_notification.php +++ b/includes/class_notification.php @@ -281,7 +281,7 @@ class NotificationCenter if ($this->users["$userid"]['options'][0] & $this->registry->emailoptions['notifications']['assignedto'] AND in_array($userid, $this->roles['-notapplicable-'])) { $user = construct_user_display($this->registry->userinfo, false); - eval('$part = "' . $this->registry->template->fetch('email/notice_unassigned.part') . '";'); + eval('$part = "' . $this->registry->template->fetch(FetchEmailPath('notice_unassigned.part', $this->_localeFromUserId($userid))) . '";'); $this->notices["$userid"][] = $part; } } @@ -299,7 +299,7 @@ class NotificationCenter if ($this->users["$userid"]['options'][0] & $this->registry->emailoptions['notifications']['assignedto'] AND in_array($userid, $this->roles['-notapplicable-'])) { $user = construct_user_display($this->registry->userinfo, false); - eval('$email = "' . $this->registry->template->fetch('email/notice_assigned.part') . '";'); + eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_assigned.part', $this->_localeFromUserId($userid))) . '";'); $this->notices["$userid"][] = $email; } } @@ -318,7 +318,7 @@ class NotificationCenter $userlist = $this->fetch_users_with_on_bit('statusresolve'); foreach ($userlist AS $userid => $user) { - eval('$email = "' . $this->registry->template->fetch('email/notice_status.part') . '";'); + eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_status.part', $this->_localeFromUserId($userid))) . '";'); $this->notices["$user[userid]"][] = $email; } } @@ -337,7 +337,7 @@ class NotificationCenter $userlist = $this->fetch_users_with_on_bit('statusresolve'); foreach ($userlist AS $userid => $user) { - eval('$email = "' . $this->registry->template->fetch('email/notice_resolution.part') . '";'); + eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_resolution.part', $this->_localeFromUserId($userid))) . '";'); $this->notices["$user[userid]"][] = $email; } } @@ -356,7 +356,7 @@ class NotificationCenter $userlist = $this->fetch_useres_with_on_bit('duplicates'); foreach ($userlist AS $userid => $user) { - eval('$email = "' . $this->registry->template->fetch('email/notice_duplicates.part') . '";'); + eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_duplicates.part', $this->_localeFromUserId($userid))) . '";'); $this->notices["$user[userid]"][] = $email; } } @@ -375,7 +375,7 @@ class NotificationCenter $userlist = $this->fetch_users_with_on_bit('otherfield'); foreach ($userlist AS $userid => $user) { - eval('$email = "' . $this->registry->template->fetch('email/notice_severity.part') . '";'); + eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_severity.part', $this->_localeFromUserId($userid))) . '";'); $this->notices["$user[userid]"][] = $email; } } @@ -394,7 +394,7 @@ class NotificationCenter $userlist = $this->fetch_users_with_on_bit('otherfield'); foreach ($userlist AS $userid => $user) { - eval('$email = "' . $this->registry->template->fetch('email/notice_priority.part') . '";'); + eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_priority.part', $this->_localeFromUserId($userid))) . '";'); $this->notices["$user[userid]"][] = $email; } } @@ -419,7 +419,7 @@ class NotificationCenter foreach ($userlist AS $userid => $user) { - eval('$email = "' . $this->registry->template->fetch('email/notice_product.part') . '";'); + eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_product.part', $this->_localeFromUserId($userid))) . '";'); $this->notices["$user[userid]"][] = $email; } } @@ -441,7 +441,7 @@ class NotificationCenter $user = construct_user_display($this->registry->userinfo, false); $date = $this->registry->modules['date']->format($this->registry->options['dateformat'], $comment['dateline']); - eval('$email = "' . $this->registry->template->fetch('email/notice_comment.part') . '";'); + eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_comment.part', $this->_localeFromUserId($userid))) . '";'); $this->notices["$userid"][] = $email; } } @@ -461,7 +461,7 @@ class NotificationCenter $userlist = $this->fetch_users_with_on_bit('otherfield'); foreach ($userlist AS $userid => $user) { - eval('$email = "' . $this->registry->template->fetch('email/notice_other.part') . '";'); + eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_other.part', $this->_localeFromUserId($userid))) . '";'); $this->notices["$user[userid]"][] = $email; } } @@ -485,7 +485,7 @@ class NotificationCenter $user = construct_user_display($this->registry->userinfo, false); $obsoletes = implode(', ', (array)$obsolete); - eval('$email = "' . $this->registry->template->fetch('email/notice_attachment.part') . '";'); + eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_attachment.part', $this->_localeFromUserId($userid))) . '";'); $this->notices["$userid"][] = $email; } } @@ -517,7 +517,7 @@ class NotificationCenter { $user = construct_user_display($this->registry->userinfo, false); $product = $this->registry->datastore['product']["$bug[product]"]['title'] . '/' . ($bug['component'] ? $this->registry->datastore['product']["$bug[component]"]['title'] . '/' : '') . $this->registry->datastore['version']["$bug[version]"]['version']; - eval('$email = "' . $this->registry->template->fetch('email/notice_new_bug.part') . '";'); + eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('notice_new_bug.part', $this->_localeFromUserId($userInfo['userid']))) . '";'); $this->notices["$userInfo[userid]"][] = $email; $this->users["$userInfo[userid]"] = $userInfo; unset($this->users["$userInfo[userid]"]['mask'], $this->users["$userInfo[userid]"]['relation']); @@ -590,7 +590,7 @@ class NotificationCenter $parts = implode("\n\n", $noticelist); - eval('$email = "' . $this->registry->template->fetch('email/bugnotification.xml') . '";'); + eval('$email = "' . $this->registry->template->fetch(FetchEmailPath('bugnotification.xml', $this->_localeFromUserId($userid))) . '";'); $email = $this->registry->xml->parse($email); $this->registry->mail->setSubject($email['email']['subject']['value']); $this->registry->mail->setBodyText($email['email']['bodyText']['value']); @@ -605,6 +605,19 @@ class NotificationCenter } } } + + // ################################################################### + /** + * Returns the locale name from a given user ID + * + * @param integer User ID + * + * @return string Locale + */ + function _localeFromUserId($userid) + { + return $this->registry->datastore['language'][$this->users[$userid]['languageid']]['langcode']; + } } /*=====================================================================*\ diff --git a/includes/functions.php b/includes/functions.php index e2c9309..37e1ef7 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -776,6 +776,21 @@ function FetchUserPermissions(&$user) return $perms; } +// ################################################################### +/** +* Fetches the path for an email template, given the name of the +* template and the locale to use +* +* @param string The template name +* @param string Language locale code +* +* @return string Template path +*/ +function FetchEmailPath($name, $locale) +{ + return '../locale/' . $locale . '/emails/' . $name; +} + /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/templates/email/accountapproved.xml.tpl b/locale/en_US/emails/accountapproved.xml.tpl similarity index 100% rename from templates/email/accountapproved.xml.tpl rename to locale/en_US/emails/accountapproved.xml.tpl diff --git a/templates/email/activateaccount.xml.tpl b/locale/en_US/emails/activateaccount.xml.tpl similarity index 100% rename from templates/email/activateaccount.xml.tpl rename to locale/en_US/emails/activateaccount.xml.tpl diff --git a/templates/email/bugnotification.xml.tpl b/locale/en_US/emails/bugnotification.xml.tpl similarity index 100% rename from templates/email/bugnotification.xml.tpl rename to locale/en_US/emails/bugnotification.xml.tpl diff --git a/templates/email/notice_assigned.part.tpl b/locale/en_US/emails/notice_assigned.part.tpl similarity index 100% rename from templates/email/notice_assigned.part.tpl rename to locale/en_US/emails/notice_assigned.part.tpl diff --git a/templates/email/notice_attachment.part.tpl b/locale/en_US/emails/notice_attachment.part.tpl similarity index 100% rename from templates/email/notice_attachment.part.tpl rename to locale/en_US/emails/notice_attachment.part.tpl diff --git a/templates/email/notice_comment.part.tpl b/locale/en_US/emails/notice_comment.part.tpl similarity index 100% rename from templates/email/notice_comment.part.tpl rename to locale/en_US/emails/notice_comment.part.tpl diff --git a/templates/email/notice_duplicates.part.tpl b/locale/en_US/emails/notice_duplicates.part.tpl similarity index 100% rename from templates/email/notice_duplicates.part.tpl rename to locale/en_US/emails/notice_duplicates.part.tpl diff --git a/templates/email/notice_new_bug.part.tpl b/locale/en_US/emails/notice_new_bug.part.tpl similarity index 100% rename from templates/email/notice_new_bug.part.tpl rename to locale/en_US/emails/notice_new_bug.part.tpl diff --git a/templates/email/notice_other.part.tpl b/locale/en_US/emails/notice_other.part.tpl similarity index 100% rename from templates/email/notice_other.part.tpl rename to locale/en_US/emails/notice_other.part.tpl diff --git a/templates/email/notice_priority.part.tpl b/locale/en_US/emails/notice_priority.part.tpl similarity index 100% rename from templates/email/notice_priority.part.tpl rename to locale/en_US/emails/notice_priority.part.tpl diff --git a/templates/email/notice_product.part.tpl b/locale/en_US/emails/notice_product.part.tpl similarity index 100% rename from templates/email/notice_product.part.tpl rename to locale/en_US/emails/notice_product.part.tpl diff --git a/templates/email/notice_resolution.part.tpl b/locale/en_US/emails/notice_resolution.part.tpl similarity index 100% rename from templates/email/notice_resolution.part.tpl rename to locale/en_US/emails/notice_resolution.part.tpl diff --git a/templates/email/notice_severity.part.tpl b/locale/en_US/emails/notice_severity.part.tpl similarity index 100% rename from templates/email/notice_severity.part.tpl rename to locale/en_US/emails/notice_severity.part.tpl diff --git a/templates/email/notice_status.part.tpl b/locale/en_US/emails/notice_status.part.tpl similarity index 100% rename from templates/email/notice_status.part.tpl rename to locale/en_US/emails/notice_status.part.tpl diff --git a/templates/email/notice_unassigned.part.tpl b/locale/en_US/emails/notice_unassigned.part.tpl similarity index 100% rename from templates/email/notice_unassigned.part.tpl rename to locale/en_US/emails/notice_unassigned.part.tpl diff --git a/templates/email/passwordreset.xml.tpl b/locale/en_US/emails/passwordreset.xml.tpl similarity index 100% rename from templates/email/passwordreset.xml.tpl rename to locale/en_US/emails/passwordreset.xml.tpl diff --git a/templates/email/welcome.xml.tpl b/locale/en_US/emails/welcome.xml.tpl similarity index 100% rename from templates/email/welcome.xml.tpl rename to locale/en_US/emails/welcome.xml.tpl diff --git a/login.php b/login.php index a94366a..5e7bb84 100755 --- a/login.php +++ b/login.php @@ -121,7 +121,7 @@ if ($_POST['do'] == 'sendpw') $activator = $funct->rand(25); $db->query("INSERT INTO " . TABLE_PREFIX . "passwordreset (activatorid, dateline, userid) VALUES ('" . $activator . "', " . TIMENOW . ", " . $user->objdata['userid'] . ")"); - eval('$email = "' . $template->fetch('email/passwordreset.xml') . '";'); + eval('$email = "' . $template->fetch(FetchEmailPath('passwordreset.xml', $bugsys->datastore['language'][$user->objdata['languageid']]['langcode'])) . '";'); $email = $bugsys->xml->parse($email); $mail->setSubject($email['email']['subject']['value']); diff --git a/register.php b/register.php index 4d516b1..bcb3f45 100755 --- a/register.php +++ b/register.php @@ -96,7 +96,7 @@ if ($_POST['do'] == 'insert') $db->query("INSERT INTO " . TABLE_PREFIX . "useractivation (userid, activator, dateline, usergroupid) VALUES ($userid, '$activationid', " . TIMENOW . ", 2)"); - eval('$email = "' . $template->fetch('email/activateaccount.xml') . '";'); + eval('$email = "' . $template->fetch(FetchEmailPath('activateaccount.xml', $bugsys->datastore['language'][$bugsys->in['languageid']]['langcode'])) . '";'); $email = $bugsys->xml->parse($email); $mail->setSubject($email['email']['subject']['value']); $mail->setBodyText($email['email']['bodyText']['value']); @@ -110,7 +110,7 @@ if ($_POST['do'] == 'insert') if ($bugsys->options['sendwelcomemail']) { $displayName = $bugsys->in['displayname']; - eval('$email = "' . $template->fetch('email/welcome.xml') . '";'); + eval('$email = "' . $template->fetch(FetchEmailPath('welcome.xml', $bugsys->datastore['language'][$bugsys->in['languageid']]['langcode'])) . '";'); $email = $bugsys->xml->parse($email); $mail->setSubject($email['email']['subject']['value']); $mail->setBodyText($email['email']['bodyText']['value']); @@ -172,7 +172,7 @@ if ($_REQUEST['do'] == 'activate') if ($bugsys->options['sendwelcomemail']) { $displayName = $user['displayname']; - eval('$email = "' . $template->fetch('email/welcome.xml') . '";'); + eval('$email = "' . $template->fetch(FetchEmailPath('welcome.xml', $bugsys->datastore['language'][$user['languageid']]['langcode'])) . '";'); $email = $bugsys->xml->parse($email); $mail->setSubject($email['email']['subject']['value']); $mail->setBodyText($email['email']['bodyText']['value']); -- 2.43.5