aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrub <rub@piwigo.org>2007-03-15 23:20:41 +0000
committerrub <rub@piwigo.org>2007-03-15 23:20:41 +0000
commit6d2ea02a9591a219f5964ecc98ffa3f7796039fa (patch)
tree81caf2c1745f31910d61ae2dcce316f657ca7f6c
parentd98c48bc6e0e5ab7de21e5252889270ecdea6c89 (diff)
Add new translation functions.inc.php
Translate subject of information mail. Notification mails are sent on the default language. No mail is sent to the author witch are not done actions git-svn-id: http://piwigo.org/svn/trunk@1908 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--admin/cat_modify.php2
-rw-r--r--include/functions.inc.php65
-rw-r--r--include/functions_comment.inc.php31
-rw-r--r--include/functions_mail.inc.php165
-rw-r--r--language/en_UK.iso-8859-1/admin.lang.php4
-rw-r--r--language/en_UK.iso-8859-1/common.lang.php20
-rw-r--r--language/fr_FR.iso-8859-1/admin.lang.php4
-rw-r--r--language/fr_FR.iso-8859-1/common.lang.php20
-rw-r--r--register.php23
-rw-r--r--template/yoga/mail/text/html/admin/cat_group_info.tpl (renamed from template/yoga/mail/text/html/cat_group_info.tpl)2
-rw-r--r--template/yoga/mail/text/plain/admin/cat_group_info.tpl6
-rw-r--r--upload.php35
12 files changed, 256 insertions, 121 deletions
diff --git a/admin/cat_modify.php b/admin/cat_modify.php
index 5571cc439..52521995d 100644
--- a/admin/cat_modify.php
+++ b/admin/cat_modify.php
@@ -565,7 +565,7 @@ SELECT id, file, path, tn_ext
pwg_mail_group(
$_POST['group'],
get_str_email_format(true), /* TODO add a checkbox in order to choose format*/
- $category['name'],
+ get_l10n_args('Come to visit %s', $category['name']),
'cat_group_info',
array
(
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 00a915d90..b69c88a71 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -1018,7 +1018,7 @@ function l10n($key)
{
global $lang, $conf;
- if ($conf['debug_l10n'] and !isset($lang[$key]))
+ if ($conf['debug_l10n'] and !isset($lang[$key]) and !empty($key))
{
echo '[l10n] language key "'.$key.'" is not defined<br />';
}
@@ -1047,6 +1047,69 @@ function l10n_dec($singular_fmt_key, $plural_fmt_key, $decimal)
: $singular_fmt_key
)), $decimal);
}
+/*
+ * returns a single element to use with l10n_args
+ *
+ * @param string key: translation key
+ * @param array/string/../number args:
+ * arguments to use on sprintf($key, args)
+ * if args is a array, each values are used on sprintf
+ * @return string
+ */
+function get_l10n_args($key, $args)
+{
+ if (is_array($args))
+ {
+ $key_arg = array_merge(array($key), $args);
+ }
+ else
+ {
+ $key_arg = array($key, $args);
+ }
+ return array('key_args' => $key_arg);
+}
+
+/*
+ * returns a string with formated with l10n_args elements
+ *
+ * @param element/array $key_args: element or array of l10n_args elements
+ * @param $sep: if $key_args is array,
+ * separator is used when translated l10n_args elements are concated
+ * @return string
+ */
+function l10n_args($key_args, $sep = "\n")
+{
+ if (is_array($key_args))
+ {
+ foreach ($key_args as $key => $element)
+ {
+ if (isset($result))
+ {
+ $result .= $sep;
+ }
+ else
+ {
+ $result = '';
+ }
+
+ if ($key === 'key_args')
+ {
+ array_unshift($element, l10n(array_shift($element)));
+ $result .= call_user_func_array('sprintf', $element);
+ }
+ else
+ {
+ $result .= l10n_args($element, $sep);
+ }
+ }
+ }
+ else
+ {
+ die('l10n_args: Invalid arguments');
+ }
+
+ return $result;
+}
/**
* Translate string in string ascii7bits
diff --git a/include/functions_comment.inc.php b/include/functions_comment.inc.php
index 9db0a4c17..1a894b69d 100644
--- a/include/functions_comment.inc.php
+++ b/include/functions_comment.inc.php
@@ -197,28 +197,27 @@ INSERT INTO '.COMMENTS_TABLE.'
$del_url =
get_absolute_root_url().'comments.php?delete='.$comm['id'];
- $content =
- 'Author: '.$comm['author']."\n"
- .'Comment: '.$comm['content']."\n"
- .get_block_mail_admin_info()
- .'Delete: '.$del_url."\n";
+ $keyargs_content = array
+ (
+ get_l10n_args('Author: %s', $comm['author']),
+ get_l10n_args('Comment: %s', $comm['content']),
+ get_l10n_args('', ''),
+ get_l10n_args('Delete: %s', $del_url)
+ );
if ($comment_action!='validate')
{
- $content .=
- 'Validate: '
- .get_absolute_root_url().'comments.php?validate='.$comm['id'];
+ $keyargs_content[] =
+ get_l10n_args('', '');
+ $keyargs_content[] =
+ get_l10n_args('Validate: %s',
+ get_absolute_root_url().'comments.php?validate='.$comm['id']);
}
- pwg_mail
+ pwg_mail_notification_admins
(
- format_email('administrators', get_webmaster_mail_address()),
- array
- (
- 'subject' => 'PWG comment by '.$comm['author'],
- 'content' => $content,
- 'Bcc' => get_administrators_email()
- )
+ get_l10n_args('Comment by %s', $comm['author']),
+ $keyargs_content
);
}
}
diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php
index 8080e2243..ffafc2305 100644
--- a/include/functions_mail.inc.php
+++ b/include/functions_mail.inc.php
@@ -154,61 +154,6 @@ function get_str_email_format($is_html)
return ($is_html ? 'text/html' : 'text/plain');
}
-/**
- * Returns email of all administrator
- *
- * @return string
- */
-function get_administrators_email()
-{
- global $conf;
-
- $result = array();
-
- $query = '
-select
- U.'.$conf['user_fields']['username'].' as username,
- U.'.$conf['user_fields']['email'].' as mail_address
-from
- '.USERS_TABLE.' as U,
- '.USER_INFOS_TABLE.' as I
-where
- I.user_id = U.'.$conf['user_fields']['id'].' and
- I.status in (\'webmaster\', \'admin\') and
- I.adviser = \'false\' and
- '.$conf['user_fields']['email'].' is not null
-order by
- username
-';
-
- $datas = pwg_query($query);
- if (!empty($datas))
- {
- while ($admin = mysql_fetch_array($datas))
- {
- if (!empty($admin['mail_address']))
- {
- array_push($result, format_email($admin['username'], $admin['mail_address']));
- }
- }
- }
-
- return $result;
-}
-
-/* Return a standard block useful for admin mail */
-function get_block_mail_admin_info()
-{
- global $user;
-
- return
- "\n"
- .'Connected user: '.$user['username']."\n"
- .'IP: '.$_SERVER['REMOTE_ADDR']."\n"
- .'Browser: '.$_SERVER['HTTP_USER_AGENT']."\n"
- ."\n";
-}
-
/*
* Switch language to param language
* All entries are push on language stack
@@ -292,23 +237,106 @@ function switch_lang_back()
}
}
}
+
+/**
+ * Returns email of all administrator
+ *
+ * @return string
+ */
+/*
+ * send en notification email to all administrators
+ * if a administrator is doing action,
+ * he's be removed to email list
+ *
+ * @param:
+ * - keyargs_subject: mail subject on l10n_args format
+ * - keyargs_content: mail content on l10n_args format
+ *
+ * @return boolean (Ok or not)
+ */
+function pwg_mail_notification_admins($keyargs_subject, $keyargs_content)
+{
+ global $conf, $user;
+ $return = true;
+
+ $admins = array();
+
+ $query = '
+select
+ U.'.$conf['user_fields']['username'].' as username,
+ U.'.$conf['user_fields']['email'].' as mail_address
+from
+ '.USERS_TABLE.' as U,
+ '.USER_INFOS_TABLE.' as I
+where
+ I.user_id = U.'.$conf['user_fields']['id'].' and
+ I.status in (\'webmaster\', \'admin\') and
+ I.adviser = \'false\' and
+ '.$conf['user_fields']['email'].' is not null and
+ I.user_id <> '.$user['id'].'
+order by
+ username
+';
+
+ $datas = pwg_query($query);
+ if (!empty($datas))
+ {
+ while ($admin = mysql_fetch_array($datas))
+ {
+ if (!empty($admin['mail_address']))
+ {
+ array_push($admins, format_email($admin['username'], $admin['mail_address']));
+ }
+ }
+ }
+
+ $keyargs_content_admin_info = array
+ (
+ get_l10n_args('Connected user: %s', $user['username']),
+ get_l10n_args('IP: %s', $_SERVER['REMOTE_ADDR']),
+ get_l10n_args('Browser: %s', $_SERVER['HTTP_USER_AGENT'])
+ );
+
+ switch_lang_to($conf['default_language']);
+
+ $return = pwg_mail
+ (
+ '',
+ array
+ (
+ 'Bcc' => $admins,
+ 'subject' => '['.$conf['gallery_title'].'] '.l10n_args($keyargs_subject),
+ 'content' =>
+ l10n_args($keyargs_content)."\n\n"
+ .l10n_args($keyargs_content_admin_info)."\n",
+ 'content_format' => 'text/plain'
+ )
+ ) and $return;
+
+ switch_lang_back();
+
+ return $return;
+}
/*
* send en email to user's group
*
- * @param:
+ * @param:
* - group_id: mail are sent to group with this Id
* - email_format: mail format
- * - key_subject: TODO Include translations
+ * - keyargs_subject: mail subject on l10n_args format
* - tpl_shortname: short template name without extension
* - assign_vars: array used to assign_vars to mail template
* - language_selected: send mail only to user with this selected language
-*/
+ *
+ * @return boolean (Ok or not)
+ */
function pwg_mail_group(
- $group_id, $email_format, $key_subject,
+ $group_id, $email_format, $keyargs_subject,
$tpl_shortname, $assign_vars = array(), $language_selected = '')
{
global $conf;
+ $return = true;
$query = '
SELECT
@@ -342,7 +370,6 @@ WHERE
}
}
-
foreach ($list as $elem)
{
$query = '
@@ -375,26 +402,30 @@ WHERE
switch_lang_to($elem['language']);
$mail_template = get_mail_template($email_format, $elem);
- $mail_template->set_filename($tpl_shortname, $tpl_shortname.'.tpl');
+ $mail_template->set_filename($tpl_shortname,
+ (IN_ADMIN ? 'admin/' : '').$tpl_shortname.'.tpl');
$mail_template->assign_vars($assign_vars);
- pwg_mail
+ $return = pwg_mail
(
'',
array
- (
- 'subject' => $key_subject,
+ (
+ 'Bcc' => $Bcc,
+ 'subject' => l10n_args($keyargs_subject),
'email_format' => $email_format,
'content' => $mail_template->parse($tpl_shortname, true),
'content_format' => $email_format,
'template' => $elem['template'],
'theme' => $elem['theme']
)
- );
+ ) and $return;
switch_lang_back();
}
}
+
+ return $return;
}
@@ -412,7 +443,9 @@ WHERE
* o content_format: format of mail content [default value 'text/plain']
* o email_format: global mail format [default value $conf_mail['default_email_format']]
* o template: template to use [default $conf['default_template']]
- * o theme: template to use [default $conf['default_template']]
+ * o theme: template to use [default $conf['default_template']]
+ *
+ * @return boolean (Ok or not)
*/
function pwg_mail($to, $args = array())
{
diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php
index 3c5dbffff..43895ce78 100644
--- a/language/en_UK.iso-8859-1/admin.lang.php
+++ b/language/en_UK.iso-8859-1/admin.lang.php
@@ -578,4 +578,8 @@ $lang['conf_history_guest'] = 'Save page visits by guests';
$lang['conf_history_user'] = 'Save page visits by users';
$lang['conf_history_admin'] = 'Save page visits by administrators';
$lang['cat_options_title'] = 'Properties';
+$lang['An information email was sent to group "%s"'] = 'An information email was sent to group "%s';
+$lang['Send an information email to group members'] = 'Send an information email to group members';
+$lang['Group'] = 'Group';
+$lang['Come to visit %s'] = 'Come to visit %s';
?>
diff --git a/language/en_UK.iso-8859-1/common.lang.php b/language/en_UK.iso-8859-1/common.lang.php
index 95b4467ff..af5f923ab 100644
--- a/language/en_UK.iso-8859-1/common.lang.php
+++ b/language/en_UK.iso-8859-1/common.lang.php
@@ -4,8 +4,7 @@
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
-// | branch : BSF (Best So Far)
-// | file : $RCSfile$
+// | file : $Id$
// | last update : $Date$
// | last modifier : $Author$
// | revision : $Revision$
@@ -615,4 +614,21 @@ $lang['w_month'] = 'Month';
$lang['yes'] = 'Yes';
$lang['page_end'] = 'Page bottom';
$lang['qsearch'] = 'Quick search';
+$lang['Connected user: %s'] = 'Connected user: %s';
+$lang['IP: %s'] = 'IP: %s';
+$lang['Browser: %s'] = 'Browser: %s';
+$lang['Author: %s'] = 'Author: %s';
+$lang['Comment: %s'] = 'Comment: %s';
+$lang['Delete: %s'] = 'Delete: %s';
+$lang['Validate: %s'] = 'Validate: %s';
+$lang['Comment by %s'] = 'Comment by %s';
+$lang['User: %s'] = 'User: %s';
+$lang['Email: %s'] = 'Email: %s';
+$lang['Admin: %s'] = 'Admin: %s';
+$lang['Registration of %s'] = 'Registration of %s';
+$lang['Category: %s'] = 'Category: %s';
+$lang['Picture name: %s'] = 'Picture name: %s';
+$lang['Creation date: %s'] = 'Creation date: %s';
+$lang['Waiting page: %s'] = 'Waiting page: %s';
+$lang['Picture uploaded by %s'] = 'Picture uploaded by %s';
?>
diff --git a/language/fr_FR.iso-8859-1/admin.lang.php b/language/fr_FR.iso-8859-1/admin.lang.php
index ab572556b..a791b78a0 100644
--- a/language/fr_FR.iso-8859-1/admin.lang.php
+++ b/language/fr_FR.iso-8859-1/admin.lang.php
@@ -577,4 +577,8 @@ $lang['conf_history_guest'] = 'Enregistrer les pages visitées par les invités';
$lang['conf_history_user'] = 'Enregistrer les pages visitées par les utilisateurs';
$lang['conf_history_admin'] = 'Enregistrer les pages visitées par les administrateurs';
$lang['cat_options_title'] = 'Propriétés';
+$lang['An information email was sent to group "%s"'] = 'Un mail d\'informations a été envoyé aux membres du groupe';
+$lang['Send an information email to group members'] = 'Envoyer un mail d\'informations aux membres d\'un groupe';
+$lang['Group'] = 'Groupe';
+$lang['Come to visit %s'] = 'Venez visiter %s';
?>
diff --git a/language/fr_FR.iso-8859-1/common.lang.php b/language/fr_FR.iso-8859-1/common.lang.php
index b0c6ff5ba..3ae1f0d8b 100644
--- a/language/fr_FR.iso-8859-1/common.lang.php
+++ b/language/fr_FR.iso-8859-1/common.lang.php
@@ -4,8 +4,7 @@
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
-// | branch : BSF (Best So Far)
-// | file : $RCSfile$
+// | file : $Id$
// | last update : $Date$
// | last modifier : $Author$
// | revision : $Revision$
@@ -615,4 +614,21 @@ $lang['w_month'] = 'Mois';
$lang['yes'] = 'Oui';
$lang['page_end'] = 'Bas de page';
$lang['qsearch'] = 'Recherche rapide';
+$lang['Connected user: %s'] = 'Utilisateur connecté: %s';
+$lang['IP: %s'] = 'IP: %s';
+$lang['Browser: %s'] = 'Navigateur: %s';
+$lang['Author: %s'] = 'Auteur: %s';
+$lang['Comment: %s'] = 'Commentaire: %s';
+$lang['Delete: %s'] = 'Suppression: %s';
+$lang['Validate: %s'] = 'Validation: %s';
+$lang['Comment by %s'] = 'Commentaire par %s';
+$lang['User: %s'] = 'Utilisateur: %s';
+$lang['Email: %s'] = 'Email: %s';
+$lang['Admin: %s'] = 'Administration: %s';
+$lang['Registration of %s'] = 'Enregistrement de %s';
+$lang['Category: %s'] = 'Catégorie: %s';
+$lang['Picture name: %s'] = 'Nom de l\'image: %s';
+$lang['Creation date: %s'] = 'Date de création: %d';
+$lang['Waiting page: %s'] = 'Page en attente: %s';
+$lang['Picture uploaded by %s'] = 'Image téléchargée par %s';
?>
diff --git a/register.php b/register.php
index 5d1e4e183..4d86d5e3b 100644
--- a/register.php
+++ b/register.php
@@ -69,21 +69,18 @@ if (isset($_POST['submit']))
$admin_url = get_absolute_root_url()
.'admin.php?page=user_list&username='.$username;
- $content =
- 'User: '.$username."\n"
- .'Mail: '.$_POST['mail_address']."\n"
- .get_block_mail_admin_info()
- .'Admin'.': '.$admin_url;
+ $keyargs_content = array
+ (
+ get_l10n_args('User: %s', $username),
+ get_l10n_args('Email: %s', $_POST['mail_address']),
+ get_l10n_args('', ''),
+ get_l10n_args('Admin: %s', $admin_url)
+ );
- pwg_mail
+ pwg_mail_notification_admins
(
- format_email('administrators', get_webmaster_mail_address()),
- array
- (
- 'subject' => 'PWG '.l10n('register_title').' '.$username,
- 'content' => $content,
- 'Bcc' => get_administrators_email()
- )
+ get_l10n_args('Registration of %s', $username),
+ $keyargs_content
);
}
redirect(make_index_url());
diff --git a/template/yoga/mail/text/html/cat_group_info.tpl b/template/yoga/mail/text/html/admin/cat_group_info.tpl
index f5c8973de..664c8701e 100644
--- a/template/yoga/mail/text/html/cat_group_info.tpl
+++ b/template/yoga/mail/text/html/admin/cat_group_info.tpl
@@ -3,5 +3,5 @@
<p>{IMG_URL}</p>
<p>{lang:hello}</p>
<p><a href="{LINK}">{LINK}</a></p>
-<p>{CPL_CONTENT}</p>
+<p>{CPL_CONTENT}</p>
</div>
diff --git a/template/yoga/mail/text/plain/admin/cat_group_info.tpl b/template/yoga/mail/text/plain/admin/cat_group_info.tpl
new file mode 100644
index 000000000..9969824b8
--- /dev/null
+++ b/template/yoga/mail/text/plain/admin/cat_group_info.tpl
@@ -0,0 +1,6 @@
+{lang:hello}
+
+{LINK}
+
+{CPL_CONTENT}
+
diff --git a/upload.php b/upload.php
index 36aba5b7d..48d36d793 100644
--- a/upload.php
+++ b/upload.php
@@ -229,27 +229,24 @@ if ( isset( $_POST['submit'] ) and !isset( $_GET['waiting_id'] ) )
$waiting_url = get_absolute_root_url().'admin.php?page=waiting';
- $content =
- 'Category: '.get_cat_display_name($category['upper_names'], null, false)."\n"
- .'Picture name: '.$_FILES['picture']['name']."\n"
- .'User: '.$_POST['username']."\n"
- .'Email: '.$_POST['mail_address']."\n"
- .'Picture name: '.$_POST['name']."\n"
- .'Author: '.$_POST['author']."\n"
- .'Creation Date: '.$_POST['date_creation']."\n"
- .'Comment: '.$_POST['comment']."\n"
- .get_block_mail_admin_info()
- .'Waiting page: '.$waiting_url."\n";
+ $keyargs_content = array
+ (
+ get_l10n_args('Category: %s', get_cat_display_name($category['upper_names'], null, false)),
+ get_l10n_args('Picture name: %s', $_FILES['picture']['name']),
+ get_l10n_args('User: %s', $_POST['username']),
+ get_l10n_args('Email: %s', $_POST['mail_address']),
+ get_l10n_args('Picture name: %s', $_POST['name']),
+ get_l10n_args('Author: %s', $_POST['author']),
+ get_l10n_args('Creation date: %s', $_POST['date_creation']),
+ get_l10n_args('Comment: %s', $_POST['comment']),
+ get_l10n_args('', ''),
+ get_l10n_args('Waiting page: %s', $waiting_url)
+ );
- pwg_mail
+ pwg_mail_notification_admins
(
- format_email('administrators', get_webmaster_mail_address()),
- array
- (
- 'subject' => 'PWG picture uploaded by '.$_POST['username'],
- 'content' => $content,
- 'Bcc' => get_administrators_email()
- )
+ get_l10n_args('Picture uploaded by %s', $_POST['username']),
+ $keyargs_content
);
}
}