Changeset 25357 for trunk/include
- Timestamp:
- Nov 6, 2013, 4:43:41 PM (11 years ago)
- Location:
- trunk/include
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/config_default.inc.php
r25344 r25357 286 286 287 287 // set true to allow text/html emails 288 $conf[' allow_html_email'] = true;288 $conf['mail_allow_html'] = true; 289 289 290 290 // 'clear' or 'dark' -
trunk/include/functions_comment.inc.php
r25018 r25357 233 233 $comment_url = get_absolute_root_url().'comments.php?comment_id='.$comm['id']; 234 234 235 $keyargs_content = array 236 ( 237 get_l10n_args('Author: %s', stripslashes($comm['author']) ), 238 get_l10n_args('Email: %s', stripslashes($comm['email']) ), 239 get_l10n_args('Comment: %s', stripslashes($comm['content']) ), 240 get_l10n_args('', ''), 241 get_l10n_args('Manage this user comment: %s', $comment_url) 235 $content = array( 236 l10n('Author: %s', stripslashes($comm['author']) ), 237 l10n('Email: %s', stripslashes($comm['email']) ), 238 l10n('Comment: %s', stripslashes($comm['content']) ), 239 '', 240 l10n('Manage this user comment: %s', $comment_url), 242 241 ); 243 242 244 243 if ('moderate' == $comment_action) 245 244 { 246 $keyargs_content[] = get_l10n_args('', ''); 247 $keyargs_content[] = get_l10n_args('(!) This comment requires validation', ''); 245 $content[] = l10n('(!) This comment requires validation'); 248 246 } 249 247 250 pwg_mail_notification_admins 251 ( 252 get_l10n_args('Comment by %s', stripslashes($comm['author']) ), 253 $keyargs_content 248 pwg_mail_notification_admins( 249 l10n('Comment by %s', stripslashes($comm['author']) ), 250 implode("\n", $content) 254 251 ); 255 252 } … … 377 374 $comment_url = get_absolute_root_url().'comments.php?comment_id='.$comment['comment_id']; 378 375 379 $keyargs_content = array 380 ( 381 get_l10n_args('Author: %s', stripslashes($GLOBALS['user']['username']) ), 382 get_l10n_args('Comment: %s', stripslashes($comment['content']) ), 383 get_l10n_args('', ''), 384 get_l10n_args('Manage this user comment: %s', $comment_url), 385 get_l10n_args('', ''), 386 get_l10n_args('(!) This comment requires validation', ''), 376 $content = array( 377 l10n('Author: %s', stripslashes($GLOBALS['user']['username']) ), 378 l10n('Comment: %s', stripslashes($comment['content']) ), 379 '', 380 l10n('Manage this user comment: %s', $comment_url), 381 l10n('(!) This comment requires validation'), 387 382 ); 388 383 389 pwg_mail_notification_admins 390 ( 391 get_l10n_args('Comment by %s', stripslashes($GLOBALS['user']['username']) ), 392 $keyargs_content 384 pwg_mail_notification_admins( 385 l10n('Comment by %s', stripslashes($GLOBALS['user']['username']) ), 386 implode("\n", $content) 393 387 ); 394 388 } … … 417 411 include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); 418 412 419 $keyargs_content = array(); 420 $keyargs_content[] = get_l10n_args('Author: %s', $comment['author']); 413 $content = array( 414 l10n('Author: %s', $comment['author']), 415 ); 416 421 417 if ($action=='delete') 422 418 { 423 $keyargs_content[] = get_l10n_args('This author removed the comment with id %d', 424 $comment['comment_id'] 425 ); 426 } 427 else 428 { 429 $keyargs_content[] = get_l10n_args('This author modified following comment:', ''); 430 $keyargs_content[] = get_l10n_args('Comment: %s', $comment['content']); 431 } 432 433 pwg_mail_notification_admins(get_l10n_args('Comment by %s', 434 $comment['author']), 435 $keyargs_content 436 ); 419 $content[] = l10n('This author removed the comment with id %d', $comment['comment_id']); 420 } 421 else 422 { 423 $content[] = l10n('This author modified following comment:'); 424 $content[] = l10n('Comment: %s', $comment['content']); 425 } 426 427 pwg_mail_notification_admins( 428 l10n('Comment by %s', $comment['author']), 429 implode("\n", $content) 430 ); 437 431 } 438 432 -
trunk/include/functions_mail.inc.php
r25344 r25357 48 48 * Returns an array of mail configuration parameters : 49 49 * - send_bcc_mail_webmaster 50 * - allow_html_email50 * - mail_allow_html 51 51 * - use_smtp 52 52 * - smtp_host … … 65 65 $conf_mail = array( 66 66 'send_bcc_mail_webmaster' => $conf['send_bcc_mail_webmaster'], 67 ' allow_html_email' => $conf['allow_html_email'],67 'mail_allow_html' => $conf['mail_allow_html'], 68 68 'mail_theme' => $conf['mail_theme'], 69 69 'use_smtp' => !empty($conf['smtp_host']), … … 254 254 255 255 /** 256 * Returns email of all administrator 257 * 258 * @return string 259 */ 260 /* 261 * send en notification email to all administrators 262 * if a administrator is doing action, 263 * he's be removed to email list 264 * 265 * @param: 266 * - keyargs_subject: mail subject on l10n_args format 267 * - keyargs_content: mail content on l10n_args format 268 * - send_technical_details: send user IP and browser 269 * 270 * @return boolean (Ok or not) 271 */ 272 function pwg_mail_notification_admins($keyargs_subject, $keyargs_content, $send_technical_details=true) 273 { 256 * Send a notification email to all administrators 257 * current user (if admin) is not notified 258 * @param string $subject 259 * @param string $content 260 * @param boolean $send_technical_details - send user IP and browser 261 * @return boolean 262 */ 263 function pwg_mail_notification_admins($subject, $content, $send_technical_details=true) 264 { 265 if (empty($subject) or empty($content)) 266 { 267 return false; 268 } 269 270 // for backward compatibility < 2.6 271 if (is_array($subject)) 272 { 273 $subject = l10n_args($subject); 274 } 275 if (is_array($content)) 276 { 277 $content = l10n_args($content); 278 } 279 274 280 global $conf, $user; 275 281 276 // Check arguments 277 if (empty($keyargs_subject) or empty($keyargs_content)) 282 $tpl_vars = array(); 283 if ($send_technical_details) 284 { 285 $tpl_vars['TECHNICAL'] = 286 l10n('Connected user: %s', stripslashes($user['username'])) ."\n". 287 l10n('IP: %s', $_SERVER['REMOTE_ADDR']) . "\n" . 288 l10n('Browser: %s', $_SERVER['HTTP_USER_AGENT']); 289 } 290 291 return pwg_mail_admins( 292 array( 293 'subject' => '['. $conf['gallery_title'] .'] '. $subject, 294 'mail_title' => $conf['gallery_title'], 295 'mail_subtitle' => $subject, 296 'content' => $content, 297 'content_format' => 'text/plain', 298 ), 299 array( 300 'filename' => 'notification_admin', 301 'assign' => $tpl_vars, 302 ) 303 ); 304 } 305 306 /** 307 * Send a email to all administrators 308 * current user (if admin) is excluded 309 * @see pwg_mail() 310 * 311 * @param array $args - as in pwg_mail() 312 * @param array $tpl - as in pwg_mail() 313 * @return boolean 314 */ 315 function pwg_mail_admins($args=array(), $tpl=array()) 316 { 317 if (empty($args['content']) and empty($tpl)) 278 318 { 279 319 return false; 280 320 } 281 321 322 global $conf, $user; 282 323 $return = true; 283 324 284 $admins = array(); 285 325 // get admins (except ourself) 286 326 $query = ' 287 327 SELECT 288 u.'.$conf['user_fields']['username'].' AS username,289 u.'.$conf['user_fields']['email'].' AS mail_address328 u.'.$conf['user_fields']['username'].' AS name, 329 u.'.$conf['user_fields']['email'].' AS email 290 330 FROM '.USERS_TABLE.' AS u 291 JOIN '.USER_INFOS_TABLE.' AS i ON i.user_id = u.'.$conf['user_fields']['id'].' 331 JOIN '.USER_INFOS_TABLE.' AS i 332 ON i.user_id = u.'.$conf['user_fields']['id'].' 292 333 WHERE i.status in (\'webmaster\', \'admin\') 293 AND '.$conf['user_fields']['email'].' IS NOT NULL334 AND u.'.$conf['user_fields']['email'].' IS NOT NULL 294 335 AND i.user_id <> '.$user['id'].' 295 336 ORDER BY username 296 337 ;'; 297 298 $datas = pwg_query($query); 299 if (!empty($datas)) 300 { 301 while ($admin = pwg_db_fetch_assoc($datas)) 302 { 303 if (!empty($admin['mail_address'])) 304 { 305 $admins[] = format_email($admin['username'], $admin['mail_address']); 306 } 307 } 308 } 309 310 if (count($admins) > 0) 311 { 312 switch_lang_to(get_default_language()); 313 314 $content = l10n_args($keyargs_content)."\n"; 315 if ($send_technical_details) 316 { 317 $keyargs_content_admin_info = array( 318 get_l10n_args('Connected user: %s', stripslashes($user['username'])), 319 get_l10n_args('IP: %s', $_SERVER['REMOTE_ADDR']), 320 get_l10n_args('Browser: %s', $_SERVER['HTTP_USER_AGENT']) 321 ); 322 323 $content.= "\n".l10n_args($keyargs_content_admin_info)."\n"; 324 } 325 326 $return = pwg_mail( 327 implode(', ', $admins), 328 array( 329 'subject' => '['.$conf['gallery_title'].'] '.l10n_args($keyargs_subject), 330 'content' => $content, 331 'content_format' => 'text/plain', 332 'email_format' => 'text/html', 333 ) 334 ); 335 336 switch_lang_back(); 337 } 338 $admins = array_from_query($query); 339 340 if (empty($admins)) 341 { 342 return $return; 343 } 344 345 switch_lang_to(get_default_language()); 346 347 $return = pwg_mail($admins, $args, $tpl); 348 349 switch_lang_back(); 338 350 339 351 return $return; 340 352 } 341 353 342 /* 343 * send en email to user's group 354 /** 355 * Send an email to a group 356 * @see pwg_mail() 344 357 * 345 * @param: 346 * - group_id: mail are sent to group with this Id 347 * - email_format: mail format 348 * - keyargs_subject: mail subject on l10n_args format 349 * - tpl_shortname: short template name without extension 350 * - assign_vars: array used to assign_vars to mail template 351 * - language_selected: send mail only to user with this selected language 352 * 353 * @return boolean (Ok or not) 354 */ 355 function pwg_mail_group( 356 $group_id, $email_format, $keyargs_subject, 357 $tpl_shortname, 358 $assign_vars = array(), $language_selected = '') 359 { 360 // Check arguments 361 if 362 ( 363 empty($group_id) or 364 empty($email_format) or 365 empty($keyargs_subject) or 366 empty($tpl_shortname) 367 ) 358 * @param int $group_id 359 * @param array $args - as in pwg_mail() 360 * @option string language_selected - filters users of the group by language 361 * @param array $tpl - as in pwg_mail() 362 * @return boolean 363 */ 364 function pwg_mail_group($group_id, $args=array(), $tpl=array()) 365 { 366 if (empty($group_id) or ( empty($args['content']) and empty($tpl) )) 368 367 { 369 368 return false; … … 373 372 $return = true; 374 373 374 // get distinct languages of targeted users 375 375 $query = ' 376 SELECT 377 distinct language, theme 378 FROM 379 '.USER_GROUP_TABLE.' as ug 380 INNER JOIN '.USERS_TABLE.' as u ON '.$conf['user_fields']['id'].' = ug.user_id 381 INNER JOIN '.USER_INFOS_TABLE.' as ui ON ui.user_id = ug.user_id 382 WHERE 383 '.$conf['user_fields']['email'].' IS NOT NULL 384 AND group_id = '.$group_id; 385 386 if (!empty($language_selected)) 376 SELECT DISTINCT language 377 FROM '.USER_GROUP_TABLE.' AS ug 378 INNER JOIN '.USERS_TABLE.' AS u 379 ON '.$conf['user_fields']['id'].' = ug.user_id 380 INNER JOIN '.USER_INFOS_TABLE.' AS ui 381 ON ui.user_id = ug.user_id 382 WHERE group_id = '.$group_id.' 383 AND '.$conf['user_fields']['email'].' <> ""'; 384 if (!empty($args['language_selected'])) 387 385 { 388 386 $query .= ' 389 AND language = \''.$ language_selected.'\'';387 AND language = \''.$args['language_selected'].'\''; 390 388 } 391 389 392 390 $query .= ' 393 391 ;'; 394 395 $result = pwg_query($query); 396 397 if (pwg_db_num_rows($result) > 0) 398 { 399 $list = array(); 400 while ($row = pwg_db_fetch_assoc($result)) 401 { 402 $list[] = $row; 403 } 404 405 foreach ($list as $elem) 406 { 407 $query = ' 392 $languages = array_from_query($query, 'language'); 393 394 if (empty($languages)) 395 { 396 return $return; 397 } 398 399 foreach ($languages as $language) 400 { 401 // get subset of users in this group for a specific language 402 $query = ' 408 403 SELECT 409 u.'.$conf['user_fields']['username'].' as username, 410 u.'.$conf['user_fields']['email'].' as mail_address 411 FROM 412 '.USER_GROUP_TABLE.' as ug 413 INNER JOIN '.USERS_TABLE.' as u ON '.$conf['user_fields']['id'].' = ug.user_id 414 INNER JOIN '.USER_INFOS_TABLE.' as ui ON ui.user_id = ug.user_id 415 WHERE 416 '.$conf['user_fields']['email'].' IS NOT NULL 417 AND group_id = '.$group_id.' 418 AND language = \''.$elem['language'].'\' 419 AND theme = \''.$elem['theme'].'\' 404 u.'.$conf['user_fields']['username'].' AS name, 405 u.'.$conf['user_fields']['email'].' AS email 406 FROM '.USER_GROUP_TABLE.' AS ug 407 INNER JOIN '.USERS_TABLE.' AS u 408 ON '.$conf['user_fields']['id'].' = ug.user_id 409 INNER JOIN '.USER_INFOS_TABLE.' AS ui 410 ON ui.user_id = ug.user_id 411 WHERE group_id = '.$group_id.' 412 AND '.$conf['user_fields']['email'].' <> "" 413 AND language = \''.$language.'\' 420 414 ;'; 421 422 $result = pwg_query($query); 423 424 if (pwg_db_num_rows($result) > 0) 425 { 426 $Bcc = array(); 427 while ($row = pwg_db_fetch_assoc($result)) 428 { 429 if (!empty($row['mail_address'])) 430 { 431 $Bcc[] = format_email(stripslashes($row['username']), $row['mail_address']); 432 } 433 } 434 435 if (count($Bcc) > 0) 436 { 437 switch_lang_to($elem['language']); 438 439 $mail_template = get_mail_template($email_format, $elem['theme']); 440 $mail_template->set_filename($tpl_shortname, $tpl_shortname.'.tpl'); 441 442 $mail_template->assign( 443 trigger_event('mail_group_assign_vars', $assign_vars)); 444 445 $return = pwg_mail 446 ( 447 '', 448 array 449 ( 450 'Bcc' => $Bcc, 451 'subject' => l10n_args($keyargs_subject), 452 'email_format' => $email_format, 453 'content' => $mail_template->parse($tpl_shortname, true), 454 'content_format' => $email_format, 455 'theme' => $elem['theme'] 456 ) 457 ) and $return; 458 459 switch_lang_back(); 460 } 461 } 462 } 415 $users = array_from_query($query); 416 417 if (empty($users)) 418 { 419 continue; 420 } 421 422 switch_lang_to($language); 423 424 $return&= pwg_mail(null, 425 array_merge( 426 $args, 427 array('Bcc' => $users) 428 ), 429 $tpl 430 ); 431 432 switch_lang_back(); 463 433 } 464 434 … … 474 444 * o Cc: array of carbon copy receivers of the mail. [default value empty] 475 445 * o Bcc: array of blind carbon copy receivers of the mail. [default value empty] 476 * o subject 477 * o content: content of mail 478 * o content_format: format of mail content 479 * o email_format: global mail format 446 * o subject [default value 'Piwigo'] 447 * o content: content of mail [default value ''] 448 * o content_format: format of mail content [default value 'text/plain'] 449 * o email_format: global mail format [default value $conf_mail['default_email_format']] 480 450 * o theme: theme to use [default value $conf_mail['mail_theme']] 481 451 * o mail_title: main title of the mail [default value $conf['gallery_title']] 482 452 * o mail_subtitle: subtitle of the mail [default value subject] 453 * @param array $tpl - use these options to define a custom content template file 454 * o filename 455 * o dirname (optional) 456 * o assign (optional) 483 457 * 484 458 * @return boolean 485 459 */ 486 function pwg_mail($to, $args =array())460 function pwg_mail($to, $args=array(), $tpl=array()) 487 461 { 488 462 global $conf, $conf_mail, $lang_info, $page; … … 572 546 $args['content'] = ''; 573 547 } 548 549 // try to decompose subject like "[....] ...." 550 if (!isset($args['mail_title']) and !isset($args['mail_subtitle'])) 551 { 552 if (preg_match('#^\[(.*)\](.*)$#', $args['subject'], $matches)) 553 { 554 $args['mail_title'] = $matches[1]; 555 $args['mail_subtitle'] = $matches[2]; 556 } 557 } 574 558 if (!isset($args['mail_title'])) 575 559 { … … 588 572 589 573 $content_type_list = array(); 590 if ($conf_mail[' allow_html_email'] and @$args['email_format'] != 'text/plain')574 if ($conf_mail['mail_allow_html'] and @$args['email_format'] != 'text/plain') 591 575 { 592 576 $content_type_list[] = 'text/html'; … … 599 583 // key compose of indexes witch allow to cache mail data 600 584 $cache_key = $content_type.'-'.$lang_info['code']; 601 $cache_key.= '-'.crc32(@$args['mail_title'] . @$args['mail_subtitle']); 585 $cache_key.= '-'.crc32(@$args['mail_title'] . @$args['mail_subtitle']); // TODO: find a way to not cache by mail_title 602 586 603 587 if (!isset($conf_mail[$cache_key])) … … 609 593 trigger_action('before_parse_mail_template', $cache_key, $content_type); 610 594 } 611 612 $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl'); 613 $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl'); 614 615 $conf_mail[$cache_key]['theme']->assign( 595 $template = &$conf_mail[$cache_key]['theme']; 596 597 $template->set_filename('mail_header', 'header.tpl'); 598 $template->set_filename('mail_footer', 'footer.tpl'); 599 600 $template->assign( 616 601 array( 617 602 'GALLERY_URL' => get_gallery_home_url(), … … 628 613 if ($content_type == 'text/html') 629 614 { 630 if ($ conf_mail[$cache_key]['theme']->smarty->template_exists('global-mail-css.tpl'))615 if ($template->smarty->template_exists('global-mail-css.tpl')) 631 616 { 632 $ conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl');633 $ conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css');617 $template->set_filename('css', 'global-mail-css.tpl'); 618 $template->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css'); 634 619 } 635 620 636 if ($ conf_mail[$cache_key]['theme']->smarty->template_exists('mail-css-'. $args['theme'] .'.tpl'))621 if ($template->smarty->template_exists('mail-css-'. $args['theme'] .'.tpl')) 637 622 { 638 $ conf_mail[$cache_key]['theme']->set_filename('css', 'mail-css-'. $args['theme'] .'.tpl');639 $ conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css');623 $template->set_filename('css', 'mail-css-'. $args['theme'] .'.tpl'); 624 $template->assign_var_from_handle('MAIL_CSS', 'css'); 640 625 } 641 626 } 642 627 643 $conf_mail[$cache_key]['header'] = $ conf_mail[$cache_key]['theme']->parse('mail_header', true);644 $conf_mail[$cache_key]['footer'] = $ conf_mail[$cache_key]['theme']->parse('mail_footer', true);628 $conf_mail[$cache_key]['header'] = $template->parse('mail_header', true); 629 $conf_mail[$cache_key]['footer'] = $template->parse('mail_footer', true); 645 630 } 646 631 … … 649 634 650 635 // Content 636 // Stored in a temp variable, if a content template is used it will be assigned 637 // to the $CONTENT template variable, otherwise it will be appened to the mail 651 638 if ($args['content_format'] == 'text/plain' and $content_type == 'text/html') 652 639 { 653 640 // convert plain text to html 654 $ contents[$content_type].=641 $mail_content = 655 642 '<p>'. 656 643 nl2br( … … 666 653 { 667 654 // convert html text to plain text 668 $ contents[$content_type].= strip_tags($args['content']);655 $mail_content = strip_tags($args['content']); 669 656 } 670 657 else 671 658 { 672 $contents[$content_type].= $args['content']; 659 $mail_content = $args['content']; 660 } 661 662 // Runtime template 663 if (isset($tpl['filename'])) 664 { 665 $template = &$conf_mail[$cache_key]['theme']; 666 if (isset($tpl['dirname'])) 667 { 668 $template->set_template_dir($tpl['dirname'] .'/'. $content_type); 669 } 670 if ($template->smarty->template_exists($tpl['filename'] .'.tpl')) 671 { 672 $template->set_filename($tpl['filename'], $tpl['filename'] .'.tpl'); 673 if (!empty($tpl['assign'])) 674 { 675 $template->assign($tpl['assign']); 676 } 677 $template->assign('CONTENT', $mail_content); 678 $contents[$content_type].= $template->parse($tpl['filename'], true); 679 } 680 else 681 { 682 $contents[$content_type].= $mail_content; 683 } 684 } 685 else 686 { 687 $contents[$content_type].= $mail_content; 673 688 } 674 689 … … 751 766 function pwg_send_mail($result, $to, $subject, $content, $headers) 752 767 { 753 trigger_error('pwg_send_mail function is deprecated', E_USER_NOTICE); 768 if (is_admin()) 769 { 770 trigger_error('pwg_send_mail function is deprecated', E_USER_NOTICE); 771 } 754 772 755 773 if (!$result) … … 764 782 return $result; 765 783 } 766 }767 768 /**769 * @deprecated 2.6770 */771 function move_ccs_rules_to_body($content)772 {773 trigger_error('move_ccs_rules_to_body function is deprecated, use move_css_to_body', E_USER_NOTICE);774 775 return move_css_to_body($content);776 784 } 777 785 -
trunk/include/functions_user.inc.php
r25237 r25357 230 230 $admin_url = get_absolute_root_url().'admin.php?page=user_list&username='.$login; 231 231 232 $ keyargs_content = array(233 get_l10n_args('User: %s', stripslashes($login)),234 get_l10n_args('Email: %s', $_POST['mail_address']),235 get_l10n_args('', ''),236 get_l10n_args('Admin: %s', $admin_url)232 $content = array( 233 l10n('User: %s', stripslashes($login) ), 234 l10n('Email: %s', $_POST['mail_address']), 235 '', 236 l10n('Admin: %s', $admin_url), 237 237 ); 238 238 239 239 pwg_mail_notification_admins( 240 get_l10n_args('Registration of %s', stripslashes($login)),241 $keyargs_content240 l10n('Registration of %s', stripslashes($login) ), 241 implode("\n", $content) 242 242 ); 243 243 }
Note: See TracChangeset
for help on using the changeset viewer.