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 } 43698cf656SMichael Große if (!$event->data[3]) { 44698cf656SMichael Große return true; 45698cf656SMichael Große } 46698cf656SMichael Große 47698cf656SMichael Große // get mail receiver 48698cf656SMichael Große //$receiver = 'grosse@cosmocode.de';// 49698cf656SMichael Große $receiver = $this->getConf('apr_mail_receiver'); 50698cf656SMichael Große 51698cf656SMichael Große // get mail sender 52698cf656SMichael Große $sender = $data['userinfo']['mail']; 53698cf656SMichael Große 54698cf656SMichael Große if ($sender == $receiver) { 55698cf656SMichael Große dbglog('Mail not send. Sender and receiver are identical.'); 56698cf656SMichael Große// return true; 57698cf656SMichael Große } 58698cf656SMichael Große 59698cf656SMichael Große if ($INFO['isadmin'] == '1') { 60698cf656SMichael Große dbglog('Mail not send. Sender is admin.'); 61698cf656SMichael Große// return true; 62698cf656SMichael Große } 63698cf656SMichael Große 64698cf656SMichael Große // get mail subject 65698cf656SMichael Große //$timestamp = time(); //$data['meta']['date']['modified']; 66698cf656SMichael Große $timestamp = $data['lastmod']; 67698cf656SMichael Große// date_default_timezone_set("Europe/Paris"); 68698cf656SMichael Große $datum = date("d.m.Y",$timestamp); 69698cf656SMichael Große $uhrzeit = date("H:i",$timestamp); 70698cf656SMichael Große $subject = $this->getLang('apr_mail_subject') . ': ' . $ID . ' - ' . $datum . ' ' . $uhrzeit; 71698cf656SMichael Große dbglog($subject); 72698cf656SMichael Große 73698cf656SMichael Große // get mail text 74698cf656SMichael Große //$body = 'apr_changemail_text'; 75698cf656SMichael Große $body = $this->getLang('apr_changemail_text'); 76698cf656SMichael Große $body = str_replace('@DOKUWIKIURL@', DOKU_URL, $body); 77698cf656SMichael Große $body = str_replace('@FULLNAME@', $data['userinfo']['name'], $body); 78698cf656SMichael Große $body = str_replace('@TITLE@', $conf['title'], $body); 79698cf656SMichael Große 8012699d35SMichael Große /** @var helper_plugin_publish $helper */ 8112699d35SMichael Große $helper = plugin_load('helper','publish'); 8212699d35SMichael Große $rev = $data['lastmod']; 8312699d35SMichael Große 8412699d35SMichael Große /** 8512699d35SMichael Große * todo it seems like the diff to the previous version is not that helpful after all. Check and remove. 8612699d35SMichael Große $changelog = new PageChangelog($ID); 8712699d35SMichael Große $difflinkPrev = $helper->getDifflink($ID, $changelog->getRelativeRevision($rev,-1), $rev); 8812699d35SMichael Große $difflinkPrev = '"' . $difflinkPrev . '"'; 8912699d35SMichael Große $body = str_replace('@CHANGESPREV@', $difflinkPrev, $body); 9012699d35SMichael Große */ 9112699d35SMichael Große 9212699d35SMichael Große $difflinkApr = $helper->getDifflink($ID, $helper->getLatestApprovedRevision($ID), $rev); 9312699d35SMichael Große $difflinkApr = '"' . $difflinkApr . '"'; 9412699d35SMichael Große $body = str_replace('@CHANGES@', $difflinkApr, $body); 9512699d35SMichael Große 96698cf656SMichael Große $apprejlink = $this->apprejlink($ID, $data['lastmod']); 97698cf656SMichael Große $apprejlink = '"' . $apprejlink . '"'; 98698cf656SMichael Große $body = str_replace('@APPREJ@', $apprejlink, $body); 99698cf656SMichael Große 10012699d35SMichael Große dbglog('mail_send?'); 10112699d35SMichael Große $returnStatus = mail_send($receiver, $subject, $body, $sender); 10212699d35SMichael Große dbglog($returnStatus); 10312699d35SMichael Große dbglog($body); 10412699d35SMichael Große return $returnStatus; 105698cf656SMichael Große } 106698cf656SMichael Große 10719a54b91SMichael Große // Funktion versendet eine approve-Mail 10819a54b91SMichael Große public function send_approve_mail() { 10919a54b91SMichael Große dbglog('send_approve_mail()'); 11019a54b91SMichael Große global $ID; 11119a54b91SMichael Große global $ACT; 11219a54b91SMichael Große global $REV; 113*8cd8852aSMichael Große 114*8cd8852aSMichael Große /** @var DokuWiki_Auth_Plugin $auth */ 115*8cd8852aSMichael Große global $auth; 11619a54b91SMichael Große global $conf; 117698cf656SMichael Große $data = pageinfo(); 11819a54b91SMichael Große 11919a54b91SMichael Große if ($ACT != 'save') { 12019a54b91SMichael Große // return true; 121698cf656SMichael Große } 122698cf656SMichael Große 12319a54b91SMichael Große // get mail receiver 124*8cd8852aSMichael Große $changelog = new PageChangelog($ID); 125*8cd8852aSMichael Große $revinfo = $changelog->getRevisionInfo($REV); 126*8cd8852aSMichael Große $userinfo = $auth->getUserData($revinfo['user']); 127*8cd8852aSMichael Große $receiver = $userinfo['mail']; 12819a54b91SMichael Große dbglog('$receiver: ' . $receiver); 12919a54b91SMichael Große // get mail sender 13019a54b91SMichael Große $sender = $data['userinfo']['mail']; 13119a54b91SMichael Große dbglog('$sender: ' . $sender); 13219a54b91SMichael Große // get mail subject 13319a54b91SMichael Große $subject = $this->getLang('apr_mail_app_subject'); 13419a54b91SMichael Große dbglog('$subject: ' . $subject); 13519a54b91SMichael Große // get mail text 13619a54b91SMichael Große $body = $this->getLang('apr_approvemail_text'); 13719a54b91SMichael Große $body = str_replace('@DOKUWIKIURL@', DOKU_URL, $body); 13819a54b91SMichael Große $body = str_replace('@FULLNAME@', $data['userinfo']['name'], $body); 13919a54b91SMichael Große $body = str_replace('@TITLE@', $conf['title'], $body); 140698cf656SMichael Große 14119a54b91SMichael Große $url = wl($ID, array('rev'=>$this->hlp->getLatestApprovedRevision($ID)), true, '&'); 14219a54b91SMichael Große $url = '"' . $url . '"'; 14319a54b91SMichael Große $body = str_replace('@URL@', $url, $body); 14419a54b91SMichael Große dbglog('$body: ' . $body); 14519a54b91SMichael Große 14619a54b91SMichael Große return mail_send($receiver, $subject, $body, $sender); 147698cf656SMichael Große } 148698cf656SMichael Große 149698cf656SMichael Große /** 150698cf656SMichael Große * erzeugt den Link auf die edit-Seite 151698cf656SMichael Große * 152698cf656SMichael Große * @param $id 153698cf656SMichael Große * @param $rev 154846d3071SMichael Große * @return string 155698cf656SMichael Große */ 156698cf656SMichael Große function apprejlink($id, $rev) { 157698cf656SMichael Große 158698cf656SMichael Große $options = array( 159698cf656SMichael Große 'rev'=> $rev, 160698cf656SMichael Große ); 161846d3071SMichael Große $apprejlink = wl($id, $options, true, '&'); 162698cf656SMichael Große 163846d3071SMichael Große return $apprejlink; 164698cf656SMichael Große } 165698cf656SMichael Große 166698cf656SMichael Große} 167