Topbar

Topbar zeigt dir im DokuWiki eine Navigationsbar oben am Browser an in der man zum Beispiel externe Links einbinden kann wie zurück zu Hauptseite oder ähnliches.

action.php:

Hier können Fallbacklinks eingegeben werden sollte das Plugin mal nicht in der Lage sein die Config Datei zu laden. Im normal Fall sollte das aber kein Problem sein.

<?php
/**
 * DokuWiki Plugin topbar (Action Component)
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 */

// Must be run within DokuWiki
if (!defined('DOKU_INC')) die();

class action_plugin_topbar extends DokuWiki_Action_Plugin {

    /**
     * Registers a callback function for a given event
     */
    public function register(Doku_Event_Handler $controller) {
        // Hook into the HTML header and content display
        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'addCss');
        $controller->register_hook('TPL_CONTENT_DISPLAY', 'BEFORE', $this, 'addTopbar');
    }

    /**
     * Adds custom CSS for the topbar
     */
    public function addCss(Doku_Event $event) {
        $event->data['link'][] = array(
            'type' => 'text/css',
            'rel'  => 'stylesheet',
            'href' => DOKU_BASE . 'lib/plugins/topbar/style.css'
        );
    }

    /**
     * Adds the Topbar HTML
     */
    public function addTopbar(Doku_Event $event) {
        // Links aus der Konfigurationsdatei laden
        $links = $this->loadLinks();

        // HTML für die Links generieren
        $linkHtml = '';
        foreach ($links as $link) {
            if (!isset($link['url']) || !isset($link['label'])) continue;

            $url = htmlspecialchars($link['url']);
            $label = htmlspecialchars($link['label']);
            $linkHtml .= "<li><a href=\"{$url}\">{$label}</a></li>";
        }

        // HTML für die Topbar
        $topbarHTML = "
            <div class=\"topbar\">
                <ul>
                    {$linkHtml}
                </ul>
            </div>
        ";

        // Topbar vor dem bestehenden HTML einfügen
        echo $topbarHTML;
    }

    /**
     * Load links from the configuration file
     */
    private function loadLinks() {
        global $conf;

        // Fallback auf Standard-Links
        $defaultLinks = [
            ['url' => '/doku.php?id=start', 'label' => 'Startseite'],
            ['url' => 'https://meine-website.de', 'label' => 'Meine Website'],
            ['url' => '/doku.php?id=kontakt', 'label' => 'Kontakt'],
        ];

        // Versuche, die Datei `default.php` zu laden
        $configFile = __DIR__ . '/conf/default.php';
        if (file_exists($configFile)) {
            include $configFile;
            if (isset($conf['links']) && is_array($conf['links'])) {
                return $conf['links'];
            }
        }

        return $defaultLinks;
    }
}

style.css:

/* Topbar ganz oben */
.topbar {
    background-color: #333;
    color: white;
    padding: 10px 0;
    position: fixed;
    top: 0; /* Ganz oben */
    left: 0;
    width: 100%;
    z-index: 2000; /* Höher als alle anderen Elemente */
    box-sizing: border-box;
}

/* Adminleiste scrollt mit */
#dokuwiki__header {
    position: relative; /* Adminleiste scrollt mit dem Inhalt */
    top: auto; /* Kein Einfluss von der Topbar */
    z-index: 1500; /* Zwischen Topbar und Inhalt, falls nötig */
}

/* Seiteninhalt verschieben, damit die Topbar nicht verdeckt */
body {
    padding-top: 50px; /* Platz für die Topbar */
}

/* Styling für Links in der Topbar */
.topbar ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: flex-start;
}

.topbar ul li {
    margin: 0 15px;
}

.topbar ul li a {
    color: white;
    text-decoration: none;
    font-weight: bold;
}

.topbar ul li a:hover {
    text-decoration: underline;
}

default.php:

Die Datei muss im Ordner conf liegen IM Plugin Ordner.

Bei Bedarf können mehr Links eingefügt werden. Einfach „[‚url‘ => ‚URL HIER EINFÜGEN‘, ‚label‘ => ‚Dein Link Name 2‘],“ kopieren und nochmal einfügen. Natürlich URL HIER EINFÜGEN durch deine Webadresse ersetzten und Dein Link Name durch deine Gewünschte Anzeige ersetzten.

<?php
$conf['links'] = [
    ['url' => 'URL HIER EINFÜGEN', 'label' => 'Dein Link Name 1'],
    ['url' => 'URL HIER EINFÜGEN', 'label' => 'Dein Link Name 2'],
];

plugin.info.txt:

base   topbar
author Hei3enberg
email  contac@hei3enberg.com
date   2024-11-24
name   Topbar Plugin
desc   Fügt eine obere Navigationsleiste hinzu, in der benutzerdefinierte Links angezeigt werden.
url    http://hei3enberg.net