1<?php
2/**
3 * Redirect plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12/**
13 * Class admin_plugin_redirect
14 *
15 * Provide editing mechanism for configuration
16 */
17class admin_plugin_redirect extends DokuWiki_Admin_Plugin {
18
19    /** @var helper_plugin_redirect */
20    protected $hlp;
21
22    /**
23     * admin_plugin_redirect constructor.
24     */
25    public function __construct() {
26        $this->hlp = plugin_load('helper', 'redirect');
27    }
28
29    /**
30     * Access for managers allowed
31     */
32    public function forAdminOnly() {
33        return false;
34    }
35
36    /**
37     * return sort order for position in admin menu
38     */
39    public function getMenuSort() {
40        return 140;
41    }
42
43    /**
44     * return prompt for admin menu
45     */
46    public function getMenuText($language) {
47        return $this->getLang('name');
48    }
49
50    /**
51     * handle user request
52     */
53    public function handle() {
54        global $INPUT;
55        if($INPUT->post->has('redirdata')) {
56            if($this->hlp->saveConfigFile($INPUT->post->str('redirdata'))) {
57                msg($this->getLang('saved'), 1);
58            }
59        }
60    }
61
62    /**
63     * output appropriate html
64     */
65    public function html() {
66        global $lang;
67        echo $this->locale_xhtml('intro');
68        echo '<form action="" method="post" >';
69        echo '<input type="hidden" name="do" value="admin" />';
70        echo '<input type="hidden" name="page" value="redirect" />';
71        echo '<textarea class="edit" rows="15" cols="80" style="height: 300px" name="redirdata">';
72        echo formtext($this->hlp->loadConfigFile());
73        echo '</textarea><br />';
74        echo '<input type="submit" value="' . $lang['btn_save'] . '" class="button" />';
75        echo '</form>';
76    }
77
78}
79