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
This commit is contained in:
rub 2007-03-15 23:20:41 +00:00
parent d98c48bc6e
commit 6d2ea02a95
12 changed files with 258 additions and 123 deletions

View file

@ -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
(

View file

@ -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

View file

@ -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
);
}
}

View file

@ -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
@ -293,22 +238,105 @@ 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:
* - 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;
}
@ -413,6 +444,8 @@ WHERE
* 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']]
*
* @return boolean (Ok or not)
*/
function pwg_mail($to, $args = array())
{

View file

@ -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';
?>

View file

@ -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';
?>

View file

@ -577,4 +577,8 @@ $lang['conf_history_guest'] = 'Enregistrer les pages visit
$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';
?>

View file

@ -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';
?>

View file

@ -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());

View file

@ -0,0 +1,6 @@
{lang:hello}
{LINK}
{CPL_CONTENT}

View file

@ -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
);
}
}