1<?php
2/**
3 * DokuWiki Plugin links4pages (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Albin Kauffmann <albin@kauff.org>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) {
11    die();
12}
13
14class action_plugin_links4pages extends DokuWiki_Action_Plugin
15{
16
17    /**
18     * Registers a callback function for a given event
19     *
20     * @param Doku_Event_Handler $controller DokuWiki's event controller object
21     *
22     * @return void
23     */
24    public function register(Doku_Event_Handler $controller)
25    {
26        $controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'handle_menu_items_assembly');
27    }
28
29    /**
30     * [Custom event handler which performs action]
31     *
32     * Called for event:
33     *
34     * @param Doku_Event $event  event object by reference
35     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
36     *                           handler was registered]
37     *
38     * @return void
39     */
40    public function handle_menu_items_assembly(Doku_Event $event, $param)
41    {
42        if($event->data['view'] == 'page') {
43            $i = 1;
44            while ($i < 3) {
45                $id = $this->getConf(sprintf("%'.02d_id", $i));
46                if (!empty($id)) {
47                    $label = $this->getConf(sprintf("%'.02d_label", $i));
48                    $svg_id = $this->getConf(sprintf("%'.02d_svg_id", $i));
49                    $pos = $this->getConf(sprintf("%'.02d_pos", $i));
50                    array_splice($event->data['items'], intval($pos), 0,
51                        [new \dokuwiki\plugin\links4pages\MenuItem($id, $label,
52                                                                   $svg_id)]);
53                }
54                $i = $i + 1;
55            }
56        }
57    }
58
59}
60