Changeset 5695 for trunk/include/functions_mail.inc.php
- Timestamp:
- Apr 7, 2010, 10:09:30 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_mail.inc.php
r5208 r5695 772 772 } 773 773 774 function move_ccs_rules_to_body($content) 775 { 776 // We search all css rules in style tags 777 preg_match('#<style>(.*?)</style>#s', $content, $matches); 778 779 if (!empty($matches[1])) 780 { 781 preg_match_all('#([^\n]*?)\{(.*?)\}#s', $matches[1], $matches); 782 783 $selectors = array(); 784 $unknow_selectors = ''; 785 786 foreach ($matches[1] as $key => $value) 787 { 788 $selects = explode(',', $value); 789 $style = trim($matches[2][$key], ' ;'); 790 791 foreach($selects as $select) 792 { 793 $select = trim($select); 794 $selectors[$select][] = $style; 795 } 796 } 797 foreach ($selectors as $selector => $style) 798 { 799 if (!preg_match('/^(#|\.|)([A-Za-z0-9_-]*)$/', $selector, $matches)) 800 { 801 $unknow_selectors .= $selector.' {'.implode('; ', $style).";}\n"; 802 } 803 else switch ($matches[1]) 804 { 805 case '#': 806 $content = preg_replace('|id="'.$matches[2].'"|', 'id="'.$matches[2].'" style="'.implode('; ', $style).';"', $content); 807 break; 808 case '.': 809 $content = preg_replace('|class="'.$matches[2].'"|', 'class="'.$matches[2].'" style="'.implode('; ', $style).';"', $content); 810 break; 811 default: 812 $content = preg_replace('#<'.$matches[2].'( |>)#', '<'.$matches[2].' style="'.implode('; ', $style).';"$1', $content); 813 break; 814 } 815 } 816 817 // Keep unknow tags in page head 818 if (!empty($unknow_selectors)) 819 { 820 $content = preg_replace('#<style>.*?</style>#s', "<style type=\"text/css\">\n$unknow_selectors</style>", $content); 821 } 822 else 823 { 824 $content = preg_replace('#<style>.*?</style>#s', '', $content); 825 } 826 } 827 return $content; 828 } 829 774 830 /*Testing block*/ 775 831 /*function pwg_send_mail_test($result, $to, $subject, $content, $headers, $args) … … 801 857 802 858 add_event_handler('send_mail', 'pwg_send_mail', EVENT_HANDLER_PRIORITY_NEUTRAL, 5); 859 add_event_handler('send_mail_content', 'move_ccs_rules_to_body'); 803 860 trigger_action('functions_mail_included'); 804 861
Note: See TracChangeset
for help on using the changeset viewer.