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 17*a9071e04SMichael Große /** 18*a9071e04SMichael Große * @var helper_plugin_publish 19*a9071e04SMichael Große */ 20*a9071e04SMichael Große private $hlp; 21*a9071e04SMichael Große 22*a9071e04SMichael Große function __construct() { 23*a9071e04SMichael Große $this->hlp = plugin_load('helper','publish'); 24*a9071e04SMichael Große } 25*a9071e04SMichael 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 80698cf656SMichael Große// dbglog(pageinfo()); 81698cf656SMichael Große $difflink = $this->difflink($ID, $this->getLastApproved(), $data['lastmod']); 82698cf656SMichael Große $difflink = '"' . $difflink . '"'; 83698cf656SMichael Große $body = str_replace('@CHANGES@', $difflink, $body); 84698cf656SMichael Große $apprejlink = $this->apprejlink($ID, $data['lastmod']); 85698cf656SMichael Große $apprejlink = '"' . $apprejlink . '"'; 86698cf656SMichael Große $body = str_replace('@APPREJ@', $apprejlink, $body); 87698cf656SMichael Große 88698cf656SMichael Große dbglog('mail_send'); 89698cf656SMichael Große return mail_send($receiver, $subject, $body, $sender); 90698cf656SMichael Große } 91698cf656SMichael Große 92698cf656SMichael Große function getLastApproved() { 93698cf656SMichael Große $data = pageinfo(); 94698cf656SMichael Große if (!$data['meta']['approval']) { 95698cf656SMichael Große return ''; 96698cf656SMichael Große } 97698cf656SMichael Große $allapproved = array_keys($data['meta']['approval']); 98698cf656SMichael Große dbglog('$allapproved: ' . $allapproved); 99698cf656SMichael Große rsort($allapproved); 100698cf656SMichael Große 101698cf656SMichael Große $latestapproved = $allapproved[0]; 102698cf656SMichael Große dbglog('$latest_rev: ' . $latestapproved); 103698cf656SMichael Große 104698cf656SMichael Große return $latestapproved; 105698cf656SMichael Große } 106698cf656SMichael Große 107698cf656SMichael Große /** 108698cf656SMichael Große * erzeugt den Link auf die edit-Seite 109698cf656SMichael Große * 110698cf656SMichael Große * @param $id 111698cf656SMichael Große * @param $rev 112698cf656SMichael Große * @return mixed|string 113698cf656SMichael Große */ 114698cf656SMichael Große function apprejlink($id, $rev) { 115698cf656SMichael Große $data = pageinfo(); 116698cf656SMichael Große 117698cf656SMichael Große $options = array( 118698cf656SMichael Große 'rev'=> $rev, 119698cf656SMichael Große 'do'=>'edit', 120698cf656SMichael Große 'suggestfrom' => $data['userinfo']['mail'], 121698cf656SMichael Große ); 122698cf656SMichael Große $difflink = wl($id, $options, true, '&'); 123698cf656SMichael Große// $difflink = str_replace('//', '/', $difflink); 124698cf656SMichael Große// $difflink = str_replace('http:/', 'http://', $difflink); 125698cf656SMichael Große 126698cf656SMichael Große return $difflink; 127698cf656SMichael Große } 128698cf656SMichael Große 129698cf656SMichael Große /** 130698cf656SMichael Große * erzeugt den Diff-Link 131698cf656SMichael Große */ 132698cf656SMichael Große function difflink($id, $rev1, $rev2) { 133698cf656SMichael Große $data = pageinfo(); 134698cf656SMichael Große 135698cf656SMichael Große if ($rev1 == $rev2) { 136698cf656SMichael Große// return ''; 137698cf656SMichael Große } 138698cf656SMichael Große $options = array( 139698cf656SMichael Große 'do' => 'diff', 140698cf656SMichael Große 'rev2[0]' => 'lastappr', 141698cf656SMichael Große 'rev2[1]' => $rev2, 142698cf656SMichael Große 'suggestfrom' => $data['userinfo']['mail'], 143698cf656SMichael Große ); 144698cf656SMichael Große 145698cf656SMichael Große// $difflink = DOKU_URL . wl($id, '&rev2[]=' . $rev1 . '&rev2[]=' . $rev2 . '&do[diff]=1&suggestfrom=' . $data['userinfo']['mail'], '', false, '&'); 146698cf656SMichael Große $difflink = wl($id, $options,true, '&'); 147698cf656SMichael Große //$difflink = str_replace('//', '/', $difflink); 148698cf656SMichael Große //$difflink = str_replace('http:/', 'http://', $difflink); 149698cf656SMichael Große 150698cf656SMichael Große return $difflink; 151698cf656SMichael Große } 152698cf656SMichael Große 153698cf656SMichael Große} 154