2006-02-01 23:07:26 +01:00
|
|
|
<?php
|
|
|
|
// +-----------------------------------------------------------------------+
|
2008-04-05 00:57:23 +02:00
|
|
|
// | Piwigo - a PHP based picture gallery |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2009-01-05 00:28:36 +01:00
|
|
|
// | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org |
|
2008-04-05 00:57:23 +02:00
|
|
|
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
|
|
|
|
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | 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 |
|
2006-02-01 23:07:26 +01:00
|
|
|
// | |
|
|
|
|
// | 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
|
|
|
|
2007-10-04 06:39:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Encodes a string using Q form if required (RFC2045)
|
|
|
|
* mail headers MUST contain only US-ASCII characters
|
|
|
|
*/
|
|
|
|
function encode_mime_header($str)
|
|
|
|
{
|
|
|
|
$x = preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
|
|
|
|
if ($x==0)
|
|
|
|
{
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
// Replace every high ascii, control =, ? and _ characters
|
|
|
|
$str = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
|
|
|
|
"'='.sprintf('%02X', ord('\\1'))", $str);
|
|
|
|
|
|
|
|
// Replace every spaces to _ (more readable than =20)
|
|
|
|
$str = str_replace(" ", "_", $str);
|
|
|
|
|
|
|
|
global $lang_info;
|
2007-10-09 01:46:09 +02:00
|
|
|
return '=?'.get_pwg_charset().'?Q?'.$str.'?=';
|
2007-10-04 06:39:59 +02:00
|
|
|
}
|
|
|
|
|
2008-03-18 23:02:33 +01:00
|
|
|
/*
|
|
|
|
* Returns the name of the mail sender :
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function get_mail_sender_name()
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
return (empty($conf['mail_sender_name']) ? $conf['gallery_title'] : $conf['mail_sender_name']);
|
|
|
|
}
|
|
|
|
|
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']
|
2008-05-15 00:25:36 +02:00
|
|
|
* - text_footer: Piwigo and version
|
2006-02-01 23:07:26 +01:00
|
|
|
*
|
|
|
|
* @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'],
|
2007-09-25 23:52:00 +02:00
|
|
|
'send_bcc_mail_webmaster' => $conf['send_bcc_mail_webmaster'],
|
|
|
|
'default_email_format' => $conf['default_email_format'],
|
2009-09-28 22:54:06 +02:00
|
|
|
'alternative_email_format' => $conf['alternative_email_format'],
|
2007-09-25 23:52:00 +02:00
|
|
|
'use_smtp' => !empty($conf['smtp_host']),
|
|
|
|
'smtp_host' => $conf['smtp_host'],
|
|
|
|
'smtp_user' => $conf['smtp_user'],
|
|
|
|
'smtp_password' => $conf['smtp_password']
|
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'] =
|
2008-03-18 23:02:33 +01:00
|
|
|
format_email(get_mail_sender_name(), $conf_mail['email_webmaster']);
|
2006-02-01 23:07:26 +01:00
|
|
|
|
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)
|
|
|
|
{
|
2008-03-17 21:22:05 +01:00
|
|
|
// Spring cleaning
|
|
|
|
$cvt_email = trim(preg_replace('#[\n\r]+#s', '', $email));
|
2008-03-18 23:02:33 +01:00
|
|
|
$cvt_name = trim(preg_replace('#[\n\r]+#s', '', $name));
|
2008-03-17 21:22:05 +01:00
|
|
|
|
2008-03-18 23:02:33 +01:00
|
|
|
if ($cvt_name!="")
|
2006-02-01 23:07:26 +01:00
|
|
|
{
|
2008-03-18 23:02:33 +01:00
|
|
|
$cvt_name = encode_mime_header(
|
|
|
|
'"'
|
|
|
|
.addcslashes($cvt_name,'"')
|
|
|
|
.'"');
|
|
|
|
$cvt_name .= ' ';
|
|
|
|
}
|
2006-08-10 00:10:12 +02:00
|
|
|
|
2008-03-18 23:02:33 +01:00
|
|
|
if (strpos($cvt_email, '<') === false)
|
|
|
|
{
|
|
|
|
return $cvt_name.'<'.$cvt_email.'>';
|
2006-02-01 23:07:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-03-18 23:02:33 +01:00
|
|
|
return $cvt_name.$cvt_email;
|
2006-02-01 23:07:26 +01:00
|
|
|
}
|
|
|
|
}
|
2007-09-25 23:52:00 +02:00
|
|
|
|
2008-03-18 23:02:33 +01:00
|
|
|
/**
|
|
|
|
* Returns an email address list with minimal email string
|
|
|
|
*
|
|
|
|
* @param string with email list (email separated by comma)
|
|
|
|
*/
|
|
|
|
function get_strict_email_list($email_list)
|
|
|
|
{
|
|
|
|
$result = array();
|
|
|
|
$list = explode(',', $email_list);
|
|
|
|
foreach ($list as $email)
|
|
|
|
{
|
|
|
|
if (strpos($email, '<') !== false)
|
|
|
|
{
|
|
|
|
$email = preg_replace('/.*<(.*)>.*/i', '$1', $email);
|
|
|
|
}
|
|
|
|
$result[] = trim($email);
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode(',', $result);
|
|
|
|
}
|
|
|
|
|
2007-09-25 23:52:00 +02:00
|
|
|
/**
|
|
|
|
* Returns an completed array template/theme
|
|
|
|
* completed with get_default_template()
|
|
|
|
*
|
|
|
|
* @params:
|
|
|
|
* - args: incompleted array of template/theme
|
|
|
|
* o template: template to use [default get_default_template()]
|
|
|
|
* o theme: template to use [default get_default_template()]
|
|
|
|
*/
|
|
|
|
function get_array_template_theme($args = array())
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
$res = array();
|
2007-10-04 06:39:59 +02:00
|
|
|
|
2007-09-25 23:52:00 +02:00
|
|
|
if (empty($args['template']) or empty($args['theme']))
|
|
|
|
{
|
|
|
|
list($res['template'], $res['theme']) = explode('/', get_default_template());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($args['template']))
|
|
|
|
{
|
|
|
|
$res['template'] = $args['template'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($args['theme']))
|
|
|
|
{
|
|
|
|
$res['theme'] = $args['theme'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an new mail template
|
|
|
|
*
|
|
|
|
* @params:
|
|
|
|
* - email_format: mail format
|
|
|
|
* - args: function params of mail function:
|
|
|
|
* o template: template to use [default get_default_template()]
|
|
|
|
* o theme: template to use [default get_default_template()]
|
|
|
|
*/
|
2008-03-13 02:43:45 +01:00
|
|
|
function & get_mail_template($email_format, $args = array())
|
2007-09-25 23:52:00 +02:00
|
|
|
{
|
|
|
|
$args = get_array_template_theme($args);
|
|
|
|
|
|
|
|
$mail_template = new Template(PHPWG_ROOT_PATH.'template/'.$args['template'], $args['theme']);
|
2008-03-13 02:43:45 +01:00
|
|
|
$mail_template->set_template_dir(PHPWG_ROOT_PATH.'template/'.$args['template'].'/mail/'.$email_format);
|
2007-09-25 23:52:00 +02:00
|
|
|
return $mail_template;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-10-04 06:39:59 +02:00
|
|
|
* Return string email format (html or not)
|
2007-09-25 23:52:00 +02:00
|
|
|
*
|
|
|
|
* @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-10-04 06:39:59 +02: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;
|
|
|
|
|
2010-02-19 00:12:47 +01:00
|
|
|
// explanation of switch_lang
|
|
|
|
// $switch_lang['language'] contains data of language
|
|
|
|
// $switch_lang['stack'] contains stack LIFO
|
|
|
|
// $switch_lang['initialisation'] allow to know if it's first call
|
|
|
|
|
|
|
|
// Treatment with current user
|
|
|
|
// Language of current user is saved (it's considered OK on firt call)
|
|
|
|
if (!isset($switch_lang['initialisation']) and !isset($switch_lang['language'][$user['language']]))
|
2007-03-14 00:01:16 +01:00
|
|
|
{
|
2010-02-19 00:12:47 +01:00
|
|
|
$switch_lang['initialisation'] = true;
|
|
|
|
$switch_lang['language'][$user['language']]['lang_info'] = $lang_info;
|
|
|
|
$switch_lang['language'][$user['language']]['lang'] = $lang;
|
2007-03-14 00:01:16 +01:00
|
|
|
}
|
|
|
|
|
2010-02-19 00:12:47 +01:00
|
|
|
// Change current infos
|
|
|
|
$switch_lang['stack'][] = $user['language'];
|
|
|
|
$user['language'] = $language;
|
2007-03-14 00:01:16 +01:00
|
|
|
|
2010-02-19 00:12:47 +01:00
|
|
|
// Load new data if necessary
|
|
|
|
if (!isset($switch_lang['language'][$language]))
|
2007-03-14 00:01:16 +01:00
|
|
|
{
|
2010-02-19 00:12:47 +01:00
|
|
|
// Re-Init language arrays
|
|
|
|
$lang_info = array();
|
|
|
|
$lang = array();
|
|
|
|
|
|
|
|
// language files
|
|
|
|
load_language('common.lang', '', array('language'=>$language) );
|
|
|
|
// No test admin because script is checked admin (user selected no)
|
|
|
|
// Translations are in admin file too
|
|
|
|
load_language('admin.lang', '', array('language'=>$language) );
|
|
|
|
trigger_action('loading_lang');
|
|
|
|
load_language('local.lang', '', array('language'=>$language, 'no_fallback'=>true));
|
|
|
|
|
|
|
|
$switch_lang['language'][$language]['lang_info'] = $lang_info;
|
|
|
|
$switch_lang['language'][$language]['lang'] = $lang;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$lang_info = $switch_lang['language'][$language]['lang_info'];
|
|
|
|
$lang = $switch_lang['language'][$language]['lang'];
|
2007-03-14 00:01:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-04 06:39:59 +02:00
|
|
|
/*
|
2007-03-14 00:01:16 +01:00
|
|
|
* Switch back language pushed with switch_lang_to function
|
|
|
|
*
|
|
|
|
* @param: none
|
|
|
|
*/
|
|
|
|
function switch_lang_back()
|
|
|
|
{
|
|
|
|
global $switch_lang, $user, $lang, $lang_info;
|
|
|
|
|
|
|
|
if (count($switch_lang['stack']) > 0)
|
|
|
|
{
|
2010-02-19 00:12:47 +01:00
|
|
|
// Get last value
|
|
|
|
$language = array_pop($switch_lang['stack']);
|
2007-03-14 00:01:16 +01:00
|
|
|
|
2010-02-19 00:12:47 +01:00
|
|
|
// Change current infos
|
|
|
|
if (isset($switch_lang['language'][$language]))
|
2007-03-14 00:01:16 +01:00
|
|
|
{
|
2010-02-19 00:12:47 +01:00
|
|
|
$lang_info = $switch_lang['language'][$language]['lang_info'];
|
|
|
|
$lang = $switch_lang['language'][$language]['lang'];
|
2007-03-14 00:01:16 +01:00
|
|
|
}
|
2007-10-16 23:18:11 +02:00
|
|
|
$user['language'] = $language;
|
2007-03-14 00:01:16 +01:00
|
|
|
}
|
|
|
|
}
|
2007-03-16 00:20:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns email of all administrator
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
/*
|
2007-09-25 23:52:00 +02:00
|
|
|
* send en notification email to all administrators
|
2007-10-04 06:39:59 +02:00
|
|
|
* if a administrator is doing action,
|
2007-03-16 00:20:41 +01:00
|
|
|
* 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)
|
|
|
|
{
|
2007-10-16 23:18:11 +02:00
|
|
|
// Check arguments
|
2008-03-13 02:43:45 +01:00
|
|
|
if
|
2007-10-16 23:18:11 +02:00
|
|
|
(
|
|
|
|
empty($keyargs_subject) or
|
|
|
|
empty($keyargs_content)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-16 00:20:41 +01:00
|
|
|
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
|
2007-09-25 23:52:00 +02:00
|
|
|
'.$conf['user_fields']['email'].' is not null and
|
2007-03-16 00:20:41 +01:00
|
|
|
I.user_id <> '.$user['id'].'
|
|
|
|
order by
|
|
|
|
username
|
|
|
|
';
|
|
|
|
|
|
|
|
$datas = pwg_query($query);
|
|
|
|
if (!empty($datas))
|
|
|
|
{
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($admin = pwg_db_fetch_assoc($datas))
|
2007-03-16 00:20:41 +01:00
|
|
|
{
|
|
|
|
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)
|
2007-09-25 23:52:00 +02:00
|
|
|
{
|
|
|
|
$keyargs_content_admin_info = array
|
|
|
|
(
|
2009-11-18 21:07:20 +01:00
|
|
|
get_l10n_args('Connected user: %s', stripslashes($user['username'])),
|
2007-09-25 23:52:00 +02:00
|
|
|
get_l10n_args('IP: %s', $_SERVER['REMOTE_ADDR']),
|
|
|
|
get_l10n_args('Browser: %s', $_SERVER['HTTP_USER_AGENT'])
|
|
|
|
);
|
2007-03-16 13:08:25 +01:00
|
|
|
|
2007-03-28 21:57:00 +02:00
|
|
|
switch_lang_to(get_default_language());
|
2007-03-16 13:08:25 +01:00
|
|
|
|
|
|
|
$return = pwg_mail
|
|
|
|
(
|
|
|
|
'',
|
|
|
|
array
|
2007-09-25 23:52:00 +02:00
|
|
|
(
|
|
|
|
'Bcc' => $admins,
|
2007-03-16 13:08:25 +01:00
|
|
|
'subject' => '['.$conf['gallery_title'].'] '.l10n_args($keyargs_subject),
|
2007-10-04 06:39:59 +02:00
|
|
|
'content' =>
|
2007-09-25 23:52:00 +02:00
|
|
|
l10n_args($keyargs_content)."\n\n"
|
2007-03-16 13:08:25 +01:00
|
|
|
.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-09-25 23:52:00 +02:00
|
|
|
|
2007-03-14 00:01:16 +01:00
|
|
|
/*
|
|
|
|
* send en email to user's group
|
|
|
|
*
|
2007-09-25 23:52:00 +02:00
|
|
|
* @param:
|
|
|
|
* - group_id: mail are sent to group with this Id
|
|
|
|
* - email_format: mail format
|
|
|
|
* - keyargs_subject: mail subject on l10n_args format
|
2007-03-16 19:49:19 +01:00
|
|
|
* - dirname: short name of directory including template
|
|
|
|
* - tpl_shortname: short template name without extension
|
2007-09-25 23:52:00 +02:00
|
|
|
* - 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-09-25 23:52:00 +02:00
|
|
|
function pwg_mail_group(
|
2007-10-04 06:39:59 +02:00
|
|
|
$group_id, $email_format, $keyargs_subject,
|
2008-10-01 00:14:19 +02:00
|
|
|
$tpl_shortname,
|
2007-03-16 19:49:19 +01:00
|
|
|
$assign_vars = array(), $language_selected = '')
|
2007-03-14 00:01:16 +01:00
|
|
|
{
|
2007-10-16 23:18:11 +02:00
|
|
|
// Check arguments
|
2008-03-13 02:43:45 +01:00
|
|
|
if
|
2007-10-16 23:18:11 +02:00
|
|
|
(
|
|
|
|
empty($group_id) or
|
|
|
|
empty($email_format) or
|
|
|
|
empty($keyargs_subject) or
|
|
|
|
empty($tpl_shortname)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-14 00:01:16 +01:00
|
|
|
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
|
2007-10-04 06:39:59 +02:00
|
|
|
FROM
|
|
|
|
'.USER_GROUP_TABLE.' as ug
|
2007-03-14 00:01:16 +01:00
|
|
|
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
|
2007-10-04 06:39:59 +02:00
|
|
|
WHERE
|
2007-03-14 00:01:16 +01:00
|
|
|
'.$conf['user_fields']['email'].' IS NOT NULL
|
|
|
|
AND group_id = '.$group_id;
|
|
|
|
|
|
|
|
if (!empty($language_selected))
|
|
|
|
{
|
|
|
|
$query .= '
|
|
|
|
AND language = \''.$language_selected.'\'';
|
|
|
|
}
|
|
|
|
|
|
|
|
$query .= '
|
|
|
|
;';
|
|
|
|
|
2007-09-25 23:52:00 +02:00
|
|
|
$result = pwg_query($query);
|
|
|
|
|
2009-11-20 15:17:04 +01:00
|
|
|
if (pwg_db_num_rows($result) > 0)
|
2007-09-25 23:52:00 +02:00
|
|
|
{
|
|
|
|
$list = array();
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2007-09-25 23:52:00 +02:00
|
|
|
{
|
|
|
|
$row['template_theme'] = $row['template'];
|
|
|
|
list($row['template'], $row['theme']) = explode('/', $row['template_theme']);
|
|
|
|
$list[] = $row;
|
|
|
|
}
|
2007-03-14 00:01:16 +01:00
|
|
|
|
2007-10-09 23:35:31 +02:00
|
|
|
foreach ($list as $elem)
|
|
|
|
{
|
|
|
|
$query = '
|
2007-03-14 00:01:16 +01:00
|
|
|
SELECT
|
|
|
|
u.'.$conf['user_fields']['username'].' as username,
|
|
|
|
u.'.$conf['user_fields']['email'].' as mail_address
|
2007-10-04 06:39:59 +02:00
|
|
|
FROM
|
|
|
|
'.USER_GROUP_TABLE.' as ug
|
2007-03-14 00:01:16 +01:00
|
|
|
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
|
2007-10-04 06:39:59 +02:00
|
|
|
WHERE
|
2007-03-14 00:01:16 +01:00
|
|
|
'.$conf['user_fields']['email'].' IS NOT NULL
|
|
|
|
AND group_id = '.$group_id.'
|
2007-09-25 23:52:00 +02:00
|
|
|
AND language = \''.$elem['language'].'\'
|
|
|
|
AND template = \''.$elem['template_theme'].'\'
|
2007-03-14 00:01:16 +01:00
|
|
|
;';
|
|
|
|
|
2007-10-09 23:35:31 +02:00
|
|
|
$result = pwg_query($query);
|
2007-03-14 00:01:16 +01:00
|
|
|
|
2009-11-20 15:17:04 +01:00
|
|
|
if (pwg_db_num_rows($result) > 0)
|
2007-03-14 00:01:16 +01:00
|
|
|
{
|
2007-10-09 23:35:31 +02:00
|
|
|
$Bcc = array();
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2007-03-14 00:01:16 +01:00
|
|
|
{
|
2007-10-09 23:35:31 +02:00
|
|
|
if (!empty($row['mail_address']))
|
|
|
|
{
|
2009-11-18 21:07:20 +01:00
|
|
|
array_push($Bcc, format_email(stripslashes($row['username']), $row['mail_address']));
|
2007-10-09 23:35:31 +02:00
|
|
|
}
|
2007-03-14 00:01:16 +01:00
|
|
|
}
|
|
|
|
|
2007-10-09 23:35:31 +02:00
|
|
|
if (count($Bcc) > 0)
|
|
|
|
{
|
|
|
|
switch_lang_to($elem['language']);
|
2007-03-16 13:08:25 +01:00
|
|
|
|
2007-10-09 23:35:31 +02:00
|
|
|
$mail_template = get_mail_template($email_format, $elem);
|
2008-10-01 00:14:19 +02:00
|
|
|
$mail_template->set_filename($tpl_shortname, $tpl_shortname.'.tpl');
|
2007-10-16 23:18:11 +02:00
|
|
|
|
2008-03-13 02:43:45 +01:00
|
|
|
$mail_template->assign(
|
2007-10-16 23:18:11 +02:00
|
|
|
trigger_event('mail_group_assign_vars', $assign_vars));
|
2007-03-16 13:08:25 +01:00
|
|
|
|
2007-10-09 23:35:31 +02:00
|
|
|
$return = pwg_mail
|
2007-09-25 23:52:00 +02:00
|
|
|
(
|
2007-10-09 23:35:31 +02:00
|
|
|
'',
|
|
|
|
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-16 13:08:25 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-05-15 00:25:36 +02:00
|
|
|
* sends an email, using Piwigo specific informations
|
2007-02-13 00:21:23 +01:00
|
|
|
*
|
|
|
|
* @param:
|
2008-03-18 23:02:33 +01:00
|
|
|
* - to: receiver(s) of the mail (list separated by comma).
|
2007-02-13 00:21:23 +01:00
|
|
|
* - args: function params of mail function:
|
2007-09-25 23:52:00 +02: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]
|
2008-05-15 00:25:36 +02:00
|
|
|
* o subject [default value 'Piwigo']
|
2007-02-13 00:21:23 +01:00
|
|
|
* o content: content of mail [default value '']
|
|
|
|
* o content_format: format of mail content [default value 'text/plain']
|
2007-09-25 23:52:00 +02:00
|
|
|
* o email_format: global mail format [default value $conf_mail['default_email_format']]
|
|
|
|
* o template: template to use [default get_default_template()]
|
2007-03-28 21:57:00 +02:00
|
|
|
* o theme: template to use [default get_default_template()]
|
2007-03-16 00:20:41 +01:00
|
|
|
*
|
|
|
|
* @return boolean (Ok or not)
|
2007-09-25 23:52:00 +02: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-09-25 23:52:00 +02:00
|
|
|
|
|
|
|
if (empty($to) and empty($args['Cc']) and empty($args['Bcc']))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2007-10-04 06:39:59 +02:00
|
|
|
|
2006-02-01 23:07:26 +01:00
|
|
|
if (!isset($conf_mail))
|
|
|
|
{
|
|
|
|
$conf_mail = get_mail_configuration();
|
|
|
|
}
|
2007-09-25 23:52:00 +02:00
|
|
|
|
|
|
|
if (empty($args['email_format']))
|
|
|
|
{
|
|
|
|
$args['email_format'] = $conf_mail['default_email_format'];
|
|
|
|
}
|
|
|
|
|
2006-12-19 23:05:01 +01:00
|
|
|
// Compute root_path in order have complete path
|
2009-09-28 22:54:06 +02:00
|
|
|
set_make_full_url();
|
2007-09-25 23:52:00 +02: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']))
|
|
|
|
{
|
2008-05-15 00:25:36 +02:00
|
|
|
$args['subject'] = 'Piwigo';
|
2006-02-01 23:07:26 +01:00
|
|
|
}
|
2007-09-25 23:52:00 +02:00
|
|
|
// Spring cleaning
|
|
|
|
$cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject']));
|
|
|
|
// Ascii convertion
|
2007-10-04 06:39:59 +02:00
|
|
|
$cvt_subject = encode_mime_header($cvt_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-09-25 23:52:00 +02:00
|
|
|
|
|
|
|
if ($conf_mail['send_bcc_mail_webmaster'])
|
|
|
|
{
|
|
|
|
$args['Bcc'][] = $conf_mail['formated_email_webmaster'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$args = array_merge($args, get_array_template_theme($args));
|
|
|
|
|
2007-02-13 00:21:23 +01:00
|
|
|
$headers = 'From: '.$args['from']."\n";
|
2007-09-25 23:52:00 +02:00
|
|
|
$headers.= 'Reply-To: '.$args['from']."\n";
|
|
|
|
|
|
|
|
if (!empty($args['Cc']))
|
|
|
|
{
|
|
|
|
$headers.= 'Cc: '.implode(',', $args['Cc'])."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($args['Bcc']))
|
|
|
|
{
|
|
|
|
$headers.= 'Bcc: '.implode(',', $args['Bcc'])."\n";
|
|
|
|
}
|
2007-02-14 23:53:04 +01:00
|
|
|
|
2007-02-13 00:21:23 +01:00
|
|
|
$headers.= 'Content-Type: multipart/alternative;'."\n";
|
|
|
|
$headers.= ' boundary="---='.$conf_mail['boundary_key'].'";'."\n";
|
2007-09-25 23:52:00 +02:00
|
|
|
$headers.= ' reply-type=original'."\n";
|
|
|
|
$headers.= 'MIME-Version: 1.0'."\n";
|
|
|
|
$headers.= 'X-Mailer: Piwigo Mailer'."\n";
|
|
|
|
|
2009-09-28 22:54:06 +02:00
|
|
|
// List on content-type
|
|
|
|
$content_type_list[] = $args['email_format'];
|
|
|
|
if (!empty($conf_mail['alternative_email_format']))
|
|
|
|
{
|
|
|
|
$content_type_list[] = $conf_mail['alternative_email_format'];
|
|
|
|
}
|
2007-09-25 23:52:00 +02:00
|
|
|
|
2009-09-28 22:54:06 +02:00
|
|
|
$content = '';
|
2007-10-09 23:35:31 +02:00
|
|
|
|
2009-09-28 22:54:06 +02:00
|
|
|
foreach (array_unique($content_type_list) as $content_type)
|
2007-09-25 23:52:00 +02:00
|
|
|
{
|
2009-09-28 22:54:06 +02:00
|
|
|
// key compose of indexes witch allow ti cache mail data
|
|
|
|
$cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['template'].'-'.$args['theme'];
|
2007-09-25 23:52:00 +02:00
|
|
|
|
2009-09-28 22:54:06 +02:00
|
|
|
if (!isset($conf_mail[$cache_key]))
|
2007-09-25 23:52:00 +02:00
|
|
|
{
|
2009-09-28 22:54:06 +02:00
|
|
|
if (!isset($conf_mail[$cache_key]['template']))
|
2007-09-25 23:52:00 +02:00
|
|
|
{
|
2009-09-28 22:54:06 +02:00
|
|
|
$conf_mail[$cache_key]['template'] = get_mail_template($content_type);
|
2007-09-25 23:52:00 +02:00
|
|
|
}
|
|
|
|
|
2009-09-28 22:54:06 +02:00
|
|
|
$conf_mail[$cache_key]['template']->set_filename('mail_header', 'header.tpl');
|
|
|
|
$conf_mail[$cache_key]['template']->set_filename('mail_footer', 'footer.tpl');
|
|
|
|
|
|
|
|
$conf_mail[$cache_key]['template']->assign(
|
|
|
|
array(
|
|
|
|
//Header
|
|
|
|
'BOUNDARY_KEY' => $conf_mail['boundary_key'],
|
|
|
|
'CONTENT_TYPE' => $content_type,
|
|
|
|
'CONTENT_ENCODING' => get_pwg_charset(),
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
|
2010-03-02 15:54:22 +01:00
|
|
|
'TITLE_MAIL' => urlencode(l10n('A comment on your site')),
|
2009-09-28 22:54:06 +02:00
|
|
|
'MAIL' => get_webmaster_mail_address()
|
|
|
|
));
|
|
|
|
|
|
|
|
if ($content_type == 'text/html')
|
2007-09-25 23:52:00 +02:00
|
|
|
{
|
2009-09-28 22:54:06 +02:00
|
|
|
if (is_file($conf_mail[$cache_key]['template']->get_template_dir().'/global-mail-css.tpl'))
|
|
|
|
{
|
|
|
|
$conf_mail[$cache_key]['template']->set_filename('css', 'global-mail-css.tpl');
|
|
|
|
$conf_mail[$cache_key]['template']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css');
|
|
|
|
}
|
2007-09-25 23:52:00 +02:00
|
|
|
|
2009-09-28 22:54:06 +02:00
|
|
|
$root_abs_path = dirname(dirname(__FILE__));
|
|
|
|
|
|
|
|
$file = $root_abs_path.'/template/'.$args['template'].'/theme/'.$args['theme'].'/mail-css.tpl';
|
|
|
|
if (is_file($file))
|
|
|
|
{
|
|
|
|
$conf_mail[$cache_key]['template']->set_filename('css', $file);
|
|
|
|
$conf_mail[$cache_key]['template']->assign_var_from_handle('MAIL_CSS', 'css');
|
|
|
|
}
|
|
|
|
|
|
|
|
$file = $root_abs_path.'/template-common/local-mail-css.tpl';
|
|
|
|
if (is_file($file))
|
|
|
|
{
|
|
|
|
$conf_mail[$cache_key]['template']->set_filename('css', $file);
|
|
|
|
$conf_mail[$cache_key]['template']->assign_var_from_handle('LOCAL_MAIL_CSS', 'css');
|
|
|
|
}
|
2007-09-25 23:52:00 +02:00
|
|
|
}
|
|
|
|
|
2009-09-28 22:54:06 +02:00
|
|
|
// what are displayed on the header of each mail ?
|
|
|
|
$conf_mail[$cache_key]['header'] =
|
|
|
|
$conf_mail[$cache_key]['template']->parse('mail_header', true);
|
2007-02-06 23:55:12 +01:00
|
|
|
|
2009-09-28 22:54:06 +02:00
|
|
|
// what are displayed on the footer of each mail ?
|
|
|
|
$conf_mail[$cache_key]['footer'] =
|
|
|
|
$conf_mail[$cache_key]['template']->parse('mail_footer', true);
|
|
|
|
}
|
2007-02-13 00:21:23 +01:00
|
|
|
|
2009-09-28 22:54:06 +02:00
|
|
|
// Header
|
|
|
|
$content.= $conf_mail[$cache_key]['header'];
|
2006-12-08 00:49:52 +01:00
|
|
|
|
2009-09-28 22:54:06 +02:00
|
|
|
// Content
|
|
|
|
if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html'))
|
|
|
|
{
|
|
|
|
$content.= '<p>'.
|
|
|
|
nl2br(
|
|
|
|
preg_replace("/(http:\/\/)([^\s,]*)/i",
|
|
|
|
"<a href='$1$2' class='thumblnk'>$1$2</a>",
|
|
|
|
htmlspecialchars($args['content']))).
|
|
|
|
'</p>';
|
|
|
|
}
|
|
|
|
else if (($args['content_format'] == 'text/html') and ($content_type == 'text/plain'))
|
|
|
|
{
|
|
|
|
// convert html text to plain text
|
|
|
|
$content.= strip_tags($args['content']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$content.= $args['content'];
|
|
|
|
}
|
2007-02-13 00:21:23 +01:00
|
|
|
|
2009-09-28 22:54:06 +02:00
|
|
|
// Footer
|
|
|
|
$content.= $conf_mail[$cache_key]['footer'];
|
2007-02-13 00:21:23 +01:00
|
|
|
|
|
|
|
// Close boundary
|
|
|
|
$content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
|
2009-09-28 22:54:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//~ // Close boundary
|
|
|
|
//~ $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
|
2007-02-13 00:21:23 +01:00
|
|
|
|
2006-12-19 23:05:01 +01:00
|
|
|
// Undo Compute root_path in order have complete path
|
2009-09-28 22:54:06 +02:00
|
|
|
unset_make_full_url();
|
2006-02-01 00:42:42 +01:00
|
|
|
|
2007-10-16 23:18:11 +02:00
|
|
|
return
|
|
|
|
trigger_event('send_mail',
|
|
|
|
false, /* Result */
|
2008-03-18 23:02:33 +01:00
|
|
|
trigger_event('send_mail_to', get_strict_email_list($to)),
|
2007-10-16 23:18:11 +02:00
|
|
|
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.
|
2008-05-15 00:25:36 +02:00
|
|
|
* - subject [default value 'Piwigo']
|
2007-10-16 23:18:11 +02:00
|
|
|
* - content: content of mail
|
|
|
|
* - headers: headers of mail
|
|
|
|
*
|
|
|
|
* @return boolean (Ok or not)
|
|
|
|
*/
|
|
|
|
function pwg_send_mail($result, $to, $subject, $content, $headers)
|
|
|
|
{
|
2008-03-17 21:22:05 +01:00
|
|
|
if (!$result)
|
|
|
|
{
|
2007-10-16 23:18:11 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2008-03-17 21:22:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $result;
|
|
|
|
}
|
2007-10-16 23:18:11 +02:00
|
|
|
}
|
|
|
|
|
2008-03-13 02:43:45 +01:00
|
|
|
/*Testing block*/
|
|
|
|
/*function pwg_send_mail_test($result, $to, $subject, $content, $headers, $args)
|
2007-10-16 23:18:11 +02:00
|
|
|
{
|
2008-03-13 02:43:45 +01:00
|
|
|
global $conf, $user, $lang_info;
|
|
|
|
$dir = $conf['local_data_dir'].'/tmp';
|
2008-09-04 03:28:34 +02:00
|
|
|
if ( mkgetdir( $dir, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR) )
|
2007-02-06 23:55:12 +01:00
|
|
|
{
|
2009-11-18 21:07:20 +01:00
|
|
|
$filename = $dir.'/mail.'.stripslashes($user['username']).'.'.$lang_info['code'].'.'.$args['template'].'.'.$args['theme'];
|
2008-09-04 03:28:34 +02:00
|
|
|
if ($args['content_format'] == 'text/plain')
|
|
|
|
{
|
|
|
|
$filename .= '.txt';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$filename .= '.html';
|
|
|
|
}
|
|
|
|
$file = fopen($filename, 'w+');
|
|
|
|
fwrite($file, $to ."\n");
|
|
|
|
fwrite($file, $subject ."\n");
|
|
|
|
fwrite($file, $headers);
|
|
|
|
fwrite($file, $content);
|
|
|
|
fclose($file);
|
2007-02-06 23:55:12 +01:00
|
|
|
}
|
2008-03-13 02:43:45 +01:00
|
|
|
return $result;
|
2006-02-01 23:07:26 +01:00
|
|
|
}
|
2008-03-13 02:43:45 +01:00
|
|
|
add_event_handler('send_mail', 'pwg_send_mail_test', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 6);*/
|
2007-10-16 23:18:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
add_event_handler('send_mail', 'pwg_send_mail', EVENT_HANDLER_PRIORITY_NEUTRAL, 5);
|
|
|
|
trigger_action('functions_mail_included');
|
2006-03-27 00:06:20 +02:00
|
|
|
|
2006-05-26 17:51:36 +02:00
|
|
|
?>
|