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

Last change on this file since 24835 was 23823, checked in by mistic100, 11 years ago

bug:2939 switch_lang_to() must reload plugins files

  • Property svn:eol-style set to LF
File size: 23.1 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, $language_files;
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   
228    if (!empty($language_files))
229    {
230      foreach ($language_files as $dirname => $files)
231        foreach ($files as $filename)
232          load_language($filename, $dirname, array('language'=>$language) );
233    }
234   
235    trigger_action('loading_lang');
236    load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR,
237      array('language'=>$language, 'no_fallback'=>true, 'local'=>true)
238    );
239
240    $switch_lang['language'][$language]['lang_info'] = $lang_info;
241    $switch_lang['language'][$language]['lang'] = $lang;
242  }
243  else
244  {
245    $lang_info = $switch_lang['language'][$language]['lang_info'];
246    $lang = $switch_lang['language'][$language]['lang'];
247  }
248}
249
250/*
251 * Switch back language pushed with switch_lang_to function
252 *
253 * @param: none
254 */
255function switch_lang_back()
256{
257  global $switch_lang, $user, $lang, $lang_info;
258
259  if (count($switch_lang['stack']) > 0)
260  {
261    // Get last value
262    $language = array_pop($switch_lang['stack']);
263
264    // Change current infos
265    if (isset($switch_lang['language'][$language]))
266    {
267      $lang_info = $switch_lang['language'][$language]['lang_info'];
268      $lang = $switch_lang['language'][$language]['lang'];
269    }
270    $user['language'] = $language;
271  }
272}
273
274/**
275 * Returns email of all administrator
276 *
277 * @return string
278 */
279/*
280 * send en notification email to all administrators
281 * if a administrator is doing action,
282 * he's be removed to email list
283 *
284 * @param:
285 *   - keyargs_subject: mail subject on l10n_args format
286 *   - keyargs_content: mail content on l10n_args format
287 *   - send_technical_details: send user IP and browser
288 *
289 * @return boolean (Ok or not)
290 */
291function pwg_mail_notification_admins($keyargs_subject, $keyargs_content, $send_technical_details=true)
292{
293  global $conf, $user;
294 
295  // Check arguments
296  if (empty($keyargs_subject) or empty($keyargs_content))
297  {
298    return false;
299  }
300
301  $return = true;
302
303  $admins = array();
304
305  $query = '
306SELECT
307    u.'.$conf['user_fields']['username'].' AS username,
308    u.'.$conf['user_fields']['email'].' AS mail_address
309  FROM '.USERS_TABLE.' AS u
310    JOIN '.USER_INFOS_TABLE.' AS i ON i.user_id =  u.'.$conf['user_fields']['id'].'
311  WHERE i.status in (\'webmaster\',  \'admin\')
312    AND '.$conf['user_fields']['email'].' IS NOT NULL
313    AND i.user_id <> '.$user['id'].'
314  ORDER BY username
315;';
316
317  $datas = pwg_query($query);
318  if (!empty($datas))
319  {
320    while ($admin = pwg_db_fetch_assoc($datas))
321    {
322      if (!empty($admin['mail_address']))
323      {
324        array_push($admins, format_email($admin['username'], $admin['mail_address']));
325      }
326    }
327  }
328
329  if (count($admins) > 0)
330  {
331    switch_lang_to(get_default_language());
332
333    $content = l10n_args($keyargs_content)."\n";
334    if ($send_technical_details)
335    {
336      $keyargs_content_admin_info = array(
337        get_l10n_args('Connected user: %s', stripslashes($user['username'])),
338        get_l10n_args('IP: %s', $_SERVER['REMOTE_ADDR']),
339        get_l10n_args('Browser: %s', $_SERVER['HTTP_USER_AGENT'])
340        );
341     
342      $content.= "\n".l10n_args($keyargs_content_admin_info)."\n";
343    }
344
345    $return = pwg_mail(
346      implode(', ', $admins),
347      array(
348        'subject' => '['.$conf['gallery_title'].'] '.l10n_args($keyargs_subject),
349        'content' => $content,
350        'content_format' => 'text/plain',
351        'email_format' => 'text/plain',
352        )
353      );
354   
355    switch_lang_back();
356  }
357
358  return $return;
359}
360
361/*
362 * send en email to user's group
363 *
364 * @param:
365 *   - group_id: mail are sent to group with this Id
366 *   - email_format: mail format
367 *   - keyargs_subject: mail subject on l10n_args format
368 *   - tpl_shortname: short template name without extension
369 *   - assign_vars: array used to assign_vars to mail template
370 *   - language_selected: send mail only to user with this selected language
371 *
372 * @return boolean (Ok or not)
373 */
374function pwg_mail_group(
375  $group_id, $email_format, $keyargs_subject,
376  $tpl_shortname,
377  $assign_vars = array(), $language_selected = '')
378{
379  // Check arguments
380  if
381    (
382      empty($group_id) or
383      empty($email_format) or
384      empty($keyargs_subject) or
385      empty($tpl_shortname)
386    )
387  {
388    return false;
389  }
390
391  global $conf;
392  $return = true;
393
394  $query = '
395SELECT
396  distinct language, theme
397FROM
398  '.USER_GROUP_TABLE.' as ug
399  INNER JOIN '.USERS_TABLE.' as u  ON '.$conf['user_fields']['id'].' = ug.user_id
400  INNER JOIN '.USER_INFOS_TABLE.' as ui  ON ui.user_id = ug.user_id
401WHERE
402        '.$conf['user_fields']['email'].' IS NOT NULL
403    AND group_id = '.$group_id;
404
405  if (!empty($language_selected))
406  {
407    $query .= '
408    AND language = \''.$language_selected.'\'';
409  }
410
411    $query .= '
412;';
413
414  $result = pwg_query($query);
415
416  if (pwg_db_num_rows($result) > 0)
417  {
418    $list = array();
419    while ($row = pwg_db_fetch_assoc($result))
420    {
421      $list[] = $row;
422    }
423
424    foreach ($list as $elem)
425    {
426      $query = '
427SELECT
428  u.'.$conf['user_fields']['username'].' as username,
429  u.'.$conf['user_fields']['email'].' as mail_address
430FROM
431  '.USER_GROUP_TABLE.' as ug
432  INNER JOIN '.USERS_TABLE.' as u  ON '.$conf['user_fields']['id'].' = ug.user_id
433  INNER JOIN '.USER_INFOS_TABLE.' as ui  ON ui.user_id = ug.user_id
434WHERE
435        '.$conf['user_fields']['email'].' IS NOT NULL
436    AND group_id = '.$group_id.'
437    AND language = \''.$elem['language'].'\'
438    AND theme = \''.$elem['theme'].'\'
439;';
440
441      $result = pwg_query($query);
442
443      if (pwg_db_num_rows($result) > 0)
444      {
445        $Bcc = array();
446        while ($row = pwg_db_fetch_assoc($result))
447        {
448          if (!empty($row['mail_address']))
449          {
450            array_push($Bcc, format_email(stripslashes($row['username']), $row['mail_address']));
451          }
452        }
453
454        if (count($Bcc) > 0)
455        {
456          switch_lang_to($elem['language']);
457
458          $mail_template = get_mail_template($email_format, $elem['theme']);
459          $mail_template->set_filename($tpl_shortname, $tpl_shortname.'.tpl');
460
461          $mail_template->assign(
462            trigger_event('mail_group_assign_vars', $assign_vars));
463
464          $return = pwg_mail
465          (
466            '',
467            array
468            (
469              'Bcc' => $Bcc,
470              'subject' => l10n_args($keyargs_subject),
471              'email_format' => $email_format,
472              'content' => $mail_template->parse($tpl_shortname, true),
473              'content_format' => $email_format,
474              'theme' => $elem['theme']
475            )
476          ) and $return;
477
478          switch_lang_back();
479        }
480      }
481    }
482  }
483
484  return $return;
485}
486
487/*
488 * sends an email, using Piwigo specific informations
489 *
490 * @param:
491 *   - to: receiver(s) of the mail (list separated by comma).
492 *   - args: function params of mail function:
493 *       o from: sender [default value webmaster email]
494 *       o Cc: array of carbon copy receivers of the mail. [default value empty]
495 *       o Bcc: array of blind carbon copy receivers of the mail. [default value empty]
496 *       o subject  [default value 'Piwigo']
497 *       o content: content of mail    [default value '']
498 *       o content_format: format of mail content  [default value 'text/plain']
499 *       o email_format: global mail format  [default value $conf_mail['default_email_format']]
500 *       o theme: template to use [default get_default_theme()]
501 *
502 * @return boolean (Ok or not)
503 */
504function pwg_mail($to, $args = array())
505{
506  global $conf, $conf_mail, $lang_info, $page;
507
508  if (empty($to) and empty($args['Cc']) and empty($args['Bcc']))
509  {
510    return true;
511  }
512
513  if (!isset($conf_mail))
514  {
515    $conf_mail = get_mail_configuration();
516  }
517
518  if (empty($args['email_format']))
519  {
520    $args['email_format'] = $conf_mail['default_email_format'];
521  }
522
523  // Compute root_path in order have complete path
524  set_make_full_url();
525
526  if (empty($args['from']))
527  {
528    $args['from'] = $conf_mail['formated_email_webmaster'];
529  }
530  else
531  {
532    $args['from'] = format_email('', $args['from']);
533  }
534
535  if (empty($args['subject']))
536  {
537    $args['subject'] = 'Piwigo';
538  }
539  // Spring cleaning
540  $cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject']));
541  // Ascii convertion
542  $cvt_subject = encode_mime_header($cvt_subject);
543
544  if (!isset($args['content']))
545  {
546    $args['content'] = '';
547  }
548
549  if (empty($args['content_format']))
550  {
551    $args['content_format'] = 'text/plain';
552  }
553
554  if ($conf_mail['send_bcc_mail_webmaster'])
555  {
556    $args['Bcc'][] = $conf_mail['formated_email_webmaster'];
557  }
558
559  if (empty($args['theme']))
560  {
561    $args['theme'] = get_default_theme();
562  }
563
564  $headers = 'From: '.$args['from']."\n";
565  $headers.= 'Reply-To: '.$args['from']."\n";
566
567  if (!empty($args['Cc']))
568  {
569    $headers.= 'Cc: '.implode(',', $args['Cc'])."\n";
570  }
571
572  if (!empty($args['Bcc']))
573  {
574    $headers.= 'Bcc: '.implode(',', $args['Bcc'])."\n";
575  }
576
577  $headers.= 'Content-Type: multipart/alternative;'."\n";
578  $headers.= '  boundary="---='.$conf_mail['boundary_key'].'";'."\n";
579  $headers.= '  reply-type=original'."\n";
580  $headers.= 'MIME-Version: 1.0'."\n";
581  $headers.= 'X-Mailer: Piwigo Mailer'."\n";
582
583  // List on content-type
584  $content_type_list[] = $args['email_format'];
585  if (!empty($conf_mail['alternative_email_format']))
586  {
587    $content_type_list[] = $conf_mail['alternative_email_format'];
588  }
589
590  $content = '';
591
592  foreach (array_unique($content_type_list) as $content_type)
593  {
594    // key compose of indexes witch allow ti cache mail data
595    $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme'];
596
597    if (!isset($conf_mail[$cache_key]))
598    {
599      if (!isset($conf_mail[$cache_key]['theme']))
600      {
601        $conf_mail[$cache_key]['theme'] = get_mail_template($content_type, $args['theme']);
602      }
603
604      $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl');
605      $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl');
606
607      $conf_mail[$cache_key]['theme']->assign(
608        array(
609          //Header
610          'BOUNDARY_KEY' => $conf_mail['boundary_key'],
611          'CONTENT_TYPE' => $content_type,
612          'CONTENT_ENCODING' => get_pwg_charset(),
613
614          // Footer
615          'GALLERY_URL' => get_gallery_home_url(),
616          'GALLERY_TITLE' =>
617            isset($page['gallery_title']) ?
618                  $page['gallery_title'] : $conf['gallery_title'],
619          'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '',
620          'PHPWG_URL' => PHPWG_URL,
621
622          'TITLE_MAIL' => urlencode(l10n('A comment on your site')),
623          'MAIL' => get_webmaster_mail_address()
624          ));
625
626      if ($content_type == 'text/html')
627      {
628        if ($conf_mail[$cache_key]['theme']->smarty->template_exists('global-mail-css.tpl'))
629        {
630          $conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl');
631          $conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css');
632        }
633
634        $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl';
635        if (is_file($file))
636        {
637          $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file));
638          $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css');
639        }
640      }
641
642      // what are displayed on the header of each mail ?
643      $conf_mail[$cache_key]['header'] =
644        $conf_mail[$cache_key]['theme']->parse('mail_header', true);
645
646      // what are displayed on the footer of each mail ?
647      $conf_mail[$cache_key]['footer'] =
648        $conf_mail[$cache_key]['theme']->parse('mail_footer', true);
649    }
650
651    // Header
652    $content.= $conf_mail[$cache_key]['header'];
653
654    // Content
655    if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html'))
656    {
657      $content.= '<p>'.
658                  nl2br(
659                    preg_replace("/(http:\/\/)([^\s,]*)/i",
660                                 "<a href='$1$2' class='thumblnk'>$1$2</a>",
661                                 htmlspecialchars($args['content']))).
662                  '</p>';
663    }
664    else if (($args['content_format'] == 'text/html') and ($content_type == 'text/plain'))
665    {
666      // convert html text to plain text
667      $content.= strip_tags($args['content']);
668    }
669    else
670    {
671      $content.= $args['content'];
672    }
673
674    // Footer
675    $content.= $conf_mail[$cache_key]['footer'];
676
677  // Close boundary
678  $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
679  }
680
681  //~ // Close boundary
682  //~ $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
683
684   // Undo Compute root_path in order have complete path
685  unset_make_full_url();
686
687  return
688    trigger_event('send_mail',
689      false, /* Result */
690      trigger_event('send_mail_to', get_strict_email_list($to)),
691      trigger_event('send_mail_subject', $cvt_subject),
692      trigger_event('send_mail_content', $content),
693      trigger_event('send_mail_headers', $headers),
694      $args
695    );
696}
697
698/*
699 * pwg sendmail
700 *
701 * @param:
702 *   - result of other sendmail
703 *   - to: Receiver or receiver(s) of the mail.
704 *   - subject  [default value 'Piwigo']
705 *   - content: content of mail
706 *   - headers: headers of mail
707 *
708 * @return boolean (Ok or not)
709 */
710function pwg_send_mail($result, $to, $subject, $content, $headers)
711{
712  if (!$result)
713  {
714    global $conf_mail;
715
716    if ($conf_mail['use_smtp'])
717    {
718      include_once( PHPWG_ROOT_PATH.'include/class_smtp_mail.inc.php' );
719      $smtp_mail = new smtp_mail(
720        $conf_mail['smtp_host'], $conf_mail['smtp_user'], $conf_mail['smtp_password'],
721        $conf_mail['email_webmaster']);
722      return $smtp_mail->mail($to, $subject, $content, $headers);
723    }
724    else
725    {
726      if ($conf_mail['mail_options'])
727      {
728        $options = '-f '.$conf_mail['email_webmaster'];
729        return mail($to, $subject, $content, $headers, $options);
730      }
731      else
732      {
733        return mail($to, $subject, $content, $headers);
734      }
735    }
736  }
737  else
738  {
739    return $result;
740  }
741}
742
743function move_ccs_rules_to_body($content)
744{
745  // We search all css rules in style tags
746  preg_match('#<style>(.*?)</style>#s', $content, $matches);
747
748  if (!empty($matches[1]))
749  {
750    preg_match_all('#([^\n]*?)\{(.*?)\}#s', $matches[1], $matches);
751
752    $selectors = array();
753    $unknow_selectors = '';
754
755    foreach ($matches[1] as $key => $value)
756    {
757      $selects = explode(',', $value);
758      $style = trim($matches[2][$key], ' ;');
759
760      foreach($selects as $select)
761      {
762        $select = trim($select);
763        $selectors[$select][] = $style;
764      }
765    }
766
767    foreach ($selectors as $selector => $style)
768    {
769      if (!preg_match('/^(#|\.|)([A-Za-z0-9_-]*)$/', $selector, $matches))
770      {
771        $unknow_selectors .= $selector.' {'.implode(";\n", $style).";}\n";
772      }
773      else switch ($matches[1])
774      {
775        case '#':
776          $content = preg_replace('|id="'.$matches[2].'"|', 'id="'.$matches[2].'" style="'.implode(";\n", $style).";\"\n", $content);
777          break;
778        case '.':
779          $content = preg_replace('|class="'.$matches[2].'"|', 'class="'.$matches[2].'" style="'.implode(";\n", $style).";\"\n", $content);
780          break;
781        default:
782          $content = preg_replace('#<'.$matches[2].'( |>)#', '<'.$matches[2].' style="'.implode(";\n", $style).";\"\n$1", $content);
783          break;
784      }
785    }
786
787    // Keep unknow tags in page head
788    if (!empty($unknow_selectors))
789    {
790      $content = preg_replace('#<style>.*?</style>#s', "<style type=\"text/css\">\n$unknow_selectors</style>", $content);
791    }
792    else
793    {
794      $content = preg_replace('#<style>.*?</style>#s', '', $content);
795    }
796  }
797  return $content;
798}
799
800/*Testing block*/
801function pwg_send_mail_test($result, $to, $subject, $content, $headers, $args)
802{
803    global $conf, $user, $lang_info;
804    $dir = PHPWG_ROOT_PATH.$conf['data_location'].'tmp';
805    if ( mkgetdir( $dir,  MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR) )
806    {
807      $filename = $dir.'/mail.'.stripslashes($user['username']).'.'.$lang_info['code'].'.'.$args['theme'].'-'.date('YmdHis');
808      if ($args['content_format'] == 'text/plain')
809      {
810        $filename .= '.txt';
811      }
812      else
813      {
814        $filename .= '.html';
815      }
816      $file = fopen($filename, 'w+');
817      fwrite($file, $to ."\n");
818      fwrite($file, $subject ."\n");
819      fwrite($file, $headers);
820      fwrite($file, $content);
821      fclose($file);
822    }
823    return $result;
824}
825if ($conf['debug_mail'])
826  add_event_handler('send_mail', 'pwg_send_mail_test', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 6);
827
828
829add_event_handler('send_mail', 'pwg_send_mail', EVENT_HANDLER_PRIORITY_NEUTRAL, 5);
830add_event_handler('send_mail_content', 'move_ccs_rules_to_body');
831trigger_action('functions_mail_included');
832
833?>
Note: See TracBrowser for help on using the repository browser.