2006-02-01 22:07:26 +00:00
|
|
|
<?php
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | PhpWebGallery - a PHP based picture gallery |
|
|
|
|
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
|
2007-01-16 22:23:05 +00:00
|
|
|
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
|
2006-02-01 22:07:26 +00:00
|
|
|
// | Copyright (C) 2006 Ruben ARNAUD - team@phpwebgallery.net |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | branch : BSF (Best So Far)
|
|
|
|
// | file : $RCSfile$
|
|
|
|
// | last update : $Date: 2005-11-26 21:15:50 +0100 (sam., 26 nov. 2005) $
|
|
|
|
// | last modifier : $Author: plg $
|
|
|
|
// | revision : $Revision: 958 $
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | This program is free software; you can redistribute it and/or modify |
|
|
|
|
// | it under the terms of the GNU General Public License as published by |
|
|
|
|
// | the Free Software Foundation |
|
|
|
|
// | |
|
|
|
|
// | This program is distributed in the hope that it will be useful, but |
|
|
|
|
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
|
|
// | General Public License for more details. |
|
|
|
|
// | |
|
|
|
|
// | You should have received a copy of the GNU General Public License |
|
|
|
|
// | along with this program; if not, write to the Free Software |
|
|
|
|
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
|
|
|
// | USA. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
|
|
|
|
/**
|
|
|
|
* - Extract mail fonctions of password.php
|
|
|
|
* - Modify pwg_mail (add pararameters + news fonctionnalities)
|
2006-03-26 22:06:20 +00:00
|
|
|
* - Var conf_mail, function get_mail_configuration, format_email, pwg_mail
|
2006-02-01 22:07:26 +00:00
|
|
|
*/
|
2006-01-31 23:42:42 +00:00
|
|
|
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | functions |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2006-02-01 22:07:26 +00:00
|
|
|
|
2006-01-31 23:42:42 +00:00
|
|
|
/*
|
2006-02-01 22:07:26 +00:00
|
|
|
* Returns an array of mail configuration parameters :
|
|
|
|
*
|
|
|
|
* - mail_options: see $conf['mail_options']
|
|
|
|
* - send_bcc_mail_webmaster: see $conf['send_bcc_mail_webmaster']
|
|
|
|
* - email_webmaster: mail corresponding to $conf['webmaster_id']
|
|
|
|
* - formated_email_webmaster: the name of webmaster is $conf['gallery_title']
|
|
|
|
* - text_footer: PhpWebGallery and version
|
|
|
|
*
|
|
|
|
* @return array
|
2006-01-31 23:42:42 +00:00
|
|
|
*/
|
2006-02-01 22:07:26 +00:00
|
|
|
function get_mail_configuration()
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
$conf_mail = array(
|
|
|
|
'mail_options' => $conf['mail_options'],
|
2006-12-07 23:49:52 +00:00
|
|
|
'send_bcc_mail_webmaster' => $conf['send_bcc_mail_webmaster'],
|
|
|
|
'default_email_format' => $conf['default_email_format']
|
2006-02-01 22:07:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// we have webmaster id among user list, what's his email address ?
|
|
|
|
$conf_mail['email_webmaster'] = get_webmaster_mail_address();
|
|
|
|
|
|
|
|
// name of the webmaster is the title of the gallery
|
|
|
|
$conf_mail['formated_email_webmaster'] =
|
|
|
|
format_email($conf['gallery_title'], $conf_mail['email_webmaster']);
|
|
|
|
|
|
|
|
// what to display at the bottom of each mail ?
|
|
|
|
$conf_mail['text_footer'] =
|
|
|
|
"\n\n-- \nPhpWebGallery ".($conf['show_version'] ? PHPWG_VERSION : '');
|
|
|
|
|
|
|
|
return $conf_mail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an email address with an associated real name
|
|
|
|
*
|
|
|
|
* @param string name
|
|
|
|
* @param string email
|
|
|
|
*/
|
|
|
|
function format_email($name, $email)
|
|
|
|
{
|
2006-08-09 22:10:12 +00:00
|
|
|
global $conf;
|
2006-06-17 22:56:35 +00:00
|
|
|
|
2006-08-09 22:10:12 +00:00
|
|
|
if ($conf['enabled_format_email'])
|
2006-02-01 22:07:26 +00:00
|
|
|
{
|
2006-08-09 22:10:12 +00:00
|
|
|
$cvt7b_name = str_translate_to_ascii7bits($name);
|
|
|
|
|
|
|
|
if (strpos($email, '<') === false)
|
|
|
|
{
|
|
|
|
return $cvt7b_name.' <'.$email.'>';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $cvt7b_name.$email;
|
|
|
|
}
|
2006-02-01 22:07:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-09 22:10:12 +00:00
|
|
|
return $email;
|
2006-02-01 22:07:26 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-09 00:43:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an new mail template
|
|
|
|
*
|
|
|
|
* @param none
|
|
|
|
*/
|
|
|
|
function get_mail_template()
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
// for mail, default template are used
|
|
|
|
list($tmpl, $thm) = explode('/', $conf['default_template']);
|
|
|
|
$mail_template = new Template(PHPWG_ROOT_PATH.'template/'.$tmpl, $thm);
|
|
|
|
|
|
|
|
return $mail_template;
|
|
|
|
}
|
2006-01-31 23:42:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* sends an email, using PhpWebGallery specific informations
|
2006-12-07 23:49:52 +00:00
|
|
|
*/
|
|
|
|
function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $format_infos = 'text/plain', $email_format = null)
|
2006-01-31 23:42:42 +00:00
|
|
|
{
|
2006-12-19 22:05:01 +00:00
|
|
|
global $conf, $conf_mail, $lang_info, $user, $page;
|
2006-01-31 23:42:42 +00:00
|
|
|
|
2006-06-17 22:56:35 +00:00
|
|
|
$cvt7b_subject = str_translate_to_ascii7bits($subject);
|
|
|
|
|
2006-02-01 22:07:26 +00:00
|
|
|
if (!isset($conf_mail))
|
|
|
|
{
|
|
|
|
$conf_mail = get_mail_configuration();
|
|
|
|
}
|
2006-12-07 23:49:52 +00:00
|
|
|
|
|
|
|
if (is_null($email_format))
|
|
|
|
{
|
|
|
|
$email_format = $conf_mail['default_email_format'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($format_infos == 'text/html') and ($email_format == 'text/plain'))
|
|
|
|
{
|
|
|
|
// Todo find function to convert html text to plain text
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-01 22:07:26 +00:00
|
|
|
|
2006-12-19 22:05:01 +00:00
|
|
|
// Compute root_path in order have complete path
|
|
|
|
if ($email_format == 'text/html')
|
|
|
|
{
|
|
|
|
set_make_full_url();
|
|
|
|
}
|
|
|
|
|
2006-02-01 22:07:26 +00:00
|
|
|
$to = format_email('', $to);
|
2006-01-31 23:42:42 +00:00
|
|
|
|
2006-02-01 22:07:26 +00:00
|
|
|
if ($from == '')
|
|
|
|
{
|
|
|
|
$from = $conf_mail['formated_email_webmaster'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$from = format_email('', $from);
|
|
|
|
}
|
2006-01-31 23:42:42 +00:00
|
|
|
|
2006-02-01 22:07:26 +00:00
|
|
|
$headers = 'From: '.$from."\n";
|
|
|
|
$headers.= 'Reply-To: '.$from."\n";
|
2006-12-07 23:49:52 +00:00
|
|
|
$headers.= 'Content-Type: '.$email_format.';format=flowed;charset="'.$lang_info['charset'].'";';
|
2006-08-11 22:37:22 +00:00
|
|
|
$headers.= 'reply-type=original'."\n";
|
|
|
|
|
2006-02-01 22:07:26 +00:00
|
|
|
if ($conf_mail['send_bcc_mail_webmaster'])
|
|
|
|
{
|
|
|
|
$headers.= 'Bcc: '.$conf_mail['formated_email_webmaster']."\n";
|
|
|
|
}
|
2006-12-07 23:49:52 +00:00
|
|
|
|
|
|
|
$content = '';
|
|
|
|
|
2006-12-09 00:43:23 +00:00
|
|
|
if (!isset($conf_mail[$email_format][$lang_info['charset']]['header']))
|
2006-12-07 23:49:52 +00:00
|
|
|
{
|
2006-12-09 00:43:23 +00:00
|
|
|
if ($email_format == 'text/html')
|
|
|
|
{
|
|
|
|
$mail_template = get_mail_template();
|
2006-12-08 06:05:01 +00:00
|
|
|
|
2006-12-09 00:43:23 +00:00
|
|
|
$mail_template->set_filenames(array('mail_header'=>'mail/header.tpl'));
|
2006-12-07 23:49:52 +00:00
|
|
|
|
2006-12-09 00:43:23 +00:00
|
|
|
$mail_template->assign_vars(
|
|
|
|
array(
|
|
|
|
'BODY_ID' =>
|
|
|
|
isset($page['body_id']) ?
|
|
|
|
$page['body_id'] : '',
|
2006-12-07 23:49:52 +00:00
|
|
|
|
2006-12-09 00:43:23 +00:00
|
|
|
'CONTENT_ENCODING' => $lang_info['charset'],
|
2006-12-19 22:05:01 +00:00
|
|
|
'LANG' => $lang_info['code'],
|
|
|
|
'DIR' => $lang_info['direction']
|
2006-12-09 00:43:23 +00:00
|
|
|
));
|
2006-12-07 23:49:52 +00:00
|
|
|
|
2006-12-09 00:43:23 +00:00
|
|
|
$conf_mail[$email_format][$lang_info['charset']]['header'] =
|
|
|
|
$mail_template->parse('mail_header', true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$conf_mail[$email_format][$lang_info['charset']]['header'] = '';
|
|
|
|
}
|
2006-12-07 23:49:52 +00:00
|
|
|
}
|
2006-12-09 00:43:23 +00:00
|
|
|
|
|
|
|
$content.= $conf_mail[$email_format][$lang_info['charset']]['header'];
|
2006-12-07 23:49:52 +00:00
|
|
|
|
|
|
|
if (($format_infos == 'text/plain') and ($email_format == 'text/html'))
|
|
|
|
{
|
|
|
|
$content.= '<pre>'.htmlentities($infos).'</pre>';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$content.= $infos;
|
|
|
|
}
|
|
|
|
|
2006-12-09 00:43:23 +00:00
|
|
|
if (!isset($conf_mail[$email_format][$lang_info['charset']]['footer']))
|
2006-12-07 23:49:52 +00:00
|
|
|
{
|
2006-12-09 00:43:23 +00:00
|
|
|
if ($email_format == 'text/html')
|
|
|
|
{
|
|
|
|
$mail_template->set_filenames(array('mail_footer'=>'mail/footer.tpl'));
|
2006-12-07 23:49:52 +00:00
|
|
|
|
2006-12-09 00:43:23 +00:00
|
|
|
$mail_template->assign_vars(
|
|
|
|
array(
|
|
|
|
'GALLERY_URL' =>
|
|
|
|
isset($page['gallery_url']) ?
|
|
|
|
$page['gallery_url'] : $conf['gallery_url'],
|
|
|
|
'GALLERY_TITLE' =>
|
|
|
|
isset($page['gallery_title']) ?
|
|
|
|
$page['gallery_title'] : $conf['gallery_title'],
|
|
|
|
'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '',
|
2007-01-16 22:23:05 +00:00
|
|
|
'PHPWG_URL' => PHPWG_URL,
|
2006-12-07 23:49:52 +00:00
|
|
|
|
2006-12-19 22:05:01 +00:00
|
|
|
'TITLE_MAIL' => urlencode(l10n('title_send_mail')),
|
|
|
|
'MAIL' => get_webmaster_mail_address()
|
2006-12-09 00:43:23 +00:00
|
|
|
));
|
2006-12-07 23:49:52 +00:00
|
|
|
|
2006-12-09 00:43:23 +00:00
|
|
|
$conf_mail[$email_format][$lang_info['charset']]['footer'] =
|
|
|
|
$mail_template->parse('mail_footer', true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$conf_mail[$email_format][$lang_info['charset']]['footer'] = $conf_mail['text_footer'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-19 22:05:01 +00:00
|
|
|
$content.= $conf_mail[$email_format][$lang_info['charset']]['footer'];
|
|
|
|
|
|
|
|
// Undo Compute root_path in order have complete path
|
|
|
|
if ($email_format == 'text/html')
|
|
|
|
{
|
|
|
|
unset_make_full_url();
|
|
|
|
}
|
2006-01-31 23:42:42 +00:00
|
|
|
|
|
|
|
if ($conf_mail['mail_options'])
|
|
|
|
{
|
2006-08-09 22:10:12 +00:00
|
|
|
$options = '-f '.$conf_mail['email_webmaster'];
|
2006-02-01 22:07:26 +00:00
|
|
|
|
2006-06-17 22:56:35 +00:00
|
|
|
return mail($to, $cvt7b_subject, $content, $headers, $options);
|
2006-01-31 23:42:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-17 22:56:35 +00:00
|
|
|
return mail($to, $cvt7b_subject, $content, $headers);
|
2006-01-31 23:42:42 +00:00
|
|
|
}
|
2006-02-01 22:07:26 +00:00
|
|
|
}
|
2006-03-26 22:06:20 +00:00
|
|
|
|
2006-05-26 15:51:36 +00:00
|
|
|
?>
|