xref: /plugin/structpublish/action/show.php (revision 63483f2079bf73678c41b0c5870bc6ddb1202321)
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                // FIXME we could add our own action to display a custom message instead of standard denied action
39            }
40
41            $REV = $latestPublishedRev;
42            $INFO['rev'] = $latestPublishedRev;
43        }
44    }
45}
46