xref: /plugin/footerv2/action.php (revision f09b1d210954774d05cc47fb4c1355dd5b81ea83)
1<?php
2/**
3 * DokuWiki Plugin footer (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 *
7 * Original: from Plugin headerfooter, author  Li Zheng <lzpublic@qq.com>
8 * Modified by Juergen  H-J-Schuemmer@Web.de
9 * Only the footer component is supported in this plugin because the header functionality breaks the section edit mode
10 */
11
12// must be run within Dokuwiki
13if(!defined('DOKU_INC')) die();
14
15class action_plugin_footer extends DokuWiki_Action_Plugin {
16    public function register(Doku_Event_Handler $controller) {
17
18       $controller->register_hook('PARSER_WIKITEXT_PREPROCESS', 'AFTER', $this, 'handle_parser_wikitext_preprocess');
19
20    }
21    public function handle_parser_wikitext_preprocess(Doku_Event &$event, $param) {
22        global $INFO;
23        global $ID;
24        global $conf;
25
26        //what does this mean???
27        if ($INFO['id'] != '') return; // Jede Seite wird zweimal ausgeführt. Wenn die ID leer ist, ist es der echte Text, andernfalls ist es das Menü.
28
29        //helper array needed for parsePageTemplate
30        //so that replacement like shown here is possible: https://www.dokuwiki.org/namespace_templates#replacement_patterns
31        $data = array(
32            'id'        => $ID, // the id of the page to be created
33            'tpl'       => '',  // the text used as template
34        );
35
36		// Auslesen der Konfiguration für das Präfix der Vorlage-Dateien:
37		$pre_nsp = $this->getConf('prefix_namespace');
38		if ($pre_nsp != '') {
39			$pre_nsp = '/'.$pre_nsp.'_';
40		} else {
41			$pre_nsp = '/_';    // Defaultwert 1 Unterstrich für Namespace
42		};
43		$pre_sub = $this->getConf('prefix_subnamespace');
44		if ($pre_sub != '') {
45			$pre_sub = '/'.$pre_sub.'_';
46		} else {
47			$pre_sub = '/__';   // Defaultwert 2 Unterstriche für Sub-Namespace
48		};
49
50        $footerpath = '';
51		$templatename = 'footer.txt';    // Name der Vorlage
52        $path = dirname(wikiFN($ID));
53        if (@file_exists($path.$pre_nsp.$templatename)) {
54            $footerpath = $path.$pre_nsp.$templatename;
55        } else {
56            // search upper namespaces for templates
57            $len = strlen(rtrim($conf['datadir'], '/'));
58            while (strlen($path) >= $len) {
59                if (@file_exists($path.$pre_sub.$templatename)) {
60                    $footerpath = $path.$pre_sub.$templatename;
61                    break;
62                }
63                $path = substr($path, 0, strrpos($path, '/'));
64            }
65        }
66
67        if (!empty($footerpath)) {
68            $footer = file_get_contents($footerpath);
69            if ($footer !== false) {
70                $data['tpl'] = cleanText($footer);
71                $footer = parsePageTemplate($data);
72
73                if ($this->getConf('separation') == 'paragraph') {
74					// Wenn Absätze zum Teilen verwendet werden
75                    $footer = rtrim($footer, " \r\n\\") . "\n\n";
76                }
77                $event->data .= $footer;
78            }
79        }
80    }
81}