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