Changeset 25344


Ignore:
Timestamp:
11/05/13 20:23:29 (6 years ago)
Author:
mistic100
Message:

feature 2965: apply new template on pwg_mail()
TODO : review other mail functions, configuration GUI

Location:
trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/config_default.inc.php

    r25338 r25344  
    230230$conf['available_permission_levels'] = array(0,1,2,4,8); 
    231231 
    232 // mail_options: only set it true if you have a send mail warning with 
    233 // "options" parameter missing on mail() function execution. 
    234 $conf['mail_options'] = false; 
     232// check_upgrade_feed: check if there are database upgrade required. Set to 
     233// true, a message will strongly encourage you to upgrade your database if 
     234// needed. 
     235// 
     236// This configuration parameter is set to true in BSF branch and to false 
     237// elsewhere. 
     238$conf['check_upgrade_feed'] = true; 
     239 
     240// rate_items: available rates for a picture 
     241$conf['rate_items'] = array(0,1,2,3,4,5); 
     242 
     243// Define default method to use ('http' or 'html' in order to do redirect) 
     244$conf['default_redirect_method'] = 'http'; 
     245 
     246// Define using double password type in admin's users management panel 
     247$conf['double_password_type_in_admin'] = false; 
     248 
     249// Define if logins must be case sentitive or not at users registration. ie : 
     250// If set true, the login "user" will equal "User" or "USER" or "user", 
     251// etc. ... And it will be impossible to use such login variation to create a 
     252// new user account. 
     253$conf['insensitive_case_logon'] = false; 
     254 
     255// how should we check for unicity when adding a photo. Can be 'md5sum' or 
     256// 'filename' 
     257$conf['uniqueness_mode'] = 'md5sum'; 
     258 
     259// Library used for image resizing. Value could be 'auto', 'imagick', 
     260// 'ext_imagick' or 'gd'. If value is 'auto', library will be choosen in this 
     261// order. If choosen library is not available, another one will be picked up. 
     262$conf['graphics_library'] = 'auto'; 
     263 
     264// If library used is external installation of ImageMagick ('ext_imagick'), 
     265// you can define imagemagick directory. 
     266$conf['ext_imagick_dir'] = ''; 
     267 
     268// how many user comments to display by default on comments.php. Use 'all' 
     269// to display all user comments without pagination. Default available values 
     270// are array(5,10,20,50,'all') but you can set any other numeric value. 
     271$conf['comments_page_nb_comments'] = 10; 
     272 
     273// +-----------------------------------------------------------------------+ 
     274// |                                 email                                 | 
     275// +-----------------------------------------------------------------------+ 
    235276 
    236277// send_bcc_mail_webmaster: send bcc mail to webmaster. Set true for debug 
     
    238279$conf['send_bcc_mail_webmaster'] = false; 
    239280 
    240 // default_email_format: 
    241 //  Define the default email format use to send email 
    242 //  Value could be text/plain  or text/html 
    243 $conf['default_email_format'] = 'text/html'; 
    244  
    245 // alternative_email_format: 
    246 //  Define the alternative email format use to send email 
    247 //  Value could be text/plain  or text/html 
    248 $conf['alternative_email_format'] = 'text/plain'; 
    249  
    250 // define the name of sender mail: 
    251 // If value is empty, gallery title is used 
     281// define the name of sender mail: if value is empty, gallery title is used 
    252282$conf['mail_sender_name'] = ''; 
    253283 
    254 // smtp configuration 
    255 // (work if fsockopen function is allowed for smtp port) 
     284// define the email of sender mail: if valie is empty, webmaster email is used 
     285$conf['mail_sender_email'] = ''; 
     286 
     287// set true to allow text/html emails 
     288$conf['allow_html_email'] = true; 
     289 
     290// 'clear' or 'dark' 
     291$conf['mail_theme'] = 'clear'; 
     292 
     293// smtp configuration (work if fsockopen function is allowed for smtp port) 
    256294// smtp_host: smtp server host 
    257295//  if null, regular mail function is used 
     
    265303// 'ssl' or 'tls' 
    266304$conf['smtp_secure'] = null; 
    267  
    268 // check_upgrade_feed: check if there are database upgrade required. Set to 
    269 // true, a message will strongly encourage you to upgrade your database if 
    270 // needed. 
    271 // 
    272 // This configuration parameter is set to true in BSF branch and to false 
    273 // elsewhere. 
    274 $conf['check_upgrade_feed'] = true; 
    275  
    276 // rate_items: available rates for a picture 
    277 $conf['rate_items'] = array(0,1,2,3,4,5); 
    278  
    279 // Define default method to use ('http' or 'html' in order to do redirect) 
    280 $conf['default_redirect_method'] = 'http'; 
    281  
    282 // Define using double password type in admin's users management panel 
    283 $conf['double_password_type_in_admin'] = false; 
    284  
    285 // Define if logins must be case sentitive or not at users registration. ie : 
    286 // If set true, the login "user" will equal "User" or "USER" or "user", 
    287 // etc. ... And it will be impossible to use such login variation to create a 
    288 // new user account. 
    289 $conf['insensitive_case_logon'] = false; 
    290  
    291 // how should we check for unicity when adding a photo. Can be 'md5sum' or 
    292 // 'filename' 
    293 $conf['uniqueness_mode'] = 'md5sum'; 
    294  
    295 // Library used for image resizing. Value could be 'auto', 'imagick', 
    296 // 'ext_imagick' or 'gd'. If value is 'auto', library will be choosen in this 
    297 // order. If choosen library is not available, another one will be picked up. 
    298 $conf['graphics_library'] = 'auto'; 
    299  
    300 // If library used is external installation of ImageMagick ('ext_imagick'), 
    301 // you can define imagemagick directory. 
    302 $conf['ext_imagick_dir'] = ''; 
    303  
    304 // how many user comments to display by default on comments.php. Use 'all' 
    305 // to display all user comments without pagination. Default available values 
    306 // are array(5,10,20,50,'all') but you can set any other numeric value. 
    307 $conf['comments_page_nb_comments'] = 10; 
    308305 
    309306// +-----------------------------------------------------------------------+ 
  • trunk/include/functions_mail.inc.php

    r25018 r25344  
    2222// +-----------------------------------------------------------------------+ 
    2323 
    24 // +-----------------------------------------------------------------------+ 
    25 // |                               functions                               | 
    26 // +-----------------------------------------------------------------------+ 
    27  
    28 /* 
    29  * Returns the name of the mail sender : 
    30  * 
     24/** 
     25 * Returns the name of the mail sender 
    3126 * @return string 
    3227 */ 
     
    3833} 
    3934 
    40 /* 
     35/** 
     36 * Returns the email of the mail sender 
     37 * @since 2.6 
     38 * @return string 
     39 */ 
     40function get_mail_sender_email() 
     41{ 
     42  global $conf; 
     43 
     44  return (empty($conf['mail_sender_email']) ? get_webmaster_mail_address() : $conf['mail_sender_email']); 
     45} 
     46 
     47/** 
    4148 * Returns an array of mail configuration parameters : 
    42  * 
    43  * - mail_options 
    4449 * - send_bcc_mail_webmaster 
    45  * - default_email_format 
    46  * - alternative_email_format 
     50 * - allow_html_email 
    4751 * - use_smtp 
    4852 * - smtp_host 
    4953 * - smtp_user 
    5054 * - smtp_password 
    51  * - boundary_key 
     55 * - smtp_secure 
    5256 * - email_webmaster 
    53  * - formated_email_webmaster 
     57 * - name_webmaster 
    5458 * 
    5559 * @return array 
     
    6064 
    6165  $conf_mail = array( 
    62     'mail_options' => $conf['mail_options'], 
    6366    'send_bcc_mail_webmaster' => $conf['send_bcc_mail_webmaster'], 
    64     'default_email_format' => $conf['default_email_format'], 
    65     'alternative_email_format' => $conf['alternative_email_format'], 
     67    'allow_html_email' => $conf['allow_html_email'], 
     68    'mail_theme' => $conf['mail_theme'], 
    6669    'use_smtp' => !empty($conf['smtp_host']), 
    6770    'smtp_host' => $conf['smtp_host'], 
     
    6972    'smtp_password' => $conf['smtp_password'], 
    7073    'smtp_secure' => $conf['smtp_secure'], 
     74    'email_webmaster' => get_mail_sender_email(), 
     75    'name_webmaster' => get_mail_sender_name(), 
    7176    ); 
    7277 
    73   // we have webmaster id among user list, what's his email address ? 
    74   $conf_mail['email_webmaster'] = get_webmaster_mail_address(); 
    75  
    76   // name of the webmaster is the title of the gallery 
    77   $conf_mail['formated_email_webmaster'] = format_email(get_mail_sender_name(), $conf_mail['email_webmaster']); 
    78  
    7978  return $conf_mail; 
    8079} 
     
    8281/** 
    8382 * Returns an email address with an associated real name 
    84  * 
    8583 * @param string name 
    8684 * @param string email 
     
    8886function format_email($name, $email) 
    8987{ 
    90   // Spring cleaning 
    9188  $cvt_email = trim(preg_replace('#[\n\r]+#s', '', $email)); 
    9289  $cvt_name = trim(preg_replace('#[\n\r]+#s', '', $name)); 
     
    108105 
    109106/** 
     107 * Returns the mail and the name from a formatted address 
     108 * @since 2.6 
     109 * @param string|array $input 
     110 * @return array 
     111 */ 
     112function unformat_email($input) 
     113{ 
     114  if (is_array($input)) 
     115  { 
     116    return $input; 
     117  } 
     118 
     119  if (preg_match('/(.*)<(.*)>.*/', $input, $matches)) 
     120  { 
     121    return array( 
     122      'email' => trim($matches[2]), 
     123      'name' => trim($matches[1]), 
     124      ); 
     125  } 
     126  else 
     127  { 
     128    return array( 
     129      'email' => trim($input), 
     130      'name' => '', 
     131      ); 
     132  } 
     133} 
     134   
     135 
     136/** 
    110137 * Returns an email address list with minimal email string 
    111  * 
    112  * @param string with email list (email separated by comma) 
     138 * @param string $email_list - comma separated 
     139 * @return string 
    113140 */ 
    114141function get_strict_email_list($email_list) 
     
    116143  $result = array(); 
    117144  $list = explode(',', $email_list); 
     145 
    118146  foreach ($list as $email) 
    119147  { 
     
    131159/** 
    132160 * Return an new mail template 
    133  * 
    134  * @param string email_format: mail format, text/html or text/plain 
    135  * @param string theme: theme to use [default get_default_theme()] 
    136  */ 
    137 function & get_mail_template($email_format, $theme='') 
    138 { 
    139   if (empty($theme)) 
    140   { 
    141     $theme = get_default_theme(); 
    142   } 
    143  
    144   $mail_template = new Template(PHPWG_ROOT_PATH.'themes', $theme, 'template/mail/'.$email_format); 
    145  
    146   return $mail_template; 
    147 } 
    148  
    149 /** 
    150  * Return string email format (text/html or text/plain) 
    151  * 
    152  * @param string format 
    153  */ 
    154 function get_str_email_format($is_html) 
    155 { 
    156   return ($is_html ? 'text/html' : 'text/plain'); 
    157 } 
    158  
    159 /* 
    160  * Switch language to param language 
     161 * @param string $email_format - text/html or text/plain 
     162 * @return Template 
     163 */ 
     164function &get_mail_template($email_format) 
     165{ 
     166  $template = new Template(PHPWG_ROOT_PATH.'themes', 'default', 'template/mail/'.$email_format); 
     167  return $template; 
     168} 
     169 
     170/** 
     171 * Switch language to specified language 
    161172 * All entries are push on language stack 
    162  * 
    163  * @param string language 
     173 * @param string $language 
    164174 */ 
    165175function switch_lang_to($language) 
     
    198208    load_language('admin.lang', '', array('language'=>$language) ); 
    199209     
     210    // Reload all plugins files (see load_language declaration) 
    200211    if (!empty($language_files)) 
    201212    { 
     
    220231} 
    221232 
    222 /* 
     233/** 
    223234 * Switch back language pushed with switch_lang_to function 
    224  * 
    225  * @param: none 
    226235 */ 
    227236function switch_lang_back() 
     
    457466} 
    458467 
    459 /* 
     468/** 
    460469 * sends an email, using Piwigo specific informations 
    461470 * 
    462  * @param: 
    463  *   - to: receiver(s) of the mail (list separated by comma). 
    464  *   - args: function params of mail function: 
     471 * @param string|string[] $to 
     472 * @param array $args 
    465473 *       o from: sender [default value webmaster email] 
    466474 *       o Cc: array of carbon copy receivers of the mail. [default value empty] 
     
    470478 *       o content_format: format of mail content  [default value 'text/plain'] 
    471479 *       o email_format: global mail format  [default value $conf_mail['default_email_format']] 
    472  *       o theme: template to use [default get_default_theme()] 
     480 *       o theme: theme to use [default value $conf_mail['mail_theme']] 
     481 *       o mail_title: main title of the mail [default value $conf['gallery_title']] 
     482 *       o mail_subtitle: subtitle of the mail [default value subject] 
    473483 * 
    474  * @return boolean (Ok or not) 
     484 * @return boolean 
    475485 */ 
    476486function pwg_mail($to, $args = array()) 
     
    492502  $mail = new PHPMailer; 
    493503 
    494   foreach (explode(',', get_strict_email_list($to)) as $recipient) 
    495   { 
    496     $mail->addAddress($recipient); 
    497   } 
    498    
     504  $recipients = !is_array($to) ? explode(',', $to) : $to; 
     505  foreach ($recipients as $recipient) 
     506  { 
     507    $recipient = unformat_email($recipient); 
     508    $mail->addAddress($recipient['email'], $recipient['name']); 
     509  } 
     510 
    499511  $mail->WordWrap = 76; 
    500512  $mail->CharSet = 'UTF-8'; 
     
    505517  if (empty($args['from'])) 
    506518  { 
    507     $mail->From = get_webmaster_mail_address(); 
    508     $mail->FromName = get_mail_sender_name(); 
    509  
    510     $mail->addReplyTo(get_webmaster_mail_address(), get_mail_sender_name()); 
     519    $from = array( 
     520      'email' => $conf_mail['email_webmaster'], 
     521      'name' => $conf_mail['name_webmaster'], 
     522      ); 
    511523  } 
    512524  else 
    513525  { 
    514     $mail->From = $args['from']; 
    515     $mail->addReplyTo($args['from']); 
    516   } 
     526    $from = unformat_email($args['from']); 
     527  } 
     528  $mail->setFrom($from['email'], $from['name']); 
     529  $mail->addReplyTo($from['email'], $from['name']); 
    517530 
    518531  // Subject 
     
    521534    $args['subject'] = 'Piwigo'; 
    522535  } 
    523    
    524536  $args['subject'] = trim(preg_replace('#[\n\r]+#s', '', $args['subject'])); 
    525  
    526537  $mail->Subject = $args['subject']; 
    527538 
     
    529540  if (!empty($args['Cc'])) 
    530541  { 
    531     $mail->addCC($args['Cc']); 
     542    foreach ($args['Cc'] as $cc) 
     543    { 
     544      $cc = unformat_email($cc); 
     545      $mail->addCC($cc['email'], $cc['name']); 
     546    } 
    532547  } 
    533548 
     
    535550  if ($conf_mail['send_bcc_mail_webmaster']) 
    536551  { 
    537     $args['Bcc'][] = get_webmaster_mail_address();; 
    538   } 
    539  
     552    $args['Bcc'][] = get_webmaster_mail_address(); 
     553  } 
    540554  if (!empty($args['Bcc'])) 
    541555  { 
    542556    foreach ($args['Bcc'] as $bcc) 
    543557    { 
    544       $mail->addBCC($bcc); 
    545     } 
     558      $bcc = unformat_email($bcc); 
     559      $mail->addBCC($bcc['email'], $bcc['name']); 
     560    } 
     561  } 
     562 
     563  // theme 
     564  if (empty($args['theme']) or !in_array($args['theme'], array('clear','dark'))) 
     565  { 
     566    $args['theme'] = $conf_mail['mail_theme']; 
    546567  } 
    547568 
    548569  // content 
    549   if (empty($args['email_format'])) 
    550   { 
    551     $args['email_format'] = $conf_mail['default_email_format']; 
    552   } 
    553  
    554570  if (!isset($args['content'])) 
    555571  { 
    556572    $args['content'] = ''; 
    557573  } 
    558  
     574  if (!isset($args['mail_title'])) 
     575  { 
     576    $args['mail_title'] = $conf['gallery_title']; 
     577  } 
     578  if (!isset($args['mail_subtitle'])) 
     579  { 
     580    $args['mail_subtitle'] = $args['subject']; 
     581  } 
     582 
     583  // content type 
    559584  if (empty($args['content_format'])) 
    560585  { 
     
    562587  } 
    563588 
    564   if (empty($args['theme'])) 
    565   { 
    566     $args['theme'] = get_default_theme(); 
    567   } 
    568  
    569   $content_type_list[] = $args['email_format']; 
    570   if (!empty($conf_mail['alternative_email_format'])) 
    571   { 
    572     $content_type_list[] = $conf_mail['alternative_email_format']; 
    573   } 
     589  $content_type_list = array(); 
     590  if ($conf_mail['allow_html_email'] and @$args['email_format'] != 'text/plain') 
     591  { 
     592    $content_type_list[] = 'text/html'; 
     593  } 
     594  $content_type_list[] = 'text/plain'; 
    574595 
    575596  $contents = array(); 
    576  
    577   foreach (array_unique($content_type_list) as $content_type) 
    578   { 
    579     // key compose of indexes witch allow ti cache mail data 
    580     $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme']; 
     597  foreach ($content_type_list as $content_type) 
     598  { 
     599    // key compose of indexes witch allow to cache mail data 
     600    $cache_key = $content_type.'-'.$lang_info['code']; 
     601    $cache_key.= '-'.crc32(@$args['mail_title'] . @$args['mail_subtitle']); 
    581602 
    582603    if (!isset($conf_mail[$cache_key])) 
    583604    { 
     605      // instanciate a new Template 
    584606      if (!isset($conf_mail[$cache_key]['theme'])) 
    585607      { 
    586         $conf_mail[$cache_key]['theme'] = get_mail_template($content_type, $args['theme']); 
     608        $conf_mail[$cache_key]['theme'] = get_mail_template($content_type); 
     609        trigger_action('before_parse_mail_template', $cache_key, $content_type); 
    587610      } 
    588611 
     
    595618          'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'], 
    596619          'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', 
    597           'PHPWG_URL' => PHPWG_URL, 
    598           'TITLE_MAIL' => urlencode(l10n('A comment on your site')), 
    599           'MAIL' => get_webmaster_mail_address() 
     620          'PHPWG_URL' => defined('PHPWG_URL') ? PHPWG_URL : '', 
     621          'CONTENT_ENCODING' => get_pwg_charset(), 
     622          'CONTACT_MAIL' => $conf_mail['email_webmaster'], 
     623          'MAIL_TITLE' => $args['mail_title'], 
     624          'MAIL_SUBTITLE' => $args['mail_subtitle'], 
    600625          ) 
    601626        ); 
     
    609634        } 
    610635 
    611         $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl'; 
    612         if (is_file($file)) 
     636        if ($conf_mail[$cache_key]['theme']->smarty->template_exists('mail-css-'. $args['theme'] .'.tpl')) 
    613637        { 
    614           $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file)); 
     638          $conf_mail[$cache_key]['theme']->set_filename('css', 'mail-css-'. $args['theme'] .'.tpl'); 
    615639          $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css'); 
    616640        } 
    617641      } 
    618642 
    619       // what are displayed on the header of each mail ? 
    620643      $conf_mail[$cache_key]['header'] = $conf_mail[$cache_key]['theme']->parse('mail_header', true); 
    621  
    622       // what are displayed on the footer of each mail ? 
    623644      $conf_mail[$cache_key]['footer'] = $conf_mail[$cache_key]['theme']->parse('mail_footer', true); 
    624645    } 
     
    628649 
    629650    // Content 
    630     if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html')) 
    631     { 
    632       $contents[$content_type].= '<p>'. 
    633                   nl2br( 
    634                     preg_replace("/(http:\/\/)([^\s,]*)/i", 
    635                                  "<a href='$1$2' class='thumblnk'>$1$2</a>", 
    636                                  htmlspecialchars($args['content']))). 
    637                   '</p>'; 
    638     } 
    639     else if (($args['content_format'] == 'text/html') and ($content_type == 'text/plain')) 
     651    if ($args['content_format'] == 'text/plain' and $content_type == 'text/html') 
     652    { 
     653      // convert plain text to html 
     654      $contents[$content_type].= 
     655        '<p>'. 
     656        nl2br( 
     657          preg_replace( 
     658            '/(https?:\/\/([-\w\.]+[-\w])+(:\d+)?(\/([\w\/_\.\#-]*(\?\S+)?[^\.\s])?)?)/i', 
     659            '<a href="$1">$1</a>', 
     660            htmlspecialchars($args['content']) 
     661            ) 
     662          ). 
     663        '</p>'; 
     664    } 
     665    else if ($args['content_format'] == 'text/html' and $content_type == 'text/plain') 
    640666    { 
    641667      // convert html text to plain text 
     
    654680  unset_make_full_url(); 
    655681 
     682  // Send content to PHPMailer 
    656683  if (isset($contents['text/html'])) 
    657684  { 
    658     $mail->isHTML(true); // Set email format to HTML 
    659     $mail->Body = $contents['text/html']; 
     685    $mail->isHTML(true); 
     686    $mail->Body = move_css_to_body($contents['text/html']); 
    660687     
    661688    if (isset($contents['text/plain'])) 
     
    704731  } 
    705732 
    706   $ret = $mail->send(); 
    707   if(!$ret) 
    708   { 
    709     trigger_error( 'Mailer Error: ' . $mail->ErrorInfo, E_USER_WARNING); 
    710   } 
     733  $ret = true; 
     734  $pre_result = trigger_event('before_send_mail', true, $to, $args, $mail); 
     735 
     736  if ($pre_result) 
     737  { 
     738    $ret = $mail->send(); 
     739    if (!$ret and is_admin()) 
     740    { 
     741      trigger_error('Mailer Error: ' . $mail->ErrorInfo, E_USER_WARNING); 
     742    } 
     743  } 
     744 
    711745  return $ret; 
    712746} 
    713747 
    714 /* DEPRECATED 
    715  * pwg sendmail 
    716  * 
    717  * @param: 
    718  *   - result of other sendmail 
    719  *   - to: Receiver or receiver(s) of the mail. 
    720  *   - subject  [default value 'Piwigo'] 
    721  *   - content: content of mail 
    722  *   - headers: headers of mail 
    723  * 
    724  * @return boolean (Ok or not) 
    725  */ 
    726 function pwg_send_mail($result, $to, $subject, $contents, $headers) 
    727 { 
     748/** 
     749 * @deprecated 2.6 
     750 */ 
     751function pwg_send_mail($result, $to, $subject, $content, $headers) 
     752{ 
     753  trigger_error('pwg_send_mail function is deprecated', E_USER_NOTICE); 
     754   
    728755  if (!$result) 
    729756  { 
    730     include_once(PHPWG_ROOT_PATH.'include/class.phpmailer.php'); 
     757    return pwg_mail($to, array( 
     758        'content' => $content, 
     759        'subject' => $subject, 
     760      )); 
     761  } 
     762  else 
     763  { 
     764    return $result; 
     765  } 
     766} 
     767 
     768/** 
     769 * @deprecated 2.6 
     770 */ 
     771function 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} 
     777 
     778/** 
     779 * Moves CSS rules contained in the <style> tag to inline CSS 
     780 * (for compatibility with Gmail and such clients) 
     781 * @since 2.6 
     782 * @param string $content 
     783 * @return string 
     784 */ 
     785function move_css_to_body($content) 
     786{ 
     787  include_once(PHPWG_ROOT_PATH.'include/emogrifier.class.php'); 
     788 
     789  $e = new Emogrifier($content); 
     790  $e->preserveStyleTag = true; 
     791  return $e->emogrify(); 
     792} 
     793 
     794/** 
     795 * Saves a copy of the mail if _data/tmp 
     796 * @param boolean $result 
     797 * @param string $to 
     798 * @param array $args 
     799 * @param PHPMailer $mail 
     800 * @return boolean $result 
     801 */ 
     802function pwg_send_mail_test($result, $to, $args, $mail) 
     803{ 
     804  global $conf, $user, $lang_info; 
     805   
     806  $dir = PHPWG_ROOT_PATH.$conf['data_location'].'tmp'; 
     807  if (mkgetdir($dir, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR)) 
     808  { 
     809    $filename = $dir.'/mail.'.stripslashes($user['username']).'.'.$lang_info['code'].'.'.$args['theme'].'-'.date('YmdHis'); 
     810    if ($args['content_format'] == 'text/plain') 
     811    { 
     812      $filename .= '.txt'; 
     813    } 
     814    else 
     815    { 
     816      $filename .= '.html'; 
     817    } 
    731818     
    732     global $conf_mail; 
    733  
    734     if ($conf_mail['use_smtp']) 
    735     { 
    736       include_once( PHPWG_ROOT_PATH.'include/class_smtp_mail.inc.php' ); 
    737       $smtp_mail = new smtp_mail( 
    738         $conf_mail['smtp_host'], $conf_mail['smtp_user'], $conf_mail['smtp_password'], 
    739         $conf_mail['email_webmaster']); 
    740       return $smtp_mail->mail($to, $subject, $content, $headers); 
    741     } 
    742     else 
    743     { 
    744       $mail = new PHPMailer; 
    745  
    746       $mail->From = 'plg@pigolabs.com'; 
    747       $mail->FromName = 'Pierrick en local'; 
    748       foreach (explode(',', $to) as $recipient) 
    749       { 
    750         $mail->addAddress($recipient);  // Add a recipient 
    751       } 
    752       // $mail->addReplyTo('plg@piwigo.org', 'Pierrick de Piwigo.org'); 
    753       // $mail->addCC('cc@example.com'); 
    754       // $mail->addBCC('bcc@example.com'); 
    755  
    756       $mail->WordWrap = 76;                                // Set word wrap to 50 characters 
    757  
    758       if (isset($contents['text/html'])) 
    759       { 
    760         $mail->isHTML(true);                                 // Set email format to HTML 
    761         $mail->Body = $contents['text/html']; 
    762  
    763         if (isset($contents['text/plain'])) 
    764         { 
    765           $mail->AltBody = $contents['text/plain']; 
    766         } 
    767       } 
    768       else 
    769       { 
    770         $mail->isHTML(false); 
    771         $mail->Body = $contents['text/plain']; 
    772       } 
    773  
    774       $mail->CharSet = 'UTF-8'; 
    775       $mail->Subject = $subject; 
    776  
    777       if(!$mail->send()) { 
    778         echo 'Message could not be sent.'; 
    779         echo 'Mailer Error: ' . $mail->ErrorInfo; 
    780         exit; 
    781       } 
    782  
    783       // if ($conf_mail['mail_options']) 
    784       // { 
    785       //   $options = '-f '.$conf_mail['email_webmaster']; 
    786       //   return mail($to, $subject, $content, $headers, $options); 
    787       // } 
    788       // else 
    789       // { 
    790       //   return mail($to, $subject, $content, $headers); 
    791       // } 
    792     } 
    793   } 
    794   else 
    795   { 
    796     return $result; 
    797   } 
    798 } 
    799  
    800 function move_ccs_rules_to_body($content) 
    801 { 
    802   return $content; 
    803   // We search all css rules in style tags 
    804   preg_match('#<style>(.*?)</style>#s', $content, $matches); 
    805  
    806   if (!empty($matches[1])) 
    807   { 
    808     preg_match_all('#([^\n]*?)\{(.*?)\}#s', $matches[1], $matches); 
    809  
    810     $selectors = array(); 
    811     $unknow_selectors = ''; 
    812  
    813     foreach ($matches[1] as $key => $value) 
    814     { 
    815       $selects = explode(',', $value); 
    816       $style = trim($matches[2][$key], ' ;'); 
    817  
    818       foreach($selects as $select) 
    819       { 
    820         $select = trim($select); 
    821         $selectors[$select][] = $style; 
    822       } 
    823     } 
    824  
    825     foreach ($selectors as $selector => $style) 
    826     { 
    827       if (!preg_match('/^(#|\.|)([A-Za-z0-9_-]*)$/', $selector, $matches)) 
    828       { 
    829         $unknow_selectors .= $selector.' {'.implode(";\n", $style).";}\n"; 
    830       } 
    831       else switch ($matches[1]) 
    832       { 
    833         case '#': 
    834           $content = preg_replace('|id="'.$matches[2].'"|', 'id="'.$matches[2].'" style="'.implode(";\n", $style).";\"\n", $content); 
    835           break; 
    836         case '.': 
    837           $content = preg_replace('|class="'.$matches[2].'"|', 'class="'.$matches[2].'" style="'.implode(";\n", $style).";\"\n", $content); 
    838           break; 
    839         default: 
    840           $content = preg_replace('#<'.$matches[2].'( |>)#', '<'.$matches[2].' style="'.implode(";\n", $style).";\"\n$1", $content); 
    841           break; 
    842       } 
    843     } 
    844  
    845     // Keep unknow tags in page head 
    846     if (!empty($unknow_selectors)) 
    847     { 
    848       $content = preg_replace('#<style>.*?</style>#s', "<style type=\"text/css\">\n$unknow_selectors</style>", $content); 
    849     } 
    850     else 
    851     { 
    852       $content = preg_replace('#<style>.*?</style>#s', '', $content); 
    853     } 
    854   } 
    855   return $content; 
    856 } 
    857  
    858 /*Testing block*/ 
    859 function pwg_send_mail_test($result, $to, $subject, $content, $headers, $args) 
    860 { 
    861     global $conf, $user, $lang_info; 
    862     $dir = PHPWG_ROOT_PATH.$conf['data_location'].'tmp'; 
    863     if ( mkgetdir( $dir,  MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR) ) 
    864     { 
    865       $filename = $dir.'/mail.'.stripslashes($user['username']).'.'.$lang_info['code'].'.'.$args['theme'].'-'.date('YmdHis'); 
    866       if ($args['content_format'] == 'text/plain') 
    867       { 
    868         $filename .= '.txt'; 
    869       } 
    870       else 
    871       { 
    872         $filename .= '.html'; 
    873       } 
    874       $file = fopen($filename, 'w+'); 
    875       fwrite($file, $to ."\n"); 
    876       fwrite($file, $subject ."\n"); 
    877       fwrite($file, $headers); 
    878       fwrite($file, $content); 
    879       fclose($file); 
    880     } 
    881     return $result; 
    882 } 
     819    $file = fopen($filename, 'w+'); 
     820    fwrite($file, implode(', ', $to) ."\n"); 
     821    fwrite($file, $mail->Subject ."\n"); 
     822    fwrite($file, $mail->createHeader() ."\n"); 
     823    fwrite($file, $mail->createBody()); 
     824    fclose($file); 
     825  } 
     826   
     827  return $result; 
     828} 
     829 
    883830if ($conf['debug_mail']) 
    884   add_event_handler('send_mail', 'pwg_send_mail_test', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 6); 
    885  
    886  
    887 add_event_handler('send_mail', 'pwg_send_mail', EVENT_HANDLER_PRIORITY_NEUTRAL, 5); 
    888 add_event_handler('send_mail_content', 'move_ccs_rules_to_body'); 
     831{ 
     832  add_event_handler('before_send_mail', 'pwg_send_mail_test', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 4); 
     833} 
     834 
    889835trigger_action('functions_mail_included'); 
    890836 
  • trunk/themes/default/template/mail/text/html/footer.tpl

    r5287 r25344  
    1 </div> <!-- content --> 
    2 <div id="copyright"> 
    3 <hr> 
    4   {'Sent by'|@translate} 
    5   <a href="{$GALLERY_URL}">{$GALLERY_TITLE}</a> 
     1            {* <!-- end $CONTENT --> *} 
     2          </td></tr> 
    63 
    7  {* Please, do not remove this copyright. If you really want to, 
    8       contact us on http://piwigo.org to find a solution on how 
    9       to show the origin of the script...*} 
    10   - {'Powered by'|@translate} 
    11   <a href="http://piwigo.org" class="Piwigo"> 
    12   <span class="Piwigo">Piwigo</span></a> 
    13   {$VERSION} 
     4          <tr><td id="footer"> 
     5            {* <!-- begin FOOTER --> *} 
     6{* <!-- Please, do not remove this copyright. If you really want to, 
     7contact us on http://piwigo.org to find a solution on how 
     8to show the origin of the script... --> *} 
     9       
     10            {'Sent by'|translate} <a href="{$GALLERY_URL}">{$GALLERY_TITLE}</a> 
     11            - {'Powered by'|translate} <a href="{$PHPWG_URL}" class="Piwigo">Piwigo</a> 
     12            {if not empty($VERSION)}{$VERSION}{/if} 
     13             
     14            - {'Contact'|translate} 
     15            <a href="mailto:{$CONTACT_MAIL}?subject={'A comment on your site'|translate|escape:url}">{'Webmaster'|@translate}</a> 
     16            {* <!-- end FOOTER --> *} 
     17          </td></tr> 
     18        </table> 
    1419 
    15   - {'Contact'|@translate} 
    16   <a href="mailto:{$MAIL}?subject={$TITLE_MAIL}">{'Webmaster'|@translate}</a> 
    17  
    18 </div> <!-- copyright --> 
    19 </div> <!-- the_page --> 
    20  
    21 </body> 
     20      </td></tr> 
     21    </table> 
     22  </body> 
    2223</html> 
  • trunk/themes/default/template/mail/text/html/global-mail-css.tpl

    r5695 r25344  
    1 /* Global mail css */ 
     1{strip} 
     2/* page */ 
     3body { 
     4  font-family:"Verdana", "Helvetica", "Optima", sans-serif; 
     5  font-size:12px; 
     6  margin:0px; 
     7  padding:0px; 
     8} 
    29 
    3 body {ldelim} font-family: Univers, Helvetica, Optima; font-size:12px; margin:0px; padding:0px; } 
    4 #the_page {ldelim} margin:0px; padding:0px; text-align:left;} 
    5 #content {ldelim} margin:0px; padding:30px 0px 0px 30px; width:732px;} 
    6 hr {ldelim} width:632px; margin-left:0;} 
    7 #copyright {ldelim} font-size:10px; margin:0px; padding:48px 0px 32px 62px;} 
    8 .PWG {ldelim} font-family:verdana, sans-serif !important; font-size:0.9em; font-weight:normal; letter-spacing:0px;} 
    9 h2 {ldelim} padding:7px 15px; width:617px; font-weight:bold;} 
    10 img {ldelim} margin:16px; border:16px solid #aaa; -moz-border-radius: 4px; border-radius: 4px 4px; } 
    11 img:hover {ldelim} padding: 15px; border: 1px solid yellow; -moz-border-radius: 4px; border-radius: 4px 4px; } 
     10html, body, #bodyTable { 
     11  width:100%; 
     12  height:100%; 
     13} 
     14 
     15/* main block */ 
     16#header { 
     17  padding:20px; 
     18} 
     19#header #title { 
     20  font-size:26px; 
     21  font-weight:bold; 
     22} 
     23#header #subtitle { 
     24  font-size:20px; 
     25} 
     26#content { 
     27  padding:0 20px 20px 20px; 
     28} 
     29#footer { 
     30  font-size:10px; 
     31  padding:5px; 
     32} 
     33#topSpacer { 
     34  margin-bottom:20px; 
     35} 
     36 
     37/* images */ 
     38img { 
     39  border:none; 
     40} 
     41 
     42h1, h2, h3, h4, h5 { 
     43  margin:0.5em 0 0.25em 0; 
     44} 
     45h1 { font-size:26px; } 
     46h2 { font-size:20px; } 
     47h3 { font-size:16px; } 
     48h4 { font-size:12px; } 
     49h5 { font-size:10px; } 
     50 
     51/* paragraphs */ 
     52p { 
     53  margin:0.25em 0 0.5em 0; 
     54} 
     55blockquote { 
     56  margin-left:10px; 
     57  padding-left:10px; 
     58  font-family:"Times",serif; 
     59  font-size:14px; 
     60} 
     61 
     62/* list */ 
     63ul, ol { 
     64  margin:0.5em 0 0.25em 30px; 
     65  padding:0; 
     66} 
     67dl { 
     68  margin:0.5em 0 0.25em 10px; 
     69} 
     70dt { 
     71  margin:0.25em 0 0 0; 
     72  font-weight:bold; 
     73} 
     74dd { 
     75  margin:0 0 0.25em 10px; 
     76} 
     77 
     78/* tables */ 
     79#content table { 
     80  width:100%; 
     81  border-spacing:0; 
     82  border-collapse:collapse; 
     83} 
     84#content table td { 
     85  padding:2px 3px; 
     86} 
     87#content table th { 
     88  font-weight:bold; 
     89  text-align:center; 
     90  padding:4px 0; 
     91} 
     92#content table tfoot td { 
     93  font-size:0.8em; 
     94} 
     95 
     96/* line */ 
     97hr { 
     98  border-width:0 0 1px 0; 
     99  border-color:#ddd; 
     100  border-style:solid; 
     101  margin:1em; 
     102} 
     103{/strip} 
  • trunk/themes/default/template/mail/text/html/header.tpl

    r24951 r25344  
    1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
     1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    22<html lang="{$lang_info.code}" dir="{$lang_info.direction}"> 
    3 <head> 
    4 <title>Piwigo Mail</title> 
    5 <meta http-equiv="Content-Type" content="text/html; charset={$CONTENT_ENCODING}"> 
    6 <style><!-- /* Mini style for mails */ 
    7 {if isset($GLOBAL_MAIL_CSS)}{$GLOBAL_MAIL_CSS}{/if} 
    8 {if isset($MAIL_CSS)}{$MAIL_CSS}{/if} 
    9 --></style> 
    10 </head> 
    11 <body> 
    12 <div id="the_page"> 
    13 <div id="content" class="content"> 
     3  <head> 
     4    <meta http-equiv="Content-Type" content="text/html; charset={$CONTENT_ENCODING}"/> 
     5    <title>Piwigo Mail</title> 
     6 
     7    <style type="text/css"> 
     8    {if isset($GLOBAL_MAIL_CSS)}{$GLOBAL_MAIL_CSS}{/if} 
     9    {if isset($MAIL_CSS)}{$MAIL_CSS}{/if} 
     10    </style> 
     11  </head> 
     12 
     13  <body> 
     14    <table id="bodyTable" cellspacing="0" cellpadding="10" border="0"> 
     15      <tr><td align="center" valign="top"> 
     16 
     17        <table id="contentTable" cellspacing="0" cellpadding="0" border="0"> 
     18          <tr><td id="header"> 
     19            {* <!-- begin HEADER --> *} 
     20            <div id="title">{$MAIL_TITLE}</div> 
     21            {if not empty($MAIL_SUBTITLE)}<div id="subtitle">{$MAIL_SUBTITLE}</div>{/if} 
     22            {* <!-- end HEADER --> *} 
     23          </td></tr> 
     24 
     25          <tr><td id="content"> 
     26{* <!-- use an invisible div with a bottom margin to force the browser  
     27to merge the margin with the element bellow (typically h1/h2/...) --> *} 
     28            <div id="topSpacer"></div> 
     29            {* <!-- begin CONTENT --> *} 
  • trunk/themes/default/template/mail/text/plain/footer.tpl

    r9354 r25344  
     1{literal} 
    12 
    2 --  
     3{/literal} 
     4---- 
    35{'Sent by'|@translate} "{$GALLERY_TITLE}" {$GALLERY_URL} 
    4 {'Contact'|@translate} {$MAIL} 
    5 {'Powered by'|@translate} Piwigo {$VERSION} 
     6{'Powered by'|@translate} "Piwigo{if not empty($VERSION)} {$VERSION}{/if}" {$PHPWG_URL} 
     7{'Contact'|@translate}: {$CONTACT_MAIL} 
  • trunk/themes/default/template/mail/text/plain/header.tpl

    r24951 r25344  
     1{$MAIL_TITLE} 
     2{if not empty($MAIL_SUBTITLE)}{$MAIL_SUBTITLE} 
     3{/if} 
     4---- 
    15{literal} 
    2  
    3 {/literal}{*note that there must be an empty line to separate the mime headers*} 
     6{/literal} 
Note: See TracChangeset for help on using the changeset viewer.