xref: /plugin/structpublish/action/banner.php (revision 871068513738e2832d0b57dbff724df27f613c49)
1<?php
2
3/**
4 * Action component responsible for the publish banner
5 * attached to struct data of a page
6 */
7class action_plugin_structpublish_banner extends DokuWiki_Action_Plugin
8{
9    /**
10     * @inheritDoc
11     */
12    public function register(Doku_Event_Handler $controller)
13    {
14        $controller->register_hook('PLUGIN_STRUCT_RENDER_SCHEMA_DATA', 'AFTER', $this, 'renderBanner');
15    }
16
17    /**
18     * Add banner to struct data of a page
19     *
20     * @return bool
21     */
22    public function renderBanner(Doku_Event $event)
23    {
24        $data = $event->data;
25        if (!$data['hasdata'] || $data['format'] !== 'xhtml') return true;
26
27        $renderer = $data['renderer'];
28        $html = $this->getBannerHtml();
29        $renderer->doc .= $html;
30
31        return true;
32    }
33
34    /**
35     * @return string
36     */
37    protected function getBannerHtml()
38    {
39        global $ID;
40        $user = $_SERVER['REMOTE_USER'];
41        $html = '';
42
43        /** @var \helper_plugin_structpublish_permissions $permissonsHelper */
44        $permissonsHelper = plugin_load('helper', 'structpublish_permissions');
45        if ($permissonsHelper->isPublisher($ID, $user)) {
46            $html .= 'YOU MAY!';
47        }
48
49        return $html;
50    }
51}
52