1698cf656SMichael Große<?php 2698cf656SMichael Große/** 3698cf656SMichael Große * @license GNU General Public License, version 2 4698cf656SMichael Große */ 5698cf656SMichael Große 6698cf656SMichael Große 7698cf656SMichael Großeif (!defined('DOKU_INC')) die(); 8698cf656SMichael Große 9698cf656SMichael Große 10698cf656SMichael Große/** 11698cf656SMichael Große * Class action_plugin_publish_mail 12698cf656SMichael Große * 13698cf656SMichael Große * @author Michael Große <grosse@cosmocode.de> 14698cf656SMichael Große */ 15698cf656SMichael Großeclass action_plugin_publish_mail extends DokuWiki_Action_Plugin { 16698cf656SMichael Große 17a9071e04SMichael Große /** 18a9071e04SMichael Große * @var helper_plugin_publish 19a9071e04SMichael Große */ 20a9071e04SMichael Große private $hlp; 21a9071e04SMichael Große 22a9071e04SMichael Große function __construct() { 23a9071e04SMichael Große $this->hlp = plugin_load('helper','publish'); 24a9071e04SMichael Große } 25a9071e04SMichael Große 26698cf656SMichael Große public function register(Doku_Event_Handler $controller) { 27698cf656SMichael Große 28698cf656SMichael Große $controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'send_change_mail', array()); 29698cf656SMichael Große } 30698cf656SMichael Große 31698cf656SMichael Große // Funktion versendet eine Änderungsmail 32698cf656SMichael Große function send_change_mail(&$event, $param) { 33698cf656SMichael Große global $ID; 34698cf656SMichael Große global $ACT; 35698cf656SMichael Große global $REV; 36698cf656SMichael Große global $INFO; 37698cf656SMichael Große global $conf; 38698cf656SMichael Große $data = pageinfo(); 39698cf656SMichael Große 40698cf656SMichael Große if ($ACT != 'save') { 41698cf656SMichael Große return true; 42698cf656SMichael Große } 438bc37331SMichael Große 448bc37331SMichael Große // IO_WIKIPAGE_WRITE is always called twice when saving a page. This makes sure to only send the mail once. 45698cf656SMichael Große if (!$event->data[3]) { 46698cf656SMichael Große return true; 47698cf656SMichael Große } 48698cf656SMichael Große 498bc37331SMichael Große // Does the publish plugin apply to this page? 508bc37331SMichael Große if (!$this->hlp->isActive($ID)) { 518bc37331SMichael Große return true; 528bc37331SMichael Große } 538bc37331SMichael Große 548bc37331SMichael Große //are we supposed to send change-mails at all? 558bc37331SMichael Große if (!$this->getConf('send_mail_on_change')) { 568bc37331SMichael Große return true; 578bc37331SMichael Große } 588bc37331SMichael Große 59698cf656SMichael Große // get mail receiver 60698cf656SMichael Große $receiver = $this->getConf('apr_mail_receiver'); 61698cf656SMichael Große 62698cf656SMichael Große // get mail sender 63698cf656SMichael Große $sender = $data['userinfo']['mail']; 64698cf656SMichael Große 65698cf656SMichael Große if ($sender == $receiver) { 669e614880SMichael Große dbglog('[publish plugin]: Mail not send. Sender and receiver are identical.'); 679e614880SMichael Große return true; 68698cf656SMichael Große } 69698cf656SMichael Große 70698cf656SMichael Große if ($INFO['isadmin'] == '1') { 719e614880SMichael Große dbglog('[publish plugin]: Mail not send. Sender is admin.'); 729e614880SMichael Große return true; 73698cf656SMichael Große } 74698cf656SMichael Große 75698cf656SMichael Große // get mail subject 76698cf656SMichael Große $timestamp = $data['lastmod']; 77698cf656SMichael Große $datum = date("d.m.Y",$timestamp); 78698cf656SMichael Große $uhrzeit = date("H:i",$timestamp); 79698cf656SMichael Große $subject = $this->getLang('apr_mail_subject') . ': ' . $ID . ' - ' . $datum . ' ' . $uhrzeit; 80698cf656SMichael Große dbglog($subject); 81698cf656SMichael Große 82*8ff23e7fSMichael Große $body = $this->create_approve_mail_body($ID, $data); 83698cf656SMichael Große 84698cf656SMichael Große 8512699d35SMichael Große dbglog('mail_send?'); 8612699d35SMichael Große $returnStatus = mail_send($receiver, $subject, $body, $sender); 8712699d35SMichael Große dbglog($returnStatus); 8812699d35SMichael Große dbglog($body); 8912699d35SMichael Große return $returnStatus; 90698cf656SMichael Große } 91698cf656SMichael Große 92*8ff23e7fSMichael Große public function create_change_mail_body($id, $pageinfo) { 93*8ff23e7fSMichael Große global $conf; 94*8ff23e7fSMichael Große // get mail text 95*8ff23e7fSMichael Große $body = $this->getLang('mail_greeting') . "\n"; 96*8ff23e7fSMichael Große $body .= $this->getLang('mail_new_suggestiopns') . "\n\n"; 97*8ff23e7fSMichael Große 98*8ff23e7fSMichael Große $rev = $pageinfo['lastmod']; 99*8ff23e7fSMichael Große 100*8ff23e7fSMichael Große //If there is no approved revision show the diff to the revision before. Otherwise show the diff to the last approved revision. 101*8ff23e7fSMichael Große if ($this->hlp->hasApprovals($pageinfo['meta'])) { 102*8ff23e7fSMichael Große $body .= $this->getLang('mail_changes_to_approved_rev') . "\n\n"; 103*8ff23e7fSMichael Große $difflink = $this->hlp->getDifflink($id, $this->hlp->getLatestApprovedRevision($id), $rev); 104*8ff23e7fSMichael Große } else { 105*8ff23e7fSMichael Große $body .= $this->getLang('mail_changes_to_previous_rev') . "\n\n"; 106*8ff23e7fSMichael Große $changelog = new PageChangelog($id); 107*8ff23e7fSMichael Große $prevrev = $changelog->getRelativeRevision($rev,-1); 108*8ff23e7fSMichael Große $difflink = $this->hlp->getDifflink($id, $prevrev, $rev); 109*8ff23e7fSMichael Große } 110*8ff23e7fSMichael Große 111*8ff23e7fSMichael Große $body .= $this->getLang('mail_dw_signature'); 112*8ff23e7fSMichael Große 113*8ff23e7fSMichael Große $body = str_replace('@CHANGES@', $difflink, $body); 114*8ff23e7fSMichael Große $apprejlink = $this->apprejlink($id, $rev); 115*8ff23e7fSMichael Große $body = str_replace('@APPREJ@', $apprejlink, $body); 116*8ff23e7fSMichael Große 117*8ff23e7fSMichael Große $body = str_replace('@DOKUWIKIURL@', DOKU_URL, $body); 118*8ff23e7fSMichael Große $body = str_replace('@FULLNAME@', $pageinfo['userinfo']['name'], $body); 119*8ff23e7fSMichael Große $body = str_replace('@TITLE@', $conf['title'], $body); 120*8ff23e7fSMichael Große 121*8ff23e7fSMichael Große return $body; 122*8ff23e7fSMichael Große } 123*8ff23e7fSMichael Große 124*8ff23e7fSMichael Große 1259e614880SMichael Große 1269e614880SMichael Große /** 1279e614880SMichael Große * Send approve-mail to editor of the now approved revision 1289e614880SMichael Große * 1299e614880SMichael Große * @return mixed 1309e614880SMichael Große */ 13119a54b91SMichael Große public function send_approve_mail() { 13219a54b91SMichael Große dbglog('send_approve_mail()'); 13319a54b91SMichael Große global $ID; 13419a54b91SMichael Große global $ACT; 13519a54b91SMichael Große global $REV; 1368cd8852aSMichael Große 1378cd8852aSMichael Große /** @var DokuWiki_Auth_Plugin $auth */ 1388cd8852aSMichael Große global $auth; 13919a54b91SMichael Große global $conf; 140698cf656SMichael Große $data = pageinfo(); 14119a54b91SMichael Große 14219a54b91SMichael Große if ($ACT != 'save') { 14319a54b91SMichael Große // return true; 144698cf656SMichael Große } 145698cf656SMichael Große 14619a54b91SMichael Große // get mail receiver 1478cd8852aSMichael Große $changelog = new PageChangelog($ID); 1488cd8852aSMichael Große $revinfo = $changelog->getRevisionInfo($REV); 1498cd8852aSMichael Große $userinfo = $auth->getUserData($revinfo['user']); 1508cd8852aSMichael Große $receiver = $userinfo['mail']; 15119a54b91SMichael Große dbglog('$receiver: ' . $receiver); 15219a54b91SMichael Große // get mail sender 15319a54b91SMichael Große $sender = $data['userinfo']['mail']; 15419a54b91SMichael Große dbglog('$sender: ' . $sender); 15519a54b91SMichael Große // get mail subject 15619a54b91SMichael Große $subject = $this->getLang('apr_mail_app_subject'); 15719a54b91SMichael Große dbglog('$subject: ' . $subject); 15819a54b91SMichael Große // get mail text 15919a54b91SMichael Große $body = $this->getLang('apr_approvemail_text'); 16019a54b91SMichael Große $body = str_replace('@DOKUWIKIURL@', DOKU_URL, $body); 16119a54b91SMichael Große $body = str_replace('@FULLNAME@', $data['userinfo']['name'], $body); 16219a54b91SMichael Große $body = str_replace('@TITLE@', $conf['title'], $body); 163698cf656SMichael Große 16419a54b91SMichael Große $url = wl($ID, array('rev'=>$this->hlp->getLatestApprovedRevision($ID)), true, '&'); 16519a54b91SMichael Große $url = '"' . $url . '"'; 16619a54b91SMichael Große $body = str_replace('@URL@', $url, $body); 16719a54b91SMichael Große dbglog('$body: ' . $body); 16819a54b91SMichael Große 16919a54b91SMichael Große return mail_send($receiver, $subject, $body, $sender); 170698cf656SMichael Große } 171698cf656SMichael Große 172698cf656SMichael Große /** 173698cf656SMichael Große * erzeugt den Link auf die edit-Seite 174698cf656SMichael Große * 175698cf656SMichael Große * @param $id 176698cf656SMichael Große * @param $rev 177846d3071SMichael Große * @return string 178698cf656SMichael Große */ 179698cf656SMichael Große function apprejlink($id, $rev) { 180698cf656SMichael Große 181698cf656SMichael Große $options = array( 182698cf656SMichael Große 'rev'=> $rev, 183698cf656SMichael Große ); 184846d3071SMichael Große $apprejlink = wl($id, $options, true, '&'); 185698cf656SMichael Große 186846d3071SMichael Große return $apprejlink; 187698cf656SMichael Große } 188698cf656SMichael Große 189698cf656SMichael Große} 190