Changeset 11808


Ignore:
Timestamp:
Jul 21, 2011, 7:45:59 PM (13 years ago)
Author:
cljosse
Message:

[extensions] mail_supervisor fix bug.

Location:
extensions/Mail_supervisor
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/Mail_supervisor/mail_send.inc.php

    r11807 r11808  
    11<?php
    2 /*
    3 $return = pwg_mail
    4           (
    5             '',
    6             array
    7             (
    8               'Bcc' => $Bcc,
    9               'subject' => l10n_args($keyargs_subject),
    10               'email_format' => $email_format,
    11               'content' => $mail_template->parse($tpl_shortname, true),
    12               'content_format' => $email_format,
    13               'theme' => $elem['theme']
    14             )
    15           ) and $return;
    16 */
     2
    173class clj {
    18 
    194static public function send_mail($result, $mailto, $subject, $content, $headers, $args) {
    205
     
    5641static public function send_mail_headers($headers_init){
    5742
    58   //    $headers_init =  preg_replace('/.*Bcc(.*).\n/i', '', $headers_init);
    59   //    $headers_init =  preg_replace('/.*Cc(.*).\n/i', '', $headers_init);
    60 
    6143 
    6244
    6345return $headers_init;
     46}
     47
     48/*
     49 * sends an email, using Piwigo specific informations
     50 *
     51 * @param:
     52 *   - to: receiver(s) of the mail (list separated by comma).
     53 *   - args: function params of mail function:
     54 *       o from: sender [default value webmaster email]
     55 *       o Cc: array of carbon copy receivers of the mail. [default value empty]
     56 *       o Bcc: array of blind carbon copy receivers of the mail. [default value empty]
     57 *       o subject  [default value 'Piwigo']
     58 *       o content: content of mail    [default value '']
     59 *       o content_format: format of mail content  [default value 'text/plain']
     60 *       o email_format: global mail format  [default value $conf_mail['default_email_format']]
     61 *       o theme: template to use [default get_default_theme()]
     62 *
     63 * @return boolean (Ok or not)
     64 * pour mise au point .
     65 */
     66function cl_pwg_mail($to, $args = array()){
     67  global $conf, $conf_mail, $lang_info, $page;
     68  if (empty($to) and empty($args['Cc']) and empty($args['Bcc'])) {
     69    return true;
     70  }
     71  if (!isset($conf_mail))  {
     72    $conf_mail = get_mail_configuration();
     73  }
     74  if (empty($args['email_format'])) {
     75    $args['email_format'] = $conf_mail['default_email_format'];
     76  }
     77  // Compute root_path in order have complete path
     78  set_make_full_url();
     79  if (empty($args['from']))  {
     80    $args['from'] = $conf_mail['formated_email_webmaster'];
     81  }  else  {
     82    $args['from'] = format_email('', $args['from']);
     83  }
     84  if (empty($args['subject']))  {
     85    $args['subject'] = 'Piwigo';
     86  }
     87  // Spring cleaning
     88  $cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject']));
     89  // Ascii convertion
     90  $cvt_subject = encode_mime_header($cvt_subject);
     91
     92  if (!isset($args['content']))  {
     93    $args['content'] = '';
     94  }
     95
     96  if (empty($args['content_format']))  {
     97    $args['content_format'] = 'text/plain';
     98  }
     99
     100  if ($conf_mail['send_bcc_mail_webmaster'])  {
     101    $args['Bcc'][] = $conf_mail['formated_email_webmaster'];
     102  }
     103
     104  if (empty($args['theme']))  {
     105    $args['theme'] = get_default_theme();
     106  }
     107
     108  $headers = 'From: '.$args['from']."\n";
     109  $headers.= 'Reply-To: '.$args['from']."\n";
     110
     111  if (!empty($args['Cc']))  {
     112    $headers.= 'Cc: '.implode(',', $args['Cc'])."\n";
     113  }
     114
     115  if (!empty($args['Bcc']))  {
     116    $headers.= 'Bcc: '.implode(',', $args['Bcc'])."\n";
     117  }
     118
     119  $headers.= 'Content-Type: multipart/alternative;'."\n";
     120  $headers.= '  boundary="---='.$conf_mail['boundary_key'].'";'."\n";
     121  $headers.= '  reply-type=original'."\n";
     122  $headers.= 'MIME-Version: 1.0'."\n";
     123  $headers.= 'X-Mailer: Piwigo Mailer'."\n";
     124
     125  // List on content-type
     126  $content_type_list[] = $args['email_format'];
     127  if (!empty($conf_mail['alternative_email_format']))  {
     128    $content_type_list[] = $conf_mail['alternative_email_format'];
     129  }
     130
     131  $content = '';
     132
     133  foreach (array_unique($content_type_list) as $content_type)  {
     134    // key compose of indexes witch allow ti cache mail data
     135    $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme'];
     136
     137    if (!isset($conf_mail[$cache_key]))    {
     138      if (!isset($conf_mail[$cache_key]['theme']))      {
     139        $conf_mail[$cache_key]['theme'] = get_mail_template($content_type, $args['theme']);
     140      }
     141
     142      $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl');
     143      $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl');
     144
     145      $conf_mail[$cache_key]['theme']->assign(
     146        array(
     147          //Header
     148          'BOUNDARY_KEY' => $conf_mail['boundary_key'],
     149          'CONTENT_TYPE' => $content_type,
     150          'CONTENT_ENCODING' => get_pwg_charset(),
     151
     152          // Footer
     153          'GALLERY_URL' => get_gallery_home_url(),
     154          'GALLERY_TITLE' =>
     155            isset($page['gallery_title']) ?
     156                  $page['gallery_title'] : $conf['gallery_title'],
     157          'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '',
     158          'PHPWG_URL' => PHPWG_URL,
     159
     160          'TITLE_MAIL' => urlencode(l10n('A comment on your site')),
     161          'MAIL' => get_webmaster_mail_address()
     162          ));
     163
     164      if ($content_type == 'text/html')     {
     165        if ($conf_mail[$cache_key]['theme']->smarty->template_exists('global-mail-css.tpl'))
     166        {
     167          $conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl');
     168          $conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css');
     169        }
     170
     171        $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl';
     172        if (is_file($file))   {
     173          $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file));
     174          $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css');
     175        }
     176      }
     177
     178      // what are displayed on the header of each mail ?
     179      $conf_mail[$cache_key]['header'] =
     180        $conf_mail[$cache_key]['theme']->parse('mail_header', true);
     181
     182      // what are displayed on the footer of each mail ?
     183      $conf_mail[$cache_key]['footer'] =
     184        $conf_mail[$cache_key]['theme']->parse('mail_footer', true);
     185    }
     186
     187    // Header
     188    $content.= $conf_mail[$cache_key]['header'];
     189
     190    // Content
     191    if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html'))    {
     192      $content.= '<p>'.
     193                  nl2br(
     194                    preg_replace("/(http:\/\/)([^\s,]*)/i",
     195                                 "<a href='$1$2' class='thumblnk'>$1$2</a>",
     196                                 htmlspecialchars($args['content']))).
     197                  '</p>';
     198    }
     199    else if (($args['content_format'] == 'text/html') and ($content_type == 'text/plain'))
     200    {
     201      // convert html text to plain text
     202      $content.= strip_tags($args['content']);
     203    }    else    {
     204      $content.= $args['content'];
     205    }
     206
     207    // Footer
     208    $content.= $conf_mail[$cache_key]['footer'];
     209
     210  // Close boundary
     211  $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
     212  }
     213
     214  //~ // Close boundary
     215  //~ $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
     216
     217   // Undo Compute root_path in order have complete path
     218  unset_make_full_url();
     219
     220  return
     221    trigger_event('send_mail',
     222      false, /* Result */
     223      trigger_event('send_mail_to', get_strict_email_list($to)),
     224      trigger_event('send_mail_subject', $cvt_subject),
     225      trigger_event('send_mail_content', $content),
     226      trigger_event('send_mail_headers', $headers),
     227      $args
     228    );
    64229}
    65230       
  • extensions/Mail_supervisor/main.inc.php

    r11807 r11808  
    206206        $pattern="---=";
    207207        $pattern ="/" . preg_quote($pattern, '/')."/" ;
    208 
    209       // site legtux ; adresse @lextux OK
    210        //  $content=$content                                          // Ok legtux
    211        //  $content= preg_replace('#(?<!\r)\n#si', "\n", $content); // Ok legtux
    212 
    213208        $pattern ="#(?<!\r)\n#si" ;
    214209        if(  preg_match($pattern, $content)  ){
    215210            $infos_message .= $pattern. " <br />";   
     211            $content= preg_replace( $pattern, "\r\n", $content);   // 
     212            //$content = str_replace("\n.", "\n..", $content);
    216213        }
    217214       
    218         $content= preg_replace('#(?<!\r)\n#si', "\r\n", $content);   // 
    219         $content = str_replace("\n.", "\n..", $content);
    220 
    221     $message = "<h2>local</h2> ";
    222     $nheaders = 'From: cl_josse@orange.fr' . "\r\n" .
    223     'Reply-To: cl_josse@orange.fr' . "\r\n" .
    224     'X-Mailer: PHP/' . phpversion();
    225 
    226 
    227      mail("cl_josse@hotmail.fr", $subject, "Test1  ".$message);
    228   mail("cl_josse@hotmail.fr", $subject,"TEST 2 ". $message,$nheaders);
    229 
    230      return true ;
    231 
    232 
    233 
    234 
    235        if(  preg_match($pattern, $content)  ){
    236             $infos_message .= "OK". " <br />";   
    237         }
    238215
    239216      }else{
     
    438415}
    439416
    440 /*
    441  * sends an email, using Piwigo specific informations
    442  *
    443  * @param:
    444  *   - to: receiver(s) of the mail (list separated by comma).
    445  *   - args: function params of mail function:
    446  *       o from: sender [default value webmaster email]
    447  *       o Cc: array of carbon copy receivers of the mail. [default value empty]
    448  *       o Bcc: array of blind carbon copy receivers of the mail. [default value empty]
    449  *       o subject  [default value 'Piwigo']
    450  *       o content: content of mail    [default value '']
    451  *       o content_format: format of mail content  [default value 'text/plain']
    452  *       o email_format: global mail format  [default value $conf_mail['default_email_format']]
    453  *       o theme: template to use [default get_default_theme()]
    454  *
    455  * @return boolean (Ok or not)
    456  */
    457 function cl_pwg_mail($to, $args = array()){
    458   global $conf, $conf_mail, $lang_info, $page;
    459   if (empty($to) and empty($args['Cc']) and empty($args['Bcc'])) {
    460     return true;
    461   }
    462   if (!isset($conf_mail))  {
    463     $conf_mail = get_mail_configuration();
    464   }
    465   if (empty($args['email_format'])) {
    466     $args['email_format'] = $conf_mail['default_email_format'];
    467   }
    468   // Compute root_path in order have complete path
    469   set_make_full_url();
    470   if (empty($args['from']))  {
    471     $args['from'] = $conf_mail['formated_email_webmaster'];
    472   }  else  {
    473     $args['from'] = format_email('', $args['from']);
    474   }
    475   if (empty($args['subject']))  {
    476     $args['subject'] = 'Piwigo';
    477   }
    478   // Spring cleaning
    479   $cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject']));
    480   // Ascii convertion
    481   $cvt_subject = encode_mime_header($cvt_subject);
    482 
    483   if (!isset($args['content']))  {
    484     $args['content'] = '';
    485   }
    486 
    487   if (empty($args['content_format']))  {
    488     $args['content_format'] = 'text/plain';
    489   }
    490 
    491   if ($conf_mail['send_bcc_mail_webmaster'])  {
    492     $args['Bcc'][] = $conf_mail['formated_email_webmaster'];
    493   }
    494 
    495   if (empty($args['theme']))  {
    496     $args['theme'] = get_default_theme();
    497   }
    498 
    499   $headers = 'From: '.$args['from']."\n";
    500   $headers.= 'Reply-To: '.$args['from']."\n";
    501 
    502   if (!empty($args['Cc']))  {
    503     $headers.= 'Cc: '.implode(',', $args['Cc'])."\n";
    504   }
    505 
    506   if (!empty($args['Bcc']))  {
    507     $headers.= 'Bcc: '.implode(',', $args['Bcc'])."\n";
    508   }
    509 
    510   $headers.= 'Content-Type: multipart/alternative;'."\n";
    511   $headers.= '  boundary="---='.$conf_mail['boundary_key'].'";'."\n";
    512   $headers.= '  reply-type=original'."\n";
    513   $headers.= 'MIME-Version: 1.0'."\n";
    514   $headers.= 'X-Mailer: Piwigo Mailer'."\n";
    515 
    516   // List on content-type
    517   $content_type_list[] = $args['email_format'];
    518   if (!empty($conf_mail['alternative_email_format']))  {
    519     $content_type_list[] = $conf_mail['alternative_email_format'];
    520   }
    521 
    522   $content = '';
    523 
    524   foreach (array_unique($content_type_list) as $content_type)  {
    525     // key compose of indexes witch allow ti cache mail data
    526     $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme'];
    527 
    528     if (!isset($conf_mail[$cache_key]))    {
    529       if (!isset($conf_mail[$cache_key]['theme']))      {
    530         $conf_mail[$cache_key]['theme'] = get_mail_template($content_type, $args['theme']);
    531       }
    532 
    533       $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl');
    534       $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl');
    535 
    536       $conf_mail[$cache_key]['theme']->assign(
    537         array(
    538           //Header
    539           'BOUNDARY_KEY' => $conf_mail['boundary_key'],
    540           'CONTENT_TYPE' => $content_type,
    541           'CONTENT_ENCODING' => get_pwg_charset(),
    542 
    543           // Footer
    544           'GALLERY_URL' => get_gallery_home_url(),
    545           'GALLERY_TITLE' =>
    546             isset($page['gallery_title']) ?
    547                   $page['gallery_title'] : $conf['gallery_title'],
    548           'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '',
    549           'PHPWG_URL' => PHPWG_URL,
    550 
    551           'TITLE_MAIL' => urlencode(l10n('A comment on your site')),
    552           'MAIL' => get_webmaster_mail_address()
    553           ));
    554 
    555       if ($content_type == 'text/html')     {
    556         if ($conf_mail[$cache_key]['theme']->smarty->template_exists('global-mail-css.tpl'))
    557         {
    558           $conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl');
    559           $conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css');
    560         }
    561 
    562         $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl';
    563         if (is_file($file))   {
    564           $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file));
    565           $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css');
    566         }
    567       }
    568 
    569       // what are displayed on the header of each mail ?
    570       $conf_mail[$cache_key]['header'] =
    571         $conf_mail[$cache_key]['theme']->parse('mail_header', true);
    572 
    573       // what are displayed on the footer of each mail ?
    574       $conf_mail[$cache_key]['footer'] =
    575         $conf_mail[$cache_key]['theme']->parse('mail_footer', true);
    576     }
    577 
    578     // Header
    579     $content.= $conf_mail[$cache_key]['header'];
    580 
    581     // Content
    582     if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html'))    {
    583       $content.= '<p>'.
    584                   nl2br(
    585                     preg_replace("/(http:\/\/)([^\s,]*)/i",
    586                                  "<a href='$1$2' class='thumblnk'>$1$2</a>",
    587                                  htmlspecialchars($args['content']))).
    588                   '</p>';
    589     }
    590     else if (($args['content_format'] == 'text/html') and ($content_type == 'text/plain'))
    591     {
    592       // convert html text to plain text
    593       $content.= strip_tags($args['content']);
    594     }    else    {
    595       $content.= $args['content'];
    596     }
    597 
    598     // Footer
    599     $content.= $conf_mail[$cache_key]['footer'];
    600 
    601   // Close boundary
    602   $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
    603   }
    604 
    605   //~ // Close boundary
    606   //~ $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
    607 
    608    // Undo Compute root_path in order have complete path
    609   unset_make_full_url();
    610 
    611   return
    612     trigger_event('send_mail',
    613       false, /* Result */
    614       trigger_event('send_mail_to', get_strict_email_list($to)),
    615       trigger_event('send_mail_subject', $cvt_subject),
    616       trigger_event('send_mail_content', $content),
    617       trigger_event('send_mail_headers', $headers),
    618       $args
    619     );
    620 }
    621417
    622418
Note: See TracChangeset for help on using the changeset viewer.