xref: /plugin/publish/action/mail.php (revision 698cf6562d7cb0df92c1ecdf8351bb86fcb93a62)
1*698cf656SMichael Große<?php
2*698cf656SMichael Große/**
3*698cf656SMichael Große * @license GNU General Public License, version 2
4*698cf656SMichael Große */
5*698cf656SMichael Große
6*698cf656SMichael Große
7*698cf656SMichael Großeif (!defined('DOKU_INC')) die();
8*698cf656SMichael Große
9*698cf656SMichael Große
10*698cf656SMichael Große/**
11*698cf656SMichael Große * Class action_plugin_publish_mail
12*698cf656SMichael Große *
13*698cf656SMichael Große * @author Michael Große <grosse@cosmocode.de>
14*698cf656SMichael Große */
15*698cf656SMichael Großeclass action_plugin_publish_mail extends DokuWiki_Action_Plugin {
16*698cf656SMichael Große
17*698cf656SMichael Große    public function register(Doku_Event_Handler $controller) {
18*698cf656SMichael Große
19*698cf656SMichael Große        $controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'send_change_mail', array());
20*698cf656SMichael Große    }
21*698cf656SMichael Große
22*698cf656SMichael Große    // Funktion versendet eine Änderungsmail
23*698cf656SMichael Große    function send_change_mail(&$event, $param) {
24*698cf656SMichael Große        global $ID;
25*698cf656SMichael Große        global $ACT;
26*698cf656SMichael Große        global $REV;
27*698cf656SMichael Große        global $INFO;
28*698cf656SMichael Große        global $conf;
29*698cf656SMichael Große        $data = pageinfo();
30*698cf656SMichael Große
31*698cf656SMichael Große        if ($ACT != 'save') {
32*698cf656SMichael Große            return true;
33*698cf656SMichael Große        }
34*698cf656SMichael Große        if (!$event->data[3]) {
35*698cf656SMichael Große            return true;
36*698cf656SMichael Große        }
37*698cf656SMichael Große
38*698cf656SMichael Große        // get mail receiver
39*698cf656SMichael Große        //$receiver = 'grosse@cosmocode.de';//
40*698cf656SMichael Große        $receiver = $this->getConf('apr_mail_receiver');
41*698cf656SMichael Große
42*698cf656SMichael Große        // get mail sender
43*698cf656SMichael Große        $sender = $data['userinfo']['mail'];
44*698cf656SMichael Große
45*698cf656SMichael Große        if ($sender == $receiver) {
46*698cf656SMichael Große            dbglog('Mail not send. Sender and receiver are identical.');
47*698cf656SMichael Große//            return true;
48*698cf656SMichael Große        }
49*698cf656SMichael Große
50*698cf656SMichael Große        if ($INFO['isadmin'] == '1') {
51*698cf656SMichael Große            dbglog('Mail not send. Sender is admin.');
52*698cf656SMichael Große//            return true;
53*698cf656SMichael Große        }
54*698cf656SMichael Große
55*698cf656SMichael Große        // get mail subject
56*698cf656SMichael Große        //$timestamp = time(); //$data['meta']['date']['modified'];
57*698cf656SMichael Große        $timestamp = $data['lastmod'];
58*698cf656SMichael Große//        date_default_timezone_set("Europe/Paris");
59*698cf656SMichael Große        $datum = date("d.m.Y",$timestamp);
60*698cf656SMichael Große        $uhrzeit = date("H:i",$timestamp);
61*698cf656SMichael Große        $subject = $this->getLang('apr_mail_subject') . ': ' . $ID . ' - ' . $datum . ' ' . $uhrzeit;
62*698cf656SMichael Große        dbglog($subject);
63*698cf656SMichael Große
64*698cf656SMichael Große        // get mail text
65*698cf656SMichael Große        //$body = 'apr_changemail_text';
66*698cf656SMichael Große        $body = $this->getLang('apr_changemail_text');
67*698cf656SMichael Große        $body = str_replace('@DOKUWIKIURL@', DOKU_URL, $body);
68*698cf656SMichael Große        $body = str_replace('@FULLNAME@', $data['userinfo']['name'], $body);
69*698cf656SMichael Große        $body = str_replace('@TITLE@', $conf['title'], $body);
70*698cf656SMichael Große
71*698cf656SMichael Große//        dbglog(pageinfo());
72*698cf656SMichael Große        $difflink = $this->difflink($ID, $this->getLastApproved(), $data['lastmod']);
73*698cf656SMichael Große        $difflink = '"' . $difflink . '"';
74*698cf656SMichael Große        $body = str_replace('@CHANGES@', $difflink, $body);
75*698cf656SMichael Große        $apprejlink = $this->apprejlink($ID, $data['lastmod']);
76*698cf656SMichael Große        $apprejlink = '"' . $apprejlink . '"';
77*698cf656SMichael Große        $body = str_replace('@APPREJ@', $apprejlink, $body);
78*698cf656SMichael Große
79*698cf656SMichael Große        dbglog('mail_send');
80*698cf656SMichael Große        return mail_send($receiver, $subject, $body, $sender);
81*698cf656SMichael Große    }
82*698cf656SMichael Große
83*698cf656SMichael Große    function getLastApproved() {
84*698cf656SMichael Große        $data = pageinfo();
85*698cf656SMichael Große        if (!$data['meta']['approval']) {
86*698cf656SMichael Große            return '';
87*698cf656SMichael Große        }
88*698cf656SMichael Große        $allapproved = array_keys($data['meta']['approval']);
89*698cf656SMichael Große        dbglog('$allapproved: ' . $allapproved);
90*698cf656SMichael Große        rsort($allapproved);
91*698cf656SMichael Große
92*698cf656SMichael Große        $latestapproved = $allapproved[0];
93*698cf656SMichael Große        dbglog('$latest_rev: ' . $latestapproved);
94*698cf656SMichael Große
95*698cf656SMichael Große        return $latestapproved;
96*698cf656SMichael Große    }
97*698cf656SMichael Große
98*698cf656SMichael Große    /**
99*698cf656SMichael Große     * erzeugt den Link auf die edit-Seite
100*698cf656SMichael Große     *
101*698cf656SMichael Große     * @param $id
102*698cf656SMichael Große     * @param $rev
103*698cf656SMichael Große     * @return mixed|string
104*698cf656SMichael Große     */
105*698cf656SMichael Große    function apprejlink($id, $rev) {
106*698cf656SMichael Große        $data = pageinfo();
107*698cf656SMichael Große
108*698cf656SMichael Große        $options = array(
109*698cf656SMichael Große             'rev'=> $rev,
110*698cf656SMichael Große             'do'=>'edit',
111*698cf656SMichael Große             'suggestfrom' => $data['userinfo']['mail'],
112*698cf656SMichael Große        );
113*698cf656SMichael Große        $difflink = wl($id, $options, true, '&');
114*698cf656SMichael Große//        $difflink = str_replace('//', '/', $difflink);
115*698cf656SMichael Große//        $difflink = str_replace('http:/', 'http://', $difflink);
116*698cf656SMichael Große
117*698cf656SMichael Große        return $difflink;
118*698cf656SMichael Große    }
119*698cf656SMichael Große
120*698cf656SMichael Große    /**
121*698cf656SMichael Große     * erzeugt den Diff-Link
122*698cf656SMichael Große     */
123*698cf656SMichael Große    function difflink($id, $rev1, $rev2) {
124*698cf656SMichael Große        $data = pageinfo();
125*698cf656SMichael Große
126*698cf656SMichael Große        if ($rev1 == $rev2) {
127*698cf656SMichael Große//            return '';
128*698cf656SMichael Große        }
129*698cf656SMichael Große        $options = array(
130*698cf656SMichael Große            'do' => 'diff',
131*698cf656SMichael Große            'rev2[0]' => 'lastappr',
132*698cf656SMichael Große            'rev2[1]' => $rev2,
133*698cf656SMichael Große            'suggestfrom' => $data['userinfo']['mail'],
134*698cf656SMichael Große        );
135*698cf656SMichael Große
136*698cf656SMichael Große//        $difflink = DOKU_URL . wl($id, '&rev2[]=' . $rev1 . '&rev2[]=' . $rev2 . '&do[diff]=1&suggestfrom=' . $data['userinfo']['mail'], '', false, '&');
137*698cf656SMichael Große        $difflink = wl($id, $options,true, '&');
138*698cf656SMichael Große        //$difflink = str_replace('//', '/', $difflink);
139*698cf656SMichael Große        //$difflink = str_replace('http:/', 'http://', $difflink);
140*698cf656SMichael Große
141*698cf656SMichael Große        return $difflink;
142*698cf656SMichael Große    }
143*698cf656SMichael Große
144*698cf656SMichael Große}
145