Skip to content

Commit

Permalink
Resolved issue 0000763: mail triggers:
Browse files Browse the repository at this point in the history
Add triggers on mail part:
  o NBM
  o Group mail
  o process send mail

+ check group_id null on group mail

Merge branch-1_7 2138:2139 into BSF

git-svn-id: http://piwigo.org/svn/trunk@2140 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rub committed Oct 16, 2007
1 parent b606b6d commit c1cd43c
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 39 deletions.
4 changes: 2 additions & 2 deletions admin/cat_modify.php
Expand Up @@ -529,7 +529,7 @@
);

// info by email to an access granted group of category informations
if (isset($_POST['submitEmail']))
if (isset($_POST['submitEmail']) and !empty($_POST['group']))
{
set_make_full_url();

Expand Down Expand Up @@ -640,7 +640,7 @@
while ($row = mysql_fetch_array($result))
{
$template->assign_block_vars(
'group_option',
'group_mail.group_option',
array(
'VALUE' => $row['id'],
'OPTION' => $row['name'],
Expand Down
46 changes: 38 additions & 8 deletions admin/notification_by_mail.php
Expand Up @@ -209,6 +209,26 @@ function insert_new_data_user_mail_notification()
}
}

/*
* Apply global functions to mail content
* return customize mail content rendered
*/
function render_global_customize_mail_content($customize_mail_content)
{
global $conf;

if ($conf['nbm_send_html_mail'] and !(strpos($customize_mail_content, '<') === 0))
{
// On HTML mail, detects if the content are HTML format.
// If it's plain text format, convert content to readable HTML
return nl2br(htmlspecialchars($customize_mail_content));
}
else
{
return $customize_mail_content;
}
}

/*
* Send mail for notification to all users
* Return list of "selected" users for 'list_to_send'
Expand Down Expand Up @@ -243,12 +263,9 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
$customize_mail_content = $conf['nbm_complementary_mail_content'];
}

if ($conf['nbm_send_html_mail'] and !(strpos($customize_mail_content, '<') === 0))
{
// On HTML mail, detects if the content are HTML format.
// If it's plain text format, convert content to readable HTML
$customize_mail_content = nl2br(htmlspecialchars($customize_mail_content));
}
$customize_mail_content =
trigger_event('nbm_render_global_customize_mail_content', $customize_mail_content);


// Prepare message after change language
if ($is_action_send)
Expand Down Expand Up @@ -343,11 +360,16 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
}
}

if (!empty($customize_mail_content))
$nbm_user_customize_mail_content =
trigger_event('nbm_render_user_customize_mail_content',
$customize_mail_content, $nbm_user);
if (!empty($nbm_user_customize_mail_content))
{
$env_nbm['mail_template']->assign_block_vars
(
'custom', array('CUSTOMIZE_MAIL_CONTENT' => $customize_mail_content)
'custom',
array('CUSTOMIZE_MAIL_CONTENT' =>
$nbm_user_customize_mail_content)
);
}

Expand Down Expand Up @@ -481,6 +503,14 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
// +-----------------------------------------------------------------------+
check_status(get_tab_status($page['mode']));


// +-----------------------------------------------------------------------+
// | Add event handler |
// +-----------------------------------------------------------------------+
add_event_handler('nbm_render_global_customize_mail_content', 'render_global_customize_mail_content');
trigger_action('nbm_event_handler_added');


// +-----------------------------------------------------------------------+
// | Insert new users with mails |
// +-----------------------------------------------------------------------+
Expand Down
119 changes: 91 additions & 28 deletions include/functions_mail.inc.php
Expand Up @@ -241,6 +241,8 @@ function switch_lang_to($language)
$lang_info = $switch_lang[$language]['lang_info'];
$lang = $switch_lang[$language]['lang'];
}

$user['language'] = $language;
}
}

Expand Down Expand Up @@ -271,6 +273,7 @@ function switch_lang_back()
$lang_info = $switch_lang[$language]['lang_info'];
$lang = $switch_lang[$language]['lang'];
}
$user['language'] = $language;
}
}

Expand All @@ -292,6 +295,16 @@ function switch_lang_back()
*/
function pwg_mail_notification_admins($keyargs_subject, $keyargs_content)
{
// Check arguments
if
(
empty($keyargs_subject) or
empty($keyargs_content)
)
{
return false;
}

global $conf, $user;
$return = true;

Expand Down Expand Up @@ -376,6 +389,18 @@ function pwg_mail_group(
$dirname, $tpl_shortname,
$assign_vars = array(), $language_selected = '')
{
// Check arguments
if
(
empty($group_id) or
empty($email_format) or
empty($keyargs_subject) or
empty($tpl_shortname)
)
{
return false;
}

global $conf;
$return = true;

Expand Down Expand Up @@ -448,7 +473,9 @@ function pwg_mail_group(
$mail_template = get_mail_template($email_format, $elem);
$mail_template->set_filename($tpl_shortname,
(empty($dirname) ? '' : $dirname.'/').$tpl_shortname.'.tpl');
$mail_template->assign_vars($assign_vars);

$mail_template->assign_vars(
trigger_event('mail_group_assign_vars', $assign_vars));

$return = pwg_mail
(
Expand Down Expand Up @@ -478,7 +505,7 @@ function pwg_mail_group(
* sends an email, using PhpWebGallery specific informations
*
* @param:
* - to: Receiver, or receivers of the mail.
* - to: receiver(s) of the mail.
* - args: function params of mail function:
* o from: sender [default value webmaster email]
* o Cc: array of carbon copy receivers of the mail. [default value empty]
Expand Down Expand Up @@ -690,9 +717,62 @@ function pwg_mail($to, $args = array())
unset_make_full_url();
}

/*Testing block
{
global $user;
return
trigger_event('send_mail',
false, /* Result */
trigger_event('send_mail_to', $to),
trigger_event('send_mail_subject', $cvt_subject),
trigger_event('send_mail_content', $content),
trigger_event('send_mail_headers', $headers),
$args
);
}

/*
* pwg sendmail
*
* @param:
* - result of other sendmail
* - to: Receiver or receiver(s) of the mail.
* - subject [default value 'PhpWebGallery']
* - content: content of mail
* - headers: headers of mail
*
* @return boolean (Ok or not)
*/
function pwg_send_mail($result, $to, $subject, $content, $headers)
{
if (!$result)
{
global $conf_mail;

if ($conf_mail['use_smtp'])
{
include_once( PHPWG_ROOT_PATH.'include/class_smtp_mail.inc.php' );
$smtp_mail = new smtp_mail(
$conf_mail['smtp_host'], $conf_mail['smtp_user'], $conf_mail['smtp_password'],
$conf_mail['email_webmaster']);
return $smtp_mail->mail($to, $subject, $content, $headers);
}
else
{
if ($conf_mail['mail_options'])
{
$options = '-f '.$conf_mail['email_webmaster'];
return mail($to, $subject, $content, $headers, $options);
}
else
{
return mail($to, $subject, $content, $headers);
}
}
}
}

/*Testing block
function pwg_send_mail_test($result, $to, $subject, $content, $headers, $args)
{
global $user, $lang_info;
@mkdir(PHPWG_ROOT_PATH.'testmail');
$filename = PHPWG_ROOT_PATH.'testmail/mail.'.$user['username'].'.'.$lang_info['code'].'.'.$args['template'].'.'.$args['theme'];
if ($args['content_format'] == 'text/plain')
Expand All @@ -705,33 +785,16 @@ function pwg_mail($to, $args = array())
}
$file = fopen($filename, 'w+');
fwrite($file, $to);
fwrite($file, $cvt_subject);
fwrite($file, $subject);
fwrite($file, $headers);
fwrite($file, $content);
fclose($file);
return true;
}*/

if ($conf_mail['use_smtp'])
{
include_once( PHPWG_ROOT_PATH.'include/class_smtp_mail.inc.php' );
$smtp_mail = new smtp_mail(
$conf_mail['smtp_host'], $conf_mail['smtp_user'], $conf_mail['smtp_password'],
$conf_mail['email_webmaster']);
return $smtp_mail->mail($to, $cvt_subject, $content, $headers);
}
else
{
if ($conf_mail['mail_options'])
{
$options = '-f '.$conf_mail['email_webmaster'];
return mail($to, $cvt_subject, $content, $headers, $options);
}
else
{
return mail($to, $cvt_subject, $content, $headers);
}
}
}
add_event_handler('send_mail', 'pwg_send_mail_test', 0, 6);*/


add_event_handler('send_mail', 'pwg_send_mail', EVENT_HANDLER_PRIORITY_NEUTRAL, 5);
trigger_action('functions_mail_included');

?>
4 changes: 3 additions & 1 deletion template/yoga/admin/cat_modify.tpl
Expand Up @@ -212,6 +212,7 @@

</fieldset>

<!-- BEGIN group_mail -->
<fieldset id="emailCatInfo">
<legend>{lang:Send an information email to group members}</legend>

Expand All @@ -221,7 +222,7 @@
<td>
<select name="group">
<!-- BEGIN group_option -->
<option value="{group_option.VALUE}">{group_option.OPTION}</option>
<option value="{group_mail.group_option.VALUE}">{group_mail.group_option.OPTION}</option>
<!-- END group_option -->
</select>
</td>
Expand All @@ -241,5 +242,6 @@
</p>

</fieldset>
<!-- END group_mail -->

</form>

0 comments on commit c1cd43c

Please sign in to comment.