diff options
author | Andreas Gohr <andi@splitbrain.org> | 2011-11-13 13:06:07 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2011-11-13 13:06:07 +0100 |
commit | 850dbf1f4b1e2bdee8b2e5f0438a5625d0a1bedf (patch) | |
tree | 61591f405fce05acd259512b2522813170c47a8c /inc/Mailer.class.php | |
parent | f08086ec453c4529ae7361f9540b430ee61238f0 (diff) | |
download | rpg-850dbf1f4b1e2bdee8b2e5f0438a5625d0a1bedf.tar.gz rpg-850dbf1f4b1e2bdee8b2e5f0438a5625d0a1bedf.tar.bz2 |
allow image embeds in HTML mail templates
Using the place holder @MEDIA(<mediaid>)@ you now can directly embed
images from the media repository into your HTML mail template.
An example was added to the mailwrap.html, but because images are
embedded as is (no prescaling) this is suboptimal. If we keep it, a
smaller version of the DokuWiki logo should be shipped with DokuWiki.
Diffstat (limited to 'inc/Mailer.class.php')
-rw-r--r-- | inc/Mailer.class.php | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/inc/Mailer.class.php b/inc/Mailer.class.php index cdd4b266a..7e6889292 100644 --- a/inc/Mailer.class.php +++ b/inc/Mailer.class.php @@ -87,6 +87,24 @@ class Mailer { } /** + * Callback function to automatically embed images referenced in HTML templates + */ + protected function autoembed_cb($matches){ + static $embeds = 0; + $embeds++; + + // get file and mime type + $media = cleanID($matches[1]); + list($ext, $mime) = mimetype($media); + $file = mediaFN($media); + if(!file_exists($file)) return $matches[0]; //bad reference, keep as is + + // attach it and set placeholder + $this->attachFile($file,$mime,'','autoembed'.$embeds); + return '%%autoembed'.$embeds.'%%'; + } + + /** * Add an arbitrary header to the mail * * If an empy value is passed, the header is removed @@ -163,6 +181,10 @@ class Mailer { } } + // embed media from templates + $html = preg_replace_callback('/@MEDIA\(([^\)]+)\)@/', + array($this,'autoembed_cb'),$html); + // prepare default replacements $ip = clientIP(); $cip = gethostsbyaddrs($ip); |