Changeset 1809

Show
Ignore:
Timestamp:
02/13/07 00:21:23 (6 years ago)
Author:
rub
Message:

When not template are selected for mail, PWG uses default template..

Sent multi-part message in MIME format. (With only one part for the moment).

Improvement pwg_mail function.

Location:
trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions_notification_by_mail.inc.php

    r1806 r1809  
    258258 * Return none 
    259259 */ 
    260 function set_user_on_env_nbm($user_id, $is_action_send) 
     260function set_user_on_env_nbm(&$nbm_user, $is_action_send) 
    261261{ 
    262262  global $user, $lang, $lang_info, $env_nbm; 
    263263 
    264264  $user = array(); 
    265   $user['id'] = $user_id; 
     265  $user['id'] = $nbm_user['user_id']; 
    266266  $user = array_merge($user, getuserdata($user['id'], true)); 
    267267 
     
    287287  if ($is_action_send) 
    288288  { 
    289     $env_nbm['mail_template'] = get_mail_template($env_nbm['email_format']); 
     289    $nbm_user['template'] = $user['template']; 
     290    $nbm_user['theme'] = $user['theme']; 
     291    $env_nbm['mail_template'] = 
     292      get_mail_template($env_nbm['email_format'],  
     293        array('template' => $nbm_user['template'], 'theme' => $nbm_user['theme'])); 
    290294    $env_nbm['mail_template']->set_filename('notification_by_mail', 'admin/notification_by_mail.tpl'); 
    291295  } 
     
    432436      { 
    433437        // set env nbm user 
    434         set_user_on_env_nbm($nbm_user['user_id'], true); 
     438        set_user_on_env_nbm($nbm_user, true); 
    435439 
    436440        $subject = '['.$conf['gallery_title'].']: '.($is_subscribe ? l10n('nbm_object_subscribe'): l10n('nbm_object_unsubscribe')); 
     
    446450        ); 
    447451 
    448         if (pwg_mail( 
     452        if (pwg_mail 
     453            ( 
    449454              format_email($nbm_user['username'], $nbm_user['mail_address']), 
    450               $env_nbm['send_as_mail_formated'], 
    451               $subject, 
    452               $env_nbm['mail_template']->parse('notification_by_mail', true), 
    453               $env_nbm['email_format'], $env_nbm['email_format'] 
    454               )) 
     455              array 
     456              ( 
     457                'from' => $env_nbm['send_as_mail_formated'], 
     458                'subject' => $subject, 
     459                'email_format' => $env_nbm['email_format'], 
     460                'content' => $env_nbm['mail_template']->parse('notification_by_mail', true), 
     461                'content_format' => $env_nbm['email_format'], 
     462                'template' => $nbm_user['template'], 
     463                'theme' => $nbm_user['theme'] 
     464              ) 
     465            )) 
    455466        { 
    456467          inc_mail_sent_success($nbm_user); 
  • trunk/admin/notification_by_mail.php

    r1806 r1809  
    274274 
    275275          // set env nbm user 
    276           set_user_on_env_nbm($nbm_user['user_id'], $is_action_send); 
     276          set_user_on_env_nbm($nbm_user, $is_action_send); 
    277277 
    278278          if ($is_action_send) 
     
    378378              ); 
    379379 
    380               if (pwg_mail( 
     380              if (pwg_mail 
     381                  ( 
    381382                    format_email($nbm_user['username'], $nbm_user['mail_address']), 
    382                     $env_nbm['send_as_mail_formated'], 
    383                     $subject, 
    384                     $env_nbm['mail_template']->parse('notification_by_mail', true), 
    385                     $env_nbm['email_format'], $env_nbm['email_format'] 
    386                     )) 
     383                    array 
     384                    ( 
     385                      'from' => $env_nbm['send_as_mail_formated'], 
     386                      'subject' => $subject, 
     387                      'email_format' => $env_nbm['email_format'], 
     388                      'content' => $env_nbm['mail_template']->parse('notification_by_mail', true), 
     389                      'content_format' => $env_nbm['email_format'], 
     390                      'template' => $nbm_user['template'], 
     391                      'theme' => $nbm_user['theme'] 
     392                    ) 
     393                  )) 
    387394              { 
    388395                inc_mail_sent_success($nbm_user); 
  • trunk/include/functions_mail.inc.php

    r1808 r1809  
    6565    format_email($conf['gallery_title'], $conf_mail['email_webmaster']); 
    6666 
     67  $conf_mail['boundary_key'] = generate_key(32); 
     68 
    6769  return $conf_mail; 
    6870} 
     
    98100 
    99101/** 
    100  * Returns an new mail template 
    101  * 
    102  * @param none 
    103  */ 
    104 function get_mail_template($email_format) 
    105 { 
    106   global $user; 
    107  
    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); 
     102 * Return an completed array template/theme 
     103 * completed with $conf['default_template'] 
     104 * 
     105 * @params: 
     106 *   - args: incompleted array of template/theme 
     107 *       o template: template to use [default $conf['default_template']] 
     108 *       o theme: template to use [default $conf['default_template']] 
     109 */ 
     110function get_array_template_theme($args = array()) 
     111{ 
     112  global $conf; 
     113 
     114  $res = array(); 
     115   
     116  if (empty($args['template']) or empty($args['theme'])) 
     117  { 
     118    list($res['template'], $res['theme']) = explode('/', $conf['default_template']); 
     119  } 
     120 
     121  if (!empty($args['template'])) 
     122  { 
     123    $res['template'] = $args['template']; 
     124  } 
     125 
     126  if (!empty($args['theme'])) 
     127  { 
     128    $res['theme'] = $args['theme']; 
     129  } 
     130 
     131  return $res; 
     132} 
     133 
     134/** 
     135 * Return an new mail template 
     136 * 
     137 * @params: 
     138 *   - email_format: mail format 
     139 *   - args: function params of mail function: 
     140 *       o template: template to use [default $conf['default_template']] 
     141 *       o theme: template to use [default $conf['default_template']] 
     142 */ 
     143function get_mail_template($email_format, $args = array()) 
     144{ 
     145  $args = get_array_template_theme($args); 
     146 
     147  $mail_template = new Template(PHPWG_ROOT_PATH.'template/'.$args['template'], $args['theme']); 
     148  $mail_template->set_rootdir(PHPWG_ROOT_PATH.'template/'.$args['template'].'/mail/'.$email_format); 
    110149 
    111150  return $mail_template; 
     
    124163/** 
    125164 * sends an email, using PhpWebGallery specific informations 
    126  */ 
    127 function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $format_infos = 'text/plain', $email_format = null) 
    128 { 
    129   global $conf, $conf_mail, $lang_info, $page, $user; 
    130  
    131   $cvt7b_subject = str_translate_to_ascii7bits($subject); 
     165 * 
     166 * @param: 
     167 *   - to: Receiver, or receivers of the mail. 
     168 *   - args: function params of mail function: 
     169 *       o from: sender [default value webmaster email] 
     170 *       o subject  [default value 'PhpWebGallery'] 
     171 *       o content: content of mail    [default value ''] 
     172 *       o content_format: format of mail content  [default value 'text/plain'] 
     173 *       o email_format: global mail format  [default value $conf_mail['default_email_format']] 
     174 *       o template: template to use [default $conf['default_template']] 
     175 *       o theme: template to use [default $conf['default_template']] 
     176 */ 
     177//function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $infos_format = 'text/plain', $email_format = null) 
     178function pwg_mail($to, $args = array()) 
     179{ 
     180  global $conf, $conf_mail, $lang_info, $page; 
    132181 
    133182  if (!isset($conf_mail)) 
     
    136185  } 
    137186 
    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')) 
     187  if (empty($args['email_format'])) 
     188  { 
     189    $args['email_format'] = $conf_mail['default_email_format']; 
     190  } 
     191 
     192  // Compute root_path in order have complete path 
     193  if ($args['email_format'] == 'text/html') 
     194  { 
     195    set_make_full_url(); 
     196  } 
     197 
     198  $to = format_email('', $to); 
     199 
     200  if (empty($args['from'])) 
     201  { 
     202    $args['from'] = $conf_mail['formated_email_webmaster']; 
     203  } 
     204  else 
     205  { 
     206    $args['from'] = format_email('', $args['from']); 
     207  } 
     208 
     209  if (empty($args['subject'])) 
     210  { 
     211    $args['subject'] = 'PhpWebGallery'; 
     212  } 
     213  $cvt7b_subject = str_translate_to_ascii7bits($args['subject']); 
     214 
     215  if (!isset($args['content'])) 
     216  { 
     217    $args['content'] = ''; 
     218  } 
     219 
     220  if (empty($args['content_format'])) 
     221  { 
     222    $args['content_format'] = 'text/plain'; 
     223  } 
     224 
     225  if (($args['content_format'] == 'text/html') and ($args['email_format'] == 'text/plain')) 
    144226  { 
    145227    // Todo find function to convert html text to plain text 
     
    147229  } 
    148230 
    149   // Compute root_path in order have complete path 
    150   if ($email_format == 'text/html') 
    151   { 
    152     set_make_full_url(); 
    153   } 
    154  
    155   $to = format_email('', $to); 
    156  
    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"; 
    168   $headers.= 'Content-Type: '.$email_format.';format=flowed;charset="'.$lang_info['charset'].'";'; 
    169   $headers.= 'reply-type=original'."\n"; 
     231  $args = array_merge($args, get_array_template_theme($args)); 
     232 
     233  $headers = 'From: '.$args['from']."\n"; 
     234  $headers.= 'Reply-To: '.$args['from']."\n"; 
     235  $headers.= 'Content-Type: multipart/alternative;'."\n"; 
     236  $headers.= '  boundary="---='.$conf_mail['boundary_key'].'";'."\n"; 
     237  $headers.= '  reply-type=original'."\n"; 
    170238  $headers.= 'MIME-Version: 1.0'."\n"; 
    171239 
     
    177245  $content = ''; 
    178246 
    179   if (!isset($conf_mail[$email_format][$lang_info['charset']][$user['template']][$user['theme']])) 
     247  if (!isset($conf_mail[$args['email_format']][$lang_info['charset']][$args['template']][$args['theme']])) 
    180248  { 
    181249    if (!isset($mail_template)) 
    182250    { 
    183       $mail_template = get_mail_template($email_format); 
     251      $mail_template = get_mail_template($args['email_format']); 
    184252    } 
    185253 
     
    190258      array( 
    191259        //Header 
     260        'BOUNDARY_KEY' => $conf_mail['boundary_key'], 
     261        'CONTENT_TYPE' => $args['email_format'], 
    192262        'CONTENT_ENCODING' => $lang_info['charset'], 
    193263        'LANG' => $lang_info['code'], 
     
    208278        )); 
    209279 
    210     if ($email_format == 'text/html') 
     280    if ($args['email_format'] == 'text/html') 
    211281    { 
    212282      $old_root = $mail_template->root; 
     
    218288      } 
    219289 
    220       $mail_template->root = PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/'.$user['theme']; 
     290      $mail_template->root = PHPWG_ROOT_PATH.'template/'.$args['template'].'/theme/'.$args['theme']; 
    221291      if (is_file($mail_template->root.'/mail-css.tpl')) 
    222292      { 
     
    236306 
    237307    // what are displayed on the header of each mail ? 
    238     $conf_mail[$email_format] 
     308    $conf_mail[$args['email_format']] 
    239309      [$lang_info['charset']] 
    240       [$user['template']][$user['theme']]['header'] = 
     310      [$args['template']][$args['theme']]['header'] = 
    241311        $mail_template->parse('mail_header', true); 
    242312 
    243313    // what are displayed on the footer of each mail ? 
    244     $conf_mail[$email_format] 
     314    $conf_mail[$args['email_format']] 
    245315      [$lang_info['charset']] 
    246       [$user['template']][$user['theme']]['footer'] = 
     316      [$args['template']][$args['theme']]['footer'] = 
    247317        $mail_template->parse('mail_footer', true); 
    248318  } 
    249319 
    250   $content.= $conf_mail[$email_format] 
     320  // Header 
     321  $content.= $conf_mail[$args['email_format']] 
    251322              [$lang_info['charset']] 
    252               [$user['template']][$user['theme']]['header']; 
    253  
    254   if (($format_infos == 'text/plain') and ($email_format == 'text/html')) 
    255   { 
    256     $content.= '<pre>'.htmlentities($infos).'</pre>'; 
     323              [$args['template']][$args['theme']]['header']; 
     324 
     325  // Content 
     326  if (($args['content_format'] == 'text/plain') and ($args['email_format'] == 'text/html')) 
     327  { 
     328    $content.= '<p>'.nl2br(htmlentities($args['content'])).'</p>'; 
    257329  } 
    258330  else 
    259331  { 
    260     $content.= $infos; 
    261   } 
    262  
    263   $content.= $conf_mail[$email_format] 
     332    $content.= $args['content']; 
     333  } 
     334 
     335  // Footer 
     336  $content.= $conf_mail[$args['email_format']] 
    264337              [$lang_info['charset']] 
    265               [$user['template']][$user['theme']]['footer']; 
    266    
     338              [$args['template']][$args['theme']]['footer']; 
     339 
     340  // Close boundary 
     341  $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n"; 
     342 
    267343   // Undo Compute root_path in order have complete path 
    268   if ($email_format == 'text/html') 
     344  if ($args['email_format'] == 'text/html') 
    269345  { 
    270346    unset_make_full_url(); 
     
    276352    @mkdir(PHPWG_ROOT_PATH.'testmail'); 
    277353    $filename = PHPWG_ROOT_PATH.'testmail/mail.'.$user['username']; 
    278     if ($format_infos == 'text/plain') 
     354    if ($args['content_format'] == 'text/plain') 
    279355    { 
    280356      $filename .= '.txt'; 
  • trunk/include/picture_comment.inc.php

    r1750 r1809  
    224224          .'comments.php?validate='.$comm['id']; 
    225225      } 
    226       pwg_mail( get_webmaster_mail_address(), '', 
    227           'PWG comment by '.$comm['author'], 
    228           $content 
    229           ); 
     226      pwg_mail(get_webmaster_mail_address(), 
     227        array('subject' => 'PWG comment by '.$comm['author'], 'content' => $content)); 
    230228    } 
    231229  } 
  • trunk/password.php

    r1531 r1809  
    8585          ; 
    8686 
    87         if (pwg_mail($row['email'], '', l10n('password updated'), $infos)) 
     87        if (pwg_mail($row['email'], 
     88              array('subject' => l10n('password updated'), 'content' => $infos))) 
    8889        { 
    8990          $data = 
  • trunk/register.php

    r1753 r1809  
    7171        .l10n('admin').': '.$admin_url; 
    7272 
    73       pwg_mail( get_webmaster_mail_address(), '', 
    74           'PWG '.l10n('register_title').' '.$username, 
    75           $content 
    76           ); 
     73      pwg_mail(get_webmaster_mail_address(), 
     74        array 
     75        ( 
     76          'subject' => 'PWG '.l10n('register_title').' '.$username, 
     77          'content' => $content 
     78        ) 
     79      ); 
    7780    } 
    7881    redirect(make_index_url()); 
  • trunk/template/yoga/mail/text/html/header.tpl

    r1807 r1809  
    1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    2             "http://www.w3.org/TR/html4/loose.dtd"> 
     1-----={BOUNDARY_KEY} 
     2Content-Type: {CONTENT_TYPE}; charset={CONTENT_ENCODING}; 
     3Content-Transfer-Encoding: 8bit 
     4 
     5<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    36<html lang="{LANG}" dir="{DIR}"> 
    47<head> 
  • trunk/template/yoga/mail/text/plain/header.tpl

    r1784 r1809  
    1 {FAKE_SIMULATE_EMPTY_FILE} 
     1-----={BOUNDARY_KEY} 
     2Content-Type: {CONTENT_TYPE}; charset={CONTENT_ENCODING}; format=flowed; 
     3Content-Transfer-Encoding: 8bit