[1021] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[1726] | 5 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[1021] | 6 | // | Copyright (C) 2006 Ruben ARNAUD - team@phpwebgallery.net | |
---|
| 7 | // +-----------------------------------------------------------------------+ |
---|
| 8 | // | branch : BSF (Best So Far) |
---|
| 9 | // | file : $RCSfile$ |
---|
| 10 | // | last update : $Date: 2005-11-26 21:15:50 +0100 (sam., 26 nov. 2005) $ |
---|
| 11 | // | last modifier : $Author: plg $ |
---|
| 12 | // | revision : $Revision: 958 $ |
---|
| 13 | // +-----------------------------------------------------------------------+ |
---|
| 14 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 15 | // | it under the terms of the GNU General Public License as published by | |
---|
| 16 | // | the Free Software Foundation | |
---|
| 17 | // | | |
---|
| 18 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 19 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 20 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 21 | // | General Public License for more details. | |
---|
| 22 | // | | |
---|
| 23 | // | You should have received a copy of the GNU General Public License | |
---|
| 24 | // | along with this program; if not, write to the Free Software | |
---|
| 25 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 26 | // | USA. | |
---|
| 27 | // +-----------------------------------------------------------------------+ |
---|
[1019] | 28 | |
---|
[1021] | 29 | /** |
---|
| 30 | * - Extract mail fonctions of password.php |
---|
| 31 | * - Modify pwg_mail (add pararameters + news fonctionnalities) |
---|
[1105] | 32 | * - Var conf_mail, function get_mail_configuration, format_email, pwg_mail |
---|
[1021] | 33 | */ |
---|
| 34 | |
---|
[1019] | 35 | // +-----------------------------------------------------------------------+ |
---|
| 36 | // | functions | |
---|
| 37 | // +-----------------------------------------------------------------------+ |
---|
[1021] | 38 | |
---|
[1019] | 39 | /* |
---|
[1021] | 40 | * Returns an array of mail configuration parameters : |
---|
| 41 | * |
---|
| 42 | * - mail_options: see $conf['mail_options'] |
---|
| 43 | * - send_bcc_mail_webmaster: see $conf['send_bcc_mail_webmaster'] |
---|
| 44 | * - email_webmaster: mail corresponding to $conf['webmaster_id'] |
---|
| 45 | * - formated_email_webmaster: the name of webmaster is $conf['gallery_title'] |
---|
| 46 | * - text_footer: PhpWebGallery and version |
---|
| 47 | * |
---|
| 48 | * @return array |
---|
[1019] | 49 | */ |
---|
[1021] | 50 | function get_mail_configuration() |
---|
| 51 | { |
---|
| 52 | global $conf; |
---|
[1019] | 53 | |
---|
[1021] | 54 | $conf_mail = array( |
---|
| 55 | 'mail_options' => $conf['mail_options'], |
---|
[1642] | 56 | 'send_bcc_mail_webmaster' => $conf['send_bcc_mail_webmaster'], |
---|
| 57 | 'default_email_format' => $conf['default_email_format'] |
---|
[1021] | 58 | ); |
---|
| 59 | |
---|
| 60 | // we have webmaster id among user list, what's his email address ? |
---|
| 61 | $conf_mail['email_webmaster'] = get_webmaster_mail_address(); |
---|
| 62 | |
---|
| 63 | // name of the webmaster is the title of the gallery |
---|
| 64 | $conf_mail['formated_email_webmaster'] = |
---|
| 65 | format_email($conf['gallery_title'], $conf_mail['email_webmaster']); |
---|
| 66 | |
---|
| 67 | return $conf_mail; |
---|
| 68 | } |
---|
| 69 | |
---|
[1019] | 70 | /** |
---|
[1021] | 71 | * Returns an email address with an associated real name |
---|
| 72 | * |
---|
| 73 | * @param string name |
---|
| 74 | * @param string email |
---|
| 75 | */ |
---|
| 76 | function format_email($name, $email) |
---|
| 77 | { |
---|
[1531] | 78 | global $conf; |
---|
[1361] | 79 | |
---|
[1531] | 80 | if ($conf['enabled_format_email']) |
---|
[1021] | 81 | { |
---|
[1531] | 82 | $cvt7b_name = str_translate_to_ascii7bits($name); |
---|
| 83 | |
---|
| 84 | if (strpos($email, '<') === false) |
---|
| 85 | { |
---|
| 86 | return $cvt7b_name.' <'.$email.'>'; |
---|
| 87 | } |
---|
| 88 | else |
---|
| 89 | { |
---|
| 90 | return $cvt7b_name.$email; |
---|
| 91 | } |
---|
[1021] | 92 | } |
---|
| 93 | else |
---|
| 94 | { |
---|
[1531] | 95 | return $email; |
---|
[1021] | 96 | } |
---|
| 97 | } |
---|
[1645] | 98 | |
---|
| 99 | /** |
---|
| 100 | * Returns an new mail template |
---|
| 101 | * |
---|
| 102 | * @param none |
---|
| 103 | */ |
---|
[1784] | 104 | function get_mail_template($email_format) |
---|
[1645] | 105 | { |
---|
[1792] | 106 | global $user; |
---|
[1645] | 107 | |
---|
[1792] | 108 | $mail_template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme']); |
---|
| 109 | $mail_template->set_rootdir(PHPWG_ROOT_PATH.'template/'.$user['template'].'/mail/'.$email_format); |
---|
[1645] | 110 | |
---|
| 111 | return $mail_template; |
---|
| 112 | } |
---|
[1784] | 113 | |
---|
| 114 | /** |
---|
| 115 | * Return string email format (html or not) |
---|
| 116 | * |
---|
| 117 | * @param string format |
---|
| 118 | */ |
---|
| 119 | function get_str_email_format($is_html) |
---|
| 120 | { |
---|
| 121 | return ($is_html ? 'text/html' : 'text/plain'); |
---|
| 122 | } |
---|
[1021] | 123 | |
---|
| 124 | /** |
---|
[1019] | 125 | * sends an email, using PhpWebGallery specific informations |
---|
[1642] | 126 | */ |
---|
| 127 | function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $format_infos = 'text/plain', $email_format = null) |
---|
[1019] | 128 | { |
---|
[1792] | 129 | global $conf, $conf_mail, $lang_info, $page, $user; |
---|
[1019] | 130 | |
---|
[1361] | 131 | $cvt7b_subject = str_translate_to_ascii7bits($subject); |
---|
| 132 | |
---|
[1021] | 133 | if (!isset($conf_mail)) |
---|
| 134 | { |
---|
| 135 | $conf_mail = get_mail_configuration(); |
---|
| 136 | } |
---|
[1642] | 137 | |
---|
| 138 | if (is_null($email_format)) |
---|
| 139 | { |
---|
| 140 | $email_format = $conf_mail['default_email_format']; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | if (($format_infos == 'text/html') and ($email_format == 'text/plain')) |
---|
| 144 | { |
---|
| 145 | // Todo find function to convert html text to plain text |
---|
| 146 | return false; |
---|
| 147 | } |
---|
[1019] | 148 | |
---|
[1676] | 149 | // Compute root_path in order have complete path |
---|
| 150 | if ($email_format == 'text/html') |
---|
| 151 | { |
---|
| 152 | set_make_full_url(); |
---|
| 153 | } |
---|
| 154 | |
---|
[1021] | 155 | $to = format_email('', $to); |
---|
[1019] | 156 | |
---|
[1021] | 157 | if ($from == '') |
---|
| 158 | { |
---|
| 159 | $from = $conf_mail['formated_email_webmaster']; |
---|
| 160 | } |
---|
| 161 | else |
---|
| 162 | { |
---|
| 163 | $from = format_email('', $from); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | $headers = 'From: '.$from."\n"; |
---|
| 167 | $headers.= 'Reply-To: '.$from."\n"; |
---|
[1642] | 168 | $headers.= 'Content-Type: '.$email_format.';format=flowed;charset="'.$lang_info['charset'].'";'; |
---|
[1532] | 169 | $headers.= 'reply-type=original'."\n"; |
---|
| 170 | |
---|
[1021] | 171 | if ($conf_mail['send_bcc_mail_webmaster']) |
---|
| 172 | { |
---|
| 173 | $headers.= 'Bcc: '.$conf_mail['formated_email_webmaster']."\n"; |
---|
| 174 | } |
---|
[1642] | 175 | |
---|
| 176 | $content = ''; |
---|
| 177 | |
---|
[1792] | 178 | if (!isset($conf_mail[$email_format][$lang_info['charset']][$user['template']][$user['theme']])) |
---|
[1642] | 179 | { |
---|
[1784] | 180 | if (!isset($mail_template)) |
---|
[1645] | 181 | { |
---|
[1784] | 182 | $mail_template = get_mail_template($email_format); |
---|
| 183 | } |
---|
[1644] | 184 | |
---|
[1784] | 185 | $mail_template->set_filename('mail_header', 'header.tpl'); |
---|
| 186 | $mail_template->set_filename('mail_footer', 'footer.tpl'); |
---|
[1642] | 187 | |
---|
[1784] | 188 | $mail_template->assign_vars( |
---|
| 189 | array( |
---|
| 190 | //Header |
---|
| 191 | 'CONTENT_ENCODING' => $lang_info['charset'], |
---|
| 192 | 'LANG' => $lang_info['code'], |
---|
| 193 | 'DIR' => $lang_info['direction'], |
---|
| 194 | |
---|
| 195 | // Footer |
---|
| 196 | 'GALLERY_URL' => |
---|
| 197 | isset($page['gallery_url']) ? |
---|
| 198 | $page['gallery_url'] : $conf['gallery_url'], |
---|
| 199 | 'GALLERY_TITLE' => |
---|
| 200 | isset($page['gallery_title']) ? |
---|
| 201 | $page['gallery_title'] : $conf['gallery_title'], |
---|
| 202 | 'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', |
---|
| 203 | 'PHPWG_URL' => PHPWG_URL, |
---|
[1642] | 204 | |
---|
[1784] | 205 | 'TITLE_MAIL' => urlencode(l10n('title_send_mail')), |
---|
| 206 | 'MAIL' => get_webmaster_mail_address() |
---|
| 207 | )); |
---|
| 208 | |
---|
[1797] | 209 | $mail_template->set_filename('mail_css_default_template', 'default-layout-mail-css.tpl'); |
---|
| 210 | $mail_template->assign_var_from_handle('MAIL_CSS_DEFAULT_TEMPLATE', 'mail_css_default_template'); |
---|
| 211 | |
---|
| 212 | $old_root = $mail_template->root; |
---|
| 213 | |
---|
| 214 | $mail_template->root = PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/'.$user['theme']; |
---|
| 215 | if (is_file($mail_template->root.'/layout-mail-css.tpl')) |
---|
| 216 | { |
---|
| 217 | $mail_template->set_filename('mail_css_theme', 'layout-mail-css.tpl'); |
---|
| 218 | $mail_template->assign_var_from_handle('MAIL_CSS_THEME', 'mail_css_theme'); |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | $mail_template->root = PHPWG_ROOT_PATH.'template-common'; |
---|
| 222 | if (is_file($mail_template->root.'/local-layout-mail-css.tpl')) |
---|
| 223 | { |
---|
| 224 | $mail_template->set_filename('mail_css_local_template', 'local-layout-mail-css.tpl'); |
---|
| 225 | $mail_template->assign_var_from_handle('MAIL_CSS_LOCAL_COMMON', 'mail_css_local_template'); |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | $mail_template->root = $old_root; |
---|
| 229 | if (is_file($mail_template->root.'/local-layout-mail-css.tpl')) |
---|
| 230 | { |
---|
| 231 | $mail_template->set_filename('mail_css_local_template', 'local-layout-mail-css.tpl'); |
---|
| 232 | $mail_template->assign_var_from_handle('MAIL_CSS_LOCAL_TEMPLATE', 'mail_css_local_template'); |
---|
| 233 | } |
---|
| 234 | |
---|
[1784] | 235 | // what are displayed on the header of each mail ? |
---|
[1792] | 236 | $conf_mail[$email_format] |
---|
| 237 | [$lang_info['charset']] |
---|
| 238 | [$user['template']][$user['theme']]['header'] = |
---|
| 239 | $mail_template->parse('mail_header', true); |
---|
[1784] | 240 | |
---|
| 241 | // what are displayed on the footer of each mail ? |
---|
[1792] | 242 | $conf_mail[$email_format] |
---|
| 243 | [$lang_info['charset']] |
---|
| 244 | [$user['template']][$user['theme']]['footer'] = |
---|
| 245 | $mail_template->parse('mail_footer', true); |
---|
[1642] | 246 | } |
---|
[1645] | 247 | |
---|
[1792] | 248 | $content.= $conf_mail[$email_format] |
---|
| 249 | [$lang_info['charset']] |
---|
| 250 | [$user['template']][$user['theme']]['header']; |
---|
[1019] | 251 | |
---|
[1642] | 252 | if (($format_infos == 'text/plain') and ($email_format == 'text/html')) |
---|
| 253 | { |
---|
| 254 | $content.= '<pre>'.htmlentities($infos).'</pre>'; |
---|
| 255 | } |
---|
| 256 | else |
---|
| 257 | { |
---|
| 258 | $content.= $infos; |
---|
| 259 | } |
---|
| 260 | |
---|
[1792] | 261 | $content.= $conf_mail[$email_format] |
---|
| 262 | [$lang_info['charset']] |
---|
| 263 | [$user['template']][$user['theme']]['footer']; |
---|
[1676] | 264 | |
---|
| 265 | // Undo Compute root_path in order have complete path |
---|
| 266 | if ($email_format == 'text/html') |
---|
| 267 | { |
---|
| 268 | unset_make_full_url(); |
---|
| 269 | } |
---|
[1642] | 270 | |
---|
[1784] | 271 | /*Testing block |
---|
| 272 | { |
---|
| 273 | global $user; |
---|
| 274 | @mkdir(PHPWG_ROOT_PATH.'testmail'); |
---|
| 275 | $filename = PHPWG_ROOT_PATH.'testmail/mail.'.$user['username']; |
---|
| 276 | if ($format_infos == 'text/plain') |
---|
| 277 | { |
---|
| 278 | $filename .= '.txt'; |
---|
| 279 | } |
---|
| 280 | else |
---|
| 281 | { |
---|
| 282 | $filename .= '.html'; |
---|
| 283 | } |
---|
| 284 | $file = fopen($filename, 'w+'); |
---|
| 285 | fwrite($file, $content); |
---|
| 286 | fclose($file); |
---|
| 287 | return true; |
---|
[1792] | 288 | }*/ |
---|
[1784] | 289 | |
---|
[1019] | 290 | if ($conf_mail['mail_options']) |
---|
| 291 | { |
---|
[1531] | 292 | $options = '-f '.$conf_mail['email_webmaster']; |
---|
[1021] | 293 | |
---|
[1361] | 294 | return mail($to, $cvt7b_subject, $content, $headers, $options); |
---|
[1019] | 295 | } |
---|
| 296 | else |
---|
| 297 | { |
---|
[1361] | 298 | return mail($to, $cvt7b_subject, $content, $headers); |
---|
[1019] | 299 | } |
---|
[1021] | 300 | } |
---|
[1105] | 301 | |
---|
[1321] | 302 | ?> |
---|