aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions_mail.inc.php
diff options
context:
space:
mode:
authorpatdenice <patdenice@piwigo.org>2010-04-07 08:09:30 +0000
committerpatdenice <patdenice@piwigo.org>2010-04-07 08:09:30 +0000
commite5f8722c33abf20d91e53324bc41425b7bf42c59 (patch)
tree0f33612da768164d9690036d60a64b10df10036a /include/functions_mail.inc.php
parent05fa1c12f704e350db6e3a1a4818e2669a5db2a1 (diff)
Fix some issues on NBM: move css rules to mail body if it's possible.
Remove fieldset on available plugins page. git-svn-id: http://piwigo.org/svn/trunk@5695 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/functions_mail.inc.php')
-rw-r--r--include/functions_mail.inc.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php
index 5322e2165..e2aa9ceae 100644
--- a/include/functions_mail.inc.php
+++ b/include/functions_mail.inc.php
@@ -771,6 +771,62 @@ function pwg_send_mail($result, $to, $subject, $content, $headers)
}
}
+function move_ccs_rules_to_body($content)
+{
+ // We search all css rules in style tags
+ preg_match('#<style>(.*?)</style>#s', $content, $matches);
+
+ if (!empty($matches[1]))
+ {
+ preg_match_all('#([^\n]*?)\{(.*?)\}#s', $matches[1], $matches);
+
+ $selectors = array();
+ $unknow_selectors = '';
+
+ foreach ($matches[1] as $key => $value)
+ {
+ $selects = explode(',', $value);
+ $style = trim($matches[2][$key], ' ;');
+
+ foreach($selects as $select)
+ {
+ $select = trim($select);
+ $selectors[$select][] = $style;
+ }
+ }
+ foreach ($selectors as $selector => $style)
+ {
+ if (!preg_match('/^(#|\.|)([A-Za-z0-9_-]*)$/', $selector, $matches))
+ {
+ $unknow_selectors .= $selector.' {'.implode('; ', $style).";}\n";
+ }
+ else switch ($matches[1])
+ {
+ case '#':
+ $content = preg_replace('|id="'.$matches[2].'"|', 'id="'.$matches[2].'" style="'.implode('; ', $style).';"', $content);
+ break;
+ case '.':
+ $content = preg_replace('|class="'.$matches[2].'"|', 'class="'.$matches[2].'" style="'.implode('; ', $style).';"', $content);
+ break;
+ default:
+ $content = preg_replace('#<'.$matches[2].'( |>)#', '<'.$matches[2].' style="'.implode('; ', $style).';"$1', $content);
+ break;
+ }
+ }
+
+ // Keep unknow tags in page head
+ if (!empty($unknow_selectors))
+ {
+ $content = preg_replace('#<style>.*?</style>#s', "<style type=\"text/css\">\n$unknow_selectors</style>", $content);
+ }
+ else
+ {
+ $content = preg_replace('#<style>.*?</style>#s', '', $content);
+ }
+ }
+ return $content;
+}
+
/*Testing block*/
/*function pwg_send_mail_test($result, $to, $subject, $content, $headers, $args)
{
@@ -800,6 +856,7 @@ add_event_handler('send_mail', 'pwg_send_mail_test', EVENT_HANDLER_PRIORITY_NEUT
add_event_handler('send_mail', 'pwg_send_mail', EVENT_HANDLER_PRIORITY_NEUTRAL, 5);
+add_event_handler('send_mail_content', 'move_ccs_rules_to_body');
trigger_action('functions_mail_included');
?>