1<?php 2/** 3 * @license GNU General Public License, version 2 4 */ 5 6 7if (!defined('DOKU_INC')) die(); 8 9 10/** 11 * Class action_plugin_publish_mail 12 * 13 * @author Michael Große <grosse@cosmocode.de> 14 */ 15class action_plugin_publish_mail extends DokuWiki_Action_Plugin { 16 17 /** 18 * @var helper_plugin_publish 19 */ 20 private $hlp; 21 22 function __construct() { 23 $this->hlp = plugin_load('helper','publish'); 24 } 25 26 public function register(Doku_Event_Handler $controller) { 27 28 $controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'send_change_mail', array()); 29 } 30 31 // Funktion versendet eine Änderungsmail 32 function send_change_mail(&$event, $param) { 33 global $ID; 34 global $ACT; 35 global $REV; 36 global $INFO; 37 global $conf; 38 $data = pageinfo(); 39 40 if ($ACT != 'save') { 41 return true; 42 } 43 44 // IO_WIKIPAGE_WRITE is always called twice when saving a page. This makes sure to only send the mail once. 45 if (!$event->data[3]) { 46 return true; 47 } 48 49 // Does the publish plugin apply to this page? 50 if (!$this->hlp->isActive($ID)) { 51 return true; 52 } 53 54 //are we supposed to send change-mails at all? 55 if (!$this->getConf('send_mail_on_change')) { 56 return true; 57 } 58 59 // get mail receiver 60 $receiver = $this->getConf('apr_mail_receiver'); 61 62 // get mail sender 63 $sender = $data['userinfo']['mail']; 64 65 if ($sender == $receiver) { 66 dbglog('[publish plugin]: Mail not send. Sender and receiver are identical.'); 67 return true; 68 } 69 70 if ($INFO['isadmin'] == '1') { 71 dbglog('[publish plugin]: Mail not send. Sender is admin.'); 72 return true; 73 } 74 75 // get mail subject 76 $timestamp = $data['lastmod']; 77 $datum = date("d.m.Y",$timestamp); 78 $uhrzeit = date("H:i",$timestamp); 79 $subject = $this->getLang('apr_mail_subject') . ': ' . $ID . ' - ' . $datum . ' ' . $uhrzeit; 80 dbglog($subject); 81 82 // get mail text 83 $body = $this->getLang('apr_changemail_text'); 84 $body = str_replace('@DOKUWIKIURL@', DOKU_URL, $body); 85 $body = str_replace('@FULLNAME@', $data['userinfo']['name'], $body); 86 $body = str_replace('@TITLE@', $conf['title'], $body); 87 88 /** @var helper_plugin_publish $helper */ 89 $helper = plugin_load('helper','publish'); 90 $rev = $data['lastmod']; 91 92 /** 93 * todo it seems like the diff to the previous version is not that helpful after all. Check and remove. 94 $changelog = new PageChangelog($ID); 95 $difflinkPrev = $helper->getDifflink($ID, $changelog->getRelativeRevision($rev,-1), $rev); 96 $difflinkPrev = '"' . $difflinkPrev . '"'; 97 $body = str_replace('@CHANGESPREV@', $difflinkPrev, $body); 98 */ 99 100 $difflinkApr = $helper->getDifflink($ID, $helper->getLatestApprovedRevision($ID), $rev); 101 $difflinkApr = '"' . $difflinkApr . '"'; 102 $body = str_replace('@CHANGES@', $difflinkApr, $body); 103 104 $apprejlink = $this->apprejlink($ID, $data['lastmod']); 105 $apprejlink = '"' . $apprejlink . '"'; 106 $body = str_replace('@APPREJ@', $apprejlink, $body); 107 108 dbglog('mail_send?'); 109 $returnStatus = mail_send($receiver, $subject, $body, $sender); 110 dbglog($returnStatus); 111 dbglog($body); 112 return $returnStatus; 113 } 114 115 116 /** 117 * Send approve-mail to editor of the now approved revision 118 * 119 * @return mixed 120 */ 121 public function send_approve_mail() { 122 dbglog('send_approve_mail()'); 123 global $ID; 124 global $ACT; 125 global $REV; 126 127 /** @var DokuWiki_Auth_Plugin $auth */ 128 global $auth; 129 global $conf; 130 $data = pageinfo(); 131 132 if ($ACT != 'save') { 133 // return true; 134 } 135 136 // get mail receiver 137 $changelog = new PageChangelog($ID); 138 $revinfo = $changelog->getRevisionInfo($REV); 139 $userinfo = $auth->getUserData($revinfo['user']); 140 $receiver = $userinfo['mail']; 141 dbglog('$receiver: ' . $receiver); 142 // get mail sender 143 $sender = $data['userinfo']['mail']; 144 dbglog('$sender: ' . $sender); 145 // get mail subject 146 $subject = $this->getLang('apr_mail_app_subject'); 147 dbglog('$subject: ' . $subject); 148 // get mail text 149 $body = $this->getLang('apr_approvemail_text'); 150 $body = str_replace('@DOKUWIKIURL@', DOKU_URL, $body); 151 $body = str_replace('@FULLNAME@', $data['userinfo']['name'], $body); 152 $body = str_replace('@TITLE@', $conf['title'], $body); 153 154 $url = wl($ID, array('rev'=>$this->hlp->getLatestApprovedRevision($ID)), true, '&'); 155 $url = '"' . $url . '"'; 156 $body = str_replace('@URL@', $url, $body); 157 dbglog('$body: ' . $body); 158 159 return mail_send($receiver, $subject, $body, $sender); 160 } 161 162 /** 163 * erzeugt den Link auf die edit-Seite 164 * 165 * @param $id 166 * @param $rev 167 * @return string 168 */ 169 function apprejlink($id, $rev) { 170 171 $options = array( 172 'rev'=> $rev, 173 ); 174 $apprejlink = wl($id, $options, true, '&'); 175 176 return $apprejlink; 177 } 178 179} 180