summaryrefslogtreecommitdiff
path: root/inc/common.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2012-04-20 12:03:03 +0200
committerAndreas Gohr <andi@splitbrain.org>2012-04-20 12:03:03 +0200
commitc67addf8c8a91cb62cdadb0f39683cdf0e2ea9fd (patch)
treeb583681b3898684590af39a2fc0a0446169e3cad /inc/common.php
parent2f85287ef7aafab72cec14c85c1ab4cd1d7facc9 (diff)
parent8aea63819532f5f49c22a3a225e18eb2640f1d71 (diff)
downloadrpg-c67addf8c8a91cb62cdadb0f39683cdf0e2ea9fd.tar.gz
rpg-c67addf8c8a91cb62cdadb0f39683cdf0e2ea9fd.tar.bz2
Merge branch 'htmlmail'
* htmlmail: (26 commits) changed internal Mailer members from private to protected made it possible to disable HTML mails in the config removed commented code left from the quoted_printable days add missing table tags for HTML diff mails fixed subscriber mail signatures use real HRs in HTML mails Add various headers to the mails FS#2247. pull request #83 closed removed footer image from HTML mails use inlinestyles for diffs in HTML mails fixed signature stripping fixed mailprefix handling fixed missing replacement for HTML notify mails allow image embeds in HTML mail templates Added HTML wrapper for mails allow non-txt extensions when accessing locales added Mailer class to autoloader Replaced mail_send calls with new Mailer class Make use of new Mailer class in notify() Copy all text replacements to HTML replacements in Mailer Added setBody() to Mailer class ...
Diffstat (limited to 'inc/common.php')
-rw-r--r--inc/common.php90
1 files changed, 48 insertions, 42 deletions
diff --git a/inc/common.php b/inc/common.php
index 0a75f2eab..22a315901 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -789,8 +789,8 @@ function formText($text){
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function rawLocale($id){
- return io_readFile(localeFN($id));
+function rawLocale($id,$ext='txt'){
+ return io_readFile(localeFN($id,$ext));
}
/**
@@ -1086,8 +1086,9 @@ function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){
global $lang;
global $conf;
global $INFO;
+ global $DIFF_INLINESTYLES;
- // decide if there is something to do
+ // decide if there is something to do, eg. whom to mail
if($who == 'admin'){
if(empty($conf['notify'])) return; //notify enabled?
$text = rawLocale('mailtext');
@@ -1112,49 +1113,54 @@ function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){
return; //just to be safe
}
- $ip = clientIP();
- $text = str_replace('@DATE@',dformat(),$text);
- $text = str_replace('@BROWSER@',$_SERVER['HTTP_USER_AGENT'],$text);
- $text = str_replace('@IPADDRESS@',$ip,$text);
- $text = str_replace('@HOSTNAME@',gethostsbyaddrs($ip),$text);
- $text = str_replace('@NEWPAGE@',wl($id,'',true,'&'),$text);
- $text = str_replace('@PAGE@',$id,$text);
- $text = str_replace('@TITLE@',$conf['title'],$text);
- $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text);
- $text = str_replace('@SUMMARY@',$summary,$text);
- $text = str_replace('@USER@',$_SERVER['REMOTE_USER'],$text);
- $text = str_replace('@NAME@',$INFO['userinfo']['name'],$text);
- $text = str_replace('@MAIL@',$INFO['userinfo']['mail'],$text);
-
- foreach ($replace as $key => $substitution) {
- $text = str_replace('@'.strtoupper($key).'@',$substitution, $text);
- }
+ // prepare replacements (keys not set in hrep will be taken from trep)
+ $trep = array(
+ 'NEWPAGE' => wl($id,'',true,'&'),
+ 'PAGE' => $id,
+ 'SUMMARY' => $summary
+ );
+ $trep = array_merge($trep,$replace);
+ $hrep = array();
+ // prepare content
if($who == 'register'){
- $subject = $lang['mail_new_user'].' '.$summary;
+ $subject = $lang['mail_new_user'].' '.$summary;
}elseif($rev){
- $subject = $lang['mail_changed'].' '.$id;
- $text = str_replace('@OLDPAGE@',wl($id,"rev=$rev",true,'&'),$text);
- $df = new Diff(explode("\n",rawWiki($id,$rev)),
- explode("\n",rawWiki($id)));
- $dformat = new UnifiedDiffFormatter();
- $diff = $dformat->format($df);
+ $subject = $lang['mail_changed'].' '.$id;
+ $trep['OLDPAGE'] = wl($id,"rev=$rev",true,'&');
+ $df = new Diff(explode("\n",rawWiki($id,$rev)),
+ explode("\n",rawWiki($id)));
+ $dformat = new UnifiedDiffFormatter();
+ $tdiff = $dformat->format($df);
+
+ $DIFF_INLINESTYLES = true;
+ $dformat = new InlineDiffFormatter();
+ $hdiff = $dformat->format($df);
+ $hdiff = '<table>'.$hdiff.'</table>';
+ $DIFF_INLINESTYLES = false;
}else{
- $subject=$lang['mail_newpage'].' '.$id;
- $text = str_replace('@OLDPAGE@','none',$text);
- $diff = rawWiki($id);
- }
- $text = str_replace('@DIFF@',$diff,$text);
- if(empty($conf['mailprefix'])) {
- if(utf8_strlen($conf['title']) < 20) {
- $subject = '['.$conf['title'].'] '.$subject;
- }else{
- $subject = '['.utf8_substr($conf['title'], 0, 20).'...] '.$subject;
- }
- }else{
- $subject = '['.$conf['mailprefix'].'] '.$subject;
- }
- mail_send($to,$subject,$text,$conf['mailfrom'],'',$bcc);
+ $subject = $lang['mail_newpage'].' '.$id;
+ $trep['OLDPAGE'] = '---';
+ $tdiff = rawWiki($id);
+ $hdiff = nl2br(hsc($tdiff));
+ }
+ $trep['DIFF'] = $tdiff;
+ $hrep['DIFF'] = $hdiff;
+
+ // send mail
+ $mail = new Mailer();
+ $mail->to($to);
+ $mail->bcc($bcc);
+ $mail->subject($subject);
+ $mail->setBody($text,$trep,$hrep);
+ if($who == 'subscribers'){
+ $mail->setHeader(
+ 'List-Unsubscribe',
+ '<'.wl($id,array('do'=>'subscribe'),true,'&').'>',
+ false
+ );
+ }
+ return $mail->send();
}
/**