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 314f5c41dbSMichael Große /** 324f5c41dbSMichael Große * send an email to inform about a changed page 334f5c41dbSMichael Große * 344f5c41dbSMichael Große * @param $event 354f5c41dbSMichael Große * @param $param 364f5c41dbSMichael Große * @return bool|mixed 374f5c41dbSMichael Große */ 38698cf656SMichael Große function send_change_mail(&$event, $param) { 39698cf656SMichael Große global $ID; 40698cf656SMichael Große global $ACT; 41698cf656SMichael Große global $INFO; 42698cf656SMichael Große $data = pageinfo(); 43698cf656SMichael Große 44698cf656SMichael Große if ($ACT != 'save') { 45698cf656SMichael Große return true; 46698cf656SMichael Große } 478bc37331SMichael Große 488bc37331SMichael Große // IO_WIKIPAGE_WRITE is always called twice when saving a page. This makes sure to only send the mail once. 49698cf656SMichael Große if (!$event->data[3]) { 50698cf656SMichael Große return true; 51698cf656SMichael Große } 52698cf656SMichael Große 538bc37331SMichael Große // Does the publish plugin apply to this page? 548bc37331SMichael Große if (!$this->hlp->isActive($ID)) { 558bc37331SMichael Große return true; 568bc37331SMichael Große } 578bc37331SMichael Große 588bc37331SMichael Große //are we supposed to send change-mails at all? 598bc37331SMichael Große if (!$this->getConf('send_mail_on_change')) { 608bc37331SMichael Große return true; 618bc37331SMichael Große } 628bc37331SMichael Große 63698cf656SMichael Große // get mail receiver 64698cf656SMichael Große $receiver = $this->getConf('apr_mail_receiver'); 65698cf656SMichael Große 66698cf656SMichael Große // get mail sender 67698cf656SMichael Große $sender = $data['userinfo']['mail']; 68698cf656SMichael Große 69698cf656SMichael Große if ($sender == $receiver) { 709e614880SMichael Große dbglog('[publish plugin]: Mail not send. Sender and receiver are identical.'); 719e614880SMichael Große return true; 72698cf656SMichael Große } 73698cf656SMichael Große 74698cf656SMichael Große if ($INFO['isadmin'] == '1') { 759e614880SMichael Große dbglog('[publish plugin]: Mail not send. Sender is admin.'); 769e614880SMichael Große return true; 77698cf656SMichael Große } 78698cf656SMichael Große 79698cf656SMichael Große // get mail subject 80698cf656SMichael Große $timestamp = $data['lastmod']; 814f5c41dbSMichael Große $datum = dformat("d.m.Y",$timestamp); 824f5c41dbSMichael Große $uhrzeit = dformat("H:i",$timestamp); 83698cf656SMichael Große $subject = $this->getLang('apr_mail_subject') . ': ' . $ID . ' - ' . $datum . ' ' . $uhrzeit; 84698cf656SMichael Große dbglog($subject); 85698cf656SMichael Große 86e6206222SMichael Große $body = $this->create_mail_body('change'); 87698cf656SMichael Große 8812699d35SMichael Große dbglog('mail_send?'); 89*3c21cb49SMichael Große 90*3c21cb49SMichael Große $replyto_header = mail_encode_address($sender, 'Reply-To'); 91*3c21cb49SMichael Große $sender = 'DokuWiki <www-data@127.0.0.1>'; 92*3c21cb49SMichael Große 93*3c21cb49SMichael Große $returnStatus = mail_send($receiver, $subject, $body, $sender,"","",$replyto_header); 9412699d35SMichael Große dbglog($returnStatus); 9512699d35SMichael Große return $returnStatus; 96698cf656SMichael Große } 97698cf656SMichael Große 98e6206222SMichael Große /** 99e6206222SMichael Große * Create the body of mails to inform about a changed or an approved page 100e6206222SMichael Große * 101e6206222SMichael Große * @param string $action Must either be "change" or "approve" 102e6206222SMichael Große * @return bool|string 103e6206222SMichael Große * @internal param $pageinfo 104e6206222SMichael Große */ 105e6206222SMichael Große public function create_mail_body($action) { 106e6206222SMichael Große global $ID; 1078ff23e7fSMichael Große global $conf; 108e6206222SMichael Große $pageinfo = pageinfo(); 109bc4555caSMichael Große 1108ff23e7fSMichael Große // get mail text 1118ff23e7fSMichael Große $body = $this->getLang('mail_greeting') . "\n"; 1128ff23e7fSMichael Große $rev = $pageinfo['lastmod']; 1138ff23e7fSMichael Große 114bc4555caSMichael Große if ($action === 'change') { 115bc4555caSMichael Große $body .= $this->getLang('mail_new_suggestiopns') . "\n\n"; 116bc4555caSMichael Große 1178ff23e7fSMichael Große //If there is no approved revision show the diff to the revision before. Otherwise show the diff to the last approved revision. 1188ff23e7fSMichael Große if($this->hlp->hasApprovals($pageinfo['meta'])) { 1198ff23e7fSMichael Große $body .= $this->getLang('mail_changes_to_approved_rev') . "\n\n"; 120e6206222SMichael Große $difflink = $this->hlp->getDifflink($ID, $this->hlp->getLatestApprovedRevision($ID), $rev); 1218ff23e7fSMichael Große } else { 1228ff23e7fSMichael Große $body .= $this->getLang('mail_changes_to_previous_rev') . "\n\n"; 123e6206222SMichael Große $changelog = new PageChangelog($ID); 1248ff23e7fSMichael Große $prevrev = $changelog->getRelativeRevision($rev, -1); 125e6206222SMichael Große $difflink = $this->hlp->getDifflink($ID, $prevrev, $rev); 1268ff23e7fSMichael Große } 1278ff23e7fSMichael Große $body = str_replace('@CHANGES@', $difflink, $body); 128e6206222SMichael Große $apprejlink = $this->apprejlink($ID, $rev); 129bc4555caSMichael Große $body = str_replace('@URL@', $apprejlink, $body); 130bc4555caSMichael Große } elseif ($action === 'approve') { 131bc4555caSMichael Große $body .= $this->getLang('mail_approved') . "\n\n"; 132e6206222SMichael Große $apprejlink = $this->apprejlink($ID, $rev); 133bc4555caSMichael Große $body = str_replace('@URL@', $apprejlink, $body); 134bc4555caSMichael Große } else { 135bc4555caSMichael Große return false; 136bc4555caSMichael Große } 137bc4555caSMichael Große 138bc4555caSMichael Große $body .= $this->getLang('mail_dw_signature'); 1398ff23e7fSMichael Große 1408ff23e7fSMichael Große $body = str_replace('@DOKUWIKIURL@', DOKU_URL, $body); 1418ff23e7fSMichael Große $body = str_replace('@FULLNAME@', $pageinfo['userinfo']['name'], $body); 1428ff23e7fSMichael Große $body = str_replace('@TITLE@', $conf['title'], $body); 1438ff23e7fSMichael Große 1448ff23e7fSMichael Große return $body; 1458ff23e7fSMichael Große } 1468ff23e7fSMichael Große 1478ff23e7fSMichael Große 1489e614880SMichael Große 1499e614880SMichael Große /** 1509e614880SMichael Große * Send approve-mail to editor of the now approved revision 1519e614880SMichael Große * 1529e614880SMichael Große * @return mixed 1539e614880SMichael Große */ 15419a54b91SMichael Große public function send_approve_mail() { 15519a54b91SMichael Große global $ID; 15619a54b91SMichael Große global $REV; 1578cd8852aSMichael Große 1588cd8852aSMichael Große /** @var DokuWiki_Auth_Plugin $auth */ 1598cd8852aSMichael Große global $auth; 160698cf656SMichael Große $data = pageinfo(); 16119a54b91SMichael Große 16219a54b91SMichael Große // get mail receiver 163*3c21cb49SMichael Große if (!$REV) { 164*3c21cb49SMichael Große $rev = $data['lastmod']; 165*3c21cb49SMichael Große } else { 166*3c21cb49SMichael Große $rev=$REV; 167*3c21cb49SMichael Große } 1688cd8852aSMichael Große $changelog = new PageChangelog($ID); 169*3c21cb49SMichael Große $revinfo = $changelog->getRevisionInfo($rev); 1708cd8852aSMichael Große $userinfo = $auth->getUserData($revinfo['user']); 1718cd8852aSMichael Große $receiver = $userinfo['mail']; 172bc4555caSMichael Große 17319a54b91SMichael Große // get mail sender 17419a54b91SMichael Große $sender = $data['userinfo']['mail']; 175bc4555caSMichael Große 17619a54b91SMichael Große // get mail subject 17719a54b91SMichael Große $subject = $this->getLang('apr_mail_app_subject'); 178698cf656SMichael Große 179bc4555caSMichael Große // get mail text 180e6206222SMichael Große $body = $this->create_mail_body('approve'); 18119a54b91SMichael Große 182*3c21cb49SMichael Große $replyto_header = mail_encode_address($sender, 'Reply-To'); 183*3c21cb49SMichael Große $sender = 'DokuWiki <www-data@127.0.0.1>'; 184*3c21cb49SMichael Große 185*3c21cb49SMichael Große return mail_send($receiver, $subject, $body, $sender,"","",$replyto_header); 186698cf656SMichael Große } 187698cf656SMichael Große 188698cf656SMichael Große /** 189698cf656SMichael Große * erzeugt den Link auf die edit-Seite 190698cf656SMichael Große * 191698cf656SMichael Große * @param $id 192698cf656SMichael Große * @param $rev 193846d3071SMichael Große * @return string 194698cf656SMichael Große */ 195698cf656SMichael Große function apprejlink($id, $rev) { 196698cf656SMichael Große 197698cf656SMichael Große $options = array( 198698cf656SMichael Große 'rev'=> $rev, 199698cf656SMichael Große ); 200846d3071SMichael Große $apprejlink = wl($id, $options, true, '&'); 201698cf656SMichael Große 202846d3071SMichael Große return $apprejlink; 203698cf656SMichael Große } 204698cf656SMichael Große 205698cf656SMichael Große} 206