[1021] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2008 Piwigo Team http://piwigo.org | |
---|
| 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[1019] | 23 | |
---|
| 24 | // +-----------------------------------------------------------------------+ |
---|
| 25 | // | functions | |
---|
| 26 | // +-----------------------------------------------------------------------+ |
---|
[1021] | 27 | |
---|
[2121] | 28 | |
---|
| 29 | /** |
---|
| 30 | * Encodes a string using Q form if required (RFC2045) |
---|
| 31 | * mail headers MUST contain only US-ASCII characters |
---|
| 32 | */ |
---|
| 33 | function encode_mime_header($str) |
---|
| 34 | { |
---|
| 35 | $x = preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); |
---|
| 36 | if ($x==0) |
---|
| 37 | { |
---|
| 38 | return $str; |
---|
| 39 | } |
---|
| 40 | // Replace every high ascii, control =, ? and _ characters |
---|
| 41 | $str = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', |
---|
| 42 | "'='.sprintf('%02X', ord('\\1'))", $str); |
---|
| 43 | |
---|
| 44 | // Replace every spaces to _ (more readable than =20) |
---|
| 45 | $str = str_replace(" ", "_", $str); |
---|
| 46 | |
---|
| 47 | global $lang_info; |
---|
[2126] | 48 | return '=?'.get_pwg_charset().'?Q?'.$str.'?='; |
---|
[2121] | 49 | } |
---|
| 50 | |
---|
[1019] | 51 | /* |
---|
[2284] | 52 | * Returns the name of the mail sender : |
---|
| 53 | * |
---|
| 54 | * @return string |
---|
| 55 | */ |
---|
| 56 | function get_mail_sender_name() |
---|
| 57 | { |
---|
| 58 | global $conf; |
---|
| 59 | |
---|
| 60 | return (empty($conf['mail_sender_name']) ? $conf['gallery_title'] : $conf['mail_sender_name']); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /* |
---|
[1021] | 64 | * Returns an array of mail configuration parameters : |
---|
| 65 | * |
---|
| 66 | * - mail_options: see $conf['mail_options'] |
---|
| 67 | * - send_bcc_mail_webmaster: see $conf['send_bcc_mail_webmaster'] |
---|
| 68 | * - email_webmaster: mail corresponding to $conf['webmaster_id'] |
---|
| 69 | * - formated_email_webmaster: the name of webmaster is $conf['gallery_title'] |
---|
[2339] | 70 | * - text_footer: Piwigo and version |
---|
[1021] | 71 | * |
---|
| 72 | * @return array |
---|
[1019] | 73 | */ |
---|
[1021] | 74 | function get_mail_configuration() |
---|
| 75 | { |
---|
| 76 | global $conf; |
---|
[1019] | 77 | |
---|
[1021] | 78 | $conf_mail = array( |
---|
| 79 | 'mail_options' => $conf['mail_options'], |
---|
[2106] | 80 | 'send_bcc_mail_webmaster' => $conf['send_bcc_mail_webmaster'], |
---|
| 81 | 'default_email_format' => $conf['default_email_format'], |
---|
| 82 | 'use_smtp' => !empty($conf['smtp_host']), |
---|
| 83 | 'smtp_host' => $conf['smtp_host'], |
---|
| 84 | 'smtp_user' => $conf['smtp_user'], |
---|
| 85 | 'smtp_password' => $conf['smtp_password'] |
---|
[1021] | 86 | ); |
---|
| 87 | |
---|
| 88 | // we have webmaster id among user list, what's his email address ? |
---|
| 89 | $conf_mail['email_webmaster'] = get_webmaster_mail_address(); |
---|
| 90 | |
---|
| 91 | // name of the webmaster is the title of the gallery |
---|
| 92 | $conf_mail['formated_email_webmaster'] = |
---|
[2284] | 93 | format_email(get_mail_sender_name(), $conf_mail['email_webmaster']); |
---|
[1021] | 94 | |
---|
[1809] | 95 | $conf_mail['boundary_key'] = generate_key(32); |
---|
| 96 | |
---|
[1021] | 97 | return $conf_mail; |
---|
| 98 | } |
---|
| 99 | |
---|
[1019] | 100 | /** |
---|
[1021] | 101 | * Returns an email address with an associated real name |
---|
| 102 | * |
---|
| 103 | * @param string name |
---|
| 104 | * @param string email |
---|
| 105 | */ |
---|
| 106 | function format_email($name, $email) |
---|
| 107 | { |
---|
[2280] | 108 | // Spring cleaning |
---|
| 109 | $cvt_email = trim(preg_replace('#[\n\r]+#s', '', $email)); |
---|
[2284] | 110 | $cvt_name = trim(preg_replace('#[\n\r]+#s', '', $name)); |
---|
[2280] | 111 | |
---|
[2284] | 112 | if ($cvt_name!="") |
---|
[1021] | 113 | { |
---|
[2284] | 114 | $cvt_name = encode_mime_header( |
---|
| 115 | '"' |
---|
| 116 | .addcslashes($cvt_name,'"') |
---|
| 117 | .'"'); |
---|
| 118 | $cvt_name .= ' '; |
---|
| 119 | } |
---|
[1531] | 120 | |
---|
[2284] | 121 | if (strpos($cvt_email, '<') === false) |
---|
| 122 | { |
---|
| 123 | return $cvt_name.'<'.$cvt_email.'>'; |
---|
[1021] | 124 | } |
---|
| 125 | else |
---|
| 126 | { |
---|
[2284] | 127 | return $cvt_name.$cvt_email; |
---|
[1021] | 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
[2106] | 131 | /** |
---|
[2284] | 132 | * Returns an email address list with minimal email string |
---|
| 133 | * |
---|
| 134 | * @param string with email list (email separated by comma) |
---|
| 135 | */ |
---|
| 136 | function get_strict_email_list($email_list) |
---|
| 137 | { |
---|
| 138 | $result = array(); |
---|
| 139 | $list = explode(',', $email_list); |
---|
| 140 | foreach ($list as $email) |
---|
| 141 | { |
---|
| 142 | if (strpos($email, '<') !== false) |
---|
| 143 | { |
---|
| 144 | $email = preg_replace('/.*<(.*)>.*/i', '$1', $email); |
---|
| 145 | } |
---|
| 146 | $result[] = trim($email); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | return implode(',', $result); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | /** |
---|
[2106] | 153 | * Returns an completed array template/theme |
---|
| 154 | * completed with get_default_template() |
---|
| 155 | * |
---|
| 156 | * @params: |
---|
| 157 | * - args: incompleted array of template/theme |
---|
| 158 | * o template: template to use [default get_default_template()] |
---|
| 159 | * o theme: template to use [default get_default_template()] |
---|
| 160 | */ |
---|
| 161 | function get_array_template_theme($args = array()) |
---|
| 162 | { |
---|
| 163 | global $conf; |
---|
| 164 | |
---|
| 165 | $res = array(); |
---|
[2121] | 166 | |
---|
[2106] | 167 | if (empty($args['template']) or empty($args['theme'])) |
---|
| 168 | { |
---|
| 169 | list($res['template'], $res['theme']) = explode('/', get_default_template()); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | if (!empty($args['template'])) |
---|
| 173 | { |
---|
| 174 | $res['template'] = $args['template']; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | if (!empty($args['theme'])) |
---|
| 178 | { |
---|
| 179 | $res['theme'] = $args['theme']; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | return $res; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | /** |
---|
| 186 | * Return an new mail template |
---|
| 187 | * |
---|
| 188 | * @params: |
---|
| 189 | * - email_format: mail format |
---|
| 190 | * - args: function params of mail function: |
---|
| 191 | * o template: template to use [default get_default_template()] |
---|
| 192 | * o theme: template to use [default get_default_template()] |
---|
| 193 | */ |
---|
[2278] | 194 | function & get_mail_template($email_format, $args = array()) |
---|
[2106] | 195 | { |
---|
| 196 | $args = get_array_template_theme($args); |
---|
| 197 | |
---|
| 198 | $mail_template = new Template(PHPWG_ROOT_PATH.'template/'.$args['template'], $args['theme']); |
---|
[2278] | 199 | $mail_template->set_template_dir(PHPWG_ROOT_PATH.'template/'.$args['template'].'/mail/'.$email_format); |
---|
[2106] | 200 | return $mail_template; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | /** |
---|
[2121] | 204 | * Return string email format (html or not) |
---|
[2106] | 205 | * |
---|
| 206 | * @param string format |
---|
| 207 | */ |
---|
| 208 | function get_str_email_format($is_html) |
---|
| 209 | { |
---|
| 210 | return ($is_html ? 'text/html' : 'text/plain'); |
---|
| 211 | } |
---|
| 212 | |
---|
[2121] | 213 | /* |
---|
[1904] | 214 | * Switch language to param language |
---|
| 215 | * All entries are push on language stack |
---|
| 216 | * |
---|
| 217 | * @param string language |
---|
| 218 | */ |
---|
| 219 | function switch_lang_to($language) |
---|
| 220 | { |
---|
| 221 | global $switch_lang, $user, $lang, $lang_info; |
---|
| 222 | |
---|
| 223 | if (count($switch_lang['stack']) == 0) |
---|
| 224 | { |
---|
| 225 | $prev_language = $user['language']; |
---|
| 226 | } |
---|
| 227 | else |
---|
| 228 | { |
---|
| 229 | $prev_language = end($switch_lang['stack']); |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | $switch_lang['stack'][] = $language; |
---|
| 233 | |
---|
| 234 | if ($prev_language != $language) |
---|
| 235 | { |
---|
| 236 | if (!isset($switch_lang['language'][$prev_language])) |
---|
| 237 | { |
---|
| 238 | $switch_lang[$prev_language]['lang_info'] = $lang_info; |
---|
| 239 | $switch_lang[$prev_language]['lang'] = $lang; |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | if (!isset($switch_lang['language'][$language])) |
---|
| 243 | { |
---|
| 244 | // Re-Init language arrays |
---|
| 245 | $lang_info = array(); |
---|
| 246 | $lang = array(); |
---|
| 247 | |
---|
| 248 | // language files |
---|
[2479] | 249 | load_language('common.lang', '', array('language'=>$language) ); |
---|
[1904] | 250 | // No test admin because script is checked admin (user selected no) |
---|
| 251 | // Translations are in admin file too |
---|
[2479] | 252 | load_language('admin.lang', '', array('language'=>$language) ); |
---|
[1904] | 253 | trigger_action('loading_lang'); |
---|
[2479] | 254 | load_language('local.lang', '', array('language'=>$language, 'no_fallback'=>true)); |
---|
[1904] | 255 | |
---|
| 256 | $switch_lang[$language]['lang_info'] = $lang_info; |
---|
| 257 | $switch_lang[$language]['lang'] = $lang; |
---|
| 258 | } |
---|
| 259 | else |
---|
| 260 | { |
---|
| 261 | $lang_info = $switch_lang[$language]['lang_info']; |
---|
| 262 | $lang = $switch_lang[$language]['lang']; |
---|
| 263 | } |
---|
[2140] | 264 | |
---|
| 265 | $user['language'] = $language; |
---|
[1904] | 266 | } |
---|
| 267 | } |
---|
| 268 | |
---|
[2121] | 269 | /* |
---|
[1904] | 270 | * Switch back language pushed with switch_lang_to function |
---|
| 271 | * |
---|
| 272 | * @param: none |
---|
| 273 | */ |
---|
| 274 | function switch_lang_back() |
---|
| 275 | { |
---|
| 276 | global $switch_lang, $user, $lang, $lang_info; |
---|
| 277 | |
---|
| 278 | $last_language = array_pop($switch_lang['stack']); |
---|
| 279 | |
---|
| 280 | if (count($switch_lang['stack']) > 0) |
---|
| 281 | { |
---|
| 282 | $language = end($switch_lang['stack']); |
---|
| 283 | } |
---|
| 284 | else |
---|
| 285 | { |
---|
| 286 | $language = $user['language']; |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | if ($last_language != $language) |
---|
| 290 | { |
---|
| 291 | if (!isset($switch_lang['language'][$language])) |
---|
| 292 | { |
---|
| 293 | $lang_info = $switch_lang[$language]['lang_info']; |
---|
| 294 | $lang = $switch_lang[$language]['lang']; |
---|
| 295 | } |
---|
[2140] | 296 | $user['language'] = $language; |
---|
[1904] | 297 | } |
---|
| 298 | } |
---|
[1908] | 299 | |
---|
| 300 | /** |
---|
| 301 | * Returns email of all administrator |
---|
| 302 | * |
---|
| 303 | * @return string |
---|
| 304 | */ |
---|
| 305 | /* |
---|
[2106] | 306 | * send en notification email to all administrators |
---|
[2121] | 307 | * if a administrator is doing action, |
---|
[1908] | 308 | * he's be removed to email list |
---|
| 309 | * |
---|
| 310 | * @param: |
---|
| 311 | * - keyargs_subject: mail subject on l10n_args format |
---|
| 312 | * - keyargs_content: mail content on l10n_args format |
---|
| 313 | * |
---|
| 314 | * @return boolean (Ok or not) |
---|
| 315 | */ |
---|
| 316 | function pwg_mail_notification_admins($keyargs_subject, $keyargs_content) |
---|
| 317 | { |
---|
[2140] | 318 | // Check arguments |
---|
[2278] | 319 | if |
---|
[2140] | 320 | ( |
---|
| 321 | empty($keyargs_subject) or |
---|
| 322 | empty($keyargs_content) |
---|
| 323 | ) |
---|
| 324 | { |
---|
| 325 | return false; |
---|
| 326 | } |
---|
| 327 | |
---|
[1908] | 328 | global $conf, $user; |
---|
| 329 | $return = true; |
---|
| 330 | |
---|
| 331 | $admins = array(); |
---|
| 332 | |
---|
| 333 | $query = ' |
---|
| 334 | select |
---|
| 335 | U.'.$conf['user_fields']['username'].' as username, |
---|
| 336 | U.'.$conf['user_fields']['email'].' as mail_address |
---|
| 337 | from |
---|
| 338 | '.USERS_TABLE.' as U, |
---|
| 339 | '.USER_INFOS_TABLE.' as I |
---|
| 340 | where |
---|
| 341 | I.user_id = U.'.$conf['user_fields']['id'].' and |
---|
| 342 | I.status in (\'webmaster\', \'admin\') and |
---|
| 343 | I.adviser = \'false\' and |
---|
[2106] | 344 | '.$conf['user_fields']['email'].' is not null and |
---|
[1908] | 345 | I.user_id <> '.$user['id'].' |
---|
| 346 | order by |
---|
| 347 | username |
---|
| 348 | '; |
---|
| 349 | |
---|
| 350 | $datas = pwg_query($query); |
---|
| 351 | if (!empty($datas)) |
---|
| 352 | { |
---|
| 353 | while ($admin = mysql_fetch_array($datas)) |
---|
| 354 | { |
---|
| 355 | if (!empty($admin['mail_address'])) |
---|
| 356 | { |
---|
| 357 | array_push($admins, format_email($admin['username'], $admin['mail_address'])); |
---|
| 358 | } |
---|
| 359 | } |
---|
| 360 | } |
---|
| 361 | |
---|
[1914] | 362 | if (count($admins) > 0) |
---|
[2106] | 363 | { |
---|
| 364 | $keyargs_content_admin_info = array |
---|
| 365 | ( |
---|
| 366 | get_l10n_args('Connected user: %s', $user['username']), |
---|
| 367 | get_l10n_args('IP: %s', $_SERVER['REMOTE_ADDR']), |
---|
| 368 | get_l10n_args('Browser: %s', $_SERVER['HTTP_USER_AGENT']) |
---|
| 369 | ); |
---|
[1908] | 370 | |
---|
[1926] | 371 | switch_lang_to(get_default_language()); |
---|
[1908] | 372 | |
---|
[1914] | 373 | $return = pwg_mail |
---|
| 374 | ( |
---|
| 375 | '', |
---|
| 376 | array |
---|
[2106] | 377 | ( |
---|
| 378 | 'Bcc' => $admins, |
---|
[1914] | 379 | 'subject' => '['.$conf['gallery_title'].'] '.l10n_args($keyargs_subject), |
---|
[2121] | 380 | 'content' => |
---|
[2106] | 381 | l10n_args($keyargs_content)."\n\n" |
---|
[1914] | 382 | .l10n_args($keyargs_content_admin_info)."\n", |
---|
| 383 | 'content_format' => 'text/plain' |
---|
| 384 | ) |
---|
| 385 | ) and $return; |
---|
| 386 | |
---|
| 387 | switch_lang_back(); |
---|
| 388 | } |
---|
| 389 | |
---|
[1908] | 390 | return $return; |
---|
| 391 | } |
---|
[2106] | 392 | |
---|
[1904] | 393 | /* |
---|
| 394 | * send en email to user's group |
---|
| 395 | * |
---|
[2106] | 396 | * @param: |
---|
| 397 | * - group_id: mail are sent to group with this Id |
---|
| 398 | * - email_format: mail format |
---|
| 399 | * - keyargs_subject: mail subject on l10n_args format |
---|
[1915] | 400 | * - dirname: short name of directory including template |
---|
| 401 | * - tpl_shortname: short template name without extension |
---|
[2106] | 402 | * - assign_vars: array used to assign_vars to mail template |
---|
| 403 | * - language_selected: send mail only to user with this selected language |
---|
[1908] | 404 | * |
---|
| 405 | * @return boolean (Ok or not) |
---|
| 406 | */ |
---|
[2106] | 407 | function pwg_mail_group( |
---|
[2121] | 408 | $group_id, $email_format, $keyargs_subject, |
---|
[2629] | 409 | $tpl_shortname, |
---|
[1915] | 410 | $assign_vars = array(), $language_selected = '') |
---|
[1904] | 411 | { |
---|
[2140] | 412 | // Check arguments |
---|
[2278] | 413 | if |
---|
[2140] | 414 | ( |
---|
| 415 | empty($group_id) or |
---|
| 416 | empty($email_format) or |
---|
| 417 | empty($keyargs_subject) or |
---|
| 418 | empty($tpl_shortname) |
---|
| 419 | ) |
---|
| 420 | { |
---|
| 421 | return false; |
---|
| 422 | } |
---|
| 423 | |
---|
[1904] | 424 | global $conf; |
---|
[1908] | 425 | $return = true; |
---|
[1904] | 426 | |
---|
| 427 | $query = ' |
---|
| 428 | SELECT |
---|
| 429 | distinct language, template |
---|
[2121] | 430 | FROM |
---|
| 431 | '.USER_GROUP_TABLE.' as ug |
---|
[1904] | 432 | INNER JOIN '.USERS_TABLE.' as u ON '.$conf['user_fields']['id'].' = ug.user_id |
---|
| 433 | INNER JOIN '.USER_INFOS_TABLE.' as ui ON ui.user_id = ug.user_id |
---|
[2121] | 434 | WHERE |
---|
[1904] | 435 | '.$conf['user_fields']['email'].' IS NOT NULL |
---|
| 436 | AND group_id = '.$group_id; |
---|
| 437 | |
---|
| 438 | if (!empty($language_selected)) |
---|
| 439 | { |
---|
| 440 | $query .= ' |
---|
| 441 | AND language = \''.$language_selected.'\''; |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | $query .= ' |
---|
| 445 | ;'; |
---|
| 446 | |
---|
[2106] | 447 | $result = pwg_query($query); |
---|
[1904] | 448 | |
---|
[2106] | 449 | if (mysql_num_rows($result) > 0) |
---|
| 450 | { |
---|
| 451 | $list = array(); |
---|
| 452 | while ($row = mysql_fetch_array($result)) |
---|
| 453 | { |
---|
| 454 | $row['template_theme'] = $row['template']; |
---|
| 455 | list($row['template'], $row['theme']) = explode('/', $row['template_theme']); |
---|
| 456 | $list[] = $row; |
---|
| 457 | } |
---|
| 458 | |
---|
[2129] | 459 | foreach ($list as $elem) |
---|
| 460 | { |
---|
| 461 | $query = ' |
---|
[1904] | 462 | SELECT |
---|
| 463 | u.'.$conf['user_fields']['username'].' as username, |
---|
| 464 | u.'.$conf['user_fields']['email'].' as mail_address |
---|
[2121] | 465 | FROM |
---|
| 466 | '.USER_GROUP_TABLE.' as ug |
---|
[1904] | 467 | INNER JOIN '.USERS_TABLE.' as u ON '.$conf['user_fields']['id'].' = ug.user_id |
---|
| 468 | INNER JOIN '.USER_INFOS_TABLE.' as ui ON ui.user_id = ug.user_id |
---|
[2121] | 469 | WHERE |
---|
[1904] | 470 | '.$conf['user_fields']['email'].' IS NOT NULL |
---|
| 471 | AND group_id = '.$group_id.' |
---|
[2106] | 472 | AND language = \''.$elem['language'].'\' |
---|
| 473 | AND template = \''.$elem['template_theme'].'\' |
---|
[1904] | 474 | ;'; |
---|
| 475 | |
---|
[2129] | 476 | $result = pwg_query($query); |
---|
[1904] | 477 | |
---|
[2129] | 478 | if (mysql_num_rows($result) > 0) |
---|
[1904] | 479 | { |
---|
[2129] | 480 | $Bcc = array(); |
---|
| 481 | while ($row = mysql_fetch_array($result)) |
---|
[1904] | 482 | { |
---|
[2129] | 483 | if (!empty($row['mail_address'])) |
---|
| 484 | { |
---|
| 485 | array_push($Bcc, format_email($row['username'], $row['mail_address'])); |
---|
| 486 | } |
---|
[1904] | 487 | } |
---|
| 488 | |
---|
[2129] | 489 | if (count($Bcc) > 0) |
---|
| 490 | { |
---|
| 491 | switch_lang_to($elem['language']); |
---|
[1904] | 492 | |
---|
[2129] | 493 | $mail_template = get_mail_template($email_format, $elem); |
---|
[2629] | 494 | $mail_template->set_filename($tpl_shortname, $tpl_shortname.'.tpl'); |
---|
[1904] | 495 | |
---|
[2278] | 496 | $mail_template->assign( |
---|
[2140] | 497 | trigger_event('mail_group_assign_vars', $assign_vars)); |
---|
| 498 | |
---|
[2129] | 499 | $return = pwg_mail |
---|
[2106] | 500 | ( |
---|
[2129] | 501 | '', |
---|
| 502 | array |
---|
| 503 | ( |
---|
| 504 | 'Bcc' => $Bcc, |
---|
| 505 | 'subject' => l10n_args($keyargs_subject), |
---|
| 506 | 'email_format' => $email_format, |
---|
| 507 | 'content' => $mail_template->parse($tpl_shortname, true), |
---|
| 508 | 'content_format' => $email_format, |
---|
| 509 | 'template' => $elem['template'], |
---|
| 510 | 'theme' => $elem['theme'] |
---|
| 511 | ) |
---|
| 512 | ) and $return; |
---|
[1904] | 513 | |
---|
[2129] | 514 | switch_lang_back(); |
---|
| 515 | } |
---|
[1914] | 516 | } |
---|
[1904] | 517 | } |
---|
| 518 | } |
---|
[1908] | 519 | |
---|
| 520 | return $return; |
---|
[1904] | 521 | } |
---|
| 522 | |
---|
| 523 | /* |
---|
[2339] | 524 | * sends an email, using Piwigo specific informations |
---|
[1809] | 525 | * |
---|
| 526 | * @param: |
---|
[2284] | 527 | * - to: receiver(s) of the mail (list separated by comma). |
---|
[1809] | 528 | * - args: function params of mail function: |
---|
[2106] | 529 | * o from: sender [default value webmaster email] |
---|
| 530 | * o Cc: array of carbon copy receivers of the mail. [default value empty] |
---|
| 531 | * o Bcc: array of blind carbon copy receivers of the mail. [default value empty] |
---|
[2339] | 532 | * o subject [default value 'Piwigo'] |
---|
[1809] | 533 | * o content: content of mail [default value ''] |
---|
| 534 | * o content_format: format of mail content [default value 'text/plain'] |
---|
[2106] | 535 | * o email_format: global mail format [default value $conf_mail['default_email_format']] |
---|
| 536 | * o template: template to use [default get_default_template()] |
---|
[1926] | 537 | * o theme: template to use [default get_default_template()] |
---|
[1908] | 538 | * |
---|
| 539 | * @return boolean (Ok or not) |
---|
[2106] | 540 | */ |
---|
[1809] | 541 | function pwg_mail($to, $args = array()) |
---|
[1019] | 542 | { |
---|
[1809] | 543 | global $conf, $conf_mail, $lang_info, $page; |
---|
[2106] | 544 | |
---|
| 545 | if (empty($to) and empty($args['Cc']) and empty($args['Bcc'])) |
---|
| 546 | { |
---|
| 547 | return true; |
---|
| 548 | } |
---|
[2121] | 549 | |
---|
[1021] | 550 | if (!isset($conf_mail)) |
---|
| 551 | { |
---|
| 552 | $conf_mail = get_mail_configuration(); |
---|
| 553 | } |
---|
[2106] | 554 | |
---|
| 555 | if (empty($args['email_format'])) |
---|
| 556 | { |
---|
| 557 | $args['email_format'] = $conf_mail['default_email_format']; |
---|
| 558 | } |
---|
| 559 | |
---|
[1676] | 560 | // Compute root_path in order have complete path |
---|
[1809] | 561 | if ($args['email_format'] == 'text/html') |
---|
[1676] | 562 | { |
---|
[2106] | 563 | set_make_full_url(); |
---|
[1676] | 564 | } |
---|
[2106] | 565 | |
---|
[1809] | 566 | if (empty($args['from'])) |
---|
[1021] | 567 | { |
---|
[1809] | 568 | $args['from'] = $conf_mail['formated_email_webmaster']; |
---|
[1021] | 569 | } |
---|
| 570 | else |
---|
| 571 | { |
---|
[1809] | 572 | $args['from'] = format_email('', $args['from']); |
---|
[1021] | 573 | } |
---|
| 574 | |
---|
[1809] | 575 | if (empty($args['subject'])) |
---|
| 576 | { |
---|
[2339] | 577 | $args['subject'] = 'Piwigo'; |
---|
[1809] | 578 | } |
---|
[2106] | 579 | // Spring cleaning |
---|
| 580 | $cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject'])); |
---|
| 581 | // Ascii convertion |
---|
[2121] | 582 | $cvt_subject = encode_mime_header($cvt_subject); |
---|
[1809] | 583 | |
---|
| 584 | if (!isset($args['content'])) |
---|
| 585 | { |
---|
| 586 | $args['content'] = ''; |
---|
| 587 | } |
---|
| 588 | |
---|
| 589 | if (empty($args['content_format'])) |
---|
| 590 | { |
---|
| 591 | $args['content_format'] = 'text/plain'; |
---|
| 592 | } |
---|
| 593 | |
---|
[2106] | 594 | if ($conf_mail['send_bcc_mail_webmaster']) |
---|
| 595 | { |
---|
| 596 | $args['Bcc'][] = $conf_mail['formated_email_webmaster']; |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | if (($args['content_format'] == 'text/html') and ($args['email_format'] == 'text/plain')) |
---|
| 600 | { |
---|
| 601 | // Todo find function to convert html text to plain text |
---|
| 602 | return false; |
---|
| 603 | } |
---|
| 604 | |
---|
| 605 | $args = array_merge($args, get_array_template_theme($args)); |
---|
| 606 | |
---|
[1809] | 607 | $headers = 'From: '.$args['from']."\n"; |
---|
[2106] | 608 | $headers.= 'Reply-To: '.$args['from']."\n"; |
---|
| 609 | if (empty($to)) |
---|
| 610 | { |
---|
| 611 | $headers.= 'To: undisclosed-recipients: ;'."\n"; |
---|
| 612 | } |
---|
[2284] | 613 | else |
---|
| 614 | { |
---|
| 615 | $headers.= 'To: '.$to."\n"; |
---|
| 616 | } |
---|
[1818] | 617 | |
---|
[2106] | 618 | if (!empty($args['Cc'])) |
---|
| 619 | { |
---|
| 620 | $headers.= 'Cc: '.implode(',', $args['Cc'])."\n"; |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | if (!empty($args['Bcc'])) |
---|
| 624 | { |
---|
| 625 | $headers.= 'Bcc: '.implode(',', $args['Bcc'])."\n"; |
---|
| 626 | } |
---|
| 627 | |
---|
[1809] | 628 | $headers.= 'Content-Type: multipart/alternative;'."\n"; |
---|
| 629 | $headers.= ' boundary="---='.$conf_mail['boundary_key'].'";'."\n"; |
---|
[2106] | 630 | $headers.= ' reply-type=original'."\n"; |
---|
| 631 | $headers.= 'MIME-Version: 1.0'."\n"; |
---|
| 632 | $headers.= 'X-Mailer: Piwigo Mailer'."\n"; |
---|
[1532] | 633 | |
---|
[2106] | 634 | $content = ''; |
---|
| 635 | |
---|
[2129] | 636 | // key compose of indexes witch allow ti cache mail data |
---|
| 637 | $cache_key = $args['email_format'].'-'.$lang_info['code'].'-'.$args['template'].'-'.$args['theme']; |
---|
| 638 | |
---|
| 639 | if (!isset($conf_mail[$cache_key])) |
---|
[2106] | 640 | { |
---|
| 641 | if (!isset($mail_template)) |
---|
| 642 | { |
---|
[1809] | 643 | $mail_template = get_mail_template($args['email_format']); |
---|
[2106] | 644 | } |
---|
| 645 | |
---|
| 646 | $mail_template->set_filename('mail_header', 'header.tpl'); |
---|
| 647 | $mail_template->set_filename('mail_footer', 'footer.tpl'); |
---|
| 648 | |
---|
[2278] | 649 | $mail_template->assign( |
---|
[2106] | 650 | array( |
---|
| 651 | //Header |
---|
[1809] | 652 | 'BOUNDARY_KEY' => $conf_mail['boundary_key'], |
---|
| 653 | 'CONTENT_TYPE' => $args['email_format'], |
---|
[2126] | 654 | 'CONTENT_ENCODING' => get_pwg_charset(), |
---|
[2121] | 655 | |
---|
[2106] | 656 | // Footer |
---|
| 657 | 'GALLERY_URL' => |
---|
| 658 | isset($page['gallery_url']) ? |
---|
| 659 | $page['gallery_url'] : $conf['gallery_url'], |
---|
| 660 | 'GALLERY_TITLE' => |
---|
| 661 | isset($page['gallery_title']) ? |
---|
| 662 | $page['gallery_title'] : $conf['gallery_title'], |
---|
| 663 | 'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', |
---|
| 664 | 'PHPWG_URL' => PHPWG_URL, |
---|
| 665 | |
---|
| 666 | 'TITLE_MAIL' => urlencode(l10n('title_send_mail')), |
---|
| 667 | 'MAIL' => get_webmaster_mail_address() |
---|
| 668 | )); |
---|
| 669 | |
---|
| 670 | if ($args['email_format'] == 'text/html') |
---|
| 671 | { |
---|
[2278] | 672 | if (is_file($mail_template->get_template_dir().'/global-mail-css.tpl')) |
---|
[2106] | 673 | { |
---|
[2278] | 674 | $mail_template->set_filename('css', 'global-mail-css.tpl'); |
---|
| 675 | $mail_template->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css'); |
---|
[2106] | 676 | } |
---|
| 677 | |
---|
[2278] | 678 | $root_abs_path = dirname(dirname(__FILE__)); |
---|
| 679 | |
---|
| 680 | $file = $root_abs_path.'/template/'.$args['template'].'/theme/'.$args['theme'].'/mail-css.tpl'; |
---|
| 681 | if (is_file($file)) |
---|
[2106] | 682 | { |
---|
[2278] | 683 | $mail_template->set_filename('css', $file); |
---|
| 684 | $mail_template->assign_var_from_handle('MAIL_CSS', 'css'); |
---|
[2106] | 685 | } |
---|
| 686 | |
---|
[2278] | 687 | $file = $root_abs_path.'/template-common/local-mail-css.tpl'; |
---|
| 688 | if (is_file($file)) |
---|
[2106] | 689 | { |
---|
[2278] | 690 | $mail_template->set_filename('css', $file); |
---|
| 691 | $mail_template->assign_var_from_handle('LOCAL_MAIL_CSS', 'css'); |
---|
[2106] | 692 | } |
---|
| 693 | } |
---|
| 694 | |
---|
| 695 | // what are displayed on the header of each mail ? |
---|
[2129] | 696 | $conf_mail[$cache_key]['header'] = |
---|
| 697 | $mail_template->parse('mail_header', true); |
---|
[1784] | 698 | |
---|
[2106] | 699 | // what are displayed on the footer of each mail ? |
---|
[2129] | 700 | $conf_mail[$cache_key]['footer'] = |
---|
| 701 | $mail_template->parse('mail_footer', true); |
---|
[2106] | 702 | } |
---|
[1809] | 703 | |
---|
| 704 | // Header |
---|
[2129] | 705 | $content.= $conf_mail[$cache_key]['header']; |
---|
[1019] | 706 | |
---|
[1809] | 707 | // Content |
---|
[2106] | 708 | if (($args['content_format'] == 'text/plain') and ($args['email_format'] == 'text/html')) |
---|
| 709 | { |
---|
[1901] | 710 | $content.= '<p>'. |
---|
| 711 | nl2br( |
---|
| 712 | preg_replace("/(http:\/\/)([^\s,]*)/i", |
---|
| 713 | "<a href='$1$2'>$1$2</a>", |
---|
[2168] | 714 | htmlspecialchars($args['content']))). |
---|
[1901] | 715 | '</p>'; |
---|
[2106] | 716 | } |
---|
| 717 | else |
---|
| 718 | { |
---|
| 719 | $content.= $args['content']; |
---|
| 720 | } |
---|
[1809] | 721 | |
---|
[2106] | 722 | // Footer |
---|
[2129] | 723 | $content.= $conf_mail[$cache_key]['footer']; |
---|
[1809] | 724 | |
---|
| 725 | // Close boundary |
---|
| 726 | $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n"; |
---|
| 727 | |
---|
[1676] | 728 | // Undo Compute root_path in order have complete path |
---|
[1809] | 729 | if ($args['email_format'] == 'text/html') |
---|
[2106] | 730 | { |
---|
[1676] | 731 | unset_make_full_url(); |
---|
| 732 | } |
---|
[1642] | 733 | |
---|
[2140] | 734 | return |
---|
| 735 | trigger_event('send_mail', |
---|
| 736 | false, /* Result */ |
---|
[2284] | 737 | trigger_event('send_mail_to', get_strict_email_list($to)), |
---|
[2140] | 738 | trigger_event('send_mail_subject', $cvt_subject), |
---|
| 739 | trigger_event('send_mail_content', $content), |
---|
| 740 | trigger_event('send_mail_headers', $headers), |
---|
| 741 | $args |
---|
| 742 | ); |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | /* |
---|
| 746 | * pwg sendmail |
---|
| 747 | * |
---|
| 748 | * @param: |
---|
| 749 | * - result of other sendmail |
---|
| 750 | * - to: Receiver or receiver(s) of the mail. |
---|
[2339] | 751 | * - subject [default value 'Piwigo'] |
---|
[2140] | 752 | * - content: content of mail |
---|
| 753 | * - headers: headers of mail |
---|
| 754 | * |
---|
| 755 | * @return boolean (Ok or not) |
---|
| 756 | */ |
---|
| 757 | function pwg_send_mail($result, $to, $subject, $content, $headers) |
---|
| 758 | { |
---|
[2280] | 759 | if (!$result) |
---|
| 760 | { |
---|
[2140] | 761 | global $conf_mail; |
---|
| 762 | |
---|
| 763 | if ($conf_mail['use_smtp']) |
---|
| 764 | { |
---|
| 765 | include_once( PHPWG_ROOT_PATH.'include/class_smtp_mail.inc.php' ); |
---|
| 766 | $smtp_mail = new smtp_mail( |
---|
| 767 | $conf_mail['smtp_host'], $conf_mail['smtp_user'], $conf_mail['smtp_password'], |
---|
| 768 | $conf_mail['email_webmaster']); |
---|
| 769 | return $smtp_mail->mail($to, $subject, $content, $headers); |
---|
| 770 | } |
---|
| 771 | else |
---|
| 772 | { |
---|
| 773 | if ($conf_mail['mail_options']) |
---|
| 774 | { |
---|
| 775 | $options = '-f '.$conf_mail['email_webmaster']; |
---|
| 776 | return mail($to, $subject, $content, $headers, $options); |
---|
| 777 | } |
---|
| 778 | else |
---|
| 779 | { |
---|
| 780 | return mail($to, $subject, $content, $headers); |
---|
| 781 | } |
---|
| 782 | } |
---|
[2280] | 783 | } |
---|
| 784 | else |
---|
| 785 | { |
---|
| 786 | return $result; |
---|
| 787 | } |
---|
[2140] | 788 | } |
---|
| 789 | |
---|
[2278] | 790 | /*Testing block*/ |
---|
| 791 | /*function pwg_send_mail_test($result, $to, $subject, $content, $headers, $args) |
---|
[2140] | 792 | { |
---|
[2278] | 793 | global $conf, $user, $lang_info; |
---|
| 794 | $dir = $conf['local_data_dir'].'/tmp'; |
---|
[2497] | 795 | if ( mkgetdir( $dir, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR) ) |
---|
[1784] | 796 | { |
---|
[2497] | 797 | $filename = $dir.'/mail.'.$user['username'].'.'.$lang_info['code'].'.'.$args['template'].'.'.$args['theme']; |
---|
| 798 | if ($args['content_format'] == 'text/plain') |
---|
| 799 | { |
---|
| 800 | $filename .= '.txt'; |
---|
| 801 | } |
---|
| 802 | else |
---|
| 803 | { |
---|
| 804 | $filename .= '.html'; |
---|
| 805 | } |
---|
| 806 | $file = fopen($filename, 'w+'); |
---|
| 807 | fwrite($file, $to ."\n"); |
---|
| 808 | fwrite($file, $subject ."\n"); |
---|
| 809 | fwrite($file, $headers); |
---|
| 810 | fwrite($file, $content); |
---|
| 811 | fclose($file); |
---|
[1784] | 812 | } |
---|
[2278] | 813 | return $result; |
---|
[1021] | 814 | } |
---|
[2278] | 815 | add_event_handler('send_mail', 'pwg_send_mail_test', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 6);*/ |
---|
[1105] | 816 | |
---|
[2140] | 817 | |
---|
| 818 | add_event_handler('send_mail', 'pwg_send_mail', EVENT_HANDLER_PRIORITY_NEUTRAL, 5); |
---|
| 819 | trigger_action('functions_mail_included'); |
---|
| 820 | |
---|
[1321] | 821 | ?> |
---|