1<?php
2/**
3 * DokuWiki Action Plugin Uparrow
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Michael Klier <chi@chimeric.de>
7 */
8// must be run within Dokuwiki
9if(!defined('DOKU_INC')) die();
10
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
12if(!defined('DOKU_LF')) define('DOKU_LF', "\n");
13
14require_once(DOKU_PLUGIN.'action.php');
15
16/**
17 * All DokuWiki plugins to extend the admin function
18 * need to inherit from this class
19 */
20class action_plugin_uparrow extends DokuWiki_Action_Plugin {
21
22    function getInfo() {
23        return array(
24                'author' => 'Michael Klier',
25                'email'  => 'chi@chimeric.de',
26                'date'   => @file_get_contents(DOKU_PLUGIN.'uparrow/VERSION'),
27                'name'   => 'UpArrow Plugin (action component)',
28                'desc'   => 'Automatically adds an arrow which links to the top of the page after each section.',
29                'url'    => 'http://dokuwiki.org/plugin:uparrow',
30            );
31    }
32
33    // register hook
34    function register(&$controller) {
35        $controller->register_hook('PARSER_HANDLER_DONE', 'BEFORE', $this, 'insert_uparrow');
36    }
37
38    /**
39     * Modifies the final instruction list of a page and adds instructions for
40     * an uparow link.
41     *
42     * Michael Klier <chi@chimeric.de>
43     */
44    function insert_uparrow(&$event, $param){
45        if(!$this->getConf('auto')) return;
46
47        $image = $this->getConf('image');
48        if(!@file_exists(DOKU_PLUGIN.'uparrow/images/' . $image)) {
49            $image = DOKU_URL.'lib/plugins/uparrow/images/tango-big.png';
50        } else {
51            $image = DOKU_URL.'lib/plugins/uparrow/images/' . $image;
52        }
53        // uparrow plugin instructions
54        $uparrow = array('plugin', array('uparrow', array($image), 1, '~~UP~~'));
55
56        $ins_new = array();
57        $ins =& $event->data->calls;
58        $num = count($ins);
59
60        for($i=0;$i<$num;$i++) {
61            if($ins[$i][0] == 'section_close') {
62                array_push($ins_new, $uparrow);
63            }
64            array_push($ins_new, $ins[$i]);
65        }
66
67        $ins = $ins_new;
68    }
69}
70
71// vim:ts=4:sw=4:et:enc=utf-8:
72