xref: /plugin/structpublish/action/show.php (revision 5c2215e890cc9516db9bc28cfa976283c0e72b1e)
1<?php
2
3use dokuwiki\plugin\structpublish\meta\Constants;
4use dokuwiki\plugin\structpublish\meta\Revision;
5
6class action_plugin_structpublish_show extends DokuWiki_Action_Plugin
7{
8    /**
9     * @inheritDoc
10     */
11    public function register(Doku_Event_Handler $controller)
12    {
13        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleShow');
14    }
15
16    public function handleShow(Doku_Event $event)
17    {
18        if ($event->data != 'show') return;
19
20        global $ID;
21        global $REV;
22        global $INFO;
23
24        /** @var helper_plugin_structpublish_db $dbHelper */
25        $dbHelper = plugin_load('helper', 'structpublish_db');
26
27        if (!$dbHelper->isPublishable()) return;
28
29        $currentRevision = new Revision($dbHelper->getDB(), $ID, $INFO['currentrev']);
30        /** @var action_plugin_structpublish_sqlitefunction $functions */
31        $functions = plugin_load('action', 'structpublish_sqlitefunction');
32        if (
33            $currentRevision->getStatus() !== Constants::STATUS_PUBLISHED
34            && !$functions->IS_PUBLISHER($ID)
35        ) {
36            $latestPublishedRev = $currentRevision->getLatestPublishedRevision()->getRev();
37            if (!$latestPublishedRev) {
38                $event->data = 'denied';
39                // FIXME we could add our own action to display a custom message instead of standard denied action
40            }
41
42            $REV = $latestPublishedRev;
43            $INFO['rev'] = $latestPublishedRev;
44        }
45    }
46}
47