Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feature 2995: New email template
restore get_l10n_args removed at r25357
apply changes to NBM

git-svn-id: http://piwigo.org/svn/trunk@25360 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
mistic100 committed Nov 6, 2013
1 parent 6863606 commit fc3b787
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 112 deletions.
33 changes: 17 additions & 16 deletions admin/include/functions_notification_by_mail.inc.php
Expand Up @@ -256,8 +256,7 @@ function set_user_on_env_nbm(&$nbm_user, $is_action_send)

if ($is_action_send)
{
$nbm_user['theme'] = $user['theme'];
$env_nbm['mail_template'] = get_mail_template($env_nbm['email_format'], $nbm_user['theme']);
$env_nbm['mail_template'] = get_mail_template($env_nbm['email_format']);
$env_nbm['mail_template']->set_filename('notification_by_mail', 'notification_by_mail.tpl');
}
}
Expand Down Expand Up @@ -423,7 +422,7 @@ function do_subscribe_unsubscribe_notification_by_mail($is_admin_request, $is_su
// set env nbm user
set_user_on_env_nbm($nbm_user, true);

$subject = '['.$conf['gallery_title'].']: '.($is_subscribe ? l10n('Subscribe to notification by mail'): l10n('Unsubscribe from notification by mail'));
$subject = '['.$conf['gallery_title'].'] '.($is_subscribe ? l10n('Subscribe to notification by mail'): l10n('Unsubscribe from notification by mail'));

// Assign current var for nbm mail
assign_vars_nbm_mail_content($nbm_user);
Expand All @@ -439,20 +438,22 @@ function do_subscribe_unsubscribe_notification_by_mail($is_admin_request, $is_su
'GOTO_GALLERY_URL' => get_gallery_home_url(),
)
);

$ret = pwg_mail(
array(
'name' => stripslashes($nbm_user['username']),
'email' => $nbm_user['mail_address'],
),
array(
'from' => $env_nbm['send_as_mail_formated'],
'subject' => $subject,
'email_format' => $env_nbm['email_format'],
'content' => $env_nbm['mail_template']->parse('notification_by_mail', true),
'content_format' => $env_nbm['email_format'],
)
);

if (pwg_mail
(
format_email(stripslashes($nbm_user['username']), $nbm_user['mail_address']),
array
(
'from' => $env_nbm['send_as_mail_formated'],
'subject' => $subject,
'email_format' => $env_nbm['email_format'],
'content' => $env_nbm['mail_template']->parse('notification_by_mail', true),
'content_format' => $env_nbm['email_format'],
'theme' => $nbm_user['theme']
)
))
if ($ret)
{
inc_mail_sent_success($nbm_user);
}
Expand Down
30 changes: 16 additions & 14 deletions admin/notification_by_mail.php
Expand Up @@ -305,7 +305,7 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l

if ($exist_data)
{
$subject = '['.$conf['gallery_title'].']: '.l10n('New photos added');
$subject = '['.$conf['gallery_title'].'] '.l10n('New photos added');

// Assign current var for nbm mail
assign_vars_nbm_mail_content($nbm_user);
Expand Down Expand Up @@ -377,20 +377,22 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
'SEND_AS_NAME' => $env_nbm['send_as_name'],
)
);

$ret = pwg_mail(
array(
'name' => stripslashes($nbm_user['username']),
'email' => $nbm_user['mail_address'],
),
array(
'from' => $env_nbm['send_as_mail_formated'],
'subject' => $subject,
'email_format' => $env_nbm['email_format'],
'content' => $env_nbm['mail_template']->parse('notification_by_mail', true),
'content_format' => $env_nbm['email_format'],
)
);

if (pwg_mail
(
format_email(stripslashes($nbm_user['username']), $nbm_user['mail_address']),
array
(
'from' => $env_nbm['send_as_mail_formated'],
'subject' => $subject,
'email_format' => $env_nbm['email_format'],
'content' => $env_nbm['mail_template']->parse('notification_by_mail', true),
'content_format' => $env_nbm['email_format'],
'theme' => $nbm_user['theme']
)
))
if ($ret)
{
inc_mail_sent_success($nbm_user);

Expand Down
2 changes: 1 addition & 1 deletion include/functions.inc.php
Expand Up @@ -1026,7 +1026,7 @@ function l10n_dec($singular_fmt_key, $plural_fmt_key, $decimal)
* if args is a array, each values are used on sprintf
* @return string
*/
function get_l10n_args($key, $args)
function get_l10n_args($key, $args='')
{
if (is_array($args))
{
Expand Down
50 changes: 25 additions & 25 deletions include/functions_comment.inc.php
Expand Up @@ -232,22 +232,22 @@ function insert_user_comment( &$comm, $key, &$infos )

$comment_url = get_absolute_root_url().'comments.php?comment_id='.$comm['id'];

$content = array(
l10n('Author: %s', stripslashes($comm['author']) ),
l10n('Email: %s', stripslashes($comm['email']) ),
l10n('Comment: %s', stripslashes($comm['content']) ),
'',
l10n('Manage this user comment: %s', $comment_url),
$keyargs_content = array(
get_l10n_args('Author: %s', stripslashes($comm['author']) ),
get_l10n_args('Email: %s', stripslashes($comm['email']) ),
get_l10n_args('Comment: %s', stripslashes($comm['content']) ),
get_l10n_args(''),
get_l10n_args('Manage this user comment: %s', $comment_url),
);

if ('moderate' == $comment_action)
{
$content[] = l10n('(!) This comment requires validation');
$keyargs_content[] = get_l10n_args('(!) This comment requires validation');
}

pwg_mail_notification_admins(
l10n('Comment by %s', stripslashes($comm['author']) ),
implode("\n", $content)
get_l10n_args('Comment by %s', stripslashes($comm['author']) ),
$keyargs_content
);
}
}
Expand Down Expand Up @@ -373,17 +373,17 @@ function update_user_comment($comment, $post_key)

$comment_url = get_absolute_root_url().'comments.php?comment_id='.$comment['comment_id'];

$content = array(
l10n('Author: %s', stripslashes($GLOBALS['user']['username']) ),
l10n('Comment: %s', stripslashes($comment['content']) ),
'',
l10n('Manage this user comment: %s', $comment_url),
l10n('(!) This comment requires validation'),
$keyargs_content = array(
get_l10n_args('Author: %s', stripslashes($GLOBALS['user']['username']) ),
get_l10n_args('Comment: %s', stripslashes($comment['content']) ),
get_l10n_args(''),
get_l10n_args('Manage this user comment: %s', $comment_url),
get_l10n_args('(!) This comment requires validation'),
);

pwg_mail_notification_admins(
l10n('Comment by %s', stripslashes($GLOBALS['user']['username']) ),
implode("\n", $content)
get_l10n_args('Comment by %s', stripslashes($GLOBALS['user']['username']) ),
$keyargs_content
);
}
// just mail admin
Expand All @@ -410,24 +410,24 @@ function email_admin($action, $comment)

include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');

$content = array(
l10n('Author: %s', $comment['author']),
$keyargs_content = array(
get_l10n_args('Author: %s', $comment['author']),
);

if ($action=='delete')
{
$content[] = l10n('This author removed the comment with id %d', $comment['comment_id']);
$keyargs_content[] = get_l10n_args('This author removed the comment with id %d', $comment['comment_id']);
}
else
{
$content[] = l10n('This author modified following comment:');
$content[] = l10n('Comment: %s', $comment['content']);
$keyargs_content[] = get_l10n_args('This author modified following comment:');
$keyargs_content[] = get_l10n_args('Comment: %s', $comment['content']);
}

pwg_mail_notification_admins(
l10n('Comment by %s', $comment['author']),
implode("\n", $content)
);
get_l10n_args('Comment by %s', $comment['author']),
$keyargs_content
);
}

function get_comment_author_id($comment_id, $die_on_error=true)
Expand Down
49 changes: 33 additions & 16 deletions include/functions_mail.inc.php
Expand Up @@ -167,6 +167,16 @@ function &get_mail_template($email_format)
return $template;
}

/**
* Return string email format (text/html or text/plain)
* @param bool is_html
* @return string
*/
function get_str_email_format($is_html)
{
return ($is_html ? 'text/html' : 'text/plain');
}

/**
* Switch language to specified language
* All entries are push on language stack
Expand Down Expand Up @@ -255,8 +265,8 @@ function switch_lang_back()
/**
* Send a notification email to all administrators
* current user (if admin) is not notified
* @param string $subject
* @param string $content
* @param string|array $subject
* @param string|array $content
* @param boolean $send_technical_details - send user IP and browser
* @return boolean
*/
Expand All @@ -266,26 +276,33 @@ function pwg_mail_notification_admins($subject, $content, $send_technical_detail
{
return false;
}

// for backward compatibility < 2.6
if (is_array($subject))
{
$subject = l10n_args($subject);
}
if (is_array($content))

global $conf, $user;

if (is_array($subject) or is_array($content))
{
$content = l10n_args($content);
switch_lang_to(get_default_language());

if (is_array($subject))
{
$subject = l10n_args($subject);
}
if (is_array($content))
{
$content = l10n_args($content);
}

switch_lang_back();
}

global $conf, $user;

$tpl_vars = array();
if ($send_technical_details)
{
$tpl_vars['TECHNICAL'] =
l10n('Connected user: %s', stripslashes($user['username'])) ."\n".
l10n('IP: %s', $_SERVER['REMOTE_ADDR']) . "\n" .
l10n('Browser: %s', $_SERVER['HTTP_USER_AGENT']);
$tpl_vars['TECHNICAL'] = array(
'username' => stripslashes($user['username']),
'ip' => $_SERVER['REMOTE_ADDR'],
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
);
}

return pwg_mail_admins(
Expand Down
14 changes: 7 additions & 7 deletions include/functions_user.inc.php
Expand Up @@ -229,16 +229,16 @@ function register_user($login, $password, $mail_address, $notify_admin=true, &$e
include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
$admin_url = get_absolute_root_url().'admin.php?page=user_list&username='.$login;

$content = array(
l10n('User: %s', stripslashes($login) ),
l10n('Email: %s', $_POST['mail_address']),
'',
l10n('Admin: %s', $admin_url),
$keyargs_content = array(
get_l10n_args('User: %s', stripslashes($login) ),
get_l10n_args('Email: %s', $_POST['mail_address']),
get_l10n_args(''),
get_l10n_args('Admin: %s', $admin_url),
);

pwg_mail_notification_admins(
l10n('Registration of %s', stripslashes($login) ),
implode("\n", $content)
get_l10n_args('Registration of %s', stripslashes($login) ),
$keyargs_content
);
}

Expand Down
Expand Up @@ -2,6 +2,8 @@

{if isset($TECHNICAL)}
<p style="padding-top:10px;font-size:11px;">
{$TECHNICAL|nl2br}
{'Connected user: %s'|translate:$TECHNICAL.username}<br>
{'IP: %s'|translate:$TECHNICAL.ip}<br>
{'Browser: %s'|translate:$TECHNICAL.user_agent}
</p>
{/if}
Expand Up @@ -38,13 +38,13 @@
{/if}
<p>{'See you soon,'|@translate}</p>
<p style="text-align:center">{$SEND_AS_NAME}</p>
<hr>
<p>
<br><hr>
{'To unsubscribe'|@translate}{', click on'|@translate} <a href="{$UNSUBSCRIBE_LINK}">{$UNSUBSCRIBE_LINK}</a><br>
{'To subscribe'|@translate}{', click on'|@translate} <a href="{$SUBSCRIBE_LINK}">{$SUBSCRIBE_LINK}</a><br>
{'If you encounter problems or have any question, please send a message to'|@translate} <a href="mailto:{$CONTACT_EMAIL}?subject={'[NBM] Problems or questions'|@translate}">{$CONTACT_EMAIL}</a><br>
<hr><br>
</p>
<hr>
{if not empty($recent_posts)}
</div>
<div id="nbm_recent_post">
Expand Down
Expand Up @@ -2,5 +2,7 @@

{if isset($TECHNICAL)}
-----------------------------
{$TECHNICAL}
{'Connected user: %s'|translate:$TECHNICAL.username}
{'IP: %s'|translate:$TECHNICAL.ip}
{'Browser: %s'|translate:$TECHNICAL.user_agent}
{/if}
34 changes: 5 additions & 29 deletions tools/triggers_list.php
Expand Up @@ -567,12 +567,6 @@
'vars' => array('string', 'username'),
'files' => array('include\functions_user.inc.php (auto_login, try_log_user)'),
),
array(
'name' => 'mail_group_assign_vars',
'type' => 'trigger_event',
'vars' => array('array', 'assign_vars'),
'files' => array('include\functions_mail.inc.php (pwg_mail_group)'),
),
array(
'name' => 'nbm_event_handler_added',
'type' => 'trigger_action',
Expand Down Expand Up @@ -706,33 +700,15 @@
'files' => array('profile.php (save_profile_from_post)'),
),
array(
'name' => 'send_mail',
'name' => 'before_send_mail',
'type' => 'trigger_event',
'vars' => array('bool', 'result', 'string', 'mail_to', 'string', 'mail_subject', 'string', 'mail_content', 'array', 'mail_headers'),
'vars' => array('bool', 'result', 'mixed', 'to', 'array', 'arguments', 'PHPMailer', 'mail'),
'files' => array('include\functions_mail.inc.php (pwg_mail)'),
),
array(
'name' => 'send_mail_content',
'type' => 'trigger_event',
'vars' => array('string', 'content'),
'files' => array('include\functions_mail.inc.php (pwg_mail)'),
),
array(
'name' => 'send_mail_headers',
'type' => 'trigger_event',
'vars' => array('array', 'headers'),
'files' => array('include\functions_mail.inc.php (pwg_mail)'),
),
array(
'name' => 'send_mail_subject',
'type' => 'trigger_event',
'vars' => array('string', 'cvt_subject'),
'files' => array('include\functions_mail.inc.php (pwg_mail)'),
),
array(
'name' => 'send_mail_to',
'type' => 'trigger_event',
'vars' => array('string', 'to'),
'name' => 'before_parse_mail_template',
'type' => 'trigger_action',
'vars' => array('string', 'cache_key', 'string', 'content_type'),
'files' => array('include\functions_mail.inc.php (pwg_mail)'),
),
array(
Expand Down

0 comments on commit fc3b787

Please sign in to comment.