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 } 43*8bc37331SMichael Große 44*8bc37331SMichael 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 49*8bc37331SMichael Große // Does the publish plugin apply to this page? 50*8bc37331SMichael Große if (!$this->hlp->isActive($ID)) { 51*8bc37331SMichael Große return true; 52*8bc37331SMichael Große } 53*8bc37331SMichael Große 54*8bc37331SMichael Große //are we supposed to send change-mails at all? 55*8bc37331SMichael Große if (!$this->getConf('send_mail_on_change')) { 56*8bc37331SMichael Große return true; 57*8bc37331SMichael Große } 58*8bc37331SMichael Große 59698cf656SMichael Große // get mail receiver 60698cf656SMichael Große //$receiver = 'grosse@cosmocode.de';// 61698cf656SMichael Große $receiver = $this->getConf('apr_mail_receiver'); 62698cf656SMichael Große 63698cf656SMichael Große // get mail sender 64698cf656SMichael Große $sender = $data['userinfo']['mail']; 65698cf656SMichael Große 66698cf656SMichael Große if ($sender == $receiver) { 67698cf656SMichael Große dbglog('Mail not send. Sender and receiver are identical.'); 68698cf656SMichael Große// return true; 69698cf656SMichael Große } 70698cf656SMichael Große 71698cf656SMichael Große if ($INFO['isadmin'] == '1') { 72698cf656SMichael Große dbglog('Mail not send. Sender is admin.'); 73698cf656SMichael Große// return true; 74698cf656SMichael Große } 75698cf656SMichael Große 76698cf656SMichael Große // get mail subject 77698cf656SMichael Große //$timestamp = time(); //$data['meta']['date']['modified']; 78698cf656SMichael Große $timestamp = $data['lastmod']; 79698cf656SMichael Große// date_default_timezone_set("Europe/Paris"); 80698cf656SMichael Große $datum = date("d.m.Y",$timestamp); 81698cf656SMichael Große $uhrzeit = date("H:i",$timestamp); 82698cf656SMichael Große $subject = $this->getLang('apr_mail_subject') . ': ' . $ID . ' - ' . $datum . ' ' . $uhrzeit; 83698cf656SMichael Große dbglog($subject); 84698cf656SMichael Große 85698cf656SMichael Große // get mail text 86698cf656SMichael Große //$body = 'apr_changemail_text'; 87698cf656SMichael Große $body = $this->getLang('apr_changemail_text'); 88698cf656SMichael Große $body = str_replace('@DOKUWIKIURL@', DOKU_URL, $body); 89698cf656SMichael Große $body = str_replace('@FULLNAME@', $data['userinfo']['name'], $body); 90698cf656SMichael Große $body = str_replace('@TITLE@', $conf['title'], $body); 91698cf656SMichael Große 9212699d35SMichael Große /** @var helper_plugin_publish $helper */ 9312699d35SMichael Große $helper = plugin_load('helper','publish'); 9412699d35SMichael Große $rev = $data['lastmod']; 9512699d35SMichael Große 9612699d35SMichael Große /** 9712699d35SMichael Große * todo it seems like the diff to the previous version is not that helpful after all. Check and remove. 9812699d35SMichael Große $changelog = new PageChangelog($ID); 9912699d35SMichael Große $difflinkPrev = $helper->getDifflink($ID, $changelog->getRelativeRevision($rev,-1), $rev); 10012699d35SMichael Große $difflinkPrev = '"' . $difflinkPrev . '"'; 10112699d35SMichael Große $body = str_replace('@CHANGESPREV@', $difflinkPrev, $body); 10212699d35SMichael Große */ 10312699d35SMichael Große 10412699d35SMichael Große $difflinkApr = $helper->getDifflink($ID, $helper->getLatestApprovedRevision($ID), $rev); 10512699d35SMichael Große $difflinkApr = '"' . $difflinkApr . '"'; 10612699d35SMichael Große $body = str_replace('@CHANGES@', $difflinkApr, $body); 10712699d35SMichael Große 108698cf656SMichael Große $apprejlink = $this->apprejlink($ID, $data['lastmod']); 109698cf656SMichael Große $apprejlink = '"' . $apprejlink . '"'; 110698cf656SMichael Große $body = str_replace('@APPREJ@', $apprejlink, $body); 111698cf656SMichael Große 11212699d35SMichael Große dbglog('mail_send?'); 11312699d35SMichael Große $returnStatus = mail_send($receiver, $subject, $body, $sender); 11412699d35SMichael Große dbglog($returnStatus); 11512699d35SMichael Große dbglog($body); 11612699d35SMichael Große return $returnStatus; 117698cf656SMichael Große } 118698cf656SMichael Große 11919a54b91SMichael Große // Funktion versendet eine approve-Mail 12019a54b91SMichael Große public function send_approve_mail() { 12119a54b91SMichael Große dbglog('send_approve_mail()'); 12219a54b91SMichael Große global $ID; 12319a54b91SMichael Große global $ACT; 12419a54b91SMichael Große global $REV; 1258cd8852aSMichael Große 1268cd8852aSMichael Große /** @var DokuWiki_Auth_Plugin $auth */ 1278cd8852aSMichael Große global $auth; 12819a54b91SMichael Große global $conf; 129698cf656SMichael Große $data = pageinfo(); 13019a54b91SMichael Große 13119a54b91SMichael Große if ($ACT != 'save') { 13219a54b91SMichael Große // return true; 133698cf656SMichael Große } 134698cf656SMichael Große 13519a54b91SMichael Große // get mail receiver 1368cd8852aSMichael Große $changelog = new PageChangelog($ID); 1378cd8852aSMichael Große $revinfo = $changelog->getRevisionInfo($REV); 1388cd8852aSMichael Große $userinfo = $auth->getUserData($revinfo['user']); 1398cd8852aSMichael Große $receiver = $userinfo['mail']; 14019a54b91SMichael Große dbglog('$receiver: ' . $receiver); 14119a54b91SMichael Große // get mail sender 14219a54b91SMichael Große $sender = $data['userinfo']['mail']; 14319a54b91SMichael Große dbglog('$sender: ' . $sender); 14419a54b91SMichael Große // get mail subject 14519a54b91SMichael Große $subject = $this->getLang('apr_mail_app_subject'); 14619a54b91SMichael Große dbglog('$subject: ' . $subject); 14719a54b91SMichael Große // get mail text 14819a54b91SMichael Große $body = $this->getLang('apr_approvemail_text'); 14919a54b91SMichael Große $body = str_replace('@DOKUWIKIURL@', DOKU_URL, $body); 15019a54b91SMichael Große $body = str_replace('@FULLNAME@', $data['userinfo']['name'], $body); 15119a54b91SMichael Große $body = str_replace('@TITLE@', $conf['title'], $body); 152698cf656SMichael Große 15319a54b91SMichael Große $url = wl($ID, array('rev'=>$this->hlp->getLatestApprovedRevision($ID)), true, '&'); 15419a54b91SMichael Große $url = '"' . $url . '"'; 15519a54b91SMichael Große $body = str_replace('@URL@', $url, $body); 15619a54b91SMichael Große dbglog('$body: ' . $body); 15719a54b91SMichael Große 15819a54b91SMichael Große return mail_send($receiver, $subject, $body, $sender); 159698cf656SMichael Große } 160698cf656SMichael Große 161698cf656SMichael Große /** 162698cf656SMichael Große * erzeugt den Link auf die edit-Seite 163698cf656SMichael Große * 164698cf656SMichael Große * @param $id 165698cf656SMichael Große * @param $rev 166846d3071SMichael Große * @return string 167698cf656SMichael Große */ 168698cf656SMichael Große function apprejlink($id, $rev) { 169698cf656SMichael Große 170698cf656SMichael Große $options = array( 171698cf656SMichael Große 'rev'=> $rev, 172698cf656SMichael Große ); 173846d3071SMichael Große $apprejlink = wl($id, $options, true, '&'); 174698cf656SMichael Große 175846d3071SMichael Große return $apprejlink; 176698cf656SMichael Große } 177698cf656SMichael Große 178698cf656SMichael Große} 179