1<?php
2/**
3 * Combonav Plugin: Vytvoří combobox pro navigaci mezi stránkami
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     [Vaše jméno]
7 */
8
9// Ujistíme se, že skript není spuštěn přímo
10if(!defined('DOKU_INC')) die();
11
12class syntax_plugin_combonav extends DokuWiki_Syntax_Plugin {
13
14    public function getType() {
15        return 'substition';
16    }
17
18    public function getSort() {
19        return 155;
20    }
21
22    public function connectTo($mode) {
23        $this->Lexer->addSpecialPattern('\{\{combonav>.*?\}\}', $mode, 'plugin_combonav');
24    }
25
26    public function handle($match, $state, $pos, Doku_Handler $handler) {
27        // Extrahujeme seznam stránek z syntaxe
28        $match = substr($match, 11, -2); // Odstraníme {{combonav> a }}
29        $pages = explode(' ', trim($match));
30        return array($pages);
31    }
32
33    public function render($mode, Doku_Renderer $renderer, $data) {
34        if($mode != 'xhtml') return false;
35
36        // Získáme seznam stránek
37        list($pages) = $data;
38
39        // Vygenerujeme jedinečné ID pro combobox
40        $id = 'combonav_' . md5(join('', $pages));
41
42        // Začátek HTML výstupu
43        $renderer->doc .= '<select id="' . $id . '" class="combonav">';
44        $renderer->doc .= '<option value="">-- Vyberte stránku --</option>';
45
46        // Přidáme každou stránku jako možnost
47        foreach($pages as $page) {
48            $title = p_get_first_heading($page); // Získáme název stránky
49            if(!$title) $title = $page; // Pokud není název, použijeme ID stránky
50            $renderer->doc .= '<option value="' . wl($page) . '">' . $title . '</option>';
51        }
52
53        $renderer->doc .= '</select>';
54
55        // Přidáme JavaScript pro obsluhu změny výběru
56        $renderer->doc .= '<script>
57            document.getElementById("' . $id . '").addEventListener("change", function() {
58                var selected = this.value;
59                if(selected) {
60                    window.location.href = selected;
61                }
62            });
63        </script>';
64
65        return true;
66    }
67}