xref: /plugin/structpublish/action/publish.php (revision 6078c200efdbea381b1635c7cb670e73fdb464f9)
1<?php
2
3use dokuwiki\plugin\structpublish\meta\Constants;
4
5class action_plugin_structpublish_publish extends DokuWiki_Action_Plugin
6{
7    /** @inheritDoc */
8    public function register(Doku_Event_Handler $controller)
9    {
10        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'changeStatus');
11    }
12
13    /**
14     * Handle the publish button and version field
15     *
16     * @param Doku_Event $event
17     * @return void
18     */
19    public function changeStatus(Doku_Event $event)
20    {
21        if ($event->data != 'show') {
22            return;
23        }
24
25        global $INPUT;
26        $in = $INPUT->arr('structpublish');
27        if (!$in || !in_array(key($in), [Constants::ACTION_PUBLISH, Constants::ACTION_APPROVE])) {
28            return;
29        }
30
31        if (!checkSecurityToken()) return;
32
33        $helper = plugin_load('helper', 'structpublish_publish');
34        $helper->saveRevision(key($in), $INPUT->str('version'));
35    }
36}
37