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

Last change on this file since 19703 was 19703, checked in by plg, 11 years ago

update Piwigo headers to 2013 (the end of the world didn't occur as expected on r12922)

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