From 7503035957fa441a0911bd9f96dc4f554875123a Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Mon, 12 Feb 2007 20:02:16 +0100 Subject: [PATCH] send notify mails for uploaded files darcs-hash:20070212190216-7ad00-7be9443a13ab0e885e569f4bdae166fcd00ab836.gz --- inc/lang/en/lang.php | 7 ++++--- inc/lang/en/uploadmail.txt | 14 ++++++++++++++ inc/media.php | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 inc/lang/en/uploadmail.txt diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php index 20f6f43c7..aa0aad6e0 100644 --- a/inc/lang/en/lang.php +++ b/inc/lang/en/lang.php @@ -140,9 +140,10 @@ $lang['restored'] = 'old revision restored'; $lang['external_edit'] = 'external edit'; $lang['summary'] = 'Edit summary'; -$lang['mail_newpage'] = 'page added:'; -$lang['mail_changed'] = 'page changed:'; -$lang['mail_new_user'] = 'New user:'; +$lang['mail_newpage'] = 'page added:'; +$lang['mail_changed'] = 'page changed:'; +$lang['mail_new_user'] = 'new user:'; +$lang['mail_upload'] = 'file uploaded:'; $lang['nosmblinks'] = 'Linking to Windows shares only works in Microsoft Internet Explorer.\nYou still can copy and paste the link.'; diff --git a/inc/lang/en/uploadmail.txt b/inc/lang/en/uploadmail.txt new file mode 100644 index 000000000..b725cf827 --- /dev/null +++ b/inc/lang/en/uploadmail.txt @@ -0,0 +1,14 @@ +A file was uploaded to your DokuWiki. Here are the details: + +File : @MEDIA@ +Date : @DATE@ +Browser : @BROWSER@ +IP-Address : @IPADDRESS@ +Hostname : @HOSTNAME@ +Size : @SIZE@ +MIME Type : @MIME@ +User : @USER@ + +-- +This mail was generated by DokuWiki at +@DOKUWIKIURL@ diff --git a/inc/media.php b/inc/media.php index ed64e6388..052e9a54a 100644 --- a/inc/media.php +++ b/inc/media.php @@ -236,6 +236,7 @@ function media_upload($ns,$auth){ // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.) chmod($fn, $conf['fmode']); msg($lang['uploadsucc'],1); + media_notify($id,$fn,$imime); return $id; }else{ msg($lang['uploadfail'],-1); @@ -279,6 +280,37 @@ function media_contentcheck($file,$mime){ return 0; } +/** + * Send a notify mail on uploads + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function media_notify($id,$file,$mime){ + global $lang; + global $conf; + if(empty($conf['notify'])) return; //notify enabled? + + $text = rawLocale('uploadmail'); + $text = str_replace('@DATE@',date($conf['dformat']),$text); + $text = str_replace('@BROWSER@',$_SERVER['HTTP_USER_AGENT'],$text); + $text = str_replace('@IPADDRESS@',$_SERVER['REMOTE_ADDR'],$text); + $text = str_replace('@HOSTNAME@',gethostbyaddr($_SERVER['REMOTE_ADDR']),$text); + $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text); + $text = str_replace('@USER@',$_SERVER['REMOTE_USER'],$text); + $text = str_replace('@MIME@',$mime,$text); + $text = str_replace('@MEDIA@',DOKU_URL.ml($id,'',true,'&'),$text); + $text = str_replace('@SIZE@',filesize_h(filesize($file)),$text); + + $from = $conf['mailfrom']; + $from = str_replace('@USER@',$_SERVER['REMOTE_USER'],$from); + $from = str_replace('@NAME@',$INFO['userinfo']['name'],$from); + $from = str_replace('@MAIL@',$INFO['userinfo']['mail'],$from); + + $subject = '['.$conf['title'].'] '.$lang['mail_upload'].' '.$id; + + mail_send($conf['notify'],$subject,$text,$from); +} + /** * List all files in a given Media namespace */ -- GitLab