2006-02-01 23:07:26 +01:00
|
|
|
<?php
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | PhpWebGallery - a PHP based picture gallery |
|
|
|
|
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
|
2007-01-16 23:23:05 +01:00
|
|
|
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
|
2007-02-14 23:53:04 +01:00
|
|
|
// | Copyright (C) 2006-2007 Ruben ARNAUD - team@phpwebgallery.net |
|
2006-02-01 23:07:26 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
2007-03-16 13:08:25 +01:00
|
|
|
// | file : $Id$
|
2007-03-16 07:30:07 +01:00
|
|
|
// | last update : $Date$
|
|
|
|
// | last modifier : $Author$
|
|
|
|
// | revision : $Revision$
|
2006-02-01 23:07:26 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | 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. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
|
2006-02-01 00:42:42 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | functions |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2006-02-01 23:07:26 +01:00
|
|
|
|
2006-02-01 00:42:42 +01:00
|
|
|
/*
|
2006-02-01 23:07:26 +01: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-02-01 00:42:42 +01:00
|
|
|
*/
|
2006-02-01 23:07:26 +01:00
|
|
|
function get_mail_configuration()
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
$conf_mail = array(
|
|
|
|
'mail_options' => $conf['mail_options'],
|
2006-12-08 00:49:52 +01:00
|
|
|
'send_bcc_mail_webmaster' => $conf['send_bcc_mail_webmaster'],
|
|
|
|
'default_email_format' => $conf['default_email_format']
|
2006-02-01 23:07:26 +01: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']);
|
|
|
|
|
2007-02-13 00:21:23 +01:00
|
|
|
$conf_mail['boundary_key'] = generate_key(32);
|
|
|
|
|
2006-02-01 23:07:26 +01:00
|
|
|
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-10 00:10:12 +02:00
|
|
|
global $conf;
|
2006-06-18 00:56:35 +02:00
|
|
|
|
2006-08-10 00:10:12 +02:00
|
|
|
if ($conf['enabled_format_email'])
|
2006-02-01 23:07:26 +01:00
|
|
|
{
|
2006-08-10 00:10:12 +02:00
|
|
|
$cvt7b_name = str_translate_to_ascii7bits($name);
|
|
|
|
|
|
|
|
if (strpos($email, '<') === false)
|
|
|
|
{
|
|
|
|
return $cvt7b_name.' <'.$email.'>';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $cvt7b_name.$email;
|
|
|
|
}
|
2006-02-01 23:07:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-10 00:10:12 +02:00
|
|
|
return $email;
|
2006-02-01 23:07:26 +01:00
|
|
|
}
|
|
|
|
}
|
2006-12-09 01:43:23 +01:00
|
|
|
|
|
|
|
/**
|
2007-02-14 23:53:04 +01:00
|
|
|
* Returns an completed array template/theme
|
2007-02-13 00:21:23 +01:00
|
|
|
* completed with $conf['default_template']
|
2006-12-09 01:43:23 +01:00
|
|
|
*
|
2007-02-13 00:21:23 +01:00
|
|
|
* @params:
|
|
|
|
* - args: incompleted array of template/theme
|
|
|
|
* o template: template to use [default $conf['default_template']]
|
|
|
|
* o theme: template to use [default $conf['default_template']]
|
2006-12-09 01:43:23 +01:00
|
|
|
*/
|
2007-02-13 00:21:23 +01:00
|
|
|
function get_array_template_theme($args = array())
|
2006-12-09 01:43:23 +01:00
|
|
|
{
|
2007-02-13 00:21:23 +01:00
|
|
|
global $conf;
|
|
|
|
|
|
|
|
$res = array();
|
|
|
|
|
|
|
|
if (empty($args['template']) or empty($args['theme']))
|
|
|
|
{
|
|
|
|
list($res['template'], $res['theme']) = explode('/', $conf['default_template']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($args['template']))
|
|
|
|
{
|
|
|
|
$res['template'] = $args['template'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($args['theme']))
|
|
|
|
{
|
|
|
|
$res['theme'] = $args['theme'];
|
|
|
|
}
|
2006-12-09 01:43:23 +01:00
|
|
|
|
2007-02-13 00:21:23 +01:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an new mail template
|
|
|
|
*
|
|
|
|
* @params:
|
|
|
|
* - email_format: mail format
|
|
|
|
* - args: function params of mail function:
|
|
|
|
* o template: template to use [default $conf['default_template']]
|
|
|
|
* o theme: template to use [default $conf['default_template']]
|
|
|
|
*/
|
|
|
|
function get_mail_template($email_format, $args = array())
|
|
|
|
{
|
|
|
|
$args = get_array_template_theme($args);
|
|
|
|
|
|
|
|
$mail_template = new Template(PHPWG_ROOT_PATH.'template/'.$args['template'], $args['theme']);
|
|
|
|
$mail_template->set_rootdir(PHPWG_ROOT_PATH.'template/'.$args['template'].'/mail/'.$email_format);
|
2006-12-09 01:43:23 +01:00
|
|
|
|
|
|
|
return $mail_template;
|
|
|
|
}
|
2007-02-06 23:55:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return string email format (html or not)
|
|
|
|
*
|
|
|
|
* @param string format
|
|
|
|
*/
|
|
|
|
function get_str_email_format($is_html)
|
|
|
|
{
|
|
|
|
return ($is_html ? 'text/html' : 'text/plain');
|
|
|
|
}
|
2006-02-01 00:42:42 +01:00
|
|
|
|
2007-03-14 00:01:16 +01:00
|
|
|
/*
|
|
|
|
* Switch language to param language
|
|
|
|
* All entries are push on language stack
|
|
|
|
*
|
|
|
|
* @param string language
|
|
|
|
*/
|
|
|
|
function switch_lang_to($language)
|
|
|
|
{
|
|
|
|
global $switch_lang, $user, $lang, $lang_info;
|
|
|
|
|
|
|
|
if (count($switch_lang['stack']) == 0)
|
|
|
|
{
|
|
|
|
$prev_language = $user['language'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$prev_language = end($switch_lang['stack']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$switch_lang['stack'][] = $language;
|
|
|
|
|
|
|
|
if ($prev_language != $language)
|
|
|
|
{
|
|
|
|
if (!isset($switch_lang['language'][$prev_language]))
|
|
|
|
{
|
|
|
|
$switch_lang[$prev_language]['lang_info'] = $lang_info;
|
|
|
|
$switch_lang[$prev_language]['lang'] = $lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($switch_lang['language'][$language]))
|
|
|
|
{
|
|
|
|
// Re-Init language arrays
|
|
|
|
$lang_info = array();
|
|
|
|
$lang = array();
|
|
|
|
|
|
|
|
// language files
|
|
|
|
include(get_language_filepath('common.lang.php', '', $language));
|
|
|
|
// No test admin because script is checked admin (user selected no)
|
|
|
|
// Translations are in admin file too
|
|
|
|
include(get_language_filepath('admin.lang.php', '', $language));
|
|
|
|
trigger_action('loading_lang');
|
|
|
|
@include(get_language_filepath('local.lang.php', '', $language));
|
|
|
|
|
|
|
|
$switch_lang[$language]['lang_info'] = $lang_info;
|
|
|
|
$switch_lang[$language]['lang'] = $lang;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$lang_info = $switch_lang[$language]['lang_info'];
|
|
|
|
$lang = $switch_lang[$language]['lang'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch back language pushed with switch_lang_to function
|
|
|
|
*
|
|
|
|
* @param: none
|
|
|
|
*/
|
|
|
|
function switch_lang_back()
|
|
|
|
{
|
|
|
|
global $switch_lang, $user, $lang, $lang_info;
|
|
|
|
|
|
|
|
$last_language = array_pop($switch_lang['stack']);
|
|
|
|
|
|
|
|
if (count($switch_lang['stack']) > 0)
|
|
|
|
{
|
|
|
|
$language = end($switch_lang['stack']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$language = $user['language'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($last_language != $language)
|
|
|
|
{
|
|
|
|
if (!isset($switch_lang['language'][$language]))
|
|
|
|
{
|
|
|
|
$lang_info = $switch_lang[$language]['lang_info'];
|
|
|
|
$lang = $switch_lang[$language]['lang'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-16 00:20:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-16 13:08:25 +01:00
|
|
|
if (count($admins) > 0)
|
|
|
|
{
|
|
|
|
$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();
|
|
|
|
}
|
2007-03-16 00:20:41 +01:00
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
2007-03-14 00:01:16 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* send en email to user's group
|
|
|
|
*
|
2007-03-16 00:20:41 +01:00
|
|
|
* @param:
|
2007-03-14 00:01:16 +01:00
|
|
|
* - group_id: mail are sent to group with this Id
|
|
|
|
* - email_format: mail format
|
2007-03-16 00:20:41 +01:00
|
|
|
* - keyargs_subject: mail subject on l10n_args format
|
2007-03-14 00:01:16 +01:00
|
|
|
* - 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
|
2007-03-16 00:20:41 +01:00
|
|
|
*
|
|
|
|
* @return boolean (Ok or not)
|
|
|
|
*/
|
2007-03-14 00:01:16 +01:00
|
|
|
function pwg_mail_group(
|
2007-03-16 00:20:41 +01:00
|
|
|
$group_id, $email_format, $keyargs_subject,
|
2007-03-14 00:01:16 +01:00
|
|
|
$tpl_shortname, $assign_vars = array(), $language_selected = '')
|
|
|
|
{
|
|
|
|
global $conf;
|
2007-03-16 00:20:41 +01:00
|
|
|
$return = true;
|
2007-03-14 00:01:16 +01:00
|
|
|
|
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
distinct language, template
|
|
|
|
FROM
|
|
|
|
'.USER_GROUP_TABLE.' as ug
|
|
|
|
INNER JOIN '.USERS_TABLE.' as u ON '.$conf['user_fields']['id'].' = ug.user_id
|
|
|
|
INNER JOIN '.USER_INFOS_TABLE.' as ui ON ui.user_id = ug.user_id
|
|
|
|
WHERE
|
|
|
|
'.$conf['user_fields']['email'].' IS NOT NULL
|
|
|
|
AND group_id = '.$group_id;
|
|
|
|
|
|
|
|
if (!empty($language_selected))
|
|
|
|
{
|
|
|
|
$query .= '
|
|
|
|
AND language = \''.$language_selected.'\'';
|
|
|
|
}
|
|
|
|
|
|
|
|
$query .= '
|
|
|
|
;';
|
|
|
|
|
|
|
|
$result = pwg_query($query);
|
|
|
|
|
|
|
|
if (mysql_num_rows($result) > 0)
|
|
|
|
{
|
|
|
|
$list = array();
|
|
|
|
while ($row = mysql_fetch_array($result))
|
|
|
|
{
|
|
|
|
list($row['template'], $row['theme']) = explode('/', $row['template']);
|
|
|
|
$list[] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($list as $elem)
|
|
|
|
{
|
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
u.'.$conf['user_fields']['username'].' as username,
|
|
|
|
u.'.$conf['user_fields']['email'].' as mail_address
|
|
|
|
FROM
|
|
|
|
'.USER_GROUP_TABLE.' as ug
|
|
|
|
INNER JOIN '.USERS_TABLE.' as u ON '.$conf['user_fields']['id'].' = ug.user_id
|
|
|
|
INNER JOIN '.USER_INFOS_TABLE.' as ui ON ui.user_id = ug.user_id
|
|
|
|
WHERE
|
|
|
|
'.$conf['user_fields']['email'].' IS NOT NULL
|
|
|
|
AND group_id = '.$group_id.'
|
|
|
|
AND language = \''.$elem['language'].'\'
|
|
|
|
;';
|
|
|
|
|
|
|
|
$result = pwg_query($query);
|
|
|
|
|
|
|
|
if (mysql_num_rows($result) > 0)
|
|
|
|
{
|
|
|
|
$Bcc = array();
|
|
|
|
while ($row = mysql_fetch_array($result))
|
|
|
|
{
|
|
|
|
if (!empty($row['mail_address']))
|
|
|
|
{
|
|
|
|
array_push($Bcc, format_email($row['username'], $row['mail_address']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-16 13:08:25 +01:00
|
|
|
if (count($Bcc) > 0)
|
|
|
|
{
|
|
|
|
switch_lang_to($elem['language']);
|
|
|
|
|
|
|
|
$mail_template = get_mail_template($email_format, $elem);
|
|
|
|
$mail_template->set_filename($tpl_shortname,
|
|
|
|
(IN_ADMIN ? 'admin/' : '').$tpl_shortname.'.tpl');
|
|
|
|
$mail_template->assign_vars($assign_vars);
|
|
|
|
|
|
|
|
$return = pwg_mail
|
|
|
|
(
|
|
|
|
'',
|
|
|
|
array
|
|
|
|
(
|
|
|
|
'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();
|
|
|
|
}
|
2007-03-14 00:01:16 +01:00
|
|
|
}
|
|
|
|
}
|
2007-03-16 00:20:41 +01:00
|
|
|
|
|
|
|
return $return;
|
2007-03-14 00:01:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-02-01 00:42:42 +01:00
|
|
|
* sends an email, using PhpWebGallery specific informations
|
2007-02-13 00:21:23 +01:00
|
|
|
*
|
|
|
|
* @param:
|
|
|
|
* - to: Receiver, or receivers of the mail.
|
|
|
|
* - args: function params of mail function:
|
2007-02-14 23:53:04 +01:00
|
|
|
* o from: sender [default value webmaster email]
|
|
|
|
* o Cc: array of carbon copy receivers of the mail. [default value empty]
|
|
|
|
* o Bcc: array of blind carbon copy receivers of the mail. [default value empty]
|
2007-02-13 00:21:23 +01:00
|
|
|
* o subject [default value 'PhpWebGallery']
|
|
|
|
* o content: content of mail [default value '']
|
|
|
|
* 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']]
|
2007-03-16 00:20:41 +01:00
|
|
|
* o theme: template to use [default $conf['default_template']]
|
|
|
|
*
|
|
|
|
* @return boolean (Ok or not)
|
2006-12-08 00:49:52 +01:00
|
|
|
*/
|
2007-02-13 00:21:23 +01:00
|
|
|
function pwg_mail($to, $args = array())
|
2006-02-01 00:42:42 +01:00
|
|
|
{
|
2007-02-13 00:21:23 +01:00
|
|
|
global $conf, $conf_mail, $lang_info, $page;
|
2007-03-16 13:08:25 +01:00
|
|
|
|
|
|
|
if (empty($to) and empty($args['Cc']) and empty($args['Bcc']))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-02-01 23:07:26 +01:00
|
|
|
if (!isset($conf_mail))
|
|
|
|
{
|
|
|
|
$conf_mail = get_mail_configuration();
|
|
|
|
}
|
2006-12-08 00:49:52 +01:00
|
|
|
|
2007-02-13 00:21:23 +01:00
|
|
|
if (empty($args['email_format']))
|
2006-12-08 00:49:52 +01:00
|
|
|
{
|
2007-02-13 00:21:23 +01:00
|
|
|
$args['email_format'] = $conf_mail['default_email_format'];
|
2006-12-08 00:49:52 +01:00
|
|
|
}
|
|
|
|
|
2006-12-19 23:05:01 +01:00
|
|
|
// Compute root_path in order have complete path
|
2007-02-13 00:21:23 +01:00
|
|
|
if ($args['email_format'] == 'text/html')
|
2006-12-19 23:05:01 +01:00
|
|
|
{
|
|
|
|
set_make_full_url();
|
|
|
|
}
|
2007-03-14 00:01:16 +01:00
|
|
|
|
|
|
|
if (!empty($to))
|
|
|
|
{
|
|
|
|
$to = format_email('', $to);
|
|
|
|
}
|
2006-02-01 00:42:42 +01:00
|
|
|
|
2007-02-13 00:21:23 +01:00
|
|
|
if (empty($args['from']))
|
2006-02-01 23:07:26 +01:00
|
|
|
{
|
2007-02-13 00:21:23 +01:00
|
|
|
$args['from'] = $conf_mail['formated_email_webmaster'];
|
2006-02-01 23:07:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-13 00:21:23 +01:00
|
|
|
$args['from'] = format_email('', $args['from']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($args['subject']))
|
|
|
|
{
|
|
|
|
$args['subject'] = 'PhpWebGallery';
|
2006-02-01 23:07:26 +01:00
|
|
|
}
|
2007-02-13 00:21:23 +01:00
|
|
|
$cvt7b_subject = str_translate_to_ascii7bits($args['subject']);
|
2006-02-01 00:42:42 +01:00
|
|
|
|
2007-02-13 00:21:23 +01:00
|
|
|
if (!isset($args['content']))
|
|
|
|
{
|
|
|
|
$args['content'] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($args['content_format']))
|
|
|
|
{
|
|
|
|
$args['content_format'] = 'text/plain';
|
|
|
|
}
|
2007-02-14 23:53:04 +01:00
|
|
|
|
|
|
|
if ($conf_mail['send_bcc_mail_webmaster'])
|
|
|
|
{
|
|
|
|
$args['Bcc'][] = $conf_mail['formated_email_webmaster'];
|
|
|
|
}
|
2007-02-13 00:21:23 +01:00
|
|
|
|
|
|
|
if (($args['content_format'] == 'text/html') and ($args['email_format'] == 'text/plain'))
|
|
|
|
{
|
|
|
|
// Todo find function to convert html text to plain text
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$args = array_merge($args, get_array_template_theme($args));
|
|
|
|
|
|
|
|
$headers = 'From: '.$args['from']."\n";
|
2007-02-14 23:53:04 +01:00
|
|
|
$headers.= 'Reply-To: '.$args['from']."\n";
|
2007-03-14 00:01:16 +01:00
|
|
|
if (empty($to))
|
|
|
|
{
|
|
|
|
$headers.= 'To: undisclosed-recipients: ;'."\n";
|
|
|
|
}
|
2007-02-14 23:53:04 +01:00
|
|
|
|
|
|
|
if (!empty($args['Cc']))
|
|
|
|
{
|
|
|
|
$headers.= 'Cc: '.implode(',', $args['Cc'])."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($args['Bcc']))
|
|
|
|
{
|
|
|
|
$headers.= 'Bcc: '.implode(',', $args['Bcc'])."\n";
|
|
|
|
}
|
|
|
|
|
2007-02-13 00:21:23 +01:00
|
|
|
$headers.= 'Content-Type: multipart/alternative;'."\n";
|
|
|
|
$headers.= ' boundary="---='.$conf_mail['boundary_key'].'";'."\n";
|
|
|
|
$headers.= ' reply-type=original'."\n";
|
2007-02-12 07:09:05 +01:00
|
|
|
$headers.= 'MIME-Version: 1.0'."\n";
|
2006-08-12 00:37:22 +02:00
|
|
|
|
2006-12-08 00:49:52 +01:00
|
|
|
$content = '';
|
|
|
|
|
2007-02-13 00:21:23 +01:00
|
|
|
if (!isset($conf_mail[$args['email_format']][$lang_info['charset']][$args['template']][$args['theme']]))
|
2006-12-08 00:49:52 +01:00
|
|
|
{
|
2007-02-06 23:55:12 +01:00
|
|
|
if (!isset($mail_template))
|
2006-12-09 01:43:23 +01:00
|
|
|
{
|
2007-02-13 00:21:23 +01:00
|
|
|
$mail_template = get_mail_template($args['email_format']);
|
2007-02-06 23:55:12 +01:00
|
|
|
}
|
2006-12-08 07:05:01 +01:00
|
|
|
|
2007-02-06 23:55:12 +01:00
|
|
|
$mail_template->set_filename('mail_header', 'header.tpl');
|
|
|
|
$mail_template->set_filename('mail_footer', 'footer.tpl');
|
2006-12-08 00:49:52 +01:00
|
|
|
|
2007-02-06 23:55:12 +01:00
|
|
|
$mail_template->assign_vars(
|
|
|
|
array(
|
|
|
|
//Header
|
2007-02-13 00:21:23 +01:00
|
|
|
'BOUNDARY_KEY' => $conf_mail['boundary_key'],
|
|
|
|
'CONTENT_TYPE' => $args['email_format'],
|
|
|
|
'CONTENT_ENCODING' => $lang_info['charset'],
|
2007-02-06 23:55:12 +01:00
|
|
|
'LANG' => $lang_info['code'],
|
|
|
|
'DIR' => $lang_info['direction'],
|
|
|
|
|
|
|
|
// Footer
|
|
|
|
'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 : '',
|
|
|
|
'PHPWG_URL' => PHPWG_URL,
|
2006-12-08 00:49:52 +01:00
|
|
|
|
2007-02-06 23:55:12 +01:00
|
|
|
'TITLE_MAIL' => urlencode(l10n('title_send_mail')),
|
|
|
|
'MAIL' => get_webmaster_mail_address()
|
|
|
|
));
|
|
|
|
|
2007-02-13 00:21:23 +01:00
|
|
|
if ($args['email_format'] == 'text/html')
|
2007-02-11 01:43:53 +01:00
|
|
|
{
|
2007-02-11 13:17:41 +01:00
|
|
|
$old_root = $mail_template->root;
|
|
|
|
|
|
|
|
if (is_file($mail_template->root.'/global-mail-css.tpl'))
|
2007-02-11 01:43:53 +01:00
|
|
|
{
|
2007-02-11 13:17:41 +01:00
|
|
|
$mail_template->set_filename('global_mail_css', 'global-mail-css.tpl');
|
|
|
|
$mail_template->assign_var_from_handle('GLOBAL_MAIL_CSS', 'global_mail_css');
|
2007-02-11 01:43:53 +01:00
|
|
|
}
|
2007-02-10 18:43:11 +01:00
|
|
|
|
2007-02-13 00:21:23 +01:00
|
|
|
$mail_template->root = PHPWG_ROOT_PATH.'template/'.$args['template'].'/theme/'.$args['theme'];
|
2007-02-11 13:17:41 +01:00
|
|
|
if (is_file($mail_template->root.'/mail-css.tpl'))
|
2007-02-11 01:43:53 +01:00
|
|
|
{
|
2007-02-11 13:17:41 +01:00
|
|
|
$mail_template->set_filename('mail_css', 'mail-css.tpl');
|
|
|
|
$mail_template->assign_var_from_handle('MAIL_CSS', 'mail_css');
|
2007-02-11 01:43:53 +01:00
|
|
|
}
|
2007-02-10 18:43:11 +01:00
|
|
|
|
2007-02-11 01:43:53 +01:00
|
|
|
$mail_template->root = PHPWG_ROOT_PATH.'template-common';
|
2007-02-11 13:17:41 +01:00
|
|
|
if (is_file($mail_template->root.'/local-mail-css.tpl'))
|
2007-02-11 01:43:53 +01:00
|
|
|
{
|
2007-02-11 13:17:41 +01:00
|
|
|
$mail_template->set_filename('local_mail_css', 'local-mail-css.tpl');
|
|
|
|
$mail_template->assign_var_from_handle('LOCAL_MAIL_CSS', 'local_mail_css');
|
2007-02-11 01:43:53 +01:00
|
|
|
}
|
2007-02-10 18:43:11 +01:00
|
|
|
|
2007-02-11 01:43:53 +01:00
|
|
|
$mail_template->root = $old_root;
|
2007-02-10 18:43:11 +01:00
|
|
|
}
|
|
|
|
|
2007-02-06 23:55:12 +01:00
|
|
|
// what are displayed on the header of each mail ?
|
2007-02-13 00:21:23 +01:00
|
|
|
$conf_mail[$args['email_format']]
|
2007-02-08 23:04:36 +01:00
|
|
|
[$lang_info['charset']]
|
2007-02-13 00:21:23 +01:00
|
|
|
[$args['template']][$args['theme']]['header'] =
|
2007-02-08 23:04:36 +01:00
|
|
|
$mail_template->parse('mail_header', true);
|
2007-02-06 23:55:12 +01:00
|
|
|
|
|
|
|
// what are displayed on the footer of each mail ?
|
2007-02-13 00:21:23 +01:00
|
|
|
$conf_mail[$args['email_format']]
|
2007-02-08 23:04:36 +01:00
|
|
|
[$lang_info['charset']]
|
2007-02-13 00:21:23 +01:00
|
|
|
[$args['template']][$args['theme']]['footer'] =
|
2007-02-08 23:04:36 +01:00
|
|
|
$mail_template->parse('mail_footer', true);
|
2006-12-08 00:49:52 +01:00
|
|
|
}
|
2007-02-13 00:21:23 +01:00
|
|
|
|
|
|
|
// Header
|
|
|
|
$content.= $conf_mail[$args['email_format']]
|
2007-02-08 23:04:36 +01:00
|
|
|
[$lang_info['charset']]
|
2007-02-13 00:21:23 +01:00
|
|
|
[$args['template']][$args['theme']]['header'];
|
2006-12-08 00:49:52 +01:00
|
|
|
|
2007-02-13 00:21:23 +01:00
|
|
|
// Content
|
|
|
|
if (($args['content_format'] == 'text/plain') and ($args['email_format'] == 'text/html'))
|
2006-12-08 00:49:52 +01:00
|
|
|
{
|
2007-03-13 00:10:35 +01:00
|
|
|
$content.= '<p>'.
|
|
|
|
nl2br(
|
|
|
|
preg_replace("/(http:\/\/)([^\s,]*)/i",
|
|
|
|
"<a href='$1$2'>$1$2</a>",
|
|
|
|
htmlentities($args['content']))).
|
|
|
|
'</p>';
|
2006-12-08 00:49:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-13 00:21:23 +01:00
|
|
|
$content.= $args['content'];
|
2006-12-08 00:49:52 +01:00
|
|
|
}
|
2007-02-13 00:21:23 +01:00
|
|
|
|
|
|
|
// Footer
|
|
|
|
$content.= $conf_mail[$args['email_format']]
|
2007-02-08 23:04:36 +01:00
|
|
|
[$lang_info['charset']]
|
2007-02-13 00:21:23 +01:00
|
|
|
[$args['template']][$args['theme']]['footer'];
|
|
|
|
|
|
|
|
// Close boundary
|
|
|
|
$content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
|
|
|
|
|
2006-12-19 23:05:01 +01:00
|
|
|
// Undo Compute root_path in order have complete path
|
2007-02-13 00:21:23 +01:00
|
|
|
if ($args['email_format'] == 'text/html')
|
2006-12-19 23:05:01 +01:00
|
|
|
{
|
|
|
|
unset_make_full_url();
|
|
|
|
}
|
2006-02-01 00:42:42 +01:00
|
|
|
|
2007-02-06 23:55:12 +01:00
|
|
|
/*Testing block
|
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
@mkdir(PHPWG_ROOT_PATH.'testmail');
|
|
|
|
$filename = PHPWG_ROOT_PATH.'testmail/mail.'.$user['username'];
|
2007-02-13 00:21:23 +01:00
|
|
|
if ($args['content_format'] == 'text/plain')
|
2007-02-06 23:55:12 +01:00
|
|
|
{
|
|
|
|
$filename .= '.txt';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$filename .= '.html';
|
|
|
|
}
|
|
|
|
$file = fopen($filename, 'w+');
|
|
|
|
fwrite($file, $content);
|
|
|
|
fclose($file);
|
|
|
|
return true;
|
2007-02-08 23:04:36 +01:00
|
|
|
}*/
|
2007-02-06 23:55:12 +01:00
|
|
|
|
2006-02-01 00:42:42 +01:00
|
|
|
if ($conf_mail['mail_options'])
|
|
|
|
{
|
2006-08-10 00:10:12 +02:00
|
|
|
$options = '-f '.$conf_mail['email_webmaster'];
|
2006-02-01 23:07:26 +01:00
|
|
|
|
2006-06-18 00:56:35 +02:00
|
|
|
return mail($to, $cvt7b_subject, $content, $headers, $options);
|
2006-02-01 00:42:42 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-18 00:56:35 +02:00
|
|
|
return mail($to, $cvt7b_subject, $content, $headers);
|
2006-02-01 00:42:42 +01:00
|
|
|
}
|
2006-02-01 23:07:26 +01:00
|
|
|
}
|
2006-03-27 00:06:20 +02:00
|
|
|
|
2006-05-26 17:51:36 +02:00
|
|
|
?>
|