xref: /plugin/publish/action/hide.php (revision 43442d828155214bbb20b0088f3c7f564c51328d) !
1<?php
2
3if(!defined('DOKU_INC')) die();
4
5class action_plugin_publish_hide extends DokuWiki_Action_Plugin {
6
7    /**
8     * @var helper_plugin_publish
9     */
10    private $hlp;
11
12    function __construct() {
13        $this->hlp = plugin_load('helper','publish');
14    }
15
16    function register(&$controller) {
17        if ($this->getConf('hide drafts')) {
18            $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'hide', array());
19        }
20    }
21
22    /**
23     * @param Doku_Event $event
24     * @param array $param
25     */
26    function hide(&$event, $param) {
27        global $ID;
28        global $REV;
29        if ($this->hlp->isRevisionApproved($REV, $ID)) {
30            return;
31        }
32
33        $allowedGroups = array_filter(explode(' ', trim($this->getConf('author groups'))));
34        if (empty($allowedGroups)) {
35            if (auth_quickaclcheck($ID) >= AUTH_EDIT) {
36                return;
37            }
38        } else {
39            if ($_SERVER['REMOTE_USER']) {
40                global $USERINFO;
41                foreach ($allowedGroups as $allowedGroup) {
42                    $allowedGroup = trim($allowedGroup);
43                    if (in_array($allowedGroup, $USERINFO['grps'])) {
44                        return;
45                    }
46                }
47            }
48        }
49
50        global $ACT;
51        if (!in_array($ACT, array('show', 'edit', 'source', 'diff'))) {
52            return;
53        }
54
55        $ACT = 'denied';
56
57        $event->preventDefault();
58        $event->stopPropagation();
59
60        print p_locale_xhtml('denied');
61
62    }
63
64}