source: trunk/include/functions_mail.inc.php @ 8722

Last change on this file since 8722 was 8722, checked in by plg, 13 years ago

feature 2112 added: ability to set an additional local directory
$conflocal_dir_site in local/config/multisite.inc.php

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